zitejs 0.10.0-start.2 → 0.10.0-start.21
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/cjs/auth/actions.d.ts +28 -0
- package/dist/cjs/auth/actions.js +93 -0
- package/dist/cjs/auth/client.d.ts +357 -0
- package/dist/cjs/auth/client.js +66 -0
- package/dist/cjs/auth/index.d.ts +2 -249
- package/dist/cjs/auth/index.js +11 -108
- package/dist/cjs/auth/index.test.js +48 -0
- package/dist/cjs/auth/previewClaim.d.ts +7 -0
- package/dist/cjs/auth/previewClaim.js +16 -0
- package/dist/cjs/auth/profileUpdates.d.ts +9 -0
- package/dist/cjs/auth/profileUpdates.js +11 -0
- package/dist/cjs/backend/index.d.ts +121 -3
- package/dist/cjs/backend/index.test.js +58 -0
- package/dist/cjs/bundle/index.d.ts +8 -0
- package/dist/cjs/bundle/index.js +9 -8
- package/dist/cjs/check/index.d.ts +45 -1
- package/dist/cjs/check/index.js +198 -109
- package/dist/cjs/check/start/problem.d.ts +11 -0
- package/dist/cjs/check/start/problem.js +5 -0
- package/dist/cjs/check/start/routeTree.d.ts +9 -0
- package/dist/cjs/check/start/routeTree.js +111 -0
- package/dist/cjs/check/start/sourceRules.d.ts +8 -0
- package/dist/cjs/check/start/sourceRules.js +1159 -0
- package/dist/cjs/check/start/tsgo.d.ts +2 -0
- package/dist/cjs/check/start/tsgo.js +35 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/client/index.d.ts +24 -0
- package/dist/cjs/dev/index.js +14 -4
- package/dist/cjs/integrations/rules.d.ts +13 -0
- package/dist/cjs/integrations/rules.js +31 -0
- package/dist/cjs/integrations/rules.test.js +1 -0
- package/dist/cjs/internal/appMode.d.ts +3 -0
- package/dist/cjs/internal/appMode.js +15 -0
- package/dist/cjs/runtime/index.d.ts +64 -25
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +33 -0
- package/dist/cjs/start/entries.d.ts +10 -4
- package/dist/cjs/start/entries.js +23 -6
- package/dist/cjs/steps/index.d.ts +78 -0
- package/dist/cjs/steps/index.js +507 -0
- package/dist/cjs/steps/index.test.d.ts +1 -0
- package/dist/cjs/steps/index.test.js +635 -0
- package/dist/cjs/sync/index.js +2 -1
- package/dist/cjs/sync/lib.d.ts +10 -3
- package/dist/cjs/sync/lib.js +44 -25
- package/dist/cjs/sync/lib.test.js +116 -36
- package/dist/cjs/types/fields.d.ts +8 -1
- package/dist/cjs/types/fields.js +7 -1
- package/dist/cjs/types/tables.d.ts +16 -0
- package/dist/cjs/upload/index.js +12 -2
- package/dist/cjs/upload/index.test.js +39 -0
- package/dist/cjs/vite/index.js +8 -3
- package/dist/cjs/vite/index.test.js +10 -2
- package/dist/esm/auth/actions.d.ts +28 -0
- package/dist/esm/auth/actions.js +55 -0
- package/dist/esm/auth/client.d.ts +357 -0
- package/dist/esm/auth/client.js +62 -0
- package/dist/esm/auth/index.d.ts +2 -249
- package/dist/esm/auth/index.js +2 -103
- package/dist/esm/auth/index.test.js +48 -0
- package/dist/esm/auth/previewClaim.d.ts +7 -0
- package/dist/esm/auth/previewClaim.js +12 -0
- package/dist/esm/auth/profileUpdates.d.ts +9 -0
- package/dist/esm/auth/profileUpdates.js +6 -0
- package/dist/esm/backend/index.d.ts +121 -3
- package/dist/esm/backend/index.test.js +58 -0
- package/dist/esm/bundle/index.d.ts +8 -0
- package/dist/esm/bundle/index.js +8 -8
- package/dist/esm/check/index.d.ts +45 -1
- package/dist/esm/check/index.js +198 -113
- package/dist/esm/check/start/problem.d.ts +11 -0
- package/dist/esm/check/start/problem.js +1 -0
- package/dist/esm/check/start/routeTree.d.ts +9 -0
- package/dist/esm/check/start/routeTree.js +70 -0
- package/dist/esm/check/start/sourceRules.d.ts +8 -0
- package/dist/esm/check/start/sourceRules.js +1156 -0
- package/dist/esm/check/start/tsgo.d.ts +2 -0
- package/dist/esm/check/start/tsgo.js +29 -0
- package/dist/esm/cli.js +1 -1
- package/dist/esm/client/index.d.ts +24 -0
- package/dist/esm/dev/index.js +16 -6
- package/dist/esm/integrations/rules.d.ts +13 -0
- package/dist/esm/integrations/rules.js +31 -0
- package/dist/esm/integrations/rules.test.js +1 -0
- package/dist/esm/internal/appMode.d.ts +3 -0
- package/dist/esm/internal/appMode.js +10 -0
- package/dist/esm/runtime/index.d.ts +64 -25
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +31 -0
- package/dist/esm/start/aiUsage.d.ts +23 -0
- package/dist/esm/start/aiUsage.js +146 -0
- package/dist/esm/start/airtable/arrayFields.d.ts +10 -0
- package/dist/esm/start/airtable/arrayFields.js +30 -0
- package/dist/esm/start/airtable/dispatch.d.ts +54 -0
- package/dist/esm/start/airtable/dispatch.js +483 -0
- package/dist/esm/start/airtable/formulas.d.ts +70 -0
- package/dist/esm/start/airtable/formulas.js +260 -0
- package/dist/esm/start/airtable/index.d.ts +8 -0
- package/dist/esm/start/airtable/index.js +54 -0
- package/dist/esm/start/authHooks.d.ts +7 -0
- package/dist/esm/start/authHooks.js +10 -0
- package/dist/esm/start/authHooksModule.d.ts +1 -0
- package/dist/esm/start/authHooksModule.js +3 -0
- package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
- package/dist/esm/start/clientErrorMessage.test.js +105 -0
- package/dist/esm/start/credentials.d.ts +2 -0
- package/dist/esm/start/credentials.js +2 -0
- package/dist/esm/start/data/baseRunner.d.ts +92 -0
- package/dist/esm/start/data/baseRunner.js +83 -0
- package/dist/esm/start/data/dispatch.d.ts +16 -0
- package/dist/esm/start/data/dispatch.js +198 -0
- package/dist/esm/start/data/index.d.ts +15 -0
- package/dist/esm/start/data/index.js +58 -0
- package/dist/esm/start/data/sqlNameMappings.d.ts +58 -0
- package/dist/esm/start/data/sqlNameMappings.js +92 -0
- package/dist/esm/start/data/transformations.d.ts +97 -0
- package/dist/esm/start/data/transformations.js +262 -0
- package/dist/esm/start/data/types.d.ts +91 -0
- package/dist/esm/start/data/types.js +14 -0
- package/dist/esm/start/describe.d.ts +42 -5
- package/dist/esm/start/describe.js +77 -23
- package/dist/esm/start/entries.d.ts +10 -4
- package/dist/esm/start/entries.js +21 -5
- package/dist/esm/start/errors.d.ts +63 -0
- package/dist/esm/start/errors.js +146 -0
- package/dist/esm/start/errors.test.d.ts +1 -0
- package/dist/esm/start/errors.test.js +23 -0
- package/dist/esm/start/factories.test-d.d.ts +2 -0
- package/dist/esm/start/factories.test-d.js +20 -0
- package/dist/esm/start/host.d.ts +2 -2
- package/dist/esm/start/index.d.ts +32 -27
- package/dist/esm/start/index.js +79 -47
- package/dist/esm/start/instance.d.ts +4 -4
- package/dist/esm/start/instance.js +54 -11
- package/dist/esm/start/outbound.d.ts +11 -0
- package/dist/esm/start/outbound.js +400 -0
- package/dist/esm/start/previewClaim.d.ts +7 -0
- package/dist/esm/start/previewClaim.js +23 -0
- package/dist/esm/start/problems.js +1 -1
- package/dist/esm/start/quiet.d.ts +2 -0
- package/dist/esm/start/quiet.js +27 -0
- package/dist/esm/start/redactSecrets.d.ts +15 -0
- package/dist/esm/start/redactSecrets.js +154 -0
- package/dist/esm/start/redactSecrets.test.d.ts +1 -0
- package/dist/esm/start/redactSecrets.test.js +151 -0
- package/dist/esm/start/registration.d.ts +13 -0
- package/dist/esm/start/registration.js +21 -0
- package/dist/esm/start/registrationHash.d.ts +22 -0
- package/dist/esm/start/registrationHash.js +470 -0
- package/dist/esm/start/router.d.ts +25 -4
- package/dist/esm/start/router.js +169 -11
- package/dist/esm/start/runLog.d.ts +7 -4
- package/dist/esm/start/runLog.js +64 -6
- package/dist/esm/start/scope.d.ts +4 -4
- package/dist/esm/start/server.d.ts +40 -36
- package/dist/esm/start/server.js +322 -49
- package/dist/esm/start/steps.d.ts +28 -0
- package/dist/esm/start/steps.js +97 -0
- package/dist/esm/start/types.d.ts +179 -6
- package/dist/esm/start/version.d.ts +1 -0
- package/dist/esm/start/version.js +2 -0
- package/dist/esm/start/vite.js +91 -14
- package/dist/esm/start/worker.d.ts +6 -0
- package/dist/esm/start/worker.js +12 -0
- package/dist/esm/start/workflow.d.ts +46 -12
- package/dist/esm/start/workflow.js +10 -3
- package/dist/esm/start/workflow.test-d.js +50 -8
- package/dist/esm/start/workflowModules.js +1 -1
- package/dist/esm/start/workflowRun.d.ts +26 -8
- package/dist/esm/start/workflowRun.js +39 -8
- package/dist/esm/steps/index.d.ts +78 -0
- package/dist/esm/steps/index.js +502 -0
- package/dist/esm/steps/index.test.d.ts +1 -0
- package/dist/esm/steps/index.test.js +633 -0
- package/dist/esm/sync/index.js +2 -1
- package/dist/esm/sync/lib.d.ts +10 -3
- package/dist/esm/sync/lib.js +44 -25
- package/dist/esm/sync/lib.test.js +116 -36
- package/dist/esm/types/fields.d.ts +8 -1
- package/dist/esm/types/fields.js +6 -0
- package/dist/esm/types/tables.d.ts +16 -0
- package/dist/esm/upload/index.js +12 -2
- package/dist/esm/upload/index.test.js +39 -0
- package/dist/esm/vite/index.js +8 -3
- package/dist/esm/vite/index.test.js +10 -2
- package/package.json +37 -16
- package/dist/cjs/start/problems.d.ts +0 -19
- package/dist/cjs/start/problems.js +0 -11
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Ported from restly's shared/src/redactSecrets.ts, so a live Start app redacts
|
|
2
|
+
// exactly what a classic one does. Keep the two in step.
|
|
3
|
+
export const REDACTED = "REDACTED";
|
|
4
|
+
/**
|
|
5
|
+
* A run of characters that can plausibly be a secret's value. Stops at
|
|
6
|
+
* whitespace and at the punctuation that normally *ends* a value in a sentence
|
|
7
|
+
* or a serialized payload, so the redaction does not swallow the rest of the
|
|
8
|
+
* text after it.
|
|
9
|
+
*/
|
|
10
|
+
const VALUE_RUN = String.raw `[^\s,;)\]}"'<>]+`;
|
|
11
|
+
const CREDENTIAL_KEY = String.raw `(?:password|passwd|secret|api[_-]?key|apikey|access[_-]?token|refresh[_-]?token|auth[_-]?token|client[_-]?secret|private[_-]?key)`;
|
|
12
|
+
// The scheme is length-capped because, unbounded, every position in a long
|
|
13
|
+
// alphanumeric run (hex, a base64 blob) rescans to the end of the run —
|
|
14
|
+
// quadratic, and minutes of blocked event loop on a megabyte of output.
|
|
15
|
+
const URL_USERINFO = String.raw `([a-z][a-z0-9+.-]{0,31}:\/\/[^\s:/@]+:)`;
|
|
16
|
+
const JSON_MEMBER = String.raw `("${CREDENTIAL_KEY}"\s*:\s*")`;
|
|
17
|
+
const JSON_VALUE = String.raw `(?:[^"\\]|\\.)*`;
|
|
18
|
+
const ESCAPED_JSON_MEMBER = String.raw `(\\"${CREDENTIAL_KEY}\\"\s*:\s*\\")`;
|
|
19
|
+
const ESCAPED_JSON_VALUE = String.raw `(?:[^"\\]|\\\\(?:\\["\\]|[^"\\]))*`;
|
|
20
|
+
const PATTERNS = [
|
|
21
|
+
{
|
|
22
|
+
// URL userinfo: scheme://user:password@host. Keeps the scheme, the user,
|
|
23
|
+
// and the host — the parts that identify *which* connection failed.
|
|
24
|
+
pattern: new RegExp(URL_USERINFO + String.raw `[^\s@/]+(@)`, "gi"),
|
|
25
|
+
replace: `$1${REDACTED}$2`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
// Bearer tokens. RFC 6750 `token68` permits a single character, so a length
|
|
29
|
+
// floor lets short opaque tokens through. Same shape guard as Basic below:
|
|
30
|
+
// reject a value that is one alphabetic word, so "Bearer token required"
|
|
31
|
+
// survives while anything mixing case or digits is redacted. Case-sensitive
|
|
32
|
+
// for the same reason as Basic, so the scheme is spelled out.
|
|
33
|
+
//
|
|
34
|
+
// `Token` is deliberately not treated as a scheme: it is a GitHub-ism
|
|
35
|
+
// rather than a registered one, and "Token" is a common enough English word
|
|
36
|
+
// that it matched the next word in prose. The credentials it precedes are
|
|
37
|
+
// already covered by the `gh*_` prefixes below.
|
|
38
|
+
pattern: new RegExp(String.raw `\b([Bb]earer)\s+(?![A-Za-z][a-z]*(?![A-Za-z0-9._~+/=-]))([A-Za-z0-9._~+/=-]+)`, "g"),
|
|
39
|
+
replace: `$1 ${REDACTED}`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
// Basic credentials are base64 of "user:pass" and can be legitimately
|
|
43
|
+
// short — base64("u:pw") is four characters — so the 16-char floor used for
|
|
44
|
+
// Bearer would let real credentials through.
|
|
45
|
+
//
|
|
46
|
+
// Length alone therefore cannot separate a credential from prose, and
|
|
47
|
+
// "Basic plan" / "Basic tier" / "Basic Auth" are exactly the kind of copy a
|
|
48
|
+
// subscription app writes. The guard is shape instead: reject the value if
|
|
49
|
+
// it is a single alphabetic word (one letter followed by lowercase to the
|
|
50
|
+
// end of the token). Base64 of any realistic "user:pass" mixes case or
|
|
51
|
+
// digits and so survives the guard, while an English word does not.
|
|
52
|
+
//
|
|
53
|
+
// Case-sensitive by necessity — an `i` flag would make `[a-z]` match
|
|
54
|
+
// uppercase and collapse that distinction — so the scheme is spelled out
|
|
55
|
+
// to still accept the lowercase form.
|
|
56
|
+
pattern: new RegExp(String.raw `\b([Bb]asic)\s+(?![A-Za-z][a-z]*(?![A-Za-z0-9+/=]))([A-Za-z0-9+/=]{4,})`, "g"),
|
|
57
|
+
replace: `$1 ${REDACTED}`,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
// JWTs, which carry claims and are frequently the credential itself. The
|
|
61
|
+
// header is capped for the same reason as the scheme above (a run of
|
|
62
|
+
// `-eyJ` fragments restarts at each one); a JWT has to fit in an HTTP
|
|
63
|
+
// header, so 8KB loses nothing real.
|
|
64
|
+
pattern: /\beyJ[A-Za-z0-9_-]{8,8192}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,
|
|
65
|
+
replace: REDACTED,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
// Provider secret keys, matched on each vendor's published prefix.
|
|
69
|
+
// OpenAI/Anthropic `sk-`, Stripe `sk_live_`/`sk_test_`/`rk_live_`.
|
|
70
|
+
// Stripe's publishable `pk_` keys are deliberately absent: they are
|
|
71
|
+
// designed to ship to browsers, so redacting them only loses detail.
|
|
72
|
+
pattern: /\b(?:sk-(?:ant-)?|sk_live_|sk_test_|rk_live_)[A-Za-z0-9_-]{16,}/g,
|
|
73
|
+
replace: REDACTED,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
// AWS access key ids (AKIA long-lived, ASIA temporary) and Google API keys.
|
|
77
|
+
// Google's are documented as AIza + 35 chars; the open-ended quantifier
|
|
78
|
+
// means an unexpectedly long variant is redacted whole rather than having
|
|
79
|
+
// its first 39 characters replaced and the remainder left exposed.
|
|
80
|
+
pattern: /\b(?:A[KS]IA[0-9A-Z]{16}\b|AIza[0-9A-Za-z_-]{35,})/g,
|
|
81
|
+
replace: REDACTED,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
// GitHub (`ghp_`, `gho_`, `ghu_`, `ghs_`, `ghr_`) and Slack (`xoxb-` etc).
|
|
85
|
+
pattern: /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|xox[abprs]-[A-Za-z0-9-]{10,})\b/g,
|
|
86
|
+
replace: REDACTED,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
// Credential-bearing key/value pairs, in query strings, connection strings
|
|
90
|
+
// and serialized config alike. Anchored on the key name plus its separator,
|
|
91
|
+
// and the key must be a whole token so an app's "reset_password_url=..."
|
|
92
|
+
// style key is not mistaken for the secret itself.
|
|
93
|
+
//
|
|
94
|
+
// The leading boundary is a captured alternation rather than a lookbehind:
|
|
95
|
+
// this module is exported from @fillout/shared and so can be bundled into
|
|
96
|
+
// the frontend, where an unsupported lookbehind would throw while building
|
|
97
|
+
// the RegExp at module load and take the whole bundle down with it.
|
|
98
|
+
pattern: new RegExp(String.raw `(^|[^\w-])(${CREDENTIAL_KEY})(\s*[:=]\s*)` + VALUE_RUN, "gi"),
|
|
99
|
+
replace: `$1$2$3${REDACTED}`,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
// The same keys as JSON string members. The closing quote after the key
|
|
103
|
+
// sits between it and the colon, so the pattern above never sees them.
|
|
104
|
+
pattern: new RegExp(JSON_MEMBER + JSON_VALUE + '"', "gi"),
|
|
105
|
+
replace: `$1${REDACTED}"`,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
// ...and as members of JSON serialized into another JSON string, where
|
|
109
|
+
// every quote arrives as \" and the value's own escapes are doubled, so a
|
|
110
|
+
// \\\" inside the value is an escaped quote rather than its end.
|
|
111
|
+
pattern: new RegExp(ESCAPED_JSON_MEMBER + ESCAPED_JSON_VALUE + String.raw `\\"`, "gi"),
|
|
112
|
+
replace: `$1${REDACTED}\\"`,
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
/**
|
|
116
|
+
* Replace any credentials in `text` with a placeholder, leaving the rest
|
|
117
|
+
* intact. Returns the input unchanged when there is nothing to redact, so
|
|
118
|
+
* callers that pass clean text see byte-identical output.
|
|
119
|
+
*/
|
|
120
|
+
export function redactSecrets(text) {
|
|
121
|
+
if (!text)
|
|
122
|
+
return text;
|
|
123
|
+
let result = text;
|
|
124
|
+
for (const { pattern, replace } of PATTERNS) {
|
|
125
|
+
// The patterns are global, so reset lastIndex — these RegExp objects are
|
|
126
|
+
// module-level and reused across calls.
|
|
127
|
+
pattern.lastIndex = 0;
|
|
128
|
+
result = result.replace(pattern, replace);
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
/** The ways a secret is written into text, longest first: as it is, URL-encoded in either case, form-encoded, JSON-escaped. */
|
|
133
|
+
export function secretForms(value) {
|
|
134
|
+
const lower = (text) => text.replace(/%[0-9A-F]{2}/g, (hex) => hex.toLowerCase());
|
|
135
|
+
const encoded = encodeURIComponent(value);
|
|
136
|
+
const form = new URLSearchParams({ v: value }).toString().slice(2);
|
|
137
|
+
const json = JSON.stringify(value).slice(1, -1);
|
|
138
|
+
return [...new Set([value, encoded, lower(encoded), form, lower(form), json])].sort((a, b) => b.length - a.length);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* `text` with each of `values`, however it was written, replaced, then
|
|
142
|
+
* anything the patterns above find. `values` longest first, so none is left
|
|
143
|
+
* half-done.
|
|
144
|
+
*/
|
|
145
|
+
export function redactKnown(text, values) {
|
|
146
|
+
let result = text;
|
|
147
|
+
for (const value of values) {
|
|
148
|
+
for (const form of secretForms(value)) {
|
|
149
|
+
if (result.includes(form))
|
|
150
|
+
result = result.split(form).join(REDACTED);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return redactSecrets(result);
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Classic's cases (restly shared/src/redactSecrets.test.ts), for the port beside it.
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
import { redactSecrets, REDACTED } from './redactSecrets.js';
|
|
4
|
+
describe('redactSecrets', () => {
|
|
5
|
+
describe('keeps the surrounding message', () => {
|
|
6
|
+
it('redacts a connection string password but keeps scheme, user and host', () => {
|
|
7
|
+
expect(redactSecrets('Failed to sync roster: postgres://svc:hunter2@db.internal:5432/prod')).toBe(`Failed to sync roster: postgres://svc:${REDACTED}@db.internal:5432/prod`);
|
|
8
|
+
});
|
|
9
|
+
it('leaves the sentence readable around a redacted key', () => {
|
|
10
|
+
expect(redactSecrets('Stripe rejected the charge (key sk_live_abcdefghijklmnop1234) — retry later')).toBe(`Stripe rejected the charge (key ${REDACTED}) — retry later`);
|
|
11
|
+
});
|
|
12
|
+
it('does not swallow text following a key=value pair', () => {
|
|
13
|
+
expect(redactSecrets('config invalid: api_key=abc123def456, region=us-west-2')).toBe(`config invalid: api_key=${REDACTED}, region=us-west-2`);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('credential formats', () => {
|
|
17
|
+
it('redacts bearer tokens', () => {
|
|
18
|
+
expect(redactSecrets('Authorization: Bearer abcdef1234567890XYZ')).toBe(`Authorization: Bearer ${REDACTED}`);
|
|
19
|
+
});
|
|
20
|
+
it('redacts a short opaque bearer token', () => {
|
|
21
|
+
// RFC 6750 token68 permits values this short, so shape decides, not length.
|
|
22
|
+
expect(redactSecrets('Authorization: Bearer abc123')).toBe(`Authorization: Bearer ${REDACTED}`);
|
|
23
|
+
});
|
|
24
|
+
it('redacts short Basic credentials, which base64 makes legitimately tiny', () => {
|
|
25
|
+
// base64("u:pw") — four characters.
|
|
26
|
+
expect(redactSecrets('Authorization: Basic dTpw')).toBe(`Authorization: Basic ${REDACTED}`);
|
|
27
|
+
expect(redactSecrets('basic YWI6Y2Q=')).toBe(`basic ${REDACTED}`);
|
|
28
|
+
});
|
|
29
|
+
it('redacts a full-length Basic credential', () => {
|
|
30
|
+
expect(redactSecrets('Basic YWxhZGRpbjpvcGVuc2VzYW1l')).toBe(`Basic ${REDACTED}`);
|
|
31
|
+
});
|
|
32
|
+
it('redacts JWTs', () => {
|
|
33
|
+
const jwt = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dQw4w9WgXcQ';
|
|
34
|
+
expect(redactSecrets(`token rejected: ${jwt}`)).toBe(`token rejected: ${REDACTED}`);
|
|
35
|
+
});
|
|
36
|
+
it('redacts OpenAI and Anthropic style keys', () => {
|
|
37
|
+
expect(redactSecrets('sk-ant-api03-abcdefghijklmnopqrstuv')).toBe(REDACTED);
|
|
38
|
+
expect(redactSecrets('sk-abcdefghijklmnopqrstuvwxyz')).toBe(REDACTED);
|
|
39
|
+
});
|
|
40
|
+
it('redacts AWS access key ids and Google API keys', () => {
|
|
41
|
+
expect(redactSecrets('using AKIAIOSFODNN7EXAMPLE for s3')).toBe(`using ${REDACTED} for s3`);
|
|
42
|
+
expect(redactSecrets('key AIzaSyA1234567890abcdefghijklmnopqrstuvw rejected')).toBe(`key ${REDACTED} rejected`);
|
|
43
|
+
});
|
|
44
|
+
it('redacts GitHub and Slack tokens', () => {
|
|
45
|
+
expect(redactSecrets('ghp_abcdefghijklmnopqrstuvwxyz0123456789')).toBe(REDACTED);
|
|
46
|
+
expect(redactSecrets('xoxb-1234567890-abcdefghij')).toBe(REDACTED);
|
|
47
|
+
});
|
|
48
|
+
it('redacts credential key/value pairs in either separator style', () => {
|
|
49
|
+
expect(redactSecrets('password: hunter2')).toBe(`password: ${REDACTED}`);
|
|
50
|
+
expect(redactSecrets('client_secret=s3cr3tvalue')).toBe(`client_secret=${REDACTED}`);
|
|
51
|
+
});
|
|
52
|
+
it('redacts the secret in a URL-encoded token exchange body', () => {
|
|
53
|
+
expect(redactSecrets('grant_type=client_credentials&client_id=3MVG9abc&client_secret=8F2A1B9C')).toBe(`grant_type=client_credentials&client_id=3MVG9abc&client_secret=${REDACTED}`);
|
|
54
|
+
});
|
|
55
|
+
it('redacts credential members of a JSON body, keeping the rest', () => {
|
|
56
|
+
expect(redactSecrets('{"client_id":"3MVG9abc","client_secret":"8F2A1B9C","grant_type":"client_credentials"}')).toBe(`{"client_id":"3MVG9abc","client_secret":"${REDACTED}","grant_type":"client_credentials"}`);
|
|
57
|
+
expect(redactSecrets('{"refreshToken": "a\\"b", "page": 2}')).toBe(`{"refreshToken": "${REDACTED}", "page": 2}`);
|
|
58
|
+
});
|
|
59
|
+
it('redacts credential members of JSON serialized inside a JSON string', () => {
|
|
60
|
+
expect(redactSecrets(String.raw `{"body":"{\"client_secret\":\"8F2A1B9C\",\"grant_type\":\"client_credentials\"}"}`)).toBe(String.raw `{"body":"{\"client_secret\":\"${REDACTED}\",\"grant_type\":\"client_credentials\"}"}`);
|
|
61
|
+
expect(redactSecrets(String.raw `{\"password\":\"a\\\"b\\\\\",\"page\":2}`)).toBe(String.raw `{\"password\":\"${REDACTED}\",\"page\":2}`);
|
|
62
|
+
});
|
|
63
|
+
it('redacts a key at the start of a line in a multi-line message', () => {
|
|
64
|
+
expect(redactSecrets('connection failed\napi_key=abc123def456')).toBe(`connection failed\napi_key=${REDACTED}`);
|
|
65
|
+
});
|
|
66
|
+
it('redacts every occurrence, not just the first', () => {
|
|
67
|
+
expect(redactSecrets('api_key=aaa111 and api_key=bbb222')).toBe(`api_key=${REDACTED} and api_key=${REDACTED}`);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('leaves app-authored prose alone', () => {
|
|
71
|
+
it('does not touch an ordinary user-facing message', () => {
|
|
72
|
+
const message = 'CAPACITY EXCEEDED: The following week(s) are now full: Week #11. Please select different weeks or join the waitlist.';
|
|
73
|
+
expect(redactSecrets(message)).toBe(message);
|
|
74
|
+
});
|
|
75
|
+
it('does not touch a parseable frontend signal', () => {
|
|
76
|
+
const message = 'CLOTHES_CHANGE_PENDING:recSHyUztFA6rF5UA';
|
|
77
|
+
expect(redactSecrets(message)).toBe(message);
|
|
78
|
+
});
|
|
79
|
+
it('does not redact prose that merely mentions a password', () => {
|
|
80
|
+
const message = 'Your password must be at least 8 characters long.';
|
|
81
|
+
expect(redactSecrets(message)).toBe(message);
|
|
82
|
+
});
|
|
83
|
+
it('does not redact the word "Bearer" without a token-shaped value', () => {
|
|
84
|
+
const message = 'Include a Bearer token in the Authorization header.';
|
|
85
|
+
expect(redactSecrets(message)).toBe(message);
|
|
86
|
+
});
|
|
87
|
+
it('does not redact "Basic" followed by an ordinary word', () => {
|
|
88
|
+
// The reason the Basic matcher guards on shape rather than length: a
|
|
89
|
+
// subscription app's own copy reads exactly like a short credential.
|
|
90
|
+
for (const message of [
|
|
91
|
+
'Your Basic plan does not include this feature.',
|
|
92
|
+
'Basic tier limits reached.',
|
|
93
|
+
'Basic Auth is required for this endpoint.',
|
|
94
|
+
'Upgrade from Basic Plan to continue.',
|
|
95
|
+
]) {
|
|
96
|
+
expect(redactSecrets(message)).toBe(message);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
it('does not redact a Stripe publishable key, which is meant to be public', () => {
|
|
100
|
+
const message = 'pk_live_abcdefghijklmnop1234 is not a secret key';
|
|
101
|
+
expect(redactSecrets(message)).toBe(message);
|
|
102
|
+
});
|
|
103
|
+
it('does not treat a URL with a port as userinfo', () => {
|
|
104
|
+
const message = 'GET https://api.example.com:8443/v1/records failed';
|
|
105
|
+
expect(redactSecrets(message)).toBe(message);
|
|
106
|
+
});
|
|
107
|
+
it('does not match a credential key embedded in a longer name', () => {
|
|
108
|
+
// "reset_password_url" ends in "password" but names a link, not a secret.
|
|
109
|
+
const message = 'reset_password_url=https://example.org/reset';
|
|
110
|
+
expect(redactSecrets(message)).toBe(message);
|
|
111
|
+
const json = '{"reset_password_url":"https://example.org/reset"}';
|
|
112
|
+
expect(redactSecrets(json)).toBe(json);
|
|
113
|
+
});
|
|
114
|
+
it('returns short or empty input untouched', () => {
|
|
115
|
+
expect(redactSecrets('')).toBe('');
|
|
116
|
+
expect(redactSecrets('nope')).toBe('nope');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('repeated use', () => {
|
|
120
|
+
it('is stable across calls despite module-level global regexes', () => {
|
|
121
|
+
const message = 'api_key=abc123def456';
|
|
122
|
+
const first = redactSecrets(message);
|
|
123
|
+
const second = redactSecrets(message);
|
|
124
|
+
expect(first).toBe(second);
|
|
125
|
+
expect(first).toBe(`api_key=${REDACTED}`);
|
|
126
|
+
});
|
|
127
|
+
it('is idempotent', () => {
|
|
128
|
+
const once = redactSecrets('postgres://svc:hunter2@db.internal/prod');
|
|
129
|
+
expect(redactSecrets(once)).toBe(once);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
describe('large input', () => {
|
|
133
|
+
// It runs synchronously on raw sandbox output, so anything worse than
|
|
134
|
+
// linear blocks the event loop long enough to fail health checks. Both
|
|
135
|
+
// inputs took several seconds at this size before the patterns were capped.
|
|
136
|
+
it.each([
|
|
137
|
+
['an unbroken alphanumeric run', 'aB3dE9fG1h'],
|
|
138
|
+
['a run of -eyJ fragments', '-eyJabcdefgh'],
|
|
139
|
+
])('stays fast on %s', (_, unit) => {
|
|
140
|
+
const text = unit.repeat(10_000);
|
|
141
|
+
const started = performance.now();
|
|
142
|
+
expect(redactSecrets(text)).toBe(text);
|
|
143
|
+
expect(performance.now() - started).toBeLessThan(2000);
|
|
144
|
+
});
|
|
145
|
+
it('still redacts a long scheme and a JWT after the caps', () => {
|
|
146
|
+
expect(redactSecrets('averyveryveryveryveryveryverylongscheme://svc:hunter2@db.internal')).toBe(`averyveryveryveryveryveryverylongscheme://svc:${REDACTED}@db.internal`);
|
|
147
|
+
const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U';
|
|
148
|
+
expect(redactSecrets(`x-${jwt}`)).toBe(`x-${REDACTED}`);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LoadedWorkflow } from "./workflowRun.js";
|
|
2
|
+
export type RegistrationResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
output: unknown;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Undefined when the workflow has no such function. */
|
|
13
|
+
export declare function runRegistration(workflows: LoadedWorkflow[], name: string, op: unknown, input: unknown): Promise<RegistrationResult | undefined>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Server-only: a provider trigger's `subscribe` or `unsubscribe`, which the host
|
|
2
|
+
// runs at publish. Not a run: nothing is logged, since what `subscribe` returns
|
|
3
|
+
// carries the provider's signing secret.
|
|
4
|
+
import { errorOf } from "./runLog.js";
|
|
5
|
+
import { runInScope } from "./scope.js";
|
|
6
|
+
/** Undefined when the workflow has no such function. */
|
|
7
|
+
export async function runRegistration(workflows, name, op, input) {
|
|
8
|
+
const trigger = workflows.find((w) => w.id === name)?.workflow.config.trigger;
|
|
9
|
+
if (!trigger || !("subscribe" in trigger))
|
|
10
|
+
return undefined;
|
|
11
|
+
const fn = op === "subscribe" ? trigger.subscribe : op === "unsubscribe" ? trigger.unsubscribe : undefined;
|
|
12
|
+
if (typeof fn !== "function")
|
|
13
|
+
return undefined;
|
|
14
|
+
try {
|
|
15
|
+
const output = await runInScope({ kind: "workflow", user: null }, () => fn(input));
|
|
16
|
+
return { ok: true, output: output ?? null };
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return { ok: false, error: errorOf(error) };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type Program = {
|
|
2
|
+
body: unknown[];
|
|
3
|
+
};
|
|
4
|
+
export declare const registrationHash: (subscribe: string, unsubscribe: string | undefined) => string;
|
|
5
|
+
/**
|
|
6
|
+
* A built function's text with its identifiers numbered in order of first appearance, so the minifier's renaming
|
|
7
|
+
* alone can't change it. Literals, property names and object keys, which it doesn't rename, stay.
|
|
8
|
+
*/
|
|
9
|
+
export declare const canonicalNames: (text: string) => string;
|
|
10
|
+
/** How the build reads the app's modules. */
|
|
11
|
+
export type ModuleSource = {
|
|
12
|
+
/** A module's source, and its AST when it parses; undefined when it can't be read. */
|
|
13
|
+
load: (file: string) => {
|
|
14
|
+
code: string;
|
|
15
|
+
program?: Program;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/** The file an import names, or undefined when it isn't the app's own code: a package, a virtual module. */
|
|
18
|
+
resolve: (source: string, importer: string) => Promise<string | undefined>;
|
|
19
|
+
};
|
|
20
|
+
/** `automation id -> registration hash` for each provider trigger the module at `file` exports. */
|
|
21
|
+
export declare function registrationHashes(file: string, source: ModuleSource): Promise<Map<string, string>>;
|
|
22
|
+
export {};
|