@magalu/webzord 1.5.0 → 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 +21 -0
- package/lib/esm/magaluService.js +24 -8
- package/lib/magaluService.d.ts +3 -0
- package/lib/magaluService.js +24 -8
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
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
|
+
|
|
17
|
+
## [1.5.1](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/compare/v1.5.0...v1.5.1) (2026-08-20)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* return a real boolean from didFoundSDK ([e26681d](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/commit/e26681d))
|
|
23
|
+
|
|
3
24
|
# [1.5.0](https://gitlab.luizalabs.com/luizalabs/plataforma-mobile/webzord/compare/v1.4.2...v1.5.0) (2026-04-13)
|
|
4
25
|
|
|
5
26
|
|
package/lib/esm/magaluService.js
CHANGED
|
@@ -26,13 +26,14 @@ class MagaluService {
|
|
|
26
26
|
console.warn("didn't found any sdk");
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
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(
|
|
44
|
-
this.callSDK(message,
|
|
44
|
+
const promise = this.buildPromise(requestId);
|
|
45
|
+
this.callSDK(message, requestId);
|
|
45
46
|
return promise;
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
this.callSDK(message,
|
|
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()) {
|
|
@@ -117,7 +128,7 @@ class MagaluService {
|
|
|
117
128
|
}
|
|
118
129
|
static didFoundSDK() {
|
|
119
130
|
var _a, _b, _c;
|
|
120
|
-
return (((_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.magaluSdk) ||
|
|
131
|
+
return Boolean(((_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.magaluSdk) ||
|
|
121
132
|
((_c = window === null || window === void 0 ? void 0 : window.magaluSdk) === null || _c === void 0 ? void 0 : _c.requestService));
|
|
122
133
|
}
|
|
123
134
|
static callSDK(message, callbackId) {
|
|
@@ -130,7 +141,7 @@ class MagaluService {
|
|
|
130
141
|
}
|
|
131
142
|
else {
|
|
132
143
|
console.warn("didn't found any sdk");
|
|
133
|
-
callbackId && this.
|
|
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
|
package/lib/magaluService.d.ts
CHANGED
|
@@ -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;
|
package/lib/magaluService.js
CHANGED
|
@@ -29,13 +29,14 @@ class MagaluService {
|
|
|
29
29
|
console.warn("didn't found any sdk");
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
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(
|
|
47
|
-
this.callSDK(message,
|
|
47
|
+
const promise = this.buildPromise(requestId);
|
|
48
|
+
this.callSDK(message, requestId);
|
|
48
49
|
return promise;
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
|
-
this.callSDK(message,
|
|
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()) {
|
|
@@ -120,7 +131,7 @@ class MagaluService {
|
|
|
120
131
|
}
|
|
121
132
|
static didFoundSDK() {
|
|
122
133
|
var _a, _b, _c;
|
|
123
|
-
return (((_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.magaluSdk) ||
|
|
134
|
+
return Boolean(((_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.magaluSdk) ||
|
|
124
135
|
((_c = window === null || window === void 0 ? void 0 : window.magaluSdk) === null || _c === void 0 ? void 0 : _c.requestService));
|
|
125
136
|
}
|
|
126
137
|
static callSDK(message, callbackId) {
|
|
@@ -133,7 +144,7 @@ class MagaluService {
|
|
|
133
144
|
}
|
|
134
145
|
else {
|
|
135
146
|
console.warn("didn't found any sdk");
|
|
136
|
-
callbackId && this.
|
|
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.
|
|
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",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"author": "Squad Mini-apps",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@types/node": "^18.11.9",
|
|
33
34
|
"@types/jest": "^26.0.23",
|
|
34
35
|
"jest": "^26.6.3",
|
|
35
36
|
"ts-jest": "^26.5.5",
|