@apifuse/provider-sdk 2.2.0-beta.60 → 2.2.0-beta.62
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 +17 -16
- package/CHANGELOG.md +8 -0
- package/bin/apifuse-dev.ts +5 -7
- package/bin/apifuse-pack-types.ts +26 -0
- package/bin/apifuse-perf.ts +4 -6
- package/bin/apifuse-record.ts +4 -7
- package/bin/apifuse-submit-check.ts +2 -2
- package/dist/define.d.ts +3 -2
- package/dist/define.js +1 -1
- package/dist/dev.js +3 -1
- package/dist/engine.d.ts +7 -6
- package/dist/engine.js +3 -4
- package/dist/error-resolution.js +21 -4
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +9 -0
- package/dist/handle-meta.d.ts +55 -0
- package/dist/handle-meta.js +57 -0
- package/dist/handle.d.ts +208 -0
- package/dist/handle.js +299 -0
- package/dist/i18n/catalog.js +21 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/lint.d.ts +3 -0
- package/dist/lint.js +372 -47
- package/dist/provider.d.ts +5 -3
- package/dist/provider.js +4 -2
- package/dist/runtime/handle-wordlist.d.ts +43 -0
- package/dist/runtime/{choice-wordlist.js → handle-wordlist.js} +127 -9
- package/dist/runtime/handle.d.ts +71 -0
- package/dist/runtime/handle.js +900 -0
- package/dist/runtime/http-telemetry-binding.d.ts +10 -0
- package/dist/runtime/http-telemetry-binding.js +152 -0
- package/dist/runtime/http-telemetry-guard.d.ts +6 -0
- package/dist/runtime/http-telemetry-guard.js +150 -0
- package/dist/runtime/http-telemetry.d.ts +104 -0
- package/dist/runtime/http-telemetry.js +190 -0
- package/dist/runtime/http.d.ts +31 -0
- package/dist/runtime/http.js +222 -146
- package/dist/runtime/native-network.d.ts +10 -1
- package/dist/runtime/native-network.js +230 -29
- package/dist/runtime/native-telemetry.d.ts +142 -0
- package/dist/runtime/native-telemetry.js +231 -0
- package/dist/runtime/state.d.ts +4 -1
- package/dist/runtime/state.js +32 -17
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +2 -0
- package/dist/server/sensitive-values.d.ts +1 -1
- package/dist/server/sensitive-values.js +0 -3
- package/dist/server/serve-implementation.d.ts +6 -11
- package/dist/server/serve-implementation.js +119 -52
- package/dist/testing/run.js +10 -7
- package/dist/types.d.ts +4 -107
- package/package.json +1 -1
- package/src/define.ts +4 -3
- package/src/dev.ts +3 -1
- package/src/engine.ts +5 -6
- package/src/error-resolution.ts +21 -4
- package/src/errors.ts +13 -0
- package/src/handle-meta.ts +93 -0
- package/src/handle.ts +612 -0
- package/src/i18n/catalog.ts +23 -1
- package/src/index.ts +45 -13
- package/src/lint.ts +437 -55
- package/src/provider.ts +19 -20
- package/src/runtime/{choice-wordlist.ts → handle-wordlist.ts} +130 -9
- package/src/runtime/handle.ts +1172 -0
- package/src/runtime/http-telemetry-binding.ts +162 -0
- package/src/runtime/http-telemetry-guard.ts +155 -0
- package/src/runtime/http-telemetry.ts +292 -0
- package/src/runtime/http.ts +295 -173
- package/src/runtime/native-network.ts +281 -33
- package/src/runtime/native-telemetry.ts +366 -0
- package/src/runtime/state.ts +44 -16
- package/src/server/index.ts +30 -0
- package/src/server/sensitive-values.ts +0 -3
- package/src/server/serve-implementation.ts +127 -89
- package/src/testing/run.ts +11 -7
- package/src/types.ts +4 -137
- package/dist/choice-token.d.ts +0 -24
- package/dist/choice-token.js +0 -74
- package/dist/runtime/choice-wordlist.d.ts +0 -9
- package/dist/runtime/choice.d.ts +0 -27
- package/dist/runtime/choice.js +0 -801
- package/src/choice-token.ts +0 -165
- package/src/runtime/choice.ts +0 -1197
package/dist/choice-token.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes, timingSafeEqual, } from "node:crypto";
|
|
2
|
-
export class ProviderChoiceTokenError extends Error {
|
|
3
|
-
reason;
|
|
4
|
-
constructor(reason, message) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = "ProviderChoiceTokenError";
|
|
7
|
-
this.reason = reason;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export function createProviderChoiceToken(options) {
|
|
11
|
-
const iv = randomBytes(12);
|
|
12
|
-
const cipher = createCipheriv("aes-256-gcm", choiceEncryptionKey(options.secret), iv);
|
|
13
|
-
const encryptedPayload = Buffer.concat([
|
|
14
|
-
cipher.update(JSON.stringify(options.payload), "utf8"),
|
|
15
|
-
cipher.final(),
|
|
16
|
-
]).toString("base64url");
|
|
17
|
-
const authTag = cipher.getAuthTag().toString("base64url");
|
|
18
|
-
const encodedIv = iv.toString("base64url");
|
|
19
|
-
const signature = signProviderChoiceTokenBody(`${options.prefix}.${encodedIv}.${encryptedPayload}.${authTag}`, options.secret);
|
|
20
|
-
return `${options.prefix}.${encodedIv}.${encryptedPayload}.${authTag}.${signature}`;
|
|
21
|
-
}
|
|
22
|
-
export function parseProviderChoiceToken(options) {
|
|
23
|
-
const [actualPrefix, encodedIv, encryptedPayload, authTag, signature, ...extra] = options.token.split(".");
|
|
24
|
-
if (actualPrefix !== options.prefix ||
|
|
25
|
-
!encodedIv ||
|
|
26
|
-
!encryptedPayload ||
|
|
27
|
-
!authTag ||
|
|
28
|
-
!signature ||
|
|
29
|
-
extra.length > 0) {
|
|
30
|
-
throw new ProviderChoiceTokenError("invalid_shape", "Provider choice token shape is invalid.");
|
|
31
|
-
}
|
|
32
|
-
const signedBody = `${options.prefix}.${encodedIv}.${encryptedPayload}.${authTag}`;
|
|
33
|
-
const expectedSignature = signProviderChoiceTokenBody(signedBody, options.secret);
|
|
34
|
-
const actualBuffer = Buffer.from(signature);
|
|
35
|
-
const expectedBuffer = Buffer.from(expectedSignature);
|
|
36
|
-
if (actualBuffer.length !== expectedBuffer.length ||
|
|
37
|
-
!timingSafeEqual(actualBuffer, expectedBuffer)) {
|
|
38
|
-
throw new ProviderChoiceTokenError("invalid_signature", "Provider choice token signature is invalid.");
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const decipher = createDecipheriv("aes-256-gcm", choiceEncryptionKey(options.secret), Buffer.from(encodedIv, "base64url"));
|
|
42
|
-
decipher.setAuthTag(Buffer.from(authTag, "base64url"));
|
|
43
|
-
const decrypted = Buffer.concat([
|
|
44
|
-
decipher.update(Buffer.from(encryptedPayload, "base64url")),
|
|
45
|
-
decipher.final(),
|
|
46
|
-
]).toString("utf8");
|
|
47
|
-
const parsed = JSON.parse(decrypted);
|
|
48
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
49
|
-
throw new Error("payload is not an object");
|
|
50
|
-
}
|
|
51
|
-
return Object.fromEntries(Object.entries(parsed));
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
throw new ProviderChoiceTokenError("invalid_payload", "Provider choice token payload is invalid.");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export function assertFreshProviderChoiceIssuedAt(issuedAtMs, options) {
|
|
58
|
-
const parsed = typeof issuedAtMs === "number" ? issuedAtMs : Number(issuedAtMs);
|
|
59
|
-
const nowMs = options.nowMs ?? Date.now();
|
|
60
|
-
const futureToleranceMs = options.futureToleranceMs ?? 30_000;
|
|
61
|
-
if (!Number.isFinite(parsed) ||
|
|
62
|
-
parsed <= 0 ||
|
|
63
|
-
nowMs - parsed > options.ttlMs ||
|
|
64
|
-
parsed - nowMs > futureToleranceMs) {
|
|
65
|
-
throw new ProviderChoiceTokenError("stale", "Provider choice token is stale.");
|
|
66
|
-
}
|
|
67
|
-
return parsed;
|
|
68
|
-
}
|
|
69
|
-
function choiceEncryptionKey(secret) {
|
|
70
|
-
return createHash("sha256").update(secret).digest();
|
|
71
|
-
}
|
|
72
|
-
function signProviderChoiceTokenBody(body, secret) {
|
|
73
|
-
return createHmac("sha256", secret).update(body).digest("base64url");
|
|
74
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const CHOICE_WORDLIST_SIZE = 1296;
|
|
2
|
-
export declare const CHOICE_WORD_ENTROPY_BITS: number;
|
|
3
|
-
export declare const STANDARD_CHOICE_WORD_COUNT = 4;
|
|
4
|
-
export declare const HIGH_CHOICE_WORD_COUNT = 5;
|
|
5
|
-
export declare const STANDARD_CHOICE_ENTROPY_BITS: number;
|
|
6
|
-
export declare const HIGH_CHOICE_ENTROPY_BITS: number;
|
|
7
|
-
export declare const EFF_SHORT_WORDLIST_2: readonly string[];
|
|
8
|
-
export declare function choiceWordAt(index: number): string;
|
|
9
|
-
export declare function isChoiceWord(value: string): boolean;
|
package/dist/runtime/choice.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { CredentialContext, EnvContext, ProviderChoiceConsumeMode, ProviderChoiceContext, ProviderRequestContext, ProviderRuntimeState } from "../types.js";
|
|
2
|
-
export declare const PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV = "APIFUSE__PROVIDER_RUNTIME__CHOICE_TOKEN_MASTER_SECRET";
|
|
3
|
-
export type ProviderChoiceTelemetryEvent = {
|
|
4
|
-
readonly providerId: string;
|
|
5
|
-
readonly purpose: string;
|
|
6
|
-
readonly operation: "parse" | "consume";
|
|
7
|
-
readonly format: "word" | "legacy";
|
|
8
|
-
readonly outcome: "success" | "not-found" | "invalid" | "unsupported" | "error";
|
|
9
|
-
readonly consumeMode: ProviderChoiceConsumeMode;
|
|
10
|
-
readonly consumed: boolean;
|
|
11
|
-
readonly replay: boolean;
|
|
12
|
-
};
|
|
13
|
-
export type CreateProviderChoiceContextOptions = {
|
|
14
|
-
readonly providerId: string;
|
|
15
|
-
readonly env?: EnvContext;
|
|
16
|
-
readonly request?: ProviderRequestContext;
|
|
17
|
-
readonly credential?: CredentialContext;
|
|
18
|
-
readonly state?: ProviderRuntimeState;
|
|
19
|
-
readonly masterSecret?: string;
|
|
20
|
-
readonly kid?: string;
|
|
21
|
-
/** Receives allowlisted metadata only; token and payload values are never included. */
|
|
22
|
-
readonly onTelemetry?: (event: ProviderChoiceTelemetryEvent) => void;
|
|
23
|
-
};
|
|
24
|
-
export declare function createProviderChoiceContext(options: CreateProviderChoiceContextOptions): ProviderChoiceContext;
|
|
25
|
-
export declare function createTestProviderChoiceContext(options: Omit<CreateProviderChoiceContextOptions, "masterSecret"> & {
|
|
26
|
-
readonly masterSecret?: string;
|
|
27
|
-
}): ProviderChoiceContext;
|