@dobbykit/lib 0.0.0-stage → 0.4.13
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/LICENSE +21 -0
- package/README.md +347 -2
- package/dist/analytics/index.d.ts +64 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +175 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/api/client.d.ts +36 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +228 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/codes.d.ts +4 -0
- package/dist/api/codes.d.ts.map +1 -0
- package/dist/api/codes.js +58 -0
- package/dist/api/codes.js.map +1 -0
- package/dist/api/contract.d.ts +12 -0
- package/dist/api/contract.d.ts.map +1 -0
- package/dist/api/contract.js +7 -0
- package/dist/api/contract.js.map +1 -0
- package/dist/api/copy.d.ts +13 -0
- package/dist/api/copy.d.ts.map +1 -0
- package/dist/api/copy.js +253 -0
- package/dist/api/copy.js.map +1 -0
- package/dist/api/errors.d.ts +26 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +44 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +7 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/query-client.d.ts +19 -0
- package/dist/api/query-client.d.ts.map +1 -0
- package/dist/api/query-client.js +52 -0
- package/dist/api/query-client.js.map +1 -0
- package/dist/api/stream.d.ts +11 -0
- package/dist/api/stream.d.ts.map +1 -0
- package/dist/api/stream.js +82 -0
- package/dist/api/stream.js.map +1 -0
- package/dist/crypto/index.d.ts +10 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +85 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/form/index.d.ts +32 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +88 -0
- package/dist/form/index.js.map +1 -0
- package/dist/format/date.d.ts +15 -0
- package/dist/format/date.d.ts.map +1 -0
- package/dist/format/date.js +109 -0
- package/dist/format/date.js.map +1 -0
- package/dist/format/index.d.ts +16 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +123 -0
- package/dist/format/index.js.map +1 -0
- package/dist/offline/index.d.ts +13 -0
- package/dist/offline/index.d.ts.map +1 -0
- package/dist/offline/index.js +62 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/search/engine.d.ts +56 -0
- package/dist/search/engine.d.ts.map +1 -0
- package/dist/search/engine.js +140 -0
- package/dist/search/engine.js.map +1 -0
- package/dist/search/index.d.ts +5 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +5 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/readers.d.ts +47 -0
- package/dist/search/readers.d.ts.map +1 -0
- package/dist/search/readers.js +227 -0
- package/dist/search/readers.js.map +1 -0
- package/dist/search/text.d.ts +6 -0
- package/dist/search/text.d.ts.map +1 -0
- package/dist/search/text.js +80 -0
- package/dist/search/text.js.map +1 -0
- package/dist/search/usage.d.ts +15 -0
- package/dist/search/usage.d.ts.map +1 -0
- package/dist/search/usage.js +45 -0
- package/dist/search/usage.js.map +1 -0
- package/dist/session/index.d.ts +28 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +140 -0
- package/dist/session/index.js.map +1 -0
- package/dist/storage/file.d.ts +3 -0
- package/dist/storage/file.d.ts.map +1 -0
- package/dist/storage/file.js +47 -0
- package/dist/storage/file.js.map +1 -0
- package/dist/storage/index.d.ts +42 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +192 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/sync/index.d.ts +51 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +61 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/telemetry/index.d.ts +39 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +134 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/webhooks/index.d.ts +14 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +47 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +127 -4
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const enc = new TextEncoder();
|
|
2
|
+
const b64 = (b) => btoa(String.fromCharCode(...b));
|
|
3
|
+
function keyBytes(secret) {
|
|
4
|
+
return Uint8Array.from(atob(secret.replace(/^whsec_/, "")), (c) => c.charCodeAt(0));
|
|
5
|
+
}
|
|
6
|
+
async function hmac(secret, content) {
|
|
7
|
+
const k = await crypto.subtle.importKey("raw", keyBytes(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
8
|
+
return b64(new Uint8Array(await crypto.subtle.sign("HMAC", k, enc.encode(content))));
|
|
9
|
+
}
|
|
10
|
+
function same(a, b) {
|
|
11
|
+
if (a.length !== b.length)
|
|
12
|
+
return false;
|
|
13
|
+
let d = 0;
|
|
14
|
+
for (let i = 0; i < a.length; i++)
|
|
15
|
+
d |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
16
|
+
return d === 0;
|
|
17
|
+
}
|
|
18
|
+
export function generateWebhookSecret() {
|
|
19
|
+
return `whsec_${b64(crypto.getRandomValues(new Uint8Array(32)))}`;
|
|
20
|
+
}
|
|
21
|
+
export async function signWebhook(input) {
|
|
22
|
+
const ts = String(input.timestamp ?? Math.floor(Date.now() / 1000));
|
|
23
|
+
const secrets = typeof input.secret === "string" ? [input.secret] : input.secret;
|
|
24
|
+
const sigs = await Promise.all(secrets.map(async (s) => `v1,${await hmac(s, `${input.id}.${ts}.${input.body}`)}`));
|
|
25
|
+
return { "webhook-id": input.id, "webhook-timestamp": ts, "webhook-signature": sigs.join(" ") };
|
|
26
|
+
}
|
|
27
|
+
export async function verifyWebhook(secret, headers, body, opts = {}) {
|
|
28
|
+
const p = opts.headerPrefix ?? "webhook";
|
|
29
|
+
const get = (n) => headers instanceof Headers ? headers.get(n) : (headers[n] ?? headers[n.toLowerCase()] ?? null);
|
|
30
|
+
const id = get(`${p}-id`);
|
|
31
|
+
const ts = get(`${p}-timestamp`);
|
|
32
|
+
const sigs = get(`${p}-signature`);
|
|
33
|
+
if (!id || !ts || !sigs || !/^\d+$/.test(ts))
|
|
34
|
+
return false;
|
|
35
|
+
const now = Math.floor((opts.now ?? Date.now()) / 1000);
|
|
36
|
+
if (Math.abs(now - Number(ts)) > (opts.toleranceSeconds ?? 300))
|
|
37
|
+
return false;
|
|
38
|
+
let expected;
|
|
39
|
+
try {
|
|
40
|
+
expected = await hmac(secret, `${id}.${ts}.${body}`);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return sigs.split(" ").some((s) => s.startsWith("v1,") && same(s.slice(3), expected));
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/webhooks/index.ts"],"names":[],"mappings":"AAeA,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAA;AAE7B,MAAM,GAAG,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAE9D,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AACrF,CAAC;AAED,KAAK,UAAU,IAAI,CAAC,MAAc,EAAE,OAAe;IACjD,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CACrC,KAAK,EACL,QAAQ,CAAC,MA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I,CAAC,GAAG,CAAC,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,IAAI,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA;IAC7E,IAAI,QAAgB,CAAA;IACpB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAA;AACvF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,129 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dobbykit/lib",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.4.13",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Dobby Kit client primitives. API client, the wire contract, and search.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"dobby-kit",
|
|
8
|
+
"api-client",
|
|
9
|
+
"fetch",
|
|
10
|
+
"format",
|
|
11
|
+
"react-query"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://signet.dapplelight.in/",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/dapplelight/dobby-kit.git",
|
|
17
|
+
"directory": "packages/lib"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/dapplelight/dobby-kit/issues"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"exports": {
|
|
25
|
+
"./api": {
|
|
26
|
+
"types": "./dist/api/index.d.ts",
|
|
27
|
+
"import": "./dist/api/index.js",
|
|
28
|
+
"default": "./dist/api/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./api/query-client": {
|
|
31
|
+
"types": "./dist/api/query-client.d.ts",
|
|
32
|
+
"import": "./dist/api/query-client.js",
|
|
33
|
+
"default": "./dist/api/query-client.js"
|
|
34
|
+
},
|
|
35
|
+
"./format": {
|
|
36
|
+
"types": "./dist/format/index.d.ts",
|
|
37
|
+
"import": "./dist/format/index.js",
|
|
38
|
+
"default": "./dist/format/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./analytics": {
|
|
41
|
+
"types": "./dist/analytics/index.d.ts",
|
|
42
|
+
"import": "./dist/analytics/index.js",
|
|
43
|
+
"default": "./dist/analytics/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./telemetry": {
|
|
46
|
+
"types": "./dist/telemetry/index.d.ts",
|
|
47
|
+
"import": "./dist/telemetry/index.js",
|
|
48
|
+
"default": "./dist/telemetry/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./crypto": {
|
|
51
|
+
"types": "./dist/crypto/index.d.ts",
|
|
52
|
+
"import": "./dist/crypto/index.js",
|
|
53
|
+
"default": "./dist/crypto/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./webhooks": {
|
|
56
|
+
"types": "./dist/webhooks/index.d.ts",
|
|
57
|
+
"import": "./dist/webhooks/index.js",
|
|
58
|
+
"default": "./dist/webhooks/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./form": {
|
|
61
|
+
"types": "./dist/form/index.d.ts",
|
|
62
|
+
"import": "./dist/form/index.js",
|
|
63
|
+
"default": "./dist/form/index.js"
|
|
64
|
+
},
|
|
65
|
+
"./search": {
|
|
66
|
+
"types": "./dist/search/index.d.ts",
|
|
67
|
+
"import": "./dist/search/index.js",
|
|
68
|
+
"default": "./dist/search/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./offline": {
|
|
71
|
+
"types": "./dist/offline/index.d.ts",
|
|
72
|
+
"import": "./dist/offline/index.js",
|
|
73
|
+
"default": "./dist/offline/index.js"
|
|
74
|
+
},
|
|
75
|
+
"./storage": {
|
|
76
|
+
"types": "./dist/storage/index.d.ts",
|
|
77
|
+
"import": "./dist/storage/index.js",
|
|
78
|
+
"default": "./dist/storage/index.js"
|
|
79
|
+
},
|
|
80
|
+
"./storage/file": {
|
|
81
|
+
"types": "./dist/storage/file.d.ts",
|
|
82
|
+
"import": "./dist/storage/file.js",
|
|
83
|
+
"default": "./dist/storage/file.js"
|
|
84
|
+
},
|
|
85
|
+
"./sync": {
|
|
86
|
+
"types": "./dist/sync/index.d.ts",
|
|
87
|
+
"import": "./dist/sync/index.js",
|
|
88
|
+
"default": "./dist/sync/index.js"
|
|
89
|
+
},
|
|
90
|
+
"./session": {
|
|
91
|
+
"types": "./dist/session/index.d.ts",
|
|
92
|
+
"import": "./dist/session/index.js",
|
|
93
|
+
"default": "./dist/session/index.js"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"scripts": {
|
|
97
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json && tsc --noEmit -p tsconfig.search.json",
|
|
98
|
+
"test": "bun run test/platform.ts && bun run test/smoke.ts && bun run test/storage.ts && bun run test/session.ts && bun run test/sync.ts && bun run test/offline.ts && bun run test/format.ts && bun run test/date.ts && bun run test/date-only.ts America/Los_Angeles && bun run test/date-only.ts Asia/Kolkata && bun run test/analytics.ts && bun run test/telemetry.ts && bun run test/form.ts && bun run test/copy.ts && bun run test/crypto.ts && bun run test/webhooks.ts && bun run test/stream.ts && bun test test/search",
|
|
99
|
+
"build": "tsc -p tsconfig.build.json",
|
|
100
|
+
"prepublishOnly": "bun run build"
|
|
101
|
+
},
|
|
102
|
+
"peerDependencies": {
|
|
103
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
104
|
+
"@tanstack/react-form": ">=1.0.0"
|
|
105
|
+
},
|
|
106
|
+
"peerDependenciesMeta": {
|
|
107
|
+
"@tanstack/react-query": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"@tanstack/react-form": {
|
|
111
|
+
"optional": true
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"devDependencies": {
|
|
115
|
+
"@tanstack/react-form": "^1.33.5",
|
|
116
|
+
"@tanstack/react-query": "^5.108.0",
|
|
117
|
+
"@types/bun": "^1.4.4",
|
|
118
|
+
"@types/node": "^26.6.6",
|
|
119
|
+
"fast-check": "^4.10.2",
|
|
120
|
+
"typescript": "^7.0.2",
|
|
121
|
+
"zod": "^4.6.7"
|
|
122
|
+
},
|
|
123
|
+
"publishConfig": {
|
|
124
|
+
"access": "public"
|
|
125
|
+
},
|
|
126
|
+
"files": [
|
|
127
|
+
"dist"
|
|
128
|
+
]
|
|
129
|
+
}
|