@bizjaya/finclient 0.1.1 → 0.2.1
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/README.md +57 -22
- package/dist/index.cjs +372 -160
- package/dist/index.d.cts +3299 -657
- package/dist/index.d.ts +3299 -657
- package/dist/index.js +371 -159
- package/dist/webhook.cjs +49 -0
- package/dist/webhook.d.cts +11 -0
- package/dist/webhook.d.ts +11 -0
- package/dist/webhook.js +24 -0
- package/package.json +19 -8
package/dist/webhook.cjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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.ts
|
|
21
|
+
var webhook_exports = {};
|
|
22
|
+
__export(webhook_exports, {
|
|
23
|
+
FinWebhook: () => FinWebhook
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(webhook_exports);
|
|
26
|
+
var import_node_crypto = require("crypto");
|
|
27
|
+
var FinWebhook = class {
|
|
28
|
+
static allowedSkewSeconds = 300;
|
|
29
|
+
/** Verify X-FinCopy-Signature over the timestamp and the exact raw request body. */
|
|
30
|
+
static verify(secret, timestamp, body, signature) {
|
|
31
|
+
if (!secret || !signature) return false;
|
|
32
|
+
const timestampText = String(timestamp);
|
|
33
|
+
if (!/^\d+$/.test(timestampText)) return false;
|
|
34
|
+
const seconds = Number(timestampText);
|
|
35
|
+
if (!Number.isSafeInteger(seconds)) return false;
|
|
36
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
37
|
+
if (now - seconds > this.allowedSkewSeconds || seconds - now > this.allowedSkewSeconds) return false;
|
|
38
|
+
const suppliedHex = signature.startsWith("sha256=") ? signature.slice(7) : signature;
|
|
39
|
+
if (!/^[a-fA-F0-9]{64}$/.test(suppliedHex)) return false;
|
|
40
|
+
const supplied = Buffer.from(suppliedHex, "hex");
|
|
41
|
+
const signedBody = Buffer.isBuffer(body) ? body : Buffer.from(body);
|
|
42
|
+
const expected = (0, import_node_crypto.createHmac)("sha256", Buffer.from(secret, "utf8")).update(Buffer.from(`${timestampText}.`, "utf8")).update(signedBody).digest();
|
|
43
|
+
return supplied.length === expected.length && (0, import_node_crypto.timingSafeEqual)(supplied, expected);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
FinWebhook
|
|
49
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies the HMAC-SHA256 signature on a FinCopy webhook request. Server-side (Node.js) only, so it is its own entry,
|
|
3
|
+
* `@bizjaya/finclient/webhook`, and the main entry stays free of Node built-ins for browsers.
|
|
4
|
+
*/
|
|
5
|
+
declare class FinWebhook {
|
|
6
|
+
private static readonly allowedSkewSeconds;
|
|
7
|
+
/** Verify X-FinCopy-Signature over the timestamp and the exact raw request body. */
|
|
8
|
+
static verify(secret: string, timestamp: string | number, body: string | Uint8Array, signature: string): boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { FinWebhook };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies the HMAC-SHA256 signature on a FinCopy webhook request. Server-side (Node.js) only, so it is its own entry,
|
|
3
|
+
* `@bizjaya/finclient/webhook`, and the main entry stays free of Node built-ins for browsers.
|
|
4
|
+
*/
|
|
5
|
+
declare class FinWebhook {
|
|
6
|
+
private static readonly allowedSkewSeconds;
|
|
7
|
+
/** Verify X-FinCopy-Signature over the timestamp and the exact raw request body. */
|
|
8
|
+
static verify(secret: string, timestamp: string | number, body: string | Uint8Array, signature: string): boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { FinWebhook };
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/webhook.ts
|
|
2
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
3
|
+
var FinWebhook = class {
|
|
4
|
+
static allowedSkewSeconds = 300;
|
|
5
|
+
/** Verify X-FinCopy-Signature over the timestamp and the exact raw request body. */
|
|
6
|
+
static verify(secret, timestamp, body, signature) {
|
|
7
|
+
if (!secret || !signature) return false;
|
|
8
|
+
const timestampText = String(timestamp);
|
|
9
|
+
if (!/^\d+$/.test(timestampText)) return false;
|
|
10
|
+
const seconds = Number(timestampText);
|
|
11
|
+
if (!Number.isSafeInteger(seconds)) return false;
|
|
12
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
13
|
+
if (now - seconds > this.allowedSkewSeconds || seconds - now > this.allowedSkewSeconds) return false;
|
|
14
|
+
const suppliedHex = signature.startsWith("sha256=") ? signature.slice(7) : signature;
|
|
15
|
+
if (!/^[a-fA-F0-9]{64}$/.test(suppliedHex)) return false;
|
|
16
|
+
const supplied = Buffer.from(suppliedHex, "hex");
|
|
17
|
+
const signedBody = Buffer.isBuffer(body) ? body : Buffer.from(body);
|
|
18
|
+
const expected = createHmac("sha256", Buffer.from(secret, "utf8")).update(Buffer.from(`${timestampText}.`, "utf8")).update(signedBody).digest();
|
|
19
|
+
return supplied.length === expected.length && timingSafeEqual(supplied, expected);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
FinWebhook
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bizjaya/finclient",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Official TypeScript SDK for the FinCopy public API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BizJaya TechLab S/B",
|
|
@@ -25,6 +25,17 @@
|
|
|
25
25
|
"default": "./dist/index.cjs"
|
|
26
26
|
},
|
|
27
27
|
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./webhook": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/webhook.d.ts",
|
|
32
|
+
"default": "./dist/webhook.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/webhook.d.cts",
|
|
36
|
+
"default": "./dist/webhook.cjs"
|
|
37
|
+
},
|
|
38
|
+
"default": "./dist/webhook.js"
|
|
28
39
|
}
|
|
29
40
|
},
|
|
30
41
|
"files": [
|
|
@@ -34,22 +45,22 @@
|
|
|
34
45
|
],
|
|
35
46
|
"sideEffects": false,
|
|
36
47
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
48
|
+
"node": ">=20"
|
|
38
49
|
},
|
|
39
50
|
"scripts": {
|
|
40
51
|
"generate:types": "openapi-typescript ../spec/fincopy-v1.json --output src/generated/schema.d.ts",
|
|
41
52
|
"prepack": "node -e \"require('fs').copyFileSync('../LICENSE', 'LICENSE')\"",
|
|
42
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean --target
|
|
53
|
+
"build": "tsup src/index.ts src/webhook.ts --format esm,cjs --dts --clean --target node20",
|
|
43
54
|
"typecheck": "tsc --noEmit",
|
|
44
55
|
"test": "vitest run"
|
|
45
56
|
},
|
|
46
57
|
"devDependencies": {
|
|
47
|
-
"@types/node": "
|
|
48
|
-
"openapi-typescript": "7.
|
|
49
|
-
"tsup": "
|
|
58
|
+
"@types/node": "26.6.5",
|
|
59
|
+
"openapi-typescript": "7.13.0",
|
|
60
|
+
"tsup": "9.0.0",
|
|
50
61
|
"typescript": "5.9.3",
|
|
51
|
-
"vite": "
|
|
52
|
-
"vitest": "
|
|
62
|
+
"vite": "8.3.4",
|
|
63
|
+
"vitest": "5.0.5"
|
|
53
64
|
},
|
|
54
65
|
"publishConfig": {
|
|
55
66
|
"access": "public",
|