@savers_app/react-native-sdk 1.2.4 → 1.2.5
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 +51 -27
- package/lib/module/data/models/tokenModel.js +25 -0
- package/lib/module/data/models/tokenModel.js.map +1 -0
- package/lib/module/data/network/apiClient.js +2 -2
- package/lib/module/data/network/apiClient.js.map +1 -1
- package/lib/module/data/network/apiEndpoints.js +2 -1
- package/lib/module/data/network/apiEndpoints.js.map +1 -1
- package/lib/module/data/network/apiRepository.js +20 -6
- package/lib/module/data/network/apiRepository.js.map +1 -1
- package/lib/module/data/network/apiService.js +36 -0
- package/lib/module/data/network/apiService.js.map +1 -1
- package/lib/module/data/network/interceptors/authInterceptor.js +6 -3
- package/lib/module/data/network/interceptors/authInterceptor.js.map +1 -1
- package/lib/module/services/url/urlGenerator.js +7 -3
- package/lib/module/services/url/urlGenerator.js.map +1 -1
- package/lib/module/services/webview/messageHandler.js +5 -2
- package/lib/module/services/webview/messageHandler.js.map +1 -1
- package/lib/module/utils/config.js +34 -0
- package/lib/module/utils/config.js.map +1 -0
- package/lib/typescript/src/data/models/tokenModel.d.ts +15 -0
- package/lib/typescript/src/data/models/tokenModel.d.ts.map +1 -0
- package/lib/typescript/src/data/network/apiEndpoints.d.ts +2 -1
- package/lib/typescript/src/data/network/apiEndpoints.d.ts.map +1 -1
- package/lib/typescript/src/data/network/apiRepository.d.ts +2 -0
- package/lib/typescript/src/data/network/apiRepository.d.ts.map +1 -1
- package/lib/typescript/src/data/network/apiService.d.ts +6 -0
- package/lib/typescript/src/data/network/apiService.d.ts.map +1 -1
- package/lib/typescript/src/data/network/interceptors/authInterceptor.d.ts +2 -0
- package/lib/typescript/src/data/network/interceptors/authInterceptor.d.ts.map +1 -1
- package/lib/typescript/src/services/url/urlGenerator.d.ts +1 -0
- package/lib/typescript/src/services/url/urlGenerator.d.ts.map +1 -1
- package/lib/typescript/src/services/webview/messageHandler.d.ts.map +1 -1
- package/lib/typescript/src/utils/config.d.ts +5 -0
- package/lib/typescript/src/utils/config.d.ts.map +1 -0
- package/package.json +8 -2
- package/src/data/models/tokenModel.ts +43 -0
- package/src/data/network/apiClient.ts +2 -2
- package/src/data/network/apiEndpoints.ts +2 -1
- package/src/data/network/apiRepository.ts +30 -6
- package/src/data/network/apiService.ts +41 -0
- package/src/data/network/interceptors/authInterceptor.ts +12 -3
- package/src/services/url/urlGenerator.ts +9 -1
- package/src/services/webview/messageHandler.ts +5 -8
- package/src/utils/config.ts +35 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ React Native SDK that bridges host app features like maps, dialer, browser, devi
|
|
|
6
6
|
- Open native maps by coordinates with graceful browser fallback
|
|
7
7
|
- Dial pad invocation with optional number and direct call helper
|
|
8
8
|
- External browser navigation from the host app or from web content
|
|
9
|
-
- Close current screen via
|
|
9
|
+
- Close current screen via global `navigationRef` (React Navigation) using **END_SESSION**
|
|
10
10
|
- Device ID retrieval (via `react-native-device-info`)
|
|
11
11
|
- Optional device location retrieval and URL payload enrichment
|
|
12
12
|
- Session and keys management (API key, encryption key, program ref code, auth mode)
|
|
@@ -155,15 +155,48 @@ const url = await generateUrl({
|
|
|
155
155
|
},
|
|
156
156
|
// sessionId is optional; when omitted, the SDK uses its stored session id
|
|
157
157
|
// deviceInfo is optional; the SDK builds it internally using device id (and optional coordinates)
|
|
158
|
+
nonce: '<NONCE_TOKEN>',
|
|
158
159
|
});
|
|
159
160
|
// returns https://m.saversapp.com/?pRefCode=...&qP=...
|
|
160
161
|
```
|
|
161
162
|
|
|
163
|
+
Fetch nonce and call generateUrl:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import { ApiService, generateUrl } from '@savers_app/react-native-sdk';
|
|
167
|
+
|
|
168
|
+
const generator = new ApiService().getNonce({
|
|
169
|
+
extUserId: '12345',
|
|
170
|
+
partnerCode: 'abcde',
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const { value } = await generator.next();
|
|
174
|
+
if (value?.error) throw new Error(value.error);
|
|
175
|
+
if (!value?.token) throw new Error('Nonce not received');
|
|
176
|
+
|
|
177
|
+
const url = await generateUrl({
|
|
178
|
+
authType: 'PHONE',
|
|
179
|
+
profile: {
|
|
180
|
+
userId: 'USER_ID',
|
|
181
|
+
email: 'jane@example.com',
|
|
182
|
+
firstname: 'Jane',
|
|
183
|
+
lastname: 'Doe',
|
|
184
|
+
phone: '+15555550100',
|
|
185
|
+
pv: '1',
|
|
186
|
+
ev: '1',
|
|
187
|
+
},
|
|
188
|
+
screen: { name: 'Explore', attributes: [{ key: 'offerId', value: '123' }] },
|
|
189
|
+
nonce: value.token,
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
162
193
|
Profile requirements:
|
|
163
194
|
- `userId` and `email` are mandatory
|
|
164
195
|
- `pv` and `ev` are optional (`'0'` or `'1'`)
|
|
165
196
|
- `phone` is mandatory when `authType` is `'PHONE'`
|
|
166
197
|
- `username` is mandatory when `authType` is `'USERNAME'`
|
|
198
|
+
Nonce requirement:
|
|
199
|
+
- `nonce` is mandatory and should be retrieved using `ApiService.getNonce` before calling `generateUrl`.
|
|
167
200
|
|
|
168
201
|
Screen requirements:
|
|
169
202
|
- `screen.name` is optional, defaults to `'Explore'`
|
|
@@ -183,34 +216,25 @@ Notes:
|
|
|
183
216
|
|
|
184
217
|
The SDK can close the current screen without knowing the host app's navigation structure. This is useful for flows initiated from web content or deep links that need to programmatically exit back to the host app.
|
|
185
218
|
|
|
186
|
-
One-time host app setup
|
|
219
|
+
One-time host app setup using a global `navigationRef`:
|
|
187
220
|
|
|
188
221
|
```tsx
|
|
189
|
-
import {
|
|
190
|
-
import {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
function SaversNavBinder() {
|
|
194
|
-
const navigation = useNavigation();
|
|
195
|
-
useEffect(() => {
|
|
196
|
-
setGoBackImpl(() => {
|
|
197
|
-
if (navigation.canGoBack()) {
|
|
198
|
-
navigation.goBack();
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
return false;
|
|
202
|
-
});
|
|
203
|
-
}, [navigation]);
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
222
|
+
import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native';
|
|
223
|
+
import { SaversAppSDK } from '@savers_app/react-native-sdk';
|
|
224
|
+
|
|
225
|
+
export const navigationRef = createNavigationContainerRef();
|
|
206
226
|
|
|
207
227
|
export function App() {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
228
|
+
// Initialize the SDK once (e.g., in a root effect or before rendering)
|
|
229
|
+
SaversAppSDK.initialized({
|
|
230
|
+
apiKey: 'YOUR_API_KEY',
|
|
231
|
+
encryptionKey: 'BASE64_256_BIT_ENCRYPTION_KEY',
|
|
232
|
+
pRefCode: 'PROGRAM_REF_CODE',
|
|
233
|
+
authMode: 'EMAIL', // or 'PHONE'
|
|
234
|
+
navigationRef, // pass the ref to the SDK
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
return <NavigationContainer ref={navigationRef}>{/* your navigators */}</NavigationContainer>;
|
|
214
238
|
}
|
|
215
239
|
```
|
|
216
240
|
|
|
@@ -224,8 +248,8 @@ closeCurrentScreenSafe(); // Android-only fallback to exitApp if it can't goBack
|
|
|
224
248
|
```
|
|
225
249
|
|
|
226
250
|
Notes:
|
|
227
|
-
-
|
|
228
|
-
- The
|
|
251
|
+
- The same `navigationRef` is passed to the `NavigationContainer` and to `SaversAppSDK.initialized`.
|
|
252
|
+
- The SDK stores this ref internally to implement `closeCurrentScreen()` reliably.
|
|
229
253
|
|
|
230
254
|
## WebView Integration
|
|
231
255
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function tokenResponseFromJson(json) {
|
|
4
|
+
const map = {
|
|
5
|
+
...json
|
|
6
|
+
};
|
|
7
|
+
const token = typeof map.token === 'string' && map.token.length > 0 ? map.token : null;
|
|
8
|
+
const statusCode = typeof map.statusCode === 'number' ? map.statusCode : typeof map.statusCode === 'string' ? Number(map.statusCode) : null;
|
|
9
|
+
const error = typeof map.error === 'string' && map.error.length > 0 ? map.error : null;
|
|
10
|
+
const messages = Array.isArray(map.message) ? map.message.filter(m => typeof m === 'string') : null;
|
|
11
|
+
return {
|
|
12
|
+
token: token ?? null,
|
|
13
|
+
statusCode: statusCode ?? null,
|
|
14
|
+
error: error ?? null,
|
|
15
|
+
messages: messages && messages.length > 0 ? messages : null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export const token = d => d?.token ?? null;
|
|
19
|
+
export const hasToken = d => !!(d?.token && d.token.length > 0);
|
|
20
|
+
export const isValid = d => hasToken(d);
|
|
21
|
+
export const status = d => d?.statusCode ?? null;
|
|
22
|
+
export const error = d => d?.error ?? null;
|
|
23
|
+
export const messages = d => d?.messages ?? null;
|
|
24
|
+
export const hasError = d => !!(d?.error || d?.messages && d.messages.length > 0 || d?.statusCode);
|
|
25
|
+
//# sourceMappingURL=tokenModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["tokenResponseFromJson","json","map","token","length","statusCode","Number","error","messages","Array","isArray","message","filter","m","d","hasToken","isValid","status","hasError"],"sourceRoot":"../../../../src","sources":["data/models/tokenModel.ts"],"mappings":";;AAOA,OAAO,SAASA,qBAAqBA,CAACC,IAAS,EAAiB;EAC9D,MAAMC,GAAG,GAAG;IAAE,GAAID;EAA6B,CAAC;EAChD,MAAME,KAAK,GACT,OAAOD,GAAG,CAACC,KAAK,KAAK,QAAQ,IAAID,GAAG,CAACC,KAAK,CAACC,MAAM,GAAG,CAAC,GAAGF,GAAG,CAACC,KAAK,GAAG,IAAI;EAC1E,MAAME,UAAU,GACd,OAAOH,GAAG,CAACG,UAAU,KAAK,QAAQ,GAC9BH,GAAG,CAACG,UAAU,GACd,OAAOH,GAAG,CAACG,UAAU,KAAK,QAAQ,G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EAAEN,QAAQ,IAAIM,CAAC,CAACN,QAAQ,CAACJ,MAAM,GAAG,CAAE,IAAIU,CAAC,EAAET,UAAU,CAAC","ignoreList":[]}
|
|
@@ -18,8 +18,8 @@ export let Environment = /*#__PURE__*/function (Environment) {
|
|
|
18
18
|
}({});
|
|
19
19
|
export class ApiClient {
|
|
20
20
|
static baseUrls = {
|
|
21
|
-
[Environment.production]: 'https
|
|
22
|
-
[Environment.staging]: 'https
|
|
21
|
+
[Environment.production]: 'https://devapi.saversapp.com/clo/v1/',
|
|
22
|
+
[Environment.staging]: 'https://devapi.saversapp.com/clo/v1/'
|
|
23
23
|
};
|
|
24
24
|
interceptors = [];
|
|
25
25
|
constructor(environment = Environment.production) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["logger","AuthInterceptor","RetryInterceptor","ErrorInterceptor","NetworkInterceptor","LoggingInterceptor","Environment","ApiClient","baseUrls","production","staging","interceptors","constructor","environment","baseUrl","get","endpoint","params","request","undefined","post","data","put","delete","method","url","buildUrl","options","headers","body","interceptor","onRequest","Error","response","fetch","JSON","stringify","responseData","json","responseObj","status","statusText","onResponse","error","handledError","onError","queryString","Object","keys","map","key","encodeURIComponent","join"],"sourceRoot":"../../../../src","sources":["data/network/apiClient.ts"],"mappings":";;AAAA;;AAEA;AACA,SAASA,MAAM,QAAQ,uBAAoB;;AAE3C;AACA,SAASC,eAAe,QAAQ,mCAAgC;AAChE,SAASC,gBAAgB,QAAQ,oCAAiC;AAClE,SAASC,gBAAgB,QAAQ,oCAAiC;AAClE,SAASC,kBAAkB,QAAQ,sCAAmC;AACtE,SAASC,kBAAkB,QAAQ,sCAAmC;AAEtE,WAAYC,WAAW,0BAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAKvB,OAAO,MAAMC,SAAS,CAAC;EACrB,OAAwBC,QAAQ,GAAgC;IAC9D,CAACF,WAAW,CAACG,UAAU,GAAG,
|
|
1
|
+
{"version":3,"names":["logger","AuthInterceptor","RetryInterceptor","ErrorInterceptor","NetworkInterceptor","LoggingInterceptor","Environment","ApiClient","baseUrls","production","staging","interceptors","constructor","environment","baseUrl","get","endpoint","params","request","undefined","post","data","put","delete","method","url","buildUrl","options","headers","body","interceptor","onRequest","Error","response","fetch","JSON","stringify","responseData","json","responseObj","status","statusText","onResponse","error","handledError","onError","queryString","Object","keys","map","key","encodeURIComponent","join"],"sourceRoot":"../../../../src","sources":["data/network/apiClient.ts"],"mappings":";;AAAA;;AAEA;AACA,SAASA,MAAM,QAAQ,uBAAoB;;AAE3C;AACA,SAASC,eAAe,QAAQ,mCAAgC;AAChE,SAASC,gBAAgB,QAAQ,oCAAiC;AAClE,SAASC,gBAAgB,QAAQ,oCAAiC;AAClE,SAASC,kBAAkB,QAAQ,sCAAmC;AACtE,SAASC,kBAAkB,QAAQ,sCAAmC;AAEtE,WAAYC,WAAW,0BAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAKvB,OAAO,MAAMC,SAAS,CAAC;EACrB,OAAwBC,QAAQ,GAAgC;IAC9D,CAACF,WAAW,CAACG,UAAU,GAAG,sCAAsC;IAChE,CAACH,WAAW,CAACI,OAAO,GAAG;EACzB,CAAC;EAGOC,YAAY,GAAU,EAAE;EAEhCC,WAAWA,CAACC,WAAwB,GAAGP,WAAW,CAACG,UAAU,EAAE;IAC7D,IAAI,CAACK,OAAO,GAAGP,SAAS,CAACC,QAAQ,CAACK,WAAW,CAAC;IAE9C,IAAI,CAACF,YAAY,GAAG,CAClB,IAAIN,kBAAkB,CAAC,CAAC,EACxB,IAAID,kBAAkB,CAAC,CAAC,EACxB,IAAIH,eAAe,CAAC,CAAC,EACrB,IAAIC,gBAAgB,CAAC,CAAC,CAAC,EACvB,IAAIC,gBAAgB,CAAC,CAAC,CACvB;EACH;EAEA,MAAMY,GAAGA,CAACC,QAAgB,EAAEC,MAA4B,EAAgB;IACtE,OAAO,IAAI,CAAC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AAG,CAAC,CAAC,EACxE,CAAC,CACAE,IAAI,CAAC,GAAG,CAAC;MACZ,IAAIN,WAAW,EAAE;QACfrB,GAAG,IAAI,IAAIqB,WAAW,EAAE;MAC1B;IACF;IACA,OAAOrB,GAAG;EACZ;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ApiEndpoints","onboarding"],"sourceRoot":"../../../../src","sources":["data/network/apiEndpoints.ts"],"mappings":";;AAAA,OAAO,MAAMA,YAAY,GAAG;EAC1BC,UAAU,EAAE;
|
|
1
|
+
{"version":3,"names":["ApiEndpoints","onboarding","get_nonce"],"sourceRoot":"../../../../src","sources":["data/network/apiEndpoints.ts"],"mappings":";;AAAA,OAAO,MAAMA,YAAY,GAAG;EAC1BC,UAAU,EAAE,sBAAsB;EAClCC,SAAS,EAAE;AACb,CAAU","ignoreList":[]}
|
|
@@ -21,13 +21,17 @@ export class ApiRepository {
|
|
|
21
21
|
}
|
|
22
22
|
async *getData(endpoint, opts) {
|
|
23
23
|
const cacheStrategy = opts?.cacheStrategy ?? CacheStrategy.normal;
|
|
24
|
-
const cacheKey = (opts?.storageKeyPrefix ?? '') + endpoint + JSON.stringify(
|
|
24
|
+
const cacheKey = (opts?.storageKeyPrefix ?? '') + endpoint + JSON.stringify({
|
|
25
|
+
params: opts?.params ?? {},
|
|
26
|
+
method: opts?.method ?? 'GET',
|
|
27
|
+
body: opts?.body ?? null
|
|
28
|
+
});
|
|
25
29
|
if (cacheStrategy === CacheStrategy.cache) {
|
|
26
30
|
const cached = await storageGet(cacheKey);
|
|
27
31
|
if (cached !== null && cached !== undefined) {
|
|
28
32
|
yield apiSuccess(cached, 'Data fetched from cache', true);
|
|
29
33
|
} else {
|
|
30
|
-
const res = await this.fetchFromNetwork(endpoint, opts?.params, cacheKey);
|
|
34
|
+
const res = await this.fetchFromNetwork(endpoint, opts?.params, cacheKey, opts?.method, opts?.body);
|
|
31
35
|
yield res;
|
|
32
36
|
}
|
|
33
37
|
return;
|
|
@@ -42,7 +46,7 @@ export class ApiRepository {
|
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
44
48
|
if (cacheStrategy === CacheStrategy.network) {
|
|
45
|
-
const res = await this.fetchFromNetwork(endpoint, opts?.params, cacheKey);
|
|
49
|
+
const res = await this.fetchFromNetwork(endpoint, opts?.params, cacheKey, opts?.method, opts?.body);
|
|
46
50
|
yield res;
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
@@ -50,12 +54,22 @@ export class ApiRepository {
|
|
|
50
54
|
if (cached !== null && cached !== undefined) {
|
|
51
55
|
yield apiSuccess(cached, 'Data fetched from cache', true);
|
|
52
56
|
}
|
|
53
|
-
const res = await this.fetchFromNetwork(endpoint, opts?.params, cacheKey);
|
|
57
|
+
const res = await this.fetchFromNetwork(endpoint, opts?.params, cacheKey, opts?.method, opts?.body);
|
|
54
58
|
yield res;
|
|
55
59
|
}
|
|
56
|
-
async fetchFromNetwork(endpoint, params, cacheKey) {
|
|
60
|
+
async fetchFromNetwork(endpoint, params, cacheKey, method, body) {
|
|
57
61
|
try {
|
|
58
|
-
const
|
|
62
|
+
const m = (method || 'GET').toUpperCase();
|
|
63
|
+
let response;
|
|
64
|
+
if (m === 'POST') {
|
|
65
|
+
response = await this.apiClient.post(endpoint, body, params);
|
|
66
|
+
} else if (m === 'PUT') {
|
|
67
|
+
response = await this.apiClient.put(endpoint, body, params);
|
|
68
|
+
} else if (m === 'DELETE') {
|
|
69
|
+
response = await this.apiClient.delete(endpoint, body, params);
|
|
70
|
+
} else {
|
|
71
|
+
response = await this.apiClient.get(endpoint, params);
|
|
72
|
+
}
|
|
59
73
|
const data = response?.data ?? null;
|
|
60
74
|
const message = response?.message ?? response?.statusText ?? 'No message';
|
|
61
75
|
if (data !== null && cacheKey) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["apiError","apiSuccess","get","storageGet","save","storageSave","CacheStrategy","ApiRepository","constructor","apiClient","getData","endpoint","opts","cacheStrategy","normal","cacheKey","storageKeyPrefix","JSON","stringify","params","cache","cached","undefined","res","fetchFromNetwork","cacheOnly","network","response","data","message","statusText","e"],"sourceRoot":"../../../../src","sources":["data/network/apiRepository.ts"],"mappings":";;AAAA;;AAGA;;AAEA,SAASA,QAAQ,EAAEC,UAAU,QAAQ,0BAAuB;;AAE5D;AACA,SACEC,GAAG,IAAIC,UAAU,EACjBC,IAAI,IAAIC,WAAW,QACd,8BAA2B;AAElC,WAAYC,aAAa,0BAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA;AAOzB,OAAO,MAAMC,aAAa,CAAC;EAGzBC,WAAWA,CAACC,SAAoB,EAAE;IAChC,IAAI,CAACA,SAAS,GAAGA,SAAS;EAC5B;EAEA,OAAOC,OAAOA,CACZC,QAAgB,EAChBC,
|
|
1
|
+
{"version":3,"names":["apiError","apiSuccess","get","storageGet","save","storageSave","CacheStrategy","ApiRepository","constructor","apiClient","getData","endpoint","opts","cacheStrategy","normal","cacheKey","storageKeyPrefix","JSON","stringify","params","method","body","cache","cached","undefined","res","fetchFromNetwork","cacheOnly","network","m","toUpperCase","response","post","put","delete","data","message","statusText","e"],"sourceRoot":"../../../../src","sources":["data/network/apiRepository.ts"],"mappings":";;AAAA;;AAGA;;AAEA,SAASA,QAAQ,EAAEC,UAAU,QAAQ,0BAAuB;;AAE5D;AACA,SACEC,GAAG,IAAIC,UAAU,EACjBC,IAAI,IAAIC,WAAW,QACd,8BAA2B;AAElC,WAAYC,aAAa,0BAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA;AAOzB,OAAO,MAAMC,aAAa,CAAC;EAGzBC,WAAWA,CAACC,SAAoB,EAAE;IAChC,IAAI,CAACA,SAAS,GAAGA,SAAS;EAC5B;EAEA,OAAOC,OAAOA,CACZC,QAAgB,EAChBC,IAMC,EACqD;I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AAM,IAAI,CAACtB,SAAS,CAACP,GAAG,CAACS,QAAQ,EAAEQ,MAAM,CAAC;MACvD;MACA,MAAMgB,IAAI,GAAGJ,QAAQ,EAAEI,IAAI,IAAI,IAAI;MACnC,MAAMC,OAAO,GAAGL,QAAQ,EAAEK,OAAO,IAAIL,QAAQ,EAAEM,UAAU,IAAI,YAAY;MACzE,IAAIF,IAAI,KAAK,IAAI,IAAIpB,QAAQ,EAAE;QAC7B,MAAMV,WAAW,CAACU,QAAQ,EAAEoB,IAAI,CAAC;MACnC;MACA,OAAOlC,UAAU,CAAIkC,IAAI,EAAEC,OAAO,EAAE,KAAK,CAAC;IAC5C,CAAC,CAAC,OAAOE,CAAC,EAAE;MACV,OAAOtC,QAAQ,CAAC,2BAA2BsC,CAAC,EAAE,CAAC;IACjD;EACF;AACF","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ import { logger } from "../../utils/logger.js";
|
|
|
6
6
|
// Types / Models
|
|
7
7
|
|
|
8
8
|
import { onBoardingDataFromJson } from "../models/onboardingModel.js";
|
|
9
|
+
import { tokenResponseFromJson } from "../models/tokenModel.js";
|
|
9
10
|
|
|
10
11
|
// Storage
|
|
11
12
|
import { clearAll as storageClearAll } from "../storage/storageManager.js";
|
|
@@ -54,6 +55,41 @@ export class ApiService {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
58
|
+
async *getNonce({
|
|
59
|
+
cacheStrategy = CacheStrategy.network,
|
|
60
|
+
extUserId = '',
|
|
61
|
+
partnerCode = ''
|
|
62
|
+
}) {
|
|
63
|
+
const generator = this.repository.getData(ApiEndpoints.get_nonce, {
|
|
64
|
+
cacheStrategy,
|
|
65
|
+
method: 'POST',
|
|
66
|
+
body: {
|
|
67
|
+
extUserId,
|
|
68
|
+
partnerCode
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
for await (const response of generator) {
|
|
72
|
+
if (response.data) {
|
|
73
|
+
try {
|
|
74
|
+
yield tokenResponseFromJson(response.data);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
yield {
|
|
77
|
+
token: null,
|
|
78
|
+
statusCode: null,
|
|
79
|
+
error: `Failed to parse nonce: ${e}`,
|
|
80
|
+
messages: null
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
yield {
|
|
85
|
+
token: null,
|
|
86
|
+
statusCode: null,
|
|
87
|
+
error: response.message ?? 'Failed to load nonce',
|
|
88
|
+
messages: null
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
57
93
|
|
|
58
94
|
/**
|
|
59
95
|
* Clear all cached data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["logger","onBoardingDataFromJson","clearAll","storageClearAll","ApiEndpoints","ApiRepository","CacheStrategy","Environment","ApiClient","ApiService","constructor","environment","production","apiClient","repository","info","getOnBoarding","opts","generator","getData","onboarding","cacheStrategy","normal","response","status","data","parsedData","e","message","fromCache","clearCache"],"sourceRoot":"../../../../src","sources":["data/network/apiService.ts"],"mappings":";;AAAA;AACA,SAASA,MAAM,QAAQ,uBAAoB;;AAE3C;;AAEA,SAEEC,sBAAsB,QACjB,8BAA2B;;
|
|
1
|
+
{"version":3,"names":["logger","onBoardingDataFromJson","tokenResponseFromJson","clearAll","storageClearAll","ApiEndpoints","ApiRepository","CacheStrategy","Environment","ApiClient","ApiService","constructor","environment","production","apiClient","repository","info","getOnBoarding","opts","generator","getData","onboarding","cacheStrategy","normal","response","status","data","parsedData","e","message","fromCache","getNonce","network","extUserId","partnerCode","get_nonce","method","body","token","statusCode","error","messages","clearCache"],"sourceRoot":"../../../../src","sources":["data/network/apiService.ts"],"mappings":";;AAAA;AACA,SAASA,MAAM,QAAQ,uBAAoB;;AAE3C;;AAEA,SAEEC,sBAAsB,QACjB,8BAA2B;AAClC,SAEEC,qBAAqB,QAChB,yBAAsB;;AAE7B;AACA,SAASC,QAAQ,IAAIC,eAAe,QAAQ,8BAA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ACVI,SAAS,EAAEN,QAAQ,CAACM;QACtB,CAAC;MACH;IACF;EACF;EAEA,OAAOC,QAAQA,CAAC;IACdT,aAAa,GAAGf,aAAa,CAACyB,OAAO;IACrCC,SAAS,GAAG,EAAE;IACdC,WAAW,GAAG;EAChB,CAAC,EAAgD;IAC/C,MAAMf,SAAS,GAAG,IAAI,CAACJ,UAAU,CAACK,OAAO,CAAMf,YAAY,CAAC8B,SAAS,EAAE;MACrEb,aAAa;MACbc,MAAM,EAAE,MAAM;MACdC,IAAI,EAAE;QACJJ,SAAS;QACTC;MACF;IACF,CAAC,CAAC;IAEF,WAAW,MAAMV,QAAQ,IAAIL,SAAS,EAAE;MACtC,IAAIK,QAAQ,CAACE,IAAI,EAAE;QACjB,IAAI;UACF,MAAMxB,qBAAqB,CAACsB,QAAQ,CAACE,IAAI,CAAC;QAC5C,CAAC,CAAC,OAAOE,CAAC,EAAE;UACV,MAAM;YACJU,KAAK,EAAE,IAAI;YACXC,UAAU,EAAE,IAAI;YAChBC,KAAK,EAAE,0BAA0BZ,CAAC,EAAE;YACpCa,QAAQ,EAAE;UACZ,CAAC;QACH;MACF,CAAC,MAAM;QACL,MAAM;UACJH,KAAK,EAAE,IAAI;UACXC,UAAU,EAAE,IAAI;UAChBC,KAAK,EAAEhB,QAAQ,CAACK,OAAO,IAAI,sBAAsB;UACjDY,QAAQ,EAAE;QACZ,CAAC;MACH;IACF;EACF;;EAEA;AACF;AACA;EACE,MAAMC,UAAUA,CAAA,EAAkB;IAChC,MAAMtC,eAAe,CAAC,CAAC;IACvBJ,MAAM,CAACgB,IAAI,CAAC,eAAe,CAAC;EAC9B;AACF","ignoreList":[]}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// Utilities
|
|
6
6
|
import { logger } from "../../../utils/logger.js";
|
|
7
7
|
export class AuthInterceptor {
|
|
8
|
+
static xApiKey = 'x-api-key';
|
|
8
9
|
static oauthSubIdKey = 'oauthSubId';
|
|
9
10
|
static bodyMethods = new Set(['POST', 'PUT', 'PATCH']);
|
|
10
11
|
static excludedApis = new Set();
|
|
@@ -13,6 +14,7 @@ export class AuthInterceptor {
|
|
|
13
14
|
if (this.shouldExcludeApi(options.url)) {
|
|
14
15
|
return options;
|
|
15
16
|
}
|
|
17
|
+
this.addApiKeyHeader(options, AuthInterceptor.xApiKey, '3xqpYp6CPn899166YXbEB1YLJIhfdj08BbCdfQdg');
|
|
16
18
|
const userId = await this.getCurrentUserId();
|
|
17
19
|
if (userId) {
|
|
18
20
|
this.addAuthenticationData(options, userId);
|
|
@@ -45,6 +47,10 @@ export class AuthInterceptor {
|
|
|
45
47
|
options.body[AuthInterceptor.oauthSubIdKey] = userId;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
addApiKeyHeader(options, key, value) {
|
|
51
|
+
options.headers = options.headers || {};
|
|
52
|
+
options.headers[key] = value;
|
|
53
|
+
}
|
|
48
54
|
shouldExcludeApi(apiPath) {
|
|
49
55
|
if (!apiPath) return false;
|
|
50
56
|
for (const excludedPath of AuthInterceptor.excludedApis) {
|
|
@@ -56,9 +62,6 @@ export class AuthInterceptor {
|
|
|
56
62
|
}
|
|
57
63
|
async getCurrentUserId() {
|
|
58
64
|
try {
|
|
59
|
-
// Placeholder for Keycloak integration
|
|
60
|
-
// const currentUser = KeycloakWebViewManager.instance.currentUser;
|
|
61
|
-
// return currentUser?.email;
|
|
62
65
|
return null;
|
|
63
66
|
} catch (e) {
|
|
64
67
|
logger.error('Failed to get current user ID:', e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["logger","AuthInterceptor","oauthSubIdKey","bodyMethods","Set","excludedApis","onRequest","options","shouldExcludeApi","url","userId","getCurrentUserId","addAuthenticationData","e","error","method","toUpperCase","has","addToQueryParametersAndBody","addToQueryParameters","params","addToRequestBody","body","FormData","append","apiPath","excludedPath","includes"],"sourceRoot":"../../../../../src","sources":["data/network/interceptors/authInterceptor.ts"],"mappings":";;AAAA;;AAEA;AACA,SAASA,MAAM,QAAQ,0BAAuB;AAE9C,OAAO,MAAMC,eAAe,CAAC;EAC3B,OAAwBC,aAAa,GAAG,YAAY;EACpD,OAAwBC,WAAW,GAAG,IAAIC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;EACvE,OAAwBC,YAAY,GAAG,IAAID,GAAG,CAAS,CAAC;EAExD,MAAME,SAASA,CAACC,OAAY,EAAgB;IAC1C,IAAI;MACF,IAAI,IAAI,CAACC,gBAAgB,CAACD,OAAO,CAACE,GAAG,CAAC,EAAE;QACtC,OAAOF,OAAO;MAChB;MAEA,
|
|
1
|
+
{"version":3,"names":["logger","AuthInterceptor","xApiKey","oauthSubIdKey","bodyMethods","Set","excludedApis","onRequest","options","shouldExcludeApi","url","addApiKeyHeader","userId","getCurrentUserId","addAuthenticationData","e","error","method","toUpperCase","has","addToQueryParametersAndBody","addToQueryParameters","params","addToRequestBody","body","FormData","append","key","value","headers","apiPath","excludedPath","includes"],"sourceRoot":"../../../../../src","sources":["data/network/interceptors/authInterceptor.ts"],"mappings":";;AAAA;;AAEA;AACA,SAASA,MAAM,QAAQ,0BAAuB;AAE9C,OAAO,MAAMC,eAAe,CAAC;EAC3B,OAAwBC,OAAO,GAAG,WAAW;EAC7C,OAAwBC,aAAa,GAAG,YAAY;EACpD,OAAwBC,WAAW,GAAG,IAAIC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;EACvE,OAAwBC,YAAY,GAAG,IAAID,GAAG,CAAS,CAAC;EAExD,MAAME,SAASA,CAACC,OAAY,EAAgB;IAC1C,IAAI;MACF,IAAI,IAAI,CAACC,gBAAgB,CAACD,OAAO,CAACE,GAAG,CAAC,EAAE;QACtC,OAAOF,OAAO;MAChB;MAEA,IAAI,CAACG,eAAe,CAClBH,OAAO,EACPP,eAAe,CAACC,OAAO,EACvB,0CACF,CAAC;MAED,MAAMU,MAAM,GAAG,MAAM,IAAI,CAACC,gBAAgB,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IAAI,EAAE;MACpEhB,OAAO,CAACgB,IAAI,CAACvB,eAAe,CAACE,aAAa,CAAC,GAAGS,MAAM;IACtD;EACF;EAEQD,eAAeA,CAACH,OAAY,EAAEmB,GAAW,EAAEC,KAAa,EAAE;IAChEpB,OAAO,CAACqB,OAAO,GAAGrB,OAAO,CAACqB,OAAO,IAAI,CAAC,CAAC;IACvCrB,OAAO,CAACqB,OAAO,CAACF,GAAG,CAAC,GAAGC,KAAK;EAC9B;EAEQnB,gBAAgBA,CAACqB,OAAe,EAAW;IACjD,IAAI,CAACA,OAAO,EAAE,OAAO,KAAK;IAC1B,KAAK,MAAMC,YAAY,IAAI9B,eAAe,CAACK,YAAY,EAAE;MACvD,IAAIwB,OAAO,CAACE,QAAQ,CAACD,YAAY,CAAC,EAAE;QAClC,OAAO,IAAI;MACb;IACF;IACA,OAAO,KAAK;EACd;EAEA,MAAclB,gBAAgBA,CAAA,EAA2B;IACvD,IAAI;MACF,OAAO,IAAI;IACb,CAAC,CAAC,OAAOE,CAAC,EAAE;MACVf,MAAM,CAACgB,KAAK,CAAC,gCAAgC,EAAED,CAAC,CAAC;MACjD,OAAO,IAAI;IACb;EACF;AACF","ignoreList":[]}
|
|
@@ -9,12 +9,14 @@ import { getDeviceId } from "../../data/storage/deviceIdManager.js";
|
|
|
9
9
|
import { getSessionId } from "../../data/storage/sessionManager.js";
|
|
10
10
|
import { getLocationCoordinates } from "../../data/storage/locationManager.js";
|
|
11
11
|
import { getEncryptionKey, getPRefCode } from "../../data/storage/keysManager.js";
|
|
12
|
+
import { getBaseUrl } from "../../utils/config.js";
|
|
12
13
|
export function validateInput(input) {
|
|
13
14
|
const errors = [];
|
|
14
15
|
const auth = input.authType ?? 'PHONE';
|
|
15
16
|
if (!input.profile) errors.push('profile is mandatory');
|
|
16
17
|
if (!input.profile?.userId) errors.push('userId is mandatory');
|
|
17
18
|
if (!input.profile?.email) errors.push('email is mandatory');
|
|
19
|
+
if (!input.nonce) errors.push('nonce is mandatory');
|
|
18
20
|
const pv = input.profile?.pv;
|
|
19
21
|
const ev = input.profile?.ev;
|
|
20
22
|
if (typeof pv !== 'undefined' && pv !== '0' && pv !== '1') {
|
|
@@ -57,7 +59,8 @@ export async function generateUrl(input) {
|
|
|
57
59
|
screen: input.screen,
|
|
58
60
|
authType: input.authType ?? 'PHONE',
|
|
59
61
|
sessionId: sessionId ?? '',
|
|
60
|
-
deviceInfo
|
|
62
|
+
deviceInfo,
|
|
63
|
+
nonce: input.nonce
|
|
61
64
|
};
|
|
62
65
|
const validation = validateInput({
|
|
63
66
|
...normalized,
|
|
@@ -73,7 +76,8 @@ export async function generateUrl(input) {
|
|
|
73
76
|
profile: normalized.profile,
|
|
74
77
|
authType: normalized.authType,
|
|
75
78
|
deviceInfo: normalized.deviceInfo,
|
|
76
|
-
sessionId: normalized.sessionId
|
|
79
|
+
sessionId: normalized.sessionId,
|
|
80
|
+
nonce: normalized.nonce
|
|
77
81
|
};
|
|
78
82
|
const json = JSON.stringify(payload);
|
|
79
83
|
const key = await getEncryptionKey();
|
|
@@ -85,6 +89,6 @@ export async function generateUrl(input) {
|
|
|
85
89
|
if (!programCode || programCode === '-') {
|
|
86
90
|
throw new SDKError('pRefCode is mandatory. Initialize SDK with pRefCode.');
|
|
87
91
|
}
|
|
88
|
-
return
|
|
92
|
+
return `${getBaseUrl()}?pRefCode=${encodeURIComponent(programCode)}&qP=${encodeURIComponent(encoded)}`;
|
|
89
93
|
}
|
|
90
94
|
//# sourceMappingURL=urlGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SDKError","aesEncrypt","getDeviceId","getSessionId","getLocationCoordinates","getEncryptionKey","getPRefCode","validateInput","input","errors","auth","authType","profile","push","userId","email","pv","ev","username","phone","screenName","screen","name","attrs","attributes","length","ok","generateUrl","deviceId","storedLocation","sessionId","deviceInfo","dId","location","normalized","validation","join","payload","json","JSON","stringify","key","encoded","programCode","encodeURIComponent"],"sourceRoot":"../../../../src","sources":["services/url/urlGenerator.ts"],"mappings":";;AAAA;AACA,SAASA,QAAQ,QAAQ,uBAAoB;AAC7C,SAASC,UAAU,QAAQ,2BAAwB;;AAEnD;AACA,SAASC,WAAW,QAAQ,uCAAoC;AAChE,SAASC,YAAY,QAAQ,sCAAmC;AAChE,SAASC,sBAAsB,QAAQ,uCAAoC;AAC3E,SAASC,gBAAgB,EAAEC,WAAW,QAAQ,mCAAgC;
|
|
1
|
+
{"version":3,"names":["SDKError","aesEncrypt","getDeviceId","getSessionId","getLocationCoordinates","getEncryptionKey","getPRefCode","getBaseUrl","validateInput","input","errors","auth","authType","profile","push","userId","email","nonce","pv","ev","username","phone","screenName","screen","name","attrs","attributes","length","ok","generateUrl","deviceId","storedLocation","sessionId","deviceInfo","dId","location","normalized","validation","join","payload","json","JSON","stringify","key","encoded","programCode","encodeURIComponent"],"sourceRoot":"../../../../src","sources":["services/url/urlGenerator.ts"],"mappings":";;AAAA;AACA,SAASA,QAAQ,QAAQ,uBAAoB;AAC7C,SAASC,UAAU,QAAQ,2BAAwB;;AAEnD;AACA,SAASC,WAAW,QAAQ,uCAAoC;AAChE,SAASC,YAAY,QAAQ,sCAAmC;AAChE,SAASC,sBAAsB,QAAQ,uCAAoC;AAC3E,SAASC,gBAAgB,EAAEC,WAAW,QAAQ,mCAAgC;AAE9E,SAASC,UAAU,QAAQ,uBAAoB;AAgC/C,OAAO,SAASC,aAAaA,CAACC,KAAe,EAG3C;EACA,MAAMC,MAAgB,GAAG,EAAE;EAC3B,MAAMC,IAAI,GAAGF,KAAK,CAACG,QAAQ,IAAI,OAAO;EACtC,IAAI,CAACH,KAAK,CAACI,OAAO,EAAEH,MAAM,CAACI,IAAI,CAAC,sBAAsB,CAAC;EACvD,IAAI,CAACL,KAAK,CAACI,OAAO,EAAEE,MAAM,EAAEL,MAAM,CAACI,IAAI,CAAC,qBAAqB,CAAC;EAC9D,IAAI,CAACL,KAAK,CAACI,OAAO,EAAEG,KAAK,EAAEN,MAAM,CAACI,IA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CAACH,OAAO,CAAC;EACpC,MAAMI,GAAG,GAAG,MAAMtC,gBAAgB,CAAC,CAAC;EACpC,IAAI,CAACsC,GAAG,IAAIA,GAAG,KAAK,GAAG,EAAE;IACvB,MAAM,IAAI3C,QAAQ,CAChB,iEACF,CAAC;EACH;EACA,MAAM4C,OAAO,GAAG,MAAM3C,UAAU,CAACuC,IAAI,EAAEG,GAAG,CAAC;EAE3C,MAAME,WAAW,GAAG,MAAMvC,WAAW,CAAC,CAAC;EACvC,IAAI,CAACuC,WAAW,IAAIA,WAAW,KAAK,GAAG,EAAE;IACvC,MAAM,IAAI7C,QAAQ,CAAC,sDAAsD,CAAC;EAC5E;EACA,OAAO,GAAGO,UAAU,CAAC,CAAC,aAAauC,kBAAkB,CACnDD,WACF,CAAC,OAAOC,kBAAkB,CAACF,OAAO,CAAC,EAAE;AACvC","ignoreList":[]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import {
|
|
3
|
+
import { openMap } from "../navigation/openMap.js";
|
|
4
|
+
import { openDialPad } from "../navigation/dialPad.js";
|
|
5
|
+
import { openBrowser } from "../navigation/openBrowser.js";
|
|
6
|
+
import { closeCurrentScreenSafe } from "../navigation/goBackNavigation.js";
|
|
7
|
+
import { setSessionId } from "../../data/storage/sessionManager.js";
|
|
5
8
|
export function handleWebMessage(raw, postBack) {
|
|
6
9
|
let msg;
|
|
7
10
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["openMap","openDialPad","openBrowser","closeCurrentScreenSafe","setSessionId","handleWebMessage","raw","postBack","msg","JSON","parse","action","payload","reply","data","lat","lng","label","ok","number","url","sessionId","id","error","e","message","String"],"sourceRoot":"../../../../src","sources":["services/webview/messageHandler.ts"],"mappings":";;AAAA
|
|
1
|
+
{"version":3,"names":["openMap","openDialPad","openBrowser","closeCurrentScreenSafe","setSessionId","handleWebMessage","raw","postBack","msg","JSON","parse","action","payload","reply","data","lat","lng","label","ok","number","url","sessionId","id","error","e","message","String"],"sourceRoot":"../../../../src","sources":["services/webview/messageHandler.ts"],"mappings":";;AAAA,SAASA,OAAO,QAAQ,0BAAuB;AAC/C,SAASC,WAAW,QAAQ,0BAAuB;AACnD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SAASC,sBAAsB,QAAQ,mCAAgC;AACvE,SAASC,YAAY,QAAQ,sCAAmC;AAEhE,OAAO,SAASC,gBAAgBA,CAACC,GAAW,EAAEC,QAA8B,EAAE;EAC5E,IAAIC,GAAuC;EAC3C,IAAI;IACFA,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACJ,GAAG,CAAC;EACvB,CAAC,CAAC,MAAM;IACN;EACF;EACA,MAAMK,MAAM,GAAGH,GAAG,EAAEG,MAAM;EAC1B,MAAMC,OAAO,GAAGJ,GAAG,EAAEI,OAAO;EAE5B,MAAMC,KAAK,GAAIC,IAAS,IAAKP,QAAQ,GAAGO,IAAI,CAAC;EAE7C,CAAC,YAAY;IACX,IAAI;MACF,IAAIH,MAAM,KAAK,UAAU,EAAE;QACzB,MAAM;UAAEI,GAAG;UAAEC,GAAG;UAAEC;QAAM,CAAC,GAAGL,OAAO,IAAI,CAAC,CAAC;QACzC,MAAMZ,OAAO,CAACe,GAAG,EAAEC,GAAG,EAAEC,KAAK,CAAC;QAC9BJ,KAAK,CAAC;UAAEK,EAAE,EAAE,IAAI;UAAEP;QAAO,CAAC,CAAC;MAC7B,CAAC,MAAM,IAAIA,MAAM,KAAK,eAAe,EAAE;QACrC,MAAMV,WAAW,CAACW,OAAO,EAAEO,MAAM,CAAC;QAClCN,KAAK,CAAC;UAAEK,EAAE,EAAE,IAAI;UAAEP;QAAO,CAAC,CAAC;MAC7B,CAAC,MAAM,IAAIA,MAAM,KAAK,0BAA0B,EAAE;QAChD,MAAMT,WAAW,CAACU,OAAO,EAAEQ,GAAG,CAAC;QAC/BP,KAAK,CAAC;UAAEK,EAAE,EAAE,IAAI;UAAEP;QAAO,CAAC,CAAC;MAC7B,CAAC,MAAM,IAAIA,MAAM,KAAK,YAAY,EAAE;QAClC,MAAM;UAAEU;QAAU,CAAC,GAAGT,OAAO,IAAI,CAAC,CAAC;QACnC,MAAMU,EAAE,GAAG,MAAMlB,YAAY,CAACiB,SAAS,CAAC;QACxCR,KAAK,CAAC;UAAEK,EAAE,EAAE,IAAI;UAAEP,MAAM;UAAEU,SAAS,EAAEC;QAAG,CAAC,CAAC;MAC5C,CAAC,MAAM,IAAIX,MAAM,KAAK,aAAa,EAAE;QACnCR,sBAAsB,CAAC,CAAC;QACxB;MACF,CAAC,MAAM;QACLU,KAAK,CAAC;UAAEK,EAAE,EAAE,KAAK;UAAEK,KAAK,EAAE,gBAAgB;UAAEZ;QAAO,CAAC,CAAC;MACvD;IACF,CAAC,CAAC,OAAOa,CAAM,EAAE;MACfX,KAAK,CAAC;QAAEK,EAAE,EAAE,KAAK;QAAEK,KAAK,EAAEC,CAAC,EAAEC,OAAO,IAAIC,MAAM,CAACF,CAAC,CAAC;QAAEb;MAAO,CAAC,CAAC;IAC9D;EACF,CAAC,EAAE,CAAC;AACN","ignoreList":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// config.ts
|
|
4
|
+
|
|
5
|
+
// Default environment (build-time injected)
|
|
6
|
+
const injectedEnv = 'production';
|
|
7
|
+
const DEFAULT_ENVIRONMENT = injectedEnv === 'production' ? 'production' : 'sandbox';
|
|
8
|
+
const ENV_URLS = {
|
|
9
|
+
sandbox: 'https://testm.saversapp.com/',
|
|
10
|
+
production: 'https://m.saversapp.com/'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Current environment
|
|
14
|
+
let currentEnvironment = DEFAULT_ENVIRONMENT;
|
|
15
|
+
|
|
16
|
+
// Current base URL
|
|
17
|
+
let BASE_URL = ENV_URLS[currentEnvironment];
|
|
18
|
+
|
|
19
|
+
// Change environment
|
|
20
|
+
export const setEnvironment = env => {
|
|
21
|
+
currentEnvironment = env;
|
|
22
|
+
BASE_URL = ENV_URLS[env];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Get current environment
|
|
26
|
+
export const getEnvironment = () => {
|
|
27
|
+
return currentEnvironment;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Get base URL
|
|
31
|
+
export const getBaseUrl = () => {
|
|
32
|
+
return BASE_URL;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["injectedEnv","DEFAULT_ENVIRONMENT","ENV_URLS","sandbox","production","currentEnvironment","BASE_URL","setEnvironment","env","getEnvironment","getBaseUrl"],"sourceRoot":"../../../src","sources":["utils/config.ts"],"mappings":";;AAAA;;AAIA;AACA,MAAMA,WAAW,GAAG,YAAsB;AAC1C,MAAMC,mBAAgC,GACpCD,WAAW,KAAK,YAAY,GAAG,YAAY,GAAG,SAAS;AAEzD,MAAME,QAAqC,GAAG;EAC5CC,OAAO,EAAE,8BAA8B;EACvCC,UAAU,EAAE;AACd,CAAC;;AAED;AACA,IAAIC,kBAA+B,GAAGJ,mBAAmB;;AAEzD;AACA,IAAIK,QAAgB,GAAGJ,QAAQ,CAACG,kBAAkB,CAAC;;AAEnD;AACA,OAAO,MAAME,cAAc,GAAIC,GAAgB,IAAK;EAClDH,kBAAkB,GAAGG,GAAG;EACxBF,QAAQ,GAAGJ,QAAQ,CAACM,GAAG,CAAC;AAC1B,CAAC;;AAED;AACA,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAmB;EAC/C,OAAOJ,kBAAkB;AAC3B,CAAC;;AAED;AACA,OAAO,MAAMK,UAAU,GAAGA,CAAA,KAAc;EACtC,OAAOJ,QAAQ;AACjB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type TokenResponse = {
|
|
2
|
+
token?: string | null;
|
|
3
|
+
statusCode?: number | null;
|
|
4
|
+
error?: string | null;
|
|
5
|
+
messages?: string[] | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function tokenResponseFromJson(json: any): TokenResponse;
|
|
8
|
+
export declare const token: (d?: TokenResponse | null) => string | null;
|
|
9
|
+
export declare const hasToken: (d?: TokenResponse | null) => boolean;
|
|
10
|
+
export declare const isValid: (d?: TokenResponse | null) => boolean;
|
|
11
|
+
export declare const status: (d?: TokenResponse | null) => number | null;
|
|
12
|
+
export declare const error: (d?: TokenResponse | null) => string | null;
|
|
13
|
+
export declare const messages: (d?: TokenResponse | null) => string[] | null;
|
|
14
|
+
export declare const hasError: (d?: TokenResponse | null) => boolean;
|
|
15
|
+
//# sourceMappingURL=tokenModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenModel.d.ts","sourceRoot":"","sources":["../../../../../src/data/models/tokenModel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,aAAa,CAqB9D;AAED,eAAO,MAAM,KAAK,GAAI,IAAI,aAAa,GAAG,IAAI,KAAG,MAAM,GAAG,IACxC,CAAC;AACnB,eAAO,MAAM,QAAQ,GAAI,IAAI,aAAa,GAAG,IAAI,KAAG,OAChB,CAAC;AACrC,eAAO,MAAM,OAAO,GAAI,IAAI,aAAa,GAAG,IAAI,KAAG,OAAsB,CAAC;AAC1E,eAAO,MAAM,MAAM,GAAI,IAAI,aAAa,GAAG,IAAI,KAAG,MAAM,GAAG,IACpC,CAAC;AACxB,eAAO,MAAM,KAAK,GAAI,IAAI,aAAa,GAAG,IAAI,KAAG,MAAM,GAAG,IACxC,CAAC;AACnB,eAAO,MAAM,QAAQ,GAAI,IAAI,aAAa,GAAG,IAAI,KAAG,MAAM,EAAE,GAAG,IAC1C,CAAC;AACtB,eAAO,MAAM,QAAQ,GAAI,IAAI,aAAa,GAAG,IAAI,KAAG,OACqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiEndpoints.d.ts","sourceRoot":"","sources":["../../../../../src/data/network/apiEndpoints.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY
|
|
1
|
+
{"version":3,"file":"apiEndpoints.d.ts","sourceRoot":"","sources":["../../../../../src/data/network/apiEndpoints.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;CAGf,CAAC"}
|
|
@@ -13,6 +13,8 @@ export declare class ApiRepository {
|
|
|
13
13
|
cacheStrategy?: CacheStrategy;
|
|
14
14
|
params?: Record<string, any>;
|
|
15
15
|
storageKeyPrefix?: string;
|
|
16
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
17
|
+
body?: any;
|
|
16
18
|
}): AsyncGenerator<ApiResponse<T | null>, void, unknown>;
|
|
17
19
|
private fetchFromNetwork;
|
|
18
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiRepository.d.ts","sourceRoot":"","sources":["../../../../../src/data/network/apiRepository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AASzD,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,MAAM,WAAW;CAClB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;gBAE1B,SAAS,EAAE,SAAS;IAIzB,OAAO,CAAC,CAAC,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE;QACL,aAAa,CAAC,EAAE,aAAa,CAAC;QAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"apiRepository.d.ts","sourceRoot":"","sources":["../../../../../src/data/network/apiRepository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AASzD,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,MAAM,WAAW;CAClB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;gBAE1B,SAAS,EAAE,SAAS;IAIzB,OAAO,CAAC,CAAC,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE;QACL,aAAa,CAAC,EAAE,aAAa,CAAC;QAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;QAC3C,IAAI,CAAC,EAAE,GAAG,CAAC;KACZ,GACA,cAAc,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC;YAgEzC,gBAAgB;CA6B/B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ApiResponse } from '../models/apiResponse';
|
|
2
2
|
import { type OnBoardingData } from '../models/onboardingModel';
|
|
3
|
+
import { type TokenResponse } from '../models/tokenModel';
|
|
3
4
|
import { CacheStrategy } from './apiRepository';
|
|
4
5
|
import { Environment } from './apiClient';
|
|
5
6
|
export declare class ApiService {
|
|
@@ -11,6 +12,11 @@ export declare class ApiService {
|
|
|
11
12
|
getOnBoarding(opts?: {
|
|
12
13
|
cacheStrategy?: CacheStrategy;
|
|
13
14
|
}): AsyncGenerator<ApiResponse<OnBoardingData | null>, void, unknown>;
|
|
15
|
+
getNonce({ cacheStrategy, extUserId, partnerCode, }: {
|
|
16
|
+
cacheStrategy?: CacheStrategy | undefined;
|
|
17
|
+
extUserId?: string | undefined;
|
|
18
|
+
partnerCode?: string | undefined;
|
|
19
|
+
}): AsyncGenerator<TokenResponse, void, unknown>;
|
|
14
20
|
/**
|
|
15
21
|
* Clear all cached data
|
|
16
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../../../../src/data/network/apiService.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../../../../src/data/network/apiService.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EAAiB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAa,MAAM,aAAa,CAAC;AAErD,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAgB;gBAEtB,WAAW,GAAE,WAAoC;IAM7D;;OAEG;IACI,aAAa,CAAC,IAAI,CAAC,EAAE;QAC1B,aAAa,CAAC,EAAE,aAAa,CAAC;KAC/B,GAAG,cAAc,CAAC,WAAW,CAAC,cAAc,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC;IAgC9D,QAAQ,CAAC,EACd,aAAqC,EACrC,SAAc,EACd,WAAgB,GACjB;;;;KAAA,GAAG,cAAc,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC;IAiChD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAIlC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare class AuthInterceptor {
|
|
2
|
+
private static readonly xApiKey;
|
|
2
3
|
private static readonly oauthSubIdKey;
|
|
3
4
|
private static readonly bodyMethods;
|
|
4
5
|
private static readonly excludedApis;
|
|
@@ -7,6 +8,7 @@ export declare class AuthInterceptor {
|
|
|
7
8
|
private addToQueryParameters;
|
|
8
9
|
private addToQueryParametersAndBody;
|
|
9
10
|
private addToRequestBody;
|
|
11
|
+
private addApiKeyHeader;
|
|
10
12
|
private shouldExcludeApi;
|
|
11
13
|
private getCurrentUserId;
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authInterceptor.d.ts","sourceRoot":"","sources":["../../../../../../src/data/network/interceptors/authInterceptor.ts"],"names":[],"mappings":"AAKA,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAgB;IACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAqC;IACxE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAEnD,SAAS,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"authInterceptor.d.ts","sourceRoot":"","sources":["../../../../../../src/data/network/interceptors/authInterceptor.ts"],"names":[],"mappings":"AAKA,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAe;IAC9C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAgB;IACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAqC;IACxE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAEnD,SAAS,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAuB3C,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,2BAA2B;IAKnC,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,gBAAgB;YAUV,gBAAgB;CAQ/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlGenerator.d.ts","sourceRoot":"","sources":["../../../../../src/services/url/urlGenerator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"urlGenerator.d.ts","sourceRoot":"","sources":["../../../../../src/services/url/urlGenerator.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACvD,MAAM,MAAM,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,OAAO,GAAG;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;IACf,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AACF,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG;IAC9C,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAoCA;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAwDlE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageHandler.d.ts","sourceRoot":"","sources":["../../../../../src/services/webview/messageHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messageHandler.d.ts","sourceRoot":"","sources":["../../../../../src/services/webview/messageHandler.ts"],"names":[],"mappings":"AAMA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,QAsC3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/utils/config.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,YAAY,CAAC;AAmBnD,eAAO,MAAM,cAAc,GAAI,KAAK,WAAW,SAG9C,CAAC;AAGF,eAAO,MAAM,cAAc,QAAO,WAEjC,CAAC;AAGF,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savers_app/react-native-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Cross-platform React Native SDK exposing native features (maps, dial pad, browser), device ID/location and session utilities, a URL generator, and a WebView message bridge to trigger actions from web content.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"react-native": "./src/index.tsx",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"run:ios": "yarn workspace @saversapp/react-native-sdk-example ios",
|
|
38
38
|
"clean": "del-cli lib",
|
|
39
39
|
"prepare": "bob build",
|
|
40
|
+
"set:sandbox": "cross-env SDK_ENV=sandbox SDK_PACKAGE=@savers_app/react-native-sandbox-sdk node scripts/replace-config.js",
|
|
41
|
+
"set:production": "cross-env SDK_ENV=production SDK_PACKAGE=@savers_app/react-native-sdk node scripts/replace-config.js",
|
|
42
|
+
"prepare:sandbox": "yarn set:sandbox && yarn install && yarn prepare",
|
|
43
|
+
"prepare:production": "yarn set:production && yarn install && yarn prepare",
|
|
40
44
|
"typecheck": "tsc",
|
|
41
45
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
42
46
|
"test": "jest",
|
|
@@ -73,12 +77,13 @@
|
|
|
73
77
|
"@types/jest": "^29.5.14",
|
|
74
78
|
"@types/react": "^19.1.12",
|
|
75
79
|
"commitlint": "^19.8.1",
|
|
80
|
+
"cross-env": "^7.0.3",
|
|
76
81
|
"del-cli": "^6.0.0",
|
|
77
82
|
"eslint": "^9.35.0",
|
|
78
83
|
"eslint-config-prettier": "^10.1.8",
|
|
79
84
|
"eslint-plugin-prettier": "^5.5.4",
|
|
80
85
|
"jest": "^29.7.0",
|
|
81
|
-
"lefthook": "2.1.
|
|
86
|
+
"lefthook-darwin-arm64": "^2.1.3",
|
|
82
87
|
"prettier": "^3.8.1",
|
|
83
88
|
"react": "19.1.0",
|
|
84
89
|
"react-native": "0.81.5",
|
|
@@ -133,6 +138,7 @@
|
|
|
133
138
|
],
|
|
134
139
|
"moduleNameMapper": {
|
|
135
140
|
"^@savers_app/react-native-sdk$": "<rootDir>/src/index.tsx",
|
|
141
|
+
"^@savers_app/react-native-sandbox-sdk$": "<rootDir>/src/index.tsx",
|
|
136
142
|
"^react-native-device-info$": "<rootDir>/src/__mocks__/react-native-device-info.ts",
|
|
137
143
|
"^@react-native-community/geolocation$": "<rootDir>/src/__mocks__/@react-native-community__geolocation.ts",
|
|
138
144
|
"^@react-native-async-storage/async-storage$": "<rootDir>/src/__mocks__/@react-native-async-storage__async-storage.ts"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type TokenResponse = {
|
|
2
|
+
token?: string | null;
|
|
3
|
+
statusCode?: number | null;
|
|
4
|
+
error?: string | null;
|
|
5
|
+
messages?: string[] | null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function tokenResponseFromJson(json: any): TokenResponse {
|
|
9
|
+
const map = { ...(json as Record<string, any>) };
|
|
10
|
+
const token =
|
|
11
|
+
typeof map.token === 'string' && map.token.length > 0 ? map.token : null;
|
|
12
|
+
const statusCode =
|
|
13
|
+
typeof map.statusCode === 'number'
|
|
14
|
+
? map.statusCode
|
|
15
|
+
: typeof map.statusCode === 'string'
|
|
16
|
+
? Number(map.statusCode)
|
|
17
|
+
: null;
|
|
18
|
+
const error =
|
|
19
|
+
typeof map.error === 'string' && map.error.length > 0 ? map.error : null;
|
|
20
|
+
const messages = Array.isArray(map.message)
|
|
21
|
+
? (map.message.filter((m: any) => typeof m === 'string') as string[])
|
|
22
|
+
: null;
|
|
23
|
+
return {
|
|
24
|
+
token: token ?? null,
|
|
25
|
+
statusCode: statusCode ?? null,
|
|
26
|
+
error: error ?? null,
|
|
27
|
+
messages: messages && messages.length > 0 ? messages : null,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const token = (d?: TokenResponse | null): string | null =>
|
|
32
|
+
d?.token ?? null;
|
|
33
|
+
export const hasToken = (d?: TokenResponse | null): boolean =>
|
|
34
|
+
!!(d?.token && d.token.length > 0);
|
|
35
|
+
export const isValid = (d?: TokenResponse | null): boolean => hasToken(d);
|
|
36
|
+
export const status = (d?: TokenResponse | null): number | null =>
|
|
37
|
+
d?.statusCode ?? null;
|
|
38
|
+
export const error = (d?: TokenResponse | null): string | null =>
|
|
39
|
+
d?.error ?? null;
|
|
40
|
+
export const messages = (d?: TokenResponse | null): string[] | null =>
|
|
41
|
+
d?.messages ?? null;
|
|
42
|
+
export const hasError = (d?: TokenResponse | null): boolean =>
|
|
43
|
+
!!(d?.error || (d?.messages && d.messages.length > 0) || d?.statusCode);
|
|
@@ -17,8 +17,8 @@ export enum Environment {
|
|
|
17
17
|
|
|
18
18
|
export class ApiClient {
|
|
19
19
|
private static readonly baseUrls: Record<Environment, string> = {
|
|
20
|
-
[Environment.production]: 'https
|
|
21
|
-
[Environment.staging]: 'https
|
|
20
|
+
[Environment.production]: 'https://devapi.saversapp.com/clo/v1/',
|
|
21
|
+
[Environment.staging]: 'https://devapi.saversapp.com/clo/v1/',
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
private baseUrl: string;
|
|
@@ -31,13 +31,19 @@ export class ApiRepository {
|
|
|
31
31
|
cacheStrategy?: CacheStrategy;
|
|
32
32
|
params?: Record<string, any>;
|
|
33
33
|
storageKeyPrefix?: string;
|
|
34
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
35
|
+
body?: any;
|
|
34
36
|
}
|
|
35
37
|
): AsyncGenerator<ApiResponse<T | null>, void, unknown> {
|
|
36
38
|
const cacheStrategy = opts?.cacheStrategy ?? CacheStrategy.normal;
|
|
37
39
|
const cacheKey =
|
|
38
40
|
(opts?.storageKeyPrefix ?? '') +
|
|
39
41
|
endpoint +
|
|
40
|
-
JSON.stringify(
|
|
42
|
+
JSON.stringify({
|
|
43
|
+
params: opts?.params ?? {},
|
|
44
|
+
method: opts?.method ?? 'GET',
|
|
45
|
+
body: opts?.body ?? null,
|
|
46
|
+
});
|
|
41
47
|
|
|
42
48
|
if (cacheStrategy === CacheStrategy.cache) {
|
|
43
49
|
const cached = await storageGet(cacheKey);
|
|
@@ -47,7 +53,9 @@ export class ApiRepository {
|
|
|
47
53
|
const res = await this.fetchFromNetwork<T>(
|
|
48
54
|
endpoint,
|
|
49
55
|
opts?.params,
|
|
50
|
-
cacheKey
|
|
56
|
+
cacheKey,
|
|
57
|
+
opts?.method,
|
|
58
|
+
opts?.body
|
|
51
59
|
);
|
|
52
60
|
yield res;
|
|
53
61
|
}
|
|
@@ -68,7 +76,9 @@ export class ApiRepository {
|
|
|
68
76
|
const res = await this.fetchFromNetwork<T>(
|
|
69
77
|
endpoint,
|
|
70
78
|
opts?.params,
|
|
71
|
-
cacheKey
|
|
79
|
+
cacheKey,
|
|
80
|
+
opts?.method,
|
|
81
|
+
opts?.body
|
|
72
82
|
);
|
|
73
83
|
yield res;
|
|
74
84
|
return;
|
|
@@ -81,7 +91,9 @@ export class ApiRepository {
|
|
|
81
91
|
const res = await this.fetchFromNetwork<T>(
|
|
82
92
|
endpoint,
|
|
83
93
|
opts?.params,
|
|
84
|
-
cacheKey
|
|
94
|
+
cacheKey,
|
|
95
|
+
opts?.method,
|
|
96
|
+
opts?.body
|
|
85
97
|
);
|
|
86
98
|
yield res;
|
|
87
99
|
}
|
|
@@ -89,10 +101,22 @@ export class ApiRepository {
|
|
|
89
101
|
private async fetchFromNetwork<T>(
|
|
90
102
|
endpoint: string,
|
|
91
103
|
params?: Record<string, any>,
|
|
92
|
-
cacheKey?: string
|
|
104
|
+
cacheKey?: string,
|
|
105
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
|
106
|
+
body?: any
|
|
93
107
|
): Promise<ApiResponse<T | null>> {
|
|
94
108
|
try {
|
|
95
|
-
const
|
|
109
|
+
const m = (method || 'GET').toUpperCase();
|
|
110
|
+
let response: any;
|
|
111
|
+
if (m === 'POST') {
|
|
112
|
+
response = await this.apiClient.post(endpoint, body, params);
|
|
113
|
+
} else if (m === 'PUT') {
|
|
114
|
+
response = await this.apiClient.put(endpoint, body, params);
|
|
115
|
+
} else if (m === 'DELETE') {
|
|
116
|
+
response = await this.apiClient.delete(endpoint, body, params);
|
|
117
|
+
} else {
|
|
118
|
+
response = await this.apiClient.get(endpoint, params);
|
|
119
|
+
}
|
|
96
120
|
const data = response?.data ?? null;
|
|
97
121
|
const message = response?.message ?? response?.statusText ?? 'No message';
|
|
98
122
|
if (data !== null && cacheKey) {
|
|
@@ -7,6 +7,10 @@ import {
|
|
|
7
7
|
type OnBoardingData,
|
|
8
8
|
onBoardingDataFromJson,
|
|
9
9
|
} from '../models/onboardingModel';
|
|
10
|
+
import {
|
|
11
|
+
type TokenResponse,
|
|
12
|
+
tokenResponseFromJson,
|
|
13
|
+
} from '../models/tokenModel';
|
|
10
14
|
|
|
11
15
|
// Storage
|
|
12
16
|
import { clearAll as storageClearAll } from '../storage/storageManager';
|
|
@@ -62,6 +66,43 @@ export class ApiService {
|
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
async *getNonce({
|
|
70
|
+
cacheStrategy = CacheStrategy.network,
|
|
71
|
+
extUserId = '',
|
|
72
|
+
partnerCode = '',
|
|
73
|
+
}): AsyncGenerator<TokenResponse, void, unknown> {
|
|
74
|
+
const generator = this.repository.getData<any>(ApiEndpoints.get_nonce, {
|
|
75
|
+
cacheStrategy,
|
|
76
|
+
method: 'POST',
|
|
77
|
+
body: {
|
|
78
|
+
extUserId,
|
|
79
|
+
partnerCode,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
for await (const response of generator) {
|
|
84
|
+
if (response.data) {
|
|
85
|
+
try {
|
|
86
|
+
yield tokenResponseFromJson(response.data);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
yield {
|
|
89
|
+
token: null,
|
|
90
|
+
statusCode: null,
|
|
91
|
+
error: `Failed to parse nonce: ${e}`,
|
|
92
|
+
messages: null,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
yield {
|
|
97
|
+
token: null,
|
|
98
|
+
statusCode: null,
|
|
99
|
+
error: response.message ?? 'Failed to load nonce',
|
|
100
|
+
messages: null,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
65
106
|
/**
|
|
66
107
|
* Clear all cached data
|
|
67
108
|
*/
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { logger } from '../../../utils/logger';
|
|
5
5
|
|
|
6
6
|
export class AuthInterceptor {
|
|
7
|
+
private static readonly xApiKey = 'x-api-key';
|
|
7
8
|
private static readonly oauthSubIdKey = 'oauthSubId';
|
|
8
9
|
private static readonly bodyMethods = new Set(['POST', 'PUT', 'PATCH']);
|
|
9
10
|
private static readonly excludedApis = new Set<string>();
|
|
@@ -14,6 +15,12 @@ export class AuthInterceptor {
|
|
|
14
15
|
return options;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
this.addApiKeyHeader(
|
|
19
|
+
options,
|
|
20
|
+
AuthInterceptor.xApiKey,
|
|
21
|
+
'3xqpYp6CPn899166YXbEB1YLJIhfdj08BbCdfQdg'
|
|
22
|
+
);
|
|
23
|
+
|
|
17
24
|
const userId = await this.getCurrentUserId();
|
|
18
25
|
if (userId) {
|
|
19
26
|
this.addAuthenticationData(options, userId);
|
|
@@ -53,6 +60,11 @@ export class AuthInterceptor {
|
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
62
|
|
|
63
|
+
private addApiKeyHeader(options: any, key: string, value: string) {
|
|
64
|
+
options.headers = options.headers || {};
|
|
65
|
+
options.headers[key] = value;
|
|
66
|
+
}
|
|
67
|
+
|
|
56
68
|
private shouldExcludeApi(apiPath: string): boolean {
|
|
57
69
|
if (!apiPath) return false;
|
|
58
70
|
for (const excludedPath of AuthInterceptor.excludedApis) {
|
|
@@ -65,9 +77,6 @@ export class AuthInterceptor {
|
|
|
65
77
|
|
|
66
78
|
private async getCurrentUserId(): Promise<string | null> {
|
|
67
79
|
try {
|
|
68
|
-
// Placeholder for Keycloak integration
|
|
69
|
-
// const currentUser = KeycloakWebViewManager.instance.currentUser;
|
|
70
|
-
// return currentUser?.email;
|
|
71
80
|
return null;
|
|
72
81
|
} catch (e) {
|
|
73
82
|
logger.error('Failed to get current user ID:', e);
|
|
@@ -8,6 +8,8 @@ import { getSessionId } from '../../data/storage/sessionManager';
|
|
|
8
8
|
import { getLocationCoordinates } from '../../data/storage/locationManager';
|
|
9
9
|
import { getEncryptionKey, getPRefCode } from '../../data/storage/keysManager';
|
|
10
10
|
|
|
11
|
+
import { getBaseUrl } from '../../utils/config';
|
|
12
|
+
|
|
11
13
|
export type Attribute = { key: string; value: string };
|
|
12
14
|
export type Screen = { name?: string; attributes?: Attribute[] };
|
|
13
15
|
export type Profile = {
|
|
@@ -36,6 +38,7 @@ export type UrlInput = {
|
|
|
36
38
|
authType?: AuthType;
|
|
37
39
|
deviceInfo?: DeviceInfo;
|
|
38
40
|
sessionId?: string;
|
|
41
|
+
nonce: string;
|
|
39
42
|
};
|
|
40
43
|
export function validateInput(input: UrlInput): {
|
|
41
44
|
ok: boolean;
|
|
@@ -46,6 +49,8 @@ export function validateInput(input: UrlInput): {
|
|
|
46
49
|
if (!input.profile) errors.push('profile is mandatory');
|
|
47
50
|
if (!input.profile?.userId) errors.push('userId is mandatory');
|
|
48
51
|
if (!input.profile?.email) errors.push('email is mandatory');
|
|
52
|
+
if (!input.nonce) errors.push('nonce is mandatory');
|
|
53
|
+
|
|
49
54
|
const pv = input.profile?.pv;
|
|
50
55
|
const ev = input.profile?.ev;
|
|
51
56
|
if (typeof pv !== 'undefined' && pv !== '0' && pv !== '1') {
|
|
@@ -89,12 +94,14 @@ export async function generateUrl(input: UrlInput): Promise<string> {
|
|
|
89
94
|
const normalized: Required<Pick<UrlInput, 'profile'>> &
|
|
90
95
|
Pick<UrlInput, 'screen' | 'authType' | 'sessionId'> & {
|
|
91
96
|
deviceInfo: DeviceInfo;
|
|
97
|
+
nonce: string;
|
|
92
98
|
} = {
|
|
93
99
|
profile: input.profile,
|
|
94
100
|
screen: input.screen,
|
|
95
101
|
authType: input.authType ?? 'PHONE',
|
|
96
102
|
sessionId: sessionId ?? '',
|
|
97
103
|
deviceInfo,
|
|
104
|
+
nonce: input.nonce,
|
|
98
105
|
};
|
|
99
106
|
|
|
100
107
|
const validation = validateInput({
|
|
@@ -111,6 +118,7 @@ export async function generateUrl(input: UrlInput): Promise<string> {
|
|
|
111
118
|
authType: normalized.authType,
|
|
112
119
|
deviceInfo: normalized.deviceInfo,
|
|
113
120
|
sessionId: normalized.sessionId,
|
|
121
|
+
nonce: normalized.nonce,
|
|
114
122
|
};
|
|
115
123
|
|
|
116
124
|
const json = JSON.stringify(payload);
|
|
@@ -126,7 +134,7 @@ export async function generateUrl(input: UrlInput): Promise<string> {
|
|
|
126
134
|
if (!programCode || programCode === '-') {
|
|
127
135
|
throw new SDKError('pRefCode is mandatory. Initialize SDK with pRefCode.');
|
|
128
136
|
}
|
|
129
|
-
return
|
|
137
|
+
return `${getBaseUrl()}?pRefCode=${encodeURIComponent(
|
|
130
138
|
programCode
|
|
131
139
|
)}&qP=${encodeURIComponent(encoded)}`;
|
|
132
140
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
closeCurrentScreenSafe,
|
|
7
|
-
setSessionId,
|
|
8
|
-
} from '@savers_app/react-native-sdk';
|
|
1
|
+
import { openMap } from '../navigation/openMap';
|
|
2
|
+
import { openDialPad } from '../navigation/dialPad';
|
|
3
|
+
import { openBrowser } from '../navigation/openBrowser';
|
|
4
|
+
import { closeCurrentScreenSafe } from '../navigation/goBackNavigation';
|
|
5
|
+
import { setSessionId } from '../../data/storage/sessionManager';
|
|
9
6
|
|
|
10
7
|
export function handleWebMessage(raw: string, postBack?: (data: any) => void) {
|
|
11
8
|
let msg: { action?: string; payload?: any };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// config.ts
|
|
2
|
+
|
|
3
|
+
export type Environment = 'sandbox' | 'production';
|
|
4
|
+
|
|
5
|
+
// Default environment (build-time injected)
|
|
6
|
+
const injectedEnv = 'production' as string;
|
|
7
|
+
const DEFAULT_ENVIRONMENT: Environment =
|
|
8
|
+
injectedEnv === 'production' ? 'production' : 'sandbox';
|
|
9
|
+
|
|
10
|
+
const ENV_URLS: Record<Environment, string> = {
|
|
11
|
+
sandbox: 'https://testm.saversapp.com/',
|
|
12
|
+
production: 'https://m.saversapp.com/',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Current environment
|
|
16
|
+
let currentEnvironment: Environment = DEFAULT_ENVIRONMENT;
|
|
17
|
+
|
|
18
|
+
// Current base URL
|
|
19
|
+
let BASE_URL: string = ENV_URLS[currentEnvironment];
|
|
20
|
+
|
|
21
|
+
// Change environment
|
|
22
|
+
export const setEnvironment = (env: Environment) => {
|
|
23
|
+
currentEnvironment = env;
|
|
24
|
+
BASE_URL = ENV_URLS[env];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Get current environment
|
|
28
|
+
export const getEnvironment = (): Environment => {
|
|
29
|
+
return currentEnvironment;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Get base URL
|
|
33
|
+
export const getBaseUrl = (): string => {
|
|
34
|
+
return BASE_URL;
|
|
35
|
+
};
|