@apifuse/provider-sdk 2.1.0-beta.9 → 2.2.0-beta.2

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