@reopt-ai/brandapp-sdk 4.5.0-platform.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +1 -0
- package/dist/ai/index.js +1 -1
- package/dist/ai-provider/index.js +1 -1
- package/dist/analytics/index.js +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/better-auth/index.d.ts +2 -7
- package/dist/better-auth/index.js +2 -3
- package/dist/{client-BwgCbfXv.js → client-BzAgabAs.js} +2 -2
- package/dist/{client-B0XUjOuP.js → client-C2xE9HGZ.js} +4 -4
- package/dist/{client-Cv1bdMBf.js → client-CI2Y00Qx.js} +2 -2
- package/dist/{client-BNht520A.js → client-Ce0gs5Ma.js} +2 -2
- package/dist/{client-CKi1NpMR.js → client-DCqp0Bis.js} +2 -2
- package/dist/{client-B270eCrs.js → client-DeC127BD.js} +2 -2
- package/dist/{client-C2ALt685.js → client-DjLhTNsZ.js} +3 -3
- package/dist/{client-BIMl52kc.js → client-FM6_YJbr.js} +3 -3
- package/dist/{client-WxPjMNy_.js → client-eDd4aWDs.js} +2 -2
- package/dist/{client-DNzgX_md.js → client-tJq0U_jn.js} +4 -4
- package/dist/cms/index.js +1 -1
- package/dist/{config-DkT0F-GG.js → config-BeOelISH.js} +2 -2
- package/dist/eav/index.js +2 -2
- package/dist/feedback/index.js +1 -1
- package/dist/files/index.js +1 -1
- package/dist/{http-client-BO5A5n4I.js → http-client-Bl8u1vHN.js} +2 -2
- package/dist/index.js +12 -12
- package/dist/logout/index.js +1 -1
- package/dist/plans/index.js +1 -1
- package/dist/push/index.js +1 -1
- package/dist/{query-D08B_HFt.js → query-JPVK_8N5.js} +2 -2
- package/dist/terms/index.js +1 -1
- package/dist/workspace/index.d.ts +372 -1
- package/dist/workspace/index.js +362 -3
- package/docs/api-reference.md +4 -0
- package/docs/workspace.md +141 -0
- package/package.json +4 -4
package/dist/workspace/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as SDK_VERSION } from "../config-
|
|
1
|
+
import { n as SDK_VERSION } from "../config-BeOelISH.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/workspace/schemas.ts
|
|
@@ -29,6 +29,12 @@ const platformTaskStageSchema = z.object({
|
|
|
29
29
|
outcome: z.enum(PLATFORM_TASK_OUTCOMES).nullable().optional(),
|
|
30
30
|
stageId: z.uuid().optional()
|
|
31
31
|
}).strict().refine(exactlyOneOf, "stage needs exactly one of outcome or stageId");
|
|
32
|
+
const platformCustomerUpsertInputSchema = z.object({
|
|
33
|
+
version: versionSchema.optional(),
|
|
34
|
+
name: z.string().trim().min(1).max(255),
|
|
35
|
+
email: z.email().max(255).nullable().optional(),
|
|
36
|
+
attributes: z.record(z.string().min(1).max(64), z.unknown()).optional()
|
|
37
|
+
}).strict();
|
|
32
38
|
const platformTaskUpsertInputSchema = z.object({
|
|
33
39
|
version: versionSchema,
|
|
34
40
|
title: z.string().trim().min(1).max(255),
|
|
@@ -49,7 +55,8 @@ const platformTaskStageInputSchema = z.object({
|
|
|
49
55
|
const platformWebhookUpsertInputSchema = z.object({
|
|
50
56
|
url: z.url().max(2e3),
|
|
51
57
|
triggers: z.array(z.enum(PLATFORM_WEBHOOK_TRIGGERS)).min(1),
|
|
52
|
-
secret: z.string().min(16).max(1024).optional()
|
|
58
|
+
secret: z.string().min(16).max(1024).optional(),
|
|
59
|
+
managedBy: z.literal("code").nullable().optional()
|
|
53
60
|
}).strict();
|
|
54
61
|
const outcomeSchema = z.enum(PLATFORM_TASK_OUTCOMES).nullable();
|
|
55
62
|
const platformTaskSchema = z.object({
|
|
@@ -138,6 +145,286 @@ const platformWorkTaskStageChangedEventSchema = z.object({
|
|
|
138
145
|
label: z.string().nullable()
|
|
139
146
|
}))
|
|
140
147
|
});
|
|
148
|
+
const PLATFORM_ADMIN_SCOPE = "workspace:admin";
|
|
149
|
+
const PLATFORM_MANAGED_BY_VALUES = ["code"];
|
|
150
|
+
/** 단계 색 어휘 — `packages/studio-ui/composites/stage-colors.ts` STAGE_COLORS와 같은 집합(apps/web 파리티 테스트가 고정) */
|
|
151
|
+
const PLATFORM_STAGE_COLORS = [
|
|
152
|
+
"slate",
|
|
153
|
+
"gray",
|
|
154
|
+
"red",
|
|
155
|
+
"rose",
|
|
156
|
+
"orange",
|
|
157
|
+
"amber",
|
|
158
|
+
"yellow",
|
|
159
|
+
"lime",
|
|
160
|
+
"green",
|
|
161
|
+
"emerald",
|
|
162
|
+
"teal",
|
|
163
|
+
"cyan",
|
|
164
|
+
"sky",
|
|
165
|
+
"blue",
|
|
166
|
+
"indigo",
|
|
167
|
+
"violet",
|
|
168
|
+
"purple",
|
|
169
|
+
"pink"
|
|
170
|
+
];
|
|
171
|
+
/** `/^[a-z0-9][a-z0-9-]{0,59}$/` — 선언 파일의 키이자 URL 경로 세그먼트 */
|
|
172
|
+
const platformResourceKeySchema = z.string().regex(/^[a-z0-9][a-z0-9-]{0,59}$/, "key must be lowercase letters, digits or '-' (≤60, must start with a letter or digit)");
|
|
173
|
+
const stageColorSchema = z.enum(PLATFORM_STAGE_COLORS);
|
|
174
|
+
const platformPipelineStageInputSchema = z.object({
|
|
175
|
+
key: platformResourceKeySchema,
|
|
176
|
+
label: z.string().trim().min(1).max(80),
|
|
177
|
+
color: stageColorSchema.optional(),
|
|
178
|
+
isEntry: z.boolean().optional(),
|
|
179
|
+
outcome: z.enum(PLATFORM_TASK_OUTCOMES).nullable().optional()
|
|
180
|
+
}).strict();
|
|
181
|
+
const platformPipelineUpsertInputSchema = z.object({
|
|
182
|
+
name: z.string().trim().min(1).max(120),
|
|
183
|
+
description: z.string().trim().max(500).nullable().optional(),
|
|
184
|
+
isDefault: z.boolean().optional(),
|
|
185
|
+
stages: z.array(platformPipelineStageInputSchema).min(1).max(50),
|
|
186
|
+
allowDestructive: z.boolean().optional()
|
|
187
|
+
}).strict().refine((value) => new Set(value.stages.map((stage) => stage.key)).size === value.stages.length, "stage keys must be unique within a pipeline").refine((value) => value.stages.filter((stage) => stage.isEntry === true).length === 1, "exactly one stage must have isEntry: true");
|
|
188
|
+
const platformPipelineImportInputSchema = z.object({ pipelineId: z.uuid() }).strict();
|
|
189
|
+
const managedBySchema = z.enum(PLATFORM_MANAGED_BY_VALUES).nullable();
|
|
190
|
+
const platformPipelineResourceSchema = z.object({
|
|
191
|
+
id: z.string(),
|
|
192
|
+
key: z.string().nullable(),
|
|
193
|
+
name: z.string(),
|
|
194
|
+
description: z.string().nullable(),
|
|
195
|
+
isDefault: z.boolean(),
|
|
196
|
+
isArchived: z.boolean(),
|
|
197
|
+
order: z.number(),
|
|
198
|
+
managedBy: managedBySchema,
|
|
199
|
+
taskCount: z.number(),
|
|
200
|
+
stages: z.array(z.object({
|
|
201
|
+
id: z.string(),
|
|
202
|
+
key: z.string(),
|
|
203
|
+
label: z.string(),
|
|
204
|
+
color: z.string(),
|
|
205
|
+
order: z.number(),
|
|
206
|
+
isEntry: z.boolean(),
|
|
207
|
+
outcome: outcomeSchema,
|
|
208
|
+
taskCount: z.number()
|
|
209
|
+
}))
|
|
210
|
+
});
|
|
211
|
+
const platformWebhookResourceSchema = z.object({
|
|
212
|
+
id: z.string(),
|
|
213
|
+
url: z.string(),
|
|
214
|
+
triggers: z.array(z.string()),
|
|
215
|
+
hasSecret: z.boolean(),
|
|
216
|
+
managedBy: managedBySchema
|
|
217
|
+
});
|
|
218
|
+
const platformResourcesSchema = z.object({
|
|
219
|
+
workspaceId: z.string(),
|
|
220
|
+
pipelines: z.array(platformPipelineResourceSchema),
|
|
221
|
+
webhooks: z.array(platformWebhookResourceSchema)
|
|
222
|
+
});
|
|
223
|
+
const platformLockAcquiredSchema = z.object({
|
|
224
|
+
acquired: z.literal(true),
|
|
225
|
+
expiresAt: z.string()
|
|
226
|
+
});
|
|
227
|
+
const platformLockReleasedSchema = z.object({ released: z.boolean() });
|
|
228
|
+
const PLATFORM_DOMAIN_STATUSES = [
|
|
229
|
+
"active",
|
|
230
|
+
"inactive",
|
|
231
|
+
"pending",
|
|
232
|
+
"suspended"
|
|
233
|
+
];
|
|
234
|
+
const PLATFORM_BRANDAPP_STATUSES = [
|
|
235
|
+
"draft",
|
|
236
|
+
"active",
|
|
237
|
+
"suspended",
|
|
238
|
+
"archived"
|
|
239
|
+
];
|
|
240
|
+
const PLATFORM_TOKEN_ENDPOINT_AUTH_METHODS = [
|
|
241
|
+
"client_secret_post",
|
|
242
|
+
"client_secret_basic",
|
|
243
|
+
"none"
|
|
244
|
+
];
|
|
245
|
+
const PLATFORM_OAUTH_GRANT_TYPES = [
|
|
246
|
+
"authorization_code",
|
|
247
|
+
"refresh_token",
|
|
248
|
+
"client_credentials"
|
|
249
|
+
];
|
|
250
|
+
const PLATFORM_OAUTH_APPLICATION_TYPES = ["web", "native"];
|
|
251
|
+
const domainStatusSchema = z.enum(PLATFORM_DOMAIN_STATUSES);
|
|
252
|
+
const hostnameSchema = z.string().trim().min(1).max(255).regex(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/, "domain must be a bare hostname");
|
|
253
|
+
const platformBrandUpsertInputSchema = z.object({
|
|
254
|
+
name: z.string().trim().min(1).max(255),
|
|
255
|
+
logo: z.url().max(2048).nullable().optional(),
|
|
256
|
+
description: z.string().trim().max(280).nullable().optional(),
|
|
257
|
+
isSystemBrand: z.boolean().optional(),
|
|
258
|
+
domain: hostnameSchema.optional()
|
|
259
|
+
}).strict();
|
|
260
|
+
const platformBrandImportInputSchema = z.object({ brandId: z.uuid() }).strict();
|
|
261
|
+
const platformBrandResourceSchema = z.object({
|
|
262
|
+
id: z.string(),
|
|
263
|
+
key: z.string().nullable(),
|
|
264
|
+
name: z.string(),
|
|
265
|
+
logo: z.string().nullable(),
|
|
266
|
+
description: z.string().nullable(),
|
|
267
|
+
isSystemBrand: z.boolean(),
|
|
268
|
+
managedBy: managedBySchema,
|
|
269
|
+
domains: z.array(z.object({
|
|
270
|
+
id: z.string(),
|
|
271
|
+
domain: z.string(),
|
|
272
|
+
isPrimary: z.boolean(),
|
|
273
|
+
status: domainStatusSchema
|
|
274
|
+
})),
|
|
275
|
+
brandappSlug: z.string().nullable()
|
|
276
|
+
});
|
|
277
|
+
const platformBrandappUpsertInputSchema = z.object({
|
|
278
|
+
name: z.string().trim().min(1).max(100),
|
|
279
|
+
brand: platformResourceKeySchema,
|
|
280
|
+
description: z.string().trim().max(500).nullable().optional(),
|
|
281
|
+
logo: z.url().max(2048).nullable().optional(),
|
|
282
|
+
aiEnabled: z.boolean().optional(),
|
|
283
|
+
isSystemBrandapp: z.boolean().optional(),
|
|
284
|
+
settings: z.record(z.string(), z.unknown()).optional()
|
|
285
|
+
}).strict();
|
|
286
|
+
const platformBrandappResourceSchema = z.object({
|
|
287
|
+
id: z.string(),
|
|
288
|
+
slug: z.string(),
|
|
289
|
+
name: z.string(),
|
|
290
|
+
description: z.string().nullable(),
|
|
291
|
+
logo: z.string().nullable(),
|
|
292
|
+
status: z.string(),
|
|
293
|
+
aiEnabled: z.boolean(),
|
|
294
|
+
isSystemBrandapp: z.boolean(),
|
|
295
|
+
brandId: z.string(),
|
|
296
|
+
brandKey: z.string().nullable(),
|
|
297
|
+
domainId: z.string().nullable(),
|
|
298
|
+
settings: z.record(z.string(), z.unknown()).nullable(),
|
|
299
|
+
managedBy: managedBySchema
|
|
300
|
+
});
|
|
301
|
+
const platformOAuthClientUpsertInputSchema = z.object({
|
|
302
|
+
brandapp: platformResourceKeySchema,
|
|
303
|
+
name: z.string().trim().min(1).max(255).optional(),
|
|
304
|
+
scopes: z.array(z.string().trim().min(1).max(64)).min(1).max(32),
|
|
305
|
+
grantTypes: z.array(z.enum(PLATFORM_OAUTH_GRANT_TYPES)).min(1),
|
|
306
|
+
redirectUris: z.array(z.url().max(500)).max(32).optional(),
|
|
307
|
+
postLogoutRedirectUris: z.array(z.url().max(500)).max(32).optional(),
|
|
308
|
+
tokenEndpointAuthMethod: z.enum(PLATFORM_TOKEN_ENDPOINT_AUTH_METHODS).optional(),
|
|
309
|
+
requirePKCE: z.boolean().optional(),
|
|
310
|
+
skipConsent: z.boolean().optional(),
|
|
311
|
+
enableEndSession: z.boolean().optional(),
|
|
312
|
+
applicationType: z.enum(PLATFORM_OAUTH_APPLICATION_TYPES).optional(),
|
|
313
|
+
disabled: z.boolean().optional()
|
|
314
|
+
}).strict().refine((value) => !value.grantTypes.includes("authorization_code") || (value.redirectUris?.length ?? 0) > 0, "authorization_code requires at least one redirectUri");
|
|
315
|
+
const platformOAuthClientImportInputSchema = z.object({ clientId: z.string().min(8).max(255) }).strict();
|
|
316
|
+
const platformOAuthClientResourceSchema = z.object({
|
|
317
|
+
id: z.string(),
|
|
318
|
+
key: z.string().nullable(),
|
|
319
|
+
clientId: z.string(),
|
|
320
|
+
name: z.string().nullable(),
|
|
321
|
+
brandappSlug: z.string().nullable(),
|
|
322
|
+
disabled: z.boolean(),
|
|
323
|
+
scopes: z.array(z.string()),
|
|
324
|
+
clientCredentialsScopes: z.array(z.string()),
|
|
325
|
+
grantTypes: z.array(z.string()),
|
|
326
|
+
redirectUris: z.array(z.string()),
|
|
327
|
+
postLogoutRedirectUris: z.array(z.string()),
|
|
328
|
+
tokenEndpointAuthMethod: z.string().nullable(),
|
|
329
|
+
requirePKCE: z.boolean(),
|
|
330
|
+
skipConsent: z.boolean(),
|
|
331
|
+
enableEndSession: z.boolean(),
|
|
332
|
+
applicationType: z.string().nullable(),
|
|
333
|
+
hasSecret: z.boolean(),
|
|
334
|
+
managedBy: managedBySchema,
|
|
335
|
+
clientSecret: z.string().optional()
|
|
336
|
+
});
|
|
337
|
+
const eavAttributeResourceSchema = z.object({
|
|
338
|
+
id: z.string(),
|
|
339
|
+
name: z.string(),
|
|
340
|
+
label: z.string(),
|
|
341
|
+
dataType: z.string(),
|
|
342
|
+
isRequired: z.boolean(),
|
|
343
|
+
isUnique: z.boolean(),
|
|
344
|
+
defaultValue: z.string().nullable(),
|
|
345
|
+
validation: z.unknown(),
|
|
346
|
+
options: z.unknown(),
|
|
347
|
+
sortOrder: z.number()
|
|
348
|
+
});
|
|
349
|
+
const platformEavEntityResourceSchema = z.object({
|
|
350
|
+
id: z.string(),
|
|
351
|
+
name: z.string(),
|
|
352
|
+
description: z.string().nullable(),
|
|
353
|
+
icon: z.string().nullable(),
|
|
354
|
+
linkedTo: z.string(),
|
|
355
|
+
attributes: z.array(eavAttributeResourceSchema),
|
|
356
|
+
recordCount: z.number()
|
|
357
|
+
});
|
|
358
|
+
const platformEavBrandappResourcesSchema = z.object({
|
|
359
|
+
brandappId: z.string(),
|
|
360
|
+
brandappSlug: z.string(),
|
|
361
|
+
entities: z.array(platformEavEntityResourceSchema)
|
|
362
|
+
});
|
|
363
|
+
const eavName = z.string().trim().min(1).max(100);
|
|
364
|
+
const platformEavSchemaOperationSchema = z.discriminatedUnion("kind", [
|
|
365
|
+
z.object({
|
|
366
|
+
kind: z.literal("addEntity"),
|
|
367
|
+
name: eavName,
|
|
368
|
+
def: z.object({
|
|
369
|
+
description: z.string().max(500).nullable().optional(),
|
|
370
|
+
icon: z.string().max(10).nullable().optional(),
|
|
371
|
+
linkedTo: z.enum(["brandapp", "brandappAuthUser"]).optional()
|
|
372
|
+
}).optional()
|
|
373
|
+
}).strict(),
|
|
374
|
+
z.object({
|
|
375
|
+
kind: z.literal("updateEntity"),
|
|
376
|
+
name: eavName,
|
|
377
|
+
changes: z.object({
|
|
378
|
+
description: z.string().max(500).nullable().optional(),
|
|
379
|
+
icon: z.string().max(10).nullable().optional()
|
|
380
|
+
}).strict()
|
|
381
|
+
}).strict(),
|
|
382
|
+
z.object({
|
|
383
|
+
kind: z.literal("removeEntity"),
|
|
384
|
+
name: eavName
|
|
385
|
+
}).strict(),
|
|
386
|
+
z.object({
|
|
387
|
+
kind: z.literal("addAttribute"),
|
|
388
|
+
entity: eavName,
|
|
389
|
+
name: eavName,
|
|
390
|
+
def: z.record(z.string(), z.unknown())
|
|
391
|
+
}).strict(),
|
|
392
|
+
z.object({
|
|
393
|
+
kind: z.literal("updateAttribute"),
|
|
394
|
+
entity: eavName,
|
|
395
|
+
name: eavName,
|
|
396
|
+
changes: z.record(z.string(), z.unknown())
|
|
397
|
+
}).strict(),
|
|
398
|
+
z.object({
|
|
399
|
+
kind: z.literal("removeAttribute"),
|
|
400
|
+
entity: eavName,
|
|
401
|
+
name: eavName
|
|
402
|
+
}).strict(),
|
|
403
|
+
z.object({
|
|
404
|
+
kind: z.literal("renameAttribute"),
|
|
405
|
+
entity: eavName,
|
|
406
|
+
oldName: eavName,
|
|
407
|
+
newName: eavName
|
|
408
|
+
}).strict()
|
|
409
|
+
]);
|
|
410
|
+
const platformEavSchemaApplyInputSchema = z.object({
|
|
411
|
+
brandapp: platformResourceKeySchema.optional(),
|
|
412
|
+
operations: z.array(platformEavSchemaOperationSchema).max(1e3),
|
|
413
|
+
allowDestructive: z.boolean().optional()
|
|
414
|
+
}).strict();
|
|
415
|
+
const platformEavSchemaApplyResultSchema = z.object({
|
|
416
|
+
applied: z.number(),
|
|
417
|
+
entities: z.array(platformEavEntityResourceSchema)
|
|
418
|
+
});
|
|
419
|
+
const platformResourcesV2Schema = z.object({
|
|
420
|
+
workspaceId: z.string(),
|
|
421
|
+
pipelines: z.array(platformPipelineResourceSchema),
|
|
422
|
+
webhooks: z.array(platformWebhookResourceSchema),
|
|
423
|
+
brands: z.array(platformBrandResourceSchema),
|
|
424
|
+
brandapps: z.array(platformBrandappResourceSchema),
|
|
425
|
+
oauthClients: z.array(platformOAuthClientResourceSchema),
|
|
426
|
+
eav: z.array(platformEavBrandappResourcesSchema)
|
|
427
|
+
});
|
|
141
428
|
|
|
142
429
|
//#endregion
|
|
143
430
|
//#region src/workspace/client.ts
|
|
@@ -290,6 +577,13 @@ function createPlatformClient(config) {
|
|
|
290
577
|
};
|
|
291
578
|
};
|
|
292
579
|
const parseData = (parse) => (value) => parse(value.data);
|
|
580
|
+
const parseWriteWith = (schema) => (value) => {
|
|
581
|
+
const envelope = value;
|
|
582
|
+
return {
|
|
583
|
+
data: schema.parse(envelope.data),
|
|
584
|
+
meta: platformWriteMetaSchema.parse(envelope.meta)
|
|
585
|
+
};
|
|
586
|
+
};
|
|
293
587
|
return {
|
|
294
588
|
/** 진단 — 이 자격이 어느 워크스페이스·source에 묶였는가 */
|
|
295
589
|
me: () => request("GET", "/v1/me", { parse: parseData((v) => platformMeSchema.parse(v)) }),
|
|
@@ -303,6 +597,71 @@ function createPlatformClient(config) {
|
|
|
303
597
|
setTaskStage: (externalId, input) => request("PATCH", `/v1/works/tasks/${encodeURIComponent(externalId)}/stage`, {
|
|
304
598
|
body: input,
|
|
305
599
|
parse: parseWrite
|
|
600
|
+
}),
|
|
601
|
+
upsertPipeline: (key, input) => request("PUT", `/v1/works/pipelines/${encodeURIComponent(key)}`, {
|
|
602
|
+
body: input,
|
|
603
|
+
parse: (value) => {
|
|
604
|
+
const envelope = value;
|
|
605
|
+
return {
|
|
606
|
+
data: platformPipelineResourceSchema.parse(envelope.data),
|
|
607
|
+
meta: platformWriteMetaSchema.parse(envelope.meta)
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
}),
|
|
611
|
+
deletePipeline: (key, options) => request("DELETE", `/v1/works/pipelines/${encodeURIComponent(key)}${options?.allowDestructive ? "?allowDestructive=true" : ""}`, { parse: parseData((v) => v) }),
|
|
612
|
+
importPipeline: (key, input) => request("POST", `/v1/works/pipelines/${encodeURIComponent(key)}/import`, {
|
|
613
|
+
body: input,
|
|
614
|
+
parse: parseData((v) => platformPipelineResourceSchema.parse(v))
|
|
615
|
+
})
|
|
616
|
+
},
|
|
617
|
+
resources: { list: () => request("GET", "/v1/resources", { parse: parseData((v) => platformResourcesV2Schema.parse(v)) }) },
|
|
618
|
+
brands: {
|
|
619
|
+
upsert: (key, input) => request("PUT", `/v1/brands/${encodeURIComponent(key)}`, {
|
|
620
|
+
body: input,
|
|
621
|
+
parse: parseWriteWith(platformBrandResourceSchema)
|
|
622
|
+
}),
|
|
623
|
+
import: (key, input) => request("POST", `/v1/brands/${encodeURIComponent(key)}/import`, {
|
|
624
|
+
body: input,
|
|
625
|
+
parse: parseData((v) => platformBrandResourceSchema.parse(v))
|
|
626
|
+
})
|
|
627
|
+
},
|
|
628
|
+
brandapps: {
|
|
629
|
+
upsert: (slug, input) => request("PUT", `/v1/brandapps/${encodeURIComponent(slug)}`, {
|
|
630
|
+
body: input,
|
|
631
|
+
parse: parseWriteWith(platformBrandappResourceSchema)
|
|
632
|
+
}),
|
|
633
|
+
import: (slug) => request("POST", `/v1/brandapps/${encodeURIComponent(slug)}/import`, {
|
|
634
|
+
body: {},
|
|
635
|
+
parse: parseData((v) => platformBrandappResourceSchema.parse(v))
|
|
636
|
+
})
|
|
637
|
+
},
|
|
638
|
+
oauthClients: {
|
|
639
|
+
upsert: (key, input) => request("PUT", `/v1/oauth-clients/${encodeURIComponent(key)}`, {
|
|
640
|
+
body: input,
|
|
641
|
+
parse: parseWriteWith(platformOAuthClientResourceSchema)
|
|
642
|
+
}),
|
|
643
|
+
rotateSecret: (key) => request("POST", `/v1/oauth-clients/${encodeURIComponent(key)}/rotate-secret`, {
|
|
644
|
+
body: {},
|
|
645
|
+
parse: parseData((v) => platformOAuthClientResourceSchema.parse(v))
|
|
646
|
+
}),
|
|
647
|
+
delete: (key, options) => request("DELETE", `/v1/oauth-clients/${encodeURIComponent(key)}${options?.allowDestructive ? "?allowDestructive=true" : ""}`, { parse: parseData((v) => v) }),
|
|
648
|
+
import: (key, input) => request("POST", `/v1/oauth-clients/${encodeURIComponent(key)}/import`, {
|
|
649
|
+
body: input,
|
|
650
|
+
parse: parseData((v) => platformOAuthClientResourceSchema.parse(v))
|
|
651
|
+
})
|
|
652
|
+
},
|
|
653
|
+
eav: { applySchema: (input) => request("POST", "/v1/eav/schema/apply", {
|
|
654
|
+
body: input,
|
|
655
|
+
parse: parseData((v) => platformEavSchemaApplyResultSchema.parse(v))
|
|
656
|
+
}) },
|
|
657
|
+
lock: {
|
|
658
|
+
acquire: (holderId) => request("POST", "/v1/lock", {
|
|
659
|
+
body: { holderId },
|
|
660
|
+
parse: parseData((v) => platformLockAcquiredSchema.parse(v))
|
|
661
|
+
}),
|
|
662
|
+
release: (holderId) => request("DELETE", "/v1/lock", {
|
|
663
|
+
body: { holderId },
|
|
664
|
+
parse: parseData((v) => platformLockReleasedSchema.parse(v))
|
|
306
665
|
})
|
|
307
666
|
},
|
|
308
667
|
webhooks: {
|
|
@@ -331,5 +690,5 @@ function createPlatformClient(config) {
|
|
|
331
690
|
}
|
|
332
691
|
|
|
333
692
|
//#endregion
|
|
334
|
-
export { DEFAULT_PLATFORM_SCOPES, PLATFORM_TASK_OUTCOMES, PLATFORM_TASK_PRIORITIES, PLATFORM_WEBHOOK_TRIGGERS, PlatformApiError, REOPT_PLATFORM_ID_URLS, REOPT_PLATFORM_URLS, createPlatformClient, platformErrorSchema, platformExternalIdSchema, platformMeSchema, platformPipelineSchema, platformTaskSchema, platformTaskStageInputSchema, platformTaskStageSchema, platformTaskUpsertInputSchema, platformWebhookSchema, platformWebhookUpsertInputSchema, platformWorkTaskStageChangedEventSchema, platformWriteMetaSchema, resolvePlatformUrls };
|
|
693
|
+
export { DEFAULT_PLATFORM_SCOPES, PLATFORM_ADMIN_SCOPE, PLATFORM_BRANDAPP_STATUSES, PLATFORM_DOMAIN_STATUSES, PLATFORM_MANAGED_BY_VALUES, PLATFORM_OAUTH_APPLICATION_TYPES, PLATFORM_OAUTH_GRANT_TYPES, PLATFORM_STAGE_COLORS, PLATFORM_TASK_OUTCOMES, PLATFORM_TASK_PRIORITIES, PLATFORM_TOKEN_ENDPOINT_AUTH_METHODS, PLATFORM_WEBHOOK_TRIGGERS, PlatformApiError, REOPT_PLATFORM_ID_URLS, REOPT_PLATFORM_URLS, createPlatformClient, platformBrandImportInputSchema, platformBrandResourceSchema, platformBrandUpsertInputSchema, platformBrandappResourceSchema, platformBrandappUpsertInputSchema, platformCustomerUpsertInputSchema, platformEavBrandappResourcesSchema, platformEavEntityResourceSchema, platformEavSchemaApplyInputSchema, platformEavSchemaApplyResultSchema, platformEavSchemaOperationSchema, platformErrorSchema, platformExternalIdSchema, platformLockAcquiredSchema, platformLockReleasedSchema, platformMeSchema, platformOAuthClientImportInputSchema, platformOAuthClientResourceSchema, platformOAuthClientUpsertInputSchema, platformPipelineImportInputSchema, platformPipelineResourceSchema, platformPipelineSchema, platformPipelineStageInputSchema, platformPipelineUpsertInputSchema, platformResourceKeySchema, platformResourcesSchema, platformResourcesV2Schema, platformTaskSchema, platformTaskStageInputSchema, platformTaskStageSchema, platformTaskUpsertInputSchema, platformWebhookResourceSchema, platformWebhookSchema, platformWebhookUpsertInputSchema, platformWorkTaskStageChangedEventSchema, platformWriteMetaSchema, resolvePlatformUrls };
|
|
335
694
|
//# sourceMappingURL=index.js.map
|
package/docs/api-reference.md
CHANGED
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
| `@reopt-ai/brandapp-sdk/feedback` | Customer feedback submission |
|
|
26
26
|
| `@reopt-ai/brandapp-sdk/logout` | OIDC Single Logout — back-channel receiver + RP-initiated end-session |
|
|
27
27
|
| `@reopt-ai/brandapp-sdk/eav/migrate` | EAV schema migration runner (`defineMigration`, `runMigrations`) |
|
|
28
|
+
| `@reopt-ai/brandapp-sdk/workspace` | Platform API — workspace work tasks, webhooks, declarative resources (server-only) |
|
|
29
|
+
|
|
30
|
+
> `/workspace` is a different surface — workspace scope instead of brandapp scope, its own host
|
|
31
|
+
> and audience, server-only. It has its own page: [`workspace.md`](./workspace.md).
|
|
28
32
|
|
|
29
33
|
## Core SDK
|
|
30
34
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Workspace / Platform API (`@reopt-ai/brandapp-sdk/workspace`)
|
|
2
|
+
|
|
3
|
+
The platform API is a **different surface** from the rest of this SDK. Everything else in
|
|
4
|
+
`@reopt-ai/brandapp-sdk` speaks to a single _brandapp_ (`brandapp.reopt.ai`) with a brandapp
|
|
5
|
+
credential. This sub-path speaks to a whole _workspace_ (`platform.reopt.ai`) with a
|
|
6
|
+
**workspace-scoped machine credential**, and it is **server-only** — `createPlatformClient`
|
|
7
|
+
throws in a browser runtime.
|
|
8
|
+
|
|
9
|
+
Two things use it: your own back-end services (create Studio work tasks from your app, move
|
|
10
|
+
them through a pipeline, receive stage changes back over a webhook) and the
|
|
11
|
+
[`reopt workspace`](https://www.npmjs.com/package/@reopt-ai/cli) CLI, which reconciles a
|
|
12
|
+
declarative `reopt.workspace.ts` against these same routes.
|
|
13
|
+
|
|
14
|
+
Specs: RFC-0029 (platform API) and RFC-0030 (Platform as Code).
|
|
15
|
+
|
|
16
|
+
## Credentials
|
|
17
|
+
|
|
18
|
+
The credential is an OAuth client with `grant_type=client_credentials`, issued per workspace.
|
|
19
|
+
The client asks `id.reopt.ai` for a token and passes `resource=<platform origin>` (RFC 8707),
|
|
20
|
+
so **the host is the audience** — a brandapp or MCP token is rejected by the platform API, and
|
|
21
|
+
a platform token is rejected elsewhere.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { createPlatformClient } from "@reopt-ai/brandapp-sdk/workspace";
|
|
25
|
+
|
|
26
|
+
const platform = createPlatformClient({
|
|
27
|
+
clientId: process.env.REOPT_PLATFORM_CLIENT_ID!,
|
|
28
|
+
clientSecret: process.env.REOPT_PLATFORM_CLIENT_SECRET!,
|
|
29
|
+
// scopes defaults to ["works:read", "works:write"]
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const me = await platform.me(); // { workspaceId, source, scopes, … }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The token is cached, renewed 60s before expiry, and re-fetched once on a 401. Never ship these
|
|
36
|
+
values to a browser bundle.
|
|
37
|
+
|
|
38
|
+
| Config | Default |
|
|
39
|
+
| ------------- | ----------------------------------------------------------- |
|
|
40
|
+
| `platformUrl` | `REOPT_PLATFORM_URL` → `https://platform.reopt.ai` |
|
|
41
|
+
| `idBaseUrl` | `REOPT_ID_BASE_URL` → `https://id.reopt.ai` |
|
|
42
|
+
| `scopes` | `DEFAULT_PLATFORM_SCOPES` = `["works:read", "works:write"]` |
|
|
43
|
+
| `timeoutMs` | `10_000` |
|
|
44
|
+
| `fetch` | `globalThis.fetch` |
|
|
45
|
+
| `requestId` | `crypto.randomUUID()` |
|
|
46
|
+
|
|
47
|
+
Filing and moving work tasks needs `works:read`/`works:write`. Everything that changes the
|
|
48
|
+
shape of the workspace — `resources`, `brands`, `brandapps`, `oauthClients`, `eav`, `lock`, and
|
|
49
|
+
the pipeline calls under `works` — additionally requires `workspace:admin`
|
|
50
|
+
(`PLATFORM_ADMIN_SCOPE`). It is deliberately a **separate key**: a service that files work
|
|
51
|
+
tasks should not be able to delete a pipeline.
|
|
52
|
+
|
|
53
|
+
## Work tasks — the common case
|
|
54
|
+
|
|
55
|
+
Your service owns the identifier; reopt owns the task. `upsertTask` is keyed by your
|
|
56
|
+
`externalId` and is idempotent, so a retry after a network failure does not create a second
|
|
57
|
+
task.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
await platform.works.upsertTask("incident-4821", {
|
|
61
|
+
title: "결제 웹훅 3회 실패",
|
|
62
|
+
pipeline: "error-triage", // pipeline key
|
|
63
|
+
stage: "new",
|
|
64
|
+
priority: "high",
|
|
65
|
+
body: "…",
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await platform.works.setTaskStage("incident-4821", { stage: "done" });
|
|
69
|
+
const task = await platform.works.getTask("incident-4821");
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
To hear about stage changes a human made in Studio, register a webhook for
|
|
73
|
+
`workTaskStageChanged` and validate the body with
|
|
74
|
+
`platformWorkTaskStageChangedEventSchema`.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
await platform.webhooks.upsert({
|
|
78
|
+
url: "https://your-app.example/api/webhooks/reopt",
|
|
79
|
+
triggers: ["workTaskStageChanged"],
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Declarative resources (RFC-0030)
|
|
84
|
+
|
|
85
|
+
These back the CLI's `plan`/`apply`. Use them directly only if you are building your own
|
|
86
|
+
tooling — otherwise declare the resources in `reopt.workspace.ts` and let
|
|
87
|
+
`reopt workspace apply` call them.
|
|
88
|
+
|
|
89
|
+
| Call | Notes |
|
|
90
|
+
| -------------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
91
|
+
| `resources.list()` | Every resource in one round-trip — what a `plan` diffs against |
|
|
92
|
+
| `brands.upsert(key, …)` · `brands.import(key, …)` | Brand + its primary domain. **No delete route** — a person removes it in superadmin |
|
|
93
|
+
| `brandapps.upsert(slug, …)` · `brandapps.import(slug)` | `slug` is the key. Brand:Brandapp is 1:1, so rebinding is refused |
|
|
94
|
+
| `oauthClients.upsert / rotateSecret / delete / import` | See the secret rule below |
|
|
95
|
+
| `eav.applySchema({ operations })` | The whole batch runs in **one server transaction** |
|
|
96
|
+
| `works.upsertPipeline / deletePipeline / importPipeline` | Stages are matched by key; a stage missing from the input is removed |
|
|
97
|
+
| `lock.acquire(holderId)` · `lock.release(holderId)` | Workspace apply lock (Redis, 30-minute TTL) |
|
|
98
|
+
|
|
99
|
+
🔴 **The plaintext OAuth secret exists only in the create/rotate response.** The server stores
|
|
100
|
+
a hash and cannot show it again. Read `result.data.clientSecret` at that moment and put it
|
|
101
|
+
somewhere durable, or rotate.
|
|
102
|
+
|
|
103
|
+
## Destructive changes are refused by default
|
|
104
|
+
|
|
105
|
+
Deleting a pipeline that still holds tasks, dropping an EAV entity that still has records,
|
|
106
|
+
removing an attribute that still has values, or deleting an OAuth client with live tokens all
|
|
107
|
+
fail **fail-closed** with `409` and code `DESTRUCTIVE_BLOCKED`. The whole transaction is rolled
|
|
108
|
+
back — nothing partially applied. Pass `{ allowDestructive: true }` (or `allowDestructive` in
|
|
109
|
+
the EAV apply input) only when you mean it.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { PlatformApiError } from "@reopt-ai/brandapp-sdk/workspace";
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await platform.works.deletePipeline("error-triage");
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (
|
|
118
|
+
error instanceof PlatformApiError &&
|
|
119
|
+
error.code === "DESTRUCTIVE_BLOCKED"
|
|
120
|
+
) {
|
|
121
|
+
// error.fields tells you what is in the way, and how much of it
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Deleting the workspace's default pipeline is refused outright (`422`) — not unlockable.
|
|
127
|
+
|
|
128
|
+
The apply lock is fail-closed too: `LOCK_HELD` (`409`) when another run holds it,
|
|
129
|
+
`LOCK_UNAVAILABLE` (`503`) when the lock store itself is unreachable. It is the same lock the
|
|
130
|
+
EAV migration runner takes, so the two cannot interleave.
|
|
131
|
+
|
|
132
|
+
## Schemas
|
|
133
|
+
|
|
134
|
+
Every request and response shape is exported as a zod schema (`platform*Schema`) alongside its
|
|
135
|
+
type, so you can validate a webhook body or a stored plan without restating the shape. `zod` is
|
|
136
|
+
an optional peer dependency used only by this sub-path.
|
|
137
|
+
|
|
138
|
+
Vocabulary constants — `PLATFORM_STAGE_COLORS`, `PLATFORM_TASK_OUTCOMES`,
|
|
139
|
+
`PLATFORM_TASK_PRIORITIES`, `PLATFORM_WEBHOOK_TRIGGERS`, `PLATFORM_ADMIN_SCOPE`,
|
|
140
|
+
`PLATFORM_MANAGED_BY_VALUES` — come from the same source the server validates against. Derive
|
|
141
|
+
from them rather than hard-coding the strings.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reopt-ai/brandapp-sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Reopt Brandapp SDK — Better Auth adapter, OAuth login, and EAV client",
|
|
5
5
|
"author": "Reopt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"@ai-sdk/provider": ">=4.0.0",
|
|
120
120
|
"@reopt-ai/opt-editor": ">=1.0.0",
|
|
121
121
|
"@tanstack/react-query": ">=5.0.0",
|
|
122
|
-
"better-auth": "^1.7.
|
|
122
|
+
"better-auth": "^1.7.4",
|
|
123
123
|
"hono": ">=4.0.0",
|
|
124
124
|
"react": ">=18.0.0",
|
|
125
125
|
"@reopt-ai/data-sdk": ">=0.1.1",
|
|
@@ -152,11 +152,11 @@
|
|
|
152
152
|
}
|
|
153
153
|
},
|
|
154
154
|
"devDependencies": {
|
|
155
|
-
"@ai-sdk/provider": "4.0.
|
|
155
|
+
"@ai-sdk/provider": "4.0.17",
|
|
156
156
|
"@reopt-ai/opt-editor": "2.0.0",
|
|
157
157
|
"@testing-library/react": "^16.3.2",
|
|
158
158
|
"@types/node": "22.13.9",
|
|
159
|
-
"better-auth": "^1.7.
|
|
159
|
+
"better-auth": "^1.7.4",
|
|
160
160
|
"happy-dom": "^20.8.9",
|
|
161
161
|
"hono": "^4.7.0",
|
|
162
162
|
"tsdown": "^0.22.14",
|