From 38592d63e4fb991272ce001118ee0335d09686e1 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Fri, 5 Nov 2021 20:37:26 -0300 Subject: [PATCH 1/3] DataLoader POC --- src/full/index.ts | 1 + src/index.ts | 1 + src/platform/getModules.ts | 9 ++++-- types/full/index.d.ts | 5 +++ types/index.d.ts | 5 +++ types/splitio.d.ts | 63 +++++++++++++++++++++++++++++++++++--- 6 files changed, 78 insertions(+), 6 deletions(-) diff --git a/src/full/index.ts b/src/full/index.ts index bf946a5..9086485 100644 --- a/src/full/index.ts +++ b/src/full/index.ts @@ -6,3 +6,4 @@ export { ErrorLogger } from '@splitsoftware/splitio-commons/src/logger/browser/E export { WarnLogger } from '@splitsoftware/splitio-commons/src/logger/browser/WarnLogger'; export { InfoLogger } from '@splitsoftware/splitio-commons/src/logger/browser/InfoLogger'; export { DebugLogger } from '@splitsoftware/splitio-commons/src/logger/browser/DebugLogger'; +export { DataLoaderFactory } from '@splitsoftware/splitio-commons/src/storages/dataLoader'; diff --git a/src/index.ts b/src/index.ts index 265fd40..b6e8c64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,3 +7,4 @@ export { WarnLogger } from '@splitsoftware/splitio-commons/src/logger/browser/Wa export { InfoLogger } from '@splitsoftware/splitio-commons/src/logger/browser/InfoLogger'; export { DebugLogger } from '@splitsoftware/splitio-commons/src/logger/browser/DebugLogger'; export { LocalhostFromObject } from '@splitsoftware/splitio-commons/src/sync/offline/LocalhostFromObject'; +export { DataLoaderFactory } from '@splitsoftware/splitio-commons/src/storages/dataLoader'; diff --git a/src/platform/getModules.ts b/src/platform/getModules.ts index 9efc12a..e0ae0b3 100644 --- a/src/platform/getModules.ts +++ b/src/platform/getModules.ts @@ -11,9 +11,10 @@ import integrationsManagerFactory from '@splitsoftware/splitio-commons/src/integ import { shouldAddPt } from '@splitsoftware/splitio-commons/src/trackers/impressionObserver/utils'; import { IPlatform, ISdkFactoryParams } from '@splitsoftware/splitio-commons/src/sdkFactory/types'; import { SplitIO, ISettings } from '@splitsoftware/splitio-commons/src/types'; -import { LOCALHOST_MODE } from '@splitsoftware/splitio-commons/src/utils/constants'; +import { CONSUMER_MODE, LOCALHOST_MODE } from '@splitsoftware/splitio-commons/src/utils/constants'; const syncManagerOnlineCSFactory = syncManagerOnlineFactory(pollingManagerCSFactory, pushManagerFactory); +const syncManagerSubmittersFactory = syncManagerOnlineFactory(undefined, undefined); export function getModules(settings: ISettings, platform: IPlatform): ISdkFactoryParams { @@ -26,7 +27,11 @@ export function getModules(settings: ISettings, platform: IPlatform): ISdkFactor splitApiFactory, - syncManagerFactory: syncManagerOnlineCSFactory, + syncManagerFactory: settings.sync.onlyImpressionsAndEvents ? + syncManagerSubmittersFactory : // partial consumer mode or standalone mode without splits/segments synchronization but data loader + settings.mode === CONSUMER_MODE ? + undefined : // consumer mode + syncManagerOnlineCSFactory, // standalone mode sdkManagerFactory, diff --git a/types/full/index.d.ts b/types/full/index.d.ts index c7e78bb..b2ba335 100644 --- a/types/full/index.d.ts +++ b/types/full/index.d.ts @@ -66,4 +66,9 @@ declare module JsSdk { * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#logging} */ export function ErrorLogger(): SplitIO.ILogger; + + /** + * @TODO + */ + export function DataLoaderFactory(preloadedData: SplitIO.PreloadedData): SplitIO.DataLoader; } diff --git a/types/index.d.ts b/types/index.d.ts index 1474700..bf21360 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -74,4 +74,9 @@ declare module JsSdk { * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#localhost-mode} */ export function LocalhostFromObject(): SplitIO.LocalhostFactory; + + /** + * @TODO + */ + export function DataLoaderFactory(preloadedData: SplitIO.PreloadedData): SplitIO.DataLoader; } diff --git a/types/splitio.d.ts b/types/splitio.d.ts index 39b62ad..29abe76 100644 --- a/types/splitio.d.ts +++ b/types/splitio.d.ts @@ -65,6 +65,7 @@ interface ISettings { eventsFirstPushWindow: number }, readonly storage?: SplitIO.StorageSyncFactory, + readonly dataLoader?: SplitIO.DataLoader, readonly urls: { events: string, sdk: string, @@ -82,7 +83,8 @@ interface ISettings { readonly sync: { splitFilters: SplitIO.SplitFilter[], impressionsMode: SplitIO.ImpressionsMode, - localhostMode?: SplitIO.LocalhostFactory + localhostMode?: SplitIO.LocalhostFactory, + onlyImpressionsAndEvents?: boolean } } /** @@ -183,7 +185,7 @@ interface ISharedSettings { */ impressionsMode?: SplitIO.ImpressionsMode, /** - * Defines the factory function to instanciate the SDK in localhost mode. + * Defines the factory function to instantiate the SDK in localhost mode. * * NOTE: this is only required if using the slim entry point of the library to init the SDK in localhost mode. * @@ -200,7 +202,16 @@ interface ISharedSettings { * ``` * @property {Object} localhostMode */ - localhostMode?: SplitIO.LocalhostFactory + localhostMode?: SplitIO.LocalhostFactory, + /* + * @TODO + * + * false by default + * if true: + * - In standalone mode, it will DISABLE splits and segments synchronization (i.e., polling and streaming) + * - In consumer mode, it will ENABLE events and impressions synchronization (i.e., submitters) + */ + onlyImpressionsAndEvents?: boolean } } /** @@ -481,6 +492,10 @@ declare namespace SplitIO { */ prefix?: string } + /** + * @TODO + */ + type DataLoader = (storage: StorageSync, key?: string) => void /** * Localhost mode factory. * Its interface details are not part of the public API. @@ -699,6 +714,42 @@ declare namespace SplitIO { * @typedef {string} ImpressionsMode */ type ImpressionsMode = 'OPTIMIZED' | 'DEBUG'; + /** + * Defines the format of Split data to preload on the factory storage (cache). + */ + interface PreloadedData { + /** + * Timestamp of the last moment the data was synchronized with Split servers. + * If this value is older than 10 days ago (expiration time policy), the data is not used to update the storage content. + * @TODO configurable expiration time policy? + */ + lastUpdated: number, + /** + * Change number of the preloaded data. + * If this value is older than the current changeNumber at the storage, the data is not used to update the storage content. + */ + since: number, + /** + * Map of splits to their serialized definitions. + */ + splitsData: { + [splitName: string]: string + }, + /** + * Optional map of user keys to their list of segments. + * @TODO remove when releasing first version + */ + mySegmentsData?: { + [key: string]: string[] + }, + /** + * Optional map of segments to their serialized definitions. + * This property is ignored if `mySegmentsData` was provided. + */ + segmentsData?: { + [segmentName: string]: string + }, + } /** * Logger * Its interface details are not part of the public API. It shouldn't be used directly. @@ -825,7 +876,7 @@ declare namespace SplitIO { */ features?: MockedFeaturesMap, /** - * Defines the factory function to instanciate the storage. If not provided, the default IN MEMORY storage is used. + * Defines the factory function to instantiate the storage. If not provided, the default IN MEMORY storage is used. * * Example: * ```typescript @@ -837,6 +888,10 @@ declare namespace SplitIO { * @property {Object} storage */ storage?: StorageSyncFactory, + /** + * @TODO + */ + dataLoader?: DataLoader, /** * List of URLs that the SDK will use as base for it's synchronization functionalities, applicable only when running as standalone. * Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy. From a0a290a1204202d67a12ff05b8b703c32b5b2c48 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Wed, 22 Jun 2022 23:48:32 -0300 Subject: [PATCH 2/3] add DataLoaderFactory in UMD build --- src/full/umd.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/full/umd.ts b/src/full/umd.ts index 23cc82b..9a49634 100644 --- a/src/full/umd.ts +++ b/src/full/umd.ts @@ -1,5 +1,5 @@ // @ts-nocheck -import { SplitFactory, InLocalStorage, GoogleAnalyticsToSplit, SplitToGoogleAnalytics, ErrorLogger, WarnLogger, InfoLogger, DebugLogger } from './index'; +import { SplitFactory, InLocalStorage, GoogleAnalyticsToSplit, SplitToGoogleAnalytics, ErrorLogger, WarnLogger, InfoLogger, DebugLogger, DataLoaderFactory } from './index'; // Include all pluggable modules as properties to expose at the global `splitio` object SplitFactory.SplitFactory = SplitFactory; @@ -10,6 +10,7 @@ SplitFactory.ErrorLogger = ErrorLogger; SplitFactory.WarnLogger = WarnLogger; SplitFactory.InfoLogger = InfoLogger; SplitFactory.DebugLogger = DebugLogger; +SplitFactory.DataLoaderFactory = DataLoaderFactory; // eslint-disable-next-line import/no-default-export export default SplitFactory; From 224d27e7715653c5a6de92a5df9541c7a751f8a9 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 23 Jun 2022 11:38:40 -0300 Subject: [PATCH 3/3] rc --- .github/workflows/ci-cd.yml | 4 ++-- package-lock.json | 8 ++++---- package.json | 4 ++-- src/settings/defaults.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 86739af..2bcc3cf 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -42,14 +42,14 @@ jobs: run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") BUILD_COMMIT=${{ github.sha }} npm run build - name: Configure AWS credentials (development) - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/data_loader' }} uses: aws-actions/configure-aws-credentials@v1 with: role-to-assume: arn:aws:iam::079419646996:role/public-assets aws-region: us-east-1 - name: Upload to S3 (development) - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/data_loader' }} run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS env: BUCKET: split-public-stage diff --git a/package-lock.json b/package-lock.json index 5c7c4b8..793fe90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-browserjs", - "version": "0.6.1-rc.1", + "version": "0.6.1-rc.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2184,9 +2184,9 @@ "dev": true }, "@splitsoftware/splitio-commons": { - "version": "1.4.2-rc.1", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.4.2-rc.1.tgz", - "integrity": "sha512-SuX2Fjt48TEHizOoAYw+cuL85kgJKUnMV1wxF5u+LUooeLrpP3GcKA6OkiHCwZSbbxhpp529mJTsyzeJpFqDYw==", + "version": "1.4.2-rc.2", + "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.4.2-rc.2.tgz", + "integrity": "sha512-9ePLuOB0jO0cAREd/UQ38GvkEieQF7c8Kk2MYN+LwvUNct17sjPHuCBWkmpQlLjFyiyKelpT6U6TgSO7hWX2Pg==", "requires": { "tslib": "^2.3.1" } diff --git a/package.json b/package.json index d7f6d49..c88061b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-browserjs", - "version": "0.6.1-rc.1", + "version": "0.6.1-rc.2", "description": "Split SDK for Javascript on Browser", "main": "cjs/index.js", "module": "esm/index.js", @@ -61,7 +61,7 @@ "bugs": "https://github.com/splitio/javascript-browser-client/issues", "homepage": "https://github.com/splitio/javascript-browser-client#readme", "dependencies": { - "@splitsoftware/splitio-commons": "1.4.2-rc.1", + "@splitsoftware/splitio-commons": "1.4.2-rc.2", "@types/google.analytics": "0.0.40" }, "devDependencies": { diff --git a/src/settings/defaults.ts b/src/settings/defaults.ts index 6beaaaf..f2ad118 100644 --- a/src/settings/defaults.ts +++ b/src/settings/defaults.ts @@ -2,7 +2,7 @@ import { LogLevels, isLogLevelString } from '@splitsoftware/splitio-commons/src/ import { ConsentStatus, LogLevel } from '@splitsoftware/splitio-commons/src/types'; import { CONSENT_GRANTED } from '@splitsoftware/splitio-commons/src/utils/constants'; -const packageVersion = '0.6.1-rc.1'; +const packageVersion = '0.6.1-rc.2'; /** * In browser, the default debug level, can be set via the `localStorage.splitio_debug` item.