@aglyn/plugins-marketing 1.19.0 → 1.20.0
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 +16 -16
- package/src/lib/components/campaign-detail-card.js +38 -13
- package/src/lib/components/campaign-detail-card.js.map +1 -1
- package/src/lib/components/campaign-edit-drawer.d.ts +11 -4
- package/src/lib/components/campaign-edit-drawer.js +57 -54
- package/src/lib/components/campaign-edit-drawer.js.map +1 -1
- package/src/lib/components/campaign-sharing-form-field.d.ts +14 -0
- package/src/lib/components/campaign-sharing-form-field.js +69 -0
- package/src/lib/components/campaign-sharing-form-field.js.map +1 -0
- package/src/lib/components/campaigns-card.js +91 -27
- package/src/lib/components/campaigns-card.js.map +1 -1
- package/src/lib/components/use-campaign-containers-blocked.d.ts +15 -1
- package/src/lib/components/use-campaign-containers-blocked.js +25 -4
- package/src/lib/components/use-campaign-containers-blocked.js.map +1 -1
- package/src/lib/model/campaign-container.d.ts +73 -7
- package/src/lib/model/campaign-container.js +121 -12
- package/src/lib/model/campaign-container.js.map +1 -1
- package/src/lib/server/campaign-manage.d.ts +5 -3
- package/src/lib/server/campaign-manage.js +111 -25
- package/src/lib/server/campaign-manage.js.map +1 -1
- package/src/lib/transfer/campaigns-package.server.js +10 -1
- package/src/lib/transfer/campaigns-package.server.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/transfer/campaigns-package.server.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\n/*==========================================\n * CAMPAIGNS IN A WORKSPACE PACKAGE — the server half (AGL-3535).\n *\n * The container is written with the fields the campaigns hub's create\n * drawer writes (its search fields, its placement), and each email the\n * way the campaign draft writer writes one (`createCampaignDraftWriter`):\n * `status: 'draft'`, sent as its site, naming a design that is a live\n * email screen there, and holding nothing a send needs a person to decide.\n * The scheduled processor only ever reads `status == 'scheduled'`, which no\n * import writes. One transaction per campaign: the container and its\n * drafts land together or not at all.\n *\n * Undo deletes an imported campaign only while every email in it is still\n * a draft; one that has started sending is the workspace's record of what\n * it sent, and stays.\n *=========================================*/\n\nimport { SCREEN_KIND_EMAIL } from '@aglyn/aglyn/app-utils/screen-route'\nimport { DECLARED_SUBSCRIPTION_TOPICS } from '@aglyn/aglyn/app-utils/subscription-topics'\nimport {\n existingPackageItemsOf,\n type ExistingPackageItem,\n type TransferReferenceKind,\n type TransferRowResult,\n} from '@aglyn/aglyn/data-transfer'\nimport type {\n TransferApplyResult,\n TransferApplyWriter,\n TransferPackageItemContent,\n TransferPackageItemWrite,\n TransferPackageRevertResult,\n TransferPackageRevertStep,\n TransferResourceContext,\n} from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport firebaseAdmin from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { CAMPAIGN_SEND_CONTAINER_FIELD } from '../model/campaign-container'\nimport { campaignContainerSearchFields, campaignSendSearchFields } from '../model/campaign-list-query'\nimport { campaignDraftEmailId } from '../server/campaign-manage'\nimport { campaignSendSiteStamp, orgCampaignSends, orgEmailCampaigns } from '../server/campaign-org-refs'\nimport {\n CAMPAIGN_REFERENCE_KINDS,\n CAMPAIGNS_TRANSFER_KEY,\n campaignPackageContent,\n draftableCampaignEmails,\n type CampaignPackageContent,\n} from './campaigns-package'\n\ntype Firestore = FirebaseFirestore.Firestore\n\nexport interface CampaignsPackageDeps {\n firestore(): Firestore\n now(): number\n}\n\nfunction defaultDeps(): CampaignsPackageDeps {\n return { firestore: () => firebaseAdmin.app().firestore() as unknown as Firestore, now: Date.now }\n}\n\n/** The id of a campaign's `n`th imported email: the draft writer's for the first, numbered after it. */\nfunction importedEmailId(campaignId: string, index: number): string {\n return index === 0 ? campaignDraftEmailId(campaignId) : `${campaignDraftEmailId(campaignId)}-${index + 1}`\n}\n\n/** The container's fields a person planned, as the create drawer stores them. */\nfunction containerFields(content: CampaignPackageContent) {\n return {\n name: content.name,\n ...campaignContainerSearchFields(content.name),\n startAtMs: content.startAtMs,\n endAtMs: content.endAtMs,\n listIds: [...content.listIds],\n topicId: content.topicId,\n visibleTo: [...content.visibleTo],\n listUnsubscribe: content.listUnsubscribe,\n }\n}\n\nasync function readAll(\n deps: CampaignsPackageDeps,\n orgId: string,\n ids?: readonly string[],\n): Promise<Array<TransferPackageItemContent<CampaignPackageContent>>> {\n const firestore = deps.firestore()\n const containers = orgEmailCampaigns(firestore, orgId)\n const docs = ids\n ? (await Promise.all(ids.map((campaignId) => containers.doc(campaignId).get()))).filter((doc) => doc.exists)\n : (await containers.get()).docs\n const items: Array<TransferPackageItemContent<CampaignPackageContent>> = []\n for (const doc of docs) {\n if (doc.get('deletedAt')) continue\n const sends = await orgCampaignSends(firestore, orgId).where(CAMPAIGN_SEND_CONTAINER_FIELD, '==', doc.id).get()\n const emails = sends.docs\n .map((send) => send.data())\n .sort((a, b) => Number(a['createdAtMs'] ?? 0) - Number(b['createdAtMs'] ?? 0))\n const content = campaignPackageContent(doc.data(), emails)\n items.push({ kind: CAMPAIGNS_TRANSFER_KEY, id: doc.id, name: content.name, content })\n }\n return items\n}\n\n/** Why one campaign cannot be written as it stands, each a sentence. */\nasync function campaignProblems(firestore: Firestore, orgId: string, content: CampaignPackageContent): Promise<string[]> {\n const problems: string[] = []\n if (!content.name) problems.push('Name the campaign.')\n if (!content.visibleTo.length) problems.push('Choose the sites the campaign is placed on.')\n for (const email of draftableCampaignEmails(content)) {\n const host = await firestore.collection('hosts').doc(email.hostId).get()\n if (!host.exists || host.get('orgId') !== orgId) {\n problems.push(`“${email.subject || 'An email'}” sends as a site that is not in this organization.`)\n continue\n }\n const design = await host.ref.collection('screens').doc(email.templateScreenId).get()\n if (!design.exists || design.get('deletedAt') != null || design.get('kind') !== SCREEN_KIND_EMAIL) {\n problems.push(`“${email.subject || 'An email'}” sends an email design that site does not have.`)\n }\n }\n return problems\n}\n\nexport function createCampaignsPackage(deps: CampaignsPackageDeps = defaultDeps()) {\n return {\n async items(ctx: TransferResourceContext): Promise<ExistingPackageItem[]> {\n return existingPackageItemsOf(CAMPAIGNS_TRANSFER_KEY, await readAll(deps, ctx.orgId))\n },\n\n async readItems(ctx: TransferResourceContext, ids: readonly string[]) {\n return readAll(deps, ctx.orgId, ids)\n },\n\n async problems(ctx: TransferResourceContext, write: TransferPackageItemWrite<CampaignPackageContent>) {\n const content = campaignPackageContent(write.content)\n return campaignProblems(deps.firestore(), ctx.orgId, { ...content, name: write.rename?.name ?? content.name })\n },\n\n async referenceTargets(ctx: TransferResourceContext, kinds: readonly string[]): Promise<TransferReferenceKind[]> {\n const firestore = deps.firestore()\n const org = firestore.collection('orgs').doc(ctx.orgId)\n const named = async (collection: string) =>\n (await org.collection(collection).get()).docs\n .filter((doc) => !doc.get('deletedAt'))\n .map((doc) => {\n const name = String(doc.get('name') ?? doc.get('label') ?? '').trim()\n return { id: doc.id, ...(name ? { name } : {}) }\n })\n const answers: TransferReferenceKind[] = []\n if (kinds.includes(CAMPAIGN_REFERENCE_KINDS.list)) {\n answers.push({ kind: CAMPAIGN_REFERENCE_KINDS.list, label: 'Email list', targets: await named('lists') })\n }\n if (kinds.includes(CAMPAIGN_REFERENCE_KINDS.topic)) {\n /*\n * Asked only when the email plugin — which owns the topic catalog and\n * answers `email.topics` as package items (AGL-3550) — is not running\n * here. Without it nobody can author a topic, so the catalog is the\n * built-ins the plugins declare.\n */\n answers.push({\n kind: CAMPAIGN_REFERENCE_KINDS.topic,\n label: 'Subscription topic',\n targets: DECLARED_SUBSCRIPTION_TOPICS.map((topic) => ({ id: topic.id, name: topic.name })),\n })\n }\n if (kinds.includes(CAMPAIGN_REFERENCE_KINDS.design)) {\n const hosts = await firestore.collection('hosts').where('orgId', '==', ctx.orgId).get()\n const targets: TransferReferenceKind['targets'] = []\n for (const host of hosts.docs) {\n const screens = await host.ref.collection('screens').where('kind', '==', SCREEN_KIND_EMAIL).get()\n for (const screen of screens.docs) {\n if (screen.get('deletedAt') != null) continue\n const title = String(screen.get('name') ?? screen.get('title') ?? screen.id)\n targets.push({ id: screen.id, name: `${title} (${String(host.get('name') ?? host.id)})` })\n }\n }\n answers.push({ kind: CAMPAIGN_REFERENCE_KINDS.design, label: 'Email design', targets })\n }\n return answers\n },\n\n async writeItems(\n ctx: TransferResourceContext,\n items: ReadonlyArray<TransferPackageItemWrite<CampaignPackageContent>>,\n writer: TransferApplyWriter,\n ): Promise<TransferApplyResult> {\n const firestore = deps.firestore()\n const actor = ctx.actorUid ?? ''\n const results: TransferRowResult[] = []\n for (const write of items) {\n const before = await writer.alreadyApplied(write.row)\n if (before) {\n results.push(before)\n continue\n }\n const incoming = campaignPackageContent(write.content)\n const content = { ...incoming, name: write.rename?.name ?? incoming.name }\n const problems = await campaignProblems(firestore, ctx.orgId, content)\n let result: TransferRowResult\n if (problems.length) {\n result = { row: write.row, outcome: 'failed', message: problems.join(' ') }\n } else {\n const nowMs = deps.now()\n const containerRef = orgEmailCampaigns(firestore, ctx.orgId).doc(write.targetId)\n result = await firestore.runTransaction(async (transaction): Promise<TransferRowResult> => {\n const current = await transaction.get(containerRef)\n if (write.decision === 'replace') {\n if (!current.exists || current.get('deletedAt')) {\n return { row: write.row, outcome: 'failed', recordId: write.targetId, message: 'That campaign no longer exists.' }\n }\n transaction.update(containerRef, containerFields(content))\n return { row: write.row, outcome: 'updated', recordId: write.targetId }\n }\n if (current.exists) {\n return { row: write.row, outcome: 'failed', recordId: write.targetId, message: 'A campaign with this id already exists.' }\n }\n transaction.create(containerRef, { ...containerFields(content), createdAtMs: nowMs, createdBy: actor })\n draftableCampaignEmails(content).forEach((email, index) => {\n transaction.create(orgCampaignSends(firestore, ctx.orgId).doc(importedEmailId(write.targetId, index)), {\n subject: email.subject,\n ...campaignSendSearchFields(email.subject),\n ...(email.preheader ? { preheader: email.preheader } : {}),\n templateScreenId: email.templateScreenId,\n ...(email.subjectVariants.length ? { subjectVariants: email.subjectVariants } : {}),\n ...(email.preheaderVariants.length ? { preheaderVariants: email.preheaderVariants } : {}),\n [CAMPAIGN_SEND_CONTAINER_FIELD]: write.targetId,\n ...campaignSendSiteStamp(email.hostId),\n status: 'draft',\n // Oldest first, as the package lists them, so a re-export reads them back in order.\n createdAtMs: nowMs + index,\n draftedAt: new Date(nowMs),\n draftedBy: actor,\n })\n })\n return { row: write.row, outcome: 'created', recordId: write.targetId }\n })\n }\n await writer.markApplied(result)\n results.push(result)\n }\n return { results, undo: [] }\n },\n\n async revertItems(\n ctx: TransferResourceContext,\n steps: ReadonlyArray<TransferPackageRevertStep<CampaignPackageContent>>,\n ): Promise<TransferPackageRevertResult> {\n const firestore = deps.firestore()\n const outcome: TransferPackageRevertResult = { done: [], refused: [] }\n for (const step of steps) {\n const containerRef = orgEmailCampaigns(firestore, ctx.orgId).doc(step.id)\n if (step.action === 'restore') {\n await containerRef.update(containerFields(campaignPackageContent(step.content)))\n outcome.done.push(step.id)\n continue\n }\n const sends = await orgCampaignSends(firestore, ctx.orgId).where(CAMPAIGN_SEND_CONTAINER_FIELD, '==', step.id).get()\n if (sends.docs.some((send) => send.get('status') !== 'draft')) {\n outcome.refused.push({ id: step.id, reason: 'An email in this campaign has been scheduled or sent since, so the campaign stays.' })\n continue\n }\n const batch = firestore.batch()\n for (const send of sends.docs) batch.delete(send.ref)\n batch.delete(containerRef)\n await batch.commit()\n outcome.done.push(step.id)\n }\n return outcome\n },\n }\n}\n\n"],"names":["SCREEN_KIND_EMAIL","DECLARED_SUBSCRIPTION_TOPICS","existingPackageItemsOf","firebaseAdmin","CAMPAIGN_SEND_CONTAINER_FIELD","campaignContainerSearchFields","campaignSendSearchFields","campaignDraftEmailId","campaignSendSiteStamp","orgCampaignSends","orgEmailCampaigns","CAMPAIGN_REFERENCE_KINDS","CAMPAIGNS_TRANSFER_KEY","campaignPackageContent","draftableCampaignEmails","defaultDeps","firestore","app","now","Date","importedEmailId","campaignId","index","containerFields","content","name","startAtMs","endAtMs","listIds","topicId","visibleTo","listUnsubscribe","readAll","deps","orgId","ids","containers","docs","Promise","all","map","doc","get","filter","exists","items","sends","where","id","emails","send","data","sort","a","b","Number","push","kind","campaignProblems","problems","length","email","host","collection","hostId","subject","design","ref","templateScreenId","createCampaignsPackage","ctx","readItems","write","rename","referenceTargets","kinds","org","named","String","trim","answers","includes","list","label","targets","topic","hosts","screens","screen","title","writeItems","writer","actor","actorUid","results","before","alreadyApplied","row","incoming","result","outcome","message","join","nowMs","containerRef","targetId","runTransaction","transaction","current","decision","recordId","update","create","createdAtMs","createdBy","forEach","preheader","subjectVariants","preheaderVariants","status","draftedAt","draftedBy","markApplied","undo","revertItems","steps","done","refused","step","action","some","reason","batch","delete","commit"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;2CAe2C,GAE3C,SAASA,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,4BAA4B,QAAQ,6CAA4C;AACzF,SACEC,sBAAsB,QAIjB,6BAA4B;AAUnC,OAAOC,mBAAmB,iDAAgD;AAC1E,SAASC,6BAA6B,QAAQ,iCAA6B;AAC3E,SAASC,6BAA6B,EAAEC,wBAAwB,QAAQ,kCAA8B;AACtG,SAASC,oBAAoB,QAAQ,+BAA2B;AAChE,SAASC,qBAAqB,EAAEC,gBAAgB,EAAEC,iBAAiB,QAAQ,iCAA6B;AACxG,SACEC,wBAAwB,EACxBC,sBAAsB,EACtBC,sBAAsB,EACtBC,uBAAuB,QAElB,yBAAqB;AAS5B,SAASC;IACP,OAAO;QAAEC,WAAW,IAAMb,cAAcc,GAAG,GAAGD,SAAS;QAA4BE,KAAKC,KAA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AAM;gBAClBlC,QAAQ0B,IAAI,CAACtE,IAAI,CAACwE,KAAKhF,EAAE;YAC3B;YACA,OAAOoD;QACT;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/transfer/campaigns-package.server.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\n/*==========================================\n * CAMPAIGNS IN A WORKSPACE PACKAGE — the server half (AGL-3535).\n *\n * The container is written with the fields the campaigns hub's create\n * drawer writes (its search fields, its placement), and each email the\n * way the campaign draft writer writes one (`createCampaignDraftWriter`):\n * `status: 'draft'`, sent as its site, naming a design that is a live\n * email screen there, and holding nothing a send needs a person to decide.\n * The scheduled processor only ever reads `status == 'scheduled'`, which no\n * import writes. One transaction per campaign: the container and its\n * drafts land together or not at all.\n *\n * Undo deletes an imported campaign only while every email in it is still\n * a draft; one that has started sending is the workspace's record of what\n * it sent, and stays.\n *=========================================*/\n\nimport { SCREEN_KIND_EMAIL } from '@aglyn/aglyn/app-utils/screen-route'\nimport { DECLARED_SUBSCRIPTION_TOPICS } from '@aglyn/aglyn/app-utils/subscription-topics'\nimport {\n existingPackageItemsOf,\n type ExistingPackageItem,\n type TransferReferenceKind,\n type TransferRowResult,\n} from '@aglyn/aglyn/data-transfer'\nimport type {\n TransferApplyResult,\n TransferApplyWriter,\n TransferPackageItemContent,\n TransferPackageItemWrite,\n TransferPackageRevertResult,\n TransferPackageRevertStep,\n TransferResourceContext,\n} from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport firebaseAdmin from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { CAMPAIGN_SEND_CONTAINER_FIELD } from '../model/campaign-container'\nimport { campaignContainerSearchFields, campaignSendSearchFields } from '../model/campaign-list-query'\nimport { campaignDraftEmailId } from '../server/campaign-manage'\nimport { campaignSendSiteStamp, orgCampaignSends, orgEmailCampaigns } from '../server/campaign-org-refs'\nimport {\n CAMPAIGN_REFERENCE_KINDS,\n CAMPAIGNS_TRANSFER_KEY,\n campaignPackageContent,\n draftableCampaignEmails,\n type CampaignPackageContent,\n} from './campaigns-package'\n\ntype Firestore = FirebaseFirestore.Firestore\n\nexport interface CampaignsPackageDeps {\n firestore(): Firestore\n now(): number\n}\n\nfunction defaultDeps(): CampaignsPackageDeps {\n return { firestore: () => firebaseAdmin.app().firestore() as unknown as Firestore, now: Date.now }\n}\n\n/** The id of a campaign's `n`th imported email: the draft writer's for the first, numbered after it. */\nfunction importedEmailId(campaignId: string, index: number): string {\n return index === 0 ? campaignDraftEmailId(campaignId) : `${campaignDraftEmailId(campaignId)}-${index + 1}`\n}\n\n/** The container's fields a person planned, as the create drawer stores them. */\nfunction containerFields(content: CampaignPackageContent) {\n return {\n name: content.name,\n ...campaignContainerSearchFields(content.name),\n startAtMs: content.startAtMs,\n endAtMs: content.endAtMs,\n listIds: [...content.listIds],\n topicId: content.topicId,\n visibleTo: [...content.visibleTo],\n listUnsubscribe: content.listUnsubscribe,\n }\n}\n\nasync function readAll(\n deps: CampaignsPackageDeps,\n orgId: string,\n ids?: readonly string[],\n): Promise<Array<TransferPackageItemContent<CampaignPackageContent>>> {\n const firestore = deps.firestore()\n const containers = orgEmailCampaigns(firestore, orgId)\n const docs = ids\n ? (await Promise.all(ids.map((campaignId) => containers.doc(campaignId).get()))).filter((doc) => doc.exists)\n : (await containers.get()).docs\n const items: Array<TransferPackageItemContent<CampaignPackageContent>> = []\n for (const doc of docs) {\n if (doc.get('deletedAt')) continue\n const sends = await orgCampaignSends(firestore, orgId).where(CAMPAIGN_SEND_CONTAINER_FIELD, '==', doc.id).get()\n const emails = sends.docs\n .map((send) => send.data())\n .sort((a, b) => Number(a['createdAtMs'] ?? 0) - Number(b['createdAtMs'] ?? 0))\n const content = campaignPackageContent(doc.data(), emails)\n items.push({ kind: CAMPAIGNS_TRANSFER_KEY, id: doc.id, name: content.name, content })\n }\n return items\n}\n\n/** Why one campaign cannot be written as it stands, each a sentence. */\nasync function campaignProblems(firestore: Firestore, orgId: string, content: CampaignPackageContent): Promise<string[]> {\n const problems: string[] = []\n if (!content.name) problems.push('Name the campaign.')\n if (!content.visibleTo.length) problems.push('Choose the sites the campaign is placed on.')\n for (const email of draftableCampaignEmails(content)) {\n const host = await firestore.collection('hosts').doc(email.hostId).get()\n if (!host.exists || host.get('orgId') !== orgId) {\n problems.push(`“${email.subject || 'An email'}” sends as a site that is not in this organization.`)\n continue\n }\n const design = await host.ref.collection('screens').doc(email.templateScreenId).get()\n if (!design.exists || design.get('deletedAt') != null || design.get('kind') !== SCREEN_KIND_EMAIL) {\n problems.push(`“${email.subject || 'An email'}” sends an email design that site does not have.`)\n }\n }\n return problems\n}\n\nexport function createCampaignsPackage(deps: CampaignsPackageDeps = defaultDeps()) {\n return {\n async items(ctx: TransferResourceContext): Promise<ExistingPackageItem[]> {\n return existingPackageItemsOf(CAMPAIGNS_TRANSFER_KEY, await readAll(deps, ctx.orgId))\n },\n\n async readItems(ctx: TransferResourceContext, ids: readonly string[]) {\n return readAll(deps, ctx.orgId, ids)\n },\n\n async problems(ctx: TransferResourceContext, write: TransferPackageItemWrite<CampaignPackageContent>) {\n const content = campaignPackageContent(write.content)\n return campaignProblems(deps.firestore(), ctx.orgId, { ...content, name: write.rename?.name ?? content.name })\n },\n\n async referenceTargets(ctx: TransferResourceContext, kinds: readonly string[]): Promise<TransferReferenceKind[]> {\n const firestore = deps.firestore()\n const org = firestore.collection('orgs').doc(ctx.orgId)\n const named = async (collection: string) =>\n (await org.collection(collection).get()).docs\n .filter((doc) => !doc.get('deletedAt'))\n .map((doc) => {\n const name = String(doc.get('name') ?? doc.get('label') ?? '').trim()\n return { id: doc.id, ...(name ? { name } : {}) }\n })\n const answers: TransferReferenceKind[] = []\n if (kinds.includes(CAMPAIGN_REFERENCE_KINDS.list)) {\n answers.push({ kind: CAMPAIGN_REFERENCE_KINDS.list, label: 'Email list', targets: await named('lists') })\n }\n if (kinds.includes(CAMPAIGN_REFERENCE_KINDS.topic)) {\n /*\n * Asked only when the email plugin — which owns the topic catalog and\n * answers `email.topics` as package items (AGL-3550) — is not running\n * here. Without it nobody can author a topic, so the catalog is the\n * built-ins the plugins declare.\n */\n answers.push({\n kind: CAMPAIGN_REFERENCE_KINDS.topic,\n label: 'Subscription topic',\n targets: DECLARED_SUBSCRIPTION_TOPICS.map((topic) => ({ id: topic.id, name: topic.name })),\n })\n }\n if (kinds.includes(CAMPAIGN_REFERENCE_KINDS.design)) {\n const hosts = await firestore.collection('hosts').where('orgId', '==', ctx.orgId).get()\n const targets: TransferReferenceKind['targets'] = []\n for (const host of hosts.docs) {\n const screens = await host.ref.collection('screens').where('kind', '==', SCREEN_KIND_EMAIL).get()\n for (const screen of screens.docs) {\n if (screen.get('deletedAt') != null) continue\n const title = String(screen.get('name') ?? screen.get('title') ?? screen.id)\n targets.push({ id: screen.id, name: `${title} (${String(host.get('name') ?? host.id)})` })\n }\n }\n answers.push({ kind: CAMPAIGN_REFERENCE_KINDS.design, label: 'Email design', targets })\n }\n return answers\n },\n\n async writeItems(\n ctx: TransferResourceContext,\n items: ReadonlyArray<TransferPackageItemWrite<CampaignPackageContent>>,\n writer: TransferApplyWriter,\n ): Promise<TransferApplyResult> {\n const firestore = deps.firestore()\n const actor = ctx.actorUid ?? ''\n const results: TransferRowResult[] = []\n for (const write of items) {\n const before = await writer.alreadyApplied(write.row)\n if (before) {\n results.push(before)\n continue\n }\n const incoming = campaignPackageContent(write.content)\n const content = { ...incoming, name: write.rename?.name ?? incoming.name }\n const problems = await campaignProblems(firestore, ctx.orgId, content)\n let result: TransferRowResult\n if (problems.length) {\n result = { row: write.row, outcome: 'failed', message: problems.join(' ') }\n } else {\n const nowMs = deps.now()\n const containerRef = orgEmailCampaigns(firestore, ctx.orgId).doc(write.targetId)\n result = await firestore.runTransaction(async (transaction): Promise<TransferRowResult> => {\n const current = await transaction.get(containerRef)\n if (write.decision === 'replace') {\n if (!current.exists || current.get('deletedAt')) {\n return { row: write.row, outcome: 'failed', recordId: write.targetId, message: 'That campaign no longer exists.' }\n }\n /*\n * A package names the sites it places a campaign on, and never\n * carries the all-sites-except marker, so a replace places it on\n * those sites: the marker comes off, as a field delete, or the\n * sweep would widen it again to every site but the excluded\n * ones (AGL-4047).\n */\n transaction.update(containerRef, {\n ...containerFields(content),\n scopeMode: firebaseAdmin.firestore.FieldValue.delete(),\n scopeExcept: firebaseAdmin.firestore.FieldValue.delete(),\n })\n return { row: write.row, outcome: 'updated', recordId: write.targetId }\n }\n if (current.exists) {\n return { row: write.row, outcome: 'failed', recordId: write.targetId, message: 'A campaign with this id already exists.' }\n }\n transaction.create(containerRef, { ...containerFields(content), createdAtMs: nowMs, createdBy: actor })\n draftableCampaignEmails(content).forEach((email, index) => {\n transaction.create(orgCampaignSends(firestore, ctx.orgId).doc(importedEmailId(write.targetId, index)), {\n subject: email.subject,\n ...campaignSendSearchFields(email.subject),\n ...(email.preheader ? { preheader: email.preheader } : {}),\n templateScreenId: email.templateScreenId,\n ...(email.subjectVariants.length ? { subjectVariants: email.subjectVariants } : {}),\n ...(email.preheaderVariants.length ? { preheaderVariants: email.preheaderVariants } : {}),\n [CAMPAIGN_SEND_CONTAINER_FIELD]: write.targetId,\n ...campaignSendSiteStamp(email.hostId),\n status: 'draft',\n // Oldest first, as the package lists them, so a re-export reads them back in order.\n createdAtMs: nowMs + index,\n draftedAt: new Date(nowMs),\n draftedBy: actor,\n })\n })\n return { row: write.row, outcome: 'created', recordId: write.targetId }\n })\n }\n await writer.markApplied(result)\n results.push(result)\n }\n return { results, undo: [] }\n },\n\n async revertItems(\n ctx: TransferResourceContext,\n steps: ReadonlyArray<TransferPackageRevertStep<CampaignPackageContent>>,\n ): Promise<TransferPackageRevertResult> {\n const firestore = deps.firestore()\n const outcome: TransferPackageRevertResult = { done: [], refused: [] }\n for (const step of steps) {\n const containerRef = orgEmailCampaigns(firestore, ctx.orgId).doc(step.id)\n if (step.action === 'restore') {\n await containerRef.update(containerFields(campaignPackageContent(step.content)))\n outcome.done.push(step.id)\n continue\n }\n const sends = await orgCampaignSends(firestore, ctx.orgId).where(CAMPAIGN_SEND_CONTAINER_FIELD, '==', step.id).get()\n if (sends.docs.some((send) => send.get('status') !== 'draft')) {\n outcome.refused.push({ id: step.id, reason: 'An email in this campaign has been scheduled or sent since, so the campaign stays.' })\n continue\n }\n const batch = firestore.batch()\n for (const send of sends.docs) batch.delete(send.ref)\n batch.delete(containerRef)\n await batch.commit()\n outcome.done.push(step.id)\n }\n return outcome\n },\n }\n}\n\n"],"names":["SCREEN_KIND_EMAIL","DECLARED_SUBSCRIPTION_TOPICS","existingPackageItemsOf","firebaseAdmin","CAMPAIGN_SEND_CONTAINER_FIELD","campaignContainerSearchFields","campaignSendSearchFields","campaignDraftEmailId","campaignSendSiteStamp","orgCampaignSends","orgEmailCampaigns","CAMPAIGN_REFERENCE_KINDS","CAMPAIGNS_TRANSFER_KEY","campaignPackageContent","draftableCampaignEmails","defaultDeps","firestore","app","now","Date","importedEmailId","campaignId","index","containerFields","content","name","startAtMs","endAtMs","listIds","topicId","visibleTo","listUnsubscribe","readAll","deps","orgId","ids","containers","docs","Promise","all","map","doc","get","filter","exists","items","sends","where","id","emails","send","data","sort","a","b","Number","push","kind","campaignProblems","problems","length","email","host","collection","hostId","subject","design","ref","templateScreenId","createCampaignsPackage","ctx","readItems","write","rename","referenceTargets","kinds","org","named","String","trim","answers","includes","list","label","targets","topic","hosts","screens","screen","title","writeItems","writer","actor","actorUid","results","before","alreadyApplied","row","incoming","result","outcome","message","join","nowMs","containerRef","targetId","runTransaction","transaction","current","decision","recordId","update","scopeMode","FieldValue","delete","scopeExcept","create","createdAtMs","createdBy","forEach","preheader","subjectVariants","preheaderVariants","status","draftedAt","draftedBy","markApplied","undo","revertItems","steps","done","refused","step","action","some","reason","batch","commit"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;2CAe2C,GAE3C,SAASA,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,4BAA4B,QAAQ,6CAA4C;AACzF,SACEC,sBAAsB,QAIjB,6BAA4B;AAUnC,OAAOC,mBAAmB,iDAAgD;AAC1E,SAASC,6BAA6B,QAAQ,iCAA6B;AAC3E,SAASC,6BAA6B,EAAEC,wBAAwB,QAAQ,kCAA8B;AACtG,SAASC,oBAAoB,QAAQ,+BAA2B;AAChE,SAASC,qBAAqB,EAAEC,gBAAgB,EAAEC,iBAAiB,QAAQ,iCAA6B;AACxG,SACEC,wBAAwB,EACxBC,sBAAsB,EACtBC,sBAAsB,EACtBC,uBAAuB,QAElB,yBAAqB;AAS5B,SAASC;IACP,OAAO;QAAEC,WAAW,IAAMb,cAAcc,GAAG,GAAGD,SAAS;QAA4BE,KAAKC,KAAKD,GAAG;IAAC;AACnG;AAEA,sGAAsG,GACtG,SAASE,gBAAgBC,UAAkB,EAAEC,KAAa;IACxD,OAAOA,UAAU,IAAIf,qBAAqBc,cAAc,GAAGd,qBAAqBc,YAAY,CAAC,EAAEC,QAAQ,GAAG;AAC5G;AAEA,+EAA+E,GAC/E,SAASC,gBAAgBC,OAA+B;IACtD,OAAO;QACLC,MAAMD,QAAQC,IAAI;OACfpB,8BAA8BmB,QAAQC,IAAI;QAC7CC,WAAWF,QAAQE,SAAS;QAC5BC,SAASH,QAAQG,OAAO;QACxBC,SAAS;eAAIJ,QAAQI,OAAO;SAAC;QAC7BC,SAASL,QAAQK,OAAO;QACxBC,WAAW;eAAIN,QAAQM,SAAS;SAAC;QACjCC,iBAAiBP,QAAQO,eAAe;;AAE5C;AAEA,eAAeC,QACbC,IAA0B,EAC1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