@apifuse/provider-sdk 2.2.0-beta.2 → 2.2.0-beta.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/AUTHORING.md +487 -0
- package/CHANGELOG.md +90 -0
- package/README.md +49 -3
- package/SUBMISSION.md +1 -1
- package/bin/apifuse-check.ts +44 -59
- package/bin/apifuse-create.ts +1 -1
- package/bin/apifuse-dev.ts +27 -52
- package/bin/apifuse-pack-check.ts +14 -0
- package/bin/apifuse-pack-smoke.ts +36 -81
- package/bin/apifuse-pack-types.ts +305 -0
- package/bin/apifuse-perf.ts +45 -127
- package/bin/apifuse-record.ts +659 -111
- package/bin/apifuse-submit-check.ts +546 -48
- package/bin/apifuse-sync-assets.ts +117 -0
- package/bin/apifuse.ts +1 -1
- package/bin/submit-check-delimited-text.ts +50 -0
- package/bin/submit-check-xml-semantics.ts +204 -0
- package/bin/submit-check-xml.ts +134 -0
- package/dist/auth-turn/index.d.ts +3 -3
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +9 -18
- package/dist/ceremonies/index.d.ts +9 -1
- package/dist/ceremonies/index.js +65 -18
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +8 -0
- package/dist/cli/create.d.ts +3 -0
- package/dist/cli/create.js +34 -35
- package/dist/cli/prompt-assets.d.ts +80 -0
- package/dist/cli/prompt-assets.js +743 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/dist/config/loader.d.ts +176 -8
- package/dist/config/loader.js +424 -95
- package/dist/contract-serialization.d.ts +2 -2
- package/dist/contract-serialization.js +3 -6
- package/dist/contract-types.d.ts +2 -2
- package/dist/contract.d.ts +3 -3
- package/dist/contract.js +4 -6
- package/dist/define.d.ts +9 -1
- package/dist/define.js +304 -119
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/error-resolution.d.ts +2 -0
- package/dist/error-resolution.js +90 -0
- package/dist/errors.d.ts +22 -1
- package/dist/errors.js +88 -0
- package/dist/fixture-sanitization.d.ts +26 -0
- package/dist/fixture-sanitization.js +216 -0
- package/dist/i18n/catalog.d.ts +2 -2
- package/dist/i18n/catalog.js +4 -10
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/keys.d.ts +2 -2
- package/dist/index.d.ts +46 -42
- package/dist/index.js +41 -37
- package/dist/lint.d.ts +1 -1
- package/dist/lint.js +8 -15
- package/dist/native-address.d.ts +43 -0
- package/dist/native-address.js +281 -0
- package/dist/native-egress-policy.d.ts +31 -0
- package/dist/native-egress-policy.js +288 -0
- package/dist/observability.d.ts +5 -2
- package/dist/observability.js +48 -1
- package/dist/provider.d.ts +12 -11
- package/dist/provider.js +10 -9
- package/dist/public-schema-field-lint.d.ts +1 -1
- package/dist/recipes/gov-api.js +1 -1
- package/dist/runtime/auth-flow.d.ts +2 -1
- package/dist/runtime/auth-flow.js +4 -3
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.js +15 -29
- package/dist/runtime/cache.d.ts +1 -1
- package/dist/runtime/cache.js +4 -8
- package/dist/runtime/choice.d.ts +1 -1
- package/dist/runtime/choice.js +31 -35
- package/dist/runtime/credential.d.ts +1 -1
- package/dist/runtime/credential.js +1 -1
- package/dist/runtime/env.d.ts +1 -1
- package/dist/runtime/executor.d.ts +1 -1
- package/dist/runtime/executor.js +31 -4
- package/dist/runtime/http.d.ts +2 -2
- package/dist/runtime/http.js +387 -47
- package/dist/runtime/insights.d.ts +1 -1
- package/dist/runtime/insights.js +6 -13
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +345 -22
- package/dist/runtime/keyring.js +1 -1
- package/dist/runtime/namespace.js +1 -1
- package/dist/runtime/native-network.d.ts +127 -0
- package/dist/runtime/native-network.js +1298 -0
- package/dist/runtime/otlp.d.ts +1 -1
- package/dist/runtime/perf.d.ts +1 -1
- package/dist/runtime/provider.d.ts +1 -1
- package/dist/runtime/provider.js +1 -2
- package/dist/runtime/proxy-errors.d.ts +1 -1
- package/dist/runtime/proxy-errors.js +9 -7
- package/dist/runtime/proxy-nodemaven.d.ts +56 -0
- package/dist/runtime/proxy-nodemaven.js +146 -0
- package/dist/runtime/proxy-retry-policy.d.ts +2 -2
- package/dist/runtime/proxy-retry-policy.js +2 -2
- package/dist/runtime/proxy-telemetry.d.ts +2 -1
- package/dist/runtime/proxy-telemetry.js +55 -52
- package/dist/runtime/redirects.d.ts +29 -0
- package/dist/runtime/redirects.js +36 -0
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +2 -4
- package/dist/runtime/request-options.d.ts +68 -1
- package/dist/runtime/request-options.js +548 -0
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/state.d.ts +2 -2
- package/dist/runtime/state.js +238 -26
- package/dist/runtime/stealth.d.ts +5 -3
- package/dist/runtime/stealth.js +423 -143
- package/dist/runtime/stt.d.ts +1 -1
- package/dist/runtime/stt.js +11 -15
- package/dist/runtime/trace.d.ts +2 -2
- package/dist/runtime/trace.js +2 -4
- package/dist/runtime/waterfall.d.ts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +7 -15
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +6 -6
- package/dist/server/self-test-input-tokens.d.ts +2 -1
- package/dist/server/self-test-input-tokens.js +18 -14
- package/dist/server/self-test-redaction.d.ts +1 -1
- package/dist/server/self-test-redaction.js +1 -1
- package/dist/server/self-test.d.ts +104 -3
- package/dist/server/self-test.js +673 -115
- package/dist/server/serve.d.ts +116 -4
- package/dist/server/serve.js +799 -128
- package/dist/server/types.d.ts +34 -9
- package/dist/server/types.js +8 -1
- package/dist/stateful/errors.d.ts +14 -0
- package/dist/stateful/errors.js +14 -0
- package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
- package/dist/stateful/http-provider-event-emitter.js +237 -0
- package/dist/stateful/http-session-owner-registry.d.ts +44 -0
- package/dist/stateful/http-session-owner-registry.js +210 -0
- package/dist/stateful/index.d.ts +18 -0
- package/dist/stateful/index.js +18 -0
- package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
- package/dist/stateful/provider-event-delivery-failures.js +43 -0
- package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
- package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
- package/dist/stateful/provider-event-pipeline.d.ts +50 -0
- package/dist/stateful/provider-event-pipeline.js +1 -0
- package/dist/stateful/provider-events.d.ts +101 -0
- package/dist/stateful/provider-events.js +289 -0
- package/dist/stateful/session-key.d.ts +15 -0
- package/dist/stateful/session-key.js +86 -0
- package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
- package/dist/stateful/stateful-provider-adapter-context.js +42 -0
- package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
- package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
- package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
- package/dist/stateful/stateful-provider-adapter.js +287 -0
- package/dist/stateful/stateful-provider-observability.d.ts +62 -0
- package/dist/stateful/stateful-provider-observability.js +161 -0
- package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
- package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
- package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
- package/dist/stateful/stateful-provider-runtime-context.js +60 -0
- package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
- package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
- package/dist/stateful/stateful-provider-session-routing.d.ts +71 -0
- package/dist/stateful/stateful-provider-session-routing.js +353 -0
- package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
- package/dist/stateful/stateful-provider-session-runtime.js +245 -0
- package/dist/stateful-signing.d.ts +18 -0
- package/dist/stateful-signing.js +27 -0
- package/dist/stealth/profiles.d.ts +1 -1
- package/dist/stealth/profiles.js +5 -14
- package/dist/stream-evidence.d.ts +74 -0
- package/dist/stream-evidence.js +785 -0
- package/dist/stream.d.ts +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/run.d.ts +32 -2
- package/dist/testing/run.js +478 -28
- package/dist/types.d.ts +342 -14
- package/dist/types.js +1 -0
- package/dist/user-input.d.ts +30 -0
- package/dist/user-input.js +66 -0
- package/package.json +16 -5
- package/src/auth-turn/index.ts +1 -1
- package/src/auth.ts +28 -86
- package/src/ceremonies/index.ts +103 -78
- package/src/cli/commands.ts +10 -0
- package/src/cli/create.ts +42 -35
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/src/config/loader.ts +652 -204
- package/src/contract-serialization.ts +5 -11
- package/src/contract-types.ts +2 -2
- package/src/contract.ts +12 -28
- package/src/define.ts +499 -498
- package/src/dev.ts +4 -9
- package/src/error-resolution.ts +91 -0
- package/src/errors.ts +110 -5
- package/src/fixture-sanitization.ts +247 -0
- package/src/i18n/catalog.ts +10 -32
- package/src/i18n/index.ts +2 -2
- package/src/i18n/keys.ts +5 -11
- package/src/index.ts +112 -42
- package/src/lint.ts +88 -152
- package/src/native-address.ts +340 -0
- package/src/native-egress-policy.ts +358 -0
- package/src/observability.ts +51 -1
- package/src/provider.ts +66 -11
- package/src/public-schema-field-lint.ts +7 -33
- package/src/recipes/gov-api.ts +2 -5
- package/src/runtime/auth-flow.ts +7 -7
- package/src/runtime/browser.ts +64 -187
- package/src/runtime/cache.ts +20 -67
- package/src/runtime/choice.ts +79 -132
- package/src/runtime/credential.ts +2 -2
- package/src/runtime/env.ts +1 -1
- package/src/runtime/executor.ts +43 -20
- package/src/runtime/http.ts +494 -57
- package/src/runtime/insights.ts +15 -53
- package/src/runtime/instrumentation.ts +495 -66
- package/src/runtime/keyring.ts +7 -19
- package/src/runtime/namespace.ts +2 -7
- package/src/runtime/native-network.ts +1686 -0
- package/src/runtime/otlp.ts +12 -23
- package/src/runtime/perf.ts +1 -1
- package/src/runtime/provider.ts +4 -9
- package/src/runtime/proxy-errors.ts +29 -42
- package/src/runtime/proxy-nodemaven.ts +221 -0
- package/src/runtime/proxy-retry-policy.ts +3 -3
- package/src/runtime/proxy-telemetry.ts +79 -77
- package/src/runtime/redirects.ts +66 -0
- package/src/runtime/redis.ts +4 -12
- package/src/runtime/request-options.ts +679 -9
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +353 -133
- package/src/runtime/stealth.ts +505 -154
- package/src/runtime/stt.ts +38 -94
- package/src/runtime/trace.ts +14 -44
- package/src/runtime/waterfall.ts +5 -18
- package/src/schema.ts +23 -84
- package/src/serve.ts +1 -1
- package/src/server/index.ts +29 -7
- package/src/server/self-test-input-tokens.ts +29 -14
- package/src/server/self-test-redaction.ts +2 -2
- package/src/server/self-test.ts +857 -132
- package/src/server/serve.ts +1151 -328
- package/src/server/types.ts +12 -13
- package/src/stateful/README.md +146 -0
- package/src/stateful/errors.ts +23 -0
- package/src/stateful/http-provider-event-emitter.ts +314 -0
- package/src/stateful/http-session-owner-registry.ts +306 -0
- package/src/stateful/index.ts +18 -0
- package/src/stateful/provider-event-delivery-failures.ts +80 -0
- package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
- package/src/stateful/provider-event-pipeline.ts +61 -0
- package/src/stateful/provider-events.ts +462 -0
- package/src/stateful/session-key.ts +111 -0
- package/src/stateful/stateful-provider-adapter-context.ts +59 -0
- package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
- package/src/stateful/stateful-provider-adapter.ts +562 -0
- package/src/stateful/stateful-provider-observability.ts +261 -0
- package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
- package/src/stateful/stateful-provider-runtime-context.ts +92 -0
- package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
- package/src/stateful/stateful-provider-session-routing.ts +555 -0
- package/src/stateful/stateful-provider-session-runtime.ts +403 -0
- package/src/stateful-signing.ts +46 -0
- package/src/stealth/profiles.ts +10 -26
- package/src/stream-evidence.ts +988 -0
- package/src/stream.ts +8 -19
- package/src/testing/index.ts +10 -2
- package/src/testing/run.ts +653 -74
- package/src/types.ts +408 -28
- package/src/user-input.ts +118 -0
- package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
- package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
- /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/dist/dev.d.ts
CHANGED
package/dist/dev.js
CHANGED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// This set suppresses the unregistered-provider-error-code signal for codes
|
|
2
|
+
// intentionally emitted by SDK paths. It is not the complete authority for
|
|
3
|
+
// runtime error resolution: branded errors and additional canonical SDK codes
|
|
4
|
+
// must also remain immune to provider-declared status/retryability overrides.
|
|
5
|
+
export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
|
|
6
|
+
"MISSING_SECRET",
|
|
7
|
+
"AUTH_PROMPT_UNAVAILABLE",
|
|
8
|
+
"BROWSER_CDP_POOL_REQUIRED",
|
|
9
|
+
"BROWSER_RUNTIME_UNSUPPORTED",
|
|
10
|
+
"STEALTH_RUNTIME_UNSUPPORTED",
|
|
11
|
+
"SSE_EVENT_UNDECLARED",
|
|
12
|
+
"STREAM_EVENT_TOO_LARGE",
|
|
13
|
+
"STREAM_CHUNK_TOO_LARGE",
|
|
14
|
+
"SSE_RESULT_UNSUPPORTED",
|
|
15
|
+
"STREAM_RESULT_UNSUPPORTED",
|
|
16
|
+
"AUTH_FLOW_NOT_CONFIGURED",
|
|
17
|
+
"refresh_not_supported",
|
|
18
|
+
"RUNTIME_UNSUPPORTED",
|
|
19
|
+
"PROVIDER_STATE_UNSUPPORTED",
|
|
20
|
+
"CHOICE_TOKEN_MASTER_SECRET_NOT_CONFIGURED",
|
|
21
|
+
"CHOICE_STATE_PAYLOAD_TOO_LARGE",
|
|
22
|
+
"CHOICE_STATE_UNAVAILABLE",
|
|
23
|
+
"CHOICE_CONTEXT_REQUIRED",
|
|
24
|
+
"unsupported_stealth_cookie_store_version",
|
|
25
|
+
"provider_secret_error",
|
|
26
|
+
"credential_key_error",
|
|
27
|
+
"credential_mode_error",
|
|
28
|
+
"flow_expired",
|
|
29
|
+
"turn_validation_error",
|
|
30
|
+
"context_access_error",
|
|
31
|
+
"UNSUPPORTED_STT_OPTION",
|
|
32
|
+
"INVALID_STT_AUDIO",
|
|
33
|
+
"STT_AUDIO_TOO_LARGE",
|
|
34
|
+
"STT_UPSTREAM_FAILED",
|
|
35
|
+
"INVALID_STT_VERIFICATION_CODE_OPTIONS",
|
|
36
|
+
"NO_CODE_FOUND",
|
|
37
|
+
"AMBIGUOUS_CODE",
|
|
38
|
+
"retry_invalid_policy",
|
|
39
|
+
"retry_unsafe_method",
|
|
40
|
+
"stealth_cookie_store_serialize_failed",
|
|
41
|
+
"response_too_large",
|
|
42
|
+
"transport_stream_unavailable",
|
|
43
|
+
"transport_invalid_method",
|
|
44
|
+
"http_transport_override_unsupported",
|
|
45
|
+
"http_redirect_policy_invalid",
|
|
46
|
+
"http_redirect_stopped",
|
|
47
|
+
"http_redirect_max_hops",
|
|
48
|
+
"http_redirect_missing_location",
|
|
49
|
+
"http_redirect_loop",
|
|
50
|
+
"transport_invalid_url",
|
|
51
|
+
"retry_exhausted",
|
|
52
|
+
"auth_abort_unsafe_data",
|
|
53
|
+
"credentials_auth_missing_credential_keys",
|
|
54
|
+
"credentials_auth_missing_credential",
|
|
55
|
+
"credentials_auth_invalid_login_result",
|
|
56
|
+
"credentials_auth_unknown_challenge",
|
|
57
|
+
"credentials_auth_unknown_pending_challenge",
|
|
58
|
+
"STATEFUL_FORWARDING_NOT_CONFIGURED",
|
|
59
|
+
"STATEFUL_FORWARDING_SIGNATURE_MISSING",
|
|
60
|
+
"STATEFUL_FORWARDING_NONCE_INVALID",
|
|
61
|
+
"STATEFUL_FORWARDING_TIMESTAMP_INVALID",
|
|
62
|
+
"STATEFUL_FORWARDING_SIGNATURE_INVALID",
|
|
63
|
+
"STATEFUL_FORWARDING_REPLAY_DETECTED",
|
|
64
|
+
"STATEFUL_FORWARDING_REPLAY_CACHE_FULL",
|
|
65
|
+
"STATEFUL_FORWARDING_ENVELOPE_INVALID",
|
|
66
|
+
"STATEFUL_FORWARDING_PROVIDER_MISMATCH",
|
|
67
|
+
"STATEFUL_FORWARDING_SOURCE_POD_MISMATCH",
|
|
68
|
+
"STATEFUL_FORWARDING_OWNER_FENCE_INVALID",
|
|
69
|
+
"STATEFUL_FORWARDING_REQUEST_FAILED",
|
|
70
|
+
"STATEFUL_FORWARDING_CONTEXT_MISSING",
|
|
71
|
+
"STATEFUL_FORWARDING_BAD_RESPONSE",
|
|
72
|
+
"STATEFUL_INTERNAL_EXECUTOR_NOT_CONFIGURED",
|
|
73
|
+
"STATEFUL_FILE_FORWARDING_UNSUPPORTED",
|
|
74
|
+
"STATEFUL_CONTROL_PLANE_OPERATION_AMBIGUOUS",
|
|
75
|
+
"STATEFUL_CONTROL_PLANE_REQUEST_FAILED",
|
|
76
|
+
"STATEFUL_CONTROL_PLANE_HTTP_ERROR",
|
|
77
|
+
"STATEFUL_CONTROL_PLANE_INVALID_RESPONSE",
|
|
78
|
+
]);
|
|
79
|
+
// Complete code authority for provider-declared runtime resolution. Keep this
|
|
80
|
+
// separate from signal suppression: declarations may document these codes, but
|
|
81
|
+
// their status and retryability can never override the SDK's canonical result.
|
|
82
|
+
export const SDK_RUNTIME_OWNED_ERROR_CODES = new Set([
|
|
83
|
+
...SDK_OWNED_PROVIDER_ERROR_CODES,
|
|
84
|
+
"reauth_required",
|
|
85
|
+
"STT_UNAVAILABLE",
|
|
86
|
+
"UNSUPPORTED_STT_BACKEND",
|
|
87
|
+
"OUTPUT_VALIDATION_FAILED",
|
|
88
|
+
"NOT_FOUND",
|
|
89
|
+
"not_found",
|
|
90
|
+
]);
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ProviderErrorCategory } from "./observability";
|
|
1
|
+
import type { ProviderErrorCategory } from "./observability.js";
|
|
2
|
+
import type { HttpRedirectFailureReason } from "./types.js";
|
|
2
3
|
export type ProviderErrorOptions = {
|
|
3
4
|
fix?: string;
|
|
4
5
|
code?: string;
|
|
@@ -17,6 +18,11 @@ export declare class ProviderError extends Error {
|
|
|
17
18
|
export declare class SDKError extends ProviderError {
|
|
18
19
|
constructor(message: string, options?: ProviderErrorOptions);
|
|
19
20
|
}
|
|
21
|
+
/** Raised when persisted stealth cookies use a store version this SDK cannot read. */
|
|
22
|
+
export declare class StealthCookieStoreVersionError extends SDKError {
|
|
23
|
+
readonly version: unknown;
|
|
24
|
+
constructor(version: unknown);
|
|
25
|
+
}
|
|
20
26
|
export declare class AuthError extends ProviderError {
|
|
21
27
|
constructor(message: string, options?: ProviderErrorOptions);
|
|
22
28
|
}
|
|
@@ -39,6 +45,21 @@ export declare class TransportError extends ProviderError {
|
|
|
39
45
|
readonly upstreamStatus?: number;
|
|
40
46
|
constructor(message: string, options?: TransportErrorOptions);
|
|
41
47
|
}
|
|
48
|
+
export type HttpRedirectErrorOptions = TransportErrorOptions & {
|
|
49
|
+
reason: HttpRedirectFailureReason;
|
|
50
|
+
/** Redacted redirect target suitable for provider diagnostics. */
|
|
51
|
+
target?: string;
|
|
52
|
+
};
|
|
53
|
+
/** Raised when an opt-in ctx.http redirect policy refuses or cannot resolve a hop. */
|
|
54
|
+
export declare class HttpRedirectError extends TransportError {
|
|
55
|
+
readonly reason: HttpRedirectFailureReason;
|
|
56
|
+
readonly target?: string;
|
|
57
|
+
constructor(message: string, options: HttpRedirectErrorOptions);
|
|
58
|
+
}
|
|
59
|
+
export declare function isProviderError(value: unknown): value is ProviderError;
|
|
60
|
+
export declare function isSessionExpiredError(value: unknown): value is SessionExpiredError;
|
|
61
|
+
export declare function isTransportError(value: unknown): value is TransportError;
|
|
62
|
+
export declare function isValidationError(value: unknown): value is ValidationError;
|
|
42
63
|
export declare class ProviderSecretError extends ProviderError {
|
|
43
64
|
constructor(message: string, options?: ProviderErrorOptions);
|
|
44
65
|
}
|
package/dist/errors.js
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
// Versioned, cross-realm brands. `Symbol.for` resolves to the same symbol in
|
|
2
|
+
// any copy/entrypoint of this SDK major version, so an error created by a
|
|
3
|
+
// duplicate module instance (e.g. the packaged CLI's src/* server vs a
|
|
4
|
+
// provider's dist/* import) still carries a brand the server can recognize even
|
|
5
|
+
// though `instanceof` splits across the two constructors. The `@1` suffix lets a
|
|
6
|
+
// future breaking change to this contract mint a distinct key.
|
|
7
|
+
const PROVIDER_ERROR_BRAND = Symbol.for("@apifuse/provider-sdk/error-brand@1");
|
|
8
|
+
const PROVIDER_ERROR_BRAND_VALUE = 1;
|
|
9
|
+
const SESSION_EXPIRED_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/session-expired@1");
|
|
10
|
+
const TRANSPORT_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/transport@1");
|
|
11
|
+
const VALIDATION_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/validation@1");
|
|
12
|
+
// Defines a non-enumerable, non-writable, non-configurable own data property.
|
|
13
|
+
// Immutable + own means a guard can trust it via a single descriptor read
|
|
14
|
+
// without invoking attacker-controlled getters or accepting inherited brands.
|
|
15
|
+
function defineErrorBrand(target, brand, value) {
|
|
16
|
+
Object.defineProperty(target, brand, {
|
|
17
|
+
value,
|
|
18
|
+
enumerable: false,
|
|
19
|
+
writable: false,
|
|
20
|
+
configurable: false,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// Recognizes an own data-property brand with the expected value. Rejects
|
|
24
|
+
// missing brands (unbranded lookalikes), accessor brands (no own `value`
|
|
25
|
+
// slot — the getter is never called), and inherited brands (own-descriptor
|
|
26
|
+
// lookup returns undefined on the child).
|
|
27
|
+
function hasOwnBrand(value, brand, expected) {
|
|
28
|
+
if (value === null || (typeof value !== "object" && typeof value !== "function")) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, brand);
|
|
32
|
+
return (descriptor !== undefined && Object.hasOwn(descriptor, "value") && descriptor.value === expected);
|
|
33
|
+
}
|
|
1
34
|
export class ProviderError extends Error {
|
|
2
35
|
options;
|
|
3
36
|
constructor(message, options) {
|
|
@@ -7,6 +40,7 @@ export class ProviderError extends Error {
|
|
|
7
40
|
if (options?.cause) {
|
|
8
41
|
this.cause = options.cause;
|
|
9
42
|
}
|
|
43
|
+
defineErrorBrand(this, PROVIDER_ERROR_BRAND, PROVIDER_ERROR_BRAND_VALUE);
|
|
10
44
|
}
|
|
11
45
|
get fix() {
|
|
12
46
|
return this.options?.fix;
|
|
@@ -24,6 +58,21 @@ export class SDKError extends ProviderError {
|
|
|
24
58
|
this.name = "SDKError";
|
|
25
59
|
}
|
|
26
60
|
}
|
|
61
|
+
/** Raised when persisted stealth cookies use a store version this SDK cannot read. */
|
|
62
|
+
export class StealthCookieStoreVersionError extends SDKError {
|
|
63
|
+
version;
|
|
64
|
+
constructor(version) {
|
|
65
|
+
const displayedVersion = typeof version === "string" || typeof version === "number"
|
|
66
|
+
? String(version)
|
|
67
|
+
: "missing or invalid";
|
|
68
|
+
super(`Unsupported stealth cookie store version: ${displayedVersion}`, {
|
|
69
|
+
code: "unsupported_stealth_cookie_store_version",
|
|
70
|
+
details: { receivedVersion: version, supportedVersions: [1] },
|
|
71
|
+
});
|
|
72
|
+
this.version = version;
|
|
73
|
+
this.name = "StealthCookieStoreVersionError";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
27
76
|
export class AuthError extends ProviderError {
|
|
28
77
|
constructor(message, options) {
|
|
29
78
|
super(message, options);
|
|
@@ -39,6 +88,7 @@ export class SessionExpiredError extends AuthError {
|
|
|
39
88
|
...options,
|
|
40
89
|
});
|
|
41
90
|
this.name = "SessionExpiredError";
|
|
91
|
+
defineErrorBrand(this, SESSION_EXPIRED_BRAND, true);
|
|
42
92
|
}
|
|
43
93
|
}
|
|
44
94
|
export class ValidationError extends ProviderError {
|
|
@@ -47,6 +97,7 @@ export class ValidationError extends ProviderError {
|
|
|
47
97
|
super(message, options);
|
|
48
98
|
this.name = "ValidationError";
|
|
49
99
|
this.zodError = options?.zodError;
|
|
100
|
+
defineErrorBrand(this, VALIDATION_BRAND, true);
|
|
50
101
|
}
|
|
51
102
|
}
|
|
52
103
|
export class TransportError extends ProviderError {
|
|
@@ -57,8 +108,45 @@ export class TransportError extends ProviderError {
|
|
|
57
108
|
this.name = "TransportError";
|
|
58
109
|
this.status = options?.status;
|
|
59
110
|
this.upstreamStatus = options?.upstreamStatus ?? options?.status;
|
|
111
|
+
defineErrorBrand(this, TRANSPORT_BRAND, true);
|
|
60
112
|
}
|
|
61
113
|
}
|
|
114
|
+
/** Raised when an opt-in ctx.http redirect policy refuses or cannot resolve a hop. */
|
|
115
|
+
export class HttpRedirectError extends TransportError {
|
|
116
|
+
reason;
|
|
117
|
+
target;
|
|
118
|
+
constructor(message, options) {
|
|
119
|
+
const { reason, target, ...transportOptions } = options;
|
|
120
|
+
super(message, {
|
|
121
|
+
...transportOptions,
|
|
122
|
+
code: `http_redirect_${reason}`,
|
|
123
|
+
details: {
|
|
124
|
+
reason,
|
|
125
|
+
...(target ? { target } : {}),
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
this.name = "HttpRedirectError";
|
|
129
|
+
this.reason = reason;
|
|
130
|
+
this.target = target;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Cross-module type guards. Prefer these over `instanceof` at any boundary that
|
|
134
|
+
// may receive an error from a different copy/entrypoint of the SDK (see the HTTP
|
|
135
|
+
// server error boundary). They recognize branded errors regardless of which
|
|
136
|
+
// module instance constructed them, while rejecting unbranded lookalikes.
|
|
137
|
+
export function isProviderError(value) {
|
|
138
|
+
return hasOwnBrand(value, PROVIDER_ERROR_BRAND, PROVIDER_ERROR_BRAND_VALUE);
|
|
139
|
+
}
|
|
140
|
+
export function isSessionExpiredError(value) {
|
|
141
|
+
return isProviderError(value) && hasOwnBrand(value, SESSION_EXPIRED_BRAND, true);
|
|
142
|
+
}
|
|
143
|
+
export function isTransportError(value) {
|
|
144
|
+
return isProviderError(value) && hasOwnBrand(value, TRANSPORT_BRAND, true);
|
|
145
|
+
}
|
|
146
|
+
export function isValidationError(value) {
|
|
147
|
+
return (isProviderError(value) &&
|
|
148
|
+
(hasOwnBrand(value, VALIDATION_BRAND, true) || value.name === "ValidationError"));
|
|
149
|
+
}
|
|
62
150
|
export class ProviderSecretError extends ProviderError {
|
|
63
151
|
constructor(message, options) {
|
|
64
152
|
super(message, { code: "provider_secret_error", ...options });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { JsonValue } from "./contract-json.js";
|
|
2
|
+
export declare const REDACTED_FIXTURE_VALUE = "[REDACTED]";
|
|
3
|
+
/** Matches credential field names without treating benign prefixes such as `author` as `auth`. */
|
|
4
|
+
export declare function isSensitiveFixtureKey(key: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Returns JSON fixture data with credential-bearing keys and heuristic-confirmed string secrets
|
|
7
|
+
* replaced. Ordinary short prose and identifiers are retained.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sanitizeFixture(value: JsonValue): JsonValue;
|
|
10
|
+
/** Applies the shared credential-key policy to ordinary JSON fixtures. */
|
|
11
|
+
export declare function sanitizeOrdinaryFixture(value: JsonValue): JsonValue;
|
|
12
|
+
/** Sanitizes a primitive fixture string only when textual-secret heuristics match. */
|
|
13
|
+
export declare function sanitizeFixtureString(value: string): string;
|
|
14
|
+
/** True for opaque values that are unsafe to retain in paths or unstructured text. */
|
|
15
|
+
export declare function isSensitiveFixtureValue(value: string): boolean;
|
|
16
|
+
/** Sanitizes every path segment and values following a credential-like segment name. */
|
|
17
|
+
export declare function sanitizePathname(pathname: string): string;
|
|
18
|
+
/** Removes userinfo, query values, fragments, and credential-like path segments from log URLs. */
|
|
19
|
+
export declare function sanitizeUrlForLogs(value: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Returns query-free request provenance with each path segment scrubbed for credential-like values.
|
|
22
|
+
* Origins, URL userinfo, query values, and fragments are never persisted in request provenance.
|
|
23
|
+
*/
|
|
24
|
+
export declare function requestPathForFixture(value: string): string;
|
|
25
|
+
/** Scrubs secrets and terminal/log control characters before diagnostic text is emitted. */
|
|
26
|
+
export declare function sanitizeDiagnosticText(value: string): string;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
export const REDACTED_FIXTURE_VALUE = "[REDACTED]";
|
|
2
|
+
const OPAQUE_TOKEN = /^[A-Za-z0-9_+/=.:~-]+$/;
|
|
3
|
+
const OPAQUE_TOKEN_RUN = /[A-Za-z0-9_+/=.:~-]{24,}/g;
|
|
4
|
+
const URL_RUN = /https?:\/\/[^\s"'<>]+/gi;
|
|
5
|
+
const PEM_PRIVATE_KEY = /-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/g;
|
|
6
|
+
/** Matches credential field names without treating benign prefixes such as `author` as `auth`. */
|
|
7
|
+
export function isSensitiveFixtureKey(key) {
|
|
8
|
+
const normalized = key.replace(/[-_\s]/g, "").toLowerCase();
|
|
9
|
+
const candidates = [normalized, normalized.replace(/(?:value|payload|header)$/, "")];
|
|
10
|
+
return candidates.some((candidate) => /^(?:authorization|authentication|auth|bearer|cookie|credential|password|passwd|privatekey|secret|session|sessionid|token)$/.test(candidate) ||
|
|
11
|
+
/^(?:api|client|service|access|consumer)(?:key|secret|token)$/.test(candidate) ||
|
|
12
|
+
/(?:authorization|credential|password|passwd|privatekey|secret|sessionid|token)$/.test(candidate));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns JSON fixture data with credential-bearing keys and heuristic-confirmed string secrets
|
|
16
|
+
* replaced. Ordinary short prose and identifiers are retained.
|
|
17
|
+
*/
|
|
18
|
+
export function sanitizeFixture(value) {
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
return value.map((item) => sanitizeFixture(item));
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === "string")
|
|
23
|
+
return sanitizeFixtureString(value);
|
|
24
|
+
if (value === null || typeof value !== "object")
|
|
25
|
+
return value;
|
|
26
|
+
return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
|
|
27
|
+
key,
|
|
28
|
+
isSensitiveFixtureKey(key) ? REDACTED_FIXTURE_VALUE : sanitizeFixture(entryValue),
|
|
29
|
+
]));
|
|
30
|
+
}
|
|
31
|
+
/** Applies the shared credential-key policy to ordinary JSON fixtures. */
|
|
32
|
+
export function sanitizeOrdinaryFixture(value) {
|
|
33
|
+
if (Array.isArray(value))
|
|
34
|
+
return value.map((item) => sanitizeOrdinaryFixture(item));
|
|
35
|
+
if (value === null || typeof value !== "object")
|
|
36
|
+
return value;
|
|
37
|
+
return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
|
|
38
|
+
key,
|
|
39
|
+
isSensitiveFixtureKey(key) ? REDACTED_FIXTURE_VALUE : sanitizeOrdinaryFixture(entryValue),
|
|
40
|
+
]));
|
|
41
|
+
}
|
|
42
|
+
/** Sanitizes a primitive fixture string only when textual-secret heuristics match. */
|
|
43
|
+
export function sanitizeFixtureString(value) {
|
|
44
|
+
let sanitized = value.replace(PEM_PRIVATE_KEY, REDACTED_FIXTURE_VALUE);
|
|
45
|
+
const retainedUrls = [];
|
|
46
|
+
sanitized = sanitized.replace(URL_RUN, (url) => {
|
|
47
|
+
const index = retainedUrls.push(isCredentialBearingUrl(url) ? sanitizeUrlForLogs(url) : url) - 1;
|
|
48
|
+
return `APIFUSEURL${index}X`;
|
|
49
|
+
});
|
|
50
|
+
sanitized = redactSensitiveAssignments(sanitized);
|
|
51
|
+
sanitized = sanitized.replace(OPAQUE_TOKEN_RUN, (candidate) => isSensitiveFixtureValue(candidate) ? REDACTED_FIXTURE_VALUE : candidate);
|
|
52
|
+
sanitized = sanitized.replace(/APIFUSEURL(\d+)X/g, (_match, index) => retainedUrls[Number(index)] ?? REDACTED_FIXTURE_VALUE);
|
|
53
|
+
return sanitized;
|
|
54
|
+
}
|
|
55
|
+
/** True for opaque values that are unsafe to retain in paths or unstructured text. */
|
|
56
|
+
export function isSensitiveFixtureValue(value) {
|
|
57
|
+
const candidate = decodePathSegment(value);
|
|
58
|
+
if (/^bot(?:\d{6,}:)?[A-Za-z0-9_-]{16,}$/i.test(candidate))
|
|
59
|
+
return true;
|
|
60
|
+
if (/^\d{6,}:[A-Za-z0-9_-]{20,}$/.test(candidate))
|
|
61
|
+
return true;
|
|
62
|
+
if (/^(?:gh[opusr]_|sk[-_]|xox[baprs]-)[A-Za-z0-9_-]{16,}$/i.test(candidate))
|
|
63
|
+
return true;
|
|
64
|
+
if (!OPAQUE_TOKEN.test(candidate) || candidate.length < 24)
|
|
65
|
+
return false;
|
|
66
|
+
if (/^[a-f0-9]{32,}$/i.test(candidate))
|
|
67
|
+
return true;
|
|
68
|
+
return shannonEntropy(candidate) >= 3.5;
|
|
69
|
+
}
|
|
70
|
+
/** Sanitizes every path segment and values following a credential-like segment name. */
|
|
71
|
+
export function sanitizePathname(pathname) {
|
|
72
|
+
const segments = pathname.split("/");
|
|
73
|
+
return segments
|
|
74
|
+
.map((segment, index) => {
|
|
75
|
+
if (!segment)
|
|
76
|
+
return segment;
|
|
77
|
+
const decoded = decodePathSegment(segment);
|
|
78
|
+
const previous = index > 0 ? decodePathSegment(segments[index - 1]) : "";
|
|
79
|
+
if (isSensitivePathSegment(decoded) ||
|
|
80
|
+
isCredentialPathKey(previous) ||
|
|
81
|
+
isSensitiveFixtureValue(decoded)) {
|
|
82
|
+
return REDACTED_FIXTURE_VALUE;
|
|
83
|
+
}
|
|
84
|
+
return segment;
|
|
85
|
+
})
|
|
86
|
+
.join("/");
|
|
87
|
+
}
|
|
88
|
+
function isCredentialPathKey(key) {
|
|
89
|
+
const finalPathPart = key.split("/").at(-1) ?? "";
|
|
90
|
+
const baseSegment = finalPathPart.split(";", 1)[0] ?? "";
|
|
91
|
+
return isSensitiveFixtureKey(baseSegment.split(/[=:]/, 1)[0] ?? "");
|
|
92
|
+
}
|
|
93
|
+
function isSensitivePathSegment(segment) {
|
|
94
|
+
return segment
|
|
95
|
+
.split(/[;/]/)
|
|
96
|
+
.some((part) => isSensitiveFixtureKey(part.split(/[=:]/, 1)[0] ?? ""));
|
|
97
|
+
}
|
|
98
|
+
/** Removes userinfo, query values, fragments, and credential-like path segments from log URLs. */
|
|
99
|
+
export function sanitizeUrlForLogs(value) {
|
|
100
|
+
try {
|
|
101
|
+
const parsed = new URL(value, "https://fixture.invalid");
|
|
102
|
+
const queryMarker = parsed.search ? `?${REDACTED_FIXTURE_VALUE}` : "";
|
|
103
|
+
const path = sanitizePathname(parsed.pathname);
|
|
104
|
+
if (parsed.origin === "https://fixture.invalid" && !hasExplicitOrigin(value)) {
|
|
105
|
+
return `${path}${queryMarker}`;
|
|
106
|
+
}
|
|
107
|
+
return `${parsed.origin}${path}${queryMarker}`;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return sanitizePathname(value.split(/[?#]/, 1)[0]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns query-free request provenance with each path segment scrubbed for credential-like values.
|
|
115
|
+
* Origins, URL userinfo, query values, and fragments are never persisted in request provenance.
|
|
116
|
+
*/
|
|
117
|
+
export function requestPathForFixture(value) {
|
|
118
|
+
try {
|
|
119
|
+
return sanitizePathname(new URL(value, "https://fixture.invalid").pathname);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
const path = value.split(/[?#]/, 1)[0];
|
|
123
|
+
return sanitizePathname(path.startsWith("/") ? path : `/${path}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Scrubs secrets and terminal/log control characters before diagnostic text is emitted. */
|
|
127
|
+
export function sanitizeDiagnosticText(value) {
|
|
128
|
+
let sanitized = value
|
|
129
|
+
.replace(URL_RUN, (url) => sanitizeUrlForLogs(url))
|
|
130
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, `Bearer ${REDACTED_FIXTURE_VALUE}`);
|
|
131
|
+
sanitized = redactSensitiveAssignments(sanitized);
|
|
132
|
+
sanitized = sanitized.replace(OPAQUE_TOKEN_RUN, (candidate, offset, source) => {
|
|
133
|
+
if (/^(?:request|trace|correlation)[-_]?id[:=]/i.test(candidate))
|
|
134
|
+
return candidate;
|
|
135
|
+
const prefix = source.slice(Math.max(0, offset - 32), offset);
|
|
136
|
+
if (/(?:request|trace|correlation)[-_]?id\s*[:=]\s*$/i.test(prefix))
|
|
137
|
+
return candidate;
|
|
138
|
+
return isSensitiveFixtureValue(candidate) ? REDACTED_FIXTURE_VALUE : candidate;
|
|
139
|
+
});
|
|
140
|
+
return encodeDiagnosticControls(sanitized);
|
|
141
|
+
}
|
|
142
|
+
function redactSensitiveAssignments(value) {
|
|
143
|
+
return value.replace(/((["']?)([\w-]+)\2\s*[:=]\s*)("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s,;&]+)/gi, (match, prefix, _quote, key, assignmentValue) => {
|
|
144
|
+
if (!isSensitiveFixtureKey(key) && key.toLowerCase() !== "key")
|
|
145
|
+
return match;
|
|
146
|
+
const quote = assignmentValue.startsWith('"')
|
|
147
|
+
? '"'
|
|
148
|
+
: assignmentValue.startsWith("'")
|
|
149
|
+
? "'"
|
|
150
|
+
: "";
|
|
151
|
+
return `${prefix}${quote}${REDACTED_FIXTURE_VALUE}${quote}`;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function isCredentialBearingUrl(value) {
|
|
155
|
+
try {
|
|
156
|
+
const parsed = new URL(value);
|
|
157
|
+
return (parsed.username !== "" ||
|
|
158
|
+
parsed.password !== "" ||
|
|
159
|
+
parsed.hash !== "" ||
|
|
160
|
+
parsed.search !== "" ||
|
|
161
|
+
parsed.pathname.split("/").some((segment, index, segments) => {
|
|
162
|
+
const decoded = decodePathSegment(segment);
|
|
163
|
+
const previous = decodePathSegment(segments[index - 1] ?? "");
|
|
164
|
+
return (isSensitiveFixtureKey(decoded) ||
|
|
165
|
+
isCredentialPathKey(previous) ||
|
|
166
|
+
isSensitiveFixtureValue(decoded));
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function encodeDiagnosticControls(value) {
|
|
174
|
+
let result = "";
|
|
175
|
+
for (const character of value) {
|
|
176
|
+
const code = character.codePointAt(0) ?? 0;
|
|
177
|
+
if (code === 0x0a || code === 0x0d || code === 0x2028 || code === 0x2029) {
|
|
178
|
+
result += " ";
|
|
179
|
+
}
|
|
180
|
+
else if ((code >= 0 && code <= 0x1f) ||
|
|
181
|
+
(code >= 0x7f && code <= 0x9f) ||
|
|
182
|
+
code === 0x061c ||
|
|
183
|
+
code === 0x200e ||
|
|
184
|
+
code === 0x200f ||
|
|
185
|
+
(code >= 0x202a && code <= 0x202e) ||
|
|
186
|
+
(code >= 0x2066 && code <= 0x2069)) {
|
|
187
|
+
result += `\\u${code.toString(16).padStart(4, "0")}`;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
result += character;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
function decodePathSegment(value) {
|
|
196
|
+
try {
|
|
197
|
+
return decodeURIComponent(value);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return value;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function hasExplicitOrigin(value) {
|
|
204
|
+
return /^[a-z][a-z\d+.-]*:\/\//i.test(value);
|
|
205
|
+
}
|
|
206
|
+
function shannonEntropy(value) {
|
|
207
|
+
const counts = new Map();
|
|
208
|
+
for (const character of value)
|
|
209
|
+
counts.set(character, (counts.get(character) ?? 0) + 1);
|
|
210
|
+
let entropy = 0;
|
|
211
|
+
for (const count of counts.values()) {
|
|
212
|
+
const probability = count / value.length;
|
|
213
|
+
entropy -= probability * Math.log2(probability);
|
|
214
|
+
}
|
|
215
|
+
return entropy;
|
|
216
|
+
}
|
package/dist/i18n/catalog.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AuthTurn } from "../types";
|
|
2
|
-
import { type ProviderLocale, type ProviderLocaleCatalog, type ProviderLocaleKey, type ProviderLocaleValue } from "./keys";
|
|
1
|
+
import type { AuthTurn } from "../types.js";
|
|
2
|
+
import { type ProviderLocale, type ProviderLocaleCatalog, type ProviderLocaleKey, type ProviderLocaleValue } from "./keys.js";
|
|
3
3
|
export type ProviderLocaleCatalogMap = Record<ProviderLocale, ProviderLocaleCatalog>;
|
|
4
4
|
export interface LoadProviderLocaleCatalogsOptions {
|
|
5
5
|
providerDir: string;
|
package/dist/i18n/catalog.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { getProviderLocalePath, isProviderLocaleValue, providerLocaleKey, } from "./keys";
|
|
3
|
+
import { getProviderLocalePath, isProviderLocaleValue, providerLocaleKey, } from "./keys.js";
|
|
4
4
|
export function loadProviderLocaleCatalogs(options) {
|
|
5
5
|
const catalogs = {};
|
|
6
6
|
for (const locale of options.locales) {
|
|
@@ -26,9 +26,7 @@ function isStringRecord(value) {
|
|
|
26
26
|
function localizeAuthInputSchema(expectedInput, options) {
|
|
27
27
|
if (!expectedInput)
|
|
28
28
|
return undefined;
|
|
29
|
-
const schema = isRecord(expectedInput.schema)
|
|
30
|
-
? expectedInput.schema
|
|
31
|
-
: expectedInput;
|
|
29
|
+
const schema = isRecord(expectedInput.schema) ? expectedInput.schema : expectedInput;
|
|
32
30
|
const localizedSchema = localizeAuthSchemaObject(schema, options);
|
|
33
31
|
if (localizedSchema === schema)
|
|
34
32
|
return undefined;
|
|
@@ -40,9 +38,7 @@ function isRecord(value) {
|
|
|
40
38
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
41
39
|
}
|
|
42
40
|
function localizeAuthSchemaObject(schema, options) {
|
|
43
|
-
const properties = isRecord(schema.properties)
|
|
44
|
-
? schema.properties
|
|
45
|
-
: undefined;
|
|
41
|
+
const properties = isRecord(schema.properties) ? schema.properties : undefined;
|
|
46
42
|
if (!properties)
|
|
47
43
|
return schema;
|
|
48
44
|
let changed = false;
|
|
@@ -50,9 +46,7 @@ function localizeAuthSchemaObject(schema, options) {
|
|
|
50
46
|
if (!isRecord(property))
|
|
51
47
|
return [fieldName, property];
|
|
52
48
|
const nameKey = typeof property.nameKey === "string" ? property.nameKey : undefined;
|
|
53
|
-
const descriptionKey = typeof property.descriptionKey === "string"
|
|
54
|
-
? property.descriptionKey
|
|
55
|
-
: undefined;
|
|
49
|
+
const descriptionKey = typeof property.descriptionKey === "string" ? property.descriptionKey : undefined;
|
|
56
50
|
const title = nameKey
|
|
57
51
|
? asStringValue(resolveProviderLocaleValue(options.catalogs, nameKey, options.locale, options.fallbackLocale))
|
|
58
52
|
: undefined;
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./catalog";
|
|
2
|
-
export * from "./keys";
|
|
1
|
+
export * from "./catalog.js";
|
|
2
|
+
export * from "./keys.js";
|
package/dist/i18n/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./catalog";
|
|
2
|
-
export * from "./keys";
|
|
1
|
+
export * from "./catalog.js";
|
|
2
|
+
export * from "./keys.js";
|
package/dist/i18n/keys.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ProviderLocaleKey } from "../types";
|
|
2
|
-
export type { ProviderLocale, ProviderLocaleKey } from "../types";
|
|
1
|
+
import type { ProviderLocaleKey } from "../types.js";
|
|
2
|
+
export type { ProviderLocale, ProviderLocaleKey } from "../types.js";
|
|
3
3
|
export declare function providerLocaleKey(key: string): ProviderLocaleKey;
|
|
4
4
|
export declare function isProviderLocaleKey(value: unknown): value is ProviderLocaleKey;
|
|
5
5
|
export declare function assertProviderLocaleKey(value: unknown): asserts value is ProviderLocaleKey;
|