@smartcrab/react-native 0.3.2 → 0.4.0-next-20261016193833

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/hooks.js CHANGED
@@ -124,7 +124,7 @@ export const usePasskey = () => {
124
124
  setPasskeys((current) => [...current, created]);
125
125
  return created;
126
126
  }), [client, ceremony]);
127
- const signIn = useCallback(() => ceremony(client.signInWithPasskey()), [client, ceremony]);
127
+ const signIn = useCallback((input) => ceremony(client.signInWithPasskey(input)), [client, ceremony]);
128
128
  const remove = useCallback((passkeyId) => client.deletePasskey(passkeyId).then(() => {
129
129
  setPasskeys((current) => current.filter((passkey) => passkey.passkeyId !== passkeyId));
130
130
  }), [client]);
@@ -143,7 +143,8 @@ export const usePasskey = () => {
143
143
  export const useEmailOtp = () => {
144
144
  const client = useAuthClient();
145
145
  return useMemo(() => ({
146
- sendCode: (email) => client.sendEmailCode({ email }),
146
+ sendCode: (email, input) => client.sendEmailCode({ email, ...input }),
147
+ resendCode: (challengeId, input) => client.resendEmailCode({ challengeId, ...input }),
147
148
  verifyCode: (input) => client.verifyEmailCode(input),
148
149
  }), [client]);
149
150
  };
@@ -151,7 +152,7 @@ export const useEmailOtp = () => {
151
152
  export const useSocialSignIn = () => {
152
153
  const client = useAuthClient();
153
154
  return useMemo(() => ({
154
- signIn: (provider) => client.signInWithSocial({ provider }),
155
+ signIn: (provider, input) => client.signInWithSocial({ provider, ...input }),
155
156
  link: (provider) => client.linkSocialAccount({ provider }),
156
157
  }), [client]);
157
158
  };
package/dist/http.d.ts CHANGED
@@ -29,6 +29,7 @@ export interface JsonRequest {
29
29
  readonly body?: unknown;
30
30
  readonly accessToken?: string;
31
31
  readonly transactionSecret?: string;
32
+ readonly idempotencyKey?: string;
32
33
  }
33
34
  export declare const isOAuthErrorCode: (value: string) => value is OAuthErrorCode;
34
35
  /**
package/dist/http.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { adaptiveChallengeRequiredResponseSchema } from "@smartcrab/contracts-public";
1
2
  import { OAUTH_ERROR_CODES, err, ok } from "@smartcrab/contracts-public";
2
3
  import { parseOAuthErrorWire, parseProblemDetailsWire } from "./errors.js";
3
4
  const OAUTH_ERROR_CODE_SET = new Set(OAUTH_ERROR_CODES);
@@ -40,6 +41,7 @@ export const requestJson = async (fetchPort, request, schema) => {
40
41
  ...(request.transactionSecret !== undefined
41
42
  ? { "x-transaction-secret": request.transactionSecret }
42
43
  : {}),
44
+ ...(request.idempotencyKey !== undefined ? { "Idempotency-Key": request.idempotencyKey } : {}),
43
45
  };
44
46
  const responseOutcome = await fetchPort(request.url, {
45
47
  method: request.method,
@@ -72,6 +74,19 @@ export const requestJson = async (fetchPort, request, schema) => {
72
74
  });
73
75
  }
74
76
  if (!response.ok) {
77
+ const adaptiveChallenge = adaptiveChallengeRequiredResponseSchema.safeParse(json);
78
+ if (adaptiveChallenge.success) {
79
+ return err({
80
+ type: "adaptive_challenge_required",
81
+ challengeId: adaptiveChallenge.data.challenge_id,
82
+ siteKey: adaptiveChallenge.data.site_key,
83
+ action: adaptiveChallenge.data.action,
84
+ transactionId: adaptiveChallenge.data.transaction_id,
85
+ ...(adaptiveChallenge.data.request_id !== undefined
86
+ ? { requestId: adaptiveChallenge.data.request_id }
87
+ : {}),
88
+ });
89
+ }
75
90
  const problem = parseProblemDetailsWire(json);
76
91
  if (problem !== null) {
77
92
  return err({
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  export declare const createReactNativeAuthClient: (initialConfig?: import("./types.js").ReactNativeAuthConfig) => import("./types.js").ReactNativeAuthClient;
2
- export type { AccessTokenRequest, AuthResult, AuthSession, AuthStateListener, AuthStateSnapshot, DeviceSession, EmailCodeChallenge, Passkey, ReactNativeAuthClient, ReactNativeAuthConfig, RegisterPasskeyInput, UpdateUserProfileInput, UserProfile, } from "./types.js";
2
+ export type { AccessTokenRequest, AuthResult, AuthSession, AuthStateListener, AuthStateSnapshot, DeviceSession, EmailCodeChallenge, Passkey, ReactNativeAuthClient, ReactNativeAuthConfig, RegisterPasskeyInput, UpdateUserProfileInput, RecoveryCompletionInput, UserProfile, } from "./types.js";
3
3
  /**
4
4
  * Re-exported so downstream packages (e.g. `@smartcrab/ui-react-native`,
5
5
  * which does not itself depend on `@smartcrab/contracts-public`) can
6
6
  * name the exact type `signInWithSocial`/`linkSocialAccount` take, without
7
7
  * needing their own dependency on contracts-public.
8
8
  */
9
- export type { SocialProvider } from "@smartcrab/contracts-public";
9
+ export type { AdaptiveChallengeAction, MeIdentityLinkCompleteResponse, MeRecoveryCompleteResponse, SocialProvider, } from "@smartcrab/contracts-public";
10
+ export type { AdaptiveChallengeRequiredError, SecureStorageError } from "./errors.js";
10
11
  export { ReactNativeAuthClientError } from "./errors.js";
11
12
  export type { InvalidFlowStateError, InvalidResponseError, NetworkFailureError, NotAuthenticatedError, NotConfiguredError, OAuthFailureError, PasskeyNotSupportedError, PasskeyOperationError, PasskeyOperationFailureReason, ProblemDetailsError, RateLimitedError, ReactNativeAuthError, SocialCancelledError, StateMismatchError, } from "./errors.js";
12
13
  /** Native adapter boundary (design.md §21.2) — never leaks react-native-passkeys types. */
@@ -12,6 +12,7 @@
12
12
  * OTP codes. The access token lives in the client's in-memory closure only
13
13
  * (`client.ts`); nothing in this module ever touches it.
14
14
  */
15
+ import type { ClientId, SocialProvider } from "@smartcrab/contracts-public";
15
16
  export interface SecureStorePort {
16
17
  getItemAsync(key: string): Promise<string | null>;
17
18
  setItemAsync(key: string, value: string): Promise<void>;
@@ -21,6 +22,8 @@ export interface SecureStorePort {
21
22
  export declare const refreshRecordKey: (environmentId: string, clientId: string) => string;
22
23
  /** Transient PKCE transaction record key (design.md §21.6). */
23
24
  export declare const pendingTransactionKey: (environmentId: string, clientId: string) => string;
25
+ /** App-held identity-link PKCE state is separate from sign-in transactions. */
26
+ export declare const pendingIdentityLinkKey: (environmentId: string, clientId: string) => string;
24
27
  /** Minimal session metadata persisted alongside the refresh token (design.md §21.6). */
25
28
  export interface PersistedRefreshRecord {
26
29
  readonly refreshToken: string;
@@ -50,6 +53,17 @@ export interface PersistedPendingTransaction {
50
53
  /** Correlates `sendEmailCode`/`verifyEmailCode` (design.md §21.3 — `verifyEmailCode` takes only `challengeId`). */
51
54
  readonly challengeId?: string;
52
55
  }
56
+ /** Pending app-held identity-link material, stored only in SecureStore. */
57
+ export interface PersistedPendingIdentityLink {
58
+ readonly provider: SocialProvider;
59
+ readonly state: string;
60
+ readonly codeVerifier: string;
61
+ readonly redirectUri: string;
62
+ readonly clientId: ClientId;
63
+ readonly userId: string;
64
+ readonly createdAt: number;
65
+ }
53
66
  /** Never trusts SecureStore contents blindly (IMPL_NOTES §1): hand-narrowed, not `as`-cast. */
54
67
  export declare const parsePersistedRefreshRecord: (value: unknown) => PersistedRefreshRecord | null;
55
68
  export declare const parsePersistedPendingTransaction: (value: unknown) => PersistedPendingTransaction | null;
69
+ export declare const parsePersistedPendingIdentityLink: (value: unknown) => PersistedPendingIdentityLink | null;
@@ -1,3 +1,4 @@
1
+ import { socialProviderSchema } from "@smartcrab/contracts-public";
1
2
  /**
2
3
  * Expo SecureStore keys accept only alphanumeric characters plus `.`, `_`, and
3
4
  * `-`. The design's colon-delimited namespace is therefore encoded with
@@ -8,6 +9,8 @@ const secureStoreKey = (environmentId, clientId, suffix) => `example-auth-${envi
8
9
  export const refreshRecordKey = (environmentId, clientId) => secureStoreKey(environmentId, clientId, "refresh");
9
10
  /** Transient PKCE transaction record key (design.md §21.6). */
10
11
  export const pendingTransactionKey = (environmentId, clientId) => secureStoreKey(environmentId, clientId, "pkce");
12
+ /** App-held identity-link PKCE state is separate from sign-in transactions. */
13
+ export const pendingIdentityLinkKey = (environmentId, clientId) => secureStoreKey(environmentId, clientId, "identity-link");
11
14
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
12
15
  /** Never trusts SecureStore contents blindly (IMPL_NOTES §1): hand-narrowed, not `as`-cast. */
13
16
  export const parsePersistedRefreshRecord = (value) => {
@@ -56,3 +59,32 @@ export const parsePersistedPendingTransaction = (value) => {
56
59
  ...(challengeId !== undefined ? { challengeId } : {}),
57
60
  };
58
61
  };
62
+ export const parsePersistedPendingIdentityLink = (value) => {
63
+ if (!isRecord(value))
64
+ return null;
65
+ const { provider, state, codeVerifier, redirectUri, clientId, userId, createdAt } = value;
66
+ const parsedProvider = socialProviderSchema.safeParse(provider);
67
+ if (!parsedProvider.success)
68
+ return null;
69
+ if (typeof state !== "string" || state.length === 0)
70
+ return null;
71
+ if (typeof codeVerifier !== "string" || codeVerifier.length === 0)
72
+ return null;
73
+ if (typeof redirectUri !== "string" || redirectUri.length === 0)
74
+ return null;
75
+ if (typeof clientId !== "string" || clientId.length === 0)
76
+ return null;
77
+ if (typeof userId !== "string" || userId.length === 0)
78
+ return null;
79
+ if (typeof createdAt !== "number" || !Number.isFinite(createdAt))
80
+ return null;
81
+ return {
82
+ provider: parsedProvider.data,
83
+ state,
84
+ codeVerifier,
85
+ redirectUri,
86
+ clientId,
87
+ userId,
88
+ createdAt,
89
+ };
90
+ };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ClientId, SocialProvider } from "@smartcrab/contracts-public";
2
+ import type { MeRecoveryCompleteResponse } from "@smartcrab/contracts-public";
2
3
  import type { WebBrowserPort } from "./browser-port.js";
3
4
  import type { CryptoPort } from "./crypto-port.js";
4
5
  import type { FetchPort } from "./http.js";
@@ -103,6 +104,9 @@ export interface AccessTokenRequest {
103
104
  export interface RegisterPasskeyInput {
104
105
  readonly name?: string;
105
106
  }
107
+ export interface RecoveryCompletionInput {
108
+ readonly idempotencyKey: string;
109
+ }
106
110
  export interface AuthStateSnapshot {
107
111
  readonly status: "signed_out" | "signed_in";
108
112
  /** Runtime WebAuthn capability (design.md §21.2): the prebuilt UI hides `<PasskeyButton/>` when false. */
@@ -147,10 +151,17 @@ export interface ReactNativeAuthClient {
147
151
  configure(config: ReactNativeAuthConfig): void;
148
152
  getSession(): Promise<AuthSession | null>;
149
153
  getAccessToken(input?: AccessTokenRequest): Promise<string>;
150
- signInWithPasskey(): Promise<AuthResult>;
154
+ signInWithPasskey(input?: {
155
+ challengeToken?: string;
156
+ }): Promise<AuthResult>;
151
157
  registerPasskey(input?: RegisterPasskeyInput): Promise<Passkey>;
152
158
  sendEmailCode(input: {
153
159
  email: string;
160
+ challengeToken?: string;
161
+ }): Promise<EmailCodeChallenge>;
162
+ resendEmailCode(input: {
163
+ challengeId: string;
164
+ challengeToken?: string;
154
165
  }): Promise<EmailCodeChallenge>;
155
166
  verifyEmailCode(input: {
156
167
  challengeId: string;
@@ -158,10 +169,12 @@ export interface ReactNativeAuthClient {
158
169
  }): Promise<AuthResult>;
159
170
  signInWithSocial(input: {
160
171
  provider: SocialProvider;
172
+ challengeToken?: string;
161
173
  }): Promise<AuthResult>;
162
174
  linkSocialAccount(input: {
163
175
  provider: SocialProvider;
164
176
  }): Promise<void>;
177
+ completeRecovery(input: RecoveryCompletionInput): Promise<MeRecoveryCompleteResponse>;
165
178
  listPasskeys(): Promise<Passkey[]>;
166
179
  deletePasskey(passkeyId: string): Promise<void>;
167
180
  listSessions(): Promise<DeviceSession[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartcrab/react-native",
3
- "version": "0.3.2",
3
+ "version": "0.4.0-next-20261016193833",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@smartcrab/contracts-public": "0.3.2"
37
+ "@smartcrab/contracts-public": "0.4.0-next-20261016193833"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": ">=19",