@gem-sdk/core 1.46.0-staging.13 → 1.46.0-staging.21

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.
@@ -26,7 +26,7 @@ const SelleasyConfig = {
26
26
  };
27
27
  const LoopSubscriptionsConfig = {
28
28
  LoopSubscriptions: {
29
- appName: 'Loop Subscriptions',
29
+ appName: 'loop-subscriptions',
30
30
  appId: '267a7c64-5cb3-4552-b817-5485165f0a0b'
31
31
  }
32
32
  };
@@ -36,10 +36,17 @@ const SkioSubscriptionsYcS20Config = {
36
36
  appId: 'de50f7a4-0bb0-4d4c-84e2-c03dce83436d'
37
37
  }
38
38
  };
39
+ const ShopifyFormsConfig = {
40
+ ShopifyForms: {
41
+ appName: 'forms',
42
+ appId: '8744a304-fcb1-4347-b211-bb6b4759a76a'
43
+ }
44
+ };
39
45
 
40
46
  exports.BonLoyaltyRewardsReferralsConfig = BonLoyaltyRewardsReferralsConfig;
41
47
  exports.LoopSubscriptionsConfig = LoopSubscriptionsConfig;
42
48
  exports.RechargeSubscriptionsConfig = RechargeSubscriptionsConfig;
43
49
  exports.SelleasyConfig = SelleasyConfig;
50
+ exports.ShopifyFormsConfig = ShopifyFormsConfig;
44
51
  exports.SkioSubscriptionsYcS20Config = SkioSubscriptionsYcS20Config;
45
52
  exports.SubifySubscriptionsConfig = SubifySubscriptionsConfig;
@@ -57,7 +57,9 @@ const SelleasyWidget = {
57
57
  };
58
58
  const LoopSubscriptions = {
59
59
  LoopSubscriptions: {
60
- 'star_rating': null
60
+ star_rating: {
61
+ product: '{{product}}'
62
+ }
61
63
  }
62
64
  };
63
65
  const SkioSubscriptionsYcS20 = {
@@ -65,7 +67,26 @@ const SkioSubscriptionsYcS20 = {
65
67
  'app-block': null
66
68
  }
67
69
  };
70
+ const ShopifyForms = {
71
+ ShopifyForms: {
72
+ inline: {
73
+ form_id: null
74
+ }
75
+ }
76
+ };
77
+ const overrideSettings = (tag, currentSetting, appSetting)=>{
78
+ switch(tag){
79
+ case 'ShopifyForms':
80
+ return {
81
+ ...currentSetting,
82
+ form_id: appSetting['formId']
83
+ };
84
+ default:
85
+ return currentSetting;
86
+ }
87
+ };
68
88
  const composeSettingsByWidgetType = {
89
+ ...ShopifyForms,
69
90
  ...SkioSubscriptionsYcS20,
70
91
  ...LoopSubscriptions,
71
92
  ...RechargeSubscriptions,
@@ -75,3 +96,4 @@ const composeSettingsByWidgetType = {
75
96
  };
76
97
 
77
98
  exports.composeSettingsByWidgetType = composeSettingsByWidgetType;
99
+ exports.overrideSettings = overrideSettings;
@@ -8,7 +8,8 @@ const mapShopifyAppMeta = {
8
8
  ...appConfig.SubifySubscriptionsConfig,
9
9
  ...appConfig.SelleasyConfig,
10
10
  ...appConfig.LoopSubscriptionsConfig,
11
- ...appConfig.SkioSubscriptionsYcS20Config
11
+ ...appConfig.SkioSubscriptionsYcS20Config,
12
+ ...appConfig.ShopifyFormsConfig
12
13
  };
13
14
  const THIRD_PARTY_APP_BLOCK_ID_PREFIX = 'gp_app';
14
15
 
@@ -15,7 +15,20 @@ const generateAppBlockConfigs = (component)=>{
15
15
  if (!config) return;
16
16
  configs.push(config);
17
17
  });
18
- return configs;
18
+ if (!configs.length) return null;
19
+ return {
20
+ newBlocks: extractBlocks(configs),
21
+ newBlockOrder: extractBlockOrder(configs)
22
+ };
19
23
  };
24
+ function extractBlocks(array) {
25
+ return array.reduce((acc, item)=>{
26
+ acc[item.key] = item.value;
27
+ return acc;
28
+ }, {});
29
+ }
30
+ function extractBlockOrder(array) {
31
+ return array.map((item)=>item.key);
32
+ }
20
33
 
21
34
  exports.generateAppBlockConfigs = generateAppBlockConfigs;
@@ -9,12 +9,13 @@ const getAppBlockConfig = (tag, appBlockId, settings)=>{
9
9
  widgetType: settings?.widgetType
10
10
  });
11
11
  const settingByWidget = appSetting.composeSettingsByWidgetType[tag][settings?.widgetType];
12
+ const appSettings = appSetting.overrideSettings(tag, settingByWidget, settings);
12
13
  return {
13
14
  key: appBlockId,
14
15
  value: {
15
16
  type: appBlockType,
16
17
  ...settingByWidget && {
17
- settings: settingByWidget
18
+ settings: appSettings
18
19
  }
19
20
  }
20
21
  };
@@ -1,40 +1,26 @@
1
1
  'use strict';
2
2
 
3
- var removeMatchingKey = require('../remove-matching-key.js');
4
3
  var addAppBlockId = require('./addAppBlockId.js');
5
4
  var generateAppBlockConfigs = require('./generateAppBlockConfigs.js');
5
+ var mergeBlock = require('./mergeBlock.js');
6
+ var mergeBlockOrder = require('./mergeBlockOrder.js');
6
7
 
7
8
  const getAppBlocks = (section, currentBlock, currentBlockOrder)=>{
8
9
  const component = JSON.parse(section?.component || '');
9
10
  const componentWithAppBlockId = addAppBlockId.addAppBlockId(component);
10
11
  const appBlockConfigs = generateAppBlockConfigs.generateAppBlockConfigs(componentWithAppBlockId);
11
- if (!appBlockConfigs?.length) {
12
+ if (!appBlockConfigs) {
12
13
  return {
13
14
  blocks: currentBlock,
14
15
  block_order: currentBlockOrder
15
16
  };
16
17
  }
17
- let newBlocks = currentBlock;
18
- let newBlockOrder = currentBlockOrder;
19
- appBlockConfigs.forEach(({ key, value })=>{
20
- const newBlock = {
21
- [key]: value
22
- };
23
- const oldKeyRemovedBlock = removeMatchingKey.removeMatchingKey(newBlocks, key);
24
- newBlocks = {
25
- ...oldKeyRemovedBlock,
26
- ...newBlock
27
- };
28
- newBlockOrder = newBlockOrder ? [
29
- ...newBlockOrder,
30
- key
31
- ] : [
32
- key
33
- ];
34
- });
18
+ const { newBlocks, newBlockOrder } = appBlockConfigs;
19
+ const blocks = mergeBlock.mergeBlocks(newBlocks, currentBlock);
20
+ const block_order = mergeBlockOrder.mergeBlockOrder(newBlockOrder, currentBlockOrder);
35
21
  return {
36
- blocks: newBlocks,
37
- block_order: newBlockOrder
22
+ blocks,
23
+ block_order
38
24
  };
39
25
  };
40
26
 
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ function mergeBlocks(newBlocks, blocks) {
4
+ if (!blocks) return newBlocks;
5
+ const result = {};
6
+ // Add all non-gp_app blocks from the original blocks
7
+ for (const [key, value] of Object.entries(blocks)){
8
+ if (!key.startsWith('gp_app')) {
9
+ result[key] = value;
10
+ }
11
+ }
12
+ // Add all blocks from new-blocks
13
+ for (const [key, value] of Object.entries(newBlocks)){
14
+ result[key] = value;
15
+ }
16
+ return result;
17
+ }
18
+
19
+ exports.mergeBlocks = mergeBlocks;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var constant = require('./constant.js');
4
+
5
+ function isGpAppItem(item) {
6
+ if (!item) return false;
7
+ return item.startsWith(constant.THIRD_PARTY_APP_BLOCK_ID_PREFIX);
8
+ }
9
+ function filterCurrentOrder(currentOrder, newOrderSet) {
10
+ return currentOrder.filter((item)=>!isGpAppItem(item) || newOrderSet.has(item));
11
+ }
12
+ function processNonGpAppItem(item, resultOrder) {
13
+ resultOrder.push(item);
14
+ }
15
+ function processGpAppItems(newOrder, newOrderIndex, resultOrder) {
16
+ while(newOrderIndex < newOrder.length && isGpAppItem(newOrder[newOrderIndex])){
17
+ resultOrder.push(newOrder[newOrderIndex]);
18
+ newOrderIndex++;
19
+ }
20
+ return newOrderIndex;
21
+ }
22
+ function addRemainingGpAppItems(newOrder, startIndex, resultOrder) {
23
+ for(let i = startIndex; i < newOrder.length; i++){
24
+ const item = newOrder[i];
25
+ if (item && isGpAppItem(item)) {
26
+ resultOrder.push(item);
27
+ }
28
+ }
29
+ }
30
+ function mergeBlockOrder(newOrder, currentOrder) {
31
+ if (!currentOrder) return newOrder;
32
+ const newOrderSet = new Set(newOrder);
33
+ const filteredCurrentOrder = filterCurrentOrder(currentOrder, newOrderSet);
34
+ const resultOrder = [];
35
+ let newOrderIndex = 0;
36
+ filteredCurrentOrder.forEach((item)=>{
37
+ if (!isGpAppItem(item)) {
38
+ processNonGpAppItem(item, resultOrder);
39
+ return;
40
+ }
41
+ newOrderIndex = processGpAppItems(newOrder, newOrderIndex, resultOrder);
42
+ });
43
+ addRemainingGpAppItems(newOrder, newOrderIndex, resultOrder);
44
+ return resultOrder;
45
+ }
46
+
47
+ exports.mergeBlockOrder = mergeBlockOrder;
@@ -24,7 +24,7 @@ const SelleasyConfig = {
24
24
  };
25
25
  const LoopSubscriptionsConfig = {
26
26
  LoopSubscriptions: {
27
- appName: 'Loop Subscriptions',
27
+ appName: 'loop-subscriptions',
28
28
  appId: '267a7c64-5cb3-4552-b817-5485165f0a0b'
29
29
  }
30
30
  };
@@ -34,5 +34,11 @@ const SkioSubscriptionsYcS20Config = {
34
34
  appId: 'de50f7a4-0bb0-4d4c-84e2-c03dce83436d'
35
35
  }
36
36
  };
37
+ const ShopifyFormsConfig = {
38
+ ShopifyForms: {
39
+ appName: 'forms',
40
+ appId: '8744a304-fcb1-4347-b211-bb6b4759a76a'
41
+ }
42
+ };
37
43
 
38
- export { BonLoyaltyRewardsReferralsConfig, LoopSubscriptionsConfig, RechargeSubscriptionsConfig, SelleasyConfig, SkioSubscriptionsYcS20Config, SubifySubscriptionsConfig };
44
+ export { BonLoyaltyRewardsReferralsConfig, LoopSubscriptionsConfig, RechargeSubscriptionsConfig, SelleasyConfig, ShopifyFormsConfig, SkioSubscriptionsYcS20Config, SubifySubscriptionsConfig };
@@ -55,7 +55,9 @@ const SelleasyWidget = {
55
55
  };
56
56
  const LoopSubscriptions = {
57
57
  LoopSubscriptions: {
58
- 'star_rating': null
58
+ star_rating: {
59
+ product: '{{product}}'
60
+ }
59
61
  }
60
62
  };
61
63
  const SkioSubscriptionsYcS20 = {
@@ -63,7 +65,26 @@ const SkioSubscriptionsYcS20 = {
63
65
  'app-block': null
64
66
  }
65
67
  };
68
+ const ShopifyForms = {
69
+ ShopifyForms: {
70
+ inline: {
71
+ form_id: null
72
+ }
73
+ }
74
+ };
75
+ const overrideSettings = (tag, currentSetting, appSetting)=>{
76
+ switch(tag){
77
+ case 'ShopifyForms':
78
+ return {
79
+ ...currentSetting,
80
+ form_id: appSetting['formId']
81
+ };
82
+ default:
83
+ return currentSetting;
84
+ }
85
+ };
66
86
  const composeSettingsByWidgetType = {
87
+ ...ShopifyForms,
67
88
  ...SkioSubscriptionsYcS20,
68
89
  ...LoopSubscriptions,
69
90
  ...RechargeSubscriptions,
@@ -72,4 +93,4 @@ const composeSettingsByWidgetType = {
72
93
  ...SelleasyWidget
73
94
  };
74
95
 
75
- export { composeSettingsByWidgetType };
96
+ export { composeSettingsByWidgetType, overrideSettings };
@@ -1,4 +1,4 @@
1
- import { RechargeSubscriptionsConfig, BonLoyaltyRewardsReferralsConfig, SubifySubscriptionsConfig, SelleasyConfig, LoopSubscriptionsConfig, SkioSubscriptionsYcS20Config } from './appConfig.js';
1
+ import { RechargeSubscriptionsConfig, BonLoyaltyRewardsReferralsConfig, SubifySubscriptionsConfig, SelleasyConfig, LoopSubscriptionsConfig, SkioSubscriptionsYcS20Config, ShopifyFormsConfig } from './appConfig.js';
2
2
 
3
3
  const mapShopifyAppMeta = {
4
4
  ...RechargeSubscriptionsConfig,
@@ -6,7 +6,8 @@ const mapShopifyAppMeta = {
6
6
  ...SubifySubscriptionsConfig,
7
7
  ...SelleasyConfig,
8
8
  ...LoopSubscriptionsConfig,
9
- ...SkioSubscriptionsYcS20Config
9
+ ...SkioSubscriptionsYcS20Config,
10
+ ...ShopifyFormsConfig
10
11
  };
11
12
  const THIRD_PARTY_APP_BLOCK_ID_PREFIX = 'gp_app';
12
13
 
@@ -13,7 +13,20 @@ const generateAppBlockConfigs = (component)=>{
13
13
  if (!config) return;
14
14
  configs.push(config);
15
15
  });
16
- return configs;
16
+ if (!configs.length) return null;
17
+ return {
18
+ newBlocks: extractBlocks(configs),
19
+ newBlockOrder: extractBlockOrder(configs)
20
+ };
17
21
  };
22
+ function extractBlocks(array) {
23
+ return array.reduce((acc, item)=>{
24
+ acc[item.key] = item.value;
25
+ return acc;
26
+ }, {});
27
+ }
28
+ function extractBlockOrder(array) {
29
+ return array.map((item)=>item.key);
30
+ }
18
31
 
19
32
  export { generateAppBlockConfigs };
@@ -1,4 +1,4 @@
1
- import { composeSettingsByWidgetType } from './appSetting.js';
1
+ import { composeSettingsByWidgetType, overrideSettings } from './appSetting.js';
2
2
  import { getAppBlockType } from './getAppBlockType.js';
3
3
 
4
4
  const getAppBlockConfig = (tag, appBlockId, settings)=>{
@@ -7,12 +7,13 @@ const getAppBlockConfig = (tag, appBlockId, settings)=>{
7
7
  widgetType: settings?.widgetType
8
8
  });
9
9
  const settingByWidget = composeSettingsByWidgetType[tag][settings?.widgetType];
10
+ const appSettings = overrideSettings(tag, settingByWidget, settings);
10
11
  return {
11
12
  key: appBlockId,
12
13
  value: {
13
14
  type: appBlockType,
14
15
  ...settingByWidget && {
15
- settings: settingByWidget
16
+ settings: appSettings
16
17
  }
17
18
  }
18
19
  };
@@ -1,38 +1,24 @@
1
- import { removeMatchingKey } from '../remove-matching-key.js';
2
1
  import { addAppBlockId } from './addAppBlockId.js';
3
2
  import { generateAppBlockConfigs } from './generateAppBlockConfigs.js';
3
+ import { mergeBlocks } from './mergeBlock.js';
4
+ import { mergeBlockOrder } from './mergeBlockOrder.js';
4
5
 
5
6
  const getAppBlocks = (section, currentBlock, currentBlockOrder)=>{
6
7
  const component = JSON.parse(section?.component || '');
7
8
  const componentWithAppBlockId = addAppBlockId(component);
8
9
  const appBlockConfigs = generateAppBlockConfigs(componentWithAppBlockId);
9
- if (!appBlockConfigs?.length) {
10
+ if (!appBlockConfigs) {
10
11
  return {
11
12
  blocks: currentBlock,
12
13
  block_order: currentBlockOrder
13
14
  };
14
15
  }
15
- let newBlocks = currentBlock;
16
- let newBlockOrder = currentBlockOrder;
17
- appBlockConfigs.forEach(({ key, value })=>{
18
- const newBlock = {
19
- [key]: value
20
- };
21
- const oldKeyRemovedBlock = removeMatchingKey(newBlocks, key);
22
- newBlocks = {
23
- ...oldKeyRemovedBlock,
24
- ...newBlock
25
- };
26
- newBlockOrder = newBlockOrder ? [
27
- ...newBlockOrder,
28
- key
29
- ] : [
30
- key
31
- ];
32
- });
16
+ const { newBlocks, newBlockOrder } = appBlockConfigs;
17
+ const blocks = mergeBlocks(newBlocks, currentBlock);
18
+ const block_order = mergeBlockOrder(newBlockOrder, currentBlockOrder);
33
19
  return {
34
- blocks: newBlocks,
35
- block_order: newBlockOrder
20
+ blocks,
21
+ block_order
36
22
  };
37
23
  };
38
24
 
@@ -0,0 +1,17 @@
1
+ function mergeBlocks(newBlocks, blocks) {
2
+ if (!blocks) return newBlocks;
3
+ const result = {};
4
+ // Add all non-gp_app blocks from the original blocks
5
+ for (const [key, value] of Object.entries(blocks)){
6
+ if (!key.startsWith('gp_app')) {
7
+ result[key] = value;
8
+ }
9
+ }
10
+ // Add all blocks from new-blocks
11
+ for (const [key, value] of Object.entries(newBlocks)){
12
+ result[key] = value;
13
+ }
14
+ return result;
15
+ }
16
+
17
+ export { mergeBlocks };
@@ -0,0 +1,45 @@
1
+ import { THIRD_PARTY_APP_BLOCK_ID_PREFIX } from './constant.js';
2
+
3
+ function isGpAppItem(item) {
4
+ if (!item) return false;
5
+ return item.startsWith(THIRD_PARTY_APP_BLOCK_ID_PREFIX);
6
+ }
7
+ function filterCurrentOrder(currentOrder, newOrderSet) {
8
+ return currentOrder.filter((item)=>!isGpAppItem(item) || newOrderSet.has(item));
9
+ }
10
+ function processNonGpAppItem(item, resultOrder) {
11
+ resultOrder.push(item);
12
+ }
13
+ function processGpAppItems(newOrder, newOrderIndex, resultOrder) {
14
+ while(newOrderIndex < newOrder.length && isGpAppItem(newOrder[newOrderIndex])){
15
+ resultOrder.push(newOrder[newOrderIndex]);
16
+ newOrderIndex++;
17
+ }
18
+ return newOrderIndex;
19
+ }
20
+ function addRemainingGpAppItems(newOrder, startIndex, resultOrder) {
21
+ for(let i = startIndex; i < newOrder.length; i++){
22
+ const item = newOrder[i];
23
+ if (item && isGpAppItem(item)) {
24
+ resultOrder.push(item);
25
+ }
26
+ }
27
+ }
28
+ function mergeBlockOrder(newOrder, currentOrder) {
29
+ if (!currentOrder) return newOrder;
30
+ const newOrderSet = new Set(newOrder);
31
+ const filteredCurrentOrder = filterCurrentOrder(currentOrder, newOrderSet);
32
+ const resultOrder = [];
33
+ let newOrderIndex = 0;
34
+ filteredCurrentOrder.forEach((item)=>{
35
+ if (!isGpAppItem(item)) {
36
+ processNonGpAppItem(item, resultOrder);
37
+ return;
38
+ }
39
+ newOrderIndex = processGpAppItems(newOrder, newOrderIndex, resultOrder);
40
+ });
41
+ addRemainingGpAppItems(newOrder, newOrderIndex, resultOrder);
42
+ return resultOrder;
43
+ }
44
+
45
+ export { mergeBlockOrder };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/core",
3
- "version": "1.46.0-staging.13",
3
+ "version": "1.46.0-staging.21",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- const removeMatchingKey = (obj, searchText)=>{
4
- for(const key in obj){
5
- if (key.includes(searchText)) {
6
- delete obj[key];
7
- }
8
- }
9
- return obj;
10
- };
11
-
12
- exports.removeMatchingKey = removeMatchingKey;
@@ -1,10 +0,0 @@
1
- const removeMatchingKey = (obj, searchText)=>{
2
- for(const key in obj){
3
- if (key.includes(searchText)) {
4
- delete obj[key];
5
- }
6
- }
7
- return obj;
8
- };
9
-
10
- export { removeMatchingKey };