@apifuse/provider-sdk 2.1.0-beta.9 → 2.2.0-beta.1
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 +134 -0
- package/CHANGELOG.md +56 -0
- package/README.md +21 -9
- package/SUBMISSION.md +10 -11
- package/bin/apifuse-pack-check.ts +22 -0
- package/bin/apifuse-submit-check.ts +1747 -388
- 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 +436 -0
- package/dist/ceremonies/index.js +7 -31
- package/dist/cli/create.js +45 -30
- 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 +87 -0
- package/dist/cli/templates/provider/CLAUDE.md.tpl +1 -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/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/dist/cli/templates/provider/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/dist/cli/templates/provider/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/dist/cli/templates/provider/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/dist/cli/templates/provider/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/dist/cli/templates/provider/skills/upstream-notes/README.md.tpl +13 -0
- package/dist/cli/templates/provider/start.ts.tpl +5 -0
- package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/dist/contract.js +1 -0
- package/dist/define.d.ts +6 -1
- package/dist/define.js +140 -70
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/lint.d.ts +1 -0
- package/dist/lint.js +27 -0
- package/dist/provider.d.ts +4 -2
- package/dist/provider.js +2 -1
- package/dist/runtime/auth-flow.js +2 -0
- package/dist/runtime/browser.js +203 -0
- package/dist/runtime/http.js +28 -8
- package/dist/runtime/stealth.d.ts +5 -2
- package/dist/runtime/stealth.js +149 -3
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +4 -0
- 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 +98 -0
- package/dist/server/self-test.js +555 -0
- package/dist/server/serve.d.ts +6 -0
- package/dist/server/serve.js +33 -8
- package/dist/testing/run.js +5 -1
- package/dist/types.d.ts +150 -0
- package/package.json +9 -2
- 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 +786 -0
- package/src/ceremonies/index.ts +9 -43
- package/src/cli/create.ts +60 -97
- package/src/cli/templates/provider/AGENTS.md.tpl +87 -0
- package/src/cli/templates/provider/CLAUDE.md.tpl +1 -0
- package/src/cli/templates/provider/README.md.tpl +7 -4
- package/src/cli/templates/provider/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/src/cli/templates/provider/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/src/cli/templates/provider/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/src/cli/templates/provider/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/src/cli/templates/provider/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/src/cli/templates/provider/skills/upstream-notes/README.md.tpl +13 -0
- package/src/contract.ts +1 -0
- package/src/define.ts +198 -71
- package/src/index.ts +16 -0
- package/src/lint.ts +33 -0
- package/src/provider.ts +27 -0
- package/src/runtime/auth-flow.ts +2 -0
- package/src/runtime/browser.ts +293 -1
- package/src/runtime/http.ts +48 -7
- package/src/runtime/stealth.ts +182 -5
- package/src/server/index.ts +36 -0
- 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 +725 -0
- package/src/server/serve.ts +67 -4
- package/src/testing/run.ts +9 -1
- package/src/types.ts +186 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "redirect",
|
|
3
|
+
"turnId": "fixture.redirect",
|
|
4
|
+
"hint": "Open the provider authorization page to continue.",
|
|
5
|
+
"data": {
|
|
6
|
+
"url": "https://auth.example.com/authorize?state=fixture-state"
|
|
7
|
+
},
|
|
8
|
+
"expectedInput": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"required": ["code", "state"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"code": { "type": "string" },
|
|
13
|
+
"state": { "type": "string" }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { AuthTurn } from "../types";
|
|
2
|
+
|
|
3
|
+
export type { AuthTurn };
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Major version of the AuthTurn envelope contract.
|
|
7
|
+
*
|
|
8
|
+
* The envelope is additive-only within a major. Adding a turn kind is never an
|
|
9
|
+
* envelope version event (the wire keeps `kind` open); a major bump happens
|
|
10
|
+
* only on an envelope-shape break, which is expected to be a ~never,
|
|
11
|
+
* gateway-first coordinated event.
|
|
12
|
+
*/
|
|
13
|
+
export const AUTH_TURN_ENVELOPE_MAJOR = 1;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Package-root-relative path of the static schema artifact shipped in the npm
|
|
17
|
+
* tarball. Tooling that needs the raw JSON document (for example codegen)
|
|
18
|
+
* should read this file off the resolved on-disk package directory.
|
|
19
|
+
*/
|
|
20
|
+
export const AUTH_TURN_SCHEMA_ARTIFACT_PATH = "dist/auth-turn/auth-turn.v1.schema.json";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* JSON Schema (draft 2020-12) for the AuthTurn envelope, version 1.
|
|
24
|
+
*
|
|
25
|
+
* This is the exact codification of the runtime validation the SDK applies to
|
|
26
|
+
* ceremony outputs (see `validateCeremonyOutput` in `src/ceremonies`), which
|
|
27
|
+
* compiles this same document. `kind` is an OPEN string on the wire: the known
|
|
28
|
+
* kinds in {@link TURN_KINDS} are tooling metadata, never a wire constraint.
|
|
29
|
+
*
|
|
30
|
+
* The committed artifact at `src/auth-turn/auth-turn.v1.schema.json` (shipped
|
|
31
|
+
* to `dist/auth-turn/auth-turn.v1.schema.json`) must stay byte-equivalent to
|
|
32
|
+
* this constant; a contract test enforces the equality.
|
|
33
|
+
*/
|
|
34
|
+
export const AUTH_TURN_SCHEMA = {
|
|
35
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
36
|
+
$id: "https://apifuse.com/contracts/auth-turn/v1",
|
|
37
|
+
title: "APIFuse AuthTurn envelope v1",
|
|
38
|
+
description:
|
|
39
|
+
"Protocol message exchanged during auth.flow ceremonies. kind is an open string; known kinds are tooling metadata, not a wire constraint.",
|
|
40
|
+
type: "object",
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
required: ["kind", "turnId"],
|
|
43
|
+
properties: {
|
|
44
|
+
kind: {
|
|
45
|
+
type: "string",
|
|
46
|
+
minLength: 1,
|
|
47
|
+
description:
|
|
48
|
+
"Open turn kind. Known kinds are listed in the TURN_KINDS registry; unknown kinds remain valid on the wire.",
|
|
49
|
+
},
|
|
50
|
+
turnId: {
|
|
51
|
+
type: "string",
|
|
52
|
+
minLength: 1,
|
|
53
|
+
description: "Provider-scoped identifier of this turn.",
|
|
54
|
+
},
|
|
55
|
+
expiresAt: {
|
|
56
|
+
type: "string",
|
|
57
|
+
minLength: 1,
|
|
58
|
+
description: "Turn expiry timestamp as an ISO 8601 / RFC 3339 string.",
|
|
59
|
+
},
|
|
60
|
+
data: {
|
|
61
|
+
type: "object",
|
|
62
|
+
additionalProperties: true,
|
|
63
|
+
description: "Kind-specific payload. Terminal kinds carry the payloads described in $defs.",
|
|
64
|
+
},
|
|
65
|
+
expectedInput: {
|
|
66
|
+
type: "object",
|
|
67
|
+
additionalProperties: true,
|
|
68
|
+
description: "JSON Schema describing the input expected next.",
|
|
69
|
+
},
|
|
70
|
+
hint: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description:
|
|
73
|
+
"Deprecated but load-bearing human-readable hint materialized from provider locale catalogs.",
|
|
74
|
+
},
|
|
75
|
+
hintKey: {
|
|
76
|
+
type: "string",
|
|
77
|
+
description: "Provider locale catalog key for the turn hint.",
|
|
78
|
+
},
|
|
79
|
+
timing: {
|
|
80
|
+
type: "object",
|
|
81
|
+
additionalProperties: false,
|
|
82
|
+
description: "Client pacing guidance for poll-style turns.",
|
|
83
|
+
properties: {
|
|
84
|
+
suggestedPollIntervalMs: { type: "number", minimum: 1 },
|
|
85
|
+
maxWaitMs: { type: "number", minimum: 1 },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
$defs: {
|
|
90
|
+
completeTurnData: {
|
|
91
|
+
title: 'Terminal payload for kind "complete"',
|
|
92
|
+
description:
|
|
93
|
+
"data payload of a complete turn. The gateway extracts data.credential for persistence; complete turns are never echoed to browsers.",
|
|
94
|
+
type: "object",
|
|
95
|
+
additionalProperties: true,
|
|
96
|
+
required: ["credential"],
|
|
97
|
+
properties: {
|
|
98
|
+
credential: { type: "object", additionalProperties: true },
|
|
99
|
+
metadata: { type: "object", additionalProperties: true },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
abortTurnData: {
|
|
103
|
+
title: 'Terminal payload for kind "abort"',
|
|
104
|
+
description:
|
|
105
|
+
"data payload of an abort turn. code, when present, is the machine-readable abort reason.",
|
|
106
|
+
type: "object",
|
|
107
|
+
additionalProperties: true,
|
|
108
|
+
properties: {
|
|
109
|
+
code: { type: "string" },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
} as const;
|
|
114
|
+
|
|
115
|
+
export type TurnKindRendering = "custom" | "schema" | "terminal";
|
|
116
|
+
|
|
117
|
+
export interface AuthTurnKindDescriptor {
|
|
118
|
+
/** Turn kind string as emitted on the wire. */
|
|
119
|
+
readonly kind: string;
|
|
120
|
+
/**
|
|
121
|
+
* How clients present the turn: "custom" (dedicated renderer), "schema"
|
|
122
|
+
* (generic expectedInput-driven rendering), or "terminal" (never rendered;
|
|
123
|
+
* consumed by the gateway).
|
|
124
|
+
*/
|
|
125
|
+
readonly rendering: TurnKindRendering;
|
|
126
|
+
/** JSON pointer into AUTH_TURN_SCHEMA for the kind's data payload contract. */
|
|
127
|
+
readonly payloadSchema?: string;
|
|
128
|
+
/** Envelope major in which the kind was first registered. */
|
|
129
|
+
readonly since: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Registry of the turn kinds the SDK is known to emit today.
|
|
134
|
+
*
|
|
135
|
+
* This is tooling metadata (renderer routing, fixtures, codegen) — it is NOT a
|
|
136
|
+
* wire constraint. Providers may emit kinds outside this list and they remain
|
|
137
|
+
* valid against {@link AUTH_TURN_SCHEMA}. Every kind registered here must ship
|
|
138
|
+
* a golden fixture at `src/auth-turn/fixtures/valid/<kind>.json`; a contract
|
|
139
|
+
* test enforces the coverage.
|
|
140
|
+
*/
|
|
141
|
+
export const TURN_KINDS = [
|
|
142
|
+
{
|
|
143
|
+
kind: "abort",
|
|
144
|
+
rendering: "terminal",
|
|
145
|
+
payloadSchema: "#/$defs/abortTurnData",
|
|
146
|
+
since: 1,
|
|
147
|
+
},
|
|
148
|
+
{ kind: "challenge", rendering: "custom", since: 1 },
|
|
149
|
+
{
|
|
150
|
+
kind: "complete",
|
|
151
|
+
rendering: "terminal",
|
|
152
|
+
payloadSchema: "#/$defs/completeTurnData",
|
|
153
|
+
since: 1,
|
|
154
|
+
},
|
|
155
|
+
{ kind: "form", rendering: "custom", since: 1 },
|
|
156
|
+
{ kind: "message", rendering: "custom", since: 1 },
|
|
157
|
+
{ kind: "multi_choice", rendering: "custom", since: 1 },
|
|
158
|
+
{ kind: "pending", rendering: "schema", since: 1 },
|
|
159
|
+
{ kind: "poll", rendering: "custom", since: 1 },
|
|
160
|
+
{ kind: "redirect", rendering: "custom", since: 1 },
|
|
161
|
+
{ kind: "retry", rendering: "custom", since: 1 },
|
|
162
|
+
] as const satisfies readonly AuthTurnKindDescriptor[];
|
|
163
|
+
|
|
164
|
+
/** Turn kinds the SDK is known to emit. Tooling metadata, not a wire constraint. */
|
|
165
|
+
export type KnownAuthTurnKind = (typeof TURN_KINDS)[number]["kind"];
|
|
166
|
+
|
|
167
|
+
/** Known kinds presented through a dedicated client renderer. */
|
|
168
|
+
export type CustomRenderedTurnKind = Extract<
|
|
169
|
+
(typeof TURN_KINDS)[number],
|
|
170
|
+
{ rendering: "custom" }
|
|
171
|
+
>["kind"];
|
|
172
|
+
|
|
173
|
+
/** Known kinds consumed by the gateway instead of being rendered. */
|
|
174
|
+
export type TerminalTurnKind = Extract<
|
|
175
|
+
(typeof TURN_KINDS)[number],
|
|
176
|
+
{ rendering: "terminal" }
|
|
177
|
+
>["kind"];
|