Skip to content

Commit 0da5d80

Browse files
authored
Merge pull request #167 from flowcore-io/add-create-tenant-command
feat: add tenant creation command to manage tenant lifecycle
2 parents 478f179 + dad666c commit 0da5d80

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Tenant
22
export * from "./tenant/tenant.disable-sensitive-data.ts"
33
export * from "./tenant/tenant.enable-sensitive-data.ts"
4+
export * from "./tenant/tenant.create.ts"
45
export * from "./tenant/tenant.fetch.ts"
56
export * from "./tenant/tenant.list.ts"
67
export * from "./tenant/tenant.update.ts"
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Type } from "@sinclair/typebox"
2+
import { Command } from "../../common/command.ts"
3+
import { type Tenant, TenantSchema } from "../../contracts/tenant.ts"
4+
import { parseResponseHelper } from "../../utils/parse-response-helper.ts"
5+
6+
/**
7+
* The input for the tenant create command
8+
*/
9+
export interface TenantCreateInput {
10+
/** The tenant slug (already normalized, lowercase, URL-safe) */
11+
tenantSlug: string
12+
/** The description of the tenant */
13+
description?: string
14+
/** The display name of the tenant */
15+
displayName?: string
16+
}
17+
18+
/**
19+
* Response schema for the tenant create command
20+
*/
21+
const responseSchema = Type.Object({
22+
...TenantSchema.properties,
23+
dedicated: Type.Union([
24+
Type.Null(),
25+
Type.Object({
26+
// parse as string to avoid SDK failures if new statuses are added
27+
status: Type.String(),
28+
configuration: Type.Object({
29+
domain: Type.String(),
30+
configurationRepoUrl: Type.String(),
31+
configurationRepoCredentials: Type.String(),
32+
}),
33+
}),
34+
]),
35+
configured: Type.Boolean(),
36+
sensitiveDataEnabled: Type.Boolean(),
37+
})
38+
39+
/**
40+
* Create a tenant
41+
*/
42+
export class TenantCreateCommand extends Command<TenantCreateInput, Tenant> {
43+
/**
44+
* Whether the command should retry on failure
45+
*/
46+
protected override retryOnFailure: boolean = false
47+
48+
/**
49+
* Get the method
50+
*/
51+
protected override getMethod(): string {
52+
return "POST"
53+
}
54+
55+
/**
56+
* Get the base url
57+
*/
58+
protected override getBaseUrl(): string {
59+
return "https://tenant.api.flowcore.io"
60+
}
61+
62+
/**
63+
* Get the path
64+
*/
65+
protected override getPath(): string {
66+
return `/api/v1/tenants`
67+
}
68+
69+
/**
70+
* Get the body for the request
71+
*/
72+
protected override getBody(): Record<string, unknown> {
73+
const { tenantSlug, description, displayName } = this.input
74+
75+
return {
76+
tenant_slug: tenantSlug,
77+
...(description !== undefined && { description }),
78+
...(displayName !== undefined && { displayName }),
79+
}
80+
}
81+
82+
/**
83+
* Parse the response
84+
*/
85+
protected override parseResponse(rawResponse: unknown): Tenant {
86+
const response = parseResponseHelper(responseSchema, rawResponse)
87+
return response as Tenant
88+
}
89+
}

0 commit comments

Comments
 (0)