@xylex-group/athena 1.9.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 +40 -43
- package/bin/athena-js.js +0 -0
- package/dist/cli/index.cjs +1151 -67
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +1151 -67
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +1592 -1000
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -254
- package/dist/index.d.ts +21 -254
- package/dist/index.js +1592 -1001
- 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/react.cjs +93 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +36 -2
- package/dist/react.d.ts +36 -2
- package/dist/react.js +93 -1
- package/dist/react.js.map +1 -1
- package/package.json +16 -17
- package/dist/model-form-Bm_kqCn2.d.ts +0 -92
- package/dist/model-form-DkS48fsh.d.cts +0 -92
package/dist/index.js
CHANGED
|
@@ -501,460 +501,1109 @@ 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
|
-
errorDetails: response.errorDetails ?? null,
|
|
513
|
-
status: response.status,
|
|
514
|
-
raw: response.raw
|
|
515
|
-
};
|
|
516
|
-
if (response.count !== void 0) {
|
|
517
|
-
result.count = response.count;
|
|
518
|
-
}
|
|
519
|
-
return result;
|
|
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(/\/$/, "");
|
|
520
512
|
}
|
|
521
|
-
function
|
|
522
|
-
|
|
523
|
-
const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
|
|
524
|
-
return {
|
|
525
|
-
...response,
|
|
526
|
-
data: singleData
|
|
527
|
-
};
|
|
513
|
+
function isRecord2(value) {
|
|
514
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
528
515
|
}
|
|
529
|
-
function
|
|
530
|
-
return
|
|
531
|
-
if (!next) return acc;
|
|
532
|
-
return { ...acc, ...next };
|
|
533
|
-
}, void 0);
|
|
516
|
+
function normalizeHeaderValue2(value) {
|
|
517
|
+
return value ? value : void 0;
|
|
534
518
|
}
|
|
535
|
-
function
|
|
536
|
-
|
|
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 };
|
|
532
|
+
}
|
|
537
533
|
}
|
|
538
|
-
function
|
|
539
|
-
return
|
|
534
|
+
function resolveRequestId2(headers) {
|
|
535
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
540
536
|
}
|
|
541
|
-
function
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
if (!promise) {
|
|
549
|
-
promise = executor(payloadColumns, payloadOptions);
|
|
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
|
+
}
|
|
550
544
|
}
|
|
551
|
-
|
|
545
|
+
}
|
|
546
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
547
|
+
return payload.trim();
|
|
548
|
+
}
|
|
549
|
+
return fallback;
|
|
550
|
+
}
|
|
551
|
+
function toErrorDetails(input) {
|
|
552
|
+
return {
|
|
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
|
|
552
561
|
};
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
single(columns = selectedColumns, options) {
|
|
563
|
-
selectedColumns = columns;
|
|
564
|
-
selectedOptions = options ?? selectedOptions;
|
|
565
|
-
return run(columns, options).then(toSingleResult);
|
|
566
|
-
},
|
|
567
|
-
maybeSingle(columns = selectedColumns, options) {
|
|
568
|
-
return mutationQuery.single(columns, options);
|
|
569
|
-
},
|
|
570
|
-
then(onfulfilled, onrejected) {
|
|
571
|
-
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
572
|
-
},
|
|
573
|
-
catch(onrejected) {
|
|
574
|
-
return run(selectedColumns, selectedOptions).catch(onrejected);
|
|
575
|
-
},
|
|
576
|
-
finally(onfinally) {
|
|
577
|
-
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
562
|
+
}
|
|
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 ?? {}
|
|
578
571
|
}
|
|
579
572
|
};
|
|
580
|
-
return mutationQuery;
|
|
581
|
-
}
|
|
582
|
-
function getResourceId(state) {
|
|
583
|
-
const candidate = state.conditions.find(
|
|
584
|
-
(condition) => condition.operator === "eq" && (condition.column === "resource_id" || condition.column === "id")
|
|
585
|
-
);
|
|
586
|
-
return candidate?.value?.toString();
|
|
587
573
|
}
|
|
588
|
-
function
|
|
589
|
-
if (
|
|
590
|
-
return
|
|
574
|
+
function extractFetchOptions(input) {
|
|
575
|
+
if (!input) {
|
|
576
|
+
return {
|
|
577
|
+
payload: void 0,
|
|
578
|
+
fetchOptions: void 0
|
|
579
|
+
};
|
|
591
580
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
return column === "id" || /(?:^|_)uuid(?:_|$)/i.test(column) || /_id$/i.test(column);
|
|
599
|
-
}
|
|
600
|
-
function shouldUseUuidTextComparison(column, value) {
|
|
601
|
-
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
581
|
+
const { fetchOptions, ...rest } = input;
|
|
582
|
+
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
583
|
+
return {
|
|
584
|
+
payload: hasPayloadKeys ? rest : void 0,
|
|
585
|
+
fetchOptions
|
|
586
|
+
};
|
|
602
587
|
}
|
|
603
|
-
function
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
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;
|
|
607
597
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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;
|
|
622
613
|
}
|
|
623
|
-
function
|
|
624
|
-
if (
|
|
625
|
-
|
|
614
|
+
function appendQueryParam(searchParams, key, value) {
|
|
615
|
+
if (value === void 0 || value === null) return;
|
|
616
|
+
if (Array.isArray(value)) {
|
|
617
|
+
value.forEach((item) => {
|
|
618
|
+
searchParams.append(key, String(item));
|
|
619
|
+
});
|
|
620
|
+
return;
|
|
626
621
|
}
|
|
627
|
-
|
|
622
|
+
searchParams.append(key, String(value));
|
|
628
623
|
}
|
|
629
|
-
function
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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;
|
|
631
|
+
}
|
|
632
|
+
function inferDefaultMethod(endpoint) {
|
|
633
|
+
if (endpoint.startsWith("/reset-password/")) {
|
|
634
|
+
return "GET";
|
|
634
635
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
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";
|
|
642
673
|
}
|
|
643
|
-
return `${normalizedSchema}.${tableName}`;
|
|
644
674
|
}
|
|
645
|
-
function
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
lte: "<=",
|
|
656
|
-
like: "LIKE",
|
|
657
|
-
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
|
|
658
685
|
};
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
686
|
+
if (context.method !== "GET") {
|
|
687
|
+
requestInit.body = JSON.stringify(body ?? {});
|
|
688
|
+
}
|
|
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
|
+
};
|
|
707
|
+
}
|
|
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)
|
|
723
|
+
});
|
|
724
|
+
return {
|
|
725
|
+
ok: false,
|
|
726
|
+
status: response.status,
|
|
727
|
+
data: null,
|
|
728
|
+
error: details.message,
|
|
729
|
+
errorDetails: details,
|
|
730
|
+
raw: parsedBody.parsed
|
|
731
|
+
};
|
|
677
732
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
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
|
+
};
|
|
683
754
|
}
|
|
684
|
-
|
|
685
|
-
|
|
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
|
+
};
|
|
686
782
|
}
|
|
687
783
|
}
|
|
688
|
-
function
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
if (!clause) return null;
|
|
693
|
-
whereClauses.push(clause);
|
|
694
|
-
}
|
|
695
|
-
let limit = input.limit;
|
|
696
|
-
let offset = input.offset;
|
|
697
|
-
if (limit === void 0 && input.pageSize !== void 0) {
|
|
698
|
-
limit = input.pageSize;
|
|
699
|
-
}
|
|
700
|
-
if (offset === void 0 && input.pageSize !== void 0 && input.currentPage !== void 0 && input.currentPage > 0) {
|
|
701
|
-
offset = (input.currentPage - 1) * input.pageSize;
|
|
702
|
-
}
|
|
703
|
-
const sqlParts = [
|
|
704
|
-
`SELECT ${buildSelectColumnsClause(input.columns)} FROM ${quoteQualifiedIdentifier(input.tableName)}`
|
|
705
|
-
];
|
|
706
|
-
if (whereClauses.length > 0) {
|
|
707
|
-
sqlParts.push(`WHERE ${whereClauses.join(" AND ")}`);
|
|
708
|
-
}
|
|
709
|
-
if (input.order?.field) {
|
|
710
|
-
const direction = input.order.direction === "descending" ? "DESC" : "ASC";
|
|
711
|
-
sqlParts.push(`ORDER BY ${quoteQualifiedIdentifier(input.order.field)} ${direction}`);
|
|
712
|
-
}
|
|
713
|
-
if (limit !== void 0) {
|
|
714
|
-
sqlParts.push(`LIMIT ${Math.max(0, Math.trunc(limit))}`);
|
|
715
|
-
}
|
|
716
|
-
if (offset !== void 0) {
|
|
717
|
-
sqlParts.push(`OFFSET ${Math.max(0, Math.trunc(offset))}`);
|
|
718
|
-
}
|
|
719
|
-
return `${sqlParts.join(" ")};`;
|
|
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);
|
|
720
788
|
}
|
|
721
|
-
function
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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);
|
|
793
|
+
}
|
|
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
|
|
816
|
+
};
|
|
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
|
+
);
|
|
827
|
+
};
|
|
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
|
+
);
|
|
839
|
+
};
|
|
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
|
+
);
|
|
850
|
+
};
|
|
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;
|
|
872
|
+
}
|
|
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;
|
|
883
|
+
}
|
|
884
|
+
const fallback = await getGeneric("/ok", input, options);
|
|
885
|
+
if (!fallback.ok) {
|
|
886
|
+
return {
|
|
887
|
+
...fallback,
|
|
888
|
+
data: null
|
|
889
|
+
};
|
|
890
|
+
}
|
|
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
|
|
729
896
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
897
|
+
};
|
|
898
|
+
};
|
|
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
|
+
)
|
|
752
1056
|
},
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
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
|
+
);
|
|
757
1237
|
},
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
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
|
+
}
|
|
761
1249
|
},
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
1250
|
+
session: {
|
|
1251
|
+
list: (input, options) => getGeneric("/list-sessions", input, options),
|
|
1252
|
+
revoke: sessionRevokeBinding,
|
|
1253
|
+
revokeOther: revokeOtherSessions
|
|
765
1254
|
},
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
return self;
|
|
1255
|
+
social: {
|
|
1256
|
+
link: (input, options) => postGeneric("/link-social", input, options)
|
|
769
1257
|
},
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1258
|
+
account: {
|
|
1259
|
+
list: (input, options) => getGeneric("/list-accounts", input, options),
|
|
1260
|
+
unlink: (input, options) => postGeneric("/unlink-account", input, options)
|
|
773
1261
|
},
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
return self;
|
|
1262
|
+
deleteUser: {
|
|
1263
|
+
callback: deleteUserCallback
|
|
777
1264
|
},
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
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)
|
|
784
1284
|
},
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
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)
|
|
788
1294
|
},
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
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
|
+
}
|
|
792
1352
|
},
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
addCondition("like", String(column), value);
|
|
807
|
-
return self;
|
|
808
|
-
},
|
|
809
|
-
ilike(column, value) {
|
|
810
|
-
addCondition("ilike", String(column), value);
|
|
811
|
-
return self;
|
|
812
|
-
},
|
|
813
|
-
is(column, value) {
|
|
814
|
-
addCondition("is", String(column), value);
|
|
815
|
-
return self;
|
|
816
|
-
},
|
|
817
|
-
in(column, values) {
|
|
818
|
-
addCondition("in", String(column), values);
|
|
819
|
-
return self;
|
|
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
|
+
)
|
|
820
1366
|
},
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
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)
|
|
824
1371
|
},
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
return self;
|
|
1372
|
+
signUp: {
|
|
1373
|
+
email: (input, options) => postGeneric("/sign-up/email", input, options)
|
|
828
1374
|
},
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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);
|
|
835
1399
|
}
|
|
836
|
-
return self;
|
|
837
|
-
},
|
|
838
|
-
or(expression) {
|
|
839
|
-
addCondition("or", void 0, expression);
|
|
840
|
-
return self;
|
|
841
1400
|
}
|
|
842
1401
|
};
|
|
843
|
-
}
|
|
844
|
-
function toRpcSelect(columns) {
|
|
845
|
-
if (!columns) return void 0;
|
|
846
|
-
return Array.isArray(columns) ? columns.join(",") : columns;
|
|
847
|
-
}
|
|
848
|
-
function createRpcFilterMethods(filters, self) {
|
|
849
|
-
const addFilter = (operator, column, value) => {
|
|
850
|
-
filters.push({ column, operator, value });
|
|
851
|
-
};
|
|
852
1402
|
return {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
addFilter("lte", column, value);
|
|
875
|
-
return self;
|
|
876
|
-
},
|
|
877
|
-
like(column, value) {
|
|
878
|
-
addFilter("like", column, value);
|
|
879
|
-
return self;
|
|
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
|
+
)
|
|
880
1424
|
},
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1425
|
+
signUp: {
|
|
1426
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
1427
|
+
resolvedConfig,
|
|
1428
|
+
{ endpoint: "/sign-up/email", method: "POST" },
|
|
1429
|
+
input,
|
|
1430
|
+
options
|
|
1431
|
+
)
|
|
884
1432
|
},
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
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
|
+
);
|
|
888
1480
|
},
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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
|
|
893
1539
|
};
|
|
894
1540
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
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
|
|
898
1553
|
};
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
count: mergedOptions?.count,
|
|
911
|
-
head: mergedOptions?.head,
|
|
912
|
-
limit: state.limit,
|
|
913
|
-
offset: state.offset,
|
|
914
|
-
order: state.order
|
|
915
|
-
};
|
|
916
|
-
const response = await client.rpcGateway(payload, mergedOptions);
|
|
917
|
-
return formatResult(response);
|
|
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
|
|
918
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;
|
|
919
1583
|
const run = (columns, options) => {
|
|
920
1584
|
const payloadColumns = columns ?? selectedColumns;
|
|
921
1585
|
const payloadOptions = options ?? selectedOptions;
|
|
922
1586
|
if (!promise) {
|
|
923
|
-
promise =
|
|
1587
|
+
promise = executor(payloadColumns, payloadOptions);
|
|
924
1588
|
}
|
|
925
1589
|
return promise;
|
|
926
1590
|
};
|
|
927
|
-
const
|
|
928
|
-
const filterMethods = createRpcFilterMethods(state.filters, builder);
|
|
929
|
-
Object.assign(builder, filterMethods, {
|
|
1591
|
+
const mutationQuery = {
|
|
930
1592
|
select(columns = selectedColumns, options) {
|
|
931
1593
|
selectedColumns = columns;
|
|
932
1594
|
selectedOptions = options ?? selectedOptions;
|
|
933
1595
|
return run(columns, options);
|
|
934
1596
|
},
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
return toSingleResult(result);
|
|
938
|
-
},
|
|
939
|
-
maybeSingle(columns, options) {
|
|
940
|
-
return builder.single(columns, options);
|
|
941
|
-
},
|
|
942
|
-
order(column, options) {
|
|
943
|
-
state.order = { column, ascending: options?.ascending ?? true };
|
|
944
|
-
return builder;
|
|
945
|
-
},
|
|
946
|
-
limit(count) {
|
|
947
|
-
state.limit = count;
|
|
948
|
-
return builder;
|
|
1597
|
+
returning(columns = selectedColumns, options) {
|
|
1598
|
+
return mutationQuery.select(columns, options);
|
|
949
1599
|
},
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1600
|
+
single(columns = selectedColumns, options) {
|
|
1601
|
+
selectedColumns = columns;
|
|
1602
|
+
selectedOptions = options ?? selectedOptions;
|
|
1603
|
+
return run(columns, options).then(toSingleResult);
|
|
953
1604
|
},
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
state.limit = to - from + 1;
|
|
957
|
-
return builder;
|
|
1605
|
+
maybeSingle(columns = selectedColumns, options) {
|
|
1606
|
+
return mutationQuery.single(columns, options);
|
|
958
1607
|
},
|
|
959
1608
|
then(onfulfilled, onrejected) {
|
|
960
1609
|
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
@@ -965,129 +1614,518 @@ function createRpcBuilder(functionName, args, baseOptions, client) {
|
|
|
965
1614
|
finally(onfinally) {
|
|
966
1615
|
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
967
1616
|
}
|
|
968
|
-
}
|
|
969
|
-
return
|
|
1617
|
+
};
|
|
1618
|
+
return mutationQuery;
|
|
970
1619
|
}
|
|
971
|
-
function
|
|
972
|
-
const
|
|
973
|
-
|
|
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"
|
|
974
1696
|
};
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
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}`;
|
|
982
1709
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
if (
|
|
986
|
-
|
|
987
|
-
|
|
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;
|
|
988
1715
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
if (
|
|
992
|
-
|
|
993
|
-
}
|
|
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(", ")})`;
|
|
994
1721
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
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);
|
|
999
1767
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
limit: state.limit,
|
|
1021
|
-
offset: state.offset,
|
|
1022
|
-
currentPage: state.currentPage,
|
|
1023
|
-
pageSize: state.pageSize,
|
|
1024
|
-
order: state.order
|
|
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
|
+
}
|
|
1025
1788
|
});
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
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);
|
|
1029
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;
|
|
1030
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);
|
|
1031
1942
|
const payload = {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
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,
|
|
1035
1950
|
limit: state.limit,
|
|
1036
1951
|
offset: state.offset,
|
|
1037
|
-
|
|
1038
|
-
page_size: state.pageSize,
|
|
1039
|
-
total_pages: state.totalPages,
|
|
1040
|
-
sort_by: state.order,
|
|
1041
|
-
strip_nulls: options?.stripNulls ?? true,
|
|
1042
|
-
count: options?.count,
|
|
1043
|
-
head: options?.head
|
|
1952
|
+
order: state.order
|
|
1044
1953
|
};
|
|
1045
|
-
const response = await client.
|
|
1954
|
+
const response = await client.rpcGateway(payload, mergedOptions);
|
|
1046
1955
|
return formatResult(response);
|
|
1047
1956
|
};
|
|
1048
|
-
const
|
|
1049
|
-
const
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
},
|
|
1056
|
-
maybeSingle(cols, opts) {
|
|
1057
|
-
return chain.single(cols, opts);
|
|
1058
|
-
},
|
|
1059
|
-
then(onfulfilled, onrejected) {
|
|
1060
|
-
return runSelect(columns, options).then(onfulfilled, onrejected);
|
|
1061
|
-
},
|
|
1062
|
-
catch(onrejected) {
|
|
1063
|
-
return runSelect(columns, options).catch(onrejected);
|
|
1064
|
-
},
|
|
1065
|
-
finally(onfinally) {
|
|
1066
|
-
return runSelect(columns, options).finally(onfinally);
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
return chain;
|
|
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;
|
|
1070
1964
|
};
|
|
1965
|
+
const builder = {};
|
|
1966
|
+
const filterMethods = createRpcFilterMethods(state.filters, builder);
|
|
1071
1967
|
Object.assign(builder, filterMethods, {
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
state.order = void 0;
|
|
1077
|
-
state.currentPage = void 0;
|
|
1078
|
-
state.pageSize = void 0;
|
|
1079
|
-
state.totalPages = void 0;
|
|
1080
|
-
return builder;
|
|
1968
|
+
select(columns = selectedColumns, options) {
|
|
1969
|
+
selectedColumns = columns;
|
|
1970
|
+
selectedOptions = options ?? selectedOptions;
|
|
1971
|
+
return run(columns, options);
|
|
1081
1972
|
},
|
|
1082
|
-
|
|
1083
|
-
|
|
1973
|
+
async single(columns, options) {
|
|
1974
|
+
const result = await run(columns, options);
|
|
1975
|
+
return toSingleResult(result);
|
|
1084
1976
|
},
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
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 = [];
|
|
2112
|
+
state.limit = void 0;
|
|
2113
|
+
state.offset = void 0;
|
|
2114
|
+
state.order = void 0;
|
|
2115
|
+
state.currentPage = void 0;
|
|
2116
|
+
state.pageSize = void 0;
|
|
2117
|
+
state.totalPages = void 0;
|
|
2118
|
+
return builder;
|
|
2119
|
+
},
|
|
2120
|
+
select(columns = DEFAULT_COLUMNS, options) {
|
|
2121
|
+
return createSelectChain(columns, options);
|
|
2122
|
+
},
|
|
2123
|
+
insert(values, options) {
|
|
2124
|
+
if (Array.isArray(values)) {
|
|
2125
|
+
const executeInsertMany = async (columns, selectOptions) => {
|
|
2126
|
+
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2127
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
2128
|
+
const payload = {
|
|
1091
2129
|
table_name: resolvedTableName,
|
|
1092
2130
|
insert_body: asAthenaJsonObjectArray(values)
|
|
1093
2131
|
};
|
|
@@ -1239,6 +2277,7 @@ function createClientFromConfig(config) {
|
|
|
1239
2277
|
backend: config.backend,
|
|
1240
2278
|
headers: config.headers
|
|
1241
2279
|
});
|
|
2280
|
+
const auth = createAuthClient(config.auth);
|
|
1242
2281
|
return {
|
|
1243
2282
|
from(table) {
|
|
1244
2283
|
return createTableBuilder(table, gateway);
|
|
@@ -1255,7 +2294,8 @@ function createClientFromConfig(config) {
|
|
|
1255
2294
|
gateway
|
|
1256
2295
|
);
|
|
1257
2296
|
},
|
|
1258
|
-
query: createQueryBuilder(gateway)
|
|
2297
|
+
query: createQueryBuilder(gateway),
|
|
2298
|
+
auth: auth.auth
|
|
1259
2299
|
};
|
|
1260
2300
|
}
|
|
1261
2301
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
@@ -1329,7 +2369,11 @@ function createClient(url, apiKey, options) {
|
|
|
1329
2369
|
const b = AthenaClient.builder().url(url).key(apiKey).backend(toBackendConfig(options?.backend));
|
|
1330
2370
|
if (options?.client) b.client(options.client);
|
|
1331
2371
|
if (options?.headers && Object.keys(options.headers).length > 0) b.headers(options.headers);
|
|
1332
|
-
|
|
2372
|
+
const client = b.build();
|
|
2373
|
+
if (options?.auth) {
|
|
2374
|
+
client.auth = createAuthClient(options.auth).auth;
|
|
2375
|
+
}
|
|
2376
|
+
return client;
|
|
1333
2377
|
}
|
|
1334
2378
|
|
|
1335
2379
|
// src/gateway/types.ts
|
|
@@ -1369,6 +2413,17 @@ var AthenaErrorCategory = {
|
|
|
1369
2413
|
Database: "database",
|
|
1370
2414
|
Unknown: "unknown"
|
|
1371
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
|
+
}
|
|
1372
2427
|
var AthenaError = class extends Error {
|
|
1373
2428
|
code;
|
|
1374
2429
|
kind;
|
|
@@ -1391,7 +2446,7 @@ var AthenaError = class extends Error {
|
|
|
1391
2446
|
this.raw = input.raw;
|
|
1392
2447
|
}
|
|
1393
2448
|
};
|
|
1394
|
-
function
|
|
2449
|
+
function isRecord3(value) {
|
|
1395
2450
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1396
2451
|
}
|
|
1397
2452
|
function safeStringify(value) {
|
|
@@ -1408,7 +2463,7 @@ function contextHint(context) {
|
|
|
1408
2463
|
return `Identity: ${identity}`;
|
|
1409
2464
|
}
|
|
1410
2465
|
function isAthenaResultLike(value) {
|
|
1411
|
-
return
|
|
2466
|
+
return isRecord3(value) && "status" in value && "error" in value && "data" in value && typeof value.status === "number";
|
|
1412
2467
|
}
|
|
1413
2468
|
function operationFromDetails(details) {
|
|
1414
2469
|
if (!details?.endpoint) return void 0;
|
|
@@ -1574,7 +2629,7 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
1574
2629
|
};
|
|
1575
2630
|
}
|
|
1576
2631
|
if (resultOrError instanceof Error) {
|
|
1577
|
-
const maybeStatus =
|
|
2632
|
+
const maybeStatus = isRecord3(resultOrError) && typeof resultOrError.status === "number" ? resultOrError.status : void 0;
|
|
1578
2633
|
const kind2 = classifyKind(maybeStatus, void 0, resultOrError.message);
|
|
1579
2634
|
return {
|
|
1580
2635
|
kind: kind2,
|
|
@@ -2316,7 +3371,7 @@ function resolveNullishValue(mode) {
|
|
|
2316
3371
|
if (mode === "null") return null;
|
|
2317
3372
|
return "";
|
|
2318
3373
|
}
|
|
2319
|
-
function
|
|
3374
|
+
function isRecord4(value) {
|
|
2320
3375
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2321
3376
|
}
|
|
2322
3377
|
function isNullableColumn(model, key) {
|
|
@@ -2325,7 +3380,7 @@ function isNullableColumn(model, key) {
|
|
|
2325
3380
|
}
|
|
2326
3381
|
function toModelFormDefaults(model, values, options) {
|
|
2327
3382
|
const source = values;
|
|
2328
|
-
if (!
|
|
3383
|
+
if (!isRecord4(source)) {
|
|
2329
3384
|
return {};
|
|
2330
3385
|
}
|
|
2331
3386
|
const mode = options?.nullishMode ?? "empty-string";
|
|
@@ -2430,6 +3485,39 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
2430
3485
|
postgresGatewayIntrospection: false,
|
|
2431
3486
|
scyllaProviderContracts: true
|
|
2432
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
|
+
}
|
|
2433
3521
|
function normalizeOutputConfig(output) {
|
|
2434
3522
|
return {
|
|
2435
3523
|
targets: {
|
|
@@ -2465,14 +3553,8 @@ function normalizeGeneratorConfig(input) {
|
|
|
2465
3553
|
...DEFAULT_NAMING,
|
|
2466
3554
|
...input.naming ?? {}
|
|
2467
3555
|
},
|
|
2468
|
-
features:
|
|
2469
|
-
|
|
2470
|
-
...input.features ?? {}
|
|
2471
|
-
},
|
|
2472
|
-
experimental: {
|
|
2473
|
-
...DEFAULT_EXPERIMENTAL_FLAGS,
|
|
2474
|
-
...input.experimental ?? {}
|
|
2475
|
-
}
|
|
3556
|
+
features: normalizeFeatureFlags(input.features),
|
|
3557
|
+
experimental: normalizeExperimentalFlags(input.experimental)
|
|
2476
3558
|
};
|
|
2477
3559
|
}
|
|
2478
3560
|
function defineGeneratorConfig(config) {
|
|
@@ -3221,497 +4303,6 @@ async function runSchemaGenerator(options = {}) {
|
|
|
3221
4303
|
};
|
|
3222
4304
|
}
|
|
3223
4305
|
|
|
3224
|
-
|
|
3225
|
-
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
3226
|
-
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
3227
|
-
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
3228
|
-
var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
|
|
3229
|
-
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
3230
|
-
function normalizeBaseUrl(baseUrl) {
|
|
3231
|
-
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
3232
|
-
}
|
|
3233
|
-
function isRecord4(value) {
|
|
3234
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3235
|
-
}
|
|
3236
|
-
function normalizeHeaderValue2(value) {
|
|
3237
|
-
return value ? value : void 0;
|
|
3238
|
-
}
|
|
3239
|
-
function parseResponseBody2(rawText, contentType) {
|
|
3240
|
-
if (!rawText) {
|
|
3241
|
-
return { parsed: null, parseFailed: false };
|
|
3242
|
-
}
|
|
3243
|
-
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
3244
|
-
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
3245
|
-
if (!looksJson) {
|
|
3246
|
-
return { parsed: rawText, parseFailed: false };
|
|
3247
|
-
}
|
|
3248
|
-
try {
|
|
3249
|
-
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
3250
|
-
} catch {
|
|
3251
|
-
return { parsed: rawText, parseFailed: true };
|
|
3252
|
-
}
|
|
3253
|
-
}
|
|
3254
|
-
function resolveRequestId2(headers) {
|
|
3255
|
-
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
3256
|
-
}
|
|
3257
|
-
function resolveErrorMessage2(payload, fallback) {
|
|
3258
|
-
if (isRecord4(payload)) {
|
|
3259
|
-
const messageCandidates = [payload.error, payload.message, payload.details];
|
|
3260
|
-
for (const candidate of messageCandidates) {
|
|
3261
|
-
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
3262
|
-
return candidate.trim();
|
|
3263
|
-
}
|
|
3264
|
-
}
|
|
3265
|
-
}
|
|
3266
|
-
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
3267
|
-
return payload.trim();
|
|
3268
|
-
}
|
|
3269
|
-
return fallback;
|
|
3270
|
-
}
|
|
3271
|
-
function toErrorDetails(input) {
|
|
3272
|
-
return {
|
|
3273
|
-
code: input.code,
|
|
3274
|
-
message: input.message,
|
|
3275
|
-
status: input.status,
|
|
3276
|
-
endpoint: input.endpoint,
|
|
3277
|
-
method: input.method,
|
|
3278
|
-
requestId: input.requestId,
|
|
3279
|
-
hint: input.hint,
|
|
3280
|
-
cause: input.cause
|
|
3281
|
-
};
|
|
3282
|
-
}
|
|
3283
|
-
function mergeCallOptions(base, override) {
|
|
3284
|
-
if (!base && !override) return void 0;
|
|
3285
|
-
return {
|
|
3286
|
-
...base,
|
|
3287
|
-
...override,
|
|
3288
|
-
headers: {
|
|
3289
|
-
...base?.headers ?? {},
|
|
3290
|
-
...override?.headers ?? {}
|
|
3291
|
-
}
|
|
3292
|
-
};
|
|
3293
|
-
}
|
|
3294
|
-
function extractFetchOptions(input) {
|
|
3295
|
-
if (!input) {
|
|
3296
|
-
return {
|
|
3297
|
-
payload: void 0,
|
|
3298
|
-
fetchOptions: void 0
|
|
3299
|
-
};
|
|
3300
|
-
}
|
|
3301
|
-
const { fetchOptions, ...rest } = input;
|
|
3302
|
-
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
3303
|
-
return {
|
|
3304
|
-
payload: hasPayloadKeys ? rest : void 0,
|
|
3305
|
-
fetchOptions
|
|
3306
|
-
};
|
|
3307
|
-
}
|
|
3308
|
-
function buildHeaders2(config, options) {
|
|
3309
|
-
const headers = {
|
|
3310
|
-
"Content-Type": "application/json",
|
|
3311
|
-
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
3312
|
-
};
|
|
3313
|
-
const apiKey = options?.apiKey ?? config.apiKey;
|
|
3314
|
-
if (apiKey) {
|
|
3315
|
-
headers.apikey = apiKey;
|
|
3316
|
-
headers["x-api-key"] = apiKey;
|
|
3317
|
-
}
|
|
3318
|
-
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
3319
|
-
if (bearerToken) {
|
|
3320
|
-
headers.Authorization = `Bearer ${bearerToken}`;
|
|
3321
|
-
}
|
|
3322
|
-
const mergedExtraHeaders = {
|
|
3323
|
-
...config.headers ?? {},
|
|
3324
|
-
...options?.headers ?? {}
|
|
3325
|
-
};
|
|
3326
|
-
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
3327
|
-
const normalized = normalizeHeaderValue2(value);
|
|
3328
|
-
if (normalized) {
|
|
3329
|
-
headers[key] = normalized;
|
|
3330
|
-
}
|
|
3331
|
-
});
|
|
3332
|
-
return headers;
|
|
3333
|
-
}
|
|
3334
|
-
function appendQueryParam(searchParams, key, value) {
|
|
3335
|
-
if (value === void 0 || value === null) return;
|
|
3336
|
-
if (Array.isArray(value)) {
|
|
3337
|
-
value.forEach((item) => {
|
|
3338
|
-
searchParams.append(key, String(item));
|
|
3339
|
-
});
|
|
3340
|
-
return;
|
|
3341
|
-
}
|
|
3342
|
-
searchParams.append(key, String(value));
|
|
3343
|
-
}
|
|
3344
|
-
function buildRequestUrl(baseUrl, endpoint, query) {
|
|
3345
|
-
const url = `${baseUrl}${endpoint}`;
|
|
3346
|
-
if (!query || Object.keys(query).length === 0) return url;
|
|
3347
|
-
const searchParams = new URLSearchParams();
|
|
3348
|
-
Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
|
|
3349
|
-
const queryText = searchParams.toString();
|
|
3350
|
-
return queryText ? `${url}?${queryText}` : url;
|
|
3351
|
-
}
|
|
3352
|
-
function inferDefaultMethod(endpoint) {
|
|
3353
|
-
if (endpoint.startsWith("/reset-password/")) {
|
|
3354
|
-
return "GET";
|
|
3355
|
-
}
|
|
3356
|
-
switch (endpoint) {
|
|
3357
|
-
case "/get-session":
|
|
3358
|
-
case "/list-sessions":
|
|
3359
|
-
case "/verify-email":
|
|
3360
|
-
case "/delete-user/callback":
|
|
3361
|
-
case "/list-accounts":
|
|
3362
|
-
case "/ok":
|
|
3363
|
-
case "/error":
|
|
3364
|
-
return "GET";
|
|
3365
|
-
default:
|
|
3366
|
-
return "POST";
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
async function callAuthEndpoint(config, context, body, query, options) {
|
|
3370
|
-
const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
3371
|
-
const url = buildRequestUrl(baseUrl, context.endpoint, query);
|
|
3372
|
-
const headers = buildHeaders2(config, options);
|
|
3373
|
-
const credentials = options?.credentials ?? config.credentials ?? "include";
|
|
3374
|
-
const requestInit = {
|
|
3375
|
-
method: context.method,
|
|
3376
|
-
headers,
|
|
3377
|
-
credentials,
|
|
3378
|
-
signal: options?.signal
|
|
3379
|
-
};
|
|
3380
|
-
if (context.method !== "GET") {
|
|
3381
|
-
requestInit.body = JSON.stringify(body ?? {});
|
|
3382
|
-
}
|
|
3383
|
-
const fetcher = config.fetch ?? globalThis.fetch;
|
|
3384
|
-
if (!fetcher) {
|
|
3385
|
-
const details = toErrorDetails({
|
|
3386
|
-
code: "UNKNOWN_ERROR",
|
|
3387
|
-
message: "No fetch implementation available for auth client",
|
|
3388
|
-
status: 0,
|
|
3389
|
-
endpoint: context.endpoint,
|
|
3390
|
-
method: context.method,
|
|
3391
|
-
hint: "Use Node 18+ or provide `fetch` in createAuthClient({ fetch })"
|
|
3392
|
-
});
|
|
3393
|
-
return {
|
|
3394
|
-
ok: false,
|
|
3395
|
-
status: 0,
|
|
3396
|
-
data: null,
|
|
3397
|
-
error: details.message,
|
|
3398
|
-
errorDetails: details,
|
|
3399
|
-
raw: null
|
|
3400
|
-
};
|
|
3401
|
-
}
|
|
3402
|
-
try {
|
|
3403
|
-
const response = await fetcher(url, requestInit);
|
|
3404
|
-
const rawText = await response.text();
|
|
3405
|
-
const requestId = resolveRequestId2(response.headers);
|
|
3406
|
-
const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
|
|
3407
|
-
if (parsedBody.parseFailed) {
|
|
3408
|
-
const details = toErrorDetails({
|
|
3409
|
-
code: "INVALID_JSON",
|
|
3410
|
-
message: "Auth server returned malformed JSON",
|
|
3411
|
-
status: response.status,
|
|
3412
|
-
endpoint: context.endpoint,
|
|
3413
|
-
method: context.method,
|
|
3414
|
-
requestId,
|
|
3415
|
-
hint: "Verify the auth endpoint response body is valid JSON.",
|
|
3416
|
-
cause: rawText.slice(0, 300)
|
|
3417
|
-
});
|
|
3418
|
-
return {
|
|
3419
|
-
ok: false,
|
|
3420
|
-
status: response.status,
|
|
3421
|
-
data: null,
|
|
3422
|
-
error: details.message,
|
|
3423
|
-
errorDetails: details,
|
|
3424
|
-
raw: parsedBody.parsed
|
|
3425
|
-
};
|
|
3426
|
-
}
|
|
3427
|
-
const parsed = parsedBody.parsed;
|
|
3428
|
-
if (!response.ok) {
|
|
3429
|
-
const details = toErrorDetails({
|
|
3430
|
-
code: "HTTP_ERROR",
|
|
3431
|
-
message: resolveErrorMessage2(
|
|
3432
|
-
parsed,
|
|
3433
|
-
`Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
|
|
3434
|
-
),
|
|
3435
|
-
status: response.status,
|
|
3436
|
-
endpoint: context.endpoint,
|
|
3437
|
-
method: context.method,
|
|
3438
|
-
requestId
|
|
3439
|
-
});
|
|
3440
|
-
return {
|
|
3441
|
-
ok: false,
|
|
3442
|
-
status: response.status,
|
|
3443
|
-
data: null,
|
|
3444
|
-
error: details.message,
|
|
3445
|
-
errorDetails: details,
|
|
3446
|
-
raw: parsed
|
|
3447
|
-
};
|
|
3448
|
-
}
|
|
3449
|
-
return {
|
|
3450
|
-
ok: true,
|
|
3451
|
-
status: response.status,
|
|
3452
|
-
data: parsed ?? null,
|
|
3453
|
-
error: null,
|
|
3454
|
-
errorDetails: null,
|
|
3455
|
-
raw: parsed
|
|
3456
|
-
};
|
|
3457
|
-
} catch (callError) {
|
|
3458
|
-
const message = callError instanceof Error ? callError.message : String(callError);
|
|
3459
|
-
const details = toErrorDetails({
|
|
3460
|
-
code: "NETWORK_ERROR",
|
|
3461
|
-
message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
|
|
3462
|
-
status: 0,
|
|
3463
|
-
endpoint: context.endpoint,
|
|
3464
|
-
method: context.method,
|
|
3465
|
-
cause: message,
|
|
3466
|
-
hint: "Check auth server URL, DNS, and network reachability."
|
|
3467
|
-
});
|
|
3468
|
-
return {
|
|
3469
|
-
ok: false,
|
|
3470
|
-
status: 0,
|
|
3471
|
-
data: null,
|
|
3472
|
-
error: details.message,
|
|
3473
|
-
errorDetails: details,
|
|
3474
|
-
raw: null
|
|
3475
|
-
};
|
|
3476
|
-
}
|
|
3477
|
-
}
|
|
3478
|
-
function executePostWithCompatibleInput(config, context, input, options) {
|
|
3479
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3480
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3481
|
-
return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
|
|
3482
|
-
}
|
|
3483
|
-
function executePostWithOptionalInput(config, context, input, options) {
|
|
3484
|
-
const { fetchOptions } = extractFetchOptions(input);
|
|
3485
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3486
|
-
return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
|
|
3487
|
-
}
|
|
3488
|
-
function executeGetWithCompatibleInput(config, context, input, options) {
|
|
3489
|
-
const { fetchOptions } = extractFetchOptions(input);
|
|
3490
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3491
|
-
return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
|
|
3492
|
-
}
|
|
3493
|
-
function createAuthClient(config = {}) {
|
|
3494
|
-
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
3495
|
-
const resolvedConfig = {
|
|
3496
|
-
...config,
|
|
3497
|
-
baseUrl: normalizedBaseUrl
|
|
3498
|
-
};
|
|
3499
|
-
const request = (input, options) => {
|
|
3500
|
-
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
3501
|
-
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
3502
|
-
return callAuthEndpoint(
|
|
3503
|
-
resolvedConfig,
|
|
3504
|
-
{ endpoint: input.endpoint, method },
|
|
3505
|
-
input.body,
|
|
3506
|
-
input.query,
|
|
3507
|
-
mergedOptions
|
|
3508
|
-
);
|
|
3509
|
-
};
|
|
3510
|
-
const signOut = (input, options) => executePostWithOptionalInput(
|
|
3511
|
-
resolvedConfig,
|
|
3512
|
-
{ endpoint: "/sign-out", method: "POST" },
|
|
3513
|
-
input,
|
|
3514
|
-
options
|
|
3515
|
-
);
|
|
3516
|
-
const revokeSessions = (input, options) => executePostWithOptionalInput(
|
|
3517
|
-
resolvedConfig,
|
|
3518
|
-
{ endpoint: "/revoke-sessions", method: "POST" },
|
|
3519
|
-
input,
|
|
3520
|
-
options
|
|
3521
|
-
);
|
|
3522
|
-
const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
|
|
3523
|
-
resolvedConfig,
|
|
3524
|
-
{ endpoint: "/revoke-other-sessions", method: "POST" },
|
|
3525
|
-
input,
|
|
3526
|
-
options
|
|
3527
|
-
);
|
|
3528
|
-
const revokeSession = (input, options) => executePostWithCompatibleInput(
|
|
3529
|
-
resolvedConfig,
|
|
3530
|
-
{ endpoint: "/revoke-session", method: "POST" },
|
|
3531
|
-
input,
|
|
3532
|
-
options
|
|
3533
|
-
);
|
|
3534
|
-
const deleteUser = (input, options) => {
|
|
3535
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3536
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3537
|
-
return callAuthEndpoint(
|
|
3538
|
-
resolvedConfig,
|
|
3539
|
-
{ endpoint: "/delete-user", method: "POST" },
|
|
3540
|
-
payload ?? {},
|
|
3541
|
-
void 0,
|
|
3542
|
-
mergedOptions
|
|
3543
|
-
);
|
|
3544
|
-
};
|
|
3545
|
-
const deleteUserCallback = (input, options) => {
|
|
3546
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3547
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3548
|
-
const query = payload ?? {};
|
|
3549
|
-
return callAuthEndpoint(
|
|
3550
|
-
resolvedConfig,
|
|
3551
|
-
{ endpoint: "/delete-user/callback", method: "GET" },
|
|
3552
|
-
void 0,
|
|
3553
|
-
{
|
|
3554
|
-
token: query.token,
|
|
3555
|
-
callbackURL: query.callbackURL
|
|
3556
|
-
},
|
|
3557
|
-
mergedOptions
|
|
3558
|
-
);
|
|
3559
|
-
};
|
|
3560
|
-
const resolveResetPasswordToken = (input, options) => {
|
|
3561
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3562
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3563
|
-
const query = payload;
|
|
3564
|
-
const token = query?.token?.trim();
|
|
3565
|
-
if (!token) {
|
|
3566
|
-
throw new Error("resolveResetPasswordToken requires a non-empty token");
|
|
3567
|
-
}
|
|
3568
|
-
const endpoint = `/reset-password/${encodeURIComponent(token)}`;
|
|
3569
|
-
return callAuthEndpoint(
|
|
3570
|
-
resolvedConfig,
|
|
3571
|
-
{ endpoint, method: "GET" },
|
|
3572
|
-
void 0,
|
|
3573
|
-
query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
|
|
3574
|
-
mergedOptions
|
|
3575
|
-
);
|
|
3576
|
-
};
|
|
3577
|
-
return {
|
|
3578
|
-
baseUrl: normalizedBaseUrl,
|
|
3579
|
-
request,
|
|
3580
|
-
signIn: {
|
|
3581
|
-
email: (input, options) => executePostWithCompatibleInput(
|
|
3582
|
-
resolvedConfig,
|
|
3583
|
-
{ endpoint: "/sign-in/email", method: "POST" },
|
|
3584
|
-
input,
|
|
3585
|
-
options
|
|
3586
|
-
),
|
|
3587
|
-
username: (input, options) => executePostWithCompatibleInput(
|
|
3588
|
-
resolvedConfig,
|
|
3589
|
-
{ endpoint: "/sign-in/username", method: "POST" },
|
|
3590
|
-
input,
|
|
3591
|
-
options
|
|
3592
|
-
),
|
|
3593
|
-
social: (input, options) => executePostWithCompatibleInput(
|
|
3594
|
-
resolvedConfig,
|
|
3595
|
-
{ endpoint: "/sign-in/social", method: "POST" },
|
|
3596
|
-
input,
|
|
3597
|
-
options
|
|
3598
|
-
)
|
|
3599
|
-
},
|
|
3600
|
-
signUp: {
|
|
3601
|
-
email: (input, options) => executePostWithCompatibleInput(
|
|
3602
|
-
resolvedConfig,
|
|
3603
|
-
{ endpoint: "/sign-up/email", method: "POST" },
|
|
3604
|
-
input,
|
|
3605
|
-
options
|
|
3606
|
-
)
|
|
3607
|
-
},
|
|
3608
|
-
signOut,
|
|
3609
|
-
logout: signOut,
|
|
3610
|
-
getSession: (input, options) => executeGetWithCompatibleInput(
|
|
3611
|
-
resolvedConfig,
|
|
3612
|
-
{ endpoint: "/get-session", method: "GET" },
|
|
3613
|
-
input,
|
|
3614
|
-
options
|
|
3615
|
-
),
|
|
3616
|
-
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
3617
|
-
resolvedConfig,
|
|
3618
|
-
{ endpoint: "/list-sessions", method: "GET" },
|
|
3619
|
-
input,
|
|
3620
|
-
options
|
|
3621
|
-
),
|
|
3622
|
-
revokeSession,
|
|
3623
|
-
clearSession: revokeSession,
|
|
3624
|
-
revokeSessions,
|
|
3625
|
-
clearSessions: revokeSessions,
|
|
3626
|
-
revokeOtherSessions,
|
|
3627
|
-
clearOtherSessions: revokeOtherSessions,
|
|
3628
|
-
forgetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3629
|
-
resolvedConfig,
|
|
3630
|
-
{ endpoint: "/forget-password", method: "POST" },
|
|
3631
|
-
input,
|
|
3632
|
-
options
|
|
3633
|
-
),
|
|
3634
|
-
resetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3635
|
-
resolvedConfig,
|
|
3636
|
-
{ endpoint: "/reset-password", method: "POST" },
|
|
3637
|
-
input,
|
|
3638
|
-
options
|
|
3639
|
-
),
|
|
3640
|
-
resolveResetPasswordToken,
|
|
3641
|
-
verifyEmail: (input, options) => {
|
|
3642
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3643
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3644
|
-
const query = payload;
|
|
3645
|
-
return callAuthEndpoint(
|
|
3646
|
-
resolvedConfig,
|
|
3647
|
-
{ endpoint: "/verify-email", method: "GET" },
|
|
3648
|
-
void 0,
|
|
3649
|
-
query ? {
|
|
3650
|
-
token: query.token,
|
|
3651
|
-
callbackURL: query.callbackURL
|
|
3652
|
-
} : void 0,
|
|
3653
|
-
mergedOptions
|
|
3654
|
-
);
|
|
3655
|
-
},
|
|
3656
|
-
sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
|
|
3657
|
-
resolvedConfig,
|
|
3658
|
-
{ endpoint: "/send-verification-email", method: "POST" },
|
|
3659
|
-
input,
|
|
3660
|
-
options
|
|
3661
|
-
),
|
|
3662
|
-
changeEmail: (input, options) => executePostWithCompatibleInput(
|
|
3663
|
-
resolvedConfig,
|
|
3664
|
-
{ endpoint: "/change-email", method: "POST" },
|
|
3665
|
-
input,
|
|
3666
|
-
options
|
|
3667
|
-
),
|
|
3668
|
-
changePassword: (input, options) => executePostWithCompatibleInput(
|
|
3669
|
-
resolvedConfig,
|
|
3670
|
-
{ endpoint: "/change-password", method: "POST" },
|
|
3671
|
-
input,
|
|
3672
|
-
options
|
|
3673
|
-
),
|
|
3674
|
-
updateUser: (input, options) => executePostWithCompatibleInput(
|
|
3675
|
-
resolvedConfig,
|
|
3676
|
-
{ endpoint: "/update-user", method: "POST" },
|
|
3677
|
-
input,
|
|
3678
|
-
options
|
|
3679
|
-
),
|
|
3680
|
-
deleteUser,
|
|
3681
|
-
deleteUserCallback,
|
|
3682
|
-
linkSocial: (input, options) => executePostWithCompatibleInput(
|
|
3683
|
-
resolvedConfig,
|
|
3684
|
-
{ endpoint: "/link-social", method: "POST" },
|
|
3685
|
-
input,
|
|
3686
|
-
options
|
|
3687
|
-
),
|
|
3688
|
-
listAccounts: (input, options) => executeGetWithCompatibleInput(
|
|
3689
|
-
resolvedConfig,
|
|
3690
|
-
{ endpoint: "/list-accounts", method: "GET" },
|
|
3691
|
-
input,
|
|
3692
|
-
options
|
|
3693
|
-
),
|
|
3694
|
-
unlinkAccount: (input, options) => executePostWithCompatibleInput(
|
|
3695
|
-
resolvedConfig,
|
|
3696
|
-
{ endpoint: "/unlink-account", method: "POST" },
|
|
3697
|
-
input,
|
|
3698
|
-
options
|
|
3699
|
-
),
|
|
3700
|
-
refreshToken: (input, options) => executePostWithCompatibleInput(
|
|
3701
|
-
resolvedConfig,
|
|
3702
|
-
{ endpoint: "/refresh-token", method: "POST" },
|
|
3703
|
-
input,
|
|
3704
|
-
options
|
|
3705
|
-
),
|
|
3706
|
-
getAccessToken: (input, options) => executePostWithCompatibleInput(
|
|
3707
|
-
resolvedConfig,
|
|
3708
|
-
{ endpoint: "/get-access-token", method: "POST" },
|
|
3709
|
-
input,
|
|
3710
|
-
options
|
|
3711
|
-
)
|
|
3712
|
-
};
|
|
3713
|
-
}
|
|
3714
|
-
|
|
3715
|
-
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, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, toModelFormDefaults, toModelPayload, 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 };
|
|
3716
4307
|
//# sourceMappingURL=index.js.map
|
|
3717
4308
|
//# sourceMappingURL=index.js.map
|