@xylex-group/athena 1.7.0 → 2.0.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 +63 -53
- package/dist/cli/index.cjs +1224 -102
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +1224 -102
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +1832 -1138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -293
- package/dist/index.d.ts +63 -293
- package/dist/index.js +1829 -1139
- package/dist/index.js.map +1 -1
- package/dist/model-form-CVOtC8jq.d.ts +1284 -0
- package/dist/model-form-hXkvHS_3.d.cts +1284 -0
- package/dist/pipeline-C-cN0ACi.d.cts +164 -0
- package/dist/pipeline-CQgV-Yfo.d.ts +164 -0
- package/dist/react.cjs +157 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +38 -4
- package/dist/react.d.ts +38 -4
- package/dist/react.js +154 -1
- package/dist/react.js.map +1 -1
- package/dist/types-BnzoaNRC.d.cts +380 -0
- package/dist/types-BnzoaNRC.d.ts +380 -0
- package/package.json +3 -3
- package/dist/errors-BJGgjHcI.d.cts +0 -31
- package/dist/errors-Bcf5Sftv.d.ts +0 -31
- package/dist/pipeline-BsKuBqmE.d.cts +0 -343
- package/dist/pipeline-xQSjGbqF.d.ts +0 -343
- package/dist/types-wPA1Z4vQ.d.cts +0 -195
- package/dist/types-wPA1Z4vQ.d.ts +0 -195
package/dist/cli/index.cjs
CHANGED
|
@@ -292,6 +292,76 @@ function resolvePostgresColumnType(column) {
|
|
|
292
292
|
return wrapArrayType(baseType, column.arrayDimensions);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
// src/gateway/errors.ts
|
|
296
|
+
var AthenaGatewayError = class _AthenaGatewayError extends Error {
|
|
297
|
+
code;
|
|
298
|
+
status;
|
|
299
|
+
endpoint;
|
|
300
|
+
method;
|
|
301
|
+
requestId;
|
|
302
|
+
hint;
|
|
303
|
+
causeDetail;
|
|
304
|
+
constructor(input) {
|
|
305
|
+
super(input.message);
|
|
306
|
+
this.name = "AthenaGatewayError";
|
|
307
|
+
this.code = input.code;
|
|
308
|
+
this.status = input.status ?? 0;
|
|
309
|
+
this.endpoint = input.endpoint;
|
|
310
|
+
this.method = input.method;
|
|
311
|
+
this.requestId = input.requestId;
|
|
312
|
+
this.hint = input.hint;
|
|
313
|
+
this.causeDetail = input.cause;
|
|
314
|
+
}
|
|
315
|
+
toDetails() {
|
|
316
|
+
return {
|
|
317
|
+
code: this.code,
|
|
318
|
+
message: this.message,
|
|
319
|
+
status: this.status,
|
|
320
|
+
endpoint: this.endpoint,
|
|
321
|
+
method: this.method,
|
|
322
|
+
requestId: this.requestId,
|
|
323
|
+
hint: this.hint,
|
|
324
|
+
cause: this.causeDetail
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
static fromResponse(response, fallback) {
|
|
328
|
+
const details = response.errorDetails;
|
|
329
|
+
if (details) {
|
|
330
|
+
return new _AthenaGatewayError({
|
|
331
|
+
code: details.code,
|
|
332
|
+
message: details.message,
|
|
333
|
+
status: details.status,
|
|
334
|
+
endpoint: details.endpoint ?? fallback.endpoint,
|
|
335
|
+
method: details.method ?? fallback.method,
|
|
336
|
+
requestId: details.requestId ?? fallback.requestId,
|
|
337
|
+
hint: details.hint,
|
|
338
|
+
cause: details.cause
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return new _AthenaGatewayError({
|
|
342
|
+
code: "HTTP_ERROR",
|
|
343
|
+
message: response.error ?? "Gateway request failed",
|
|
344
|
+
status: response.status,
|
|
345
|
+
endpoint: fallback.endpoint,
|
|
346
|
+
method: fallback.method,
|
|
347
|
+
requestId: fallback.requestId
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// src/auxiliaries.ts
|
|
353
|
+
function parseBooleanFlag(rawValue, fallback) {
|
|
354
|
+
if (!rawValue) return fallback;
|
|
355
|
+
const normalized = rawValue.trim().toLowerCase();
|
|
356
|
+
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
return fallback;
|
|
363
|
+
}
|
|
364
|
+
|
|
295
365
|
// src/generator/schema-selection.ts
|
|
296
366
|
var DEFAULT_POSTGRES_SCHEMAS = ["public"];
|
|
297
367
|
function collectSchemaNames(input) {
|
|
@@ -351,6 +421,39 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
351
421
|
postgresGatewayIntrospection: false,
|
|
352
422
|
scyllaProviderContracts: true
|
|
353
423
|
};
|
|
424
|
+
function normalizeBooleanFlag(rawValue, fallback) {
|
|
425
|
+
if (typeof rawValue === "boolean") {
|
|
426
|
+
return rawValue;
|
|
427
|
+
}
|
|
428
|
+
if (typeof rawValue === "string") {
|
|
429
|
+
return parseBooleanFlag(rawValue, fallback);
|
|
430
|
+
}
|
|
431
|
+
return fallback;
|
|
432
|
+
}
|
|
433
|
+
function normalizeFeatureFlags(input) {
|
|
434
|
+
return {
|
|
435
|
+
emitRelations: normalizeBooleanFlag(
|
|
436
|
+
input?.emitRelations,
|
|
437
|
+
DEFAULT_FEATURES.emitRelations
|
|
438
|
+
),
|
|
439
|
+
emitRegistry: normalizeBooleanFlag(
|
|
440
|
+
input?.emitRegistry,
|
|
441
|
+
DEFAULT_FEATURES.emitRegistry
|
|
442
|
+
)
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function normalizeExperimentalFlags(input) {
|
|
446
|
+
return {
|
|
447
|
+
postgresGatewayIntrospection: normalizeBooleanFlag(
|
|
448
|
+
input?.postgresGatewayIntrospection,
|
|
449
|
+
DEFAULT_EXPERIMENTAL_FLAGS.postgresGatewayIntrospection
|
|
450
|
+
),
|
|
451
|
+
scyllaProviderContracts: normalizeBooleanFlag(
|
|
452
|
+
input?.scyllaProviderContracts,
|
|
453
|
+
DEFAULT_EXPERIMENTAL_FLAGS.scyllaProviderContracts
|
|
454
|
+
)
|
|
455
|
+
};
|
|
456
|
+
}
|
|
354
457
|
function normalizeOutputConfig(output) {
|
|
355
458
|
return {
|
|
356
459
|
targets: {
|
|
@@ -386,14 +489,8 @@ function normalizeGeneratorConfig(input) {
|
|
|
386
489
|
...DEFAULT_NAMING,
|
|
387
490
|
...input.naming ?? {}
|
|
388
491
|
},
|
|
389
|
-
features:
|
|
390
|
-
|
|
391
|
-
...input.features ?? {}
|
|
392
|
-
},
|
|
393
|
-
experimental: {
|
|
394
|
-
...DEFAULT_EXPERIMENTAL_FLAGS,
|
|
395
|
-
...input.experimental ?? {}
|
|
396
|
-
}
|
|
492
|
+
features: normalizeFeatureFlags(input.features),
|
|
493
|
+
experimental: normalizeExperimentalFlags(input.experimental)
|
|
397
494
|
};
|
|
398
495
|
}
|
|
399
496
|
function findGeneratorConfigPath(cwd = process.cwd()) {
|
|
@@ -722,63 +819,6 @@ function generateArtifactsFromSnapshot(snapshot, config) {
|
|
|
722
819
|
return new ArtifactComposer(snapshot, normalizedConfig).compose();
|
|
723
820
|
}
|
|
724
821
|
|
|
725
|
-
// src/gateway/errors.ts
|
|
726
|
-
var AthenaGatewayError = class _AthenaGatewayError extends Error {
|
|
727
|
-
code;
|
|
728
|
-
status;
|
|
729
|
-
endpoint;
|
|
730
|
-
method;
|
|
731
|
-
requestId;
|
|
732
|
-
hint;
|
|
733
|
-
causeDetail;
|
|
734
|
-
constructor(input) {
|
|
735
|
-
super(input.message);
|
|
736
|
-
this.name = "AthenaGatewayError";
|
|
737
|
-
this.code = input.code;
|
|
738
|
-
this.status = input.status ?? 0;
|
|
739
|
-
this.endpoint = input.endpoint;
|
|
740
|
-
this.method = input.method;
|
|
741
|
-
this.requestId = input.requestId;
|
|
742
|
-
this.hint = input.hint;
|
|
743
|
-
this.causeDetail = input.cause;
|
|
744
|
-
}
|
|
745
|
-
toDetails() {
|
|
746
|
-
return {
|
|
747
|
-
code: this.code,
|
|
748
|
-
message: this.message,
|
|
749
|
-
status: this.status,
|
|
750
|
-
endpoint: this.endpoint,
|
|
751
|
-
method: this.method,
|
|
752
|
-
requestId: this.requestId,
|
|
753
|
-
hint: this.hint,
|
|
754
|
-
cause: this.causeDetail
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
static fromResponse(response, fallback) {
|
|
758
|
-
const details = response.errorDetails;
|
|
759
|
-
if (details) {
|
|
760
|
-
return new _AthenaGatewayError({
|
|
761
|
-
code: details.code,
|
|
762
|
-
message: details.message,
|
|
763
|
-
status: details.status,
|
|
764
|
-
endpoint: details.endpoint ?? fallback.endpoint,
|
|
765
|
-
method: details.method ?? fallback.method,
|
|
766
|
-
requestId: details.requestId ?? fallback.requestId,
|
|
767
|
-
hint: details.hint,
|
|
768
|
-
cause: details.cause
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
return new _AthenaGatewayError({
|
|
772
|
-
code: "HTTP_ERROR",
|
|
773
|
-
message: response.error ?? "Gateway request failed",
|
|
774
|
-
status: response.status,
|
|
775
|
-
endpoint: fallback.endpoint,
|
|
776
|
-
method: fallback.method,
|
|
777
|
-
requestId: fallback.requestId
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
|
|
782
822
|
// src/gateway/client.ts
|
|
783
823
|
var DEFAULT_BASE_URL = "https://athena-db.com";
|
|
784
824
|
var DEFAULT_CLIENT = "railway_direct";
|
|
@@ -1200,6 +1240,1044 @@ function quoteSelectColumnsExpression(columns) {
|
|
|
1200
1240
|
return tokens.map(quoteSelectToken).join(", ");
|
|
1201
1241
|
}
|
|
1202
1242
|
|
|
1243
|
+
// src/auth/client.ts
|
|
1244
|
+
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
1245
|
+
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
1246
|
+
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
1247
|
+
var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
|
|
1248
|
+
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
1249
|
+
function normalizeBaseUrl(baseUrl) {
|
|
1250
|
+
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
1251
|
+
}
|
|
1252
|
+
function isRecord2(value) {
|
|
1253
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1254
|
+
}
|
|
1255
|
+
function normalizeHeaderValue2(value) {
|
|
1256
|
+
return value ? value : void 0;
|
|
1257
|
+
}
|
|
1258
|
+
function parseResponseBody2(rawText, contentType) {
|
|
1259
|
+
if (!rawText) {
|
|
1260
|
+
return { parsed: null, parseFailed: false };
|
|
1261
|
+
}
|
|
1262
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
1263
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
1264
|
+
if (!looksJson) {
|
|
1265
|
+
return { parsed: rawText, parseFailed: false };
|
|
1266
|
+
}
|
|
1267
|
+
try {
|
|
1268
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
1269
|
+
} catch {
|
|
1270
|
+
return { parsed: rawText, parseFailed: true };
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
function resolveRequestId2(headers) {
|
|
1274
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
1275
|
+
}
|
|
1276
|
+
function resolveErrorMessage2(payload, fallback) {
|
|
1277
|
+
if (isRecord2(payload)) {
|
|
1278
|
+
const messageCandidates = [payload.error, payload.message, payload.details];
|
|
1279
|
+
for (const candidate of messageCandidates) {
|
|
1280
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
1281
|
+
return candidate.trim();
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
1286
|
+
return payload.trim();
|
|
1287
|
+
}
|
|
1288
|
+
return fallback;
|
|
1289
|
+
}
|
|
1290
|
+
function toErrorDetails(input) {
|
|
1291
|
+
return {
|
|
1292
|
+
code: input.code,
|
|
1293
|
+
message: input.message,
|
|
1294
|
+
status: input.status,
|
|
1295
|
+
endpoint: input.endpoint,
|
|
1296
|
+
method: input.method,
|
|
1297
|
+
requestId: input.requestId,
|
|
1298
|
+
hint: input.hint,
|
|
1299
|
+
cause: input.cause
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
function mergeCallOptions(base, override) {
|
|
1303
|
+
if (!base && !override) return void 0;
|
|
1304
|
+
return {
|
|
1305
|
+
...base,
|
|
1306
|
+
...override,
|
|
1307
|
+
headers: {
|
|
1308
|
+
...base?.headers ?? {},
|
|
1309
|
+
...override?.headers ?? {}
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
function extractFetchOptions(input) {
|
|
1314
|
+
if (!input) {
|
|
1315
|
+
return {
|
|
1316
|
+
payload: void 0,
|
|
1317
|
+
fetchOptions: void 0
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
const { fetchOptions, ...rest } = input;
|
|
1321
|
+
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
1322
|
+
return {
|
|
1323
|
+
payload: hasPayloadKeys ? rest : void 0,
|
|
1324
|
+
fetchOptions
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
function buildHeaders2(config, options) {
|
|
1328
|
+
const headers = {
|
|
1329
|
+
"Content-Type": "application/json",
|
|
1330
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
1331
|
+
};
|
|
1332
|
+
const apiKey = options?.apiKey ?? config.apiKey;
|
|
1333
|
+
if (apiKey) {
|
|
1334
|
+
headers.apikey = apiKey;
|
|
1335
|
+
headers["x-api-key"] = apiKey;
|
|
1336
|
+
}
|
|
1337
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
1338
|
+
if (bearerToken) {
|
|
1339
|
+
headers.Authorization = `Bearer ${bearerToken}`;
|
|
1340
|
+
}
|
|
1341
|
+
const mergedExtraHeaders = {
|
|
1342
|
+
...config.headers ?? {},
|
|
1343
|
+
...options?.headers ?? {}
|
|
1344
|
+
};
|
|
1345
|
+
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
1346
|
+
const normalized = normalizeHeaderValue2(value);
|
|
1347
|
+
if (normalized) {
|
|
1348
|
+
headers[key] = normalized;
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
return headers;
|
|
1352
|
+
}
|
|
1353
|
+
function appendQueryParam(searchParams, key, value) {
|
|
1354
|
+
if (value === void 0 || value === null) return;
|
|
1355
|
+
if (Array.isArray(value)) {
|
|
1356
|
+
value.forEach((item) => {
|
|
1357
|
+
searchParams.append(key, String(item));
|
|
1358
|
+
});
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
searchParams.append(key, String(value));
|
|
1362
|
+
}
|
|
1363
|
+
function buildRequestUrl(baseUrl, endpoint, query) {
|
|
1364
|
+
const url = `${baseUrl}${endpoint}`;
|
|
1365
|
+
if (!query || Object.keys(query).length === 0) return url;
|
|
1366
|
+
const searchParams = new URLSearchParams();
|
|
1367
|
+
Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
|
|
1368
|
+
const queryText = searchParams.toString();
|
|
1369
|
+
return queryText ? `${url}?${queryText}` : url;
|
|
1370
|
+
}
|
|
1371
|
+
function inferDefaultMethod(endpoint) {
|
|
1372
|
+
if (endpoint.startsWith("/reset-password/")) {
|
|
1373
|
+
return "GET";
|
|
1374
|
+
}
|
|
1375
|
+
switch (endpoint) {
|
|
1376
|
+
case "/get-session":
|
|
1377
|
+
case "/list-sessions":
|
|
1378
|
+
case "/verify-email":
|
|
1379
|
+
case "/change-email/verify":
|
|
1380
|
+
case "/delete-user/verify":
|
|
1381
|
+
case "/email-list":
|
|
1382
|
+
case "/email/list":
|
|
1383
|
+
case "/delete-user/callback":
|
|
1384
|
+
case "/list-accounts":
|
|
1385
|
+
case "/passkey/generate-register-options":
|
|
1386
|
+
case "/passkey/list-user-passkeys":
|
|
1387
|
+
case "/.well-known/webauthn":
|
|
1388
|
+
case "/admin/list-users":
|
|
1389
|
+
case "/admin/athena-client/list":
|
|
1390
|
+
case "/admin/audit-log/list":
|
|
1391
|
+
case "/admin/email/get":
|
|
1392
|
+
case "/admin/email-failure/list":
|
|
1393
|
+
case "/admin/email-failure/get":
|
|
1394
|
+
case "/admin/email-template/get":
|
|
1395
|
+
case "/admin/email-template/list":
|
|
1396
|
+
case "/admin/email/list":
|
|
1397
|
+
case "/api-key/get":
|
|
1398
|
+
case "/api-key/list":
|
|
1399
|
+
case "/organization/get-full-organization":
|
|
1400
|
+
case "/organization/list":
|
|
1401
|
+
case "/organization/get-invitation":
|
|
1402
|
+
case "/organization/list-invitations":
|
|
1403
|
+
case "/organization/list-user-invitations":
|
|
1404
|
+
case "/organization/list-members":
|
|
1405
|
+
case "/organization/get-active-member":
|
|
1406
|
+
case "/health":
|
|
1407
|
+
case "/ok":
|
|
1408
|
+
case "/error":
|
|
1409
|
+
return "GET";
|
|
1410
|
+
default:
|
|
1411
|
+
return "POST";
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
async function callAuthEndpoint(config, context, body, query, options) {
|
|
1415
|
+
const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
1416
|
+
const url = buildRequestUrl(baseUrl, context.endpoint, query);
|
|
1417
|
+
const headers = buildHeaders2(config, options);
|
|
1418
|
+
const credentials = options?.credentials ?? config.credentials ?? "include";
|
|
1419
|
+
const requestInit = {
|
|
1420
|
+
method: context.method,
|
|
1421
|
+
headers,
|
|
1422
|
+
credentials,
|
|
1423
|
+
signal: options?.signal
|
|
1424
|
+
};
|
|
1425
|
+
if (context.method !== "GET") {
|
|
1426
|
+
requestInit.body = JSON.stringify(body ?? {});
|
|
1427
|
+
}
|
|
1428
|
+
const fetcher = config.fetch ?? globalThis.fetch;
|
|
1429
|
+
if (!fetcher) {
|
|
1430
|
+
const details = toErrorDetails({
|
|
1431
|
+
code: "UNKNOWN_ERROR",
|
|
1432
|
+
message: "No fetch implementation available for auth client",
|
|
1433
|
+
status: 0,
|
|
1434
|
+
endpoint: context.endpoint,
|
|
1435
|
+
method: context.method,
|
|
1436
|
+
hint: "Use Node 18+ or provide `fetch` via createClient(..., { auth: { fetch } }) or createAuthClient({ fetch })"
|
|
1437
|
+
});
|
|
1438
|
+
return {
|
|
1439
|
+
ok: false,
|
|
1440
|
+
status: 0,
|
|
1441
|
+
data: null,
|
|
1442
|
+
error: details.message,
|
|
1443
|
+
errorDetails: details,
|
|
1444
|
+
raw: null
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
try {
|
|
1448
|
+
const response = await fetcher(url, requestInit);
|
|
1449
|
+
const rawText = await response.text();
|
|
1450
|
+
const requestId = resolveRequestId2(response.headers);
|
|
1451
|
+
const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
|
|
1452
|
+
if (parsedBody.parseFailed) {
|
|
1453
|
+
const details = toErrorDetails({
|
|
1454
|
+
code: "INVALID_JSON",
|
|
1455
|
+
message: "Auth server returned malformed JSON",
|
|
1456
|
+
status: response.status,
|
|
1457
|
+
endpoint: context.endpoint,
|
|
1458
|
+
method: context.method,
|
|
1459
|
+
requestId,
|
|
1460
|
+
hint: "Verify the auth endpoint response body is valid JSON.",
|
|
1461
|
+
cause: rawText.slice(0, 300)
|
|
1462
|
+
});
|
|
1463
|
+
return {
|
|
1464
|
+
ok: false,
|
|
1465
|
+
status: response.status,
|
|
1466
|
+
data: null,
|
|
1467
|
+
error: details.message,
|
|
1468
|
+
errorDetails: details,
|
|
1469
|
+
raw: parsedBody.parsed
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
const parsed = parsedBody.parsed;
|
|
1473
|
+
if (!response.ok) {
|
|
1474
|
+
const details = toErrorDetails({
|
|
1475
|
+
code: "HTTP_ERROR",
|
|
1476
|
+
message: resolveErrorMessage2(
|
|
1477
|
+
parsed,
|
|
1478
|
+
`Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
|
|
1479
|
+
),
|
|
1480
|
+
status: response.status,
|
|
1481
|
+
endpoint: context.endpoint,
|
|
1482
|
+
method: context.method,
|
|
1483
|
+
requestId
|
|
1484
|
+
});
|
|
1485
|
+
return {
|
|
1486
|
+
ok: false,
|
|
1487
|
+
status: response.status,
|
|
1488
|
+
data: null,
|
|
1489
|
+
error: details.message,
|
|
1490
|
+
errorDetails: details,
|
|
1491
|
+
raw: parsed
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
return {
|
|
1495
|
+
ok: true,
|
|
1496
|
+
status: response.status,
|
|
1497
|
+
data: parsed ?? null,
|
|
1498
|
+
error: null,
|
|
1499
|
+
errorDetails: null,
|
|
1500
|
+
raw: parsed
|
|
1501
|
+
};
|
|
1502
|
+
} catch (callError) {
|
|
1503
|
+
const message = callError instanceof Error ? callError.message : String(callError);
|
|
1504
|
+
const details = toErrorDetails({
|
|
1505
|
+
code: "NETWORK_ERROR",
|
|
1506
|
+
message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
|
|
1507
|
+
status: 0,
|
|
1508
|
+
endpoint: context.endpoint,
|
|
1509
|
+
method: context.method,
|
|
1510
|
+
cause: message,
|
|
1511
|
+
hint: "Check auth server URL, DNS, and network reachability."
|
|
1512
|
+
});
|
|
1513
|
+
return {
|
|
1514
|
+
ok: false,
|
|
1515
|
+
status: 0,
|
|
1516
|
+
data: null,
|
|
1517
|
+
error: details.message,
|
|
1518
|
+
errorDetails: details,
|
|
1519
|
+
raw: null
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
function executePostWithCompatibleInput(config, context, input, options) {
|
|
1524
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1525
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1526
|
+
return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
|
|
1527
|
+
}
|
|
1528
|
+
function executePostWithOptionalInput(config, context, input, options) {
|
|
1529
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
1530
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1531
|
+
return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
|
|
1532
|
+
}
|
|
1533
|
+
function executeGetWithCompatibleInput(config, context, input, options) {
|
|
1534
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
1535
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1536
|
+
return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
|
|
1537
|
+
}
|
|
1538
|
+
function executeGetWithQueryCompatibleInput(config, context, input, options) {
|
|
1539
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1540
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1541
|
+
const query = payload?.query;
|
|
1542
|
+
return callAuthEndpoint(
|
|
1543
|
+
config,
|
|
1544
|
+
context,
|
|
1545
|
+
void 0,
|
|
1546
|
+
query,
|
|
1547
|
+
mergedOptions
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
function createAuthClient(config = {}) {
|
|
1551
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1552
|
+
const resolvedConfig = {
|
|
1553
|
+
...config,
|
|
1554
|
+
baseUrl: normalizedBaseUrl
|
|
1555
|
+
};
|
|
1556
|
+
const request = (input, options) => {
|
|
1557
|
+
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
1558
|
+
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
1559
|
+
return callAuthEndpoint(
|
|
1560
|
+
resolvedConfig,
|
|
1561
|
+
{ endpoint: input.endpoint, method },
|
|
1562
|
+
input.body,
|
|
1563
|
+
input.query,
|
|
1564
|
+
mergedOptions
|
|
1565
|
+
);
|
|
1566
|
+
};
|
|
1567
|
+
const postGeneric = (endpoint, input, options) => {
|
|
1568
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1569
|
+
return request(
|
|
1570
|
+
{
|
|
1571
|
+
endpoint,
|
|
1572
|
+
method: "POST",
|
|
1573
|
+
body: payload ?? {},
|
|
1574
|
+
fetchOptions
|
|
1575
|
+
},
|
|
1576
|
+
options
|
|
1577
|
+
);
|
|
1578
|
+
};
|
|
1579
|
+
const getGeneric = (endpoint, input, options) => {
|
|
1580
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
1581
|
+
return request(
|
|
1582
|
+
{
|
|
1583
|
+
endpoint,
|
|
1584
|
+
method: "GET",
|
|
1585
|
+
fetchOptions
|
|
1586
|
+
},
|
|
1587
|
+
options
|
|
1588
|
+
);
|
|
1589
|
+
};
|
|
1590
|
+
const getWithQuery = (endpoint, input, options) => {
|
|
1591
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1592
|
+
const query = payload?.query;
|
|
1593
|
+
return request(
|
|
1594
|
+
{
|
|
1595
|
+
endpoint,
|
|
1596
|
+
method: "GET",
|
|
1597
|
+
query,
|
|
1598
|
+
fetchOptions
|
|
1599
|
+
},
|
|
1600
|
+
options
|
|
1601
|
+
);
|
|
1602
|
+
};
|
|
1603
|
+
const listUserEmailsWithFallback = async (input, options) => {
|
|
1604
|
+
const primary = await getWithQuery(
|
|
1605
|
+
"/email/list",
|
|
1606
|
+
input,
|
|
1607
|
+
options
|
|
1608
|
+
);
|
|
1609
|
+
if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
|
|
1610
|
+
return primary;
|
|
1611
|
+
}
|
|
1612
|
+
return getWithQuery(
|
|
1613
|
+
"/email-list",
|
|
1614
|
+
input,
|
|
1615
|
+
options
|
|
1616
|
+
);
|
|
1617
|
+
};
|
|
1618
|
+
const healthWithFallback = async (input, options) => {
|
|
1619
|
+
const primary = await getGeneric("/health", input, options);
|
|
1620
|
+
if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
|
|
1621
|
+
return primary;
|
|
1622
|
+
}
|
|
1623
|
+
const fallback = await getGeneric("/ok", input, options);
|
|
1624
|
+
if (!fallback.ok) {
|
|
1625
|
+
return {
|
|
1626
|
+
...fallback,
|
|
1627
|
+
data: null
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
const fallbackStatus = isRecord2(fallback.data) && typeof fallback.data.ok === "boolean" ? fallback.data.ok ? "ok" : "error" : "ok";
|
|
1631
|
+
return {
|
|
1632
|
+
...fallback,
|
|
1633
|
+
data: {
|
|
1634
|
+
status: fallbackStatus
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
};
|
|
1638
|
+
const signOut = (input, options) => executePostWithOptionalInput(
|
|
1639
|
+
resolvedConfig,
|
|
1640
|
+
{ endpoint: "/sign-out", method: "POST" },
|
|
1641
|
+
input,
|
|
1642
|
+
options
|
|
1643
|
+
);
|
|
1644
|
+
const revokeSessions = (input, options) => executePostWithOptionalInput(
|
|
1645
|
+
resolvedConfig,
|
|
1646
|
+
{ endpoint: "/revoke-sessions", method: "POST" },
|
|
1647
|
+
input,
|
|
1648
|
+
options
|
|
1649
|
+
);
|
|
1650
|
+
const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
|
|
1651
|
+
resolvedConfig,
|
|
1652
|
+
{ endpoint: "/revoke-other-sessions", method: "POST" },
|
|
1653
|
+
input,
|
|
1654
|
+
options
|
|
1655
|
+
);
|
|
1656
|
+
const revokeSession = (input, options) => executePostWithCompatibleInput(
|
|
1657
|
+
resolvedConfig,
|
|
1658
|
+
{ endpoint: "/revoke-session", method: "POST" },
|
|
1659
|
+
input,
|
|
1660
|
+
options
|
|
1661
|
+
);
|
|
1662
|
+
const deleteUser = (input, options) => {
|
|
1663
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1664
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1665
|
+
return callAuthEndpoint(
|
|
1666
|
+
resolvedConfig,
|
|
1667
|
+
{ endpoint: "/delete-user", method: "POST" },
|
|
1668
|
+
payload ?? {},
|
|
1669
|
+
void 0,
|
|
1670
|
+
mergedOptions
|
|
1671
|
+
);
|
|
1672
|
+
};
|
|
1673
|
+
const deleteUserCallback = (input, options) => {
|
|
1674
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1675
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1676
|
+
const query = payload ?? {};
|
|
1677
|
+
return callAuthEndpoint(
|
|
1678
|
+
resolvedConfig,
|
|
1679
|
+
{ endpoint: "/delete-user/callback", method: "GET" },
|
|
1680
|
+
void 0,
|
|
1681
|
+
{
|
|
1682
|
+
token: query.token,
|
|
1683
|
+
callbackURL: query.callbackURL
|
|
1684
|
+
},
|
|
1685
|
+
mergedOptions
|
|
1686
|
+
);
|
|
1687
|
+
};
|
|
1688
|
+
const resolveResetPasswordToken = (input, options) => {
|
|
1689
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1690
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1691
|
+
const query = payload;
|
|
1692
|
+
const token = query?.token?.trim();
|
|
1693
|
+
if (!token) {
|
|
1694
|
+
throw new Error("resolveResetPasswordToken requires a non-empty token");
|
|
1695
|
+
}
|
|
1696
|
+
const endpoint = `/reset-password/${encodeURIComponent(token)}`;
|
|
1697
|
+
return callAuthEndpoint(
|
|
1698
|
+
resolvedConfig,
|
|
1699
|
+
{ endpoint, method: "GET" },
|
|
1700
|
+
void 0,
|
|
1701
|
+
query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
|
|
1702
|
+
mergedOptions
|
|
1703
|
+
);
|
|
1704
|
+
};
|
|
1705
|
+
const organization = {
|
|
1706
|
+
create: (input, options) => executePostWithCompatibleInput(
|
|
1707
|
+
resolvedConfig,
|
|
1708
|
+
{ endpoint: "/organization/create", method: "POST" },
|
|
1709
|
+
input,
|
|
1710
|
+
options
|
|
1711
|
+
),
|
|
1712
|
+
update: (input, options) => executePostWithCompatibleInput(
|
|
1713
|
+
resolvedConfig,
|
|
1714
|
+
{ endpoint: "/organization/update", method: "POST" },
|
|
1715
|
+
input,
|
|
1716
|
+
options
|
|
1717
|
+
),
|
|
1718
|
+
delete: (input, options) => executePostWithCompatibleInput(
|
|
1719
|
+
resolvedConfig,
|
|
1720
|
+
{ endpoint: "/organization/delete", method: "POST" },
|
|
1721
|
+
input,
|
|
1722
|
+
options
|
|
1723
|
+
),
|
|
1724
|
+
setActive: (input, options) => executePostWithCompatibleInput(
|
|
1725
|
+
resolvedConfig,
|
|
1726
|
+
{ endpoint: "/organization/set-active", method: "POST" },
|
|
1727
|
+
input,
|
|
1728
|
+
options
|
|
1729
|
+
),
|
|
1730
|
+
list: (input, options) => getGeneric(
|
|
1731
|
+
"/organization/list",
|
|
1732
|
+
input,
|
|
1733
|
+
options
|
|
1734
|
+
),
|
|
1735
|
+
getFull: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1736
|
+
resolvedConfig,
|
|
1737
|
+
{ endpoint: "/organization/get-full-organization", method: "GET" },
|
|
1738
|
+
input,
|
|
1739
|
+
options
|
|
1740
|
+
),
|
|
1741
|
+
checkSlug: (input, options) => executePostWithCompatibleInput(
|
|
1742
|
+
resolvedConfig,
|
|
1743
|
+
{ endpoint: "/organization/check-slug", method: "POST" },
|
|
1744
|
+
input,
|
|
1745
|
+
options
|
|
1746
|
+
),
|
|
1747
|
+
leave: (input, options) => executePostWithCompatibleInput(
|
|
1748
|
+
resolvedConfig,
|
|
1749
|
+
{ endpoint: "/organization/leave", method: "POST" },
|
|
1750
|
+
input,
|
|
1751
|
+
options
|
|
1752
|
+
),
|
|
1753
|
+
listUserInvitations: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1754
|
+
resolvedConfig,
|
|
1755
|
+
{ endpoint: "/organization/list-user-invitations", method: "GET" },
|
|
1756
|
+
input,
|
|
1757
|
+
options
|
|
1758
|
+
),
|
|
1759
|
+
hasPermission: (input, options) => postGeneric(
|
|
1760
|
+
"/organization/has-permission",
|
|
1761
|
+
input,
|
|
1762
|
+
options
|
|
1763
|
+
),
|
|
1764
|
+
invitation: {
|
|
1765
|
+
cancel: (input, options) => executePostWithCompatibleInput(
|
|
1766
|
+
resolvedConfig,
|
|
1767
|
+
{ endpoint: "/organization/cancel-invitation", method: "POST" },
|
|
1768
|
+
input,
|
|
1769
|
+
options
|
|
1770
|
+
),
|
|
1771
|
+
accept: (input, options) => executePostWithCompatibleInput(
|
|
1772
|
+
resolvedConfig,
|
|
1773
|
+
{ endpoint: "/organization/accept-invitation", method: "POST" },
|
|
1774
|
+
input,
|
|
1775
|
+
options
|
|
1776
|
+
),
|
|
1777
|
+
get: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1778
|
+
resolvedConfig,
|
|
1779
|
+
{ endpoint: "/organization/get-invitation", method: "GET" },
|
|
1780
|
+
input,
|
|
1781
|
+
options
|
|
1782
|
+
),
|
|
1783
|
+
reject: (input, options) => executePostWithCompatibleInput(
|
|
1784
|
+
resolvedConfig,
|
|
1785
|
+
{ endpoint: "/organization/reject-invitation", method: "POST" },
|
|
1786
|
+
input,
|
|
1787
|
+
options
|
|
1788
|
+
),
|
|
1789
|
+
list: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1790
|
+
resolvedConfig,
|
|
1791
|
+
{ endpoint: "/organization/list-invitations", method: "GET" },
|
|
1792
|
+
input,
|
|
1793
|
+
options
|
|
1794
|
+
)
|
|
1795
|
+
},
|
|
1796
|
+
member: {
|
|
1797
|
+
remove: (input, options) => executePostWithCompatibleInput(
|
|
1798
|
+
resolvedConfig,
|
|
1799
|
+
{ endpoint: "/organization/remove-member", method: "POST" },
|
|
1800
|
+
input,
|
|
1801
|
+
options
|
|
1802
|
+
),
|
|
1803
|
+
updateRole: (input, options) => executePostWithCompatibleInput(
|
|
1804
|
+
resolvedConfig,
|
|
1805
|
+
{ endpoint: "/organization/update-member-role", method: "POST" },
|
|
1806
|
+
input,
|
|
1807
|
+
options
|
|
1808
|
+
),
|
|
1809
|
+
invite: (input, options) => executePostWithCompatibleInput(
|
|
1810
|
+
resolvedConfig,
|
|
1811
|
+
{ endpoint: "/organization/invite-member", method: "POST" },
|
|
1812
|
+
input,
|
|
1813
|
+
options
|
|
1814
|
+
),
|
|
1815
|
+
getActive: (input, options) => executeGetWithCompatibleInput(
|
|
1816
|
+
resolvedConfig,
|
|
1817
|
+
{ endpoint: "/organization/get-active-member", method: "GET" },
|
|
1818
|
+
input,
|
|
1819
|
+
options
|
|
1820
|
+
),
|
|
1821
|
+
list: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1822
|
+
resolvedConfig,
|
|
1823
|
+
{ endpoint: "/organization/list-members", method: "GET" },
|
|
1824
|
+
input,
|
|
1825
|
+
options
|
|
1826
|
+
)
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
const authResetPassword = Object.assign(
|
|
1830
|
+
(input, options) => executePostWithCompatibleInput(
|
|
1831
|
+
resolvedConfig,
|
|
1832
|
+
{ endpoint: "/reset-password", method: "POST" },
|
|
1833
|
+
input,
|
|
1834
|
+
options
|
|
1835
|
+
),
|
|
1836
|
+
{
|
|
1837
|
+
token: resolveResetPasswordToken
|
|
1838
|
+
}
|
|
1839
|
+
);
|
|
1840
|
+
const sessionRevokeBinding = (input, options) => {
|
|
1841
|
+
if (Array.isArray(input)) {
|
|
1842
|
+
if (input.length === 0) {
|
|
1843
|
+
throw new Error("session.revoke requires at least one session token");
|
|
1844
|
+
}
|
|
1845
|
+
if (input.length === 1) {
|
|
1846
|
+
return revokeSession(input[0], options);
|
|
1847
|
+
}
|
|
1848
|
+
return revokeSessions(void 0, options);
|
|
1849
|
+
}
|
|
1850
|
+
const parsed = input;
|
|
1851
|
+
const tokens = Array.isArray(parsed.tokens) ? parsed.tokens.filter((token2) => token2.trim().length > 0) : void 0;
|
|
1852
|
+
if (tokens && tokens.length > 1) {
|
|
1853
|
+
return revokeSessions(
|
|
1854
|
+
parsed.fetchOptions ? { fetchOptions: parsed.fetchOptions } : void 0,
|
|
1855
|
+
options
|
|
1856
|
+
);
|
|
1857
|
+
}
|
|
1858
|
+
if (tokens && tokens.length === 1) {
|
|
1859
|
+
return revokeSession(
|
|
1860
|
+
{ token: tokens[0], fetchOptions: parsed.fetchOptions },
|
|
1861
|
+
options
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
const token = parsed.token?.trim();
|
|
1865
|
+
if (!token) {
|
|
1866
|
+
throw new Error("session.revoke requires a non-empty token or a non-empty token list");
|
|
1867
|
+
}
|
|
1868
|
+
return revokeSession(
|
|
1869
|
+
{
|
|
1870
|
+
token,
|
|
1871
|
+
fetchOptions: parsed.fetchOptions
|
|
1872
|
+
},
|
|
1873
|
+
options
|
|
1874
|
+
);
|
|
1875
|
+
};
|
|
1876
|
+
const adminUserSessionRevokeBinding = (input, options) => {
|
|
1877
|
+
const requireUserId = (userId) => {
|
|
1878
|
+
const trimmed = String(userId ?? "").trim();
|
|
1879
|
+
if (!trimmed) {
|
|
1880
|
+
throw new Error("admin.user.session.revoke requires a non-empty userId");
|
|
1881
|
+
}
|
|
1882
|
+
return trimmed;
|
|
1883
|
+
};
|
|
1884
|
+
const requireSinglePluralUserId = (sessions2) => {
|
|
1885
|
+
const uniqueUserIds = [...new Set(sessions2.map((session) => requireUserId(session.userId)))];
|
|
1886
|
+
if (uniqueUserIds.length !== 1) {
|
|
1887
|
+
throw new Error("admin.user.session.revoke requires the same userId across plural payloads");
|
|
1888
|
+
}
|
|
1889
|
+
return { userId: uniqueUserIds[0] };
|
|
1890
|
+
};
|
|
1891
|
+
if (Array.isArray(input)) {
|
|
1892
|
+
if (input.length === 0) {
|
|
1893
|
+
throw new Error("admin.user.session.revoke requires at least one payload item");
|
|
1894
|
+
}
|
|
1895
|
+
if (input.length === 1) {
|
|
1896
|
+
return postGeneric(
|
|
1897
|
+
"/admin/revoke-user-session",
|
|
1898
|
+
{
|
|
1899
|
+
...input[0],
|
|
1900
|
+
userId: requireUserId(input[0].userId)
|
|
1901
|
+
},
|
|
1902
|
+
options
|
|
1903
|
+
);
|
|
1904
|
+
}
|
|
1905
|
+
return postGeneric(
|
|
1906
|
+
"/admin/revoke-user-sessions",
|
|
1907
|
+
requireSinglePluralUserId(input),
|
|
1908
|
+
options
|
|
1909
|
+
);
|
|
1910
|
+
}
|
|
1911
|
+
const parsed = input;
|
|
1912
|
+
const sessions = parsed.sessions;
|
|
1913
|
+
if (sessions && sessions.length === 0) {
|
|
1914
|
+
throw new Error("admin.user.session.revoke requires at least one payload item");
|
|
1915
|
+
}
|
|
1916
|
+
if (sessions && sessions.length === 1) {
|
|
1917
|
+
return postGeneric(
|
|
1918
|
+
"/admin/revoke-user-session",
|
|
1919
|
+
{
|
|
1920
|
+
...sessions[0],
|
|
1921
|
+
userId: requireUserId(sessions[0].userId),
|
|
1922
|
+
fetchOptions: parsed.fetchOptions
|
|
1923
|
+
},
|
|
1924
|
+
options
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
1927
|
+
if (sessions && sessions.length > 1) {
|
|
1928
|
+
return postGeneric(
|
|
1929
|
+
"/admin/revoke-user-sessions",
|
|
1930
|
+
{
|
|
1931
|
+
...requireSinglePluralUserId(sessions),
|
|
1932
|
+
fetchOptions: parsed.fetchOptions
|
|
1933
|
+
},
|
|
1934
|
+
options
|
|
1935
|
+
);
|
|
1936
|
+
}
|
|
1937
|
+
const normalizedUserId = requireUserId(parsed.userId);
|
|
1938
|
+
if (!parsed.sessionToken) {
|
|
1939
|
+
return postGeneric(
|
|
1940
|
+
"/admin/revoke-user-sessions",
|
|
1941
|
+
{
|
|
1942
|
+
userId: normalizedUserId,
|
|
1943
|
+
fetchOptions: parsed.fetchOptions
|
|
1944
|
+
},
|
|
1945
|
+
options
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
return postGeneric(
|
|
1949
|
+
"/admin/revoke-user-session",
|
|
1950
|
+
{
|
|
1951
|
+
...parsed,
|
|
1952
|
+
userId: normalizedUserId
|
|
1953
|
+
},
|
|
1954
|
+
options
|
|
1955
|
+
);
|
|
1956
|
+
};
|
|
1957
|
+
const auth = {
|
|
1958
|
+
getSession: (input, options) => getGeneric("/get-session", input, options),
|
|
1959
|
+
signOut,
|
|
1960
|
+
forgetPassword: (input, options) => postGeneric("/forget-password", input, options),
|
|
1961
|
+
resetPassword: authResetPassword,
|
|
1962
|
+
setPassword: (input, options) => postGeneric("/set-password", input, options),
|
|
1963
|
+
verifyEmail: (input, options) => {
|
|
1964
|
+
const queryInput = {
|
|
1965
|
+
query: {
|
|
1966
|
+
token: input.token,
|
|
1967
|
+
callbackURL: input.callbackURL
|
|
1968
|
+
},
|
|
1969
|
+
fetchOptions: input.fetchOptions
|
|
1970
|
+
};
|
|
1971
|
+
return getWithQuery(
|
|
1972
|
+
"/verify-email",
|
|
1973
|
+
queryInput,
|
|
1974
|
+
options
|
|
1975
|
+
);
|
|
1976
|
+
},
|
|
1977
|
+
sendVerificationEmail: (input, options) => postGeneric("/send-verification-email", input, options),
|
|
1978
|
+
changeEmail: (input, options) => postGeneric("/change-email", input, options),
|
|
1979
|
+
changeEmailVerify: (input, options) => getWithQuery("/change-email/verify", input, options),
|
|
1980
|
+
deleteUserVerify: (input, options) => getWithQuery("/delete-user/verify", input, options),
|
|
1981
|
+
changePassword: (input, options) => postGeneric("/change-password", input, options),
|
|
1982
|
+
user: {
|
|
1983
|
+
update: (input, options) => postGeneric("/update-user", input, options),
|
|
1984
|
+
delete: (input, options) => postGeneric("/delete-user", input, options),
|
|
1985
|
+
email: {
|
|
1986
|
+
list: listUserEmailsWithFallback
|
|
1987
|
+
}
|
|
1988
|
+
},
|
|
1989
|
+
session: {
|
|
1990
|
+
list: (input, options) => getGeneric("/list-sessions", input, options),
|
|
1991
|
+
revoke: sessionRevokeBinding,
|
|
1992
|
+
revokeOther: revokeOtherSessions
|
|
1993
|
+
},
|
|
1994
|
+
social: {
|
|
1995
|
+
link: (input, options) => postGeneric("/link-social", input, options)
|
|
1996
|
+
},
|
|
1997
|
+
account: {
|
|
1998
|
+
list: (input, options) => getGeneric("/list-accounts", input, options),
|
|
1999
|
+
unlink: (input, options) => postGeneric("/unlink-account", input, options)
|
|
2000
|
+
},
|
|
2001
|
+
deleteUser: {
|
|
2002
|
+
callback: deleteUserCallback
|
|
2003
|
+
},
|
|
2004
|
+
refreshToken: (input, options) => postGeneric("/refresh-token", input, options),
|
|
2005
|
+
getAccessToken: (input, options) => postGeneric("/get-access-token", input, options),
|
|
2006
|
+
health: healthWithFallback,
|
|
2007
|
+
ok: (input, options) => getGeneric("/ok", input, options),
|
|
2008
|
+
error: (input, options) => getGeneric("/error", input, options),
|
|
2009
|
+
twoFactor: {
|
|
2010
|
+
getTotpUri: (input, options) => postGeneric("/two-factor/get-totp-uri", input, options),
|
|
2011
|
+
verifyTotp: (input, options) => postGeneric("/two-factor/verify-totp", input, options),
|
|
2012
|
+
sendOtp: (input, options) => postGeneric("/two-factor/send-otp", input, options),
|
|
2013
|
+
verifyOtp: (input, options) => postGeneric("/two-factor/verify-otp", input, options),
|
|
2014
|
+
verifyBackupCode: (input, options) => postGeneric("/two-factor/verify-backup-code", input, options),
|
|
2015
|
+
generateBackupCodes: (input, options) => executePostWithCompatibleInput(
|
|
2016
|
+
resolvedConfig,
|
|
2017
|
+
{ endpoint: "/two-factor/generate-backup-codes", method: "POST" },
|
|
2018
|
+
input,
|
|
2019
|
+
options
|
|
2020
|
+
),
|
|
2021
|
+
enable: (input, options) => postGeneric("/two-factor/enable", input, options),
|
|
2022
|
+
disable: (input, options) => postGeneric("/two-factor/disable", input, options)
|
|
2023
|
+
},
|
|
2024
|
+
passkey: {
|
|
2025
|
+
generateRegisterOptions: (input, options) => getGeneric("/passkey/generate-register-options", input, options),
|
|
2026
|
+
generateAuthenticateOptions: (input, options) => postGeneric("/passkey/generate-authenticate-options", input, options),
|
|
2027
|
+
verifyRegistration: (input, options) => postGeneric("/passkey/verify-registration", input, options),
|
|
2028
|
+
verifyAuthentication: (input, options) => postGeneric("/passkey/verify-authentication", input, options),
|
|
2029
|
+
listUserPasskeys: (input, options) => getGeneric("/passkey/list-user-passkeys", input, options),
|
|
2030
|
+
deletePasskey: (input, options) => postGeneric("/passkey/delete-passkey", input, options),
|
|
2031
|
+
updatePasskey: (input, options) => postGeneric("/passkey/update-passkey", input, options),
|
|
2032
|
+
getRelatedOrigins: (input, options) => getGeneric("/.well-known/webauthn", input, options)
|
|
2033
|
+
},
|
|
2034
|
+
admin: {
|
|
2035
|
+
role: {
|
|
2036
|
+
set: (input, options) => postGeneric("/admin/set-role", input, options)
|
|
2037
|
+
},
|
|
2038
|
+
user: {
|
|
2039
|
+
list: (input, options) => getWithQuery("/admin/list-users", input, options),
|
|
2040
|
+
create: (input, options) => postGeneric("/admin/create-user", input, options),
|
|
2041
|
+
unban: (input, options) => postGeneric("/admin/unban-user", input, options),
|
|
2042
|
+
ban: (input, options) => postGeneric("/admin/ban-user", input, options),
|
|
2043
|
+
impersonate: (input, options) => postGeneric("/admin/impersonate-user", input, options),
|
|
2044
|
+
stopImpersonating: (input, options) => postGeneric("/admin/stop-impersonating", input, options),
|
|
2045
|
+
remove: (input, options) => postGeneric("/admin/remove-user", input, options),
|
|
2046
|
+
setPassword: (input, options) => postGeneric("/admin/set-user-password", input, options),
|
|
2047
|
+
session: {
|
|
2048
|
+
list: (input, options) => postGeneric("/admin/list-user-sessions", input, options),
|
|
2049
|
+
revoke: adminUserSessionRevokeBinding
|
|
2050
|
+
}
|
|
2051
|
+
},
|
|
2052
|
+
hasPermission: (input, options) => postGeneric("/admin/has-permission", input, options),
|
|
2053
|
+
apiKey: {
|
|
2054
|
+
create: (input, options) => postGeneric("/admin/api-key/create", input, options)
|
|
2055
|
+
},
|
|
2056
|
+
athenaClient: {
|
|
2057
|
+
create: (input, options) => postGeneric("/admin/athena-client/create", input, options),
|
|
2058
|
+
list: (input, options) => getWithQuery("/admin/athena-client/list", input, options)
|
|
2059
|
+
},
|
|
2060
|
+
auditLog: {
|
|
2061
|
+
list: (input, options) => getWithQuery("/admin/audit-log/list", input, options)
|
|
2062
|
+
},
|
|
2063
|
+
email: {
|
|
2064
|
+
list: (input, options) => getWithQuery("/admin/email/list", input, options),
|
|
2065
|
+
get: (input, options) => getWithQuery("/admin/email/get", input, options),
|
|
2066
|
+
create: (input, options) => postGeneric("/admin/email/create", input, options),
|
|
2067
|
+
update: (input, options) => postGeneric("/admin/email/update", input, options),
|
|
2068
|
+
delete: (input, options) => postGeneric("/admin/email/delete", input, options),
|
|
2069
|
+
failure: {
|
|
2070
|
+
list: (input, options) => getWithQuery("/admin/email-failure/list", input, options),
|
|
2071
|
+
get: (input, options) => getWithQuery("/admin/email-failure/get", input, options),
|
|
2072
|
+
create: (input, options) => postGeneric("/admin/email-failure/create", input, options),
|
|
2073
|
+
update: (input, options) => postGeneric("/admin/email-failure/update", input, options),
|
|
2074
|
+
delete: (input, options) => postGeneric("/admin/email-failure/delete", input, options)
|
|
2075
|
+
},
|
|
2076
|
+
template: {
|
|
2077
|
+
list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
|
|
2078
|
+
get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
|
|
2079
|
+
create: (input, options) => postGeneric("/admin/email-template/create", input, options),
|
|
2080
|
+
update: (input, options) => postGeneric("/admin/email-template/update", input, options),
|
|
2081
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
|
|
2082
|
+
}
|
|
2083
|
+
},
|
|
2084
|
+
emailTemplate: {
|
|
2085
|
+
get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
|
|
2086
|
+
create: (input, options) => postGeneric("/admin/email-template/create", input, options),
|
|
2087
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
|
|
2088
|
+
list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
|
|
2089
|
+
update: (input, options) => postGeneric("/admin/email-template/update", input, options)
|
|
2090
|
+
}
|
|
2091
|
+
},
|
|
2092
|
+
apiKey: {
|
|
2093
|
+
create: (input, options) => postGeneric("/api-key/create", input, options),
|
|
2094
|
+
get: (input, options) => getWithQuery("/api-key/get", input, options),
|
|
2095
|
+
update: (input, options) => postGeneric("/api-key/update", input, options),
|
|
2096
|
+
delete: (input, options) => postGeneric("/api-key/delete", input, options),
|
|
2097
|
+
list: (input, options) => getWithQuery("/api-key/list", input, options),
|
|
2098
|
+
verify: (input, options) => postGeneric("/api-key/verify", input, options),
|
|
2099
|
+
deleteAllExpired: (input, options) => executePostWithOptionalInput(
|
|
2100
|
+
resolvedConfig,
|
|
2101
|
+
{ endpoint: "/api-key/delete-all-expired-api-keys", method: "POST" },
|
|
2102
|
+
input,
|
|
2103
|
+
options
|
|
2104
|
+
)
|
|
2105
|
+
},
|
|
2106
|
+
signIn: {
|
|
2107
|
+
email: (input, options) => postGeneric("/sign-in/email", input, options),
|
|
2108
|
+
username: (input, options) => postGeneric("/sign-in/username", input, options),
|
|
2109
|
+
social: (input, options) => postGeneric("/sign-in/social", input, options)
|
|
2110
|
+
},
|
|
2111
|
+
signUp: {
|
|
2112
|
+
email: (input, options) => postGeneric("/sign-up/email", input, options)
|
|
2113
|
+
},
|
|
2114
|
+
organization,
|
|
2115
|
+
callback: {
|
|
2116
|
+
provider: (input, options) => {
|
|
2117
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
2118
|
+
const parsed = payload;
|
|
2119
|
+
const provider = String(parsed?.provider ?? "").trim();
|
|
2120
|
+
if (!provider) {
|
|
2121
|
+
throw new Error("callback.provider requires a non-empty provider value");
|
|
2122
|
+
}
|
|
2123
|
+
const code = String(parsed?.code ?? "").trim();
|
|
2124
|
+
const state = String(parsed?.state ?? "").trim();
|
|
2125
|
+
if (!code || !state) {
|
|
2126
|
+
throw new Error("callback.provider requires non-empty code and state values");
|
|
2127
|
+
}
|
|
2128
|
+
const endpoint = `/callback/${encodeURIComponent(provider)}`;
|
|
2129
|
+
return request({
|
|
2130
|
+
endpoint,
|
|
2131
|
+
method: "GET",
|
|
2132
|
+
query: {
|
|
2133
|
+
code,
|
|
2134
|
+
state
|
|
2135
|
+
},
|
|
2136
|
+
fetchOptions
|
|
2137
|
+
}, options);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2141
|
+
return {
|
|
2142
|
+
baseUrl: normalizedBaseUrl,
|
|
2143
|
+
request,
|
|
2144
|
+
signIn: {
|
|
2145
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
2146
|
+
resolvedConfig,
|
|
2147
|
+
{ endpoint: "/sign-in/email", method: "POST" },
|
|
2148
|
+
input,
|
|
2149
|
+
options
|
|
2150
|
+
),
|
|
2151
|
+
username: (input, options) => executePostWithCompatibleInput(
|
|
2152
|
+
resolvedConfig,
|
|
2153
|
+
{ endpoint: "/sign-in/username", method: "POST" },
|
|
2154
|
+
input,
|
|
2155
|
+
options
|
|
2156
|
+
),
|
|
2157
|
+
social: (input, options) => executePostWithCompatibleInput(
|
|
2158
|
+
resolvedConfig,
|
|
2159
|
+
{ endpoint: "/sign-in/social", method: "POST" },
|
|
2160
|
+
input,
|
|
2161
|
+
options
|
|
2162
|
+
)
|
|
2163
|
+
},
|
|
2164
|
+
signUp: {
|
|
2165
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
2166
|
+
resolvedConfig,
|
|
2167
|
+
{ endpoint: "/sign-up/email", method: "POST" },
|
|
2168
|
+
input,
|
|
2169
|
+
options
|
|
2170
|
+
)
|
|
2171
|
+
},
|
|
2172
|
+
signOut,
|
|
2173
|
+
logout: signOut,
|
|
2174
|
+
getSession: (input, options) => executeGetWithCompatibleInput(
|
|
2175
|
+
resolvedConfig,
|
|
2176
|
+
{ endpoint: "/get-session", method: "GET" },
|
|
2177
|
+
input,
|
|
2178
|
+
options
|
|
2179
|
+
),
|
|
2180
|
+
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
2181
|
+
resolvedConfig,
|
|
2182
|
+
{ endpoint: "/list-sessions", method: "GET" },
|
|
2183
|
+
input,
|
|
2184
|
+
options
|
|
2185
|
+
),
|
|
2186
|
+
revokeSession,
|
|
2187
|
+
clearSession: revokeSession,
|
|
2188
|
+
revokeSessions,
|
|
2189
|
+
clearSessions: revokeSessions,
|
|
2190
|
+
revokeOtherSessions,
|
|
2191
|
+
clearOtherSessions: revokeOtherSessions,
|
|
2192
|
+
forgetPassword: (input, options) => executePostWithCompatibleInput(
|
|
2193
|
+
resolvedConfig,
|
|
2194
|
+
{ endpoint: "/forget-password", method: "POST" },
|
|
2195
|
+
input,
|
|
2196
|
+
options
|
|
2197
|
+
),
|
|
2198
|
+
resetPassword: (input, options) => executePostWithCompatibleInput(
|
|
2199
|
+
resolvedConfig,
|
|
2200
|
+
{ endpoint: "/reset-password", method: "POST" },
|
|
2201
|
+
input,
|
|
2202
|
+
options
|
|
2203
|
+
),
|
|
2204
|
+
resolveResetPasswordToken,
|
|
2205
|
+
verifyEmail: (input, options) => {
|
|
2206
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
2207
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
2208
|
+
const query = payload;
|
|
2209
|
+
return callAuthEndpoint(
|
|
2210
|
+
resolvedConfig,
|
|
2211
|
+
{ endpoint: "/verify-email", method: "GET" },
|
|
2212
|
+
void 0,
|
|
2213
|
+
query ? {
|
|
2214
|
+
token: query.token,
|
|
2215
|
+
callbackURL: query.callbackURL
|
|
2216
|
+
} : void 0,
|
|
2217
|
+
mergedOptions
|
|
2218
|
+
);
|
|
2219
|
+
},
|
|
2220
|
+
sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
|
|
2221
|
+
resolvedConfig,
|
|
2222
|
+
{ endpoint: "/send-verification-email", method: "POST" },
|
|
2223
|
+
input,
|
|
2224
|
+
options
|
|
2225
|
+
),
|
|
2226
|
+
changeEmail: (input, options) => executePostWithCompatibleInput(
|
|
2227
|
+
resolvedConfig,
|
|
2228
|
+
{ endpoint: "/change-email", method: "POST" },
|
|
2229
|
+
input,
|
|
2230
|
+
options
|
|
2231
|
+
),
|
|
2232
|
+
changePassword: (input, options) => executePostWithCompatibleInput(
|
|
2233
|
+
resolvedConfig,
|
|
2234
|
+
{ endpoint: "/change-password", method: "POST" },
|
|
2235
|
+
input,
|
|
2236
|
+
options
|
|
2237
|
+
),
|
|
2238
|
+
updateUser: (input, options) => executePostWithCompatibleInput(
|
|
2239
|
+
resolvedConfig,
|
|
2240
|
+
{ endpoint: "/update-user", method: "POST" },
|
|
2241
|
+
input,
|
|
2242
|
+
options
|
|
2243
|
+
),
|
|
2244
|
+
deleteUser,
|
|
2245
|
+
deleteUserCallback,
|
|
2246
|
+
linkSocial: (input, options) => executePostWithCompatibleInput(
|
|
2247
|
+
resolvedConfig,
|
|
2248
|
+
{ endpoint: "/link-social", method: "POST" },
|
|
2249
|
+
input,
|
|
2250
|
+
options
|
|
2251
|
+
),
|
|
2252
|
+
listAccounts: (input, options) => executeGetWithCompatibleInput(
|
|
2253
|
+
resolvedConfig,
|
|
2254
|
+
{ endpoint: "/list-accounts", method: "GET" },
|
|
2255
|
+
input,
|
|
2256
|
+
options
|
|
2257
|
+
),
|
|
2258
|
+
unlinkAccount: (input, options) => executePostWithCompatibleInput(
|
|
2259
|
+
resolvedConfig,
|
|
2260
|
+
{ endpoint: "/unlink-account", method: "POST" },
|
|
2261
|
+
input,
|
|
2262
|
+
options
|
|
2263
|
+
),
|
|
2264
|
+
refreshToken: (input, options) => executePostWithCompatibleInput(
|
|
2265
|
+
resolvedConfig,
|
|
2266
|
+
{ endpoint: "/refresh-token", method: "POST" },
|
|
2267
|
+
input,
|
|
2268
|
+
options
|
|
2269
|
+
),
|
|
2270
|
+
getAccessToken: (input, options) => executePostWithCompatibleInput(
|
|
2271
|
+
resolvedConfig,
|
|
2272
|
+
{ endpoint: "/get-access-token", method: "POST" },
|
|
2273
|
+
input,
|
|
2274
|
+
options
|
|
2275
|
+
),
|
|
2276
|
+
organization,
|
|
2277
|
+
auth
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
|
|
1203
2281
|
// src/client.ts
|
|
1204
2282
|
var DEFAULT_COLUMNS = "*";
|
|
1205
2283
|
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
@@ -1231,6 +2309,12 @@ function mergeOptions(...options) {
|
|
|
1231
2309
|
return { ...acc, ...next };
|
|
1232
2310
|
}, void 0);
|
|
1233
2311
|
}
|
|
2312
|
+
function asAthenaJsonObject(value) {
|
|
2313
|
+
return value;
|
|
2314
|
+
}
|
|
2315
|
+
function asAthenaJsonObjectArray(values) {
|
|
2316
|
+
return values;
|
|
2317
|
+
}
|
|
1234
2318
|
function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS) {
|
|
1235
2319
|
let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
|
|
1236
2320
|
let selectedOptions;
|
|
@@ -1319,6 +2403,22 @@ function buildSelectColumnsClause(columns) {
|
|
|
1319
2403
|
}
|
|
1320
2404
|
return quoteSelectColumnsExpression(columns);
|
|
1321
2405
|
}
|
|
2406
|
+
function resolveTableNameForCall(tableName, schema) {
|
|
2407
|
+
if (!schema) return tableName;
|
|
2408
|
+
const normalizedSchema = schema.trim();
|
|
2409
|
+
if (!normalizedSchema) {
|
|
2410
|
+
throw new Error("schema option must be a non-empty string");
|
|
2411
|
+
}
|
|
2412
|
+
if (tableName.includes(".")) {
|
|
2413
|
+
if (tableName.startsWith(`${normalizedSchema}.`)) {
|
|
2414
|
+
return tableName;
|
|
2415
|
+
}
|
|
2416
|
+
throw new Error(
|
|
2417
|
+
`schema option "${normalizedSchema}" conflicts with schema-qualified table "${tableName}"`
|
|
2418
|
+
);
|
|
2419
|
+
}
|
|
2420
|
+
return `${normalizedSchema}.${tableName}`;
|
|
2421
|
+
}
|
|
1322
2422
|
function conditionToSqlClause(condition) {
|
|
1323
2423
|
if (!condition.column) return null;
|
|
1324
2424
|
const column = withCast(quoteQualifiedIdentifier(condition.column), condition.column_cast);
|
|
@@ -1398,23 +2498,27 @@ function buildTypedSelectQuery(input) {
|
|
|
1398
2498
|
function createFilterMethods(state, addCondition, self) {
|
|
1399
2499
|
return {
|
|
1400
2500
|
eq(column, value) {
|
|
1401
|
-
|
|
1402
|
-
|
|
2501
|
+
const columnName = String(column);
|
|
2502
|
+
if (shouldUseUuidTextComparison(columnName, value)) {
|
|
2503
|
+
addCondition("eq", columnName, value, { columnCast: "text" });
|
|
1403
2504
|
} else {
|
|
1404
|
-
addCondition("eq",
|
|
2505
|
+
addCondition("eq", columnName, value);
|
|
1405
2506
|
}
|
|
1406
2507
|
return self;
|
|
1407
2508
|
},
|
|
1408
2509
|
eqCast(column, value, cast) {
|
|
1409
|
-
addCondition("eq", column, value, { valueCast: cast });
|
|
2510
|
+
addCondition("eq", String(column), value, { valueCast: cast });
|
|
1410
2511
|
return self;
|
|
1411
2512
|
},
|
|
1412
2513
|
eqUuid(column, value) {
|
|
1413
|
-
addCondition("eq", column, value, { valueCast: "uuid" });
|
|
2514
|
+
addCondition("eq", String(column), value, { valueCast: "uuid" });
|
|
1414
2515
|
return self;
|
|
1415
2516
|
},
|
|
1416
2517
|
match(filters) {
|
|
1417
2518
|
Object.entries(filters).forEach(([column, value]) => {
|
|
2519
|
+
if (value === void 0) {
|
|
2520
|
+
return;
|
|
2521
|
+
}
|
|
1418
2522
|
if (shouldUseUuidTextComparison(column, value)) {
|
|
1419
2523
|
addCondition("eq", column, value, { columnCast: "text" });
|
|
1420
2524
|
} else {
|
|
@@ -1450,60 +2554,61 @@ function createFilterMethods(state, addCondition, self) {
|
|
|
1450
2554
|
},
|
|
1451
2555
|
order(column, options) {
|
|
1452
2556
|
state.order = {
|
|
1453
|
-
field: column,
|
|
2557
|
+
field: String(column),
|
|
1454
2558
|
direction: options?.ascending === false ? "descending" : "ascending"
|
|
1455
2559
|
};
|
|
1456
2560
|
return self;
|
|
1457
2561
|
},
|
|
1458
2562
|
gt(column, value) {
|
|
1459
|
-
addCondition("gt", column, value);
|
|
2563
|
+
addCondition("gt", String(column), value);
|
|
1460
2564
|
return self;
|
|
1461
2565
|
},
|
|
1462
2566
|
gte(column, value) {
|
|
1463
|
-
addCondition("gte", column, value);
|
|
2567
|
+
addCondition("gte", String(column), value);
|
|
1464
2568
|
return self;
|
|
1465
2569
|
},
|
|
1466
2570
|
lt(column, value) {
|
|
1467
|
-
addCondition("lt", column, value);
|
|
2571
|
+
addCondition("lt", String(column), value);
|
|
1468
2572
|
return self;
|
|
1469
2573
|
},
|
|
1470
2574
|
lte(column, value) {
|
|
1471
|
-
addCondition("lte", column, value);
|
|
2575
|
+
addCondition("lte", String(column), value);
|
|
1472
2576
|
return self;
|
|
1473
2577
|
},
|
|
1474
2578
|
neq(column, value) {
|
|
1475
|
-
addCondition("neq", column, value);
|
|
2579
|
+
addCondition("neq", String(column), value);
|
|
1476
2580
|
return self;
|
|
1477
2581
|
},
|
|
1478
2582
|
like(column, value) {
|
|
1479
|
-
addCondition("like", column, value);
|
|
2583
|
+
addCondition("like", String(column), value);
|
|
1480
2584
|
return self;
|
|
1481
2585
|
},
|
|
1482
2586
|
ilike(column, value) {
|
|
1483
|
-
addCondition("ilike", column, value);
|
|
2587
|
+
addCondition("ilike", String(column), value);
|
|
1484
2588
|
return self;
|
|
1485
2589
|
},
|
|
1486
2590
|
is(column, value) {
|
|
1487
|
-
addCondition("is", column, value);
|
|
2591
|
+
addCondition("is", String(column), value);
|
|
1488
2592
|
return self;
|
|
1489
2593
|
},
|
|
1490
2594
|
in(column, values) {
|
|
1491
|
-
addCondition("in", column, values);
|
|
2595
|
+
addCondition("in", String(column), values);
|
|
1492
2596
|
return self;
|
|
1493
2597
|
},
|
|
1494
2598
|
contains(column, values) {
|
|
1495
|
-
addCondition("contains", column, values);
|
|
2599
|
+
addCondition("contains", String(column), values);
|
|
1496
2600
|
return self;
|
|
1497
2601
|
},
|
|
1498
2602
|
containedBy(column, values) {
|
|
1499
|
-
addCondition("containedBy", column, values);
|
|
2603
|
+
addCondition("containedBy", String(column), values);
|
|
1500
2604
|
return self;
|
|
1501
2605
|
},
|
|
1502
2606
|
not(columnOrExpression, operator, value) {
|
|
2607
|
+
const expression = String(columnOrExpression);
|
|
1503
2608
|
if (operator != null && value !== void 0) {
|
|
1504
|
-
addCondition("not", void 0, `${
|
|
2609
|
+
addCondition("not", void 0, `${expression}.${operator}.${stringifyFilterValue(value)}`);
|
|
1505
2610
|
} else {
|
|
1506
|
-
addCondition("not", void 0,
|
|
2611
|
+
addCondition("not", void 0, expression);
|
|
1507
2612
|
}
|
|
1508
2613
|
return self;
|
|
1509
2614
|
},
|
|
@@ -1673,15 +2778,20 @@ function createTableBuilder(tableName, client) {
|
|
|
1673
2778
|
state.conditions.push(condition);
|
|
1674
2779
|
};
|
|
1675
2780
|
const builder = {};
|
|
1676
|
-
const filterMethods = createFilterMethods(
|
|
2781
|
+
const filterMethods = createFilterMethods(
|
|
2782
|
+
state,
|
|
2783
|
+
addCondition,
|
|
2784
|
+
builder
|
|
2785
|
+
);
|
|
1677
2786
|
const runSelect = async (columns = DEFAULT_COLUMNS, options) => {
|
|
2787
|
+
const resolvedTableName = resolveTableNameForCall(tableName, options?.schema);
|
|
1678
2788
|
const conditions = state.conditions.length ? state.conditions.map((condition) => ({ ...condition })) : void 0;
|
|
1679
2789
|
const hasTypedEqualityComparison = conditions?.some(
|
|
1680
2790
|
(condition) => condition.operator === "eq" && (condition.value_cast !== void 0 || condition.column_cast !== void 0)
|
|
1681
2791
|
) ?? false;
|
|
1682
2792
|
if (hasTypedEqualityComparison && !options?.head && !options?.count && conditions) {
|
|
1683
2793
|
const query = buildTypedSelectQuery({
|
|
1684
|
-
tableName,
|
|
2794
|
+
tableName: resolvedTableName,
|
|
1685
2795
|
columns,
|
|
1686
2796
|
conditions,
|
|
1687
2797
|
limit: state.limit,
|
|
@@ -1696,7 +2806,7 @@ function createTableBuilder(tableName, client) {
|
|
|
1696
2806
|
}
|
|
1697
2807
|
}
|
|
1698
2808
|
const payload = {
|
|
1699
|
-
table_name:
|
|
2809
|
+
table_name: resolvedTableName,
|
|
1700
2810
|
columns,
|
|
1701
2811
|
conditions,
|
|
1702
2812
|
limit: state.limit,
|
|
@@ -1753,9 +2863,10 @@ function createTableBuilder(tableName, client) {
|
|
|
1753
2863
|
if (Array.isArray(values)) {
|
|
1754
2864
|
const executeInsertMany = async (columns, selectOptions) => {
|
|
1755
2865
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2866
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1756
2867
|
const payload = {
|
|
1757
|
-
table_name:
|
|
1758
|
-
insert_body: values
|
|
2868
|
+
table_name: resolvedTableName,
|
|
2869
|
+
insert_body: asAthenaJsonObjectArray(values)
|
|
1759
2870
|
};
|
|
1760
2871
|
if (columns) payload.columns = columns;
|
|
1761
2872
|
if (mergedOptions?.count) payload.count = mergedOptions.count;
|
|
@@ -1770,9 +2881,10 @@ function createTableBuilder(tableName, client) {
|
|
|
1770
2881
|
}
|
|
1771
2882
|
const executeInsertOne = async (columns, selectOptions) => {
|
|
1772
2883
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2884
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1773
2885
|
const payload = {
|
|
1774
|
-
table_name:
|
|
1775
|
-
insert_body: values
|
|
2886
|
+
table_name: resolvedTableName,
|
|
2887
|
+
insert_body: asAthenaJsonObject(values)
|
|
1776
2888
|
};
|
|
1777
2889
|
if (columns) payload.columns = columns;
|
|
1778
2890
|
if (mergedOptions?.count) payload.count = mergedOptions.count;
|
|
@@ -1789,10 +2901,11 @@ function createTableBuilder(tableName, client) {
|
|
|
1789
2901
|
if (Array.isArray(values)) {
|
|
1790
2902
|
const executeUpsertMany = async (columns, selectOptions) => {
|
|
1791
2903
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2904
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1792
2905
|
const payload = {
|
|
1793
|
-
table_name:
|
|
1794
|
-
insert_body: values,
|
|
1795
|
-
update_body: options?.updateBody ? options.updateBody : void 0
|
|
2906
|
+
table_name: resolvedTableName,
|
|
2907
|
+
insert_body: asAthenaJsonObjectArray(values),
|
|
2908
|
+
update_body: options?.updateBody ? asAthenaJsonObject(options.updateBody) : void 0
|
|
1796
2909
|
};
|
|
1797
2910
|
if (columns) payload.columns = columns;
|
|
1798
2911
|
if (options?.onConflict) payload.on_conflict = options.onConflict;
|
|
@@ -1808,10 +2921,11 @@ function createTableBuilder(tableName, client) {
|
|
|
1808
2921
|
}
|
|
1809
2922
|
const executeUpsertOne = async (columns, selectOptions) => {
|
|
1810
2923
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2924
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1811
2925
|
const payload = {
|
|
1812
|
-
table_name:
|
|
1813
|
-
insert_body: values,
|
|
1814
|
-
update_body: options?.updateBody ? options.updateBody : void 0
|
|
2926
|
+
table_name: resolvedTableName,
|
|
2927
|
+
insert_body: asAthenaJsonObject(values),
|
|
2928
|
+
update_body: options?.updateBody ? asAthenaJsonObject(options.updateBody) : void 0
|
|
1815
2929
|
};
|
|
1816
2930
|
if (columns) payload.columns = columns;
|
|
1817
2931
|
if (options?.onConflict) payload.on_conflict = options.onConflict;
|
|
@@ -1829,9 +2943,10 @@ function createTableBuilder(tableName, client) {
|
|
|
1829
2943
|
const executeUpdate = async (columns, selectOptions) => {
|
|
1830
2944
|
const filters = state.conditions.length ? [...state.conditions] : void 0;
|
|
1831
2945
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2946
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1832
2947
|
const payload = {
|
|
1833
|
-
table_name:
|
|
1834
|
-
set: values,
|
|
2948
|
+
table_name: resolvedTableName,
|
|
2949
|
+
set: asAthenaJsonObject(values),
|
|
1835
2950
|
conditions: filters,
|
|
1836
2951
|
strip_nulls: mergedOptions?.stripNulls ?? true
|
|
1837
2952
|
};
|
|
@@ -1857,8 +2972,9 @@ function createTableBuilder(tableName, client) {
|
|
|
1857
2972
|
}
|
|
1858
2973
|
const executeDelete = async (columns, selectOptions) => {
|
|
1859
2974
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2975
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1860
2976
|
const payload = {
|
|
1861
|
-
table_name:
|
|
2977
|
+
table_name: resolvedTableName,
|
|
1862
2978
|
resource_id: resourceId,
|
|
1863
2979
|
conditions: filters
|
|
1864
2980
|
};
|
|
@@ -1900,6 +3016,7 @@ function createClientFromConfig(config) {
|
|
|
1900
3016
|
backend: config.backend,
|
|
1901
3017
|
headers: config.headers
|
|
1902
3018
|
});
|
|
3019
|
+
const auth = createAuthClient(config.auth);
|
|
1903
3020
|
return {
|
|
1904
3021
|
from(table) {
|
|
1905
3022
|
return createTableBuilder(table, gateway);
|
|
@@ -1916,7 +3033,8 @@ function createClientFromConfig(config) {
|
|
|
1916
3033
|
gateway
|
|
1917
3034
|
);
|
|
1918
3035
|
},
|
|
1919
|
-
query: createQueryBuilder(gateway)
|
|
3036
|
+
query: createQueryBuilder(gateway),
|
|
3037
|
+
auth: auth.auth
|
|
1920
3038
|
};
|
|
1921
3039
|
}
|
|
1922
3040
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
@@ -1990,7 +3108,11 @@ function createClient(url, apiKey, options) {
|
|
|
1990
3108
|
const b = AthenaClient.builder().url(url).key(apiKey).backend(toBackendConfig(options?.backend));
|
|
1991
3109
|
if (options?.client) b.client(options.client);
|
|
1992
3110
|
if (options?.headers && Object.keys(options.headers).length > 0) b.headers(options.headers);
|
|
1993
|
-
|
|
3111
|
+
const client = b.build();
|
|
3112
|
+
if (options?.auth) {
|
|
3113
|
+
client.auth = createAuthClient(options.auth).auth;
|
|
3114
|
+
}
|
|
3115
|
+
return client;
|
|
1994
3116
|
}
|
|
1995
3117
|
|
|
1996
3118
|
// src/schema/postgres-introspection-core.ts
|