@usesophi/sophi-event-react-native 0.0.0-stage → 0.0.1-alpha01

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 (74) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +116 -2
  3. package/SophiEventSDK-ReactNative.podspec +23 -0
  4. package/android/build.gradle +39 -0
  5. package/android/consumer-rules.pro +1 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/java/com/sophi/eventreactnative/SophiEventsModule.kt +199 -0
  8. package/android/src/main/java/com/sophi/eventreactnative/SophiEventsPackage.kt +11 -0
  9. package/index.ts +4 -0
  10. package/ios/Frameworks/SophiEventSDK.xcframework/Info.plist +44 -0
  11. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/Headers/SophiEventSDK-Swift.h +382 -0
  12. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/Info.plist +0 -0
  13. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios.abi.json +21707 -0
  14. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +413 -0
  15. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  16. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios.swiftinterface +413 -0
  17. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/Modules/module.modulemap +3 -0
  18. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/PrivacyInfo.xcprivacy +153 -0
  19. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64/SophiEventSDK.framework/SophiEventSDK +0 -0
  20. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Headers/SophiEventSDK-Swift.h +760 -0
  21. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Info.plist +0 -0
  22. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +21707 -0
  23. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +413 -0
  24. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  25. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +413 -0
  26. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +21707 -0
  27. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +413 -0
  28. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  29. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/SophiEventSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +413 -0
  30. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/Modules/module.modulemap +3 -0
  31. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/PrivacyInfo.xcprivacy +153 -0
  32. package/ios/Frameworks/SophiEventSDK.xcframework/ios-arm64_x86_64-simulator/SophiEventSDK.framework/SophiEventSDK +0 -0
  33. package/ios/Frameworks/SophiIdentity.xcframework/Info.plist +44 -0
  34. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/Headers/SophiIdentity-Swift.h +382 -0
  35. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/Info.plist +0 -0
  36. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios.abi.json +6314 -0
  37. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios.private.swiftinterface +170 -0
  38. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  39. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios.swiftinterface +170 -0
  40. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/Modules/module.modulemap +3 -0
  41. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/PrivacyInfo.xcprivacy +50 -0
  42. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64/SophiIdentity.framework/SophiIdentity +0 -0
  43. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Headers/SophiIdentity-Swift.h +760 -0
  44. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Info.plist +0 -0
  45. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios-simulator.abi.json +6314 -0
  46. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +170 -0
  47. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  48. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/arm64-apple-ios-simulator.swiftinterface +170 -0
  49. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/x86_64-apple-ios-simulator.abi.json +6314 -0
  50. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +170 -0
  51. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  52. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/SophiIdentity.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +170 -0
  53. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/Modules/module.modulemap +3 -0
  54. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/PrivacyInfo.xcprivacy +50 -0
  55. package/ios/Frameworks/SophiIdentity.xcframework/ios-arm64_x86_64-simulator/SophiIdentity.framework/SophiIdentity +0 -0
  56. package/ios/SophiEventsModule.m +54 -0
  57. package/ios/SophiEventsModuleImpl.swift +178 -0
  58. package/lib/index.d.ts +4 -0
  59. package/lib/index.js +10 -0
  60. package/lib/src/SophiEvents.d.ts +3 -0
  61. package/lib/src/SophiEvents.js +11 -0
  62. package/lib/src/client.d.ts +60 -0
  63. package/lib/src/client.js +151 -0
  64. package/lib/src/types.d.ts +204 -0
  65. package/lib/src/types.js +3 -0
  66. package/lib/src/wire.d.ts +10 -0
  67. package/lib/src/wire.js +191 -0
  68. package/native-versions.json +16 -0
  69. package/package.json +62 -4
  70. package/react-native.config.js +10 -0
  71. package/src/SophiEvents.ts +13 -0
  72. package/src/client.ts +191 -0
  73. package/src/types.ts +216 -0
  74. package/src/wire.ts +189 -0
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_native_1 = require("react-native");
4
+ const client_1 = require("./client");
5
+ const native = react_native_1.NativeModules.SophiEventsModule;
6
+ if (!native) {
7
+ throw new Error('Sophi event native module is not linked. Rebuild the native application after installing @usesophi/sophi-event-react-native.');
8
+ }
9
+ const emitter = new react_native_1.NativeEventEmitter(native);
10
+ /** The app-wide event SDK. Configure once at startup, then report merchant actions. */
11
+ exports.default = (0, client_1.createEventsClient)(native, listener => emitter.addListener('SophiEventDiagnostic', listener));
@@ -0,0 +1,60 @@
1
+ import type { BasketObject, EventConfiguration, EventDiagnostic, EventHandlers, EventReceipt, FlushResult, JsonObject, ListingObject, PageObject, ProductObject, SophiEvent, TransactionObject, UserObject } from './types';
2
+ /** The single error type of the API. `code` is the same on iOS and Android. */
3
+ export declare class SophiEventError extends Error {
4
+ readonly code: string;
5
+ /** HTTP status for `http`. */
6
+ readonly status?: number;
7
+ /** Invalid wire paths for `validation`, e.g. `basket.line_items[0].quantity`. */
8
+ readonly fields?: string[];
9
+ constructor(code: string, message: string, details?: {
10
+ status?: number;
11
+ fields?: string[];
12
+ });
13
+ }
14
+ /** What the native module provides on both platforms. */
15
+ export interface NativeEvents {
16
+ configure(options: Record<string, unknown>): Promise<void>;
17
+ setAnalyticsEnabled(enabled: boolean): Promise<void>;
18
+ updateUser(externalUserId: string | null): Promise<void>;
19
+ logout(): Promise<void>;
20
+ track(eventJson: string): Promise<{
21
+ id: string | null;
22
+ status: string;
23
+ }>;
24
+ flush(): Promise<FlushResult>;
25
+ pendingCount(): Promise<number>;
26
+ }
27
+ type Subscribe = (listener: (diagnostic: EventDiagnostic) => void) => {
28
+ remove(): void;
29
+ };
30
+ export interface SophiEventsClient {
31
+ /** Configure once at startup and await it before tracking. Calling it again replaces the setup. */
32
+ configure(config: EventConfiguration, handlers?: EventHandlers): Promise<void>;
33
+ /** Report the consent answer when it arrives. `false` deletes the stored queue. */
34
+ setAnalyticsEnabled(enabled: boolean): Promise<void>;
35
+ /** The merchant customer ID after sign-in, or `null` for a guest. */
36
+ updateUser(externalUserId: string | null): Promise<void>;
37
+ /** Sign-out: forgets the shopper and deletes its pending events. */
38
+ logout(): Promise<void>;
39
+ /** Accepts one occurrence. A queued receipt means stored on the device; delivery may follow later. */
40
+ track(event: SophiEvent): Promise<EventReceipt>;
41
+ pageView(page: PageObject): Promise<EventReceipt>;
42
+ productView(page: PageObject, product: ProductObject): Promise<EventReceipt>;
43
+ listingView(page: PageObject, listing: ListingObject): Promise<EventReceipt>;
44
+ basketView(page: PageObject, basket: BasketObject): Promise<EventReceipt>;
45
+ /** One call per added unit, each with the resulting complete basket. */
46
+ addToCart(page: PageObject, product: ProductObject, basket: BasketObject): Promise<EventReceipt>;
47
+ removeFromCart(page: PageObject, product: ProductObject, basket: BasketObject): Promise<EventReceipt>;
48
+ checkoutStarted(page: PageObject, basket: BasketObject): Promise<EventReceipt>;
49
+ /** Once per confirmed order. */
50
+ purchase(page: PageObject, transaction: TransactionObject): Promise<EventReceipt>;
51
+ /** Sent from memory only; requires granted analytics. */
52
+ identify(page: PageObject, user: UserObject): Promise<EventReceipt>;
53
+ custom(page: PageObject, properties: JsonObject): Promise<EventReceipt>;
54
+ /** Sends what is due now. Queued events are also sent automatically. */
55
+ flush(): Promise<FlushResult>;
56
+ /** Events waiting on this device for the current shopper. */
57
+ pendingCount(): Promise<number>;
58
+ }
59
+ export declare function createEventsClient(native: NativeEvents, subscribe: Subscribe): SophiEventsClient;
60
+ export {};
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SophiEventError = void 0;
4
+ exports.createEventsClient = createEventsClient;
5
+ const wire_1 = require("./wire");
6
+ /** The single error type of the API. `code` is the same on iOS and Android. */
7
+ class SophiEventError extends Error {
8
+ constructor(code, message, details = {}) {
9
+ super(message);
10
+ this.name = 'SophiEventError';
11
+ this.code = code;
12
+ if (details.status !== undefined)
13
+ this.status = details.status;
14
+ if (details.fields !== undefined)
15
+ this.fields = details.fields;
16
+ }
17
+ }
18
+ exports.SophiEventError = SophiEventError;
19
+ const STATUSES = ['queued', 'disabled', 'deliveredMemoryOnly'];
20
+ function normalize(error) {
21
+ var _a, _b;
22
+ if (error instanceof SophiEventError)
23
+ return error;
24
+ const info = (_a = error === null || error === void 0 ? void 0 : error.userInfo) !== null && _a !== void 0 ? _a : {};
25
+ const code = typeof (error === null || error === void 0 ? void 0 : error.code) === 'string' && error.code ? error.code : 'internal_error';
26
+ return new SophiEventError(code, (_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : 'The native event SDK failed', {
27
+ status: typeof info.status === 'number' ? info.status : undefined,
28
+ fields: Array.isArray(info.fields) ? info.fields.map(String) : undefined,
29
+ });
30
+ }
31
+ async function call(operation) {
32
+ try {
33
+ return await operation();
34
+ }
35
+ catch (error) {
36
+ throw normalize(error);
37
+ }
38
+ }
39
+ function invalid(message) {
40
+ throw new SophiEventError('invalid_configuration', message);
41
+ }
42
+ function configurationSnapshot(config) {
43
+ var _a, _b;
44
+ if (!config || typeof config !== 'object')
45
+ invalid('A configuration object is required');
46
+ if (typeof config.apiKey !== 'string' || !config.apiKey.trim())
47
+ invalid('apiKey is required');
48
+ if (config.baseUrl !== undefined && (typeof config.baseUrl !== 'string' || !/^https:\/\/[^/?#\s]+\/?$/i.test(config.baseUrl)))
49
+ invalid('baseUrl must be an HTTPS origin without a path, query or fragment');
50
+ const consent = config.analyticsEnabled;
51
+ if (consent !== undefined && consent !== null && typeof consent !== 'boolean')
52
+ invalid('analyticsEnabled must be true, false or left out');
53
+ const user = config.externalUserId;
54
+ if (user !== undefined && user !== null && typeof user !== 'string')
55
+ invalid('externalUserId must be a string');
56
+ const limits = {};
57
+ for (const [key, value] of Object.entries((_a = config.queueLimits) !== null && _a !== void 0 ? _a : {})) {
58
+ if (!['maxAgeMs', 'maxEvents', 'maxBytes', 'maxEventBytes'].includes(key))
59
+ invalid(`Unknown queue limit ${key}`);
60
+ if (value === undefined)
61
+ continue;
62
+ if (!Number.isSafeInteger(value) || value <= 0)
63
+ invalid(`${key} must be a positive integer`);
64
+ limits[key] = value;
65
+ }
66
+ return {
67
+ apiKey: config.apiKey,
68
+ baseUrl: (_b = config.baseUrl) !== null && _b !== void 0 ? _b : null,
69
+ // The native bridges read a missing value as "not known yet".
70
+ analyticsEnabled: typeof consent === 'boolean' ? consent : null,
71
+ externalUserId: user !== null && user !== void 0 ? user : null,
72
+ queueLimits: limits,
73
+ };
74
+ }
75
+ function createEventsClient(native, subscribe) {
76
+ let subscription;
77
+ let handlers = {};
78
+ const listen = () => {
79
+ if (subscription)
80
+ return;
81
+ subscription = subscribe(diagnostic => {
82
+ var _a;
83
+ try {
84
+ (_a = handlers.onDiagnostic) === null || _a === void 0 ? void 0 : _a.call(handlers, {
85
+ code: String(diagnostic.code),
86
+ eventId: diagnostic.eventId ? String(diagnostic.eventId).toLowerCase() : null,
87
+ count: Number(diagnostic.count) || 0,
88
+ });
89
+ }
90
+ catch (_b) {
91
+ // A host logging callback must never break event delivery.
92
+ }
93
+ });
94
+ };
95
+ const track = async (event) => {
96
+ const wire = (0, wire_1.toWire)(event);
97
+ if ('fields' in wire)
98
+ throw new SophiEventError('validation', `Invalid event fields: ${wire.fields.join(', ')}`, { fields: wire.fields });
99
+ const receipt = await call(() => native.track(wire.json));
100
+ const status = STATUSES.includes(receipt === null || receipt === void 0 ? void 0 : receipt.status) ? receipt.status : 'queued';
101
+ return { id: (receipt === null || receipt === void 0 ? void 0 : receipt.id) ? String(receipt.id).toLowerCase() : null, status: status };
102
+ };
103
+ return {
104
+ async configure(config, next = {}) {
105
+ const snapshot = configurationSnapshot(config);
106
+ if (next.onDiagnostic !== undefined && typeof next.onDiagnostic !== 'function')
107
+ invalid('onDiagnostic must be a function');
108
+ handlers = Object.assign({}, next);
109
+ listen();
110
+ await call(() => native.configure(snapshot));
111
+ },
112
+ async setAnalyticsEnabled(enabled) {
113
+ if (typeof enabled !== 'boolean')
114
+ invalid('setAnalyticsEnabled takes true or false');
115
+ await call(() => native.setAnalyticsEnabled(enabled));
116
+ },
117
+ async updateUser(externalUserId) {
118
+ if (externalUserId !== null && (typeof externalUserId !== 'string' || !externalUserId.trim()))
119
+ invalid('updateUser takes a nonempty customer ID or null');
120
+ await call(() => native.updateUser(externalUserId));
121
+ },
122
+ async logout() {
123
+ await call(() => native.logout());
124
+ },
125
+ track,
126
+ pageView: page => track({ type: 'page_view', page }),
127
+ productView: (page, product) => track({ type: 'product_view', page, product }),
128
+ listingView: (page, listing) => track({ type: 'listing_view', page, listing }),
129
+ basketView: (page, basket) => track({ type: 'basket_view', page, basket }),
130
+ addToCart: (page, product, basket) => track({ type: 'add_to_cart', page, product, basket }),
131
+ removeFromCart: (page, product, basket) => track({ type: 'remove_from_cart', page, product, basket }),
132
+ checkoutStarted: (page, basket) => track({ type: 'checkout_started', page, basket }),
133
+ purchase: (page, transaction) => track({ type: 'purchase', page, transaction }),
134
+ identify: (page, user) => track({ type: 'identify', page, user }),
135
+ custom: (page, properties) => track({ type: 'custom', page, custom: properties }),
136
+ async flush() {
137
+ var _a;
138
+ const result = await call(() => native.flush());
139
+ return {
140
+ delivered: Number(result === null || result === void 0 ? void 0 : result.delivered) || 0,
141
+ retried: Number(result === null || result === void 0 ? void 0 : result.retried) || 0,
142
+ discarded: Number(result === null || result === void 0 ? void 0 : result.discarded) || 0,
143
+ pending: Number(result === null || result === void 0 ? void 0 : result.pending) || 0,
144
+ pausedReason: (_a = result === null || result === void 0 ? void 0 : result.pausedReason) !== null && _a !== void 0 ? _a : null,
145
+ };
146
+ },
147
+ async pendingCount() {
148
+ return Number(await call(() => native.pendingCount())) || 0;
149
+ },
150
+ };
151
+ }
@@ -0,0 +1,204 @@
1
+ /** Public types of the Sophi React Native event SDK. Field names match EVENT-REFERENCE.md. */
2
+ /** JSON value for `custom` and `appliedFilters`: no functions, dates, undefined or non-finite numbers. */
3
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
4
+ [key: string]: JsonValue;
5
+ };
6
+ export type JsonObject = {
7
+ [key: string]: JsonValue;
8
+ };
9
+ export type PageType = 'Home' | 'Category' | 'Product' | 'Basket' | 'Checkout' | 'Confirmation' | 'Search' | 'Account' | 'Custom';
10
+ export type EventType = 'page_view' | 'product_view' | 'listing_view' | 'basket_view' | 'add_to_cart' | 'remove_from_cart' | 'checkout_started' | 'purchase' | 'identify' | 'custom';
11
+ export interface PageObject {
12
+ type: PageType;
13
+ /** A native deep link such as `merchant://products/42` is valid. */
14
+ url: string;
15
+ title?: string;
16
+ language?: string;
17
+ categoryId?: string;
18
+ searchQuery?: string;
19
+ custom?: JsonObject;
20
+ }
21
+ export interface ConsentObject {
22
+ gdprOptin: boolean;
23
+ version: string;
24
+ /** Epoch seconds. */
25
+ timestamp: number;
26
+ }
27
+ export interface IdentityObject {
28
+ uuid?: string;
29
+ email?: string;
30
+ phoneNumber?: string;
31
+ }
32
+ export interface ProfileObject {
33
+ name?: string;
34
+ surname?: string;
35
+ /** `F`, `M`, `O` or `U`. */
36
+ gender?: string;
37
+ birthday?: string;
38
+ language?: string;
39
+ }
40
+ export interface BehaviorObject {
41
+ returning?: boolean;
42
+ hasTransacted?: boolean;
43
+ transactionCount?: number;
44
+ /** Epoch seconds. */
45
+ lastTransactionAt?: number;
46
+ }
47
+ export interface SegmentationObject {
48
+ staticSegmentIds?: Array<string | number>;
49
+ }
50
+ export interface UserObject {
51
+ consent: ConsentObject;
52
+ identity?: IdentityObject;
53
+ profile?: ProfileObject;
54
+ behavior?: BehaviorObject;
55
+ segmentation?: SegmentationObject;
56
+ custom?: JsonObject;
57
+ }
58
+ export interface ProductObject {
59
+ id: string;
60
+ categoryIds: string[];
61
+ name: string;
62
+ url: string;
63
+ productImageUrl: string;
64
+ taxonomy: string[];
65
+ /** Uppercase three-letter code. */
66
+ currency: string;
67
+ /** Major currency units, not minor-unit integers. */
68
+ unitPrice: number;
69
+ unitSalePrice: number;
70
+ /** 0 or 1. */
71
+ inStock: number;
72
+ variantId?: string;
73
+ sku?: string;
74
+ groupCode?: string;
75
+ omnibusPrice?: number;
76
+ stock?: number;
77
+ brand?: string;
78
+ color?: string;
79
+ size?: string;
80
+ gender?: string;
81
+ locale?: string;
82
+ description?: string;
83
+ tags?: string[];
84
+ custom?: JsonObject;
85
+ }
86
+ export interface LineItem {
87
+ productId: string;
88
+ quantity: number;
89
+ currency: string;
90
+ unitPrice: number;
91
+ unitSalePrice: number;
92
+ lineTotal: number;
93
+ variantId?: string;
94
+ sku?: string;
95
+ }
96
+ export interface BasketObject {
97
+ currency: string;
98
+ total: number;
99
+ lineItems: LineItem[];
100
+ basketId?: string;
101
+ subtotal?: number;
102
+ tax?: number;
103
+ shippingCost?: number;
104
+ discountTotal?: number;
105
+ couponCode?: string;
106
+ }
107
+ export interface ListingItem {
108
+ productId: string;
109
+ position: number;
110
+ name: string;
111
+ url: string;
112
+ productImageUrl: string;
113
+ currency: string;
114
+ unitPrice: number;
115
+ unitSalePrice: number;
116
+ variantId?: string;
117
+ inStock?: number;
118
+ brand?: string;
119
+ }
120
+ export interface ListingObject {
121
+ categoryId?: string;
122
+ slug?: string;
123
+ searchQuery?: string;
124
+ name?: string;
125
+ taxonomy?: string[];
126
+ totalResults?: number;
127
+ pageNumber?: number;
128
+ pageSize?: number;
129
+ sort?: string;
130
+ appliedFilters?: JsonObject;
131
+ items?: ListingItem[];
132
+ }
133
+ export interface TransactionObject {
134
+ orderId: string;
135
+ currency: string;
136
+ total: number;
137
+ lineItems: LineItem[];
138
+ subtotal?: number;
139
+ tax?: number;
140
+ shippingCost?: number;
141
+ discountTotal?: number;
142
+ couponCode?: string;
143
+ paymentMethod?: string;
144
+ }
145
+ /** An explicit merchant action. Use the typed helpers, or `track` to attach optional context. */
146
+ export interface SophiEvent {
147
+ type: EventType;
148
+ page: PageObject;
149
+ product?: ProductObject;
150
+ basket?: BasketObject;
151
+ listing?: ListingObject;
152
+ transaction?: TransactionObject;
153
+ user?: UserObject;
154
+ custom?: JsonObject;
155
+ }
156
+ export interface QueueLimits {
157
+ /** At most 7 days. */
158
+ maxAgeMs?: number;
159
+ maxEvents?: number;
160
+ maxBytes?: number;
161
+ maxEventBytes?: number;
162
+ }
163
+ export interface EventConfiguration {
164
+ apiKey: string;
165
+ /** HTTPS origin only, e.g. `https://api.usesophi.com` (the default). Use the same origin as chat. */
166
+ baseUrl?: string;
167
+ /**
168
+ * The shopper's analytics consent. Leave it out (or `null`) while it is not known yet: nothing is
169
+ * collected and nothing stored is deleted. `false` deletes the stored queue.
170
+ */
171
+ analyticsEnabled?: boolean | null;
172
+ /** The merchant's customer ID when the shopper is signed in. */
173
+ externalUserId?: string | null;
174
+ queueLimits?: QueueLimits;
175
+ }
176
+ export interface EventDiagnostic {
177
+ code: string;
178
+ eventId: string | null;
179
+ count: number;
180
+ }
181
+ export interface EventHandlers {
182
+ /** Delivery and storage diagnostics, for logging only. Never contains event payloads. */
183
+ onDiagnostic?: (diagnostic: EventDiagnostic) => void;
184
+ }
185
+ export interface EventReceipt {
186
+ /** Lowercase UUID of this occurrence; `null` when nothing was accepted. */
187
+ id: string | null;
188
+ /** `queued`: stored on the device. `disabled`: analytics not granted. `deliveredMemoryOnly`: identify. */
189
+ status: 'queued' | 'disabled' | 'deliveredMemoryOnly';
190
+ }
191
+ export interface FlushResult {
192
+ delivered: number;
193
+ retried: number;
194
+ discarded: number;
195
+ pending: number;
196
+ pausedReason: string | null;
197
+ }
198
+ /**
199
+ * Error codes, the same on iOS and Android: `validation` (see `fields`), `not_configured`,
200
+ * `invalid_configuration`, `event_too_large`, `queue_full`, `storage_unavailable`, `network`,
201
+ * `http` (see `status`), `invalid_response`, `invalid_receipt`, `backend_unsupported`, `disabled`,
202
+ * `merge_pending`, `identity_changed`, `duplicate_identity_module`, `internal_error`.
203
+ */
204
+ export type EventErrorCode = string;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ /** Public types of the Sophi React Native event SDK. Field names match EVENT-REFERENCE.md. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import type { SophiEvent } from './types';
2
+ export declare const EVENT_TYPES: readonly ["page_view", "product_view", "listing_view", "basket_view", "add_to_cart", "remove_from_cart", "checkout_started", "purchase", "identify", "custom"];
3
+ /** camelCase public name to wire name: `productImageUrl` -> `product_image_url`. */
4
+ export declare function wireName(name: string): string;
5
+ /** Wire JSON for the native SDKs, or the invalid field paths. */
6
+ export declare function toWire(input: SophiEvent): {
7
+ json: string;
8
+ } | {
9
+ fields: string[];
10
+ };
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVENT_TYPES = void 0;
4
+ exports.wireName = wireName;
5
+ exports.toWire = toWire;
6
+ const page = [
7
+ ['type', 's', true], ['url', 's', true], ['title', 's', false], ['language', 's', false],
8
+ ['categoryId', 's', false], ['searchQuery', 's', false], ['custom', 'json', false],
9
+ ];
10
+ const consent = [['gdprOptin', 'b', true], ['version', 's', true], ['timestamp', 'i', true]];
11
+ const identity = [['uuid', 's', false], ['email', 's', false], ['phoneNumber', 's', false]];
12
+ const profile = [
13
+ ['name', 's', false], ['surname', 's', false], ['gender', 's', false], ['birthday', 's', false],
14
+ ['language', 's', false],
15
+ ];
16
+ const behavior = [
17
+ ['returning', 'b', false], ['hasTransacted', 'b', false], ['transactionCount', 'i', false],
18
+ ['lastTransactionAt', 'i', false],
19
+ ];
20
+ const segmentation = [['staticSegmentIds', 'segments', false]];
21
+ const user = [
22
+ ['consent', { object: consent }, true], ['identity', { object: identity }, false],
23
+ ['profile', { object: profile }, false], ['behavior', { object: behavior }, false],
24
+ ['segmentation', { object: segmentation }, false], ['custom', 'json', false],
25
+ ];
26
+ const product = [
27
+ ['id', 's', true], ['categoryIds', 'strings', true], ['name', 's', true], ['url', 's', true],
28
+ ['productImageUrl', 's', true], ['taxonomy', 'strings', true], ['currency', 's', true],
29
+ ['unitPrice', 'n', true], ['unitSalePrice', 'n', true], ['inStock', 'i', true],
30
+ ['variantId', 's', false], ['sku', 's', false], ['groupCode', 's', false],
31
+ ['omnibusPrice', 'n', false], ['stock', 'i', false], ['brand', 's', false], ['color', 's', false],
32
+ ['size', 's', false], ['gender', 's', false], ['locale', 's', false], ['description', 's', false],
33
+ ['tags', 'strings', false], ['custom', 'json', false],
34
+ ];
35
+ const lineItem = [
36
+ ['productId', 's', true], ['quantity', 'i', true], ['currency', 's', true], ['unitPrice', 'n', true],
37
+ ['unitSalePrice', 'n', true], ['lineTotal', 'n', true], ['variantId', 's', false], ['sku', 's', false],
38
+ ];
39
+ const basket = [
40
+ ['currency', 's', true], ['total', 'n', true], ['lineItems', { array: lineItem }, true],
41
+ ['basketId', 's', false], ['subtotal', 'n', false], ['tax', 'n', false], ['shippingCost', 'n', false],
42
+ ['discountTotal', 'n', false], ['couponCode', 's', false],
43
+ ];
44
+ const listingItem = [
45
+ ['productId', 's', true], ['position', 'i', true], ['name', 's', true], ['url', 's', true],
46
+ ['productImageUrl', 's', true], ['currency', 's', true], ['unitPrice', 'n', true],
47
+ ['unitSalePrice', 'n', true], ['variantId', 's', false], ['inStock', 'i', false], ['brand', 's', false],
48
+ ];
49
+ const listing = [
50
+ ['categoryId', 's', false], ['slug', 's', false], ['searchQuery', 's', false], ['name', 's', false],
51
+ ['taxonomy', 'strings', false], ['totalResults', 'i', false], ['pageNumber', 'i', false],
52
+ ['pageSize', 'i', false], ['sort', 's', false], ['appliedFilters', 'json', false],
53
+ ['items', { array: listingItem }, false],
54
+ ];
55
+ const transaction = [
56
+ ['orderId', 's', true], ['currency', 's', true], ['total', 'n', true], ['lineItems', { array: lineItem }, true],
57
+ ['subtotal', 'n', false], ['tax', 'n', false], ['shippingCost', 'n', false],
58
+ ['discountTotal', 'n', false], ['couponCode', 's', false], ['paymentMethod', 's', false],
59
+ ];
60
+ const event = [
61
+ ['page', { object: page }, true], ['product', { object: product }, false], ['basket', { object: basket }, false],
62
+ ['listing', { object: listing }, false], ['transaction', { object: transaction }, false],
63
+ ['user', { object: user }, false], ['custom', 'json', false],
64
+ ];
65
+ exports.EVENT_TYPES = [
66
+ 'page_view', 'product_view', 'listing_view', 'basket_view', 'add_to_cart', 'remove_from_cart',
67
+ 'checkout_started', 'purchase', 'identify', 'custom',
68
+ ];
69
+ const MAX_JSON_DEPTH = 16;
70
+ /** camelCase public name to wire name: `productImageUrl` -> `product_image_url`. */
71
+ function wireName(name) {
72
+ return name.replace(/[A-Z]/g, letter => '_' + letter.toLowerCase());
73
+ }
74
+ function isPlainObject(value) {
75
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
76
+ return false;
77
+ const prototype = Object.getPrototypeOf(value);
78
+ return prototype === Object.prototype || prototype === null;
79
+ }
80
+ /** Copies a JSON value, rejecting what JSON cannot carry. Returns false when invalid. */
81
+ function copyJson(value, depth, seen, out) {
82
+ if (depth > MAX_JSON_DEPTH)
83
+ return false;
84
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') {
85
+ out.value = value;
86
+ return true;
87
+ }
88
+ if (typeof value === 'number') {
89
+ if (!Number.isFinite(value))
90
+ return false;
91
+ out.value = value;
92
+ return true;
93
+ }
94
+ if (Array.isArray(value) || isPlainObject(value)) {
95
+ if (seen.has(value))
96
+ return false;
97
+ seen.add(value);
98
+ const entries = Array.isArray(value) ? value.map((v, i) => [i, v]) : Object.entries(value);
99
+ const copy = Array.isArray(value) ? [] : {};
100
+ for (const [key, child] of entries) {
101
+ const inner = {};
102
+ if (!copyJson(child, depth + 1, seen, inner))
103
+ return false;
104
+ copy[key] = inner.value;
105
+ }
106
+ seen.delete(value);
107
+ out.value = copy;
108
+ return true;
109
+ }
110
+ return false; // functions, undefined, dates, maps, class instances, symbols, bigint
111
+ }
112
+ function convert(value, kind, path, errors) {
113
+ switch (kind) {
114
+ case 's':
115
+ if (typeof value !== 'string')
116
+ errors.push(path);
117
+ return value;
118
+ case 'n':
119
+ if (typeof value !== 'number' || !Number.isFinite(value))
120
+ errors.push(path);
121
+ return value;
122
+ case 'i':
123
+ if (typeof value !== 'number' || !Number.isSafeInteger(value))
124
+ errors.push(path);
125
+ return value;
126
+ case 'b':
127
+ if (typeof value !== 'boolean')
128
+ errors.push(path);
129
+ return value;
130
+ case 'strings':
131
+ if (!Array.isArray(value) || !value.every(item => typeof item === 'string'))
132
+ errors.push(path);
133
+ return Array.isArray(value) ? [...value] : value;
134
+ case 'segments':
135
+ if (!Array.isArray(value) || !value.every(item => typeof item === 'string' || (typeof item === 'number' && Number.isSafeInteger(item))))
136
+ errors.push(path);
137
+ return Array.isArray(value) ? [...value] : value;
138
+ case 'json': {
139
+ const out = {};
140
+ if (!isPlainObject(value) || !copyJson(value, 1, new Set(), out)) {
141
+ errors.push(path);
142
+ return undefined;
143
+ }
144
+ return out.value;
145
+ }
146
+ }
147
+ if ('object' in kind)
148
+ return convertObject(value, kind.object, path, errors);
149
+ if (!Array.isArray(value)) {
150
+ errors.push(path);
151
+ return undefined;
152
+ }
153
+ return value.map((item, index) => convertObject(item, kind.array, `${path}[${index}]`, errors));
154
+ }
155
+ function convertObject(value, schema, path, errors) {
156
+ if (!isPlainObject(value)) {
157
+ errors.push(path);
158
+ return undefined;
159
+ }
160
+ const known = new Set(schema.map(([name]) => name));
161
+ for (const key of Object.keys(value)) {
162
+ if (!known.has(key) && value[key] !== undefined)
163
+ errors.push(`${path}.${key}`);
164
+ }
165
+ const out = {};
166
+ for (const [name, kind, required] of schema) {
167
+ const fieldPath = `${path}.${wireName(name)}`;
168
+ const raw = value[name];
169
+ if (raw === undefined || raw === null) {
170
+ if (required)
171
+ errors.push(fieldPath);
172
+ continue;
173
+ }
174
+ out[wireName(name)] = convert(raw, kind, fieldPath, errors);
175
+ }
176
+ return out;
177
+ }
178
+ /** Wire JSON for the native SDKs, or the invalid field paths. */
179
+ function toWire(input) {
180
+ const errors = [];
181
+ if (!isPlainObject(input))
182
+ return { fields: ['event'] };
183
+ if (!exports.EVENT_TYPES.includes(input.type))
184
+ errors.push('event_type');
185
+ const body = convertObject(Object.assign(Object.assign({}, input), { type: undefined }), event, 'event', errors);
186
+ if (errors.length) {
187
+ // Paths are relative to the event, as in the native SDKs: `page.url`, not `event.page.url`.
188
+ return { fields: [...new Set(errors.map(e => (e === 'event' ? e : e.replace(/^event\./, ''))))] };
189
+ }
190
+ return { json: JSON.stringify(Object.assign({ event_type: input.type }, body)) };
191
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "ios": {
3
+ "version": "0.0.1-alpha01",
4
+ "identity": {
5
+ "url": "https://github.com/Let-Me-Shop-For-You/Sophi-Event-iOS-SDK/releases/download/0.0.1-alpha01/SophiIdentity.xcframework.zip",
6
+ "checksum": "c1a80c03c871a97a18870b460a9ff881cb9c5044482161bb44234c15a101831d"
7
+ },
8
+ "event": {
9
+ "url": "https://github.com/Let-Me-Shop-For-You/Sophi-Event-iOS-SDK/releases/download/0.0.1-alpha01/SophiEventSDK.xcframework.zip",
10
+ "checksum": "3f0e2d1303133d808af9b356900f20619df5a12a59c07f044141b8777e9fa4cd"
11
+ }
12
+ },
13
+ "android": {
14
+ "version": "0.0.1-alpha01"
15
+ }
16
+ }