|
| 1 | +import { Type } from "@sinclair/typebox" |
| 2 | +import { Command } from "../../common/command.ts" |
| 3 | +import { parseResponseHelper } from "../../utils/parse-response-helper.ts" |
| 4 | +import type { Static, TBoolean, TObject, TString } from "@sinclair/typebox" |
| 5 | + |
| 6 | +/** |
| 7 | + * The input for inviting an existing user to a tenant |
| 8 | + */ |
| 9 | +export interface UserInviteToTenantInput { |
| 10 | + tenantName: string |
| 11 | + userEmail: string |
| 12 | +} |
| 13 | + |
| 14 | +/** |
| 15 | + * The output for inviting an existing user to a tenant |
| 16 | + */ |
| 17 | +export type UserInviteToTenantOutput = Static<typeof responseSchema> |
| 18 | + |
| 19 | +const responseSchema: TObject<{ |
| 20 | + success: TBoolean |
| 21 | + tenantName: TString |
| 22 | + invitedEmail: TString |
| 23 | +}> = Type.Object({ |
| 24 | + success: Type.Boolean(), |
| 25 | + tenantName: Type.String(), |
| 26 | + invitedEmail: Type.String(), |
| 27 | +}) |
| 28 | + |
| 29 | +/** |
| 30 | + * Invite an existing user (by email) to a tenant |
| 31 | + */ |
| 32 | +export class UserInviteToTenantCommand extends Command<UserInviteToTenantInput, UserInviteToTenantOutput> { |
| 33 | + /** |
| 34 | + * The allowed modes for the command |
| 35 | + */ |
| 36 | + protected override allowedModes: ("apiKey" | "bearer")[] = ["bearer"] |
| 37 | + |
| 38 | + /** |
| 39 | + * Get the base URL for the request |
| 40 | + */ |
| 41 | + protected override getBaseUrl(): string { |
| 42 | + return "https://user-2.api.flowcore.io" |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Get the method |
| 47 | + */ |
| 48 | + protected override getMethod(): string { |
| 49 | + return "POST" |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Get the path for the request |
| 54 | + */ |
| 55 | + protected override getPath(): string { |
| 56 | + return "/api/users/invitations" |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Get the body for the request |
| 61 | + */ |
| 62 | + protected override getBody(): Record<string, unknown> { |
| 63 | + return { |
| 64 | + tenantName: this.input.tenantName, |
| 65 | + userEmail: this.input.userEmail, |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Parse the response |
| 71 | + */ |
| 72 | + protected override parseResponse(rawResponse: unknown): UserInviteToTenantOutput { |
| 73 | + const response = parseResponseHelper(responseSchema, rawResponse) |
| 74 | + return response |
| 75 | + } |
| 76 | +} |
| 77 | +import { Type } from "@sinclair/typebox" |
| 78 | +import { Command } from "../../common/command.ts" |
| 79 | +import { parseResponseHelper } from "../../utils/parse-response-helper.ts" |
| 80 | +import type { Static, TBoolean, TObject, TString } from "@sinclair/typebox" |
| 81 | + |
| 82 | +/** |
| 83 | + * The input for inviting a user to a tenant |
| 84 | + */ |
| 85 | +export interface UserInviteToTenantInput { |
| 86 | + tenantName: string |
| 87 | + userEmail: string |
| 88 | +} |
| 89 | + |
| 90 | +/** |
| 91 | + * The output for inviting a user to a tenant |
| 92 | + */ |
| 93 | +export type UserInviteToTenantOutput = Static<typeof responseSchema> |
| 94 | + |
| 95 | +const responseSchema: TObject<{ |
| 96 | + success: TBoolean |
| 97 | + tenantName: TString |
| 98 | + invitedEmail: TString |
| 99 | +}> = Type.Object({ |
| 100 | + success: Type.Boolean(), |
| 101 | + tenantName: Type.String(), |
| 102 | + invitedEmail: Type.String(), |
| 103 | +}) |
| 104 | + |
| 105 | +/** |
| 106 | + * Invite an existing user (by email) to a tenant |
| 107 | + */ |
| 108 | +export class UserInviteToTenantCommand extends Command< |
| 109 | + UserInviteToTenantInput, |
| 110 | + UserInviteToTenantOutput |
| 111 | +> { |
| 112 | + /** |
| 113 | + * The allowed modes for the command |
| 114 | + */ |
| 115 | + protected override allowedModes: ("apiKey" | "bearer")[] = ["bearer"] |
| 116 | + |
| 117 | + /** |
| 118 | + * Get the base URL for the request |
| 119 | + */ |
| 120 | + protected override getBaseUrl(): string { |
| 121 | + return "https://user-2.api.flowcore.io" |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Get the method |
| 126 | + */ |
| 127 | + protected override getMethod(): string { |
| 128 | + return "POST" |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Get the path for the request |
| 133 | + */ |
| 134 | + protected override getPath(): string { |
| 135 | + return "/api/users/invitations" |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Parse the response |
| 140 | + */ |
| 141 | + protected override parseResponse(rawResponse: unknown): UserInviteToTenantOutput { |
| 142 | + const response = parseResponseHelper(responseSchema, rawResponse) |
| 143 | + return response |
| 144 | + } |
| 145 | +} |
0 commit comments