@reopt-ai/workspace-sdk 0.1.0-rc.11 → 0.1.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +7 -2
- package/dist/better-auth/index.d.ts +1 -1
- package/dist/better-auth/index.js +1 -1
- package/dist/{client-XAvKlbbn.js → client-BLaFMBbS.js} +2 -2
- package/dist/{client-WEomQekp.js → client-BX4VHJS6.js} +5 -5
- package/dist/{client-DlgVNj3w.d.ts → client-DVozA5Ep.d.ts} +2 -2
- package/dist/{client-ByIjKnf3.d.ts → client-olMIaJZH.d.ts} +3 -3
- package/dist/{connect-BBf9QfQB.d.ts → connect-CTxppAjD.d.ts} +104 -5
- package/dist/connect.d.ts +6 -5
- package/dist/connect.js +4 -3
- package/dist/{errors-DLJlABJL.d.ts → errors-CLUuzCNG.d.ts} +3 -1
- package/dist/{errors-C5_fhcqb.js → errors-DKMC4kId.js} +2 -2
- package/dist/forms.d.ts +167 -0
- package/dist/forms.js +221 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -4
- package/dist/installation/index.d.ts +3 -3
- package/dist/installation/index.js +3 -3
- package/dist/{keys-6gwtNd0g.js → keys--ef_VwZ-.js} +6 -5
- package/dist/{keys-B2pA8EkU.d.ts → keys-BXkGh0VM.d.ts} +10 -2
- package/dist/machine/index.d.ts +2 -2
- package/dist/machine/index.js +2 -2
- package/dist/machine/keygen-cli.js +1 -1
- package/dist/mentions-BMI2c7O6.d.ts +26 -0
- package/dist/mentions.d.ts +2 -0
- package/dist/mentions.js +45 -0
- package/dist/{page-79Ab4UGQ.d.ts → page-j1OCu4of.d.ts} +8 -4
- package/dist/{page-SjWh1rqY.js → page-rc95cliL.js} +72 -7
- package/dist/{permissions-COCbNJeQ.d.ts → permissions-DKm_zC_X.d.ts} +2 -2
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.js +48 -0
- package/dist/social/index.d.ts +2 -2
- package/dist/social/index.js +2 -2
- package/dist/testing/index.d.ts +27 -3
- package/dist/testing/index.js +343 -30
- package/dist/{transport-CN64IoHx.js → transport-BEwY_twi.js} +2 -2
- package/docs/forms.md +100 -0
- package/docs/machine.md +14 -4
- package/docs/testing.md +10 -6
- package/docs/workspace.md +70 -19
- package/package.json +9 -1
package/dist/testing/index.js
CHANGED
|
@@ -290,16 +290,17 @@ function build(options) {
|
|
|
290
290
|
return typeof value === "string" && value ? value : null;
|
|
291
291
|
};
|
|
292
292
|
const labelled = form.fields.filter((field) => display(row.answers[field.name]) !== "");
|
|
293
|
+
const linked = state.customers.find((c) => c.id === row.customerId);
|
|
293
294
|
return {
|
|
294
295
|
submissionId: row.id,
|
|
295
296
|
formId: form.id,
|
|
296
297
|
formName: form.name,
|
|
297
298
|
brandId: null,
|
|
298
299
|
submittedAt: row.submittedAt,
|
|
299
|
-
customerId: null,
|
|
300
|
-
customerName: text("name"),
|
|
301
|
-
customerEmail: text("email"),
|
|
302
|
-
customerPhone: text("phone"),
|
|
300
|
+
customerId: linked?.id ?? null,
|
|
301
|
+
customerName: linked?.name ?? text("name"),
|
|
302
|
+
customerEmail: linked?.email ?? text("email"),
|
|
303
|
+
customerPhone: linked?.phoneNumber ?? text("phone"),
|
|
303
304
|
taskId: row.taskId,
|
|
304
305
|
stageId: found?.stage.id ?? null,
|
|
305
306
|
stageKey: found?.stage.key ?? null,
|
|
@@ -370,6 +371,58 @@ function build(options) {
|
|
|
370
371
|
if (!body || typeof body !== "object" || Array.isArray(body) || body instanceof FormData) return refuse(400, "VALIDATION_ERROR", "Expected a JSON object body");
|
|
371
372
|
return body;
|
|
372
373
|
};
|
|
374
|
+
const feedOf = (taskId) => {
|
|
375
|
+
let feed = state.feeds.get(taskId);
|
|
376
|
+
if (!feed) state.feeds.set(taskId, feed = []);
|
|
377
|
+
return feed;
|
|
378
|
+
};
|
|
379
|
+
const logActivity = (taskId, activityType, payload = null) => feedOf(taskId).push({
|
|
380
|
+
type: "activity",
|
|
381
|
+
id: newId(),
|
|
382
|
+
actorMemberId: me().memberId,
|
|
383
|
+
activityType,
|
|
384
|
+
payload,
|
|
385
|
+
createdAt: stamp()
|
|
386
|
+
});
|
|
387
|
+
const feedMember = (memberId) => {
|
|
388
|
+
const member = state.members.find((m) => m.memberId === memberId);
|
|
389
|
+
return member ? {
|
|
390
|
+
memberId: member.memberId,
|
|
391
|
+
name: member.name,
|
|
392
|
+
image: member.image
|
|
393
|
+
} : null;
|
|
394
|
+
};
|
|
395
|
+
const feedDto = (taskId, row) => row.type === "comment" ? {
|
|
396
|
+
type: "comment",
|
|
397
|
+
id: row.id,
|
|
398
|
+
taskId,
|
|
399
|
+
author: feedMember(row.authorMemberId),
|
|
400
|
+
content: row.content,
|
|
401
|
+
isEdited: row.isEdited,
|
|
402
|
+
createdAt: row.createdAt
|
|
403
|
+
} : {
|
|
404
|
+
type: "activity",
|
|
405
|
+
id: row.id,
|
|
406
|
+
actor: feedMember(row.actorMemberId),
|
|
407
|
+
activityType: row.activityType,
|
|
408
|
+
payload: row.payload,
|
|
409
|
+
createdAt: row.createdAt
|
|
410
|
+
};
|
|
411
|
+
const findComment = (commentId) => {
|
|
412
|
+
for (const [taskId, feed] of state.feeds) {
|
|
413
|
+
const comment = feed.find((r) => r.type === "comment" && r.id === commentId);
|
|
414
|
+
if (comment?.type === "comment" && state.tasks.some((t) => t.id === taskId)) return {
|
|
415
|
+
taskId,
|
|
416
|
+
feed,
|
|
417
|
+
comment
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
return notFound("Comment");
|
|
421
|
+
};
|
|
422
|
+
const commentText = (body) => str(assertBody(body), "content", {
|
|
423
|
+
required: true,
|
|
424
|
+
max: 4e3
|
|
425
|
+
});
|
|
373
426
|
const findTask = (id) => state.tasks.find((t) => t.id === id) ?? notFound("Task");
|
|
374
427
|
const findPost = (id) => state.posts.find((p) => p.id === id) ?? notFound("Post");
|
|
375
428
|
const findFile = (id) => state.files.find((f) => f.id === id) ?? notFound("File");
|
|
@@ -458,6 +511,23 @@ function build(options) {
|
|
|
458
511
|
return `${browserBase}/v1/signed/files/${token}`;
|
|
459
512
|
};
|
|
460
513
|
const findCustomer = (id) => state.customers.find((c) => c.id === id) ?? notFound("Customer");
|
|
514
|
+
/** 알림 종류 → 그 알림이 가리키는 자료를 읽는 데 필요한 권한(+scope). 실제 서버의 표와 같다 */
|
|
515
|
+
const NOTIFICATION_ACCESS = {
|
|
516
|
+
task_assigned: { permission: "works:read" },
|
|
517
|
+
task_comment: { permission: "works:read" },
|
|
518
|
+
task_mention: { permission: "works:read" },
|
|
519
|
+
task_stage_changed: { permission: "works:read" },
|
|
520
|
+
task_due_soon: { permission: "works:read" },
|
|
521
|
+
form_submitted: { permission: "form:read" },
|
|
522
|
+
customer_created: {
|
|
523
|
+
permission: "customer:read",
|
|
524
|
+
scope: "customer:read"
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
const visibleNotifications = () => state.notifications.filter((row) => {
|
|
528
|
+
const access = NOTIFICATION_ACCESS[row.kind];
|
|
529
|
+
return access !== void 0 && permissions.has(access.permission) && (!access.scope || scopes.includes(access.scope));
|
|
530
|
+
}).sort((a, b) => b.createdAt.localeCompare(a.createdAt) || b.id.localeCompare(a.id));
|
|
461
531
|
const customerSummary = (row) => ({
|
|
462
532
|
id: row.id,
|
|
463
533
|
name: row.name,
|
|
@@ -481,7 +551,7 @@ function build(options) {
|
|
|
481
551
|
notes: row.notes.length,
|
|
482
552
|
tasks: 0,
|
|
483
553
|
comments: 0,
|
|
484
|
-
formSubmissions:
|
|
554
|
+
formSubmissions: state.submissions.filter((submission) => submission.customerId === row.id).length
|
|
485
555
|
},
|
|
486
556
|
updatedAt: row.updatedAt
|
|
487
557
|
});
|
|
@@ -716,6 +786,7 @@ function build(options) {
|
|
|
716
786
|
title: void 0
|
|
717
787
|
});
|
|
718
788
|
state.tasks.push(row);
|
|
789
|
+
logActivity(row.id, "created");
|
|
719
790
|
return ok(taskDto(row), 201);
|
|
720
791
|
}
|
|
721
792
|
],
|
|
@@ -729,6 +800,26 @@ function build(options) {
|
|
|
729
800
|
checkTaskVersion(row, input);
|
|
730
801
|
const draft = { ...row };
|
|
731
802
|
applyTaskFields(draft, input);
|
|
803
|
+
if (draft.title !== row.title) logActivity(row.id, "retitled", {
|
|
804
|
+
from: row.title,
|
|
805
|
+
to: draft.title
|
|
806
|
+
});
|
|
807
|
+
if (draft.priority !== row.priority) logActivity(row.id, "priority_changed", {
|
|
808
|
+
from: row.priority,
|
|
809
|
+
to: draft.priority
|
|
810
|
+
});
|
|
811
|
+
if (draft.dueDate !== row.dueDate) logActivity(row.id, "due_date_changed", {
|
|
812
|
+
from: row.dueDate,
|
|
813
|
+
to: draft.dueDate
|
|
814
|
+
});
|
|
815
|
+
const added = draft.assigneeMemberIds.filter((id) => !row.assigneeMemberIds.includes(id)).length;
|
|
816
|
+
const removed = row.assigneeMemberIds.filter((id) => !draft.assigneeMemberIds.includes(id)).length;
|
|
817
|
+
if (added + removed > 0) logActivity(row.id, "assignees_changed", {
|
|
818
|
+
addedMembers: added,
|
|
819
|
+
addedGroups: 0,
|
|
820
|
+
removedMembers: removed,
|
|
821
|
+
removedGroups: 0
|
|
822
|
+
});
|
|
732
823
|
Object.assign(row, draft, { updatedAt: stamp() });
|
|
733
824
|
return ok(taskDto(row));
|
|
734
825
|
}
|
|
@@ -745,9 +836,14 @@ function build(options) {
|
|
|
745
836
|
const target = stageOf(stageId);
|
|
746
837
|
if (!target) return invalid("stageId", "Unknown stage");
|
|
747
838
|
if (!Number.isInteger(input.sortOrder)) return invalid("sortOrder", "Expected an integer index");
|
|
839
|
+
const from = stageOf(row.stageId)?.stage;
|
|
748
840
|
row.pipelineId = target.pipeline.id;
|
|
749
841
|
placeInStage(row, stageId, input.sortOrder);
|
|
750
842
|
row.updatedAt = stamp();
|
|
843
|
+
if (from?.id !== stageId) logActivity(row.id, "stage_changed", {
|
|
844
|
+
from: from?.label ?? null,
|
|
845
|
+
to: target.stage.label
|
|
846
|
+
});
|
|
751
847
|
return ok(taskDto(row));
|
|
752
848
|
}
|
|
753
849
|
],
|
|
@@ -777,6 +873,60 @@ function build(options) {
|
|
|
777
873
|
});
|
|
778
874
|
}
|
|
779
875
|
],
|
|
876
|
+
[
|
|
877
|
+
"GET",
|
|
878
|
+
new RegExp(`^/works/tasks/${UUID}/feed$`),
|
|
879
|
+
"works.listFeed",
|
|
880
|
+
({ params }) => {
|
|
881
|
+
const task = findTask(params[0]);
|
|
882
|
+
return paged([...feedOf(task.id)].sort((a, b) => a.createdAt.localeCompare(b.createdAt)).map((row) => feedDto(task.id, row)), {
|
|
883
|
+
limit: null,
|
|
884
|
+
offset: 0
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
],
|
|
888
|
+
[
|
|
889
|
+
"POST",
|
|
890
|
+
new RegExp(`^/works/tasks/${UUID}/comments$`),
|
|
891
|
+
"works.addComment",
|
|
892
|
+
({ body, params }) => {
|
|
893
|
+
const task = findTask(params[0]);
|
|
894
|
+
const row = {
|
|
895
|
+
type: "comment",
|
|
896
|
+
id: newId(),
|
|
897
|
+
authorMemberId: me().memberId,
|
|
898
|
+
content: commentText(body),
|
|
899
|
+
isEdited: false,
|
|
900
|
+
createdAt: stamp()
|
|
901
|
+
};
|
|
902
|
+
feedOf(task.id).push(row);
|
|
903
|
+
return ok(feedDto(task.id, row), 201);
|
|
904
|
+
}
|
|
905
|
+
],
|
|
906
|
+
[
|
|
907
|
+
"PATCH",
|
|
908
|
+
new RegExp(`^/works/task-comments/${UUID}$`),
|
|
909
|
+
"works.updateComment",
|
|
910
|
+
({ body, params }) => {
|
|
911
|
+
const { taskId, comment } = findComment(params[0]);
|
|
912
|
+
const content = commentText(body);
|
|
913
|
+
if (comment.authorMemberId !== me().memberId) refuse(403, "FORBIDDEN", "Only the author can edit a comment");
|
|
914
|
+
comment.content = content;
|
|
915
|
+
comment.isEdited = true;
|
|
916
|
+
return ok(feedDto(taskId, comment));
|
|
917
|
+
}
|
|
918
|
+
],
|
|
919
|
+
[
|
|
920
|
+
"DELETE",
|
|
921
|
+
new RegExp(`^/works/task-comments/${UUID}$`),
|
|
922
|
+
"works.deleteComment",
|
|
923
|
+
({ params }) => {
|
|
924
|
+
const { taskId, feed, comment } = findComment(params[0]);
|
|
925
|
+
if (comment.authorMemberId !== me().memberId && !permissions.has("works:delete")) refuse(403, "FORBIDDEN", "Only the author can delete a comment");
|
|
926
|
+
state.feeds.set(taskId, feed.filter((row) => row !== comment));
|
|
927
|
+
return ok({ id: comment.id });
|
|
928
|
+
}
|
|
929
|
+
],
|
|
780
930
|
[
|
|
781
931
|
"GET",
|
|
782
932
|
/^\/post-groups$/,
|
|
@@ -1223,6 +1373,50 @@ function build(options) {
|
|
|
1223
1373
|
});
|
|
1224
1374
|
}
|
|
1225
1375
|
],
|
|
1376
|
+
[
|
|
1377
|
+
"GET",
|
|
1378
|
+
/^\/notifications$/,
|
|
1379
|
+
"notifications.list",
|
|
1380
|
+
({ url }) => {
|
|
1381
|
+
const window = windowOf(url, 50);
|
|
1382
|
+
const unseen = url.searchParams.get("unseen");
|
|
1383
|
+
if (unseen !== null && unseen !== "true" && unseen !== "false") invalid("unseen", "Expected true or false");
|
|
1384
|
+
return paged(visibleNotifications().filter((row) => unseen !== "true" || row.seenAt === null), {
|
|
1385
|
+
limit: window.limit ?? 20,
|
|
1386
|
+
offset: window.offset
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
],
|
|
1390
|
+
[
|
|
1391
|
+
"GET",
|
|
1392
|
+
/^\/notifications\/unseen-count$/,
|
|
1393
|
+
"notifications.unseenCount",
|
|
1394
|
+
() => ok({ count: Math.min(visibleNotifications().filter((row) => row.seenAt === null).length, 100) })
|
|
1395
|
+
],
|
|
1396
|
+
[
|
|
1397
|
+
"POST",
|
|
1398
|
+
/^\/notifications\/seen$/,
|
|
1399
|
+
"notifications.markAllSeen",
|
|
1400
|
+
() => {
|
|
1401
|
+
const unseen = visibleNotifications().filter((row) => row.seenAt === null);
|
|
1402
|
+
const at = stamp();
|
|
1403
|
+
for (const row of unseen) row.seenAt = at;
|
|
1404
|
+
return ok({ count: unseen.length });
|
|
1405
|
+
}
|
|
1406
|
+
],
|
|
1407
|
+
[
|
|
1408
|
+
"POST",
|
|
1409
|
+
new RegExp(`^/notifications/${UUID}/seen$`),
|
|
1410
|
+
"notifications.markSeen",
|
|
1411
|
+
({ params }) => {
|
|
1412
|
+
const row = visibleNotifications().find((item) => item.id === params[0]) ?? notFound("Notification");
|
|
1413
|
+
row.seenAt ??= stamp();
|
|
1414
|
+
return ok({
|
|
1415
|
+
id: row.id,
|
|
1416
|
+
seenAt: row.seenAt
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
],
|
|
1226
1420
|
[
|
|
1227
1421
|
"GET",
|
|
1228
1422
|
/^\/customers$/,
|
|
@@ -1267,6 +1461,7 @@ function build(options) {
|
|
|
1267
1461
|
"customers.listFields",
|
|
1268
1462
|
() => paged(state.customerFields.map((field) => ({
|
|
1269
1463
|
id: field.id,
|
|
1464
|
+
name: field.name,
|
|
1270
1465
|
label: field.label,
|
|
1271
1466
|
dataType: field.dataType,
|
|
1272
1467
|
options: field.options
|
|
@@ -1303,9 +1498,10 @@ function build(options) {
|
|
|
1303
1498
|
existing.updatedAt = stamp();
|
|
1304
1499
|
return ok(customerDto(existing));
|
|
1305
1500
|
}
|
|
1306
|
-
refuse(409, "CONTACT_TAKEN", "Another customer already has this contact", conflicts.map(({ field, message }) => ({
|
|
1501
|
+
refuse(409, "CONTACT_TAKEN", "Another customer already has this contact", conflicts.map(({ field, message, customerId }) => ({
|
|
1307
1502
|
field,
|
|
1308
|
-
message
|
|
1503
|
+
message,
|
|
1504
|
+
relatedId: customerId
|
|
1309
1505
|
})));
|
|
1310
1506
|
}
|
|
1311
1507
|
const at = stamp();
|
|
@@ -1321,7 +1517,8 @@ function build(options) {
|
|
|
1321
1517
|
notes: [],
|
|
1322
1518
|
events: [{
|
|
1323
1519
|
id: newId(),
|
|
1324
|
-
type: "customer.
|
|
1520
|
+
type: "customer.create",
|
|
1521
|
+
metadata: null,
|
|
1325
1522
|
createdAt: at
|
|
1326
1523
|
}],
|
|
1327
1524
|
createdAt: at,
|
|
@@ -1362,10 +1559,17 @@ function build(options) {
|
|
|
1362
1559
|
const contact = readContact(input);
|
|
1363
1560
|
const attributes = readAttributes(input);
|
|
1364
1561
|
const conflicts = contactConflicts(contact, row.id);
|
|
1365
|
-
if (conflicts.length > 0) refuse(409, "CONTACT_TAKEN", "Another customer already has this contact", conflicts.map(({ field, message }) => ({
|
|
1562
|
+
if (conflicts.length > 0) refuse(409, "CONTACT_TAKEN", "Another customer already has this contact", conflicts.map(({ field, message, customerId }) => ({
|
|
1366
1563
|
field,
|
|
1367
|
-
message
|
|
1564
|
+
message,
|
|
1565
|
+
relatedId: customerId
|
|
1368
1566
|
})));
|
|
1567
|
+
const beforeUpdate = {
|
|
1568
|
+
name: row.name,
|
|
1569
|
+
email: row.email,
|
|
1570
|
+
phoneNumber: row.phoneNumber,
|
|
1571
|
+
address: row.address
|
|
1572
|
+
};
|
|
1369
1573
|
if (name) row.name = name;
|
|
1370
1574
|
if (input.record === "person" || input.record === "company") row.record = input.record;
|
|
1371
1575
|
if (contact.email !== void 0) row.email = contact.email;
|
|
@@ -1377,9 +1581,20 @@ function build(options) {
|
|
|
1377
1581
|
...attributes
|
|
1378
1582
|
};
|
|
1379
1583
|
row.updatedAt = stamp();
|
|
1380
|
-
|
|
1584
|
+
const changes = {};
|
|
1585
|
+
for (const key of [
|
|
1586
|
+
"name",
|
|
1587
|
+
"email",
|
|
1588
|
+
"phoneNumber",
|
|
1589
|
+
"address"
|
|
1590
|
+
]) if (beforeUpdate[key] !== row[key]) changes[key] = {
|
|
1591
|
+
old: beforeUpdate[key],
|
|
1592
|
+
new: row[key]
|
|
1593
|
+
};
|
|
1594
|
+
if (Object.keys(changes).length > 0) row.events.push({
|
|
1381
1595
|
id: newId(),
|
|
1382
|
-
type: "customer.
|
|
1596
|
+
type: "customer.update",
|
|
1597
|
+
metadata: { changes },
|
|
1383
1598
|
createdAt: row.updatedAt
|
|
1384
1599
|
});
|
|
1385
1600
|
return ok(customerDto(row));
|
|
@@ -1395,8 +1610,18 @@ function build(options) {
|
|
|
1395
1610
|
const add = readTags(input.add, "add");
|
|
1396
1611
|
const remove = readTags(input.remove, "remove");
|
|
1397
1612
|
if (add.length + remove.length === 0) refuse(400, "VALIDATION_ERROR", "Give add or remove");
|
|
1613
|
+
const tagsBefore = row.tags.join(",");
|
|
1398
1614
|
row.tags = [.../* @__PURE__ */ new Set([...row.tags.filter((tag) => !remove.includes(tag)), ...add])];
|
|
1399
1615
|
row.updatedAt = stamp();
|
|
1616
|
+
if (tagsBefore !== row.tags.join(",")) row.events.push({
|
|
1617
|
+
id: newId(),
|
|
1618
|
+
type: "customer.update",
|
|
1619
|
+
metadata: { changes: { tags: {
|
|
1620
|
+
old: tagsBefore,
|
|
1621
|
+
new: row.tags.join(",")
|
|
1622
|
+
} } },
|
|
1623
|
+
createdAt: row.updatedAt
|
|
1624
|
+
});
|
|
1400
1625
|
return ok(customerDto(row));
|
|
1401
1626
|
}
|
|
1402
1627
|
],
|
|
@@ -1465,7 +1690,7 @@ function build(options) {
|
|
|
1465
1690
|
id: event.id,
|
|
1466
1691
|
type: event.type,
|
|
1467
1692
|
actorType: "member",
|
|
1468
|
-
metadata:
|
|
1693
|
+
metadata: event.metadata,
|
|
1469
1694
|
createdAt: event.createdAt
|
|
1470
1695
|
})), {
|
|
1471
1696
|
limit,
|
|
@@ -1706,15 +1931,23 @@ function build(options) {
|
|
|
1706
1931
|
const formDefinition = (form) => ({
|
|
1707
1932
|
formId: form.id,
|
|
1708
1933
|
name: form.name,
|
|
1709
|
-
fields: form.fields.map((field) =>
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1934
|
+
fields: form.fields.map((field) => {
|
|
1935
|
+
const kind = field.type ?? "text";
|
|
1936
|
+
return {
|
|
1937
|
+
name: field.name,
|
|
1938
|
+
label: field.label,
|
|
1939
|
+
type: kind === "text" || kind === "tel" ? "string" : kind === "checkbox" ? "boolean" : kind,
|
|
1940
|
+
required: field.required ?? false,
|
|
1941
|
+
placeholder: null,
|
|
1942
|
+
description: null,
|
|
1943
|
+
options: field.options?.map((option) => typeof option === "string" ? {
|
|
1944
|
+
value: option,
|
|
1945
|
+
label: option
|
|
1946
|
+
} : option) ?? null,
|
|
1947
|
+
inputPurpose: kind === "email" ? "email" : kind === "tel" ? "tel" : field.name === "name" ? "name" : null,
|
|
1948
|
+
appearance: kind === "tel" ? "phone" : "default"
|
|
1949
|
+
};
|
|
1950
|
+
}),
|
|
1718
1951
|
submitLabel: form.submitLabel,
|
|
1719
1952
|
successMessage: form.successMessage,
|
|
1720
1953
|
consent: form.consentLabel ? [{
|
|
@@ -1723,7 +1956,7 @@ function build(options) {
|
|
|
1723
1956
|
required: true,
|
|
1724
1957
|
linkUrl: null,
|
|
1725
1958
|
termsId: null
|
|
1726
|
-
}] :
|
|
1959
|
+
}] : null
|
|
1727
1960
|
});
|
|
1728
1961
|
const submitForm = (form, body) => {
|
|
1729
1962
|
const input = body;
|
|
@@ -1737,8 +1970,8 @@ function build(options) {
|
|
|
1737
1970
|
status: 422,
|
|
1738
1971
|
body: { error: {
|
|
1739
1972
|
code: "CONSENT_REQUIRED",
|
|
1740
|
-
message: "필수
|
|
1741
|
-
|
|
1973
|
+
message: "필수 동의 항목에 동의해주세요.",
|
|
1974
|
+
fieldErrors: { consent: "필수 동의 항목입니다." }
|
|
1742
1975
|
} }
|
|
1743
1976
|
};
|
|
1744
1977
|
const answers = {};
|
|
@@ -1746,7 +1979,7 @@ function build(options) {
|
|
|
1746
1979
|
for (const field of form.fields) {
|
|
1747
1980
|
const value = input.values[field.name];
|
|
1748
1981
|
if (value === void 0 || value === null || value === "" || value === false) {
|
|
1749
|
-
if (field.required) errors[field.name] =
|
|
1982
|
+
if (field.required) errors[field.name] = "필수 항목입니다.";
|
|
1750
1983
|
continue;
|
|
1751
1984
|
}
|
|
1752
1985
|
if (field.type === "email" && !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(String(value))) {
|
|
@@ -1763,8 +1996,8 @@ function build(options) {
|
|
|
1763
1996
|
status: 422,
|
|
1764
1997
|
body: { error: {
|
|
1765
1998
|
code: "VALIDATION_ERROR",
|
|
1766
|
-
message: "
|
|
1767
|
-
|
|
1999
|
+
message: "입력값을 확인해주세요.",
|
|
2000
|
+
fieldErrors: errors
|
|
1768
2001
|
} }
|
|
1769
2002
|
};
|
|
1770
2003
|
const submission = addSubmission(form, answers, void 0, void 0);
|
|
@@ -1772,9 +2005,45 @@ function build(options) {
|
|
|
1772
2005
|
submissionId: submission.id,
|
|
1773
2006
|
ok: true,
|
|
1774
2007
|
successMessage: form.successMessage,
|
|
1775
|
-
customerId:
|
|
2008
|
+
customerId: submission.customerId
|
|
1776
2009
|
});
|
|
1777
2010
|
};
|
|
2011
|
+
/**
|
|
2012
|
+
* 제출한 사람을 고객 명부에 잇는다 — 실제 서버처럼 이메일(없으면 전화)로 찾고, 없으면 새로 만든다.
|
|
2013
|
+
* 연락처가 없는 제출은 고객 없이 남는다(`customerId: null`).
|
|
2014
|
+
*/
|
|
2015
|
+
const linkSubmitter = (answers, at) => {
|
|
2016
|
+
const read = (name) => {
|
|
2017
|
+
const value = answers[name];
|
|
2018
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
2019
|
+
};
|
|
2020
|
+
const email = read("email")?.toLowerCase() ?? null;
|
|
2021
|
+
const phone = (read("phone") ?? read("phoneNumber"))?.replace(/\D/g, "") || null;
|
|
2022
|
+
if (!email && !phone) return null;
|
|
2023
|
+
const existing = state.customers.find((c) => email && c.email === email || phone && c.phoneNumber === phone);
|
|
2024
|
+
if (existing) return existing.id;
|
|
2025
|
+
const created = {
|
|
2026
|
+
id: newId(),
|
|
2027
|
+
name: read("name") ?? email ?? phone,
|
|
2028
|
+
record: "person",
|
|
2029
|
+
email,
|
|
2030
|
+
phoneNumber: phone,
|
|
2031
|
+
address: null,
|
|
2032
|
+
tags: [],
|
|
2033
|
+
attributes: {},
|
|
2034
|
+
notes: [],
|
|
2035
|
+
events: [{
|
|
2036
|
+
id: newId(),
|
|
2037
|
+
type: "customer.create",
|
|
2038
|
+
metadata: null,
|
|
2039
|
+
createdAt: at
|
|
2040
|
+
}],
|
|
2041
|
+
createdAt: at,
|
|
2042
|
+
updatedAt: at
|
|
2043
|
+
};
|
|
2044
|
+
state.customers.push(created);
|
|
2045
|
+
return created.id;
|
|
2046
|
+
};
|
|
1778
2047
|
const addSubmission = (form, answers, stageKey, memo, submittedAt) => {
|
|
1779
2048
|
const at = submittedAt ?? stamp();
|
|
1780
2049
|
let taskId = null;
|
|
@@ -1805,6 +2074,7 @@ function build(options) {
|
|
|
1805
2074
|
const row = {
|
|
1806
2075
|
id: newId(),
|
|
1807
2076
|
formId: form.id,
|
|
2077
|
+
customerId: linkSubmitter(answers, at),
|
|
1808
2078
|
answers,
|
|
1809
2079
|
taskId,
|
|
1810
2080
|
submittedAt: at
|
|
@@ -1898,6 +2168,7 @@ function seedState(options) {
|
|
|
1898
2168
|
brands: [],
|
|
1899
2169
|
pipelines: [],
|
|
1900
2170
|
tasks: [],
|
|
2171
|
+
feeds: /* @__PURE__ */ new Map(),
|
|
1901
2172
|
groups: [],
|
|
1902
2173
|
posts: [],
|
|
1903
2174
|
folders: [],
|
|
@@ -1906,6 +2177,7 @@ function seedState(options) {
|
|
|
1906
2177
|
submissions: [],
|
|
1907
2178
|
customers: [],
|
|
1908
2179
|
customerFields: [],
|
|
2180
|
+
notifications: [],
|
|
1909
2181
|
tables: [],
|
|
1910
2182
|
ids: /* @__PURE__ */ new Map(),
|
|
1911
2183
|
counter: 0,
|
|
@@ -1987,6 +2259,26 @@ function seedState(options) {
|
|
|
1987
2259
|
updatedAt: at
|
|
1988
2260
|
});
|
|
1989
2261
|
}
|
|
2262
|
+
for (const [index, task] of (seed.tasks ?? []).entries()) {
|
|
2263
|
+
const row = state.tasks[index];
|
|
2264
|
+
const feed = [{
|
|
2265
|
+
type: "activity",
|
|
2266
|
+
id: newId("record"),
|
|
2267
|
+
actorMemberId: row.creatorMemberId,
|
|
2268
|
+
activityType: "created",
|
|
2269
|
+
payload: null,
|
|
2270
|
+
createdAt: row.createdAt
|
|
2271
|
+
}];
|
|
2272
|
+
for (const comment of task.comments ?? []) feed.push({
|
|
2273
|
+
type: "comment",
|
|
2274
|
+
id: newId("record"),
|
|
2275
|
+
authorMemberId: comment.author ? ref("member", comment.author, `task "${task.title}"`) : state.members[0].memberId,
|
|
2276
|
+
content: comment.content,
|
|
2277
|
+
isEdited: false,
|
|
2278
|
+
createdAt: stamp()
|
|
2279
|
+
});
|
|
2280
|
+
state.feeds.set(row.id, feed);
|
|
2281
|
+
}
|
|
1990
2282
|
for (const folder of seed.folders ?? []) state.folders.push({
|
|
1991
2283
|
id: newId("folder", folder.key),
|
|
1992
2284
|
name: folder.name,
|
|
@@ -2081,13 +2373,34 @@ function seedState(options) {
|
|
|
2081
2373
|
}),
|
|
2082
2374
|
events: [{
|
|
2083
2375
|
id: newId("record"),
|
|
2084
|
-
type: "customer.
|
|
2376
|
+
type: "customer.create",
|
|
2377
|
+
metadata: null,
|
|
2085
2378
|
createdAt: at
|
|
2086
2379
|
}],
|
|
2087
2380
|
createdAt: at,
|
|
2088
2381
|
updatedAt: at
|
|
2089
2382
|
});
|
|
2090
2383
|
}
|
|
2384
|
+
for (const item of seed.notifications ?? []) {
|
|
2385
|
+
const at = item.createdAt ? new Date(item.createdAt).toISOString() : stamp();
|
|
2386
|
+
state.notifications.push({
|
|
2387
|
+
id: newId("notification", item.key),
|
|
2388
|
+
kind: item.kind,
|
|
2389
|
+
subject: item.subject ?? null,
|
|
2390
|
+
content: item.content,
|
|
2391
|
+
seenAt: item.seen ? at : null,
|
|
2392
|
+
createdAt: at,
|
|
2393
|
+
actorName: item.actorName ?? null,
|
|
2394
|
+
actorImage: null,
|
|
2395
|
+
entity: item.task ? {
|
|
2396
|
+
type: "task",
|
|
2397
|
+
id: ref("task", item.task, "a notification")
|
|
2398
|
+
} : item.form ? {
|
|
2399
|
+
type: "form",
|
|
2400
|
+
id: ref("form", item.form, "a notification")
|
|
2401
|
+
} : null
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2091
2404
|
for (const table of seed.tables ?? []) {
|
|
2092
2405
|
const row = {
|
|
2093
2406
|
id: newId("table", table.key),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as SDK_VERSION, n as PlatformApiError } from "./errors-
|
|
1
|
+
import { l as SDK_VERSION, n as PlatformApiError } from "./errors-DKMC4kId.js";
|
|
2
2
|
|
|
3
3
|
//#region src/workspace/transport.ts
|
|
4
4
|
function parseRetryAfter(value) {
|
|
@@ -189,4 +189,4 @@ function createTransport(config) {
|
|
|
189
189
|
|
|
190
190
|
//#endregion
|
|
191
191
|
export { readPlatformFailure as n, createTransport as t };
|
|
192
|
-
//# sourceMappingURL=transport-
|
|
192
|
+
//# sourceMappingURL=transport-BEwY_twi.js.map
|
package/docs/forms.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Public forms (`@reopt-ai/workspace-sdk/forms`)
|
|
2
|
+
|
|
3
|
+
A visitor's browser reads a published Reopt form and submits to it **directly**. No dependencies,
|
|
4
|
+
no credentials — a form id is not a secret, and only published forms answer.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import {
|
|
8
|
+
createPublicFormClient,
|
|
9
|
+
isPublicFormError,
|
|
10
|
+
} from "@reopt-ai/workspace-sdk/forms";
|
|
11
|
+
|
|
12
|
+
const forms = createPublicFormClient(); // https://studio.reopt.ai
|
|
13
|
+
|
|
14
|
+
const form = await forms.get(formId); // fields, consent items, button label
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const { successMessage } = await forms.submit(formId, {
|
|
18
|
+
values: { name, email, topic, message }, // keyed by field.name
|
|
19
|
+
consents: { [consentItem.id]: true },
|
|
20
|
+
meta: { hp: honeypotValue, pagePath: location.pathname },
|
|
21
|
+
});
|
|
22
|
+
showDone(successMessage ?? form.successMessage);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (!isPublicFormError(error)) throw error;
|
|
25
|
+
showFieldErrors(error.fieldErrors); // { email: "…", [consentItem.id]: "…" }
|
|
26
|
+
if (Object.keys(error.fieldErrors).length === 0) showBanner(error.message);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Do not relay through your server
|
|
31
|
+
|
|
32
|
+
Reopt limits submissions **per visitor IP** (5 a minute, 50 an hour). If your server posts on the
|
|
33
|
+
visitor's behalf, every visitor shares your server's address and its limit. Reopt allows
|
|
34
|
+
cross-origin requests on these routes and accepts no cookies (the client sends `credentials:
|
|
35
|
+
"omit"`). Add the Studio origin to your CSP `connect-src`.
|
|
36
|
+
|
|
37
|
+
In dev mode point the client at the emulator instead — `studioUrl` is the `browserBaseUrl` you
|
|
38
|
+
gave `createDevPlatform` (see [testing.md](./testing.md)). The emulator does not rate-limit.
|
|
39
|
+
|
|
40
|
+
## The definition
|
|
41
|
+
|
|
42
|
+
`forms.get(formId)` returns the published form.
|
|
43
|
+
|
|
44
|
+
| Field | Meaning |
|
|
45
|
+
| ----------------------- | -------------------------------------------------------------------------------------------- |
|
|
46
|
+
| `fields[]` | `name` (the key in `values`), `label`, `type`, `required`, `options`, `placeholder` |
|
|
47
|
+
| `fields[].type` | `string` `textarea` `email` `url` `number` `boolean` `date` `select` `multiselect` `file` |
|
|
48
|
+
| `fields[].options` | `{ value, label }[]` for select types — submit the `value` |
|
|
49
|
+
| `fields[].inputPurpose` | `name` / `email` / `tel` — use it for `autocomplete`; `appearance: "phone"` for phone inputs |
|
|
50
|
+
| `consent[]` | `id` (the key in `consents`), `label`, `required`, `linkUrl` — empty when there are none |
|
|
51
|
+
| `submitLabel` | Button text, or null |
|
|
52
|
+
| `successMessage` | Text to show after submitting, or null |
|
|
53
|
+
|
|
54
|
+
Everything else Reopt's own renderer uses (theme, page breaks, booking slots) is passed through
|
|
55
|
+
untyped. Render from `fields` and a form edited in Studio keeps working without a deploy; a
|
|
56
|
+
field you hard-code stops matching the day someone renames it.
|
|
57
|
+
|
|
58
|
+
## Submitting
|
|
59
|
+
|
|
60
|
+
- An empty answer (`""`, `null`, missing) means "not answered".
|
|
61
|
+
- **Honeypot**: render an input people cannot see and pass its value as `meta.hp`. If it is
|
|
62
|
+
filled Reopt answers as if it succeeded and stores nothing (`submissionId: null`) — show your
|
|
63
|
+
normal done screen.
|
|
64
|
+
- The same answers sent again within two minutes return the first result instead of creating a
|
|
65
|
+
second submission, as long as the submission names someone (a name, email or phone). An
|
|
66
|
+
anonymous form can store a retry twice.
|
|
67
|
+
- `file` fields need Reopt's upload route first; this client does not cover it yet.
|
|
68
|
+
|
|
69
|
+
## Errors
|
|
70
|
+
|
|
71
|
+
Everything the client throws is a `PublicFormError` (except the caller's own abort).
|
|
72
|
+
|
|
73
|
+
| `code` | When | `retryable` |
|
|
74
|
+
| ------------------------- | ------------------------------------------------------------------------------- | ----------- |
|
|
75
|
+
| `VALIDATION_ERROR` | A required field is empty or a value is invalid — `fieldErrors` by field `name` | no |
|
|
76
|
+
| `CONSENT_REQUIRED` | A required consent is missing — `fieldErrors` by consent `id` | no |
|
|
77
|
+
| `FORM_NOT_FOUND` | No such form, or it is not published | no |
|
|
78
|
+
| `RATE_LIMITED` | Too many submissions from this visitor | yes |
|
|
79
|
+
| `SUBMISSION_IN_PROGRESS` | The same submission is still being processed | yes |
|
|
80
|
+
| `PAYLOAD_TOO_LARGE` | The body is over the limit | no |
|
|
81
|
+
| `NETWORK_ERROR` `TIMEOUT` | No answer (client-made, `status: 0`) | yes |
|
|
82
|
+
| `INVALID_RESPONSE` | An answer in an unexpected shape | on 5xx |
|
|
83
|
+
|
|
84
|
+
`error.message` is Reopt's own Korean sentence for the first six and safe to show a visitor.
|
|
85
|
+
|
|
86
|
+
## Labelling answers in an admin screen
|
|
87
|
+
|
|
88
|
+
Inquiries (`createConnectClient().inquiries`) carry `answers` keyed by field `name`. Label them
|
|
89
|
+
from the form instead of repeating the field list in your code:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { labelAnswers } from "@reopt-ai/workspace-sdk/forms";
|
|
93
|
+
|
|
94
|
+
const form = await forms.get(inquiry.formId);
|
|
95
|
+
labelAnswers(form.fields, inquiry.answers);
|
|
96
|
+
// [{ name: "topic", label: "문의 유형", value: "service", text: "서비스 도입" }, …]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Rows follow the form's field order; answers to fields that were later removed come after them
|
|
100
|
+
under their `name`; empty answers are left out.
|