@camstack/sdk 1.1.19 → 1.1.20

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.cjs CHANGED
@@ -932,7 +932,8 @@ var System = class {
932
932
  if (typeof result === "object" && result !== null && "token" in result) {
933
933
  const r = result;
934
934
  const token = r.token;
935
- if (typeof token === "string" && r.requiresTotp !== true) this.setToken(token);
935
+ const requiresSecondFactor = r.requiresTotp === true || Array.isArray(r.secondFactors) && r.secondFactors.length > 0;
936
+ if (typeof token === "string" && !requiresSecondFactor) this.setToken(token);
936
937
  }
937
938
  return result;
938
939
  }
@@ -954,6 +955,30 @@ var System = class {
954
955
  }
955
956
  return result;
956
957
  }
958
+ /**
959
+ * Passkey second leg — step 1. Exchanges the login challenge token for
960
+ * the WebAuthn assertion options; the caller feeds `optionsJSON` to
961
+ * `@simplewebauthn/browser` `startAuthentication`. PUBLIC (pre-session).
962
+ */
963
+ async loginBeginPasskey(challengeToken) {
964
+ return await this._trpcClient.auth.loginBeginPasskey.mutate({ challengeToken });
965
+ }
966
+ /**
967
+ * Passkey second leg — step 2. Submits the browser assertion; on
968
+ * success the server mints the real session JWT, which we set as the
969
+ * active token on this client.
970
+ */
971
+ async loginVerifyPasskey(challengeToken, response) {
972
+ const result = await this._trpcClient.auth.loginVerifyPasskey.mutate({
973
+ challengeToken,
974
+ response
975
+ });
976
+ if (typeof result === "object" && result !== null && "token" in result) {
977
+ const token = result.token;
978
+ if (typeof token === "string") this.setToken(token);
979
+ }
980
+ return result;
981
+ }
957
982
  async logout() {
958
983
  await this._trpcClient.auth.logout.mutate();
959
984
  }
@@ -975,6 +1000,18 @@ var System = class {
975
1000
  async getOwnTotpStatus() {
976
1001
  return await this._trpcClient.auth.getOwnTotpStatus.query();
977
1002
  }
1003
+ async beginOwnPasskeyRegistration() {
1004
+ return await this._trpcClient.auth.beginOwnPasskeyRegistration.mutate();
1005
+ }
1006
+ async finishOwnPasskeyRegistration(input) {
1007
+ return await this._trpcClient.auth.finishOwnPasskeyRegistration.mutate(input);
1008
+ }
1009
+ async listOwnPasskeys() {
1010
+ return await this._trpcClient.auth.listOwnPasskeys.query();
1011
+ }
1012
+ async removeOwnPasskey(input) {
1013
+ return await this._trpcClient.auth.removeOwnPasskey.mutate(input);
1014
+ }
978
1015
  /** Update the auth token (e.g. after login or token refresh). */
979
1016
  setToken(token) {
980
1017
  this.token = token;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { System, createSystem, raceFastestEndpoint } from './system.js';
2
- export type { SystemConfig, UserInfo, SystemLiveEvent, SystemLiveEventListener } from './system.js';
2
+ export type { SystemConfig, UserInfo, SystemLiveEvent, SystemLiveEventListener, SecondFactorKind, } from './system.js';
3
3
  export type { DeviceInfo } from '@camstack/types';
4
4
  export type { BackendAppRouter } from './backend-router.js';
5
5
  export type { BackendAppRouter as AppRouter } from './backend-router.js';
package/dist/index.js CHANGED
@@ -931,7 +931,8 @@ var System = class {
931
931
  if (typeof result === "object" && result !== null && "token" in result) {
932
932
  const r = result;
933
933
  const token = r.token;
934
- if (typeof token === "string" && r.requiresTotp !== true) this.setToken(token);
934
+ const requiresSecondFactor = r.requiresTotp === true || Array.isArray(r.secondFactors) && r.secondFactors.length > 0;
935
+ if (typeof token === "string" && !requiresSecondFactor) this.setToken(token);
935
936
  }
936
937
  return result;
937
938
  }
@@ -953,6 +954,30 @@ var System = class {
953
954
  }
954
955
  return result;
955
956
  }
957
+ /**
958
+ * Passkey second leg — step 1. Exchanges the login challenge token for
959
+ * the WebAuthn assertion options; the caller feeds `optionsJSON` to
960
+ * `@simplewebauthn/browser` `startAuthentication`. PUBLIC (pre-session).
961
+ */
962
+ async loginBeginPasskey(challengeToken) {
963
+ return await this._trpcClient.auth.loginBeginPasskey.mutate({ challengeToken });
964
+ }
965
+ /**
966
+ * Passkey second leg — step 2. Submits the browser assertion; on
967
+ * success the server mints the real session JWT, which we set as the
968
+ * active token on this client.
969
+ */
970
+ async loginVerifyPasskey(challengeToken, response) {
971
+ const result = await this._trpcClient.auth.loginVerifyPasskey.mutate({
972
+ challengeToken,
973
+ response
974
+ });
975
+ if (typeof result === "object" && result !== null && "token" in result) {
976
+ const token = result.token;
977
+ if (typeof token === "string") this.setToken(token);
978
+ }
979
+ return result;
980
+ }
956
981
  async logout() {
957
982
  await this._trpcClient.auth.logout.mutate();
958
983
  }
@@ -974,6 +999,18 @@ var System = class {
974
999
  async getOwnTotpStatus() {
975
1000
  return await this._trpcClient.auth.getOwnTotpStatus.query();
976
1001
  }
1002
+ async beginOwnPasskeyRegistration() {
1003
+ return await this._trpcClient.auth.beginOwnPasskeyRegistration.mutate();
1004
+ }
1005
+ async finishOwnPasskeyRegistration(input) {
1006
+ return await this._trpcClient.auth.finishOwnPasskeyRegistration.mutate(input);
1007
+ }
1008
+ async listOwnPasskeys() {
1009
+ return await this._trpcClient.auth.listOwnPasskeys.query();
1010
+ }
1011
+ async removeOwnPasskey(input) {
1012
+ return await this._trpcClient.auth.removeOwnPasskey.mutate(input);
1013
+ }
977
1014
  /** Update the auth token (e.g. after login or token refresh). */
978
1015
  setToken(token) {
979
1016
  this.token = token;
package/dist/system.d.ts CHANGED
@@ -11,9 +11,16 @@
11
11
  * — a future phase will narrow the surface further.
12
12
  */
13
13
  import { createWSClient, type TRPCClient } from '@trpc/client';
14
- import type { DeviceProxy, DeviceInfo, DeviceQueryFilters, DeviceLifecycleListener, SystemProxy } from '@camstack/types';
14
+ import type { DeviceProxy, DeviceInfo, DeviceQueryFilters, DeviceLifecycleListener, SystemProxy, PasskeySummary } from '@camstack/types';
15
15
  import type { BackendAppRouter } from './backend-router.js';
16
16
  import type { BackendConnectionState } from './types.js';
17
+ /**
18
+ * Second-factor kinds reported by `auth.login`. Kept in the SDK (not
19
+ * imported from a cap) because it's a login-flow contract, not a cap
20
+ * surface. `totp` → the `user-management` TOTP surface; `passkey` → any
21
+ * `user-passkeys` cap provider.
22
+ */
23
+ export type SecondFactorKind = 'totp' | 'passkey';
17
24
  /**
18
25
  * Canonical user-info shape returned by `getMe()`. Mirrors the server's
19
26
  * `auth.me` output — kept narrow so SDK consumers don't need the full
@@ -184,6 +191,7 @@ export declare class System {
184
191
  login(username: string, password: string): Promise<{
185
192
  token: string;
186
193
  requiresTotp?: boolean;
194
+ secondFactors?: readonly SecondFactorKind[];
187
195
  }>;
188
196
  /**
189
197
  * Second leg of the 2FA login. The caller passes the challenge
@@ -195,6 +203,22 @@ export declare class System {
195
203
  loginVerifyTotp(challengeToken: string, code: string): Promise<{
196
204
  token: string;
197
205
  }>;
206
+ /**
207
+ * Passkey second leg — step 1. Exchanges the login challenge token for
208
+ * the WebAuthn assertion options; the caller feeds `optionsJSON` to
209
+ * `@simplewebauthn/browser` `startAuthentication`. PUBLIC (pre-session).
210
+ */
211
+ loginBeginPasskey(challengeToken: string): Promise<{
212
+ optionsJSON: Record<string, unknown>;
213
+ }>;
214
+ /**
215
+ * Passkey second leg — step 2. Submits the browser assertion; on
216
+ * success the server mints the real session JWT, which we set as the
217
+ * active token on this client.
218
+ */
219
+ loginVerifyPasskey(challengeToken: string, response: Record<string, unknown>): Promise<{
220
+ token: string;
221
+ }>;
198
222
  logout(): Promise<void>;
199
223
  getMe(): Promise<UserInfo>;
200
224
  changeOwnPassword(input: {
@@ -219,6 +243,22 @@ export declare class System {
219
243
  enabled: boolean;
220
244
  confirmedAt: number | null;
221
245
  }>;
246
+ beginOwnPasskeyRegistration(): Promise<{
247
+ optionsJSON: Record<string, unknown>;
248
+ }>;
249
+ finishOwnPasskeyRegistration(input: {
250
+ response: Record<string, unknown>;
251
+ label: string;
252
+ }): Promise<{
253
+ success: true;
254
+ credentialId: string;
255
+ }>;
256
+ listOwnPasskeys(): Promise<readonly PasskeySummary[]>;
257
+ removeOwnPasskey(input: {
258
+ credentialId: string;
259
+ }): Promise<{
260
+ success: true;
261
+ }>;
222
262
  /** Update the auth token (e.g. after login or token refresh). */
223
263
  setToken(token: string): void;
224
264
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/sdk",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",