@reopt-ai/brandapp-sdk 3.3.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 +67 -0
- package/README.md +10 -1
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -8
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -685
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -34
- 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 -144
- 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 +103 -86
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-Cw0a3-C8.js +487 -0
- package/dist/dev/index.d.ts +2 -528
- package/dist/dev/index.js +2731 -2967
- 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 -126
- 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-BjDFIyA6.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -6
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -25
- 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 -230
- package/dist/index.js +119 -71
- package/dist/logout/index.d.ts +56 -53
- package/dist/logout/index.js +232 -289
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -6
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -6
- package/dist/query-BvbCiGWb.js +35 -0
- package/dist/react/hooks.d.ts +97 -99
- package/dist/react/hooks.js +742 -404
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -6
- 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 -50
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +87 -6
- package/package.json +6 -5
- package/dist/chunk-2LSCQHAU.js +0 -21
- package/dist/chunk-4U4ZPPL4.js +0 -599
- package/dist/chunk-55KHY5GH.js +0 -96
- package/dist/chunk-C5VTRZWX.js +0 -458
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-FJUCWXX3.js +0 -350
- package/dist/chunk-H33OTQEN.js +0 -112
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-OG7R3UAR.js +0 -105
- package/dist/chunk-PF24XU54.js +0 -32
- package/dist/chunk-QN3QD67K.js +0 -49
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-UGBBXCZE.js +0 -157
- package/dist/chunk-UVT2E6KD.js +0 -81
- package/dist/chunk-YPLT3RFL.js +0 -63
- package/dist/chunk-YTKSAWV2.js +0 -463
- 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-4U4ZPPL4.js
DELETED
|
@@ -1,599 +0,0 @@
|
|
|
1
|
-
import { buildQuery } from './chunk-PF24XU54.js';
|
|
2
|
-
import { BaseHttpClient } from './chunk-YTKSAWV2.js';
|
|
3
|
-
|
|
4
|
-
// src/eav/cache.ts
|
|
5
|
-
var SchemaCache = class {
|
|
6
|
-
cache = /* @__PURE__ */ new Map();
|
|
7
|
-
ttl;
|
|
8
|
-
constructor(ttlMs = 5 * 60 * 1e3) {
|
|
9
|
-
this.ttl = ttlMs;
|
|
10
|
-
}
|
|
11
|
-
get(key) {
|
|
12
|
-
const entry = this.cache.get(key);
|
|
13
|
-
if (!entry) return void 0;
|
|
14
|
-
if (Date.now() > entry.expiresAt) {
|
|
15
|
-
this.cache.delete(key);
|
|
16
|
-
return void 0;
|
|
17
|
-
}
|
|
18
|
-
return entry.data;
|
|
19
|
-
}
|
|
20
|
-
set(key, data) {
|
|
21
|
-
this.cache.set(key, { data, expiresAt: Date.now() + this.ttl });
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Invalidate cache entries.
|
|
25
|
-
*
|
|
26
|
-
* - No argument: clears the entire cache.
|
|
27
|
-
* - String: prefix match against keys (e.g. `"entity:"` matches all
|
|
28
|
-
* per-entity caches, `"entities"` matches only the top-level list).
|
|
29
|
-
*/
|
|
30
|
-
invalidate(pattern) {
|
|
31
|
-
if (!pattern) {
|
|
32
|
-
this.cache.clear();
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
for (const key of Array.from(this.cache.keys())) {
|
|
36
|
-
if (key === pattern || key.startsWith(pattern)) this.cache.delete(key);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/eav/client.ts
|
|
42
|
-
function createReoptEavClient(config) {
|
|
43
|
-
const http = new BaseHttpClient(
|
|
44
|
-
config,
|
|
45
|
-
`/api/v1/brandapp/${config.brandappId}/eav`
|
|
46
|
-
);
|
|
47
|
-
let entityNameMap = null;
|
|
48
|
-
let entityMapPromise = null;
|
|
49
|
-
const schemaCache = new SchemaCache();
|
|
50
|
-
function invalidateEntityCaches() {
|
|
51
|
-
entityNameMap = null;
|
|
52
|
-
entityMapPromise = null;
|
|
53
|
-
schemaCache.invalidate("entities");
|
|
54
|
-
schemaCache.invalidate("entity:");
|
|
55
|
-
}
|
|
56
|
-
async function resolveEntityId(entityName) {
|
|
57
|
-
if (!entityNameMap) {
|
|
58
|
-
if (!entityMapPromise) {
|
|
59
|
-
entityMapPromise = client.entities.list().then((entities) => new Map(entities.map((e) => [e.name, e.id]))).catch((err) => {
|
|
60
|
-
entityMapPromise = null;
|
|
61
|
-
throw err;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
entityNameMap = await entityMapPromise;
|
|
65
|
-
}
|
|
66
|
-
const id = entityNameMap.get(entityName);
|
|
67
|
-
if (!id) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`ReoptSDK: Entity "${entityName}" not found on server. Run schema sync or check the entity name.`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return id;
|
|
73
|
-
}
|
|
74
|
-
const MAX_BULK = 100;
|
|
75
|
-
function assertBulkSize(count, op) {
|
|
76
|
-
if (count > MAX_BULK) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`ReoptSDK: ${op} accepts at most ${MAX_BULK} records per call (got ${count}). Split into smaller batches.`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
if (count === 0) {
|
|
82
|
-
throw new Error(`ReoptSDK: ${op} requires at least one record.`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const client = {
|
|
86
|
-
entities: {
|
|
87
|
-
async list() {
|
|
88
|
-
const cached = schemaCache.get("entities");
|
|
89
|
-
if (cached) return cached;
|
|
90
|
-
const res = await http.fetch(
|
|
91
|
-
"GET",
|
|
92
|
-
"/entities"
|
|
93
|
-
);
|
|
94
|
-
schemaCache.set("entities", res.data);
|
|
95
|
-
return res.data;
|
|
96
|
-
},
|
|
97
|
-
async create(input) {
|
|
98
|
-
const res = await http.fetch(
|
|
99
|
-
"POST",
|
|
100
|
-
"/entities",
|
|
101
|
-
input
|
|
102
|
-
);
|
|
103
|
-
invalidateEntityCaches();
|
|
104
|
-
return res.data;
|
|
105
|
-
},
|
|
106
|
-
async get(entityId) {
|
|
107
|
-
const cacheKey = `entity:${entityId}`;
|
|
108
|
-
const cached = schemaCache.get(cacheKey);
|
|
109
|
-
if (cached) return cached;
|
|
110
|
-
const res = await http.fetch("GET", `/entities/${entityId}`);
|
|
111
|
-
schemaCache.set(cacheKey, res.data);
|
|
112
|
-
return res.data;
|
|
113
|
-
},
|
|
114
|
-
async update(entityId, input) {
|
|
115
|
-
const res = await http.fetch(
|
|
116
|
-
"PUT",
|
|
117
|
-
`/entities/${entityId}`,
|
|
118
|
-
input
|
|
119
|
-
);
|
|
120
|
-
invalidateEntityCaches();
|
|
121
|
-
return res.data;
|
|
122
|
-
},
|
|
123
|
-
async delete(entityId) {
|
|
124
|
-
await http.fetch("DELETE", `/entities/${entityId}`);
|
|
125
|
-
invalidateEntityCaches();
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
attributes: {
|
|
129
|
-
async create(entityId, input) {
|
|
130
|
-
const res = await http.fetch(
|
|
131
|
-
"POST",
|
|
132
|
-
`/entities/${entityId}/attributes`,
|
|
133
|
-
input
|
|
134
|
-
);
|
|
135
|
-
schemaCache.invalidate("entity:");
|
|
136
|
-
return res.data;
|
|
137
|
-
},
|
|
138
|
-
async update(entityId, attributeId, input) {
|
|
139
|
-
const res = await http.fetch(
|
|
140
|
-
"PUT",
|
|
141
|
-
`/entities/${entityId}/attributes/${attributeId}`,
|
|
142
|
-
input
|
|
143
|
-
);
|
|
144
|
-
schemaCache.invalidate("entity:");
|
|
145
|
-
return res.data;
|
|
146
|
-
},
|
|
147
|
-
async delete(entityId, attributeId) {
|
|
148
|
-
await http.fetch(
|
|
149
|
-
"DELETE",
|
|
150
|
-
`/entities/${entityId}/attributes/${attributeId}`
|
|
151
|
-
);
|
|
152
|
-
schemaCache.invalidate("entity:");
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
records: {
|
|
156
|
-
/** List records with pagination, filtering, and sorting.
|
|
157
|
-
* @example
|
|
158
|
-
* ```ts
|
|
159
|
-
* const result = await eav.records.list(entityId, {
|
|
160
|
-
* authUserId: userId,
|
|
161
|
-
* filters: [{ attributeId: "status-attr-id", operator: "eq", value: "active" }],
|
|
162
|
-
* sortBy: "createdAt",
|
|
163
|
-
* sortOrder: "desc",
|
|
164
|
-
* page: 1,
|
|
165
|
-
* limit: 50,
|
|
166
|
-
* });
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
async list(entityId, query) {
|
|
170
|
-
const qs = buildQuery(query ?? {});
|
|
171
|
-
const res = await http.fetch(
|
|
172
|
-
"GET",
|
|
173
|
-
`/entities/${entityId}/records${qs}`
|
|
174
|
-
);
|
|
175
|
-
return res.data;
|
|
176
|
-
},
|
|
177
|
-
/** Create a new record with attribute values.
|
|
178
|
-
* @example
|
|
179
|
-
* ```ts
|
|
180
|
-
* const record = await eav.records.create(entityId, {
|
|
181
|
-
* authUserId: userId,
|
|
182
|
-
* values: { [attrs.name]: "John", [attrs.email]: "john@example.com" },
|
|
183
|
-
* });
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
async create(entityId, input) {
|
|
187
|
-
const res = await http.fetch(
|
|
188
|
-
"POST",
|
|
189
|
-
`/entities/${entityId}/records`,
|
|
190
|
-
input
|
|
191
|
-
);
|
|
192
|
-
return res.data;
|
|
193
|
-
},
|
|
194
|
-
/** Get a single record by ID.
|
|
195
|
-
* @example
|
|
196
|
-
* ```ts
|
|
197
|
-
* const record = await eav.records.get(entityId, recordId);
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
async get(entityId, recordId) {
|
|
201
|
-
const res = await http.fetch(
|
|
202
|
-
"GET",
|
|
203
|
-
`/entities/${entityId}/records/${recordId}`
|
|
204
|
-
);
|
|
205
|
-
return res.data;
|
|
206
|
-
},
|
|
207
|
-
/** Update a record's attribute values. Only specified values are changed.
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* const updated = await eav.records.update(entityId, recordId, {
|
|
211
|
-
* values: { [attrs.status]: "completed" },
|
|
212
|
-
* });
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
async update(entityId, recordId, input) {
|
|
216
|
-
const res = await http.fetch(
|
|
217
|
-
"PATCH",
|
|
218
|
-
`/entities/${entityId}/records/${recordId}`,
|
|
219
|
-
input
|
|
220
|
-
);
|
|
221
|
-
return res.data;
|
|
222
|
-
},
|
|
223
|
-
/** Delete a single record by ID. */
|
|
224
|
-
async delete(entityId, recordId) {
|
|
225
|
-
await http.fetch("DELETE", `/entities/${entityId}/records/${recordId}`);
|
|
226
|
-
},
|
|
227
|
-
/** Count records matching filters without fetching bodies.
|
|
228
|
-
* @example
|
|
229
|
-
* ```ts
|
|
230
|
-
* // Count active tasks
|
|
231
|
-
* const count = await eav.records.count(entityId, {
|
|
232
|
-
* authUserId: userId,
|
|
233
|
-
* filters: [{ attributeId: attrs.deleted_at, operator: "is_null" }],
|
|
234
|
-
* });
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
async count(entityId, query) {
|
|
238
|
-
const qs = buildQuery(query ?? {});
|
|
239
|
-
const res = await http.fetch(
|
|
240
|
-
"GET",
|
|
241
|
-
`/entities/${entityId}/records/count${qs}`
|
|
242
|
-
);
|
|
243
|
-
return res.data.total;
|
|
244
|
-
},
|
|
245
|
-
/** Delete multiple records by ID (max 100). Returns count of deleted records. */
|
|
246
|
-
async bulkDelete(entityId, ids) {
|
|
247
|
-
assertBulkSize(ids.length, "bulkDelete");
|
|
248
|
-
const res = await http.fetch(
|
|
249
|
-
"DELETE",
|
|
250
|
-
`/entities/${entityId}/records`,
|
|
251
|
-
{ ids }
|
|
252
|
-
);
|
|
253
|
-
return res.data.count;
|
|
254
|
-
},
|
|
255
|
-
/** Update multiple records in a single transaction (max 100).
|
|
256
|
-
* @example
|
|
257
|
-
* ```ts
|
|
258
|
-
* const updated = await eav.records.bulkUpdate(entityId, [
|
|
259
|
-
* { id: "record-1", values: { [attrs.is_active]: false } },
|
|
260
|
-
* { id: "record-2", values: { [attrs.is_active]: false } },
|
|
261
|
-
* ]);
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
async bulkUpdate(entityId, updates) {
|
|
265
|
-
assertBulkSize(updates.length, "bulkUpdate");
|
|
266
|
-
const res = await http.fetch(
|
|
267
|
-
"PATCH",
|
|
268
|
-
`/entities/${entityId}/records`,
|
|
269
|
-
{ updates }
|
|
270
|
-
);
|
|
271
|
-
return res.data;
|
|
272
|
-
},
|
|
273
|
-
/** Find a single record matching filters. Returns null if not found.
|
|
274
|
-
* Prefer this over list() + filter when you need exactly one record.
|
|
275
|
-
* @example
|
|
276
|
-
* ```ts
|
|
277
|
-
* // Find setting by key
|
|
278
|
-
* const record = await eav.records.findOne(entityId, {
|
|
279
|
-
* authUserId: userId,
|
|
280
|
-
* filters: [{ attributeId: attrs.key, operator: "eq", value: "theme" }],
|
|
281
|
-
* });
|
|
282
|
-
* ```
|
|
283
|
-
*/
|
|
284
|
-
async findOne(entityId, query) {
|
|
285
|
-
const res = await client.records.list(entityId, {
|
|
286
|
-
...query,
|
|
287
|
-
page: 1,
|
|
288
|
-
limit: 1
|
|
289
|
-
});
|
|
290
|
-
return res.records[0] ?? null;
|
|
291
|
-
},
|
|
292
|
-
/** Find a record by filters -- update if exists, create if not. Atomic operation.
|
|
293
|
-
* @returns `{ data: EavRecord, created: boolean }`
|
|
294
|
-
* @example
|
|
295
|
-
* ```ts
|
|
296
|
-
* // Upsert a user setting
|
|
297
|
-
* const { data, created } = await eav.records.upsert(entityId, {
|
|
298
|
-
* authUserId: userId,
|
|
299
|
-
* filters: [{ attributeId: attrs.key, operator: "eq", value: "theme" }],
|
|
300
|
-
* values: { [attrs.key]: "theme", [attrs.value]: "dark" },
|
|
301
|
-
* });
|
|
302
|
-
* ```
|
|
303
|
-
*/
|
|
304
|
-
async upsert(entityId, input) {
|
|
305
|
-
const res = await http.fetch("PUT", `/entities/${entityId}/records/upsert`, input);
|
|
306
|
-
return { data: res.data.record, created: res.data.created };
|
|
307
|
-
},
|
|
308
|
-
/** Create multiple records in a single transaction (max 100).
|
|
309
|
-
* @example
|
|
310
|
-
* ```ts
|
|
311
|
-
* const records = await eav.records.bulkCreate(entityId, [
|
|
312
|
-
* { values: { [attrs.name]: "Alice" } },
|
|
313
|
-
* { values: { [attrs.name]: "Bob" } },
|
|
314
|
-
* ]);
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
|
-
async bulkCreate(entityId, records) {
|
|
318
|
-
assertBulkSize(records.length, "bulkCreate");
|
|
319
|
-
const res = await http.fetch(
|
|
320
|
-
"POST",
|
|
321
|
-
`/entities/${entityId}/records/bulk`,
|
|
322
|
-
{ records }
|
|
323
|
-
);
|
|
324
|
-
return res.data;
|
|
325
|
-
},
|
|
326
|
-
/** Delete all records matching filters. Returns count of deleted records.
|
|
327
|
-
* @example
|
|
328
|
-
* ```ts
|
|
329
|
-
* // Delete all inactive records
|
|
330
|
-
* const count = await eav.records.deleteWhere(entityId, {
|
|
331
|
-
* authUserId: userId,
|
|
332
|
-
* filters: [{ attributeId: attrs.status, operator: "eq", value: "inactive" }],
|
|
333
|
-
* });
|
|
334
|
-
* ```
|
|
335
|
-
*/
|
|
336
|
-
async deleteWhere(entityId, input) {
|
|
337
|
-
const res = await http.fetch(
|
|
338
|
-
"POST",
|
|
339
|
-
`/entities/${entityId}/records/delete-where`,
|
|
340
|
-
input
|
|
341
|
-
);
|
|
342
|
-
return res.data.count;
|
|
343
|
-
},
|
|
344
|
-
/** Iterate all records across pages as an AsyncGenerator.
|
|
345
|
-
* @example
|
|
346
|
-
* ```ts
|
|
347
|
-
* // Stream all records
|
|
348
|
-
* for await (const record of eav.records.listAll(entityId, { authUserId: userId })) {
|
|
349
|
-
* process.stdout.write(".");
|
|
350
|
-
* }
|
|
351
|
-
*
|
|
352
|
-
* // Or collect to array
|
|
353
|
-
* import { collectAll } from "@reopt-ai/brandapp-sdk/eav";
|
|
354
|
-
* const all = await collectAll(eav.records.listAll(entityId));
|
|
355
|
-
* ```
|
|
356
|
-
*/
|
|
357
|
-
async *listAll(entityId, query) {
|
|
358
|
-
let page = 1;
|
|
359
|
-
const limit = query?.limit ?? 100;
|
|
360
|
-
while (true) {
|
|
361
|
-
const res = await client.records.list(entityId, {
|
|
362
|
-
...query,
|
|
363
|
-
page,
|
|
364
|
-
limit
|
|
365
|
-
});
|
|
366
|
-
for (const record of res.records) {
|
|
367
|
-
yield record;
|
|
368
|
-
}
|
|
369
|
-
if (page >= res.totalPages) break;
|
|
370
|
-
page++;
|
|
371
|
-
}
|
|
372
|
-
},
|
|
373
|
-
/**
|
|
374
|
-
* Backfill records by streaming through pages, calling `transform` per
|
|
375
|
-
* record, and applying `update` for each non-null result.
|
|
376
|
-
*
|
|
377
|
-
* Designed for the "expand-contract" middle step of an EAV migration —
|
|
378
|
-
* e.g. copy values from a soon-to-be-deleted attribute to a new one.
|
|
379
|
-
*
|
|
380
|
-
* @example
|
|
381
|
-
* ```ts
|
|
382
|
-
* await sdk.eav.records.backfill(entityId, {
|
|
383
|
-
* filters: [{ attributeId: levelAttrId, operator: "is_null" }],
|
|
384
|
-
* concurrency: 10,
|
|
385
|
-
* transform: (r) => ({ level: r.values.tier ?? "free" }),
|
|
386
|
-
* onProgress: ({ processed, total }) =>
|
|
387
|
-
* console.log(`${processed}/${total}`),
|
|
388
|
-
* });
|
|
389
|
-
* ```
|
|
390
|
-
*
|
|
391
|
-
* Failed updates are collected in `result.failed[]` rather than aborting
|
|
392
|
-
* the run — inspect that array after the call to retry or escalate.
|
|
393
|
-
*/
|
|
394
|
-
async backfill(entityId, opts) {
|
|
395
|
-
const concurrency = Math.max(1, opts.concurrency ?? 5);
|
|
396
|
-
const pageSize = Math.min(Math.max(1, opts.pageSize ?? 100), 100);
|
|
397
|
-
const batchSize = Math.min(
|
|
398
|
-
Math.max(1, opts.batchSize ?? MAX_BULK),
|
|
399
|
-
MAX_BULK
|
|
400
|
-
);
|
|
401
|
-
const total = await client.records.count(entityId, {
|
|
402
|
-
authUserId: opts.authUserId,
|
|
403
|
-
filters: opts.filters
|
|
404
|
-
});
|
|
405
|
-
let updated = 0;
|
|
406
|
-
let skipped = 0;
|
|
407
|
-
const failed = [];
|
|
408
|
-
let processed = 0;
|
|
409
|
-
const emit = () => {
|
|
410
|
-
opts.onProgress?.({
|
|
411
|
-
processed,
|
|
412
|
-
total,
|
|
413
|
-
updated,
|
|
414
|
-
skipped,
|
|
415
|
-
failed: failed.length
|
|
416
|
-
});
|
|
417
|
-
};
|
|
418
|
-
const applyOne = async (item) => {
|
|
419
|
-
try {
|
|
420
|
-
await client.records.update(entityId, item.id, {
|
|
421
|
-
values: item.values
|
|
422
|
-
});
|
|
423
|
-
updated++;
|
|
424
|
-
} catch (err) {
|
|
425
|
-
failed.push({
|
|
426
|
-
recordId: item.id,
|
|
427
|
-
error: err instanceof Error ? err.message : String(err)
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
const flush = async (items) => {
|
|
432
|
-
try {
|
|
433
|
-
await client.records.bulkUpdate(entityId, items);
|
|
434
|
-
updated += items.length;
|
|
435
|
-
} catch {
|
|
436
|
-
for (const item of items) await applyOne(item);
|
|
437
|
-
} finally {
|
|
438
|
-
processed += items.length;
|
|
439
|
-
emit();
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
const inFlight = /* @__PURE__ */ new Set();
|
|
443
|
-
let buffer = [];
|
|
444
|
-
const scheduleFlush = () => {
|
|
445
|
-
const items = buffer;
|
|
446
|
-
buffer = [];
|
|
447
|
-
const task = flush(items).finally(() => {
|
|
448
|
-
inFlight.delete(task);
|
|
449
|
-
});
|
|
450
|
-
inFlight.add(task);
|
|
451
|
-
};
|
|
452
|
-
for await (const record of client.records.listAll(entityId, {
|
|
453
|
-
authUserId: opts.authUserId,
|
|
454
|
-
filters: opts.filters,
|
|
455
|
-
sortBy: opts.sortBy ?? "createdAt",
|
|
456
|
-
sortOrder: opts.sortOrder ?? "asc",
|
|
457
|
-
limit: pageSize
|
|
458
|
-
})) {
|
|
459
|
-
const next = opts.transform(record);
|
|
460
|
-
if (next === null || next === void 0) {
|
|
461
|
-
skipped++;
|
|
462
|
-
processed++;
|
|
463
|
-
emit();
|
|
464
|
-
continue;
|
|
465
|
-
}
|
|
466
|
-
buffer.push({ id: record.id, values: next });
|
|
467
|
-
if (buffer.length >= batchSize) {
|
|
468
|
-
scheduleFlush();
|
|
469
|
-
if (inFlight.size >= concurrency) {
|
|
470
|
-
await Promise.race(inFlight);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
if (buffer.length > 0) scheduleFlush();
|
|
475
|
-
await Promise.all(inFlight);
|
|
476
|
-
return { total, updated, skipped, failed };
|
|
477
|
-
}
|
|
478
|
-
},
|
|
479
|
-
users: {
|
|
480
|
-
async getRecords(authUserId, query) {
|
|
481
|
-
const qs = buildQuery(query ?? {});
|
|
482
|
-
const res = await http.fetch(
|
|
483
|
-
"GET",
|
|
484
|
-
`/users/${authUserId}/records${qs}`
|
|
485
|
-
);
|
|
486
|
-
return res.data;
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
/**
|
|
490
|
-
* Fetch the server's current EAV schema fingerprint (Phase C, RFC-0005).
|
|
491
|
-
*
|
|
492
|
-
* Pair with `verifyEavSchema(localHash, client)` to detect drift between
|
|
493
|
-
* a deployed bundle and the live schema. Cacheable for ~60s — the server
|
|
494
|
-
* recomputes on every schema mutation.
|
|
495
|
-
*/
|
|
496
|
-
async schemaHash() {
|
|
497
|
-
const res = await http.fetch("GET", "/schema-hash");
|
|
498
|
-
return res.data;
|
|
499
|
-
},
|
|
500
|
-
/** Create a type-safe entity-scoped client. Resolves entity name to ID automatically.
|
|
501
|
-
* Requires `schema` in SDK config for type inference.
|
|
502
|
-
* @example
|
|
503
|
-
* ```ts
|
|
504
|
-
* const contacts = sdk.eav.entity("contacts");
|
|
505
|
-
* const record = await contacts.records.create({
|
|
506
|
-
* values: { name: "John", email: "john@example.com" }, // typed!
|
|
507
|
-
* });
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
entity(name) {
|
|
511
|
-
const entityName = config.schema ? config.schema.entities[name].name : name;
|
|
512
|
-
return {
|
|
513
|
-
entityName,
|
|
514
|
-
records: {
|
|
515
|
-
async list(query) {
|
|
516
|
-
const id = await resolveEntityId(entityName);
|
|
517
|
-
return client.records.list(id, query);
|
|
518
|
-
},
|
|
519
|
-
async findOne(query) {
|
|
520
|
-
const id = await resolveEntityId(entityName);
|
|
521
|
-
return client.records.findOne(id, query);
|
|
522
|
-
},
|
|
523
|
-
async create(input) {
|
|
524
|
-
const id = await resolveEntityId(entityName);
|
|
525
|
-
return client.records.create(
|
|
526
|
-
id,
|
|
527
|
-
input
|
|
528
|
-
);
|
|
529
|
-
},
|
|
530
|
-
async upsert(input) {
|
|
531
|
-
const id = await resolveEntityId(entityName);
|
|
532
|
-
return client.records.upsert(
|
|
533
|
-
id,
|
|
534
|
-
input
|
|
535
|
-
);
|
|
536
|
-
},
|
|
537
|
-
async get(recordId) {
|
|
538
|
-
const id = await resolveEntityId(entityName);
|
|
539
|
-
return client.records.get(id, recordId);
|
|
540
|
-
},
|
|
541
|
-
async update(recordId, input) {
|
|
542
|
-
const id = await resolveEntityId(entityName);
|
|
543
|
-
return client.records.update(
|
|
544
|
-
id,
|
|
545
|
-
recordId,
|
|
546
|
-
input
|
|
547
|
-
);
|
|
548
|
-
},
|
|
549
|
-
async delete(recordId) {
|
|
550
|
-
const id = await resolveEntityId(entityName);
|
|
551
|
-
return client.records.delete(id, recordId);
|
|
552
|
-
},
|
|
553
|
-
async count(query) {
|
|
554
|
-
const id = await resolveEntityId(entityName);
|
|
555
|
-
return client.records.count(id, query);
|
|
556
|
-
},
|
|
557
|
-
async bulkCreate(records) {
|
|
558
|
-
const id = await resolveEntityId(entityName);
|
|
559
|
-
return client.records.bulkCreate(
|
|
560
|
-
id,
|
|
561
|
-
records
|
|
562
|
-
);
|
|
563
|
-
},
|
|
564
|
-
async bulkDelete(ids) {
|
|
565
|
-
const id = await resolveEntityId(entityName);
|
|
566
|
-
return client.records.bulkDelete(id, ids);
|
|
567
|
-
},
|
|
568
|
-
async bulkUpdate(updates) {
|
|
569
|
-
const id = await resolveEntityId(entityName);
|
|
570
|
-
return client.records.bulkUpdate(id, updates);
|
|
571
|
-
},
|
|
572
|
-
async deleteWhere(input) {
|
|
573
|
-
const id = await resolveEntityId(entityName);
|
|
574
|
-
return client.records.deleteWhere(id, input);
|
|
575
|
-
},
|
|
576
|
-
async *listAll(query) {
|
|
577
|
-
const id = await resolveEntityId(entityName);
|
|
578
|
-
yield* client.records.listAll(id, query);
|
|
579
|
-
},
|
|
580
|
-
async backfill(opts) {
|
|
581
|
-
const id = await resolveEntityId(entityName);
|
|
582
|
-
return client.records.backfill(id, opts);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
},
|
|
587
|
-
/** Clear the entity name → ID cache and schema cache. Call after creating/deleting entities externally. */
|
|
588
|
-
invalidateCache() {
|
|
589
|
-
entityNameMap = null;
|
|
590
|
-
entityMapPromise = null;
|
|
591
|
-
schemaCache.invalidate();
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
return client;
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
export { createReoptEavClient };
|
|
598
|
-
//# sourceMappingURL=chunk-4U4ZPPL4.js.map
|
|
599
|
-
//# sourceMappingURL=chunk-4U4ZPPL4.js.map
|
package/dist/chunk-55KHY5GH.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { BaseHttpClient } from './chunk-YTKSAWV2.js';
|
|
2
|
-
|
|
3
|
-
// src/feedback/client.ts
|
|
4
|
-
function buildListQuery(query) {
|
|
5
|
-
const params = new URLSearchParams();
|
|
6
|
-
if (query.status) params.set("status", query.status);
|
|
7
|
-
if (query.customerId) params.set("customerId", query.customerId);
|
|
8
|
-
if (query.page != null) params.set("page", String(query.page));
|
|
9
|
-
if (query.limit != null) params.set("limit", String(query.limit));
|
|
10
|
-
const qs = params.toString();
|
|
11
|
-
return qs ? `?${qs}` : "";
|
|
12
|
-
}
|
|
13
|
-
var ReoptFeedbackClient = class {
|
|
14
|
-
http;
|
|
15
|
-
constructor(config) {
|
|
16
|
-
this.http = new BaseHttpClient(
|
|
17
|
-
config,
|
|
18
|
-
`/api/v1/brandapp/${config.brandappId}/feedback`
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Create a feedback with app credentials (server-to-server collection).
|
|
23
|
-
* Pass `customerId` to attribute it to a customer linked to this brandapp.
|
|
24
|
-
*/
|
|
25
|
-
async create(input) {
|
|
26
|
-
const body = await this.http.fetch(
|
|
27
|
-
"POST",
|
|
28
|
-
"",
|
|
29
|
-
input
|
|
30
|
-
);
|
|
31
|
-
return body.data;
|
|
32
|
-
}
|
|
33
|
-
/** List feedback this brandapp collected (app credentials). */
|
|
34
|
-
async list(query = {}) {
|
|
35
|
-
const body = await this.http.fetch(
|
|
36
|
-
"GET",
|
|
37
|
-
buildListQuery(query)
|
|
38
|
-
);
|
|
39
|
-
return { feedbacks: body.data, meta: body.meta };
|
|
40
|
-
}
|
|
41
|
-
/** Fetch one feedback with its reply thread (app credentials). */
|
|
42
|
-
async get(feedbackId) {
|
|
43
|
-
const body = await this.http.fetch(
|
|
44
|
-
"GET",
|
|
45
|
-
`/${encodeURIComponent(feedbackId)}`
|
|
46
|
-
);
|
|
47
|
-
return body.data;
|
|
48
|
-
}
|
|
49
|
-
/** End-user surface — requires the signed-in user's OAuth access token. */
|
|
50
|
-
me = {
|
|
51
|
-
/**
|
|
52
|
-
* Create a feedback as the signed-in user. The server resolves the
|
|
53
|
-
* token's linked customer; unlinked users get 403 `LINK_REQUIRED`
|
|
54
|
-
* (call `sdk.auth.linkCurrentUser` first).
|
|
55
|
-
*/
|
|
56
|
-
create: async (input, accessToken) => {
|
|
57
|
-
const body = await this.http.fetch(
|
|
58
|
-
"POST",
|
|
59
|
-
"/me",
|
|
60
|
-
input,
|
|
61
|
-
{ bearerToken: accessToken }
|
|
62
|
-
);
|
|
63
|
-
return body.data;
|
|
64
|
-
},
|
|
65
|
-
/**
|
|
66
|
-
* List the signed-in user's own feedback (all collection sources —
|
|
67
|
-
* brand form submissions included).
|
|
68
|
-
*/
|
|
69
|
-
list: async (accessToken, query = {}) => {
|
|
70
|
-
const body = await this.http.fetch(
|
|
71
|
-
"GET",
|
|
72
|
-
`/me${buildListQuery(query)}`,
|
|
73
|
-
void 0,
|
|
74
|
-
{ bearerToken: accessToken }
|
|
75
|
-
);
|
|
76
|
-
return { feedbacks: body.data, meta: body.meta };
|
|
77
|
-
},
|
|
78
|
-
/** Fetch one of the signed-in user's feedback with staff replies. */
|
|
79
|
-
get: async (feedbackId, accessToken) => {
|
|
80
|
-
const body = await this.http.fetch(
|
|
81
|
-
"GET",
|
|
82
|
-
`/me/${encodeURIComponent(feedbackId)}`,
|
|
83
|
-
void 0,
|
|
84
|
-
{ bearerToken: accessToken }
|
|
85
|
-
);
|
|
86
|
-
return body.data;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
function createReoptFeedbackClient(config) {
|
|
91
|
-
return new ReoptFeedbackClient(config);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { ReoptFeedbackClient, createReoptFeedbackClient };
|
|
95
|
-
//# sourceMappingURL=chunk-55KHY5GH.js.map
|
|
96
|
-
//# sourceMappingURL=chunk-55KHY5GH.js.map
|