Site SDK
The Site SDK is a npm package that provides support for working with Spheron Site organizations.
NOTE: The package is only meant for Node.js environments.
Installation
Using NPM
npm i @spheron/site
Using Yarn
yarn add @spheron/site
Usage
To use the Site SDK, you have to create an instance of SpheronClient
.
import { SpheronClient, ProtocolEnum } from "@spheron/site";
const client = new SpheronClient({ token });
The SpheronClient
constructor takes an object that has one property token
.
Follow the instructions in the DOCS (opens in a new tab) to generate this token.
NOTE: When you are creating the tokens, please choose web app type in the dashboard.
The SpheronClient
has three properties:
deployments
provides methods for working with deployments.projects
provides methods for working with projects.organization
provides methods for working with organizations.
Deployments
deploy
Used to start a new deployment.
await spheron.deployments.deploy({
gitUrl, // the url of the repository
projectName, // if the project for the repository does not exists, a new project will be created with this name
environmentVariables: {
KEY_1: "value1",
},
provider: ProviderEnum.GITHUB, // the provider of the git url
branch: "main", // the branch name that should be deployed
protocol: ProtocolEnum.IPFS, // the protocol on which the deployment should be uploaded
configuration: {
framework: FrameworkEnum.REACT,
workspace: "",
installCommand: "yarn install",
buildCommand: "yarn build",
publishDir: "build",
nodeVersion: NodeVersionEnum.V_16,
},
gitProviderPreferences: {
prComments: true;
commitComments: false;
buildStatus: false;
githubDeployment: true;
}
});
Params:
gitUrl
: (string) - the url of the repository.NOTE: Only repositories for which you have authorized the Spheron Git App can be deployed.
projectName
: (string) - if the project for thegitUrl
does not exists, a new project will be created andprojectName
will be used for the name of the project.environmentVariables
: (object) - an object that represents environment variables that should be used when deploying. If new variables are passed, they will automatically be added to the project's environment variables. Besides these variables, the variables of the Project will also be added to the deployment process.provider
: (ProviderEnum) - the provider of the repository.branch
: (string) - the branch of the deployment.protocol
: (ProtocolEnum) - the protocol on which the deployment should be uploaded. Supported protocols are:
enum ProtocolEnum {
ARWEAVE,
FILECOIN,
IPFS
}
configuration
: Configuration` - the configuration that should be used for the deployment. Checkout the configuration interface for more details.gitProviderPreferences
- (optional) If not passed, each property in the object will be set with its default value.prComments
: boolean - (optional) when set to false, a comment will not be left on a PR. The default value istrue
.commitComments
: boolean - (optional) when set to false, comment will not be left on a commit. The default value istrue
.buildStatus
: boolean - (optional) when set to false, build status will not be created for a commit. The default value istrue
.githubDeployment
: boolean - (optional) The option is only valid for Github repositories. When set to false, a Github Deployment (opens in a new tab) will not be created. Default value istrue
.
Returns the information about the deployment:
interface DeploymentResponse {
success: boolean; // indicates if the deployment has been started
message: string; // holds information about the deployment and more details if the deployment fails
deploymentId: string; // the id of the newly created deployment
projectId: string; // the project id of the newly created deployment
deployment: Deployment; // the newly created deployment
}
get
Used to get the deployment.
const deployment: Deployment = await spheron.deployments.get(deploymentId);
Params:
deploymentId
: (string) - Id of the deployment.
Returns an object of type Deployment
. Checkout the update configuration section for more details about the configuration interface.
interface Deployment {
id: string; // the id of the deployment
status: DeploymentStatusEnum; // the current state of the deployment
configuration: Configuration; // the specific configuration that was used for the deployment
buildTime: number; // the time it took for the deployment to finish, represented in seconds
fileSize: number; // the total file size of the deployment
deploymentEnvironmentName: string; // the environment of the deployment
commitId: string; // the commit id of the deployment
branch: string; // the branch of the deployment
protocol: ProtocolEnum; // the protocol that was used for the deployment
sitePreview: string; // the link to the deployed data
}
enum DeploymentStatusEnum {
PRE_QUEUE,
QUEUED,
PENDING,
CANCELED,
DEPLOYED,
FAILED,
AUTHORIZATION_NEEDED,
KILLING,
TIMED_OUT
}
getLogs
Used to get the logs of the deployment.
const logs: DeploymentLog[] = await spheron.deployments.getLogs(deploymentId);
Params:
deploymentId
: (string) - Id of the deployment.
Returns an array of objects that represent the deployment logs.
interface DeploymentLog {
log: string;
time: string;
}
cancel
Used to cancel a deployment that is in progress. The deployment is in progress if it is in PRE_QUEUE, QUEUED or, PENDING state.
await spheron.deployments.cancel(deploymentId);
NOTE: Owners and Admins can cancel any deployment. Members can only cancel deployments which that they have started.
Params:
deploymentId
: (string) - Id of the deployment.
Returns:
interface CancelDeploymentResponse {
message: string; // information about the cancellation
canceled: boolean; // true if deployment was canceled
killing: boolean; // true if deployment is in the cancellation process.
}
authorize
Used to authorize a deployment that is in AUTHORIZATION_NEEDED state.
await spheron.deployments.authorize(deploymentId);
NOTE: Only Owners or Admins can authorize a deployment.
Params:
deploymentId
: (string) - Id of the deployment.
Returns the information about the deployment:
interface DeploymentResponse {
success: boolean;
message: string;
deploymentId: string;
projectId: string;
deployment: Deployment;
}
redeploy
Used to start a new deployment with the same configuration as the one for which the deploymentId
is passed. The same configuration and commit id will be deployed, but the latest environment variables will be used.
await spheron.deployments.redeploy(deploymentId);
Params:
deploymentId
: (string) - Id of the deployment.
Returns the information about the deployment:
interface DeploymentResponse {
success: boolean;
message: string;
deploymentId: string;
projectId: string;
deployment: Deployment;
}
Projects
get
Used to get the project based on the passed Id.
const project: Project = await spheron.projects.get(projectId);
Params:
projectId
: (string) - Id of the project.
Returns an object of type Project
.
interface Project {
id: string; // the id of a project
name: string; // the name of a project
state: ProjectStateEnum; // the state of a project
url: string; // the url to the git repository of a project
organizationId: string; // the organizationId in which a project is
provider: ProviderEnum; // the Git provider of a project
configuration: Configuration; // the default configuration of a project. This configuration is used for webhook deployments.
}
enum ProjectStateEnum {
MAINTAINED,
ARCHIVED
}
enum ProviderEnum {
GITHUB,
GITLAB,
BITBUCKET
}
interface Configuration {
installCommand: string; // command that will be used to install the dependencies of the repository
buildCommand: string; // command that will be executed to build the repository
workspace: string; // the path to the app inside repository
publishDir: string; // the path to the build directory
framework: FrameworkEnum; // the framework of a project
nodeVersion: NodeVersionEnum; // the node version that will be used to build the project
}
enum NodeVersionEnum {
V_12,
V_14,
V_16
}
enum FrameworkEnum {
SIMPLE_JAVASCRIPT_APP,
VUE,
REACT,
NEXT,
ANGULAR,
PREACT,
NUXT,
SVELTE,
GATSBY,
ELEVENTY,
DOCUSAURUS,
SANITY,
HUGO,
IONIC_REACT,
VITE,
SCULLY,
STENCIL,
BRUNCH,
IONIC_ANGULAR
}
archive
Used to archive a project. When a project is archived new deployments cannot be started for it. If a project is already in an Archived state, an error will be thrown.
await spheron.projects.archive(projectId);
Params:
projectId
: (string) - Id of the project.
Method return type is void. If there is an issue while archiving, an error will be thrown.
unarchive
Used to update the project state from Archived to Maintained. If a project is already in a Maintained state, an error will be thrown.
await spheron.projects.unarchive(projectId);
Params:
projectId
: (string) - Id of the project.
Method return type is void. If there is an issue while archiving, an error will be thrown.
updateConfiguration
Used to update the default configuration of a project.
const configuration: Configuration = await spheron.projects.updateConfiguration(
projectId,
{
framework: FrameworkEnum.REACT,
workspace: "",
installCommand: "yarn install",
buildCommand: "yarn build",
publishDir: "build",
nodeVersion: NodeVersionEnum.V_16,
}
);
Params:
-
projectId
: (string) - Id of the project. -
configuration
:framework
: (FrameworkEnum) - the framework of the repositoryworkspace
: (string) - the path to the app inside the repositoryinstallCommand
: (string) - command that will be used to install the dependencies of the repositorybuildCommand
: (string) - command that will be executed to build the repositorypublishDir
: (string) - the path to the build directorynodeVersion
: (NodeVersionEnum) - the node version of your repository
Returns the updated configuration.
interface Configuration {
installCommand: string; // command that will be used to install the dependencies of the repository
buildCommand: string; // command that will be executed to build the repository
workspace: string; // the path to the app inside repository
publishDir: string; // the path to the build directory
framework: FrameworkEnum; // the framework of a project
nodeVersion: NodeVersionEnum; // the node version that will be used to build the project
}
enum NodeVersionEnum {
V_12,
V_14,
V_16
}
enum FrameworkEnum {
SIMPLE_JAVASCRIPT_APP,
VUE,
REACT,
NEXT,
ANGULAR,
PREACT,
NUXT,
SVELTE,
GATSBY,
ELEVENTY,
DOCUSAURUS,
SANITY,
HUGO,
IONIC_REACT,
VITE,
SCULLY,
STENCIL,
BRUNCH,
IONIC_ANGULAR
}
getEnvironmentVariables
Used to get the environment variables of a project
const variables: EnvironmentVariable[] =
await spheron.projects.getEnvironmentVariables(projectId);
Params:
projectId
: (string) - Id of the project.
Returns an array of environment variables.
interface EnvironmentVariable {
id: string; // the id of a environment variable
name: string; // the name of a environment variable
value: string; // the value of a environment variable
environments: string[]; // the deployment environments for which the variable will be used
}
addEnvironmentVariable
Used to add environment variables to a project.
const added: EnvironmentVariable[] =
await spheron.projects.addEnvironmentVariable(projectId, [
{
name: "variable1",
value: "value1",
environments: ["Production"],
},
{
name: "variable2",
value: "value2",
environments: ["Development", "Production"],
},
]);
Params:
projectId
: (string) - Id of the project.- Array of variables that should be added. Each object of the array should have the following properties:
name
: (string) - the name of the variable.value
: (string) - the value of the variable.environments
: (string[]) - the deployment environments for which the variable will be used
Returns an array of added variables.
updateEnvironmentVariable
Used to update an environment variable.
const updated = await spheron.projects.updateEnvironmentVariable(
projectId,
environmentVariableId,
{
name: "updated_name",
value: "updated_value",
environments: ["Development", "Production"],
}
);
Params:
projectId
: (string) - Id of the project.environmentVariableId
: (string) - Id of the environment variable.options
:name
: (string) - the name of the variable.value
: (string) - the value of the variable.environments
: (string[]) - the deployment environments for which the variable will be used
Returns the updated variable.
deleteEnvironmentVariable
Used to delete an environment variable.
await spheron.projects.deleteEnvironmentVariable(
projectId,
environmentVariableId
);
Params:
projectId
: (string) - Id of the project.environmentVariableId
: (string) - Id of the environment variable.
Method return type is void. If there is an issue while deleting, an error will be thrown.
getDeploymentEnvironments
Used to get the deployment environments of the project. For more information about deployment environments, checkout the Deployment Environment Docs
const deploymentEnvironments: DeploymentEnvironment[] =
await spheron.projects.getDeploymentEnvironments(projectId);
Params:
projectId
: (string) - Id of the project.
Returns an array of deployment environments.
interface DeploymentEnvironment {
id: string; // the id of the deployment environment
name: string; // the name of the deployment environment
protocol: ProtocolEnum; // the protocol of the deployment environment
branches: string[]; // the branches for which the deployment environment
}
enum ProtocolEnum {
ARWEAVE,
FILECOIN,
IPFS
}
createDeploymentEnvironment
Used to create a deployment environment for a project.
const created: DeploymentEnvironment =
await spheron.projects.createDeploymentEnvironment(projectId, {
name: "Deployment Environment Name",
branches: ["branch1", "branch2"],
protocol: ProtocolEnum.IPFS,
});
NOTE: To create a deployment environment, a pro subscription is needed, and it also costs 5$ per subscription. If your organization does not have a pro subscription or enough funds, an error will be thrown.
Params:
projectId
: (string) - Id of the project.options
:name
: (string) - the name of the deployment environment. The name of the deployment environment needs to be unique for the project or else an error will be thrown.branches
: (string[]) - an array of strings that represent the branches of the deployment environment. If a branch already exists in the Production deployment environment, an error will be thrown ( you would first need to remove the branch from the Production environment and add it to the one you want ). If a branch exists in some other deployment environment ( that is not a production one ), it will be removed from it and added to the newly created one.protocol
: (ProtocolEnum) - the protocol of the deployment environment.
Returns the created deployment environment.
updateDeploymentEnvironment
Used to update the deployment environment of the project.
const updated: DeploymentEnvironment =
await spheron.projects.updateDeploymentEnvironment(
projectId,
deploymentEnvironmentId,
{
name: "Deployment Environment Name Updated",
branches: ["branch1", "branch2", "branch3"],
protocol: ProtocolEnum.FILECOIN,
}
);
Params:
-
projectId
: (string) - Id of the project. -
deploymentEnvironmentId
: (string) - Id of the deployment environment. -
options
:name
: (string) - the name of the deployment environment.branches
: (string[]) - an array of strings that represent the branches of the deployment environment.protocol
: (ProtocolEnum) - the protocol of the deployment environment.
NOTE: The same constraints for names and branches exist both when creating and updating the deployment environment. Also, it is not possible to rename the Production and Development environments.
Returns the updated deployment environment.
deleteDeploymentEnvironment
Used to delete a deployment environment.
await spheron.projects.deleteDeploymentEnvironment(
projectId,
deploymentEnvironmentId
);
Params:
projectId
: (string) - Id of the project.deploymentEnvironmentId
: (string) - Id of the deployment environment.
NOTE: It is not possible to delete the Production and Development environments.
Method return type is void.
activateDeploymentEnvironment
Used to activate a deployment environment.
const deploymentEnvironment: DeploymentEnvironment =
await spheron.projects.activateDeploymentEnvironment(
projectId,
deploymentEnvironmentId
);
Params:
projectId
: (string) - Id of the project.deploymentEnvironmentId
: (string) - Id of the deployment environment.
Method returns the activated deployment environment.
deactivateDeploymentEnvironment
Used to deactivate a deployment environment.
const deploymentEnvironment: DeploymentEnvironment =
await spheron.projects.deactivateDeploymentEnvironment(
projectId,
deploymentEnvironmentId
);
Params:
projectId
: (string) - Id of the project.deploymentEnvironmentId
: (string) - Id of the deployment environment.
Method returns the deactivated deployment environment.
getDomains
Used to get the domains of a project.
const domains: Domain[] = await spheron.projects.getDomains(projectId);
Params:
projectId
: (string) - Id of the project.
Returns an array of deployment domains.
interface Domain {
id: string; // the id of the domain
name: string; // the domain name
verified: boolean; // true means that the domain is verified and that it will start serving the content
link: string; // the link to which the domain points to
type: DomainTypeEnum; // the type of the domain
projectId: string; // the project id of which the domain is
deploymentEnvironmentIds: string[]; // the ids of the deployment environments for the domain. Whenever a deployment for the specified environment is done, the domain will be updated to point to the new link of the deployment.
}
enum DomainTypeEnum {
DOMAIN,
SUBDOMAIN,
HANDSHAKE_DOMAIN,
HANDSHAKE_SUBDOMAIN,
ENS_DOMAIN
}
getDomain
Used to get the domain of a project.
const domain: Domain = await spheron.projects.getDomain(projectId, "test.com");
Params:
projectId
: (string) - Id of the project.domainIdentifier
: (string) The domain identifier can be the domain id, or the domain name itself.
Returns the domain.
addDomain
Used to add a new domain to a project.
const domain: Domain = await spheron.projects.addDomain(projectId, {
name: "domain.com",
type: DomainTypeEnum.DOMAIN,
deploymentEnvironments: ["Production"],
});
Params:
projectId
: (string) - Id of the project.options
:name
: (string) - the domain name.type
: (DomainTypeEnum) - the domain type.deploymentEnvironments
: (string[]) - (optional) name of the deployment environments. Whenever a deployment for the specified deployment environment is successfully executed, the domain will be updated to point to the newly deployed data.link
: (string) - (optional) thesitePreview
of a specific deployment of the same project. When this property is set, the domain will point to data of the specified deployment and will not be updated when a new deployment is done.
NOTE: Ether deploymentEnvironments
or link
is required. When only a
link is passed, the domain will not be updated when new deployments are done.
Returns the newly created domain. After a domain is created, you need to call the verifyDomain function for it to work.
updateDomain
Used to update a domain of a project.
const domain: Domain = await spheron.projects.updateDomain(
projectId,
domainId,
{
name: "test.com",
deploymentEnvironments: ["Production"],
}
);
Params:
projectId
: (string) - Id of the project.domainIdentifier
: (string) The domain identifier can be the domain id, or the domain name itself.options
:name
: (string) - the domain name.deploymentEnvironments
: (string) - (optional) name of the deployment environments. Whenever a deployment for the specified deployment environment is successfully executed, the domain will be updated to point to the newly deployed data.link
: (string) - (optional) ThesitePreview
of a specific deployment of the same project. When this property is set, the domain will point to data of the specified deployment and will not be updated when a new deployment is done.
NOTE: Same rules for deploymentEnvironments
and links
are applied here
as when creating a domain.
Returns the updated domain. If the domain name is updated, you need to call the verifyDomain function again.
verifyDomain
Used to verify the domain, after which the content behind the domain will be cached on CDN.
const domain: Domain = await spheron.projects.verifyDomain(projectId, domainId);
Params:
projectId
: (string) - Id of the project.domainIdentifier
: (string) The domain identifier can be the domain id, or the domain name itself.
Returns the verified domain.
getCdnDnsRecords
Used to get the values that should be set on your DNS provider for your bucket domains.
const { cdnARecords, cdnCnameRecords } =
await client.projects.getCdnDnsRecords();
Function getCdnDnsRecords
doesn't take any parameters.
Response
- cdnARecords - (string) - will contain the DNS value that should be used for domains.
- cdnCnameRecords - (string) - will contain the DNS value that should be used for subdomains.
deleteDomain
Used to delete a domain of a project.
await spheron.projects.deleteDomain(projectId, domainId);
Params:
projectId
: (string) - Id of the project.domainIdentifier
: (string) The domain identifier can be the domain id, or the domain name itself.
Method return type is void.
getDeployments
Used to get the deployments of a projects. Methods support pagination.
const deployments: Deployment[] = await spheron.projects.getDeployments(
projectId,
{
skip: 0,
limit: 5,
status: DeploymentStatusEnum.QUEUED,
}
);
Params:
projectId
: (string) - Id of the project.options
:skip
: (number)` - number of deployments to skip.limit
: (number)` - number of deployments to take.status
: (DeploymentStatusEnum) - (optional) status of the deployments.
Return the array of deployments. Check the get deployment function for the interface details.
getDeploymentCount
Used to get the deployment count of the project.
const deploymentCount: DeploymentCount =
await spheron.projects.getDeploymentCount(projectId);
Params:
projectId
: (string) - Id of the project.
Returns the number of deployments.
interface DeploymentCount {
total: number; // the total number of deployments
successful: number; // the number of successful deployments
failed: number; // the number of failed deployments
pending: number; // the number of deployments in pending state
}
Organization
The methods for working with organizations are available on the organization
property of the SpheronClient
object. All the methods work with the organization of the token that is passed in the constructor.
get
Used to get the organization.
const organization: Organization = await spheron.organization.get();
Returns an Organization for which the token was created.
interface Organization {
id: string; // the id of a organization
profile: {
name: string, // the name of a organization
username: string, // the username of a organization
image: string, // the url to the avatar image of a organization
};
}
getProjects
Used to get the projects of the organization. The methods support pagination.
const projects: Project[] = await spheron.organization.getProjects({
skip: 0,
limit: 10,
state: ProjectStateEnum.MAINTAINED,
});
Params:
options
:skip
: (number) - the number of projects to skip.limit
: (number) - the number of projects to take.state
: (ProjectStateEnum) - the state of the projects to fetch (optional).
Returns an array of projects. Checkout the get project section for more details on the project interface properties.
getProjectCount
Used to get the number of projects in the organization.
const count: number = await spheron.organization.getProjectCount({
state: ProjectStateEnum.MAINTAINED,
});
Params:
options
state
: (ProjectStateEnum) - project state filter (optional).
Returns the number of projects.
getUsage
Used to get the current subscription usage of the organization.
const usage: UsageWithLimits = await spheron.organization.getUsage();
Returns the UsageWithLimits
object.
interface UsageWithLimits {
used: {
bandwidth: number, // the bytes of bandwidth used for the current subscription
buildExecution: number, // the seconds of build execution done for the current subscription
concurrentBuild: number,// the number of concurrent builds in progress
storageArweave: number, // the bytes of used Arweave storage for the current subscription
storageIPFS: number, // the bytes of used IPFS storage for the current subscription
deploymentsPerDay: number, // number of deployments an organization can have one one day
domains: number, // the number of domains and subdomain an organization has
hnsDomains: number,// the number of hns domains an organization has
ensDomains: number,// the number of ens domains an organization has
environments: number,// the number of deployment environments an organization has
numberOfRequests: number,// the number of requests the organization has had till now
passwordProtection: number,; // 1 - if organization has support for password protection, otherwise 0.
};
limit: {
bandwidth: number, // the bandwidth limit for the current subscription
buildExecution: number,// the build execution limit for the current subscription
concurrentBuild: number, // how many concurrent builds can the organization have with the current subscription plan
storageArweave: number, // the limit in bytes for the Arweave storage for the current subscription
storageIPFS: number, // the limit in bytes for the IPFS storage for the current subscription
deploymentsPerDay: number,// the limit of how many deployments can an organization have per day
domains: number,// the limit on how many domains and subdomains can an organization have
hnsDomains: number, // the limit on how many hns domains can an organization have
ensDomains: number,// the limit on how many ens domains can an organization have
environments: number, // the limit on how many deployment environment can an organization have
membersLimit: number,// how many members can an organization have
};
}