@aglyn/plugins-crm 1.29.0 → 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,90 @@
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 PlannedTransferRow, type TransferFieldChange, type TransferPlan, type TransferPlanRow, type TransferWarningSample } from '@aglyn/aglyn/data-transfer';
18
+ import { type CustomerFileSource } from './customer-sources';
19
+ /** What the apply does with one row's choice, as the plan stamped it. */
20
+ export interface ImportedConsentDetail {
21
+ action: 'grant' | 'decline';
22
+ /** Who planned the import: the member who answered the Permission step. */
23
+ by: string | null;
24
+ /** Whether that member confirmed these people agreed to hear from this business. */
25
+ attested: boolean;
26
+ jobId: string | null;
27
+ /** The store the file came from, or `file` for one the import does not recognize. */
28
+ source: CustomerFileSource | 'file';
29
+ }
30
+ /** A row's change to `marketingConsent`, carrying {@link ImportedConsentDetail}. */
31
+ export type ImportedConsentChange = TransferFieldChange & {
32
+ consent: ImportedConsentDetail;
33
+ };
34
+ /** The consent change a planned row carries, if any. */
35
+ export declare function importedConsentChange(row: Pick<PlannedTransferRow, 'diff'>): ImportedConsentChange | null;
36
+ /** The rows with every import-only value taken out, for the core's plan. */
37
+ export declare function withoutCustomerSourceFields(rows: readonly TransferPlanRow[]): TransferPlanRow[];
38
+ /** What the plan needs to know beside the rows. */
39
+ export interface ContactConsentPlanContext {
40
+ /** The site the consent is recorded for; `null` for an import with no Source site. */
41
+ hostId: string | null;
42
+ /** The Permission step's statement. */
43
+ attested: boolean;
44
+ /** The member planning the import. */
45
+ recordedBy: string | null;
46
+ jobId: string | null;
47
+ source: CustomerFileSource | null;
48
+ /** Addresses the site's unsubscribe list holds, lowercased. */
49
+ suppressed: ReadonlySet<string>;
50
+ }
51
+ /** What the file's choices come to, counted for the dry run. */
52
+ export interface ContactConsentCounts {
53
+ optedIn: number;
54
+ unsubscribes: number;
55
+ /** Of the unsubscribes, people who were subscribed here. */
56
+ unsubscribedFromSubscribed: number;
57
+ noConsent: number;
58
+ alreadySame: number;
59
+ notConfirmed: number;
60
+ keptUnsubscribed: number;
61
+ noSite: number;
62
+ noEmail: number;
63
+ unread: number;
64
+ unreadSample: string | null;
65
+ }
66
+ /** The address a row is about: the file's, else the matched contact's. */
67
+ export declare function consentRowEmail(row: TransferPlanRow | undefined, planned: PlannedTransferRow, existing: ReadonlyMap<string, Readonly<Record<string, unknown>>>): string;
68
+ /** The addresses whose file opt-in the plan may carry, for the unsubscribe-list read. */
69
+ export declare function consentOptInEmails(plan: Pick<TransferPlan, 'rows'>, rows: readonly TransferPlanRow[], existing: ReadonlyMap<string, Readonly<Record<string, unknown>>>): string[];
70
+ /** The dry run's lines about the file's marketing choices and what is not kept. */
71
+ export declare function contactConsentSamples(counts: ContactConsentCounts | null, notes: {
72
+ sms: boolean;
73
+ spend: boolean;
74
+ }, ctx: Pick<ContactConsentPlanContext, 'source'>): TransferWarningSample[];
75
+ /**
76
+ * The plan with the file's marketing choices carried (see the module note):
77
+ * each opt-in it may carry and each opt-out that changes something becomes a
78
+ * `marketingConsent` change on its row — an otherwise unchanged row becomes
79
+ * an update — and the dry run gains one `screening` warning counting what
80
+ * happens and what is not kept. A file with none of the columns is returned
81
+ * as it came.
82
+ *
83
+ * `rows` are the rows as the file read them, import-only values included;
84
+ * `existing` holds each matched contact's values, `marketingConsent` read
85
+ * for the import's site (`true`, `false` or `null`).
86
+ */
87
+ export declare function planContactConsent(plan: TransferPlan, rows: readonly TransferPlanRow[], existing: ReadonlyMap<string, Readonly<Record<string, unknown>>>, ctx: ContactConsentPlanContext): {
88
+ plan: TransferPlan;
89
+ counts: ContactConsentCounts | null;
90
+ };
@@ -0,0 +1,258 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { TRANSFER_FILE_SAMPLE_ROW, TRANSFER_WARNING_CLASSES } from "@aglyn/aglyn/data-transfer";
18
+ import { CUSTOMER_FIELD as C, CUSTOMER_FILE_SOURCE_NAMES, CUSTOMER_SOURCE_ONLY_FIELDS, MARKETING_CONSENT_FIELD_ID, readMarketingChoice } from "./customer-sources.js";
19
+ /** The consent change a planned row carries, if any. */ export function importedConsentChange(row) {
20
+ const change = row.diff.find((entry)=>entry.fieldId === MARKETING_CONSENT_FIELD_ID);
21
+ const detail = change == null ? void 0 : change.consent;
22
+ if (!change || !detail || detail.action !== 'grant' && detail.action !== 'decline') return null;
23
+ return change;
24
+ }
25
+ /** The rows with every import-only value taken out, for the core's plan. */ export function withoutCustomerSourceFields(rows) {
26
+ return rows.map((row)=>{
27
+ if (!CUSTOMER_SOURCE_ONLY_FIELDS.some((fieldId)=>fieldId in row.values)) return row;
28
+ const values = _extends({}, row.values);
29
+ for (const fieldId of CUSTOMER_SOURCE_ONLY_FIELDS)delete values[fieldId];
30
+ return _extends({}, row, {
31
+ values
32
+ });
33
+ });
34
+ }
35
+ const emptyCounts = ()=>({
36
+ optedIn: 0,
37
+ unsubscribes: 0,
38
+ unsubscribedFromSubscribed: 0,
39
+ noConsent: 0,
40
+ alreadySame: 0,
41
+ notConfirmed: 0,
42
+ keptUnsubscribed: 0,
43
+ noSite: 0,
44
+ noEmail: 0,
45
+ unread: 0,
46
+ unreadSample: null
47
+ });
48
+ const lower = (value)=>value === null || value === undefined ? '' : String(value).trim().toLowerCase();
49
+ /** Whether any row carries the column. */ const carries = (rows, fieldId)=>rows.some((row)=>fieldId in row.values);
50
+ /** The address a row is about: the file's, else the matched contact's. */ export function consentRowEmail(row, planned, existing) {
51
+ const before = planned.recordId ? existing.get(planned.recordId) : undefined;
52
+ return lower(row == null ? void 0 : row.values['email']) || lower(before == null ? void 0 : before['email']);
53
+ }
54
+ /** The addresses whose file opt-in the plan may carry, for the unsubscribe-list read. */ export function consentOptInEmails(plan, rows, existing) {
55
+ const byIndex = new Map(rows.map((row)=>[
56
+ row.index,
57
+ row
58
+ ]));
59
+ const out = new Set();
60
+ for (const planned of plan.rows){
61
+ const row = byIndex.get(planned.index);
62
+ if (!row || readMarketingChoice(row.values[C.emailMarketing]).choice !== 'optIn') continue;
63
+ const email = consentRowEmail(row, planned, existing);
64
+ if (email) out.add(email);
65
+ }
66
+ return [
67
+ ...out
68
+ ];
69
+ }
70
+ const n = (count)=>count.toLocaleString('en-US');
71
+ const people = (count)=>`${n(count)} ${count === 1 ? 'person' : 'people'}`;
72
+ /** The dry run's lines about the file's marketing choices and what is not kept. */ export function contactConsentSamples(counts, notes, ctx) {
73
+ const where = ctx.source ? `your ${CUSTOMER_FILE_SOURCE_NAMES[ctx.source]} file` : 'the file';
74
+ const line = (fieldId, value, detail)=>({
75
+ row: TRANSFER_FILE_SAMPLE_ROW,
76
+ fieldId,
77
+ value: typeof value === 'number' ? n(value) : value,
78
+ detail
79
+ });
80
+ const samples = [];
81
+ const F = C.emailMarketing;
82
+ if (counts) {
83
+ samples.push(line(F, counts.optedIn, counts.optedIn ? `${people(counts.optedIn)} will be opted in to marketing email, as ${where} records and as you confirmed they agreed to hear from you.` : 'Nobody will be opted in to marketing email from this file.'), line(F, counts.unsubscribes, counts.unsubscribes ? `${n(counts.unsubscribes)} ${counts.unsubscribes === 1 ? 'unsubscribe' : 'unsubscribes'} from ${where} will be kept` + (counts.unsubscribedFromSubscribed ? `, and ${people(counts.unsubscribedFromSubscribed)} subscribed here will be unsubscribed.` : '.') + ' Undoing the import keeps these unsubscribes, because they are each person’s own choice.' : 'No unsubscribes in this file change anything here.'), line(F, counts.noConsent, `${people(counts.noConsent)} ${counts.noConsent === 1 ? 'has' : 'have'} no marketing choice recorded, and nothing about their marketing email changes.`));
84
+ if (counts.notConfirmed) {
85
+ samples.push(line(F, counts.notConfirmed, `${people(counts.notConfirmed)} said yes in ${where} but will not be opted in, because you did not confirm on the Permission step that they agreed to hear from you.`));
86
+ }
87
+ if (counts.keptUnsubscribed) {
88
+ samples.push(line(F, counts.keptUnsubscribed, `${people(counts.keptUnsubscribed)} said yes in ${where} but unsubscribed here, so they stay unsubscribed.`));
89
+ }
90
+ if (counts.noSite) {
91
+ samples.push(line(F, counts.noSite, `${people(counts.noSite)} said yes in ${where} but will not be opted in, because the import names no site. Import under the site they signed up on to bring opt-ins in.`));
92
+ }
93
+ if (counts.alreadySame) {
94
+ samples.push(line(F, counts.alreadySame, `${people(counts.alreadySame)} already ${counts.alreadySame === 1 ? 'has' : 'have'} the same choice recorded here.`));
95
+ }
96
+ if (counts.noEmail) {
97
+ samples.push(line(F, counts.noEmail, `${people(counts.noEmail)} ${counts.noEmail === 1 ? 'has' : 'have'} a marketing choice but no email address, so it is not kept.`));
98
+ }
99
+ if (counts.unread) {
100
+ var _counts_unreadSample;
101
+ samples.push(line(F, (_counts_unreadSample = counts.unreadSample) != null ? _counts_unreadSample : n(counts.unread), `${n(counts.unread)} marketing ${counts.unread === 1 ? 'value' : 'values'} could not be read, and count as no choice.`));
102
+ }
103
+ }
104
+ if (notes.sms) {
105
+ samples.push(line(C.smsMarketing, '', 'The text message marketing column is not kept: marketing texts are not sent from here, so nobody is opted in to them.'));
106
+ }
107
+ if (notes.spend) {
108
+ samples.push(line(C.totalSpent, '', 'Total spent and order counts from your old store are not kept. A contact’s spend counts what they buy on your site.'));
109
+ }
110
+ return samples;
111
+ }
112
+ /** The summary of `rows`, counted again. */ function summaryOf(rows) {
113
+ const summary = {
114
+ create: 0,
115
+ update: 0,
116
+ unchanged: 0,
117
+ skip: 0,
118
+ fail: 0,
119
+ total: rows.length
120
+ };
121
+ for (const row of rows)summary[row.verdict] += 1;
122
+ return summary;
123
+ }
124
+ /**
125
+ * The plan with the file's marketing choices carried (see the module note):
126
+ * each opt-in it may carry and each opt-out that changes something becomes a
127
+ * `marketingConsent` change on its row — an otherwise unchanged row becomes
128
+ * an update — and the dry run gains one `screening` warning counting what
129
+ * happens and what is not kept. A file with none of the columns is returned
130
+ * as it came.
131
+ *
132
+ * `rows` are the rows as the file read them, import-only values included;
133
+ * `existing` holds each matched contact's values, `marketingConsent` read
134
+ * for the import's site (`true`, `false` or `null`).
135
+ */ export function planContactConsent(plan, rows, existing, ctx) {
136
+ const notes = {
137
+ sms: carries(rows, C.smsMarketing),
138
+ spend: carries(rows, C.totalSpent) || carries(rows, C.orderCount)
139
+ };
140
+ const mapped = carries(rows, C.emailMarketing);
141
+ if (!mapped && !notes.sms && !notes.spend) return {
142
+ plan,
143
+ counts: null
144
+ };
145
+ const counts = mapped ? emptyCounts() : null;
146
+ const byIndex = new Map(rows.map((row)=>[
147
+ row.index,
148
+ row
149
+ ]));
150
+ const planned = plan.rows.map((plannedRow)=>{
151
+ var _ctx_source;
152
+ var _existing_get;
153
+ if (!counts) return plannedRow;
154
+ if (plannedRow.verdict !== 'create' && plannedRow.verdict !== 'update' && plannedRow.verdict !== 'unchanged') {
155
+ return plannedRow;
156
+ }
157
+ const row = byIndex.get(plannedRow.index);
158
+ const raw = row == null ? void 0 : row.values[C.emailMarketing];
159
+ const { choice, read } = readMarketingChoice(raw);
160
+ if (!read) {
161
+ var _counts, _unreadSample;
162
+ counts.unread += 1;
163
+ (_unreadSample = (_counts = counts).unreadSample) != null ? _unreadSample : _counts.unreadSample = String(raw != null ? raw : '').slice(0, 40);
164
+ }
165
+ const email = consentRowEmail(row, plannedRow, existing);
166
+ const before = plannedRow.recordId ? (_existing_get = existing.get(plannedRow.recordId)) == null ? void 0 : _existing_get[MARKETING_CONSENT_FIELD_ID] : null;
167
+ const stored = before === true ? true : before === false ? false : null;
168
+ if (choice === 'none') {
169
+ counts.noConsent += 1;
170
+ return plannedRow;
171
+ }
172
+ if (!email) {
173
+ counts.noEmail += 1;
174
+ return plannedRow;
175
+ }
176
+ let action = null;
177
+ if (choice === 'optOut') {
178
+ if (stored === false) counts.alreadySame += 1;
179
+ else {
180
+ action = 'decline';
181
+ counts.unsubscribes += 1;
182
+ if (stored === true) counts.unsubscribedFromSubscribed += 1;
183
+ }
184
+ } else if (!ctx.hostId) counts.noSite += 1;
185
+ else if (stored === false || ctx.suppressed.has(email)) counts.keptUnsubscribed += 1;
186
+ else if (stored === true) counts.alreadySame += 1;
187
+ else if (!ctx.attested) counts.notConfirmed += 1;
188
+ else {
189
+ action = 'grant';
190
+ counts.optedIn += 1;
191
+ }
192
+ if (!action) return plannedRow;
193
+ const change = {
194
+ fieldId: MARKETING_CONSENT_FIELD_ID,
195
+ before: stored,
196
+ after: action === 'grant',
197
+ mode: 'overwrite',
198
+ source: 'locked',
199
+ rule: 'written',
200
+ consent: {
201
+ action,
202
+ by: ctx.recordedBy,
203
+ attested: ctx.attested,
204
+ jobId: ctx.jobId,
205
+ source: (_ctx_source = ctx.source) != null ? _ctx_source : 'file'
206
+ }
207
+ };
208
+ return _extends({}, plannedRow, {
209
+ verdict: plannedRow.verdict === 'unchanged' ? 'update' : plannedRow.verdict,
210
+ diff: [
211
+ ...plannedRow.diff.filter((entry)=>entry.fieldId !== MARKETING_CONSENT_FIELD_ID),
212
+ change
213
+ ]
214
+ });
215
+ });
216
+ const samples = contactConsentSamples(counts, notes, ctx);
217
+ const warning = {
218
+ class: 'screening',
219
+ count: samples.length,
220
+ rows: 0,
221
+ fieldIds: [
222
+ ...new Set(samples.map((sample)=>sample.fieldId).filter((id)=>Boolean(id)))
223
+ ],
224
+ samples,
225
+ requiresAcknowledgement: true
226
+ };
227
+ const prior = plan.warnings.find((entry)=>entry.class === 'screening');
228
+ const warnings = prior ? plan.warnings.map((entry)=>entry === prior ? _extends({}, prior, {
229
+ count: prior.count + warning.count,
230
+ fieldIds: [
231
+ ...new Set([
232
+ ...prior.fieldIds,
233
+ ...warning.fieldIds
234
+ ])
235
+ ],
236
+ samples: [
237
+ ...prior.samples,
238
+ ...samples
239
+ ],
240
+ requiresAcknowledgement: true
241
+ }) : entry) : [
242
+ ...plan.warnings,
243
+ warning
244
+ ];
245
+ // The core's order of classes, kept.
246
+ warnings.sort((a, b)=>TRANSFER_WARNING_CLASSES.indexOf(a.class) - TRANSFER_WARNING_CLASSES.indexOf(b.class));
247
+ return {
248
+ plan: {
249
+ rows: planned,
250
+ summary: summaryOf(planned),
251
+ warnings,
252
+ acknowledgementsRequired: warnings.filter((entry)=>entry.requiresAcknowledgement).map((entry)=>entry.class)
253
+ },
254
+ counts
255
+ };
256
+ }
257
+
258
+ //# sourceMappingURL=customer-consent-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/transfer/customer-consent-plan.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 {\n TRANSFER_FILE_SAMPLE_ROW,\n TRANSFER_WARNING_CLASSES,\n type PlannedTransferRow,\n type TransferFieldChange,\n type TransferPlan,\n type TransferPlanRow,\n type TransferPlanSummary,\n type TransferWarning,\n type TransferWarningSample,\n} from '@aglyn/aglyn/data-transfer'\nimport {\n CUSTOMER_FIELD as C,\n CUSTOMER_FILE_SOURCE_NAMES,\n CUSTOMER_SOURCE_ONLY_FIELDS,\n MARKETING_CONSENT_FIELD_ID,\n readMarketingChoice,\n type CustomerFileSource,\n} from './customer-sources'\n\n/*==========================================\n * A STORE FILE'S MARKETING CHOICES, PLANNED (AGL-4245) — see the note of\n * `customer-sources.ts` for the rules. The server half: what each row's\n * choice comes to against the contact it matched, as a row change the apply\n * reads back, and the dry run's count of it.\n *=========================================*/\n\n\n/** What the apply does with one row's choice, as the plan stamped it. */\nexport interface ImportedConsentDetail {\n action: 'grant' | 'decline'\n /** Who planned the import: the member who answered the Permission step. */\n by: string | null\n /** Whether that member confirmed these people agreed to hear from this business. */\n attested: boolean\n jobId: string | null\n /** The store the file came from, or `file` for one the import does not recognize. */\n source: CustomerFileSource | 'file'\n}\n\n/** A row's change to `marketingConsent`, carrying {@link ImportedConsentDetail}. */\nexport type ImportedConsentChange = TransferFieldChange & { consent: ImportedConsentDetail }\n\n/** The consent change a planned row carries, if any. */\nexport function importedConsentChange(row: Pick<PlannedTransferRow, 'diff'>): ImportedConsentChange | null {\n const change = row.diff.find((entry) => entry.fieldId === MARKETING_CONSENT_FIELD_ID) as\n | Partial<ImportedConsentChange>\n | undefined\n const detail = change?.consent\n if (!change || !detail || (detail.action !== 'grant' && detail.action !== 'decline')) return null\n return change as ImportedConsentChange\n}\n\n/** The rows with every import-only value taken out, for the core's plan. */\nexport function withoutCustomerSourceFields(rows: readonly TransferPlanRow[]): TransferPlanRow[] {\n return rows.map((row) => {\n if (!CUSTOMER_SOURCE_ONLY_FIELDS.some((fieldId) => fieldId in row.values)) return row\n const values = { ...row.values }\n for (const fieldId of CUSTOMER_SOURCE_ONLY_FIELDS) delete values[fieldId]\n return { ...row, values }\n })\n}\n\n/** What the plan needs to know beside the rows. */\nexport interface ContactConsentPlanContext {\n /** The site the consent is recorded for; `null` for an import with no Source site. */\n hostId: string | null\n /** The Permission step's statement. */\n attested: boolean\n /** The member planning the import. */\n recordedBy: string | null\n jobId: string | null\n source: CustomerFileSource | null\n /** Addresses the site's unsubscribe list holds, lowercased. */\n suppressed: ReadonlySet<string>\n}\n\n/** What the file's choices come to, counted for the dry run. */\nexport interface ContactConsentCounts {\n optedIn: number\n unsubscribes: number\n /** Of the unsubscribes, people who were subscribed here. */\n unsubscribedFromSubscribed: number\n noConsent: number\n alreadySame: number\n notConfirmed: number\n keptUnsubscribed: number\n noSite: number\n noEmail: number\n unread: number\n unreadSample: string | null\n}\n\nconst emptyCounts = (): ContactConsentCounts => ({\n optedIn: 0,\n unsubscribes: 0,\n unsubscribedFromSubscribed: 0,\n noConsent: 0,\n alreadySame: 0,\n notConfirmed: 0,\n keptUnsubscribed: 0,\n noSite: 0,\n noEmail: 0,\n unread: 0,\n unreadSample: null,\n})\n\nconst lower = (value: unknown) => (value === null || value === undefined ? '' : String(value).trim().toLowerCase())\n\n/** Whether any row carries the column. */\nconst carries = (rows: readonly TransferPlanRow[], fieldId: string) => rows.some((row) => fieldId in row.values)\n\n/** The address a row is about: the file's, else the matched contact's. */\nexport function consentRowEmail(\n row: TransferPlanRow | undefined,\n planned: PlannedTransferRow,\n existing: ReadonlyMap<string, Readonly<Record<string, unknown>>>,\n): string {\n const before = planned.recordId ? existing.get(planned.recordId) : undefined\n return lower(row?.values['email']) || lower(before?.['email'])\n}\n\n/** The addresses whose file opt-in the plan may carry, for the unsubscribe-list read. */\nexport function consentOptInEmails(\n plan: Pick<TransferPlan, 'rows'>,\n rows: readonly TransferPlanRow[],\n existing: ReadonlyMap<string, Readonly<Record<string, unknown>>>,\n): string[] {\n const byIndex = new Map(rows.map((row) => [row.index, row]))\n const out = new Set<string>()\n for (const planned of plan.rows) {\n const row = byIndex.get(planned.index)\n if (!row || readMarketingChoice(row.values[C.emailMarketing]).choice !== 'optIn') continue\n const email = consentRowEmail(row, planned, existing)\n if (email) out.add(email)\n }\n return [...out]\n}\n\nconst n = (count: number) => count.toLocaleString('en-US')\nconst people = (count: number) => `${n(count)} ${count === 1 ? 'person' : 'people'}`\n\n/** The dry run's lines about the file's marketing choices and what is not kept. */\nexport function contactConsentSamples(\n counts: ContactConsentCounts | null,\n notes: { sms: boolean; spend: boolean },\n ctx: Pick<ContactConsentPlanContext, 'source'>,\n): TransferWarningSample[] {\n const where = ctx.source ? `your ${CUSTOMER_FILE_SOURCE_NAMES[ctx.source]} file` : 'the file'\n const line = (fieldId: string, value: number | string, detail: string): TransferWarningSample => ({\n row: TRANSFER_FILE_SAMPLE_ROW,\n fieldId,\n value: typeof value === 'number' ? n(value) : value,\n detail,\n })\n const samples: TransferWarningSample[] = []\n const F = C.emailMarketing\n if (counts) {\n samples.push(\n line(\n F,\n counts.optedIn,\n counts.optedIn\n ? `${people(counts.optedIn)} will be opted in to marketing email, as ${where} records and as you confirmed they agreed to hear from you.`\n : 'Nobody will be opted in to marketing email from this file.',\n ),\n line(\n F,\n counts.unsubscribes,\n counts.unsubscribes\n ? `${n(counts.unsubscribes)} ${counts.unsubscribes === 1 ? 'unsubscribe' : 'unsubscribes'} from ${where} will be kept` +\n (counts.unsubscribedFromSubscribed\n ? `, and ${people(counts.unsubscribedFromSubscribed)} subscribed here will be unsubscribed.`\n : '.') +\n ' Undoing the import keeps these unsubscribes, because they are each person’s own choice.'\n : 'No unsubscribes in this file change anything here.',\n ),\n line(\n F,\n counts.noConsent,\n `${people(counts.noConsent)} ${counts.noConsent === 1 ? 'has' : 'have'} no marketing choice recorded, and nothing about their marketing email changes.`,\n ),\n )\n if (counts.notConfirmed) {\n samples.push(\n line(\n F,\n counts.notConfirmed,\n `${people(counts.notConfirmed)} said yes in ${where} but will not be opted in, because you did not confirm on the Permission step that they agreed to hear from you.`,\n ),\n )\n }\n if (counts.keptUnsubscribed) {\n samples.push(\n line(\n F,\n counts.keptUnsubscribed,\n `${people(counts.keptUnsubscribed)} said yes in ${where} but unsubscribed here, so they stay unsubscribed.`,\n ),\n )\n }\n if (counts.noSite) {\n samples.push(\n line(\n F,\n counts.noSite,\n `${people(counts.noSite)} said yes in ${where} but will not be opted in, because the import names no site. Import under the site they signed up on to bring opt-ins in.`,\n ),\n )\n }\n if (counts.alreadySame) {\n samples.push(line(F, counts.alreadySame, `${people(counts.alreadySame)} already ${counts.alreadySame === 1 ? 'has' : 'have'} the same choice recorded here.`))\n }\n if (counts.noEmail) {\n samples.push(\n line(F, counts.noEmail, `${people(counts.noEmail)} ${counts.noEmail === 1 ? 'has' : 'have'} a marketing choice but no email address, so it is not kept.`),\n )\n }\n if (counts.unread) {\n samples.push(\n line(\n F,\n counts.unreadSample ?? n(counts.unread),\n `${n(counts.unread)} marketing ${counts.unread === 1 ? 'value' : 'values'} could not be read, and count as no choice.`,\n ),\n )\n }\n }\n if (notes.sms) {\n samples.push(\n line(C.smsMarketing, '', 'The text message marketing column is not kept: marketing texts are not sent from here, so nobody is opted in to them.'),\n )\n }\n if (notes.spend) {\n samples.push(\n line(C.totalSpent, '', 'Total spent and order counts from your old store are not kept. A contact’s spend counts what they buy on your site.'),\n )\n }\n return samples\n}\n\n/** The summary of `rows`, counted again. */\nfunction summaryOf(rows: readonly PlannedTransferRow[]): TransferPlanSummary {\n const summary: TransferPlanSummary = { create: 0, update: 0, unchanged: 0, skip: 0, fail: 0, total: rows.length }\n for (const row of rows) summary[row.verdict] += 1\n return summary\n}\n\n/**\n * The plan with the file's marketing choices carried (see the module note):\n * each opt-in it may carry and each opt-out that changes something becomes a\n * `marketingConsent` change on its row — an otherwise unchanged row becomes\n * an update — and the dry run gains one `screening` warning counting what\n * happens and what is not kept. A file with none of the columns is returned\n * as it came.\n *\n * `rows` are the rows as the file read them, import-only values included;\n * `existing` holds each matched contact's values, `marketingConsent` read\n * for the import's site (`true`, `false` or `null`).\n */\nexport function planContactConsent(\n plan: TransferPlan,\n rows: readonly TransferPlanRow[],\n existing: ReadonlyMap<string, Readonly<Record<string, unknown>>>,\n ctx: ContactConsentPlanContext,\n): { plan: TransferPlan; counts: ContactConsentCounts | null } {\n const notes = { sms: carries(rows, C.smsMarketing), spend: carries(rows, C.totalSpent) || carries(rows, C.orderCount) }\n const mapped = carries(rows, C.emailMarketing)\n if (!mapped && !notes.sms && !notes.spend) return { plan, counts: null }\n\n const counts = mapped ? emptyCounts() : null\n const byIndex = new Map(rows.map((row) => [row.index, row]))\n const planned = plan.rows.map((plannedRow): PlannedTransferRow => {\n if (!counts) return plannedRow\n if (plannedRow.verdict !== 'create' && plannedRow.verdict !== 'update' && plannedRow.verdict !== 'unchanged') {\n return plannedRow\n }\n const row = byIndex.get(plannedRow.index)\n const raw = row?.values[C.emailMarketing]\n const { choice, read } = readMarketingChoice(raw)\n if (!read) {\n counts.unread += 1\n counts.unreadSample ??= String(raw ?? '').slice(0, 40)\n }\n const email = consentRowEmail(row, plannedRow, existing)\n const before = plannedRow.recordId ? existing.get(plannedRow.recordId)?.[MARKETING_CONSENT_FIELD_ID] : null\n const stored = before === true ? true : before === false ? false : null\n if (choice === 'none') {\n counts.noConsent += 1\n return plannedRow\n }\n if (!email) {\n counts.noEmail += 1\n return plannedRow\n }\n let action: ImportedConsentDetail['action'] | null = null\n if (choice === 'optOut') {\n if (stored === false) counts.alreadySame += 1\n else {\n action = 'decline'\n counts.unsubscribes += 1\n if (stored === true) counts.unsubscribedFromSubscribed += 1\n }\n } else if (!ctx.hostId) counts.noSite += 1\n else if (stored === false || ctx.suppressed.has(email)) counts.keptUnsubscribed += 1\n else if (stored === true) counts.alreadySame += 1\n else if (!ctx.attested) counts.notConfirmed += 1\n else {\n action = 'grant'\n counts.optedIn += 1\n }\n if (!action) return plannedRow\n const change: ImportedConsentChange = {\n fieldId: MARKETING_CONSENT_FIELD_ID,\n before: stored,\n after: action === 'grant',\n mode: 'overwrite',\n source: 'locked',\n rule: 'written',\n consent: {\n action,\n by: ctx.recordedBy,\n attested: ctx.attested,\n jobId: ctx.jobId,\n source: ctx.source ?? 'file',\n },\n }\n return {\n ...plannedRow,\n verdict: plannedRow.verdict === 'unchanged' ? 'update' : plannedRow.verdict,\n diff: [...plannedRow.diff.filter((entry) => entry.fieldId !== MARKETING_CONSENT_FIELD_ID), change],\n }\n })\n\n const samples = contactConsentSamples(counts, notes, ctx)\n const warning: TransferWarning = {\n class: 'screening',\n count: samples.length,\n rows: 0,\n fieldIds: [...new Set(samples.map((sample) => sample.fieldId).filter((id): id is string => Boolean(id)))],\n samples,\n requiresAcknowledgement: true,\n }\n const prior = plan.warnings.find((entry) => entry.class === 'screening')\n const warnings = prior\n ? plan.warnings.map((entry) =>\n entry === prior\n ? {\n ...prior,\n count: prior.count + warning.count,\n fieldIds: [...new Set([...prior.fieldIds, ...warning.fieldIds])],\n samples: [...prior.samples, ...samples],\n requiresAcknowledgement: true,\n }\n : entry,\n )\n : [...plan.warnings, warning]\n // The core's order of classes, kept.\n warnings.sort((a, b) => TRANSFER_WARNING_CLASSES.indexOf(a.class) - TRANSFER_WARNING_CLASSES.indexOf(b.class))\n return {\n plan: {\n rows: planned,\n summary: summaryOf(planned),\n warnings,\n acknowledgementsRequired: warnings.filter((entry) => entry.requiresAcknowledgement).map((entry) => entry.class),\n },\n counts,\n }\n}\n"],"names":["TRANSFER_FILE_SAMPLE_ROW","TRANSFER_WARNING_CLASSES","CUSTOMER_FIELD","C","CUSTOMER_FILE_SOURCE_NAMES","CUSTOMER_SOURCE_ONLY_FIELDS","MARKETING_CONSENT_FIELD_ID","readMarketingChoice","importedConsentChange","row","change","diff","find","entry","fieldId","detail","consent","action","withoutCustomerSourceFields","rows","map","some","values","emptyCounts","optedIn","unsubscribes","unsubscribedFromSubscribed","noConsent","alreadySame","notConfirmed","keptUnsubscribed","noSite","noEmail","unread","unreadSample","lower","value","undefined","String","trim","toLowerCase","carries","consentRowEmail","planned","existing","before","recordId","get","consentOptInEmails","plan","byIndex","Map","index","out","Set","emailMarketing","choice","email","add","n","count","toLocaleString","people","contactConsentSamples","counts","notes","ctx","where","source","line","samples","F","push","sms","smsMarketing","spend","totalSpent","summaryOf","summary","create","update","unchanged","skip","fail","total","length","verdict","planContactConsent","orderCount","mapped","plannedRow","raw","read","slice","stored","hostId","suppressed","has","attested","after","mode","rule","by","recordedBy","jobId","filter","warning","class","fieldIds","sample","id","Boolean","requiresAcknowledgement","prior","warnings","sort","a","b","indexOf","acknowledgementsRequired"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,wBAAwB,QAQnB,6BAA4B;AACnC,SACEC,kBAAkBC,CAAC,EACnBC,0BAA0B,EAC1BC,2BAA2B,EAC3BC,0BAA0B,EAC1BC,mBAAmB,QAEd,wBAAoB;AAyB3B,sDAAsD,GACtD,OAAO,SAASC,sBAAsBC,GAAqC;IACzE,MAAMC,SAASD,IAAIE,IAAI,CAACC,IAAI,CAAC,CAACC,QAAUA,MAAMC,OAAO,KAAKR;IAG1D,MAAMS,SAASL,0BAAAA,OAAQM,OAAO;IAC9B,IAAI,CAACN,UAAU,CAACK,UAAWA,OAAOE,MAAM,KAAK,WAAWF,OAAOE,MAAM,KAAK,WAAY,OAAO;IAC7F,OAAOP;AACT;AAEA,0EAA0E,GAC1E,OAAO,SAASQ,4BAA4BC,IAAgC;IAC1E,OAAOA,KAAKC,GAAG,CAAC,CAACX;QACf,IAAI,CAACJ,4BAA4BgB,IAAI,CAAC,CAACP,UAAYA,WAAWL,IAAIa,MAAM,GAAG,OAAOb;QAClF,MAAMa,SAAS,aAAKb,IAAIa,MAAM;QAC9B,KAAK,MAAMR,WAAWT,4BAA6B,OAAOiB,MAAM,CAACR,QAAQ;QACzE,OAAO,aAAKL;YAAKa;;IACnB;AACF;AAgCA,MAAMC,cAAc,IAA6B,CAAA;QAC/CC,SAAS;QACTC,cAAc;QACdC,4BAA4B;QAC5BC,WAAW;QACXC,aAAa;QACbC,cAAc;QACdC,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;IACrCQ,SAASC,IAAI,CAAC,CAACC,GAAGC,IAAMpH,yBAAyBqH,OAAO,CAACF,EAAET,KAAK,IAAI1G,yBAAyBqH,OAAO,CAACD,EAAEV,KAAK;IAC5G,OAAO;QACL1D,MAAM;YACJ9B,MAAMwB;YACNmC,SAASD,UAAUlC;YACnBuE;YACAK,0BAA0BL,SAAST,MAAM,CAAC,CAAC5F,QAAUA,MAAMmG,uBAAuB,EAAE5F,GAAG,CAAC,CAACP,QAAUA,MAAM8F,KAAK;QAChH;QACA3C;IACF;AACF"}
@@ -0,0 +1,68 @@
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, TransferField, TransferFieldGroup } from '@aglyn/aglyn/data-transfer';
18
+ /** The field ids this module reads; the import-only ones are never stored. */
19
+ export declare const CUSTOMER_FIELD: {
20
+ readonly emailMarketing: "emailMarketingChoice";
21
+ readonly smsMarketing: "smsMarketingChoice";
22
+ readonly totalSpent: "oldStoreTotalSpent";
23
+ readonly orderCount: "oldStoreOrderCount";
24
+ readonly customerId: "oldStoreCustomerId";
25
+ };
26
+ /** The contact field a carried choice changes. */
27
+ export declare const MARKETING_CONSENT_FIELD_ID = "marketingConsent";
28
+ /** The fields that exist only to read another platform's file; never stored, never exported. */
29
+ export declare const CUSTOMER_SOURCE_ONLY_FIELDS: readonly string[];
30
+ /** The picker group the import-only fields are listed under. */
31
+ export declare const CUSTOMER_SWITCHING_GROUP: TransferFieldGroup;
32
+ /** The import-only fields, as the Columns step offers them. */
33
+ export declare const CUSTOMER_SOURCE_FIELDS: readonly TransferField[];
34
+ /**
35
+ * Shopify's customers CSV, by the field each column means: today's
36
+ * `Default Address …` columns and the older file's bare ones. Its address
37
+ * phone is the contact's other phone; its `Phone` is their phone.
38
+ */
39
+ export declare const SHOPIFY_CUSTOMER_COLUMNS: Readonly<Record<string, readonly string[]>>;
40
+ /** Wix's contacts CSV: two emails and phones (the first is the person's), two addresses, labels. */
41
+ export declare const WIX_CONTACT_COLUMNS: Readonly<Record<string, readonly string[]>>;
42
+ /** Squarespace's customers CSV: the shipping address is the mailing one, billing the other. */
43
+ export declare const SQUARESPACE_CUSTOMER_COLUMNS: Readonly<Record<string, readonly string[]>>;
44
+ /** The three dictionaries, beside the CRMs' own (`aliases.ts`). */
45
+ export declare const CUSTOMER_ALIAS_DICTIONARIES: readonly TransferAliasDictionary[];
46
+ /** Which store's customer file this is. */
47
+ export type CustomerFileSource = 'shopify' | 'wix' | 'squarespace';
48
+ /** Each store's name, as the dry run and the consent record say it. */
49
+ export declare const CUSTOMER_FILE_SOURCE_NAMES: Readonly<Record<CustomerFileSource, string>>;
50
+ /**
51
+ * The store a file came from, by its header signature, or `null` for any
52
+ * other file: Shopify's `Accepts Email Marketing` or `Default Address …`
53
+ * columns (or the older `Accepts Marketing` beside `Total Orders`); Wix's
54
+ * `Email 1` beside its subscriber status or numbered addresses;
55
+ * Squarespace's `Accepts Marketing` beside its shipping or billing columns.
56
+ */
57
+ export declare function customerFileSource(headers: readonly string[] | undefined): CustomerFileSource | null;
58
+ /** A marketing cell as a choice: the platform's reader, shared with the email list import. */
59
+ export { readMarketingChoice, type MarketingChoice } from '@aglyn/aglyn/app-utils/marketing-choice';
60
+ /** The CRM contact import's own wizard step: the statement of permission. */
61
+ export declare const CONTACT_CONSENT_STEP_ID = "crm-consent";
62
+ /** The answer of the {@link CONTACT_CONSENT_STEP_ID} step. */
63
+ export interface ContactConsentAnswer {
64
+ /** The person importing states that the people the file opts in agreed to hear from this business. */
65
+ attest: boolean;
66
+ }
67
+ /** The answer in `extras`. Anything but a literal `true` is no statement at all. */
68
+ export declare function readContactConsentAnswer(extras: Readonly<Record<string, unknown>> | undefined): ContactConsentAnswer;