@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.cjs
CHANGED
|
@@ -503,460 +503,1109 @@ function identifier(...segments) {
|
|
|
503
503
|
return new SqlIdentifierPath(expandedSegments);
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
-
// src/client.ts
|
|
507
|
-
var
|
|
508
|
-
var
|
|
509
|
-
var
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
errorDetails: response.errorDetails ?? null,
|
|
515
|
-
status: response.status,
|
|
516
|
-
raw: response.raw
|
|
517
|
-
};
|
|
518
|
-
if (response.count !== void 0) {
|
|
519
|
-
result.count = response.count;
|
|
520
|
-
}
|
|
521
|
-
return result;
|
|
506
|
+
// src/auth/client.ts
|
|
507
|
+
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
508
|
+
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
509
|
+
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
510
|
+
var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
|
|
511
|
+
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
512
|
+
function normalizeBaseUrl(baseUrl) {
|
|
513
|
+
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
522
514
|
}
|
|
523
|
-
function
|
|
524
|
-
|
|
525
|
-
const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
|
|
526
|
-
return {
|
|
527
|
-
...response,
|
|
528
|
-
data: singleData
|
|
529
|
-
};
|
|
515
|
+
function isRecord2(value) {
|
|
516
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
530
517
|
}
|
|
531
|
-
function
|
|
532
|
-
return
|
|
533
|
-
if (!next) return acc;
|
|
534
|
-
return { ...acc, ...next };
|
|
535
|
-
}, void 0);
|
|
518
|
+
function normalizeHeaderValue2(value) {
|
|
519
|
+
return value ? value : void 0;
|
|
536
520
|
}
|
|
537
|
-
function
|
|
538
|
-
|
|
521
|
+
function parseResponseBody2(rawText, contentType) {
|
|
522
|
+
if (!rawText) {
|
|
523
|
+
return { parsed: null, parseFailed: false };
|
|
524
|
+
}
|
|
525
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
526
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
527
|
+
if (!looksJson) {
|
|
528
|
+
return { parsed: rawText, parseFailed: false };
|
|
529
|
+
}
|
|
530
|
+
try {
|
|
531
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
532
|
+
} catch {
|
|
533
|
+
return { parsed: rawText, parseFailed: true };
|
|
534
|
+
}
|
|
539
535
|
}
|
|
540
|
-
function
|
|
541
|
-
return
|
|
536
|
+
function resolveRequestId2(headers) {
|
|
537
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
542
538
|
}
|
|
543
|
-
function
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
if (!promise) {
|
|
551
|
-
promise = executor(payloadColumns, payloadOptions);
|
|
539
|
+
function resolveErrorMessage2(payload, fallback) {
|
|
540
|
+
if (isRecord2(payload)) {
|
|
541
|
+
const messageCandidates = [payload.error, payload.message, payload.details];
|
|
542
|
+
for (const candidate of messageCandidates) {
|
|
543
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
544
|
+
return candidate.trim();
|
|
545
|
+
}
|
|
552
546
|
}
|
|
553
|
-
|
|
547
|
+
}
|
|
548
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
549
|
+
return payload.trim();
|
|
550
|
+
}
|
|
551
|
+
return fallback;
|
|
552
|
+
}
|
|
553
|
+
function toErrorDetails(input) {
|
|
554
|
+
return {
|
|
555
|
+
code: input.code,
|
|
556
|
+
message: input.message,
|
|
557
|
+
status: input.status,
|
|
558
|
+
endpoint: input.endpoint,
|
|
559
|
+
method: input.method,
|
|
560
|
+
requestId: input.requestId,
|
|
561
|
+
hint: input.hint,
|
|
562
|
+
cause: input.cause
|
|
554
563
|
};
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
single(columns = selectedColumns, options) {
|
|
565
|
-
selectedColumns = columns;
|
|
566
|
-
selectedOptions = options ?? selectedOptions;
|
|
567
|
-
return run(columns, options).then(toSingleResult);
|
|
568
|
-
},
|
|
569
|
-
maybeSingle(columns = selectedColumns, options) {
|
|
570
|
-
return mutationQuery.single(columns, options);
|
|
571
|
-
},
|
|
572
|
-
then(onfulfilled, onrejected) {
|
|
573
|
-
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
574
|
-
},
|
|
575
|
-
catch(onrejected) {
|
|
576
|
-
return run(selectedColumns, selectedOptions).catch(onrejected);
|
|
577
|
-
},
|
|
578
|
-
finally(onfinally) {
|
|
579
|
-
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
564
|
+
}
|
|
565
|
+
function mergeCallOptions(base, override) {
|
|
566
|
+
if (!base && !override) return void 0;
|
|
567
|
+
return {
|
|
568
|
+
...base,
|
|
569
|
+
...override,
|
|
570
|
+
headers: {
|
|
571
|
+
...base?.headers ?? {},
|
|
572
|
+
...override?.headers ?? {}
|
|
580
573
|
}
|
|
581
574
|
};
|
|
582
|
-
return mutationQuery;
|
|
583
|
-
}
|
|
584
|
-
function getResourceId(state) {
|
|
585
|
-
const candidate = state.conditions.find(
|
|
586
|
-
(condition) => condition.operator === "eq" && (condition.column === "resource_id" || condition.column === "id")
|
|
587
|
-
);
|
|
588
|
-
return candidate?.value?.toString();
|
|
589
575
|
}
|
|
590
|
-
function
|
|
591
|
-
if (
|
|
592
|
-
return
|
|
576
|
+
function extractFetchOptions(input) {
|
|
577
|
+
if (!input) {
|
|
578
|
+
return {
|
|
579
|
+
payload: void 0,
|
|
580
|
+
fetchOptions: void 0
|
|
581
|
+
};
|
|
593
582
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return column === "id" || /(?:^|_)uuid(?:_|$)/i.test(column) || /_id$/i.test(column);
|
|
601
|
-
}
|
|
602
|
-
function shouldUseUuidTextComparison(column, value) {
|
|
603
|
-
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
583
|
+
const { fetchOptions, ...rest } = input;
|
|
584
|
+
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
585
|
+
return {
|
|
586
|
+
payload: hasPayloadKeys ? rest : void 0,
|
|
587
|
+
fetchOptions
|
|
588
|
+
};
|
|
604
589
|
}
|
|
605
|
-
function
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
590
|
+
function buildHeaders2(config, options) {
|
|
591
|
+
const headers = {
|
|
592
|
+
"Content-Type": "application/json",
|
|
593
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
594
|
+
};
|
|
595
|
+
const apiKey = options?.apiKey ?? config.apiKey;
|
|
596
|
+
if (apiKey) {
|
|
597
|
+
headers.apikey = apiKey;
|
|
598
|
+
headers["x-api-key"] = apiKey;
|
|
609
599
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
600
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
601
|
+
if (bearerToken) {
|
|
602
|
+
headers.Authorization = `Bearer ${bearerToken}`;
|
|
603
|
+
}
|
|
604
|
+
const mergedExtraHeaders = {
|
|
605
|
+
...config.headers ?? {},
|
|
606
|
+
...options?.headers ?? {}
|
|
607
|
+
};
|
|
608
|
+
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
609
|
+
const normalized = normalizeHeaderValue2(value);
|
|
610
|
+
if (normalized) {
|
|
611
|
+
headers[key] = normalized;
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
return headers;
|
|
624
615
|
}
|
|
625
|
-
function
|
|
626
|
-
if (
|
|
627
|
-
|
|
616
|
+
function appendQueryParam(searchParams, key, value) {
|
|
617
|
+
if (value === void 0 || value === null) return;
|
|
618
|
+
if (Array.isArray(value)) {
|
|
619
|
+
value.forEach((item) => {
|
|
620
|
+
searchParams.append(key, String(item));
|
|
621
|
+
});
|
|
622
|
+
return;
|
|
628
623
|
}
|
|
629
|
-
|
|
624
|
+
searchParams.append(key, String(value));
|
|
630
625
|
}
|
|
631
|
-
function
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
626
|
+
function buildRequestUrl(baseUrl, endpoint, query) {
|
|
627
|
+
const url = `${baseUrl}${endpoint}`;
|
|
628
|
+
if (!query || Object.keys(query).length === 0) return url;
|
|
629
|
+
const searchParams = new URLSearchParams();
|
|
630
|
+
Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
|
|
631
|
+
const queryText = searchParams.toString();
|
|
632
|
+
return queryText ? `${url}?${queryText}` : url;
|
|
633
|
+
}
|
|
634
|
+
function inferDefaultMethod(endpoint) {
|
|
635
|
+
if (endpoint.startsWith("/reset-password/")) {
|
|
636
|
+
return "GET";
|
|
636
637
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
638
|
+
switch (endpoint) {
|
|
639
|
+
case "/get-session":
|
|
640
|
+
case "/list-sessions":
|
|
641
|
+
case "/verify-email":
|
|
642
|
+
case "/change-email/verify":
|
|
643
|
+
case "/delete-user/verify":
|
|
644
|
+
case "/email-list":
|
|
645
|
+
case "/email/list":
|
|
646
|
+
case "/delete-user/callback":
|
|
647
|
+
case "/list-accounts":
|
|
648
|
+
case "/passkey/generate-register-options":
|
|
649
|
+
case "/passkey/list-user-passkeys":
|
|
650
|
+
case "/.well-known/webauthn":
|
|
651
|
+
case "/admin/list-users":
|
|
652
|
+
case "/admin/athena-client/list":
|
|
653
|
+
case "/admin/audit-log/list":
|
|
654
|
+
case "/admin/email/get":
|
|
655
|
+
case "/admin/email-failure/list":
|
|
656
|
+
case "/admin/email-failure/get":
|
|
657
|
+
case "/admin/email-template/get":
|
|
658
|
+
case "/admin/email-template/list":
|
|
659
|
+
case "/admin/email/list":
|
|
660
|
+
case "/api-key/get":
|
|
661
|
+
case "/api-key/list":
|
|
662
|
+
case "/organization/get-full-organization":
|
|
663
|
+
case "/organization/list":
|
|
664
|
+
case "/organization/get-invitation":
|
|
665
|
+
case "/organization/list-invitations":
|
|
666
|
+
case "/organization/list-user-invitations":
|
|
667
|
+
case "/organization/list-members":
|
|
668
|
+
case "/organization/get-active-member":
|
|
669
|
+
case "/health":
|
|
670
|
+
case "/ok":
|
|
671
|
+
case "/error":
|
|
672
|
+
return "GET";
|
|
673
|
+
default:
|
|
674
|
+
return "POST";
|
|
644
675
|
}
|
|
645
|
-
return `${normalizedSchema}.${tableName}`;
|
|
646
676
|
}
|
|
647
|
-
function
|
|
648
|
-
|
|
649
|
-
const
|
|
650
|
-
const
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
lte: "<=",
|
|
658
|
-
like: "LIKE",
|
|
659
|
-
ilike: "ILIKE"
|
|
677
|
+
async function callAuthEndpoint(config, context, body, query, options) {
|
|
678
|
+
const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
679
|
+
const url = buildRequestUrl(baseUrl, context.endpoint, query);
|
|
680
|
+
const headers = buildHeaders2(config, options);
|
|
681
|
+
const credentials = options?.credentials ?? config.credentials ?? "include";
|
|
682
|
+
const requestInit = {
|
|
683
|
+
method: context.method,
|
|
684
|
+
headers,
|
|
685
|
+
credentials,
|
|
686
|
+
signal: options?.signal
|
|
660
687
|
};
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
688
|
+
if (context.method !== "GET") {
|
|
689
|
+
requestInit.body = JSON.stringify(body ?? {});
|
|
690
|
+
}
|
|
691
|
+
const fetcher = config.fetch ?? globalThis.fetch;
|
|
692
|
+
if (!fetcher) {
|
|
693
|
+
const details = toErrorDetails({
|
|
694
|
+
code: "UNKNOWN_ERROR",
|
|
695
|
+
message: "No fetch implementation available for auth client",
|
|
696
|
+
status: 0,
|
|
697
|
+
endpoint: context.endpoint,
|
|
698
|
+
method: context.method,
|
|
699
|
+
hint: "Use Node 18+ or provide `fetch` via createClient(..., { auth: { fetch } }) or createAuthClient({ fetch })"
|
|
700
|
+
});
|
|
701
|
+
return {
|
|
702
|
+
ok: false,
|
|
703
|
+
status: 0,
|
|
704
|
+
data: null,
|
|
705
|
+
error: details.message,
|
|
706
|
+
errorDetails: details,
|
|
707
|
+
raw: null
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
try {
|
|
711
|
+
const response = await fetcher(url, requestInit);
|
|
712
|
+
const rawText = await response.text();
|
|
713
|
+
const requestId = resolveRequestId2(response.headers);
|
|
714
|
+
const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
|
|
715
|
+
if (parsedBody.parseFailed) {
|
|
716
|
+
const details = toErrorDetails({
|
|
717
|
+
code: "INVALID_JSON",
|
|
718
|
+
message: "Auth server returned malformed JSON",
|
|
719
|
+
status: response.status,
|
|
720
|
+
endpoint: context.endpoint,
|
|
721
|
+
method: context.method,
|
|
722
|
+
requestId,
|
|
723
|
+
hint: "Verify the auth endpoint response body is valid JSON.",
|
|
724
|
+
cause: rawText.slice(0, 300)
|
|
725
|
+
});
|
|
726
|
+
return {
|
|
727
|
+
ok: false,
|
|
728
|
+
status: response.status,
|
|
729
|
+
data: null,
|
|
730
|
+
error: details.message,
|
|
731
|
+
errorDetails: details,
|
|
732
|
+
raw: parsedBody.parsed
|
|
733
|
+
};
|
|
679
734
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
735
|
+
const parsed = parsedBody.parsed;
|
|
736
|
+
if (!response.ok) {
|
|
737
|
+
const details = toErrorDetails({
|
|
738
|
+
code: "HTTP_ERROR",
|
|
739
|
+
message: resolveErrorMessage2(
|
|
740
|
+
parsed,
|
|
741
|
+
`Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
|
|
742
|
+
),
|
|
743
|
+
status: response.status,
|
|
744
|
+
endpoint: context.endpoint,
|
|
745
|
+
method: context.method,
|
|
746
|
+
requestId
|
|
747
|
+
});
|
|
748
|
+
return {
|
|
749
|
+
ok: false,
|
|
750
|
+
status: response.status,
|
|
751
|
+
data: null,
|
|
752
|
+
error: details.message,
|
|
753
|
+
errorDetails: details,
|
|
754
|
+
raw: parsed
|
|
755
|
+
};
|
|
685
756
|
}
|
|
686
|
-
|
|
687
|
-
|
|
757
|
+
return {
|
|
758
|
+
ok: true,
|
|
759
|
+
status: response.status,
|
|
760
|
+
data: parsed ?? null,
|
|
761
|
+
error: null,
|
|
762
|
+
errorDetails: null,
|
|
763
|
+
raw: parsed
|
|
764
|
+
};
|
|
765
|
+
} catch (callError) {
|
|
766
|
+
const message = callError instanceof Error ? callError.message : String(callError);
|
|
767
|
+
const details = toErrorDetails({
|
|
768
|
+
code: "NETWORK_ERROR",
|
|
769
|
+
message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
|
|
770
|
+
status: 0,
|
|
771
|
+
endpoint: context.endpoint,
|
|
772
|
+
method: context.method,
|
|
773
|
+
cause: message,
|
|
774
|
+
hint: "Check auth server URL, DNS, and network reachability."
|
|
775
|
+
});
|
|
776
|
+
return {
|
|
777
|
+
ok: false,
|
|
778
|
+
status: 0,
|
|
779
|
+
data: null,
|
|
780
|
+
error: details.message,
|
|
781
|
+
errorDetails: details,
|
|
782
|
+
raw: null
|
|
783
|
+
};
|
|
688
784
|
}
|
|
689
785
|
}
|
|
690
|
-
function
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if (!clause) return null;
|
|
695
|
-
whereClauses.push(clause);
|
|
696
|
-
}
|
|
697
|
-
let limit = input.limit;
|
|
698
|
-
let offset = input.offset;
|
|
699
|
-
if (limit === void 0 && input.pageSize !== void 0) {
|
|
700
|
-
limit = input.pageSize;
|
|
701
|
-
}
|
|
702
|
-
if (offset === void 0 && input.pageSize !== void 0 && input.currentPage !== void 0 && input.currentPage > 0) {
|
|
703
|
-
offset = (input.currentPage - 1) * input.pageSize;
|
|
704
|
-
}
|
|
705
|
-
const sqlParts = [
|
|
706
|
-
`SELECT ${buildSelectColumnsClause(input.columns)} FROM ${quoteQualifiedIdentifier(input.tableName)}`
|
|
707
|
-
];
|
|
708
|
-
if (whereClauses.length > 0) {
|
|
709
|
-
sqlParts.push(`WHERE ${whereClauses.join(" AND ")}`);
|
|
710
|
-
}
|
|
711
|
-
if (input.order?.field) {
|
|
712
|
-
const direction = input.order.direction === "descending" ? "DESC" : "ASC";
|
|
713
|
-
sqlParts.push(`ORDER BY ${quoteQualifiedIdentifier(input.order.field)} ${direction}`);
|
|
714
|
-
}
|
|
715
|
-
if (limit !== void 0) {
|
|
716
|
-
sqlParts.push(`LIMIT ${Math.max(0, Math.trunc(limit))}`);
|
|
717
|
-
}
|
|
718
|
-
if (offset !== void 0) {
|
|
719
|
-
sqlParts.push(`OFFSET ${Math.max(0, Math.trunc(offset))}`);
|
|
720
|
-
}
|
|
721
|
-
return `${sqlParts.join(" ")};`;
|
|
786
|
+
function executePostWithCompatibleInput(config, context, input, options) {
|
|
787
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
788
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
789
|
+
return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
|
|
722
790
|
}
|
|
723
|
-
function
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
791
|
+
function executePostWithOptionalInput(config, context, input, options) {
|
|
792
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
793
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
794
|
+
return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
|
|
795
|
+
}
|
|
796
|
+
function executeGetWithCompatibleInput(config, context, input, options) {
|
|
797
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
798
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
799
|
+
return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
|
|
800
|
+
}
|
|
801
|
+
function executeGetWithQueryCompatibleInput(config, context, input, options) {
|
|
802
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
803
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
804
|
+
const query = payload?.query;
|
|
805
|
+
return callAuthEndpoint(
|
|
806
|
+
config,
|
|
807
|
+
context,
|
|
808
|
+
void 0,
|
|
809
|
+
query,
|
|
810
|
+
mergedOptions
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
function createAuthClient(config = {}) {
|
|
814
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
815
|
+
const resolvedConfig = {
|
|
816
|
+
...config,
|
|
817
|
+
baseUrl: normalizedBaseUrl
|
|
818
|
+
};
|
|
819
|
+
const request = (input, options) => {
|
|
820
|
+
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
821
|
+
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
822
|
+
return callAuthEndpoint(
|
|
823
|
+
resolvedConfig,
|
|
824
|
+
{ endpoint: input.endpoint, method },
|
|
825
|
+
input.body,
|
|
826
|
+
input.query,
|
|
827
|
+
mergedOptions
|
|
828
|
+
);
|
|
829
|
+
};
|
|
830
|
+
const postGeneric = (endpoint, input, options) => {
|
|
831
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
832
|
+
return request(
|
|
833
|
+
{
|
|
834
|
+
endpoint,
|
|
835
|
+
method: "POST",
|
|
836
|
+
body: payload ?? {},
|
|
837
|
+
fetchOptions
|
|
838
|
+
},
|
|
839
|
+
options
|
|
840
|
+
);
|
|
841
|
+
};
|
|
842
|
+
const getGeneric = (endpoint, input, options) => {
|
|
843
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
844
|
+
return request(
|
|
845
|
+
{
|
|
846
|
+
endpoint,
|
|
847
|
+
method: "GET",
|
|
848
|
+
fetchOptions
|
|
849
|
+
},
|
|
850
|
+
options
|
|
851
|
+
);
|
|
852
|
+
};
|
|
853
|
+
const getWithQuery = (endpoint, input, options) => {
|
|
854
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
855
|
+
const query = payload?.query;
|
|
856
|
+
return request(
|
|
857
|
+
{
|
|
858
|
+
endpoint,
|
|
859
|
+
method: "GET",
|
|
860
|
+
query,
|
|
861
|
+
fetchOptions
|
|
862
|
+
},
|
|
863
|
+
options
|
|
864
|
+
);
|
|
865
|
+
};
|
|
866
|
+
const listUserEmailsWithFallback = async (input, options) => {
|
|
867
|
+
const primary = await getWithQuery(
|
|
868
|
+
"/email/list",
|
|
869
|
+
input,
|
|
870
|
+
options
|
|
871
|
+
);
|
|
872
|
+
if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
|
|
873
|
+
return primary;
|
|
874
|
+
}
|
|
875
|
+
return getWithQuery(
|
|
876
|
+
"/email-list",
|
|
877
|
+
input,
|
|
878
|
+
options
|
|
879
|
+
);
|
|
880
|
+
};
|
|
881
|
+
const healthWithFallback = async (input, options) => {
|
|
882
|
+
const primary = await getGeneric("/health", input, options);
|
|
883
|
+
if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
|
|
884
|
+
return primary;
|
|
885
|
+
}
|
|
886
|
+
const fallback = await getGeneric("/ok", input, options);
|
|
887
|
+
if (!fallback.ok) {
|
|
888
|
+
return {
|
|
889
|
+
...fallback,
|
|
890
|
+
data: null
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
const fallbackStatus = isRecord2(fallback.data) && typeof fallback.data.ok === "boolean" ? fallback.data.ok ? "ok" : "error" : "ok";
|
|
894
|
+
return {
|
|
895
|
+
...fallback,
|
|
896
|
+
data: {
|
|
897
|
+
status: fallbackStatus
|
|
731
898
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
899
|
+
};
|
|
900
|
+
};
|
|
901
|
+
const signOut = (input, options) => executePostWithOptionalInput(
|
|
902
|
+
resolvedConfig,
|
|
903
|
+
{ endpoint: "/sign-out", method: "POST" },
|
|
904
|
+
input,
|
|
905
|
+
options
|
|
906
|
+
);
|
|
907
|
+
const revokeSessions = (input, options) => executePostWithOptionalInput(
|
|
908
|
+
resolvedConfig,
|
|
909
|
+
{ endpoint: "/revoke-sessions", method: "POST" },
|
|
910
|
+
input,
|
|
911
|
+
options
|
|
912
|
+
);
|
|
913
|
+
const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
|
|
914
|
+
resolvedConfig,
|
|
915
|
+
{ endpoint: "/revoke-other-sessions", method: "POST" },
|
|
916
|
+
input,
|
|
917
|
+
options
|
|
918
|
+
);
|
|
919
|
+
const revokeSession = (input, options) => executePostWithCompatibleInput(
|
|
920
|
+
resolvedConfig,
|
|
921
|
+
{ endpoint: "/revoke-session", method: "POST" },
|
|
922
|
+
input,
|
|
923
|
+
options
|
|
924
|
+
);
|
|
925
|
+
const deleteUser = (input, options) => {
|
|
926
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
927
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
928
|
+
return callAuthEndpoint(
|
|
929
|
+
resolvedConfig,
|
|
930
|
+
{ endpoint: "/delete-user", method: "POST" },
|
|
931
|
+
payload ?? {},
|
|
932
|
+
void 0,
|
|
933
|
+
mergedOptions
|
|
934
|
+
);
|
|
935
|
+
};
|
|
936
|
+
const deleteUserCallback = (input, options) => {
|
|
937
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
938
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
939
|
+
const query = payload ?? {};
|
|
940
|
+
return callAuthEndpoint(
|
|
941
|
+
resolvedConfig,
|
|
942
|
+
{ endpoint: "/delete-user/callback", method: "GET" },
|
|
943
|
+
void 0,
|
|
944
|
+
{
|
|
945
|
+
token: query.token,
|
|
946
|
+
callbackURL: query.callbackURL
|
|
947
|
+
},
|
|
948
|
+
mergedOptions
|
|
949
|
+
);
|
|
950
|
+
};
|
|
951
|
+
const resolveResetPasswordToken = (input, options) => {
|
|
952
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
953
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
954
|
+
const query = payload;
|
|
955
|
+
const token = query?.token?.trim();
|
|
956
|
+
if (!token) {
|
|
957
|
+
throw new Error("resolveResetPasswordToken requires a non-empty token");
|
|
958
|
+
}
|
|
959
|
+
const endpoint = `/reset-password/${encodeURIComponent(token)}`;
|
|
960
|
+
return callAuthEndpoint(
|
|
961
|
+
resolvedConfig,
|
|
962
|
+
{ endpoint, method: "GET" },
|
|
963
|
+
void 0,
|
|
964
|
+
query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
|
|
965
|
+
mergedOptions
|
|
966
|
+
);
|
|
967
|
+
};
|
|
968
|
+
const organization = {
|
|
969
|
+
create: (input, options) => executePostWithCompatibleInput(
|
|
970
|
+
resolvedConfig,
|
|
971
|
+
{ endpoint: "/organization/create", method: "POST" },
|
|
972
|
+
input,
|
|
973
|
+
options
|
|
974
|
+
),
|
|
975
|
+
update: (input, options) => executePostWithCompatibleInput(
|
|
976
|
+
resolvedConfig,
|
|
977
|
+
{ endpoint: "/organization/update", method: "POST" },
|
|
978
|
+
input,
|
|
979
|
+
options
|
|
980
|
+
),
|
|
981
|
+
delete: (input, options) => executePostWithCompatibleInput(
|
|
982
|
+
resolvedConfig,
|
|
983
|
+
{ endpoint: "/organization/delete", method: "POST" },
|
|
984
|
+
input,
|
|
985
|
+
options
|
|
986
|
+
),
|
|
987
|
+
setActive: (input, options) => executePostWithCompatibleInput(
|
|
988
|
+
resolvedConfig,
|
|
989
|
+
{ endpoint: "/organization/set-active", method: "POST" },
|
|
990
|
+
input,
|
|
991
|
+
options
|
|
992
|
+
),
|
|
993
|
+
list: (input, options) => getGeneric(
|
|
994
|
+
"/organization/list",
|
|
995
|
+
input,
|
|
996
|
+
options
|
|
997
|
+
),
|
|
998
|
+
getFull: (input, options) => executeGetWithQueryCompatibleInput(
|
|
999
|
+
resolvedConfig,
|
|
1000
|
+
{ endpoint: "/organization/get-full-organization", method: "GET" },
|
|
1001
|
+
input,
|
|
1002
|
+
options
|
|
1003
|
+
),
|
|
1004
|
+
checkSlug: (input, options) => executePostWithCompatibleInput(
|
|
1005
|
+
resolvedConfig,
|
|
1006
|
+
{ endpoint: "/organization/check-slug", method: "POST" },
|
|
1007
|
+
input,
|
|
1008
|
+
options
|
|
1009
|
+
),
|
|
1010
|
+
leave: (input, options) => executePostWithCompatibleInput(
|
|
1011
|
+
resolvedConfig,
|
|
1012
|
+
{ endpoint: "/organization/leave", method: "POST" },
|
|
1013
|
+
input,
|
|
1014
|
+
options
|
|
1015
|
+
),
|
|
1016
|
+
listUserInvitations: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1017
|
+
resolvedConfig,
|
|
1018
|
+
{ endpoint: "/organization/list-user-invitations", method: "GET" },
|
|
1019
|
+
input,
|
|
1020
|
+
options
|
|
1021
|
+
),
|
|
1022
|
+
hasPermission: (input, options) => postGeneric(
|
|
1023
|
+
"/organization/has-permission",
|
|
1024
|
+
input,
|
|
1025
|
+
options
|
|
1026
|
+
),
|
|
1027
|
+
invitation: {
|
|
1028
|
+
cancel: (input, options) => executePostWithCompatibleInput(
|
|
1029
|
+
resolvedConfig,
|
|
1030
|
+
{ endpoint: "/organization/cancel-invitation", method: "POST" },
|
|
1031
|
+
input,
|
|
1032
|
+
options
|
|
1033
|
+
),
|
|
1034
|
+
accept: (input, options) => executePostWithCompatibleInput(
|
|
1035
|
+
resolvedConfig,
|
|
1036
|
+
{ endpoint: "/organization/accept-invitation", method: "POST" },
|
|
1037
|
+
input,
|
|
1038
|
+
options
|
|
1039
|
+
),
|
|
1040
|
+
get: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1041
|
+
resolvedConfig,
|
|
1042
|
+
{ endpoint: "/organization/get-invitation", method: "GET" },
|
|
1043
|
+
input,
|
|
1044
|
+
options
|
|
1045
|
+
),
|
|
1046
|
+
reject: (input, options) => executePostWithCompatibleInput(
|
|
1047
|
+
resolvedConfig,
|
|
1048
|
+
{ endpoint: "/organization/reject-invitation", method: "POST" },
|
|
1049
|
+
input,
|
|
1050
|
+
options
|
|
1051
|
+
),
|
|
1052
|
+
list: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1053
|
+
resolvedConfig,
|
|
1054
|
+
{ endpoint: "/organization/list-invitations", method: "GET" },
|
|
1055
|
+
input,
|
|
1056
|
+
options
|
|
1057
|
+
)
|
|
754
1058
|
},
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
1059
|
+
member: {
|
|
1060
|
+
remove: (input, options) => executePostWithCompatibleInput(
|
|
1061
|
+
resolvedConfig,
|
|
1062
|
+
{ endpoint: "/organization/remove-member", method: "POST" },
|
|
1063
|
+
input,
|
|
1064
|
+
options
|
|
1065
|
+
),
|
|
1066
|
+
updateRole: (input, options) => executePostWithCompatibleInput(
|
|
1067
|
+
resolvedConfig,
|
|
1068
|
+
{ endpoint: "/organization/update-member-role", method: "POST" },
|
|
1069
|
+
input,
|
|
1070
|
+
options
|
|
1071
|
+
),
|
|
1072
|
+
invite: (input, options) => executePostWithCompatibleInput(
|
|
1073
|
+
resolvedConfig,
|
|
1074
|
+
{ endpoint: "/organization/invite-member", method: "POST" },
|
|
1075
|
+
input,
|
|
1076
|
+
options
|
|
1077
|
+
),
|
|
1078
|
+
getActive: (input, options) => executeGetWithCompatibleInput(
|
|
1079
|
+
resolvedConfig,
|
|
1080
|
+
{ endpoint: "/organization/get-active-member", method: "GET" },
|
|
1081
|
+
input,
|
|
1082
|
+
options
|
|
1083
|
+
),
|
|
1084
|
+
list: (input, options) => executeGetWithQueryCompatibleInput(
|
|
1085
|
+
resolvedConfig,
|
|
1086
|
+
{ endpoint: "/organization/list-members", method: "GET" },
|
|
1087
|
+
input,
|
|
1088
|
+
options
|
|
1089
|
+
)
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
const authResetPassword = Object.assign(
|
|
1093
|
+
(input, options) => executePostWithCompatibleInput(
|
|
1094
|
+
resolvedConfig,
|
|
1095
|
+
{ endpoint: "/reset-password", method: "POST" },
|
|
1096
|
+
input,
|
|
1097
|
+
options
|
|
1098
|
+
),
|
|
1099
|
+
{
|
|
1100
|
+
token: resolveResetPasswordToken
|
|
1101
|
+
}
|
|
1102
|
+
);
|
|
1103
|
+
const sessionRevokeBinding = (input, options) => {
|
|
1104
|
+
if (Array.isArray(input)) {
|
|
1105
|
+
if (input.length === 0) {
|
|
1106
|
+
throw new Error("session.revoke requires at least one session token");
|
|
1107
|
+
}
|
|
1108
|
+
if (input.length === 1) {
|
|
1109
|
+
return revokeSession(input[0], options);
|
|
1110
|
+
}
|
|
1111
|
+
return revokeSessions(void 0, options);
|
|
1112
|
+
}
|
|
1113
|
+
const parsed = input;
|
|
1114
|
+
const tokens = Array.isArray(parsed.tokens) ? parsed.tokens.filter((token2) => token2.trim().length > 0) : void 0;
|
|
1115
|
+
if (tokens && tokens.length > 1) {
|
|
1116
|
+
return revokeSessions(
|
|
1117
|
+
parsed.fetchOptions ? { fetchOptions: parsed.fetchOptions } : void 0,
|
|
1118
|
+
options
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
if (tokens && tokens.length === 1) {
|
|
1122
|
+
return revokeSession(
|
|
1123
|
+
{ token: tokens[0], fetchOptions: parsed.fetchOptions },
|
|
1124
|
+
options
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
const token = parsed.token?.trim();
|
|
1128
|
+
if (!token) {
|
|
1129
|
+
throw new Error("session.revoke requires a non-empty token or a non-empty token list");
|
|
1130
|
+
}
|
|
1131
|
+
return revokeSession(
|
|
1132
|
+
{
|
|
1133
|
+
token,
|
|
1134
|
+
fetchOptions: parsed.fetchOptions
|
|
1135
|
+
},
|
|
1136
|
+
options
|
|
1137
|
+
);
|
|
1138
|
+
};
|
|
1139
|
+
const adminUserSessionRevokeBinding = (input, options) => {
|
|
1140
|
+
const requireUserId = (userId) => {
|
|
1141
|
+
const trimmed = String(userId ?? "").trim();
|
|
1142
|
+
if (!trimmed) {
|
|
1143
|
+
throw new Error("admin.user.session.revoke requires a non-empty userId");
|
|
1144
|
+
}
|
|
1145
|
+
return trimmed;
|
|
1146
|
+
};
|
|
1147
|
+
const requireSinglePluralUserId = (sessions2) => {
|
|
1148
|
+
const uniqueUserIds = [...new Set(sessions2.map((session) => requireUserId(session.userId)))];
|
|
1149
|
+
if (uniqueUserIds.length !== 1) {
|
|
1150
|
+
throw new Error("admin.user.session.revoke requires the same userId across plural payloads");
|
|
1151
|
+
}
|
|
1152
|
+
return { userId: uniqueUserIds[0] };
|
|
1153
|
+
};
|
|
1154
|
+
if (Array.isArray(input)) {
|
|
1155
|
+
if (input.length === 0) {
|
|
1156
|
+
throw new Error("admin.user.session.revoke requires at least one payload item");
|
|
1157
|
+
}
|
|
1158
|
+
if (input.length === 1) {
|
|
1159
|
+
return postGeneric(
|
|
1160
|
+
"/admin/revoke-user-session",
|
|
1161
|
+
{
|
|
1162
|
+
...input[0],
|
|
1163
|
+
userId: requireUserId(input[0].userId)
|
|
1164
|
+
},
|
|
1165
|
+
options
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
return postGeneric(
|
|
1169
|
+
"/admin/revoke-user-sessions",
|
|
1170
|
+
requireSinglePluralUserId(input),
|
|
1171
|
+
options
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
const parsed = input;
|
|
1175
|
+
const sessions = parsed.sessions;
|
|
1176
|
+
if (sessions && sessions.length === 0) {
|
|
1177
|
+
throw new Error("admin.user.session.revoke requires at least one payload item");
|
|
1178
|
+
}
|
|
1179
|
+
if (sessions && sessions.length === 1) {
|
|
1180
|
+
return postGeneric(
|
|
1181
|
+
"/admin/revoke-user-session",
|
|
1182
|
+
{
|
|
1183
|
+
...sessions[0],
|
|
1184
|
+
userId: requireUserId(sessions[0].userId),
|
|
1185
|
+
fetchOptions: parsed.fetchOptions
|
|
1186
|
+
},
|
|
1187
|
+
options
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
if (sessions && sessions.length > 1) {
|
|
1191
|
+
return postGeneric(
|
|
1192
|
+
"/admin/revoke-user-sessions",
|
|
1193
|
+
{
|
|
1194
|
+
...requireSinglePluralUserId(sessions),
|
|
1195
|
+
fetchOptions: parsed.fetchOptions
|
|
1196
|
+
},
|
|
1197
|
+
options
|
|
1198
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
const normalizedUserId = requireUserId(parsed.userId);
|
|
1201
|
+
if (!parsed.sessionToken) {
|
|
1202
|
+
return postGeneric(
|
|
1203
|
+
"/admin/revoke-user-sessions",
|
|
1204
|
+
{
|
|
1205
|
+
userId: normalizedUserId,
|
|
1206
|
+
fetchOptions: parsed.fetchOptions
|
|
1207
|
+
},
|
|
1208
|
+
options
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
return postGeneric(
|
|
1212
|
+
"/admin/revoke-user-session",
|
|
1213
|
+
{
|
|
1214
|
+
...parsed,
|
|
1215
|
+
userId: normalizedUserId
|
|
1216
|
+
},
|
|
1217
|
+
options
|
|
1218
|
+
);
|
|
1219
|
+
};
|
|
1220
|
+
const auth = {
|
|
1221
|
+
getSession: (input, options) => getGeneric("/get-session", input, options),
|
|
1222
|
+
signOut,
|
|
1223
|
+
forgetPassword: (input, options) => postGeneric("/forget-password", input, options),
|
|
1224
|
+
resetPassword: authResetPassword,
|
|
1225
|
+
setPassword: (input, options) => postGeneric("/set-password", input, options),
|
|
1226
|
+
verifyEmail: (input, options) => {
|
|
1227
|
+
const queryInput = {
|
|
1228
|
+
query: {
|
|
1229
|
+
token: input.token,
|
|
1230
|
+
callbackURL: input.callbackURL
|
|
1231
|
+
},
|
|
1232
|
+
fetchOptions: input.fetchOptions
|
|
1233
|
+
};
|
|
1234
|
+
return getWithQuery(
|
|
1235
|
+
"/verify-email",
|
|
1236
|
+
queryInput,
|
|
1237
|
+
options
|
|
1238
|
+
);
|
|
759
1239
|
},
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
1240
|
+
sendVerificationEmail: (input, options) => postGeneric("/send-verification-email", input, options),
|
|
1241
|
+
changeEmail: (input, options) => postGeneric("/change-email", input, options),
|
|
1242
|
+
changeEmailVerify: (input, options) => getWithQuery("/change-email/verify", input, options),
|
|
1243
|
+
deleteUserVerify: (input, options) => getWithQuery("/delete-user/verify", input, options),
|
|
1244
|
+
changePassword: (input, options) => postGeneric("/change-password", input, options),
|
|
1245
|
+
user: {
|
|
1246
|
+
update: (input, options) => postGeneric("/update-user", input, options),
|
|
1247
|
+
delete: (input, options) => postGeneric("/delete-user", input, options),
|
|
1248
|
+
email: {
|
|
1249
|
+
list: listUserEmailsWithFallback
|
|
1250
|
+
}
|
|
763
1251
|
},
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
1252
|
+
session: {
|
|
1253
|
+
list: (input, options) => getGeneric("/list-sessions", input, options),
|
|
1254
|
+
revoke: sessionRevokeBinding,
|
|
1255
|
+
revokeOther: revokeOtherSessions
|
|
767
1256
|
},
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
return self;
|
|
1257
|
+
social: {
|
|
1258
|
+
link: (input, options) => postGeneric("/link-social", input, options)
|
|
771
1259
|
},
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
1260
|
+
account: {
|
|
1261
|
+
list: (input, options) => getGeneric("/list-accounts", input, options),
|
|
1262
|
+
unlink: (input, options) => postGeneric("/unlink-account", input, options)
|
|
775
1263
|
},
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
return self;
|
|
1264
|
+
deleteUser: {
|
|
1265
|
+
callback: deleteUserCallback
|
|
779
1266
|
},
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
1267
|
+
refreshToken: (input, options) => postGeneric("/refresh-token", input, options),
|
|
1268
|
+
getAccessToken: (input, options) => postGeneric("/get-access-token", input, options),
|
|
1269
|
+
health: healthWithFallback,
|
|
1270
|
+
ok: (input, options) => getGeneric("/ok", input, options),
|
|
1271
|
+
error: (input, options) => getGeneric("/error", input, options),
|
|
1272
|
+
twoFactor: {
|
|
1273
|
+
getTotpUri: (input, options) => postGeneric("/two-factor/get-totp-uri", input, options),
|
|
1274
|
+
verifyTotp: (input, options) => postGeneric("/two-factor/verify-totp", input, options),
|
|
1275
|
+
sendOtp: (input, options) => postGeneric("/two-factor/send-otp", input, options),
|
|
1276
|
+
verifyOtp: (input, options) => postGeneric("/two-factor/verify-otp", input, options),
|
|
1277
|
+
verifyBackupCode: (input, options) => postGeneric("/two-factor/verify-backup-code", input, options),
|
|
1278
|
+
generateBackupCodes: (input, options) => executePostWithCompatibleInput(
|
|
1279
|
+
resolvedConfig,
|
|
1280
|
+
{ endpoint: "/two-factor/generate-backup-codes", method: "POST" },
|
|
1281
|
+
input,
|
|
1282
|
+
options
|
|
1283
|
+
),
|
|
1284
|
+
enable: (input, options) => postGeneric("/two-factor/enable", input, options),
|
|
1285
|
+
disable: (input, options) => postGeneric("/two-factor/disable", input, options)
|
|
786
1286
|
},
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
1287
|
+
passkey: {
|
|
1288
|
+
generateRegisterOptions: (input, options) => getGeneric("/passkey/generate-register-options", input, options),
|
|
1289
|
+
generateAuthenticateOptions: (input, options) => postGeneric("/passkey/generate-authenticate-options", input, options),
|
|
1290
|
+
verifyRegistration: (input, options) => postGeneric("/passkey/verify-registration", input, options),
|
|
1291
|
+
verifyAuthentication: (input, options) => postGeneric("/passkey/verify-authentication", input, options),
|
|
1292
|
+
listUserPasskeys: (input, options) => getGeneric("/passkey/list-user-passkeys", input, options),
|
|
1293
|
+
deletePasskey: (input, options) => postGeneric("/passkey/delete-passkey", input, options),
|
|
1294
|
+
updatePasskey: (input, options) => postGeneric("/passkey/update-passkey", input, options),
|
|
1295
|
+
getRelatedOrigins: (input, options) => getGeneric("/.well-known/webauthn", input, options)
|
|
790
1296
|
},
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
1297
|
+
admin: {
|
|
1298
|
+
role: {
|
|
1299
|
+
set: (input, options) => postGeneric("/admin/set-role", input, options)
|
|
1300
|
+
},
|
|
1301
|
+
user: {
|
|
1302
|
+
list: (input, options) => getWithQuery("/admin/list-users", input, options),
|
|
1303
|
+
create: (input, options) => postGeneric("/admin/create-user", input, options),
|
|
1304
|
+
unban: (input, options) => postGeneric("/admin/unban-user", input, options),
|
|
1305
|
+
ban: (input, options) => postGeneric("/admin/ban-user", input, options),
|
|
1306
|
+
impersonate: (input, options) => postGeneric("/admin/impersonate-user", input, options),
|
|
1307
|
+
stopImpersonating: (input, options) => postGeneric("/admin/stop-impersonating", input, options),
|
|
1308
|
+
remove: (input, options) => postGeneric("/admin/remove-user", input, options),
|
|
1309
|
+
setPassword: (input, options) => postGeneric("/admin/set-user-password", input, options),
|
|
1310
|
+
session: {
|
|
1311
|
+
list: (input, options) => postGeneric("/admin/list-user-sessions", input, options),
|
|
1312
|
+
revoke: adminUserSessionRevokeBinding
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
hasPermission: (input, options) => postGeneric("/admin/has-permission", input, options),
|
|
1316
|
+
apiKey: {
|
|
1317
|
+
create: (input, options) => postGeneric("/admin/api-key/create", input, options)
|
|
1318
|
+
},
|
|
1319
|
+
athenaClient: {
|
|
1320
|
+
create: (input, options) => postGeneric("/admin/athena-client/create", input, options),
|
|
1321
|
+
list: (input, options) => getWithQuery("/admin/athena-client/list", input, options)
|
|
1322
|
+
},
|
|
1323
|
+
auditLog: {
|
|
1324
|
+
list: (input, options) => getWithQuery("/admin/audit-log/list", input, options)
|
|
1325
|
+
},
|
|
1326
|
+
email: {
|
|
1327
|
+
list: (input, options) => getWithQuery("/admin/email/list", input, options),
|
|
1328
|
+
get: (input, options) => getWithQuery("/admin/email/get", input, options),
|
|
1329
|
+
create: (input, options) => postGeneric("/admin/email/create", input, options),
|
|
1330
|
+
update: (input, options) => postGeneric("/admin/email/update", input, options),
|
|
1331
|
+
delete: (input, options) => postGeneric("/admin/email/delete", input, options),
|
|
1332
|
+
failure: {
|
|
1333
|
+
list: (input, options) => getWithQuery("/admin/email-failure/list", input, options),
|
|
1334
|
+
get: (input, options) => getWithQuery("/admin/email-failure/get", input, options),
|
|
1335
|
+
create: (input, options) => postGeneric("/admin/email-failure/create", input, options),
|
|
1336
|
+
update: (input, options) => postGeneric("/admin/email-failure/update", input, options),
|
|
1337
|
+
delete: (input, options) => postGeneric("/admin/email-failure/delete", input, options)
|
|
1338
|
+
},
|
|
1339
|
+
template: {
|
|
1340
|
+
list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
|
|
1341
|
+
get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
|
|
1342
|
+
create: (input, options) => postGeneric("/admin/email-template/create", input, options),
|
|
1343
|
+
update: (input, options) => postGeneric("/admin/email-template/update", input, options),
|
|
1344
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
emailTemplate: {
|
|
1348
|
+
get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
|
|
1349
|
+
create: (input, options) => postGeneric("/admin/email-template/create", input, options),
|
|
1350
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
|
|
1351
|
+
list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
|
|
1352
|
+
update: (input, options) => postGeneric("/admin/email-template/update", input, options)
|
|
1353
|
+
}
|
|
794
1354
|
},
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
addCondition("like", String(column), value);
|
|
809
|
-
return self;
|
|
810
|
-
},
|
|
811
|
-
ilike(column, value) {
|
|
812
|
-
addCondition("ilike", String(column), value);
|
|
813
|
-
return self;
|
|
814
|
-
},
|
|
815
|
-
is(column, value) {
|
|
816
|
-
addCondition("is", String(column), value);
|
|
817
|
-
return self;
|
|
818
|
-
},
|
|
819
|
-
in(column, values) {
|
|
820
|
-
addCondition("in", String(column), values);
|
|
821
|
-
return self;
|
|
1355
|
+
apiKey: {
|
|
1356
|
+
create: (input, options) => postGeneric("/api-key/create", input, options),
|
|
1357
|
+
get: (input, options) => getWithQuery("/api-key/get", input, options),
|
|
1358
|
+
update: (input, options) => postGeneric("/api-key/update", input, options),
|
|
1359
|
+
delete: (input, options) => postGeneric("/api-key/delete", input, options),
|
|
1360
|
+
list: (input, options) => getWithQuery("/api-key/list", input, options),
|
|
1361
|
+
verify: (input, options) => postGeneric("/api-key/verify", input, options),
|
|
1362
|
+
deleteAllExpired: (input, options) => executePostWithOptionalInput(
|
|
1363
|
+
resolvedConfig,
|
|
1364
|
+
{ endpoint: "/api-key/delete-all-expired-api-keys", method: "POST" },
|
|
1365
|
+
input,
|
|
1366
|
+
options
|
|
1367
|
+
)
|
|
822
1368
|
},
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
1369
|
+
signIn: {
|
|
1370
|
+
email: (input, options) => postGeneric("/sign-in/email", input, options),
|
|
1371
|
+
username: (input, options) => postGeneric("/sign-in/username", input, options),
|
|
1372
|
+
social: (input, options) => postGeneric("/sign-in/social", input, options)
|
|
826
1373
|
},
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
return self;
|
|
1374
|
+
signUp: {
|
|
1375
|
+
email: (input, options) => postGeneric("/sign-up/email", input, options)
|
|
830
1376
|
},
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
1377
|
+
organization,
|
|
1378
|
+
callback: {
|
|
1379
|
+
provider: (input, options) => {
|
|
1380
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1381
|
+
const parsed = payload;
|
|
1382
|
+
const provider = String(parsed?.provider ?? "").trim();
|
|
1383
|
+
if (!provider) {
|
|
1384
|
+
throw new Error("callback.provider requires a non-empty provider value");
|
|
1385
|
+
}
|
|
1386
|
+
const code = String(parsed?.code ?? "").trim();
|
|
1387
|
+
const state = String(parsed?.state ?? "").trim();
|
|
1388
|
+
if (!code || !state) {
|
|
1389
|
+
throw new Error("callback.provider requires non-empty code and state values");
|
|
1390
|
+
}
|
|
1391
|
+
const endpoint = `/callback/${encodeURIComponent(provider)}`;
|
|
1392
|
+
return request({
|
|
1393
|
+
endpoint,
|
|
1394
|
+
method: "GET",
|
|
1395
|
+
query: {
|
|
1396
|
+
code,
|
|
1397
|
+
state
|
|
1398
|
+
},
|
|
1399
|
+
fetchOptions
|
|
1400
|
+
}, options);
|
|
837
1401
|
}
|
|
838
|
-
return self;
|
|
839
|
-
},
|
|
840
|
-
or(expression) {
|
|
841
|
-
addCondition("or", void 0, expression);
|
|
842
|
-
return self;
|
|
843
1402
|
}
|
|
844
1403
|
};
|
|
845
|
-
}
|
|
846
|
-
function toRpcSelect(columns) {
|
|
847
|
-
if (!columns) return void 0;
|
|
848
|
-
return Array.isArray(columns) ? columns.join(",") : columns;
|
|
849
|
-
}
|
|
850
|
-
function createRpcFilterMethods(filters, self) {
|
|
851
|
-
const addFilter = (operator, column, value) => {
|
|
852
|
-
filters.push({ column, operator, value });
|
|
853
|
-
};
|
|
854
1404
|
return {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
addFilter("lte", column, value);
|
|
877
|
-
return self;
|
|
878
|
-
},
|
|
879
|
-
like(column, value) {
|
|
880
|
-
addFilter("like", column, value);
|
|
881
|
-
return self;
|
|
1405
|
+
baseUrl: normalizedBaseUrl,
|
|
1406
|
+
request,
|
|
1407
|
+
signIn: {
|
|
1408
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
1409
|
+
resolvedConfig,
|
|
1410
|
+
{ endpoint: "/sign-in/email", method: "POST" },
|
|
1411
|
+
input,
|
|
1412
|
+
options
|
|
1413
|
+
),
|
|
1414
|
+
username: (input, options) => executePostWithCompatibleInput(
|
|
1415
|
+
resolvedConfig,
|
|
1416
|
+
{ endpoint: "/sign-in/username", method: "POST" },
|
|
1417
|
+
input,
|
|
1418
|
+
options
|
|
1419
|
+
),
|
|
1420
|
+
social: (input, options) => executePostWithCompatibleInput(
|
|
1421
|
+
resolvedConfig,
|
|
1422
|
+
{ endpoint: "/sign-in/social", method: "POST" },
|
|
1423
|
+
input,
|
|
1424
|
+
options
|
|
1425
|
+
)
|
|
882
1426
|
},
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1427
|
+
signUp: {
|
|
1428
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
1429
|
+
resolvedConfig,
|
|
1430
|
+
{ endpoint: "/sign-up/email", method: "POST" },
|
|
1431
|
+
input,
|
|
1432
|
+
options
|
|
1433
|
+
)
|
|
886
1434
|
},
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1435
|
+
signOut,
|
|
1436
|
+
logout: signOut,
|
|
1437
|
+
getSession: (input, options) => executeGetWithCompatibleInput(
|
|
1438
|
+
resolvedConfig,
|
|
1439
|
+
{ endpoint: "/get-session", method: "GET" },
|
|
1440
|
+
input,
|
|
1441
|
+
options
|
|
1442
|
+
),
|
|
1443
|
+
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
1444
|
+
resolvedConfig,
|
|
1445
|
+
{ endpoint: "/list-sessions", method: "GET" },
|
|
1446
|
+
input,
|
|
1447
|
+
options
|
|
1448
|
+
),
|
|
1449
|
+
revokeSession,
|
|
1450
|
+
clearSession: revokeSession,
|
|
1451
|
+
revokeSessions,
|
|
1452
|
+
clearSessions: revokeSessions,
|
|
1453
|
+
revokeOtherSessions,
|
|
1454
|
+
clearOtherSessions: revokeOtherSessions,
|
|
1455
|
+
forgetPassword: (input, options) => executePostWithCompatibleInput(
|
|
1456
|
+
resolvedConfig,
|
|
1457
|
+
{ endpoint: "/forget-password", method: "POST" },
|
|
1458
|
+
input,
|
|
1459
|
+
options
|
|
1460
|
+
),
|
|
1461
|
+
resetPassword: (input, options) => executePostWithCompatibleInput(
|
|
1462
|
+
resolvedConfig,
|
|
1463
|
+
{ endpoint: "/reset-password", method: "POST" },
|
|
1464
|
+
input,
|
|
1465
|
+
options
|
|
1466
|
+
),
|
|
1467
|
+
resolveResetPasswordToken,
|
|
1468
|
+
verifyEmail: (input, options) => {
|
|
1469
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
1470
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
1471
|
+
const query = payload;
|
|
1472
|
+
return callAuthEndpoint(
|
|
1473
|
+
resolvedConfig,
|
|
1474
|
+
{ endpoint: "/verify-email", method: "GET" },
|
|
1475
|
+
void 0,
|
|
1476
|
+
query ? {
|
|
1477
|
+
token: query.token,
|
|
1478
|
+
callbackURL: query.callbackURL
|
|
1479
|
+
} : void 0,
|
|
1480
|
+
mergedOptions
|
|
1481
|
+
);
|
|
890
1482
|
},
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1483
|
+
sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
|
|
1484
|
+
resolvedConfig,
|
|
1485
|
+
{ endpoint: "/send-verification-email", method: "POST" },
|
|
1486
|
+
input,
|
|
1487
|
+
options
|
|
1488
|
+
),
|
|
1489
|
+
changeEmail: (input, options) => executePostWithCompatibleInput(
|
|
1490
|
+
resolvedConfig,
|
|
1491
|
+
{ endpoint: "/change-email", method: "POST" },
|
|
1492
|
+
input,
|
|
1493
|
+
options
|
|
1494
|
+
),
|
|
1495
|
+
changePassword: (input, options) => executePostWithCompatibleInput(
|
|
1496
|
+
resolvedConfig,
|
|
1497
|
+
{ endpoint: "/change-password", method: "POST" },
|
|
1498
|
+
input,
|
|
1499
|
+
options
|
|
1500
|
+
),
|
|
1501
|
+
updateUser: (input, options) => executePostWithCompatibleInput(
|
|
1502
|
+
resolvedConfig,
|
|
1503
|
+
{ endpoint: "/update-user", method: "POST" },
|
|
1504
|
+
input,
|
|
1505
|
+
options
|
|
1506
|
+
),
|
|
1507
|
+
deleteUser,
|
|
1508
|
+
deleteUserCallback,
|
|
1509
|
+
linkSocial: (input, options) => executePostWithCompatibleInput(
|
|
1510
|
+
resolvedConfig,
|
|
1511
|
+
{ endpoint: "/link-social", method: "POST" },
|
|
1512
|
+
input,
|
|
1513
|
+
options
|
|
1514
|
+
),
|
|
1515
|
+
listAccounts: (input, options) => executeGetWithCompatibleInput(
|
|
1516
|
+
resolvedConfig,
|
|
1517
|
+
{ endpoint: "/list-accounts", method: "GET" },
|
|
1518
|
+
input,
|
|
1519
|
+
options
|
|
1520
|
+
),
|
|
1521
|
+
unlinkAccount: (input, options) => executePostWithCompatibleInput(
|
|
1522
|
+
resolvedConfig,
|
|
1523
|
+
{ endpoint: "/unlink-account", method: "POST" },
|
|
1524
|
+
input,
|
|
1525
|
+
options
|
|
1526
|
+
),
|
|
1527
|
+
refreshToken: (input, options) => executePostWithCompatibleInput(
|
|
1528
|
+
resolvedConfig,
|
|
1529
|
+
{ endpoint: "/refresh-token", method: "POST" },
|
|
1530
|
+
input,
|
|
1531
|
+
options
|
|
1532
|
+
),
|
|
1533
|
+
getAccessToken: (input, options) => executePostWithCompatibleInput(
|
|
1534
|
+
resolvedConfig,
|
|
1535
|
+
{ endpoint: "/get-access-token", method: "POST" },
|
|
1536
|
+
input,
|
|
1537
|
+
options
|
|
1538
|
+
),
|
|
1539
|
+
organization,
|
|
1540
|
+
auth
|
|
895
1541
|
};
|
|
896
1542
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
1543
|
+
|
|
1544
|
+
// src/client.ts
|
|
1545
|
+
var DEFAULT_COLUMNS = "*";
|
|
1546
|
+
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;
|
|
1547
|
+
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
1548
|
+
function formatResult(response) {
|
|
1549
|
+
const result = {
|
|
1550
|
+
data: response.data ?? null,
|
|
1551
|
+
error: response.error ?? null,
|
|
1552
|
+
errorDetails: response.errorDetails ?? null,
|
|
1553
|
+
status: response.status,
|
|
1554
|
+
raw: response.raw
|
|
900
1555
|
};
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
count: mergedOptions?.count,
|
|
913
|
-
head: mergedOptions?.head,
|
|
914
|
-
limit: state.limit,
|
|
915
|
-
offset: state.offset,
|
|
916
|
-
order: state.order
|
|
917
|
-
};
|
|
918
|
-
const response = await client.rpcGateway(payload, mergedOptions);
|
|
919
|
-
return formatResult(response);
|
|
1556
|
+
if (response.count !== void 0) {
|
|
1557
|
+
result.count = response.count;
|
|
1558
|
+
}
|
|
1559
|
+
return result;
|
|
1560
|
+
}
|
|
1561
|
+
function toSingleResult(response) {
|
|
1562
|
+
const payload = response.data;
|
|
1563
|
+
const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
|
|
1564
|
+
return {
|
|
1565
|
+
...response,
|
|
1566
|
+
data: singleData
|
|
920
1567
|
};
|
|
1568
|
+
}
|
|
1569
|
+
function mergeOptions(...options) {
|
|
1570
|
+
return options.reduce((acc, next) => {
|
|
1571
|
+
if (!next) return acc;
|
|
1572
|
+
return { ...acc, ...next };
|
|
1573
|
+
}, void 0);
|
|
1574
|
+
}
|
|
1575
|
+
function asAthenaJsonObject(value) {
|
|
1576
|
+
return value;
|
|
1577
|
+
}
|
|
1578
|
+
function asAthenaJsonObjectArray(values) {
|
|
1579
|
+
return values;
|
|
1580
|
+
}
|
|
1581
|
+
function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS) {
|
|
1582
|
+
let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
|
|
1583
|
+
let selectedOptions;
|
|
1584
|
+
let promise = null;
|
|
921
1585
|
const run = (columns, options) => {
|
|
922
1586
|
const payloadColumns = columns ?? selectedColumns;
|
|
923
1587
|
const payloadOptions = options ?? selectedOptions;
|
|
924
1588
|
if (!promise) {
|
|
925
|
-
promise =
|
|
1589
|
+
promise = executor(payloadColumns, payloadOptions);
|
|
926
1590
|
}
|
|
927
1591
|
return promise;
|
|
928
1592
|
};
|
|
929
|
-
const
|
|
930
|
-
const filterMethods = createRpcFilterMethods(state.filters, builder);
|
|
931
|
-
Object.assign(builder, filterMethods, {
|
|
1593
|
+
const mutationQuery = {
|
|
932
1594
|
select(columns = selectedColumns, options) {
|
|
933
1595
|
selectedColumns = columns;
|
|
934
1596
|
selectedOptions = options ?? selectedOptions;
|
|
935
1597
|
return run(columns, options);
|
|
936
1598
|
},
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
return toSingleResult(result);
|
|
940
|
-
},
|
|
941
|
-
maybeSingle(columns, options) {
|
|
942
|
-
return builder.single(columns, options);
|
|
943
|
-
},
|
|
944
|
-
order(column, options) {
|
|
945
|
-
state.order = { column, ascending: options?.ascending ?? true };
|
|
946
|
-
return builder;
|
|
947
|
-
},
|
|
948
|
-
limit(count) {
|
|
949
|
-
state.limit = count;
|
|
950
|
-
return builder;
|
|
1599
|
+
returning(columns = selectedColumns, options) {
|
|
1600
|
+
return mutationQuery.select(columns, options);
|
|
951
1601
|
},
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1602
|
+
single(columns = selectedColumns, options) {
|
|
1603
|
+
selectedColumns = columns;
|
|
1604
|
+
selectedOptions = options ?? selectedOptions;
|
|
1605
|
+
return run(columns, options).then(toSingleResult);
|
|
955
1606
|
},
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
state.limit = to - from + 1;
|
|
959
|
-
return builder;
|
|
1607
|
+
maybeSingle(columns = selectedColumns, options) {
|
|
1608
|
+
return mutationQuery.single(columns, options);
|
|
960
1609
|
},
|
|
961
1610
|
then(onfulfilled, onrejected) {
|
|
962
1611
|
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
@@ -967,129 +1616,518 @@ function createRpcBuilder(functionName, args, baseOptions, client) {
|
|
|
967
1616
|
finally(onfinally) {
|
|
968
1617
|
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
969
1618
|
}
|
|
970
|
-
}
|
|
971
|
-
return
|
|
1619
|
+
};
|
|
1620
|
+
return mutationQuery;
|
|
972
1621
|
}
|
|
973
|
-
function
|
|
974
|
-
const
|
|
975
|
-
|
|
1622
|
+
function getResourceId(state) {
|
|
1623
|
+
const candidate = state.conditions.find(
|
|
1624
|
+
(condition) => condition.operator === "eq" && (condition.column === "resource_id" || condition.column === "id")
|
|
1625
|
+
);
|
|
1626
|
+
return candidate?.value?.toString();
|
|
1627
|
+
}
|
|
1628
|
+
function stringifyFilterValue(value) {
|
|
1629
|
+
if (Array.isArray(value)) {
|
|
1630
|
+
return value.join(",");
|
|
1631
|
+
}
|
|
1632
|
+
return String(value);
|
|
1633
|
+
}
|
|
1634
|
+
function isUuidString(value) {
|
|
1635
|
+
return UUID_PATTERN.test(value.trim());
|
|
1636
|
+
}
|
|
1637
|
+
function isUuidIdentifierColumn(column) {
|
|
1638
|
+
return column === "id" || /(?:^|_)uuid(?:_|$)/i.test(column) || /_id$/i.test(column);
|
|
1639
|
+
}
|
|
1640
|
+
function shouldUseUuidTextComparison(column, value) {
|
|
1641
|
+
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
1642
|
+
}
|
|
1643
|
+
function normalizeCast(cast) {
|
|
1644
|
+
const normalized = cast.trim().toLowerCase();
|
|
1645
|
+
if (!SAFE_CAST_PATTERN.test(normalized)) {
|
|
1646
|
+
throw new Error(`Invalid cast type "${cast}"`);
|
|
1647
|
+
}
|
|
1648
|
+
return normalized;
|
|
1649
|
+
}
|
|
1650
|
+
function escapeSqlStringLiteral(value) {
|
|
1651
|
+
return value.replace(/'/g, "''");
|
|
1652
|
+
}
|
|
1653
|
+
function toSqlLiteral(value) {
|
|
1654
|
+
if (value === null) return "NULL";
|
|
1655
|
+
if (typeof value === "number") return Number.isFinite(value) ? String(value) : "NULL";
|
|
1656
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
1657
|
+
return `'${escapeSqlStringLiteral(value)}'`;
|
|
1658
|
+
}
|
|
1659
|
+
function withCast(expression, cast) {
|
|
1660
|
+
if (!cast) return expression;
|
|
1661
|
+
return `${expression}::${normalizeCast(cast)}`;
|
|
1662
|
+
}
|
|
1663
|
+
function buildSelectColumnsClause(columns) {
|
|
1664
|
+
if (Array.isArray(columns)) {
|
|
1665
|
+
return columns.map((column) => quoteQualifiedIdentifier(column)).join(", ");
|
|
1666
|
+
}
|
|
1667
|
+
return quoteSelectColumnsExpression(columns);
|
|
1668
|
+
}
|
|
1669
|
+
function resolveTableNameForCall(tableName, schema) {
|
|
1670
|
+
if (!schema) return tableName;
|
|
1671
|
+
const normalizedSchema = schema.trim();
|
|
1672
|
+
if (!normalizedSchema) {
|
|
1673
|
+
throw new Error("schema option must be a non-empty string");
|
|
1674
|
+
}
|
|
1675
|
+
if (tableName.includes(".")) {
|
|
1676
|
+
if (tableName.startsWith(`${normalizedSchema}.`)) {
|
|
1677
|
+
return tableName;
|
|
1678
|
+
}
|
|
1679
|
+
throw new Error(
|
|
1680
|
+
`schema option "${normalizedSchema}" conflicts with schema-qualified table "${tableName}"`
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
return `${normalizedSchema}.${tableName}`;
|
|
1684
|
+
}
|
|
1685
|
+
function conditionToSqlClause(condition) {
|
|
1686
|
+
if (!condition.column) return null;
|
|
1687
|
+
const column = withCast(quoteQualifiedIdentifier(condition.column), condition.column_cast);
|
|
1688
|
+
const value = condition.value;
|
|
1689
|
+
const sqlOperator = {
|
|
1690
|
+
eq: "=",
|
|
1691
|
+
neq: "!=",
|
|
1692
|
+
gt: ">",
|
|
1693
|
+
gte: ">=",
|
|
1694
|
+
lt: "<",
|
|
1695
|
+
lte: "<=",
|
|
1696
|
+
like: "LIKE",
|
|
1697
|
+
ilike: "ILIKE"
|
|
976
1698
|
};
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1699
|
+
switch (condition.operator) {
|
|
1700
|
+
case "eq":
|
|
1701
|
+
case "neq":
|
|
1702
|
+
case "gt":
|
|
1703
|
+
case "gte":
|
|
1704
|
+
case "lt":
|
|
1705
|
+
case "lte":
|
|
1706
|
+
case "like":
|
|
1707
|
+
case "ilike": {
|
|
1708
|
+
if (Array.isArray(value) || value === void 0) return null;
|
|
1709
|
+
const rhs = withCast(toSqlLiteral(value), condition.value_cast);
|
|
1710
|
+
return `${column} ${sqlOperator[condition.operator]} ${rhs}`;
|
|
984
1711
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
if (
|
|
988
|
-
|
|
989
|
-
|
|
1712
|
+
case "is": {
|
|
1713
|
+
if (value === null) return `${column} IS NULL`;
|
|
1714
|
+
if (value === true) return `${column} IS TRUE`;
|
|
1715
|
+
if (value === false) return `${column} IS FALSE`;
|
|
1716
|
+
return null;
|
|
990
1717
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
if (
|
|
994
|
-
|
|
995
|
-
}
|
|
1718
|
+
case "in": {
|
|
1719
|
+
if (!Array.isArray(value)) return null;
|
|
1720
|
+
if (value.length === 0) return "FALSE";
|
|
1721
|
+
const values = value.map((item) => withCast(toSqlLiteral(item), condition.value_cast));
|
|
1722
|
+
return `${column} IN (${values.join(", ")})`;
|
|
996
1723
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1724
|
+
default:
|
|
1725
|
+
return null;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
function buildTypedSelectQuery(input) {
|
|
1729
|
+
const whereClauses = [];
|
|
1730
|
+
for (const condition of input.conditions) {
|
|
1731
|
+
const clause = conditionToSqlClause(condition);
|
|
1732
|
+
if (!clause) return null;
|
|
1733
|
+
whereClauses.push(clause);
|
|
1734
|
+
}
|
|
1735
|
+
let limit = input.limit;
|
|
1736
|
+
let offset = input.offset;
|
|
1737
|
+
if (limit === void 0 && input.pageSize !== void 0) {
|
|
1738
|
+
limit = input.pageSize;
|
|
1739
|
+
}
|
|
1740
|
+
if (offset === void 0 && input.pageSize !== void 0 && input.currentPage !== void 0 && input.currentPage > 0) {
|
|
1741
|
+
offset = (input.currentPage - 1) * input.pageSize;
|
|
1742
|
+
}
|
|
1743
|
+
const sqlParts = [
|
|
1744
|
+
`SELECT ${buildSelectColumnsClause(input.columns)} FROM ${quoteQualifiedIdentifier(input.tableName)}`
|
|
1745
|
+
];
|
|
1746
|
+
if (whereClauses.length > 0) {
|
|
1747
|
+
sqlParts.push(`WHERE ${whereClauses.join(" AND ")}`);
|
|
1748
|
+
}
|
|
1749
|
+
if (input.order?.field) {
|
|
1750
|
+
const direction = input.order.direction === "descending" ? "DESC" : "ASC";
|
|
1751
|
+
sqlParts.push(`ORDER BY ${quoteQualifiedIdentifier(input.order.field)} ${direction}`);
|
|
1752
|
+
}
|
|
1753
|
+
if (limit !== void 0) {
|
|
1754
|
+
sqlParts.push(`LIMIT ${Math.max(0, Math.trunc(limit))}`);
|
|
1755
|
+
}
|
|
1756
|
+
if (offset !== void 0) {
|
|
1757
|
+
sqlParts.push(`OFFSET ${Math.max(0, Math.trunc(offset))}`);
|
|
1758
|
+
}
|
|
1759
|
+
return `${sqlParts.join(" ")};`;
|
|
1760
|
+
}
|
|
1761
|
+
function createFilterMethods(state, addCondition, self) {
|
|
1762
|
+
return {
|
|
1763
|
+
eq(column, value) {
|
|
1764
|
+
const columnName = String(column);
|
|
1765
|
+
if (shouldUseUuidTextComparison(columnName, value)) {
|
|
1766
|
+
addCondition("eq", columnName, value, { columnCast: "text" });
|
|
1767
|
+
} else {
|
|
1768
|
+
addCondition("eq", columnName, value);
|
|
1001
1769
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
limit: state.limit,
|
|
1023
|
-
offset: state.offset,
|
|
1024
|
-
currentPage: state.currentPage,
|
|
1025
|
-
pageSize: state.pageSize,
|
|
1026
|
-
order: state.order
|
|
1770
|
+
return self;
|
|
1771
|
+
},
|
|
1772
|
+
eqCast(column, value, cast) {
|
|
1773
|
+
addCondition("eq", String(column), value, { valueCast: cast });
|
|
1774
|
+
return self;
|
|
1775
|
+
},
|
|
1776
|
+
eqUuid(column, value) {
|
|
1777
|
+
addCondition("eq", String(column), value, { valueCast: "uuid" });
|
|
1778
|
+
return self;
|
|
1779
|
+
},
|
|
1780
|
+
match(filters) {
|
|
1781
|
+
Object.entries(filters).forEach(([column, value]) => {
|
|
1782
|
+
if (value === void 0) {
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
if (shouldUseUuidTextComparison(column, value)) {
|
|
1786
|
+
addCondition("eq", column, value, { columnCast: "text" });
|
|
1787
|
+
} else {
|
|
1788
|
+
addCondition("eq", column, value);
|
|
1789
|
+
}
|
|
1027
1790
|
});
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1791
|
+
return self;
|
|
1792
|
+
},
|
|
1793
|
+
range(from, to) {
|
|
1794
|
+
state.offset = from;
|
|
1795
|
+
state.limit = to - from + 1;
|
|
1796
|
+
return self;
|
|
1797
|
+
},
|
|
1798
|
+
limit(count) {
|
|
1799
|
+
state.limit = count;
|
|
1800
|
+
return self;
|
|
1801
|
+
},
|
|
1802
|
+
offset(count) {
|
|
1803
|
+
state.offset = count;
|
|
1804
|
+
return self;
|
|
1805
|
+
},
|
|
1806
|
+
currentPage(value) {
|
|
1807
|
+
state.currentPage = value;
|
|
1808
|
+
return self;
|
|
1809
|
+
},
|
|
1810
|
+
pageSize(value) {
|
|
1811
|
+
state.pageSize = value;
|
|
1812
|
+
return self;
|
|
1813
|
+
},
|
|
1814
|
+
totalPages(value) {
|
|
1815
|
+
state.totalPages = value;
|
|
1816
|
+
return self;
|
|
1817
|
+
},
|
|
1818
|
+
order(column, options) {
|
|
1819
|
+
state.order = {
|
|
1820
|
+
field: String(column),
|
|
1821
|
+
direction: options?.ascending === false ? "descending" : "ascending"
|
|
1822
|
+
};
|
|
1823
|
+
return self;
|
|
1824
|
+
},
|
|
1825
|
+
gt(column, value) {
|
|
1826
|
+
addCondition("gt", String(column), value);
|
|
1827
|
+
return self;
|
|
1828
|
+
},
|
|
1829
|
+
gte(column, value) {
|
|
1830
|
+
addCondition("gte", String(column), value);
|
|
1831
|
+
return self;
|
|
1832
|
+
},
|
|
1833
|
+
lt(column, value) {
|
|
1834
|
+
addCondition("lt", String(column), value);
|
|
1835
|
+
return self;
|
|
1836
|
+
},
|
|
1837
|
+
lte(column, value) {
|
|
1838
|
+
addCondition("lte", String(column), value);
|
|
1839
|
+
return self;
|
|
1840
|
+
},
|
|
1841
|
+
neq(column, value) {
|
|
1842
|
+
addCondition("neq", String(column), value);
|
|
1843
|
+
return self;
|
|
1844
|
+
},
|
|
1845
|
+
like(column, value) {
|
|
1846
|
+
addCondition("like", String(column), value);
|
|
1847
|
+
return self;
|
|
1848
|
+
},
|
|
1849
|
+
ilike(column, value) {
|
|
1850
|
+
addCondition("ilike", String(column), value);
|
|
1851
|
+
return self;
|
|
1852
|
+
},
|
|
1853
|
+
is(column, value) {
|
|
1854
|
+
addCondition("is", String(column), value);
|
|
1855
|
+
return self;
|
|
1856
|
+
},
|
|
1857
|
+
in(column, values) {
|
|
1858
|
+
addCondition("in", String(column), values);
|
|
1859
|
+
return self;
|
|
1860
|
+
},
|
|
1861
|
+
contains(column, values) {
|
|
1862
|
+
addCondition("contains", String(column), values);
|
|
1863
|
+
return self;
|
|
1864
|
+
},
|
|
1865
|
+
containedBy(column, values) {
|
|
1866
|
+
addCondition("containedBy", String(column), values);
|
|
1867
|
+
return self;
|
|
1868
|
+
},
|
|
1869
|
+
not(columnOrExpression, operator, value) {
|
|
1870
|
+
const expression = String(columnOrExpression);
|
|
1871
|
+
if (operator != null && value !== void 0) {
|
|
1872
|
+
addCondition("not", void 0, `${expression}.${operator}.${stringifyFilterValue(value)}`);
|
|
1873
|
+
} else {
|
|
1874
|
+
addCondition("not", void 0, expression);
|
|
1031
1875
|
}
|
|
1876
|
+
return self;
|
|
1877
|
+
},
|
|
1878
|
+
or(expression) {
|
|
1879
|
+
addCondition("or", void 0, expression);
|
|
1880
|
+
return self;
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
function toRpcSelect(columns) {
|
|
1885
|
+
if (!columns) return void 0;
|
|
1886
|
+
return Array.isArray(columns) ? columns.join(",") : columns;
|
|
1887
|
+
}
|
|
1888
|
+
function createRpcFilterMethods(filters, self) {
|
|
1889
|
+
const addFilter = (operator, column, value) => {
|
|
1890
|
+
filters.push({ column, operator, value });
|
|
1891
|
+
};
|
|
1892
|
+
return {
|
|
1893
|
+
eq(column, value) {
|
|
1894
|
+
addFilter("eq", column, value);
|
|
1895
|
+
return self;
|
|
1896
|
+
},
|
|
1897
|
+
neq(column, value) {
|
|
1898
|
+
addFilter("neq", column, value);
|
|
1899
|
+
return self;
|
|
1900
|
+
},
|
|
1901
|
+
gt(column, value) {
|
|
1902
|
+
addFilter("gt", column, value);
|
|
1903
|
+
return self;
|
|
1904
|
+
},
|
|
1905
|
+
gte(column, value) {
|
|
1906
|
+
addFilter("gte", column, value);
|
|
1907
|
+
return self;
|
|
1908
|
+
},
|
|
1909
|
+
lt(column, value) {
|
|
1910
|
+
addFilter("lt", column, value);
|
|
1911
|
+
return self;
|
|
1912
|
+
},
|
|
1913
|
+
lte(column, value) {
|
|
1914
|
+
addFilter("lte", column, value);
|
|
1915
|
+
return self;
|
|
1916
|
+
},
|
|
1917
|
+
like(column, value) {
|
|
1918
|
+
addFilter("like", column, value);
|
|
1919
|
+
return self;
|
|
1920
|
+
},
|
|
1921
|
+
ilike(column, value) {
|
|
1922
|
+
addFilter("ilike", column, value);
|
|
1923
|
+
return self;
|
|
1924
|
+
},
|
|
1925
|
+
is(column, value) {
|
|
1926
|
+
addFilter("is", column, value);
|
|
1927
|
+
return self;
|
|
1928
|
+
},
|
|
1929
|
+
in(column, values) {
|
|
1930
|
+
addFilter("in", column, values);
|
|
1931
|
+
return self;
|
|
1032
1932
|
}
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
function createRpcBuilder(functionName, args, baseOptions, client) {
|
|
1936
|
+
const state = {
|
|
1937
|
+
filters: []
|
|
1938
|
+
};
|
|
1939
|
+
let selectedColumns;
|
|
1940
|
+
let selectedOptions;
|
|
1941
|
+
let promise = null;
|
|
1942
|
+
const executeRpc = async (columns, options) => {
|
|
1943
|
+
const mergedOptions = mergeOptions(baseOptions, options);
|
|
1033
1944
|
const payload = {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1945
|
+
function: functionName,
|
|
1946
|
+
args,
|
|
1947
|
+
schema: mergedOptions?.schema,
|
|
1948
|
+
select: toRpcSelect(columns),
|
|
1949
|
+
filters: state.filters.length ? [...state.filters] : void 0,
|
|
1950
|
+
count: mergedOptions?.count,
|
|
1951
|
+
head: mergedOptions?.head,
|
|
1037
1952
|
limit: state.limit,
|
|
1038
1953
|
offset: state.offset,
|
|
1039
|
-
|
|
1040
|
-
page_size: state.pageSize,
|
|
1041
|
-
total_pages: state.totalPages,
|
|
1042
|
-
sort_by: state.order,
|
|
1043
|
-
strip_nulls: options?.stripNulls ?? true,
|
|
1044
|
-
count: options?.count,
|
|
1045
|
-
head: options?.head
|
|
1954
|
+
order: state.order
|
|
1046
1955
|
};
|
|
1047
|
-
const response = await client.
|
|
1956
|
+
const response = await client.rpcGateway(payload, mergedOptions);
|
|
1048
1957
|
return formatResult(response);
|
|
1049
1958
|
};
|
|
1050
|
-
const
|
|
1051
|
-
const
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
},
|
|
1058
|
-
maybeSingle(cols, opts) {
|
|
1059
|
-
return chain.single(cols, opts);
|
|
1060
|
-
},
|
|
1061
|
-
then(onfulfilled, onrejected) {
|
|
1062
|
-
return runSelect(columns, options).then(onfulfilled, onrejected);
|
|
1063
|
-
},
|
|
1064
|
-
catch(onrejected) {
|
|
1065
|
-
return runSelect(columns, options).catch(onrejected);
|
|
1066
|
-
},
|
|
1067
|
-
finally(onfinally) {
|
|
1068
|
-
return runSelect(columns, options).finally(onfinally);
|
|
1069
|
-
}
|
|
1070
|
-
});
|
|
1071
|
-
return chain;
|
|
1959
|
+
const run = (columns, options) => {
|
|
1960
|
+
const payloadColumns = columns ?? selectedColumns;
|
|
1961
|
+
const payloadOptions = options ?? selectedOptions;
|
|
1962
|
+
if (!promise) {
|
|
1963
|
+
promise = executeRpc(payloadColumns, payloadOptions);
|
|
1964
|
+
}
|
|
1965
|
+
return promise;
|
|
1072
1966
|
};
|
|
1967
|
+
const builder = {};
|
|
1968
|
+
const filterMethods = createRpcFilterMethods(state.filters, builder);
|
|
1073
1969
|
Object.assign(builder, filterMethods, {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
state.order = void 0;
|
|
1079
|
-
state.currentPage = void 0;
|
|
1080
|
-
state.pageSize = void 0;
|
|
1081
|
-
state.totalPages = void 0;
|
|
1082
|
-
return builder;
|
|
1970
|
+
select(columns = selectedColumns, options) {
|
|
1971
|
+
selectedColumns = columns;
|
|
1972
|
+
selectedOptions = options ?? selectedOptions;
|
|
1973
|
+
return run(columns, options);
|
|
1083
1974
|
},
|
|
1084
|
-
|
|
1085
|
-
|
|
1975
|
+
async single(columns, options) {
|
|
1976
|
+
const result = await run(columns, options);
|
|
1977
|
+
return toSingleResult(result);
|
|
1086
1978
|
},
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1979
|
+
maybeSingle(columns, options) {
|
|
1980
|
+
return builder.single(columns, options);
|
|
1981
|
+
},
|
|
1982
|
+
order(column, options) {
|
|
1983
|
+
state.order = { column, ascending: options?.ascending ?? true };
|
|
1984
|
+
return builder;
|
|
1985
|
+
},
|
|
1986
|
+
limit(count) {
|
|
1987
|
+
state.limit = count;
|
|
1988
|
+
return builder;
|
|
1989
|
+
},
|
|
1990
|
+
offset(count) {
|
|
1991
|
+
state.offset = count;
|
|
1992
|
+
return builder;
|
|
1993
|
+
},
|
|
1994
|
+
range(from, to) {
|
|
1995
|
+
state.offset = from;
|
|
1996
|
+
state.limit = to - from + 1;
|
|
1997
|
+
return builder;
|
|
1998
|
+
},
|
|
1999
|
+
then(onfulfilled, onrejected) {
|
|
2000
|
+
return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
|
|
2001
|
+
},
|
|
2002
|
+
catch(onrejected) {
|
|
2003
|
+
return run(selectedColumns, selectedOptions).catch(onrejected);
|
|
2004
|
+
},
|
|
2005
|
+
finally(onfinally) {
|
|
2006
|
+
return run(selectedColumns, selectedOptions).finally(onfinally);
|
|
2007
|
+
}
|
|
2008
|
+
});
|
|
2009
|
+
return builder;
|
|
2010
|
+
}
|
|
2011
|
+
function createTableBuilder(tableName, client) {
|
|
2012
|
+
const state = {
|
|
2013
|
+
conditions: []
|
|
2014
|
+
};
|
|
2015
|
+
const addCondition = (operator, column, value, hints) => {
|
|
2016
|
+
const condition = { operator };
|
|
2017
|
+
if (column) {
|
|
2018
|
+
condition.column = column;
|
|
2019
|
+
if (operator === "eq") {
|
|
2020
|
+
condition.eq_column = column;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
if (value !== void 0) {
|
|
2024
|
+
condition.value = value;
|
|
2025
|
+
if (operator === "eq") {
|
|
2026
|
+
condition.eq_value = value;
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
if (hints?.valueCast) {
|
|
2030
|
+
condition.value_cast = hints.valueCast;
|
|
2031
|
+
if (operator === "eq") {
|
|
2032
|
+
condition.eq_value_cast = hints.valueCast;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (hints?.columnCast) {
|
|
2036
|
+
condition.column_cast = hints.columnCast;
|
|
2037
|
+
if (operator === "eq") {
|
|
2038
|
+
condition.eq_column_cast = hints.columnCast;
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
state.conditions.push(condition);
|
|
2042
|
+
};
|
|
2043
|
+
const builder = {};
|
|
2044
|
+
const filterMethods = createFilterMethods(
|
|
2045
|
+
state,
|
|
2046
|
+
addCondition,
|
|
2047
|
+
builder
|
|
2048
|
+
);
|
|
2049
|
+
const runSelect = async (columns = DEFAULT_COLUMNS, options) => {
|
|
2050
|
+
const resolvedTableName = resolveTableNameForCall(tableName, options?.schema);
|
|
2051
|
+
const conditions = state.conditions.length ? state.conditions.map((condition) => ({ ...condition })) : void 0;
|
|
2052
|
+
const hasTypedEqualityComparison = conditions?.some(
|
|
2053
|
+
(condition) => condition.operator === "eq" && (condition.value_cast !== void 0 || condition.column_cast !== void 0)
|
|
2054
|
+
) ?? false;
|
|
2055
|
+
if (hasTypedEqualityComparison && !options?.head && !options?.count && conditions) {
|
|
2056
|
+
const query = buildTypedSelectQuery({
|
|
2057
|
+
tableName: resolvedTableName,
|
|
2058
|
+
columns,
|
|
2059
|
+
conditions,
|
|
2060
|
+
limit: state.limit,
|
|
2061
|
+
offset: state.offset,
|
|
2062
|
+
currentPage: state.currentPage,
|
|
2063
|
+
pageSize: state.pageSize,
|
|
2064
|
+
order: state.order
|
|
2065
|
+
});
|
|
2066
|
+
if (query) {
|
|
2067
|
+
const queryResponse = await client.queryGateway({ query }, options);
|
|
2068
|
+
return formatResult(queryResponse);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
const payload = {
|
|
2072
|
+
table_name: resolvedTableName,
|
|
2073
|
+
columns,
|
|
2074
|
+
conditions,
|
|
2075
|
+
limit: state.limit,
|
|
2076
|
+
offset: state.offset,
|
|
2077
|
+
current_page: state.currentPage,
|
|
2078
|
+
page_size: state.pageSize,
|
|
2079
|
+
total_pages: state.totalPages,
|
|
2080
|
+
sort_by: state.order,
|
|
2081
|
+
strip_nulls: options?.stripNulls ?? true,
|
|
2082
|
+
count: options?.count,
|
|
2083
|
+
head: options?.head
|
|
2084
|
+
};
|
|
2085
|
+
const response = await client.fetchGateway(payload, options);
|
|
2086
|
+
return formatResult(response);
|
|
2087
|
+
};
|
|
2088
|
+
const createSelectChain = (columns, options) => {
|
|
2089
|
+
const chain = {};
|
|
2090
|
+
const filterMethods2 = createFilterMethods(state, addCondition, chain);
|
|
2091
|
+
Object.assign(chain, filterMethods2, {
|
|
2092
|
+
async single(cols, opts) {
|
|
2093
|
+
const r = await runSelect(cols ?? columns, opts ?? options);
|
|
2094
|
+
return toSingleResult(r);
|
|
2095
|
+
},
|
|
2096
|
+
maybeSingle(cols, opts) {
|
|
2097
|
+
return chain.single(cols, opts);
|
|
2098
|
+
},
|
|
2099
|
+
then(onfulfilled, onrejected) {
|
|
2100
|
+
return runSelect(columns, options).then(onfulfilled, onrejected);
|
|
2101
|
+
},
|
|
2102
|
+
catch(onrejected) {
|
|
2103
|
+
return runSelect(columns, options).catch(onrejected);
|
|
2104
|
+
},
|
|
2105
|
+
finally(onfinally) {
|
|
2106
|
+
return runSelect(columns, options).finally(onfinally);
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
return chain;
|
|
2110
|
+
};
|
|
2111
|
+
Object.assign(builder, filterMethods, {
|
|
2112
|
+
reset() {
|
|
2113
|
+
state.conditions = [];
|
|
2114
|
+
state.limit = void 0;
|
|
2115
|
+
state.offset = void 0;
|
|
2116
|
+
state.order = void 0;
|
|
2117
|
+
state.currentPage = void 0;
|
|
2118
|
+
state.pageSize = void 0;
|
|
2119
|
+
state.totalPages = void 0;
|
|
2120
|
+
return builder;
|
|
2121
|
+
},
|
|
2122
|
+
select(columns = DEFAULT_COLUMNS, options) {
|
|
2123
|
+
return createSelectChain(columns, options);
|
|
2124
|
+
},
|
|
2125
|
+
insert(values, options) {
|
|
2126
|
+
if (Array.isArray(values)) {
|
|
2127
|
+
const executeInsertMany = async (columns, selectOptions) => {
|
|
2128
|
+
const mergedOptions = mergeOptions(options, selectOptions);
|
|
2129
|
+
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
2130
|
+
const payload = {
|
|
1093
2131
|
table_name: resolvedTableName,
|
|
1094
2132
|
insert_body: asAthenaJsonObjectArray(values)
|
|
1095
2133
|
};
|
|
@@ -1241,6 +2279,7 @@ function createClientFromConfig(config) {
|
|
|
1241
2279
|
backend: config.backend,
|
|
1242
2280
|
headers: config.headers
|
|
1243
2281
|
});
|
|
2282
|
+
const auth = createAuthClient(config.auth);
|
|
1244
2283
|
return {
|
|
1245
2284
|
from(table) {
|
|
1246
2285
|
return createTableBuilder(table, gateway);
|
|
@@ -1257,7 +2296,8 @@ function createClientFromConfig(config) {
|
|
|
1257
2296
|
gateway
|
|
1258
2297
|
);
|
|
1259
2298
|
},
|
|
1260
|
-
query: createQueryBuilder(gateway)
|
|
2299
|
+
query: createQueryBuilder(gateway),
|
|
2300
|
+
auth: auth.auth
|
|
1261
2301
|
};
|
|
1262
2302
|
}
|
|
1263
2303
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
@@ -1331,7 +2371,11 @@ function createClient(url, apiKey, options) {
|
|
|
1331
2371
|
const b = AthenaClient.builder().url(url).key(apiKey).backend(toBackendConfig(options?.backend));
|
|
1332
2372
|
if (options?.client) b.client(options.client);
|
|
1333
2373
|
if (options?.headers && Object.keys(options.headers).length > 0) b.headers(options.headers);
|
|
1334
|
-
|
|
2374
|
+
const client = b.build();
|
|
2375
|
+
if (options?.auth) {
|
|
2376
|
+
client.auth = createAuthClient(options.auth).auth;
|
|
2377
|
+
}
|
|
2378
|
+
return client;
|
|
1335
2379
|
}
|
|
1336
2380
|
|
|
1337
2381
|
// src/gateway/types.ts
|
|
@@ -1371,6 +2415,17 @@ var AthenaErrorCategory = {
|
|
|
1371
2415
|
Database: "database",
|
|
1372
2416
|
Unknown: "unknown"
|
|
1373
2417
|
};
|
|
2418
|
+
function parseBooleanFlag(rawValue, fallback) {
|
|
2419
|
+
if (!rawValue) return fallback;
|
|
2420
|
+
const normalized = rawValue.trim().toLowerCase();
|
|
2421
|
+
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
|
|
2422
|
+
return true;
|
|
2423
|
+
}
|
|
2424
|
+
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
|
|
2425
|
+
return false;
|
|
2426
|
+
}
|
|
2427
|
+
return fallback;
|
|
2428
|
+
}
|
|
1374
2429
|
var AthenaError = class extends Error {
|
|
1375
2430
|
code;
|
|
1376
2431
|
kind;
|
|
@@ -1393,7 +2448,7 @@ var AthenaError = class extends Error {
|
|
|
1393
2448
|
this.raw = input.raw;
|
|
1394
2449
|
}
|
|
1395
2450
|
};
|
|
1396
|
-
function
|
|
2451
|
+
function isRecord3(value) {
|
|
1397
2452
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1398
2453
|
}
|
|
1399
2454
|
function safeStringify(value) {
|
|
@@ -1410,7 +2465,7 @@ function contextHint(context) {
|
|
|
1410
2465
|
return `Identity: ${identity}`;
|
|
1411
2466
|
}
|
|
1412
2467
|
function isAthenaResultLike(value) {
|
|
1413
|
-
return
|
|
2468
|
+
return isRecord3(value) && "status" in value && "error" in value && "data" in value && typeof value.status === "number";
|
|
1414
2469
|
}
|
|
1415
2470
|
function operationFromDetails(details) {
|
|
1416
2471
|
if (!details?.endpoint) return void 0;
|
|
@@ -1576,7 +2631,7 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
1576
2631
|
};
|
|
1577
2632
|
}
|
|
1578
2633
|
if (resultOrError instanceof Error) {
|
|
1579
|
-
const maybeStatus =
|
|
2634
|
+
const maybeStatus = isRecord3(resultOrError) && typeof resultOrError.status === "number" ? resultOrError.status : void 0;
|
|
1580
2635
|
const kind2 = classifyKind(maybeStatus, void 0, resultOrError.message);
|
|
1581
2636
|
return {
|
|
1582
2637
|
kind: kind2,
|
|
@@ -2318,7 +3373,7 @@ function resolveNullishValue(mode) {
|
|
|
2318
3373
|
if (mode === "null") return null;
|
|
2319
3374
|
return "";
|
|
2320
3375
|
}
|
|
2321
|
-
function
|
|
3376
|
+
function isRecord4(value) {
|
|
2322
3377
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2323
3378
|
}
|
|
2324
3379
|
function isNullableColumn(model, key) {
|
|
@@ -2327,7 +3382,7 @@ function isNullableColumn(model, key) {
|
|
|
2327
3382
|
}
|
|
2328
3383
|
function toModelFormDefaults(model, values, options) {
|
|
2329
3384
|
const source = values;
|
|
2330
|
-
if (!
|
|
3385
|
+
if (!isRecord4(source)) {
|
|
2331
3386
|
return {};
|
|
2332
3387
|
}
|
|
2333
3388
|
const mode = options?.nullishMode ?? "empty-string";
|
|
@@ -2432,6 +3487,39 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
2432
3487
|
postgresGatewayIntrospection: false,
|
|
2433
3488
|
scyllaProviderContracts: true
|
|
2434
3489
|
};
|
|
3490
|
+
function normalizeBooleanFlag(rawValue, fallback) {
|
|
3491
|
+
if (typeof rawValue === "boolean") {
|
|
3492
|
+
return rawValue;
|
|
3493
|
+
}
|
|
3494
|
+
if (typeof rawValue === "string") {
|
|
3495
|
+
return parseBooleanFlag(rawValue, fallback);
|
|
3496
|
+
}
|
|
3497
|
+
return fallback;
|
|
3498
|
+
}
|
|
3499
|
+
function normalizeFeatureFlags(input) {
|
|
3500
|
+
return {
|
|
3501
|
+
emitRelations: normalizeBooleanFlag(
|
|
3502
|
+
input?.emitRelations,
|
|
3503
|
+
DEFAULT_FEATURES.emitRelations
|
|
3504
|
+
),
|
|
3505
|
+
emitRegistry: normalizeBooleanFlag(
|
|
3506
|
+
input?.emitRegistry,
|
|
3507
|
+
DEFAULT_FEATURES.emitRegistry
|
|
3508
|
+
)
|
|
3509
|
+
};
|
|
3510
|
+
}
|
|
3511
|
+
function normalizeExperimentalFlags(input) {
|
|
3512
|
+
return {
|
|
3513
|
+
postgresGatewayIntrospection: normalizeBooleanFlag(
|
|
3514
|
+
input?.postgresGatewayIntrospection,
|
|
3515
|
+
DEFAULT_EXPERIMENTAL_FLAGS.postgresGatewayIntrospection
|
|
3516
|
+
),
|
|
3517
|
+
scyllaProviderContracts: normalizeBooleanFlag(
|
|
3518
|
+
input?.scyllaProviderContracts,
|
|
3519
|
+
DEFAULT_EXPERIMENTAL_FLAGS.scyllaProviderContracts
|
|
3520
|
+
)
|
|
3521
|
+
};
|
|
3522
|
+
}
|
|
2435
3523
|
function normalizeOutputConfig(output) {
|
|
2436
3524
|
return {
|
|
2437
3525
|
targets: {
|
|
@@ -2467,14 +3555,8 @@ function normalizeGeneratorConfig(input) {
|
|
|
2467
3555
|
...DEFAULT_NAMING,
|
|
2468
3556
|
...input.naming ?? {}
|
|
2469
3557
|
},
|
|
2470
|
-
features:
|
|
2471
|
-
|
|
2472
|
-
...input.features ?? {}
|
|
2473
|
-
},
|
|
2474
|
-
experimental: {
|
|
2475
|
-
...DEFAULT_EXPERIMENTAL_FLAGS,
|
|
2476
|
-
...input.experimental ?? {}
|
|
2477
|
-
}
|
|
3558
|
+
features: normalizeFeatureFlags(input.features),
|
|
3559
|
+
experimental: normalizeExperimentalFlags(input.experimental)
|
|
2478
3560
|
};
|
|
2479
3561
|
}
|
|
2480
3562
|
function defineGeneratorConfig(config) {
|
|
@@ -3223,497 +4305,6 @@ async function runSchemaGenerator(options = {}) {
|
|
|
3223
4305
|
};
|
|
3224
4306
|
}
|
|
3225
4307
|
|
|
3226
|
-
// src/auth/client.ts
|
|
3227
|
-
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
3228
|
-
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
3229
|
-
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
3230
|
-
var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
|
|
3231
|
-
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
3232
|
-
function normalizeBaseUrl(baseUrl) {
|
|
3233
|
-
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
3234
|
-
}
|
|
3235
|
-
function isRecord4(value) {
|
|
3236
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3237
|
-
}
|
|
3238
|
-
function normalizeHeaderValue2(value) {
|
|
3239
|
-
return value ? value : void 0;
|
|
3240
|
-
}
|
|
3241
|
-
function parseResponseBody2(rawText, contentType) {
|
|
3242
|
-
if (!rawText) {
|
|
3243
|
-
return { parsed: null, parseFailed: false };
|
|
3244
|
-
}
|
|
3245
|
-
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
3246
|
-
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
3247
|
-
if (!looksJson) {
|
|
3248
|
-
return { parsed: rawText, parseFailed: false };
|
|
3249
|
-
}
|
|
3250
|
-
try {
|
|
3251
|
-
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
3252
|
-
} catch {
|
|
3253
|
-
return { parsed: rawText, parseFailed: true };
|
|
3254
|
-
}
|
|
3255
|
-
}
|
|
3256
|
-
function resolveRequestId2(headers) {
|
|
3257
|
-
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
3258
|
-
}
|
|
3259
|
-
function resolveErrorMessage2(payload, fallback) {
|
|
3260
|
-
if (isRecord4(payload)) {
|
|
3261
|
-
const messageCandidates = [payload.error, payload.message, payload.details];
|
|
3262
|
-
for (const candidate of messageCandidates) {
|
|
3263
|
-
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
3264
|
-
return candidate.trim();
|
|
3265
|
-
}
|
|
3266
|
-
}
|
|
3267
|
-
}
|
|
3268
|
-
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
3269
|
-
return payload.trim();
|
|
3270
|
-
}
|
|
3271
|
-
return fallback;
|
|
3272
|
-
}
|
|
3273
|
-
function toErrorDetails(input) {
|
|
3274
|
-
return {
|
|
3275
|
-
code: input.code,
|
|
3276
|
-
message: input.message,
|
|
3277
|
-
status: input.status,
|
|
3278
|
-
endpoint: input.endpoint,
|
|
3279
|
-
method: input.method,
|
|
3280
|
-
requestId: input.requestId,
|
|
3281
|
-
hint: input.hint,
|
|
3282
|
-
cause: input.cause
|
|
3283
|
-
};
|
|
3284
|
-
}
|
|
3285
|
-
function mergeCallOptions(base, override) {
|
|
3286
|
-
if (!base && !override) return void 0;
|
|
3287
|
-
return {
|
|
3288
|
-
...base,
|
|
3289
|
-
...override,
|
|
3290
|
-
headers: {
|
|
3291
|
-
...base?.headers ?? {},
|
|
3292
|
-
...override?.headers ?? {}
|
|
3293
|
-
}
|
|
3294
|
-
};
|
|
3295
|
-
}
|
|
3296
|
-
function extractFetchOptions(input) {
|
|
3297
|
-
if (!input) {
|
|
3298
|
-
return {
|
|
3299
|
-
payload: void 0,
|
|
3300
|
-
fetchOptions: void 0
|
|
3301
|
-
};
|
|
3302
|
-
}
|
|
3303
|
-
const { fetchOptions, ...rest } = input;
|
|
3304
|
-
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
3305
|
-
return {
|
|
3306
|
-
payload: hasPayloadKeys ? rest : void 0,
|
|
3307
|
-
fetchOptions
|
|
3308
|
-
};
|
|
3309
|
-
}
|
|
3310
|
-
function buildHeaders2(config, options) {
|
|
3311
|
-
const headers = {
|
|
3312
|
-
"Content-Type": "application/json",
|
|
3313
|
-
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
3314
|
-
};
|
|
3315
|
-
const apiKey = options?.apiKey ?? config.apiKey;
|
|
3316
|
-
if (apiKey) {
|
|
3317
|
-
headers.apikey = apiKey;
|
|
3318
|
-
headers["x-api-key"] = apiKey;
|
|
3319
|
-
}
|
|
3320
|
-
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
3321
|
-
if (bearerToken) {
|
|
3322
|
-
headers.Authorization = `Bearer ${bearerToken}`;
|
|
3323
|
-
}
|
|
3324
|
-
const mergedExtraHeaders = {
|
|
3325
|
-
...config.headers ?? {},
|
|
3326
|
-
...options?.headers ?? {}
|
|
3327
|
-
};
|
|
3328
|
-
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
3329
|
-
const normalized = normalizeHeaderValue2(value);
|
|
3330
|
-
if (normalized) {
|
|
3331
|
-
headers[key] = normalized;
|
|
3332
|
-
}
|
|
3333
|
-
});
|
|
3334
|
-
return headers;
|
|
3335
|
-
}
|
|
3336
|
-
function appendQueryParam(searchParams, key, value) {
|
|
3337
|
-
if (value === void 0 || value === null) return;
|
|
3338
|
-
if (Array.isArray(value)) {
|
|
3339
|
-
value.forEach((item) => {
|
|
3340
|
-
searchParams.append(key, String(item));
|
|
3341
|
-
});
|
|
3342
|
-
return;
|
|
3343
|
-
}
|
|
3344
|
-
searchParams.append(key, String(value));
|
|
3345
|
-
}
|
|
3346
|
-
function buildRequestUrl(baseUrl, endpoint, query) {
|
|
3347
|
-
const url = `${baseUrl}${endpoint}`;
|
|
3348
|
-
if (!query || Object.keys(query).length === 0) return url;
|
|
3349
|
-
const searchParams = new URLSearchParams();
|
|
3350
|
-
Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
|
|
3351
|
-
const queryText = searchParams.toString();
|
|
3352
|
-
return queryText ? `${url}?${queryText}` : url;
|
|
3353
|
-
}
|
|
3354
|
-
function inferDefaultMethod(endpoint) {
|
|
3355
|
-
if (endpoint.startsWith("/reset-password/")) {
|
|
3356
|
-
return "GET";
|
|
3357
|
-
}
|
|
3358
|
-
switch (endpoint) {
|
|
3359
|
-
case "/get-session":
|
|
3360
|
-
case "/list-sessions":
|
|
3361
|
-
case "/verify-email":
|
|
3362
|
-
case "/delete-user/callback":
|
|
3363
|
-
case "/list-accounts":
|
|
3364
|
-
case "/ok":
|
|
3365
|
-
case "/error":
|
|
3366
|
-
return "GET";
|
|
3367
|
-
default:
|
|
3368
|
-
return "POST";
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
async function callAuthEndpoint(config, context, body, query, options) {
|
|
3372
|
-
const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
3373
|
-
const url = buildRequestUrl(baseUrl, context.endpoint, query);
|
|
3374
|
-
const headers = buildHeaders2(config, options);
|
|
3375
|
-
const credentials = options?.credentials ?? config.credentials ?? "include";
|
|
3376
|
-
const requestInit = {
|
|
3377
|
-
method: context.method,
|
|
3378
|
-
headers,
|
|
3379
|
-
credentials,
|
|
3380
|
-
signal: options?.signal
|
|
3381
|
-
};
|
|
3382
|
-
if (context.method !== "GET") {
|
|
3383
|
-
requestInit.body = JSON.stringify(body ?? {});
|
|
3384
|
-
}
|
|
3385
|
-
const fetcher = config.fetch ?? globalThis.fetch;
|
|
3386
|
-
if (!fetcher) {
|
|
3387
|
-
const details = toErrorDetails({
|
|
3388
|
-
code: "UNKNOWN_ERROR",
|
|
3389
|
-
message: "No fetch implementation available for auth client",
|
|
3390
|
-
status: 0,
|
|
3391
|
-
endpoint: context.endpoint,
|
|
3392
|
-
method: context.method,
|
|
3393
|
-
hint: "Use Node 18+ or provide `fetch` in createAuthClient({ fetch })"
|
|
3394
|
-
});
|
|
3395
|
-
return {
|
|
3396
|
-
ok: false,
|
|
3397
|
-
status: 0,
|
|
3398
|
-
data: null,
|
|
3399
|
-
error: details.message,
|
|
3400
|
-
errorDetails: details,
|
|
3401
|
-
raw: null
|
|
3402
|
-
};
|
|
3403
|
-
}
|
|
3404
|
-
try {
|
|
3405
|
-
const response = await fetcher(url, requestInit);
|
|
3406
|
-
const rawText = await response.text();
|
|
3407
|
-
const requestId = resolveRequestId2(response.headers);
|
|
3408
|
-
const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
|
|
3409
|
-
if (parsedBody.parseFailed) {
|
|
3410
|
-
const details = toErrorDetails({
|
|
3411
|
-
code: "INVALID_JSON",
|
|
3412
|
-
message: "Auth server returned malformed JSON",
|
|
3413
|
-
status: response.status,
|
|
3414
|
-
endpoint: context.endpoint,
|
|
3415
|
-
method: context.method,
|
|
3416
|
-
requestId,
|
|
3417
|
-
hint: "Verify the auth endpoint response body is valid JSON.",
|
|
3418
|
-
cause: rawText.slice(0, 300)
|
|
3419
|
-
});
|
|
3420
|
-
return {
|
|
3421
|
-
ok: false,
|
|
3422
|
-
status: response.status,
|
|
3423
|
-
data: null,
|
|
3424
|
-
error: details.message,
|
|
3425
|
-
errorDetails: details,
|
|
3426
|
-
raw: parsedBody.parsed
|
|
3427
|
-
};
|
|
3428
|
-
}
|
|
3429
|
-
const parsed = parsedBody.parsed;
|
|
3430
|
-
if (!response.ok) {
|
|
3431
|
-
const details = toErrorDetails({
|
|
3432
|
-
code: "HTTP_ERROR",
|
|
3433
|
-
message: resolveErrorMessage2(
|
|
3434
|
-
parsed,
|
|
3435
|
-
`Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
|
|
3436
|
-
),
|
|
3437
|
-
status: response.status,
|
|
3438
|
-
endpoint: context.endpoint,
|
|
3439
|
-
method: context.method,
|
|
3440
|
-
requestId
|
|
3441
|
-
});
|
|
3442
|
-
return {
|
|
3443
|
-
ok: false,
|
|
3444
|
-
status: response.status,
|
|
3445
|
-
data: null,
|
|
3446
|
-
error: details.message,
|
|
3447
|
-
errorDetails: details,
|
|
3448
|
-
raw: parsed
|
|
3449
|
-
};
|
|
3450
|
-
}
|
|
3451
|
-
return {
|
|
3452
|
-
ok: true,
|
|
3453
|
-
status: response.status,
|
|
3454
|
-
data: parsed ?? null,
|
|
3455
|
-
error: null,
|
|
3456
|
-
errorDetails: null,
|
|
3457
|
-
raw: parsed
|
|
3458
|
-
};
|
|
3459
|
-
} catch (callError) {
|
|
3460
|
-
const message = callError instanceof Error ? callError.message : String(callError);
|
|
3461
|
-
const details = toErrorDetails({
|
|
3462
|
-
code: "NETWORK_ERROR",
|
|
3463
|
-
message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
|
|
3464
|
-
status: 0,
|
|
3465
|
-
endpoint: context.endpoint,
|
|
3466
|
-
method: context.method,
|
|
3467
|
-
cause: message,
|
|
3468
|
-
hint: "Check auth server URL, DNS, and network reachability."
|
|
3469
|
-
});
|
|
3470
|
-
return {
|
|
3471
|
-
ok: false,
|
|
3472
|
-
status: 0,
|
|
3473
|
-
data: null,
|
|
3474
|
-
error: details.message,
|
|
3475
|
-
errorDetails: details,
|
|
3476
|
-
raw: null
|
|
3477
|
-
};
|
|
3478
|
-
}
|
|
3479
|
-
}
|
|
3480
|
-
function executePostWithCompatibleInput(config, context, input, options) {
|
|
3481
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3482
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3483
|
-
return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
|
|
3484
|
-
}
|
|
3485
|
-
function executePostWithOptionalInput(config, context, input, options) {
|
|
3486
|
-
const { fetchOptions } = extractFetchOptions(input);
|
|
3487
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3488
|
-
return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
|
|
3489
|
-
}
|
|
3490
|
-
function executeGetWithCompatibleInput(config, context, input, options) {
|
|
3491
|
-
const { fetchOptions } = extractFetchOptions(input);
|
|
3492
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3493
|
-
return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
|
|
3494
|
-
}
|
|
3495
|
-
function createAuthClient(config = {}) {
|
|
3496
|
-
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
3497
|
-
const resolvedConfig = {
|
|
3498
|
-
...config,
|
|
3499
|
-
baseUrl: normalizedBaseUrl
|
|
3500
|
-
};
|
|
3501
|
-
const request = (input, options) => {
|
|
3502
|
-
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
3503
|
-
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
3504
|
-
return callAuthEndpoint(
|
|
3505
|
-
resolvedConfig,
|
|
3506
|
-
{ endpoint: input.endpoint, method },
|
|
3507
|
-
input.body,
|
|
3508
|
-
input.query,
|
|
3509
|
-
mergedOptions
|
|
3510
|
-
);
|
|
3511
|
-
};
|
|
3512
|
-
const signOut = (input, options) => executePostWithOptionalInput(
|
|
3513
|
-
resolvedConfig,
|
|
3514
|
-
{ endpoint: "/sign-out", method: "POST" },
|
|
3515
|
-
input,
|
|
3516
|
-
options
|
|
3517
|
-
);
|
|
3518
|
-
const revokeSessions = (input, options) => executePostWithOptionalInput(
|
|
3519
|
-
resolvedConfig,
|
|
3520
|
-
{ endpoint: "/revoke-sessions", method: "POST" },
|
|
3521
|
-
input,
|
|
3522
|
-
options
|
|
3523
|
-
);
|
|
3524
|
-
const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
|
|
3525
|
-
resolvedConfig,
|
|
3526
|
-
{ endpoint: "/revoke-other-sessions", method: "POST" },
|
|
3527
|
-
input,
|
|
3528
|
-
options
|
|
3529
|
-
);
|
|
3530
|
-
const revokeSession = (input, options) => executePostWithCompatibleInput(
|
|
3531
|
-
resolvedConfig,
|
|
3532
|
-
{ endpoint: "/revoke-session", method: "POST" },
|
|
3533
|
-
input,
|
|
3534
|
-
options
|
|
3535
|
-
);
|
|
3536
|
-
const deleteUser = (input, options) => {
|
|
3537
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3538
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3539
|
-
return callAuthEndpoint(
|
|
3540
|
-
resolvedConfig,
|
|
3541
|
-
{ endpoint: "/delete-user", method: "POST" },
|
|
3542
|
-
payload ?? {},
|
|
3543
|
-
void 0,
|
|
3544
|
-
mergedOptions
|
|
3545
|
-
);
|
|
3546
|
-
};
|
|
3547
|
-
const deleteUserCallback = (input, options) => {
|
|
3548
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3549
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3550
|
-
const query = payload ?? {};
|
|
3551
|
-
return callAuthEndpoint(
|
|
3552
|
-
resolvedConfig,
|
|
3553
|
-
{ endpoint: "/delete-user/callback", method: "GET" },
|
|
3554
|
-
void 0,
|
|
3555
|
-
{
|
|
3556
|
-
token: query.token,
|
|
3557
|
-
callbackURL: query.callbackURL
|
|
3558
|
-
},
|
|
3559
|
-
mergedOptions
|
|
3560
|
-
);
|
|
3561
|
-
};
|
|
3562
|
-
const resolveResetPasswordToken = (input, options) => {
|
|
3563
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3564
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3565
|
-
const query = payload;
|
|
3566
|
-
const token = query?.token?.trim();
|
|
3567
|
-
if (!token) {
|
|
3568
|
-
throw new Error("resolveResetPasswordToken requires a non-empty token");
|
|
3569
|
-
}
|
|
3570
|
-
const endpoint = `/reset-password/${encodeURIComponent(token)}`;
|
|
3571
|
-
return callAuthEndpoint(
|
|
3572
|
-
resolvedConfig,
|
|
3573
|
-
{ endpoint, method: "GET" },
|
|
3574
|
-
void 0,
|
|
3575
|
-
query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
|
|
3576
|
-
mergedOptions
|
|
3577
|
-
);
|
|
3578
|
-
};
|
|
3579
|
-
return {
|
|
3580
|
-
baseUrl: normalizedBaseUrl,
|
|
3581
|
-
request,
|
|
3582
|
-
signIn: {
|
|
3583
|
-
email: (input, options) => executePostWithCompatibleInput(
|
|
3584
|
-
resolvedConfig,
|
|
3585
|
-
{ endpoint: "/sign-in/email", method: "POST" },
|
|
3586
|
-
input,
|
|
3587
|
-
options
|
|
3588
|
-
),
|
|
3589
|
-
username: (input, options) => executePostWithCompatibleInput(
|
|
3590
|
-
resolvedConfig,
|
|
3591
|
-
{ endpoint: "/sign-in/username", method: "POST" },
|
|
3592
|
-
input,
|
|
3593
|
-
options
|
|
3594
|
-
),
|
|
3595
|
-
social: (input, options) => executePostWithCompatibleInput(
|
|
3596
|
-
resolvedConfig,
|
|
3597
|
-
{ endpoint: "/sign-in/social", method: "POST" },
|
|
3598
|
-
input,
|
|
3599
|
-
options
|
|
3600
|
-
)
|
|
3601
|
-
},
|
|
3602
|
-
signUp: {
|
|
3603
|
-
email: (input, options) => executePostWithCompatibleInput(
|
|
3604
|
-
resolvedConfig,
|
|
3605
|
-
{ endpoint: "/sign-up/email", method: "POST" },
|
|
3606
|
-
input,
|
|
3607
|
-
options
|
|
3608
|
-
)
|
|
3609
|
-
},
|
|
3610
|
-
signOut,
|
|
3611
|
-
logout: signOut,
|
|
3612
|
-
getSession: (input, options) => executeGetWithCompatibleInput(
|
|
3613
|
-
resolvedConfig,
|
|
3614
|
-
{ endpoint: "/get-session", method: "GET" },
|
|
3615
|
-
input,
|
|
3616
|
-
options
|
|
3617
|
-
),
|
|
3618
|
-
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
3619
|
-
resolvedConfig,
|
|
3620
|
-
{ endpoint: "/list-sessions", method: "GET" },
|
|
3621
|
-
input,
|
|
3622
|
-
options
|
|
3623
|
-
),
|
|
3624
|
-
revokeSession,
|
|
3625
|
-
clearSession: revokeSession,
|
|
3626
|
-
revokeSessions,
|
|
3627
|
-
clearSessions: revokeSessions,
|
|
3628
|
-
revokeOtherSessions,
|
|
3629
|
-
clearOtherSessions: revokeOtherSessions,
|
|
3630
|
-
forgetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3631
|
-
resolvedConfig,
|
|
3632
|
-
{ endpoint: "/forget-password", method: "POST" },
|
|
3633
|
-
input,
|
|
3634
|
-
options
|
|
3635
|
-
),
|
|
3636
|
-
resetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3637
|
-
resolvedConfig,
|
|
3638
|
-
{ endpoint: "/reset-password", method: "POST" },
|
|
3639
|
-
input,
|
|
3640
|
-
options
|
|
3641
|
-
),
|
|
3642
|
-
resolveResetPasswordToken,
|
|
3643
|
-
verifyEmail: (input, options) => {
|
|
3644
|
-
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3645
|
-
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3646
|
-
const query = payload;
|
|
3647
|
-
return callAuthEndpoint(
|
|
3648
|
-
resolvedConfig,
|
|
3649
|
-
{ endpoint: "/verify-email", method: "GET" },
|
|
3650
|
-
void 0,
|
|
3651
|
-
query ? {
|
|
3652
|
-
token: query.token,
|
|
3653
|
-
callbackURL: query.callbackURL
|
|
3654
|
-
} : void 0,
|
|
3655
|
-
mergedOptions
|
|
3656
|
-
);
|
|
3657
|
-
},
|
|
3658
|
-
sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
|
|
3659
|
-
resolvedConfig,
|
|
3660
|
-
{ endpoint: "/send-verification-email", method: "POST" },
|
|
3661
|
-
input,
|
|
3662
|
-
options
|
|
3663
|
-
),
|
|
3664
|
-
changeEmail: (input, options) => executePostWithCompatibleInput(
|
|
3665
|
-
resolvedConfig,
|
|
3666
|
-
{ endpoint: "/change-email", method: "POST" },
|
|
3667
|
-
input,
|
|
3668
|
-
options
|
|
3669
|
-
),
|
|
3670
|
-
changePassword: (input, options) => executePostWithCompatibleInput(
|
|
3671
|
-
resolvedConfig,
|
|
3672
|
-
{ endpoint: "/change-password", method: "POST" },
|
|
3673
|
-
input,
|
|
3674
|
-
options
|
|
3675
|
-
),
|
|
3676
|
-
updateUser: (input, options) => executePostWithCompatibleInput(
|
|
3677
|
-
resolvedConfig,
|
|
3678
|
-
{ endpoint: "/update-user", method: "POST" },
|
|
3679
|
-
input,
|
|
3680
|
-
options
|
|
3681
|
-
),
|
|
3682
|
-
deleteUser,
|
|
3683
|
-
deleteUserCallback,
|
|
3684
|
-
linkSocial: (input, options) => executePostWithCompatibleInput(
|
|
3685
|
-
resolvedConfig,
|
|
3686
|
-
{ endpoint: "/link-social", method: "POST" },
|
|
3687
|
-
input,
|
|
3688
|
-
options
|
|
3689
|
-
),
|
|
3690
|
-
listAccounts: (input, options) => executeGetWithCompatibleInput(
|
|
3691
|
-
resolvedConfig,
|
|
3692
|
-
{ endpoint: "/list-accounts", method: "GET" },
|
|
3693
|
-
input,
|
|
3694
|
-
options
|
|
3695
|
-
),
|
|
3696
|
-
unlinkAccount: (input, options) => executePostWithCompatibleInput(
|
|
3697
|
-
resolvedConfig,
|
|
3698
|
-
{ endpoint: "/unlink-account", method: "POST" },
|
|
3699
|
-
input,
|
|
3700
|
-
options
|
|
3701
|
-
),
|
|
3702
|
-
refreshToken: (input, options) => executePostWithCompatibleInput(
|
|
3703
|
-
resolvedConfig,
|
|
3704
|
-
{ endpoint: "/refresh-token", method: "POST" },
|
|
3705
|
-
input,
|
|
3706
|
-
options
|
|
3707
|
-
),
|
|
3708
|
-
getAccessToken: (input, options) => executePostWithCompatibleInput(
|
|
3709
|
-
resolvedConfig,
|
|
3710
|
-
{ endpoint: "/get-access-token", method: "POST" },
|
|
3711
|
-
input,
|
|
3712
|
-
options
|
|
3713
|
-
)
|
|
3714
|
-
};
|
|
3715
|
-
}
|
|
3716
|
-
|
|
3717
4308
|
exports.AthenaClient = AthenaClient;
|
|
3718
4309
|
exports.AthenaError = AthenaError;
|
|
3719
4310
|
exports.AthenaErrorCategory = AthenaErrorCategory;
|
|
@@ -3743,6 +4334,7 @@ exports.loadGeneratorConfig = loadGeneratorConfig;
|
|
|
3743
4334
|
exports.normalizeAthenaError = normalizeAthenaError;
|
|
3744
4335
|
exports.normalizeGeneratorConfig = normalizeGeneratorConfig;
|
|
3745
4336
|
exports.normalizeSchemaSelection = normalizeSchemaSelection;
|
|
4337
|
+
exports.parseBooleanFlag = parseBooleanFlag;
|
|
3746
4338
|
exports.requireAffected = requireAffected;
|
|
3747
4339
|
exports.requireSuccess = requireSuccess;
|
|
3748
4340
|
exports.resolveGeneratorProvider = resolveGeneratorProvider;
|