@glitchgrab/whatsapp 0.1.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.
@@ -0,0 +1,97 @@
1
+ /** Shared shapes. Mirrors the `/api/v1/wa` responses. */
2
+ type WaTemplateCategory = "MARKETING" | "UTILITY" | "AUTHENTICATION" | "SERVICE";
3
+ type WaTemplateStatus = "DRAFT" | "PENDING" | "APPROVED" | "REJECTED" | "PAUSED" | "DISABLED";
4
+ type WaMessageDirection = "INBOUND" | "OUTBOUND";
5
+ type WaMessageStatus = "QUEUED" | "SENT" | "DELIVERED" | "READ" | "FAILED";
6
+ type WaConversationStatus = "OPEN" | "SNOOZED" | "CLOSED";
7
+ type WaMatchType = "EXACT" | "CONTAINS" | "STARTS_WITH" | "REGEX" | "ANY";
8
+ /**
9
+ * Every failure carries a stable `code`, so callers branch on that rather than
10
+ * matching on a message that may be reworded.
11
+ */
12
+ type WaErrorCode = "UNAUTHORIZED" | "PLATFORM_INACTIVE" | "TENANT_NOT_FOUND" | "INSUFFICIENT_FUNDS" | "NO_PRICE_RULE" | "INVALID_AMOUNT" | "DUPLICATE_REQUEST" | "INTERNAL";
13
+ declare class WhatsappError extends Error {
14
+ readonly code: WaErrorCode | string;
15
+ readonly status: number;
16
+ readonly detail?: Record<string, unknown> | undefined;
17
+ constructor(code: WaErrorCode | string, message: string, status: number, detail?: Record<string, unknown> | undefined);
18
+ /** The owner has run out of balance. `detail.shortfallPaise` says by how much. */
19
+ get isInsufficientFunds(): boolean;
20
+ }
21
+ interface WaNumber {
22
+ phoneNumberId: string;
23
+ displayNumber: string;
24
+ verifiedName: string;
25
+ status: "PENDING" | "VERIFIED" | "REGISTERED" | "DISCONNECTED";
26
+ qualityRating?: string | null;
27
+ messagingLimitTier?: string | null;
28
+ }
29
+ interface WaMessage {
30
+ id: string;
31
+ direction: WaMessageDirection;
32
+ status: WaMessageStatus;
33
+ contactPhone?: string;
34
+ category?: WaTemplateCategory | null;
35
+ payload: unknown;
36
+ error?: string | null;
37
+ sentAt?: string | null;
38
+ deliveredAt?: string | null;
39
+ readAt?: string | null;
40
+ createdAt: string;
41
+ }
42
+ interface WaConversation {
43
+ id: string;
44
+ contactPhone: string;
45
+ contactName?: string | null;
46
+ windowExpiresAt?: string | null;
47
+ /** Whether free-form text is legal right now. Computed server-side. */
48
+ windowOpen: boolean;
49
+ lastInboundAt?: string | null;
50
+ lastOutboundAt?: string | null;
51
+ optedOut: boolean;
52
+ status: WaConversationStatus;
53
+ assignedAgentId?: string | null;
54
+ unreadCount: number;
55
+ updatedAt: string;
56
+ lastMessage?: WaMessage | null;
57
+ }
58
+ interface WaTemplate {
59
+ id: string;
60
+ name: string;
61
+ language: string;
62
+ category: WaTemplateCategory;
63
+ status: WaTemplateStatus;
64
+ rejectionReason?: string | null;
65
+ components?: unknown;
66
+ submittedAt?: string | null;
67
+ lastSyncedAt?: string | null;
68
+ }
69
+ interface WaAgent {
70
+ id: string;
71
+ externalAgentId: string;
72
+ name: string;
73
+ email?: string | null;
74
+ role: "AGENT" | "ADMIN";
75
+ active: boolean;
76
+ }
77
+ interface WaBalance {
78
+ balancePaise: number;
79
+ heldPaise: number;
80
+ spendablePaise: number;
81
+ }
82
+ interface WaSendResult {
83
+ messageId: string;
84
+ metaMessageId: string;
85
+ status: "SENT";
86
+ category: WaTemplateCategory;
87
+ tenantPricePaise: number;
88
+ tenantBalancePaise: number;
89
+ }
90
+ interface WaSignupLaunch {
91
+ appId: string;
92
+ configId: string;
93
+ scopes: string[];
94
+ state: string;
95
+ }
96
+
97
+ export { type WaAgent as W, type WaBalance as a, type WaConversation as b, type WaConversationStatus as c, type WaErrorCode as d, type WaMatchType as e, type WaMessage as f, type WaMessageDirection as g, type WaMessageStatus as h, type WaNumber as i, type WaSendResult as j, type WaSignupLaunch as k, type WaTemplate as l, type WaTemplateCategory as m, type WaTemplateStatus as n, WhatsappError as o };
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@glitchgrab/whatsapp",
3
+ "version": "0.1.0",
4
+ "description": "WhatsApp Business messaging for SaaS products \u2014 connect a customer's own number, send templates, and run a shared inbox.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./react": {
15
+ "types": "./dist/react.d.ts",
16
+ "import": "./dist/react.mjs",
17
+ "require": "./dist/react.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsup",
22
+ "dev": "tsup --watch",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest"
25
+ },
26
+ "peerDependencies": {
27
+ "react": ">=18",
28
+ "react-dom": ">=18"
29
+ },
30
+ "peerDependenciesMeta": {
31
+ "react": {
32
+ "optional": true
33
+ },
34
+ "react-dom": {
35
+ "optional": true
36
+ }
37
+ },
38
+ "devDependencies": {
39
+ "@types/react": "^19",
40
+ "react": "^19",
41
+ "tsup": "^8",
42
+ "typescript": "^5",
43
+ "vitest": "^4.1.3"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/Navibyte-Innovations-Pvt-Ltd/glitchgrab.git",
54
+ "directory": "packages/sdk-whatsapp"
55
+ },
56
+ "license": "MIT",
57
+ "keywords": [
58
+ "whatsapp",
59
+ "whatsapp-business",
60
+ "messaging",
61
+ "saas",
62
+ "multi-tenant"
63
+ ]
64
+ }