@mparticle/web-sdk 2.61.0 → 2.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/mparticle.common.js +7 -6
  2. package/dist/mparticle.esm.js +7 -6
  3. package/dist/mparticle.js +131 -102
  4. package/dist/types/src/apiClient.d.ts +34 -0
  5. package/dist/types/src/audience.d.ts +4 -0
  6. package/dist/types/src/audienceManager.d.ts +19 -0
  7. package/dist/types/src/batchUploader.d.ts +72 -0
  8. package/dist/types/src/configAPIClient.d.ts +68 -0
  9. package/dist/types/src/consent.d.ts +71 -0
  10. package/dist/types/src/constants.d.ts +201 -0
  11. package/dist/types/src/cookieConsentManager.d.ts +50 -0
  12. package/dist/types/src/cookieSyncManager.d.ts +34 -0
  13. package/dist/types/src/ecommerce.d.ts +52 -0
  14. package/dist/types/src/ecommerce.interfaces.d.ts +78 -0
  15. package/dist/types/src/events.d.ts +17 -0
  16. package/dist/types/src/events.interfaces.d.ts +21 -0
  17. package/dist/types/src/filteredMparticleUser.d.ts +8 -0
  18. package/dist/types/src/foregroundTimeTracker.d.ts +21 -0
  19. package/dist/types/src/forwarders.d.ts +27 -0
  20. package/dist/types/src/forwarders.interfaces.d.ts +59 -0
  21. package/dist/types/src/forwardingStatsUploader.d.ts +5 -0
  22. package/dist/types/src/helpers.d.ts +54 -0
  23. package/dist/types/src/identity-user-interfaces.d.ts +106 -0
  24. package/dist/types/src/identity-utils.d.ts +36 -0
  25. package/dist/types/src/identity.interfaces.d.ts +117 -0
  26. package/dist/types/src/identityApiClient.d.ts +14 -0
  27. package/dist/types/src/integrationCapture.d.ts +83 -0
  28. package/dist/types/src/internal-types.d.ts +20 -0
  29. package/dist/types/src/kitBlocking.d.ts +116 -0
  30. package/dist/types/src/kitFilterHelper.d.ts +15 -0
  31. package/dist/types/src/logger.d.ts +18 -0
  32. package/dist/types/src/mockBatchCreator.d.ts +7 -0
  33. package/dist/types/src/mp-instance.d.ts +76 -0
  34. package/dist/types/src/mparticle-instance-manager.d.ts +2 -0
  35. package/dist/types/src/nativeSdkHelpers.d.ts +12 -0
  36. package/dist/types/src/nativeSdkHelpers.interfaces.d.ts +10 -0
  37. package/dist/types/src/persistence.d.ts +44 -0
  38. package/dist/types/src/persistence.interfaces.d.ts +73 -0
  39. package/dist/types/src/polyfill.d.ts +15 -0
  40. package/dist/types/src/pre-init-utils.d.ts +11 -0
  41. package/dist/types/src/public-types.d.ts +23 -0
  42. package/dist/types/src/reporting/errorReportingDispatcher.d.ts +8 -0
  43. package/dist/types/src/reporting/loggingDispatcher.d.ts +8 -0
  44. package/dist/types/src/reporting/types.d.ts +37 -0
  45. package/dist/types/src/roktManager.d.ts +176 -0
  46. package/dist/types/src/sdkRuntimeModels.d.ts +319 -0
  47. package/dist/types/src/sdkToEventsApiConverter.d.ts +43 -0
  48. package/dist/types/src/serverModel.d.ts +105 -0
  49. package/dist/types/src/sessionManager.d.ts +16 -0
  50. package/dist/types/src/sideloadedKit.d.ts +30 -0
  51. package/dist/types/src/store.d.ts +157 -0
  52. package/dist/types/src/stub/mparticle.stub.d.ts +182 -0
  53. package/dist/types/src/types.d.ts +154 -0
  54. package/dist/types/src/uploaders.d.ts +21 -0
  55. package/dist/types/src/user-utils.d.ts +5 -0
  56. package/dist/types/src/utils.d.ts +82 -0
  57. package/dist/types/src/validators.d.ts +18 -0
  58. package/dist/types/src/vault.d.ts +41 -0
  59. package/package.json +15 -2
  60. package/src/batchUploader.ts +13 -0
  61. package/src/forwarders.interfaces.ts +42 -0
  62. package/src/forwarders.js +28 -1
  63. package/src/internal-types.ts +66 -0
  64. package/src/public-types.ts +84 -0
  65. package/src/roktManager.ts +25 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.61.0",
3
+ "version": "2.63.0",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -12,6 +12,7 @@
12
12
  "dist/mparticle.common.js",
13
13
  "dist/mparticle.esm.js",
14
14
  "dist/mparticle.js",
15
+ "dist/types/",
15
16
  "src/"
16
17
  ],
17
18
  "publishConfig": {
@@ -21,9 +22,18 @@
21
22
  },
22
23
  "main": "dist/mparticle.common.js",
23
24
  "module": "dist/mparticle.esm.js",
25
+ "types": "dist/types/src/public-types.d.ts",
26
+ "typesVersions": {
27
+ "*": {
28
+ "internal": [
29
+ "dist/types/src/internal-types.d.ts"
30
+ ]
31
+ }
32
+ },
24
33
  "repository": "https://github.com/mParticle/mparticle-web-sdk",
25
34
  "scripts": {
26
- "build": "cross-env ENVIRONMENT=prod BUILDALL=true rollup --config rollup.config.js",
35
+ "build": "cross-env ENVIRONMENT=prod BUILDALL=true rollup --config rollup.config.js && npm run build:types",
36
+ "build:types": "rm -rf dist/types && (tsc -p tsconfig.types.json || true) && test -f dist/types/src/public-types.d.ts && test -f dist/types/src/internal-types.d.ts",
27
37
  "build:cbt": "rollup --config test/cross-browser-testing/rollup.CBT.config.js",
28
38
  "build:dev": "cross-env ENVIRONMENT=dev BUILD=iife rollup --config rollup.config.js",
29
39
  "build:iife": "cross-env ENVIRONMENT=prod BUILD=iife rollup --config rollup.config.js",
@@ -148,6 +158,9 @@
148
158
  "webpack": "^5.36.2",
149
159
  "webpack-cli": "^5.0.2"
150
160
  },
161
+ "peerDependencies": {
162
+ "@mparticle/event-models": "^1.1.9"
163
+ },
151
164
  "dependencies": {
152
165
  "@babel/runtime": "^7.23.2"
153
166
  }
@@ -333,6 +333,19 @@ export class BatchUploader {
333
333
  entry[1],
334
334
  mpInstance
335
335
  );
336
+
337
+ if (uploadBatchObject) {
338
+ try {
339
+ mpInstance._Forwarders.sendBatchToForwarders(
340
+ uploadBatchObject
341
+ );
342
+ } catch (e) {
343
+ mpInstance.Logger.error(
344
+ `Error forwarding batch to kits. ${e}`
345
+ );
346
+ }
347
+ }
348
+
336
349
  const onCreateBatchCallback =
337
350
  mpInstance._Store.SDKConfig.onCreateBatch;
338
351
 
@@ -2,6 +2,8 @@ import { SDKEvent, SDKEventCustomFlags } from './sdkRuntimeModels';
2
2
  import { Dictionary } from './utils';
3
3
  import { IKitConfigs, IKitFilterSettings } from './configAPIClient';
4
4
  import { IdentityApiData, IdentityType } from '@mparticle/web-sdk';
5
+ import { Batch } from '@mparticle/event-models';
6
+
5
7
  import {
6
8
  IMParticleUser,
7
9
  ISDKUserIdentity,
@@ -89,6 +91,46 @@ export interface ConfiguredKit
89
91
  hasSandbox: boolean;
90
92
  }
91
93
 
94
+ export interface KitInterface {
95
+ id: number;
96
+ name: string;
97
+ init(
98
+ settings: Dictionary<unknown>,
99
+ service: forwardingStatsCallback,
100
+ testMode?: boolean,
101
+ trackerId?: string | null,
102
+ userAttributes?: UserAttributes,
103
+ userIdentities?: ISDKUserIdentity,
104
+ appVersion?: string,
105
+ appName?: string,
106
+ customFlags?: SDKEventCustomFlags,
107
+ clientId?: string
108
+ ): string;
109
+ onIdentifyComplete?(
110
+ user: IMParticleUser,
111
+ filteredIdentityRequest: IdentityApiData
112
+ ): string;
113
+ onLoginComplete?(
114
+ user: IMParticleUser,
115
+ filteredIdentityRequest: IdentityApiData
116
+ ): string;
117
+ onLogoutComplete?(
118
+ user: IMParticleUser,
119
+ filteredIdentityRequest: IdentityApiData
120
+ ): string;
121
+ onModifyComplete?(
122
+ user: IMParticleUser,
123
+ filteredIdentityRequest: IdentityApiData
124
+ ): string;
125
+ onUserIdentified?(user: IMParticleUser): string;
126
+ process?(event: SDKEvent): string;
127
+ processBatch?(batch: Batch): string;
128
+ setOptOut?(isOptingOut: boolean): string;
129
+ removeUserAttribute?(key: string): string;
130
+ setUserAttribute?(key: string, value: string): string;
131
+ setUserIdentity?(id: UserIdentityId, type: UserIdentityType): void;
132
+ }
133
+
92
134
  export type UserIdentityId = string;
93
135
  export type UserIdentityType = number;
94
136
  export type UserAttributeFilters = number[];
package/src/forwarders.js CHANGED
@@ -405,6 +405,34 @@ export default function Forwarders(mpInstance, kitBlocker) {
405
405
  }
406
406
  };
407
407
 
408
+ this.sendBatchToForwarders = function(batch) {
409
+ if (
410
+ mpInstance._Store.webviewBridgeEnabled ||
411
+ !mpInstance._Store.activeForwarders
412
+ ) {
413
+ return;
414
+ }
415
+
416
+ for (const forwarder of mpInstance._Store.activeForwarders) {
417
+ if (forwarder.processBatch) {
418
+ try {
419
+ const batchCopy = mpInstance._Helpers.extend(
420
+ true,
421
+ {},
422
+ batch
423
+ );
424
+ const result = forwarder.processBatch(batchCopy);
425
+
426
+ if (result) {
427
+ mpInstance.Logger.verbose(result);
428
+ }
429
+ } catch (e) {
430
+ mpInstance.Logger.verbose(e);
431
+ }
432
+ }
433
+ }
434
+ };
435
+
408
436
  this.handleForwarderUserAttributes = function(functionNameKey, key, value) {
409
437
  if (
410
438
  (kitBlocker && kitBlocker.isAttributeKeyBlocked(key)) ||
@@ -747,7 +775,6 @@ export default function Forwarders(mpInstance, kitBlocker) {
747
775
  config.filteringConsentRuleValues || {};
748
776
  newForwarder.excludeAnonymousUser =
749
777
  config.excludeAnonymousUser || false;
750
-
751
778
  return newForwarder;
752
779
  };
753
780
 
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Internal types for @mparticle/web-sdk
3
+ *
4
+ * These types are shared between mParticle and Rokt SDKs but are NOT part of
5
+ * the public API. They may change without notice between minor versions.
6
+ *
7
+ * Usage:
8
+ * import type { IKitFilterSettings, IRoktKit, SDKProduct } from '@mparticle/web-sdk/internal';
9
+ *
10
+ * This entry point re-exports all public types so that internal consumers
11
+ * only need a single import path.
12
+ *
13
+ * Customers should NOT import from this path.
14
+ */
15
+
16
+ // Re-export all public types so internal consumers have a single import path
17
+ export * from './public-types';
18
+
19
+ export type {
20
+ KitInterface,
21
+ } from './forwarders.interfaces';
22
+
23
+ // Rokt integration types
24
+ export type {
25
+ RoktAttributeValue,
26
+ RoktAttributeValueType,
27
+ RoktAttributeValueArray,
28
+ RoktAttributes,
29
+ IRoktPartnerExtensionData,
30
+ IRoktSelectPlacementsOptions,
31
+ IRoktSelection,
32
+ IRoktLauncher,
33
+ IRoktMessage,
34
+ RoktKitFilterSettings,
35
+ IRoktKitSettings,
36
+ IRoktKit,
37
+ IRoktOptions,
38
+ IRoktLauncherOptions,
39
+ } from './roktManager';
40
+
41
+ // Reporting / Error types (type-only to avoid runtime mismatch with entry point)
42
+ export type {
43
+ ErrorCodes,
44
+ WSDKErrorSeverity,
45
+ } from './reporting/types';
46
+
47
+ export type {
48
+ ISDKError,
49
+ ISDKLogEntry,
50
+ IErrorReportingService,
51
+ ILoggingService,
52
+ } from './reporting/types';
53
+
54
+ // SDK internals shared between kits
55
+ export type {
56
+ SDKEvent,
57
+ SDKProductAction,
58
+ SDKProductActionType,
59
+ SDKPromotionAction,
60
+ SDKShoppingCart,
61
+ SDKGeoLocation,
62
+ SDKDataPlan,
63
+ SDKLoggerApi,
64
+ SDKConfigApi,
65
+ IMParticleInstanceManager,
66
+ } from './sdkRuntimeModels';
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Public types for @mparticle/web-sdk
3
+ *
4
+ * These types are part of the stable public API and are safe for customers
5
+ * to import. Only add types here that are intended for external consumption.
6
+ *
7
+ * Usage:
8
+ * import type { SDKInitConfig, EventType } from '@mparticle/web-sdk';
9
+ *
10
+ * Note: Types from @types/mparticle__web-sdk (e.g., MPConfiguration, MPID,
11
+ * ConsentState) are NOT re-exported here to avoid circular references.
12
+ * Consumers get those automatically via DefinitelyTyped until they are
13
+ * natively defined in this SDK and the DT package is deprecated.
14
+ */
15
+
16
+ // Re-export types from @mparticle/event-models
17
+ // Consumers should not need to install @mparticle/event-models directly
18
+ export type {
19
+ Batch,
20
+ } from '@mparticle/event-models';
21
+
22
+ // Enums / Constants (type-only to avoid runtime mismatch with entry point)
23
+ export type {
24
+ EventType,
25
+ CommerceEventType,
26
+ IdentityType,
27
+ ProductActionType,
28
+ PromotionActionType,
29
+ MessageType,
30
+ } from './types';
31
+
32
+ // Configuration
33
+ export type {
34
+ SDKInitConfig,
35
+ DataPlanConfig,
36
+ BaseEvent,
37
+ SDKEventCustomFlags,
38
+ LogLevelType,
39
+ MParticleWebSDK,
40
+ } from './sdkRuntimeModels';
41
+
42
+ // User & Identity
43
+ export type {
44
+ IMParticleUser,
45
+ IdentityCallback,
46
+ IdentityResult,
47
+ IdentityResultBody,
48
+ IdentityModifyResultBody,
49
+ ISDKUserIdentity,
50
+ ISDKUserAttributes,
51
+ } from './identity-user-interfaces';
52
+
53
+ export type {
54
+ SDKIdentityApi,
55
+ IAliasRequest,
56
+ IAliasCallback,
57
+ IAliasResult,
58
+ SDKIdentityTypeEnum,
59
+ } from './identity.interfaces';
60
+
61
+ // eCommerce
62
+ export type {
63
+ SDKECommerceAPI,
64
+ SDKCart,
65
+ } from './ecommerce.interfaces';
66
+
67
+ export type {
68
+ SDKProduct,
69
+ SDKPromotion,
70
+ SDKImpression,
71
+ SDKProductImpression,
72
+ } from './sdkRuntimeModels';
73
+
74
+ // Consent
75
+ export type {
76
+ SDKConsentApi,
77
+ SDKConsentState,
78
+ SDKConsentStateData,
79
+ SDKGDPRConsentState,
80
+ SDKCCPAConsentState,
81
+ } from './consent';
82
+
83
+ // Utilities
84
+ export type { Dictionary, valueof } from './utils';
@@ -305,27 +305,39 @@ export default class RoktManager {
305
305
  }
306
306
 
307
307
  if (!isEmpty(newIdentities)) {
308
- // Call identify with the new user identities
308
+ // Fire-and-forget identify — best-effort, does not block selectPlacements
309
309
  try {
310
- await new Promise<void>((resolve, reject) => {
311
- this.identityService.identify({
310
+ this.identityService.identify(
311
+ {
312
312
  userIdentities: {
313
313
  ...currentUserIdentities,
314
- ...newIdentities
314
+ ...newIdentities,
315
+ },
316
+ },
317
+ (result) => {
318
+ const httpCode = Number(result?.httpCode);
319
+ if (httpCode && (httpCode >= 400 || httpCode < 0)) {
320
+ this.logger.error(
321
+ 'Background identify failed with HTTP ' + httpCode
322
+ );
315
323
  }
316
- }, () => {
317
- resolve();
318
- });
319
- });
324
+ // Drain any selectPlacements calls that were deferred while
325
+ // identify was in-flight. By the time this callback fires,
326
+ // identityCallInFlight has already been reset to false.
327
+ this.processMessageQueue();
328
+ }
329
+ );
320
330
  } catch (error) {
321
331
  const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
322
- this.logger.error('Failed to identify user with updated identities: ' + errorMessage);
332
+ this.logger.error('Background identify threw an error: ' + errorMessage);
323
333
  }
324
334
  }
325
-
326
- // Refresh current user identities to ensure we have the latest values before building enrichedAttributes
327
- this.currentUser = this.identityService.getCurrentUser();
328
- const finalUserIdentities = this.currentUser?.getUserIdentities()?.userIdentities || {};
335
+
336
+ // Optimistic merge: apply the pending identity changes locally so
337
+ // enrichedAttributes are correct without waiting for the identify round-trip.
338
+ // The next call to selectPlacements re-fetches currentUser (see line above),
339
+ // so stale identity state does not persist beyond this invocation.
340
+ const finalUserIdentities = { ...currentUserIdentities, ...newIdentities };
329
341
 
330
342
  this.setUserAttributes(mappedAttributes);
331
343