@omnara/sdk 0.1.43 → 0.1.44
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 +98 -0
- package/dist/browser.js +22 -13
- package/dist/browser.js.map +1 -1
- package/dist/{chunk-WM4BXMLD.js → chunk-BUM22BVJ.js} +194 -11
- package/dist/chunk-BUM22BVJ.js.map +1 -0
- package/dist/chunk-HFFDN2XF.js +1604 -0
- package/dist/chunk-HFFDN2XF.js.map +1 -0
- package/dist/{chunk-PPREVIWL.js → chunk-WVD6U2JJ.js} +217 -820
- package/dist/chunk-WVD6U2JJ.js.map +1 -0
- package/dist/index.d.ts +104 -13
- package/dist/index.js +344 -138
- package/dist/index.js.map +1 -1
- package/dist/{sdk.gen-Bp5seXss.d.ts → sdk.gen-BG9nJQHq.d.ts} +1600 -515
- package/dist/tanstack.d.ts +426 -2206
- package/dist/tanstack.js +305 -32
- package/dist/tanstack.js.map +1 -1
- package/dist/zod.d.ts +1 -1
- package/dist/{zod.gen-ArHIe1NX.d.ts → zod.gen-DMsuMMrB.d.ts} +850 -9
- package/dist/zod.js +61 -1
- package/package.json +8 -5
- package/dist/chunk-6YKVAVCM.js +0 -73
- package/dist/chunk-6YKVAVCM.js.map +0 -1
- package/dist/chunk-NZCMY3BC.js +0 -50
- package/dist/chunk-NZCMY3BC.js.map +0 -1
- package/dist/chunk-PPREVIWL.js.map +0 -1
- package/dist/chunk-WM4BXMLD.js.map +0 -1
package/dist/zod.js
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
zActorProvider,
|
|
7
7
|
zAgent,
|
|
8
8
|
zAgentActivity,
|
|
9
|
+
zAgentActivityState,
|
|
10
|
+
zAgentActivityStateFilter,
|
|
9
11
|
zAgentConfig,
|
|
10
12
|
zAgentConfigDefinition,
|
|
11
13
|
zAgentConfigDefinitionGitCredentials,
|
|
@@ -390,6 +392,8 @@ import {
|
|
|
390
392
|
zGetArtifactContentResponse,
|
|
391
393
|
zGetArtifactPath,
|
|
392
394
|
zGetArtifactResponse,
|
|
395
|
+
zGetConfiguredModelPath,
|
|
396
|
+
zGetConfiguredModelResponse,
|
|
393
397
|
zGetCronTriggerPath,
|
|
394
398
|
zGetCronTriggerResponse,
|
|
395
399
|
zGetCurrentUserResponse,
|
|
@@ -398,8 +402,12 @@ import {
|
|
|
398
402
|
zGetDaemonSkillArchivePath,
|
|
399
403
|
zGetDaemonSkillArchiveQuery,
|
|
400
404
|
zGetDaemonSkillArchiveResponse,
|
|
405
|
+
zGetEventWebhookPath,
|
|
406
|
+
zGetEventWebhookResponse,
|
|
401
407
|
zGetIntegrationPath,
|
|
402
408
|
zGetIntegrationResponse,
|
|
409
|
+
zGetIntegrationSubscriptionPath,
|
|
410
|
+
zGetIntegrationSubscriptionResponse,
|
|
403
411
|
zGetMachinePath,
|
|
404
412
|
zGetMachinePoolPath,
|
|
405
413
|
zGetMachinePoolResponse,
|
|
@@ -422,15 +430,27 @@ import {
|
|
|
422
430
|
zGetOrgUsageTimeseriesResponse,
|
|
423
431
|
zGetProjectAvailableSecretPath,
|
|
424
432
|
zGetProjectAvailableSecretResponse,
|
|
433
|
+
zGetProjectMachineGrantPath,
|
|
434
|
+
zGetProjectMachineGrantResponse,
|
|
425
435
|
zGetProjectMachinePoolGrantPath,
|
|
426
436
|
zGetProjectMachinePoolGrantResponse,
|
|
437
|
+
zGetProjectModelGrantPath,
|
|
438
|
+
zGetProjectModelGrantResponse,
|
|
439
|
+
zGetProjectPath,
|
|
440
|
+
zGetProjectResponse,
|
|
427
441
|
zGetProjectUsagePath,
|
|
428
442
|
zGetProjectUsageQuery,
|
|
429
443
|
zGetProjectUsageResponse,
|
|
444
|
+
zGetSecretGrantPath,
|
|
445
|
+
zGetSecretGrantResponse,
|
|
430
446
|
zGetSecretPath,
|
|
431
447
|
zGetSecretResponse,
|
|
448
|
+
zGetSkillGrantPath,
|
|
449
|
+
zGetSkillGrantResponse,
|
|
432
450
|
zGetSkillPath,
|
|
433
451
|
zGetSkillResponse,
|
|
452
|
+
zGetToolCallPath,
|
|
453
|
+
zGetToolCallResponse,
|
|
434
454
|
zGetToolCatalogResponse,
|
|
435
455
|
zGitHubAppCredentialsSecretMaterial,
|
|
436
456
|
zGitHubInstallations,
|
|
@@ -591,6 +611,9 @@ import {
|
|
|
591
611
|
zListProjectAvailableSkillsPath,
|
|
592
612
|
zListProjectAvailableSkillsQuery,
|
|
593
613
|
zListProjectAvailableSkillsResponse,
|
|
614
|
+
zListProjectInteractionsPath,
|
|
615
|
+
zListProjectInteractionsQuery,
|
|
616
|
+
zListProjectInteractionsResponse,
|
|
594
617
|
zListProjectMachineGrantsPath,
|
|
595
618
|
zListProjectMachineGrantsQuery,
|
|
596
619
|
zListProjectMachineGrantsResponse,
|
|
@@ -606,6 +629,9 @@ import {
|
|
|
606
629
|
zListProjectModelGrantsResponse2,
|
|
607
630
|
zListProjectSecretAccessesResponse,
|
|
608
631
|
zListProjectSkillAccessesResponse,
|
|
632
|
+
zListProjectToolCallsPath,
|
|
633
|
+
zListProjectToolCallsQuery,
|
|
634
|
+
zListProjectToolCallsResponse,
|
|
609
635
|
zListProjectsResponse,
|
|
610
636
|
zListQueuedBacklogInputsPath,
|
|
611
637
|
zListQueuedBacklogInputsQuery,
|
|
@@ -961,6 +987,7 @@ import {
|
|
|
961
987
|
zUpdateOrgMemberPath,
|
|
962
988
|
zUpdateOrgMemberRequest,
|
|
963
989
|
zUpdateOrgMemberResponse,
|
|
990
|
+
zUpdateProjectBody,
|
|
964
991
|
zUpdateProjectMachinePoolGrantBody,
|
|
965
992
|
zUpdateProjectMachinePoolGrantPath,
|
|
966
993
|
zUpdateProjectMachinePoolGrantRequest,
|
|
@@ -969,6 +996,9 @@ import {
|
|
|
969
996
|
zUpdateProjectModelGrantPath,
|
|
970
997
|
zUpdateProjectModelGrantRequest,
|
|
971
998
|
zUpdateProjectModelGrantResponse,
|
|
999
|
+
zUpdateProjectPath,
|
|
1000
|
+
zUpdateProjectRequest,
|
|
1001
|
+
zUpdateProjectResponse,
|
|
972
1002
|
zUpdateSecretBody,
|
|
973
1003
|
zUpdateSecretPath,
|
|
974
1004
|
zUpdateSecretRequest,
|
|
@@ -1007,7 +1037,7 @@ import {
|
|
|
1007
1037
|
zWriteMemoryFilePath,
|
|
1008
1038
|
zWriteMemoryFileQuery,
|
|
1009
1039
|
zWriteMemoryFileResponse
|
|
1010
|
-
} from "./chunk-
|
|
1040
|
+
} from "./chunk-BUM22BVJ.js";
|
|
1011
1041
|
export {
|
|
1012
1042
|
zAcceptInvitationPath,
|
|
1013
1043
|
zAcceptInvitationResponse,
|
|
@@ -1016,6 +1046,8 @@ export {
|
|
|
1016
1046
|
zActorProvider,
|
|
1017
1047
|
zAgent,
|
|
1018
1048
|
zAgentActivity,
|
|
1049
|
+
zAgentActivityState,
|
|
1050
|
+
zAgentActivityStateFilter,
|
|
1019
1051
|
zAgentConfig,
|
|
1020
1052
|
zAgentConfigDefinition,
|
|
1021
1053
|
zAgentConfigDefinitionGitCredentials,
|
|
@@ -1400,6 +1432,8 @@ export {
|
|
|
1400
1432
|
zGetArtifactContentResponse,
|
|
1401
1433
|
zGetArtifactPath,
|
|
1402
1434
|
zGetArtifactResponse,
|
|
1435
|
+
zGetConfiguredModelPath,
|
|
1436
|
+
zGetConfiguredModelResponse,
|
|
1403
1437
|
zGetCronTriggerPath,
|
|
1404
1438
|
zGetCronTriggerResponse,
|
|
1405
1439
|
zGetCurrentUserResponse,
|
|
@@ -1408,8 +1442,12 @@ export {
|
|
|
1408
1442
|
zGetDaemonSkillArchivePath,
|
|
1409
1443
|
zGetDaemonSkillArchiveQuery,
|
|
1410
1444
|
zGetDaemonSkillArchiveResponse,
|
|
1445
|
+
zGetEventWebhookPath,
|
|
1446
|
+
zGetEventWebhookResponse,
|
|
1411
1447
|
zGetIntegrationPath,
|
|
1412
1448
|
zGetIntegrationResponse,
|
|
1449
|
+
zGetIntegrationSubscriptionPath,
|
|
1450
|
+
zGetIntegrationSubscriptionResponse,
|
|
1413
1451
|
zGetMachinePath,
|
|
1414
1452
|
zGetMachinePoolPath,
|
|
1415
1453
|
zGetMachinePoolResponse,
|
|
@@ -1432,15 +1470,27 @@ export {
|
|
|
1432
1470
|
zGetOrgUsageTimeseriesResponse,
|
|
1433
1471
|
zGetProjectAvailableSecretPath,
|
|
1434
1472
|
zGetProjectAvailableSecretResponse,
|
|
1473
|
+
zGetProjectMachineGrantPath,
|
|
1474
|
+
zGetProjectMachineGrantResponse,
|
|
1435
1475
|
zGetProjectMachinePoolGrantPath,
|
|
1436
1476
|
zGetProjectMachinePoolGrantResponse,
|
|
1477
|
+
zGetProjectModelGrantPath,
|
|
1478
|
+
zGetProjectModelGrantResponse,
|
|
1479
|
+
zGetProjectPath,
|
|
1480
|
+
zGetProjectResponse,
|
|
1437
1481
|
zGetProjectUsagePath,
|
|
1438
1482
|
zGetProjectUsageQuery,
|
|
1439
1483
|
zGetProjectUsageResponse,
|
|
1484
|
+
zGetSecretGrantPath,
|
|
1485
|
+
zGetSecretGrantResponse,
|
|
1440
1486
|
zGetSecretPath,
|
|
1441
1487
|
zGetSecretResponse,
|
|
1488
|
+
zGetSkillGrantPath,
|
|
1489
|
+
zGetSkillGrantResponse,
|
|
1442
1490
|
zGetSkillPath,
|
|
1443
1491
|
zGetSkillResponse,
|
|
1492
|
+
zGetToolCallPath,
|
|
1493
|
+
zGetToolCallResponse,
|
|
1444
1494
|
zGetToolCatalogResponse,
|
|
1445
1495
|
zGitHubAppCredentialsSecretMaterial,
|
|
1446
1496
|
zGitHubInstallations,
|
|
@@ -1601,6 +1651,9 @@ export {
|
|
|
1601
1651
|
zListProjectAvailableSkillsPath,
|
|
1602
1652
|
zListProjectAvailableSkillsQuery,
|
|
1603
1653
|
zListProjectAvailableSkillsResponse,
|
|
1654
|
+
zListProjectInteractionsPath,
|
|
1655
|
+
zListProjectInteractionsQuery,
|
|
1656
|
+
zListProjectInteractionsResponse,
|
|
1604
1657
|
zListProjectMachineGrantsPath,
|
|
1605
1658
|
zListProjectMachineGrantsQuery,
|
|
1606
1659
|
zListProjectMachineGrantsResponse,
|
|
@@ -1616,6 +1669,9 @@ export {
|
|
|
1616
1669
|
zListProjectModelGrantsResponse2,
|
|
1617
1670
|
zListProjectSecretAccessesResponse,
|
|
1618
1671
|
zListProjectSkillAccessesResponse,
|
|
1672
|
+
zListProjectToolCallsPath,
|
|
1673
|
+
zListProjectToolCallsQuery,
|
|
1674
|
+
zListProjectToolCallsResponse,
|
|
1619
1675
|
zListProjectsResponse,
|
|
1620
1676
|
zListQueuedBacklogInputsPath,
|
|
1621
1677
|
zListQueuedBacklogInputsQuery,
|
|
@@ -1971,6 +2027,7 @@ export {
|
|
|
1971
2027
|
zUpdateOrgMemberPath,
|
|
1972
2028
|
zUpdateOrgMemberRequest,
|
|
1973
2029
|
zUpdateOrgMemberResponse,
|
|
2030
|
+
zUpdateProjectBody,
|
|
1974
2031
|
zUpdateProjectMachinePoolGrantBody,
|
|
1975
2032
|
zUpdateProjectMachinePoolGrantPath,
|
|
1976
2033
|
zUpdateProjectMachinePoolGrantRequest,
|
|
@@ -1979,6 +2036,9 @@ export {
|
|
|
1979
2036
|
zUpdateProjectModelGrantPath,
|
|
1980
2037
|
zUpdateProjectModelGrantRequest,
|
|
1981
2038
|
zUpdateProjectModelGrantResponse,
|
|
2039
|
+
zUpdateProjectPath,
|
|
2040
|
+
zUpdateProjectRequest,
|
|
2041
|
+
zUpdateProjectResponse,
|
|
1982
2042
|
zUpdateSecretBody,
|
|
1983
2043
|
zUpdateSecretPath,
|
|
1984
2044
|
zUpdateSecretRequest,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnara/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"description": "TypeScript SDK for the Omnara API, with browser, TanStack Query, and Zod entry points",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -47,10 +47,11 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
+
"standardwebhooks": "1.1.1",
|
|
50
51
|
"zod": "^4.4.3"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"@tanstack/react-query": "^5.
|
|
54
|
+
"@tanstack/react-query": "^5.62.0"
|
|
54
55
|
},
|
|
55
56
|
"peerDependenciesMeta": {
|
|
56
57
|
"@tanstack/react-query": {
|
|
@@ -59,14 +60,16 @@
|
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@hey-api/openapi-ts": "0.99.0",
|
|
62
|
-
"@tanstack/react-query": "^5.
|
|
63
|
+
"@tanstack/react-query": "^5.101.0",
|
|
64
|
+
"@tanstack/react-query-minimum": "npm:@tanstack/react-query@5.62.0",
|
|
63
65
|
"tsup": "^9.0.0",
|
|
64
66
|
"typescript": "^5.6.0",
|
|
65
|
-
"vitest": "5.0.5"
|
|
67
|
+
"vitest": "5.0.5",
|
|
68
|
+
"yaml": "^2.9.0"
|
|
66
69
|
},
|
|
67
70
|
"scripts": {
|
|
68
71
|
"build": "tsup",
|
|
69
|
-
"generate:api": "openapi-ts && node scripts/relax-response-enums.mjs",
|
|
72
|
+
"generate:api": "openapi-ts && node scripts/relax-response-enums.mjs && node scripts/extend-client-config.mjs && node scripts/preserve-query-option-types.mjs && node scripts/generate-replay-contracts.mjs",
|
|
70
73
|
"test": "vitest run",
|
|
71
74
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
72
75
|
}
|
package/dist/chunk-6YKVAVCM.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
relaxedSchema
|
|
3
|
-
} from "./chunk-NZCMY3BC.js";
|
|
4
|
-
import {
|
|
5
|
-
zError
|
|
6
|
-
} from "./chunk-WM4BXMLD.js";
|
|
7
|
-
|
|
8
|
-
// src/json-body.ts
|
|
9
|
-
import * as z from "zod";
|
|
10
|
-
var zJsonBody = z.json();
|
|
11
|
-
var zJsonText = z.string().transform((text, ctx) => {
|
|
12
|
-
try {
|
|
13
|
-
const value = JSON.parse(text);
|
|
14
|
-
return value;
|
|
15
|
-
} catch (error) {
|
|
16
|
-
ctx.addIssue({ code: "custom", message: String(error), input: text, params: { cause: error } });
|
|
17
|
-
return z.NEVER;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// src/errors.ts
|
|
22
|
-
import * as z2 from "zod";
|
|
23
|
-
var zErrorBody = zJsonText.pipe(zJsonBody);
|
|
24
|
-
var zErrorResponse = relaxedSchema(
|
|
25
|
-
zError.partial({ code: true }).extend({ error_description: z2.string().optional() })
|
|
26
|
-
);
|
|
27
|
-
var ApiError = class _ApiError extends Error {
|
|
28
|
-
status;
|
|
29
|
-
code;
|
|
30
|
-
body;
|
|
31
|
-
issues;
|
|
32
|
-
currentDigest;
|
|
33
|
-
retryAfterMs;
|
|
34
|
-
constructor(status, message, code, body, retryAfterMs) {
|
|
35
|
-
super(message);
|
|
36
|
-
this.name = "ApiError";
|
|
37
|
-
this.status = status;
|
|
38
|
-
this.code = code;
|
|
39
|
-
this.body = body;
|
|
40
|
-
const parsed = zErrorResponse.safeParse(body);
|
|
41
|
-
this.issues = parsed.data?.issues ?? [];
|
|
42
|
-
this.currentDigest = parsed.data?.current_digest;
|
|
43
|
-
this.retryAfterMs = retryAfterMs;
|
|
44
|
-
}
|
|
45
|
-
static async fromResponse(response) {
|
|
46
|
-
const body = zErrorBody.safeParse(await response.clone().text());
|
|
47
|
-
return _ApiError.fromBody(
|
|
48
|
-
response.status,
|
|
49
|
-
body.success ? body.data : void 0,
|
|
50
|
-
parseRetryAfter(response.headers.get("Retry-After"))
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
static fromBody(status, body, retryAfterMs) {
|
|
54
|
-
const parsed = zErrorResponse.safeParse(body);
|
|
55
|
-
const message = parsed.data?.error_description ?? parsed.data?.error ?? `request failed with status ${status}`;
|
|
56
|
-
return new _ApiError(status, message, parsed.data?.code, body, retryAfterMs);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
function parseRetryAfter(value) {
|
|
60
|
-
if (value == null) return void 0;
|
|
61
|
-
const trimmed = value.trim();
|
|
62
|
-
if (/^\d+$/.test(trimmed)) return Number.parseInt(trimmed, 10) * 1e3;
|
|
63
|
-
const at = Date.parse(trimmed);
|
|
64
|
-
if (Number.isNaN(at)) return void 0;
|
|
65
|
-
return Math.max(at - Date.now(), 0);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export {
|
|
69
|
-
zJsonText,
|
|
70
|
-
zErrorResponse,
|
|
71
|
-
ApiError
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=chunk-6YKVAVCM.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/json-body.ts","../src/errors.ts"],"sourcesContent":["import * as z from 'zod'\n\nexport const zJsonBody = z.json()\n\nexport type JsonBody = z.infer<typeof zJsonBody>\n\nexport const zJsonText = z.string().transform((text, ctx) => {\n try {\n const value: unknown = JSON.parse(text)\n return value\n } catch (error) {\n ctx.addIssue({ code: 'custom', message: String(error), input: text, params: { cause: error } })\n return z.NEVER\n }\n})\n","import * as z from 'zod'\n\nimport type { AgentConfigErrorIssue, ErrorCode } from './generated/types.gen'\nimport { zError } from './generated/zod.gen'\nimport { type JsonBody, zJsonBody, zJsonText } from './json-body'\nimport { relaxedSchema } from './validate-response'\n\nexport type ApiErrorCode = ErrorCode | (string & {})\n\nconst zErrorBody = zJsonText.pipe(zJsonBody)\n\nexport const zErrorResponse = relaxedSchema(\n zError.partial({ code: true }).extend({ error_description: z.string().optional() }),\n)\n\nexport class ApiError extends Error {\n readonly status: number\n readonly code: ApiErrorCode | undefined\n readonly body: JsonBody | undefined\n readonly issues: AgentConfigErrorIssue[]\n readonly currentDigest: string | undefined\n readonly retryAfterMs: number | undefined\n\n constructor(\n status: number,\n message: string,\n code?: ApiErrorCode,\n body?: JsonBody,\n retryAfterMs?: number,\n ) {\n super(message)\n this.name = 'ApiError'\n this.status = status\n this.code = code\n this.body = body\n const parsed = zErrorResponse.safeParse(body)\n this.issues = parsed.data?.issues ?? []\n this.currentDigest = parsed.data?.current_digest\n this.retryAfterMs = retryAfterMs\n }\n\n static async fromResponse(response: Response): Promise<ApiError> {\n const body = zErrorBody.safeParse(await response.clone().text())\n return ApiError.fromBody(\n response.status,\n body.success ? body.data : undefined,\n parseRetryAfter(response.headers.get('Retry-After')),\n )\n }\n\n static fromBody(status: number, body: JsonBody | undefined, retryAfterMs?: number): ApiError {\n const parsed = zErrorResponse.safeParse(body)\n const message =\n parsed.data?.error_description ?? parsed.data?.error ?? `request failed with status ${status}`\n return new ApiError(status, message, parsed.data?.code, body, retryAfterMs)\n }\n}\n\nfunction parseRetryAfter(value: string | null): number | undefined {\n if (value == null) return undefined\n const trimmed = value.trim()\n if (/^\\d+$/.test(trimmed)) return Number.parseInt(trimmed, 10) * 1_000\n const at = Date.parse(trimmed)\n if (Number.isNaN(at)) return undefined\n return Math.max(at - Date.now(), 0)\n}\n"],"mappings":";;;;;;;;AAAA,YAAY,OAAO;AAEZ,IAAM,YAAc,OAAK;AAIzB,IAAM,YAAc,SAAO,EAAE,UAAU,CAAC,MAAM,QAAQ;AAC3D,MAAI;AACF,UAAM,QAAiB,KAAK,MAAM,IAAI;AACtC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,SAAS,EAAE,MAAM,UAAU,SAAS,OAAO,KAAK,GAAG,OAAO,MAAM,QAAQ,EAAE,OAAO,MAAM,EAAE,CAAC;AAC9F,WAAS;AAAA,EACX;AACF,CAAC;;;ACdD,YAAYA,QAAO;AASnB,IAAM,aAAa,UAAU,KAAK,SAAS;AAEpC,IAAM,iBAAiB;AAAA,EAC5B,OAAO,QAAQ,EAAE,MAAM,KAAK,CAAC,EAAE,OAAO,EAAE,mBAAqB,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BC.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/validate-response.ts
|
|
2
|
-
import * as z from "zod";
|
|
3
|
-
var zStringInput = z.string();
|
|
4
|
-
function isStringInput(issue) {
|
|
5
|
-
return zStringInput.safeParse(issue.input).success;
|
|
6
|
-
}
|
|
7
|
-
function hasStringDiscriminator(issue) {
|
|
8
|
-
if (issue.discriminator === void 0) return isStringInput(issue);
|
|
9
|
-
return z.object({ [issue.discriminator]: zStringInput }).safeParse(issue.input).success;
|
|
10
|
-
}
|
|
11
|
-
function samePath(a, b) {
|
|
12
|
-
return a.length === b.length && a.every((segment, index) => segment === b[index]);
|
|
13
|
-
}
|
|
14
|
-
function isUnknownEnumIssue(issue) {
|
|
15
|
-
if (issue.code === "invalid_value") return isStringInput(issue);
|
|
16
|
-
if (issue.code !== "invalid_union") return false;
|
|
17
|
-
if (issue.errors.length === 0) return hasStringDiscriminator(issue);
|
|
18
|
-
if (issue.errors.some((arm) => arm.every(isUnknownEnumIssue))) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
const [first, ...rest] = issue.errors;
|
|
22
|
-
return (first ?? []).some(
|
|
23
|
-
(candidate) => candidate.code === "invalid_value" && isStringInput(candidate) && rest.every(
|
|
24
|
-
(arm) => arm.some((other) => other.code === "invalid_value" && samePath(other.path, candidate.path))
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
function isUnknownEnumError(error) {
|
|
29
|
-
return error.issues.every(isUnknownEnumIssue);
|
|
30
|
-
}
|
|
31
|
-
function relaxedSchema(schema) {
|
|
32
|
-
return z.custom().superRefine((value, ctx) => {
|
|
33
|
-
const result = schema.safeParse(value, { reportInput: true });
|
|
34
|
-
if (result.success || isUnknownEnumError(result.error)) return;
|
|
35
|
-
for (const issue of result.error.issues) ctx.addIssue({ ...issue });
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function relaxedResponseValidator(schema) {
|
|
39
|
-
return async (data) => {
|
|
40
|
-
const result = await schema.safeParseAsync(data, { reportInput: true });
|
|
41
|
-
if (result.success || isUnknownEnumError(result.error)) return;
|
|
42
|
-
throw result.error;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export {
|
|
47
|
-
relaxedSchema,
|
|
48
|
-
relaxedResponseValidator
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=chunk-NZCMY3BC.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/validate-response.ts"],"sourcesContent":["import * as z from 'zod'\n\nimport type { Config } from './generated/client'\n\ntype Issue = z.core.$ZodIssue\n\ntype ResponseValidator = NonNullable<Config['responseValidator']>\n\nconst zStringInput = z.string()\n\nfunction isStringInput(issue: Issue): boolean {\n return zStringInput.safeParse(issue.input).success\n}\n\nfunction hasStringDiscriminator(issue: z.core.$ZodIssueInvalidUnion): boolean {\n if (issue.discriminator === undefined) return isStringInput(issue)\n return z.object({ [issue.discriminator]: zStringInput }).safeParse(issue.input).success\n}\n\nfunction samePath(a: readonly PropertyKey[], b: readonly PropertyKey[]): boolean {\n return a.length === b.length && a.every((segment, index) => segment === b[index])\n}\n\nfunction isUnknownEnumIssue(issue: Issue): boolean {\n if (issue.code === 'invalid_value') return isStringInput(issue)\n if (issue.code !== 'invalid_union') return false\n if (issue.errors.length === 0) return hasStringDiscriminator(issue)\n if (issue.errors.some((arm) => arm.every(isUnknownEnumIssue))) {\n return true\n }\n const [first, ...rest] = issue.errors\n return (first ?? []).some(\n (candidate) =>\n candidate.code === 'invalid_value' &&\n isStringInput(candidate) &&\n rest.every((arm) =>\n arm.some((other) => other.code === 'invalid_value' && samePath(other.path, candidate.path)),\n ),\n )\n}\n\nexport function isUnknownEnumError(error: z.ZodError): boolean {\n return error.issues.every(isUnknownEnumIssue)\n}\n\nexport function relaxedSchema<S extends z.ZodType>(schema: S): z.ZodType<z.output<S>> {\n return z.custom<z.output<S>>().superRefine((value, ctx) => {\n const result = schema.safeParse(value, { reportInput: true })\n if (result.success || isUnknownEnumError(result.error)) return\n for (const issue of result.error.issues) ctx.addIssue({ ...issue })\n })\n}\n\nexport function relaxedResponseValidator(schema: z.ZodType): ResponseValidator {\n return async (data) => {\n const result = await schema.safeParseAsync(data, { reportInput: true })\n if (result.success || isUnknownEnumError(result.error)) return\n throw result.error\n }\n}\n"],"mappings":";AAAA,YAAY,OAAO;AAQnB,IAAM,eAAiB,SAAO;AAE9B,SAAS,cAAc,OAAuB;AAC5C,SAAO,aAAa,UAAU,MAAM,KAAK,EAAE;AAC7C;AAEA,SAAS,uBAAuB,OAA8C;AAC5E,MAAI,MAAM,kBAAkB,OAAW,QAAO,cAAc,KAAK;AACjE,SAAS,SAAO,EAAE,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,EAAE,UAAU,MAAM,KAAK,EAAE;AAClF;AAEA,SAAS,SAAS,GAA2B,GAAoC;AAC/E,SAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,SAAS,UAAU,YAAY,EAAE,KAAK,CAAC;AAClF;AAEA,SAAS,mBAAmB,OAAuB;AACjD,MAAI,MAAM,SAAS,gBAAiB,QAAO,cAAc,KAAK;AAC9D,MAAI,MAAM,SAAS,gBAAiB,QAAO;AAC3C,MAAI,MAAM,OAAO,WAAW,EAAG,QAAO,uBAAuB,KAAK;AAClE,MAAI,MAAM,OAAO,KAAK,CAAC,QAAQ,IAAI,MAAM,kBAAkB,CAAC,GAAG;AAC7D,WAAO;AAAA,EACT;AACA,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI,MAAM;AAC/B,UAAQ,SAAS,CAAC,GAAG;AAAA,IACnB,CAAC,cACC,UAAU,SAAS,mBACnB,cAAc,SAAS,KACvB,KAAK;AAAA,MAAM,CAAC,QACV,IAAI,KAAK,CAAC,UAAU,MAAM,SAAS,mBAAmB,SAAS,MAAM,MAAM,UAAU,IAAI,CAAC;AAAA,IAC5F;AAAA,EACJ;AACF;AAEO,SAAS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