@explorins/pers-sdk-react-native 2.0.2 → 2.0.4

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.
@@ -1,4 +1,5 @@
1
1
  import type { RawUserData } from '@explorins/pers-sdk/core';
2
+ import { AccountOwnerType } from '@explorins/pers-sdk/core';
2
3
  import type { UserDTO, AdminDTO, SessionAuthContextResponseDTO } from '@explorins/pers-shared';
3
4
  export type { RawUserData };
4
5
  /**
@@ -42,7 +43,7 @@ export declare const useAuth: () => {
42
43
  isInitialized: boolean;
43
44
  isAuthenticated: boolean;
44
45
  user: UserDTO | AdminDTO | null;
45
- login: (jwtToken: string, userType?: 'user' | 'admin') => Promise<SessionAuthContextResponseDTO>;
46
+ login: (jwtToken: string, userType?: AccountOwnerType) => Promise<SessionAuthContextResponseDTO>;
46
47
  loginWithRawData: (rawUserData: RawUserData) => Promise<void>;
47
48
  logout: () => Promise<void>;
48
49
  refreshUserData: () => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAG/F,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,OAAO;;;;sBA0ByB,MAAM,aAAY,MAAM,GAAG,OAAO,KAAY,QAAQ,6BAA6B,CAAC;oCAuCtE,WAAW,KAAG,QAAQ,IAAI,CAAC;kBAuC/C,QAAQ,IAAI,CAAC;;0BA0BL,QAAQ,OAAO,CAAC;gCAmBV,QAAQ,OAAO,CAAC;mCAqBX,MAAM;qBAmBtB,QAAQ,IAAI,CAAC;wBAoBV,QAAQ,OAAO,CAAC;CAwB5D,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAG/F,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,OAAO;;;;sBA0ByB,MAAM,aAAY,gBAAgB,KAA2B,QAAQ,6BAA6B,CAAC;oCAuCrF,WAAW,KAAG,QAAQ,IAAI,CAAC;kBAuC/C,QAAQ,IAAI,CAAC;;0BA0BL,QAAQ,OAAO,CAAC;gCAmBV,QAAQ,OAAO,CAAC;mCAqBX,MAAM;qBAmBtB,QAAQ,IAAI,CAAC;wBAoBV,QAAQ,OAAO,CAAC;CAwB5D,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import { AccountOwnerType } from '@explorins/pers-sdk/core';
3
4
  /**
4
5
  * React hook for authentication operations in the PERS SDK
5
6
  *
@@ -43,18 +44,18 @@ export const useAuth = () => {
43
44
  * Authenticates a user with a JWT token
44
45
  *
45
46
  * @param jwtToken - The JWT token to authenticate with
46
- * @param userType - The type of user ('user' | 'admin'), defaults to 'user'
47
+ * @param userType - The type of user (AccountOwnerType), defaults to USER
47
48
  * @returns Promise resolving to session auth context with user data
48
49
  * @throws Error if SDK is not initialized or authentication fails
49
50
  *
50
51
  * @example
51
52
  * ```typescript
52
53
  * const { login } = useAuth();
53
- * const result = await login(jwtToken, 'user');
54
+ * const result = await login(jwtToken, AccountOwnerType.USER);
54
55
  * console.log('Logged in user:', result.user);
55
56
  * ```
56
57
  */
57
- const login = useCallback(async (jwtToken, userType = 'user') => {
58
+ const login = useCallback(async (jwtToken, userType = AccountOwnerType.USER) => {
58
59
  if (!sdk || !authProvider) {
59
60
  throw new Error('SDK not initialized. Call initialize() first.');
60
61
  }
package/dist/index.js CHANGED
@@ -27127,7 +27127,7 @@ class AuthService {
27127
27127
  async loginTenantAdmin(jwt) {
27128
27128
  const response = await this.authApi.loginTenantAdmin(jwt);
27129
27129
  if (this.authProvider && response.accessToken) {
27130
- await this.storeTokens(response.accessToken, response.refreshToken, 'admin', jwt);
27130
+ await this.storeTokens(response.accessToken, response.refreshToken, exports.AccountOwnerType.TENANT, jwt);
27131
27131
  }
27132
27132
  return response;
27133
27133
  }
@@ -27137,7 +27137,7 @@ class AuthService {
27137
27137
  async loginUser(jwt) {
27138
27138
  const response = await this.authApi.loginUser(jwt);
27139
27139
  if (this.authProvider && response.accessToken) {
27140
- await this.storeTokens(response.accessToken, response.refreshToken, 'user', jwt);
27140
+ await this.storeTokens(response.accessToken, response.refreshToken, exports.AccountOwnerType.USER, jwt);
27141
27141
  }
27142
27142
  return response;
27143
27143
  }
@@ -27168,7 +27168,7 @@ class AuthService {
27168
27168
  async loginBusiness(jwt, options) {
27169
27169
  const response = await this.authApi.loginBusiness(jwt, options);
27170
27170
  if (this.authProvider && response.accessToken) {
27171
- await this.storeTokens(response.accessToken, response.refreshToken, 'business', jwt);
27171
+ await this.storeTokens(response.accessToken, response.refreshToken, exports.AccountOwnerType.BUSINESS, jwt);
27172
27172
  }
27173
27173
  return response;
27174
27174
  }
@@ -27178,7 +27178,7 @@ class AuthService {
27178
27178
  async loginUserWithRawData(rawLoginData) {
27179
27179
  const response = await this.authApi.loginUnAuthenticated(rawLoginData);
27180
27180
  if (this.authProvider && response.accessToken) {
27181
- await this.storeTokens(response.accessToken, response.refreshToken, 'user');
27181
+ await this.storeTokens(response.accessToken, response.refreshToken, exports.AccountOwnerType.USER);
27182
27182
  }
27183
27183
  return response;
27184
27184
  }
@@ -27660,7 +27660,7 @@ class DPoPManager {
27660
27660
  class DefaultAuthProvider {
27661
27661
  constructor(config = {}) {
27662
27662
  this.config = config;
27663
- this.authType = config.authType || 'user';
27663
+ this.authType = config.authType || exports.AccountOwnerType.USER;
27664
27664
  const storage = config.storage || this.createStorage();
27665
27665
  this.tokenManager = new AuthTokenManager(storage);
27666
27666
  if (config.dpop?.enabled) {
@@ -27793,7 +27793,7 @@ class PersApiClient {
27793
27793
  // Auto-create auth provider if none provided
27794
27794
  if (!this.mergedConfig.authProvider) {
27795
27795
  this.mergedConfig.authProvider = new DefaultAuthProvider({
27796
- authType: this.mergedConfig.authType || 'user',
27796
+ authType: this.mergedConfig.authType || exports.AccountOwnerType.USER,
27797
27797
  projectKey: this.mergedConfig.apiProjectKey,
27798
27798
  storage: this.mergedConfig.authStorage, // Support custom storage
27799
27799
  dpop: {
@@ -28374,9 +28374,9 @@ class AuthManager {
28374
28374
  * console.log('Admin authenticated:', authResult.admin.email);
28375
28375
  * ```
28376
28376
  */
28377
- async loginWithToken(jwtToken, userType = 'user') {
28377
+ async loginWithToken(jwtToken, userType = exports.AccountOwnerType.USER) {
28378
28378
  const authService = this.apiClient.getAuthService();
28379
- const result = userType === 'admin'
28379
+ const result = userType === exports.AccountOwnerType.TENANT
28380
28380
  ? await authService.loginTenantAdmin(jwtToken)
28381
28381
  : await authService.loginUser(jwtToken);
28382
28382
  this.events?.emitSuccess({
@@ -34324,7 +34324,7 @@ function createReactNativeAuthProvider(projectKey, config = {}) {
34324
34324
  if (!projectKey || typeof projectKey !== 'string') {
34325
34325
  throw new Error('createReactNativeAuthProvider: projectKey is required and must be a string');
34326
34326
  }
34327
- const { keyPrefix = `pers_${projectKey.slice(0, 8)}_`, debug = false, customStorage, authType = 'user', dpop } = config;
34327
+ const { keyPrefix = `pers_${projectKey.slice(0, 8)}_`, debug = false, customStorage, authType = exports.AccountOwnerType.USER, dpop } = config;
34328
34328
  // Platform-specific storage selection
34329
34329
  const tokenStorage = customStorage || (isWebPlatform
34330
34330
  ? new LocalStorageTokenStorage()
@@ -34738,18 +34738,18 @@ const useAuth = () => {
34738
34738
  * Authenticates a user with a JWT token
34739
34739
  *
34740
34740
  * @param jwtToken - The JWT token to authenticate with
34741
- * @param userType - The type of user ('user' | 'admin'), defaults to 'user'
34741
+ * @param userType - The type of user (AccountOwnerType), defaults to USER
34742
34742
  * @returns Promise resolving to session auth context with user data
34743
34743
  * @throws Error if SDK is not initialized or authentication fails
34744
34744
  *
34745
34745
  * @example
34746
34746
  * ```typescript
34747
34747
  * const { login } = useAuth();
34748
- * const result = await login(jwtToken, 'user');
34748
+ * const result = await login(jwtToken, AccountOwnerType.USER);
34749
34749
  * console.log('Logged in user:', result.user);
34750
34750
  * ```
34751
34751
  */
34752
- const login = react.useCallback(async (jwtToken, userType = 'user') => {
34752
+ const login = react.useCallback(async (jwtToken, userType = exports.AccountOwnerType.USER) => {
34753
34753
  if (!sdk || !authProvider) {
34754
34754
  throw new Error('SDK not initialized. Call initialize() first.');
34755
34755
  }
@@ -37586,9 +37586,16 @@ function getMetadataFromTokenUnitResponse(tokenUnit, incrementalId) {
37586
37586
  if (!tokenUnit.token?.metadata || tokenUnit.token.metadata.length === 0) {
37587
37587
  return null;
37588
37588
  }
37589
- // Use provided incrementalId, or tokenUnit's incrementalId, or default to 0
37590
- const index = incrementalId ?? tokenUnit.tokenMetadataIncrementalId ?? 0;
37591
- return tokenUnit.token.metadata[index] ?? null;
37589
+ const metadata = tokenUnit.token.metadata;
37590
+ // Use provided incrementalId or tokenUnit's incrementalId to find matching metadata
37591
+ const targetId = incrementalId ?? tokenUnit.tokenMetadataIncrementalId;
37592
+ if (targetId !== undefined) {
37593
+ const found = metadata.find((m) => m.incrementalId === targetId);
37594
+ if (found)
37595
+ return found;
37596
+ }
37597
+ // Fallback to first metadata item
37598
+ return metadata[0];
37592
37599
  }
37593
37600
 
37594
37601
  // ============================================================================