@scalemule/nextjs 0.1.62 → 0.1.63
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/dist/index.d.mts +50 -2
- package/dist/index.d.ts +50 -2
- package/dist/index.js +84 -5
- package/dist/index.mjs +86 -8
- package/dist/server/auth.js +27 -0
- package/dist/server/auth.mjs +27 -0
- package/dist/server/index.d.mts +3 -2
- package/dist/server/index.d.ts +3 -2
- package/dist/server/index.js +27 -0
- package/dist/server/index.mjs +27 -0
- package/dist/server/webhook-handler.d.mts +2 -1
- package/dist/server/webhook-handler.d.ts +2 -1
- package/dist/server/webhook-handler.js +1 -0
- package/dist/server/webhook-handler.mjs +1 -0
- package/dist/{webhook-handler-D--VG8bN.d.mts → webhook-handler-CJm0sIZG.d.mts} +30 -0
- package/dist/{webhook-handler-B2GL4SDl.d.ts → webhook-handler-CnQe9hm5.d.ts} +30 -0
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -210,6 +210,15 @@ interface SecurityChallenge {
|
|
|
210
210
|
}
|
|
211
211
|
type SecurityChallengePrompt = (challenge: SecurityChallenge) => Promise<string | null>;
|
|
212
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Experiment assignment helpers used inside this package.
|
|
215
|
+
*
|
|
216
|
+
* The canonical helpers live in `@scalemule/sdk` (`withExperiments`, `normalizeExperiments`); the
|
|
217
|
+
* provider and analytics hook keep a local copy so a test or app that mocks `@scalemule/sdk` with
|
|
218
|
+
* a partial module still renders. Same rules: slug keys and variants, at most ten per event.
|
|
219
|
+
*/
|
|
220
|
+
type ExperimentAssignments = Record<string, string>;
|
|
221
|
+
|
|
213
222
|
interface ScaleMuleContextValue {
|
|
214
223
|
requestSecurityCode: SecurityChallengePrompt;
|
|
215
224
|
/** The API client instance */
|
|
@@ -274,6 +283,10 @@ interface ScaleMuleContextValue {
|
|
|
274
283
|
accountSwitcherPrivacy?: string;
|
|
275
284
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
276
285
|
bootstrapFlags?: Record<string, unknown>;
|
|
286
|
+
/** Experiment assignments for this visitor (flag key → variant). `useAnalytics` attaches them to every event. */
|
|
287
|
+
experiments: ExperimentAssignments;
|
|
288
|
+
/** Registers an assignment made by `useExperiment` (or a server-side evaluation) so analytics events carry it. */
|
|
289
|
+
registerExperiment: (flagKey: string, variant: string | null) => void;
|
|
277
290
|
}
|
|
278
291
|
interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
279
292
|
/** Recovery link in the built-in security challenge. */
|
|
@@ -289,6 +302,8 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
289
302
|
onAuthError?: (error: ApiError$1) => void;
|
|
290
303
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
291
304
|
bootstrapFlags?: Record<string, unknown>;
|
|
305
|
+
/** Experiment assignments already made on the server (e.g. by `createServerClient().flags.experiment`). */
|
|
306
|
+
initialExperiments?: ExperimentAssignments;
|
|
292
307
|
/**
|
|
293
308
|
* Default media-pipeline policy applied to `useMedia()` calls when no
|
|
294
309
|
* per-call `policy` override is given. Five modes — see
|
|
@@ -340,7 +355,7 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
340
355
|
*/
|
|
341
356
|
memberTokenPollMs?: number | null;
|
|
342
357
|
}
|
|
343
|
-
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, sessionMode, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, mediaPolicy, getToken, userResolver, memberTokenPollMs, passwordRecoveryUrl, onSecurityChallenge, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
358
|
+
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, sessionMode, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, initialExperiments, mediaPolicy, getToken, userResolver, memberTokenPollMs, passwordRecoveryUrl, onSecurityChallenge, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
344
359
|
declare function useScaleMule(): ScaleMuleContextValue;
|
|
345
360
|
declare function useScaleMuleClient(): ScaleMuleClient;
|
|
346
361
|
declare function useMoneyClient(): MoneyClient;
|
|
@@ -842,6 +857,39 @@ interface UseFeatureFlagsReturn {
|
|
|
842
857
|
}
|
|
843
858
|
declare function useFeatureFlags(options?: UseFeatureFlagsOptions): UseFeatureFlagsReturn;
|
|
844
859
|
|
|
860
|
+
interface UseExperimentOptions {
|
|
861
|
+
/** Flag environment (defaults to the provider's). */
|
|
862
|
+
environment?: string;
|
|
863
|
+
/** Extra evaluation context (attributes for targeting rules). The visitor's anonymous id is always sent as `session_id`. */
|
|
864
|
+
context?: Record<string, unknown>;
|
|
865
|
+
/** Variant to report while loading or when the flag is off or missing. */
|
|
866
|
+
fallback?: string | null;
|
|
867
|
+
/** Set false to skip evaluation (the fallback is returned and nothing is tracked). */
|
|
868
|
+
enabled?: boolean;
|
|
869
|
+
/** Set false to skip the `experiment_exposed` event (for example when the server already sent it). */
|
|
870
|
+
trackExposure?: boolean;
|
|
871
|
+
}
|
|
872
|
+
interface UseExperimentReturn {
|
|
873
|
+
/** The visitor's variant, the fallback while loading, or null when the flag serves no variant. */
|
|
874
|
+
variant: string | null;
|
|
875
|
+
loading: boolean;
|
|
876
|
+
error: ApiError$1 | null;
|
|
877
|
+
evaluation: FeatureFlagEvaluation | null;
|
|
878
|
+
refresh: () => Promise<void>;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Assigns the visitor to an experiment (a flag with weighted variants), registers the assignment
|
|
882
|
+
* so every `useAnalytics` event carries `properties.experiments`, and tracks one
|
|
883
|
+
* `experiment_exposed` per session and flag.
|
|
884
|
+
*
|
|
885
|
+
* @example
|
|
886
|
+
* ```tsx
|
|
887
|
+
* const { variant } = useExperiment('checkout_button')
|
|
888
|
+
* return variant === 'green' ? <GreenButton /> : <BlueButton />
|
|
889
|
+
* ```
|
|
890
|
+
*/
|
|
891
|
+
declare function useExperiment(flagKey: string, options?: UseExperimentOptions): UseExperimentReturn;
|
|
892
|
+
|
|
845
893
|
interface UsePushNotificationsOptions {
|
|
846
894
|
/** Service worker URL (default: '/sw.js') */
|
|
847
895
|
serviceWorkerUrl?: string;
|
|
@@ -1303,4 +1351,4 @@ declare function createSafeLogger(prefix: string): {
|
|
|
1303
1351
|
error: (message: string, data?: unknown) => void;
|
|
1304
1352
|
};
|
|
1305
1353
|
|
|
1306
|
-
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, type HoneypotFieldName, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, RegisterHoneypot, type RegisterHoneypotProps, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, type SecurityChallenge, type SecurityChallengePrompt, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseHoneypotReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useHoneypot, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
|
1354
|
+
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, type HoneypotFieldName, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, RegisterHoneypot, type RegisterHoneypotProps, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, type SecurityChallenge, type SecurityChallengePrompt, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseExperimentOptions, type UseExperimentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseHoneypotReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useExperiment, useFeatureFlags, useFeedback, useFileStatus, useHoneypot, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
package/dist/index.d.ts
CHANGED
|
@@ -210,6 +210,15 @@ interface SecurityChallenge {
|
|
|
210
210
|
}
|
|
211
211
|
type SecurityChallengePrompt = (challenge: SecurityChallenge) => Promise<string | null>;
|
|
212
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Experiment assignment helpers used inside this package.
|
|
215
|
+
*
|
|
216
|
+
* The canonical helpers live in `@scalemule/sdk` (`withExperiments`, `normalizeExperiments`); the
|
|
217
|
+
* provider and analytics hook keep a local copy so a test or app that mocks `@scalemule/sdk` with
|
|
218
|
+
* a partial module still renders. Same rules: slug keys and variants, at most ten per event.
|
|
219
|
+
*/
|
|
220
|
+
type ExperimentAssignments = Record<string, string>;
|
|
221
|
+
|
|
213
222
|
interface ScaleMuleContextValue {
|
|
214
223
|
requestSecurityCode: SecurityChallengePrompt;
|
|
215
224
|
/** The API client instance */
|
|
@@ -274,6 +283,10 @@ interface ScaleMuleContextValue {
|
|
|
274
283
|
accountSwitcherPrivacy?: string;
|
|
275
284
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
276
285
|
bootstrapFlags?: Record<string, unknown>;
|
|
286
|
+
/** Experiment assignments for this visitor (flag key → variant). `useAnalytics` attaches them to every event. */
|
|
287
|
+
experiments: ExperimentAssignments;
|
|
288
|
+
/** Registers an assignment made by `useExperiment` (or a server-side evaluation) so analytics events carry it. */
|
|
289
|
+
registerExperiment: (flagKey: string, variant: string | null) => void;
|
|
277
290
|
}
|
|
278
291
|
interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
279
292
|
/** Recovery link in the built-in security challenge. */
|
|
@@ -289,6 +302,8 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
289
302
|
onAuthError?: (error: ApiError$1) => void;
|
|
290
303
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
291
304
|
bootstrapFlags?: Record<string, unknown>;
|
|
305
|
+
/** Experiment assignments already made on the server (e.g. by `createServerClient().flags.experiment`). */
|
|
306
|
+
initialExperiments?: ExperimentAssignments;
|
|
292
307
|
/**
|
|
293
308
|
* Default media-pipeline policy applied to `useMedia()` calls when no
|
|
294
309
|
* per-call `policy` override is given. Five modes — see
|
|
@@ -340,7 +355,7 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
340
355
|
*/
|
|
341
356
|
memberTokenPollMs?: number | null;
|
|
342
357
|
}
|
|
343
|
-
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, sessionMode, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, mediaPolicy, getToken, userResolver, memberTokenPollMs, passwordRecoveryUrl, onSecurityChallenge, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
358
|
+
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, sessionMode, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, initialExperiments, mediaPolicy, getToken, userResolver, memberTokenPollMs, passwordRecoveryUrl, onSecurityChallenge, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
344
359
|
declare function useScaleMule(): ScaleMuleContextValue;
|
|
345
360
|
declare function useScaleMuleClient(): ScaleMuleClient;
|
|
346
361
|
declare function useMoneyClient(): MoneyClient;
|
|
@@ -842,6 +857,39 @@ interface UseFeatureFlagsReturn {
|
|
|
842
857
|
}
|
|
843
858
|
declare function useFeatureFlags(options?: UseFeatureFlagsOptions): UseFeatureFlagsReturn;
|
|
844
859
|
|
|
860
|
+
interface UseExperimentOptions {
|
|
861
|
+
/** Flag environment (defaults to the provider's). */
|
|
862
|
+
environment?: string;
|
|
863
|
+
/** Extra evaluation context (attributes for targeting rules). The visitor's anonymous id is always sent as `session_id`. */
|
|
864
|
+
context?: Record<string, unknown>;
|
|
865
|
+
/** Variant to report while loading or when the flag is off or missing. */
|
|
866
|
+
fallback?: string | null;
|
|
867
|
+
/** Set false to skip evaluation (the fallback is returned and nothing is tracked). */
|
|
868
|
+
enabled?: boolean;
|
|
869
|
+
/** Set false to skip the `experiment_exposed` event (for example when the server already sent it). */
|
|
870
|
+
trackExposure?: boolean;
|
|
871
|
+
}
|
|
872
|
+
interface UseExperimentReturn {
|
|
873
|
+
/** The visitor's variant, the fallback while loading, or null when the flag serves no variant. */
|
|
874
|
+
variant: string | null;
|
|
875
|
+
loading: boolean;
|
|
876
|
+
error: ApiError$1 | null;
|
|
877
|
+
evaluation: FeatureFlagEvaluation | null;
|
|
878
|
+
refresh: () => Promise<void>;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Assigns the visitor to an experiment (a flag with weighted variants), registers the assignment
|
|
882
|
+
* so every `useAnalytics` event carries `properties.experiments`, and tracks one
|
|
883
|
+
* `experiment_exposed` per session and flag.
|
|
884
|
+
*
|
|
885
|
+
* @example
|
|
886
|
+
* ```tsx
|
|
887
|
+
* const { variant } = useExperiment('checkout_button')
|
|
888
|
+
* return variant === 'green' ? <GreenButton /> : <BlueButton />
|
|
889
|
+
* ```
|
|
890
|
+
*/
|
|
891
|
+
declare function useExperiment(flagKey: string, options?: UseExperimentOptions): UseExperimentReturn;
|
|
892
|
+
|
|
845
893
|
interface UsePushNotificationsOptions {
|
|
846
894
|
/** Service worker URL (default: '/sw.js') */
|
|
847
895
|
serviceWorkerUrl?: string;
|
|
@@ -1303,4 +1351,4 @@ declare function createSafeLogger(prefix: string): {
|
|
|
1303
1351
|
error: (message: string, data?: unknown) => void;
|
|
1304
1352
|
};
|
|
1305
1353
|
|
|
1306
|
-
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, type HoneypotFieldName, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, RegisterHoneypot, type RegisterHoneypotProps, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, type SecurityChallenge, type SecurityChallengePrompt, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseHoneypotReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useHoneypot, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
|
1354
|
+
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, type HoneypotFieldName, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, RegisterHoneypot, type RegisterHoneypotProps, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, type SecurityChallenge, type SecurityChallengePrompt, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseExperimentOptions, type UseExperimentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseHoneypotReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useExperiment, useFeatureFlags, useFeedback, useFileStatus, useHoneypot, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
package/dist/index.js
CHANGED
|
@@ -157,6 +157,29 @@ async function withAdaptiveChallenge(attempt, prompt, mfa) {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
// src/experiments.ts
|
|
161
|
+
var KEY = /^[a-z0-9][a-z0-9_.-]{0,63}$/;
|
|
162
|
+
var VARIANT = /^[a-z0-9][a-z0-9_.:-]{0,63}$/;
|
|
163
|
+
var MAX = 10;
|
|
164
|
+
function normalizeExperiments(input) {
|
|
165
|
+
const result = {};
|
|
166
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return result;
|
|
167
|
+
let count = 0;
|
|
168
|
+
for (const [key, value] of Object.entries(input)) {
|
|
169
|
+
if (count >= MAX) break;
|
|
170
|
+
if (KEY.test(key) && typeof value === "string" && VARIANT.test(value)) {
|
|
171
|
+
result[key] = value;
|
|
172
|
+
count++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
function withExperiments(properties, experiments) {
|
|
178
|
+
const merged = normalizeExperiments({ ...normalizeExperiments(properties?.experiments), ...experiments ?? {} });
|
|
179
|
+
if (Object.keys(merged).length === 0) return properties;
|
|
180
|
+
return { ...properties ?? {}, experiments: merged };
|
|
181
|
+
}
|
|
182
|
+
|
|
160
183
|
// src/types/index.ts
|
|
161
184
|
var ScaleMuleApiError = class extends Error {
|
|
162
185
|
constructor(error, status) {
|
|
@@ -1167,6 +1190,7 @@ function ScaleMuleProvider({
|
|
|
1167
1190
|
onLogout,
|
|
1168
1191
|
onAuthError,
|
|
1169
1192
|
bootstrapFlags,
|
|
1193
|
+
initialExperiments,
|
|
1170
1194
|
mediaPolicy,
|
|
1171
1195
|
getToken,
|
|
1172
1196
|
userResolver,
|
|
@@ -1181,6 +1205,16 @@ function ScaleMuleProvider({
|
|
|
1181
1205
|
const browserKey = cookieSession ? publishableKey || process.env.NEXT_PUBLIC_SCALEMULE_PUBLISHABLE_KEY || apiKey : apiKey;
|
|
1182
1206
|
const browserGateway = cookieSession ? `${authProxyUrl.replace(/\/$/, "")}/client` : void 0;
|
|
1183
1207
|
const [user, setUser] = React.useState(null);
|
|
1208
|
+
const [experiments, setExperiments] = React.useState(() => normalizeExperiments(initialExperiments));
|
|
1209
|
+
const registerExperiment = React.useCallback((flagKey, variant) => {
|
|
1210
|
+
setExperiments((current) => {
|
|
1211
|
+
const next = { ...current };
|
|
1212
|
+
if (variant === null) delete next[flagKey];
|
|
1213
|
+
else Object.assign(next, normalizeExperiments({ [flagKey]: variant }));
|
|
1214
|
+
const same = Object.keys(next).length === Object.keys(current).length && Object.entries(next).every(([k, v]) => current[k] === v);
|
|
1215
|
+
return same ? current : next;
|
|
1216
|
+
});
|
|
1217
|
+
}, []);
|
|
1184
1218
|
const [initializing, setInitializing] = React.useState(true);
|
|
1185
1219
|
const [error, setError] = React.useState(null);
|
|
1186
1220
|
React.useEffect(() => {
|
|
@@ -1453,9 +1487,11 @@ function ScaleMuleProvider({
|
|
|
1453
1487
|
environment: environment || void 0,
|
|
1454
1488
|
enableAccountSwitcher,
|
|
1455
1489
|
accountSwitcherPrivacy,
|
|
1456
|
-
bootstrapFlags
|
|
1490
|
+
bootstrapFlags,
|
|
1491
|
+
experiments,
|
|
1492
|
+
registerExperiment
|
|
1457
1493
|
}),
|
|
1458
|
-
[requestSecurityCode, client, money$1, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, browserKey, cookieSession, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1494
|
+
[requestSecurityCode, client, money$1, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, browserKey, cookieSession, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy, experiments, registerExperiment]
|
|
1459
1495
|
);
|
|
1460
1496
|
return /* @__PURE__ */ jsxRuntime.jsxs(ScaleMuleContext.Provider, { value, children: [
|
|
1461
1497
|
children,
|
|
@@ -4240,7 +4276,7 @@ function useAnalytics(options = {}) {
|
|
|
4240
4276
|
eventDedupMs = DEFAULT_EVENT_DEDUP_MS
|
|
4241
4277
|
} = options;
|
|
4242
4278
|
const shouldAutoCaptureUtmParams = autoCaptureUtmParams ?? autoCapturUtmParams ?? true;
|
|
4243
|
-
const { client, user, analyticsProxyUrl, publishableKey, apiKey, gatewayUrl } = useScaleMule();
|
|
4279
|
+
const { client, user, analyticsProxyUrl, publishableKey, apiKey, gatewayUrl, experiments } = useScaleMule();
|
|
4244
4280
|
const proxyModeMisconfigWarnedRef = React.useRef(false);
|
|
4245
4281
|
React.useEffect(() => {
|
|
4246
4282
|
if (process.env.NODE_ENV === "production") return;
|
|
@@ -4338,7 +4374,8 @@ function useAnalytics(options = {}) {
|
|
|
4338
4374
|
const fullEvent = {
|
|
4339
4375
|
event_name: event.event_name,
|
|
4340
4376
|
event_category: event.event_category,
|
|
4341
|
-
|
|
4377
|
+
// Experiment assignments ride on every event so the analytics experiment report can attribute it
|
|
4378
|
+
properties: withExperiments(event.properties, experiments),
|
|
4342
4379
|
// Use refs for IDs - they're always current, and this keeps the callback stable
|
|
4343
4380
|
session_id: event.session_id || sessionIdRef.current,
|
|
4344
4381
|
anonymous_id: event.anonymous_id || anonymousIdRef.current,
|
|
@@ -4370,7 +4407,7 @@ function useAnalytics(options = {}) {
|
|
|
4370
4407
|
return fullEvent;
|
|
4371
4408
|
},
|
|
4372
4409
|
// Note: sessionId/anonymousId removed - we use refs to keep this stable
|
|
4373
|
-
[user, utmParams, getDeviceInfo]
|
|
4410
|
+
[user, utmParams, getDeviceInfo, experiments]
|
|
4374
4411
|
);
|
|
4375
4412
|
const sendEvent = React.useCallback(
|
|
4376
4413
|
async (event) => {
|
|
@@ -4702,6 +4739,47 @@ function useFeatureFlags(options = {}) {
|
|
|
4702
4739
|
getFlag
|
|
4703
4740
|
};
|
|
4704
4741
|
}
|
|
4742
|
+
function useExperiment(flagKey, options = {}) {
|
|
4743
|
+
const { environment, context, fallback = null, enabled = true, trackExposure = true } = options;
|
|
4744
|
+
const { client, registerExperiment, experiments } = useScaleMule();
|
|
4745
|
+
const { trackEvent } = useAnalytics();
|
|
4746
|
+
const anonymousId = client.getAnonymousId();
|
|
4747
|
+
const evaluationContext = React.useMemo(
|
|
4748
|
+
() => ({ session_id: anonymousId, ...context ?? {} }),
|
|
4749
|
+
// The anonymous id is stable for the visitor; the caller's context is merged by value.
|
|
4750
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4751
|
+
[anonymousId, JSON.stringify(context ?? {})]
|
|
4752
|
+
);
|
|
4753
|
+
const { flags, loading, error, refresh } = useFeatureFlags({ keys: [flagKey], environment, context: evaluationContext, enabled });
|
|
4754
|
+
const evaluation = flags[flagKey] ?? null;
|
|
4755
|
+
const variant = loading && !evaluation ? sdk.isVariantKey(fallback) ? fallback : null : sdk.experimentVariant(evaluation) ?? (sdk.isVariantKey(fallback) ? fallback : null);
|
|
4756
|
+
React.useEffect(() => {
|
|
4757
|
+
if (!enabled || loading) return;
|
|
4758
|
+
const assigned = sdk.experimentVariant(evaluation);
|
|
4759
|
+
if (experiments[flagKey] !== (assigned ?? void 0)) registerExperiment(flagKey, assigned);
|
|
4760
|
+
}, [enabled, loading, evaluation, flagKey, registerExperiment, experiments]);
|
|
4761
|
+
const exposedRef = React.useRef(null);
|
|
4762
|
+
React.useEffect(() => {
|
|
4763
|
+
if (!enabled || !trackExposure || loading) return;
|
|
4764
|
+
const assigned = sdk.experimentVariant(evaluation);
|
|
4765
|
+
if (!assigned || exposedRef.current === assigned) return;
|
|
4766
|
+
const key = sdk.exposureStorageKey(flagKey);
|
|
4767
|
+
let already = false;
|
|
4768
|
+
try {
|
|
4769
|
+
already = typeof sessionStorage !== "undefined" && sessionStorage.getItem(key) === assigned;
|
|
4770
|
+
} catch {
|
|
4771
|
+
}
|
|
4772
|
+
exposedRef.current = assigned;
|
|
4773
|
+
if (already) return;
|
|
4774
|
+
try {
|
|
4775
|
+
sessionStorage.setItem(key, assigned);
|
|
4776
|
+
} catch {
|
|
4777
|
+
}
|
|
4778
|
+
void trackEvent(sdk.exposureEvent(flagKey, assigned)).catch(() => {
|
|
4779
|
+
});
|
|
4780
|
+
}, [enabled, trackExposure, loading, evaluation, flagKey, trackEvent]);
|
|
4781
|
+
return { variant, loading, error, evaluation, refresh };
|
|
4782
|
+
}
|
|
4705
4783
|
function getCsrfToken() {
|
|
4706
4784
|
if (typeof document === "undefined") return "";
|
|
4707
4785
|
const match = document.cookie.match(/(?:^|;\s*)sm_csrf=([^;]*)/);
|
|
@@ -5972,6 +6050,7 @@ exports.useAudio = useAudio;
|
|
|
5972
6050
|
exports.useAuth = useAuth;
|
|
5973
6051
|
exports.useBilling = useBilling;
|
|
5974
6052
|
exports.useContent = useContent;
|
|
6053
|
+
exports.useExperiment = useExperiment;
|
|
5975
6054
|
exports.useFeatureFlags = useFeatureFlags;
|
|
5976
6055
|
exports.useFeedback = useFeedback;
|
|
5977
6056
|
exports.useFileStatus = useFileStatus;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createContext, useState, useEffect, useMemo,
|
|
2
|
+
import { createContext, useState, useCallback, useEffect, useMemo, useContext, useRef } from 'react';
|
|
3
3
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { createMoneyClient } from '@scalemule/money';
|
|
5
5
|
export { MoneyClient, createMoneyClient } from '@scalemule/money';
|
|
6
|
-
import { STORAGE_KEYS, ensureAnonymousId, ScaleMule, WebPushManager } from '@scalemule/sdk';
|
|
6
|
+
import { STORAGE_KEYS, ensureAnonymousId, ScaleMule, isVariantKey, experimentVariant, exposureStorageKey, exposureEvent, WebPushManager } from '@scalemule/sdk';
|
|
7
7
|
|
|
8
8
|
// src/security-challenge.tsx
|
|
9
9
|
function useSecurityChallenge(recoveryUrl) {
|
|
@@ -137,6 +137,29 @@ async function withAdaptiveChallenge(attempt, prompt, mfa) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
// src/experiments.ts
|
|
141
|
+
var KEY = /^[a-z0-9][a-z0-9_.-]{0,63}$/;
|
|
142
|
+
var VARIANT = /^[a-z0-9][a-z0-9_.:-]{0,63}$/;
|
|
143
|
+
var MAX = 10;
|
|
144
|
+
function normalizeExperiments(input) {
|
|
145
|
+
const result = {};
|
|
146
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return result;
|
|
147
|
+
let count = 0;
|
|
148
|
+
for (const [key, value] of Object.entries(input)) {
|
|
149
|
+
if (count >= MAX) break;
|
|
150
|
+
if (KEY.test(key) && typeof value === "string" && VARIANT.test(value)) {
|
|
151
|
+
result[key] = value;
|
|
152
|
+
count++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
function withExperiments(properties, experiments) {
|
|
158
|
+
const merged = normalizeExperiments({ ...normalizeExperiments(properties?.experiments), ...experiments ?? {} });
|
|
159
|
+
if (Object.keys(merged).length === 0) return properties;
|
|
160
|
+
return { ...properties ?? {}, experiments: merged };
|
|
161
|
+
}
|
|
162
|
+
|
|
140
163
|
// src/types/index.ts
|
|
141
164
|
var ScaleMuleApiError = class extends Error {
|
|
142
165
|
constructor(error, status) {
|
|
@@ -1147,6 +1170,7 @@ function ScaleMuleProvider({
|
|
|
1147
1170
|
onLogout,
|
|
1148
1171
|
onAuthError,
|
|
1149
1172
|
bootstrapFlags,
|
|
1173
|
+
initialExperiments,
|
|
1150
1174
|
mediaPolicy,
|
|
1151
1175
|
getToken,
|
|
1152
1176
|
userResolver,
|
|
@@ -1161,6 +1185,16 @@ function ScaleMuleProvider({
|
|
|
1161
1185
|
const browserKey = cookieSession ? publishableKey || process.env.NEXT_PUBLIC_SCALEMULE_PUBLISHABLE_KEY || apiKey : apiKey;
|
|
1162
1186
|
const browserGateway = cookieSession ? `${authProxyUrl.replace(/\/$/, "")}/client` : void 0;
|
|
1163
1187
|
const [user, setUser] = useState(null);
|
|
1188
|
+
const [experiments, setExperiments] = useState(() => normalizeExperiments(initialExperiments));
|
|
1189
|
+
const registerExperiment = useCallback((flagKey, variant) => {
|
|
1190
|
+
setExperiments((current) => {
|
|
1191
|
+
const next = { ...current };
|
|
1192
|
+
if (variant === null) delete next[flagKey];
|
|
1193
|
+
else Object.assign(next, normalizeExperiments({ [flagKey]: variant }));
|
|
1194
|
+
const same = Object.keys(next).length === Object.keys(current).length && Object.entries(next).every(([k, v]) => current[k] === v);
|
|
1195
|
+
return same ? current : next;
|
|
1196
|
+
});
|
|
1197
|
+
}, []);
|
|
1164
1198
|
const [initializing, setInitializing] = useState(true);
|
|
1165
1199
|
const [error, setError] = useState(null);
|
|
1166
1200
|
useEffect(() => {
|
|
@@ -1433,9 +1467,11 @@ function ScaleMuleProvider({
|
|
|
1433
1467
|
environment: environment || void 0,
|
|
1434
1468
|
enableAccountSwitcher,
|
|
1435
1469
|
accountSwitcherPrivacy,
|
|
1436
|
-
bootstrapFlags
|
|
1470
|
+
bootstrapFlags,
|
|
1471
|
+
experiments,
|
|
1472
|
+
registerExperiment
|
|
1437
1473
|
}),
|
|
1438
|
-
[requestSecurityCode, client, money, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, browserKey, cookieSession, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1474
|
+
[requestSecurityCode, client, money, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, browserKey, cookieSession, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy, experiments, registerExperiment]
|
|
1439
1475
|
);
|
|
1440
1476
|
return /* @__PURE__ */ jsxs(ScaleMuleContext.Provider, { value, children: [
|
|
1441
1477
|
children,
|
|
@@ -4220,7 +4256,7 @@ function useAnalytics(options = {}) {
|
|
|
4220
4256
|
eventDedupMs = DEFAULT_EVENT_DEDUP_MS
|
|
4221
4257
|
} = options;
|
|
4222
4258
|
const shouldAutoCaptureUtmParams = autoCaptureUtmParams ?? autoCapturUtmParams ?? true;
|
|
4223
|
-
const { client, user, analyticsProxyUrl, publishableKey, apiKey, gatewayUrl } = useScaleMule();
|
|
4259
|
+
const { client, user, analyticsProxyUrl, publishableKey, apiKey, gatewayUrl, experiments } = useScaleMule();
|
|
4224
4260
|
const proxyModeMisconfigWarnedRef = useRef(false);
|
|
4225
4261
|
useEffect(() => {
|
|
4226
4262
|
if (process.env.NODE_ENV === "production") return;
|
|
@@ -4318,7 +4354,8 @@ function useAnalytics(options = {}) {
|
|
|
4318
4354
|
const fullEvent = {
|
|
4319
4355
|
event_name: event.event_name,
|
|
4320
4356
|
event_category: event.event_category,
|
|
4321
|
-
|
|
4357
|
+
// Experiment assignments ride on every event so the analytics experiment report can attribute it
|
|
4358
|
+
properties: withExperiments(event.properties, experiments),
|
|
4322
4359
|
// Use refs for IDs - they're always current, and this keeps the callback stable
|
|
4323
4360
|
session_id: event.session_id || sessionIdRef.current,
|
|
4324
4361
|
anonymous_id: event.anonymous_id || anonymousIdRef.current,
|
|
@@ -4350,7 +4387,7 @@ function useAnalytics(options = {}) {
|
|
|
4350
4387
|
return fullEvent;
|
|
4351
4388
|
},
|
|
4352
4389
|
// Note: sessionId/anonymousId removed - we use refs to keep this stable
|
|
4353
|
-
[user, utmParams, getDeviceInfo]
|
|
4390
|
+
[user, utmParams, getDeviceInfo, experiments]
|
|
4354
4391
|
);
|
|
4355
4392
|
const sendEvent = useCallback(
|
|
4356
4393
|
async (event) => {
|
|
@@ -4682,6 +4719,47 @@ function useFeatureFlags(options = {}) {
|
|
|
4682
4719
|
getFlag
|
|
4683
4720
|
};
|
|
4684
4721
|
}
|
|
4722
|
+
function useExperiment(flagKey, options = {}) {
|
|
4723
|
+
const { environment, context, fallback = null, enabled = true, trackExposure = true } = options;
|
|
4724
|
+
const { client, registerExperiment, experiments } = useScaleMule();
|
|
4725
|
+
const { trackEvent } = useAnalytics();
|
|
4726
|
+
const anonymousId = client.getAnonymousId();
|
|
4727
|
+
const evaluationContext = useMemo(
|
|
4728
|
+
() => ({ session_id: anonymousId, ...context ?? {} }),
|
|
4729
|
+
// The anonymous id is stable for the visitor; the caller's context is merged by value.
|
|
4730
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4731
|
+
[anonymousId, JSON.stringify(context ?? {})]
|
|
4732
|
+
);
|
|
4733
|
+
const { flags, loading, error, refresh } = useFeatureFlags({ keys: [flagKey], environment, context: evaluationContext, enabled });
|
|
4734
|
+
const evaluation = flags[flagKey] ?? null;
|
|
4735
|
+
const variant = loading && !evaluation ? isVariantKey(fallback) ? fallback : null : experimentVariant(evaluation) ?? (isVariantKey(fallback) ? fallback : null);
|
|
4736
|
+
useEffect(() => {
|
|
4737
|
+
if (!enabled || loading) return;
|
|
4738
|
+
const assigned = experimentVariant(evaluation);
|
|
4739
|
+
if (experiments[flagKey] !== (assigned ?? void 0)) registerExperiment(flagKey, assigned);
|
|
4740
|
+
}, [enabled, loading, evaluation, flagKey, registerExperiment, experiments]);
|
|
4741
|
+
const exposedRef = useRef(null);
|
|
4742
|
+
useEffect(() => {
|
|
4743
|
+
if (!enabled || !trackExposure || loading) return;
|
|
4744
|
+
const assigned = experimentVariant(evaluation);
|
|
4745
|
+
if (!assigned || exposedRef.current === assigned) return;
|
|
4746
|
+
const key = exposureStorageKey(flagKey);
|
|
4747
|
+
let already = false;
|
|
4748
|
+
try {
|
|
4749
|
+
already = typeof sessionStorage !== "undefined" && sessionStorage.getItem(key) === assigned;
|
|
4750
|
+
} catch {
|
|
4751
|
+
}
|
|
4752
|
+
exposedRef.current = assigned;
|
|
4753
|
+
if (already) return;
|
|
4754
|
+
try {
|
|
4755
|
+
sessionStorage.setItem(key, assigned);
|
|
4756
|
+
} catch {
|
|
4757
|
+
}
|
|
4758
|
+
void trackEvent(exposureEvent(flagKey, assigned)).catch(() => {
|
|
4759
|
+
});
|
|
4760
|
+
}, [enabled, trackExposure, loading, evaluation, flagKey, trackEvent]);
|
|
4761
|
+
return { variant, loading, error, evaluation, refresh };
|
|
4762
|
+
}
|
|
4685
4763
|
function getCsrfToken() {
|
|
4686
4764
|
if (typeof document === "undefined") return "";
|
|
4687
4765
|
const match = document.cookie.match(/(?:^|;\s*)sm_csrf=([^;]*)/);
|
|
@@ -5925,4 +6003,4 @@ function createSafeLogger(prefix) {
|
|
|
5925
6003
|
};
|
|
5926
6004
|
}
|
|
5927
6005
|
|
|
5928
|
-
export { FeedbackWidget, NarrationPlayer, RegisterHoneypot, ScaleMuleApiError, ScaleMuleClient, ScaleMuleMedia, ScaleMuleProvider, VoteButton, composePhone, createClient, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useHoneypot, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
|
6006
|
+
export { FeedbackWidget, NarrationPlayer, RegisterHoneypot, ScaleMuleApiError, ScaleMuleClient, ScaleMuleMedia, ScaleMuleProvider, VoteButton, composePhone, createClient, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useExperiment, useFeatureFlags, useFeedback, useFileStatus, useHoneypot, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
package/dist/server/auth.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var sdk = require('@scalemule/sdk');
|
|
3
4
|
var money = require('@scalemule/money');
|
|
4
5
|
var headers = require('next/headers');
|
|
5
6
|
require('next/server');
|
|
@@ -708,6 +709,17 @@ var ScaleMuleServer = class {
|
|
|
708
709
|
clientContext: options?.clientContext
|
|
709
710
|
});
|
|
710
711
|
},
|
|
712
|
+
/**
|
|
713
|
+
* Track that a visitor saw an experiment variant (once per visitor and flag). The event carries
|
|
714
|
+
* `properties.experiments` so the analytics experiment report attributes it.
|
|
715
|
+
*/
|
|
716
|
+
trackExposure: async (flagKey, variant, data, options) => {
|
|
717
|
+
const event = sdk.exposureEvent(flagKey, variant);
|
|
718
|
+
return this.request("POST", "/v1/analytics/v2/events", {
|
|
719
|
+
body: { ...event, ...data ?? {} },
|
|
720
|
+
clientContext: options?.clientContext
|
|
721
|
+
});
|
|
722
|
+
},
|
|
711
723
|
/**
|
|
712
724
|
* Track a page view
|
|
713
725
|
*
|
|
@@ -755,6 +767,21 @@ var ScaleMuleServer = class {
|
|
|
755
767
|
}
|
|
756
768
|
};
|
|
757
769
|
this.flags = {
|
|
770
|
+
/**
|
|
771
|
+
* Assign a visitor to an experiment (a flag with weighted variants). Pass a stable identifier
|
|
772
|
+
* (`session_id` or `user_id`) so the assignment is sticky. Attach the returned assignment to
|
|
773
|
+
* every analytics event as `properties.experiments` and track one `experiment_exposed` with
|
|
774
|
+
* `analytics.trackExposure` when the variant is shown.
|
|
775
|
+
*
|
|
776
|
+
* @example
|
|
777
|
+
* ```typescript
|
|
778
|
+
* const { variant } = await scalemule.flags.experiment('front_page_layout', { session_id: visitorId })
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
experiment: async (flagKey, context = {}, environment = "prod", options) => {
|
|
782
|
+
const evaluation = await this.flags.evaluate(flagKey, context, environment, options);
|
|
783
|
+
return { flag_key: flagKey, variant: sdk.experimentVariant(evaluation), evaluation };
|
|
784
|
+
},
|
|
758
785
|
evaluate: async (flagKey, context = {}, environment = "prod", options) => {
|
|
759
786
|
return this.request("POST", "/v1/flags/evaluate", {
|
|
760
787
|
body: {
|
package/dist/server/auth.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { exposureEvent, experimentVariant } from '@scalemule/sdk';
|
|
1
2
|
import { createMoneyClient } from '@scalemule/money';
|
|
2
3
|
import { cookies, headers } from 'next/headers';
|
|
3
4
|
import 'next/server';
|
|
@@ -706,6 +707,17 @@ var ScaleMuleServer = class {
|
|
|
706
707
|
clientContext: options?.clientContext
|
|
707
708
|
});
|
|
708
709
|
},
|
|
710
|
+
/**
|
|
711
|
+
* Track that a visitor saw an experiment variant (once per visitor and flag). The event carries
|
|
712
|
+
* `properties.experiments` so the analytics experiment report attributes it.
|
|
713
|
+
*/
|
|
714
|
+
trackExposure: async (flagKey, variant, data, options) => {
|
|
715
|
+
const event = exposureEvent(flagKey, variant);
|
|
716
|
+
return this.request("POST", "/v1/analytics/v2/events", {
|
|
717
|
+
body: { ...event, ...data ?? {} },
|
|
718
|
+
clientContext: options?.clientContext
|
|
719
|
+
});
|
|
720
|
+
},
|
|
709
721
|
/**
|
|
710
722
|
* Track a page view
|
|
711
723
|
*
|
|
@@ -753,6 +765,21 @@ var ScaleMuleServer = class {
|
|
|
753
765
|
}
|
|
754
766
|
};
|
|
755
767
|
this.flags = {
|
|
768
|
+
/**
|
|
769
|
+
* Assign a visitor to an experiment (a flag with weighted variants). Pass a stable identifier
|
|
770
|
+
* (`session_id` or `user_id`) so the assignment is sticky. Attach the returned assignment to
|
|
771
|
+
* every analytics event as `properties.experiments` and track one `experiment_exposed` with
|
|
772
|
+
* `analytics.trackExposure` when the variant is shown.
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```typescript
|
|
776
|
+
* const { variant } = await scalemule.flags.experiment('front_page_layout', { session_id: visitorId })
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
experiment: async (flagKey, context = {}, environment = "prod", options) => {
|
|
780
|
+
const evaluation = await this.flags.evaluate(flagKey, context, environment, options);
|
|
781
|
+
return { flag_key: flagKey, variant: experimentVariant(evaluation), evaluation };
|
|
782
|
+
},
|
|
756
783
|
evaluate: async (flagKey, context = {}, environment = "prod", options) => {
|
|
757
784
|
return this.request("POST", "/v1/flags/evaluate", {
|
|
758
785
|
body: {
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-CJm0sIZG.mjs';
|
|
2
|
+
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-CJm0sIZG.mjs';
|
|
3
3
|
import { q as ClientContext, A as ApiError } from '../index-CEi5Nd4L.mjs';
|
|
4
4
|
export { L as LedveryRoutesConfig, a as LedverySessionData, S as SM_LEDVERY_ACCESS_TOKEN_COOKIE, b as SM_LEDVERY_ID_TOKEN_COOKIE, c as SM_LEDVERY_NONCE_COOKIE, d as SM_LEDVERY_PKCE_VERIFIER_COOKIE, e as SM_LEDVERY_STATE_COOKIE, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-CxPzZpxP.mjs';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
|
+
import '@scalemule/sdk';
|
|
6
7
|
import '@scalemule/money';
|
|
7
8
|
|
|
8
9
|
/**
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-CnQe9hm5.js';
|
|
2
|
+
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-CnQe9hm5.js';
|
|
3
3
|
import { q as ClientContext, A as ApiError } from '../index-CEi5Nd4L.js';
|
|
4
4
|
export { L as LedveryRoutesConfig, a as LedverySessionData, S as SM_LEDVERY_ACCESS_TOKEN_COOKIE, b as SM_LEDVERY_ID_TOKEN_COOKIE, c as SM_LEDVERY_NONCE_COOKIE, d as SM_LEDVERY_PKCE_VERIFIER_COOKIE, e as SM_LEDVERY_STATE_COOKIE, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-CxPzZpxP.js';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
|
+
import '@scalemule/sdk';
|
|
6
7
|
import '@scalemule/money';
|
|
7
8
|
|
|
8
9
|
/**
|
package/dist/server/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var sdk = require('@scalemule/sdk');
|
|
3
4
|
var money = require('@scalemule/money');
|
|
4
5
|
var headers = require('next/headers');
|
|
5
6
|
var server = require('next/server');
|
|
@@ -782,6 +783,17 @@ var ScaleMuleServer = class {
|
|
|
782
783
|
clientContext: options?.clientContext
|
|
783
784
|
});
|
|
784
785
|
},
|
|
786
|
+
/**
|
|
787
|
+
* Track that a visitor saw an experiment variant (once per visitor and flag). The event carries
|
|
788
|
+
* `properties.experiments` so the analytics experiment report attributes it.
|
|
789
|
+
*/
|
|
790
|
+
trackExposure: async (flagKey, variant, data, options) => {
|
|
791
|
+
const event = sdk.exposureEvent(flagKey, variant);
|
|
792
|
+
return this.request("POST", "/v1/analytics/v2/events", {
|
|
793
|
+
body: { ...event, ...data ?? {} },
|
|
794
|
+
clientContext: options?.clientContext
|
|
795
|
+
});
|
|
796
|
+
},
|
|
785
797
|
/**
|
|
786
798
|
* Track a page view
|
|
787
799
|
*
|
|
@@ -829,6 +841,21 @@ var ScaleMuleServer = class {
|
|
|
829
841
|
}
|
|
830
842
|
};
|
|
831
843
|
this.flags = {
|
|
844
|
+
/**
|
|
845
|
+
* Assign a visitor to an experiment (a flag with weighted variants). Pass a stable identifier
|
|
846
|
+
* (`session_id` or `user_id`) so the assignment is sticky. Attach the returned assignment to
|
|
847
|
+
* every analytics event as `properties.experiments` and track one `experiment_exposed` with
|
|
848
|
+
* `analytics.trackExposure` when the variant is shown.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* ```typescript
|
|
852
|
+
* const { variant } = await scalemule.flags.experiment('front_page_layout', { session_id: visitorId })
|
|
853
|
+
* ```
|
|
854
|
+
*/
|
|
855
|
+
experiment: async (flagKey, context = {}, environment = "prod", options) => {
|
|
856
|
+
const evaluation = await this.flags.evaluate(flagKey, context, environment, options);
|
|
857
|
+
return { flag_key: flagKey, variant: sdk.experimentVariant(evaluation), evaluation };
|
|
858
|
+
},
|
|
832
859
|
evaluate: async (flagKey, context = {}, environment = "prod", options) => {
|
|
833
860
|
return this.request("POST", "/v1/flags/evaluate", {
|
|
834
861
|
body: {
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { exposureEvent, experimentVariant } from '@scalemule/sdk';
|
|
1
2
|
import { createMoneyClient } from '@scalemule/money';
|
|
2
3
|
import { cookies, headers } from 'next/headers';
|
|
3
4
|
import { NextResponse } from 'next/server';
|
|
@@ -780,6 +781,17 @@ var ScaleMuleServer = class {
|
|
|
780
781
|
clientContext: options?.clientContext
|
|
781
782
|
});
|
|
782
783
|
},
|
|
784
|
+
/**
|
|
785
|
+
* Track that a visitor saw an experiment variant (once per visitor and flag). The event carries
|
|
786
|
+
* `properties.experiments` so the analytics experiment report attributes it.
|
|
787
|
+
*/
|
|
788
|
+
trackExposure: async (flagKey, variant, data, options) => {
|
|
789
|
+
const event = exposureEvent(flagKey, variant);
|
|
790
|
+
return this.request("POST", "/v1/analytics/v2/events", {
|
|
791
|
+
body: { ...event, ...data ?? {} },
|
|
792
|
+
clientContext: options?.clientContext
|
|
793
|
+
});
|
|
794
|
+
},
|
|
783
795
|
/**
|
|
784
796
|
* Track a page view
|
|
785
797
|
*
|
|
@@ -827,6 +839,21 @@ var ScaleMuleServer = class {
|
|
|
827
839
|
}
|
|
828
840
|
};
|
|
829
841
|
this.flags = {
|
|
842
|
+
/**
|
|
843
|
+
* Assign a visitor to an experiment (a flag with weighted variants). Pass a stable identifier
|
|
844
|
+
* (`session_id` or `user_id`) so the assignment is sticky. Attach the returned assignment to
|
|
845
|
+
* every analytics event as `properties.experiments` and track one `experiment_exposed` with
|
|
846
|
+
* `analytics.trackExposure` when the variant is shown.
|
|
847
|
+
*
|
|
848
|
+
* @example
|
|
849
|
+
* ```typescript
|
|
850
|
+
* const { variant } = await scalemule.flags.experiment('front_page_layout', { session_id: visitorId })
|
|
851
|
+
* ```
|
|
852
|
+
*/
|
|
853
|
+
experiment: async (flagKey, context = {}, environment = "prod", options) => {
|
|
854
|
+
const evaluation = await this.flags.evaluate(flagKey, context, environment, options);
|
|
855
|
+
return { flag_key: flagKey, variant: experimentVariant(evaluation), evaluation };
|
|
856
|
+
},
|
|
830
857
|
evaluate: async (flagKey, context = {}, environment = "prod", options) => {
|
|
831
858
|
return this.request("POST", "/v1/flags/evaluate", {
|
|
832
859
|
body: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExperimentAssignment } from '@scalemule/sdk';
|
|
1
2
|
import { MoneyClient } from '@scalemule/money';
|
|
2
3
|
import { A as ApiError, a3 as RegisterRequest, q as ClientContext, U as User, L as LoginResponse, y as LoginRequest, c as ListFilesParams, w as ListFilesResponse, ad as StorageFile, aj as UploadResponse } from './index-CEi5Nd4L.mjs';
|
|
3
4
|
|
|
@@ -510,6 +511,21 @@ declare class ScaleMuleServer {
|
|
|
510
511
|
tracked: number;
|
|
511
512
|
session_id?: string;
|
|
512
513
|
}>;
|
|
514
|
+
/**
|
|
515
|
+
* Track that a visitor saw an experiment variant (once per visitor and flag). The event carries
|
|
516
|
+
* `properties.experiments` so the analytics experiment report attributes it.
|
|
517
|
+
*/
|
|
518
|
+
trackExposure: (flagKey: string, variant: string, data?: {
|
|
519
|
+
session_id?: string;
|
|
520
|
+
anonymous_id?: string;
|
|
521
|
+
user_id?: string;
|
|
522
|
+
page_url?: string;
|
|
523
|
+
}, options?: {
|
|
524
|
+
clientContext?: ClientContext;
|
|
525
|
+
}) => Promise<{
|
|
526
|
+
tracked: number;
|
|
527
|
+
session_id?: string;
|
|
528
|
+
}>;
|
|
513
529
|
/**
|
|
514
530
|
* Track a page view
|
|
515
531
|
*
|
|
@@ -576,6 +592,20 @@ declare class ScaleMuleServer {
|
|
|
576
592
|
}>;
|
|
577
593
|
};
|
|
578
594
|
flags: {
|
|
595
|
+
/**
|
|
596
|
+
* Assign a visitor to an experiment (a flag with weighted variants). Pass a stable identifier
|
|
597
|
+
* (`session_id` or `user_id`) so the assignment is sticky. Attach the returned assignment to
|
|
598
|
+
* every analytics event as `properties.experiments` and track one `experiment_exposed` with
|
|
599
|
+
* `analytics.trackExposure` when the variant is shown.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* const { variant } = await scalemule.flags.experiment('front_page_layout', { session_id: visitorId })
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
experiment: <T = unknown>(flagKey: string, context?: Record<string, unknown>, environment?: string, options?: {
|
|
607
|
+
clientContext?: ClientContext;
|
|
608
|
+
}) => Promise<ExperimentAssignment<T>>;
|
|
579
609
|
evaluate: <T = unknown>(flagKey: string, context?: Record<string, unknown>, environment?: string, options?: {
|
|
580
610
|
clientContext?: ClientContext;
|
|
581
611
|
}) => Promise<{
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExperimentAssignment } from '@scalemule/sdk';
|
|
1
2
|
import { MoneyClient } from '@scalemule/money';
|
|
2
3
|
import { A as ApiError, a3 as RegisterRequest, q as ClientContext, U as User, L as LoginResponse, y as LoginRequest, c as ListFilesParams, w as ListFilesResponse, ad as StorageFile, aj as UploadResponse } from './index-CEi5Nd4L.js';
|
|
3
4
|
|
|
@@ -510,6 +511,21 @@ declare class ScaleMuleServer {
|
|
|
510
511
|
tracked: number;
|
|
511
512
|
session_id?: string;
|
|
512
513
|
}>;
|
|
514
|
+
/**
|
|
515
|
+
* Track that a visitor saw an experiment variant (once per visitor and flag). The event carries
|
|
516
|
+
* `properties.experiments` so the analytics experiment report attributes it.
|
|
517
|
+
*/
|
|
518
|
+
trackExposure: (flagKey: string, variant: string, data?: {
|
|
519
|
+
session_id?: string;
|
|
520
|
+
anonymous_id?: string;
|
|
521
|
+
user_id?: string;
|
|
522
|
+
page_url?: string;
|
|
523
|
+
}, options?: {
|
|
524
|
+
clientContext?: ClientContext;
|
|
525
|
+
}) => Promise<{
|
|
526
|
+
tracked: number;
|
|
527
|
+
session_id?: string;
|
|
528
|
+
}>;
|
|
513
529
|
/**
|
|
514
530
|
* Track a page view
|
|
515
531
|
*
|
|
@@ -576,6 +592,20 @@ declare class ScaleMuleServer {
|
|
|
576
592
|
}>;
|
|
577
593
|
};
|
|
578
594
|
flags: {
|
|
595
|
+
/**
|
|
596
|
+
* Assign a visitor to an experiment (a flag with weighted variants). Pass a stable identifier
|
|
597
|
+
* (`session_id` or `user_id`) so the assignment is sticky. Attach the returned assignment to
|
|
598
|
+
* every analytics event as `properties.experiments` and track one `experiment_exposed` with
|
|
599
|
+
* `analytics.trackExposure` when the variant is shown.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* const { variant } = await scalemule.flags.experiment('front_page_layout', { session_id: visitorId })
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
experiment: <T = unknown>(flagKey: string, context?: Record<string, unknown>, environment?: string, options?: {
|
|
607
|
+
clientContext?: ClientContext;
|
|
608
|
+
}) => Promise<ExperimentAssignment<T>>;
|
|
579
609
|
evaluate: <T = unknown>(flagKey: string, context?: Record<string, unknown>, environment?: string, options?: {
|
|
580
610
|
clientContext?: ClientContext;
|
|
581
611
|
}) => Promise<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalemule/nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.63",
|
|
4
4
|
"description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@scalemule/ledvery": "^0.0.1",
|
|
71
71
|
"@scalemule/money": "^0.0.2",
|
|
72
|
-
"@scalemule/sdk": "^0.0.
|
|
72
|
+
"@scalemule/sdk": "^0.0.77"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"next": ">=14.0.0",
|