@wireai/activation 0.9.2 → 0.10.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/AGENTS.md +7 -0
- package/CHANGELOG.md +24 -0
- package/INTEGRATION_PROMPT.md +11 -1
- package/README.md +62 -0
- package/dist/analytics/index.d.mts +2 -2
- package/dist/analytics/index.d.ts +2 -2
- package/dist/analytics/index.js +39 -20
- package/dist/analytics/index.js.map +1 -1
- package/dist/analytics/index.mjs +38 -21
- package/dist/analytics/index.mjs.map +1 -1
- package/dist/{currentSession-Dj0cN3Rg.d.ts → currentSession-D0Vq7_VE.d.ts} +33 -4
- package/dist/{currentSession-CRRQLbAq.d.mts → currentSession-DdDkprpM.d.mts} +33 -4
- package/dist/index.d.mts +116 -3
- package/dist/index.d.ts +116 -3
- package/dist/index.js +155 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -22
- package/dist/index.mjs.map +1 -1
- package/dist/questionnaire/index.js +1 -2
- package/dist/questionnaire/index.js.map +1 -1
- package/dist/questionnaire/index.mjs +1 -2
- package/dist/questionnaire/index.mjs.map +1 -1
- package/llms.txt +1 -0
- package/package.json +1 -1
- package/src/activation/index.ts +24 -0
- package/src/activation/revalidation.ts +88 -0
- package/src/activation/useWireActivation.ts +70 -0
- package/src/activation/wireActivation.ts +156 -0
- package/src/analytics/currentSession.ts +41 -7
- package/src/analytics/eventQueue.ts +9 -28
- package/src/analytics/index.ts +7 -1
- package/src/analytics/reportClientEvent.ts +56 -10
- package/src/index.ts +18 -0
- package/src/questionnaire/transport.ts +1 -9
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StyleSheet, Easing, Animated, BackHandler, Modal, Pressable, Text, View, TouchableOpacity, KeyboardAvoidingView, ScrollView, useWindowDimensions, TextInput, Image, AccessibilityInfo, Platform, Dimensions, I18nManager, AppState, NativeModules, TurboModuleRegistry } from 'react-native';
|
|
2
|
-
import React18, { createContext, forwardRef, useRef, useState, useEffect, useCallback, useImperativeHandle, useMemo, useContext } from 'react';
|
|
2
|
+
import React18, { createContext, forwardRef, useRef, useState, useEffect, useCallback, useImperativeHandle, useMemo, useContext, useSyncExternalStore } from 'react';
|
|
3
3
|
import { useWireAIThread, useWireAIAction, ComponentRenderer, WireAIProvider } from 'wireai-rn';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
@@ -1501,22 +1501,38 @@ var readProgress = (response) => {
|
|
|
1501
1501
|
|
|
1502
1502
|
// src/analytics/reportClientEvent.ts
|
|
1503
1503
|
var makeSessionId = () => `wire_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
1504
|
-
var
|
|
1505
|
-
if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return;
|
|
1504
|
+
var buildEventsRequest = (target, events) => {
|
|
1505
|
+
if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return null;
|
|
1506
1506
|
try {
|
|
1507
1507
|
const url = `${target.serverUrl.replace(/\/$/, "")}/v1/events`;
|
|
1508
1508
|
const headers = { "Content-Type": "application/json" };
|
|
1509
1509
|
if (target.apiKey) headers.Authorization = `Bearer ${target.apiKey}`;
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1510
|
+
return { url, init: { method: "POST", headers, body: JSON.stringify({ events }) } };
|
|
1511
|
+
} catch {
|
|
1512
|
+
return null;
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
var reportClientEvents = (target, events) => {
|
|
1516
|
+
try {
|
|
1517
|
+
const req = buildEventsRequest(target, events);
|
|
1518
|
+
if (!req) return;
|
|
1519
|
+
void fetch(req.url, req.init).catch(() => {
|
|
1515
1520
|
});
|
|
1516
1521
|
} catch {
|
|
1517
1522
|
}
|
|
1518
1523
|
};
|
|
1519
1524
|
var reportClientEvent = (target, event) => reportClientEvents(target, [event]);
|
|
1525
|
+
var reportClientEventsAwait = async (target, events) => {
|
|
1526
|
+
try {
|
|
1527
|
+
const req = buildEventsRequest(target, events);
|
|
1528
|
+
if (!req) return false;
|
|
1529
|
+
const res = await fetch(req.url, req.init);
|
|
1530
|
+
return Boolean(res && res.ok);
|
|
1531
|
+
} catch {
|
|
1532
|
+
return false;
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
var reportClientEventAwait = (target, event) => reportClientEventsAwait(target, [event]);
|
|
1520
1536
|
|
|
1521
1537
|
// src/analytics/sendPreview.ts
|
|
1522
1538
|
var sendPreview = (target, { sessionId, userMessage }) => {
|
|
@@ -3279,13 +3295,18 @@ var collectDeviceContext = () => {
|
|
|
3279
3295
|
};
|
|
3280
3296
|
|
|
3281
3297
|
// src/analytics/currentSession.ts
|
|
3282
|
-
var
|
|
3298
|
+
var CURRENT_SESSION_ID_SLOT = /* @__PURE__ */ Symbol.for(
|
|
3299
|
+
"@wireai/activation:currentSessionId"
|
|
3300
|
+
);
|
|
3301
|
+
var globalSlot = globalThis;
|
|
3283
3302
|
var setCurrentSessionId = (id) => {
|
|
3284
|
-
if (typeof id === "string" && id.length > 0)
|
|
3303
|
+
if (typeof id === "string" && id.length > 0) {
|
|
3304
|
+
globalSlot[CURRENT_SESSION_ID_SLOT] = id;
|
|
3305
|
+
}
|
|
3285
3306
|
};
|
|
3286
|
-
var getCurrentSessionId = () =>
|
|
3307
|
+
var getCurrentSessionId = () => globalSlot[CURRENT_SESSION_ID_SLOT];
|
|
3287
3308
|
var resetCurrentSessionId = () => {
|
|
3288
|
-
|
|
3309
|
+
globalSlot[CURRENT_SESSION_ID_SLOT] = void 0;
|
|
3289
3310
|
};
|
|
3290
3311
|
|
|
3291
3312
|
// src/session/persistedSession.ts
|
|
@@ -4109,6 +4130,115 @@ var mintDeviceId = () => {
|
|
|
4109
4130
|
return `${AUTO_DEVICE_ID_PREFIX}${time}_${randomChunk()}${randomChunk()}`;
|
|
4110
4131
|
};
|
|
4111
4132
|
|
|
4133
|
+
// src/activation/revalidation.ts
|
|
4134
|
+
var REVALIDATION_SLOT = /* @__PURE__ */ Symbol.for(
|
|
4135
|
+
"@wireai/activation:activationRevalidation"
|
|
4136
|
+
);
|
|
4137
|
+
var globalSlot2 = globalThis;
|
|
4138
|
+
var store = () => {
|
|
4139
|
+
const existing = globalSlot2[REVALIDATION_SLOT];
|
|
4140
|
+
if (existing) return existing;
|
|
4141
|
+
const created = { version: 0, listeners: /* @__PURE__ */ new Set() };
|
|
4142
|
+
globalSlot2[REVALIDATION_SLOT] = created;
|
|
4143
|
+
return created;
|
|
4144
|
+
};
|
|
4145
|
+
var bumpActivationRevalidation = () => {
|
|
4146
|
+
const s = store();
|
|
4147
|
+
s.version += 1;
|
|
4148
|
+
for (const listener of Array.from(s.listeners)) {
|
|
4149
|
+
try {
|
|
4150
|
+
listener();
|
|
4151
|
+
} catch {
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
};
|
|
4155
|
+
var subscribeActivationRevalidation = (listener) => {
|
|
4156
|
+
const s = store();
|
|
4157
|
+
s.listeners.add(listener);
|
|
4158
|
+
return () => {
|
|
4159
|
+
s.listeners.delete(listener);
|
|
4160
|
+
};
|
|
4161
|
+
};
|
|
4162
|
+
var getActivationRevalidationVersion = () => store().version;
|
|
4163
|
+
var resetActivationRevalidation = () => {
|
|
4164
|
+
const s = store();
|
|
4165
|
+
s.version = 0;
|
|
4166
|
+
s.listeners.clear();
|
|
4167
|
+
};
|
|
4168
|
+
|
|
4169
|
+
// src/activation/wireActivation.ts
|
|
4170
|
+
var clean = (value) => {
|
|
4171
|
+
if (typeof value !== "string") return void 0;
|
|
4172
|
+
const trimmed = value.trim();
|
|
4173
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
4174
|
+
};
|
|
4175
|
+
var createWireActivation = (config) => {
|
|
4176
|
+
var _a2, _b;
|
|
4177
|
+
const target = { serverUrl: config.serverUrl, apiKey: config.apiKey };
|
|
4178
|
+
const explicitDeviceKey = (_b = clean(config.deviceKey)) != null ? _b : clean((_a2 = config.userContext) == null ? void 0 : _a2.deviceKey);
|
|
4179
|
+
let autoDeviceKey = explicitDeviceKey != null ? explicitDeviceKey : mintDeviceId();
|
|
4180
|
+
if (config.storage && !explicitDeviceKey) {
|
|
4181
|
+
const storage = config.storage;
|
|
4182
|
+
const key = deviceIdStorageKey(config.appId);
|
|
4183
|
+
void storage.getItem(key).then((saved) => {
|
|
4184
|
+
const persisted = clean(saved != null ? saved : void 0);
|
|
4185
|
+
if (persisted) autoDeviceKey = persisted;
|
|
4186
|
+
else void storage.setItem(key, autoDeviceKey).catch(() => {
|
|
4187
|
+
});
|
|
4188
|
+
}).catch(() => {
|
|
4189
|
+
});
|
|
4190
|
+
}
|
|
4191
|
+
const applyContext = (event) => {
|
|
4192
|
+
var _a3, _b2;
|
|
4193
|
+
const resolved = resolveUserContext(
|
|
4194
|
+
{ ...(_a3 = config.userContext) != null ? _a3 : {}, deviceKey: explicitDeviceKey != null ? explicitDeviceKey : autoDeviceKey },
|
|
4195
|
+
{ autoAppVersion: config.appVersion }
|
|
4196
|
+
);
|
|
4197
|
+
if (resolved.userContext) {
|
|
4198
|
+
event.user_context = { ...resolved.userContext, ...(_b2 = event.user_context) != null ? _b2 : {} };
|
|
4199
|
+
}
|
|
4200
|
+
if (resolved.userId && !event.user_id) event.user_id = resolved.userId;
|
|
4201
|
+
};
|
|
4202
|
+
const track = async (name2, meta) => {
|
|
4203
|
+
const sessionId = getCurrentSessionId();
|
|
4204
|
+
if (!clean(name2) || !sessionId) return false;
|
|
4205
|
+
const event = {
|
|
4206
|
+
event_type: "app_event",
|
|
4207
|
+
session_id: sessionId,
|
|
4208
|
+
question_key: name2
|
|
4209
|
+
};
|
|
4210
|
+
if (meta && Object.keys(meta).length > 0) event.meta = JSON.stringify(meta);
|
|
4211
|
+
applyContext(event);
|
|
4212
|
+
const ok = await reportClientEventAwait(target, event);
|
|
4213
|
+
if (ok) bumpActivationRevalidation();
|
|
4214
|
+
return ok;
|
|
4215
|
+
};
|
|
4216
|
+
return {
|
|
4217
|
+
track,
|
|
4218
|
+
get sessionId() {
|
|
4219
|
+
return getCurrentSessionId();
|
|
4220
|
+
},
|
|
4221
|
+
subscribeRevalidation: subscribeActivationRevalidation,
|
|
4222
|
+
getRevalidationVersion: getActivationRevalidationVersion
|
|
4223
|
+
};
|
|
4224
|
+
};
|
|
4225
|
+
var useActivationRevalidation = () => useSyncExternalStore(
|
|
4226
|
+
subscribeActivationRevalidation,
|
|
4227
|
+
getActivationRevalidationVersion,
|
|
4228
|
+
getActivationRevalidationVersion
|
|
4229
|
+
);
|
|
4230
|
+
var useWireActivation = (config) => {
|
|
4231
|
+
const ref = useRef(void 0);
|
|
4232
|
+
const prevKeys = useRef("");
|
|
4233
|
+
const currentKeys = `${config.serverUrl}|${config.apiKey}|${config.appId}|${config.deviceKey}`;
|
|
4234
|
+
if (!ref.current || prevKeys.current !== currentKeys) {
|
|
4235
|
+
prevKeys.current = currentKeys;
|
|
4236
|
+
ref.current = createWireActivation(config);
|
|
4237
|
+
}
|
|
4238
|
+
const revalidation = useActivationRevalidation();
|
|
4239
|
+
return { track: ref.current.track, sessionId: ref.current.sessionId, revalidation };
|
|
4240
|
+
};
|
|
4241
|
+
|
|
4112
4242
|
// src/session-analytics/reportSessionStart.ts
|
|
4113
4243
|
var SESSION_STARTED_EVENT = "app.session_started";
|
|
4114
4244
|
var _emitted = /* @__PURE__ */ new Set();
|
|
@@ -4429,9 +4559,8 @@ var createEventQueue = (options) => {
|
|
|
4429
4559
|
} catch {
|
|
4430
4560
|
}
|
|
4431
4561
|
})();
|
|
4432
|
-
const DROP_STATUSES = /* @__PURE__ */ new Set([400, 404, 413, 422]);
|
|
4433
4562
|
const postBatch = async (events) => {
|
|
4434
|
-
if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return
|
|
4563
|
+
if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return false;
|
|
4435
4564
|
const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
|
|
4436
4565
|
const timer = setTimeout(() => controller == null ? void 0 : controller.abort(), 15e3);
|
|
4437
4566
|
try {
|
|
@@ -4444,12 +4573,9 @@ var createEventQueue = (options) => {
|
|
|
4444
4573
|
body: JSON.stringify({ events }),
|
|
4445
4574
|
signal: controller == null ? void 0 : controller.signal
|
|
4446
4575
|
});
|
|
4447
|
-
|
|
4448
|
-
const status = res == null ? void 0 : res.status;
|
|
4449
|
-
if (typeof status === "number" && DROP_STATUSES.has(status)) return "drop";
|
|
4450
|
-
return "retry";
|
|
4576
|
+
return !!(res && res.ok);
|
|
4451
4577
|
} catch {
|
|
4452
|
-
return
|
|
4578
|
+
return false;
|
|
4453
4579
|
} finally {
|
|
4454
4580
|
clearTimeout(timer);
|
|
4455
4581
|
}
|
|
@@ -4481,8 +4607,8 @@ var createEventQueue = (options) => {
|
|
|
4481
4607
|
try {
|
|
4482
4608
|
while (pending.length > 0) {
|
|
4483
4609
|
const batch = pending.slice(0, batchSize);
|
|
4484
|
-
const
|
|
4485
|
-
if (
|
|
4610
|
+
const ok = await postBatch(batch.map((item) => item.event));
|
|
4611
|
+
if (!ok) {
|
|
4486
4612
|
scheduleRetry();
|
|
4487
4613
|
return;
|
|
4488
4614
|
}
|
|
@@ -4612,6 +4738,6 @@ var useLifecycleEvents = (config, options = {}) => {
|
|
|
4612
4738
|
}, []);
|
|
4613
4739
|
};
|
|
4614
4740
|
|
|
4615
|
-
export { AUTO_DEVICE_ID_PREFIX, AnimatedSparkle, BACKGROUND_SESSION_MS, CardGridSelectCard, CardHandoff, CenteredModal, ChipSelectCard, CompletionView, DEFAULT_FEATURES_TTL_MS, DEFAULT_SESSION_TTL_MS, DemoOnboarding, DoneBlock, EXTRA_KEY_PREFIX, ErrorBlock, FIRST_OPEN_EVENT, IconRegistryProvider, IllustrationProvider, InterstitialCard, LoadingBlock, LoadingScreen, NumberStepperCard, Button as OnboardingButton, OnboardingFlow, OnboardingScaffold, OnboardingThemeProvider, RESERVED_USER_CONTEXT_KEYS, SESSION_STARTED_EVENT, SelectionCard, StatusCard, StepProgress, TextInputCard, USER_ID_MAX_LENGTH, WIRE_ICON_GLYPHS, WIRE_ICON_NAMES, WIRE_ONBOARDING_EVENTS, WireFeaturesProvider, WireIcon, WireOnboarding, attributionMetadata, clearPersistedSession, collectDeviceContext, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, detectAppVersion, detectNativeModel, deviceIdStorageKey, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, getCurrentSessionId, hashEmailFnv1a, identifyOnboarding, isFeaturesFresh, isOnboardingEnabled, isWireScalar, loadPersistedSession, lookupIconGlyph, makeSessionId, mergeTheme, mintDeviceId, motionSpec_exports as motionSpec, namespaceExtra, onboardingComponents, parseWireFeatures, peekPersistedSession, readCachedFeatures, readProgress, reportClientEvent, reportClientEvents, reportFirstOpen, reportSessionStart, resetCurrentSessionId, resetFirstOpenLatch, resetSessionStartGuard, resolveUserContext, sanitizeUserId, savePersistedSession, sessionStorageKey, setCurrentSessionId, themeFromBrand, toAnalyticsEvent, useHostIcon, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
|
|
4741
|
+
export { AUTO_DEVICE_ID_PREFIX, AnimatedSparkle, BACKGROUND_SESSION_MS, CardGridSelectCard, CardHandoff, CenteredModal, ChipSelectCard, CompletionView, DEFAULT_FEATURES_TTL_MS, DEFAULT_SESSION_TTL_MS, DemoOnboarding, DoneBlock, EXTRA_KEY_PREFIX, ErrorBlock, FIRST_OPEN_EVENT, IconRegistryProvider, IllustrationProvider, InterstitialCard, LoadingBlock, LoadingScreen, NumberStepperCard, Button as OnboardingButton, OnboardingFlow, OnboardingScaffold, OnboardingThemeProvider, RESERVED_USER_CONTEXT_KEYS, SESSION_STARTED_EVENT, SelectionCard, StatusCard, StepProgress, TextInputCard, USER_ID_MAX_LENGTH, WIRE_ICON_GLYPHS, WIRE_ICON_NAMES, WIRE_ONBOARDING_EVENTS, WireFeaturesProvider, WireIcon, WireOnboarding, attributionMetadata, bumpActivationRevalidation, clearPersistedSession, collectDeviceContext, createWireActivation, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, detectAppVersion, detectNativeModel, deviceIdStorageKey, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, getActivationRevalidationVersion, getCurrentSessionId, hashEmailFnv1a, identifyOnboarding, isFeaturesFresh, isOnboardingEnabled, isWireScalar, loadPersistedSession, lookupIconGlyph, makeSessionId, mergeTheme, mintDeviceId, motionSpec_exports as motionSpec, namespaceExtra, onboardingComponents, parseWireFeatures, peekPersistedSession, readCachedFeatures, readProgress, reportClientEvent, reportClientEventAwait, reportClientEvents, reportClientEventsAwait, reportFirstOpen, reportSessionStart, resetActivationRevalidation, resetCurrentSessionId, resetFirstOpenLatch, resetSessionStartGuard, resolveUserContext, sanitizeUserId, savePersistedSession, sessionStorageKey, setCurrentSessionId, subscribeActivationRevalidation, themeFromBrand, toAnalyticsEvent, useActivationRevalidation, useHostIcon, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireActivation, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
|
|
4616
4742
|
//# sourceMappingURL=index.mjs.map
|
|
4617
4743
|
//# sourceMappingURL=index.mjs.map
|