@shrfe/assets 1.0.72 → 1.0.73

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.
@@ -36652,21 +36652,25 @@ const PROFILE_KEY_MAP = {
36652
36652
  firstName: 'first_name',
36653
36653
  lastName: 'last_name'
36654
36654
  };
36655
- // Customer.io's documented person attributes; any other profile key is dropped before identify.
36656
- const CUSTOMER_IO_ATTRIBUTES = new Set([
36655
+ // Renamed or ambiguous attributes: the stored key differs from the Customer.io name, or its leaf
36656
+ // ("id", "name") repeats across the tree, so each is pinned to an exact flattened key.
36657
+ const CUSTOMER_IO_ATTRIBUTE_SOURCES = {
36658
+ employee_phone: 'phone_number',
36659
+ employee_id: 'employee_id',
36660
+ employee_ums_user_id: 'breeze_user_id',
36661
+ jobrole_name: 'job_title',
36662
+ company_name: 'employer_name'
36663
+ };
36664
+ // Attributes a module stores under their own name; caught wherever they sit once flattened.
36665
+ const CUSTOMER_IO_ATTRIBUTES = [
36657
36666
  'first_name',
36658
36667
  'last_name',
36659
36668
  'gender',
36660
36669
  'email',
36661
- 'phone_number',
36662
- 'employer_name',
36663
36670
  'employer_address',
36664
36671
  'date_joined',
36665
36672
  'time_in_company',
36666
- 'employee_id',
36667
- 'job_title',
36668
36673
  'department',
36669
- 'breeze_user_id',
36670
36674
  'channel',
36671
36675
  'date_of_birth',
36672
36676
  'location',
@@ -36678,7 +36682,7 @@ const CUSTOMER_IO_ATTRIBUTES = new Set([
36678
36682
  'repayment_status',
36679
36683
  'device',
36680
36684
  'number_of_loans'
36681
- ]);
36685
+ ];
36682
36686
  // Where the SDK persists the identified person (localStorage and cookies).
36683
36687
  const STORED_IDENTITY_KEYS = [
36684
36688
  'ajs_user_id',
@@ -36745,6 +36749,18 @@ const isEventAllowed = (eventName)=>{
36745
36749
  return false;
36746
36750
  }
36747
36751
  };
36752
+ // The login payload nests attributes (employee.first_name, employee.company.name), so flatten to
36753
+ // parent_leaf keys the map can match. Only the immediate parent prefixes; later siblings win a clash.
36754
+ const flattenProfile = (source, containerKey = '', result = {})=>{
36755
+ Object.entries(source).forEach(([key, value])=>{
36756
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
36757
+ flattenProfile(value, key, result);
36758
+ } else {
36759
+ result[containerKey ? `${containerKey}_${key}` : key] = value;
36760
+ }
36761
+ });
36762
+ return result;
36763
+ };
36748
36764
  const toProfileTraits = (profile = {})=>{
36749
36765
  const traits = {};
36750
36766
  Object.entries(profile).forEach(([key, value])=>{
@@ -36795,12 +36811,20 @@ const CustomerIoService = {
36795
36811
  isInitialized () {
36796
36812
  return analytics !== null;
36797
36813
  },
36798
- identify (userId, profile) {
36799
- if (userId === undefined || userId === null || userId === '') return;
36814
+ identify (profile) {
36815
+ const flattened = flattenProfile(profile ?? {});
36800
36816
  const attributeProfile = {};
36801
- CUSTOMER_IO_ATTRIBUTES.forEach((name)=>{
36802
- if (profile && name in profile) attributeProfile[name] = profile[name];
36817
+ Object.entries(CUSTOMER_IO_ATTRIBUTE_SOURCES).forEach(([flatKey, attribute])=>{
36818
+ if (flatKey in flattened) attributeProfile[attribute] = flattened[flatKey];
36803
36819
  });
36820
+ CUSTOMER_IO_ATTRIBUTES.forEach((attribute)=>{
36821
+ if (attribute in attributeProfile) return;
36822
+ const match = Object.keys(flattened).find((key)=>key === attribute || key.endsWith(`_${attribute}`));
36823
+ if (match) attributeProfile[attribute] = flattened[match];
36824
+ });
36825
+ // Customer.io's second identifier (breeze_user_id) is the ums_user_id; it is the person's id.
36826
+ const userId = attributeProfile.breeze_user_id;
36827
+ if (userId === undefined || userId === null || userId === '') return;
36804
36828
  const traits = toProfileTraits(attributeProfile);
36805
36829
  log('identify', userId, traits);
36806
36830
  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",
3
+ "version": "1.0.73",
4
4
  "description": "The assets used in SeamlessHR products",
5
5
  "author": "SeamlessHR LTD <oludayo@seamlesshr.com>",
6
6
  "license": "ISC",