@wazapi/sdk 0.2.0 → 0.3.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
@@ -108,6 +108,27 @@ operation is created):
108
108
  | `template_parameter_count_mismatch` | `parameters.length` ≠ `body_parameter_count`. |
109
109
  | `template_format_unsupported` | Needs media/variable header, named params, buttons. |
110
110
 
111
+ Compliance gates on template sends (rejected synchronously with 403/422, and
112
+ re-checked by the worker — the same codes can appear as `error.code` on the
113
+ polled operation):
114
+
115
+ | Code | Meaning |
116
+ | --------------------------------------- | ------------------------------------------------------------------------ |
117
+ | `marketing_sends_disabled` | MARKETING sending is off for the company (an owner enables it in the dashboard) or platform-wide. |
118
+ | `recipient_opted_out` | The recipient opted out (reply keyword, native WhatsApp control, or manual suppression). Filter on `contact.marketing_opted_out`. |
119
+ | `duplicate_template_send` | Same template already sent to this phone in the last 24h. |
120
+ | `template_frequency_cap_exceeded` | Per-contact MARKETING cap (1/24h, 3/7 days). |
121
+ | `company_daily_marketing_cap_exceeded` | Company-wide daily MARKETING cap. |
122
+ | `channel_marketing_paused` | Meta flagged the number's quality; MARKETING is paused temporarily. |
123
+ | `template_quality_blocked` | This specific template dropped to RED quality on Meta. |
124
+ | `send_pacing_timeout` | Operation-only: delivery was deferred by per-channel pacing for too long. |
125
+
126
+ Delivery is paced per channel to protect number quality, so an accepted `202`
127
+ can take longer to complete under load — poll the operation instead of
128
+ re-sending. AUTHENTICATION (OTP) templates are exempt from opt-outs and caps.
129
+ Use `error.isComplianceBlocked` to branch on this whole family, and the
130
+ `SendComplianceErrorCode` type to narrow `operation.error.code`.
131
+
111
132
  ## Contacts
112
133
 
113
134
  ```ts
package/dist/error.d.ts CHANGED
@@ -21,4 +21,11 @@ export declare class WazapiError extends Error {
21
21
  });
22
22
  /** True for 429 rate-limit responses. */
23
23
  get isRateLimited(): boolean;
24
+ /**
25
+ * True when the send was refused by a compliance gate (opt-out, frequency
26
+ * cap, marketing policy, channel/template quality pause) rather than by a
27
+ * malformed request. Retrying without changing the audience will not help —
28
+ * fix the recipient list or the account policy instead.
29
+ */
30
+ get isComplianceBlocked(): boolean;
24
31
  }
package/dist/error.js CHANGED
@@ -24,4 +24,22 @@ export class WazapiError extends Error {
24
24
  get isRateLimited() {
25
25
  return this.status === 429;
26
26
  }
27
+ /**
28
+ * True when the send was refused by a compliance gate (opt-out, frequency
29
+ * cap, marketing policy, channel/template quality pause) rather than by a
30
+ * malformed request. Retrying without changing the audience will not help —
31
+ * fix the recipient list or the account policy instead.
32
+ */
33
+ get isComplianceBlocked() {
34
+ return [
35
+ 'marketing_sends_disabled',
36
+ 'template_sends_disabled',
37
+ 'recipient_opted_out',
38
+ 'duplicate_template_send',
39
+ 'template_frequency_cap_exceeded',
40
+ 'company_daily_marketing_cap_exceeded',
41
+ 'channel_marketing_paused',
42
+ 'template_quality_blocked',
43
+ ].includes(this.code);
44
+ }
27
45
  }
package/dist/types.d.ts CHANGED
@@ -30,6 +30,14 @@ export interface Contact {
30
30
  email: string | null;
31
31
  tags: string[];
32
32
  custom_fields: Record<string, unknown>;
33
+ /**
34
+ * True when the contact opted out of marketing messages (reply keyword such
35
+ * as PARAR/STOP, the native WhatsApp control, or manual suppression).
36
+ * Sending a MARKETING template to an opted-out contact fails with
37
+ * `recipient_opted_out` — filter your audience on this before a campaign.
38
+ */
39
+ marketing_opted_out: boolean;
40
+ marketing_opt_out_at: string | null;
33
41
  last_interaction_at: string | null;
34
42
  created_at: string | null;
35
43
  updated_at: string | null;
@@ -91,6 +99,13 @@ export interface Message {
91
99
  updated_at: string | null;
92
100
  }
93
101
  export type OperationStatus = 'queued' | 'processing' | 'waiting' | 'succeeded' | 'failed';
102
+ /**
103
+ * Compliance codes the send guard can answer with. They surface both as a
104
+ * synchronous 4xx on `POST /messages` (403 for the two `*_disabled` codes,
105
+ * 422 for the rest) and as `error.code` on the polled operation —
106
+ * `send_pacing_timeout` only ever appears on the operation.
107
+ */
108
+ export type SendComplianceErrorCode = 'marketing_sends_disabled' | 'template_sends_disabled' | 'recipient_opted_out' | 'duplicate_template_send' | 'template_frequency_cap_exceeded' | 'company_daily_marketing_cap_exceeded' | 'channel_marketing_paused' | 'template_quality_blocked' | 'send_pacing_timeout';
94
109
  export interface Operation {
95
110
  uuid: string;
96
111
  type: 'message.send' | 'flow.execute';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazapi/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Official Node.js SDK for the Wazapi Public API v1",
5
5
  "license": "MIT",
6
6
  "type": "module",