@magalu/webzord 1.5.1 → 1.5.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.5.3](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/compare/v1.5.2...v1.5.3) (2026-11-18)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * duplicated callbackid ([f891184](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/commit/f891184))
9
+
10
+ ## [1.5.2](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/compare/v1.5.1...v1.5.2) (2026-08-21)
11
+
12
+
13
+ ### Continuous Integration
14
+
15
+ * internal npm publish ([2c1e77e](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/commit/2c1e77e))
16
+
3
17
  ## [1.5.1](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/compare/v1.5.0...v1.5.1) (2026-08-20)
4
18
 
5
19
 
@@ -26,13 +26,14 @@ class MagaluService {
26
26
  console.warn("didn't found any sdk");
27
27
  return;
28
28
  }
29
- if (id && callback) {
30
- this.callbacks.set(id, callback);
29
+ const requestId = this.reserveCallbackId(id);
30
+ if (callback) {
31
+ this.callbacks.set(requestId, callback);
31
32
  }
32
33
  try {
33
34
  const argsString = JSON.stringify(serviceArgs);
34
35
  const payload = {
35
- callbackId,
36
+ callbackId: requestId,
36
37
  serviceName,
37
38
  authId: (_b = (_a = this.hash) !== null && _a !== void 0 ? _a : authId) !== null && _b !== void 0 ? _b : '',
38
39
  arguments: argsString,
@@ -40,17 +41,27 @@ class MagaluService {
40
41
  };
41
42
  const message = JSON.stringify(payload);
42
43
  if (isUsingPromise) {
43
- const promise = this.buildPromise(id);
44
- this.callSDK(message, id);
44
+ const promise = this.buildPromise(requestId);
45
+ this.callSDK(message, requestId);
45
46
  return promise;
46
47
  }
47
48
  else {
48
- this.callSDK(message, callbackId);
49
+ this.callSDK(message, requestId);
49
50
  }
50
51
  }
51
52
  catch (e) {
52
53
  console.error(e);
54
+ this.unregister(requestId);
55
+ }
56
+ }
57
+ static reserveCallbackId(callbackId) {
58
+ let candidate = callbackId;
59
+ while (this.pendingCallbackIds.has(candidate)) {
60
+ this.callbackIdSequence += 1;
61
+ candidate = `${callbackId}-${this.callbackIdSequence}`;
53
62
  }
63
+ this.pendingCallbackIds.add(candidate);
64
+ return candidate;
54
65
  }
55
66
  static handleMockRequest(serviceName, callbackId, callback, isUsingPromise) {
56
67
  if (isProductionBuild()) {
@@ -130,7 +141,7 @@ class MagaluService {
130
141
  }
131
142
  else {
132
143
  console.warn("didn't found any sdk");
133
- callbackId && this.callbacks.delete(callbackId);
144
+ callbackId && this.unregister(callbackId);
134
145
  }
135
146
  }
136
147
  /**
@@ -138,12 +149,14 @@ class MagaluService {
138
149
  */
139
150
  static unregister(callbackId) {
140
151
  this.callbacks.delete(callbackId);
152
+ this.pendingCallbackIds.delete(callbackId);
141
153
  }
142
154
  /**
143
155
  * Wipes all the callbacks
144
156
  */
145
157
  static unregisterAll() {
146
158
  this.callbacks.clear();
159
+ this.pendingCallbackIds.clear();
147
160
  }
148
161
  /**
149
162
  * @protected
@@ -153,6 +166,7 @@ class MagaluService {
153
166
  */
154
167
  static pushResponse(response) {
155
168
  try {
169
+ this.pendingCallbackIds.delete(response.callbackId);
156
170
  const callback = this.callbacks.get(response.callbackId);
157
171
  if (!callback) {
158
172
  return;
@@ -198,6 +212,8 @@ MagaluService.deeplink = extractParam('deeplink');
198
212
  * @private
199
213
  * Mapping from `callbackId` to a `callback` function */
200
214
  MagaluService.callbacks = new Map();
215
+ MagaluService.pendingCallbackIds = new Set();
216
+ MagaluService.callbackIdSequence = 0;
201
217
  /**
202
218
  * @param {ServiceResponse} result - a response from the SDK
203
219
  * @returns true if the result code is between 200...299
@@ -52,6 +52,8 @@ declare class MagaluService {
52
52
  * @private
53
53
  * Mapping from `callbackId` to a `callback` function */
54
54
  static callbacks: Map<string, ServiceCallback>;
55
+ private static pendingCallbackIds;
56
+ private static callbackIdSequence;
55
57
  /** Cache for lazy-loaded mock module. */
56
58
  private static mockDataPromise?;
57
59
  /**
@@ -109,6 +111,7 @@ declare class MagaluService {
109
111
  * ```
110
112
  */
111
113
  static request({ serviceName, serviceArgs, callbackId, callback }: ServiceCall, mockMode?: boolean): void;
114
+ private static reserveCallbackId;
112
115
  private static handleMockRequest;
113
116
  private static loadMockData;
114
117
  private static returnMockedResponse;
@@ -29,13 +29,14 @@ class MagaluService {
29
29
  console.warn("didn't found any sdk");
30
30
  return;
31
31
  }
32
- if (id && callback) {
33
- this.callbacks.set(id, callback);
32
+ const requestId = this.reserveCallbackId(id);
33
+ if (callback) {
34
+ this.callbacks.set(requestId, callback);
34
35
  }
35
36
  try {
36
37
  const argsString = JSON.stringify(serviceArgs);
37
38
  const payload = {
38
- callbackId,
39
+ callbackId: requestId,
39
40
  serviceName,
40
41
  authId: (_b = (_a = this.hash) !== null && _a !== void 0 ? _a : authId) !== null && _b !== void 0 ? _b : '',
41
42
  arguments: argsString,
@@ -43,17 +44,27 @@ class MagaluService {
43
44
  };
44
45
  const message = JSON.stringify(payload);
45
46
  if (isUsingPromise) {
46
- const promise = this.buildPromise(id);
47
- this.callSDK(message, id);
47
+ const promise = this.buildPromise(requestId);
48
+ this.callSDK(message, requestId);
48
49
  return promise;
49
50
  }
50
51
  else {
51
- this.callSDK(message, callbackId);
52
+ this.callSDK(message, requestId);
52
53
  }
53
54
  }
54
55
  catch (e) {
55
56
  console.error(e);
57
+ this.unregister(requestId);
58
+ }
59
+ }
60
+ static reserveCallbackId(callbackId) {
61
+ let candidate = callbackId;
62
+ while (this.pendingCallbackIds.has(candidate)) {
63
+ this.callbackIdSequence += 1;
64
+ candidate = `${callbackId}-${this.callbackIdSequence}`;
56
65
  }
66
+ this.pendingCallbackIds.add(candidate);
67
+ return candidate;
57
68
  }
58
69
  static handleMockRequest(serviceName, callbackId, callback, isUsingPromise) {
59
70
  if (isProductionBuild()) {
@@ -133,7 +144,7 @@ class MagaluService {
133
144
  }
134
145
  else {
135
146
  console.warn("didn't found any sdk");
136
- callbackId && this.callbacks.delete(callbackId);
147
+ callbackId && this.unregister(callbackId);
137
148
  }
138
149
  }
139
150
  /**
@@ -141,12 +152,14 @@ class MagaluService {
141
152
  */
142
153
  static unregister(callbackId) {
143
154
  this.callbacks.delete(callbackId);
155
+ this.pendingCallbackIds.delete(callbackId);
144
156
  }
145
157
  /**
146
158
  * Wipes all the callbacks
147
159
  */
148
160
  static unregisterAll() {
149
161
  this.callbacks.clear();
162
+ this.pendingCallbackIds.clear();
150
163
  }
151
164
  /**
152
165
  * @protected
@@ -156,6 +169,7 @@ class MagaluService {
156
169
  */
157
170
  static pushResponse(response) {
158
171
  try {
172
+ this.pendingCallbackIds.delete(response.callbackId);
159
173
  const callback = this.callbacks.get(response.callbackId);
160
174
  if (!callback) {
161
175
  return;
@@ -202,6 +216,8 @@ MagaluService.deeplink = extractParam('deeplink');
202
216
  * @private
203
217
  * Mapping from `callbackId` to a `callback` function */
204
218
  MagaluService.callbacks = new Map();
219
+ MagaluService.pendingCallbackIds = new Set();
220
+ MagaluService.callbackIdSequence = 0;
205
221
  /**
206
222
  * @param {ServiceResponse} result - a response from the SDK
207
223
  * @returns true if the result code is between 200...299
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magalu/webzord",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Toolkit to consume superapp api",
5
5
  "main": "lib/magaluService.js",
6
6
  "module": "lib/esm/magaluService.js",