@shware/http 2.11.4 → 2.12.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 (236) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +13 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +13 -0
  3. package/dist/cache/index.cjs +5 -30
  4. package/dist/cache/index.cjs.map +1 -1
  5. package/dist/cache/index.d.cts +7 -5
  6. package/dist/cache/index.d.cts.map +1 -0
  7. package/dist/cache/index.d.mts +11 -0
  8. package/dist/cache/index.d.mts.map +1 -0
  9. package/dist/cache/index.mjs +5 -6
  10. package/dist/cache/index.mjs.map +1 -1
  11. package/dist/error/detail.cjs +100 -90
  12. package/dist/error/detail.cjs.map +1 -1
  13. package/dist/error/detail.d.cts +77 -78
  14. package/dist/error/detail.d.cts.map +1 -0
  15. package/dist/error/detail.d.mts +108 -0
  16. package/dist/error/detail.d.mts.map +1 -0
  17. package/dist/error/detail.mjs +99 -65
  18. package/dist/error/detail.mjs.map +1 -1
  19. package/dist/error/i18n/en-us.cjs +5 -29
  20. package/dist/error/i18n/en-us.cjs.map +1 -1
  21. package/dist/error/i18n/en-us.d.cts +3 -1
  22. package/dist/error/i18n/en-us.d.cts.map +1 -0
  23. package/dist/error/i18n/en-us.d.mts +5 -0
  24. package/dist/error/i18n/en-us.d.mts.map +1 -0
  25. package/dist/error/i18n/en-us.mjs +5 -5
  26. package/dist/error/i18n/en-us.mjs.map +1 -1
  27. package/dist/error/index.cjs +29 -56
  28. package/dist/error/index.cjs.map +1 -1
  29. package/dist/error/index.d.cts +12 -10
  30. package/dist/error/index.d.cts.map +1 -0
  31. package/dist/error/index.d.mts +21 -0
  32. package/dist/error/index.d.mts.map +1 -0
  33. package/dist/error/index.mjs +25 -28
  34. package/dist/error/index.mjs.map +1 -1
  35. package/dist/error/parse.cjs +63 -61
  36. package/dist/error/parse.cjs.map +1 -1
  37. package/dist/error/parse.d.cts +8 -7
  38. package/dist/error/parse.d.cts.map +1 -0
  39. package/dist/error/{parse.d.ts → parse.d.mts} +8 -7
  40. package/dist/error/parse.d.mts.map +1 -0
  41. package/dist/error/parse.mjs +59 -33
  42. package/dist/error/parse.mjs.map +1 -1
  43. package/dist/error/reason.cjs +0 -19
  44. package/dist/error/reason.d.cts +5 -4
  45. package/dist/error/reason.d.cts.map +1 -0
  46. package/dist/error/reason.d.mts +6 -0
  47. package/dist/error/reason.d.mts.map +1 -0
  48. package/dist/error/reason.mjs +1 -1
  49. package/dist/error/status.cjs +103 -256
  50. package/dist/error/status.cjs.map +1 -1
  51. package/dist/error/status.d.cts +58 -58
  52. package/dist/error/status.d.cts.map +1 -0
  53. package/dist/error/status.d.mts +69 -0
  54. package/dist/error/status.d.mts.map +1 -0
  55. package/dist/error/status.mjs +98 -227
  56. package/dist/error/status.mjs.map +1 -1
  57. package/dist/google-one-tap/index.cjs +135 -138
  58. package/dist/google-one-tap/index.cjs.map +1 -1
  59. package/dist/google-one-tap/index.d.cts +49 -48
  60. package/dist/google-one-tap/index.d.cts.map +1 -0
  61. package/dist/google-one-tap/index.d.mts +82 -0
  62. package/dist/google-one-tap/index.d.mts.map +1 -0
  63. package/dist/google-one-tap/index.mjs +133 -112
  64. package/dist/google-one-tap/index.mjs.map +1 -1
  65. package/dist/google-one-tap/types.cjs +0 -19
  66. package/dist/google-one-tap/types.d.cts +124 -122
  67. package/dist/google-one-tap/types.d.cts.map +1 -0
  68. package/dist/google-one-tap/types.d.mts +157 -0
  69. package/dist/google-one-tap/types.d.mts.map +1 -0
  70. package/dist/google-one-tap/types.mjs +1 -1
  71. package/dist/hono/authorizer.cjs +28 -65
  72. package/dist/hono/authorizer.cjs.map +1 -1
  73. package/dist/hono/authorizer.d.cts +12 -11
  74. package/dist/hono/authorizer.d.cts.map +1 -0
  75. package/dist/hono/authorizer.d.mts +19 -0
  76. package/dist/hono/authorizer.d.mts.map +1 -0
  77. package/dist/hono/authorizer.mjs +23 -36
  78. package/dist/hono/authorizer.mjs.map +1 -1
  79. package/dist/hono/csrf.cjs +81 -92
  80. package/dist/hono/csrf.cjs.map +1 -1
  81. package/dist/hono/csrf.d.cts +46 -45
  82. package/dist/hono/csrf.d.cts.map +1 -0
  83. package/dist/hono/csrf.d.mts +76 -0
  84. package/dist/hono/csrf.d.mts.map +1 -0
  85. package/dist/hono/csrf.mjs +76 -63
  86. package/dist/hono/csrf.mjs.map +1 -1
  87. package/dist/hono/geolocation.cjs +10 -34
  88. package/dist/hono/geolocation.cjs.map +1 -1
  89. package/dist/hono/geolocation.d.cts +5 -4
  90. package/dist/hono/geolocation.d.cts.map +1 -0
  91. package/dist/hono/geolocation.d.mts +7 -0
  92. package/dist/hono/geolocation.d.mts.map +1 -0
  93. package/dist/hono/geolocation.mjs +8 -12
  94. package/dist/hono/geolocation.mjs.map +1 -1
  95. package/dist/hono/handler.cjs +37 -61
  96. package/dist/hono/handler.cjs.map +1 -1
  97. package/dist/hono/handler.d.cts +26 -25
  98. package/dist/hono/handler.d.cts.map +1 -0
  99. package/dist/hono/handler.d.mts +32 -0
  100. package/dist/hono/handler.d.mts.map +1 -0
  101. package/dist/hono/handler.mjs +34 -34
  102. package/dist/hono/handler.mjs.map +1 -1
  103. package/dist/hono/index.cjs +14 -48
  104. package/dist/hono/index.d.cts +7 -15
  105. package/dist/hono/index.d.mts +7 -0
  106. package/dist/hono/index.mjs +4 -14
  107. package/dist/hono/rate-limit.cjs +65 -110
  108. package/dist/hono/rate-limit.cjs.map +1 -1
  109. package/dist/hono/rate-limit.d.cts +27 -26
  110. package/dist/hono/rate-limit.d.cts.map +1 -0
  111. package/dist/hono/rate-limit.d.mts +36 -0
  112. package/dist/hono/rate-limit.d.mts.map +1 -0
  113. package/dist/hono/rate-limit.mjs +60 -81
  114. package/dist/hono/rate-limit.mjs.map +1 -1
  115. package/dist/hono/validator.cjs +47 -66
  116. package/dist/hono/validator.cjs.map +1 -1
  117. package/dist/hono/validator.d.cts +25 -30
  118. package/dist/hono/validator.d.cts.map +1 -0
  119. package/dist/hono/validator.d.mts +26 -0
  120. package/dist/hono/validator.d.mts.map +1 -0
  121. package/dist/hono/validator.mjs +43 -43
  122. package/dist/hono/validator.mjs.map +1 -1
  123. package/dist/index.cjs +39 -95
  124. package/dist/index.d.cts +12 -14
  125. package/dist/index.d.mts +12 -0
  126. package/dist/index.mjs +5 -48
  127. package/dist/iso/iso_3601_1.cjs +1512 -290
  128. package/dist/iso/iso_3601_1.cjs.map +1 -1
  129. package/dist/iso/iso_3601_1.d.cts +8 -6
  130. package/dist/iso/iso_3601_1.d.cts.map +1 -0
  131. package/dist/iso/iso_3601_1.d.mts +11 -0
  132. package/dist/iso/iso_3601_1.d.mts.map +1 -0
  133. package/dist/iso/iso_3601_1.mjs +1511 -265
  134. package/dist/iso/iso_3601_1.mjs.map +1 -1
  135. package/dist/max-length/index.cjs +158 -91
  136. package/dist/max-length/index.cjs.map +1 -1
  137. package/dist/max-length/index.d.cts +110 -1
  138. package/dist/max-length/index.d.cts.map +1 -0
  139. package/dist/{index-BhgdyigB.d.ts → max-length/index.d.mts} +9 -28
  140. package/dist/max-length/index.d.mts.map +1 -0
  141. package/dist/max-length/index.mjs +133 -47
  142. package/dist/max-length/index.mjs.map +1 -1
  143. package/dist/message.cjs +5 -30
  144. package/dist/message.cjs.map +1 -1
  145. package/dist/message.d.cts +3 -1
  146. package/dist/message.d.cts.map +1 -0
  147. package/dist/{message.d.ts → message.d.mts} +3 -1
  148. package/dist/message.d.mts.map +1 -0
  149. package/dist/message.mjs +5 -6
  150. package/dist/message.mjs.map +1 -1
  151. package/dist/polyfills/index.cjs +4 -4
  152. package/dist/polyfills/index.cjs.map +1 -1
  153. package/dist/polyfills/index.d.cts +1 -2
  154. package/dist/polyfills/index.d.mts +1 -0
  155. package/dist/polyfills/index.mjs +5 -2
  156. package/dist/polyfills/index.mjs.map +1 -1
  157. package/dist/response.cjs +191 -208
  158. package/dist/response.cjs.map +1 -1
  159. package/dist/response.d.cts +53 -54
  160. package/dist/response.d.cts.map +1 -0
  161. package/dist/response.d.mts +82 -0
  162. package/dist/response.d.mts.map +1 -0
  163. package/dist/response.mjs +182 -175
  164. package/dist/response.mjs.map +1 -1
  165. package/dist/snowflake.cjs +48 -70
  166. package/dist/snowflake.cjs.map +1 -1
  167. package/dist/snowflake.d.cts +16 -14
  168. package/dist/snowflake.d.cts.map +1 -0
  169. package/dist/snowflake.d.mts +31 -0
  170. package/dist/snowflake.d.mts.map +1 -0
  171. package/dist/snowflake.mjs +46 -44
  172. package/dist/snowflake.mjs.map +1 -1
  173. package/dist/utils/geolocation.cjs +51 -75
  174. package/dist/utils/geolocation.cjs.map +1 -1
  175. package/dist/utils/geolocation.d.cts +14 -12
  176. package/dist/utils/geolocation.d.cts.map +1 -0
  177. package/dist/utils/{geolocation.d.ts → geolocation.d.mts} +14 -12
  178. package/dist/utils/geolocation.d.mts.map +1 -0
  179. package/dist/utils/geolocation.mjs +47 -47
  180. package/dist/utils/geolocation.mjs.map +1 -1
  181. package/dist/utils/google-tag-gateway.cjs +35 -56
  182. package/dist/utils/google-tag-gateway.cjs.map +1 -1
  183. package/dist/utils/google-tag-gateway.d.cts +3 -1
  184. package/dist/utils/google-tag-gateway.d.cts.map +1 -0
  185. package/dist/utils/{google-tag-gateway.d.ts → google-tag-gateway.d.mts} +3 -1
  186. package/dist/utils/google-tag-gateway.d.mts.map +1 -0
  187. package/dist/utils/google-tag-gateway.mjs +33 -30
  188. package/dist/utils/google-tag-gateway.mjs.map +1 -1
  189. package/dist/utils/timing.cjs +50 -71
  190. package/dist/utils/timing.cjs.map +1 -1
  191. package/dist/utils/timing.d.cts +11 -9
  192. package/dist/utils/timing.d.cts.map +1 -0
  193. package/dist/utils/timing.d.mts +15 -0
  194. package/dist/utils/timing.d.mts.map +1 -0
  195. package/dist/utils/timing.mjs +49 -46
  196. package/dist/utils/timing.mjs.map +1 -1
  197. package/dist/webhook/index.cjs +43 -72
  198. package/dist/webhook/index.cjs.map +1 -1
  199. package/dist/webhook/index.d.cts +3 -1
  200. package/dist/webhook/index.d.cts.map +1 -0
  201. package/dist/webhook/{index.d.ts → index.d.mts} +3 -1
  202. package/dist/webhook/index.d.mts.map +1 -0
  203. package/dist/webhook/index.mjs +41 -46
  204. package/dist/webhook/index.mjs.map +1 -1
  205. package/package.json +49 -24
  206. package/dist/cache/index.d.ts +0 -9
  207. package/dist/error/detail.d.ts +0 -109
  208. package/dist/error/i18n/en-us.d.ts +0 -3
  209. package/dist/error/index.d.ts +0 -19
  210. package/dist/error/reason.cjs.map +0 -1
  211. package/dist/error/reason.d.ts +0 -5
  212. package/dist/error/reason.mjs.map +0 -1
  213. package/dist/error/status.d.ts +0 -69
  214. package/dist/google-one-tap/index.d.ts +0 -81
  215. package/dist/google-one-tap/types.cjs.map +0 -1
  216. package/dist/google-one-tap/types.d.ts +0 -155
  217. package/dist/google-one-tap/types.mjs.map +0 -1
  218. package/dist/hono/authorizer.d.ts +0 -18
  219. package/dist/hono/csrf.d.ts +0 -75
  220. package/dist/hono/geolocation.d.ts +0 -6
  221. package/dist/hono/handler.d.ts +0 -31
  222. package/dist/hono/index.cjs.map +0 -1
  223. package/dist/hono/index.d.ts +0 -15
  224. package/dist/hono/index.mjs.map +0 -1
  225. package/dist/hono/rate-limit.d.ts +0 -35
  226. package/dist/hono/validator.d.ts +0 -31
  227. package/dist/index-BhgdyigB.d.cts +0 -129
  228. package/dist/index.cjs.map +0 -1
  229. package/dist/index.d.ts +0 -14
  230. package/dist/index.mjs.map +0 -1
  231. package/dist/iso/iso_3601_1.d.ts +0 -9
  232. package/dist/max-length/index.d.ts +0 -1
  233. package/dist/polyfills/index.d.ts +0 -2
  234. package/dist/response.d.ts +0 -83
  235. package/dist/snowflake.d.ts +0 -29
  236. package/dist/utils/timing.d.ts +0 -13
@@ -1,77 +1,48 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/webhook/index.ts
21
- var webhook_exports = {};
22
- __export(webhook_exports, {
23
- verifyStandardWebhook: () => verifyStandardWebhook
24
- });
25
- module.exports = __toCommonJS(webhook_exports);
26
- var import_node_crypto = require("crypto");
27
- var import_status = require("../error/status.cjs");
28
- var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_error_status = require("../error/status.cjs");
3
+ let node_crypto = require("node:crypto");
4
+ //#region src/webhook/index.ts
5
+ const WEBHOOK_TOLERANCE_IN_SECONDS = 300;
29
6
  function verifyTimestamp(webhookTimestamp) {
30
- const now = Math.floor(Date.now() / 1e3);
31
- const timestamp = parseInt(webhookTimestamp, 10);
32
- if (isNaN(timestamp)) {
33
- throw import_status.Status.invalidArgument("invalid webhook timestamp").error();
34
- }
35
- if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {
36
- throw import_status.Status.invalidArgument("webhook timestamp is too old").error();
37
- }
38
- if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {
39
- throw import_status.Status.invalidArgument("webhook timestamp is too new").error();
40
- }
41
- return timestamp;
7
+ const now = Math.floor(Date.now() / 1e3);
8
+ const timestamp = parseInt(webhookTimestamp, 10);
9
+ if (isNaN(timestamp)) throw require_error_status.Status.invalidArgument("invalid webhook timestamp").error();
10
+ if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) throw require_error_status.Status.invalidArgument("webhook timestamp is too old").error();
11
+ if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) throw require_error_status.Status.invalidArgument("webhook timestamp is too new").error();
12
+ return timestamp;
42
13
  }
14
+ /**
15
+ * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript
16
+ * hono usage:
17
+ * ```ts
18
+ * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');
19
+ * ```
20
+ */
43
21
  function verifyStandardWebhook(headers, payload, secret) {
44
- const webhookId = headers["webhook-id"];
45
- const webhookTimestamp = headers["webhook-timestamp"];
46
- const webhookSignature = headers["webhook-signature"];
47
- if (!webhookId || !webhookTimestamp || !webhookSignature) {
48
- throw import_status.Status.invalidArgument("invalid webhook").error();
49
- }
50
- const timestamp = verifyTimestamp(webhookTimestamp);
51
- const encoder = new TextEncoder();
52
- const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);
53
- const hmac = (0, import_node_crypto.createHmac)("sha256", Buffer.from(secret, "base64"));
54
- const digest = hmac.update(toSign).digest();
55
- const computedSignature = `v1,${Buffer.from(digest).toString("base64")}`;
56
- const expectedSignature = computedSignature.split(",")[1];
57
- const passedSignatures = webhookSignature.split(" ");
58
- for (const versionedSignature of passedSignatures) {
59
- const [version, signature] = versionedSignature.split(",");
60
- if (version !== "v1") continue;
61
- if ((0, import_node_crypto.timingSafeEqual)(encoder.encode(signature), encoder.encode(expectedSignature))) {
62
- try {
63
- return JSON.parse(payload);
64
- } catch (_) {
65
- console.error("invalid payload", payload);
66
- throw import_status.Status.invalidArgument("invalid webhook payload").error();
67
- }
68
- }
69
- }
70
- console.error("webhook verification failed");
71
- throw import_status.Status.invalidArgument("invalid webhook signature").error();
22
+ const webhookId = headers["webhook-id"];
23
+ const webhookTimestamp = headers["webhook-timestamp"];
24
+ const webhookSignature = headers["webhook-signature"];
25
+ if (!webhookId || !webhookTimestamp || !webhookSignature) throw require_error_status.Status.invalidArgument("invalid webhook").error();
26
+ const timestamp = verifyTimestamp(webhookTimestamp);
27
+ const encoder = new TextEncoder();
28
+ const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);
29
+ const digest = (0, node_crypto.createHmac)("sha256", Buffer.from(secret, "base64")).update(toSign).digest();
30
+ const expectedSignature = `v1,${Buffer.from(digest).toString("base64")}`.split(",")[1];
31
+ const passedSignatures = webhookSignature.split(" ");
32
+ for (const versionedSignature of passedSignatures) {
33
+ const [version, signature] = versionedSignature.split(",");
34
+ if (version !== "v1") continue;
35
+ if ((0, node_crypto.timingSafeEqual)(encoder.encode(signature), encoder.encode(expectedSignature))) try {
36
+ return JSON.parse(payload);
37
+ } catch (_) {
38
+ console.error("invalid payload", payload);
39
+ throw require_error_status.Status.invalidArgument("invalid webhook payload").error();
40
+ }
41
+ }
42
+ console.error("webhook verification failed");
43
+ throw require_error_status.Status.invalidArgument("invalid webhook signature").error();
72
44
  }
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
75
- verifyStandardWebhook
76
- });
45
+ //#endregion
46
+ exports.verifyStandardWebhook = verifyStandardWebhook;
47
+
77
48
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto';\nimport { Status } from '../error/status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA4C;AAC5C,oBAAuB;AAEvB,IAAM,+BAA+B,IAAI;AAEzC,SAAS,gBAAgB,kBAA0B;AACjD,QAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAM,YAAY,SAAS,kBAAkB,EAAE;AAC/C,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,qBAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAAA,EAClE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,qBAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,qBAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,SAAO;AACT;AASO,SAAS,sBACd,SACA,SACA,QACG;AACH,QAAM,YAAY,QAAQ,YAAY;AACtC,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,MAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBAAkB;AACxD,UAAM,qBAAO,gBAAgB,iBAAiB,EAAE,MAAM;AAAA,EACxD;AACA,QAAM,YAAY,gBAAgB,gBAAgB;AAElD,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,SAAS,QAAQ,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE;AACpE,QAAM,WAAO,+BAAW,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAAC;AAC/D,QAAM,SAAS,KAAK,OAAO,MAAM,EAAE,OAAO;AAE1C,QAAM,oBAAoB,MAAM,OAAO,KAAK,MAAM,EAAE,SAAS,QAAQ,CAAC;AACtE,QAAM,oBAAoB,kBAAkB,MAAM,GAAG,EAAE,CAAC;AACxD,QAAM,mBAAmB,iBAAiB,MAAM,GAAG;AAEnD,aAAW,sBAAsB,kBAAkB;AACjD,UAAM,CAAC,SAAS,SAAS,IAAI,mBAAmB,MAAM,GAAG;AACzD,QAAI,YAAY,KAAM;AACtB,YAAI,oCAAgB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAAG;AACjF,UAAI;AACF,eAAO,KAAK,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG;AACV,gBAAQ,MAAM,mBAAmB,OAAO;AACxC,cAAM,qBAAO,gBAAgB,yBAAyB,EAAE,MAAM;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACA,UAAQ,MAAM,6BAA6B;AAC3C,QAAM,qBAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAClE;","names":[]}
1
+ {"version":3,"file":"index.cjs","names":["Status"],"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto';\nimport { Status } from '../error/status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";;;;AAGA,MAAM,+BAA+B;AAErC,SAAS,gBAAgB,kBAA0B;CACjD,MAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;CACxC,MAAM,YAAY,SAAS,kBAAkB,EAAE;CAC/C,IAAI,MAAM,SAAS,GACjB,MAAMA,qBAAAA,OAAO,gBAAgB,2BAA2B,CAAC,CAAC,MAAM;CAElE,IAAI,YAAY,MAAM,8BACpB,MAAMA,qBAAAA,OAAO,gBAAgB,8BAA8B,CAAC,CAAC,MAAM;CAErE,IAAI,YAAY,MAAM,8BACpB,MAAMA,qBAAAA,OAAO,gBAAgB,8BAA8B,CAAC,CAAC,MAAM;CAErE,OAAO;AACT;;;;;;;;AASA,SAAgB,sBACd,SACA,SACA,QACG;CACH,MAAM,YAAY,QAAQ;CAC1B,MAAM,mBAAmB,QAAQ;CACjC,MAAM,mBAAmB,QAAQ;CACjC,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBACtC,MAAMA,qBAAAA,OAAO,gBAAgB,iBAAiB,CAAC,CAAC,MAAM;CAExD,MAAM,YAAY,gBAAgB,gBAAgB;CAElD,MAAM,UAAU,IAAI,YAAY;CAChC,MAAM,SAAS,QAAQ,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS;CAEpE,MAAM,UAAA,GAAA,YAAA,WAAA,CADkB,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAC5C,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO;CAG1C,MAAM,oBAAoB,MADM,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,QAAQ,IACzB,MAAM,GAAG,CAAC,CAAC;CACvD,MAAM,mBAAmB,iBAAiB,MAAM,GAAG;CAEnD,KAAK,MAAM,sBAAsB,kBAAkB;EACjD,MAAM,CAAC,SAAS,aAAa,mBAAmB,MAAM,GAAG;EACzD,IAAI,YAAY,MAAM;EACtB,KAAA,GAAA,YAAA,gBAAA,CAAoB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAC9E,IAAI;GACF,OAAO,KAAK,MAAM,OAAO;EAC3B,SAAS,GAAG;GACV,QAAQ,MAAM,mBAAmB,OAAO;GACxC,MAAMA,qBAAAA,OAAO,gBAAgB,yBAAyB,CAAC,CAAC,MAAM;EAChE;CAEJ;CACA,QAAQ,MAAM,6BAA6B;CAC3C,MAAMA,qBAAAA,OAAO,gBAAgB,2BAA2B,CAAC,CAAC,MAAM;AAClE"}
@@ -1,3 +1,4 @@
1
+ //#region src/webhook/index.d.ts
1
2
  /**
2
3
  * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript
3
4
  * hono usage:
@@ -6,5 +7,6 @@
6
7
  * ```
7
8
  */
8
9
  declare function verifyStandardWebhook<T = unknown>(headers: Record<string, string>, payload: string, secret: string): T;
9
-
10
+ //#endregion
10
11
  export { verifyStandardWebhook };
12
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/webhook/index.ts"],"mappings":";;;;;;;;iBA2BgB,sBAAsB,aACpC,SAAS,wBACT,iBACA,iBACC"}
@@ -1,3 +1,4 @@
1
+ //#region src/webhook/index.d.ts
1
2
  /**
2
3
  * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript
3
4
  * hono usage:
@@ -6,5 +7,6 @@
6
7
  * ```
7
8
  */
8
9
  declare function verifyStandardWebhook<T = unknown>(headers: Record<string, string>, payload: string, secret: string): T;
9
-
10
+ //#endregion
10
11
  export { verifyStandardWebhook };
12
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/webhook/index.ts"],"mappings":";;;;;;;;iBA2BgB,sBAAsB,aACpC,SAAS,wBACT,iBACA,iBACC"}
@@ -1,52 +1,47 @@
1
- // src/webhook/index.ts
2
- import { createHmac, timingSafeEqual } from "crypto";
3
1
  import { Status } from "../error/status.mjs";
4
- var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
2
+ import { createHmac, timingSafeEqual } from "node:crypto";
3
+ //#region src/webhook/index.ts
4
+ const WEBHOOK_TOLERANCE_IN_SECONDS = 300;
5
5
  function verifyTimestamp(webhookTimestamp) {
6
- const now = Math.floor(Date.now() / 1e3);
7
- const timestamp = parseInt(webhookTimestamp, 10);
8
- if (isNaN(timestamp)) {
9
- throw Status.invalidArgument("invalid webhook timestamp").error();
10
- }
11
- if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {
12
- throw Status.invalidArgument("webhook timestamp is too old").error();
13
- }
14
- if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {
15
- throw Status.invalidArgument("webhook timestamp is too new").error();
16
- }
17
- return timestamp;
6
+ const now = Math.floor(Date.now() / 1e3);
7
+ const timestamp = parseInt(webhookTimestamp, 10);
8
+ if (isNaN(timestamp)) throw Status.invalidArgument("invalid webhook timestamp").error();
9
+ if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) throw Status.invalidArgument("webhook timestamp is too old").error();
10
+ if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) throw Status.invalidArgument("webhook timestamp is too new").error();
11
+ return timestamp;
18
12
  }
13
+ /**
14
+ * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript
15
+ * hono usage:
16
+ * ```ts
17
+ * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');
18
+ * ```
19
+ */
19
20
  function verifyStandardWebhook(headers, payload, secret) {
20
- const webhookId = headers["webhook-id"];
21
- const webhookTimestamp = headers["webhook-timestamp"];
22
- const webhookSignature = headers["webhook-signature"];
23
- if (!webhookId || !webhookTimestamp || !webhookSignature) {
24
- throw Status.invalidArgument("invalid webhook").error();
25
- }
26
- const timestamp = verifyTimestamp(webhookTimestamp);
27
- const encoder = new TextEncoder();
28
- const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);
29
- const hmac = createHmac("sha256", Buffer.from(secret, "base64"));
30
- const digest = hmac.update(toSign).digest();
31
- const computedSignature = `v1,${Buffer.from(digest).toString("base64")}`;
32
- const expectedSignature = computedSignature.split(",")[1];
33
- const passedSignatures = webhookSignature.split(" ");
34
- for (const versionedSignature of passedSignatures) {
35
- const [version, signature] = versionedSignature.split(",");
36
- if (version !== "v1") continue;
37
- if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {
38
- try {
39
- return JSON.parse(payload);
40
- } catch (_) {
41
- console.error("invalid payload", payload);
42
- throw Status.invalidArgument("invalid webhook payload").error();
43
- }
44
- }
45
- }
46
- console.error("webhook verification failed");
47
- throw Status.invalidArgument("invalid webhook signature").error();
21
+ const webhookId = headers["webhook-id"];
22
+ const webhookTimestamp = headers["webhook-timestamp"];
23
+ const webhookSignature = headers["webhook-signature"];
24
+ if (!webhookId || !webhookTimestamp || !webhookSignature) throw Status.invalidArgument("invalid webhook").error();
25
+ const timestamp = verifyTimestamp(webhookTimestamp);
26
+ const encoder = new TextEncoder();
27
+ const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);
28
+ const digest = createHmac("sha256", Buffer.from(secret, "base64")).update(toSign).digest();
29
+ const expectedSignature = `v1,${Buffer.from(digest).toString("base64")}`.split(",")[1];
30
+ const passedSignatures = webhookSignature.split(" ");
31
+ for (const versionedSignature of passedSignatures) {
32
+ const [version, signature] = versionedSignature.split(",");
33
+ if (version !== "v1") continue;
34
+ if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) try {
35
+ return JSON.parse(payload);
36
+ } catch (_) {
37
+ console.error("invalid payload", payload);
38
+ throw Status.invalidArgument("invalid webhook payload").error();
39
+ }
40
+ }
41
+ console.error("webhook verification failed");
42
+ throw Status.invalidArgument("invalid webhook signature").error();
48
43
  }
49
- export {
50
- verifyStandardWebhook
51
- };
44
+ //#endregion
45
+ export { verifyStandardWebhook };
46
+
52
47
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto';\nimport { Status } from '../error/status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";AAAA,SAAS,YAAY,uBAAuB;AAC5C,SAAS,cAAc;AAEvB,IAAM,+BAA+B,IAAI;AAEzC,SAAS,gBAAgB,kBAA0B;AACjD,QAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAM,YAAY,SAAS,kBAAkB,EAAE;AAC/C,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,OAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAAA,EAClE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,OAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,OAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,SAAO;AACT;AASO,SAAS,sBACd,SACA,SACA,QACG;AACH,QAAM,YAAY,QAAQ,YAAY;AACtC,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,MAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBAAkB;AACxD,UAAM,OAAO,gBAAgB,iBAAiB,EAAE,MAAM;AAAA,EACxD;AACA,QAAM,YAAY,gBAAgB,gBAAgB;AAElD,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,SAAS,QAAQ,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE;AACpE,QAAM,OAAO,WAAW,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAAC;AAC/D,QAAM,SAAS,KAAK,OAAO,MAAM,EAAE,OAAO;AAE1C,QAAM,oBAAoB,MAAM,OAAO,KAAK,MAAM,EAAE,SAAS,QAAQ,CAAC;AACtE,QAAM,oBAAoB,kBAAkB,MAAM,GAAG,EAAE,CAAC;AACxD,QAAM,mBAAmB,iBAAiB,MAAM,GAAG;AAEnD,aAAW,sBAAsB,kBAAkB;AACjD,UAAM,CAAC,SAAS,SAAS,IAAI,mBAAmB,MAAM,GAAG;AACzD,QAAI,YAAY,KAAM;AACtB,QAAI,gBAAgB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAAG;AACjF,UAAI;AACF,eAAO,KAAK,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG;AACV,gBAAQ,MAAM,mBAAmB,OAAO;AACxC,cAAM,OAAO,gBAAgB,yBAAyB,EAAE,MAAM;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACA,UAAQ,MAAM,6BAA6B;AAC3C,QAAM,OAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAClE;","names":[]}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto';\nimport { Status } from '../error/status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";;;AAGA,MAAM,+BAA+B;AAErC,SAAS,gBAAgB,kBAA0B;CACjD,MAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;CACxC,MAAM,YAAY,SAAS,kBAAkB,EAAE;CAC/C,IAAI,MAAM,SAAS,GACjB,MAAM,OAAO,gBAAgB,2BAA2B,CAAC,CAAC,MAAM;CAElE,IAAI,YAAY,MAAM,8BACpB,MAAM,OAAO,gBAAgB,8BAA8B,CAAC,CAAC,MAAM;CAErE,IAAI,YAAY,MAAM,8BACpB,MAAM,OAAO,gBAAgB,8BAA8B,CAAC,CAAC,MAAM;CAErE,OAAO;AACT;;;;;;;;AASA,SAAgB,sBACd,SACA,SACA,QACG;CACH,MAAM,YAAY,QAAQ;CAC1B,MAAM,mBAAmB,QAAQ;CACjC,MAAM,mBAAmB,QAAQ;CACjC,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBACtC,MAAM,OAAO,gBAAgB,iBAAiB,CAAC,CAAC,MAAM;CAExD,MAAM,YAAY,gBAAgB,gBAAgB;CAElD,MAAM,UAAU,IAAI,YAAY;CAChC,MAAM,SAAS,QAAQ,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS;CAEpE,MAAM,SADO,WAAW,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAC5C,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO;CAG1C,MAAM,oBAAoB,MADM,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,QAAQ,IACzB,MAAM,GAAG,CAAC,CAAC;CACvD,MAAM,mBAAmB,iBAAiB,MAAM,GAAG;CAEnD,KAAK,MAAM,sBAAsB,kBAAkB;EACjD,MAAM,CAAC,SAAS,aAAa,mBAAmB,MAAM,GAAG;EACzD,IAAI,YAAY,MAAM;EACtB,IAAI,gBAAgB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAC9E,IAAI;GACF,OAAO,KAAK,MAAM,OAAO;EAC3B,SAAS,GAAG;GACV,QAAQ,MAAM,mBAAmB,OAAO;GACxC,MAAM,OAAO,gBAAgB,yBAAyB,CAAC,CAAC,MAAM;EAChE;CAEJ;CACA,QAAQ,MAAM,6BAA6B;CAC3C,MAAM,OAAO,gBAAgB,2BAA2B,CAAC,CAAC,MAAM;AAClE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "2.11.4",
3
+ "version": "2.12.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,49 +12,74 @@
12
12
  "type": "module",
13
13
  "exports": {
14
14
  ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.mjs",
17
- "require": "./dist/index.cjs"
15
+ "import": {
16
+ "types": "./dist/index.d.mts",
17
+ "default": "./dist/index.mjs"
18
+ },
19
+ "require": {
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
22
+ }
18
23
  },
19
24
  "./polyfills": {
20
- "types": "./dist/polyfills/index.d.ts",
21
- "import": "./dist/polyfills/index.mjs",
22
- "require": "./dist/polyfills/index.cjs"
25
+ "import": {
26
+ "types": "./dist/polyfills/index.d.mts",
27
+ "default": "./dist/polyfills/index.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./dist/polyfills/index.d.cts",
31
+ "default": "./dist/polyfills/index.cjs"
32
+ }
23
33
  },
24
34
  "./hono": {
25
- "types": "./dist/hono/index.d.ts",
26
- "import": "./dist/hono/index.mjs",
27
- "require": "./dist/hono/index.cjs"
35
+ "import": {
36
+ "types": "./dist/hono/index.d.mts",
37
+ "default": "./dist/hono/index.mjs"
38
+ },
39
+ "require": {
40
+ "types": "./dist/hono/index.d.cts",
41
+ "default": "./dist/hono/index.cjs"
42
+ }
28
43
  },
29
44
  "./webhook": {
30
- "types": "./dist/webhook/index.d.ts",
31
- "import": "./dist/webhook/index.mjs",
32
- "require": "./dist/webhook/index.cjs"
45
+ "import": {
46
+ "types": "./dist/webhook/index.d.mts",
47
+ "default": "./dist/webhook/index.mjs"
48
+ },
49
+ "require": {
50
+ "types": "./dist/webhook/index.d.cts",
51
+ "default": "./dist/webhook/index.cjs"
52
+ }
33
53
  },
34
54
  "./google-one-tap": {
35
- "types": "./dist/google-one-tap/index.d.ts",
36
- "import": "./dist/google-one-tap/index.mjs",
37
- "require": "./dist/google-one-tap/index.cjs"
55
+ "import": {
56
+ "types": "./dist/google-one-tap/index.d.mts",
57
+ "default": "./dist/google-one-tap/index.mjs"
58
+ },
59
+ "require": {
60
+ "types": "./dist/google-one-tap/index.d.cts",
61
+ "default": "./dist/google-one-tap/index.cjs"
62
+ }
38
63
  }
39
64
  },
40
65
  "publishConfig": {
41
66
  "access": "public"
42
67
  },
43
68
  "dependencies": {
44
- "vitest": "^4.1.9",
69
+ "vitest": "^4.1.10",
45
70
  "zod": "^4.4.3",
46
- "@shware/utils": "^1.4.5"
71
+ "@shware/utils": "^1.5.0"
47
72
  },
48
73
  "devDependencies": {
49
- "@types/node": "^26.1.0",
74
+ "@types/node": "^26.1.1",
50
75
  "@types/react": "^19.2.17",
51
- "typescript": "^6.0.3",
76
+ "typescript": "^7.0.2",
52
77
  "@repo/typescript-config": "0.0.0"
53
78
  },
54
79
  "peerDependencies": {
55
- "hono": "^4.12.28",
56
- "i18next": "^26.3.4",
57
- "react": "^19"
80
+ "hono": "^4.12.29",
81
+ "i18next": "^26.3.6",
82
+ "react": "^19.2.7"
58
83
  },
59
84
  "peerDependenciesMeta": {
60
85
  "hono": {
@@ -69,7 +94,7 @@
69
94
  },
70
95
  "scripts": {
71
96
  "dev": "tsc --watch",
72
- "build": "tsup",
97
+ "build": "tsdown",
73
98
  "test": "vitest run",
74
99
  "check-types": "tsc --noEmit",
75
100
  "lint": "oxlint --type-aware . --fix"
@@ -1,9 +0,0 @@
1
- interface Props<A extends unknown[], R> {
2
- name: string;
3
- key: (...args: A) => string;
4
- fn: (...args: A) => R;
5
- condition?: (...args: A) => boolean;
6
- }
7
- declare function cache<A extends unknown[], R>(_props: Props<A, R>): void;
8
-
9
- export { cache };
@@ -1,109 +0,0 @@
1
- import { ResolvedErrorReason } from './reason.js';
2
-
3
- /** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */
4
-
5
- declare enum DetailType {
6
- ERROR_INFO = "type.googleapis.com/google.rpc.ErrorInfo",
7
- RETRY_INFO = "type.googleapis.com/google.rpc.RetryInfo",
8
- DEBUG_INFO = "type.googleapis.com/google.rpc.DebugInfo",
9
- QUOTA_FAILURE = "type.googleapis.com/google.rpc.QuotaFailure",
10
- PRECONDITION_FAILURE = "type.googleapis.com/google.rpc.PreconditionFailure",
11
- BAD_REQUEST = "type.googleapis.com/google.rpc.BadRequest",
12
- REQUEST_INFO = "type.googleapis.com/google.rpc.RequestInfo",
13
- RESOURCE_INFO = "type.googleapis.com/google.rpc.ResourceInfo",
14
- HELP = "type.googleapis.com/google.rpc.Help",
15
- LOCALIZED_MESSAGE = "type.googleapis.com/google.rpc.LocalizedMessage"
16
- }
17
- interface ErrorInfo {
18
- '@type': DetailType.ERROR_INFO;
19
- reason: ResolvedErrorReason;
20
- domain?: string;
21
- metadata?: Record<string, string>;
22
- }
23
- interface RetryInfo {
24
- '@type': DetailType.RETRY_INFO;
25
- retryDelay: number;
26
- }
27
- interface DebugInfo {
28
- '@type': DetailType.DEBUG_INFO;
29
- stackEntries: string[];
30
- detail: string;
31
- }
32
- interface QuotaFailure {
33
- '@type': DetailType.QUOTA_FAILURE;
34
- violations: {
35
- subject: string;
36
- description: string;
37
- apiService: string;
38
- quoteId: string;
39
- quoteValue: number;
40
- quotaMetric: string;
41
- quotaDimensions: Record<string, string>;
42
- futureQuotaValue: number;
43
- }[];
44
- }
45
- interface PreconditionFailure {
46
- '@type': DetailType.PRECONDITION_FAILURE;
47
- violations: {
48
- type: string;
49
- subject: string;
50
- description: string;
51
- }[];
52
- }
53
- interface BadRequest {
54
- '@type': DetailType.BAD_REQUEST;
55
- fieldViolations: {
56
- field: string;
57
- description: string;
58
- reason: string;
59
- localizedMessage: Omit<LocalizedMessage, '@type'>;
60
- }[];
61
- }
62
- interface RequestInfo {
63
- '@type': DetailType.REQUEST_INFO;
64
- requestId: string;
65
- servingData: string;
66
- }
67
- interface ResourceInfo {
68
- '@type': DetailType.RESOURCE_INFO;
69
- resourceType: string;
70
- resourceName: string;
71
- owner: string;
72
- description: string;
73
- }
74
- interface Help {
75
- '@type': DetailType.HELP;
76
- links: {
77
- url: string;
78
- description: string;
79
- }[];
80
- }
81
- interface LocalizedMessage {
82
- '@type': DetailType.LOCALIZED_MESSAGE;
83
- locale: string;
84
- message: string;
85
- }
86
- type Detail = RetryInfo | DebugInfo | QuotaFailure | ErrorInfo | PreconditionFailure | BadRequest | RequestInfo | ResourceInfo | Help | LocalizedMessage;
87
- /**
88
- * Example usage:
89
- * const details = Details.new()
90
- * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })
91
- * .errorInfo({ reason: 'ACCOUNT_LOCKED' });
92
- * */
93
- declare class Details {
94
- readonly list: Detail[];
95
- private constructor();
96
- static new(): Details;
97
- errorInfo(detail: Omit<ErrorInfo, '@type'>): this;
98
- retryInfo(detail: Omit<RetryInfo, '@type'>): this;
99
- debugInfo(detail: Omit<DebugInfo, '@type'>): this;
100
- quotaFailure(detail: Omit<QuotaFailure, '@type'>): this;
101
- preconditionFailure(detail: Omit<PreconditionFailure, '@type'>): this;
102
- badRequest(detail: Omit<BadRequest, '@type'>): this;
103
- requestInfo(detail: Omit<RequestInfo, '@type'>): this;
104
- resourceInfo(detail: Omit<ResourceInfo, '@type'>): this;
105
- help(detail: Omit<Help, '@type'>): this;
106
- localizedMessage(detail: Omit<LocalizedMessage, '@type'>): this;
107
- }
108
-
109
- export { type BadRequest, type DebugInfo, type Detail, DetailType, Details, type ErrorInfo, type Help, type LocalizedMessage, type PreconditionFailure, type QuotaFailure, type RequestInfo, type ResourceInfo, type RetryInfo };
@@ -1,3 +0,0 @@
1
- declare const enUS: {};
2
-
3
- export { enUS };
@@ -1,19 +0,0 @@
1
- declare class LoginTimeoutError extends Error {
2
- constructor(timeout: number);
3
- }
4
- declare class LoginCanceledError extends Error {
5
- constructor();
6
- }
7
- declare class CheckoutCreateError extends Error {
8
- constructor();
9
- }
10
- declare enum PurchaseError {
11
- LOGIN_TIMEOUT = "LOGIN_TIMEOUT",
12
- LOGIN_CANCELED = "LOGIN_CANCELED",
13
- CHECKOUT_CANCELED = "CHECKOUT_CANCELED",
14
- CHECKOUT_CREATE_FAILED = "CHECKOUT_CREATE_FAILED",
15
- CHECKOUT_SESSION_ID_NOT_FOUND = "CHECKOUT_SESSION_ID_NOT_FOUND",
16
- UNKNOWN = "UNKNOWN"
17
- }
18
-
19
- export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/error/reason.ts"],"sourcesContent":["// oxlint-disable-next-line typescript/no-empty-object-type\nexport interface ErrorReason {}\n\nexport type ResolvedErrorReason = keyof ErrorReason extends never ? string : keyof ErrorReason;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,5 +0,0 @@
1
- interface ErrorReason {
2
- }
3
- type ResolvedErrorReason = keyof ErrorReason extends never ? string : keyof ErrorReason;
4
-
5
- export type { ErrorReason, ResolvedErrorReason };
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}