@reopt-ai/workspace-sdk 0.1.0-rc.12 → 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 +22 -0
- package/README.md +6 -2
- package/dist/{client-CJekFhCW.js → client-BX4VHJS6.js} +3 -3
- package/dist/{connect-3zkyD_-0.d.ts → connect-CTxppAjD.d.ts} +56 -3
- package/dist/connect.d.ts +3 -3
- package/dist/connect.js +2 -2
- package/dist/{errors-CkgGRAPR.js → errors-DKMC4kId.js} +2 -2
- package/dist/forms.d.ts +167 -0
- package/dist/forms.js +221 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/installation/index.js +1 -1
- package/dist/{page-CV3oG_Zu.js → page-rc95cliL.js} +32 -4
- package/dist/{permissions-LF1orSvQ.d.ts → permissions-DKm_zC_X.d.ts} +2 -2
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.js +24 -0
- package/dist/social/index.js +2 -2
- package/dist/testing/index.d.ts +22 -3
- package/dist/testing/index.js +105 -15
- package/dist/{transport-BVPl0lgF.js → transport-BEwY_twi.js} +2 -2
- package/docs/forms.md +100 -0
- package/docs/testing.md +10 -6
- package/docs/workspace.md +31 -0
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,28 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.0-rc.13] — 2026-11-22
|
|
11
|
+
|
|
12
|
+
Pre-release (`npm i @reopt-ai/workspace-sdk@next`). 깨지는 변경 없음.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **알림** — `notifications.list({ unseen })`·`unseenCount()`·`markSeen(id)`·`markAllSeen()`. 로그인한 직원이 리옵트에서 받은
|
|
17
|
+
알림 중 이 연결로 읽을 수 있는 종류만 온다(업무 담당 지정·댓글·멘션·단계 이동·마감 임박, 폼 제출, 신규 고객 —
|
|
18
|
+
역할·scope·플랜으로 판정). 결제·보안 알림은 오지 않고 `markAllSeen`도 건드리지 않는다. `entity`(`task`·`form`)로 앱의 화면에
|
|
19
|
+
잇는다. 읽음 상태는 Studio와 같은 값이다. `/testing`은 `seed.notifications`로 채운다.
|
|
20
|
+
- **`@reopt-ai/workspace-sdk/forms`** — 공개 폼(브랜드폼) 클라이언트. 의존이 없고 방문자 브라우저에서 돈다:
|
|
21
|
+
`createPublicFormClient().get(formId)`(게시된 정의 — 필드·선택지·동의 항목)·`submit(formId, { values, consents, meta })`,
|
|
22
|
+
실패는 `PublicFormError`(`code`·칸별 `fieldErrors`·`retryable`), 관리 화면용 `labelAnswers(fields, answers)`.
|
|
23
|
+
지금까지는 앱이 제출 주소와 오류 해석을 손으로 짰다. 문서 `docs/forms.md`.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- `/testing` — 공개 폼 응답이 실제 서버와 달랐다: 칸별 오류를 `fields`로 실었고(실제는 `fieldErrors` — 그 키를 읽는 앱에는
|
|
28
|
+
dev 모드에서 칸별 문구가 보이지 않았다), 필드 타입을 `text`·`tel`·`checkbox`로 냈으며(실제는 `string`·`boolean` +
|
|
29
|
+
`appearance`·`inputPurpose`), 선택지를 문자열로도 냈다(실제는 언제나 `{ value, label }`). 같은 계약 시나리오를
|
|
30
|
+
에뮬레이터와 실제 라우터에 돌려 고정했다.
|
|
31
|
+
|
|
10
32
|
## [0.1.0-rc.12] — 2026-11-22
|
|
11
33
|
|
|
12
34
|
Pre-release (`npm i @reopt-ai/workspace-sdk@next`). 깨지는 변경 없음.
|
package/README.md
CHANGED
|
@@ -7,13 +7,17 @@ a company site, a service that files work into Studio) rather than being one bra
|
|
|
7
7
|
published posts for a public site, declarative workspace resources, webhooks.
|
|
8
8
|
- **Delegated access** (`createConnectClient`, also at `/connect`) — a staff member signs in with
|
|
9
9
|
Reopt and your app acts as **them**: Works tasks, posts, files and folders, forms and
|
|
10
|
-
inquiries, brands, members and the app's own tables, limited
|
|
10
|
+
inquiries, customers, their notifications, brands, members and the app's own tables, limited
|
|
11
|
+
by their workspace role.
|
|
11
12
|
Every list is a page (`{ items, nextOffset }`), every write returns the object, every failure
|
|
12
13
|
is a `PlatformApiError` with a typed `code`.
|
|
13
14
|
- **Permissions** (`/permissions`, no dependencies — safe in client components) — the permission
|
|
14
15
|
keys and `can(me, "post:publish")` / `canCall(me, "works.deleteTask")`.
|
|
15
16
|
- **Dev platform** (`/testing`) — an in-memory Reopt for dev mode and E2E: keep the real clients,
|
|
16
17
|
swap their `fetch`. See `docs/testing.md`.
|
|
18
|
+
- **Public forms** (`/forms`, no dependencies — runs in the visitor's browser) — read a published
|
|
19
|
+
form and submit to it directly: `createPublicFormClient()`, typed `PublicFormError` with
|
|
20
|
+
per-field messages, `labelAnswers` for admin screens. See `docs/forms.md`.
|
|
17
21
|
- **Mentions** (`/mentions`, no dependencies) — `mentionToken`, `splitMentions` for task comments.
|
|
18
22
|
- **Webhooks** (`/webhooks`, no dependencies) — receive Reopt's events with the signature and
|
|
19
23
|
replay window checked: `createWebhookHandler({ secret, handlers })`.
|
|
@@ -21,7 +25,7 @@ a company site, a service that files work into Studio) rather than being one bra
|
|
|
21
25
|
- **Installations** (`/installation`) — declare, sign and request your app's connection.
|
|
22
26
|
- **Resource verifier** (`/resource`), **social operations** (`/social`), **id host resolution** (`/urls`).
|
|
23
27
|
|
|
24
|
-
Server-only (it holds private keys and tokens) except `/permissions`, `/operator` and `/urls`
|
|
28
|
+
Server-only (it holds private keys and tokens) except `/forms`, `/mentions`, `/permissions`, `/operator` and `/urls`
|
|
25
29
|
(`/webhooks` runs anywhere Web Crypto does, but holds your webhook secret — keep it on the server).
|
|
26
30
|
Optional peers: `zod` for `.`, `/connect`, `/social` and `/installation`; `@better-auth/core` for
|
|
27
31
|
`.`, `/machine` and `/resource` (the platform client signs DPoP proofs with it). An app that only
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as SDK_VERSION, n as PlatformApiError } from "./errors-
|
|
2
|
-
import { n as readPlatformFailure } from "./transport-
|
|
1
|
+
import { l as SDK_VERSION, n as PlatformApiError } from "./errors-DKMC4kId.js";
|
|
2
|
+
import { n as readPlatformFailure } from "./transport-BEwY_twi.js";
|
|
3
3
|
import { resolvePlatformUrls } from "./urls.js";
|
|
4
4
|
import { o as readClientKeyRing } from "./keys--ef_VwZ-.js";
|
|
5
5
|
import { r as createMachineClient } from "./client-BLaFMBbS.js";
|
|
@@ -272,4 +272,4 @@ function createPlatformClient(config) {
|
|
|
272
272
|
|
|
273
273
|
//#endregion
|
|
274
274
|
export { createPlatformClient as n, createPlatformRequester as r, DEFAULT_PLATFORM_SCOPES as t };
|
|
275
|
-
//# sourceMappingURL=client-
|
|
275
|
+
//# sourceMappingURL=client-BX4VHJS6.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as WorkspacePermissionKey, o as ConnectScope } from "./permissions-
|
|
1
|
+
import { c as WorkspacePermissionKey, o as ConnectScope } from "./permissions-DKm_zC_X.js";
|
|
2
2
|
import { i as SortOf, n as Page, r as PageQuery, t as CountedPage } from "./page-j1OCu4of.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region src/workspace/transport.d.ts
|
|
@@ -318,6 +318,34 @@ type ConnectSignedUrl = {
|
|
|
318
318
|
};
|
|
319
319
|
type ConnectFormType = "feedback" | "inquiry" | "consultation" | "custom" | "booking" | (string & {});
|
|
320
320
|
type ConnectFormStatus = "draft" | "published" | "archived";
|
|
321
|
+
/**
|
|
322
|
+
* 앱에 열리는 알림 종류 — 업무(담당 지정·댓글·멘션·단계 이동·마감 임박), 폼 제출, 신규 고객. 리옵트의 다른 알림
|
|
323
|
+
* (결제·보안·구성원)은 이 표면에 오지 않는다.
|
|
324
|
+
*/
|
|
325
|
+
type ConnectNotificationKind = "task_assigned" | "task_comment" | "task_mention" | "task_stage_changed" | "task_due_soon" | "form_submitted" | "customer_created";
|
|
326
|
+
type ConnectNotification = {
|
|
327
|
+
id: string;
|
|
328
|
+
/** 목록에 없는 종류가 나중에 더해질 수 있다 — 모르는 값은 `subject`·`content`만 보여 주면 된다 */
|
|
329
|
+
kind: ConnectNotificationKind | (string & {});
|
|
330
|
+
/** 한 줄 제목(업무 알림은 업무 제목) */
|
|
331
|
+
subject: string | null;
|
|
332
|
+
/** 사람이 읽는 문장 — 리옵트가 쓴 그대로 */
|
|
333
|
+
content: string;
|
|
334
|
+
/** 읽은 시각 — 안 읽었으면 null */
|
|
335
|
+
seenAt: string | null;
|
|
336
|
+
createdAt: string;
|
|
337
|
+
/** 알림을 일으킨 사람(시스템이 낸 알림은 null) */
|
|
338
|
+
actorName: string | null;
|
|
339
|
+
actorImage: string | null;
|
|
340
|
+
/**
|
|
341
|
+
* 알림이 가리키는 것 — 앱이 자기 화면으로 보낼 때 쓴다(`task` → `works.getTask(id)`, `form` → 그 폼의 문의 목록).
|
|
342
|
+
* 여러 건을 묶은 알림("오늘 신규 고객 3명")은 가리키는 것이 없어 null.
|
|
343
|
+
*/
|
|
344
|
+
entity: {
|
|
345
|
+
type: "task" | "form" | (string & {});
|
|
346
|
+
id: string;
|
|
347
|
+
} | null;
|
|
348
|
+
};
|
|
321
349
|
type ConnectForm = {
|
|
322
350
|
id: string;
|
|
323
351
|
name: string;
|
|
@@ -639,6 +667,7 @@ declare const connectPostSchema: z.ZodType<ConnectPost>;
|
|
|
639
667
|
declare const connectFolderSchema: z.ZodType<ConnectFolder>;
|
|
640
668
|
declare const connectFileSchema: z.ZodType<ConnectFile>;
|
|
641
669
|
declare const connectFileUsageSchema: z.ZodType<ConnectFileUsage>;
|
|
670
|
+
declare const connectNotificationSchema: z.ZodType<ConnectNotification>;
|
|
642
671
|
declare const connectFormSchema: z.ZodType<ConnectForm>;
|
|
643
672
|
declare const connectInquirySchema: z.ZodType<ConnectInquiry>;
|
|
644
673
|
declare const connectInquiryDetailSchema: z.ZodType<ConnectInquiryDetail>;
|
|
@@ -779,6 +808,30 @@ type ConnectClient = {
|
|
|
779
808
|
forms: {
|
|
780
809
|
list: (options?: Options) => Promise<Page<ConnectForm>>;
|
|
781
810
|
};
|
|
811
|
+
/**
|
|
812
|
+
* 알림 — 로그인한 직원이 리옵트에서 받은 것 중 **이 앱에 열린 범위의 것**(업무 담당 지정·댓글·멘션·단계 이동·마감 임박,
|
|
813
|
+
* 폼 제출, 신규 고객). 어느 종류가 오는지는 리옵트가 그 직원의 역할·동의한 scope·플랜으로 정한다(예: `customer_created`는
|
|
814
|
+
* `customer:read` scope가 있어야 온다). 결제·보안 알림은 오지 않는다.
|
|
815
|
+
*
|
|
816
|
+
* 읽음 상태는 Studio와 같은 값이다 — 여기서 읽으면 Studio 벨에서도 읽은 것이 되고, 그 반대도 같다.
|
|
817
|
+
*/
|
|
818
|
+
notifications: {
|
|
819
|
+
/** 최근순. `limit`을 안 주면 한 장에 20건(최대 50). `unseen: true`면 안 읽은 것만 */
|
|
820
|
+
list: (query?: {
|
|
821
|
+
unseen?: boolean;
|
|
822
|
+
} & PageQuery, options?: Options) => Promise<Page<ConnectNotification>>;
|
|
823
|
+
/** 벨의 숫자 — 100에서 멈춘다(100이면 "99+"로 보이면 된다) */
|
|
824
|
+
unseenCount: (options?: Options) => Promise<number>;
|
|
825
|
+
/** 한 건 읽음. 이미 읽은 것이면 처음 읽은 시각이 그대로 온다 */
|
|
826
|
+
markSeen: (id: string, options?: Options) => Promise<{
|
|
827
|
+
id: string;
|
|
828
|
+
seenAt: string | null;
|
|
829
|
+
}>;
|
|
830
|
+
/** 이 앱에 보이는 알림만 모두 읽음 — 보이지 않는 종류(결제·보안)는 건드리지 않는다. `count`는 바뀐 건수 */
|
|
831
|
+
markAllSeen: (options?: Options) => Promise<{
|
|
832
|
+
count: number;
|
|
833
|
+
}>;
|
|
834
|
+
};
|
|
782
835
|
/** 문의 = 브랜드폼 제출 + 운영 보드 단계. 읽기는 `customer:read` scope가 필요하다(연락처) */
|
|
783
836
|
inquiries: {
|
|
784
837
|
/** `formIds`는 1~50개. `limit`을 안 주면 한 장에 100건(최대 500) */
|
|
@@ -845,5 +898,5 @@ type ConnectClient = {
|
|
|
845
898
|
};
|
|
846
899
|
declare function createConnectClient(config: ConnectClientConfig): ConnectClient;
|
|
847
900
|
//#endregion
|
|
848
|
-
export {
|
|
849
|
-
//# sourceMappingURL=connect-
|
|
901
|
+
export { ConnectStageColor as $, ConnectInquiryMoveResult as A, connectPostGroupSchema as At, ConnectPostGroup as B, ConnectFolder as C, connectInquiryDetailSchema as Ct, ConnectFormType as D, connectMemberSchema as Dt, ConnectFormStatus as E, connectMeSchema as Et, ConnectNotificationKind as F, connectTaskFeedItemSchema as Ft, ConnectPostSpec as G, ConnectPostListQuery as H, ConnectPipeline as I, connectTaskSchema as It, ConnectPostTag as J, ConnectPostStatus as K, ConnectPost as L, createConnectClient as Lt, ConnectMember as M, connectPostSummarySchema as Mt, ConnectMemberRole as N, connectPostTagSchema as Nt, ConnectInquiry as O, connectNotificationSchema as Ot, ConnectNotification as P, connectTaskCommentSchema as Pt, ConnectSignedUrlOptions as Q, ConnectPostAuthor as R, ConnectFileVisibility as S, connectFormSchema as St, ConnectForm as T, connectInquirySchema as Tt, ConnectPostMetaInput as U, ConnectPostGroupKind as V, ConnectPostSortField as W, ConnectRequestOptions as X, ConnectPostUpdateInput as Y, ConnectSignedUrl as Z, ConnectEavRecord as _, connectEavEntitySchema as _t, ConnectClientConfig as a, ConnectTaskFeedItem as at, ConnectFileSortField as b, connectFileUsageSchema as bt, ConnectCustomerEvent as c, ConnectTaskMoveInput as ct, ConnectCustomerNote as d, ConnectTaskUpdateInput as dt, ConnectStageOutcome as et, ConnectCustomerRecord as f, ConnectWorkspaceTier as ft, ConnectEavEntity as g, connectCustomerSummarySchema as gt, ConnectCustomerUpdateInput as h, connectCustomerSchema as ht, ConnectClient as i, ConnectTaskCreateInput as it, ConnectMe as j, connectPostSchema as jt, ConnectInquiryDetail as k, connectPipelineSchema as kt, ConnectCustomerField as l, ConnectTaskPriority as lt, ConnectCustomerTag as m, connectCustomerNoteSchema as mt, ConnectAnswerValue as n, ConnectTaskActivity as nt, ConnectCustomer as o, ConnectTaskFeedMember as ot, ConnectCustomerSummary as p, connectBrandSchema as pt, ConnectPostSummary as q, ConnectBrand as r, ConnectTaskComment as rt, ConnectCustomerCreateInput as s, ConnectTaskListQuery as st, ConnectAccessToken as t, ConnectTask as tt, ConnectCustomerListQuery as u, ConnectTaskSortField as ut, ConnectFile as v, connectEavRecordSchema as vt, ConnectFolderKind as w, connectInquiryMoveResultSchema as wt, ConnectFileUsage as x, connectFolderSchema as xt, ConnectFileListQuery as y, connectFileSchema as yt, ConnectPostCreateInput as z };
|
|
902
|
+
//# sourceMappingURL=connect-CTxppAjD.d.ts.map
|
package/dist/connect.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as ConnectOperationRule, c as WorkspacePermissionKey, d as canAny, f as canCall, i as ConnectOperation, l as can, n as CONNECT_OPERATION_NAMES, o as ConnectScope, r as CONNECT_SCOPES, s as WORKSPACE_PERMISSION_KEYS, t as CONNECT_OPERATIONS, u as canAll } from "./permissions-
|
|
1
|
+
import { a as ConnectOperationRule, c as WorkspacePermissionKey, d as canAny, f as canCall, i as ConnectOperation, l as can, n as CONNECT_OPERATION_NAMES, o as ConnectScope, r as CONNECT_SCOPES, s as WORKSPACE_PERMISSION_KEYS, t as CONNECT_OPERATIONS, u as canAll } from "./permissions-DKm_zC_X.js";
|
|
2
2
|
import { a as iterate, i as SortOf, n as Page, o as listAll, r as PageQuery, t as CountedPage } from "./page-j1OCu4of.js";
|
|
3
3
|
import { a as PlatformSdkErrorCode, c as isNotImplemented, d as isPlatformError, f as isSignInRequired, i as PlatformFieldError, l as isPermissionDenied, n as PlatformApiError, o as PlatformServerErrorCode, r as PlatformErrorCode, s as SDK_ERROR_CODES, t as PLATFORM_ERROR_CODES, u as isPlatformApiError } from "./errors-CLUuzCNG.js";
|
|
4
|
-
import { $ as
|
|
4
|
+
import { $ as ConnectStageColor, A as ConnectInquiryMoveResult, At as connectPostGroupSchema, B as ConnectPostGroup, C as ConnectFolder, Ct as connectInquiryDetailSchema, D as ConnectFormType, Dt as connectMemberSchema, E as ConnectFormStatus, Et as connectMeSchema, F as ConnectNotificationKind, Ft as connectTaskFeedItemSchema, G as ConnectPostSpec, H as ConnectPostListQuery, I as ConnectPipeline, It as connectTaskSchema, J as ConnectPostTag, K as ConnectPostStatus, L as ConnectPost, Lt as createConnectClient, M as ConnectMember, Mt as connectPostSummarySchema, N as ConnectMemberRole, Nt as connectPostTagSchema, O as ConnectInquiry, Ot as connectNotificationSchema, P as ConnectNotification, Pt as connectTaskCommentSchema, Q as ConnectSignedUrlOptions, R as ConnectPostAuthor, S as ConnectFileVisibility, St as connectFormSchema, T as ConnectForm, Tt as connectInquirySchema, U as ConnectPostMetaInput, V as ConnectPostGroupKind, W as ConnectPostSortField, X as ConnectRequestOptions, Y as ConnectPostUpdateInput, Z as ConnectSignedUrl, _ as ConnectEavRecord, _t as connectEavEntitySchema, a as ConnectClientConfig, at as ConnectTaskFeedItem, b as ConnectFileSortField, bt as connectFileUsageSchema, c as ConnectCustomerEvent, ct as ConnectTaskMoveInput, d as ConnectCustomerNote, dt as ConnectTaskUpdateInput, et as ConnectStageOutcome, f as ConnectCustomerRecord, ft as ConnectWorkspaceTier, g as ConnectEavEntity, gt as connectCustomerSummarySchema, h as ConnectCustomerUpdateInput, ht as connectCustomerSchema, i as ConnectClient, it as ConnectTaskCreateInput, j as ConnectMe, jt as connectPostSchema, k as ConnectInquiryDetail, kt as connectPipelineSchema, l as ConnectCustomerField, lt as ConnectTaskPriority, m as ConnectCustomerTag, mt as connectCustomerNoteSchema, n as ConnectAnswerValue, nt as ConnectTaskActivity, o as ConnectCustomer, ot as ConnectTaskFeedMember, p as ConnectCustomerSummary, pt as connectBrandSchema, q as ConnectPostSummary, r as ConnectBrand, rt as ConnectTaskComment, s as ConnectCustomerCreateInput, st as ConnectTaskListQuery, t as ConnectAccessToken, tt as ConnectTask, u as ConnectCustomerListQuery, ut as ConnectTaskSortField, v as ConnectFile, vt as connectEavRecordSchema, w as ConnectFolderKind, wt as connectInquiryMoveResultSchema, x as ConnectFileUsage, xt as connectFolderSchema, y as ConnectFileListQuery, yt as connectFileSchema, z as ConnectPostCreateInput } from "./connect-CTxppAjD.js";
|
|
5
5
|
import { n as mentionToken, r as splitMentions, t as MentionSegment } from "./mentions-BMI2c7O6.js";
|
|
6
|
-
export { CONNECT_OPERATIONS, CONNECT_OPERATION_NAMES, CONNECT_SCOPES, type ConnectAccessToken, type ConnectAnswerValue, type ConnectBrand, type ConnectClient, type ConnectClientConfig, type ConnectCustomer, type ConnectCustomerCreateInput, type ConnectCustomerEvent, type ConnectCustomerField, type ConnectCustomerListQuery, type ConnectCustomerNote, type ConnectCustomerRecord, type ConnectCustomerSummary, type ConnectCustomerTag, type ConnectCustomerUpdateInput, type ConnectEavEntity, type ConnectEavRecord, type ConnectFile, type ConnectFileListQuery, type ConnectFileSortField, type ConnectFileUsage, type ConnectFileVisibility, type ConnectFolder, type ConnectFolderKind, type ConnectForm, type ConnectFormStatus, type ConnectFormType, type ConnectInquiry, type ConnectInquiryDetail, type ConnectInquiryMoveResult, type ConnectMe, type ConnectMember, type ConnectMemberRole, type ConnectOperation, type ConnectOperationRule, type ConnectPipeline, type ConnectPost, type ConnectPostAuthor, type ConnectPostCreateInput, type ConnectPostGroup, type ConnectPostGroupKind, type ConnectPostListQuery, type ConnectPostMetaInput, type ConnectPostSortField, type ConnectPostSpec, type ConnectPostStatus, type ConnectPostSummary, type ConnectPostTag, type ConnectPostUpdateInput, type ConnectRequestOptions, type ConnectScope, type ConnectSignedUrl, type ConnectSignedUrlOptions, type ConnectStageColor, type ConnectStageOutcome, type ConnectTask, type ConnectTaskActivity, type ConnectTaskComment, type ConnectTaskCreateInput, type ConnectTaskFeedItem, type ConnectTaskFeedMember, type ConnectTaskListQuery, type ConnectTaskMoveInput, type ConnectTaskPriority, type ConnectTaskSortField, type ConnectTaskUpdateInput, type ConnectWorkspaceTier, type CountedPage, type MentionSegment, PLATFORM_ERROR_CODES, type Page, type PageQuery, PlatformApiError, type PlatformErrorCode, type PlatformFieldError, type PlatformSdkErrorCode, type PlatformServerErrorCode, SDK_ERROR_CODES, type SortOf, WORKSPACE_PERMISSION_KEYS, type WorkspacePermissionKey, can, canAll, canAny, canCall, connectBrandSchema, type connectCustomerNoteSchema, type connectCustomerSchema, type connectCustomerSummarySchema, connectEavEntitySchema, connectEavRecordSchema, connectFileSchema, connectFileUsageSchema, connectFolderSchema, connectFormSchema, connectInquiryDetailSchema, type connectInquiryMoveResultSchema, connectInquirySchema, connectMeSchema, connectMemberSchema, connectPipelineSchema, connectPostGroupSchema, connectPostSchema, connectPostSummarySchema, connectPostTagSchema, type connectTaskCommentSchema, type connectTaskFeedItemSchema, connectTaskSchema, createConnectClient, isNotImplemented, isPermissionDenied, isPlatformApiError, isPlatformError, isSignInRequired, iterate, listAll, mentionToken, splitMentions };
|
|
6
|
+
export { CONNECT_OPERATIONS, CONNECT_OPERATION_NAMES, CONNECT_SCOPES, type ConnectAccessToken, type ConnectAnswerValue, type ConnectBrand, type ConnectClient, type ConnectClientConfig, type ConnectCustomer, type ConnectCustomerCreateInput, type ConnectCustomerEvent, type ConnectCustomerField, type ConnectCustomerListQuery, type ConnectCustomerNote, type ConnectCustomerRecord, type ConnectCustomerSummary, type ConnectCustomerTag, type ConnectCustomerUpdateInput, type ConnectEavEntity, type ConnectEavRecord, type ConnectFile, type ConnectFileListQuery, type ConnectFileSortField, type ConnectFileUsage, type ConnectFileVisibility, type ConnectFolder, type ConnectFolderKind, type ConnectForm, type ConnectFormStatus, type ConnectFormType, type ConnectInquiry, type ConnectInquiryDetail, type ConnectInquiryMoveResult, type ConnectMe, type ConnectMember, type ConnectMemberRole, type ConnectNotification, type ConnectNotificationKind, type ConnectOperation, type ConnectOperationRule, type ConnectPipeline, type ConnectPost, type ConnectPostAuthor, type ConnectPostCreateInput, type ConnectPostGroup, type ConnectPostGroupKind, type ConnectPostListQuery, type ConnectPostMetaInput, type ConnectPostSortField, type ConnectPostSpec, type ConnectPostStatus, type ConnectPostSummary, type ConnectPostTag, type ConnectPostUpdateInput, type ConnectRequestOptions, type ConnectScope, type ConnectSignedUrl, type ConnectSignedUrlOptions, type ConnectStageColor, type ConnectStageOutcome, type ConnectTask, type ConnectTaskActivity, type ConnectTaskComment, type ConnectTaskCreateInput, type ConnectTaskFeedItem, type ConnectTaskFeedMember, type ConnectTaskListQuery, type ConnectTaskMoveInput, type ConnectTaskPriority, type ConnectTaskSortField, type ConnectTaskUpdateInput, type ConnectWorkspaceTier, type CountedPage, type MentionSegment, PLATFORM_ERROR_CODES, type Page, type PageQuery, PlatformApiError, type PlatformErrorCode, type PlatformFieldError, type PlatformSdkErrorCode, type PlatformServerErrorCode, SDK_ERROR_CODES, type SortOf, WORKSPACE_PERMISSION_KEYS, type WorkspacePermissionKey, can, canAll, canAny, canCall, connectBrandSchema, type connectCustomerNoteSchema, type connectCustomerSchema, type connectCustomerSummarySchema, connectEavEntitySchema, connectEavRecordSchema, connectFileSchema, connectFileUsageSchema, connectFolderSchema, connectFormSchema, connectInquiryDetailSchema, type connectInquiryMoveResultSchema, connectInquirySchema, connectMeSchema, connectMemberSchema, type connectNotificationSchema, connectPipelineSchema, connectPostGroupSchema, connectPostSchema, connectPostSummarySchema, connectPostTagSchema, type connectTaskCommentSchema, type connectTaskFeedItemSchema, connectTaskSchema, createConnectClient, isNotImplemented, isPermissionDenied, isPlatformApiError, isPlatformError, isSignInRequired, iterate, listAll, mentionToken, splitMentions };
|
package/dist/connect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as isPermissionDenied, c as isSignInRequired, i as isNotImplemented, n as PlatformApiError, o as isPlatformApiError, r as SDK_ERROR_CODES, s as isPlatformError, t as PLATFORM_ERROR_CODES } from "./errors-
|
|
1
|
+
import { a as isPermissionDenied, c as isSignInRequired, i as isNotImplemented, n as PlatformApiError, o as isPlatformApiError, r as SDK_ERROR_CODES, s as isPlatformError, t as PLATFORM_ERROR_CODES } from "./errors-DKMC4kId.js";
|
|
2
2
|
import { CONNECT_OPERATIONS, CONNECT_OPERATION_NAMES, CONNECT_SCOPES, WORKSPACE_PERMISSION_KEYS, can, canAll, canAny, canCall } from "./permissions.js";
|
|
3
3
|
import { mentionToken, splitMentions } from "./mentions.js";
|
|
4
|
-
import { _ as connectPostSummarySchema, a as connectEavRecordSchema, b as createConnectClient, c as connectFolderSchema, d as connectInquirySchema, f as connectMeSchema, g as connectPostSchema, h as connectPostGroupSchema, i as connectEavEntitySchema, l as connectFormSchema, m as connectPipelineSchema, n as listAll, o as connectFileSchema, p as connectMemberSchema, r as connectBrandSchema, s as connectFileUsageSchema, t as iterate, u as connectInquiryDetailSchema, v as connectPostTagSchema, y as connectTaskSchema } from "./page-
|
|
4
|
+
import { _ as connectPostSummarySchema, a as connectEavRecordSchema, b as createConnectClient, c as connectFolderSchema, d as connectInquirySchema, f as connectMeSchema, g as connectPostSchema, h as connectPostGroupSchema, i as connectEavEntitySchema, l as connectFormSchema, m as connectPipelineSchema, n as listAll, o as connectFileSchema, p as connectMemberSchema, r as connectBrandSchema, s as connectFileUsageSchema, t as iterate, u as connectInquiryDetailSchema, v as connectPostTagSchema, y as connectTaskSchema } from "./page-rc95cliL.js";
|
|
5
5
|
|
|
6
6
|
export { CONNECT_OPERATIONS, CONNECT_OPERATION_NAMES, CONNECT_SCOPES, PLATFORM_ERROR_CODES, PlatformApiError, SDK_ERROR_CODES, WORKSPACE_PERMISSION_KEYS, can, canAll, canAny, canCall, connectBrandSchema, connectEavEntitySchema, connectEavRecordSchema, connectFileSchema, connectFileUsageSchema, connectFolderSchema, connectFormSchema, connectInquiryDetailSchema, connectInquirySchema, connectMeSchema, connectMemberSchema, connectPipelineSchema, connectPostGroupSchema, connectPostSchema, connectPostSummarySchema, connectPostTagSchema, connectTaskSchema, createConnectClient, isNotImplemented, isPermissionDenied, isPlatformApiError, isPlatformError, isSignInRequired, iterate, listAll, mentionToken, splitMentions };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/version.ts
|
|
2
2
|
/** 이 패키지(`@reopt-ai/workspace-sdk`)의 버전 — 빌드가 package.json에서 주입한다(미번들 실행은 `0.0.0-dev`). */
|
|
3
|
-
const SDK_VERSION = "0.1.0-rc.
|
|
3
|
+
const SDK_VERSION = "0.1.0-rc.13";
|
|
4
4
|
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/workspace/errors.ts
|
|
@@ -120,4 +120,4 @@ function isPermissionDenied(error) {
|
|
|
120
120
|
|
|
121
121
|
//#endregion
|
|
122
122
|
export { isPermissionDenied as a, isSignInRequired as c, isNotImplemented as i, SDK_VERSION as l, PlatformApiError as n, isPlatformApiError as o, SDK_ERROR_CODES as r, isPlatformError as s, PLATFORM_ERROR_CODES as t };
|
|
123
|
-
//# sourceMappingURL=errors-
|
|
123
|
+
//# sourceMappingURL=errors-DKMC4kId.js.map
|
package/dist/forms.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
//#region src/forms.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `@reopt-ai/workspace-sdk/forms` — 공개 폼(브랜드폼) 클라이언트. 방문자 브라우저가 리옵트에 **직접** 제출한다.
|
|
4
|
+
*
|
|
5
|
+
* 의존이 없다 — 클라이언트 컴포넌트에서 쓴다. 인증도 없다: 폼 id는 비밀이 아니고, 게시된 폼만 열린다.
|
|
6
|
+
*
|
|
7
|
+
* 🔑 **앱 서버로 중계하지 않는다.** 리옵트의 제출 한도는 방문자 IP 기준이라, 서버가 대신 보내면 모든 방문자가 서버 IP
|
|
8
|
+
* 하나로 묶여 그 한도를 나눠 쓴다. 리옵트는 이 주소에 CORS를 열어 두었고 쿠키는 받지 않는다(RFC-0043 §3.6).
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const forms = createPublicFormClient();
|
|
12
|
+
* const form = await forms.get(formId); // 게시된 정의 — 필드·동의 항목·버튼 문구
|
|
13
|
+
* try {
|
|
14
|
+
* const { successMessage } = await forms.submit(formId, { values, consents, meta: { hp } });
|
|
15
|
+
* } catch (error) {
|
|
16
|
+
* if (isPublicFormError(error)) showErrors(error.fieldErrors, error.message);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/** 리옵트 Studio 호스트 — 공개 폼 주소가 여기에 있다. */
|
|
21
|
+
declare const REOPT_STUDIO_URL: string;
|
|
22
|
+
type PublicFormFieldType = "string" | "number" | "boolean" | "date" | "email" | "url" | "select" | "multiselect" | "textarea" | "file";
|
|
23
|
+
type PublicFormField = {
|
|
24
|
+
/** 제출 본문 `values`의 키이자 문의 `answers`의 키 */
|
|
25
|
+
name: string;
|
|
26
|
+
label: string;
|
|
27
|
+
type: PublicFormFieldType | (string & {});
|
|
28
|
+
required: boolean;
|
|
29
|
+
placeholder: string | null;
|
|
30
|
+
description: string | null;
|
|
31
|
+
/** 선택형의 선택지 — 제출 값은 `value`다 */
|
|
32
|
+
options: {
|
|
33
|
+
value: string;
|
|
34
|
+
label: string;
|
|
35
|
+
}[] | null;
|
|
36
|
+
/** 브라우저 자동완성에 쓰는 의미(이름·이메일·전화) */
|
|
37
|
+
inputPurpose?: "name" | "email" | "tel" | null;
|
|
38
|
+
/** 저장 타입은 그대로 두고 입력 모양만 바꾸는 표현(전화·시간·별점 등) */
|
|
39
|
+
appearance?: string | null;
|
|
40
|
+
scaleMax?: number | null;
|
|
41
|
+
};
|
|
42
|
+
type PublicFormConsentItem = {
|
|
43
|
+
/** 제출 본문 `consents`의 키 */
|
|
44
|
+
id: string;
|
|
45
|
+
label: string;
|
|
46
|
+
details?: string | null;
|
|
47
|
+
/** 필수 동의 — 빠지면 리옵트가 `CONSENT_REQUIRED`로 거절한다 */
|
|
48
|
+
required: boolean;
|
|
49
|
+
/** 약관 전문 주소 */
|
|
50
|
+
linkUrl: string | null;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* 게시된 폼의 정의. 여기 적힌 필드는 약속이고, 그 밖의 것(테마·페이지 분할·예약 정보 등 리옵트 렌더러가 쓰는 값)도
|
|
54
|
+
* 그대로 실려 온다 — 이름을 약속하지 않으므로 타입에는 없다.
|
|
55
|
+
*/
|
|
56
|
+
type PublicForm = {
|
|
57
|
+
formId: string;
|
|
58
|
+
name: string;
|
|
59
|
+
fields: PublicFormField[];
|
|
60
|
+
/** 제출 버튼 문구 — 없으면 앱이 정한다 */
|
|
61
|
+
submitLabel: string | null;
|
|
62
|
+
/** 제출 뒤 보여 줄 문구 */
|
|
63
|
+
successMessage: string | null;
|
|
64
|
+
/** 동의 항목 — 없으면 빈 배열 */
|
|
65
|
+
consent: PublicFormConsentItem[];
|
|
66
|
+
[extra: string]: unknown;
|
|
67
|
+
};
|
|
68
|
+
type PublicFormSubmitMeta = {
|
|
69
|
+
/**
|
|
70
|
+
* 허니팟 — 사람에게 보이지 않는 입력의 값. 채워져 있으면 리옵트는 **성공처럼 답하고 버린다**
|
|
71
|
+
* (`submissionId: null`). 봇에게 단서를 주지 않으려는 것이니 앱도 평소처럼 완료 화면을 보인다.
|
|
72
|
+
*/
|
|
73
|
+
hp?: string;
|
|
74
|
+
locale?: string;
|
|
75
|
+
/** 폼이 놓인 페이지 경로 */
|
|
76
|
+
pagePath?: string;
|
|
77
|
+
/** 유입 주소 — 리옵트가 origin + 경로만 남긴다 */
|
|
78
|
+
referrer?: string;
|
|
79
|
+
/** 추천 코드 */
|
|
80
|
+
ref?: string;
|
|
81
|
+
utm?: Partial<Record<"utm_source" | "utm_medium" | "utm_campaign" | "utm_term" | "utm_content", string>>;
|
|
82
|
+
/** 예약 폼 — 고른 시각(ISO)과 방문자 타임존 */
|
|
83
|
+
bookedAt?: string;
|
|
84
|
+
timezone?: string;
|
|
85
|
+
};
|
|
86
|
+
type PublicFormSubmission = {
|
|
87
|
+
/** 필드 `name` → 값. 비운 답(빈 문자열·null)은 "답하지 않음"으로 읽는다 */
|
|
88
|
+
values: Record<string, unknown>;
|
|
89
|
+
/** 동의 항목 `id` → 동의 여부 */
|
|
90
|
+
consents?: Record<string, boolean>;
|
|
91
|
+
meta?: PublicFormSubmitMeta;
|
|
92
|
+
};
|
|
93
|
+
type PublicFormSubmitResult = {
|
|
94
|
+
/** 허니팟에 걸린 제출은 null */
|
|
95
|
+
submissionId: string | null;
|
|
96
|
+
successMessage: string | null;
|
|
97
|
+
};
|
|
98
|
+
/** 리옵트가 내는 코드(앞의 여섯) + 클라이언트가 만드는 코드(뒤의 셋). 목록 밖의 코드도 문자열로 그대로 온다. */
|
|
99
|
+
type PublicFormErrorCode = "FORM_NOT_FOUND" | "VALIDATION_ERROR" | "CONSENT_REQUIRED" | "RATE_LIMITED" | "PAYLOAD_TOO_LARGE" | "SUBMISSION_IN_PROGRESS" | "NETWORK_ERROR" | "TIMEOUT" | "INVALID_RESPONSE" | (string & {});
|
|
100
|
+
/**
|
|
101
|
+
* 공개 폼 요청의 실패 — 이 클라이언트가 던지는 것은 언제나 이것이다(요청을 취소한 `AbortError`만 예외).
|
|
102
|
+
*
|
|
103
|
+
* - `fieldErrors` — 칸별 문구(필드 `name` 또는 동의 항목 `id` → 문구). 없으면 빈 객체
|
|
104
|
+
* - `message` — 방문자에게 그대로 보여도 되는 문구(리옵트가 준 것). 클라이언트가 만든 코드는 영문이다
|
|
105
|
+
* - `retryable` — 잠시 뒤 같은 요청을 다시 보내도 되는가(한도 초과·처리 중·네트워크)
|
|
106
|
+
*/
|
|
107
|
+
declare class PublicFormError extends Error {
|
|
108
|
+
readonly code: PublicFormErrorCode;
|
|
109
|
+
/** HTTP 상태 — 응답을 받지 못했으면 0 */
|
|
110
|
+
readonly status: number;
|
|
111
|
+
readonly fieldErrors: Record<string, string>;
|
|
112
|
+
readonly retryable: boolean;
|
|
113
|
+
constructor(input: {
|
|
114
|
+
code: PublicFormErrorCode;
|
|
115
|
+
message: string;
|
|
116
|
+
status: number;
|
|
117
|
+
fieldErrors?: Record<string, string>;
|
|
118
|
+
retryable?: boolean;
|
|
119
|
+
cause?: unknown;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** `instanceof` 대신 — 번들이 둘로 갈려도(서버·클라이언트 사본) 맞는다. */
|
|
123
|
+
declare function isPublicFormError(error: unknown): error is PublicFormError;
|
|
124
|
+
type PublicFormClientOptions = {
|
|
125
|
+
/** 리옵트 Studio 주소 — 기본 `https://studio.reopt.ai`. 개발에서는 에뮬레이터의 `browserBaseUrl` */
|
|
126
|
+
studioUrl?: string;
|
|
127
|
+
fetch?: typeof globalThis.fetch;
|
|
128
|
+
/** 응답을 기다리는 상한(ms) — 기본 15000 */
|
|
129
|
+
timeoutMs?: number;
|
|
130
|
+
};
|
|
131
|
+
type PublicFormRequestOptions = {
|
|
132
|
+
signal?: AbortSignal;
|
|
133
|
+
};
|
|
134
|
+
type PublicFormClient = {
|
|
135
|
+
/** 정의를 읽는 주소 */
|
|
136
|
+
url: (formId: string) => string;
|
|
137
|
+
/** 제출 주소 — JS 없이 동작하는 `<form>`을 직접 짜거나 CSP `connect-src`에 넣을 때 */
|
|
138
|
+
submitUrl: (formId: string) => string;
|
|
139
|
+
/** 게시된 폼의 정의. 게시되지 않았거나 없는 폼은 `FORM_NOT_FOUND` */
|
|
140
|
+
get: (formId: string, options?: PublicFormRequestOptions) => Promise<PublicForm>;
|
|
141
|
+
/** 제출. 칸이 틀리면 `VALIDATION_ERROR`·`CONSENT_REQUIRED`에 `fieldErrors`가 실린다 */
|
|
142
|
+
submit: (formId: string, submission: PublicFormSubmission, options?: PublicFormRequestOptions) => Promise<PublicFormSubmitResult>;
|
|
143
|
+
};
|
|
144
|
+
declare function createPublicFormClient(options?: PublicFormClientOptions): PublicFormClient;
|
|
145
|
+
type LabeledAnswer = {
|
|
146
|
+
/** 필드 `name` */
|
|
147
|
+
name: string;
|
|
148
|
+
/** 폼의 라벨 — 지금 폼에 없는 칸(나중에 지운 필드)의 답이면 `name` 그대로 */
|
|
149
|
+
label: string;
|
|
150
|
+
value: unknown;
|
|
151
|
+
/** 사람이 읽는 값 — 선택형은 선택지 라벨, 여러 값은 쉼표로, 예/아니오 */
|
|
152
|
+
text: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* 제출된 답(`answers`)에 폼의 라벨을 붙인다 — 관리 화면이 필드 이름을 손으로 적지 않게.
|
|
156
|
+
* 순서는 폼의 필드 순서이고, 폼에 없는 키의 답은 뒤에 붙는다(지운 필드의 옛 답을 숨기지 않는다).
|
|
157
|
+
* 비어 있는 답은 뺀다.
|
|
158
|
+
*
|
|
159
|
+
* ```ts
|
|
160
|
+
* const form = await forms.get(inquiry.formId);
|
|
161
|
+
* labelAnswers(form.fields, inquiry.answers).map(({ label, text }) => …);
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function labelAnswers(fields: readonly PublicFormField[], answers: Readonly<Record<string, unknown>>): LabeledAnswer[];
|
|
165
|
+
//#endregion
|
|
166
|
+
export { LabeledAnswer, PublicForm, PublicFormClient, PublicFormClientOptions, PublicFormConsentItem, PublicFormError, PublicFormErrorCode, PublicFormField, PublicFormFieldType, PublicFormRequestOptions, PublicFormSubmission, PublicFormSubmitMeta, PublicFormSubmitResult, REOPT_STUDIO_URL, createPublicFormClient, isPublicFormError, labelAnswers };
|
|
167
|
+
//# sourceMappingURL=forms.d.ts.map
|
package/dist/forms.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
//#region src/forms.ts
|
|
2
|
+
/**
|
|
3
|
+
* `@reopt-ai/workspace-sdk/forms` — 공개 폼(브랜드폼) 클라이언트. 방문자 브라우저가 리옵트에 **직접** 제출한다.
|
|
4
|
+
*
|
|
5
|
+
* 의존이 없다 — 클라이언트 컴포넌트에서 쓴다. 인증도 없다: 폼 id는 비밀이 아니고, 게시된 폼만 열린다.
|
|
6
|
+
*
|
|
7
|
+
* 🔑 **앱 서버로 중계하지 않는다.** 리옵트의 제출 한도는 방문자 IP 기준이라, 서버가 대신 보내면 모든 방문자가 서버 IP
|
|
8
|
+
* 하나로 묶여 그 한도를 나눠 쓴다. 리옵트는 이 주소에 CORS를 열어 두었고 쿠키는 받지 않는다(RFC-0043 §3.6).
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const forms = createPublicFormClient();
|
|
12
|
+
* const form = await forms.get(formId); // 게시된 정의 — 필드·동의 항목·버튼 문구
|
|
13
|
+
* try {
|
|
14
|
+
* const { successMessage } = await forms.submit(formId, { values, consents, meta: { hp } });
|
|
15
|
+
* } catch (error) {
|
|
16
|
+
* if (isPublicFormError(error)) showErrors(error.fieldErrors, error.message);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/** 리옵트 Studio 호스트 — 공개 폼 주소가 여기에 있다. */
|
|
21
|
+
const REOPT_STUDIO_URL = "https://studio.reopt.ai";
|
|
22
|
+
const BRAND = "@reopt-ai/workspace-sdk:PublicFormError";
|
|
23
|
+
/**
|
|
24
|
+
* 공개 폼 요청의 실패 — 이 클라이언트가 던지는 것은 언제나 이것이다(요청을 취소한 `AbortError`만 예외).
|
|
25
|
+
*
|
|
26
|
+
* - `fieldErrors` — 칸별 문구(필드 `name` 또는 동의 항목 `id` → 문구). 없으면 빈 객체
|
|
27
|
+
* - `message` — 방문자에게 그대로 보여도 되는 문구(리옵트가 준 것). 클라이언트가 만든 코드는 영문이다
|
|
28
|
+
* - `retryable` — 잠시 뒤 같은 요청을 다시 보내도 되는가(한도 초과·처리 중·네트워크)
|
|
29
|
+
*/
|
|
30
|
+
var PublicFormError = class extends Error {
|
|
31
|
+
code;
|
|
32
|
+
/** HTTP 상태 — 응답을 받지 못했으면 0 */
|
|
33
|
+
status;
|
|
34
|
+
fieldErrors;
|
|
35
|
+
retryable;
|
|
36
|
+
constructor(input) {
|
|
37
|
+
super(input.message, input.cause === void 0 ? void 0 : { cause: input.cause });
|
|
38
|
+
this.name = "PublicFormError";
|
|
39
|
+
this.code = input.code;
|
|
40
|
+
this.status = input.status;
|
|
41
|
+
this.fieldErrors = input.fieldErrors ?? {};
|
|
42
|
+
this.retryable = input.retryable ?? false;
|
|
43
|
+
Object.defineProperty(this, BRAND, { value: true });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** `instanceof` 대신 — 번들이 둘로 갈려도(서버·클라이언트 사본) 맞는다. */
|
|
47
|
+
function isPublicFormError(error) {
|
|
48
|
+
return typeof error === "object" && error !== null && error[BRAND] === true;
|
|
49
|
+
}
|
|
50
|
+
const DEFAULT_TIMEOUT_MS = 15e3;
|
|
51
|
+
const RETRYABLE = /* @__PURE__ */ new Set([
|
|
52
|
+
"RATE_LIMITED",
|
|
53
|
+
"SUBMISSION_IN_PROGRESS",
|
|
54
|
+
"NETWORK_ERROR",
|
|
55
|
+
"TIMEOUT"
|
|
56
|
+
]);
|
|
57
|
+
function isRecord(value) {
|
|
58
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59
|
+
}
|
|
60
|
+
function readFieldErrors(error) {
|
|
61
|
+
const out = {};
|
|
62
|
+
if (isRecord(error.fieldErrors)) {
|
|
63
|
+
for (const [key, value] of Object.entries(error.fieldErrors)) if (typeof value === "string") out[key] = value;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(error.fields)) {
|
|
66
|
+
for (const item of error.fields) if (isRecord(item) && typeof item.field === "string" && typeof item.message === "string" && !(item.field in out)) out[item.field] = item.message;
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function createPublicFormClient(options = {}) {
|
|
71
|
+
const base = (options.studioUrl ?? "https://studio.reopt.ai").replace(/\/+$/, "");
|
|
72
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
73
|
+
const url = (formId) => `${base}/api/brandfront/forms/${encodeURIComponent(formId)}`;
|
|
74
|
+
const submitUrl = (formId) => `${url(formId)}/submit`;
|
|
75
|
+
const request = async (target, init, signal) => {
|
|
76
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
77
|
+
const controller = new AbortController();
|
|
78
|
+
let timedOut = false;
|
|
79
|
+
const timer = setTimeout(() => {
|
|
80
|
+
timedOut = true;
|
|
81
|
+
controller.abort();
|
|
82
|
+
}, timeoutMs);
|
|
83
|
+
const onAbort = () => controller.abort(signal?.reason);
|
|
84
|
+
if (signal?.aborted) onAbort();
|
|
85
|
+
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
86
|
+
let response;
|
|
87
|
+
let body;
|
|
88
|
+
try {
|
|
89
|
+
response = await doFetch(target, {
|
|
90
|
+
...init,
|
|
91
|
+
credentials: "omit",
|
|
92
|
+
signal: controller.signal
|
|
93
|
+
});
|
|
94
|
+
body = await response.json().catch(() => null);
|
|
95
|
+
} catch (cause) {
|
|
96
|
+
if (signal?.aborted && !timedOut) throw cause;
|
|
97
|
+
throw new PublicFormError(timedOut ? {
|
|
98
|
+
code: "TIMEOUT",
|
|
99
|
+
message: `Reopt did not answer within ${timeoutMs}ms`,
|
|
100
|
+
status: 0,
|
|
101
|
+
retryable: true,
|
|
102
|
+
cause
|
|
103
|
+
} : {
|
|
104
|
+
code: "NETWORK_ERROR",
|
|
105
|
+
message: "Could not reach Reopt",
|
|
106
|
+
status: 0,
|
|
107
|
+
retryable: true,
|
|
108
|
+
cause
|
|
109
|
+
});
|
|
110
|
+
} finally {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
signal?.removeEventListener("abort", onAbort);
|
|
113
|
+
}
|
|
114
|
+
if (!response.ok) {
|
|
115
|
+
const error = isRecord(body) && isRecord(body.error) ? body.error : null;
|
|
116
|
+
const code = error && typeof error.code === "string" ? error.code : response.status === 429 ? "RATE_LIMITED" : "INVALID_RESPONSE";
|
|
117
|
+
throw new PublicFormError({
|
|
118
|
+
code,
|
|
119
|
+
message: error && typeof error.message === "string" ? error.message : `Reopt answered ${response.status}`,
|
|
120
|
+
status: response.status,
|
|
121
|
+
fieldErrors: error ? readFieldErrors(error) : {},
|
|
122
|
+
retryable: RETRYABLE.has(code) || response.status >= 500
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (!isRecord(body) || !isRecord(body.data)) throw new PublicFormError({
|
|
126
|
+
code: "INVALID_RESPONSE",
|
|
127
|
+
message: "Reopt answered in an unexpected shape",
|
|
128
|
+
status: response.status
|
|
129
|
+
});
|
|
130
|
+
return body.data;
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
url,
|
|
134
|
+
submitUrl,
|
|
135
|
+
get: async (formId, requestOptions) => {
|
|
136
|
+
const data = await request(url(formId), {
|
|
137
|
+
method: "GET",
|
|
138
|
+
headers: { Accept: "application/json" }
|
|
139
|
+
}, requestOptions?.signal);
|
|
140
|
+
if (typeof data.formId !== "string" || typeof data.name !== "string" || !Array.isArray(data.fields)) throw new PublicFormError({
|
|
141
|
+
code: "INVALID_RESPONSE",
|
|
142
|
+
message: "Reopt answered in an unexpected shape",
|
|
143
|
+
status: 200
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
...data,
|
|
147
|
+
formId: data.formId,
|
|
148
|
+
name: data.name,
|
|
149
|
+
fields: data.fields,
|
|
150
|
+
submitLabel: typeof data.submitLabel === "string" ? data.submitLabel : null,
|
|
151
|
+
successMessage: typeof data.successMessage === "string" ? data.successMessage : null,
|
|
152
|
+
consent: Array.isArray(data.consent) ? data.consent : []
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
submit: async (formId, submission, requestOptions) => {
|
|
156
|
+
const data = await request(submitUrl(formId), {
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers: {
|
|
159
|
+
Accept: "application/json",
|
|
160
|
+
"Content-Type": "application/json"
|
|
161
|
+
},
|
|
162
|
+
body: JSON.stringify({
|
|
163
|
+
values: submission.values,
|
|
164
|
+
...submission.consents ? { consents: submission.consents } : {},
|
|
165
|
+
...submission.meta ? { meta: submission.meta } : {}
|
|
166
|
+
})
|
|
167
|
+
}, requestOptions?.signal);
|
|
168
|
+
return {
|
|
169
|
+
submissionId: typeof data.submissionId === "string" ? data.submissionId : null,
|
|
170
|
+
successMessage: typeof data.successMessage === "string" ? data.successMessage : null
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function answerText(value, options) {
|
|
176
|
+
if (value === null || value === void 0) return "";
|
|
177
|
+
if (Array.isArray(value)) return value.map((item) => answerText(item, options)).filter(Boolean).join(", ");
|
|
178
|
+
if (typeof value === "boolean") return value ? "예" : "아니오";
|
|
179
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
180
|
+
const raw = String(value);
|
|
181
|
+
return options?.find((option) => option.value === raw)?.label ?? raw;
|
|
182
|
+
}
|
|
183
|
+
if (isRecord(value)) {
|
|
184
|
+
if (typeof value.name === "string") return value.name;
|
|
185
|
+
if (typeof value.url === "string") return value.url;
|
|
186
|
+
}
|
|
187
|
+
return JSON.stringify(value);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 제출된 답(`answers`)에 폼의 라벨을 붙인다 — 관리 화면이 필드 이름을 손으로 적지 않게.
|
|
191
|
+
* 순서는 폼의 필드 순서이고, 폼에 없는 키의 답은 뒤에 붙는다(지운 필드의 옛 답을 숨기지 않는다).
|
|
192
|
+
* 비어 있는 답은 뺀다.
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* const form = await forms.get(inquiry.formId);
|
|
196
|
+
* labelAnswers(form.fields, inquiry.answers).map(({ label, text }) => …);
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
function labelAnswers(fields, answers) {
|
|
200
|
+
const rows = [];
|
|
201
|
+
const seen = /* @__PURE__ */ new Set();
|
|
202
|
+
const push = (name, label, options) => {
|
|
203
|
+
seen.add(name);
|
|
204
|
+
const value = answers[name];
|
|
205
|
+
const text = answerText(value, options);
|
|
206
|
+
if (text === "") return;
|
|
207
|
+
rows.push({
|
|
208
|
+
name,
|
|
209
|
+
label,
|
|
210
|
+
value,
|
|
211
|
+
text
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
for (const field of fields) push(field.name, field.label, field.options);
|
|
215
|
+
for (const name of Object.keys(answers)) if (!seen.has(name)) push(name, name, void 0);
|
|
216
|
+
return rows;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
export { PublicFormError, REOPT_STUDIO_URL, createPublicFormClient, isPublicFormError, labelAnswers };
|
|
221
|
+
//# sourceMappingURL=forms.js.map
|