@open-apime/sdk 0.2.2

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.
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/types/index.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,46 @@
1
+ export { C as ChatPresencePayload, a as ContactReachoutLockedPayload, b as ContactUpdatePayload, D as DisconnectedPayload, M as MessageButton, c as MessagePayload, P as PresencePayload, R as ReceiptPayload, d as RestrictionLiftedPayload, T as TemporaryBanPayload, W as WebhookEnvelope, e as WebhookEvent, f as WebhookEventType } from '../events-BV5UVoFu.cjs';
2
+
3
+ /** Shapes the apime returns. Field names are the ones on the wire. */
4
+ interface Instance {
5
+ id: string;
6
+ name: string;
7
+ status: string;
8
+ ownerUserId?: string;
9
+ webhook_url?: string;
10
+ phone?: string;
11
+ createdAt?: string;
12
+ updatedAt?: string;
13
+ }
14
+ interface InstanceInfo {
15
+ id: string;
16
+ connected: boolean;
17
+ jid?: string;
18
+ pushName?: string;
19
+ phone?: string;
20
+ }
21
+ interface QrCode {
22
+ qr: string;
23
+ instanceId?: string;
24
+ timeout?: number;
25
+ }
26
+ interface EventLogEntry {
27
+ id: string;
28
+ instanceId: string;
29
+ type: string;
30
+ payload: string;
31
+ createdAt: string;
32
+ }
33
+ interface SentMessage {
34
+ /** WhatsApp side id, used later to edit, delete and match receipts. */
35
+ whatsappId?: string;
36
+ id?: string;
37
+ status?: string;
38
+ }
39
+ interface Profile {
40
+ jid?: string;
41
+ pushName?: string;
42
+ status?: string;
43
+ pictureUrl?: string;
44
+ }
45
+
46
+ export type { EventLogEntry, Instance, InstanceInfo, Profile, QrCode, SentMessage };
@@ -0,0 +1,46 @@
1
+ export { C as ChatPresencePayload, a as ContactReachoutLockedPayload, b as ContactUpdatePayload, D as DisconnectedPayload, M as MessageButton, c as MessagePayload, P as PresencePayload, R as ReceiptPayload, d as RestrictionLiftedPayload, T as TemporaryBanPayload, W as WebhookEnvelope, e as WebhookEvent, f as WebhookEventType } from '../events-BV5UVoFu.js';
2
+
3
+ /** Shapes the apime returns. Field names are the ones on the wire. */
4
+ interface Instance {
5
+ id: string;
6
+ name: string;
7
+ status: string;
8
+ ownerUserId?: string;
9
+ webhook_url?: string;
10
+ phone?: string;
11
+ createdAt?: string;
12
+ updatedAt?: string;
13
+ }
14
+ interface InstanceInfo {
15
+ id: string;
16
+ connected: boolean;
17
+ jid?: string;
18
+ pushName?: string;
19
+ phone?: string;
20
+ }
21
+ interface QrCode {
22
+ qr: string;
23
+ instanceId?: string;
24
+ timeout?: number;
25
+ }
26
+ interface EventLogEntry {
27
+ id: string;
28
+ instanceId: string;
29
+ type: string;
30
+ payload: string;
31
+ createdAt: string;
32
+ }
33
+ interface SentMessage {
34
+ /** WhatsApp side id, used later to edit, delete and match receipts. */
35
+ whatsappId?: string;
36
+ id?: string;
37
+ status?: string;
38
+ }
39
+ interface Profile {
40
+ jid?: string;
41
+ pushName?: string;
42
+ status?: string;
43
+ pictureUrl?: string;
44
+ }
45
+
46
+ export type { EventLogEntry, Instance, InstanceInfo, Profile, QrCode, SentMessage };
@@ -0,0 +1 @@
1
+ import "../chunk-2BUPSB7O.js";
@@ -0,0 +1,78 @@
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
+ InvalidSignatureError: () => InvalidSignatureError,
24
+ SIGNATURE_HEADER: () => SIGNATURE_HEADER,
25
+ constructEvent: () => constructEvent,
26
+ verifyWebhookSignature: () => verifyWebhookSignature
27
+ });
28
+ module.exports = __toCommonJS(webhook_exports);
29
+ var import_node_crypto = require("crypto");
30
+
31
+ // src/errors/index.ts
32
+ var ApimeError = class extends Error {
33
+ status;
34
+ body;
35
+ /** Value of the request id header, when the response carried one. */
36
+ requestId;
37
+ constructor(message, options = {}) {
38
+ super(message, options.cause !== void 0 ? { cause: options.cause } : void 0);
39
+ this.name = new.target.name;
40
+ this.status = options.status;
41
+ this.body = options.body;
42
+ this.requestId = options.requestId;
43
+ }
44
+ };
45
+
46
+ // src/webhook/index.ts
47
+ var SIGNATURE_HEADER = "X-ApiMe-Signature";
48
+ var InvalidSignatureError = class extends ApimeError {
49
+ };
50
+ function verifyWebhookSignature(rawBody, signature, secret) {
51
+ if (!signature || !secret) return false;
52
+ const body = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
53
+ const expected = `sha256=${(0, import_node_crypto.createHmac)("sha256", secret).update(body).digest("hex")}`;
54
+ const received = Buffer.from(signature, "utf8");
55
+ const digest = Buffer.from(expected, "utf8");
56
+ if (received.length !== digest.length) return false;
57
+ return (0, import_node_crypto.timingSafeEqual)(received, digest);
58
+ }
59
+ function constructEvent(rawBody, signature, secret) {
60
+ if (!verifyWebhookSignature(rawBody, signature, secret)) {
61
+ throw new InvalidSignatureError("assinatura do webhook n\xE3o confere");
62
+ }
63
+ const text = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
64
+ let parsed;
65
+ try {
66
+ parsed = JSON.parse(text);
67
+ } catch (cause) {
68
+ throw new InvalidSignatureError("corpo do webhook n\xE3o \xE9 JSON v\xE1lido", { cause });
69
+ }
70
+ return parsed;
71
+ }
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ InvalidSignatureError,
75
+ SIGNATURE_HEADER,
76
+ constructEvent,
77
+ verifyWebhookSignature
78
+ });
@@ -0,0 +1,2 @@
1
+ export { e as InvalidSignatureError, g as SIGNATURE_HEADER, f as constructEvent, v as verifyWebhookSignature } from '../index-37ITjlwO.cjs';
2
+ export { e as WebhookEvent } from '../events-BV5UVoFu.cjs';
@@ -0,0 +1,2 @@
1
+ export { e as InvalidSignatureError, g as SIGNATURE_HEADER, f as constructEvent, v as verifyWebhookSignature } from '../index-TqYrYke0.js';
2
+ export { e as WebhookEvent } from '../events-BV5UVoFu.js';
@@ -0,0 +1,12 @@
1
+ import {
2
+ InvalidSignatureError,
3
+ SIGNATURE_HEADER,
4
+ constructEvent,
5
+ verifyWebhookSignature
6
+ } from "../chunk-HS2RZ6SJ.js";
7
+ export {
8
+ InvalidSignatureError,
9
+ SIGNATURE_HEADER,
10
+ constructEvent,
11
+ verifyWebhookSignature
12
+ };
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@open-apime/sdk",
3
+ "version": "0.2.2",
4
+ "description": "Cliente TypeScript da API do apime: WhatsApp, instâncias e webhooks",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/open-apime/sdk.git"
9
+ },
10
+ "homepage": "https://github.com/open-apime/sdk#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/open-apime/sdk/issues"
13
+ },
14
+ "keywords": [
15
+ "apime",
16
+ "whatsapp",
17
+ "whatsmeow",
18
+ "sdk",
19
+ "client"
20
+ ],
21
+ "type": "module",
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "files": [
30
+ "dist/**/*.js",
31
+ "dist/**/*.cjs",
32
+ "dist/**/*.d.ts",
33
+ "dist/**/*.d.cts",
34
+ "README.md",
35
+ "LICENSE"
36
+ ],
37
+ "main": "./dist/index.cjs",
38
+ "module": "./dist/index.js",
39
+ "types": "./dist/index.d.ts",
40
+ "exports": {
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "import": "./dist/index.js",
44
+ "require": "./dist/index.cjs"
45
+ },
46
+ "./webhook": {
47
+ "types": "./dist/webhook/index.d.ts",
48
+ "import": "./dist/webhook/index.js",
49
+ "require": "./dist/webhook/index.cjs"
50
+ },
51
+ "./types": {
52
+ "types": "./dist/types/index.d.ts",
53
+ "import": "./dist/types/index.js",
54
+ "require": "./dist/types/index.cjs"
55
+ },
56
+ "./package.json": "./package.json"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "dev": "tsup --watch",
61
+ "test": "vitest run",
62
+ "test:watch": "vitest",
63
+ "typecheck": "tsc --noEmit",
64
+ "lint": "tsc --noEmit",
65
+ "prepublishOnly": "npm run typecheck && npm run test && npm run build"
66
+ },
67
+ "devDependencies": {
68
+ "@types/node": "^22.10.2",
69
+ "tsup": "^8.3.5",
70
+ "typescript": "^5.7.2",
71
+ "vitest": "^2.1.8"
72
+ }
73
+ }