@aglyn/plugins-marketing 1.0.0-beta.203 → 1.0.0-beta.205
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.
|
@@ -35,6 +35,7 @@ export async function getScreenExperiments(options) {
|
|
|
35
35
|
const publishedVersionId = String((_options_screen_versionId = options.screen.versionId) != null ? _options_screen_versionId : '');
|
|
36
36
|
const payloads = {};
|
|
37
37
|
for (const variant of ((_experiment_variants = experiment.variants) != null ? _experiment_variants : []).slice(0, MarketingModel.EXPERIMENT_MAX_VARIANTS)){
|
|
38
|
+
var _variant_name;
|
|
38
39
|
var _variant_versionId;
|
|
39
40
|
const versionId = (_variant_versionId = variant.versionId) == null ? void 0 : _variant_versionId.trim();
|
|
40
41
|
if (!versionId || versionId === publishedVersionId) {
|
|
@@ -46,7 +47,15 @@ export async function getScreenExperiments(options) {
|
|
|
46
47
|
screenId: options.screenId,
|
|
47
48
|
screen: options.screen,
|
|
48
49
|
versionId,
|
|
49
|
-
host: options.host
|
|
50
|
+
host: options.host,
|
|
51
|
+
// Named as the variant it is if the page review holds it (AGL-3374).
|
|
52
|
+
page: {
|
|
53
|
+
variant: {
|
|
54
|
+
experimentId: doc.id,
|
|
55
|
+
variantId: variant.id,
|
|
56
|
+
name: (_variant_name = variant.name) != null ? _variant_name : null
|
|
57
|
+
}
|
|
58
|
+
}
|
|
50
59
|
});
|
|
51
60
|
}
|
|
52
61
|
experiments.push(_extends({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/server/get-screen-experiments.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 * as Aglyn from '@aglyn/aglyn/server'\nimport * as MarketingModel from '../model'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\nimport composeScreenNodes from '@aglyn/tenant-runtime/compose-screen-nodes'\n\n/**\n * A screen/section experiment prepared for the page runtime (AGL-253):\n * the assignment inputs plus a composed node tree per variant whose\n * version differs from the published one (null payload = serve the\n * default tree). Section experiments swap the whole tree too — the\n * variant version differs only in the tested section by construction\n * (the editor duplicates the version and edits that section), so a\n * whole-tree swap is equivalent and avoids subtree surgery on the\n * client. `nodeId` stays as besigner metadata.\n */\nexport type { ScreenExperiment } from '../model/site-contract'\nimport type { ScreenExperiment } from '../model/site-contract'\n\nexport async function getScreenExperiments(options: {\n hostId: string\n screenId: string\n screen: Aglyn.AglynScreen\n /**\n * The site the page renders for (AGL-2883). A variant tree is swapped in\n * for the published one on the client, so its host variables fill in from\n * the same site document, or a visitor bucketed into a variant would read\n * nothing where everyone else reads the business name.\n */\n host?: Aglyn.HostTokenSource | null\n}): Promise<ScreenExperiment[]> {\n const experiments: ScreenExperiment[] = []\n try {\n const snapshot = await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(options.hostId)\n .collection('experiments')\n .where('screenId', '==', options.screenId)\n .limit(10)\n .get()\n for (const doc of snapshot.docs) {\n const experiment = doc.data() as MarketingModel.HostExperiment\n if ((experiment as any).deletedAt) continue\n if (experiment.target !== 'screen' && experiment.target !== 'section') {\n continue\n }\n // Running experiments split traffic; finished ones with a winner\n // serve the winner to everyone until the editor republishes.\n const active =\n experiment.status === 'running' ||\n (experiment.status === 'done' && experiment.winnerVariantId)\n if (!active) continue\n const publishedVersionId = String(options.screen.versionId ?? '')\n const payloads: Record<string, Record<string, any> | null> = {}\n for (const variant of (experiment.variants ?? []).slice(\n 0,\n MarketingModel.EXPERIMENT_MAX_VARIANTS,\n )) {\n const versionId = variant.versionId?.trim()\n if (!versionId || versionId === publishedVersionId) {\n payloads[variant.id] = null\n continue\n }\n payloads[variant.id] = await composeScreenNodes({\n hostId: options.hostId,\n screenId: options.screenId,\n screen: options.screen,\n versionId,\n host: options.host,\n })\n }\n experiments.push({\n id: doc.id,\n target: experiment.target,\n status: experiment.status,\n ...(experiment.nodeId ? { nodeId: experiment.nodeId } : {}),\n ...(experiment.winnerVariantId\n ? { winnerVariantId: experiment.winnerVariantId }\n : {}),\n ...(experiment.endAtMs ? { endAtMs: experiment.endAtMs } : {}),\n ...(experiment.goal ? { goal: experiment.goal } : {}),\n variants: (experiment.variants ?? []).map((variant) => ({\n id: variant.id,\n ...(variant.weight != null ? { weight: variant.weight } : {}),\n ...(variant.versionId ? { versionId: variant.versionId } : {}),\n })),\n payloads,\n })\n }\n } catch (error) {\n console.error(error)\n }\n return experiments\n}\n\nexport default getScreenExperiments\n"],"names":["MarketingModel","firebaseAdmin","composeScreenNodes","getScreenExperiments","options","experiments","snapshot","app","firestore","collection","doc","hostId","where","screenId","limit","get","docs","experiment","data","deletedAt","target","active","status","winnerVariantId","publishedVersionId","String","screen","versionId","payloads","variant","variants","slice","EXPERIMENT_MAX_VARIANTS","trim","id","host","push","nodeId","endAtMs","goal","map","weight","error","console"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,YAAYA,oBAAoB,oBAAU;AAC1C,SAASC,aAAa,QAAQ,2BAA0B;AACxD,OAAOC,wBAAwB,6CAA4C;AAe3E,OAAO,eAAeC,qBAAqBC,OAW1C;IACC,MAAMC,cAAkC,EAAE;IAC1C,IAAI;QACF,MAAMC,WAAW,MAAML,cACpBM,GAAG,GACHC,SAAS,GACTC,UAAU,CAAC,SACXC,GAAG,CAACN,QAAQO,MAAM,EAClBF,UAAU,CAAC,eACXG,KAAK,CAAC,YAAY,MAAMR,QAAQS,QAAQ,EACxCC,KAAK,CAAC,IACNC,GAAG;QACN,KAAK,MAAML,OAAOJ,SAASU,IAAI,CAAE;gBAYGZ,2BAEXa,
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/server/get-screen-experiments.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 * as Aglyn from '@aglyn/aglyn/server'\nimport * as MarketingModel from '../model'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\nimport composeScreenNodes from '@aglyn/tenant-runtime/compose-screen-nodes'\n\n/**\n * A screen/section experiment prepared for the page runtime (AGL-253):\n * the assignment inputs plus a composed node tree per variant whose\n * version differs from the published one (null payload = serve the\n * default tree). Section experiments swap the whole tree too — the\n * variant version differs only in the tested section by construction\n * (the editor duplicates the version and edits that section), so a\n * whole-tree swap is equivalent and avoids subtree surgery on the\n * client. `nodeId` stays as besigner metadata.\n */\nexport type { ScreenExperiment } from '../model/site-contract'\nimport type { ScreenExperiment } from '../model/site-contract'\n\nexport async function getScreenExperiments(options: {\n hostId: string\n screenId: string\n screen: Aglyn.AglynScreen\n /**\n * The site the page renders for (AGL-2883). A variant tree is swapped in\n * for the published one on the client, so its host variables fill in from\n * the same site document, or a visitor bucketed into a variant would read\n * nothing where everyone else reads the business name.\n */\n host?: Aglyn.HostTokenSource | null\n}): Promise<ScreenExperiment[]> {\n const experiments: ScreenExperiment[] = []\n try {\n const snapshot = await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(options.hostId)\n .collection('experiments')\n .where('screenId', '==', options.screenId)\n .limit(10)\n .get()\n for (const doc of snapshot.docs) {\n const experiment = doc.data() as MarketingModel.HostExperiment\n if ((experiment as any).deletedAt) continue\n if (experiment.target !== 'screen' && experiment.target !== 'section') {\n continue\n }\n // Running experiments split traffic; finished ones with a winner\n // serve the winner to everyone until the editor republishes.\n const active =\n experiment.status === 'running' ||\n (experiment.status === 'done' && experiment.winnerVariantId)\n if (!active) continue\n const publishedVersionId = String(options.screen.versionId ?? '')\n const payloads: Record<string, Record<string, any> | null> = {}\n for (const variant of (experiment.variants ?? []).slice(\n 0,\n MarketingModel.EXPERIMENT_MAX_VARIANTS,\n )) {\n const versionId = variant.versionId?.trim()\n if (!versionId || versionId === publishedVersionId) {\n payloads[variant.id] = null\n continue\n }\n payloads[variant.id] = await composeScreenNodes({\n hostId: options.hostId,\n screenId: options.screenId,\n screen: options.screen,\n versionId,\n host: options.host,\n // Named as the variant it is if the page review holds it (AGL-3374).\n page: {\n variant: {\n experimentId: doc.id,\n variantId: variant.id,\n name: variant.name ?? null,\n },\n },\n })\n }\n experiments.push({\n id: doc.id,\n target: experiment.target,\n status: experiment.status,\n ...(experiment.nodeId ? { nodeId: experiment.nodeId } : {}),\n ...(experiment.winnerVariantId\n ? { winnerVariantId: experiment.winnerVariantId }\n : {}),\n ...(experiment.endAtMs ? { endAtMs: experiment.endAtMs } : {}),\n ...(experiment.goal ? { goal: experiment.goal } : {}),\n variants: (experiment.variants ?? []).map((variant) => ({\n id: variant.id,\n ...(variant.weight != null ? { weight: variant.weight } : {}),\n ...(variant.versionId ? { versionId: variant.versionId } : {}),\n })),\n payloads,\n })\n }\n } catch (error) {\n console.error(error)\n }\n return experiments\n}\n\nexport default getScreenExperiments\n"],"names":["MarketingModel","firebaseAdmin","composeScreenNodes","getScreenExperiments","options","experiments","snapshot","app","firestore","collection","doc","hostId","where","screenId","limit","get","docs","experiment","data","deletedAt","target","active","status","winnerVariantId","publishedVersionId","String","screen","versionId","payloads","variant","variants","slice","EXPERIMENT_MAX_VARIANTS","trim","id","host","page","experimentId","variantId","name","push","nodeId","endAtMs","goal","map","weight","error","console"],"mappings":"AAAA;;;;;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