@shrfe/assets 1.0.72-staging.1 → 1.0.73-staging.1

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.
@@ -36661,21 +36661,25 @@ const PROFILE_KEY_MAP = {
36661
36661
  firstName: 'first_name',
36662
36662
  lastName: 'last_name'
36663
36663
  };
36664
- // Customer.io's documented person attributes; any other profile key is dropped before identify.
36665
- const CUSTOMER_IO_ATTRIBUTES = new Set([
36664
+ // Renamed or ambiguous attributes: the stored key differs from the Customer.io name, or its leaf
36665
+ // ("id", "name") repeats across the tree, so each is pinned to an exact flattened key.
36666
+ const CUSTOMER_IO_ATTRIBUTE_SOURCES = {
36667
+ employee_phone: 'phone_number',
36668
+ employee_id: 'employee_id',
36669
+ employee_ums_user_id: 'breeze_user_id',
36670
+ jobrole_name: 'job_title',
36671
+ company_name: 'employer_name'
36672
+ };
36673
+ // Attributes a module stores under their own name; caught wherever they sit once flattened.
36674
+ const CUSTOMER_IO_ATTRIBUTES = [
36666
36675
  'first_name',
36667
36676
  'last_name',
36668
36677
  'gender',
36669
36678
  'email',
36670
- 'phone_number',
36671
- 'employer_name',
36672
36679
  'employer_address',
36673
36680
  'date_joined',
36674
36681
  'time_in_company',
36675
- 'employee_id',
36676
- 'job_title',
36677
36682
  'department',
36678
- 'breeze_user_id',
36679
36683
  'channel',
36680
36684
  'date_of_birth',
36681
36685
  'location',
@@ -36687,7 +36691,7 @@ const CUSTOMER_IO_ATTRIBUTES = new Set([
36687
36691
  'repayment_status',
36688
36692
  'device',
36689
36693
  'number_of_loans'
36690
- ]);
36694
+ ];
36691
36695
  // Where the SDK persists the identified person (localStorage and cookies).
36692
36696
  const STORED_IDENTITY_KEYS = [
36693
36697
  'ajs_user_id',
@@ -36754,6 +36758,18 @@ const isEventAllowed = (eventName)=>{
36754
36758
  return false;
36755
36759
  }
36756
36760
  };
36761
+ // The login payload nests attributes (employee.first_name, employee.company.name), so flatten to
36762
+ // parent_leaf keys the map can match. Only the immediate parent prefixes; later siblings win a clash.
36763
+ const flattenProfile = (source, containerKey = '', result = {})=>{
36764
+ Object.entries(source).forEach(([key, value])=>{
36765
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
36766
+ flattenProfile(value, key, result);
36767
+ } else {
36768
+ result[containerKey ? `${containerKey}_${key}` : key] = value;
36769
+ }
36770
+ });
36771
+ return result;
36772
+ };
36757
36773
  const toProfileTraits = (profile = {})=>{
36758
36774
  const traits = {};
36759
36775
  Object.entries(profile).forEach(([key, value])=>{
@@ -36804,12 +36820,20 @@ const CustomerIoService = {
36804
36820
  isInitialized () {
36805
36821
  return analytics !== null;
36806
36822
  },
36807
- identify (userId, profile) {
36808
- if (userId === undefined || userId === null || userId === '') return;
36823
+ identify (profile) {
36824
+ const flattened = flattenProfile(profile ?? {});
36809
36825
  const attributeProfile = {};
36810
- CUSTOMER_IO_ATTRIBUTES.forEach((name)=>{
36811
- if (profile && name in profile) attributeProfile[name] = profile[name];
36826
+ Object.entries(CUSTOMER_IO_ATTRIBUTE_SOURCES).forEach(([flatKey, attribute])=>{
36827
+ if (flatKey in flattened) attributeProfile[attribute] = flattened[flatKey];
36812
36828
  });
36829
+ CUSTOMER_IO_ATTRIBUTES.forEach((attribute)=>{
36830
+ if (attribute in attributeProfile) return;
36831
+ const match = Object.keys(flattened).find((key)=>key === attribute || key.endsWith(`_${attribute}`));
36832
+ if (match) attributeProfile[attribute] = flattened[match];
36833
+ });
36834
+ // Customer.io's second identifier (breeze_user_id) is the ums_user_id; it is the person's id.
36835
+ const userId = attributeProfile.breeze_user_id;
36836
+ if (userId === undefined || userId === null || userId === '') return;
36813
36837
  const traits = toProfileTraits(attributeProfile);
36814
36838
  log('identify', userId, traits);
36815
36839
  safely((client)=>client.identify(String(userId), traits));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shrfe/assets",
3
- "version": "1.0.72-staging.1",
3
+ "version": "1.0.73-staging.1",
4
4
  "description": "The assets used in SeamlessHR products",
5
5
  "author": "SeamlessHR LTD <oludayo@seamlesshr.com>",
6
6
  "license": "ISC",