@grantex/sdk 0.5.1 → 0.7.0

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 (185) hide show
  1. package/LICENSE +185 -0
  2. package/NOTICE +16 -0
  3. package/README.md +34 -2
  4. package/dist/authorization-details.d.ts +86 -0
  5. package/dist/authorization-details.d.ts.map +1 -0
  6. package/dist/authorization-details.js +209 -0
  7. package/dist/authorization-details.js.map +1 -0
  8. package/dist/canonical.d.ts +47 -0
  9. package/dist/canonical.d.ts.map +1 -0
  10. package/dist/canonical.js +163 -0
  11. package/dist/canonical.js.map +1 -0
  12. package/dist/caps/index.d.ts +19 -0
  13. package/dist/caps/index.d.ts.map +1 -0
  14. package/dist/caps/index.js +19 -0
  15. package/dist/caps/index.js.map +1 -0
  16. package/dist/caps/limits.d.ts +40 -0
  17. package/dist/caps/limits.d.ts.map +1 -0
  18. package/dist/caps/limits.js +109 -0
  19. package/dist/caps/limits.js.map +1 -0
  20. package/dist/caps/memory.d.ts +15 -0
  21. package/dist/caps/memory.d.ts.map +1 -0
  22. package/dist/caps/memory.js +57 -0
  23. package/dist/caps/memory.js.map +1 -0
  24. package/dist/caps/meter.d.ts +107 -0
  25. package/dist/caps/meter.d.ts.map +1 -0
  26. package/dist/caps/meter.js +200 -0
  27. package/dist/caps/meter.js.map +1 -0
  28. package/dist/caps/postgres.d.ts +64 -0
  29. package/dist/caps/postgres.d.ts.map +1 -0
  30. package/dist/caps/postgres.js +221 -0
  31. package/dist/caps/postgres.js.map +1 -0
  32. package/dist/caps/redis.d.ts +45 -0
  33. package/dist/caps/redis.d.ts.map +1 -0
  34. package/dist/caps/redis.js +173 -0
  35. package/dist/caps/redis.js.map +1 -0
  36. package/dist/client.d.ts +12 -0
  37. package/dist/client.d.ts.map +1 -1
  38. package/dist/client.js +517 -57
  39. package/dist/client.js.map +1 -1
  40. package/dist/decisions/action.d.ts +51 -0
  41. package/dist/decisions/action.d.ts.map +1 -0
  42. package/dist/decisions/action.js +237 -0
  43. package/dist/decisions/action.js.map +1 -0
  44. package/dist/decisions/index.d.ts +11 -0
  45. package/dist/decisions/index.d.ts.map +1 -0
  46. package/dist/decisions/index.js +8 -0
  47. package/dist/decisions/index.js.map +1 -0
  48. package/dist/decisions/verify.d.ts +103 -0
  49. package/dist/decisions/verify.d.ts.map +1 -0
  50. package/dist/decisions/verify.js +277 -0
  51. package/dist/decisions/verify.js.map +1 -0
  52. package/dist/denials.d.ts +132 -0
  53. package/dist/denials.d.ts.map +1 -0
  54. package/dist/denials.js +129 -0
  55. package/dist/denials.js.map +1 -0
  56. package/dist/evidence/build.d.ts +63 -0
  57. package/dist/evidence/build.d.ts.map +1 -0
  58. package/dist/evidence/build.js +201 -0
  59. package/dist/evidence/build.js.map +1 -0
  60. package/dist/evidence/canonical.d.ts +3 -0
  61. package/dist/evidence/canonical.d.ts.map +1 -0
  62. package/dist/evidence/canonical.js +3 -0
  63. package/dist/evidence/canonical.js.map +1 -0
  64. package/dist/evidence/checks.d.ts +13 -0
  65. package/dist/evidence/checks.d.ts.map +1 -0
  66. package/dist/evidence/checks.js +406 -0
  67. package/dist/evidence/checks.js.map +1 -0
  68. package/dist/evidence/document.d.ts +8 -0
  69. package/dist/evidence/document.d.ts.map +1 -0
  70. package/dist/evidence/document.js +298 -0
  71. package/dist/evidence/document.js.map +1 -0
  72. package/dist/evidence/hashing.d.ts +37 -0
  73. package/dist/evidence/hashing.d.ts.map +1 -0
  74. package/dist/evidence/hashing.js +106 -0
  75. package/dist/evidence/hashing.js.map +1 -0
  76. package/dist/evidence/index.d.ts +24 -0
  77. package/dist/evidence/index.d.ts.map +1 -0
  78. package/dist/evidence/index.js +24 -0
  79. package/dist/evidence/index.js.map +1 -0
  80. package/dist/evidence/result.d.ts +88 -0
  81. package/dist/evidence/result.d.ts.map +1 -0
  82. package/dist/evidence/result.js +88 -0
  83. package/dist/evidence/result.js.map +1 -0
  84. package/dist/evidence/schema-1.0.d.ts +2 -0
  85. package/dist/evidence/schema-1.0.d.ts.map +1 -0
  86. package/dist/evidence/schema-1.0.js +1398 -0
  87. package/dist/evidence/schema-1.0.js.map +1 -0
  88. package/dist/evidence/schema.d.ts +13 -0
  89. package/dist/evidence/schema.d.ts.map +1 -0
  90. package/dist/evidence/schema.js +264 -0
  91. package/dist/evidence/schema.js.map +1 -0
  92. package/dist/evidence/signature.d.ts +23 -0
  93. package/dist/evidence/signature.d.ts.map +1 -0
  94. package/dist/evidence/signature.js +136 -0
  95. package/dist/evidence/signature.js.map +1 -0
  96. package/dist/evidence/trace.d.ts +23 -0
  97. package/dist/evidence/trace.d.ts.map +1 -0
  98. package/dist/evidence/trace.js +69 -0
  99. package/dist/evidence/trace.js.map +1 -0
  100. package/dist/evidence/verify.d.ts +29 -0
  101. package/dist/evidence/verify.d.ts.map +1 -0
  102. package/dist/evidence/verify.js +163 -0
  103. package/dist/evidence/verify.js.map +1 -0
  104. package/dist/http.d.ts +12 -1
  105. package/dist/http.d.ts.map +1 -1
  106. package/dist/http.js +11 -5
  107. package/dist/http.js.map +1 -1
  108. package/dist/index.d.ts +16 -3
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +16 -2
  111. package/dist/index.js.map +1 -1
  112. package/dist/manifest.d.ts +178 -9
  113. package/dist/manifest.d.ts.map +1 -1
  114. package/dist/manifest.js +379 -16
  115. package/dist/manifest.js.map +1 -1
  116. package/dist/prepaid-wallets.d.ts +21 -0
  117. package/dist/prepaid-wallets.d.ts.map +1 -1
  118. package/dist/prepaid-wallets.js +6 -0
  119. package/dist/prepaid-wallets.js.map +1 -1
  120. package/dist/purpose.d.ts +29 -0
  121. package/dist/purpose.d.ts.map +1 -0
  122. package/dist/purpose.js +60 -0
  123. package/dist/purpose.js.map +1 -0
  124. package/dist/resources/agents.js +3 -3
  125. package/dist/resources/agents.js.map +1 -1
  126. package/dist/resources/anomalies.d.ts +3 -1
  127. package/dist/resources/anomalies.d.ts.map +1 -1
  128. package/dist/resources/anomalies.js +7 -1
  129. package/dist/resources/anomalies.js.map +1 -1
  130. package/dist/resources/audit.js +1 -1
  131. package/dist/resources/audit.js.map +1 -1
  132. package/dist/resources/budgets.js +2 -2
  133. package/dist/resources/budgets.js.map +1 -1
  134. package/dist/resources/credentials.js +1 -1
  135. package/dist/resources/credentials.js.map +1 -1
  136. package/dist/resources/decisions.d.ts +69 -0
  137. package/dist/resources/decisions.d.ts.map +1 -0
  138. package/dist/resources/decisions.js +115 -0
  139. package/dist/resources/decisions.js.map +1 -0
  140. package/dist/resources/domains.js +2 -2
  141. package/dist/resources/domains.js.map +1 -1
  142. package/dist/resources/dpdp.js +4 -4
  143. package/dist/resources/dpdp.js.map +1 -1
  144. package/dist/resources/grants.js +2 -2
  145. package/dist/resources/grants.js.map +1 -1
  146. package/dist/resources/policies.js +3 -3
  147. package/dist/resources/policies.js.map +1 -1
  148. package/dist/resources/scim.js +5 -5
  149. package/dist/resources/scim.js.map +1 -1
  150. package/dist/resources/tokens.d.ts.map +1 -1
  151. package/dist/resources/tokens.js +5 -1
  152. package/dist/resources/tokens.js.map +1 -1
  153. package/dist/resources/vault.js +2 -2
  154. package/dist/resources/vault.js.map +1 -1
  155. package/dist/resources/webauthn.d.ts +6 -1
  156. package/dist/resources/webauthn.d.ts.map +1 -1
  157. package/dist/resources/webauthn.js +5 -1
  158. package/dist/resources/webauthn.js.map +1 -1
  159. package/dist/resources/webhooks.js +1 -1
  160. package/dist/resources/webhooks.js.map +1 -1
  161. package/dist/revocations/feed.d.ts +61 -0
  162. package/dist/revocations/feed.d.ts.map +1 -0
  163. package/dist/revocations/feed.js +282 -0
  164. package/dist/revocations/feed.js.map +1 -0
  165. package/dist/revocations/index.d.ts +20 -0
  166. package/dist/revocations/index.d.ts.map +1 -0
  167. package/dist/revocations/index.js +19 -0
  168. package/dist/revocations/index.js.map +1 -0
  169. package/dist/revocations/set.d.ts +59 -0
  170. package/dist/revocations/set.d.ts.map +1 -0
  171. package/dist/revocations/set.js +87 -0
  172. package/dist/revocations/set.js.map +1 -0
  173. package/dist/scopes.d.ts +26 -0
  174. package/dist/scopes.d.ts.map +1 -0
  175. package/dist/scopes.js +37 -0
  176. package/dist/scopes.js.map +1 -0
  177. package/dist/types.d.ts +121 -4
  178. package/dist/types.d.ts.map +1 -1
  179. package/dist/types.js +0 -1
  180. package/dist/types.js.map +1 -1
  181. package/dist/verify.d.ts +31 -2
  182. package/dist/verify.d.ts.map +1 -1
  183. package/dist/verify.js +236 -29
  184. package/dist/verify.js.map +1 -1
  185. package/package.json +13 -4
package/LICENSE ADDED
@@ -0,0 +1,185 @@
1
+ Copyright 2026 Orchestrum Technologies LLP.
2
+ Grantex inventor and owner: Sanjeev Kumar <sanjeev@orchestrum.in> or <mishra.sanjeev@gmail.com>.
3
+
4
+ Apache License
5
+ Version 2.0, January 2004
6
+ http://www.apache.org/licenses/
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction,
13
+ and distribution as defined by Sections 1 through 9 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by
16
+ the copyright owner that is granting the License.
17
+
18
+ "Legal Entity" shall mean the union of the acting entity and all
19
+ other entities that control, are controlled by, or are under common
20
+ control with that entity. For the purposes of this definition,
21
+ "control" means (i) the power, direct or indirect, to cause the
22
+ direction or management of such entity, whether by contract or
23
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
24
+ outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity
27
+ exercising permissions granted by this License.
28
+
29
+ "Source" form shall mean the preferred form for making modifications,
30
+ including but not limited to software source code, documentation
31
+ source, and configuration files.
32
+
33
+ "Object" form shall mean any form resulting from mechanical
34
+ transformation or translation of a Source form, including but
35
+ not limited to compiled object code, generated documentation,
36
+ and conversions to other media types.
37
+
38
+ "Work" shall mean the work of authorship made available under
39
+ the License, as indicated by a copyright notice that is included in
40
+ or attached to the work (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean, as defined by the copyright owner or by an
51
+ individual or Legal Entity authorized to submit on behalf of the
52
+ copyright owner. For the purposes of this definition, "submitted"
53
+ means any form of electronic, verbal, or written communication sent
54
+ to the Licensor or its representatives, including but not limited to
55
+ communication on electronic mailing lists, source code control systems,
56
+ and issue tracking systems that are managed by, or on behalf of, the
57
+ Licensor for the purpose of discussing and improving the Work, but
58
+ excluding communication that is conspicuously marked or otherwise
59
+ designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
62
+ whom a Contribution has been received by the Licensor and subsequently
63
+ incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of
66
+ this License, each Contributor hereby grants to You a perpetual,
67
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
68
+ copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the
70
+ Work and such Derivative Works in Source or Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of
73
+ this License, each Contributor hereby grants to You a perpetual,
74
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
+ (except as stated in this section) patent license to make, have made,
76
+ use, offer to sell, sell, import, and otherwise transfer the Work,
77
+ where such license applies only to those patent claims licensable
78
+ by such Contributor that are necessarily infringed by their
79
+ Contribution(s) alone or by the combination of their Contribution(s)
80
+ with the Work to which such Contribution(s) was submitted. If You
81
+ institute patent litigation against any entity (including a cross-claim
82
+ or counterclaim in a lawsuit) alleging that the Work or any
83
+ Contribution embodied within the Work constitutes direct or contributory
84
+ patent infringement, then any patent licenses granted to You under
85
+ this License for that Work shall terminate as of the date such
86
+ litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the
89
+ Work or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You
91
+ meet the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or Derivative
94
+ Works a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works
100
+ that You distribute, all copyright, patent, trademark, and
101
+ attribution notices from the Source form of the Work,
102
+ excluding those notices that do not pertain to any part of
103
+ the Derivative Works; and
104
+
105
+ (d) If the Work includes a "NOTICE" text file as part of its
106
+ distribution, You must include a readable copy of the
107
+ attribution notices contained within such NOTICE file, in
108
+ at least one of the following places: within a NOTICE text
109
+ file distributed as part of the Derivative Works; within
110
+ the Source form or documentation, if provided along with the
111
+ Derivative Works; or, within a display generated by the
112
+ Derivative Works, if and wherever such third-party notices
113
+ normally appear. The contents of the NOTICE file are for
114
+ informational purposes only and do not modify the License.
115
+ You may add Your own attribution notices within Derivative
116
+ Works that You distribute, alongside or in addition to the
117
+ NOTICE text from the Work, provided that such additional
118
+ attribution notices cannot be construed as modifying the License.
119
+
120
+ You may add Your own license statement for Your modifications and
121
+ may provide additional grant of rights to use, copy, modify, merge,
122
+ publish, distribute, sublicense, and/or sell copies of the
123
+ Contribution, either on an inclusive or exclusive basis.
124
+
125
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
126
+ any Contribution intentionally submitted for inclusion in the Work
127
+ by You to the Licensor shall be under the terms and conditions of
128
+ this License, without any additional terms or conditions.
129
+ Notwithstanding the above, nothing herein shall supersede or modify
130
+ the terms of any separate license agreement you may have executed
131
+ with Licensor regarding such Contributions.
132
+
133
+ 6. Trademarks. This License does not grant permission to use the trade
134
+ names, trademarks, service marks, or product names of the Licensor,
135
+ except as required for reasonable and customary use in describing the
136
+ origin of the Work and reproducing the content of the NOTICE file.
137
+
138
+ 7. Disclaimer of Warranty. Unless required by applicable law or
139
+ agreed to in writing, Licensor provides the Work (and each
140
+ Contributor provides its Contributions) on an "AS IS" BASIS,
141
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
142
+ implied, including, without limitation, any warranties or conditions
143
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
144
+ PARTICULAR PURPOSE. You are solely responsible for determining the
145
+ appropriateness of using or reproducing the Work and assume any
146
+ risks associated with Your exercise of permissions under this License.
147
+
148
+ 8. Limitation of Liability. In no event and under no legal theory,
149
+ whether in tort (including negligence), contract, or otherwise,
150
+ unless required by applicable law (such as deliberate and grossly
151
+ negligent acts) or agreed to in writing, shall any Contributor be
152
+ liable to You for damages, including any direct, indirect, special,
153
+ incidental, or exemplary damages of any character arising as a
154
+ result of this License or out of the use or inability to use the
155
+ Work (including but not limited to damages for loss of goodwill,
156
+ work stoppage, computer failure or malfunction, or all other
157
+ commercial damages or losses), even if such Contributor has been
158
+ advised of the possibility of such damages.
159
+
160
+ 9. Accepting Warranty or Additional Liability. While redistributing
161
+ the Work or Derivative Works thereof, You may choose to offer,
162
+ and charge a fee for, acceptance of support, warranty, indemnity,
163
+ or other liability obligations and/or rights consistent with this
164
+ License. However, in accepting such obligations, You may offer such
165
+ conditions only on Your own behalf and on Your sole responsibility,
166
+ not on behalf of any other Contributor, and only if You agree to
167
+ indemnify, defend, and hold each Contributor harmless for any
168
+ liability incurred by, or claims asserted against, such Contributor
169
+ by reason of your accepting any such warranty or additional liability.
170
+
171
+ END OF TERMS AND CONDITIONS
172
+
173
+ Copyright 2026 Grantex Contributors
174
+
175
+ Licensed under the Apache License, Version 2.0 (the "License");
176
+ you may not use this file except in compliance with the License.
177
+ You may obtain a copy of the License at
178
+
179
+ http://www.apache.org/licenses/LICENSE-2.0
180
+
181
+ Unless required by applicable law or agreed to in writing, software
182
+ distributed under the License is distributed on an "AS IS" BASIS,
183
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
184
+ See the License for the specific language governing permissions and
185
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,16 @@
1
+ Grantex Ownership Notice
2
+
3
+ Grantex is owned by Orchestrum Technologies LLP.
4
+
5
+ Inventor and owner: Sanjeev Kumar.
6
+
7
+ Ownership contact: sanjeev@orchestrum.in or mishra.sanjeev@gmail.com
8
+
9
+ The Grantex protocol specification, source code, SDKs, examples, and
10
+ documentation are made available under the Apache License 2.0 unless a file
11
+ states otherwise. The open-source license does not remove or transfer the
12
+ product ownership notice above.
13
+
14
+ Third-party dependencies retain their own licenses. See
15
+ https://github.com/mishrasanjeev/grantex/blob/main/THIRD_PARTY_NOTICES.md
16
+ for reviewed distribution notices and obligations.
package/README.md CHANGED
@@ -9,8 +9,18 @@ TypeScript SDK for the [Grantex](https://grantex.dev) delegated authorization pr
9
9
 
10
10
  ## Installation
11
11
 
12
+ **Version 0.7.0:** adds hosted passkey enrollment sessions and
13
+ account-level irregularity response policy methods. The server must enable the
14
+ corresponding feature flags; this SDK does not register a passkey without an
15
+ authenticated customer handoff. Version 0.6.0 added wallet clients that preserve the
16
+ server's Base USDC `evmPayment` payload and expose `reconcileReservation()` for
17
+ finalized settlement/expiry. Use `@grantex/x402@0.4.0` or later for
18
+ the automatic 402/payment/retry flow. Confirm the published SDK version in
19
+ [Release Status](https://docs.grantex.dev/release-status) before installing.
20
+ See [Base custody setup](https://docs.grantex.dev/guides/base-usdc-custody).
21
+
12
22
  ```bash
13
- npm install @grantex/sdk
23
+ npm install @grantex/sdk@0.7.0
14
24
  ```
15
25
 
16
26
  ## Quick Start
@@ -159,7 +169,7 @@ const agentWallets = new PrepaidWalletAgentClient({
159
169
  });
160
170
 
161
171
  const principalWallets = new PrincipalPrepaidWalletClient({
162
- baseUrl: 'https://grantex.dev',
172
+ baseUrl: 'https://api.grantex.dev',
163
173
  sessionToken,
164
174
  });
165
175
 
@@ -708,6 +718,22 @@ console.log(pack.policies);
708
718
 
709
719
  ### Anomaly Detection
710
720
 
721
+ In version 0.7.0, `grantex.anomalies.getResponsePolicy()` and
722
+ `grantex.anomalies.setResponsePolicy('alert_only')` control the account-wide
723
+ response of the legacy detector when the server operator enables
724
+ `IRREGULARITY_RESPONSE_POLICY_ENABLED=true`. Default behavior revokes active
725
+ grants for a high/critical finding's agent. Alert-only retains findings and
726
+ events without that automatic revocation. This setting does not disable other
727
+ security controls.
728
+
729
+ Version 0.7.0 also supports
730
+ `grantex.webauthn.createEnrollmentSession({ principalId, authRequestId? })`.
731
+ Call it only on your server after authenticating the customer. Deliver the
732
+ returned one-use hosted link to that exact customer; never expose the API key
733
+ or log the link. Hosted enrollment requires the server's default-off
734
+ `PASSKEY_ENROLLMENT_ENABLED=true` setting. Live consent has no password or
735
+ sandbox fallback.
736
+
711
737
  #### `grantex.anomalies.detect()`
712
738
 
713
739
  Run anomaly detection across all agents.
@@ -940,3 +966,9 @@ const result = await grantex.enforce({ grantToken: token, connector: 'my-crm', t
940
966
  ## Ownership
941
967
 
942
968
  Grantex is owned by Orchestrum Technologies LLP. Inventor and owner: Sanjeev Kumar. Ownership contact: [sanjeev@orchestrum.in](mailto:sanjeev@orchestrum.in) or [mishra.sanjeev@gmail.com](mailto:mishra.sanjeev@gmail.com).
969
+
970
+ ## Source Development
971
+
972
+ Use Node.js 24 LTS and `npm ci` to build or test this checkout with Vitest 5.
973
+ Repository validation steps are in [the dependency upgrade guide](https://docs.grantex.dev/guides/dependency-updates).
974
+ Source-tooling requirements are separate from published package runtime support.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Read `urn:grantex:tools:v1` entries from a grant's `authorization_details`.
3
+ *
4
+ * This is the only place that interprets the `authorization_details` claim
5
+ * (RFC 9396), so a change to the token format touches one function. Shape:
6
+ *
7
+ * ```json
8
+ * "authorization_details": [{
9
+ * "type": "urn:grantex:tools:v1",
10
+ * "connector": "acme_kyb",
11
+ * "purpose": "aml.cdd.onboarding",
12
+ * "data_region": "eu",
13
+ * "tools": ["resolve_business", "verify_business", "screen_*"],
14
+ * "caps": {"verify_business": {"per_hour": 50, "per_case": 3},
15
+ * "cost_units": {"per_day": 5000}}
16
+ * }]
17
+ * ```
18
+ *
19
+ * Entries of other types are separate authorizations and are ignored here. A
20
+ * tools entry constrains calls on its connector in addition to the grant's
21
+ * scopes. Anything ambiguous (a claim that is not an array, an entry without
22
+ * a string `type`, a tools entry with an unknown key, a value of the wrong
23
+ * type, or two tools entries for one connector) throws
24
+ * `AuthorizationDetailsError`, and `enforce()` denies. Mirrors the Python
25
+ * SDK's `grantex._authorization_details`.
26
+ *
27
+ * `caps` is validated here, for every call on the connector: each key is an
28
+ * exact tool name or `cost_units` (the connector's cost-unit budget), never a
29
+ * wildcard, and each value is a non-empty object of `per_hour`, `per_day` and
30
+ * `per_case` counts from 0 to 2147483647.
31
+ */
32
+ export declare const TOOLS_DETAIL_TYPE = "urn:grantex:tools:v1";
33
+ declare const CAP_WINDOWS: readonly ['per_hour', 'per_day', 'per_case'];
34
+ /** Key of the connector cost-unit budget in `caps`; reserved as a tool name. */
35
+ export declare const COST_UNITS_KEY = "cost_units";
36
+ export type CapWindowCounts = Partial<Record<(typeof CAP_WINDOWS)[number], number>>;
37
+ export declare class AuthorizationDetailsError extends Error {
38
+ constructor(message: string);
39
+ }
40
+ /** One `urn:grantex:tools:v1` entry. */
41
+ export interface ToolsAuthorization {
42
+ connector: string;
43
+ /** The grant's purpose for this connector, exactly as issued (not validated). */
44
+ purpose?: string;
45
+ dataRegion?: string;
46
+ /** Tool names, or prefixes ending in `*`; absent means every tool. */
47
+ tools?: readonly string[];
48
+ /** Validated caps: tool name (or `cost_units`) to window to count. */
49
+ caps?: Readonly<Record<string, Readonly<CapWindowCounts>>>;
50
+ }
51
+ /** Whether an entry's `tools` list (when present) names `tool`. */
52
+ export declare function toolsAuthorizationAllows(entry: ToolsAuthorization, tool: string): boolean;
53
+ /**
54
+ * Return the tools entries of an `authorization_details` claim by connector.
55
+ * `undefined` or `null` (no claim) yields an empty map.
56
+ *
57
+ * @throws {AuthorizationDetailsError} the claim is malformed or ambiguous.
58
+ */
59
+ export declare function parseToolsAuthorization(claim: unknown): Map<string, ToolsAuthorization>;
60
+ export declare const DECISION_DETAIL_TYPE = "urn:grantex:decision:v1";
61
+ /**
62
+ * One `urn:grantex:decision:v1` entry: tools on a connector that need a
63
+ * decision grant, and the decisions on each that need two approvers.
64
+ *
65
+ * ```json
66
+ * {"type": "urn:grantex:decision:v1", "connector": "acme_kyb",
67
+ * "tools": ["case_decision"], "four_eyes_on": {"case_decision": ["decline"]}}
68
+ * ```
69
+ */
70
+ export interface DecisionReference {
71
+ connector: string;
72
+ tools: readonly string[];
73
+ fourEyesOn: Readonly<Record<string, readonly string[]>>;
74
+ }
75
+ /**
76
+ * Return the decision references of an `authorization_details` claim by
77
+ * connector. `undefined` or `null` yields an empty map. Entries of other types
78
+ * are ignored.
79
+ *
80
+ * @throws {AuthorizationDetailsError} an entry is malformed: an unknown key, no
81
+ * tools, a tool name that is not a name, `four_eyes_on` naming a tool not in
82
+ * `tools`, or two entries for one connector.
83
+ */
84
+ export declare function parseDecisionReferences(claim: unknown): Map<string, DecisionReference>;
85
+ export {};
86
+ //# sourceMappingURL=authorization-details.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-details.d.ts","sourceRoot":"","sources":["../src/authorization-details.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AAKxD,QAAA,MAAM,WAAW,YAAI,UAAU,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AAGjE,gFAAgF;AAChF,eAAO,MAAM,cAAc,eAAe,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAEpF,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,wCAAwC;AACxC,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,sEAAsE;IACtE,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;CAC5D;AAmCD,mEAAmE;AACnE,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAGzF;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAmDvF;AAED,eAAO,MAAM,oBAAoB,4BAA4B,CAAC;AAM9D;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CACzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAsDtF"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Read `urn:grantex:tools:v1` entries from a grant's `authorization_details`.
3
+ *
4
+ * This is the only place that interprets the `authorization_details` claim
5
+ * (RFC 9396), so a change to the token format touches one function. Shape:
6
+ *
7
+ * ```json
8
+ * "authorization_details": [{
9
+ * "type": "urn:grantex:tools:v1",
10
+ * "connector": "acme_kyb",
11
+ * "purpose": "aml.cdd.onboarding",
12
+ * "data_region": "eu",
13
+ * "tools": ["resolve_business", "verify_business", "screen_*"],
14
+ * "caps": {"verify_business": {"per_hour": 50, "per_case": 3},
15
+ * "cost_units": {"per_day": 5000}}
16
+ * }]
17
+ * ```
18
+ *
19
+ * Entries of other types are separate authorizations and are ignored here. A
20
+ * tools entry constrains calls on its connector in addition to the grant's
21
+ * scopes. Anything ambiguous (a claim that is not an array, an entry without
22
+ * a string `type`, a tools entry with an unknown key, a value of the wrong
23
+ * type, or two tools entries for one connector) throws
24
+ * `AuthorizationDetailsError`, and `enforce()` denies. Mirrors the Python
25
+ * SDK's `grantex._authorization_details`.
26
+ *
27
+ * `caps` is validated here, for every call on the connector: each key is an
28
+ * exact tool name or `cost_units` (the connector's cost-unit budget), never a
29
+ * wildcard, and each value is a non-empty object of `per_hour`, `per_day` and
30
+ * `per_case` counts from 0 to 2147483647.
31
+ */
32
+ export const TOOLS_DETAIL_TYPE = 'urn:grantex:tools:v1';
33
+ const ENTRY_KEYS = new Set(['type', 'connector', 'purpose', 'data_region', 'tools', 'caps']);
34
+ const NAME_RE = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
35
+ const TOOL_PATTERN_RE = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}\*?$/;
36
+ const CAP_WINDOWS = ['per_hour', 'per_day', 'per_case'];
37
+ const MAX_COUNT = 2147483647;
38
+ /** Key of the connector cost-unit budget in `caps`; reserved as a tool name. */
39
+ export const COST_UNITS_KEY = 'cost_units';
40
+ export class AuthorizationDetailsError extends Error {
41
+ constructor(message) {
42
+ super(message);
43
+ this.name = 'AuthorizationDetailsError';
44
+ }
45
+ }
46
+ function isPlainObject(value) {
47
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
48
+ }
49
+ function parseCaps(raw, where) {
50
+ if (!isPlainObject(raw) || Object.keys(raw).length === 0) {
51
+ throw new AuthorizationDetailsError(`${where} must be a non-empty object`);
52
+ }
53
+ const parsed = {};
54
+ for (const [name, windows] of Object.entries(raw)) {
55
+ if (!(name === COST_UNITS_KEY || NAME_RE.test(name))) {
56
+ throw new AuthorizationDetailsError(`${where} key "${name}" must be an exact tool name or cost_units; wildcards are not allowed`);
57
+ }
58
+ if (!isPlainObject(windows) || Object.keys(windows).length === 0) {
59
+ throw new AuthorizationDetailsError(`${where}.${name} must be a non-empty object`);
60
+ }
61
+ const counts = {};
62
+ for (const [window, value] of Object.entries(windows)) {
63
+ if (!CAP_WINDOWS.includes(window)) {
64
+ throw new AuthorizationDetailsError(`${where}.${name} has unknown window "${window}"`);
65
+ }
66
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > MAX_COUNT) {
67
+ throw new AuthorizationDetailsError(`${where}.${name}.${window} must be an integer between 0 and ${MAX_COUNT}`);
68
+ }
69
+ counts[window] = value;
70
+ }
71
+ Object.defineProperty(parsed, name, { value: Object.freeze(counts), enumerable: true, writable: false, configurable: false });
72
+ }
73
+ return parsed;
74
+ }
75
+ /** Whether an entry's `tools` list (when present) names `tool`. */
76
+ export function toolsAuthorizationAllows(entry, tool) {
77
+ if (entry.tools === undefined)
78
+ return true;
79
+ return entry.tools.some((t) => (t.endsWith('*') ? tool.startsWith(t.slice(0, -1)) : t === tool));
80
+ }
81
+ /**
82
+ * Return the tools entries of an `authorization_details` claim by connector.
83
+ * `undefined` or `null` (no claim) yields an empty map.
84
+ *
85
+ * @throws {AuthorizationDetailsError} the claim is malformed or ambiguous.
86
+ */
87
+ export function parseToolsAuthorization(claim) {
88
+ const entries = new Map();
89
+ if (claim === undefined || claim === null)
90
+ return entries;
91
+ if (!Array.isArray(claim))
92
+ throw new AuthorizationDetailsError('authorization_details must be an array');
93
+ claim.forEach((raw, index) => {
94
+ const where = `authorization_details[${index}]`;
95
+ if (!isPlainObject(raw))
96
+ throw new AuthorizationDetailsError(`${where} must be an object`);
97
+ const type = raw['type'];
98
+ if (typeof type !== 'string' || type.length === 0) {
99
+ throw new AuthorizationDetailsError(`${where}.type must be a non-empty string`);
100
+ }
101
+ if (type !== TOOLS_DETAIL_TYPE)
102
+ return;
103
+ const unknown = Object.keys(raw).filter((k) => !ENTRY_KEYS.has(k)).sort();
104
+ if (unknown.length > 0)
105
+ throw new AuthorizationDetailsError(`${where} has unknown key "${unknown[0]}"`);
106
+ const connector = raw['connector'];
107
+ if (typeof connector !== 'string' || !NAME_RE.test(connector)) {
108
+ throw new AuthorizationDetailsError(`${where}.connector must be a connector name`);
109
+ }
110
+ if (entries.has(connector)) {
111
+ throw new AuthorizationDetailsError(`${where} repeats connector "${connector}"; a grant carries one tools entry per connector`);
112
+ }
113
+ const entry = { connector };
114
+ const purpose = raw['purpose'];
115
+ if (purpose !== undefined && purpose !== null) {
116
+ if (typeof purpose !== 'string')
117
+ throw new AuthorizationDetailsError(`${where}.purpose must be a string`);
118
+ entry.purpose = purpose;
119
+ }
120
+ const dataRegion = raw['data_region'];
121
+ if (dataRegion !== undefined && dataRegion !== null) {
122
+ if (typeof dataRegion !== 'string')
123
+ throw new AuthorizationDetailsError(`${where}.data_region must be a string`);
124
+ entry.dataRegion = dataRegion;
125
+ }
126
+ if ('tools' in raw) {
127
+ const tools = raw['tools'];
128
+ if (!Array.isArray(tools) || !tools.every((t) => typeof t === 'string' && TOOL_PATTERN_RE.test(t))) {
129
+ throw new AuthorizationDetailsError(`${where}.tools must be an array of tool names or name prefixes ending in *`);
130
+ }
131
+ entry.tools = Object.freeze([...tools]);
132
+ }
133
+ if ('caps' in raw) {
134
+ entry.caps = Object.freeze(parseCaps(raw['caps'], `${where}.caps`));
135
+ }
136
+ entries.set(connector, entry);
137
+ });
138
+ return entries;
139
+ }
140
+ export const DECISION_DETAIL_TYPE = 'urn:grantex:decision:v1';
141
+ const DECISION_ENTRY_KEYS = new Set(['type', 'connector', 'tools', 'four_eyes_on']);
142
+ const TOOL_NAME_RE = NAME_RE;
143
+ const DECISION_RE = /^[a-z][a-z0-9_]{0,63}$/;
144
+ /**
145
+ * Return the decision references of an `authorization_details` claim by
146
+ * connector. `undefined` or `null` yields an empty map. Entries of other types
147
+ * are ignored.
148
+ *
149
+ * @throws {AuthorizationDetailsError} an entry is malformed: an unknown key, no
150
+ * tools, a tool name that is not a name, `four_eyes_on` naming a tool not in
151
+ * `tools`, or two entries for one connector.
152
+ */
153
+ export function parseDecisionReferences(claim) {
154
+ const entries = new Map();
155
+ if (claim === undefined || claim === null)
156
+ return entries;
157
+ if (!Array.isArray(claim))
158
+ throw new AuthorizationDetailsError('authorization_details must be an array');
159
+ claim.forEach((raw, index) => {
160
+ const where = `authorization_details[${index}]`;
161
+ if (!isPlainObject(raw))
162
+ throw new AuthorizationDetailsError(`${where} must be an object`);
163
+ const type = raw['type'];
164
+ if (typeof type !== 'string' || type.length === 0) {
165
+ throw new AuthorizationDetailsError(`${where}.type must be a non-empty string`);
166
+ }
167
+ if (type !== DECISION_DETAIL_TYPE)
168
+ return;
169
+ const unknown = Object.keys(raw).filter((k) => !DECISION_ENTRY_KEYS.has(k)).sort();
170
+ if (unknown.length > 0)
171
+ throw new AuthorizationDetailsError(`${where} has unknown key "${unknown[0]}"`);
172
+ const connector = raw['connector'];
173
+ if (typeof connector !== 'string' || !NAME_RE.test(connector)) {
174
+ throw new AuthorizationDetailsError(`${where}.connector must be a connector name`);
175
+ }
176
+ if (entries.has(connector)) {
177
+ throw new AuthorizationDetailsError(`${where} repeats connector "${connector}"; a grant carries one decision entry per connector`);
178
+ }
179
+ const tools = raw['tools'];
180
+ if (!Array.isArray(tools) || tools.length === 0
181
+ || !tools.every((t) => typeof t === 'string' && TOOL_NAME_RE.test(t))) {
182
+ throw new AuthorizationDetailsError(`${where}.tools must be a non-empty array of tool names`);
183
+ }
184
+ const fourEyesOn = {};
185
+ if ('four_eyes_on' in raw) {
186
+ const rawFourEyes = raw['four_eyes_on'];
187
+ if (!isPlainObject(rawFourEyes)) {
188
+ throw new AuthorizationDetailsError(`${where}.four_eyes_on must be an object`);
189
+ }
190
+ for (const [tool, decisions] of Object.entries(rawFourEyes)) {
191
+ if (!tools.includes(tool)) {
192
+ throw new AuthorizationDetailsError(`${where}.four_eyes_on names "${tool}", which is not in tools`);
193
+ }
194
+ if (!Array.isArray(decisions) || decisions.length === 0
195
+ || !decisions.every((d) => typeof d === 'string' && DECISION_RE.test(d))) {
196
+ throw new AuthorizationDetailsError(`${where}.four_eyes_on.${tool} must be a non-empty array of decisions`);
197
+ }
198
+ fourEyesOn[tool] = Object.freeze([...decisions]);
199
+ }
200
+ }
201
+ entries.set(connector, {
202
+ connector,
203
+ tools: Object.freeze([...tools]),
204
+ fourEyesOn: Object.freeze(fourEyesOn),
205
+ });
206
+ });
207
+ return entries;
208
+ }
209
+ //# sourceMappingURL=authorization-details.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-details.js","sourceRoot":"","sources":["../src/authorization-details.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAExD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAC7F,MAAM,OAAO,GAAG,qCAAqC,CAAC;AACtD,MAAM,eAAe,GAAG,wCAAwC,CAAC;AACjE,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AACjE,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B,gFAAgF;AAChF,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAI3C,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAcD,SAAS,aAAa,CAAC,K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AyB,CAAC,GAAG,KAAK,iCAAiC,CAAC,CAAC;YACjF,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC5D,IAAI,CAAE,KAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxC,MAAM,IAAI,yBAAyB,CAAC,GAAG,KAAK,wBAAwB,IAAI,0BAA0B,CAAC,CAAC;gBACtG,CAAC;gBACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;uBAChD,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC7E,MAAM,IAAI,yBAAyB,CAAC,GAAG,KAAK,iBAAiB,IAAI,yCAAyC,CAAC,CAAC;gBAC9G,CAAC;gBACD,UAAU,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAI,SAAsB,CAAC,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;YACrB,SAAS;YACT,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAI,KAAkB,CAAC,CAAC;YAC9C,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;SACtC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * JSON Canonicalization Scheme (RFC 8785).
3
+ *
4
+ * `canonicalize` turns a JSON value into its canonical text: object members
5
+ * sorted by the UTF-16 code units of their names, no insignificant
6
+ * whitespace, strings escaped as `JSON.stringify` escapes them and numbers in
7
+ * the ECMAScript `Number` format. Two values that differ only in member order,
8
+ * whitespace or number spelling canonicalise to the same text.
9
+ *
10
+ * The input must be I-JSON (RFC 7493). Anything without a single canonical
11
+ * form throws `CanonicalizationError` instead of being coerced or dropped:
12
+ * `NaN` and infinities; strings or member names with an unpaired surrogate;
13
+ * `undefined`, functions, symbols, bigints, sparse arrays and objects that
14
+ * are not plain objects (such as `Date` or `Map`, whose `toJSON` is not
15
+ * consulted); nesting deeper than `MAX_DEPTH`.
16
+ *
17
+ * The Python SDK implements the same rules in `grantex.canonical`; both are
18
+ * tested against the RFC 8785 test vectors and the shared fixtures in
19
+ * `spec/examples/canonicalization/`. Python additionally refuses integers
20
+ * whose digits are not the canonical form of a double (such as 2^53 + 1);
21
+ * a JavaScript number has already been rounded by the parser.
22
+ */
23
+ /** Deepest nesting of arrays and objects accepted. */
24
+ export declare const MAX_DEPTH = 64;
25
+ /** The value has no RFC 8785 canonical form. */
26
+ export declare class CanonicalizationError extends Error {
27
+ constructor(message: string);
28
+ }
29
+ /** Returns the RFC 8785 canonical JSON text of `value`. */
30
+ export declare function canonicalize(value: unknown): string;
31
+ /** Returns the RFC 8785 canonical JSON of `value` as UTF-8 bytes. */
32
+ export declare function canonicalizeToBytes(value: unknown): Uint8Array;
33
+ /** Serialises a finite number as `Number.prototype.toString` does (`-0` as `0`). */
34
+ export declare function serializeNumber(value: number): string;
35
+ /** A JSON text repeats a member name within one object. */
36
+ export declare class DuplicateKeyError extends CanonicalizationError {
37
+ readonly key: string;
38
+ constructor(key: string);
39
+ }
40
+ /**
41
+ * Parses JSON text like `JSON.parse`, but throws `DuplicateKeyError` when an
42
+ * object repeats a member name (after unescaping), instead of silently keeping
43
+ * the last value. Use it wherever the raw text of a value to canonicalise is
44
+ * available.
45
+ */
46
+ export declare function parseJsonRejectingDuplicates(text: string): unknown;
47
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,sDAAsD;AACtD,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,gDAAgD;AAChD,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAID,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAInD;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAE9D;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrD;AA+DD,2DAA2D;AAC3D,qBAAa,iBAAkB,SAAQ,qBAAqB;IAC1D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,YAAY,GAAG,EAAE,MAAM,EAItB;CACF;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CA6BlE"}