@glomopay/react-native-sdk 2.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/MIGRATION.md +50 -0
  3. package/README.md +348 -316
  4. package/lib/config/base.d.ts +17 -11
  5. package/lib/config/base.d.ts.map +1 -1
  6. package/lib/config/base.js +19 -7
  7. package/lib/config/segment.js +3 -3
  8. package/lib/glomo-checkout.d.ts +8 -0
  9. package/lib/glomo-checkout.d.ts.map +1 -0
  10. package/lib/glomo-checkout.js +106 -0
  11. package/lib/glomo-lrs-checkout.js +9 -9
  12. package/lib/glomo-standard-checkout.d.ts +25 -0
  13. package/lib/glomo-standard-checkout.d.ts.map +1 -0
  14. package/lib/glomo-standard-checkout.js +229 -0
  15. package/lib/glomo-subscriptions-checkout.d.ts +8 -0
  16. package/lib/glomo-subscriptions-checkout.d.ts.map +1 -0
  17. package/lib/glomo-subscriptions-checkout.js +85 -0
  18. package/lib/index.d.ts +5 -4
  19. package/lib/index.d.ts.map +1 -1
  20. package/lib/index.js +7 -5
  21. package/lib/injections/index.d.ts +1 -0
  22. package/lib/injections/index.d.ts.map +1 -1
  23. package/lib/injections/index.js +2 -0
  24. package/lib/injections/webview-flow.injection.d.ts.map +1 -1
  25. package/lib/injections/webview-flow.injection.js +106 -69
  26. package/lib/injections/webview-main.injection.d.ts.map +1 -1
  27. package/lib/injections/webview-main.injection.js +112 -77
  28. package/lib/injections/webview-standard.injection.d.ts +3 -0
  29. package/lib/injections/webview-standard.injection.d.ts.map +1 -0
  30. package/lib/injections/webview-standard.injection.js +214 -0
  31. package/lib/services/order-type-fetcher.d.ts +28 -0
  32. package/lib/services/order-type-fetcher.d.ts.map +1 -0
  33. package/lib/services/order-type-fetcher.js +99 -0
  34. package/lib/types/checkout.d.ts +65 -0
  35. package/lib/types/checkout.d.ts.map +1 -0
  36. package/lib/types/checkout.js +3 -0
  37. package/lib/types/standard-checkout.d.ts +40 -0
  38. package/lib/types/standard-checkout.d.ts.map +1 -0
  39. package/lib/types/standard-checkout.js +3 -0
  40. package/lib/types/subscriptions-checkout.d.ts +29 -0
  41. package/lib/types/subscriptions-checkout.d.ts.map +1 -0
  42. package/lib/types/subscriptions-checkout.js +3 -0
  43. package/lib/use-glomo-checkout.d.ts +54 -0
  44. package/lib/use-glomo-checkout.d.ts.map +1 -0
  45. package/lib/use-glomo-checkout.js +261 -0
  46. package/lib/use-lrs-checkout.d.ts +9 -4
  47. package/lib/use-lrs-checkout.d.ts.map +1 -1
  48. package/lib/use-lrs-checkout.js +76 -93
  49. package/lib/use-standard-checkout.d.ts +74 -0
  50. package/lib/use-standard-checkout.d.ts.map +1 -0
  51. package/lib/use-standard-checkout.js +849 -0
  52. package/lib/utils/analytics.d.ts +188 -2
  53. package/lib/utils/analytics.d.ts.map +1 -1
  54. package/lib/utils/analytics.js +636 -22
  55. package/lib/utils/device-compliance.d.ts.map +1 -1
  56. package/lib/utils/device-compliance.js +3 -4
  57. package/lib/utils/validation.d.ts.map +1 -1
  58. package/lib/utils/validation.js +7 -6
  59. package/package.json +17 -5
  60. package/src/config/base.ts +36 -17
  61. package/src/config/segment.ts +3 -3
  62. package/src/glomo-checkout.tsx +147 -0
  63. package/src/glomo-lrs-checkout.tsx +9 -9
  64. package/src/glomo-standard-checkout.tsx +353 -0
  65. package/src/glomo-subscriptions-checkout.tsx +83 -0
  66. package/src/index.ts +13 -7
  67. package/src/injections/index.ts +2 -0
  68. package/src/injections/webview-flow.injection.ts +106 -69
  69. package/src/injections/webview-main.injection.ts +112 -77
  70. package/src/injections/webview-standard.injection.ts +211 -0
  71. package/src/services/order-type-fetcher.ts +86 -0
  72. package/src/types/checkout.ts +72 -0
  73. package/src/types/standard-checkout.ts +49 -0
  74. package/src/types/subscriptions-checkout.ts +31 -0
  75. package/src/use-glomo-checkout.tsx +369 -0
  76. package/src/use-lrs-checkout.tsx +91 -111
  77. package/src/use-standard-checkout.tsx +1203 -0
  78. package/src/utils/analytics.ts +908 -34
  79. package/src/utils/device-compliance.ts +3 -4
  80. package/src/utils/validation.ts +7 -8
@@ -4,182 +4,217 @@ exports.injectedScript = void 0;
4
4
  /** Injection JavaScript for the Primary WebView */
5
5
  exports.injectedScript = `
6
6
  (function() {
7
- // Overriding console methods
7
+ // Log prefix for all messages originating from the main WebView
8
+ const LOG_PREFIX = 'MAIN_WEBVIEW: ';
9
+
10
+ /**
11
+ * Formats an array of arguments into a single prefixed string for posting back to React Native.
12
+ * Objects are JSON-stringified; primitives are coerced to strings.
13
+ */
14
+ function formatMessage(args) {
15
+ return args.map(function(arg) {
16
+ if (typeof arg === 'object') {
17
+ try {
18
+ return LOG_PREFIX + JSON.stringify(arg, null, 2);
19
+ } catch (error) {
20
+ return LOG_PREFIX + '[unserializable object]';
21
+ }
22
+ }
23
+ return LOG_PREFIX + String(arg);
24
+ }).join(' ');
25
+ }
26
+
27
+ // Saving original console methods before overriding (must be declared before safePostMessage references them)
8
28
  const originalLog = console.log;
9
29
  const originalWarn = console.warn;
10
30
  const originalError = console.error;
11
31
  const originalInfo = console.info;
12
-
32
+
33
+ /**
34
+ * Safely posts a message to ReactNativeWebView with a guard check.
35
+ * Prevents crashes if the WebView bridge is not yet ready or has been torn down.
36
+ */
37
+ function safePostMessage(payload) {
38
+ try {
39
+ if (window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === 'function') {
40
+ window.ReactNativeWebView.postMessage(JSON.stringify(payload));
41
+ }
42
+ } catch (error) {
43
+ originalError && originalError.call(console, LOG_PREFIX + 'Failed to post message to ReactNativeWebView', error);
44
+ }
45
+ }
46
+
47
+ // Overriding console methods to forward logs back to React Native
13
48
  console.log = function(...args) {
14
49
  originalLog.apply(console, args);
15
- window.ReactNativeWebView.postMessage(JSON.stringify({
50
+ safePostMessage({
16
51
  type: 'console',
17
52
  level: 'log',
18
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
19
- }));
53
+ message: formatMessage(args)
54
+ });
20
55
  };
21
-
56
+
22
57
  console.warn = function(...args) {
23
58
  originalWarn.apply(console, args);
24
- window.ReactNativeWebView.postMessage(JSON.stringify({
59
+ safePostMessage({
25
60
  type: 'console',
26
61
  level: 'warn',
27
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
28
- }));
62
+ message: formatMessage(args)
63
+ });
29
64
  };
30
-
65
+
31
66
  console.error = function(...args) {
32
67
  originalError.apply(console, args);
33
- window.ReactNativeWebView.postMessage(JSON.stringify({
68
+ safePostMessage({
34
69
  type: 'console',
35
70
  level: 'error',
36
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
37
- }));
71
+ message: formatMessage(args)
72
+ });
38
73
  };
39
-
74
+
40
75
  console.info = function(...args) {
41
76
  originalInfo.apply(console, args);
42
- window.ReactNativeWebView.postMessage(JSON.stringify({
77
+ safePostMessage({
43
78
  type: 'console',
44
79
  level: 'info',
45
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
46
- }));
80
+ message: formatMessage(args)
81
+ });
47
82
  };
48
-
49
- // Intercepting fetch requests
83
+
84
+ // Intercepting fetch requests to log network activity
50
85
  const originalFetch = window.fetch;
51
86
  window.fetch = function(...args) {
52
87
  const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || 'Unknown URL';
53
- window.ReactNativeWebView.postMessage(JSON.stringify({
88
+ safePostMessage({
54
89
  type: 'console',
55
90
  level: 'network',
56
- message: 'FETCH REQUEST: ' + url
57
- }));
58
-
91
+ message: LOG_PREFIX + 'FETCH REQUEST: ' + url
92
+ });
93
+
59
94
  return originalFetch.apply(this, args)
60
95
  .then(response => {
61
- window.ReactNativeWebView.postMessage(JSON.stringify({
62
- type: 'console',
63
- level: 'network',
64
- message: 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
65
- }));
96
+ safePostMessage({
97
+ type: 'console',
98
+ level: 'network',
99
+ message: LOG_PREFIX + 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
100
+ });
66
101
  return response;
67
102
  })
68
103
  .catch(error => {
69
- window.ReactNativeWebView.postMessage(JSON.stringify({
104
+ safePostMessage({
70
105
  type: 'console',
71
106
  level: 'error',
72
- message: 'FETCH ERROR: ' + url + ' - ' + error.message
73
- }));
107
+ message: LOG_PREFIX + 'FETCH ERROR: ' + url + ' - ' + error.message
108
+ });
74
109
  throw error;
75
110
  });
76
111
  };
77
-
78
- // Intercepting XMLHttpRequest
112
+
113
+ // Intercepting XMLHttpRequest to log network activity
79
114
  const originalOpen = XMLHttpRequest.prototype.open;
80
115
  const originalSend = XMLHttpRequest.prototype.send;
81
-
116
+
82
117
  XMLHttpRequest.prototype.open = function(method, url) {
83
118
  this._url = url;
84
119
  this._method = method;
85
120
  return originalOpen.apply(this, arguments);
86
121
  };
87
-
122
+
88
123
  XMLHttpRequest.prototype.send = function() {
89
- window.ReactNativeWebView.postMessage(JSON.stringify({
124
+ safePostMessage({
90
125
  type: 'console',
91
126
  level: 'network',
92
- message: 'XHR REQUEST: ' + this._method + ' ' + this._url
93
- }));
94
-
127
+ message: LOG_PREFIX + 'XHR REQUEST: ' + this._method + ' ' + this._url
128
+ });
129
+
95
130
  this.addEventListener('load', function() {
96
131
  try {
97
- window.ReactNativeWebView.postMessage(JSON.stringify({
98
- type: 'console',
99
- level: 'network',
100
- message: 'XHR RESPONSE LOAD: ' + this._url + ' - Status: ' + this.status
101
- }));
132
+ safePostMessage({
133
+ type: 'console',
134
+ level: 'network',
135
+ message: LOG_PREFIX + 'XHR RESPONSE LOAD: ' + this._url + ' - Status: ' + this.status
136
+ });
102
137
  } catch (e) {
103
- window.ReactNativeWebView.postMessage(JSON.stringify({
138
+ safePostMessage({
104
139
  type: 'console',
105
140
  level: 'network',
106
- message: 'XHR RESPONSE ERROR: ' + this._url + ' - Status: ' + this.status
107
- }));
141
+ message: LOG_PREFIX + 'XHR RESPONSE ERROR: ' + this._url + ' - Status: ' + this.status
142
+ });
108
143
  }
109
144
  });
110
-
145
+
111
146
  this.addEventListener('error', function() {
112
- window.ReactNativeWebView.postMessage(JSON.stringify({
147
+ safePostMessage({
113
148
  type: 'console',
114
149
  level: 'error',
115
- message: 'XHR ERROR: ' + this._url
116
- }));
150
+ message: LOG_PREFIX + 'XHR ERROR: ' + this._url
151
+ });
117
152
  });
118
-
153
+
119
154
  return originalSend.apply(this, arguments);
120
155
  };
121
-
156
+
122
157
  // Intercepting window.open
123
158
  const originalWindowOpen = window.open;
124
159
  window.open = function(url, target, features) {
125
- window.ReactNativeWebView.postMessage(JSON.stringify({
160
+ safePostMessage({
126
161
  type: 'window.open',
127
162
  url: url,
128
163
  target: target,
129
164
  features: features
130
- }));
131
-
132
- // Returning a dummy window object to prevent JS errors
165
+ });
166
+
167
+ // Returning a mock window object to prevent JS errors
133
168
  return {
134
169
  closed: false,
135
170
  close: function() {
136
- window.ReactNativeWebView.postMessage(JSON.stringify({
171
+ safePostMessage({
137
172
  type: 'window.close'
138
- }));
173
+ });
139
174
  },
140
175
  focus: function() {
141
- window.ReactNativeWebView.postMessage(JSON.stringify({
176
+ safePostMessage({
142
177
  type: 'window.focus'
143
- }));
178
+ });
144
179
  },
145
180
  blur: function() {
146
- window.ReactNativeWebView.postMessage(JSON.stringify({
181
+ safePostMessage({
147
182
  type: 'window.blur'
148
- }));
183
+ });
149
184
  }
150
185
  };
151
186
  };
152
-
187
+
153
188
  // Listening for unhandled errors
154
189
  window.addEventListener('error', function(event) {
155
- window.ReactNativeWebView.postMessage(JSON.stringify({
190
+ safePostMessage({
156
191
  type: 'console',
157
192
  level: 'error',
158
- message: 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
159
- }));
193
+ message: LOG_PREFIX + 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
194
+ });
160
195
  });
161
-
196
+
162
197
  // Listening for unhandled promise rejections
163
198
  window.addEventListener('unhandledrejection', function(event) {
164
- window.ReactNativeWebView.postMessage(JSON.stringify({
199
+ safePostMessage({
165
200
  type: 'console',
166
201
  level: 'error',
167
- message: 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
168
- }));
202
+ message: LOG_PREFIX + 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
203
+ });
169
204
  });
170
205
 
171
206
  // Listening for messages from the WebView
172
207
  window.addEventListener('message', function(event) {
173
- console.log("MAIN_WEBVIEW: " + 'Message received: ' + event.data);
174
- window.ReactNativeWebView.postMessage(JSON.stringify({
208
+ console.log(LOG_PREFIX + 'Message received: ' + event.data);
209
+ safePostMessage({
175
210
  type: 'message',
176
211
  message: event.data
177
- }));
212
+ });
178
213
  });
179
-
214
+
180
215
  // Logging that injection is complete
181
- console.log('GlomoPay WebView JavaScript injection complete');
182
-
216
+ console.log(LOG_PREFIX + 'GlomoPay WebView JavaScript injection complete');
217
+
183
218
  true; // Required for injected JavaScript
184
219
  })();
185
220
  `;
@@ -0,0 +1,3 @@
1
+ /** Injection JavaScript for the Standard Checkout WebView */
2
+ export declare const injectedScript: string;
3
+ //# sourceMappingURL=webview-standard.injection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webview-standard.injection.d.ts","sourceRoot":"","sources":["../../src/injections/webview-standard.injection.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,eAAO,MAAM,cAAc,EAAE,MAiN5B,CAAC"}
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.injectedScript = void 0;
4
+ /** Injection JavaScript for the Standard Checkout WebView */
5
+ exports.injectedScript = `
6
+ (function() {
7
+ // Log prefix for all messages originating from the standard checkout WebView
8
+ const LOG_PREFIX = 'STANDARD_WEBVIEW: ';
9
+
10
+ /**
11
+ * Formats an array of arguments into a single prefixed string for posting back to React Native.
12
+ * Objects are JSON-stringified; primitives are coerced to strings.
13
+ */
14
+ function formatMessage(args) {
15
+ return args.map(function(arg) {
16
+ if (typeof arg === 'object') {
17
+ try {
18
+ return LOG_PREFIX + JSON.stringify(arg, null, 2);
19
+ } catch (error) {
20
+ return LOG_PREFIX + '[unserializable object]';
21
+ }
22
+ }
23
+ return LOG_PREFIX + String(arg);
24
+ }).join(' ');
25
+ }
26
+
27
+ // Saving original console methods before overriding (must be declared before safePostMessage references them)
28
+ const originalLog = console.log;
29
+ const originalWarn = console.warn;
30
+ const originalError = console.error;
31
+ const originalInfo = console.info;
32
+
33
+ /**
34
+ * Safely posts a message to ReactNativeWebView with a guard check.
35
+ * Prevents crashes if the WebView bridge is not yet ready or has been torn down.
36
+ */
37
+ function safePostMessage(payload) {
38
+ try {
39
+ if (window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === 'function') {
40
+ window.ReactNativeWebView.postMessage(JSON.stringify(payload));
41
+ }
42
+ } catch (error) {
43
+ originalError && originalError.call(console, LOG_PREFIX + 'Failed to post message to ReactNativeWebView', error);
44
+ }
45
+ }
46
+
47
+ // Overriding console methods to forward logs back to React Native
48
+
49
+ console.log = function(...args) {
50
+ originalLog.apply(console, args);
51
+ safePostMessage({
52
+ type: 'console',
53
+ level: 'log',
54
+ message: formatMessage(args)
55
+ });
56
+ };
57
+
58
+ console.warn = function(...args) {
59
+ originalWarn.apply(console, args);
60
+ safePostMessage({
61
+ type: 'console',
62
+ level: 'warn',
63
+ message: formatMessage(args)
64
+ });
65
+ };
66
+
67
+ console.error = function(...args) {
68
+ originalError.apply(console, args);
69
+ safePostMessage({
70
+ type: 'console',
71
+ level: 'error',
72
+ message: formatMessage(args)
73
+ });
74
+ };
75
+
76
+ console.info = function(...args) {
77
+ originalInfo.apply(console, args);
78
+ safePostMessage({
79
+ type: 'console',
80
+ level: 'info',
81
+ message: formatMessage(args)
82
+ });
83
+ };
84
+
85
+ // Intercepting fetch requests to log network activity
86
+ const originalFetch = window.fetch;
87
+ window.fetch = function(...args) {
88
+ const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || 'Unknown URL';
89
+ safePostMessage({
90
+ type: 'console',
91
+ level: 'network',
92
+ message: LOG_PREFIX + 'FETCH REQUEST: ' + url
93
+ });
94
+
95
+ return originalFetch.apply(this, args)
96
+ .then(response => {
97
+ safePostMessage({
98
+ type: 'console',
99
+ level: 'network',
100
+ message: LOG_PREFIX + 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
101
+ });
102
+ return response;
103
+ })
104
+ .catch(error => {
105
+ safePostMessage({
106
+ type: 'console',
107
+ level: 'error',
108
+ message: LOG_PREFIX + 'FETCH ERROR: ' + url + ' - ' + error.message
109
+ });
110
+ throw error;
111
+ });
112
+ };
113
+
114
+ // Intercepting XMLHttpRequest to log network activity
115
+ const originalOpen = XMLHttpRequest.prototype.open;
116
+ const originalSend = XMLHttpRequest.prototype.send;
117
+
118
+ XMLHttpRequest.prototype.open = function(method, url) {
119
+ this._url = url;
120
+ this._method = method;
121
+ return originalOpen.apply(this, arguments);
122
+ };
123
+
124
+ XMLHttpRequest.prototype.send = function() {
125
+ safePostMessage({
126
+ type: 'console',
127
+ level: 'network',
128
+ message: LOG_PREFIX + 'XHR REQUEST: ' + this._method + ' ' + this._url
129
+ });
130
+
131
+ this.addEventListener('load', function() {
132
+ safePostMessage({
133
+ type: 'console',
134
+ level: 'network',
135
+ message: LOG_PREFIX + 'XHR RESPONSE: ' + this._url + ' - Status: ' + this.status
136
+ });
137
+ });
138
+
139
+ this.addEventListener('error', function() {
140
+ safePostMessage({
141
+ type: 'console',
142
+ level: 'error',
143
+ message: LOG_PREFIX + 'XHR ERROR: ' + this._url
144
+ });
145
+ });
146
+
147
+ return originalSend.apply(this, arguments);
148
+ };
149
+
150
+ // Intercepting programmatic form.submit() - force target="_blank" to "_self"
151
+ const originalSubmit = HTMLFormElement.prototype.submit;
152
+ HTMLFormElement.prototype.submit = function() {
153
+ if (this.target === '_blank') {
154
+ this.target = '_self';
155
+ }
156
+ return originalSubmit.call(this);
157
+ };
158
+
159
+ // Intercepting window.open (for 3DS redirects, bank pages, etc.)
160
+ const originalWindowOpen = window.open;
161
+ window.open = function(url, target, features) {
162
+ safePostMessage({
163
+ type: 'window.open',
164
+ url: url,
165
+ target: target,
166
+ features: features
167
+ });
168
+
169
+ // Returning a mock window object so the caller does not crash on .close()/.focus() calls
170
+ return {
171
+ closed: false,
172
+ close: function() {
173
+ safePostMessage({
174
+ type: 'window.close'
175
+ });
176
+ },
177
+ focus: function() {},
178
+ blur: function() {}
179
+ };
180
+ };
181
+
182
+ // Listening for unhandled errors
183
+ window.addEventListener('error', function(event) {
184
+ safePostMessage({
185
+ type: 'console',
186
+ level: 'error',
187
+ message: LOG_PREFIX + 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
188
+ });
189
+ });
190
+
191
+ // Listening for unhandled promise rejections
192
+ window.addEventListener('unhandledrejection', function(event) {
193
+ safePostMessage({
194
+ type: 'console',
195
+ level: 'error',
196
+ message: LOG_PREFIX + 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
197
+ });
198
+ });
199
+
200
+ // Listening for messages from the checkout page (payment events, lifecycle events)
201
+ window.addEventListener('message', function(event) {
202
+ console.log(LOG_PREFIX + 'Message received: ' + event.data);
203
+ safePostMessage({
204
+ type: 'message',
205
+ message: event.data
206
+ });
207
+ });
208
+
209
+ // Logging that injection is complete
210
+ console.log(LOG_PREFIX + 'GlomoPay WebView JavaScript injection complete');
211
+
212
+ true; // Required for injected JavaScript
213
+ })();
214
+ `;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Order type fetcher service.
3
+ * Calls the order API to determine whether a given orderId is an LRS or Standard checkout flow.
4
+ * Used by the unified GlomoCheckout component to delegate to the correct inner component.
5
+ */
6
+ import { type GlomoServer } from "../config/base";
7
+ /** The two supported checkout flow types */
8
+ export type OrderType = "standard" | "lrs";
9
+ /** Discriminated union result - either a resolved order type or an error message */
10
+ export type OrderTypeResult = {
11
+ success: true;
12
+ orderType: OrderType;
13
+ } | {
14
+ success: false;
15
+ error: string;
16
+ };
17
+ /**
18
+ * Fetches the order type for the given orderId from the public API.
19
+ * Returns a discriminated union so the caller can handle success/failure without try-catch.
20
+ */
21
+ export declare function fetchOrderType(options: {
22
+ orderId: string;
23
+ publicKey: string;
24
+ server?: GlomoServer;
25
+ timeoutMs?: number;
26
+ devMode?: boolean;
27
+ }): Promise<OrderTypeResult>;
28
+ //# sourceMappingURL=order-type-fetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-type-fetcher.d.ts","sourceRoot":"","sources":["../../src/services/order-type-fetcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEvE,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,KAAK,CAAC;AAE3C,oFAAoF;AACpF,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1G;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC,eAAe,CAAC,CA4D3B"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * Order type fetcher service.
4
+ * Calls the order API to determine whether a given orderId is an LRS or Standard checkout flow.
5
+ * Used by the unified GlomoCheckout component to delegate to the correct inner component.
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.fetchOrderType = fetchOrderType;
42
+ const axios_1 = __importStar(require("axios"));
43
+ const base_1 = require("../config/base");
44
+ /**
45
+ * Fetches the order type for the given orderId from the public API.
46
+ * Returns a discriminated union so the caller can handle success/failure without try-catch.
47
+ */
48
+ async function fetchOrderType(options) {
49
+ var _a;
50
+ try {
51
+ // Resolving the API base URL from the server config
52
+ const config = (0, base_1.resolveServerConfig)(options.server);
53
+ const apiUrl = `${config.baseUrl.api}/api/public/v1/order/${options.orderId}`;
54
+ if (options.devMode) {
55
+ console.log(`[Glomo-RN-SDK] Order type API URL: ${apiUrl}`);
56
+ }
57
+ /**
58
+ * Calling the order API with the publicKey as Bearer token.
59
+ * Cache-busting headers prevent okhttp (Android) from sending If-None-Match on repeat calls,
60
+ * which would cause the server to return a 304 with an empty body and break order type detection.
61
+ */
62
+ const response = await axios_1.default.get(apiUrl, {
63
+ headers: {
64
+ Authorization: `Bearer ${options.publicKey}`,
65
+ "Cache-Control": "no-cache, no-store, must-revalidate",
66
+ Pragma: "no-cache",
67
+ },
68
+ timeout: (_a = options.timeoutMs) !== null && _a !== void 0 ? _a : 30000,
69
+ });
70
+ const data = response.data;
71
+ // Validating that the returned order type is one of the expected values
72
+ if (data.orderType === "lrs" || data.orderType === "standard") {
73
+ if (options.devMode) {
74
+ console.log(`[Glomo-RN-SDK] Order type for orderId: ${options.orderId} successfully determined to be ${data.orderType}`);
75
+ }
76
+ return { success: true, orderType: data.orderType };
77
+ }
78
+ if (options.devMode) {
79
+ console.log(`[Glomo-RN-SDK] Unexpected orderType ${data.orderType} provided for ${options.orderId}`);
80
+ }
81
+ return { success: false, error: `Unexpected order type from ${apiUrl}: ${data.orderType}` };
82
+ }
83
+ catch (error) {
84
+ // Extracting the error message for logging and returning
85
+ const message = error instanceof Error ? error.message : String(error);
86
+ const config = (0, base_1.resolveServerConfig)(options.server);
87
+ const apiUrl = `${config.baseUrl.api}/api/public/v1/order/${options.orderId}`;
88
+ if (options.devMode) {
89
+ // Logging additional response details for Axios errors (status code, response body)
90
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
91
+ console.log(`[Glomo-RN-SDK] orderType determination failed for ${options.orderId} from ${apiUrl}: ${message} (${error.response.status}) and data:`, JSON.stringify(error.response.data));
92
+ }
93
+ else {
94
+ console.log(`[Glomo-RN-SDK] orderType determination failed for ${options.orderId} from ${apiUrl}: ${message}`);
95
+ }
96
+ }
97
+ return { success: false, error: `Failed to determine order type for ${apiUrl}: ${message}` };
98
+ }
99
+ }