@kerdly/expo 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +235 -2
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +19 -0
- package/android/src/main/java/com/kerdly/expo/KerdlySdkModule.kt +326 -0
- package/android/vendor/kerdly-sdk/.kerdly-sync.json +8 -0
- package/android/vendor/kerdly-sdk/consumer-rules.pro +15 -0
- package/android/vendor/kerdly-sdk/kerdly-sdk.properties +2 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/Kerdly.kt +343 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/KerdlyTypes.kt +89 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Attribution.kt +39 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Batch.kt +159 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Core.kt +991 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeepLinks.kt +114 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeferredLinks.kt +111 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeviceContext.kt +137 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/EventQueue.kt +135 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Events.kt +314 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Json.kt +116 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Logger.kt +49 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Options.kt +47 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Ports.kt +83 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/PublicIp.kt +120 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Referrers.kt +137 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/RemoteConfig.kt +100 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Storage.kt +271 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidPlatform.kt +274 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidRuntime.kt +187 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/PlayReferrerReader.kt +97 -0
- package/app.plugin.js +2 -0
- package/build/Kerdly.d.ts +106 -0
- package/build/Kerdly.d.ts.map +1 -0
- package/build/Kerdly.js +494 -0
- package/build/Kerdly.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -0
- package/build/log.d.ts +13 -0
- package/build/log.d.ts.map +1 -0
- package/build/log.js +45 -0
- package/build/log.js.map +1 -0
- package/build/native.d.ts +74 -0
- package/build/native.d.ts.map +1 -0
- package/build/native.js +56 -0
- package/build/native.js.map +1 -0
- package/build/normalize.d.ts +8 -0
- package/build/normalize.d.ts.map +1 -0
- package/build/normalize.js +86 -0
- package/build/normalize.js.map +1 -0
- package/build/types.d.ts +134 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/validation.d.ts +70 -0
- package/build/validation.d.ts.map +1 -0
- package/build/validation.js +349 -0
- package/build/validation.js.map +1 -0
- package/build/version.d.ts +4 -0
- package/build/version.d.ts.map +1 -0
- package/build/version.js +5 -0
- package/build/version.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/KerdlySDK/.kerdly-sync.json +7 -0
- package/ios/KerdlySDK/Core/Dependencies.swift +163 -0
- package/ios/KerdlySDK/Core/KerdlyCore+API.swift +117 -0
- package/ios/KerdlySDK/Core/KerdlyCore+Collectors.swift +410 -0
- package/ios/KerdlySDK/Core/KerdlyCore+DeferredLinks.swift +220 -0
- package/ios/KerdlySDK/Core/KerdlyCore+Delivery.swift +424 -0
- package/ios/KerdlySDK/Core/KerdlyCore.swift +557 -0
- package/ios/KerdlySDK/Core/Support.swift +95 -0
- package/ios/KerdlySDK/Logic/Backoff.swift +22 -0
- package/ios/KerdlySDK/Logic/Batch.swift +180 -0
- package/ios/KerdlySDK/Logic/Context.swift +85 -0
- package/ios/KerdlySDK/Logic/DeepLinks.swift +93 -0
- package/ios/KerdlySDK/Logic/DeferredLinks.swift +239 -0
- package/ios/KerdlySDK/Logic/Environment.swift +39 -0
- package/ios/KerdlySDK/Logic/EventQueue.swift +85 -0
- package/ios/KerdlySDK/Logic/EventValidator.swift +84 -0
- package/ios/KerdlySDK/Logic/Events.swift +102 -0
- package/ios/KerdlySDK/Logic/IPv6Address.swift +26 -0
- package/ios/KerdlySDK/Logic/InstallIdentity.swift +106 -0
- package/ios/KerdlySDK/Logic/JSONValue.swift +198 -0
- package/ios/KerdlySDK/Logic/Purchases.swift +84 -0
- package/ios/KerdlySDK/Logic/RemoteConfig.swift +185 -0
- package/ios/KerdlySDK/Logic/Skan.swift +343 -0
- package/ios/KerdlySDK/Logic/StandardEvents.swift +126 -0
- package/ios/KerdlySDK/Platform/AdSignals.swift +19 -0
- package/ios/KerdlySDK/Platform/DeferredLinkBundle.swift +25 -0
- package/ios/KerdlySDK/Platform/DeviceInfo.swift +82 -0
- package/ios/KerdlySDK/Platform/Lifecycle.swift +74 -0
- package/ios/KerdlySDK/Platform/PublicIp.swift +33 -0
- package/ios/KerdlySDK/Platform/SkanWriter.swift +70 -0
- package/ios/KerdlySDK/Platform/StoreKitAdapter.swift +185 -0
- package/ios/KerdlySDK/Platform/SystemStores.swift +200 -0
- package/ios/KerdlySDK/Platform/Tracking.swift +124 -0
- package/ios/KerdlySDK/Public/Kerdly.swift +202 -0
- package/ios/KerdlySDK/Public/KerdlyTypes.swift +130 -0
- package/ios/KerdlySDK/Resources/PrivacyInfo.xcprivacy +95 -0
- package/ios/KerdlySDK/Storage/PersistedState.swift +175 -0
- package/ios/KerdlySDK/Storage/StateStore.swift +36 -0
- package/ios/KerdlySdk.podspec +45 -0
- package/ios/KerdlySdkModule.swift +332 -0
- package/package.json +92 -4
- package/plugin/withKerdly.js +163 -0
- package/src/Kerdly.ts +524 -0
- package/src/index.ts +23 -0
- package/src/log.ts +49 -0
- package/src/native.ts +150 -0
- package/src/normalize.ts +82 -0
- package/src/types.ts +183 -0
- package/src/validation.ts +343 -0
- package/src/version.ts +5 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// Custom and standard event rules: the same rules the native SDKs apply before enqueue.
|
|
2
|
+
export const EVENT_NAME_PATTERN = /^[a-z][a-z0-9_]{0,39}$/;
|
|
3
|
+
export const PROP_KEY_PATTERN = /^[a-z][a-z0-9_]{0,39}$/;
|
|
4
|
+
export const MAX_PROPS = 25;
|
|
5
|
+
export const MAX_STRING_LENGTH = 256;
|
|
6
|
+
export const MAX_ID_LENGTH = 128;
|
|
7
|
+
export const MAX_METHOD_LENGTH = 64;
|
|
8
|
+
/** The native `Int` (32-bit on Android). */
|
|
9
|
+
export const MAX_QUANTITY = 2147483647;
|
|
10
|
+
const CURRENCY_PATTERN = /^[A-Z]{3}$/;
|
|
11
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12
|
+
export function isPlainObject(value) {
|
|
13
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
14
|
+
return false;
|
|
15
|
+
const proto = Object.getPrototypeOf(value);
|
|
16
|
+
return proto === Object.prototype || proto === null;
|
|
17
|
+
}
|
|
18
|
+
export function isUuid(value) {
|
|
19
|
+
return typeof value === 'string' && UUID_PATTERN.test(value);
|
|
20
|
+
}
|
|
21
|
+
/** Cuts to 256 UTF-16 units without leaving half of a surrogate pair at the end. */
|
|
22
|
+
export function truncate(value, max = MAX_STRING_LENGTH) {
|
|
23
|
+
if (value.length <= max)
|
|
24
|
+
return value;
|
|
25
|
+
let cut = value.slice(0, max);
|
|
26
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
27
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
28
|
+
cut = cut.slice(0, -1);
|
|
29
|
+
return cut;
|
|
30
|
+
}
|
|
31
|
+
function describe(value) {
|
|
32
|
+
if (value === null)
|
|
33
|
+
return 'null';
|
|
34
|
+
if (Array.isArray(value))
|
|
35
|
+
return 'array';
|
|
36
|
+
if (typeof value === 'number')
|
|
37
|
+
return String(value);
|
|
38
|
+
return typeof value;
|
|
39
|
+
}
|
|
40
|
+
function quoted(value) {
|
|
41
|
+
return typeof value === 'string' ? JSON.stringify(value) : describe(value);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validates a custom event. An invalid name drops the event. Invalid props are
|
|
45
|
+
* dropped one by one; props beyond the 25th valid one are dropped; strings are truncated to 256
|
|
46
|
+
* characters. `undefined` values are skipped silently, like JSON does.
|
|
47
|
+
*/
|
|
48
|
+
export function validateEvent(name, properties) {
|
|
49
|
+
const problems = [];
|
|
50
|
+
if (typeof name !== 'string' || !EVENT_NAME_PATTERN.test(name)) {
|
|
51
|
+
const shown = typeof name === 'string' ? JSON.stringify(name) : describe(name);
|
|
52
|
+
problems.push(typeof name === 'string' && name.startsWith('$')
|
|
53
|
+
? `event name ${shown} is reserved: "$" events are sent by the SDK itself`
|
|
54
|
+
: `event name ${shown} must match ${EVENT_NAME_PATTERN} (lowercase letters, digits, "_"; at most 40 characters)`);
|
|
55
|
+
return { event: null, problems };
|
|
56
|
+
}
|
|
57
|
+
if (properties !== undefined && properties !== null && !isPlainObject(properties)) {
|
|
58
|
+
problems.push(`properties must be a plain object, got ${describe(properties)}`);
|
|
59
|
+
return { event: null, problems };
|
|
60
|
+
}
|
|
61
|
+
return { event: { name, properties: cleanProperties(properties ?? {}, problems) }, problems };
|
|
62
|
+
}
|
|
63
|
+
/** The custom-event prop rules; what is dropped is appended to `problems`. */
|
|
64
|
+
function cleanProperties(properties, problems) {
|
|
65
|
+
const clean = {};
|
|
66
|
+
let count = 0;
|
|
67
|
+
const overflow = [];
|
|
68
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
69
|
+
if (value === undefined)
|
|
70
|
+
continue;
|
|
71
|
+
if (!PROP_KEY_PATTERN.test(key)) {
|
|
72
|
+
problems.push(`property key ${JSON.stringify(key)} must match ${PROP_KEY_PATTERN}`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let accepted;
|
|
76
|
+
if (typeof value === 'string') {
|
|
77
|
+
accepted = truncate(value);
|
|
78
|
+
}
|
|
79
|
+
else if (typeof value === 'number' && Number.isFinite(value)) {
|
|
80
|
+
accepted = value;
|
|
81
|
+
}
|
|
82
|
+
else if (typeof value === 'boolean') {
|
|
83
|
+
accepted = value;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
problems.push(`property "${key}" has an unsupported value (${describe(value)}): use a string, a finite number or a boolean`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (count >= MAX_PROPS) {
|
|
90
|
+
overflow.push(key);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
clean[key] = accepted;
|
|
94
|
+
count += 1;
|
|
95
|
+
}
|
|
96
|
+
if (overflow.length > 0) {
|
|
97
|
+
problems.push(`more than ${MAX_PROPS} properties; dropped ${overflow.map((k) => `"${k}"`).join(', ')}`);
|
|
98
|
+
}
|
|
99
|
+
return clean;
|
|
100
|
+
}
|
|
101
|
+
/** A non-empty string, or a safe integer turned into one (store ids are sometimes numbers). */
|
|
102
|
+
function idString(value) {
|
|
103
|
+
if (typeof value === 'string')
|
|
104
|
+
return value.length > 0 ? value : undefined;
|
|
105
|
+
if (typeof value === 'number' && Number.isSafeInteger(value))
|
|
106
|
+
return String(value);
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
function optionalString(value) {
|
|
110
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
111
|
+
}
|
|
112
|
+
/** The typed fields of each standard event. */
|
|
113
|
+
const STANDARD_FIELDS = {
|
|
114
|
+
trackRegistration: ['method'],
|
|
115
|
+
trackStartTrial: ['productId', 'value', 'currency', 'transactionId'],
|
|
116
|
+
trackSubscribe: ['productId', 'value', 'currency', 'transactionId'],
|
|
117
|
+
trackPurchase: ['productId', 'value', 'currency', 'quantity', 'transactionId'],
|
|
118
|
+
};
|
|
119
|
+
/** The wire prop each typed field becomes. */
|
|
120
|
+
const PROP_NAMES = {
|
|
121
|
+
method: 'method',
|
|
122
|
+
productId: 'product_id',
|
|
123
|
+
value: 'value',
|
|
124
|
+
currency: 'currency',
|
|
125
|
+
quantity: 'quantity',
|
|
126
|
+
transactionId: 'transaction_id',
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Validates a standard event's typed fields. A malformed field is dropped, not the
|
|
130
|
+
* event: ids are non-empty strings (a safe integer is turned into one) cut to 128 characters,
|
|
131
|
+
* `method` a non-empty string cut to 64, `value` a finite number ≥ 0, `currency` three letters
|
|
132
|
+
* (upper-cased), `quantity` an integer ≥ 1. `value` is dropped without a valid `currency`.
|
|
133
|
+
* `properties` follows the custom-event rules; a key that is one of the event's typed props is
|
|
134
|
+
* dropped (the typed field sets it). The native SDK checks everything again.
|
|
135
|
+
*/
|
|
136
|
+
export function validateStandardEvent(method, input) {
|
|
137
|
+
const problems = [];
|
|
138
|
+
if (input !== undefined && input !== null && !isPlainObject(input)) {
|
|
139
|
+
problems.push(`expected an object of fields, got ${describe(input)}`);
|
|
140
|
+
return { event: null, problems };
|
|
141
|
+
}
|
|
142
|
+
const given = isPlainObject(input) ? input : {};
|
|
143
|
+
const allowed = STANDARD_FIELDS[method];
|
|
144
|
+
const fields = {
|
|
145
|
+
method: null,
|
|
146
|
+
productId: null,
|
|
147
|
+
value: null,
|
|
148
|
+
currency: null,
|
|
149
|
+
quantity: null,
|
|
150
|
+
transactionId: null,
|
|
151
|
+
};
|
|
152
|
+
for (const [key, raw] of Object.entries(given)) {
|
|
153
|
+
if (raw === undefined || raw === null || key === 'properties')
|
|
154
|
+
continue;
|
|
155
|
+
if (!allowed.includes(key)) {
|
|
156
|
+
problems.push(`unknown field "${key}" (custom props go in \`properties\`)`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const field = key;
|
|
160
|
+
if (field === 'productId' || field === 'transactionId') {
|
|
161
|
+
const id = idString(raw);
|
|
162
|
+
if (id === undefined)
|
|
163
|
+
problems.push(`${field} must be a non-empty string, got ${quoted(raw)}`);
|
|
164
|
+
else
|
|
165
|
+
fields[field] = truncate(id, MAX_ID_LENGTH);
|
|
166
|
+
}
|
|
167
|
+
else if (field === 'method') {
|
|
168
|
+
const text = optionalString(raw);
|
|
169
|
+
if (text === undefined)
|
|
170
|
+
problems.push(`method must be a non-empty string, got ${quoted(raw)}`);
|
|
171
|
+
else
|
|
172
|
+
fields.method = truncate(text, MAX_METHOD_LENGTH);
|
|
173
|
+
}
|
|
174
|
+
else if (field === 'value') {
|
|
175
|
+
if (typeof raw === 'number' && Number.isFinite(raw) && raw >= 0)
|
|
176
|
+
fields.value = raw;
|
|
177
|
+
else
|
|
178
|
+
problems.push(`value must be a finite number ≥ 0, got ${quoted(raw)}`);
|
|
179
|
+
}
|
|
180
|
+
else if (field === 'currency') {
|
|
181
|
+
const code = typeof raw === 'string' ? raw.toUpperCase() : undefined;
|
|
182
|
+
if (code !== undefined && CURRENCY_PATTERN.test(code))
|
|
183
|
+
fields.currency = code;
|
|
184
|
+
else
|
|
185
|
+
problems.push(`currency must be a three-letter ISO 4217 code, got ${quoted(raw)}`);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
if (typeof raw === 'number' && Number.isInteger(raw) && raw >= 1 && raw <= MAX_QUANTITY)
|
|
189
|
+
fields.quantity = raw;
|
|
190
|
+
else
|
|
191
|
+
problems.push(`quantity must be an integer ≥ 1, got ${quoted(raw)}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (fields.value !== null && fields.currency === null) {
|
|
195
|
+
problems.push('value needs a valid currency, so it was dropped');
|
|
196
|
+
fields.value = null;
|
|
197
|
+
}
|
|
198
|
+
let properties = {};
|
|
199
|
+
const extra = given.properties;
|
|
200
|
+
if (extra !== undefined && extra !== null) {
|
|
201
|
+
if (!isPlainObject(extra)) {
|
|
202
|
+
problems.push(`properties must be a plain object, got ${describe(extra)}`);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
const custom = {};
|
|
206
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
207
|
+
const field = allowed.find((f) => PROP_NAMES[f] === key);
|
|
208
|
+
if (field === undefined)
|
|
209
|
+
custom[key] = value;
|
|
210
|
+
else if (value !== undefined)
|
|
211
|
+
problems.push(`property "${key}" is a typed prop: pass it as \`${field}\``);
|
|
212
|
+
}
|
|
213
|
+
properties = cleanProperties(custom, problems);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { event: { fields, properties }, problems };
|
|
217
|
+
}
|
|
218
|
+
const PURCHASE_ID_FIELDS = [
|
|
219
|
+
'originalTransactionId',
|
|
220
|
+
'transactionId',
|
|
221
|
+
'productId',
|
|
222
|
+
'purchaseToken',
|
|
223
|
+
'orderId',
|
|
224
|
+
];
|
|
225
|
+
const PURCHASE_STRING_FIELDS = ['obfuscatedAccountId', 'obfuscatedProfileId'];
|
|
226
|
+
/**
|
|
227
|
+
* Keeps the fields of either purchase shape that have the right type, so a malformed field can't
|
|
228
|
+
* make the native argument conversion reject the whole purchase. Returns `null` for a missing
|
|
229
|
+
* purchase (on iOS that means "sweep current entitlements").
|
|
230
|
+
*/
|
|
231
|
+
export function sanitizePurchase(purchase) {
|
|
232
|
+
const problems = [];
|
|
233
|
+
if (purchase === undefined || purchase === null)
|
|
234
|
+
return { purchase: null, problems };
|
|
235
|
+
if (!isPlainObject(purchase)) {
|
|
236
|
+
problems.push(`purchase must be an object, got ${describe(purchase)}`);
|
|
237
|
+
return { purchase: null, problems };
|
|
238
|
+
}
|
|
239
|
+
const out = {};
|
|
240
|
+
for (const field of PURCHASE_ID_FIELDS) {
|
|
241
|
+
const raw = purchase[field];
|
|
242
|
+
if (raw === undefined || raw === null)
|
|
243
|
+
continue;
|
|
244
|
+
const value = idString(raw);
|
|
245
|
+
if (value === undefined)
|
|
246
|
+
problems.push(`purchase.${field} must be a non-empty string`);
|
|
247
|
+
else
|
|
248
|
+
out[field] = value;
|
|
249
|
+
}
|
|
250
|
+
for (const field of PURCHASE_STRING_FIELDS) {
|
|
251
|
+
const raw = purchase[field];
|
|
252
|
+
if (raw === undefined || raw === null)
|
|
253
|
+
continue;
|
|
254
|
+
const value = optionalString(raw);
|
|
255
|
+
if (value === undefined)
|
|
256
|
+
problems.push(`purchase.${field} must be a non-empty string`);
|
|
257
|
+
else
|
|
258
|
+
out[field] = value;
|
|
259
|
+
}
|
|
260
|
+
const token = purchase.appAccountToken;
|
|
261
|
+
if (token !== undefined && token !== null) {
|
|
262
|
+
if (isUuid(token))
|
|
263
|
+
out.appAccountToken = token;
|
|
264
|
+
else
|
|
265
|
+
problems.push('purchase.appAccountToken must be a UUID string');
|
|
266
|
+
}
|
|
267
|
+
const products = purchase.products;
|
|
268
|
+
if (products !== undefined && products !== null) {
|
|
269
|
+
const list = typeof products === 'string' ? [products] : products;
|
|
270
|
+
if (Array.isArray(list)) {
|
|
271
|
+
const valid = list.filter((p) => typeof p === 'string' && p.length > 0);
|
|
272
|
+
if (valid.length !== list.length)
|
|
273
|
+
problems.push('purchase.products must contain only non-empty strings');
|
|
274
|
+
if (valid.length > 0)
|
|
275
|
+
out.products = valid;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
problems.push('purchase.products must be an array of strings');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const time = purchase.purchaseTime;
|
|
282
|
+
if (time !== undefined && time !== null) {
|
|
283
|
+
if (typeof time === 'number' && Number.isFinite(time) && time > 0)
|
|
284
|
+
out.purchaseTime = Math.round(time);
|
|
285
|
+
else
|
|
286
|
+
problems.push('purchase.purchaseTime must be milliseconds since epoch');
|
|
287
|
+
}
|
|
288
|
+
return { purchase: out, problems };
|
|
289
|
+
}
|
|
290
|
+
/** `null` when `network` or `event` is missing; optional fields with the wrong type are dropped. */
|
|
291
|
+
export function sanitizeNetworkSend(send) {
|
|
292
|
+
const problems = [];
|
|
293
|
+
if (!isPlainObject(send)) {
|
|
294
|
+
problems.push(`recordNetworkSend needs an object, got ${describe(send)}`);
|
|
295
|
+
return { send: null, problems };
|
|
296
|
+
}
|
|
297
|
+
const network = optionalString(send.network);
|
|
298
|
+
const event = optionalString(send.event);
|
|
299
|
+
if (network === undefined || event === undefined) {
|
|
300
|
+
problems.push('recordNetworkSend needs non-empty `network` and `event` strings');
|
|
301
|
+
return { send: null, problems };
|
|
302
|
+
}
|
|
303
|
+
const out = { network, event };
|
|
304
|
+
const eventId = send.eventId;
|
|
305
|
+
if (eventId !== undefined && eventId !== null) {
|
|
306
|
+
const value = idString(eventId);
|
|
307
|
+
if (value === undefined)
|
|
308
|
+
problems.push('eventId must be a non-empty string');
|
|
309
|
+
else
|
|
310
|
+
out.eventId = value;
|
|
311
|
+
}
|
|
312
|
+
const value = send.value;
|
|
313
|
+
if (value !== undefined && value !== null) {
|
|
314
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
315
|
+
out.value = value;
|
|
316
|
+
else
|
|
317
|
+
problems.push('value must be a finite number');
|
|
318
|
+
}
|
|
319
|
+
for (const field of ['currency', 'flag']) {
|
|
320
|
+
const raw = send[field];
|
|
321
|
+
if (raw === undefined || raw === null)
|
|
322
|
+
continue;
|
|
323
|
+
const str = optionalString(raw);
|
|
324
|
+
if (str === undefined)
|
|
325
|
+
problems.push(`${field} must be a non-empty string`);
|
|
326
|
+
else
|
|
327
|
+
out[field] = str;
|
|
328
|
+
}
|
|
329
|
+
return { send: out, problems };
|
|
330
|
+
}
|
|
331
|
+
/** Keeps the string -> string entries of a partner id map. */
|
|
332
|
+
export function sanitizePartnerIds(ids) {
|
|
333
|
+
const problems = [];
|
|
334
|
+
if (!isPlainObject(ids)) {
|
|
335
|
+
problems.push(`setPartnerIds needs an object of strings, got ${describe(ids)}`);
|
|
336
|
+
return { ids: null, problems };
|
|
337
|
+
}
|
|
338
|
+
const out = {};
|
|
339
|
+
for (const [key, value] of Object.entries(ids)) {
|
|
340
|
+
if (value === undefined)
|
|
341
|
+
continue;
|
|
342
|
+
if (typeof value === 'string' && key.length > 0)
|
|
343
|
+
out[key] = value;
|
|
344
|
+
else
|
|
345
|
+
problems.push(`partner id "${key}" must be a string, got ${describe(value)}`);
|
|
346
|
+
}
|
|
347
|
+
return { ids: out, problems };
|
|
348
|
+
}
|
|
349
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAGA,wFAAwF;AACxF,MAAM,CAAC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAC3D,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AACzD,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAC5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,4CAA4C;AAC5C,MAAM,CAAC,MAAM,YAAY,GAAG,UAAa,CAAC;AAC1C,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC,MAAM,YAAY,GAAG,iEAAiE,CAAC;AAEvF,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KA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AC,iDAAiD,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChF,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjC,CAAC;IACD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;;YAC7D,QAAQ,CAAC,IAAI,CAAC,eAAe,GAAG,2BAA2B,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,8GAA8G;AAC9G,eAAO,MAAM,OAAO,eAAwB,CAAC"}
|
package/build/version.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Must equal "version" in package.json (test/version.test.ts enforces it).
|
|
2
|
+
export const SDK_VERSION = '0.1.0';
|
|
3
|
+
/** Passed to the native SDKs as `KerdlyOptions.wrapper`; they send it in `X-Kerdly-Sdk` and `sdk.wrapper`. */
|
|
4
|
+
export const WRAPPER = `expo/${SDK_VERSION}`;
|
|
5
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC,8GAA8G;AAC9G,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
// The seams between the SDK's logic and the system. Each protocol is small; the system
|
|
4
|
+
// implementations live in Platform/, the tests' fakes in Tests/KerdlySDKTests/Support/.
|
|
5
|
+
|
|
6
|
+
/// The Keychain copy of the install id (service `com.kerdly.sdk`, account `install_id`).
|
|
7
|
+
protocol KeychainStoring: Sendable {
|
|
8
|
+
func readInstallId() -> KeychainRead
|
|
9
|
+
func writeInstallId(_ id: String) -> Bool
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/// The standard UserDefaults suite.
|
|
13
|
+
protocol DefaultsStoring: Sendable {
|
|
14
|
+
func string(forKey key: String) -> String?
|
|
15
|
+
func bool(forKey key: String) -> Bool
|
|
16
|
+
func set(_ value: String?, forKey key: String)
|
|
17
|
+
func set(_ value: Bool, forKey key: String)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// The SDK's own files (`Application Support/kerdly/`). Writes are atomic.
|
|
21
|
+
protocol FileStoring: Sendable {
|
|
22
|
+
func read(_ name: String) -> Data?
|
|
23
|
+
@discardableResult func write(_ data: Data, to name: String) -> Bool
|
|
24
|
+
func remove(_ name: String)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
struct HTTPRequest: Equatable, Sendable {
|
|
28
|
+
var method: String
|
|
29
|
+
var url: URL
|
|
30
|
+
var headers: [String: String]
|
|
31
|
+
var body: Data?
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
enum HTTPResult: Equatable, Sendable {
|
|
35
|
+
/// Header names are lowercased.
|
|
36
|
+
case response(status: Int, headers: [String: String], body: Data)
|
|
37
|
+
case failure(String)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protocol HTTPTransport: Sendable {
|
|
41
|
+
func send(_ request: HTTPRequest, completion: @escaping @Sendable (HTTPResult) -> Void)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protocol Clock: Sendable {
|
|
45
|
+
func now() -> Date
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Main-bundle, file-system and UIKit facts.
|
|
49
|
+
protocol DeviceInfoProviding: Sendable {
|
|
50
|
+
func appInfo() -> AppInfo
|
|
51
|
+
func facts() -> DeviceFacts
|
|
52
|
+
/// UIKit reads: idfv, screen, application state. Main thread only.
|
|
53
|
+
@MainActor func snapshot() -> DeviceSnapshot
|
|
54
|
+
/// The Documents directory's creation date.
|
|
55
|
+
func installedAt() -> Date?
|
|
56
|
+
func environmentInputs() -> EnvironmentInputs
|
|
57
|
+
/// The bundle's Facebook config and URL schemes, for deferred deep links.
|
|
58
|
+
func deferredLinkBundle() -> DeferredLinkBundle
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// App Tracking Transparency.
|
|
62
|
+
protocol TrackingAuthorizing: Sendable {
|
|
63
|
+
func status() -> KerdlyAttStatus
|
|
64
|
+
/// Whether the app declares `NSUserTrackingUsageDescription` (without it, iOS terminates an app
|
|
65
|
+
/// that asks).
|
|
66
|
+
func canPrompt() -> Bool
|
|
67
|
+
/// `ATTrackingManager.requestTrackingAuthorization`; call on the main thread, while active.
|
|
68
|
+
func request(_ completion: @escaping @Sendable (KerdlyAttStatus) -> Void)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// `AAAttribution.attributionToken()`; blocking, call off the main thread.
|
|
72
|
+
protocol AdServicesTokenProviding: Sendable {
|
|
73
|
+
func attributionToken() throws -> String
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// The IDFA; nil when unavailable or all zeros.
|
|
77
|
+
protocol AdvertisingIdProviding: Sendable {
|
|
78
|
+
func advertisingId() -> String?
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// The IPv6 echo: one `GET` answering `{"ip": "…"}`.
|
|
82
|
+
protocol PublicIpProviding: Sendable {
|
|
83
|
+
/// Completes with the answer's `ip` as given, or nil on an error, a timeout or another body.
|
|
84
|
+
func lookup(_ url: URL, completion: @escaping @Sendable (String?) -> Void)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// The AppTransaction signal's fields (`app_transaction`).
|
|
88
|
+
struct AppTransactionInfo: Equatable, Sendable {
|
|
89
|
+
var jws: String
|
|
90
|
+
var appTransactionId: String?
|
|
91
|
+
var originalPurchaseDate: Date
|
|
92
|
+
var originalAppVersion: String
|
|
93
|
+
var environment: String
|
|
94
|
+
var deviceVerificationNonce: String
|
|
95
|
+
var deviceVerification: String
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protocol StoreKitProviding: Sendable {
|
|
99
|
+
/// `AppTransaction.shared` (iOS 16+). Never `refresh()`. Fails with a reason on older systems.
|
|
100
|
+
func appTransaction(_ completion: @escaping @Sendable (Result<AppTransactionInfo, KerdlyAdapterError>) -> Void)
|
|
101
|
+
/// Verified `Transaction.currentEntitlements`.
|
|
102
|
+
func currentEntitlements(_ completion: @escaping @Sendable ([PurchaseInfo]) -> Void)
|
|
103
|
+
/// The verified transaction a paywall notify refers to, if StoreKit has it.
|
|
104
|
+
func findTransaction(transactionId: String?, originalTransactionId: String?, productId: String?,
|
|
105
|
+
_ completion: @escaping @Sendable (PurchaseInfo?) -> Void)
|
|
106
|
+
/// Starts listening to `Transaction.updates` (verified only) for the life of the process.
|
|
107
|
+
func observeUpdates(_ handler: @escaping @Sendable (PurchaseInfo) -> Void)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
enum LifecycleEvent: Equatable, Sendable {
|
|
111
|
+
case willEnterForeground
|
|
112
|
+
case didBecomeActive
|
|
113
|
+
case didEnterBackground
|
|
114
|
+
case protectedDataAvailable
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protocol LifecycleObserving: Sendable {
|
|
118
|
+
/// Delivers UIApplication notifications (on the main thread) for the life of the process.
|
|
119
|
+
func observe(_ handler: @escaping @Sendable (LifecycleEvent) -> Void)
|
|
120
|
+
/// Asks iOS for time to finish a flush after going to the background; returns a token for `end`.
|
|
121
|
+
func beginBackgroundTask() -> Int?
|
|
122
|
+
func endBackgroundTask(_ token: Int)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// A cancellable delayed task.
|
|
126
|
+
protocol Cancellable: Sendable {
|
|
127
|
+
func cancel()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
protocol Scheduling: Sendable {
|
|
131
|
+
/// Runs `work` on the SDK's queue after `delay` seconds.
|
|
132
|
+
@discardableResult
|
|
133
|
+
func schedule(after delay: TimeInterval, _ work: @escaping @Sendable () -> Void) -> Cancellable
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
struct KerdlyAdapterError: Error, Equatable, Sendable, CustomStringConvertible {
|
|
137
|
+
let description: String
|
|
138
|
+
init(_ description: String) { self.description = description }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Everything `KerdlyCore` talks to.
|
|
142
|
+
struct KerdlyDependencies: Sendable {
|
|
143
|
+
var keychain: KeychainStoring
|
|
144
|
+
var defaults: DefaultsStoring
|
|
145
|
+
var files: FileStoring
|
|
146
|
+
var transport: HTTPTransport
|
|
147
|
+
var clock: Clock
|
|
148
|
+
var device: DeviceInfoProviding
|
|
149
|
+
var tracking: TrackingAuthorizing
|
|
150
|
+
var adServices: AdServicesTokenProviding
|
|
151
|
+
var advertisingId: AdvertisingIdProviding
|
|
152
|
+
var publicIp: PublicIpProviding
|
|
153
|
+
var storeKit: StoreKitProviding
|
|
154
|
+
var skanWriter: SkanWriting
|
|
155
|
+
var lifecycle: LifecycleObserving
|
|
156
|
+
/// Builds the scheduler for the SDK's queue.
|
|
157
|
+
var makeScheduler: @Sendable (DispatchQueue) -> Scheduling
|
|
158
|
+
/// A queue for blocking system calls (the AdServices token, the IDFA) and the IPv6 lookup.
|
|
159
|
+
var workQueue: DispatchQueue
|
|
160
|
+
var newId: @Sendable () -> String
|
|
161
|
+
/// A value in [0, 1] for back-off jitter.
|
|
162
|
+
var unitRandom: @Sendable () -> Double
|
|
163
|
+
}
|