@pliuz/sdk 0.1.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.
@@ -0,0 +1,179 @@
1
+ import { P as PliuzClient, O as Originator } from './client-BABvN_88.cjs';
2
+ export { A as ApiErrorBody, a as ApprovalRequest, b as ApprovalStatus, C as CreateApprovalInput, c as CreateApprovalResponse, D as DEFAULT_BASE_URL, d as DEFAULT_MAX_RETRIES, e as DEFAULT_TIMEOUT_MS, E as ENV_API_KEY, f as ENV_BASE_URL, g as ExecutionInput, h as ExecutionResult, i as ExecutionStatus, j as OriginatorType, k as PliuzClientOptions } from './client-BABvN_88.cjs';
3
+
4
+ /**
5
+ * Single source of truth for the package version.
6
+ * Kept in sync with `package.json` by release tooling at publish time.
7
+ */
8
+ declare const VERSION: "0.1.0";
9
+
10
+ /**
11
+ * Field-level redaction applied client-side BEFORE sending to Pliuz.
12
+ *
13
+ * Non-negotiable architectural decision: sensitive fields (PII, secrets, PHI)
14
+ * must never leave the caller's process in plaintext. The SDK applies
15
+ * redaction on the client side, transmits the redacted payload, and the
16
+ * backend never sees the raw values.
17
+ *
18
+ * ## Path syntax
19
+ *
20
+ * "customer.ssn" → payload.customer.ssn
21
+ * "items[*].card_number" → every item's card_number
22
+ * "headers.authorization" → payload.headers.authorization
23
+ *
24
+ * Limitations (intentional — keep the surface tiny):
25
+ * - No JSONPath wildcards beyond `[*]`
26
+ * - No filter expressions
27
+ * - Missing keys are silently ignored
28
+ */
29
+ declare const REDACTED_PLACEHOLDER: "<redacted>";
30
+ /**
31
+ * Returns a deep copy of `payload` with values at `paths` replaced by
32
+ * `REDACTED_PLACEHOLDER`. Does not mutate the input.
33
+ *
34
+ * @example
35
+ * applyRedaction({ customer: { ssn: '123-45-6789' } }, ['customer.ssn'])
36
+ * // → { customer: { ssn: '<redacted>' } }
37
+ */
38
+ declare function applyRedaction<T extends Record<string, unknown>>(payload: T, paths: readonly string[] | null | undefined): T;
39
+
40
+ /**
41
+ * Error hierarchy for the Pliuz SDK.
42
+ *
43
+ * All exceptions extend `PliuzError`. HTTP-level failures use `PliuzApiError`
44
+ * subclasses keyed by status code, so callers can do narrow `instanceof` checks:
45
+ *
46
+ * ```ts
47
+ * try {
48
+ * await pliuz.createApproval(...)
49
+ * } catch (e) {
50
+ * if (e instanceof PliuzAuthError) {
51
+ * // refresh API key
52
+ * } else if (e instanceof PliuzPolicyError) {
53
+ * // no policy matched — define a catch-all
54
+ * } else if (e instanceof PliuzApiError) {
55
+ * // other 4xx/5xx
56
+ * }
57
+ * throw e
58
+ * }
59
+ * ```
60
+ */
61
+ declare class PliuzError extends Error {
62
+ constructor(message: string);
63
+ }
64
+ declare class PliuzNetworkError extends PliuzError {
65
+ readonly cause?: unknown | undefined;
66
+ constructor(message: string, cause?: unknown | undefined);
67
+ }
68
+ declare class PliuzTimeoutError extends PliuzError {
69
+ constructor(message: string);
70
+ }
71
+ declare class PliuzApiError extends PliuzError {
72
+ readonly statusCode: number;
73
+ readonly errorCode: string;
74
+ readonly details?: Record<string, unknown> | undefined;
75
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown> | undefined);
76
+ }
77
+ declare class PliuzValidationError extends PliuzApiError {
78
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
79
+ }
80
+ declare class PliuzAuthError extends PliuzApiError {
81
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
82
+ }
83
+ declare class PliuzForbiddenError extends PliuzApiError {
84
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
85
+ }
86
+ declare class PliuzNotFoundError extends PliuzApiError {
87
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
88
+ }
89
+ declare class PliuzConflictError extends PliuzApiError {
90
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
91
+ }
92
+ declare class PliuzPolicyError extends PliuzApiError {
93
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
94
+ }
95
+ declare class PliuzRateLimitError extends PliuzApiError {
96
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
97
+ }
98
+ declare class PliuzServerError extends PliuzApiError {
99
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
100
+ }
101
+ declare class PliuzRejectedError extends PliuzError {
102
+ readonly approvalId: string;
103
+ readonly reason: string | null;
104
+ constructor(approvalId: string, reason: string | null);
105
+ }
106
+ declare class PliuzApprovalExpiredError extends PliuzError {
107
+ readonly approvalId: string;
108
+ constructor(approvalId: string);
109
+ }
110
+ declare class PliuzApprovalTimeoutError extends PliuzError {
111
+ readonly approvalId: string;
112
+ readonly timeoutMs: number;
113
+ constructor(approvalId: string, timeoutMs: number);
114
+ }
115
+ declare function errorForStatus(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>): PliuzApiError;
116
+
117
+ /**
118
+ * The `gated()` wrapper — the headline API of the Pliuz TypeScript SDK.
119
+ *
120
+ * Wraps any function (sync or async) so every call is gated by a Pliuz
121
+ * approval request. The wrapped function always returns `Promise<TResult>`
122
+ * even if the original is synchronous — gating is inherently async because
123
+ * it involves an HTTP call.
124
+ *
125
+ * @example
126
+ * import { gated } from '@pliuz/sdk'
127
+ *
128
+ * const issueRefund = gated(
129
+ * {
130
+ * policy: 'refund',
131
+ * redact: ['customer.ssn'],
132
+ * toolArgs: (customerId: string, amountCents: number) => ({
133
+ * customer_id: customerId,
134
+ * amount_cents: amountCents,
135
+ * }),
136
+ * },
137
+ * async (customerId, amountCents) => stripe.refund(customerId, amountCents),
138
+ * )
139
+ *
140
+ * const result = await issueRefund('cus_123', 5000)
141
+ */
142
+
143
+ declare const DEFAULT_GATED_TIMEOUT_MS = 300000;
144
+ declare const DEFAULT_GATED_POLL_INTERVAL_MS = 2000;
145
+ interface GatedOptions<TArgs extends readonly unknown[]> {
146
+ /** Policy slug to bind this gate to. Default: backend resolves by toolName. */
147
+ policy?: string;
148
+ /** Redaction paths applied to tool_args BEFORE sending. */
149
+ redact?: readonly string[];
150
+ /** Override the tool name. Default: `fn.name` (may be empty for anonymous). */
151
+ toolName?: string;
152
+ /**
153
+ * Map the wrapped function's args into a tool_args object.
154
+ * Default: `(...args) => ({ args })` — wraps all positional args under
155
+ * a single `args` key. Provide a custom mapper for cleaner audit trails.
156
+ */
157
+ toolArgs?: (...args: TArgs) => Record<string, unknown>;
158
+ /** Max ms to poll for the approval to resolve. Throws on timeout. */
159
+ timeoutMs?: number;
160
+ /** Ms between GET /approvals/:id polls. */
161
+ pollIntervalMs?: number;
162
+ /** Reuse an existing PliuzClient. Default: `new PliuzClient()`. */
163
+ client?: PliuzClient;
164
+ /** Optional context for the human approver. */
165
+ contextMessages?: readonly string[];
166
+ /** Optional session id (groups related approvals in the UI). */
167
+ sessionId?: string;
168
+ /** Optional originator (default: { type: 'system' }). */
169
+ originator?: Originator;
170
+ }
171
+ /**
172
+ * Wrap a function so every call is gated by Pliuz.
173
+ *
174
+ * The returned function ALWAYS returns a Promise, even if the input is sync.
175
+ * This is intentional — gating necessarily involves async HTTP calls.
176
+ */
177
+ declare function gated<TArgs extends readonly unknown[], TResult>(options: GatedOptions<TArgs>, fn: (...args: TArgs) => Promise<TResult> | TResult): (...args: TArgs) => Promise<TResult>;
178
+
179
+ export { DEFAULT_GATED_POLL_INTERVAL_MS, DEFAULT_GATED_TIMEOUT_MS, type GatedOptions, Originator, PliuzApiError, PliuzApprovalExpiredError, PliuzApprovalTimeoutError, PliuzAuthError, PliuzClient, PliuzConflictError, PliuzError, PliuzForbiddenError, PliuzNetworkError, PliuzNotFoundError, PliuzPolicyError, PliuzRateLimitError, PliuzRejectedError, PliuzServerError, PliuzTimeoutError, PliuzValidationError, REDACTED_PLACEHOLDER, VERSION, applyRedaction, errorForStatus, gated };
@@ -0,0 +1,179 @@
1
+ import { P as PliuzClient, O as Originator } from './client-BABvN_88.js';
2
+ export { A as ApiErrorBody, a as ApprovalRequest, b as ApprovalStatus, C as CreateApprovalInput, c as CreateApprovalResponse, D as DEFAULT_BASE_URL, d as DEFAULT_MAX_RETRIES, e as DEFAULT_TIMEOUT_MS, E as ENV_API_KEY, f as ENV_BASE_URL, g as ExecutionInput, h as ExecutionResult, i as ExecutionStatus, j as OriginatorType, k as PliuzClientOptions } from './client-BABvN_88.js';
3
+
4
+ /**
5
+ * Single source of truth for the package version.
6
+ * Kept in sync with `package.json` by release tooling at publish time.
7
+ */
8
+ declare const VERSION: "0.1.0";
9
+
10
+ /**
11
+ * Field-level redaction applied client-side BEFORE sending to Pliuz.
12
+ *
13
+ * Non-negotiable architectural decision: sensitive fields (PII, secrets, PHI)
14
+ * must never leave the caller's process in plaintext. The SDK applies
15
+ * redaction on the client side, transmits the redacted payload, and the
16
+ * backend never sees the raw values.
17
+ *
18
+ * ## Path syntax
19
+ *
20
+ * "customer.ssn" → payload.customer.ssn
21
+ * "items[*].card_number" → every item's card_number
22
+ * "headers.authorization" → payload.headers.authorization
23
+ *
24
+ * Limitations (intentional — keep the surface tiny):
25
+ * - No JSONPath wildcards beyond `[*]`
26
+ * - No filter expressions
27
+ * - Missing keys are silently ignored
28
+ */
29
+ declare const REDACTED_PLACEHOLDER: "<redacted>";
30
+ /**
31
+ * Returns a deep copy of `payload` with values at `paths` replaced by
32
+ * `REDACTED_PLACEHOLDER`. Does not mutate the input.
33
+ *
34
+ * @example
35
+ * applyRedaction({ customer: { ssn: '123-45-6789' } }, ['customer.ssn'])
36
+ * // → { customer: { ssn: '<redacted>' } }
37
+ */
38
+ declare function applyRedaction<T extends Record<string, unknown>>(payload: T, paths: readonly string[] | null | undefined): T;
39
+
40
+ /**
41
+ * Error hierarchy for the Pliuz SDK.
42
+ *
43
+ * All exceptions extend `PliuzError`. HTTP-level failures use `PliuzApiError`
44
+ * subclasses keyed by status code, so callers can do narrow `instanceof` checks:
45
+ *
46
+ * ```ts
47
+ * try {
48
+ * await pliuz.createApproval(...)
49
+ * } catch (e) {
50
+ * if (e instanceof PliuzAuthError) {
51
+ * // refresh API key
52
+ * } else if (e instanceof PliuzPolicyError) {
53
+ * // no policy matched — define a catch-all
54
+ * } else if (e instanceof PliuzApiError) {
55
+ * // other 4xx/5xx
56
+ * }
57
+ * throw e
58
+ * }
59
+ * ```
60
+ */
61
+ declare class PliuzError extends Error {
62
+ constructor(message: string);
63
+ }
64
+ declare class PliuzNetworkError extends PliuzError {
65
+ readonly cause?: unknown | undefined;
66
+ constructor(message: string, cause?: unknown | undefined);
67
+ }
68
+ declare class PliuzTimeoutError extends PliuzError {
69
+ constructor(message: string);
70
+ }
71
+ declare class PliuzApiError extends PliuzError {
72
+ readonly statusCode: number;
73
+ readonly errorCode: string;
74
+ readonly details?: Record<string, unknown> | undefined;
75
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown> | undefined);
76
+ }
77
+ declare class PliuzValidationError extends PliuzApiError {
78
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
79
+ }
80
+ declare class PliuzAuthError extends PliuzApiError {
81
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
82
+ }
83
+ declare class PliuzForbiddenError extends PliuzApiError {
84
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
85
+ }
86
+ declare class PliuzNotFoundError extends PliuzApiError {
87
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
88
+ }
89
+ declare class PliuzConflictError extends PliuzApiError {
90
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
91
+ }
92
+ declare class PliuzPolicyError extends PliuzApiError {
93
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
94
+ }
95
+ declare class PliuzRateLimitError extends PliuzApiError {
96
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
97
+ }
98
+ declare class PliuzServerError extends PliuzApiError {
99
+ constructor(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>);
100
+ }
101
+ declare class PliuzRejectedError extends PliuzError {
102
+ readonly approvalId: string;
103
+ readonly reason: string | null;
104
+ constructor(approvalId: string, reason: string | null);
105
+ }
106
+ declare class PliuzApprovalExpiredError extends PliuzError {
107
+ readonly approvalId: string;
108
+ constructor(approvalId: string);
109
+ }
110
+ declare class PliuzApprovalTimeoutError extends PliuzError {
111
+ readonly approvalId: string;
112
+ readonly timeoutMs: number;
113
+ constructor(approvalId: string, timeoutMs: number);
114
+ }
115
+ declare function errorForStatus(statusCode: number, errorCode: string, message: string, details?: Record<string, unknown>): PliuzApiError;
116
+
117
+ /**
118
+ * The `gated()` wrapper — the headline API of the Pliuz TypeScript SDK.
119
+ *
120
+ * Wraps any function (sync or async) so every call is gated by a Pliuz
121
+ * approval request. The wrapped function always returns `Promise<TResult>`
122
+ * even if the original is synchronous — gating is inherently async because
123
+ * it involves an HTTP call.
124
+ *
125
+ * @example
126
+ * import { gated } from '@pliuz/sdk'
127
+ *
128
+ * const issueRefund = gated(
129
+ * {
130
+ * policy: 'refund',
131
+ * redact: ['customer.ssn'],
132
+ * toolArgs: (customerId: string, amountCents: number) => ({
133
+ * customer_id: customerId,
134
+ * amount_cents: amountCents,
135
+ * }),
136
+ * },
137
+ * async (customerId, amountCents) => stripe.refund(customerId, amountCents),
138
+ * )
139
+ *
140
+ * const result = await issueRefund('cus_123', 5000)
141
+ */
142
+
143
+ declare const DEFAULT_GATED_TIMEOUT_MS = 300000;
144
+ declare const DEFAULT_GATED_POLL_INTERVAL_MS = 2000;
145
+ interface GatedOptions<TArgs extends readonly unknown[]> {
146
+ /** Policy slug to bind this gate to. Default: backend resolves by toolName. */
147
+ policy?: string;
148
+ /** Redaction paths applied to tool_args BEFORE sending. */
149
+ redact?: readonly string[];
150
+ /** Override the tool name. Default: `fn.name` (may be empty for anonymous). */
151
+ toolName?: string;
152
+ /**
153
+ * Map the wrapped function's args into a tool_args object.
154
+ * Default: `(...args) => ({ args })` — wraps all positional args under
155
+ * a single `args` key. Provide a custom mapper for cleaner audit trails.
156
+ */
157
+ toolArgs?: (...args: TArgs) => Record<string, unknown>;
158
+ /** Max ms to poll for the approval to resolve. Throws on timeout. */
159
+ timeoutMs?: number;
160
+ /** Ms between GET /approvals/:id polls. */
161
+ pollIntervalMs?: number;
162
+ /** Reuse an existing PliuzClient. Default: `new PliuzClient()`. */
163
+ client?: PliuzClient;
164
+ /** Optional context for the human approver. */
165
+ contextMessages?: readonly string[];
166
+ /** Optional session id (groups related approvals in the UI). */
167
+ sessionId?: string;
168
+ /** Optional originator (default: { type: 'system' }). */
169
+ originator?: Originator;
170
+ }
171
+ /**
172
+ * Wrap a function so every call is gated by Pliuz.
173
+ *
174
+ * The returned function ALWAYS returns a Promise, even if the input is sync.
175
+ * This is intentional — gating necessarily involves async HTTP calls.
176
+ */
177
+ declare function gated<TArgs extends readonly unknown[], TResult>(options: GatedOptions<TArgs>, fn: (...args: TArgs) => Promise<TResult> | TResult): (...args: TArgs) => Promise<TResult>;
178
+
179
+ export { DEFAULT_GATED_POLL_INTERVAL_MS, DEFAULT_GATED_TIMEOUT_MS, type GatedOptions, Originator, PliuzApiError, PliuzApprovalExpiredError, PliuzApprovalTimeoutError, PliuzAuthError, PliuzClient, PliuzConflictError, PliuzError, PliuzForbiddenError, PliuzNetworkError, PliuzNotFoundError, PliuzPolicyError, PliuzRateLimitError, PliuzRejectedError, PliuzServerError, PliuzTimeoutError, PliuzValidationError, REDACTED_PLACEHOLDER, VERSION, applyRedaction, errorForStatus, gated };