@sendoracloud/sdk-react-native 1.27.0 → 1.30.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.cjs +317 -57
- package/dist/index.d.cts +230 -19
- package/dist/index.d.ts +230 -19
- package/dist/index.js +317 -57
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -221,10 +221,19 @@ declare class Storage {
|
|
|
221
221
|
* user_id is preserved on success. Throws
|
|
222
222
|
* EmailAlreadyTakenError on 409. Otherwise calls
|
|
223
223
|
* /auth-service/signup as a fresh account.
|
|
224
|
-
* signIn(email, password) — POST /auth-service/login.
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
224
|
+
* signIn(email, password) — POST /auth-service/login.
|
|
225
|
+
*
|
|
226
|
+
* HARD INVARIANT — a failed auth attempt leaves the caller exactly as
|
|
227
|
+
* it found them. Every credentialed path captures the anonymous
|
|
228
|
+
* refresh token into a local (for the device-takeover hint), performs
|
|
229
|
+
* its network call, validates the response, and only THEN clears the
|
|
230
|
+
* old identity and persists the new one. Clearing first would drop the
|
|
231
|
+
* refresh token — for an anonymous user the ONLY durable handle on the
|
|
232
|
+
* account — so any failure after that point (offline, 5xx, a mistyped
|
|
233
|
+
* OTP, a cancelled IdP callback) would orphan the account permanently.
|
|
234
|
+
* A track() fired during the round-trip therefore attaches to the
|
|
235
|
+
* still-anonymous identity, which is correct: the user is not
|
|
236
|
+
* identified yet, and the backend reattributes it via the takeover.
|
|
228
237
|
*
|
|
229
238
|
* All public auth ops are serialized through a single-flight chain
|
|
230
239
|
* so a UI double-submit can't mint two anonymous users or interleave
|
|
@@ -308,8 +317,70 @@ declare class AlreadyIdentifiedError extends Error {
|
|
|
308
317
|
* account instead, or link a different credential.
|
|
309
318
|
*/
|
|
310
319
|
declare class CredentialInUseError extends Error {
|
|
311
|
-
|
|
320
|
+
/** Always `"CREDENTIAL_IN_USE"`. */
|
|
321
|
+
readonly code = "CREDENTIAL_IN_USE";
|
|
322
|
+
/**
|
|
323
|
+
* Always `"credential_in_use"`. Carried so this can be handled in the same
|
|
324
|
+
* `switch (err.kind)` as every other auth failure.
|
|
325
|
+
*
|
|
326
|
+
* NOTE this class deliberately does NOT extend `AuthError` — widening
|
|
327
|
+
* `instanceof AuthError` to include it would silently re-route an upgrading
|
|
328
|
+
* app that checks `AuthError` before this class. The taxonomy fields are
|
|
329
|
+
* duplicated instead.
|
|
330
|
+
*/
|
|
331
|
+
readonly kind: "credential_in_use";
|
|
332
|
+
/** Always false — a different account owns it; retrying changes nothing. */
|
|
333
|
+
readonly retryable = false;
|
|
334
|
+
/** The provider whose credential collided, when the server named it. */
|
|
335
|
+
readonly provider?: string;
|
|
336
|
+
/**
|
|
337
|
+
* Which collision this was: `"identity"` = that exact provider identity is
|
|
338
|
+
* already linked to another account; `"email"` = the provider's verified
|
|
339
|
+
* email already belongs to one. Absent on older backends.
|
|
340
|
+
*/
|
|
341
|
+
readonly collision?: "identity" | "email";
|
|
342
|
+
readonly status?: number;
|
|
343
|
+
constructor(message?: string, opts?: {
|
|
344
|
+
provider?: string;
|
|
345
|
+
collision?: "identity" | "email";
|
|
346
|
+
status?: number;
|
|
347
|
+
});
|
|
312
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* What a sign-in should do when the credential you present already belongs to
|
|
351
|
+
* an account (1.30.0).
|
|
352
|
+
*
|
|
353
|
+
* - `"adopt"` (default — and what every earlier release did unconditionally):
|
|
354
|
+
* sign in to that account. This is the reinstall-recovery path: a Game Center
|
|
355
|
+
* / Play Games player identity survives a reinstall server-side, so the
|
|
356
|
+
* "collision" is usually the SAME person's earlier account. If this device is
|
|
357
|
+
* anonymous, that anonymous account is retired — **its row is deleted** — and
|
|
358
|
+
* `onDeviceTakeover` fires with its id.
|
|
359
|
+
* - `"reject"`: throw `CredentialInUseError` and change nothing at all. Use it
|
|
360
|
+
* when the local anonymous session holds progress you are not willing to
|
|
361
|
+
* trade. Mirrors Firebase `linkWithCredential`
|
|
362
|
+
* (`auth/credential-already-in-use`) and Supabase `linkIdentity`.
|
|
363
|
+
*
|
|
364
|
+
* `"reject"` blocks the switch; it does not merge the two accounts. To offer
|
|
365
|
+
* "use my other account", catch the error and re-call with `"adopt"`, then
|
|
366
|
+
* migrate your own data from `onDeviceTakeover`'s `retiredAnonUserId`.
|
|
367
|
+
*/
|
|
368
|
+
type CredentialCollisionPolicy = "adopt" | "reject";
|
|
369
|
+
/** Options for the Game Center / Play Games sign-in methods. */
|
|
370
|
+
type GameSignInOptions = {
|
|
371
|
+
/**
|
|
372
|
+
* ADR-025 link-in-place. When this device is anonymous and the player
|
|
373
|
+
* identity is BRAND NEW, the anonymous account is promoted in place and the
|
|
374
|
+
* user id (sub) is preserved. Has no effect on a collision — see
|
|
375
|
+
* `onCredentialInUse` for that case.
|
|
376
|
+
*/
|
|
377
|
+
link?: boolean;
|
|
378
|
+
/**
|
|
379
|
+
* What to do when the player identity already belongs to an account.
|
|
380
|
+
* Default `"adopt"`. See {@link CredentialCollisionPolicy}.
|
|
381
|
+
*/
|
|
382
|
+
onCredentialInUse?: CredentialCollisionPolicy;
|
|
383
|
+
};
|
|
313
384
|
/** One credential linked to an account (ADR-030 read side, s58.270). */
|
|
314
385
|
type LinkedIdentity = {
|
|
315
386
|
provider: string;
|
|
@@ -321,9 +392,40 @@ type LinkedIdentitiesResponse = {
|
|
|
321
392
|
identities: LinkedIdentity[];
|
|
322
393
|
hasPassword: boolean;
|
|
323
394
|
};
|
|
395
|
+
/**
|
|
396
|
+
* Closed set of auth failure categories (1.28.0). Branch on `kind` instead of
|
|
397
|
+
* string-matching the ~20 raw `code`s the backend and transport can produce.
|
|
398
|
+
*
|
|
399
|
+
* Pairs with the hard guarantee this release introduces: **a failed auth
|
|
400
|
+
* attempt never changes the local session.** An offline sign-in, a mistyped
|
|
401
|
+
* OTP, a dismissed Game Center sheet and a 429 all leave `getUserSync()` and
|
|
402
|
+
* the stored refresh token exactly as they were.
|
|
403
|
+
*/
|
|
404
|
+
type AuthErrorKind = "network" | "server" | "rate_limited" | "invalid_credential" | "account_locked" | "credential_in_use" | "already_identified" | "cancelled" | "config" | "unknown";
|
|
324
405
|
declare class AuthError extends Error {
|
|
325
406
|
code: string;
|
|
326
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Category of the failure — the field to branch on. See `AuthErrorKind`.
|
|
409
|
+
* Derived from `code` (+ HTTP status when known); never affects `code`,
|
|
410
|
+
* which stays exactly what shipped before 1.28.0.
|
|
411
|
+
*/
|
|
412
|
+
readonly kind: AuthErrorKind;
|
|
413
|
+
/** True when retrying the SAME input can plausibly succeed later. */
|
|
414
|
+
readonly retryable: boolean;
|
|
415
|
+
/**
|
|
416
|
+
* Seconds to wait before retrying, when the server told us (429 backoff, or
|
|
417
|
+
* an ACCOUNT_LOCKED cool-off). Absent means "no server-provided hint" — for
|
|
418
|
+
* `account_locked` specifically, absent means the lock does NOT expire on
|
|
419
|
+
* its own and needs support.
|
|
420
|
+
*/
|
|
421
|
+
readonly retryAfterSeconds?: number;
|
|
422
|
+
/** HTTP status when the failure came from a response (absent when offline). */
|
|
423
|
+
readonly status?: number;
|
|
424
|
+
constructor(code: string, message: string, opts?: {
|
|
425
|
+
status?: number;
|
|
426
|
+
retryAfterSeconds?: number;
|
|
427
|
+
kind?: AuthErrorKind;
|
|
428
|
+
});
|
|
327
429
|
}
|
|
328
430
|
interface AuthHooks {
|
|
329
431
|
/** Storage shared with the parent SDK so re-hydration is consistent. */
|
|
@@ -366,6 +468,40 @@ interface DeletionCancelledEvent {
|
|
|
366
468
|
/** Local clock at the time the SDK observed the event. */
|
|
367
469
|
at: Date;
|
|
368
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* Why the local session ended (1.28.0). Before this, a session that died in
|
|
473
|
+
* the background emitted NOTHING — an app could not tell a deliberate sign-out
|
|
474
|
+
* apart from an expired refresh token, and only discovered the difference when
|
|
475
|
+
* `getAccessToken()` started returning null.
|
|
476
|
+
*
|
|
477
|
+
* - `user` — the app called `signOut()`.
|
|
478
|
+
* - `session_expired` — the server rejected the stored refresh token (revoked,
|
|
479
|
+
* expired, rotated away). Transient network failures and
|
|
480
|
+
* rate limits do NOT produce this.
|
|
481
|
+
* - `account_deleted` — `deleteAccount()` succeeded.
|
|
482
|
+
*/
|
|
483
|
+
type AuthSignedOutReason = "user" | "session_expired" | "account_deleted";
|
|
484
|
+
/**
|
|
485
|
+
* A single auth-state transition (1.28.0). Subscribe with
|
|
486
|
+
* `onAuthStateChanged` — one stream covering everything that used to need
|
|
487
|
+
* separate listeners (or had none at all).
|
|
488
|
+
*/
|
|
489
|
+
type AuthStateChange = {
|
|
490
|
+
event: "signed_in";
|
|
491
|
+
user: AuthUser;
|
|
492
|
+
} | {
|
|
493
|
+
event: "signed_out";
|
|
494
|
+
user: null;
|
|
495
|
+
reason: AuthSignedOutReason;
|
|
496
|
+
} | {
|
|
497
|
+
event: "device_takeover";
|
|
498
|
+
user: AuthUser | null;
|
|
499
|
+
retiredAnonUserId: string;
|
|
500
|
+
} | {
|
|
501
|
+
event: "deletion_cancelled";
|
|
502
|
+
user: AuthUser | null;
|
|
503
|
+
};
|
|
504
|
+
type AuthStateListener = (change: AuthStateChange) => void;
|
|
369
505
|
declare class Auth {
|
|
370
506
|
private hooks;
|
|
371
507
|
private user;
|
|
@@ -388,6 +524,7 @@ declare class Auth {
|
|
|
388
524
|
private refreshCooldownUntil;
|
|
389
525
|
private takeoverListeners;
|
|
390
526
|
private deletionCancelledListeners;
|
|
527
|
+
private authStateListeners;
|
|
391
528
|
private lastDeletionCancelled;
|
|
392
529
|
private lastTakeover;
|
|
393
530
|
/**
|
|
@@ -413,6 +550,11 @@ declare class Auth {
|
|
|
413
550
|
*/
|
|
414
551
|
private readyPromise;
|
|
415
552
|
private resolveReady;
|
|
553
|
+
/**
|
|
554
|
+
* True once `hydrate()` has run. Distinguishes "no session restored YET"
|
|
555
|
+
* from "genuinely signed out" for `onAuthStateChanged`'s replay-on-subscribe.
|
|
556
|
+
*/
|
|
557
|
+
private hydrated;
|
|
416
558
|
constructor(hooks: AuthHooks);
|
|
417
559
|
/**
|
|
418
560
|
* Re-hydrate session from storage. Called by the parent SDK during
|
|
@@ -449,6 +591,31 @@ declare class Auth {
|
|
|
449
591
|
* + logged in dev mode. Auth state never depends on listener success.
|
|
450
592
|
*/
|
|
451
593
|
onDeviceTakeover(listener: (evt: DeviceTakeoverEvent) => void): () => void;
|
|
594
|
+
/**
|
|
595
|
+
* Subscribe to every auth-state transition (1.28.0) — the single stream that
|
|
596
|
+
* answers "what happened to my session?". Firebase `onAuthStateChanged` /
|
|
597
|
+
* Supabase `onAuthStateChange` parity.
|
|
598
|
+
*
|
|
599
|
+
* The reason it exists: a session that dies in the BACKGROUND (the server
|
|
600
|
+
* rejected the stored refresh token) used to emit no signal whatsoever, so
|
|
601
|
+
* an app could not distinguish it from a deliberate sign-out and only
|
|
602
|
+
* noticed when `getAccessToken()` began returning null. That transition is
|
|
603
|
+
* now `{ event: "signed_out", reason: "session_expired" }`.
|
|
604
|
+
*
|
|
605
|
+
* Fires the CURRENT state immediately on subscribe once `init()` has
|
|
606
|
+
* hydrated (a `signed_in` when a session was restored from disk — including
|
|
607
|
+
* offline, since hydrate is disk-only), so a subscriber never misses the
|
|
608
|
+
* state it started in. Nothing is emitted for a signed-out cold start.
|
|
609
|
+
*
|
|
610
|
+
* A failed sign-in emits NOTHING: the session is unchanged, so there is no
|
|
611
|
+
* transition to report — the rejected promise is the whole story.
|
|
612
|
+
*
|
|
613
|
+
* Listeners are best-effort; a throwing listener is swallowed (dev-logged)
|
|
614
|
+
* and never affects auth state. Returns an unsubscribe function.
|
|
615
|
+
*/
|
|
616
|
+
onAuthStateChanged(listener: AuthStateListener): () => void;
|
|
617
|
+
/** Fan a state change out to subscribers. Never throws. */
|
|
618
|
+
private emitAuthState;
|
|
452
619
|
/**
|
|
453
620
|
* Inspect the most recent device-takeover event observed by the
|
|
454
621
|
* SDK. Cleared on signOut. Returns null when no takeover has
|
|
@@ -506,9 +673,25 @@ declare class Auth {
|
|
|
506
673
|
getAccessToken(): Promise<string | null>;
|
|
507
674
|
/** Sync read — returns whatever's cached even if expired. Prefer the async variant. */
|
|
508
675
|
getAccessTokenSync(): string | null;
|
|
676
|
+
/**
|
|
677
|
+
* Mint (or return) an anonymous session.
|
|
678
|
+
*
|
|
679
|
+
* Reuses the existing anonymous user when there already is one — the same
|
|
680
|
+
* short-circuit Firebase's `signInAnonymously` performs. Without it, an app
|
|
681
|
+
* that calls this defensively on every cold launch (the most natural thing
|
|
682
|
+
* to write) mints a fresh `user_id` each time, and `persist()` overwrites
|
|
683
|
+
* the stored refresh token — the previous anonymous account's only durable
|
|
684
|
+
* handle — with no takeover, no webhook and no state event. That is the same
|
|
685
|
+
* silent progress loss as a failed sign-in wiping the session, except it
|
|
686
|
+
* happens on a *healthy* network.
|
|
687
|
+
*
|
|
688
|
+
* Pass `forceNew: true` to deliberately abandon the current anonymous
|
|
689
|
+
* session and mint a separate one.
|
|
690
|
+
*/
|
|
509
691
|
signInAnonymously(opts?: {
|
|
510
692
|
name?: string;
|
|
511
693
|
metadata?: Record<string, unknown>;
|
|
694
|
+
forceNew?: boolean;
|
|
512
695
|
}): Promise<AuthUser>;
|
|
513
696
|
/**
|
|
514
697
|
* Create an email/password account.
|
|
@@ -569,6 +752,13 @@ declare class Auth {
|
|
|
569
752
|
* another account (collision → falls back to takeover/merge).
|
|
570
753
|
*/
|
|
571
754
|
link?: boolean;
|
|
755
|
+
/**
|
|
756
|
+
* What to do if this social identity (or its verified email) already
|
|
757
|
+
* belongs to an account. Default `"adopt"` = sign in to it, retiring this
|
|
758
|
+
* device's anonymous account. `"reject"` throws `CredentialInUseError` and
|
|
759
|
+
* leaves everything untouched. See {@link CredentialCollisionPolicy}.
|
|
760
|
+
*/
|
|
761
|
+
onCredentialInUse?: CredentialCollisionPolicy;
|
|
572
762
|
}): Promise<AuthUser>;
|
|
573
763
|
signInWithGoogle(code: string, redirectUri: string, link?: boolean): Promise<AuthUser>;
|
|
574
764
|
signInWithGitHub(code: string, redirectUri: string): Promise<AuthUser>;
|
|
@@ -602,12 +792,8 @@ declare class Auth {
|
|
|
602
792
|
* `link: true` KEEPS the same user id when upgrading an anonymous device
|
|
603
793
|
* (ADR-025 link-in-place); no effect off-anon or on a collision.
|
|
604
794
|
*/
|
|
605
|
-
signInWithGameCenter(opts?:
|
|
606
|
-
|
|
607
|
-
}): Promise<AuthUser>;
|
|
608
|
-
signInWithGameCenter(payload: GameCenterPayload, opts?: {
|
|
609
|
-
link?: boolean;
|
|
610
|
-
}): Promise<AuthUser>;
|
|
795
|
+
signInWithGameCenter(opts?: GameSignInOptions): Promise<AuthUser>;
|
|
796
|
+
signInWithGameCenter(payload: GameCenterPayload, opts?: GameSignInOptions): Promise<AuthUser>;
|
|
611
797
|
/**
|
|
612
798
|
* Google Play Games sign-in (email-less, Android-only).
|
|
613
799
|
*
|
|
@@ -623,14 +809,10 @@ declare class Auth {
|
|
|
623
809
|
*
|
|
624
810
|
* `link: true` = ADR-025 link-in-place (same user id on an anon upgrade).
|
|
625
811
|
*/
|
|
626
|
-
signInWithPlayGames(opts?:
|
|
627
|
-
link?: boolean;
|
|
628
|
-
}): Promise<AuthUser>;
|
|
812
|
+
signInWithPlayGames(opts?: GameSignInOptions): Promise<AuthUser>;
|
|
629
813
|
signInWithPlayGames(payload: {
|
|
630
814
|
serverAuthCode: string;
|
|
631
|
-
}, opts?:
|
|
632
|
-
link?: boolean;
|
|
633
|
-
}): Promise<AuthUser>;
|
|
815
|
+
}, opts?: GameSignInOptions): Promise<AuthUser>;
|
|
634
816
|
/** Link email + password to the current account (sub preserved). */
|
|
635
817
|
linkEmailPassword(email: string, password: string): Promise<AuthUser>;
|
|
636
818
|
/** Link an OAuth social identity (verified idToken or code) to the current account. */
|
|
@@ -882,6 +1064,29 @@ declare class Auth {
|
|
|
882
1064
|
}>;
|
|
883
1065
|
private callAuth;
|
|
884
1066
|
private persist;
|
|
1067
|
+
/**
|
|
1068
|
+
* Drop the local session.
|
|
1069
|
+
*
|
|
1070
|
+
* `reason` drives the `onAuthStateChanged` emission: a real sign-out reason
|
|
1071
|
+
* emits `signed_out`, while `"replaced"` (the internal pre-`persist()` clear
|
|
1072
|
+
* on a SUCCESSFUL sign-in) emits nothing — subscribers see one `signed_in`,
|
|
1073
|
+
* not a spurious logout/login pair.
|
|
1074
|
+
*
|
|
1075
|
+
* ⚠ Never call this before a fallible network request. A failed sign-in must
|
|
1076
|
+
* leave the caller exactly as it found them; for an anonymous session the
|
|
1077
|
+
* refresh token dropped here is the ONLY durable handle on the account, so a
|
|
1078
|
+
* pre-call wipe that is not followed by a successful `persist()` orphans the
|
|
1079
|
+
* account permanently (offline: deterministically). Capture the anon refresh
|
|
1080
|
+
* into a local, make the call, and wipe only after the response validates.
|
|
1081
|
+
*/
|
|
1082
|
+
/**
|
|
1083
|
+
* True when `sent` is still the refresh token on disk — i.e. nothing
|
|
1084
|
+
* replaced or cleared the session while a request carrying it was in
|
|
1085
|
+
* flight. Guards both directions of the refresh race: installing a rotated
|
|
1086
|
+
* token over a session that has since been signed out or replaced, and
|
|
1087
|
+
* wiping a fresh session because an OLD token was rejected.
|
|
1088
|
+
*/
|
|
1089
|
+
private tokenStillCurrent;
|
|
885
1090
|
private wipeLocalIdentity;
|
|
886
1091
|
}
|
|
887
1092
|
|
|
@@ -1664,6 +1869,12 @@ declare class SendoraSDK {
|
|
|
1664
1869
|
* Clear identity + rotate the anonymous id. Call on logout. Awaits
|
|
1665
1870
|
* the AsyncStorage writes so a caller who kills the app immediately
|
|
1666
1871
|
* after doesn't leave stale identity on disk.
|
|
1872
|
+
*
|
|
1873
|
+
* Signs out through `auth` rather than just clearing storage: `clearAll()`
|
|
1874
|
+
* removes the auth keys too, so doing it directly left `Auth` holding an
|
|
1875
|
+
* in-memory user and reporting itself signed in while its refresh token was
|
|
1876
|
+
* already gone — with the server-side session never revoked and no
|
|
1877
|
+
* `onAuthStateChanged` emission telling the app the session had ended.
|
|
1667
1878
|
*/
|
|
1668
1879
|
reset(): Promise<void>;
|
|
1669
1880
|
/** Tear down auto-track listeners. Call in test harnesses. */
|
|
@@ -1673,4 +1884,4 @@ declare class SendoraSDK {
|
|
|
1673
1884
|
}
|
|
1674
1885
|
declare const SendoraCloud: SendoraSDK;
|
|
1675
1886
|
|
|
1676
|
-
export { AlreadyIdentifiedError, type AttachLinkingApiOptions, Auth, AuthError, type AuthTokens, type AuthUser, CredentialInUseError, EmailAlreadyTakenError, type IdentifyTraits, type LinkCreateInput, type LinkCreateResult, type LinkData, LinkError, type LinkErrorCode, type LinkMatchInput, type LinkOpenedEvent, type LinkOpenedHandler, type LinkStats, type LinkedIdentitiesResponse, type LinkedIdentity, Links, type PushTokenReceipt, type PushTokenRegistration, SendoraCloud, type SendoraConfig, type TrackProperties, computeDeviceFingerprint, SendoraCloud as default, extractShortcodeFromUrl, getPlayInstallReferrer };
|
|
1887
|
+
export { AlreadyIdentifiedError, type AttachLinkingApiOptions, Auth, AuthError, type AuthErrorKind, type AuthSignedOutReason, type AuthStateChange, type AuthTokens, type AuthUser, type CredentialCollisionPolicy, CredentialInUseError, type DeletionCancelledEvent, type DeviceTakeoverEvent, EmailAlreadyTakenError, type GameSignInOptions, type IdentifyTraits, type LinkCreateInput, type LinkCreateResult, type LinkData, LinkError, type LinkErrorCode, type LinkMatchInput, type LinkOpenedEvent, type LinkOpenedHandler, type LinkStats, type LinkedIdentitiesResponse, type LinkedIdentity, Links, type PushTokenReceipt, type PushTokenRegistration, SendoraCloud, type SendoraConfig, type TrackProperties, computeDeviceFingerprint, SendoraCloud as default, extractShortcodeFromUrl, getPlayInstallReferrer };
|