Setting the file. One moment. Orchestration Decisions · Wix Replatform · wix/skills · Skills Docslib/orchestration-decisions.js
JavaScript·150 lines·4 KB
],
9 websiteScope: ['websiteScope', 'frontendScope'],
10 faceliftMode: ['faceliftMode', 'facelift'],
11 fileInputPaths: ['fileInputPaths'],
12 sourcePlatform: ['sourcePlatform'],
13 sourceCredentialRef: ['sourceCredentialRef'],
14 managementImportMode: ['managementImportMode', 'importMode'],
15 includeAdditionalFiles: ['includeAdditionalFiles'],
16};
17
18function readDecisionValue(decisions, keys) {
19 for (const key of keys) {
20 const entry = decisions && decisions[key];
21 if (entry && Object.prototype.hasOwnProperty.call(entry, 'value') && entry.value != null) {
22 return entry.value;
23 }
24 }
25 return null;
26}
27
28function getDecisionEntry(decisions, canonicalKey) {
29 const keys = DECISION_ALIASES[canonicalKey] || [canonicalKey];
30 for (const key of keys) {
31 const entry = decisions && decisions[key];
32 if (entry && Object.prototype.hasOwnProperty.call(entry, 'value') && entry.value != null) {
33 return entry;
34 }
35 }
36 return null;
37}
38
39function normalizeSourceMode(value) {
40 if (value == null) return null;
41 switch (value) {
42 case 'private_authenticated':
43 return 'private_data';
44 case 'public_content_only':
45 return 'public_content';
46 default:
47 return value;
48 }
49}
50
51function normalizeTargetSiteStrategy(value) {
52 if (value == null) return null;
53 switch (value) {
54 case 'new':
55 return 'new_site';
56 case 'existing':
57 return 'existing_site';
58 default:
59 return value;
60 }
61}
62
63function normalizeAutomationMode(value) {
64 if (value == null) return null;
65 switch (value) {
66 case '1-click':
67 case '1click':
68 case 'one-click':
69 case 'one_click':
70 return 'one_click';
71 case 'manual':
72 return 'manual';
73 default:
74 return value;
75 }
76}
77
78function normalizeDeliveryMode(value) {
79 if (value == null) return null;
80 switch (String(value).trim().toLowerCase()) {
81 case 'both':
82 case 'management+website':
83 case 'management_and_website':
84 return 'management_and_website';
85 case 'management':
86 case 'website':
87 return String(value).trim().toLowerCase();
88 default:
89 return value;
90 }
91}
92
93function normalizeManagementImportMode(value) {
94 if (value == null) return null;
95 switch (String(value).trim().toLowerCase()) {
96 case 'quick':
97 case 'quick_mode':
98 return 'quick';
99 case 'standard':
100 case 'normal':
101 return 'standard';
102 default:
103 return value;
104 }
105}
106
107function normalizeFaceliftMode(value) {
108 if (value === true) return 'requested';
109 if (value === false || value == null) return 'off';
110 return ['requested', 'facelift', 'on', 'true'].includes(String(value).trim().toLowerCase()) ? 'requested' : 'off';
111}
112
113function getDecisionValue(decisions, canonicalKey) {
114 const keys = DECISION_ALIASES[canonicalKey] || [canonicalKey];
115 const value = readDecisionValue(decisions, keys);
116 if (canonicalKey === 'sourceMode') {
117 return normalizeSourceMode(value);
118 }
119 if (canonicalKey === 'targetSiteStrategy') {
120 return normalizeTargetSiteStrategy(value);
121 }
122 if (canonicalKey === 'automationMode') {
123 return normalizeAutomationMode(value);
124 }
125 if (canonicalKey === 'deliveryMode') {
126 return normalizeDeliveryMode(value);
127 }
128 if (canonicalKey === 'managementImportMode') {
129 return normalizeManagementImportMode(value);
130 }
131 if (canonicalKey === 'faceliftMode') return normalizeFaceliftMode(value);
132 return value;
133}
134
135function isExplicitUserOneClick(decisions) {
136 const entry = getDecisionEntry(decisions, 'automationMode');
137 return Boolean(entry && entry.source === 'user' && normalizeAutomationMode(entry.value) === 'one_click');
138}
139
140module.exports = {
141 getDecisionEntry,
142 getDecisionValue,
143 isExplicitUserOneClick,
144 normalizeAutomationMode,
145 normalizeDeliveryMode,
146 normalizeManagementImportMode,
147 normalizeFaceliftMode,
148 normalizeSourceMode,
149 normalizeTargetSiteStrategy,
150};