@mparticle/web-sdk 2.66.0 → 2.68.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.
@@ -12,6 +12,7 @@ import {
12
12
  mParticleUserCart,
13
13
  IIdentityResponse,
14
14
  } from './identity-user-interfaces';
15
+ import { IdentitySearchCallback } from './identity/search';
15
16
  const { platform, sdkVendor, sdkVersion, HTTPCodes } = Constants;
16
17
 
17
18
  export type IdentityPreProcessResult = {
@@ -156,8 +157,53 @@ export interface SDKIdentityApi {
156
157
  destinationUser: IMParticleUser,
157
158
  scope?: AliasRequestScope
158
159
  ): IAliasRequest;
160
+ /**
161
+ * Sends a request to mParticle's IDSync `/v1/search` endpoint to look up
162
+ * a workspace identity without affecting the current user. The callback
163
+ * receives `httpCode` (always) and an optional `body` containing the
164
+ * parsed JSON response. Consumers should gate behaviour on
165
+ * `httpCode === 200`.
166
+ *
167
+ * `workspaceApiKey` is a workspace-specific API key supplied by the
168
+ * caller (from a kit's settings). It is sent as the `x-mp-key` header.
169
+ * The SDK's own workspace token is intentionally not used.
170
+ */
171
+ search?(
172
+ workspaceApiKey: string,
173
+ knownIdentities: UserIdentities,
174
+ callback: IdentitySearchCallback
175
+ ): void;
159
176
  }
160
177
 
178
+ export type {
179
+ IIdentitySearchResult,
180
+ IIdentitySearchResponseBody,
181
+ IdentitySearchCallback,
182
+ } from './identity/search';
183
+
184
+ export interface IUserIdentities {
185
+ customerid?: string;
186
+ email?: string;
187
+ other?: string;
188
+ other2?: string;
189
+ other3?: string;
190
+ other4?: string;
191
+ other5?: string;
192
+ other6?: string;
193
+ other7?: string;
194
+ other8?: string;
195
+ other9?: string;
196
+ other10?: string;
197
+ mobile_number?: string;
198
+ phone_number_2?: string;
199
+ phone_number_3?: string;
200
+ facebook?: string;
201
+ facebookcustomaudienceid?: string;
202
+ google?: string;
203
+ twitter?: string;
204
+ microsoft?: string;
205
+ yahoo?: string;
206
+ }
161
207
  export interface IIdentity {
162
208
  audienceManager: AudienceManager;
163
209
  idCache: BaseVault<Dictionary<ICachedIdentityCall>>;
package/src/identity.js CHANGED
@@ -3,6 +3,8 @@ import Types, { IdentityType } from './types';
3
3
  import {
4
4
  cacheOrClearIdCache,
5
5
  createKnownIdentities,
6
+ executeSearchRequest,
7
+ normalizeUserIdentityKeys,
6
8
  tryCacheIdentity,
7
9
  } from './identity-utils';
8
10
  import AudienceManager from './audienceManager';
@@ -34,11 +36,21 @@ export default function Identity(mpInstance) {
34
36
  );
35
37
 
36
38
  // First, remove any falsy identity values and warn about them
37
- const cleanedIdentityApiData = mpInstance._Helpers.Validators.removeFalsyIdentityValues(
39
+ const removedFalsyIdentityData = mpInstance._Helpers.Validators.removeFalsyIdentityValues(
38
40
  identityApiData,
39
41
  mpInstance.Logger
40
42
  );
41
43
 
44
+ // Normalize convenience aliases (email_sha256 → other, mobile_sha256 → other2)
45
+ const cleanedIdentityApiData = removedFalsyIdentityData?.userIdentities
46
+ ? {
47
+ ...removedFalsyIdentityData,
48
+ userIdentities: normalizeUserIdentityKeys(
49
+ removedFalsyIdentityData.userIdentities
50
+ ),
51
+ }
52
+ : removedFalsyIdentityData;
53
+
42
54
  var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(
43
55
  cleanedIdentityApiData,
44
56
  method
@@ -730,6 +742,32 @@ export default function Identity(mpInstance) {
730
742
  }
731
743
  },
732
744
 
745
+ /**
746
+ * Search the IDSync Workspace endpoint for a known identity.
747
+ *
748
+ * POSTs to mParticle's `/v1/search` endpoint and invokes `callback`
749
+ * with `{ httpCode, body? }`.
750
+ *
751
+ * The `workspaceApiKey` is a workspace-specific API key supplied by
752
+ * the caller (passed in from a kit's settings). It is intentionally
753
+ * NOT read from the SDK's own workspace token, so that workspace
754
+ * searches can be authorised independently of the host SDK's
755
+ * workspace.
756
+ *
757
+ * @method search
758
+ * @param {String} workspaceApiKey Workspace API key (sent as x-mp-key).
759
+ * @param {Object} knownIdentities A `UserIdentities` map.
760
+ * @param {Function} callback Invoked with the `IIdentitySearchResult`.
761
+ */
762
+ search: function(workspaceApiKey, knownIdentities, callback) {
763
+ executeSearchRequest(
764
+ mpInstance,
765
+ workspaceApiKey,
766
+ knownIdentities,
767
+ callback
768
+ );
769
+ },
770
+
733
771
  /**
734
772
  Create a default AliasRequest for 2 MParticleUsers. This will construct the request
735
773
  using the sourceUser's firstSeenTime as the startTime, and its lastSeenTime as the endTime.
@@ -394,6 +394,13 @@ function mParticleInstanceManager(this: IMParticleInstanceManager) {
394
394
  modify: function(identityApiData, callback) {
395
395
  self.getInstance().Identity.modify(identityApiData, callback);
396
396
  },
397
+ search: function(workspaceApiKey, knownIdentities, callback) {
398
+ self.getInstance().Identity.search(
399
+ workspaceApiKey,
400
+ knownIdentities,
401
+ callback
402
+ );
403
+ },
397
404
  };
398
405
 
399
406
  this.sessionManager = {
@@ -56,6 +56,10 @@ export type {
56
56
  IAliasCallback,
57
57
  IAliasResult,
58
58
  SDKIdentityTypeEnum,
59
+ IIdentitySearchResult,
60
+ IIdentitySearchResponseBody,
61
+ IdentitySearchCallback,
62
+ IUserIdentities
59
63
  } from './identity.interfaces';
60
64
 
61
65
  // eCommerce
@@ -161,9 +161,9 @@ export interface SDKProductAction {
161
161
  }
162
162
 
163
163
  export interface SDKProduct {
164
- Sku?: string;
165
- Name?: string;
166
- Price?: number;
164
+ Sku: string;
165
+ Name: string;
166
+ Price: number;
167
167
  Quantity?: number;
168
168
  Brand?: string;
169
169
  Variant?: string;
@@ -173,7 +173,7 @@ export interface SDKProduct {
173
173
  TotalAmount?: number;
174
174
 
175
175
  // https://go.mparticle.com/work/SQDSDKS-4801
176
- Attributes?: Record<string, unknown> | null;
176
+ Attributes?: Record<string, unknown>;
177
177
  }
178
178
 
179
179
  // https://go.mparticle.com/work/SQDSDKS-6949
@@ -306,7 +306,7 @@ export const LogLevelType = {
306
306
  // Currently, this extends MPConfiguration in @types/mparticle__web-sdk
307
307
  // and the two will be merged in once the Store module is refactored
308
308
  export interface SDKInitConfig
309
- extends Omit<MPConfiguration, 'dataPlan' | 'logLevel'> {
309
+ extends Omit<MPConfiguration, 'dataPlan' | 'logLevel' | 'identityCallback'> {
310
310
  dataPlan?: DataPlanConfig | KitBlockerDataPlan; // TODO: These should be eventually split into two different attributes
311
311
  logLevel?: LogLevelType;
312
312
 
@@ -56,6 +56,7 @@ let mParticle = {
56
56
  login: voidFunction,
57
57
  logout: voidFunction,
58
58
  modify: voidFunction,
59
+ search: voidFunction,
59
60
  },
60
61
  };
61
62
 
package/src/types.ts CHANGED
@@ -205,6 +205,10 @@ export const IdentityType = {
205
205
  return IdentityType.PhoneNumber2;
206
206
  case 'phone_number_3':
207
207
  return IdentityType.PhoneNumber3;
208
+ case 'email_sha256':
209
+ return IdentityType.Other;
210
+ case 'mobile_sha256':
211
+ return IdentityType.Other2;
208
212
  default:
209
213
  return false;
210
214
  }