@sylphx/sdk 0.5.0 → 0.7.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/README.md +13 -0
- package/dist/index.d.cts +3304 -20506
- package/dist/index.d.ts +3304 -20506
- package/dist/index.js +8399 -1698
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8108 -1456
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.d.cts +24 -5697
- package/dist/nextjs/index.d.ts +24 -5697
- package/dist/nextjs/index.js +24 -25
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +24 -25
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +404 -6088
- package/dist/react/index.d.ts +404 -6088
- package/dist/react/index.js +1124 -611
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +1191 -677
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.cts +116 -19551
- package/dist/server/index.d.ts +116 -19551
- package/dist/server/index.js +128 -61
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +128 -51
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.js +0 -3
- package/dist/web-analytics.js.map +1 -1
- package/dist/web-analytics.mjs +0 -3
- package/dist/web-analytics.mjs.map +1 -1
- package/package.json +2 -5
package/dist/server/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/server/index.ts
|
|
@@ -34,7 +24,7 @@ __export(server_exports, {
|
|
|
34
24
|
InvalidConnectionUrlError: () => InvalidConnectionUrlError,
|
|
35
25
|
createAI: () => createAI,
|
|
36
26
|
createAuthenticatedServerClient: () => createAuthenticatedServerClient,
|
|
37
|
-
createClient: () =>
|
|
27
|
+
createClient: () => createClient,
|
|
38
28
|
createKv: () => createKv,
|
|
39
29
|
createServerClient: () => createServerClient,
|
|
40
30
|
createServerRestClient: () => createServerRestClient,
|
|
@@ -77,7 +67,7 @@ __export(server_exports, {
|
|
|
77
67
|
});
|
|
78
68
|
module.exports = __toCommonJS(server_exports);
|
|
79
69
|
|
|
80
|
-
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
70
|
+
// ../../node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
81
71
|
var encoder = new TextEncoder();
|
|
82
72
|
var decoder = new TextDecoder();
|
|
83
73
|
var MAX_INT32 = 2 ** 32;
|
|
@@ -103,7 +93,7 @@ function encode(string) {
|
|
|
103
93
|
return bytes;
|
|
104
94
|
}
|
|
105
95
|
|
|
106
|
-
// node_modules/jose/dist/webapi/lib/base64.js
|
|
96
|
+
// ../../node_modules/jose/dist/webapi/lib/base64.js
|
|
107
97
|
function decodeBase64(encoded) {
|
|
108
98
|
if (Uint8Array.fromBase64) {
|
|
109
99
|
return Uint8Array.fromBase64(encoded);
|
|
@@ -116,7 +106,7 @@ function decodeBase64(encoded) {
|
|
|
116
106
|
return bytes;
|
|
117
107
|
}
|
|
118
108
|
|
|
119
|
-
// node_modules/jose/dist/webapi/util/base64url.js
|
|
109
|
+
// ../../node_modules/jose/dist/webapi/util/base64url.js
|
|
120
110
|
function decode(input) {
|
|
121
111
|
if (Uint8Array.fromBase64) {
|
|
122
112
|
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
@@ -135,7 +125,7 @@ function decode(input) {
|
|
|
135
125
|
}
|
|
136
126
|
}
|
|
137
127
|
|
|
138
|
-
// node_modules/jose/dist/webapi/util/errors.js
|
|
128
|
+
// ../../node_modules/jose/dist/webapi/util/errors.js
|
|
139
129
|
var JOSEError = class extends Error {
|
|
140
130
|
static code = "ERR_JOSE_GENERIC";
|
|
141
131
|
code = "ERR_JOSE_GENERIC";
|
|
@@ -195,7 +185,7 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
|
195
185
|
}
|
|
196
186
|
};
|
|
197
187
|
|
|
198
|
-
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
188
|
+
// ../../node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
199
189
|
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
200
190
|
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
201
191
|
function getHashLength(hash) {
|
|
@@ -283,7 +273,7 @@ function checkSigCryptoKey(key, alg, usage) {
|
|
|
283
273
|
checkUsage(key, usage);
|
|
284
274
|
}
|
|
285
275
|
|
|
286
|
-
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
276
|
+
// ../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
287
277
|
function message(msg, actual, ...types) {
|
|
288
278
|
types = types.filter(Boolean);
|
|
289
279
|
if (types.length > 2) {
|
|
@@ -308,7 +298,7 @@ function message(msg, actual, ...types) {
|
|
|
308
298
|
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
309
299
|
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
310
300
|
|
|
311
|
-
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
301
|
+
// ../../node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
312
302
|
var isCryptoKey = (key) => {
|
|
313
303
|
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
314
304
|
return true;
|
|
@@ -321,7 +311,7 @@ var isCryptoKey = (key) => {
|
|
|
321
311
|
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
322
312
|
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
323
313
|
|
|
324
|
-
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
314
|
+
// ../../node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
325
315
|
function isDisjoint(...headers) {
|
|
326
316
|
const sources = headers.filter(Boolean);
|
|
327
317
|
if (sources.length === 0 || sources.length === 1) {
|
|
@@ -344,7 +334,7 @@ function isDisjoint(...headers) {
|
|
|
344
334
|
return true;
|
|
345
335
|
}
|
|
346
336
|
|
|
347
|
-
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
337
|
+
// ../../node_modules/jose/dist/webapi/lib/is_object.js
|
|
348
338
|
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
349
339
|
function isObject(input) {
|
|
350
340
|
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
@@ -360,7 +350,7 @@ function isObject(input) {
|
|
|
360
350
|
return Object.getPrototypeOf(input) === proto;
|
|
361
351
|
}
|
|
362
352
|
|
|
363
|
-
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
353
|
+
// ../../node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
364
354
|
function checkKeyLength(alg, key) {
|
|
365
355
|
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
366
356
|
const { modulusLength } = key.algorithm;
|
|
@@ -370,7 +360,7 @@ function checkKeyLength(alg, key) {
|
|
|
370
360
|
}
|
|
371
361
|
}
|
|
372
362
|
|
|
373
|
-
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
363
|
+
// ../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
374
364
|
function subtleMapping(jwk) {
|
|
375
365
|
let algorithm;
|
|
376
366
|
let keyUsages;
|
|
@@ -480,7 +470,7 @@ async function jwkToKey(jwk) {
|
|
|
480
470
|
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
481
471
|
}
|
|
482
472
|
|
|
483
|
-
// node_modules/jose/dist/webapi/key/import.js
|
|
473
|
+
// ../../node_modules/jose/dist/webapi/key/import.js
|
|
484
474
|
async function importJWK(jwk, alg, options) {
|
|
485
475
|
if (!isObject(jwk)) {
|
|
486
476
|
throw new TypeError("JWK must be an object");
|
|
@@ -516,7 +506,7 @@ async function importJWK(jwk, alg, options) {
|
|
|
516
506
|
}
|
|
517
507
|
}
|
|
518
508
|
|
|
519
|
-
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
509
|
+
// ../../node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
520
510
|
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
521
511
|
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
522
512
|
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
@@ -547,7 +537,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
547
537
|
return new Set(protectedHeader.crit);
|
|
548
538
|
}
|
|
549
539
|
|
|
550
|
-
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
540
|
+
// ../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
551
541
|
function validateAlgorithms(option, algorithms) {
|
|
552
542
|
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
553
543
|
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
@@ -558,13 +548,13 @@ function validateAlgorithms(option, algorithms) {
|
|
|
558
548
|
return new Set(algorithms);
|
|
559
549
|
}
|
|
560
550
|
|
|
561
|
-
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
551
|
+
// ../../node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
562
552
|
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
563
553
|
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
564
554
|
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
565
555
|
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
566
556
|
|
|
567
|
-
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
557
|
+
// ../../node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
568
558
|
var cache;
|
|
569
559
|
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
570
560
|
cache ||= /* @__PURE__ */ new WeakMap();
|
|
@@ -735,7 +725,7 @@ async function normalizeKey(key, alg) {
|
|
|
735
725
|
throw new Error("unreachable");
|
|
736
726
|
}
|
|
737
727
|
|
|
738
|
-
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
728
|
+
// ../../node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
739
729
|
var tag = (key) => key?.[Symbol.toStringTag];
|
|
740
730
|
var jwkMatchesOp = (alg, key, usage) => {
|
|
741
731
|
if (key.use !== void 0) {
|
|
@@ -855,7 +845,7 @@ function checkKeyType(alg, key, usage) {
|
|
|
855
845
|
}
|
|
856
846
|
}
|
|
857
847
|
|
|
858
|
-
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
848
|
+
// ../../node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
859
849
|
function subtleAlgorithm(alg, algorithm) {
|
|
860
850
|
const hash = `SHA-${alg.slice(-3)}`;
|
|
861
851
|
switch (alg) {
|
|
@@ -887,7 +877,7 @@ function subtleAlgorithm(alg, algorithm) {
|
|
|
887
877
|
}
|
|
888
878
|
}
|
|
889
879
|
|
|
890
|
-
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
880
|
+
// ../../node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
891
881
|
async function getSigKey(alg, key, usage) {
|
|
892
882
|
if (key instanceof Uint8Array) {
|
|
893
883
|
if (!alg.startsWith("HS")) {
|
|
@@ -899,7 +889,7 @@ async function getSigKey(alg, key, usage) {
|
|
|
899
889
|
return key;
|
|
900
890
|
}
|
|
901
891
|
|
|
902
|
-
// node_modules/jose/dist/webapi/lib/verify.js
|
|
892
|
+
// ../../node_modules/jose/dist/webapi/lib/verify.js
|
|
903
893
|
async function verify(alg, key, signature, data) {
|
|
904
894
|
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
905
895
|
checkKeyLength(alg, cryptoKey);
|
|
@@ -911,7 +901,7 @@ async function verify(alg, key, signature, data) {
|
|
|
911
901
|
}
|
|
912
902
|
}
|
|
913
903
|
|
|
914
|
-
// node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
904
|
+
// ../../node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
915
905
|
async function flattenedVerify(jws, key, options) {
|
|
916
906
|
if (!isObject(jws)) {
|
|
917
907
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
@@ -1013,7 +1003,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
1013
1003
|
return result;
|
|
1014
1004
|
}
|
|
1015
1005
|
|
|
1016
|
-
// node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
1006
|
+
// ../../node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
1017
1007
|
async function compactVerify(jws, key, options) {
|
|
1018
1008
|
if (jws instanceof Uint8Array) {
|
|
1019
1009
|
jws = decoder.decode(jws);
|
|
@@ -1033,7 +1023,7 @@ async function compactVerify(jws, key, options) {
|
|
|
1033
1023
|
return result;
|
|
1034
1024
|
}
|
|
1035
1025
|
|
|
1036
|
-
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1026
|
+
// ../../node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1037
1027
|
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
1038
1028
|
var minute = 60;
|
|
1039
1029
|
var hour = minute * 60;
|
|
@@ -1190,7 +1180,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
1190
1180
|
return payload;
|
|
1191
1181
|
}
|
|
1192
1182
|
|
|
1193
|
-
// node_modules/jose/dist/webapi/jwt/verify.js
|
|
1183
|
+
// ../../node_modules/jose/dist/webapi/jwt/verify.js
|
|
1194
1184
|
async function jwtVerify(jwt, key, options) {
|
|
1195
1185
|
const verified = await compactVerify(jwt, key, options);
|
|
1196
1186
|
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
@@ -1246,9 +1236,6 @@ var CIRCUIT_BREAKER_OPEN_DURATION_MS = 3e4;
|
|
|
1246
1236
|
var ETAG_CACHE_MAX_ENTRIES = 100;
|
|
1247
1237
|
var ETAG_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
1248
1238
|
|
|
1249
|
-
// src/rest-client.ts
|
|
1250
|
-
var import_openapi_fetch = __toESM(require("openapi-fetch"), 1);
|
|
1251
|
-
|
|
1252
1239
|
// src/errors.ts
|
|
1253
1240
|
var ERROR_CODE_STATUS = {
|
|
1254
1241
|
BAD_REQUEST: 400,
|
|
@@ -1645,6 +1632,92 @@ function isDevelopmentRuntime() {
|
|
|
1645
1632
|
}
|
|
1646
1633
|
|
|
1647
1634
|
// src/rest-client.ts
|
|
1635
|
+
async function runPipeline(middlewares, initial) {
|
|
1636
|
+
let request = initial;
|
|
1637
|
+
for (const mw of middlewares) {
|
|
1638
|
+
if (mw.onRequest) {
|
|
1639
|
+
const next = await mw.onRequest({ request });
|
|
1640
|
+
if (next) request = next;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
let response = await fetch(request);
|
|
1644
|
+
for (const mw of middlewares) {
|
|
1645
|
+
if (mw.onResponse) {
|
|
1646
|
+
const next = await mw.onResponse({ request, response });
|
|
1647
|
+
if (next) response = next;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
return response;
|
|
1651
|
+
}
|
|
1652
|
+
function buildUrl(baseUrl, path, params) {
|
|
1653
|
+
const url = `${baseUrl}${path}`;
|
|
1654
|
+
if (!params) return url;
|
|
1655
|
+
const entries = Object.entries(params).filter(([, v]) => v !== void 0);
|
|
1656
|
+
if (entries.length === 0) return url;
|
|
1657
|
+
const search = new URLSearchParams(
|
|
1658
|
+
entries.map(([k, v]) => [k, String(v)])
|
|
1659
|
+
).toString();
|
|
1660
|
+
return `${url}?${search}`;
|
|
1661
|
+
}
|
|
1662
|
+
function interpolatePath(path, pathParams) {
|
|
1663
|
+
if (!pathParams) return path;
|
|
1664
|
+
return path.replace(/\{(\w+)\}/g, (_match, key) => {
|
|
1665
|
+
const value = pathParams[key];
|
|
1666
|
+
if (value === void 0) return `{${key}}`;
|
|
1667
|
+
return encodeURIComponent(value);
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
async function executeRequest(method, baseUrl, path, options, baseHeaders, middlewares) {
|
|
1671
|
+
const finalPath = interpolatePath(path, options?.params?.path);
|
|
1672
|
+
const url = buildUrl(baseUrl, finalPath, options?.params?.query);
|
|
1673
|
+
const headers = { ...baseHeaders, ...options?.headers };
|
|
1674
|
+
const init = { method, headers };
|
|
1675
|
+
if (options?.body !== void 0) {
|
|
1676
|
+
init.body = typeof options.body === "string" ? options.body : JSON.stringify(options.body);
|
|
1677
|
+
if (!headers["Content-Type"] && !headers["content-type"]) {
|
|
1678
|
+
headers["Content-Type"] = "application/json";
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
const request = new Request(url, init);
|
|
1682
|
+
const response = await runPipeline(middlewares, request);
|
|
1683
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1684
|
+
let parsed;
|
|
1685
|
+
if (contentType.includes("json")) {
|
|
1686
|
+
try {
|
|
1687
|
+
parsed = await response.clone().json();
|
|
1688
|
+
} catch {
|
|
1689
|
+
parsed = void 0;
|
|
1690
|
+
}
|
|
1691
|
+
} else if (response.status !== 204 && response.status !== 205) {
|
|
1692
|
+
try {
|
|
1693
|
+
const text = await response.clone().text();
|
|
1694
|
+
parsed = text === "" ? void 0 : text;
|
|
1695
|
+
} catch {
|
|
1696
|
+
parsed = void 0;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
if (response.ok) {
|
|
1700
|
+
return { data: parsed, response };
|
|
1701
|
+
}
|
|
1702
|
+
return { error: parsed, response };
|
|
1703
|
+
}
|
|
1704
|
+
function buildClient(baseUrl, baseHeaders) {
|
|
1705
|
+
const middlewares = [];
|
|
1706
|
+
const dispatch = (method) => (path, options) => executeRequest(method, baseUrl, path, options, baseHeaders, middlewares);
|
|
1707
|
+
const client = {
|
|
1708
|
+
GET: dispatch("GET"),
|
|
1709
|
+
POST: dispatch("POST"),
|
|
1710
|
+
PUT: dispatch("PUT"),
|
|
1711
|
+
PATCH: dispatch("PATCH"),
|
|
1712
|
+
DELETE: dispatch("DELETE"),
|
|
1713
|
+
HEAD: dispatch("HEAD"),
|
|
1714
|
+
OPTIONS: dispatch("OPTIONS"),
|
|
1715
|
+
use(...mws) {
|
|
1716
|
+
middlewares.push(...mws);
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
return { client, middlewares };
|
|
1720
|
+
}
|
|
1648
1721
|
function createAuthMiddleware(config) {
|
|
1649
1722
|
return {
|
|
1650
1723
|
async onRequest({ request }) {
|
|
@@ -1971,23 +2044,20 @@ function validateClientConfig(config) {
|
|
|
1971
2044
|
}
|
|
1972
2045
|
function createRestClient(config) {
|
|
1973
2046
|
const { secretKey, baseUrl } = validateClientConfig(config);
|
|
1974
|
-
const client = (
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
"Content-Type": "application/json",
|
|
1978
|
-
"x-app-secret": secretKey
|
|
1979
|
-
}
|
|
2047
|
+
const { client, middlewares } = buildClient(`${baseUrl}${SDK_API_PATH}`, {
|
|
2048
|
+
"Content-Type": "application/json",
|
|
2049
|
+
"x-app-secret": secretKey
|
|
1980
2050
|
});
|
|
1981
2051
|
if (config.deduplication !== false) {
|
|
1982
|
-
|
|
2052
|
+
middlewares.push(createDeduplicationMiddleware(config.deduplication));
|
|
1983
2053
|
}
|
|
1984
2054
|
if (config.circuitBreaker !== false) {
|
|
1985
|
-
|
|
2055
|
+
middlewares.push(createCircuitBreakerMiddleware(config.circuitBreaker));
|
|
1986
2056
|
}
|
|
1987
2057
|
if (config.etag !== false) {
|
|
1988
|
-
|
|
2058
|
+
middlewares.push(createETagMiddleware(config.etag));
|
|
1989
2059
|
}
|
|
1990
|
-
|
|
2060
|
+
middlewares.push(createRetryMiddleware(config.retry));
|
|
1991
2061
|
return client;
|
|
1992
2062
|
}
|
|
1993
2063
|
function createDynamicRestClient(config) {
|
|
@@ -1997,23 +2067,20 @@ function createDynamicRestClient(config) {
|
|
|
1997
2067
|
secretKey,
|
|
1998
2068
|
platformUrl: baseUrl
|
|
1999
2069
|
};
|
|
2000
|
-
const client = (
|
|
2001
|
-
|
|
2002
|
-
headers: {
|
|
2003
|
-
"Content-Type": "application/json"
|
|
2004
|
-
}
|
|
2070
|
+
const { client, middlewares } = buildClient(`${baseUrl}${SDK_API_PATH}`, {
|
|
2071
|
+
"Content-Type": "application/json"
|
|
2005
2072
|
});
|
|
2006
2073
|
if (config.deduplication !== false) {
|
|
2007
|
-
|
|
2074
|
+
middlewares.push(createDeduplicationMiddleware(config.deduplication));
|
|
2008
2075
|
}
|
|
2009
|
-
|
|
2076
|
+
middlewares.push(createAuthMiddleware(validatedConfig));
|
|
2010
2077
|
if (config.circuitBreaker !== false) {
|
|
2011
|
-
|
|
2078
|
+
middlewares.push(createCircuitBreakerMiddleware(config.circuitBreaker));
|
|
2012
2079
|
}
|
|
2013
2080
|
if (config.etag !== false) {
|
|
2014
|
-
|
|
2081
|
+
middlewares.push(createETagMiddleware(config.etag));
|
|
2015
2082
|
}
|
|
2016
|
-
|
|
2083
|
+
middlewares.push(createRetryMiddleware(config.retry));
|
|
2017
2084
|
return client;
|
|
2018
2085
|
}
|
|
2019
2086
|
|
|
@@ -2138,14 +2205,14 @@ function freezeConfig(opts) {
|
|
|
2138
2205
|
ref: opts.slug
|
|
2139
2206
|
});
|
|
2140
2207
|
}
|
|
2141
|
-
function
|
|
2208
|
+
function createClient(input) {
|
|
2142
2209
|
if (typeof input === "string") {
|
|
2143
2210
|
return createConfigFromUrl(input);
|
|
2144
2211
|
}
|
|
2145
2212
|
return createConfigFromComponents(input);
|
|
2146
2213
|
}
|
|
2147
2214
|
function createServerClient(input) {
|
|
2148
|
-
const config =
|
|
2215
|
+
const config = createClient(input);
|
|
2149
2216
|
if (config.credentialType !== "sk") {
|
|
2150
2217
|
throw new SylphxError(
|
|
2151
2218
|
"[Sylphx] createServerClient() requires a secret key (sk_*). Use a SYLPHX_SECRET_URL with an sk_ credential, or pass { secretKey } in the components object.",
|
|
@@ -2211,7 +2278,7 @@ function createConfigFromComponents(input) {
|
|
|
2211
2278
|
const credentialType = match[1];
|
|
2212
2279
|
const env = match[2];
|
|
2213
2280
|
const slug = resolvedSlug.trim().toLowerCase();
|
|
2214
|
-
const domain = input.domain?.trim() || "sylphx.com";
|
|
2281
|
+
const domain = input.domain?.trim() || "api.sylphx.com";
|
|
2215
2282
|
const baseUrl = `https://${slug}.${domain}/v1`;
|
|
2216
2283
|
return freezeConfig({
|
|
2217
2284
|
credential: trimmedCred,
|