@zyphr-dev/node-sdk 0.1.12 → 0.1.16

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
@@ -412,10 +412,17 @@ const session = await zyphr.auth.login.loginEndUser({
412
412
  });
413
413
 
414
414
  // User profile (requires end-user access token)
415
- const profile = await zyphr.auth.profile.getEndUser();
416
- await zyphr.auth.profile.updateEndUser({
417
- updateEndUserRequest: { name: 'Updated Name' },
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' },
418
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
+ );
419
426
 
420
427
  // Email verification
421
428
  await zyphr.auth.emailVerification.sendVerification('user@example.com');
package/dist/index.cjs CHANGED
@@ -19675,7 +19675,9 @@ var Zyphr = class {
19675
19675
  devices;
19676
19676
  waas;
19677
19677
  auth;
19678
+ options;
19678
19679
  constructor(options) {
19680
+ this.options = options;
19679
19681
  const config = new Configuration({
19680
19682
  basePath: options.baseUrl,
19681
19683
  apiKey: (name) => {
@@ -19716,6 +19718,33 @@ var Zyphr = class {
19716
19718
  webauthn: new AuthWebAuthnApi(config)
19717
19719
  };
19718
19720
  }
19721
+ /**
19722
+ * Create request overrides that authenticate as an end user.
19723
+ * Use this when calling profile, session, or MFA endpoints that
19724
+ * require the end user's access token instead of the API key.
19725
+ *
19726
+ * Includes both the end-user Bearer token and the application
19727
+ * public key (X-Application-Key) required by user-scoped endpoints.
19728
+ *
19729
+ * @example
19730
+ * ```ts
19731
+ * const login = await zyphr.auth.login.loginEndUser({ ... });
19732
+ * const token = login.data.tokens.access_token;
19733
+ *
19734
+ * const profile = await zyphr.auth.profile.getEndUser(
19735
+ * zyphr.asEndUser(token)
19736
+ * );
19737
+ * ```
19738
+ */
19739
+ asEndUser(accessToken) {
19740
+ const headers = {
19741
+ Authorization: `Bearer ${accessToken}`
19742
+ };
19743
+ if (this.options.applicationKey) {
19744
+ headers["X-Application-Key"] = this.options.applicationKey;
19745
+ }
19746
+ return { headers };
19747
+ }
19719
19748
  };
19720
19749
 
19721
19750
  // src/index.ts