@zindua/sdk 1.4.0 → 1.4.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 +1 -1
- package/dist/client.d.ts +12 -3
- package/dist/client.js +10 -3
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type SendChannel = "email" | "whatsapp";
|
|
2
2
|
export type ZinduaSendOptions = {
|
|
3
|
-
to: string;
|
|
3
|
+
to: string | string[];
|
|
4
4
|
template: string;
|
|
5
5
|
channel?: SendChannel;
|
|
6
6
|
lang?: string;
|
|
@@ -26,6 +26,9 @@ export type ZinduaEmailVerifyResult = {
|
|
|
26
26
|
suppressed: boolean;
|
|
27
27
|
suppressionReason: string | null;
|
|
28
28
|
deliverable: boolean;
|
|
29
|
+
catchAll?: boolean;
|
|
30
|
+
headline?: string;
|
|
31
|
+
youShould?: string;
|
|
29
32
|
};
|
|
30
33
|
export type ZinduaClientOptions = {
|
|
31
34
|
apiKey: string;
|
|
@@ -149,6 +152,8 @@ export type ZinduaSendResult = {
|
|
|
149
152
|
channel: SendChannel;
|
|
150
153
|
status: string;
|
|
151
154
|
logId: string;
|
|
155
|
+
logIds?: string[];
|
|
156
|
+
billed?: number;
|
|
152
157
|
langUsed?: string;
|
|
153
158
|
langFallback?: boolean;
|
|
154
159
|
testMode?: boolean;
|
|
@@ -208,7 +213,9 @@ export declare class Zindua {
|
|
|
208
213
|
expiresAt: string;
|
|
209
214
|
};
|
|
210
215
|
}>;
|
|
211
|
-
respond: (challengeId: string, value: string
|
|
216
|
+
respond: (challengeId: string, value: string, options?: {
|
|
217
|
+
userExternalId?: string;
|
|
218
|
+
}) => Promise<{
|
|
212
219
|
ok: boolean;
|
|
213
220
|
status: string;
|
|
214
221
|
error?: string;
|
|
@@ -274,7 +281,9 @@ export declare class Zindua {
|
|
|
274
281
|
expiresAt: string;
|
|
275
282
|
};
|
|
276
283
|
}>;
|
|
277
|
-
respond: (challengeId: string, value: string
|
|
284
|
+
respond: (challengeId: string, value: string, options?: {
|
|
285
|
+
userExternalId?: string;
|
|
286
|
+
}) => Promise<{
|
|
278
287
|
ok: boolean;
|
|
279
288
|
status: string;
|
|
280
289
|
error?: string;
|
package/dist/client.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.Zindua = void 0;
|
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
5
|
const validate_1 = require("./validate");
|
|
6
6
|
const whatsapp_anti_ban_1 = require("./whatsapp-anti-ban");
|
|
7
|
-
const SDK_VERSION = "1.4.
|
|
7
|
+
const SDK_VERSION = "1.4.1";
|
|
8
8
|
const USER_AGENT = `Zindua-JS/${SDK_VERSION}`;
|
|
9
9
|
function buildPayload(options, channel) {
|
|
10
10
|
const to = (0, validate_1.validateRecipient)(options.to, channel);
|
|
@@ -120,8 +120,8 @@ class Zindua {
|
|
|
120
120
|
getStatus: async (challengeId) => {
|
|
121
121
|
return this.request("GET", `challenges/${encodeURIComponent(challengeId)}`);
|
|
122
122
|
},
|
|
123
|
-
respond: async (challengeId, value) => {
|
|
124
|
-
return this.request("POST", `challenges/${encodeURIComponent(challengeId)}/respond`, { value });
|
|
123
|
+
respond: async (challengeId, value, options) => {
|
|
124
|
+
return this.request("POST", `challenges/${encodeURIComponent(challengeId)}/respond`, { value, userExternalId: options?.userExternalId });
|
|
125
125
|
},
|
|
126
126
|
/**
|
|
127
127
|
* SSE listener for challenge status (requires API key — server-side or trusted runtime).
|
|
@@ -360,6 +360,9 @@ class Zindua {
|
|
|
360
360
|
suppressed: Boolean(data.suppressed),
|
|
361
361
|
suppressionReason: typeof data.suppressionReason === "string" ? data.suppressionReason : null,
|
|
362
362
|
deliverable: Boolean(data.deliverable),
|
|
363
|
+
catchAll: Boolean(data.catchAll),
|
|
364
|
+
headline: typeof data.headline === "string" ? data.headline : undefined,
|
|
365
|
+
youShould: typeof data.youShould === "string" ? data.youShould : undefined,
|
|
363
366
|
};
|
|
364
367
|
}
|
|
365
368
|
/** Delivery status for a logId returned by send() (GET /logs/{logId}). */
|
|
@@ -398,6 +401,10 @@ class Zindua {
|
|
|
398
401
|
channel: (data.channel === "whatsapp" ? "whatsapp" : "email"),
|
|
399
402
|
status: typeof data.status === "string" ? data.status : "queued",
|
|
400
403
|
logId: data.logId,
|
|
404
|
+
logIds: Array.isArray(data.logIds)
|
|
405
|
+
? data.logIds.filter((id) => typeof id === "string")
|
|
406
|
+
: undefined,
|
|
407
|
+
billed: typeof data.billed === "number" ? data.billed : undefined,
|
|
401
408
|
langUsed: typeof data.langUsed === "string" ? data.langUsed : undefined,
|
|
402
409
|
langFallback: typeof data.langFallback === "boolean" ? data.langFallback : undefined,
|
|
403
410
|
testMode: typeof data.testMode === "boolean" ? data.testMode : undefined,
|
package/dist/validate.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare function validateApiKey(apiKey: string): string;
|
|
|
16
16
|
export declare function validateBaseUrl(raw: string): string;
|
|
17
17
|
export declare function resolveBaseUrl(explicit?: string): string;
|
|
18
18
|
export declare function validateTemplateSlug(template: string): string;
|
|
19
|
-
export declare function validateRecipient(to: string, channel: "email" | "whatsapp"): string;
|
|
19
|
+
export declare function validateRecipient(to: string | string[], channel: "email" | "whatsapp"): string | string[];
|
|
20
20
|
export declare function validateChannel(channel?: string): "email" | "whatsapp";
|
|
21
21
|
export declare function validateLang(lang?: string): string | undefined;
|
|
22
22
|
export declare function sanitizeVariables(variables?: Record<string, string>): Record<string, string> | undefined;
|
package/dist/validate.js
CHANGED
|
@@ -104,6 +104,20 @@ function validateTemplateSlug(template) {
|
|
|
104
104
|
return slug;
|
|
105
105
|
}
|
|
106
106
|
function validateRecipient(to, channel) {
|
|
107
|
+
const parts = (Array.isArray(to) ? to : [to])
|
|
108
|
+
.flatMap((value) => String(value).split(/[,;]/))
|
|
109
|
+
.map((value) => value.trim())
|
|
110
|
+
.filter(Boolean);
|
|
111
|
+
if (parts.length === 0) {
|
|
112
|
+
throw new errors_1.ZinduaError("to is required and must be under 320 characters.", {
|
|
113
|
+
status: 0,
|
|
114
|
+
code: "MISSING_FIELDS",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const validated = parts.map((part) => validateOneRecipient(part, channel));
|
|
118
|
+
return validated.length === 1 ? validated[0] : validated;
|
|
119
|
+
}
|
|
120
|
+
function validateOneRecipient(to, channel) {
|
|
107
121
|
const recipient = to.trim();
|
|
108
122
|
if (!recipient || recipient.length > exports.LIMITS.maxToLength) {
|
|
109
123
|
throw new errors_1.ZinduaError("to is required and must be under 320 characters.", {
|