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