@veroxm/sdk 1.1.0 → 1.3.0
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/CHANGELOG.md +21 -0
- package/README.md +35 -0
- package/dist/auth.d.ts +67 -1
- package/dist/auth.js +89 -1
- package/dist/errors.d.ts +20 -0
- package/dist/errors.js +23 -0
- package/dist/generated/api.d.ts +1167 -119
- package/dist/http.js +2 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/passkeys.d.ts +32 -0
- package/dist/passkeys.js +84 -0
- package/package.json +1 -1
package/dist/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { apiError } from './errors.js';
|
|
2
2
|
function safeJsonParse(text) {
|
|
3
3
|
try {
|
|
4
4
|
return JSON.parse(text);
|
|
@@ -36,7 +36,7 @@ export async function rawRequest(apiBase, opts) {
|
|
|
36
36
|
const text = await res.text();
|
|
37
37
|
const parsed = text ? safeJsonParse(text) : null;
|
|
38
38
|
if (!res.ok) {
|
|
39
|
-
throw
|
|
39
|
+
throw apiError(res.status, parsed ?? text);
|
|
40
40
|
}
|
|
41
41
|
return parsed;
|
|
42
42
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { VeroXMApp } from './client.js';
|
|
2
2
|
export type { VeroXMAppOptions } from './client.js';
|
|
3
3
|
export { VeroXMAuth } from './auth.js';
|
|
4
|
-
export type { Account, EmailCode, PendingStore, SocialProvider, SocialSignInStart } from './auth.js';
|
|
4
|
+
export type { Account, AuthenticatorSetup, EmailCode, Passkey, PendingStore, SecondStep, SocialProvider, SocialSignInStart, TwoStepStatus, WithTicket, } from './auth.js';
|
|
5
|
+
export { browserPasskeys, creationOptionsFromJSON, credentialToJSON, requestOptionsFromJSON } from './passkeys.js';
|
|
6
|
+
export type { PasskeyOptionsJSON, PasskeyProvider } from './passkeys.js';
|
|
5
7
|
export { createPkce } from './pkce.js';
|
|
6
8
|
export { ContentResource } from './content.js';
|
|
7
9
|
export type { ListOptions } from './content.js';
|
|
@@ -14,7 +16,8 @@ export { ProcessesResource } from './processes.js';
|
|
|
14
16
|
export type { ProcessRun, ProcessRunDetail, ProcessRunListOptions } from './processes.js';
|
|
15
17
|
export type { Schemas } from './schemas.js';
|
|
16
18
|
export type { paths as ApiPaths, components as ApiComponents, operations as ApiOperations } from './generated/api.js';
|
|
17
|
-
export { VeroXMApiError, VeroXMNotAuthenticatedError } from './errors.js';
|
|
19
|
+
export { VeroXMApiError, VeroXMNotAuthenticatedError, VeroXMTwoStepRequiredError } from './errors.js';
|
|
20
|
+
export type { TwoStepMethod } from './errors.js';
|
|
18
21
|
export { MemoryTokenStorage, BrowserLocalStorageTokenStorage } from './token-storage.js';
|
|
19
22
|
export type { TokenStorage, StoredSession, AuthUser } from './token-storage.js';
|
|
20
23
|
export { VeroxmTracker, createTracker } from './tracker.js';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export { VeroXMApp } from './client.js';
|
|
2
2
|
export { VeroXMAuth } from './auth.js';
|
|
3
|
+
export { browserPasskeys, creationOptionsFromJSON, credentialToJSON, requestOptionsFromJSON } from './passkeys.js';
|
|
3
4
|
export { createPkce } from './pkce.js';
|
|
4
5
|
export { ContentResource } from './content.js';
|
|
5
6
|
export { MediaResource } from './media.js';
|
|
6
7
|
export { FunctionsResource } from './functions.js';
|
|
7
8
|
export { TasksResource } from './tasks.js';
|
|
8
9
|
export { ProcessesResource } from './processes.js';
|
|
9
|
-
export { VeroXMApiError, VeroXMNotAuthenticatedError } from './errors.js';
|
|
10
|
+
export { VeroXMApiError, VeroXMNotAuthenticatedError, VeroXMTwoStepRequiredError } from './errors.js';
|
|
10
11
|
export { MemoryTokenStorage, BrowserLocalStorageTokenStorage } from './token-storage.js';
|
|
11
12
|
// Experience OS visitor tracking (page views, actions, consent, identify).
|
|
12
13
|
export { VeroxmTracker, createTracker } from './tracker.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Options from VeroXM, as JSON (PublicKeyCredentialCreationOptionsJSON or ...RequestOptionsJSON). */
|
|
2
|
+
export type PasskeyOptionsJSON = Record<string, unknown> & {
|
|
3
|
+
challenge: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Makes and uses passkeys: the browser's navigator.credentials by default. In React Native or another runtime, pass
|
|
7
|
+
* one that calls the platform's passkey API (most take and return these same JSON forms).
|
|
8
|
+
*/
|
|
9
|
+
export interface PasskeyProvider {
|
|
10
|
+
create(options: PasskeyOptionsJSON): Promise<Record<string, unknown>>;
|
|
11
|
+
get(options: PasskeyOptionsJSON): Promise<Record<string, unknown>>;
|
|
12
|
+
}
|
|
13
|
+
/** JSON creation options as the browser takes them (binary fields as ArrayBuffers). */
|
|
14
|
+
export declare function creationOptionsFromJSON(o: PasskeyOptionsJSON): Record<string, unknown>;
|
|
15
|
+
/** JSON request options as the browser takes them. */
|
|
16
|
+
export declare function requestOptionsFromJSON(o: PasskeyOptionsJSON): Record<string, unknown>;
|
|
17
|
+
interface CredentialLike {
|
|
18
|
+
id: string;
|
|
19
|
+
rawId: ArrayBuffer;
|
|
20
|
+
type: string;
|
|
21
|
+
authenticatorAttachment?: string | null;
|
|
22
|
+
response: Record<string, unknown> & {
|
|
23
|
+
getTransports?: () => string[];
|
|
24
|
+
};
|
|
25
|
+
getClientExtensionResults?: () => Record<string, unknown>;
|
|
26
|
+
toJSON?: () => Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** A browser PublicKeyCredential as the JSON VeroXM takes. */
|
|
29
|
+
export declare function credentialToJSON(cred: CredentialLike): Record<string, unknown>;
|
|
30
|
+
/** The browser's passkeys (navigator.credentials). Throws where there are none. */
|
|
31
|
+
export declare const browserPasskeys: PasskeyProvider;
|
|
32
|
+
export {};
|
package/dist/passkeys.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Passkeys in the browser: VeroXM sends WebAuthn options as JSON and takes the browser's answer as JSON. Browsers
|
|
2
|
+
// that have PublicKeyCredential.parseCreationOptionsFromJSON do the conversion themselves; for the rest, the binary
|
|
3
|
+
// fields are converted here.
|
|
4
|
+
const toBytes = (b64url) => {
|
|
5
|
+
const b64 = b64url.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(b64url.length / 4) * 4, '=');
|
|
6
|
+
const bin = atob(b64);
|
|
7
|
+
const out = new Uint8Array(bin.length);
|
|
8
|
+
for (let i = 0; i < bin.length; i++)
|
|
9
|
+
out[i] = bin.charCodeAt(i);
|
|
10
|
+
return out.buffer;
|
|
11
|
+
};
|
|
12
|
+
const toB64url = (buf) => {
|
|
13
|
+
const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
14
|
+
let bin = '';
|
|
15
|
+
for (const b of bytes)
|
|
16
|
+
bin += String.fromCharCode(b);
|
|
17
|
+
return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
18
|
+
};
|
|
19
|
+
/** JSON creation options as the browser takes them (binary fields as ArrayBuffers). */
|
|
20
|
+
export function creationOptionsFromJSON(o) {
|
|
21
|
+
const user = o.user;
|
|
22
|
+
return {
|
|
23
|
+
...o,
|
|
24
|
+
challenge: toBytes(o.challenge),
|
|
25
|
+
user: { ...user, id: toBytes(user.id) },
|
|
26
|
+
excludeCredentials: (o.excludeCredentials ?? []).map((c) => ({ ...c, type: c.type ?? 'public-key', id: toBytes(c.id) })),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** JSON request options as the browser takes them. */
|
|
30
|
+
export function requestOptionsFromJSON(o) {
|
|
31
|
+
return {
|
|
32
|
+
...o,
|
|
33
|
+
challenge: toBytes(o.challenge),
|
|
34
|
+
allowCredentials: (o.allowCredentials ?? []).map((c) => ({ ...c, type: c.type ?? 'public-key', id: toBytes(c.id) })),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** A browser PublicKeyCredential as the JSON VeroXM takes. */
|
|
38
|
+
export function credentialToJSON(cred) {
|
|
39
|
+
if (typeof cred.toJSON === 'function')
|
|
40
|
+
return cred.toJSON();
|
|
41
|
+
const r = cred.response;
|
|
42
|
+
const response = {};
|
|
43
|
+
for (const key of ['clientDataJSON', 'attestationObject', 'authenticatorData', 'signature', 'userHandle']) {
|
|
44
|
+
const v = r[key];
|
|
45
|
+
if (v instanceof ArrayBuffer || ArrayBuffer.isView(v))
|
|
46
|
+
response[key] = toB64url(v);
|
|
47
|
+
}
|
|
48
|
+
if (typeof r.getTransports === 'function')
|
|
49
|
+
response.transports = r.getTransports();
|
|
50
|
+
return {
|
|
51
|
+
id: cred.id,
|
|
52
|
+
rawId: toB64url(cred.rawId),
|
|
53
|
+
type: cred.type,
|
|
54
|
+
authenticatorAttachment: cred.authenticatorAttachment ?? undefined,
|
|
55
|
+
clientExtensionResults: cred.getClientExtensionResults?.() ?? {},
|
|
56
|
+
response,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The browser's passkeys (navigator.credentials). Throws where there are none. */
|
|
60
|
+
export const browserPasskeys = {
|
|
61
|
+
async create(options) {
|
|
62
|
+
const { credentials, PKC } = webauthn();
|
|
63
|
+
const publicKey = PKC.parseCreationOptionsFromJSON ? PKC.parseCreationOptionsFromJSON(options) : creationOptionsFromJSON(options);
|
|
64
|
+
const cred = (await credentials.create({ publicKey }));
|
|
65
|
+
if (!cred)
|
|
66
|
+
throw Object.assign(new Error('No passkey was made.'), { code: 'passkey_cancelled' });
|
|
67
|
+
return credentialToJSON(cred);
|
|
68
|
+
},
|
|
69
|
+
async get(options) {
|
|
70
|
+
const { credentials, PKC } = webauthn();
|
|
71
|
+
const publicKey = PKC.parseRequestOptionsFromJSON ? PKC.parseRequestOptionsFromJSON(options) : requestOptionsFromJSON(options);
|
|
72
|
+
const cred = (await credentials.get({ publicKey }));
|
|
73
|
+
if (!cred)
|
|
74
|
+
throw Object.assign(new Error('No passkey was chosen.'), { code: 'passkey_cancelled' });
|
|
75
|
+
return credentialToJSON(cred);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
function webauthn() {
|
|
79
|
+
const g = globalThis;
|
|
80
|
+
if (!g.navigator?.credentials || !g.PublicKeyCredential) {
|
|
81
|
+
throw Object.assign(new Error("Passkeys aren't available here: use a browser that has them, or pass a passkey provider."), { code: 'passkeys_unavailable' });
|
|
82
|
+
}
|
|
83
|
+
return { credentials: g.navigator.credentials, PKC: g.PublicKeyCredential };
|
|
84
|
+
}
|