@sonordev/contracts 2.28.0 → 2.29.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 +9 -0
- package/README.md +135 -0
- package/dist/delegated-command.d.ts +271 -0
- package/dist/delegated-command.js +2224 -0
- package/dist/delegated-command.mjs +2197 -0
- package/dist/resonance-confirmation.d.ts +33 -11
- package/dist/resonance-confirmation.js +61 -8
- package/dist/resonance-confirmation.mjs +56 -9
- package/dist/resonance.d.ts +993 -0
- package/dist/resonance.js +820 -528
- package/dist/resonance.mjs +803 -529
- package/dist/wire-native-cas.d.ts +7 -0
- package/package.json +6 -1
package/dist/resonance.mjs
CHANGED
|
@@ -7,31 +7,31 @@ var RESONANCE_SOURCE_MARKER_PARAMETER = "sonor_source";
|
|
|
7
7
|
var RESONANCE_SUBJECT_HEADER = "X-Sonor-Resonance-Subject";
|
|
8
8
|
|
|
9
9
|
// src/contracts/wire-schema.ts
|
|
10
|
-
function createWireSchema(
|
|
10
|
+
function createWireSchema(fail4, isValidationError) {
|
|
11
11
|
const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);
|
|
12
12
|
const field3 = (schema, read) => ({ schema, read });
|
|
13
|
-
const
|
|
14
|
-
const choice3 = (...values) => field3({ type: "string", enum: values }, (v, p) => typeof v === "string" && values.includes(v) ? v :
|
|
15
|
-
const literal3 = (value) => field3({ const: value }, (v, p) => v === value ? value :
|
|
16
|
-
const integer3 = (min = 0, max = Number.MAX_SAFE_INTEGER) => field3({ type: "integer", minimum: min, maximum: max }, (v, p) => typeof v === "number" && Number.isSafeInteger(v) && v >= min && v <= max ? v :
|
|
17
|
-
const bool2 = field3({ type: "boolean" }, (v, p) => typeof v === "boolean" ? v :
|
|
13
|
+
const text4 = (max = 200, pattern, min = 1) => field3({ type: "string", minLength: min, maxLength: max, ...pattern ? { pattern: pattern.source } : {} }, (v, p) => typeof v === "string" && v.length >= min && v.length <= max && (!pattern || pattern.test(v)) ? v : fail4(p, "invalid string"));
|
|
14
|
+
const choice3 = (...values) => field3({ type: "string", enum: values }, (v, p) => typeof v === "string" && values.includes(v) ? v : fail4(p, "unsupported value"));
|
|
15
|
+
const literal3 = (value) => field3({ const: value }, (v, p) => v === value ? value : fail4(p, "unexpected value"));
|
|
16
|
+
const integer3 = (min = 0, max = Number.MAX_SAFE_INTEGER) => field3({ type: "integer", minimum: min, maximum: max }, (v, p) => typeof v === "number" && Number.isSafeInteger(v) && v >= min && v <= max ? v : fail4(p, "invalid integer"));
|
|
17
|
+
const bool2 = field3({ type: "boolean" }, (v, p) => typeof v === "boolean" ? v : fail4(p, "must be boolean"));
|
|
18
18
|
const optional3 = (f) => ({ ...f, optional: true });
|
|
19
19
|
const nullable3 = (f) => field3({ anyOf: [f.schema, { type: "null" }] }, (v, p) => v === null ? null : f.read(v, p));
|
|
20
20
|
const list3 = (f, max = 100, min = 0) => field3({ type: "array", items: f.schema, minItems: min, maxItems: max }, (v, p) => {
|
|
21
|
-
if (!Array.isArray(v) || v.length < min || v.length > max)
|
|
21
|
+
if (!Array.isArray(v) || v.length < min || v.length > max) fail4(p, "invalid array");
|
|
22
22
|
return v.map((x, i) => f.read(x, `${p}[${i}]`));
|
|
23
23
|
});
|
|
24
24
|
const object3 = (fields2) => field3({ type: "object", additionalProperties: false, properties: Object.fromEntries(Object.entries(fields2).map(([k, f]) => [k, f.schema])), required: Object.keys(fields2).filter((k) => !("optional" in fields2[k])) }, (v, p) => {
|
|
25
|
-
if (!v || typeof v !== "object" || Array.isArray(v) || ![Object.prototype, null].includes(Object.getPrototypeOf(v)))
|
|
25
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) fail4(p, "must be a plain object");
|
|
26
26
|
const source2 = v, result = {};
|
|
27
|
-
for (const key of Reflect.ownKeys(source2)) if (typeof key !== "string" || !own(fields2, key))
|
|
27
|
+
for (const key of Reflect.ownKeys(source2)) if (typeof key !== "string" || !own(fields2, key)) fail4(p, "unknown field");
|
|
28
28
|
for (const [key, f] of Object.entries(fields2)) {
|
|
29
29
|
if (!own(source2, key)) {
|
|
30
30
|
if ("optional" in f) continue;
|
|
31
|
-
|
|
31
|
+
fail4(`${p}.${key}`, "required");
|
|
32
32
|
}
|
|
33
33
|
const descriptor = Object.getOwnPropertyDescriptor(source2, key);
|
|
34
|
-
if (!own(descriptor, "value"))
|
|
34
|
+
if (!own(descriptor, "value")) fail4(`${p}.${key}`, "accessors are not wire data");
|
|
35
35
|
result[key] = f.read(descriptor.value, `${p}.${key}`);
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
@@ -45,16 +45,35 @@ function createWireSchema(fail3, isValidationError) {
|
|
|
45
45
|
if (!isValidationError(e)) throw e;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
return found.length === 1 ? found[0] :
|
|
48
|
+
return found.length === 1 ? found[0] : fail4(p, "must match exactly one supported shape");
|
|
49
49
|
});
|
|
50
|
-
const
|
|
50
|
+
const refine4 = (f, check) => field3(f.schema, (v, p) => {
|
|
51
51
|
const result = f.read(v, p);
|
|
52
52
|
check(result, p);
|
|
53
53
|
return result;
|
|
54
54
|
});
|
|
55
|
-
return { field: field3, text:
|
|
55
|
+
return { field: field3, text: text4, choice: choice3, literal: literal3, integer: integer3, bool: bool2, optional: optional3, nullable: nullable3, list: list3, object: object3, union: union3, refine: refine4 };
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// src/contracts/wire-native-cas.ts
|
|
59
|
+
var NativeCasTimestampValidationError = class extends Error {
|
|
60
|
+
constructor(path2, reason) {
|
|
61
|
+
super(`${path2}: ${reason}`);
|
|
62
|
+
this.path = path2;
|
|
63
|
+
this.name = "NativeCasTimestampValidationError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var fail = (path2, reason) => {
|
|
67
|
+
throw new NativeCasTimestampValidationError(path2, reason);
|
|
68
|
+
};
|
|
69
|
+
var { text, refine } = createWireSchema(fail, (error) => error instanceof NativeCasTimestampValidationError);
|
|
70
|
+
var timestamp = refine(text(32, /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d{1,6})?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/), (v, p) => {
|
|
71
|
+
const calendar = v.slice(0, 19) + "Z";
|
|
72
|
+
if (v.startsWith("0000") || !Number.isFinite(Date.parse(calendar)) || new Date(calendar).toISOString().slice(0, 19) !== v.slice(0, 19)) fail(p, "invalid native CAS calendar timestamp");
|
|
73
|
+
});
|
|
74
|
+
var parseNativeCasTimestamp = (v) => timestamp.read(v, "nativeCasTimestamp");
|
|
75
|
+
var NATIVE_CAS_TIMESTAMP_JSON_SCHEMA = timestamp.schema;
|
|
76
|
+
|
|
58
77
|
// src/contracts/sites-normalize.ts
|
|
59
78
|
function stripWww(host) {
|
|
60
79
|
return host.startsWith("www.") ? host.slice(4) : host;
|
|
@@ -128,37 +147,37 @@ var SignalExperimentValidationError = class extends Error {
|
|
|
128
147
|
this.name = "SignalExperimentValidationError";
|
|
129
148
|
}
|
|
130
149
|
};
|
|
131
|
-
var
|
|
150
|
+
var fail2 = (path2, reason) => {
|
|
132
151
|
throw new SignalExperimentValidationError(path2, reason);
|
|
133
152
|
};
|
|
134
|
-
var { field, text, choice, literal, integer, optional, nullable, list, object, union, refine } = createWireSchema(
|
|
135
|
-
var percent = field({ type: "number", minimum: 0, maximum: 100 }, (v, p) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 100 ? v :
|
|
136
|
-
var page =
|
|
153
|
+
var { field, text: text2, choice, literal, integer, optional, nullable, list, object, union, refine: refine2 } = createWireSchema(fail2, (error) => error instanceof SignalExperimentValidationError);
|
|
154
|
+
var percent = field({ type: "number", minimum: 0, maximum: 100 }, (v, p) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 100 ? v : fail2(p, "must be a finite percentage from 0 to 100"));
|
|
155
|
+
var page = refine2(text2(2048, /^\/(?!\/)[^?#\s\\]*$/), (v, p) => {
|
|
137
156
|
const parsed = new URL(v, "https://example.com");
|
|
138
|
-
if (parsed.pathname !== v)
|
|
157
|
+
if (parsed.pathname !== v) fail2(p, "must be a canonical page path");
|
|
139
158
|
});
|
|
140
|
-
var variant = object({ key:
|
|
141
|
-
var variants =
|
|
142
|
-
if (new Set(v.map((x) => x.key)).size !== v.length)
|
|
143
|
-
if (Math.abs(v.reduce((sum, x) => sum + x.weight, 0) - 100) > 0.01)
|
|
159
|
+
var variant = object({ key: text2(80), name: text2(160), weight: percent, description: optional(text2(1e3, void 0, 0)) });
|
|
160
|
+
var variants = refine2(list(variant, 50, 2), (v, p) => {
|
|
161
|
+
if (new Set(v.map((x) => x.key)).size !== v.length) fail2(p, "variant keys must be unique");
|
|
162
|
+
if (Math.abs(v.reduce((sum, x) => sum + x.weight, 0) - 100) > 0.01) fail2(p, "variant weights must sum to 100");
|
|
144
163
|
});
|
|
145
|
-
var targeting = object({ pages: optional(list(page, 100)), segments: optional(list(
|
|
146
|
-
var fields = { name:
|
|
164
|
+
var targeting = object({ pages: optional(list(page, 100)), segments: optional(list(text2(160), 100)), devices: optional(list(choice("desktop", "mobile", "tablet"), 3)), geo: optional(list(text2(160), 100)) });
|
|
165
|
+
var fields = { name: text2(160), description: text2(1e4, void 0, 0), variants, traffic_allocation: percent, targeting_rules: targeting };
|
|
147
166
|
var create = object({ ...fields, description: optional(fields.description), traffic_allocation: optional(fields.traffic_allocation), targeting_rules: optional(fields.targeting_rules) });
|
|
148
167
|
var update = object({ name: optional(fields.name), description: optional(fields.description), variants: optional(fields.variants), traffic_allocation: optional(fields.traffic_allocation), targeting_rules: optional(fields.targeting_rules) });
|
|
149
168
|
var parseSignalExperimentCreate = (v) => create.read(v, "experimentCreate");
|
|
150
169
|
var parseSignalExperimentUpdate = (v) => update.read(v, "experimentUpdate");
|
|
151
170
|
var SIGNAL_EXPERIMENT_CREATE_JSON_SCHEMA = create.schema;
|
|
152
171
|
var SIGNAL_EXPERIMENT_UPDATE_JSON_SCHEMA = update.schema;
|
|
153
|
-
var measurementUuid =
|
|
154
|
-
var measurementRevision =
|
|
155
|
-
var measurementInstant =
|
|
156
|
-
if (!Number.isFinite(Date.parse(v)) || new Date(v).toISOString().replace(".000Z", "Z") !== v.replace(".000Z", "Z"))
|
|
172
|
+
var measurementUuid = text2(36, UUID_V1_TO_V8_PATTERN);
|
|
173
|
+
var measurementRevision = text2(128, /^[a-zA-Z0-9._:-]+$/);
|
|
174
|
+
var measurementInstant = refine2(text2(30, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/), (v, p) => {
|
|
175
|
+
if (!Number.isFinite(Date.parse(v)) || new Date(v).toISOString().replace(".000Z", "Z") !== v.replace(".000Z", "Z")) fail2(p, "invalid UTC instant");
|
|
157
176
|
});
|
|
158
|
-
var measurementSite =
|
|
159
|
-
if (!isNormalizedSiteHost(v) || isBlockedPublicUrlHost(v))
|
|
177
|
+
var measurementSite = refine2(text2(253), (v, p) => {
|
|
178
|
+
if (!isNormalizedSiteHost(v) || isBlockedPublicUrlHost(v)) fail2(p, "must be a normalized public site host");
|
|
160
179
|
});
|
|
161
|
-
var measurementCount =
|
|
180
|
+
var measurementCount = text2(30, /^(?:0|[1-9][0-9]*)$/);
|
|
162
181
|
var measurementScope = object({
|
|
163
182
|
projectId: measurementUuid,
|
|
164
183
|
experimentId: measurementUuid,
|
|
@@ -171,7 +190,7 @@ var measurementScope = object({
|
|
|
171
190
|
assignedTo: measurementInstant
|
|
172
191
|
});
|
|
173
192
|
var assignmentCounts = {
|
|
174
|
-
variantKey:
|
|
193
|
+
variantKey: text2(80),
|
|
175
194
|
assignedUnits: measurementCount,
|
|
176
195
|
exposureEvents: measurementCount,
|
|
177
196
|
exposedUnits: measurementCount,
|
|
@@ -201,7 +220,7 @@ var observedFields = {
|
|
|
201
220
|
semanticRole: literal("accepted_form_diagnostic"),
|
|
202
221
|
businessMetrics
|
|
203
222
|
};
|
|
204
|
-
var observedMeasurement =
|
|
223
|
+
var observedMeasurement = refine2(union(
|
|
205
224
|
object({
|
|
206
225
|
...observedFields,
|
|
207
226
|
originalGoal: object({ ...originalGoalFields, sourceKind: formSourceKind }),
|
|
@@ -218,17 +237,17 @@ var observedMeasurement = refine(union(
|
|
|
218
237
|
})
|
|
219
238
|
), (value, p) => {
|
|
220
239
|
if (Date.parse(value.scope.assignedFrom) >= Date.parse(value.scope.assignedTo) || Date.parse(value.scope.assignedTo) > Date.parse(value.observedAt))
|
|
221
|
-
|
|
222
|
-
if (new Set(value.variants.map((v) => v.variantKey)).size !== value.variants.length)
|
|
240
|
+
fail2(p + ".scope", "requires an increasing assignment cohort ending by the native observation");
|
|
241
|
+
if (new Set(value.variants.map((v) => v.variantKey)).size !== value.variants.length) fail2(p + ".variants", "variant keys must be unique");
|
|
223
242
|
for (const [index, v] of value.variants.entries()) {
|
|
224
243
|
const assigned = BigInt(v.assignedUnits), exposed = BigInt(v.exposedUnits), mature = BigInt(v.matureAssignedUnits);
|
|
225
244
|
const at = `${p}.variants[${index}]`;
|
|
226
245
|
if (exposed > assigned || BigInt(v.exposureEvents) < exposed || BigInt(v.assignmentsWithoutExposure) !== assigned - exposed || mature + BigInt(v.immatureAssignedUnits) !== assigned)
|
|
227
|
-
|
|
246
|
+
fail2(at, "assignment, exposure and maturity counts are inconsistent");
|
|
228
247
|
if (v.acceptedFormUnits !== null && v.acceptedFormEvents !== null && v.matureAcceptedFormUnits !== null) {
|
|
229
248
|
const accepted = BigInt(v.acceptedFormUnits), matureAccepted = BigInt(v.matureAcceptedFormUnits);
|
|
230
249
|
if (accepted > exposed || accepted > BigInt(v.acceptedFormEvents) || matureAccepted > mature || matureAccepted > accepted)
|
|
231
|
-
|
|
250
|
+
fail2(at, "accepted form units must remain within their exposed, event and mature cohorts");
|
|
232
251
|
}
|
|
233
252
|
}
|
|
234
253
|
});
|
|
@@ -247,11 +266,11 @@ var scopeOption = object({
|
|
|
247
266
|
experimentId: measurementUuid,
|
|
248
267
|
experimentRevision: integer(1),
|
|
249
268
|
goalRevision: measurementRevision,
|
|
250
|
-
goalLabel: nullable(
|
|
269
|
+
goalLabel: nullable(text2(200)),
|
|
251
270
|
assignmentExtent: nullable(object({ firstAssignedAt: measurementInstant, lastAssignedAt: measurementInstant })),
|
|
252
271
|
suggestedCohort: nullable(object({ assignedFrom: measurementInstant, assignedTo: measurementInstant }))
|
|
253
272
|
});
|
|
254
|
-
var scopeOptions =
|
|
273
|
+
var scopeOptions = refine2(object({ observedAt: measurementInstant, items: list(scopeOption, 100), nextCursor: nullable(text2(4096)) }), (value, p) => {
|
|
255
274
|
const observed = Date.parse(value.observedAt), tuples = /* @__PURE__ */ new Set();
|
|
256
275
|
for (const [index, item] of value.items.entries()) {
|
|
257
276
|
const at = `${p}.items[${index}]`, accepted = Date.parse(item.acceptedAt);
|
|
@@ -263,16 +282,16 @@ var scopeOptions = refine(object({ observedAt: measurementInstant, items: list(s
|
|
|
263
282
|
item.experimentRevision,
|
|
264
283
|
item.goalRevision
|
|
265
284
|
]);
|
|
266
|
-
if (tuples.has(tuple))
|
|
285
|
+
if (tuples.has(tuple)) fail2(at, "original scope tuples must be unique");
|
|
267
286
|
tuples.add(tuple);
|
|
268
|
-
if (accepted > observed)
|
|
287
|
+
if (accepted > observed) fail2(at + ".acceptedAt", "must not follow the native observation");
|
|
269
288
|
if (item.assignmentExtent) {
|
|
270
289
|
const first = Date.parse(item.assignmentExtent.firstAssignedAt), last = Date.parse(item.assignmentExtent.lastAssignedAt);
|
|
271
|
-
if (first > last || last > observed)
|
|
290
|
+
if (first > last || last > observed) fail2(at + ".assignmentExtent", "requires first <= last <= native observation");
|
|
272
291
|
}
|
|
273
292
|
if (item.suggestedCohort) {
|
|
274
293
|
const from = Date.parse(item.suggestedCohort.assignedFrom), to = Date.parse(item.suggestedCohort.assignedTo);
|
|
275
|
-
if (from !== accepted || from >= to || to > observed)
|
|
294
|
+
if (from !== accepted || from >= to || to > observed) fail2(at + ".suggestedCohort", "requires original acceptance start and increasing cohort ending by native observation");
|
|
276
295
|
}
|
|
277
296
|
}
|
|
278
297
|
});
|
|
@@ -296,29 +315,29 @@ var ResonanceValidationError = class extends Error {
|
|
|
296
315
|
this.name = "ResonanceValidationError";
|
|
297
316
|
}
|
|
298
317
|
};
|
|
299
|
-
var
|
|
318
|
+
var fail3 = (path2, reason) => {
|
|
300
319
|
throw new ResonanceValidationError(path2, reason);
|
|
301
320
|
};
|
|
302
|
-
var { field: field2, text:
|
|
303
|
-
var uuid =
|
|
304
|
-
var digest =
|
|
305
|
-
var revision =
|
|
306
|
-
var instant =
|
|
307
|
-
if (!Number.isFinite(Date.parse(v)) || new Date(v).toISOString().replace(".000Z", "Z") !== v.replace(".000Z", "Z"))
|
|
308
|
-
});
|
|
309
|
-
var timeZone =
|
|
321
|
+
var { field: field2, text: text3, choice: choice2, literal: literal2, integer: integer2, bool, optional: optional2, nullable: nullable2, list: list2, object: object2, union: union2, refine: refine3 } = createWireSchema(fail3, (error) => error instanceof ResonanceValidationError);
|
|
322
|
+
var uuid = text3(36, UUID_V1_TO_V8_PATTERN);
|
|
323
|
+
var digest = text3(64, /^[a-f0-9]{64}$/);
|
|
324
|
+
var revision = text3(128, /^[a-zA-Z0-9._:-]+$/);
|
|
325
|
+
var instant = refine3(text3(30, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/), (v, p) => {
|
|
326
|
+
if (!Number.isFinite(Date.parse(v)) || new Date(v).toISOString().replace(".000Z", "Z") !== v.replace(".000Z", "Z")) fail3(p, "invalid UTC instant");
|
|
327
|
+
});
|
|
328
|
+
var timeZone = refine3(text3(80), (v, p) => {
|
|
310
329
|
try {
|
|
311
330
|
new Intl.DateTimeFormat("en", { timeZone: v });
|
|
312
331
|
} catch {
|
|
313
|
-
|
|
332
|
+
fail3(p, "invalid IANA timezone");
|
|
314
333
|
}
|
|
315
334
|
});
|
|
316
|
-
var site =
|
|
317
|
-
if (!isNormalizedSiteHost(v) || isBlockedPublicUrlHost(v))
|
|
335
|
+
var site = refine3(text3(253), (v, p) => {
|
|
336
|
+
if (!isNormalizedSiteHost(v) || isBlockedPublicUrlHost(v)) fail3(p, "must be a normalized public site host");
|
|
318
337
|
});
|
|
319
|
-
var path =
|
|
320
|
-
var decimal =
|
|
321
|
-
var operationKey =
|
|
338
|
+
var path = text3(2048, /^\/(?!\/)[^?#\s\\]*$/);
|
|
339
|
+
var decimal = text3(30, /^(?:0|[1-9][0-9]{0,29})$/);
|
|
340
|
+
var operationKey = text3(200, /^[a-zA-Z0-9._:-]+$/);
|
|
322
341
|
var objectiveCountingUnit = choice2("unique_source", "unique_qualified_contact", "net_order");
|
|
323
342
|
var RESONANCE_CURRENCIES = ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SLL", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XCG", "XDR", "XOF", "XPF", "XSU", "YER", "ZAR", "ZMW", "ZWG", "ZWL"];
|
|
324
343
|
var currency = choice2(...RESONANCE_CURRENCIES);
|
|
@@ -327,28 +346,28 @@ var parseMoney = (value) => money.read(value, "money");
|
|
|
327
346
|
function addMoney(a, b) {
|
|
328
347
|
a = parseMoney(a);
|
|
329
348
|
b = parseMoney(b);
|
|
330
|
-
if (a.currency !== b.currency)
|
|
349
|
+
if (a.currency !== b.currency) fail3("money.currency", "currency mismatch; no implicit FX");
|
|
331
350
|
return parseMoney({ currency: a.currency, amountMicros: (BigInt(a.amountMicros) + BigInt(b.amountMicros)).toString() });
|
|
332
351
|
}
|
|
333
352
|
function moneyToProviderUnits(input, account) {
|
|
334
353
|
const m = parseMoney(input);
|
|
335
354
|
currency.read(account.currency, "account.currency");
|
|
336
355
|
decimal.read(account.maxUnits, "account.maxUnits");
|
|
337
|
-
if (m.currency !== account.currency)
|
|
338
|
-
if (![0, 2, 3, 6].includes(account.unitExponent))
|
|
356
|
+
if (m.currency !== account.currency) fail3("money.currency", "currency mismatch");
|
|
357
|
+
if (![0, 2, 3, 6].includes(account.unitExponent)) fail3("account.unitExponent", "unsupported provider exponent");
|
|
339
358
|
const factor = 10n ** BigInt(6 - account.unitExponent), amount = BigInt(m.amountMicros);
|
|
340
|
-
if (amount % factor !== 0n)
|
|
359
|
+
if (amount % factor !== 0n) fail3("money.amountMicros", "not exactly representable in provider units");
|
|
341
360
|
const units = amount / factor;
|
|
342
|
-
if (units > BigInt(account.maxUnits))
|
|
361
|
+
if (units > BigInt(account.maxUnits)) fail3("money.amountMicros", "provider overflow");
|
|
343
362
|
return units.toString();
|
|
344
363
|
}
|
|
345
364
|
function moneyFromProviderUnits(units, account) {
|
|
346
365
|
decimal.read(units, "provider.units");
|
|
347
|
-
if (![0, 2, 3, 6].includes(account.unitExponent))
|
|
366
|
+
if (![0, 2, 3, 6].includes(account.unitExponent)) fail3("account.unitExponent", "unsupported provider exponent");
|
|
348
367
|
return parseMoney({ currency: account.currency, amountMicros: (BigInt(units) * 10n ** BigInt(6 - account.unitExponent)).toString() });
|
|
349
368
|
}
|
|
350
369
|
var MONEY_JSON_SCHEMA = money.schema;
|
|
351
|
-
var sourceMarker =
|
|
370
|
+
var sourceMarker = text3(1536, /^rsm1\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{43}$/);
|
|
352
371
|
var parseResonanceSourceMarker = (v) => sourceMarker.read(v, "sourceMarker");
|
|
353
372
|
var RESONANCE_SOURCE_MARKER_JSON_SCHEMA = sourceMarker.schema;
|
|
354
373
|
var scope = { projectId: uuid, site };
|
|
@@ -358,13 +377,13 @@ var qualificationFields = { schemaVersion: literal2(1), semantics: literal2("cur
|
|
|
358
377
|
var checkQualificationPartitions = (v, p) => {
|
|
359
378
|
unique([...v.positiveStageKeys, ...v.finalNegativeStageKeys, ...v.pendingStageKeys], p + ".stagePartitions");
|
|
360
379
|
};
|
|
361
|
-
var qualificationRule =
|
|
380
|
+
var qualificationRule = refine3(object2({ ...qualificationFields, attributionModel: literal2(RESONANCE_ATTRIBUTION_MODEL) }), checkQualificationPartitions);
|
|
362
381
|
var parseResonanceQualificationRule = (v) => qualificationRule.read(v, "qualificationRule");
|
|
363
382
|
var RESONANCE_QUALIFICATION_RULE_JSON_SCHEMA = qualificationRule.schema;
|
|
364
|
-
var resolvedQualificationRule =
|
|
383
|
+
var resolvedQualificationRule = refine3(object2({
|
|
365
384
|
...qualificationFields,
|
|
366
385
|
ref: resource,
|
|
367
|
-
crmVariant:
|
|
386
|
+
crmVariant: text3(128),
|
|
368
387
|
ladderSnapshot: list2(object2({ id: nullable2(uuid), stage_key: revision, semantic_key: nullable2(revision), is_won: bool, is_lost: bool }), 500, 1),
|
|
369
388
|
// eligibleBookingTypeIds: Sync booking types whose confirmed bookings also count, beside the one form. Absent means forms only.
|
|
370
389
|
eligibleFormIds: list2(uuid, 500, 1),
|
|
@@ -373,18 +392,18 @@ var resolvedQualificationRule = refine2(object2({
|
|
|
373
392
|
cohort: object2({ startAt: instant, endAt: instant, maturityDelaySeconds: integer2(0, 31536e3) })
|
|
374
393
|
}), (v, p) => {
|
|
375
394
|
checkQualificationPartitions(v, p);
|
|
376
|
-
if (v.ref.module !== "crm" || v.ref.id !== v.ref.projectId)
|
|
395
|
+
if (v.ref.module !== "crm" || v.ref.id !== v.ref.projectId) fail3(p + ".ref", "must reference the actual CRM project configuration");
|
|
377
396
|
unique(v.eligibleFormIds, p + ".eligibleFormIds");
|
|
378
397
|
if (v.eligibleBookingTypeIds) unique(v.eligibleBookingTypeIds.map((x) => x.toLowerCase()), p + ".eligibleBookingTypeIds");
|
|
379
398
|
unique(v.ladderSnapshot.flatMap((x) => x.id ? [x.id] : []), p + ".ladderSnapshot.id");
|
|
380
399
|
unique(v.ladderSnapshot.map((x) => x.stage_key), p + ".ladderSnapshot.stage_key");
|
|
381
400
|
const partitions = [...v.positiveStageKeys, ...v.finalNegativeStageKeys, ...v.pendingStageKeys], keys = new Set(v.ladderSnapshot.map((x) => x.stage_key));
|
|
382
|
-
if (partitions.length !== keys.size || partitions.some((k) => !keys.has(k)))
|
|
383
|
-
if (Date.parse(v.cohort.endAt) <= Date.parse(v.cohort.startAt))
|
|
401
|
+
if (partitions.length !== keys.size || partitions.some((k) => !keys.has(k))) fail3(p + ".stagePartitions", "must exhaust the actual native ladder");
|
|
402
|
+
if (Date.parse(v.cohort.endAt) <= Date.parse(v.cohort.startAt)) fail3(p + ".cohort", "invalid cohort interval");
|
|
384
403
|
});
|
|
385
404
|
var parseResonanceResolvedQualificationRule = (v) => resolvedQualificationRule.read(v, "resolvedQualificationRule");
|
|
386
405
|
var RESONANCE_RESOLVED_QUALIFICATION_RULE_JSON_SCHEMA = resolvedQualificationRule.schema;
|
|
387
|
-
var objective =
|
|
406
|
+
var objective = refine3(object2({
|
|
388
407
|
source,
|
|
389
408
|
measurementRevision: revision,
|
|
390
409
|
countingUnit: objectiveCountingUnit,
|
|
@@ -396,23 +415,23 @@ var objective = refine2(object2({
|
|
|
396
415
|
eligibleBookingTypeIds: optional2(list2(uuid, 100, 1))
|
|
397
416
|
}), (v, p) => {
|
|
398
417
|
if (v.eligibleBookingTypeIds) {
|
|
399
|
-
if (v.source.kind !== "qualified_lead")
|
|
418
|
+
if (v.source.kind !== "qualified_lead") fail3(p + ".eligibleBookingTypeIds", "requires the native qualified-lead source");
|
|
400
419
|
unique(v.eligibleBookingTypeIds.map((x) => x.toLowerCase()), p + ".eligibleBookingTypeIds");
|
|
401
420
|
}
|
|
402
|
-
if (v.qualificationRule && v.source.kind !== "qualified_lead")
|
|
403
|
-
if (v.qualificationRule && v.qualificationRuleRef && (v.qualificationRuleRef.module !== "crm" || v.qualificationRuleRef.id !== v.source.projectId))
|
|
421
|
+
if (v.qualificationRule && v.source.kind !== "qualified_lead") fail3(p + ".qualificationRule", "requires the native qualified-lead source");
|
|
422
|
+
if (v.qualificationRule && v.qualificationRuleRef && (v.qualificationRuleRef.module !== "crm" || v.qualificationRuleRef.id !== v.source.projectId)) fail3(p + ".qualificationRuleRef", "must reference actual CRM project configuration");
|
|
404
423
|
});
|
|
405
|
-
var creative = object2({ id: uuid, assetRef: resource, preparedArtifactRef: nullable2(resource), headline:
|
|
424
|
+
var creative = object2({ id: uuid, assetRef: resource, preparedArtifactRef: nullable2(resource), headline: text3(160), body: text3(1e4), callToAction: text3(80), cropDigest: digest });
|
|
406
425
|
var destination = union2(
|
|
407
|
-
object2({ kind: literal2("funnel"), id: uuid, ...scope, path, funnelRef: resource, formSlug:
|
|
426
|
+
object2({ kind: literal2("funnel"), id: uuid, ...scope, path, funnelRef: resource, formSlug: text3(80, /^[a-z0-9]+(?:-[a-z0-9]+)*$/), installationRevision: revision }),
|
|
408
427
|
object2({ kind: literal2("existing_page"), id: uuid, ...scope, path, pageRevision: revision, evidenceDigest: digest })
|
|
409
428
|
);
|
|
410
429
|
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") });
|
|
411
430
|
var experiment = object2({ ...scope, id: uuid, revision: integer2(1), digest });
|
|
412
|
-
var budget =
|
|
413
|
-
if (Date.parse(v.endAt) <= Date.parse(v.startAt))
|
|
414
|
-
for (const m of [v.reserveMargin, v.maxChange, ...v.dailyAllocationCeiling ? [v.dailyAllocationCeiling] : []]) if (m.currency !== v.total.currency)
|
|
415
|
-
if (BigInt(v.reserveMargin.amountMicros) > BigInt(v.total.amountMicros))
|
|
431
|
+
var budget = refine3(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) => {
|
|
432
|
+
if (Date.parse(v.endAt) <= Date.parse(v.startAt)) fail3(p, "end must follow start");
|
|
433
|
+
for (const m of [v.reserveMargin, v.maxChange, ...v.dailyAllocationCeiling ? [v.dailyAllocationCeiling] : []]) if (m.currency !== v.total.currency) fail3(p, "currency mismatch");
|
|
434
|
+
if (BigInt(v.reserveMargin.amountMicros) > BigInt(v.total.amountMicros)) fail3(p, "reserve exceeds total");
|
|
416
435
|
});
|
|
417
436
|
var allocationPolicyFields = {
|
|
418
437
|
schemaVersion: literal2(1),
|
|
@@ -449,7 +468,7 @@ var finiteStopRule = choice2("exploration_cap", "flight_end", "policy_or_mandate
|
|
|
449
468
|
var positiveMicrosPattern = /^[1-9][0-9]*(?![\s\S])/;
|
|
450
469
|
var positiveMoneyShape = field2({ allOf: [money.schema, { properties: { amountMicros: { pattern: positiveMicrosPattern.source } } }] }, (v, p) => {
|
|
451
470
|
const m = money.read(v, p);
|
|
452
|
-
if (!positiveMicrosPattern.test(m.amountMicros))
|
|
471
|
+
if (!positiveMicrosPattern.test(m.amountMicros)) fail3(p, "requires positive canonical money");
|
|
453
472
|
return m;
|
|
454
473
|
});
|
|
455
474
|
var finiteMetaCandidatePolicy = object2({
|
|
@@ -477,27 +496,27 @@ function parseResonanceOptimizationPolicy(v) {
|
|
|
477
496
|
return r;
|
|
478
497
|
}
|
|
479
498
|
const p = "optimizationPolicy", ids = r.candidateChannelIds, guard = r.measurementGuard;
|
|
480
|
-
if (r.selection.candidateOrder.length !== ids.length || r.selection.candidateOrder.some((id) => !ids.includes(id)))
|
|
499
|
+
if (r.selection.candidateOrder.length !== ids.length || r.selection.candidateOrder.some((id) => !ids.includes(id))) fail3(p + ".selection.candidateOrder", "must be the exact candidate permutation");
|
|
481
500
|
unique(r.selection.eligibilitySchedule.map((s) => s.channelId), p + ".selection.eligibilitySchedule");
|
|
482
|
-
if (r.selection.eligibilitySchedule.length !== ids.length || r.selection.eligibilitySchedule.some((s) => !ids.includes(s.channelId)))
|
|
483
|
-
if (r.selection.eligibilitySchedule.some((s) => Date.parse(s.notAfter) <= Date.parse(s.notBefore) || Date.parse(s.notAfter) > Date.parse(r.expiresAt)))
|
|
484
|
-
if (r.maxConcurrentCandidates > ids.length)
|
|
485
|
-
if (BigInt(r.totalExplorationCap.amountMicros) === 0n)
|
|
486
|
-
if (guard.sourceRef.kind !== r.eligibleGoal || guard.qualificationRuleRef.module !== "crm" || guard.qualificationRuleRef.id !== guard.sourceRef.projectId || guard.qualificationRuleRef.projectId !== guard.sourceRef.projectId || guard.qualificationRuleRef.site !== guard.sourceRef.site)
|
|
501
|
+
if (r.selection.eligibilitySchedule.length !== ids.length || r.selection.eligibilitySchedule.some((s) => !ids.includes(s.channelId))) fail3(p + ".selection.eligibilitySchedule", "must cover exactly the original candidates");
|
|
502
|
+
if (r.selection.eligibilitySchedule.some((s) => Date.parse(s.notAfter) <= Date.parse(s.notBefore) || Date.parse(s.notAfter) > Date.parse(r.expiresAt))) fail3(p + ".selection.eligibilitySchedule", "invalid policy selection window");
|
|
503
|
+
if (r.maxConcurrentCandidates > ids.length) fail3(p + ".maxConcurrentCandidates", "exceeds finite candidate count");
|
|
504
|
+
if (BigInt(r.totalExplorationCap.amountMicros) === 0n) fail3(p + ".totalExplorationCap", "requires a positive reviewed ceiling");
|
|
505
|
+
if (guard.sourceRef.kind !== r.eligibleGoal || guard.qualificationRuleRef.module !== "crm" || guard.qualificationRuleRef.id !== guard.sourceRef.projectId || guard.qualificationRuleRef.projectId !== guard.sourceRef.projectId || guard.qualificationRuleRef.site !== guard.sourceRef.site) fail3(p + ".measurementGuard", "requires the original qualified source and CRM witness scope");
|
|
487
506
|
scoped(r, guard.sourceRef.projectId, [guard.sourceRef.site], p);
|
|
488
507
|
return r;
|
|
489
508
|
}
|
|
490
509
|
var RESONANCE_OPTIMIZATION_POLICY_JSON_SCHEMA = optimizationPolicy.schema;
|
|
491
510
|
var optimization = object2({ enabled: bool, policy: optimizationPolicy, stopLoss: object2({ confirmedSpend: money, unreconciledExposure: money }) });
|
|
492
511
|
var channelBase = { id: uuid, ...scope, destinationId: uuid, creativeIds: list2(uuid, 50, 1) };
|
|
493
|
-
var search = object2({ ...channelBase, localCampaignKey:
|
|
494
|
-
var metaAgeConstraint = union2(
|
|
495
|
-
if (v.min > v.max)
|
|
512
|
+
var search = object2({ ...channelBase, localCampaignKey: text3(80), kind: literal2("google_search"), provider: literal2("google_ads"), accountBindingId: uuid, capabilityRevision: revision, allocation: money, budgetMode: choice2("campaign_total", "average_daily"), keywords: list2(object2({ text: text3(80), match: choice2("exact", "phrase", "broad") }), 200, 1), negativeKeywords: list2(text3(80), 200), bidding: union2(object2({ strategy: literal2("maximize_conversions") }), object2({ strategy: literal2("target_cpa"), target: money })), locationIds: list2(text3(80), 100, 1), network: object2({ googleSearch: literal2(true), searchPartners: bool, displayExpansion: literal2(false) }), geoPresence: choice2("presence", "presence_or_interest"), excludedLocationIds: list2(text3(80), 100), adGroups: list2(object2({ localKey: text3(80), ads: list2(object2({ localKey: text3(80), creativeId: uuid, headlines: list2(text3(30), 15, 3), descriptions: list2(text3(90), 4, 2) }), 20, 1) }), 100, 1), assetAutomation: literal2("disabled") });
|
|
513
|
+
var metaAgeConstraint = union2(refine3(object2({ mode: literal2("bounded"), min: integer2(1, 120), max: integer2(1, 120) }), (v, p) => {
|
|
514
|
+
if (v.min > v.max) fail3(p, "minimum age exceeds maximum");
|
|
496
515
|
}), object2({ mode: literal2("omitted") }), object2({ mode: literal2("provider_managed") }));
|
|
497
|
-
var propertyKey = object2({ key:
|
|
516
|
+
var propertyKey = object2({ key: text3(40, /^[a-z0-9]+(?:-[a-z0-9]+)*$/), label: text3(80) });
|
|
498
517
|
var meta = object2({
|
|
499
518
|
...channelBase,
|
|
500
|
-
localCampaignKey:
|
|
519
|
+
localCampaignKey: text3(80),
|
|
501
520
|
kind: literal2("meta_retargeting"),
|
|
502
521
|
provider: literal2("meta_ads"),
|
|
503
522
|
accountBindingId: uuid,
|
|
@@ -506,34 +525,34 @@ var meta = object2({
|
|
|
506
525
|
budgetMode: choice2("lifetime", "daily"),
|
|
507
526
|
audienceRuleRefs: list2(audience, 50, 1),
|
|
508
527
|
objective: choice2("OUTCOME_LEADS", "OUTCOME_SALES", "OUTCOME_TRAFFIC"),
|
|
509
|
-
pageRef: object2({ connectionId: uuid, externalId:
|
|
510
|
-
instagramRef: nullable2(object2({ connectionId: uuid, externalId:
|
|
511
|
-
datasetRef: object2({ id:
|
|
528
|
+
pageRef: object2({ connectionId: uuid, externalId: text3(160), revision }),
|
|
529
|
+
instagramRef: nullable2(object2({ connectionId: uuid, externalId: text3(160), revision })),
|
|
530
|
+
datasetRef: object2({ id: text3(160), revision }),
|
|
512
531
|
conversionGoalRef: resource,
|
|
513
532
|
optimization: choice2("landing_page_views", "lead", "purchase"),
|
|
514
533
|
billing: literal2("impressions"),
|
|
515
534
|
bid: union2(object2({ strategy: literal2("lowest_cost") }), object2({ strategy: literal2("cost_cap"), cap: money })),
|
|
516
|
-
localAdSetKey:
|
|
517
|
-
localAdKey:
|
|
535
|
+
localAdSetKey: text3(80),
|
|
536
|
+
localAdKey: text3(80),
|
|
518
537
|
budgetOwner: choice2("campaign", "adset"),
|
|
519
538
|
specialCategories: list2(choice2("housing", "employment", "financial_products_services"), 3),
|
|
520
|
-
countryCodes: list2(
|
|
539
|
+
countryCodes: list2(text3(2, /^[A-Z]{2}$/), 30, 1),
|
|
521
540
|
placement: literal2("automatic"),
|
|
522
541
|
ageConstraint: optional2(metaAgeConstraint),
|
|
523
542
|
// 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.
|
|
524
543
|
channelGroup: optional2(propertyKey),
|
|
525
544
|
property: optional2(propertyKey),
|
|
526
|
-
tier: optional2(object2({ label:
|
|
527
|
-
primaryText: optional2(
|
|
545
|
+
tier: optional2(object2({ label: text3(40) })),
|
|
546
|
+
primaryText: optional2(text3(2200)),
|
|
528
547
|
convertersAcknowledged: optional2(literal2(true))
|
|
529
548
|
});
|
|
530
549
|
var owned = object2({ ...channelBase, kind: choice2("funnel", "broadcast", "outreach"), resourceRef: resource });
|
|
531
550
|
var channel = union2(search, meta, owned);
|
|
532
|
-
var definitionFields = { schemaVersion: literal2(1), projectId: uuid, name:
|
|
533
|
-
if (normalizeCampaignSlug(v) !== v)
|
|
551
|
+
var definitionFields = { schemaVersion: literal2(1), projectId: uuid, name: text3(160), slug: refine3(text3(80), (v, p) => {
|
|
552
|
+
if (normalizeCampaignSlug(v) !== v) fail3(p, "must be canonical campaign slug");
|
|
534
553
|
}), sites: list2(site, 50, 1), objective, brandRef: resource, creativeRefs: list2(creative, 100, 1), destinations: list2(destination, 100, 1), channels: list2(channel, 100, 1), experimentRefs: list2(experiment, 50), budget, optimization };
|
|
535
554
|
var definition = object2(definitionFields);
|
|
536
|
-
var draft = object2({ schemaVersion: literal2(1), projectId: uuid, name:
|
|
555
|
+
var draft = object2({ schemaVersion: literal2(1), projectId: uuid, name: text3(160, void 0, 0), slug: definitionFields.slug, sites: list2(site, 50), objective: optional2(objective), brandRef: optional2(resource), creativeRefs: optional2(list2(creative, 100)), destinations: optional2(list2(destination, 100)), channels: optional2(list2(channel, 100)), experimentRefs: optional2(list2(experiment, 50)), budget: optional2(budget), optimization: optional2(optimization) });
|
|
537
556
|
function scoped(value, projectId, sites, at) {
|
|
538
557
|
if (!value || typeof value !== "object") return;
|
|
539
558
|
if (Array.isArray(value)) {
|
|
@@ -541,36 +560,36 @@ function scoped(value, projectId, sites, at) {
|
|
|
541
560
|
return;
|
|
542
561
|
}
|
|
543
562
|
const v = value;
|
|
544
|
-
if ("projectId" in v && v.projectId !== projectId)
|
|
545
|
-
if ("site" in v && !sites.includes(v.site))
|
|
563
|
+
if ("projectId" in v && v.projectId !== projectId) fail3(at, "cross-project reference");
|
|
564
|
+
if ("site" in v && !sites.includes(v.site)) fail3(at, "site outside campaign scope");
|
|
546
565
|
for (const [k, x] of Object.entries(v)) scoped(x, projectId, sites, `${at}.${k}`);
|
|
547
566
|
}
|
|
548
567
|
function unique(values, at) {
|
|
549
|
-
if (new Set(values).size !== values.length)
|
|
568
|
+
if (new Set(values).size !== values.length) fail3(at, "duplicate identity");
|
|
550
569
|
}
|
|
551
570
|
function checkDefinition(v) {
|
|
552
571
|
unique(v.sites, "campaign.sites");
|
|
553
572
|
scoped(v, v.projectId, v.sites, "campaign");
|
|
554
573
|
parseResonanceOptimizationPolicy(v.optimization.policy);
|
|
555
|
-
if (v.optimization.enabled && v.objective.source.kind !== v.optimization.policy.eligibleGoal)
|
|
556
|
-
if ([v.optimization.stopLoss.confirmedSpend, v.optimization.stopLoss.unreconciledExposure].some((m) => m.currency !== v.budget.total.currency))
|
|
574
|
+
if (v.optimization.enabled && v.objective.source.kind !== v.optimization.policy.eligibleGoal) fail3("campaign.optimization.policy", "policy is not eligible for this goal");
|
|
575
|
+
if ([v.optimization.stopLoss.confirmedSpend, v.optimization.stopLoss.unreconciledExposure].some((m) => m.currency !== v.budget.total.currency)) fail3("campaign.optimization.stopLoss", "currency mismatch");
|
|
557
576
|
unique(v.channels.map((c) => c.id), "campaign.channels");
|
|
558
577
|
unique(v.creativeRefs.map((c) => c.id), "campaign.creativeRefs");
|
|
559
578
|
unique(v.destinations.map((d) => d.id), "campaign.destinations");
|
|
560
|
-
if (!["business_brain", "publication"].includes(v.brandRef.module))
|
|
561
|
-
for (const c of v.creativeRefs) if (c.assetRef.module !== "files" || c.preparedArtifactRef && !["files", "broadcast"].includes(c.preparedArtifactRef.module))
|
|
562
|
-
for (const d of v.destinations) if (d.kind === "funnel" && d.funnelRef.module !== "funnel")
|
|
579
|
+
if (!["business_brain", "publication"].includes(v.brandRef.module)) fail3("campaign.brandRef", "must reference existing brand owner");
|
|
580
|
+
for (const c of v.creativeRefs) if (c.assetRef.module !== "files" || c.preparedArtifactRef && !["files", "broadcast"].includes(c.preparedArtifactRef.module)) fail3("campaign.creativeRefs", "unsupported asset owner");
|
|
581
|
+
for (const d of v.destinations) if (d.kind === "funnel" && d.funnelRef.module !== "funnel") fail3("campaign.destinations", "must reference funnel owner");
|
|
563
582
|
for (const c of v.channels) {
|
|
564
|
-
const dest = v.destinations.find((d) => d.id === c.destinationId) ??
|
|
565
|
-
if (dest.site !== c.site)
|
|
566
|
-
if (c.creativeIds.some((id) => !v.creativeRefs.some((x) => x.id === id)))
|
|
567
|
-
if ("bid" in c && "cap" in c.bid && c.bid.cap.currency !== v.budget.total.currency)
|
|
583
|
+
const dest = v.destinations.find((d) => d.id === c.destinationId) ?? fail3("campaign.channels.destinationId", "must reference a destination ID");
|
|
584
|
+
if (dest.site !== c.site) fail3("campaign.channels.destinationId", "destination site mismatch");
|
|
585
|
+
if (c.creativeIds.some((id) => !v.creativeRefs.some((x) => x.id === id))) fail3("campaign.channels.creativeIds", "unknown creative");
|
|
586
|
+
if ("bid" in c && "cap" in c.bid && c.bid.cap.currency !== v.budget.total.currency) fail3("campaign.channels.bid", "currency mismatch");
|
|
568
587
|
if ("adGroups" in c) {
|
|
569
|
-
for (const g of c.adGroups) for (const a of g.ads) if (!c.creativeIds.includes(a.creativeId))
|
|
588
|
+
for (const g of c.adGroups) for (const a of g.ads) if (!c.creativeIds.includes(a.creativeId)) fail3("campaign.channels.adGroups", "ad creative outside channel");
|
|
570
589
|
}
|
|
571
|
-
if ("resourceRef" in c && c.resourceRef.module !== c.kind)
|
|
572
|
-
if ("bidding" in c && "target" in c.bidding && c.bidding.target.currency !== v.budget.total.currency)
|
|
573
|
-
if ("allocation" in c && c.allocation.currency !== v.budget.total.currency)
|
|
590
|
+
if ("resourceRef" in c && c.resourceRef.module !== c.kind) fail3("campaign.channels.resourceRef", "module owner mismatch");
|
|
591
|
+
if ("bidding" in c && "target" in c.bidding && c.bidding.target.currency !== v.budget.total.currency) fail3("campaign.channels.bidding", "currency mismatch");
|
|
592
|
+
if ("allocation" in c && c.allocation.currency !== v.budget.total.currency) fail3("campaign.channels.allocation", "currency mismatch");
|
|
574
593
|
}
|
|
575
594
|
checkChannelGroups(v.channels);
|
|
576
595
|
checkGroupedAllocations(v);
|
|
@@ -578,12 +597,12 @@ function checkDefinition(v) {
|
|
|
578
597
|
const policy = v.optimization.policy;
|
|
579
598
|
if (policy.algorithm === "finite_meta_candidates_v1") {
|
|
580
599
|
const guard = policy.measurementGuard, goal = v.objective;
|
|
581
|
-
if (canonical(guard.sourceRef) !== canonical(goal.source) || !goal.qualificationRuleRef || canonical(guard.qualificationRuleRef) !== canonical(goal.qualificationRuleRef) || guard.maturityDelaySeconds !== goal.maturityDelaySeconds || goal.countingUnit !== "unique_qualified_contact")
|
|
582
|
-
if (policy.totalExplorationCap.currency !== v.budget.total.currency || compareMoney(policy.totalExplorationCap, v.budget.total) > 0)
|
|
583
|
-
if (Date.parse(policy.expiresAt) > Date.parse(v.budget.endAt) || policy.selection.eligibilitySchedule.some((s) => Date.parse(s.notBefore) < Date.parse(v.budget.startAt) || Date.parse(s.notAfter) > Date.parse(v.budget.endAt)))
|
|
600
|
+
if (canonical(guard.sourceRef) !== canonical(goal.source) || !goal.qualificationRuleRef || canonical(guard.qualificationRuleRef) !== canonical(goal.qualificationRuleRef) || guard.maturityDelaySeconds !== goal.maturityDelaySeconds || goal.countingUnit !== "unique_qualified_contact") fail3("campaign.optimization.policy.measurementGuard", "must match the original qualified objective");
|
|
601
|
+
if (policy.totalExplorationCap.currency !== v.budget.total.currency || compareMoney(policy.totalExplorationCap, v.budget.total) > 0) fail3("campaign.optimization.policy.totalExplorationCap", "outside original budget ceiling");
|
|
602
|
+
if (Date.parse(policy.expiresAt) > Date.parse(v.budget.endAt) || policy.selection.eligibilitySchedule.some((s) => Date.parse(s.notBefore) < Date.parse(v.budget.startAt) || Date.parse(s.notAfter) > Date.parse(v.budget.endAt))) fail3("campaign.optimization.policy.selection", "selection windows must stay inside the original flight");
|
|
584
603
|
for (const id of policy.candidateChannelIds) {
|
|
585
604
|
const c = v.channels.find((c2) => c2.id === id);
|
|
586
|
-
if (!c || c.kind !== "meta_retargeting" || c.budgetMode !== "lifetime" || c.budgetOwner !== "adset" || BigInt(c.allocation.amountMicros) === 0n)
|
|
605
|
+
if (!c || c.kind !== "meta_retargeting" || c.budgetMode !== "lifetime" || c.budgetOwner !== "adset" || BigInt(c.allocation.amountMicros) === 0n) fail3("campaign.optimization.policy.candidateChannelIds", "requires an original independently capped Meta adset channel");
|
|
587
606
|
}
|
|
588
607
|
}
|
|
589
608
|
}
|
|
@@ -600,10 +619,10 @@ function parseResonanceCampaignDraft(v) {
|
|
|
600
619
|
}
|
|
601
620
|
var RESONANCE_CAMPAIGN_DEFINITION_JSON_SCHEMA = definition.schema;
|
|
602
621
|
var RESONANCE_CAMPAIGN_DRAFT_JSON_SCHEMA = draft.schema;
|
|
603
|
-
var capability = object2({ id: uuid, projectId: uuid, connectionId: uuid, provider: choice2("google_ads", "meta_ads"), externalAccountId:
|
|
622
|
+
var capability = object2({ id: uuid, projectId: uuid, connectionId: uuid, provider: choice2("google_ads", "meta_ads"), externalAccountId: text3(160), currency, timeZone, connectionRevision: revision, capabilityRevision: revision, observedAt: instant, expiresAt: instant, advertiserState: choice2("eligible", "blocked", "unknown"), operations: list2(object2({ operation: choice2("discover", "prepare", "launch", "update", "pause", "resume", "finish", "reconcile", "measure", "audience", "conversion", "experiment"), state: choice2("supported", "blocked", "unknown"), reasonCodes: list2(text3(80), 30), prerequisites: list2(text3(100), 30) }), 20), profiles: list2(object2({ profile: choice2("google_search", "meta_retargeting"), state: choice2("supported", "blocked", "unknown"), reasonCodes: list2(text3(80), 30), budgetModes: list2(choice2("campaign_total", "average_daily", "lifetime", "daily"), 4), providerApiVersion: text3(30) }), 2) });
|
|
604
623
|
var parseResonanceAccountCapability = (v) => {
|
|
605
624
|
const r = capability.read(v, "account");
|
|
606
|
-
if (Date.parse(r.expiresAt) <= Date.parse(r.observedAt))
|
|
625
|
+
if (Date.parse(r.expiresAt) <= Date.parse(r.observedAt)) fail3("account.expiresAt", "must follow observation");
|
|
607
626
|
return r;
|
|
608
627
|
};
|
|
609
628
|
var mandateRef = object2({ ledgerActionId: uuid, campaignId: uuid, preparedPlanId: uuid, reviewDigest: digest, mandateDigest: digest, expectedKillRevision: integer2(0) });
|
|
@@ -631,16 +650,16 @@ var websiteVisitFeed = object2({ profile: literal2(RESONANCE_WEBSITE_VISIT_PROFI
|
|
|
631
650
|
matchingProfileRef
|
|
632
651
|
}), 100, 1) });
|
|
633
652
|
var RESONANCE_WEBSITE_VISIT_FEED_JSON_SCHEMA = websiteVisitFeed.schema;
|
|
634
|
-
var providerReportingChannelIds =
|
|
653
|
+
var providerReportingChannelIds = refine3(uniqueList(uuid, 100, 1), (ids, p) => unique(ids.map((id) => id.toLowerCase()), p));
|
|
635
654
|
var RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS = ["1d_click", "7d_click", "1d_view"];
|
|
636
655
|
var metaReportingQuery = object2({ channelId: uuid, attributionWindow: choice2(...RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS), actionReportTime: literal2("conversion"), basis: literal2("explicit_query") });
|
|
637
|
-
var providerReportingMetaQueries =
|
|
656
|
+
var providerReportingMetaQueries = refine3(list2(metaReportingQuery, 100, 1), (queries, p) => unique(queries.map((query) => query.channelId.toLowerCase()), p));
|
|
638
657
|
function checkReportingQuerySubset(v, p) {
|
|
639
|
-
if (v.metaQueries?.some((query) => !v.channelIds.some((id) => id.toLowerCase() === query.channelId.toLowerCase())))
|
|
658
|
+
if (v.metaQueries?.some((query) => !v.channelIds.some((id) => id.toLowerCase() === query.channelId.toLowerCase()))) fail3(p + ".metaQueries", "query channel must be selected");
|
|
640
659
|
}
|
|
641
|
-
var providerReportingSelection =
|
|
642
|
-
var providerReportingGrant =
|
|
643
|
-
if (v.agentContactId.toLowerCase() === v.principalContactId.toLowerCase())
|
|
660
|
+
var providerReportingSelection = refine3(object2({ agentContactId: uuid, channelIds: providerReportingChannelIds, metaQueries: optional2(providerReportingMetaQueries) }), checkReportingQuerySubset);
|
|
661
|
+
var providerReportingGrant = refine3(object2({ purpose: literal2("provider_reporting_refresh"), orgId: uuid, projectId: uuid, agentContactId: uuid, principalContactId: uuid, channelIds: providerReportingChannelIds, metaQueries: optional2(providerReportingMetaQueries), reportingUntil: optional2(instant) }), (v, p) => {
|
|
662
|
+
if (v.agentContactId.toLowerCase() === v.principalContactId.toLowerCase()) fail3(p + ".principalContactId", "agent and human principal must remain distinct");
|
|
644
663
|
checkReportingQuerySubset(v, p);
|
|
645
664
|
});
|
|
646
665
|
var parseResonanceProviderReportingSelection = (v) => providerReportingSelection.read(v, "providerReportingSelection");
|
|
@@ -648,18 +667,18 @@ var parseResonanceProviderReportingGrant = (v) => providerReportingGrant.read(v,
|
|
|
648
667
|
var RESONANCE_PROVIDER_REPORTING_SELECTION_JSON_SCHEMA = providerReportingSelection.schema;
|
|
649
668
|
var RESONANCE_PROVIDER_REPORTING_GRANT_JSON_SCHEMA = providerReportingGrant.schema;
|
|
650
669
|
var RESONANCE_PROVIDER_REPORTING_MAX_TAIL_DAYS = 92;
|
|
651
|
-
var googleContentTarget = { channelId: uuid, adGroupLocalKey:
|
|
670
|
+
var googleContentTarget = { channelId: uuid, adGroupLocalKey: text3(80), adLocalKey: text3(80) };
|
|
652
671
|
var normalizeResonanceGoogleCriterionText = (value) => value.trim().replace(/\s+/gu, " ").toLowerCase().normalize("NFC");
|
|
653
|
-
var googleCriterionText =
|
|
654
|
-
var googleExactText =
|
|
655
|
-
var googleContentKeywords = (criterion) =>
|
|
672
|
+
var googleCriterionText = text3(80, /^(?! +$)[^\x00-\x1f\x7f]+$/);
|
|
673
|
+
var googleExactText = text3(80, /^(?! +$)[^\x00-\x1f\x7f\\\[\]"]+$/);
|
|
674
|
+
var googleContentKeywords = (criterion) => refine3(list2(criterion, 20), (items, p) => {
|
|
656
675
|
const normalized = items.map(normalizeResonanceGoogleCriterionText);
|
|
657
|
-
if (normalized.some((value) => !value || value.length > 80))
|
|
676
|
+
if (normalized.some((value) => !value || value.length > 80)) fail3(p, "requires nonempty bounded criterion text");
|
|
658
677
|
unique(normalized, p);
|
|
659
678
|
items.splice(0, items.length, ...normalized.sort());
|
|
660
679
|
});
|
|
661
|
-
var rsaAsset = (length) =>
|
|
662
|
-
if (!asset.trim() || asset.trim() !== asset)
|
|
680
|
+
var rsaAsset = (length) => refine3(text3(length, /^[^\x00-\x1f\x7f]+$/), (asset, p) => {
|
|
681
|
+
if (!asset.trim() || asset.trim() !== asset) fail3(p, "requires trimmed, nonempty asset text");
|
|
663
682
|
});
|
|
664
683
|
var googleContentRsa = object2({
|
|
665
684
|
creativeRef: resource,
|
|
@@ -671,10 +690,10 @@ var googleContentMaterial = {
|
|
|
671
690
|
exactAdditions: googleContentKeywords(googleExactText),
|
|
672
691
|
rsa: nullable2(googleContentRsa)
|
|
673
692
|
};
|
|
674
|
-
var googleContentEntry =
|
|
675
|
-
if (!entry.negativeRemovals.length && !entry.exactAdditions.length && !entry.rsa)
|
|
693
|
+
var googleContentEntry = refine3(object2({ ...googleContentTarget, ...googleContentMaterial }), (entry, p) => {
|
|
694
|
+
if (!entry.negativeRemovals.length && !entry.exactAdditions.length && !entry.rsa) fail3(p, "must select at least one bounded content effect");
|
|
676
695
|
});
|
|
677
|
-
var googleSearchContent =
|
|
696
|
+
var googleSearchContent = refine3(list2(googleContentEntry, 100), (entries, p) => {
|
|
678
697
|
const identity = (entry) => JSON.stringify([entry.channelId.toLowerCase(), entry.adGroupLocalKey, entry.adLocalKey]);
|
|
679
698
|
unique(entries.map(identity), p);
|
|
680
699
|
entries.sort((a, b) => identity(a) < identity(b) ? -1 : identity(a) > identity(b) ? 1 : 0);
|
|
@@ -686,9 +705,9 @@ var operatingPolicyFields = {
|
|
|
686
705
|
cooldownSeconds: integer2(3600, 2592e3)
|
|
687
706
|
};
|
|
688
707
|
var operatingPolicySelection = object2(operatingPolicyFields);
|
|
689
|
-
var operatingPolicy =
|
|
708
|
+
var operatingPolicy = refine3(object2({ ...operatingPolicyFields, principalContactId: uuid }), (policy, p) => {
|
|
690
709
|
if (policy.agentContactId.toLowerCase() === policy.principalContactId.toLowerCase()) {
|
|
691
|
-
|
|
710
|
+
fail3(p + ".principalContactId", "agent and human principal must remain distinct");
|
|
692
711
|
}
|
|
693
712
|
});
|
|
694
713
|
var operatingPolicyRef = object2({ ledgerActionId: uuid, receiptId: uuid, digest });
|
|
@@ -700,8 +719,8 @@ var operatingPolicyBase = object2({
|
|
|
700
719
|
});
|
|
701
720
|
var operatingPolicyActionIdentity = object2({ mandateDigest: digest, operatingPolicyBase });
|
|
702
721
|
var googleContentUpdateSelection = object2(googleContentTarget);
|
|
703
|
-
var googleContentUpdate =
|
|
704
|
-
if (!update2.negativeRemovals.length && !update2.exactAdditions.length && !update2.rsa)
|
|
722
|
+
var googleContentUpdate = refine3(object2({ ...googleContentTarget, ...googleContentMaterial, policyRef: operatingPolicyRef, beforeDigest: digest }), (update2, p) => {
|
|
723
|
+
if (!update2.negativeRemovals.length && !update2.exactAdditions.length && !update2.rsa) fail3(p, "must select at least one bounded content effect");
|
|
705
724
|
});
|
|
706
725
|
var parseResonanceOperatingPolicy = (v) => operatingPolicy.read(v, "operatingPolicy");
|
|
707
726
|
var parseResonanceOperatingPolicySelection = (v) => operatingPolicySelection.read(v, "operatingPolicySelection");
|
|
@@ -745,40 +764,40 @@ function parseResonanceMandateScope(v, preparedPlan) {
|
|
|
745
764
|
if (r.operatingPolicy) {
|
|
746
765
|
const p = "mandateScope.operatingPolicy";
|
|
747
766
|
if (Date.parse(r.expiresAt) <= Date.parse(r.budget.startAt) || Date.parse(r.expiresAt) > Date.parse(r.budget.endAt)) {
|
|
748
|
-
|
|
767
|
+
fail3(p, "operating policy remains inside the original mandate flight and expiry");
|
|
749
768
|
}
|
|
750
769
|
if (r.operatingPolicy.googleSearchContent.length && !r.allowedOperations.includes("update")) {
|
|
751
|
-
|
|
770
|
+
fail3(p, "Google content requires the update operation");
|
|
752
771
|
}
|
|
753
772
|
if (preparedPlan !== void 0) {
|
|
754
773
|
const plan = parseResonancePreparedPlan(preparedPlan);
|
|
755
|
-
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))
|
|
774
|
+
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)) fail3(p, "requires the exact original plan, review, goal and flight");
|
|
756
775
|
for (const entry of r.operatingPolicy.googleSearchContent) {
|
|
757
776
|
const channel2 = plan.definition.channels.find((item) => item.id.toLowerCase() === entry.channelId.toLowerCase());
|
|
758
|
-
if (channel2?.kind !== "google_search") return
|
|
777
|
+
if (channel2?.kind !== "google_search") return fail3(p, "requires an original Google Search channel");
|
|
759
778
|
const group = channel2.adGroups.find((item) => item.localKey === entry.adGroupLocalKey);
|
|
760
|
-
if (!r.sites.includes(channel2.site) || !r.accountBindingIds.includes(channel2.accountBindingId) || !group?.ads.some((ad) => ad.localKey === entry.adLocalKey) || entry.rsa && entry.rsa.creativeRef.site !== channel2.site)
|
|
779
|
+
if (!r.sites.includes(channel2.site) || !r.accountBindingIds.includes(channel2.accountBindingId) || !group?.ads.some((ad) => ad.localKey === entry.adLocalKey) || entry.rsa && entry.rsa.creativeRef.site !== channel2.site) fail3(p, "requires the original account, site, ad group and ad");
|
|
761
780
|
}
|
|
762
781
|
}
|
|
763
782
|
}
|
|
764
783
|
if (r.providerReporting) {
|
|
765
784
|
const grant = r.providerReporting, p = "mandateScope.providerReporting";
|
|
766
|
-
if (grant.projectId !== r.projectId)
|
|
785
|
+
if (grant.projectId !== r.projectId) fail3(p + ".projectId", "must match the original mandate project");
|
|
767
786
|
const flightEnd = Date.parse(r.budget.endAt);
|
|
768
|
-
if (Date.parse(r.expiresAt) <= Date.parse(r.budget.startAt) || Date.parse(r.expiresAt) > flightEnd)
|
|
787
|
+
if (Date.parse(r.expiresAt) <= Date.parse(r.budget.startAt) || Date.parse(r.expiresAt) > flightEnd) fail3(p, "mandate expiry remains inside the original flight");
|
|
769
788
|
if (grant.reportingUntil !== void 0) {
|
|
770
789
|
const deadline = Date.parse(grant.reportingUntil);
|
|
771
790
|
if (deadline <= flightEnd || deadline > flightEnd + RESONANCE_PROVIDER_REPORTING_MAX_TAIL_DAYS * 864e5) {
|
|
772
|
-
|
|
791
|
+
fail3(p + ".reportingUntil", "must follow the original flight by no more than 92 elapsed days");
|
|
773
792
|
}
|
|
774
793
|
}
|
|
775
794
|
if (preparedPlan !== void 0) {
|
|
776
795
|
const plan = parseResonancePreparedPlan(preparedPlan);
|
|
777
|
-
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))
|
|
778
|
-
if (r.sites.some((site2) => !plan.definition.sites.includes(site2)) || r.accountBindingIds.some((id) => !plan.accounts.some((account) => account.id === id)))
|
|
796
|
+
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)) fail3(p, "requires the exact original plan, review, goal and flight");
|
|
797
|
+
if (r.sites.some((site2) => !plan.definition.sites.includes(site2)) || r.accountBindingIds.some((id) => !plan.accounts.some((account) => account.id === id))) fail3(p, "mandate sites and accounts must stay inside the original plan");
|
|
779
798
|
for (const id of grant.channelIds) {
|
|
780
799
|
const channel2 = plan.definition.channels.find((c) => c.id.toLowerCase() === id.toLowerCase());
|
|
781
|
-
if (!channel2 || !("provider" in channel2) || !r.sites.includes(channel2.site) || !r.accountBindingIds.includes(channel2.accountBindingId))
|
|
800
|
+
if (!channel2 || !("provider" in channel2) || !r.sites.includes(channel2.site) || !r.accountBindingIds.includes(channel2.accountBindingId)) fail3(p + ".channelIds", "requires an explicit original paid channel inside mandate sites and accounts");
|
|
782
801
|
}
|
|
783
802
|
}
|
|
784
803
|
}
|
|
@@ -789,7 +808,7 @@ function resonanceWebsiteVisitEventTime(value, context) {
|
|
|
789
808
|
const input = websiteVisitTimes.read(value, "websiteVisitTime");
|
|
790
809
|
const actual = object2({ mandate: mandateScope, approvedAt: instant, now: instant }).read(context, "websiteVisitTime.context");
|
|
791
810
|
const grant = parseResonanceMandateScope(actual.mandate);
|
|
792
|
-
if (!grant.websiteVisitFeed)
|
|
811
|
+
if (!grant.websiteVisitFeed) fail3("websiteVisitTime.context.mandate.websiteVisitFeed", "requires an explicit original feed selection");
|
|
793
812
|
const start = Math.max(Date.parse(grant.budget.startAt), Date.parse(actual.approvedAt));
|
|
794
813
|
const end = Math.min(Date.parse(grant.budget.endAt), Date.parse(grant.expiresAt));
|
|
795
814
|
return websiteVisitEventTime(input, start, end, Date.parse(actual.now));
|
|
@@ -797,8 +816,8 @@ function resonanceWebsiteVisitEventTime(value, context) {
|
|
|
797
816
|
function websiteVisitEventTime(input, start, end, now) {
|
|
798
817
|
const occurred = Date.parse(input.occurredAt), received = Date.parse(input.receivedAt);
|
|
799
818
|
const policy = RESONANCE_WEBSITE_VISIT_PROFILE;
|
|
800
|
-
if (received < occurred - policy.maxFutureSkewMs || received - occurred > policy.maxCaptureAgeMs || now < received || now < occurred - policy.maxFutureSkewMs || now - occurred > policy.maxDispatchAgeMs)
|
|
801
|
-
if (occurred < start || received < start || occurred >= end || received >= end || now >= end)
|
|
819
|
+
if (received < occurred - policy.maxFutureSkewMs || received - occurred > policy.maxCaptureAgeMs || now < received || now < occurred - policy.maxFutureSkewMs || now - occurred > policy.maxDispatchAgeMs) fail3("websiteVisitTime", "outside the local original observation freshness profile");
|
|
820
|
+
if (occurred < start || received < start || occurred >= end || received >= end || now >= end) fail3("websiteVisitTime", "outside the original approval and dispatch window");
|
|
802
821
|
return Math.floor(occurred / 1e3);
|
|
803
822
|
}
|
|
804
823
|
var RESONANCE_GOOGLE_SIGNAL_SEMANTICS = "qualified_at_observation_v1";
|
|
@@ -812,13 +831,13 @@ function googleConversionActionSemantics(input) {
|
|
|
812
831
|
var googleSetupPolicyInput = object2({ source, countingUnit: objectiveCountingUnit, attributionWindowDays: integer2(1, 365) });
|
|
813
832
|
function googleUploadClicksSetupSemantics(input) {
|
|
814
833
|
const v = googleSetupPolicyInput.read(input, "googleSetupPolicy");
|
|
815
|
-
if (v.source.kind !== "qualified_lead" || v.countingUnit !== "unique_qualified_contact")
|
|
816
|
-
if (v.attributionWindowDays > 90)
|
|
834
|
+
if (v.source.kind !== "qualified_lead" || v.countingUnit !== "unique_qualified_contact") fail3("googleSetupPolicy", "unsupported_counting_policy");
|
|
835
|
+
if (v.attributionWindowDays > 90) fail3("googleSetupPolicy.attributionWindowDays", "unsupported_attribution_window");
|
|
817
836
|
return { ...googleConversionActionSemantics({ sourceKind: v.source.kind, counting: "one", clickWindowDays: v.attributionWindowDays }), category: RESONANCE_GOOGLE_SOURCE_CATEGORIES.qualified_lead, countingType: "ONE_PER_CLICK" };
|
|
818
837
|
}
|
|
819
838
|
var googleGoalChoiceFields = {
|
|
820
|
-
externalId:
|
|
821
|
-
actionIds: list2(
|
|
839
|
+
externalId: text3(160, /^customers\/[0-9]+\/customConversionGoals\/[0-9]+$/),
|
|
840
|
+
actionIds: list2(text3(160, /^customers\/[0-9]+\/conversionActions\/[0-9]+$/), 100, 1)
|
|
822
841
|
};
|
|
823
842
|
var googleDeclarationChoiceFields = {
|
|
824
843
|
statement: literal2("DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING"),
|
|
@@ -834,10 +853,10 @@ var googleSetupSpec = object2({
|
|
|
834
853
|
kind: literal2("google_upload_clicks_custom_goal_v1"),
|
|
835
854
|
signalSemantics: googleSignalSemantics,
|
|
836
855
|
goalLocalKey: literal2("setup:custom-goal"),
|
|
837
|
-
requestedGoalName:
|
|
856
|
+
requestedGoalName: text3(160),
|
|
838
857
|
action: object2({
|
|
839
858
|
localKey: literal2("setup:conversion-action"),
|
|
840
|
-
requestedActionName:
|
|
859
|
+
requestedActionName: text3(160),
|
|
841
860
|
type: literal2("UPLOAD_CLICKS"),
|
|
842
861
|
category: literal2(RESONANCE_GOOGLE_SOURCE_CATEGORIES.qualified_lead),
|
|
843
862
|
countingType: literal2("ONE_PER_CLICK"),
|
|
@@ -852,20 +871,20 @@ var resonanceGoogleSetupDigestInput = (value) => canonical(parseResonanceGoogleU
|
|
|
852
871
|
var googleSaveCommonFields = { schemaVersion: literal2(1), expectedCampaignRevision: integer2(1), expectedRevision: integer2(0), idempotencyKey: operationKey, signalSemantics: googleSignalSemantics, declaration: object2(googleDeclarationChoiceFields) };
|
|
853
872
|
var googleSave = union2(
|
|
854
873
|
object2({ ...googleSaveCommonFields, mode: literal2("existing"), nativeGoal: object2(googleGoalChoiceFields) }),
|
|
855
|
-
object2({ ...googleSaveCommonFields, mode: literal2("admitted_setup"), setupIntent: object2({ requestedGoalName:
|
|
874
|
+
object2({ ...googleSaveCommonFields, mode: literal2("admitted_setup"), setupIntent: object2({ requestedGoalName: text3(160), requestedActionName: text3(160) }) })
|
|
856
875
|
);
|
|
857
876
|
function parseResonanceGoogleConfigurationSaveCommand(value) {
|
|
858
877
|
const result = googleSave.read(value, "googleConfigurationSave");
|
|
859
878
|
if (result.mode === "existing") normalizeGoogleGoal(result.nativeGoal, "googleConfigurationSave.nativeGoal");
|
|
860
879
|
return result;
|
|
861
880
|
}
|
|
862
|
-
var googleGoalDraft = object2({ ...googleGoalChoiceFields, name: nullable2(
|
|
863
|
-
var googleGoalReviewed = object2({ ...googleGoalChoiceFields, name:
|
|
881
|
+
var googleGoalDraft = object2({ ...googleGoalChoiceFields, name: nullable2(text3(200, void 0, 0)), revision: nullable2(digest) });
|
|
882
|
+
var googleGoalReviewed = object2({ ...googleGoalChoiceFields, name: text3(200, void 0, 0), revision: digest });
|
|
864
883
|
var googleDeclared = object2({
|
|
865
884
|
...googleDeclarationChoiceFields,
|
|
866
885
|
creativeDigest: digest,
|
|
867
|
-
locationIds: list2(
|
|
868
|
-
excludedLocationIds: list2(
|
|
886
|
+
locationIds: list2(text3(80), 100, 1),
|
|
887
|
+
excludedLocationIds: list2(text3(80), 100),
|
|
869
888
|
declaredByActorId: uuid,
|
|
870
889
|
declaredAt: instant,
|
|
871
890
|
declaredForCampaignRevision: integer2(1)
|
|
@@ -888,7 +907,7 @@ var googleConfigurationFields = {
|
|
|
888
907
|
var googleExistingChoiceFields = { mode: literal2("existing"), nativeGoal: googleGoalDraft };
|
|
889
908
|
var googleSetupChoiceFields = { mode: literal2("admitted_setup"), setupSpec: googleSetupSpec, setupDigest: digest };
|
|
890
909
|
function checkGoogleConfiguration(value, at) {
|
|
891
|
-
if (value.source.projectId !== value.projectId || value.source.site !== value.site)
|
|
910
|
+
if (value.source.projectId !== value.projectId || value.source.site !== value.site) fail3(at + ".source", "source scope mismatch");
|
|
892
911
|
unique(value.declaration.locationIds, at + ".declaration.locationIds");
|
|
893
912
|
unique(value.declaration.excludedLocationIds, at + ".declaration.excludedLocationIds");
|
|
894
913
|
value.declaration.locationIds.sort();
|
|
@@ -898,28 +917,28 @@ function checkGoogleConfiguration(value, at) {
|
|
|
898
917
|
normalizeGoogleGoal(value.nativeGoal, at + ".nativeGoal");
|
|
899
918
|
return;
|
|
900
919
|
}
|
|
901
|
-
if (canonical({ type: value.setupSpec.action.type, category: value.setupSpec.action.category, countingType: value.setupSpec.action.countingType, clickThroughLookbackWindowDays: value.setupSpec.action.clickThroughLookbackWindowDays, primaryForGoal: value.setupSpec.action.primaryForGoal }) !== canonical(expected))
|
|
920
|
+
if (canonical({ type: value.setupSpec.action.type, category: value.setupSpec.action.category, countingType: value.setupSpec.action.countingType, clickThroughLookbackWindowDays: value.setupSpec.action.clickThroughLookbackWindowDays, primaryForGoal: value.setupSpec.action.primaryForGoal }) !== canonical(expected)) fail3(at + ".setupSpec.action", "canonical setup semantics mismatch");
|
|
902
921
|
}
|
|
903
922
|
var googleSnapshotBase = union2(object2({ ...googleConfigurationFields, ...googleExistingChoiceFields }), object2({ ...googleConfigurationFields, ...googleSetupChoiceFields }));
|
|
904
|
-
var googleConfigurationSnapshot =
|
|
905
|
-
var googleConfigurationReview =
|
|
923
|
+
var googleConfigurationSnapshot = refine3(googleSnapshotBase, checkGoogleConfiguration);
|
|
924
|
+
var googleConfigurationReview = refine3(union2(object2({ ...googleConfigurationFields, mode: literal2("existing"), nativeGoal: googleGoalReviewed }), object2({ ...googleConfigurationFields, ...googleSetupChoiceFields })), checkGoogleConfiguration);
|
|
906
925
|
var parseResonanceGoogleConfigurationSnapshot = (value) => googleConfigurationSnapshot.read(value, "googleConfiguration");
|
|
907
926
|
var parseResonanceGoogleConfigurationReview = (value) => googleConfigurationReview.read(value, "googleConfigurationReview");
|
|
908
927
|
var { configurationRevision: _configurationRevisionField, ...googleViewContentFields } = googleConfigurationFields;
|
|
909
|
-
var googleReadinessFields = { ready: bool, activationReadiness: choice2("blocked", "pending_setup", "requires_final_verification", "verified"), reasonCodes: list2(
|
|
928
|
+
var googleReadinessFields = { ready: bool, activationReadiness: choice2("blocked", "pending_setup", "requires_final_verification", "verified"), reasonCodes: list2(text3(200), 100) };
|
|
910
929
|
var googleViewFields = { ...googleViewContentFields, revision: integer2(1), ...googleReadinessFields };
|
|
911
930
|
var googleViewBase = union2(object2({ ...googleViewFields, ...googleExistingChoiceFields }), object2({ ...googleViewFields, ...googleSetupChoiceFields }));
|
|
912
931
|
function checkGoogleView(value, at) {
|
|
913
932
|
checkGoogleConfiguration(value, at);
|
|
914
|
-
if (!value.ready && value.activationReadiness !== "blocked")
|
|
933
|
+
if (!value.ready && value.activationReadiness !== "blocked") fail3(at + ".activationReadiness", "unready configuration must be blocked");
|
|
915
934
|
if (value.mode === "existing") {
|
|
916
|
-
if (value.ready && (value.nativeGoal.name === null || value.nativeGoal.revision === null))
|
|
917
|
-
if (value.ready && value.activationReadiness !== "requires_final_verification" && value.activationReadiness !== "verified")
|
|
918
|
-
} else if (value.ready && value.activationReadiness !== "pending_setup")
|
|
935
|
+
if (value.ready && (value.nativeGoal.name === null || value.nativeGoal.revision === null)) fail3(at + ".ready", "unavailable native evidence cannot be ready");
|
|
936
|
+
if (value.ready && value.activationReadiness !== "requires_final_verification" && value.activationReadiness !== "verified") fail3(at + ".activationReadiness", "existing native setup needs current verification");
|
|
937
|
+
} else if (value.ready && value.activationReadiness !== "pending_setup") fail3(at + ".activationReadiness", "reviewed setup intent is not native activation");
|
|
919
938
|
}
|
|
920
|
-
var googleConfigurationView =
|
|
939
|
+
var googleConfigurationView = refine3(googleViewBase, checkGoogleView);
|
|
921
940
|
var googleSaveResultFields = { operationId: uuid, replayed: bool, campaignRevision: integer2(1) };
|
|
922
|
-
var googleConfigurationSaveResponse =
|
|
941
|
+
var googleConfigurationSaveResponse = refine3(union2(object2({ ...googleViewFields, ...googleExistingChoiceFields, ...googleSaveResultFields }), object2({ ...googleViewFields, ...googleSetupChoiceFields, ...googleSaveResultFields })), checkGoogleView);
|
|
923
942
|
var parseResonanceGoogleConfigurationView = (value) => googleConfigurationView.read(value, "googleConfigurationView");
|
|
924
943
|
var parseResonanceGoogleConfigurationSaveResponse = (value) => googleConfigurationSaveResponse.read(value, "googleConfigurationSaveResponse");
|
|
925
944
|
function projectResonanceGoogleConfiguration(value, readiness) {
|
|
@@ -932,7 +951,7 @@ function projectResonanceGoogleConfiguration(value, readiness) {
|
|
|
932
951
|
function googleReadiness() {
|
|
933
952
|
return object2(googleReadinessFields);
|
|
934
953
|
}
|
|
935
|
-
var googleConfigurationDigestValue =
|
|
954
|
+
var googleConfigurationDigestValue = refine3(union2(object2({ ...googleConfigurationFields, ...googleExistingChoiceFields, configurationDigest: optional2(digest) }), object2({ ...googleConfigurationFields, ...googleSetupChoiceFields, configurationDigest: optional2(digest) })), checkGoogleConfiguration);
|
|
936
955
|
function resonanceGoogleConfigurationDigestInput(value) {
|
|
937
956
|
const { configurationDigest: _self, ...content } = googleConfigurationDigestValue.read(value, "googleConfigurationDigestInput");
|
|
938
957
|
return canonical(content);
|
|
@@ -943,9 +962,9 @@ var RESONANCE_GOOGLE_CONFIGURATION_SNAPSHOT_JSON_SCHEMA = googleConfigurationSna
|
|
|
943
962
|
var RESONANCE_GOOGLE_CONFIGURATION_REVIEW_JSON_SCHEMA = googleConfigurationReview.schema;
|
|
944
963
|
var RESONANCE_GOOGLE_CONFIGURATION_VIEW_JSON_SCHEMA = googleConfigurationView.schema;
|
|
945
964
|
var RESONANCE_GOOGLE_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA = googleConfigurationSaveResponse.schema;
|
|
946
|
-
var preparedManifestRef = object2({ id: uuid, digest, providerVersion:
|
|
947
|
-
var preview = object2({ channelId: uuid, site, accountBindingId: nullable2(uuid), accountName:
|
|
948
|
-
var prepared = object2({ schemaVersion: literal2(1), id: uuid, campaignId: uuid, projectId: uuid, expectedRevision: integer2(1), definitionDigest: digest, reviewDigest: digest, definition, resolvedEvidencePolicy: optimizationPolicy, resolvedQualificationRule: nullable2(resolvedQualificationRule), accounts: list2(capability, 100), channelPreviews: list2(preview, 100, 1), preparedAt: instant, expiresAt: instant, blockingReasons: list2(
|
|
965
|
+
var preparedManifestRef = object2({ id: uuid, digest, providerVersion: text3(30), revision });
|
|
966
|
+
var preview = object2({ channelId: uuid, site, accountBindingId: nullable2(uuid), accountName: text3(200), accountTimeZone: timeZone, destinationUrl: text3(4096), attributionMarker: optional2(object2({ parameter: literal2(RESONANCE_SOURCE_MARKER_PARAMETER), value: sourceMarker })), orderedCreatives: list2(creative, 50, 1), audienceRuleRefs: list2(audience, 100), allocation: nullable2(money), capabilityRevision: revision, snapshotDigest: digest, manifestRef: preparedManifestRef, conversionRevision: revision, policyRevision: revision, googleConfiguration: nullable2(googleConfigurationReview) });
|
|
967
|
+
var prepared = object2({ schemaVersion: literal2(1), id: uuid, campaignId: uuid, projectId: uuid, expectedRevision: integer2(1), definitionDigest: digest, reviewDigest: digest, definition, resolvedEvidencePolicy: optimizationPolicy, resolvedQualificationRule: nullable2(resolvedQualificationRule), accounts: list2(capability, 100), channelPreviews: list2(preview, 100, 1), preparedAt: instant, expiresAt: instant, blockingReasons: list2(text3(200), 100) });
|
|
949
968
|
function bookingTypesMatch(goalIds, witnessIds) {
|
|
950
969
|
const norm = (ids) => ids === void 0 ? null : [...ids].map((id) => id.toLowerCase()).sort();
|
|
951
970
|
return canonical(norm(goalIds)) === canonical(norm(witnessIds));
|
|
@@ -954,50 +973,50 @@ function parseResonancePreparedPlan(v) {
|
|
|
954
973
|
const r = prepared.read(v, "preparedPlan");
|
|
955
974
|
checkDefinition(r.definition);
|
|
956
975
|
scoped(r, r.projectId, r.definition.sites, "preparedPlan");
|
|
957
|
-
if (Date.parse(r.expiresAt) <= Date.parse(r.preparedAt))
|
|
976
|
+
if (Date.parse(r.expiresAt) <= Date.parse(r.preparedAt)) fail3("preparedPlan.expiresAt", "must follow preparation");
|
|
958
977
|
const goal = r.definition.objective, witness = r.resolvedQualificationRule;
|
|
959
978
|
if (goal.source.kind === "qualified_lead") {
|
|
960
|
-
if (!goal.qualificationRule || !goal.qualificationRuleRef || !witness)
|
|
979
|
+
if (!goal.qualificationRule || !goal.qualificationRuleRef || !witness) fail3("preparedPlan.resolvedQualificationRule", "qualified-lead preparation requires actual configured native witness");
|
|
961
980
|
const w = witness, selected = goal.qualificationRule;
|
|
962
|
-
if (goal.countingUnit !== "unique_qualified_contact" || canonical(w.ref) !== canonical(goal.qualificationRuleRef) || w.eligibleFormIds.length !== 1 || w.eligibleFormIds[0] !== goal.source.id || !bookingTypesMatch(goal.eligibleBookingTypeIds, w.eligibleBookingTypeIds) || w.cohort.maturityDelaySeconds !== goal.maturityDelaySeconds)
|
|
963
|
-
for (const key of ["schemaVersion", "semantics", "positiveStageKeys", "finalNegativeStageKeys", "pendingStageKeys", "existingContactPolicy"]) if (canonical(w[key]) !== canonical(selected[key]))
|
|
964
|
-
} else if (witness !== null)
|
|
965
|
-
if (canonical(r.resolvedEvidencePolicy) !== canonical(r.definition.optimization.policy))
|
|
981
|
+
if (goal.countingUnit !== "unique_qualified_contact" || canonical(w.ref) !== canonical(goal.qualificationRuleRef) || w.eligibleFormIds.length !== 1 || w.eligibleFormIds[0] !== goal.source.id || !bookingTypesMatch(goal.eligibleBookingTypeIds, w.eligibleBookingTypeIds) || w.cohort.maturityDelaySeconds !== goal.maturityDelaySeconds) fail3("preparedPlan.resolvedQualificationRule", "source, counting unit, reference or maturity mismatch");
|
|
982
|
+
for (const key of ["schemaVersion", "semantics", "positiveStageKeys", "finalNegativeStageKeys", "pendingStageKeys", "existingContactPolicy"]) if (canonical(w[key]) !== canonical(selected[key])) fail3("preparedPlan.resolvedQualificationRule", "selected qualification snapshot mismatch");
|
|
983
|
+
} else if (witness !== null) fail3("preparedPlan.resolvedQualificationRule", "nonqualified objectives require explicit null");
|
|
984
|
+
if (canonical(r.resolvedEvidencePolicy) !== canonical(r.definition.optimization.policy)) fail3("preparedPlan.resolvedEvidencePolicy", "policy snapshot mismatch");
|
|
966
985
|
parseResonanceOptimizationPolicy(r.resolvedEvidencePolicy);
|
|
967
|
-
if (r.resolvedEvidencePolicy.algorithm === "finite_meta_candidates_v1" && Date.parse(r.resolvedEvidencePolicy.expiresAt) <= Date.parse(r.preparedAt))
|
|
986
|
+
if (r.resolvedEvidencePolicy.algorithm === "finite_meta_candidates_v1" && Date.parse(r.resolvedEvidencePolicy.expiresAt) <= Date.parse(r.preparedAt)) fail3("preparedPlan.resolvedEvidencePolicy.expiresAt", "finite policy expired before preparation");
|
|
968
987
|
unique(r.accounts.map((a) => a.id), "preparedPlan.accounts");
|
|
969
988
|
unique(r.channelPreviews.map((p) => p.channelId), "preparedPlan.channelPreviews");
|
|
970
|
-
if (r.channelPreviews.length !== r.definition.channels.length)
|
|
989
|
+
if (r.channelPreviews.length !== r.definition.channels.length) fail3("preparedPlan.channelPreviews", "must cover every channel");
|
|
971
990
|
for (const a of r.accounts) parseResonanceAccountCapability(a);
|
|
972
991
|
for (const p of r.channelPreviews) {
|
|
973
|
-
const c = r.definition.channels.find((c2) => c2.id === p.channelId) ??
|
|
974
|
-
if (c.site !== p.site)
|
|
992
|
+
const c = r.definition.channels.find((c2) => c2.id === p.channelId) ?? fail3("preparedPlan.channelPreviews", "unknown channel");
|
|
993
|
+
if (c.site !== p.site) fail3("preparedPlan.channelPreviews", "channel scope mismatch");
|
|
975
994
|
const google = p.googleConfiguration;
|
|
976
995
|
if (c.kind === "google_search") {
|
|
977
|
-
if (!google)
|
|
996
|
+
if (!google) fail3("preparedPlan.channelPreviews.googleConfiguration", "Google requires the actual reviewed configuration");
|
|
978
997
|
const g = google;
|
|
979
|
-
if (g.projectId !== r.projectId || g.campaignId !== r.campaignId || g.channelId !== c.id || g.site !== c.site || g.accountBindingId !== c.accountBindingId)
|
|
980
|
-
if (canonical(g.source) !== canonical(goal.source) || g.measurementRevision !== goal.measurementRevision || g.countingUnit !== goal.countingUnit || g.attributionWindowDays !== goal.attributionWindowDays)
|
|
998
|
+
if (g.projectId !== r.projectId || g.campaignId !== r.campaignId || g.channelId !== c.id || g.site !== c.site || g.accountBindingId !== c.accountBindingId) fail3("preparedPlan.channelPreviews.googleConfiguration", "configuration scope mismatch");
|
|
999
|
+
if (canonical(g.source) !== canonical(goal.source) || g.measurementRevision !== goal.measurementRevision || g.countingUnit !== goal.countingUnit || g.attributionWindowDays !== goal.attributionWindowDays) fail3("preparedPlan.channelPreviews.googleConfiguration.source", "objective measurement mismatch");
|
|
981
1000
|
unique(c.locationIds, "preparedPlan.channelPreviews.googleConfiguration.locationIds");
|
|
982
1001
|
unique(c.excludedLocationIds, "preparedPlan.channelPreviews.googleConfiguration.excludedLocationIds");
|
|
983
|
-
if (canonical(g.declaration.locationIds) !== canonical([...c.locationIds].sort()) || canonical(g.declaration.excludedLocationIds) !== canonical([...c.excludedLocationIds].sort()))
|
|
984
|
-
if (g.declaration.declaredForCampaignRevision > r.expectedRevision || Date.parse(g.declaration.declaredAt) > Date.parse(r.preparedAt))
|
|
985
|
-
} else if (google !== null)
|
|
1002
|
+
if (canonical(g.declaration.locationIds) !== canonical([...c.locationIds].sort()) || canonical(g.declaration.excludedLocationIds) !== canonical([...c.excludedLocationIds].sort())) fail3("preparedPlan.channelPreviews.googleConfiguration.declaration", "region scope mismatch");
|
|
1003
|
+
if (g.declaration.declaredForCampaignRevision > r.expectedRevision || Date.parse(g.declaration.declaredAt) > Date.parse(r.preparedAt)) fail3("preparedPlan.channelPreviews.googleConfiguration.declaration", "declaration follows preparation scope");
|
|
1004
|
+
} else if (google !== null) fail3("preparedPlan.channelPreviews.googleConfiguration", "non-Google channels require explicit null");
|
|
986
1005
|
const d = r.definition.destinations.find((d2) => d2.id === c.destinationId);
|
|
987
1006
|
const expectedUrl = p.attributionMarker ? new URL(`https://${p.site}${d.path}`) : null;
|
|
988
1007
|
if (expectedUrl && p.attributionMarker) expectedUrl.searchParams.set(RESONANCE_SOURCE_MARKER_PARAMETER, p.attributionMarker.value);
|
|
989
|
-
if (!sameSite(hostFromUrl(p.destinationUrl), p.site) || p.destinationUrl !== (expectedUrl?.toString() ?? `https://${p.site}${d.path}`))
|
|
990
|
-
if (canonical(p.orderedCreatives) !== canonical(c.creativeIds.map((id) => r.definition.creativeRefs.find((x) => x.id === id))))
|
|
1008
|
+
if (!sameSite(hostFromUrl(p.destinationUrl), p.site) || p.destinationUrl !== (expectedUrl?.toString() ?? `https://${p.site}${d.path}`)) fail3("preparedPlan.channelPreviews.destinationUrl", "must be exact HTTPS destination and reviewed source marker on the owned site");
|
|
1009
|
+
if (canonical(p.orderedCreatives) !== canonical(c.creativeIds.map((id) => r.definition.creativeRefs.find((x) => x.id === id)))) fail3("preparedPlan.channelPreviews.orderedCreatives", "creative order/content mismatch");
|
|
991
1010
|
if ("provider" in c) {
|
|
992
|
-
if (p.accountBindingId !== c.accountBindingId || !r.accounts.some((a) => a.id === c.accountBindingId))
|
|
993
|
-
if (canonical(p.allocation) !== canonical(c.allocation))
|
|
994
|
-
} else if (p.accountBindingId !== null || p.allocation !== null)
|
|
1011
|
+
if (p.accountBindingId !== c.accountBindingId || !r.accounts.some((a) => a.id === c.accountBindingId)) fail3("preparedPlan.channelPreviews.accountBindingId", "account binding mismatch");
|
|
1012
|
+
if (canonical(p.allocation) !== canonical(c.allocation)) fail3("preparedPlan.channelPreviews.allocation", "allocation mismatch");
|
|
1013
|
+
} else if (p.accountBindingId !== null || p.allocation !== null) fail3("preparedPlan.channelPreviews", "nonpaid child cannot select paid account/allocation");
|
|
995
1014
|
}
|
|
996
1015
|
return r;
|
|
997
1016
|
}
|
|
998
1017
|
var commandBase = { schemaVersion: literal2(1), campaignId: uuid, expectedRevision: integer2(1), idempotencyKey: operationKey, channelIds: list2(uuid, 100) };
|
|
999
1018
|
var effect = object2({ ...commandBase, operation: choice2("launch", "update", "resume"), preparedPlanId: uuid, reviewDigest: digest, mandateRef, expectedRemoteSnapshots: list2(object2({ channelId: uuid, digest }), 100) });
|
|
1000
|
-
var googleContentEffect =
|
|
1019
|
+
var googleContentEffect = refine3(object2({
|
|
1001
1020
|
...commandBase,
|
|
1002
1021
|
operation: literal2("update"),
|
|
1003
1022
|
preparedPlanId: uuid,
|
|
@@ -1009,7 +1028,7 @@ var googleContentEffect = refine2(object2({
|
|
|
1009
1028
|
}), (command2, p) => {
|
|
1010
1029
|
const update2 = command2.googleContentUpdate, remote = command2.expectedRemoteSnapshots[0];
|
|
1011
1030
|
if (command2.channelIds[0] !== update2.channelId || remote.channelId !== update2.channelId || remote.digest !== update2.beforeDigest) {
|
|
1012
|
-
|
|
1031
|
+
fail3(p + ".googleContentUpdate", "requires the same single channel and before snapshot");
|
|
1013
1032
|
}
|
|
1014
1033
|
});
|
|
1015
1034
|
var optimize = object2({ ...commandBase, operation: literal2("optimize"), preparedPlanId: uuid, reviewDigest: digest, mandateRef, decisionRef: object2({ id: uuid, revision, evidenceDigest: digest }), expectedRemoteSnapshots: list2(object2({ channelId: uuid, digest }), 100) });
|
|
@@ -1020,101 +1039,101 @@ var command = union2(effect, googleContentEffect, optimize, safety, deliverConve
|
|
|
1020
1039
|
function parseResonanceCommand(v, context) {
|
|
1021
1040
|
const r = command.read(v, "command");
|
|
1022
1041
|
unique(r.channelIds, "command.channelIds");
|
|
1023
|
-
if ("mandateRef" in r && (r.mandateRef.campaignId !== r.campaignId || r.mandateRef.preparedPlanId !== r.preparedPlanId || r.mandateRef.reviewDigest !== r.reviewDigest))
|
|
1042
|
+
if ("mandateRef" in r && (r.mandateRef.campaignId !== r.campaignId || r.mandateRef.preparedPlanId !== r.preparedPlanId || r.mandateRef.reviewDigest !== r.reviewDigest)) fail3("command.mandateRef", "snapshot mismatch");
|
|
1024
1043
|
if ("googleContentUpdate" in r && context) {
|
|
1025
1044
|
const p = "command.googleContentUpdate", update2 = r.googleContentUpdate;
|
|
1026
1045
|
const plan = parseResonancePreparedPlan(context.preparedPlan);
|
|
1027
1046
|
const grant = parseResonanceMandateScope(context.mandate, plan);
|
|
1028
1047
|
const now = Date.parse(instant.read(context.now, "command.context.now"));
|
|
1029
1048
|
if (r.expectedRevision !== plan.expectedRevision || r.campaignId !== plan.campaignId || r.preparedPlanId !== plan.id || r.reviewDigest !== plan.reviewDigest || grant.projectId !== plan.projectId || grant.campaignId !== plan.campaignId || grant.preparedPlanId !== plan.id || grant.reviewDigest !== plan.reviewDigest || !grant.allowedOperations.includes("update") || canonical(grant.goal) !== canonical(plan.definition.objective) || canonical(grant.budget) !== canonical(plan.definition.budget) || now < Date.parse(grant.budget.startAt) || now >= Date.parse(grant.budget.endAt) || now >= Date.parse(grant.expiresAt)) {
|
|
1030
|
-
|
|
1049
|
+
fail3(p, "requires the current original Google mandate and flight");
|
|
1031
1050
|
}
|
|
1032
1051
|
const channel2 = plan.definition.channels.find((item) => item.id === update2.channelId);
|
|
1033
1052
|
if (channel2?.kind !== "google_search" || !grant.sites.includes(channel2.site) || !grant.accountBindingIds.includes(channel2.accountBindingId) || !channel2.adGroups.some((group) => group.localKey === update2.adGroupLocalKey && group.ads.some((ad) => ad.localKey === update2.adLocalKey))) {
|
|
1034
|
-
|
|
1053
|
+
fail3(p, "requires an original Google Search group and ad in scope");
|
|
1035
1054
|
} else if (update2.rsa) scoped(update2.rsa, plan.projectId, [channel2.site], p + ".rsa");
|
|
1036
1055
|
}
|
|
1037
1056
|
if ((r.operation === "deliver_conversion" || r.operation === "deliver_website_visit") && context) {
|
|
1038
1057
|
const plan = parseResonancePreparedPlan(context.preparedPlan), grant = parseResonanceMandateScope(context.mandate);
|
|
1039
1058
|
const now = Date.parse(instant.read(context.now, "command.context.now"));
|
|
1040
|
-
if (r.expectedRevision !== plan.expectedRevision)
|
|
1041
|
-
if (r.campaignId !== plan.campaignId || r.preparedPlanId !== plan.id || r.reviewDigest !== plan.reviewDigest || grant.projectId !== plan.projectId || grant.campaignId !== plan.campaignId || grant.preparedPlanId !== plan.id || grant.reviewDigest !== plan.reviewDigest)
|
|
1042
|
-
if (canonical(grant.goal) !== canonical(plan.definition.objective) || canonical(grant.budget) !== canonical(plan.definition.budget))
|
|
1059
|
+
if (r.expectedRevision !== plan.expectedRevision) fail3("command.expectedRevision", "requires the original prepared definition revision");
|
|
1060
|
+
if (r.campaignId !== plan.campaignId || r.preparedPlanId !== plan.id || r.reviewDigest !== plan.reviewDigest || grant.projectId !== plan.projectId || grant.campaignId !== plan.campaignId || grant.preparedPlanId !== plan.id || grant.reviewDigest !== plan.reviewDigest) fail3("command.context", "requires the exact original plan and mandate scope");
|
|
1061
|
+
if (canonical(grant.goal) !== canonical(plan.definition.objective) || canonical(grant.budget) !== canonical(plan.definition.budget)) fail3("command.context.mandate", "original goal or budget mismatch");
|
|
1043
1062
|
const channel2 = plan.definition.channels.find((c) => c.id === r.channelIds[0]);
|
|
1044
1063
|
if (r.operation === "deliver_conversion") {
|
|
1045
|
-
if (!grant.allowedOperations.includes("deliver_conversion"))
|
|
1046
|
-
if (!channel2 || channel2.kind !== "google_search")
|
|
1064
|
+
if (!grant.allowedOperations.includes("deliver_conversion")) fail3("command.context.mandate.allowedOperations", "requires the explicit original delivery grant");
|
|
1065
|
+
if (!channel2 || channel2.kind !== "google_search") fail3("command.channelIds", "requires one original Google channel");
|
|
1047
1066
|
const c = channel2;
|
|
1048
1067
|
const goal = plan.definition.objective, witness = plan.resolvedQualificationRule;
|
|
1049
|
-
if (goal.source.kind !== "qualified_lead" || goal.countingUnit !== "unique_qualified_contact" || !witness || witness.eligibleFormIds.length !== 1 || witness.eligibleFormIds[0] !== goal.source.id || !bookingTypesMatch(goal.eligibleBookingTypeIds, witness.eligibleBookingTypeIds) || goal.source.site !== c.site)
|
|
1068
|
+
if (goal.source.kind !== "qualified_lead" || goal.countingUnit !== "unique_qualified_contact" || !witness || witness.eligibleFormIds.length !== 1 || witness.eligibleFormIds[0] !== goal.source.id || !bookingTypesMatch(goal.eligibleBookingTypeIds, witness.eligibleBookingTypeIds) || goal.source.site !== c.site) fail3("command.context.goal", "requires the original single managed-form qualified source");
|
|
1050
1069
|
const account = plan.accounts.find((a) => a.id === c.accountBindingId);
|
|
1051
|
-
if (!account || account.provider !== "google_ads" || !grant.accountBindingIds.includes(c.accountBindingId) || !grant.sites.includes(c.site))
|
|
1070
|
+
if (!account || account.provider !== "google_ads" || !grant.accountBindingIds.includes(c.accountBindingId) || !grant.sites.includes(c.site)) fail3("command.context.account", "requires the original granted Google account and site");
|
|
1052
1071
|
const configuration = plan.channelPreviews.find((p) => p.channelId === c.id)?.googleConfiguration;
|
|
1053
|
-
if (!configuration || configuration.signalSemantics !== RESONANCE_GOOGLE_SIGNAL_SEMANTICS)
|
|
1072
|
+
if (!configuration || configuration.signalSemantics !== RESONANCE_GOOGLE_SIGNAL_SEMANTICS) fail3("command.context.googleConfiguration", "requires the reviewed qualified-at-observation profile");
|
|
1054
1073
|
const g = configuration;
|
|
1055
|
-
if (g.mode === "existing" && (g.nativeGoal.actionIds.length !== 1 || g.nativeGoal.actionIds[0].split("/")[1] !== account.externalAccountId || g.nativeGoal.externalId.split("/")[1] !== account.externalAccountId))
|
|
1056
|
-
if (g.mode === "admitted_setup" && (g.setupSpec.goalStrategy !== "exclusive_custom_goal_v1" || g.setupSpec.goalActionKey !== g.setupSpec.action.localKey))
|
|
1074
|
+
if (g.mode === "existing" && (g.nativeGoal.actionIds.length !== 1 || g.nativeGoal.actionIds[0].split("/")[1] !== account.externalAccountId || g.nativeGoal.externalId.split("/")[1] !== account.externalAccountId)) fail3("command.context.googleConfiguration.nativeGoal", "requires one action owned by the original account; cross-account delivery is unsupported");
|
|
1075
|
+
if (g.mode === "admitted_setup" && (g.setupSpec.goalStrategy !== "exclusive_custom_goal_v1" || g.setupSpec.goalActionKey !== g.setupSpec.action.localKey)) fail3("command.context.googleConfiguration.setupSpec", "requires the original single-action setup intent");
|
|
1057
1076
|
} else {
|
|
1058
1077
|
const selected = grant.websiteVisitFeed?.channels.find((c2) => c2.channelId === r.channelIds[0]);
|
|
1059
|
-
if (!selected)
|
|
1060
|
-
if (!channel2 || channel2.kind !== "meta_retargeting")
|
|
1078
|
+
if (!selected) fail3("command.context.mandate.websiteVisitFeed", "requires the explicit original feed channel");
|
|
1079
|
+
if (!channel2 || channel2.kind !== "meta_retargeting") fail3("command.channelIds", "requires one original Meta channel");
|
|
1061
1080
|
const c = channel2;
|
|
1062
1081
|
const account = plan.accounts.find((a) => a.id === c.accountBindingId);
|
|
1063
|
-
if (!account || account.provider !== "meta_ads" || !grant.accountBindingIds.includes(c.accountBindingId) || !grant.sites.includes(c.site))
|
|
1064
|
-
if (c.audienceRuleRefs.some((rule) => !grant.audienceRuleRefs.some((original) => canonical(original) === canonical(rule))))
|
|
1082
|
+
if (!account || account.provider !== "meta_ads" || !grant.accountBindingIds.includes(c.accountBindingId) || !grant.sites.includes(c.site)) fail3("command.context.account", "requires the original granted Meta account and site");
|
|
1083
|
+
if (c.audienceRuleRefs.some((rule) => !grant.audienceRuleRefs.some((original) => canonical(original) === canonical(rule)))) fail3("command.context.audienceRuleRefs", "requires the original granted audience rules");
|
|
1065
1084
|
}
|
|
1066
|
-
if (now < Date.parse(grant.budget.startAt) || now >= Date.parse(grant.budget.endAt) || now >= Date.parse(grant.expiresAt))
|
|
1085
|
+
if (now < Date.parse(grant.budget.startAt) || now >= Date.parse(grant.budget.endAt) || now >= Date.parse(grant.expiresAt)) fail3("command.context.now", "outside the original mandate and budget dispatch window");
|
|
1067
1086
|
}
|
|
1068
1087
|
return r;
|
|
1069
1088
|
}
|
|
1070
1089
|
var RESONANCE_COMMAND_JSON_SCHEMA = command.schema;
|
|
1071
|
-
var step = object2({ id: uuid, channelId: uuid, state: choice2("planned", "admitted", "confirmed", "failed", "uncertain"), providerRequestId: nullable2(
|
|
1072
|
-
var receipt = object2({ schemaVersion: literal2(1), id: uuid, projectId: uuid, campaignId: uuid, preparedPlanId: nullable2(uuid), effectKey:
|
|
1090
|
+
var step = object2({ id: uuid, channelId: uuid, state: choice2("planned", "admitted", "confirmed", "failed", "uncertain"), providerRequestId: nullable2(text3(200)), admission: choice2("not_dispatched", "accepted", "rejected", "unknown"), configuredStatus: nullable2(text3(80)), effectiveStatus: nullable2(text3(80)), reviewStatus: nullable2(text3(80)), retryAfter: nullable2(instant), errorSubcode: nullable2(text3(80)), errorFieldPath: nullable2(text3(200)), resourceRefs: list2(object2({ type: text3(80), externalId: text3(200) }), 100), evidenceDigest: nullable2(digest), errorCode: nullable2(text3(80)), observedAt: nullable2(instant) });
|
|
1091
|
+
var receipt = object2({ schemaVersion: literal2(1), id: uuid, projectId: uuid, campaignId: uuid, preparedPlanId: nullable2(uuid), effectKey: text3(200), requestDigest: digest, ledgerActionId: uuid, actorId: text3(160), state: choice2("pending", "applying", "accepted", "failed", "needs_reconciliation"), steps: list2(step, 1e3), reservedExposure: money, unreconciledExposure: money, providerSemanticsNotice: list2(text3(500), 30), nextActions: list2(choice2("read", "reconcile", "retry_same_operation", "pause", "escalate"), 5) });
|
|
1073
1092
|
function parseResonanceReceipt(v) {
|
|
1074
1093
|
const r = receipt.read(v, "receipt");
|
|
1075
|
-
if (r.reservedExposure.currency !== r.unreconciledExposure.currency)
|
|
1094
|
+
if (r.reservedExposure.currency !== r.unreconciledExposure.currency) fail3("receipt", "currency mismatch");
|
|
1076
1095
|
const uncertain = r.steps.some((s) => s.state === "uncertain" || s.admission === "unknown");
|
|
1077
|
-
if (uncertain && r.state !== "needs_reconciliation")
|
|
1078
|
-
if ((uncertain || r.state === "needs_reconciliation") && r.nextActions.includes("retry_same_operation"))
|
|
1096
|
+
if (uncertain && r.state !== "needs_reconciliation") fail3("receipt.state", "uncertain child requires reconciliation state");
|
|
1097
|
+
if ((uncertain || r.state === "needs_reconciliation") && r.nextActions.includes("retry_same_operation")) fail3("receipt.nextActions", "unknown admission must reconcile before retry");
|
|
1079
1098
|
return r;
|
|
1080
1099
|
}
|
|
1081
1100
|
var lifecycle = choice2("not_materialized", "pending", "partially_live", "live", "pausing", "paused", "finished", "needs_attention", "unknown");
|
|
1082
|
-
var view = object2({ id: uuid, projectId: uuid, managementMode: choice2("tracking_only", "managed"), revision: integer2(0), definition: nullable2(draft), acceptedPlanId: nullable2(uuid), desiredLifecycle: choice2("draft", "running", "paused", "finished"), effectiveLifecycle: lifecycle, blockingReasons: list2(
|
|
1101
|
+
var view = object2({ id: uuid, projectId: uuid, managementMode: choice2("tracking_only", "managed"), revision: integer2(0), definition: nullable2(draft), acceptedPlanId: nullable2(uuid), desiredLifecycle: choice2("draft", "running", "paused", "finished"), effectiveLifecycle: lifecycle, blockingReasons: list2(text3(200), 100), activeOperation: nullable2(receipt), unresolvedExposure: nullable2(money) });
|
|
1083
1102
|
function parseResonanceCampaignView(v) {
|
|
1084
1103
|
const r = view.read(v, "campaignView");
|
|
1085
|
-
if (r.managementMode === "managed" && r.revision < 1)
|
|
1104
|
+
if (r.managementMode === "managed" && r.revision < 1) fail3("campaignView.revision", "managed campaigns require revision >=1");
|
|
1086
1105
|
if (r.definition) parseResonanceCampaignDraft(r.definition);
|
|
1087
1106
|
if (r.activeOperation) parseResonanceReceipt(r.activeOperation);
|
|
1088
|
-
if (r.definition && r.definition.projectId !== r.projectId)
|
|
1089
|
-
if (r.activeOperation && (r.activeOperation.projectId !== r.projectId || r.activeOperation.campaignId !== r.id))
|
|
1107
|
+
if (r.definition && r.definition.projectId !== r.projectId) fail3("campaignView.definition", "cross-project reference");
|
|
1108
|
+
if (r.activeOperation && (r.activeOperation.projectId !== r.projectId || r.activeOperation.campaignId !== r.id)) fail3("campaignView.activeOperation", "scope mismatch");
|
|
1090
1109
|
return r;
|
|
1091
1110
|
}
|
|
1092
|
-
var metricValue = union2(object2({ kind: literal2("count"), count: decimal }), object2({ kind: literal2("money"), money }), object2({ kind: literal2("ratio"), numerator: decimal, denominator:
|
|
1093
|
-
if (v === "0")
|
|
1111
|
+
var metricValue = union2(object2({ kind: literal2("count"), count: decimal }), object2({ kind: literal2("money"), money }), object2({ kind: literal2("ratio"), numerator: decimal, denominator: refine3(decimal, (v, p) => {
|
|
1112
|
+
if (v === "0") fail3(p, "zero denominator");
|
|
1094
1113
|
}) }));
|
|
1095
|
-
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(
|
|
1096
|
-
var metric = union2(object2({ ...metricBase, state: literal2("observed"), value: metricValue }), object2({ ...metricBase, state: choice2("unknown", "insufficient", "delayed", "unavailable"), value: literal2(null), reasonCode:
|
|
1114
|
+
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(text3(100)), asOf: instant, dataThrough: nullable2(instant), maturityDelaySeconds: integer2(0), coverageBasisPoints: nullable2(integer2(0, 1e4)), eligibleExposures: nullable2(decimal), matureOutcomes: nullable2(decimal), native: nullable2(object2({ unit: text3(80), amount: decimal, currency: nullable2(currency), unitExponent: integer2(0, 9), providerVersion: text3(30) })) };
|
|
1115
|
+
var metric = union2(object2({ ...metricBase, state: literal2("observed"), value: metricValue }), object2({ ...metricBase, state: choice2("unknown", "insufficient", "delayed", "unavailable"), value: literal2(null), reasonCode: text3(80) }));
|
|
1097
1116
|
function parseResonanceMetricObservation(v) {
|
|
1098
1117
|
const r = metric.read(v, "metric");
|
|
1099
|
-
if (["accepted_goals", "qualified_goals", "revenue", "conversion_rate"].includes(r.name) && r.goalRevision === null)
|
|
1100
|
-
if (Date.parse(r.windowEnd) <= Date.parse(r.windowStart))
|
|
1101
|
-
if (r.name === "reach" !== (r.countingUnit === "provider_unique_reach"))
|
|
1118
|
+
if (["accepted_goals", "qualified_goals", "revenue", "conversion_rate"].includes(r.name) && r.goalRevision === null) fail3("metric.goalRevision", "goal measurement requires explicit revision");
|
|
1119
|
+
if (Date.parse(r.windowEnd) <= Date.parse(r.windowStart)) fail3("metric.window", "invalid window");
|
|
1120
|
+
if (r.name === "reach" !== (r.countingUnit === "provider_unique_reach")) fail3("metric.countingUnit", "reach, and only reach, counts unique provider reach");
|
|
1102
1121
|
if (r.state === "observed") {
|
|
1103
1122
|
const expected = r.name === "spend" || r.name === "revenue" ? "money" : r.name === "conversion_rate" ? "ratio" : "count";
|
|
1104
|
-
if (r.value.kind !== expected)
|
|
1123
|
+
if (r.value.kind !== expected) fail3("metric.value", "metric unit mismatch");
|
|
1105
1124
|
}
|
|
1106
1125
|
return r;
|
|
1107
1126
|
}
|
|
1108
1127
|
var purpose = choice2("analytics_storage", "ad_storage", "ad_user_data", "ad_personalization");
|
|
1109
|
-
var consent = object2({ ...scope, receiptId: uuid, visitorNamespace:
|
|
1128
|
+
var consent = object2({ ...scope, receiptId: uuid, visitorNamespace: text3(160), configRevision: revision, policyRevision: revision, consentRevision: integer2(1), state: choice2("unknown", "granted", "denied", "withdrawn"), purpose, observedAt: instant, evidenceRef: revision });
|
|
1110
1129
|
var parseResonanceConsentSnapshot = (v) => consent.read(v, "consent");
|
|
1111
|
-
var exposure = object2({ ...scope, experimentId: uuid, experimentRevision: integer2(1), assignmentId: uuid, variantKey:
|
|
1112
|
-
var conversion = object2({ schemaVersion: literal2(1), ...scope, eventId: uuid, sourceRef: source, campaignId: nullable2(uuid), goalRevision: revision, occurredAt: instant, receivedAt: instant, value: union2(object2({ state: literal2("observed"), money }), object2({ state: choice2("unknown", "unavailable"), money: literal2(null), reasonCode:
|
|
1130
|
+
var exposure = object2({ ...scope, experimentId: uuid, experimentRevision: integer2(1), assignmentId: uuid, variantKey: text3(80), exposureId: uuid, occurredAt: instant });
|
|
1131
|
+
var conversion = object2({ schemaVersion: literal2(1), ...scope, eventId: uuid, sourceRef: source, campaignId: nullable2(uuid), goalRevision: revision, occurredAt: instant, receivedAt: instant, value: union2(object2({ state: literal2("observed"), money }), object2({ state: choice2("unknown", "unavailable"), money: literal2(null), reasonCode: text3(80) })), consent: list2(consent, 4), experiment: nullable2(exposure) });
|
|
1113
1132
|
function parseResonanceConversionEnvelope(v) {
|
|
1114
1133
|
const r = conversion.read(v, "conversion");
|
|
1115
1134
|
unique(r.consent.map((c) => c.purpose), "conversion.consent");
|
|
1116
1135
|
scoped(r, r.projectId, [r.site], "conversion");
|
|
1117
|
-
if (Date.parse(r.receivedAt) < Date.parse(r.occurredAt))
|
|
1136
|
+
if (Date.parse(r.receivedAt) < Date.parse(r.occurredAt)) fail3("conversion.receivedAt", "precedes occurrence");
|
|
1118
1137
|
return r;
|
|
1119
1138
|
}
|
|
1120
1139
|
var RESONANCE_CONVERSION_JSON_SCHEMA = conversion.schema;
|
|
@@ -1136,9 +1155,9 @@ function parseResonanceMandateApprovalPayload(v, target) {
|
|
|
1136
1155
|
const r = mandateApproval.read(v, "mandateApproval"), t = mandateTarget.read(target, "target_ref");
|
|
1137
1156
|
parseResonanceMandateScope(r.mandate);
|
|
1138
1157
|
if (r.operatingPolicyBase && !r.mandate.operatingPolicy && !r.mandate.providerReporting) {
|
|
1139
|
-
|
|
1158
|
+
fail3("mandateApproval.operatingPolicyBase", "requires explicit prospective operating or reporting scope");
|
|
1140
1159
|
}
|
|
1141
|
-
if (r.mandate.projectId !== t.project_id || r.mandate.campaignId !== t.campaign_id || r.preparedPlanId !== r.mandate.preparedPlanId || r.reviewDigest !== r.mandate.reviewDigest)
|
|
1160
|
+
if (r.mandate.projectId !== t.project_id || r.mandate.campaignId !== t.campaign_id || r.preparedPlanId !== r.mandate.preparedPlanId || r.reviewDigest !== r.mandate.reviewDigest) fail3("mandateApproval", "target or snapshot mismatch");
|
|
1142
1161
|
return r;
|
|
1143
1162
|
}
|
|
1144
1163
|
function canonical(value) {
|
|
@@ -1152,7 +1171,7 @@ var parseResonanceMandateTarget = (v) => mandateTarget.read(v, "target_ref");
|
|
|
1152
1171
|
var positioningTarget = union2(
|
|
1153
1172
|
object2({ kind: literal2("broadcast"), channelId: uuid }),
|
|
1154
1173
|
object2({ kind: literal2("meta"), channelId: uuid, creativeId: uuid }),
|
|
1155
|
-
object2({ kind: literal2("google_search"), channelId: uuid, adGroupKey:
|
|
1174
|
+
object2({ kind: literal2("google_search"), channelId: uuid, adGroupKey: text3(80), adKey: text3(80) })
|
|
1156
1175
|
);
|
|
1157
1176
|
var positioningRequest = object2({
|
|
1158
1177
|
schemaVersion: literal2(1),
|
|
@@ -1165,46 +1184,46 @@ var positioningRequest = object2({
|
|
|
1165
1184
|
var positioningWitnessFields = {
|
|
1166
1185
|
id: operationKey,
|
|
1167
1186
|
kind: choice2("page", "funnel", "offer", "brain", "buyer", "proof"),
|
|
1168
|
-
sourceId:
|
|
1187
|
+
sourceId: text3(160),
|
|
1169
1188
|
revision,
|
|
1170
1189
|
observedAt: instant,
|
|
1171
1190
|
expiresAt: instant,
|
|
1172
1191
|
permission: choice2("private", "public"),
|
|
1173
1192
|
certainty: choice2("verified", "reported", "conflicting")
|
|
1174
1193
|
};
|
|
1175
|
-
var positioningWitness =
|
|
1176
|
-
var positioningText = (max) =>
|
|
1177
|
-
if (!value.trim() || /[\x00-\x08\x0b-\x1f\x7f]/.test(value))
|
|
1194
|
+
var positioningWitness = refine3(object2(positioningWitnessFields), checkPositioningWitness);
|
|
1195
|
+
var positioningText = (max) => refine3(text3(max), (value, at) => {
|
|
1196
|
+
if (!value.trim() || /[\x00-\x08\x0b-\x1f\x7f]/.test(value)) fail3(at, "requires nonblank text without control characters");
|
|
1178
1197
|
});
|
|
1179
|
-
var positioningEvidence =
|
|
1198
|
+
var positioningEvidence = refine3(object2({ ...positioningWitnessFields, text: positioningText(1600) }), checkPositioningWitness);
|
|
1180
1199
|
function checkPositioningWitness(value, at) {
|
|
1181
|
-
if (Date.parse(value.observedAt) >= Date.parse(value.expiresAt))
|
|
1200
|
+
if (Date.parse(value.observedAt) >= Date.parse(value.expiresAt)) fail3(at, "requires a positive witness lifetime");
|
|
1182
1201
|
}
|
|
1183
1202
|
var positioningScopeFields = { schemaVersion: literal2(1), projectId: uuid, campaignId: uuid, request: positioningRequest, observedAt: instant, expiresAt: instant };
|
|
1184
1203
|
function checkPositioningWindow(value, at) {
|
|
1185
|
-
if (Date.parse(value.observedAt) >= Date.parse(value.expiresAt))
|
|
1204
|
+
if (Date.parse(value.observedAt) >= Date.parse(value.expiresAt)) fail3(at, "requires a positive review lifetime");
|
|
1186
1205
|
unique(value.evidence.map((item) => item.id), at + ".evidence");
|
|
1187
|
-
if (value.evidence.some((item) => Date.parse(item.observedAt) > Date.parse(value.observedAt)))
|
|
1206
|
+
if (value.evidence.some((item) => Date.parse(item.observedAt) > Date.parse(value.observedAt))) fail3(at + ".evidence", "witness observation postdates the preview");
|
|
1188
1207
|
}
|
|
1189
|
-
var positioningContext =
|
|
1208
|
+
var positioningContext = refine3(object2({
|
|
1190
1209
|
...positioningScopeFields,
|
|
1191
1210
|
orgId: uuid,
|
|
1192
1211
|
evidence: list2(positioningEvidence, 32)
|
|
1193
1212
|
}), (value, at) => {
|
|
1194
1213
|
checkPositioningWindow(value, at);
|
|
1195
1214
|
if (value.evidence.reduce((total, witness) => total + witness.text.length, 0) > 16e3) {
|
|
1196
|
-
|
|
1215
|
+
fail3(at + ".evidence", "exceeds the combined source text budget");
|
|
1197
1216
|
}
|
|
1198
1217
|
});
|
|
1199
1218
|
var positioningEvidenceIds = uniqueList(operationKey, 8);
|
|
1200
1219
|
var positioningSupportedText = object2({ text: positioningText(320), evidenceIds: positioningEvidenceIds });
|
|
1201
|
-
var positioningAlternative =
|
|
1220
|
+
var positioningAlternative = refine3(object2({
|
|
1202
1221
|
text: positioningText(320),
|
|
1203
1222
|
kind: choice2("status_quo", "alternative"),
|
|
1204
1223
|
basis: choice2("evidence", "hypothesis"),
|
|
1205
1224
|
evidenceIds: positioningEvidenceIds
|
|
1206
1225
|
}), (value, at) => {
|
|
1207
|
-
if (value.basis === "evidence" !== value.evidenceIds.length > 0)
|
|
1226
|
+
if (value.basis === "evidence" !== value.evidenceIds.length > 0) fail3(at, "requires evidence references exactly for evidenced alternatives");
|
|
1208
1227
|
});
|
|
1209
1228
|
var positioningClaim = object2({
|
|
1210
1229
|
attribute: positioningText(320),
|
|
@@ -1245,7 +1264,7 @@ var positioningReasonCodes = choice2(
|
|
|
1245
1264
|
"generation_unavailable"
|
|
1246
1265
|
);
|
|
1247
1266
|
var RESONANCE_POSITIONING_METHOD_VERSION = "positioning_v1";
|
|
1248
|
-
var positioningResult =
|
|
1267
|
+
var positioningResult = refine3(object2({
|
|
1249
1268
|
methodVersion: literal2(RESONANCE_POSITIONING_METHOD_VERSION),
|
|
1250
1269
|
state: choice2("ready", "provisional", "no_fit"),
|
|
1251
1270
|
reasonCodes: uniqueList(positioningReasonCodes, 12),
|
|
@@ -1259,15 +1278,15 @@ var positioningResult = refine2(object2({
|
|
|
1259
1278
|
copy: nullable2(positioningCopy)
|
|
1260
1279
|
}), (value, at) => {
|
|
1261
1280
|
if (value.state !== "ready") {
|
|
1262
|
-
if (value.copy || !value.reasonCodes.length)
|
|
1281
|
+
if (value.copy || !value.reasonCodes.length) fail3(at, "requires a reason and no draft copy when held");
|
|
1263
1282
|
return;
|
|
1264
1283
|
}
|
|
1265
1284
|
const { copy, claims, category, bestFit, alternatives } = value;
|
|
1266
1285
|
if (!copy || value.reasonCodes.length || !claims.length || !category || !bestFit.length || !alternatives.length) {
|
|
1267
|
-
return
|
|
1286
|
+
return fail3(at, "requires a supported ready brief and channel draft");
|
|
1268
1287
|
}
|
|
1269
1288
|
unique(copy.claimIndexes.map(String), at + ".copy.claimIndexes");
|
|
1270
|
-
if (copy.claimIndexes.some((index) => index >= claims.length))
|
|
1289
|
+
if (copy.claimIndexes.some((index) => index >= claims.length)) fail3(at + ".copy.claimIndexes", "requires an existing claim index");
|
|
1271
1290
|
});
|
|
1272
1291
|
function checkPositioningEvidence(result, context, at) {
|
|
1273
1292
|
const evidence = new Map(context.evidence.map((witness) => [witness.id, witness]));
|
|
@@ -1279,37 +1298,37 @@ function checkPositioningEvidence(result, context, at) {
|
|
|
1279
1298
|
...result.category ? [result.category] : [],
|
|
1280
1299
|
...result.timelyContext ? [result.timelyContext] : []
|
|
1281
1300
|
];
|
|
1282
|
-
if (cited.some((item) => item.evidenceIds.some((id) => !evidence.has(id))))
|
|
1301
|
+
if (cited.some((item) => item.evidenceIds.some((id) => !evidence.has(id)))) fail3(at, "references unknown evidence");
|
|
1283
1302
|
for (const claim of result.claims) {
|
|
1284
1303
|
for (const id of claim.publicProofIds) {
|
|
1285
1304
|
const witness = evidence.get(id);
|
|
1286
|
-
if (!witness || witness.permission !== "public" || !current(witness))
|
|
1305
|
+
if (!witness || witness.permission !== "public" || !current(witness)) fail3(at, "public proof requires a current permitted witness");
|
|
1287
1306
|
}
|
|
1288
1307
|
}
|
|
1289
1308
|
if (result.timelyContext && (!result.timelyContext.evidenceIds.length || result.timelyContext.evidenceIds.some((id) => {
|
|
1290
1309
|
const witness = evidence.get(id);
|
|
1291
1310
|
return !witness || !current(witness);
|
|
1292
|
-
})))
|
|
1311
|
+
}))) fail3(at, "timely context requires current verified evidence");
|
|
1293
1312
|
if (!result.copy) return;
|
|
1294
|
-
if (result.copy.kind !== context.request.target.kind)
|
|
1313
|
+
if (result.copy.kind !== context.request.target.kind) fail3(at, "copy target differs from the request");
|
|
1295
1314
|
const { destination: selected, offerId } = context.request;
|
|
1296
1315
|
const owns = (kind, id) => {
|
|
1297
1316
|
const witnesses = context.evidence.filter((w) => w.kind === kind && (!id || w.sourceId.toLowerCase() === id.toLowerCase()));
|
|
1298
1317
|
return witnesses.some(current) && !witnesses.some((w) => w.certainty === "conflicting");
|
|
1299
1318
|
};
|
|
1300
1319
|
if (!selected || !owns(selected.kind === "existing_page" ? "page" : "funnel", selected.id) || !owns("brain") || offerId && !owns("offer", offerId)) {
|
|
1301
|
-
|
|
1320
|
+
fail3(at, "ready copy requires current destination, Brain and selected offer witnesses");
|
|
1302
1321
|
}
|
|
1303
1322
|
for (const index of result.copy.claimIndexes) {
|
|
1304
1323
|
const claim = result.claims[index];
|
|
1305
1324
|
if (![...claim.evidenceIds, ...claim.publicProofIds].every((id) => {
|
|
1306
1325
|
const witness = evidence.get(id);
|
|
1307
1326
|
return witness && witness.permission === "public" && current(witness);
|
|
1308
|
-
}))
|
|
1327
|
+
})) fail3(at, "selected copy requires current verified public claim evidence");
|
|
1309
1328
|
}
|
|
1310
1329
|
}
|
|
1311
|
-
var positioningApplicationToken =
|
|
1312
|
-
var positioningPreview =
|
|
1330
|
+
var positioningApplicationToken = text3(32e3, /^[a-zA-Z0-9._-]+$/);
|
|
1331
|
+
var positioningPreview = refine3(object2({
|
|
1313
1332
|
...positioningScopeFields,
|
|
1314
1333
|
evidence: list2(positioningWitness, 32),
|
|
1315
1334
|
result: positioningResult,
|
|
@@ -1317,7 +1336,7 @@ var positioningPreview = refine2(object2({
|
|
|
1317
1336
|
}), (value, at) => {
|
|
1318
1337
|
checkPositioningWindow(value, at);
|
|
1319
1338
|
checkPositioningEvidence(value.result, value, at + ".result");
|
|
1320
|
-
if (value.result.state === "ready" !== (value.applicationToken !== null))
|
|
1339
|
+
if (value.result.state === "ready" !== (value.applicationToken !== null)) fail3(at, "requires an application token exactly for ready copy");
|
|
1321
1340
|
});
|
|
1322
1341
|
var positioningApplyRequest = object2({ applicationToken: positioningApplicationToken });
|
|
1323
1342
|
var parseResonancePositioningPreviewRequest = (value) => positioningRequest.read(value, "positioningPreviewRequest");
|
|
@@ -1357,12 +1376,12 @@ function parseResonancePositioningConsistencyAssessment(value, expected) {
|
|
|
1357
1376
|
const at = "positioningConsistencyAssessment";
|
|
1358
1377
|
const assessment = positioningConsistencyAssessment.read(value, at);
|
|
1359
1378
|
if (assessment.evidenceDigest !== digest.read(expected.evidenceDigest, at + ".expectedEvidenceDigest")) {
|
|
1360
|
-
|
|
1379
|
+
fail3(at + ".evidenceDigest", "requires the exact current permitted evidence digest");
|
|
1361
1380
|
}
|
|
1362
1381
|
const eligibleIds = new Set(projectResonancePositioningConsistencyEvidence(expected.context).map((witness) => witness.id));
|
|
1363
1382
|
const { state, coveredSourceIds } = assessment;
|
|
1364
1383
|
if (coveredSourceIds.some((id) => !eligibleIds.has(id)) || state !== "unknown" && coveredSourceIds.length !== eligibleIds.size || state === "compatible" && coveredSourceIds.length < 1 || state === "conflicting" && coveredSourceIds.length < 2) {
|
|
1365
|
-
|
|
1384
|
+
fail3(at + ".coveredSourceIds", "coverage does not support this consistency state");
|
|
1366
1385
|
}
|
|
1367
1386
|
return assessment;
|
|
1368
1387
|
}
|
|
@@ -1370,13 +1389,268 @@ var RESONANCE_POSITIONING_CONSISTENCY_ASSESSMENT_JSON_SCHEMA = positioningConsis
|
|
|
1370
1389
|
var prepareCommand = object2({ expectedRevision: integer2(1), idempotencyKey: operationKey, googleContentUpdate: optional2(googleContentUpdateSelection) });
|
|
1371
1390
|
var parseResonancePrepareCommand = (v) => prepareCommand.read(v, "prepare");
|
|
1372
1391
|
var parseResonanceCommandPrepareRequest = parseResonancePrepareCommand;
|
|
1373
|
-
var commandPreparation = object2({ command: nullable2(command), covered: bool, approvalRequirement: nullable2(choice2("existing_mandate", "current_owner")), reasonCodes: list2(
|
|
1392
|
+
var commandPreparation = object2({ command: nullable2(command), covered: bool, approvalRequirement: nullable2(choice2("existing_mandate", "current_owner")), reasonCodes: list2(text3(200), 100) });
|
|
1374
1393
|
function parseResonanceCommandPrepareResponse(v) {
|
|
1375
1394
|
const r = commandPreparation.read(v, "commandPreparation");
|
|
1376
1395
|
if (r.command) parseResonanceCommand(r.command);
|
|
1377
1396
|
return r;
|
|
1378
1397
|
}
|
|
1379
1398
|
var RESONANCE_COMMAND_PREPARE_REQUEST_JSON_SCHEMA = prepareCommand.schema;
|
|
1399
|
+
var preparationLookupRequest = object2({ expectedRevision: integer2(1), idempotencyKey: operationKey });
|
|
1400
|
+
var preparationLookupOperation = object2({
|
|
1401
|
+
operationId: uuid,
|
|
1402
|
+
preparedPlanId: uuid,
|
|
1403
|
+
executionState: choice2("reserved", "claimed", "dispatched", "succeeded", "rejected", "uncertain", "cancelled"),
|
|
1404
|
+
createdAt: instant,
|
|
1405
|
+
hasAdDispatch: bool,
|
|
1406
|
+
artifactCount: integer2(0, 512),
|
|
1407
|
+
completedArtifactCount: integer2(0, 512),
|
|
1408
|
+
originalActorMatches: bool,
|
|
1409
|
+
originalPrincipalMatches: bool
|
|
1410
|
+
});
|
|
1411
|
+
var preparationLookupResponse = object2({
|
|
1412
|
+
schemaVersion: literal2(1),
|
|
1413
|
+
projectId: uuid,
|
|
1414
|
+
campaignId: uuid,
|
|
1415
|
+
request: preparationLookupRequest,
|
|
1416
|
+
state: choice2("not_found", "working", "recovery_required", "succeeded", "rejected", "cancelled"),
|
|
1417
|
+
currentRevision: integer2(1),
|
|
1418
|
+
operation: nullable2(preparationLookupOperation),
|
|
1419
|
+
preparedPlan: nullable2(prepared),
|
|
1420
|
+
readiness: object2({ reasonCodes: list2(choice2(
|
|
1421
|
+
"PREPARATION_NOT_FOUND",
|
|
1422
|
+
"PREPARATION_WORKING",
|
|
1423
|
+
"PREPARATION_RECOVERY_REQUIRED",
|
|
1424
|
+
"PREPARATION_REJECTED",
|
|
1425
|
+
"PREPARATION_CANCELLED",
|
|
1426
|
+
"PREPARATION_OWNER_MISMATCH",
|
|
1427
|
+
"PREPARATION_REVISION_CHANGED",
|
|
1428
|
+
"PREPARATION_HAS_AD_DISPATCH",
|
|
1429
|
+
"PREPARATION_INVENTORY_UNAVAILABLE",
|
|
1430
|
+
"PREPARATION_TERMINAL_PROVIDER_REJECTION",
|
|
1431
|
+
"PREPARATION_ACCEPTED_REVIEW_AVAILABLE",
|
|
1432
|
+
"PREPARATION_FINANCIAL_EXPOSURE",
|
|
1433
|
+
"OWNER_STEP_FAILED",
|
|
1434
|
+
"OWNER_SOURCE_CHANGED",
|
|
1435
|
+
"SIGNER_CHANGED"
|
|
1436
|
+
), 30), canResume: bool })
|
|
1437
|
+
});
|
|
1438
|
+
var parseResonancePreparationLookupRequest = (v) => preparationLookupRequest.read(v, "preparationLookupRequest");
|
|
1439
|
+
function parseResonancePreparationLookupResponse(v) {
|
|
1440
|
+
const r = preparationLookupResponse.read(v, "preparationLookupResponse"), p = "preparationLookupResponse";
|
|
1441
|
+
if (r.state === "not_found") {
|
|
1442
|
+
if (r.operation || r.preparedPlan || r.readiness.canResume) fail3(p, "absence cannot carry a saved operation, plan or recovery permission");
|
|
1443
|
+
return r;
|
|
1444
|
+
}
|
|
1445
|
+
const o = r.operation;
|
|
1446
|
+
if (!o || o.completedArtifactCount > o.artifactCount) return fail3(p + ".operation", "requires the original operation and consistent artifact counts");
|
|
1447
|
+
const terminal = ["succeeded", "rejected", "cancelled"].includes(r.state);
|
|
1448
|
+
if (terminal ? o.executionState !== r.state : !["reserved", "claimed", "dispatched", "uncertain"].includes(o.executionState)) fail3(p + ".state", "does not match the original execution state");
|
|
1449
|
+
if (r.readiness.canResume && (r.state !== "recovery_required" || o.hasAdDispatch || !o.originalActorMatches || !o.originalPrincipalMatches || r.currentRevision !== r.request.expectedRevision)) fail3(p + ".readiness", "requires the same original caller and a recoverable pre-dispatch outcome");
|
|
1450
|
+
if (r.state === "succeeded") {
|
|
1451
|
+
if (!r.preparedPlan) return fail3(p + ".preparedPlan", "requires the saved original plan");
|
|
1452
|
+
const plan = parseResonancePreparedPlan(r.preparedPlan);
|
|
1453
|
+
if (plan.projectId !== r.projectId || plan.campaignId !== r.campaignId || plan.expectedRevision !== r.request.expectedRevision || plan.id !== o.preparedPlanId) fail3(p + ".preparedPlan", "must match the exact original request and operation");
|
|
1454
|
+
} else if (r.preparedPlan) fail3(p + ".preparedPlan", "an unfinished preparation cannot return a successful plan");
|
|
1455
|
+
return r;
|
|
1456
|
+
}
|
|
1457
|
+
var RESONANCE_PREPARATION_LOOKUP_REQUEST_JSON_SCHEMA = preparationLookupRequest.schema;
|
|
1458
|
+
var RESONANCE_PREPARATION_LOOKUP_RESPONSE_JSON_SCHEMA = preparationLookupResponse.schema;
|
|
1459
|
+
var preparationRetireRequest = object2({ expectedRevision: integer2(1), reason: literal2("retain_unpublished_artifacts") });
|
|
1460
|
+
var preparationRetireResponse = refine3(object2({
|
|
1461
|
+
schemaVersion: literal2(1),
|
|
1462
|
+
projectId: uuid,
|
|
1463
|
+
campaignId: uuid,
|
|
1464
|
+
preparationOperationId: uuid,
|
|
1465
|
+
state: literal2("cancelled"),
|
|
1466
|
+
replayed: bool,
|
|
1467
|
+
retainedArtifactCount: integer2(0, 512),
|
|
1468
|
+
unrecordedSlotCount: integer2(0, 512),
|
|
1469
|
+
retiredAt: instant,
|
|
1470
|
+
reasonCodes: list2(text3(100), 0)
|
|
1471
|
+
}), (v, p) => {
|
|
1472
|
+
if (v.retainedArtifactCount + v.unrecordedSlotCount > 512) fail3(p, "artifact and unrecorded slot total exceeds bound");
|
|
1473
|
+
});
|
|
1474
|
+
var parseResonancePreparationRetireRequest = (v) => preparationRetireRequest.read(v, "preparationRetireRequest");
|
|
1475
|
+
var parseResonancePreparationRetireResponse = (v) => preparationRetireResponse.read(v, "preparationRetireResponse");
|
|
1476
|
+
var RESONANCE_PREPARATION_RETIRE_REQUEST_JSON_SCHEMA = preparationRetireRequest.schema;
|
|
1477
|
+
var RESONANCE_PREPARATION_RETIRE_RESPONSE_JSON_SCHEMA = preparationRetireResponse.schema;
|
|
1478
|
+
var diagnosticsCode = text3(100, /^[A-Za-z][A-Za-z0-9_]*$/);
|
|
1479
|
+
var diagnosticsReasons = list2(diagnosticsCode, 64);
|
|
1480
|
+
var diagnosticsId = text3(30, /^[1-9][0-9]*$/);
|
|
1481
|
+
var diagnosticsResource = text3(200, /^customers\/[0-9]+\/(?:conversionActions|customConversionGoals)\/[0-9]+$/);
|
|
1482
|
+
var diagnosticsDay = refine3(text3(10, /^\d{4}-\d{2}-\d{2}$/), (v, p) => {
|
|
1483
|
+
if (!Number.isFinite(Date.parse(v)) || new Date(v).toISOString().slice(0, 10) !== v || v.startsWith("0000")) fail3(p, "invalid calendar date");
|
|
1484
|
+
});
|
|
1485
|
+
var RESONANCE_GOOGLE_DIAGNOSTICS_SECTIONS = ["campaign", "totals", "daily", "keywords", "searchTerms", "goals", "uploadDiagnostics"];
|
|
1486
|
+
var googleDiagnosticsRequestFields = {
|
|
1487
|
+
channelId: uuid,
|
|
1488
|
+
startDate: diagnosticsDay,
|
|
1489
|
+
endDate: diagnosticsDay,
|
|
1490
|
+
sections: list2(choice2(...RESONANCE_GOOGLE_DIAGNOSTICS_SECTIONS), 7, 1),
|
|
1491
|
+
directive: text3(2e3)
|
|
1492
|
+
};
|
|
1493
|
+
var checkDiagnosticsRequest = (v, p) => {
|
|
1494
|
+
unique(v.sections, p + ".sections");
|
|
1495
|
+
const days = (Date.parse(v.endDate) - Date.parse(v.startDate)) / 864e5 + 1;
|
|
1496
|
+
if (days < 1 || days > 31) fail3(p, "requires one to 31 calendar days");
|
|
1497
|
+
if (!v.directive.trim()) fail3(p + ".directive", "requires an explicit command");
|
|
1498
|
+
};
|
|
1499
|
+
var googleDiagnosticsRequest = refine3(object2(googleDiagnosticsRequestFields), checkDiagnosticsRequest);
|
|
1500
|
+
var parseResonanceGoogleCampaignDiagnosticsRequest = (v) => googleDiagnosticsRequest.read(v, "googleCampaignDiagnosticsRequest");
|
|
1501
|
+
var RESONANCE_GOOGLE_CAMPAIGN_DIAGNOSTICS_REQUEST_JSON_SCHEMA = googleDiagnosticsRequest.schema;
|
|
1502
|
+
var googleDiagnosticsPayload = refine3(object2({
|
|
1503
|
+
schemaVersion: literal2(1),
|
|
1504
|
+
campaignId: uuid,
|
|
1505
|
+
expectedRevision: integer2(1),
|
|
1506
|
+
...googleDiagnosticsRequestFields,
|
|
1507
|
+
accountBindingId: uuid,
|
|
1508
|
+
site,
|
|
1509
|
+
idempotencyKey: operationKey
|
|
1510
|
+
}), checkDiagnosticsRequest);
|
|
1511
|
+
var parseResonanceGoogleCampaignDiagnosticsPayload = (v) => googleDiagnosticsPayload.read(v, "googleCampaignDiagnosticsPayload");
|
|
1512
|
+
var RESONANCE_GOOGLE_CAMPAIGN_DIAGNOSTICS_PAYLOAD_JSON_SCHEMA = googleDiagnosticsPayload.schema;
|
|
1513
|
+
var diagnosticsMetricsFields = {
|
|
1514
|
+
spendMicros: nullable2(decimal),
|
|
1515
|
+
impressions: nullable2(decimal),
|
|
1516
|
+
clicks: nullable2(decimal),
|
|
1517
|
+
conversions: nullable2(text3(61, /^(?:0|[1-9][0-9]{0,29})(?:\.[0-9]{0,29}[1-9])?$/)),
|
|
1518
|
+
allConversions: nullable2(text3(61, /^(?:0|[1-9][0-9]{0,29})(?:\.[0-9]{0,29}[1-9])?$/))
|
|
1519
|
+
};
|
|
1520
|
+
var diagnosticsMetrics = object2(diagnosticsMetricsFields);
|
|
1521
|
+
var diagnosticsCampaignRow = object2({
|
|
1522
|
+
status: diagnosticsCode,
|
|
1523
|
+
primaryStatus: nullable2(diagnosticsCode),
|
|
1524
|
+
primaryStatusReasons: diagnosticsReasons,
|
|
1525
|
+
servingStatus: nullable2(diagnosticsCode),
|
|
1526
|
+
biddingStrategyType: nullable2(diagnosticsCode),
|
|
1527
|
+
startDate: nullable2(diagnosticsDay),
|
|
1528
|
+
endDate: nullable2(diagnosticsDay),
|
|
1529
|
+
budgetAmountMicros: nullable2(decimal),
|
|
1530
|
+
budgetPeriod: nullable2(diagnosticsCode),
|
|
1531
|
+
searchNetwork: nullable2(bool),
|
|
1532
|
+
searchPartners: nullable2(bool),
|
|
1533
|
+
displayNetwork: nullable2(bool),
|
|
1534
|
+
positiveGeoTargetType: nullable2(diagnosticsCode),
|
|
1535
|
+
negativeGeoTargetType: nullable2(diagnosticsCode),
|
|
1536
|
+
locationCriterionIds: list2(diagnosticsId, 100)
|
|
1537
|
+
});
|
|
1538
|
+
var diagnosticsKeywordRow = object2({
|
|
1539
|
+
criterionId: diagnosticsId,
|
|
1540
|
+
adGroupId: diagnosticsId,
|
|
1541
|
+
matchType: nullable2(diagnosticsCode),
|
|
1542
|
+
status: nullable2(diagnosticsCode),
|
|
1543
|
+
negative: bool,
|
|
1544
|
+
...diagnosticsMetricsFields
|
|
1545
|
+
});
|
|
1546
|
+
var diagnosticsTermRow = object2({
|
|
1547
|
+
rowId: digest,
|
|
1548
|
+
adGroupId: diagnosticsId,
|
|
1549
|
+
status: nullable2(diagnosticsCode),
|
|
1550
|
+
keywordCriterionId: nullable2(diagnosticsId),
|
|
1551
|
+
matchType: nullable2(diagnosticsCode),
|
|
1552
|
+
...diagnosticsMetricsFields
|
|
1553
|
+
});
|
|
1554
|
+
var diagnosticsGoalRow = object2({
|
|
1555
|
+
goalConfigLevel: nullable2(diagnosticsCode),
|
|
1556
|
+
customGoalResourceName: nullable2(diagnosticsResource),
|
|
1557
|
+
customGoalStatus: nullable2(diagnosticsCode),
|
|
1558
|
+
actionResourceName: diagnosticsResource,
|
|
1559
|
+
actionStatus: nullable2(diagnosticsCode),
|
|
1560
|
+
type: nullable2(diagnosticsCode),
|
|
1561
|
+
category: nullable2(diagnosticsCode),
|
|
1562
|
+
primaryForGoal: nullable2(bool),
|
|
1563
|
+
countingType: nullable2(diagnosticsCode),
|
|
1564
|
+
clickThroughLookbackWindowDays: nullable2(integer2(1, 365))
|
|
1565
|
+
});
|
|
1566
|
+
var diagnosticsUploadRow = object2({
|
|
1567
|
+
actionResourceName: diagnosticsResource,
|
|
1568
|
+
client: nullable2(diagnosticsCode),
|
|
1569
|
+
status: nullable2(diagnosticsCode),
|
|
1570
|
+
lastUploadDateTime: nullable2(text3(40, /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:\d{2})?$/)),
|
|
1571
|
+
totalEventCount: nullable2(decimal),
|
|
1572
|
+
successfulEventCount: nullable2(decimal),
|
|
1573
|
+
pendingEventCount: nullable2(decimal),
|
|
1574
|
+
alertCodes: diagnosticsReasons
|
|
1575
|
+
});
|
|
1576
|
+
function diagnosticsSection(row, max) {
|
|
1577
|
+
return refine3(object2({
|
|
1578
|
+
state: choice2("available", "unavailable", "capped"),
|
|
1579
|
+
reasonCodes: diagnosticsReasons,
|
|
1580
|
+
rows: list2(row, max),
|
|
1581
|
+
pagesRead: integer2(0, 100)
|
|
1582
|
+
}), (v, p) => {
|
|
1583
|
+
if (v.state === "unavailable" && v.rows.length) fail3(p, "unavailable sections cannot assert observed rows");
|
|
1584
|
+
if (v.state !== "available" && !v.reasonCodes.length) fail3(p, "incomplete sections require a reason");
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
var googleDiagnosticsReport = object2({
|
|
1588
|
+
schemaVersion: literal2(1),
|
|
1589
|
+
provider: literal2("google_ads"),
|
|
1590
|
+
projectId: uuid,
|
|
1591
|
+
campaignId: uuid,
|
|
1592
|
+
channelId: uuid,
|
|
1593
|
+
site,
|
|
1594
|
+
accountBindingId: uuid,
|
|
1595
|
+
externalCampaignId: diagnosticsId,
|
|
1596
|
+
currency,
|
|
1597
|
+
accountTimeZone: timeZone,
|
|
1598
|
+
window: object2({ startDate: diagnosticsDay, endDate: diagnosticsDay, completeness: literal2("completed_days") }),
|
|
1599
|
+
observedAt: instant,
|
|
1600
|
+
sections: object2({
|
|
1601
|
+
campaign: diagnosticsSection(diagnosticsCampaignRow, 1),
|
|
1602
|
+
totals: diagnosticsSection(diagnosticsMetrics, 1),
|
|
1603
|
+
daily: diagnosticsSection(object2({ localDate: diagnosticsDay, ...diagnosticsMetricsFields }), 31),
|
|
1604
|
+
keywords: diagnosticsSection(diagnosticsKeywordRow, 500),
|
|
1605
|
+
searchTerms: diagnosticsSection(diagnosticsTermRow, 1e3),
|
|
1606
|
+
goals: diagnosticsSection(diagnosticsGoalRow, 100),
|
|
1607
|
+
uploadDiagnostics: diagnosticsSection(diagnosticsUploadRow, 300)
|
|
1608
|
+
}),
|
|
1609
|
+
searchTermCoverage: object2({
|
|
1610
|
+
state: choice2("available", "unavailable"),
|
|
1611
|
+
reasonCodes: diagnosticsReasons,
|
|
1612
|
+
disclosed: nullable2(diagnosticsMetrics),
|
|
1613
|
+
remainder: nullable2(diagnosticsMetrics)
|
|
1614
|
+
}),
|
|
1615
|
+
providerAuthored: object2({
|
|
1616
|
+
campaignName: nullable2(text3(300)),
|
|
1617
|
+
keywords: list2(object2({ adGroupId: diagnosticsId, criterionId: diagnosticsId, text: text3(500) }), 500),
|
|
1618
|
+
searchTerms: list2(object2({ rowId: digest, text: text3(500) }), 1e3),
|
|
1619
|
+
locations: list2(object2({ criterionId: diagnosticsId, name: text3(300) }), 100)
|
|
1620
|
+
})
|
|
1621
|
+
});
|
|
1622
|
+
function parseResonanceGoogleCampaignDiagnosticsReport(v) {
|
|
1623
|
+
const r = googleDiagnosticsReport.read(v, "googleCampaignDiagnosticsReport"), p = "googleCampaignDiagnosticsReport";
|
|
1624
|
+
const { startDate, endDate } = r.window;
|
|
1625
|
+
if (endDate < startDate || Date.parse(endDate) - Date.parse(startDate) > 30 * 864e5) fail3(p + ".window", "requires at most 31 calendar days");
|
|
1626
|
+
const local = new Intl.DateTimeFormat("en-CA", { timeZone: r.accountTimeZone, year: "numeric", month: "2-digit", day: "2-digit" }).formatToParts(new Date(r.observedAt));
|
|
1627
|
+
const today = ["year", "month", "day"].map((type) => local.find((part) => part.type === type).value).join("-");
|
|
1628
|
+
if (endDate >= today) fail3(p + ".window", "requires completed advertiser-local days");
|
|
1629
|
+
const days = r.sections.daily.rows.map((row) => row.localDate);
|
|
1630
|
+
if (days.some((day) => day < startDate || day > endDate)) fail3(p + ".daily", "row outside requested window");
|
|
1631
|
+
unique(days, p + ".daily");
|
|
1632
|
+
const keywordKey = (row) => row.adGroupId + ":" + row.criterionId;
|
|
1633
|
+
unique(r.sections.keywords.rows.map(keywordKey), p + ".keywords");
|
|
1634
|
+
unique(r.sections.searchTerms.rows.map((row) => row.rowId), p + ".searchTerms");
|
|
1635
|
+
const coverage = r.searchTermCoverage;
|
|
1636
|
+
if (coverage.state === "unavailable" && (coverage.remainder || !coverage.reasonCodes.length)) fail3(p + ".searchTermCoverage", "unknown coverage must not assert a remainder");
|
|
1637
|
+
if (coverage.state === "available" && (r.sections.searchTerms.state !== "available" || r.sections.totals.state !== "available" || !coverage.disclosed || !coverage.remainder)) fail3(p + ".searchTermCoverage", "requires complete compatible totals and disclosed rows");
|
|
1638
|
+
if (coverage.state === "available") {
|
|
1639
|
+
const total = r.sections.totals.rows[0];
|
|
1640
|
+
if (!total) fail3(p + ".searchTermCoverage", "requires campaign totals");
|
|
1641
|
+
for (const metric2 of ["spendMicros", "impressions", "clicks"]) {
|
|
1642
|
+
const all = total[metric2], disclosed = coverage.disclosed[metric2], remainder = coverage.remainder[metric2];
|
|
1643
|
+
if (remainder !== null && (all === null || disclosed === null || BigInt(all) - BigInt(disclosed) !== BigInt(remainder))) fail3(p + ".searchTermCoverage", "remainder must match compatible disclosed and campaign totals");
|
|
1644
|
+
}
|
|
1645
|
+
if (coverage.remainder.conversions !== null || coverage.remainder.allConversions !== null) fail3(p + ".searchTermCoverage", "conversion remainder is not established by this profile");
|
|
1646
|
+
}
|
|
1647
|
+
const keywordIds = new Set(r.sections.keywords.rows.map(keywordKey)), termIds = new Set(r.sections.searchTerms.rows.map((row) => row.rowId));
|
|
1648
|
+
unique(r.providerAuthored.keywords.map(keywordKey), p + ".providerAuthored.keywords");
|
|
1649
|
+
unique(r.providerAuthored.searchTerms.map((row) => row.rowId), p + ".providerAuthored.searchTerms");
|
|
1650
|
+
if (r.providerAuthored.keywords.some((row) => !keywordIds.has(keywordKey(row))) || r.providerAuthored.searchTerms.some((row) => !termIds.has(row.rowId))) fail3(p + ".providerAuthored", "text must identify an observed row");
|
|
1651
|
+
return r;
|
|
1652
|
+
}
|
|
1653
|
+
var RESONANCE_GOOGLE_CAMPAIGN_DIAGNOSTICS_REPORT_JSON_SCHEMA = googleDiagnosticsReport.schema;
|
|
1380
1654
|
var RESONANCE_COMMAND_PREPARE_RESPONSE_JSON_SCHEMA = commandPreparation.schema;
|
|
1381
1655
|
function resonancePlanIssues(input, at) {
|
|
1382
1656
|
const plan = parseResonancePreparedPlan(input), issues = [];
|
|
@@ -1410,12 +1684,12 @@ function resonancePlanIssues(input, at) {
|
|
|
1410
1684
|
function compareMoney(a, b) {
|
|
1411
1685
|
a = parseMoney(a);
|
|
1412
1686
|
b = parseMoney(b);
|
|
1413
|
-
if (a.currency !== b.currency)
|
|
1687
|
+
if (a.currency !== b.currency) fail3("money.currency", "currency mismatch");
|
|
1414
1688
|
const left = BigInt(a.amountMicros), right = BigInt(b.amountMicros);
|
|
1415
1689
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
1416
1690
|
}
|
|
1417
1691
|
function subtractMoney(a, b) {
|
|
1418
|
-
if (compareMoney(a, b) < 0)
|
|
1692
|
+
if (compareMoney(a, b) < 0) fail3("money.amountMicros", "negative result");
|
|
1419
1693
|
return parseMoney({ currency: a.currency, amountMicros: (BigInt(a.amountMicros) - BigInt(b.amountMicros)).toString() });
|
|
1420
1694
|
}
|
|
1421
1695
|
function formatMoney(input) {
|
|
@@ -1427,21 +1701,21 @@ var saveCommand = object2({ definition: draft, expectedRevision: optional2(integ
|
|
|
1427
1701
|
function parseResonanceCampaignSaveCommand(v, mode = "update") {
|
|
1428
1702
|
const r = saveCommand.read(v, "save");
|
|
1429
1703
|
parseResonanceCampaignDraft(r.definition);
|
|
1430
|
-
if (mode !== "create" && mode !== "update")
|
|
1431
|
-
if (mode === "update" && (r.expectedRevision === void 0 || r.expectedRevision < 1))
|
|
1704
|
+
if (mode !== "create" && mode !== "update") fail3("save.mode", "unsupported mode");
|
|
1705
|
+
if (mode === "update" && (r.expectedRevision === void 0 || r.expectedRevision < 1)) fail3("save.expectedRevision", "required for update");
|
|
1432
1706
|
return r;
|
|
1433
1707
|
}
|
|
1434
1708
|
var acceptCommand = object2({ expectedRevision: integer2(1), ledgerActionId: uuid });
|
|
1435
1709
|
var parseResonanceAcceptCommand = (v) => acceptCommand.read(v, "accept");
|
|
1436
|
-
var bindingCommand = object2({ connectionId: uuid, provider: choice2("google_ads", "meta_ads"), externalAccountId:
|
|
1710
|
+
var bindingCommand = object2({ connectionId: uuid, provider: choice2("google_ads", "meta_ads"), externalAccountId: text3(160), expectedConnectionRevision: revision, idempotencyKey: operationKey });
|
|
1437
1711
|
var parseResonanceBindingCommand = (v) => bindingCommand.read(v, "binding");
|
|
1438
1712
|
var RESONANCE_SAVE_COMMAND_JSON_SCHEMA = saveCommand.schema;
|
|
1439
1713
|
var RESONANCE_ACCEPT_COMMAND_JSON_SCHEMA = acceptCommand.schema;
|
|
1440
1714
|
var RESONANCE_BINDING_COMMAND_JSON_SCHEMA = bindingCommand.schema;
|
|
1441
1715
|
var RESONANCE_CPQL_UNCERTAINTY_METHOD = "observational_cpql_missing_outcome_bound_v1";
|
|
1442
1716
|
var allocationHorizon = union2(
|
|
1443
|
-
|
|
1444
|
-
if (Date.parse(r.endAt) <= Date.parse(r.startAt))
|
|
1717
|
+
refine3(object2({ kind: literal2("finite_period"), startAt: instant, endAt: instant, timeZone, sourceRef: revision }), (r, p) => {
|
|
1718
|
+
if (Date.parse(r.endAt) <= Date.parse(r.startAt)) fail3(p, "invalid finite horizon");
|
|
1445
1719
|
}),
|
|
1446
1720
|
object2({ kind: literal2("daily_average"), timeZone, sourceRef: revision })
|
|
1447
1721
|
);
|
|
@@ -1453,7 +1727,7 @@ function conditionalCpqlOutcomeBound(input, spend) {
|
|
|
1453
1727
|
const n = BigInt(decimal.read(input.eligibleContacts, "bound.eligibleContacts"));
|
|
1454
1728
|
const c = BigInt(decimal.read(input.fullyResolvedContacts, "bound.fullyResolvedContacts"));
|
|
1455
1729
|
const k = BigInt(decimal.read(input.qualifiedContacts, "bound.qualifiedContacts"));
|
|
1456
|
-
if (c > n || k > c)
|
|
1730
|
+
if (c > n || k > c) fail3("bound", "inconsistent unique-contact source universe");
|
|
1457
1731
|
if (n === 0n || k === 0n || parseMoney(spend).amountMicros === "0") return null;
|
|
1458
1732
|
const u = n - c, denominator = 2n * k + u;
|
|
1459
1733
|
return Number((10000n * u + denominator - 1n) / denominator);
|
|
@@ -1481,17 +1755,17 @@ var allocationEvidenceFields = {
|
|
|
1481
1755
|
assignmentCheck: choice2("pass", "failed", "unknown", "not_applicable"),
|
|
1482
1756
|
powerCheck: choice2("pass", "failed", "unknown", "not_applicable")
|
|
1483
1757
|
};
|
|
1484
|
-
var allocationChannelFields = { channelId: uuid, site, accountBindingId: uuid, trackingState: choice2("healthy", "blocked", "unknown"), coverageBasisPoints: nullable2(integer2(0, 1e4)), coverageFamily: choice2("crm_attribution", "provider_import", "experiment_exposure"), coverageDefinitionRef: resource, coveredNumerator: nullable2(decimal), eligibleDenominator: nullable2(decimal), uncertaintyBasisPoints: nullable2(integer2(0, 1e4)), uncertaintySource: nullable2(uncertaintySource), dedupeCheck: choice2("pass", "failed", "unknown", "not_applicable"), qualificationCheck: choice2("pass", "failed", "unknown", "not_applicable"), reasonCodes: list2(
|
|
1485
|
-
if (![0, 2, 3, 6].includes(v))
|
|
1758
|
+
var allocationChannelFields = { channelId: uuid, site, accountBindingId: uuid, trackingState: choice2("healthy", "blocked", "unknown"), coverageBasisPoints: nullable2(integer2(0, 1e4)), coverageFamily: choice2("crm_attribution", "provider_import", "experiment_exposure"), coverageDefinitionRef: resource, coveredNumerator: nullable2(decimal), eligibleDenominator: nullable2(decimal), uncertaintyBasisPoints: nullable2(integer2(0, 1e4)), uncertaintySource: nullable2(uncertaintySource), dedupeCheck: choice2("pass", "failed", "unknown", "not_applicable"), qualificationCheck: choice2("pass", "failed", "unknown", "not_applicable"), reasonCodes: list2(text3(80), 50), capabilityRevision: revision, budgetMode: choice2("campaign_total", "average_daily", "lifetime", "daily"), allocationHorizon: nullable2(allocationHorizon), matureThrough: nullable2(instant), dataThrough: nullable2(instant), goalRevision: revision, countingUnit: choice2("unique_source", "unique_qualified_contact", "net_order"), attributionModel: text3(100), attributionWindowDays: integer2(1, 365), policyRevision: revision, currentAllocation: money, remoteSnapshotDigest: digest, observations: list2(metric, 100), providerUnitExponent: refine3(integer2(0, 6), (v, p) => {
|
|
1759
|
+
if (![0, 2, 3, 6].includes(v)) fail3(p, "unsupported provider exponent");
|
|
1486
1760
|
}), providerMaxUnits: decimal };
|
|
1487
1761
|
var { uncertaintySource: _legacyUncertaintyField, ...reportedChannelFields } = allocationChannelFields;
|
|
1488
1762
|
var matureOptimizationEvidence = object2({ ...allocationEvidenceFields, resolvedPolicy: matureOptimizationPolicy, channels: list2(object2({ ...allocationChannelFields, uncertaintySource: nullable2(uncertaintySource) }), 100, 1) });
|
|
1489
1763
|
var reportedCostFields = { basis: literal2("provider_reported_snapshot_v1"), observationId: uuid, sourceEvidenceDigest: digest, reportedSpend: money, queriedFrom: instant, queriedThrough: instant, firstReceivedAt: instant, receivedAt: instant, recordedAt: instant, providerFinality: literal2("unknown"), correctionsPossible: literal2(true) };
|
|
1490
1764
|
var reportedOutcomeSource = object2({ method: literal2(RESONANCE_CPQL_UNCERTAINTY_METHOD), eligibleContacts: decimal, fullyResolvedContacts: decimal, qualifiedContacts: decimal, sourceRevision: revision, qualificationRuleRef: resource, universeComplete: literal2(true) });
|
|
1491
|
-
var nativeSqlReadInstant =
|
|
1765
|
+
var nativeSqlReadInstant = refine3(text3(32, /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,6}))?(?:Z|\+00:00)$/), (v, p) => {
|
|
1492
1766
|
const match = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,6}))?(?:Z|\+00:00)$/.exec(v);
|
|
1493
1767
|
const projected = match[1] + "." + (match[2] ?? "").padEnd(3, "0").slice(0, 3) + "Z";
|
|
1494
|
-
if (!Number.isFinite(Date.parse(projected)) || new Date(projected).toISOString() !== projected)
|
|
1768
|
+
if (!Number.isFinite(Date.parse(projected)) || new Date(projected).toISOString() !== projected) fail3(p, "invalid native SQL UTC instant");
|
|
1495
1769
|
});
|
|
1496
1770
|
var providerReadClock = object2({ kind: literal2("sql_before_provider_read_lower_bound_v1"), notBeforeAt: nativeSqlReadInstant });
|
|
1497
1771
|
var channelReportedCost = object2({ ...reportedCostFields, readClock: providerReadClock });
|
|
@@ -1508,34 +1782,34 @@ function parseMatureOptimizationEvidence(v) {
|
|
|
1508
1782
|
const r = matureOptimizationEvidence.read(v, "optimizationEvidence");
|
|
1509
1783
|
for (const c of r.channels) {
|
|
1510
1784
|
if (c.uncertaintySource === null) {
|
|
1511
|
-
if (c.uncertaintyBasisPoints !== null)
|
|
1512
|
-
} else if (c.uncertaintySource.verifiedSpend.currency !== c.currentAllocation.currency || c.uncertaintyBasisPoints !== cpqlMissingOutcomeBound(c.uncertaintySource))
|
|
1785
|
+
if (c.uncertaintyBasisPoints !== null) fail3("optimizationEvidence.channels.uncertainty", "no bound without source witness");
|
|
1786
|
+
} else if (c.uncertaintySource.verifiedSpend.currency !== c.currentAllocation.currency || c.uncertaintyBasisPoints !== cpqlMissingOutcomeBound(c.uncertaintySource)) fail3("optimizationEvidence.channels.uncertainty", "source bound mismatch");
|
|
1513
1787
|
}
|
|
1514
1788
|
checkAllocationEvidence(r);
|
|
1515
1789
|
return r;
|
|
1516
1790
|
}
|
|
1517
1791
|
function checkAllocationEvidence(r) {
|
|
1518
|
-
if (r.objective.measurementRevision !== r.goalRevision)
|
|
1519
|
-
if (Date.parse(r.windowEnd) <= Date.parse(r.windowStart) || r.dataThrough !== null && Date.parse(r.dataThrough) > Date.parse(r.observedAt))
|
|
1792
|
+
if (r.objective.measurementRevision !== r.goalRevision) fail3("optimizationEvidence.goalRevision", "goal snapshot mismatch");
|
|
1793
|
+
if (Date.parse(r.windowEnd) <= Date.parse(r.windowStart) || r.dataThrough !== null && Date.parse(r.dataThrough) > Date.parse(r.observedAt)) fail3("optimizationEvidence.window", "invalid observed window");
|
|
1520
1794
|
const sites = r.channels.map((c) => c.site);
|
|
1521
1795
|
scoped(r, r.projectId, sites, "optimizationEvidence");
|
|
1522
1796
|
unique(r.channels.map((c) => c.channelId), "optimizationEvidence.channels");
|
|
1523
1797
|
const currency2 = r.channels[0].currentAllocation.currency;
|
|
1524
1798
|
for (const c of r.channels) {
|
|
1525
|
-
if (c.allocationHorizon !== null && (["campaign_total", "lifetime"].includes(c.budgetMode) ? c.allocationHorizon.kind !== "finite_period" : c.allocationHorizon.kind !== "daily_average"))
|
|
1799
|
+
if (c.allocationHorizon !== null && (["campaign_total", "lifetime"].includes(c.budgetMode) ? c.allocationHorizon.kind !== "finite_period" : c.allocationHorizon.kind !== "daily_average")) fail3("optimizationEvidence.channels.allocationHorizon", "unapproved budget period normalization");
|
|
1526
1800
|
if (c.coveredNumerator === null || c.eligibleDenominator === null || c.eligibleDenominator === "0") {
|
|
1527
|
-
if (c.coverageBasisPoints !== null)
|
|
1801
|
+
if (c.coverageBasisPoints !== null) fail3("optimizationEvidence.channels.coverage", "unknown denominator means unknown coverage");
|
|
1528
1802
|
} else {
|
|
1529
1803
|
const numerator = BigInt(c.coveredNumerator), denominator = BigInt(c.eligibleDenominator);
|
|
1530
|
-
if (numerator > denominator || c.coverageBasisPoints !== Number(numerator * 10000n / denominator))
|
|
1804
|
+
if (numerator > denominator || c.coverageBasisPoints !== Number(numerator * 10000n / denominator)) fail3("optimizationEvidence.channels.coverage", "coverage ratio mismatch");
|
|
1531
1805
|
}
|
|
1532
|
-
if (r.resolvedPolicy.sourceRef === null && c.policyRevision !== r.policyDigest)
|
|
1533
|
-
if (c.goalRevision !== r.goalRevision || c.countingUnit !== r.objective.countingUnit || c.attributionWindowDays !== r.objective.attributionWindowDays)
|
|
1534
|
-
if (c.currentAllocation.currency !== currency2)
|
|
1806
|
+
if (r.resolvedPolicy.sourceRef === null && c.policyRevision !== r.policyDigest) fail3("optimizationEvidence.channels.policyRevision", "inline policy digest mismatch");
|
|
1807
|
+
if (c.goalRevision !== r.goalRevision || c.countingUnit !== r.objective.countingUnit || c.attributionWindowDays !== r.objective.attributionWindowDays) fail3("optimizationEvidence.channels", "measurement semantics mismatch");
|
|
1808
|
+
if (c.currentAllocation.currency !== currency2) fail3("optimizationEvidence.channels", "currency mismatch");
|
|
1535
1809
|
moneyToProviderUnits(c.currentAllocation, { currency: currency2, unitExponent: c.providerUnitExponent, maxUnits: c.providerMaxUnits });
|
|
1536
1810
|
for (const observation of c.observations) {
|
|
1537
1811
|
parseResonanceMetricObservation(observation);
|
|
1538
|
-
if (observation.campaignId !== r.campaignId || observation.site !== c.site)
|
|
1812
|
+
if (observation.campaignId !== r.campaignId || observation.site !== c.site) fail3("optimizationEvidence.channels.observations", "scope mismatch");
|
|
1539
1813
|
}
|
|
1540
1814
|
}
|
|
1541
1815
|
}
|
|
@@ -1547,37 +1821,37 @@ function parseReportedOptimizationEvidence(v) {
|
|
|
1547
1821
|
function checkReportedAllocationEvidence(r) {
|
|
1548
1822
|
const p = "optimizationEvidence";
|
|
1549
1823
|
parseResonanceOptimizationPolicy(r.resolvedPolicy);
|
|
1550
|
-
if (r.objective.source.kind !== "qualified_lead" || r.objective.countingUnit !== "unique_qualified_contact" || !r.objective.qualificationRuleRef || r.objective.qualificationRuleRef.module !== "crm")
|
|
1551
|
-
if (r.dataThrough !== null)
|
|
1824
|
+
if (r.objective.source.kind !== "qualified_lead" || r.objective.countingUnit !== "unique_qualified_contact" || !r.objective.qualificationRuleRef || r.objective.qualificationRuleRef.module !== "crm") fail3(p + ".objective", "requires the original independent qualified-contact source");
|
|
1825
|
+
if (r.dataThrough !== null) fail3(p + ".dataThrough", "query coverage cannot become mature provider dataThrough");
|
|
1552
1826
|
unique(r.channels.map((c) => c.channelReportedCost.observationId), p + ".channels.channelReportedCost.observationId");
|
|
1553
1827
|
const observedAt = Date.parse(r.observedAt), windowStart = Date.parse(r.windowStart), windowEnd = Date.parse(r.windowEnd);
|
|
1554
|
-
if (windowEnd <= windowStart || windowEnd > observedAt)
|
|
1828
|
+
if (windowEnd <= windowStart || windowEnd > observedAt) fail3(p + ".window", "requires a completed observed interval");
|
|
1555
1829
|
let commonZone;
|
|
1556
1830
|
for (const c of r.channels) {
|
|
1557
1831
|
const cost = c.channelReportedCost, outcome = c.outcomeSource;
|
|
1558
|
-
if (c.dataThrough !== null)
|
|
1559
|
-
if (Date.parse(cost.queriedFrom) !== windowStart || Date.parse(cost.queriedThrough) !== windowEnd)
|
|
1832
|
+
if (c.dataThrough !== null) fail3(p + ".channels.dataThrough", "query coverage cannot become mature provider dataThrough");
|
|
1833
|
+
if (Date.parse(cost.queriedFrom) !== windowStart || Date.parse(cost.queriedThrough) !== windowEnd) fail3(p + ".channels.channelReportedCost", "requires the exact common query interval");
|
|
1560
1834
|
const firstReceived = Date.parse(cost.firstReceivedAt), received = Date.parse(cost.receivedAt), recorded = Date.parse(cost.recordedAt);
|
|
1561
1835
|
const anchor = Date.parse(cost.readClock.notBeforeAt);
|
|
1562
|
-
if (received < firstReceived)
|
|
1563
|
-
if (anchor < windowEnd || anchor > recorded || recorded > observedAt || observedAt - anchor > r.resolvedPolicy.maxEvidenceAgeSeconds * 1e3)
|
|
1564
|
-
if (cost.reportedSpend.currency !== c.currentAllocation.currency || canonical(outcome.qualificationRuleRef) !== canonical(r.objective.qualificationRuleRef))
|
|
1565
|
-
if (c.uncertaintyBasisPoints !== reportedCpqlMissingOutcomeBound({ ...outcome, reportedSpend: cost.reportedSpend }))
|
|
1836
|
+
if (received < firstReceived) fail3(p + ".channels.channelReportedCost", "HTTP receipts must retain internal ordering");
|
|
1837
|
+
if (anchor < windowEnd || anchor > recorded || recorded > observedAt || observedAt - anchor > r.resolvedPolicy.maxEvidenceAgeSeconds * 1e3) fail3(p + ".channels.channelReportedCost.readClock", "requires the original fresh SQL-before-HTTP lower bound and SQL receipt order");
|
|
1838
|
+
if (cost.reportedSpend.currency !== c.currentAllocation.currency || canonical(outcome.qualificationRuleRef) !== canonical(r.objective.qualificationRuleRef)) fail3(p + ".channels.outcomeSource", "requires original qualification reference and currency");
|
|
1839
|
+
if (c.uncertaintyBasisPoints !== reportedCpqlMissingOutcomeBound({ ...outcome, reportedSpend: cost.reportedSpend })) fail3(p + ".channels.uncertainty", "conditional source bound mismatch");
|
|
1566
1840
|
const spends = c.observations.filter((o) => o.name === "spend");
|
|
1567
|
-
if (spends.length !== 1)
|
|
1841
|
+
if (spends.length !== 1) fail3(p + ".channels.observations", "requires one exact provider spend snapshot, never overlapping sums");
|
|
1568
1842
|
const spend = spends[0];
|
|
1569
|
-
if (spend.state !== "observed" || spend.source !== "provider" || spend.countingUnit !== "provider_aggregate" || spend.attributionModel !== "provider_reported" || spend.value.kind !== "money" || canonical(spend.value.money) !== canonical(cost.reportedSpend) || Date.parse(spend.windowStart) !== windowStart || Date.parse(spend.windowEnd) !== windowEnd || spend.dataThrough !== null || Date.parse(spend.asOf) !== recorded)
|
|
1843
|
+
if (spend.state !== "observed" || spend.source !== "provider" || spend.countingUnit !== "provider_aggregate" || spend.attributionModel !== "provider_reported" || spend.value.kind !== "money" || canonical(spend.value.money) !== canonical(cost.reportedSpend) || Date.parse(spend.windowStart) !== windowStart || Date.parse(spend.windowEnd) !== windowEnd || spend.dataThrough !== null || Date.parse(spend.asOf) !== recorded) fail3(p + ".channels.observations", "reported spend must match the exact nonfinal provider snapshot");
|
|
1570
1844
|
const outcomes = c.observations.filter((o) => o.name === "qualified_goals");
|
|
1571
|
-
if (outcomes.length !== 1)
|
|
1845
|
+
if (outcomes.length !== 1) fail3(p + ".channels.observations", "requires one independent qualified-contact source");
|
|
1572
1846
|
const qualified = outcomes[0];
|
|
1573
|
-
if (qualified.state !== "observed" || qualified.source !== "first_party" || qualified.sourceRef !== outcome.sourceRevision || qualified.goalRevision !== r.goalRevision || qualified.countingUnit !== "unique_qualified_contact" || qualified.attributionModel !== r.resolvedPolicy.attributionModel || qualified.value.kind !== "count" || qualified.value.count !== outcome.qualifiedContacts || qualified.eligibleExposures !== outcome.eligibleContacts || qualified.matureOutcomes !== outcome.qualifiedContacts || qualified.dataThrough === null || Date.parse(qualified.dataThrough) < windowEnd || Date.parse(qualified.dataThrough) > observedAt || c.matureThrough === null || Date.parse(c.matureThrough) < windowEnd || Date.parse(c.matureThrough) > observedAt)
|
|
1847
|
+
if (qualified.state !== "observed" || qualified.source !== "first_party" || qualified.sourceRef !== outcome.sourceRevision || qualified.goalRevision !== r.goalRevision || qualified.countingUnit !== "unique_qualified_contact" || qualified.attributionModel !== r.resolvedPolicy.attributionModel || qualified.value.kind !== "count" || qualified.value.count !== outcome.qualifiedContacts || qualified.eligibleExposures !== outcome.eligibleContacts || qualified.matureOutcomes !== outcome.qualifiedContacts || qualified.dataThrough === null || Date.parse(qualified.dataThrough) < windowEnd || Date.parse(qualified.dataThrough) > observedAt || c.matureThrough === null || Date.parse(c.matureThrough) < windowEnd || Date.parse(c.matureThrough) > observedAt) fail3(p + ".channels.outcomeSource", "requires independent mature qualified-contact evidence");
|
|
1574
1848
|
const formatter = new Intl.DateTimeFormat("en-GB", { timeZone: spend.timeZone, hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" });
|
|
1575
|
-
if ([r.windowStart, r.windowEnd].some((t) => new Date(t).getUTCMilliseconds() !== 0 || formatter.format(new Date(t)) !== "00:00:00") || commonZone !== void 0 && commonZone !== spend.timeZone)
|
|
1849
|
+
if ([r.windowStart, r.windowEnd].some((t) => new Date(t).getUTCMilliseconds() !== 0 || formatter.format(new Date(t)) !== "00:00:00") || commonZone !== void 0 && commonZone !== spend.timeZone) fail3(p + ".channels.observations", "requires common advertiser-local completed days without rounding");
|
|
1576
1850
|
commonZone = spend.timeZone;
|
|
1577
1851
|
for (const o of c.observations) {
|
|
1578
1852
|
parseResonanceMetricObservation(o);
|
|
1579
|
-
if (o.projectId !== r.projectId || o.campaignId !== r.campaignId || o.site !== c.site || Date.parse(o.windowStart) !== windowStart || Date.parse(o.windowEnd) !== windowEnd || o.timeZone !== spend.timeZone || Date.parse(o.asOf) > observedAt)
|
|
1580
|
-
if (o.source === "provider" && o.dataThrough !== null)
|
|
1853
|
+
if (o.projectId !== r.projectId || o.campaignId !== r.campaignId || o.site !== c.site || Date.parse(o.windowStart) !== windowStart || Date.parse(o.windowEnd) !== windowEnd || o.timeZone !== spend.timeZone || Date.parse(o.asOf) > observedAt) fail3(p + ".channels.observations", "foreign or mismatched observation interval");
|
|
1854
|
+
if (o.source === "provider" && o.dataThrough !== null) fail3(p + ".channels.observations", "reported provider observation remains nonfinal");
|
|
1581
1855
|
}
|
|
1582
1856
|
}
|
|
1583
1857
|
checkAllocationEvidence(r);
|
|
@@ -1585,9 +1859,9 @@ function checkReportedAllocationEvidence(r) {
|
|
|
1585
1859
|
var optimizationEvidenceRefFields = { id: uuid, revision, evidenceDigest: digest };
|
|
1586
1860
|
var optimizationEvidenceRef = object2(optimizationEvidenceRefFields);
|
|
1587
1861
|
var finiteOwnMeasurement = union2(
|
|
1588
|
-
object2({ state: literal2("unobserved"), observations: literal2(null), reasonCodes: list2(
|
|
1589
|
-
object2({ state: choice2("pending", "blocked"), observations: nullable2(list2(metric, 100)), reasonCodes: list2(
|
|
1590
|
-
object2({ state: literal2("mature"), observations: list2(metric, 100, 1), reasonCodes: list2(
|
|
1862
|
+
object2({ state: literal2("unobserved"), observations: literal2(null), reasonCodes: list2(text3(80), 50) }),
|
|
1863
|
+
object2({ state: choice2("pending", "blocked"), observations: nullable2(list2(metric, 100)), reasonCodes: list2(text3(80), 50) }),
|
|
1864
|
+
object2({ state: literal2("mature"), observations: list2(metric, 100, 1), reasonCodes: list2(text3(80), 50) })
|
|
1591
1865
|
);
|
|
1592
1866
|
var finiteCandidateObservation = object2({
|
|
1593
1867
|
channelId: uuid,
|
|
@@ -1605,7 +1879,7 @@ var finiteCandidateObservation = object2({
|
|
|
1605
1879
|
coverageBasisPoints: nullable2(integer2(0, 1e4)),
|
|
1606
1880
|
dedupeCheck: choice2("pass", "failed", "unknown", "not_applicable"),
|
|
1607
1881
|
qualificationCheck: choice2("pass", "failed", "unknown", "not_applicable"),
|
|
1608
|
-
reasonCodes: list2(
|
|
1882
|
+
reasonCodes: list2(text3(80), 50),
|
|
1609
1883
|
ownMeasurement: finiteOwnMeasurement
|
|
1610
1884
|
});
|
|
1611
1885
|
var finiteOptimizationEvidence = object2({
|
|
@@ -1641,48 +1915,48 @@ function parseResonanceOptimizationEvidence(v, preparedPlan) {
|
|
|
1641
1915
|
if (!("evidenceKind" in r)) return parseMatureOptimizationEvidence(r);
|
|
1642
1916
|
if (r.evidenceKind === "reported_cpql_sql_clock_v1") return parseReportedOptimizationEvidence(r);
|
|
1643
1917
|
const p = "optimizationEvidence", policy = parseResonanceOptimizationPolicy(r.resolvedPolicy);
|
|
1644
|
-
if (r.objective.measurementRevision !== r.goalRevision || r.objective.countingUnit !== "unique_qualified_contact" || canonical(policy.measurementGuard.sourceRef) !== canonical(r.objective.source) || canonical(policy.measurementGuard.qualificationRuleRef) !== canonical(r.objective.qualificationRuleRef) || policy.measurementGuard.maturityDelaySeconds !== r.objective.maturityDelaySeconds)
|
|
1645
|
-
if (Date.parse(r.windowEnd) <= Date.parse(r.windowStart) || r.dataThrough !== null && Date.parse(r.dataThrough) > Date.parse(r.observedAt))
|
|
1918
|
+
if (r.objective.measurementRevision !== r.goalRevision || r.objective.countingUnit !== "unique_qualified_contact" || canonical(policy.measurementGuard.sourceRef) !== canonical(r.objective.source) || canonical(policy.measurementGuard.qualificationRuleRef) !== canonical(r.objective.qualificationRuleRef) || policy.measurementGuard.maturityDelaySeconds !== r.objective.maturityDelaySeconds) fail3(p + ".objective", "finite policy must retain the original qualified objective");
|
|
1919
|
+
if (Date.parse(r.windowEnd) <= Date.parse(r.windowStart) || r.dataThrough !== null && Date.parse(r.dataThrough) > Date.parse(r.observedAt)) fail3(p + ".window", "invalid observed window");
|
|
1646
1920
|
unique(r.candidates.map((c) => c.channelId), p + ".candidates");
|
|
1647
|
-
if (r.candidates.length !== policy.candidateChannelIds.length || r.candidates.some((c) => !policy.candidateChannelIds.includes(c.channelId)))
|
|
1921
|
+
if (r.candidates.length !== policy.candidateChannelIds.length || r.candidates.some((c) => !policy.candidateChannelIds.includes(c.channelId))) fail3(p + ".candidates", "must cover exactly the original finite policy");
|
|
1648
1922
|
scoped(r, r.projectId, r.candidates.map((c) => c.site), p);
|
|
1649
1923
|
for (const c of r.candidates) {
|
|
1650
|
-
if (c.graphDigest !== c.manifestRef.digest)
|
|
1651
|
-
if (c.cap.currency !== policy.totalExplorationCap.currency || BigInt(c.cap.amountMicros) === 0n)
|
|
1652
|
-
if (Date.parse(c.flight.endAt) <= Date.parse(c.flight.startAt))
|
|
1924
|
+
if (c.graphDigest !== c.manifestRef.digest) fail3(p + ".candidates.graphDigest", "must match the actual original manifest graph digest");
|
|
1925
|
+
if (c.cap.currency !== policy.totalExplorationCap.currency || BigInt(c.cap.amountMicros) === 0n) fail3(p + ".candidates.cap", "requires the original positive cap currency");
|
|
1926
|
+
if (Date.parse(c.flight.endAt) <= Date.parse(c.flight.startAt)) fail3(p + ".candidates.flight", "invalid original flight");
|
|
1653
1927
|
const schedule = policy.selection.eligibilitySchedule.find((s) => s.channelId === c.channelId);
|
|
1654
|
-
if (Date.parse(schedule.notBefore) < Date.parse(c.flight.startAt) || Date.parse(schedule.notAfter) > Date.parse(c.flight.endAt))
|
|
1655
|
-
if (c.lifecycle === "not_materialized" && (c.commitmentEvidenceRef !== null || c.activationsObserved !== 0))
|
|
1656
|
-
if (["active", "stopped"].includes(c.lifecycle) && c.activationsObserved !== 1)
|
|
1657
|
-
if (c.lifecycle === "not_materialized" && c.ownMeasurement.observations !== null || c.activationsObserved === 0 && c.ownMeasurement.state === "mature")
|
|
1658
|
-
if (c.ownMeasurement.state === "mature" && c.ownMeasurement.observations.some((o) => o.state !== "observed"))
|
|
1928
|
+
if (Date.parse(schedule.notBefore) < Date.parse(c.flight.startAt) || Date.parse(schedule.notAfter) > Date.parse(c.flight.endAt)) fail3(p + ".candidates.flight", "selection must stay inside original flight");
|
|
1929
|
+
if (c.lifecycle === "not_materialized" && (c.commitmentEvidenceRef !== null || c.activationsObserved !== 0)) fail3(p + ".candidates", "absence cannot borrow a commitment or prior activation");
|
|
1930
|
+
if (["active", "stopped"].includes(c.lifecycle) && c.activationsObserved !== 1) fail3(p + ".candidates.activationsObserved", "active/stopped state requires its original activation");
|
|
1931
|
+
if (c.lifecycle === "not_materialized" && c.ownMeasurement.observations !== null || c.activationsObserved === 0 && c.ownMeasurement.state === "mature") fail3(p + ".candidates.ownMeasurement", "cold/absent candidates cannot borrow mature observations");
|
|
1932
|
+
if (c.ownMeasurement.state === "mature" && c.ownMeasurement.observations.some((o) => o.state !== "observed")) fail3(p + ".candidates.ownMeasurement", "mature observations must be observed");
|
|
1659
1933
|
for (const o of c.ownMeasurement.observations ?? []) {
|
|
1660
1934
|
parseResonanceMetricObservation(o);
|
|
1661
|
-
if (o.projectId !== r.projectId || o.campaignId !== r.campaignId || o.site !== c.site)
|
|
1662
|
-
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))
|
|
1935
|
+
if (o.projectId !== r.projectId || o.campaignId !== r.campaignId || o.site !== c.site) fail3(p + ".candidates.ownMeasurement", "foreign candidate measurement scope");
|
|
1936
|
+
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)) fail3(p + ".candidates.ownMeasurement", "outside the actual candidate evidence window");
|
|
1663
1937
|
const aggregate = o.source === "provider" && RESONANCE_PROVIDER_METRIC_NAMES.includes(o.name);
|
|
1664
|
-
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)
|
|
1938
|
+
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) fail3(p + ".candidates.ownMeasurement", "preserve actual provider aggregate versus first-party cohort provenance");
|
|
1665
1939
|
}
|
|
1666
1940
|
}
|
|
1667
1941
|
return r;
|
|
1668
1942
|
}
|
|
1669
1943
|
function checkOptimizationEvidencePlan(e, plan) {
|
|
1670
1944
|
const p = "optimizationEvidence";
|
|
1671
|
-
if (e.projectId !== plan.projectId || e.campaignId !== plan.campaignId || e.preparedPlanId !== plan.id || e.reviewDigest !== plan.reviewDigest || canonical(e.objective) !== canonical(plan.definition.objective) || canonical(e.resolvedPolicy) !== canonical(plan.resolvedEvidencePolicy))
|
|
1945
|
+
if (e.projectId !== plan.projectId || e.campaignId !== plan.campaignId || e.preparedPlanId !== plan.id || e.reviewDigest !== plan.reviewDigest || canonical(e.objective) !== canonical(plan.definition.objective) || canonical(e.resolvedPolicy) !== canonical(plan.resolvedEvidencePolicy)) fail3(p + ".preparedPlanId", "requires the exact original prepared scope and policy");
|
|
1672
1946
|
if (!("evidenceKind" in e)) return;
|
|
1673
1947
|
if (e.evidenceKind === "reported_cpql_sql_clock_v1") {
|
|
1674
1948
|
const cohort = plan.resolvedQualificationRule?.cohort;
|
|
1675
|
-
if (!cohort || Date.parse(e.windowStart) < Date.parse(cohort.startAt) || Date.parse(e.windowEnd) > Date.parse(cohort.endAt))
|
|
1949
|
+
if (!cohort || Date.parse(e.windowStart) < Date.parse(cohort.startAt) || Date.parse(e.windowEnd) > Date.parse(cohort.endAt)) fail3(p + ".window", "outside the original frozen qualification cohort");
|
|
1676
1950
|
for (const c of e.channels) {
|
|
1677
1951
|
const original = plan.definition.channels.find((x) => x.id === c.channelId), account = plan.accounts.find((x) => x.id === c.accountBindingId);
|
|
1678
|
-
if (!original || !("provider" in original) || original.site !== c.site || original.accountBindingId !== c.accountBindingId || !account || c.observations.some((o) => o.timeZone !== account.timeZone))
|
|
1952
|
+
if (!original || !("provider" in original) || original.site !== c.site || original.accountBindingId !== c.accountBindingId || !account || c.observations.some((o) => o.timeZone !== account.timeZone)) fail3(p + ".channels", "reported evidence must retain original channel/account/site/timezone");
|
|
1679
1953
|
}
|
|
1680
1954
|
return;
|
|
1681
1955
|
}
|
|
1682
1956
|
for (const observed of e.candidates) {
|
|
1683
1957
|
const original = plan.definition.channels.find((c) => c.id === observed.channelId), preview2 = plan.channelPreviews.find((c) => c.channelId === observed.channelId);
|
|
1684
|
-
if (!original || original.kind !== "meta_retargeting" || !preview2 || observed.site !== original.site || observed.accountBindingId !== original.accountBindingId || canonical(observed.cap) !== canonical(original.allocation) || canonical(observed.manifestRef) !== canonical(preview2.manifestRef))
|
|
1685
|
-
if (canonical(observed.flight) !== canonical({ startAt: plan.definition.budget.startAt, endAt: plan.definition.budget.endAt, timeZone: plan.definition.budget.timeZone }))
|
|
1958
|
+
if (!original || original.kind !== "meta_retargeting" || !preview2 || observed.site !== original.site || observed.accountBindingId !== original.accountBindingId || canonical(observed.cap) !== canonical(original.allocation) || canonical(observed.manifestRef) !== canonical(preview2.manifestRef)) fail3(p + ".candidates", "candidate projection differs from original channel and manifest");
|
|
1959
|
+
if (canonical(observed.flight) !== canonical({ startAt: plan.definition.budget.startAt, endAt: plan.definition.budget.endAt, timeZone: plan.definition.budget.timeZone })) fail3(p + ".candidates.flight", "must retain the original budget flight");
|
|
1686
1960
|
}
|
|
1687
1961
|
}
|
|
1688
1962
|
var matureOptimizationDecision = object2({
|
|
@@ -1701,9 +1975,9 @@ var matureOptimizationDecision = object2({
|
|
|
1701
1975
|
state: choice2("actionable", "noop", "blocked"),
|
|
1702
1976
|
decisionKind: choice2("observational_allocation", "experimental_promotion"),
|
|
1703
1977
|
executionOrder: literal2("reduce_then_increase"),
|
|
1704
|
-
reasonCodes: list2(
|
|
1705
|
-
adjustments: list2(object2({ channelId: uuid, site, budgetMode: choice2("campaign_total", "average_daily", "lifetime", "daily"), providerUnitExponent:
|
|
1706
|
-
if (![0, 2, 3, 6].includes(v))
|
|
1978
|
+
reasonCodes: list2(text3(80), 50),
|
|
1979
|
+
adjustments: list2(object2({ channelId: uuid, site, budgetMode: choice2("campaign_total", "average_daily", "lifetime", "daily"), providerUnitExponent: refine3(integer2(0, 6), (v, p) => {
|
|
1980
|
+
if (![0, 2, 3, 6].includes(v)) fail3(p, "unsupported provider exponent");
|
|
1707
1981
|
}), providerMaxUnits: decimal, before: money, after: money, remoteSnapshotDigest: digest }), 100),
|
|
1708
1982
|
createdAt: instant
|
|
1709
1983
|
});
|
|
@@ -1728,7 +2002,7 @@ var finiteDecisionFields = {
|
|
|
1728
2002
|
algorithmRevision: literal2("finite_meta_candidates_v1"),
|
|
1729
2003
|
sourceRefs: list2(revision, 200),
|
|
1730
2004
|
decisionKind: literal2("preapproved_candidate_operation"),
|
|
1731
|
-
reasonCodes: list2(
|
|
2005
|
+
reasonCodes: list2(text3(80), 50, 1)
|
|
1732
2006
|
};
|
|
1733
2007
|
var finiteOptimizationDecision = union2(
|
|
1734
2008
|
object2({ ...finiteDecisionFields, state: literal2("actionable"), candidateActions: list2(finiteCandidateActionBody, 1, 1) }),
|
|
@@ -1737,77 +2011,77 @@ var finiteOptimizationDecision = union2(
|
|
|
1737
2011
|
var optimizationDecision = union2(matureOptimizationDecision, finiteOptimizationDecision);
|
|
1738
2012
|
function parseResonanceOptimizationDecision(v, evidence, preparedPlan) {
|
|
1739
2013
|
const r = optimizationDecision.read(v, "optimizationDecision");
|
|
1740
|
-
if (Date.parse(r.expiresAt) <= Date.parse(r.createdAt))
|
|
1741
|
-
if (preparedPlan !== void 0 && evidence === void 0)
|
|
2014
|
+
if (Date.parse(r.expiresAt) <= Date.parse(r.createdAt)) fail3("optimizationDecision.expiresAt", "must follow decision");
|
|
2015
|
+
if (preparedPlan !== void 0 && evidence === void 0) fail3("optimizationDecision.evidenceRef", "plan binding requires actual evidence");
|
|
1742
2016
|
if (evidence !== void 0) checkOptimizationDecisionEvidence(r, parseResonanceOptimizationEvidence(evidence, preparedPlan));
|
|
1743
2017
|
if (r.decisionKind === "preapproved_candidate_operation") return r;
|
|
1744
2018
|
unique(r.adjustments.map((c) => c.channelId), "optimizationDecision.adjustments");
|
|
1745
2019
|
scoped(r, r.projectId, r.adjustments.map((c) => c.site), "optimizationDecision");
|
|
1746
|
-
if (r.state !== "actionable" && r.adjustments.length)
|
|
1747
|
-
if (r.state === "actionable" && !r.adjustments.length)
|
|
2020
|
+
if (r.state !== "actionable" && r.adjustments.length) fail3("optimizationDecision.adjustments", "no effects for blocked/noop decision");
|
|
2021
|
+
if (r.state === "actionable" && !r.adjustments.length) fail3("optimizationDecision.adjustments", "action requires exact adjustments");
|
|
1748
2022
|
for (const a of r.adjustments) {
|
|
1749
2023
|
compareMoney(a.before, a.after);
|
|
1750
2024
|
moneyToProviderUnits(a.before, { currency: a.before.currency, unitExponent: a.providerUnitExponent, maxUnits: a.providerMaxUnits });
|
|
1751
2025
|
moneyToProviderUnits(a.after, { currency: a.after.currency, unitExponent: a.providerUnitExponent, maxUnits: a.providerMaxUnits });
|
|
1752
|
-
if (r.adjustments[0].before.currency !== a.before.currency)
|
|
2026
|
+
if (r.adjustments[0].before.currency !== a.before.currency) fail3("optimizationDecision.adjustments", "currency mismatch");
|
|
1753
2027
|
}
|
|
1754
2028
|
return r;
|
|
1755
2029
|
}
|
|
1756
2030
|
function checkOptimizationDecisionEvidence(d, e) {
|
|
1757
2031
|
const p = "optimizationDecision";
|
|
1758
|
-
if (d.projectId !== e.projectId || d.campaignId !== e.campaignId || d.preparedPlanId !== e.preparedPlanId || d.reviewDigest !== e.reviewDigest || d.policyDigest !== e.policyDigest || canonical(d.evidenceRef) !== canonical({ id: e.id, revision: e.revision, evidenceDigest: e.evidenceDigest }))
|
|
1759
|
-
if (Date.parse(d.createdAt) < Date.parse(e.observedAt))
|
|
2032
|
+
if (d.projectId !== e.projectId || d.campaignId !== e.campaignId || d.preparedPlanId !== e.preparedPlanId || d.reviewDigest !== e.reviewDigest || d.policyDigest !== e.policyDigest || canonical(d.evidenceRef) !== canonical({ id: e.id, revision: e.revision, evidenceDigest: e.evidenceDigest })) fail3(p + ".evidenceRef", "must bind the exact original evidence and review");
|
|
2033
|
+
if (Date.parse(d.createdAt) < Date.parse(e.observedAt)) fail3(p + ".createdAt", "precedes actual evidence");
|
|
1760
2034
|
if (d.decisionKind !== "preapproved_candidate_operation") {
|
|
1761
|
-
if ("evidenceKind" in e && e.evidenceKind !== "reported_cpql_sql_clock_v1")
|
|
1762
|
-
if ("evidenceKind" in e && e.evidenceKind === "reported_cpql_sql_clock_v1" ? d.algorithmRevision !== e.resolvedPolicy.algorithm || d.decisionKind !== "observational_allocation" : d.algorithmRevision === "reported_cpql_conserved_transfer_v1")
|
|
2035
|
+
if ("evidenceKind" in e && e.evidenceKind !== "reported_cpql_sql_clock_v1") fail3(p + ".decisionKind", "mature decisions cannot borrow finite lifecycle evidence");
|
|
2036
|
+
if ("evidenceKind" in e && e.evidenceKind === "reported_cpql_sql_clock_v1" ? d.algorithmRevision !== e.resolvedPolicy.algorithm || d.decisionKind !== "observational_allocation" : d.algorithmRevision === "reported_cpql_conserved_transfer_v1") fail3(p + ".algorithmRevision", "reported-cost decisions require the exact reported evidence policy");
|
|
1763
2037
|
if ("evidenceKind" in e && e.evidenceKind === "reported_cpql_sql_clock_v1") {
|
|
1764
2038
|
const deadline = Math.min(Date.parse(e.observedAt), ...e.channels.flatMap((c) => [Date.parse(c.channelReportedCost.readClock.notBeforeAt), Date.parse(c.channelReportedCost.recordedAt)])) + e.resolvedPolicy.maxEvidenceAgeSeconds * 1e3;
|
|
1765
|
-
if (Date.parse(d.createdAt) > deadline || Date.parse(d.expiresAt) > deadline)
|
|
2039
|
+
if (Date.parse(d.createdAt) > deadline || Date.parse(d.expiresAt) > deadline) fail3(p + ".expiresAt", "outside original HTTP/database evidence freshness");
|
|
1766
2040
|
const refs = e.channels.flatMap((c) => [c.channelReportedCost.observationId, c.outcomeSource.sourceRevision]);
|
|
1767
|
-
if (refs.some((ref) => !d.sourceRefs.includes(ref)))
|
|
2041
|
+
if (refs.some((ref) => !d.sourceRefs.includes(ref))) fail3(p + ".sourceRefs", "requires immutable reported-cost and independent outcome sources");
|
|
1768
2042
|
}
|
|
1769
|
-
if (d.algorithmRevision === "finite_meta_candidates_v1")
|
|
2043
|
+
if (d.algorithmRevision === "finite_meta_candidates_v1") fail3(p + ".algorithmRevision", "mature decisions cannot use the finite algorithm");
|
|
1770
2044
|
return;
|
|
1771
2045
|
}
|
|
1772
|
-
if (!("evidenceKind" in e) || e.evidenceKind !== "finite_candidate_lifecycle_v1")
|
|
2046
|
+
if (!("evidenceKind" in e) || e.evidenceKind !== "finite_candidate_lifecycle_v1") fail3(p + ".decisionKind", "finite actions require finite lifecycle evidence");
|
|
1773
2047
|
const finite = e, policy = finite.resolvedPolicy;
|
|
1774
|
-
if (Date.parse(d.createdAt) - Date.parse(finite.observedAt) > policy.measurementGuard.maxEvidenceAgeSeconds * 1e3 || Date.parse(d.expiresAt) > Date.parse(policy.expiresAt))
|
|
2048
|
+
if (Date.parse(d.createdAt) - Date.parse(finite.observedAt) > policy.measurementGuard.maxEvidenceAgeSeconds * 1e3 || Date.parse(d.expiresAt) > Date.parse(policy.expiresAt)) fail3(p + ".expiresAt", "outside current policy/evidence freshness");
|
|
1775
2049
|
for (const a of d.candidateActions) {
|
|
1776
|
-
const c = finite.candidates.find((c2) => c2.channelId === a.channelId) ??
|
|
1777
|
-
if (!policy.allowedActions.includes(a.action) || c.graphDigest !== a.graphDigest || c.nativeStateEvidenceRef === null || canonical(c.nativeStateEvidenceRef) !== canonical(a.nativeStateEvidenceRef))
|
|
1778
|
-
if (c.lifecycle === "unknown")
|
|
2050
|
+
const c = finite.candidates.find((c2) => c2.channelId === a.channelId) ?? fail3(p + ".candidateActions", "unknown original candidate");
|
|
2051
|
+
if (!policy.allowedActions.includes(a.action) || c.graphDigest !== a.graphDigest || c.nativeStateEvidenceRef === null || canonical(c.nativeStateEvidenceRef) !== canonical(a.nativeStateEvidenceRef)) fail3(p + ".candidateActions", "outside original candidate action/state evidence");
|
|
2052
|
+
if (c.lifecycle === "unknown") fail3(p + ".candidateActions", "unknown state requires reconciliation");
|
|
1779
2053
|
if (a.action === "pause_candidate") {
|
|
1780
|
-
if (c.lifecycle !== "active")
|
|
2054
|
+
if (c.lifecycle !== "active") fail3(p + ".candidateActions", "pause requires the actual active original candidate");
|
|
1781
2055
|
continue;
|
|
1782
2056
|
}
|
|
1783
|
-
if (finite.inventoryState !== "complete" || finite.candidates.some((c2) => c2.lifecycle === "unknown") || c.activationsObserved !== 0 || finite.candidates.filter((c2) => c2.lifecycle === "active").length >= policy.maxConcurrentCandidates)
|
|
2057
|
+
if (finite.inventoryState !== "complete" || finite.candidates.some((c2) => c2.lifecycle === "unknown") || c.activationsObserved !== 0 || finite.candidates.filter((c2) => c2.lifecycle === "active").length >= policy.maxConcurrentCandidates) fail3(p + ".candidateActions", "unknown inventory, prior activation or concurrency blocks activation");
|
|
1784
2058
|
const firstEligible = policy.selection.candidateOrder.find((id) => {
|
|
1785
2059
|
const candidate = finite.candidates.find((c2) => c2.channelId === id), window = policy.selection.eligibilitySchedule.find((s) => s.channelId === id);
|
|
1786
2060
|
const permittedLifecycle = candidate.lifecycle === "not_materialized" && policy.allowedActions.includes("materialize_and_activate") && candidate.nativeStateEvidenceRef !== null || candidate.lifecycle === "paused" && policy.allowedActions.includes("activate_held") && candidate.commitmentEvidenceRef !== null && candidate.nativeStateEvidenceRef !== null;
|
|
1787
2061
|
return permittedLifecycle && candidate.activationsObserved === 0 && Date.parse(d.createdAt) >= Date.parse(window.notBefore) && Date.parse(d.createdAt) < Date.parse(window.notAfter);
|
|
1788
2062
|
});
|
|
1789
|
-
if (firstEligible !== c.channelId)
|
|
2063
|
+
if (firstEligible !== c.channelId) fail3(p + ".candidateActions", "must retain the original fixed candidate order");
|
|
1790
2064
|
const schedule = policy.selection.eligibilitySchedule.find((s) => s.channelId === c.channelId);
|
|
1791
|
-
if (Date.parse(d.createdAt) < Date.parse(schedule.notBefore) || Date.parse(d.createdAt) >= Date.parse(schedule.notAfter))
|
|
1792
|
-
if (a.action === "materialize_and_activate" && (c.lifecycle !== "not_materialized" || c.commitmentEvidenceRef !== null))
|
|
1793
|
-
if (a.action === "activate_held" && (c.lifecycle !== "paused" || !c.commitmentEvidenceRef || c.commitmentEvidenceRef.commitmentOperationId !== a.commitmentOperationId))
|
|
1794
|
-
if (compareMoney(c.cap, policy.totalExplorationCap) > 0)
|
|
1795
|
-
if (finite.trackingState !== "healthy" || c.trackingState !== "healthy" || c.coverageBasisPoints === null || c.coverageBasisPoints < policy.measurementGuard.minimumCoverageBasisPoints)
|
|
2065
|
+
if (Date.parse(d.createdAt) < Date.parse(schedule.notBefore) || Date.parse(d.createdAt) >= Date.parse(schedule.notAfter)) fail3(p + ".candidateActions", "outside original selection window");
|
|
2066
|
+
if (a.action === "materialize_and_activate" && (c.lifecycle !== "not_materialized" || c.commitmentEvidenceRef !== null)) fail3(p + ".candidateActions", "new create requires original absence, not a borrowed hold");
|
|
2067
|
+
if (a.action === "activate_held" && (c.lifecycle !== "paused" || !c.commitmentEvidenceRef || c.commitmentEvidenceRef.commitmentOperationId !== a.commitmentOperationId)) fail3(p + ".candidateActions", "held activation requires the exact original commitment reference");
|
|
2068
|
+
if (compareMoney(c.cap, policy.totalExplorationCap) > 0) fail3(p + ".candidateActions", "original full cap exceeds reviewed exploration ceiling");
|
|
2069
|
+
if (finite.trackingState !== "healthy" || c.trackingState !== "healthy" || c.coverageBasisPoints === null || c.coverageBasisPoints < policy.measurementGuard.minimumCoverageBasisPoints) fail3(p + ".candidateActions", "current required tracking coverage unavailable");
|
|
1796
2070
|
for (const check of policy.measurementGuard.requiredChecks) {
|
|
1797
|
-
if (check === "dedupe" && c.dedupeCheck !== "pass" || check === "qualification" && c.qualificationCheck !== "pass")
|
|
1798
|
-
if (["uncertainty", "assignment", "power"].includes(check))
|
|
2071
|
+
if (check === "dedupe" && c.dedupeCheck !== "pass" || check === "qualification" && c.qualificationCheck !== "pass") fail3(p + ".candidateActions", "required source check unavailable");
|
|
2072
|
+
if (["uncertainty", "assignment", "power"].includes(check)) fail3(p + ".candidateActions", "fixed exploration has no adopted measured/assignment decision policy");
|
|
1799
2073
|
}
|
|
1800
2074
|
}
|
|
1801
2075
|
}
|
|
1802
2076
|
var RESONANCE_OPTIMIZATION_EVIDENCE_JSON_SCHEMA = optimizationEvidence.schema;
|
|
1803
2077
|
var RESONANCE_OPTIMIZATION_DECISION_JSON_SCHEMA = optimizationDecision.schema;
|
|
1804
|
-
var metaBrowserWitness = object2({ controlsRevision:
|
|
2078
|
+
var metaBrowserWitness = object2({ controlsRevision: text3(60, /^[A-Z][A-Z0-9_]*$/), policyRevision: revision, witnessId: uuid, assertedAt: instant });
|
|
1805
2079
|
var publicDestination = union2(
|
|
1806
|
-
object2({ provider: literal2("google_ads"), id: uuid, tagId:
|
|
2080
|
+
object2({ provider: literal2("google_ads"), id: uuid, tagId: text3(40, /^AW-[0-9]+$/) }),
|
|
1807
2081
|
// browserWitness and tagManagerAttested are optional so configurations from before the Meta loader keep parsing; absent means no Meta browser loading.
|
|
1808
|
-
object2({ provider: literal2("meta_ads"), id: uuid, pixelId:
|
|
2082
|
+
object2({ provider: literal2("meta_ads"), id: uuid, pixelId: text3(40, /^[0-9]+$/), browserWitness: optional2(metaBrowserWitness), tagManagerAttested: optional2(bool) })
|
|
1809
2083
|
);
|
|
1810
|
-
var interestResource = object2({ ...scope, type: choice2("page", "article", "product", "listing"), id:
|
|
2084
|
+
var interestResource = object2({ ...scope, type: choice2("page", "article", "product", "listing"), id: text3(160, /^[a-zA-Z0-9._:-]+$/), revision });
|
|
1811
2085
|
var measurementConfig = object2({
|
|
1812
2086
|
schemaVersion: literal2(1),
|
|
1813
2087
|
...scope,
|
|
@@ -1818,7 +2092,7 @@ var measurementConfig = object2({
|
|
|
1818
2092
|
consentPolicy: object2({ mode: literal2("basic"), requiredPurposes: list2(purpose, 4, 1) }),
|
|
1819
2093
|
destinations: list2(publicDestination, 10),
|
|
1820
2094
|
// metaEligible is set by a person with owner or admin standing; absent means false. The browser never decides it.
|
|
1821
|
-
resourceRules: list2(object2({ id: uuid, revision, site, resource: interestResource, path, interestKey:
|
|
2095
|
+
resourceRules: list2(object2({ id: uuid, revision, site, resource: interestResource, path, interestKey: text3(100, /^[a-zA-Z0-9._:-]+$/), metaEligible: optional2(bool) }), 500)
|
|
1822
2096
|
});
|
|
1823
2097
|
function parseResonanceMeasurementConfig(v) {
|
|
1824
2098
|
const r = measurementConfig.read(v, "measurementConfig");
|
|
@@ -1826,7 +2100,7 @@ function parseResonanceMeasurementConfig(v) {
|
|
|
1826
2100
|
unique(r.destinations.map((d) => d.id), "measurementConfig.destinations");
|
|
1827
2101
|
unique(r.consentPolicy.requiredPurposes, "measurementConfig.consentPolicy.requiredPurposes");
|
|
1828
2102
|
unique(r.resourceRules.map((rule) => rule.id), "measurementConfig.resourceRules");
|
|
1829
|
-
if (r.destinations.length && ["ad_storage", "ad_user_data", "ad_personalization"].some((p) => !r.consentPolicy.requiredPurposes.includes(p)))
|
|
2103
|
+
if (r.destinations.length && ["ad_storage", "ad_user_data", "ad_personalization"].some((p) => !r.consentPolicy.requiredPurposes.includes(p))) fail3("measurementConfig.consentPolicy", "provider minimum purposes are mandatory");
|
|
1830
2104
|
return r;
|
|
1831
2105
|
}
|
|
1832
2106
|
function resonanceMeasurementConfigDigestInput(value) {
|
|
@@ -1834,7 +2108,7 @@ function resonanceMeasurementConfigDigestInput(value) {
|
|
|
1834
2108
|
return canonical(semantic);
|
|
1835
2109
|
}
|
|
1836
2110
|
var clickIdentifierPattern = /^[^\s\u0000-\u001f\u007f-\u009f]+(?![\s\S])/;
|
|
1837
|
-
var clickIdentifier = field2({ type: "string", minLength: 1, maxLength: 1024, pattern: clickIdentifierPattern.source }, (v, p) => typeof v === "string" && v.length <= 2048 && [...v].length <= 1024 && clickIdentifierPattern.test(v) ? v :
|
|
2111
|
+
var clickIdentifier = field2({ type: "string", minLength: 1, maxLength: 1024, pattern: clickIdentifierPattern.source }, (v, p) => typeof v === "string" && v.length <= 2048 && [...v].length <= 1024 && clickIdentifierPattern.test(v) ? v : fail3(p, "invalid click identifier"));
|
|
1838
2112
|
var clickIdentifiersShape = union2(object2({ gclid: clickIdentifier }), object2({ gbraid: clickIdentifier }), object2({ wbraid: clickIdentifier }));
|
|
1839
2113
|
var clickIdentifiers = field2(clickIdentifiersShape.schema, clickIdentifiersShape.read);
|
|
1840
2114
|
var parseResonanceClickIdentifiers = (v) => clickIdentifiers.read(v, "clickIdentifiers");
|
|
@@ -1842,13 +2116,13 @@ var RESONANCE_CLICK_IDENTIFIERS_JSON_SCHEMA = clickIdentifiers.schema;
|
|
|
1842
2116
|
var observedPathControl = /[\s\u0000-\u001f\u007f-\u009f]/;
|
|
1843
2117
|
var observedPagePath = field2({ ...path.schema, allOf: [{ not: { pattern: observedPathControl.source } }] }, (v, p) => {
|
|
1844
2118
|
const result = path.read(v, p);
|
|
1845
|
-
if (observedPathControl.test(result))
|
|
2119
|
+
if (observedPathControl.test(result)) fail3(p, "invalid observed path");
|
|
1846
2120
|
return result;
|
|
1847
2121
|
});
|
|
1848
2122
|
var metaCookieShape = object2({ source: literal2(RESONANCE_WEBSITE_VISIT_PROFILE.source), fbp: optional2(clickIdentifier), fbc: optional2(clickIdentifier) });
|
|
1849
2123
|
var metaCookieObservation = field2({ ...metaCookieShape.schema, anyOf: [{ required: ["fbp"] }, { required: ["fbc"] }] }, (v, p) => {
|
|
1850
2124
|
const result = metaCookieShape.read(v, p);
|
|
1851
|
-
if (!result.fbp && !result.fbc)
|
|
2125
|
+
if (!result.fbp && !result.fbc) fail3(p, "requires an actual reported cookie value");
|
|
1852
2126
|
return result;
|
|
1853
2127
|
});
|
|
1854
2128
|
var occurrenceShape = object2({
|
|
@@ -1874,17 +2148,17 @@ var occurrence = field2({ ...occurrenceShape.schema, allOf: [
|
|
|
1874
2148
|
{ if: { required: ["metaCookieObservation"] }, then: { required: ["pagePath"], properties: { kind: { const: "page_view" }, resourceRef: interestResource.schema } } }
|
|
1875
2149
|
] }, (v, p) => {
|
|
1876
2150
|
const r = occurrenceShape.read(v, p);
|
|
1877
|
-
if (r.clickIdentifiers && r.kind !== "page_view")
|
|
1878
|
-
if (r.pagePath !== void 0 && r.kind !== "page_view" && r.kind !== "experiment_exposure")
|
|
1879
|
-
if (r.metaCookieObservation && (r.kind !== "page_view" || r.pagePath === void 0 || !r.resourceRef))
|
|
2151
|
+
if (r.clickIdentifiers && r.kind !== "page_view") fail3(p + ".clickIdentifiers", "requires page_view");
|
|
2152
|
+
if (r.pagePath !== void 0 && r.kind !== "page_view" && r.kind !== "experiment_exposure") fail3(p + ".pagePath", "requires page_view or experiment_exposure");
|
|
2153
|
+
if (r.metaCookieObservation && (r.kind !== "page_view" || r.pagePath === void 0 || !r.resourceRef)) fail3(p + ".metaCookieObservation", "requires the same page_view path and resource");
|
|
1880
2154
|
return r;
|
|
1881
2155
|
});
|
|
1882
2156
|
function parseResonanceMeasurementOccurrence(v) {
|
|
1883
2157
|
const r = occurrence.read(v, "occurrence");
|
|
1884
2158
|
scoped(r, r.projectId, [r.site], "occurrence");
|
|
1885
2159
|
unique(r.consentReceiptRefs.map((c) => c.purpose), "occurrence.consentReceiptRefs");
|
|
1886
|
-
if (r.kind === "content_interest" && !r.resourceRef)
|
|
1887
|
-
if (r.kind === "experiment_exposure" && !r.experiment)
|
|
2160
|
+
if (r.kind === "content_interest" && !r.resourceRef) fail3("occurrence.resourceRef", "content interest requires resource");
|
|
2161
|
+
if (r.kind === "experiment_exposure" && !r.experiment) fail3("occurrence.experiment", "exposure requires assignment context");
|
|
1888
2162
|
return r;
|
|
1889
2163
|
}
|
|
1890
2164
|
var consentUpdate = object2({ schemaVersion: literal2(1), ...scope, configRevision: revision, policyRevision: revision, expectedConsentRevision: integer2(0), occurredAt: instant, idempotencyKey: operationKey, source: choice2("cmp", "user_preference"), purposes: list2(object2({ purpose, state: choice2("unknown", "granted", "denied", "withdrawn") }), 4, 1) });
|
|
@@ -1904,12 +2178,12 @@ function resonanceOptimizationDecisionDigestInput(v) {
|
|
|
1904
2178
|
const { requestDigest: _digest, ...body } = parseResonanceOptimizationDecision(v);
|
|
1905
2179
|
return canonical(body);
|
|
1906
2180
|
}
|
|
1907
|
-
var consentResult = object2({ subjectProof:
|
|
2181
|
+
var consentResult = object2({ subjectProof: text3(200, /^[a-zA-Z0-9_-]{32,}$/), expiresAt: instant, currentConsentRevision: integer2(1), receipts: list2(consent, 4, 4) });
|
|
1908
2182
|
function parseResonanceConsentResponse(v) {
|
|
1909
2183
|
const r = consentResult.read(v, "consentResponse"), first = r.receipts[0];
|
|
1910
|
-
if (r.receipts.some((c) => c.consentRevision !== r.currentConsentRevision))
|
|
2184
|
+
if (r.receipts.some((c) => c.consentRevision !== r.currentConsentRevision)) fail3("consentResponse.receipts", "global consent revision mismatch");
|
|
1911
2185
|
unique(r.receipts.map((c) => c.purpose), "consentResult.receipts");
|
|
1912
|
-
for (const c of r.receipts) if (c.projectId !== first.projectId || c.site !== first.site || c.configRevision !== first.configRevision || c.policyRevision !== first.policyRevision || c.visitorNamespace !== first.visitorNamespace)
|
|
2186
|
+
for (const c of r.receipts) if (c.projectId !== first.projectId || c.site !== first.site || c.configRevision !== first.configRevision || c.policyRevision !== first.policyRevision || c.visitorNamespace !== first.visitorNamespace) fail3("consentResult.receipts", "mixed consent subjects or scope");
|
|
1913
2187
|
return r;
|
|
1914
2188
|
}
|
|
1915
2189
|
var occurrenceResult = object2({ eventId: uuid, accepted: literal2(true), replayed: bool, exposureId: nullable2(uuid) });
|
|
@@ -1930,12 +2204,12 @@ var audienceDraft = object2({
|
|
|
1930
2204
|
schemaVersion: literal2(1),
|
|
1931
2205
|
expectedRevision: optional2(integer2(1)),
|
|
1932
2206
|
idempotencyKey: operationKey,
|
|
1933
|
-
definition: object2({ name:
|
|
2207
|
+
definition: object2({ name: text3(160), site, accountBindingId: uuid, resourceRuleId: uuid, excludedResourceRuleIds: list2(uuid, 50), retentionDays: integer2(1, 540), minDaysSinceVisit: optional2(integer2(1, 179)), policyRevision: revision, currentConsentPolicyRevision: revision })
|
|
1934
2208
|
});
|
|
1935
2209
|
function parseResonanceAudienceDraftSaveCommand(v) {
|
|
1936
2210
|
const r = audienceDraft.read(v, "audienceDraftSave");
|
|
1937
2211
|
unique(r.definition.excludedResourceRuleIds, "audienceDraftSave.definition.excludedResourceRuleIds");
|
|
1938
|
-
if (r.definition.minDaysSinceVisit !== void 0 && r.definition.minDaysSinceVisit >= r.definition.retentionDays)
|
|
2212
|
+
if (r.definition.minDaysSinceVisit !== void 0 && r.definition.minDaysSinceVisit >= r.definition.retentionDays) fail3("audienceDraftSave.definition.minDaysSinceVisit", "must be shorter than the retention window");
|
|
1939
2213
|
return r;
|
|
1940
2214
|
}
|
|
1941
2215
|
var RESONANCE_AUDIENCE_DRAFT_SAVE_COMMAND_JSON_SCHEMA = audienceDraft.schema;
|
|
@@ -1944,20 +2218,20 @@ var experimentCreateField = field2(SIGNAL_EXPERIMENT_CREATE_JSON_SCHEMA, (v, p)
|
|
|
1944
2218
|
try {
|
|
1945
2219
|
return parseSignalExperimentCreate(v);
|
|
1946
2220
|
} catch (error) {
|
|
1947
|
-
return
|
|
2221
|
+
return fail3(p, error instanceof Error ? error.message : "invalid experiment");
|
|
1948
2222
|
}
|
|
1949
2223
|
});
|
|
1950
2224
|
var experimentUpdateField = field2(SIGNAL_EXPERIMENT_UPDATE_JSON_SCHEMA, (v, p) => {
|
|
1951
2225
|
try {
|
|
1952
2226
|
return parseSignalExperimentUpdate(v);
|
|
1953
2227
|
} catch (error) {
|
|
1954
|
-
return
|
|
2228
|
+
return fail3(p, error instanceof Error ? error.message : "invalid experiment");
|
|
1955
2229
|
}
|
|
1956
2230
|
});
|
|
1957
2231
|
var managedExperimentCreate = object2({ ...managedExperimentBase, experiment: experimentCreateField });
|
|
1958
2232
|
var managedExperimentUpdate = object2({ ...managedExperimentBase, experiment: experimentUpdateField });
|
|
1959
2233
|
var managedExperimentLifecycle = object2(managedExperimentBase);
|
|
1960
|
-
var managedExperimentComplete = object2({ ...managedExperimentBase, winnerVariant:
|
|
2234
|
+
var managedExperimentComplete = object2({ ...managedExperimentBase, winnerVariant: text3(80) });
|
|
1961
2235
|
var managedExperimentLink = object2({ ...managedExperimentBase, experimentId: uuid });
|
|
1962
2236
|
var parseResonanceExperimentCreateCommand = (v) => managedExperimentCreate.read(v, "experimentCreateCommand");
|
|
1963
2237
|
var parseResonanceExperimentUpdateCommand = (v) => managedExperimentUpdate.read(v, "experimentUpdateCommand");
|
|
@@ -1971,18 +2245,18 @@ var RESONANCE_EXPERIMENT_COMPLETE_COMMAND_JSON_SCHEMA = managedExperimentComplet
|
|
|
1971
2245
|
var RESONANCE_EXPERIMENT_LINK_COMMAND_JSON_SCHEMA = managedExperimentLink.schema;
|
|
1972
2246
|
var nativePageRevision = field2({ ...instant.schema, pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z(?![\\s\\S])" }, (v, p) => {
|
|
1973
2247
|
const result = instant.read(v, p);
|
|
1974
|
-
if (new Date(result).toISOString() !== result)
|
|
2248
|
+
if (new Date(result).toISOString() !== result) fail3(p, "requires canonical UTC milliseconds");
|
|
1975
2249
|
return result;
|
|
1976
2250
|
});
|
|
1977
|
-
var positiveRevision =
|
|
1978
|
-
var friendlyName = field2({ type: "string", minLength: 0, maxLength: 200 }, (v, p) => typeof v === "string" && [...v].length <= 200 ? v :
|
|
2251
|
+
var positiveRevision = text3(128, /^[1-9][0-9]*(?![\s\S])/);
|
|
2252
|
+
var friendlyName = field2({ type: "string", minLength: 0, maxLength: 200 }, (v, p) => typeof v === "string" && [...v].length <= 200 ? v : fail3(p, "invalid friendly name"));
|
|
1979
2253
|
var setupConsentPolicyShape = object2({ mode: literal2("basic"), requiredPurposes: uniqueList(purpose, 4, 3) });
|
|
1980
2254
|
var setupConsentPolicy = field2({ ...setupConsentPolicyShape.schema, allOf: [{ properties: { requiredPurposes: { allOf: ["ad_storage", "ad_user_data", "ad_personalization"].map((value) => ({ contains: { const: value } })) } } }] }, (input, p) => {
|
|
1981
2255
|
const v = setupConsentPolicyShape.read(input, p);
|
|
1982
|
-
for (const required of ["ad_storage", "ad_user_data", "ad_personalization"]) if (!v.requiredPurposes.includes(required))
|
|
2256
|
+
for (const required of ["ad_storage", "ad_user_data", "ad_personalization"]) if (!v.requiredPurposes.includes(required)) fail3(p, "all advertising purpose requirements are mandatory");
|
|
1983
2257
|
return v;
|
|
1984
2258
|
});
|
|
1985
|
-
var measurementSave =
|
|
2259
|
+
var measurementSave = refine3(object2({
|
|
1986
2260
|
schemaVersion: literal2(1),
|
|
1987
2261
|
site,
|
|
1988
2262
|
expectedCampaignRevision: integer2(1),
|
|
@@ -1999,20 +2273,20 @@ var measurementSavedFields = { configurationRevision: integer2(1), configuration
|
|
|
1999
2273
|
object2(measurementSavedFields);
|
|
2000
2274
|
function checkMeasurementSaved(v, p) {
|
|
2001
2275
|
const config = parseResonanceMeasurementConfig(v.configuration);
|
|
2002
|
-
if (config.projectId !== v.projectId || config.site !== v.site)
|
|
2276
|
+
if (config.projectId !== v.projectId || config.site !== v.site) fail3(p + ".configuration", "configuration scope mismatch");
|
|
2003
2277
|
positiveRevision.read(config.configRevision, p + ".configuration.configRevision");
|
|
2004
2278
|
positiveRevision.read(config.policyRevision, p + ".configuration.policyRevision");
|
|
2005
2279
|
setupConsentPolicy.read(config.consentPolicy, p + ".configuration.consentPolicy");
|
|
2006
2280
|
unique(v.pages.map((page2) => page2.pageId), p + ".pages");
|
|
2007
|
-
if (v.pages.length !== config.resourceRules.length)
|
|
2281
|
+
if (v.pages.length !== config.resourceRules.length) fail3(p + ".pages", "must cover the exact native page rules");
|
|
2008
2282
|
for (const page2 of v.pages) {
|
|
2009
2283
|
const rule = config.resourceRules.find((rule2) => rule2.id === page2.resourceRuleId);
|
|
2010
|
-
if (page2.resourceRuleId !== page2.pageId || page2.resourceRuleRevision !== page2.evidenceDigest || !rule || rule.revision !== page2.evidenceDigest || rule.path !== page2.path || rule.interestKey !== page2.pageId || rule.resource.type !== "page" || rule.resource.id !== page2.pageId || rule.resource.revision !== page2.pageRevision)
|
|
2284
|
+
if (page2.resourceRuleId !== page2.pageId || page2.resourceRuleRevision !== page2.evidenceDigest || !rule || rule.revision !== page2.evidenceDigest || rule.path !== page2.path || rule.interestKey !== page2.pageId || rule.resource.type !== "page" || rule.resource.id !== page2.pageId || rule.resource.revision !== page2.pageRevision) fail3(p + ".pages", "native page/resource/rule version mismatch");
|
|
2011
2285
|
}
|
|
2012
2286
|
}
|
|
2013
|
-
var measurementCurrent =
|
|
2287
|
+
var measurementCurrent = refine3(union2(
|
|
2014
2288
|
object2({ schemaVersion: literal2(1), kind: literal2("unconfigured"), ...scope, configurationRevision: literal2(0) }),
|
|
2015
|
-
object2({ schemaVersion: literal2(1), kind: literal2("configured"), ...scope, ...measurementSavedFields, reasonCodes: uniqueList(
|
|
2289
|
+
object2({ schemaVersion: literal2(1), kind: literal2("configured"), ...scope, ...measurementSavedFields, reasonCodes: uniqueList(text3(200), 100) })
|
|
2016
2290
|
), (v, p) => {
|
|
2017
2291
|
if (v.kind === "configured") checkMeasurementSaved(v, p);
|
|
2018
2292
|
});
|
|
@@ -2021,8 +2295,8 @@ var measurementSnapshotShape = object2(measurementSnapshotFields);
|
|
|
2021
2295
|
function checkMeasurementSnapshot(v, p) {
|
|
2022
2296
|
checkMeasurementSaved({ ...v, saveOperationId: v.operationId }, p);
|
|
2023
2297
|
}
|
|
2024
|
-
var measurementSnapshot =
|
|
2025
|
-
var measurementSaveResponse =
|
|
2298
|
+
var measurementSnapshot = refine3(measurementSnapshotShape, checkMeasurementSnapshot);
|
|
2299
|
+
var measurementSaveResponse = refine3(object2({ ...measurementSnapshotFields, replayed: bool }), checkMeasurementSnapshot);
|
|
2026
2300
|
var parseResonanceMeasurementConfigurationCurrent = (v) => measurementCurrent.read(v, "measurementConfigurationCurrent");
|
|
2027
2301
|
var parseResonanceMeasurementConfigurationSnapshot = (v) => measurementSnapshot.read(v, "measurementConfigurationSnapshot");
|
|
2028
2302
|
var parseResonanceMeasurementConfigurationSaveResponse = (v) => measurementSaveResponse.read(v, "measurementConfigurationSaveResponse");
|
|
@@ -2030,9 +2304,9 @@ var measurementProjectionContext = object2({ projectId: uuid, current: measureme
|
|
|
2030
2304
|
function projectResonanceMeasurementConfiguration(value, context) {
|
|
2031
2305
|
const command2 = parseResonanceMeasurementConfigurationSaveCommand(value), actual = measurementProjectionContext.read(context, "measurementConfigurationProjection");
|
|
2032
2306
|
const current = parseResonanceMeasurementConfigurationCurrent(actual.current);
|
|
2033
|
-
if (current.projectId !== actual.projectId || current.site !== command2.site || current.configurationRevision !== command2.expectedConfigurationRevision)
|
|
2307
|
+
if (current.projectId !== actual.projectId || current.site !== command2.site || current.configurationRevision !== command2.expectedConfigurationRevision) fail3("measurementConfigurationProjection.current", "scope or configuration CAS mismatch");
|
|
2034
2308
|
unique(actual.pages.map((page2) => page2.pageId), "measurementConfigurationProjection.pages");
|
|
2035
|
-
if (actual.pages.length !== command2.pages.length || actual.pages.some((page2) => !command2.pages.some((selected) => selected.pageId === page2.pageId && selected.observedRevision === page2.pageRevision && selected.observedDigest === page2.evidenceDigest)))
|
|
2309
|
+
if (actual.pages.length !== command2.pages.length || actual.pages.some((page2) => !command2.pages.some((selected) => selected.pageId === page2.pageId && selected.observedRevision === page2.pageRevision && selected.observedDigest === page2.evidenceDigest))) fail3("measurementConfigurationProjection.pages", "requires the exact selected current native page evidence");
|
|
2036
2310
|
const pages = [...actual.pages].sort((a, b) => a.pageId < b.pageId ? -1 : a.pageId > b.pageId ? 1 : 0).map((page2) => ({ ...page2, resourceRuleId: page2.pageId, resourceRuleRevision: page2.evidenceDigest }));
|
|
2037
2311
|
const consentPolicy = { ...command2.consentPolicy, requiredPurposes: [...command2.consentPolicy.requiredPurposes].sort() };
|
|
2038
2312
|
const previous = current.kind === "configured" ? current.configuration : null;
|
|
@@ -2061,10 +2335,10 @@ var RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA = measurementSa
|
|
|
2061
2335
|
var RESONANCE_MEASUREMENT_CONFIGURATION_CURRENT_JSON_SCHEMA = measurementCurrent.schema;
|
|
2062
2336
|
var RESONANCE_MEASUREMENT_CONFIGURATION_SNAPSHOT_JSON_SCHEMA = measurementSnapshot.schema;
|
|
2063
2337
|
var RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA = measurementSaveResponse.schema;
|
|
2064
|
-
var nativeAudienceId =
|
|
2338
|
+
var nativeAudienceId = text3(160, /^[0-9]+(?![\s\S])/);
|
|
2065
2339
|
var RESONANCE_META_DATASET_NAME_MAX_LENGTH = 160;
|
|
2066
|
-
var metaDatasetName =
|
|
2067
|
-
if (!value.trim() || value !== value.trim() || /[\x00-\x1f\x7f]/.test(value))
|
|
2340
|
+
var metaDatasetName = refine3(text3(RESONANCE_META_DATASET_NAME_MAX_LENGTH), (value, at) => {
|
|
2341
|
+
if (!value.trim() || value !== value.trim() || /[\x00-\x1f\x7f]/.test(value)) fail3(at, "requires a trimmed dataset name without control characters");
|
|
2068
2342
|
});
|
|
2069
2343
|
var parseResonanceMetaDatasetName = (value) => metaDatasetName.read(value, "metaDatasetName");
|
|
2070
2344
|
var metaDatasetExistingSelection = object2({ kind: literal2("existing"), externalId: nativeAudienceId });
|
|
@@ -2110,7 +2384,7 @@ var RESONANCE_META_DATASET_SETUP_REVIEW_JSON_SCHEMA = metaDatasetSetupReview.sch
|
|
|
2110
2384
|
var metaDatasetSetupFirstOutcome = object2({
|
|
2111
2385
|
admission: choice2("accepted", "rejected", "unknown"),
|
|
2112
2386
|
externalId: nullable2(nativeAudienceId),
|
|
2113
|
-
providerRequestId: nullable2(
|
|
2387
|
+
providerRequestId: nullable2(text3(200)),
|
|
2114
2388
|
providerRequestDigest: digest
|
|
2115
2389
|
});
|
|
2116
2390
|
var metaSetupVerificationFields = {
|
|
@@ -2131,39 +2405,39 @@ var metaSetupReceiptFields = {
|
|
|
2131
2405
|
requestDigest: digest,
|
|
2132
2406
|
status: choice2("pending", "selected", "created_unverified", "verified", "rejected", "uncertain", "cancelled"),
|
|
2133
2407
|
firstOutcome: nullable2(metaDatasetSetupFirstOutcome),
|
|
2134
|
-
reasonCodes: uniqueList(
|
|
2408
|
+
reasonCodes: uniqueList(text3(80, /^[a-z][a-z0-9_]*$/), 30)
|
|
2135
2409
|
};
|
|
2136
2410
|
function checkMetaSetupReceipt(value, at, resource2) {
|
|
2137
2411
|
const { status, firstOutcome, currentVerification } = value;
|
|
2138
2412
|
if (firstOutcome && firstOutcome.admission === "accepted" !== (firstOutcome.externalId !== null)) {
|
|
2139
|
-
|
|
2413
|
+
fail3(at + ".firstOutcome", "requires the original provider ID exactly when creation was accepted");
|
|
2140
2414
|
}
|
|
2141
2415
|
switch (status) {
|
|
2142
2416
|
case "pending":
|
|
2143
2417
|
case "cancelled":
|
|
2144
|
-
if (firstOutcome || currentVerification)
|
|
2418
|
+
if (firstOutcome || currentVerification) fail3(at, "cannot carry a creation outcome or verification");
|
|
2145
2419
|
break;
|
|
2146
2420
|
case "selected":
|
|
2147
|
-
if (firstOutcome || !currentVerification)
|
|
2421
|
+
if (firstOutcome || !currentVerification) fail3(at, "requires verified existing selection without a creation outcome");
|
|
2148
2422
|
break;
|
|
2149
2423
|
case "created_unverified":
|
|
2150
|
-
if (firstOutcome?.admission !== "accepted" || currentVerification)
|
|
2424
|
+
if (firstOutcome?.admission !== "accepted" || currentVerification) fail3(at, "requires accepted creation and no verified readback");
|
|
2151
2425
|
break;
|
|
2152
2426
|
case "verified":
|
|
2153
2427
|
if (firstOutcome?.admission !== "accepted" || !currentVerification || firstOutcome.externalId !== currentVerification.externalId) {
|
|
2154
|
-
|
|
2428
|
+
fail3(at, `requires verified readback of the exact created ${resource2}`);
|
|
2155
2429
|
}
|
|
2156
2430
|
break;
|
|
2157
2431
|
case "rejected":
|
|
2158
|
-
if (firstOutcome?.admission !== "rejected")
|
|
2432
|
+
if (firstOutcome?.admission !== "rejected") fail3(at, "requires the original rejection");
|
|
2159
2433
|
break;
|
|
2160
2434
|
case "uncertain":
|
|
2161
|
-
if (firstOutcome?.admission !== "unknown" || currentVerification)
|
|
2435
|
+
if (firstOutcome?.admission !== "unknown" || currentVerification) fail3(at, `requires an unknown outcome without an attributable ${resource2}`);
|
|
2162
2436
|
break;
|
|
2163
2437
|
}
|
|
2164
2438
|
}
|
|
2165
2439
|
var metaSetupReceiptState = object2({ ...metaSetupReceiptFields, currentVerification: nullable2(metaDatasetSetupVerification) });
|
|
2166
|
-
var metaDatasetSetupReceipt =
|
|
2440
|
+
var metaDatasetSetupReceipt = refine3(metaSetupReceiptState, (value, at) => checkMetaSetupReceipt(value, at, "dataset"));
|
|
2167
2441
|
var parseResonanceMetaDatasetSetupReceipt = (value) => metaDatasetSetupReceipt.read(value, "metaDatasetSetupReceipt");
|
|
2168
2442
|
var RESONANCE_META_DATASET_SETUP_RECEIPT_JSON_SCHEMA = metaDatasetSetupReceipt.schema;
|
|
2169
2443
|
var metaAudienceSetupResource = object2({ externalId: nativeAudienceId, resourceRevision: revision });
|
|
@@ -2189,7 +2463,7 @@ var metaAudienceSetupPrepareFields = {
|
|
|
2189
2463
|
var metaAudienceSetupPrepare = object2(metaAudienceSetupPrepareFields);
|
|
2190
2464
|
var parseResonanceMetaAudienceSetupPrepareRequest = (value) => metaAudienceSetupPrepare.read(value, "metaAudienceSetupPrepare");
|
|
2191
2465
|
var RESONANCE_META_AUDIENCE_SETUP_PREPARE_REQUEST_JSON_SCHEMA = metaAudienceSetupPrepare.schema;
|
|
2192
|
-
var metaAudienceSetupIntent =
|
|
2466
|
+
var metaAudienceSetupIntent = refine3(object2({
|
|
2193
2467
|
...metaAudienceSetupPrepareFields,
|
|
2194
2468
|
...metaSetupOwnerFields,
|
|
2195
2469
|
audienceRuleRef: audience,
|
|
@@ -2202,11 +2476,11 @@ var metaAudienceSetupIntent = refine2(object2({
|
|
|
2202
2476
|
expiresAt: instant
|
|
2203
2477
|
}), (value, at) => {
|
|
2204
2478
|
const { audienceRule, audienceRuleRef, resourceRuleRef, excludedResourceRuleRefs, measurementConfigRef: measurementConfigRef2 } = value;
|
|
2205
|
-
if (audienceRuleRef.projectId !== value.projectId || audienceRuleRef.site !== value.site || audienceRuleRef.id !== audienceRule.id || audienceRuleRef.revision !== audienceRule.revision || audienceRuleRef.policyRevision !== measurementConfigRef2.policyRevision)
|
|
2479
|
+
if (audienceRuleRef.projectId !== value.projectId || audienceRuleRef.site !== value.site || audienceRuleRef.id !== audienceRule.id || audienceRuleRef.revision !== audienceRule.revision || audienceRuleRef.policyRevision !== measurementConfigRef2.policyRevision) fail3(at + ".audienceRuleRef", "requires the exact scoped audience and policy revision");
|
|
2206
2480
|
const excludedIds = excludedResourceRuleRefs.map((ref) => ref.id);
|
|
2207
2481
|
unique(excludedIds, at + ".excludedResourceRuleRefs");
|
|
2208
2482
|
if (excludedIds.includes(resourceRuleRef.id) || canonical([...audienceRuleRef.exclusionRuleIds].sort()) !== canonical(excludedIds.sort())) {
|
|
2209
|
-
|
|
2483
|
+
fail3(at + ".excludedResourceRuleRefs", "requires the exact exclusions disjoint from the positive rule");
|
|
2210
2484
|
}
|
|
2211
2485
|
checkAudienceBand(audienceRuleRef, "meta_ads", at + ".audienceRuleRef");
|
|
2212
2486
|
});
|
|
@@ -2223,14 +2497,14 @@ var metaAudienceSetupVerification = object2({
|
|
|
2223
2497
|
audienceSpecDigest: digest,
|
|
2224
2498
|
retentionDays: integer2(1, META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS)
|
|
2225
2499
|
});
|
|
2226
|
-
var metaAudienceSetupReceipt =
|
|
2500
|
+
var metaAudienceSetupReceipt = refine3(object2({
|
|
2227
2501
|
...metaSetupReceiptFields,
|
|
2228
2502
|
currentVerification: nullable2(metaAudienceSetupVerification)
|
|
2229
2503
|
}), (value, at) => checkMetaSetupReceipt(value, at, "audience"));
|
|
2230
2504
|
var parseResonanceMetaAudienceSetupReceipt = (value) => metaAudienceSetupReceipt.read(value, "metaAudienceSetupReceipt");
|
|
2231
2505
|
var resonanceMetaAudienceSetupReceiptDigestInput = (value) => canonical(parseResonanceMetaAudienceSetupReceipt(value));
|
|
2232
2506
|
var RESONANCE_META_AUDIENCE_SETUP_RECEIPT_JSON_SCHEMA = metaAudienceSetupReceipt.schema;
|
|
2233
|
-
var websiteVisitSetupGrantProof =
|
|
2507
|
+
var websiteVisitSetupGrantProof = refine3(object2({
|
|
2234
2508
|
schemaVersion: literal2(1),
|
|
2235
2509
|
grantOperationId: uuid,
|
|
2236
2510
|
audienceOperationId: uuid,
|
|
@@ -2246,10 +2520,10 @@ var websiteVisitSetupGrantProof = refine2(object2({
|
|
|
2246
2520
|
accountBindingId: uuid,
|
|
2247
2521
|
audience: metaAudienceSetupVerification
|
|
2248
2522
|
}), (value, at) => {
|
|
2249
|
-
if (value.grantOperationId.toLowerCase() === value.audienceOperationId.toLowerCase())
|
|
2250
|
-
if (Date.parse(value.audience.observedAt) > Date.parse(value.activatedAt) || Date.parse(value.activatedAt) >= Date.parse(value.expiresAt))
|
|
2523
|
+
if (value.grantOperationId.toLowerCase() === value.audienceOperationId.toLowerCase()) fail3(at + ".grantOperationId", "requires a distinct native grant operation");
|
|
2524
|
+
if (Date.parse(value.audience.observedAt) > Date.parse(value.activatedAt) || Date.parse(value.activatedAt) >= Date.parse(value.expiresAt)) fail3(at, "requires verification by activation and a nonempty grant window");
|
|
2251
2525
|
});
|
|
2252
|
-
var websiteVisitSetupGrantStatus =
|
|
2526
|
+
var websiteVisitSetupGrantStatus = refine3(object2({
|
|
2253
2527
|
proof: websiteVisitSetupGrantProof,
|
|
2254
2528
|
status: choice2("active", "revoked", "expired", "invalidated"),
|
|
2255
2529
|
checkedAt: instant,
|
|
@@ -2257,14 +2531,14 @@ var websiteVisitSetupGrantStatus = refine2(object2({
|
|
|
2257
2531
|
reasonCodes: metaSetupReceiptFields.reasonCodes
|
|
2258
2532
|
}), (value, at) => {
|
|
2259
2533
|
const checked = Date.parse(value.checkedAt), activated = Date.parse(value.proof.activatedAt), expires = Date.parse(value.proof.expiresAt);
|
|
2260
|
-
if (checked < activated)
|
|
2534
|
+
if (checked < activated) fail3(at + ".checkedAt", "cannot predate activation");
|
|
2261
2535
|
if (value.status === "revoked") {
|
|
2262
2536
|
if (!value.revokedAt || Date.parse(value.revokedAt) < activated || Date.parse(value.revokedAt) > checked) {
|
|
2263
|
-
|
|
2537
|
+
fail3(at + ".revokedAt", "requires the recorded revocation between activation and observation");
|
|
2264
2538
|
}
|
|
2265
|
-
} else if (value.revokedAt)
|
|
2539
|
+
} else if (value.revokedAt) fail3(at + ".revokedAt", "requires revoked status");
|
|
2266
2540
|
if (value.status === "active" && checked >= expires || value.status === "expired" && checked < expires) {
|
|
2267
|
-
|
|
2541
|
+
fail3(at + ".status", "must agree with the original expiry");
|
|
2268
2542
|
}
|
|
2269
2543
|
});
|
|
2270
2544
|
var parseResonanceWebsiteVisitSetupGrantProof = (value) => websiteVisitSetupGrantProof.read(value, "websiteVisitSetupGrantProof");
|
|
@@ -2276,23 +2550,23 @@ function checkMetaAudienceSetupStatus({ receipt: receipt2, grant }, at) {
|
|
|
2276
2550
|
if (!grant) return;
|
|
2277
2551
|
const { proof } = grant;
|
|
2278
2552
|
if (receipt2.status !== "selected" && receipt2.status !== "verified" || !receipt2.currentVerification || canonical(receipt2.currentVerification) !== canonical(proof.audience)) {
|
|
2279
|
-
|
|
2553
|
+
fail3(at + ".grant", "requires the same verified audience witness as the setup receipt");
|
|
2280
2554
|
}
|
|
2281
2555
|
if (proof.audienceOperationId !== receipt2.operationId || proof.requestDigest !== receipt2.requestDigest || proof.projectId !== receipt2.projectId || proof.campaignId !== receipt2.campaignId || proof.site !== receipt2.site || proof.accountBindingId !== receipt2.accountBindingId) {
|
|
2282
|
-
|
|
2556
|
+
fail3(at + ".grant", "requires the grant linked to this exact setup operation");
|
|
2283
2557
|
}
|
|
2284
2558
|
}
|
|
2285
2559
|
var metaAudienceSetupStatusShape = object2(metaAudienceSetupStatusFields);
|
|
2286
|
-
var metaAudienceSetupStatus =
|
|
2560
|
+
var metaAudienceSetupStatus = refine3(metaAudienceSetupStatusShape, checkMetaAudienceSetupStatus);
|
|
2287
2561
|
var parseResonanceMetaAudienceSetupStatus = (value) => metaAudienceSetupStatus.read(value, "metaAudienceSetupStatus");
|
|
2288
2562
|
var RESONANCE_META_AUDIENCE_SETUP_STATUS_JSON_SCHEMA = metaAudienceSetupStatus.schema;
|
|
2289
|
-
var metaAudienceSetupListItem =
|
|
2563
|
+
var metaAudienceSetupListItem = refine3(object2({ ledgerActionId: uuid, ...metaAudienceSetupStatusFields }), (item, at) => {
|
|
2290
2564
|
checkMetaAudienceSetupStatus(item, at);
|
|
2291
2565
|
if (item.grant && item.grant.proof.approvalActionId.toLowerCase() !== item.ledgerActionId.toLowerCase()) {
|
|
2292
|
-
|
|
2566
|
+
fail3(at + ".ledgerActionId", "requires the original approval linked to this grant");
|
|
2293
2567
|
}
|
|
2294
2568
|
});
|
|
2295
|
-
var metaAudienceSetupList =
|
|
2569
|
+
var metaAudienceSetupList = refine3(object2({
|
|
2296
2570
|
items: list2(metaAudienceSetupListItem, 25),
|
|
2297
2571
|
nextCursor: nullable2(uuid)
|
|
2298
2572
|
}), ({ items }, at) => {
|
|
@@ -2300,18 +2574,18 @@ var metaAudienceSetupList = refine2(object2({
|
|
|
2300
2574
|
});
|
|
2301
2575
|
var parseResonanceMetaAudienceSetupList = (value) => metaAudienceSetupList.read(value, "metaAudienceSetupList");
|
|
2302
2576
|
var RESONANCE_META_AUDIENCE_SETUP_LIST_JSON_SCHEMA = metaAudienceSetupList.schema;
|
|
2303
|
-
var websiteVisitSetupGrant =
|
|
2577
|
+
var websiteVisitSetupGrant = refine3(object2({
|
|
2304
2578
|
proof: websiteVisitSetupGrantProof,
|
|
2305
2579
|
intent: metaAudienceSetupIntent
|
|
2306
2580
|
}), (value, at) => {
|
|
2307
2581
|
const { proof, intent } = value;
|
|
2308
2582
|
const { audience: witness } = proof;
|
|
2309
|
-
if (intent.feed.kind !== "enable" || Date.parse(intent.feed.expiresAt) !== Date.parse(proof.expiresAt) || Date.parse(proof.activatedAt) >= Date.parse(intent.expiresAt))
|
|
2583
|
+
if (intent.feed.kind !== "enable" || Date.parse(intent.feed.expiresAt) !== Date.parse(proof.expiresAt) || Date.parse(proof.activatedAt) >= Date.parse(intent.expiresAt)) fail3(at, "requires the explicit original opt-in and an unexpired setup approval");
|
|
2310
2584
|
if (proof.projectId !== intent.projectId || proof.campaignId !== intent.campaignId || proof.site !== intent.site || proof.accountBindingId !== intent.accountBindingId || witness.externalAccountId !== intent.externalAccountId || witness.businessId !== intent.businessId || witness.datasetExternalId !== intent.dataset.externalId || witness.datasetResourceRevision !== intent.dataset.resourceRevision || witness.audienceSpecDigest !== intent.audienceSpecDigest || witness.retentionDays !== intent.audienceRuleRef.retentionDays) {
|
|
2311
|
-
|
|
2585
|
+
fail3(at, "requires the exact original scope and verified destination");
|
|
2312
2586
|
}
|
|
2313
2587
|
if (intent.selection.kind === "existing" && (witness.externalId !== intent.selection.externalId || witness.resourceRevision !== intent.selection.resourceRevision)) {
|
|
2314
|
-
|
|
2588
|
+
fail3(at, "requires verification of the exact existing audience");
|
|
2315
2589
|
}
|
|
2316
2590
|
});
|
|
2317
2591
|
var parseResonanceWebsiteVisitSetupGrant = (value) => websiteVisitSetupGrant.read(value, "websiteVisitSetupGrant");
|
|
@@ -2339,7 +2613,7 @@ function resonanceWebsiteVisitSetupEventTime(value, context) {
|
|
|
2339
2613
|
return websiteVisitEventTime(input, Date.parse(actual.activatedAt), Date.parse(actual.expiresAt), Date.parse(actual.now));
|
|
2340
2614
|
}
|
|
2341
2615
|
var nativeAudienceRef = object2({ externalId: nativeAudienceId, revision: digest });
|
|
2342
|
-
var metaSave =
|
|
2616
|
+
var metaSave = refine3(object2({
|
|
2343
2617
|
schemaVersion: literal2(1),
|
|
2344
2618
|
expectedCampaignRevision: integer2(1),
|
|
2345
2619
|
expectedConfigurationRevision: integer2(0),
|
|
@@ -2363,7 +2637,7 @@ var metaMaterialFields = {
|
|
|
2363
2637
|
configurationRevision: integer2(1),
|
|
2364
2638
|
saveOperationId: uuid,
|
|
2365
2639
|
channel: meta,
|
|
2366
|
-
account: object2({ id: uuid, externalId:
|
|
2640
|
+
account: object2({ id: uuid, externalId: text3(160), name: nullable2(friendlyName) }),
|
|
2367
2641
|
datasetName: nullable2(friendlyName),
|
|
2368
2642
|
pageName: nullable2(friendlyName),
|
|
2369
2643
|
instagramName: nullable2(friendlyName),
|
|
@@ -2375,34 +2649,34 @@ var metaMaterialFields = {
|
|
|
2375
2649
|
object2(metaMaterialFields);
|
|
2376
2650
|
function checkMetaMaterial(v, p) {
|
|
2377
2651
|
scoped(v, v.projectId, [v.site], p);
|
|
2378
|
-
if (v.channel.id !== v.channelId || v.channel.accountBindingId !== v.account.id || v.matchingProfileRef.id !== v.saveOperationId || v.matchingProfileRef.revision !== v.configurationRevision)
|
|
2379
|
-
if (!v.channel.instagramRef && v.instagramName !== null)
|
|
2652
|
+
if (v.channel.id !== v.channelId || v.channel.accountBindingId !== v.account.id || v.matchingProfileRef.id !== v.saveOperationId || v.matchingProfileRef.revision !== v.configurationRevision) fail3(p, "original channel/account/profile receipt mismatch");
|
|
2653
|
+
if (!v.channel.instagramRef && v.instagramName !== null) fail3(p + ".instagramName", "absent original Instagram identity requires null");
|
|
2380
2654
|
unique(v.rules.map((rule) => rule.id), p + ".rules");
|
|
2381
2655
|
unique(v.audiences.map((a) => a.audienceRuleRef.id), p + ".audiences");
|
|
2382
2656
|
unique(v.channel.audienceRuleRefs.map((a) => a.id), p + ".channel.audienceRuleRefs");
|
|
2383
|
-
if (v.audiences.length !== v.channel.audienceRuleRefs.length)
|
|
2657
|
+
if (v.audiences.length !== v.channel.audienceRuleRefs.length) fail3(p + ".audiences", "must cover exactly the original logical audiences");
|
|
2384
2658
|
checkMetaAudienceBands(v.channel, p + ".channel.audienceRuleRefs");
|
|
2385
2659
|
for (const a of v.audiences) {
|
|
2386
|
-
if (!v.channel.audienceRuleRefs.some((ref) => canonical(ref) === canonical(a.audienceRuleRef)))
|
|
2660
|
+
if (!v.channel.audienceRuleRefs.some((ref) => canonical(ref) === canonical(a.audienceRuleRef))) fail3(p + ".audiences", "original logical audience version mismatch");
|
|
2387
2661
|
unique(a.excludedResourceRuleRefs.map((ref) => ref.id), p + ".audiences.excludedResourceRuleRefs");
|
|
2388
2662
|
unique(a.audienceRuleRef.exclusionRuleIds, p + ".audiences.audienceRuleRef.exclusionRuleIds");
|
|
2389
|
-
if (canonical([...a.audienceRuleRef.exclusionRuleIds].sort()) !== canonical(a.excludedResourceRuleRefs.map((ref) => ref.id).sort()) || a.excludedResourceRuleRefs.some((ref) => ref.id === a.resourceRuleRef.id))
|
|
2390
|
-
for (const selected of [a.resourceRuleRef, ...a.excludedResourceRuleRefs]) if (!v.rules.some((rule) => rule.id === selected.id && rule.revision === selected.revision))
|
|
2391
|
-
if (a.selection.mode === "admitted_setup" && a.selection.setup.localOutputKey !== `audience:${a.audienceRuleRef.id}:${a.audienceRuleRef.revision}`)
|
|
2663
|
+
if (canonical([...a.audienceRuleRef.exclusionRuleIds].sort()) !== canonical(a.excludedResourceRuleRefs.map((ref) => ref.id).sort()) || a.excludedResourceRuleRefs.some((ref) => ref.id === a.resourceRuleRef.id)) fail3(p + ".audiences", "positive/excluded resource scope mismatch");
|
|
2664
|
+
for (const selected of [a.resourceRuleRef, ...a.excludedResourceRuleRefs]) if (!v.rules.some((rule) => rule.id === selected.id && rule.revision === selected.revision)) fail3(p + ".audiences", "resource rule version mismatch");
|
|
2665
|
+
if (a.selection.mode === "admitted_setup" && a.selection.setup.localOutputKey !== `audience:${a.audienceRuleRef.id}:${a.audienceRuleRef.revision}`) fail3(p + ".audiences.selection.setup.localOutputKey", "must retain the actual original SDK creator key");
|
|
2392
2666
|
}
|
|
2393
2667
|
}
|
|
2394
|
-
var metaSnapshot =
|
|
2668
|
+
var metaSnapshot = refine3(object2({ ...metaMaterialFields, configurationDigest: digest }), checkMetaMaterial);
|
|
2395
2669
|
var parseResonanceMetaConfigurationSnapshot = (v) => metaSnapshot.read(v, "metaConfigurationSnapshot");
|
|
2396
|
-
var metaDigestValue =
|
|
2670
|
+
var metaDigestValue = refine3(object2({ ...metaMaterialFields, configurationDigest: optional2(digest) }), checkMetaMaterial);
|
|
2397
2671
|
function resonanceMetaConfigurationDigestInput(v) {
|
|
2398
2672
|
const { configurationDigest: _self, ...material } = metaDigestValue.read(v, "metaConfigurationDigestInput");
|
|
2399
2673
|
return canonical(material);
|
|
2400
2674
|
}
|
|
2401
|
-
var metaCurrentMetadata = object2({ currentCampaignRevision: integer2(1), currentDefinitionDigest: digest, observedAt: instant, expiresAt: nullable2(instant), reasonCodes: uniqueList(
|
|
2675
|
+
var metaCurrentMetadata = object2({ currentCampaignRevision: integer2(1), currentDefinitionDigest: digest, observedAt: instant, expiresAt: nullable2(instant), reasonCodes: uniqueList(text3(200), 100), pendingRequirements: uniqueList(text3(200), 100) });
|
|
2402
2676
|
function metaReviewable(snapshot, metadata) {
|
|
2403
2677
|
return metadata.currentCampaignRevision >= snapshot.campaignRevision && metadata.currentDefinitionDigest === snapshot.reviewedDefinitionDigest && metadata.reasonCodes.length === 0 && metadata.expiresAt !== null && Date.parse(metadata.expiresAt) > Date.parse(metadata.observedAt);
|
|
2404
2678
|
}
|
|
2405
|
-
var metaView =
|
|
2679
|
+
var metaView = refine3(union2(
|
|
2406
2680
|
object2({ schemaVersion: literal2(1), kind: literal2("unconfigured"), projectId: uuid, campaignId: uuid, channelId: uuid, configurationRevision: literal2(0) }),
|
|
2407
2681
|
object2({
|
|
2408
2682
|
schemaVersion: literal2(1),
|
|
@@ -2417,14 +2691,14 @@ var metaView = refine2(union2(
|
|
|
2417
2691
|
observedAt: instant,
|
|
2418
2692
|
expiresAt: nullable2(instant),
|
|
2419
2693
|
readyForReview: bool,
|
|
2420
|
-
reasonCodes: uniqueList(
|
|
2421
|
-
pendingRequirements: uniqueList(
|
|
2694
|
+
reasonCodes: uniqueList(text3(200), 100),
|
|
2695
|
+
pendingRequirements: uniqueList(text3(200), 100)
|
|
2422
2696
|
})
|
|
2423
2697
|
), (v, p) => {
|
|
2424
2698
|
if (v.kind !== "configured") return;
|
|
2425
2699
|
const s = parseResonanceMetaConfigurationSnapshot(v.snapshot);
|
|
2426
|
-
if (v.projectId !== s.projectId || v.campaignId !== s.campaignId || v.channelId !== s.channelId || v.configurationRevision !== s.configurationRevision)
|
|
2427
|
-
if (v.readyForReview !== metaReviewable(s, v))
|
|
2700
|
+
if (v.projectId !== s.projectId || v.campaignId !== s.campaignId || v.channelId !== s.channelId || v.configurationRevision !== s.configurationRevision) fail3(p, "snapshot identity or configuration CAS mismatch");
|
|
2701
|
+
if (v.readyForReview !== metaReviewable(s, v)) fail3(p + ".readyForReview", "must reflect current review prerequisites only");
|
|
2428
2702
|
});
|
|
2429
2703
|
var parseResonanceMetaConfigurationView = (v) => metaView.read(v, "metaConfigurationView");
|
|
2430
2704
|
var RESONANCE_META_AUDIENCE_VERDICTS = ["ready", "too_small", "blocked", "unknown"];
|
|
@@ -2454,24 +2728,24 @@ var RESONANCE_META_AUDIENCE_REASONS = [
|
|
|
2454
2728
|
"meta_audience_name_sensitive"
|
|
2455
2729
|
];
|
|
2456
2730
|
var metaReadinessPage = object2({ resourceRuleRef: measurementRuleRef, path: observedPagePath, label: nullable2(friendlyName) });
|
|
2457
|
-
var metaAudienceSize =
|
|
2458
|
-
if (v.upper < v.lower)
|
|
2731
|
+
var metaAudienceSize = refine3(object2({ lower: integer2(0), upper: integer2(0) }), (v, p) => {
|
|
2732
|
+
if (v.upper < v.lower) fail3(p, "size bounds must be ordered");
|
|
2459
2733
|
});
|
|
2460
2734
|
var metaAudienceReadinessFields = {
|
|
2461
2735
|
verdict: choice2(...RESONANCE_META_AUDIENCE_VERDICTS),
|
|
2462
2736
|
reasonCodes: uniqueList(choice2(...RESONANCE_META_AUDIENCE_REASONS), 50),
|
|
2463
2737
|
size: nullable2(metaAudienceSize)
|
|
2464
2738
|
};
|
|
2465
|
-
var metaAudienceSetupReadiness =
|
|
2739
|
+
var metaAudienceSetupReadiness = refine3(object2({
|
|
2466
2740
|
status: metaAudienceSetupStatus,
|
|
2467
2741
|
delivery: nullable2(object2(websiteVisitSetupAcceptedVisitFields)),
|
|
2468
2742
|
providerAudience: nullable2(object2({ externalId: nativeAudienceId, observedAt: instant, readiness: object2(metaAudienceReadinessFields) }))
|
|
2469
2743
|
}), ({ status, delivery, providerAudience }, at) => {
|
|
2470
2744
|
if (delivery && (!status.grant || Date.parse(delivery.checkedAt) < Date.parse(status.grant.proof.activatedAt))) {
|
|
2471
|
-
|
|
2745
|
+
fail3(at + ".delivery", "requires the grant and an observation at or after activation");
|
|
2472
2746
|
}
|
|
2473
2747
|
if (providerAudience && (status.receipt.status !== "selected" && status.receipt.status !== "verified" || status.receipt.currentVerification?.externalId !== providerAudience.externalId)) {
|
|
2474
|
-
|
|
2748
|
+
fail3(at + ".providerAudience", "requires observation of the exact verified audience");
|
|
2475
2749
|
}
|
|
2476
2750
|
});
|
|
2477
2751
|
var parseResonanceMetaAudienceSetupReadiness = (value) => metaAudienceSetupReadiness.read(value, "metaAudienceSetupReadiness");
|
|
@@ -2481,23 +2755,23 @@ var metaReadinessCheck = union2(
|
|
|
2481
2755
|
object2({ state: literal2("observed"), mappingSource: choice2("selected_external_audience", "current_materialized_audience"), ...metaAudienceReadinessFields, observedAt: instant, expiresAt: nullable2(instant), sizeObservedAt: literal2(null), sizeExpiresAt: literal2(null) })
|
|
2482
2756
|
);
|
|
2483
2757
|
var metaReadinessAudience = object2({ audienceRuleRef: audience, name: friendlyName, includedPage: metaReadinessPage, excludedPages: list2(metaReadinessPage, 50), nativeAudienceId: nullable2(nativeAudienceId), check: metaReadinessCheck });
|
|
2484
|
-
var metaRetargetingReadiness =
|
|
2758
|
+
var metaRetargetingReadiness = refine3(object2({ schemaVersion: literal2(1), projectId: uuid, campaignId: uuid, channelId: uuid, site, campaignRevision: integer2(1), accountBindingId: uuid, configuration: metaView, audiences: list2(metaReadinessAudience, 50) }), (v, p) => {
|
|
2485
2759
|
const sameId = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
2486
2760
|
const config = v.configuration;
|
|
2487
|
-
if (!sameId(config.projectId, v.projectId) || !sameId(config.campaignId, v.campaignId) || !sameId(config.channelId, v.channelId))
|
|
2488
|
-
if (config.kind === "configured" && (config.currentCampaignRevision !== v.campaignRevision || config.snapshot.site !== v.site || !sameId(config.snapshot.account.id, v.accountBindingId)))
|
|
2761
|
+
if (!sameId(config.projectId, v.projectId) || !sameId(config.campaignId, v.campaignId) || !sameId(config.channelId, v.channelId)) fail3(p + ".configuration", "configuration scope mismatch");
|
|
2762
|
+
if (config.kind === "configured" && (config.currentCampaignRevision !== v.campaignRevision || config.snapshot.site !== v.site || !sameId(config.snapshot.account.id, v.accountBindingId))) fail3(p + ".configuration", "current configuration revision, site or account mismatch");
|
|
2489
2763
|
unique(v.audiences.map((row) => row.audienceRuleRef.id.toLowerCase()), p + ".audiences");
|
|
2490
2764
|
for (const row of v.audiences) {
|
|
2491
|
-
if (!sameId(row.audienceRuleRef.projectId, v.projectId) || row.audienceRuleRef.site !== v.site)
|
|
2765
|
+
if (!sameId(row.audienceRuleRef.projectId, v.projectId) || row.audienceRuleRef.site !== v.site) fail3(p + ".audiences", "audience scope mismatch");
|
|
2492
2766
|
const excluded = row.excludedPages.map((page2) => page2.resourceRuleRef.id.toLowerCase());
|
|
2493
2767
|
unique(excluded, p + ".audiences.excludedPages");
|
|
2494
2768
|
const expected = row.audienceRuleRef.exclusionRuleIds.map((id) => id.toLowerCase());
|
|
2495
2769
|
unique(expected, p + ".audiences.audienceRuleRef.exclusionRuleIds");
|
|
2496
|
-
if (excluded.includes(row.includedPage.resourceRuleRef.id.toLowerCase()) || excluded.length !== expected.length || expected.some((id) => !excluded.includes(id)))
|
|
2497
|
-
if (row.check.state === "observed" && (row.nativeAudienceId === null || config.kind !== "configured"))
|
|
2770
|
+
if (excluded.includes(row.includedPage.resourceRuleRef.id.toLowerCase()) || excluded.length !== expected.length || expected.some((id) => !excluded.includes(id))) fail3(p + ".audiences.excludedPages", "exclusion rule scope mismatch");
|
|
2771
|
+
if (row.check.state === "observed" && (row.nativeAudienceId === null || config.kind !== "configured")) fail3(p + ".audiences.check", "observed check requires configured scope and actual native audience identity");
|
|
2498
2772
|
if (config.kind === "configured" && config.currentDefinitionDigest === config.snapshot.reviewedDefinitionDigest) {
|
|
2499
2773
|
const original = config.snapshot.audiences.find((a) => sameId(a.audienceRuleRef.id, row.audienceRuleRef.id));
|
|
2500
|
-
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))))
|
|
2774
|
+
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)))) fail3(p + ".audiences", "original audience and page rule versions must match");
|
|
2501
2775
|
}
|
|
2502
2776
|
}
|
|
2503
2777
|
});
|
|
@@ -2515,38 +2789,38 @@ var RESONANCE_META_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA = metaSave.schema;
|
|
|
2515
2789
|
var RESONANCE_META_CONFIGURATION_SNAPSHOT_JSON_SCHEMA = metaSnapshot.schema;
|
|
2516
2790
|
var RESONANCE_META_CONFIGURATION_VIEW_JSON_SCHEMA = metaView.schema;
|
|
2517
2791
|
var RESONANCE_META_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA = metaSaveResponse.schema;
|
|
2518
|
-
var feedSelection =
|
|
2792
|
+
var feedSelection = refine3(object2({ channels: list2(object2({ channelId: uuid, expectedConfigurationRevision: integer2(1), resourceRuleRefs: list2(measurementRuleRef, 500, 1) }), 100, 1) }), (v, p) => {
|
|
2519
2793
|
unique(v.channels.map((c) => c.channelId), p + ".channels");
|
|
2520
2794
|
for (const c of v.channels) unique(c.resourceRuleRefs.map((ref) => ref.id), p + ".resourceRuleRefs");
|
|
2521
2795
|
});
|
|
2522
2796
|
var mandateDraftRequest = object2({ expectedRevision: integer2(1), allowedOperations: mandateAllowedOperations, expiresAt: instant, websiteVisitFeedSelection: optional2(feedSelection), providerReporting: optional2(providerReportingSelection), operatingPolicySelection: optional2(operatingPolicySelection), activation: optional2(literal2("operating_policy")) });
|
|
2523
2797
|
var parseResonanceMandateDraftRequest = (v) => mandateDraftRequest.read(v, "mandateDraftRequest");
|
|
2524
2798
|
var RESONANCE_MANDATE_DRAFT_REQUEST_JSON_SCHEMA = mandateDraftRequest.schema;
|
|
2525
|
-
var feedReview = object2({ schemaVersion: literal2(1), approval: mandateApproval, mandateRef, configurations: list2(metaSnapshot, 100), current: object2({ state: choice2("not_enabled", "eligible", "invalidated", "unavailable"), checkedAt: instant, expiresAt: nullable2(instant), reasonCodes: uniqueList(
|
|
2799
|
+
var feedReview = object2({ schemaVersion: literal2(1), approval: mandateApproval, mandateRef, configurations: list2(metaSnapshot, 100), current: object2({ state: choice2("not_enabled", "eligible", "invalidated", "unavailable"), checkedAt: instant, expiresAt: nullable2(instant), reasonCodes: uniqueList(text3(200), 100) }) });
|
|
2526
2800
|
function parseResonanceWebsiteVisitFeedReview(v, context) {
|
|
2527
2801
|
const r = feedReview.read(v, "websiteVisitFeedReview"), original = r.approval, grant = parseResonanceMandateScope(original.mandate), ref = r.mandateRef, p = "websiteVisitFeedReview";
|
|
2528
2802
|
parseResonanceMandateApprovalPayload(original, { project_id: grant.projectId, campaign_id: grant.campaignId });
|
|
2529
|
-
if (ref.campaignId !== grant.campaignId || ref.preparedPlanId !== original.preparedPlanId || ref.reviewDigest !== original.reviewDigest || ref.mandateDigest !== original.mandateDigest)
|
|
2803
|
+
if (ref.campaignId !== grant.campaignId || ref.preparedPlanId !== original.preparedPlanId || ref.reviewDigest !== original.reviewDigest || ref.mandateDigest !== original.mandateDigest) fail3(p + ".mandateRef", "requires the same original accepted mandate");
|
|
2530
2804
|
unique(r.configurations.map((c) => c.channelId), p + ".configurations");
|
|
2531
2805
|
const feed = grant.websiteVisitFeed;
|
|
2532
2806
|
if (!feed) {
|
|
2533
|
-
if (r.configurations.length || r.current.state !== "not_enabled")
|
|
2807
|
+
if (r.configurations.length || r.current.state !== "not_enabled") fail3(p, "absent original feed requires not_enabled and no configurations");
|
|
2534
2808
|
} else {
|
|
2535
|
-
if (r.current.state === "not_enabled" || r.configurations.length !== feed.channels.length)
|
|
2809
|
+
if (r.current.state === "not_enabled" || r.configurations.length !== feed.channels.length) fail3(p, "must cover the exact original feed channels");
|
|
2536
2810
|
for (const selected of feed.channels) {
|
|
2537
2811
|
const config = r.configurations.find((c) => c.channelId === selected.channelId);
|
|
2538
|
-
if (!config || config.projectId !== grant.projectId || config.campaignId !== grant.campaignId || !grant.sites.includes(config.site) || !grant.accountBindingIds.includes(config.account.id) || config.campaignRevision > original.expectedRevision || canonical(config.measurementConfigRef) !== canonical(selected.measurementConfigRef) || canonical(config.matchingProfileRef) !== canonical(selected.matchingProfileRef))
|
|
2812
|
+
if (!config || config.projectId !== grant.projectId || config.campaignId !== grant.campaignId || !grant.sites.includes(config.site) || !grant.accountBindingIds.includes(config.account.id) || config.campaignRevision > original.expectedRevision || canonical(config.measurementConfigRef) !== canonical(selected.measurementConfigRef) || canonical(config.matchingProfileRef) !== canonical(selected.matchingProfileRef)) fail3(p + ".configurations", "original configuration/profile/scope mismatch");
|
|
2539
2813
|
const saved = config;
|
|
2540
|
-
for (const a of saved.channel.audienceRuleRefs) if (!grant.audienceRuleRefs.some((ref2) => canonical(ref2) === canonical(a)))
|
|
2814
|
+
for (const a of saved.channel.audienceRuleRefs) if (!grant.audienceRuleRefs.some((ref2) => canonical(ref2) === canonical(a))) fail3(p + ".configurations", "original logical audience grant mismatch");
|
|
2541
2815
|
const positive = saved.audiences.map((a) => a.resourceRuleRef);
|
|
2542
|
-
for (const rule of selected.resourceRuleRefs) if (!positive.some((ref2) => ref2.id === rule.id && ref2.revision === rule.revision))
|
|
2816
|
+
for (const rule of selected.resourceRuleRefs) if (!positive.some((ref2) => ref2.id === rule.id && ref2.revision === rule.revision)) fail3(p + ".configurations", "feed requires an original positive resource rule, never excluded-only");
|
|
2543
2817
|
}
|
|
2544
|
-
if (r.current.state === "eligible" && (r.current.reasonCodes.length || r.current.expiresAt === null || Date.parse(r.current.expiresAt) <= Date.parse(r.current.checkedAt)))
|
|
2818
|
+
if (r.current.state === "eligible" && (r.current.reasonCodes.length || r.current.expiresAt === null || Date.parse(r.current.expiresAt) <= Date.parse(r.current.checkedAt))) fail3(p + ".current", "eligible review requires an observed nonexpired horizon and no blockers");
|
|
2545
2819
|
}
|
|
2546
2820
|
if (context) {
|
|
2547
2821
|
const actual = object2({ preparedPlan: prepared }).read(context, p + ".context"), plan = parseResonancePreparedPlan(actual.preparedPlan);
|
|
2548
|
-
if (plan.id !== original.preparedPlanId || plan.campaignId !== grant.campaignId || plan.projectId !== grant.projectId || plan.reviewDigest !== original.reviewDigest || plan.expectedRevision !== original.expectedRevision || canonical(plan.definition.budget) !== canonical(grant.budget) || canonical(plan.definition.objective) !== canonical(grant.goal))
|
|
2549
|
-
for (const config of r.configurations) if (config.reviewedDefinitionDigest !== plan.definitionDigest || !plan.definition.channels.some((c) => canonical(c) === canonical(config.channel)))
|
|
2822
|
+
if (plan.id !== original.preparedPlanId || plan.campaignId !== grant.campaignId || plan.projectId !== grant.projectId || plan.reviewDigest !== original.reviewDigest || plan.expectedRevision !== original.expectedRevision || canonical(plan.definition.budget) !== canonical(grant.budget) || canonical(plan.definition.objective) !== canonical(grant.goal)) fail3(p + ".context", "requires the original prepared plan and mandate material");
|
|
2823
|
+
for (const config of r.configurations) if (config.reviewedDefinitionDigest !== plan.definitionDigest || !plan.definition.channels.some((c) => canonical(c) === canonical(config.channel))) fail3(p + ".context", "original channel or reviewed definition mismatch");
|
|
2550
2824
|
}
|
|
2551
2825
|
return r;
|
|
2552
2826
|
}
|
|
@@ -2554,7 +2828,7 @@ var RESONANCE_WEBSITE_VISIT_FEED_REVIEW_JSON_SCHEMA = feedReview.schema;
|
|
|
2554
2828
|
var observationIdentity = { observationId: uuid, channelId: uuid, versionId: uuid, accountBindingId: uuid };
|
|
2555
2829
|
var publicObservationMetric = union2(
|
|
2556
2830
|
object2({ ...metricBase, ...observationIdentity, source: choice2("provider", "first_party"), state: literal2("observed"), value: metricValue }),
|
|
2557
|
-
object2({ ...metricBase, ...observationIdentity, source: choice2("provider", "first_party"), state: choice2("unknown", "insufficient", "delayed", "unavailable"), value: literal2(null), reasonCode:
|
|
2831
|
+
object2({ ...metricBase, ...observationIdentity, source: choice2("provider", "first_party"), state: choice2("unknown", "insufficient", "delayed", "unavailable"), value: literal2(null), reasonCode: text3(80) })
|
|
2558
2832
|
);
|
|
2559
2833
|
function parseResonancePublicObservationMetric(v) {
|
|
2560
2834
|
const r = publicObservationMetric.read(v, "observationItem");
|
|
@@ -2563,7 +2837,7 @@ function parseResonancePublicObservationMetric(v) {
|
|
|
2563
2837
|
return r;
|
|
2564
2838
|
}
|
|
2565
2839
|
var observationDenominators = object2({ eligibleContacts: nullable2(decimal), fullyResolvedContacts: nullable2(decimal), qualifiedContacts: nullable2(decimal) });
|
|
2566
|
-
var observationSupportFields = { ...observationIdentity, currency, fetchedAt: instant, dataThrough: nullable2(instant), coverage: choice2("unknown", "partial", "complete"), reasonCode: nullable2(
|
|
2840
|
+
var observationSupportFields = { ...observationIdentity, currency, fetchedAt: instant, dataThrough: nullable2(instant), coverage: choice2("unknown", "partial", "complete"), reasonCode: nullable2(text3(80)), denominators: observationDenominators };
|
|
2567
2841
|
var firstPartyObservationSupport = object2({ ...observationSupportFields, source: literal2("first_party") });
|
|
2568
2842
|
var providerObservationSupport = object2({
|
|
2569
2843
|
...observationSupportFields,
|
|
@@ -2579,53 +2853,53 @@ var providerObservationSupport = object2({
|
|
|
2579
2853
|
var observationSupport = union2(firstPartyObservationSupport, providerObservationSupport);
|
|
2580
2854
|
function parseResonanceObservationSupport(v) {
|
|
2581
2855
|
const r = observationSupport.read(v, "observationSupport"), p = "observationSupport", d = r.denominators;
|
|
2582
|
-
if (d.fullyResolvedContacts !== null && (d.eligibleContacts === null || BigInt(d.fullyResolvedContacts) > BigInt(d.eligibleContacts)) || d.qualifiedContacts !== null && (d.fullyResolvedContacts === null || BigInt(d.qualifiedContacts) > BigInt(d.fullyResolvedContacts)))
|
|
2856
|
+
if (d.fullyResolvedContacts !== null && (d.eligibleContacts === null || BigInt(d.fullyResolvedContacts) > BigInt(d.eligibleContacts)) || d.qualifiedContacts !== null && (d.fullyResolvedContacts === null || BigInt(d.qualifiedContacts) > BigInt(d.fullyResolvedContacts))) fail3(p + ".denominators", "inconsistent independent contact universe");
|
|
2583
2857
|
if (r.source === "provider") {
|
|
2584
|
-
if (Object.values(d).some((v2) => v2 !== null))
|
|
2585
|
-
if (r.firstReceivedAt !== null && (r.receivedAt === null || Date.parse(r.firstReceivedAt) > Date.parse(r.receivedAt)))
|
|
2586
|
-
if (r.recordedAt !== null && Date.parse(r.recordedAt) !== Date.parse(r.fetchedAt))
|
|
2587
|
-
if (r.readClock !== null && (r.firstReceivedAt === null || r.receivedAt === null || r.recordedAt === null || Date.parse(r.readClock.notBeforeAt) > Date.parse(r.recordedAt)))
|
|
2588
|
-
if (r.coverageBasis === "closed_query_snapshot" ? r.coverage !== "complete" || r.reasonCode !== null || r.receivedAt === null || r.recordedAt === null || r.dataThrough !== null : r.coverage === "complete")
|
|
2858
|
+
if (Object.values(d).some((v2) => v2 !== null)) fail3(p + ".denominators", "provider reporting cannot supply qualified-contact denominators");
|
|
2859
|
+
if (r.firstReceivedAt !== null && (r.receivedAt === null || Date.parse(r.firstReceivedAt) > Date.parse(r.receivedAt))) fail3(p + ".firstReceivedAt", "preserve actual internal HTTP receipt order");
|
|
2860
|
+
if (r.recordedAt !== null && Date.parse(r.recordedAt) !== Date.parse(r.fetchedAt)) fail3(p + ".recordedAt", "must retain the native immutable SQL write time");
|
|
2861
|
+
if (r.readClock !== null && (r.firstReceivedAt === null || r.receivedAt === null || r.recordedAt === null || Date.parse(r.readClock.notBeforeAt) > Date.parse(r.recordedAt))) fail3(p + ".readClock", "requires actual earliest/final HTTP metadata and SQL lower-bound chronology");
|
|
2862
|
+
if (r.coverageBasis === "closed_query_snapshot" ? r.coverage !== "complete" || r.reasonCode !== null || r.receivedAt === null || r.recordedAt === null || r.dataThrough !== null : r.coverage === "complete") fail3(p + ".coverage", "distinguish revisable query coverage from unestablished legacy reporting");
|
|
2589
2863
|
}
|
|
2590
2864
|
return r;
|
|
2591
2865
|
}
|
|
2592
2866
|
var observationsPage = object2({ items: list2(publicObservationMetric, 500), nextCursor: nullable2(uuid), observedAt: instant, support: list2(observationSupport, 500) });
|
|
2593
2867
|
function parseResonanceObservationsPage(v) {
|
|
2594
2868
|
const r = observationsPage.read(v, "observationsPage"), p = "observationsPage";
|
|
2595
|
-
if (r.items.length !== r.support.length)
|
|
2869
|
+
if (r.items.length !== r.support.length) fail3(p + ".support", "requires one support entry for each metric item");
|
|
2596
2870
|
const pairs = /* @__PURE__ */ new Set(), rows = /* @__PURE__ */ new Map(), observedAt = Date.parse(r.observedAt);
|
|
2597
2871
|
let previous;
|
|
2598
2872
|
const first = r.items[0];
|
|
2599
2873
|
for (let i = 0; i < r.items.length; i++) {
|
|
2600
2874
|
const item = parseResonancePublicObservationMetric(r.items[i]), s = parseResonanceObservationSupport(r.support[i]), rowId = item.observationId.toLowerCase();
|
|
2601
|
-
if (Object.keys(observationIdentity).some((k) => item[k] !== s[k]))
|
|
2602
|
-
if (item.source !== s.source || item.projectId !== first.projectId || item.campaignId !== first.campaignId || item.site !== first.site)
|
|
2603
|
-
if (Date.parse(item.asOf) !== Date.parse(s.fetchedAt) || Date.parse(s.fetchedAt) > observedAt || item.dataThrough === null !== (s.dataThrough === null) || item.dataThrough !== null && s.dataThrough !== null && Date.parse(item.dataThrough) !== Date.parse(s.dataThrough))
|
|
2604
|
-
if (item.state === "observed" && item.value.kind === "money" && item.value.money.currency !== s.currency)
|
|
2605
|
-
if (previous !== void 0 && rowId < previous)
|
|
2875
|
+
if (Object.keys(observationIdentity).some((k) => item[k] !== s[k])) fail3(p + ".support", "item/support observation, channel, version and account must align in order");
|
|
2876
|
+
if (item.source !== s.source || item.projectId !== first.projectId || item.campaignId !== first.campaignId || item.site !== first.site) fail3(p + ".items", "requires one scoped provider or first-party page");
|
|
2877
|
+
if (Date.parse(item.asOf) !== Date.parse(s.fetchedAt) || Date.parse(s.fetchedAt) > observedAt || item.dataThrough === null !== (s.dataThrough === null) || item.dataThrough !== null && s.dataThrough !== null && Date.parse(item.dataThrough) !== Date.parse(s.dataThrough)) fail3(p + ".support", "preserve native SQL observation chronology and data-through meaning");
|
|
2878
|
+
if (item.state === "observed" && item.value.kind === "money" && item.value.money.currency !== s.currency) fail3(p + ".support.currency", "observed money must retain account currency");
|
|
2879
|
+
if (previous !== void 0 && rowId < previous) fail3(p + ".items", "native-row UUID order cannot be replaced by metric/time sorting");
|
|
2606
2880
|
previous = rowId;
|
|
2607
2881
|
const key = rowId + ":" + item.name;
|
|
2608
|
-
if (pairs.has(key))
|
|
2882
|
+
if (pairs.has(key)) fail3(p + ".items", "duplicate observation/metric pair");
|
|
2609
2883
|
pairs.add(key);
|
|
2610
2884
|
const supportIdentity = { ...s, fetchedAt: Date.parse(s.fetchedAt), dataThrough: s.dataThrough === null ? null : Date.parse(s.dataThrough), ...s.source === "provider" ? { firstReceivedAt: s.firstReceivedAt === null ? null : Date.parse(s.firstReceivedAt), receivedAt: s.receivedAt === null ? null : Date.parse(s.receivedAt), recordedAt: s.recordedAt === null ? null : Date.parse(s.recordedAt) } : {} };
|
|
2611
2885
|
const row = canonical({ projectId: item.projectId, campaignId: item.campaignId, site: item.site, channelId: item.channelId, versionId: item.versionId, accountBindingId: item.accountBindingId, source: item.source, windowStart: Date.parse(item.windowStart), windowEnd: Date.parse(item.windowEnd), timeZone: item.timeZone, fetchedAt: Date.parse(s.fetchedAt), support: supportIdentity });
|
|
2612
|
-
if (rows.has(rowId) && rows.get(rowId) !== row)
|
|
2886
|
+
if (rows.has(rowId) && rows.get(rowId) !== row) fail3(p + ".support", "one immutable native observation cannot change identity or support across metrics");
|
|
2613
2887
|
rows.set(rowId, row);
|
|
2614
2888
|
if (s.source === "provider") {
|
|
2615
|
-
if (item.state === "observed" && (s.coverage !== "complete" || s.coverageBasis !== "closed_query_snapshot" || s.reasonCode !== null))
|
|
2616
|
-
if (!RESONANCE_PROVIDER_METRIC_NAMES.includes(item.name) || item.sourceRef !== item.observationId || item.countingUnit !== providerCountingUnit(item.name) || item.attributionModel !== "provider_reported")
|
|
2617
|
-
if (s.readClock !== null && Date.parse(s.readClock.notBeforeAt) < Date.parse(item.windowEnd))
|
|
2889
|
+
if (item.state === "observed" && (s.coverage !== "complete" || s.coverageBasis !== "closed_query_snapshot" || s.reasonCode !== null)) fail3(p + ".support", "observed provider values require complete genuine closed-query support");
|
|
2890
|
+
if (!RESONANCE_PROVIDER_METRIC_NAMES.includes(item.name) || item.sourceRef !== item.observationId || item.countingUnit !== providerCountingUnit(item.name) || item.attributionModel !== "provider_reported") fail3(p + ".items", "provider metrics retain exact native observation and aggregate semantics");
|
|
2891
|
+
if (s.readClock !== null && Date.parse(s.readClock.notBeforeAt) < Date.parse(item.windowEnd)) fail3(p + ".support.readClock", "SQL pre-read lower bound must follow the completed query window");
|
|
2618
2892
|
} else {
|
|
2619
2893
|
const d = s.denominators;
|
|
2620
|
-
if (item.name !== "qualified_goals" || item.countingUnit !== "unique_qualified_contact" || item.goalRevision === null || item.attributionModel !== RESONANCE_ATTRIBUTION_MODEL || item.eligibleExposures !== null || item.matureOutcomes !== null)
|
|
2894
|
+
if (item.name !== "qualified_goals" || item.countingUnit !== "unique_qualified_contact" || item.goalRevision === null || item.attributionModel !== RESONANCE_ATTRIBUTION_MODEL || item.eligibleExposures !== null || item.matureOutcomes !== null) fail3(p + ".items", "preserve genuine first-party qualification without fabricated exposure counts");
|
|
2621
2895
|
const coverage = d.eligibleContacts === null || d.eligibleContacts === "0" || d.fullyResolvedContacts === null ? null : Number(BigInt(d.fullyResolvedContacts) * 10000n / BigInt(d.eligibleContacts));
|
|
2622
|
-
if (item.coverageBasisPoints !== coverage)
|
|
2623
|
-
if (item.state !== "observed" && (s.coverage === "complete" || s.reasonCode !== item.reasonCode))
|
|
2624
|
-
if (item.state === "observed" && (s.coverage !== "complete" || s.reasonCode !== null || d.eligibleContacts === null || d.fullyResolvedContacts !== d.eligibleContacts || d.qualifiedContacts === null || item.value.kind !== "count" || item.value.count !== d.qualifiedContacts))
|
|
2896
|
+
if (item.coverageBasisPoints !== coverage) fail3(p + ".support.denominators", "contact resolution coverage must match the independent universe");
|
|
2897
|
+
if (item.state !== "observed" && (s.coverage === "complete" || s.reasonCode !== item.reasonCode)) fail3(p + ".support", "unresolved qualified sources keep incomplete coverage and their native reason");
|
|
2898
|
+
if (item.state === "observed" && (s.coverage !== "complete" || s.reasonCode !== null || d.eligibleContacts === null || d.fullyResolvedContacts !== d.eligibleContacts || d.qualifiedContacts === null || item.value.kind !== "count" || item.value.count !== d.qualifiedContacts)) fail3(p + ".support", "observed qualified count requires its complete independent native universe");
|
|
2625
2899
|
}
|
|
2626
2900
|
}
|
|
2627
|
-
if (rows.size > 100)
|
|
2628
|
-
if (r.nextCursor !== null && (!r.items.length || r.nextCursor.toLowerCase() !== previous))
|
|
2901
|
+
if (rows.size > 100) fail3(p + ".items", "at most 100 native rows per page");
|
|
2902
|
+
if (r.nextCursor !== null && (!r.items.length || r.nextCursor.toLowerCase() !== previous)) fail3(p + ".nextCursor", "cursor must retain the final native row, not a metric offset");
|
|
2629
2903
|
return r;
|
|
2630
2904
|
}
|
|
2631
2905
|
var RESONANCE_PUBLIC_OBSERVATION_METRIC_JSON_SCHEMA = publicObservationMetric.schema;
|
|
@@ -2641,13 +2915,13 @@ var isMetaChannel = (c) => c.kind === "meta_retargeting";
|
|
|
2641
2915
|
var usesPropertyModel = (c) => c.channelGroup !== void 0 || c.audienceRuleRefs.some((ref) => ref.minDaysSinceVisit !== void 0);
|
|
2642
2916
|
function checkAudienceBand(ref, provider = "meta_ads", at = "audienceRuleRef") {
|
|
2643
2917
|
const min = ref.minDaysSinceVisit;
|
|
2644
|
-
if (min !== void 0 && min >= ref.retentionDays)
|
|
2918
|
+
if (min !== void 0 && min >= ref.retentionDays) fail3(at + ".minDaysSinceVisit", "must be shorter than the retention window");
|
|
2645
2919
|
if (provider === "google_ads") {
|
|
2646
|
-
if (min !== void 0)
|
|
2920
|
+
if (min !== void 0) fail3(at + ".minDaysSinceVisit", "Google audiences have no recency band");
|
|
2647
2921
|
return;
|
|
2648
2922
|
}
|
|
2649
|
-
if (ref.retentionDays > META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS)
|
|
2650
|
-
if (1 + ref.exclusionRuleIds.length + (min === void 0 ? 0 : 1) > META_AUDIENCE_RULE_LIMIT)
|
|
2923
|
+
if (ref.retentionDays > META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS) fail3(at + ".retentionDays", `exceeds the ${META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS}-day Meta website audience maximum`);
|
|
2924
|
+
if (1 + ref.exclusionRuleIds.length + (min === void 0 ? 0 : 1) > META_AUDIENCE_RULE_LIMIT) fail3(at + ".exclusionRuleIds", `a Meta audience holds at most ${META_AUDIENCE_RULE_LIMIT} rules including the page and any recency band`);
|
|
2651
2925
|
}
|
|
2652
2926
|
function checkMetaAudienceBands(channel2, at) {
|
|
2653
2927
|
if (!usesPropertyModel(channel2)) return;
|
|
@@ -2659,25 +2933,25 @@ function checkChannelGroups(channels) {
|
|
|
2659
2933
|
for (const c of channels) if (isMetaChannel(c) && c.channelGroup) groups.set(c.channelGroup.key, [...groups.get(c.channelGroup.key) ?? [], c]);
|
|
2660
2934
|
for (const [key, members] of groups) {
|
|
2661
2935
|
const at = `campaign.channelGroup.${key}`;
|
|
2662
|
-
if (members.length > RESONANCE_MAX_CHANNELS_PER_GROUP)
|
|
2936
|
+
if (members.length > RESONANCE_MAX_CHANNELS_PER_GROUP) fail3(at, `at most ${RESONANCE_MAX_CHANNELS_PER_GROUP} channels per group`);
|
|
2663
2937
|
const first = members[0];
|
|
2664
2938
|
const shared = (c) => canonical([c.site, c.accountBindingId, c.datasetRef.id, c.pageRef, c.instagramRef, c.specialCategories, c.countryCodes, c.objective, c.optimization]);
|
|
2665
2939
|
const identity = /* @__PURE__ */ new Set(), destinationOf = /* @__PURE__ */ new Map(), propertyOfDestination = /* @__PURE__ */ new Map();
|
|
2666
2940
|
for (const c of members) {
|
|
2667
|
-
if (shared(c) !== shared(first))
|
|
2668
|
-
if (c.specialCategories.length > 0 && c.ageConstraint?.mode !== "provider_managed")
|
|
2669
|
-
const pk = (c.property ??
|
|
2670
|
-
if (identity.has(id))
|
|
2941
|
+
if (shared(c) !== shared(first)) fail3(at, "channels in one group must share site, account, dataset, Page, categories, countries, objective and optimization");
|
|
2942
|
+
if (c.specialCategories.length > 0 && c.ageConstraint?.mode !== "provider_managed") fail3(at + ".ageConstraint", "a special category requires provider-managed age");
|
|
2943
|
+
const pk = (c.property ?? fail3(at + ".property", "a grouped channel names its property")).key, tier = c.tier?.label ?? "", id = `${pk}|${tier}`;
|
|
2944
|
+
if (identity.has(id)) fail3(at + ".property", "two channels share one property and tier");
|
|
2671
2945
|
identity.add(id);
|
|
2672
|
-
if (destinationOf.has(pk) && destinationOf.get(pk) !== c.destinationId)
|
|
2946
|
+
if (destinationOf.has(pk) && destinationOf.get(pk) !== c.destinationId) fail3(at + ".destinationId", "channels for one property share one destination");
|
|
2673
2947
|
destinationOf.set(pk, c.destinationId);
|
|
2674
2948
|
const other = propertyOfDestination.get(c.destinationId);
|
|
2675
|
-
if (other !== void 0 && other !== pk)
|
|
2949
|
+
if (other !== void 0 && other !== pk) fail3(at + ".destinationId", "channels for different properties have different destinations");
|
|
2676
2950
|
propertyOfDestination.set(c.destinationId, pk);
|
|
2677
2951
|
}
|
|
2678
2952
|
for (let i = 0; i < members.length; i++) for (let j = i + 1; j < members.length; j++) {
|
|
2679
2953
|
if (members[i].property?.key !== members[j].property?.key) continue;
|
|
2680
|
-
for (const a of members[i].audienceRuleRefs) for (const b of members[j].audienceRuleRefs) if (bandsOverlap(a, b))
|
|
2954
|
+
for (const a of members[i].audienceRuleRefs) for (const b of members[j].audienceRuleRefs) if (bandsOverlap(a, b)) fail3(at + ".audienceRuleRefs", "tiers of one property cannot overlap in time");
|
|
2681
2955
|
}
|
|
2682
2956
|
}
|
|
2683
2957
|
}
|
|
@@ -2685,14 +2959,14 @@ function checkGroupedAllocations(v) {
|
|
|
2685
2959
|
if (!v.channels.some((c) => isMetaChannel(c) && c.channelGroup)) return;
|
|
2686
2960
|
let sum = 0n;
|
|
2687
2961
|
for (const c of v.channels) if ("allocation" in c) sum += BigInt(c.allocation.amountMicros);
|
|
2688
|
-
if (sum > BigInt(v.budget.total.amountMicros) - BigInt(v.budget.reserveMargin.amountMicros))
|
|
2962
|
+
if (sum > BigInt(v.budget.total.amountMicros) - BigInt(v.budget.reserveMargin.amountMicros)) fail3("campaign.channels.allocation", "channel allocations exceed the campaign total less its reserve");
|
|
2689
2963
|
}
|
|
2690
2964
|
function splitBudget(total, weights, quantumMicros) {
|
|
2691
2965
|
const t = parseMoney(total), at = "splitBudget";
|
|
2692
|
-
if (!/^[1-9][0-9]{0,29}$/.test(quantumMicros))
|
|
2693
|
-
if (weights.length < 1 || weights.length > 100 || weights.some((w) => !Number.isSafeInteger(w) || w < 1))
|
|
2966
|
+
if (!/^[1-9][0-9]{0,29}$/.test(quantumMicros)) fail3(at + ".quantumMicros", "must be a positive whole number of micros");
|
|
2967
|
+
if (weights.length < 1 || weights.length > 100 || weights.some((w) => !Number.isSafeInteger(w) || w < 1)) fail3(at + ".weights", "one to 100 positive whole weights");
|
|
2694
2968
|
const quantum = BigInt(quantumMicros), micros = BigInt(t.amountMicros);
|
|
2695
|
-
if (micros % quantum !== 0n)
|
|
2969
|
+
if (micros % quantum !== 0n) fail3(at + ".total", "must be a whole number of provider quanta");
|
|
2696
2970
|
const units = micros / quantum, sum = weights.reduce((a, w) => a + BigInt(w), 0n);
|
|
2697
2971
|
const parts = weights.map((w, index) => ({ index, floor: units * BigInt(w) / sum, rest: units * BigInt(w) % sum }));
|
|
2698
2972
|
let left = units - parts.reduce((a, p) => a + p.floor, 0n);
|
|
@@ -2707,8 +2981,8 @@ function splitBudget(total, weights, quantumMicros) {
|
|
|
2707
2981
|
}
|
|
2708
2982
|
function suggestPropertyWeights(visitors, bounds = {}) {
|
|
2709
2983
|
const floor = bounds.floorBasisPoints ?? 1e3, ceiling = bounds.ceilingBasisPoints ?? 4e3, n = visitors.length, at = "suggestPropertyWeights";
|
|
2710
|
-
if (n < 1 || n > 100 || visitors.some((v) => !Number.isSafeInteger(v) || v < 0))
|
|
2711
|
-
if (!Number.isInteger(floor) || !Number.isInteger(ceiling) || floor < 0 || ceiling > 1e4 || floor > ceiling || n * floor > 1e4 || n * ceiling < 1e4)
|
|
2984
|
+
if (n < 1 || n > 100 || visitors.some((v) => !Number.isSafeInteger(v) || v < 0)) fail3(at + ".visitors", "one to 100 whole, non-negative visitor counts");
|
|
2985
|
+
if (!Number.isInteger(floor) || !Number.isInteger(ceiling) || floor < 0 || ceiling > 1e4 || floor > ceiling || n * floor > 1e4 || n * ceiling < 1e4) fail3(at + ".bounds", "floor and ceiling cannot hold every share");
|
|
2712
2986
|
const weight = visitors.map((v) => v + 1);
|
|
2713
2987
|
const total = (lambda) => weight.reduce((a, w) => a + Math.min(ceiling, Math.max(floor, lambda * w)), 0);
|
|
2714
2988
|
let low = 0, high = ceiling / Math.min(...weight) + 1;
|
|
@@ -2745,7 +3019,7 @@ var clip = (value, max) => value.length <= max ? value : value.slice(0, max);
|
|
|
2745
3019
|
function expandPropertyChannels(definition2, groupKey, additions, options) {
|
|
2746
3020
|
const at = "expandPropertyChannels";
|
|
2747
3021
|
const group = definition2.channels.filter((c) => isMetaChannel(c) && c.channelGroup?.key === groupKey);
|
|
2748
|
-
if (!group.length)
|
|
3022
|
+
if (!group.length) fail3(at + ".group", "needs an existing property channel to use as the template");
|
|
2749
3023
|
const template = group[0];
|
|
2750
3024
|
const present = new Set(group.map((c) => c.property?.key));
|
|
2751
3025
|
const keys = additions.map((a) => a.key);
|
|
@@ -2829,4 +3103,4 @@ function deriveProviderRatios(items) {
|
|
|
2829
3103
|
return { frequency, costPerResult, reasonCodes: reasons };
|
|
2830
3104
|
}
|
|
2831
3105
|
|
|
2832
|
-
export { MAX_MONEY_MICROS, META_AUDIENCE_RULE_LIMIT, META_CALL_TO_ACTIONS, META_SAC_CUSTOM_AUDIENCE_EXCLUSION_VERIFIED, META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS, MONEY_EXPONENT, MONEY_JSON_SCHEMA, RESONANCE_ACCEPT_COMMAND_JSON_SCHEMA, RESONANCE_ACCOUNT_CAPABILITY_JSON_SCHEMA, RESONANCE_ATTRIBUTION_MODEL, RESONANCE_AUDIENCE_DRAFT_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_AUDIENCE_RULE_REF_JSON_SCHEMA, RESONANCE_BINDING_COMMAND_JSON_SCHEMA, RESONANCE_CAMPAIGN_DEFINITION_JSON_SCHEMA, RESONANCE_CAMPAIGN_DRAFT_JSON_SCHEMA, RESONANCE_CAMPAIGN_VIEW_JSON_SCHEMA, RESONANCE_CLICK_IDENTIFIERS_JSON_SCHEMA, RESONANCE_COMMAND_JSON_SCHEMA, RESONANCE_COMMAND_PREPARE_REQUEST_JSON_SCHEMA, RESONANCE_COMMAND_PREPARE_RESPONSE_JSON_SCHEMA, RESONANCE_CONSENT_JSON_SCHEMA, RESONANCE_CONSENT_RESPONSE_JSON_SCHEMA, RESONANCE_CONSENT_UPDATE_JSON_SCHEMA, RESONANCE_CONVERSION_JSON_SCHEMA, RESONANCE_CPQL_UNCERTAINTY_METHOD, RESONANCE_CURRENCIES, RESONANCE_EXPERIMENT_COMPLETE_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_CREATE_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_LIFECYCLE_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_LINK_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_REF_JSON_SCHEMA, RESONANCE_EXPERIMENT_UPDATE_COMMAND_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_REVIEW_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_SNAPSHOT_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_VIEW_JSON_SCHEMA, RESONANCE_GOOGLE_CONTENT_UPDATE_JSON_SCHEMA, RESONANCE_GOOGLE_CONTENT_UPDATE_SELECTION_JSON_SCHEMA, RESONANCE_GOOGLE_SETUP_SPEC_JSON_SCHEMA, RESONANCE_GOOGLE_SIGNAL_SEMANTICS, RESONANCE_GOOGLE_SOURCE_CATEGORIES, RESONANCE_MANDATE_ACTION_KIND, RESONANCE_MANDATE_APPROVAL_JSON_SCHEMA, RESONANCE_MANDATE_DRAFT_REQUEST_JSON_SCHEMA, RESONANCE_MANDATE_REF_JSON_SCHEMA, RESONANCE_MANDATE_SCOPE_JSON_SCHEMA, RESONANCE_MANDATE_TARGET_JSON_SCHEMA, RESONANCE_MAX_CHANNELS_PER_GROUP, RESONANCE_MEASUREMENT_CONFIGURATION_CURRENT_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIGURATION_SNAPSHOT_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIG_JSON_SCHEMA, RESONANCE_MEASUREMENT_OCCURRENCE_JSON_SCHEMA, RESONANCE_META_AUDIENCE_REASONS, RESONANCE_META_AUDIENCE_SETUP_LIST_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_PREPARE_REQUEST_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_READINESS_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_RECEIPT_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_REVIEW_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_STATUS_JSON_SCHEMA, RESONANCE_META_AUDIENCE_VERDICTS, RESONANCE_META_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_META_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA, RESONANCE_META_CONFIGURATION_SNAPSHOT_JSON_SCHEMA, RESONANCE_META_CONFIGURATION_VIEW_JSON_SCHEMA, RESONANCE_META_DATASET_NAME_MAX_LENGTH, RESONANCE_META_DATASET_SELECTION_REQUEST_JSON_SCHEMA, RESONANCE_META_DATASET_SELECTION_WITNESS_JSON_SCHEMA, RESONANCE_META_DATASET_SETUP_PREPARE_REQUEST_JSON_SCHEMA, RESONANCE_META_DATASET_SETUP_RECEIPT_JSON_SCHEMA, RESONANCE_META_DATASET_SETUP_REVIEW_JSON_SCHEMA, RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS, RESONANCE_META_RETARGETING_READINESS_JSON_SCHEMA, RESONANCE_METRIC_JSON_SCHEMA, RESONANCE_OBSERVATIONS_PAGE_JSON_SCHEMA, RESONANCE_OBSERVATION_SUPPORT_JSON_SCHEMA, RESONANCE_OCCURRENCE_RESPONSE_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_BASE_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_REF_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_SELECTION_JSON_SCHEMA, RESONANCE_OPTIMIZATION_DECISION_JSON_SCHEMA, RESONANCE_OPTIMIZATION_EVIDENCE_JSON_SCHEMA, RESONANCE_OPTIMIZATION_POLICY_JSON_SCHEMA, RESONANCE_POSITIONING_APPLY_REQUEST_JSON_SCHEMA, RESONANCE_POSITIONING_CONSISTENCY_ASSESSMENT_JSON_SCHEMA, RESONANCE_POSITIONING_CONTEXT_JSON_SCHEMA, RESONANCE_POSITIONING_METHOD_VERSION, RESONANCE_POSITIONING_PREVIEW_JSON_SCHEMA, RESONANCE_POSITIONING_PREVIEW_REQUEST_JSON_SCHEMA, RESONANCE_POSITIONING_RESULT_JSON_SCHEMA, RESONANCE_PREPARED_PLAN_JSON_SCHEMA, RESONANCE_PROVIDER_METRIC_NAMES, RESONANCE_PROVIDER_REPORTING_GRANT_JSON_SCHEMA, RESONANCE_PROVIDER_REPORTING_MAX_TAIL_DAYS, RESONANCE_PROVIDER_REPORTING_SELECTION_JSON_SCHEMA, RESONANCE_PUBLIC_OBSERVATION_METRIC_JSON_SCHEMA, RESONANCE_QUALIFICATION_RULE_JSON_SCHEMA, RESONANCE_RECEIPT_JSON_SCHEMA, RESONANCE_RESOLVED_QUALIFICATION_RULE_JSON_SCHEMA, RESONANCE_RESOURCE_REF_JSON_SCHEMA, RESONANCE_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_SCHEMA_VERSION, RESONANCE_SOURCE_MARKER_JSON_SCHEMA, RESONANCE_SOURCE_MARKER_PARAMETER, RESONANCE_SUBJECT_HEADER, RESONANCE_SUBJECT_RENEW_COMMAND_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_FEED_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_FEED_REVIEW_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_PROFILE, RESONANCE_WEBSITE_VISIT_SETUP_DELIVERY_COMMAND_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_SETUP_GRANT_ACCEPTED_VISITS_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_SETUP_GRANT_PROOF_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_SETUP_GRANT_STATUS_JSON_SCHEMA, ResonanceValidationError, addMoney, checkAudienceBand, checkChannelGroups, compareMoney, cpqlMissingOutcomeBound, deriveProviderRatios, expandPropertyChannels, formatMoney, googleConversionActionSemantics, googleUploadClicksSetupSemantics, metaExclusionPolicy, moneyFromProviderUnits, moneyToProviderUnits, normalizeResonanceGoogleCriterionText, parseMoney, parseResonanceAcceptCommand, parseResonanceAccountCapability, parseResonanceAudienceDraftSaveCommand, parseResonanceAudienceRuleRef, parseResonanceBindingCommand, parseResonanceCampaignDefinition, parseResonanceCampaignDraft, parseResonanceCampaignSaveCommand, parseResonanceCampaignView, parseResonanceClickIdentifiers, parseResonanceCommand, parseResonanceCommandPrepareRequest, parseResonanceCommandPrepareResponse, parseResonanceConsentResponse, parseResonanceConsentSnapshot, parseResonanceConsentUpdate, parseResonanceConversionEnvelope, parseResonanceExperimentCompleteCommand, parseResonanceExperimentCreateCommand, parseResonanceExperimentExposure, parseResonanceExperimentLifecycleCommand, parseResonanceExperimentLinkCommand, parseResonanceExperimentRef, parseResonanceExperimentUpdateCommand, parseResonanceGoogleConfigurationReview, parseResonanceGoogleConfigurationSaveCommand, parseResonanceGoogleConfigurationSaveResponse, parseResonanceGoogleConfigurationSnapshot, parseResonanceGoogleConfigurationView, parseResonanceGoogleContentUpdate, parseResonanceGoogleContentUpdateSelection, parseResonanceGoogleUploadClicksCustomGoalSpec, parseResonanceMandateApprovalPayload, parseResonanceMandateDraftRequest, parseResonanceMandateRef, parseResonanceMandateScope, parseResonanceMandateTarget, parseResonanceMeasurementConfig, parseResonanceMeasurementConfigurationCurrent, parseResonanceMeasurementConfigurationSaveCommand, parseResonanceMeasurementConfigurationSaveResponse, parseResonanceMeasurementConfigurationSnapshot, parseResonanceMeasurementOccurrence, parseResonanceMetaAudienceSetupIntent, parseResonanceMetaAudienceSetupList, parseResonanceMetaAudienceSetupPrepareRequest, parseResonanceMetaAudienceSetupReadiness, parseResonanceMetaAudienceSetupReceipt, parseResonanceMetaAudienceSetupReview, parseResonanceMetaAudienceSetupStatus, parseResonanceMetaConfigurationSaveCommand, parseResonanceMetaConfigurationSaveResponse, parseResonanceMetaConfigurationSnapshot, parseResonanceMetaConfigurationView, parseResonanceMetaDatasetName, parseResonanceMetaDatasetSelectionRequest, parseResonanceMetaDatasetSelectionWitness, parseResonanceMetaDatasetSetupIntent, parseResonanceMetaDatasetSetupPrepareRequest, parseResonanceMetaDatasetSetupReceipt, parseResonanceMetaDatasetSetupReview, parseResonanceMetaRetargetingReadiness, parseResonanceMetricObservation, parseResonanceObservationSupport, parseResonanceObservationsPage, parseResonanceOccurrenceResponse, parseResonanceOperatingPolicy, parseResonanceOperatingPolicyBase, parseResonanceOperatingPolicyRef, parseResonanceOperatingPolicySelection, parseResonanceOptimizationDecision, parseResonanceOptimizationEvidence, parseResonanceOptimizationPolicy, parseResonancePositioningApplyRequest, parseResonancePositioningConsistencyAssessment, parseResonancePositioningContext, parseResonancePositioningPreview, parseResonancePositioningPreviewRequest, parseResonancePositioningResult, parseResonancePrepareCommand, parseResonancePreparedPlan, parseResonanceProviderReportingGrant, parseResonanceProviderReportingSelection, parseResonancePublicObservationMetric, parseResonanceQualificationRule, parseResonanceReceipt, parseResonanceResolvedQualificationRule, parseResonanceResourceRef, parseResonanceSourceMarker, parseResonanceSubjectRenewCommand, parseResonanceWebsiteVisitFeedReview, parseResonanceWebsiteVisitSetupDeliveryCommand, parseResonanceWebsiteVisitSetupGrant, parseResonanceWebsiteVisitSetupGrantAcceptedVisits, parseResonanceWebsiteVisitSetupGrantProof, parseResonanceWebsiteVisitSetupGrantStatus, parseResonanceWebsiteVisitSetupOrigin, projectResonanceGoogleConfiguration, projectResonanceMeasurementConfiguration, projectResonanceMetaConfiguration, projectResonancePositioningConsistencyEvidence, reportedCpqlMissingOutcomeBound, resonanceCommandDigestInput, resonanceGoogleConfigurationDigestInput, resonanceGoogleSetupDigestInput, resonanceMandateDigestInput, resonanceMeasurementConfigDigestInput, resonanceMeasurementConfigurationSaveDigestInput, resonanceMetaAudienceSetupDigestInput, resonanceMetaAudienceSetupReceiptDigestInput, resonanceMetaConfigurationDigestInput, resonanceMetaConfigurationSaveDigestInput, resonanceMetaDatasetSetupDigestInput, resonanceOperatingPolicyActionDigestInput, resonanceOperatingPolicyDigestInput, resonanceOptimizationDecisionDigestInput, resonanceOptimizationEvidenceDigestInput, resonanceOptimizationPolicyDigestInput, resonancePlanIssues, resonancePositioningConsistencyEvidenceDigestInput, resonancePositioningContextDigestInput, resonancePositioningEvidenceDigestInput, resonancePositioningResultDigestInput, resonanceWebsiteVisitEventTime, resonanceWebsiteVisitProfileDigestInput, resonanceWebsiteVisitSetupDeliveryDigestInput, resonanceWebsiteVisitSetupEventTime, splitBudget, subtractMoney, suggestPropertyWeights };
|
|
3106
|
+
export { MAX_MONEY_MICROS, META_AUDIENCE_RULE_LIMIT, META_CALL_TO_ACTIONS, META_SAC_CUSTOM_AUDIENCE_EXCLUSION_VERIFIED, META_WEBSITE_AUDIENCE_MAX_RETENTION_DAYS, MONEY_EXPONENT, MONEY_JSON_SCHEMA, NATIVE_CAS_TIMESTAMP_JSON_SCHEMA, NativeCasTimestampValidationError, RESONANCE_ACCEPT_COMMAND_JSON_SCHEMA, RESONANCE_ACCOUNT_CAPABILITY_JSON_SCHEMA, RESONANCE_ATTRIBUTION_MODEL, RESONANCE_AUDIENCE_DRAFT_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_AUDIENCE_RULE_REF_JSON_SCHEMA, RESONANCE_BINDING_COMMAND_JSON_SCHEMA, RESONANCE_CAMPAIGN_DEFINITION_JSON_SCHEMA, RESONANCE_CAMPAIGN_DRAFT_JSON_SCHEMA, RESONANCE_CAMPAIGN_VIEW_JSON_SCHEMA, RESONANCE_CLICK_IDENTIFIERS_JSON_SCHEMA, RESONANCE_COMMAND_JSON_SCHEMA, RESONANCE_COMMAND_PREPARE_REQUEST_JSON_SCHEMA, RESONANCE_COMMAND_PREPARE_RESPONSE_JSON_SCHEMA, RESONANCE_CONSENT_JSON_SCHEMA, RESONANCE_CONSENT_RESPONSE_JSON_SCHEMA, RESONANCE_CONSENT_UPDATE_JSON_SCHEMA, RESONANCE_CONVERSION_JSON_SCHEMA, RESONANCE_CPQL_UNCERTAINTY_METHOD, RESONANCE_CURRENCIES, RESONANCE_EXPERIMENT_COMPLETE_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_CREATE_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_LIFECYCLE_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_LINK_COMMAND_JSON_SCHEMA, RESONANCE_EXPERIMENT_REF_JSON_SCHEMA, RESONANCE_EXPERIMENT_UPDATE_COMMAND_JSON_SCHEMA, RESONANCE_GOOGLE_CAMPAIGN_DIAGNOSTICS_PAYLOAD_JSON_SCHEMA, RESONANCE_GOOGLE_CAMPAIGN_DIAGNOSTICS_REPORT_JSON_SCHEMA, RESONANCE_GOOGLE_CAMPAIGN_DIAGNOSTICS_REQUEST_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_REVIEW_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_SNAPSHOT_JSON_SCHEMA, RESONANCE_GOOGLE_CONFIGURATION_VIEW_JSON_SCHEMA, RESONANCE_GOOGLE_CONTENT_UPDATE_JSON_SCHEMA, RESONANCE_GOOGLE_CONTENT_UPDATE_SELECTION_JSON_SCHEMA, RESONANCE_GOOGLE_DIAGNOSTICS_SECTIONS, RESONANCE_GOOGLE_SETUP_SPEC_JSON_SCHEMA, RESONANCE_GOOGLE_SIGNAL_SEMANTICS, RESONANCE_GOOGLE_SOURCE_CATEGORIES, RESONANCE_MANDATE_ACTION_KIND, RESONANCE_MANDATE_APPROVAL_JSON_SCHEMA, RESONANCE_MANDATE_DRAFT_REQUEST_JSON_SCHEMA, RESONANCE_MANDATE_REF_JSON_SCHEMA, RESONANCE_MANDATE_SCOPE_JSON_SCHEMA, RESONANCE_MANDATE_TARGET_JSON_SCHEMA, RESONANCE_MAX_CHANNELS_PER_GROUP, RESONANCE_MEASUREMENT_CONFIGURATION_CURRENT_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIGURATION_SNAPSHOT_JSON_SCHEMA, RESONANCE_MEASUREMENT_CONFIG_JSON_SCHEMA, RESONANCE_MEASUREMENT_OCCURRENCE_JSON_SCHEMA, RESONANCE_META_AUDIENCE_REASONS, RESONANCE_META_AUDIENCE_SETUP_LIST_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_PREPARE_REQUEST_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_READINESS_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_RECEIPT_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_REVIEW_JSON_SCHEMA, RESONANCE_META_AUDIENCE_SETUP_STATUS_JSON_SCHEMA, RESONANCE_META_AUDIENCE_VERDICTS, RESONANCE_META_CONFIGURATION_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_META_CONFIGURATION_SAVE_RESPONSE_JSON_SCHEMA, RESONANCE_META_CONFIGURATION_SNAPSHOT_JSON_SCHEMA, RESONANCE_META_CONFIGURATION_VIEW_JSON_SCHEMA, RESONANCE_META_DATASET_NAME_MAX_LENGTH, RESONANCE_META_DATASET_SELECTION_REQUEST_JSON_SCHEMA, RESONANCE_META_DATASET_SELECTION_WITNESS_JSON_SCHEMA, RESONANCE_META_DATASET_SETUP_PREPARE_REQUEST_JSON_SCHEMA, RESONANCE_META_DATASET_SETUP_RECEIPT_JSON_SCHEMA, RESONANCE_META_DATASET_SETUP_REVIEW_JSON_SCHEMA, RESONANCE_META_QUERY_ATTRIBUTION_WINDOWS, RESONANCE_META_RETARGETING_READINESS_JSON_SCHEMA, RESONANCE_METRIC_JSON_SCHEMA, RESONANCE_OBSERVATIONS_PAGE_JSON_SCHEMA, RESONANCE_OBSERVATION_SUPPORT_JSON_SCHEMA, RESONANCE_OCCURRENCE_RESPONSE_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_BASE_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_REF_JSON_SCHEMA, RESONANCE_OPERATING_POLICY_SELECTION_JSON_SCHEMA, RESONANCE_OPTIMIZATION_DECISION_JSON_SCHEMA, RESONANCE_OPTIMIZATION_EVIDENCE_JSON_SCHEMA, RESONANCE_OPTIMIZATION_POLICY_JSON_SCHEMA, RESONANCE_POSITIONING_APPLY_REQUEST_JSON_SCHEMA, RESONANCE_POSITIONING_CONSISTENCY_ASSESSMENT_JSON_SCHEMA, RESONANCE_POSITIONING_CONTEXT_JSON_SCHEMA, RESONANCE_POSITIONING_METHOD_VERSION, RESONANCE_POSITIONING_PREVIEW_JSON_SCHEMA, RESONANCE_POSITIONING_PREVIEW_REQUEST_JSON_SCHEMA, RESONANCE_POSITIONING_RESULT_JSON_SCHEMA, RESONANCE_PREPARATION_LOOKUP_REQUEST_JSON_SCHEMA, RESONANCE_PREPARATION_LOOKUP_RESPONSE_JSON_SCHEMA, RESONANCE_PREPARATION_RETIRE_REQUEST_JSON_SCHEMA, RESONANCE_PREPARATION_RETIRE_RESPONSE_JSON_SCHEMA, RESONANCE_PREPARED_PLAN_JSON_SCHEMA, RESONANCE_PROVIDER_METRIC_NAMES, RESONANCE_PROVIDER_REPORTING_GRANT_JSON_SCHEMA, RESONANCE_PROVIDER_REPORTING_MAX_TAIL_DAYS, RESONANCE_PROVIDER_REPORTING_SELECTION_JSON_SCHEMA, RESONANCE_PUBLIC_OBSERVATION_METRIC_JSON_SCHEMA, RESONANCE_QUALIFICATION_RULE_JSON_SCHEMA, RESONANCE_RECEIPT_JSON_SCHEMA, RESONANCE_RESOLVED_QUALIFICATION_RULE_JSON_SCHEMA, RESONANCE_RESOURCE_REF_JSON_SCHEMA, RESONANCE_SAVE_COMMAND_JSON_SCHEMA, RESONANCE_SCHEMA_VERSION, RESONANCE_SOURCE_MARKER_JSON_SCHEMA, RESONANCE_SOURCE_MARKER_PARAMETER, RESONANCE_SUBJECT_HEADER, RESONANCE_SUBJECT_RENEW_COMMAND_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_FEED_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_FEED_REVIEW_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_PROFILE, RESONANCE_WEBSITE_VISIT_SETUP_DELIVERY_COMMAND_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_SETUP_GRANT_ACCEPTED_VISITS_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_SETUP_GRANT_PROOF_JSON_SCHEMA, RESONANCE_WEBSITE_VISIT_SETUP_GRANT_STATUS_JSON_SCHEMA, ResonanceValidationError, addMoney, checkAudienceBand, checkChannelGroups, compareMoney, cpqlMissingOutcomeBound, deriveProviderRatios, expandPropertyChannels, formatMoney, googleConversionActionSemantics, googleUploadClicksSetupSemantics, metaExclusionPolicy, moneyFromProviderUnits, moneyToProviderUnits, normalizeResonanceGoogleCriterionText, parseMoney, parseNativeCasTimestamp, parseResonanceAcceptCommand, parseResonanceAccountCapability, parseResonanceAudienceDraftSaveCommand, parseResonanceAudienceRuleRef, parseResonanceBindingCommand, parseResonanceCampaignDefinition, parseResonanceCampaignDraft, parseResonanceCampaignSaveCommand, parseResonanceCampaignView, parseResonanceClickIdentifiers, parseResonanceCommand, parseResonanceCommandPrepareRequest, parseResonanceCommandPrepareResponse, parseResonanceConsentResponse, parseResonanceConsentSnapshot, parseResonanceConsentUpdate, parseResonanceConversionEnvelope, parseResonanceExperimentCompleteCommand, parseResonanceExperimentCreateCommand, parseResonanceExperimentExposure, parseResonanceExperimentLifecycleCommand, parseResonanceExperimentLinkCommand, parseResonanceExperimentRef, parseResonanceExperimentUpdateCommand, parseResonanceGoogleCampaignDiagnosticsPayload, parseResonanceGoogleCampaignDiagnosticsReport, parseResonanceGoogleCampaignDiagnosticsRequest, parseResonanceGoogleConfigurationReview, parseResonanceGoogleConfigurationSaveCommand, parseResonanceGoogleConfigurationSaveResponse, parseResonanceGoogleConfigurationSnapshot, parseResonanceGoogleConfigurationView, parseResonanceGoogleContentUpdate, parseResonanceGoogleContentUpdateSelection, parseResonanceGoogleUploadClicksCustomGoalSpec, parseResonanceMandateApprovalPayload, parseResonanceMandateDraftRequest, parseResonanceMandateRef, parseResonanceMandateScope, parseResonanceMandateTarget, parseResonanceMeasurementConfig, parseResonanceMeasurementConfigurationCurrent, parseResonanceMeasurementConfigurationSaveCommand, parseResonanceMeasurementConfigurationSaveResponse, parseResonanceMeasurementConfigurationSnapshot, parseResonanceMeasurementOccurrence, parseResonanceMetaAudienceSetupIntent, parseResonanceMetaAudienceSetupList, parseResonanceMetaAudienceSetupPrepareRequest, parseResonanceMetaAudienceSetupReadiness, parseResonanceMetaAudienceSetupReceipt, parseResonanceMetaAudienceSetupReview, parseResonanceMetaAudienceSetupStatus, parseResonanceMetaConfigurationSaveCommand, parseResonanceMetaConfigurationSaveResponse, parseResonanceMetaConfigurationSnapshot, parseResonanceMetaConfigurationView, parseResonanceMetaDatasetName, parseResonanceMetaDatasetSelectionRequest, parseResonanceMetaDatasetSelectionWitness, parseResonanceMetaDatasetSetupIntent, parseResonanceMetaDatasetSetupPrepareRequest, parseResonanceMetaDatasetSetupReceipt, parseResonanceMetaDatasetSetupReview, parseResonanceMetaRetargetingReadiness, parseResonanceMetricObservation, parseResonanceObservationSupport, parseResonanceObservationsPage, parseResonanceOccurrenceResponse, parseResonanceOperatingPolicy, parseResonanceOperatingPolicyBase, parseResonanceOperatingPolicyRef, parseResonanceOperatingPolicySelection, parseResonanceOptimizationDecision, parseResonanceOptimizationEvidence, parseResonanceOptimizationPolicy, parseResonancePositioningApplyRequest, parseResonancePositioningConsistencyAssessment, parseResonancePositioningContext, parseResonancePositioningPreview, parseResonancePositioningPreviewRequest, parseResonancePositioningResult, parseResonancePreparationLookupRequest, parseResonancePreparationLookupResponse, parseResonancePreparationRetireRequest, parseResonancePreparationRetireResponse, parseResonancePrepareCommand, parseResonancePreparedPlan, parseResonanceProviderReportingGrant, parseResonanceProviderReportingSelection, parseResonancePublicObservationMetric, parseResonanceQualificationRule, parseResonanceReceipt, parseResonanceResolvedQualificationRule, parseResonanceResourceRef, parseResonanceSourceMarker, parseResonanceSubjectRenewCommand, parseResonanceWebsiteVisitFeedReview, parseResonanceWebsiteVisitSetupDeliveryCommand, parseResonanceWebsiteVisitSetupGrant, parseResonanceWebsiteVisitSetupGrantAcceptedVisits, parseResonanceWebsiteVisitSetupGrantProof, parseResonanceWebsiteVisitSetupGrantStatus, parseResonanceWebsiteVisitSetupOrigin, projectResonanceGoogleConfiguration, projectResonanceMeasurementConfiguration, projectResonanceMetaConfiguration, projectResonancePositioningConsistencyEvidence, reportedCpqlMissingOutcomeBound, resonanceCommandDigestInput, resonanceGoogleConfigurationDigestInput, resonanceGoogleSetupDigestInput, resonanceMandateDigestInput, resonanceMeasurementConfigDigestInput, resonanceMeasurementConfigurationSaveDigestInput, resonanceMetaAudienceSetupDigestInput, resonanceMetaAudienceSetupReceiptDigestInput, resonanceMetaConfigurationDigestInput, resonanceMetaConfigurationSaveDigestInput, resonanceMetaDatasetSetupDigestInput, resonanceOperatingPolicyActionDigestInput, resonanceOperatingPolicyDigestInput, resonanceOptimizationDecisionDigestInput, resonanceOptimizationEvidenceDigestInput, resonanceOptimizationPolicyDigestInput, resonancePlanIssues, resonancePositioningConsistencyEvidenceDigestInput, resonancePositioningContextDigestInput, resonancePositioningEvidenceDigestInput, resonancePositioningResultDigestInput, resonanceWebsiteVisitEventTime, resonanceWebsiteVisitProfileDigestInput, resonanceWebsiteVisitSetupDeliveryDigestInput, resonanceWebsiteVisitSetupEventTime, splitBudget, subtractMoney, suggestPropertyWeights };
|