@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/index.js
CHANGED
|
@@ -501,544 +501,1614 @@ function identifier(...segments) {
|
|
|
501
501
|
return new SqlIdentifierPath(expandedSegments);
|
|
502
502
|
}
|
|
503
503
|
|
|
504
|
-
// src/client.ts
|
|
505
|
-
var
|
|
506
|
-
var
|
|
507
|
-
var
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
504
|
+
// src/auth/client.ts
|
|
505
|
+
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
506
|
+
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
507
|
+
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
508
|
+
var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
|
|
509
|
+
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
510
|
+
function normalizeBaseUrl(baseUrl) {
|
|
511
|
+
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
512
|
+
}
|
|
513
|
+
function isRecord2(value) {
|
|
514
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
515
|
+
}
|
|
516
|
+
function normalizeHeaderValue2(value) {
|
|
517
|
+
return value ? value : void 0;
|
|
518
|
+
}
|
|
519
|
+
function parseResponseBody2(rawText, contentType) {
|
|
520
|
+
if (!rawText) {
|
|
521
|
+
return { parsed: null, parseFailed: false };
|
|
522
|
+
}
|
|
523
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
524
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
525
|
+
if (!looksJson) {
|
|
526
|
+
return { parsed: rawText, parseFailed: false };
|
|
527
|
+
}
|
|
528
|
+
try {
|
|
529
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
530
|
+
} catch {
|
|
531
|
+
return { parsed: rawText, parseFailed: true };
|
|
518
532
|
}
|
|
519
|
-
return result;
|
|
520
533
|
}
|
|
521
|
-
function
|
|
522
|
-
|
|
523
|
-
|
|
534
|
+
function resolveRequestId2(headers) {
|
|
535
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
536
|
+
}
|
|
537
|
+
function resolveErrorMessage2(payload, fallback) {
|
|
538
|
+
if (isRecord2(payload)) {
|
|
539
|
+
const messageCandidates = [payload.error, payload.message, payload.details];
|
|
540
|
+
for (const candidate of messageCandidates) {
|
|
541
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
542
|
+
return candidate.trim();
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
547
|
+
return payload.trim();
|
|
548
|
+
}
|
|
549
|
+
return fallback;
|
|
550
|
+
}
|
|
551
|
+
function toErrorDetails(input) {
|
|
524
552
|
return {
|
|
525
|
-
|
|
526
|
-
|
|
553
|
+
code: input.code,
|
|
554
|
+
message: input.message,
|
|
555
|
+
status: input.status,
|
|
556
|
+
endpoint: input.endpoint,
|
|
557
|
+
method: input.method,
|
|
558
|
+
requestId: input.requestId,
|
|
559
|
+
hint: input.hint,
|
|
560
|
+
cause: input.cause
|
|
527
561
|
};
|
|
528
562
|
}
|
|
529
|
-
function
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
let selectedOptions;
|
|
538
|
-
let promise = null;
|
|
539
|
-
const run = (columns, options) => {
|
|
540
|
-
const payloadColumns = columns ?? selectedColumns;
|
|
541
|
-
const payloadOptions = options ?? selectedOptions;
|
|
542
|
-
if (!promise) {
|
|
543
|
-
promise = executor(payloadColumns, payloadOptions);
|
|
563
|
+
function mergeCallOptions(base, override) {
|
|
564
|
+
if (!base && !override) return void 0;
|
|
565
|
+
return {
|
|
566
|
+
...base,
|
|
567
|
+
...override,
|
|
568
|
+
headers: {
|
|
569
|
+
...base?.headers ?? {},
|
|
570
|
+
...override?.headers ?? {}
|
|
544
571
|
}
|
|
545
|
-
return promise;
|
|
546
572
|
};
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
},
|
|
561
|
-
maybeSingle(columns = selectedColumns, options) {
|
|
562
|
-
return mutationQuery.single(columns, options);
|
|
563
|
-
},
|
|
564
|
-
then(onfulfilled, onrejected) {
|
|
565
|
-
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
566
|
-
},
|
|
567
|
-
catch(onrejected) {
|
|
568
|
-
return run(selectedColumns, selectedOptions).catch(onrejected);
|
|
569
|
-
},
|
|
570
|
-
finally(onfinally) {
|
|
571
|
-
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
572
|
-
}
|
|
573
|
+
}
|
|
574
|
+
function extractFetchOptions(input) {
|
|
575
|
+
if (!input) {
|
|
576
|
+
return {
|
|
577
|
+
payload: void 0,
|
|
578
|
+
fetchOptions: void 0
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
const { fetchOptions, ...rest } = input;
|
|
582
|
+
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
583
|
+
return {
|
|
584
|
+
payload: hasPayloadKeys ? rest : void 0,
|
|
585
|
+
fetchOptions
|
|
573
586
|
};
|
|
574
|
-
return mutationQuery;
|
|
575
587
|
}
|
|
576
|
-
function
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
588
|
+
function buildHeaders2(config, options) {
|
|
589
|
+
const headers = {
|
|
590
|
+
"Content-Type": "application/json",
|
|
591
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
592
|
+
};
|
|
593
|
+
const apiKey = options?.apiKey ?? config.apiKey;
|
|
594
|
+
if (apiKey) {
|
|
595
|
+
headers.apikey = apiKey;
|
|
596
|
+
headers["x-api-key"] = apiKey;
|
|
597
|
+
}
|
|
598
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
599
|
+
if (bearerToken) {
|
|
600
|
+
headers.Authorization = `Bearer ${bearerToken}`;
|
|
601
|
+
}
|
|
602
|
+
const mergedExtraHeaders = {
|
|
603
|
+
...config.headers ?? {},
|
|
604
|
+
...options?.headers ?? {}
|
|
605
|
+
};
|
|
606
|
+
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
607
|
+
const normalized = normalizeHeaderValue2(value);
|
|
608
|
+
if (normalized) {
|
|
609
|
+
headers[key] = normalized;
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
return headers;
|
|
581
613
|
}
|
|
582
|
-
function
|
|
614
|
+
function appendQueryParam(searchParams, key, value) {
|
|
615
|
+
if (value === void 0 || value === null) return;
|
|
583
616
|
if (Array.isArray(value)) {
|
|
584
|
-
|
|
617
|
+
value.forEach((item) => {
|
|
618
|
+
searchParams.append(key, String(item));
|
|
619
|
+
});
|
|
620
|
+
return;
|
|
585
621
|
}
|
|
586
|
-
|
|
587
|
-
}
|
|
588
|
-
function isUuidString(value) {
|
|
589
|
-
return UUID_PATTERN.test(value.trim());
|
|
590
|
-
}
|
|
591
|
-
function isUuidIdentifierColumn(column) {
|
|
592
|
-
return column === "id" || /(?:^|_)uuid(?:_|$)/i.test(column) || /_id$/i.test(column);
|
|
622
|
+
searchParams.append(key, String(value));
|
|
593
623
|
}
|
|
594
|
-
function
|
|
595
|
-
|
|
624
|
+
function buildRequestUrl(baseUrl, endpoint, query) {
|
|
625
|
+
const url = `${baseUrl}${endpoint}`;
|
|
626
|
+
if (!query || Object.keys(query).length === 0) return url;
|
|
627
|
+
const searchParams = new URLSearchParams();
|
|
628
|
+
Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
|
|
629
|
+
const queryText = searchParams.toString();
|
|
630
|
+
return queryText ? `${url}?${queryText}` : url;
|
|
596
631
|
}
|
|
597
|
-
function
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
throw new Error(`Invalid cast type "${cast}"`);
|
|
632
|
+
function inferDefaultMethod(endpoint) {
|
|
633
|
+
if (endpoint.startsWith("/reset-password/")) {
|
|
634
|
+
return "GET";
|
|
601
635
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
636
|
+
switch (endpoint) {
|
|
637
|
+
case "/get-session":
|
|
638
|
+
case "/list-sessions":
|
|
639
|
+
case "/verify-email":
|
|
640
|
+
case "/change-email/verify":
|
|
641
|
+
case "/delete-user/verify":
|
|
642
|
+
case "/email-list":
|
|
643
|
+
case "/email/list":
|
|
644
|
+
case "/delete-user/callback":
|
|
645
|
+
case "/list-accounts":
|
|
646
|
+
case "/passkey/generate-register-options":
|
|
647
|
+
case "/passkey/list-user-passkeys":
|
|
648
|
+
case "/.well-known/webauthn":
|
|
649
|
+
case "/admin/list-users":
|
|
650
|
+
case "/admin/athena-client/list":
|
|
651
|
+
case "/admin/audit-log/list":
|
|
652
|
+
case "/admin/email/get":
|
|
653
|
+
case "/admin/email-failure/list":
|
|
654
|
+
case "/admin/email-failure/get":
|
|
655
|
+
case "/admin/email-template/get":
|
|
656
|
+
case "/admin/email-template/list":
|
|
657
|
+
case "/admin/email/list":
|
|
658
|
+
case "/api-key/get":
|
|
659
|
+
case "/api-key/list":
|
|
660
|
+
case "/organization/get-full-organization":
|
|
661
|
+
case "/organization/list":
|
|
662
|
+
case "/organization/get-invitation":
|
|
663
|
+
case "/organization/list-invitations":
|
|
664
|
+
case "/organization/list-user-invitations":
|
|
665
|
+
case "/organization/list-members":
|
|
666
|
+
case "/organization/get-active-member":
|
|
667
|
+
case "/health":
|
|
668
|
+
case "/ok":
|
|
669
|
+
case "/error":
|
|
670
|
+
return "GET";
|
|
671
|
+
default:
|
|
672
|
+
return "POST";
|
|
620
673
|
}
|
|
621
|
-
return quoteSelectColumnsExpression(columns);
|
|
622
674
|
}
|
|
623
|
-
function
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
const
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
lte: "<=",
|
|
634
|
-
like: "LIKE",
|
|
635
|
-
ilike: "ILIKE"
|
|
675
|
+
async function callAuthEndpoint(config, context, body, query, options) {
|
|
676
|
+
const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
677
|
+
const url = buildRequestUrl(baseUrl, context.endpoint, query);
|
|
678
|
+
const headers = buildHeaders2(config, options);
|
|
679
|
+
const credentials = options?.credentials ?? config.credentials ?? "include";
|
|
680
|
+
const requestInit = {
|
|
681
|
+
method: context.method,
|
|
682
|
+
headers,
|
|
683
|
+
credentials,
|
|
684
|
+
signal: options?.signal
|
|
636
685
|
};
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
case "neq":
|
|
640
|
-
case "gt":
|
|
641
|
-
case "gte":
|
|
642
|
-
case "lt":
|
|
643
|
-
case "lte":
|
|
644
|
-
case "like":
|
|
645
|
-
case "ilike": {
|
|
646
|
-
if (Array.isArray(value) || value === void 0) return null;
|
|
647
|
-
const rhs = withCast(toSqlLiteral(value), condition.value_cast);
|
|
648
|
-
return `${column} ${sqlOperator[condition.operator]} ${rhs}`;
|
|
649
|
-
}
|
|
650
|
-
case "is": {
|
|
651
|
-
if (value === null) return `${column} IS NULL`;
|
|
652
|
-
if (value === true) return `${column} IS TRUE`;
|
|
653
|
-
if (value === false) return `${column} IS FALSE`;
|
|
654
|
-
return null;
|
|
655
|
-
}
|
|
656
|
-
case "in": {
|
|
657
|
-
if (!Array.isArray(value)) return null;
|
|
658
|
-
if (value.length === 0) return "FALSE";
|
|
659
|
-
const values = value.map((item) => withCast(toSqlLiteral(item), condition.value_cast));
|
|
660
|
-
return `${column} IN (${values.join(", ")})`;
|
|
661
|
-
}
|
|
662
|
-
default:
|
|
663
|
-
return null;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
function buildTypedSelectQuery(input) {
|
|
667
|
-
const whereClauses = [];
|
|
668
|
-
for (const condition of input.conditions) {
|
|
669
|
-
const clause = conditionToSqlClause(condition);
|
|
670
|
-
if (!clause) return null;
|
|
671
|
-
whereClauses.push(clause);
|
|
672
|
-
}
|
|
673
|
-
let limit = input.limit;
|
|
674
|
-
let offset = input.offset;
|
|
675
|
-
if (limit === void 0 && input.pageSize !== void 0) {
|
|
676
|
-
limit = input.pageSize;
|
|
677
|
-
}
|
|
678
|
-
if (offset === void 0 && input.pageSize !== void 0 && input.currentPage !== void 0 && input.currentPage > 0) {
|
|
679
|
-
offset = (input.currentPage - 1) * input.pageSize;
|
|
680
|
-
}
|
|
681
|
-
const sqlParts = [
|
|
682
|
-
`SELECT ${buildSelectColumnsClause(input.columns)} FROM ${quoteQualifiedIdentifier(input.tableName)}`
|
|
683
|
-
];
|
|
684
|
-
if (whereClauses.length > 0) {
|
|
685
|
-
sqlParts.push(`WHERE ${whereClauses.join(" AND ")}`);
|
|
686
|
-
}
|
|
687
|
-
if (input.order?.field) {
|
|
688
|
-
const direction = input.order.direction === "descending" ? "DESC" : "ASC";
|
|
689
|
-
sqlParts.push(`ORDER BY ${quoteQualifiedIdentifier(input.order.field)} ${direction}`);
|
|
690
|
-
}
|
|
691
|
-
if (limit !== void 0) {
|
|
692
|
-
sqlParts.push(`LIMIT ${Math.max(0, Math.trunc(limit))}`);
|
|
686
|
+
if (context.method !== "GET") {
|
|
687
|
+
requestInit.body = JSON.stringify(body ?? {});
|
|
693
688
|
}
|
|
694
|
-
|
|
695
|
-
|
|
689
|
+
const fetcher = config.fetch ?? globalThis.fetch;
|
|
690
|
+
if (!fetcher) {
|
|
691
|
+
const details = toErrorDetails({
|
|
692
|
+
code: "UNKNOWN_ERROR",
|
|
693
|
+
message: "No fetch implementation available for auth client",
|
|
694
|
+
status: 0,
|
|
695
|
+
endpoint: context.endpoint,
|
|
696
|
+
method: context.method,
|
|
697
|
+
hint: "Use Node 18+ or provide `fetch` via createClient(..., { auth: { fetch } }) or createAuthClient({ fetch })"
|
|
698
|
+
});
|
|
699
|
+
return {
|
|
700
|
+
ok: false,
|
|
701
|
+
status: 0,
|
|
702
|
+
data: null,
|
|
703
|
+
error: details.message,
|
|
704
|
+
errorDetails: details,
|
|
705
|
+
raw: null
|
|
706
|
+
};
|
|
696
707
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
},
|
|
713
|
-
eqUuid(column, value) {
|
|
714
|
-
addCondition("eq", column, value, { valueCast: "uuid" });
|
|
715
|
-
return self;
|
|
716
|
-
},
|
|
717
|
-
match(filters) {
|
|
718
|
-
Object.entries(filters).forEach(([column, value]) => {
|
|
719
|
-
if (shouldUseUuidTextComparison(column, value)) {
|
|
720
|
-
addCondition("eq", column, value, { columnCast: "text" });
|
|
721
|
-
} else {
|
|
722
|
-
addCondition("eq", column, value);
|
|
723
|
-
}
|
|
708
|
+
try {
|
|
709
|
+
const response = await fetcher(url, requestInit);
|
|
710
|
+
const rawText = await response.text();
|
|
711
|
+
const requestId = resolveRequestId2(response.headers);
|
|
712
|
+
const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
|
|
713
|
+
if (parsedBody.parseFailed) {
|
|
714
|
+
const details = toErrorDetails({
|
|
715
|
+
code: "INVALID_JSON",
|
|
716
|
+
message: "Auth server returned malformed JSON",
|
|
717
|
+
status: response.status,
|
|
718
|
+
endpoint: context.endpoint,
|
|
719
|
+
method: context.method,
|
|
720
|
+
requestId,
|
|
721
|
+
hint: "Verify the auth endpoint response body is valid JSON.",
|
|
722
|
+
cause: rawText.slice(0, 300)
|
|
724
723
|
});
|
|
725
|
-
return
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
limit(count) {
|
|
733
|
-
state.limit = count;
|
|
734
|
-
return self;
|
|
735
|
-
},
|
|
736
|
-
offset(count) {
|
|
737
|
-
state.offset = count;
|
|
738
|
-
return self;
|
|
739
|
-
},
|
|
740
|
-
currentPage(value) {
|
|
741
|
-
state.currentPage = value;
|
|
742
|
-
return self;
|
|
743
|
-
},
|
|
744
|
-
pageSize(value) {
|
|
745
|
-
state.pageSize = value;
|
|
746
|
-
return self;
|
|
747
|
-
},
|
|
748
|
-
totalPages(value) {
|
|
749
|
-
state.totalPages = value;
|
|
750
|
-
return self;
|
|
751
|
-
},
|
|
752
|
-
order(column, options) {
|
|
753
|
-
state.order = {
|
|
754
|
-
field: column,
|
|
755
|
-
direction: options?.ascending === false ? "descending" : "ascending"
|
|
724
|
+
return {
|
|
725
|
+
ok: false,
|
|
726
|
+
status: response.status,
|
|
727
|
+
data: null,
|
|
728
|
+
error: details.message,
|
|
729
|
+
errorDetails: details,
|
|
730
|
+
raw: parsedBody.parsed
|
|
756
731
|
};
|
|
757
|
-
return self;
|
|
758
|
-
},
|
|
759
|
-
gt(column, value) {
|
|
760
|
-
addCondition("gt", column, value);
|
|
761
|
-
return self;
|
|
762
|
-
},
|
|
763
|
-
gte(column, value) {
|
|
764
|
-
addCondition("gte", column, value);
|
|
765
|
-
return self;
|
|
766
|
-
},
|
|
767
|
-
lt(column, value) {
|
|
768
|
-
addCondition("lt", column, value);
|
|
769
|
-
return self;
|
|
770
|
-
},
|
|
771
|
-
lte(column, value) {
|
|
772
|
-
addCondition("lte", column, value);
|
|
773
|
-
return self;
|
|
774
|
-
},
|
|
775
|
-
neq(column, value) {
|
|
776
|
-
addCondition("neq", column, value);
|
|
777
|
-
return self;
|
|
778
|
-
},
|
|
779
|
-
like(column, value) {
|
|
780
|
-
addCondition("like", column, value);
|
|
781
|
-
return self;
|
|
782
|
-
},
|
|
783
|
-
ilike(column, value) {
|
|
784
|
-
addCondition("ilike", column, value);
|
|
785
|
-
return self;
|
|
786
|
-
},
|
|
787
|
-
is(column, value) {
|
|
788
|
-
addCondition("is", column, value);
|
|
789
|
-
return self;
|
|
790
|
-
},
|
|
791
|
-
in(column, values) {
|
|
792
|
-
addCondition("in", column, values);
|
|
793
|
-
return self;
|
|
794
|
-
},
|
|
795
|
-
contains(column, values) {
|
|
796
|
-
addCondition("contains", column, values);
|
|
797
|
-
return self;
|
|
798
|
-
},
|
|
799
|
-
containedBy(column, values) {
|
|
800
|
-
addCondition("containedBy", column, values);
|
|
801
|
-
return self;
|
|
802
|
-
},
|
|
803
|
-
not(columnOrExpression, operator, value) {
|
|
804
|
-
if (operator != null && value !== void 0) {
|
|
805
|
-
addCondition("not", void 0, `${columnOrExpression}.${operator}.${stringifyFilterValue(value)}`);
|
|
806
|
-
} else {
|
|
807
|
-
addCondition("not", void 0, columnOrExpression);
|
|
808
|
-
}
|
|
809
|
-
return self;
|
|
810
|
-
},
|
|
811
|
-
or(expression) {
|
|
812
|
-
addCondition("or", void 0, expression);
|
|
813
|
-
return self;
|
|
814
732
|
}
|
|
815
|
-
|
|
733
|
+
const parsed = parsedBody.parsed;
|
|
734
|
+
if (!response.ok) {
|
|
735
|
+
const details = toErrorDetails({
|
|
736
|
+
code: "HTTP_ERROR",
|
|
737
|
+
message: resolveErrorMessage2(
|
|
738
|
+
parsed,
|
|
739
|
+
`Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
|
|
740
|
+
),
|
|
741
|
+
status: response.status,
|
|
742
|
+
endpoint: context.endpoint,
|
|
743
|
+
method: context.method,
|
|
744
|
+
requestId
|
|
745
|
+
});
|
|
746
|
+
return {
|
|
747
|
+
ok: false,
|
|
748
|
+
status: response.status,
|
|
749
|
+
data: null,
|
|
750
|
+
error: details.message,
|
|
751
|
+
errorDetails: details,
|
|
752
|
+
raw: parsed
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
return {
|
|
756
|
+
ok: true,
|
|
757
|
+
status: response.status,
|
|
758
|
+
data: parsed ?? null,
|
|
759
|
+
error: null,
|
|
760
|
+
errorDetails: null,
|
|
761
|
+
raw: parsed
|
|
762
|
+
};
|
|
763
|
+
} catch (callError) {
|
|
764
|
+
const message = callError instanceof Error ? callError.message : String(callError);
|
|
765
|
+
const details = toErrorDetails({
|
|
766
|
+
code: "NETWORK_ERROR",
|
|
767
|
+
message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
|
|
768
|
+
status: 0,
|
|
769
|
+
endpoint: context.endpoint,
|
|
770
|
+
method: context.method,
|
|
771
|
+
cause: message,
|
|
772
|
+
hint: "Check auth server URL, DNS, and network reachability."
|
|
773
|
+
});
|
|
774
|
+
return {
|
|
775
|
+
ok: false,
|
|
776
|
+
status: 0,
|
|
777
|
+
data: null,
|
|
778
|
+
error: details.message,
|
|
779
|
+
errorDetails: details,
|
|
780
|
+
raw: null
|
|
781
|
+
};
|
|
782
|
+
}
|
|
816
783
|
}
|
|
817
|
-
function
|
|
818
|
-
|
|
819
|
-
|
|
784
|
+
function executePostWithCompatibleInput(config, context, input, options) {
|
|
785
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
786
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
787
|
+
return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
|
|
820
788
|
}
|
|
821
|
-
function
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
};
|
|
825
|
-
return {
|
|
826
|
-
eq(column, value) {
|
|
827
|
-
addFilter("eq", column, value);
|
|
828
|
-
return self;
|
|
829
|
-
},
|
|
830
|
-
neq(column, value) {
|
|
831
|
-
addFilter("neq", column, value);
|
|
832
|
-
return self;
|
|
833
|
-
},
|
|
834
|
-
gt(column, value) {
|
|
835
|
-
addFilter("gt", column, value);
|
|
836
|
-
return self;
|
|
837
|
-
},
|
|
838
|
-
gte(column, value) {
|
|
839
|
-
addFilter("gte", column, value);
|
|
840
|
-
return self;
|
|
841
|
-
},
|
|
842
|
-
lt(column, value) {
|
|
843
|
-
addFilter("lt", column, value);
|
|
844
|
-
return self;
|
|
845
|
-
},
|
|
846
|
-
lte(column, value) {
|
|
847
|
-
addFilter("lte", column, value);
|
|
848
|
-
return self;
|
|
849
|
-
},
|
|
850
|
-
like(column, value) {
|
|
851
|
-
addFilter("like", column, value);
|
|
852
|
-
return self;
|
|
853
|
-
},
|
|
854
|
-
ilike(column, value) {
|
|
855
|
-
addFilter("ilike", column, value);
|
|
856
|
-
return self;
|
|
857
|
-
},
|
|
858
|
-
is(column, value) {
|
|
859
|
-
addFilter("is", column, value);
|
|
860
|
-
return self;
|
|
861
|
-
},
|
|
862
|
-
in(column, values) {
|
|
863
|
-
addFilter("in", column, values);
|
|
864
|
-
return self;
|
|
865
|
-
}
|
|
866
|
-
};
|
|
789
|
+
function executePostWithOptionalInput(config, context, input, options) {
|
|
790
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
791
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
792
|
+
return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
|
|
867
793
|
}
|
|
868
|
-
function
|
|
869
|
-
const
|
|
870
|
-
|
|
794
|
+
function executeGetWithCompatibleInput(config, context, input, options) {
|
|
795
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
796
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
797
|
+
return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
|
|
798
|
+
}
|
|
799
|
+
function executeGetWithQueryCompatibleInput(config, context, input, options) {
|
|
800
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
801
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
802
|
+
const query = payload?.query;
|
|
803
|
+
return callAuthEndpoint(
|
|
804
|
+
config,
|
|
805
|
+
context,
|
|
806
|
+
void 0,
|
|
807
|
+
query,
|
|
808
|
+
mergedOptions
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
function createAuthClient(config = {}) {
|
|
812
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
813
|
+
const resolvedConfig = {
|
|
814
|
+
...config,
|
|
815
|
+
baseUrl: normalizedBaseUrl
|
|
871
816
|
};
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
filters: state.filters.length ? [...state.filters] : void 0,
|
|
883
|
-
count: mergedOptions?.count,
|
|
884
|
-
head: mergedOptions?.head,
|
|
885
|
-
limit: state.limit,
|
|
886
|
-
offset: state.offset,
|
|
887
|
-
order: state.order
|
|
888
|
-
};
|
|
889
|
-
const response = await client.rpcGateway(payload, mergedOptions);
|
|
890
|
-
return formatResult(response);
|
|
817
|
+
const request = (input, options) => {
|
|
818
|
+
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
819
|
+
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
820
|
+
return callAuthEndpoint(
|
|
821
|
+
resolvedConfig,
|
|
822
|
+
{ endpoint: input.endpoint, method },
|
|
823
|
+
input.body,
|
|
824
|
+
input.query,
|
|
825
|
+
mergedOptions
|
|
826
|
+
);
|
|
891
827
|
};
|
|
892
|
-
const
|
|
893
|
-
const
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
828
|
+
const postGeneric = (endpoint, input, options) => {
|
|
829
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
830
|
+
return request(
|
|
831
|
+
{
|
|
832
|
+
endpoint,
|
|
833
|
+
method: "POST",
|
|
834
|
+
body: payload ?? {},
|
|
835
|
+
fetchOptions
|
|
836
|
+
},
|
|
837
|
+
options
|
|
838
|
+
);
|
|
899
839
|
};
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
return toSingleResult(result);
|
|
911
|
-
},
|
|
912
|
-
maybeSingle(columns, options) {
|
|
913
|
-
return builder.single(columns, options);
|
|
914
|
-
},
|
|
915
|
-
order(column, options) {
|
|
916
|
-
state.order = { column, ascending: options?.ascending ?? true };
|
|
917
|
-
return builder;
|
|
918
|
-
},
|
|
919
|
-
limit(count) {
|
|
920
|
-
state.limit = count;
|
|
921
|
-
return builder;
|
|
922
|
-
},
|
|
923
|
-
offset(count) {
|
|
924
|
-
state.offset = count;
|
|
925
|
-
return builder;
|
|
926
|
-
},
|
|
927
|
-
range(from, to) {
|
|
928
|
-
state.offset = from;
|
|
929
|
-
state.limit = to - from + 1;
|
|
930
|
-
return builder;
|
|
931
|
-
},
|
|
932
|
-
then(onfulfilled, onrejected) {
|
|
933
|
-
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
934
|
-
},
|
|
935
|
-
catch(onrejected) {
|
|
936
|
-
return run(selectedColumns, selectedOptions).catch(onrejected);
|
|
937
|
-
},
|
|
938
|
-
finally(onfinally) {
|
|
939
|
-
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
940
|
-
}
|
|
941
|
-
});
|
|
942
|
-
return builder;
|
|
943
|
-
}
|
|
944
|
-
function createTableBuilder(tableName, client) {
|
|
945
|
-
const state = {
|
|
946
|
-
conditions: []
|
|
840
|
+
const getGeneric = (endpoint, input, options) => {
|
|
841
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
842
|
+
return request(
|
|
843
|
+
{
|
|
844
|
+
endpoint,
|
|
845
|
+
method: "GET",
|
|
846
|
+
fetchOptions
|
|
847
|
+
},
|
|
848
|
+
options
|
|
849
|
+
);
|
|
947
850
|
};
|
|
948
|
-
const
|
|
949
|
-
const
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
851
|
+
const getWithQuery = (endpoint, input, options) => {
|
|
852
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
853
|
+
const query = payload?.query;
|
|
854
|
+
return request(
|
|
855
|
+
{
|
|
856
|
+
endpoint,
|
|
857
|
+
method: "GET",
|
|
858
|
+
query,
|
|
859
|
+
fetchOptions
|
|
860
|
+
},
|
|
861
|
+
options
|
|
862
|
+
);
|
|
863
|
+
};
|
|
864
|
+
const listUserEmailsWithFallback = async (input, options) => {
|
|
865
|
+
const primary = await getWithQuery(
|
|
866
|
+
"/email/list",
|
|
867
|
+
input,
|
|
868
|
+
options
|
|
869
|
+
);
|
|
870
|
+
if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
|
|
871
|
+
return primary;
|
|
961
872
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
873
|
+
return getWithQuery(
|
|
874
|
+
"/email-list",
|
|
875
|
+
input,
|
|
876
|
+
options
|
|
877
|
+
);
|
|
878
|
+
};
|
|
879
|
+
const healthWithFallback = async (input, options) => {
|
|
880
|
+
const primary = await getGeneric("/health", input, options);
|
|
881
|
+
if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
|
|
882
|
+
return primary;
|
|
967
883
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
884
|
+
const fallback = await getGeneric("/ok", input, options);
|
|
885
|
+
if (!fallback.ok) {
|
|
886
|
+
return {
|
|
887
|
+
...fallback,
|
|
888
|
+
data: null
|
|
889
|
+
};
|
|
973
890
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
const conditions = state.conditions.length ? state.conditions.map((condition) => ({ ...condition })) : void 0;
|
|
980
|
-
const hasTypedEqualityComparison = conditions?.some(
|
|
981
|
-
(condition) => condition.operator === "eq" && (condition.value_cast !== void 0 || condition.column_cast !== void 0)
|
|
982
|
-
) ?? false;
|
|
983
|
-
if (hasTypedEqualityComparison && !options?.head && !options?.count && conditions) {
|
|
984
|
-
const query = buildTypedSelectQuery({
|
|
985
|
-
tableName,
|
|
986
|
-
columns,
|
|
987
|
-
conditions,
|
|
988
|
-
limit: state.limit,
|
|
989
|
-
offset: state.offset,
|
|
990
|
-
currentPage: state.currentPage,
|
|
991
|
-
pageSize: state.pageSize,
|
|
992
|
-
order: state.order
|
|
993
|
-
});
|
|
994
|
-
if (query) {
|
|
995
|
-
const queryResponse = await client.queryGateway({ query }, options);
|
|
996
|
-
return formatResult(queryResponse);
|
|
891
|
+
const fallbackStatus = isRecord2(fallback.data) && typeof fallback.data.ok === "boolean" ? fallback.data.ok ? "ok" : "error" : "ok";
|
|
892
|
+
return {
|
|
893
|
+
...fallback,
|
|
894
|
+
data: {
|
|
895
|
+
status: fallbackStatus
|
|
997
896
|
}
|
|
998
|
-
}
|
|
999
|
-
const payload = {
|
|
1000
|
-
table_name: tableName,
|
|
1001
|
-
columns,
|
|
1002
|
-
conditions,
|
|
1003
|
-
limit: state.limit,
|
|
1004
|
-
offset: state.offset,
|
|
1005
|
-
current_page: state.currentPage,
|
|
1006
|
-
page_size: state.pageSize,
|
|
1007
|
-
total_pages: state.totalPages,
|
|
1008
|
-
sort_by: state.order,
|
|
1009
|
-
strip_nulls: options?.stripNulls ?? true,
|
|
1010
|
-
count: options?.count,
|
|
1011
|
-
head: options?.head
|
|
1012
897
|
};
|
|
1013
|
-
const response = await client.fetchGateway(payload, options);
|
|
1014
|
-
return formatResult(response);
|
|
1015
|
-
};
|
|
1016
|
-
const createSelectChain = (columns, options) => {
|
|
1017
|
-
const chain = {};
|
|
1018
|
-
const filterMethods2 = createFilterMethods(state, addCondition, chain);
|
|
1019
|
-
Object.assign(chain, filterMethods2, {
|
|
1020
|
-
async single(cols, opts) {
|
|
1021
|
-
const r = await runSelect(cols ?? columns, opts ?? options);
|
|
1022
|
-
return toSingleResult(r);
|
|
1023
|
-
},
|
|
1024
|
-
maybeSingle(cols, opts) {
|
|
1025
|
-
return chain.single(cols, opts);
|
|
1026
|
-
},
|
|
1027
|
-
then(onfulfilled, onrejected) {
|
|
1028
|
-
return runSelect(columns, options).then(onfulfilled, onrejected);
|
|
1029
|
-
},
|
|
1030
|
-
catch(onrejected) {
|
|
1031
|
-
return runSelect(columns, options).catch(onrejected);
|
|
1032
|
-
},
|
|
1033
|
-
finally(onfinally) {
|
|
1034
|
-
return runSelect(columns, options).finally(onfinally);
|
|
1035
|
-
}
|
|
1036
|
-
});
|
|
1037
|
-
return chain;
|
|
1038
898
|
};
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
899
|
+
const signOut = (input, options) => executePostWithOptionalInput(
|
|
900
|
+
resolvedConfig,
|
|
901
|
+
{ endpoint: "/sign-out", method: "POST" },
|
|
902
|
+
input,
|
|
903
|
+
options
|
|
904
|
+
);
|
|
905
|
+
const revokeSessions = (input, options) => executePostWithOptionalInput(
|
|
906
|
+
resolvedConfig,
|
|
907
|
+
{ endpoint: "/revoke-sessions", method: "POST" },
|
|
908
|
+
input,
|
|
909
|
+
options
|
|
910
|
+
);
|
|
911
|
+
const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
|
|
912
|
+
resolvedConfig,
|
|
913
|
+
{ endpoint: "/revoke-other-sessions", method: "POST" },
|
|
914
|
+
input,
|
|
915
|
+
options
|
|
916
|
+
);
|
|
917
|
+
const revokeSession = (input, options) => executePostWithCompatibleInput(
|
|
918
|
+
resolvedConfig,
|
|
919
|
+
{ endpoint: "/revoke-session", method: "POST" },
|
|
920
|
+
input,
|
|
921
|
+
options
|
|
922
|
+
);
|
|
923
|
+
const deleteUser = (input, options) => {
|
|
924
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
925
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
926
|
+
return callAuthEndpoint(
|
|
927
|
+
resolvedConfig,
|
|
928
|
+
{ endpoint: "/delete-user", method: "POST" },
|
|
929
|
+
payload ?? {},
|
|
930
|
+
void 0,
|
|
931
|
+
mergedOptions
|
|
932
|
+
);
|
|
933
|
+
};
|
|
934
|
+
const deleteUserCallback = (input, options) => {
|
|
935
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
936
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
937
|
+
const query = payload ?? {};
|
|
938
|
+
return callAuthEndpoint(
|
|
939
|
+
resolvedConfig,
|
|
940
|
+
{ endpoint: "/delete-user/callback", method: "GET" },
|
|
941
|
+
void 0,
|
|
942
|
+
{
|
|
943
|
+
token: query.token,
|
|
944
|
+
callbackURL: query.callbackURL
|
|
945
|
+
},
|
|
946
|
+
mergedOptions
|
|
947
|
+
);
|
|
948
|
+
};
|
|
949
|
+
const resolveResetPasswordToken = (input, options) => {
|
|
950
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
951
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
952
|
+
const query = payload;
|
|
953
|
+
const token = query?.token?.trim();
|
|
954
|
+
if (!token) {
|
|
955
|
+
throw new Error("resolveResetPasswordToken requires a non-empty token");
|
|
956
|
+
}
|
|
957
|
+
const endpoint = `/reset-password/${encodeURIComponent(token)}`;
|
|
958
|
+
return callAuthEndpoint(
|
|
959
|
+
resolvedConfig,
|
|
960
|
+
{ endpoint, method: "GET" },
|
|
961
|
+
void 0,
|
|
962
|
+
query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
|
|
963
|
+
mergedOptions
|
|
964
|
+
);
|
|
965
|
+
};
|
|
966
|
+
const organization = {
|
|
967
|
+
create: (input, options) => executePostWithCompatibleInput(
|
|
968
|
+
resolvedConfig,
|
|
969
|
+
{ endpoint: "/organization/create", method: "POST" },
|
|
970
|
+
input,
|
|
971
|
+
options
|
|
972
|
+
),
|
|
973
|
+
update: (input, options) => executePostWithCompatibleInput(
|
|
974
|
+
resolvedConfig,
|
|
975
|
+
{ endpoint: "/organization/update", method: "POST" },
|
|
976
|
+
input,
|
|
977
|
+
options
|
|
978
|
+
),
|
|
979
|
+
delete: (input, options) => executePostWithCompatibleInput(
|
|
980
|
+
resolvedConfig,
|
|
981
|
+
{ endpoint: "/organization/delete", method: "POST" },
|
|
982
|
+
input,
|
|
983
|
+
options
|
|
984
|
+
),
|
|
985
|
+
setActive: (input, options) => executePostWithCompatibleInput(
|
|
986
|
+
resolvedConfig,
|
|
987
|
+
{ endpoint: "/organization/set-active", method: "POST" },
|
|
988
|
+
input,
|
|
989
|
+
options
|
|
990
|
+
),
|
|
991
|
+
list: (input, options) => getGeneric(
|
|
992
|
+
"/organization/list",
|
|
993
|
+
input,
|
|
994
|
+
options
|
|
995
|
+
),
|
|
996
|
+
getFull: (input, options) => executeGetWithQueryCompatibleInput(
|
|
997
|
+
resolvedConfig,
|
|
998
|
+
{ endpoint: "/organization/get-full-organization", method: "GET" },
|
|
999
|
+
input,
|
|
1000
|
+
options
|
|
1001
|
+
),
|
|
1002
|
+
checkSlug: (input, options) => executePostWithCompatibleInput(
|
|
1003
|
+
resolvedConfig,
|
|
1004
|
+
{ endpoint: "/organization/check-slug", method: "POST" },
|
|
1005
|
+
input,
|
|
1006
|
+
options
|
|
1007
|
+
),
|
|
1008
|
+
leave: (input, options) => executePostWithCompatibleInput(
|
|
1009
|
+
resolvedConfig,
|
|
1010
|
+
{ endpoint: "/organization/leave", method: "POST" },
|
|
1011
|
+
input,
|
|
1012
|
+
options
|
|
1013
|
+
),
|
|
1014
|
+
listUserInvitations: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1015
|
+
resolvedConfig,
|
|
1016
|
+
{ endpoint: "/organization/list-user-invitations", method: "GET" },
|
|
1017
|
+
input,
|
|
1018
|
+
options
|
|
1019
|
+
),
|
|
1020
|
+
hasPermission: (input, options) => postGeneric(
|
|
1021
|
+
"/organization/has-permission",
|
|
1022
|
+
input,
|
|
1023
|
+
options
|
|
1024
|
+
),
|
|
1025
|
+
invitation: {
|
|
1026
|
+
cancel: (input, options) => executePostWithCompatibleInput(
|
|
1027
|
+
resolvedConfig,
|
|
1028
|
+
{ endpoint: "/organization/cancel-invitation", method: "POST" },
|
|
1029
|
+
input,
|
|
1030
|
+
options
|
|
1031
|
+
),
|
|
1032
|
+
accept: (input, options) => executePostWithCompatibleInput(
|
|
1033
|
+
resolvedConfig,
|
|
1034
|
+
{ endpoint: "/organization/accept-invitation", method: "POST" },
|
|
1035
|
+
input,
|
|
1036
|
+
options
|
|
1037
|
+
),
|
|
1038
|
+
get: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1039
|
+
resolvedConfig,
|
|
1040
|
+
{ endpoint: "/organization/get-invitation", method: "GET" },
|
|
1041
|
+
input,
|
|
1042
|
+
options
|
|
1043
|
+
),
|
|
1044
|
+
reject: (input, options) => executePostWithCompatibleInput(
|
|
1045
|
+
resolvedConfig,
|
|
1046
|
+
{ endpoint: "/organization/reject-invitation", method: "POST" },
|
|
1047
|
+
input,
|
|
1048
|
+
options
|
|
1049
|
+
),
|
|
1050
|
+
list: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1051
|
+
resolvedConfig,
|
|
1052
|
+
{ endpoint: "/organization/list-invitations", method: "GET" },
|
|
1053
|
+
input,
|
|
1054
|
+
options
|
|
1055
|
+
)
|
|
1056
|
+
},
|
|
1057
|
+
member: {
|
|
1058
|
+
remove: (input, options) => executePostWithCompatibleInput(
|
|
1059
|
+
resolvedConfig,
|
|
1060
|
+
{ endpoint: "/organization/remove-member", method: "POST" },
|
|
1061
|
+
input,
|
|
1062
|
+
options
|
|
1063
|
+
),
|
|
1064
|
+
updateRole: (input, options) => executePostWithCompatibleInput(
|
|
1065
|
+
resolvedConfig,
|
|
1066
|
+
{ endpoint: "/organization/update-member-role", method: "POST" },
|
|
1067
|
+
input,
|
|
1068
|
+
options
|
|
1069
|
+
),
|
|
1070
|
+
invite: (input, options) => executePostWithCompatibleInput(
|
|
1071
|
+
resolvedConfig,
|
|
1072
|
+
{ endpoint: "/organization/invite-member", method: "POST" },
|
|
1073
|
+
input,
|
|
1074
|
+
options
|
|
1075
|
+
),
|
|
1076
|
+
getActive: (input, options) => executeGetWithCompatibleInput(
|
|
1077
|
+
resolvedConfig,
|
|
1078
|
+
{ endpoint: "/organization/get-active-member", method: "GET" },
|
|
1079
|
+
input,
|
|
1080
|
+
options
|
|
1081
|
+
),
|
|
1082
|
+
list: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1083
|
+
resolvedConfig,
|
|
1084
|
+
{ endpoint: "/organization/list-members", method: "GET" },
|
|
1085
|
+
input,
|
|
1086
|
+
options
|
|
1087
|
+
)
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
const authResetPassword = Object.assign(
|
|
1091
|
+
(input, options) => executePostWithCompatibleInput(
|
|
1092
|
+
resolvedConfig,
|
|
1093
|
+
{ endpoint: "/reset-password", method: "POST" },
|
|
1094
|
+
input,
|
|
1095
|
+
options
|
|
1096
|
+
),
|
|
1097
|
+
{
|
|
1098
|
+
token: resolveResetPasswordToken
|
|
1099
|
+
}
|
|
1100
|
+
);
|
|
1101
|
+
const sessionRevokeBinding = (input, options) => {
|
|
1102
|
+
if (Array.isArray(input)) {
|
|
1103
|
+
if (input.length === 0) {
|
|
1104
|
+
throw new Error("session.revoke requires at least one session token");
|
|
1105
|
+
}
|
|
1106
|
+
if (input.length === 1) {
|
|
1107
|
+
return revokeSession(input[0], options);
|
|
1108
|
+
}
|
|
1109
|
+
return revokeSessions(void 0, options);
|
|
1110
|
+
}
|
|
1111
|
+
const parsed = input;
|
|
1112
|
+
const tokens = Array.isArray(parsed.tokens) ? parsed.tokens.filter((token2) => token2.trim().length > 0) : void 0;
|
|
1113
|
+
if (tokens && tokens.length > 1) {
|
|
1114
|
+
return revokeSessions(
|
|
1115
|
+
parsed.fetchOptions ? { fetchOptions: parsed.fetchOptions } : void 0,
|
|
1116
|
+
options
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
if (tokens && tokens.length === 1) {
|
|
1120
|
+
return revokeSession(
|
|
1121
|
+
{ token: tokens[0], fetchOptions: parsed.fetchOptions },
|
|
1122
|
+
options
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
1125
|
+
const token = parsed.token?.trim();
|
|
1126
|
+
if (!token) {
|
|
1127
|
+
throw new Error("session.revoke requires a non-empty token or a non-empty token list");
|
|
1128
|
+
}
|
|
1129
|
+
return revokeSession(
|
|
1130
|
+
{
|
|
1131
|
+
token,
|
|
1132
|
+
fetchOptions: parsed.fetchOptions
|
|
1133
|
+
},
|
|
1134
|
+
options
|
|
1135
|
+
);
|
|
1136
|
+
};
|
|
1137
|
+
const adminUserSessionRevokeBinding = (input, options) => {
|
|
1138
|
+
const requireUserId = (userId) => {
|
|
1139
|
+
const trimmed = String(userId ?? "").trim();
|
|
1140
|
+
if (!trimmed) {
|
|
1141
|
+
throw new Error("admin.user.session.revoke requires a non-empty userId");
|
|
1142
|
+
}
|
|
1143
|
+
return trimmed;
|
|
1144
|
+
};
|
|
1145
|
+
const requireSinglePluralUserId = (sessions2) => {
|
|
1146
|
+
const uniqueUserIds = [...new Set(sessions2.map((session) => requireUserId(session.userId)))];
|
|
1147
|
+
if (uniqueUserIds.length !== 1) {
|
|
1148
|
+
throw new Error("admin.user.session.revoke requires the same userId across plural payloads");
|
|
1149
|
+
}
|
|
1150
|
+
return { userId: uniqueUserIds[0] };
|
|
1151
|
+
};
|
|
1152
|
+
if (Array.isArray(input)) {
|
|
1153
|
+
if (input.length === 0) {
|
|
1154
|
+
throw new Error("admin.user.session.revoke requires at least one payload item");
|
|
1155
|
+
}
|
|
1156
|
+
if (input.length === 1) {
|
|
1157
|
+
return postGeneric(
|
|
1158
|
+
"/admin/revoke-user-session",
|
|
1159
|
+
{
|
|
1160
|
+
...input[0],
|
|
1161
|
+
userId: requireUserId(input[0].userId)
|
|
1162
|
+
},
|
|
1163
|
+
options
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
return postGeneric(
|
|
1167
|
+
"/admin/revoke-user-sessions",
|
|
1168
|
+
requireSinglePluralUserId(input),
|
|
1169
|
+
options
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
const parsed = input;
|
|
1173
|
+
const sessions = parsed.sessions;
|
|
1174
|
+
if (sessions && sessions.length === 0) {
|
|
1175
|
+
throw new Error("admin.user.session.revoke requires at least one payload item");
|
|
1176
|
+
}
|
|
1177
|
+
if (sessions && sessions.length === 1) {
|
|
1178
|
+
return postGeneric(
|
|
1179
|
+
"/admin/revoke-user-session",
|
|
1180
|
+
{
|
|
1181
|
+
...sessions[0],
|
|
1182
|
+
userId: requireUserId(sessions[0].userId),
|
|
1183
|
+
fetchOptions: parsed.fetchOptions
|
|
1184
|
+
},
|
|
1185
|
+
options
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
if (sessions && sessions.length > 1) {
|
|
1189
|
+
return postGeneric(
|
|
1190
|
+
"/admin/revoke-user-sessions",
|
|
1191
|
+
{
|
|
1192
|
+
...requireSinglePluralUserId(sessions),
|
|
1193
|
+
fetchOptions: parsed.fetchOptions
|
|
1194
|
+
},
|
|
1195
|
+
options
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
const normalizedUserId = requireUserId(parsed.userId);
|
|
1199
|
+
if (!parsed.sessionToken) {
|
|
1200
|
+
return postGeneric(
|
|
1201
|
+
"/admin/revoke-user-sessions",
|
|
1202
|
+
{
|
|
1203
|
+
userId: normalizedUserId,
|
|
1204
|
+
fetchOptions: parsed.fetchOptions
|
|
1205
|
+
},
|
|
1206
|
+
options
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
return postGeneric(
|
|
1210
|
+
"/admin/revoke-user-session",
|
|
1211
|
+
{
|
|
1212
|
+
...parsed,
|
|
1213
|
+
userId: normalizedUserId
|
|
1214
|
+
},
|
|
1215
|
+
options
|
|
1216
|
+
);
|
|
1217
|
+
};
|
|
1218
|
+
const auth = {
|
|
1219
|
+
getSession: (input, options) => getGeneric("/get-session", input, options),
|
|
1220
|
+
signOut,
|
|
1221
|
+
forgetPassword: (input, options) => postGeneric("/forget-password", input, options),
|
|
1222
|
+
resetPassword: authResetPassword,
|
|
1223
|
+
setPassword: (input, options) => postGeneric("/set-password", input, options),
|
|
1224
|
+
verifyEmail: (input, options) => {
|
|
1225
|
+
const queryInput = {
|
|
1226
|
+
query: {
|
|
1227
|
+
token: input.token,
|
|
1228
|
+
callbackURL: input.callbackURL
|
|
1229
|
+
},
|
|
1230
|
+
fetchOptions: input.fetchOptions
|
|
1231
|
+
};
|
|
1232
|
+
return getWithQuery(
|
|
1233
|
+
"/verify-email",
|
|
1234
|
+
queryInput,
|
|
1235
|
+
options
|
|
1236
|
+
);
|
|
1237
|
+
},
|
|
1238
|
+
sendVerificationEmail: (input, options) => postGeneric("/send-verification-email", input, options),
|
|
1239
|
+
changeEmail: (input, options) => postGeneric("/change-email", input, options),
|
|
1240
|
+
changeEmailVerify: (input, options) => getWithQuery("/change-email/verify", input, options),
|
|
1241
|
+
deleteUserVerify: (input, options) => getWithQuery("/delete-user/verify", input, options),
|
|
1242
|
+
changePassword: (input, options) => postGeneric("/change-password", input, options),
|
|
1243
|
+
user: {
|
|
1244
|
+
update: (input, options) => postGeneric("/update-user", input, options),
|
|
1245
|
+
delete: (input, options) => postGeneric("/delete-user", input, options),
|
|
1246
|
+
email: {
|
|
1247
|
+
list: listUserEmailsWithFallback
|
|
1248
|
+
}
|
|
1249
|
+
},
|
|
1250
|
+
session: {
|
|
1251
|
+
list: (input, options) => getGeneric("/list-sessions", input, options),
|
|
1252
|
+
revoke: sessionRevokeBinding,
|
|
1253
|
+
revokeOther: revokeOtherSessions
|
|
1254
|
+
},
|
|
1255
|
+
social: {
|
|
1256
|
+
link: (input, options) => postGeneric("/link-social", input, options)
|
|
1257
|
+
},
|
|
1258
|
+
account: {
|
|
1259
|
+
list: (input, options) => getGeneric("/list-accounts", input, options),
|
|
1260
|
+
unlink: (input, options) => postGeneric("/unlink-account", input, options)
|
|
1261
|
+
},
|
|
1262
|
+
deleteUser: {
|
|
1263
|
+
callback: deleteUserCallback
|
|
1264
|
+
},
|
|
1265
|
+
refreshToken: (input, options) => postGeneric("/refresh-token", input, options),
|
|
1266
|
+
getAccessToken: (input, options) => postGeneric("/get-access-token", input, options),
|
|
1267
|
+
health: healthWithFallback,
|
|
1268
|
+
ok: (input, options) => getGeneric("/ok", input, options),
|
|
1269
|
+
error: (input, options) => getGeneric("/error", input, options),
|
|
1270
|
+
twoFactor: {
|
|
1271
|
+
getTotpUri: (input, options) => postGeneric("/two-factor/get-totp-uri", input, options),
|
|
1272
|
+
verifyTotp: (input, options) => postGeneric("/two-factor/verify-totp", input, options),
|
|
1273
|
+
sendOtp: (input, options) => postGeneric("/two-factor/send-otp", input, options),
|
|
1274
|
+
verifyOtp: (input, options) => postGeneric("/two-factor/verify-otp", input, options),
|
|
1275
|
+
verifyBackupCode: (input, options) => postGeneric("/two-factor/verify-backup-code", input, options),
|
|
1276
|
+
generateBackupCodes: (input, options) => executePostWithCompatibleInput(
|
|
1277
|
+
resolvedConfig,
|
|
1278
|
+
{ endpoint: "/two-factor/generate-backup-codes", method: "POST" },
|
|
1279
|
+
input,
|
|
1280
|
+
options
|
|
1281
|
+
),
|
|
1282
|
+
enable: (input, options) => postGeneric("/two-factor/enable", input, options),
|
|
1283
|
+
disable: (input, options) => postGeneric("/two-factor/disable", input, options)
|
|
1284
|
+
},
|
|
1285
|
+
passkey: {
|
|
1286
|
+
generateRegisterOptions: (input, options) => getGeneric("/passkey/generate-register-options", input, options),
|
|
1287
|
+
generateAuthenticateOptions: (input, options) => postGeneric("/passkey/generate-authenticate-options", input, options),
|
|
1288
|
+
verifyRegistration: (input, options) => postGeneric("/passkey/verify-registration", input, options),
|
|
1289
|
+
verifyAuthentication: (input, options) => postGeneric("/passkey/verify-authentication", input, options),
|
|
1290
|
+
listUserPasskeys: (input, options) => getGeneric("/passkey/list-user-passkeys", input, options),
|
|
1291
|
+
deletePasskey: (input, options) => postGeneric("/passkey/delete-passkey", input, options),
|
|
1292
|
+
updatePasskey: (input, options) => postGeneric("/passkey/update-passkey", input, options),
|
|
1293
|
+
getRelatedOrigins: (input, options) => getGeneric("/.well-known/webauthn", input, options)
|
|
1294
|
+
},
|
|
1295
|
+
admin: {
|
|
1296
|
+
role: {
|
|
1297
|
+
set: (input, options) => postGeneric("/admin/set-role", input, options)
|
|
1298
|
+
},
|
|
1299
|
+
user: {
|
|
1300
|
+
list: (input, options) => getWithQuery("/admin/list-users", input, options),
|
|
1301
|
+
create: (input, options) => postGeneric("/admin/create-user", input, options),
|
|
1302
|
+
unban: (input, options) => postGeneric("/admin/unban-user", input, options),
|
|
1303
|
+
ban: (input, options) => postGeneric("/admin/ban-user", input, options),
|
|
1304
|
+
impersonate: (input, options) => postGeneric("/admin/impersonate-user", input, options),
|
|
1305
|
+
stopImpersonating: (input, options) => postGeneric("/admin/stop-impersonating", input, options),
|
|
1306
|
+
remove: (input, options) => postGeneric("/admin/remove-user", input, options),
|
|
1307
|
+
setPassword: (input, options) => postGeneric("/admin/set-user-password", input, options),
|
|
1308
|
+
session: {
|
|
1309
|
+
list: (input, options) => postGeneric("/admin/list-user-sessions", input, options),
|
|
1310
|
+
revoke: adminUserSessionRevokeBinding
|
|
1311
|
+
}
|
|
1312
|
+
},
|
|
1313
|
+
hasPermission: (input, options) => postGeneric("/admin/has-permission", input, options),
|
|
1314
|
+
apiKey: {
|
|
1315
|
+
create: (input, options) => postGeneric("/admin/api-key/create", input, options)
|
|
1316
|
+
},
|
|
1317
|
+
athenaClient: {
|
|
1318
|
+
create: (input, options) => postGeneric("/admin/athena-client/create", input, options),
|
|
1319
|
+
list: (input, options) => getWithQuery("/admin/athena-client/list", input, options)
|
|
1320
|
+
},
|
|
1321
|
+
auditLog: {
|
|
1322
|
+
list: (input, options) => getWithQuery("/admin/audit-log/list", input, options)
|
|
1323
|
+
},
|
|
1324
|
+
email: {
|
|
1325
|
+
list: (input, options) => getWithQuery("/admin/email/list", input, options),
|
|
1326
|
+
get: (input, options) => getWithQuery("/admin/email/get", input, options),
|
|
1327
|
+
create: (input, options) => postGeneric("/admin/email/create", input, options),
|
|
1328
|
+
update: (input, options) => postGeneric("/admin/email/update", input, options),
|
|
1329
|
+
delete: (input, options) => postGeneric("/admin/email/delete", input, options),
|
|
1330
|
+
failure: {
|
|
1331
|
+
list: (input, options) => getWithQuery("/admin/email-failure/list", input, options),
|
|
1332
|
+
get: (input, options) => getWithQuery("/admin/email-failure/get", input, options),
|
|
1333
|
+
create: (input, options) => postGeneric("/admin/email-failure/create", input, options),
|
|
1334
|
+
update: (input, options) => postGeneric("/admin/email-failure/update", input, options),
|
|
1335
|
+
delete: (input, options) => postGeneric("/admin/email-failure/delete", input, options)
|
|
1336
|
+
},
|
|
1337
|
+
template: {
|
|
1338
|
+
list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
|
|
1339
|
+
get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
|
|
1340
|
+
create: (input, options) => postGeneric("/admin/email-template/create", input, options),
|
|
1341
|
+
update: (input, options) => postGeneric("/admin/email-template/update", input, options),
|
|
1342
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
|
|
1343
|
+
}
|
|
1344
|
+
},
|
|
1345
|
+
emailTemplate: {
|
|
1346
|
+
get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
|
|
1347
|
+
create: (input, options) => postGeneric("/admin/email-template/create", input, options),
|
|
1348
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
|
|
1349
|
+
list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
|
|
1350
|
+
update: (input, options) => postGeneric("/admin/email-template/update", input, options)
|
|
1351
|
+
}
|
|
1352
|
+
},
|
|
1353
|
+
apiKey: {
|
|
1354
|
+
create: (input, options) => postGeneric("/api-key/create", input, options),
|
|
1355
|
+
get: (input, options) => getWithQuery("/api-key/get", input, options),
|
|
1356
|
+
update: (input, options) => postGeneric("/api-key/update", input, options),
|
|
1357
|
+
delete: (input, options) => postGeneric("/api-key/delete", input, options),
|
|
1358
|
+
list: (input, options) => getWithQuery("/api-key/list", input, options),
|
|
1359
|
+
verify: (input, options) => postGeneric("/api-key/verify", input, options),
|
|
1360
|
+
deleteAllExpired: (input, options) => executePostWithOptionalInput(
|
|
1361
|
+
resolvedConfig,
|
|
1362
|
+
{ endpoint: "/api-key/delete-all-expired-api-keys", method: "POST" },
|
|
1363
|
+
input,
|
|
1364
|
+
options
|
|
1365
|
+
)
|
|
1366
|
+
},
|
|
1367
|
+
signIn: {
|
|
1368
|
+
email: (input, options) => postGeneric("/sign-in/email", input, options),
|
|
1369
|
+
username: (input, options) => postGeneric("/sign-in/username", input, options),
|
|
1370
|
+
social: (input, options) => postGeneric("/sign-in/social", input, options)
|
|
1371
|
+
},
|
|
1372
|
+
signUp: {
|
|
1373
|
+
email: (input, options) => postGeneric("/sign-up/email", input, options)
|
|
1374
|
+
},
|
|
1375
|
+
organization,
|
|
1376
|
+
callback: {
|
|
1377
|
+
provider: (input, options) => {
|
|
1378
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1379
|
+
const parsed = payload;
|
|
1380
|
+
const provider = String(parsed?.provider ?? "").trim();
|
|
1381
|
+
if (!provider) {
|
|
1382
|
+
throw new Error("callback.provider requires a non-empty provider value");
|
|
1383
|
+
}
|
|
1384
|
+
const code = String(parsed?.code ?? "").trim();
|
|
1385
|
+
const state = String(parsed?.state ?? "").trim();
|
|
1386
|
+
if (!code || !state) {
|
|
1387
|
+
throw new Error("callback.provider requires non-empty code and state values");
|
|
1388
|
+
}
|
|
1389
|
+
const endpoint = `/callback/${encodeURIComponent(provider)}`;
|
|
1390
|
+
return request({
|
|
1391
|
+
endpoint,
|
|
1392
|
+
method: "GET",
|
|
1393
|
+
query: {
|
|
1394
|
+
code,
|
|
1395
|
+
state
|
|
1396
|
+
},
|
|
1397
|
+
fetchOptions
|
|
1398
|
+
}, options);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
return {
|
|
1403
|
+
baseUrl: normalizedBaseUrl,
|
|
1404
|
+
request,
|
|
1405
|
+
signIn: {
|
|
1406
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
1407
|
+
resolvedConfig,
|
|
1408
|
+
{ endpoint: "/sign-in/email", method: "POST" },
|
|
1409
|
+
input,
|
|
1410
|
+
options
|
|
1411
|
+
),
|
|
1412
|
+
username: (input, options) => executePostWithCompatibleInput(
|
|
1413
|
+
resolvedConfig,
|
|
1414
|
+
{ endpoint: "/sign-in/username", method: "POST" },
|
|
1415
|
+
input,
|
|
1416
|
+
options
|
|
1417
|
+
),
|
|
1418
|
+
social: (input, options) => executePostWithCompatibleInput(
|
|
1419
|
+
resolvedConfig,
|
|
1420
|
+
{ endpoint: "/sign-in/social", method: "POST" },
|
|
1421
|
+
input,
|
|
1422
|
+
options
|
|
1423
|
+
)
|
|
1424
|
+
},
|
|
1425
|
+
signUp: {
|
|
1426
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
1427
|
+
resolvedConfig,
|
|
1428
|
+
{ endpoint: "/sign-up/email", method: "POST" },
|
|
1429
|
+
input,
|
|
1430
|
+
options
|
|
1431
|
+
)
|
|
1432
|
+
},
|
|
1433
|
+
signOut,
|
|
1434
|
+
logout: signOut,
|
|
1435
|
+
getSession: (input, options) => executeGetWithCompatibleInput(
|
|
1436
|
+
resolvedConfig,
|
|
1437
|
+
{ endpoint: "/get-session", method: "GET" },
|
|
1438
|
+
input,
|
|
1439
|
+
options
|
|
1440
|
+
),
|
|
1441
|
+
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
1442
|
+
resolvedConfig,
|
|
1443
|
+
{ endpoint: "/list-sessions", method: "GET" },
|
|
1444
|
+
input,
|
|
1445
|
+
options
|
|
1446
|
+
),
|
|
1447
|
+
revokeSession,
|
|
1448
|
+
clearSession: revokeSession,
|
|
1449
|
+
revokeSessions,
|
|
1450
|
+
clearSessions: revokeSessions,
|
|
1451
|
+
revokeOtherSessions,
|
|
1452
|
+
clearOtherSessions: revokeOtherSessions,
|
|
1453
|
+
forgetPassword: (input, options) => executePostWithCompatibleInput(
|
|
1454
|
+
resolvedConfig,
|
|
1455
|
+
{ endpoint: "/forget-password", method: "POST" },
|
|
1456
|
+
input,
|
|
1457
|
+
options
|
|
1458
|
+
),
|
|
1459
|
+
resetPassword: (input, options) => executePostWithCompatibleInput(
|
|
1460
|
+
resolvedConfig,
|
|
1461
|
+
{ endpoint: "/reset-password", method: "POST" },
|
|
1462
|
+
input,
|
|
1463
|
+
options
|
|
1464
|
+
),
|
|
1465
|
+
resolveResetPasswordToken,
|
|
1466
|
+
verifyEmail: (input, options) => {
|
|
1467
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1468
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1469
|
+
const query = payload;
|
|
1470
|
+
return callAuthEndpoint(
|
|
1471
|
+
resolvedConfig,
|
|
1472
|
+
{ endpoint: "/verify-email", method: "GET" },
|
|
1473
|
+
void 0,
|
|
1474
|
+
query ? {
|
|
1475
|
+
token: query.token,
|
|
1476
|
+
callbackURL: query.callbackURL
|
|
1477
|
+
} : void 0,
|
|
1478
|
+
mergedOptions
|
|
1479
|
+
);
|
|
1480
|
+
},
|
|
1481
|
+
sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
|
|
1482
|
+
resolvedConfig,
|
|
1483
|
+
{ endpoint: "/send-verification-email", method: "POST" },
|
|
1484
|
+
input,
|
|
1485
|
+
options
|
|
1486
|
+
),
|
|
1487
|
+
changeEmail: (input, options) => executePostWithCompatibleInput(
|
|
1488
|
+
resolvedConfig,
|
|
1489
|
+
{ endpoint: "/change-email", method: "POST" },
|
|
1490
|
+
input,
|
|
1491
|
+
options
|
|
1492
|
+
),
|
|
1493
|
+
changePassword: (input, options) => executePostWithCompatibleInput(
|
|
1494
|
+
resolvedConfig,
|
|
1495
|
+
{ endpoint: "/change-password", method: "POST" },
|
|
1496
|
+
input,
|
|
1497
|
+
options
|
|
1498
|
+
),
|
|
1499
|
+
updateUser: (input, options) => executePostWithCompatibleInput(
|
|
1500
|
+
resolvedConfig,
|
|
1501
|
+
{ endpoint: "/update-user", method: "POST" },
|
|
1502
|
+
input,
|
|
1503
|
+
options
|
|
1504
|
+
),
|
|
1505
|
+
deleteUser,
|
|
1506
|
+
deleteUserCallback,
|
|
1507
|
+
linkSocial: (input, options) => executePostWithCompatibleInput(
|
|
1508
|
+
resolvedConfig,
|
|
1509
|
+
{ endpoint: "/link-social", method: "POST" },
|
|
1510
|
+
input,
|
|
1511
|
+
options
|
|
1512
|
+
),
|
|
1513
|
+
listAccounts: (input, options) => executeGetWithCompatibleInput(
|
|
1514
|
+
resolvedConfig,
|
|
1515
|
+
{ endpoint: "/list-accounts", method: "GET" },
|
|
1516
|
+
input,
|
|
1517
|
+
options
|
|
1518
|
+
),
|
|
1519
|
+
unlinkAccount: (input, options) => executePostWithCompatibleInput(
|
|
1520
|
+
resolvedConfig,
|
|
1521
|
+
{ endpoint: "/unlink-account", method: "POST" },
|
|
1522
|
+
input,
|
|
1523
|
+
options
|
|
1524
|
+
),
|
|
1525
|
+
refreshToken: (input, options) => executePostWithCompatibleInput(
|
|
1526
|
+
resolvedConfig,
|
|
1527
|
+
{ endpoint: "/refresh-token", method: "POST" },
|
|
1528
|
+
input,
|
|
1529
|
+
options
|
|
1530
|
+
),
|
|
1531
|
+
getAccessToken: (input, options) => executePostWithCompatibleInput(
|
|
1532
|
+
resolvedConfig,
|
|
1533
|
+
{ endpoint: "/get-access-token", method: "POST" },
|
|
1534
|
+
input,
|
|
1535
|
+
options
|
|
1536
|
+
),
|
|
1537
|
+
organization,
|
|
1538
|
+
auth
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// src/client.ts
|
|
1543
|
+
var DEFAULT_COLUMNS = "*";
|
|
1544
|
+
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;
|
|
1545
|
+
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
1546
|
+
function formatResult(response) {
|
|
1547
|
+
const result = {
|
|
1548
|
+
data: response.data ?? null,
|
|
1549
|
+
error: response.error ?? null,
|
|
1550
|
+
errorDetails: response.errorDetails ?? null,
|
|
1551
|
+
status: response.status,
|
|
1552
|
+
raw: response.raw
|
|
1553
|
+
};
|
|
1554
|
+
if (response.count !== void 0) {
|
|
1555
|
+
result.count = response.count;
|
|
1556
|
+
}
|
|
1557
|
+
return result;
|
|
1558
|
+
}
|
|
1559
|
+
function toSingleResult(response) {
|
|
1560
|
+
const payload = response.data;
|
|
1561
|
+
const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
|
|
1562
|
+
return {
|
|
1563
|
+
...response,
|
|
1564
|
+
data: singleData
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
function mergeOptions(...options) {
|
|
1568
|
+
return options.reduce((acc, next) => {
|
|
1569
|
+
if (!next) return acc;
|
|
1570
|
+
return { ...acc, ...next };
|
|
1571
|
+
}, void 0);
|
|
1572
|
+
}
|
|
1573
|
+
function asAthenaJsonObject(value) {
|
|
1574
|
+
return value;
|
|
1575
|
+
}
|
|
1576
|
+
function asAthenaJsonObjectArray(values) {
|
|
1577
|
+
return values;
|
|
1578
|
+
}
|
|
1579
|
+
function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS) {
|
|
1580
|
+
let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
|
|
1581
|
+
let selectedOptions;
|
|
1582
|
+
let promise = null;
|
|
1583
|
+
const run = (columns, options) => {
|
|
1584
|
+
const payloadColumns = columns ?? selectedColumns;
|
|
1585
|
+
const payloadOptions = options ?? selectedOptions;
|
|
1586
|
+
if (!promise) {
|
|
1587
|
+
promise = executor(payloadColumns, payloadOptions);
|
|
1588
|
+
}
|
|
1589
|
+
return promise;
|
|
1590
|
+
};
|
|
1591
|
+
const mutationQuery = {
|
|
1592
|
+
select(columns = selectedColumns, options) {
|
|
1593
|
+
selectedColumns = columns;
|
|
1594
|
+
selectedOptions = options ?? selectedOptions;
|
|
1595
|
+
return run(columns, options);
|
|
1596
|
+
},
|
|
1597
|
+
returning(columns = selectedColumns, options) {
|
|
1598
|
+
return mutationQuery.select(columns, options);
|
|
1599
|
+
},
|
|
1600
|
+
single(columns = selectedColumns, options) {
|
|
1601
|
+
selectedColumns = columns;
|
|
1602
|
+
selectedOptions = options ?? selectedOptions;
|
|
1603
|
+
return run(columns, options).then(toSingleResult);
|
|
1604
|
+
},
|
|
1605
|
+
maybeSingle(columns = selectedColumns, options) {
|
|
1606
|
+
return mutationQuery.single(columns, options);
|
|
1607
|
+
},
|
|
1608
|
+
then(onfulfilled, onrejected) {
|
|
1609
|
+
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
1610
|
+
},
|
|
1611
|
+
catch(onrejected) {
|
|
1612
|
+
return run(selectedColumns, selectedOptions).catch(onrejected);
|
|
1613
|
+
},
|
|
1614
|
+
finally(onfinally) {
|
|
1615
|
+
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
return mutationQuery;
|
|
1619
|
+
}
|
|
1620
|
+
function getResourceId(state) {
|
|
1621
|
+
const candidate = state.conditions.find(
|
|
1622
|
+
(condition) => condition.operator === "eq" && (condition.column === "resource_id" || condition.column === "id")
|
|
1623
|
+
);
|
|
1624
|
+
return candidate?.value?.toString();
|
|
1625
|
+
}
|
|
1626
|
+
function stringifyFilterValue(value) {
|
|
1627
|
+
if (Array.isArray(value)) {
|
|
1628
|
+
return value.join(",");
|
|
1629
|
+
}
|
|
1630
|
+
return String(value);
|
|
1631
|
+
}
|
|
1632
|
+
function isUuidString(value) {
|
|
1633
|
+
return UUID_PATTERN.test(value.trim());
|
|
1634
|
+
}
|
|
1635
|
+
function isUuidIdentifierColumn(column) {
|
|
1636
|
+
return column === "id" || /(?:^|_)uuid(?:_|$)/i.test(column) || /_id$/i.test(column);
|
|
1637
|
+
}
|
|
1638
|
+
function shouldUseUuidTextComparison(column, value) {
|
|
1639
|
+
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
1640
|
+
}
|
|
1641
|
+
function normalizeCast(cast) {
|
|
1642
|
+
const normalized = cast.trim().toLowerCase();
|
|
1643
|
+
if (!SAFE_CAST_PATTERN.test(normalized)) {
|
|
1644
|
+
throw new Error(`Invalid cast type "${cast}"`);
|
|
1645
|
+
}
|
|
1646
|
+
return normalized;
|
|
1647
|
+
}
|
|
1648
|
+
function escapeSqlStringLiteral(value) {
|
|
1649
|
+
return value.replace(/'/g, "''");
|
|
1650
|
+
}
|
|
1651
|
+
function toSqlLiteral(value) {
|
|
1652
|
+
if (value === null) return "NULL";
|
|
1653
|
+
if (typeof value === "number") return Number.isFinite(value) ? String(value) : "NULL";
|
|
1654
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
1655
|
+
return `'${escapeSqlStringLiteral(value)}'`;
|
|
1656
|
+
}
|
|
1657
|
+
function withCast(expression, cast) {
|
|
1658
|
+
if (!cast) return expression;
|
|
1659
|
+
return `${expression}::${normalizeCast(cast)}`;
|
|
1660
|
+
}
|
|
1661
|
+
function buildSelectColumnsClause(columns) {
|
|
1662
|
+
if (Array.isArray(columns)) {
|
|
1663
|
+
return columns.map((column) => quoteQualifiedIdentifier(column)).join(", ");
|
|
1664
|
+
}
|
|
1665
|
+
return quoteSelectColumnsExpression(columns);
|
|
1666
|
+
}
|
|
1667
|
+
function resolveTableNameForCall(tableName, schema) {
|
|
1668
|
+
if (!schema) return tableName;
|
|
1669
|
+
const normalizedSchema = schema.trim();
|
|
1670
|
+
if (!normalizedSchema) {
|
|
1671
|
+
throw new Error("schema option must be a non-empty string");
|
|
1672
|
+
}
|
|
1673
|
+
if (tableName.includes(".")) {
|
|
1674
|
+
if (tableName.startsWith(`${normalizedSchema}.`)) {
|
|
1675
|
+
return tableName;
|
|
1676
|
+
}
|
|
1677
|
+
throw new Error(
|
|
1678
|
+
`schema option "${normalizedSchema}" conflicts with schema-qualified table "${tableName}"`
|
|
1679
|
+
);
|
|
1680
|
+
}
|
|
1681
|
+
return `${normalizedSchema}.${tableName}`;
|
|
1682
|
+
}
|
|
1683
|
+
function conditionToSqlClause(condition) {
|
|
1684
|
+
if (!condition.column) return null;
|
|
1685
|
+
const column = withCast(quoteQualifiedIdentifier(condition.column), condition.column_cast);
|
|
1686
|
+
const value = condition.value;
|
|
1687
|
+
const sqlOperator = {
|
|
1688
|
+
eq: "=",
|
|
1689
|
+
neq: "!=",
|
|
1690
|
+
gt: ">",
|
|
1691
|
+
gte: ">=",
|
|
1692
|
+
lt: "<",
|
|
1693
|
+
lte: "<=",
|
|
1694
|
+
like: "LIKE",
|
|
1695
|
+
ilike: "ILIKE"
|
|
1696
|
+
};
|
|
1697
|
+
switch (condition.operator) {
|
|
1698
|
+
case "eq":
|
|
1699
|
+
case "neq":
|
|
1700
|
+
case "gt":
|
|
1701
|
+
case "gte":
|
|
1702
|
+
case "lt":
|
|
1703
|
+
case "lte":
|
|
1704
|
+
case "like":
|
|
1705
|
+
case "ilike": {
|
|
1706
|
+
if (Array.isArray(value) || value === void 0) return null;
|
|
1707
|
+
const rhs = withCast(toSqlLiteral(value), condition.value_cast);
|
|
1708
|
+
return `${column} ${sqlOperator[condition.operator]} ${rhs}`;
|
|
1709
|
+
}
|
|
1710
|
+
case "is": {
|
|
1711
|
+
if (value === null) return `${column} IS NULL`;
|
|
1712
|
+
if (value === true) return `${column} IS TRUE`;
|
|
1713
|
+
if (value === false) return `${column} IS FALSE`;
|
|
1714
|
+
return null;
|
|
1715
|
+
}
|
|
1716
|
+
case "in": {
|
|
1717
|
+
if (!Array.isArray(value)) return null;
|
|
1718
|
+
if (value.length === 0) return "FALSE";
|
|
1719
|
+
const values = value.map((item) => withCast(toSqlLiteral(item), condition.value_cast));
|
|
1720
|
+
return `${column} IN (${values.join(", ")})`;
|
|
1721
|
+
}
|
|
1722
|
+
default:
|
|
1723
|
+
return null;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
function buildTypedSelectQuery(input) {
|
|
1727
|
+
const whereClauses = [];
|
|
1728
|
+
for (const condition of input.conditions) {
|
|
1729
|
+
const clause = conditionToSqlClause(condition);
|
|
1730
|
+
if (!clause) return null;
|
|
1731
|
+
whereClauses.push(clause);
|
|
1732
|
+
}
|
|
1733
|
+
let limit = input.limit;
|
|
1734
|
+
let offset = input.offset;
|
|
1735
|
+
if (limit === void 0 && input.pageSize !== void 0) {
|
|
1736
|
+
limit = input.pageSize;
|
|
1737
|
+
}
|
|
1738
|
+
if (offset === void 0 && input.pageSize !== void 0 && input.currentPage !== void 0 && input.currentPage > 0) {
|
|
1739
|
+
offset = (input.currentPage - 1) * input.pageSize;
|
|
1740
|
+
}
|
|
1741
|
+
const sqlParts = [
|
|
1742
|
+
`SELECT ${buildSelectColumnsClause(input.columns)} FROM ${quoteQualifiedIdentifier(input.tableName)}`
|
|
1743
|
+
];
|
|
1744
|
+
if (whereClauses.length > 0) {
|
|
1745
|
+
sqlParts.push(`WHERE ${whereClauses.join(" AND ")}`);
|
|
1746
|
+
}
|
|
1747
|
+
if (input.order?.field) {
|
|
1748
|
+
const direction = input.order.direction === "descending" ? "DESC" : "ASC";
|
|
1749
|
+
sqlParts.push(`ORDER BY ${quoteQualifiedIdentifier(input.order.field)} ${direction}`);
|
|
1750
|
+
}
|
|
1751
|
+
if (limit !== void 0) {
|
|
1752
|
+
sqlParts.push(`LIMIT ${Math.max(0, Math.trunc(limit))}`);
|
|
1753
|
+
}
|
|
1754
|
+
if (offset !== void 0) {
|
|
1755
|
+
sqlParts.push(`OFFSET ${Math.max(0, Math.trunc(offset))}`);
|
|
1756
|
+
}
|
|
1757
|
+
return `${sqlParts.join(" ")};`;
|
|
1758
|
+
}
|
|
1759
|
+
function createFilterMethods(state, addCondition, self) {
|
|
1760
|
+
return {
|
|
1761
|
+
eq(column, value) {
|
|
1762
|
+
const columnName = String(column);
|
|
1763
|
+
if (shouldUseUuidTextComparison(columnName, value)) {
|
|
1764
|
+
addCondition("eq", columnName, value, { columnCast: "text" });
|
|
1765
|
+
} else {
|
|
1766
|
+
addCondition("eq", columnName, value);
|
|
1767
|
+
}
|
|
1768
|
+
return self;
|
|
1769
|
+
},
|
|
1770
|
+
eqCast(column, value, cast) {
|
|
1771
|
+
addCondition("eq", String(column), value, { valueCast: cast });
|
|
1772
|
+
return self;
|
|
1773
|
+
},
|
|
1774
|
+
eqUuid(column, value) {
|
|
1775
|
+
addCondition("eq", String(column), value, { valueCast: "uuid" });
|
|
1776
|
+
return self;
|
|
1777
|
+
},
|
|
1778
|
+
match(filters) {
|
|
1779
|
+
Object.entries(filters).forEach(([column, value]) => {
|
|
1780
|
+
if (value === void 0) {
|
|
1781
|
+
return;
|
|
1782
|
+
}
|
|
1783
|
+
if (shouldUseUuidTextComparison(column, value)) {
|
|
1784
|
+
addCondition("eq", column, value, { columnCast: "text" });
|
|
1785
|
+
} else {
|
|
1786
|
+
addCondition("eq", column, value);
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
return self;
|
|
1790
|
+
},
|
|
1791
|
+
range(from, to) {
|
|
1792
|
+
state.offset = from;
|
|
1793
|
+
state.limit = to - from + 1;
|
|
1794
|
+
return self;
|
|
1795
|
+
},
|
|
1796
|
+
limit(count) {
|
|
1797
|
+
state.limit = count;
|
|
1798
|
+
return self;
|
|
1799
|
+
},
|
|
1800
|
+
offset(count) {
|
|
1801
|
+
state.offset = count;
|
|
1802
|
+
return self;
|
|
1803
|
+
},
|
|
1804
|
+
currentPage(value) {
|
|
1805
|
+
state.currentPage = value;
|
|
1806
|
+
return self;
|
|
1807
|
+
},
|
|
1808
|
+
pageSize(value) {
|
|
1809
|
+
state.pageSize = value;
|
|
1810
|
+
return self;
|
|
1811
|
+
},
|
|
1812
|
+
totalPages(value) {
|
|
1813
|
+
state.totalPages = value;
|
|
1814
|
+
return self;
|
|
1815
|
+
},
|
|
1816
|
+
order(column, options) {
|
|
1817
|
+
state.order = {
|
|
1818
|
+
field: String(column),
|
|
1819
|
+
direction: options?.ascending === false ? "descending" : "ascending"
|
|
1820
|
+
};
|
|
1821
|
+
return self;
|
|
1822
|
+
},
|
|
1823
|
+
gt(column, value) {
|
|
1824
|
+
addCondition("gt", String(column), value);
|
|
1825
|
+
return self;
|
|
1826
|
+
},
|
|
1827
|
+
gte(column, value) {
|
|
1828
|
+
addCondition("gte", String(column), value);
|
|
1829
|
+
return self;
|
|
1830
|
+
},
|
|
1831
|
+
lt(column, value) {
|
|
1832
|
+
addCondition("lt", String(column), value);
|
|
1833
|
+
return self;
|
|
1834
|
+
},
|
|
1835
|
+
lte(column, value) {
|
|
1836
|
+
addCondition("lte", String(column), value);
|
|
1837
|
+
return self;
|
|
1838
|
+
},
|
|
1839
|
+
neq(column, value) {
|
|
1840
|
+
addCondition("neq", String(column), value);
|
|
1841
|
+
return self;
|
|
1842
|
+
},
|
|
1843
|
+
like(column, value) {
|
|
1844
|
+
addCondition("like", String(column), value);
|
|
1845
|
+
return self;
|
|
1846
|
+
},
|
|
1847
|
+
ilike(column, value) {
|
|
1848
|
+
addCondition("ilike", String(column), value);
|
|
1849
|
+
return self;
|
|
1850
|
+
},
|
|
1851
|
+
is(column, value) {
|
|
1852
|
+
addCondition("is", String(column), value);
|
|
1853
|
+
return self;
|
|
1854
|
+
},
|
|
1855
|
+
in(column, values) {
|
|
1856
|
+
addCondition("in", String(column), values);
|
|
1857
|
+
return self;
|
|
1858
|
+
},
|
|
1859
|
+
contains(column, values) {
|
|
1860
|
+
addCondition("contains", String(column), values);
|
|
1861
|
+
return self;
|
|
1862
|
+
},
|
|
1863
|
+
containedBy(column, values) {
|
|
1864
|
+
addCondition("containedBy", String(column), values);
|
|
1865
|
+
return self;
|
|
1866
|
+
},
|
|
1867
|
+
not(columnOrExpression, operator, value) {
|
|
1868
|
+
const expression = String(columnOrExpression);
|
|
1869
|
+
if (operator != null && value !== void 0) {
|
|
1870
|
+
addCondition("not", void 0, `${expression}.${operator}.${stringifyFilterValue(value)}`);
|
|
1871
|
+
} else {
|
|
1872
|
+
addCondition("not", void 0, expression);
|
|
1873
|
+
}
|
|
1874
|
+
return self;
|
|
1875
|
+
},
|
|
1876
|
+
or(expression) {
|
|
1877
|
+
addCondition("or", void 0, expression);
|
|
1878
|
+
return self;
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
function toRpcSelect(columns) {
|
|
1883
|
+
if (!columns) return void 0;
|
|
1884
|
+
return Array.isArray(columns) ? columns.join(",") : columns;
|
|
1885
|
+
}
|
|
1886
|
+
function createRpcFilterMethods(filters, self) {
|
|
1887
|
+
const addFilter = (operator, column, value) => {
|
|
1888
|
+
filters.push({ column, operator, value });
|
|
1889
|
+
};
|
|
1890
|
+
return {
|
|
1891
|
+
eq(column, value) {
|
|
1892
|
+
addFilter("eq", column, value);
|
|
1893
|
+
return self;
|
|
1894
|
+
},
|
|
1895
|
+
neq(column, value) {
|
|
1896
|
+
addFilter("neq", column, value);
|
|
1897
|
+
return self;
|
|
1898
|
+
},
|
|
1899
|
+
gt(column, value) {
|
|
1900
|
+
addFilter("gt", column, value);
|
|
1901
|
+
return self;
|
|
1902
|
+
},
|
|
1903
|
+
gte(column, value) {
|
|
1904
|
+
addFilter("gte", column, value);
|
|
1905
|
+
return self;
|
|
1906
|
+
},
|
|
1907
|
+
lt(column, value) {
|
|
1908
|
+
addFilter("lt", column, value);
|
|
1909
|
+
return self;
|
|
1910
|
+
},
|
|
1911
|
+
lte(column, value) {
|
|
1912
|
+
addFilter("lte", column, value);
|
|
1913
|
+
return self;
|
|
1914
|
+
},
|
|
1915
|
+
like(column, value) {
|
|
1916
|
+
addFilter("like", column, value);
|
|
1917
|
+
return self;
|
|
1918
|
+
},
|
|
1919
|
+
ilike(column, value) {
|
|
1920
|
+
addFilter("ilike", column, value);
|
|
1921
|
+
return self;
|
|
1922
|
+
},
|
|
1923
|
+
is(column, value) {
|
|
1924
|
+
addFilter("is", column, value);
|
|
1925
|
+
return self;
|
|
1926
|
+
},
|
|
1927
|
+
in(column, values) {
|
|
1928
|
+
addFilter("in", column, values);
|
|
1929
|
+
return self;
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
function createRpcBuilder(functionName, args, baseOptions, client) {
|
|
1934
|
+
const state = {
|
|
1935
|
+
filters: []
|
|
1936
|
+
};
|
|
1937
|
+
let selectedColumns;
|
|
1938
|
+
let selectedOptions;
|
|
1939
|
+
let promise = null;
|
|
1940
|
+
const executeRpc = async (columns, options) => {
|
|
1941
|
+
const mergedOptions = mergeOptions(baseOptions, options);
|
|
1942
|
+
const payload = {
|
|
1943
|
+
function: functionName,
|
|
1944
|
+
args,
|
|
1945
|
+
schema: mergedOptions?.schema,
|
|
1946
|
+
select: toRpcSelect(columns),
|
|
1947
|
+
filters: state.filters.length ? [...state.filters] : void 0,
|
|
1948
|
+
count: mergedOptions?.count,
|
|
1949
|
+
head: mergedOptions?.head,
|
|
1950
|
+
limit: state.limit,
|
|
1951
|
+
offset: state.offset,
|
|
1952
|
+
order: state.order
|
|
1953
|
+
};
|
|
1954
|
+
const response = await client.rpcGateway(payload, mergedOptions);
|
|
1955
|
+
return formatResult(response);
|
|
1956
|
+
};
|
|
1957
|
+
const run = (columns, options) => {
|
|
1958
|
+
const payloadColumns = columns ?? selectedColumns;
|
|
1959
|
+
const payloadOptions = options ?? selectedOptions;
|
|
1960
|
+
if (!promise) {
|
|
1961
|
+
promise = executeRpc(payloadColumns, payloadOptions);
|
|
1962
|
+
}
|
|
1963
|
+
return promise;
|
|
1964
|
+
};
|
|
1965
|
+
const builder = {};
|
|
1966
|
+
const filterMethods = createRpcFilterMethods(state.filters, builder);
|
|
1967
|
+
Object.assign(builder, filterMethods, {
|
|
1968
|
+
select(columns = selectedColumns, options) {
|
|
1969
|
+
selectedColumns = columns;
|
|
1970
|
+
selectedOptions = options ?? selectedOptions;
|
|
1971
|
+
return run(columns, options);
|
|
1972
|
+
},
|
|
1973
|
+
async single(columns, options) {
|
|
1974
|
+
const result = await run(columns, options);
|
|
1975
|
+
return toSingleResult(result);
|
|
1976
|
+
},
|
|
1977
|
+
maybeSingle(columns, options) {
|
|
1978
|
+
return builder.single(columns, options);
|
|
1979
|
+
},
|
|
1980
|
+
order(column, options) {
|
|
1981
|
+
state.order = { column, ascending: options?.ascending ?? true };
|
|
1982
|
+
return builder;
|
|
1983
|
+
},
|
|
1984
|
+
limit(count) {
|
|
1985
|
+
state.limit = count;
|
|
1986
|
+
return builder;
|
|
1987
|
+
},
|
|
1988
|
+
offset(count) {
|
|
1989
|
+
state.offset = count;
|
|
1990
|
+
return builder;
|
|
1991
|
+
},
|
|
1992
|
+
range(from, to) {
|
|
1993
|
+
state.offset = from;
|
|
1994
|
+
state.limit = to - from + 1;
|
|
1995
|
+
return builder;
|
|
1996
|
+
},
|
|
1997
|
+
then(onfulfilled, onrejected) {
|
|
1998
|
+
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
1999
|
+
},
|
|
2000
|
+
catch(onrejected) {
|
|
2001
|
+
return run(selectedColumns, selectedOptions).catch(onrejected);
|
|
2002
|
+
},
|
|
2003
|
+
finally(onfinally) {
|
|
2004
|
+
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
return builder;
|
|
2008
|
+
}
|
|
2009
|
+
function createTableBuilder(tableName, client) {
|
|
2010
|
+
const state = {
|
|
2011
|
+
conditions: []
|
|
2012
|
+
};
|
|
2013
|
+
const addCondition = (operator, column, value, hints) => {
|
|
2014
|
+
const condition = { operator };
|
|
2015
|
+
if (column) {
|
|
2016
|
+
condition.column = column;
|
|
2017
|
+
if (operator === "eq") {
|
|
2018
|
+
condition.eq_column = column;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
if (value !== void 0) {
|
|
2022
|
+
condition.value = value;
|
|
2023
|
+
if (operator === "eq") {
|
|
2024
|
+
condition.eq_value = value;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
if (hints?.valueCast) {
|
|
2028
|
+
condition.value_cast = hints.valueCast;
|
|
2029
|
+
if (operator === "eq") {
|
|
2030
|
+
condition.eq_value_cast = hints.valueCast;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
if (hints?.columnCast) {
|
|
2034
|
+
condition.column_cast = hints.columnCast;
|
|
2035
|
+
if (operator === "eq") {
|
|
2036
|
+
condition.eq_column_cast = hints.columnCast;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
state.conditions.push(condition);
|
|
2040
|
+
};
|
|
2041
|
+
const builder = {};
|
|
2042
|
+
const filterMethods = createFilterMethods(
|
|
2043
|
+
state,
|
|
2044
|
+
addCondition,
|
|
2045
|
+
builder
|
|
2046
|
+
);
|
|
2047
|
+
const runSelect = async (columns = DEFAULT_COLUMNS, options) => {
|
|
2048
|
+
const resolvedTableName = resolveTableNameForCall(tableName, options?.schema);
|
|
2049
|
+
const conditions = state.conditions.length ? state.conditions.map((condition) => ({ ...condition })) : void 0;
|
|
2050
|
+
const hasTypedEqualityComparison = conditions?.some(
|
|
2051
|
+
(condition) => condition.operator === "eq" && (condition.value_cast !== void 0 || condition.column_cast !== void 0)
|
|
2052
|
+
) ?? false;
|
|
2053
|
+
if (hasTypedEqualityComparison && !options?.head && !options?.count && conditions) {
|
|
2054
|
+
const query = buildTypedSelectQuery({
|
|
2055
|
+
tableName: resolvedTableName,
|
|
2056
|
+
columns,
|
|
2057
|
+
conditions,
|
|
2058
|
+
limit: state.limit,
|
|
2059
|
+
offset: state.offset,
|
|
2060
|
+
currentPage: state.currentPage,
|
|
2061
|
+
pageSize: state.pageSize,
|
|
2062
|
+
order: state.order
|
|
2063
|
+
});
|
|
2064
|
+
if (query) {
|
|
2065
|
+
const queryResponse = await client.queryGateway({ query }, options);
|
|
2066
|
+
return formatResult(queryResponse);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
const payload = {
|
|
2070
|
+
table_name: resolvedTableName,
|
|
2071
|
+
columns,
|
|
2072
|
+
conditions,
|
|
2073
|
+
limit: state.limit,
|
|
2074
|
+
offset: state.offset,
|
|
2075
|
+
current_page: state.currentPage,
|
|
2076
|
+
page_size: state.pageSize,
|
|
2077
|
+
total_pages: state.totalPages,
|
|
2078
|
+
sort_by: state.order,
|
|
2079
|
+
strip_nulls: options?.stripNulls ?? true,
|
|
2080
|
+
count: options?.count,
|
|
2081
|
+
head: options?.head
|
|
2082
|
+
};
|
|
2083
|
+
const response = await client.fetchGateway(payload, options);
|
|
2084
|
+
return formatResult(response);
|
|
2085
|
+
};
|
|
2086
|
+
const createSelectChain = (columns, options) => {
|
|
2087
|
+
const chain = {};
|
|
2088
|
+
const filterMethods2 = createFilterMethods(state, addCondition, chain);
|
|
2089
|
+
Object.assign(chain, filterMethods2, {
|
|
2090
|
+
async single(cols, opts) {
|
|
2091
|
+
const r = await runSelect(cols ?? columns, opts ?? options);
|
|
2092
|
+
return toSingleResult(r);
|
|
2093
|
+
},
|
|
2094
|
+
maybeSingle(cols, opts) {
|
|
2095
|
+
return chain.single(cols, opts);
|
|
2096
|
+
},
|
|
2097
|
+
then(onfulfilled, onrejected) {
|
|
2098
|
+
return runSelect(columns, options).then(onfulfilled, onrejected);
|
|
2099
|
+
},
|
|
2100
|
+
catch(onrejected) {
|
|
2101
|
+
return runSelect(columns, options).catch(onrejected);
|
|
2102
|
+
},
|
|
2103
|
+
finally(onfinally) {
|
|
2104
|
+
return runSelect(columns, options).finally(onfinally);
|
|
2105
|
+
}
|
|
2106
|
+
});
|
|
2107
|
+
return chain;
|
|
2108
|
+
};
|
|
2109
|
+
Object.assign(builder, filterMethods, {
|
|
2110
|
+
reset() {
|
|
2111
|
+
state.conditions = [];
|
|
1042
2112
|
state.limit = void 0;
|
|
1043
2113
|
state.offset = void 0;
|
|
1044
2114
|
state.order = void 0;
|
|
@@ -1054,9 +2124,10 @@ function createTableBuilder(tableName, client) {
|
|
|
1054
2124
|
if (Array.isArray(values)) {
|
|
1055
2125
|
const executeInsertMany = async (columns, selectOptions) => {
|
|
1056
2126
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2127
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1057
2128
|
const payload = {
|
|
1058
|
-
table_name:
|
|
1059
|
-
insert_body: values
|
|
2129
|
+
table_name: resolvedTableName,
|
|
2130
|
+
insert_body: asAthenaJsonObjectArray(values)
|
|
1060
2131
|
};
|
|
1061
2132
|
if (columns) payload.columns = columns;
|
|
1062
2133
|
if (mergedOptions?.count) payload.count = mergedOptions.count;
|
|
@@ -1071,9 +2142,10 @@ function createTableBuilder(tableName, client) {
|
|
|
1071
2142
|
}
|
|
1072
2143
|
const executeInsertOne = async (columns, selectOptions) => {
|
|
1073
2144
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2145
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1074
2146
|
const payload = {
|
|
1075
|
-
table_name:
|
|
1076
|
-
insert_body: values
|
|
2147
|
+
table_name: resolvedTableName,
|
|
2148
|
+
insert_body: asAthenaJsonObject(values)
|
|
1077
2149
|
};
|
|
1078
2150
|
if (columns) payload.columns = columns;
|
|
1079
2151
|
if (mergedOptions?.count) payload.count = mergedOptions.count;
|
|
@@ -1090,10 +2162,11 @@ function createTableBuilder(tableName, client) {
|
|
|
1090
2162
|
if (Array.isArray(values)) {
|
|
1091
2163
|
const executeUpsertMany = async (columns, selectOptions) => {
|
|
1092
2164
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2165
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1093
2166
|
const payload = {
|
|
1094
|
-
table_name:
|
|
1095
|
-
insert_body: values,
|
|
1096
|
-
update_body: options?.updateBody ? options.updateBody : void 0
|
|
2167
|
+
table_name: resolvedTableName,
|
|
2168
|
+
insert_body: asAthenaJsonObjectArray(values),
|
|
2169
|
+
update_body: options?.updateBody ? asAthenaJsonObject(options.updateBody) : void 0
|
|
1097
2170
|
};
|
|
1098
2171
|
if (columns) payload.columns = columns;
|
|
1099
2172
|
if (options?.onConflict) payload.on_conflict = options.onConflict;
|
|
@@ -1109,10 +2182,11 @@ function createTableBuilder(tableName, client) {
|
|
|
1109
2182
|
}
|
|
1110
2183
|
const executeUpsertOne = async (columns, selectOptions) => {
|
|
1111
2184
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2185
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1112
2186
|
const payload = {
|
|
1113
|
-
table_name:
|
|
1114
|
-
insert_body: values,
|
|
1115
|
-
update_body: options?.updateBody ? options.updateBody : void 0
|
|
2187
|
+
table_name: resolvedTableName,
|
|
2188
|
+
insert_body: asAthenaJsonObject(values),
|
|
2189
|
+
update_body: options?.updateBody ? asAthenaJsonObject(options.updateBody) : void 0
|
|
1116
2190
|
};
|
|
1117
2191
|
if (columns) payload.columns = columns;
|
|
1118
2192
|
if (options?.onConflict) payload.on_conflict = options.onConflict;
|
|
@@ -1130,9 +2204,10 @@ function createTableBuilder(tableName, client) {
|
|
|
1130
2204
|
const executeUpdate = async (columns, selectOptions) => {
|
|
1131
2205
|
const filters = state.conditions.length ? [...state.conditions] : void 0;
|
|
1132
2206
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2207
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1133
2208
|
const payload = {
|
|
1134
|
-
table_name:
|
|
1135
|
-
set: values,
|
|
2209
|
+
table_name: resolvedTableName,
|
|
2210
|
+
set: asAthenaJsonObject(values),
|
|
1136
2211
|
conditions: filters,
|
|
1137
2212
|
strip_nulls: mergedOptions?.stripNulls ?? true
|
|
1138
2213
|
};
|
|
@@ -1158,8 +2233,9 @@ function createTableBuilder(tableName, client) {
|
|
|
1158
2233
|
}
|
|
1159
2234
|
const executeDelete = async (columns, selectOptions) => {
|
|
1160
2235
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2236
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
1161
2237
|
const payload = {
|
|
1162
|
-
table_name:
|
|
2238
|
+
table_name: resolvedTableName,
|
|
1163
2239
|
resource_id: resourceId,
|
|
1164
2240
|
conditions: filters
|
|
1165
2241
|
};
|
|
@@ -1201,6 +2277,7 @@ function createClientFromConfig(config) {
|
|
|
1201
2277
|
backend: config.backend,
|
|
1202
2278
|
headers: config.headers
|
|
1203
2279
|
});
|
|
2280
|
+
const auth = createAuthClient(config.auth);
|
|
1204
2281
|
return {
|
|
1205
2282
|
from(table) {
|
|
1206
2283
|
return createTableBuilder(table, gateway);
|
|
@@ -1217,7 +2294,8 @@ function createClientFromConfig(config) {
|
|
|
1217
2294
|
gateway
|
|
1218
2295
|
);
|
|
1219
2296
|
},
|
|
1220
|
-
query: createQueryBuilder(gateway)
|
|
2297
|
+
query: createQueryBuilder(gateway),
|
|
2298
|
+
auth: auth.auth
|
|
1221
2299
|
};
|
|
1222
2300
|
}
|
|
1223
2301
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
@@ -1291,7 +2369,11 @@ function createClient(url, apiKey, options) {
|
|
|
1291
2369
|
const b = AthenaClient.builder().url(url).key(apiKey).backend(toBackendConfig(options?.backend));
|
|
1292
2370
|
if (options?.client) b.client(options.client);
|
|
1293
2371
|
if (options?.headers && Object.keys(options.headers).length > 0) b.headers(options.headers);
|
|
1294
|
-
|
|
2372
|
+
const client = b.build();
|
|
2373
|
+
if (options?.auth) {
|
|
2374
|
+
client.auth = createAuthClient(options.auth).auth;
|
|
2375
|
+
}
|
|
2376
|
+
return client;
|
|
1295
2377
|
}
|
|
1296
2378
|
|
|
1297
2379
|
// src/gateway/types.ts
|
|
@@ -1331,6 +2413,17 @@ var AthenaErrorCategory = {
|
|
|
1331
2413
|
Database: "database",
|
|
1332
2414
|
Unknown: "unknown"
|
|
1333
2415
|
};
|
|
2416
|
+
function parseBooleanFlag(rawValue, fallback) {
|
|
2417
|
+
if (!rawValue) return fallback;
|
|
2418
|
+
const normalized = rawValue.trim().toLowerCase();
|
|
2419
|
+
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
|
|
2420
|
+
return true;
|
|
2421
|
+
}
|
|
2422
|
+
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
|
|
2423
|
+
return false;
|
|
2424
|
+
}
|
|
2425
|
+
return fallback;
|
|
2426
|
+
}
|
|
1334
2427
|
var AthenaError = class extends Error {
|
|
1335
2428
|
code;
|
|
1336
2429
|
kind;
|
|
@@ -1353,7 +2446,7 @@ var AthenaError = class extends Error {
|
|
|
1353
2446
|
this.raw = input.raw;
|
|
1354
2447
|
}
|
|
1355
2448
|
};
|
|
1356
|
-
function
|
|
2449
|
+
function isRecord3(value) {
|
|
1357
2450
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1358
2451
|
}
|
|
1359
2452
|
function safeStringify(value) {
|
|
@@ -1370,7 +2463,7 @@ function contextHint(context) {
|
|
|
1370
2463
|
return `Identity: ${identity}`;
|
|
1371
2464
|
}
|
|
1372
2465
|
function isAthenaResultLike(value) {
|
|
1373
|
-
return
|
|
2466
|
+
return isRecord3(value) && "status" in value && "error" in value && "data" in value && typeof value.status === "number";
|
|
1374
2467
|
}
|
|
1375
2468
|
function operationFromDetails(details) {
|
|
1376
2469
|
if (!details?.endpoint) return void 0;
|
|
@@ -1536,7 +2629,7 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
1536
2629
|
};
|
|
1537
2630
|
}
|
|
1538
2631
|
if (resultOrError instanceof Error) {
|
|
1539
|
-
const maybeStatus =
|
|
2632
|
+
const maybeStatus = isRecord3(resultOrError) && typeof resultOrError.status === "number" ? resultOrError.status : void 0;
|
|
1540
2633
|
const kind2 = classifyKind(maybeStatus, void 0, resultOrError.message);
|
|
1541
2634
|
return {
|
|
1542
2635
|
kind: kind2,
|
|
@@ -2272,6 +3365,67 @@ function createPostgresIntrospectionProvider(options) {
|
|
|
2272
3365
|
return new PostgresIntrospectionProvider(options);
|
|
2273
3366
|
}
|
|
2274
3367
|
|
|
3368
|
+
// src/schema/model-form.ts
|
|
3369
|
+
function resolveNullishValue(mode) {
|
|
3370
|
+
if (mode === "undefined") return void 0;
|
|
3371
|
+
if (mode === "null") return null;
|
|
3372
|
+
return "";
|
|
3373
|
+
}
|
|
3374
|
+
function isRecord4(value) {
|
|
3375
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3376
|
+
}
|
|
3377
|
+
function isNullableColumn(model, key) {
|
|
3378
|
+
const nullable = model.meta.nullable;
|
|
3379
|
+
return nullable?.[key] === true;
|
|
3380
|
+
}
|
|
3381
|
+
function toModelFormDefaults(model, values, options) {
|
|
3382
|
+
const source = values;
|
|
3383
|
+
if (!isRecord4(source)) {
|
|
3384
|
+
return {};
|
|
3385
|
+
}
|
|
3386
|
+
const mode = options?.nullishMode ?? "empty-string";
|
|
3387
|
+
const nullishValue = resolveNullishValue(mode);
|
|
3388
|
+
const result = {};
|
|
3389
|
+
for (const [key, value] of Object.entries(source)) {
|
|
3390
|
+
if (value === null && isNullableColumn(model, key)) {
|
|
3391
|
+
result[key] = nullishValue;
|
|
3392
|
+
continue;
|
|
3393
|
+
}
|
|
3394
|
+
result[key] = value;
|
|
3395
|
+
}
|
|
3396
|
+
return result;
|
|
3397
|
+
}
|
|
3398
|
+
function toModelPayload(model, formValues, options) {
|
|
3399
|
+
const emptyStringAsNull = options?.emptyStringAsNull ?? true;
|
|
3400
|
+
const stripUndefined = options?.stripUndefined ?? true;
|
|
3401
|
+
const result = {};
|
|
3402
|
+
for (const [key, rawValue] of Object.entries(formValues)) {
|
|
3403
|
+
if (rawValue === void 0 && stripUndefined) {
|
|
3404
|
+
continue;
|
|
3405
|
+
}
|
|
3406
|
+
if (emptyStringAsNull && rawValue === "" && isNullableColumn(model, key)) {
|
|
3407
|
+
result[key] = null;
|
|
3408
|
+
continue;
|
|
3409
|
+
}
|
|
3410
|
+
result[key] = rawValue;
|
|
3411
|
+
}
|
|
3412
|
+
return result;
|
|
3413
|
+
}
|
|
3414
|
+
function createModelFormAdapter(model) {
|
|
3415
|
+
return {
|
|
3416
|
+
model,
|
|
3417
|
+
toDefaults(values, options) {
|
|
3418
|
+
return toModelFormDefaults(model, values, options);
|
|
3419
|
+
},
|
|
3420
|
+
toInsert(values, options) {
|
|
3421
|
+
return toModelPayload(model, values, options);
|
|
3422
|
+
},
|
|
3423
|
+
toUpdate(values, options) {
|
|
3424
|
+
return toModelPayload(model, values, options);
|
|
3425
|
+
}
|
|
3426
|
+
};
|
|
3427
|
+
}
|
|
3428
|
+
|
|
2275
3429
|
// src/generator/schema-selection.ts
|
|
2276
3430
|
var DEFAULT_POSTGRES_SCHEMAS = ["public"];
|
|
2277
3431
|
function collectSchemaNames(input) {
|
|
@@ -2331,6 +3485,39 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
2331
3485
|
postgresGatewayIntrospection: false,
|
|
2332
3486
|
scyllaProviderContracts: true
|
|
2333
3487
|
};
|
|
3488
|
+
function normalizeBooleanFlag(rawValue, fallback) {
|
|
3489
|
+
if (typeof rawValue === "boolean") {
|
|
3490
|
+
return rawValue;
|
|
3491
|
+
}
|
|
3492
|
+
if (typeof rawValue === "string") {
|
|
3493
|
+
return parseBooleanFlag(rawValue, fallback);
|
|
3494
|
+
}
|
|
3495
|
+
return fallback;
|
|
3496
|
+
}
|
|
3497
|
+
function normalizeFeatureFlags(input) {
|
|
3498
|
+
return {
|
|
3499
|
+
emitRelations: normalizeBooleanFlag(
|
|
3500
|
+
input?.emitRelations,
|
|
3501
|
+
DEFAULT_FEATURES.emitRelations
|
|
3502
|
+
),
|
|
3503
|
+
emitRegistry: normalizeBooleanFlag(
|
|
3504
|
+
input?.emitRegistry,
|
|
3505
|
+
DEFAULT_FEATURES.emitRegistry
|
|
3506
|
+
)
|
|
3507
|
+
};
|
|
3508
|
+
}
|
|
3509
|
+
function normalizeExperimentalFlags(input) {
|
|
3510
|
+
return {
|
|
3511
|
+
postgresGatewayIntrospection: normalizeBooleanFlag(
|
|
3512
|
+
input?.postgresGatewayIntrospection,
|
|
3513
|
+
DEFAULT_EXPERIMENTAL_FLAGS.postgresGatewayIntrospection
|
|
3514
|
+
),
|
|
3515
|
+
scyllaProviderContracts: normalizeBooleanFlag(
|
|
3516
|
+
input?.scyllaProviderContracts,
|
|
3517
|
+
DEFAULT_EXPERIMENTAL_FLAGS.scyllaProviderContracts
|
|
3518
|
+
)
|
|
3519
|
+
};
|
|
3520
|
+
}
|
|
2334
3521
|
function normalizeOutputConfig(output) {
|
|
2335
3522
|
return {
|
|
2336
3523
|
targets: {
|
|
@@ -2366,14 +3553,8 @@ function normalizeGeneratorConfig(input) {
|
|
|
2366
3553
|
...DEFAULT_NAMING,
|
|
2367
3554
|
...input.naming ?? {}
|
|
2368
3555
|
},
|
|
2369
|
-
features:
|
|
2370
|
-
|
|
2371
|
-
...input.features ?? {}
|
|
2372
|
-
},
|
|
2373
|
-
experimental: {
|
|
2374
|
-
...DEFAULT_EXPERIMENTAL_FLAGS,
|
|
2375
|
-
...input.experimental ?? {}
|
|
2376
|
-
}
|
|
3556
|
+
features: normalizeFeatureFlags(input.features),
|
|
3557
|
+
experimental: normalizeExperimentalFlags(input.experimental)
|
|
2377
3558
|
};
|
|
2378
3559
|
}
|
|
2379
3560
|
function defineGeneratorConfig(config) {
|
|
@@ -2983,636 +4164,145 @@ var ArtifactComposer = class {
|
|
|
2983
4164
|
files
|
|
2984
4165
|
};
|
|
2985
4166
|
}
|
|
2986
|
-
};
|
|
2987
|
-
function generateArtifactsFromSnapshot(snapshot, config) {
|
|
2988
|
-
const normalizedConfig = "naming" in config && "features" in config && "experimental" in config ? config : normalizeGeneratorConfig(config);
|
|
2989
|
-
return new ArtifactComposer(snapshot, normalizedConfig).compose();
|
|
2990
|
-
}
|
|
2991
|
-
|
|
2992
|
-
// src/generator/providers.ts
|
|
2993
|
-
var AthenaGatewayCatalogClient = class {
|
|
2994
|
-
constructor(client) {
|
|
2995
|
-
this.client = client;
|
|
2996
|
-
}
|
|
2997
|
-
async queryRows(query) {
|
|
2998
|
-
const result = await this.client.query(query);
|
|
2999
|
-
if (result.error || result.status < 200 || result.status >= 300) {
|
|
3000
|
-
throw new Error(result.error ?? `Gateway query failed with status ${result.status}`);
|
|
3001
|
-
}
|
|
3002
|
-
return result.data ?? [];
|
|
3003
|
-
}
|
|
3004
|
-
async queryColumns(query) {
|
|
3005
|
-
return this.queryRows(query);
|
|
3006
|
-
}
|
|
3007
|
-
async queryEnums(query) {
|
|
3008
|
-
const rows = await this.queryRows(query);
|
|
3009
|
-
const enumMap = /* @__PURE__ */ new Map();
|
|
3010
|
-
for (const row of rows) {
|
|
3011
|
-
const existing = enumMap.get(row.type_oid) ?? [];
|
|
3012
|
-
existing.push(row.enum_label);
|
|
3013
|
-
enumMap.set(row.type_oid, existing);
|
|
3014
|
-
}
|
|
3015
|
-
return enumMap;
|
|
3016
|
-
}
|
|
3017
|
-
async queryPrimaryKeys(query) {
|
|
3018
|
-
return this.queryRows(query);
|
|
3019
|
-
}
|
|
3020
|
-
async queryForeignKeys(query) {
|
|
3021
|
-
return this.queryRows(query);
|
|
3022
|
-
}
|
|
3023
|
-
};
|
|
3024
|
-
var AthenaGatewayPostgresIntrospectionProvider = class {
|
|
3025
|
-
constructor(config) {
|
|
3026
|
-
this.config = config;
|
|
3027
|
-
this.client = createClient(this.config.gatewayUrl, this.config.apiKey, {
|
|
3028
|
-
backend: {
|
|
3029
|
-
type: this.config.backend ?? "postgresql"
|
|
3030
|
-
}
|
|
3031
|
-
});
|
|
3032
|
-
this.schemas = normalizeSchemaSelection(this.config.schemas);
|
|
3033
|
-
}
|
|
3034
|
-
backend = "postgresql";
|
|
3035
|
-
client;
|
|
3036
|
-
schemas;
|
|
3037
|
-
async inspect(options) {
|
|
3038
|
-
const schemas = options?.schemas && options.schemas.length > 0 ? normalizeSchemaSelection(options.schemas) : this.schemas;
|
|
3039
|
-
const catalogClient = new AthenaGatewayCatalogClient(this.client);
|
|
3040
|
-
const queries = buildGatewayCatalogQueries(schemas);
|
|
3041
|
-
const [columnRows, enumMap, primaryKeyRows, foreignKeyRows] = await Promise.all([
|
|
3042
|
-
catalogClient.queryColumns(queries.columns),
|
|
3043
|
-
catalogClient.queryEnums(queries.enums),
|
|
3044
|
-
catalogClient.queryPrimaryKeys(queries.primaryKeys),
|
|
3045
|
-
catalogClient.queryForeignKeys(queries.foreignKeys)
|
|
3046
|
-
]);
|
|
3047
|
-
const assembler = new PostgresCatalogSnapshotAssembler();
|
|
3048
|
-
assembler.addColumnRows(columnRows, enumMap);
|
|
3049
|
-
assembler.addPrimaryKeyRows(primaryKeyRows);
|
|
3050
|
-
assembler.addForeignKeyRows(foreignKeyRows);
|
|
3051
|
-
assembler.addManyToManyRows(foreignKeyRows);
|
|
3052
|
-
return {
|
|
3053
|
-
backend: "postgresql",
|
|
3054
|
-
database: this.config.database,
|
|
3055
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3056
|
-
schemas: assembler.toSchemas()
|
|
3057
|
-
};
|
|
3058
|
-
}
|
|
3059
|
-
};
|
|
3060
|
-
var ScyllaIntrospectionProvider = class {
|
|
3061
|
-
constructor(config) {
|
|
3062
|
-
this.config = config;
|
|
3063
|
-
}
|
|
3064
|
-
backend = "scylladb";
|
|
3065
|
-
async inspect() {
|
|
3066
|
-
throw new Error(
|
|
3067
|
-
`Scylla introspection provider is not implemented yet for keyspace ${this.config.keyspace}.`
|
|
3068
|
-
);
|
|
3069
|
-
}
|
|
3070
|
-
};
|
|
3071
|
-
function createPostgresProvider(config) {
|
|
3072
|
-
return createPostgresIntrospectionProvider({
|
|
3073
|
-
connectionString: config.connectionString,
|
|
3074
|
-
database: config.database,
|
|
3075
|
-
schemas: normalizeSchemaSelection(config.schemas)
|
|
3076
|
-
});
|
|
3077
|
-
}
|
|
3078
|
-
function resolveGeneratorProvider(providerConfig, experimentalFlags) {
|
|
3079
|
-
if (providerConfig.kind === "postgres" && providerConfig.mode === "direct") {
|
|
3080
|
-
return createPostgresProvider(providerConfig);
|
|
3081
|
-
}
|
|
3082
|
-
if (providerConfig.kind === "postgres" && providerConfig.mode === "gateway") {
|
|
3083
|
-
return new AthenaGatewayPostgresIntrospectionProvider(providerConfig);
|
|
3084
|
-
}
|
|
3085
|
-
if (providerConfig.kind === "scylla") {
|
|
3086
|
-
if (!experimentalFlags.scyllaProviderContracts) {
|
|
3087
|
-
throw new Error(
|
|
3088
|
-
"Scylla provider contracts are disabled. Set experimental.scyllaProviderContracts=true to enable placeholders."
|
|
3089
|
-
);
|
|
3090
|
-
}
|
|
3091
|
-
return new ScyllaIntrospectionProvider(providerConfig);
|
|
3092
|
-
}
|
|
3093
|
-
throw new Error(`Unsupported generator provider kind: ${providerConfig.kind ?? "unknown"}`);
|
|
3094
|
-
}
|
|
3095
|
-
async function writeArtifacts(files, cwd) {
|
|
3096
|
-
const writtenFiles = [];
|
|
3097
|
-
for (const file of files) {
|
|
3098
|
-
const absolutePath = resolve(cwd, file.path);
|
|
3099
|
-
await mkdir(dirname(absolutePath), { recursive: true });
|
|
3100
|
-
await writeFile(absolutePath, file.content, "utf8");
|
|
3101
|
-
writtenFiles.push(file.path);
|
|
3102
|
-
}
|
|
3103
|
-
return writtenFiles;
|
|
3104
|
-
}
|
|
3105
|
-
async function runSchemaGenerator(options = {}) {
|
|
3106
|
-
const cwd = options.cwd ?? process.cwd();
|
|
3107
|
-
const configOptions = {
|
|
3108
|
-
cwd,
|
|
3109
|
-
configPath: options.configPath
|
|
3110
|
-
};
|
|
3111
|
-
const { configPath, config } = await loadGeneratorConfig(configOptions);
|
|
3112
|
-
const provider = options.provider ?? resolveGeneratorProvider(config.provider, config.experimental);
|
|
3113
|
-
const snapshot = await provider.inspect({
|
|
3114
|
-
schemas: resolveProviderSchemas(config.provider)
|
|
3115
|
-
});
|
|
3116
|
-
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
3117
|
-
const writtenFiles = options.dryRun ? [] : await writeArtifacts(generated.files, cwd);
|
|
3118
|
-
return {
|
|
3119
|
-
...generated,
|
|
3120
|
-
configPath,
|
|
3121
|
-
writtenFiles
|
|
3122
|
-
};
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
|
-
// src/auth/client.ts
|
|
3126
|
-
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
3127
|
-
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
3128
|
-
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
3129
|
-
var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
|
|
3130
|
-
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
3131
|
-
function normalizeBaseUrl(baseUrl) {
|
|
3132
|
-
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
3133
|
-
}
|
|
3134
|
-
function isRecord3(value) {
|
|
3135
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3136
|
-
}
|
|
3137
|
-
function normalizeHeaderValue2(value) {
|
|
3138
|
-
return value ? value : void 0;
|
|
3139
|
-
}
|
|
3140
|
-
function parseResponseBody2(rawText, contentType) {
|
|
3141
|
-
if (!rawText) {
|
|
3142
|
-
return { parsed: null, parseFailed: false };
|
|
3143
|
-
}
|
|
3144
|
-
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
3145
|
-
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
3146
|
-
if (!looksJson) {
|
|
3147
|
-
return { parsed: rawText, parseFailed: false };
|
|
3148
|
-
}
|
|
3149
|
-
try {
|
|
3150
|
-
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
3151
|
-
} catch {
|
|
3152
|
-
return { parsed: rawText, parseFailed: true };
|
|
3153
|
-
}
|
|
3154
|
-
}
|
|
3155
|
-
function resolveRequestId2(headers) {
|
|
3156
|
-
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
3157
|
-
}
|
|
3158
|
-
function resolveErrorMessage2(payload, fallback) {
|
|
3159
|
-
if (isRecord3(payload)) {
|
|
3160
|
-
const messageCandidates = [payload.error, payload.message, payload.details];
|
|
3161
|
-
for (const candidate of messageCandidates) {
|
|
3162
|
-
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
3163
|
-
return candidate.trim();
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
3168
|
-
return payload.trim();
|
|
3169
|
-
}
|
|
3170
|
-
return fallback;
|
|
3171
|
-
}
|
|
3172
|
-
function toErrorDetails(input) {
|
|
3173
|
-
return {
|
|
3174
|
-
code: input.code,
|
|
3175
|
-
message: input.message,
|
|
3176
|
-
status: input.status,
|
|
3177
|
-
endpoint: input.endpoint,
|
|
3178
|
-
method: input.method,
|
|
3179
|
-
requestId: input.requestId,
|
|
3180
|
-
hint: input.hint,
|
|
3181
|
-
cause: input.cause
|
|
3182
|
-
};
|
|
3183
|
-
}
|
|
3184
|
-
function mergeCallOptions(base, override) {
|
|
3185
|
-
if (!base && !override) return void 0;
|
|
3186
|
-
return {
|
|
3187
|
-
...base,
|
|
3188
|
-
...override,
|
|
3189
|
-
headers: {
|
|
3190
|
-
...base?.headers ?? {},
|
|
3191
|
-
...override?.headers ?? {}
|
|
3192
|
-
}
|
|
3193
|
-
};
|
|
3194
|
-
}
|
|
3195
|
-
function extractFetchOptions(input) {
|
|
3196
|
-
if (!input) {
|
|
3197
|
-
return {
|
|
3198
|
-
payload: void 0,
|
|
3199
|
-
fetchOptions: void 0
|
|
3200
|
-
};
|
|
3201
|
-
}
|
|
3202
|
-
const { fetchOptions, ...rest } = input;
|
|
3203
|
-
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
3204
|
-
return {
|
|
3205
|
-
payload: hasPayloadKeys ? rest : void 0,
|
|
3206
|
-
fetchOptions
|
|
3207
|
-
};
|
|
4167
|
+
};
|
|
4168
|
+
function generateArtifactsFromSnapshot(snapshot, config) {
|
|
4169
|
+
const normalizedConfig = "naming" in config && "features" in config && "experimental" in config ? config : normalizeGeneratorConfig(config);
|
|
4170
|
+
return new ArtifactComposer(snapshot, normalizedConfig).compose();
|
|
3208
4171
|
}
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
const apiKey = options?.apiKey ?? config.apiKey;
|
|
3215
|
-
if (apiKey) {
|
|
3216
|
-
headers.apikey = apiKey;
|
|
3217
|
-
headers["x-api-key"] = apiKey;
|
|
3218
|
-
}
|
|
3219
|
-
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
3220
|
-
if (bearerToken) {
|
|
3221
|
-
headers.Authorization = `Bearer ${bearerToken}`;
|
|
4172
|
+
|
|
4173
|
+
// src/generator/providers.ts
|
|
4174
|
+
var AthenaGatewayCatalogClient = class {
|
|
4175
|
+
constructor(client) {
|
|
4176
|
+
this.client = client;
|
|
3222
4177
|
}
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
3228
|
-
const normalized = normalizeHeaderValue2(value);
|
|
3229
|
-
if (normalized) {
|
|
3230
|
-
headers[key] = normalized;
|
|
4178
|
+
async queryRows(query) {
|
|
4179
|
+
const result = await this.client.query(query);
|
|
4180
|
+
if (result.error || result.status < 200 || result.status >= 300) {
|
|
4181
|
+
throw new Error(result.error ?? `Gateway query failed with status ${result.status}`);
|
|
3231
4182
|
}
|
|
3232
|
-
|
|
3233
|
-
return headers;
|
|
3234
|
-
}
|
|
3235
|
-
function appendQueryParam(searchParams, key, value) {
|
|
3236
|
-
if (value === void 0 || value === null) return;
|
|
3237
|
-
if (Array.isArray(value)) {
|
|
3238
|
-
value.forEach((item) => {
|
|
3239
|
-
searchParams.append(key, String(item));
|
|
3240
|
-
});
|
|
3241
|
-
return;
|
|
4183
|
+
return result.data ?? [];
|
|
3242
4184
|
}
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
function buildRequestUrl(baseUrl, endpoint, query) {
|
|
3246
|
-
const url = `${baseUrl}${endpoint}`;
|
|
3247
|
-
if (!query || Object.keys(query).length === 0) return url;
|
|
3248
|
-
const searchParams = new URLSearchParams();
|
|
3249
|
-
Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
|
|
3250
|
-
const queryText = searchParams.toString();
|
|
3251
|
-
return queryText ? `${url}?${queryText}` : url;
|
|
3252
|
-
}
|
|
3253
|
-
function inferDefaultMethod(endpoint) {
|
|
3254
|
-
if (endpoint.startsWith("/reset-password/")) {
|
|
3255
|
-
return "GET";
|
|
4185
|
+
async queryColumns(query) {
|
|
4186
|
+
return this.queryRows(query);
|
|
3256
4187
|
}
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
default:
|
|
3267
|
-
return "POST";
|
|
4188
|
+
async queryEnums(query) {
|
|
4189
|
+
const rows = await this.queryRows(query);
|
|
4190
|
+
const enumMap = /* @__PURE__ */ new Map();
|
|
4191
|
+
for (const row of rows) {
|
|
4192
|
+
const existing = enumMap.get(row.type_oid) ?? [];
|
|
4193
|
+
existing.push(row.enum_label);
|
|
4194
|
+
enumMap.set(row.type_oid, existing);
|
|
4195
|
+
}
|
|
4196
|
+
return enumMap;
|
|
3268
4197
|
}
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
3272
|
-
const url = buildRequestUrl(baseUrl, context.endpoint, query);
|
|
3273
|
-
const headers = buildHeaders2(config, options);
|
|
3274
|
-
const credentials = options?.credentials ?? config.credentials ?? "include";
|
|
3275
|
-
const requestInit = {
|
|
3276
|
-
method: context.method,
|
|
3277
|
-
headers,
|
|
3278
|
-
credentials,
|
|
3279
|
-
signal: options?.signal
|
|
3280
|
-
};
|
|
3281
|
-
if (context.method !== "GET") {
|
|
3282
|
-
requestInit.body = JSON.stringify(body ?? {});
|
|
4198
|
+
async queryPrimaryKeys(query) {
|
|
4199
|
+
return this.queryRows(query);
|
|
3283
4200
|
}
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
4201
|
+
async queryForeignKeys(query) {
|
|
4202
|
+
return this.queryRows(query);
|
|
4203
|
+
}
|
|
4204
|
+
};
|
|
4205
|
+
var AthenaGatewayPostgresIntrospectionProvider = class {
|
|
4206
|
+
constructor(config) {
|
|
4207
|
+
this.config = config;
|
|
4208
|
+
this.client = createClient(this.config.gatewayUrl, this.config.apiKey, {
|
|
4209
|
+
backend: {
|
|
4210
|
+
type: this.config.backend ?? "postgresql"
|
|
4211
|
+
}
|
|
3293
4212
|
});
|
|
4213
|
+
this.schemas = normalizeSchemaSelection(this.config.schemas);
|
|
4214
|
+
}
|
|
4215
|
+
backend = "postgresql";
|
|
4216
|
+
client;
|
|
4217
|
+
schemas;
|
|
4218
|
+
async inspect(options) {
|
|
4219
|
+
const schemas = options?.schemas && options.schemas.length > 0 ? normalizeSchemaSelection(options.schemas) : this.schemas;
|
|
4220
|
+
const catalogClient = new AthenaGatewayCatalogClient(this.client);
|
|
4221
|
+
const queries = buildGatewayCatalogQueries(schemas);
|
|
4222
|
+
const [columnRows, enumMap, primaryKeyRows, foreignKeyRows] = await Promise.all([
|
|
4223
|
+
catalogClient.queryColumns(queries.columns),
|
|
4224
|
+
catalogClient.queryEnums(queries.enums),
|
|
4225
|
+
catalogClient.queryPrimaryKeys(queries.primaryKeys),
|
|
4226
|
+
catalogClient.queryForeignKeys(queries.foreignKeys)
|
|
4227
|
+
]);
|
|
4228
|
+
const assembler = new PostgresCatalogSnapshotAssembler();
|
|
4229
|
+
assembler.addColumnRows(columnRows, enumMap);
|
|
4230
|
+
assembler.addPrimaryKeyRows(primaryKeyRows);
|
|
4231
|
+
assembler.addForeignKeyRows(foreignKeyRows);
|
|
4232
|
+
assembler.addManyToManyRows(foreignKeyRows);
|
|
3294
4233
|
return {
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
errorDetails: details,
|
|
3300
|
-
raw: null
|
|
4234
|
+
backend: "postgresql",
|
|
4235
|
+
database: this.config.database,
|
|
4236
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4237
|
+
schemas: assembler.toSchemas()
|
|
3301
4238
|
};
|
|
3302
4239
|
}
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
`Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
|
|
3335
|
-
),
|
|
3336
|
-
status: response.status,
|
|
3337
|
-
endpoint: context.endpoint,
|
|
3338
|
-
method: context.method,
|
|
3339
|
-
requestId
|
|
3340
|
-
});
|
|
3341
|
-
return {
|
|
3342
|
-
ok: false,
|
|
3343
|
-
status: response.status,
|
|
3344
|
-
data: null,
|
|
3345
|
-
error: details.message,
|
|
3346
|
-
errorDetails: details,
|
|
3347
|
-
raw: parsed
|
|
3348
|
-
};
|
|
4240
|
+
};
|
|
4241
|
+
var ScyllaIntrospectionProvider = class {
|
|
4242
|
+
constructor(config) {
|
|
4243
|
+
this.config = config;
|
|
4244
|
+
}
|
|
4245
|
+
backend = "scylladb";
|
|
4246
|
+
async inspect() {
|
|
4247
|
+
throw new Error(
|
|
4248
|
+
`Scylla introspection provider is not implemented yet for keyspace ${this.config.keyspace}.`
|
|
4249
|
+
);
|
|
4250
|
+
}
|
|
4251
|
+
};
|
|
4252
|
+
function createPostgresProvider(config) {
|
|
4253
|
+
return createPostgresIntrospectionProvider({
|
|
4254
|
+
connectionString: config.connectionString,
|
|
4255
|
+
database: config.database,
|
|
4256
|
+
schemas: normalizeSchemaSelection(config.schemas)
|
|
4257
|
+
});
|
|
4258
|
+
}
|
|
4259
|
+
function resolveGeneratorProvider(providerConfig, experimentalFlags) {
|
|
4260
|
+
if (providerConfig.kind === "postgres" && providerConfig.mode === "direct") {
|
|
4261
|
+
return createPostgresProvider(providerConfig);
|
|
4262
|
+
}
|
|
4263
|
+
if (providerConfig.kind === "postgres" && providerConfig.mode === "gateway") {
|
|
4264
|
+
return new AthenaGatewayPostgresIntrospectionProvider(providerConfig);
|
|
4265
|
+
}
|
|
4266
|
+
if (providerConfig.kind === "scylla") {
|
|
4267
|
+
if (!experimentalFlags.scyllaProviderContracts) {
|
|
4268
|
+
throw new Error(
|
|
4269
|
+
"Scylla provider contracts are disabled. Set experimental.scyllaProviderContracts=true to enable placeholders."
|
|
4270
|
+
);
|
|
3349
4271
|
}
|
|
3350
|
-
return
|
|
3351
|
-
ok: true,
|
|
3352
|
-
status: response.status,
|
|
3353
|
-
data: parsed ?? null,
|
|
3354
|
-
error: null,
|
|
3355
|
-
errorDetails: null,
|
|
3356
|
-
raw: parsed
|
|
3357
|
-
};
|
|
3358
|
-
} catch (callError) {
|
|
3359
|
-
const message = callError instanceof Error ? callError.message : String(callError);
|
|
3360
|
-
const details = toErrorDetails({
|
|
3361
|
-
code: "NETWORK_ERROR",
|
|
3362
|
-
message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
|
|
3363
|
-
status: 0,
|
|
3364
|
-
endpoint: context.endpoint,
|
|
3365
|
-
method: context.method,
|
|
3366
|
-
cause: message,
|
|
3367
|
-
hint: "Check auth server URL, DNS, and network reachability."
|
|
3368
|
-
});
|
|
3369
|
-
return {
|
|
3370
|
-
ok: false,
|
|
3371
|
-
status: 0,
|
|
3372
|
-
data: null,
|
|
3373
|
-
error: details.message,
|
|
3374
|
-
errorDetails: details,
|
|
3375
|
-
raw: null
|
|
3376
|
-
};
|
|
4272
|
+
return new ScyllaIntrospectionProvider(providerConfig);
|
|
3377
4273
|
}
|
|
4274
|
+
throw new Error(`Unsupported generator provider kind: ${providerConfig.kind ?? "unknown"}`);
|
|
3378
4275
|
}
|
|
3379
|
-
function
|
|
3380
|
-
const
|
|
3381
|
-
const
|
|
3382
|
-
|
|
3383
|
-
}
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
return
|
|
3388
|
-
}
|
|
3389
|
-
function executeGetWithCompatibleInput(config, context, input, options) {
|
|
3390
|
-
const { fetchOptions } = extractFetchOptions(input);
|
|
3391
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3392
|
-
return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
|
|
4276
|
+
async function writeArtifacts(files, cwd) {
|
|
4277
|
+
const writtenFiles = [];
|
|
4278
|
+
for (const file of files) {
|
|
4279
|
+
const absolutePath = resolve(cwd, file.path);
|
|
4280
|
+
await mkdir(dirname(absolutePath), { recursive: true });
|
|
4281
|
+
await writeFile(absolutePath, file.content, "utf8");
|
|
4282
|
+
writtenFiles.push(file.path);
|
|
4283
|
+
}
|
|
4284
|
+
return writtenFiles;
|
|
3393
4285
|
}
|
|
3394
|
-
function
|
|
3395
|
-
const
|
|
3396
|
-
const
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
};
|
|
3400
|
-
const request = (input, options) => {
|
|
3401
|
-
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
3402
|
-
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
3403
|
-
return callAuthEndpoint(
|
|
3404
|
-
resolvedConfig,
|
|
3405
|
-
{ endpoint: input.endpoint, method },
|
|
3406
|
-
input.body,
|
|
3407
|
-
input.query,
|
|
3408
|
-
mergedOptions
|
|
3409
|
-
);
|
|
3410
|
-
};
|
|
3411
|
-
const signOut = (input, options) => executePostWithOptionalInput(
|
|
3412
|
-
resolvedConfig,
|
|
3413
|
-
{ endpoint: "/sign-out", method: "POST" },
|
|
3414
|
-
input,
|
|
3415
|
-
options
|
|
3416
|
-
);
|
|
3417
|
-
const revokeSessions = (input, options) => executePostWithOptionalInput(
|
|
3418
|
-
resolvedConfig,
|
|
3419
|
-
{ endpoint: "/revoke-sessions", method: "POST" },
|
|
3420
|
-
input,
|
|
3421
|
-
options
|
|
3422
|
-
);
|
|
3423
|
-
const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
|
|
3424
|
-
resolvedConfig,
|
|
3425
|
-
{ endpoint: "/revoke-other-sessions", method: "POST" },
|
|
3426
|
-
input,
|
|
3427
|
-
options
|
|
3428
|
-
);
|
|
3429
|
-
const revokeSession = (input, options) => executePostWithCompatibleInput(
|
|
3430
|
-
resolvedConfig,
|
|
3431
|
-
{ endpoint: "/revoke-session", method: "POST" },
|
|
3432
|
-
input,
|
|
3433
|
-
options
|
|
3434
|
-
);
|
|
3435
|
-
const deleteUser = (input, options) => {
|
|
3436
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3437
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3438
|
-
return callAuthEndpoint(
|
|
3439
|
-
resolvedConfig,
|
|
3440
|
-
{ endpoint: "/delete-user", method: "POST" },
|
|
3441
|
-
payload ?? {},
|
|
3442
|
-
void 0,
|
|
3443
|
-
mergedOptions
|
|
3444
|
-
);
|
|
3445
|
-
};
|
|
3446
|
-
const deleteUserCallback = (input, options) => {
|
|
3447
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3448
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3449
|
-
const query = payload ?? {};
|
|
3450
|
-
return callAuthEndpoint(
|
|
3451
|
-
resolvedConfig,
|
|
3452
|
-
{ endpoint: "/delete-user/callback", method: "GET" },
|
|
3453
|
-
void 0,
|
|
3454
|
-
{
|
|
3455
|
-
token: query.token,
|
|
3456
|
-
callbackURL: query.callbackURL
|
|
3457
|
-
},
|
|
3458
|
-
mergedOptions
|
|
3459
|
-
);
|
|
3460
|
-
};
|
|
3461
|
-
const resolveResetPasswordToken = (input, options) => {
|
|
3462
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3463
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3464
|
-
const query = payload;
|
|
3465
|
-
const token = query?.token?.trim();
|
|
3466
|
-
if (!token) {
|
|
3467
|
-
throw new Error("resolveResetPasswordToken requires a non-empty token");
|
|
3468
|
-
}
|
|
3469
|
-
const endpoint = `/reset-password/${encodeURIComponent(token)}`;
|
|
3470
|
-
return callAuthEndpoint(
|
|
3471
|
-
resolvedConfig,
|
|
3472
|
-
{ endpoint, method: "GET" },
|
|
3473
|
-
void 0,
|
|
3474
|
-
query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
|
|
3475
|
-
mergedOptions
|
|
3476
|
-
);
|
|
4286
|
+
async function runSchemaGenerator(options = {}) {
|
|
4287
|
+
const cwd = options.cwd ?? process.cwd();
|
|
4288
|
+
const configOptions = {
|
|
4289
|
+
cwd,
|
|
4290
|
+
configPath: options.configPath
|
|
3477
4291
|
};
|
|
4292
|
+
const { configPath, config } = await loadGeneratorConfig(configOptions);
|
|
4293
|
+
const provider = options.provider ?? resolveGeneratorProvider(config.provider, config.experimental);
|
|
4294
|
+
const snapshot = await provider.inspect({
|
|
4295
|
+
schemas: resolveProviderSchemas(config.provider)
|
|
4296
|
+
});
|
|
4297
|
+
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
4298
|
+
const writtenFiles = options.dryRun ? [] : await writeArtifacts(generated.files, cwd);
|
|
3478
4299
|
return {
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
email: (input, options) => executePostWithCompatibleInput(
|
|
3483
|
-
resolvedConfig,
|
|
3484
|
-
{ endpoint: "/sign-in/email", method: "POST" },
|
|
3485
|
-
input,
|
|
3486
|
-
options
|
|
3487
|
-
),
|
|
3488
|
-
username: (input, options) => executePostWithCompatibleInput(
|
|
3489
|
-
resolvedConfig,
|
|
3490
|
-
{ endpoint: "/sign-in/username", method: "POST" },
|
|
3491
|
-
input,
|
|
3492
|
-
options
|
|
3493
|
-
),
|
|
3494
|
-
social: (input, options) => executePostWithCompatibleInput(
|
|
3495
|
-
resolvedConfig,
|
|
3496
|
-
{ endpoint: "/sign-in/social", method: "POST" },
|
|
3497
|
-
input,
|
|
3498
|
-
options
|
|
3499
|
-
)
|
|
3500
|
-
},
|
|
3501
|
-
signUp: {
|
|
3502
|
-
email: (input, options) => executePostWithCompatibleInput(
|
|
3503
|
-
resolvedConfig,
|
|
3504
|
-
{ endpoint: "/sign-up/email", method: "POST" },
|
|
3505
|
-
input,
|
|
3506
|
-
options
|
|
3507
|
-
)
|
|
3508
|
-
},
|
|
3509
|
-
signOut,
|
|
3510
|
-
logout: signOut,
|
|
3511
|
-
getSession: (input, options) => executeGetWithCompatibleInput(
|
|
3512
|
-
resolvedConfig,
|
|
3513
|
-
{ endpoint: "/get-session", method: "GET" },
|
|
3514
|
-
input,
|
|
3515
|
-
options
|
|
3516
|
-
),
|
|
3517
|
-
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
3518
|
-
resolvedConfig,
|
|
3519
|
-
{ endpoint: "/list-sessions", method: "GET" },
|
|
3520
|
-
input,
|
|
3521
|
-
options
|
|
3522
|
-
),
|
|
3523
|
-
revokeSession,
|
|
3524
|
-
clearSession: revokeSession,
|
|
3525
|
-
revokeSessions,
|
|
3526
|
-
clearSessions: revokeSessions,
|
|
3527
|
-
revokeOtherSessions,
|
|
3528
|
-
clearOtherSessions: revokeOtherSessions,
|
|
3529
|
-
forgetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3530
|
-
resolvedConfig,
|
|
3531
|
-
{ endpoint: "/forget-password", method: "POST" },
|
|
3532
|
-
input,
|
|
3533
|
-
options
|
|
3534
|
-
),
|
|
3535
|
-
resetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3536
|
-
resolvedConfig,
|
|
3537
|
-
{ endpoint: "/reset-password", method: "POST" },
|
|
3538
|
-
input,
|
|
3539
|
-
options
|
|
3540
|
-
),
|
|
3541
|
-
resolveResetPasswordToken,
|
|
3542
|
-
verifyEmail: (input, options) => {
|
|
3543
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3544
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3545
|
-
const query = payload;
|
|
3546
|
-
return callAuthEndpoint(
|
|
3547
|
-
resolvedConfig,
|
|
3548
|
-
{ endpoint: "/verify-email", method: "GET" },
|
|
3549
|
-
void 0,
|
|
3550
|
-
query ? {
|
|
3551
|
-
token: query.token,
|
|
3552
|
-
callbackURL: query.callbackURL
|
|
3553
|
-
} : void 0,
|
|
3554
|
-
mergedOptions
|
|
3555
|
-
);
|
|
3556
|
-
},
|
|
3557
|
-
sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
|
|
3558
|
-
resolvedConfig,
|
|
3559
|
-
{ endpoint: "/send-verification-email", method: "POST" },
|
|
3560
|
-
input,
|
|
3561
|
-
options
|
|
3562
|
-
),
|
|
3563
|
-
changeEmail: (input, options) => executePostWithCompatibleInput(
|
|
3564
|
-
resolvedConfig,
|
|
3565
|
-
{ endpoint: "/change-email", method: "POST" },
|
|
3566
|
-
input,
|
|
3567
|
-
options
|
|
3568
|
-
),
|
|
3569
|
-
changePassword: (input, options) => executePostWithCompatibleInput(
|
|
3570
|
-
resolvedConfig,
|
|
3571
|
-
{ endpoint: "/change-password", method: "POST" },
|
|
3572
|
-
input,
|
|
3573
|
-
options
|
|
3574
|
-
),
|
|
3575
|
-
updateUser: (input, options) => executePostWithCompatibleInput(
|
|
3576
|
-
resolvedConfig,
|
|
3577
|
-
{ endpoint: "/update-user", method: "POST" },
|
|
3578
|
-
input,
|
|
3579
|
-
options
|
|
3580
|
-
),
|
|
3581
|
-
deleteUser,
|
|
3582
|
-
deleteUserCallback,
|
|
3583
|
-
linkSocial: (input, options) => executePostWithCompatibleInput(
|
|
3584
|
-
resolvedConfig,
|
|
3585
|
-
{ endpoint: "/link-social", method: "POST" },
|
|
3586
|
-
input,
|
|
3587
|
-
options
|
|
3588
|
-
),
|
|
3589
|
-
listAccounts: (input, options) => executeGetWithCompatibleInput(
|
|
3590
|
-
resolvedConfig,
|
|
3591
|
-
{ endpoint: "/list-accounts", method: "GET" },
|
|
3592
|
-
input,
|
|
3593
|
-
options
|
|
3594
|
-
),
|
|
3595
|
-
unlinkAccount: (input, options) => executePostWithCompatibleInput(
|
|
3596
|
-
resolvedConfig,
|
|
3597
|
-
{ endpoint: "/unlink-account", method: "POST" },
|
|
3598
|
-
input,
|
|
3599
|
-
options
|
|
3600
|
-
),
|
|
3601
|
-
refreshToken: (input, options) => executePostWithCompatibleInput(
|
|
3602
|
-
resolvedConfig,
|
|
3603
|
-
{ endpoint: "/refresh-token", method: "POST" },
|
|
3604
|
-
input,
|
|
3605
|
-
options
|
|
3606
|
-
),
|
|
3607
|
-
getAccessToken: (input, options) => executePostWithCompatibleInput(
|
|
3608
|
-
resolvedConfig,
|
|
3609
|
-
{ endpoint: "/get-access-token", method: "POST" },
|
|
3610
|
-
input,
|
|
3611
|
-
options
|
|
3612
|
-
)
|
|
4300
|
+
...generated,
|
|
4301
|
+
configPath,
|
|
4302
|
+
writtenFiles
|
|
3613
4303
|
};
|
|
3614
4304
|
}
|
|
3615
4305
|
|
|
3616
|
-
export { AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, coerceInt, createAuthClient, createClient, createPostgresIntrospectionProvider, createTypedClient, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, findGeneratorConfigPath, generateArtifactsFromSnapshot, identifier, isAthenaGatewayError, isOk, loadGeneratorConfig, normalizeAthenaError, normalizeGeneratorConfig, normalizeSchemaSelection, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, unwrap, unwrapOne, unwrapRows, withRetry };
|
|
4306
|
+
export { AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, coerceInt, createAuthClient, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, findGeneratorConfigPath, generateArtifactsFromSnapshot, identifier, isAthenaGatewayError, isOk, loadGeneratorConfig, normalizeAthenaError, normalizeGeneratorConfig, normalizeSchemaSelection, parseBooleanFlag, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, withRetry };
|
|
3617
4307
|
//# sourceMappingURL=index.js.map
|
|
3618
4308
|
//# sourceMappingURL=index.js.map
|