@byteplus-iga-pages/agent 0.0.0-stage → 1.0.4
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/LICENSE +20 -0
- package/README.md +84 -2
- package/dist/cjs/261.js +77 -0
- package/dist/cjs/341.js +43 -0
- package/dist/cjs/401.js +3632 -0
- package/dist/cjs/419.js +854 -0
- package/dist/cjs/504.js +760 -0
- package/dist/cjs/521.js +242 -0
- package/dist/cjs/594.js +79 -0
- package/dist/cjs/647.js +1367 -0
- package/dist/cjs/808.js +322 -0
- package/dist/cjs/82.js +10089 -0
- package/dist/cjs/893.js +17720 -0
- package/dist/cjs/893.js.LICENSE.txt +13 -0
- package/dist/cjs/951.js +59 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/runtime.js +79 -0
- package/dist/cjs/sandbox/host.js +125 -0
- package/dist/cjs/sandbox/index.js +286 -0
- package/dist/cjs/store/claude.js +209 -0
- package/dist/cjs/store/host.js +92 -0
- package/dist/cjs/store/index.js +43 -0
- package/dist/cjs/store/langgraph.js +581 -0
- package/dist/cjs/store/openai.js +118 -0
- package/dist/cjs/tools/claude.js +59 -0
- package/dist/cjs/tools/index.js +37 -0
- package/dist/cjs/tools/langchain.js +52 -0
- package/dist/cjs/tools/openai-agents.js +43 -0
- package/dist/cjs/tools/openai.js +43 -0
- package/dist/esm/128.js +10381 -0
- package/dist/esm/261.js +67 -0
- package/dist/esm/341.js +30 -0
- package/dist/esm/392.js +4453 -0
- package/dist/esm/417.js +704 -0
- package/dist/esm/521.js +230 -0
- package/dist/esm/594.js +67 -0
- package/dist/esm/613.js +19042 -0
- package/dist/esm/613.js.LICENSE.txt +13 -0
- package/dist/esm/951.js +44 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/runtime.js +39 -0
- package/dist/esm/sandbox/host.js +1 -0
- package/dist/esm/sandbox/index.js +183 -0
- package/dist/esm/store/claude.js +172 -0
- package/dist/esm/store/host.js +46 -0
- package/dist/esm/store/index.js +2 -0
- package/dist/esm/store/langgraph.js +542 -0
- package/dist/esm/store/openai.js +81 -0
- package/dist/esm/tools/claude.js +22 -0
- package/dist/esm/tools/index.js +1 -0
- package/dist/esm/tools/langchain.js +16 -0
- package/dist/esm/tools/openai-agents.js +6 -0
- package/dist/esm/tools/openai.js +6 -0
- package/dist/types/_internal/data-plane/control-plane-request.d.ts +12 -0
- package/dist/types/_internal/data-plane/control-plane.d.ts +3 -0
- package/dist/types/_internal/data-plane/credential-provider.d.ts +25 -0
- package/dist/types/_internal/data-plane/errors.d.ts +19 -0
- package/dist/types/_internal/data-plane/index.d.ts +11 -0
- package/dist/types/_internal/data-plane/supabase-client.d.ts +12 -0
- package/dist/types/_internal/data-plane/token-client.d.ts +23 -0
- package/dist/types/sandbox/api-client.d.ts +37 -0
- package/dist/types/sandbox/api-types.d.ts +81 -0
- package/dist/types/sandbox/binding-repository.d.ts +62 -0
- package/dist/types/sandbox/error.d.ts +22 -0
- package/dist/types/sandbox/expiry.d.ts +11 -0
- package/dist/types/sandbox/host.d.ts +6 -0
- package/dist/types/sandbox/iga-sandbox.d.ts +208 -0
- package/dist/types/sandbox/index.d.ts +8 -0
- package/dist/types/sandbox/public-surface.d.ts +19 -0
- package/dist/types/sandbox/runtime-sandbox.d.ts +32 -0
- package/dist/types/sandbox/types.d.ts +238 -0
- package/dist/types/store/append.d.ts +41 -0
- package/dist/types/store/claude-repository.d.ts +36 -0
- package/dist/types/store/claude.d.ts +3 -0
- package/dist/types/store/control-plane-request.d.ts +2 -0
- package/dist/types/store/credential-error.d.ts +2 -0
- package/dist/types/store/credential-provider.d.ts +29 -0
- package/dist/types/store/errors.d.ts +29 -0
- package/dist/types/store/factory.d.ts +31 -0
- package/dist/types/store/host.d.ts +5 -0
- package/dist/types/store/index.d.ts +6 -0
- package/dist/types/store/json.d.ts +7 -0
- package/dist/types/store/langgraph-repository.d.ts +98 -0
- package/dist/types/store/langgraph.d.ts +43 -0
- package/dist/types/store/openai.d.ts +12 -0
- package/dist/types/store/pagination.d.ts +27 -0
- package/dist/types/store/runtime-data-plane.d.ts +8 -0
- package/dist/types/store/runtime-provider.d.ts +1 -0
- package/dist/types/store/runtime-store.d.ts +20 -0
- package/dist/types/store/store.d.ts +240 -0
- package/dist/types/store/supabase-transport.d.ts +43 -0
- package/dist/types/store/token-client.d.ts +7 -0
- package/dist/types/tools/adapters.d.ts +5 -0
- package/dist/types/tools/claude.d.ts +4 -0
- package/dist/types/tools/index.d.ts +2 -0
- package/dist/types/tools/langchain.d.ts +16 -0
- package/dist/types/tools/model-output.d.ts +8 -0
- package/dist/types/tools/openai-agents.d.ts +4 -0
- package/dist/types/tools/openai.d.ts +5 -0
- package/dist/types/tools/registry.d.ts +16 -0
- package/dist/types/tools/result.d.ts +17 -0
- package/dist/types/tools/sandbox-result-mappers.d.ts +10 -0
- package/dist/types/tools/sandbox-tools.d.ts +17 -0
- package/dist/types/tools/types.d.ts +307 -0
- package/package.json +136 -4
package/dist/cjs/504.js
ADDED
|
@@ -0,0 +1,760 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.ids = [
|
|
3
|
+
"504"
|
|
4
|
+
];
|
|
5
|
+
exports.modules = {
|
|
6
|
+
"../store/src/credential-error.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
7
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
8
|
+
y: ()=>toStoreCredentialError
|
|
9
|
+
});
|
|
10
|
+
var _iga_pages_data_plane__rspack_import_0 = __webpack_require__("../data-plane/dist/esm/index.js");
|
|
11
|
+
var _errors_js__rspack_import_1 = __webpack_require__("../store/src/errors.ts");
|
|
12
|
+
function toStoreCredentialError(error) {
|
|
13
|
+
if (error instanceof _errors_js__rspack_import_1.A) return error;
|
|
14
|
+
const source = error instanceof _iga_pages_data_plane__rspack_import_0.d ? error : void 0;
|
|
15
|
+
const codes = {
|
|
16
|
+
authentication_failed: "Unauthorized",
|
|
17
|
+
timeout: "TimeoutError",
|
|
18
|
+
aborted: "AbortError",
|
|
19
|
+
rate_limited: "TooManyRequests",
|
|
20
|
+
unavailable: "ServiceUnavailable",
|
|
21
|
+
unknown: "UnknownError"
|
|
22
|
+
};
|
|
23
|
+
let type = "unavailable";
|
|
24
|
+
if (source) {
|
|
25
|
+
if ("authentication_failed" === source.failureKind || "unauthenticated" === source.code || "permission_denied" === source.code) type = "authentication_failed";
|
|
26
|
+
else if ("timeout" === source.failureKind) type = "timeout";
|
|
27
|
+
else if ("aborted" === source.code) type = "aborted";
|
|
28
|
+
else if ("rate_limited" === source.code) type = "rate_limited";
|
|
29
|
+
else if ("unavailable" !== source.code) type = "unknown";
|
|
30
|
+
}
|
|
31
|
+
const messages = {
|
|
32
|
+
authentication_failed: "Store authentication failed",
|
|
33
|
+
timeout: "Store authentication request timed out",
|
|
34
|
+
aborted: "Store request was cancelled",
|
|
35
|
+
rate_limited: "Store authentication is receiving too many requests",
|
|
36
|
+
unavailable: "Store authentication is temporarily unavailable",
|
|
37
|
+
unknown: "Store returned invalid credentials"
|
|
38
|
+
};
|
|
39
|
+
return new _errors_js__rspack_import_1.A(codes[type], messages[type], {
|
|
40
|
+
status: source?.status,
|
|
41
|
+
error: null
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"../store/src/credential-provider.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
46
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
47
|
+
Up: ()=>StoreCredentialProviderCache,
|
|
48
|
+
q1: ()=>StoreCredentialProvider
|
|
49
|
+
});
|
|
50
|
+
var _iga_pages_data_plane__rspack_import_0 = __webpack_require__("../data-plane/dist/esm/index.js");
|
|
51
|
+
var _errors_js__rspack_import_1 = __webpack_require__("../store/src/errors.ts");
|
|
52
|
+
var _credential_error_js__rspack_import_2 = __webpack_require__("../store/src/credential-error.ts");
|
|
53
|
+
function toDataPlaneError(error) {
|
|
54
|
+
if (error instanceof _iga_pages_data_plane__rspack_import_0.d) return error;
|
|
55
|
+
if (error instanceof _errors_js__rspack_import_1.A) return new _iga_pages_data_plane__rspack_import_0.d("Unauthorized" === error.code ? "unauthenticated" : "TooManyRequests" === error.code ? "rate_limited" : "AbortError" === error.code ? "aborted" : "ServiceUnavailable" === error.code || "TimeoutError" === error.code ? "unavailable" : "internal", error.message, {
|
|
56
|
+
operation: "data-plane.authenticate",
|
|
57
|
+
status: error.status,
|
|
58
|
+
..."TimeoutError" === error.code ? {
|
|
59
|
+
failureKind: "timeout"
|
|
60
|
+
} : {}
|
|
61
|
+
});
|
|
62
|
+
return new _iga_pages_data_plane__rspack_import_0.d("unavailable", "Data plane authentication is temporarily unavailable", {
|
|
63
|
+
operation: "data-plane.authenticate",
|
|
64
|
+
retryable: true
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
class StoreCredentialProvider {
|
|
68
|
+
async getValidCredentials() {
|
|
69
|
+
try {
|
|
70
|
+
return await this.delegate.getValidCredentials();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw (0, _credential_error_js__rspack_import_2.y)(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async getProjectId() {
|
|
76
|
+
try {
|
|
77
|
+
return await this.delegate.getProjectId();
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw (0, _credential_error_js__rspack_import_2.y)(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
invalidate(jwt) {
|
|
83
|
+
this.delegate.invalidate(jwt);
|
|
84
|
+
}
|
|
85
|
+
constructor(options){
|
|
86
|
+
this.delegate = new _iga_pages_data_plane__rspack_import_0.ZQ({
|
|
87
|
+
now: options.now,
|
|
88
|
+
fetchCredentials: async ()=>{
|
|
89
|
+
try {
|
|
90
|
+
return await options.fetchCredentials();
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw toDataPlaneError(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class StoreCredentialProviderCache {
|
|
99
|
+
get(scope) {
|
|
100
|
+
if (!scope.environment || !scope.projectId) throw new _errors_js__rspack_import_1.A("ServiceUnavailable", "Store credentials are unavailable");
|
|
101
|
+
let projects = this.providers.get(scope.environment);
|
|
102
|
+
if (!projects) {
|
|
103
|
+
projects = new Map();
|
|
104
|
+
this.providers.set(scope.environment, projects);
|
|
105
|
+
}
|
|
106
|
+
let provider = projects.get(scope.projectId);
|
|
107
|
+
if (!provider) {
|
|
108
|
+
provider = this.createProvider(Object.freeze({
|
|
109
|
+
...scope
|
|
110
|
+
}));
|
|
111
|
+
projects.set(scope.projectId, provider);
|
|
112
|
+
}
|
|
113
|
+
return provider;
|
|
114
|
+
}
|
|
115
|
+
clear(scope) {
|
|
116
|
+
if (!scope) return void this.providers.clear();
|
|
117
|
+
const projects = this.providers.get(scope.environment);
|
|
118
|
+
projects?.delete(scope.projectId);
|
|
119
|
+
if (projects?.size === 0) this.providers.delete(scope.environment);
|
|
120
|
+
}
|
|
121
|
+
constructor(options){
|
|
122
|
+
this.providers = new Map();
|
|
123
|
+
this.createProvider = options.createProvider;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"../store/src/errors.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
128
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
129
|
+
A: ()=>StoreError,
|
|
130
|
+
Q: ()=>storeCodeForStatus
|
|
131
|
+
});
|
|
132
|
+
class StoreError extends Error {
|
|
133
|
+
toJSON() {
|
|
134
|
+
return {
|
|
135
|
+
code: this.code,
|
|
136
|
+
message: this.error?.message ?? this.message,
|
|
137
|
+
...void 0 !== this.status ? {
|
|
138
|
+
status: this.status
|
|
139
|
+
} : {},
|
|
140
|
+
...void 0 !== this.error ? {
|
|
141
|
+
error: this.error
|
|
142
|
+
} : {}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
constructor(code, message, options = {}){
|
|
146
|
+
super(options.error?.message ?? message);
|
|
147
|
+
this.name = "StoreError";
|
|
148
|
+
this.code = code;
|
|
149
|
+
if (null !== options.error) this.error = options.error ?? {
|
|
150
|
+
message
|
|
151
|
+
};
|
|
152
|
+
if (Number.isInteger(options.status) && options.status >= 0 && options.status <= 599) this.status = options.status;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function storeCodeForStatus(status) {
|
|
156
|
+
const codes = {
|
|
157
|
+
0: "NetworkError",
|
|
158
|
+
400: "BadRequest",
|
|
159
|
+
401: "Unauthorized",
|
|
160
|
+
402: "PaymentRequired",
|
|
161
|
+
403: "Forbidden",
|
|
162
|
+
404: "NotFound",
|
|
163
|
+
405: "MethodNotAllowed",
|
|
164
|
+
406: "NotAcceptable",
|
|
165
|
+
408: "RequestTimeout",
|
|
166
|
+
409: "Conflict",
|
|
167
|
+
410: "Gone",
|
|
168
|
+
411: "LengthRequired",
|
|
169
|
+
412: "PreconditionFailed",
|
|
170
|
+
413: "PayloadTooLarge",
|
|
171
|
+
414: "URITooLong",
|
|
172
|
+
415: "UnsupportedMediaType",
|
|
173
|
+
416: "RangeNotSatisfiable",
|
|
174
|
+
417: "ExpectationFailed",
|
|
175
|
+
418: "ImATeapot",
|
|
176
|
+
422: "UnprocessableEntity",
|
|
177
|
+
423: "Locked",
|
|
178
|
+
424: "FailedDependency",
|
|
179
|
+
425: "TooEarly",
|
|
180
|
+
426: "UpgradeRequired",
|
|
181
|
+
428: "PreconditionRequired",
|
|
182
|
+
429: "TooManyRequests",
|
|
183
|
+
431: "RequestHeaderFieldsTooLarge",
|
|
184
|
+
451: "UnavailableForLegalReasons",
|
|
185
|
+
500: "InternalServerError",
|
|
186
|
+
501: "NotImplemented",
|
|
187
|
+
502: "BadGateway",
|
|
188
|
+
503: "ServiceUnavailable",
|
|
189
|
+
504: "GatewayTimeout",
|
|
190
|
+
505: "HTTPVersionNotSupported"
|
|
191
|
+
};
|
|
192
|
+
return codes[status] ?? "UnknownError";
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"../store/src/json.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
196
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
197
|
+
P: ()=>cloneJsonObject,
|
|
198
|
+
j: ()=>cloneJsonValue
|
|
199
|
+
});
|
|
200
|
+
var _errors_js__rspack_import_0 = __webpack_require__("../store/src/errors.ts");
|
|
201
|
+
function invalidJson(field) {
|
|
202
|
+
return new _errors_js__rspack_import_0.A("BadRequest", `${field} must contain only JSON-compatible values`);
|
|
203
|
+
}
|
|
204
|
+
function cloneJsonValueInternal(value, field, ancestors) {
|
|
205
|
+
if (null === value || "string" == typeof value || "boolean" == typeof value) return value;
|
|
206
|
+
if ("number" == typeof value) {
|
|
207
|
+
if (!Number.isFinite(value)) throw invalidJson(field);
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
if (Array.isArray(value)) {
|
|
211
|
+
if (ancestors.has(value)) throw invalidJson(field);
|
|
212
|
+
ancestors.add(value);
|
|
213
|
+
const cloned = [];
|
|
214
|
+
for(let index = 0; index < value.length; index += 1){
|
|
215
|
+
if (!(index in value)) throw invalidJson(field);
|
|
216
|
+
cloned.push(cloneJsonValueInternal(value[index], field, ancestors));
|
|
217
|
+
}
|
|
218
|
+
ancestors.delete(value);
|
|
219
|
+
return cloned;
|
|
220
|
+
}
|
|
221
|
+
if ("object" == typeof value) {
|
|
222
|
+
const prototype = Object.getPrototypeOf(value);
|
|
223
|
+
if (prototype !== Object.prototype && null !== prototype) throw invalidJson(field);
|
|
224
|
+
if (ancestors.has(value)) throw invalidJson(field);
|
|
225
|
+
ancestors.add(value);
|
|
226
|
+
const cloned = {};
|
|
227
|
+
for (const [key, child] of Object.entries(value))Object.defineProperty(cloned, key, {
|
|
228
|
+
configurable: true,
|
|
229
|
+
enumerable: true,
|
|
230
|
+
writable: true,
|
|
231
|
+
value: cloneJsonValueInternal(child, field, ancestors)
|
|
232
|
+
});
|
|
233
|
+
ancestors.delete(value);
|
|
234
|
+
return cloned;
|
|
235
|
+
}
|
|
236
|
+
throw invalidJson(field);
|
|
237
|
+
}
|
|
238
|
+
function cloneJsonValue(value, field) {
|
|
239
|
+
return cloneJsonValueInternal(value, field, new WeakSet());
|
|
240
|
+
}
|
|
241
|
+
function cloneJsonObject(value, field) {
|
|
242
|
+
const cloned = cloneJsonValue(value, field);
|
|
243
|
+
if (null === cloned || Array.isArray(cloned) || "object" != typeof cloned) throw new _errors_js__rspack_import_0.A("BadRequest", `${field} must be a JSON object`);
|
|
244
|
+
return cloned;
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
"../store/src/store.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
248
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
249
|
+
y$: ()=>createStore
|
|
250
|
+
});
|
|
251
|
+
var external_node_crypto_ = __webpack_require__("node:crypto");
|
|
252
|
+
var errors = __webpack_require__("../store/src/errors.ts");
|
|
253
|
+
var json = __webpack_require__("../store/src/json.ts");
|
|
254
|
+
function materializeAppendMessages(messages, generateUuid = external_node_crypto_.randomUUID) {
|
|
255
|
+
if (!Array.isArray(messages) || messages.length < 1 || messages.length > 100) throw new errors.A("BadRequest", "appendMessages requires between 1 and 100 messages");
|
|
256
|
+
const ids = new Set();
|
|
257
|
+
return messages.map((message, index)=>{
|
|
258
|
+
if (null === message || "object" != typeof message) throw new errors.A("BadRequest", `messages[${index}] must be an object`);
|
|
259
|
+
if (void 0 !== message.role && null !== message.role && "string" != typeof message.role) throw new errors.A("BadRequest", `messages[${index}].role must be a string or null`);
|
|
260
|
+
if (void 0 !== message.type && null !== message.type && "string" != typeof message.type) throw new errors.A("BadRequest", `messages[${index}].type must be a string or null`);
|
|
261
|
+
if (void 0 !== message.messageId && "string" != typeof message.messageId) throw new errors.A("BadRequest", `messages[${index}].messageId must be a string`);
|
|
262
|
+
const messageId = message.messageId ?? generateUuid();
|
|
263
|
+
if (ids.has(messageId)) throw new errors.A("BadRequest", "appendMessages contains duplicate messageId values");
|
|
264
|
+
ids.add(messageId);
|
|
265
|
+
return Object.freeze({
|
|
266
|
+
messageId,
|
|
267
|
+
role: message.role ?? null,
|
|
268
|
+
type: message.type ?? null,
|
|
269
|
+
payload: (0, json.j)(message.payload, `messages[${index}].payload`),
|
|
270
|
+
metadata: void 0 === message.metadata ? {} : (0, json.P)(message.metadata, `messages[${index}].metadata`)
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
const DEFAULT_STORE_PAGE_LIMIT = 50;
|
|
275
|
+
const MAX_STORE_PAGE_LIMIT = 100;
|
|
276
|
+
const TIMESTAMP_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
277
|
+
function validationError() {
|
|
278
|
+
return new errors.A("BadRequest", "Store cursor is invalid");
|
|
279
|
+
}
|
|
280
|
+
function encode(value) {
|
|
281
|
+
return Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
282
|
+
}
|
|
283
|
+
function decode(value) {
|
|
284
|
+
try {
|
|
285
|
+
return JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
286
|
+
} catch {
|
|
287
|
+
throw validationError();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function isObject(value) {
|
|
291
|
+
return null !== value && "object" == typeof value && !Array.isArray(value);
|
|
292
|
+
}
|
|
293
|
+
function isTimestamp(value) {
|
|
294
|
+
return "string" == typeof value && TIMESTAMP_PATTERN.test(value) && Number.isFinite(Date.parse(value));
|
|
295
|
+
}
|
|
296
|
+
function isConversationId(value) {
|
|
297
|
+
return "string" == typeof value && value.length > 0 && Buffer.byteLength(value, "utf8") <= 256;
|
|
298
|
+
}
|
|
299
|
+
function isSequence(value) {
|
|
300
|
+
return "string" == typeof value && /^(0|[1-9]\d*)$/.test(value);
|
|
301
|
+
}
|
|
302
|
+
function normalizeStorePageLimit(limit) {
|
|
303
|
+
if (void 0 === limit) return DEFAULT_STORE_PAGE_LIMIT;
|
|
304
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > MAX_STORE_PAGE_LIMIT) throw new errors.A("BadRequest", `Store page limit must be an integer from 1 to ${MAX_STORE_PAGE_LIMIT}`);
|
|
305
|
+
return limit;
|
|
306
|
+
}
|
|
307
|
+
function encodeConversationCursor(cursor) {
|
|
308
|
+
return encode({
|
|
309
|
+
version: 1,
|
|
310
|
+
kind: "conversations",
|
|
311
|
+
...cursor
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
function decodeConversationCursor(value) {
|
|
315
|
+
const cursor = decode(value);
|
|
316
|
+
if (!isObject(cursor) || 1 !== cursor.version || "conversations" !== cursor.kind || !isTimestamp(cursor.updatedAt) || !isConversationId(cursor.conversationId)) throw validationError();
|
|
317
|
+
return {
|
|
318
|
+
updatedAt: cursor.updatedAt,
|
|
319
|
+
conversationId: cursor.conversationId
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function encodeMessageCursor(cursor) {
|
|
323
|
+
return encode({
|
|
324
|
+
version: 1,
|
|
325
|
+
kind: "messages",
|
|
326
|
+
...cursor
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function decodeMessageCursor(value, expected) {
|
|
330
|
+
const cursor = decode(value);
|
|
331
|
+
if (!isObject(cursor) || 1 !== cursor.version || "messages" !== cursor.kind || !isConversationId(cursor.conversationId) || cursor.conversationId !== expected.conversationId || cursor.order !== expected.order || !isSequence(cursor.snapshotSeq) || !isSequence(cursor.lastSeq)) throw validationError();
|
|
332
|
+
return {
|
|
333
|
+
conversationId: cursor.conversationId,
|
|
334
|
+
order: expected.order,
|
|
335
|
+
snapshotSeq: cursor.snapshotSeq,
|
|
336
|
+
lastSeq: cursor.lastSeq
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
const SEQUENCE_PATTERN = /^(0|[1-9]\d*)$/;
|
|
340
|
+
const CONVERSATION_COLUMNS = "conversation_id,metadata,created_at,updated_at";
|
|
341
|
+
const MESSAGE_COLUMNS = "event_id,conversation_id,seq_text,role,event_type,payload,metadata,created_at,updated_at";
|
|
342
|
+
const DEFAULT_STORE_RPC_NAMES = Object.freeze({
|
|
343
|
+
appendMessages: "append_messages",
|
|
344
|
+
updateConversation: "update_conversation",
|
|
345
|
+
deleteConversation: "delete_conversation",
|
|
346
|
+
deleteMessage: "delete_event",
|
|
347
|
+
clearMessages: "clear_messages"
|
|
348
|
+
});
|
|
349
|
+
function invalid(message) {
|
|
350
|
+
throw new errors.A("BadRequest", message);
|
|
351
|
+
}
|
|
352
|
+
function internal() {
|
|
353
|
+
throw new errors.A("UnknownError", "Store returned invalid data");
|
|
354
|
+
}
|
|
355
|
+
function requireObject(value, field) {
|
|
356
|
+
if (null === value || "object" != typeof value || Array.isArray(value)) invalid(`${field} must be an object`);
|
|
357
|
+
return value;
|
|
358
|
+
}
|
|
359
|
+
function requireConversationId(value) {
|
|
360
|
+
if ("string" != typeof value || 0 === value.length) invalid("conversationId must be a non-empty string");
|
|
361
|
+
if (Buffer.byteLength(value, "utf8") > 256) invalid("conversationId must not exceed 256 UTF-8 bytes");
|
|
362
|
+
return value;
|
|
363
|
+
}
|
|
364
|
+
function requireMessageId(value) {
|
|
365
|
+
if ("string" != typeof value || "" === value) invalid("messageId must be a non-empty string");
|
|
366
|
+
return value;
|
|
367
|
+
}
|
|
368
|
+
function requireTimestamp(value) {
|
|
369
|
+
if ("string" != typeof value || "" === value || !Number.isFinite(Date.parse(value))) internal();
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
function requireNextSequence(value) {
|
|
373
|
+
if ("string" == typeof value && SEQUENCE_PATTERN.test(value)) return value;
|
|
374
|
+
if ("number" == typeof value && Number.isSafeInteger(value) && value >= 0) return String(value);
|
|
375
|
+
internal();
|
|
376
|
+
}
|
|
377
|
+
function mapConversation(value) {
|
|
378
|
+
const row = requireStoreRow(value);
|
|
379
|
+
if ("string" != typeof row.conversation_id) internal();
|
|
380
|
+
return {
|
|
381
|
+
conversationId: row.conversation_id,
|
|
382
|
+
metadata: readStoreJsonObject(row.metadata),
|
|
383
|
+
createdAt: requireTimestamp(row.created_at),
|
|
384
|
+
updatedAt: requireTimestamp(row.updated_at)
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function mapMessage(value) {
|
|
388
|
+
const row = requireStoreRow(value);
|
|
389
|
+
if ("string" != typeof row.event_id || "string" != typeof row.conversation_id || "string" != typeof row.seq_text || !SEQUENCE_PATTERN.test(row.seq_text) || null !== row.role && "string" != typeof row.role || null !== row.event_type && "string" != typeof row.event_type) internal();
|
|
390
|
+
return {
|
|
391
|
+
messageId: row.event_id,
|
|
392
|
+
conversationId: row.conversation_id,
|
|
393
|
+
seq: row.seq_text,
|
|
394
|
+
role: row.role,
|
|
395
|
+
type: row.event_type,
|
|
396
|
+
payload: readStoreJsonValue(row.payload),
|
|
397
|
+
metadata: readStoreJsonObject(row.metadata),
|
|
398
|
+
createdAt: requireTimestamp(row.created_at),
|
|
399
|
+
updatedAt: requireTimestamp(row.updated_at)
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function requireStoreRow(value) {
|
|
403
|
+
if (null === value || "object" != typeof value || Array.isArray(value)) internal();
|
|
404
|
+
return value;
|
|
405
|
+
}
|
|
406
|
+
function readStoreJsonValue(value) {
|
|
407
|
+
try {
|
|
408
|
+
return (0, json.j)(value, "Store data");
|
|
409
|
+
} catch {
|
|
410
|
+
internal();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function readStoreJsonObject(value) {
|
|
414
|
+
try {
|
|
415
|
+
return (0, json.P)(value, "Store data");
|
|
416
|
+
} catch {
|
|
417
|
+
internal();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function requireRows(value) {
|
|
421
|
+
if (!Array.isArray(value)) internal();
|
|
422
|
+
return value;
|
|
423
|
+
}
|
|
424
|
+
class SupabaseStore {
|
|
425
|
+
async createConversation(input = {}) {
|
|
426
|
+
const value = requireObject(input, "createConversation input");
|
|
427
|
+
const conversationId = void 0 === value.conversationId ? requireConversationId(this.generateUuid()) : requireConversationId(value.conversationId);
|
|
428
|
+
const metadata = void 0 === value.metadata ? {} : (0, json.P)(value.metadata, "metadata");
|
|
429
|
+
const data = await this.execute((client)=>client.from("conversations").insert({
|
|
430
|
+
project_id: this.projectId,
|
|
431
|
+
conversation_id: conversationId,
|
|
432
|
+
metadata
|
|
433
|
+
}).select(CONVERSATION_COLUMNS).single(), {
|
|
434
|
+
operation: "store.createConversation",
|
|
435
|
+
retryNetwork: false
|
|
436
|
+
});
|
|
437
|
+
return mapConversation(data);
|
|
438
|
+
}
|
|
439
|
+
async getConversation(input) {
|
|
440
|
+
const value = requireObject(input, "getConversation input");
|
|
441
|
+
const conversationId = requireConversationId(value.conversationId);
|
|
442
|
+
const data = await this.execute((client)=>client.from("conversations").select(CONVERSATION_COLUMNS).eq("project_id", this.projectId).eq("conversation_id", conversationId).maybeSingle(), {
|
|
443
|
+
operation: "store.getConversation",
|
|
444
|
+
retryNetwork: true
|
|
445
|
+
});
|
|
446
|
+
return null === data ? null : mapConversation(data);
|
|
447
|
+
}
|
|
448
|
+
async listConversations(input = {}) {
|
|
449
|
+
const value = requireObject(input, "listConversations input");
|
|
450
|
+
const limit = normalizeStorePageLimit(value.limit);
|
|
451
|
+
const cursor = void 0 === value.cursor ? void 0 : "string" == typeof value.cursor ? decodeConversationCursor(value.cursor) : invalid("cursor must be a string");
|
|
452
|
+
const data = await this.execute((client)=>{
|
|
453
|
+
let query = client.from("conversations").select(CONVERSATION_COLUMNS).eq("project_id", this.projectId).order("updated_at", {
|
|
454
|
+
ascending: false
|
|
455
|
+
}).order("conversation_id", {
|
|
456
|
+
ascending: false
|
|
457
|
+
}).limit(limit + 1);
|
|
458
|
+
if (cursor) {
|
|
459
|
+
const quotedId = `"${cursor.conversationId.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
460
|
+
query = query.or(`updated_at.lt.${cursor.updatedAt},and(updated_at.eq.${cursor.updatedAt},conversation_id.lt.${quotedId})`);
|
|
461
|
+
}
|
|
462
|
+
return query;
|
|
463
|
+
}, {
|
|
464
|
+
operation: "store.listConversations",
|
|
465
|
+
retryNetwork: true
|
|
466
|
+
});
|
|
467
|
+
const rows = requireRows(data);
|
|
468
|
+
const hasMore = rows.length > limit;
|
|
469
|
+
const items = rows.slice(0, limit).map(mapConversation);
|
|
470
|
+
const last = items.at(-1);
|
|
471
|
+
return {
|
|
472
|
+
items,
|
|
473
|
+
nextCursor: hasMore && last ? encodeConversationCursor({
|
|
474
|
+
updatedAt: last.updatedAt,
|
|
475
|
+
conversationId: last.conversationId
|
|
476
|
+
}) : null
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
async updateConversation(input) {
|
|
480
|
+
const value = requireObject(input, "updateConversation input");
|
|
481
|
+
const conversationId = requireConversationId(value.conversationId);
|
|
482
|
+
if (!("metadata" in value)) invalid("metadata is required");
|
|
483
|
+
const metadata = (0, json.P)(value.metadata, "metadata");
|
|
484
|
+
const removalKeys = [];
|
|
485
|
+
for (const [key, item] of Object.entries(metadata))if (null === item) {
|
|
486
|
+
removalKeys.push(key);
|
|
487
|
+
delete metadata[key];
|
|
488
|
+
}
|
|
489
|
+
const data = await this.execute((client)=>client.rpc(this.rpcNames.updateConversation, {
|
|
490
|
+
p_project_id: this.projectId,
|
|
491
|
+
p_conversation_id: conversationId,
|
|
492
|
+
p_metadata: metadata,
|
|
493
|
+
p_remove_metadata_keys: removalKeys
|
|
494
|
+
}).maybeSingle(), {
|
|
495
|
+
operation: "store.updateConversation",
|
|
496
|
+
retryNetwork: false
|
|
497
|
+
});
|
|
498
|
+
if (null === data) throw new errors.A("NotFound", "Conversation was not found");
|
|
499
|
+
return mapConversation(data);
|
|
500
|
+
}
|
|
501
|
+
async deleteConversation(input) {
|
|
502
|
+
const value = requireObject(input, "deleteConversation input");
|
|
503
|
+
const conversationId = requireConversationId(value.conversationId);
|
|
504
|
+
await this.execute((client)=>client.rpc(this.rpcNames.deleteConversation, {
|
|
505
|
+
p_project_id: this.projectId,
|
|
506
|
+
p_conversation_id: conversationId
|
|
507
|
+
}), {
|
|
508
|
+
operation: "store.deleteConversation",
|
|
509
|
+
retryNetwork: true
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
async appendMessage(input) {
|
|
513
|
+
const value = requireObject(input, "appendMessage input");
|
|
514
|
+
const { conversationId, ...message } = value;
|
|
515
|
+
const [result] = await this.appendMessages({
|
|
516
|
+
conversationId: conversationId,
|
|
517
|
+
messages: [
|
|
518
|
+
message
|
|
519
|
+
]
|
|
520
|
+
});
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
523
|
+
async appendMessages(input) {
|
|
524
|
+
const value = requireObject(input, "appendMessages input");
|
|
525
|
+
const conversationId = requireConversationId(value.conversationId);
|
|
526
|
+
const materialized = materializeAppendMessages(value.messages, this.generateUuid);
|
|
527
|
+
const rpcMessages = materialized.map((message)=>({
|
|
528
|
+
message_id: message.messageId,
|
|
529
|
+
role: message.role,
|
|
530
|
+
event_type: message.type,
|
|
531
|
+
payload: message.payload,
|
|
532
|
+
metadata: message.metadata
|
|
533
|
+
}));
|
|
534
|
+
const data = await this.execute((client)=>client.rpc(this.rpcNames.appendMessages, {
|
|
535
|
+
p_project_id: this.projectId,
|
|
536
|
+
p_conversation_id: conversationId,
|
|
537
|
+
p_messages: rpcMessages
|
|
538
|
+
}), {
|
|
539
|
+
operation: "store.appendMessages",
|
|
540
|
+
retryNetwork: true
|
|
541
|
+
});
|
|
542
|
+
const byId = new Map(requireRows(data).map((row)=>{
|
|
543
|
+
const message = mapMessage(row);
|
|
544
|
+
return [
|
|
545
|
+
message.messageId,
|
|
546
|
+
message
|
|
547
|
+
];
|
|
548
|
+
}));
|
|
549
|
+
if (byId.size !== materialized.length) internal();
|
|
550
|
+
return materialized.map((inputMessage)=>{
|
|
551
|
+
const message = byId.get(inputMessage.messageId);
|
|
552
|
+
if (!message || message.conversationId !== conversationId) internal();
|
|
553
|
+
return message;
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
async getMessage(input) {
|
|
557
|
+
const value = requireObject(input, "getMessage input");
|
|
558
|
+
const messageId = requireMessageId(value.messageId);
|
|
559
|
+
const data = await this.execute((client)=>client.from("events").select(MESSAGE_COLUMNS).eq("project_id", this.projectId).eq("event_id", messageId).maybeSingle(), {
|
|
560
|
+
operation: "store.getMessage",
|
|
561
|
+
retryNetwork: true
|
|
562
|
+
});
|
|
563
|
+
return null === data ? null : mapMessage(data);
|
|
564
|
+
}
|
|
565
|
+
async listMessages(input) {
|
|
566
|
+
const value = requireObject(input, "listMessages input");
|
|
567
|
+
const conversationId = requireConversationId(value.conversationId);
|
|
568
|
+
const limit = normalizeStorePageLimit(value.limit);
|
|
569
|
+
const order = value.order ?? "asc";
|
|
570
|
+
if ("asc" !== order && "desc" !== order) invalid('order must be "asc" or "desc"');
|
|
571
|
+
const cursor = void 0 === value.cursor ? void 0 : "string" == typeof value.cursor ? decodeMessageCursor(value.cursor, {
|
|
572
|
+
conversationId,
|
|
573
|
+
order
|
|
574
|
+
}) : invalid("cursor must be a string");
|
|
575
|
+
const snapshotSeq = cursor?.snapshotSeq ?? await this.readSnapshotSeq(conversationId);
|
|
576
|
+
if (null === snapshotSeq) return {
|
|
577
|
+
items: [],
|
|
578
|
+
nextCursor: null
|
|
579
|
+
};
|
|
580
|
+
const data = await this.execute((client)=>{
|
|
581
|
+
let query = client.from("events").select(MESSAGE_COLUMNS).eq("project_id", this.projectId).eq("conversation_id", conversationId).lte("seq", snapshotSeq).order("seq", {
|
|
582
|
+
ascending: "asc" === order
|
|
583
|
+
}).limit(limit + 1);
|
|
584
|
+
if (cursor) query = "asc" === order ? query.gt("seq", cursor.lastSeq) : query.lt("seq", cursor.lastSeq);
|
|
585
|
+
return query;
|
|
586
|
+
}, {
|
|
587
|
+
operation: "store.listMessages",
|
|
588
|
+
retryNetwork: true
|
|
589
|
+
});
|
|
590
|
+
const rows = requireRows(data);
|
|
591
|
+
const hasMore = rows.length > limit;
|
|
592
|
+
const items = rows.slice(0, limit).map(mapMessage);
|
|
593
|
+
const last = items.at(-1);
|
|
594
|
+
return {
|
|
595
|
+
items,
|
|
596
|
+
nextCursor: hasMore && last ? encodeMessageCursor({
|
|
597
|
+
conversationId,
|
|
598
|
+
order,
|
|
599
|
+
snapshotSeq,
|
|
600
|
+
lastSeq: last.seq
|
|
601
|
+
}) : null
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
async updateMessage(input) {
|
|
605
|
+
const value = requireObject(input, "updateMessage input");
|
|
606
|
+
const messageId = requireMessageId(value.messageId);
|
|
607
|
+
const update = {};
|
|
608
|
+
if ("role" in value) {
|
|
609
|
+
if (null !== value.role && "string" != typeof value.role) invalid("role must be a string or null");
|
|
610
|
+
update.role = value.role;
|
|
611
|
+
}
|
|
612
|
+
if ("type" in value) {
|
|
613
|
+
if (null !== value.type && "string" != typeof value.type) invalid("type must be a string or null");
|
|
614
|
+
update.event_type = value.type;
|
|
615
|
+
}
|
|
616
|
+
if ("payload" in value) update.payload = (0, json.j)(value.payload, "payload");
|
|
617
|
+
if ("metadata" in value) update.metadata = (0, json.P)(value.metadata, "metadata");
|
|
618
|
+
if (0 === Object.keys(update).length) invalid("updateMessage requires at least one mutable field");
|
|
619
|
+
const data = await this.execute((client)=>client.from("events").update(update).eq("project_id", this.projectId).eq("event_id", messageId).select(MESSAGE_COLUMNS).maybeSingle(), {
|
|
620
|
+
operation: "store.updateMessage",
|
|
621
|
+
retryNetwork: false
|
|
622
|
+
});
|
|
623
|
+
if (null === data) throw new errors.A("NotFound", "Message was not found");
|
|
624
|
+
return mapMessage(data);
|
|
625
|
+
}
|
|
626
|
+
async deleteMessage(input) {
|
|
627
|
+
const value = requireObject(input, "deleteMessage input");
|
|
628
|
+
const messageId = requireMessageId(value.messageId);
|
|
629
|
+
await this.execute((client)=>client.rpc(this.rpcNames.deleteMessage, {
|
|
630
|
+
p_project_id: this.projectId,
|
|
631
|
+
p_event_id: messageId
|
|
632
|
+
}), {
|
|
633
|
+
operation: "store.deleteMessage",
|
|
634
|
+
retryNetwork: true
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
async clearMessages(input) {
|
|
638
|
+
const value = requireObject(input, "clearMessages input");
|
|
639
|
+
const conversationId = requireConversationId(value.conversationId);
|
|
640
|
+
await this.execute((client)=>client.rpc(this.rpcNames.clearMessages, {
|
|
641
|
+
p_project_id: this.projectId,
|
|
642
|
+
p_conversation_id: conversationId
|
|
643
|
+
}), {
|
|
644
|
+
operation: "store.clearMessages",
|
|
645
|
+
retryNetwork: true
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
async readSnapshotSeq(conversationId) {
|
|
649
|
+
const data = await this.execute((client)=>client.from("conversations").select("next_seq").eq("project_id", this.projectId).eq("conversation_id", conversationId).maybeSingle(), {
|
|
650
|
+
operation: "store.listMessages",
|
|
651
|
+
retryNetwork: true
|
|
652
|
+
});
|
|
653
|
+
if (null === data) return null;
|
|
654
|
+
const row = requireStoreRow(data);
|
|
655
|
+
const next = BigInt(requireNextSequence(row.next_seq));
|
|
656
|
+
return next > 0n ? String(next - 1n) : "0";
|
|
657
|
+
}
|
|
658
|
+
async execute(operation, options) {
|
|
659
|
+
const result = await this.transport.execute({
|
|
660
|
+
operationName: options.operation,
|
|
661
|
+
retryOnUnauthorized: true,
|
|
662
|
+
retryOnNetworkError: options.retryNetwork,
|
|
663
|
+
operation
|
|
664
|
+
});
|
|
665
|
+
return result.data;
|
|
666
|
+
}
|
|
667
|
+
constructor(options){
|
|
668
|
+
if (!options.projectId) throw new errors.A("UnknownError", "Store project scope is missing");
|
|
669
|
+
this.projectId = options.projectId;
|
|
670
|
+
this.transport = options.transport;
|
|
671
|
+
this.generateUuid = options.generateUuid ?? external_node_crypto_.randomUUID;
|
|
672
|
+
this.rpcNames = {
|
|
673
|
+
...DEFAULT_STORE_RPC_NAMES,
|
|
674
|
+
...options.rpcNames
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function createStore(options) {
|
|
679
|
+
return new SupabaseStore(options);
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
"../store/src/supabase-transport.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
683
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
684
|
+
H: ()=>SupabaseStoreTransport
|
|
685
|
+
});
|
|
686
|
+
var _iga_pages_data_plane__rspack_import_0 = __webpack_require__("../data-plane/dist/esm/index.js");
|
|
687
|
+
var _errors_js__rspack_import_1 = __webpack_require__("../store/src/errors.ts");
|
|
688
|
+
function throwForStatus(status, error) {
|
|
689
|
+
throw new _errors_js__rspack_import_1.A((0, _errors_js__rspack_import_1.Q)(status), error?.message ?? "Store request failed", {
|
|
690
|
+
status,
|
|
691
|
+
...error ? {
|
|
692
|
+
error
|
|
693
|
+
} : {}
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
class SupabaseStoreTransport {
|
|
697
|
+
async execute(options) {
|
|
698
|
+
const attempts = options.retryOnUnauthorized || options.retryOnNetworkError ? 2 : 1;
|
|
699
|
+
for(let attempt = 0; attempt < attempts; attempt += 1){
|
|
700
|
+
const credentials = await this.credentialProvider.getValidCredentials();
|
|
701
|
+
const client = (0, _iga_pages_data_plane__rspack_import_0.Ju)({
|
|
702
|
+
credentials,
|
|
703
|
+
fetch: this.fetch,
|
|
704
|
+
createClient: this.createClient,
|
|
705
|
+
realtimeError: ()=>new _errors_js__rspack_import_1.A("UnknownError", "Store does not support Supabase Realtime")
|
|
706
|
+
});
|
|
707
|
+
let result;
|
|
708
|
+
try {
|
|
709
|
+
result = await options.operation(client);
|
|
710
|
+
} catch (error) {
|
|
711
|
+
if (error instanceof _errors_js__rspack_import_1.A) throw error;
|
|
712
|
+
const name = error?.name;
|
|
713
|
+
if ("AbortError" === name) throw new _errors_js__rspack_import_1.A("AbortError", "Store request was cancelled");
|
|
714
|
+
if (options.retryOnNetworkError && attempt + 1 < attempts) continue;
|
|
715
|
+
throw new _errors_js__rspack_import_1.A("TimeoutError" === name ? "TimeoutError" : "NetworkError", error instanceof Error ? error.message : "Store request failed");
|
|
716
|
+
}
|
|
717
|
+
if (0 !== result.status || !options.retryOnNetworkError || !(attempt + 1 < attempts)) {
|
|
718
|
+
if (401 === result.status && attempt + 1 < attempts) {
|
|
719
|
+
this.credentialProvider.invalidate(credentials.jwt);
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
if (!result.success || result.status < 200 || result.status >= 300) throwForStatus(result.status, result.error);
|
|
723
|
+
return {
|
|
724
|
+
data: result.data,
|
|
725
|
+
count: result.count ?? null
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
throw new _errors_js__rspack_import_1.A("Unauthorized", "Store authorization failed");
|
|
730
|
+
}
|
|
731
|
+
constructor(options){
|
|
732
|
+
this.credentialProvider = options.credentialProvider;
|
|
733
|
+
this.fetch = options.fetch ?? globalThis.fetch;
|
|
734
|
+
this.createClient = options.createClient;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
"../store/src/token-client.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
739
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
740
|
+
f: ()=>validateStoreRootUrl,
|
|
741
|
+
o: ()=>fetchStoreCredentials
|
|
742
|
+
});
|
|
743
|
+
var _iga_pages_data_plane__rspack_import_0 = __webpack_require__("../data-plane/dist/esm/index.js");
|
|
744
|
+
var _credential_error_js__rspack_import_1 = __webpack_require__("../store/src/credential-error.ts");
|
|
745
|
+
function validateStoreRootUrl(value, isAllowedHostname) {
|
|
746
|
+
try {
|
|
747
|
+
return (0, _iga_pages_data_plane__rspack_import_0.uk)(value, isAllowedHostname);
|
|
748
|
+
} catch (error) {
|
|
749
|
+
throw (0, _credential_error_js__rspack_import_1.y)(error);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
async function fetchStoreCredentials(options) {
|
|
753
|
+
try {
|
|
754
|
+
return await (0, _iga_pages_data_plane__rspack_import_0.R5)(options);
|
|
755
|
+
} catch (error) {
|
|
756
|
+
throw (0, _credential_error_js__rspack_import_1.y)(error);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
};
|