@atproto/oauth-provider 0.16.5 → 0.17.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 (321) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/access-token/access-token-mode.js +2 -5
  3. package/dist/access-token/access-token-mode.js.map +1 -1
  4. package/dist/account/account-manager.js +25 -33
  5. package/dist/account/account-manager.js.map +1 -1
  6. package/dist/account/account-store.js +11 -32
  7. package/dist/account/account-store.js.map +1 -1
  8. package/dist/account/sign-in-data.js +9 -12
  9. package/dist/account/sign-in-data.js.map +1 -1
  10. package/dist/account/sign-up-input.js +14 -17
  11. package/dist/account/sign-up-input.js.map +1 -1
  12. package/dist/client/client-auth.js +1 -2
  13. package/dist/client/client-data.js +1 -2
  14. package/dist/client/client-id.js +2 -5
  15. package/dist/client/client-id.js.map +1 -1
  16. package/dist/client/client-info.js +1 -2
  17. package/dist/client/client-manager.js +86 -97
  18. package/dist/client/client-manager.js.map +1 -1
  19. package/dist/client/client-store.js +7 -26
  20. package/dist/client/client-store.js.map +1 -1
  21. package/dist/client/client-utils.js +10 -14
  22. package/dist/client/client-utils.js.map +1 -1
  23. package/dist/client/client.js +43 -53
  24. package/dist/client/client.js.map +1 -1
  25. package/dist/constants.js +28 -31
  26. package/dist/constants.js.map +1 -1
  27. package/dist/customization/branding.js +8 -11
  28. package/dist/customization/branding.js.map +1 -1
  29. package/dist/customization/build-customization-css.js +8 -11
  30. package/dist/customization/build-customization-css.js.map +1 -1
  31. package/dist/customization/build-customization-data.js +1 -4
  32. package/dist/customization/build-customization-data.js.map +1 -1
  33. package/dist/customization/colors.js +11 -14
  34. package/dist/customization/colors.js.map +1 -1
  35. package/dist/customization/customization.js +8 -11
  36. package/dist/customization/customization.js.map +1 -1
  37. package/dist/customization/links.js +7 -10
  38. package/dist/customization/links.js.map +1 -1
  39. package/dist/device/device-data.js +7 -10
  40. package/dist/device/device-data.js.map +1 -1
  41. package/dist/device/device-id.js +11 -16
  42. package/dist/device/device-id.js.map +1 -1
  43. package/dist/device/device-manager.js +32 -38
  44. package/dist/device/device-manager.js.map +1 -1
  45. package/dist/device/device-store.js +7 -25
  46. package/dist/device/device-store.js.map +1 -1
  47. package/dist/device/session-id.js +9 -13
  48. package/dist/device/session-id.js.map +1 -1
  49. package/dist/dpop/dpop-manager.d.ts +3 -3
  50. package/dist/dpop/dpop-manager.js +38 -43
  51. package/dist/dpop/dpop-manager.js.map +1 -1
  52. package/dist/dpop/dpop-nonce.d.ts +2 -2
  53. package/dist/dpop/dpop-nonce.d.ts.map +1 -1
  54. package/dist/dpop/dpop-nonce.js +14 -18
  55. package/dist/dpop/dpop-nonce.js.map +1 -1
  56. package/dist/dpop/dpop-proof.js +1 -2
  57. package/dist/errors/access-denied-error.js +2 -6
  58. package/dist/errors/access-denied-error.js.map +1 -1
  59. package/dist/errors/account-selection-required-error.js +2 -6
  60. package/dist/errors/account-selection-required-error.js.map +1 -1
  61. package/dist/errors/authorization-error.js +7 -12
  62. package/dist/errors/authorization-error.js.map +1 -1
  63. package/dist/errors/consent-required-error.js +2 -6
  64. package/dist/errors/consent-required-error.js.map +1 -1
  65. package/dist/errors/error-parser.js +14 -18
  66. package/dist/errors/error-parser.js.map +1 -1
  67. package/dist/errors/handle-unavailable-error.js +2 -7
  68. package/dist/errors/handle-unavailable-error.js.map +1 -1
  69. package/dist/errors/invalid-authorization-details-error.js +2 -6
  70. package/dist/errors/invalid-authorization-details-error.js.map +1 -1
  71. package/dist/errors/invalid-client-error.js +2 -6
  72. package/dist/errors/invalid-client-error.js.map +1 -1
  73. package/dist/errors/invalid-client-id-error.js +2 -6
  74. package/dist/errors/invalid-client-id-error.js.map +1 -1
  75. package/dist/errors/invalid-client-metadata-error.js +7 -11
  76. package/dist/errors/invalid-client-metadata-error.js.map +1 -1
  77. package/dist/errors/invalid-credentials-error.js +2 -7
  78. package/dist/errors/invalid-credentials-error.js.map +1 -1
  79. package/dist/errors/invalid-dpop-key-binding-error.js +2 -6
  80. package/dist/errors/invalid-dpop-key-binding-error.js.map +1 -1
  81. package/dist/errors/invalid-dpop-proof-error.js +2 -6
  82. package/dist/errors/invalid-dpop-proof-error.js.map +1 -1
  83. package/dist/errors/invalid-grant-error.js +2 -6
  84. package/dist/errors/invalid-grant-error.js.map +1 -1
  85. package/dist/errors/invalid-invite-code-error.d.ts +1 -1
  86. package/dist/errors/invalid-invite-code-error.d.ts.map +1 -1
  87. package/dist/errors/invalid-invite-code-error.js +2 -6
  88. package/dist/errors/invalid-invite-code-error.js.map +1 -1
  89. package/dist/errors/invalid-redirect-uri-error.js +2 -6
  90. package/dist/errors/invalid-redirect-uri-error.js.map +1 -1
  91. package/dist/errors/invalid-request-error.js +3 -7
  92. package/dist/errors/invalid-request-error.js.map +1 -1
  93. package/dist/errors/invalid-scope-error.js +2 -6
  94. package/dist/errors/invalid-scope-error.js.map +1 -1
  95. package/dist/errors/invalid-token-error.js +10 -15
  96. package/dist/errors/invalid-token-error.js.map +1 -1
  97. package/dist/errors/login-required-error.js +2 -6
  98. package/dist/errors/login-required-error.js.map +1 -1
  99. package/dist/errors/oauth-error.js +1 -9
  100. package/dist/errors/oauth-error.js.map +1 -1
  101. package/dist/errors/second-authentication-factor-required-error.js +2 -8
  102. package/dist/errors/second-authentication-factor-required-error.js.map +1 -1
  103. package/dist/errors/unauthorized-client-error.js +2 -6
  104. package/dist/errors/unauthorized-client-error.js.map +1 -1
  105. package/dist/errors/use-dpop-nonce-error.js +4 -8
  106. package/dist/errors/use-dpop-nonce-error.js.map +1 -1
  107. package/dist/errors/www-authenticate-error.js +4 -9
  108. package/dist/errors/www-authenticate-error.js.map +1 -1
  109. package/dist/index.js +14 -30
  110. package/dist/index.js.map +1 -1
  111. package/dist/lexicon/lexicon-data.js +1 -2
  112. package/dist/lexicon/lexicon-getter.js +6 -10
  113. package/dist/lexicon/lexicon-getter.js.map +1 -1
  114. package/dist/lexicon/lexicon-manager.js +10 -30
  115. package/dist/lexicon/lexicon-manager.js.map +1 -1
  116. package/dist/lexicon/lexicon-store.js +5 -10
  117. package/dist/lexicon/lexicon-store.js.map +1 -1
  118. package/dist/lib/csp/index.js +3 -8
  119. package/dist/lib/csp/index.js.map +1 -1
  120. package/dist/lib/hcaptcha.js +33 -43
  121. package/dist/lib/hcaptcha.js.map +1 -1
  122. package/dist/lib/html/build-document.js +19 -24
  123. package/dist/lib/html/build-document.js.map +1 -1
  124. package/dist/lib/html/escapers.js +10 -16
  125. package/dist/lib/html/escapers.js.map +1 -1
  126. package/dist/lib/html/html.js +1 -5
  127. package/dist/lib/html/html.js.map +1 -1
  128. package/dist/lib/html/hydration-data.js +6 -10
  129. package/dist/lib/html/hydration-data.js.map +1 -1
  130. package/dist/lib/html/index.js +3 -19
  131. package/dist/lib/html/index.js.map +1 -1
  132. package/dist/lib/html/tags.js +14 -23
  133. package/dist/lib/html/tags.js.map +1 -1
  134. package/dist/lib/html/util.js +1 -4
  135. package/dist/lib/html/util.js.map +1 -1
  136. package/dist/lib/http/accept.d.ts.map +1 -1
  137. package/dist/lib/http/accept.js +8 -8
  138. package/dist/lib/http/accept.js.map +1 -1
  139. package/dist/lib/http/context.js +1 -4
  140. package/dist/lib/http/context.js.map +1 -1
  141. package/dist/lib/http/headers.js +1 -4
  142. package/dist/lib/http/headers.js.map +1 -1
  143. package/dist/lib/http/index.js +10 -26
  144. package/dist/lib/http/index.js.map +1 -1
  145. package/dist/lib/http/method.js +1 -4
  146. package/dist/lib/http/method.js.map +1 -1
  147. package/dist/lib/http/middleware.js +11 -17
  148. package/dist/lib/http/middleware.js.map +1 -1
  149. package/dist/lib/http/parser.js +13 -20
  150. package/dist/lib/http/parser.js.map +1 -1
  151. package/dist/lib/http/path.js +1 -4
  152. package/dist/lib/http/path.js.map +1 -1
  153. package/dist/lib/http/request.d.ts.map +1 -1
  154. package/dist/lib/http/request.js +32 -47
  155. package/dist/lib/http/request.js.map +1 -1
  156. package/dist/lib/http/response.js +14 -27
  157. package/dist/lib/http/response.js.map +1 -1
  158. package/dist/lib/http/route.js +9 -12
  159. package/dist/lib/http/route.js.map +1 -1
  160. package/dist/lib/http/router.js +8 -13
  161. package/dist/lib/http/router.js.map +1 -1
  162. package/dist/lib/http/security-headers.js +10 -15
  163. package/dist/lib/http/security-headers.js.map +1 -1
  164. package/dist/lib/http/stream.js +12 -20
  165. package/dist/lib/http/stream.js.map +1 -1
  166. package/dist/lib/http/types.js +1 -2
  167. package/dist/lib/http/url.js +1 -4
  168. package/dist/lib/http/url.js.map +1 -1
  169. package/dist/lib/nsid.js +4 -8
  170. package/dist/lib/nsid.js.map +1 -1
  171. package/dist/lib/redis.js +4 -7
  172. package/dist/lib/redis.js.map +1 -1
  173. package/dist/lib/util/authorization-header.js +11 -15
  174. package/dist/lib/util/authorization-header.js.map +1 -1
  175. package/dist/lib/util/cast.js +3 -8
  176. package/dist/lib/util/cast.js.map +1 -1
  177. package/dist/lib/util/color.js +23 -32
  178. package/dist/lib/util/color.js.map +1 -1
  179. package/dist/lib/util/crypto.js +5 -10
  180. package/dist/lib/util/crypto.js.map +1 -1
  181. package/dist/lib/util/date.js +2 -6
  182. package/dist/lib/util/date.js.map +1 -1
  183. package/dist/lib/util/error.js +5 -8
  184. package/dist/lib/util/error.js.map +1 -1
  185. package/dist/lib/util/function.js +3 -8
  186. package/dist/lib/util/function.js.map +1 -1
  187. package/dist/lib/util/locale.js +3 -6
  188. package/dist/lib/util/locale.js.map +1 -1
  189. package/dist/lib/util/object.js +1 -4
  190. package/dist/lib/util/object.js.map +1 -1
  191. package/dist/lib/util/redirect-uri.js +3 -6
  192. package/dist/lib/util/redirect-uri.js.map +1 -1
  193. package/dist/lib/util/time.js +5 -9
  194. package/dist/lib/util/time.js.map +1 -1
  195. package/dist/lib/util/type.d.ts.map +1 -1
  196. package/dist/lib/util/type.js +1 -5
  197. package/dist/lib/util/type.js.map +1 -1
  198. package/dist/lib/util/ui8.js +3 -8
  199. package/dist/lib/util/ui8.js.map +1 -1
  200. package/dist/lib/util/well-known.js +1 -4
  201. package/dist/lib/util/well-known.js.map +1 -1
  202. package/dist/lib/util/zod-error.js +4 -8
  203. package/dist/lib/util/zod-error.js.map +1 -1
  204. package/dist/lib/write-form-redirect.js +9 -12
  205. package/dist/lib/write-form-redirect.js.map +1 -1
  206. package/dist/lib/write-html.js +12 -15
  207. package/dist/lib/write-html.js.map +1 -1
  208. package/dist/metadata/build-metadata.js +9 -12
  209. package/dist/metadata/build-metadata.js.map +1 -1
  210. package/dist/oauth-client.js +2 -18
  211. package/dist/oauth-client.js.map +1 -1
  212. package/dist/oauth-dpop.js +2 -18
  213. package/dist/oauth-dpop.js.map +1 -1
  214. package/dist/oauth-errors.js +24 -42
  215. package/dist/oauth-errors.js.map +1 -1
  216. package/dist/oauth-hooks.js +8 -15
  217. package/dist/oauth-hooks.js.map +1 -1
  218. package/dist/oauth-middleware.js +13 -16
  219. package/dist/oauth-middleware.js.map +1 -1
  220. package/dist/oauth-provider.js +108 -125
  221. package/dist/oauth-provider.js.map +1 -1
  222. package/dist/oauth-store.js +7 -23
  223. package/dist/oauth-store.js.map +1 -1
  224. package/dist/oauth-verifier.js +41 -53
  225. package/dist/oauth-verifier.js.map +1 -1
  226. package/dist/oidc/sub.js +2 -5
  227. package/dist/oidc/sub.js.map +1 -1
  228. package/dist/replay/replay-manager.js +6 -11
  229. package/dist/replay/replay-manager.js.map +1 -1
  230. package/dist/replay/replay-store-memory.js +5 -7
  231. package/dist/replay/replay-store-memory.js.map +1 -1
  232. package/dist/replay/replay-store-redis.js +3 -8
  233. package/dist/replay/replay-store-redis.js.map +1 -1
  234. package/dist/replay/replay-store.js +3 -8
  235. package/dist/replay/replay-store.js.map +1 -1
  236. package/dist/request/code.js +10 -15
  237. package/dist/request/code.js.map +1 -1
  238. package/dist/request/request-data.js +1 -5
  239. package/dist/request/request-data.js.map +1 -1
  240. package/dist/request/request-id.js +9 -13
  241. package/dist/request/request-id.js.map +1 -1
  242. package/dist/request/request-manager.js +61 -71
  243. package/dist/request/request-manager.js.map +1 -1
  244. package/dist/request/request-store.js +9 -27
  245. package/dist/request/request-store.js.map +1 -1
  246. package/dist/request/request-uri.js +17 -23
  247. package/dist/request/request-uri.js.map +1 -1
  248. package/dist/result/authorization-redirect-parameters.js +1 -2
  249. package/dist/result/authorization-result-authorize-page.js +1 -2
  250. package/dist/result/authorization-result-redirect.js +1 -2
  251. package/dist/router/assets/assets-manifest.d.ts.map +1 -1
  252. package/dist/router/assets/assets-manifest.js +14 -15
  253. package/dist/router/assets/assets-manifest.js.map +1 -1
  254. package/dist/router/assets/assets.d.ts.map +1 -1
  255. package/dist/router/assets/assets.js +25 -27
  256. package/dist/router/assets/assets.js.map +1 -1
  257. package/dist/router/assets/csrf.js +16 -25
  258. package/dist/router/assets/csrf.js.map +1 -1
  259. package/dist/router/assets/send-account-page.js +3 -6
  260. package/dist/router/assets/send-account-page.js.map +1 -1
  261. package/dist/router/assets/send-authorization-page.js +3 -6
  262. package/dist/router/assets/send-authorization-page.js.map +1 -1
  263. package/dist/router/assets/send-cookie-error-page.js +3 -6
  264. package/dist/router/assets/send-cookie-error-page.js.map +1 -1
  265. package/dist/router/assets/send-error-page.js +6 -9
  266. package/dist/router/assets/send-error-page.js.map +1 -1
  267. package/dist/router/assets/send-redirect.js +12 -20
  268. package/dist/router/assets/send-redirect.js.map +1 -1
  269. package/dist/router/create-account-page-middleware.js +11 -14
  270. package/dist/router/create-account-page-middleware.js.map +1 -1
  271. package/dist/router/create-api-middleware.js +83 -90
  272. package/dist/router/create-api-middleware.js.map +1 -1
  273. package/dist/router/create-authorization-page-middleware.js +43 -46
  274. package/dist/router/create-authorization-page-middleware.js.map +1 -1
  275. package/dist/router/create-oauth-middleware.js +31 -34
  276. package/dist/router/create-oauth-middleware.js.map +1 -1
  277. package/dist/router/error-handler.js +1 -2
  278. package/dist/router/middleware-options.js +1 -2
  279. package/dist/signer/access-token-payload.js +12 -15
  280. package/dist/signer/access-token-payload.js.map +1 -1
  281. package/dist/signer/api-token-payload.js +8 -11
  282. package/dist/signer/api-token-payload.js.map +1 -1
  283. package/dist/signer/signer.js +11 -17
  284. package/dist/signer/signer.js.map +1 -1
  285. package/dist/token/refresh-token.js +10 -15
  286. package/dist/token/refresh-token.js.map +1 -1
  287. package/dist/token/token-claims.js +1 -2
  288. package/dist/token/token-data.js +1 -2
  289. package/dist/token/token-id.js +10 -15
  290. package/dist/token/token-id.js.map +1 -1
  291. package/dist/token/token-manager.js +40 -51
  292. package/dist/token/token-manager.js.map +1 -1
  293. package/dist/token/token-store.js +7 -25
  294. package/dist/token/token-store.js.map +1 -1
  295. package/dist/types/authorization-response-error.js +8 -12
  296. package/dist/types/authorization-response-error.js.map +1 -1
  297. package/dist/types/color-hue.js +2 -5
  298. package/dist/types/color-hue.js.map +1 -1
  299. package/dist/types/email-otp.js +2 -5
  300. package/dist/types/email-otp.js.map +1 -1
  301. package/dist/types/email.js +6 -9
  302. package/dist/types/email.js.map +1 -1
  303. package/dist/types/handle.js +6 -9
  304. package/dist/types/handle.js.map +1 -1
  305. package/dist/types/invite-code.js +2 -5
  306. package/dist/types/invite-code.js.map +1 -1
  307. package/dist/types/par-response-error.js +5 -9
  308. package/dist/types/par-response-error.js.map +1 -1
  309. package/dist/types/password.js +3 -6
  310. package/dist/types/password.js.map +1 -1
  311. package/dist/types/rgb-color.js +7 -10
  312. package/dist/types/rgb-color.js.map +1 -1
  313. package/package.json +20 -22
  314. package/src/dpop/dpop-nonce.ts +1 -1
  315. package/src/errors/invalid-invite-code-error.ts +1 -1
  316. package/src/lib/http/accept.ts +4 -1
  317. package/src/lib/http/request.ts +4 -1
  318. package/src/lib/util/type.ts +0 -1
  319. package/src/router/assets/assets-manifest.ts +3 -1
  320. package/src/router/assets/assets.ts +2 -0
  321. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,41 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CrossOriginOpenerPolicy = exports.CrossOriginResourcePolicy = exports.CrossOriginEmbedderPolicy = void 0;
4
- exports.buildSecurityHeaders = buildSecurityHeaders;
5
- exports.setSecurityHeaders = setSecurityHeaders;
6
- const index_js_1 = require("../csp/index.js");
1
+ import { buildCsp } from '../csp/index.js';
7
2
  /**
8
3
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy COEP on MDN}
9
4
  */
10
- var CrossOriginEmbedderPolicy;
5
+ export var CrossOriginEmbedderPolicy;
11
6
  (function (CrossOriginEmbedderPolicy) {
12
7
  CrossOriginEmbedderPolicy["unsafeNone"] = "unsafe-none";
13
8
  CrossOriginEmbedderPolicy["requireCorp"] = "require-corp";
14
9
  CrossOriginEmbedderPolicy["credentialless"] = "credentialless";
15
- })(CrossOriginEmbedderPolicy || (exports.CrossOriginEmbedderPolicy = CrossOriginEmbedderPolicy = {}));
10
+ })(CrossOriginEmbedderPolicy || (CrossOriginEmbedderPolicy = {}));
16
11
  /**
17
12
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy CORP on MDN}
18
13
  */
19
- var CrossOriginResourcePolicy;
14
+ export var CrossOriginResourcePolicy;
20
15
  (function (CrossOriginResourcePolicy) {
21
16
  CrossOriginResourcePolicy["sameSite"] = "same-site";
22
17
  CrossOriginResourcePolicy["sameOrigin"] = "same-origin";
23
18
  CrossOriginResourcePolicy["crossOrigin"] = "cross-origin";
24
- })(CrossOriginResourcePolicy || (exports.CrossOriginResourcePolicy = CrossOriginResourcePolicy = {}));
19
+ })(CrossOriginResourcePolicy || (CrossOriginResourcePolicy = {}));
25
20
  /**
26
21
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy COOP on MDN}
27
22
  */
28
- var CrossOriginOpenerPolicy;
23
+ export var CrossOriginOpenerPolicy;
29
24
  (function (CrossOriginOpenerPolicy) {
30
25
  CrossOriginOpenerPolicy["unsafeNone"] = "unsafe-none";
31
26
  CrossOriginOpenerPolicy["sameOriginAllowPopups"] = "same-origin-allow-popups";
32
27
  CrossOriginOpenerPolicy["sameOrigin"] = "same-origin";
33
28
  CrossOriginOpenerPolicy["noopenerAllowPopups"] = "noopener-allow-popups";
34
- })(CrossOriginOpenerPolicy || (exports.CrossOriginOpenerPolicy = CrossOriginOpenerPolicy = {}));
35
- function* buildSecurityHeaders({ csp = { 'default-src': ["'none'"] }, coep = CrossOriginEmbedderPolicy.requireCorp, corp = CrossOriginResourcePolicy.sameOrigin, coop = CrossOriginOpenerPolicy.sameOrigin, hsts = { maxAge: 63072000 }, }) {
29
+ })(CrossOriginOpenerPolicy || (CrossOriginOpenerPolicy = {}));
30
+ export function* buildSecurityHeaders({ csp = { 'default-src': ["'none'"] }, coep = CrossOriginEmbedderPolicy.requireCorp, corp = CrossOriginResourcePolicy.sameOrigin, coop = CrossOriginOpenerPolicy.sameOrigin, hsts = { maxAge: 63072000 }, }) {
36
31
  // @NOTE Never set CSP through http-equiv meta as not all directives will
37
32
  // be honored. Always set it through the Content-Security-Policy header.
38
- const cspString = (0, index_js_1.buildCsp)(csp);
33
+ const cspString = buildCsp(csp);
39
34
  if (cspString) {
40
35
  yield ['Content-Security-Policy', cspString];
41
36
  }
@@ -52,7 +47,7 @@ function* buildSecurityHeaders({ csp = { 'default-src': ["'none'"] }, coep = Cro
52
47
  yield ['X-Content-Type-Options', 'nosniff'];
53
48
  yield ['X-XSS-Protection', '0'];
54
49
  }
55
- function setSecurityHeaders(res, options) {
50
+ export function setSecurityHeaders(res, options) {
56
51
  for (const [header, value] of buildSecurityHeaders(options)) {
57
52
  // Only set the header if it is not already set
58
53
  if (!res.hasHeader(header)) {
@@ -1 +1 @@
1
- {"version":3,"file":"security-headers.js","sourceRoot":"","sources":["../../../src/lib/http/security-headers.ts"],"names":[],"mappings":";;;AAoDA,oDA4BC;AAED,gDAUC;AA3FD,8CAA0D;AAE1D;;GAEG;AACH,IAAY,yBAIX;AAJD,WAAY,yBAAyB;IAC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uCAAuC,CAAC,CAAA;IACrE,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAA;IACxC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;IACjC,MAAM,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAA;IAC3C,MAAM,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAA;AACjC,CAAC;AAED,SAAgB,kBAAkB,CAChC,GAAmB,EACnB,OAA+B;IAE/B,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5D,+CAA+C;QAC/C,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC9B,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,MAAyC;IAC/D,IAAI,KAAK,GAAG,WAAW,MAAM,CAAC,MAAM,EAAE,CAAA;IACtC,IAAI,MAAM,CAAC,iBAAiB;QAAE,KAAK,IAAI,qBAAqB,CAAA;IAC5D,IAAI,MAAM,CAAC,OAAO;QAAE,KAAK,IAAI,WAAW,CAAA;IACxC,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import type { ServerResponse } from 'node:http'\nimport { type CspConfig, buildCsp } from '../csp/index.js'\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy COEP on MDN}\n */\nexport enum CrossOriginEmbedderPolicy {\n unsafeNone = 'unsafe-none',\n requireCorp = 'require-corp',\n credentialless = 'credentialless',\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy CORP on MDN}\n */\nexport enum CrossOriginResourcePolicy {\n sameSite = 'same-site',\n sameOrigin = 'same-origin',\n crossOrigin = 'cross-origin',\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy COOP on MDN}\n */\nexport enum CrossOriginOpenerPolicy {\n unsafeNone = 'unsafe-none',\n sameOriginAllowPopups = 'same-origin-allow-popups',\n sameOrigin = 'same-origin',\n noopenerAllowPopups = 'noopener-allow-popups',\n}\n\nexport type HTTPStrictTransportSecurityConfig = {\n maxAge: number\n includeSubDomains?: boolean\n preload?: boolean\n}\n\nexport type SecurityHeadersOptions = {\n /**\n * Defaults to `default-src: 'none'`. Use an empty object to disable CSP.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy CSP on MDN}\n */\n csp?: CspConfig\n coep?: CrossOriginEmbedderPolicy\n corp?: CrossOriginResourcePolicy\n coop?: CrossOriginOpenerPolicy\n /**\n * Defaults to 2 years. Use `false` to disable HSTS.\n */\n hsts?: HTTPStrictTransportSecurityConfig | false\n}\n\nexport function* buildSecurityHeaders({\n csp = { 'default-src': [\"'none'\"] },\n coep = CrossOriginEmbedderPolicy.requireCorp,\n corp = CrossOriginResourcePolicy.sameOrigin,\n coop = CrossOriginOpenerPolicy.sameOrigin,\n hsts = { maxAge: 63072000 },\n}: SecurityHeadersOptions): Generator<[string, string], void, unknown> {\n // @NOTE Never set CSP through http-equiv meta as not all directives will\n // be honored. Always set it through the Content-Security-Policy header.\n const cspString = buildCsp(csp)\n if (cspString) {\n yield ['Content-Security-Policy', cspString]\n }\n\n yield ['Cross-Origin-Embedder-Policy', coep]\n yield ['Cross-Origin-Resource-Policy', corp]\n yield ['Cross-Origin-Opener-Policy', coop]\n\n if (hsts) {\n yield ['Strict-Transport-Security', buildHstsValue(hsts)]\n }\n\n // @TODO make these headers configurable (?)\n yield ['Permissions-Policy', 'otp-credentials=*, document-domain=()']\n yield ['Referrer-Policy', 'same-origin']\n yield ['X-Frame-Options', 'DENY']\n yield ['X-Content-Type-Options', 'nosniff']\n yield ['X-XSS-Protection', '0']\n}\n\nexport function setSecurityHeaders(\n res: ServerResponse,\n options: SecurityHeadersOptions,\n): void {\n for (const [header, value] of buildSecurityHeaders(options)) {\n // Only set the header if it is not already set\n if (!res.hasHeader(header)) {\n res.setHeader(header, value)\n }\n }\n}\n\nfunction buildHstsValue(config: HTTPStrictTransportSecurityConfig): string {\n let value = `max-age=${config.maxAge}`\n if (config.includeSubDomains) value += '; includeSubDomains'\n if (config.preload) value += '; preload'\n return value\n}\n"]}
1
+ {"version":3,"file":"security-headers.js","sourceRoot":"","sources":["../../../src/lib/http/security-headers.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE1D;;GAEG;AACH,MAAM,CAAN,IAAY,yBAIX;AAJD,WAAY,yBAAyB;IACnC,uDAA0B,CAAA;IAC1B,yDAA4B,CAAA;IAC5B,8DAAiC,CAAA;AACnC,CAAC,EAJW,yBAAyB,KAAzB,yBAAyB,QAIpC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,yBAIX;AAJD,WAAY,yBAAyB;IACnC,mDAAsB,CAAA;IACtB,uDAA0B,CAAA;IAC1B,yDAA4B,CAAA;AAC9B,CAAC,EAJW,yBAAyB,KAAzB,yBAAyB,QAIpC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IACjC,qDAA0B,CAAA;IAC1B,6EAAkD,CAAA;IAClD,qDAA0B,CAAA;IAC1B,wEAA6C,CAAA;AAC/C,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC;AAuBD,MAAM,SAAS,CAAC,CAAC,oBAAoB,CAAC,EACpC,GAAG,GAAG,EAAE,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,EACnC,IAAI,GAAG,yBAAyB,CAAC,WAAW,EAC5C,IAAI,GAAG,yBAAyB,CAAC,UAAU,EAC3C,IAAI,GAAG,uBAAuB,CAAC,UAAU,EACzC,IAAI,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GACJ;IACvB,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QAAE,KAAK,IAAI,WAAW,CAAA;IACxC,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import type { ServerResponse } from 'node:http'\nimport { type CspConfig, buildCsp } from '../csp/index.js'\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy COEP on MDN}\n */\nexport enum CrossOriginEmbedderPolicy {\n unsafeNone = 'unsafe-none',\n requireCorp = 'require-corp',\n credentialless = 'credentialless',\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy CORP on MDN}\n */\nexport enum CrossOriginResourcePolicy {\n sameSite = 'same-site',\n sameOrigin = 'same-origin',\n crossOrigin = 'cross-origin',\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy COOP on MDN}\n */\nexport enum CrossOriginOpenerPolicy {\n unsafeNone = 'unsafe-none',\n sameOriginAllowPopups = 'same-origin-allow-popups',\n sameOrigin = 'same-origin',\n noopenerAllowPopups = 'noopener-allow-popups',\n}\n\nexport type HTTPStrictTransportSecurityConfig = {\n maxAge: number\n includeSubDomains?: boolean\n preload?: boolean\n}\n\nexport type SecurityHeadersOptions = {\n /**\n * Defaults to `default-src: 'none'`. Use an empty object to disable CSP.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy CSP on MDN}\n */\n csp?: CspConfig\n coep?: CrossOriginEmbedderPolicy\n corp?: CrossOriginResourcePolicy\n coop?: CrossOriginOpenerPolicy\n /**\n * Defaults to 2 years. Use `false` to disable HSTS.\n */\n hsts?: HTTPStrictTransportSecurityConfig | false\n}\n\nexport function* buildSecurityHeaders({\n csp = { 'default-src': [\"'none'\"] },\n coep = CrossOriginEmbedderPolicy.requireCorp,\n corp = CrossOriginResourcePolicy.sameOrigin,\n coop = CrossOriginOpenerPolicy.sameOrigin,\n hsts = { maxAge: 63072000 },\n}: SecurityHeadersOptions): Generator<[string, string], void, unknown> {\n // @NOTE Never set CSP through http-equiv meta as not all directives will\n // be honored. Always set it through the Content-Security-Policy header.\n const cspString = buildCsp(csp)\n if (cspString) {\n yield ['Content-Security-Policy', cspString]\n }\n\n yield ['Cross-Origin-Embedder-Policy', coep]\n yield ['Cross-Origin-Resource-Policy', corp]\n yield ['Cross-Origin-Opener-Policy', coop]\n\n if (hsts) {\n yield ['Strict-Transport-Security', buildHstsValue(hsts)]\n }\n\n // @TODO make these headers configurable (?)\n yield ['Permissions-Policy', 'otp-credentials=*, document-domain=()']\n yield ['Referrer-Policy', 'same-origin']\n yield ['X-Frame-Options', 'DENY']\n yield ['X-Content-Type-Options', 'nosniff']\n yield ['X-XSS-Protection', '0']\n}\n\nexport function setSecurityHeaders(\n res: ServerResponse,\n options: SecurityHeadersOptions,\n): void {\n for (const [header, value] of buildSecurityHeaders(options)) {\n // Only set the header if it is not already set\n if (!res.hasHeader(header)) {\n res.setHeader(header, value)\n }\n }\n}\n\nfunction buildHstsValue(config: HTTPStrictTransportSecurityConfig): string {\n let value = `max-age=${config.maxAge}`\n if (config.includeSubDomains) value += '; includeSubDomains'\n if (config.preload) value += '; preload'\n return value\n}\n"]}
@@ -1,21 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.decodeHttpRequest = decodeHttpRequest;
7
- exports.parseHttpRequest = parseHttpRequest;
8
- exports.flushStream = flushStream;
9
- const http_errors_1 = __importDefault(require("http-errors"));
10
- const common_1 = require("@atproto/common");
11
- const parser_js_1 = require("./parser.js");
12
- function decodeHttpRequest(req) {
1
+ import createHttpError from 'http-errors';
2
+ import { decodeStream, streamToNodeBuffer } from '@atproto/common';
3
+ import { parseContentType, parsers, } from './parser.js';
4
+ export function decodeHttpRequest(req) {
13
5
  try {
14
- return (0, common_1.decodeStream)(req, req.headers['content-encoding']);
6
+ return decodeStream(req, req.headers['content-encoding']);
15
7
  }
16
8
  catch (cause) {
17
9
  const message = cause instanceof TypeError ? cause.message : `Invalid content-encoding`;
18
- throw (0, http_errors_1.default)(415, message, { cause });
10
+ throw createHttpError(415, message, { cause });
19
11
  }
20
12
  }
21
13
  /**
@@ -24,17 +16,17 @@ function decodeHttpRequest(req) {
24
16
  *
25
17
  * @throws {TypeError} If the content-type is not valid or supported.
26
18
  */
27
- async function parseHttpRequest(req, allow) {
28
- const type = (0, parser_js_1.parseContentType)(req.headers['content-type'] ?? 'application/octet-stream');
29
- const parser = parser_js_1.parsers.find((parser) => allow.includes(parser.name) && parser.test(type.mime));
19
+ export async function parseHttpRequest(req, allow) {
20
+ const type = parseContentType(req.headers['content-type'] ?? 'application/octet-stream');
21
+ const parser = parsers.find((parser) => allow.includes(parser.name) && parser.test(type.mime));
30
22
  if (!parser) {
31
- throw (0, http_errors_1.default)(415, `Unsupported content-type: ${type.mime}`);
23
+ throw createHttpError(415, `Unsupported content-type: ${type.mime}`);
32
24
  }
33
25
  const stream = decodeHttpRequest(req);
34
- const buffer = await (0, common_1.streamToNodeBuffer)(stream);
26
+ const buffer = await streamToNodeBuffer(stream);
35
27
  return parser.parse(buffer, type);
36
28
  }
37
- async function flushStream(stream) {
29
+ export async function flushStream(stream) {
38
30
  for await (const _ of stream) {
39
31
  // Consume the stream to completion
40
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/lib/http/stream.ts"],"names":[],"mappings":";;;;;AAYA,8CAQC;AASD,4CAqBC;AAED,kCAIC;AAtDD,8DAAyC;AACzC,4CAAkE;AAClE,2CAMoB;AAEpB,SAAgB,iBAAiB,CAAC,GAAoB;IACpD,IAAI,CAAC;QACH,OAAO,IAAA,qBAAY,EAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAA;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GACX,KAAK,YAAY,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAA;QACzE,MAAM,IAAA,qBAAe,EAAC,GAAG,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAChD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AAEI,KAAK,UAAU,gBAAgB,CACpC,GAAoB,EACpB,KAAQ;IAER,MAAM,IAAI,GAAG,IAAA,4BAAgB,EAC3B,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,0BAA0B,CAC1D,CAAA;IAED,MAAM,MAAM,GAAG,mBAAO,CAAC,IAAI,CACzB,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAClE,CAAA;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAA,qBAAe,EAAC,GAAG,EAAE,6BAA6B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACtE,CAAC;IAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;IACrC,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAkB,EAAC,MAAM,CAAC,CAAA;IAC/C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAE/B,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,MAA0B;IAC1D,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QAC7B,mCAAmC;IACrC,CAAC;AACH,CAAC","sourcesContent":["import type { IncomingMessage } from 'node:http'\nimport { Readable } from 'node:stream'\nimport createHttpError from 'http-errors'\nimport { decodeStream, streamToNodeBuffer } from '@atproto/common'\nimport {\n KnownNames,\n KnownParser,\n ParserResult,\n parseContentType,\n parsers,\n} from './parser.js'\n\nexport function decodeHttpRequest(req: IncomingMessage): Readable {\n try {\n return decodeStream(req, req.headers['content-encoding'])\n } catch (cause) {\n const message =\n cause instanceof TypeError ? cause.message : `Invalid content-encoding`\n throw createHttpError(415, message, { cause })\n }\n}\n\n/**\n * Generic method that parses a stream of unknown nature (HTTP request/response,\n * socket, file, etc.), but of known mime type, into a parsed object.\n *\n * @throws {TypeError} If the content-type is not valid or supported.\n */\n\nexport async function parseHttpRequest<A extends readonly KnownNames[]>(\n req: IncomingMessage,\n allow: A,\n) {\n const type = parseContentType(\n req.headers['content-type'] ?? 'application/octet-stream',\n )\n\n const parser = parsers.find(\n (parser) => allow.includes(parser.name) && parser.test(type.mime),\n )\n\n if (!parser) {\n throw createHttpError(415, `Unsupported content-type: ${type.mime}`)\n }\n\n const stream = decodeHttpRequest(req)\n const buffer = await streamToNodeBuffer(stream)\n return parser.parse(buffer, type) as ParserResult<\n Extract<KnownParser, { name: A[number] }>\n >\n}\n\nexport async function flushStream(stream: AsyncIterable<any>): Promise<void> {\n for await (const _ of stream) {\n // Consume the stream to completion\n }\n}\n"]}
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/lib/http/stream.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,EAIL,gBAAgB,EAChB,OAAO,GACR,MAAM,aAAa,CAAA;AAEpB,MAAM,UAAU,iBAAiB,CAAC,GAAoB;IACpD,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAA;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GACX,KAAK,YAAY,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAA;QACzE,MAAM,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAChD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AAEH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAoB,EACpB,KAAQ;IAER,MAAM,IAAI,GAAG,gBAAgB,CAC3B,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,0BAA0B,CAC1D,CAAA;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CACzB,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAClE,CAAA;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,eAAe,CAAC,GAAG,EAAE,6BAA6B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACtE,CAAC;IAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;IACrC,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,CAAA;IAC/C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAE/B,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAA0B;IAC1D,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QAC7B,mCAAmC;IACrC,CAAC;AACH,CAAC","sourcesContent":["import type { IncomingMessage } from 'node:http'\nimport { Readable } from 'node:stream'\nimport createHttpError from 'http-errors'\nimport { decodeStream, streamToNodeBuffer } from '@atproto/common'\nimport {\n KnownNames,\n KnownParser,\n ParserResult,\n parseContentType,\n parsers,\n} from './parser.js'\n\nexport function decodeHttpRequest(req: IncomingMessage): Readable {\n try {\n return decodeStream(req, req.headers['content-encoding'])\n } catch (cause) {\n const message =\n cause instanceof TypeError ? cause.message : `Invalid content-encoding`\n throw createHttpError(415, message, { cause })\n }\n}\n\n/**\n * Generic method that parses a stream of unknown nature (HTTP request/response,\n * socket, file, etc.), but of known mime type, into a parsed object.\n *\n * @throws {TypeError} If the content-type is not valid or supported.\n */\n\nexport async function parseHttpRequest<A extends readonly KnownNames[]>(\n req: IncomingMessage,\n allow: A,\n) {\n const type = parseContentType(\n req.headers['content-type'] ?? 'application/octet-stream',\n )\n\n const parser = parsers.find(\n (parser) => allow.includes(parser.name) && parser.test(type.mime),\n )\n\n if (!parser) {\n throw createHttpError(415, `Unsupported content-type: ${type.mime}`)\n }\n\n const stream = decodeHttpRequest(req)\n const buffer = await streamToNodeBuffer(stream)\n return parser.parse(buffer, type) as ParserResult<\n Extract<KnownParser, { name: A[number] }>\n >\n}\n\nexport async function flushStream(stream: AsyncIterable<any>): Promise<void> {\n for await (const _ of stream) {\n // Consume the stream to completion\n }\n}\n"]}
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.urlMatch = urlMatch;
4
- function urlMatch(url, reference) {
1
+ export function urlMatch(url, reference) {
5
2
  if (reference.origin !== undefined) {
6
3
  if (url.origin !== reference.origin)
7
4
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/lib/http/url.ts"],"names":[],"mappings":";;AAMA,4BAgBC;AAhBD,SAAgB,QAAQ,CAAC,GAAQ,EAAE,SAAuB;IACxD,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACnC,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM;YAAE,OAAO,KAAK,CAAA;IACnD,CAAC;IAED,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACrC,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;IACvD,CAAC;IAED,IAAI,SAAS,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC;YAClD,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK;gBAAE,OAAO,KAAK,CAAA;QACvD,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["export type UrlReference = {\n origin?: string\n pathname?: string\n searchParams?: Iterable<readonly [string, string]> // compatible with URLSearchParams\n}\n\nexport function urlMatch(url: URL, reference: UrlReference) {\n if (reference.origin !== undefined) {\n if (url.origin !== reference.origin) return false\n }\n\n if (reference.pathname !== undefined) {\n if (url.pathname !== reference.pathname) return false\n }\n\n if (reference.searchParams !== undefined) {\n for (const [key, value] of reference.searchParams) {\n if (url.searchParams.get(key) !== value) return false\n }\n }\n\n return true\n}\n"]}
1
+ {"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/lib/http/url.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,QAAQ,CAAC,GAAQ,EAAE,SAAuB;IACxD,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACnC,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM;YAAE,OAAO,KAAK,CAAA;IACnD,CAAC;IAED,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACrC,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;IACvD,CAAC;IAED,IAAI,SAAS,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC;YAClD,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK;gBAAE,OAAO,KAAK,CAAA;QACvD,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["export type UrlReference = {\n origin?: string\n pathname?: string\n searchParams?: Iterable<readonly [string, string]> // compatible with URLSearchParams\n}\n\nexport function urlMatch(url: URL, reference: UrlReference) {\n if (reference.origin !== undefined) {\n if (url.origin !== reference.origin) return false\n }\n\n if (reference.pathname !== undefined) {\n if (url.pathname !== reference.pathname) return false\n }\n\n if (reference.searchParams !== undefined) {\n for (const [key, value] of reference.searchParams) {\n if (url.searchParams.get(key) !== value) return false\n }\n }\n\n return true\n}\n"]}
package/dist/lib/nsid.js CHANGED
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NSID = void 0;
4
- exports.parseNSID = parseNSID;
5
- const syntax_1 = require("@atproto/syntax");
6
- Object.defineProperty(exports, "NSID", { enumerable: true, get: function () { return syntax_1.NSID; } });
7
- function parseNSID(value) {
1
+ import { NSID } from '@atproto/syntax';
2
+ export { NSID };
3
+ export function parseNSID(value) {
8
4
  try {
9
- return syntax_1.NSID.parse(value);
5
+ return NSID.parse(value);
10
6
  }
11
7
  catch {
12
8
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"nsid.js","sourceRoot":"","sources":["../../src/lib/nsid.ts"],"names":[],"mappings":";;;AAGA,8BAMC;AATD,4CAAsC;AAC7B,qFADA,aAAI,OACA;AAEb,SAAgB,SAAS,CAAC,KAAa;IACrC,IAAI,CAAC;QACH,OAAO,aAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { NSID } from '@atproto/syntax'\nexport { NSID }\n\nexport function parseNSID(value: string): NSID | null {\n try {\n return NSID.parse(value)\n } catch {\n return null\n }\n}\n"]}
1
+ {"version":3,"file":"nsid.js","sourceRoot":"","sources":["../../src/lib/nsid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,CAAA;AAEf,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { NSID } from '@atproto/syntax'\nexport { NSID }\n\nexport function parseNSID(value: string): NSID | null {\n try {\n return NSID.parse(value)\n } catch {\n return null\n }\n}\n"]}
package/dist/lib/redis.js CHANGED
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRedis = createRedis;
4
- const ioredis_1 = require("ioredis");
5
- function createRedis(options) {
1
+ import { Redis } from 'ioredis';
2
+ export function createRedis(options) {
6
3
  if (typeof options === 'string') {
7
4
  const url = new URL(options.startsWith('redis://') ? options : `redis://${options}`);
8
- return new ioredis_1.Redis({
5
+ return new Redis({
9
6
  host: url.hostname,
10
7
  port: parseInt(url.port, 10),
11
8
  password: url.password,
@@ -17,7 +14,7 @@ function createRedis(options) {
17
14
  return options;
18
15
  }
19
16
  else {
20
- return new ioredis_1.Redis(options);
17
+ return new Redis(options);
21
18
  }
22
19
  }
23
20
  //# sourceMappingURL=redis.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/lib/redis.ts"],"names":[],"mappings":";;AAMA,kCAkBC;AAxBD,qCAAkD;AAMlD,SAAgB,WAAW,CAAC,OAA2B;IACrD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,OAAO,EAAE,CAChE,CAAA;QAED,OAAO,IAAI,eAAK,CAAC;YACf,IAAI,EAAE,GAAG,CAAC,QAAQ;YAClB,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC,CAAA;IACJ,CAAC;SAAM,IAAI,IAAI,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;QACpE,4EAA4E;QAC5E,+DAA+D;QAC/D,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,eAAK,CAAC,OAAO,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC","sourcesContent":["import { Redis, type RedisOptions } from 'ioredis'\n\nexport type { Redis, RedisOptions }\n\nexport type CreateRedisOptions = Redis | RedisOptions | string\n\nexport function createRedis(options: CreateRedisOptions): Redis {\n if (typeof options === 'string') {\n const url = new URL(\n options.startsWith('redis://') ? options : `redis://${options}`,\n )\n\n return new Redis({\n host: url.hostname,\n port: parseInt(url.port, 10),\n password: url.password,\n })\n } else if ('on' in options && 'call' in options && 'acl' in options) {\n // Not using \"instanceof\" here in case the options is an instance of another\n // version of ioredis (Redis is both a class and an interface).\n return options\n } else {\n return new Redis(options)\n }\n}\n"]}
1
+ {"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/lib/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,SAAS,CAAA;AAMlD,MAAM,UAAU,WAAW,CAAC,OAA2B;IACrD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,OAAO,EAAE,CAChE,CAAA;QAED,OAAO,IAAI,KAAK,CAAC;YACf,IAAI,EAAE,GAAG,CAAC,QAAQ;YAClB,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC,CAAA;IACJ,CAAC;SAAM,IAAI,IAAI,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;QACpE,4EAA4E;QAC5E,+DAA+D;QAC/D,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC","sourcesContent":["import { Redis, type RedisOptions } from 'ioredis'\n\nexport type { Redis, RedisOptions }\n\nexport type CreateRedisOptions = Redis | RedisOptions | string\n\nexport function createRedis(options: CreateRedisOptions): Redis {\n if (typeof options === 'string') {\n const url = new URL(\n options.startsWith('redis://') ? options : `redis://${options}`,\n )\n\n return new Redis({\n host: url.hostname,\n port: parseInt(url.port, 10),\n password: url.password,\n })\n } else if ('on' in options && 'call' in options && 'acl' in options) {\n // Not using \"instanceof\" here in case the options is an instance of another\n // version of ioredis (Redis is both a class and an interface).\n return options\n } else {\n return new Redis(options)\n }\n}\n"]}
@@ -1,23 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseAuthorizationHeader = exports.authorizationHeaderSchema = void 0;
4
- const zod_1 = require("zod");
5
- const oauth_types_1 = require("@atproto/oauth-types");
6
- const invalid_request_error_js_1 = require("../../errors/invalid-request-error.js");
7
- const www_authenticate_error_js_1 = require("../../errors/www-authenticate-error.js");
8
- exports.authorizationHeaderSchema = zod_1.z.tuple([
9
- oauth_types_1.oauthTokenTypeSchema,
10
- oauth_types_1.oauthAccessTokenSchema,
1
+ import { z } from 'zod';
2
+ import { oauthAccessTokenSchema, oauthTokenTypeSchema, } from '@atproto/oauth-types';
3
+ import { InvalidRequestError } from '../../errors/invalid-request-error.js';
4
+ import { WWWAuthenticateError } from '../../errors/www-authenticate-error.js';
5
+ export const authorizationHeaderSchema = z.tuple([
6
+ oauthTokenTypeSchema,
7
+ oauthAccessTokenSchema,
11
8
  ]);
12
- const parseAuthorizationHeader = (header) => {
9
+ export const parseAuthorizationHeader = (header) => {
13
10
  if (typeof header !== 'string') {
14
- throw new www_authenticate_error_js_1.WWWAuthenticateError('invalid_request', 'Authorization header required', { Bearer: {}, DPoP: {} });
11
+ throw new WWWAuthenticateError('invalid_request', 'Authorization header required', { Bearer: {}, DPoP: {} });
15
12
  }
16
- const parsed = exports.authorizationHeaderSchema.safeParse(header.split(' '));
13
+ const parsed = authorizationHeaderSchema.safeParse(header.split(' '));
17
14
  if (!parsed.success) {
18
- throw new invalid_request_error_js_1.InvalidRequestError('Invalid authorization header');
15
+ throw new InvalidRequestError('Invalid authorization header');
19
16
  }
20
17
  return parsed.data;
21
18
  };
22
- exports.parseAuthorizationHeader = parseAuthorizationHeader;
23
19
  //# sourceMappingURL=authorization-header.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authorization-header.js","sourceRoot":"","sources":["../../../src/lib/util/authorization-header.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,sDAG6B;AAC7B,oFAA2E;AAC3E,sFAA6E;AAEhE,QAAA,yBAAyB,GAAG,OAAC,CAAC,KAAK,CAAC;IAC/C,kCAAoB;IACpB,oCAAsB;CACvB,CAAC,CAAA;AAEK,MAAM,wBAAwB,GAAG,CAAC,MAAe,EAAE,EAAE;IAC1D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,gDAAoB,CAC5B,iBAAiB,EACjB,+BAA+B,EAC/B,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CACzB,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,iCAAyB,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IACrE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,8CAAmB,CAAC,8BAA8B,CAAC,CAAA;IAC/D,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAA;AACpB,CAAC,CAAA;AAdY,QAAA,wBAAwB,4BAcpC","sourcesContent":["import { z } from 'zod'\nimport {\n oauthAccessTokenSchema,\n oauthTokenTypeSchema,\n} from '@atproto/oauth-types'\nimport { InvalidRequestError } from '../../errors/invalid-request-error.js'\nimport { WWWAuthenticateError } from '../../errors/www-authenticate-error.js'\n\nexport const authorizationHeaderSchema = z.tuple([\n oauthTokenTypeSchema,\n oauthAccessTokenSchema,\n])\n\nexport const parseAuthorizationHeader = (header: unknown) => {\n if (typeof header !== 'string') {\n throw new WWWAuthenticateError(\n 'invalid_request',\n 'Authorization header required',\n { Bearer: {}, DPoP: {} },\n )\n }\n\n const parsed = authorizationHeaderSchema.safeParse(header.split(' '))\n if (!parsed.success) {\n throw new InvalidRequestError('Invalid authorization header')\n }\n return parsed.data\n}\n"]}
1
+ {"version":3,"file":"authorization-header.js","sourceRoot":"","sources":["../../../src/lib/util/authorization-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAA;AAE7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC;IAC/C,oBAAoB;IACpB,sBAAsB;CACvB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAe,EAAE,EAAE;IAC1D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,oBAAoB,CAC5B,iBAAiB,EACjB,+BAA+B,EAC/B,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CACzB,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,yBAAyB,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IACrE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,mBAAmB,CAAC,8BAA8B,CAAC,CAAA;IAC/D,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAA;AACpB,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\nimport {\n oauthAccessTokenSchema,\n oauthTokenTypeSchema,\n} from '@atproto/oauth-types'\nimport { InvalidRequestError } from '../../errors/invalid-request-error.js'\nimport { WWWAuthenticateError } from '../../errors/www-authenticate-error.js'\n\nexport const authorizationHeaderSchema = z.tuple([\n oauthTokenTypeSchema,\n oauthAccessTokenSchema,\n])\n\nexport const parseAuthorizationHeader = (header: unknown) => {\n if (typeof header !== 'string') {\n throw new WWWAuthenticateError(\n 'invalid_request',\n 'Authorization header required',\n { Bearer: {}, DPoP: {} },\n )\n }\n\n const parsed = authorizationHeaderSchema.safeParse(header.split(' '))\n if (!parsed.success) {\n throw new InvalidRequestError('Invalid authorization header')\n }\n return parsed.data\n}\n"]}
@@ -1,17 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asArray = asArray;
4
- exports.asURL = asURL;
5
- exports.ifURL = ifURL;
6
- function asArray(value) {
1
+ export function asArray(value) {
7
2
  if (value == null)
8
3
  return [];
9
4
  return Array.isArray(value) ? value : [value];
10
5
  }
11
- function asURL(value) {
6
+ export function asURL(value) {
12
7
  return new URL(value);
13
8
  }
14
- function ifURL(value) {
9
+ export function ifURL(value) {
15
10
  try {
16
11
  return asURL(value);
17
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cast.js","sourceRoot":"","sources":["../../../src/lib/util/cast.ts"],"names":[],"mappings":";;AAAA,0BAGC;AAED,sBAEC;AAED,sBAQC;AAjBD,SAAgB,OAAO,CAAI,KAAc;IACvC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAA;IAC5B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC;AAED,SAAgB,KAAK,CAAC,KAA0C;IAC9D,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;AACvB,CAAC;AAED,SAAgB,KAAK,CACnB,KAA0C;IAE1C,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC","sourcesContent":["export function asArray<T>(value: T | T[]): T[] {\n if (value == null) return []\n return Array.isArray(value) ? value : [value]\n}\n\nexport function asURL(value: string | { toString: () => string }): URL {\n return new URL(value)\n}\n\nexport function ifURL(\n value: string | { toString: () => string },\n): URL | undefined {\n try {\n return asURL(value)\n } catch {\n return undefined\n }\n}\n"]}
1
+ {"version":3,"file":"cast.js","sourceRoot":"","sources":["../../../src/lib/util/cast.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAI,KAAc;IACvC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAA;IAC5B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAA0C;IAC9D,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,KAAK,CACnB,KAA0C;IAE1C,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC","sourcesContent":["export function asArray<T>(value: T | T[]): T[] {\n if (value == null) return []\n return Array.isArray(value) ? value : [value]\n}\n\nexport function asURL(value: string | { toString: () => string }): URL {\n return new URL(value)\n}\n\nexport function ifURL(\n value: string | { toString: () => string },\n): URL | undefined {\n try {\n return asURL(value)\n } catch {\n return undefined\n }\n}\n"]}
@@ -1,14 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseColor = parseColor;
4
- exports.parseHexColor = parseHexColor;
5
- exports.parseRgbColor = parseRgbColor;
6
- exports.parseRgbaColor = parseRgbaColor;
7
- exports.pickContrastColor = pickContrastColor;
8
- exports.hslToRgb = hslToRgb;
9
- exports.extractHue = extractHue;
10
- const ui8_js_1 = require("./ui8.js");
11
- function parseColor(color) {
1
+ import { parseUi8Dec, parseUi8Hex } from './ui8.js';
2
+ export function parseColor(color) {
12
3
  if (color.startsWith('#')) {
13
4
  return parseHexColor(color);
14
5
  }
@@ -21,53 +12,53 @@ function parseColor(color) {
21
12
  // Should never happen (as long as the input is a validated WebColor)
22
13
  throw new TypeError(`Invalid color value: ${color}`);
23
14
  }
24
- function parseHexColor(v) {
15
+ export function parseHexColor(v) {
25
16
  // parseInt('az', 16) does not return NaN so we need to check the format
26
17
  if (!/^#[0-9a-f]+$/i.test(v)) {
27
18
  throw new TypeError(`Invalid hex color value: ${v}`);
28
19
  }
29
20
  if (v.length === 4 || v.length === 5) {
30
- const r = (0, ui8_js_1.parseUi8Hex)(v[1].repeat(2));
31
- const g = (0, ui8_js_1.parseUi8Hex)(v[2].repeat(2));
32
- const b = (0, ui8_js_1.parseUi8Hex)(v[3].repeat(2));
33
- const a = v.length > 4 ? (0, ui8_js_1.parseUi8Hex)(v[4].repeat(2)) : undefined;
21
+ const r = parseUi8Hex(v[1].repeat(2));
22
+ const g = parseUi8Hex(v[2].repeat(2));
23
+ const b = parseUi8Hex(v[3].repeat(2));
24
+ const a = v.length > 4 ? parseUi8Hex(v[4].repeat(2)) : undefined;
34
25
  return a == null ? { r, g, b } : { r, g, b, a };
35
26
  }
36
27
  if (v.length === 7 || v.length === 9) {
37
- const r = (0, ui8_js_1.parseUi8Hex)(v.slice(1, 3));
38
- const g = (0, ui8_js_1.parseUi8Hex)(v.slice(3, 5));
39
- const b = (0, ui8_js_1.parseUi8Hex)(v.slice(5, 7));
40
- const a = v.length > 8 ? (0, ui8_js_1.parseUi8Hex)(v.slice(7, 9)) : undefined;
28
+ const r = parseUi8Hex(v.slice(1, 3));
29
+ const g = parseUi8Hex(v.slice(3, 5));
30
+ const b = parseUi8Hex(v.slice(5, 7));
31
+ const a = v.length > 8 ? parseUi8Hex(v.slice(7, 9)) : undefined;
41
32
  return a == null ? { r, g, b } : { r, g, b, a };
42
33
  }
43
34
  throw new TypeError(`Invalid hex color value: ${v}`);
44
35
  }
45
- function parseRgbColor(v) {
36
+ export function parseRgbColor(v) {
46
37
  const matches = v.match(/^\s*rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/);
47
38
  if (!matches)
48
39
  throw new TypeError(`Invalid rgb color value: ${v}`);
49
- const r = (0, ui8_js_1.parseUi8Dec)(matches[1]);
50
- const g = (0, ui8_js_1.parseUi8Dec)(matches[2]);
51
- const b = (0, ui8_js_1.parseUi8Dec)(matches[3]);
40
+ const r = parseUi8Dec(matches[1]);
41
+ const g = parseUi8Dec(matches[2]);
42
+ const b = parseUi8Dec(matches[3]);
52
43
  return { r, g, b };
53
44
  }
54
- function parseRgbaColor(v) {
45
+ export function parseRgbaColor(v) {
55
46
  const matches = v.match(/^\s*rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/);
56
47
  if (!matches)
57
48
  throw new TypeError(`Invalid rgba color value: ${v}`);
58
- const r = (0, ui8_js_1.parseUi8Dec)(matches[1]);
59
- const g = (0, ui8_js_1.parseUi8Dec)(matches[2]);
60
- const b = (0, ui8_js_1.parseUi8Dec)(matches[3]);
61
- const a = (0, ui8_js_1.parseUi8Dec)(matches[4]);
49
+ const r = parseUi8Dec(matches[1]);
50
+ const g = parseUi8Dec(matches[2]);
51
+ const b = parseUi8Dec(matches[3]);
52
+ const a = parseUi8Dec(matches[4]);
62
53
  return { r, g, b, a };
63
54
  }
64
55
  /**
65
56
  * Return the color that has the best contrast with the reference color.
66
57
  */
67
- function pickContrastColor(ref, a, b) {
58
+ export function pickContrastColor(ref, a, b) {
68
59
  return computeContrastRatio(ref, a) > computeContrastRatio(ref, b) ? a : b;
69
60
  }
70
- function hslToRgb(input) {
61
+ export function hslToRgb(input) {
71
62
  const { h, s, l } = input;
72
63
  // Achromatic (gray)
73
64
  if (s === 0) {
@@ -117,7 +108,7 @@ function computeContrastRatio(a, b) {
117
108
  const [lighter, darker] = aLum > bLum ? [aLum, bLum] : [bLum, aLum];
118
109
  return (lighter + 0.05) / (darker + 0.05);
119
110
  }
120
- function extractHue(input) {
111
+ export function extractHue(input) {
121
112
  const r = input.r / 255;
122
113
  const g = input.g / 255;
123
114
  const b = input.b / 255;
@@ -1 +1 @@
1
- {"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/lib/util/color.ts"],"names":[],"mappings":";;AASA,gCAeC;AAED,sCAuBC;AAED,sCAQC;AAED,wCAWC;AAKD,8CAEC;AAID,4BA6BC;AAyBD,gCA8BC;AAvKD,qCAAmD;AASnD,SAAgB,UAAU,CAAC,KAAa;IACtC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,aAAa,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,IAAI,KAAK,CAAC,UA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AAC;QACD,6EAA6E;QAC7E,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;YAChC,MAAM,KAAK,GAAG,GAAG,GAAG,EAAE,CAAA;YACtB,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { parseUi8Dec, parseUi8Hex } from './ui8.js'\n\nexport type RgbColor = { r: number; g: number; b: number }\nexport type HslColor = { h: number; s: number; l: number }\nexport type RgbaColor = { r: number; g: number; b: number; a: number }\nexport type HslaColor = { h: number; s: number; l: number; a: number }\n\nexport type Color = RgbColor | HslColor | RgbaColor | HslaColor\n\nexport function parseColor(color: string): RgbColor | RgbaColor {\n if (color.startsWith('#')) {\n return parseHexColor(color)\n }\n\n if (color.startsWith('rgba(')) {\n return parseRgbaColor(color)\n }\n\n if (color.startsWith('rgb(')) {\n return parseRgbColor(color)\n }\n\n // Should never happen (as long as the input is a validated WebColor)\n throw new TypeError(`Invalid color value: ${color}`)\n}\n\nexport function parseHexColor(v: string): RgbColor | RgbaColor {\n // parseInt('az', 16) does not return NaN so we need to check the format\n if (!/^#[0-9a-f]+$/i.test(v)) {\n throw new TypeError(`Invalid hex color value: ${v}`)\n }\n\n if (v.length === 4 || v.length === 5) {\n const r = parseUi8Hex(v[1].repeat(2))\n const g = parseUi8Hex(v[2].repeat(2))\n const b = parseUi8Hex(v[3].repeat(2))\n const a = v.length > 4 ? parseUi8Hex(v[4].repeat(2)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n if (v.length === 7 || v.length === 9) {\n const r = parseUi8Hex(v.slice(1, 3))\n const g = parseUi8Hex(v.slice(3, 5))\n const b = parseUi8Hex(v.slice(5, 7))\n const a = v.length > 8 ? parseUi8Hex(v.slice(7, 9)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n throw new TypeError(`Invalid hex color value: ${v}`)\n}\n\nexport function parseRgbColor(v: string): RgbColor {\n const matches = v.match(/^\\s*rgb\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/)\n if (!matches) throw new TypeError(`Invalid rgb color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n return { r, g, b }\n}\n\nexport function parseRgbaColor(v: string): RgbaColor {\n const matches = v.match(\n /^\\s*rgba\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/,\n )\n if (!matches) throw new TypeError(`Invalid rgba color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n const a = parseUi8Dec(matches[4])\n return { r, g, b, a }\n}\n\n/**\n * Return the color that has the best contrast with the reference color.\n */\nexport function pickContrastColor(ref: RgbColor, a: RgbColor, b: RgbColor) {\n return computeContrastRatio(ref, a) > computeContrastRatio(ref, b) ? a : b\n}\n\nexport function hslToRgb({ h, s, l }: HslColor): RgbColor\nexport function hslToRgb({ h, s, l, a }: HslaColor): RgbaColor\nexport function hslToRgb(input: HslaColor | HslColor): RgbColor | RgbaColor {\n const { h, s, l } = input\n\n // Achromatic (gray)\n if (s === 0) {\n const gray = Math.round(l * 255)\n return 'a' in input\n ? { r: gray, g: gray, b: gray, a: input.a }\n : { r: gray, g: gray, b: gray }\n }\n\n const hueToRgb = (p: number, q: number, t: number): number => {\n if (t < 0) t += 1\n if (t > 1) t -= 1\n if (t < 1 / 6) return p + (q - p) * 6 * t\n if (t < 1 / 2) return q\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6\n return p\n }\n\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s\n const p = 2 * l - q\n const hNorm = h / 360\n\n const r = Math.round(hueToRgb(p, q, hNorm + 1 / 3) * 255)\n const g = Math.round(hueToRgb(p, q, hNorm) * 255)\n const b = Math.round(hueToRgb(p, q, hNorm - 1 / 3) * 255)\n\n return 'a' in input ? { r, g, b, a: input.a } : { r, g, b }\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef}\n */\nfunction relativeLuminance(color: HslColor | RgbColor) {\n const { r, g, b } = 'h' in color ? hslToRgb(color) : color\n return rgbLum(r) * 0.2126 + rgbLum(g) * 0.7152 + rgbLum(b) * 0.0722\n}\n\nfunction rgbLum(value) {\n const rgb = value / 255\n return rgb < 0.03928 ? rgb / 12.92 : Math.pow((rgb + 0.055) / 1.055, 2.4)\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef}\n */\nfunction computeContrastRatio(a: RgbColor, b: RgbColor) {\n const aLum = relativeLuminance(a)\n const bLum = relativeLuminance(b)\n const [lighter, darker] = aLum > bLum ? [aLum, bLum] : [bLum, aLum]\n return (lighter + 0.05) / (darker + 0.05)\n}\n\nexport function extractHue(input: RgbColor): number {\n const r = input.r / 255\n const g = input.g / 255\n const b = input.b / 255\n\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n\n const chroma = max - min\n\n switch (max) {\n case min:\n return 0 // Achromatic\n case r: {\n const segment = (g - b) / chroma\n const shift = segment < 0 ? 360 / 60 : 0 / 60\n return 60 * (segment + shift)\n }\n case g: {\n const segment = (b - r) / chroma\n const shift = 120 / 60\n return 60 * (segment + shift)\n }\n // \"default\" needed for type safety. In practice, should be same as \"case b:\"\n default: {\n const segment = (r - g) / chroma\n const shift = 240 / 60\n return 60 * (segment + shift)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/lib/util/color.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AASnD,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAI,K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CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;YAChC,MAAM,KAAK,GAAG,GAAG,GAAG,EAAE,CAAA;YACtB,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,CAAA;QAC/B,CAAC;QACD,6EAA6E;QAC7E,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;YAChC,MAAM,KAAK,GAAG,GAAG,GAAG,EAAE,CAAA;YACtB,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { parseUi8Dec, parseUi8Hex } from './ui8.js'\n\nexport type RgbColor = { r: number; g: number; b: number }\nexport type HslColor = { h: number; s: number; l: number }\nexport type RgbaColor = { r: number; g: number; b: number; a: number }\nexport type HslaColor = { h: number; s: number; l: number; a: number }\n\nexport type Color = RgbColor | HslColor | RgbaColor | HslaColor\n\nexport function parseColor(color: string): RgbColor | RgbaColor {\n if (color.startsWith('#')) {\n return parseHexColor(color)\n }\n\n if (color.startsWith('rgba(')) {\n return parseRgbaColor(color)\n }\n\n if (color.startsWith('rgb(')) {\n return parseRgbColor(color)\n }\n\n // Should never happen (as long as the input is a validated WebColor)\n throw new TypeError(`Invalid color value: ${color}`)\n}\n\nexport function parseHexColor(v: string): RgbColor | RgbaColor {\n // parseInt('az', 16) does not return NaN so we need to check the format\n if (!/^#[0-9a-f]+$/i.test(v)) {\n throw new TypeError(`Invalid hex color value: ${v}`)\n }\n\n if (v.length === 4 || v.length === 5) {\n const r = parseUi8Hex(v[1].repeat(2))\n const g = parseUi8Hex(v[2].repeat(2))\n const b = parseUi8Hex(v[3].repeat(2))\n const a = v.length > 4 ? parseUi8Hex(v[4].repeat(2)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n if (v.length === 7 || v.length === 9) {\n const r = parseUi8Hex(v.slice(1, 3))\n const g = parseUi8Hex(v.slice(3, 5))\n const b = parseUi8Hex(v.slice(5, 7))\n const a = v.length > 8 ? parseUi8Hex(v.slice(7, 9)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n throw new TypeError(`Invalid hex color value: ${v}`)\n}\n\nexport function parseRgbColor(v: string): RgbColor {\n const matches = v.match(/^\\s*rgb\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/)\n if (!matches) throw new TypeError(`Invalid rgb color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n return { r, g, b }\n}\n\nexport function parseRgbaColor(v: string): RgbaColor {\n const matches = v.match(\n /^\\s*rgba\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/,\n )\n if (!matches) throw new TypeError(`Invalid rgba color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n const a = parseUi8Dec(matches[4])\n return { r, g, b, a }\n}\n\n/**\n * Return the color that has the best contrast with the reference color.\n */\nexport function pickContrastColor(ref: RgbColor, a: RgbColor, b: RgbColor) {\n return computeContrastRatio(ref, a) > computeContrastRatio(ref, b) ? a : b\n}\n\nexport function hslToRgb({ h, s, l }: HslColor): RgbColor\nexport function hslToRgb({ h, s, l, a }: HslaColor): RgbaColor\nexport function hslToRgb(input: HslaColor | HslColor): RgbColor | RgbaColor {\n const { h, s, l } = input\n\n // Achromatic (gray)\n if (s === 0) {\n const gray = Math.round(l * 255)\n return 'a' in input\n ? { r: gray, g: gray, b: gray, a: input.a }\n : { r: gray, g: gray, b: gray }\n }\n\n const hueToRgb = (p: number, q: number, t: number): number => {\n if (t < 0) t += 1\n if (t > 1) t -= 1\n if (t < 1 / 6) return p + (q - p) * 6 * t\n if (t < 1 / 2) return q\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6\n return p\n }\n\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s\n const p = 2 * l - q\n const hNorm = h / 360\n\n const r = Math.round(hueToRgb(p, q, hNorm + 1 / 3) * 255)\n const g = Math.round(hueToRgb(p, q, hNorm) * 255)\n const b = Math.round(hueToRgb(p, q, hNorm - 1 / 3) * 255)\n\n return 'a' in input ? { r, g, b, a: input.a } : { r, g, b }\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef}\n */\nfunction relativeLuminance(color: HslColor | RgbColor) {\n const { r, g, b } = 'h' in color ? hslToRgb(color) : color\n return rgbLum(r) * 0.2126 + rgbLum(g) * 0.7152 + rgbLum(b) * 0.0722\n}\n\nfunction rgbLum(value) {\n const rgb = value / 255\n return rgb < 0.03928 ? rgb / 12.92 : Math.pow((rgb + 0.055) / 1.055, 2.4)\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef}\n */\nfunction computeContrastRatio(a: RgbColor, b: RgbColor) {\n const aLum = relativeLuminance(a)\n const bLum = relativeLuminance(b)\n const [lighter, darker] = aLum > bLum ? [aLum, bLum] : [bLum, aLum]\n return (lighter + 0.05) / (darker + 0.05)\n}\n\nexport function extractHue(input: RgbColor): number {\n const r = input.r / 255\n const g = input.g / 255\n const b = input.b / 255\n\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n\n const chroma = max - min\n\n switch (max) {\n case min:\n return 0 // Achromatic\n case r: {\n const segment = (g - b) / chroma\n const shift = segment < 0 ? 360 / 60 : 0 / 60\n return 60 * (segment + shift)\n }\n case g: {\n const segment = (b - r) / chroma\n const shift = 120 / 60\n return 60 * (segment + shift)\n }\n // \"default\" needed for type safety. In practice, should be same as \"case b:\"\n default: {\n const segment = (r - g) / chroma\n const shift = 240 / 60\n return 60 * (segment + shift)\n }\n }\n}\n"]}
@@ -1,25 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERIFY_ALGOS = void 0;
4
- exports.randomBuffer = randomBuffer;
5
- exports.randomHexId = randomHexId;
6
- const node_crypto_1 = require("node:crypto");
7
- async function randomBuffer(bytesLength = 16) {
1
+ import { randomBytes } from 'node:crypto';
2
+ export async function randomBuffer(bytesLength = 16) {
8
3
  return new Promise((resolve, reject) => {
9
- (0, node_crypto_1.randomBytes)(bytesLength, (err, buf) => {
4
+ randomBytes(bytesLength, (err, buf) => {
10
5
  if (err)
11
6
  return reject(err);
12
7
  resolve(buf);
13
8
  });
14
9
  });
15
10
  }
16
- async function randomHexId(bytesLength = 16) {
11
+ export async function randomHexId(bytesLength = 16) {
17
12
  const buffer = await randomBuffer(bytesLength);
18
13
  return buffer.toString('hex');
19
14
  }
20
15
  // Basically all algorithms supported by "jose"'s jwtVerify().
21
16
  // @TODO Is there a way to get this list from the runtime instead of hardcoding it?
22
- exports.VERIFY_ALGOS = [
17
+ export const VERIFY_ALGOS = [
23
18
  'RS256',
24
19
  'RS384',
25
20
  'RS512',
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/lib/util/crypto.ts"],"names":[],"mappings":";;;AAEA,oCAOC;AAED,kCAGC;AAdD,6CAAyC;AAElC,KAAK,UAAU,YAAY,CAAC,WAAW,GAAG,EAAE;IACjD,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,IAAA,yBAAW,EAAC,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACpC,IAAI,GAAG;gBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;YAC3B,OAAO,CAAC,GAAG,CAAC,CAAA;QACd,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,WAAW,GAAG,EAAE;IAChD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,CAAA;IAC9C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC/B,CAAC;AAED,8DAA8D;AAC9D,mFAAmF;AACtE,QAAA,YAAY,GAAG;IAC1B,OAAO;IACP,OAAO;IACP,OAAO;IAEP,OAAO;IACP,OAAO;IACP,OAAO;IAEP,OAAO;IACP,QAAQ;IACR,OAAO;IACP,OAAO;CACC,CAAA","sourcesContent":["import { randomBytes } from 'node:crypto'\n\nexport async function randomBuffer(bytesLength = 16) {\n return new Promise<Buffer>((resolve, reject) => {\n randomBytes(bytesLength, (err, buf) => {\n if (err) return reject(err)\n resolve(buf)\n })\n })\n}\n\nexport async function randomHexId(bytesLength = 16) {\n const buffer = await randomBuffer(bytesLength)\n return buffer.toString('hex')\n}\n\n// Basically all algorithms supported by \"jose\"'s jwtVerify().\n// @TODO Is there a way to get this list from the runtime instead of hardcoding it?\nexport const VERIFY_ALGOS = [\n 'RS256',\n 'RS384',\n 'RS512',\n\n 'PS256',\n 'PS384',\n 'PS512',\n\n 'ES256',\n 'ES256K',\n 'ES384',\n 'ES512',\n] as const\n"]}
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/lib/util/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAW,GAAG,EAAE;IACjD,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,WAAW,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACpC,IAAI,GAAG;gBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;YAC3B,OAAO,CAAC,GAAG,CAAC,CAAA;QACd,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,WAAW,GAAG,EAAE;IAChD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,CAAA;IAC9C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC/B,CAAC;AAED,8DAA8D;AAC9D,mFAAmF;AACnF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO;IACP,OAAO;IACP,OAAO;IAEP,OAAO;IACP,OAAO;IACP,OAAO;IAEP,OAAO;IACP,QAAQ;IACR,OAAO;IACP,OAAO;CACC,CAAA","sourcesContent":["import { randomBytes } from 'node:crypto'\n\nexport async function randomBuffer(bytesLength = 16) {\n return new Promise<Buffer>((resolve, reject) => {\n randomBytes(bytesLength, (err, buf) => {\n if (err) return reject(err)\n resolve(buf)\n })\n })\n}\n\nexport async function randomHexId(bytesLength = 16) {\n const buffer = await randomBuffer(bytesLength)\n return buffer.toString('hex')\n}\n\n// Basically all algorithms supported by \"jose\"'s jwtVerify().\n// @TODO Is there a way to get this list from the runtime instead of hardcoding it?\nexport const VERIFY_ALGOS = [\n 'RS256',\n 'RS384',\n 'RS512',\n\n 'PS256',\n 'PS384',\n 'PS512',\n\n 'ES256',\n 'ES256K',\n 'ES384',\n 'ES512',\n] as const\n"]}
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dateToEpoch = dateToEpoch;
4
- exports.dateToRelativeSeconds = dateToRelativeSeconds;
5
- function dateToEpoch(date = new Date()) {
1
+ export function dateToEpoch(date = new Date()) {
6
2
  return Math.floor(date.getTime() / 1000);
7
3
  }
8
- function dateToRelativeSeconds(date) {
4
+ export function dateToRelativeSeconds(date) {
9
5
  return Math.floor((date.getTime() - Date.now()) / 1000);
10
6
  }
11
7
  //# sourceMappingURL=date.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/lib/util/date.ts"],"names":[],"mappings":";;AAAA,kCAEC;AAED,sDAEC;AAND,SAAgB,WAAW,CAAC,OAAa,IAAI,IAAI,EAAE;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;AAC1C,CAAC;AAED,SAAgB,qBAAqB,CAAC,IAAU;IAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;AACzD,CAAC","sourcesContent":["export function dateToEpoch(date: Date = new Date()) {\n return Math.floor(date.getTime() / 1000)\n}\n\nexport function dateToRelativeSeconds(date: Date) {\n return Math.floor((date.getTime() - Date.now()) / 1000)\n}\n"]}
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/lib/util/date.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,OAAa,IAAI,IAAI,EAAE;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;AAC1C,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAU;IAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;AACzD,CAAC","sourcesContent":["export function dateToEpoch(date: Date = new Date()) {\n return Math.floor(date.getTime() / 1000)\n}\n\nexport function dateToRelativeSeconds(date: Date) {\n return Math.floor((date.getTime() - Date.now()) / 1000)\n}\n"]}
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatError = formatError;
4
- const zod_1 = require("zod");
5
- const zod_error_js_1 = require("./zod-error.js");
6
- function formatError(err, prefix) {
7
- if (err instanceof zod_1.ZodError)
8
- return (0, zod_error_js_1.formatZodError)(err, prefix);
1
+ import { ZodError } from 'zod';
2
+ import { formatZodError } from './zod-error.js';
3
+ export function formatError(err, prefix) {
4
+ if (err instanceof ZodError)
5
+ return formatZodError(err, prefix);
9
6
  return prefix;
10
7
  }
11
8
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/lib/util/error.ts"],"names":[],"mappings":";;AAGA,kCAGC;AAND,6BAA8B;AAC9B,iDAA+C;AAE/C,SAAgB,WAAW,CAAC,GAAY,EAAE,MAAc;IACtD,IAAI,GAAG,YAAY,cAAQ;QAAE,OAAO,IAAA,6BAAc,EAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC/D,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { ZodError } from 'zod'\nimport { formatZodError } from './zod-error.js'\n\nexport function formatError(err: unknown, prefix: string): string {\n if (err instanceof ZodError) return formatZodError(err, prefix)\n return prefix\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/lib/util/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,UAAU,WAAW,CAAC,GAAY,EAAE,MAAc;IACtD,IAAI,GAAG,YAAY,QAAQ;QAAE,OAAO,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC/D,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { ZodError } from 'zod'\nimport { formatZodError } from './zod-error.js'\n\nexport function formatError(err: unknown, prefix: string): string {\n if (err instanceof ZodError) return formatZodError(err, prefix)\n return prefix\n}\n"]}
@@ -1,12 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.callAsync = callAsync;
4
- exports.invokeOnce = invokeOnce;
5
- exports.includedIn = includedIn;
6
- async function callAsync(fn, ...args) {
1
+ export async function callAsync(fn, ...args) {
7
2
  return (await fn?.(...args));
8
3
  }
9
- function invokeOnce(fn) {
4
+ export function invokeOnce(fn) {
10
5
  let fnNullable = fn;
11
6
  return function (...args) {
12
7
  if (fnNullable) {
@@ -17,7 +12,7 @@ function invokeOnce(fn) {
17
12
  throw new Error('Function called multiple times');
18
13
  };
19
14
  }
20
- function includedIn(value) {
15
+ export function includedIn(value) {
21
16
  return this.includes(value);
22
17
  }
23
18
  //# sourceMappingURL=function.js.map