@codespar/sdk 0.3.0 → 0.10.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 +191 -9
- package/dist/__tests__/base-url-resolution.test.d.ts +10 -0
- package/dist/__tests__/base-url-resolution.test.d.ts.map +1 -0
- package/dist/__tests__/base-url-resolution.test.js +57 -0
- package/dist/__tests__/base-url-resolution.test.js.map +1 -0
- package/dist/__tests__/errors.test.d.ts +16 -0
- package/dist/__tests__/errors.test.d.ts.map +1 -0
- package/dist/__tests__/errors.test.js +163 -0
- package/dist/__tests__/errors.test.js.map +1 -0
- package/dist/__tests__/forward-mocks.test.d.ts +15 -0
- package/dist/__tests__/forward-mocks.test.d.ts.map +1 -0
- package/dist/__tests__/forward-mocks.test.js +134 -0
- package/dist/__tests__/forward-mocks.test.js.map +1 -0
- package/dist/__tests__/mocks-wire-parity.test.d.ts +15 -0
- package/dist/__tests__/mocks-wire-parity.test.d.ts.map +1 -0
- package/dist/__tests__/mocks-wire-parity.test.js +71 -0
- package/dist/__tests__/mocks-wire-parity.test.js.map +1 -0
- package/dist/__tests__/testing.test.d.ts +2 -0
- package/dist/__tests__/testing.test.d.ts.map +1 -0
- package/dist/__tests__/testing.test.js +133 -0
- package/dist/__tests__/testing.test.js.map +1 -0
- package/dist/__tests__/tool-result-codes.test.d.ts +18 -0
- package/dist/__tests__/tool-result-codes.test.d.ts.map +1 -0
- package/dist/__tests__/tool-result-codes.test.js +164 -0
- package/dist/__tests__/tool-result-codes.test.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +77 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +237 -35
- package/dist/session.js.map +1 -1
- package/dist/testing/index.d.ts +9 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +68 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tool-result-codes.d.ts +82 -0
- package/dist/tool-result-codes.d.ts.map +1 -0
- package/dist/tool-result-codes.js +99 -0
- package/dist/tool-result-codes.js.map +1 -0
- package/dist/types.d.ts +20 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-result code helpers — type-narrowed guards for the discriminated
|
|
3
|
+
* `tool_result.output` union surfaced on streamed `ToolCallRecord`
|
|
4
|
+
* values.
|
|
5
|
+
*
|
|
6
|
+
* The five variants are inert wire shapes — they only describe what the
|
|
7
|
+
* backend may stamp on `tool_result.output`. The guards turn `unknown`
|
|
8
|
+
* into one of the five `*Output` interfaces so callers can branch
|
|
9
|
+
* without casting.
|
|
10
|
+
*
|
|
11
|
+
* Each guard checks both the `code` discriminant against
|
|
12
|
+
* TOOL_RESULT_CODES AND its own required sibling fields — so a
|
|
13
|
+
* well-formed `code` with a missing sibling returns false rather
|
|
14
|
+
* than narrowing positive on the discriminant alone. The exhaustive-
|
|
15
|
+
* match utility (`assertExhaustiveToolResult`) makes a switch over
|
|
16
|
+
* ToolResultCode fail to compile if a sixth variant lands without
|
|
17
|
+
* the consumer updating their handler.
|
|
18
|
+
*/
|
|
19
|
+
import type { ToolCallRecord } from "@codespar/types";
|
|
20
|
+
export declare const ToolResultCode: {
|
|
21
|
+
readonly PolicyDenied: "policy_denied";
|
|
22
|
+
readonly ApprovalRequired: "approval_required";
|
|
23
|
+
readonly MocksExhausted: "mocks_exhausted";
|
|
24
|
+
readonly MocksEngineError: "mocks_engine_error";
|
|
25
|
+
readonly ToolNotMocked: "tool_not_mocked";
|
|
26
|
+
};
|
|
27
|
+
export type ToolResultCode = (typeof ToolResultCode)[keyof typeof ToolResultCode];
|
|
28
|
+
export declare const TOOL_RESULT_CODES: ReadonlySet<ToolResultCode>;
|
|
29
|
+
export interface PolicyDeniedOutput {
|
|
30
|
+
code: typeof ToolResultCode.PolicyDenied;
|
|
31
|
+
rule_id: string;
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ApprovalRequiredOutput {
|
|
35
|
+
code: typeof ToolResultCode.ApprovalRequired;
|
|
36
|
+
approval_id: string;
|
|
37
|
+
expires_at: string;
|
|
38
|
+
message: string;
|
|
39
|
+
}
|
|
40
|
+
export interface MocksExhaustedOutput {
|
|
41
|
+
code: typeof ToolResultCode.MocksExhausted;
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export interface MocksEngineErrorOutput {
|
|
45
|
+
code: typeof ToolResultCode.MocksEngineError;
|
|
46
|
+
message: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ToolNotMockedOutput {
|
|
49
|
+
code: typeof ToolResultCode.ToolNotMocked;
|
|
50
|
+
tool_name: string;
|
|
51
|
+
message: string;
|
|
52
|
+
}
|
|
53
|
+
export type ToolResultOutcome = PolicyDeniedOutput | ApprovalRequiredOutput | MocksExhaustedOutput | MocksEngineErrorOutput | ToolNotMockedOutput;
|
|
54
|
+
export type PolicyDeniedToolCall = ToolCallRecord & {
|
|
55
|
+
output: PolicyDeniedOutput;
|
|
56
|
+
};
|
|
57
|
+
export type ApprovalRequiredToolCall = ToolCallRecord & {
|
|
58
|
+
output: ApprovalRequiredOutput;
|
|
59
|
+
};
|
|
60
|
+
export type MocksExhaustedToolCall = ToolCallRecord & {
|
|
61
|
+
output: MocksExhaustedOutput;
|
|
62
|
+
};
|
|
63
|
+
export type MocksEngineErrorToolCall = ToolCallRecord & {
|
|
64
|
+
output: MocksEngineErrorOutput;
|
|
65
|
+
};
|
|
66
|
+
export type ToolNotMockedToolCall = ToolCallRecord & {
|
|
67
|
+
output: ToolNotMockedOutput;
|
|
68
|
+
};
|
|
69
|
+
export declare function isPolicyDenied(value: unknown): value is PolicyDeniedOutput;
|
|
70
|
+
export declare function isApprovalRequired(value: unknown): value is ApprovalRequiredOutput;
|
|
71
|
+
export declare function isMocksExhausted(value: unknown): value is MocksExhaustedOutput;
|
|
72
|
+
export declare function isMocksEngineError(value: unknown): value is MocksEngineErrorOutput;
|
|
73
|
+
export declare function isToolNotMocked(value: unknown): value is ToolNotMockedOutput;
|
|
74
|
+
/**
|
|
75
|
+
* Exhaustive-match witness. A `switch` over `ToolResultCode` should
|
|
76
|
+
* pass `value` here in the default branch — TS fails to compile if
|
|
77
|
+
* `value` isn't narrowed to `never`, i.e. if a code variant escaped
|
|
78
|
+
* the switch. The runtime body throws so a hostile cast at runtime
|
|
79
|
+
* doesn't silently swallow an unknown code.
|
|
80
|
+
*/
|
|
81
|
+
export declare function assertExhaustiveToolResult(value: never): never;
|
|
82
|
+
//# sourceMappingURL=tool-result-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-result-codes.d.ts","sourceRoot":"","sources":["../src/tool-result-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAElF,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,cAAc,CAMxD,CAAC;AAEH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,cAAc,CAAC,YAAY,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,OAAO,cAAc,CAAC,gBAAgB,CAAC;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAA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AsB,CAKlF;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAM5E;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAI9D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-result code helpers — type-narrowed guards for the discriminated
|
|
3
|
+
* `tool_result.output` union surfaced on streamed `ToolCallRecord`
|
|
4
|
+
* values.
|
|
5
|
+
*
|
|
6
|
+
* The five variants are inert wire shapes — they only describe what the
|
|
7
|
+
* backend may stamp on `tool_result.output`. The guards turn `unknown`
|
|
8
|
+
* into one of the five `*Output` interfaces so callers can branch
|
|
9
|
+
* without casting.
|
|
10
|
+
*
|
|
11
|
+
* Each guard checks both the `code` discriminant against
|
|
12
|
+
* TOOL_RESULT_CODES AND its own required sibling fields — so a
|
|
13
|
+
* well-formed `code` with a missing sibling returns false rather
|
|
14
|
+
* than narrowing positive on the discriminant alone. The exhaustive-
|
|
15
|
+
* match utility (`assertExhaustiveToolResult`) makes a switch over
|
|
16
|
+
* ToolResultCode fail to compile if a sixth variant lands without
|
|
17
|
+
* the consumer updating their handler.
|
|
18
|
+
*/
|
|
19
|
+
export const ToolResultCode = {
|
|
20
|
+
PolicyDenied: "policy_denied",
|
|
21
|
+
ApprovalRequired: "approval_required",
|
|
22
|
+
MocksExhausted: "mocks_exhausted",
|
|
23
|
+
MocksEngineError: "mocks_engine_error",
|
|
24
|
+
ToolNotMocked: "tool_not_mocked",
|
|
25
|
+
};
|
|
26
|
+
export const TOOL_RESULT_CODES = new Set([
|
|
27
|
+
ToolResultCode.PolicyDenied,
|
|
28
|
+
ToolResultCode.ApprovalRequired,
|
|
29
|
+
ToolResultCode.MocksExhausted,
|
|
30
|
+
ToolResultCode.MocksEngineError,
|
|
31
|
+
ToolResultCode.ToolNotMocked,
|
|
32
|
+
]);
|
|
33
|
+
function isObject(value) {
|
|
34
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
function readStringField(obj, key) {
|
|
37
|
+
const v = obj[key];
|
|
38
|
+
return typeof v === "string" ? v : null;
|
|
39
|
+
}
|
|
40
|
+
export function isPolicyDenied(value) {
|
|
41
|
+
if (!isObject(value))
|
|
42
|
+
return false;
|
|
43
|
+
if (value.code !== ToolResultCode.PolicyDenied)
|
|
44
|
+
return false;
|
|
45
|
+
if (!TOOL_RESULT_CODES.has(value.code))
|
|
46
|
+
return false;
|
|
47
|
+
return readStringField(value, "rule_id") !== null
|
|
48
|
+
&& readStringField(value, "message") !== null;
|
|
49
|
+
}
|
|
50
|
+
export function isApprovalRequired(value) {
|
|
51
|
+
if (!isObject(value))
|
|
52
|
+
return false;
|
|
53
|
+
if (value.code !== ToolResultCode.ApprovalRequired)
|
|
54
|
+
return false;
|
|
55
|
+
if (!TOOL_RESULT_CODES.has(value.code))
|
|
56
|
+
return false;
|
|
57
|
+
return readStringField(value, "approval_id") !== null
|
|
58
|
+
&& readStringField(value, "expires_at") !== null
|
|
59
|
+
&& readStringField(value, "message") !== null;
|
|
60
|
+
}
|
|
61
|
+
export function isMocksExhausted(value) {
|
|
62
|
+
if (!isObject(value))
|
|
63
|
+
return false;
|
|
64
|
+
if (value.code !== ToolResultCode.MocksExhausted)
|
|
65
|
+
return false;
|
|
66
|
+
if (!TOOL_RESULT_CODES.has(value.code))
|
|
67
|
+
return false;
|
|
68
|
+
return readStringField(value, "message") !== null;
|
|
69
|
+
}
|
|
70
|
+
export function isMocksEngineError(value) {
|
|
71
|
+
if (!isObject(value))
|
|
72
|
+
return false;
|
|
73
|
+
if (value.code !== ToolResultCode.MocksEngineError)
|
|
74
|
+
return false;
|
|
75
|
+
if (!TOOL_RESULT_CODES.has(value.code))
|
|
76
|
+
return false;
|
|
77
|
+
return readStringField(value, "message") !== null;
|
|
78
|
+
}
|
|
79
|
+
export function isToolNotMocked(value) {
|
|
80
|
+
if (!isObject(value))
|
|
81
|
+
return false;
|
|
82
|
+
if (value.code !== ToolResultCode.ToolNotMocked)
|
|
83
|
+
return false;
|
|
84
|
+
if (!TOOL_RESULT_CODES.has(value.code))
|
|
85
|
+
return false;
|
|
86
|
+
return readStringField(value, "tool_name") !== null
|
|
87
|
+
&& readStringField(value, "message") !== null;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Exhaustive-match witness. A `switch` over `ToolResultCode` should
|
|
91
|
+
* pass `value` here in the default branch — TS fails to compile if
|
|
92
|
+
* `value` isn't narrowed to `never`, i.e. if a code variant escaped
|
|
93
|
+
* the switch. The runtime body throws so a hostile cast at runtime
|
|
94
|
+
* doesn't silently swallow an unknown code.
|
|
95
|
+
*/
|
|
96
|
+
export function assertExhaustiveToolResult(value) {
|
|
97
|
+
throw new Error(`tool-result-codes: unexpected output variant ${JSON.stringify(value)}`);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=tool-result-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-result-codes.js","sourceRoot":"","sources":["../src/tool-result-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,YAAY,EAAE,eAAe;IAC7B,gBAAgB,EAAE,mBAAmB;IACrC,cAAc,EAAE,iBAAiB;IACjC,gBAAgB,EAAE,oBAAoB;IACtC,aAAa,EAAE,iBAAiB;CACxB,CAAC;AAIX,MAAM,CAAC,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAC;IACpE,cAAc,CAAC,YAAY;IAC3B,cAAc,CAAC,gBAAgB;IAC/B,cAAc,CAAC,cAAc;IAC7B,cAAc,CAAC,gBAAgB;IAC/B,cAAc,CAAC,aAAa;CAC7B,CAAC,CAAC;AAwDH,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,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1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { ToolResult } from "@codespar/types";
|
|
2
|
+
import type { MockValue, ToolResult } from "@codespar/types";
|
|
3
3
|
export interface CodeSparConfig {
|
|
4
4
|
/** API key for managed mode. Obtain from dashboard.codespar.dev */
|
|
5
5
|
apiKey?: string;
|
|
@@ -24,6 +24,22 @@ export interface SessionConfig {
|
|
|
24
24
|
metadata?: Record<string, string>;
|
|
25
25
|
/** Optional project scope. Defaults to the org's default project when omitted. */
|
|
26
26
|
projectId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Test-mode mocks. Map of canonical tool names (slash form,
|
|
29
|
+
* `^[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9_-]*$` — e.g.
|
|
30
|
+
* `asaas/create_payment`) to mock responses. Values are either a
|
|
31
|
+
* single MockObject (static mock) or an array of MockObject
|
|
32
|
+
* (stateful mock, consumed in order).
|
|
33
|
+
*
|
|
34
|
+
* Requires a `csk_test_*` key against a `test`-environment project
|
|
35
|
+
* — the backend rejects with `mocks_not_permitted` otherwise.
|
|
36
|
+
* Forwarded verbatim to `POST /v1/sessions` so the OSS-runtime
|
|
37
|
+
* double-underscore form (`asaas__create_payment`) reaches the
|
|
38
|
+
* backend unrewritten and surfaces as `mocks_invalid`. An empty
|
|
39
|
+
* `{}` is accepted; strict-mode (R3a) activates only on non-empty
|
|
40
|
+
* maps.
|
|
41
|
+
*/
|
|
42
|
+
mocks?: Record<string, MockValue>;
|
|
27
43
|
}
|
|
28
44
|
export interface Tool {
|
|
29
45
|
/** Tool name (e.g. "codespar_pay") */
|
|
@@ -85,6 +101,7 @@ export declare const SessionConfigSchema: z.ZodObject<{
|
|
|
85
101
|
}>>;
|
|
86
102
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
87
103
|
projectId: z.ZodOptional<z.ZodString>;
|
|
104
|
+
mocks: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">]>>>;
|
|
88
105
|
}, "strip", z.ZodTypeAny, {
|
|
89
106
|
servers?: string[] | undefined;
|
|
90
107
|
preset?: "brazilian" | "mexican" | "argentinian" | "colombian" | "all" | undefined;
|
|
@@ -94,6 +111,7 @@ export declare const SessionConfigSchema: z.ZodObject<{
|
|
|
94
111
|
} | undefined;
|
|
95
112
|
metadata?: Record<string, string> | undefined;
|
|
96
113
|
projectId?: string | undefined;
|
|
114
|
+
mocks?: Record<string, Record<string, unknown> | Record<string, unknown>[]> | undefined;
|
|
97
115
|
}, {
|
|
98
116
|
servers?: string[] | undefined;
|
|
99
117
|
preset?: "brazilian" | "mexican" | "argentinian" | "colombian" | "all" | undefined;
|
|
@@ -103,5 +121,6 @@ export declare const SessionConfigSchema: z.ZodObject<{
|
|
|
103
121
|
} | undefined;
|
|
104
122
|
metadata?: Record<string, string> | undefined;
|
|
105
123
|
projectId?: string | undefined;
|
|
124
|
+
mocks?: Record<string, Record<string, unknown> | Record<string, unknown>[]> | undefined;
|
|
106
125
|
}>;
|
|
107
126
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7D,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,MAAM,CAAC,EAAE,MA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K,OAAO,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,uCAAuC;IACvC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7E,6BAA6B;IAC7B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACpE,oCAAoC;IACpC,WAAW,CAAC,EAAE;QACZ,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;QACnC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,gEAAgE;IAChE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB;AAYD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAY9B,CAAC"}
|
package/dist/types.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
/* ── Validation schemas ───────────────────────────────────────── */
|
|
3
|
+
// Mock values pass through verbatim — the backend owns the strict
|
|
4
|
+
// validation, so the client-side schema accepts any object shape
|
|
5
|
+
// rather than re-encoding the rules and risking drift.
|
|
6
|
+
const MockValueSchema = z.union([
|
|
7
|
+
z.record(z.unknown()),
|
|
8
|
+
z.array(z.record(z.unknown())),
|
|
9
|
+
]);
|
|
3
10
|
export const SessionConfigSchema = z.object({
|
|
4
11
|
servers: z.array(z.string()).optional(),
|
|
5
12
|
preset: z.enum(["brazilian", "mexican", "argentinian", "colombian", "all"]).optional(),
|
|
@@ -11,5 +18,6 @@ export const SessionConfigSchema = z.object({
|
|
|
11
18
|
.optional(),
|
|
12
19
|
metadata: z.record(z.string()).optional(),
|
|
13
20
|
projectId: z.string().regex(/^prj_[A-Za-z0-9]{16}$/).optional(),
|
|
21
|
+
mocks: z.record(MockValueSchema).optional(),
|
|
14
22
|
});
|
|
15
23
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuGxB,qEAAqE;AAErE,kEAAkE;AAClE,iEAAiE;AACjE,uDAAuD;AACvD,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC;IAC9B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACrB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACvC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtF,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,kBAAkB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAC1C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC/B,CAAC;SACD,QAAQ,EAAE;IACb,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACzC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE;IAC/D,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE;CAC5C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codespar/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Commerce SDK for AI agents — sessions, managed auth, Complete Loop orchestration for Latin American APIs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./testing": {
|
|
14
|
+
"import": "./dist/testing/index.js",
|
|
15
|
+
"types": "./dist/testing/index.d.ts"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"files": [
|
|
@@ -48,7 +52,7 @@
|
|
|
48
52
|
},
|
|
49
53
|
"dependencies": {
|
|
50
54
|
"zod": "^3.24.0",
|
|
51
|
-
"@codespar/types": "^0.
|
|
55
|
+
"@codespar/types": "^0.10.0"
|
|
52
56
|
},
|
|
53
57
|
"devDependencies": {
|
|
54
58
|
"@types/node": "^25.6.0",
|