Socket
Socket
Sign inDemoInstall

@ninetailed/experience.js-shared

Package Overview
Dependencies
Maintainers
2
Versions
374
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ninetailed/experience.js-shared - npm Package Compare versions

Comparing version 5.0.0-beta.3 to 6.0.1-beta.0

9

index.d.ts
export * from './lib/types/Endpoints/CreateProfile';
export * from './lib/types/Endpoints/UpdateProfile';
export * from './lib/types/Endpoints/UpsertManyProfiles';
export * from './lib/types/Endpoints/RequestBodyOptions';
export * from './lib/types/Event/Event';

@@ -18,2 +19,3 @@ export * from './lib/types/Event/PageviewEvent';

export * from './lib/types/Event/NinetailedRequestContext';
export * from './lib/types/Event/SharedEventProperties';
export * from './lib/types/generic/Json';

@@ -24,4 +26,2 @@ export * from './lib/types/Localization/Locale';

export * from './lib/types/Profile/GeoLocation';
export * from './lib/types/SelectedVariantInfo/SelectedVariantInfo';
export * from './lib/types/SelectedVariantInfo/ProfileWithSelectedVariants';
export * from './lib/types/Session/SessionStatistics';

@@ -33,2 +33,3 @@ export * from './lib/types/ExperienceDefinition';

export type { FetchImpl } from './lib/api/FetchImpl';
export { fetchTimeout } from './lib/api/fetch-timeout';
export { Logger, logger } from './lib/logger/Logger';

@@ -41,2 +42,3 @@ export { ConsoleLogSink } from './lib/logger/ConsoleLogSink';

export type { OnErrorHandler } from './lib/logger/OnErrorLogSink';
export * from './lib/event/build-event';
export * from './lib/event/build-query';

@@ -62,4 +64,3 @@ export * from './lib/event/build-campaign';

export * from './lib/utils/experiences/selectHasVariants';
export * from './lib/utils/experiences/selectVariantClientSide';
export * from './lib/utils/experiences/selectVariant';
export * from './lib/utils/experiences/selectVariants';
export * from './lib/utils/experiences/selectVariant';

@@ -19,2 +19,3 @@ import { z } from 'zod';

const SessionStatistics = z.object({
id: z.string(),
isReturningVisitor: z.boolean(),

@@ -50,2 +51,3 @@ landingPage: Page,

id: z.string(),
stableId: z.string(),
random: z.number(),

@@ -62,8 +64,2 @@ audiences: z.array(z.string()),

const SelectedVariantInfo = z.object({
experienceId: z.string(),
variantIndex: z.number(),
variants: z.record(z.string())
});
const CreateProfileRequestBody = z.object({

@@ -77,4 +73,3 @@ // TODO

data: z.object({
profile: Profile,
experiences: z.array(SelectedVariantInfo)
profile: Profile
}),

@@ -92,4 +87,3 @@ error: z.boolean().nullable()

data: z.object({
profile: Profile,
experiences: z.array(SelectedVariantInfo)
profile: Profile
}),

@@ -136,2 +130,3 @@ error: z.boolean().nullable()

const Alias = 'alias';
const Component = 'component';

@@ -142,3 +137,2 @@ const LEGACY_ANONYMOUS_ID = '__anon_id';

const PROFILE_FALLBACK_CACHE = '__nt_profile__';
const EXPERIENCES_FALLBACK_CACHE = '__nt_experiences__';
const PROFILE_CHANGE = 'profile-change';

@@ -358,6 +352,8 @@ const PROFILE_RESET = 'profile-reset';

const {
data
data: {
profile
}
} = CreateProfileResponse.parse(yield response.json());
logger.debug(`${requestName} request succesfully completed.`);
return data;
return profile;
} catch (error) {

@@ -390,6 +386,8 @@ this.logRequestError(error, {

const {
data
data: {
profile
}
} = UpdateProfileResponse.parse(yield response.json());
logger.debug(`${requestName} request successfully completed.`);
return data;
return profile;
} catch (error) {

@@ -591,3 +589,3 @@ this.logRequestError(error, {

name: 'Ninetailed React Analytics SDK',
version: "5.0.0-beta.3"
version: "6.0.1-beta.0"
},

@@ -605,2 +603,3 @@ userAgent: ctx.userAgent,

originalTimestamp: date,
timestamp: date,
sentAt: date,

@@ -794,3 +793,3 @@ type

const selectVariantClientSide = ({
const selectVariant = ({
baseline,

@@ -801,4 +800,10 @@ experience,

const variants = selectVariants(experience, baseline);
const baselineVariant = Object.assign(Object.assign({}, baseline), {
hidden: false
});
if (!variants.length) {
return null;
return {
variant: baselineVariant,
index: 0
};
}

@@ -810,42 +815,28 @@ const distribution = selectDistribution({

if (!distribution) {
return null;
return {
variant: baselineVariant,
index: 0
};
}
if (distribution.index === 0) {
return Object.assign(Object.assign({}, baseline), {
hidden: false
});
return {
variant: baselineVariant,
index: 0
};
}
const correctedVariantIndex = distribution.index - 1;
if (variants.length <= correctedVariantIndex) {
console.warn("A distribution for a variant was selected but it's metadata could not be found.");
return null;
const selectableVariants = [baselineVariant, ...variants];
if (selectableVariants.length <= distribution.index) {
logger.warn("A distribution for a variant was selected but it's metadata could not be found.");
return {
variant: baselineVariant,
index: 0
};
}
const variant = variants[correctedVariantIndex];
if (!variant) {
console.warn("A distribution for a variant was selected but it's metadata could not be found.");
return null;
}
return variant;
const variant = selectableVariants[distribution.index];
return {
variant,
index: distribution.index
};
};
const selectVariant = (baseline, experiences, variantSelections) => {
var _a, _b;
const firstMatchingExperience = experiences.find(experience => {
return variantSelections.some(selection => selection.experienceId === experience.id);
});
if (!firstMatchingExperience) {
return baseline;
}
const component = firstMatchingExperience.components.find(component => component.baseline.id === baseline.id);
if (!component) {
return baseline;
}
const selectedVariantIndex = (_b = (_a = variantSelections.find(selection => selection.experienceId === firstMatchingExperience.id)) === null || _a === void 0 ? void 0 : _a.variantIndex) !== null && _b !== void 0 ? _b : 0;
const variants = [component.baseline, ...component.variants];
if (selectedVariantIndex >= variants.length) {
return baseline;
}
return variants[selectedVariantIndex];
};
export { ANONYMOUS_ID, Alias, Alpha2Code, CONSENT, Campaign, ConsoleLogSink, CreateProfileRequestBody, CreateProfileResponse, DEBUG_FLAG, EMPTY_MERGE_ID, EXPERIENCES_FALLBACK_CACHE, EXPERIENCE_TRAIT_PREFIX, FEATURES, GeoLocation, Group, Identify, Json, JsonLiteral, JsonLiteralObject, JsonObject, LEGACY_ANONYMOUS_ID, Logger, NINETAILED_ANONYMOUS_ID_COOKIE, NinetailedApiClient, OnErrorLogSink, OnLogLogSink, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, Page, Pageview, PageviewProperties, Profile, JsonObject as Properties, Query, SET_ENABLED_FEATURES, Screen, SelectedVariantInfo, SessionStatistics, Track, JsonObject as Traits, UpdateProfileRequestBody, UpdateProfileResponse, UpsertManyProfilesRequestBody, UpsertManyProfilesResponse, buildCampaign, buildIdentifyEvent, buildPage, buildPageEvent, buildQuery, buildTrackEvent, getDistributionRandom, getTrafficRandom, isBrowser, isExperienceMatch, logger, pickBy, pickExperimentTraits, pipe, selectActiveExperiments, selectBaselineWithVariants, selectDistribution, selectEligibleExperiences, selectExperience, selectHasVariants, selectVariant, selectVariantClientSide, selectVariants, template, unionBy };
export { ANONYMOUS_ID, Alias, Alpha2Code, CONSENT, Campaign, Component, ConsoleLogSink, CreateProfileRequestBody, CreateProfileResponse, DEBUG_FLAG, EMPTY_MERGE_ID, EXPERIENCE_TRAIT_PREFIX, FEATURES, GeoLocation, Group, Identify, Json, JsonLiteral, JsonLiteralObject, JsonObject, LEGACY_ANONYMOUS_ID, Logger, NINETAILED_ANONYMOUS_ID_COOKIE, NinetailedApiClient, OnErrorLogSink, OnLogLogSink, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, Page, Pageview, PageviewProperties, Profile, JsonObject as Properties, Query, RequestBodyOptions, SET_ENABLED_FEATURES, Screen, SessionStatistics, Track, JsonObject as Traits, UpdateProfileRequestBody, UpdateProfileResponse, UpsertManyProfilesRequestBody, UpsertManyProfilesResponse, buildCampaign, buildEvent, buildIdentifyEvent, buildPage, buildPageEvent, buildQuery, buildTrackEvent, fetchTimeout, getDistributionRandom, getTrafficRandom, isBrowser, isExperienceMatch, logger, pickBy, pickExperimentTraits, pipe, selectActiveExperiments, selectBaselineWithVariants, selectDistribution, selectEligibleExperiences, selectExperience, selectHasVariants, selectVariant, selectVariants, template, unionBy };

@@ -1,2 +0,2 @@

import { ProfileWithSelectedVariants } from '../types/SelectedVariantInfo/ProfileWithSelectedVariants';
import type { Profile } from '../types/Profile/Profile';
import type { Event } from '../types/Event/Event';

@@ -91,3 +91,37 @@ import { FetchImpl } from './FetchImpl';

private logRequestError;
upsertProfile({ profileId, events }: UpsertProfileParams, options?: RequestOptions): Promise<ProfileWithSelectedVariants>;
upsertProfile({ profileId, events }: UpsertProfileParams, options?: RequestOptions): Promise<{
location: {
coordinates?: {
latitude: number;
longitude: number;
} | undefined;
city?: string | undefined;
postalCode?: string | undefined;
region?: string | undefined;
regionCode?: string | undefined;
country?: string | undefined;
countryCode?: string | undefined;
continent?: string | undefined;
timezone?: string | undefined;
};
traits: import("../..").Properties;
id: string;
stableId: string;
random: number;
audiences: string[];
session: {
id: string;
isReturningVisitor: boolean;
landingPage: {
url: string;
path: string;
query: Record<string, string>;
referrer: string;
search: string;
};
count: number;
activeSessionLength: number;
averageSessionLength: number;
};
}>;
private makeRequest;

@@ -99,3 +133,3 @@ /**

*/
createProfile({ events }: CreateProfileParams, options?: RequestOptions): Promise<ProfileWithSelectedVariants>;
createProfile({ events }: CreateProfileParams, options?: RequestOptions): Promise<Profile>;
/**

@@ -105,3 +139,3 @@ * Updates a profile with the given profileId.

*/
updateProfile({ profileId, events }: UpdateProfileParams, options?: RequestOptions): Promise<ProfileWithSelectedVariants>;
updateProfile({ profileId, events }: UpdateProfileParams, options?: RequestOptions): Promise<Profile>;
/**

@@ -131,5 +165,7 @@ * Sends multiple events to the Ninetailed API.

id: string;
stableId: string;
random: number;
audiences: string[];
session: {
id: string;
isReturningVisitor: boolean;

@@ -136,0 +172,0 @@ landingPage: {

@@ -5,3 +5,2 @@ export declare const LEGACY_ANONYMOUS_ID = "__anon_id";

export declare const PROFILE_FALLBACK_CACHE = "__nt_profile__";
export declare const EXPERIENCES_FALLBACK_CACHE = "__nt_experiences__";
export declare const PROFILE_CHANGE = "profile-change";

@@ -8,0 +7,0 @@ export declare const PROFILE_RESET = "profile-reset";

@@ -28,2 +28,3 @@ import { z } from 'zod';

id: z.ZodString;
stableId: z.ZodString;
random: z.ZodNumber;

@@ -79,2 +80,3 @@ audiences: z.ZodArray<z.ZodString, "many">;

session: z.ZodObject<{
id: z.ZodString;
isReturningVisitor: z.ZodBoolean;

@@ -104,2 +106,3 @@ landingPage: z.ZodObject<{

}, "strip", z.ZodTypeAny, {
id: string;
isReturningVisitor: boolean;

@@ -117,2 +120,3 @@ landingPage: {

}, {
id: string;
isReturningVisitor: boolean;

@@ -132,2 +136,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -151,2 +156,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -166,2 +172,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -185,2 +192,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -199,18 +207,6 @@ landingPage: {

}>;
experiences: z.ZodArray<z.ZodObject<{
experienceId: z.ZodString;
variantIndex: z.ZodNumber;
variants: z.ZodRecord<z.ZodString, z.ZodString>;
}, "strip", z.ZodTypeAny, {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}, {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}>, "many">;
}, "strip", z.ZodTypeAny, {
profile: {
id: string;
stableId: string;
random: number;

@@ -234,2 +230,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -248,10 +245,6 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
}, {
profile: {
id: string;
stableId: string;
random: number;

@@ -275,2 +268,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -289,7 +283,2 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
}>;

@@ -302,2 +291,3 @@ error: z.ZodNullable<z.ZodBoolean>;

id: string;
stableId: string;
random: number;

@@ -321,2 +311,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -335,7 +326,2 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
};

@@ -348,2 +334,3 @@ error: boolean | null;

id: string;
stableId: string;
random: number;

@@ -367,2 +354,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -381,7 +369,2 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
};

@@ -388,0 +371,0 @@ error: boolean | null;

@@ -28,2 +28,3 @@ import { z } from 'zod';

id: z.ZodString;
stableId: z.ZodString;
random: z.ZodNumber;

@@ -79,2 +80,3 @@ audiences: z.ZodArray<z.ZodString, "many">;

session: z.ZodObject<{
id: z.ZodString;
isReturningVisitor: z.ZodBoolean;

@@ -104,2 +106,3 @@ landingPage: z.ZodObject<{

}, "strip", z.ZodTypeAny, {
id: string;
isReturningVisitor: boolean;

@@ -117,2 +120,3 @@ landingPage: {

}, {
id: string;
isReturningVisitor: boolean;

@@ -132,2 +136,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -151,2 +156,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -166,2 +172,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -185,2 +192,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -199,18 +207,6 @@ landingPage: {

}>;
experiences: z.ZodArray<z.ZodObject<{
experienceId: z.ZodString;
variantIndex: z.ZodNumber;
variants: z.ZodRecord<z.ZodString, z.ZodString>;
}, "strip", z.ZodTypeAny, {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}, {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}>, "many">;
}, "strip", z.ZodTypeAny, {
profile: {
id: string;
stableId: string;
random: number;

@@ -234,2 +230,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -248,10 +245,6 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
}, {
profile: {
id: string;
stableId: string;
random: number;

@@ -275,2 +268,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -289,7 +283,2 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
}>;

@@ -302,2 +291,3 @@ error: z.ZodNullable<z.ZodBoolean>;

id: string;
stableId: string;
random: number;

@@ -321,2 +311,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -335,7 +326,2 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
};

@@ -348,2 +334,3 @@ error: boolean | null;

id: string;
stableId: string;
random: number;

@@ -367,2 +354,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -381,7 +369,2 @@ landingPage: {

};
experiences: {
experienceId: string;
variantIndex: number;
variants: Record<string, string>;
}[];
};

@@ -388,0 +371,0 @@ error: boolean | null;

@@ -28,2 +28,3 @@ import { z } from 'zod';

id: z.ZodString;
stableId: z.ZodString;
random: z.ZodNumber;

@@ -79,2 +80,3 @@ audiences: z.ZodArray<z.ZodString, "many">;

session: z.ZodObject<{
id: z.ZodString;
isReturningVisitor: z.ZodBoolean;

@@ -104,2 +106,3 @@ landingPage: z.ZodObject<{

}, "strip", z.ZodTypeAny, {
id: string;
isReturningVisitor: boolean;

@@ -117,2 +120,3 @@ landingPage: {

}, {
id: string;
isReturningVisitor: boolean;

@@ -132,2 +136,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -151,2 +156,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -166,2 +172,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -185,2 +192,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -202,2 +210,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -221,2 +230,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -238,2 +248,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -257,2 +268,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -278,2 +290,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -297,2 +310,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -318,2 +332,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -337,2 +352,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -339,0 +355,0 @@ landingPage: {

@@ -7,2 +7,3 @@ export declare const Pageview = "page";

export declare const Alias = "alias";
export declare const Component = "component";
export type Pageview = typeof Pageview;

@@ -14,2 +15,3 @@ export type Track = typeof Track;

export type Alias = typeof Alias;
export type EventType = Pageview | Track | Identify | Screen | Group | Alias;
export type Component = typeof Component;
export type EventType = Pageview | Track | Identify | Screen | Group | Alias | Component;

@@ -28,2 +28,3 @@ import type { GeoLocation } from '../Profile/GeoLocation';

originalTimestamp: string;
timestamp: string;
sentAt: string;

@@ -30,0 +31,0 @@ type: EventType;

@@ -5,2 +5,3 @@ import { z } from 'zod';

id: z.ZodString;
stableId: z.ZodString;
random: z.ZodNumber;

@@ -56,2 +57,3 @@ audiences: z.ZodArray<z.ZodString, "many">;

session: z.ZodObject<{
id: z.ZodString;
isReturningVisitor: z.ZodBoolean;

@@ -81,2 +83,3 @@ landingPage: z.ZodObject<{

}, "strip", z.ZodTypeAny, {
id: string;
isReturningVisitor: boolean;

@@ -94,2 +97,3 @@ landingPage: {

}, {
id: string;
isReturningVisitor: boolean;

@@ -109,2 +113,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -128,2 +133,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -143,2 +149,3 @@ landingPage: {

id: string;
stableId: string;
random: number;

@@ -162,2 +169,3 @@ audiences: string[];

session: {
id: string;
isReturningVisitor: boolean;

@@ -164,0 +172,0 @@ landingPage: {

import { z } from 'zod';
export declare const SessionStatistics: z.ZodObject<{
id: z.ZodString;
isReturningVisitor: z.ZodBoolean;

@@ -27,2 +28,3 @@ landingPage: z.ZodObject<{

}, "strip", z.ZodTypeAny, {
id: string;
isReturningVisitor: boolean;

@@ -40,2 +42,3 @@ landingPage: {

}, {
id: string;
isReturningVisitor: boolean;

@@ -42,0 +45,0 @@ landingPage: {

@@ -1,3 +0,12 @@

import { Baseline, ExperienceConfiguration } from '../../types/ExperienceDefinition';
import { SelectedVariantInfo } from '../../types/SelectedVariantInfo/SelectedVariantInfo';
export declare const selectVariant: (baseline: Baseline, experiences: ExperienceConfiguration[], variantSelections: SelectedVariantInfo[]) => import("../../types/ExperienceDefinition").Reference;
import { Profile } from '../../types/Profile/Profile';
import { Baseline, ExperienceConfiguration, Reference, VariantRef } from '../../types/ExperienceDefinition';
type SelectVariantArgs<Variant extends Reference> = {
baseline: Baseline;
experience: ExperienceConfiguration<Variant>;
profile: Profile;
};
export declare const selectVariant: <Variant extends Reference>({ baseline, experience, profile, }: SelectVariantArgs<Variant>) => {
variant: Variant | VariantRef;
index: number;
};
export {};
{
"name": "@ninetailed/experience.js-shared",
"version": "5.0.0-beta.3",
"version": "6.0.1-beta.0",
"devDependencies": {

@@ -5,0 +5,0 @@ "@ninetailed/testing-utils": "*"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc