@reopt-ai/brandapp-sdk 3.1.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +147 -0
- package/README.md +39 -14
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -7
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -671
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -33
- package/dist/better-auth/client.d.ts +6 -5
- package/dist/better-auth/client.js +28 -5
- package/dist/better-auth/index.d.ts +19 -17
- package/dist/better-auth/index.js +180 -133
- package/dist/client-B1q5P8rv.js +83 -0
- package/dist/client-B9QHVhdM.js +77 -0
- package/dist/client-BGGd_cpV.d.ts +103 -0
- package/dist/client-BJcy1V1a.js +140 -0
- package/dist/client-Beivhucf.js +55 -0
- package/dist/client-BruP5_nU.d.ts +147 -0
- package/dist/client-D-yNxNfk.js +28 -0
- package/dist/client-D0eBxh8j.d.ts +284 -0
- package/dist/client-D3RHHUUW.d.ts +207 -0
- package/dist/client-D6gs61w8.d.ts +53 -0
- package/dist/client-DBnK7ooQ.js +86 -0
- package/dist/client-DDw5yz_h.d.ts +53 -0
- package/dist/client-DPmoKuR9.js +305 -0
- package/dist/client-DsdakibF.js +503 -0
- package/dist/client-Dxg8_DIH.d.ts +71 -0
- package/dist/client-EbhUIhHq.js +53 -0
- package/dist/client-lk6wBu_0.d.ts +48 -0
- package/dist/client-p49ol9pg.d.ts +124 -0
- package/dist/cms/index.d.ts +52 -108
- package/dist/cms/index.js +105 -84
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-Cw0a3-C8.js +487 -0
- package/dist/dev/index.d.ts +2 -509
- package/dist/dev/index.js +2740 -2873
- package/dist/eav/coerce.d.ts +3 -1
- package/dist/eav/coerce.js +72 -46
- package/dist/eav/index.d.ts +72 -100
- package/dist/eav/index.js +158 -125
- package/dist/eav/migrate.d.ts +112 -109
- package/dist/eav/migrate.js +230 -196
- package/dist/eav/schema.d.ts +111 -150
- package/dist/eav/schema.js +624 -603
- package/dist/encoding-Bwfm3iaE.js +21 -0
- package/dist/{errors-DIAS8Rsl.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -5
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -24
- package/dist/http-client-QKUvvirs.js +386 -0
- package/dist/index-DrVaKfhs.d.ts +456 -0
- package/dist/index-Z6OGcurJ.d.ts +169 -0
- package/dist/index.d.ts +6 -221
- package/dist/index.js +119 -70
- package/dist/logout/index.d.ts +109 -0
- package/dist/logout/index.js +264 -0
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -5
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -5
- package/dist/query-BvbCiGWb.js +35 -0
- package/dist/react/hooks.d.ts +97 -95
- package/dist/react/hooks.js +742 -356
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -5
- package/dist/testing/index.d.ts +52 -104
- package/dist/testing/index.js +94 -72
- package/dist/types-B-SMkH6s.d.ts +26 -0
- package/dist/types-BXDcoJHG.d.ts +131 -0
- package/dist/types-BrghN2rJ.d.ts +105 -0
- package/dist/types-DjDRszNj.js +11 -0
- package/dist/webhooks/index.d.ts +77 -47
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +179 -2
- package/docs/dev-server.md +19 -18
- package/docs/errors.md +72 -15
- package/docs/logout.md +166 -0
- package/package.json +10 -5
- package/dist/chunk-2Q654O63.js +0 -350
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-IJOXTBIE.js +0 -599
- package/dist/chunk-JWXUVQRC.js +0 -157
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-MRQY45U5.js +0 -465
- package/dist/chunk-N5JVE4WX.js +0 -449
- package/dist/chunk-O3PUWIDJ.js +0 -105
- package/dist/chunk-POLKEOYH.js +0 -63
- package/dist/chunk-R5CCGDUH.js +0 -49
- package/dist/chunk-RBHP7IZF.js +0 -96
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-T7YTITRJ.js +0 -112
- package/dist/chunk-V73GORO3.js +0 -81
- package/dist/chunk-VRNBYSWU.js +0 -32
- package/dist/client-BkcO-0C2.d.ts +0 -216
- package/dist/client-CN5_tNOC.d.ts +0 -147
- package/dist/client-DttyeM_h.d.ts +0 -102
- package/dist/config-CtxyJsDR.d.ts +0 -397
- package/dist/typed-client-BxOVIiMU.d.ts +0 -40
- package/dist/types-6E3ZLL9X.d.ts +0 -24
- package/dist/types-DskYLVb8.d.ts +0 -104
- package/dist/types-ckmDDW3N.d.ts +0 -129
package/dist/chunk-N5JVE4WX.js
DELETED
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
import { validateConfig, resolveIdBaseUrl, resolveBaseUrl, createAuthHeader, SDK_VERSION, mapHttpStatusToError, ReoptSDKError, RateLimitError, ServerError } from './chunk-MRQY45U5.js';
|
|
2
|
-
|
|
3
|
-
// src/core/debug.ts
|
|
4
|
-
function resolveLevel(configDebug) {
|
|
5
|
-
if (configDebug === true) return "info";
|
|
6
|
-
if (configDebug === false || configDebug === void 0) ; else if (typeof configDebug === "string") {
|
|
7
|
-
return configDebug;
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
if (typeof process !== "undefined" && process.env) {
|
|
11
|
-
const v = process.env.BRANDAPP_SDK_DEBUG;
|
|
12
|
-
if (v === "trace") return "trace";
|
|
13
|
-
if (v === "info" || v === "1") return "info";
|
|
14
|
-
if (process.env.DEBUG?.includes("brandapp")) return "info";
|
|
15
|
-
}
|
|
16
|
-
} catch {
|
|
17
|
-
}
|
|
18
|
-
return "off";
|
|
19
|
-
}
|
|
20
|
-
var SAFE_QUERY_KEYS = /* @__PURE__ */ new Set([
|
|
21
|
-
"page",
|
|
22
|
-
"limit",
|
|
23
|
-
"sort",
|
|
24
|
-
"sortBy",
|
|
25
|
-
"sortOrder",
|
|
26
|
-
"order",
|
|
27
|
-
"cursor",
|
|
28
|
-
"offset"
|
|
29
|
-
]);
|
|
30
|
-
function maskUrl(url) {
|
|
31
|
-
const qIndex = url.indexOf("?");
|
|
32
|
-
if (qIndex === -1) return url;
|
|
33
|
-
const base = url.slice(0, qIndex);
|
|
34
|
-
const query = url.slice(qIndex + 1);
|
|
35
|
-
if (!query) return base;
|
|
36
|
-
const masked = query.split("&").map((pair) => {
|
|
37
|
-
const eq = pair.indexOf("=");
|
|
38
|
-
if (eq === -1) return pair;
|
|
39
|
-
const key = pair.slice(0, eq);
|
|
40
|
-
return SAFE_QUERY_KEYS.has(key) ? pair : `${key}=***`;
|
|
41
|
-
}).join("&");
|
|
42
|
-
return `${base}?${masked}`;
|
|
43
|
-
}
|
|
44
|
-
var SENSITIVE_KEYS = /(?:^authorization$)|(?:(secret|password|credential|token|apikey)$)/i;
|
|
45
|
-
function redactBody(value, depth = 0) {
|
|
46
|
-
if (value == null || depth > 4) return value;
|
|
47
|
-
if (Array.isArray(value)) {
|
|
48
|
-
return value.slice(0, 20).map((v) => redactBody(v, depth + 1));
|
|
49
|
-
}
|
|
50
|
-
if (typeof value === "object") {
|
|
51
|
-
const out = {};
|
|
52
|
-
for (const [k, v] of Object.entries(value)) {
|
|
53
|
-
out[k] = SENSITIVE_KEYS.test(k) ? "***" : redactBody(v, depth + 1);
|
|
54
|
-
}
|
|
55
|
-
return out;
|
|
56
|
-
}
|
|
57
|
-
if (typeof value === "string" && value.length > 500) {
|
|
58
|
-
return `${value.slice(0, 500)}\u2026(${value.length - 500} more chars)`;
|
|
59
|
-
}
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
function isStructuredMode() {
|
|
63
|
-
try {
|
|
64
|
-
return typeof process !== "undefined" && process.env?.BRANDAPP_SDK_LOG_FORMAT === "json";
|
|
65
|
-
} catch {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function createDebugLogger(configDebug) {
|
|
70
|
-
const level = resolveLevel(configDebug);
|
|
71
|
-
if (level === "off") {
|
|
72
|
-
return {
|
|
73
|
-
level,
|
|
74
|
-
request: () => {
|
|
75
|
-
},
|
|
76
|
-
response: () => {
|
|
77
|
-
},
|
|
78
|
-
retry: () => {
|
|
79
|
-
},
|
|
80
|
-
error: () => {
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return isStructuredMode() ? createStructuredLogger(level) : createHumanLogger(level);
|
|
85
|
-
}
|
|
86
|
-
function createHumanLogger(level) {
|
|
87
|
-
const prefix = "[brandapp-sdk]";
|
|
88
|
-
return {
|
|
89
|
-
level,
|
|
90
|
-
request(method, url, requestId, body) {
|
|
91
|
-
console.debug(
|
|
92
|
-
`${prefix} \u2192 ${method} ${maskUrl(url)} (req ${requestId.slice(0, 8)})`
|
|
93
|
-
);
|
|
94
|
-
if (level === "trace" && body !== void 0) {
|
|
95
|
-
console.debug(`${prefix} body:`, redactBody(body));
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
response(method, url, status, durationMs, requestId, body) {
|
|
99
|
-
console.debug(
|
|
100
|
-
`${prefix} \u2190 ${method} ${maskUrl(url)} ${status} (${durationMs}ms, req ${requestId.slice(
|
|
101
|
-
0,
|
|
102
|
-
8
|
|
103
|
-
)})`
|
|
104
|
-
);
|
|
105
|
-
if (level === "trace" && body !== void 0) {
|
|
106
|
-
console.debug(`${prefix} body:`, redactBody(body));
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
retry(method, url, attempt, reason) {
|
|
110
|
-
console.debug(
|
|
111
|
-
`${prefix} \u21BB ${method} ${maskUrl(url)} retry #${attempt} (${reason})`
|
|
112
|
-
);
|
|
113
|
-
},
|
|
114
|
-
error(method, url, error, requestId) {
|
|
115
|
-
console.debug(
|
|
116
|
-
`${prefix} \u2715 ${method} ${maskUrl(url)} ${error} (req ${requestId.slice(
|
|
117
|
-
0,
|
|
118
|
-
8
|
|
119
|
-
)})`
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function createStructuredLogger(level) {
|
|
125
|
-
const log = (entry) => {
|
|
126
|
-
console.debug(JSON.stringify({ sdk: "brandapp-sdk", ...entry }));
|
|
127
|
-
};
|
|
128
|
-
return {
|
|
129
|
-
level,
|
|
130
|
-
request(method, url, requestId, body) {
|
|
131
|
-
log({
|
|
132
|
-
level: "debug",
|
|
133
|
-
event: "request",
|
|
134
|
-
method,
|
|
135
|
-
url: maskUrl(url),
|
|
136
|
-
requestId,
|
|
137
|
-
...level === "trace" && body !== void 0 ? { body: redactBody(body) } : {}
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
response(method, url, status, durationMs, requestId, body) {
|
|
141
|
-
log({
|
|
142
|
-
level: "debug",
|
|
143
|
-
event: "response",
|
|
144
|
-
method,
|
|
145
|
-
url: maskUrl(url),
|
|
146
|
-
status,
|
|
147
|
-
durationMs,
|
|
148
|
-
requestId,
|
|
149
|
-
...level === "trace" && body !== void 0 ? { body: redactBody(body) } : {}
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
retry(method, url, attempt, reason) {
|
|
153
|
-
log({
|
|
154
|
-
level: "warn",
|
|
155
|
-
event: "retry",
|
|
156
|
-
method,
|
|
157
|
-
url: maskUrl(url),
|
|
158
|
-
attempt,
|
|
159
|
-
reason
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
error(method, url, error, requestId) {
|
|
163
|
-
log({
|
|
164
|
-
level: "error",
|
|
165
|
-
event: "error",
|
|
166
|
-
method,
|
|
167
|
-
url: maskUrl(url),
|
|
168
|
-
error,
|
|
169
|
-
requestId
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// src/core/http-client.ts
|
|
176
|
-
function parseRetryAfter(value) {
|
|
177
|
-
if (!value) return null;
|
|
178
|
-
const seconds = Number(value);
|
|
179
|
-
if (!Number.isNaN(seconds) && seconds >= 0) {
|
|
180
|
-
return seconds * 1e3;
|
|
181
|
-
}
|
|
182
|
-
const date = Date.parse(value);
|
|
183
|
-
if (!Number.isNaN(date)) {
|
|
184
|
-
const ms = date - Date.now();
|
|
185
|
-
return ms > 0 ? ms : 0;
|
|
186
|
-
}
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
function detectRuntime() {
|
|
190
|
-
if (typeof globalThis.EdgeRuntime === "string") return "edge";
|
|
191
|
-
if (typeof window !== "undefined") return "browser";
|
|
192
|
-
return "node";
|
|
193
|
-
}
|
|
194
|
-
var RUNTIME = detectRuntime();
|
|
195
|
-
var DEFAULT_TIMEOUT = 15e3;
|
|
196
|
-
var DEFAULT_MAX_RETRIES = 3;
|
|
197
|
-
var INITIAL_RETRY_DELAY = 1e3;
|
|
198
|
-
var MAX_RETRY_DELAY = 3e4;
|
|
199
|
-
var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE", "OPTIONS"]);
|
|
200
|
-
function isIdempotentMethod(method) {
|
|
201
|
-
return IDEMPOTENT_METHODS.has(method.toUpperCase());
|
|
202
|
-
}
|
|
203
|
-
function backoffDelay(attempt) {
|
|
204
|
-
const base = Math.min(
|
|
205
|
-
INITIAL_RETRY_DELAY * Math.pow(2, attempt),
|
|
206
|
-
MAX_RETRY_DELAY
|
|
207
|
-
);
|
|
208
|
-
return base * (0.5 + Math.random() * 0.5);
|
|
209
|
-
}
|
|
210
|
-
function abortableSleep(ms, signal) {
|
|
211
|
-
return new Promise((resolve) => {
|
|
212
|
-
if (signal?.aborted) return resolve();
|
|
213
|
-
const onAbort = () => {
|
|
214
|
-
clearTimeout(timer);
|
|
215
|
-
resolve();
|
|
216
|
-
};
|
|
217
|
-
const timer = setTimeout(() => {
|
|
218
|
-
signal?.removeEventListener("abort", onAbort);
|
|
219
|
-
resolve();
|
|
220
|
-
}, ms);
|
|
221
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
function parseErrorBody(errorBody) {
|
|
225
|
-
if (typeof errorBody?.error === "string") {
|
|
226
|
-
return {
|
|
227
|
-
code: void 0,
|
|
228
|
-
message: errorBody.error
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
return {
|
|
232
|
-
code: errorBody?.error?.code,
|
|
233
|
-
message: errorBody?.error?.message
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
var BaseHttpClient = class {
|
|
237
|
-
baseUrl;
|
|
238
|
-
authHeader;
|
|
239
|
-
timeout;
|
|
240
|
-
maxRetries;
|
|
241
|
-
retryNonIdempotent;
|
|
242
|
-
debug;
|
|
243
|
-
constructor(config, pathPrefix, options) {
|
|
244
|
-
validateConfig(config);
|
|
245
|
-
const base = options?.useIdServer ? resolveIdBaseUrl(config) : resolveBaseUrl(config);
|
|
246
|
-
this.baseUrl = base + pathPrefix;
|
|
247
|
-
this.authHeader = createAuthHeader(config);
|
|
248
|
-
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
249
|
-
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
250
|
-
this.retryNonIdempotent = config.retryNonIdempotent ?? false;
|
|
251
|
-
this.debug = createDebugLogger(config.debug ?? false);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Resolved request origin + path prefix
|
|
255
|
-
* (e.g. `https://brandapp.reopt.ai/api/v1/brandapp/{id}/ai`). Exposed so domain
|
|
256
|
-
* clients that must hand-roll `fetch` (SSE streaming, multipart upload) reuse
|
|
257
|
-
* the same resolved host instead of re-deriving it.
|
|
258
|
-
*/
|
|
259
|
-
get requestBaseUrl() {
|
|
260
|
-
return this.baseUrl;
|
|
261
|
-
}
|
|
262
|
-
/** The default `Authorization` header value (Basic or pre-minted Bearer). */
|
|
263
|
-
get authorizationHeader() {
|
|
264
|
-
return this.authHeader;
|
|
265
|
-
}
|
|
266
|
-
/** Configured request timeout in ms. */
|
|
267
|
-
get timeoutMs() {
|
|
268
|
-
return this.timeout;
|
|
269
|
-
}
|
|
270
|
-
async fetch(method, path, body, options) {
|
|
271
|
-
const url = `${this.baseUrl}${path}`;
|
|
272
|
-
const requestId = crypto.randomUUID();
|
|
273
|
-
const timeout = options?.timeout ?? this.timeout;
|
|
274
|
-
const methodRetryable = this.retryNonIdempotent || isIdempotentMethod(method);
|
|
275
|
-
let lastError;
|
|
276
|
-
this.debug.request(method, url, requestId, body);
|
|
277
|
-
const startTime = Date.now();
|
|
278
|
-
for (let attempt = 0; attempt < this.maxRetries; attempt++) {
|
|
279
|
-
const ctx = { method, url, attempt, requestId };
|
|
280
|
-
let canRetry = false;
|
|
281
|
-
const controller = new AbortController();
|
|
282
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
283
|
-
const externalSignal = options?.signal;
|
|
284
|
-
const onExternalAbort = () => controller.abort();
|
|
285
|
-
if (externalSignal) {
|
|
286
|
-
if (externalSignal.aborted) {
|
|
287
|
-
controller.abort();
|
|
288
|
-
} else {
|
|
289
|
-
externalSignal.addEventListener("abort", onExternalAbort, {
|
|
290
|
-
once: true
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
try {
|
|
295
|
-
const headers = {
|
|
296
|
-
Authorization: options?.bearerToken ? `Bearer ${options.bearerToken}` : this.authHeader,
|
|
297
|
-
"X-SDK-Version": `brandapp-sdk/${SDK_VERSION}`,
|
|
298
|
-
"X-SDK-Runtime": RUNTIME,
|
|
299
|
-
"X-Request-Id": requestId
|
|
300
|
-
};
|
|
301
|
-
if (body !== void 0) {
|
|
302
|
-
headers["Content-Type"] = "application/json";
|
|
303
|
-
}
|
|
304
|
-
if (!isIdempotentMethod(method)) {
|
|
305
|
-
headers["Idempotency-Key"] = requestId;
|
|
306
|
-
}
|
|
307
|
-
const response = await globalThis.fetch(url, {
|
|
308
|
-
method,
|
|
309
|
-
headers,
|
|
310
|
-
body: body !== void 0 ? JSON.stringify(body) : void 0,
|
|
311
|
-
signal: controller.signal
|
|
312
|
-
});
|
|
313
|
-
if (response.ok) {
|
|
314
|
-
const durationMs = Date.now() - startTime;
|
|
315
|
-
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
316
|
-
this.debug.response(
|
|
317
|
-
method,
|
|
318
|
-
url,
|
|
319
|
-
response.status,
|
|
320
|
-
durationMs,
|
|
321
|
-
requestId
|
|
322
|
-
);
|
|
323
|
-
return void 0;
|
|
324
|
-
}
|
|
325
|
-
if (this.debug.level === "trace") {
|
|
326
|
-
const parsed = await response.json();
|
|
327
|
-
this.debug.response(
|
|
328
|
-
method,
|
|
329
|
-
url,
|
|
330
|
-
response.status,
|
|
331
|
-
durationMs,
|
|
332
|
-
requestId,
|
|
333
|
-
parsed
|
|
334
|
-
);
|
|
335
|
-
return parsed;
|
|
336
|
-
}
|
|
337
|
-
this.debug.response(
|
|
338
|
-
method,
|
|
339
|
-
url,
|
|
340
|
-
response.status,
|
|
341
|
-
durationMs,
|
|
342
|
-
requestId
|
|
343
|
-
);
|
|
344
|
-
return await response.json();
|
|
345
|
-
}
|
|
346
|
-
const errorBody = await response.json().catch(() => ({}));
|
|
347
|
-
const { code: errorCode, message: errorMessage } = parseErrorBody(errorBody);
|
|
348
|
-
const fieldErrors = response.status === 422 ? parseFieldErrors(errorBody) : [];
|
|
349
|
-
const mapped = mapHttpStatusToError(
|
|
350
|
-
response.status,
|
|
351
|
-
errorCode,
|
|
352
|
-
errorMessage,
|
|
353
|
-
ctx,
|
|
354
|
-
fieldErrors
|
|
355
|
-
);
|
|
356
|
-
if (response.status === 429) {
|
|
357
|
-
lastError = mapped;
|
|
358
|
-
canRetry = true;
|
|
359
|
-
const retryAfter = parseRetryAfter(
|
|
360
|
-
response.headers.get("retry-after")
|
|
361
|
-
);
|
|
362
|
-
if (retryAfter !== null && attempt < this.maxRetries - 1) {
|
|
363
|
-
await abortableSleep(
|
|
364
|
-
Math.min(retryAfter, MAX_RETRY_DELAY),
|
|
365
|
-
externalSignal
|
|
366
|
-
);
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
} else if (response.status >= 500) {
|
|
370
|
-
lastError = mapped;
|
|
371
|
-
canRetry = methodRetryable;
|
|
372
|
-
} else {
|
|
373
|
-
throw mapped;
|
|
374
|
-
}
|
|
375
|
-
} catch (error) {
|
|
376
|
-
if (error instanceof ReoptSDKError) {
|
|
377
|
-
if (!(error instanceof RateLimitError) && !(error instanceof ServerError)) {
|
|
378
|
-
throw error;
|
|
379
|
-
}
|
|
380
|
-
lastError = error;
|
|
381
|
-
canRetry = methodRetryable;
|
|
382
|
-
} else if (error instanceof Error && error.name === "AbortError") {
|
|
383
|
-
lastError = new ReoptSDKError(
|
|
384
|
-
"Request timed out",
|
|
385
|
-
408,
|
|
386
|
-
"TIMEOUT",
|
|
387
|
-
ctx
|
|
388
|
-
);
|
|
389
|
-
canRetry = methodRetryable;
|
|
390
|
-
} else {
|
|
391
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
392
|
-
canRetry = methodRetryable;
|
|
393
|
-
}
|
|
394
|
-
} finally {
|
|
395
|
-
clearTimeout(timeoutId);
|
|
396
|
-
if (externalSignal) {
|
|
397
|
-
externalSignal.removeEventListener("abort", onExternalAbort);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
if (!canRetry) break;
|
|
401
|
-
if (attempt < this.maxRetries - 1) {
|
|
402
|
-
this.debug.retry(
|
|
403
|
-
method,
|
|
404
|
-
url,
|
|
405
|
-
attempt + 1,
|
|
406
|
-
lastError?.message ?? "unknown"
|
|
407
|
-
);
|
|
408
|
-
await abortableSleep(backoffDelay(attempt), externalSignal);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
this.debug.error(method, url, lastError?.message ?? "unknown", requestId);
|
|
412
|
-
if (lastError instanceof ReoptSDKError && !lastError.context?.requestId) {
|
|
413
|
-
Object.assign(lastError.context ?? {}, { requestId });
|
|
414
|
-
}
|
|
415
|
-
throw lastError ?? new ServerError("All retry attempts failed");
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
function parseFieldErrors(body) {
|
|
419
|
-
if (!body?.error || typeof body.error !== "object") return [];
|
|
420
|
-
const err = body.error;
|
|
421
|
-
if (Array.isArray(err.fields)) {
|
|
422
|
-
return err.fields.filter(
|
|
423
|
-
(f) => f && typeof f === "object" && "field" in f
|
|
424
|
-
).map((f) => ({
|
|
425
|
-
field: f.field,
|
|
426
|
-
message: f.message ?? "Validation failed",
|
|
427
|
-
code: f.code
|
|
428
|
-
}));
|
|
429
|
-
}
|
|
430
|
-
if (err.fields && typeof err.fields === "object" && !Array.isArray(err.fields)) {
|
|
431
|
-
return Object.entries(err.fields).map(
|
|
432
|
-
([field, message]) => ({ field, message })
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
if (Array.isArray(err.issues)) {
|
|
436
|
-
return err.issues.filter(
|
|
437
|
-
(i) => i && typeof i === "object" && "path" in i
|
|
438
|
-
).map((i) => ({
|
|
439
|
-
field: i.path?.join(".") ?? "unknown",
|
|
440
|
-
message: i.message ?? "Validation failed",
|
|
441
|
-
code: i.code
|
|
442
|
-
}));
|
|
443
|
-
}
|
|
444
|
-
return [];
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
export { BaseHttpClient, parseFieldErrors };
|
|
448
|
-
//# sourceMappingURL=chunk-N5JVE4WX.js.map
|
|
449
|
-
//# sourceMappingURL=chunk-N5JVE4WX.js.map
|
package/dist/chunk-O3PUWIDJ.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { BaseHttpClient } from './chunk-N5JVE4WX.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-O3PUWIDJ.js.map
|
|
105
|
-
//# sourceMappingURL=chunk-O3PUWIDJ.js.map
|
package/dist/chunk-POLKEOYH.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { BaseHttpClient } from './chunk-N5JVE4WX.js';
|
|
2
|
-
|
|
3
|
-
// src/auth/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 ReoptAuthClient = class {
|
|
12
|
-
/**
|
|
13
|
-
* Root client for `/api/auth/*` endpoints (OIDC userinfo, etc). Pinned to
|
|
14
|
-
* the id server because Better Auth's handler is only mounted there.
|
|
15
|
-
*/
|
|
16
|
-
rootHttp;
|
|
17
|
-
/** Brandapp-scoped client — prefixed for per-brandapp endpoints. */
|
|
18
|
-
brandappHttp;
|
|
19
|
-
constructor(config) {
|
|
20
|
-
this.rootHttp = new BaseHttpClient(config, "", { useIdServer: true });
|
|
21
|
-
this.brandappHttp = new BaseHttpClient(
|
|
22
|
-
config,
|
|
23
|
-
`/api/v1/brandapp/${config.brandappId}`
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Upsert the Customer ↔ reoptUser link for the OAuth user represented by
|
|
28
|
-
* the supplied access token.
|
|
29
|
-
*/
|
|
30
|
-
async linkCurrentUser(accessToken) {
|
|
31
|
-
const body = await this.brandappHttp.fetch("POST", "/external-auth", {}, { bearerToken: accessToken });
|
|
32
|
-
return unwrap(body);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Soft-withdraw the current OAuth user from this Brandapp: BrandappCustomer
|
|
36
|
-
* flips to `churned`, the Brand↔Customer junction is removed, all
|
|
37
|
-
* terms-consents move to `withdrawn`, and any Stripe subscription is
|
|
38
|
-
* cancelled. The Customer record itself is retained so re-linking later
|
|
39
|
-
* restores the same customerId (see `linkCurrentUser`).
|
|
40
|
-
*/
|
|
41
|
-
async withdrawCurrentUser(accessToken) {
|
|
42
|
-
const body = await this.brandappHttp.fetch("DELETE", "/external-auth", void 0, { bearerToken: accessToken });
|
|
43
|
-
return unwrap(body);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Fetch the OIDC userinfo claims for the supplied access token.
|
|
47
|
-
*/
|
|
48
|
-
async getUserInfo(accessToken) {
|
|
49
|
-
return this.rootHttp.fetch(
|
|
50
|
-
"GET",
|
|
51
|
-
"/api/auth/oauth2/userinfo",
|
|
52
|
-
void 0,
|
|
53
|
-
{ bearerToken: accessToken }
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
function createReoptAuthClient(config) {
|
|
58
|
-
return new ReoptAuthClient(config);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { ReoptAuthClient, createReoptAuthClient };
|
|
62
|
-
//# sourceMappingURL=chunk-POLKEOYH.js.map
|
|
63
|
-
//# sourceMappingURL=chunk-POLKEOYH.js.map
|
package/dist/chunk-R5CCGDUH.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { BaseHttpClient } from './chunk-N5JVE4WX.js';
|
|
2
|
-
|
|
3
|
-
// src/push/client.ts
|
|
4
|
-
var ReoptPushClient = class {
|
|
5
|
-
http;
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.http = new BaseHttpClient(
|
|
8
|
-
config,
|
|
9
|
-
`/api/v1/brandapp/${config.brandappId}/push`
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
/** Register (or refresh) the signed-in customer's device push token. */
|
|
13
|
-
async registerDeviceToken(input, accessToken) {
|
|
14
|
-
const body = await this.http.fetch(
|
|
15
|
-
"POST",
|
|
16
|
-
"/me/tokens",
|
|
17
|
-
input,
|
|
18
|
-
{ bearerToken: accessToken }
|
|
19
|
-
);
|
|
20
|
-
return body.data;
|
|
21
|
-
}
|
|
22
|
-
/** Unregister a device token by `token` or `deviceId` (own tokens only). */
|
|
23
|
-
async unregisterDeviceToken(input, accessToken) {
|
|
24
|
-
const body = await this.http.fetch(
|
|
25
|
-
"DELETE",
|
|
26
|
-
"/me/tokens",
|
|
27
|
-
input,
|
|
28
|
-
{ bearerToken: accessToken }
|
|
29
|
-
);
|
|
30
|
-
return body.data;
|
|
31
|
-
}
|
|
32
|
-
/** List the signed-in customer's registered devices (no raw tokens). */
|
|
33
|
-
async listDevices(accessToken) {
|
|
34
|
-
const body = await this.http.fetch(
|
|
35
|
-
"GET",
|
|
36
|
-
"/me/tokens",
|
|
37
|
-
void 0,
|
|
38
|
-
{ bearerToken: accessToken }
|
|
39
|
-
);
|
|
40
|
-
return body.data;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
function createReoptPushClient(config) {
|
|
44
|
-
return new ReoptPushClient(config);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { ReoptPushClient, createReoptPushClient };
|
|
48
|
-
//# sourceMappingURL=chunk-R5CCGDUH.js.map
|
|
49
|
-
//# sourceMappingURL=chunk-R5CCGDUH.js.map
|