@explorins/pers-sdk-react-native 1.3.2 → 1.5.1
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/README.md +276 -123
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/useAnalytics.d.ts +96 -0
- package/dist/hooks/useAnalytics.d.ts.map +1 -0
- package/dist/hooks/useAnalytics.js +73 -0
- package/dist/hooks/useAuth.d.ts +52 -7
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +250 -3
- package/dist/hooks/useBusiness.d.ts +45 -3
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +182 -28
- package/dist/hooks/useCampaigns.d.ts +11 -4
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +101 -39
- package/dist/hooks/useDonations.d.ts +33 -0
- package/dist/hooks/useDonations.d.ts.map +1 -0
- package/dist/hooks/useDonations.js +62 -0
- package/dist/hooks/useFiles.d.ts +50 -0
- package/dist/hooks/useFiles.d.ts.map +1 -0
- package/dist/hooks/useFiles.js +140 -0
- package/dist/hooks/usePurchases.d.ts +9 -0
- package/dist/hooks/usePurchases.d.ts.map +1 -0
- package/dist/hooks/usePurchases.js +56 -0
- package/dist/hooks/useRedemptions.d.ts +10 -5
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +94 -66
- package/dist/hooks/useTenants.d.ts +10 -0
- package/dist/hooks/useTenants.d.ts.map +1 -0
- package/dist/hooks/useTenants.js +68 -0
- package/dist/hooks/useTokens.d.ts +36 -2
- package/dist/hooks/useTokens.d.ts.map +1 -1
- package/dist/hooks/useTokens.js +180 -19
- package/dist/hooks/useTransactions.d.ts +45 -3
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +152 -31
- package/dist/hooks/useUserStatus.d.ts +9 -0
- package/dist/hooks/useUserStatus.d.ts.map +1 -0
- package/dist/hooks/useUserStatus.js +57 -0
- package/dist/hooks/useUsers.d.ts +17 -0
- package/dist/hooks/useUsers.d.ts.map +1 -0
- package/dist/hooks/useUsers.js +120 -0
- package/dist/hooks/useWeb3.d.ts +69 -6
- package/dist/hooks/useWeb3.d.ts.map +1 -1
- package/dist/hooks/useWeb3.js +177 -17
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12199 -796
- package/dist/index.js.map +1 -1
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/polyfills/index.d.ts.map +1 -1
- package/dist/polyfills/index.js +155 -9
- package/dist/polyfills/web3-polyfills.d.ts +7 -0
- package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
- package/dist/polyfills/web3-polyfills.js +85 -0
- package/dist/providers/PersSDKProvider.d.ts +28 -18
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +63 -129
- package/dist/providers/react-native-auth-provider.d.ts +19 -64
- package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
- package/dist/providers/react-native-auth-provider.js +57 -175
- package/package.json +171 -157
- package/src/hooks/index.ts +11 -1
- package/src/hooks/useAnalytics.ts +150 -0
- package/src/hooks/useAuth.ts +286 -27
- package/src/hooks/useBusiness.ts +193 -30
- package/src/hooks/useCampaigns.ts +121 -43
- package/src/hooks/useDonations.ts +68 -0
- package/src/hooks/useFiles.ts +160 -0
- package/src/hooks/usePurchases.ts +69 -0
- package/src/hooks/useRedemptions.ts +109 -68
- package/src/hooks/useTenants.ts +77 -0
- package/src/hooks/useTokens.ts +189 -21
- package/src/hooks/useTransactions.ts +170 -34
- package/src/hooks/useUserStatus.ts +65 -0
- package/src/hooks/useUsers.ts +133 -0
- package/src/hooks/useWeb3.ts +201 -21
- package/src/index.ts +21 -17
- package/src/polyfills/index.ts +163 -10
- package/src/polyfills/web3-polyfills.ts +98 -0
- package/src/providers/PersSDKProvider.tsx +114 -178
- package/src/providers/react-native-auth-provider.ts +65 -208
- package/dist/index.esm.js +0 -1057
- package/dist/index.esm.js.map +0 -1
- package/dist/polyfills/index.simple.d.ts +0 -2
- package/dist/polyfills/index.simple.d.ts.map +0 -1
- package/dist/polyfills/index.simple.js +0 -17
- package/src/polyfills/index.simple.ts +0 -22
- package/src/types/external-modules.d.ts +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/polyfills/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/polyfills/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,8BAA8B,QAAO,OAuHjD,CAAC;AA0CF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/polyfills/index.js
CHANGED
|
@@ -1,13 +1,159 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// React Native polyfills for crypto and Web3 functionality
|
|
2
|
+
// Consolidated "batteries included" approach for React Native SDK
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { setupWeb3InstanceofPolyfill } from './web3-polyfills';
|
|
5
|
+
// Initialize React Native polyfills
|
|
4
6
|
export const initializeReactNativePolyfills = () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
try {
|
|
8
|
+
// Set up basic global environment
|
|
9
|
+
global.global = global;
|
|
10
|
+
global.Buffer = Buffer;
|
|
11
|
+
// Add process if missing
|
|
12
|
+
if (typeof global !== 'undefined' && !global.process) {
|
|
13
|
+
global.process = {
|
|
14
|
+
env: {},
|
|
15
|
+
version: '16.0.0',
|
|
16
|
+
nextTick: (callback) => setTimeout(callback, 0)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// Initialize crypto polyfills (CRITICAL for Web3)
|
|
20
|
+
require('react-native-get-random-values');
|
|
21
|
+
// Crypto polyfill for better Web3 compatibility
|
|
22
|
+
if (typeof global !== 'undefined' && !global.crypto) {
|
|
23
|
+
global.crypto = {
|
|
24
|
+
getRandomValues: (arr) => {
|
|
25
|
+
require('react-native-get-random-values');
|
|
26
|
+
return global.crypto.getRandomValues(arr);
|
|
27
|
+
},
|
|
28
|
+
randomUUID: () => {
|
|
29
|
+
const hex = '0123456789abcdef';
|
|
30
|
+
let result = '';
|
|
31
|
+
for (let i = 0; i < 32; i++) {
|
|
32
|
+
result += hex[Math.floor(Math.random() * 16)];
|
|
33
|
+
if (i === 7 || i === 11 || i === 15 || i === 19)
|
|
34
|
+
result += '-';
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Add URL polyfill for Web3 compatibility
|
|
41
|
+
if (typeof global !== 'undefined' && !global.URL) {
|
|
42
|
+
try {
|
|
43
|
+
// Try to use react-native-url-polyfill if available
|
|
44
|
+
require('react-native-url-polyfill/auto');
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Fallback to basic URL implementation
|
|
48
|
+
global.URL = class URL {
|
|
49
|
+
constructor(href) {
|
|
50
|
+
this.href = href;
|
|
51
|
+
}
|
|
52
|
+
toString() { return this.href; }
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Add btoa/atob polyfills for Web3 compatibility
|
|
57
|
+
if (typeof global !== 'undefined') {
|
|
58
|
+
if (!global.btoa) {
|
|
59
|
+
global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');
|
|
60
|
+
}
|
|
61
|
+
if (!global.atob) {
|
|
62
|
+
global.atob = (str) => Buffer.from(str, 'base64').toString('binary');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// EventTarget polyfill for Web3 providers
|
|
66
|
+
if (typeof global !== 'undefined' && !global.EventTarget) {
|
|
67
|
+
global.EventTarget = class EventTarget {
|
|
68
|
+
constructor() {
|
|
69
|
+
this.listeners = {};
|
|
70
|
+
}
|
|
71
|
+
addEventListener(type, listener) {
|
|
72
|
+
if (!this.listeners[type]) {
|
|
73
|
+
this.listeners[type] = [];
|
|
74
|
+
}
|
|
75
|
+
this.listeners[type].push(listener);
|
|
76
|
+
}
|
|
77
|
+
removeEventListener(type, listener) {
|
|
78
|
+
if (this.listeners[type]) {
|
|
79
|
+
const index = this.listeners[type].indexOf(listener);
|
|
80
|
+
if (index > -1) {
|
|
81
|
+
this.listeners[type].splice(index, 1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
dispatchEvent(event) {
|
|
86
|
+
if (this.listeners[event.type]) {
|
|
87
|
+
this.listeners[event.type].forEach(listener => {
|
|
88
|
+
listener(event);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Performance polyfill
|
|
96
|
+
if (typeof global !== 'undefined' && !global.performance) {
|
|
97
|
+
global.performance = {
|
|
98
|
+
now: () => Date.now(),
|
|
99
|
+
timeOrigin: Date.now()
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// Stream polyfill (minimal)
|
|
103
|
+
if (typeof global !== 'undefined' && !global.stream) {
|
|
104
|
+
global.stream = {
|
|
105
|
+
Readable: class {
|
|
106
|
+
},
|
|
107
|
+
Writable: class {
|
|
108
|
+
},
|
|
109
|
+
Transform: class {
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// Web3 specific polyfills for instanceof issues
|
|
114
|
+
setupWeb3Polyfills();
|
|
115
|
+
setupWeb3InstanceofPolyfill();
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.warn('[PERS SDK] Failed to initialize some polyfills:', error);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
7
122
|
};
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
123
|
+
// Web3 specific polyfills to fix instanceof issues
|
|
124
|
+
const setupWeb3Polyfills = () => {
|
|
125
|
+
try {
|
|
126
|
+
// Ensure Symbol polyfill for constructor comparison
|
|
127
|
+
if (typeof global !== 'undefined' && !global.Symbol) {
|
|
128
|
+
global.Symbol = {
|
|
129
|
+
for: (key) => `Symbol(${key})`,
|
|
130
|
+
iterator: '@@iterator',
|
|
131
|
+
toStringTag: '@@toStringTag'
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// Add constructor.name polyfill for better class detection
|
|
135
|
+
if (typeof global !== 'undefined' && typeof Function !== 'undefined') {
|
|
136
|
+
const originalToString = Function.prototype.toString;
|
|
137
|
+
if (!Function.prototype.name) {
|
|
138
|
+
Object.defineProperty(Function.prototype, 'name', {
|
|
139
|
+
get: function () {
|
|
140
|
+
const match = originalToString.call(this).match(/function\s*([^(]*)/);
|
|
141
|
+
return match ? match[1] : '';
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Module resolution enhancement for Web3
|
|
147
|
+
if (typeof global !== 'undefined') {
|
|
148
|
+
// Store reference to help with instanceof checks
|
|
149
|
+
global.__PERS_SDK_WEB3_POLYFILLS__ = true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
console.warn('[PERS SDK] Web3 polyfills setup failed:', error);
|
|
154
|
+
}
|
|
11
155
|
};
|
|
12
|
-
// Auto-initialize
|
|
156
|
+
// Auto-initialize polyfills when SDK is imported
|
|
13
157
|
initializeReactNativePolyfills();
|
|
158
|
+
// Export utilities for advanced usage
|
|
159
|
+
export { createSafeWeb3Check } from './web3-polyfills';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web3 specific polyfills for React Native
|
|
3
|
+
* Addresses instanceof and constructor issues in React Native environments
|
|
4
|
+
*/
|
|
5
|
+
export declare const setupWeb3InstanceofPolyfill: () => boolean;
|
|
6
|
+
export declare const createSafeWeb3Check: (provider: unknown) => boolean;
|
|
7
|
+
//# sourceMappingURL=web3-polyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web3-polyfills.d.ts","sourceRoot":"","sources":["../../src/polyfills/web3-polyfills.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,2BAA2B,eAuDvC,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,OAAO,KAAG,OAgCvD,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web3 specific polyfills for React Native
|
|
3
|
+
* Addresses instanceof and constructor issues in React Native environments
|
|
4
|
+
*/
|
|
5
|
+
export const setupWeb3InstanceofPolyfill = () => {
|
|
6
|
+
try {
|
|
7
|
+
// Store the original instanceof behavior
|
|
8
|
+
const originalInstanceof = Function.prototype[Symbol.hasInstance];
|
|
9
|
+
// Override Symbol.hasInstance for better Web3 detection in React Native
|
|
10
|
+
if (typeof global !== 'undefined' && global.Symbol && global.Symbol.hasInstance) {
|
|
11
|
+
// Create a safer instanceof check for Web3
|
|
12
|
+
const createSafeInstanceofCheck = (constructor) => {
|
|
13
|
+
return function (instance) {
|
|
14
|
+
// Try the original check first
|
|
15
|
+
try {
|
|
16
|
+
if (originalInstanceof) {
|
|
17
|
+
return originalInstanceof.call(constructor, instance);
|
|
18
|
+
}
|
|
19
|
+
return instance instanceof constructor;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
// Fallback to constructor and duck-typing checks
|
|
23
|
+
if (!instance || typeof instance !== 'object') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// Check constructor name
|
|
27
|
+
if (instance.constructor && instance.constructor.name === constructor.name) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
// Check constructor reference
|
|
31
|
+
if (instance.constructor === constructor) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// For Web3 specifically, check characteristic properties
|
|
35
|
+
if (constructor.name === 'Web3' &&
|
|
36
|
+
'currentProvider' in instance &&
|
|
37
|
+
'eth' in instance &&
|
|
38
|
+
'utils' in instance) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// Apply the polyfill to global scope for dynamic loading
|
|
46
|
+
global.__PERS_SDK_SAFE_INSTANCEOF__ = createSafeInstanceofCheck;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.warn('[PERS SDK] Web3 instanceof polyfill setup failed:', error);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
export const createSafeWeb3Check = (provider) => {
|
|
56
|
+
if (!provider || typeof provider !== 'object') {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
// Method 1: Check if it's already a Web3 instance using multiple approaches
|
|
61
|
+
const providerObj = provider;
|
|
62
|
+
// Constructor name check
|
|
63
|
+
if (providerObj.constructor?.name === 'Web3') {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
// Duck typing for Web3 properties
|
|
67
|
+
if ('currentProvider' in providerObj &&
|
|
68
|
+
'eth' in providerObj &&
|
|
69
|
+
'utils' in providerObj &&
|
|
70
|
+
typeof providerObj.eth === 'object') {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
// Check for Web3 version property
|
|
74
|
+
if ('version' in providerObj && typeof providerObj.version === 'string') {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.warn('Safe Web3 check failed:', error);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// Auto-initialize
|
|
85
|
+
setupWeb3InstanceofPolyfill();
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
2
|
+
import { PersSDK, PersConfig } from '@explorins/pers-sdk/core';
|
|
3
|
+
import { ReactNativeAuthProvider } from './react-native-auth-provider';
|
|
4
|
+
import { UserDTO, AdminDTO } from '@explorins/pers-shared';
|
|
5
|
+
import type { AuthManager, UserManager, TokenManager, BusinessManager, CampaignManager, RedemptionManager, TransactionManager, PurchaseManager, TenantManager, AnalyticsManager, DonationManager } from '@explorins/pers-sdk/core';
|
|
6
|
+
export type { PersConfig } from '@explorins/pers-sdk/core';
|
|
8
7
|
export interface PersSDKContext {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
sdk: PersSDK | null;
|
|
9
|
+
auth: AuthManager | null;
|
|
10
|
+
users: UserManager | null;
|
|
11
|
+
tokens: TokenManager | null;
|
|
12
|
+
businesses: BusinessManager | null;
|
|
13
|
+
campaigns: CampaignManager | null;
|
|
14
|
+
redemptions: RedemptionManager | null;
|
|
15
|
+
transactions: TransactionManager | null;
|
|
16
|
+
purchases: PurchaseManager | null;
|
|
17
|
+
tenants: TenantManager | null;
|
|
18
|
+
analytics: AnalyticsManager | null;
|
|
19
|
+
donations: DonationManager | null;
|
|
20
|
+
business: BusinessManager | null;
|
|
21
|
+
authProvider: ReactNativeSDKAuthProvider | null;
|
|
16
22
|
isInitialized: boolean;
|
|
17
23
|
isAuthenticated: boolean;
|
|
18
|
-
user:
|
|
24
|
+
user: UserDTO | AdminDTO | null;
|
|
19
25
|
accountAddress: string | null;
|
|
20
|
-
initialize: (config:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
initialize: (config: PersConfig) => Promise<void>;
|
|
27
|
+
setAuthenticationState: (user: UserDTO | AdminDTO | null, accountAddress: string | null, isAuthenticated: boolean) => void;
|
|
28
|
+
refreshUserData: () => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
declare class ReactNativeSDKAuthProvider extends ReactNativeAuthProvider {
|
|
31
|
+
constructor(projectKey: string);
|
|
32
|
+
setToken(token: string | null): Promise<void>;
|
|
33
|
+
getToken(): Promise<string | null>;
|
|
24
34
|
}
|
|
25
35
|
export declare const PersSDKProvider: React.FC<{
|
|
26
36
|
children: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersSDKProvider.d.ts","sourceRoot":"","sources":["../../src/providers/PersSDKProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"PersSDKProvider.d.ts","sourceRoot":"","sources":["../../src/providers/PersSDKProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAuC,SAAS,EAAuB,MAAM,OAAO,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,UAAU,EAAsB,MAAM,0BAA0B,CAAC;AAEnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,WAAW,cAAc;IAE7B,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAGpB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAGlC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAGjC,YAAY,EAAE,0BAA0B,GAAG,IAAI,CAAC;IAGhD,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAG9B,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,sBAAsB,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,eAAe,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3H,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAMD,cAAM,0BAA2B,SAAQ,uBAAuB;gBAClD,UAAU,EAAE,MAAM;IAKxB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAGzC;AAGD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;IACrC,QAAQ,EAAE,SAAS,CAAC;CACrB,CAgHA,CAAC;AAGF,eAAO,MAAM,UAAU,QAAO,cAQ7B,CAAC"}
|
|
@@ -1,51 +1,34 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useState, useCallback, useRef } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { TokenSDK } from '@explorins/pers-sdk/token';
|
|
5
|
-
import { createTransactionSDK } from '@explorins/pers-sdk/transaction';
|
|
6
|
-
import { createBusinessSDK } from '@explorins/pers-sdk/business';
|
|
7
|
-
import { createCampaignSDK } from '@explorins/pers-sdk/campaign';
|
|
8
|
-
import { createRedemptionSDK } from '@explorins/pers-sdk/redemption';
|
|
9
|
-
import { createWeb3SDK } from '@explorins/pers-sdk/web3';
|
|
3
|
+
import { PersSDK } from '@explorins/pers-sdk/core';
|
|
10
4
|
import { ReactNativeHttpClient } from './react-native-http-client';
|
|
11
|
-
import {
|
|
5
|
+
import { ReactNativeAuthProvider } from './react-native-auth-provider';
|
|
12
6
|
// Create the context
|
|
13
7
|
const SDKContext = createContext(null);
|
|
14
|
-
//
|
|
15
|
-
class ReactNativeSDKAuthProvider extends
|
|
8
|
+
// Simple wrapper for SDK integration
|
|
9
|
+
class ReactNativeSDKAuthProvider extends ReactNativeAuthProvider {
|
|
16
10
|
constructor(projectKey) {
|
|
17
|
-
super(projectKey);
|
|
18
|
-
this.projectKey = projectKey;
|
|
19
|
-
this.authType = 'user';
|
|
20
|
-
this._token = null;
|
|
21
|
-
}
|
|
22
|
-
async getToken() {
|
|
23
|
-
return this._token;
|
|
11
|
+
super(projectKey, { debug: true });
|
|
24
12
|
}
|
|
13
|
+
// Override setAccessToken to provide backward compatibility
|
|
25
14
|
async setToken(token) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
if (token) {
|
|
16
|
+
await this.setAccessToken(token);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
await this.clearTokens();
|
|
20
|
+
}
|
|
30
21
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
// Override getToken for backward compatibility
|
|
23
|
+
async getToken() {
|
|
24
|
+
return await super.getToken();
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
27
|
// Provider component
|
|
37
28
|
export const PersSDKProvider = ({ children }) => {
|
|
38
29
|
const initializingRef = useRef(false);
|
|
39
|
-
const [
|
|
30
|
+
const [sdk, setSdk] = useState(null);
|
|
40
31
|
const [authProvider, setAuthProvider] = useState(null);
|
|
41
|
-
const [sdks, setSdks] = useState({
|
|
42
|
-
tokens: null,
|
|
43
|
-
transactions: null,
|
|
44
|
-
business: null,
|
|
45
|
-
campaigns: null,
|
|
46
|
-
redemptions: null,
|
|
47
|
-
web3: null,
|
|
48
|
-
});
|
|
49
32
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
50
33
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
51
34
|
const [user, setUser] = useState(null);
|
|
@@ -53,39 +36,30 @@ export const PersSDKProvider = ({ children }) => {
|
|
|
53
36
|
const initialize = useCallback(async (config) => {
|
|
54
37
|
// Prevent multiple initializations
|
|
55
38
|
if (isInitialized || initializingRef.current) {
|
|
56
|
-
console.log('
|
|
39
|
+
console.log('SDK already initialized or initializing, skipping...');
|
|
57
40
|
return;
|
|
58
41
|
}
|
|
59
42
|
initializingRef.current = true;
|
|
60
43
|
try {
|
|
61
|
-
console.log('
|
|
62
|
-
// Create auth provider
|
|
63
|
-
const auth = new ReactNativeSDKAuthProvider(config.apiProjectKey);
|
|
44
|
+
console.log('Initializing PERS SDK with config:', config);
|
|
45
|
+
// Create React Native auth provider
|
|
46
|
+
const auth = new ReactNativeSDKAuthProvider(config.apiProjectKey || 'default-project');
|
|
64
47
|
setAuthProvider(auth);
|
|
65
48
|
// Create HTTP client
|
|
66
49
|
const httpClient = new ReactNativeHttpClient();
|
|
67
|
-
// Create
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
authProvider: auth
|
|
71
|
-
environment: config.environment || 'development',
|
|
72
|
-
});
|
|
73
|
-
setApiClient(client);
|
|
74
|
-
// Initialize domain SDKs
|
|
75
|
-
const domainSDKs = {
|
|
76
|
-
tokens: new TokenSDK(client),
|
|
77
|
-
transactions: createTransactionSDK(client),
|
|
78
|
-
business: createBusinessSDK(client),
|
|
79
|
-
campaigns: createCampaignSDK(client),
|
|
80
|
-
redemptions: createRedemptionSDK(client),
|
|
81
|
-
web3: createWeb3SDK(client),
|
|
50
|
+
// Create config with auth provider - use the ReactNative auth provider directly
|
|
51
|
+
const sdkConfig = {
|
|
52
|
+
...config,
|
|
53
|
+
authProvider: auth
|
|
82
54
|
};
|
|
83
|
-
|
|
55
|
+
// Initialize PersSDK with manager pattern
|
|
56
|
+
const sdkInstance = new PersSDK(httpClient, sdkConfig);
|
|
57
|
+
setSdk(sdkInstance);
|
|
84
58
|
setIsInitialized(true);
|
|
85
|
-
console.log('
|
|
59
|
+
console.log('PERS SDK initialized successfully');
|
|
86
60
|
}
|
|
87
61
|
catch (error) {
|
|
88
|
-
console.error('
|
|
62
|
+
console.error('Failed to initialize PERS SDK:', error);
|
|
89
63
|
initializingRef.current = false;
|
|
90
64
|
throw error;
|
|
91
65
|
}
|
|
@@ -93,84 +67,45 @@ export const PersSDKProvider = ({ children }) => {
|
|
|
93
67
|
initializingRef.current = false;
|
|
94
68
|
}
|
|
95
69
|
}, []);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// Perform login with API client
|
|
105
|
-
const result = userType === 'admin'
|
|
106
|
-
? await apiClient.loginAdmin(jwtToken)
|
|
107
|
-
: await apiClient.loginUser(jwtToken);
|
|
108
|
-
const userData = result.user || result.admin;
|
|
109
|
-
const userAccountAddress = userData?.accountAddress ||
|
|
110
|
-
userData?.wallets?.[0]?.address ||
|
|
111
|
-
null;
|
|
112
|
-
setUser(userData);
|
|
113
|
-
setAccountAddress(userAccountAddress);
|
|
114
|
-
setIsAuthenticated(true);
|
|
115
|
-
console.log('✅ Login successful');
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.error('❌ Login failed:', error);
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
}, [apiClient, authProvider]);
|
|
123
|
-
const loginWithRawData = useCallback(async (rawUserData) => {
|
|
124
|
-
if (!apiClient || !authProvider) {
|
|
125
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
console.log('🔐 Logging in with raw user data...');
|
|
129
|
-
const result = await apiClient.loginUserWithRawData(rawUserData);
|
|
130
|
-
// Set token from result
|
|
131
|
-
if (result.accessToken) {
|
|
132
|
-
await authProvider.setToken(result.accessToken);
|
|
133
|
-
}
|
|
134
|
-
const userData = result.user;
|
|
135
|
-
const userAccountAddress = userData?.accountAddress ||
|
|
136
|
-
userData?.wallets?.[0]?.address ||
|
|
137
|
-
null;
|
|
138
|
-
setUser(userData);
|
|
139
|
-
setAccountAddress(userAccountAddress);
|
|
140
|
-
setIsAuthenticated(true);
|
|
141
|
-
console.log('✅ Raw data login successful');
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
console.error('❌ Raw data login failed:', error);
|
|
146
|
-
throw error;
|
|
70
|
+
const setAuthenticationState = useCallback((user, accountAddress, isAuthenticated) => {
|
|
71
|
+
setUser(user);
|
|
72
|
+
setAccountAddress(accountAddress);
|
|
73
|
+
setIsAuthenticated(isAuthenticated);
|
|
74
|
+
}, []);
|
|
75
|
+
const refreshUserData = useCallback(async () => {
|
|
76
|
+
if (!sdk || !isAuthenticated || !isInitialized) {
|
|
77
|
+
throw new Error('SDK not initialized or not authenticated. Cannot refresh user data.');
|
|
147
78
|
}
|
|
148
|
-
}, [apiClient, authProvider]);
|
|
149
|
-
const logout = useCallback(async () => {
|
|
150
79
|
try {
|
|
151
|
-
console.log('
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
setUser(null);
|
|
156
|
-
setAccountAddress(null);
|
|
157
|
-
setIsAuthenticated(false);
|
|
158
|
-
console.log('✅ Logout successful');
|
|
80
|
+
console.log('Refreshing user data from remote server...');
|
|
81
|
+
const freshUserData = await sdk.users.getCurrentUser();
|
|
82
|
+
setUser(freshUserData);
|
|
83
|
+
console.log('User data refreshed successfully:', freshUserData);
|
|
159
84
|
}
|
|
160
85
|
catch (error) {
|
|
161
|
-
console.error('
|
|
86
|
+
console.error('Failed to refresh user data:', error);
|
|
162
87
|
throw error;
|
|
163
88
|
}
|
|
164
|
-
}, [
|
|
89
|
+
}, [sdk, isAuthenticated, isInitialized]);
|
|
165
90
|
const contextValue = {
|
|
166
|
-
// SDK
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
91
|
+
// Main SDK instance
|
|
92
|
+
sdk,
|
|
93
|
+
// Manager shortcuts for convenience
|
|
94
|
+
auth: sdk?.auth || null,
|
|
95
|
+
users: sdk?.users || null,
|
|
96
|
+
tokens: sdk?.tokens || null,
|
|
97
|
+
businesses: sdk?.businesses || null,
|
|
98
|
+
campaigns: sdk?.campaigns || null,
|
|
99
|
+
redemptions: sdk?.redemptions || null,
|
|
100
|
+
transactions: sdk?.transactions || null,
|
|
101
|
+
purchases: sdk?.purchases || null,
|
|
102
|
+
tenants: sdk?.tenants || null,
|
|
103
|
+
analytics: sdk?.analytics || null,
|
|
104
|
+
donations: sdk?.donations || null,
|
|
105
|
+
// Legacy support (deprecated but kept for backward compatibility)
|
|
106
|
+
business: sdk?.businesses || null,
|
|
107
|
+
// Platform-specific providers
|
|
108
|
+
authProvider,
|
|
174
109
|
// State
|
|
175
110
|
isInitialized,
|
|
176
111
|
isAuthenticated,
|
|
@@ -178,9 +113,8 @@ export const PersSDKProvider = ({ children }) => {
|
|
|
178
113
|
accountAddress,
|
|
179
114
|
// Methods
|
|
180
115
|
initialize,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
logout,
|
|
116
|
+
setAuthenticationState,
|
|
117
|
+
refreshUserData,
|
|
184
118
|
};
|
|
185
119
|
return (_jsx(SDKContext.Provider, { value: contextValue, children: children }));
|
|
186
120
|
};
|