@aranova/tracking-react 1.17.0 → 1.18.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/dist/sales.mjs CHANGED
@@ -230,7 +230,6 @@ var jsonValueSchema = z.lazy(
230
230
  ])
231
231
  ).register(z.globalRegistry, { id: "JsonSerializableValue" });
232
232
  var contractNameSchema = z.string().check(z.regex(/^[a-z][a-z0-9_]{0,47}(:[a-z0-9_-]{1,48})?$/));
233
- var contractName = contractNameSchema;
234
233
  var violationRole = z.string().check(
235
234
  z.maxLength(200),
236
235
  z.regex(
@@ -242,38 +241,41 @@ var contractViolationSchema = z.strictObject({
242
241
  role: z.nullable(violationRole),
243
242
  rule: z.string().check(z.regex(/^[a-z][a-z_]{0,47}$/))
244
243
  });
244
+ var formFieldSchema = z.strictObject({
245
+ name: z.string(),
246
+ type: z.string(),
247
+ label: z.nullable(z.string()),
248
+ value: jsonValueSchema,
249
+ role: z.optional(z.nullable(contractNameSchema))
250
+ });
251
+ var formExtraSchema = z.optional(
252
+ z.nullable(
253
+ z.array(
254
+ z.strictObject({
255
+ key: z.string().check(z.maxLength(64)),
256
+ label: z.string().check(z.maxLength(200)),
257
+ value: jsonValueSchema
258
+ })
259
+ ).check(z.maxLength(20))
260
+ )
261
+ );
262
+ var contractVersionSchema = z.optional(z.nullable(z.int().check(z.gte(1))));
263
+ var contractHashSchema = z.optional(z.nullable(z.string().check(z.maxLength(64))));
264
+ var formContractViolationsSchema = z.optional(
265
+ z.nullable(z.array(contractViolationSchema).check(z.maxLength(MAX_CONTRACT_VIOLATIONS)))
266
+ );
245
267
  var formSubmitMetadataSchema = z.strictObject({
246
268
  form: z.strictObject({
247
269
  id: z.string(),
248
270
  action: z.nullable(z.string()),
249
- fields: z.optional(
250
- z.array(
251
- z.strictObject({
252
- name: z.string(),
253
- type: z.string(),
254
- label: z.nullable(z.string()),
255
- value: jsonValueSchema,
256
- role: z.optional(z.nullable(contractName))
257
- })
258
- )
259
- ),
260
- kind: z.optional(z.nullable(contractName)),
261
- contract_version: z.optional(z.nullable(z.int().check(z.gte(1)))),
262
- contract_hash: z.optional(z.nullable(z.string().check(z.maxLength(64)))),
263
- extra: z.optional(
264
- z.nullable(
265
- z.array(
266
- z.strictObject({
267
- key: z.string().check(z.maxLength(64)),
268
- label: z.string().check(z.maxLength(200)),
269
- value: jsonValueSchema
270
- })
271
- ).check(z.maxLength(20))
272
- )
273
- ),
274
- contract_violations: z.optional(
275
- z.nullable(z.array(contractViolationSchema).check(z.maxLength(MAX_CONTRACT_VIOLATIONS)))
276
- )
271
+ fields: z.optional(z.array(formFieldSchema)),
272
+ kind: z.optional(z.nullable(contractNameSchema)),
273
+ contract_version: contractVersionSchema,
274
+ contract_hash: contractHashSchema,
275
+ extra: formExtraSchema,
276
+ contract_violations: formContractViolationsSchema,
277
+ // Minted per submit; a later `form_details` names it to add answers to this lead.
278
+ submission_id: z.optional(z.nullable(z.uuidv4()))
277
279
  }),
278
280
  page: z.strictObject({
279
281
  path: z.string()
@@ -1287,10 +1289,10 @@ var KNOWN_ROLES = new Set(LEAD_FORM_ROLES);
1287
1289
  var ROLE_ORDER = new Map(LEAD_FORM_ROLES.map((role, index) => [role, index]));
1288
1290
  var ADD_ON = /^add_on:[a-z0-9_-]{1,48}$/;
1289
1291
  var CONTRACT_NAME = /^[a-z][a-z0-9_]{0,47}(:[a-z0-9_-]{1,48})?$/;
1290
- function judgeLeadForm(kind, formId, fields, contracts, settings) {
1292
+ function judgeLeadForm(kind, formId, fields, contracts, settings, { partial = false } = {}) {
1291
1293
  const generated = contracts?.contracts[kind];
1292
1294
  const live = liveContract(settings.trackingConfig, kind);
1293
- const violations = check(live === void 0 ? generated : fromLive(live), fields);
1295
+ const violations = check(live === void 0 ? generated : fromLive(live), fields, partial);
1294
1296
  const liveHash = live === void 0 ? void 0 : live?.contract_hash ?? null;
1295
1297
  if (contracts && (liveHash !== void 0 && (generated?.hash ?? null) !== liveHash || contracts.registryVersion !== LEAD_FORM_REGISTRY_VERSION)) {
1296
1298
  violations.push({ role: null, rule: "contract_behind" });
@@ -1322,7 +1324,7 @@ function fromLive(live) {
1322
1324
  options: Object.fromEntries(live.options.map((o) => [o.role, o.options.map((x) => x.key)]))
1323
1325
  };
1324
1326
  }
1325
- function check(contract, fields) {
1327
+ function check(contract, fields, partial) {
1326
1328
  const answered = new Map(fields);
1327
1329
  const violations = [];
1328
1330
  for (const [role, value] of fields) {
@@ -1340,6 +1342,7 @@ function check(contract, fields) {
1340
1342
  violations.push({ role, rule: "unknown_option" });
1341
1343
  }
1342
1344
  }
1345
+ if (partial) return violations;
1343
1346
  for (const { role, requiredWhen } of contract?.requires ?? []) {
1344
1347
  const owing = requiredWhen === null || optionKeys(answered.get(requiredWhen.role)).some((key) => requiredWhen.anyOf.includes(key));
1345
1348
  if (owing && !answered.has(role)) violations.push({ role, rule: "missing_required" });
@@ -2003,12 +2006,15 @@ var zSmsWithheldReason = z4.enum([
2003
2006
  "test_or_bot_session",
2004
2007
  "invalid_phone",
2005
2008
  "recently_texted",
2009
+ "owner_not_alerted",
2010
+ "no_new_details",
2006
2011
  "do_not_contact",
2007
2012
  "do_not_text_tag",
2008
2013
  "missing_value",
2009
2014
  "us_texting_pending",
2010
2015
  "us_texting_rejected",
2011
- "texts_paused"
2016
+ "texts_paused",
2017
+ "outside_nanp"
2012
2018
  ]);
2013
2019
  var zSaleSmsStatusSchema = z4.object({
2014
2020
  can_send_now: z4._default(z4.boolean(), false),