@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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -2
  3. package/android/build.gradle +61 -0
  4. package/android/src/main/AndroidManifest.xml +19 -0
  5. package/android/src/main/java/com/kerdly/expo/KerdlySdkModule.kt +326 -0
  6. package/android/vendor/kerdly-sdk/.kerdly-sync.json +8 -0
  7. package/android/vendor/kerdly-sdk/consumer-rules.pro +15 -0
  8. package/android/vendor/kerdly-sdk/kerdly-sdk.properties +2 -0
  9. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/Kerdly.kt +343 -0
  10. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/KerdlyTypes.kt +89 -0
  11. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Attribution.kt +39 -0
  12. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Batch.kt +159 -0
  13. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Core.kt +991 -0
  14. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeepLinks.kt +114 -0
  15. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeferredLinks.kt +111 -0
  16. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeviceContext.kt +137 -0
  17. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/EventQueue.kt +135 -0
  18. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Events.kt +314 -0
  19. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Json.kt +116 -0
  20. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Logger.kt +49 -0
  21. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Options.kt +47 -0
  22. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Ports.kt +83 -0
  23. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/PublicIp.kt +120 -0
  24. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Referrers.kt +137 -0
  25. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/RemoteConfig.kt +100 -0
  26. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Storage.kt +271 -0
  27. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidPlatform.kt +274 -0
  28. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidRuntime.kt +187 -0
  29. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/PlayReferrerReader.kt +97 -0
  30. package/app.plugin.js +2 -0
  31. package/build/Kerdly.d.ts +106 -0
  32. package/build/Kerdly.d.ts.map +1 -0
  33. package/build/Kerdly.js +494 -0
  34. package/build/Kerdly.js.map +1 -0
  35. package/build/index.d.ts +4 -0
  36. package/build/index.d.ts.map +1 -0
  37. package/build/index.js +2 -0
  38. package/build/index.js.map +1 -0
  39. package/build/log.d.ts +13 -0
  40. package/build/log.d.ts.map +1 -0
  41. package/build/log.js +45 -0
  42. package/build/log.js.map +1 -0
  43. package/build/native.d.ts +74 -0
  44. package/build/native.d.ts.map +1 -0
  45. package/build/native.js +56 -0
  46. package/build/native.js.map +1 -0
  47. package/build/normalize.d.ts +8 -0
  48. package/build/normalize.d.ts.map +1 -0
  49. package/build/normalize.js +86 -0
  50. package/build/normalize.js.map +1 -0
  51. package/build/types.d.ts +134 -0
  52. package/build/types.d.ts.map +1 -0
  53. package/build/types.js +3 -0
  54. package/build/types.js.map +1 -0
  55. package/build/validation.d.ts +70 -0
  56. package/build/validation.d.ts.map +1 -0
  57. package/build/validation.js +349 -0
  58. package/build/validation.js.map +1 -0
  59. package/build/version.d.ts +4 -0
  60. package/build/version.d.ts.map +1 -0
  61. package/build/version.js +5 -0
  62. package/build/version.js.map +1 -0
  63. package/expo-module.config.json +9 -0
  64. package/ios/KerdlySDK/.kerdly-sync.json +7 -0
  65. package/ios/KerdlySDK/Core/Dependencies.swift +163 -0
  66. package/ios/KerdlySDK/Core/KerdlyCore+API.swift +117 -0
  67. package/ios/KerdlySDK/Core/KerdlyCore+Collectors.swift +410 -0
  68. package/ios/KerdlySDK/Core/KerdlyCore+DeferredLinks.swift +220 -0
  69. package/ios/KerdlySDK/Core/KerdlyCore+Delivery.swift +424 -0
  70. package/ios/KerdlySDK/Core/KerdlyCore.swift +557 -0
  71. package/ios/KerdlySDK/Core/Support.swift +95 -0
  72. package/ios/KerdlySDK/Logic/Backoff.swift +22 -0
  73. package/ios/KerdlySDK/Logic/Batch.swift +180 -0
  74. package/ios/KerdlySDK/Logic/Context.swift +85 -0
  75. package/ios/KerdlySDK/Logic/DeepLinks.swift +93 -0
  76. package/ios/KerdlySDK/Logic/DeferredLinks.swift +239 -0
  77. package/ios/KerdlySDK/Logic/Environment.swift +39 -0
  78. package/ios/KerdlySDK/Logic/EventQueue.swift +85 -0
  79. package/ios/KerdlySDK/Logic/EventValidator.swift +84 -0
  80. package/ios/KerdlySDK/Logic/Events.swift +102 -0
  81. package/ios/KerdlySDK/Logic/IPv6Address.swift +26 -0
  82. package/ios/KerdlySDK/Logic/InstallIdentity.swift +106 -0
  83. package/ios/KerdlySDK/Logic/JSONValue.swift +198 -0
  84. package/ios/KerdlySDK/Logic/Purchases.swift +84 -0
  85. package/ios/KerdlySDK/Logic/RemoteConfig.swift +185 -0
  86. package/ios/KerdlySDK/Logic/Skan.swift +343 -0
  87. package/ios/KerdlySDK/Logic/StandardEvents.swift +126 -0
  88. package/ios/KerdlySDK/Platform/AdSignals.swift +19 -0
  89. package/ios/KerdlySDK/Platform/DeferredLinkBundle.swift +25 -0
  90. package/ios/KerdlySDK/Platform/DeviceInfo.swift +82 -0
  91. package/ios/KerdlySDK/Platform/Lifecycle.swift +74 -0
  92. package/ios/KerdlySDK/Platform/PublicIp.swift +33 -0
  93. package/ios/KerdlySDK/Platform/SkanWriter.swift +70 -0
  94. package/ios/KerdlySDK/Platform/StoreKitAdapter.swift +185 -0
  95. package/ios/KerdlySDK/Platform/SystemStores.swift +200 -0
  96. package/ios/KerdlySDK/Platform/Tracking.swift +124 -0
  97. package/ios/KerdlySDK/Public/Kerdly.swift +202 -0
  98. package/ios/KerdlySDK/Public/KerdlyTypes.swift +130 -0
  99. package/ios/KerdlySDK/Resources/PrivacyInfo.xcprivacy +95 -0
  100. package/ios/KerdlySDK/Storage/PersistedState.swift +175 -0
  101. package/ios/KerdlySDK/Storage/StateStore.swift +36 -0
  102. package/ios/KerdlySdk.podspec +45 -0
  103. package/ios/KerdlySdkModule.swift +332 -0
  104. package/package.json +92 -4
  105. package/plugin/withKerdly.js +163 -0
  106. package/src/Kerdly.ts +524 -0
  107. package/src/index.ts +23 -0
  108. package/src/log.ts +49 -0
  109. package/src/native.ts +150 -0
  110. package/src/normalize.ts +82 -0
  111. package/src/types.ts +183 -0
  112. package/src/validation.ts +343 -0
  113. package/src/version.ts +5 -0
@@ -0,0 +1,343 @@
1
+ import type { NativeNetworkSend, NativePurchase } from './native';
2
+ import type { KerdlyEventValue } from './types';
3
+
4
+ // Custom and standard event rules: the same rules the native SDKs apply before enqueue.
5
+ export const EVENT_NAME_PATTERN = /^[a-z][a-z0-9_]{0,39}$/;
6
+ export const PROP_KEY_PATTERN = /^[a-z][a-z0-9_]{0,39}$/;
7
+ export const MAX_PROPS = 25;
8
+ export const MAX_STRING_LENGTH = 256;
9
+ export const MAX_ID_LENGTH = 128;
10
+ export const MAX_METHOD_LENGTH = 64;
11
+ /** The native `Int` (32-bit on Android). */
12
+ export const MAX_QUANTITY = 2_147_483_647;
13
+ const CURRENCY_PATTERN = /^[A-Z]{3}$/;
14
+
15
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
16
+
17
+ export function isPlainObject(value: unknown): value is Record<string, unknown> {
18
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
19
+ const proto = Object.getPrototypeOf(value);
20
+ return proto === Object.prototype || proto === null;
21
+ }
22
+
23
+ export function isUuid(value: unknown): value is string {
24
+ return typeof value === 'string' && UUID_PATTERN.test(value);
25
+ }
26
+
27
+ /** Cuts to 256 UTF-16 units without leaving half of a surrogate pair at the end. */
28
+ export function truncate(value: string, max = MAX_STRING_LENGTH): string {
29
+ if (value.length <= max) return value;
30
+ let cut = value.slice(0, max);
31
+ const last = cut.charCodeAt(cut.length - 1);
32
+ if (last >= 0xd800 && last <= 0xdbff) cut = cut.slice(0, -1);
33
+ return cut;
34
+ }
35
+
36
+ function describe(value: unknown): string {
37
+ if (value === null) return 'null';
38
+ if (Array.isArray(value)) return 'array';
39
+ if (typeof value === 'number') return String(value);
40
+ return typeof value;
41
+ }
42
+
43
+ function quoted(value: unknown): string {
44
+ return typeof value === 'string' ? JSON.stringify(value) : describe(value);
45
+ }
46
+
47
+ export interface EventValidation {
48
+ /** `null` when the event must be dropped (invalid name or props argument). */
49
+ event: { name: string; properties: Record<string, KerdlyEventValue> } | null;
50
+ /** Human-readable reasons for everything that was dropped. */
51
+ problems: string[];
52
+ }
53
+
54
+ /**
55
+ * Validates a custom event. An invalid name drops the event. Invalid props are
56
+ * dropped one by one; props beyond the 25th valid one are dropped; strings are truncated to 256
57
+ * characters. `undefined` values are skipped silently, like JSON does.
58
+ */
59
+ export function validateEvent(name: unknown, properties: unknown): EventValidation {
60
+ const problems: string[] = [];
61
+ if (typeof name !== 'string' || !EVENT_NAME_PATTERN.test(name)) {
62
+ const shown = typeof name === 'string' ? JSON.stringify(name) : describe(name);
63
+ problems.push(
64
+ typeof name === 'string' && name.startsWith('$')
65
+ ? `event name ${shown} is reserved: "$" events are sent by the SDK itself`
66
+ : `event name ${shown} must match ${EVENT_NAME_PATTERN} (lowercase letters, digits, "_"; at most 40 characters)`
67
+ );
68
+ return { event: null, problems };
69
+ }
70
+ if (properties !== undefined && properties !== null && !isPlainObject(properties)) {
71
+ problems.push(`properties must be a plain object, got ${describe(properties)}`);
72
+ return { event: null, problems };
73
+ }
74
+ return { event: { name, properties: cleanProperties(properties ?? {}, problems) }, problems };
75
+ }
76
+
77
+ /** The custom-event prop rules; what is dropped is appended to `problems`. */
78
+ function cleanProperties(properties: Record<string, unknown>, problems: string[]): Record<string, KerdlyEventValue> {
79
+ const clean: Record<string, KerdlyEventValue> = {};
80
+ let count = 0;
81
+ const overflow: string[] = [];
82
+ for (const [key, value] of Object.entries(properties)) {
83
+ if (value === undefined) continue;
84
+ if (!PROP_KEY_PATTERN.test(key)) {
85
+ problems.push(`property key ${JSON.stringify(key)} must match ${PROP_KEY_PATTERN}`);
86
+ continue;
87
+ }
88
+ let accepted: KerdlyEventValue;
89
+ if (typeof value === 'string') {
90
+ accepted = truncate(value);
91
+ } else if (typeof value === 'number' && Number.isFinite(value)) {
92
+ accepted = value;
93
+ } else if (typeof value === 'boolean') {
94
+ accepted = value;
95
+ } else {
96
+ problems.push(
97
+ `property "${key}" has an unsupported value (${describe(value)}): use a string, a finite number or a boolean`
98
+ );
99
+ continue;
100
+ }
101
+ if (count >= MAX_PROPS) {
102
+ overflow.push(key);
103
+ continue;
104
+ }
105
+ clean[key] = accepted;
106
+ count += 1;
107
+ }
108
+ if (overflow.length > 0) {
109
+ problems.push(`more than ${MAX_PROPS} properties; dropped ${overflow.map((k) => `"${k}"`).join(', ')}`);
110
+ }
111
+ return clean;
112
+ }
113
+
114
+ /** A non-empty string, or a safe integer turned into one (store ids are sometimes numbers). */
115
+ function idString(value: unknown): string | undefined {
116
+ if (typeof value === 'string') return value.length > 0 ? value : undefined;
117
+ if (typeof value === 'number' && Number.isSafeInteger(value)) return String(value);
118
+ return undefined;
119
+ }
120
+
121
+ function optionalString(value: unknown): string | undefined {
122
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
123
+ }
124
+
125
+ export type StandardEventMethod = 'trackRegistration' | 'trackStartTrial' | 'trackSubscribe' | 'trackPurchase';
126
+
127
+ type StandardField = 'method' | 'productId' | 'value' | 'currency' | 'quantity' | 'transactionId';
128
+
129
+ /** The typed fields of each standard event. */
130
+ const STANDARD_FIELDS: Record<StandardEventMethod, readonly StandardField[]> = {
131
+ trackRegistration: ['method'],
132
+ trackStartTrial: ['productId', 'value', 'currency', 'transactionId'],
133
+ trackSubscribe: ['productId', 'value', 'currency', 'transactionId'],
134
+ trackPurchase: ['productId', 'value', 'currency', 'quantity', 'transactionId'],
135
+ };
136
+
137
+ /** The wire prop each typed field becomes. */
138
+ const PROP_NAMES: Record<StandardField, string> = {
139
+ method: 'method',
140
+ productId: 'product_id',
141
+ value: 'value',
142
+ currency: 'currency',
143
+ quantity: 'quantity',
144
+ transactionId: 'transaction_id',
145
+ };
146
+
147
+ /** The typed fields after validation; `null` = omitted (fields an event does not have stay `null`). */
148
+ export type StandardFields = Record<'method' | 'productId' | 'currency' | 'transactionId', string | null> &
149
+ Record<'value' | 'quantity', number | null>;
150
+
151
+ export interface StandardEventValidation {
152
+ /** `null` when the event must be dropped (the argument is not an object). */
153
+ event: { fields: StandardFields; properties: Record<string, KerdlyEventValue> } | null;
154
+ /** Human-readable reasons for everything that was dropped. */
155
+ problems: string[];
156
+ }
157
+
158
+ /**
159
+ * Validates a standard event's typed fields. A malformed field is dropped, not the
160
+ * event: ids are non-empty strings (a safe integer is turned into one) cut to 128 characters,
161
+ * `method` a non-empty string cut to 64, `value` a finite number ≥ 0, `currency` three letters
162
+ * (upper-cased), `quantity` an integer ≥ 1. `value` is dropped without a valid `currency`.
163
+ * `properties` follows the custom-event rules; a key that is one of the event's typed props is
164
+ * dropped (the typed field sets it). The native SDK checks everything again.
165
+ */
166
+ export function validateStandardEvent(method: StandardEventMethod, input: unknown): StandardEventValidation {
167
+ const problems: string[] = [];
168
+ if (input !== undefined && input !== null && !isPlainObject(input)) {
169
+ problems.push(`expected an object of fields, got ${describe(input)}`);
170
+ return { event: null, problems };
171
+ }
172
+ const given: Record<string, unknown> = isPlainObject(input) ? input : {};
173
+ const allowed = STANDARD_FIELDS[method];
174
+ const fields: StandardFields = {
175
+ method: null,
176
+ productId: null,
177
+ value: null,
178
+ currency: null,
179
+ quantity: null,
180
+ transactionId: null,
181
+ };
182
+
183
+ for (const [key, raw] of Object.entries(given)) {
184
+ if (raw === undefined || raw === null || key === 'properties') continue;
185
+ if (!(allowed as readonly string[]).includes(key)) {
186
+ problems.push(`unknown field "${key}" (custom props go in \`properties\`)`);
187
+ continue;
188
+ }
189
+ const field = key as StandardField;
190
+ if (field === 'productId' || field === 'transactionId') {
191
+ const id = idString(raw);
192
+ if (id === undefined) problems.push(`${field} must be a non-empty string, got ${quoted(raw)}`);
193
+ else fields[field] = truncate(id, MAX_ID_LENGTH);
194
+ } else if (field === 'method') {
195
+ const text = optionalString(raw);
196
+ if (text === undefined) problems.push(`method must be a non-empty string, got ${quoted(raw)}`);
197
+ else fields.method = truncate(text, MAX_METHOD_LENGTH);
198
+ } else if (field === 'value') {
199
+ if (typeof raw === 'number' && Number.isFinite(raw) && raw >= 0) fields.value = raw;
200
+ else problems.push(`value must be a finite number ≥ 0, got ${quoted(raw)}`);
201
+ } else if (field === 'currency') {
202
+ const code = typeof raw === 'string' ? raw.toUpperCase() : undefined;
203
+ if (code !== undefined && CURRENCY_PATTERN.test(code)) fields.currency = code;
204
+ else problems.push(`currency must be a three-letter ISO 4217 code, got ${quoted(raw)}`);
205
+ } else {
206
+ if (typeof raw === 'number' && Number.isInteger(raw) && raw >= 1 && raw <= MAX_QUANTITY) fields.quantity = raw;
207
+ else problems.push(`quantity must be an integer ≥ 1, got ${quoted(raw)}`);
208
+ }
209
+ }
210
+ if (fields.value !== null && fields.currency === null) {
211
+ problems.push('value needs a valid currency, so it was dropped');
212
+ fields.value = null;
213
+ }
214
+
215
+ let properties: Record<string, KerdlyEventValue> = {};
216
+ const extra = given.properties;
217
+ if (extra !== undefined && extra !== null) {
218
+ if (!isPlainObject(extra)) {
219
+ problems.push(`properties must be a plain object, got ${describe(extra)}`);
220
+ } else {
221
+ const custom: Record<string, unknown> = {};
222
+ for (const [key, value] of Object.entries(extra)) {
223
+ const field = allowed.find((f) => PROP_NAMES[f] === key);
224
+ if (field === undefined) custom[key] = value;
225
+ else if (value !== undefined) problems.push(`property "${key}" is a typed prop: pass it as \`${field}\``);
226
+ }
227
+ properties = cleanProperties(custom, problems);
228
+ }
229
+ }
230
+ return { event: { fields, properties }, problems };
231
+ }
232
+
233
+ const PURCHASE_ID_FIELDS = [
234
+ 'originalTransactionId',
235
+ 'transactionId',
236
+ 'productId',
237
+ 'purchaseToken',
238
+ 'orderId',
239
+ ] as const;
240
+
241
+ const PURCHASE_STRING_FIELDS = ['obfuscatedAccountId', 'obfuscatedProfileId'] as const;
242
+
243
+ /**
244
+ * Keeps the fields of either purchase shape that have the right type, so a malformed field can't
245
+ * make the native argument conversion reject the whole purchase. Returns `null` for a missing
246
+ * purchase (on iOS that means "sweep current entitlements").
247
+ */
248
+ export function sanitizePurchase(purchase: unknown): { purchase: NativePurchase | null; problems: string[] } {
249
+ const problems: string[] = [];
250
+ if (purchase === undefined || purchase === null) return { purchase: null, problems };
251
+ if (!isPlainObject(purchase)) {
252
+ problems.push(`purchase must be an object, got ${describe(purchase)}`);
253
+ return { purchase: null, problems };
254
+ }
255
+ const out: NativePurchase = {};
256
+ for (const field of PURCHASE_ID_FIELDS) {
257
+ const raw = purchase[field];
258
+ if (raw === undefined || raw === null) continue;
259
+ const value = idString(raw);
260
+ if (value === undefined) problems.push(`purchase.${field} must be a non-empty string`);
261
+ else out[field] = value;
262
+ }
263
+ for (const field of PURCHASE_STRING_FIELDS) {
264
+ const raw = purchase[field];
265
+ if (raw === undefined || raw === null) continue;
266
+ const value = optionalString(raw);
267
+ if (value === undefined) problems.push(`purchase.${field} must be a non-empty string`);
268
+ else out[field] = value;
269
+ }
270
+ const token = purchase.appAccountToken;
271
+ if (token !== undefined && token !== null) {
272
+ if (isUuid(token)) out.appAccountToken = token;
273
+ else problems.push('purchase.appAccountToken must be a UUID string');
274
+ }
275
+ const products = purchase.products;
276
+ if (products !== undefined && products !== null) {
277
+ const list = typeof products === 'string' ? [products] : products;
278
+ if (Array.isArray(list)) {
279
+ const valid = list.filter((p): p is string => typeof p === 'string' && p.length > 0);
280
+ if (valid.length !== list.length) problems.push('purchase.products must contain only non-empty strings');
281
+ if (valid.length > 0) out.products = valid;
282
+ } else {
283
+ problems.push('purchase.products must be an array of strings');
284
+ }
285
+ }
286
+ const time = purchase.purchaseTime;
287
+ if (time !== undefined && time !== null) {
288
+ if (typeof time === 'number' && Number.isFinite(time) && time > 0) out.purchaseTime = Math.round(time);
289
+ else problems.push('purchase.purchaseTime must be milliseconds since epoch');
290
+ }
291
+ return { purchase: out, problems };
292
+ }
293
+
294
+ /** `null` when `network` or `event` is missing; optional fields with the wrong type are dropped. */
295
+ export function sanitizeNetworkSend(send: unknown): { send: NativeNetworkSend | null; problems: string[] } {
296
+ const problems: string[] = [];
297
+ if (!isPlainObject(send)) {
298
+ problems.push(`recordNetworkSend needs an object, got ${describe(send)}`);
299
+ return { send: null, problems };
300
+ }
301
+ const network = optionalString(send.network);
302
+ const event = optionalString(send.event);
303
+ if (network === undefined || event === undefined) {
304
+ problems.push('recordNetworkSend needs non-empty `network` and `event` strings');
305
+ return { send: null, problems };
306
+ }
307
+ const out: NativeNetworkSend = { network, event };
308
+ const eventId = send.eventId;
309
+ if (eventId !== undefined && eventId !== null) {
310
+ const value = idString(eventId);
311
+ if (value === undefined) problems.push('eventId must be a non-empty string');
312
+ else out.eventId = value;
313
+ }
314
+ const value = send.value;
315
+ if (value !== undefined && value !== null) {
316
+ if (typeof value === 'number' && Number.isFinite(value)) out.value = value;
317
+ else problems.push('value must be a finite number');
318
+ }
319
+ for (const field of ['currency', 'flag'] as const) {
320
+ const raw = send[field];
321
+ if (raw === undefined || raw === null) continue;
322
+ const str = optionalString(raw);
323
+ if (str === undefined) problems.push(`${field} must be a non-empty string`);
324
+ else out[field] = str;
325
+ }
326
+ return { send: out, problems };
327
+ }
328
+
329
+ /** Keeps the string -> string entries of a partner id map. */
330
+ export function sanitizePartnerIds(ids: unknown): { ids: Record<string, string> | null; problems: string[] } {
331
+ const problems: string[] = [];
332
+ if (!isPlainObject(ids)) {
333
+ problems.push(`setPartnerIds needs an object of strings, got ${describe(ids)}`);
334
+ return { ids: null, problems };
335
+ }
336
+ const out: Record<string, string> = {};
337
+ for (const [key, value] of Object.entries(ids)) {
338
+ if (value === undefined) continue;
339
+ if (typeof value === 'string' && key.length > 0) out[key] = value;
340
+ else problems.push(`partner id "${key}" must be a string, got ${describe(value)}`);
341
+ }
342
+ return { ids: out, problems };
343
+ }
package/src/version.ts 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
+
4
+ /** Passed to the native SDKs as `KerdlyOptions.wrapper`; they send it in `X-Kerdly-Sdk` and `sdk.wrapper`. */
5
+ export const WRAPPER = `expo/${SDK_VERSION}`;