@apifuse/provider-sdk 2.1.0-beta.9 → 2.2.0-beta.10
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 +240 -0
- package/CHANGELOG.md +93 -0
- package/README.md +26 -10
- package/SUBMISSION.md +11 -12
- 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 +36 -0
- package/bin/apifuse-pack-smoke.ts +22 -81
- package/bin/apifuse-pack-types.ts +266 -0
- package/bin/apifuse-perf.ts +45 -127
- package/bin/apifuse-record.ts +53 -70
- package/bin/apifuse-submit-check.ts +2177 -353
- 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/auth-turn.v1.schema.json +89 -0
- package/dist/auth-turn/fixtures/invalid/empty-kind.json +4 -0
- package/dist/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
- package/dist/auth-turn/fixtures/invalid/missing-kind.json +3 -0
- package/dist/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
- package/dist/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
- package/dist/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
- package/dist/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
- package/dist/auth-turn/fixtures/valid/abort.json +8 -0
- package/dist/auth-turn/fixtures/valid/challenge.json +17 -0
- package/dist/auth-turn/fixtures/valid/complete.json +13 -0
- package/dist/auth-turn/fixtures/valid/form.json +14 -0
- package/dist/auth-turn/fixtures/valid/message.json +13 -0
- package/dist/auth-turn/fixtures/valid/multi_choice.json +15 -0
- package/dist/auth-turn/fixtures/valid/pending.json +5 -0
- package/dist/auth-turn/fixtures/valid/poll.json +9 -0
- package/dist/auth-turn/fixtures/valid/redirect.json +16 -0
- package/dist/auth-turn/fixtures/valid/retry.json +8 -0
- package/dist/auth-turn/fixtures/valid/unknown-kind.json +7 -0
- package/dist/auth-turn/index.d.ts +195 -0
- package/dist/auth-turn/index.js +133 -0
- package/dist/auth.d.ts +76 -0
- package/dist/auth.js +427 -0
- package/dist/ceremonies/index.d.ts +1 -1
- package/dist/ceremonies/index.js +14 -48
- 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 +47 -33
- package/dist/cli/prompt-assets.d.ts +80 -0
- package/dist/cli/prompt-assets.js +743 -0
- package/dist/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/dist/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/dist/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/dist/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/dist/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
- package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
- package/dist/cli/templates/provider/.gitignore.tpl +22 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +96 -0
- package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
- package/dist/cli/templates/provider/README.md.tpl +163 -0
- package/dist/cli/templates/provider/dev.ts.tpl +5 -0
- package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
- package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
- package/dist/cli/templates/provider/index.ts.tpl +15 -0
- package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
- package/dist/cli/templates/provider/meta.ts.tpl +7 -0
- package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
- package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/start.ts.tpl +5 -0
- package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/dist/config/loader.d.ts +149 -8
- package/dist/config/loader.js +378 -89
- 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 +5 -6
- package/dist/define.d.ts +13 -1
- package/dist/define.js +245 -178
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +48 -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 +44 -41
- package/dist/index.js +39 -36
- package/dist/lint.d.ts +1 -0
- package/dist/lint.js +35 -15
- package/dist/provider.d.ts +11 -9
- package/dist/provider.js +9 -8
- 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 +1 -1
- package/dist/runtime/auth-flow.js +4 -2
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.js +214 -25
- 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 +15 -3
- package/dist/runtime/http.d.ts +2 -2
- package/dist/runtime/http.js +160 -344
- 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 +56 -19
- package/dist/runtime/keyring.js +1 -1
- package/dist/runtime/namespace.js +1 -1
- 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 +35 -0
- package/dist/runtime/proxy-nodemaven.js +128 -0
- package/dist/runtime/proxy-retry-policy.d.ts +40 -0
- package/dist/runtime/proxy-retry-policy.js +326 -0
- package/dist/runtime/proxy-telemetry.d.ts +2 -1
- package/dist/runtime/proxy-telemetry.js +55 -52
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +2 -4
- package/dist/runtime/request-options.d.ts +1 -1
- 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 +15 -4
- package/dist/runtime/stealth.d.ts +7 -4
- package/dist/runtime/stealth.js +257 -215
- 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 -3
- package/dist/server/index.js +6 -2
- package/dist/server/self-test-input-tokens.d.ts +1 -0
- package/dist/server/self-test-input-tokens.js +37 -0
- package/dist/server/self-test-redaction.d.ts +20 -0
- package/dist/server/self-test-redaction.js +70 -0
- package/dist/server/self-test-token.d.ts +30 -0
- package/dist/server/self-test-token.js +50 -0
- package/dist/server/self-test.d.ts +199 -0
- package/dist/server/self-test.js +1113 -0
- package/dist/server/serve.d.ts +14 -3
- package/dist/server/serve.js +135 -64
- package/dist/server/types.d.ts +10 -9
- package/dist/server/types.js +3 -7
- package/dist/stealth/profiles.d.ts +1 -1
- package/dist/stealth/profiles.js +5 -14
- 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 +1 -1
- package/dist/testing/run.js +12 -15
- package/dist/types.d.ts +237 -1
- package/dist/user-input.d.ts +30 -0
- package/dist/user-input.js +66 -0
- package/package.json +16 -5
- package/src/auth-turn/auth-turn.v1.schema.json +89 -0
- package/src/auth-turn/fixtures/invalid/empty-kind.json +4 -0
- package/src/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
- package/src/auth-turn/fixtures/invalid/missing-kind.json +3 -0
- package/src/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
- package/src/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
- package/src/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
- package/src/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
- package/src/auth-turn/fixtures/valid/abort.json +8 -0
- package/src/auth-turn/fixtures/valid/challenge.json +17 -0
- package/src/auth-turn/fixtures/valid/complete.json +13 -0
- package/src/auth-turn/fixtures/valid/form.json +14 -0
- package/src/auth-turn/fixtures/valid/message.json +13 -0
- package/src/auth-turn/fixtures/valid/multi_choice.json +15 -0
- package/src/auth-turn/fixtures/valid/pending.json +5 -0
- package/src/auth-turn/fixtures/valid/poll.json +9 -0
- package/src/auth-turn/fixtures/valid/redirect.json +16 -0
- package/src/auth-turn/fixtures/valid/retry.json +8 -0
- package/src/auth-turn/fixtures/valid/unknown-kind.json +7 -0
- package/src/auth-turn/index.ts +177 -0
- package/src/auth.ts +728 -0
- package/src/ceremonies/index.ts +33 -121
- package/src/cli/commands.ts +10 -0
- package/src/cli/create.ts +69 -99
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/src/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/src/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/src/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/src/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +96 -0
- package/src/cli/templates/provider/README.md.tpl +7 -4
- package/src/config/loader.ts +543 -208
- package/src/contract-serialization.ts +5 -11
- package/src/contract-types.ts +2 -2
- package/src/contract.ts +13 -28
- package/src/define.ts +397 -528
- package/src/dev.ts +4 -9
- package/src/errors.ts +58 -5
- 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 +64 -41
- package/src/lint.ts +122 -159
- package/src/provider.ts +40 -9
- package/src/public-schema-field-lint.ts +7 -33
- package/src/recipes/gov-api.ts +2 -5
- package/src/runtime/auth-flow.ts +6 -6
- package/src/runtime/browser.ts +320 -151
- 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 +23 -20
- package/src/runtime/http.ts +216 -539
- package/src/runtime/insights.ts +15 -53
- package/src/runtime/instrumentation.ts +78 -65
- package/src/runtime/keyring.ts +7 -19
- package/src/runtime/namespace.ts +2 -7
- 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 +178 -0
- package/src/runtime/proxy-retry-policy.ts +469 -0
- package/src/runtime/proxy-telemetry.ts +79 -77
- package/src/runtime/redis.ts +4 -12
- package/src/runtime/request-options.ts +4 -13
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +41 -110
- package/src/runtime/stealth.ts +331 -369
- 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 +44 -3
- package/src/server/self-test-input-tokens.ts +46 -0
- package/src/server/self-test-redaction.ts +97 -0
- package/src/server/self-test-token.ts +70 -0
- package/src/server/self-test.ts +1450 -0
- package/src/server/serve.ts +206 -216
- package/src/server/types.ts +7 -19
- package/src/stealth/profiles.ts +10 -26
- package/src/stream.ts +8 -19
- package/src/testing/index.ts +2 -2
- package/src/testing/run.ts +24 -64
- package/src/types.ts +274 -1
- package/src/user-input.ts +118 -0
package/src/dev.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { serve } from "./server/serve";
|
|
2
|
-
import type { ProviderDefinition } from "./types";
|
|
1
|
+
import { serve } from "./server/serve.js";
|
|
2
|
+
import type { ProviderDefinition } from "./types.js";
|
|
3
3
|
|
|
4
4
|
export interface DevServerOptions {
|
|
5
5
|
port?: number;
|
|
@@ -18,17 +18,12 @@ export function createDevServer(
|
|
|
18
18
|
console.log(
|
|
19
19
|
`[apifuse dev] ${provider.id}@${provider.version} running at http://localhost:${port}`,
|
|
20
20
|
);
|
|
21
|
-
console.log(
|
|
22
|
-
`[apifuse dev] Operations: ${Object.keys(provider.operations).join(", ")}`,
|
|
23
|
-
);
|
|
21
|
+
console.log(`[apifuse dev] Operations: ${Object.keys(provider.operations).join(", ")}`);
|
|
24
22
|
console.log(`[apifuse dev] Health: http://localhost:${port}/health`);
|
|
25
23
|
},
|
|
26
24
|
};
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
export function startDevServer(
|
|
30
|
-
provider: ProviderDefinition,
|
|
31
|
-
options?: DevServerOptions,
|
|
32
|
-
): void {
|
|
27
|
+
export function startDevServer(provider: ProviderDefinition, options?: DevServerOptions): void {
|
|
33
28
|
createDevServer(provider, options).start();
|
|
34
29
|
}
|
package/src/errors.ts
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
-
import type { ProviderErrorCategory } from "./observability";
|
|
1
|
+
import type { ProviderErrorCategory } from "./observability.js";
|
|
2
|
+
|
|
3
|
+
// Versioned, cross-realm brands. `Symbol.for` resolves to the same symbol in
|
|
4
|
+
// any copy/entrypoint of this SDK major version, so an error created by a
|
|
5
|
+
// duplicate module instance (e.g. the packaged CLI's src/* server vs a
|
|
6
|
+
// provider's dist/* import) still carries a brand the server can recognize even
|
|
7
|
+
// though `instanceof` splits across the two constructors. The `@1` suffix lets a
|
|
8
|
+
// future breaking change to this contract mint a distinct key.
|
|
9
|
+
const PROVIDER_ERROR_BRAND = Symbol.for("@apifuse/provider-sdk/error-brand@1");
|
|
10
|
+
const PROVIDER_ERROR_BRAND_VALUE = 1;
|
|
11
|
+
const SESSION_EXPIRED_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/session-expired@1");
|
|
12
|
+
const TRANSPORT_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/transport@1");
|
|
13
|
+
|
|
14
|
+
// Defines a non-enumerable, non-writable, non-configurable own data property.
|
|
15
|
+
// Immutable + own means a guard can trust it via a single descriptor read
|
|
16
|
+
// without invoking attacker-controlled getters or accepting inherited brands.
|
|
17
|
+
function defineErrorBrand(target: object, brand: symbol, value: number | true): void {
|
|
18
|
+
Object.defineProperty(target, brand, {
|
|
19
|
+
value,
|
|
20
|
+
enumerable: false,
|
|
21
|
+
writable: false,
|
|
22
|
+
configurable: false,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Recognizes an own data-property brand with the expected value. Rejects
|
|
27
|
+
// missing brands (unbranded lookalikes), accessor brands (no own `value`
|
|
28
|
+
// slot — the getter is never called), and inherited brands (own-descriptor
|
|
29
|
+
// lookup returns undefined on the child).
|
|
30
|
+
function hasOwnBrand(value: unknown, brand: symbol, expected: number | true): boolean {
|
|
31
|
+
if (value === null || (typeof value !== "object" && typeof value !== "function")) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, brand);
|
|
35
|
+
return (
|
|
36
|
+
descriptor !== undefined && Object.hasOwn(descriptor, "value") && descriptor.value === expected
|
|
37
|
+
);
|
|
38
|
+
}
|
|
2
39
|
|
|
3
40
|
export type ProviderErrorOptions = {
|
|
4
41
|
fix?: string;
|
|
@@ -19,6 +56,7 @@ export class ProviderError extends Error {
|
|
|
19
56
|
if (options?.cause) {
|
|
20
57
|
this.cause = options.cause;
|
|
21
58
|
}
|
|
59
|
+
defineErrorBrand(this, PROVIDER_ERROR_BRAND, PROVIDER_ERROR_BRAND_VALUE);
|
|
22
60
|
}
|
|
23
61
|
|
|
24
62
|
get fix(): string | undefined {
|
|
@@ -49,10 +87,7 @@ export class AuthError extends ProviderError {
|
|
|
49
87
|
}
|
|
50
88
|
|
|
51
89
|
export class SessionExpiredError extends AuthError {
|
|
52
|
-
constructor(
|
|
53
|
-
message = "Provider session expired",
|
|
54
|
-
options?: ProviderErrorOptions,
|
|
55
|
-
) {
|
|
90
|
+
constructor(message = "Provider session expired", options?: ProviderErrorOptions) {
|
|
56
91
|
super(message, {
|
|
57
92
|
code: "reauth_required",
|
|
58
93
|
category: "credential_expired",
|
|
@@ -60,6 +95,7 @@ export class SessionExpiredError extends AuthError {
|
|
|
60
95
|
...options,
|
|
61
96
|
});
|
|
62
97
|
this.name = "SessionExpiredError";
|
|
98
|
+
defineErrorBrand(this, SESSION_EXPIRED_BRAND, true);
|
|
63
99
|
}
|
|
64
100
|
}
|
|
65
101
|
|
|
@@ -91,9 +127,26 @@ export class TransportError extends ProviderError {
|
|
|
91
127
|
this.name = "TransportError";
|
|
92
128
|
this.status = options?.status;
|
|
93
129
|
this.upstreamStatus = options?.upstreamStatus ?? options?.status;
|
|
130
|
+
defineErrorBrand(this, TRANSPORT_BRAND, true);
|
|
94
131
|
}
|
|
95
132
|
}
|
|
96
133
|
|
|
134
|
+
// Cross-module type guards. Prefer these over `instanceof` at any boundary that
|
|
135
|
+
// may receive an error from a different copy/entrypoint of the SDK (see the HTTP
|
|
136
|
+
// server error boundary). They recognize branded errors regardless of which
|
|
137
|
+
// module instance constructed them, while rejecting unbranded lookalikes.
|
|
138
|
+
export function isProviderError(value: unknown): value is ProviderError {
|
|
139
|
+
return hasOwnBrand(value, PROVIDER_ERROR_BRAND, PROVIDER_ERROR_BRAND_VALUE);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function isSessionExpiredError(value: unknown): value is SessionExpiredError {
|
|
143
|
+
return isProviderError(value) && hasOwnBrand(value, SESSION_EXPIRED_BRAND, true);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function isTransportError(value: unknown): value is TransportError {
|
|
147
|
+
return isProviderError(value) && hasOwnBrand(value, TRANSPORT_BRAND, true);
|
|
148
|
+
}
|
|
149
|
+
|
|
97
150
|
export class ProviderSecretError extends ProviderError {
|
|
98
151
|
constructor(message: string, options?: ProviderErrorOptions) {
|
|
99
152
|
super(message, { code: "provider_secret_error", ...options });
|
package/src/i18n/catalog.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
|
-
import type { AuthTurn } from "../types";
|
|
4
|
+
import type { AuthTurn } from "../types.js";
|
|
5
5
|
import {
|
|
6
6
|
getProviderLocalePath,
|
|
7
7
|
isProviderLocaleValue,
|
|
@@ -10,12 +10,9 @@ import {
|
|
|
10
10
|
type ProviderLocaleKey,
|
|
11
11
|
type ProviderLocaleValue,
|
|
12
12
|
providerLocaleKey,
|
|
13
|
-
} from "./keys";
|
|
13
|
+
} from "./keys.js";
|
|
14
14
|
|
|
15
|
-
export type ProviderLocaleCatalogMap = Record<
|
|
16
|
-
ProviderLocale,
|
|
17
|
-
ProviderLocaleCatalog
|
|
18
|
-
>;
|
|
15
|
+
export type ProviderLocaleCatalogMap = Record<ProviderLocale, ProviderLocaleCatalog>;
|
|
19
16
|
|
|
20
17
|
export interface LoadProviderLocaleCatalogsOptions {
|
|
21
18
|
providerDir: string;
|
|
@@ -58,9 +55,7 @@ export function resolveProviderLocaleValue(
|
|
|
58
55
|
);
|
|
59
56
|
}
|
|
60
57
|
|
|
61
|
-
function asStringValue(
|
|
62
|
-
value: ProviderLocaleValue | undefined,
|
|
63
|
-
): string | undefined {
|
|
58
|
+
function asStringValue(value: ProviderLocaleValue | undefined): string | undefined {
|
|
64
59
|
return typeof value === "string" ? value : undefined;
|
|
65
60
|
}
|
|
66
61
|
|
|
@@ -82,9 +77,7 @@ function localizeAuthInputSchema(
|
|
|
82
77
|
},
|
|
83
78
|
): Record<string, unknown> | undefined {
|
|
84
79
|
if (!expectedInput) return undefined;
|
|
85
|
-
const schema = isRecord(expectedInput.schema)
|
|
86
|
-
? expectedInput.schema
|
|
87
|
-
: expectedInput;
|
|
80
|
+
const schema = isRecord(expectedInput.schema) ? expectedInput.schema : expectedInput;
|
|
88
81
|
const localizedSchema = localizeAuthSchemaObject(schema, options);
|
|
89
82
|
if (localizedSchema === schema) return undefined;
|
|
90
83
|
return isRecord(expectedInput.schema)
|
|
@@ -104,21 +97,16 @@ function localizeAuthSchemaObject(
|
|
|
104
97
|
fallbackLocale: ProviderLocale;
|
|
105
98
|
},
|
|
106
99
|
): Record<string, unknown> {
|
|
107
|
-
const properties = isRecord(schema.properties)
|
|
108
|
-
? schema.properties
|
|
109
|
-
: undefined;
|
|
100
|
+
const properties = isRecord(schema.properties) ? schema.properties : undefined;
|
|
110
101
|
if (!properties) return schema;
|
|
111
102
|
|
|
112
103
|
let changed = false;
|
|
113
104
|
const localizedProperties = Object.fromEntries(
|
|
114
105
|
Object.entries(properties).map(([fieldName, property]) => {
|
|
115
106
|
if (!isRecord(property)) return [fieldName, property];
|
|
116
|
-
const nameKey =
|
|
117
|
-
typeof property.nameKey === "string" ? property.nameKey : undefined;
|
|
107
|
+
const nameKey = typeof property.nameKey === "string" ? property.nameKey : undefined;
|
|
118
108
|
const descriptionKey =
|
|
119
|
-
typeof property.descriptionKey === "string"
|
|
120
|
-
? property.descriptionKey
|
|
121
|
-
: undefined;
|
|
109
|
+
typeof property.descriptionKey === "string" ? property.descriptionKey : undefined;
|
|
122
110
|
const title = nameKey
|
|
123
111
|
? asStringValue(
|
|
124
112
|
resolveProviderLocaleValue(
|
|
@@ -166,12 +154,7 @@ export function localizeAuthTurn(
|
|
|
166
154
|
const fallbackLocale = options.fallbackLocale ?? "en";
|
|
167
155
|
const hint = turn.hintKey
|
|
168
156
|
? asStringValue(
|
|
169
|
-
resolveProviderLocaleValue(
|
|
170
|
-
options.catalogs,
|
|
171
|
-
turn.hintKey,
|
|
172
|
-
options.locale,
|
|
173
|
-
fallbackLocale,
|
|
174
|
-
),
|
|
157
|
+
resolveProviderLocaleValue(options.catalogs, turn.hintKey, options.locale, fallbackLocale),
|
|
175
158
|
)
|
|
176
159
|
: undefined;
|
|
177
160
|
const expectedInput = localizeAuthInputSchema(turn.expectedInput, {
|
|
@@ -184,12 +167,7 @@ export function localizeAuthTurn(
|
|
|
184
167
|
? Object.fromEntries(
|
|
185
168
|
Object.entries(fieldErrorKeys).flatMap(([fieldName, key]) => {
|
|
186
169
|
const message = asStringValue(
|
|
187
|
-
resolveProviderLocaleValue(
|
|
188
|
-
options.catalogs,
|
|
189
|
-
key,
|
|
190
|
-
options.locale,
|
|
191
|
-
fallbackLocale,
|
|
192
|
-
),
|
|
170
|
+
resolveProviderLocaleValue(options.catalogs, key, options.locale, fallbackLocale),
|
|
193
171
|
);
|
|
194
172
|
return message ? [[fieldName, message]] : [];
|
|
195
173
|
}),
|
package/src/i18n/index.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/src/i18n/keys.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ProviderLocaleKey } from "../types";
|
|
1
|
+
import type { ProviderLocaleKey } from "../types.js";
|
|
2
2
|
|
|
3
|
-
export type { ProviderLocale, ProviderLocaleKey } from "../types";
|
|
3
|
+
export type { ProviderLocale, ProviderLocaleKey } from "../types.js";
|
|
4
4
|
|
|
5
5
|
const PROVIDER_LOCALE_KEY_RE =
|
|
6
6
|
/^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]+)*(?:\.[a-z][a-z0-9]*(?:[A-Z][a-z0-9]+)*|\.[0-9]+)*$/;
|
|
@@ -10,15 +10,11 @@ export function providerLocaleKey(key: string): ProviderLocaleKey {
|
|
|
10
10
|
return key;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function isProviderLocaleKey(
|
|
14
|
-
value: unknown,
|
|
15
|
-
): value is ProviderLocaleKey {
|
|
13
|
+
export function isProviderLocaleKey(value: unknown): value is ProviderLocaleKey {
|
|
16
14
|
return typeof value === "string" && PROVIDER_LOCALE_KEY_RE.test(value);
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
export function assertProviderLocaleKey(
|
|
20
|
-
value: unknown,
|
|
21
|
-
): asserts value is ProviderLocaleKey {
|
|
17
|
+
export function assertProviderLocaleKey(value: unknown): asserts value is ProviderLocaleKey {
|
|
22
18
|
if (!isProviderLocaleKey(value)) {
|
|
23
19
|
throw new Error(
|
|
24
20
|
`Provider locale key must be a dot path such as "meta.description" or "operations.search.description"; received ${JSON.stringify(value)}`,
|
|
@@ -50,9 +46,7 @@ export function getProviderLocalePath(
|
|
|
50
46
|
export type ProviderLocaleValue = string | readonly string[];
|
|
51
47
|
export type ProviderLocaleCatalog = Record<string, unknown>;
|
|
52
48
|
|
|
53
|
-
export function isProviderLocaleValue(
|
|
54
|
-
value: unknown,
|
|
55
|
-
): value is ProviderLocaleValue {
|
|
49
|
+
export function isProviderLocaleValue(value: unknown): value is ProviderLocaleValue {
|
|
56
50
|
return (
|
|
57
51
|
typeof value === "string" ||
|
|
58
52
|
(Array.isArray(value) && value.every((entry) => typeof entry === "string"))
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// @apifuse/provider-sdk
|
|
2
2
|
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./auth.js";
|
|
4
|
+
export * from "./ceremonies/index.js";
|
|
5
|
+
export * from "./choice-token.js";
|
|
5
6
|
export type {
|
|
6
7
|
ApiFuseConfig,
|
|
7
8
|
BrowserConfig,
|
|
8
9
|
ProxyConfig,
|
|
9
10
|
SessionConfig,
|
|
10
|
-
} from "./config/loader";
|
|
11
|
-
export { defineConfig, loadApiFuseConfig } from "./config/loader";
|
|
11
|
+
} from "./config/loader.js";
|
|
12
|
+
export { defineConfig, loadApiFuseConfig } from "./config/loader.js";
|
|
12
13
|
export {
|
|
13
14
|
canonicalJson,
|
|
14
15
|
digestProviderContract,
|
|
@@ -18,8 +19,10 @@ export {
|
|
|
18
19
|
PROVIDER_CONTRACT_SCHEMA_VERSION,
|
|
19
20
|
type ProviderContractOperation,
|
|
20
21
|
type ProviderContractSnapshot,
|
|
21
|
-
} from "./contract";
|
|
22
|
+
} from "./contract.js";
|
|
22
23
|
export {
|
|
24
|
+
centered,
|
|
25
|
+
delayed,
|
|
23
26
|
defineHealthJourney,
|
|
24
27
|
defineOperation,
|
|
25
28
|
defineProvider,
|
|
@@ -27,54 +30,60 @@ export {
|
|
|
27
30
|
defineStreamOperation,
|
|
28
31
|
every,
|
|
29
32
|
type ProviderConfig,
|
|
30
|
-
} from "./define";
|
|
31
|
-
export type { DevServerOptions } from "./dev";
|
|
32
|
-
export { createDevServer, startDevServer } from "./dev";
|
|
33
|
-
export * from "./errors";
|
|
34
|
-
export * from "./
|
|
33
|
+
} from "./define.js";
|
|
34
|
+
export type { DevServerOptions } from "./dev.js";
|
|
35
|
+
export { createDevServer, startDevServer } from "./dev.js";
|
|
36
|
+
export * from "./errors.js";
|
|
37
|
+
export * from "./user-input.js";
|
|
38
|
+
export * from "./i18n/index.js";
|
|
35
39
|
export {
|
|
36
40
|
type LintDiagnostic,
|
|
37
41
|
lintOperation,
|
|
38
42
|
lintProvider,
|
|
39
|
-
} from "./lint";
|
|
40
|
-
export * from "./recipes/gov-api";
|
|
41
|
-
export * from "./recipes/rest-api";
|
|
42
|
-
export { createFlowContext, createScratchpad } from "./runtime/auth-flow";
|
|
43
|
-
export type { BrowserClientOptions } from "./runtime/browser";
|
|
44
|
-
export { BrowserClient, createBrowserClient } from "./runtime/browser";
|
|
43
|
+
} from "./lint.js";
|
|
44
|
+
export * from "./recipes/gov-api.js";
|
|
45
|
+
export * from "./recipes/rest-api.js";
|
|
46
|
+
export { createFlowContext, createScratchpad } from "./runtime/auth-flow.js";
|
|
47
|
+
export type { BrowserClientOptions } from "./runtime/browser.js";
|
|
48
|
+
export { BrowserClient, createBrowserClient } from "./runtime/browser.js";
|
|
45
49
|
export {
|
|
46
50
|
createBypassProviderCache,
|
|
47
51
|
createProviderCache,
|
|
48
52
|
type ProviderCacheOptions,
|
|
49
53
|
resetProviderCacheForTests,
|
|
50
|
-
} from "./runtime/cache";
|
|
54
|
+
} from "./runtime/cache.js";
|
|
51
55
|
export {
|
|
52
56
|
type CreateProviderChoiceContextOptions,
|
|
53
57
|
createProviderChoiceContext,
|
|
54
58
|
createTestProviderChoiceContext,
|
|
55
59
|
PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV,
|
|
56
|
-
} from "./runtime/choice";
|
|
60
|
+
} from "./runtime/choice.js";
|
|
57
61
|
export {
|
|
58
62
|
type CreateCredentialContextOptions,
|
|
59
63
|
createCredentialContext,
|
|
60
|
-
} from "./runtime/credential";
|
|
61
|
-
export { createEnvContext } from "./runtime/env";
|
|
62
|
-
export { executeOperation } from "./runtime/executor";
|
|
63
|
-
export { createHttpClient } from "./runtime/http";
|
|
64
|
-
export type { Insight, InsightSeverity } from "./runtime/insights";
|
|
65
|
-
export { generateInsights } from "./runtime/insights";
|
|
64
|
+
} from "./runtime/credential.js";
|
|
65
|
+
export { createEnvContext } from "./runtime/env.js";
|
|
66
|
+
export { executeOperation } from "./runtime/executor.js";
|
|
67
|
+
export { createHttpClient } from "./runtime/http.js";
|
|
68
|
+
export type { Insight, InsightSeverity } from "./runtime/insights.js";
|
|
69
|
+
export { generateInsights } from "./runtime/insights.js";
|
|
66
70
|
export {
|
|
67
71
|
type InstrumentationOptions,
|
|
68
72
|
type InstrumentedProviderContext,
|
|
69
73
|
wrapWithInstrumentation,
|
|
70
|
-
} from "./runtime/instrumentation";
|
|
71
|
-
export { type PrevalidateResult, prevalidate } from "./runtime/prevalidate";
|
|
72
|
-
export { getProviderBaseUrl } from "./runtime/provider";
|
|
74
|
+
} from "./runtime/instrumentation.js";
|
|
75
|
+
export { type PrevalidateResult, prevalidate } from "./runtime/prevalidate.js";
|
|
76
|
+
export { getProviderBaseUrl } from "./runtime/provider.js";
|
|
77
|
+
export {
|
|
78
|
+
assertRequiredSecretsPresent,
|
|
79
|
+
listMissingRequiredSecrets,
|
|
80
|
+
MISSING_SECRET_CODE,
|
|
81
|
+
} from "./runtime/secrets.js";
|
|
73
82
|
export {
|
|
74
83
|
createUnsupportedProviderRuntimeState,
|
|
75
84
|
UnsupportedProviderStateError,
|
|
76
|
-
} from "./runtime/state";
|
|
77
|
-
export { createStealthClient } from "./runtime/stealth";
|
|
85
|
+
} from "./runtime/state.js";
|
|
86
|
+
export { createStealthClient } from "./runtime/stealth.js";
|
|
78
87
|
export {
|
|
79
88
|
APIFUSE__STT__BACKEND_ENV,
|
|
80
89
|
APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV,
|
|
@@ -83,13 +92,13 @@ export {
|
|
|
83
92
|
createUnsupportedSttClient,
|
|
84
93
|
extractVerificationCode,
|
|
85
94
|
resolveSttPrompt,
|
|
86
|
-
} from "./runtime/stt";
|
|
95
|
+
} from "./runtime/stt.js";
|
|
87
96
|
export {
|
|
88
97
|
type CreateTraceContextOptions,
|
|
89
98
|
createTraceContext,
|
|
90
99
|
type Span,
|
|
91
100
|
type TraceContext,
|
|
92
|
-
} from "./runtime/trace";
|
|
101
|
+
} from "./runtime/trace.js";
|
|
93
102
|
export {
|
|
94
103
|
APIFUSE_DESCRIPTION_KEY_META_KEY,
|
|
95
104
|
APIFUSE_REDACTION_MARKER,
|
|
@@ -106,10 +115,10 @@ export {
|
|
|
106
115
|
type SensitivePath,
|
|
107
116
|
sensitive,
|
|
108
117
|
z,
|
|
109
|
-
} from "./schema";
|
|
110
|
-
export { createServerApp, type ServeOptions, serve } from "./server";
|
|
111
|
-
export { getStealthProfile, listStealthProfiles } from "./stealth/profiles";
|
|
112
|
-
export * from "./stream";
|
|
118
|
+
} from "./schema.js";
|
|
119
|
+
export { createServerApp, type ServeOptions, serve } from "./server/index.js";
|
|
120
|
+
export { getStealthProfile, listStealthProfiles } from "./stealth/profiles.js";
|
|
121
|
+
export * from "./stream.js";
|
|
113
122
|
export type {
|
|
114
123
|
ApiFuseResponse,
|
|
115
124
|
AuthConfig,
|
|
@@ -122,8 +131,15 @@ export type {
|
|
|
122
131
|
Bcp47Locale,
|
|
123
132
|
BrowserEngine,
|
|
124
133
|
BrowserOptions,
|
|
134
|
+
BrowserResourceBody,
|
|
135
|
+
BrowserResourceDecision,
|
|
136
|
+
BrowserResourceMethod,
|
|
137
|
+
BrowserResourcePolicy,
|
|
138
|
+
BrowserResourceRequest,
|
|
139
|
+
BrowserResourceRoute,
|
|
125
140
|
ConnectionMode,
|
|
126
141
|
ContextDeclaration,
|
|
142
|
+
CookieJar,
|
|
127
143
|
ContextScratchpad,
|
|
128
144
|
CredentialContext,
|
|
129
145
|
CredentialDeclaration,
|
|
@@ -144,6 +160,7 @@ export type {
|
|
|
144
160
|
HealthJourneyRunContext,
|
|
145
161
|
HealthJourneyRunResult,
|
|
146
162
|
HealthJourneySchedule,
|
|
163
|
+
HealthScheduleRandomization,
|
|
147
164
|
HealthJourneySmsContext,
|
|
148
165
|
HealthJourneyStep,
|
|
149
166
|
HttpClient,
|
|
@@ -190,7 +207,9 @@ export type {
|
|
|
190
207
|
ProviderChoiceParseOptions,
|
|
191
208
|
ProviderContext,
|
|
192
209
|
ProviderDefinition,
|
|
210
|
+
ProviderDeploymentOverrides,
|
|
193
211
|
ProviderHealthMonitorConfig,
|
|
212
|
+
ProviderHealthProbeConfig,
|
|
194
213
|
ProviderLocale,
|
|
195
214
|
ProviderLocaleKey,
|
|
196
215
|
ProviderLocaleKeyInput,
|
|
@@ -229,8 +248,12 @@ export type {
|
|
|
229
248
|
StealthFetchOptions,
|
|
230
249
|
StealthPlatform,
|
|
231
250
|
StealthProfile,
|
|
251
|
+
StealthRedirectHop,
|
|
252
|
+
StealthRedirectRunOptions,
|
|
253
|
+
StealthRedirectRunResult,
|
|
232
254
|
StealthResponse,
|
|
233
255
|
StealthSession,
|
|
256
|
+
StealthSessionCookies,
|
|
234
257
|
SttAudioInput,
|
|
235
258
|
SttContext,
|
|
236
259
|
SttPromptPolicy,
|
|
@@ -247,7 +270,7 @@ export type {
|
|
|
247
270
|
VerificationCodeCandidate,
|
|
248
271
|
VerificationCodeCandidateSource,
|
|
249
272
|
VerificationCodeExtractionResult,
|
|
250
|
-
} from "./types";
|
|
273
|
+
} from "./types.js";
|
|
251
274
|
export {
|
|
252
275
|
DEFAULT_OPERATION_TRANSPORT,
|
|
253
276
|
HttpRetryAfterPolicy,
|
|
@@ -264,8 +287,8 @@ export {
|
|
|
264
287
|
STREAM_IDLE_TIMEOUT_MS_MIN,
|
|
265
288
|
STREAM_MAX_DURATION_MS_MAX,
|
|
266
289
|
STREAM_MAX_DURATION_MS_MIN,
|
|
267
|
-
} from "./types";
|
|
268
|
-
export * from "./utils/date";
|
|
269
|
-
export * from "./utils/parse";
|
|
270
|
-
export * from "./utils/text";
|
|
271
|
-
export * from "./utils/transform";
|
|
290
|
+
} from "./types.js";
|
|
291
|
+
export * from "./utils/date.js";
|
|
292
|
+
export * from "./utils/parse.js";
|
|
293
|
+
export * from "./utils/text.js";
|
|
294
|
+
export * from "./utils/transform.js";
|