@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.
- package/dist/_virtual/_rolldown/runtime.cjs +13 -0
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/cache/index.cjs +5 -30
- package/dist/cache/index.cjs.map +1 -1
- package/dist/cache/index.d.cts +7 -5
- package/dist/cache/index.d.cts.map +1 -0
- package/dist/cache/index.d.mts +11 -0
- package/dist/cache/index.d.mts.map +1 -0
- package/dist/cache/index.mjs +5 -6
- package/dist/cache/index.mjs.map +1 -1
- package/dist/error/detail.cjs +100 -90
- package/dist/error/detail.cjs.map +1 -1
- package/dist/error/detail.d.cts +77 -78
- package/dist/error/detail.d.cts.map +1 -0
- package/dist/error/detail.d.mts +108 -0
- package/dist/error/detail.d.mts.map +1 -0
- package/dist/error/detail.mjs +99 -65
- package/dist/error/detail.mjs.map +1 -1
- package/dist/error/i18n/en-us.cjs +5 -29
- package/dist/error/i18n/en-us.cjs.map +1 -1
- package/dist/error/i18n/en-us.d.cts +3 -1
- package/dist/error/i18n/en-us.d.cts.map +1 -0
- package/dist/error/i18n/en-us.d.mts +5 -0
- package/dist/error/i18n/en-us.d.mts.map +1 -0
- package/dist/error/i18n/en-us.mjs +5 -5
- package/dist/error/i18n/en-us.mjs.map +1 -1
- package/dist/error/index.cjs +29 -56
- package/dist/error/index.cjs.map +1 -1
- package/dist/error/index.d.cts +12 -10
- package/dist/error/index.d.cts.map +1 -0
- package/dist/error/index.d.mts +21 -0
- package/dist/error/index.d.mts.map +1 -0
- package/dist/error/index.mjs +25 -28
- package/dist/error/index.mjs.map +1 -1
- package/dist/error/parse.cjs +63 -61
- package/dist/error/parse.cjs.map +1 -1
- package/dist/error/parse.d.cts +8 -7
- package/dist/error/parse.d.cts.map +1 -0
- package/dist/error/{parse.d.ts → parse.d.mts} +8 -7
- package/dist/error/parse.d.mts.map +1 -0
- package/dist/error/parse.mjs +59 -33
- package/dist/error/parse.mjs.map +1 -1
- package/dist/error/reason.cjs +0 -19
- package/dist/error/reason.d.cts +5 -4
- package/dist/error/reason.d.cts.map +1 -0
- package/dist/error/reason.d.mts +6 -0
- package/dist/error/reason.d.mts.map +1 -0
- package/dist/error/reason.mjs +1 -1
- package/dist/error/status.cjs +103 -256
- package/dist/error/status.cjs.map +1 -1
- package/dist/error/status.d.cts +58 -58
- package/dist/error/status.d.cts.map +1 -0
- package/dist/error/status.d.mts +69 -0
- package/dist/error/status.d.mts.map +1 -0
- package/dist/error/status.mjs +98 -227
- package/dist/error/status.mjs.map +1 -1
- package/dist/google-one-tap/index.cjs +135 -138
- package/dist/google-one-tap/index.cjs.map +1 -1
- package/dist/google-one-tap/index.d.cts +49 -48
- package/dist/google-one-tap/index.d.cts.map +1 -0
- package/dist/google-one-tap/index.d.mts +82 -0
- package/dist/google-one-tap/index.d.mts.map +1 -0
- package/dist/google-one-tap/index.mjs +133 -112
- package/dist/google-one-tap/index.mjs.map +1 -1
- package/dist/google-one-tap/types.cjs +0 -19
- package/dist/google-one-tap/types.d.cts +124 -122
- package/dist/google-one-tap/types.d.cts.map +1 -0
- package/dist/google-one-tap/types.d.mts +157 -0
- package/dist/google-one-tap/types.d.mts.map +1 -0
- package/dist/google-one-tap/types.mjs +1 -1
- package/dist/hono/authorizer.cjs +28 -65
- package/dist/hono/authorizer.cjs.map +1 -1
- package/dist/hono/authorizer.d.cts +12 -11
- package/dist/hono/authorizer.d.cts.map +1 -0
- package/dist/hono/authorizer.d.mts +19 -0
- package/dist/hono/authorizer.d.mts.map +1 -0
- package/dist/hono/authorizer.mjs +23 -36
- package/dist/hono/authorizer.mjs.map +1 -1
- package/dist/hono/csrf.cjs +81 -92
- package/dist/hono/csrf.cjs.map +1 -1
- package/dist/hono/csrf.d.cts +46 -45
- package/dist/hono/csrf.d.cts.map +1 -0
- package/dist/hono/csrf.d.mts +76 -0
- package/dist/hono/csrf.d.mts.map +1 -0
- package/dist/hono/csrf.mjs +76 -63
- package/dist/hono/csrf.mjs.map +1 -1
- package/dist/hono/geolocation.cjs +10 -34
- package/dist/hono/geolocation.cjs.map +1 -1
- package/dist/hono/geolocation.d.cts +5 -4
- package/dist/hono/geolocation.d.cts.map +1 -0
- package/dist/hono/geolocation.d.mts +7 -0
- package/dist/hono/geolocation.d.mts.map +1 -0
- package/dist/hono/geolocation.mjs +8 -12
- package/dist/hono/geolocation.mjs.map +1 -1
- package/dist/hono/handler.cjs +37 -61
- package/dist/hono/handler.cjs.map +1 -1
- package/dist/hono/handler.d.cts +26 -25
- package/dist/hono/handler.d.cts.map +1 -0
- package/dist/hono/handler.d.mts +32 -0
- package/dist/hono/handler.d.mts.map +1 -0
- package/dist/hono/handler.mjs +34 -34
- package/dist/hono/handler.mjs.map +1 -1
- package/dist/hono/index.cjs +14 -48
- package/dist/hono/index.d.cts +7 -15
- package/dist/hono/index.d.mts +7 -0
- package/dist/hono/index.mjs +4 -14
- package/dist/hono/rate-limit.cjs +65 -110
- package/dist/hono/rate-limit.cjs.map +1 -1
- package/dist/hono/rate-limit.d.cts +27 -26
- package/dist/hono/rate-limit.d.cts.map +1 -0
- package/dist/hono/rate-limit.d.mts +36 -0
- package/dist/hono/rate-limit.d.mts.map +1 -0
- package/dist/hono/rate-limit.mjs +60 -81
- package/dist/hono/rate-limit.mjs.map +1 -1
- package/dist/hono/validator.cjs +47 -66
- package/dist/hono/validator.cjs.map +1 -1
- package/dist/hono/validator.d.cts +25 -30
- package/dist/hono/validator.d.cts.map +1 -0
- package/dist/hono/validator.d.mts +26 -0
- package/dist/hono/validator.d.mts.map +1 -0
- package/dist/hono/validator.mjs +43 -43
- package/dist/hono/validator.mjs.map +1 -1
- package/dist/index.cjs +39 -95
- package/dist/index.d.cts +12 -14
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +5 -48
- package/dist/iso/iso_3601_1.cjs +1512 -290
- package/dist/iso/iso_3601_1.cjs.map +1 -1
- package/dist/iso/iso_3601_1.d.cts +8 -6
- package/dist/iso/iso_3601_1.d.cts.map +1 -0
- package/dist/iso/iso_3601_1.d.mts +11 -0
- package/dist/iso/iso_3601_1.d.mts.map +1 -0
- package/dist/iso/iso_3601_1.mjs +1511 -265
- package/dist/iso/iso_3601_1.mjs.map +1 -1
- package/dist/max-length/index.cjs +158 -91
- package/dist/max-length/index.cjs.map +1 -1
- package/dist/max-length/index.d.cts +110 -1
- package/dist/max-length/index.d.cts.map +1 -0
- package/dist/{index-BhgdyigB.d.ts → max-length/index.d.mts} +9 -28
- package/dist/max-length/index.d.mts.map +1 -0
- package/dist/max-length/index.mjs +133 -47
- package/dist/max-length/index.mjs.map +1 -1
- package/dist/message.cjs +5 -30
- package/dist/message.cjs.map +1 -1
- package/dist/message.d.cts +3 -1
- package/dist/message.d.cts.map +1 -0
- package/dist/{message.d.ts → message.d.mts} +3 -1
- package/dist/message.d.mts.map +1 -0
- package/dist/message.mjs +5 -6
- package/dist/message.mjs.map +1 -1
- package/dist/polyfills/index.cjs +4 -4
- package/dist/polyfills/index.cjs.map +1 -1
- package/dist/polyfills/index.d.cts +1 -2
- package/dist/polyfills/index.d.mts +1 -0
- package/dist/polyfills/index.mjs +5 -2
- package/dist/polyfills/index.mjs.map +1 -1
- package/dist/response.cjs +191 -208
- package/dist/response.cjs.map +1 -1
- package/dist/response.d.cts +53 -54
- package/dist/response.d.cts.map +1 -0
- package/dist/response.d.mts +82 -0
- package/dist/response.d.mts.map +1 -0
- package/dist/response.mjs +182 -175
- package/dist/response.mjs.map +1 -1
- package/dist/snowflake.cjs +48 -70
- package/dist/snowflake.cjs.map +1 -1
- package/dist/snowflake.d.cts +16 -14
- package/dist/snowflake.d.cts.map +1 -0
- package/dist/snowflake.d.mts +31 -0
- package/dist/snowflake.d.mts.map +1 -0
- package/dist/snowflake.mjs +46 -44
- package/dist/snowflake.mjs.map +1 -1
- package/dist/utils/geolocation.cjs +51 -75
- package/dist/utils/geolocation.cjs.map +1 -1
- package/dist/utils/geolocation.d.cts +14 -12
- package/dist/utils/geolocation.d.cts.map +1 -0
- package/dist/utils/{geolocation.d.ts → geolocation.d.mts} +14 -12
- package/dist/utils/geolocation.d.mts.map +1 -0
- package/dist/utils/geolocation.mjs +47 -47
- package/dist/utils/geolocation.mjs.map +1 -1
- package/dist/utils/google-tag-gateway.cjs +35 -56
- package/dist/utils/google-tag-gateway.cjs.map +1 -1
- package/dist/utils/google-tag-gateway.d.cts +3 -1
- package/dist/utils/google-tag-gateway.d.cts.map +1 -0
- package/dist/utils/{google-tag-gateway.d.ts → google-tag-gateway.d.mts} +3 -1
- package/dist/utils/google-tag-gateway.d.mts.map +1 -0
- package/dist/utils/google-tag-gateway.mjs +33 -30
- package/dist/utils/google-tag-gateway.mjs.map +1 -1
- package/dist/utils/timing.cjs +50 -71
- package/dist/utils/timing.cjs.map +1 -1
- package/dist/utils/timing.d.cts +11 -9
- package/dist/utils/timing.d.cts.map +1 -0
- package/dist/utils/timing.d.mts +15 -0
- package/dist/utils/timing.d.mts.map +1 -0
- package/dist/utils/timing.mjs +49 -46
- package/dist/utils/timing.mjs.map +1 -1
- package/dist/webhook/index.cjs +43 -72
- package/dist/webhook/index.cjs.map +1 -1
- package/dist/webhook/index.d.cts +3 -1
- package/dist/webhook/index.d.cts.map +1 -0
- package/dist/webhook/{index.d.ts → index.d.mts} +3 -1
- package/dist/webhook/index.d.mts.map +1 -0
- package/dist/webhook/index.mjs +41 -46
- package/dist/webhook/index.mjs.map +1 -1
- package/package.json +49 -24
- package/dist/cache/index.d.ts +0 -9
- package/dist/error/detail.d.ts +0 -109
- package/dist/error/i18n/en-us.d.ts +0 -3
- package/dist/error/index.d.ts +0 -19
- package/dist/error/reason.cjs.map +0 -1
- package/dist/error/reason.d.ts +0 -5
- package/dist/error/reason.mjs.map +0 -1
- package/dist/error/status.d.ts +0 -69
- package/dist/google-one-tap/index.d.ts +0 -81
- package/dist/google-one-tap/types.cjs.map +0 -1
- package/dist/google-one-tap/types.d.ts +0 -155
- package/dist/google-one-tap/types.mjs.map +0 -1
- package/dist/hono/authorizer.d.ts +0 -18
- package/dist/hono/csrf.d.ts +0 -75
- package/dist/hono/geolocation.d.ts +0 -6
- package/dist/hono/handler.d.ts +0 -31
- package/dist/hono/index.cjs.map +0 -1
- package/dist/hono/index.d.ts +0 -15
- package/dist/hono/index.mjs.map +0 -1
- package/dist/hono/rate-limit.d.ts +0 -35
- package/dist/hono/validator.d.ts +0 -31
- package/dist/index-BhgdyigB.d.cts +0 -129
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.mjs.map +0 -1
- package/dist/iso/iso_3601_1.d.ts +0 -9
- package/dist/max-length/index.d.ts +0 -1
- package/dist/polyfills/index.d.ts +0 -2
- package/dist/response.d.ts +0 -83
- package/dist/snowflake.d.ts +0 -29
- package/dist/utils/timing.d.ts +0 -13
package/dist/webhook/index.cjs
CHANGED
|
@@ -1,77 +1,48 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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":"
|
|
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"}
|
package/dist/webhook/index.d.cts
CHANGED
|
@@ -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"}
|
package/dist/webhook/index.mjs
CHANGED
|
@@ -1,52 +1,47 @@
|
|
|
1
|
-
// src/webhook/index.ts
|
|
2
|
-
import { createHmac, timingSafeEqual } from "crypto";
|
|
3
1
|
import { Status } from "../error/status.mjs";
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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":"
|
|
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.
|
|
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
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
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.
|
|
69
|
+
"vitest": "^4.1.10",
|
|
45
70
|
"zod": "^4.4.3",
|
|
46
|
-
"@shware/utils": "^1.
|
|
71
|
+
"@shware/utils": "^1.5.0"
|
|
47
72
|
},
|
|
48
73
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^26.1.
|
|
74
|
+
"@types/node": "^26.1.1",
|
|
50
75
|
"@types/react": "^19.2.17",
|
|
51
|
-
"typescript": "^
|
|
76
|
+
"typescript": "^7.0.2",
|
|
52
77
|
"@repo/typescript-config": "0.0.0"
|
|
53
78
|
},
|
|
54
79
|
"peerDependencies": {
|
|
55
|
-
"hono": "^4.12.
|
|
56
|
-
"i18next": "^26.3.
|
|
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": "
|
|
97
|
+
"build": "tsdown",
|
|
73
98
|
"test": "vitest run",
|
|
74
99
|
"check-types": "tsc --noEmit",
|
|
75
100
|
"lint": "oxlint --type-aware . --fix"
|
package/dist/cache/index.d.ts
DELETED
package/dist/error/detail.d.ts
DELETED
|
@@ -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 };
|
package/dist/error/index.d.ts
DELETED
|
@@ -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":[]}
|
package/dist/error/reason.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|