@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 +10 -3
- package/dist/index.cjs +29 -0
- 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 +29 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +31 -0
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -103,7 +103,10 @@ export class Zyphr {
|
|
|
103
103
|
readonly webauthn: AuthWebAuthnApi;
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
+
private readonly options: ZyphrOptions;
|
|
107
|
+
|
|
106
108
|
constructor(options: ZyphrOptions) {
|
|
109
|
+
this.options = options;
|
|
107
110
|
const config = new Configuration({
|
|
108
111
|
basePath: options.baseUrl,
|
|
109
112
|
apiKey: (name: string) => {
|
|
@@ -148,4 +151,32 @@ export class Zyphr {
|
|
|
148
151
|
webauthn: new AuthWebAuthnApi(config),
|
|
149
152
|
};
|
|
150
153
|
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Create request overrides that authenticate as an end user.
|
|
157
|
+
* Use this when calling profile, session, or MFA endpoints that
|
|
158
|
+
* require the end user's access token instead of the API key.
|
|
159
|
+
*
|
|
160
|
+
* Includes both the end-user Bearer token and the application
|
|
161
|
+
* public key (X-Application-Key) required by user-scoped endpoints.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const login = await zyphr.auth.login.loginEndUser({ ... });
|
|
166
|
+
* const token = login.data.tokens.access_token;
|
|
167
|
+
*
|
|
168
|
+
* const profile = await zyphr.auth.profile.getEndUser(
|
|
169
|
+
* zyphr.asEndUser(token)
|
|
170
|
+
* );
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
asEndUser(accessToken: string): RequestInit {
|
|
174
|
+
const headers: Record<string, string> = {
|
|
175
|
+
Authorization: `Bearer ${accessToken}`,
|
|
176
|
+
};
|
|
177
|
+
if (this.options.applicationKey) {
|
|
178
|
+
headers['X-Application-Key'] = this.options.applicationKey;
|
|
179
|
+
}
|
|
180
|
+
return { headers };
|
|
181
|
+
}
|
|
151
182
|
}
|