@aglyn/plugins-commerce 1.29.1 → 1.29.2
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.
- package/package.json +13 -13
- package/src/lib/components/console/checkout-tax-blocked-notice.component.d.ts +18 -0
- package/src/lib/components/console/checkout-tax-blocked-notice.component.js +67 -0
- package/src/lib/components/console/checkout-tax-blocked-notice.component.js.map +1 -0
- package/src/lib/components/console/payments-settings-card.component.d.ts +2 -2
- package/src/lib/components/console/payments-settings-card.component.js +99 -5
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +14 -3
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/stripe-tax-readiness.component.d.ts +45 -0
- package/src/lib/components/console/stripe-tax-readiness.component.js +276 -0
- package/src/lib/components/console/stripe-tax-readiness.component.js.map +1 -0
- package/src/lib/components/console/tax-settings-card.component.js +22 -8
- package/src/lib/components/console/tax-settings-card.component.js.map +1 -1
- package/src/lib/constants/operator-alerts.d.ts +9 -0
- package/src/lib/constants/operator-alerts.js +22 -1
- package/src/lib/constants/operator-alerts.js.map +1 -1
- package/src/lib/declarations.server.js +11 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/commerce-tax-readiness.d.ts +79 -0
- package/src/lib/model/commerce-tax-readiness.js +99 -0
- package/src/lib/model/commerce-tax-readiness.js.map +1 -0
- package/src/lib/model/commerce.d.ts +7 -0
- package/src/lib/model/commerce.js +17 -4
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/payments-setup-status.d.ts +68 -0
- package/src/lib/model/payments-setup-status.js +103 -0
- package/src/lib/model/payments-setup-status.js.map +1 -0
- package/src/lib/plan-entitlements.d.ts +2 -1
- package/src/lib/plan-entitlements.js +2 -1
- package/src/lib/plan-entitlements.js.map +1 -1
- package/src/lib/server/cart-checkout.js +3 -0
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/checkout-tax-refusal.d.ts +51 -0
- package/src/lib/server/checkout-tax-refusal.js +133 -0
- package/src/lib/server/checkout-tax-refusal.js.map +1 -0
- package/src/lib/server/checkout.d.ts +2 -1
- package/src/lib/server/checkout.js +7 -2
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/connect-prefill.d.ts +65 -0
- package/src/lib/server/connect-prefill.js +85 -0
- package/src/lib/server/connect-prefill.js.map +1 -0
- package/src/lib/server/connect.d.ts +4 -2
- package/src/lib/server/connect.js +117 -37
- package/src/lib/server/connect.js.map +1 -1
- package/src/lib/server/draft-order.js +4 -2
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/pos-order.js +1 -1
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/product-writer.d.ts +27 -0
- package/src/lib/server/product-writer.js +174 -4
- package/src/lib/server/product-writer.js.map +1 -1
- package/src/lib/server/quote-pay.d.ts +6 -0
- package/src/lib/server/quote-pay.js +8 -2
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/seller-stripe-account.d.ts +19 -0
- package/src/lib/server/seller-stripe-account.js +40 -4
- package/src/lib/server/seller-stripe-account.js.map +1 -1
- package/src/lib/server/site-page-resolver.d.ts +1 -6
- package/src/lib/server/site-page-resolver.js +4 -12
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server/site-search.d.ts +43 -0
- package/src/lib/server/site-search.js +124 -0
- package/src/lib/server/site-search.js.map +1 -0
- package/src/lib/server/tax-readiness.d.ts +56 -0
- package/src/lib/server/tax-readiness.js +169 -0
- package/src/lib/server/tax-readiness.js.map +1 -0
- package/src/lib/server.js +6 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/transfer/product-image-copy.server.d.ts +77 -0
- package/src/lib/transfer/product-image-copy.server.js +307 -0
- package/src/lib/transfer/product-image-copy.server.js.map +1 -0
- package/src/lib/transfer/product-images.d.ts +62 -0
- package/src/lib/transfer/product-images.js +143 -0
- package/src/lib/transfer/product-images.js.map +1 -0
- package/src/lib/transfer/product-sources.d.ts +92 -0
- package/src/lib/transfer/product-sources.js +519 -0
- package/src/lib/transfer/product-sources.js.map +1 -0
- package/src/lib/transfer/product-transfer.d.ts +26 -1
- package/src/lib/transfer/product-transfer.js +283 -11
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.d.ts +29 -3
- package/src/lib/transfer/products.server.js +289 -13
- package/src/lib/transfer/products.server.js.map +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { TransferAliasDictionary, TransferPlanRow } from '@aglyn/aglyn/data-transfer';
|
|
18
|
+
/** The field ids this module reads and writes; the same ids as `PRODUCT_FIELD`. */
|
|
19
|
+
export declare const SOURCE_FIELD: {
|
|
20
|
+
readonly handle: "handle";
|
|
21
|
+
readonly title: "title";
|
|
22
|
+
readonly description: "description";
|
|
23
|
+
readonly kind: "type";
|
|
24
|
+
readonly published: "published";
|
|
25
|
+
readonly tags: "tags";
|
|
26
|
+
readonly categories: "categories";
|
|
27
|
+
readonly option1Name: "option1Name";
|
|
28
|
+
readonly option2Name: "option2Name";
|
|
29
|
+
readonly option3Name: "option3Name";
|
|
30
|
+
readonly option1Value: "option1Value";
|
|
31
|
+
readonly option2Value: "option2Value";
|
|
32
|
+
readonly option3Value: "option3Value";
|
|
33
|
+
readonly sku: "sku";
|
|
34
|
+
readonly barcode: "barcode";
|
|
35
|
+
readonly price: "price";
|
|
36
|
+
readonly compareAtPrice: "compareAtPrice";
|
|
37
|
+
readonly inventory: "inventory";
|
|
38
|
+
readonly weightGrams: "weightGrams";
|
|
39
|
+
readonly variantImage: "variantImage";
|
|
40
|
+
readonly variantCheckIn: "variantCheckIn";
|
|
41
|
+
readonly images: "images";
|
|
42
|
+
readonly sourceProductId: "sourceProductId";
|
|
43
|
+
readonly rowType: "rowType";
|
|
44
|
+
readonly priceSurcharge: "priceSurcharge";
|
|
45
|
+
readonly discountType: "discountType";
|
|
46
|
+
readonly discountAmount: "discountAmount";
|
|
47
|
+
readonly salePrice: "salePrice";
|
|
48
|
+
readonly onSale: "onSale";
|
|
49
|
+
readonly sourceType: "sourceType";
|
|
50
|
+
};
|
|
51
|
+
/** The fields that exist only to read another store's file; never stored, blank on export. */
|
|
52
|
+
export declare const SOURCE_ONLY_FIELDS: readonly string[];
|
|
53
|
+
/** Where a row's group key is kept once the file's own grouping is read. */
|
|
54
|
+
export declare const SOURCE_GROUP_KEY = "$group";
|
|
55
|
+
/** Where a row that is not brought in keeps why. */
|
|
56
|
+
export declare const SOURCE_SKIP_KEY = "$skip";
|
|
57
|
+
/** Wix Stores' product CSV columns, by the field each one means. */
|
|
58
|
+
export declare const WIX_PRODUCT_COLUMNS: Readonly<Record<string, readonly string[]>>;
|
|
59
|
+
/** Squarespace's product CSV columns, by the field each one means. */
|
|
60
|
+
export declare const SQUARESPACE_PRODUCT_COLUMNS: Readonly<Record<string, readonly string[]>>;
|
|
61
|
+
/** The two dictionaries, beside Shopify's. */
|
|
62
|
+
export declare const SOURCE_ALIAS_DICTIONARIES: readonly TransferAliasDictionary[];
|
|
63
|
+
/** Which other store's file this is. */
|
|
64
|
+
export type ProductFileSource = 'wix' | 'squarespace';
|
|
65
|
+
/**
|
|
66
|
+
* The store a file came from, by its header signature: Wix's `handleId` and
|
|
67
|
+
* `fieldType` beside its image or option columns; Squarespace's two
|
|
68
|
+
* `[Non Editable]` ids or its hosted images. `null` for any other file,
|
|
69
|
+
* Shopify's included. With no headers (a JSON file), by the columns read.
|
|
70
|
+
*/
|
|
71
|
+
export declare function productFileSource(headers: readonly string[] | undefined, rows?: readonly TransferPlanRow[]): ProductFileSource | null;
|
|
72
|
+
/** Something the dry run says about how another store's file was read. */
|
|
73
|
+
export interface SourceNote {
|
|
74
|
+
/** The row; `-1` for the whole file. */
|
|
75
|
+
row: number;
|
|
76
|
+
fieldId?: string;
|
|
77
|
+
value?: string;
|
|
78
|
+
detail: string;
|
|
79
|
+
}
|
|
80
|
+
/** A Wix choice as it is shown: `#ff0000:Red` is Red. */
|
|
81
|
+
export declare function wixChoiceName(value: unknown): string;
|
|
82
|
+
/**
|
|
83
|
+
* The rows read into the layout the products plan reads. For another
|
|
84
|
+
* store's file: each row's group under {@link SOURCE_GROUP_KEY}, prices
|
|
85
|
+
* settled, stock words read, a row not brought in marked under
|
|
86
|
+
* {@link SOURCE_SKIP_KEY}. For any file: a sale price settled, and the
|
|
87
|
+
* source-only fields gone. What was changed or left out is in `notes`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function adaptProductSourceRows(rows: readonly TransferPlanRow[], source: ProductFileSource | null): {
|
|
90
|
+
rows: TransferPlanRow[];
|
|
91
|
+
notes: SourceNote[];
|
|
92
|
+
};
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
17
|
+
/*==========================================
|
|
18
|
+
* WIX AND SQUARESPACE PRODUCT FILES (AGL-4245).
|
|
19
|
+
*
|
|
20
|
+
* A Shopify product CSV is laid out the way an Aglyn one is (a row per
|
|
21
|
+
* variant, the product's fields on its first row, a handle on every row), so
|
|
22
|
+
* its columns only need names (`SHOPIFY_PRODUCT_COLUMNS`). A Wix or
|
|
23
|
+
* Squarespace export is recognized the same way, by an alias dictionary of
|
|
24
|
+
* its own column names, so the Columns step maps it with nothing to pick.
|
|
25
|
+
* What the two files MEAN differs from that layout, and is read here before
|
|
26
|
+
* the plan, by the file's header signature:
|
|
27
|
+
*
|
|
28
|
+
* - **Wix Stores** (the catalog export): rows of `fieldType` `Product` carry
|
|
29
|
+
* the product, its option names and each option's choices; `Variant` rows
|
|
30
|
+
* sharing the `handleId` carry each variant's choice, SKU, stock and a
|
|
31
|
+
* `surcharge` on the product's price. A colour choice may read `#hex:Name`,
|
|
32
|
+
* and is kept as its name. `inventory` is a number, or `InStock` (not
|
|
33
|
+
* counted) or `OutOfStock` (none). A `PERCENT` or `AMOUNT` discount makes
|
|
34
|
+
* the discounted price the price and the full one the compare-at price.
|
|
35
|
+
* `handleId` is an id, not an address, so a product's handle is made from
|
|
36
|
+
* its name.
|
|
37
|
+
* - **Squarespace Commerce**: a row per variant, the product's title and
|
|
38
|
+
* description on its first row only. Rows are grouped by
|
|
39
|
+
* `Product ID [Non Editable]`, or, without one, a row with no handle and no
|
|
40
|
+
* title belongs to the product above it. `Product URL` is the old address,
|
|
41
|
+
* kept as the handle. `Stock` may be `Unlimited` (not counted). `On Sale`
|
|
42
|
+
* with a `Sale Price` makes the sale price the price and `Price` the
|
|
43
|
+
* compare-at price. `Product Type` maps to Physical, Digital or Service, and
|
|
44
|
+
* a gift card is not a product: its rows are skipped with a note.
|
|
45
|
+
* - **Both**: a photo cell lists several (Wix by `;`, Squarespace by
|
|
46
|
+
* spaces), read into **Images**. A weight is dropped with a note, because
|
|
47
|
+
* neither file says whether it is in pounds or kilograms.
|
|
48
|
+
*
|
|
49
|
+
* Unknown and missing columns are never a failure: a column no field claims
|
|
50
|
+
* is left unmapped, and a field no column fills is left as it is.
|
|
51
|
+
*=========================================*/ /** The field ids this module reads and writes; the same ids as `PRODUCT_FIELD`. */ export const SOURCE_FIELD = {
|
|
52
|
+
handle: 'handle',
|
|
53
|
+
title: 'title',
|
|
54
|
+
description: 'description',
|
|
55
|
+
kind: 'type',
|
|
56
|
+
published: 'published',
|
|
57
|
+
tags: 'tags',
|
|
58
|
+
categories: 'categories',
|
|
59
|
+
option1Name: 'option1Name',
|
|
60
|
+
option2Name: 'option2Name',
|
|
61
|
+
option3Name: 'option3Name',
|
|
62
|
+
option1Value: 'option1Value',
|
|
63
|
+
option2Value: 'option2Value',
|
|
64
|
+
option3Value: 'option3Value',
|
|
65
|
+
sku: 'sku',
|
|
66
|
+
barcode: 'barcode',
|
|
67
|
+
price: 'price',
|
|
68
|
+
compareAtPrice: 'compareAtPrice',
|
|
69
|
+
inventory: 'inventory',
|
|
70
|
+
weightGrams: 'weightGrams',
|
|
71
|
+
variantImage: 'variantImage',
|
|
72
|
+
variantCheckIn: 'variantCheckIn',
|
|
73
|
+
images: 'images',
|
|
74
|
+
sourceProductId: 'sourceProductId',
|
|
75
|
+
rowType: 'rowType',
|
|
76
|
+
priceSurcharge: 'priceSurcharge',
|
|
77
|
+
discountType: 'discountType',
|
|
78
|
+
discountAmount: 'discountAmount',
|
|
79
|
+
salePrice: 'salePrice',
|
|
80
|
+
onSale: 'onSale',
|
|
81
|
+
sourceType: 'sourceType'
|
|
82
|
+
};
|
|
83
|
+
const S = SOURCE_FIELD;
|
|
84
|
+
/** The fields that exist only to read another store's file; never stored, blank on export. */ export const SOURCE_ONLY_FIELDS = [
|
|
85
|
+
S.sourceProductId,
|
|
86
|
+
S.rowType,
|
|
87
|
+
S.priceSurcharge,
|
|
88
|
+
S.discountType,
|
|
89
|
+
S.discountAmount,
|
|
90
|
+
S.salePrice,
|
|
91
|
+
S.onSale,
|
|
92
|
+
S.sourceType
|
|
93
|
+
];
|
|
94
|
+
/** Where a row's group key is kept once the file's own grouping is read. */ export const SOURCE_GROUP_KEY = '$group';
|
|
95
|
+
/** Where a row that is not brought in keeps why. */ export const SOURCE_SKIP_KEY = '$skip';
|
|
96
|
+
/** Wix Stores' product CSV columns, by the field each one means. */ export const WIX_PRODUCT_COLUMNS = {
|
|
97
|
+
[S.sourceProductId]: [
|
|
98
|
+
'handleId'
|
|
99
|
+
],
|
|
100
|
+
[S.rowType]: [
|
|
101
|
+
'fieldType'
|
|
102
|
+
],
|
|
103
|
+
[S.title]: [
|
|
104
|
+
'name'
|
|
105
|
+
],
|
|
106
|
+
[S.description]: [
|
|
107
|
+
'description'
|
|
108
|
+
],
|
|
109
|
+
[S.images]: [
|
|
110
|
+
'productImageUrl'
|
|
111
|
+
],
|
|
112
|
+
[S.categories]: [
|
|
113
|
+
'collection'
|
|
114
|
+
],
|
|
115
|
+
[S.sku]: [
|
|
116
|
+
'sku'
|
|
117
|
+
],
|
|
118
|
+
[S.price]: [
|
|
119
|
+
'price'
|
|
120
|
+
],
|
|
121
|
+
[S.priceSurcharge]: [
|
|
122
|
+
'surcharge'
|
|
123
|
+
],
|
|
124
|
+
[S.published]: [
|
|
125
|
+
'visible'
|
|
126
|
+
],
|
|
127
|
+
[S.discountType]: [
|
|
128
|
+
'discountMode'
|
|
129
|
+
],
|
|
130
|
+
[S.discountAmount]: [
|
|
131
|
+
'discountValue'
|
|
132
|
+
],
|
|
133
|
+
[S.inventory]: [
|
|
134
|
+
'inventory'
|
|
135
|
+
],
|
|
136
|
+
[S.weightGrams]: [
|
|
137
|
+
'weight'
|
|
138
|
+
],
|
|
139
|
+
[S.option1Name]: [
|
|
140
|
+
'productOptionName1'
|
|
141
|
+
],
|
|
142
|
+
[S.option2Name]: [
|
|
143
|
+
'productOptionName2'
|
|
144
|
+
],
|
|
145
|
+
[S.option3Name]: [
|
|
146
|
+
'productOptionName3'
|
|
147
|
+
],
|
|
148
|
+
[S.option1Value]: [
|
|
149
|
+
'productOptionDescription1'
|
|
150
|
+
],
|
|
151
|
+
[S.option2Value]: [
|
|
152
|
+
'productOptionDescription2'
|
|
153
|
+
],
|
|
154
|
+
[S.option3Value]: [
|
|
155
|
+
'productOptionDescription3'
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
/** Squarespace's product CSV columns, by the field each one means. */ export const SQUARESPACE_PRODUCT_COLUMNS = {
|
|
159
|
+
[S.sourceProductId]: [
|
|
160
|
+
'Product ID [Non Editable]'
|
|
161
|
+
],
|
|
162
|
+
[S.sourceType]: [
|
|
163
|
+
'Product Type [Non Editable]'
|
|
164
|
+
],
|
|
165
|
+
[S.handle]: [
|
|
166
|
+
'Product URL'
|
|
167
|
+
],
|
|
168
|
+
[S.title]: [
|
|
169
|
+
'Title'
|
|
170
|
+
],
|
|
171
|
+
[S.description]: [
|
|
172
|
+
'Description'
|
|
173
|
+
],
|
|
174
|
+
[S.sku]: [
|
|
175
|
+
'SKU'
|
|
176
|
+
],
|
|
177
|
+
[S.option1Name]: [
|
|
178
|
+
'Option Name 1'
|
|
179
|
+
],
|
|
180
|
+
[S.option1Value]: [
|
|
181
|
+
'Option Value 1'
|
|
182
|
+
],
|
|
183
|
+
[S.option2Name]: [
|
|
184
|
+
'Option Name 2'
|
|
185
|
+
],
|
|
186
|
+
[S.option2Value]: [
|
|
187
|
+
'Option Value 2'
|
|
188
|
+
],
|
|
189
|
+
[S.option3Name]: [
|
|
190
|
+
'Option Name 3'
|
|
191
|
+
],
|
|
192
|
+
[S.option3Value]: [
|
|
193
|
+
'Option Value 3'
|
|
194
|
+
],
|
|
195
|
+
[S.price]: [
|
|
196
|
+
'Price'
|
|
197
|
+
],
|
|
198
|
+
[S.salePrice]: [
|
|
199
|
+
'Sale Price'
|
|
200
|
+
],
|
|
201
|
+
[S.onSale]: [
|
|
202
|
+
'On Sale'
|
|
203
|
+
],
|
|
204
|
+
[S.inventory]: [
|
|
205
|
+
'Stock'
|
|
206
|
+
],
|
|
207
|
+
[S.categories]: [
|
|
208
|
+
'Categories'
|
|
209
|
+
],
|
|
210
|
+
[S.tags]: [
|
|
211
|
+
'Tags'
|
|
212
|
+
],
|
|
213
|
+
[S.weightGrams]: [
|
|
214
|
+
'Weight'
|
|
215
|
+
],
|
|
216
|
+
[S.published]: [
|
|
217
|
+
'Visible'
|
|
218
|
+
],
|
|
219
|
+
[S.images]: [
|
|
220
|
+
'Hosted Image URLs'
|
|
221
|
+
]
|
|
222
|
+
};
|
|
223
|
+
/** The two dictionaries, beside Shopify's. */ export const SOURCE_ALIAS_DICTIONARIES = [
|
|
224
|
+
{
|
|
225
|
+
source: 'Wix',
|
|
226
|
+
aliases: WIX_PRODUCT_COLUMNS
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
source: 'Squarespace',
|
|
230
|
+
aliases: SQUARESPACE_PRODUCT_COLUMNS
|
|
231
|
+
}
|
|
232
|
+
];
|
|
233
|
+
const compact = (header)=>String(header != null ? header : '').toLowerCase().replace(/[^a-z0-9]+/g, '');
|
|
234
|
+
/**
|
|
235
|
+
* The store a file came from, by its header signature: Wix's `handleId` and
|
|
236
|
+
* `fieldType` beside its image or option columns; Squarespace's two
|
|
237
|
+
* `[Non Editable]` ids or its hosted images. `null` for any other file,
|
|
238
|
+
* Shopify's included. With no headers (a JSON file), by the columns read.
|
|
239
|
+
*/ export function productFileSource(headers, rows = []) {
|
|
240
|
+
if (headers == null ? void 0 : headers.length) {
|
|
241
|
+
const have = new Set(headers.map(compact));
|
|
242
|
+
if (have.has('handleid') && have.has('fieldtype') && (have.has('productimageurl') || have.has('productoptionname1'))) {
|
|
243
|
+
return 'wix';
|
|
244
|
+
}
|
|
245
|
+
if (have.has('productidnoneditable') && (have.has('variantidnoneditable') || have.has('hostedimageurls'))) {
|
|
246
|
+
return 'squarespace';
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
const mapped = (fieldId)=>rows.some((row)=>fieldId in row.values);
|
|
251
|
+
if (mapped(S.rowType) && mapped(S.sourceProductId)) return 'wix';
|
|
252
|
+
if (mapped(S.sourceType) || mapped(S.onSale) || mapped(S.salePrice)) return 'squarespace';
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
const text = (value)=>value === null || value === undefined ? '' : String(value).trim();
|
|
256
|
+
/** A money cell as a number of dollars; `null` for blank, unreadable or not in US dollars. */ function amountOf(value) {
|
|
257
|
+
if (value === null || value === undefined || value === '') return null;
|
|
258
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : null;
|
|
259
|
+
if (typeof value === 'object' && 'amountMinor' in value) {
|
|
260
|
+
const amount = value;
|
|
261
|
+
return String(amount.currency).toUpperCase() === 'USD' ? Math.round(Number(amount.amountMinor)) / 100 : null;
|
|
262
|
+
}
|
|
263
|
+
const number = Number(String(value).replace(/[$,\s]/g, ''));
|
|
264
|
+
return Number.isFinite(number) ? number : null;
|
|
265
|
+
}
|
|
266
|
+
const cents = (value)=>Math.round(value * 100) / 100;
|
|
267
|
+
const VARIANT_FIELDS = [
|
|
268
|
+
S.option1Value,
|
|
269
|
+
S.option2Value,
|
|
270
|
+
S.option3Value,
|
|
271
|
+
S.sku,
|
|
272
|
+
S.barcode,
|
|
273
|
+
S.price,
|
|
274
|
+
S.compareAtPrice,
|
|
275
|
+
S.inventory,
|
|
276
|
+
S.weightGrams,
|
|
277
|
+
S.variantImage,
|
|
278
|
+
S.variantCheckIn
|
|
279
|
+
];
|
|
280
|
+
const OPTION_NAMES = [
|
|
281
|
+
S.option1Name,
|
|
282
|
+
S.option2Name,
|
|
283
|
+
S.option3Name
|
|
284
|
+
];
|
|
285
|
+
const OPTION_VALUES = [
|
|
286
|
+
S.option1Value,
|
|
287
|
+
S.option2Value,
|
|
288
|
+
S.option3Value
|
|
289
|
+
];
|
|
290
|
+
/** A Wix choice as it is shown: `#ff0000:Red` is Red. */ export function wixChoiceName(value) {
|
|
291
|
+
return text(value).replace(/^#[0-9a-f]{3,8}\s*:\s*/i, '').trim();
|
|
292
|
+
}
|
|
293
|
+
/** A Wix option's choices, from the product row's comma list. */ function wixChoices(value) {
|
|
294
|
+
return text(value).split(',').map(wixChoiceName).filter(Boolean);
|
|
295
|
+
}
|
|
296
|
+
function draftOf(row) {
|
|
297
|
+
var _row_problems;
|
|
298
|
+
return {
|
|
299
|
+
index: row.index,
|
|
300
|
+
values: _extends({}, row.values),
|
|
301
|
+
problems: [
|
|
302
|
+
...(_row_problems = row.problems) != null ? _row_problems : []
|
|
303
|
+
],
|
|
304
|
+
source: row
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function rowOf(draft) {
|
|
308
|
+
const rest = _extends({}, draft.source);
|
|
309
|
+
delete rest.problems;
|
|
310
|
+
return _extends({}, rest, {
|
|
311
|
+
values: draft.values
|
|
312
|
+
}, draft.problems.length ? {
|
|
313
|
+
problems: draft.problems
|
|
314
|
+
} : {});
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* A stock cell a number could not read, as the other store wrote it:
|
|
318
|
+
* `InStock` and `Unlimited` are stock that is not counted, `OutOfStock` none.
|
|
319
|
+
*/ function readStockWords(draft) {
|
|
320
|
+
var _draft_problems_at;
|
|
321
|
+
const at = draft.problems.findIndex((problem)=>problem.fieldId === S.inventory);
|
|
322
|
+
if (at < 0) return;
|
|
323
|
+
const raw = text((_draft_problems_at = draft.problems[at]) == null ? void 0 : _draft_problems_at.raw).toLowerCase().replace(/[\s_-]+/g, '');
|
|
324
|
+
if (raw === 'instock' || raw === 'unlimited') {
|
|
325
|
+
draft.problems.splice(at, 1);
|
|
326
|
+
delete draft.values[S.inventory];
|
|
327
|
+
} else if (raw === 'outofstock') {
|
|
328
|
+
draft.problems.splice(at, 1);
|
|
329
|
+
draft.values[S.inventory] = 0;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/** The price a row ends with once a sale or discount is read: the sale price, the full one as compare-at. */ function applySale(draft, full, sale) {
|
|
333
|
+
if (full === null) return;
|
|
334
|
+
if (sale !== null && sale > 0 && sale < full) {
|
|
335
|
+
draft.values[S.price] = cents(sale);
|
|
336
|
+
if (text(draft.values[S.compareAtPrice]) === '') draft.values[S.compareAtPrice] = cents(full);
|
|
337
|
+
} else {
|
|
338
|
+
draft.values[S.price] = cents(full);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function wixDiscounted(full, mode, amount) {
|
|
342
|
+
if (full === null || amount === null || amount <= 0) return null;
|
|
343
|
+
if (mode === 'percent') return amount < 100 ? full * (1 - amount / 100) : null;
|
|
344
|
+
if (mode === 'amount') return amount < full ? full - amount : null;
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
function dropWeights(drafts, source, notes) {
|
|
348
|
+
let dropped = false;
|
|
349
|
+
for (const draft of drafts){
|
|
350
|
+
if (text(draft.values[S.weightGrams]) !== '') dropped = true;
|
|
351
|
+
delete draft.values[S.weightGrams];
|
|
352
|
+
draft.problems = draft.problems.filter((problem)=>problem.fieldId !== S.weightGrams);
|
|
353
|
+
}
|
|
354
|
+
if (dropped) {
|
|
355
|
+
notes.push({
|
|
356
|
+
row: -1,
|
|
357
|
+
fieldId: S.weightGrams,
|
|
358
|
+
detail: `Weights are not brought in, because a ${source === 'wix' ? 'Wix' : 'Squarespace'} file does not say whether they are in pounds or kilograms. Set each product's weight on the product.`
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function clearSourceFields(draft) {
|
|
363
|
+
for (const fieldId of SOURCE_ONLY_FIELDS)delete draft.values[fieldId];
|
|
364
|
+
}
|
|
365
|
+
function adaptWix(drafts, notes) {
|
|
366
|
+
const groups = new Map();
|
|
367
|
+
drafts.forEach((draft, position)=>{
|
|
368
|
+
var _groups_get;
|
|
369
|
+
const id = text(draft.values[S.sourceProductId]);
|
|
370
|
+
const key = id ? `w:${id}` : `r:${position}`;
|
|
371
|
+
draft.values[SOURCE_GROUP_KEY] = key;
|
|
372
|
+
groups.set(key, [
|
|
373
|
+
...(_groups_get = groups.get(key)) != null ? _groups_get : [],
|
|
374
|
+
draft
|
|
375
|
+
]);
|
|
376
|
+
});
|
|
377
|
+
for (const group of groups.values()){
|
|
378
|
+
var _group_find;
|
|
379
|
+
const kind = (draft)=>text(draft.values[S.rowType]).toLowerCase();
|
|
380
|
+
const product = (_group_find = group.find((draft)=>kind(draft) === 'product')) != null ? _group_find : group[0];
|
|
381
|
+
const variants = group.filter((draft)=>draft !== product && kind(draft) === 'variant');
|
|
382
|
+
const base = amountOf(product.values[S.price]);
|
|
383
|
+
const mode = text(product.values[S.discountType]).toLowerCase();
|
|
384
|
+
const discount = amountOf(product.values[S.discountAmount]);
|
|
385
|
+
const priced = (draft, full)=>applySale(draft, full, wixDiscounted(full, mode, discount));
|
|
386
|
+
if (variants.length) {
|
|
387
|
+
// The product row holds the product; its own SKU, price and choice lists are not a variant.
|
|
388
|
+
for (const fieldId of VARIANT_FIELDS)delete product.values[fieldId];
|
|
389
|
+
product.problems = product.problems.filter((problem)=>!VARIANT_FIELDS.includes(problem.fieldId));
|
|
390
|
+
for (const variant of variants){
|
|
391
|
+
var _amountOf;
|
|
392
|
+
OPTION_VALUES.forEach((fieldId)=>{
|
|
393
|
+
if (text(variant.values[fieldId])) variant.values[fieldId] = wixChoiceName(variant.values[fieldId]);
|
|
394
|
+
});
|
|
395
|
+
const own = amountOf(variant.values[S.price]);
|
|
396
|
+
const surcharge = (_amountOf = amountOf(variant.values[S.priceSurcharge])) != null ? _amountOf : 0;
|
|
397
|
+
priced(variant, own != null ? own : base === null ? null : base + surcharge);
|
|
398
|
+
readStockWords(variant);
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
// A product with no variant rows is one variant; a choice list cannot be one.
|
|
402
|
+
const lists = OPTION_VALUES.map((fieldId)=>wixChoices(product.values[fieldId]));
|
|
403
|
+
if (lists.some((choices)=>choices.length > 1)) {
|
|
404
|
+
const named = OPTION_NAMES.map((fieldId, axis)=>{
|
|
405
|
+
var _lists_axis, _lists_axis1;
|
|
406
|
+
return text(product.values[fieldId]) && ((_lists_axis = lists[axis]) == null ? void 0 : _lists_axis.length) ? `${text(product.values[fieldId])}: ${(_lists_axis1 = lists[axis]) == null ? void 0 : _lists_axis1.join(', ')}` : '';
|
|
407
|
+
}).filter(Boolean);
|
|
408
|
+
notes.push({
|
|
409
|
+
row: product.index,
|
|
410
|
+
fieldId: S.option1Value,
|
|
411
|
+
value: named.join('; '),
|
|
412
|
+
detail: "This product's choices have no variant rows in the file, so it is brought in as one variant. Add its choices on the product."
|
|
413
|
+
});
|
|
414
|
+
for (const fieldId of [
|
|
415
|
+
...OPTION_VALUES,
|
|
416
|
+
...OPTION_NAMES
|
|
417
|
+
])delete product.values[fieldId];
|
|
418
|
+
} else {
|
|
419
|
+
OPTION_VALUES.forEach((fieldId, axis)=>{
|
|
420
|
+
var _lists_axis, _lists_axis1;
|
|
421
|
+
if ((_lists_axis = lists[axis]) == null ? void 0 : _lists_axis.length) product.values[fieldId] = (_lists_axis1 = lists[axis]) == null ? void 0 : _lists_axis1[0];
|
|
422
|
+
else delete product.values[fieldId];
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
priced(product, base);
|
|
426
|
+
readStockWords(product);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/** A Squarespace `Product URL` is the last part of the old address. */ function squarespaceHandle(value) {
|
|
431
|
+
var _parts_;
|
|
432
|
+
const parts = text(value).split(/[/?#]/).filter(Boolean);
|
|
433
|
+
return (_parts_ = parts[parts.length - 1]) != null ? _parts_ : '';
|
|
434
|
+
}
|
|
435
|
+
const SQUARESPACE_KIND = {
|
|
436
|
+
physical: 'Physical',
|
|
437
|
+
digital: 'Digital',
|
|
438
|
+
service: 'Service'
|
|
439
|
+
};
|
|
440
|
+
function adaptSquarespace(drafts, notes) {
|
|
441
|
+
const groups = new Map();
|
|
442
|
+
let current = null;
|
|
443
|
+
drafts.forEach((draft, position)=>{
|
|
444
|
+
var _groups_get;
|
|
445
|
+
const id = text(draft.values[S.sourceProductId]);
|
|
446
|
+
if (text(draft.values[S.handle])) draft.values[S.handle] = squarespaceHandle(draft.values[S.handle]);
|
|
447
|
+
const handle = text(draft.values[S.handle]);
|
|
448
|
+
const key = id ? `s:${id}` : handle ? `h:${handle.toLowerCase()}` : text(draft.values[S.title]) ? `r:${position}` : current != null ? current : `r:${position}`;
|
|
449
|
+
current = key;
|
|
450
|
+
draft.values[SOURCE_GROUP_KEY] = key;
|
|
451
|
+
groups.set(key, [
|
|
452
|
+
...(_groups_get = groups.get(key)) != null ? _groups_get : [],
|
|
453
|
+
draft
|
|
454
|
+
]);
|
|
455
|
+
});
|
|
456
|
+
for (const group of groups.values()){
|
|
457
|
+
const type = text(group.map((draft)=>draft.values[S.sourceType]).find((value)=>text(value))).toLowerCase().replace(/[\s-]+/g, '_');
|
|
458
|
+
const first = group[0];
|
|
459
|
+
if (type === 'gift_card' || type === 'giftcard') {
|
|
460
|
+
for (const draft of group)draft.values[SOURCE_SKIP_KEY] = 'giftCard';
|
|
461
|
+
notes.push({
|
|
462
|
+
row: first.index,
|
|
463
|
+
value: text(first.values[S.title]) || undefined,
|
|
464
|
+
detail: 'A gift card is not a product, so its rows are skipped. Bring gift cards in with a gift card import.'
|
|
465
|
+
});
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
const kind = SQUARESPACE_KIND[type];
|
|
469
|
+
if (kind && text(first.values[S.kind]) === '') first.values[S.kind] = kind;
|
|
470
|
+
for (const draft of group){
|
|
471
|
+
const full = amountOf(draft.values[S.price]);
|
|
472
|
+
const sale = draft.values[S.onSale] === true ? amountOf(draft.values[S.salePrice]) : null;
|
|
473
|
+
if (full !== null) applySale(draft, full, sale);
|
|
474
|
+
readStockWords(draft);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* A sale price in any other file: below the price, it becomes the price and
|
|
480
|
+
* the price the compare-at price; with an On sale column, only when it says yes.
|
|
481
|
+
*/ function adaptSalePrices(drafts) {
|
|
482
|
+
const flagged = drafts.some((draft)=>S.onSale in draft.values);
|
|
483
|
+
for (const draft of drafts){
|
|
484
|
+
if (!(S.salePrice in draft.values)) continue;
|
|
485
|
+
if (flagged && draft.values[S.onSale] !== true) continue;
|
|
486
|
+
const full = amountOf(draft.values[S.price]);
|
|
487
|
+
const sale = amountOf(draft.values[S.salePrice]);
|
|
488
|
+
if (full !== null && sale !== null) applySale(draft, full, sale);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* The rows read into the layout the products plan reads. For another
|
|
493
|
+
* store's file: each row's group under {@link SOURCE_GROUP_KEY}, prices
|
|
494
|
+
* settled, stock words read, a row not brought in marked under
|
|
495
|
+
* {@link SOURCE_SKIP_KEY}. For any file: a sale price settled, and the
|
|
496
|
+
* source-only fields gone. What was changed or left out is in `notes`.
|
|
497
|
+
*/ export function adaptProductSourceRows(rows, source) {
|
|
498
|
+
const touched = rows.some((row)=>SOURCE_ONLY_FIELDS.some((fieldId)=>fieldId in row.values));
|
|
499
|
+
if (!source && !touched) return {
|
|
500
|
+
rows: [
|
|
501
|
+
...rows
|
|
502
|
+
],
|
|
503
|
+
notes: []
|
|
504
|
+
};
|
|
505
|
+
const drafts = rows.map(draftOf);
|
|
506
|
+
const notes = [];
|
|
507
|
+
// Before the rows are read, which clears a Wix product row's own variant cells.
|
|
508
|
+
if (source) dropWeights(drafts, source, notes);
|
|
509
|
+
if (source === 'wix') adaptWix(drafts, notes);
|
|
510
|
+
else if (source === 'squarespace') adaptSquarespace(drafts, notes);
|
|
511
|
+
else adaptSalePrices(drafts);
|
|
512
|
+
for (const draft of drafts)clearSourceFields(draft);
|
|
513
|
+
return {
|
|
514
|
+
rows: drafts.map(rowOf),
|
|
515
|
+
notes
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
//# sourceMappingURL=product-sources.js.map
|