@formizeflow/sdk 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +91 -2
- package/dist/index.cjs +1882 -0
- package/dist/index.d.cts +5582 -0
- package/dist/index.d.ts +5582 -0
- package/dist/index.js +1751 -0
- package/dist/pgp-4ZL3RFNG.js +37 -0
- package/package.json +52 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1751 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var FormFlowError = class extends Error {
|
|
3
|
+
constructor(status, code, message, details, requestId) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.details = details;
|
|
8
|
+
this.requestId = requestId;
|
|
9
|
+
this.name = "FormFlowError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var AuthenticationError = class extends FormFlowError {
|
|
13
|
+
constructor(...a) {
|
|
14
|
+
super(...a);
|
|
15
|
+
this.name = "AuthenticationError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var PermissionError = class extends FormFlowError {
|
|
19
|
+
constructor(...a) {
|
|
20
|
+
super(...a);
|
|
21
|
+
this.name = "PermissionError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var NotFoundError = class extends FormFlowError {
|
|
25
|
+
constructor(...a) {
|
|
26
|
+
super(...a);
|
|
27
|
+
this.name = "NotFoundError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var ConflictError = class extends FormFlowError {
|
|
31
|
+
constructor(...a) {
|
|
32
|
+
super(...a);
|
|
33
|
+
this.name = "ConflictError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var ValidationError = class extends FormFlowError {
|
|
37
|
+
constructor(...a) {
|
|
38
|
+
super(...a);
|
|
39
|
+
this.name = "ValidationError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var RateLimitError = class extends FormFlowError {
|
|
43
|
+
constructor(status, code, message, details, requestId, retryAfterSec) {
|
|
44
|
+
super(status, code, message, details, requestId);
|
|
45
|
+
this.retryAfterSec = retryAfterSec;
|
|
46
|
+
this.name = "RateLimitError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function errorFor(status, body, requestId, retryAfter) {
|
|
50
|
+
const e = body?.error;
|
|
51
|
+
const code = e?.code ?? "internal";
|
|
52
|
+
const msg = e?.message ?? `Request failed with status ${status}`;
|
|
53
|
+
if (status === 401) return new AuthenticationError(status, code, msg, e?.details, requestId);
|
|
54
|
+
if (status === 403) return new PermissionError(status, code, msg, e?.details, requestId);
|
|
55
|
+
if (status === 404) return new NotFoundError(status, code, msg, e?.details, requestId);
|
|
56
|
+
if (status === 409) return new ConflictError(status, code, msg, e?.details, requestId);
|
|
57
|
+
if (status === 422) return new ValidationError(status, code, msg, e?.details, requestId);
|
|
58
|
+
if (status === 429) return new RateLimitError(status, code, msg, e?.details, requestId, retryAfter);
|
|
59
|
+
return new FormFlowError(status, code, msg, e?.details, requestId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/core.ts
|
|
63
|
+
var DEFAULT_VERSION = "2026-10-01";
|
|
64
|
+
var sleepDefault = (ms, signal) => new Promise((resolve, reject) => {
|
|
65
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
66
|
+
const t = setTimeout(resolve, ms);
|
|
67
|
+
signal?.addEventListener("abort", () => {
|
|
68
|
+
clearTimeout(t);
|
|
69
|
+
reject(signal.reason);
|
|
70
|
+
}, { once: true });
|
|
71
|
+
});
|
|
72
|
+
var backoff = (attempt) => Math.min(3e4, 500 * 2 ** attempt) * (0.75 + Math.random() * 0.5);
|
|
73
|
+
var randomKey = () => typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
74
|
+
var HttpClient = class {
|
|
75
|
+
constructor(o) {
|
|
76
|
+
if (!o.apiKey) throw new Error("FormFlow: apiKey is required");
|
|
77
|
+
this.opts = {
|
|
78
|
+
apiKey: o.apiKey,
|
|
79
|
+
baseUrl: (o.baseUrl ?? "https://app.formflow.dev").replace(/\/$/, ""),
|
|
80
|
+
version: o.version ?? DEFAULT_VERSION,
|
|
81
|
+
maxRetries: o.maxRetries ?? 3,
|
|
82
|
+
timeoutMs: o.timeoutMs ?? 3e4,
|
|
83
|
+
fetch: o.fetch,
|
|
84
|
+
sleep: o.sleep,
|
|
85
|
+
workspaceId: o.workspaceId
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Low-level request: retries 429/5xx/network errors with backoff (honors Retry-After). Returns the parsed JSON body. */
|
|
89
|
+
async request(method, path, init = {}) {
|
|
90
|
+
const url = new URL(`${this.opts.baseUrl}/api/v1${path}`);
|
|
91
|
+
for (const [k, v] of Object.entries(init.query ?? {})) if (v !== void 0 && v !== null) url.searchParams.set(k, typeof v === "object" ? JSON.stringify(v) : String(v));
|
|
92
|
+
const headers = { Authorization: `Bearer ${this.opts.apiKey}`, "FormFlow-Version": this.opts.version, Accept: "application/json" };
|
|
93
|
+
if (this.opts.workspaceId) headers["FormFlow-Workspace"] = this.opts.workspaceId;
|
|
94
|
+
if (init.body !== void 0) headers["Content-Type"] = "application/json";
|
|
95
|
+
const key = init.idempotencyKey ?? (method === "POST" ? randomKey() : void 0);
|
|
96
|
+
if (key) headers["Idempotency-Key"] = key;
|
|
97
|
+
const doFetch = this.opts.fetch ?? fetch;
|
|
98
|
+
const sleep = this.opts.sleep ?? ((ms) => sleepDefault(ms, init.signal));
|
|
99
|
+
for (let attempt = 0; ; attempt++) {
|
|
100
|
+
if (init.signal?.aborted) throw init.signal.reason;
|
|
101
|
+
const timeout = AbortSignal.timeout(this.opts.timeoutMs);
|
|
102
|
+
const signal = init.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
103
|
+
let res;
|
|
104
|
+
try {
|
|
105
|
+
res = await doFetch(url.toString(), { method, headers, signal, body: init.body === void 0 ? void 0 : JSON.stringify(init.body) });
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (init.signal?.aborted) throw init.signal.reason;
|
|
108
|
+
if (attempt >= this.opts.maxRetries) throw new FormFlowError(0, "network_error", e instanceof Error ? e.message : "Network error");
|
|
109
|
+
await sleep(backoff(attempt));
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (res.ok) return res.status === 204 ? null : await res.json();
|
|
113
|
+
const retryAfter = Number(res.headers.get("retry-after")) || void 0;
|
|
114
|
+
if ((res.status === 429 || res.status >= 500) && attempt < this.opts.maxRetries) {
|
|
115
|
+
await sleep(retryAfter ? retryAfter * 1e3 : backoff(attempt));
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
let body = null;
|
|
119
|
+
try {
|
|
120
|
+
body = await res.json();
|
|
121
|
+
} catch {
|
|
122
|
+
}
|
|
123
|
+
throw errorFor(res.status, body, res.headers.get("x-request-id") ?? void 0, retryAfter);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async data(method, path, init) {
|
|
127
|
+
return (await this.request(method, path, init))?.data;
|
|
128
|
+
}
|
|
129
|
+
page(path, q, o) {
|
|
130
|
+
return this.request("GET", path, { query: q, ...o }).then((r) => ({ data: r.data, nextCursor: r.nextCursor ?? null, ...r.partial ? { partial: true, scanned: r.scanned } : {} }));
|
|
131
|
+
}
|
|
132
|
+
/** Auto-paginating async iterator over any list endpoint. */
|
|
133
|
+
async *paginate(path, q = {}, o) {
|
|
134
|
+
let cursor = q.cursor;
|
|
135
|
+
do {
|
|
136
|
+
const p = await this.page(path, { ...q, cursor }, o);
|
|
137
|
+
yield* p.data;
|
|
138
|
+
cursor = p.nextCursor ?? void 0;
|
|
139
|
+
} while (cursor);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/resources/forms.ts
|
|
144
|
+
var FormsResource = class {
|
|
145
|
+
constructor(h) {
|
|
146
|
+
this.h = h;
|
|
147
|
+
this.fields = {
|
|
148
|
+
list: (id, o) => this.h.data("GET", `/forms/${id}/fields`, o),
|
|
149
|
+
add: (id, body, o) => this.h.data("POST", `/forms/${id}/fields`, { body, ...o }),
|
|
150
|
+
update: (id, fieldId, patch, o) => this.h.data("PATCH", `/forms/${id}/fields/${fieldId}`, { body: patch, ...o }),
|
|
151
|
+
reorder: (id, fieldIds, expectedRevision, o) => this.h.data("POST", `/forms/${id}/fields/reorder`, { body: { fieldIds, expectedRevision }, ...o }),
|
|
152
|
+
delete: (id, fieldId, o) => this.h.data("DELETE", `/forms/${id}/fields/${fieldId}`, o)
|
|
153
|
+
};
|
|
154
|
+
this.sections = {
|
|
155
|
+
list: (id, o) => this.h.data("GET", `/forms/${id}/sections`, o),
|
|
156
|
+
add: (id, section, o) => this.h.data("POST", `/forms/${id}/sections`, { body: section, ...o }),
|
|
157
|
+
update: (id, sectionId, patch, o) => this.h.data("PATCH", `/forms/${id}/sections/${sectionId}`, { body: patch, ...o }),
|
|
158
|
+
delete: (id, sectionId, o) => this.h.data("DELETE", `/forms/${id}/sections/${sectionId}`, o)
|
|
159
|
+
};
|
|
160
|
+
/** Internal draft comments, anchored to a question (`fieldId`) or the whole form. Mention teammates with @email. */
|
|
161
|
+
this.comments = {
|
|
162
|
+
list: (id, q = {}, o) => this.h.data("GET", `/forms/${id}/comments`, { query: { fieldId: q.fieldId, includeResolved: q.includeResolved === void 0 ? void 0 : String(q.includeResolved) }, ...o }),
|
|
163
|
+
add: (id, body, o) => this.h.data("POST", `/forms/${id}/comments`, { body, ...o }),
|
|
164
|
+
resolve: (id, commentId, resolved = true, o) => this.h.data("PATCH", `/forms/${id}/comments/${commentId}`, { body: { resolved }, ...o }),
|
|
165
|
+
delete: (id, commentId, o) => this.h.data("DELETE", `/forms/${id}/comments/${commentId}`, o)
|
|
166
|
+
};
|
|
167
|
+
this.logic = {
|
|
168
|
+
list: (id, o) => this.h.data("GET", `/forms/${id}/logic`, o),
|
|
169
|
+
add: (id, rule, o) => this.h.data("POST", `/forms/${id}/logic`, { body: rule, ...o }),
|
|
170
|
+
update: (id, ruleId, patch, o) => this.h.data("PATCH", `/forms/${id}/logic/${ruleId}`, { body: patch, ...o }),
|
|
171
|
+
delete: (id, ruleId, o) => this.h.data("DELETE", `/forms/${id}/logic/${ruleId}`, o)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
list(q, o) {
|
|
175
|
+
return this.h.page("/forms", q, o);
|
|
176
|
+
}
|
|
177
|
+
/** Async iterator over every form (auto-pagination). */
|
|
178
|
+
listAll(q, o) {
|
|
179
|
+
return this.h.paginate("/forms", q, o);
|
|
180
|
+
}
|
|
181
|
+
get(id, o) {
|
|
182
|
+
return this.h.data("GET", `/forms/${id}`, o);
|
|
183
|
+
}
|
|
184
|
+
create(body, o) {
|
|
185
|
+
return this.h.data("POST", "/forms", { body, ...o });
|
|
186
|
+
}
|
|
187
|
+
update(id, body, o) {
|
|
188
|
+
return this.h.data("PATCH", `/forms/${id}`, { body, ...o });
|
|
189
|
+
}
|
|
190
|
+
delete(id, o) {
|
|
191
|
+
return this.h.data("DELETE", `/forms/${id}`, o);
|
|
192
|
+
}
|
|
193
|
+
/** Copy a form; pass `workspaceId` to copy into another workspace you can write to (user/OAuth credentials). */
|
|
194
|
+
duplicate(id, body = {}, o) {
|
|
195
|
+
return this.h.data("POST", `/forms/${id}/duplicate`, { body, ...o });
|
|
196
|
+
}
|
|
197
|
+
archive(id, o) {
|
|
198
|
+
return this.h.data("POST", `/forms/${id}/archive`, { body: {}, ...o });
|
|
199
|
+
}
|
|
200
|
+
restore(id, o) {
|
|
201
|
+
return this.h.data("POST", `/forms/${id}/restore`, { body: {}, ...o });
|
|
202
|
+
}
|
|
203
|
+
/** Throws ValidationError whose `details.issues` lists the blocking problems. */
|
|
204
|
+
publish(id, { force, ...o } = {}) {
|
|
205
|
+
return this.h.data("POST", `/forms/${id}/publish`, { body: force ? { force } : {}, ...o });
|
|
206
|
+
}
|
|
207
|
+
/** Idempotent create-or-update of the draft by slug (global slugs); with `publish: true` publishes only when the definition changed. */
|
|
208
|
+
upsertBySlug(slug2, body, o) {
|
|
209
|
+
return this.h.data("PUT", `/forms/by-slug/${encodeURIComponent(slug2)}`, { body, ...o });
|
|
210
|
+
}
|
|
211
|
+
/** The theme the draft would publish with right now (workspace default, saved theme, brand kit and inline overrides merged; CSS sanitized). */
|
|
212
|
+
theme(id, o) {
|
|
213
|
+
return this.h.data("GET", `/forms/${id}/theme`, o);
|
|
214
|
+
}
|
|
215
|
+
versions(id, o) {
|
|
216
|
+
return this.h.data("GET", `/forms/${id}/versions`, o);
|
|
217
|
+
}
|
|
218
|
+
version(id, version, o) {
|
|
219
|
+
return this.h.data("GET", `/forms/${id}/versions/${version}`, o);
|
|
220
|
+
}
|
|
221
|
+
import(body, o) {
|
|
222
|
+
return this.h.data("POST", "/forms/import", { body, ...o });
|
|
223
|
+
}
|
|
224
|
+
/** Hosted URL, QR code and embed snippets. */
|
|
225
|
+
/** Hosted URL that opens the form with answers (`prefill`: field id to value), hidden fields and respondent attributes filled in. */
|
|
226
|
+
prefillLink(id, body, o) {
|
|
227
|
+
return this.h.data("POST", `/forms/${id}/prefill-link`, { body, ...o });
|
|
228
|
+
}
|
|
229
|
+
/** A complete HTML page that embeds the live form, plus the embed snippets. */
|
|
230
|
+
html(id, o) {
|
|
231
|
+
return this.h.data("GET", `/forms/${id}/html`, o);
|
|
232
|
+
}
|
|
233
|
+
share(id, o) {
|
|
234
|
+
return this.h.data("GET", `/forms/${id}/share`, o);
|
|
235
|
+
}
|
|
236
|
+
/** Atomic batch edit of the draft. */
|
|
237
|
+
operations(id, operations, expectedRevision, o) {
|
|
238
|
+
return this.h.data("POST", `/forms/${id}/operations`, { body: { operations, expectedRevision }, ...o });
|
|
239
|
+
}
|
|
240
|
+
/** Convenience: edit with a callback that returns operations. */
|
|
241
|
+
async edit(id, build, o) {
|
|
242
|
+
const f = await this.get(id, o);
|
|
243
|
+
return this.operations(id, build(f), f.draftRevision, o);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/resources/submissions.ts
|
|
248
|
+
var csv = (a) => a?.length ? a.join(",") : void 0;
|
|
249
|
+
var prep = (q) => q && { ...q, expand: csv(q.expand), fields: csv(q.fields), filters: q.filters ? JSON.stringify(q.filters) : void 0 };
|
|
250
|
+
var SubmissionsResource = class {
|
|
251
|
+
constructor(h) {
|
|
252
|
+
this.h = h;
|
|
253
|
+
}
|
|
254
|
+
list(formId, q, o) {
|
|
255
|
+
return this.h.page(`/forms/${formId}/submissions`, prep(q), o);
|
|
256
|
+
}
|
|
257
|
+
listAll(formId, q, o) {
|
|
258
|
+
return this.h.paginate(`/forms/${formId}/submissions`, prep(q) ?? {}, o);
|
|
259
|
+
}
|
|
260
|
+
/** Same filters in a request body. Sensitive fields are redacted unless `includeSensitive` (needs workspace:manage). */
|
|
261
|
+
search(formId, body = {}, o) {
|
|
262
|
+
return this.h.request("POST", `/forms/${formId}/submissions/search`, { body, ...o }).then((r) => ({ data: r.data, nextCursor: r.nextCursor ?? null, ...r.partial ? { partial: true, scanned: r.scanned } : {} }));
|
|
263
|
+
}
|
|
264
|
+
/** Iterate every match of a search. */
|
|
265
|
+
async *searchAll(formId, body = {}, o) {
|
|
266
|
+
let cursor = body.cursor;
|
|
267
|
+
do {
|
|
268
|
+
const p = await this.search(formId, { ...body, cursor }, o);
|
|
269
|
+
yield* p.data;
|
|
270
|
+
cursor = p.nextCursor ?? void 0;
|
|
271
|
+
} while (cursor);
|
|
272
|
+
}
|
|
273
|
+
get(id, q = {}, o) {
|
|
274
|
+
return this.h.data("GET", `/submissions/${id}`, { query: { expand: csv(q.expand), redact: q.redact }, ...o });
|
|
275
|
+
}
|
|
276
|
+
update(id, body, o) {
|
|
277
|
+
return this.h.data("PATCH", `/submissions/${id}`, { body, ...o });
|
|
278
|
+
}
|
|
279
|
+
delete(id, o) {
|
|
280
|
+
return this.h.data("DELETE", `/submissions/${id}`, o);
|
|
281
|
+
}
|
|
282
|
+
bulkDelete(ids, o) {
|
|
283
|
+
return this.h.data("POST", "/submissions/bulk-delete", { body: { ids }, ...o });
|
|
284
|
+
}
|
|
285
|
+
/** Start an export of matching responses. Poll with `exports.get`. */
|
|
286
|
+
export(formId, body = {}, o) {
|
|
287
|
+
return this.h.data("POST", `/forms/${formId}/exports`, { body, ...o });
|
|
288
|
+
}
|
|
289
|
+
/** Email the response rendered through a document template (PDF or Word) to up to 10 recipients. */
|
|
290
|
+
emailDocument(id, body, o) {
|
|
291
|
+
return this.h.data("POST", `/submissions/${id}/document/email`, { body, ...o });
|
|
292
|
+
}
|
|
293
|
+
bulkExport(body, o) {
|
|
294
|
+
return this.h.data("POST", "/submissions/bulk-export", { body, ...o });
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// src/resources/themes.ts
|
|
299
|
+
var ThemesResource = class {
|
|
300
|
+
constructor(h) {
|
|
301
|
+
this.h = h;
|
|
302
|
+
}
|
|
303
|
+
/** Presets plus the workspace's saved themes. */
|
|
304
|
+
list(o) {
|
|
305
|
+
return this.h.data("GET", "/themes", o);
|
|
306
|
+
}
|
|
307
|
+
/** Built-in presets only. Use the id as a form's `themeId`. */
|
|
308
|
+
presets(o) {
|
|
309
|
+
return this.h.data("GET", "/themes/presets", o);
|
|
310
|
+
}
|
|
311
|
+
/** Proposes a theme from a public page's CSS custom properties, fonts and radius. Saves nothing; `found` lists what was read. */
|
|
312
|
+
fromUrl(url, o) {
|
|
313
|
+
return this.h.data("POST", "/themes/from-url", { body: { url }, ...o });
|
|
314
|
+
}
|
|
315
|
+
get(id, o) {
|
|
316
|
+
return this.h.data("GET", `/themes/${id}`, o);
|
|
317
|
+
}
|
|
318
|
+
create(body, o) {
|
|
319
|
+
return this.h.data("POST", "/themes", { body, ...o });
|
|
320
|
+
}
|
|
321
|
+
update(id, body, o) {
|
|
322
|
+
return this.h.data("PATCH", `/themes/${id}`, { body, ...o });
|
|
323
|
+
}
|
|
324
|
+
delete(id, o) {
|
|
325
|
+
return this.h.data("DELETE", `/themes/${id}`, o);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// src/resources/templates.ts
|
|
330
|
+
var TemplatesResource = class {
|
|
331
|
+
constructor(h) {
|
|
332
|
+
this.h = h;
|
|
333
|
+
}
|
|
334
|
+
list(q = {}, o) {
|
|
335
|
+
return this.h.data("GET", "/templates", { query: q, ...o });
|
|
336
|
+
}
|
|
337
|
+
get(id, o) {
|
|
338
|
+
return this.h.data("GET", `/templates/${id}`, o);
|
|
339
|
+
}
|
|
340
|
+
/** Template types (NPS, RSVP, order form...) with the designs each is offered in. Combine as `${typeId}--${designId}` for `get`. */
|
|
341
|
+
types(q = {}, o) {
|
|
342
|
+
return this.h.data("GET", "/templates/types", { query: q, ...o });
|
|
343
|
+
}
|
|
344
|
+
/** Designs (theme, imagery, layout presets), optionally those that suit a template `category`. */
|
|
345
|
+
designs(q = {}, o) {
|
|
346
|
+
return this.h.data("GET", "/designs", { query: q, ...o });
|
|
347
|
+
}
|
|
348
|
+
/** Dress a draft in a design. Never touches questions, copy, logic or scoring. */
|
|
349
|
+
applyDesign(formId, designId, expectedRevision, o) {
|
|
350
|
+
return this.h.data("POST", `/forms/${formId}/design`, { body: { designId, expectedRevision }, ...o });
|
|
351
|
+
}
|
|
352
|
+
/** Curated question library; each entry's `spec` is a ready field to add with a new id. */
|
|
353
|
+
questionBank(q = {}, o) {
|
|
354
|
+
return this.h.data("GET", "/question-bank", { query: q, ...o });
|
|
355
|
+
}
|
|
356
|
+
/** Parse a product CSV (name, price, description, image, stock) into `choices` for a product field. Nothing is saved. */
|
|
357
|
+
importProducts(csv2, o) {
|
|
358
|
+
return this.h.data("POST", "/products/import", { body: { csv: csv2 }, ...o });
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// src/resources/webhooks.ts
|
|
363
|
+
var EVENT_TYPES = [
|
|
364
|
+
"form.published",
|
|
365
|
+
"form.updated",
|
|
366
|
+
"form.archived",
|
|
367
|
+
"form.deleted",
|
|
368
|
+
"submission.created",
|
|
369
|
+
"submission.completed",
|
|
370
|
+
"submission.updated",
|
|
371
|
+
"submission.deleted",
|
|
372
|
+
"comment.created",
|
|
373
|
+
"member.added",
|
|
374
|
+
"member.removed",
|
|
375
|
+
"member.role_changed",
|
|
376
|
+
"payment.status_changed",
|
|
377
|
+
"workflow.completed",
|
|
378
|
+
"workflow.failed",
|
|
379
|
+
"experiment.started",
|
|
380
|
+
"experiment.paused",
|
|
381
|
+
"experiment.guardrail_breached",
|
|
382
|
+
"experiment.winner_declared",
|
|
383
|
+
"experiment.promoted",
|
|
384
|
+
"apikey.expiring"
|
|
385
|
+
];
|
|
386
|
+
var WebhooksResource = class {
|
|
387
|
+
constructor(h) {
|
|
388
|
+
this.h = h;
|
|
389
|
+
}
|
|
390
|
+
list(o) {
|
|
391
|
+
return this.h.data("GET", "/webhooks", o);
|
|
392
|
+
}
|
|
393
|
+
/** The signing `secret` is returned once, here. Store it. */
|
|
394
|
+
create(body, o) {
|
|
395
|
+
return this.h.data("POST", "/webhooks", { body, ...o });
|
|
396
|
+
}
|
|
397
|
+
update(id, body, o) {
|
|
398
|
+
return this.h.data("PATCH", `/webhooks/${id}`, { body, ...o });
|
|
399
|
+
}
|
|
400
|
+
delete(id, o) {
|
|
401
|
+
return this.h.data("DELETE", `/webhooks/${id}`, o);
|
|
402
|
+
}
|
|
403
|
+
deliveries(id, q, o) {
|
|
404
|
+
return this.h.page(`/webhooks/${id}/deliveries`, q, o);
|
|
405
|
+
}
|
|
406
|
+
deliveriesAll(id, q, o) {
|
|
407
|
+
return this.h.paginate(`/webhooks/${id}/deliveries`, q, o);
|
|
408
|
+
}
|
|
409
|
+
redeliver(id, deliveryId, o) {
|
|
410
|
+
return this.h.data("POST", `/webhooks/${id}/deliveries/${deliveryId}/redeliver`, { body: {}, ...o });
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// src/resources/analytics.ts
|
|
415
|
+
var AnalyticsResource = class {
|
|
416
|
+
constructor(h) {
|
|
417
|
+
this.h = h;
|
|
418
|
+
}
|
|
419
|
+
metrics(formId, q = {}, o) {
|
|
420
|
+
return this.h.data("GET", `/forms/${formId}/analytics`, { query: q, ...o });
|
|
421
|
+
}
|
|
422
|
+
question(formId, fieldId, q = {}, o) {
|
|
423
|
+
return this.h.data("GET", `/forms/${formId}/analytics/questions/${fieldId}`, { query: q, ...o });
|
|
424
|
+
}
|
|
425
|
+
funnel(formId, q = {}, o) {
|
|
426
|
+
return this.h.data("GET", `/forms/${formId}/analytics/funnel`, { query: q, ...o });
|
|
427
|
+
}
|
|
428
|
+
/** NPS / CSAT / CES for every such field (or one `fieldId`). */
|
|
429
|
+
satisfaction(formId, q = {}, o) {
|
|
430
|
+
return this.h.data("GET", `/forms/${formId}/analytics/satisfaction`, { query: q, ...o });
|
|
431
|
+
}
|
|
432
|
+
scores(formId, o) {
|
|
433
|
+
return this.h.data("GET", `/forms/${formId}/analytics/scores`, o);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// src/resources/ai.ts
|
|
438
|
+
var AiResource = class {
|
|
439
|
+
constructor(h) {
|
|
440
|
+
this.h = h;
|
|
441
|
+
}
|
|
442
|
+
/** Prompt to validated FormDefinition. With `create`, also saves a draft form. Uses AI credits. */
|
|
443
|
+
generateForm(body, o) {
|
|
444
|
+
return this.h.data("POST", "/ai/generate-form", { body, ...o });
|
|
445
|
+
}
|
|
446
|
+
/** Edit a form from an instruction. Give `formId` (its draft) or `definition`. `apply` saves the draft and needs `formId` + `expectedRevision`; destructive edits also need `allowDestructive`. */
|
|
447
|
+
edit(body, o) {
|
|
448
|
+
return this.h.data("POST", "/ai/edit", { body, ...o });
|
|
449
|
+
}
|
|
450
|
+
/** Translate form copy into one locale. With `apply` it merges into `settings.translations[locale]` of the draft. */
|
|
451
|
+
translate(body, o) {
|
|
452
|
+
return this.h.data("POST", "/ai/translate", { body, ...o });
|
|
453
|
+
}
|
|
454
|
+
/** Before/after wording per question. Proposal only. */
|
|
455
|
+
rewrite(body, o) {
|
|
456
|
+
return this.h.data("POST", "/ai/rewrite", { body, ...o });
|
|
457
|
+
}
|
|
458
|
+
/** Vetted logic rule suggestions. Proposal only. */
|
|
459
|
+
suggestLogic(body, o) {
|
|
460
|
+
return this.h.data("POST", "/ai/suggest-logic", { body, ...o });
|
|
461
|
+
}
|
|
462
|
+
/** Natural language to a validated calculated-field expression, with a step-by-step explanation and test results on sample answers. Pass `expression` instead of `instruction` to explain and test an existing one (no AI credits). */
|
|
463
|
+
writeFormula(body, o) {
|
|
464
|
+
return this.h.data("POST", "/ai/formula", { body, ...o });
|
|
465
|
+
}
|
|
466
|
+
/** Form from pasted `text` or a base64 text document (txt, md, csv, tsv, json, html). With `create` also saves a draft. */
|
|
467
|
+
importDocument(body, o) {
|
|
468
|
+
return this.h.data("POST", "/ai/import", { body, ...o });
|
|
469
|
+
}
|
|
470
|
+
/** Theme from a site `url`, a logo/`image` (base64) or a `prompt`. With `apply` + `formId` + `expectedRevision` it merges into the draft. */
|
|
471
|
+
brandKit(body, o) {
|
|
472
|
+
return this.h.data("POST", "/ai/brand-kit", { body, ...o });
|
|
473
|
+
}
|
|
474
|
+
/** Workspace AI memory (brand voice, audience, default languages, compliance phrasing, field patterns), injected into generateForm and edit. */
|
|
475
|
+
getMemory(o) {
|
|
476
|
+
return this.h.data("GET", "/ai/memory", o);
|
|
477
|
+
}
|
|
478
|
+
/** Replace the AI memory (workspace:manage). `{}` clears it. */
|
|
479
|
+
setMemory(body, o) {
|
|
480
|
+
return this.h.data("PUT", "/ai/memory", { body, ...o });
|
|
481
|
+
}
|
|
482
|
+
/** Theme shares of an open-text question over ALL answers (each classified once; cached per answer count). Refused above the cost guard unless `maxAnswers` is raised. */
|
|
483
|
+
themes(formId, body, o) {
|
|
484
|
+
return this.h.data("POST", `/forms/${formId}/ai/themes`, { body, ...o });
|
|
485
|
+
}
|
|
486
|
+
/** The latest cached theme analysis for a question, or null. No AI credits. */
|
|
487
|
+
cachedThemes(formId, fieldId, o) {
|
|
488
|
+
return this.h.data("GET", `/forms/${formId}/ai/themes`, { query: { fieldId }, ...o });
|
|
489
|
+
}
|
|
490
|
+
/** AI summary of responses. Sensitive fields never reach the model. */
|
|
491
|
+
analyzeResponses(formId, body = {}, o) {
|
|
492
|
+
return this.h.data("POST", `/forms/${formId}/ai/analyze`, { body, ...o });
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// src/resources/account.ts
|
|
497
|
+
var AccountResource = class {
|
|
498
|
+
constructor(h) {
|
|
499
|
+
this.h = h;
|
|
500
|
+
this.members = {
|
|
501
|
+
list: (o) => this.h.data("GET", "/members", o),
|
|
502
|
+
invite: (body, o) => this.h.data("POST", "/members", { body, ...o }),
|
|
503
|
+
setRole: (membershipId, role, o) => this.h.data("PATCH", `/members/${membershipId}`, { body: { role }, ...o }),
|
|
504
|
+
/** `transferTo` (a user id) takes over the leaver's forms, views, schedules and templates. */
|
|
505
|
+
remove: (membershipId, transferTo, o) => this.h.data("DELETE", `/members/${membershipId}`, { query: { transferTo }, ...o })
|
|
506
|
+
};
|
|
507
|
+
this.apiKeys = {
|
|
508
|
+
list: (o) => this.h.data("GET", "/api-keys", o),
|
|
509
|
+
/** The full `key` is returned once. */
|
|
510
|
+
create: (body, o) => this.h.data("POST", "/api-keys", { body, ...o }),
|
|
511
|
+
/** Org owners/admins: mint a key bound to another workspace of the organization. The full `key` is returned once. */
|
|
512
|
+
createForWorkspace: (workspaceId, body, o) => this.h.data("POST", `/workspaces/${workspaceId}/api-keys`, { body, ...o }),
|
|
513
|
+
revoke: (id, o) => this.h.data("DELETE", `/api-keys/${id}`, o)
|
|
514
|
+
};
|
|
515
|
+
/** The workspace's signed-uid secret (uid_sig = HMAC-SHA256(secret, uid)). `secret` is returned only on create or `rotate: true`. */
|
|
516
|
+
this.identity = {
|
|
517
|
+
get: (o) => this.h.data("GET", "/workspace/identity", o),
|
|
518
|
+
/** atlasIssuer: https issuer whose Atlas session tokens prove a uid (`atlas_token`); null clears it. */
|
|
519
|
+
update: (body, o) => this.h.data("PUT", "/workspace/identity", { body, ...o })
|
|
520
|
+
};
|
|
521
|
+
this.auditEvents = {
|
|
522
|
+
list: (q, o) => this.h.page("/audit-events", q, o),
|
|
523
|
+
listAll: (q, o) => this.h.paginate("/audit-events", q, o),
|
|
524
|
+
/** Across every workspace of the organization. Org owners and admins only. */
|
|
525
|
+
listOrg: (q, o) => this.h.page("/org/audit-events", q, o),
|
|
526
|
+
/** Start a CSV or JSON export of the audit log. Poll with `exports.get`. */
|
|
527
|
+
export: (body, o) => this.h.data("POST", "/audit-events/export", { body, ...o })
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
me(o) {
|
|
531
|
+
return this.h.data("GET", "/me", o);
|
|
532
|
+
}
|
|
533
|
+
fieldTypes(o) {
|
|
534
|
+
return this.h.data("GET", "/field-types", o);
|
|
535
|
+
}
|
|
536
|
+
usage(period, o) {
|
|
537
|
+
return this.h.data("GET", "/usage", { query: { period }, ...o });
|
|
538
|
+
}
|
|
539
|
+
/** Check a URL before using it as `Media.url`: reachable, public, image/video, size limits. */
|
|
540
|
+
validateMedia(url, kind, o) {
|
|
541
|
+
return this.h.data("POST", "/media/validate", { body: { url, kind }, ...o });
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// src/resources/exports.ts
|
|
546
|
+
var ExportsResource = class {
|
|
547
|
+
constructor(h) {
|
|
548
|
+
this.h = h;
|
|
549
|
+
/** Recurring exports of a form's responses. */
|
|
550
|
+
this.schedules = {
|
|
551
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/export-schedules`, o),
|
|
552
|
+
create: (formId, body, o) => this.h.data("POST", `/forms/${formId}/export-schedules`, { body, ...o }),
|
|
553
|
+
update: (scheduleId, body, o) => this.h.data("PATCH", `/export-schedules/${scheduleId}`, { body, ...o }),
|
|
554
|
+
delete: (scheduleId, o) => this.h.data("DELETE", `/export-schedules/${scheduleId}`, o),
|
|
555
|
+
/** Queue one run now. */
|
|
556
|
+
run: (scheduleId, o) => this.h.data("POST", `/export-schedules/${scheduleId}/run`, { body: {}, ...o })
|
|
557
|
+
};
|
|
558
|
+
/** Document templates that turn one response into a PDF or Word file. */
|
|
559
|
+
this.documentTemplates = {
|
|
560
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/document-templates`, o),
|
|
561
|
+
create: (formId, body, o) => this.h.data("POST", `/forms/${formId}/document-templates`, { body, ...o }),
|
|
562
|
+
/** A Word file (base64, up to 1.4 MB) with {{placeholders}}. */
|
|
563
|
+
uploadDocx: (formId, body, o) => this.h.data("POST", `/forms/${formId}/document-templates/docx`, { body, ...o }),
|
|
564
|
+
/** A fillable PDF (base64, up to 1.4 MB); map its fields with `update`. */
|
|
565
|
+
uploadPdf: (formId, body, o) => this.h.data("POST", `/forms/${formId}/document-templates/pdf`, { body, ...o }),
|
|
566
|
+
update: (templateId, body, o) => this.h.data("PATCH", `/document-templates/${templateId}`, { body, ...o }),
|
|
567
|
+
delete: (templateId, o) => this.h.data("DELETE", `/document-templates/${templateId}`, o)
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
get(id, o) {
|
|
571
|
+
return this.h.data("GET", `/exports/${id}`, o);
|
|
572
|
+
}
|
|
573
|
+
/** Poll until the export is done or failed. */
|
|
574
|
+
async wait(id, opts = {}) {
|
|
575
|
+
const deadline = Date.now() + (opts.timeoutMs ?? 12e4);
|
|
576
|
+
for (; ; ) {
|
|
577
|
+
const j = await this.get(id, { signal: opts.signal });
|
|
578
|
+
if (j.export.status === "done" || j.export.status === "failed") return j;
|
|
579
|
+
if (Date.now() > deadline) throw new Error(`Export ${id} did not finish in time`);
|
|
580
|
+
await new Promise((r) => setTimeout(r, opts.intervalMs ?? 1500));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/resources/public.ts
|
|
586
|
+
var PublicClient = class {
|
|
587
|
+
constructor(o, extra = {}) {
|
|
588
|
+
this.extra = extra;
|
|
589
|
+
this.base = `${o.baseUrl.replace(/\/$/, "")}/api/v1/public`;
|
|
590
|
+
this.f = o.fetch ?? fetch;
|
|
591
|
+
this.extra = { credentials: o.credentials ?? extra.credentials };
|
|
592
|
+
}
|
|
593
|
+
async call(method, path, body, signal, headers = {}) {
|
|
594
|
+
const res = await this.f(`${this.base}${path}`, {
|
|
595
|
+
method,
|
|
596
|
+
signal,
|
|
597
|
+
credentials: this.extra.credentials,
|
|
598
|
+
headers: { Accept: "application/json", ...body !== void 0 ? { "Content-Type": "application/json" } : {}, ...headers },
|
|
599
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
600
|
+
});
|
|
601
|
+
if (res.status === 204) return null;
|
|
602
|
+
const json = await res.json().catch(() => null);
|
|
603
|
+
if (!res.ok) throw errorFor(res.status, json, res.headers.get("x-request-id") ?? void 0, Number(res.headers.get("retry-after")) || void 0);
|
|
604
|
+
return json.data;
|
|
605
|
+
}
|
|
606
|
+
getForm(slug2, signal) {
|
|
607
|
+
return this.call("GET", `/forms/${encodeURIComponent(slug2)}`, void 0, signal);
|
|
608
|
+
}
|
|
609
|
+
/** Sets an httpOnly cookie on success (use `credentials: "include"` in browsers). Throws PermissionError code "forbidden" / details.reason "wrong_password". */
|
|
610
|
+
unlock(slug2, password, signal) {
|
|
611
|
+
return this.call("POST", `/forms/${encodeURIComponent(slug2)}/unlock`, { password }, signal);
|
|
612
|
+
}
|
|
613
|
+
start(slug2, body = {}, signal) {
|
|
614
|
+
return this.call("POST", `/forms/${encodeURIComponent(slug2)}/submissions`, { action: "start", ...body }, signal);
|
|
615
|
+
}
|
|
616
|
+
save(slug2, body, signal) {
|
|
617
|
+
return this.call("POST", `/forms/${encodeURIComponent(slug2)}/submissions`, { action: "save", ...body }, signal);
|
|
618
|
+
}
|
|
619
|
+
/** Headless decide for native rendering: show or not, which variant or journey step, resume and the published definition. Holdout answers `show: false`; excluded (outside traffic or targeting) answers `show: true` with the original form and no experiment id. */
|
|
620
|
+
decide(body, signal) {
|
|
621
|
+
return this.call("POST", "/onboarding/decide", body, signal);
|
|
622
|
+
}
|
|
623
|
+
/** Report a goal for a signed uid (or `atlas_token`) with no API key. Needs a running or finished test at `entrySlug`; rate limited per uid. */
|
|
624
|
+
reportConversion(entrySlug, body, signal) {
|
|
625
|
+
return this.call("POST", `/experiments/${encodeURIComponent(entrySlug)}/conversions`, body, signal);
|
|
626
|
+
}
|
|
627
|
+
/** Adaptive AI of a form that opted in. The server falls back to the author's static content on any trouble. */
|
|
628
|
+
ai(slug2, body, signal) {
|
|
629
|
+
return this.call("POST", `/forms/${encodeURIComponent(slug2)}/ai`, body, signal);
|
|
630
|
+
}
|
|
631
|
+
/** Options of a database-backed choice field (record picker). `q` searches server side; pass `nextCursor` back as `cursor` for the next page. */
|
|
632
|
+
choices(slug2, fieldId, o = {}, signal) {
|
|
633
|
+
const qs = new URLSearchParams(Object.entries(o).flatMap(([k, v]) => v === void 0 ? [] : [[k, String(v)]]));
|
|
634
|
+
return this.call("GET", `/forms/${encodeURIComponent(slug2)}/choices/${encodeURIComponent(fieldId)}${qs.size ? `?${qs}` : ""}`, void 0, signal);
|
|
635
|
+
}
|
|
636
|
+
/** Typed attributes and prefill from the form's profile lookup. */
|
|
637
|
+
profile(slug2, body, signal) {
|
|
638
|
+
return this.call("POST", `/forms/${encodeURIComponent(slug2)}/profile`, body, signal);
|
|
639
|
+
}
|
|
640
|
+
complete(slug2, body, signal) {
|
|
641
|
+
return this.call("POST", `/forms/${encodeURIComponent(slug2)}/submissions`, { action: "complete", ...body }, signal, body.idempotencyKey ? { "Idempotency-Key": body.idempotencyKey } : {});
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// src/resources/results.ts
|
|
646
|
+
var ResultsResource = class {
|
|
647
|
+
constructor(h) {
|
|
648
|
+
this.h = h;
|
|
649
|
+
/** Saved views of the results table: filters, columns and sort. Shared views are visible to the whole workspace. */
|
|
650
|
+
this.views = {
|
|
651
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/views`, o),
|
|
652
|
+
create: (formId, body, o) => this.h.data("POST", `/forms/${formId}/views`, { body, ...o }),
|
|
653
|
+
update: (viewId, body, o) => this.h.data("PATCH", `/views/${viewId}`, { body, ...o }),
|
|
654
|
+
delete: (viewId, o) => this.h.data("DELETE", `/views/${viewId}`, o)
|
|
655
|
+
};
|
|
656
|
+
this.invitations = {
|
|
657
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/invitations`, o),
|
|
658
|
+
/** Each token and link is returned once; only a hash is stored. */
|
|
659
|
+
create: (formId, body, o) => this.h.data("POST", `/forms/${formId}/invitations`, { body, ...o }),
|
|
660
|
+
revoke: (formId, invitationId, o) => this.h.data("DELETE", `/forms/${formId}/invitations/${invitationId}`, o)
|
|
661
|
+
};
|
|
662
|
+
this.shareLinks = {
|
|
663
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/share-links`, o),
|
|
664
|
+
create: (formId, body, o) => this.h.data("POST", `/forms/${formId}/share-links`, { body, ...o }),
|
|
665
|
+
revoke: (linkId, o) => this.h.data("DELETE", `/share-links/${linkId}`, o)
|
|
666
|
+
};
|
|
667
|
+
this.versions = {
|
|
668
|
+
history: (formId, o) => this.h.data("GET", `/forms/${formId}/version-history`, o),
|
|
669
|
+
/** `from` and `to` are version numbers or "draft". */
|
|
670
|
+
compare: (formId, from, to, o) => this.h.data("GET", `/forms/${formId}/versions/compare`, { query: { from, to }, ...o }),
|
|
671
|
+
/** Replaces the draft; the previous draft is snapshotted first. The live form is unchanged until publish. */
|
|
672
|
+
restore: (formId, version, o) => this.h.data("POST", `/forms/${formId}/versions/${version}/restore`, { body: {}, ...o }),
|
|
673
|
+
undoRestore: (formId, snapshotId, o) => this.h.data("POST", `/forms/${formId}/restores/${snapshotId}/undo`, { body: {}, ...o })
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
triage(formId, o) {
|
|
677
|
+
return this.h.data("GET", `/forms/${formId}/triage`, o);
|
|
678
|
+
}
|
|
679
|
+
setTriage(submissionId, patch, o) {
|
|
680
|
+
return this.h.data("PATCH", `/submissions/${submissionId}/triage`, { body: patch, ...o });
|
|
681
|
+
}
|
|
682
|
+
bulkTriage(body, o) {
|
|
683
|
+
return this.h.data("POST", "/submissions/bulk-triage", { body, ...o });
|
|
684
|
+
}
|
|
685
|
+
/** Edit history of a response; the original value of every correction stays recoverable. */
|
|
686
|
+
edits(submissionId, o) {
|
|
687
|
+
return this.h.data("GET", `/submissions/${submissionId}/edits`, o);
|
|
688
|
+
}
|
|
689
|
+
editAnswer(submissionId, body, o) {
|
|
690
|
+
return this.h.data("POST", `/submissions/${submissionId}/edits`, { body, ...o });
|
|
691
|
+
}
|
|
692
|
+
revertEdit(submissionId, editId, o) {
|
|
693
|
+
return this.h.data("POST", `/submissions/${submissionId}/edits/${editId}/revert`, { body: {}, ...o });
|
|
694
|
+
}
|
|
695
|
+
markSpam(submissionId, o) {
|
|
696
|
+
return this.h.data("POST", `/submissions/${submissionId}/spam`, { body: {}, ...o });
|
|
697
|
+
}
|
|
698
|
+
/** Spam to completed; completion events, webhooks and notifications fire now. */
|
|
699
|
+
restoreFromSpam(submissionId, o) {
|
|
700
|
+
return this.h.data("POST", `/submissions/${submissionId}/restore`, { body: {}, ...o });
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// src/resources/payments.ts
|
|
705
|
+
var PaymentsResource = class {
|
|
706
|
+
constructor(h) {
|
|
707
|
+
this.h = h;
|
|
708
|
+
this.connections = {
|
|
709
|
+
list: (o) => this.h.data("GET", "/payments/connections", o),
|
|
710
|
+
connect: (body, o) => this.h.data("POST", "/payments/connections", { body, ...o }),
|
|
711
|
+
/** Adds test-mode credentials next to the live ones (same body as `connect`). Used for test-mode responses. */
|
|
712
|
+
connectTest: (body, o) => this.h.data("POST", "/payments/connections/test", { body, ...o }),
|
|
713
|
+
disconnect: (id, o) => this.h.data("DELETE", `/payments/connections/${id}`, o),
|
|
714
|
+
/** Stripe Connect OAuth URL to navigate a signed-in owner to. Needs Connect configured on the instance. */
|
|
715
|
+
stripeAuthorize: (o) => this.h.data("POST", "/payments/connections/stripe/authorize", { body: {}, ...o })
|
|
716
|
+
};
|
|
717
|
+
/** Cards respondents agreed to keep (Stripe ids only). */
|
|
718
|
+
this.savedMethods = {
|
|
719
|
+
list: (q = {}, o) => this.h.data("GET", "/payments/saved-methods", { query: q, ...o }),
|
|
720
|
+
/** Charges the card with no respondent present. The same `idempotencyKey` is one charge however often it is sent. `requires_action` means the bank wants the respondent: they were emailed a link (also returned). Refund through `refund`. */
|
|
721
|
+
charge: (id, body, o) => this.h.data("POST", `/payments/saved-methods/${id}/charge`, { body, ...o })
|
|
722
|
+
};
|
|
723
|
+
/** Workspace-wide test mode. A form can also set `settings.testMode`. */
|
|
724
|
+
this.testMode = {
|
|
725
|
+
get: (o) => this.h.data("GET", "/payments/test-mode", o),
|
|
726
|
+
set: (enabled, o) => this.h.data("PUT", "/payments/test-mode", { body: { enabled }, ...o })
|
|
727
|
+
};
|
|
728
|
+
/** Identity (Stripe Identity) and bank (Plaid) checks from `id_check` fields. Ids and status only. */
|
|
729
|
+
this.checks = {
|
|
730
|
+
list: (q = {}, o) => this.h.data("GET", "/verification-checks", { query: q, ...o })
|
|
731
|
+
};
|
|
732
|
+
this.rules = {
|
|
733
|
+
get: (formId, o) => this.h.data("GET", `/forms/${formId}/payment-settings`, o),
|
|
734
|
+
set: (formId, rules, o) => this.h.data("PUT", `/forms/${formId}/payment-settings`, { body: rules, ...o })
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
/** The ledger as CSV (up to 10,000 rows, oldest first). `truncated` means narrow it with from/to. */
|
|
738
|
+
exportCsv(q = {}, o) {
|
|
739
|
+
return this.h.data("GET", "/payments/export", { query: q, ...o });
|
|
740
|
+
}
|
|
741
|
+
list(q = {}, o) {
|
|
742
|
+
return this.h.data("GET", "/payments", { query: { ...q, flagged: q.flagged ? "1" : void 0 }, ...o });
|
|
743
|
+
}
|
|
744
|
+
/** Only an amount you confirm (`confirmAmountMinor`, equal to the refund amount) is refunded. Defaults to the remaining balance. */
|
|
745
|
+
refund(paymentId, body, o) {
|
|
746
|
+
return this.h.data("POST", `/payments/${paymentId}/refund`, { body, ...o });
|
|
747
|
+
}
|
|
748
|
+
/** Ask the provider for the current state and repair what a missed webhook left behind. */
|
|
749
|
+
sync(paymentId, o) {
|
|
750
|
+
return this.h.data("POST", `/payments/${paymentId}/sync`, { body: {}, ...o });
|
|
751
|
+
}
|
|
752
|
+
/** Braintree / Authorize.Net: charge the submission's open payment with a browser-SDK token. The amount is the server-priced one. */
|
|
753
|
+
charge(submissionId, body, o) {
|
|
754
|
+
return this.h.data("POST", `/public/payments/${submissionId}/charge`, { body, ...o });
|
|
755
|
+
}
|
|
756
|
+
/** Recover or re-open checkout. `wallet: "applePay"` opens Mollie's hosted page on Apple Pay when the form enables it. Braintree and Authorize.Net return `client` instead of a URL. */
|
|
757
|
+
checkout(submissionId, wallet, o) {
|
|
758
|
+
return this.h.data("POST", `/public/payments/${submissionId}/checkout`, { query: { wallet }, ...o });
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// src/resources/scheduling.ts
|
|
763
|
+
var SchedulingResource = class {
|
|
764
|
+
constructor(h) {
|
|
765
|
+
this.h = h;
|
|
766
|
+
this.quickIntegrations = {
|
|
767
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/quick-integrations`, o),
|
|
768
|
+
/** Creates a normal workflow from a preset. `params` holds the values the preset lists (for example { listId }). */
|
|
769
|
+
apply: (formId, body, o) => this.h.data("POST", `/forms/${formId}/quick-integrations`, { body, ...o })
|
|
770
|
+
};
|
|
771
|
+
this.bookings = {
|
|
772
|
+
list: (formId, q = {}, o) => this.h.data("GET", `/forms/${formId}/bookings`, { query: q, ...o }),
|
|
773
|
+
cancel: (bookingId, o) => this.h.data("POST", `/bookings/${bookingId}/cancel`, { body: {}, ...o })
|
|
774
|
+
};
|
|
775
|
+
/** The respondent's own booking, by the signed token in the email link. */
|
|
776
|
+
this.manage = {
|
|
777
|
+
get: (token, o) => this.h.data("GET", `/public/bookings/${token}`, o),
|
|
778
|
+
slots: (token, q = {}, o) => this.h.data("GET", `/public/bookings/${token}/slots`, { query: q, ...o }),
|
|
779
|
+
reschedule: (token, start, o) => this.h.data("POST", `/public/bookings/${token}/reschedule`, { body: { start }, ...o }),
|
|
780
|
+
cancel: (token, o) => this.h.data("POST", `/public/bookings/${token}/cancel`, { body: {}, ...o })
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
/** Open slots of an appointment field (public endpoint; no credentials needed). */
|
|
784
|
+
availability(slug2, fieldId, q = {}, o) {
|
|
785
|
+
return this.h.data("GET", `/public/forms/${slug2}/availability/${fieldId}`, { query: q, ...o });
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// src/resources/workflows.ts
|
|
790
|
+
var WorkflowsResource = class {
|
|
791
|
+
constructor(h) {
|
|
792
|
+
this.h = h;
|
|
793
|
+
this.approvals = {
|
|
794
|
+
list: (q = {}, o) => this.h.data("GET", "/approvals", { query: { status: q.status, mine: q.mine === void 0 ? void 0 : String(q.mine) }, ...o }),
|
|
795
|
+
get: (id, o) => this.h.data("GET", `/approvals/${id}`, o),
|
|
796
|
+
/** In-app decision: the signed-in user must be a current-stage approver. */
|
|
797
|
+
decide: (id, body, o) => this.h.data("POST", `/approvals/${id}/decision`, { body, ...o }),
|
|
798
|
+
cancel: (id, o) => this.h.data("POST", `/approvals/${id}/cancel`, { body: {}, ...o }),
|
|
799
|
+
resend: (id, o) => this.h.data("POST", `/approvals/${id}/resend`, { body: {}, ...o })
|
|
800
|
+
};
|
|
801
|
+
/** Signature requests keep a tamper-evident audit trail. No compliance certification is claimed; legal validity depends on jurisdiction. */
|
|
802
|
+
this.signing = {
|
|
803
|
+
list: (o) => this.h.data("GET", "/signing", o),
|
|
804
|
+
/** Signer links are returned once. */
|
|
805
|
+
create: (body, o) => this.h.data("POST", "/signing", { body, ...o }),
|
|
806
|
+
get: (id, o) => this.h.data("GET", `/signing/${id}`, o),
|
|
807
|
+
void: (id, o) => this.h.data("POST", `/signing/${id}/void`, { body: {}, ...o }),
|
|
808
|
+
verify: (id, o) => this.h.data("GET", `/signing/${id}/verify`, o),
|
|
809
|
+
resendSigner: (id, signerId, o) => this.h.data("POST", `/signing/${id}/signers/${signerId}/resend`, { body: {}, ...o }),
|
|
810
|
+
revokeSigner: (id, signerId, o) => this.h.data("POST", `/signing/${id}/signers/${signerId}/revoke`, { body: {}, ...o })
|
|
811
|
+
};
|
|
812
|
+
/** AI draft of a workflow from a plain-language description. Nothing is saved: review, then create. */
|
|
813
|
+
this.draft = (body, o) => this.h.data("POST", "/workflows/draft", { body, ...o });
|
|
814
|
+
/** Runs, failures, average duration and assignment statuses per step. */
|
|
815
|
+
this.stepReport = (workflowId, o) => this.h.data("GET", `/workflows/${workflowId}/step-report`, o);
|
|
816
|
+
/** The signed-in user's inbox (assignments and approvals). An API key must pass `email`. */
|
|
817
|
+
this.tasks = {
|
|
818
|
+
list: (q = {}, o) => this.h.data("GET", "/tasks", { query: q, ...o }),
|
|
819
|
+
act: (id, body, o) => this.h.data("POST", `/tasks/${id}/act`, { body, ...o })
|
|
820
|
+
};
|
|
821
|
+
/** Share one response with a person, a role or a signed link, with a view/edit permission per field. */
|
|
822
|
+
this.shares = {
|
|
823
|
+
list: (submissionId, o) => this.h.data("GET", `/submissions/${submissionId}/shares`, o),
|
|
824
|
+
/** Without email and role the share is a link (`url` in the result). */
|
|
825
|
+
create: (submissionId, body, o) => this.h.data("POST", `/submissions/${submissionId}/shares`, { body, ...o }),
|
|
826
|
+
revoke: (shareId, o) => this.h.data("DELETE", `/submission-shares/${shareId}`, o),
|
|
827
|
+
sharedWithMe: (o) => this.h.data("GET", "/shared-with-me", o),
|
|
828
|
+
getShared: (shareId, o) => this.h.data("GET", `/shared-with-me/${shareId}`, o),
|
|
829
|
+
editShared: (shareId, body, o) => this.h.data("PATCH", `/shared-with-me/${shareId}`, { body, ...o })
|
|
830
|
+
};
|
|
831
|
+
/** Tasks handed out by form_request, payment_request and sign steps. */
|
|
832
|
+
this.assignments = {
|
|
833
|
+
list: (q = {}, o) => this.h.data("GET", "/assignments", { query: q, ...o }),
|
|
834
|
+
cancel: (id, o) => this.h.data("POST", `/assignments/${id}/cancel`, { body: {}, ...o })
|
|
835
|
+
};
|
|
836
|
+
/** Several forms for one audience behind a branded landing page at /p/<slug>. */
|
|
837
|
+
this.portals = {
|
|
838
|
+
list: (o) => this.h.data("GET", "/portals", o),
|
|
839
|
+
create: (body, o) => this.h.data("POST", "/portals", { body, ...o }),
|
|
840
|
+
get: (id, o) => this.h.data("GET", `/portals/${id}`, o),
|
|
841
|
+
update: (id, body, o) => this.h.data("PATCH", `/portals/${id}`, { body, ...o }),
|
|
842
|
+
delete: (id, o) => this.h.data("DELETE", `/portals/${id}`, o),
|
|
843
|
+
/** Emails personal links; they are returned once. */
|
|
844
|
+
invite: (id, people, o) => this.h.data("POST", `/portals/${id}/invites`, { body: { people }, ...o }),
|
|
845
|
+
/** Kills the invitee's portal link and form links. Submitted responses stay. */
|
|
846
|
+
revokeInvite: (id, inviteId, o) => this.h.data("DELETE", `/portals/${id}/invites/${inviteId}`, o),
|
|
847
|
+
/** New personal link (the old one stops working), emailed and returned once. */
|
|
848
|
+
regenerateInvite: (id, inviteId, o) => this.h.data("POST", `/portals/${id}/invites/${inviteId}/regenerate`, { body: {}, ...o }),
|
|
849
|
+
progress: (id, o) => this.h.data("GET", `/portals/${id}/progress`, o)
|
|
850
|
+
};
|
|
851
|
+
/** Sandboxed custom-field widgets: use one in a `custom` field with component "widget" and config { widgetId, settings }. */
|
|
852
|
+
this.widgets = {
|
|
853
|
+
list: (o) => this.h.data("GET", "/widgets", o),
|
|
854
|
+
register: (manifest, o) => this.h.data("POST", "/widgets", { body: manifest, ...o }),
|
|
855
|
+
delete: (registrationId, o) => this.h.data("DELETE", `/widgets/${registrationId}`, o)
|
|
856
|
+
};
|
|
857
|
+
/** Browser-side answer encryption. Generate the key pair with generateKeyPair() from this SDK and keep the private key yourself. */
|
|
858
|
+
this.encryption = {
|
|
859
|
+
enable: (formId, body, o) => this.h.data("PUT", `/forms/${formId}/encryption`, { body, ...o }),
|
|
860
|
+
disable: (formId, o) => this.h.data("DELETE", `/forms/${formId}/encryption`, o)
|
|
861
|
+
};
|
|
862
|
+
this.integrations = {
|
|
863
|
+
health: (o) => this.h.data("GET", "/integrations/health", o),
|
|
864
|
+
/** Failure alert emails: workspace switch, extra recipients and a per-connection on/off map ({ [connectionId]: boolean }). */
|
|
865
|
+
alerts: {
|
|
866
|
+
get: (o) => this.h.data("GET", "/integrations/alerts", o),
|
|
867
|
+
update: (body, o) => this.h.data("PUT", "/integrations/alerts", { body, ...o })
|
|
868
|
+
},
|
|
869
|
+
/** Read-only test; providers that cannot be tested without sending data answer status "unchecked". */
|
|
870
|
+
testConnection: (id, o) => this.h.data("POST", `/integrations/connections/${id}/test`, { body: {}, ...o }),
|
|
871
|
+
/** Idempotent per failure state; `warnings` lists steps whose target cannot dedupe. */
|
|
872
|
+
replay: (executionId, requestKey, o) => this.h.data("POST", `/integrations/executions/${executionId}/replay`, { body: { requestKey }, ...o })
|
|
873
|
+
};
|
|
874
|
+
this.dataSources = {
|
|
875
|
+
list: (formId, o) => this.h.data("GET", "/data-sources", { query: { formId }, ...o }),
|
|
876
|
+
create: (body, o) => this.h.data("POST", "/data-sources", { body, ...o }),
|
|
877
|
+
update: (id, body, o) => this.h.data("PATCH", `/data-sources/${id}`, { body, ...o }),
|
|
878
|
+
delete: (id, o) => this.h.data("DELETE", `/data-sources/${id}`, o)
|
|
879
|
+
};
|
|
880
|
+
/** Workspace captcha keys. The secret is write-only. */
|
|
881
|
+
this.captcha = {
|
|
882
|
+
status: (o) => this.h.data("GET", "/captcha", o),
|
|
883
|
+
set: (body, o) => this.h.data("PUT", "/captcha", { body, ...o }),
|
|
884
|
+
clear: (o) => this.h.data("DELETE", "/captcha", o)
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
// src/resources/experiments.ts
|
|
890
|
+
var ExperimentsResource = class {
|
|
891
|
+
constructor(h) {
|
|
892
|
+
this.h = h;
|
|
893
|
+
}
|
|
894
|
+
list(q = {}, o) {
|
|
895
|
+
return this.h.data("GET", "/experiments", { query: q, ...o });
|
|
896
|
+
}
|
|
897
|
+
get(id, o) {
|
|
898
|
+
return this.h.data("GET", `/experiments/${id}`, o);
|
|
899
|
+
}
|
|
900
|
+
create(body, o) {
|
|
901
|
+
return this.h.data("POST", "/experiments", { body, ...o });
|
|
902
|
+
}
|
|
903
|
+
update(id, test, o) {
|
|
904
|
+
return this.h.data("PATCH", `/experiments/${id}`, { body: { action: "update", test }, ...o });
|
|
905
|
+
}
|
|
906
|
+
/** Create the test at this entry address, or update it while it is a draft (`formId` is needed to create). Idempotent: the infrastructure-as-code call. */
|
|
907
|
+
upsertByEntry(entrySlug, body, o) {
|
|
908
|
+
return this.h.data("PUT", `/experiments/by-entry/${encodeURIComponent(entrySlug)}`, { body, ...o });
|
|
909
|
+
}
|
|
910
|
+
/** Forget one uid in a test (assignment, exposures, conversions). Needs form:write; audit logged. */
|
|
911
|
+
removeParticipant(id, uid, o) {
|
|
912
|
+
return this.h.data("DELETE", `/experiments/${id}/participants/${encodeURIComponent(uid)}`, o);
|
|
913
|
+
}
|
|
914
|
+
delete(id, o) {
|
|
915
|
+
return this.h.data("DELETE", `/experiments/${id}`, o);
|
|
916
|
+
}
|
|
917
|
+
start(id, o) {
|
|
918
|
+
return this.h.data("PATCH", `/experiments/${id}`, { body: { action: "start" }, ...o });
|
|
919
|
+
}
|
|
920
|
+
stop(id, o) {
|
|
921
|
+
return this.h.data("PATCH", `/experiments/${id}`, { body: { action: "stop" }, ...o });
|
|
922
|
+
}
|
|
923
|
+
/** `promote: false` only marks the winner and stops the test. */
|
|
924
|
+
declareWinner(id, variantId, promote, o) {
|
|
925
|
+
return this.h.data("PATCH", `/experiments/${id}`, { body: { action: "winner", variantId, promote }, ...o });
|
|
926
|
+
}
|
|
927
|
+
/** Keeps the winning version per segment as permanent targeting rules and ends the test. */
|
|
928
|
+
personalize(id, body = {}, o) {
|
|
929
|
+
return this.h.data("PATCH", `/experiments/${id}`, { body: { action: "personalize", ...body }, ...o });
|
|
930
|
+
}
|
|
931
|
+
results(id, o) {
|
|
932
|
+
return this.h.data("GET", `/experiments/${id}/results`, o);
|
|
933
|
+
}
|
|
934
|
+
/** Report a downstream goal for a user from your backend (key needs form:write). `uid` is the id your app passes to the form. */
|
|
935
|
+
reportConversion(id, body, o) {
|
|
936
|
+
return this.h.data("POST", `/experiments/${id}/conversions`, { body, ...o });
|
|
937
|
+
}
|
|
938
|
+
explain(id, o) {
|
|
939
|
+
return this.h.data("POST", `/experiments/${id}/ai/explain`, { body: {}, ...o });
|
|
940
|
+
}
|
|
941
|
+
suggest(id, o) {
|
|
942
|
+
return this.h.data("POST", `/experiments/${id}/ai/suggest`, { body: {}, ...o });
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
// src/resources/destinations.ts
|
|
947
|
+
var DestinationsResource = class {
|
|
948
|
+
constructor(h) {
|
|
949
|
+
this.h = h;
|
|
950
|
+
}
|
|
951
|
+
list(o) {
|
|
952
|
+
return this.h.data("GET", "/destinations", o);
|
|
953
|
+
}
|
|
954
|
+
create(body, o) {
|
|
955
|
+
return this.h.data("POST", "/destinations", { body, ...o });
|
|
956
|
+
}
|
|
957
|
+
update(id, body, o) {
|
|
958
|
+
return this.h.data("PATCH", `/destinations/${id}`, { body, ...o });
|
|
959
|
+
}
|
|
960
|
+
delete(id, o) {
|
|
961
|
+
return this.h.data("DELETE", `/destinations/${id}`, o);
|
|
962
|
+
}
|
|
963
|
+
/** Requeue this destination's dead deliveries. */
|
|
964
|
+
retry(id, o) {
|
|
965
|
+
return this.h.data("POST", `/destinations/${id}/retry`, { body: {}, ...o });
|
|
966
|
+
}
|
|
967
|
+
/** Sends one clearly labelled test event. */
|
|
968
|
+
test(id, o) {
|
|
969
|
+
return this.h.data("POST", `/destinations/${id}/test`, { body: {}, ...o });
|
|
970
|
+
}
|
|
971
|
+
getFormSettings(formId, o) {
|
|
972
|
+
return this.h.data("GET", `/forms/${formId}/analytics-settings`, o);
|
|
973
|
+
}
|
|
974
|
+
putFormSettings(formId, body, o) {
|
|
975
|
+
return this.h.data("PUT", `/forms/${formId}/analytics-settings`, { body, ...o });
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
// src/resources/onboarding.ts
|
|
980
|
+
var OnboardingResource = class {
|
|
981
|
+
constructor(h) {
|
|
982
|
+
this.h = h;
|
|
983
|
+
this.profileSources = {
|
|
984
|
+
list: (o) => this.h.data("GET", "/profile-sources", o),
|
|
985
|
+
create: (body, o) => this.h.data("POST", "/profile-sources", { body, ...o }),
|
|
986
|
+
update: (id, body, o) => this.h.data("PATCH", `/profile-sources/${id}`, { body, ...o }),
|
|
987
|
+
delete: (id, o) => this.h.data("DELETE", `/profile-sources/${id}`, o)
|
|
988
|
+
};
|
|
989
|
+
this.journeys = {
|
|
990
|
+
list: (o) => this.h.data("GET", "/journeys", o),
|
|
991
|
+
get: (id, o) => this.h.data("GET", `/journeys/${id}`, o),
|
|
992
|
+
create: (body, o) => this.h.data("POST", "/journeys", { body, ...o }),
|
|
993
|
+
update: (id, body, o) => this.h.data("PATCH", `/journeys/${id}`, { body, ...o }),
|
|
994
|
+
delete: (id, o) => this.h.data("DELETE", `/journeys/${id}`, o),
|
|
995
|
+
/** Report a product event (for example `first_project_created`) so stage entry conditions can see it. */
|
|
996
|
+
event: (id, body, o) => this.h.data("POST", `/journeys/${id}/events`, { body, ...o }),
|
|
997
|
+
analytics: (id, o) => this.h.data("GET", `/journeys/${id}/analytics`, o)
|
|
998
|
+
};
|
|
999
|
+
this.autopilot = {
|
|
1000
|
+
get: (experimentId, o) => this.h.data("GET", "/autopilot", { query: { experimentId }, ...o }),
|
|
1001
|
+
set: (body, o) => this.h.data("PUT", "/autopilot", { body, ...o }),
|
|
1002
|
+
actions: (q = {}, o) => this.h.data("GET", "/autopilot/actions", { query: q, ...o }),
|
|
1003
|
+
propose: (experimentId, o) => this.h.data("POST", "/autopilot/propose", { body: { experimentId }, ...o }),
|
|
1004
|
+
approve: (id, o) => this.h.data("POST", `/autopilot/actions/${id}/approve`, o),
|
|
1005
|
+
reject: (id, o) => this.h.data("POST", `/autopilot/actions/${id}/reject`, o)
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
/** For backends: the uid is trusted, no signature needed. Respondent apps use `client.public.decide`. */
|
|
1009
|
+
decide(body, o) {
|
|
1010
|
+
return this.h.data("POST", "/onboarding/decide", { body, ...o });
|
|
1011
|
+
}
|
|
1012
|
+
/** Describe your app and users; get a draft onboarding form, variant drafts with hypotheses and a suggested experiment. Nothing is published. */
|
|
1013
|
+
generate(body, o) {
|
|
1014
|
+
return this.h.data("POST", "/onboarding/generate", { body, ...o });
|
|
1015
|
+
}
|
|
1016
|
+
digest(body = {}, o) {
|
|
1017
|
+
return this.h.data("POST", "/onboarding/digest", { body, ...o });
|
|
1018
|
+
}
|
|
1019
|
+
/** AI themes in an open-text field, with counts and PII-free example quotes. */
|
|
1020
|
+
themes(formId, q = {}, o) {
|
|
1021
|
+
return this.h.data("GET", `/forms/${formId}/themes`, { query: q, ...o });
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
// src/resources/platform.ts
|
|
1026
|
+
var PlatformResource = class {
|
|
1027
|
+
constructor(h) {
|
|
1028
|
+
this.h = h;
|
|
1029
|
+
this.workspaces = {
|
|
1030
|
+
list: (o) => this.h.data("GET", "/workspaces", o),
|
|
1031
|
+
/** `bootstrapKey` also mints a first key for the new workspace, returned once as `data.bootstrapKey.key`. */
|
|
1032
|
+
create: (body, o) => this.h.data("POST", "/workspaces", { body, ...o })
|
|
1033
|
+
};
|
|
1034
|
+
this.folders = {
|
|
1035
|
+
list: (o) => this.h.data("GET", "/folders", o),
|
|
1036
|
+
create: (body, o) => this.h.data("POST", "/folders", { body, ...o }),
|
|
1037
|
+
update: (id, body, o) => this.h.data("PATCH", `/folders/${id}`, { body, ...o }),
|
|
1038
|
+
/** Forms inside move to the root. */
|
|
1039
|
+
delete: (id, o) => this.h.data("DELETE", `/folders/${id}`, o)
|
|
1040
|
+
};
|
|
1041
|
+
this.domains = {
|
|
1042
|
+
list: (o) => this.h.data("GET", "/domains", o),
|
|
1043
|
+
/** Returns the DNS records to create; then call `verify`. */
|
|
1044
|
+
add: (hostname, o) => this.h.data("POST", "/domains", { body: { hostname }, ...o }),
|
|
1045
|
+
verify: (id, o) => this.h.data("POST", `/domains/${id}/verify`, { body: {}, ...o }),
|
|
1046
|
+
remove: (id, o) => this.h.data("DELETE", `/domains/${id}`, o)
|
|
1047
|
+
};
|
|
1048
|
+
this.media = {
|
|
1049
|
+
list: (q = {}, o) => this.h.data("GET", "/media", { query: q, ...o }),
|
|
1050
|
+
/** Upload from base64 (about 1.3 MB of file) or have the server fetch a public `fromUrl`. Returns a stable `url`. Larger files: multipart POST /api/media. */
|
|
1051
|
+
upload: (body, o) => this.h.data("POST", "/media", { body, ...o }),
|
|
1052
|
+
/** Stock photo search. `enabled: false` means the server has no stock provider; show `credit` next to a photo. */
|
|
1053
|
+
stock: (q, o) => this.h.data("GET", "/media/stock", { query: q, ...o }),
|
|
1054
|
+
/** Upload bytes you hold (Uint8Array). */
|
|
1055
|
+
uploadBytes: (filename, bytes, meta = {}, o) => this.h.data("POST", "/media", { body: { filename, contentBase64: btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join("")), ...meta }, ...o }),
|
|
1056
|
+
/** Designs of the connected Canva account (connect Canva under Integrations first; `connectionId` null means not connected). */
|
|
1057
|
+
canvaDesigns: (q = {}, o) => this.h.data("GET", "/media/canva", { query: q, ...o }),
|
|
1058
|
+
/** Export one page of a Canva design to PNG or JPG and store it in the media library. */
|
|
1059
|
+
importCanva: (body, o) => this.h.data("POST", "/media/canva/import", { body, ...o })
|
|
1060
|
+
};
|
|
1061
|
+
this.integrations = {
|
|
1062
|
+
/** Providers with credential fields and action schemas. */
|
|
1063
|
+
providers: (o) => this.h.data("GET", "/integrations/providers", o),
|
|
1064
|
+
connections: {
|
|
1065
|
+
list: (o) => this.h.data("GET", "/integrations/connections", o),
|
|
1066
|
+
/** API-key and webhook-URL providers. OAuth providers connect in the app. Credentials are never returned. */
|
|
1067
|
+
create: (body, o) => this.h.data("POST", "/integrations/connections", { body, ...o }),
|
|
1068
|
+
update: (id, body, o) => this.h.data("PATCH", `/integrations/connections/${id}`, { body, ...o }),
|
|
1069
|
+
delete: (id, o) => this.h.data("DELETE", `/integrations/connections/${id}`, o),
|
|
1070
|
+
test: (id, o) => this.h.data("POST", `/integrations/connections/${id}/test`, { body: {}, ...o })
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
this.workflows = {
|
|
1074
|
+
list: (formId, o) => this.h.data("GET", "/workflows", { query: { formId }, ...o }),
|
|
1075
|
+
get: (id, o) => this.h.data("GET", `/workflows/${id}`, o),
|
|
1076
|
+
create: (body, o) => this.h.data("POST", "/workflows", { body, ...o }),
|
|
1077
|
+
update: (id, body, o) => this.h.data("PATCH", `/workflows/${id}`, { body, ...o }),
|
|
1078
|
+
delete: (id, o) => this.h.data("DELETE", `/workflows/${id}`, o),
|
|
1079
|
+
executions: (id, o) => this.h.data("GET", `/workflows/${id}/executions`, o)
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
|
|
1084
|
+
// src/resources/insights.ts
|
|
1085
|
+
var InsightsResource = class {
|
|
1086
|
+
constructor(h) {
|
|
1087
|
+
this.h = h;
|
|
1088
|
+
this.dashboards = {
|
|
1089
|
+
list: (o) => this.h.data("GET", "/dashboards", o),
|
|
1090
|
+
get: (id, o) => this.h.data("GET", `/dashboards/${id}`, o),
|
|
1091
|
+
create: (body, o) => this.h.data("POST", "/dashboards", { body, ...o }),
|
|
1092
|
+
update: (id, body, o) => this.h.data("PATCH", `/dashboards/${id}`, { body, ...o }),
|
|
1093
|
+
delete: (id, o) => this.h.data("DELETE", `/dashboards/${id}`, o),
|
|
1094
|
+
/** Every widget's computed data (summaries and metrics). */
|
|
1095
|
+
data: (id, o) => this.h.data("GET", `/dashboards/${id}/data`, o),
|
|
1096
|
+
/** enabled=true returns the public url and iframe snippet once. */
|
|
1097
|
+
share: (id, enabled, o) => this.h.data("POST", `/dashboards/${id}/share`, { body: { enabled }, ...o })
|
|
1098
|
+
};
|
|
1099
|
+
this.compareRules = {
|
|
1100
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/compare-rules`, o),
|
|
1101
|
+
save: (formId, body, o) => this.h.data("POST", `/forms/${formId}/compare-rules`, { body, ...o }),
|
|
1102
|
+
run: (ruleId, o) => this.h.data("GET", `/compare-rules/${ruleId}`, o),
|
|
1103
|
+
delete: (ruleId, o) => this.h.data("DELETE", `/compare-rules/${ruleId}`, o)
|
|
1104
|
+
};
|
|
1105
|
+
this.feeds = {
|
|
1106
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/feed-tokens`, o),
|
|
1107
|
+
/** The token and its csv / json / odata URLs are returned once. */
|
|
1108
|
+
create: (formId, name, o) => this.h.data("POST", `/forms/${formId}/feed-tokens`, { body: { name }, ...o }),
|
|
1109
|
+
revoke: (tokenId, o) => this.h.data("DELETE", `/feed-tokens/${tokenId}`, o)
|
|
1110
|
+
};
|
|
1111
|
+
this.grading = {
|
|
1112
|
+
queue: (formId, q, o) => this.h.data("GET", `/forms/${formId}/grading`, { query: q, ...o }),
|
|
1113
|
+
grade: (submissionId, body, o) => this.h.data("POST", `/submissions/${submissionId}/grade`, { body, ...o }),
|
|
1114
|
+
release: (formId, body = {}, o) => this.h.data("POST", `/forms/${formId}/grading/release`, { body, ...o })
|
|
1115
|
+
};
|
|
1116
|
+
this.tagRules = {
|
|
1117
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/tag-rules`, o),
|
|
1118
|
+
create: (formId, body, o) => this.h.data("POST", `/forms/${formId}/tag-rules`, { body, ...o }),
|
|
1119
|
+
update: (ruleId, body, o) => this.h.data("PATCH", `/tag-rules/${ruleId}`, { body, ...o }),
|
|
1120
|
+
delete: (ruleId, o) => this.h.data("DELETE", `/tag-rules/${ruleId}`, o),
|
|
1121
|
+
/** Tags the responses already collected. */
|
|
1122
|
+
apply: (formId, o) => this.h.data("POST", `/forms/${formId}/tag-rules/apply`, { body: {}, ...o })
|
|
1123
|
+
};
|
|
1124
|
+
this.comments = {
|
|
1125
|
+
list: (submissionId, o) => this.h.data("GET", `/submissions/${submissionId}/comments`, o),
|
|
1126
|
+
/** Mention a teammate with @email. */
|
|
1127
|
+
add: (submissionId, body, o) => this.h.data("POST", `/submissions/${submissionId}/comments`, { body: { body }, ...o }),
|
|
1128
|
+
delete: (commentId, o) => this.h.data("DELETE", `/comments/${commentId}`, o)
|
|
1129
|
+
};
|
|
1130
|
+
this.bulk = {
|
|
1131
|
+
/** Up to 100 per call; each item reports its own result. */
|
|
1132
|
+
create: (formId, items, o) => this.h.data("POST", `/forms/${formId}/submissions/bulk`, { body: { items }, ...o }),
|
|
1133
|
+
update: (items, o) => this.h.data("POST", "/submissions/bulk-update", { body: { items }, ...o }),
|
|
1134
|
+
delete: (ids, o) => this.h.data("POST", "/submissions/bulk-delete", { body: { ids }, ...o })
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
/** Crosstab with chi-square and per-cell significance. */
|
|
1138
|
+
significance(formId, q, o) {
|
|
1139
|
+
return this.h.data("GET", `/forms/${formId}/analytics/significance`, { query: { ...q, filters: q.filters ? JSON.stringify(q.filters) : void 0 }, ...o });
|
|
1140
|
+
}
|
|
1141
|
+
/** Ask a question about the results; returns an answer and suggested actions. */
|
|
1142
|
+
chat(formId, body, o) {
|
|
1143
|
+
return this.h.data("POST", `/forms/${formId}/ai/chat`, { body, ...o });
|
|
1144
|
+
}
|
|
1145
|
+
/** CSV text or base64 XLSX mapped to field ids. Use dryRun to validate first. */
|
|
1146
|
+
importResponses(formId, body, o) {
|
|
1147
|
+
return this.h.data("POST", `/forms/${formId}/import`, { body, ...o });
|
|
1148
|
+
}
|
|
1149
|
+
/** format: docx, pptx, spss and sav come back base64, html and print as text. */
|
|
1150
|
+
report(formId, format, filters, o) {
|
|
1151
|
+
return this.h.data("GET", `/forms/${formId}/report`, { query: { format, filters: filters ? JSON.stringify(filters) : void 0 }, ...o });
|
|
1152
|
+
}
|
|
1153
|
+
/** Responses and team actions across the workspace. */
|
|
1154
|
+
activity(days = 30, o) {
|
|
1155
|
+
return this.h.data("GET", "/activity", { query: { days }, ...o });
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
// src/resources/library.ts
|
|
1160
|
+
var LibraryResource = class {
|
|
1161
|
+
constructor(h) {
|
|
1162
|
+
this.h = h;
|
|
1163
|
+
this.optionLists = {
|
|
1164
|
+
list: (o) => this.h.data("GET", "/option-lists", o),
|
|
1165
|
+
get: (id, o) => this.h.data("GET", `/option-lists/${id}`, o),
|
|
1166
|
+
create: (body, o) => this.h.data("POST", "/option-lists", { body, ...o }),
|
|
1167
|
+
update: (id, body, o) => this.h.data("PATCH", `/option-lists/${id}`, { body, ...o }),
|
|
1168
|
+
delete: (id, o) => this.h.data("DELETE", `/option-lists/${id}`, o)
|
|
1169
|
+
};
|
|
1170
|
+
this.savedBlocks = {
|
|
1171
|
+
list: (q = {}, o) => this.h.data("GET", "/saved-blocks", { query: q, ...o }),
|
|
1172
|
+
/** Copy a field or section out of a form (formId + fieldId or sectionId), or pass a payload. */
|
|
1173
|
+
save: (body, o) => this.h.data("POST", "/saved-blocks", { body, ...o }),
|
|
1174
|
+
delete: (id, o) => this.h.data("DELETE", `/saved-blocks/${id}`, o),
|
|
1175
|
+
insert: (formId, body, o) => this.h.data("POST", `/forms/${formId}/insert-block`, { body, ...o })
|
|
1176
|
+
};
|
|
1177
|
+
this.community = {
|
|
1178
|
+
list: (q, o) => this.h.data("GET", "/community-templates", { query: q, ...o }),
|
|
1179
|
+
mine: (o) => this.h.data("GET", "/community-templates/mine", o),
|
|
1180
|
+
submit: (body, o) => this.h.data("POST", "/community-templates", { body, ...o }),
|
|
1181
|
+
use: (id, name, o) => this.h.data("POST", `/community-templates/${id}/use`, { body: { name }, ...o }),
|
|
1182
|
+
/** Platform administrators. */
|
|
1183
|
+
queue: (status, o) => this.h.data("GET", "/community-templates/moderation", { query: { status }, ...o }),
|
|
1184
|
+
moderate: (id, body, o) => this.h.data("PATCH", `/community-templates/${id}`, { body, ...o })
|
|
1185
|
+
};
|
|
1186
|
+
this.recordings = {
|
|
1187
|
+
list: (submissionId, o) => this.h.data("GET", `/submissions/${submissionId}/recordings`, o),
|
|
1188
|
+
transcribe: (submissionId, force, o) => this.h.data("POST", `/submissions/${submissionId}/transcribe`, { body: { force }, ...o }),
|
|
1189
|
+
/** Needs the respondent's consent (field.reuseConsentFieldId). Returns the public player url and an iframe snippet. */
|
|
1190
|
+
share: (submissionId, fileId, o) => this.h.data("POST", `/submissions/${submissionId}/recordings/${fileId}/share`, o),
|
|
1191
|
+
unshare: (submissionId, fileId, o) => this.h.data("DELETE", `/submissions/${submissionId}/recordings/${fileId}/share`, o)
|
|
1192
|
+
};
|
|
1193
|
+
/** Workspace tables not tied to a form. Forms read from them (data sources with tableId) and write to them (settings.tableWrite). */
|
|
1194
|
+
this.tables = {
|
|
1195
|
+
list: (o) => this.h.data("GET", "/tables", o),
|
|
1196
|
+
get: (id, o) => this.h.data("GET", `/tables/${id}`, o),
|
|
1197
|
+
create: (body, o) => this.h.data("POST", "/tables", { body, ...o }),
|
|
1198
|
+
update: (id, body, o) => this.h.data("PATCH", `/tables/${id}`, { body, ...o }),
|
|
1199
|
+
delete: (id, o) => this.h.data("DELETE", `/tables/${id}`, o),
|
|
1200
|
+
/** `sort` is `column:asc|desc`; `filters` run in SQL. */
|
|
1201
|
+
rows: (id, q = {}, o) => this.h.page(`/tables/${id}/rows`, { ...q, filters: q.filters ? JSON.stringify(q.filters) : void 0 }, o),
|
|
1202
|
+
/** Update (`set`) or delete every row matching at least one filter, all or nothing. */
|
|
1203
|
+
bulkRows: (id, body, o) => this.h.data("POST", `/tables/${id}/rows/bulk`, { body, ...o }),
|
|
1204
|
+
rowHistory: (id, rowId, o) => this.h.data("GET", `/tables/${id}/rows/${rowId}/history`, o),
|
|
1205
|
+
addRows: (id, rows, o) => this.h.data("POST", `/tables/${id}/rows`, { body: rows, ...o }),
|
|
1206
|
+
updateRow: (id, rowId, cells, o) => this.h.data("PATCH", `/tables/${id}/rows/${rowId}`, { body: cells, ...o }),
|
|
1207
|
+
deleteRow: (id, rowId, o) => this.h.data("DELETE", `/tables/${id}/rows/${rowId}`, o),
|
|
1208
|
+
importCsv: (id, csv2, o) => this.h.data("POST", `/tables/${id}/import`, { body: { csv: csv2 }, ...o }),
|
|
1209
|
+
exportCsv: (id, o) => this.h.data("GET", `/tables/${id}/export`, o)
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
/** Run a form's saved logic scenarios (settings.logicTests) against its draft. Publishing runs them too. */
|
|
1213
|
+
runLogicTests(formId, o) {
|
|
1214
|
+
return this.h.data("POST", `/forms/${formId}/logic-tests/run`, o);
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
// src/resources/distribution.ts
|
|
1219
|
+
var DistributionResource = class {
|
|
1220
|
+
constructor(h) {
|
|
1221
|
+
this.h = h;
|
|
1222
|
+
this.contacts = {
|
|
1223
|
+
list: (q, o) => this.h.data("GET", "/contacts", { query: q, ...o }),
|
|
1224
|
+
/** Creates the contact, or updates the one with the same email (tags and attributes merge). */
|
|
1225
|
+
upsert: (body, o) => this.h.data("POST", "/contacts", { body, ...o }),
|
|
1226
|
+
/** Profile with lists, invitations and the responses linked to this contact. */
|
|
1227
|
+
get: (id, o) => this.h.data("GET", `/contacts/${id}`, o),
|
|
1228
|
+
update: (id, body, o) => this.h.data("PATCH", `/contacts/${id}`, { body, ...o }),
|
|
1229
|
+
delete: (id, o) => this.h.data("DELETE", `/contacts/${id}`, o),
|
|
1230
|
+
/** CSV text (header: email, phone, name, language, tags; other columns become attributes) or an array. */
|
|
1231
|
+
import: (body, o) => this.h.data("POST", "/contacts/import", { body, ...o })
|
|
1232
|
+
};
|
|
1233
|
+
this.lists = {
|
|
1234
|
+
list: (o) => this.h.data("GET", "/contact-lists", o),
|
|
1235
|
+
create: (name, o) => this.h.data("POST", "/contact-lists", { body: { name }, ...o }),
|
|
1236
|
+
delete: (id, o) => this.h.data("DELETE", `/contact-lists/${id}`, o),
|
|
1237
|
+
members: (id, body, o) => this.h.data("POST", `/contact-lists/${id}/members`, { body, ...o })
|
|
1238
|
+
};
|
|
1239
|
+
this.sends = {
|
|
1240
|
+
list: (formId, o) => this.h.data("GET", `/forms/${formId}/distributions`, o),
|
|
1241
|
+
/** Send a form to a list now, at `sendAt`, or on a cadence. Opted-out contacts are skipped. */
|
|
1242
|
+
create: (formId, body, o) => this.h.data("POST", `/forms/${formId}/distributions`, { body, ...o }),
|
|
1243
|
+
cancel: (id, o) => this.h.data("DELETE", `/distributions/${id}`, o)
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
/** Enter a response on someone's behalf (paper form, phone call). It is marked manual in its metadata. */
|
|
1247
|
+
manualResponse(formId, body, o) {
|
|
1248
|
+
return this.h.data("POST", `/forms/${formId}/manual-response`, { body, ...o });
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
// src/resources/programs.ts
|
|
1253
|
+
var ProgramsResource = class {
|
|
1254
|
+
constructor(h) {
|
|
1255
|
+
this.h = h;
|
|
1256
|
+
this.programs = {
|
|
1257
|
+
list: (formId, o) => this.h.data("GET", "/programs", { query: { formId }, ...o }),
|
|
1258
|
+
/** Scheduled programs (weekly, monthly, quarterly) start their own waves; a manual program starts one when you call `startWave`. */
|
|
1259
|
+
create: (body, o) => this.h.data("POST", "/programs", { body, ...o }),
|
|
1260
|
+
get: (id, o) => this.h.data("GET", `/programs/${id}`, o),
|
|
1261
|
+
update: (id, body, o) => this.h.data("PATCH", `/programs/${id}`, { body, ...o }),
|
|
1262
|
+
delete: (id, o) => this.h.data("DELETE", `/programs/${id}`, o),
|
|
1263
|
+
/** Starts the next wave; with a list on the program it also sends the form to that list. */
|
|
1264
|
+
startWave: (id, body = {}, o) => this.h.data("POST", `/programs/${id}/waves`, { body, ...o }),
|
|
1265
|
+
/** Counts, averages, NPS and choice shares per wave for every comparable question, each with the change vs the previous wave. */
|
|
1266
|
+
trend: (id, q, o) => this.h.data("GET", `/programs/${id}/trend`, { query: { fieldIds: q?.fieldIds?.join(","), waves: q?.waves }, ...o })
|
|
1267
|
+
};
|
|
1268
|
+
this.hris = {
|
|
1269
|
+
/** Pulls current employees from a BambooHR integration connection into contact attributes. */
|
|
1270
|
+
syncBambooHr: (connectionId, o) => this.h.data("POST", "/hris/sync", { body: { source: "bamboohr", connectionId }, ...o }),
|
|
1271
|
+
/** SCIM 2.0 User resources or a CSV export (any HRIS; for Workday, export its report as CSV). `mapping` is { segmentKey: columnName }. */
|
|
1272
|
+
import: (body, o) => this.h.data("POST", "/hris/import", { body, ...o }),
|
|
1273
|
+
/** One question split by a contact attribute. Groups smaller than `minGroup` (default 5) come back without a summary. */
|
|
1274
|
+
/** Stored sources. `create` and `update` with rotateScimToken return the SCIM bearer `scimToken` once; point a directory at `scimUrl` (SCIM 2.0 /Users). */
|
|
1275
|
+
connections: {
|
|
1276
|
+
list: (o) => this.h.data("GET", "/hris/connections", o),
|
|
1277
|
+
create: (body, o) => this.h.data("POST", "/hris/connections", { body, ...o }),
|
|
1278
|
+
update: (id, body, o) => this.h.data("PATCH", `/hris/connections/${id}`, { body, ...o }),
|
|
1279
|
+
delete: (id, o) => this.h.data("DELETE", `/hris/connections/${id}`, o),
|
|
1280
|
+
/** Pulls a BambooHR source now with its saved settings. */
|
|
1281
|
+
sync: (id, o) => this.h.data("POST", `/hris/connections/${id}/sync`, { body: {}, ...o }),
|
|
1282
|
+
/** Uploads a CSV through a csv source; `mapping` is saved for the next upload. */
|
|
1283
|
+
importCsv: (id, body, o) => this.h.data("POST", `/hris/connections/${id}/import`, { body, ...o }),
|
|
1284
|
+
runs: (id, o) => this.h.data("GET", `/hris/connections/${id}/runs`, o)
|
|
1285
|
+
},
|
|
1286
|
+
/** Column-mapping step: headers, sample rows and the suggested { segmentKey: column } mapping. */
|
|
1287
|
+
previewCsv: (csv2, o) => this.h.data("POST", "/hris/preview", { body: { csv: csv2 }, ...o }),
|
|
1288
|
+
breakdown: (formId, q, o) => this.h.data("GET", `/forms/${formId}/attribute-breakdown`, { query: q, ...o })
|
|
1289
|
+
};
|
|
1290
|
+
this.crmTriggers = {
|
|
1291
|
+
list: (o) => this.h.data("GET", "/crm-triggers", o),
|
|
1292
|
+
/** The signing `secret` is in this response only. Sign each CRM call: `X-FormFlow-Signature: t=<unix s>,v1=<hex HMAC-SHA256(secret, t + "." + body)>`. */
|
|
1293
|
+
create: (body, o) => this.h.data("POST", "/crm-triggers", { body, ...o }),
|
|
1294
|
+
/** `rotateSecret` returns a new signing secret once; the old one stops working. */
|
|
1295
|
+
update: (id, body, o) => this.h.data("PATCH", `/crm-triggers/${id}`, { body, ...o }),
|
|
1296
|
+
/** Delivery log, newest first. */
|
|
1297
|
+
events: (id, o) => this.h.data("GET", `/crm-triggers/${id}/events`, o),
|
|
1298
|
+
/** Creates the "write answers back" workflow: on each response, send the email and chosen answers to a CRM integration action. */
|
|
1299
|
+
writeBack: (id, body, o) => this.h.data("POST", `/crm-triggers/${id}/write-back`, { body, ...o }),
|
|
1300
|
+
delete: (id, o) => this.h.data("DELETE", `/crm-triggers/${id}`, o)
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
// src/resources/admin.ts
|
|
1306
|
+
var AdminResource = class {
|
|
1307
|
+
constructor(h) {
|
|
1308
|
+
this.h = h;
|
|
1309
|
+
/** Who may open and answer a published form, plus per-form IP lists. */
|
|
1310
|
+
this.formAccess = {
|
|
1311
|
+
get: (formId, o) => this.h.data("GET", `/forms/${formId}/access`, o),
|
|
1312
|
+
set: (formId, body, o) => this.h.data("PUT", `/forms/${formId}/access`, { body, ...o })
|
|
1313
|
+
};
|
|
1314
|
+
this.tags = {
|
|
1315
|
+
list: (o) => this.h.data("GET", "/tags", o),
|
|
1316
|
+
get: (formId, o) => this.h.data("GET", `/forms/${formId}/tags`, o),
|
|
1317
|
+
set: (formId, tags, o) => this.h.data("PUT", `/forms/${formId}/tags`, { body: { tags }, ...o })
|
|
1318
|
+
};
|
|
1319
|
+
/** Team template library. */
|
|
1320
|
+
this.templates = {
|
|
1321
|
+
list: (o) => this.h.data("GET", "/workspace-templates", o),
|
|
1322
|
+
get: (id, o) => this.h.data("GET", `/workspace-templates/${id}`, o),
|
|
1323
|
+
save: (body, o) => this.h.data("POST", "/workspace-templates", { body, ...o }),
|
|
1324
|
+
update: (id, body, o) => this.h.data("PATCH", `/workspace-templates/${id}`, { body, ...o }),
|
|
1325
|
+
delete: (id, o) => this.h.data("DELETE", `/workspace-templates/${id}`, o),
|
|
1326
|
+
use: (id, body = {}, o) => this.h.data("POST", `/workspace-templates/${id}/use`, { body, ...o })
|
|
1327
|
+
};
|
|
1328
|
+
this.security = {
|
|
1329
|
+
get: (o) => this.h.data("GET", "/org/security", o),
|
|
1330
|
+
update: (body, o) => this.h.data("PUT", "/org/security", { body, ...o })
|
|
1331
|
+
};
|
|
1332
|
+
this.brandKit = {
|
|
1333
|
+
get: (o) => this.h.data("GET", "/org/brand-kit", o),
|
|
1334
|
+
set: (body, o) => this.h.data("PUT", "/org/brand-kit", { body, ...o })
|
|
1335
|
+
};
|
|
1336
|
+
/** Domain-enforced account join: claim a domain, publish the TXT record, verify; members of the domain join automatically or after approval. */
|
|
1337
|
+
this.domainJoin = {
|
|
1338
|
+
get: (o) => this.h.data("GET", "/org/domain-join", o),
|
|
1339
|
+
update: (body, o) => this.h.data("PATCH", "/org/domain-join", { body, ...o }),
|
|
1340
|
+
addDomain: (domain, o) => this.h.data("POST", "/org/domain-join/domains", { body: { domain }, ...o }),
|
|
1341
|
+
verifyDomain: (domain, o) => this.h.data("POST", "/org/domain-join/domains/verify", { body: { domain }, ...o }),
|
|
1342
|
+
removeDomain: (domain, o) => this.h.data("DELETE", "/org/domain-join/domains", { query: { domain }, ...o }),
|
|
1343
|
+
requests: (status, o) => this.h.data("GET", "/org/join-requests", { query: { status }, ...o }),
|
|
1344
|
+
decide: (id, decision, o) => this.h.data("POST", `/org/join-requests/${id}`, { body: { decision }, ...o })
|
|
1345
|
+
};
|
|
1346
|
+
this.roles = {
|
|
1347
|
+
list: (o) => this.h.data("GET", "/org/roles", o),
|
|
1348
|
+
create: (body, o) => this.h.data("POST", "/org/roles", { body, ...o }),
|
|
1349
|
+
update: (id, body, o) => this.h.data("PATCH", `/org/roles/${id}`, { body, ...o }),
|
|
1350
|
+
delete: (id, o) => this.h.data("DELETE", `/org/roles/${id}`, o),
|
|
1351
|
+
/** Give a member a custom role (null removes it) and/or make them a guest limited to grants. */
|
|
1352
|
+
assign: (membershipId, body, o) => this.h.data("PUT", `/org/members/${membershipId}/access`, { body, ...o })
|
|
1353
|
+
};
|
|
1354
|
+
this.groups = {
|
|
1355
|
+
list: (o) => this.h.data("GET", "/org/groups", o),
|
|
1356
|
+
create: (name, o) => this.h.data("POST", "/org/groups", { body: { name }, ...o }),
|
|
1357
|
+
rename: (id, name, o) => this.h.data("PATCH", `/org/groups/${id}`, { body: { name }, ...o }),
|
|
1358
|
+
delete: (id, o) => this.h.data("DELETE", `/org/groups/${id}`, o),
|
|
1359
|
+
setMembers: (id, userIds, o) => this.h.data("PUT", `/org/groups/${id}/members`, { body: { userIds }, ...o })
|
|
1360
|
+
};
|
|
1361
|
+
this.grants = {
|
|
1362
|
+
list: (q = {}, o) => this.h.data("GET", "/org/grants", { query: q, ...o }),
|
|
1363
|
+
create: (body, o) => this.h.data("POST", "/org/grants", { body, ...o }),
|
|
1364
|
+
delete: (id, o) => this.h.data("DELETE", `/org/grants/${id}`, o)
|
|
1365
|
+
};
|
|
1366
|
+
/** Dead-letter view of background jobs. Platform administrators only. */
|
|
1367
|
+
this.jobs = {
|
|
1368
|
+
list: (q = {}, o) => this.h.data("GET", "/admin/jobs", { query: q, ...o }),
|
|
1369
|
+
requeue: (id, o) => this.h.data("POST", `/admin/jobs/${id}/requeue`, { body: {}, ...o })
|
|
1370
|
+
};
|
|
1371
|
+
/** Partner and reseller provisioning. */
|
|
1372
|
+
this.partner = {
|
|
1373
|
+
setStatus: (organizationId, enabled, o) => this.h.data("PUT", "/org/partner", { body: { organizationId, enabled }, ...o }),
|
|
1374
|
+
organizations: {
|
|
1375
|
+
list: (o) => this.h.data("GET", "/org/partner/organizations", o),
|
|
1376
|
+
create: (body, o) => this.h.data("POST", "/org/partner/organizations", { body, ...o }),
|
|
1377
|
+
delete: (id, o) => this.h.data("DELETE", `/org/partner/organizations/${id}`, o),
|
|
1378
|
+
createWorkspace: (id, name, o) => this.h.data("POST", `/org/partner/organizations/${id}/workspaces`, { body: { name }, ...o })
|
|
1379
|
+
},
|
|
1380
|
+
keys: {
|
|
1381
|
+
list: (organizationId, workspaceId, o) => this.h.data("GET", `/org/partner/organizations/${organizationId}/keys`, { query: { workspaceId }, ...o }),
|
|
1382
|
+
/** The secret is returned once in `key`. */
|
|
1383
|
+
issue: (organizationId, body, o) => this.h.data("POST", `/org/partner/organizations/${organizationId}/keys`, { body, ...o }),
|
|
1384
|
+
revoke: (organizationId, workspaceId, keyId, o) => this.h.data("DELETE", `/org/partner/organizations/${organizationId}/keys/${keyId}`, { query: { workspaceId }, ...o })
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
/** Move (not copy) a form with its responses to another workspace of the same organization. */
|
|
1389
|
+
moveForm(formId, workspaceId, opts = {}, o) {
|
|
1390
|
+
return this.h.data("POST", `/forms/${formId}/move`, { body: { workspaceId, ...opts }, ...o });
|
|
1391
|
+
}
|
|
1392
|
+
/** Workspace default theme (preset id or saved theme id; null clears it). */
|
|
1393
|
+
setDefaultTheme(defaultThemeId, o) {
|
|
1394
|
+
return this.h.data("PATCH", "/workspaces/current", { body: { defaultThemeId }, ...o });
|
|
1395
|
+
}
|
|
1396
|
+
/** IANA timezone (e.g. "America/New_York") for day buckets and date ranges in results and analytics; null = UTC. */
|
|
1397
|
+
setTimezone(timezone, o) {
|
|
1398
|
+
return this.h.data("PATCH", "/workspaces/current", { body: { timezone }, ...o });
|
|
1399
|
+
}
|
|
1400
|
+
/** Remove a member; transferTo hands over their forms, views, schedules and templates. */
|
|
1401
|
+
removeMember(membershipId, transferTo, o) {
|
|
1402
|
+
return this.h.data("DELETE", `/members/${membershipId}`, { query: { transferTo }, ...o });
|
|
1403
|
+
}
|
|
1404
|
+
/** Email delivery log. */
|
|
1405
|
+
emailLog(q = {}, o) {
|
|
1406
|
+
return this.h.page("/org/email-log", q, o);
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
// src/client.ts
|
|
1411
|
+
var FormFlowClient = class {
|
|
1412
|
+
constructor(o) {
|
|
1413
|
+
this.http = new HttpClient(o);
|
|
1414
|
+
this.forms = new FormsResource(this.http);
|
|
1415
|
+
this.submissions = new SubmissionsResource(this.http);
|
|
1416
|
+
this.themes = new ThemesResource(this.http);
|
|
1417
|
+
this.templates = new TemplatesResource(this.http);
|
|
1418
|
+
this.webhooks = new WebhooksResource(this.http);
|
|
1419
|
+
this.analytics = new AnalyticsResource(this.http);
|
|
1420
|
+
this.ai = new AiResource(this.http);
|
|
1421
|
+
this.exports = new ExportsResource(this.http);
|
|
1422
|
+
this.account = new AccountResource(this.http);
|
|
1423
|
+
this.results = new ResultsResource(this.http);
|
|
1424
|
+
this.payments = new PaymentsResource(this.http);
|
|
1425
|
+
this.scheduling = new SchedulingResource(this.http);
|
|
1426
|
+
this.workflows = new WorkflowsResource(this.http);
|
|
1427
|
+
this.experiments = new ExperimentsResource(this.http);
|
|
1428
|
+
this.destinations = new DestinationsResource(this.http);
|
|
1429
|
+
this.onboarding = new OnboardingResource(this.http);
|
|
1430
|
+
this.platform = new PlatformResource(this.http);
|
|
1431
|
+
this.insights = new InsightsResource(this.http);
|
|
1432
|
+
this.library = new LibraryResource(this.http);
|
|
1433
|
+
this.distribution = new DistributionResource(this.http);
|
|
1434
|
+
this.programs = new ProgramsResource(this.http);
|
|
1435
|
+
this.admin = new AdminResource(this.http);
|
|
1436
|
+
this.public = new PublicClient({ baseUrl: this.http.opts.baseUrl, fetch: o.fetch });
|
|
1437
|
+
}
|
|
1438
|
+
/** Escape hatch for endpoints without a typed method. */
|
|
1439
|
+
request(method, path, init) {
|
|
1440
|
+
return this.http.request(method, path, init);
|
|
1441
|
+
}
|
|
1442
|
+
/** Auto-paginate any list endpoint. */
|
|
1443
|
+
paginate(path, q, o) {
|
|
1444
|
+
return this.http.paginate(path, q, o);
|
|
1445
|
+
}
|
|
1446
|
+
// Backward-compatible shortcuts (SDK v1 surface).
|
|
1447
|
+
get members() {
|
|
1448
|
+
return this.account.members;
|
|
1449
|
+
}
|
|
1450
|
+
get apiKeys() {
|
|
1451
|
+
return this.account.apiKeys;
|
|
1452
|
+
}
|
|
1453
|
+
get auditEvents() {
|
|
1454
|
+
return this.account.auditEvents;
|
|
1455
|
+
}
|
|
1456
|
+
get usage() {
|
|
1457
|
+
return { get: (period) => this.account.usage(period) };
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
|
|
1461
|
+
// src/webhooks.ts
|
|
1462
|
+
var enc = new TextEncoder();
|
|
1463
|
+
function hex(buf) {
|
|
1464
|
+
return Array.from(new Uint8Array(buf), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1465
|
+
}
|
|
1466
|
+
function constantTimeEqual(a, b) {
|
|
1467
|
+
if (a.length !== b.length) return false;
|
|
1468
|
+
let diff = 0;
|
|
1469
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
1470
|
+
return diff === 0;
|
|
1471
|
+
}
|
|
1472
|
+
async function signWebhookPayload(payload, secret, timestamp) {
|
|
1473
|
+
const key = await crypto.subtle.importKey("raw", enc.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
1474
|
+
return hex(await crypto.subtle.sign("HMAC", key, enc.encode(`${timestamp}.${payload}`)));
|
|
1475
|
+
}
|
|
1476
|
+
async function verifyWebhookSignature(payload, header, secret, toleranceSec = 300, nowSec = Math.floor(Date.now() / 1e3)) {
|
|
1477
|
+
if (!header) return false;
|
|
1478
|
+
const parts = header.split(",").map((p) => p.trim().split("="));
|
|
1479
|
+
const t = Number(parts.find(([k]) => k === "t")?.[1]);
|
|
1480
|
+
if (!Number.isFinite(t) || Math.abs(nowSec - t) > toleranceSec) return false;
|
|
1481
|
+
const expected = await signWebhookPayload(payload, secret, t);
|
|
1482
|
+
return parts.some(([k, v]) => k === "v1" && typeof v === "string" && constantTimeEqual(v, expected));
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// src/webhook-events.ts
|
|
1486
|
+
async function constructWebhookEvent(rawBody, signatureHeader, secret, toleranceSec = 300) {
|
|
1487
|
+
if (!await verifyWebhookSignature(rawBody, signatureHeader, secret, toleranceSec)) throw new FormFlowError(400, "invalid_signature", "Webhook signature verification failed");
|
|
1488
|
+
try {
|
|
1489
|
+
return JSON.parse(rawBody);
|
|
1490
|
+
} catch {
|
|
1491
|
+
throw new FormFlowError(400, "invalid_payload", "Webhook body is not JSON");
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
var isEvent = (e, type) => e.type === type;
|
|
1495
|
+
|
|
1496
|
+
// src/builder.ts
|
|
1497
|
+
var slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 40) || "choice";
|
|
1498
|
+
var ID = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;
|
|
1499
|
+
function choices(items) {
|
|
1500
|
+
const used = /* @__PURE__ */ new Set();
|
|
1501
|
+
return items.map((c, i) => {
|
|
1502
|
+
const o = typeof c === "string" ? { label: c } : c;
|
|
1503
|
+
let id = o.id ?? slug(o.label);
|
|
1504
|
+
if (!/^[a-zA-Z]/.test(id)) id = `c_${id}`;
|
|
1505
|
+
while (used.has(id)) id = `${id}_${i}`;
|
|
1506
|
+
used.add(id);
|
|
1507
|
+
return { ...o, id };
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
var FormBuilder = class {
|
|
1511
|
+
constructor(title) {
|
|
1512
|
+
this.ids = /* @__PURE__ */ new Set();
|
|
1513
|
+
this.section = null;
|
|
1514
|
+
this.def = { schemaVersion: 1, title, fields: [], sections: [], logic: [], endings: [] };
|
|
1515
|
+
}
|
|
1516
|
+
description(text) {
|
|
1517
|
+
this.def.description = text;
|
|
1518
|
+
return this;
|
|
1519
|
+
}
|
|
1520
|
+
welcome(w) {
|
|
1521
|
+
this.def.welcome = w;
|
|
1522
|
+
return this;
|
|
1523
|
+
}
|
|
1524
|
+
settings(s) {
|
|
1525
|
+
this.def.settings = { ...this.def.settings, ...s };
|
|
1526
|
+
return this;
|
|
1527
|
+
}
|
|
1528
|
+
theme(t) {
|
|
1529
|
+
this.def.theme = { ...this.def.theme, ...t, colors: { ...this.def.theme?.colors, ...t.colors } };
|
|
1530
|
+
return this;
|
|
1531
|
+
}
|
|
1532
|
+
/** Start a new section/page; following fields go into it. */
|
|
1533
|
+
startSection(id, title) {
|
|
1534
|
+
this.section = { id, title, fieldIds: [] };
|
|
1535
|
+
this.def.sections.push(this.section);
|
|
1536
|
+
return this;
|
|
1537
|
+
}
|
|
1538
|
+
logic(rule) {
|
|
1539
|
+
this.def.logic.push(rule);
|
|
1540
|
+
return this;
|
|
1541
|
+
}
|
|
1542
|
+
ending(title, body, extra = {}) {
|
|
1543
|
+
this.def.endings.push({ id: extra.id ?? `ending${this.def.endings.length + 1}`, title, body, ...extra });
|
|
1544
|
+
return this;
|
|
1545
|
+
}
|
|
1546
|
+
/** Show `fieldId` only when the condition holds. */
|
|
1547
|
+
showWhen(fieldId, when) {
|
|
1548
|
+
const f = this.def.fields.find((x) => x.id === fieldId);
|
|
1549
|
+
if (!f) throw new Error(`showWhen: unknown field "${fieldId}"`);
|
|
1550
|
+
f.visibleWhen = when;
|
|
1551
|
+
return this;
|
|
1552
|
+
}
|
|
1553
|
+
/** Any field type. Prefer the typed helpers below. */
|
|
1554
|
+
field(type, id, label, opts = {}) {
|
|
1555
|
+
if (!ID.test(id)) throw new Error(`Invalid field id "${id}": start with a letter; use letters, digits, _ or -`);
|
|
1556
|
+
if (this.ids.has(id)) throw new Error(`Duplicate field id "${id}"`);
|
|
1557
|
+
this.ids.add(id);
|
|
1558
|
+
this.def.fields.push({ id, type, label, ...opts });
|
|
1559
|
+
this.section?.fieldIds.push(id);
|
|
1560
|
+
return this;
|
|
1561
|
+
}
|
|
1562
|
+
shortText(id, label, o = {}) {
|
|
1563
|
+
return this.field("short_text", id, label, o);
|
|
1564
|
+
}
|
|
1565
|
+
longText(id, label, o = {}) {
|
|
1566
|
+
return this.field("long_text", id, label, o);
|
|
1567
|
+
}
|
|
1568
|
+
email(id, label, o = {}) {
|
|
1569
|
+
return this.field("email", id, label, o);
|
|
1570
|
+
}
|
|
1571
|
+
phone(id, label, o = {}) {
|
|
1572
|
+
return this.field("phone", id, label, o);
|
|
1573
|
+
}
|
|
1574
|
+
url(id, label, o = {}) {
|
|
1575
|
+
return this.field("url", id, label, o);
|
|
1576
|
+
}
|
|
1577
|
+
number(id, label, o = {}) {
|
|
1578
|
+
return this.field("decimal", id, label, o);
|
|
1579
|
+
}
|
|
1580
|
+
date(id, label, o = {}) {
|
|
1581
|
+
return this.field("date", id, label, o);
|
|
1582
|
+
}
|
|
1583
|
+
yesNo(id, label, o = {}) {
|
|
1584
|
+
return this.field("yes_no", id, label, o);
|
|
1585
|
+
}
|
|
1586
|
+
/** Single choice by default; `{ multiple: true }` for multiple, `{ as: "dropdown" }` for a dropdown. */
|
|
1587
|
+
choice(id, label, items, o = {}) {
|
|
1588
|
+
const { multiple, as, ...rest } = o;
|
|
1589
|
+
return this.field(as ?? (multiple ? "multiple_choice" : "single_choice"), id, label, { ...rest, choices: choices(items) });
|
|
1590
|
+
}
|
|
1591
|
+
rating(id, label, o = {}) {
|
|
1592
|
+
return this.field("star_rating", id, label, { max: 5, ...o });
|
|
1593
|
+
}
|
|
1594
|
+
nps(id, label = "How likely are you to recommend us to a friend or colleague?", o = {}) {
|
|
1595
|
+
return this.field("nps", id, label, { minLabel: "Not likely", maxLabel: "Very likely", ...o });
|
|
1596
|
+
}
|
|
1597
|
+
csat(id, label, o = {}) {
|
|
1598
|
+
return this.field("csat", id, label, o);
|
|
1599
|
+
}
|
|
1600
|
+
fileUpload(id, label, o = {}) {
|
|
1601
|
+
return this.field("file_upload", id, label, o);
|
|
1602
|
+
}
|
|
1603
|
+
consent(id, label, text, o = {}) {
|
|
1604
|
+
return this.field("consent", id, label, { text, required: true, ...o });
|
|
1605
|
+
}
|
|
1606
|
+
statement(id, label, o = {}) {
|
|
1607
|
+
return this.field("statement", id, label, o);
|
|
1608
|
+
}
|
|
1609
|
+
hidden(id, param = id) {
|
|
1610
|
+
return this.field("hidden", id, id, { source: "url_param", param });
|
|
1611
|
+
}
|
|
1612
|
+
/** Field ids defined so far (for building logic rules). */
|
|
1613
|
+
get fieldIds() {
|
|
1614
|
+
return [...this.ids];
|
|
1615
|
+
}
|
|
1616
|
+
/** Returns a deep copy. Final validation (references, cycles) happens on the server at create/publish. */
|
|
1617
|
+
build() {
|
|
1618
|
+
if (!this.def.fields.length) throw new Error("A form needs at least one field");
|
|
1619
|
+
const out = structuredClone(this.def);
|
|
1620
|
+
if (!out.sections.length) delete out.sections;
|
|
1621
|
+
if (!out.logic.length) delete out.logic;
|
|
1622
|
+
if (!out.endings.length) delete out.endings;
|
|
1623
|
+
return out;
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
var form = (title) => new FormBuilder(title);
|
|
1627
|
+
|
|
1628
|
+
// src/encryption.ts
|
|
1629
|
+
var subtle = () => globalThis.crypto.subtle;
|
|
1630
|
+
var enc2 = new TextEncoder();
|
|
1631
|
+
var dec = new TextDecoder();
|
|
1632
|
+
var ENVELOPE_PREFIX = "ffenc1.";
|
|
1633
|
+
var MAX_ENVELOPE = 6e4;
|
|
1634
|
+
var RSA = { name: "RSA-OAEP", hash: "SHA-256" };
|
|
1635
|
+
var b64 = (b) => {
|
|
1636
|
+
const u = b instanceof Uint8Array ? b : new Uint8Array(b);
|
|
1637
|
+
let s = "";
|
|
1638
|
+
for (const x of u) s += String.fromCharCode(x);
|
|
1639
|
+
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1640
|
+
};
|
|
1641
|
+
var unb64 = (s) => {
|
|
1642
|
+
const p = atob(s.replace(/-/g, "+").replace(/_/g, "/"));
|
|
1643
|
+
const u = new Uint8Array(p.length);
|
|
1644
|
+
for (let i = 0; i < p.length; i++) u[i] = p.charCodeAt(i);
|
|
1645
|
+
return u;
|
|
1646
|
+
};
|
|
1647
|
+
async function keyIdOf(pub) {
|
|
1648
|
+
return b64(await subtle().digest("SHA-256", enc2.encode(`${pub.e}.${pub.n}`))).slice(0, 16);
|
|
1649
|
+
}
|
|
1650
|
+
async function generateKeyPair() {
|
|
1651
|
+
const kp = await subtle().generateKey({ ...RSA, modulusLength: 3072, publicExponent: new Uint8Array([1, 0, 1]) }, true, ["encrypt", "decrypt"]);
|
|
1652
|
+
const pub = await subtle().exportKey("jwk", kp.publicKey), priv = await subtle().exportKey("jwk", kp.privateKey);
|
|
1653
|
+
const clean = ({ kty, n, e }) => ({ kty, n, e });
|
|
1654
|
+
return { publicKeyJwk: clean(pub), privateKeyJwk: { ...priv, key_ops: void 0, ext: void 0 }, keyId: await keyIdOf(pub) };
|
|
1655
|
+
}
|
|
1656
|
+
var importPub = (j) => subtle().importKey("jwk", { kty: "RSA", n: j.n, e: j.e, alg: "RSA-OAEP-256", ext: true }, RSA, false, ["encrypt"]);
|
|
1657
|
+
var importPriv = (j) => subtle().importKey("jwk", { ...j, alg: "RSA-OAEP-256", ext: true }, RSA, false, ["decrypt"]);
|
|
1658
|
+
async function encryptBytes(pub, data, kid) {
|
|
1659
|
+
const aes = await subtle().generateKey({ name: "AES-GCM", length: 256 }, true, ["encrypt"]);
|
|
1660
|
+
const iv = globalThis.crypto.getRandomValues(new Uint8Array(12));
|
|
1661
|
+
const ct = await subtle().encrypt({ name: "AES-GCM", iv }, aes, data);
|
|
1662
|
+
const wrapped = await subtle().encrypt({ name: "RSA-OAEP" }, await importPub(pub), await subtle().exportKey("raw", aes));
|
|
1663
|
+
return { v: 1, kid: kid ?? await keyIdOf(pub), k: b64(wrapped), iv: b64(iv), ct: b64(ct) };
|
|
1664
|
+
}
|
|
1665
|
+
async function decryptBytes(priv, box) {
|
|
1666
|
+
const raw = await subtle().decrypt({ name: "RSA-OAEP" }, await importPriv(priv), unb64(box.k));
|
|
1667
|
+
const aes = await subtle().importKey("raw", raw, "AES-GCM", false, ["decrypt"]);
|
|
1668
|
+
return new Uint8Array(await subtle().decrypt({ name: "AES-GCM", iv: unb64(box.iv) }, aes, unb64(box.ct)));
|
|
1669
|
+
}
|
|
1670
|
+
var isRsaEnvelope = (v) => typeof v === "string" && v.startsWith(ENVELOPE_PREFIX) && v.length <= MAX_ENVELOPE && /^[A-Za-z0-9_-]+$/.test(v.slice(ENVELOPE_PREFIX.length));
|
|
1671
|
+
var isPgpEnvelope = (v) => typeof v === "string" && v.length <= MAX_ENVELOPE && /^-----BEGIN PGP MESSAGE-----[A-Za-z0-9+/=:.\s-]+-----END PGP MESSAGE-----\s*$/.test(v);
|
|
1672
|
+
var isEnvelope = (v) => isRsaEnvelope(v) || isPgpEnvelope(v);
|
|
1673
|
+
async function encryptValue(pub, value, kid) {
|
|
1674
|
+
const box = await encryptBytes(pub, enc2.encode(JSON.stringify(value)), kid);
|
|
1675
|
+
return ENVELOPE_PREFIX + b64(enc2.encode(JSON.stringify(box)));
|
|
1676
|
+
}
|
|
1677
|
+
async function decryptValue(priv, envelope) {
|
|
1678
|
+
if (!isRsaEnvelope(envelope)) throw new Error("Not an RSA-encrypted value");
|
|
1679
|
+
return JSON.parse(dec.decode(await decryptBytes(priv, JSON.parse(dec.decode(unb64(envelope.slice(ENVELOPE_PREFIX.length)))))));
|
|
1680
|
+
}
|
|
1681
|
+
var empty = (v) => v === void 0 || v === null || v === "" || Array.isArray(v) && !v.length;
|
|
1682
|
+
async function encryptAnswers(cfg, answers) {
|
|
1683
|
+
const out = { ...answers };
|
|
1684
|
+
for (const id of cfg.fieldIds) if (id in out && !empty(out[id]) && !isEnvelope(out[id])) out[id] = cfg.pgp ? await (await import("./pgp-4ZL3RFNG.js")).encryptPgp(cfg.pgp.publicKeyArmored, out[id]) : await encryptValue(cfg.publicKeyJwk, out[id], cfg.keyId);
|
|
1685
|
+
return out;
|
|
1686
|
+
}
|
|
1687
|
+
async function decryptAnswers(priv, answers) {
|
|
1688
|
+
const walk = async (v) => {
|
|
1689
|
+
if (isEnvelope(v)) {
|
|
1690
|
+
try {
|
|
1691
|
+
return await decryptValue(priv, v);
|
|
1692
|
+
} catch {
|
|
1693
|
+
return v;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
if (Array.isArray(v)) return Promise.all(v.map(walk));
|
|
1697
|
+
if (v && typeof v === "object") return Object.fromEntries(await Promise.all(Object.entries(v).map(async ([k, x]) => [k, await walk(x)])));
|
|
1698
|
+
return v;
|
|
1699
|
+
};
|
|
1700
|
+
return await walk(answers);
|
|
1701
|
+
}
|
|
1702
|
+
export {
|
|
1703
|
+
AccountResource,
|
|
1704
|
+
AdminResource,
|
|
1705
|
+
AiResource,
|
|
1706
|
+
AnalyticsResource,
|
|
1707
|
+
AuthenticationError,
|
|
1708
|
+
ConflictError,
|
|
1709
|
+
DEFAULT_VERSION,
|
|
1710
|
+
DestinationsResource,
|
|
1711
|
+
DistributionResource,
|
|
1712
|
+
EVENT_TYPES,
|
|
1713
|
+
ExperimentsResource,
|
|
1714
|
+
ExportsResource,
|
|
1715
|
+
FormBuilder,
|
|
1716
|
+
FormFlowClient as FormFlow,
|
|
1717
|
+
FormFlowClient,
|
|
1718
|
+
FormFlowError,
|
|
1719
|
+
FormsResource,
|
|
1720
|
+
InsightsResource,
|
|
1721
|
+
NotFoundError,
|
|
1722
|
+
OnboardingResource,
|
|
1723
|
+
PaymentsResource,
|
|
1724
|
+
PermissionError,
|
|
1725
|
+
PlatformResource,
|
|
1726
|
+
ProgramsResource,
|
|
1727
|
+
PublicClient,
|
|
1728
|
+
RateLimitError,
|
|
1729
|
+
ResultsResource,
|
|
1730
|
+
SchedulingResource,
|
|
1731
|
+
SubmissionsResource,
|
|
1732
|
+
TemplatesResource,
|
|
1733
|
+
ThemesResource,
|
|
1734
|
+
ValidationError,
|
|
1735
|
+
WorkflowsResource,
|
|
1736
|
+
choices,
|
|
1737
|
+
constructWebhookEvent,
|
|
1738
|
+
decryptAnswers,
|
|
1739
|
+
decryptBytes,
|
|
1740
|
+
decryptValue,
|
|
1741
|
+
encryptAnswers,
|
|
1742
|
+
encryptBytes,
|
|
1743
|
+
encryptValue,
|
|
1744
|
+
errorFor,
|
|
1745
|
+
form,
|
|
1746
|
+
generateKeyPair,
|
|
1747
|
+
isEnvelope,
|
|
1748
|
+
isEvent,
|
|
1749
|
+
signWebhookPayload,
|
|
1750
|
+
verifyWebhookSignature
|
|
1751
|
+
};
|