@opendatalabs/personal-server-ts-core 1.33.8 → 1.34.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.
Files changed (333) hide show
  1. package/dist/additions/budget.d.ts +28 -0
  2. package/dist/additions/budget.d.ts.map +1 -0
  3. package/dist/additions/budget.js +119 -0
  4. package/dist/additions/budget.js.map +1 -0
  5. package/dist/additions/durable.d.ts +64 -0
  6. package/dist/additions/durable.d.ts.map +1 -0
  7. package/dist/additions/durable.js +591 -0
  8. package/dist/additions/durable.js.map +1 -0
  9. package/dist/additions/first-added.d.ts +32 -48
  10. package/dist/additions/first-added.d.ts.map +1 -1
  11. package/dist/additions/first-added.js +68 -123
  12. package/dist/additions/first-added.js.map +1 -1
  13. package/dist/additions/index.d.ts +3 -0
  14. package/dist/additions/index.d.ts.map +1 -1
  15. package/dist/additions/index.js +3 -0
  16. package/dist/additions/index.js.map +1 -1
  17. package/dist/additions/ledger-store.js +1 -1
  18. package/dist/additions/record-rules.d.ts.map +1 -1
  19. package/dist/additions/record-rules.js +7 -0
  20. package/dist/additions/record-rules.js.map +1 -1
  21. package/dist/additions/summary.d.ts +88 -1
  22. package/dist/additions/summary.d.ts.map +1 -1
  23. package/dist/additions/summary.js +173 -8
  24. package/dist/additions/summary.js.map +1 -1
  25. package/dist/additions/version-inventory.d.ts +80 -0
  26. package/dist/additions/version-inventory.d.ts.map +1 -0
  27. package/dist/additions/version-inventory.js +232 -0
  28. package/dist/additions/version-inventory.js.map +1 -0
  29. package/dist/api/index.d.ts +70 -2
  30. package/dist/api/index.d.ts.map +1 -1
  31. package/dist/api/index.js +506 -79
  32. package/dist/api/index.js.map +1 -1
  33. package/dist/auth/index.d.ts +1 -1
  34. package/dist/auth/index.d.ts.map +1 -1
  35. package/dist/auth/index.js +1 -1
  36. package/dist/auth/index.js.map +1 -1
  37. package/dist/auth/request.d.ts +6 -0
  38. package/dist/auth/request.d.ts.map +1 -1
  39. package/dist/auth/request.js +66 -4
  40. package/dist/auth/request.js.map +1 -1
  41. package/dist/contracts/data.d.ts +54 -8
  42. package/dist/contracts/data.d.ts.map +1 -1
  43. package/dist/contracts/data.js +178 -35
  44. package/dist/contracts/data.js.map +1 -1
  45. package/dist/contracts/index.d.ts +1 -1
  46. package/dist/contracts/index.d.ts.map +1 -1
  47. package/dist/derivatives/registration.d.ts +0 -5
  48. package/dist/derivatives/registration.d.ts.map +1 -1
  49. package/dist/derivatives/registration.js +2 -1
  50. package/dist/derivatives/registration.js.map +1 -1
  51. package/dist/errors/pdpp-catalog.d.ts +36 -0
  52. package/dist/errors/pdpp-catalog.d.ts.map +1 -0
  53. package/dist/errors/pdpp-catalog.js +86 -0
  54. package/dist/errors/pdpp-catalog.js.map +1 -0
  55. package/dist/grants/index.d.ts +2 -0
  56. package/dist/grants/index.d.ts.map +1 -1
  57. package/dist/grants/index.js +4 -0
  58. package/dist/grants/index.js.map +1 -1
  59. package/dist/grants/pdpp-binding-store.d.ts +89 -0
  60. package/dist/grants/pdpp-binding-store.d.ts.map +1 -0
  61. package/dist/grants/pdpp-binding-store.js +112 -0
  62. package/dist/grants/pdpp-binding-store.js.map +1 -0
  63. package/dist/grants/pdpp-binding.d.ts +169 -0
  64. package/dist/grants/pdpp-binding.d.ts.map +1 -0
  65. package/dist/grants/pdpp-binding.js +236 -0
  66. package/dist/grants/pdpp-binding.js.map +1 -0
  67. package/dist/legacy-projection/bindings.d.ts +28 -1
  68. package/dist/legacy-projection/bindings.d.ts.map +1 -1
  69. package/dist/legacy-projection/bindings.js +622 -189
  70. package/dist/legacy-projection/bindings.js.map +1 -1
  71. package/dist/legacy-projection/claude-source-record.d.ts +22 -0
  72. package/dist/legacy-projection/claude-source-record.d.ts.map +1 -0
  73. package/dist/legacy-projection/claude-source-record.js +360 -0
  74. package/dist/legacy-projection/claude-source-record.js.map +1 -0
  75. package/dist/legacy-projection/declared-text.d.ts +41 -0
  76. package/dist/legacy-projection/declared-text.d.ts.map +1 -0
  77. package/dist/legacy-projection/declared-text.js +199 -0
  78. package/dist/legacy-projection/declared-text.js.map +1 -0
  79. package/dist/legacy-projection/github-browser-bindings.d.ts.map +1 -1
  80. package/dist/legacy-projection/github-browser-bindings.js +89 -5
  81. package/dist/legacy-projection/github-browser-bindings.js.map +1 -1
  82. package/dist/legacy-projection/github-legacy-fields.d.ts +6 -0
  83. package/dist/legacy-projection/github-legacy-fields.d.ts.map +1 -0
  84. package/dist/legacy-projection/github-legacy-fields.js +202 -0
  85. package/dist/legacy-projection/github-legacy-fields.js.map +1 -0
  86. package/dist/legacy-projection/index.d.ts +5 -1
  87. package/dist/legacy-projection/index.d.ts.map +1 -1
  88. package/dist/legacy-projection/index.js +55 -1
  89. package/dist/legacy-projection/index.js.map +1 -1
  90. package/dist/legacy-projection/oura-browser-bindings.d.ts.map +1 -1
  91. package/dist/legacy-projection/oura-browser-bindings.js +43 -41
  92. package/dist/legacy-projection/oura-browser-bindings.js.map +1 -1
  93. package/dist/legacy-projection/types.d.ts +38 -2
  94. package/dist/legacy-projection/types.d.ts.map +1 -1
  95. package/dist/mcp/read-client.d.ts.map +1 -1
  96. package/dist/mcp/read-client.js +10 -1
  97. package/dist/mcp/read-client.js.map +1 -1
  98. package/dist/mcp/resources.d.ts.map +1 -1
  99. package/dist/mcp/resources.js +3 -0
  100. package/dist/mcp/resources.js.map +1 -1
  101. package/dist/mcp/tools.d.ts.map +1 -1
  102. package/dist/mcp/tools.js +11 -2
  103. package/dist/mcp/tools.js.map +1 -1
  104. package/dist/pdpp/approval.d.ts +271 -0
  105. package/dist/pdpp/approval.d.ts.map +1 -0
  106. package/dist/pdpp/approval.js +467 -0
  107. package/dist/pdpp/approval.js.map +1 -0
  108. package/dist/pdpp/client-identity.d.ts +88 -0
  109. package/dist/pdpp/client-identity.d.ts.map +1 -0
  110. package/dist/pdpp/client-identity.js +196 -0
  111. package/dist/pdpp/client-identity.js.map +1 -0
  112. package/dist/pdpp/client-metadata.d.ts +95 -0
  113. package/dist/pdpp/client-metadata.d.ts.map +1 -0
  114. package/dist/pdpp/client-metadata.js +96 -0
  115. package/dist/pdpp/client-metadata.js.map +1 -0
  116. package/dist/pdpp/commitments.d.ts +75 -0
  117. package/dist/pdpp/commitments.d.ts.map +1 -0
  118. package/dist/pdpp/commitments.js +113 -0
  119. package/dist/pdpp/commitments.js.map +1 -0
  120. package/dist/pdpp/declaration.d.ts +118 -0
  121. package/dist/pdpp/declaration.d.ts.map +1 -0
  122. package/dist/pdpp/declaration.js +836 -0
  123. package/dist/pdpp/declaration.js.map +1 -0
  124. package/dist/pdpp/index.d.ts +37 -0
  125. package/dist/pdpp/index.d.ts.map +1 -0
  126. package/dist/pdpp/index.js +23 -0
  127. package/dist/pdpp/index.js.map +1 -0
  128. package/dist/pdpp/issuance.d.ts +126 -0
  129. package/dist/pdpp/issuance.d.ts.map +1 -0
  130. package/dist/pdpp/issuance.js +180 -0
  131. package/dist/pdpp/issuance.js.map +1 -0
  132. package/dist/pdpp/pkce.d.ts +53 -0
  133. package/dist/pdpp/pkce.d.ts.map +1 -0
  134. package/dist/pdpp/pkce.js +109 -0
  135. package/dist/pdpp/pkce.js.map +1 -0
  136. package/dist/pdpp/redirect.d.ts +60 -0
  137. package/dist/pdpp/redirect.d.ts.map +1 -0
  138. package/dist/pdpp/redirect.js +125 -0
  139. package/dist/pdpp/redirect.js.map +1 -0
  140. package/dist/pdpp/resolve.d.ts +109 -0
  141. package/dist/pdpp/resolve.d.ts.map +1 -0
  142. package/dist/pdpp/resolve.js +393 -0
  143. package/dist/pdpp/resolve.js.map +1 -0
  144. package/dist/pdpp/review.d.ts +280 -0
  145. package/dist/pdpp/review.d.ts.map +1 -0
  146. package/dist/pdpp/review.js +205 -0
  147. package/dist/pdpp/review.js.map +1 -0
  148. package/dist/pdpp/selection.d.ts +50 -0
  149. package/dist/pdpp/selection.d.ts.map +1 -0
  150. package/dist/pdpp/selection.js +442 -0
  151. package/dist/pdpp/selection.js.map +1 -0
  152. package/dist/pdpp/store.d.ts +228 -0
  153. package/dist/pdpp/store.d.ts.map +1 -0
  154. package/dist/pdpp/store.js +542 -0
  155. package/dist/pdpp/store.js.map +1 -0
  156. package/dist/pdpp/tokens.d.ts +181 -0
  157. package/dist/pdpp/tokens.d.ts.map +1 -0
  158. package/dist/pdpp/tokens.js +419 -0
  159. package/dist/pdpp/tokens.js.map +1 -0
  160. package/dist/pdpp/types.d.ts +441 -0
  161. package/dist/pdpp/types.d.ts.map +1 -0
  162. package/dist/pdpp/types.js +61 -0
  163. package/dist/pdpp/types.js.map +1 -0
  164. package/dist/pdpp-version.d.ts +28 -0
  165. package/dist/pdpp-version.d.ts.map +1 -0
  166. package/dist/pdpp-version.js +28 -0
  167. package/dist/pdpp-version.js.map +1 -0
  168. package/dist/policy/data-read.d.ts +24 -0
  169. package/dist/policy/data-read.d.ts.map +1 -1
  170. package/dist/policy/data-read.js +60 -3
  171. package/dist/policy/data-read.js.map +1 -1
  172. package/dist/policy/data-write.d.ts.map +1 -1
  173. package/dist/policy/data-write.js +3 -0
  174. package/dist/policy/data-write.js.map +1 -1
  175. package/dist/policy/index.d.ts +1 -0
  176. package/dist/policy/index.d.ts.map +1 -1
  177. package/dist/policy/index.js +1 -0
  178. package/dist/policy/index.js.map +1 -1
  179. package/dist/policy/reserved-scopes.d.ts +3 -0
  180. package/dist/policy/reserved-scopes.d.ts.map +1 -0
  181. package/dist/policy/reserved-scopes.js +5 -0
  182. package/dist/policy/reserved-scopes.js.map +1 -0
  183. package/dist/ports/index.d.ts +63 -0
  184. package/dist/ports/index.d.ts.map +1 -1
  185. package/dist/ports/index.js.map +1 -1
  186. package/dist/ports/pdpp-auth.d.ts +129 -0
  187. package/dist/ports/pdpp-auth.d.ts.map +1 -0
  188. package/dist/ports/pdpp-auth.js +60 -0
  189. package/dist/ports/pdpp-auth.js.map +1 -0
  190. package/dist/ports/pdpp-auth.test-utils.d.ts +9 -0
  191. package/dist/ports/pdpp-auth.test-utils.d.ts.map +1 -0
  192. package/dist/ports/pdpp-auth.test-utils.js +18 -0
  193. package/dist/ports/pdpp-auth.test-utils.js.map +1 -0
  194. package/dist/schemas/server-config.d.ts +44 -0
  195. package/dist/schemas/server-config.d.ts.map +1 -1
  196. package/dist/schemas/server-config.js +91 -0
  197. package/dist/schemas/server-config.js.map +1 -1
  198. package/dist/signing/request-signer.d.ts +2 -0
  199. package/dist/signing/request-signer.d.ts.map +1 -1
  200. package/dist/signing/request-signer.js +1 -0
  201. package/dist/signing/request-signer.js.map +1 -1
  202. package/dist/storage/adapters/interface.d.ts +3 -0
  203. package/dist/storage/adapters/interface.d.ts.map +1 -1
  204. package/dist/storage/adapters/vana-audience.d.ts +12 -0
  205. package/dist/storage/adapters/vana-audience.d.ts.map +1 -0
  206. package/dist/storage/adapters/vana-audience.js +72 -0
  207. package/dist/storage/adapters/vana-audience.js.map +1 -0
  208. package/dist/storage/adapters/vana.d.ts +2 -0
  209. package/dist/storage/adapters/vana.d.ts.map +1 -1
  210. package/dist/storage/adapters/vana.js +53 -20
  211. package/dist/storage/adapters/vana.js.map +1 -1
  212. package/dist/storage/canonical-legacy-projection.d.ts +262 -0
  213. package/dist/storage/canonical-legacy-projection.d.ts.map +1 -0
  214. package/dist/storage/canonical-legacy-projection.js +761 -0
  215. package/dist/storage/canonical-legacy-projection.js.map +1 -0
  216. package/dist/storage/index/manager.d.ts +29 -2
  217. package/dist/storage/index/manager.d.ts.map +1 -1
  218. package/dist/storage/index/schema.d.ts +1 -1
  219. package/dist/storage/index/schema.js +1 -1
  220. package/dist/storage/index/types.d.ts +7 -1
  221. package/dist/storage/index/types.d.ts.map +1 -1
  222. package/dist/storage/legacy-projection.d.ts +13 -10
  223. package/dist/storage/legacy-projection.d.ts.map +1 -1
  224. package/dist/storage/legacy-projection.js +269 -74
  225. package/dist/storage/legacy-projection.js.map +1 -1
  226. package/dist/storage/legacy-scope-coverage-exceptions.d.ts +8 -0
  227. package/dist/storage/legacy-scope-coverage-exceptions.d.ts.map +1 -0
  228. package/dist/storage/legacy-scope-coverage-exceptions.js +10 -0
  229. package/dist/storage/legacy-scope-coverage-exceptions.js.map +1 -0
  230. package/dist/storage/legacy-scope-coverage.d.ts +53 -0
  231. package/dist/storage/legacy-scope-coverage.d.ts.map +1 -0
  232. package/dist/storage/legacy-scope-coverage.js +403 -0
  233. package/dist/storage/legacy-scope-coverage.js.map +1 -0
  234. package/dist/storage/legacy-scope-entity-keys.d.ts +4 -0
  235. package/dist/storage/legacy-scope-entity-keys.d.ts.map +1 -0
  236. package/dist/storage/legacy-scope-entity-keys.js +92 -0
  237. package/dist/storage/legacy-scope-entity-keys.js.map +1 -0
  238. package/dist/storage/legacy-scope-view.d.ts +154 -0
  239. package/dist/storage/legacy-scope-view.d.ts.map +1 -0
  240. package/dist/storage/legacy-scope-view.js +735 -0
  241. package/dist/storage/legacy-scope-view.js.map +1 -0
  242. package/dist/storage/pdpp-records/completion.d.ts +91 -0
  243. package/dist/storage/pdpp-records/completion.d.ts.map +1 -0
  244. package/dist/storage/pdpp-records/completion.js +170 -0
  245. package/dist/storage/pdpp-records/completion.js.map +1 -0
  246. package/dist/storage/pdpp-records/cursor.d.ts +41 -0
  247. package/dist/storage/pdpp-records/cursor.d.ts.map +1 -0
  248. package/dist/storage/pdpp-records/cursor.js +49 -0
  249. package/dist/storage/pdpp-records/cursor.js.map +1 -0
  250. package/dist/storage/pdpp-records/declaration-witness.d.ts +58 -0
  251. package/dist/storage/pdpp-records/declaration-witness.d.ts.map +1 -0
  252. package/dist/storage/pdpp-records/declaration-witness.js +230 -0
  253. package/dist/storage/pdpp-records/declaration-witness.js.map +1 -0
  254. package/dist/storage/pdpp-records/enforcement.d.ts +52 -0
  255. package/dist/storage/pdpp-records/enforcement.d.ts.map +1 -0
  256. package/dist/storage/pdpp-records/enforcement.js +116 -0
  257. package/dist/storage/pdpp-records/enforcement.js.map +1 -0
  258. package/dist/storage/pdpp-records/index.d.ts +5 -0
  259. package/dist/storage/pdpp-records/index.d.ts.map +1 -0
  260. package/dist/storage/pdpp-records/index.js +5 -0
  261. package/dist/storage/pdpp-records/index.js.map +1 -0
  262. package/dist/storage/pdpp-records/ingest-plan.d.ts +39 -0
  263. package/dist/storage/pdpp-records/ingest-plan.d.ts.map +1 -0
  264. package/dist/storage/pdpp-records/ingest-plan.js +103 -0
  265. package/dist/storage/pdpp-records/ingest-plan.js.map +1 -0
  266. package/dist/storage/pdpp-records/interface.d.ts +104 -0
  267. package/dist/storage/pdpp-records/interface.d.ts.map +1 -0
  268. package/dist/storage/pdpp-records/interface.js +2 -0
  269. package/dist/storage/pdpp-records/interface.js.map +1 -0
  270. package/dist/storage/pdpp-records/memory-store.d.ts +9 -0
  271. package/dist/storage/pdpp-records/memory-store.d.ts.map +1 -0
  272. package/dist/storage/pdpp-records/memory-store.js +466 -0
  273. package/dist/storage/pdpp-records/memory-store.js.map +1 -0
  274. package/dist/storage/pdpp-records/portable.d.ts +9 -0
  275. package/dist/storage/pdpp-records/portable.d.ts.map +1 -0
  276. package/dist/storage/pdpp-records/portable.js +8 -0
  277. package/dist/storage/pdpp-records/portable.js.map +1 -0
  278. package/dist/storage/pdpp-records/read-port.d.ts +44 -0
  279. package/dist/storage/pdpp-records/read-port.d.ts.map +1 -0
  280. package/dist/storage/pdpp-records/read-port.js +22 -0
  281. package/dist/storage/pdpp-records/read-port.js.map +1 -0
  282. package/dist/storage/pdpp-records/record-key.d.ts +52 -0
  283. package/dist/storage/pdpp-records/record-key.d.ts.map +1 -0
  284. package/dist/storage/pdpp-records/record-key.js +97 -0
  285. package/dist/storage/pdpp-records/record-key.js.map +1 -0
  286. package/dist/storage/pdpp-records/schema.d.ts +41 -0
  287. package/dist/storage/pdpp-records/schema.d.ts.map +1 -0
  288. package/dist/storage/pdpp-records/schema.js +153 -0
  289. package/dist/storage/pdpp-records/schema.js.map +1 -0
  290. package/dist/storage/pdpp-records/stream-declaration.d.ts +88 -0
  291. package/dist/storage/pdpp-records/stream-declaration.d.ts.map +1 -0
  292. package/dist/storage/pdpp-records/stream-declaration.js +57 -0
  293. package/dist/storage/pdpp-records/stream-declaration.js.map +1 -0
  294. package/dist/storage/pdpp-records/types.d.ts +138 -0
  295. package/dist/storage/pdpp-records/types.d.ts.map +1 -0
  296. package/dist/storage/pdpp-records/types.js +38 -0
  297. package/dist/storage/pdpp-records/types.js.map +1 -0
  298. package/dist/sync/data-point-feed.d.ts +3 -0
  299. package/dist/sync/data-point-feed.d.ts.map +1 -1
  300. package/dist/sync/data-point-feed.js +17 -1
  301. package/dist/sync/data-point-feed.js.map +1 -1
  302. package/dist/sync/delete-data-port.d.ts +2 -0
  303. package/dist/sync/delete-data-port.d.ts.map +1 -1
  304. package/dist/sync/delete-data-port.js +1 -1
  305. package/dist/sync/delete-data-port.js.map +1 -1
  306. package/dist/sync/engine/sync-manager.d.ts.map +1 -1
  307. package/dist/sync/engine/sync-manager.js +5 -2
  308. package/dist/sync/engine/sync-manager.js.map +1 -1
  309. package/dist/sync/index.d.ts +3 -1
  310. package/dist/sync/index.d.ts.map +1 -1
  311. package/dist/sync/index.js +4 -0
  312. package/dist/sync/index.js.map +1 -1
  313. package/dist/sync/pdpp-import.d.ts +192 -0
  314. package/dist/sync/pdpp-import.d.ts.map +1 -0
  315. package/dist/sync/pdpp-import.js +441 -0
  316. package/dist/sync/pdpp-import.js.map +1 -0
  317. package/dist/sync/scope-deletions.d.ts +10 -0
  318. package/dist/sync/scope-deletions.d.ts.map +1 -1
  319. package/dist/sync/scope-deletions.js +40 -7
  320. package/dist/sync/scope-deletions.js.map +1 -1
  321. package/dist/sync/workers/download.d.ts +14 -0
  322. package/dist/sync/workers/download.d.ts.map +1 -1
  323. package/dist/sync/workers/download.js +149 -13
  324. package/dist/sync/workers/download.js.map +1 -1
  325. package/dist/sync/workers/upload.d.ts +2 -0
  326. package/dist/sync/workers/upload.d.ts.map +1 -1
  327. package/dist/sync/workers/upload.js +7 -0
  328. package/dist/sync/workers/upload.js.map +1 -1
  329. package/dist/test-utils/memory-storage.d.ts +1 -1
  330. package/dist/test-utils/memory-storage.d.ts.map +1 -1
  331. package/dist/test-utils/memory-storage.js +11 -5
  332. package/dist/test-utils/memory-storage.js.map +1 -1
  333. package/package.json +54 -4
@@ -0,0 +1,181 @@
1
+ /**
2
+ * PDPP grant-bound token issuance, introspection, and revocation (§8, §9 AS
3
+ * items 8–10, 18–20; delivery scope §2).
4
+ *
5
+ * This module is the single token-validation authority. The RS resolves every
6
+ * request through `resolveToken` and enforces only from the result — §8 is
7
+ * explicit that the separated RS must not make a second AS lookup while
8
+ * handling a request, and that a co-located RS may use a local equivalent.
9
+ * `resolveToken` is that local equivalent, and `introspect` is the same
10
+ * decision rendered onto the RFC 7662 wire shape. They share one code path so
11
+ * the two deployments cannot drift apart.
12
+ *
13
+ * Revocation is immediate here by construction: resolution reads current store
14
+ * state on every call rather than trusting a cached decision, so a revoked
15
+ * grant reports `active: false` on the very next call. The 60-second bound in
16
+ * §8 is the RS's positive-result cache, not slack in the AS.
17
+ */
18
+ import { type PdppAuthStore } from "./store.js";
19
+ import { type AccessMode, type Grant, type PdppAuthorizationDetail, type PdppAuthorizationEntry, type PdppIntrospectionResponse, type PdppTokenContext } from "./types.js";
20
+ /** Default client access-token lifetime. Short: the refresh path renews it. */
21
+ export declare const DEFAULT_ACCESS_TOKEN_TTL_SECONDS: number;
22
+ /** How long an authorization code stays redeemable. RFC 6749 §4.1.2 suggests <=10 min. */
23
+ export declare const AUTHORIZATION_CODE_TTL_SECONDS = 60;
24
+ export interface TokenIssuanceResult {
25
+ access_token: string;
26
+ token_type: "Bearer";
27
+ expires_in: number;
28
+ /** Present only for continuous grants (§9 AS item 20). */
29
+ refresh_token?: string;
30
+ /** Echoed so a client can bind its own state to the grant. */
31
+ grant_id: string;
32
+ /**
33
+ * The approved RFC 9396 detail, as granted. RFC 9396 §7 requires the token
34
+ * response to return `authorization_details` as granted by the resource
35
+ * owner and assigned to the access token — the same projection introspection
36
+ * carries.
37
+ *
38
+ * One element per covered grant, each in its own revision's shape: a v0.1
39
+ * grant yields the v0.1 projection, a v0.2 grant yields `{ type, grant }`
40
+ * with the complete grant. v0.2 forbids a lossy summary, and the v0.1
41
+ * projection is one, so the two cannot share a shape.
42
+ */
43
+ authorization_details: PdppAuthorizationEntry[];
44
+ }
45
+ export type TokenFailureCode = "invalid_grant" | "invalid_request";
46
+ export interface TokenFailure {
47
+ code: TokenFailureCode;
48
+ message: string;
49
+ }
50
+ export type TokenResult = {
51
+ ok: true;
52
+ issued: TokenIssuanceResult;
53
+ } | {
54
+ ok: false;
55
+ failure: TokenFailure;
56
+ };
57
+ /**
58
+ * Whether a grant may carry a refresh token.
59
+ *
60
+ * §9 AS item 20: refresh tokens are issued only for `continuous` grants, or
61
+ * for a grant package only when *every* child grant is continuous. A
62
+ * single-use grant with a refresh token would be a contradiction — the grant
63
+ * is consumed at first issuance, so there is nothing left to refresh into.
64
+ */
65
+ export declare function mayIssueRefreshToken(accessModes: AccessMode[]): boolean;
66
+ export interface PdppTokenServiceOptions {
67
+ accessTokenTtlSeconds?: number;
68
+ }
69
+ export declare class PdppTokenService {
70
+ private readonly store;
71
+ private readonly accessTtl;
72
+ constructor(store: PdppAuthStore, options?: PdppTokenServiceOptions);
73
+ /**
74
+ * Issue the first client token for a grant, redeeming an authorization code.
75
+ *
76
+ * The code is consumed atomically before anything else happens (§9 AS item
77
+ * 19) and a single-use grant is consumed atomically with the token insert
78
+ * (§9 AS item 10). Both preconditions live in SQL WHERE clauses, so a
79
+ * concurrent duplicate redemption loses the race rather than double-issuing.
80
+ */
81
+ redeemAuthorizationCode(input: {
82
+ code: string;
83
+ clientId: string;
84
+ redirectUri: string;
85
+ /** RFC 7636 verifier. Required when the code was issued with a challenge. */
86
+ codeVerifier?: string;
87
+ now?: Date;
88
+ }): TokenResult;
89
+ /**
90
+ * Rotate a refresh token within its family.
91
+ *
92
+ * Reuse of a superseded token revokes the family and every family-linked
93
+ * access token inside `rotateRefreshToken`, then this returns
94
+ * `invalid_grant`, which is what §9 AS item 20 requires: reject the reuse
95
+ * and require fresh authorization.
96
+ */
97
+ refresh(input: {
98
+ refreshToken: string;
99
+ now?: Date;
100
+ }): TokenResult;
101
+ /**
102
+ * Mint an access token (and, for continuous grants, a refresh token) bound
103
+ * to a grant.
104
+ *
105
+ * `existingFamilyId` carries a rotation into the same family so reuse
106
+ * detection keeps working across the whole chain; a first issuance creates
107
+ * the family.
108
+ */
109
+ private mintForGrant;
110
+ /**
111
+ * The single shared token-validation path (§8 "Grant enforcement").
112
+ *
113
+ * Reads live store state every call. That is what makes revocation immediate
114
+ * in introspection (§9 AS item 8) — there is no AS-side cache to invalidate.
115
+ */
116
+ resolveToken(accessToken: string, now?: Date): PdppTokenContext;
117
+ /**
118
+ * RFC 7662 introspection.
119
+ *
120
+ * An inactive token yields exactly `{ active: false }`. RFC 7662 §2.2 is
121
+ * clear that the response must not distinguish revoked from expired from
122
+ * never-issued — the reason stays internal (`resolveToken`) for the
123
+ * co-located RS, which needs it to pick 403 `grant_revoked`.
124
+ */
125
+ introspect(accessToken: string, now?: Date): PdppIntrospectionResponse;
126
+ /** Revoke a grant and every linked token family. Immediate (§2, §9 item 8). */
127
+ revokeGrant(grantId: string, now?: Date): boolean;
128
+ /**
129
+ * Issue an owner token for a subject.
130
+ *
131
+ * An owner token carries no grant (§8 "Authentication"): it scopes to a
132
+ * single subject's data store, and the RS derives subject scope from it
133
+ * rather than synthesizing a grant. It is also what authenticates a consent
134
+ * decision — see `approval.ts` for why the AS requires this rather than
135
+ * trusting the consent UI's affiliation.
136
+ *
137
+ * How the owner *obtains* this token is out of scope for Core; this build
138
+ * mints it from the already-authenticated owner session paths.
139
+ */
140
+ issueOwnerToken(input: {
141
+ subjectId: string;
142
+ sourceId?: string;
143
+ instanceIds?: string[];
144
+ ttlSeconds?: number;
145
+ now?: Date;
146
+ }): {
147
+ access_token: string;
148
+ token_type: "Bearer";
149
+ expires_in: number;
150
+ };
151
+ /** Revoke a single access token without touching its grant. */
152
+ revokeAccessToken(token: string, now?: Date): boolean;
153
+ }
154
+ /**
155
+ * Project a grant onto the RFC 9396 detail the introspection response carries.
156
+ *
157
+ * Note what is absent: `client_claims` and `retention` are not enforcement
158
+ * fields. §6 keeps claims outside introspection rights and RS enforcement
159
+ * entirely; retention is a policy commitment PDPP does not technically
160
+ * enforce, so including it would invite an RS to act on it.
161
+ */
162
+ /**
163
+ * Project a grant onto the `authorization_details` element for *its own*
164
+ * revision.
165
+ *
166
+ * v0.1 gets the narrow enforcement projection below, unchanged. v0.2 gets
167
+ * `{ type, grant }` carrying the complete immutable grant, because v0.2 makes
168
+ * the result the client's source of truth and forbids substituting the
169
+ * original selection request or a lossy summary — and the v0.1 projection is
170
+ * precisely a lossy summary. It drops `retention`, `expires_at`, the resolved
171
+ * client identity, and the requested-vs-approved record, so a v0.2 client
172
+ * receiving it could not tell a narrowed grant from an unnarrowed one.
173
+ *
174
+ * Branching on the grant rather than on a caller-supplied flag is what keeps
175
+ * the two revisions from drifting: the same function serves the token response
176
+ * and introspection, so a client and an authenticated RS cannot be handed
177
+ * different facts about one grant.
178
+ */
179
+ export declare function toAuthorizationEntry(grant: Grant): PdppAuthorizationEntry;
180
+ export declare function toAuthorizationDetail(grant: Grant): PdppAuthorizationDetail;
181
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/pdpp/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,KAAK,EAEV,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAEpB,+EAA+E;AAC/E,eAAO,MAAM,gCAAgC,QAAU,CAAC;AAExD,0FAA0F;AAC1F,eAAO,MAAM,8BAA8B,KAAK,CA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AAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,WAAW;IAuCjE;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAwEpB;;;;;OAKG;IACH,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,gBAAgB;IA8E3E;;;;;;;OAOG;IACH,UAAU,CACR,WAAW,EAAE,MAAM,EACnB,GAAG,GAAE,IAAiB,GACrB,yBAAyB;IA8B5B,+EAA+E;IAC/E,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO;IAI7D;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,KAAK,EAAE;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,GAAG,CAAC,EAAE,IAAI,CAAC;KACZ,GAAG;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,QAAQ,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAsBtE,+DAA+D;IAC/D,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO;CAGlE;AAED;;;;;;;GAOG;AACH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,sBAAsB,CAKzE;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,uBAAuB,CAW3E"}
@@ -0,0 +1,419 @@
1
+ /**
2
+ * PDPP grant-bound token issuance, introspection, and revocation (§8, §9 AS
3
+ * items 8–10, 18–20; delivery scope §2).
4
+ *
5
+ * This module is the single token-validation authority. The RS resolves every
6
+ * request through `resolveToken` and enforces only from the result — §8 is
7
+ * explicit that the separated RS must not make a second AS lookup while
8
+ * handling a request, and that a co-located RS may use a local equivalent.
9
+ * `resolveToken` is that local equivalent, and `introspect` is the same
10
+ * decision rendered onto the RFC 7662 wire shape. They share one code path so
11
+ * the two deployments cannot drift apart.
12
+ *
13
+ * Revocation is immediate here by construction: resolution reads current store
14
+ * state on every call rather than trusting a cached decision, so a revoked
15
+ * grant reports `active: false` on the very next call. The 60-second bound in
16
+ * §8 is the RS's positive-result cache, not slack in the AS.
17
+ */
18
+ import { verifyCodeVerifier } from "./pkce.js";
19
+ import { newOpaqueToken, } from "./store.js";
20
+ import { isV02Grant, PDPP_DATA_ACCESS_TYPE, PDPP_DATA_ACCESS_TYPE_V02, } from "./types.js";
21
+ /** Default client access-token lifetime. Short: the refresh path renews it. */
22
+ export const DEFAULT_ACCESS_TOKEN_TTL_SECONDS = 60 * 60;
23
+ /** How long an authorization code stays redeemable. RFC 6749 §4.1.2 suggests <=10 min. */
24
+ export const AUTHORIZATION_CODE_TTL_SECONDS = 60;
25
+ /**
26
+ * Whether a grant may carry a refresh token.
27
+ *
28
+ * §9 AS item 20: refresh tokens are issued only for `continuous` grants, or
29
+ * for a grant package only when *every* child grant is continuous. A
30
+ * single-use grant with a refresh token would be a contradiction — the grant
31
+ * is consumed at first issuance, so there is nothing left to refresh into.
32
+ */
33
+ export function mayIssueRefreshToken(accessModes) {
34
+ return accessModes.length > 0 && accessModes.every((m) => m === "continuous");
35
+ }
36
+ function grantInactiveReason(store, stored, now) {
37
+ const status = store.grantStatus(stored, now);
38
+ if (status === "revoked")
39
+ return "grant_revoked";
40
+ if (status === "expired")
41
+ return "grant_expired";
42
+ return null;
43
+ }
44
+ export class PdppTokenService {
45
+ store;
46
+ accessTtl;
47
+ constructor(store, options = {}) {
48
+ this.store = store;
49
+ this.accessTtl =
50
+ options.accessTokenTtlSeconds ?? DEFAULT_ACCESS_TOKEN_TTL_SECONDS;
51
+ }
52
+ /**
53
+ * Issue the first client token for a grant, redeeming an authorization code.
54
+ *
55
+ * The code is consumed atomically before anything else happens (§9 AS item
56
+ * 19) and a single-use grant is consumed atomically with the token insert
57
+ * (§9 AS item 10). Both preconditions live in SQL WHERE clauses, so a
58
+ * concurrent duplicate redemption loses the race rather than double-issuing.
59
+ */
60
+ redeemAuthorizationCode(input) {
61
+ const now = input.now ?? new Date();
62
+ const record = this.store.consumeAuthCode(input.code, now);
63
+ if (!record) {
64
+ // Unknown, expired, or already redeemed — deliberately one answer, so a
65
+ // replay cannot be distinguished from a bad code.
66
+ return {
67
+ ok: false,
68
+ failure: {
69
+ code: "invalid_grant",
70
+ message: "authorization code is invalid, expired, or already redeemed",
71
+ },
72
+ };
73
+ }
74
+ // RFC 6749 §4.1.3: the client and redirect_uri must match the ones the
75
+ // code was issued to. The code is already burned at this point, which is
76
+ // correct — a mismatched redemption attempt must not leave it redeemable.
77
+ if (record.clientId !== input.clientId) {
78
+ return {
79
+ ok: false,
80
+ failure: {
81
+ code: "invalid_grant",
82
+ message: "authorization code was not issued to this client",
83
+ },
84
+ };
85
+ }
86
+ if (record.redirectUri !== input.redirectUri) {
87
+ return {
88
+ ok: false,
89
+ failure: {
90
+ code: "invalid_grant",
91
+ message: "redirect_uri does not match the authorization request",
92
+ },
93
+ };
94
+ }
95
+ // RFC 7636 §4.6. Checked after the code is burned, like the client and
96
+ // redirect checks above: an attacker who intercepted the code must not be
97
+ // able to probe verifiers against a code that stays alive between guesses.
98
+ // One wrong verifier costs them the code.
99
+ const pkceFailure = verifyCodeVerifier(input.codeVerifier, record.codeChallenge, record.codeChallengeMethod);
100
+ if (pkceFailure) {
101
+ return {
102
+ ok: false,
103
+ failure: { code: "invalid_grant", message: pkceFailure.message },
104
+ };
105
+ }
106
+ const stored = this.store.getGrant(record.grantId);
107
+ if (!stored) {
108
+ return {
109
+ ok: false,
110
+ failure: { code: "invalid_grant", message: "grant not found" },
111
+ };
112
+ }
113
+ const inactive = grantInactiveReason(this.store, stored, now);
114
+ if (inactive) {
115
+ return {
116
+ ok: false,
117
+ failure: {
118
+ code: "invalid_grant",
119
+ message: `grant is ${inactive === "grant_revoked" ? "revoked" : "expired"}`,
120
+ },
121
+ };
122
+ }
123
+ return this.mintForGrant(stored, now);
124
+ }
125
+ /**
126
+ * Rotate a refresh token within its family.
127
+ *
128
+ * Reuse of a superseded token revokes the family and every family-linked
129
+ * access token inside `rotateRefreshToken`, then this returns
130
+ * `invalid_grant`, which is what §9 AS item 20 requires: reject the reuse
131
+ * and require fresh authorization.
132
+ */
133
+ refresh(input) {
134
+ const now = input.now ?? new Date();
135
+ const rotation = this.store.rotateRefreshToken(input.refreshToken, now);
136
+ if (!rotation.ok) {
137
+ return {
138
+ ok: false,
139
+ failure: {
140
+ code: "invalid_grant",
141
+ message: rotation.reason === "reuse_detected"
142
+ ? "refresh token reuse detected; the token family has been revoked and fresh authorization is required"
143
+ : "refresh token is unknown or its family is revoked",
144
+ },
145
+ };
146
+ }
147
+ const stored = this.store.getGrant(rotation.grantId);
148
+ if (!stored) {
149
+ return {
150
+ ok: false,
151
+ failure: { code: "invalid_grant", message: "grant not found" },
152
+ };
153
+ }
154
+ const inactive = grantInactiveReason(this.store, stored, now);
155
+ if (inactive) {
156
+ return {
157
+ ok: false,
158
+ failure: {
159
+ code: "invalid_grant",
160
+ message: `grant is ${inactive === "grant_revoked" ? "revoked" : "expired"}`,
161
+ },
162
+ };
163
+ }
164
+ return this.mintForGrant(stored, now, rotation.familyId);
165
+ }
166
+ /**
167
+ * Mint an access token (and, for continuous grants, a refresh token) bound
168
+ * to a grant.
169
+ *
170
+ * `existingFamilyId` carries a rotation into the same family so reuse
171
+ * detection keeps working across the whole chain; a first issuance creates
172
+ * the family.
173
+ */
174
+ mintForGrant(stored, now, existingFamilyId) {
175
+ const { grant } = stored;
176
+ const continuous = mayIssueRefreshToken([grant.access_mode]);
177
+ let familyId = existingFamilyId ?? null;
178
+ if (continuous && familyId === null) {
179
+ familyId = this.store.createRefreshFamily(grant.grant_id);
180
+ }
181
+ const accessToken = newOpaqueToken("pdpp_at");
182
+ // A token must never outlive the grant it is bound to. Clamping here means
183
+ // the RS's `min(token_exp, 60s)` cache bound can never extend access past
184
+ // grant expiry either.
185
+ const ttlExpiry = new Date(now.getTime() + this.accessTtl * 1000);
186
+ const grantExpiry = grant.expires_at ? new Date(grant.expires_at) : null;
187
+ const effectiveExpiry = grantExpiry && grantExpiry < ttlExpiry ? grantExpiry : ttlExpiry;
188
+ const issued = this.store.issueAccessToken({
189
+ token: accessToken,
190
+ grantId: grant.grant_id,
191
+ subjectId: stored.subjectId,
192
+ clientId: grant.client.client_id,
193
+ tokenKind: "client",
194
+ familyId,
195
+ expiresAt: effectiveExpiry.toISOString(),
196
+ // A single-use grant is consumed exactly at first client-token issuance.
197
+ // A rotation is never a first issuance, so it never re-consumes.
198
+ consumeSingleUse: grant.access_mode === "single_use" && existingFamilyId === undefined,
199
+ now,
200
+ });
201
+ if (!issued) {
202
+ return {
203
+ ok: false,
204
+ failure: {
205
+ code: "invalid_grant",
206
+ message: "single_use grant has already been consumed; no further access tokens may be issued against it",
207
+ },
208
+ };
209
+ }
210
+ const expiresIn = Math.max(1, Math.floor((effectiveExpiry.getTime() - now.getTime()) / 1000));
211
+ let refreshToken;
212
+ if (continuous && familyId) {
213
+ refreshToken = newOpaqueToken("pdpp_rt");
214
+ this.store.insertRefreshToken(refreshToken, familyId, now);
215
+ }
216
+ return {
217
+ ok: true,
218
+ issued: {
219
+ access_token: accessToken,
220
+ token_type: "Bearer",
221
+ expires_in: expiresIn,
222
+ ...(refreshToken && { refresh_token: refreshToken }),
223
+ grant_id: grant.grant_id,
224
+ authorization_details: [toAuthorizationEntry(grant)],
225
+ },
226
+ };
227
+ }
228
+ /**
229
+ * The single shared token-validation path (§8 "Grant enforcement").
230
+ *
231
+ * Reads live store state every call. That is what makes revocation immediate
232
+ * in introspection (§9 AS item 8) — there is no AS-side cache to invalidate.
233
+ */
234
+ resolveToken(accessToken, now = new Date()) {
235
+ const record = this.store.getAccessToken(accessToken);
236
+ if (!record) {
237
+ return { active: false, inactiveReason: "unknown" };
238
+ }
239
+ // Grant state is checked BEFORE the token's own revocation flag, because
240
+ // revoking a grant also marks its linked tokens revoked. Checking the
241
+ // token first would report `revoked` for what is really a grant
242
+ // revocation, and the RS keys 403 `grant_revoked` off this exact reason
243
+ // (§2 revocation propagation) — it would return the wrong error.
244
+ if (record.tokenKind === "client" && record.grantId) {
245
+ const stored = this.store.getGrant(record.grantId);
246
+ if (!stored) {
247
+ return { active: false, inactiveReason: "unknown" };
248
+ }
249
+ const grantInactive = grantInactiveReason(this.store, stored, now);
250
+ if (grantInactive) {
251
+ return { active: false, inactiveReason: grantInactive };
252
+ }
253
+ }
254
+ if (record.revokedAt) {
255
+ return { active: false, inactiveReason: "revoked" };
256
+ }
257
+ if (record.expiresAt && Date.parse(record.expiresAt) <= now.getTime()) {
258
+ return { active: false, inactiveReason: "expired" };
259
+ }
260
+ // A token minted into a family that was later burned by reuse detection is
261
+ // dead even if its own row was not individually marked — belt and braces
262
+ // against a token inserted concurrently with the family revocation.
263
+ if (record.familyId && this.store.isFamilyRevoked(record.familyId)) {
264
+ return { active: false, inactiveReason: "revoked" };
265
+ }
266
+ if (record.tokenKind === "owner") {
267
+ // An owner token carries no grant. The RS derives subject scope from
268
+ // `subjectId` and must not synthesize a grant for it (§8).
269
+ return {
270
+ active: true,
271
+ tokenKind: "owner",
272
+ subjectId: record.subjectId,
273
+ ...(record.ownerSourceId && { sourceId: record.ownerSourceId }),
274
+ ...(record.ownerInstanceIds && {
275
+ instanceIds: record.ownerInstanceIds,
276
+ }),
277
+ ...(record.expiresAt && { expiresAt: record.expiresAt }),
278
+ };
279
+ }
280
+ if (!record.grantId) {
281
+ // A client token with no grant link is unusable by definition.
282
+ return { active: false, inactiveReason: "unknown" };
283
+ }
284
+ const stored = this.store.getGrant(record.grantId);
285
+ if (!stored) {
286
+ return { active: false, inactiveReason: "unknown" };
287
+ }
288
+ const inactive = grantInactiveReason(this.store, stored, now);
289
+ if (inactive) {
290
+ // grant_revoked is the reason the RS turns into 403 grant_revoked.
291
+ return { active: false, inactiveReason: inactive };
292
+ }
293
+ return {
294
+ active: true,
295
+ tokenKind: "client",
296
+ subjectId: stored.subjectId,
297
+ grant: stored.grant,
298
+ clientId: stored.grant.client.client_id,
299
+ ...(record.expiresAt && { expiresAt: record.expiresAt }),
300
+ };
301
+ }
302
+ /**
303
+ * RFC 7662 introspection.
304
+ *
305
+ * An inactive token yields exactly `{ active: false }`. RFC 7662 §2.2 is
306
+ * clear that the response must not distinguish revoked from expired from
307
+ * never-issued — the reason stays internal (`resolveToken`) for the
308
+ * co-located RS, which needs it to pick 403 `grant_revoked`.
309
+ */
310
+ introspect(accessToken, now = new Date()) {
311
+ const context = this.resolveToken(accessToken, now);
312
+ if (!context.active) {
313
+ return { active: false };
314
+ }
315
+ const base = {
316
+ active: true,
317
+ pdpp_token_kind: context.tokenKind,
318
+ subject_id: context.subjectId,
319
+ ...(context.sourceId && { source_id: context.sourceId }),
320
+ ...(context.instanceIds && { instance_ids: context.instanceIds }),
321
+ ...(context.expiresAt && {
322
+ exp: Math.floor(Date.parse(context.expiresAt) / 1000),
323
+ }),
324
+ };
325
+ if (context.tokenKind === "owner" || !context.grant) {
326
+ return base;
327
+ }
328
+ return {
329
+ ...base,
330
+ grant_id: context.grant.grant_id,
331
+ client_id: context.grant.client.client_id,
332
+ // The complete resolved enforcement context, in one response (§9 item 18).
333
+ authorization_details: [toAuthorizationEntry(context.grant)],
334
+ };
335
+ }
336
+ /** Revoke a grant and every linked token family. Immediate (§2, §9 item 8). */
337
+ revokeGrant(grantId, now = new Date()) {
338
+ return this.store.revokeGrant(grantId, now);
339
+ }
340
+ /**
341
+ * Issue an owner token for a subject.
342
+ *
343
+ * An owner token carries no grant (§8 "Authentication"): it scopes to a
344
+ * single subject's data store, and the RS derives subject scope from it
345
+ * rather than synthesizing a grant. It is also what authenticates a consent
346
+ * decision — see `approval.ts` for why the AS requires this rather than
347
+ * trusting the consent UI's affiliation.
348
+ *
349
+ * How the owner *obtains* this token is out of scope for Core; this build
350
+ * mints it from the already-authenticated owner session paths.
351
+ */
352
+ issueOwnerToken(input) {
353
+ const now = input.now ?? new Date();
354
+ const ttl = input.ttlSeconds ?? this.accessTtl;
355
+ const token = newOpaqueToken("pdpp_ot");
356
+ const expiresAt = new Date(now.getTime() + ttl * 1000);
357
+ this.store.issueAccessToken({
358
+ token,
359
+ grantId: null,
360
+ subjectId: input.subjectId,
361
+ clientId: null,
362
+ tokenKind: "owner",
363
+ ownerSourceId: input.sourceId,
364
+ ownerInstanceIds: input.instanceIds,
365
+ expiresAt: expiresAt.toISOString(),
366
+ consumeSingleUse: false,
367
+ now,
368
+ });
369
+ return { access_token: token, token_type: "Bearer", expires_in: ttl };
370
+ }
371
+ /** Revoke a single access token without touching its grant. */
372
+ revokeAccessToken(token, now = new Date()) {
373
+ return this.store.revokeAccessToken(token, now);
374
+ }
375
+ }
376
+ /**
377
+ * Project a grant onto the RFC 9396 detail the introspection response carries.
378
+ *
379
+ * Note what is absent: `client_claims` and `retention` are not enforcement
380
+ * fields. §6 keeps claims outside introspection rights and RS enforcement
381
+ * entirely; retention is a policy commitment PDPP does not technically
382
+ * enforce, so including it would invite an RS to act on it.
383
+ */
384
+ /**
385
+ * Project a grant onto the `authorization_details` element for *its own*
386
+ * revision.
387
+ *
388
+ * v0.1 gets the narrow enforcement projection below, unchanged. v0.2 gets
389
+ * `{ type, grant }` carrying the complete immutable grant, because v0.2 makes
390
+ * the result the client's source of truth and forbids substituting the
391
+ * original selection request or a lossy summary — and the v0.1 projection is
392
+ * precisely a lossy summary. It drops `retention`, `expires_at`, the resolved
393
+ * client identity, and the requested-vs-approved record, so a v0.2 client
394
+ * receiving it could not tell a narrowed grant from an unnarrowed one.
395
+ *
396
+ * Branching on the grant rather than on a caller-supplied flag is what keeps
397
+ * the two revisions from drifting: the same function serves the token response
398
+ * and introspection, so a client and an authenticated RS cannot be handed
399
+ * different facts about one grant.
400
+ */
401
+ export function toAuthorizationEntry(grant) {
402
+ if (isV02Grant(grant)) {
403
+ return { type: PDPP_DATA_ACCESS_TYPE_V02, grant };
404
+ }
405
+ return toAuthorizationDetail(grant);
406
+ }
407
+ export function toAuthorizationDetail(grant) {
408
+ return {
409
+ type: PDPP_DATA_ACCESS_TYPE,
410
+ source: grant.source,
411
+ purpose_code: grant.purpose_code,
412
+ ...(grant.purpose_description && {
413
+ purpose_description: grant.purpose_description,
414
+ }),
415
+ access_mode: grant.access_mode,
416
+ streams: grant.streams,
417
+ };
418
+ }
419
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/pdpp/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,cAAc,GAGf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,yBAAyB,GAQ1B,MAAM,YAAY,CAAC;AAEpB,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gCAAgC,GAAG,EAAE,GAAG,EAAE,CAAC;AAExD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAmCjD;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAyB;IAC5D,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,mBAAmB,CAC1B,KAAoB,EACpB,MAAmB,EACnB,GAAS;IAET,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC;IACjD,IAAI,MAAM,KAAK,SAAS;Q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