@zyphr-dev/node-sdk 0.1.10 → 0.1.14
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 +41 -12
- package/dist/index.cjs +25 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +31 -1
package/README.md
CHANGED
|
@@ -377,21 +377,52 @@ await zyphr.devices.deleteUserDevices('user_123');
|
|
|
377
377
|
|
|
378
378
|
### Authentication — `zyphr.auth.*`
|
|
379
379
|
|
|
380
|
-
Full
|
|
380
|
+
Full Auth-as-a-Service API for end-user authentication: registration, login, MFA, magic links, OAuth, and more.
|
|
381
|
+
|
|
382
|
+
> **Important:** Auth endpoints require application credentials, not just an API key. Create an application in the Zyphr dashboard first, then pass the credentials when constructing the client:
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
const zyphr = new Zyphr({
|
|
386
|
+
apiKey: process.env.ZYPHR_API_KEY!,
|
|
387
|
+
applicationKey: process.env.ZYPHR_APP_PUBLIC_KEY!, // za_pub_*
|
|
388
|
+
applicationSecret: process.env.ZYPHR_APP_SECRET_KEY!, // za_sec_*
|
|
389
|
+
});
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
> **Common mistake:** `POST /v1/auth/register` creates a **platform account** (for the Zyphr dashboard). To register **end users** in your application, use `POST /v1/auth/users/register` via `zyphr.auth.registration.registerEndUser()`.
|
|
381
393
|
|
|
382
394
|
```ts
|
|
395
|
+
// Register an end user
|
|
396
|
+
const result = await zyphr.auth.registration.registerEndUser({
|
|
397
|
+
registerRequest: {
|
|
398
|
+
email: 'new@example.com',
|
|
399
|
+
password: 'SecureP@ss123',
|
|
400
|
+
name: 'New User',
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
// result.data.user — the new user
|
|
404
|
+
// result.data.tokens — { access_token, refresh_token, expires_in }
|
|
405
|
+
|
|
383
406
|
// Login
|
|
384
407
|
const session = await zyphr.auth.login.loginEndUser({
|
|
385
|
-
|
|
386
|
-
|
|
408
|
+
loginRequest: {
|
|
409
|
+
email: 'user@example.com',
|
|
410
|
+
password: 'SecureP@ss123',
|
|
411
|
+
},
|
|
387
412
|
});
|
|
388
413
|
|
|
389
|
-
//
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
password: '
|
|
393
|
-
name: 'New User',
|
|
414
|
+
// User profile (requires end-user access token)
|
|
415
|
+
// Use zyphr.asEndUser(token) to authenticate as the end user
|
|
416
|
+
const login = await zyphr.auth.login.loginEndUser({
|
|
417
|
+
loginRequest: { email: 'user@example.com', password: 'SecureP@ss123' },
|
|
394
418
|
});
|
|
419
|
+
const token = login.data.tokens.access_token;
|
|
420
|
+
|
|
421
|
+
const profile = await zyphr.auth.profile.getEndUser(zyphr.asEndUser(token));
|
|
422
|
+
await zyphr.auth.profile.updateEndUser(
|
|
423
|
+
{ updateEndUserRequest: { name: 'Updated Name' } },
|
|
424
|
+
zyphr.asEndUser(token),
|
|
425
|
+
);
|
|
395
426
|
|
|
396
427
|
// Email verification
|
|
397
428
|
await zyphr.auth.emailVerification.sendVerification('user@example.com');
|
|
@@ -405,14 +436,12 @@ await zyphr.auth.magicLinks.sendMagicLink('user@example.com');
|
|
|
405
436
|
// MFA
|
|
406
437
|
const mfaStatus = await zyphr.auth.mfa.getMfaStatus();
|
|
407
438
|
await zyphr.auth.mfa.enrollMfa({ method: 'totp' });
|
|
408
|
-
|
|
409
|
-
// User profile
|
|
410
|
-
const profile = await zyphr.auth.profile.getProfile();
|
|
411
|
-
await zyphr.auth.profile.updateProfile({ name: 'Updated Name' });
|
|
412
439
|
```
|
|
413
440
|
|
|
414
441
|
**Available auth modules:** `login`, `registration`, `sessions`, `emailVerification`, `passwordReset`, `magicLinks`, `mfa`, `oauth`, `phone`, `webauthn`, `profile`.
|
|
415
442
|
|
|
443
|
+
See the [Auth-as-a-Service guide](https://zyphr.dev/docs/guides/auth-as-a-service) for the full setup walkthrough.
|
|
444
|
+
|
|
416
445
|
### WaaS — `zyphr.waas.*`
|
|
417
446
|
|
|
418
447
|
Webhooks-as-a-Service: multi-tenant webhook delivery infrastructure for your customers.
|
package/dist/index.cjs
CHANGED
|
@@ -19678,7 +19678,11 @@ var Zyphr = class {
|
|
|
19678
19678
|
constructor(options) {
|
|
19679
19679
|
const config = new Configuration({
|
|
19680
19680
|
basePath: options.baseUrl,
|
|
19681
|
-
apiKey: () =>
|
|
19681
|
+
apiKey: (name) => {
|
|
19682
|
+
if (name === "X-Application-Key" && options.applicationKey) return options.applicationKey;
|
|
19683
|
+
if (name === "X-Application-Secret" && options.applicationSecret) return options.applicationSecret;
|
|
19684
|
+
return options.apiKey;
|
|
19685
|
+
},
|
|
19682
19686
|
middleware: [errorMiddleware]
|
|
19683
19687
|
});
|
|
19684
19688
|
this.emails = new EmailsApi(config);
|
|
@@ -19712,6 +19716,26 @@ var Zyphr = class {
|
|
|
19712
19716
|
webauthn: new AuthWebAuthnApi(config)
|
|
19713
19717
|
};
|
|
19714
19718
|
}
|
|
19719
|
+
/**
|
|
19720
|
+
* Create request overrides that authenticate as an end user.
|
|
19721
|
+
* Use this when calling profile, session, or MFA endpoints that
|
|
19722
|
+
* require the end user's access token instead of the API key.
|
|
19723
|
+
*
|
|
19724
|
+
* @example
|
|
19725
|
+
* ```ts
|
|
19726
|
+
* const login = await zyphr.auth.login.loginEndUser({ ... });
|
|
19727
|
+
* const token = login.data.tokens.access_token;
|
|
19728
|
+
*
|
|
19729
|
+
* const profile = await zyphr.auth.profile.getEndUser(
|
|
19730
|
+
* zyphr.asEndUser(token)
|
|
19731
|
+
* );
|
|
19732
|
+
* ```
|
|
19733
|
+
*/
|
|
19734
|
+
asEndUser(accessToken) {
|
|
19735
|
+
return {
|
|
19736
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
19737
|
+
};
|
|
19738
|
+
}
|
|
19715
19739
|
};
|
|
19716
19740
|
|
|
19717
19741
|
// src/index.ts
|