diff --git a/dist/types/src/consent.d.ts b/dist/types/src/consent.d.ts index 0c91d14bc..97eae4656 100644 --- a/dist/types/src/consent.d.ts +++ b/dist/types/src/consent.d.ts @@ -1,4 +1,4 @@ -import { ConsentState, PrivacyConsentState } from '@mparticle/web-sdk'; +import { ConsentState, PrivacyConsentState } from './publicSdkTypes'; import { Dictionary } from './utils'; import { IMParticleUser } from './identity-user-interfaces'; import { IMParticleWebSDKInstance } from './mp-instance'; diff --git a/dist/types/src/cookieSyncManager.d.ts b/dist/types/src/cookieSyncManager.d.ts index 49cb3b21c..fd94edd31 100644 --- a/dist/types/src/cookieSyncManager.d.ts +++ b/dist/types/src/cookieSyncManager.d.ts @@ -1,5 +1,5 @@ import { Dictionary } from './utils'; -import { MPID } from '@mparticle/web-sdk'; +import { MPID } from './publicSdkTypes'; import { IConsentRules } from './consent'; import { IMParticleWebSDKInstance } from './mp-instance'; export declare const DAYS_IN_MILLISECONDS: number; diff --git a/dist/types/src/ecommerce.interfaces.d.ts b/dist/types/src/ecommerce.interfaces.d.ts index 001a09e67..8cbd00ce2 100644 --- a/dist/types/src/ecommerce.interfaces.d.ts +++ b/dist/types/src/ecommerce.interfaces.d.ts @@ -1,5 +1,5 @@ import { ProductAction, Product, Promotion, CommerceEvent } from '@mparticle/event-models'; -import { SDKEventAttrs, SDKEventOptions, TransactionAttributes } from '@mparticle/web-sdk'; +import { SDKEventAttrs, SDKEventOptions, TransactionAttributes } from './publicSdkTypes'; import { valueof } from './utils'; import { ProductActionType, PromotionActionType, CommerceEventType, EventType } from './types'; import { SDKEvent, SDKEventCustomFlags, SDKImpression, SDKProduct, SDKProductImpression, SDKPromotion } from './sdkRuntimeModels'; @@ -58,9 +58,8 @@ interface ExtractedTransactionId { } export interface IECommerce extends IECommerceShared { buildProductList(event: SDKEvent, product: Product | Product[]): Product[]; - convertProductActionToEventType(productActionType: valueof): // https://go.mparticle.com/work/SQDSDKS-4801 - typeof CommerceEventType | typeof EventType | null; - convertPromotionActionToEventType(promotionActionType: valueof): typeof CommerceEventType | null; + convertProductActionToEventType(productActionType: valueof): valueof | valueof | null; + convertPromotionActionToEventType(promotionActionType: valueof): valueof | null; convertTransactionAttributesToProductAction(transactionAttributes: TransactionAttributes, productAction: ProductAction): void; createCommerceEventObject(customFlags: SDKEventCustomFlags, options?: SDKEventOptions): SDKEvent | null; expandProductAction(commerceEvent: CommerceEvent): SDKEvent[]; diff --git a/dist/types/src/events.interfaces.d.ts b/dist/types/src/events.interfaces.d.ts index d6cb3ae5b..a2a9f37bb 100644 --- a/dist/types/src/events.interfaces.d.ts +++ b/dist/types/src/events.interfaces.d.ts @@ -1,4 +1,4 @@ -import { Callback, SDKEventAttrs, SDKEventOptions, TransactionAttributes } from '@mparticle/web-sdk'; +import { Callback, SDKEventAttrs, SDKEventOptions, TransactionAttributes } from './publicSdkTypes'; import { BaseEvent, SDKEvent, SDKEventCustomFlags, SDKProduct, SDKProductImpression, SDKPromotion } from './sdkRuntimeModels'; import { valueof } from './utils'; import { EventType, ProductActionType, PromotionActionType } from './types'; diff --git a/dist/types/src/forwarders.interfaces.d.ts b/dist/types/src/forwarders.interfaces.d.ts index 8d52f64d4..faaa424d4 100644 --- a/dist/types/src/forwarders.interfaces.d.ts +++ b/dist/types/src/forwarders.interfaces.d.ts @@ -1,7 +1,8 @@ import { SDKEvent, SDKEventCustomFlags } from './sdkRuntimeModels'; import { Dictionary } from './utils'; import { IKitConfigs, IKitFilterSettings } from './configAPIClient'; -import { IdentityApiData, IdentityType } from '@mparticle/web-sdk'; +import { IdentityApiData } from './publicSdkTypes'; +import { IdentityType } from './types'; import { Batch } from '@mparticle/event-models'; import { IMParticleUser, ISDKUserIdentity, UserAttributes } from './identity-user-interfaces'; export type MPForwarder = Dictionary; diff --git a/dist/types/src/helpers.d.ts b/dist/types/src/helpers.d.ts index fbf123728..3c027218d 100644 --- a/dist/types/src/helpers.d.ts +++ b/dist/types/src/helpers.d.ts @@ -33,8 +33,8 @@ export default class Helpers { isStringOrNumber: (value: any) => boolean; isValidAttributeValue: (value: any) => boolean; isValidKeyValue: (key: any) => boolean; - removeFalsyIdentityValues: (identityApiData: import("@mparticle/web-sdk").IdentityApiData, logger: any) => import("@mparticle/web-sdk").IdentityApiData; - validateIdentities: (identityApiData: import("@mparticle/web-sdk").IdentityApiData, method?: import("./identity.interfaces").IdentityAPIMethod) => { + removeFalsyIdentityValues: (identityApiData: import("./publicSdkTypes").IdentityApiData, logger: any) => import("./publicSdkTypes").IdentityApiData; + validateIdentities: (identityApiData: import("./publicSdkTypes").IdentityApiData, method?: import("./identity.interfaces").IdentityAPIMethod) => { valid: boolean; error?: utils.valueof<{ readonly ModifyIdentityRequestUserIdentitiesPresent: "identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again"; diff --git a/dist/types/src/identity-user-interfaces.d.ts b/dist/types/src/identity-user-interfaces.d.ts index 483990b3b..721e624e4 100644 --- a/dist/types/src/identity-user-interfaces.d.ts +++ b/dist/types/src/identity-user-interfaces.d.ts @@ -1,16 +1,8 @@ -import { AllUserAttributes, MPID, User } from '@mparticle/web-sdk'; +import type { AllUserAttributes, IdentityCallback, IdentityResultBody, User } from './publicSdkTypes'; import { SDKIdentityTypeEnum } from './identity.interfaces'; import { MessageType } from './types'; import { BaseEvent, SDKProduct } from './sdkRuntimeModels'; -declare const HTTPCodes: { - readonly noHttpCoverage: -1; - readonly activeIdentityRequest: -2; - readonly activeSession: -3; - readonly validationIssue: -4; - readonly nativeIdentityRequest: -5; - readonly loggingDisabledOrMissingAPIKey: -6; - readonly tooManyRequests: 429; -}; +export type { IdentityCallback, IdentityModifyResultBody, IdentityResult, IdentityResultBody, } from './publicSdkTypes'; interface ICart { /** * @deprecated Cart persistence in mParticle has been deprecated. Please use mParticle.eCommerce.logProductAction(mParticle.ProductActionType.AddToCart, [products]) @@ -68,34 +60,12 @@ export interface IUserAttributeChangeEvent extends BaseEvent { messageType: typeof MessageType.UserAttributeChange; userAttributeChanges: ISDKUserAttributeChangeData; } -export interface IdentityCallback { - (result: IdentityResult): void; -} export interface IIdentityResponse { responseText: IdentityResultBody; status: number; cacheMaxAge?: number; expireTimestamp?: number; } -export interface IdentityResult { - httpCode: typeof HTTPCodes; - getPreviousUser(): User; - getUser(): User; - body: IdentityResultBody | IdentityModifyResultBody; -} -export interface IdentityResultBody { - context: string | null; - is_ephemeral: boolean; - is_logged_in: boolean; - matched_identities: Record; - mpid?: MPID; -} -export interface IdentityModifyResultBody { - change_results?: { - identity_type: SDKIdentityTypeEnum; - modified_mpid: MPID; - }; -} export interface mParticleUserCart { add(): void; remove(): void; @@ -103,4 +73,3 @@ export interface mParticleUserCart { getCartProducts(): SDKProduct[]; } export type UserAttributes = AllUserAttributes; -export {}; diff --git a/dist/types/src/identity-utils.d.ts b/dist/types/src/identity-utils.d.ts index 04983b95d..eaa73512a 100644 --- a/dist/types/src/identity-utils.d.ts +++ b/dist/types/src/identity-utils.d.ts @@ -1,8 +1,8 @@ import { Dictionary, Environment } from './utils'; import { BaseVault } from './vault'; -import { IdentityApiData, UserIdentities, IdentityCallback } from '@mparticle/web-sdk'; +import { IdentityApiData, UserIdentities } from './publicSdkTypes'; import { IdentityAPIMethod } from './identity.interfaces'; -import { IIdentityResponse, IMParticleUser } from './identity-user-interfaces'; +import { IdentityCallback, IIdentityResponse, IMParticleUser } from './identity-user-interfaces'; import { IStore } from './store'; import type { IMParticleWebSDKInstance } from './mp-instance'; import { IIdentitySearchRequestBody, IdentitySearchCallback } from './identity/search'; diff --git a/dist/types/src/identity.interfaces.d.ts b/dist/types/src/identity.interfaces.d.ts index a78d0755e..c09a05c24 100644 --- a/dist/types/src/identity.interfaces.d.ts +++ b/dist/types/src/identity.interfaces.d.ts @@ -1,8 +1,8 @@ -import { IdentityApiData, MPID, UserIdentities } from '@mparticle/web-sdk'; +import { IdentityApiData, MPID, UserIdentities } from './publicSdkTypes'; import AudienceManager from './audienceManager'; import { ICachedIdentityCall, IKnownIdentities } from './identity-utils'; import { BaseVault } from './vault'; -import { Dictionary, Environment, valueof } from './utils'; +import { Dictionary, valueof } from './utils'; import Constants from './constants'; import { IdentityCallback, IUserAttributeChangeEvent, IUserIdentityChangeEvent, IMParticleUser, mParticleUserCart, IIdentityResponse } from './identity-user-interfaces'; import { IdentitySearchCallback } from './identity/search'; @@ -51,9 +51,9 @@ export interface IIdentityAPIRequestData { sdk_version: typeof sdkVersion; }; context: string | null; - environment: Environment; + environment: string; request_id: string; - request_timestamp_unixtime_ms: number; + request_timestamp_ms: number; previous_mpid: MPID | null; known_identities: IKnownIdentities; } @@ -61,7 +61,7 @@ export interface IIdentityAPIModifyRequestData extends Omit = Record; +export type MPID = string; +export type SDKEventAttrTypes = string | number | boolean | null | undefined; +export interface SDKEventAttrs { + [key: string]: SDKEventAttrTypes; +} +export interface SDKEventCustomFlags { + [key: string]: number | string | boolean | unknown[] | Record; +} +export interface SDKEventOptions { + shouldUploadEvent?: boolean; +} +export interface Logger { + error?: (error: string) => void; + warning?: (warning: string) => void; + verbose?: (message: string) => void; +} +export interface DataPlanResult { + dtpn?: { + vers: DataPlanVersion; + blok: { + ev: boolean; + ea: boolean; + ua: boolean; + id: boolean; + }; + }; + error_message?: string; +} +export interface DataPlanConfig { + planId?: string; + planVersion?: number; + document?: DataPlanResult; +} +export interface KitBlockerOptions { + dataPlanVersion: DataPlanVersion; + blockUserAttributes: boolean; + blockEventAttributes: boolean; + blockEvents: boolean; + blockUserIdentities: boolean; +} +export interface KitBlockerDataPlan { + document: DataPlanResult; +} +export type MPForwarder = Dictionary; +export interface IdentityApiData { + userIdentities?: UserIdentities; + onUserAlias?: string; + copyUserAttributes?: boolean; +} +export interface IdentifyRequest extends IdentityApiData { + userIdentities: UserIdentities; +} +export interface UserIdentities { + customerid?: string; + email?: string; + other?: string; + other2?: string; + other3?: string; + other4?: string; + other5?: string; + other6?: string; + other7?: string; + other8?: string; + other9?: string; + other10?: string; + mobile_number?: string; + phone_number_2?: string; + phone_number_3?: string; + facebook?: string; + facebookcustomaudienceid?: string; + google?: string; + twitter?: string; + microsoft?: string; + yahoo?: string; +} +export type UserAttributesValue = string | number | boolean | null; +export type AllUserAttributes = Record; +export interface PrivacyConsentState { + Consented: boolean; + Timestamp?: number; + ConsentDocument?: string; + Location?: string; + HardwareId?: string; +} +export interface GDPRConsentState { + [key: string]: PrivacyConsentState; +} +export type CCPAConsentState = PrivacyConsentState; +export interface ConsentState { + setGDPRConsentState(gdprConsentState: GDPRConsentState): ConsentState; + setCCPAConsentState(ccpaConsentState: CCPAConsentState): ConsentState; + addGDPRConsentState(purpose: string, gdprConsent: PrivacyConsentState): ConsentState; + getGDPRConsentState(): GDPRConsentState; + getCCPAConsentState(): CCPAConsentState; + removeGDPRConsentState(purpose: string): ConsentState; + removeCCPAConsentState(): ConsentState; + removeCCPAState(): ConsentState; +} +export interface Product { + Name: string; + Sku: string; + Price: number; + Quantity?: number; + Variant?: string; + Category?: string; + Brand?: string; + Position?: number; + Coupon?: string; + CouponCode?: string; + TotalAmount?: number; + Attributes?: Record; +} +export interface TransactionAttributes { + Id: string | number; + Affiliation?: string; + CouponCode?: string; + Revenue?: string | number; + Shipping?: string | number; + Tax?: number; +} +export interface Impression { + Name: string; + Product: Product; +} +export interface Promotion { + Id: string; + Creative?: string; + Name?: string; + Position?: string; +} +export interface Cart { + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + add(product: Product | Product[], logEventBoolean?: boolean): void; + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + remove(product: Product | Product[], logEventBoolean?: boolean): void; + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + clear(): void; +} +export interface User { + getUserIdentities(): IdentityApiData; + getMPID(): MPID; + setUserTag(tag: string, value?: any): void; + removeUserTag(tag: string): void; + setUserAttribute(key: string, value: UserAttributesValue | UserAttributesValue[] | unknown): void; + setUserAttributes(attributeObject: Record): void; + removeUserAttribute(key: string): void; + setUserAttributeList(key: string, value: UserAttributesValue[]): void; + removeAllUserAttributes(): void; + getUserAttributesLists(): Record; + getAllUserAttributes(): AllUserAttributes; + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + getCart(): Cart; + getConsentState(): ConsentState; + setConsentState(consentState: ConsentState): void; + isLoggedIn(): boolean; + getLastSeenTime(): number; + getFirstSeenTime(): number; +} +export interface IdentityResultBody { + context: string | null; + is_ephemeral: boolean; + is_logged_in: boolean; + matched_identities: Record; + mpid?: MPID; +} +export interface IdentityModifyResultBody { + change_results?: { + identity_type: string; + modified_mpid: MPID; + }; +} +export interface IdentityResult { + httpCode: number; + getPreviousUser(): User; + getUser(): User; + body: IdentityResultBody | IdentityModifyResultBody; +} +export interface IdentityCallback { + (result: IdentityResult): void; +} +export type AliasRequestScope = 'device' | 'mpid'; +export interface UserAliasRequest { + destinationMpid: MPID; + sourceMpid: MPID; + startTime: number; + endTime: number; + scope?: AliasRequestScope; +} +export interface AliasUsersCallback { + (result: { + httpCode: number; + message: string; + }): void; +} +export interface Callback { + (): void; +} +export interface Location { + coords: { + latitude: number; + longitude: number; + }; + timestamp: number; +} +export interface TrackLocationCallback { + (location: Location): void; +} +export interface OnCreateBatch { + (batch: Batch): Batch; +} +export type onCreateBatch = OnCreateBatch; +export type LogLevel = 'verbose' | 'warning' | 'error' | 'none'; +export interface MPConfiguration { + isDevelopmentMode?: boolean; + identifyRequest?: IdentifyRequest; + identityCallback?: IdentityCallback; + dataPlan?: DataPlanConfig; + appVersion?: string; + appName?: string; + package?: string; + logLevel?: LogLevel; + logger?: Logger; + sessionTimeout?: number; + deviceId?: string; + onCreateBatch?: OnCreateBatch; + useCookieStorage?: boolean; + maxCookieSize?: number; + cookieDomain?: string; + customFlags?: SDKEventCustomFlags; + sideloadedKits?: MPForwarder[]; + workspaceToken?: string; + requiredWebviewBridgeName?: string; + minWebviewBridgeVersion?: 1 | 2; +} diff --git a/dist/types/src/sdkRuntimeModels.d.ts b/dist/types/src/sdkRuntimeModels.d.ts index 498eba155..91a9528a4 100644 --- a/dist/types/src/sdkRuntimeModels.d.ts +++ b/dist/types/src/sdkRuntimeModels.d.ts @@ -1,6 +1,5 @@ import * as EventsApi from '@mparticle/event-models'; -import { DataPlanVersion } from '@mparticle/data-planning-models'; -import { MPConfiguration, MPID, SDKEventOptions, SDKEventAttrs, Callback } from '@mparticle/web-sdk'; +import { Callback, DataPlanConfig, KitBlockerDataPlan, KitBlockerOptions, MPConfiguration, MPID, SDKEventAttrs, SDKEventOptions } from './publicSdkTypes'; import { IntegrationAttribute, IntegrationAttributes, IStore, WrapperSDKTypes } from './store'; import Validators from './validators'; import { Dictionary, valueof } from './utils'; @@ -20,6 +19,7 @@ import Constants from './constants'; import RoktManager, { IRoktLauncherOptions } from './roktManager'; import { IConsoleLogger } from './logger'; import { ErrorCodes, IErrorReportingService, ILoggingService } from './reporting/types'; +export type { DataPlanConfig, DataPlanResult, KitBlockerDataPlan, KitBlockerOptions, } from './publicSdkTypes'; export type SDKEventCustomFlags = Dictionary; export interface SDKEvent { DeviceId: string; @@ -175,14 +175,24 @@ export interface MParticleWebSDK { setOptOut(isOptingOut: boolean): void; startTrackingLocation(callback?: Callback): void; stopTrackingLocation(): void; - generateHash(value: string): string; + generateHash(value: string): number; setIntegrationAttribute(integrationModuleId: number, attrs: IntegrationAttribute): void; getIntegrationAttributes(integrationModuleId: number): IntegrationAttribute; captureTiming(metricName: string): void; _registerErrorReportingService(service: IErrorReportingService): void; _registerLoggingService(service: ILoggingService): void; } -export interface IMParticleInstanceManager extends MParticleWebSDK { +export interface MParticleWebSDKInstance extends MParticleWebSDK { +} +export interface MParticleWebSDKManager extends MParticleWebSDK { + config: SDKInitConfig; + isIOS?: boolean; + Rokt: RoktManager; + sessionManager: Pick; + Store: IStore; + getInstance(instanceName?: string): MParticleWebSDKInstance | null; +} +export interface IMParticleInstanceManager extends MParticleWebSDKManager { _BatchValidator: _BatchValidator; _instances: Dictionary; _isTestEnv?: boolean; @@ -237,11 +247,6 @@ export interface SDKInitConfig extends Omit, timeoutStart: number, now: number): boolean; isEventType?(type: valueof): boolean; isObject?(item: any): any; invokeCallback?(callback: IdentityCallback, code: number, body: string, mParticleUser?: IMParticleUser, previousMpid?: MPID): void; - sanitizeAttributes?(attrs: SDKEventAttrs, name: string): Dictionary | null; + sanitizeAttributes?(attrs: SDKEventAttrs, name: string): Dictionary | null; Validators: typeof Validators; } export interface SDKLoggerApi { @@ -295,25 +300,3 @@ export interface BaseEvent { userAttributeChanges?: ISDKUserAttributeChangeData; userIdentityChanges?: ISDKUserIdentityChanges; } -export interface KitBlockerOptions { - dataPlanVersion: DataPlanVersion; - blockUserAttributes: boolean; - blockEventAttributes: boolean; - blockEvents: boolean; - blockUserIdentities: boolean; -} -export interface KitBlockerDataPlan { - document: DataPlanResult; -} -export interface DataPlanResult { - dtpn?: { - vers: DataPlanVersion; - blok: { - ev: boolean; - ea: boolean; - ua: boolean; - id: boolean; - }; - }; - error_message?: string; -} diff --git a/dist/types/src/serverModel.d.ts b/dist/types/src/serverModel.d.ts index d36fb6802..135fc5c0d 100644 --- a/dist/types/src/serverModel.d.ts +++ b/dist/types/src/serverModel.d.ts @@ -1,7 +1,7 @@ import { BaseEvent, SDKEvent, SDKGeoLocation } from './sdkRuntimeModels'; import { Dictionary } from './utils'; import { ServerSettings } from './store'; -import { MPID } from '@mparticle/web-sdk'; +import { MPID } from './publicSdkTypes'; import { IConsentStateV2DTO, SDKConsentState } from './consent'; import { IMParticleUser, ISDKUserIdentity } from './identity-user-interfaces'; import { IMParticleWebSDKInstance } from './mp-instance'; diff --git a/dist/types/src/store.d.ts b/dist/types/src/store.d.ts index 13c51e041..7839c319b 100644 --- a/dist/types/src/store.d.ts +++ b/dist/types/src/store.d.ts @@ -1,5 +1,5 @@ import { Batch, Context } from '@mparticle/event-models'; -import { MPID, IdentifyRequest, SDKEventCustomFlags, ConsentState, UserIdentities } from '@mparticle/web-sdk'; +import { MPID, IdentifyRequest, SDKEventCustomFlags, ConsentState, UserIdentities } from './publicSdkTypes'; import { IKitConfigs } from './configAPIClient'; import { DataPlanResult, KitBlockerOptions, LogLevelType, SDKDataPlan, SDKEvent, SDKGeoLocation, SDKInitConfig, SDKProduct } from './sdkRuntimeModels'; import { Dictionary, AttributeValue } from './utils'; diff --git a/dist/types/src/utils.d.ts b/dist/types/src/utils.d.ts index 904e475d2..556d68e02 100644 --- a/dist/types/src/utils.d.ts +++ b/dist/types/src/utils.d.ts @@ -1,4 +1,4 @@ -import { MPID } from '@mparticle/web-sdk'; +import { MPID } from './publicSdkTypes'; import Constants from './constants'; import { SDKInitConfig } from './sdkRuntimeModels'; import { IKitConfigs } from './configAPIClient'; diff --git a/dist/types/src/validators.d.ts b/dist/types/src/validators.d.ts index 6f6791650..0c52ccbda 100644 --- a/dist/types/src/validators.d.ts +++ b/dist/types/src/validators.d.ts @@ -1,6 +1,6 @@ import { valueof } from './utils'; import Constants from './constants'; -import { IdentityApiData } from '@mparticle/web-sdk'; +import { IdentityApiData } from './publicSdkTypes'; import { IdentityAPIMethod } from './identity.interfaces'; type ValidationIdentitiesReturn = { valid: boolean; diff --git a/dist/types/src/window.interfaces.d.ts b/dist/types/src/window.interfaces.d.ts new file mode 100644 index 000000000..9a989db11 --- /dev/null +++ b/dist/types/src/window.interfaces.d.ts @@ -0,0 +1,8 @@ +export {}; +declare global { + interface Window { + mParticle?: any; + mParticleAndroid?: any; + webkit?: any; + } +} diff --git a/package.json b/package.json index 1eff994e6..9056a34c9 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "test:integrations:module": "npm run test:integrations:module:webpack && npm run test:integrations:module:rollup", "test:integrations:module:webpack": "npm run build:webpack:module && npm run test:karma:webpack:module", "test:integrations:module:rollup": "npm run build:rollup:module && npm run test:karma:rollup:module", + "test:types": "tsc -p test/types/tsconfig.json", "test:requirejs": "npm run build:iife && npm run build:rollup:requirejs && npm run test:requirejs:before && npm run test:requirejs:after", "test:requirejs:before": "cross-env FILE_ORDER=before_mp karma start test/integrations/requirejs/karma.requirejs.config.js", "test:requirejs:after": "cross-env FILE_ORDER=after_mp karma start test/integrations/requirejs/karma.requirejs.config.js", diff --git a/src/configAPIClient.ts b/src/configAPIClient.ts index b551af5f9..c0a0c1455 100644 --- a/src/configAPIClient.ts +++ b/src/configAPIClient.ts @@ -1,4 +1,4 @@ -import { DataPlanConfig } from '@mparticle/web-sdk'; +import { DataPlanConfig } from './publicSdkTypes'; import { BooleanStringLowerCase, DataPlanResult, diff --git a/src/consent.ts b/src/consent.ts index 81ae944cd..d301f12ff 100644 --- a/src/consent.ts +++ b/src/consent.ts @@ -3,7 +3,7 @@ import { ConsentState, GDPRConsentState, PrivacyConsentState, -} from '@mparticle/web-sdk'; +} from './publicSdkTypes'; import { Dictionary, isObject } from './utils'; import KitFilterHelper from './kitFilterHelper'; import Constants from './constants'; diff --git a/src/cookieSyncManager.ts b/src/cookieSyncManager.ts index 7a4ea9b63..8bdc019e4 100644 --- a/src/cookieSyncManager.ts +++ b/src/cookieSyncManager.ts @@ -4,7 +4,7 @@ import { createCookieSyncUrl, } from './utils'; import Constants from './constants'; -import { MPID } from '@mparticle/web-sdk'; +import { MPID } from './publicSdkTypes'; import { IConsentRules } from './consent'; import { IMParticleWebSDKInstance } from './mp-instance'; @@ -185,4 +185,4 @@ export const isLastSyncDateExpired = ( new Date().getTime() > new Date(lastSyncDate).getTime() + frequencyCap * DAYS_IN_MILLISECONDS ); -}; \ No newline at end of file +}; diff --git a/src/ecommerce.interfaces.ts b/src/ecommerce.interfaces.ts index 053f848c0..7d1076fee 100644 --- a/src/ecommerce.interfaces.ts +++ b/src/ecommerce.interfaces.ts @@ -8,7 +8,7 @@ import { SDKEventAttrs, SDKEventOptions, TransactionAttributes, -} from '@mparticle/web-sdk'; +} from './publicSdkTypes'; import { valueof } from './utils'; import { ProductActionType, @@ -159,10 +159,12 @@ export interface IECommerce extends IECommerceShared { convertProductActionToEventType( productActionType: valueof ): // https://go.mparticle.com/work/SQDSDKS-4801 - typeof CommerceEventType | typeof EventType | null; + | valueof + | valueof + | null; convertPromotionActionToEventType( promotionActionType: valueof - ): typeof CommerceEventType | null; + ): valueof | null; convertTransactionAttributesToProductAction( transactionAttributes: TransactionAttributes, productAction: ProductAction diff --git a/src/events.interfaces.ts b/src/events.interfaces.ts index 0674e47a8..92946e583 100644 --- a/src/events.interfaces.ts +++ b/src/events.interfaces.ts @@ -3,7 +3,7 @@ import { SDKEventAttrs, SDKEventOptions, TransactionAttributes, -} from '@mparticle/web-sdk'; +} from './publicSdkTypes'; import { BaseEvent, SDKEvent, diff --git a/src/forwarders.interfaces.ts b/src/forwarders.interfaces.ts index 17caa1a67..755c513ea 100644 --- a/src/forwarders.interfaces.ts +++ b/src/forwarders.interfaces.ts @@ -1,7 +1,8 @@ import { SDKEvent, SDKEventCustomFlags } from './sdkRuntimeModels'; import { Dictionary } from './utils'; import { IKitConfigs, IKitFilterSettings } from './configAPIClient'; -import { IdentityApiData, IdentityType } from '@mparticle/web-sdk'; +import { IdentityApiData } from './publicSdkTypes'; +import { IdentityType } from './types'; import { Batch } from '@mparticle/event-models'; import { diff --git a/src/identity-user-interfaces.ts b/src/identity-user-interfaces.ts index 9a4b673b6..eb3865941 100644 --- a/src/identity-user-interfaces.ts +++ b/src/identity-user-interfaces.ts @@ -1,9 +1,20 @@ -import { AllUserAttributes, MPID, User } from '@mparticle/web-sdk'; +import type { + AllUserAttributes, + IdentityCallback, + IdentityResultBody, + MPID, + User, +} from './publicSdkTypes'; import { SDKIdentityTypeEnum } from './identity.interfaces'; import { MessageType } from './types'; import { BaseEvent, SDKProduct } from './sdkRuntimeModels'; -import Constants from './constants'; -const { HTTPCodes } = Constants; + +export type { + IdentityCallback, + IdentityModifyResultBody, + IdentityResult, + IdentityResultBody, +} from './publicSdkTypes'; // Cart is Deprecated and private to mParticle user in @mparticle/web-sdk // but we need to expose it here for type safety in some of our tests @@ -79,11 +90,6 @@ export interface IUserAttributeChangeEvent extends BaseEvent { userAttributeChanges: ISDKUserAttributeChangeData; } -// https://go.mparticle.com/work/SQDSDKS-6460 -export interface IdentityCallback { - (result: IdentityResult): void; -} - export interface IIdentityResponse { // https://go.mparticle.com/work/SQDSDKS-6672 responseText: IdentityResultBody; @@ -92,28 +98,6 @@ export interface IIdentityResponse { expireTimestamp?: number; } -export interface IdentityResult { - httpCode: typeof HTTPCodes; - getPreviousUser(): User; - getUser(): User; - body: IdentityResultBody | IdentityModifyResultBody; -} - -export interface IdentityResultBody { - context: string | null; - is_ephemeral: boolean; - is_logged_in: boolean; - matched_identities: Record; - mpid?: MPID; -} - -export interface IdentityModifyResultBody { - change_results?: { - identity_type: SDKIdentityTypeEnum; - modified_mpid: MPID; - }; -} - export interface mParticleUserCart { add(): void; remove(): void; diff --git a/src/identity-utils.ts b/src/identity-utils.ts index 59ef35274..0d048e0f3 100644 --- a/src/identity-utils.ts +++ b/src/identity-utils.ts @@ -5,10 +5,10 @@ import Types from './types'; import { IdentityApiData, UserIdentities, - IdentityCallback, -} from '@mparticle/web-sdk'; +} from './publicSdkTypes'; import { IdentityAPIMethod, IIdentityRequest } from './identity.interfaces'; import { + IdentityCallback, IdentityResultBody, IIdentityResponse, IMParticleUser, diff --git a/src/identity.interfaces.ts b/src/identity.interfaces.ts index a223b77d2..46da40ac4 100644 --- a/src/identity.interfaces.ts +++ b/src/identity.interfaces.ts @@ -1,8 +1,8 @@ -import { IdentityApiData, MPID, UserIdentities } from '@mparticle/web-sdk'; +import { IdentityApiData, MPID, UserIdentities } from './publicSdkTypes'; import AudienceManager from './audienceManager'; import { ICachedIdentityCall, IKnownIdentities } from './identity-utils'; import { BaseVault } from './vault'; -import { Dictionary, Environment, valueof } from './utils'; +import { Dictionary, valueof } from './utils'; import Constants from './constants'; import { IdentityCallback, @@ -54,9 +54,9 @@ export interface IIdentityAPIRequestData { sdk_version: typeof sdkVersion; }; context: string | null; - environment: Environment; + environment: string; request_id: string; - request_timestamp_unixtime_ms: number; + request_timestamp_ms: number; previous_mpid: MPID | null; known_identities: IKnownIdentities; } @@ -70,7 +70,7 @@ export interface IIdentityAPIModifyRequestData } export interface IIdentityAPIIdentityChangeData { - identity_type: SDKIdentityTypeEnum; + identity_type: SDKIdentityTypeEnum | string; old_value: string; new_value: string; } @@ -100,7 +100,7 @@ export interface IIdentityRequest { createIdentityChanges( previousIdentities: UserIdentities, newIdentitie: UserIdentities - ): IIdentityAPIIdentityChangeData; + ): IIdentityAPIIdentityChangeData[]; preProcessIdentityRequest( identityApiData: IdentityApiData, callback: IdentityCallback, @@ -129,30 +129,30 @@ export interface IAliasResult { export interface SDKIdentityApi { HTTPCodes: typeof HTTPCodes; - identify?( + identify( identityApiData?: IdentityApiData, callback?: IdentityCallback ): void; - login?( + login( identityApiData?: IdentityApiData, callback?: IdentityCallback ): void; - logout?( + logout( identityApiData?: IdentityApiData, callback?: IdentityCallback ): void; - modify?( + modify( identityApiData?: IdentityApiData, callback?: IdentityCallback ): void; - getCurrentUser?(): IMParticleUser; - getUser?(mpid: string): IMParticleUser; - getUsers?(): IMParticleUser[]; - aliasUsers?( + getCurrentUser(): IMParticleUser; + getUser(mpid: string): IMParticleUser; + getUsers(): IMParticleUser[]; + aliasUsers( aliasRequest?: IAliasRequest, callback?: IdentityCallback ): void; - createAliasRequest?( + createAliasRequest( sourceUser: IMParticleUser, destinationUser: IMParticleUser, scope?: AliasRequestScope @@ -168,7 +168,7 @@ export interface SDKIdentityApi { * caller (from a kit's settings). It is sent as the `x-mp-key` header. * The SDK's own workspace token is intentionally not used. */ - search?( + search( workspaceApiKey: string, knownIdentities: UserIdentities, callback: IdentitySearchCallback diff --git a/src/identity.js b/src/identity.js index 29c9dacb9..a8a8f8b9e 100644 --- a/src/identity.js +++ b/src/identity.js @@ -844,6 +844,9 @@ export default function Identity(mpInstance) { * Example: mParticle.Identity.getCurrentUser().getAllUserAttributes() * @class mParticle.Identity.getCurrentUser() */ + /** + * @returns {import('./identity-user-interfaces').IMParticleUser} + */ this.mParticleUser = function(mpid, isLoggedIn) { var self = this; return { @@ -1326,6 +1329,9 @@ export default function Identity(mpInstance) { * @class mParticle.Identity.getCurrentUser().getCart() * @deprecated */ + /** + * @returns {import('./identity-user-interfaces').mParticleUserCart} + */ this.mParticleUserCart = function() { return { /** diff --git a/src/identity/search.ts b/src/identity/search.ts index 934cfae1b..8a8afa97b 100644 --- a/src/identity/search.ts +++ b/src/identity/search.ts @@ -12,7 +12,7 @@ import { IErrorReportingService, WSDKErrorSeverity, } from '../reporting/types'; -import { IdentityApiData, UserIdentities } from '@mparticle/web-sdk'; +import { IdentityApiData, UserIdentities } from '../publicSdkTypes'; import Validators from '../validators'; const { HTTPCodes } = Constants; diff --git a/src/identityApiClient.ts b/src/identityApiClient.ts index c26b9bade..a2cf3cdd3 100644 --- a/src/identityApiClient.ts +++ b/src/identityApiClient.ts @@ -18,7 +18,7 @@ import { IdentityApiData, MPID, UserIdentities, -} from '@mparticle/web-sdk'; +} from './publicSdkTypes'; import { IdentityCallback, IdentityResultBody, diff --git a/src/internal-types.ts b/src/internal-types.ts index 8097eda7c..e6609aabe 100644 --- a/src/internal-types.ts +++ b/src/internal-types.ts @@ -17,9 +17,24 @@ export * from './public-types'; export type { + ConfiguredKit, + forwardingStatsCallback, KitInterface, + KitRegistrationConfig, + MPForwarder, + RegisteredKit, + UnregisteredKit, + UserAttributeFilters, + UserIdentityFilters, + UserIdentityId, + UserIdentityType, } from './forwarders.interfaces'; +export type { + IKitConfigs, + IKitFilterSettings, +} from './configAPIClient'; + // Rokt integration types export type { RoktAttributeValue, diff --git a/src/mp-instance.ts b/src/mp-instance.ts index 618b19ab3..bba6eb6f4 100644 --- a/src/mp-instance.ts +++ b/src/mp-instance.ts @@ -36,13 +36,13 @@ import Consent, { IConsent } from './consent'; import KitBlocker from './kitBlocking'; import ConfigAPIClient, { IKitConfigs } from './configAPIClient'; import IdentityAPIClient from './identityApiClient'; -import { isFunction, parseConfig, valueof, generateDeprecationMessage, extend } from './utils'; +import { Dictionary, isFunction, parseConfig, valueof, generateDeprecationMessage, extend } from './utils'; import { DisabledVault, LocalStorageVault } from './vault'; import { removeExpiredIdentityCacheDates, hasExplicitIdentifier } from './identity-utils'; import IntegrationCapture from './integrationCapture'; import { IPreInit, processReadyQueue } from './pre-init-utils'; import { BaseEvent, MParticleWebSDK, SDKHelpersApi } from './sdkRuntimeModels'; -import { Dictionary, SDKEventAttrs } from '@mparticle/web-sdk'; +import { SDKEventAttrs } from './publicSdkTypes'; import { IIdentity } from './identity.interfaces'; import { IEvents } from './events.interfaces'; import { IECommerce } from './ecommerce.interfaces'; @@ -1741,4 +1741,3 @@ function queueIfNotInitialized(func, self) { }); return true; } - diff --git a/src/mparticle-instance-manager.ts b/src/mparticle-instance-manager.ts index 5c51b51bb..3bd36d5e4 100644 --- a/src/mparticle-instance-manager.ts +++ b/src/mparticle-instance-manager.ts @@ -6,7 +6,7 @@ import _BatchValidator from './mockBatchCreator'; import MPSideloadedKit from './sideloadedKit'; import { IMParticleInstanceManager } from './sdkRuntimeModels'; import { IStore } from './store'; -import { Dictionary } from '@mparticle/web-sdk'; +import { Dictionary } from './utils'; if (!Array.prototype.forEach) { Array.prototype.forEach = Polyfill.forEach; @@ -515,4 +515,4 @@ if (typeof window !== 'undefined') { window.mParticle._BatchValidator = new _BatchValidator(); } -export default mParticleManager; \ No newline at end of file +export default mParticleManager; diff --git a/src/persistence.interfaces.ts b/src/persistence.interfaces.ts index 639de8a3e..1a8e7b217 100644 --- a/src/persistence.interfaces.ts +++ b/src/persistence.interfaces.ts @@ -4,7 +4,7 @@ import { MPID, Product, UserIdentities, -} from '@mparticle/web-sdk'; +} from './publicSdkTypes'; import { IForwardingStatsData } from './apiClient'; import { IntegrationAttributes, @@ -102,7 +102,7 @@ export interface IPersistence { storeDataInMemory(obj: IPersistenceMinified, currentMPID: MPID): void; determineLocalStorageAvailability(storage: Storage): boolean; setLocalStorage(): void; - getLocalStorage(): IPersistenceMinified | null; + getLocalStorage(): IPersistenceMinified | Dictionary | null; expireCookies(cookieName: string): void; getCookie(): IPersistenceMinified | null; setCookie(): void; diff --git a/src/public-types.ts b/src/public-types.ts index d84f52ab4..ff687f342 100644 --- a/src/public-types.ts +++ b/src/public-types.ts @@ -7,18 +7,66 @@ * Usage: * import type { SDKInitConfig, EventType } from '@mparticle/web-sdk'; * - * Note: Types from @types/mparticle__web-sdk (e.g., MPConfiguration, MPID, - * ConsentState) are NOT re-exported here to avoid circular references. - * Consumers get those automatically via DefinitelyTyped until they are - * natively defined in this SDK and the DT package is deprecated. + * These declarations replace the legacy DefinitelyTyped surface. Keep this + * file focused on customer-facing SDK types; kit and SDK implementation types + * belong in internal-types.ts. */ +import type { MParticleWebSDKManager } from './sdkRuntimeModels'; + +declare const mParticle: MParticleWebSDKManager; + +export default mParticle; + // Re-export types from @mparticle/event-models // Consumers should not need to install @mparticle/event-models directly export type { Batch, } from '@mparticle/event-models'; +// Legacy DefinitelyTyped-owned public primitives now owned by this package +export type { + AliasRequestScope, + AliasUsersCallback, + AllUserAttributes, + Callback, + Cart, + CCPAConsentState, + ConsentState, + DataPlanConfig, + DataPlanResult, + Dictionary, + GDPRConsentState, + IdentityApiData, + IdentityCallback, + IdentityModifyResultBody, + IdentityResult, + IdentityResultBody, + IdentifyRequest, + Impression, + Location, + Logger, + LogLevel, + MPConfiguration, + MPForwarder, + MPID, + OnCreateBatch, + onCreateBatch, + PrivacyConsentState, + Product, + Promotion, + SDKEventAttrs, + SDKEventAttrTypes, + SDKEventCustomFlags, + SDKEventOptions, + TrackLocationCallback, + TransactionAttributes, + User, + UserAliasRequest, + UserAttributesValue, + UserIdentities, +} from './publicSdkTypes'; + // Enums / Constants (type-only to avoid runtime mismatch with entry point) export type { EventType, @@ -32,20 +80,16 @@ export type { // Configuration export type { SDKInitConfig, - DataPlanConfig, BaseEvent, - SDKEventCustomFlags, LogLevelType, + MParticleWebSDKInstance, + MParticleWebSDKManager, MParticleWebSDK, } from './sdkRuntimeModels'; // User & Identity export type { IMParticleUser, - IdentityCallback, - IdentityResult, - IdentityResultBody, - IdentityModifyResultBody, ISDKUserIdentity, ISDKUserAttributes, } from './identity-user-interfaces'; @@ -59,7 +103,7 @@ export type { IIdentitySearchResult, IIdentitySearchResponseBody, IdentitySearchCallback, - IUserIdentities + IUserIdentities, } from './identity.interfaces'; // eCommerce @@ -75,7 +119,7 @@ export type { SDKProductImpression, } from './sdkRuntimeModels'; -// Consent +// Consent API facade types export type { SDKConsentApi, SDKConsentState, @@ -85,4 +129,4 @@ export type { } from './consent'; // Utilities -export type { Dictionary, valueof } from './utils'; +export type { valueof } from './utils'; diff --git a/src/publicSdkTypes.ts b/src/publicSdkTypes.ts new file mode 100644 index 000000000..092fa2b98 --- /dev/null +++ b/src/publicSdkTypes.ts @@ -0,0 +1,297 @@ +import { Batch } from '@mparticle/event-models'; +import { DataPlanVersion } from '@mparticle/data-planning-models'; + +export type Dictionary = Record; + +export type MPID = string; + +export type SDKEventAttrTypes = string | number | boolean | null | undefined; + +export interface SDKEventAttrs { + [key: string]: SDKEventAttrTypes; +} + +export interface SDKEventCustomFlags { + [key: string]: + | number + | string + | boolean + | unknown[] + | Record; +} + +export interface SDKEventOptions { + shouldUploadEvent?: boolean; +} + +export interface Logger { + error?: (error: string) => void; + warning?: (warning: string) => void; + verbose?: (message: string) => void; +} + +export interface DataPlanResult { + dtpn?: { + vers: DataPlanVersion; + blok: { + ev: boolean; + ea: boolean; + ua: boolean; + id: boolean; + }; + }; + error_message?: string; +} + +export interface DataPlanConfig { + planId?: string; + planVersion?: number; + document?: DataPlanResult; +} + +export interface KitBlockerOptions { + dataPlanVersion: DataPlanVersion; + blockUserAttributes: boolean; + blockEventAttributes: boolean; + blockEvents: boolean; + blockUserIdentities: boolean; +} + +export interface KitBlockerDataPlan { + document: DataPlanResult; +} + +export type MPForwarder = Dictionary; + +export interface IdentityApiData { + userIdentities?: UserIdentities; + onUserAlias?: string; + copyUserAttributes?: boolean; +} + +export interface IdentifyRequest extends IdentityApiData { + userIdentities: UserIdentities; +} + +export interface UserIdentities { + customerid?: string; + email?: string; + other?: string; + other2?: string; + other3?: string; + other4?: string; + other5?: string; + other6?: string; + other7?: string; + other8?: string; + other9?: string; + other10?: string; + mobile_number?: string; + phone_number_2?: string; + phone_number_3?: string; + facebook?: string; + facebookcustomaudienceid?: string; + google?: string; + twitter?: string; + microsoft?: string; + yahoo?: string; +} + +export type UserAttributesValue = string | number | boolean | null; + +export type AllUserAttributes = Record< + string, + UserAttributesValue | UserAttributesValue[] +>; + +export interface PrivacyConsentState { + Consented: boolean; + Timestamp?: number; + ConsentDocument?: string; + Location?: string; + HardwareId?: string; +} + +export interface GDPRConsentState { + [key: string]: PrivacyConsentState; +} + +export type CCPAConsentState = PrivacyConsentState; + +export interface ConsentState { + setGDPRConsentState(gdprConsentState: GDPRConsentState): ConsentState; + setCCPAConsentState(ccpaConsentState: CCPAConsentState): ConsentState; + addGDPRConsentState( + purpose: string, + gdprConsent: PrivacyConsentState + ): ConsentState; + getGDPRConsentState(): GDPRConsentState; + getCCPAConsentState(): CCPAConsentState; + removeGDPRConsentState(purpose: string): ConsentState; + removeCCPAConsentState(): ConsentState; + removeCCPAState(): ConsentState; +} + +export interface Product { + Name: string; + Sku: string; + Price: number; + Quantity?: number; + Variant?: string; + Category?: string; + Brand?: string; + Position?: number; + Coupon?: string; + CouponCode?: string; + TotalAmount?: number; + Attributes?: Record; +} + +export interface TransactionAttributes { + Id: string | number; + Affiliation?: string; + CouponCode?: string; + Revenue?: string | number; + Shipping?: string | number; + Tax?: number; +} + +export interface Impression { + Name: string; + Product: Product; +} + +export interface Promotion { + Id: string; + Creative?: string; + Name?: string; + Position?: string; +} + +export interface Cart { + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + add(product: Product | Product[], logEventBoolean?: boolean): void; + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + remove(product: Product | Product[], logEventBoolean?: boolean): void; + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + clear(): void; +} + +export interface User { + getUserIdentities(): IdentityApiData; + getMPID(): MPID; + setUserTag(tag: string, value?: any): void; + removeUserTag(tag: string): void; + setUserAttribute( + key: string, + value: UserAttributesValue | UserAttributesValue[] | unknown + ): void; + setUserAttributes(attributeObject: Record): void; + removeUserAttribute(key: string): void; + setUserAttributeList(key: string, value: UserAttributesValue[]): void; + removeAllUserAttributes(): void; + getUserAttributesLists(): Record; + getAllUserAttributes(): AllUserAttributes; + /** + * @deprecated Cart persistence in mParticle has been deprecated. + */ + getCart(): Cart; + getConsentState(): ConsentState; + setConsentState(consentState: ConsentState): void; + isLoggedIn(): boolean; + getLastSeenTime(): number; + getFirstSeenTime(): number; +} + +export interface IdentityResultBody { + context: string | null; + is_ephemeral: boolean; + is_logged_in: boolean; + matched_identities: Record; + mpid?: MPID; +} + +export interface IdentityModifyResultBody { + change_results?: { + identity_type: string; + modified_mpid: MPID; + }; +} + +export interface IdentityResult { + httpCode: number; + getPreviousUser(): User; + getUser(): User; + body: IdentityResultBody | IdentityModifyResultBody; +} + +export interface IdentityCallback { + (result: IdentityResult): void; +} + +export type AliasRequestScope = 'device' | 'mpid'; + +export interface UserAliasRequest { + destinationMpid: MPID; + sourceMpid: MPID; + startTime: number; + endTime: number; + scope?: AliasRequestScope; +} + +export interface AliasUsersCallback { + (result: { httpCode: number; message: string }): void; +} + +export interface Callback { + (): void; +} + +export interface Location { + coords: { + latitude: number; + longitude: number; + }; + timestamp: number; +} + +export interface TrackLocationCallback { + (location: Location): void; +} + +export interface OnCreateBatch { + (batch: Batch): Batch; +} + +export type onCreateBatch = OnCreateBatch; + +export type LogLevel = 'verbose' | 'warning' | 'error' | 'none'; + +export interface MPConfiguration { + isDevelopmentMode?: boolean; + identifyRequest?: IdentifyRequest; + identityCallback?: IdentityCallback; + dataPlan?: DataPlanConfig; + appVersion?: string; + appName?: string; + package?: string; + logLevel?: LogLevel; + logger?: Logger; + sessionTimeout?: number; + deviceId?: string; + onCreateBatch?: OnCreateBatch; + useCookieStorage?: boolean; + maxCookieSize?: number; + cookieDomain?: string; + customFlags?: SDKEventCustomFlags; + sideloadedKits?: MPForwarder[]; + workspaceToken?: string; + requiredWebviewBridgeName?: string; + minWebviewBridgeVersion?: 1 | 2; +} diff --git a/src/roktManager.ts b/src/roktManager.ts index 844d2a209..fe76cc9aa 100644 --- a/src/roktManager.ts +++ b/src/roktManager.ts @@ -14,7 +14,7 @@ import { import { SDKIdentityApi } from "./identity.interfaces"; import { SDKLoggerApi } from "./sdkRuntimeModels"; import { IStore, LocalSessionAttributes } from "./store"; -import { UserIdentities } from "@mparticle/web-sdk"; +import { UserIdentities } from './publicSdkTypes'; import { IdentityType, PerformanceMarkType } from "./types"; import { ErrorCodes, IErrorReportingService, ILoggingService, WSDKErrorSeverity } from "./reporting/types"; diff --git a/src/sdkRuntimeModels.ts b/src/sdkRuntimeModels.ts index e31084228..2816d3075 100644 --- a/src/sdkRuntimeModels.ts +++ b/src/sdkRuntimeModels.ts @@ -1,12 +1,14 @@ import * as EventsApi from '@mparticle/event-models'; -import { DataPlanVersion } from '@mparticle/data-planning-models'; import { + Callback, + DataPlanConfig, + KitBlockerDataPlan, + KitBlockerOptions, MPConfiguration, MPID, - SDKEventOptions, SDKEventAttrs, - Callback, -} from '@mparticle/web-sdk'; + SDKEventOptions, +} from './publicSdkTypes'; import { IntegrationAttribute, IntegrationAttributes, @@ -53,7 +55,15 @@ import RoktManager, { IRoktLauncherOptions } from './roktManager'; import { IConsoleLogger } from './logger'; import { ErrorCodes, IErrorReportingService, ILoggingService } from './reporting/types'; -// TODO: Resolve this with version in @mparticle/web-sdk +export type { + DataPlanConfig, + DataPlanResult, + KitBlockerDataPlan, + KitBlockerOptions, +} from './publicSdkTypes'; + +// Internal SDK custom flags are normalized before upload and may temporarily +// contain arrays or other values supported by the legacy public API. export type SDKEventCustomFlags = Dictionary; export interface SDKEvent { @@ -253,7 +263,7 @@ export interface MParticleWebSDK { startTrackingLocation(callback?: Callback): void; stopTrackingLocation(): void; - generateHash(value: string): string; + generateHash(value: string): number; setIntegrationAttribute( integrationModuleId: number, attrs: IntegrationAttribute @@ -264,10 +274,21 @@ export interface MParticleWebSDK { _registerLoggingService(service: ILoggingService): void; } +export interface MParticleWebSDKInstance extends MParticleWebSDK {} + +export interface MParticleWebSDKManager extends MParticleWebSDK { + config: SDKInitConfig; + isIOS?: boolean; + Rokt: RoktManager; + sessionManager: Pick; + Store: IStore; + getInstance(instanceName?: string): MParticleWebSDKInstance | null; +} + // https://go.mparticle.com/work/SQDSDKS-4805 // https://go.mparticle.com/work/SQDSDKS-6949 -export interface IMParticleInstanceManager extends MParticleWebSDK { +export interface IMParticleInstanceManager extends MParticleWebSDKManager { // https://go.mparticle.com/work/SQDSDKS-5053 // Private Properties _BatchValidator: _BatchValidator; @@ -348,12 +369,6 @@ export interface SDKInitConfig logger?: IConsoleLogger; } -export interface DataPlanConfig { - planId?: string; - planVersion?: number; - document?: DataPlanResult; // when the data plan comes from the server via /mparticle.js -} - export interface SDKHelpersApi { canLog?(): boolean; createMainStorageName?(workspaceToken: string): string; @@ -363,7 +378,7 @@ export interface SDKHelpersApi { findKeyInObject?(obj: any, key: string): string; parseNumber?(value: string | number): number; generateUniqueId(); - generateHash?(value: string): string; + generateHash?(value: string): number; // https://go.mparticle.com/work/SQDSDKS-6317 getFeatureFlag?(feature: string): boolean | string; // TODO: Feature Constants should be converted to enum invokeAliasCallback( @@ -388,7 +403,7 @@ export interface SDKHelpersApi { sanitizeAttributes?( attrs: SDKEventAttrs, name: string - ): Dictionary | null; + ): Dictionary | null; Validators: typeof Validators; } @@ -428,28 +443,3 @@ export interface BaseEvent { userAttributeChanges?: ISDKUserAttributeChangeData; userIdentityChanges?: ISDKUserIdentityChanges; } - -export interface KitBlockerOptions { - dataPlanVersion: DataPlanVersion; - blockUserAttributes: boolean; - blockEventAttributes: boolean; - blockEvents: boolean; - blockUserIdentities: boolean; -} - -export interface KitBlockerDataPlan { - document: DataPlanResult; -} - -export interface DataPlanResult { - dtpn?: { - vers: DataPlanVersion; - blok: { - ev: boolean; - ea: boolean; - ua: boolean; - id: boolean; - }; - }; - error_message?: string; -} diff --git a/src/serverModel.ts b/src/serverModel.ts index c21663c9a..10044b67c 100644 --- a/src/serverModel.ts +++ b/src/serverModel.ts @@ -19,7 +19,7 @@ import { extend, } from './utils'; import { IntegrationAttributes, ServerSettings } from './store'; -import { MPID } from '@mparticle/web-sdk'; +import { MPID } from './publicSdkTypes'; import { IConsentStateV2DTO, IGDPRConsentStateV2DTO, diff --git a/src/sessionManager.ts b/src/sessionManager.ts index 4b6cf68a4..2380fb7b5 100644 --- a/src/sessionManager.ts +++ b/src/sessionManager.ts @@ -1,4 +1,4 @@ -import { MPID } from '@mparticle/web-sdk'; +import { MPID } from './publicSdkTypes'; import Constants from './constants'; import { IPersistenceMinified } from './persistence.interfaces'; import Types from './types'; diff --git a/src/store.ts b/src/store.ts index 4bd1617e1..df27301f5 100644 --- a/src/store.ts +++ b/src/store.ts @@ -6,7 +6,7 @@ import { SDKEventCustomFlags, ConsentState, UserIdentities, -} from '@mparticle/web-sdk'; +} from './publicSdkTypes'; import { IKitConfigs } from './configAPIClient'; import Constants from './constants'; import { diff --git a/src/user-utils.ts b/src/user-utils.ts index 9e491389b..7283de0fd 100644 --- a/src/user-utils.ts +++ b/src/user-utils.ts @@ -1,4 +1,4 @@ -import { UserIdentities } from '@mparticle/web-sdk'; +import { UserIdentities } from './publicSdkTypes'; import { IMParticleUser, ISDKUserIdentity, IdentityResultBody } from './identity-user-interfaces'; import { SDKEvent } from './sdkRuntimeModels'; import Types from './types'; diff --git a/src/utils.ts b/src/utils.ts index 916043e1a..2a90f1efa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { MPID } from '@mparticle/web-sdk'; +import { MPID } from './publicSdkTypes'; import Constants from './constants'; import { SDKInitConfig } from './sdkRuntimeModels'; import { IKitConfigs } from './configAPIClient'; diff --git a/src/validators.ts b/src/validators.ts index a9abf54ac..2c838585d 100644 --- a/src/validators.ts +++ b/src/validators.ts @@ -8,7 +8,7 @@ import { valueof, } from './utils'; import Constants from './constants'; -import { IdentityApiData } from '@mparticle/web-sdk'; +import { IdentityApiData } from './publicSdkTypes'; import { IdentityAPIMethod } from './identity.interfaces'; type ValidationIdentitiesReturn = { diff --git a/src/window.interfaces.ts b/src/window.interfaces.ts new file mode 100644 index 000000000..ef4073065 --- /dev/null +++ b/src/window.interfaces.ts @@ -0,0 +1,9 @@ +export {}; + +declare global { + interface Window { + mParticle?: any; + mParticleAndroid?: any; + webkit?: any; + } +} diff --git a/test/types/internal-consumer.ts b/test/types/internal-consumer.ts new file mode 100644 index 000000000..3867442c3 --- /dev/null +++ b/test/types/internal-consumer.ts @@ -0,0 +1,62 @@ +import type { + Batch, + ConfiguredKit, + IKitFilterSettings, + IRoktKit, + KitInterface, + SDKEvent, + UserIdentities, +} from '@mparticle/web-sdk/internal'; + +const filters: IKitFilterSettings = { + attributeFilters: [], + consentRegulationFilters: [], + consentRegulationPurposeFilters: [], + eventNameFilters: [], + eventTypeFilters: [], + messageTypeFilters: [], + messageTypeStateFilters: [], + screenAttributeFilters: [], + screenNameFilters: [], + userAttributeFilters: [], + userIdentityFilters: [], +}; + +const kit: KitInterface = { + id: 123, + name: 'Type Test Kit', + init(settings, service, testMode, trackerId, userAttributes) { + void settings; + void service; + void testMode; + void trackerId; + void userAttributes; + return 'initialized'; + }, + process(event: SDKEvent) { + return event.EventName; + }, + processBatch(batch: Batch) { + return String(batch.events?.length ?? 0); + }, + setUserIdentity(id, type) { + void id; + void type; + }, +}; + +const configuredKit = {} as ConfiguredKit; +const event = {} as SDKEvent; + +const forwarderResult: void = kit.setUserIdentity?.('user-id', 1); +const roktKit = {} as IRoktKit; +const identities: UserIdentities = { + email: 'name@example.com', +}; + +void filters; +void configuredKit; +void event; +void forwarderResult; +void roktKit; +void identities; diff --git a/test/types/public-consumer.ts b/test/types/public-consumer.ts new file mode 100644 index 000000000..e2644182c --- /dev/null +++ b/test/types/public-consumer.ts @@ -0,0 +1,165 @@ +import mParticle, { + type AllUserAttributes, + type IdentityApiData, + type IdentityCallback, + type IdentifyRequest, + type MPConfiguration, + type MPID, + type PrivacyConsentState, + type SDKEventAttrs, + type SDKEventCustomFlags, + type SDKEventOptions, + type SDKInitConfig, + type SDKProduct, + type TransactionAttributes, + type UserIdentities, +} from '@mparticle/web-sdk'; + +const identities: UserIdentities = { + customerid: 'customer-1', + email: 'name@example.com', + mobile_number: '+15555555555', +}; + +const identifyRequest: IdentifyRequest = { + userIdentities: identities, + copyUserAttributes: true, +}; + +const identityCallback: IdentityCallback = result => { + const mpid: MPID | undefined = + 'mpid' in result.body ? result.body.mpid : undefined; + const user = result.getUser(); + const attrs: AllUserAttributes = user.getAllUserAttributes(); + + user.setUserTag('vip', true); + user.setUserAttribute('age', 42); + user.setUserAttributeList('plans', ['basic', 'premium']); + user.setConsentState(mParticle.Consent.createConsentState()); + + void mpid; + void attrs; +}; + +const config: SDKInitConfig = { + appName: 'Type Test App', + appVersion: '1.2.3', + dataPlan: { + planId: 'web-plan', + planVersion: 2, + }, + dataPlanOptions: { + dataPlanVersion: { + version: 2, + }, + blockUserAttributes: true, + blockEventAttributes: true, + blockEvents: false, + blockUserIdentities: false, + }, + identityCallback, + identifyRequest, + integrationDelayTimeout: 500, + isDevelopmentMode: true, + launcherOptions: { + noFunctional: false, + noTargeting: true, + }, + logLevel: 'error', + requestConfig: false, + workspaceToken: 'workspace-token', +}; + +const legacyConfig: MPConfiguration = { + appName: 'Legacy Config Shape', + customFlags: { + bool: true, + list: ['a', 1, false], + nested: { source: 'type-test' }, + }, + logLevel: 'error', + onCreateBatch: batch => batch, +}; + +mParticle.init('api-key', config); +mParticle.init('api-key', legacyConfig); + +const instance = mParticle.getInstance(); + +if (instance) { + const attrs: SDKEventAttrs = { + bool: true, + count: 1, + nullable: null, + string: 'value', + }; + + const customFlags: SDKEventCustomFlags = { + flag: 'value', + values: ['a', 1, false], + }; + + const options: SDKEventOptions = { + shouldUploadEvent: false, + }; + + const product: SDKProduct | null = mParticle.eCommerce.createProduct( + 'Socks', + 'sku-1', + 12.99, + 2, + 'blue', + 'apparel', + 'mParticle', + 1, + 'WELCOME' + ); + + const transactionAttributes: TransactionAttributes | null = mParticle.eCommerce.createTransactionAttributes( + 'txn-1', + 'store', + 'WELCOME', + '25.98', + '0', + 2 + ); + + if (!product || !transactionAttributes) { + throw new Error('Expected ecommerce helpers to return values'); + } + + instance.logEvent( + 'Type Test Event', + mParticle.EventType.Other, + attrs, + customFlags, + options + ); + instance.logPageView('Type Test Page', attrs, customFlags, options); + instance.eCommerce.logProductAction( + mParticle.ProductActionType.Purchase, + product, + attrs, + customFlags, + transactionAttributes, + options + ); + instance.Identity.identify(identifyRequest, identityCallback); + instance.Identity.search('workspace-api-key', identities, result => { + if (result.httpCode === 200) { + void result.body?.mpid; + } + }); +} + +const consent: PrivacyConsentState | null = mParticle.Consent.createGDPRConsent( + true, + Date.now() +); + +const state = mParticle.Consent.createConsentState(); +if (consent) { + state.addGDPRConsentState('analytics', consent); +} +state.removeCCPAConsentState(); +state.removeCCPAState(); diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json new file mode 100644 index 000000000..d5a76ef4e --- /dev/null +++ b/test/types/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "baseUrl": "../..", + "esModuleInterop": true, + "lib": ["es5", "es6", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "noEmit": true, + "skipLibCheck": false, + "strict": true, + "target": "es5", + "types": [], + "paths": { + "@mparticle/web-sdk": ["dist/types/src/public-types.d.ts"], + "@mparticle/web-sdk/internal": ["dist/types/src/internal-types.d.ts"] + } + }, + "include": ["*.ts"] +}