@orangecheck/me-client 0.54.0 → 0.55.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/index.mjs CHANGED
@@ -343,14 +343,43 @@ function computeFees(cfg, payment_amount_sats, opts) {
343
343
  const site_rebate_sats = gross - platform_fee_sats - user_earned_sats;
344
344
  return { gross_fee_sats: gross, platform_fee_sats, user_earned_sats, site_rebate_sats };
345
345
  }
346
+ var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
347
+ function siteFeeShapeProblem(v) {
348
+ if (!isRecord(v)) return "must be an object";
349
+ if (v.kind === "fixed_sats") return Number.isFinite(v.sats) ? null : "sats must be a number";
350
+ if (v.kind === "percent_of_amount") {
351
+ return Number.isFinite(v.pct) ? null : "pct must be a number";
352
+ }
353
+ return `kind must be fixed_sats or percent_of_amount (got ${JSON.stringify(v.kind)})`;
354
+ }
355
+ function eventShapeProblem(e) {
356
+ const fee = siteFeeShapeProblem(e.site_pays);
357
+ if (fee) return `site_pays ${fee}`;
358
+ if (!Number.isFinite(e.user_share_pct)) return "user_share_pct must be a number";
359
+ if (e.agent == null) return null;
360
+ if (!isRecord(e.agent)) return "agent must be an object";
361
+ if (e.agent.site_pays != null) {
362
+ const agentFee = siteFeeShapeProblem(e.agent.site_pays);
363
+ if (agentFee) return `agent.site_pays ${agentFee}`;
364
+ }
365
+ if (e.agent.user_share_pct != null && !Number.isFinite(e.agent.user_share_pct)) {
366
+ return "agent.user_share_pct must be a number";
367
+ }
368
+ return null;
369
+ }
346
370
  function validateIntegratorConfig(cfg) {
347
371
  const errors = [];
348
372
  if (!cfg.project_key) errors.push({ message: "project_key is required" });
349
373
  if (!cfg.display_name) errors.push({ message: "display_name is required" });
350
374
  if (!cfg.domain) errors.push({ message: "domain is required" });
351
- for (const [key, eventCfg] of Object.entries(cfg.events)) {
375
+ if (!isRecord(cfg.events)) errors.push({ message: "events must be an object" });
376
+ for (const [key, eventCfg] of Object.entries(isRecord(cfg.events) ? cfg.events : {})) {
352
377
  if (!eventCfg) continue;
353
378
  const subtype = key;
379
+ if (!isRecord(eventCfg)) {
380
+ errors.push({ subtype, message: "must be an object" });
381
+ continue;
382
+ }
354
383
  const builtin = Object.prototype.hasOwnProperty.call(EVENT_SUBTYPES, key);
355
384
  if (!builtin && !CUSTOM_EVENT_KEY_RE.test(key)) {
356
385
  errors.push({
@@ -370,6 +399,11 @@ function validateIntegratorConfig(cfg) {
370
399
  });
371
400
  }
372
401
  if (!eventCfg.enabled) continue;
402
+ const shape = eventShapeProblem(eventCfg);
403
+ if (shape) {
404
+ errors.push({ subtype, message: shape });
405
+ continue;
406
+ }
373
407
  if (eventCfg.site_pays.kind === "fixed_sats") {
374
408
  if (eventCfg.site_pays.sats < MIN_INTEGRATOR_PRICE_SATS) {
375
409
  errors.push({