let read = require('./_read.cjs') let write = require('./_write.cjs') let deploy = require('./_deploy.cjs') /** @typedef {{token: string}} BaseParams */ /** @typedef {{appID: string}} UniqueApp */ module.exports = { /** * @description find an app by appID * @param {BaseParams & UniqueApp} options */ async find ({ token, appID, _staging }) { if (!appID) throw Error('missing_appID') return read({ token, appID, _staging }) }, /** * @description list apps * @param {BaseParams} options */ async list ({ token, _staging }) { return read({ token, _staging }) }, /** * @description list regions available to create a new app with * @param {BaseParams} options */ async regions ({ token, _staging }) { return read({ token, _staging, path: 'regions' }) }, /** * @description create an app * @param {BaseParams & {name: string, envName: string, region: string}} options */ async create ({ token, name, envName, region, _staging }) { return write({ token, _staging }, { envName, name, region }) }, /** * @description update app.name * @param {BaseParams & UniqueApp & {name: string}} options */ async update ({ token, appID, name, _staging }) { return write({ token, appID, _staging }, { name }) }, /** * @description destroy app and all environments * @param {BaseParams & UniqueApp} options */ async destroy ({ token, appID, _staging }) { return write({ token, appID, path: 'delete', _staging }) }, domains: { /** * @description list account domains * @param {BaseParams} options */ async list ({ token, _staging }) { return read({ token, _staging, scope: 'domains' }) }, /** * @description add an unmanaged domain * @param {BaseParams & {domain: string}} options */ async add ({ token, domain, _staging }) { if (!domain) throw Error('missing_domain') return write({ token, _staging, scope: 'domains' }, { domain }) }, /** * @description remove an unmanaged domain * @param {BaseParams & {domainID: string}} options */ async remove ({ token, domainID, _staging }) { if (!domainID) throw Error('missing_domainID') return write({ token, _staging, scope: 'domains', path: `${domainID}/delete` }) }, /** * @description check domain availability and retrieve purchase link * @param {BaseParams & {domain: string}} options */ async check ({ token, domain, _staging }) { if (!domain) throw Error('missing_domain') return read({ token, _staging, scope: 'domains', path: domain, }) }, /** * @description link a domain with an app environment * @param {BaseParams & UniqueApp & {domainID: string, envID: string}} options */ async link ({ token, appID, envID, domainID, _staging }) { if (!appID) throw Error('missing_appID') if (!envID) throw Error('missing_envID') if (!domainID) throw Error('missing_domainID') return write( { token, _staging, scope: 'domains', path: `${domainID}/link` }, { appID, envID }, ) }, /** * @description unlink a domain with an app environment * @param {BaseParams & {domainID: string, appID?: string, envID?: string}} options */ async unlink ({ token, domainID, appID, envID, _staging }) { if (!appID) throw Error('missing_appID') if (!envID) throw Error('missing_envID') if (!domainID) throw Error('missing_domainID') return write( { token, _staging, scope: 'domains', path: `${domainID}/unlink` }, { appID, envID }, ) }, /** * @description validate an external domain * repeat this operation until the domain is validated * @param {BaseParams & {domainID: string}} options * returns DNS validation records */ async validate ({ token, domainID, _staging }) { if (!domainID) throw Error('missing_domainID') return write({ token, _staging, scope: 'domains', path: `${domainID}/validate` }) }, records: { /** * @description list domain records * @param {BaseParams & {domainID: string}} options */ async list ({ token, domainID, _staging }) { if (!domainID) throw Error('missing_domainID') return read({ token, _staging, scope: 'domains', path: `${domainID}/records` }) }, /** * @description upsert domain record changes * @param {BaseParams & { * domainID: string, * changes: {name?: string, ttl: number, type?: string, values?: string[], value?: string}[] * }} options */ async upsert ({ token, domainID, changes, _staging }) { if (!domainID) throw Error('missing_domainID') if (!changes) throw Error('missing_changes') return write( { token, _staging, scope: 'domains', path: `${domainID}/records` }, { changes }, ) }, /** * @description remove domain record * @param {BaseParams & { * domainID: string, * record: {name?: string, ttl: number, type?: string, values?: string[], value?: string} * }} options * @todo simplify function signature for record to require less details from client */ async delete ({ token, domainID, record, _staging }) { if (!domainID) throw Error('missing_domainID') if (!record) throw Error('missing_record') return write( { token, _staging, scope: 'domains', path: `${domainID}/records/delete` }, { ...record }, ) }, }, }, env: { /** * @description add an environment * @param {BaseParams & UniqueApp & {name: string, envName: string}} options */ async add ({ token, appID, name, envName, region, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, _staging }, { envName, name, region }) }, /** * @description remove an environment * @param {BaseParams & UniqueApp & {envID: string}} options */ async remove ({ token, appID, envID, _staging }) { if (!appID) throw Error('missing_appID') if (!envID) throw Error('missing_envID') return write({ token, appID, envID, path: 'delete', _staging }) }, /** * @description deploy code to environment * @param {BaseParams & UniqueApp & {envID: string, dir: string, zip: string, verbose: boolean}} options */ async deploy ({ token, appID, envID, dir, zip, verbose, _staging }) { return deploy({ token, appID, envID, dir, zip, verbose, _staging }) }, /** * @description read environment runtime logs * @param {BaseParams & UniqueApp & {envID: string, query: unknown}} options */ async logs ({ token, appID, envID, query, _staging }) { return read({ token, appID, envID, query, path: 'logs', _staging }) }, /** * @description read a single build * @param {BaseParams & UniqueApp & {envID: string, buildID: string}} options */ async build ({ token, appID, envID, buildID, _staging }) { return read({ token, appID, envID, path: `builds/${buildID}`, _staging }) }, /** * @description read build logs * @param {BaseParams & UniqueApp & {envID: string}} options */ async builds ({ token, appID, envID, _staging }) { return read({ token, appID, envID, path: 'builds', _staging }) }, vars: { /** * @description upsert env vars * @param {BaseParams & UniqueApp & {envID: string, vars: unknown}} options */ async add ({ token, appID, envID, vars, _staging }) { return write({ token, appID, envID, path: 'vars', _staging }, { vars }) }, /** * @description remove env vars * @param {BaseParams & UniqueApp & {envID: string, vars: unknown}} options */ async remove ({ token, appID, envID, vars, _staging }) { return write({ token, appID, envID, path: 'vars/delete', _staging }, { vars }) } } }, team: { /** * @description list an app's teammates * @param {BaseParams & UniqueApp} options */ async list ({ token, appID, _staging }) { if (!appID) throw Error('missing_appID') return read({ token, appID, path: 'team', _staging }) }, /** * @description generate a new invite code * @param {BaseParams & UniqueApp & {role?: string}} options */ async invite ({ token, appID, role, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, path: 'team', _staging }, { role }) }, /** * @description revoke an app invite * @param {BaseParams & UniqueApp & {inviteID: string}} options */ async revoke ({ token, appID, inviteID, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, path: 'team/revoke', _staging }, { inviteID }) }, /** * @description remove a teammate from an app * @param {BaseParams & UniqueApp & {accountID: string}} options */ async remove ({ token, appID, accountID, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, path: 'team/delete', _staging }, { accountID }) }, /** * @description assign a new role to a teammate; must be either `admin` or `collaborator` * @param {BaseParams & UniqueApp & {accountID: string, role: string}} options */ async role ({ token, appID, accountID, role, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, path: 'team/role', _staging }, { accountID, role }) }, /** * @description accept an app invite code * @param {BaseParams & UniqueApp & {inviteID: string}} options */ async accept ({ token, appID, inviteID, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, path: 'team/accept', _staging }, { inviteID }) }, /** * @description decline an app invite code * @param {BaseParams & UniqueApp & {inviteID: string}} options */ async decline ({ token, appID, inviteID, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, path: 'team/decline', _staging }, { inviteID }) }, /** * @description leave an app * @param {BaseParams & UniqueApp} options */ async leave ({ token, appID, _staging }) { if (!appID) throw Error('missing_appID') return write({ token, appID, path: 'team/leave', _staging }) }, }, tokens: { /** * list an account's tokens * @param {BaseParams} options */ async list ({ token, _staging }) { return read({ token, scope: 'tokens', _staging }) }, /** * generate a new token * @param {BaseParams & {tokenType?: string}} options */ async create ({ token, _staging, tokenType = 'personal_access', ttl }) { return write({ token, scope: 'tokens', _staging }, { tokenType, ttl }) }, /** * revoke a token * @param {BaseParams & {tokenID: string}} options */ async revoke ({ token, appID, tokenID, _staging }) { return write({ token, appID, scope: 'tokens', path: `${tokenID}/delete`, _staging }) }, }, }