@isoftdata/svelte-ecommerce 1.0.0-beta.4 → 1.0.0-beta.6

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.
@@ -1,199 +1,204 @@
1
- <script lang="ts">
2
- import type { i18n } from 'i18next'
3
-
4
- import { getContext } from 'svelte'
5
-
6
- import EcommerceDefaults from './EcommerceDefaults.svelte'
7
- import type {
8
- EbayCategory,
9
- EbayCategoryMap,
10
- EbayPolicy,
11
- EbayLocation,
12
- EcommerceCondition,
13
- EcommerceConditionMap,
14
- ExtendedEcommerceConditionMap,
15
- EcommercePartnerConfiguration,
16
- EcommerceSharedDefaults,
17
- ExtendedEbayCategoryMap,
18
- ExtendedInventoryTypeListingDefaults,
19
- InventoryType,
20
- InventoryTypeCategory,
21
- InventoryTypeListingDefaults,
22
- NewInventoryTypeListingDefaults,
23
- Store,
24
- } from './utils.js'
25
- import EcommerceConditionMapConfig from './EcommerceConditionMapConfiguration.svelte'
26
- import EcommerceCategoryMapConfig from './EcommerceCategoryMapConfiguration.svelte'
27
- import EcommerceStoreConfig from './EcommerceStoreConfiguration.svelte'
28
- import EcommercePartTypeConfig from './EcommercePartTypeConfig.svelte'
29
-
30
- import { translate as defaultTranslate } from '@isoftdata/utility-string'
31
- const { t: translate } = getContext<i18n>('i18next') || { t: defaultTranslate }
32
-
33
- interface Props {
34
- ebayCategoryList: Array<EbayCategory>
35
- ebayCategoryMapList: Array<ExtendedEbayCategoryMap>
36
- ebayPolicyList: Array<EbayPolicy>
37
- ebayLocationList: Array<EbayLocation>
38
- ecommerceConditionList: Array<EcommerceCondition>
39
- ecommerceConditionMappingList: Array<ExtendedEcommerceConditionMap>
40
- inventoryConditionList: Array<string>
41
- inventoryTypeCategoryList: Array<InventoryTypeCategory>
42
- inventoryTypeList: Array<InventoryType>
43
- inventoryTypeWithDefaultConfigList: Array<ExtendedInventoryTypeListingDefaults>
44
- partnerConfigurationList: Array<EcommercePartnerConfiguration>
45
- saveEcommerceCategoryMap?: ((categoryMappingRow: EbayCategoryMap) => Promise<void>) | undefined
46
- saveEcommerceConditionMap?: ((config: EcommerceConditionMap) => Promise<void>) | undefined
47
- saveEcommercePartnerConfig?: ((config: EcommercePartnerConfiguration) => Promise<void>) | undefined
48
- saveEcommercePartTypeConfig?:
49
- | ((config: InventoryTypeListingDefaults | NewInventoryTypeListingDefaults) => Promise<void>)
50
- | undefined
51
- storeList: Array<Store>
52
- //
53
- }
54
-
55
- let {
56
- ebayCategoryList = [],
57
- ebayCategoryMapList = [],
58
- ebayLocationList = [],
59
- ebayPolicyList = [],
60
- ecommerceConditionList = [],
61
- ecommerceConditionMappingList = [],
62
- inventoryConditionList = [],
63
- inventoryTypeCategoryList = [],
64
- inventoryTypeList = [],
65
- inventoryTypeWithDefaultConfigList = [],
66
- partnerConfigurationList = [],
67
- saveEcommerceCategoryMap,
68
- saveEcommerceConditionMap,
69
- saveEcommercePartnerConfig,
70
- saveEcommercePartTypeConfig,
71
- storeList = [],
72
- }: Props = $props()
73
- // Hard coding this for now, should be selectable between htp and ebay....maybe just default to the only one?
74
- let selectedEcommercePartnerId = $state(1)
75
-
76
- let globalDefaults = $derived.by(getGlobalDefaults)
77
-
78
- function getGlobalDefaults() {
79
- const matchingPartnerConfig = partnerConfigurationList.find(
80
- row => row.ecommercePartnerId === selectedEcommercePartnerId,
81
- )
82
- if (matchingPartnerConfig) {
83
- return matchingPartnerConfig.defaults?.global
84
- }
85
- }
86
-
87
- // Handles global defaults being changed
88
- async function handleGlobalConfigChange() {
89
- // Find the matching partner config to update the global defaults on
90
- const matchingPartnerConfig = partnerConfigurationList.find(
91
- row => row.ecommercePartnerId === selectedEcommercePartnerId,
92
- )
93
-
94
- if (!matchingPartnerConfig) {
95
- console.error('No matching partner configuration found for ID:', selectedEcommercePartnerId)
96
- return
97
- }
98
-
99
- // Initialize defaults if it doesn't exist
100
- if (!matchingPartnerConfig.defaults) {
101
- matchingPartnerConfig.defaults = {
102
- global: {},
103
- store: [],
104
- }
105
- }
106
-
107
- // Update the global defaults with the new values (globalDefaults is already updated via binding)
108
- if (globalDefaults) {
109
- matchingPartnerConfig.defaults.global = { ...globalDefaults }
110
- }
111
-
112
- await saveEcommercePartnerConfig?.(matchingPartnerConfig)
113
- }
114
-
115
- async function handleStoreConfigChange(updatedPartnerConfig: EcommercePartnerConfiguration) {
116
- await saveEcommercePartnerConfig?.(updatedPartnerConfig)
117
- }
118
-
119
- async function handleCategoryMapChange(categoryMappingRow: EbayCategoryMap) {
120
- await saveEcommerceCategoryMap?.(categoryMappingRow)
121
- }
122
- async function handleConditionMapChange(conditionMapRow: EcommerceConditionMap) {
123
- await saveEcommerceConditionMap?.(conditionMapRow)
124
- }
125
-
126
- async function handlePartTypeConfigurationChange(
127
- partTypeConfigRow: InventoryTypeListingDefaults | NewInventoryTypeListingDefaults,
128
- ) {
129
- await saveEcommercePartTypeConfig?.(partTypeConfigRow)
130
- }
131
- </script>
132
-
133
- <div class="row mb-3">
134
- <div class="col">
135
- <div class="card">
136
- <div class="card-header">
137
- <h4 class="mb-0">{translate('ecommerce.configuration.globalDefaults', 'Global Defaults')}</h4>
138
- <p class="text-muted mb-0">
139
- {translate('ecommerce.configuration.configureGlobalDefaultsForEbay', 'Configure global defaults for eBay')}
140
- </p>
141
- </div>
142
- <div class="card-body">
143
- <EcommerceDefaults
144
- bind:defaults={globalDefaults}
145
- {ebayPolicyList}
146
- {ecommerceConditionList}
147
- {partnerConfigurationList}
148
- defaultsChanged={handleGlobalConfigChange}
149
- {selectedEcommercePartnerId}
150
- />
151
- </div>
152
- </div>
153
- </div>
154
- <div class="col">
155
- <EcommerceStoreConfig
156
- {ecommerceConditionList}
157
- {ebayLocationList}
158
- {ebayPolicyList}
159
- partnerConfigurationChanged={handleStoreConfigChange}
160
- {partnerConfigurationList}
161
- {selectedEcommercePartnerId}
162
- {storeList}
163
- />
164
- </div>
165
- </div>
166
- <div class="row mb-3">
167
- <div class="col">
168
- <EcommerceConditionMapConfig
169
- {ecommerceConditionList}
170
- {inventoryConditionList}
171
- {ecommerceConditionMappingList}
172
- conditionMapChanged={handleConditionMapChange}
173
- />
174
- </div>
175
- </div>
176
- <div class="row mb-3">
177
- <div class="col">
178
- <EcommerceCategoryMapConfig
179
- {ebayCategoryList}
180
- {ebayCategoryMapList}
181
- {inventoryTypeList}
182
- categoryMapChanged={handleCategoryMapChange}
183
- />
184
- </div>
185
- </div>
186
- <div class="row mb-3">
187
- <div class="col">
188
- <EcommercePartTypeConfig
189
- {ebayPolicyList}
190
- {ecommerceConditionList}
191
- {inventoryTypeList}
192
- {inventoryTypeWithDefaultConfigList}
193
- {inventoryTypeCategoryList}
194
- {partnerConfigurationList}
195
- partTypeConfigurationChanged={handlePartTypeConfigurationChange}
196
- {selectedEcommercePartnerId}
197
- />
198
- </div>
199
- </div>
1
+ <script lang="ts">
2
+ import type { i18n } from 'i18next'
3
+
4
+ import { getContext } from 'svelte'
5
+
6
+ import EcommerceDefaults from './EcommerceDefaults.svelte'
7
+ import type {
8
+ EbayCategory,
9
+ EbayCategoryMap,
10
+ EbayPolicy,
11
+ EbayLocation,
12
+ EcommerceCondition,
13
+ EcommerceConditionMap,
14
+ ExtendedEcommerceConditionMap,
15
+ EcommercePartnerConfiguration,
16
+ EcommerceSharedDefaults,
17
+ ExtendedEbayCategoryMap,
18
+ ExtendedInventoryTypeListingDefaults,
19
+ InventoryType,
20
+ InventoryTypeCategory,
21
+ InventoryTypeListingDefaults,
22
+ NewInventoryTypeListingDefaults,
23
+ Store,
24
+ } from './utils.js'
25
+ import EcommerceConditionMapConfig from './EcommerceConditionMapConfiguration.svelte'
26
+ import EcommerceCategoryMapConfig from './EcommerceCategoryMapConfiguration.svelte'
27
+ import EcommerceStoreConfig from './EcommerceStoreConfiguration.svelte'
28
+ import EcommercePartTypeConfig from './EcommercePartTypeConfig.svelte'
29
+
30
+ import { translate as defaultTranslate } from '@isoftdata/utility-string'
31
+ const { t: translate } = getContext<i18n>('i18next') || { t: defaultTranslate }
32
+
33
+ interface Props {
34
+ ebayCategoryList: Array<EbayCategory>
35
+ ebayCategoryMapList: Array<ExtendedEbayCategoryMap>
36
+ ebayPolicyList: Array<EbayPolicy>
37
+ ebayLocationList: Array<EbayLocation>
38
+ ecommerceConditionList: Array<EcommerceCondition>
39
+ ecommerceConditionMappingList: Array<ExtendedEcommerceConditionMap>
40
+ inventoryConditionList: Array<string>
41
+ inventoryTypeCategoryList: Array<InventoryTypeCategory>
42
+ inventoryTypeList: Array<InventoryType>
43
+ inventoryTypeWithDefaultConfigList: Array<ExtendedInventoryTypeListingDefaults>
44
+ partnerConfigurationList: Array<EcommercePartnerConfiguration>
45
+ saveEcommerceCategoryMap?: ((categoryMappingRow: EbayCategoryMap) => Promise<void>) | undefined
46
+ saveEcommerceConditionMap?: ((config: EcommerceConditionMap) => Promise<void>) | undefined
47
+ saveEcommercePartnerConfig?: ((config: EcommercePartnerConfiguration) => Promise<void>) | undefined
48
+ saveEcommercePartTypeConfig?:
49
+ | ((config: InventoryTypeListingDefaults | NewInventoryTypeListingDefaults) => Promise<void>)
50
+ | undefined
51
+ storeList: Array<Store>
52
+ //
53
+ }
54
+
55
+ let {
56
+ ebayCategoryList = [],
57
+ ebayCategoryMapList = [],
58
+ ebayLocationList = [],
59
+ ebayPolicyList = [],
60
+ ecommerceConditionList = [],
61
+ ecommerceConditionMappingList = [],
62
+ inventoryConditionList = [],
63
+ inventoryTypeCategoryList = [],
64
+ inventoryTypeList = [],
65
+ inventoryTypeWithDefaultConfigList = [],
66
+ partnerConfigurationList = [],
67
+ saveEcommerceCategoryMap,
68
+ saveEcommerceConditionMap,
69
+ saveEcommercePartnerConfig,
70
+ saveEcommercePartTypeConfig,
71
+ storeList = [],
72
+ }: Props = $props()
73
+ // Hard coding this for now, should be selectable between htp and ebay....maybe just default to the only one?
74
+ let selectedEcommercePartnerId = $derived.by(getEcommercePartnerId)
75
+
76
+ let globalDefaults = $derived.by(getGlobalDefaults)
77
+
78
+ function getEcommercePartnerId() {
79
+ const matchingPartnerConfig = partnerConfigurationList.find(row => row.name === 'ebay')
80
+ return matchingPartnerConfig ? matchingPartnerConfig.ecommercePartnerId : 1
81
+ }
82
+
83
+ function getGlobalDefaults() {
84
+ const matchingPartnerConfig = partnerConfigurationList.find(
85
+ row => row.ecommercePartnerId === selectedEcommercePartnerId,
86
+ )
87
+ if (matchingPartnerConfig) {
88
+ return matchingPartnerConfig.defaults?.global
89
+ }
90
+ }
91
+
92
+ // Handles global defaults being changed
93
+ async function handleGlobalConfigChange() {
94
+ // Find the matching partner config to update the global defaults on
95
+ const matchingPartnerConfig = partnerConfigurationList.find(
96
+ row => row.ecommercePartnerId === selectedEcommercePartnerId,
97
+ )
98
+
99
+ if (!matchingPartnerConfig) {
100
+ console.error('No matching partner configuration found for ID:', selectedEcommercePartnerId)
101
+ return
102
+ }
103
+
104
+ // Initialize defaults if it doesn't exist
105
+ if (!matchingPartnerConfig.defaults) {
106
+ matchingPartnerConfig.defaults = {
107
+ global: {},
108
+ store: [],
109
+ }
110
+ }
111
+
112
+ // Update the global defaults with the new values (globalDefaults is already updated via binding)
113
+ if (globalDefaults) {
114
+ matchingPartnerConfig.defaults.global = { ...globalDefaults }
115
+ }
116
+
117
+ await saveEcommercePartnerConfig?.(matchingPartnerConfig)
118
+ }
119
+
120
+ async function handleStoreConfigChange(updatedPartnerConfig: EcommercePartnerConfiguration) {
121
+ await saveEcommercePartnerConfig?.(updatedPartnerConfig)
122
+ }
123
+
124
+ async function handleCategoryMapChange(categoryMappingRow: EbayCategoryMap) {
125
+ await saveEcommerceCategoryMap?.(categoryMappingRow)
126
+ }
127
+ async function handleConditionMapChange(conditionMapRow: EcommerceConditionMap) {
128
+ await saveEcommerceConditionMap?.(conditionMapRow)
129
+ }
130
+
131
+ async function handlePartTypeConfigurationChange(
132
+ partTypeConfigRow: InventoryTypeListingDefaults | NewInventoryTypeListingDefaults,
133
+ ) {
134
+ await saveEcommercePartTypeConfig?.(partTypeConfigRow)
135
+ }
136
+ </script>
137
+
138
+ <div class="row mb-3">
139
+ <div class="col">
140
+ <div class="card">
141
+ <div class="card-header">
142
+ <h4 class="mb-0">{translate('ecommerce.configuration.globalDefaults', 'Global Defaults')}</h4>
143
+ <p class="text-muted mb-0">
144
+ {translate('ecommerce.configuration.configureGlobalDefaultsForEbay', 'Configure global defaults for eBay')}
145
+ </p>
146
+ </div>
147
+ <div class="card-body">
148
+ <EcommerceDefaults
149
+ bind:defaults={globalDefaults}
150
+ {ebayPolicyList}
151
+ {ecommerceConditionList}
152
+ {partnerConfigurationList}
153
+ defaultsChanged={handleGlobalConfigChange}
154
+ {selectedEcommercePartnerId}
155
+ />
156
+ </div>
157
+ </div>
158
+ </div>
159
+ <div class="col">
160
+ <EcommerceStoreConfig
161
+ {ecommerceConditionList}
162
+ {ebayLocationList}
163
+ {ebayPolicyList}
164
+ partnerConfigurationChanged={handleStoreConfigChange}
165
+ {partnerConfigurationList}
166
+ {selectedEcommercePartnerId}
167
+ {storeList}
168
+ />
169
+ </div>
170
+ </div>
171
+ <div class="row mb-3">
172
+ <div class="col">
173
+ <EcommerceConditionMapConfig
174
+ {ecommerceConditionList}
175
+ {inventoryConditionList}
176
+ {ecommerceConditionMappingList}
177
+ conditionMapChanged={handleConditionMapChange}
178
+ />
179
+ </div>
180
+ </div>
181
+ <div class="row mb-3">
182
+ <div class="col">
183
+ <EcommerceCategoryMapConfig
184
+ {ebayCategoryList}
185
+ {ebayCategoryMapList}
186
+ {inventoryTypeList}
187
+ categoryMapChanged={handleCategoryMapChange}
188
+ />
189
+ </div>
190
+ </div>
191
+ <div class="row mb-3">
192
+ <div class="col">
193
+ <EcommercePartTypeConfig
194
+ {ebayPolicyList}
195
+ {ecommerceConditionList}
196
+ {inventoryTypeList}
197
+ {inventoryTypeWithDefaultConfigList}
198
+ {inventoryTypeCategoryList}
199
+ {partnerConfigurationList}
200
+ partTypeConfigurationChanged={handlePartTypeConfigurationChange}
201
+ {selectedEcommercePartnerId}
202
+ />
203
+ </div>
204
+ </div>