@referalli/cli 0.4.1 → 0.4.3

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 CHANGED
@@ -5,6 +5,15 @@ All notable changes to `@referalli/cli` are recorded here. The format follows
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Before 1.0, a minor
6
6
  bump may include breaking changes; they are called out under **Changed**.
7
7
 
8
+ ## 0.4.3 - 2026-11-04
9
+
10
+ - `doctor` fails an auth connection whose last refused call (`lastError`) is newer than its last sign-up, with the error. It also warns when the org's tracking consent mode is `none` (live keys).
11
+
12
+ ## 0.4.2 - 2026-11-03
13
+
14
+ - Fixed: `plan`/`apply` with a `billingConnections:` list failed with `conns.filter is not a function` (the connections list now arrives in the list envelope).
15
+ - Programs take `publicPage` (`pitch`, `autoApprove`) and `riskPolicy` (`holdBotScore`, `holdRiskScore`, `holdHighRiskLevel`, `holdDisposableEmail`, `holdVelocity`, `holdUnverifiedEmail`, `holdSelfReferral`). Only the keys you list are compared; `apply` merges them into the live settings.
16
+
8
17
  ## 0.4.1 - 2026-11-03
9
18
 
10
19
  - New `env pull [--mode live|test]`: prints one mode's tracking token (`REFERALLI_TRACKING_TOKEN`, `NEXT_PUBLIC_REFERALLI_TRACKING_TOKEN`), aff.js URL, link base and, for the key's own mode, the program id as `.env` lines. Keys are never pulled.
package/dist/src/apply.js CHANGED
@@ -14,7 +14,9 @@ export class ConfigError extends Error {
14
14
  const PROGRAM_TOP = ['name', 'attributionModel', 'cookieWindowDays', 'signupToConversionDays', 'termsMd', 'status', 'publicHandle'];
15
15
  // Program settings: PATCH takes them top-level, GET returns them under `settings`.
16
16
  const PROGRAM_SETTINGS = ['probabilisticPolicy', 'selfReferralPolicy', 'splitCommissions', 'allowPaidSearch', 'challengeLinks', 'settlement'];
17
- const PROGRAM_KEYS = ['slug', ...PROGRAM_TOP, ...PROGRAM_SETTINGS, 'destinationUrl', 'commissionRule', 'stripeCredits'];
17
+ // Mappings merged into what's live: only the keys the file names are compared, and PATCH sends the live block with them applied.
18
+ const PROGRAM_BLOCKS = { publicPage: ['pitch', 'autoApprove'], riskPolicy: ['holdBotScore', 'holdRiskScore', 'holdHighRiskLevel', 'holdDisposableEmail', 'holdVelocity', 'holdUnverifiedEmail', 'holdSelfReferral'] };
19
+ const PROGRAM_KEYS = ['slug', ...PROGRAM_TOP, ...PROGRAM_SETTINGS, ...Object.keys(PROGRAM_BLOCKS), 'destinationUrl', 'commissionRule', 'stripeCredits'];
18
20
  const STRIPE_KEYS = ['enabled', 'referrerMatch', 'metadataKey', 'refereeRewards', 'balanceCurrency', 'createCustomerIfMissing', 'waitForCustomer', 'secretKeyEnv'];
19
21
  const WEBHOOK_KEYS = ['url', 'topics', 'programs', 'status', 'alertContacts'];
20
22
  const API_KEY_KEYS = ['name', 'owner', 'mode', 'scopes', 'expiresInDays', 'programs', 'apiVersion'];
@@ -58,6 +60,13 @@ export function parseConfig(text, file = 'config') {
58
60
  checkKeys(p, PROGRAM_KEYS, where, 'slug');
59
61
  if (p.commissionRule !== undefined && !isObj(p.commissionRule))
60
62
  throw new ConfigError(`${where}.commissionRule: expected a mapping`);
63
+ for (const [block, keys] of Object.entries(PROGRAM_BLOCKS)) {
64
+ if (p[block] === undefined)
65
+ continue;
66
+ if (!isObj(p[block]))
67
+ throw new ConfigError(`${where}.${block}: expected a mapping`);
68
+ checkKeys(p[block], [...keys], `${where}.${block}`);
69
+ }
61
70
  if (p.stripeCredits !== undefined) {
62
71
  checkKeys(p.stripeCredits, STRIPE_KEYS, `${where}.stripeCredits`);
63
72
  if (typeof p.stripeCredits.enabled !== 'boolean')
@@ -141,7 +150,7 @@ export async function buildPlan(client, config, env) {
141
150
  const cur = programs.find((p) => p.slug === spec.slug);
142
151
  const label = `program "${spec.slug}"`;
143
152
  const desired = {};
144
- for (const k of [...PROGRAM_TOP, ...PROGRAM_SETTINGS, 'destinationUrl'])
153
+ for (const k of [...PROGRAM_TOP, ...PROGRAM_SETTINGS, ...Object.keys(PROGRAM_BLOCKS), 'destinationUrl'])
145
154
  if (spec[k] !== undefined)
146
155
  desired[k] = spec[k];
147
156
  if (!cur) {
@@ -163,12 +172,14 @@ export async function buildPlan(client, config, env) {
163
172
  else {
164
173
  const now = (k) => k === 'destinationUrl'
165
174
  ? (cur.settings.widget?.destinationUrl ?? null)
166
- : PROGRAM_SETTINGS.includes(k)
175
+ : PROGRAM_SETTINGS.includes(k) || k === 'riskPolicy'
167
176
  ? cur.settings[k]
168
177
  : cur[k];
178
+ // A block counts as changed only on the keys the file names; the new value is the live block with them applied.
179
+ const want = (k, v) => (k in PROGRAM_BLOCKS ? { ...(now(k) ?? {}), ...v } : v);
169
180
  const fields = Object.entries(desired)
170
- .filter(([k, v]) => !same(now(k), v))
171
- .map(([k, v]) => [k, now(k), v]);
181
+ .filter(([k, v]) => !same(now(k), want(k, v)))
182
+ .map(([k, v]) => [k, now(k), want(k, v)]);
172
183
  const patch = Object.fromEntries(fields.map(([k, , v]) => [k, v]));
173
184
  changes.push({
174
185
  action: fields.length ? 'update' : 'noop',
@@ -308,7 +319,7 @@ export async function buildPlan(client, config, env) {
308
319
  });
309
320
  }
310
321
  if (config.billingConnections.length) {
311
- const conns = await client.request('GET', '/v1/billing/connections');
322
+ const conns = await listAll(client, '/v1/billing/connections');
312
323
  for (const spec of config.billingConnections) {
313
324
  const label = `billingConnection "${spec.name}"`;
314
325
  checkRefs(spec.programs, label);
@@ -100,6 +100,10 @@ async function authChecks(client, now) {
100
100
  if (c.tokenVerification && c.allowedOrigins.length === 0) {
101
101
  return { id, status: 'warn', message: `${label} verifies tokens but has no allowedOrigins: the widget session refuses browsers`, fix: `PATCH /v1/auth/connections/${c.id} {"allowedOrigins":["https://your.app"]}` };
102
102
  }
103
+ // A refusal newer than the last sign-up: the platform is calling, and its calls are failing.
104
+ if (c.lastError && (!c.lastSignupAt || new Date(c.lastError.at) > new Date(c.lastSignupAt))) {
105
+ return { id, status: 'fail', message: `${label} refused its last call (${c.lastError.at}): ${c.lastError.code}: ${c.lastError.message}`, fix: `fix the caller's request body, then retry its failed calls (Atlas: POST /v1/instance/referrals/calls/retry_failed)` };
106
+ }
103
107
  // Protocol connections (Atlas, custom) can't be pinged with an API key: when it last filed a sign-up says it's wired.
104
108
  // undefined: an API from before lastSignupAt, nothing to say.
105
109
  if (c.lastSignupAt === null) {
@@ -130,6 +134,15 @@ async function trackingCheck(client, env) {
130
134
  throw err;
131
135
  out.push({ id: 'tracking', status: 'fail', message: `tracking token ${org.trackingToken} is unknown to /t/…/config.json`, fix: '/settings' });
132
136
  }
137
+ // Consent mode `none` (orgs from before consent support start there): aff.js stores the referral before the visitor chooses.
138
+ if (org.livemode !== false) {
139
+ out.push(...(await guard('tracking.consent', '/settings → Install', async () => {
140
+ const c = await client.request('GET', '/v1/org/tracking-consent');
141
+ return c.mode === 'none'
142
+ ? [{ id: 'tracking.consent', status: 'warn', message: "tracking consent is 'none': aff.js stores the referral before the visitor chooses", fix: `PUT /v1/org/tracking-consent {"mode":"auto"} (or /settings → Install)` }]
143
+ : [{ id: 'tracking.consent', status: 'ok', message: `tracking consent: ${c.mode}` }];
144
+ })));
145
+ }
133
146
  // The token the product is configured with (run doctor with the app's env) must be this mode's.
134
147
  const name = env.REFERALLI_TRACKING_TOKEN ? 'REFERALLI_TRACKING_TOKEN' : env.NEXT_PUBLIC_REFERALLI_TRACKING_TOKEN ? 'NEXT_PUBLIC_REFERALLI_TRACKING_TOKEN' : null;
135
148
  if (!name)
@@ -1,2 +1,2 @@
1
1
  /** Kept in step with package.json by test/version.test.ts. */
2
- export declare const VERSION = "0.4.1";
2
+ export declare const VERSION = "0.4.3";
@@ -1,2 +1,2 @@
1
1
  /** Kept in step with package.json by test/version.test.ts. */
2
- export const VERSION = '0.4.1';
2
+ export const VERSION = '0.4.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@referalli/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "The Referalli command line: sign in, forward webhooks to localhost, trigger test events, tail events and API logs.",
5
5
  "license": "MIT",
6
6
  "type": "module",