@spacelr/sdk 0.12.0 → 0.13.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/dist/index.d.mts +59 -3
- package/dist/index.d.ts +59 -3
- package/dist/index.js +79 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -42,7 +42,7 @@ interface LoginResponse {
|
|
|
42
42
|
user: {
|
|
43
43
|
id: string;
|
|
44
44
|
sub: string;
|
|
45
|
-
email: string;
|
|
45
|
+
email: string | null;
|
|
46
46
|
username?: string;
|
|
47
47
|
name?: string;
|
|
48
48
|
roles: string[];
|
|
@@ -90,7 +90,7 @@ interface UserInfo {
|
|
|
90
90
|
}
|
|
91
91
|
interface UserProfile {
|
|
92
92
|
id: string;
|
|
93
|
-
email: string;
|
|
93
|
+
email: string | null;
|
|
94
94
|
username?: string;
|
|
95
95
|
name?: string;
|
|
96
96
|
roles: string[];
|
|
@@ -245,7 +245,23 @@ interface PasskeyRegistrationResponseJSON {
|
|
|
245
245
|
interface PasskeyLoginResponse {
|
|
246
246
|
user: {
|
|
247
247
|
id: string;
|
|
248
|
-
email: string;
|
|
248
|
+
email: string | null;
|
|
249
|
+
roles: string[];
|
|
250
|
+
};
|
|
251
|
+
access_token: string;
|
|
252
|
+
refresh_token?: string;
|
|
253
|
+
expires_in?: number;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Response returned by the email-less passkey SIGNUP flow (#780). Same shape as
|
|
257
|
+
* {@link PasskeyLoginResponse} (a freshly-created passkey account is always
|
|
258
|
+
* email-less, so `email` is null), kept as a distinct name for clarity.
|
|
259
|
+
*/
|
|
260
|
+
interface PasskeySignupResponse {
|
|
261
|
+
user: {
|
|
262
|
+
id: string;
|
|
263
|
+
email: string | null;
|
|
264
|
+
username?: string;
|
|
249
265
|
roles: string[];
|
|
250
266
|
};
|
|
251
267
|
access_token: string;
|
|
@@ -1062,6 +1078,46 @@ declare class AuthModule {
|
|
|
1062
1078
|
* against the options returned by `beginPasskeyLogin()`, completing login.
|
|
1063
1079
|
*/
|
|
1064
1080
|
verifyPasskeyLogin(response: PasskeyAuthenticationResponseJSON): Promise<PasskeyLoginResponse>;
|
|
1081
|
+
/**
|
|
1082
|
+
* Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
|
|
1083
|
+
* (#780) — creating a brand-new account with no email and no password. The
|
|
1084
|
+
* project must have passkeys AND public registration enabled. No account is
|
|
1085
|
+
* created until {@link verifyPasskeySignup} succeeds.
|
|
1086
|
+
*
|
|
1087
|
+
* IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
|
|
1088
|
+
* account. Before offering signup, the app MUST first attempt a discoverable
|
|
1089
|
+
* passkey login ({@link beginPasskeyLogin} with no email); only offer signup
|
|
1090
|
+
* when the user has no existing passkey. Skipping this creates duplicate,
|
|
1091
|
+
* fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
|
|
1092
|
+
*/
|
|
1093
|
+
beginPasskeySignup(displayName?: string): Promise<PasskeyRegistrationOptionsJSON>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Verify a WebAuthn attestation produced by `navigator.credentials.create()`
|
|
1096
|
+
* against the options from {@link beginPasskeySignup}, materializing the
|
|
1097
|
+
* email-less account and returning JWT tokens (the caller is now logged in).
|
|
1098
|
+
*/
|
|
1099
|
+
verifyPasskeySignup(response: PasskeyRegistrationResponseJSON): Promise<PasskeySignupResponse>;
|
|
1100
|
+
/**
|
|
1101
|
+
* One-call email-less passkey signup with the B1 idempotency fallback baked
|
|
1102
|
+
* in. The browser WebAuthn functions are injected (the SDK stays transport-
|
|
1103
|
+
* only and does not depend on `@simplewebauthn/browser`):
|
|
1104
|
+
*
|
|
1105
|
+
* 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
|
|
1106
|
+
* 2. If verify fails with `challenge_expired`, a network/timeout error, or
|
|
1107
|
+
* `passkey_already_registered` (the account was in fact created but the
|
|
1108
|
+
* response was lost, or the passkey already exists), fall back to a fresh
|
|
1109
|
+
* discoverable LOGIN ceremony and return that session. That fallback IS the
|
|
1110
|
+
* idempotency mechanism — the server never mints a session from a bare
|
|
1111
|
+
* credential lookup.
|
|
1112
|
+
* 3. If the login fallback also fails (genuinely no credential), the original
|
|
1113
|
+
* error is surfaced so the app can restart signup.
|
|
1114
|
+
*/
|
|
1115
|
+
createUserWithPasskey(ceremony: {
|
|
1116
|
+
startRegistration: (optionsJSON: PasskeyRegistrationOptionsJSON) => Promise<PasskeyRegistrationResponseJSON>;
|
|
1117
|
+
startAuthentication: (optionsJSON: PasskeyAuthenticationOptionsJSON) => Promise<PasskeyAuthenticationResponseJSON>;
|
|
1118
|
+
displayName?: string;
|
|
1119
|
+
}): Promise<PasskeySignupResponse | PasskeyLoginResponse>;
|
|
1120
|
+
private static isSignupFallbackError;
|
|
1065
1121
|
/**
|
|
1066
1122
|
* Fetch WebAuthn attestation options to register a new passkey for the
|
|
1067
1123
|
* currently authenticated user.
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ interface LoginResponse {
|
|
|
42
42
|
user: {
|
|
43
43
|
id: string;
|
|
44
44
|
sub: string;
|
|
45
|
-
email: string;
|
|
45
|
+
email: string | null;
|
|
46
46
|
username?: string;
|
|
47
47
|
name?: string;
|
|
48
48
|
roles: string[];
|
|
@@ -90,7 +90,7 @@ interface UserInfo {
|
|
|
90
90
|
}
|
|
91
91
|
interface UserProfile {
|
|
92
92
|
id: string;
|
|
93
|
-
email: string;
|
|
93
|
+
email: string | null;
|
|
94
94
|
username?: string;
|
|
95
95
|
name?: string;
|
|
96
96
|
roles: string[];
|
|
@@ -245,7 +245,23 @@ interface PasskeyRegistrationResponseJSON {
|
|
|
245
245
|
interface PasskeyLoginResponse {
|
|
246
246
|
user: {
|
|
247
247
|
id: string;
|
|
248
|
-
email: string;
|
|
248
|
+
email: string | null;
|
|
249
|
+
roles: string[];
|
|
250
|
+
};
|
|
251
|
+
access_token: string;
|
|
252
|
+
refresh_token?: string;
|
|
253
|
+
expires_in?: number;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Response returned by the email-less passkey SIGNUP flow (#780). Same shape as
|
|
257
|
+
* {@link PasskeyLoginResponse} (a freshly-created passkey account is always
|
|
258
|
+
* email-less, so `email` is null), kept as a distinct name for clarity.
|
|
259
|
+
*/
|
|
260
|
+
interface PasskeySignupResponse {
|
|
261
|
+
user: {
|
|
262
|
+
id: string;
|
|
263
|
+
email: string | null;
|
|
264
|
+
username?: string;
|
|
249
265
|
roles: string[];
|
|
250
266
|
};
|
|
251
267
|
access_token: string;
|
|
@@ -1062,6 +1078,46 @@ declare class AuthModule {
|
|
|
1062
1078
|
* against the options returned by `beginPasskeyLogin()`, completing login.
|
|
1063
1079
|
*/
|
|
1064
1080
|
verifyPasskeyLogin(response: PasskeyAuthenticationResponseJSON): Promise<PasskeyLoginResponse>;
|
|
1081
|
+
/**
|
|
1082
|
+
* Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
|
|
1083
|
+
* (#780) — creating a brand-new account with no email and no password. The
|
|
1084
|
+
* project must have passkeys AND public registration enabled. No account is
|
|
1085
|
+
* created until {@link verifyPasskeySignup} succeeds.
|
|
1086
|
+
*
|
|
1087
|
+
* IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
|
|
1088
|
+
* account. Before offering signup, the app MUST first attempt a discoverable
|
|
1089
|
+
* passkey login ({@link beginPasskeyLogin} with no email); only offer signup
|
|
1090
|
+
* when the user has no existing passkey. Skipping this creates duplicate,
|
|
1091
|
+
* fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
|
|
1092
|
+
*/
|
|
1093
|
+
beginPasskeySignup(displayName?: string): Promise<PasskeyRegistrationOptionsJSON>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Verify a WebAuthn attestation produced by `navigator.credentials.create()`
|
|
1096
|
+
* against the options from {@link beginPasskeySignup}, materializing the
|
|
1097
|
+
* email-less account and returning JWT tokens (the caller is now logged in).
|
|
1098
|
+
*/
|
|
1099
|
+
verifyPasskeySignup(response: PasskeyRegistrationResponseJSON): Promise<PasskeySignupResponse>;
|
|
1100
|
+
/**
|
|
1101
|
+
* One-call email-less passkey signup with the B1 idempotency fallback baked
|
|
1102
|
+
* in. The browser WebAuthn functions are injected (the SDK stays transport-
|
|
1103
|
+
* only and does not depend on `@simplewebauthn/browser`):
|
|
1104
|
+
*
|
|
1105
|
+
* 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
|
|
1106
|
+
* 2. If verify fails with `challenge_expired`, a network/timeout error, or
|
|
1107
|
+
* `passkey_already_registered` (the account was in fact created but the
|
|
1108
|
+
* response was lost, or the passkey already exists), fall back to a fresh
|
|
1109
|
+
* discoverable LOGIN ceremony and return that session. That fallback IS the
|
|
1110
|
+
* idempotency mechanism — the server never mints a session from a bare
|
|
1111
|
+
* credential lookup.
|
|
1112
|
+
* 3. If the login fallback also fails (genuinely no credential), the original
|
|
1113
|
+
* error is surfaced so the app can restart signup.
|
|
1114
|
+
*/
|
|
1115
|
+
createUserWithPasskey(ceremony: {
|
|
1116
|
+
startRegistration: (optionsJSON: PasskeyRegistrationOptionsJSON) => Promise<PasskeyRegistrationResponseJSON>;
|
|
1117
|
+
startAuthentication: (optionsJSON: PasskeyAuthenticationOptionsJSON) => Promise<PasskeyAuthenticationResponseJSON>;
|
|
1118
|
+
displayName?: string;
|
|
1119
|
+
}): Promise<PasskeySignupResponse | PasskeyLoginResponse>;
|
|
1120
|
+
private static isSignupFallbackError;
|
|
1065
1121
|
/**
|
|
1066
1122
|
* Fetch WebAuthn attestation options to register a new passkey for the
|
|
1067
1123
|
* currently authenticated user.
|
package/dist/index.js
CHANGED
|
@@ -1870,13 +1870,14 @@ function mapProfile(u) {
|
|
|
1870
1870
|
const name = u.name ?? ([u.firstName, u.lastName].filter(Boolean).join(" ") || void 0) ?? u.displayName;
|
|
1871
1871
|
return {
|
|
1872
1872
|
id: u.id ?? u._id ?? u.userId ?? u.sub ?? "",
|
|
1873
|
-
|
|
1873
|
+
// Honest null for email-less (passkey-only) accounts (#780), not a '' coercion.
|
|
1874
|
+
email: u.email ?? null,
|
|
1874
1875
|
username: u.username,
|
|
1875
1876
|
name,
|
|
1876
1877
|
roles: u.roles ?? []
|
|
1877
1878
|
};
|
|
1878
1879
|
}
|
|
1879
|
-
var AuthModule = class {
|
|
1880
|
+
var AuthModule = class _AuthModule {
|
|
1880
1881
|
constructor(http, tokenManager, config) {
|
|
1881
1882
|
this.stateListeners = /* @__PURE__ */ new Set();
|
|
1882
1883
|
this.lastEmittedState = null;
|
|
@@ -2192,6 +2193,82 @@ var AuthModule = class {
|
|
|
2192
2193
|
await this.storeTokensFromLogin(result);
|
|
2193
2194
|
return result;
|
|
2194
2195
|
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
|
|
2198
|
+
* (#780) — creating a brand-new account with no email and no password. The
|
|
2199
|
+
* project must have passkeys AND public registration enabled. No account is
|
|
2200
|
+
* created until {@link verifyPasskeySignup} succeeds.
|
|
2201
|
+
*
|
|
2202
|
+
* IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
|
|
2203
|
+
* account. Before offering signup, the app MUST first attempt a discoverable
|
|
2204
|
+
* passkey login ({@link beginPasskeyLogin} with no email); only offer signup
|
|
2205
|
+
* when the user has no existing passkey. Skipping this creates duplicate,
|
|
2206
|
+
* fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
|
|
2207
|
+
*/
|
|
2208
|
+
async beginPasskeySignup(displayName) {
|
|
2209
|
+
return this.http.request({
|
|
2210
|
+
method: "POST",
|
|
2211
|
+
path: "/auth/passkey/signup/options",
|
|
2212
|
+
body: displayName ? { displayName } : {}
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
/**
|
|
2216
|
+
* Verify a WebAuthn attestation produced by `navigator.credentials.create()`
|
|
2217
|
+
* against the options from {@link beginPasskeySignup}, materializing the
|
|
2218
|
+
* email-less account and returning JWT tokens (the caller is now logged in).
|
|
2219
|
+
*/
|
|
2220
|
+
async verifyPasskeySignup(response) {
|
|
2221
|
+
const result = await this.http.request({
|
|
2222
|
+
method: "POST",
|
|
2223
|
+
path: "/auth/passkey/signup/verify",
|
|
2224
|
+
body: { response }
|
|
2225
|
+
});
|
|
2226
|
+
await this.storeTokensFromLogin(result);
|
|
2227
|
+
return result;
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* One-call email-less passkey signup with the B1 idempotency fallback baked
|
|
2231
|
+
* in. The browser WebAuthn functions are injected (the SDK stays transport-
|
|
2232
|
+
* only and does not depend on `@simplewebauthn/browser`):
|
|
2233
|
+
*
|
|
2234
|
+
* 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
|
|
2235
|
+
* 2. If verify fails with `challenge_expired`, a network/timeout error, or
|
|
2236
|
+
* `passkey_already_registered` (the account was in fact created but the
|
|
2237
|
+
* response was lost, or the passkey already exists), fall back to a fresh
|
|
2238
|
+
* discoverable LOGIN ceremony and return that session. That fallback IS the
|
|
2239
|
+
* idempotency mechanism — the server never mints a session from a bare
|
|
2240
|
+
* credential lookup.
|
|
2241
|
+
* 3. If the login fallback also fails (genuinely no credential), the original
|
|
2242
|
+
* error is surfaced so the app can restart signup.
|
|
2243
|
+
*/
|
|
2244
|
+
async createUserWithPasskey(ceremony) {
|
|
2245
|
+
const options = await this.beginPasskeySignup(ceremony.displayName);
|
|
2246
|
+
const attestation = await ceremony.startRegistration(options);
|
|
2247
|
+
try {
|
|
2248
|
+
return await this.verifyPasskeySignup(attestation);
|
|
2249
|
+
} catch (error) {
|
|
2250
|
+
if (!_AuthModule.isSignupFallbackError(error)) {
|
|
2251
|
+
throw error;
|
|
2252
|
+
}
|
|
2253
|
+
try {
|
|
2254
|
+
const loginOptions = await this.beginPasskeyLogin();
|
|
2255
|
+
const assertion = await ceremony.startAuthentication(loginOptions);
|
|
2256
|
+
return await this.verifyPasskeyLogin(assertion);
|
|
2257
|
+
} catch {
|
|
2258
|
+
throw error;
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
static isSignupFallbackError(error) {
|
|
2263
|
+
if (error instanceof SpacelrNetworkError || error instanceof SpacelrTimeoutError) {
|
|
2264
|
+
return true;
|
|
2265
|
+
}
|
|
2266
|
+
if (error instanceof SpacelrError) {
|
|
2267
|
+
const message = (error.message || "").toLowerCase();
|
|
2268
|
+
return error.statusCode === 409 || message.includes("challenge_expired") || message.includes("already_registered");
|
|
2269
|
+
}
|
|
2270
|
+
return false;
|
|
2271
|
+
}
|
|
2195
2272
|
/**
|
|
2196
2273
|
* Fetch WebAuthn attestation options to register a new passkey for the
|
|
2197
2274
|
* currently authenticated user.
|