@reopt-ai/workspace-sdk 0.0.0-stage → 0.1.0-rc.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/dist/index.js ADDED
@@ -0,0 +1,306 @@
1
+ import { $ as platformTaskStageSchema, A as platformEavSchemaOperationSchema, B as platformPipelineResourceSchema, C as platformBrandappResourceSchema, D as platformEavEntityResourceSchema, E as platformEavBrandappResourcesSchema, F as platformMeSchema, G as platformPublishedPostPageSchema, H as platformPipelineStageInputSchema, I as platformOAuthClientImportInputSchema, J as platformResourceKeySchema, K as platformPublishedPostSchema, L as platformOAuthClientResourceSchema, M as platformExternalIdSchema, N as platformLockAcquiredSchema, O as platformEavSchemaApplyInputSchema, P as platformLockReleasedSchema, Q as platformTaskStageInputSchema, R as platformOAuthClientUpsertInputSchema, S as platformBrandUpsertInputSchema, T as platformCustomerUpsertInputSchema, U as platformPipelineUpsertInputSchema, V as platformPipelineSchema, W as platformPublishedPostListQuerySchema, X as platformResourcesV2Schema, Y as platformResourcesSchema, Z as platformTaskSchema, _ as PLATFORM_TASK_PRIORITIES, a as createPlatformClient, at as platformWriteMetaSchema, b as platformBrandImportInputSchema, c as PLATFORM_ADMIN_SCOPE, d as PLATFORM_MANAGED_BY_VALUES, et as platformTaskUpsertInputSchema, f as PLATFORM_OAUTH_APPLICATION_TYPES, g as PLATFORM_TASK_OUTCOMES, h as PLATFORM_STAGE_COLORS, i as REOPT_PLATFORM_URLS, it as platformWorkTaskStageChangedEventSchema, j as platformErrorSchema, k as platformEavSchemaApplyResultSchema, l as PLATFORM_BRANDAPP_STATUSES, m as PLATFORM_OAUTH_GRANT_TYPES, n as PlatformApiError, nt as platformWebhookSchema, ot as SDK_VERSION, p as PLATFORM_OAUTH_CLIENT_PURPOSES, q as platformPublishedPostSummarySchema, r as REOPT_PLATFORM_ID_URLS, rt as platformWebhookUpsertInputSchema, s as resolvePlatformUrls, t as DEFAULT_PLATFORM_SCOPES, tt as platformWebhookResourceSchema, u as PLATFORM_DOMAIN_STATUSES, v as PLATFORM_TOKEN_ENDPOINT_AUTH_METHODS, w as platformBrandappUpsertInputSchema, x as platformBrandResourceSchema, y as PLATFORM_WEBHOOK_TRIGGERS, z as platformPipelineImportInputSchema } from "./client-BUatgjlv.js";
2
+ import { z } from "zod";
3
+
4
+ //#region src/workspace/connect.ts
5
+ const iso = z.union([z.string(), z.date().transform((d) => d.toISOString())]);
6
+ const nullableIso = iso.nullable();
7
+ const outcome = z.enum(["completed", "canceled"]).nullable();
8
+ const memberSchema = z.looseObject({
9
+ memberId: z.string(),
10
+ userId: z.string(),
11
+ name: z.string(),
12
+ image: z.string().nullable()
13
+ });
14
+ const connectMeSchema = z.looseObject({
15
+ principal: z.literal("user"),
16
+ clientId: z.string(),
17
+ clientName: z.string(),
18
+ user: z.looseObject({
19
+ id: z.string(),
20
+ name: z.string().nullable(),
21
+ email: z.string().nullable()
22
+ }),
23
+ workspace: z.looseObject({
24
+ id: z.string(),
25
+ name: z.string(),
26
+ tier: z.string()
27
+ }),
28
+ scopes: z.array(z.string()),
29
+ member: z.looseObject({
30
+ id: z.string(),
31
+ role: z.string()
32
+ }),
33
+ permissions: z.array(z.string())
34
+ });
35
+ const connectMemberSchema = memberSchema;
36
+ const connectPipelineSchema = z.looseObject({
37
+ id: z.string(),
38
+ name: z.string(),
39
+ isDefault: z.boolean(),
40
+ isArchived: z.boolean(),
41
+ key: z.string().nullable(),
42
+ stages: z.array(z.looseObject({
43
+ id: z.string(),
44
+ key: z.string(),
45
+ label: z.string(),
46
+ color: z.string(),
47
+ order: z.number(),
48
+ isEntry: z.boolean(),
49
+ outcome
50
+ }))
51
+ });
52
+ const connectTaskSchema = z.looseObject({
53
+ id: z.string(),
54
+ title: z.string(),
55
+ description: z.string().nullable(),
56
+ priority: z.enum([
57
+ "low",
58
+ "medium",
59
+ "high",
60
+ "urgent"
61
+ ]),
62
+ dueDate: nullableIso,
63
+ startDate: nullableIso,
64
+ isTimed: z.boolean(),
65
+ sortOrder: z.number(),
66
+ pipeline: z.looseObject({
67
+ id: z.string(),
68
+ name: z.string()
69
+ }).nullable(),
70
+ stage: z.looseObject({
71
+ id: z.string(),
72
+ key: z.string(),
73
+ label: z.string(),
74
+ outcome
75
+ }).nullable(),
76
+ assignees: z.array(z.union([z.looseObject({
77
+ kind: z.literal("member"),
78
+ member: memberSchema
79
+ }), z.looseObject({
80
+ kind: z.literal("group"),
81
+ group: z.looseObject({
82
+ id: z.string(),
83
+ name: z.string()
84
+ })
85
+ })])),
86
+ creator: memberSchema.nullable(),
87
+ createdAt: iso,
88
+ updatedAt: iso
89
+ });
90
+ const coverSchema = z.looseObject({
91
+ id: z.string(),
92
+ url: z.string()
93
+ }).nullable();
94
+ const connectPostGroupSchema = z.looseObject({
95
+ id: z.string(),
96
+ name: z.string(),
97
+ slug: z.string(),
98
+ kind: z.string(),
99
+ brand: z.looseObject({
100
+ id: z.string(),
101
+ name: z.string()
102
+ }).nullable()
103
+ });
104
+ const postBase = {
105
+ id: z.string(),
106
+ title: z.string(),
107
+ slug: z.string(),
108
+ status: z.string(),
109
+ groupId: z.string(),
110
+ publishedAt: nullableIso,
111
+ updatedAt: iso,
112
+ coverImage: coverSchema
113
+ };
114
+ const connectPostSummarySchema = z.looseObject({
115
+ ...postBase,
116
+ excerpt: z.string()
117
+ });
118
+ const connectPostSchema = z.looseObject({
119
+ ...postBase,
120
+ authorUserId: z.string().nullable(),
121
+ contentRich: z.unknown(),
122
+ version: z.number()
123
+ });
124
+ const connectFolderSchema = z.looseObject({
125
+ id: z.string(),
126
+ name: z.string(),
127
+ parentId: z.string().nullable(),
128
+ kind: z.string(),
129
+ brandId: z.string().nullable(),
130
+ createdAt: iso
131
+ });
132
+ const connectFileSchema = z.looseObject({
133
+ id: z.string(),
134
+ name: z.string(),
135
+ size: z.number(),
136
+ contentType: z.string().nullable(),
137
+ visibility: z.string(),
138
+ folderId: z.string().nullable(),
139
+ url: z.string().nullable(),
140
+ createdAt: iso
141
+ });
142
+ const connectFormSchema = z.looseObject({
143
+ id: z.string(),
144
+ name: z.string(),
145
+ slug: z.string(),
146
+ type: z.string(),
147
+ status: z.string(),
148
+ brandId: z.string().nullable(),
149
+ publishedAt: nullableIso
150
+ });
151
+ const connectInquirySchema = z.looseObject({
152
+ submissionId: z.string(),
153
+ formId: z.string(),
154
+ formName: z.string(),
155
+ brandId: z.string().nullable(),
156
+ submittedAt: iso,
157
+ customerId: z.string().nullable(),
158
+ customerName: z.string().nullable(),
159
+ customerEmail: z.string().nullable(),
160
+ customerPhone: z.string().nullable(),
161
+ taskId: z.string().nullable(),
162
+ stageId: z.string().nullable(),
163
+ stageKey: z.string().nullable(),
164
+ stageLabel: z.string().nullable(),
165
+ answers: z.record(z.string(), z.unknown()),
166
+ highlights: z.array(z.looseObject({
167
+ label: z.string(),
168
+ value: z.string()
169
+ })),
170
+ details: z.array(z.looseObject({
171
+ label: z.string(),
172
+ value: z.string(),
173
+ multiline: z.boolean()
174
+ }))
175
+ });
176
+ const idResult = z.looseObject({ id: z.string() });
177
+ function queryString(params) {
178
+ const search = new URLSearchParams();
179
+ for (const [key, value] of Object.entries(params)) {
180
+ if (value === void 0) continue;
181
+ if (Array.isArray(value)) for (const v of value) search.append(key, v);
182
+ else search.set(key, String(value));
183
+ }
184
+ const text = search.toString();
185
+ return text ? `?${text}` : "";
186
+ }
187
+ const enc = encodeURIComponent;
188
+ function createConnectClient(config) {
189
+ if (!config.accessToken) throw new Error("createConnectClient: accessToken is required");
190
+ const { platformUrl } = resolvePlatformUrls({ ...config.platformUrl ? { platformUrl: config.platformUrl } : {} });
191
+ const fetchImpl = config.fetch ?? globalThis.fetch;
192
+ const timeoutMs = config.timeoutMs ?? 1e4;
193
+ const base = `${platformUrl}/v1/connect`;
194
+ async function token() {
195
+ return typeof config.accessToken === "function" ? await config.accessToken() : config.accessToken;
196
+ }
197
+ async function send(method, path, body) {
198
+ const isForm = typeof FormData !== "undefined" && body instanceof FormData;
199
+ const res = await fetchImpl(`${base}${path}`, {
200
+ method,
201
+ headers: {
202
+ authorization: `Bearer ${await token()}`,
203
+ accept: "application/json",
204
+ "x-sdk-version": SDK_VERSION,
205
+ ...body !== void 0 && !isForm ? { "content-type": "application/json" } : {}
206
+ },
207
+ body: body === void 0 ? void 0 : isForm ? body : JSON.stringify(body),
208
+ signal: AbortSignal.timeout(timeoutMs)
209
+ });
210
+ if (!res.ok) {
211
+ const text = await res.text();
212
+ let json = null;
213
+ try {
214
+ json = text ? JSON.parse(text) : null;
215
+ } catch {
216
+ json = null;
217
+ }
218
+ const parsed = platformErrorSchema.safeParse(json);
219
+ const error = parsed.success ? parsed.data.error : null;
220
+ throw new PlatformApiError({
221
+ status: res.status,
222
+ code: error?.code ?? "HTTP_ERROR",
223
+ message: error?.message ?? `Platform API responded ${res.status}`,
224
+ retryable: error?.retryable ?? (res.status >= 500 || res.status === 429),
225
+ fields: error?.fields,
226
+ requestId: res.headers.get("x-request-id") ?? void 0
227
+ });
228
+ }
229
+ return res;
230
+ }
231
+ async function data(method, path, schema, body) {
232
+ const json = await (await send(method, path, body)).json();
233
+ return schema.parse(json.data);
234
+ }
235
+ const list = (schema) => z.array(schema);
236
+ return {
237
+ platformUrl,
238
+ me: () => data("GET", "/me", connectMeSchema),
239
+ members: () => data("GET", "/members", list(connectMemberSchema)),
240
+ works: {
241
+ listPipelines: () => data("GET", "/works/pipelines", list(connectPipelineSchema)),
242
+ listTasks: (query = {}) => data("GET", `/works/tasks${queryString(query)}`, list(connectTaskSchema)),
243
+ createTask: (input) => data("POST", "/works/tasks", idResult, input),
244
+ updateTask: (id, input) => data("PATCH", `/works/tasks/${enc(id)}`, idResult, input),
245
+ moveTask: (id, input) => data("POST", `/works/tasks/${enc(id)}/move`, idResult, input),
246
+ deleteTask: (id) => data("DELETE", `/works/tasks/${enc(id)}`, idResult)
247
+ },
248
+ posts: {
249
+ listGroups: () => data("GET", "/post-groups", list(connectPostGroupSchema)),
250
+ list: (query = {}) => data("GET", `/posts${queryString(query)}`, list(connectPostSummarySchema)),
251
+ get: (id) => data("GET", `/posts/${enc(id)}`, connectPostSchema),
252
+ create: (input) => data("POST", "/posts", z.looseObject({
253
+ id: z.string(),
254
+ slug: z.string(),
255
+ groupId: z.string()
256
+ }), input),
257
+ update: (id, input) => data("PATCH", `/posts/${enc(id)}`, z.looseObject({
258
+ id: z.string(),
259
+ version: z.number().nullable()
260
+ }), input),
261
+ publish: (id) => data("POST", `/posts/${enc(id)}/publish`, z.looseObject({
262
+ id: z.string(),
263
+ status: z.string()
264
+ })),
265
+ unpublish: (id) => data("POST", `/posts/${enc(id)}/unpublish`, z.looseObject({
266
+ id: z.string(),
267
+ status: z.string()
268
+ })),
269
+ delete: (id) => data("DELETE", `/posts/${enc(id)}`, idResult)
270
+ },
271
+ folders: {
272
+ list: (query = {}) => data("GET", `/folders${queryString(query)}`, list(connectFolderSchema)),
273
+ create: (input) => data("POST", "/folders", z.looseObject({ folderId: z.string() }), input)
274
+ },
275
+ files: {
276
+ list: (query = {}) => data("GET", `/files${queryString(query)}`, list(connectFileSchema)),
277
+ upload: (file, options = {}) => {
278
+ const form = new FormData();
279
+ const name = options.name ?? (file instanceof File ? file.name : "upload");
280
+ form.set("file", file, name);
281
+ if (options.folderId) form.set("folderId", options.folderId);
282
+ return data("POST", "/files", connectFileSchema, form);
283
+ },
284
+ update: (id, input) => data("PATCH", `/files/${enc(id)}`, z.looseObject({ fileId: z.string() }), input),
285
+ delete: (id) => data("DELETE", `/files/${enc(id)}`, z.looseObject({ fileId: z.string() })),
286
+ content: (id) => send("GET", `/files/${enc(id)}/content`)
287
+ },
288
+ forms: { list: () => data("GET", "/forms", list(connectFormSchema)) },
289
+ inquiries: {
290
+ list: ({ formIds, limit }) => data("GET", `/inquiries${queryString({
291
+ formId: formIds,
292
+ limit
293
+ })}`, list(connectInquirySchema)),
294
+ moveStage: (submissionId, stageId) => data("POST", `/inquiries/${enc(submissionId)}/stage`, z.looseObject({
295
+ submissionId: z.string(),
296
+ taskId: z.string(),
297
+ fromStageLabel: z.string().nullable(),
298
+ toStageLabel: z.string()
299
+ }), { stageId })
300
+ }
301
+ };
302
+ }
303
+
304
+ //#endregion
305
+ export { DEFAULT_PLATFORM_SCOPES, PLATFORM_ADMIN_SCOPE, PLATFORM_BRANDAPP_STATUSES, PLATFORM_DOMAIN_STATUSES, PLATFORM_MANAGED_BY_VALUES, PLATFORM_OAUTH_APPLICATION_TYPES, PLATFORM_OAUTH_CLIENT_PURPOSES, 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, connectFileSchema, connectFolderSchema, connectFormSchema, connectInquirySchema, connectMeSchema, connectMemberSchema, connectPipelineSchema, connectPostGroupSchema, connectPostSchema, connectPostSummarySchema, connectTaskSchema, createConnectClient, 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, platformPublishedPostListQuerySchema, platformPublishedPostPageSchema, platformPublishedPostSchema, platformPublishedPostSummarySchema, platformResourceKeySchema, platformResourcesSchema, platformResourcesV2Schema, platformTaskSchema, platformTaskStageInputSchema, platformTaskStageSchema, platformTaskUpsertInputSchema, platformWebhookResourceSchema, platformWebhookSchema, platformWebhookUpsertInputSchema, platformWorkTaskStageChangedEventSchema, platformWriteMetaSchema, resolvePlatformUrls };
306
+ //# sourceMappingURL=index.js.map