@limetry/sdk 1.2.42
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/dist/app-version.d.ts +2 -0
- package/dist/app-version.d.ts.map +1 -0
- package/dist/app-version.js +2 -0
- package/dist/app-version.js.map +1 -0
- package/dist/engine/policy-engine.d.ts +21 -0
- package/dist/engine/policy-engine.d.ts.map +1 -0
- package/dist/engine/policy-engine.js +8 -0
- package/dist/engine/policy-engine.js.map +1 -0
- package/dist/engine/remote-engine.d.ts +70 -0
- package/dist/engine/remote-engine.d.ts.map +1 -0
- package/dist/engine/remote-engine.js +104 -0
- package/dist/engine/remote-engine.js.map +1 -0
- package/dist/errors.d.ts +90 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +110 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/policy/slim-policy.d.ts +126 -0
- package/dist/policy/slim-policy.d.ts.map +1 -0
- package/dist/policy/slim-policy.js +100 -0
- package/dist/policy/slim-policy.js.map +1 -0
- package/dist/privacy/redact.d.ts +269 -0
- package/dist/privacy/redact.d.ts.map +1 -0
- package/dist/privacy/redact.js +295 -0
- package/dist/privacy/redact.js.map +1 -0
- package/dist/types.d.ts +712 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers that expand a small set of limits into full Limetry policy documents.
|
|
3
|
+
*
|
|
4
|
+
* Prefer these builders for CLI/MCP first-run instead of hand-rolled JSON.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
/**
|
|
8
|
+
* Builds a full {@link SpendingPolicy} from a small set of limits.
|
|
9
|
+
*
|
|
10
|
+
* Prefer this for CLI/MCP first-run instead of hand-rolled JSON. Sets version
|
|
11
|
+
* `1`, status `"active"`, sensible replay/isolation defaults, and derives
|
|
12
|
+
* velocity and monthly caps when those inputs are omitted.
|
|
13
|
+
*
|
|
14
|
+
* @param input - Slim spending limits and identity fields.
|
|
15
|
+
* @returns Fully populated {@link SpendingPolicy} ready for persistence or evaluation.
|
|
16
|
+
*/
|
|
17
|
+
export function createSlimPolicy(input) {
|
|
18
|
+
const currency = input.currency ?? "USD";
|
|
19
|
+
const policyId = input.policyId ?? randomUUID();
|
|
20
|
+
const now = new Date().toISOString();
|
|
21
|
+
const allowed = input.allowedMerchantIds ?? [];
|
|
22
|
+
const maxSingle = input.maxSingleTransactionMinor;
|
|
23
|
+
const maxDaily = input.maxDailySpendMinor;
|
|
24
|
+
const maxMonthly = input.maxMonthlySpendMinor ?? maxDaily * 30;
|
|
25
|
+
return {
|
|
26
|
+
policy_id: policyId,
|
|
27
|
+
version: 1,
|
|
28
|
+
organization_id: input.organizationId ?? "default",
|
|
29
|
+
agent_id: input.agentId,
|
|
30
|
+
limits: {
|
|
31
|
+
max_single_transaction_minor: maxSingle,
|
|
32
|
+
max_daily_spend_minor: maxDaily,
|
|
33
|
+
max_monthly_spend_minor: maxMonthly,
|
|
34
|
+
currency,
|
|
35
|
+
},
|
|
36
|
+
velocity: {
|
|
37
|
+
max_transactions_per_minute: input.maxTransactionsPerMinute ?? 10,
|
|
38
|
+
max_transactions_per_hour: (input.maxTransactionsPerMinute ?? 10) * 20,
|
|
39
|
+
max_transactions_per_day: (input.maxTransactionsPerMinute ?? 10) * 100,
|
|
40
|
+
max_aggregate_amount_per_hour_minor: Math.min(maxDaily, maxSingle * 20),
|
|
41
|
+
},
|
|
42
|
+
replay: {
|
|
43
|
+
nonce_window_seconds: 300,
|
|
44
|
+
max_clock_skew_seconds: 300,
|
|
45
|
+
require_monotonic_nonce: true,
|
|
46
|
+
},
|
|
47
|
+
isolation: {
|
|
48
|
+
max_concurrent_pending_intents: 5,
|
|
49
|
+
max_pending_aggregate_minor: maxSingle * 5,
|
|
50
|
+
intent_ttl_seconds: 300,
|
|
51
|
+
enforce_unique_payee_per_intent_batch: true,
|
|
52
|
+
},
|
|
53
|
+
destination_rules: {
|
|
54
|
+
allowed_merchant_ids: allowed,
|
|
55
|
+
allowed_mcc_codes: [],
|
|
56
|
+
blocked_merchant_ids: [],
|
|
57
|
+
require_merchant_allowlist: allowed.length > 0,
|
|
58
|
+
},
|
|
59
|
+
effective_window: {
|
|
60
|
+
effective_from: now,
|
|
61
|
+
expires_at: null,
|
|
62
|
+
},
|
|
63
|
+
status: "active",
|
|
64
|
+
updated_at: now,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Builds a generic {@link ActionPolicy} from a small set of action constraints.
|
|
69
|
+
*
|
|
70
|
+
* Sets version `1`, status `"active"`, `audit_mode` to the input or `"minimal"`,
|
|
71
|
+
* and an open-ended effective window starting now.
|
|
72
|
+
*
|
|
73
|
+
* @param input - Slim action constraints and identity fields.
|
|
74
|
+
* @returns Fully populated {@link ActionPolicy} ready for persistence or evaluation.
|
|
75
|
+
*/
|
|
76
|
+
export function createSlimActionPolicy(input) {
|
|
77
|
+
const policyId = input.policyId ?? randomUUID();
|
|
78
|
+
const now = new Date().toISOString();
|
|
79
|
+
return {
|
|
80
|
+
policy_id: policyId,
|
|
81
|
+
version: 1,
|
|
82
|
+
organization_id: input.organizationId ?? "default",
|
|
83
|
+
agent_id: input.agentId,
|
|
84
|
+
allowed_action_types: input.allowedActionTypes,
|
|
85
|
+
denied_action_types: input.deniedActionTypes,
|
|
86
|
+
allowed_resource_patterns: input.allowedResourcePatterns,
|
|
87
|
+
blocked_resource_patterns: input.blockedResourcePatterns,
|
|
88
|
+
max_cost_minor: input.maxCostMinor,
|
|
89
|
+
currency: input.currency,
|
|
90
|
+
require_approval_action_types: input.requireApprovalActionTypes,
|
|
91
|
+
require_approval_resource_patterns: input.requireApprovalResourcePatterns,
|
|
92
|
+
approval_cost_minor: input.approvalCostMinor,
|
|
93
|
+
audit_mode: input.auditMode ?? "minimal",
|
|
94
|
+
status: "active",
|
|
95
|
+
updated_at: now,
|
|
96
|
+
effective_from: now,
|
|
97
|
+
expires_at: null,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=slim-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slim-policy.js","sourceRoot":"","sources":["../../src/policy/slim-policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAwGxC;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAsB;IACrD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAA;IACxC,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,UAAU,EAAE,CAAA;IAC/C,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACpC,MAAM,OAAO,GAAG,KAAK,CAAC,kBAAkB,IAAI,EAAE,CAAA;IAC9C,MAAM,SAAS,GAAG,KAAK,CAAC,yBAAyB,CAAA;IACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,kBAAkB,CAAA;IACzC,MAAM,UAAU,GAAG,KAAK,CAAC,oBAAoB,IAAI,QAAQ,GAAG,EAAE,CAAA;IAE9D,OAAO;QACL,SAAS,EAAE,QAAQ;QACnB,OAAO,EAAE,CAAC;QACV,eAAe,EAAE,KAAK,CAAC,cAAc,IAAI,SAAS;QAClD,QAAQ,EAAE,KAAK,CAAC,OAAO;QACvB,MAAM,EAAE;YACN,4BAA4B,EAAE,SAAS;YACvC,qBAAqB,EAAE,QAAQ;YAC/B,uBAAuB,EAAE,UAAU;YACnC,QAAQ;SACT;QACD,QAAQ,EAAE;YACR,2BAA2B,EAAE,KAAK,CAAC,wBAAwB,IAAI,EAAE;YACjE,yBAAyB,EAAE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B;QACxD,yBAAyB,EAAE,KAAK,CAAC,uBAAuB;QACxD,cAAc,EAAE,KAAK,CAAC,YAAY;QAClC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,6BAA6B,EAAE,KAAK,CAAC,0BAA0B;QAC/D,kCAAkC,EAAE,KAAK,CAAC,+BAA+B;QACzE,mBAAmB,EAAE,KAAK,CAAC,iBAAiB;QAC5C,UAAU,EAAE,KAAK,CAAC,SAAS,IAAI,SAAS;QACxC,MAAM,EAAE,QAAQ;QAChB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,GAAG;QACnB,UAAU,EAAE,IAAI;KACjB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Privacy helpers for scrubbing secrets from intents and building audit projections.
|
|
3
|
+
*
|
|
4
|
+
* Used when persisting authorization requests/responses and `policy.evaluated` /
|
|
5
|
+
* `action.recorded` audit detail blobs so raw credentials are never stored.
|
|
6
|
+
*/
|
|
7
|
+
import type { ActionIntent } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Audit retention modes for ActionPolicy.
|
|
10
|
+
* - minimal: store decision projection only (default)
|
|
11
|
+
* - forensics: store redacted intent + details after secret scrubbing
|
|
12
|
+
*/
|
|
13
|
+
export type AuditMode = "minimal" | "forensics";
|
|
14
|
+
/**
|
|
15
|
+
* Default audit retention mode when a policy or env override is absent.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_AUDIT_MODE: AuditMode;
|
|
18
|
+
/**
|
|
19
|
+
* Returns whether a metadata/details key name looks like a secret or credential.
|
|
20
|
+
*
|
|
21
|
+
* @param key - Object key to test.
|
|
22
|
+
* @returns `true` when the key name matches known secret/credential patterns.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isSensitiveKey(key: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Strips query string, hash, and URL userinfo from a resource identifier.
|
|
27
|
+
*
|
|
28
|
+
* Non-URL resources are returned unchanged after trimming; if a `?` is present
|
|
29
|
+
* on a non-URL string, only the prefix before the query is kept.
|
|
30
|
+
*
|
|
31
|
+
* @param resource - Resource identifier (URL or opaque string).
|
|
32
|
+
* @returns Scrubbed resource string.
|
|
33
|
+
*/
|
|
34
|
+
export declare function scrubResource(resource: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Drops or redacts sensitive keys from a string metadata map.
|
|
37
|
+
*
|
|
38
|
+
* Sensitive keys keep their key but get value `"[REDACTED]"`; other values
|
|
39
|
+
* pass through {@link scrubEmbeddedSecrets}. Returns `undefined` for empty
|
|
40
|
+
* or missing input.
|
|
41
|
+
*
|
|
42
|
+
* @param metadata - Optional string key/value metadata bag.
|
|
43
|
+
* @returns Redacted metadata, or `undefined` when empty/absent.
|
|
44
|
+
*/
|
|
45
|
+
export declare function redactMetadata(metadata: Record<string, string> | undefined): Record<string, string> | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Recursively redacts sensitive keys and scrubs string values in open JSON bags.
|
|
48
|
+
*
|
|
49
|
+
* @param details - Optional open JSON object.
|
|
50
|
+
* @returns Redacted deep copy, or `undefined` when input is absent.
|
|
51
|
+
*/
|
|
52
|
+
export declare function redactDetails(details: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Redacts common secret patterns embedded in free-text / URL query values.
|
|
55
|
+
*
|
|
56
|
+
* Replaces query param values for token-like keys, Bearer tokens, and
|
|
57
|
+
* `sk_live` / `sk_test` style secret key literals.
|
|
58
|
+
*
|
|
59
|
+
* @param value - Free-text string that may embed secrets.
|
|
60
|
+
* @returns String with matched secret substrings replaced by `"[REDACTED]"`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function scrubEmbeddedSecrets(value: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Returns an {@link ActionIntent} safe to log or forward after secret scrubbing.
|
|
65
|
+
*
|
|
66
|
+
* Resource query strings are removed; sensitive metadata keys are redacted.
|
|
67
|
+
*
|
|
68
|
+
* @param intent - Original action intent.
|
|
69
|
+
* @returns Shallow copy with scrubbed `resource` and redacted `metadata`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function redactActionIntent(intent: ActionIntent): ActionIntent;
|
|
72
|
+
/**
|
|
73
|
+
* Intent fields retained in audit / authorization projections after scrubbing.
|
|
74
|
+
*/
|
|
75
|
+
export type AuditIntentProjection = {
|
|
76
|
+
/**
|
|
77
|
+
* Intent identifier.
|
|
78
|
+
*/
|
|
79
|
+
intent_id: string;
|
|
80
|
+
/**
|
|
81
|
+
* Policy identifier.
|
|
82
|
+
*/
|
|
83
|
+
policy_id: string;
|
|
84
|
+
/**
|
|
85
|
+
* Agent identifier.
|
|
86
|
+
*/
|
|
87
|
+
agent_id: string;
|
|
88
|
+
/**
|
|
89
|
+
* Action type string.
|
|
90
|
+
*/
|
|
91
|
+
action_type: string;
|
|
92
|
+
/**
|
|
93
|
+
* Scrubbed resource identifier.
|
|
94
|
+
*/
|
|
95
|
+
resource: string;
|
|
96
|
+
/**
|
|
97
|
+
* Optional cost object (unchanged; not secret-scrubbed beyond intent redaction).
|
|
98
|
+
*/
|
|
99
|
+
cost?: ActionIntent["cost"];
|
|
100
|
+
/**
|
|
101
|
+
* Issue timestamp (ISO-8601).
|
|
102
|
+
*/
|
|
103
|
+
issued_at: string;
|
|
104
|
+
/**
|
|
105
|
+
* Redacted metadata; present only in `forensics` mode projections.
|
|
106
|
+
*/
|
|
107
|
+
metadata?: Record<string, string>;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Builds the intent payload stored in audit / authorization rows.
|
|
111
|
+
*
|
|
112
|
+
* `minimal` drops metadata; `forensics` keeps redacted metadata.
|
|
113
|
+
*
|
|
114
|
+
* @param intent - Original action intent.
|
|
115
|
+
* @param mode - Audit retention mode; defaults to {@link DEFAULT_AUDIT_MODE}.
|
|
116
|
+
* @returns Projection suitable for persistence.
|
|
117
|
+
*/
|
|
118
|
+
export declare function projectIntentForAudit(intent: ActionIntent, mode?: AuditMode): AuditIntentProjection;
|
|
119
|
+
/**
|
|
120
|
+
* Inputs for {@link buildEvaluatedAuditDetails}.
|
|
121
|
+
*/
|
|
122
|
+
export type EvaluatedAuditDetailsInput = {
|
|
123
|
+
/**
|
|
124
|
+
* Whether the policy evaluation approved the intent.
|
|
125
|
+
*/
|
|
126
|
+
approved: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Human-readable decision reasons.
|
|
129
|
+
*/
|
|
130
|
+
reasons: string[];
|
|
131
|
+
/**
|
|
132
|
+
* Policy identifier under evaluation.
|
|
133
|
+
*/
|
|
134
|
+
policy_id: string;
|
|
135
|
+
/**
|
|
136
|
+
* Intent being audited.
|
|
137
|
+
*/
|
|
138
|
+
intent: ActionIntent;
|
|
139
|
+
/**
|
|
140
|
+
* Optional audit mode; defaults to {@link DEFAULT_AUDIT_MODE}.
|
|
141
|
+
*/
|
|
142
|
+
mode?: AuditMode;
|
|
143
|
+
/**
|
|
144
|
+
* When true, adds `legacy: true` to the details blob.
|
|
145
|
+
*/
|
|
146
|
+
legacy?: boolean;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Builds the details blob for `policy.evaluated` audit events.
|
|
150
|
+
*
|
|
151
|
+
* @param input - Approval result, policy id, intent, and optional mode/legacy flags.
|
|
152
|
+
* @returns JSON-serializable audit details object.
|
|
153
|
+
*/
|
|
154
|
+
export declare function buildEvaluatedAuditDetails(input: EvaluatedAuditDetailsInput): Record<string, unknown>;
|
|
155
|
+
/**
|
|
156
|
+
* Inputs for {@link buildRecordedAuditDetails}.
|
|
157
|
+
*/
|
|
158
|
+
export type RecordedAuditDetailsInput = {
|
|
159
|
+
/**
|
|
160
|
+
* Recording outcome for the action.
|
|
161
|
+
*/
|
|
162
|
+
outcome: "executed" | "skipped" | "blocked";
|
|
163
|
+
/**
|
|
164
|
+
* Correlated decision id, if any.
|
|
165
|
+
*/
|
|
166
|
+
decision_id?: string | null;
|
|
167
|
+
/**
|
|
168
|
+
* Intent being audited.
|
|
169
|
+
*/
|
|
170
|
+
intent: ActionIntent;
|
|
171
|
+
/**
|
|
172
|
+
* Optional open JSON details; included (redacted) only in `forensics` mode.
|
|
173
|
+
*/
|
|
174
|
+
details?: Record<string, unknown>;
|
|
175
|
+
/**
|
|
176
|
+
* Optional audit mode; defaults to {@link DEFAULT_AUDIT_MODE}.
|
|
177
|
+
*/
|
|
178
|
+
mode?: AuditMode;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Builds the details blob for `action.recorded` audit events.
|
|
182
|
+
*
|
|
183
|
+
* In `forensics` mode, includes a redacted `details` object (empty object when
|
|
184
|
+
* absent). In `minimal` mode, omits the `details` field.
|
|
185
|
+
*
|
|
186
|
+
* @param input - Outcome, intent, and optional decision id / details / mode.
|
|
187
|
+
* @returns JSON-serializable audit details object.
|
|
188
|
+
*/
|
|
189
|
+
export declare function buildRecordedAuditDetails(input: RecordedAuditDetailsInput): Record<string, unknown>;
|
|
190
|
+
/**
|
|
191
|
+
* Resolves audit mode from a policy document or environment default.
|
|
192
|
+
*
|
|
193
|
+
* Prefers a valid `policy.audit_mode`, then a valid `envDefault`, otherwise
|
|
194
|
+
* {@link DEFAULT_AUDIT_MODE}.
|
|
195
|
+
*
|
|
196
|
+
* @param policy - Policy-like object that may carry `audit_mode`, or nullish.
|
|
197
|
+
* @param envDefault - Optional environment default string.
|
|
198
|
+
* @returns Resolved {@link AuditMode}.
|
|
199
|
+
*/
|
|
200
|
+
export declare function resolveAuditMode(policy: {
|
|
201
|
+
audit_mode?: AuditMode | string | null;
|
|
202
|
+
} | null | undefined, envDefault?: string | null): AuditMode;
|
|
203
|
+
/**
|
|
204
|
+
* Builds a minimized authorization request projection for Cloud persistence.
|
|
205
|
+
*
|
|
206
|
+
* Keeps a digest of the original intent; never stores raw secrets.
|
|
207
|
+
*
|
|
208
|
+
* @param input - Tenant/policy ids, intent, digest hex, and optional audit mode.
|
|
209
|
+
* @returns JSON-serializable authorization request projection.
|
|
210
|
+
*/
|
|
211
|
+
export declare function buildMinimizedAuthorizationRequest(input: {
|
|
212
|
+
/**
|
|
213
|
+
* Tenant identifier.
|
|
214
|
+
*/
|
|
215
|
+
tenantId: string;
|
|
216
|
+
/**
|
|
217
|
+
* Policy identifier.
|
|
218
|
+
*/
|
|
219
|
+
policyId: string;
|
|
220
|
+
/**
|
|
221
|
+
* Intent to project into the request.
|
|
222
|
+
*/
|
|
223
|
+
intent: ActionIntent;
|
|
224
|
+
/**
|
|
225
|
+
* Hex digest of the original intent for correlation without storing secrets.
|
|
226
|
+
*/
|
|
227
|
+
intentDigestHex: string;
|
|
228
|
+
/**
|
|
229
|
+
* Optional audit mode; defaults to {@link DEFAULT_AUDIT_MODE}.
|
|
230
|
+
*/
|
|
231
|
+
mode?: AuditMode;
|
|
232
|
+
}): Record<string, unknown>;
|
|
233
|
+
/**
|
|
234
|
+
* Builds a minimized authorization response projection for Cloud persistence.
|
|
235
|
+
*
|
|
236
|
+
* @param input - Decision, reasons, digests, and optional ids / receipt / expiry.
|
|
237
|
+
* @returns JSON-serializable authorization response projection.
|
|
238
|
+
*/
|
|
239
|
+
export declare function buildMinimizedAuthorizationResponse(input: {
|
|
240
|
+
/**
|
|
241
|
+
* Final authorization decision.
|
|
242
|
+
*/
|
|
243
|
+
decision: "allow" | "deny";
|
|
244
|
+
/**
|
|
245
|
+
* Human-readable decision reasons.
|
|
246
|
+
*/
|
|
247
|
+
reasons: string[];
|
|
248
|
+
/**
|
|
249
|
+
* Optional stable decision identifier.
|
|
250
|
+
*/
|
|
251
|
+
decisionId?: string;
|
|
252
|
+
/**
|
|
253
|
+
* Optional authorization row identifier.
|
|
254
|
+
*/
|
|
255
|
+
authorizationId?: string;
|
|
256
|
+
/**
|
|
257
|
+
* Hex digest of the original intent.
|
|
258
|
+
*/
|
|
259
|
+
intentDigestHex: string;
|
|
260
|
+
/**
|
|
261
|
+
* Optional authorization expiry (ISO-8601), or null.
|
|
262
|
+
*/
|
|
263
|
+
expiresAt?: string | null;
|
|
264
|
+
/**
|
|
265
|
+
* Optional opaque decision receipt from the engine.
|
|
266
|
+
*/
|
|
267
|
+
decisionReceipt?: unknown;
|
|
268
|
+
}): Record<string, unknown>;
|
|
269
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../src/privacy/redact.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAqB,CAAA;AAatD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAoBtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAcpC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC3C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAKrC;AAuCD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAe1D;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAMrE;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAC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for scrubbing secrets from intents and building audit projections.
|
|
3
|
+
*
|
|
4
|
+
* Used when persisting authorization requests/responses and `policy.evaluated` /
|
|
5
|
+
* `action.recorded` audit detail blobs so raw credentials are never stored.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Default audit retention mode when a policy or env override is absent.
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_AUDIT_MODE = "minimal";
|
|
11
|
+
/**
|
|
12
|
+
* Case-insensitive pattern matching common secret / credential key names.
|
|
13
|
+
*/
|
|
14
|
+
const SENSITIVE_KEY_PATTERN = /pass(word|wd)?|secret|token|api[_-]?key|authorization|auth|cookie|credential|private[_-]?key|access[_-]?key|refresh|bearer|ssn|credit[_-]?card|cvv|session/i;
|
|
15
|
+
/**
|
|
16
|
+
* Replacement string written in place of redacted secret values.
|
|
17
|
+
*/
|
|
18
|
+
const REDACTED = "[REDACTED]";
|
|
19
|
+
/**
|
|
20
|
+
* Returns whether a metadata/details key name looks like a secret or credential.
|
|
21
|
+
*
|
|
22
|
+
* @param key - Object key to test.
|
|
23
|
+
* @returns `true` when the key name matches known secret/credential patterns.
|
|
24
|
+
*/
|
|
25
|
+
export function isSensitiveKey(key) {
|
|
26
|
+
return SENSITIVE_KEY_PATTERN.test(key);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Strips query string, hash, and URL userinfo from a resource identifier.
|
|
30
|
+
*
|
|
31
|
+
* Non-URL resources are returned unchanged after trimming; if a `?` is present
|
|
32
|
+
* on a non-URL string, only the prefix before the query is kept.
|
|
33
|
+
*
|
|
34
|
+
* @param resource - Resource identifier (URL or opaque string).
|
|
35
|
+
* @returns Scrubbed resource string.
|
|
36
|
+
*/
|
|
37
|
+
export function scrubResource(resource) {
|
|
38
|
+
const trimmed = resource.trim();
|
|
39
|
+
if (trimmed.length === 0) {
|
|
40
|
+
return trimmed;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const url = new URL(trimmed);
|
|
44
|
+
url.username = "";
|
|
45
|
+
url.password = "";
|
|
46
|
+
url.search = "";
|
|
47
|
+
url.hash = "";
|
|
48
|
+
return url.toString();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
const queryIndex = trimmed.indexOf("?");
|
|
52
|
+
if (queryIndex >= 0) {
|
|
53
|
+
return trimmed.slice(0, queryIndex);
|
|
54
|
+
}
|
|
55
|
+
return trimmed;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Drops or redacts sensitive keys from a string metadata map.
|
|
60
|
+
*
|
|
61
|
+
* Sensitive keys keep their key but get value `"[REDACTED]"`; other values
|
|
62
|
+
* pass through {@link scrubEmbeddedSecrets}. Returns `undefined` for empty
|
|
63
|
+
* or missing input.
|
|
64
|
+
*
|
|
65
|
+
* @param metadata - Optional string key/value metadata bag.
|
|
66
|
+
* @returns Redacted metadata, or `undefined` when empty/absent.
|
|
67
|
+
*/
|
|
68
|
+
export function redactMetadata(metadata) {
|
|
69
|
+
if (!metadata) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const next = {};
|
|
73
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
74
|
+
if (isSensitiveKey(key)) {
|
|
75
|
+
next[key] = REDACTED;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
next[key] = scrubEmbeddedSecrets(value);
|
|
79
|
+
}
|
|
80
|
+
return Object.keys(next).length > 0 ? next : undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Recursively redacts sensitive keys and scrubs string values in open JSON bags.
|
|
84
|
+
*
|
|
85
|
+
* @param details - Optional open JSON object.
|
|
86
|
+
* @returns Redacted deep copy, or `undefined` when input is absent.
|
|
87
|
+
*/
|
|
88
|
+
export function redactDetails(details) {
|
|
89
|
+
if (!details) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return redactUnknownRecord(details);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Redacts every entry in a plain object, replacing sensitive keys with `"[REDACTED]"`.
|
|
96
|
+
*
|
|
97
|
+
* @param value - Plain object to redact.
|
|
98
|
+
* @returns New object with redacted children.
|
|
99
|
+
*/
|
|
100
|
+
function redactUnknownRecord(value) {
|
|
101
|
+
const next = {};
|
|
102
|
+
for (const [key, child] of Object.entries(value)) {
|
|
103
|
+
if (isSensitiveKey(key)) {
|
|
104
|
+
next[key] = REDACTED;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
next[key] = redactUnknownValue(child);
|
|
108
|
+
}
|
|
109
|
+
return next;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Redacts a single JSON value (string, array, object, or primitive).
|
|
113
|
+
*
|
|
114
|
+
* @param value - Value to scrub.
|
|
115
|
+
* @returns Scrubbed value of the same structural shape.
|
|
116
|
+
*/
|
|
117
|
+
function redactUnknownValue(value) {
|
|
118
|
+
if (typeof value === "string") {
|
|
119
|
+
return scrubEmbeddedSecrets(value);
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(value)) {
|
|
122
|
+
return value.map((entry) => redactUnknownValue(entry));
|
|
123
|
+
}
|
|
124
|
+
if (value && typeof value === "object") {
|
|
125
|
+
return redactUnknownRecord(value);
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Redacts common secret patterns embedded in free-text / URL query values.
|
|
131
|
+
*
|
|
132
|
+
* Replaces query param values for token-like keys, Bearer tokens, and
|
|
133
|
+
* `sk_live` / `sk_test` style secret key literals.
|
|
134
|
+
*
|
|
135
|
+
* @param value - Free-text string that may embed secrets.
|
|
136
|
+
* @returns String with matched secret substrings replaced by `"[REDACTED]"`.
|
|
137
|
+
*/
|
|
138
|
+
export function scrubEmbeddedSecrets(value) {
|
|
139
|
+
let next = value;
|
|
140
|
+
next = next.replace(/([?&](?:access_token|api_key|token|key|secret|password|auth)=)([^&#]*)/gi, `$1${REDACTED}`);
|
|
141
|
+
next = next.replace(/\b(Bearer\s+)[A-Za-z0-9\-._~+/]+=*/gi, `$1${REDACTED}`);
|
|
142
|
+
next = next.replace(/\b(sk[-_](?:live|test)[-_][A-Za-z0-9]+)/g, REDACTED);
|
|
143
|
+
return next;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Returns an {@link ActionIntent} safe to log or forward after secret scrubbing.
|
|
147
|
+
*
|
|
148
|
+
* Resource query strings are removed; sensitive metadata keys are redacted.
|
|
149
|
+
*
|
|
150
|
+
* @param intent - Original action intent.
|
|
151
|
+
* @returns Shallow copy with scrubbed `resource` and redacted `metadata`.
|
|
152
|
+
*/
|
|
153
|
+
export function redactActionIntent(intent) {
|
|
154
|
+
return {
|
|
155
|
+
...intent,
|
|
156
|
+
resource: scrubResource(intent.resource),
|
|
157
|
+
metadata: redactMetadata(intent.metadata),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Builds the intent payload stored in audit / authorization rows.
|
|
162
|
+
*
|
|
163
|
+
* `minimal` drops metadata; `forensics` keeps redacted metadata.
|
|
164
|
+
*
|
|
165
|
+
* @param intent - Original action intent.
|
|
166
|
+
* @param mode - Audit retention mode; defaults to {@link DEFAULT_AUDIT_MODE}.
|
|
167
|
+
* @returns Projection suitable for persistence.
|
|
168
|
+
*/
|
|
169
|
+
export function projectIntentForAudit(intent, mode = DEFAULT_AUDIT_MODE) {
|
|
170
|
+
const redacted = redactActionIntent(intent);
|
|
171
|
+
if (mode === "forensics") {
|
|
172
|
+
return {
|
|
173
|
+
intent_id: redacted.intent_id,
|
|
174
|
+
policy_id: redacted.policy_id,
|
|
175
|
+
agent_id: redacted.agent_id,
|
|
176
|
+
action_type: redacted.action_type,
|
|
177
|
+
resource: redacted.resource,
|
|
178
|
+
cost: redacted.cost,
|
|
179
|
+
issued_at: redacted.issued_at,
|
|
180
|
+
metadata: redacted.metadata,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
intent_id: redacted.intent_id,
|
|
185
|
+
policy_id: redacted.policy_id,
|
|
186
|
+
agent_id: redacted.agent_id,
|
|
187
|
+
action_type: redacted.action_type,
|
|
188
|
+
resource: redacted.resource,
|
|
189
|
+
cost: redacted.cost,
|
|
190
|
+
issued_at: redacted.issued_at,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Builds the details blob for `policy.evaluated` audit events.
|
|
195
|
+
*
|
|
196
|
+
* @param input - Approval result, policy id, intent, and optional mode/legacy flags.
|
|
197
|
+
* @returns JSON-serializable audit details object.
|
|
198
|
+
*/
|
|
199
|
+
export function buildEvaluatedAuditDetails(input) {
|
|
200
|
+
const mode = input.mode ?? DEFAULT_AUDIT_MODE;
|
|
201
|
+
const projected = projectIntentForAudit(input.intent, mode);
|
|
202
|
+
return {
|
|
203
|
+
approved: input.approved,
|
|
204
|
+
reasons: input.reasons,
|
|
205
|
+
policy_id: input.policy_id,
|
|
206
|
+
agent_id: projected.agent_id,
|
|
207
|
+
action_type: projected.action_type,
|
|
208
|
+
resource: projected.resource,
|
|
209
|
+
audit_mode: mode,
|
|
210
|
+
intent: projected,
|
|
211
|
+
...(input.legacy ? { legacy: true } : {}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Builds the details blob for `action.recorded` audit events.
|
|
216
|
+
*
|
|
217
|
+
* In `forensics` mode, includes a redacted `details` object (empty object when
|
|
218
|
+
* absent). In `minimal` mode, omits the `details` field.
|
|
219
|
+
*
|
|
220
|
+
* @param input - Outcome, intent, and optional decision id / details / mode.
|
|
221
|
+
* @returns JSON-serializable audit details object.
|
|
222
|
+
*/
|
|
223
|
+
export function buildRecordedAuditDetails(input) {
|
|
224
|
+
const mode = input.mode ?? DEFAULT_AUDIT_MODE;
|
|
225
|
+
const projected = projectIntentForAudit(input.intent, mode);
|
|
226
|
+
const base = {
|
|
227
|
+
outcome: input.outcome,
|
|
228
|
+
decision_id: input.decision_id ?? null,
|
|
229
|
+
agent_id: projected.agent_id,
|
|
230
|
+
action_type: projected.action_type,
|
|
231
|
+
resource: projected.resource,
|
|
232
|
+
audit_mode: mode,
|
|
233
|
+
intent: projected,
|
|
234
|
+
};
|
|
235
|
+
if (mode === "forensics") {
|
|
236
|
+
base.details = redactDetails(input.details) ?? {};
|
|
237
|
+
}
|
|
238
|
+
return base;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Resolves audit mode from a policy document or environment default.
|
|
242
|
+
*
|
|
243
|
+
* Prefers a valid `policy.audit_mode`, then a valid `envDefault`, otherwise
|
|
244
|
+
* {@link DEFAULT_AUDIT_MODE}.
|
|
245
|
+
*
|
|
246
|
+
* @param policy - Policy-like object that may carry `audit_mode`, or nullish.
|
|
247
|
+
* @param envDefault - Optional environment default string.
|
|
248
|
+
* @returns Resolved {@link AuditMode}.
|
|
249
|
+
*/
|
|
250
|
+
export function resolveAuditMode(policy, envDefault) {
|
|
251
|
+
const fromPolicy = policy?.audit_mode;
|
|
252
|
+
if (fromPolicy === "minimal" || fromPolicy === "forensics") {
|
|
253
|
+
return fromPolicy;
|
|
254
|
+
}
|
|
255
|
+
if (envDefault === "minimal" || envDefault === "forensics") {
|
|
256
|
+
return envDefault;
|
|
257
|
+
}
|
|
258
|
+
return DEFAULT_AUDIT_MODE;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Builds a minimized authorization request projection for Cloud persistence.
|
|
262
|
+
*
|
|
263
|
+
* Keeps a digest of the original intent; never stores raw secrets.
|
|
264
|
+
*
|
|
265
|
+
* @param input - Tenant/policy ids, intent, digest hex, and optional audit mode.
|
|
266
|
+
* @returns JSON-serializable authorization request projection.
|
|
267
|
+
*/
|
|
268
|
+
export function buildMinimizedAuthorizationRequest(input) {
|
|
269
|
+
const mode = input.mode ?? DEFAULT_AUDIT_MODE;
|
|
270
|
+
return {
|
|
271
|
+
tenant_id: input.tenantId,
|
|
272
|
+
policy_id: input.policyId,
|
|
273
|
+
intent_digest_hex: input.intentDigestHex,
|
|
274
|
+
audit_mode: mode,
|
|
275
|
+
intent: projectIntentForAudit(input.intent, mode),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Builds a minimized authorization response projection for Cloud persistence.
|
|
280
|
+
*
|
|
281
|
+
* @param input - Decision, reasons, digests, and optional ids / receipt / expiry.
|
|
282
|
+
* @returns JSON-serializable authorization response projection.
|
|
283
|
+
*/
|
|
284
|
+
export function buildMinimizedAuthorizationResponse(input) {
|
|
285
|
+
return {
|
|
286
|
+
decision: input.decision,
|
|
287
|
+
reasons: input.reasons,
|
|
288
|
+
decision_id: input.decisionId ?? null,
|
|
289
|
+
authorization_id: input.authorizationId ?? null,
|
|
290
|
+
intent_digest_hex: input.intentDigestHex,
|
|
291
|
+
expires_at: input.expiresAt ?? null,
|
|
292
|
+
decision_receipt: input.decisionReceipt ?? null,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../src/privacy/redact.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAc,SAAS,CAAA;AAEtD;;GAEG;AACH,MAAM,qBAAqB,GACzB,6JAA6J,CAAA;AAE/J;;GAEG;AACH,MAAM,QAAQ,GAAG,YAAY,CAAA;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC/B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAA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