Skip to content

Commit 7be1902

Browse files
committed
test: add web sdk type consumer fixtures
1 parent 583a66a commit 7be1902

16 files changed

Lines changed: 349 additions & 100 deletions

dist/types/src/identity-user-interfaces.d.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import { AllUserAttributes, MPID, User } from './publicSdkTypes';
1+
import type { AllUserAttributes, IdentityCallback, IdentityResultBody, User } from './publicSdkTypes';
22
import { SDKIdentityTypeEnum } from './identity.interfaces';
33
import { MessageType } from './types';
44
import { BaseEvent, SDKProduct } from './sdkRuntimeModels';
5-
declare const HTTPCodes: {
6-
readonly noHttpCoverage: -1;
7-
readonly activeIdentityRequest: -2;
8-
readonly activeSession: -3;
9-
readonly validationIssue: -4;
10-
readonly nativeIdentityRequest: -5;
11-
readonly loggingDisabledOrMissingAPIKey: -6;
12-
readonly tooManyRequests: 429;
13-
};
5+
export type { IdentityCallback, IdentityModifyResultBody, IdentityResult, IdentityResultBody, } from './publicSdkTypes';
146
interface ICart {
157
/**
168
* @deprecated Cart persistence in mParticle has been deprecated. Please use mParticle.eCommerce.logProductAction(mParticle.ProductActionType.AddToCart, [products])
@@ -68,39 +60,16 @@ export interface IUserAttributeChangeEvent extends BaseEvent {
6860
messageType: typeof MessageType.UserAttributeChange;
6961
userAttributeChanges: ISDKUserAttributeChangeData;
7062
}
71-
export interface IdentityCallback {
72-
(result: IdentityResult): void;
73-
}
7463
export interface IIdentityResponse {
7564
responseText: IdentityResultBody;
7665
status: number;
7766
cacheMaxAge?: number;
7867
expireTimestamp?: number;
7968
}
80-
export interface IdentityResult {
81-
httpCode: typeof HTTPCodes;
82-
getPreviousUser(): User;
83-
getUser(): User;
84-
body: IdentityResultBody | IdentityModifyResultBody;
85-
}
86-
export interface IdentityResultBody {
87-
context: string | null;
88-
is_ephemeral: boolean;
89-
is_logged_in: boolean;
90-
matched_identities: Record<string, unknown>;
91-
mpid?: MPID;
92-
}
93-
export interface IdentityModifyResultBody {
94-
change_results?: {
95-
identity_type: SDKIdentityTypeEnum;
96-
modified_mpid: MPID;
97-
};
98-
}
9969
export interface mParticleUserCart {
10070
add(): void;
10171
remove(): void;
10272
clear(): void;
10373
getCartProducts(): SDKProduct[];
10474
}
10575
export type UserAttributes = AllUserAttributes;
106-
export {};

dist/types/src/identity.interfaces.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ export interface IAliasResult {
8989
}
9090
export interface SDKIdentityApi {
9191
HTTPCodes: typeof HTTPCodes;
92-
identify?(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
93-
login?(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
94-
logout?(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
95-
modify?(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
96-
getCurrentUser?(): IMParticleUser;
97-
getUser?(mpid: string): IMParticleUser;
98-
getUsers?(): IMParticleUser[];
99-
aliasUsers?(aliasRequest?: IAliasRequest, callback?: IdentityCallback): void;
100-
createAliasRequest?(sourceUser: IMParticleUser, destinationUser: IMParticleUser, scope?: AliasRequestScope): IAliasRequest;
92+
identify(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
93+
login(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
94+
logout(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
95+
modify(identityApiData?: IdentityApiData, callback?: IdentityCallback): void;
96+
getCurrentUser(): IMParticleUser;
97+
getUser(mpid: string): IMParticleUser;
98+
getUsers(): IMParticleUser[];
99+
aliasUsers(aliasRequest?: IAliasRequest, callback?: IdentityCallback): void;
100+
createAliasRequest(sourceUser: IMParticleUser, destinationUser: IMParticleUser, scope?: AliasRequestScope): IAliasRequest;
101101
/**
102102
* Sends a request to mParticle's IDSync `/v1/search` endpoint to look up
103103
* a workspace identity without affecting the current user. The callback
@@ -109,7 +109,7 @@ export interface SDKIdentityApi {
109109
* caller (from a kit's settings). It is sent as the `x-mp-key` header.
110110
* The SDK's own workspace token is intentionally not used.
111111
*/
112-
search?(workspaceApiKey: string, knownIdentities: UserIdentities, callback: IdentitySearchCallback): void;
112+
search(workspaceApiKey: string, knownIdentities: UserIdentities, callback: IdentitySearchCallback): void;
113113
}
114114
export type { IIdentitySearchResult, IIdentitySearchResponseBody, IdentitySearchCallback, } from './identity/search';
115115
export interface IUserIdentities {

dist/types/src/internal-types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* Customers should NOT import from this path.
1414
*/
1515
export * from './public-types';
16-
export type { KitInterface, } from './forwarders.interfaces';
16+
export type { ConfiguredKit, forwardingStatsCallback, KitInterface, KitRegistrationConfig, MPForwarder, RegisteredKit, UnregisteredKit, UserAttributeFilters, UserIdentityFilters, UserIdentityId, UserIdentityType, } from './forwarders.interfaces';
17+
export type { IKitConfigs, IKitFilterSettings, } from './configAPIClient';
1718
export type { RoktAttributeValue, RoktAttributeValueType, RoktAttributeValueArray, RoktAttributes, IRoktPartnerExtensionData, IRoktSelectPlacementsOptions, IRoktSelection, IRoktLauncher, IRoktMessage, RoktKitFilterSettings, IRoktKitSettings, IRoktKit, IRoktOptions, IRoktLauncherOptions, } from './roktManager';
1819
export type { ErrorCodes, WSDKErrorSeverity, } from './reporting/types';
1920
export type { ISDKError, ISDKLogEntry, IErrorReportingService, ILoggingService, } from './reporting/types';

dist/types/src/public-types.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
* file focused on customer-facing SDK types; kit and SDK implementation types
1212
* belong in internal-types.ts.
1313
*/
14+
import type { MParticleWebSDKManager } from './sdkRuntimeModels';
15+
declare const mParticle: MParticleWebSDKManager;
16+
export default mParticle;
1417
export type { Batch, } from '@mparticle/event-models';
1518
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';
1619
export type { EventType, CommerceEventType, IdentityType, ProductActionType, PromotionActionType, MessageType, } from './types';
17-
export type { SDKInitConfig, BaseEvent, LogLevelType, MParticleWebSDK, } from './sdkRuntimeModels';
20+
export type { SDKInitConfig, BaseEvent, LogLevelType, MParticleWebSDKInstance, MParticleWebSDKManager, MParticleWebSDK, } from './sdkRuntimeModels';
1821
export type { IMParticleUser, ISDKUserIdentity, ISDKUserAttributes, } from './identity-user-interfaces';
1922
export type { SDKIdentityApi, IAliasRequest, IAliasCallback, IAliasResult, SDKIdentityTypeEnum, IIdentitySearchResult, IIdentitySearchResponseBody, IdentitySearchCallback, IUserIdentities, } from './identity.interfaces';
2023
export type { SDKECommerceAPI, SDKCart, } from './ecommerce.interfaces';

dist/types/src/publicSdkTypes.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ export interface KitBlockerDataPlan {
4545
document: DataPlanResult;
4646
}
4747
export type MPForwarder = Dictionary;
48-
export interface IdentifyRequest {
49-
userIdentities: UserIdentities;
50-
}
5148
export interface IdentityApiData {
5249
userIdentities?: UserIdentities;
5350
onUserAlias?: string;
5451
copyUserAttributes?: boolean;
5552
}
53+
export interface IdentifyRequest extends IdentityApiData {
54+
userIdentities: UserIdentities;
55+
}
5656
export interface UserIdentities {
5757
customerid?: string;
5858
email?: string;
@@ -101,7 +101,7 @@ export interface ConsentState {
101101
}
102102
export interface Product {
103103
Name: string;
104-
Sku: string | number;
104+
Sku: string;
105105
Price: number;
106106
Quantity?: number;
107107
Variant?: string;
@@ -126,10 +126,10 @@ export interface Impression {
126126
Product: Product;
127127
}
128128
export interface Promotion {
129-
Id: string | number;
129+
Id: string;
130130
Creative?: string;
131131
Name?: string;
132-
Position?: string | number;
132+
Position?: string;
133133
}
134134
export interface Cart {
135135
/**

dist/types/src/sdkRuntimeModels.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,17 @@ export interface MParticleWebSDK {
182182
_registerErrorReportingService(service: IErrorReportingService): void;
183183
_registerLoggingService(service: ILoggingService): void;
184184
}
185-
export interface IMParticleInstanceManager extends MParticleWebSDK {
185+
export interface MParticleWebSDKInstance extends MParticleWebSDK {
186+
}
187+
export interface MParticleWebSDKManager extends MParticleWebSDK {
188+
config: SDKInitConfig;
189+
isIOS?: boolean;
190+
Rokt: RoktManager;
191+
sessionManager: Pick<ISessionManager, 'getSession'>;
192+
Store: IStore;
193+
getInstance(instanceName?: string): MParticleWebSDKInstance | null;
194+
}
195+
export interface IMParticleInstanceManager extends MParticleWebSDKManager {
186196
_BatchValidator: _BatchValidator;
187197
_instances: Dictionary<IMParticleWebSDKInstance>;
188198
_isTestEnv?: boolean;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"test:integrations:module": "npm run test:integrations:module:webpack && npm run test:integrations:module:rollup",
6868
"test:integrations:module:webpack": "npm run build:webpack:module && npm run test:karma:webpack:module",
6969
"test:integrations:module:rollup": "npm run build:rollup:module && npm run test:karma:rollup:module",
70+
"test:types": "tsc -p test/types/tsconfig.json",
7071
"test:requirejs": "npm run build:iife && npm run build:rollup:requirejs && npm run test:requirejs:before && npm run test:requirejs:after",
7172
"test:requirejs:before": "cross-env FILE_ORDER=before_mp karma start test/integrations/requirejs/karma.requirejs.config.js",
7273
"test:requirejs:after": "cross-env FILE_ORDER=after_mp karma start test/integrations/requirejs/karma.requirejs.config.js",

src/identity-user-interfaces.ts

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
import { AllUserAttributes, MPID, User } from './publicSdkTypes';
1+
import type {
2+
AllUserAttributes,
3+
IdentityCallback,
4+
IdentityResultBody,
5+
MPID,
6+
User,
7+
} from './publicSdkTypes';
28
import { SDKIdentityTypeEnum } from './identity.interfaces';
39
import { MessageType } from './types';
410
import { BaseEvent, SDKProduct } from './sdkRuntimeModels';
5-
import Constants from './constants';
6-
const { HTTPCodes } = Constants;
11+
12+
export type {
13+
IdentityCallback,
14+
IdentityModifyResultBody,
15+
IdentityResult,
16+
IdentityResultBody,
17+
} from './publicSdkTypes';
718

819
// Cart is Deprecated and private to mParticle user in @mparticle/web-sdk
920
// but we need to expose it here for type safety in some of our tests
@@ -79,11 +90,6 @@ export interface IUserAttributeChangeEvent extends BaseEvent {
7990
userAttributeChanges: ISDKUserAttributeChangeData;
8091
}
8192

82-
// https://go.mparticle.com/work/SQDSDKS-6460
83-
export interface IdentityCallback {
84-
(result: IdentityResult): void;
85-
}
86-
8793
export interface IIdentityResponse {
8894
// https://go.mparticle.com/work/SQDSDKS-6672
8995
responseText: IdentityResultBody;
@@ -92,28 +98,6 @@ export interface IIdentityResponse {
9298
expireTimestamp?: number;
9399
}
94100

95-
export interface IdentityResult {
96-
httpCode: typeof HTTPCodes;
97-
getPreviousUser(): User;
98-
getUser(): User;
99-
body: IdentityResultBody | IdentityModifyResultBody;
100-
}
101-
102-
export interface IdentityResultBody {
103-
context: string | null;
104-
is_ephemeral: boolean;
105-
is_logged_in: boolean;
106-
matched_identities: Record<string, unknown>;
107-
mpid?: MPID;
108-
}
109-
110-
export interface IdentityModifyResultBody {
111-
change_results?: {
112-
identity_type: SDKIdentityTypeEnum;
113-
modified_mpid: MPID;
114-
};
115-
}
116-
117101
export interface mParticleUserCart {
118102
add(): void;
119103
remove(): void;

src/identity.interfaces.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,30 @@ export interface IAliasResult {
129129

130130
export interface SDKIdentityApi {
131131
HTTPCodes: typeof HTTPCodes;
132-
identify?(
132+
identify(
133133
identityApiData?: IdentityApiData,
134134
callback?: IdentityCallback
135135
): void;
136-
login?(
136+
login(
137137
identityApiData?: IdentityApiData,
138138
callback?: IdentityCallback
139139
): void;
140-
logout?(
140+
logout(
141141
identityApiData?: IdentityApiData,
142142
callback?: IdentityCallback
143143
): void;
144-
modify?(
144+
modify(
145145
identityApiData?: IdentityApiData,
146146
callback?: IdentityCallback
147147
): void;
148-
getCurrentUser?(): IMParticleUser;
149-
getUser?(mpid: string): IMParticleUser;
150-
getUsers?(): IMParticleUser[];
151-
aliasUsers?(
148+
getCurrentUser(): IMParticleUser;
149+
getUser(mpid: string): IMParticleUser;
150+
getUsers(): IMParticleUser[];
151+
aliasUsers(
152152
aliasRequest?: IAliasRequest,
153153
callback?: IdentityCallback
154154
): void;
155-
createAliasRequest?(
155+
createAliasRequest(
156156
sourceUser: IMParticleUser,
157157
destinationUser: IMParticleUser,
158158
scope?: AliasRequestScope
@@ -168,7 +168,7 @@ export interface SDKIdentityApi {
168168
* caller (from a kit's settings). It is sent as the `x-mp-key` header.
169169
* The SDK's own workspace token is intentionally not used.
170170
*/
171-
search?(
171+
search(
172172
workspaceApiKey: string,
173173
knownIdentities: UserIdentities,
174174
callback: IdentitySearchCallback

src/internal-types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,24 @@
1717
export * from './public-types';
1818

1919
export type {
20+
ConfiguredKit,
21+
forwardingStatsCallback,
2022
KitInterface,
23+
KitRegistrationConfig,
24+
MPForwarder,
25+
RegisteredKit,
26+
UnregisteredKit,
27+
UserAttributeFilters,
28+
UserIdentityFilters,
29+
UserIdentityId,
30+
UserIdentityType,
2131
} from './forwarders.interfaces';
2232

33+
export type {
34+
IKitConfigs,
35+
IKitFilterSettings,
36+
} from './configAPIClient';
37+
2338
// Rokt integration types
2439
export type {
2540
RoktAttributeValue,

0 commit comments

Comments
 (0)