@altcraft/react-native-sdk 0.0.2 → 0.0.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.
- package/LICENSE +20 -20
- package/README.md +119 -27
- package/Sdk.podspec +2 -2
- package/android/build.gradle +3 -4
- package/android/src/main/java/com/altcraft/sdk/SdkEventEmitter.kt +50 -0
- package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +663 -480
- package/android/src/main/java/com/altcraft/sdk/SdkPackage.kt +16 -8
- package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +164 -0
- package/android/src/main/java/com/altcraft/sdk/utilities/Extension.kt +72 -0
- package/ios/Converter.swift +485 -48
- package/ios/Sdk.mm +195 -270
- package/ios/SdkModule.swift +456 -507
- package/lib/module/NativeSdk.js +35 -0
- package/lib/module/NativeSdk.js.map +1 -1
- package/lib/module/Utilities.js +178 -0
- package/lib/module/Utilities.js.map +1 -0
- package/lib/module/index.js +335 -245
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeSdk.d.ts +125 -33
- package/lib/typescript/src/NativeSdk.d.ts.map +1 -1
- package/lib/typescript/src/Utilities.d.ts +47 -0
- package/lib/typescript/src/Utilities.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +218 -94
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeSdk.ts +169 -46
- package/src/Utilities.ts +180 -0
- package/src/index.tsx +410 -312
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnFCMProvider.kt +0 -26
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnHMSProvider.kt +0 -32
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnJWTProvider.kt +0 -21
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnRustoreProvider.kt +0 -53
- package/ios/protocols/RNAPNSProvider.swift +0 -15
- package/ios/protocols/RNFCMProvider.swift +0 -24
- package/ios/protocols/RNHMSProvider.swift +0 -24
- package/ios/protocols/RNJWTProvider.swift +0 -15
package/lib/module/NativeSdk.js
CHANGED
|
@@ -4,10 +4,45 @@ import { TurboModuleRegistry } from 'react-native';
|
|
|
4
4
|
|
|
5
5
|
// ---------------- Data models ----------------
|
|
6
6
|
|
|
7
|
+
/** Subscription category metadata. */
|
|
8
|
+
|
|
9
|
+
/** UTM parameters for event attribution. */
|
|
10
|
+
|
|
11
|
+
// ---------------- Subscription Types ----------------
|
|
12
|
+
|
|
13
|
+
/** Email subscription data. */
|
|
14
|
+
|
|
15
|
+
/** SMS subscription data. */
|
|
16
|
+
|
|
17
|
+
/** Push subscription data. */
|
|
18
|
+
|
|
19
|
+
/** CC-data subscription (Telegram, WhatsApp, Viber, Notify). */
|
|
20
|
+
|
|
21
|
+
/** Union of all supported subscription types. */
|
|
22
|
+
|
|
23
|
+
// ---------------- API models ----------------
|
|
24
|
+
|
|
25
|
+
/** Profile data returned from the API. */
|
|
26
|
+
|
|
27
|
+
/** API response payload. */
|
|
28
|
+
|
|
29
|
+
/** API response with HTTP status code. */
|
|
30
|
+
|
|
31
|
+
// ---------------- Config / SDK models ----------------
|
|
32
|
+
|
|
33
|
+
/** Application metadata. */
|
|
34
|
+
|
|
35
|
+
/** SDK configuration object. */
|
|
36
|
+
|
|
37
|
+
/** Push token data. */
|
|
38
|
+
|
|
39
|
+
/** SDK event emitted from native via NativeEventEmitter ("AltcraftSdkEvent"). */
|
|
40
|
+
|
|
7
41
|
// ---------------- TurboModule Spec ----------------
|
|
8
42
|
|
|
9
43
|
// ---------------- Export ----------------
|
|
10
44
|
|
|
45
|
+
/** Native TurboModule instance. */
|
|
11
46
|
const NativeSDK = TurboModuleRegistry.getEnforcing('Sdk');
|
|
12
47
|
export default NativeSDK;
|
|
13
48
|
//# sourceMappingURL=NativeSdk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","NativeSDK","getEnforcing"],"sourceRoot":"../../src","sources":["NativeSdk.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;;AAEpE;;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","NativeSDK","getEnforcing"],"sourceRoot":"../../src","sources":["NativeSdk.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;;AAEpE;;AAEA;;AAQA;;AAUA;;AAEA;;AAWA;;AAWA;;AAYA;;AAYA;;AAOA;;AAEA;;AAQA;;AAOA;;AAMA;;AAEA;;AAOA;;AAeA;;AAMA;;AASA;;AAyKA;;AAEA;AACA,MAAMC,SAAS,GAAGD,mBAAmB,CAACE,YAAY,CAAO,KAAK,CAAC;AAC/D,eAAeD,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/** Supported action types for profile field manipulation. */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builder for structured profile field actions.
|
|
7
|
+
*
|
|
8
|
+
* Produces a map entry compatible with the native SDK's ActionFieldBuilder.
|
|
9
|
+
* The resulting map is intended to be merged into `profileFields` before
|
|
10
|
+
* passing to `pushSubscribe`, `updateProfileFields`, or similar APIs.
|
|
11
|
+
*/
|
|
12
|
+
export class ActionFieldBuilder {
|
|
13
|
+
constructor(key) {
|
|
14
|
+
this.key = key;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Set field to a specific value. */
|
|
18
|
+
set(value) {
|
|
19
|
+
return {
|
|
20
|
+
[this.key]: {
|
|
21
|
+
action: 'set',
|
|
22
|
+
value
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Unset (remove) a field value. */
|
|
28
|
+
unset(value) {
|
|
29
|
+
return {
|
|
30
|
+
[this.key]: {
|
|
31
|
+
action: 'unset',
|
|
32
|
+
value
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Increment a numeric field by the given value. */
|
|
38
|
+
incr(value) {
|
|
39
|
+
return {
|
|
40
|
+
[this.key]: {
|
|
41
|
+
action: 'incr',
|
|
42
|
+
value
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Add a value to a set/array field. */
|
|
48
|
+
add(value) {
|
|
49
|
+
return {
|
|
50
|
+
[this.key]: {
|
|
51
|
+
action: 'add',
|
|
52
|
+
value
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Delete a value from a set/array field. */
|
|
58
|
+
delete(value) {
|
|
59
|
+
return {
|
|
60
|
+
[this.key]: {
|
|
61
|
+
action: 'delete',
|
|
62
|
+
value
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Upsert: set if missing, update if exists. */
|
|
68
|
+
upsert(value) {
|
|
69
|
+
return {
|
|
70
|
+
[this.key]: {
|
|
71
|
+
action: 'upsert',
|
|
72
|
+
value
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Creates an ActionFieldBuilder for the given field key.
|
|
80
|
+
*
|
|
81
|
+
* @param key Profile field key to operate on.
|
|
82
|
+
* @returns Builder instance with action methods.
|
|
83
|
+
*/
|
|
84
|
+
export function actionField(key) {
|
|
85
|
+
return new ActionFieldBuilder(key);
|
|
86
|
+
}
|
|
87
|
+
export class Utilities {
|
|
88
|
+
/** Converts a JS object to { [key: string]: string }
|
|
89
|
+
* for the RN bridge; drops null/undefined. */
|
|
90
|
+
static toNativeStringMap(input) {
|
|
91
|
+
if (input == null) return null;
|
|
92
|
+
const out = {};
|
|
93
|
+
for (const [key, value] of Object.entries(input)) {
|
|
94
|
+
if (value == null) continue;
|
|
95
|
+
switch (typeof value) {
|
|
96
|
+
case 'string':
|
|
97
|
+
out[key] = value;
|
|
98
|
+
break;
|
|
99
|
+
case 'number':
|
|
100
|
+
case 'boolean':
|
|
101
|
+
case 'bigint':
|
|
102
|
+
out[key] = String(value);
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
try {
|
|
106
|
+
out[key] = JSON.stringify(value);
|
|
107
|
+
} catch {
|
|
108
|
+
out[key] = String(value);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* New Arch safe:
|
|
118
|
+
* TurboModule codegen does NOT support `any`.
|
|
119
|
+
* Therefore, we serialize any value for UserDefaults into `string`.
|
|
120
|
+
*/
|
|
121
|
+
static toUserDefaultsString(value) {
|
|
122
|
+
if (value == null) return null;
|
|
123
|
+
const t = typeof value;
|
|
124
|
+
if (t === 'string') return String(value);
|
|
125
|
+
if (t === 'number' || t === 'boolean') return String(value);
|
|
126
|
+
try {
|
|
127
|
+
return JSON.stringify(value);
|
|
128
|
+
} catch {
|
|
129
|
+
return String(value);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Converts Subscription object to native string map format. */
|
|
134
|
+
static subscriptionToNativeMap(subscription) {
|
|
135
|
+
if (subscription == null) return null;
|
|
136
|
+
const result = {
|
|
137
|
+
type: subscription.type,
|
|
138
|
+
resource_id: String(subscription.resource_id)
|
|
139
|
+
};
|
|
140
|
+
if (subscription.status != null) result.status = subscription.status;
|
|
141
|
+
if (subscription.priority != null) result.priority = String(subscription.priority);
|
|
142
|
+
if (subscription.custom_fields != null) {
|
|
143
|
+
try {
|
|
144
|
+
result.custom_fields = JSON.stringify(subscription.custom_fields);
|
|
145
|
+
} catch {
|
|
146
|
+
result.custom_fields = '{}';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (subscription.cats != null) {
|
|
150
|
+
try {
|
|
151
|
+
result.cats = JSON.stringify(subscription.cats);
|
|
152
|
+
} catch {
|
|
153
|
+
result.cats = '[]';
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
switch (subscription.type) {
|
|
157
|
+
case 'email':
|
|
158
|
+
result.email = subscription.email;
|
|
159
|
+
break;
|
|
160
|
+
case 'sms':
|
|
161
|
+
result.phone = subscription.phone;
|
|
162
|
+
break;
|
|
163
|
+
case 'push':
|
|
164
|
+
result.provider = subscription.provider;
|
|
165
|
+
result.subscription_id = subscription.subscription_id;
|
|
166
|
+
break;
|
|
167
|
+
case 'cc_data':
|
|
168
|
+
try {
|
|
169
|
+
result.cc_data = JSON.stringify(subscription.cc_data);
|
|
170
|
+
} catch {
|
|
171
|
+
result.cc_data = '{}';
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=Utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ActionFieldBuilder","constructor","key","set","value","action","unset","incr","add","delete","upsert","actionField","Utilities","toNativeStringMap","input","out","Object","entries","String","JSON","stringify","keys","length","toUserDefaultsString","t","subscriptionToNativeMap","subscription","result","type","resource_id","status","priority","custom_fields","cats","email","phone","provider","subscription_id","cc_data"],"sourceRoot":"../../src","sources":["Utilities.ts"],"mappings":";;AAEA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,CAAC;EAG9BC,WAAWA,CAACC,GAAW,EAAE;IACvB,IAAI,CAACA,GAAG,GAAGA,GAAG;EAChB;;EAEA;EACAC,GAAGA,CAACC,KAAc,EAA2B;IAC3C,OAAO;MAAE,CAAC,IAAI,CAACF,GAAG,GAAG;QAAEG,MAAM,EAAE,KAAK;QAAED;MAAM;IAAE,CAAC;EACjD;;EAEA;EACAE,KAAKA,CAACF,KAAc,EAA2B;IAC7C,OAAO;MAAE,CAAC,IAAI,CAACF,GAAG,GAAG;QAAEG,MAAM,EAAE,OA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