affise-attribution-lib 1.6.14 → 1.6.15
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 +34 -8
- package/affise-attribution-native.podspec +1 -1
- package/android/build.gradle +6 -2
- package/lib/commonjs/events/OnSendFailedCallback.js +6 -0
- package/lib/commonjs/events/OnSendFailedCallback.js.map +1 -0
- package/lib/commonjs/events/OnSendSuccessCallback.js +2 -0
- package/lib/commonjs/events/OnSendSuccessCallback.js.map +1 -0
- package/lib/commonjs/events/base/AffiseEvent.js +7 -0
- package/lib/commonjs/events/base/AffiseEvent.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native/AffiseApiMethod.js +1 -0
- package/lib/commonjs/native/AffiseApiMethod.js.map +1 -1
- package/lib/commonjs/native/AffiseNative.js +40 -13
- package/lib/commonjs/native/AffiseNative.js.map +1 -1
- package/lib/commonjs/native/NativeBase.js +25 -3
- package/lib/commonjs/native/NativeBase.js.map +1 -1
- package/lib/commonjs/native/utils/DebugUtils.js +26 -16
- package/lib/commonjs/native/utils/DebugUtils.js.map +1 -1
- package/lib/module/events/OnSendFailedCallback.js +2 -0
- package/lib/module/events/OnSendFailedCallback.js.map +1 -0
- package/lib/module/events/OnSendSuccessCallback.js +2 -0
- package/lib/module/events/OnSendSuccessCallback.js.map +1 -0
- package/lib/module/events/base/AffiseEvent.js +7 -1
- package/lib/module/events/base/AffiseEvent.js.map +1 -1
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/AffiseApiMethod.js +1 -0
- package/lib/module/native/AffiseApiMethod.js.map +1 -1
- package/lib/module/native/AffiseNative.js +40 -13
- package/lib/module/native/AffiseNative.js.map +1 -1
- package/lib/module/native/NativeBase.js +25 -3
- package/lib/module/native/NativeBase.js.map +1 -1
- package/lib/module/native/utils/DebugUtils.js +26 -16
- package/lib/module/native/utils/DebugUtils.js.map +1 -1
- package/lib/typescript/events/OnSendFailedCallback.d.ts +3 -0
- package/lib/typescript/events/OnSendFailedCallback.d.ts.map +1 -0
- package/lib/typescript/events/OnSendSuccessCallback.d.ts +2 -0
- package/lib/typescript/events/OnSendSuccessCallback.d.ts.map +1 -0
- package/lib/typescript/events/base/AffiseEvent.d.ts +6 -0
- package/lib/typescript/events/base/AffiseEvent.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/native/AffiseApiMethod.d.ts +1 -0
- package/lib/typescript/native/AffiseApiMethod.d.ts.map +1 -1
- package/lib/typescript/native/AffiseNative.d.ts +6 -1
- package/lib/typescript/native/AffiseNative.d.ts.map +1 -1
- package/lib/typescript/native/NativeBase.d.ts +4 -1
- package/lib/typescript/native/NativeBase.d.ts.map +1 -1
- package/lib/typescript/native/utils/DebugUtils.d.ts +2 -0
- package/lib/typescript/native/utils/DebugUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/events/OnSendFailedCallback.ts +3 -0
- package/src/events/OnSendSuccessCallback.ts +1 -0
- package/src/events/base/AffiseEvent.ts +9 -0
- package/src/index.ts +9 -0
- package/src/native/AffiseApiMethod.ts +1 -1
- package/src/native/AffiseNative.ts +31 -1
- package/src/native/NativeBase.ts +26 -3
- package/src/native/utils/DebugUtils.ts +30 -16
|
@@ -16,9 +16,14 @@ import {toAffiseKeyValueList} from "../module/AffiseKeyValue";
|
|
|
16
16
|
import type {DebugOnValidateCallback} from "../debug/validate/DebugOnValidateCallback";
|
|
17
17
|
import type {DebugOnNetworkCallback} from "../debug/network/DebugOnNetworkCallback";
|
|
18
18
|
import {DebugUtils} from "./utils/DebugUtils";
|
|
19
|
+
import type {OnSendSuccessCallback} from "../events/OnSendSuccessCallback";
|
|
20
|
+
import type {OnSendFailedCallback} from "../events/OnSendFailedCallback";
|
|
19
21
|
|
|
20
22
|
export class AffiseNative extends NativeBase {
|
|
21
23
|
|
|
24
|
+
protected SUCCESS: string = "success";
|
|
25
|
+
protected FAILED: string = "failed";
|
|
26
|
+
|
|
22
27
|
init(initProperties: AffiseInitProperties | AffiseInitPropertiesType) {
|
|
23
28
|
let option: AffiseInitProperties;
|
|
24
29
|
if (isAffiseInitPropertiesType(initProperties)) {
|
|
@@ -38,6 +43,17 @@ export class AffiseNative extends NativeBase {
|
|
|
38
43
|
this.native(AffiseApiMethod.SEND_EVENT, event.toRecord());
|
|
39
44
|
}
|
|
40
45
|
|
|
46
|
+
sendEventNow(event: AffiseEvent, success: OnSendSuccessCallback, failed: OnSendFailedCallback) {
|
|
47
|
+
this.nativeCallbackGroup(
|
|
48
|
+
AffiseApiMethod.SEND_EVENT_NOW,
|
|
49
|
+
new Map([
|
|
50
|
+
[this.SUCCESS, success],
|
|
51
|
+
[this.FAILED, failed],
|
|
52
|
+
]),
|
|
53
|
+
event.toRecord()
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
41
57
|
addPushToken(pushToken: string) {
|
|
42
58
|
this.native(AffiseApiMethod.ADD_PUSH_TOKEN, pushToken);
|
|
43
59
|
}
|
|
@@ -146,8 +162,22 @@ export class AffiseNative extends NativeBase {
|
|
|
146
162
|
this.nativeCallback(AffiseApiMethod.DEBUG_NETWORK_CALLBACK, callback);
|
|
147
163
|
}
|
|
148
164
|
|
|
149
|
-
protected handleCallback(api: AffiseApiMethod, callback: unknown, data: any) {
|
|
165
|
+
protected handleCallback(api: AffiseApiMethod, callback: unknown, data: any, tag: string | null) {
|
|
150
166
|
switch (api) {
|
|
167
|
+
case AffiseApiMethod.SEND_EVENT_NOW:
|
|
168
|
+
switch (tag) {
|
|
169
|
+
case this.SUCCESS:
|
|
170
|
+
tryCast<OnSendSuccessCallback>(callback)?.();
|
|
171
|
+
break;
|
|
172
|
+
case this.FAILED: {
|
|
173
|
+
const response = DebugUtils.parseResponse(data);
|
|
174
|
+
tryCast<OnSendFailedCallback>(callback)?.(response);
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
default:
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
151
181
|
case AffiseApiMethod.GET_REFERRER_CALLBACK:
|
|
152
182
|
tryCast<ReferrerCallback>(callback)?.(data as string || "");
|
|
153
183
|
break;
|
package/src/native/NativeBase.ts
CHANGED
|
@@ -6,7 +6,9 @@ import {apiMethodFrom} from "./AffiseApiMethod";
|
|
|
6
6
|
|
|
7
7
|
export class NativeBase extends NativeBasePlatform {
|
|
8
8
|
protected UUID: string = "callback_uuid";
|
|
9
|
+
protected TAG: string = "callback_tag";
|
|
9
10
|
|
|
11
|
+
protected callbacksGroup: Map<string, Map<string, unknown>> = new Map<string, Map<string, unknown>>();
|
|
10
12
|
protected callbacksOnce: Map<string, unknown> = new Map<string, unknown>();
|
|
11
13
|
protected callbacks: Map<AffiseApiMethod, unknown> = new Map<AffiseApiMethod, unknown>();
|
|
12
14
|
|
|
@@ -34,6 +36,16 @@ export class NativeBase extends NativeBasePlatform {
|
|
|
34
36
|
this.apiCall(api.toString(), apiData);
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
protected nativeCallbackGroup(api: AffiseApiMethod, callbackGroup: Map<string, unknown>, data: any | null = null) {
|
|
40
|
+
const uuid = Uuid.generate();
|
|
41
|
+
const apiData: Record<string, any> = {
|
|
42
|
+
[api.toString()]: data,
|
|
43
|
+
[this.UUID]: uuid,
|
|
44
|
+
};
|
|
45
|
+
this.callbacksGroup.set(uuid, callbackGroup);
|
|
46
|
+
this.apiCall(api.toString(), apiData);
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
protected nativeCallback(api: AffiseApiMethod, callback: unknown, data: any | null = null) {
|
|
38
50
|
const apiData: Record<string, any> = {
|
|
39
51
|
[api.toString()]: data,
|
|
@@ -47,23 +59,34 @@ export class NativeBase extends NativeBasePlatform {
|
|
|
47
59
|
if (api == null) return;
|
|
48
60
|
const dataRecord = apiData as Record<string, any>;
|
|
49
61
|
const uuid = dataRecord[this.UUID] as string;
|
|
62
|
+
const tag = dataRecord[this.TAG] as string;
|
|
50
63
|
const data = dataRecord[apiName];
|
|
64
|
+
|
|
51
65
|
if (uuid == null || uuid.length == 0) {
|
|
52
66
|
const callback = this.callbacks.get(api);
|
|
53
67
|
if (callback !== undefined) {
|
|
54
|
-
this.handleCallback(api, callback, data);
|
|
68
|
+
this.handleCallback(api, callback, data, null);
|
|
69
|
+
}
|
|
70
|
+
} else if (tag != null && uuid.length > 0) {
|
|
71
|
+
const callbackGroup = this.callbacksGroup.get(uuid);
|
|
72
|
+
if (callbackGroup !== undefined) {
|
|
73
|
+
const callback = callbackGroup.get(tag);
|
|
74
|
+
if (callback !== undefined) {
|
|
75
|
+
this.handleCallback(api, callback, data, tag);
|
|
76
|
+
}
|
|
55
77
|
}
|
|
78
|
+
this.callbacksGroup.delete(uuid);
|
|
56
79
|
} else {
|
|
57
80
|
const callback = this.callbacksOnce.get(uuid);
|
|
58
81
|
if (callback !== undefined) {
|
|
59
|
-
this.handleCallback(api, callback, data);
|
|
82
|
+
this.handleCallback(api, callback, data, null);
|
|
60
83
|
}
|
|
61
84
|
this.callbacksOnce.delete(uuid);
|
|
62
85
|
}
|
|
63
86
|
}
|
|
64
87
|
|
|
65
88
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
-
protected handleCallback(_api: AffiseApiMethod, _callback: unknown, _data: any) {
|
|
89
|
+
protected handleCallback(_api: AffiseApiMethod, _callback: unknown, _data: any, _tag: string | null) {
|
|
67
90
|
|
|
68
91
|
}
|
|
69
92
|
}
|
|
@@ -9,29 +9,43 @@ export class DebugUtils {
|
|
|
9
9
|
return validationStatusFrom(data as string || "") || ValidationStatus.UNKNOWN_ERROR;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
static
|
|
12
|
+
static parseResponse(data: any): HttpResponse {
|
|
13
13
|
const json = tryCast<Record<string, any>>(data) || {};
|
|
14
|
+
const resCode = json["code"] as number || 0;
|
|
15
|
+
const resMessage = json["message"] || "";
|
|
16
|
+
const resBody = json["body"];
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
return new HttpResponse({
|
|
19
|
+
code: resCode,
|
|
20
|
+
message: resMessage,
|
|
21
|
+
body: resBody
|
|
22
|
+
});
|
|
23
|
+
}
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
+
static parseRequest(data: any): HttpRequest {
|
|
26
|
+
const json = tryCast<Record<string, any>>(data) || {};
|
|
27
|
+
const reqUrl = json["url"] || "";
|
|
28
|
+
const reqMethod = json["method"] || "";
|
|
29
|
+
const reqBody = json["body"];
|
|
30
|
+
const reqHeaders = tryCast<Record<string, string>>(json["headers"]) || {};
|
|
25
31
|
|
|
26
|
-
return
|
|
32
|
+
return new HttpRequest({
|
|
27
33
|
url: reqUrl,
|
|
28
34
|
method: httpMethodFrom(reqMethod) || HttpMethod.POST,
|
|
29
35
|
headers: reqHeaders,
|
|
30
36
|
body: reqBody
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static parseRequestResponse(data: any): [HttpRequest, HttpResponse] {
|
|
41
|
+
const json = tryCast<Record<string, any>>(data) || {};
|
|
42
|
+
|
|
43
|
+
const req = json["request"];
|
|
44
|
+
const request = this.parseRequest(req);
|
|
45
|
+
|
|
46
|
+
const res = json["response"];
|
|
47
|
+
const response = this.parseResponse(res);
|
|
48
|
+
|
|
49
|
+
return [request, response];
|
|
36
50
|
}
|
|
37
51
|
}
|