From 8881273143da3c478217ccd2b4da75c628df1b6e Mon Sep 17 00:00:00 2001 From: Cody Miller Date: Sat, 30 Sep 2023 00:58:49 -0400 Subject: [PATCH 1/6] feat: create and edit deployment groups through SDK --- src/rest/types/ignite.ts | 48 ++++++++++++++++++++++++++++++++- src/sdks/ignite.ts | 57 ++++++++++++++++++++++++++++++++++++++-- src/util/types.ts | 4 +++ 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/rest/types/ignite.ts b/src/rest/types/ignite.ts index d71cebae..4fca7947 100644 --- a/src/rest/types/ignite.ts +++ b/src/rest/types/ignite.ts @@ -291,6 +291,11 @@ export interface Deployment { * Build settings for deployment */ build_settings?: BuildSettings; + + /** + * The group the deployment belongs in + */ + group_id: Id<'deployment_group'> | null; } /** @@ -546,6 +551,29 @@ export type HealthCheck = { created_at: Timestamp; }; +export type Group = { + /** + * The ID of the group + */ + id: Id<'deployment_group'>; + /** + * The name of the group + */ + name: string; + /** + * The ID of the project the group belongs to + */ + project_id: Id<'project'>; + /** + * The position of the group in the list + */ + position: number; + /** + * The date the group was created + */ + created_at: Timestamp; +}; + /** * A deployment rollout * @public @@ -1084,4 +1112,22 @@ export type IgniteEndpoints = Partial> > | Endpoint<'DELETE', '/v1/ignite/domains/:domain_id', Empty> - | Endpoint<'GET', '/v1/ignite/domains/:domain_id', {domain: Domain}>; + | Endpoint<'GET', '/v1/ignite/domains/:domain_id', {domain: Domain}> + | Endpoint< + 'POST', + '/v1/ignite/groups', + {group: Group}, + { + name: string; + deployment_ids: Id<'deployment'>[]; + } + > + | Endpoint< + 'PATCH', + '/v1/ignite/groups/:group_id', + {group: Group}, + { + name?: string | undefined; + position?: number | undefined; + } + >; diff --git a/src/sdks/ignite.ts b/src/sdks/ignite.ts index b3bd16bb..8db03e07 100644 --- a/src/sdks/ignite.ts +++ b/src/sdks/ignite.ts @@ -255,7 +255,7 @@ export const ignite = sdk(client => { const deploymentGateways = { /** - * Fecthes all gateways attached to a deployment + * Fetches all gateways attached to a deployment * * @param deploymentId - The ID of the deployment to fetch gateways for */ @@ -272,7 +272,7 @@ export const ignite = sdk(client => { * Creates and attaches a gateway to a deployment * * @param deployment - The deployment to create a gateway on - * @param type - The type of the gatway to create, either internal or external + * @param type - The type of the gateway to create, either internal or external * @param protocol - The protocol that the gateway will listen for * @param targetPort - The port to listen on */ @@ -315,7 +315,60 @@ export const ignite = sdk(client => { }, }; + const groups = { + async create( + name: string, + deploymentIds?: Id<'deployment'>[] | undefined, + projectId?: Id<'project'>, + ) { + if (client.authType !== 'ptk' && !projectId) { + throw new Error( + 'Project ID is required for Bearer or PAT authentication', + ); + } + + const {group} = await client.post( + '/v1/ignite/groups', + { + name, + deployment_ids: deploymentIds ?? [], + }, + projectId ? {project: projectId} : {}, + ); + + return group; + }, + + async edit( + groupId: Id<'deployment_group'>, + { + name, + position, + }: {name?: string | undefined; position?: number | undefined}, + projectId?: Id<'project'>, + ) { + if (client.authType !== 'ptk' && !projectId) { + throw new Error( + 'Project ID is required for Bearer or PAT authentication', + ); + } + + const {group} = await client.patch( + '/v1/ignite/groups/:group_id', + { + name, + position, + }, + {group_id: groupId, ...(projectId ? {project: projectId} : {})}, + ); + + return group; + }, + }; + const igniteSDK = { + groups, + domains: { delete: async (id: Id<'domain'>) => { await client.delete('/v1/ignite/domains/:domain_id', undefined, { diff --git a/src/util/types.ts b/src/util/types.ts index 6269e5fe..34c3a384 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -141,6 +141,10 @@ export const ID_PREFIXES = [ prefix: 'webhook', description: 'Webhook ID for webhooks on a project.', }, + { + prefix: 'deployment_group', + description: 'Group ID for Ignite deployments', + }, ] as const; /** From 2ad7b362c5456a1ce90dd3f3565fb9baa159046e Mon Sep 17 00:00:00 2001 From: Cody Miller Date: Sun, 1 Oct 2023 15:55:07 -0400 Subject: [PATCH 2/6] feat: add groups to deployments request + PUT and DELETE request --- src/rest/types/ignite.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rest/types/ignite.ts b/src/rest/types/ignite.ts index 4fca7947..e1d24076 100644 --- a/src/rest/types/ignite.ts +++ b/src/rest/types/ignite.ts @@ -990,7 +990,11 @@ export interface DomainRedirect { * @public */ export type IgniteEndpoints = - | Endpoint<'GET', '/v1/ignite/deployments', {deployments: Deployment[]}> + | Endpoint< + 'GET', + '/v1/ignite/deployments', + {deployments: Deployment[]; groups: Group[]} + > | Endpoint< 'GET', '/v1/ignite/deployments/:deployment_id/containers', @@ -1130,4 +1134,10 @@ export type IgniteEndpoints = name?: string | undefined; position?: number | undefined; } - >; + > + | Endpoint< + 'PUT', + '/v1/ignite/groups/:group_id/deployments/:deployment_id', + {group: Group} + > + | Endpoint<'DELETE', '/v1/ignite/groups/:group_id', Empty>; From f6cd8c31de40b59cf0016a627c25372d78be42b7 Mon Sep 17 00:00:00 2001 From: Cody Miller Date: Sun, 1 Oct 2023 15:55:23 -0400 Subject: [PATCH 3/6] feat: add move and delete requests to group SDK --- src/sdks/ignite.ts | 58 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/src/sdks/ignite.ts b/src/sdks/ignite.ts index 8db03e07..87afcf16 100644 --- a/src/sdks/ignite.ts +++ b/src/sdks/ignite.ts @@ -7,6 +7,7 @@ import { type DeploymentConfig, type DeploymentMetadata, type Gateway, + type Group, } from '../rest/types/ignite.ts'; import {parseSize, validateId} from '../util/index.ts'; import {sdk} from './create.ts'; @@ -327,7 +328,7 @@ export const ignite = sdk(client => { ); } - const {group} = await client.post( + return await client.post( '/v1/ignite/groups', { name, @@ -335,8 +336,6 @@ export const ignite = sdk(client => { }, projectId ? {project: projectId} : {}, ); - - return group; }, async edit( @@ -353,7 +352,7 @@ export const ignite = sdk(client => { ); } - const {group} = await client.patch( + return await client.patch( '/v1/ignite/groups/:group_id', { name, @@ -361,8 +360,41 @@ export const ignite = sdk(client => { }, {group_id: groupId, ...(projectId ? {project: projectId} : {})}, ); + }, + + async move( + deploymentId: Id<'deployment'>, + groupId: Id<'deployment_group'>, + projectId?: Id<'project'>, + ) { + if (client.authType !== 'ptk' && !projectId) { + throw new Error( + 'Project ID is required for Bearer or PAT authentication', + ); + } - return group; + return await client.put( + '/v1/ignite/groups/:group_id/deployments/:deployment_id', + undefined, + { + group_id: groupId, + deployment_id: deploymentId, + ...(projectId ? {project: projectId} : {}), + }, + ); + }, + + async delete(groupId: Id<'deployment_group'>, projectId?: Id<'project'>) { + if (client.authType !== 'ptk' && !projectId) { + throw new Error( + 'Project ID is required for Bearer or PAT authentication', + ); + } + + await client.delete('/v1/ignite/groups/:group_id', undefined, { + group_id: groupId, + ...(projectId ? {project: projectId} : {}), + }); }, }; @@ -509,12 +541,24 @@ export const ignite = sdk(client => { ); } - const {deployments} = await client.get( + const {deployments, groups} = await client.get( '/v1/ignite/deployments', projectId ? {project: projectId} : {}, ); - return deployments.map(Deployments.from); + const groupRecord = groups.reduce((acc, group) => { + acc[group.id] = group; + return acc; + }, {} as Record); + + return deployments + .map(deployment => ({ + ...deployment, + group: deployment.group_id + ? groupRecord[deployment.group_id] + : null, + })) + .map(Deployments.from); }, /** From e34ef0640e309b796b900312748ccc237ecd27c3 Mon Sep 17 00:00:00 2001 From: Cody Miller Date: Mon, 2 Oct 2023 00:39:05 -0400 Subject: [PATCH 4/6] fix: return --- src/sdks/ignite.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sdks/ignite.ts b/src/sdks/ignite.ts index 87afcf16..c1ca0e34 100644 --- a/src/sdks/ignite.ts +++ b/src/sdks/ignite.ts @@ -328,7 +328,7 @@ export const ignite = sdk(client => { ); } - return await client.post( + const {group} = await client.post( '/v1/ignite/groups', { name, @@ -336,6 +336,8 @@ export const ignite = sdk(client => { }, projectId ? {project: projectId} : {}, ); + + return group; }, async edit( @@ -352,7 +354,7 @@ export const ignite = sdk(client => { ); } - return await client.patch( + const {group} = await client.patch( '/v1/ignite/groups/:group_id', { name, @@ -360,6 +362,8 @@ export const ignite = sdk(client => { }, {group_id: groupId, ...(projectId ? {project: projectId} : {})}, ); + + return group; }, async move( @@ -373,7 +377,7 @@ export const ignite = sdk(client => { ); } - return await client.put( + const {group} = await client.put( '/v1/ignite/groups/:group_id/deployments/:deployment_id', undefined, { @@ -382,6 +386,8 @@ export const ignite = sdk(client => { ...(projectId ? {project: projectId} : {}), }, ); + + return group; }, async delete(groupId: Id<'deployment_group'>, projectId?: Id<'project'>) { From 40d346ad488d94dda32dd512207b01be8fff5d49 Mon Sep 17 00:00:00 2001 From: Cody Miller Date: Mon, 2 Oct 2023 19:15:21 -0400 Subject: [PATCH 5/6] docs(changeset): Adds new deployment group SDKs and new types --- .changeset/tame-actors-care.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tame-actors-care.md diff --git a/.changeset/tame-actors-care.md b/.changeset/tame-actors-care.md new file mode 100644 index 00000000..1244908b --- /dev/null +++ b/.changeset/tame-actors-care.md @@ -0,0 +1,5 @@ +--- +'@onehop/js': minor +--- + +Adds new deployment group SDKs and new types From a508e89c2b112465cfa80b2a64ddd9e527b5faba Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 2 Oct 2023 23:16:55 +0000 Subject: [PATCH 6/6] Bump version --- .changeset/tame-actors-care.md | 5 ----- CHANGELOG.md | 6 ++++++ package.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 .changeset/tame-actors-care.md diff --git a/.changeset/tame-actors-care.md b/.changeset/tame-actors-care.md deleted file mode 100644 index 1244908b..00000000 --- a/.changeset/tame-actors-care.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@onehop/js': minor ---- - -Adds new deployment group SDKs and new types diff --git a/CHANGELOG.md b/CHANGELOG.md index 946fb6ce..b665c37b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @onehop/js +## 1.39.0 + +### Minor Changes + +- 40d346a: Adds new deployment group SDKs and new types + ## 1.38.0 ### Minor Changes diff --git a/package.json b/package.json index ddca4f50..7fbb80ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onehop/js", - "version": "1.38.0", + "version": "1.39.0", "type": "module", "main": "./dist/index.cjs", "module": "./dist/index.js",