@zyphr-dev/node-sdk 0.1.21 → 0.1.23
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 +47 -35
- package/dist/index.cjs +15 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -20
- package/dist/index.d.ts +21 -20
- package/dist/index.js +13 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/src/errors.ts +20 -0
- package/src/src/models/CreateTemplateRequest.ts +0 -8
- package/src/src/models/Template.ts +5 -4
- package/src/src/models/UpdateTemplateRequest.ts +0 -8
package/README.md
CHANGED
|
@@ -234,9 +234,9 @@ const subs = await zyphr.subscribers.listSubscribers('subscribed', undefined, 50
|
|
|
234
234
|
// Preferences
|
|
235
235
|
const prefs = await zyphr.subscribers.getSubscriberPreferences('sub_id');
|
|
236
236
|
await zyphr.subscribers.setSubscriberPreferences('sub_id', {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
preferences: [
|
|
238
|
+
{ categoryId: 'marketing', channel: 'email', enabled: false },
|
|
239
|
+
],
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
// Unsubscribe/resubscribe
|
|
@@ -342,7 +342,9 @@ await zyphr.topics.createTopic({
|
|
|
342
342
|
await zyphr.topics.addTopicSubscribers('product-updates', {
|
|
343
343
|
subscriberIds: ['sub_123', 'sub_456'],
|
|
344
344
|
});
|
|
345
|
-
await zyphr.topics.removeTopicSubscribers('product-updates',
|
|
345
|
+
await zyphr.topics.removeTopicSubscribers('product-updates', {
|
|
346
|
+
subscriberIds: ['sub_789'],
|
|
347
|
+
});
|
|
346
348
|
|
|
347
349
|
// CRUD
|
|
348
350
|
const topic = await zyphr.topics.getTopic('product-updates');
|
|
@@ -360,8 +362,8 @@ Register and manage push notification devices.
|
|
|
360
362
|
const device = await zyphr.devices.registerDevice({
|
|
361
363
|
userId: 'user_123',
|
|
362
364
|
platform: 'ios',
|
|
363
|
-
|
|
364
|
-
deviceName: 'iPhone 16 Pro',
|
|
365
|
+
token: 'apns_token_xxx',
|
|
366
|
+
metadata: { deviceName: 'iPhone 16 Pro' },
|
|
365
367
|
});
|
|
366
368
|
|
|
367
369
|
// List devices
|
|
@@ -394,48 +396,52 @@ const zyphr = new Zyphr({
|
|
|
394
396
|
```ts
|
|
395
397
|
// Register an end user
|
|
396
398
|
const result = await zyphr.auth.registration.registerEndUser({
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
name: 'New User',
|
|
401
|
-
},
|
|
399
|
+
email: 'new@example.com',
|
|
400
|
+
password: 'SecureP@ss123',
|
|
401
|
+
name: 'New User',
|
|
402
402
|
});
|
|
403
|
-
// result.data
|
|
404
|
-
// result.data
|
|
403
|
+
// result.data?.user — the new user
|
|
404
|
+
// result.data?.tokens — { accessToken, refreshToken, expiresIn }
|
|
405
405
|
|
|
406
406
|
// Login
|
|
407
407
|
const session = await zyphr.auth.login.loginEndUser({
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
password: 'SecureP@ss123',
|
|
411
|
-
},
|
|
408
|
+
email: 'user@example.com',
|
|
409
|
+
password: 'SecureP@ss123',
|
|
412
410
|
});
|
|
413
411
|
|
|
414
412
|
// User profile (requires end-user access token)
|
|
415
413
|
// Use zyphr.asEndUser(token) to authenticate as the end user
|
|
416
414
|
const login = await zyphr.auth.login.loginEndUser({
|
|
417
|
-
|
|
415
|
+
email: 'user@example.com',
|
|
416
|
+
password: 'SecureP@ss123',
|
|
418
417
|
});
|
|
419
|
-
const token = login.data
|
|
418
|
+
const token = login.data?.tokens?.accessToken;
|
|
419
|
+
if (!token) throw new Error('No access token returned');
|
|
420
420
|
|
|
421
421
|
const profile = await zyphr.auth.profile.getEndUser(zyphr.asEndUser(token));
|
|
422
422
|
await zyphr.auth.profile.updateEndUser(
|
|
423
|
-
{
|
|
423
|
+
{ name: 'Updated Name' },
|
|
424
424
|
zyphr.asEndUser(token),
|
|
425
425
|
);
|
|
426
426
|
|
|
427
|
-
// Email verification
|
|
428
|
-
await zyphr.auth.emailVerification.
|
|
427
|
+
// Email verification (acts on the authenticated end user)
|
|
428
|
+
await zyphr.auth.emailVerification.sendEmailVerification(
|
|
429
|
+
{ redirectUrl: 'https://myapp.com/verified' },
|
|
430
|
+
zyphr.asEndUser(token),
|
|
431
|
+
);
|
|
429
432
|
|
|
430
433
|
// Password reset
|
|
431
|
-
await zyphr.auth.passwordReset.
|
|
434
|
+
await zyphr.auth.passwordReset.forgotPassword({ email: 'user@example.com' });
|
|
432
435
|
|
|
433
436
|
// Magic links
|
|
434
|
-
await zyphr.auth.magicLinks.sendMagicLink(
|
|
437
|
+
await zyphr.auth.magicLinks.sendMagicLink({
|
|
438
|
+
email: 'user@example.com',
|
|
439
|
+
redirectUrl: 'https://myapp.com/auth/callback',
|
|
440
|
+
});
|
|
435
441
|
|
|
436
442
|
// MFA
|
|
437
|
-
const mfaStatus = await zyphr.auth.mfa.getMfaStatus();
|
|
438
|
-
await zyphr.auth.mfa.
|
|
443
|
+
const mfaStatus = await zyphr.auth.mfa.getMfaStatus('user_123');
|
|
444
|
+
await zyphr.auth.mfa.startMfaEnrollment({ userId: 'user_123' });
|
|
439
445
|
```
|
|
440
446
|
|
|
441
447
|
**Available auth modules:** `login`, `registration`, `sessions`, `emailVerification`, `passwordReset`, `magicLinks`, `mfa`, `oauth`, `phone`, `webauthn`, `profile`.
|
|
@@ -448,28 +454,34 @@ Webhooks-as-a-Service: multi-tenant webhook delivery infrastructure for your cus
|
|
|
448
454
|
|
|
449
455
|
```ts
|
|
450
456
|
// Create a WaaS application
|
|
451
|
-
const
|
|
457
|
+
const created = await zyphr.waas.applications.createWaaSApplication({
|
|
452
458
|
name: 'My SaaS',
|
|
459
|
+
slug: 'my-saas',
|
|
453
460
|
description: 'Webhook delivery for My SaaS customers',
|
|
454
461
|
});
|
|
462
|
+
const appId = created.data?.id;
|
|
463
|
+
if (!appId) throw new Error('App id missing from response');
|
|
455
464
|
|
|
456
465
|
// Define event types
|
|
457
|
-
await zyphr.waas.eventTypes.
|
|
466
|
+
await zyphr.waas.eventTypes.createWaaSEventType(appId, {
|
|
458
467
|
eventType: 'order.created',
|
|
459
468
|
name: 'Order Created',
|
|
460
469
|
description: 'Fired when a new order is placed',
|
|
461
|
-
examplePayload: {
|
|
470
|
+
examplePayload: { orderId: '123', total: 99.99 },
|
|
462
471
|
});
|
|
463
472
|
|
|
464
|
-
//
|
|
465
|
-
await zyphr.waas.events.
|
|
473
|
+
// Publish events — fans out to all matching tenant endpoints
|
|
474
|
+
await zyphr.waas.events.publishWaaSEvent(appId, {
|
|
466
475
|
eventType: 'order.created',
|
|
467
|
-
|
|
476
|
+
tenantId: 'cust_abc123',
|
|
477
|
+
data: { orderId: '456', total: 149.99 },
|
|
468
478
|
});
|
|
469
479
|
|
|
470
|
-
// Generate portal token for embedded UI
|
|
471
|
-
const portalToken = await zyphr.waas.portal.
|
|
472
|
-
|
|
480
|
+
// Generate a tenant-scoped portal token for embedded UI
|
|
481
|
+
const portalToken = await zyphr.waas.portal.generateWaaSPortalToken(appId, {
|
|
482
|
+
tenantId: 'cust_abc123',
|
|
483
|
+
});
|
|
484
|
+
// Pass portalToken.data?.token to @zyphr-dev/webhook-portal
|
|
473
485
|
```
|
|
474
486
|
|
|
475
487
|
**Available WaaS modules:** `applications`, `eventTypes`, `endpoints`, `events`, `deliveries`, `portal`.
|
package/dist/index.cjs
CHANGED
|
@@ -1573,6 +1573,7 @@ __export(index_exports, {
|
|
|
1573
1573
|
WebhookUsageResponseFromJSONTyped: () => WebhookUsageResponseFromJSONTyped,
|
|
1574
1574
|
WebhookUsageResponseToJSON: () => WebhookUsageResponseToJSON,
|
|
1575
1575
|
WebhookUsageResponseToJSONTyped: () => WebhookUsageResponseToJSONTyped,
|
|
1576
|
+
WebhookVerificationError: () => WebhookVerificationError,
|
|
1576
1577
|
WebhookVersionFromJSON: () => WebhookVersionFromJSON,
|
|
1577
1578
|
WebhookVersionFromJSONTyped: () => WebhookVersionFromJSONTyped,
|
|
1578
1579
|
WebhookVersionToJSON: () => WebhookVersionToJSON,
|
|
@@ -1615,6 +1616,7 @@ __export(index_exports, {
|
|
|
1615
1616
|
ZyphrNotFoundError: () => ZyphrNotFoundError,
|
|
1616
1617
|
ZyphrRateLimitError: () => ZyphrRateLimitError,
|
|
1617
1618
|
ZyphrValidationError: () => ZyphrValidationError,
|
|
1619
|
+
ZyphrWebhookVerificationError: () => ZyphrWebhookVerificationError,
|
|
1618
1620
|
canConsumeForm: () => canConsumeForm,
|
|
1619
1621
|
exists: () => exists,
|
|
1620
1622
|
instanceOfAddTopicSubscribersRequest: () => instanceOfAddTopicSubscribersRequest,
|
|
@@ -4122,8 +4124,7 @@ function CreateTemplateRequestFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
4122
4124
|
"description": json["description"] == null ? void 0 : json["description"],
|
|
4123
4125
|
"subject": json["subject"] == null ? void 0 : json["subject"],
|
|
4124
4126
|
"html": json["html"] == null ? void 0 : json["html"],
|
|
4125
|
-
"text": json["text"] == null ? void 0 : json["text"]
|
|
4126
|
-
"variables": json["variables"] == null ? void 0 : json["variables"]
|
|
4127
|
+
"text": json["text"] == null ? void 0 : json["text"]
|
|
4127
4128
|
};
|
|
4128
4129
|
}
|
|
4129
4130
|
function CreateTemplateRequestToJSON(json) {
|
|
@@ -4138,8 +4139,7 @@ function CreateTemplateRequestToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
4138
4139
|
"description": value["description"],
|
|
4139
4140
|
"subject": value["subject"],
|
|
4140
4141
|
"html": value["html"],
|
|
4141
|
-
"text": value["text"]
|
|
4142
|
-
"variables": value["variables"]
|
|
4142
|
+
"text": value["text"]
|
|
4143
4143
|
};
|
|
4144
4144
|
}
|
|
4145
4145
|
|
|
@@ -11337,7 +11337,6 @@ function TemplateToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
11337
11337
|
"subject": value["subject"],
|
|
11338
11338
|
"html": value["html"],
|
|
11339
11339
|
"text": value["text"],
|
|
11340
|
-
"variables": value["variables"],
|
|
11341
11340
|
"version": value["version"],
|
|
11342
11341
|
"created_at": value["createdAt"] == null ? void 0 : value["createdAt"].toISOString(),
|
|
11343
11342
|
"updated_at": value["updatedAt"] == null ? void 0 : value["updatedAt"].toISOString()
|
|
@@ -12300,8 +12299,7 @@ function UpdateTemplateRequestFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
12300
12299
|
"description": json["description"] == null ? void 0 : json["description"],
|
|
12301
12300
|
"subject": json["subject"] == null ? void 0 : json["subject"],
|
|
12302
12301
|
"html": json["html"] == null ? void 0 : json["html"],
|
|
12303
|
-
"text": json["text"] == null ? void 0 : json["text"]
|
|
12304
|
-
"variables": json["variables"] == null ? void 0 : json["variables"]
|
|
12302
|
+
"text": json["text"] == null ? void 0 : json["text"]
|
|
12305
12303
|
};
|
|
12306
12304
|
}
|
|
12307
12305
|
function UpdateTemplateRequestToJSON(json) {
|
|
@@ -12316,8 +12314,7 @@ function UpdateTemplateRequestToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
12316
12314
|
"description": value["description"],
|
|
12317
12315
|
"subject": value["subject"],
|
|
12318
12316
|
"html": value["html"],
|
|
12319
|
-
"text": value["text"]
|
|
12320
|
-
"variables": value["variables"]
|
|
12317
|
+
"text": value["text"]
|
|
12321
12318
|
};
|
|
12322
12319
|
}
|
|
12323
12320
|
|
|
@@ -21793,6 +21790,13 @@ var ZyphrNotFoundError = class extends ZyphrError {
|
|
|
21793
21790
|
this.name = "ZyphrNotFoundError";
|
|
21794
21791
|
}
|
|
21795
21792
|
};
|
|
21793
|
+
var ZyphrWebhookVerificationError = class extends ZyphrError {
|
|
21794
|
+
constructor(message) {
|
|
21795
|
+
super({ message, status: 401, code: "webhook_verification_failed" });
|
|
21796
|
+
this.name = "ZyphrWebhookVerificationError";
|
|
21797
|
+
}
|
|
21798
|
+
};
|
|
21799
|
+
var WebhookVerificationError = ZyphrWebhookVerificationError;
|
|
21796
21800
|
async function parseErrorResponse(response) {
|
|
21797
21801
|
let body = {};
|
|
21798
21802
|
try {
|
|
@@ -23476,6 +23480,7 @@ var SDK_VERSION = "0.1.0";
|
|
|
23476
23480
|
WebhookUsageResponseFromJSONTyped,
|
|
23477
23481
|
WebhookUsageResponseToJSON,
|
|
23478
23482
|
WebhookUsageResponseToJSONTyped,
|
|
23483
|
+
WebhookVerificationError,
|
|
23479
23484
|
WebhookVersionFromJSON,
|
|
23480
23485
|
WebhookVersionFromJSONTyped,
|
|
23481
23486
|
WebhookVersionToJSON,
|
|
@@ -23518,6 +23523,7 @@ var SDK_VERSION = "0.1.0";
|
|
|
23518
23523
|
ZyphrNotFoundError,
|
|
23519
23524
|
ZyphrRateLimitError,
|
|
23520
23525
|
ZyphrValidationError,
|
|
23526
|
+
ZyphrWebhookVerificationError,
|
|
23521
23527
|
canConsumeForm,
|
|
23522
23528
|
exists,
|
|
23523
23529
|
instanceOfAddTopicSubscribersRequest,
|