@wireai/activation 0.9.1 → 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 +34 -11
- package/dist/analytics/index.js.map +1 -1
- package/dist/analytics/index.mjs +33 -12
- package/dist/analytics/index.mjs.map +1 -1
- package/dist/{currentSession-61dcm3V-.d.ts → currentSession-D0Vq7_VE.d.ts} +49 -4
- package/dist/{currentSession-Bs2JfTJ8.d.mts → currentSession-DdDkprpM.d.mts} +49 -4
- package/dist/index.d.mts +116 -3
- package/dist/index.d.ts +116 -3
- package/dist/index.js +154 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -15
- package/dist/index.mjs.map +1 -1
- package/llms.txt +1 -0
- package/package.json +1 -1
- package/src/WireOnboarding.tsx +15 -4
- 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/index.ts +7 -1
- package/src/analytics/reportClientEvent.ts +56 -10
- package/src/index.ts +18 -0
- package/src/session/persistedSession.ts +17 -0
- package/src/types.ts +16 -0
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
|
|
@@ -3345,6 +3366,7 @@ var clearPersistedSession = (storage, key) => {
|
|
|
3345
3366
|
} catch {
|
|
3346
3367
|
}
|
|
3347
3368
|
};
|
|
3369
|
+
var shouldClearOnComplete = (retainSessionOnComplete) => !retainSessionOnComplete;
|
|
3348
3370
|
|
|
3349
3371
|
// src/identity/userIdentity.ts
|
|
3350
3372
|
var USER_ID_MAX_LENGTH = 128;
|
|
@@ -3394,6 +3416,7 @@ var WireOnboarding = ({
|
|
|
3394
3416
|
storage,
|
|
3395
3417
|
sessionTtlMs = DEFAULT_SESSION_TTL_MS,
|
|
3396
3418
|
persistKey,
|
|
3419
|
+
retainSessionOnComplete,
|
|
3397
3420
|
userContext,
|
|
3398
3421
|
userId
|
|
3399
3422
|
}) => {
|
|
@@ -3428,10 +3451,10 @@ var WireOnboarding = ({
|
|
|
3428
3451
|
}, [storage, storageKey, sessionTtlMs, session]);
|
|
3429
3452
|
const handleComplete = useCallback(
|
|
3430
3453
|
(result) => {
|
|
3431
|
-
if (storage) clearPersistedSession(storage, storageKey);
|
|
3454
|
+
if (storage && shouldClearOnComplete(retainSessionOnComplete)) clearPersistedSession(storage, storageKey);
|
|
3432
3455
|
onComplete(result);
|
|
3433
3456
|
},
|
|
3434
|
-
[storage, storageKey, onComplete]
|
|
3457
|
+
[storage, storageKey, retainSessionOnComplete, onComplete]
|
|
3435
3458
|
);
|
|
3436
3459
|
const sessionId = (_a2 = session == null ? void 0 : session.id) != null ? _a2 : "";
|
|
3437
3460
|
const startupUserIdRef = useRef(boundUserId);
|
|
@@ -4107,6 +4130,115 @@ var mintDeviceId = () => {
|
|
|
4107
4130
|
return `${AUTO_DEVICE_ID_PREFIX}${time}_${randomChunk()}${randomChunk()}`;
|
|
4108
4131
|
};
|
|
4109
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
|
+
|
|
4110
4242
|
// src/session-analytics/reportSessionStart.ts
|
|
4111
4243
|
var SESSION_STARTED_EVENT = "app.session_started";
|
|
4112
4244
|
var _emitted = /* @__PURE__ */ new Set();
|
|
@@ -4606,6 +4738,6 @@ var useLifecycleEvents = (config, options = {}) => {
|
|
|
4606
4738
|
}, []);
|
|
4607
4739
|
};
|
|
4608
4740
|
|
|
4609
|
-
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 };
|
|
4610
4742
|
//# sourceMappingURL=index.mjs.map
|
|
4611
4743
|
//# sourceMappingURL=index.mjs.map
|