meterflow 0.1.0 → 0.2.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/README.md CHANGED
@@ -61,7 +61,7 @@ const client = new MeterFlow({
61
61
  ## Webhook verification
62
62
 
63
63
  ```typescript
64
- import { verifyWebhook } from "meterflow";
64
+ import { verifyWebhook } from "meterflow/webhook";
65
65
 
66
66
  const isValid = verifyWebhook(rawBody, req.headers["x-meterflow-signature"], webhookSecret);
67
67
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IAClD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,SAAS;IACpB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAE7C,OAAO,CAAC,QAAQ,CAAC,CAAkB;IACnC,OAAO,CAAC,MAAM,CAAC,CAAgB;IAC/B,OAAO,CAA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AAkB;IACnC,OAAO,CAAC,MAAM,CAAC,CAAgB;IAC/B,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,MAAM,CAAC,CAAgB;gBAEnB,OAAO,EAAE,gBAAgB;IAerC,IAAI,OAAO,IAAI,eAAe,CAE7B;IAED,IAAI,KAAK,IAAI,aAAa,CAEzB;IAED,IAAI,aAAa,IAAI,qBAAqB,CAEzC;IAED,IAAI,KAAK,IAAI,aAAa,CAEzB;IAED,4EAA4E;IAC5E,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;CAG5E"}
package/dist/index.cjs CHANGED
@@ -28,8 +28,7 @@ __export(index_exports, {
28
28
  NotFoundError: () => NotFoundError,
29
29
  RateLimitError: () => RateLimitError,
30
30
  ServerError: () => ServerError,
31
- ValidationError: () => ValidationError,
32
- verifyWebhook: () => verifyWebhook
31
+ ValidationError: () => ValidationError
33
32
  });
34
33
  module.exports = __toCommonJS(index_exports);
35
34
 
@@ -122,7 +121,7 @@ async function retryable(fn, opts, shouldRetry = () => true) {
122
121
  }
123
122
 
124
123
  // src/utils/http.ts
125
- var SDK_VERSION = "0.1.0";
124
+ var SDK_VERSION = "0.2.0";
126
125
  function buildUrl(baseUrl, path, query) {
127
126
  const url = new URL(path, baseUrl.endsWith("/") ? baseUrl : baseUrl + "/");
128
127
  if (query) {
@@ -312,7 +311,9 @@ var MeterFlow = class {
312
311
  baseUrl: options.baseUrl ?? "https://api.meterflow.com/api/v1",
313
312
  timeout: options.timeout ?? 3e4,
314
313
  retries: options.retries ?? 3,
315
- fetch: options.fetch ?? globalThis.fetch
314
+ // Bind to globalThis: browsers throw "Illegal invocation" if window.fetch is
315
+ // called detached from window (Node tolerates it, so this only bites in the browser).
316
+ fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
316
317
  };
317
318
  }
318
319
  get credits() {
@@ -332,17 +333,6 @@ var MeterFlow = class {
332
333
  return httpRequest(this.options, method, path, opts);
333
334
  }
334
335
  };
335
-
336
- // src/utils/webhook-verify.ts
337
- var import_crypto = require("crypto");
338
- function verifyWebhook(rawBody, signature, secret) {
339
- const body = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
340
- const expected = (0, import_crypto.createHmac)("sha256", secret).update(body).digest("hex");
341
- const expectedBuf = Buffer.from(expected, "utf8");
342
- const actualBuf = Buffer.from(signature, "utf8");
343
- if (expectedBuf.length !== actualBuf.length) return false;
344
- return (0, import_crypto.timingSafeEqual)(expectedBuf, actualBuf);
345
- }
346
336
  // Annotate the CommonJS export names for ESM import in node:
347
337
  0 && (module.exports = {
348
338
  AuthError,
@@ -353,6 +343,5 @@ function verifyWebhook(rawBody, signature, secret) {
353
343
  NotFoundError,
354
344
  RateLimitError,
355
345
  ServerError,
356
- ValidationError,
357
- verifyWebhook
346
+ ValidationError
358
347
  });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export { MeterFlow } from "./client";
2
- export { verifyWebhook } from "./utils/webhook-verify";
3
2
  export { MeterFlowError, AuthError, NotFoundError, InsufficientCreditsError, ConflictError, ValidationError, RateLimitError, ServerError, } from "./errors";
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,SAAS,EACT,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,cAAc,EACd,WAAW,GACZ,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIrC,OAAO,EACL,cAAc,EACd,SAAS,EACT,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,cAAc,EACd,WAAW,GACZ,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -28,8 +28,7 @@ __export(index_exports, {
28
28
  NotFoundError: () => NotFoundError,
29
29
  RateLimitError: () => RateLimitError,
30
30
  ServerError: () => ServerError,
31
- ValidationError: () => ValidationError,
32
- verifyWebhook: () => verifyWebhook
31
+ ValidationError: () => ValidationError
33
32
  });
34
33
  module.exports = __toCommonJS(index_exports);
35
34
 
@@ -122,7 +121,7 @@ async function retryable(fn, opts, shouldRetry = () => true) {
122
121
  }
123
122
 
124
123
  // src/utils/http.ts
125
- var SDK_VERSION = "0.1.0";
124
+ var SDK_VERSION = "0.2.0";
126
125
  function buildUrl(baseUrl, path, query) {
127
126
  const url = new URL(path, baseUrl.endsWith("/") ? baseUrl : baseUrl + "/");
128
127
  if (query) {
@@ -312,7 +311,9 @@ var MeterFlow = class {
312
311
  baseUrl: options.baseUrl ?? "https://api.meterflow.com/api/v1",
313
312
  timeout: options.timeout ?? 3e4,
314
313
  retries: options.retries ?? 3,
315
- fetch: options.fetch ?? globalThis.fetch
314
+ // Bind to globalThis: browsers throw "Illegal invocation" if window.fetch is
315
+ // called detached from window (Node tolerates it, so this only bites in the browser).
316
+ fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
316
317
  };
317
318
  }
318
319
  get credits() {
@@ -332,17 +333,6 @@ var MeterFlow = class {
332
333
  return httpRequest(this.options, method, path, opts);
333
334
  }
334
335
  };
335
-
336
- // src/utils/webhook-verify.ts
337
- var import_crypto = require("crypto");
338
- function verifyWebhook(rawBody, signature, secret) {
339
- const body = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
340
- const expected = (0, import_crypto.createHmac)("sha256", secret).update(body).digest("hex");
341
- const expectedBuf = Buffer.from(expected, "utf8");
342
- const actualBuf = Buffer.from(signature, "utf8");
343
- if (expectedBuf.length !== actualBuf.length) return false;
344
- return (0, import_crypto.timingSafeEqual)(expectedBuf, actualBuf);
345
- }
346
336
  // Annotate the CommonJS export names for ESM import in node:
347
337
  0 && (module.exports = {
348
338
  AuthError,
@@ -353,6 +343,5 @@ function verifyWebhook(rawBody, signature, secret) {
353
343
  NotFoundError,
354
344
  RateLimitError,
355
345
  ServerError,
356
- ValidationError,
357
- verifyWebhook
346
+ ValidationError
358
347
  });
package/dist/index.mjs CHANGED
@@ -87,7 +87,7 @@ async function retryable(fn, opts, shouldRetry = () => true) {
87
87
  }
88
88
 
89
89
  // src/utils/http.ts
90
- var SDK_VERSION = "0.1.0";
90
+ var SDK_VERSION = "0.2.0";
91
91
  function buildUrl(baseUrl, path, query) {
92
92
  const url = new URL(path, baseUrl.endsWith("/") ? baseUrl : baseUrl + "/");
93
93
  if (query) {
@@ -277,7 +277,9 @@ var MeterFlow = class {
277
277
  baseUrl: options.baseUrl ?? "https://api.meterflow.com/api/v1",
278
278
  timeout: options.timeout ?? 3e4,
279
279
  retries: options.retries ?? 3,
280
- fetch: options.fetch ?? globalThis.fetch
280
+ // Bind to globalThis: browsers throw "Illegal invocation" if window.fetch is
281
+ // called detached from window (Node tolerates it, so this only bites in the browser).
282
+ fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
281
283
  };
282
284
  }
283
285
  get credits() {
@@ -297,17 +299,6 @@ var MeterFlow = class {
297
299
  return httpRequest(this.options, method, path, opts);
298
300
  }
299
301
  };
300
-
301
- // src/utils/webhook-verify.ts
302
- import { createHmac, timingSafeEqual } from "crypto";
303
- function verifyWebhook(rawBody, signature, secret) {
304
- const body = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
305
- const expected = createHmac("sha256", secret).update(body).digest("hex");
306
- const expectedBuf = Buffer.from(expected, "utf8");
307
- const actualBuf = Buffer.from(signature, "utf8");
308
- if (expectedBuf.length !== actualBuf.length) return false;
309
- return timingSafeEqual(expectedBuf, actualBuf);
310
- }
311
302
  export {
312
303
  AuthError,
313
304
  ConflictError,
@@ -317,6 +308,5 @@ export {
317
308
  NotFoundError,
318
309
  RateLimitError,
319
310
  ServerError,
320
- ValidationError,
321
- verifyWebhook
311
+ ValidationError
322
312
  };
@@ -0,0 +1,40 @@
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
+ verifyWebhook: () => verifyWebhook
24
+ });
25
+ module.exports = __toCommonJS(webhook_exports);
26
+
27
+ // src/utils/webhook-verify.ts
28
+ var import_crypto = require("crypto");
29
+ function verifyWebhook(rawBody, signature, secret) {
30
+ const body = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
31
+ const expected = (0, import_crypto.createHmac)("sha256", secret).update(body).digest("hex");
32
+ const expectedBuf = Buffer.from(expected, "utf8");
33
+ const actualBuf = Buffer.from(signature, "utf8");
34
+ if (expectedBuf.length !== actualBuf.length) return false;
35
+ return (0, import_crypto.timingSafeEqual)(expectedBuf, actualBuf);
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ verifyWebhook
40
+ });
@@ -0,0 +1,2 @@
1
+ export { verifyWebhook } from "./utils/webhook-verify";
2
+ //# sourceMappingURL=webhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/webhook.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,13 @@
1
+ // src/utils/webhook-verify.ts
2
+ import { createHmac, timingSafeEqual } from "crypto";
3
+ function verifyWebhook(rawBody, signature, secret) {
4
+ const body = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
5
+ const expected = createHmac("sha256", secret).update(body).digest("hex");
6
+ const expectedBuf = Buffer.from(expected, "utf8");
7
+ const actualBuf = Buffer.from(signature, "utf8");
8
+ if (expectedBuf.length !== actualBuf.length) return false;
9
+ return timingSafeEqual(expectedBuf, actualBuf);
10
+ }
11
+ export {
12
+ verifyWebhook
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meterflow",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Official Node.js SDK for MeterFlow — usage-based billing, credit management, and metering.",
5
5
  "license": "MIT",
6
6
  "author": "MeterFlow",
@@ -17,16 +17,22 @@
17
17
  "types": "dist/index.d.ts",
18
18
  "exports": {
19
19
  ".": {
20
+ "types": "./dist/index.d.ts",
20
21
  "import": "./dist/index.mjs",
21
- "require": "./dist/index.cjs",
22
- "types": "./dist/index.d.ts"
22
+ "require": "./dist/index.cjs"
23
+ },
24
+ "./webhook": {
25
+ "types": "./dist/webhook.d.ts",
26
+ "import": "./dist/webhook.mjs",
27
+ "require": "./dist/webhook.cjs"
23
28
  }
24
29
  },
25
30
  "files": [
26
31
  "dist"
27
32
  ],
28
33
  "scripts": {
29
- "build": "tsc --project tsconfig.json --emitDeclarationOnly && node scripts/build-fix.mjs && esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.mjs && esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.cjs && node -e \"require('fs').copyFileSync('dist/index.cjs','dist/index.js')\"",
34
+ "prepublishOnly": "npm run build",
35
+ "build": "tsc --project tsconfig.json --emitDeclarationOnly && node scripts/build-fix.mjs && esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.mjs && esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.cjs && esbuild src/webhook.ts --bundle --platform=node --format=esm --outfile=dist/webhook.mjs && esbuild src/webhook.ts --bundle --platform=node --format=cjs --outfile=dist/webhook.cjs && node -e \"require('fs').copyFileSync('dist/index.cjs','dist/index.js')\"",
30
36
  "dev": "tsc --project tsconfig.json --watch",
31
37
  "quickstart": "npm run build && npx tsx examples/quickstart.ts",
32
38
  "typecheck": "tsc --noEmit",