@aglyn/plugins-crm 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.
@@ -0,0 +1,420 @@
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
+ * A STORE'S CUSTOMER FILE (AGL-4245).
19
+ *
20
+ * A store moving from Shopify, Wix or Squarespace brings its customers in
21
+ * through the contact import. Each platform's customer export is recognized
22
+ * by its own column names (the dictionaries below, read by the header
23
+ * matcher like Salesforce's), so the Columns step maps it with nothing to
24
+ * pick. Unknown and missing columns are never a failure.
25
+ *
26
+ * ## The marketing choice the file records
27
+ *
28
+ * Each file says whether a customer agreed to marketing email: Shopify's
29
+ * `Accepts Email Marketing` (`Accepts Marketing` in older files), Wix's
30
+ * `Email subscriber status`, Squarespace's `Accepts Marketing`. It is read
31
+ * into an import-only field and carried under three rules:
32
+ *
33
+ * - **An opt-in** becomes the contact's marketing consent for the import's
34
+ * site ONLY when the person importing states, on the Permission step, that
35
+ * these people agreed to hear from this business. Without that, nobody is
36
+ * opted in from the file. A contact who unsubscribed here (a refusal on
37
+ * record, or the site's unsubscribe list) is never opted back in.
38
+ * - **An opt-out** (`no`, `false`, `Unsubscribed`) is ALWAYS kept, whatever
39
+ * the step says: it is recorded as the contact's refusal, and a contact
40
+ * who was subscribed here is unsubscribed.
41
+ * - **No choice** (`Never subscribed`, `Pending`, blank, a word we cannot
42
+ * read) changes nothing.
43
+ *
44
+ * The plan carries each change as a `marketingConsent` row change stamped
45
+ * with who planned it and whether they confirmed, so the apply never takes
46
+ * either from the browser (`customer-consent-plan.ts`).
47
+ *
48
+ * Types only from the transfer core, so the console registrar that reads
49
+ * the dictionaries costs no transfer code.
50
+ *
51
+ * Text message marketing is not sent from here, so its column is read and
52
+ * not kept; a store's lifetime spend and order count are not kept either,
53
+ * because a contact's spend counts what they buy here. The dry run says so.
54
+ *=========================================*/ /** The field ids this module reads; the import-only ones are never stored. */ export const CUSTOMER_FIELD = {
55
+ emailMarketing: 'emailMarketingChoice',
56
+ smsMarketing: 'smsMarketingChoice',
57
+ totalSpent: 'oldStoreTotalSpent',
58
+ orderCount: 'oldStoreOrderCount',
59
+ customerId: 'oldStoreCustomerId'
60
+ };
61
+ const C = CUSTOMER_FIELD;
62
+ /** The contact field a carried choice changes. */ export const MARKETING_CONSENT_FIELD_ID = 'marketingConsent';
63
+ /** The fields that exist only to read another platform's file; never stored, never exported. */ export const CUSTOMER_SOURCE_ONLY_FIELDS = [
64
+ C.emailMarketing,
65
+ C.smsMarketing,
66
+ C.totalSpent,
67
+ C.orderCount,
68
+ C.customerId
69
+ ];
70
+ /** The picker group the import-only fields are listed under. */ export const CUSTOMER_SWITCHING_GROUP = {
71
+ id: 'switching',
72
+ label: 'From your old store'
73
+ };
74
+ /** The import-only fields, as the Columns step offers them. */ export const CUSTOMER_SOURCE_FIELDS = [
75
+ {
76
+ id: C.emailMarketing,
77
+ label: 'Email marketing choice',
78
+ group: CUSTOMER_SWITCHING_GROUP.id,
79
+ importOnly: true,
80
+ type: 'text',
81
+ maxLength: 60,
82
+ aliases: [
83
+ 'accepts email marketing',
84
+ 'email marketing',
85
+ 'email subscriber status',
86
+ 'accepts marketing'
87
+ ],
88
+ description: 'Yes or Subscribed opts a person in only when you confirm on the Permission step that they agreed to hear from you. No or Unsubscribed is always kept.'
89
+ },
90
+ {
91
+ id: C.smsMarketing,
92
+ label: 'Text message marketing choice',
93
+ group: CUSTOMER_SWITCHING_GROUP.id,
94
+ importOnly: true,
95
+ type: 'text',
96
+ maxLength: 60,
97
+ aliases: [
98
+ 'accepts sms marketing',
99
+ 'sms subscriber status',
100
+ 'sms marketing'
101
+ ],
102
+ description: 'Read and not kept: marketing texts are not sent from here.'
103
+ },
104
+ {
105
+ id: C.totalSpent,
106
+ label: 'Total spent at your old store',
107
+ group: CUSTOMER_SWITCHING_GROUP.id,
108
+ importOnly: true,
109
+ type: 'text',
110
+ maxLength: 60,
111
+ description: 'Read and not kept: a contact’s spend counts what they buy on your site.'
112
+ },
113
+ {
114
+ id: C.orderCount,
115
+ label: 'Orders at your old store',
116
+ group: CUSTOMER_SWITCHING_GROUP.id,
117
+ importOnly: true,
118
+ type: 'text',
119
+ maxLength: 60,
120
+ description: 'Read and not kept, like the total spent.'
121
+ },
122
+ {
123
+ id: C.customerId,
124
+ label: 'Old store customer ID',
125
+ group: CUSTOMER_SWITCHING_GROUP.id,
126
+ importOnly: true,
127
+ type: 'text',
128
+ maxLength: 120,
129
+ description: 'Read and not kept. A person is matched by their email.'
130
+ }
131
+ ];
132
+ /*------------------------------------------
133
+ * The three files' columns
134
+ *-----------------------------------------*/ /** A contact address's six columns, under the field prefix (`mailing`, `other`). */ function addressColumns(prefix, words) {
135
+ return {
136
+ [`${prefix}Street`]: words.street,
137
+ [`${prefix}Street2`]: words.street2,
138
+ [`${prefix}City`]: words.city,
139
+ [`${prefix}State`]: words.state,
140
+ [`${prefix}PostalCode`]: words.postalCode,
141
+ [`${prefix}Country`]: words.country
142
+ };
143
+ }
144
+ /**
145
+ * Shopify's customers CSV, by the field each column means: today's
146
+ * `Default Address …` columns and the older file's bare ones. Its address
147
+ * phone is the contact's other phone; its `Phone` is their phone.
148
+ */ export const SHOPIFY_CUSTOMER_COLUMNS = _extends({
149
+ [C.customerId]: [
150
+ 'Customer ID'
151
+ ],
152
+ firstName: [
153
+ 'First Name'
154
+ ],
155
+ lastName: [
156
+ 'Last Name'
157
+ ],
158
+ email: [
159
+ 'Email'
160
+ ],
161
+ phone: [
162
+ 'Phone'
163
+ ],
164
+ otherPhone: [
165
+ 'Default Address Phone'
166
+ ],
167
+ company: [
168
+ 'Default Address Company',
169
+ 'Company'
170
+ ],
171
+ [C.emailMarketing]: [
172
+ 'Accepts Email Marketing',
173
+ 'Accepts Marketing'
174
+ ],
175
+ [C.smsMarketing]: [
176
+ 'Accepts SMS Marketing'
177
+ ],
178
+ [C.totalSpent]: [
179
+ 'Total Spent'
180
+ ],
181
+ [C.orderCount]: [
182
+ 'Total Orders'
183
+ ],
184
+ notes: [
185
+ 'Note'
186
+ ],
187
+ tags: [
188
+ 'Tags'
189
+ ]
190
+ }, addressColumns('mailing', {
191
+ street: [
192
+ 'Default Address Address1',
193
+ 'Address1'
194
+ ],
195
+ street2: [
196
+ 'Default Address Address2',
197
+ 'Address2'
198
+ ],
199
+ city: [
200
+ 'Default Address City',
201
+ 'City'
202
+ ],
203
+ state: [
204
+ 'Default Address Province Code',
205
+ 'Province',
206
+ 'Province Code'
207
+ ],
208
+ postalCode: [
209
+ 'Default Address Zip',
210
+ 'Zip'
211
+ ],
212
+ country: [
213
+ 'Default Address Country Code',
214
+ 'Country Code',
215
+ 'Country'
216
+ ]
217
+ }));
218
+ /** Wix's contacts CSV: two emails and phones (the first is the person's), two addresses, labels. */ export const WIX_CONTACT_COLUMNS = _extends({
219
+ firstName: [
220
+ 'First Name'
221
+ ],
222
+ lastName: [
223
+ 'Last Name'
224
+ ],
225
+ email: [
226
+ 'Email 1'
227
+ ],
228
+ phone: [
229
+ 'Phone 1'
230
+ ],
231
+ otherPhone: [
232
+ 'Phone 2'
233
+ ],
234
+ company: [
235
+ 'Company'
236
+ ],
237
+ jobTitle: [
238
+ 'Position'
239
+ ],
240
+ tags: [
241
+ 'Labels'
242
+ ],
243
+ [C.emailMarketing]: [
244
+ 'Email subscriber status'
245
+ ],
246
+ [C.smsMarketing]: [
247
+ 'SMS subscriber status'
248
+ ]
249
+ }, addressColumns('mailing', {
250
+ street: [
251
+ 'Address 1 - Street',
252
+ 'Address 1 - Street Line 1'
253
+ ],
254
+ street2: [
255
+ 'Address 1 - Street Line 2',
256
+ 'Address 1 - Street 2'
257
+ ],
258
+ city: [
259
+ 'Address 1 - City'
260
+ ],
261
+ state: [
262
+ 'Address 1 - State/Region',
263
+ 'Address 1 - State'
264
+ ],
265
+ postalCode: [
266
+ 'Address 1 - Zip',
267
+ 'Address 1 - Zip/Postal Code'
268
+ ],
269
+ country: [
270
+ 'Address 1 - Country'
271
+ ]
272
+ }), addressColumns('other', {
273
+ street: [
274
+ 'Address 2 - Street',
275
+ 'Address 2 - Street Line 1'
276
+ ],
277
+ street2: [
278
+ 'Address 2 - Street Line 2',
279
+ 'Address 2 - Street 2'
280
+ ],
281
+ city: [
282
+ 'Address 2 - City'
283
+ ],
284
+ state: [
285
+ 'Address 2 - State/Region',
286
+ 'Address 2 - State'
287
+ ],
288
+ postalCode: [
289
+ 'Address 2 - Zip',
290
+ 'Address 2 - Zip/Postal Code'
291
+ ],
292
+ country: [
293
+ 'Address 2 - Country'
294
+ ]
295
+ }));
296
+ /** Squarespace's customers CSV: the shipping address is the mailing one, billing the other. */ export const SQUARESPACE_CUSTOMER_COLUMNS = _extends({
297
+ email: [
298
+ 'Email'
299
+ ],
300
+ firstName: [
301
+ 'First Name'
302
+ ],
303
+ lastName: [
304
+ 'Last Name'
305
+ ],
306
+ phone: [
307
+ 'Shipping Phone Number'
308
+ ],
309
+ otherPhone: [
310
+ 'Billing Phone Number'
311
+ ],
312
+ tags: [
313
+ 'Tags'
314
+ ],
315
+ [C.emailMarketing]: [
316
+ 'Accepts Marketing'
317
+ ],
318
+ [C.totalSpent]: [
319
+ 'Total Spent'
320
+ ],
321
+ [C.orderCount]: [
322
+ 'Order Count'
323
+ ]
324
+ }, addressColumns('mailing', {
325
+ street: [
326
+ 'Shipping Address 1'
327
+ ],
328
+ street2: [
329
+ 'Shipping Address 2'
330
+ ],
331
+ city: [
332
+ 'Shipping City'
333
+ ],
334
+ state: [
335
+ 'Shipping Province/State',
336
+ 'Shipping State'
337
+ ],
338
+ postalCode: [
339
+ 'Shipping Zip',
340
+ 'Shipping Postal Code'
341
+ ],
342
+ country: [
343
+ 'Shipping Country'
344
+ ]
345
+ }), addressColumns('other', {
346
+ street: [
347
+ 'Billing Address 1'
348
+ ],
349
+ street2: [
350
+ 'Billing Address 2'
351
+ ],
352
+ city: [
353
+ 'Billing City'
354
+ ],
355
+ state: [
356
+ 'Billing Province/State',
357
+ 'Billing State'
358
+ ],
359
+ postalCode: [
360
+ 'Billing Zip',
361
+ 'Billing Postal Code'
362
+ ],
363
+ country: [
364
+ 'Billing Country'
365
+ ]
366
+ }));
367
+ /** The three dictionaries, beside the CRMs' own (`aliases.ts`). */ export const CUSTOMER_ALIAS_DICTIONARIES = [
368
+ {
369
+ source: 'Shopify',
370
+ aliases: SHOPIFY_CUSTOMER_COLUMNS
371
+ },
372
+ {
373
+ source: 'Wix',
374
+ aliases: WIX_CONTACT_COLUMNS
375
+ },
376
+ {
377
+ source: 'Squarespace',
378
+ aliases: SQUARESPACE_CUSTOMER_COLUMNS
379
+ }
380
+ ];
381
+ /** Each store's name, as the dry run and the consent record say it. */ export const CUSTOMER_FILE_SOURCE_NAMES = {
382
+ shopify: 'Shopify',
383
+ wix: 'Wix',
384
+ squarespace: 'Squarespace'
385
+ };
386
+ const compact = (header)=>String(header != null ? header : '').toLowerCase().replace(/[^a-z0-9]+/g, '');
387
+ /**
388
+ * The store a file came from, by its header signature, or `null` for any
389
+ * other file: Shopify's `Accepts Email Marketing` or `Default Address …`
390
+ * columns (or the older `Accepts Marketing` beside `Total Orders`); Wix's
391
+ * `Email 1` beside its subscriber status or numbered addresses;
392
+ * Squarespace's `Accepts Marketing` beside its shipping or billing columns.
393
+ */ export function customerFileSource(headers) {
394
+ if (!(headers == null ? void 0 : headers.length)) return null;
395
+ const have = new Set(headers.map(compact));
396
+ if (have.has('email1') && (have.has('emailsubscriberstatus') || have.has('address1street') || have.has('labels'))) {
397
+ return 'wix';
398
+ }
399
+ if (have.has('acceptsemailmarketing') || have.has('defaultaddressaddress1') || have.has('acceptsmarketing') && (have.has('totalorders') || have.has('customerid'))) {
400
+ return 'shopify';
401
+ }
402
+ if (have.has('acceptsmarketing') && (have.has('shippingaddress1') || have.has('billingaddress1') || have.has('customersince') || have.has('ordercount'))) {
403
+ return 'squarespace';
404
+ }
405
+ return null;
406
+ }
407
+ /*------------------------------------------
408
+ * Reading a marketing choice
409
+ *-----------------------------------------*/ /** A marketing cell as a choice: the platform's reader, shared with the email list import. */ export { readMarketingChoice } from "@aglyn/aglyn/app-utils/marketing-choice";
410
+ /*------------------------------------------
411
+ * The Permission step's answer
412
+ *-----------------------------------------*/ /** The CRM contact import's own wizard step: the statement of permission. */ export const CONTACT_CONSENT_STEP_ID = 'crm-consent';
413
+ /** The answer in `extras`. Anything but a literal `true` is no statement at all. */ export function readContactConsentAnswer(extras) {
414
+ const value = extras == null ? void 0 : extras[CONTACT_CONSENT_STEP_ID];
415
+ return {
416
+ attest: !!value && typeof value === 'object' && value['attest'] === true
417
+ };
418
+ }
419
+
420
+ //# sourceMappingURL=customer-sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/transfer/customer-sources.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { TransferAliasDictionary, TransferField, TransferFieldGroup } from '@aglyn/aglyn/data-transfer'\n\n/*==========================================\n * A STORE'S CUSTOMER FILE (AGL-4245).\n *\n * A store moving from Shopify, Wix or Squarespace brings its customers in\n * through the contact import. Each platform's customer export is recognized\n * by its own column names (the dictionaries below, read by the header\n * matcher like Salesforce's), so the Columns step maps it with nothing to\n * pick. Unknown and missing columns are never a failure.\n *\n * ## The marketing choice the file records\n *\n * Each file says whether a customer agreed to marketing email: Shopify's\n * `Accepts Email Marketing` (`Accepts Marketing` in older files), Wix's\n * `Email subscriber status`, Squarespace's `Accepts Marketing`. It is read\n * into an import-only field and carried under three rules:\n *\n * - **An opt-in** becomes the contact's marketing consent for the import's\n * site ONLY when the person importing states, on the Permission step, that\n * these people agreed to hear from this business. Without that, nobody is\n * opted in from the file. A contact who unsubscribed here (a refusal on\n * record, or the site's unsubscribe list) is never opted back in.\n * - **An opt-out** (`no`, `false`, `Unsubscribed`) is ALWAYS kept, whatever\n * the step says: it is recorded as the contact's refusal, and a contact\n * who was subscribed here is unsubscribed.\n * - **No choice** (`Never subscribed`, `Pending`, blank, a word we cannot\n * read) changes nothing.\n *\n * The plan carries each change as a `marketingConsent` row change stamped\n * with who planned it and whether they confirmed, so the apply never takes\n * either from the browser (`customer-consent-plan.ts`).\n *\n * Types only from the transfer core, so the console registrar that reads\n * the dictionaries costs no transfer code.\n *\n * Text message marketing is not sent from here, so its column is read and\n * not kept; a store's lifetime spend and order count are not kept either,\n * because a contact's spend counts what they buy here. The dry run says so.\n *=========================================*/\n\n/** The field ids this module reads; the import-only ones are never stored. */\nexport const CUSTOMER_FIELD = {\n emailMarketing: 'emailMarketingChoice',\n smsMarketing: 'smsMarketingChoice',\n totalSpent: 'oldStoreTotalSpent',\n orderCount: 'oldStoreOrderCount',\n customerId: 'oldStoreCustomerId',\n} as const\n\nconst C = CUSTOMER_FIELD\n\n/** The contact field a carried choice changes. */\nexport const MARKETING_CONSENT_FIELD_ID = 'marketingConsent'\n\n/** The fields that exist only to read another platform's file; never stored, never exported. */\nexport const CUSTOMER_SOURCE_ONLY_FIELDS: readonly string[] = [\n C.emailMarketing,\n C.smsMarketing,\n C.totalSpent,\n C.orderCount,\n C.customerId,\n]\n\n/** The picker group the import-only fields are listed under. */\nexport const CUSTOMER_SWITCHING_GROUP: TransferFieldGroup = { id: 'switching', label: 'From your old store' }\n\n/** The import-only fields, as the Columns step offers them. */\nexport const CUSTOMER_SOURCE_FIELDS: readonly TransferField[] = [\n {\n id: C.emailMarketing,\n label: 'Email marketing choice',\n group: CUSTOMER_SWITCHING_GROUP.id,\n importOnly: true,\n type: 'text',\n maxLength: 60,\n aliases: ['accepts email marketing', 'email marketing', 'email subscriber status', 'accepts marketing'],\n description:\n 'Yes or Subscribed opts a person in only when you confirm on the Permission step that they agreed to hear from you. No or Unsubscribed is always kept.',\n },\n {\n id: C.smsMarketing,\n label: 'Text message marketing choice',\n group: CUSTOMER_SWITCHING_GROUP.id,\n importOnly: true,\n type: 'text',\n maxLength: 60,\n aliases: ['accepts sms marketing', 'sms subscriber status', 'sms marketing'],\n description: 'Read and not kept: marketing texts are not sent from here.',\n },\n {\n id: C.totalSpent,\n label: 'Total spent at your old store',\n group: CUSTOMER_SWITCHING_GROUP.id,\n importOnly: true,\n type: 'text',\n maxLength: 60,\n description: 'Read and not kept: a contact’s spend counts what they buy on your site.',\n },\n {\n id: C.orderCount,\n label: 'Orders at your old store',\n group: CUSTOMER_SWITCHING_GROUP.id,\n importOnly: true,\n type: 'text',\n maxLength: 60,\n description: 'Read and not kept, like the total spent.',\n },\n {\n id: C.customerId,\n label: 'Old store customer ID',\n group: CUSTOMER_SWITCHING_GROUP.id,\n importOnly: true,\n type: 'text',\n maxLength: 120,\n description: 'Read and not kept. A person is matched by their email.',\n },\n]\n\n/*------------------------------------------\n * The three files' columns\n *-----------------------------------------*/\n\n/** A contact address's six columns, under the field prefix (`mailing`, `other`). */\nfunction addressColumns(\n prefix: 'mailing' | 'other',\n words: { street: string[]; street2: string[]; city: string[]; state: string[]; postalCode: string[]; country: string[] },\n): Record<string, readonly string[]> {\n return {\n [`${prefix}Street`]: words.street,\n [`${prefix}Street2`]: words.street2,\n [`${prefix}City`]: words.city,\n [`${prefix}State`]: words.state,\n [`${prefix}PostalCode`]: words.postalCode,\n [`${prefix}Country`]: words.country,\n }\n}\n\n/**\n * Shopify's customers CSV, by the field each column means: today's\n * `Default Address …` columns and the older file's bare ones. Its address\n * phone is the contact's other phone; its `Phone` is their phone.\n */\nexport const SHOPIFY_CUSTOMER_COLUMNS: Readonly<Record<string, readonly string[]>> = {\n [C.customerId]: ['Customer ID'],\n firstName: ['First Name'],\n lastName: ['Last Name'],\n email: ['Email'],\n phone: ['Phone'],\n otherPhone: ['Default Address Phone'],\n company: ['Default Address Company', 'Company'],\n [C.emailMarketing]: ['Accepts Email Marketing', 'Accepts Marketing'],\n [C.smsMarketing]: ['Accepts SMS Marketing'],\n [C.totalSpent]: ['Total Spent'],\n [C.orderCount]: ['Total Orders'],\n notes: ['Note'],\n tags: ['Tags'],\n ...addressColumns('mailing', {\n street: ['Default Address Address1', 'Address1'],\n street2: ['Default Address Address2', 'Address2'],\n city: ['Default Address City', 'City'],\n state: ['Default Address Province Code', 'Province', 'Province Code'],\n postalCode: ['Default Address Zip', 'Zip'],\n country: ['Default Address Country Code', 'Country Code', 'Country'],\n }),\n}\n\n/** Wix's contacts CSV: two emails and phones (the first is the person's), two addresses, labels. */\nexport const WIX_CONTACT_COLUMNS: Readonly<Record<string, readonly string[]>> = {\n firstName: ['First Name'],\n lastName: ['Last Name'],\n email: ['Email 1'],\n phone: ['Phone 1'],\n otherPhone: ['Phone 2'],\n company: ['Company'],\n jobTitle: ['Position'],\n tags: ['Labels'],\n [C.emailMarketing]: ['Email subscriber status'],\n [C.smsMarketing]: ['SMS subscriber status'],\n ...addressColumns('mailing', {\n street: ['Address 1 - Street', 'Address 1 - Street Line 1'],\n street2: ['Address 1 - Street Line 2', 'Address 1 - Street 2'],\n city: ['Address 1 - City'],\n state: ['Address 1 - State/Region', 'Address 1 - State'],\n postalCode: ['Address 1 - Zip', 'Address 1 - Zip/Postal Code'],\n country: ['Address 1 - Country'],\n }),\n ...addressColumns('other', {\n street: ['Address 2 - Street', 'Address 2 - Street Line 1'],\n street2: ['Address 2 - Street Line 2', 'Address 2 - Street 2'],\n city: ['Address 2 - City'],\n state: ['Address 2 - State/Region', 'Address 2 - State'],\n postalCode: ['Address 2 - Zip', 'Address 2 - Zip/Postal Code'],\n country: ['Address 2 - Country'],\n }),\n}\n\n/** Squarespace's customers CSV: the shipping address is the mailing one, billing the other. */\nexport const SQUARESPACE_CUSTOMER_COLUMNS: Readonly<Record<string, readonly string[]>> = {\n email: ['Email'],\n firstName: ['First Name'],\n lastName: ['Last Name'],\n phone: ['Shipping Phone Number'],\n otherPhone: ['Billing Phone Number'],\n tags: ['Tags'],\n [C.emailMarketing]: ['Accepts Marketing'],\n [C.totalSpent]: ['Total Spent'],\n [C.orderCount]: ['Order Count'],\n ...addressColumns('mailing', {\n street: ['Shipping Address 1'],\n street2: ['Shipping Address 2'],\n city: ['Shipping City'],\n state: ['Shipping Province/State', 'Shipping State'],\n postalCode: ['Shipping Zip', 'Shipping Postal Code'],\n country: ['Shipping Country'],\n }),\n ...addressColumns('other', {\n street: ['Billing Address 1'],\n street2: ['Billing Address 2'],\n city: ['Billing City'],\n state: ['Billing Province/State', 'Billing State'],\n postalCode: ['Billing Zip', 'Billing Postal Code'],\n country: ['Billing Country'],\n }),\n}\n\n/** The three dictionaries, beside the CRMs' own (`aliases.ts`). */\nexport const CUSTOMER_ALIAS_DICTIONARIES: readonly TransferAliasDictionary[] = [\n { source: 'Shopify', aliases: SHOPIFY_CUSTOMER_COLUMNS },\n { source: 'Wix', aliases: WIX_CONTACT_COLUMNS },\n { source: 'Squarespace', aliases: SQUARESPACE_CUSTOMER_COLUMNS },\n]\n\n/** Which store's customer file this is. */\nexport type CustomerFileSource = 'shopify' | 'wix' | 'squarespace'\n\n/** Each store's name, as the dry run and the consent record say it. */\nexport const CUSTOMER_FILE_SOURCE_NAMES: Readonly<Record<CustomerFileSource, string>> = {\n shopify: 'Shopify',\n wix: 'Wix',\n squarespace: 'Squarespace',\n}\n\nconst compact = (header: unknown) => String(header ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '')\n\n/**\n * The store a file came from, by its header signature, or `null` for any\n * other file: Shopify's `Accepts Email Marketing` or `Default Address …`\n * columns (or the older `Accepts Marketing` beside `Total Orders`); Wix's\n * `Email 1` beside its subscriber status or numbered addresses;\n * Squarespace's `Accepts Marketing` beside its shipping or billing columns.\n */\nexport function customerFileSource(headers: readonly string[] | undefined): CustomerFileSource | null {\n if (!headers?.length) return null\n const have = new Set(headers.map(compact))\n if (have.has('email1') && (have.has('emailsubscriberstatus') || have.has('address1street') || have.has('labels'))) {\n return 'wix'\n }\n if (\n have.has('acceptsemailmarketing') ||\n have.has('defaultaddressaddress1') ||\n (have.has('acceptsmarketing') && (have.has('totalorders') || have.has('customerid')))\n ) {\n return 'shopify'\n }\n if (\n have.has('acceptsmarketing') &&\n (have.has('shippingaddress1') || have.has('billingaddress1') || have.has('customersince') || have.has('ordercount'))\n ) {\n return 'squarespace'\n }\n return null\n}\n\n/*------------------------------------------\n * Reading a marketing choice\n *-----------------------------------------*/\n\n/** A marketing cell as a choice: the platform's reader, shared with the email list import. */\nexport { readMarketingChoice, type MarketingChoice } from '@aglyn/aglyn/app-utils/marketing-choice'\n\n/*------------------------------------------\n * The Permission step's answer\n *-----------------------------------------*/\n\n/** The CRM contact import's own wizard step: the statement of permission. */\nexport const CONTACT_CONSENT_STEP_ID = 'crm-consent'\n\n/** The answer of the {@link CONTACT_CONSENT_STEP_ID} step. */\nexport interface ContactConsentAnswer {\n /** The person importing states that the people the file opts in agreed to hear from this business. */\n attest: boolean\n}\n\n/** The answer in `extras`. Anything but a literal `true` is no statement at all. */\nexport function readContactConsentAnswer(extras: Readonly<Record<string, unknown>> | undefined): ContactConsentAnswer {\n const value = extras?.[CONTACT_CONSENT_STEP_ID]\n return {\n attest: !!value && typeof value === 'object' && (value as Record<string, unknown>)['attest'] === true,\n }\n}\n"],"names":["CUSTOMER_FIELD","emailMarketing","smsMarketing","totalSpent","orderCount","customerId","C","MARKETING_CONSENT_FIELD_ID","CUSTOMER_SOURCE_ONLY_FIELDS","CUSTOMER_SWITCHING_GROUP","id","label","CUSTOMER_SOURCE_FIELDS","group","importOnly","type","maxLength","aliases","description","addressColumns","prefix","words","street","street2","city","state","postalCode","country","SHOPIFY_CUSTOMER_COLUMNS","firstName","lastName","email","phone","otherPhone","company","notes","tags","WIX_CONTACT_COLUMNS","jobTitle","SQUARESPACE_CUSTOMER_COLUMNS","CUSTOMER_ALIAS_DICTIONARIES","source","CUSTOMER_FILE_SOURCE_NAMES","shopify","wix","squarespace","compact","header","String","toLowerCase","replace","customerFileSource","headers","length","have","Set","map","has","readMarketingChoice","CONTACT_CONSENT_STEP_ID","readContactConsentAnswer","extras","value","attest"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAqC2C,GAE3C,4EAA4E,GAC5E,OAAO,MAAMA,iBAAiB;IAC5BC,gBAAgB;IAChBC,cAAc;IACdC,YAAY;IACZC,YAAY;IACZC,YAAY;AACd,EAAU;AAEV,MAAMC,IAAIN;AAEV,gDAAgD,GAChD,OAAO,MAAMO,6BAA6B,mBAAkB;AAE5D,8FAA8F,GAC9F,OAAO,MAAMC,8BAAiD;IAC5DF,EAAEL,cAAc;IAChBK,EAAEJ,YAAY;IACdI,EAAEH,UAAU;IACZG,EAAEF,UAAU;IACZE,EAAED,UAAU;CACb,CAAA;AAED,8DAA8D,GAC9D,OAAO,MAAMI,2BAA+C;IAAEC,IAAI;IAAaC,OAAO;AAAsB,EAAC;AAE7G,6DAA6D,GAC7D,OAAO,MAAMC,yBAAmD;IAC9D;QACEF,IAAIJ,EAAEL,cAAc;QACpBU,OAAO;QACPE,OAAOJ,yBAAyBC,EAAE;QAClCI,YAAY;QACZC,MAAM;QACNC,WAAW;QACXC,SAAS;YA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MC,UAAU,CAACC,SAAoBC,OAAOD,iBAAAA,SAAU,IAAIE,WAAW,GAAGC,OAAO,CAAC,eAAe;AAE/F;;;;;;CAMC,GACD,OAAO,SAASC,mBAAmBC,OAAsC;IACvE,IAAI,EAACA,2BAAAA,QAASC,MAAM,GAAE,OAAO;IAC7B,MAAMC,OAAO,IAAIC,IAAIH,QAAQI,GAAG,CAACV;IACjC,IAAIQ,KAAKG,GAAG,CAAC,aAAcH,CAAAA,KAAKG,GAAG,CAAC,4BAA4BH,KAAKG,GAAG,CAAC,qBAAqBH,KAAKG,GAAG,CAAC,SAAQ,GAAI;QACjH,OAAO;IACT;IACA,IACEH,KAAKG,GAAG,CAAC,4BACTH,KAAKG,GAAG,CAAC,6BACRH,KAAKG,GAAG,CAAC,uBAAwBH,CAAAA,KAAKG,GAAG,CAAC,kBAAkBH,KAAKG,GAAG,CAAC,aAAY,GAClF;QACA,OAAO;IACT;IACA,IACEH,KAAKG,GAAG,CAAC,uBACRH,CAAAA,KAAKG,GAAG,CAAC,uBAAuBH,KAAKG,GAAG,CAAC,sBAAsBH,KAAKG,GAAG,CAAC,oBAAoBH,KAAKG,GAAG,CAAC,aAAY,GAClH;QACA,OAAO;IACT;IACA,OAAO;AACT;AAEA;;2CAE2C,GAE3C,4FAA4F,GAC5F,SAASC,mBAAmB,QAA8B,0CAAyC;AAEnG;;2CAE2C,GAE3C,2EAA2E,GAC3E,OAAO,MAAMC,0BAA0B,cAAa;AAQpD,kFAAkF,GAClF,OAAO,SAASC,yBAAyBC,MAAqD;IAC5F,MAAMC,QAAQD,0BAAAA,MAAQ,CAACF,wBAAwB;IAC/C,OAAO;QACLI,QAAQ,CAAC,CAACD,SAAS,OAAOA,UAAU,YAAY,AAACA,KAAiC,CAAC,SAAS,KAAK;IACnG;AACF"}
@@ -39,6 +39,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
39
39
  * record keeps one postal address; the server half composes it.
40
40
  *=========================================*/ import { CONTACT_LIFECYCLE_STAGE_LABELS, CONTACT_LIFECYCLE_STAGES, CRM_LEAD_SOURCE_PICKLIST, CRM_LEAD_STATUS_PICKLIST, CRM_OPPORTUNITY_TYPE_PICKLIST, CRM_SALUTATION_PICKLIST } from "@aglyn/aglyn/app-utils/crm";
41
41
  import { CRM_ACTIVITIES_RESOURCE, CRM_COMPANIES_RESOURCE, CRM_CONTACTS_RESOURCE, CRM_DEALS_RESOURCE, CRM_FIELDS_RESOURCE, CRM_LEADS_RESOURCE, CRM_PIPELINES_RESOURCE, CRM_TASKS_RESOURCE } from "./resource-keys.js";
42
+ import { CUSTOMER_SOURCE_FIELDS, CUSTOMER_SWITCHING_GROUP } from "./customer-sources.js";
42
43
  /** The CRM's resource keys, as `plugins.config.json` declares them. */ export { CRM_ACTIVITIES_RESOURCE, CRM_COMPANIES_RESOURCE, CRM_CONTACTS_RESOURCE, CRM_DEALS_RESOURCE, CRM_FIELDS_RESOURCE, CRM_LEADS_RESOURCE, CRM_PIPELINES_RESOURCE, CRM_TASKS_RESOURCE, };
43
44
  /**
44
45
  * The workspace's members, as an owner column names them: a lookup target
@@ -141,7 +142,8 @@ import { CRM_ACTIVITIES_RESOURCE, CRM_COMPANIES_RESOURCE, CRM_CONTACTS_RESOURCE,
141
142
  {
142
143
  id: 'activity',
143
144
  label: 'Activity'
144
- }
145
+ },
146
+ CUSTOMER_SWITCHING_GROUP
145
147
  ];
146
148
  /** A contact's own fields, in the order the picker lists them. */ export const CONTACT_TRANSFER_FIELDS = [
147
149
  {
@@ -437,8 +439,10 @@ import { CRM_ACTIVITIES_RESOURCE, CRM_COMPANIES_RESOURCE, CRM_CONTACTS_RESOURCE,
437
439
  'email consent',
438
440
  'email opt in'
439
441
  ],
440
- description: 'Exported as it stands; never set from a file.'
441
- }
442
+ description: 'Exported as it stands; never set from this column. A store’s marketing choice goes to Email marketing choice.'
443
+ },
444
+ // Read from a store's customer file (AGL-4245, `customer-sources.ts`); never stored, so import-only.
445
+ ...CUSTOMER_SOURCE_FIELDS
442
446
  ];
443
447
  /** What only the platform writes about a contact: exported, never imported. */ export const CONTACT_TRANSFER_DERIVED = [
444
448
  {