Reverse registry sync: push LinkSpin-first members to InstantAdPay (iapsync.js)

Mirror of InstantAdPay's lssync: touch() on account create / username / wallet (incl. admin set) / sponsor / profile
via a new accounts.onChange hook, plus a 2-minute hashed tick, 100 rows per signed POST to IAP_URL/api/partner/registry
with the same LS_SYNC_SECRET. Inert while the secret is missing or short.

Loop guard (documented in the module header): only rows changed since our last push, and never rows the registry
already holds (= what InstantAdPay told us), so the accounts built from the InstantAdPay import are recorded and not
sent. A pushed LinkSpin-first email gets a registry row with firstProperty 'linkspin', and registry.upsert no longer
overwrites an existing firstProperty, so InstantAdPay's echo cannot relabel it.

Also: the inbound InstantAdPay handler binds sponsors in a second pass, so a row that precedes its sponsor's row in the
same batch (newest-first order) is no longer left without a sponsor. Admin: GET /api/admin/iapsync, POST .../run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-15 10:44:54 -05:00
parent baa7db61ff
commit 2e026e1a42
4 changed files with 156 additions and 9 deletions
+5 -1
View File
@@ -23,7 +23,11 @@ const J = {
if (!this.db) this.load();
const e = norm(rec.email); if (!e) return null;
const cur = this.db.byEmail[e] || { email: e, created: Date.now() };
for (const k of ['username', 'wallet', 'sponsorEmail', 'firstProperty', 'joinedAt', 'profile']) if (rec[k] != null && rec[k] !== '') cur[k] = k === 'wallet' || k === 'sponsorEmail' ? norm(rec[k]) : rec[k];
for (const k of ['username', 'wallet', 'sponsorEmail', 'firstProperty', 'joinedAt', 'profile']) {
if (rec[k] == null || rec[k] === '') continue;
if (k === 'firstProperty' && cur.firstProperty) continue; // first contact is history: an InstantAdPay echo of a LinkSpin-first row must not relabel it (2026-10-15)
cur[k] = k === 'wallet' || k === 'sponsorEmail' ? norm(rec[k]) : rec[k];
}
cur.updated = Date.now(); this.db.byEmail[e] = cur; this.save(); return cur;
},
async all() { if (!this.db) this.load(); return Object.values(this.db.byEmail); },