@reopt-ai/brandapp-sdk 3.0.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +111 -3
  2. package/README.md +29 -13
  3. package/dist/ai/index.js +4 -3
  4. package/dist/ai-provider/index.js +16 -2
  5. package/dist/auth/index.js +4 -3
  6. package/dist/better-auth/index.d.ts +1 -1
  7. package/dist/better-auth/index.js +35 -24
  8. package/dist/chunk-2LSCQHAU.js +21 -0
  9. package/dist/{chunk-E457LO5A.js → chunk-4U4ZPPL4.js} +4 -4
  10. package/dist/{chunk-K3YVJE6E.js → chunk-55KHY5GH.js} +3 -3
  11. package/dist/{chunk-J5Y2GSJF.js → chunk-C5VTRZWX.js} +43 -28
  12. package/dist/{chunk-KU2LN5SE.js → chunk-FJUCWXX3.js} +4 -4
  13. package/dist/{chunk-TUKIYH4Q.js → chunk-H33OTQEN.js} +3 -3
  14. package/dist/chunk-OG7R3UAR.js +105 -0
  15. package/dist/{chunk-6FLYVNZI.js → chunk-PF24XU54.js} +3 -3
  16. package/dist/{chunk-6KPKZ7ZB.js → chunk-QN3QD67K.js} +3 -3
  17. package/dist/{chunk-YRGLBM6V.js → chunk-UGBBXCZE.js} +6 -6
  18. package/dist/{chunk-WSEROZVO.js → chunk-UVT2E6KD.js} +6 -6
  19. package/dist/{chunk-PJZB4VP7.js → chunk-YPLT3RFL.js} +3 -3
  20. package/dist/{chunk-DI6QJPTQ.js → chunk-YTKSAWV2.js} +20 -6
  21. package/dist/cms/index.js +10 -6
  22. package/dist/dev/index.d.ts +19 -0
  23. package/dist/dev/index.js +107 -4
  24. package/dist/eav/index.d.ts +1 -1
  25. package/dist/eav/index.js +5 -4
  26. package/dist/{errors-5hd5ZR-M.d.ts → errors-BjDFIyA6.d.ts} +25 -3
  27. package/dist/feedback/index.js +4 -3
  28. package/dist/files/index.js +4 -3
  29. package/dist/index.d.ts +10 -1
  30. package/dist/index.js +14 -13
  31. package/dist/logout/index.d.ts +106 -0
  32. package/dist/logout/index.js +321 -0
  33. package/dist/plans/index.d.ts +107 -11
  34. package/dist/plans/index.js +4 -3
  35. package/dist/push/index.js +4 -3
  36. package/dist/react/hooks.d.ts +5 -1
  37. package/dist/react/hooks.js +63 -15
  38. package/dist/terms/index.js +4 -3
  39. package/dist/testing/index.d.ts +1 -1
  40. package/dist/webhooks/index.d.ts +6 -3
  41. package/docs/api-reference.md +99 -3
  42. package/docs/cms.md +0 -1
  43. package/docs/dev-server.md +19 -18
  44. package/docs/errors.md +72 -15
  45. package/docs/logout.md +166 -0
  46. package/package.json +7 -1
  47. package/dist/chunk-T2WXHAAC.js +0 -54
@@ -0,0 +1,105 @@
1
+ import { BaseHttpClient } from './chunk-YTKSAWV2.js';
2
+
3
+ // src/plans/client.ts
4
+ function unwrap(body) {
5
+ if (body && typeof body === "object" && "data" in body) {
6
+ const withData = body;
7
+ if (withData.data !== void 0) return withData.data;
8
+ }
9
+ return body;
10
+ }
11
+ var ReoptPlansClient = class {
12
+ http;
13
+ constructor(config) {
14
+ this.http = new BaseHttpClient(
15
+ config,
16
+ `/api/v1/brandapp/${config.brandappId}/plans`
17
+ );
18
+ }
19
+ /**
20
+ * List active plans for this Brandapp (the customer-facing catalog). Works
21
+ * with either Basic Auth (default) or Bearer Auth — pass `accessToken` when
22
+ * calling from a handler that already has the customer's OAuth token to avoid
23
+ * sending app credentials.
24
+ */
25
+ async list(accessToken) {
26
+ const body = await this.http.fetch(
27
+ "GET",
28
+ "",
29
+ void 0,
30
+ accessToken ? { bearerToken: accessToken } : void 0
31
+ );
32
+ return unwrap(body);
33
+ }
34
+ /**
35
+ * Fetch the current plan / entitlement for the OAuth customer represented by
36
+ * `accessToken`. Returns `null` when the customer has no active plan.
37
+ */
38
+ async getMyPlan(accessToken) {
39
+ const body = await this.http.fetch(
40
+ "GET",
41
+ "/me/plan",
42
+ void 0,
43
+ { bearerToken: accessToken }
44
+ );
45
+ return unwrap(body);
46
+ }
47
+ /**
48
+ * Start a hosted checkout to subscribe the current customer (identified by
49
+ * `accessToken`) to `input.planId`, then redirect the browser to the returned
50
+ * `checkoutUrl`. In sandbox mode that URL is a virtual-payment page on
51
+ * id.reopt.ai which activates the subscription and returns to your
52
+ * `successUrl` / `cancelUrl`.
53
+ *
54
+ * @throws {RequiredTermsError} when the plan has required terms the customer
55
+ * has not consented to. Read `missingTermsIds`, collect consent via
56
+ * `sdk.terms`, then call again.
57
+ * @throws {ReoptSDKError} `LIVE_MODE_UNSUPPORTED` (409) when the Brandapp is
58
+ * configured for live Toss/Paddle payments (use the brandfront checkout).
59
+ */
60
+ async createCheckout(input, accessToken) {
61
+ const body = await this.http.fetch(
62
+ "POST",
63
+ "/me/checkout",
64
+ input,
65
+ { bearerToken: accessToken }
66
+ );
67
+ return unwrap(body);
68
+ }
69
+ /**
70
+ * Poll a checkout session by id (e.g. on your return page) to read its
71
+ * `status` — `completed` means the subscription is active. `checkoutUrl` is
72
+ * `null` here; use the URL from {@link createCheckout} to re-redirect.
73
+ */
74
+ async getCheckout(checkoutId, accessToken) {
75
+ const body = await this.http.fetch(
76
+ "GET",
77
+ `/me/checkout/${encodeURIComponent(checkoutId)}`,
78
+ void 0,
79
+ { bearerToken: accessToken }
80
+ );
81
+ return unwrap(body);
82
+ }
83
+ /**
84
+ * Cancel the current customer's active **sandbox** subscription. Access is
85
+ * kept until the paid period ends (the billing state becomes `canceled`).
86
+ * Real Toss/Paddle subscriptions are not affected — those use the provider
87
+ * flow.
88
+ */
89
+ async cancel(accessToken) {
90
+ const body = await this.http.fetch(
91
+ "POST",
92
+ "/me/subscription/cancel",
93
+ {},
94
+ { bearerToken: accessToken }
95
+ );
96
+ return unwrap(body);
97
+ }
98
+ };
99
+ function createReoptPlansClient(config) {
100
+ return new ReoptPlansClient(config);
101
+ }
102
+
103
+ export { ReoptPlansClient, createReoptPlansClient };
104
+ //# sourceMappingURL=chunk-OG7R3UAR.js.map
105
+ //# sourceMappingURL=chunk-OG7R3UAR.js.map
@@ -1,4 +1,4 @@
1
- import { ReoptSDKError } from './chunk-J5Y2GSJF.js';
1
+ import { ReoptSDKError } from './chunk-C5VTRZWX.js';
2
2
 
3
3
  // src/core/query.ts
4
4
  var MAX_QUERY_STRING_LENGTH = 7500;
@@ -28,5 +28,5 @@ function buildQuery(params) {
28
28
  }
29
29
 
30
30
  export { buildQuery };
31
- //# sourceMappingURL=chunk-6FLYVNZI.js.map
32
- //# sourceMappingURL=chunk-6FLYVNZI.js.map
31
+ //# sourceMappingURL=chunk-PF24XU54.js.map
32
+ //# sourceMappingURL=chunk-PF24XU54.js.map
@@ -1,4 +1,4 @@
1
- import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
1
+ import { BaseHttpClient } from './chunk-YTKSAWV2.js';
2
2
 
3
3
  // src/push/client.ts
4
4
  var ReoptPushClient = class {
@@ -45,5 +45,5 @@ function createReoptPushClient(config) {
45
45
  }
46
46
 
47
47
  export { ReoptPushClient, createReoptPushClient };
48
- //# sourceMappingURL=chunk-6KPKZ7ZB.js.map
49
- //# sourceMappingURL=chunk-6KPKZ7ZB.js.map
48
+ //# sourceMappingURL=chunk-QN3QD67K.js.map
49
+ //# sourceMappingURL=chunk-QN3QD67K.js.map
@@ -1,6 +1,6 @@
1
1
  import { createManagedAbort } from './chunk-F7BXBTZI.js';
2
- import { BaseHttpClient, parseFieldErrors } from './chunk-DI6QJPTQ.js';
3
- import { validateConfig, SDK_VERSION, mapHttpStatusToError, ReoptSDKError } from './chunk-J5Y2GSJF.js';
2
+ import { BaseHttpClient, parseFieldErrors } from './chunk-YTKSAWV2.js';
3
+ import { validateConfig, SDK_VERSION, mapHttpStatusToError, ReoptSDKError } from './chunk-C5VTRZWX.js';
4
4
 
5
5
  // src/files/client.ts
6
6
  var ReoptFileClient = class {
@@ -50,7 +50,7 @@ var ReoptFileClient = class {
50
50
  async get(fileId) {
51
51
  const response = await this.http.fetch(
52
52
  "GET",
53
- `/${fileId}`
53
+ `/${encodeURIComponent(fileId)}`
54
54
  );
55
55
  return response.data;
56
56
  }
@@ -63,7 +63,7 @@ var ReoptFileClient = class {
63
63
  * ```
64
64
  */
65
65
  async delete(fileId) {
66
- await this.http.fetch("DELETE", `/${fileId}`);
66
+ await this.http.fetch("DELETE", `/${encodeURIComponent(fileId)}`);
67
67
  }
68
68
  /**
69
69
  * 파일 업로드
@@ -153,5 +153,5 @@ function createReoptFileClient(config) {
153
153
  }
154
154
 
155
155
  export { ReoptFileClient, createReoptFileClient };
156
- //# sourceMappingURL=chunk-YRGLBM6V.js.map
157
- //# sourceMappingURL=chunk-YRGLBM6V.js.map
156
+ //# sourceMappingURL=chunk-UGBBXCZE.js.map
157
+ //# sourceMappingURL=chunk-UGBBXCZE.js.map
@@ -1,5 +1,5 @@
1
- import { buildQuery } from './chunk-6FLYVNZI.js';
2
- import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
1
+ import { buildQuery } from './chunk-PF24XU54.js';
2
+ import { BaseHttpClient } from './chunk-YTKSAWV2.js';
3
3
 
4
4
  // src/cms/client.ts
5
5
  function createReoptCmsClient(config) {
@@ -20,7 +20,7 @@ function createReoptCmsClient(config) {
20
20
  async get(postId) {
21
21
  const res = await http.fetch(
22
22
  "GET",
23
- `/posts/${postId}`
23
+ `/posts/${encodeURIComponent(postId)}`
24
24
  );
25
25
  return res.data;
26
26
  },
@@ -49,7 +49,7 @@ function createReoptCmsClient(config) {
49
49
  async get(groupId) {
50
50
  const res = await http.fetch(
51
51
  "GET",
52
- `/post-groups/${groupId}`
52
+ `/post-groups/${encodeURIComponent(groupId)}`
53
53
  );
54
54
  return res.data;
55
55
  },
@@ -77,5 +77,5 @@ function createReoptCmsClient(config) {
77
77
  }
78
78
 
79
79
  export { createReoptCmsClient };
80
- //# sourceMappingURL=chunk-WSEROZVO.js.map
81
- //# sourceMappingURL=chunk-WSEROZVO.js.map
80
+ //# sourceMappingURL=chunk-UVT2E6KD.js.map
81
+ //# sourceMappingURL=chunk-UVT2E6KD.js.map
@@ -1,4 +1,4 @@
1
- import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
1
+ import { BaseHttpClient } from './chunk-YTKSAWV2.js';
2
2
 
3
3
  // src/auth/client.ts
4
4
  function unwrap(body) {
@@ -59,5 +59,5 @@ function createReoptAuthClient(config) {
59
59
  }
60
60
 
61
61
  export { ReoptAuthClient, createReoptAuthClient };
62
- //# sourceMappingURL=chunk-PJZB4VP7.js.map
63
- //# sourceMappingURL=chunk-PJZB4VP7.js.map
62
+ //# sourceMappingURL=chunk-YPLT3RFL.js.map
63
+ //# sourceMappingURL=chunk-YPLT3RFL.js.map
@@ -1,4 +1,5 @@
1
- import { validateConfig, resolveIdBaseUrl, resolveBaseUrl, createAuthHeader, SDK_VERSION, mapHttpStatusToError, ReoptSDKError, RateLimitError, ServerError } from './chunk-J5Y2GSJF.js';
1
+ import { createAuthHeader } from './chunk-2LSCQHAU.js';
2
+ import { validateConfig, resolveIdBaseUrl, resolveBaseUrl, SDK_VERSION, mapHttpStatusToError, ReoptSDKError, RateLimitError, ServerError } from './chunk-C5VTRZWX.js';
2
3
 
3
4
  // src/core/debug.ts
4
5
  function resolveLevel(configDebug) {
@@ -271,7 +272,7 @@ var BaseHttpClient = class {
271
272
  const url = `${this.baseUrl}${path}`;
272
273
  const requestId = crypto.randomUUID();
273
274
  const timeout = options?.timeout ?? this.timeout;
274
- const methodRetryable = this.retryNonIdempotent || isIdempotentMethod(method);
275
+ const methodRetryable = this.retryNonIdempotent || isIdempotentMethod(method) || options?.idempotent === true;
275
276
  let lastError;
276
277
  this.debug.request(method, url, requestId, body);
277
278
  const startTime = Date.now();
@@ -380,6 +381,16 @@ var BaseHttpClient = class {
380
381
  lastError = error;
381
382
  canRetry = methodRetryable;
382
383
  } else if (error instanceof Error && error.name === "AbortError") {
384
+ if (externalSignal?.aborted) {
385
+ const cancelled = new ReoptSDKError(
386
+ "Request aborted by caller",
387
+ 0,
388
+ "CANCELLED",
389
+ ctx
390
+ );
391
+ cancelled.name = "AbortError";
392
+ throw cancelled;
393
+ }
383
394
  lastError = new ReoptSDKError(
384
395
  "Request timed out",
385
396
  408,
@@ -410,9 +421,12 @@ var BaseHttpClient = class {
410
421
  }
411
422
  this.debug.error(method, url, lastError?.message ?? "unknown", requestId);
412
423
  if (lastError instanceof ReoptSDKError && !lastError.context?.requestId) {
413
- Object.assign(lastError.context ?? {}, { requestId });
424
+ lastError.context = {
425
+ ...lastError.context ?? {},
426
+ requestId
427
+ };
414
428
  }
415
- throw lastError ?? new ServerError("All retry attempts failed");
429
+ throw lastError ?? new ServerError("All retry attempts failed", { requestId });
416
430
  }
417
431
  };
418
432
  function parseFieldErrors(body) {
@@ -445,5 +459,5 @@ function parseFieldErrors(body) {
445
459
  }
446
460
 
447
461
  export { BaseHttpClient, parseFieldErrors };
448
- //# sourceMappingURL=chunk-DI6QJPTQ.js.map
449
- //# sourceMappingURL=chunk-DI6QJPTQ.js.map
462
+ //# sourceMappingURL=chunk-YTKSAWV2.js.map
463
+ //# sourceMappingURL=chunk-YTKSAWV2.js.map
package/dist/cms/index.js CHANGED
@@ -1,7 +1,8 @@
1
- export { createReoptCmsClient } from '../chunk-WSEROZVO.js';
2
- import '../chunk-6FLYVNZI.js';
3
- import '../chunk-DI6QJPTQ.js';
4
- import '../chunk-J5Y2GSJF.js';
1
+ export { createReoptCmsClient } from '../chunk-UVT2E6KD.js';
2
+ import '../chunk-PF24XU54.js';
3
+ import '../chunk-YTKSAWV2.js';
4
+ import '../chunk-2LSCQHAU.js';
5
+ import '../chunk-C5VTRZWX.js';
5
6
 
6
7
  // src/cms/helpers.ts
7
8
  function joinUrl(siteUrl, path) {
@@ -13,11 +14,14 @@ function postUrl(post, opts) {
13
14
  const basePath = opts.basePath ?? "/blog";
14
15
  return joinUrl(opts.siteUrl, `${basePath}/${post.slug}`);
15
16
  }
17
+ function stripXmlInvalidChars(input) {
18
+ return input.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, "");
19
+ }
16
20
  function escapeXml(input) {
17
- return input.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
21
+ return stripXmlInvalidChars(input).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
18
22
  }
19
23
  function cdataSafe(input) {
20
- return input.replace(/]]>/g, "]]]]><![CDATA[>");
24
+ return stripXmlInvalidChars(input).replace(/]]>/g, "]]]]><![CDATA[>");
21
25
  }
22
26
  function toMetadata(post, opts) {
23
27
  const url = postUrl(post, opts);
@@ -252,6 +252,17 @@ declare class InMemoryStore {
252
252
  clear(): void;
253
253
  }
254
254
 
255
+ type MintLogoutTokenInput = {
256
+ /** The RP's OAuth client_id — becomes the logout_token `aud`. */
257
+ clientId: string;
258
+ /** The IdP session id being revoked — becomes `sid` (RP session-termination key). */
259
+ sessionId: string;
260
+ /** Optional subject (`sub`). */
261
+ userId?: string;
262
+ /** Override `iat` (epoch ms) — for testing max-age/expiry branches. */
263
+ issuedAtMs?: number;
264
+ };
265
+
255
266
  /**
256
267
  * Markdown → EditorSpec converter for dev seed workflows.
257
268
  *
@@ -501,6 +512,14 @@ type DevServer = {
501
512
  snapshot: (path: string) => Promise<void>;
502
513
  /** Restore state from a JSON file */
503
514
  restore: (path: string) => Promise<void>;
515
+ /**
516
+ * Mint a spec-compliant `logout_token` signed by the dev IdP, so you can
517
+ * exercise a `createBackchannelLogoutHandler` end-to-end against this server
518
+ * (which serves the matching JWKS at `/api/auth/jwks`). Point the SDK's logout
519
+ * verifier at `dev.url` as `idBaseUrl`. Rejects if the runtime lacks Ed25519
520
+ * Web Crypto (Node 20+).
521
+ */
522
+ mintLogoutToken: (input: MintLogoutTokenInput) => Promise<string>;
504
523
  /** Stop the dev server */
505
524
  close: () => Promise<void>;
506
525
  };
package/dist/dev/index.js CHANGED
@@ -2392,6 +2392,57 @@ function createTermsRoutes(store, brandappId) {
2392
2392
  return app;
2393
2393
  }
2394
2394
 
2395
+ // src/dev/oidc-signing.ts
2396
+ var BACKCHANNEL_LOGOUT_EVENT = "http://schemas.openid.net/event/backchannel-logout";
2397
+ function base64UrlEncode(bytes) {
2398
+ let binary = "";
2399
+ for (let i = 0; i < bytes.length; i++)
2400
+ binary += String.fromCharCode(bytes[i]);
2401
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
2402
+ }
2403
+ function encodeSegment(obj) {
2404
+ return base64UrlEncode(new TextEncoder().encode(JSON.stringify(obj)));
2405
+ }
2406
+ async function createDevOidcSigning() {
2407
+ const keyPair = await crypto.subtle.generateKey({ name: "Ed25519" }, true, [
2408
+ "sign",
2409
+ "verify"
2410
+ ]);
2411
+ const kid = "dev-ed25519";
2412
+ const jwk = await crypto.subtle.exportKey(
2413
+ "jwk",
2414
+ keyPair.publicKey
2415
+ );
2416
+ const publicJwk = { ...jwk, kid, alg: "EdDSA", use: "sig" };
2417
+ const sign = async (payload) => {
2418
+ const header = { alg: "EdDSA", typ: "JWT", kid };
2419
+ const signingInput = `${encodeSegment(header)}.${encodeSegment(payload)}`;
2420
+ const signature = new Uint8Array(
2421
+ await crypto.subtle.sign(
2422
+ { name: "Ed25519" },
2423
+ keyPair.privateKey,
2424
+ new TextEncoder().encode(signingInput)
2425
+ )
2426
+ );
2427
+ return `${signingInput}.${base64UrlEncode(signature)}`;
2428
+ };
2429
+ return { kid, publicJwk, sign };
2430
+ }
2431
+ var LOGOUT_TOKEN_TTL_SECONDS = 2 * 60;
2432
+ async function mintDevLogoutToken(signing, issuer, jti, input) {
2433
+ const nowSeconds = Math.floor((input.issuedAtMs ?? Date.now()) / 1e3);
2434
+ return signing.sign({
2435
+ iss: issuer,
2436
+ aud: input.clientId,
2437
+ iat: nowSeconds,
2438
+ exp: nowSeconds + LOGOUT_TOKEN_TTL_SECONDS,
2439
+ jti,
2440
+ events: { [BACKCHANNEL_LOGOUT_EVENT]: {} },
2441
+ sid: input.sessionId,
2442
+ ...input.userId ? { sub: input.userId } : {}
2443
+ });
2444
+ }
2445
+
2395
2446
  // src/dev/index.ts
2396
2447
  function seedSchema(store, brandappId, schema) {
2397
2448
  for (const [key, entityDef] of Object.entries(schema.entities)) {
@@ -2702,6 +2753,17 @@ async function createDevServer(options = {}) {
2702
2753
  </html>`);
2703
2754
  });
2704
2755
  app.get("/health", (c) => c.json({ ok: true, mode: "dev" }));
2756
+ let devSigning = null;
2757
+ try {
2758
+ devSigning = await createDevOidcSigning();
2759
+ } catch {
2760
+ devSigning = null;
2761
+ if (verbose) {
2762
+ console.warn(
2763
+ "[reopt-dev] Ed25519 Web Crypto unavailable \u2014 OIDC discovery omits JWKS/EdDSA/end-session (id_token stays a mock literal)."
2764
+ );
2765
+ }
2766
+ }
2705
2767
  app.get("/api/auth/.well-known/openid-configuration", (c) => {
2706
2768
  const baseUrl = `http://localhost:${actualPort}`;
2707
2769
  return c.json({
@@ -2709,26 +2771,59 @@ async function createDevServer(options = {}) {
2709
2771
  authorization_endpoint: `${baseUrl}/api/auth/authorize`,
2710
2772
  token_endpoint: `${baseUrl}/api/auth/token`,
2711
2773
  userinfo_endpoint: `${baseUrl}/api/auth/userinfo`,
2712
- jwks_uri: `${baseUrl}/api/auth/jwks`,
2713
2774
  response_types_supported: ["code"],
2714
2775
  subject_types_supported: ["public"],
2715
- id_token_signing_alg_values_supported: ["RS256"],
2716
2776
  scopes_supported: ["openid", "profile", "email"],
2717
2777
  token_endpoint_auth_methods_supported: [
2718
2778
  "client_secret_basic",
2719
2779
  "client_secret_post"
2720
2780
  ],
2721
2781
  grant_types_supported: ["authorization_code", "refresh_token"],
2722
- code_challenge_methods_supported: ["S256"]
2782
+ code_challenge_methods_supported: ["S256"],
2783
+ // Signing-backed capabilities: advertised only when the mock can actually
2784
+ // serve them (Ed25519 keypair up + JWKS/end-session routes mounted).
2785
+ ...devSigning ? {
2786
+ jwks_uri: `${baseUrl}/api/auth/jwks`,
2787
+ end_session_endpoint: `${baseUrl}/api/auth/oauth2/end-session`,
2788
+ id_token_signing_alg_values_supported: ["EdDSA"]
2789
+ } : {}
2723
2790
  });
2724
2791
  });
2792
+ app.get("/api/auth/jwks", (c) => {
2793
+ return c.json({ keys: devSigning ? [devSigning.publicJwk] : [] });
2794
+ });
2795
+ app.get("/api/auth/oauth2/end-session", (c) => {
2796
+ const redirectUri = c.req.query("post_logout_redirect_uri");
2797
+ const state = c.req.query("state");
2798
+ if (redirectUri) {
2799
+ try {
2800
+ const target = new URL(redirectUri);
2801
+ if (state) target.searchParams.set("state", state);
2802
+ return c.redirect(target.toString(), 302);
2803
+ } catch {
2804
+ return c.json({ error: "invalid_request" }, 400);
2805
+ }
2806
+ }
2807
+ return c.json({ ok: true, loggedOut: true });
2808
+ });
2725
2809
  app.post("/api/auth/token", async (c) => {
2810
+ const baseUrl = `http://localhost:${actualPort}`;
2811
+ const nowSeconds = Math.floor(Date.now() / 1e3);
2812
+ const idToken = devSigning ? await devSigning.sign({
2813
+ iss: baseUrl,
2814
+ sub: "dev-user-id",
2815
+ aud: "dev-client",
2816
+ iat: nowSeconds,
2817
+ exp: nowSeconds + 3600,
2818
+ email: "dev@example.com",
2819
+ email_verified: true
2820
+ }) : "dev-id-token";
2726
2821
  return c.json({
2727
2822
  access_token: `dev-access-token-${store.generateId()}`,
2728
2823
  token_type: "Bearer",
2729
2824
  expires_in: 3600,
2730
2825
  refresh_token: `dev-refresh-token-${store.generateId()}`,
2731
- id_token: "dev-id-token",
2826
+ id_token: idToken,
2732
2827
  scope: "openid profile email"
2733
2828
  });
2734
2829
  });
@@ -3049,6 +3144,14 @@ async function createDevServer(options = {}) {
3049
3144
  store.fromJSON(json);
3050
3145
  persistIfNeeded();
3051
3146
  },
3147
+ async mintLogoutToken(input) {
3148
+ if (!devSigning) {
3149
+ throw new Error(
3150
+ "[@reopt-ai/brandapp-sdk/dev] mintLogoutToken requires Ed25519 Web Crypto (Node 20+), which is unavailable in this runtime."
3151
+ );
3152
+ }
3153
+ return mintDevLogoutToken(devSigning, url, store.generateId(), input);
3154
+ },
3052
3155
  async close() {
3053
3156
  if (persistTimer) clearTimeout(persistTimer);
3054
3157
  if (dataPath) {
@@ -3,7 +3,7 @@ export { c as createReoptEavClient } from '../client-BkcO-0C2.js';
3
3
  import { a as AttributeFilter } from '../config-CtxyJsDR.js';
4
4
  export { b as AttributeFilterOperator, d as BulkUpdateItem, C as CountRecordsQuery, e as CreateAttributeInput, f as CreateEntityInput, g as CreateRecordInput, i as DeleteWhereInput, E as EavAttribute, j as EavAttributeOption, k as EavDataType, l as EavEntity, m as EavRecord, n as EavSchemaLinkedTo, o as EavValidation, L as ListRecordsQuery, P as PaginatedResponse, q as ReoptSDKConfig, U as UpdateAttributeInput, r as UpdateEntityInput, s as UpdateRecordInput, t as UpsertRecordInput, u as UpsertRecordResult } from '../config-CtxyJsDR.js';
5
5
  export { E as EntityClient, T as TypedEavRecord } from '../typed-client-BxOVIiMU.js';
6
- export { a as AuthUserNotFoundError, b as AuthUserRecordExistsError, D as DuplicateAuthUserError, L as LimitExceededError } from '../errors-5hd5ZR-M.js';
6
+ export { a as AuthUserNotFoundError, b as AuthUserRecordExistsError, D as DuplicateAuthUserError, L as LimitExceededError } from '../errors-BjDFIyA6.js';
7
7
 
8
8
  /**
9
9
  * Runtime drift check between a deployed bundle and the live server schema
package/dist/eav/index.js CHANGED
@@ -1,7 +1,8 @@
1
- export { createReoptEavClient } from '../chunk-E457LO5A.js';
2
- import '../chunk-6FLYVNZI.js';
3
- import '../chunk-DI6QJPTQ.js';
4
- export { AuthUserNotFoundError, AuthUserRecordExistsError, DuplicateAuthUserError, LimitExceededError } from '../chunk-J5Y2GSJF.js';
1
+ export { createReoptEavClient } from '../chunk-4U4ZPPL4.js';
2
+ import '../chunk-PF24XU54.js';
3
+ import '../chunk-YTKSAWV2.js';
4
+ import '../chunk-2LSCQHAU.js';
5
+ export { AuthUserNotFoundError, AuthUserRecordExistsError, DuplicateAuthUserError, LimitExceededError } from '../chunk-C5VTRZWX.js';
5
6
 
6
7
  // src/eav/verify.ts
7
8
  async function verifyEavSchema(input) {
@@ -31,10 +31,10 @@ declare class AuthError extends ReoptSDKError {
31
31
  constructor(message?: string, context?: ReoptSDKErrorContext);
32
32
  }
33
33
  declare class RateLimitError extends ReoptSDKError {
34
- constructor(message?: string, retryAfterMs?: number);
34
+ constructor(message?: string, retryAfterMs?: number, context?: ReoptSDKErrorContext);
35
35
  }
36
36
  declare class ServerError extends ReoptSDKError {
37
- constructor(message?: string);
37
+ constructor(message?: string, context?: ReoptSDKErrorContext);
38
38
  }
39
39
  /** AI 크레딧 잔액 부족 (HTTP 402). */
40
40
  declare class CreditLimitError extends ReoptSDKError {
@@ -89,6 +89,28 @@ declare class AuthUserNotFoundError extends ReoptSDKError {
89
89
  declare class LimitExceededError extends ReoptSDKError {
90
90
  constructor(message: string, code: "LIMIT_EXCEEDED_ENTITIES" | "LIMIT_EXCEEDED_ATTRIBUTES" | "LIMIT_EXCEEDED_RECORDS", context?: ReoptSDKErrorContext);
91
91
  }
92
+ /**
93
+ * 플랜 구독(checkout) 전에 동의해야 하는 필수 약관이 미동의 상태 (HTTP 422,
94
+ * `REQUIRED_TERMS`). `missingTermsIds`로 어떤 약관에 동의가 필요한지 알 수 있다 —
95
+ * `sdk.terms.list()` + `sdk.terms.consent()`로 동의를 수집한 뒤 checkout을 재시도한다.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * try {
100
+ * await sdk.plans.createCheckout({ planId, successUrl, cancelUrl }, token);
101
+ * } catch (e) {
102
+ * if (isRequiredTermsError(e)) {
103
+ * // e.missingTermsIds 에 해당하는 약관 동의 UI를 띄운다
104
+ * }
105
+ * }
106
+ * ```
107
+ */
108
+ declare class RequiredTermsError extends ReoptSDKError {
109
+ readonly missingTermsIds: string[];
110
+ constructor(message?: string, missingTermsIds?: string[], context?: ReoptSDKErrorContext);
111
+ }
112
+ /** Bundle-safe type guard for RequiredTermsError */
113
+ declare function isRequiredTermsError(error: unknown): error is RequiredTermsError;
92
114
  /** 필드 수준 검증 에러 */
93
115
  type FieldError = {
94
116
  /** 필드 이름 (attribute name) */
@@ -155,4 +177,4 @@ declare function isModelAccessError(error: unknown): error is ModelAccessError;
155
177
  */
156
178
  declare function mapHttpStatusToError(status: number, code: string | undefined, message: string | undefined, ctx?: ReoptSDKErrorContext, fieldErrors?: FieldError[]): ReoptSDKError;
157
179
 
158
- export { AuthError as A, BadRequestError as B, ConflictError as C, DuplicateAuthUserError as D, type ErrorDiagnostic as E, type FieldError as F, LimitExceededError as L, ModelAccessError as M, NotFoundError as N, RateLimitError as R, ServerError as S, ValidationError as V, AuthUserNotFoundError as a, AuthUserRecordExistsError as b, ContentFilterError as c, CreditLimitError as d, ForbiddenError as e, ModelNotFoundError as f, ReoptSDKError as g, type ReoptSDKErrorContext as h, isCreditLimitError as i, isModelAccessError as j, isReoptSDKError as k, isValidationError as l, mapHttpStatusToError as m };
180
+ export { AuthError as A, BadRequestError as B, ConflictError as C, DuplicateAuthUserError as D, type ErrorDiagnostic as E, type FieldError as F, LimitExceededError as L, ModelAccessError as M, NotFoundError as N, RateLimitError as R, ServerError as S, ValidationError as V, AuthUserNotFoundError as a, AuthUserRecordExistsError as b, ContentFilterError as c, CreditLimitError as d, ForbiddenError as e, ModelNotFoundError as f, ReoptSDKError as g, type ReoptSDKErrorContext as h, RequiredTermsError as i, isCreditLimitError as j, isModelAccessError as k, isReoptSDKError as l, isRequiredTermsError as m, isValidationError as n, mapHttpStatusToError as o };
@@ -1,5 +1,6 @@
1
- export { ReoptFeedbackClient, createReoptFeedbackClient } from '../chunk-K3YVJE6E.js';
2
- import '../chunk-DI6QJPTQ.js';
3
- import '../chunk-J5Y2GSJF.js';
1
+ export { ReoptFeedbackClient, createReoptFeedbackClient } from '../chunk-55KHY5GH.js';
2
+ import '../chunk-YTKSAWV2.js';
3
+ import '../chunk-2LSCQHAU.js';
4
+ import '../chunk-C5VTRZWX.js';
4
5
  //# sourceMappingURL=index.js.map
5
6
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,8 @@
1
- export { ReoptFileClient, createReoptFileClient } from '../chunk-YRGLBM6V.js';
1
+ export { ReoptFileClient, createReoptFileClient } from '../chunk-UGBBXCZE.js';
2
2
  import '../chunk-F7BXBTZI.js';
3
- import '../chunk-DI6QJPTQ.js';
4
- import '../chunk-J5Y2GSJF.js';
3
+ import '../chunk-YTKSAWV2.js';
4
+ import '../chunk-2LSCQHAU.js';
5
+ import '../chunk-C5VTRZWX.js';
5
6
 
6
7
  // src/files/helpers.ts
7
8
  var REOPT_IMAGE_REMOTE_PATTERNS = [
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import { a as ListPostsQuery, C as CmsPaginatedResponse, P as Post, c as PostDet
9
9
  import { R as ReoptAuthClient } from './client-DttyeM_h.js';
10
10
  import { ReoptAiClient } from './ai/index.js';
11
11
  export { AgentInfo, ChatMessage, CompletionOptions, CompletionResult, CreditInfo, FinishReason, ImageGenerateOptions, ImageGenerateResult, MessageRole, ModelInfo, StreamDoneData, StreamEvent } from './ai/index.js';
12
- export { A as AuthError, a as AuthUserNotFoundError, b as AuthUserRecordExistsError, B as BadRequestError, C as ConflictError, c as ContentFilterError, d as CreditLimitError, D as DuplicateAuthUserError, E as ErrorDiagnostic, F as FieldError, e as ForbiddenError, L as LimitExceededError, M as ModelAccessError, f as ModelNotFoundError, N as NotFoundError, R as RateLimitError, g as ReoptSDKError, h as ReoptSDKErrorContext, S as ServerError, V as ValidationError, i as isCreditLimitError, j as isModelAccessError, k as isReoptSDKError, l as isValidationError, m as mapHttpStatusToError } from './errors-5hd5ZR-M.js';
12
+ export { A as AuthError, a as AuthUserNotFoundError, b as AuthUserRecordExistsError, B as BadRequestError, C as ConflictError, c as ContentFilterError, d as CreditLimitError, D as DuplicateAuthUserError, E as ErrorDiagnostic, F as FieldError, e as ForbiddenError, L as LimitExceededError, M as ModelAccessError, f as ModelNotFoundError, N as NotFoundError, R as RateLimitError, g as ReoptSDKError, h as ReoptSDKErrorContext, i as RequiredTermsError, S as ServerError, V as ValidationError, j as isCreditLimitError, k as isModelAccessError, l as isReoptSDKError, m as isRequiredTermsError, n as isValidationError, o as mapHttpStatusToError } from './errors-BjDFIyA6.js';
13
13
  import { E as EntityClient } from './typed-client-BxOVIiMU.js';
14
14
  export { T as TypedEavRecord } from './typed-client-BxOVIiMU.js';
15
15
  import './types-DskYLVb8.js';
@@ -26,6 +26,15 @@ type FetchOptions = {
26
26
  * than client credentials.
27
27
  */
28
28
  bearerToken?: string;
29
+ /**
30
+ * Treat this request as idempotent for retry purposes even when the HTTP
31
+ * method is POST/PATCH. Use for read-style operations tunneled over POST
32
+ * (e.g. the Better Auth adapter's `findOne`/`findMany`/`count`) so transient
33
+ * 5xx / network / timeout failures are retried without opting the whole
34
+ * client into `retryNonIdempotent`. **Never** set this on a mutation — a
35
+ * retried write may duplicate a committed side effect.
36
+ */
37
+ idempotent?: boolean;
29
38
  };
30
39
  type BaseHttpClientOptions = {
31
40
  /**
package/dist/index.js CHANGED
@@ -1,18 +1,19 @@
1
- import { createReoptPushClient } from './chunk-6KPKZ7ZB.js';
2
- import { createReoptTermsClient } from './chunk-TUKIYH4Q.js';
3
- import { createReoptEavClient } from './chunk-E457LO5A.js';
4
- import { createReoptFeedbackClient } from './chunk-K3YVJE6E.js';
5
- import { createReoptFileClient } from './chunk-YRGLBM6V.js';
6
- import { createReoptPlansClient } from './chunk-T2WXHAAC.js';
7
- import { createReoptAiClient } from './chunk-KU2LN5SE.js';
1
+ import { createReoptPlansClient } from './chunk-OG7R3UAR.js';
2
+ import { createReoptPushClient } from './chunk-QN3QD67K.js';
3
+ import { createReoptTermsClient } from './chunk-H33OTQEN.js';
4
+ import { createReoptEavClient } from './chunk-4U4ZPPL4.js';
5
+ import { createReoptFeedbackClient } from './chunk-55KHY5GH.js';
6
+ import { createReoptFileClient } from './chunk-UGBBXCZE.js';
7
+ import { createReoptAiClient } from './chunk-FJUCWXX3.js';
8
8
  import './chunk-L4DHB36G.js';
9
9
  import './chunk-F7BXBTZI.js';
10
- import { createReoptAuthClient } from './chunk-PJZB4VP7.js';
11
- import { createReoptCmsClient } from './chunk-WSEROZVO.js';
12
- import './chunk-6FLYVNZI.js';
13
- export { BaseHttpClient } from './chunk-DI6QJPTQ.js';
14
- import { assertBrowserSafe } from './chunk-J5Y2GSJF.js';
15
- export { AuthError, AuthUserNotFoundError, AuthUserRecordExistsError, BadRequestError, ConflictError, ContentFilterError, CreditLimitError, DuplicateAuthUserError, ForbiddenError, LimitExceededError, ModelAccessError, ModelNotFoundError, NotFoundError, REOPT_BASE_URLS, RateLimitError, ReoptSDKError, ServerError, ValidationError, isCreditLimitError, isModelAccessError, isReoptSDKError, isValidationError, mapHttpStatusToError, resolveBaseUrl } from './chunk-J5Y2GSJF.js';
10
+ import { createReoptAuthClient } from './chunk-YPLT3RFL.js';
11
+ import { createReoptCmsClient } from './chunk-UVT2E6KD.js';
12
+ import './chunk-PF24XU54.js';
13
+ export { BaseHttpClient } from './chunk-YTKSAWV2.js';
14
+ import './chunk-2LSCQHAU.js';
15
+ import { assertBrowserSafe } from './chunk-C5VTRZWX.js';
16
+ export { AuthError, AuthUserNotFoundError, AuthUserRecordExistsError, BadRequestError, ConflictError, ContentFilterError, CreditLimitError, DuplicateAuthUserError, ForbiddenError, LimitExceededError, ModelAccessError, ModelNotFoundError, NotFoundError, REOPT_BASE_URLS, RateLimitError, ReoptSDKError, RequiredTermsError, ServerError, ValidationError, isCreditLimitError, isModelAccessError, isReoptSDKError, isRequiredTermsError, isValidationError, mapHttpStatusToError, resolveBaseUrl } from './chunk-C5VTRZWX.js';
16
17
 
17
18
  // src/singleton.ts
18
19
  var _instance;