react-amwal-pay 0.1.2 → 0.1.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,84 +1,84 @@
1
- import { Alert } from 'react-native';
2
- import { Environment } from '../NativeReactAmwalPay';
3
- import SecureHashUtil from '../utils/SecureHashUtil';
4
-
5
- class NetworkClient {
6
- private static instance: NetworkClient;
7
-
8
- private constructor() {}
9
-
10
- static getInstance(): NetworkClient {
11
- if (!NetworkClient.instance) {
12
- NetworkClient.instance = new NetworkClient();
13
- }
14
- return NetworkClient.instance;
15
- }
16
-
17
- private getWebhookUrl(env: Environment): string {
18
- switch (env) {
19
- case Environment.SIT:
20
- return 'https://test.amwalpg.com:24443/';
21
- case Environment.UAT:
22
- return 'https://test.amwalpg.com:14443/';
23
- case Environment.PROD:
24
- return 'https://webhook.amwalpg.com/';
25
- default:
26
- return 'https://test.amwalpg.com:24443/';
27
- }
28
- }
29
-
30
- async fetchSessionToken(
31
- env: Environment,
32
- merchantId: string,
33
- customerId: string | null,
34
- secureHashValue: string
35
- ): Promise<string | null> {
36
- try {
37
- const webhookUrl = this.getWebhookUrl(env);
38
-
39
- const dataMap = {
40
- merchantId,
41
- customerId
42
- };
43
-
44
- const secureHash = SecureHashUtil.clearSecureHash(secureHashValue, dataMap);
45
-
46
- const response = await fetch(`${webhookUrl}Membership/GetSDKSessionToken`, {
47
- method: 'POST',
48
- headers: {
49
- 'Accept': 'text/plain',
50
- 'Accept-Language': 'en-US,en;q=0.9',
51
- 'Content-Type': 'application/json',
52
- },
53
- body: JSON.stringify({
54
- merchantId,
55
- secureHashValue: secureHash,
56
- customerId
57
- })
58
- });
59
-
60
- const responseData = await response.json();
61
-
62
- if (response.ok && responseData.success) {
63
- return responseData.data.sessionToken;
64
- } else {
65
- const errorMessage = responseData.errorList?.join(',') || 'Unknown error';
66
- this.showErrorDialog(errorMessage);
67
- return null;
68
- }
69
- } catch (error) {
70
- this.showErrorDialog('Something Went Wrong');
71
- return null;
72
- }
73
- }
74
-
75
- private showErrorDialog(message: string): void {
76
- Alert.alert(
77
- 'Error',
78
- message,
79
- [{ text: 'OK' }]
80
- );
81
- }
82
- }
83
-
1
+ import { Alert } from 'react-native';
2
+ import { Environment } from '../NativeReactAmwalPay';
3
+ import SecureHashUtil from '../utils/SecureHashUtil';
4
+
5
+ class NetworkClient {
6
+ private static instance: NetworkClient;
7
+
8
+ private constructor() {}
9
+
10
+ static getInstance(): NetworkClient {
11
+ if (!NetworkClient.instance) {
12
+ NetworkClient.instance = new NetworkClient();
13
+ }
14
+ return NetworkClient.instance;
15
+ }
16
+
17
+ private getWebhookUrl(env: Environment): string {
18
+ switch (env) {
19
+ case Environment.SIT:
20
+ return 'https://test.amwalpg.com:24443/';
21
+ case Environment.UAT:
22
+ return 'https://test.amwalpg.com:14443/';
23
+ case Environment.PROD:
24
+ return 'https://webhook.amwalpg.com/';
25
+ default:
26
+ return 'https://test.amwalpg.com:24443/';
27
+ }
28
+ }
29
+
30
+ async fetchSessionToken(
31
+ env: Environment,
32
+ merchantId: string,
33
+ customerId: string | null,
34
+ secureHashValue: string
35
+ ): Promise<string | null> {
36
+ try {
37
+ const webhookUrl = this.getWebhookUrl(env);
38
+
39
+ const dataMap = {
40
+ merchantId,
41
+ customerId
42
+ };
43
+
44
+ const secureHash = SecureHashUtil.clearSecureHash(secureHashValue, dataMap);
45
+
46
+ const response = await fetch(`${webhookUrl}Membership/GetSDKSessionToken`, {
47
+ method: 'POST',
48
+ headers: {
49
+ 'Accept': 'text/plain',
50
+ 'Accept-Language': 'en-US,en;q=0.9',
51
+ 'Content-Type': 'application/json',
52
+ },
53
+ body: JSON.stringify({
54
+ merchantId,
55
+ secureHashValue: secureHash,
56
+ customerId
57
+ })
58
+ });
59
+
60
+ const responseData = await response.json();
61
+
62
+ if (response.ok && responseData.success) {
63
+ return responseData.data.sessionToken;
64
+ } else {
65
+ const errorMessage = responseData.errorList?.join(',') || 'Unknown error';
66
+ this.showErrorDialog(errorMessage);
67
+ return null;
68
+ }
69
+ } catch (error) {
70
+ this.showErrorDialog('Something Went Wrong');
71
+ return null;
72
+ }
73
+ }
74
+
75
+ private showErrorDialog(message: string): void {
76
+ Alert.alert(
77
+ 'Error',
78
+ message,
79
+ [{ text: 'OK' }]
80
+ );
81
+ }
82
+ }
83
+
84
84
  export default NetworkClient;
@@ -1,45 +1,45 @@
1
- import HmacSHA256 from 'crypto-js/hmac-sha256';
2
- import Hex from 'crypto-js/enc-hex';
3
-
4
- type DataMap = { [key: string]: string | null };
5
-
6
- class SecureHashUtil {
7
- static clearSecureHash(secretKey: string, data: DataMap): string {
8
- delete data.secureHashValue;
9
- const concatenatedString = this.composeData(data);
10
- return this.generateSecureHash(concatenatedString, secretKey);
11
- }
12
-
13
- private static composeData(requestParameters: DataMap): string {
14
- return Object.entries(requestParameters)
15
- .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
16
- .filter(([_, value]) => value != null && value !== '')
17
- .map(([key, value]) => `${key}=${value}`)
18
- .join('&');
19
- }
20
-
21
- private static generateSecureHash(message: string, secretKey: string): string {
22
- try {
23
- // Convert hex string to byte array
24
- const keyBytes = secretKey.match(/.{2}/g)?.map(byte => parseInt(byte, 16));
25
-
26
- if (!keyBytes) {
27
- throw new Error('Invalid secret key format');
28
- }
29
-
30
- // Convert key bytes to hex string for crypto-js
31
- const keyHex = keyBytes.map(byte => byte.toString(16).padStart(2, '0')).join('');
32
-
33
- // Generate HMAC-SHA256
34
- const hash = HmacSHA256(message, Hex.parse(keyHex));
35
-
36
- // Convert to uppercase hex string
37
- return hash.toString(Hex).toUpperCase();
38
- } catch (e) {
39
- console.error('Error generating secure hash:', e);
40
- return '';
41
- }
42
- }
43
- }
44
-
1
+ import HmacSHA256 from 'crypto-js/hmac-sha256';
2
+ import Hex from 'crypto-js/enc-hex';
3
+
4
+ type DataMap = { [key: string]: string | null };
5
+
6
+ class SecureHashUtil {
7
+ static clearSecureHash(secretKey: string, data: DataMap): string {
8
+ delete data.secureHashValue;
9
+ const concatenatedString = this.composeData(data);
10
+ return this.generateSecureHash(concatenatedString, secretKey);
11
+ }
12
+
13
+ private static composeData(requestParameters: DataMap): string {
14
+ return Object.entries(requestParameters)
15
+ .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
16
+ .filter(([_, value]) => value != null && value !== '')
17
+ .map(([key, value]) => `${key}=${value}`)
18
+ .join('&');
19
+ }
20
+
21
+ private static generateSecureHash(message: string, secretKey: string): string {
22
+ try {
23
+ // Convert hex string to byte array
24
+ const keyBytes = secretKey.match(/.{2}/g)?.map(byte => parseInt(byte, 16));
25
+
26
+ if (!keyBytes) {
27
+ throw new Error('Invalid secret key format');
28
+ }
29
+
30
+ // Convert key bytes to hex string for crypto-js
31
+ const keyHex = keyBytes.map(byte => byte.toString(16).padStart(2, '0')).join('');
32
+
33
+ // Generate HMAC-SHA256
34
+ const hash = HmacSHA256(message, Hex.parse(keyHex));
35
+
36
+ // Convert to uppercase hex string
37
+ return hash.toString(Hex).toUpperCase();
38
+ } catch (e) {
39
+ console.error('Error generating secure hash:', e);
40
+ return '';
41
+ }
42
+ }
43
+ }
44
+
45
45
  export default SecureHashUtil;
package/lib/AmwalPay.d.ts DELETED
@@ -1,47 +0,0 @@
1
- export type Environment = 'SIT' | 'UAT' | 'PROD';
2
- export declare const Environment: {
3
- SIT: Environment;
4
- UAT: Environment;
5
- PROD: Environment;
6
- };
7
- export type Currency = 'OMR';
8
- export declare const Currency: {
9
- OMR: "OMR";
10
- };
11
- export type TransactionType = 'NFC' | 'CARD_WALLET' | 'APPLE_PAY';
12
- export declare const TransactionType: {
13
- NFC: TransactionType;
14
- CARD_WALLET: TransactionType;
15
- APPLE_PAY: TransactionType;
16
- };
17
- export interface AmwalPayConfig {
18
- environment: Environment;
19
- secureHash: string;
20
- currency: Currency;
21
- amount: string;
22
- merchantId: string;
23
- terminalId: string;
24
- locale: string;
25
- customerId: string | null;
26
- transactionType: TransactionType;
27
- sessionToken?: string;
28
- onResponse: (response: AmwalPayResponse) => void;
29
- onCustomerIdResponse: (customerId: string) => void;
30
- }
31
- export interface AmwalPayResponse {
32
- success: boolean;
33
- transactionId?: string;
34
- message?: string;
35
- error?: string;
36
- }
37
- declare class AmwalPay {
38
- private static instance;
39
- private eventEmitter;
40
- private constructor();
41
- static getInstance(): AmwalPay;
42
- private getSessionToken;
43
- start(amwalPayConfig: AmwalPayConfig): Promise<void>;
44
- private registerEventListeners;
45
- removeEventListeners(): void;
46
- }
47
- export default AmwalPay;
package/lib/AmwalPay.js DELETED
@@ -1,63 +0,0 @@
1
- import { NativeModules, NativeEventEmitter } from 'react-native';
2
- import NetworkClient from './services/NetworkClient';
3
- const { AmwalPaySDK } = NativeModules;
4
- export const Environment = {
5
- SIT: 'SIT',
6
- UAT: 'UAT',
7
- PROD: 'PROD'
8
- };
9
- export const Currency = {
10
- OMR: 'OMR'
11
- };
12
- export const TransactionType = {
13
- NFC: 'NFC',
14
- CARD_WALLET: 'CARD_WALLET',
15
- APPLE_PAY: 'APPLE_PAY'
16
- };
17
- class AmwalPay {
18
- constructor() {
19
- this.eventEmitter = new NativeEventEmitter(AmwalPaySDK);
20
- }
21
- static getInstance() {
22
- if (!AmwalPay.instance) {
23
- AmwalPay.instance = new AmwalPay();
24
- }
25
- return AmwalPay.instance;
26
- }
27
- async getSessionToken(config) {
28
- const { environment, merchantId, customerId, secureHash } = config;
29
- const sessionToken = await NetworkClient.getInstance().fetchSessionToken(environment, merchantId, customerId, secureHash);
30
- return sessionToken;
31
- }
32
- async start(amwalPayConfig) {
33
- const token = await this.getSessionToken(amwalPayConfig);
34
- console.log(token);
35
- if (token) {
36
- amwalPayConfig.sessionToken = token;
37
- try {
38
- // Initialize the AmwalPay SDK
39
- await AmwalPaySDK.initialize(amwalPayConfig);
40
- // Register event listeners
41
- this.registerEventListeners(amwalPayConfig);
42
- }
43
- catch (error) {
44
- throw new Error(`Failed to initialize AmwalPay SDK: ${error}`);
45
- }
46
- }
47
- }
48
- registerEventListeners(amwalPayConfig) {
49
- this.eventEmitter.addListener('AmwalPayEvent', async (event) => {
50
- if (event.type === 'onResponse') {
51
- amwalPayConfig.onResponse(event.data);
52
- }
53
- else if (event.type === 'onCustomerId') {
54
- amwalPayConfig.onCustomerIdResponse(event.data);
55
- }
56
- });
57
- }
58
- removeEventListeners() {
59
- this.eventEmitter.removeAllListeners('AmwalPayEvent');
60
- }
61
- }
62
- export default AmwalPay;
63
- //# sourceMappingURL=AmwalPay.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AmwalPay.js","sourceRoot":"","sources":["../src/AmwalPay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,aAAa,MAAM,0BAA0B,CAAC;AAGrD,MAAM,EAAE,WAAW,EAAE,GAAG,aAAa,CAAC;AAItC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,EAAE,KAAoB;IACzB,GAAG,EAAE,KAAoB;IACzB,IAAI,EAAE,MAAqB;CAC5B,CAAC;AAGF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,GAAG,EAAE,KAAiB;CACvB,CAAC;AAGF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,GAAG,EAAE,KAAwB;IAC7B,WAAW,EAAE,aAAgC;IAC7C,SAAS,EAAE,WAA8B;CAC1C,CAAC;AAwBF,MAAM,QAAQ;IAIZ;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC1D,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;YACtB,QAAQ,CAAC,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;SACpC;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,EAAE,WAAW,EAAE,UA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@@ -1,4 +0,0 @@
1
- import AmwalPay, { Environment, Currency, TransactionType, AmwalPayConfig, AmwalPayResponse } from './AmwalPay';
2
- export { AmwalPay, Environment, Currency, TransactionType };
3
- export type { AmwalPayConfig, AmwalPayResponse };
4
- export default AmwalPay;
package/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- import AmwalPay, { Environment, Currency, TransactionType, } from './AmwalPay';
2
- export { AmwalPay, Environment, Currency, TransactionType };
3
- export default AmwalPay;
4
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EACf,WAAW,EACX,QAAQ,EACR,eAAe,GAGhB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAC,CAAC;AAG1D,eAAe,QAAQ,CAAC"}
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const PaymentScreen: React.FC;
@@ -1,133 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { View, Text, TextInput, TouchableOpacity, StyleSheet, ScrollView, Alert, } from 'react-native';
3
- import { Picker } from '@react-native-picker/picker';
4
- import AmwalPay, { Environment, Currency, TransactionType, } from '../AmwalPay';
5
- export const PaymentScreen = () => {
6
- const [config, setConfig] = useState({
7
- environment: Environment.SIT,
8
- currency: Currency.OMR,
9
- transactionType: TransactionType.CARD_WALLET,
10
- locale: 'en',
11
- merchantId: '84131',
12
- terminalId: '811018',
13
- amount: '1',
14
- secureHash: '8570CEED656C8818E4A7CE04F22206358F272DAD5F0227D322B654675ABF8F83',
15
- onCustomerIdResponse(customerId) {
16
- console.log('Customer ID:', customerId);
17
- },
18
- onResponse(response) {
19
- console.log('Payment Response:', response);
20
- },
21
- });
22
- const handleInitializePayment = async () => {
23
- try {
24
- if (!isConfigValid()) {
25
- Alert.alert('Error', 'Please fill in all required fields');
26
- return;
27
- }
28
- const amwalPay = AmwalPay.getInstance();
29
- await amwalPay.start(config);
30
- }
31
- catch (e) {
32
- Alert.alert('Error', 'Error starting payment');
33
- console.log(e);
34
- }
35
- };
36
- const isConfigValid = () => {
37
- return Boolean(config.environment &&
38
- config.secureHash &&
39
- config.currency &&
40
- config.amount &&
41
- config.merchantId &&
42
- config.terminalId &&
43
- config.locale &&
44
- config.transactionType);
45
- };
46
- return (<ScrollView style={styles.container}>
47
- <Text style={styles.title}>Payment Configuration</Text>
48
-
49
- <Text style={styles.label}>Environment</Text>
50
- <View style={styles.pickerContainer}>
51
- <Picker selectedValue={config.environment} onValueChange={value => setConfig({ ...config, environment: value })}>
52
- {Object.values(Environment).map(env => (<Picker.Item key={env} label={env} value={env}/>))}
53
- </Picker>
54
- </View>
55
-
56
- <Text style={styles.label}>Secure Hash</Text>
57
- <TextInput style={styles.input} value={config.secureHash} onChangeText={value => setConfig({ ...config, secureHash: value })} placeholder="Enter Secure Hash"/>
58
-
59
- <Text style={styles.label}>Currency</Text>
60
- <View style={styles.pickerContainer}>
61
- <Picker selectedValue={config.currency} onValueChange={value => setConfig({ ...config, currency: value })}>
62
- {Object.values(Currency).map(curr => (<Picker.Item key={curr} label={curr} value={curr}/>))}
63
- </Picker>
64
- </View>
65
- <Text style={styles.label}>Amount</Text>
66
- <TextInput style={styles.input} value={config.amount} onChangeText={value => setConfig({ ...config, amount: value })} placeholder="Enter amount" keyboardType="decimal-pad"/>
67
-
68
- <Text style={styles.label}>Merchant ID</Text>
69
- <TextInput style={styles.input} value={config.merchantId} onChangeText={value => setConfig({ ...config, merchantId: value })} placeholder="Enter merchant ID"/>
70
-
71
- <Text style={styles.label}>Terminal ID</Text>
72
- <TextInput style={styles.input} value={config.terminalId} onChangeText={value => setConfig({ ...config, terminalId: value })} placeholder="Enter terminal ID"/>
73
-
74
- <Text style={styles.label}>Transaction Type</Text>
75
- <View style={styles.pickerContainer}>
76
- <Picker selectedValue={config.transactionType} onValueChange={value => setConfig({ ...config, transactionType: value })}>
77
- {Object.values(TransactionType).map(type => (<Picker.Item key={type} label={type} value={type}/>))}
78
- </Picker>
79
- </View>
80
-
81
- <TouchableOpacity style={styles.button} onPress={handleInitializePayment}>
82
- <Text style={styles.buttonText}>Start Payment</Text>
83
- </TouchableOpacity>
84
- </ScrollView>);
85
- };
86
- const styles = StyleSheet.create({
87
- container: {
88
- flex: 1,
89
- padding: 16,
90
- backgroundColor: '#fff',
91
- },
92
- title: {
93
- fontSize: 24,
94
- fontWeight: 'bold',
95
- marginBottom: 24,
96
- textAlign: 'center',
97
- },
98
- label: {
99
- fontSize: 16,
100
- marginBottom: 8,
101
- color: '#333',
102
- },
103
- input: {
104
- borderWidth: 1,
105
- borderColor: '#ddd',
106
- borderRadius: 8,
107
- padding: 12,
108
- marginBottom: 16,
109
- fontSize: 16,
110
- },
111
- button: {
112
- backgroundColor: '#007AFF',
113
- padding: 16,
114
- borderRadius: 8,
115
- marginTop: 24,
116
- marginBottom: 32,
117
- },
118
- buttonText: {
119
- color: '#fff',
120
- fontSize: 18,
121
- fontWeight: 'bold',
122
- textAlign: 'center',
123
- },
124
- pickerContainer: {
125
- borderWidth: 1,
126
- borderColor: '#ccc',
127
- borderRadius: 8,
128
- overflow: 'hidden',
129
- width: '100%',
130
- maxWidth: 300, // Optional: Limit max width
131
- },
132
- });
133
- //# sourceMappingURL=PaymentScreen.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PaymentScreen.js","sourceRoot":"","sources":["../../src/screens/PaymentScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,KAAK,GAEN,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,MAAM,EAAC,MAAM,6BAA6B,CAAC;AACnD,OAAO,QAAQ,EAAE,EACf,WAA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QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,GAAG,EAAE,4BAA4B;KAC5C;CACF,CAAC,CAAC"}
@@ -1,10 +0,0 @@
1
- import { Environment } from '../AmwalPay';
2
- declare class NetworkClient {
3
- private static instance;
4
- private constructor();
5
- static getInstance(): NetworkClient;
6
- private getWebhookUrl;
7
- fetchSessionToken(env: Environment, merchantId: string, customerId: string | null, secureHashValue: string): Promise<string | null>;
8
- private showErrorDialog;
9
- }
10
- export default NetworkClient;
@@ -1,65 +0,0 @@
1
- import { Alert } from 'react-native';
2
- import { Environment } from '../AmwalPay';
3
- import SecureHashUtil from '../utils/SecureHashUtil';
4
- class NetworkClient {
5
- constructor() { }
6
- static getInstance() {
7
- if (!NetworkClient.instance) {
8
- NetworkClient.instance = new NetworkClient();
9
- }
10
- return NetworkClient.instance;
11
- }
12
- getWebhookUrl(env) {
13
- switch (env) {
14
- case Environment.SIT:
15
- return 'https://test.amwalpg.com:24443/';
16
- case Environment.UAT:
17
- return 'https://test.amwalpg.com:14443/';
18
- case Environment.PROD:
19
- return 'https://webhook.amwalpg.com/';
20
- default:
21
- return 'https://test.amwalpg.com:24443/';
22
- }
23
- }
24
- async fetchSessionToken(env, merchantId, customerId, secureHashValue) {
25
- try {
26
- const webhookUrl = this.getWebhookUrl(env);
27
- const dataMap = {
28
- merchantId,
29
- customerId
30
- };
31
- const secureHash = SecureHashUtil.clearSecureHash(secureHashValue, dataMap);
32
- const response = await fetch(`${webhookUrl}Membership/GetSDKSessionToken`, {
33
- method: 'POST',
34
- headers: {
35
- 'Accept': 'text/plain',
36
- 'Accept-Language': 'en-US,en;q=0.9',
37
- 'Content-Type': 'application/json',
38
- },
39
- body: JSON.stringify({
40
- merchantId,
41
- secureHashValue: secureHash,
42
- customerId
43
- })
44
- });
45
- const responseData = await response.json();
46
- if (response.ok && responseData.success) {
47
- return responseData.data.sessionToken;
48
- }
49
- else {
50
- const errorMessage = responseData.errorList?.join(',') || 'Unknown error';
51
- this.showErrorDialog(errorMessage);
52
- return null;
53
- }
54
- }
55
- catch (error) {
56
- this.showErrorDialog('Something Went Wrong');
57
- return null;
58
- }
59
- }
60
- showErrorDialog(message) {
61
- Alert.alert('Error', message, [{ text: 'OK' }]);
62
- }
63
- }
64
- export default NetworkClient;
65
- //# sourceMappingURL=NetworkClient.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NetworkClient.js","sourceRoot":"","sources":["../../src/services/NetworkClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,MAAM,aAAa;IAGjB,gBAAuB,CAAC;IAExB,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC3B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;SAC9C;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEO,aAAa,CAAC,GAAgB;QACpC,QAAQ,GAAG,EAAE;YACX,KAAK,WAAW,CAAC,GAAG;gBAClB,OAAO,iCAAiC,CAAC;YAC3C,KAAK,WAAW,CAAC,GAAG;gBAClB,OAAO,iCAAiC,CAAC;YAC3C,KAAK,WAAW,CAAC,IAAI;gBACnB,OAAO,8BAA8B,CAAC;YACxC;gBACE,OAAO,iCAAiC,CAAC;SAC5C;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,GAAgB,EAChB,UAAkB,EAClB,UAAyB,EACzB,eAAuB;QAEvB,IAAI;YACF,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YAE3C,MAAM,OAAO,GAAG;gBACd,UAAU;gBACV,UAAU;aACX,CAAC;YAEF,MAAM,UAAU,GAAG,cAAc,CAAC,eAAe,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YAE5E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,UAAU,+BAA+B,EAAE;gBACzE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,QAAQ,EAAE,YAAY;oBACtB,iBAAiB,EAAE,gBAAgB;oBACnC,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,UAAU;oBACV,eAAe,EAAE,UAAU;oBAC3B,UAAU;iBACX,CAAC;aACH,CAAC,CAAC;YAEH,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAE3C,IAAI,QAAQ,CAAC,EAAE,IAAI,YAAY,CAAC,OAAO,EAAE;gBACvC,OAAO,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;aACvC;iBAAM;gBACL,MAAM,YAAY,GAAG,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC;gBAC1E,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;gBACnC,OAAO,IAAI,CAAC;aACb;SACF;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC;YAC7C,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAEO,eAAe,CAAC,OAAe;QACrC,KAAK,CAAC,KAAK,CACT,OAAO,EACP,OAAO,EACP,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CACjB,CAAC;IACJ,CAAC;CACF;AAED,eAAe,aAAa,CAAC"}
@@ -1,9 +0,0 @@
1
- type DataMap = {
2
- [key: string]: string | null;
3
- };
4
- declare class SecureHashUtil {
5
- static clearSecureHash(secretKey: string, data: DataMap): string;
6
- private static composeData;
7
- private static generateSecureHash;
8
- }
9
- export default SecureHashUtil;