@sonordev/contracts 2.21.0 → 2.23.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/CHANGELOG.md +15 -0
- package/README.md +60 -1
- package/dist/outreach.js +1 -45
- package/dist/outreach.mjs +1 -45
- package/dist/resonance.d.ts +803 -82
- package/dist/resonance.js +336 -14
- package/dist/resonance.mjs +319 -15
- package/package.json +1 -1
package/dist/resonance.js
CHANGED
|
@@ -389,7 +389,7 @@ var destination = union2(
|
|
|
389
389
|
object2({ kind: literal2("funnel"), id: uuid, ...scope, path, funnelRef: resource, formSlug: text2(80, /^[a-z0-9]+(?:-[a-z0-9]+)*$/), installationRevision: revision }),
|
|
390
390
|
object2({ kind: literal2("existing_page"), id: uuid, ...scope, path, pageRevision: revision, evidenceDigest: digest })
|
|
391
391
|
);
|
|
392
|
-
var audience = object2({ ...scope, id: uuid, revision, policyRevision: revision, retentionDays: integer2(1, 540), exclusionRuleIds: list2(uuid, 50), consentPurpose: literal2("ad_personalization") });
|
|
392
|
+
var audience = object2({ ...scope, id: uuid, revision, policyRevision: revision, retentionDays: integer2(1, 540), exclusionRuleIds: list2(uuid, 50), minDaysSinceVisit: optional2(integer2(1, 179)), consentPurpose: literal2("ad_personalization") });
|
|
393
393
|
var experiment = object2({ ...scope, id: uuid, revision: integer2(1), digest });
|
|
394
394
|
var budget = refine2(object2({ total: money, dailyAllocationCeiling: nullable2(money), reserveMargin: money, startAt: instant, endAt: instant, timeZone, maxChange: money, maxChangeBasisPoints: integer2(0, 1e4), cooldownSeconds: integer2(0, 31536e3) }), (v, p) => {
|
|
395
395
|
if (Date.parse(v.endAt) <= Date.parse(v.startAt)) fail2(p, "end must follow start");
|
|
@@ -476,7 +476,39 @@ var search = object2({ ...channelBase, localCampaignKey: text2(80), kind: litera
|
|
|
476
476
|
var metaAgeConstraint = union2(refine2(object2({ mode: literal2("bounded"), min: integer2(1, 120), max: integer2(1, 120) }), (v, p) => {
|
|
477
477
|
if (v.min > v.max) fail2(p, "minimum age exceeds maximum");
|
|
478
478
|
}), object2({ mode: literal2("omitted") }), object2({ mode: literal2("provider_managed") }));
|
|
479
|
-
var
|
|
479
|
+
var propertyKey = object2({ key: text2(40, /^[a-z0-9]+(?:-[a-z0-9]+)*$/), label: text2(80) });
|
|
480
|
+
var meta = object2({
|
|
481
|
+
...channelBase,
|
|
482
|
+
localCampaignKey: text2(80),
|
|
483
|
+
kind: literal2("meta_retargeting"),
|
|
484
|
+
provider: literal2("meta_ads"),
|
|
485
|
+
accountBindingId: uuid,
|
|
486
|
+
capabilityRevision: revision,
|
|
487
|
+
allocation: money,
|
|
488
|
+
budgetMode: choice2("lifetime", "daily"),
|
|
489
|
+
audienceRuleRefs: list2(audience, 50, 1),
|
|
490
|
+
objective: choice2("OUTCOME_LEADS", "OUTCOME_SALES", "OUTCOME_TRAFFIC"),
|
|
491
|
+
pageRef: object2({ connectionId: uuid, externalId: text2(160), revision }),
|
|
492
|
+
instagramRef: nullable2(object2({ connectionId: uuid, externalId: text2(160), revision })),
|
|
493
|
+
datasetRef: object2({ id: text2(160), revision }),
|
|
494
|
+
conversionGoalRef: resource,
|
|
495
|
+
optimization: choice2("landing_page_views", "lead", "purchase"),
|
|
496
|
+
billing: literal2("impressions"),
|
|
497
|
+
bid: union2(object2({ strategy: literal2("lowest_cost") }), object2({ strategy: literal2("cost_cap"), cap: money })),
|
|
498
|
+
localAdSetKey: text2(80),
|
|
499
|
+
localAdKey: text2(80),
|
|
500
|
+
budgetOwner: choice2("campaign", "adset"),
|
|
501
|
+
specialCategories: list2(choice2("housing", "employment", "financial_products_services"), 3),
|
|
502
|
+
countryCodes: list2(text2(2, /^[A-Z]{2}$/), 30, 1),
|
|
503
|
+
placement: literal2("automatic"),
|
|
504
|
+
ageConstraint: optional2(metaAgeConstraint),
|
|
505
|
+
// Property retargeting (one channel per property under one group). Every field is optional and omitted from the canonical form when absent, so no existing reviewed digest changes.
|
|
506
|
+
channelGroup: optional2(propertyKey),
|
|
507
|
+
property: optional2(propertyKey),
|
|
508
|
+
tier: optional2(object2({ label: text2(40) })),
|
|
509
|
+
primaryText: optional2(text2(2200)),
|
|
510
|
+
convertersAcknowledged: optional2(literal2(true))
|
|
511
|
+
});
|
|
480
512
|
var owned = object2({ ...channelBase, kind: choice2("funnel", "broadcast", "outreach"), resourceRef: resource });
|
|
481
513
|
var channel = union2(search, meta, owned);
|
|
482
514
|
var definitionFields = { schemaVersion: literal2(1), projectId: uuid, name: text2(160), slug: refine2(text2(80), (v, p) => {
|
|
@@ -522,6 +554,9 @@ function checkDefinition(v) {
|
|
|
522
554
|
if ("bidding" in c && "target" in c.bidding && c.bidding.target.currency !== v.budget.total.currency) fail2("campaign.channels.bidding", "currency mismatch");
|
|
523
555
|
if ("allocation" in c && c.allocation.currency !== v.budget.total.currency) fail2("campaign.channels.allocation", "currency mismatch");
|
|
524
556
|
}
|
|
557
|
+
checkChannelGroups(v.channels);
|
|
558
|
+
checkGroupedAllocations(v);
|
|
559
|
+
for (const c of v.channels) if (c.kind === "meta_retargeting") checkMetaAudienceBands(c, "campaign.channels.audienceRuleRefs");
|
|
525
560
|
const policy = v.optimization.policy;
|
|
526
561
|
if (policy.algorithm === "finite_meta_candidates_v1") {
|
|
527
562
|
const guard = policy.measurementGuard, goal = v.objective;
|
|
@@ -579,9 +614,16 @@ var websiteVisitFeed = object2({ profile: literal2(RESONANCE_WEBSITE_VISIT_PROFI
|
|
|
579
614
|
}), 100, 1) });
|
|
580
615
|
var RESONANCE_WEBSITE_VISIT_FEED_JSON_SCHEMA = websiteVisitFeed.schema;
|
|
581
616
|
var providerReportingChannelIds = refine2(uniqueList(uuid, 100, 1), (ids, p) => unique(ids.map((id) => id.toLowerCase()), p));
|
|
582
|
-
var
|
|
583
|
-
var
|
|
617
|
+
var RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS = ["1d_click", "7d_click", "1d_view"];
|
|
618
|
+
var metaReportingQuery = object2({ channelId: uuid, attributionWindow: choice2(...RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS), actionReportTime: literal2("conversion"), basis: literal2("explicit_query") });
|
|
619
|
+
var providerReportingMetaQueries = refine2(list2(metaReportingQuery, 100, 1), (queries, p) => unique(queries.map((query) => query.channelId.toLowerCase()), p));
|
|
620
|
+
function checkReportingQuerySubset(v, p) {
|
|
621
|
+
if (v.metaQueries?.some((query) => !v.channelIds.some((id) => id.toLowerCase() === query.channelId.toLowerCase()))) fail2(p + ".metaQueries", "query channel must be selected");
|
|
622
|
+
}
|
|
623
|
+
var providerReportingSelection = refine2(object2({ agentContactId: uuid, channelIds: providerReportingChannelIds, metaQueries: optional2(providerReportingMetaQueries) }), checkReportingQuerySubset);
|
|
624
|
+
var providerReportingGrant = refine2(object2({ purpose: literal2("provider_reporting_refresh"), orgId: uuid, projectId: uuid, agentContactId: uuid, principalContactId: uuid, channelIds: providerReportingChannelIds, metaQueries: optional2(providerReportingMetaQueries) }), (v, p) => {
|
|
584
625
|
if (v.agentContactId.toLowerCase() === v.principalContactId.toLowerCase()) fail2(p + ".principalContactId", "agent and human principal must remain distinct");
|
|
626
|
+
checkReportingQuerySubset(v, p);
|
|
585
627
|
});
|
|
586
628
|
var parseResonanceProviderReportingSelection = (v) => providerReportingSelection.read(v, "providerReportingSelection");
|
|
587
629
|
var parseResonanceProviderReportingGrant = (v) => providerReportingGrant.read(v, "providerReportingGrant");
|
|
@@ -604,7 +646,7 @@ function parseResonanceMandateScope(v, preparedPlan) {
|
|
|
604
646
|
if (r.projectId !== plan.projectId || r.campaignId !== plan.campaignId || r.preparedPlanId !== plan.id || r.reviewDigest !== plan.reviewDigest || canonical(r.goal) !== canonical(plan.definition.objective) || canonical(r.budget) !== canonical(plan.definition.budget)) fail2(p, "requires the exact original plan, review, goal and flight");
|
|
605
647
|
if (r.sites.some((site2) => !plan.definition.sites.includes(site2)) || r.accountBindingIds.some((id) => !plan.accounts.some((account) => account.id === id))) fail2(p, "mandate sites and accounts must stay inside the original plan");
|
|
606
648
|
for (const id of grant.channelIds) {
|
|
607
|
-
const channel2 = plan.definition.channels.find((c) => c.id === id);
|
|
649
|
+
const channel2 = plan.definition.channels.find((c) => c.id.toLowerCase() === id.toLowerCase());
|
|
608
650
|
if (!channel2 || !("provider" in channel2) || !r.sites.includes(channel2.site) || !r.accountBindingIds.includes(channel2.accountBindingId)) fail2(p + ".channelIds", "requires an explicit original paid channel inside mandate sites and accounts");
|
|
609
651
|
}
|
|
610
652
|
}
|
|
@@ -883,12 +925,13 @@ function parseResonanceCampaignView(v) {
|
|
|
883
925
|
var metricValue = union2(object2({ kind: literal2("count"), count: decimal }), object2({ kind: literal2("money"), money }), object2({ kind: literal2("ratio"), numerator: decimal, denominator: refine2(decimal, (v, p) => {
|
|
884
926
|
if (v === "0") fail2(p, "zero denominator");
|
|
885
927
|
}) }));
|
|
886
|
-
var metricBase = { ...scope, campaignId: uuid, name: choice2("impressions", "clicks", "spend", "accepted_goals", "qualified_goals", "revenue", "conversion_rate"), source: choice2("first_party", "provider", "experiment"), sourceRef: revision, goalRevision: nullable2(revision), countingUnit: choice2("unique_source", "unique_qualified_contact", "net_order", "provider_aggregate"), windowStart: instant, windowEnd: instant, timeZone, attributionModel: nullable2(text2(100)), asOf: instant, dataThrough: nullable2(instant), maturityDelaySeconds: integer2(0), coverageBasisPoints: nullable2(integer2(0, 1e4)), eligibleExposures: nullable2(decimal), matureOutcomes: nullable2(decimal), native: nullable2(object2({ unit: text2(80), amount: decimal, currency: nullable2(currency), unitExponent: integer2(0, 9), providerVersion: text2(30) })) };
|
|
928
|
+
var metricBase = { ...scope, campaignId: uuid, name: choice2("impressions", "clicks", "spend", "accepted_goals", "qualified_goals", "revenue", "conversion_rate", "reach", "results"), source: choice2("first_party", "provider", "experiment"), sourceRef: revision, goalRevision: nullable2(revision), countingUnit: choice2("unique_source", "unique_qualified_contact", "net_order", "provider_aggregate", "provider_unique_reach"), windowStart: instant, windowEnd: instant, timeZone, attributionModel: nullable2(text2(100)), asOf: instant, dataThrough: nullable2(instant), maturityDelaySeconds: integer2(0), coverageBasisPoints: nullable2(integer2(0, 1e4)), eligibleExposures: nullable2(decimal), matureOutcomes: nullable2(decimal), native: nullable2(object2({ unit: text2(80), amount: decimal, currency: nullable2(currency), unitExponent: integer2(0, 9), providerVersion: text2(30) })) };
|
|
887
929
|
var metric = union2(object2({ ...metricBase, state: literal2("observed"), value: metricValue }), object2({ ...metricBase, state: choice2("unknown", "insufficient", "delayed", "unavailable"), value: literal2(null), reasonCode: text2(80) }));
|
|
888
930
|
function parseResonanceMetricObservation(v) {
|
|
889
931
|
const r = metric.read(v, "metric");
|
|
890
932
|
if (["accepted_goals", "qualified_goals", "revenue", "conversion_rate"].includes(r.name) && r.goalRevision === null) fail2("metric.goalRevision", "goal measurement requires explicit revision");
|
|
891
933
|
if (Date.parse(r.windowEnd) <= Date.parse(r.windowStart)) fail2("metric.window", "invalid window");
|
|
934
|
+
if (r.name === "reach" !== (r.countingUnit === "provider_unique_reach")) fail2("metric.countingUnit", "reach, and only reach, counts unique provider reach");
|
|
892
935
|
if (r.state === "observed") {
|
|
893
936
|
const expected = r.name === "spend" || r.name === "revenue" ? "money" : r.name === "conversion_rate" ? "ratio" : "count";
|
|
894
937
|
if (r.value.kind !== expected) fail2("metric.value", "metric unit mismatch");
|
|
@@ -1229,8 +1272,8 @@ function parseResonanceOptimizationEvidence(v, preparedPlan) {
|
|
|
1229
1272
|
parseResonanceMetricObservation(o);
|
|
1230
1273
|
if (o.projectId !== r.projectId || o.campaignId !== r.campaignId || o.site !== c.site) fail2(p + ".candidates.ownMeasurement", "foreign candidate measurement scope");
|
|
1231
1274
|
if (Date.parse(o.asOf) > Date.parse(r.observedAt) || Date.parse(o.windowStart) < Date.parse(r.windowStart) || Date.parse(o.windowEnd) > Date.parse(r.windowEnd) || o.dataThrough !== null && Date.parse(o.dataThrough) > Date.parse(r.observedAt)) fail2(p + ".candidates.ownMeasurement", "outside the actual candidate evidence window");
|
|
1232
|
-
const aggregate = o.source === "provider" &&
|
|
1233
|
-
if (aggregate ? o.countingUnit !==
|
|
1275
|
+
const aggregate = o.source === "provider" && RESONANCE_PROVIDER_METRIC_NAMES.includes(o.name);
|
|
1276
|
+
if (aggregate ? o.countingUnit !== providerCountingUnit(o.name) || o.attributionModel !== "provider_reported" || o.goalRevision !== null && o.goalRevision !== r.goalRevision : o.source !== "first_party" || o.goalRevision !== r.goalRevision || o.countingUnit !== r.objective.countingUnit || o.attributionModel !== policy.measurementGuard.attributionModel) fail2(p + ".candidates.ownMeasurement", "preserve actual provider aggregate versus first-party cohort provenance");
|
|
1234
1277
|
}
|
|
1235
1278
|
}
|
|
1236
1279
|
return r;
|
|
@@ -1370,9 +1413,11 @@ function checkOptimizationDecisionEvidence(d, e) {
|
|
|
1370
1413
|
}
|
|
1371
1414
|
var RESONANCE_OPTIMIZATION_EVIDENCE_JSON_SCHEMA = optimizationEvidence.schema;
|
|
1372
1415
|
var RESONANCE_OPTIMIZATION_DECISION_JSON_SCHEMA = optimizationDecision.schema;
|
|
1416
|
+
var metaBrowserWitness = object2({ controlsRevision: text2(60, /^[A-Z][A-Z0-9_]*$/), policyRevision: revision, witnessId: uuid, assertedAt: instant });
|
|
1373
1417
|
var publicDestination = union2(
|
|
1374
1418
|
object2({ provider: literal2("google_ads"), id: uuid, tagId: text2(40, /^AW-[0-9]+$/) }),
|
|
1375
|
-
|
|
1419
|
+
// browserWitness and tagManagerAttested are optional so configurations from before the Meta loader keep parsing; absent means no Meta browser loading.
|
|
1420
|
+
object2({ provider: literal2("meta_ads"), id: uuid, pixelId: text2(40, /^[0-9]+$/), browserWitness: optional2(metaBrowserWitness), tagManagerAttested: optional2(bool) })
|
|
1376
1421
|
);
|
|
1377
1422
|
var interestResource = object2({ ...scope, type: choice2("page", "article", "product", "listing"), id: text2(160, /^[a-zA-Z0-9._:-]+$/), revision });
|
|
1378
1423
|
var measurementConfig = object2({
|
|
@@ -1384,7 +1429,8 @@ var measurementConfig = object2({
|
|
|
1384
1429
|
enabled: bool,
|
|
1385
1430
|
consentPolicy: object2({ mode: literal2("basic"), requiredPurposes: list2(purpose, 4, 1) }),
|
|
1386
1431
|
destinations: list2(publicDestination, 10),
|
|
1387
|
-
|
|
1432
|
+
// metaEligible is set by a person with owner or admin standing; absent means false. The browser never decides it.
|
|
1433
|
+
resourceRules: list2(object2({ id: uuid, revision, site, resource: interestResource, path, interestKey: text2(100, /^[a-zA-Z0-9._:-]+$/), metaEligible: optional2(bool) }), 500)
|
|
1388
1434
|
});
|
|
1389
1435
|
function parseResonanceMeasurementConfig(v) {
|
|
1390
1436
|
const r = measurementConfig.read(v, "measurementConfig");
|
|
@@ -1496,11 +1542,12 @@ var audienceDraft = object2({
|
|
|
1496
1542
|
schemaVersion: literal2(1),
|
|
1497
1543
|
expectedRevision: optional2(integer2(1)),
|
|
1498
1544
|
idempotencyKey: operationKey,
|
|
1499
|
-
definition: object2({ name: text2(160), site, accountBindingId: uuid, resourceRuleId: uuid, excludedResourceRuleIds: list2(uuid, 50), retentionDays: integer2(1, 540), policyRevision: revision, currentConsentPolicyRevision: revision })
|
|
1545
|
+
definition: object2({ name: text2(160), site, accountBindingId: uuid, resourceRuleId: uuid, excludedResourceRuleIds: list2(uuid, 50), retentionDays: integer2(1, 540), minDaysSinceVisit: optional2(integer2(1, 179)), policyRevision: revision, currentConsentPolicyRevision: revision })
|
|
1500
1546
|
});
|
|
1501
1547
|
function parseResonanceAudienceDraftSaveCommand(v) {
|
|
1502
1548
|
const r = audienceDraft.read(v, "audienceDraftSave");
|
|
1503
1549
|
unique(r.definition.excludedResourceRuleIds, "audienceDraftSave.definition.excludedResourceRuleIds");
|
|
1550
|
+
if (r.definition.minDaysSinceVisit !== void 0 && r.definition.minDaysSinceVisit >= r.definition.retentionDays) fail2("audienceDraftSave.definition.minDaysSinceVisit", "must be shorter than the retention window");
|
|
1504
1551
|
return r;
|
|
1505
1552
|
}
|
|
1506
1553
|
var RESONANCE_AUDIENCE_DRAFT_SAVE_COMMAND_JSON_SCHEMA = audienceDraft.schema;
|
|
@@ -1626,7 +1673,8 @@ var RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA = measurementSa
|
|
|
1626
1673
|
var RESONANCE_MEASUREMENT_CONFIGURATION_CURRENT_JSON_SCHEMA = measurementCurrent.schema;
|
|
1627
1674
|
var RESONANCE_MEASUREMENT_CONFIGURATION_SNAPSHOT_JSON_SCHEMA = measurementSnapshot.schema;
|
|
1628
1675
|
var RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA = measurementSaveResponse.schema;
|
|
1629
|
-
var
|
|
1676
|
+
var nativeAudienceId = text2(160, /^[0-9]+(?![\s\S])/);
|
|
1677
|
+
var nativeAudienceRef = object2({ externalId: nativeAudienceId, revision: digest });
|
|
1630
1678
|
var metaSave = refine2(object2({
|
|
1631
1679
|
schemaVersion: literal2(1),
|
|
1632
1680
|
expectedCampaignRevision: integer2(1),
|
|
@@ -1669,6 +1717,7 @@ function checkMetaMaterial(v, p) {
|
|
|
1669
1717
|
unique(v.audiences.map((a) => a.audienceRuleRef.id), p + ".audiences");
|
|
1670
1718
|
unique(v.channel.audienceRuleRefs.map((a) => a.id), p + ".channel.audienceRuleRefs");
|
|
1671
1719
|
if (v.audiences.length !== v.channel.audienceRuleRefs.length) fail2(p + ".audiences", "must cover exactly the original logical audiences");
|
|
1720
|
+
checkMetaAudienceBands(v.channel, p + ".channel.audienceRuleRefs");
|
|
1672
1721
|
for (const a of v.audiences) {
|
|
1673
1722
|
if (!v.channel.audienceRuleRefs.some((ref) => canonical(ref) === canonical(a.audienceRuleRef))) fail2(p + ".audiences", "original logical audience version mismatch");
|
|
1674
1723
|
unique(a.excludedResourceRuleRefs.map((ref) => ref.id), p + ".audiences.excludedResourceRuleRefs");
|
|
@@ -1714,6 +1763,63 @@ var metaView = refine2(union2(
|
|
|
1714
1763
|
if (v.readyForReview !== metaReviewable(s, v)) fail2(p + ".readyForReview", "must reflect current review prerequisites only");
|
|
1715
1764
|
});
|
|
1716
1765
|
var parseResonanceMetaConfigurationView = (v) => metaView.read(v, "metaConfigurationView");
|
|
1766
|
+
var RESONANCE_META_AUDIENCE_VERDICTS = ["ready", "too_small", "blocked", "unknown"];
|
|
1767
|
+
var RESONANCE_META_AUDIENCE_REASONS = [
|
|
1768
|
+
"meta_audience_status_unreadable",
|
|
1769
|
+
"meta_audience_status_unrecognized",
|
|
1770
|
+
"meta_audience_integrity_flagged",
|
|
1771
|
+
"meta_audience_account_inactive",
|
|
1772
|
+
"meta_audience_pixel_problem",
|
|
1773
|
+
"meta_audience_error",
|
|
1774
|
+
"meta_audience_out_of_date",
|
|
1775
|
+
"meta_audience_too_small",
|
|
1776
|
+
"meta_audience_not_usable",
|
|
1777
|
+
"meta_audience_prefill_failed",
|
|
1778
|
+
"meta_audience_filling",
|
|
1779
|
+
"meta_audience_category_unknown",
|
|
1780
|
+
"meta_url_audience_unverified",
|
|
1781
|
+
"meta_core_setup_suspected",
|
|
1782
|
+
"meta_audience_fill_mismatch",
|
|
1783
|
+
"meta_core_setup_attestation_missing",
|
|
1784
|
+
"meta_flight_too_short_after_wait",
|
|
1785
|
+
"meta_terms_nondiscrimination_pending",
|
|
1786
|
+
"meta_terms_custom_audience_unconfirmed",
|
|
1787
|
+
"meta_terms_business_tools_pending",
|
|
1788
|
+
"meta_special_category_age_must_be_provider_managed",
|
|
1789
|
+
"meta_special_category_genders_not_allowed",
|
|
1790
|
+
"meta_audience_name_sensitive"
|
|
1791
|
+
];
|
|
1792
|
+
var metaReadinessPage = object2({ resourceRuleRef: measurementRuleRef, path: observedPagePath, label: nullable2(friendlyName) });
|
|
1793
|
+
var metaAudienceSize = refine2(object2({ lower: integer2(0), upper: integer2(0) }), (v, p) => {
|
|
1794
|
+
if (v.upper < v.lower) fail2(p, "size bounds must be ordered");
|
|
1795
|
+
});
|
|
1796
|
+
var metaReadinessCheck = union2(
|
|
1797
|
+
object2({ state: literal2("not_checked"), reasonCode: choice2("configuration_unavailable", "native_mapping_unavailable") }),
|
|
1798
|
+
object2({ state: literal2("observed"), mappingSource: choice2("selected_external_audience", "current_materialized_audience"), verdict: choice2(...RESONANCE_META_AUDIENCE_VERDICTS), reasonCodes: uniqueList(choice2(...RESONANCE_META_AUDIENCE_REASONS), 50), size: nullable2(metaAudienceSize), observedAt: instant, expiresAt: nullable2(instant), sizeObservedAt: literal2(null), sizeExpiresAt: literal2(null) })
|
|
1799
|
+
);
|
|
1800
|
+
var metaReadinessAudience = object2({ audienceRuleRef: audience, name: friendlyName, includedPage: metaReadinessPage, excludedPages: list2(metaReadinessPage, 50), nativeAudienceId: nullable2(nativeAudienceId), check: metaReadinessCheck });
|
|
1801
|
+
var metaRetargetingReadiness = refine2(object2({ schemaVersion: literal2(1), projectId: uuid, campaignId: uuid, channelId: uuid, site, campaignRevision: integer2(1), accountBindingId: uuid, configuration: metaView, audiences: list2(metaReadinessAudience, 50) }), (v, p) => {
|
|
1802
|
+
const sameId = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
1803
|
+
const config = v.configuration;
|
|
1804
|
+
if (!sameId(config.projectId, v.projectId) || !sameId(config.campaignId, v.campaignId) || !sameId(config.channelId, v.channelId)) fail2(p + ".configuration", "configuration scope mismatch");
|
|
1805
|
+
if (config.kind === "configured" && (config.currentCampaignRevision !== v.campaignRevision || config.snapshot.site !== v.site || !sameId(config.snapshot.account.id, v.accountBindingId))) fail2(p + ".configuration", "current configuration revision, site or account mismatch");
|
|
1806
|
+
unique(v.audiences.map((row) => row.audienceRuleRef.id.toLowerCase()), p + ".audiences");
|
|
1807
|
+
for (const row of v.audiences) {
|
|
1808
|
+
if (!sameId(row.audienceRuleRef.projectId, v.projectId) || row.audienceRuleRef.site !== v.site) fail2(p + ".audiences", "audience scope mismatch");
|
|
1809
|
+
const excluded = row.excludedPages.map((page2) => page2.resourceRuleRef.id.toLowerCase());
|
|
1810
|
+
unique(excluded, p + ".audiences.excludedPages");
|
|
1811
|
+
const expected = row.audienceRuleRef.exclusionRuleIds.map((id) => id.toLowerCase());
|
|
1812
|
+
unique(expected, p + ".audiences.audienceRuleRef.exclusionRuleIds");
|
|
1813
|
+
if (excluded.includes(row.includedPage.resourceRuleRef.id.toLowerCase()) || excluded.length !== expected.length || expected.some((id) => !excluded.includes(id))) fail2(p + ".audiences.excludedPages", "exclusion rule scope mismatch");
|
|
1814
|
+
if (row.check.state === "observed" && (row.nativeAudienceId === null || config.kind !== "configured")) fail2(p + ".audiences.check", "observed check requires configured scope and actual native audience identity");
|
|
1815
|
+
if (config.kind === "configured" && config.currentDefinitionDigest === config.snapshot.reviewedDefinitionDigest) {
|
|
1816
|
+
const original = config.snapshot.audiences.find((a) => sameId(a.audienceRuleRef.id, row.audienceRuleRef.id));
|
|
1817
|
+
if (!original || canonical(original.audienceRuleRef) !== canonical(row.audienceRuleRef) || canonical(original.resourceRuleRef) !== canonical(row.includedPage.resourceRuleRef) || original.excludedResourceRuleRefs.length !== row.excludedPages.length || original.excludedResourceRuleRefs.some((ref) => !row.excludedPages.some((page2) => canonical(page2.resourceRuleRef) === canonical(ref)))) fail2(p + ".audiences", "original audience and page rule versions must match");
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
});
|
|
1821
|
+
var parseResonanceMetaRetargetingReadiness = (v) => metaRetargetingReadiness.read(v, "metaRetargetingReadiness");
|
|
1822
|
+
var RESONANCE_META_RETARGETING_READINESS_JSON_SCHEMA = metaRetargetingReadiness.schema;
|
|
1717
1823
|
var metaSaveResponse = object2({ schemaVersion: literal2(1), snapshot: metaSnapshot, replayed: bool });
|
|
1718
1824
|
var parseResonanceMetaConfigurationSaveResponse = (v) => metaSaveResponse.read(v, "metaConfigurationSaveResponse");
|
|
1719
1825
|
function projectResonanceMetaConfiguration(v, currentMetadata) {
|
|
@@ -1800,7 +1906,7 @@ function parseResonanceObservationSupport(v) {
|
|
|
1800
1906
|
}
|
|
1801
1907
|
return r;
|
|
1802
1908
|
}
|
|
1803
|
-
var observationsPage = object2({ items: list2(publicObservationMetric,
|
|
1909
|
+
var observationsPage = object2({ items: list2(publicObservationMetric, 500), nextCursor: nullable2(uuid), observedAt: instant, support: list2(observationSupport, 500) });
|
|
1804
1910
|
function parseResonanceObservationsPage(v) {
|
|
1805
1911
|
const r = observationsPage.read(v, "observationsPage"), p = "observationsPage";
|
|
1806
1912
|
if (r.items.length !== r.support.length) fail2(p + ".support", "requires one support entry for each metric item");
|
|
@@ -1824,7 +1930,7 @@ function parseResonanceObservationsPage(v) {
|
|
|
1824
1930
|
rows.set(rowId, row);
|
|
1825
1931
|
if (s.source === "provider") {
|
|
1826
1932
|
if (item.state === "observed" && (s.coverage !== "complete" || s.coverageBasis !== "closed_query_snapshot" || s.reasonCode !== null)) fail2(p + ".support", "observed provider values require complete genuine closed-query support");
|
|
1827
|
-
if (!
|
|
1933
|
+
if (!RESONANCE_PROVIDER_METRIC_NAMES.includes(item.name) || item.sourceRef !== item.observationId || item.countingUnit !== providerCountingUnit(item.name) || item.attributionModel !== "provider_reported") fail2(p + ".items", "provider metrics retain exact native observation and aggregate semantics");
|
|
1828
1934
|
if (s.readClock !== null && Date.parse(s.readClock.notBeforeAt) < Date.parse(item.windowEnd)) fail2(p + ".support.readClock", "SQL pre-read lower bound must follow the completed query window");
|
|
1829
1935
|
} else {
|
|
1830
1936
|
const d = s.denominators;
|
|
@@ -1842,8 +1948,210 @@ function parseResonanceObservationsPage(v) {
|
|
|
1842
1948
|
var RESONANCE_PUBLIC_OBSERVATION_METRIC_JSON_SCHEMA = publicObservationMetric.schema;
|
|
1843
1949
|
var RESONANCE_OBSERVATION_SUPPORT_JSON_SCHEMA = observationSupport.schema;
|
|
1844
1950
|
var RESONANCE_OBSERVATIONS_PAGE_JSON_SCHEMA = observationsPage.schema;
|
|
1951
|
+
var META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS = 180;
|
|
1952
|
+
var META_AUDIENCE_RULE_LIMIT = 10;
|
|
1953
|
+
var META_SAC_CUSTOM_AUDIENCE_EXCLUSION_VERIFIED = false;
|
|
1954
|
+
var META_CALL_TO_ACTIONS = ["LEARN_MORE", "SIGN_UP", "SHOP_NOW", "APPLY_NOW", "BOOK_TRAVEL", "CONTACT_US", "GET_QUOTE"];
|
|
1955
|
+
var RESONANCE_MAX_CHANNELS_PER_GROUP = 20;
|
|
1956
|
+
var RESONANCE_PROVIDER_METRIC_NAMES = ["spend", "impressions", "clicks", "reach", "results"];
|
|
1957
|
+
var providerCountingUnit = (name) => name === "reach" ? "provider_unique_reach" : "provider_aggregate";
|
|
1958
|
+
var isMetaChannel = (c) => c.kind === "meta_retargeting";
|
|
1959
|
+
var usesPropertyModel = (c) => c.channelGroup !== void 0 || c.audienceRuleRefs.some((ref) => ref.minDaysSinceVisit !== void 0);
|
|
1960
|
+
function checkAudienceBand(ref, provider = "meta_ads", at = "audienceRuleRef") {
|
|
1961
|
+
const min = ref.minDaysSinceVisit;
|
|
1962
|
+
if (min !== void 0 && min >= ref.retentionDays) fail2(at + ".minDaysSinceVisit", "must be shorter than the retention window");
|
|
1963
|
+
if (provider === "google_ads") {
|
|
1964
|
+
if (min !== void 0) fail2(at + ".minDaysSinceVisit", "Google audiences have no recency band");
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1967
|
+
if (ref.retentionDays > META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS) fail2(at + ".retentionDays", `exceeds the ${META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS}-day Meta website audience maximum`);
|
|
1968
|
+
if (1 + ref.exclusionRuleIds.length + (min === void 0 ? 0 : 1) > META_AUDIENCE_RULE_LIMIT) fail2(at + ".exclusionRuleIds", `a Meta audience holds at most ${META_AUDIENCE_RULE_LIMIT} rules including the page and any recency band`);
|
|
1969
|
+
}
|
|
1970
|
+
function checkMetaAudienceBands(channel2, at) {
|
|
1971
|
+
if (!usesPropertyModel(channel2)) return;
|
|
1972
|
+
channel2.audienceRuleRefs.forEach((ref, index) => checkAudienceBand(ref, "meta_ads", `${at}[${index}]`));
|
|
1973
|
+
}
|
|
1974
|
+
var bandsOverlap = (a, b) => (a.minDaysSinceVisit ?? 0) < b.retentionDays && (b.minDaysSinceVisit ?? 0) < a.retentionDays;
|
|
1975
|
+
function checkChannelGroups(channels) {
|
|
1976
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1977
|
+
for (const c of channels) if (isMetaChannel(c) && c.channelGroup) groups.set(c.channelGroup.key, [...groups.get(c.channelGroup.key) ?? [], c]);
|
|
1978
|
+
for (const [key, members] of groups) {
|
|
1979
|
+
const at = `campaign.channelGroup.${key}`;
|
|
1980
|
+
if (members.length > RESONANCE_MAX_CHANNELS_PER_GROUP) fail2(at, `at most ${RESONANCE_MAX_CHANNELS_PER_GROUP} channels per group`);
|
|
1981
|
+
const first = members[0];
|
|
1982
|
+
const shared = (c) => canonical([c.site, c.accountBindingId, c.datasetRef.id, c.pageRef, c.instagramRef, c.specialCategories, c.countryCodes, c.objective, c.optimization]);
|
|
1983
|
+
const identity = /* @__PURE__ */ new Set(), destinationOf = /* @__PURE__ */ new Map(), propertyOfDestination = /* @__PURE__ */ new Map();
|
|
1984
|
+
for (const c of members) {
|
|
1985
|
+
if (shared(c) !== shared(first)) fail2(at, "channels in one group must share site, account, dataset, Page, categories, countries, objective and optimization");
|
|
1986
|
+
if (c.specialCategories.length > 0 && c.ageConstraint?.mode !== "provider_managed") fail2(at + ".ageConstraint", "a special category requires provider-managed age");
|
|
1987
|
+
const pk = (c.property ?? fail2(at + ".property", "a grouped channel names its property")).key, tier = c.tier?.label ?? "", id = `${pk}|${tier}`;
|
|
1988
|
+
if (identity.has(id)) fail2(at + ".property", "two channels share one property and tier");
|
|
1989
|
+
identity.add(id);
|
|
1990
|
+
if (destinationOf.has(pk) && destinationOf.get(pk) !== c.destinationId) fail2(at + ".destinationId", "channels for one property share one destination");
|
|
1991
|
+
destinationOf.set(pk, c.destinationId);
|
|
1992
|
+
const other = propertyOfDestination.get(c.destinationId);
|
|
1993
|
+
if (other !== void 0 && other !== pk) fail2(at + ".destinationId", "channels for different properties have different destinations");
|
|
1994
|
+
propertyOfDestination.set(c.destinationId, pk);
|
|
1995
|
+
}
|
|
1996
|
+
for (let i = 0; i < members.length; i++) for (let j = i + 1; j < members.length; j++) {
|
|
1997
|
+
if (members[i].property?.key !== members[j].property?.key) continue;
|
|
1998
|
+
for (const a of members[i].audienceRuleRefs) for (const b of members[j].audienceRuleRefs) if (bandsOverlap(a, b)) fail2(at + ".audienceRuleRefs", "tiers of one property cannot overlap in time");
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
function checkGroupedAllocations(v) {
|
|
2003
|
+
if (!v.channels.some((c) => isMetaChannel(c) && c.channelGroup)) return;
|
|
2004
|
+
let sum = 0n;
|
|
2005
|
+
for (const c of v.channels) if ("allocation" in c) sum += BigInt(c.allocation.amountMicros);
|
|
2006
|
+
if (sum > BigInt(v.budget.total.amountMicros) - BigInt(v.budget.reserveMargin.amountMicros)) fail2("campaign.channels.allocation", "channel allocations exceed the campaign total less its reserve");
|
|
2007
|
+
}
|
|
2008
|
+
function splitBudget(total, weights, quantumMicros) {
|
|
2009
|
+
const t = parseMoney(total), at = "splitBudget";
|
|
2010
|
+
if (!/^[1-9][0-9]{0,29}$/.test(quantumMicros)) fail2(at + ".quantumMicros", "must be a positive whole number of micros");
|
|
2011
|
+
if (weights.length < 1 || weights.length > 100 || weights.some((w) => !Number.isSafeInteger(w) || w < 1)) fail2(at + ".weights", "one to 100 positive whole weights");
|
|
2012
|
+
const quantum = BigInt(quantumMicros), micros = BigInt(t.amountMicros);
|
|
2013
|
+
if (micros % quantum !== 0n) fail2(at + ".total", "must be a whole number of provider quanta");
|
|
2014
|
+
const units = micros / quantum, sum = weights.reduce((a, w) => a + BigInt(w), 0n);
|
|
2015
|
+
const parts = weights.map((w, index) => ({ index, floor: units * BigInt(w) / sum, rest: units * BigInt(w) % sum }));
|
|
2016
|
+
let left = units - parts.reduce((a, p) => a + p.floor, 0n);
|
|
2017
|
+
const order = [...parts].sort((a, b) => a.rest === b.rest ? a.index - b.index : a.rest > b.rest ? -1 : 1);
|
|
2018
|
+
const extra = /* @__PURE__ */ new Set();
|
|
2019
|
+
for (const p of order) {
|
|
2020
|
+
if (left === 0n) break;
|
|
2021
|
+
extra.add(p.index);
|
|
2022
|
+
left -= 1n;
|
|
2023
|
+
}
|
|
2024
|
+
return parts.map((p) => ({ currency: t.currency, amountMicros: ((p.floor + (extra.has(p.index) ? 1n : 0n)) * quantum).toString() }));
|
|
2025
|
+
}
|
|
2026
|
+
function suggestPropertyWeights(visitors, bounds = {}) {
|
|
2027
|
+
const floor = bounds.floorBasisPoints ?? 1e3, ceiling = bounds.ceilingBasisPoints ?? 4e3, n = visitors.length, at = "suggestPropertyWeights";
|
|
2028
|
+
if (n < 1 || n > 100 || visitors.some((v) => !Number.isSafeInteger(v) || v < 0)) fail2(at + ".visitors", "one to 100 whole, non-negative visitor counts");
|
|
2029
|
+
if (!Number.isInteger(floor) || !Number.isInteger(ceiling) || floor < 0 || ceiling > 1e4 || floor > ceiling || n * floor > 1e4 || n * ceiling < 1e4) fail2(at + ".bounds", "floor and ceiling cannot hold every share");
|
|
2030
|
+
const weight = visitors.map((v) => v + 1);
|
|
2031
|
+
const total = (lambda) => weight.reduce((a, w) => a + Math.min(ceiling, Math.max(floor, lambda * w)), 0);
|
|
2032
|
+
let low = 0, high = ceiling / Math.min(...weight) + 1;
|
|
2033
|
+
for (let i = 0; i < 200; i++) {
|
|
2034
|
+
const mid = (low + high) / 2;
|
|
2035
|
+
if (total(mid) < 1e4) low = mid;
|
|
2036
|
+
else high = mid;
|
|
2037
|
+
}
|
|
2038
|
+
const share = weight.map((w) => Math.min(ceiling, Math.max(floor, high * w)));
|
|
2039
|
+
const whole = share.map(Math.floor), rest = share.map((value, i) => ({ i, rest: value - whole[i] })).sort((a, b) => b.rest - a.rest || a.i - b.i);
|
|
2040
|
+
let left = 1e4 - whole.reduce((a, b) => a + b, 0);
|
|
2041
|
+
for (const r of rest) {
|
|
2042
|
+
if (left <= 0) break;
|
|
2043
|
+
whole[r.i] += 1;
|
|
2044
|
+
left -= 1;
|
|
2045
|
+
}
|
|
2046
|
+
return whole;
|
|
2047
|
+
}
|
|
2048
|
+
function deterministicUuid(seed) {
|
|
2049
|
+
const mask = (1n << 64n) - 1n, prime = 0x100000001b3n, bytes = new TextEncoder().encode(seed);
|
|
2050
|
+
const hash = (basis) => {
|
|
2051
|
+
let h = basis;
|
|
2052
|
+
for (const b of bytes) {
|
|
2053
|
+
h ^= BigInt(b);
|
|
2054
|
+
h = h * prime & mask;
|
|
2055
|
+
}
|
|
2056
|
+
return h.toString(16).padStart(16, "0");
|
|
2057
|
+
};
|
|
2058
|
+
const hex = hash(0xcbf29ce484222325n) + hash(0x84222325cbf29ce4n);
|
|
2059
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-${"89ab"[parseInt(hex[16], 16) & 3]}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
2060
|
+
}
|
|
2061
|
+
var PLACEHOLDER_CREATIVE_ID = "00000000-0000-4000-8000-000000000000";
|
|
2062
|
+
var clip = (value, max) => value.length <= max ? value : value.slice(0, max);
|
|
2063
|
+
function expandPropertyChannels(definition2, groupKey, additions, options) {
|
|
2064
|
+
const at = "expandPropertyChannels";
|
|
2065
|
+
const group = definition2.channels.filter((c) => isMetaChannel(c) && c.channelGroup?.key === groupKey);
|
|
2066
|
+
if (!group.length) fail2(at + ".group", "needs an existing property channel to use as the template");
|
|
2067
|
+
const template = group[0];
|
|
2068
|
+
const present = new Set(group.map((c) => c.property?.key));
|
|
2069
|
+
const keys = additions.map((a) => a.key);
|
|
2070
|
+
unique(keys, at + ".additions");
|
|
2071
|
+
const fresh = additions.filter((a) => !present.has(a.key));
|
|
2072
|
+
if (!fresh.length) return { channels: [], allocations: [], blockingReasons: [] };
|
|
2073
|
+
const weightOf = (key, own) => own ?? options.weights?.[key] ?? 1;
|
|
2074
|
+
const members = [...group.map((c) => ({ key: c.property.key, id: c.id, weight: weightOf(c.property.key) })), ...fresh.map((a) => ({ key: a.key, id: deterministicUuid(`${definition2.projectId}|${definition2.slug}|${groupKey}|${a.key}`), weight: weightOf(a.key, a.weight) }))];
|
|
2075
|
+
const total = group.reduce((a, c) => addMoney(a, c.allocation), { currency: template.allocation.currency, amountMicros: "0" });
|
|
2076
|
+
const split = splitBudget(total, members.map((m) => m.weight), options.quantumMicros);
|
|
2077
|
+
const allocations = members.map((m, i) => ({ channelId: m.id, allocation: split[i] }));
|
|
2078
|
+
const { tier: _tier, primaryText: _primary, convertersAcknowledged: _converters, ...rest } = template;
|
|
2079
|
+
const channels = fresh.map((a) => {
|
|
2080
|
+
const id = members.find((m) => m.key === a.key).id;
|
|
2081
|
+
const proposal = {
|
|
2082
|
+
...rest,
|
|
2083
|
+
id,
|
|
2084
|
+
localCampaignKey: clip(`${groupKey}-${a.key}`, 80),
|
|
2085
|
+
localAdSetKey: clip(`${a.key}-visitors`, 80),
|
|
2086
|
+
localAdKey: clip(`${a.key}-1`, 80),
|
|
2087
|
+
property: { key: a.key, label: a.label },
|
|
2088
|
+
destinationId: a.destinationId,
|
|
2089
|
+
audienceRuleRefs: a.audienceRuleRefs,
|
|
2090
|
+
creativeIds: [],
|
|
2091
|
+
allocation: allocations.find((x) => x.channelId === id).allocation
|
|
2092
|
+
};
|
|
2093
|
+
meta.read({ ...proposal, creativeIds: [PLACEHOLDER_CREATIVE_ID] }, at + ".channel");
|
|
2094
|
+
return proposal;
|
|
2095
|
+
});
|
|
2096
|
+
const combined = [...definition2.channels, ...channels.map((c) => ({ ...c, creativeIds: [PLACEHOLDER_CREATIVE_ID] }))];
|
|
2097
|
+
unique(combined.map((c) => c.id), at + ".channels");
|
|
2098
|
+
checkChannelGroups(combined);
|
|
2099
|
+
const changed = group.some((c) => canonical(allocations.find((x) => x.channelId === c.id).allocation) !== canonical(c.allocation));
|
|
2100
|
+
return { channels, allocations, blockingReasons: [...fresh.map((a) => `property_creative_required:${a.key}`), ...changed ? ["rebalance_changes_running_allocations"] : []] };
|
|
2101
|
+
}
|
|
2102
|
+
function metaExclusionPolicy(channel2, use) {
|
|
2103
|
+
const special = channel2.specialCategories.length > 0;
|
|
2104
|
+
if (use.targetingLevel && special && !META_SAC_CUSTOM_AUDIENCE_EXCLUSION_VERIFIED) return { allowed: false, reason: "meta_exclusion_targeting_blocked_special_category", requiresEligibilityReadback: false };
|
|
2105
|
+
return { allowed: true, reason: null, requiresEligibilityReadback: special && (use.inRule || use.targetingLevel) };
|
|
2106
|
+
}
|
|
2107
|
+
function deriveProviderRatios(items) {
|
|
2108
|
+
const unknown = (reasonCode) => ({ frequency: { state: "unknown", reasonCode }, costPerResult: { state: "unknown", reasonCode }, reasonCodes: [reasonCode] });
|
|
2109
|
+
if (!items.length) return unknown("no_inputs");
|
|
2110
|
+
const first = items[0];
|
|
2111
|
+
if (items.some((i) => i.source !== "provider" || i.state !== "observed" || i.observationId === void 0 || i.observationId !== first.observationId || i.channelId !== first.channelId || i.windowStart !== first.windowStart || i.windowEnd !== first.windowEnd)) return unknown("mixed_inputs");
|
|
2112
|
+
const named = (name) => items.filter((i) => i.name === name);
|
|
2113
|
+
if (RESONANCE_PROVIDER_METRIC_NAMES.some((name) => named(name).length > 1)) return unknown("duplicate_metric");
|
|
2114
|
+
const count = (name) => {
|
|
2115
|
+
const i = named(name)[0];
|
|
2116
|
+
return i && i.state === "observed" && i.value?.kind === "count" ? BigInt(i.value.count) : null;
|
|
2117
|
+
};
|
|
2118
|
+
const spend = () => {
|
|
2119
|
+
const i = named("spend")[0];
|
|
2120
|
+
return i && i.state === "observed" && i.value?.kind === "money" ? i.value.money : null;
|
|
2121
|
+
};
|
|
2122
|
+
const reasons = [];
|
|
2123
|
+
let frequency;
|
|
2124
|
+
const impressions = count("impressions"), reach = count("reach");
|
|
2125
|
+
if (impressions === null || reach === null) {
|
|
2126
|
+
frequency = { state: "unknown", reasonCode: impressions === null ? "missing_impressions" : "missing_reach" };
|
|
2127
|
+
reasons.push(frequency.reasonCode);
|
|
2128
|
+
} else if (reach === 0n) {
|
|
2129
|
+
frequency = { state: "unknown", reasonCode: "no_reach" };
|
|
2130
|
+
reasons.push("no_reach");
|
|
2131
|
+
} else frequency = { state: "observed", value: { kind: "ratio", numerator: impressions.toString(), denominator: reach.toString() } };
|
|
2132
|
+
let costPerResult;
|
|
2133
|
+
const money2 = spend(), results = count("results");
|
|
2134
|
+
if (money2 === null || results === null) {
|
|
2135
|
+
costPerResult = { state: "unknown", reasonCode: money2 === null ? "missing_spend" : "missing_results" };
|
|
2136
|
+
reasons.push(costPerResult.reasonCode);
|
|
2137
|
+
} else if (results === 0n) {
|
|
2138
|
+
costPerResult = { state: "unknown", reasonCode: "no_results" };
|
|
2139
|
+
reasons.push("no_results");
|
|
2140
|
+
} else {
|
|
2141
|
+
const micros = BigInt(money2.amountMicros);
|
|
2142
|
+
let quotient = micros / results;
|
|
2143
|
+
const twice = 2n * (micros % results);
|
|
2144
|
+
if (twice > results || twice === results && quotient % 2n === 1n) quotient += 1n;
|
|
2145
|
+
costPerResult = { state: "observed", money: { currency: money2.currency, amountMicros: quotient.toString() } };
|
|
2146
|
+
}
|
|
2147
|
+
return { frequency, costPerResult, reasonCodes: reasons };
|
|
2148
|
+
}
|
|
1845
2149
|
|
|
1846
2150
|
exports.MAX_MONEY_MICROS = MAX_MONEY_MICROS;
|
|
2151
|
+
exports.META_AUDIENCE_RULE_LIMIT = META_AUDIENCE_RULE_LIMIT;
|
|
2152
|
+
exports.META_CALL_TO_ACTIONS = META_CALL_TO_ACTIONS;
|
|
2153
|
+
exports.META_SAC_CUSTOM_AUDIENCE_EXCLUSION_VERIFIED = META_SAC_CUSTOM_AUDIENCE_EXCLUSION_VERIFIED;
|
|
2154
|
+
exports.META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS = META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS;
|
|
1847
2155
|
exports.MONEY_EXPONENT = MONEY_EXPONENT;
|
|
1848
2156
|
exports.MONEY_JSON_SCHEMA = MONEY_JSON_SCHEMA;
|
|
1849
2157
|
exports.RESONANCE_ACCEPT_COMMAND_JSON_SCHEMA = RESONANCE_ACCEPT_COMMAND_JSON_SCHEMA;
|
|
@@ -1885,16 +2193,21 @@ exports.RESONANCE_MANDATE_DRAFT_REQUEST_JSON_SCHEMA = RESONANCE_MANDATE_DRAFT_RE
|
|
|
1885
2193
|
exports.RESONANCE_MANDATE_REF_JSON_SCHEMA = RESONANCE_MANDATE_REF_JSON_SCHEMA;
|
|
1886
2194
|
exports.RESONANCE_MANDATE_SCOPE_JSON_SCHEMA = RESONANCE_MANDATE_SCOPE_JSON_SCHEMA;
|
|
1887
2195
|
exports.RESONANCE_MANDATE_TARGET_JSON_SCHEMA = RESONANCE_MANDATE_TARGET_JSON_SCHEMA;
|
|
2196
|
+
exports.RESONANCE_MAX_CHANNELS_PER_GROUP = RESONANCE_MAX_CHANNELS_PER_GROUP;
|
|
1888
2197
|
exports.RESONANCE_MEASUREMENT_CONFIGURATION_CURRENT_JSON_SCHEMA = RESONANCE_MEASUREMENT_CONFIGURATION_CURRENT_JSON_SCHEMA;
|
|
1889
2198
|
exports.RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA = RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA;
|
|
1890
2199
|
exports.RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA = RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA;
|
|
1891
2200
|
exports.RESONANCE_MEASUREMENT_CONFIGURATION_SNAPSHOT_JSON_SCHEMA = RESONANCE_MEASUREMENT_CONFIGURATION_SNAPSHOT_JSON_SCHEMA;
|
|
1892
2201
|
exports.RESONANCE_MEASUREMENT_CONFIG_JSON_SCHEMA = RESONANCE_MEASUREMENT_CONFIG_JSON_SCHEMA;
|
|
1893
2202
|
exports.RESONANCE_MEASUREMENT_OCCURRENCE_JSON_SCHEMA = RESONANCE_MEASUREMENT_OCCURRENCE_JSON_SCHEMA;
|
|
2203
|
+
exports.RESONANCE_META_AUDIENCE_REASONS = RESONANCE_META_AUDIENCE_REASONS;
|
|
2204
|
+
exports.RESONANCE_META_AUDIENCE_VERDICTS = RESONANCE_META_AUDIENCE_VERDICTS;
|
|
1894
2205
|
exports.RESONANCE_META_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA = RESONANCE_META_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA;
|
|
1895
2206
|
exports.RESONANCE_META_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA = RESONANCE_META_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA;
|
|
1896
2207
|
exports.RESONANCE_META_CONFIGURATION_SNAPSHOT_JSON_SCHEMA = RESONANCE_META_CONFIGURATION_SNAPSHOT_JSON_SCHEMA;
|
|
1897
2208
|
exports.RESONANCE_META_CONFIGURATION_VIEW_JSON_SCHEMA = RESONANCE_META_CONFIGURATION_VIEW_JSON_SCHEMA;
|
|
2209
|
+
exports.RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS = RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS;
|
|
2210
|
+
exports.RESONANCE_META_RETARGETING_READINESS_JSON_SCHEMA = RESONANCE_META_RETARGETING_READINESS_JSON_SCHEMA;
|
|
1898
2211
|
exports.RESONANCE_METRIC_JSON_SCHEMA = RESONANCE_METRIC_JSON_SCHEMA;
|
|
1899
2212
|
exports.RESONANCE_OBSERVATIONS_PAGE_JSON_SCHEMA = RESONANCE_OBSERVATIONS_PAGE_JSON_SCHEMA;
|
|
1900
2213
|
exports.RESONANCE_OBSERVATION_SUPPORT_JSON_SCHEMA = RESONANCE_OBSERVATION_SUPPORT_JSON_SCHEMA;
|
|
@@ -1903,6 +2216,7 @@ exports.RESONANCE_OPTIMIZATION_DECISION_JSON_SCHEMA = RESONANCE_OPTIMIZATION_DEC
|
|
|
1903
2216
|
exports.RESONANCE_OPTIMIZATION_EVIDENCE_JSON_SCHEMA = RESONANCE_OPTIMIZATION_EVIDENCE_JSON_SCHEMA;
|
|
1904
2217
|
exports.RESONANCE_OPTIMIZATION_POLICY_JSON_SCHEMA = RESONANCE_OPTIMIZATION_POLICY_JSON_SCHEMA;
|
|
1905
2218
|
exports.RESONANCE_PREPARED_PLAN_JSON_SCHEMA = RESONANCE_PREPARED_PLAN_JSON_SCHEMA;
|
|
2219
|
+
exports.RESONANCE_PROVIDER_METRIC_NAMES = RESONANCE_PROVIDER_METRIC_NAMES;
|
|
1906
2220
|
exports.RESONANCE_PROVIDER_REPORTING_GRANT_JSON_SCHEMA = RESONANCE_PROVIDER_REPORTING_GRANT_JSON_SCHEMA;
|
|
1907
2221
|
exports.RESONANCE_PROVIDER_REPORTING_SELECTION_JSON_SCHEMA = RESONANCE_PROVIDER_REPORTING_SELECTION_JSON_SCHEMA;
|
|
1908
2222
|
exports.RESONANCE_PUBLIC_OBSERVATION_METRIC_JSON_SCHEMA = RESONANCE_PUBLIC_OBSERVATION_METRIC_JSON_SCHEMA;
|
|
@@ -1921,11 +2235,16 @@ exports.RESONANCE_WEBSITE_VISIT_FEED_REVIEW_JSON_SCHEMA = RESONANCE_WEBSITE_VISI
|
|
|
1921
2235
|
exports.RESONANCE_WEBSITE_VISIT_PROFILE = RESONANCE_WEBSITE_VISIT_PROFILE;
|
|
1922
2236
|
exports.ResonanceValidationError = ResonanceValidationError;
|
|
1923
2237
|
exports.addMoney = addMoney;
|
|
2238
|
+
exports.checkAudienceBand = checkAudienceBand;
|
|
2239
|
+
exports.checkChannelGroups = checkChannelGroups;
|
|
1924
2240
|
exports.compareMoney = compareMoney;
|
|
1925
2241
|
exports.cpqlMissingOutcomeBound = cpqlMissingOutcomeBound;
|
|
2242
|
+
exports.deriveProviderRatios = deriveProviderRatios;
|
|
2243
|
+
exports.expandPropertyChannels = expandPropertyChannels;
|
|
1926
2244
|
exports.formatMoney = formatMoney;
|
|
1927
2245
|
exports.googleConversionActionSemantics = googleConversionActionSemantics;
|
|
1928
2246
|
exports.googleUploadClicksSetupSemantics = googleUploadClicksSetupSemantics;
|
|
2247
|
+
exports.metaExclusionPolicy = metaExclusionPolicy;
|
|
1929
2248
|
exports.moneyFromProviderUnits = moneyFromProviderUnits;
|
|
1930
2249
|
exports.moneyToProviderUnits = moneyToProviderUnits;
|
|
1931
2250
|
exports.parseMoney = parseMoney;
|
|
@@ -1974,6 +2293,7 @@ exports.parseResonanceMetaConfigurationSaveCommand = parseResonanceMetaConfigura
|
|
|
1974
2293
|
exports.parseResonanceMetaConfigurationSaveResponse = parseResonanceMetaConfigurationSaveResponse;
|
|
1975
2294
|
exports.parseResonanceMetaConfigurationSnapshot = parseResonanceMetaConfigurationSnapshot;
|
|
1976
2295
|
exports.parseResonanceMetaConfigurationView = parseResonanceMetaConfigurationView;
|
|
2296
|
+
exports.parseResonanceMetaRetargetingReadiness = parseResonanceMetaRetargetingReadiness;
|
|
1977
2297
|
exports.parseResonanceMetricObservation = parseResonanceMetricObservation;
|
|
1978
2298
|
exports.parseResonanceObservationSupport = parseResonanceObservationSupport;
|
|
1979
2299
|
exports.parseResonanceObservationsPage = parseResonanceObservationsPage;
|
|
@@ -2011,4 +2331,6 @@ exports.resonanceOptimizationPolicyDigestInput = resonanceOptimizationPolicyDige
|
|
|
2011
2331
|
exports.resonancePlanIssues = resonancePlanIssues;
|
|
2012
2332
|
exports.resonanceWebsiteVisitEventTime = resonanceWebsiteVisitEventTime;
|
|
2013
2333
|
exports.resonanceWebsiteVisitProfileDigestInput = resonanceWebsiteVisitProfileDigestInput;
|
|
2334
|
+
exports.splitBudget = splitBudget;
|
|
2014
2335
|
exports.subtractMoney = subtractMoney;
|
|
2336
|
+
exports.suggestPropertyWeights = suggestPropertyWeights;
|