@apex-inc/capacitor-plugin 0.3.8 → 2.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/android/build.gradle +4 -2
- package/android/src/main/AndroidManifest.xml +35 -3
- package/android/src/main/java/inc/apex/capacitor/ApexCapacitorPlugin.kt +403 -6
- package/android/src/main/java/inc/apex/capacitor/ApexEvents.kt +122 -0
- package/android/src/main/java/inc/apex/capacitor/ApexFirebaseMessagingService.kt +99 -0
- package/android/src/main/java/inc/apex/capacitor/NativeBatchSender.kt +260 -0
- package/dist/batch-sender.d.ts +12 -0
- package/dist/batch-sender.d.ts.map +1 -1
- package/dist/batch-sender.js +25 -0
- package/dist/batch-sender.js.map +1 -1
- package/dist/cart-helpers.d.ts +63 -0
- package/dist/cart-helpers.d.ts.map +1 -0
- package/dist/cart-helpers.js +50 -0
- package/dist/cart-helpers.js.map +1 -0
- package/dist/definitions.d.ts +166 -2
- package/dist/definitions.d.ts.map +1 -1
- package/dist/esm/batch-sender.d.ts +12 -0
- package/dist/esm/batch-sender.d.ts.map +1 -1
- package/dist/esm/batch-sender.js +25 -0
- package/dist/esm/batch-sender.js.map +1 -1
- package/dist/esm/cart-helpers.d.ts +63 -0
- package/dist/esm/cart-helpers.d.ts.map +1 -0
- package/dist/esm/cart-helpers.js +44 -0
- package/dist/esm/cart-helpers.js.map +1 -0
- package/dist/esm/definitions.d.ts +166 -2
- package/dist/esm/definitions.d.ts.map +1 -1
- package/dist/esm/events.d.ts +85 -0
- package/dist/esm/events.d.ts.map +1 -0
- package/dist/esm/events.js +96 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/index.d.ts +4 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +19 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/offline-queue.d.ts +15 -0
- package/dist/esm/offline-queue.d.ts.map +1 -1
- package/dist/esm/offline-queue.js +35 -0
- package/dist/esm/offline-queue.js.map +1 -1
- package/dist/esm/screen-view.d.ts +18 -0
- package/dist/esm/screen-view.d.ts.map +1 -0
- package/dist/esm/screen-view.js +28 -0
- package/dist/esm/screen-view.js.map +1 -0
- package/dist/esm/web.d.ts +29 -1
- package/dist/esm/web.d.ts.map +1 -1
- package/dist/esm/web.js +182 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/events.d.ts +85 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +99 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/offline-queue.d.ts +15 -0
- package/dist/offline-queue.d.ts.map +1 -1
- package/dist/offline-queue.js +35 -0
- package/dist/offline-queue.js.map +1 -1
- package/dist/screen-view.d.ts +18 -0
- package/dist/screen-view.d.ts.map +1 -0
- package/dist/screen-view.js +31 -0
- package/dist/screen-view.js.map +1 -0
- package/dist/web.d.ts +29 -1
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +182 -3
- package/dist/web.js.map +1 -1
- package/ios/Sources/ApexCapacitorPlugin/ApexEvents.swift +124 -0
- package/ios/Sources/ApexCapacitorPlugin/BatchSender.swift +18 -0
- package/ios/Sources/ApexCapacitorPlugin/OfflineQueue.swift +19 -0
- package/ios/Sources/ApexCapacitorPlugin/PushNotificationManager.swift +47 -0
- package/ios/Sources/ApexCapacitorPluginBridge/ApexCapacitorPlugin.swift +280 -20
- package/package.json +1 -1
package/dist/definitions.d.ts
CHANGED
|
@@ -40,6 +40,30 @@ export interface PushReceivedEvent {
|
|
|
40
40
|
}
|
|
41
41
|
/** Supported tracking platforms. */
|
|
42
42
|
export type ApexPlatform = "ios" | "android" | "web";
|
|
43
|
+
/**
|
|
44
|
+
* Build source the app was installed from. Detected by the SDK from
|
|
45
|
+
* `AppTransaction` / receipt URL (iOS) or installer package source +
|
|
46
|
+
* `BuildConfig.DEBUG` (Android).
|
|
47
|
+
*
|
|
48
|
+
* - `xcode-debug` — Xcode-attached debug build (iOS) or Gradle DEBUG (Android).
|
|
49
|
+
* Also returned for iOS Simulator regardless of `sandboxReceipt` presence.
|
|
50
|
+
* - `testflight` — iOS TestFlight build (sandbox receipt, no debugger attached).
|
|
51
|
+
* - `app-store` — production App Store build (valid receipt).
|
|
52
|
+
* - `play-internal` — Play Console closed test track (currently only reachable
|
|
53
|
+
* via explicit `Apex.initialize({ releaseChannel: "play-internal" })`
|
|
54
|
+
* override; server-side reconciliation via Play Console API ships in MMP-069).
|
|
55
|
+
* - `play-production` — installed via Google Play Store.
|
|
56
|
+
* - `sideloaded` — installed via APK download / ADB / unknown installer.
|
|
57
|
+
* - `unknown` — fallback when no signal is available (enterprise / in-house
|
|
58
|
+
* iOS distribution, AppTransaction `.unverified` with no receipt URL).
|
|
59
|
+
*
|
|
60
|
+
* Why this matters: the SDK auto-tags every event so dashboards, audiences,
|
|
61
|
+
* billing, and the push composer route to the right "Dev / Beta / Production"
|
|
62
|
+
* bucket without merchants flipping a flag.
|
|
63
|
+
*/
|
|
64
|
+
export type ReleaseChannel = "xcode-debug" | "testflight" | "app-store" | "play-internal" | "play-production" | "sideloaded" | "unknown";
|
|
65
|
+
/** How {@link ReleaseChannel} was determined. */
|
|
66
|
+
export type ReleaseChannelSource = "auto" | "override" | "play-api";
|
|
43
67
|
/** Fallback source when the primary advertising identifier is unavailable. */
|
|
44
68
|
export type AdvertisingIdFallback = "idfv" | "android_id" | null;
|
|
45
69
|
/** Coarse SKAN 4.0 conversion value. */
|
|
@@ -64,6 +88,46 @@ export interface ApexEvent {
|
|
|
64
88
|
utmCampaign?: string;
|
|
65
89
|
experimentId?: string;
|
|
66
90
|
variant?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Per-event override for the SDK-managed visitor id. Normally
|
|
93
|
+
* stamped by the SDK from `getVisitorId()`; setting this on a
|
|
94
|
+
* track payload is rare. The server requires a visitor id at the
|
|
95
|
+
* top level of every event (otherwise the event is accepted into
|
|
96
|
+
* the SDK firehose but never reaches the tracking-event store the
|
|
97
|
+
* dashboards read from), so the SDK fills it in automatically.
|
|
98
|
+
*/
|
|
99
|
+
visitorId?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Source platform. Stamped automatically by the SDK at `track()`
|
|
102
|
+
* time so each event carries its origin (`ios` / `android` / `web`)
|
|
103
|
+
* without relying solely on the `X-Apex-Platform` HTTP header. The
|
|
104
|
+
* server prefers the per-event field over the header when both
|
|
105
|
+
* differ.
|
|
106
|
+
*/
|
|
107
|
+
platform?: ApexPlatform;
|
|
108
|
+
/**
|
|
109
|
+
* MMP-080/081 — runtime context. Stamped automatically by the SDK
|
|
110
|
+
* based on which plugin variant emitted the event:
|
|
111
|
+
*
|
|
112
|
+
* - Native iOS plugin → `native-ios`
|
|
113
|
+
* - Native Android plugin → `native-android`
|
|
114
|
+
* - Web fallback (no native plugin) → `capacitor-webview`
|
|
115
|
+
*
|
|
116
|
+
* Server-side ingest validates these values; callers almost never
|
|
117
|
+
* set this directly. The dashboard groups events by `clientType` to
|
|
118
|
+
* distinguish "Capacitor app running natively" from "Capacitor app
|
|
119
|
+
* running in a browser fallback" — the latter loses IDFA, store
|
|
120
|
+
* receipts, install referrer, and deep links, which usually means
|
|
121
|
+
* the merchant forgot to wire the native plugin.
|
|
122
|
+
*/
|
|
123
|
+
clientType?: "capacitor-webview" | "native-ios" | "native-android" | "browser-tab" | "installed-pwa" | "server";
|
|
124
|
+
/**
|
|
125
|
+
* When true, the event is routed to the test-event store and is
|
|
126
|
+
* excluded from production analytics. The SDK stamps this from
|
|
127
|
+
* `initialize({ testMode })` / `setTestMode({ enabled })` — callers
|
|
128
|
+
* normally shouldn't set it directly on a `track()` call.
|
|
129
|
+
*/
|
|
130
|
+
testMode?: boolean;
|
|
67
131
|
/** Typed payload for in-app purchases. */
|
|
68
132
|
purchase?: {
|
|
69
133
|
productId: string;
|
|
@@ -93,6 +157,26 @@ export interface InitializeOptions {
|
|
|
93
157
|
projectKey: string;
|
|
94
158
|
/** API base URL. Defaults to `https://api.apex.inc`. */
|
|
95
159
|
apiUrl?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Optional workspace-bound API key (`apex_uk_*` or `apex_sk_*`).
|
|
162
|
+
*
|
|
163
|
+
* When set, the plugin attaches it as `x-apex-api-key` on every
|
|
164
|
+
* outbound request to `/api/events` and `/api/identity/stitch`. The
|
|
165
|
+
* server uses this to authorize quarantine-mode auto-stitch
|
|
166
|
+
* (Phase 2-quarantine) and explicit `identify()` calls
|
|
167
|
+
* (Phase 2-prep `stitchIdentity` verified mode).
|
|
168
|
+
*
|
|
169
|
+
* Without an API key, events still flow but auto-stitch is
|
|
170
|
+
* suppressed and `identify()` calls are accepted only for projects
|
|
171
|
+
* whose visitor->Contact link can be derived from the request
|
|
172
|
+
* project key alone.
|
|
173
|
+
*
|
|
174
|
+
* IMPORTANT: only embed API keys in mobile apps when the workspace
|
|
175
|
+
* is dedicated to that app. Treat the value like a publishable key,
|
|
176
|
+
* not a secret — assume it will leak via reverse-engineering. Apex
|
|
177
|
+
* rate-limits per key + per visitor to make leaked keys low-yield.
|
|
178
|
+
*/
|
|
179
|
+
apiKey?: string;
|
|
96
180
|
/** Tag subsequent events as test mode (excluded from production analytics). */
|
|
97
181
|
testMode?: boolean;
|
|
98
182
|
/** Session timeout in minutes. Default 30. */
|
|
@@ -101,6 +185,57 @@ export interface InitializeOptions {
|
|
|
101
185
|
offlineQueueMaxSize?: number;
|
|
102
186
|
/** Enable verbose console logging. Default false. */
|
|
103
187
|
debug?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* MMP-061 — manual override for {@link ReleaseChannel}.
|
|
190
|
+
*
|
|
191
|
+
* On Android this is the canonical way to flag closed-test builds
|
|
192
|
+
* (Play does NOT expose internal/closed/open tracks at the device
|
|
193
|
+
* level). Wire it through your `BuildConfig.RELEASE_CHANNEL` per
|
|
194
|
+
* build flavor so each flavor reports the right channel without
|
|
195
|
+
* thinking about it. Once a merchant connects their Play Console via
|
|
196
|
+
* MMP-069, server-side reconciliation takes over and the override
|
|
197
|
+
* becomes optional.
|
|
198
|
+
*
|
|
199
|
+
* On iOS this is **ignored** — `AppTransaction` / receipt URL are
|
|
200
|
+
* authoritative. We log a console warning when an override is passed
|
|
201
|
+
* on iOS so the discrepancy is visible during development; the
|
|
202
|
+
* server stamps `releaseChannelSource: "auto"` regardless.
|
|
203
|
+
*/
|
|
204
|
+
releaseChannel?: ReleaseChannel;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Options for {@link ApexCapacitorPlugin.identify}.
|
|
208
|
+
*
|
|
209
|
+
* Phase 2-SDK (council-revised mobile dashboard plan). Identify is the
|
|
210
|
+
* explicit, first-class call merchants use to bind a known user to the
|
|
211
|
+
* current visitor session. The server resolves the email (and optional
|
|
212
|
+
* userId) to an Apex Contact and stamps `verifiedAt = now`, promoting
|
|
213
|
+
* any previously-quarantined Contact for this visitor + lighting up
|
|
214
|
+
* affiliate stamping, scoring, and journey dispatch.
|
|
215
|
+
*
|
|
216
|
+
* This is intentionally distinct from `track({ type: "user_signed_up",
|
|
217
|
+
* data: { email } })`. Track is a fire-and-forget event; identify is
|
|
218
|
+
* the durable identity gesture. The two interact: a server-side
|
|
219
|
+
* auto-stitch on `user_signed_up` lands the Contact in quarantine; an
|
|
220
|
+
* `identify()` call promotes it to verified.
|
|
221
|
+
*/
|
|
222
|
+
export interface IdentifyOptions {
|
|
223
|
+
/**
|
|
224
|
+
* Email address — the canonical identifier Apex uses to merge
|
|
225
|
+
* anonymous visitor sessions into a known Contact. Required.
|
|
226
|
+
*/
|
|
227
|
+
email: string;
|
|
228
|
+
/**
|
|
229
|
+
* Optional merchant-side stable user id (e.g. a row id from the
|
|
230
|
+
* merchant's user table). When provided, Apex stores it on the
|
|
231
|
+
* Contact so cross-platform stitching can use both email + userId.
|
|
232
|
+
*/
|
|
233
|
+
userId?: string;
|
|
234
|
+
/**
|
|
235
|
+
* Optional metadata to attach to the identify event (e.g. signup
|
|
236
|
+
* source, plan tier, locale). Merged into the Contact's traits.
|
|
237
|
+
*/
|
|
238
|
+
traits?: Record<string, unknown>;
|
|
104
239
|
}
|
|
105
240
|
/** Return value of {@link ApexCapacitorPlugin.getAdvertisingId}. */
|
|
106
241
|
export interface AdvertisingIdResult {
|
|
@@ -118,6 +253,14 @@ export interface DeviceInfo {
|
|
|
118
253
|
bundleId: string;
|
|
119
254
|
timezone: string;
|
|
120
255
|
locale: string;
|
|
256
|
+
/**
|
|
257
|
+
* MMP-061 — the detected build source (or override). Surfaced so
|
|
258
|
+
* sample apps + developer-facing UIs can show a "Running: TestFlight"
|
|
259
|
+
* badge without round-tripping to the server.
|
|
260
|
+
*/
|
|
261
|
+
releaseChannel?: ReleaseChannel;
|
|
262
|
+
/** How {@link DeviceInfo.releaseChannel} was determined. */
|
|
263
|
+
releaseChannelSource?: ReleaseChannelSource;
|
|
121
264
|
}
|
|
122
265
|
/** Summary of offline-queue state. */
|
|
123
266
|
export interface QueueStatus {
|
|
@@ -187,8 +330,12 @@ export interface ApexCapacitorPlugin {
|
|
|
187
330
|
* listener AND is auto-registered with Apex via `POST /api/mobile/push-token`
|
|
188
331
|
* so the dashboard sees it immediately.
|
|
189
332
|
*
|
|
190
|
-
* On Android
|
|
191
|
-
* `
|
|
333
|
+
* On Android this fetches the FCM registration token via
|
|
334
|
+
* `FirebaseMessaging`, auto-registers it with Apex via
|
|
335
|
+
* `POST /api/mobile/push-token`, and fires `pushTokenReceived`. (The
|
|
336
|
+
* app must include a `google-services.json` and the host must be a
|
|
337
|
+
* Firebase project.) On web this remains a no-op returning
|
|
338
|
+
* `permission: "denied"`.
|
|
192
339
|
*/
|
|
193
340
|
registerForPushNotifications(): Promise<PushRegistrationResult>;
|
|
194
341
|
/**
|
|
@@ -219,6 +366,23 @@ export interface ApexCapacitorPlugin {
|
|
|
219
366
|
setVisitorId(options: {
|
|
220
367
|
visitorId: string;
|
|
221
368
|
}): Promise<void>;
|
|
369
|
+
/**
|
|
370
|
+
* Identifies the current visitor as a known user. Resolves the email
|
|
371
|
+
* to an Apex Contact (creating it if needed) and stamps the
|
|
372
|
+
* resulting Contact as `verified` so downstream pipelines (affiliate
|
|
373
|
+
* stamping, scoring, journey dispatch) can run.
|
|
374
|
+
*
|
|
375
|
+
* Typical placement:
|
|
376
|
+
* - Right after a user submits a signup form
|
|
377
|
+
* - Right after a user signs in
|
|
378
|
+
* - On app start when a known authenticated user is hydrated from
|
|
379
|
+
* your auth provider
|
|
380
|
+
*
|
|
381
|
+
* Idempotent — calling identify with the same email + visitor is
|
|
382
|
+
* safe. The server rate-limits per visitor (1 req/sec) to prevent
|
|
383
|
+
* identity-flip-flop attacks.
|
|
384
|
+
*/
|
|
385
|
+
identify(options: IdentifyOptions): Promise<void>;
|
|
222
386
|
/**
|
|
223
387
|
* Updates the SKAdNetwork 4.0 postback conversion value. No-op on Android.
|
|
224
388
|
* `fineValue` is 0-63 (fine conversion value); `coarseValue` is optional
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../src/definitions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,0DAA0D;AAC1D,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,QAAQ,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAElF,qFAAqF;AACrF,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEpE,0EAA0E;AAC1E,MAAM,WAAW,sBAAsB;IACrC,oDAAoD;IACpD,UAAU,EAAE,oBAAoB,CAAC;IACjC;;;;;OAKG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IA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AAC,CAAC;IAEjC;;;;;OAKG;IACH,WAAW,CACT,SAAS,EAAE,aAAa,EACxB,YAAY,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAC/C,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEjC,gEAAgE;IAChE,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC"}
|
|
@@ -16,6 +16,12 @@ export interface BatchSenderOptions {
|
|
|
16
16
|
apiUrl?: string;
|
|
17
17
|
/** Project key attached to each request. Required. */
|
|
18
18
|
projectKey: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional workspace-bound SDK key (`apex_uk_*` / `apex_sk_*`).
|
|
21
|
+
* Forwarded as `x-apex-api-key` on every batch so the server can
|
|
22
|
+
* authorize quarantine-mode auto-stitch.
|
|
23
|
+
*/
|
|
24
|
+
apiKey?: string;
|
|
19
25
|
/** Max events sent per batch. Default 50. */
|
|
20
26
|
batchSize?: number;
|
|
21
27
|
/** Max retry attempts before giving up on a batch. Default 3. */
|
|
@@ -40,6 +46,7 @@ export interface FlushResult {
|
|
|
40
46
|
export declare class BatchSender {
|
|
41
47
|
private readonly apiUrl;
|
|
42
48
|
private readonly projectKey;
|
|
49
|
+
private readonly apiKey?;
|
|
43
50
|
/** Exposed for callers (e.g. getVariant) that need to address the same server. */
|
|
44
51
|
getApiUrl(): string;
|
|
45
52
|
private readonly batchSize;
|
|
@@ -54,6 +61,11 @@ export declare class BatchSender {
|
|
|
54
61
|
* Flushes as many events from the queue as possible, one batch at a time,
|
|
55
62
|
* with exponential backoff on retryable failures. Stops early on
|
|
56
63
|
* non-retryable errors (400/401/403) and leaves remaining events queued.
|
|
64
|
+
*
|
|
65
|
+
* MOBX-005 (post-mortem #5) — every flush starts with queue hygiene:
|
|
66
|
+
* events older than 7 days or with more than 20 failed delivery
|
|
67
|
+
* attempts are evicted so a poisoned head can never block fresh
|
|
68
|
+
* events indefinitely.
|
|
57
69
|
*/
|
|
58
70
|
flush(queue: OfflineQueue): Promise<FlushResult>;
|
|
59
71
|
private sendBatchWithRetry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sender.d.ts","sourceRoot":"","sources":["../../src/batch-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,iBAAiB,CAAC;AAEjE,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,sDAAsD;IACtD,cAAc,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,KAAK,CAAC;IAC3C,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;
|
|
1
|
+
{"version":3,"file":"batch-sender.d.ts","sourceRoot":"","sources":["../../src/batch-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,iBAAiB,CA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C,CAA4B;IAC5D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;gBAEpB,OAAO,EAAE,kBAAkB;IAkBvC;;;;;;;;;OASG;IACG,KAAK,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;YA8CxC,kBAAkB;YAyClB,SAAS;CA2BxB"}
|
package/dist/esm/batch-sender.js
CHANGED
|
@@ -18,6 +18,7 @@ export class BatchSender {
|
|
|
18
18
|
constructor(options) {
|
|
19
19
|
this.apiUrl = (options.apiUrl ?? "https://api.apex.inc").replace(/\/+$/, "");
|
|
20
20
|
this.projectKey = options.projectKey;
|
|
21
|
+
this.apiKey = options.apiKey;
|
|
21
22
|
this.batchSize = options.batchSize ?? 50;
|
|
22
23
|
this.maxRetries = options.maxRetries ?? 3;
|
|
23
24
|
this.baseBackoffMs = options.baseBackoffMs ?? 1000;
|
|
@@ -34,11 +35,28 @@ export class BatchSender {
|
|
|
34
35
|
* Flushes as many events from the queue as possible, one batch at a time,
|
|
35
36
|
* with exponential backoff on retryable failures. Stops early on
|
|
36
37
|
* non-retryable errors (400/401/403) and leaves remaining events queued.
|
|
38
|
+
*
|
|
39
|
+
* MOBX-005 (post-mortem #5) — every flush starts with queue hygiene:
|
|
40
|
+
* events older than 7 days or with more than 20 failed delivery
|
|
41
|
+
* attempts are evicted so a poisoned head can never block fresh
|
|
42
|
+
* events indefinitely.
|
|
37
43
|
*/
|
|
38
44
|
async flush(queue) {
|
|
39
45
|
let flushed = 0;
|
|
40
46
|
let attemptedBatches = 0;
|
|
41
47
|
let lastError;
|
|
48
|
+
try {
|
|
49
|
+
const evicted = await queue.evictStale({
|
|
50
|
+
maxAttempts: 20,
|
|
51
|
+
maxAgeMs: 7 * 24 * 60 * 60 * 1000,
|
|
52
|
+
});
|
|
53
|
+
if (evicted > 0 && this.debug) {
|
|
54
|
+
console.warn(`[apex-capacitor] evicted ${evicted} stale event(s) from the offline queue (TTL 7d / 20 attempts)`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
/* hygiene is best-effort — never block the flush */
|
|
59
|
+
}
|
|
42
60
|
while (true) {
|
|
43
61
|
const batch = await queue.peek(this.batchSize);
|
|
44
62
|
if (batch.length === 0)
|
|
@@ -105,6 +123,13 @@ export class BatchSender {
|
|
|
105
123
|
if (this.platformHeader) {
|
|
106
124
|
headers["X-Apex-Platform"] = this.platformHeader;
|
|
107
125
|
}
|
|
126
|
+
if (this.apiKey) {
|
|
127
|
+
// Phase 2-quarantine — workspace-bound SDK key. The server uses
|
|
128
|
+
// this to authorize auto-stitch on `user_signed_up` /
|
|
129
|
+
// `user_identified`. Missing key means events still flow but
|
|
130
|
+
// auto-stitch is suppressed (the fail-closed default).
|
|
131
|
+
headers["x-apex-api-key"] = this.apiKey;
|
|
132
|
+
}
|
|
108
133
|
return this.fetchFn(`${this.apiUrl}/api/events`, {
|
|
109
134
|
method: "POST",
|
|
110
135
|
headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sender.js","sourceRoot":"","sources":["../../src/batch-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"batch-sender.js","sourceRoot":"","sources":["../../src/batch-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAsCH,MAAM,OAAO,WAAW;IAKtB,kFAAkF;IAClF,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAUD,YAAY,OAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,sBAAsB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI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;gBACJ,CAAC;gBACD,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAC7D,CAAC;IAEO,KAAK,CAAC,SAAS,CAAC,KAAoB;QAC1C,MAAM,IAAI,GAAG;YACX,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;SAClC,CAAC;QAEF,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,oBAAoB,EAAE,IAAI,CAAC,UAAU;SACtC,CAAC;QACF,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC;QACnD,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,gEAAgE;YAChE,sDAAsD;YACtD,6DAA6D;YAC7D,uDAAuD;YACvD,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1C,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,aAAa,EAAE;YAC/C,MAAM,EAAE,MAAM;YACd,OAAO;YACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Journey Exit Semantics — SDK catch-up.
|
|
3
|
+
*
|
|
4
|
+
* Typed cart helpers. Operators who reach for "track an add-to-cart"
|
|
5
|
+
* with the raw `Apex.track({ type: "add_to_cart", data: { ... } })`
|
|
6
|
+
* have to invent the data shape — which means the server-side cart
|
|
7
|
+
* rollup writer (Phase 2) reads inconsistent SKUs/qtys/IDs and the
|
|
8
|
+
* `Contact.cart` state drifts.
|
|
9
|
+
*
|
|
10
|
+
* These helpers emit the canonical shape the rollup expects so
|
|
11
|
+
* branches on `cart.itemCount` / `cart.valueCents` light up
|
|
12
|
+
* automatically with zero downstream configuration.
|
|
13
|
+
*
|
|
14
|
+
* All helpers delegate to `Apex.track()` so the existing offline
|
|
15
|
+
* queue / batch-sender / session-manager paths stay unchanged.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Canonical line shape consumed by the server-side cart rollup. Mirrors
|
|
19
|
+
* the same interface in `@apex-inc/sdk` for documentation parity.
|
|
20
|
+
*/
|
|
21
|
+
export interface CartLine {
|
|
22
|
+
/** Merchant SKU. Required for stable identity. */
|
|
23
|
+
sku: string;
|
|
24
|
+
/** Items in the line. Negative deltas clamp at 0 server-side. */
|
|
25
|
+
qty: number;
|
|
26
|
+
priceCents?: number;
|
|
27
|
+
currency?: string;
|
|
28
|
+
/** Display name for the Contact-drawer rendering. */
|
|
29
|
+
name?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Stable line identifier when one SKU can have multiple cart lines
|
|
32
|
+
* (e.g. configurable products with different variants). Defaults
|
|
33
|
+
* to `sku` server-side when omitted.
|
|
34
|
+
*/
|
|
35
|
+
stableLineId?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Add an item to the cart. */
|
|
38
|
+
export declare function trackCartAdd(line: CartLine): Promise<void>;
|
|
39
|
+
/** Remove an item from the cart. */
|
|
40
|
+
export declare function trackCartRemove(opts: {
|
|
41
|
+
sku: string;
|
|
42
|
+
qty: number;
|
|
43
|
+
stableLineId?: string;
|
|
44
|
+
cartValueCents?: number;
|
|
45
|
+
currency?: string;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Full-cart reconciliation. Use whenever the app loads the source-of-
|
|
49
|
+
* truth cart (login restore, foreground refresh, cart screen mount).
|
|
50
|
+
* The rollup writer replaces stored lines wholesale on this event,
|
|
51
|
+
* which heals drift caused by missed add/remove deltas.
|
|
52
|
+
*/
|
|
53
|
+
export declare function trackCartSnapshot(opts: {
|
|
54
|
+
lines: CartLine[];
|
|
55
|
+
currency?: string;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
/** Clear the cart on successful checkout. */
|
|
58
|
+
export declare function trackCheckoutCompleted(opts: {
|
|
59
|
+
orderId: string;
|
|
60
|
+
totalCents: number;
|
|
61
|
+
currency?: string;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
//# sourceMappingURL=cart-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart-helpers.d.ts","sourceRoot":"","sources":["../../src/cart-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,iEAAiE;IACjE,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,+BAA+B;AAC/B,wBAAsB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAED,oCAAoC;AACpC,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhB;AAED,6CAA6C;AAC7C,wBAAsB,sBAAsB,CAAC,IAAI,EAAE;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Journey Exit Semantics — SDK catch-up.
|
|
3
|
+
*
|
|
4
|
+
* Typed cart helpers. Operators who reach for "track an add-to-cart"
|
|
5
|
+
* with the raw `Apex.track({ type: "add_to_cart", data: { ... } })`
|
|
6
|
+
* have to invent the data shape — which means the server-side cart
|
|
7
|
+
* rollup writer (Phase 2) reads inconsistent SKUs/qtys/IDs and the
|
|
8
|
+
* `Contact.cart` state drifts.
|
|
9
|
+
*
|
|
10
|
+
* These helpers emit the canonical shape the rollup expects so
|
|
11
|
+
* branches on `cart.itemCount` / `cart.valueCents` light up
|
|
12
|
+
* automatically with zero downstream configuration.
|
|
13
|
+
*
|
|
14
|
+
* All helpers delegate to `Apex.track()` so the existing offline
|
|
15
|
+
* queue / batch-sender / session-manager paths stay unchanged.
|
|
16
|
+
*/
|
|
17
|
+
import { Apex } from "./index";
|
|
18
|
+
import { ApexEvents } from "./events";
|
|
19
|
+
/** Add an item to the cart. */
|
|
20
|
+
export async function trackCartAdd(line) {
|
|
21
|
+
await Apex.track({ type: ApexEvents.AddToCart, data: { ...line } });
|
|
22
|
+
}
|
|
23
|
+
/** Remove an item from the cart. */
|
|
24
|
+
export async function trackCartRemove(opts) {
|
|
25
|
+
await Apex.track({ type: ApexEvents.RemoveFromCart, data: { ...opts } });
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Full-cart reconciliation. Use whenever the app loads the source-of-
|
|
29
|
+
* truth cart (login restore, foreground refresh, cart screen mount).
|
|
30
|
+
* The rollup writer replaces stored lines wholesale on this event,
|
|
31
|
+
* which heals drift caused by missed add/remove deltas.
|
|
32
|
+
*/
|
|
33
|
+
export async function trackCartSnapshot(opts) {
|
|
34
|
+
// `cart_snapshot` isn't in the published ApexEvents enum yet (it's
|
|
35
|
+
// a Phase-2 addition). Passing the canonical string lets older
|
|
36
|
+
// plugin versions still emit it cleanly; the server route accepts
|
|
37
|
+
// arbitrary string event types.
|
|
38
|
+
await Apex.track({ type: "cart_snapshot", data: { ...opts } });
|
|
39
|
+
}
|
|
40
|
+
/** Clear the cart on successful checkout. */
|
|
41
|
+
export async function trackCheckoutCompleted(opts) {
|
|
42
|
+
await Apex.track({ type: "checkout_completed", data: { ...opts } });
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=cart-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart-helpers.js","sourceRoot":"","sources":["../../src/cart-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAuBtC,+BAA+B;AAC/B,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAc;IAC/C,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,oCAAoC;AACpC,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAMrC;IACC,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,cAAc,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAGvC;IACC,mEAAmE;IACnE,+DAA+D;IAC/D,kEAAkE;IAClE,gCAAgC;IAChC,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,6CAA6C;AAC7C,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAI5C;IACC,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC"}
|