@cavlyn/react-native-sdk 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/CavlynReactNative.podspec +22 -0
- package/LICENSE +202 -0
- package/README.md +164 -2
- package/android/build.gradle +47 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/kotlin/com/cavlyn/reactnative/CavlynReactNativeModule.kt +384 -0
- package/android/src/main/kotlin/com/cavlyn/reactnative/CavlynReactNativePackage.kt +14 -0
- package/dist/client.d.ts +95 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +395 -0
- package/dist/client.js.map +1 -0
- package/dist/hooks.d.ts +24 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +78 -0
- package/dist/hooks.js.map +1 -0
- package/dist/http.d.ts +30 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +126 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/nativeBridge.d.ts +46 -0
- package/dist/nativeBridge.d.ts.map +1 -0
- package/dist/nativeBridge.js +99 -0
- package/dist/nativeBridge.js.map +1 -0
- package/dist/parser.d.ts +38 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +198 -0
- package/dist/parser.js.map +1 -0
- package/dist/storage.d.ts +27 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +72 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +182 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/ios/CavlynReactNative.m +40 -0
- package/ios/CavlynReactNative.swift +455 -0
- package/package.json +65 -4
- package/react-native.config.js +14 -0
- package/src/client.ts +479 -0
- package/src/hooks.ts +117 -0
- package/src/http.ts +158 -0
- package/src/index.ts +38 -0
- package/src/nativeBridge.ts +109 -0
- package/src/parser.ts +202 -0
- package/src/storage.ts +76 -0
- package/src/types.ts +214 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported event types matching the Cavlyn Event Ingestion API (`POST /api/v1/events`).
|
|
3
|
+
*/
|
|
4
|
+
export type AttributionEventType = 'INSTALL' | 'APP_OPEN' | 'CONVERSION';
|
|
5
|
+
|
|
6
|
+
export type CommerceEventType =
|
|
7
|
+
| 'PRODUCT_VIEW'
|
|
8
|
+
| 'STORE_VIEW'
|
|
9
|
+
| 'ADD_TO_CART'
|
|
10
|
+
| 'REMOVE_FROM_CART'
|
|
11
|
+
| 'CHECKOUT_STARTED'
|
|
12
|
+
| 'CHECKOUT_COMPLETED'
|
|
13
|
+
| 'PURCHASE'
|
|
14
|
+
| 'REFUND';
|
|
15
|
+
|
|
16
|
+
export type CavlynEventType = AttributionEventType | CommerceEventType;
|
|
17
|
+
|
|
18
|
+
export type CavlynPlatformName =
|
|
19
|
+
| 'IOS'
|
|
20
|
+
| 'ANDROID'
|
|
21
|
+
| 'WEB'
|
|
22
|
+
| 'REACT_NATIVE_IOS'
|
|
23
|
+
| 'REACT_NATIVE_ANDROID'
|
|
24
|
+
| string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Pluggable key-value storage adapter used by the JavaScript runtime fallback
|
|
28
|
+
* (e.g. `@react-native-async-storage/async-storage`, MMKV, or in-memory storage).
|
|
29
|
+
*/
|
|
30
|
+
export interface CavlynStorage {
|
|
31
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
32
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
33
|
+
removeItem(key: string): void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Minimal fetch function signature for injecting custom HTTP transports or mocks.
|
|
38
|
+
*/
|
|
39
|
+
export type FetchLike = (
|
|
40
|
+
input: string,
|
|
41
|
+
init?: {
|
|
42
|
+
method?: string;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
body?: string;
|
|
45
|
+
signal?: AbortSignal;
|
|
46
|
+
},
|
|
47
|
+
) => Promise<{
|
|
48
|
+
ok: boolean;
|
|
49
|
+
status: number;
|
|
50
|
+
statusText: string;
|
|
51
|
+
json(): Promise<unknown>;
|
|
52
|
+
}>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Configuration passed to `Cavlyn.initialize(...)`.
|
|
56
|
+
*/
|
|
57
|
+
export interface CavlynConfiguration {
|
|
58
|
+
/** App-scoped API key (sent in the `X-API-Key` header). */
|
|
59
|
+
apiKey: string;
|
|
60
|
+
/** Base URL of the Cavlyn API service (default: `https://api.cavlyn.com`). */
|
|
61
|
+
apiBaseUrl?: string;
|
|
62
|
+
/** HTTP request timeout in milliseconds (default: `10000`). */
|
|
63
|
+
timeoutMs?: number;
|
|
64
|
+
/** Automatically check and process the initial launch URL during `initialize()` (default: `true`). */
|
|
65
|
+
autoHandleInitialUrl?: boolean;
|
|
66
|
+
/** Automatically subscribe to incoming URL events from native / React Native `Linking` (default: `true`). */
|
|
67
|
+
autoListenLinking?: boolean;
|
|
68
|
+
/** Automatically capture Apple Search Ads AdServices token on iOS when available (default: `true`). */
|
|
69
|
+
autoCaptureAdServicesToken?: boolean;
|
|
70
|
+
/** Optional platform override sent in event payloads (defaults to `'IOS'` or `'ANDROID'`). */
|
|
71
|
+
platform?: CavlynPlatformName;
|
|
72
|
+
/** Optional persistent storage adapter (e.g., AsyncStorage) for Expo Go / JS-only runtimes. */
|
|
73
|
+
storage?: CavlynStorage;
|
|
74
|
+
/** Optional custom fetch implementation (defaults to global `fetch`). */
|
|
75
|
+
fetch?: FetchLike;
|
|
76
|
+
/** Optional native module override (primarily for testing). */
|
|
77
|
+
nativeModule?: CavlynNativeModule | null;
|
|
78
|
+
/** Enable diagnostic logging via `console.debug` (default: `false`). */
|
|
79
|
+
debug?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Parsed UTM attribution parameters extracted from a DynamicLink.
|
|
84
|
+
*/
|
|
85
|
+
export interface UtmParameters {
|
|
86
|
+
source?: string;
|
|
87
|
+
medium?: string;
|
|
88
|
+
campaign?: string;
|
|
89
|
+
term?: string;
|
|
90
|
+
content?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Attribution data attached to an opened Universal Link, App Link, or custom scheme URL.
|
|
95
|
+
*/
|
|
96
|
+
export interface DynamicLink {
|
|
97
|
+
/** Full incoming URL string. */
|
|
98
|
+
uri: string;
|
|
99
|
+
/** Normalized pathname (e.g., `/products/123`). */
|
|
100
|
+
path: string;
|
|
101
|
+
/** Backend-issued dynamic link UUID (lowercased). */
|
|
102
|
+
linkId: string;
|
|
103
|
+
/** Optional backend-issued click UUID (lowercased). */
|
|
104
|
+
clickId?: string;
|
|
105
|
+
/** All remaining query parameters (excluding `linkId`/`link_id`/`clickId`/`click_id`). */
|
|
106
|
+
parameters: Record<string, string>;
|
|
107
|
+
/** Convenience parsed UTM parameters. */
|
|
108
|
+
utm: UtmParameters;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Response payload from `GET /api/v1/links/resolve`.
|
|
113
|
+
*/
|
|
114
|
+
export interface ResolvedDynamicLink {
|
|
115
|
+
id: string;
|
|
116
|
+
appId: string;
|
|
117
|
+
shortCode: string;
|
|
118
|
+
customAlias?: string;
|
|
119
|
+
deepPath: string;
|
|
120
|
+
deepQuery?: string;
|
|
121
|
+
status: 'ACTIVE' | 'DISABLED' | string;
|
|
122
|
+
expiresAt?: string;
|
|
123
|
+
campaignId?: string;
|
|
124
|
+
queryParams: Record<string, string>;
|
|
125
|
+
metadata?: Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Optional overrides when tracking a custom conversion event.
|
|
130
|
+
*/
|
|
131
|
+
export interface TrackEventOptions {
|
|
132
|
+
/** Override attribution linkId (defaults to current/initial attribution link). */
|
|
133
|
+
linkId?: string;
|
|
134
|
+
/** Override attribution clickId (defaults to current/initial attribution link). */
|
|
135
|
+
clickId?: string;
|
|
136
|
+
/** Optional custom idempotency key (defaults to random UUID). */
|
|
137
|
+
idempotencyKey?: string;
|
|
138
|
+
/** Optional event timestamp (defaults to `new Date()`). */
|
|
139
|
+
occurredAt?: Date | string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Typed payload for V2 commerce events (`PRODUCT_VIEW`, `ADD_TO_CART`, `PURCHASE`, etc.).
|
|
144
|
+
*/
|
|
145
|
+
export interface CommerceEventInput {
|
|
146
|
+
type: CommerceEventType;
|
|
147
|
+
eventName?: string;
|
|
148
|
+
storeId?: string;
|
|
149
|
+
productId?: string;
|
|
150
|
+
variantId?: string;
|
|
151
|
+
orderId?: string;
|
|
152
|
+
currency?: string;
|
|
153
|
+
value?: number;
|
|
154
|
+
quantity?: number;
|
|
155
|
+
metadata?: Record<string, unknown>;
|
|
156
|
+
linkId?: string;
|
|
157
|
+
clickId?: string;
|
|
158
|
+
idempotencyKey?: string;
|
|
159
|
+
occurredAt?: Date | string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Wire payload sent to `POST /api/v1/events`.
|
|
164
|
+
*/
|
|
165
|
+
export interface EventApiPayload {
|
|
166
|
+
linkId: string;
|
|
167
|
+
type: CavlynEventType;
|
|
168
|
+
clickId?: string;
|
|
169
|
+
installId: string;
|
|
170
|
+
platform: CavlynPlatformName;
|
|
171
|
+
eventName?: string;
|
|
172
|
+
occurredAt: string;
|
|
173
|
+
storeId?: string;
|
|
174
|
+
productId?: string;
|
|
175
|
+
variantId?: string;
|
|
176
|
+
orderId?: string;
|
|
177
|
+
currency?: string;
|
|
178
|
+
value?: number;
|
|
179
|
+
quantity?: number;
|
|
180
|
+
metadata?: Record<string, unknown>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type LinkListener = (link: DynamicLink) => void;
|
|
184
|
+
|
|
185
|
+
export interface LinkSubscription {
|
|
186
|
+
remove(): void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Native bridge payload serialized by iOS Swift and Android Kotlin native modules.
|
|
191
|
+
*/
|
|
192
|
+
export interface NativeLinkPayload {
|
|
193
|
+
uri: string;
|
|
194
|
+
linkId: string;
|
|
195
|
+
clickId?: string | null;
|
|
196
|
+
parameters?: Record<string, string> | null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Native module contract exposed as `NativeModules.CavlynReactNative`.
|
|
201
|
+
*/
|
|
202
|
+
export interface CavlynNativeModule {
|
|
203
|
+
initialize(apiKey: string, apiBaseUrl: string): Promise<void>;
|
|
204
|
+
handleUrl(url: string): Promise<NativeLinkPayload | null>;
|
|
205
|
+
initialLink(): Promise<NativeLinkPayload | null>;
|
|
206
|
+
currentLink(): Promise<NativeLinkPayload | null>;
|
|
207
|
+
trackEvent(name: string, properties: Record<string, unknown>): Promise<void>;
|
|
208
|
+
trackCommerceEvent?(payload: Record<string, unknown>): Promise<void>;
|
|
209
|
+
getAdServicesToken?(): Promise<string | null>;
|
|
210
|
+
recordAdServicesToken?(token: string): Promise<void>;
|
|
211
|
+
getInstallationId?(): Promise<string>;
|
|
212
|
+
addListener?(eventName: string): void;
|
|
213
|
+
removeListeners?(count: number): void;
|
|
214
|
+
}
|