@shifter/nodedeprecated

Shifter API SDK for Node.js

Usage no npm install needed!

<script type="module">
  import shifterNode from 'https://cdn.skypack.dev/@shifter/node';
</script>

README

Shifter SDK for JavaScript

Table of Contents

Created by gh-md-toc

Usage

Sign in

import { Auth, Statistics } from 'shifter-sdk'

const client = new Auth()
client.login('USERNAME', 'PASSWORD')
  .then(result => console.log(result))
{
  AccessToken: string,
  RefreshToken: string
}

Basic Usage

import { Auth, Statistics } from 'shifter-sdk'

const client = new Auth()
client.login('USERNAME', 'PASSWORD')
  .then(({ AccessToken }) => {
    const client = new Statistics.UsageSummary({
      token: AccessToken
    })
    return client.describe()
  })
  .then(result => console.log(result))

{
  updated_time: '2019-03-13T23:20:42.588404',
  projects_count: 10,
  disk_total: 10000,
  transfer_total: 0,
  user_name: 'hello',
  track_month: 201903
}

Refresh access token

import { Auth, Statistics } from 'shifter-sdk'

const client = new Auth()
client.login('USERNAME', 'PASSWORD')
  .then(({ RefreshToken }) => {
    return client.refresh(RefreshToken))
  })
  .then(result => console.log(result))

{
  AccessToken: string
}

Statistics

Describe Statistics

import { Statistics } from 'shifter-sdk'

const client = new Statistics.UsageSummary({
  token: 'YOUR_TOKEN'
})
client.describe()
  .then(result => console.log(result))

{
  updated_time: '2019-03-13T23:20:42.588404',
  projects_count: 10,
  disk_total: 10000,
  transfer_total: 0,
  user_name: 'hello',
  track_month: 201903
}

Describe site transfer amount

import { Statistics } from 'shifter-sdk'

const client = new Statistics.SiteTransfer({
  token: 'YOUR_TOKEN'
})

const result = await client.describe(siteId)
[
 {
   "transfer_gb": 5,
   "track_month": 201902
 }, {
   "transfer_gb": 10,
   "track_month": 201903
 }
]

Sites

Initilize

import { Sites } from 'shifter-sdk'

const client = new Sites({
  token: 'ACCESS_TOKEN'
})

List sites

const sites = await client.list()
[
 {
  "project_name": "test",
  "stock_state": "inuse",
  "project_id": "xxxxx-xxxxx-xxxx",
  "project_owner": "xxxxx",
  "wordpress_site_url": null,
  "php_version": "7.2",
  "access_url": "xxxxxx.on.getshifter.io",
  "last_launched": "2019-02-18T03:14:59+00:00",
  "disk_usage": 4,
  "deploy_type": "shifter_cdn",
  "raw_url": "xxxxxx.cloudfront.net",
  "create_time": "2019-01-18T06:21:31+00:00",
  "automation": true
 }
]

Describe site

const sites = await client.describe('site id')

 {
  "project_name": "test",
  "stock_state": "inuse",
  "project_id": "xxxxx-xxxxx-xxxx",
  "project_owner": "xxxxx",
  "wordpress_site_url": null,
  "php_version": "7.2",
  "access_url": "xxxxxx.on.getshifter.io",
  "last_launched": "2019-02-18T03:14:59+00:00",
  "disk_usage": 4,
  "deploy_type": "shifter_cdn",
  "raw_url": "xxxxxx.cloudfront.net",
  "create_time": "2019-01-18T06:21:31+00:00",
  "automation": true
 }

Create new site

const result = await client.create('my new site')
{
 "project_id": "xxx-xxxx-xxxx-xxxx",
 "project_name": "my new site",
 "shifter_cdn_url": "xxxx.cloudfront.net"
}

Update site name

await client.updateName(siteId, name)
""

Enable / Disable auto deployment

await client.enabledDeployAutomation(siteId)
""

await client.disabledDeployAutomation(siteId)
""

Start WordPress container

await client.startWordPress(siteId)
{
  "notification_id": "xxxxxxxxxxxxxxxxxxx"
}

await client.startWordPressAsEmergency(siteId)
{
  "notification_id": "xxxxxxxxxxxxxxxxxxx",
  "emergency_password": "xxxxxxxxx"
}

Get WordPress starting status

const { notification_id } = await client.startWordPress(siteId)
const status = await client.getWPSetupStatus(siteId, notification_id)
"INITIALIZING"

Stop WordPress container

await client.stopWordPress(siteId)
""

Delete site

await client.delete(siteId)
""

Artifacts

Initilize

import { Artifacts } from 'shifter-sdk'

const client = new Artifacts({
  token: 'ACCESS_TOKEN'
})

Generate

Start to generate a new artifact

const sites = await client.generate(siteId)
{
 "project_id":"xxxx-xxxxx-xxxxx-xxxx",
 "artifact_id":"xxxx-xxxxx-xxxxx-xxxx"
}

Get download URL

await client.getDownloadURL(siteId, artifactId)
{
  "url": "https://xxxxx"
}

Get genrating progress

await client.getGeneratingProcess(siteId)

{
  "percent": null,
  "sum_url": 0,
  "created_url": 0,
  "step": "queuing",
  "update_time": "2019-02-18T03:16:21.760Z",
  "owner": "john",
  "message": "queuing",
  "disk_usage": 4
}

List artifacts

const sites = await client.list()

[
 {
   "artifact_id": "xxx-xxxxx-xxxxx",
   "status": "published-shifter",
   "context_status": "success",
   "created_at": "2019-02-18T03:15:49+00:00",
   "failure_pages": "[]"
 }
]

Publish

await Client.publish(siteId, artifactId)
''

Stop generating artifact

const sites = await client.stopGenerating(siteId, artifactId)
""

Update specific artifact name

const sites = await client.updateName(siteId, artifactId, name)
""

Enable preview

await client.enablePreview(siteId, artifactId)

"https://xxxxx-xxxx-xxxxx-xxxx.preview.getshifter.io"

Delete

await client.delete(siteId, artifactId)
""

Organizations

Initilize

import { Organizations } from 'shifter-sdk'

const client = new Organizations.Foundation({
  token: 'ACCESS_TOKEN'
})

Create

client.create({
  org_name: 'organization name'
}).then(result => console.log(result))

{
  org_id: 'xxxxxxxxxxx'
}

Update

client.update('org_id', {
  org_name: 'organization name'
}).then(() => console.log('ok'))

ok

List

client.list().then(result => console.log(result))

[
 {
    org_id: 'xxxxx-xxxx-xxxx-xxxx',
    org_name: 'xxxxx',
    org_owner: 'xxxxxxx',
    org_website: '',
    phone_number: '',
    org_country: '',
    org_state: '',
    org_twitter: '',
    org_size: '',
    projects: [],
    members: []
  }
] 

Describe

client.descibe('org_id')
  .then(result => console.log(result))

{
  org_id: 'xxxxx-xxxx-xxxx-xxxx',
  org_name: 'xxxxx',
  org_owner: 'xxxxxxx',
  org_website: '',
  phone_number: '',
  org_country: '',
  org_state: '',
  org_twitter: '',
  org_size: '',
  projects: [],
  members: []
}

Delete

client.delete('org_id')
  .then(() => console.log('ok'))

ok

Activate invited member

client.activateInvitation('org_id', 'key')
  .then(() => console.log('ok'))

ok

Organization Site

Initilize

import { Organizations } from 'shifter-sdk'

const client = new Organizations.Sites({
  token: 'YOUR_TOKEN'
})

List site of organization

client.list('org_id')
  .then(result => console.log(result))

[
  {
    "project_name": "test-sub",
    "stock_state": "inuse",
    "project_id": "xxxx-xxxxxx-xxxxxx-xxxxxx",
    "project_owner": "xxxxxx",
    "php_version": "7.2",
    "access_url": "xxxxxxxxx.on.getshifter.io",
    "update_time": "",
    "last_launched": false,
    "disk_usage": 0,
    "deploy_type": false,
    "raw_url": "xxxxxxxxx.cloudfront.net",
    "create_time": "2018-07-05T07:41:25+00:00",
    "automation": false,
    "generate_state": "",
    "trial": ""
  }
]

Get site of organization

client.describe('org_id', 'site_id')
  .then(result => console.log(result))

{
  "project_name": "test-sub",
  "stock_state": "inuse",
  "project_id": "xxxx-xxxxxx-xxxxxx-xxxxxx",
  "project_owner": "xxxxxx",
  "php_version": "7.2",
  "access_url": "xxxxxxxxx.on.getshifter.io",
  "update_time": "",
  "last_launched": false,
  "disk_usage": 0,
  "deploy_type": false,
  "raw_url": "xxxxxxxxx.cloudfront.net",
  "create_time": "2018-07-05T07:41:25+00:00",
  "automation": false,
  "generate_state": "",
  "trial": ""
}

Add site to organization

client.add('org_id', ['site_id'])
  .then(() => console.log('ok'))

ok

Remove site from organization

client.remove('org_id', ['site_id'])
  .then(() => console.log('ok'))

ok

Organization Members

Initilize

import { Organizations } from 'shifter-sdk'

const client = new Organizations.Members({
  token: 'YOUR_TOKEN'
})

List site of organization

client.list('org_id')
  .then(result => console.log(result))

[
  {
    "username": "johndoe",
    "email": "hhoge@example.com",
    "user_status": "approval"
    "role": "owner"
  }
]

Add member to organization

client.add('org_id', 'hoge@example.com', 'username')
  .then(() => console.log('ok'))

ok

Remove members from organization

client.remove('org_id', ['username'])
  .then(() => console.log('ok'))

ok

Status

Initilize

import { Status } from 'shifter-sdk'

const client = new Status({
  token: 'YOUR_TOKEN'
})

Describe status

client.descibe()
  .then(result => console.log(result))

{ maintenance:
   { message:
      'XXXXXXXXXXXx',
     target: [ 'generator', 'container' ],
     status: 'not_maintenance' },
  user:
   { credit_card_status: 'registered',
     upper_limit_projects: '50',
     notification: { email: [Object] },
     group: { name: 'owner' },
     max_transfer_gb: '10240',
     max_disk_gb: '1024',
     domain_setting: 'true',
     import_archives: 'true',
     export_archives: 'true',
     backup: '365',
     enable_subuser: 'true',
     export_artifact: 'true' } }

Webhooks(Site)

Initilize

import { Webhooks } from 'shifter-sdk'

const client = new Webhooks.Site({
  token: 'YOUR_TOKEN'
})

Add new Webhook

const result = await client.create(siteId, [{
  hook_event: 'Webhook:Artifact:Created',
  url: 'https://hoge.example.com',
  enabled: false,
  headers: {},
  method: 'post'
}])
[
  {
    "enabled": false,
    "hook_event": "Webhook:Artifact:Created#d34c85ad-d50a-4efe-a52a-1023b30e37ed",
    "webhook_url": "https://hoge.example.com",
    "headers": {},
    "method": "post",
    "site_id": "bfd1fbde-8f01-11e8-aa52-9ad4a0753b52"
  }
]

Update Webhook

const result = await client.update(siteId, [{
  hook_event: 'Webhook:Artifact:Created#d34c85ad-d50a-4efe-a52a-1023b30e37ed',
  url: 'https://hoge.example.com',
  enabled: true,
  headers: { 'x-test': 'hoge' },
  method: 'post'
}])
[
  {
    "enabled": true,
    "hook_event": "Webhook:Artifact:Created#d34c85ad-d50a-4efe-a52a-1023b30e37ed",
    "webhook_url": "https://hoge.example.com",
    "headers": { 'x-test': 'hoge' },
    "method": "post",
    "site_id": "bfd1fbde-8f01-11e8-aa52-9ad4a0753b52"
  }
]

List Webhook

const result = await client.list(siteId)
[
  {
    "enabled": false,
    "hook_event": "Webhook:Artifact:Created#d34c85ad-d50a-4efe-a52a-1023b30e37ed",
    "webhook_url": "https://hoge.example.com",
    "headers": {},
    "method": "post",
    "site_id": "bfd1fbde-8f01-11e8-aa52-9ad4a0753b52"
  }
]

Delete Webhook

const result = await client.delete(siteId, [{
  hook_event: 'Webhook:Artifact:Created#d34c85ad-d50a-4efe-a52a-1023b30e37ed'
}])
""