vibes-diy 14.3.486 → 14.3.487
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/cli/cmd-evento.d.ts +221 -221
- package/cli/cmds/run/backend-worker/run-backend-entry.js +460 -23
- package/cli/cmds/run/bundle-inputs.json +2 -0
- package/cli/cmds/run/run-bundle.js +2843 -2310
- package/package.json +8 -8
|
@@ -36124,7 +36124,8 @@ var init_capi_share_msg = __esm({
|
|
|
36124
36124
|
evtCapiShare = lazyType(
|
|
36125
36125
|
() => type({
|
|
36126
36126
|
type: "'vibes.diy.evt-capi-share'",
|
|
36127
|
-
|
|
36127
|
+
/** `share`, or one of the host-intent steps (owner 2026-12-04); see `CAPI_SHARE_STEPS`. */
|
|
36128
|
+
kind: "'share' | 'shareSheetOpened' | 'shareReach' | 'shareLinkCopied'",
|
|
36128
36129
|
userId: "string > 0",
|
|
36129
36130
|
/** ISO instant the relay enqueued it; the click window is measured from now at handling. */
|
|
36130
36131
|
at: "string"
|
|
@@ -36136,6 +36137,11 @@ var init_capi_share_msg = __esm({
|
|
|
36136
36137
|
openerKey: "string > 0",
|
|
36137
36138
|
"viewerUserId?": "string",
|
|
36138
36139
|
"userAgent?": "string",
|
|
36140
|
+
/**
|
|
36141
|
+
* Chris 2026-12-04: the opener stayed (`friendDwell`) or tapped around the app (`friendExplored`),
|
|
36142
|
+
* on the same open token. Absent is the open itself (`shareOpened`).
|
|
36143
|
+
*/
|
|
36144
|
+
"step?": "'friendDwell' | 'friendExplored'",
|
|
36139
36145
|
at: "string"
|
|
36140
36146
|
})
|
|
36141
36147
|
);
|
|
@@ -36194,16 +36200,28 @@ var init_friend_acted_msg = __esm({
|
|
|
36194
36200
|
evtFriendActed = lazyType(
|
|
36195
36201
|
() => type({
|
|
36196
36202
|
type: "'vibes.diy.evt-friend-acted'",
|
|
36197
|
-
|
|
36203
|
+
/**
|
|
36204
|
+
* `friend-answered` (Chris 2026-12-04): a guest's saved, non-rejected answer that is not the
|
|
36205
|
+
* host's own; the consumer pays the host `friendAnswered` once per invite. It carries the
|
|
36206
|
+
* answer's visitor digest, like `friend-acted`.
|
|
36207
|
+
*/
|
|
36208
|
+
kind: "'host-published' | 'friend-acted' | 'share-acted' | 'friend-answered' | 'friend-step'",
|
|
36198
36209
|
/** The invite; for `share-acted`, the share link id (#11687). */
|
|
36199
36210
|
inviteId: "string > 0",
|
|
36200
|
-
/** The answer's visitor digest; present on `friend-acted`
|
|
36211
|
+
/** The answer's visitor digest; present on `friend-acted`, `friend-answered` and `friend-step`. */
|
|
36201
36212
|
"visitorDigest?": "string",
|
|
36213
|
+
/** `friend-step` only (Chris 2026-12-04): which friend-side step the guest took on the card. */
|
|
36214
|
+
"step?": "'friendOpened' | 'friendDwell' | 'friendExplored'",
|
|
36202
36215
|
/**
|
|
36203
36216
|
* `share-acted` only: the writer's principal (an account or a guest principal), from the door's
|
|
36204
36217
|
* verified bearer, never a body claim. The recorder digests it before it is stored or logged.
|
|
36205
36218
|
*/
|
|
36206
36219
|
"actorUserId?": "string",
|
|
36220
|
+
/**
|
|
36221
|
+
* `friend-step` only: the door's verified signed-in viewer (followed from a guest principal to its
|
|
36222
|
+
* account), never a body claim, so `payFriendStep` refuses staff and test-traffic viewers.
|
|
36223
|
+
*/
|
|
36224
|
+
"viewerUserId?": "string",
|
|
36207
36225
|
/** ISO instant of the act. */
|
|
36208
36226
|
at: "string",
|
|
36209
36227
|
/** The edge country of the request that made the act; the outcome log line carries it. */
|
|
@@ -36306,7 +36324,7 @@ async function postCapiEventOk(pixelId, payload, eventLabel) {
|
|
|
36306
36324
|
});
|
|
36307
36325
|
return true;
|
|
36308
36326
|
}
|
|
36309
|
-
var LEAD_POINTS, WEB_GROUP_ACTIVE_CAP, WEB_CHILD_GROUP_CAP, META_CLICK_WINDOW_MS;
|
|
36327
|
+
var LEAD_POINTS, FRIEND_STEP_CAP, FRIEND_STEP_CAP_WINDOW_MS, WEB_GROUP_ACTIVE_CAP, WEB_CHILD_GROUP_CAP, META_CLICK_WINDOW_MS;
|
|
36310
36328
|
var init_meta_capi_core = __esm({
|
|
36311
36329
|
"../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/types/meta-capi-core.ts"() {
|
|
36312
36330
|
"use strict";
|
|
@@ -36329,6 +36347,14 @@ var init_meta_capi_core = __esm({
|
|
|
36329
36347
|
return: 125,
|
|
36330
36348
|
share: 125,
|
|
36331
36349
|
shareOpened: 125,
|
|
36350
|
+
// Chris 2026-12-04 ("Host opens share should have 10 points ... none of them should have zero, even
|
|
36351
|
+
// intent matters for this path since it is so rare"): the host's steps on the way to a share, each
|
|
36352
|
+
// once per account (once per click signed out), on the host's own click, Meta and Google alike.
|
|
36353
|
+
// Opening the Share card or sheet is 10, a tap on Share in reach or Make public is 10, and a copied
|
|
36354
|
+
// link is 25, the same as hostPublishedInvite; the copy still earns `share` (125) beside it.
|
|
36355
|
+
shareSheetOpened: 10,
|
|
36356
|
+
shareReach: 10,
|
|
36357
|
+
shareLinkCopied: 25,
|
|
36332
36358
|
// Owner 2026-11-13 (traction cell c-2650, the group text campaign): the group ladder. A tap on
|
|
36333
36359
|
// good.vibes.diy/text's Send button opens Messages and "counts for a lot", so it pays a typed
|
|
36334
36360
|
// prompt's worth once a page load. The bridge pays the person who started a group with Vibes:
|
|
@@ -36338,15 +36364,31 @@ var init_meta_capi_core = __esm({
|
|
|
36338
36364
|
groupStart: 125,
|
|
36339
36365
|
groupActive: 250,
|
|
36340
36366
|
groupAgain: 125,
|
|
36367
|
+
// Chris 2026-12-04 ("Is there something like the friend steps we can do for groups?", and "no step
|
|
36368
|
+
// on any path to friend acted or a group spreading pays zero; intent matters because the end signals
|
|
36369
|
+
// are rare"): the group's own steps, each paid on the group STARTER's stored click (the parent
|
|
36370
|
+
// starter's for a child), once per group (per child for `groupChildStarted`), never to a member.
|
|
36371
|
+
// `groupMemberJoined` is the text group's first other member the bridge sees (a member added, or a
|
|
36372
|
+
// non-starter's first text); `groupFirstReply` is the first other member taking part after Vibes'
|
|
36373
|
+
// first reply (text) or the first other writer (web), one person before `groupActive` needs two;
|
|
36374
|
+
// `groupChildStarted` is a member of the group starting their own, before it goes active as
|
|
36375
|
+
// `childGroup`. They stack under groupActive (250) and childGroup (500). Wiring: imessage-bridge
|
|
36376
|
+
// capi.ts `planGroupLeads` / `planChildStartedLead`, and svc/intern/capi-web-group-event.ts.
|
|
36377
|
+
groupMemberJoined: 50,
|
|
36378
|
+
groupFirstReply: 50,
|
|
36379
|
+
groupChildStarted: 100,
|
|
36341
36380
|
// A /hero or /text tap with a friend's number typed in. Chris 2026-11-22 set it at the group start's
|
|
36342
|
-
// 125; on 2026-11-30 (#11550, "a typed number is an intent") it went to 0
|
|
36343
|
-
// friend taps to one real text
|
|
36344
|
-
//
|
|
36345
|
-
//
|
|
36346
|
-
//
|
|
36347
|
-
//
|
|
36348
|
-
//
|
|
36349
|
-
|
|
36381
|
+
// 125; on 2026-11-30 (#11550, "a typed number is an intent") it went to 0, because c-2656 drew about
|
|
36382
|
+
// ten friend taps to one real text and Meta was learning to buy people who type a number and stop.
|
|
36383
|
+
// Chris 2026-12-04 reversed the zero at 25: "none of them [the steps before friend acted] should have
|
|
36384
|
+
// zero, even intent matters for this path since it is so rare". Friend acted is the company's goal
|
|
36385
|
+
// (agents/goals/README.md), and a rung at 0 teaches the bidder nothing about the people who start it.
|
|
36386
|
+
// The 125 still waits for the text itself, which the bridge pays as `group_start` on the tap's
|
|
36387
|
+
// claimed click (imessage-bridge/capi.ts `planGroupLeads`). The pages fire the pixel at this value
|
|
36388
|
+
// (hero.hbs and text.hbs `FRIEND_TAP_POINTS`, pinned by api/tests/text-lane/hero-friend-lead.test.ts)
|
|
36389
|
+
// and `planHeroFriendLead` sends the Conversions API copy with the same event id. Nothing about the
|
|
36390
|
+
// friend goes. Meta only: the tap lane holds no Google click.
|
|
36391
|
+
friendTap: 25,
|
|
36350
36392
|
// #11075 (the forward-invite test, Chris 2026-11-25: "so Meta can learn from friends acting rather
|
|
36351
36393
|
// than from taps alone"): a forward-arm host's photo guess game drew its second guess. Two friends
|
|
36352
36394
|
// acting on a forwarded link is the same proof of a group as `groupActive`, so it pays the same. The
|
|
@@ -36363,10 +36405,28 @@ var init_meta_capi_core = __esm({
|
|
|
36363
36405
|
// caps in svc/intern/friend-acted-rules.ts. Owner 2026-12-04: friend acted is the company's goal, so it
|
|
36364
36406
|
// rises from 175 to 500, above a Plus purchase (300), sent now so Meta's learning starts catching up.
|
|
36365
36407
|
friendActed: 500,
|
|
36408
|
+
// Chris 2026-12-04 ("none of them should have zero"): a guest's saved answer to a host's invite,
|
|
36409
|
+
// strict or not, paid on the HOST's stored click once per invite, never for a rejected answer or the
|
|
36410
|
+
// host's own. It stacks under friendActed: a strict answer pays 100 at the answer, then 500 at acted.
|
|
36411
|
+
friendAnswered: 100,
|
|
36412
|
+
// Chris 2026-12-04 ("there are multiple paths to friend acted and we should pay them all", "friend
|
|
36413
|
+
// dwell etc", "friend explores app (clicks not writes?)"): the friend's own steps before friend
|
|
36414
|
+
// acted, paid on the HOST's stored click (fbc / gclid), never the friend's, once per (invite or app,
|
|
36415
|
+
// friend) and at most `FRIEND_STEP_CAP` friends per step per host per 7 days. `friendOpened` is a
|
|
36416
|
+
// friend (not the host, staff, test traffic or a link preview) opening the host's invite, on the
|
|
36417
|
+
// paths that pay no open yet (an app share link already pays `shareOpened` 125 to the maker);
|
|
36418
|
+
// `friendDwell` is that friend staying 10 s or scrolling 25% (`useEngagedVisit`'s threshold);
|
|
36419
|
+
// `friendExplored` is 3+ taps inside the app without needing a write (`vibe_engagement`'s taps).
|
|
36420
|
+
// They stack under friendAnswered (100) and friendActed (500). Wiring: svc/intern/friend-step-event.ts.
|
|
36421
|
+
friendOpened: 50,
|
|
36422
|
+
friendDwell: 25,
|
|
36423
|
+
friendExplored: 50,
|
|
36366
36424
|
// #11565 Round 3 (2026-11-30): the host published an invite. 25, not 75, so friend acted (500 since 2026-12-04, was 175)
|
|
36367
36425
|
// carries most of the value: at 25 answers outweigh publishes from about a 13% reply rate.
|
|
36368
36426
|
hostPublishedInvite: 25
|
|
36369
36427
|
};
|
|
36428
|
+
FRIEND_STEP_CAP = 10;
|
|
36429
|
+
FRIEND_STEP_CAP_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
36370
36430
|
WEB_GROUP_ACTIVE_CAP = 4;
|
|
36371
36431
|
WEB_CHILD_GROUP_CAP = 4;
|
|
36372
36432
|
META_CLICK_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
@@ -96616,7 +96676,11 @@ async function landLedgerWrite(sql2, userId, asRead, settings, now2) {
|
|
|
96616
96676
|
function ledgerRungOf(key) {
|
|
96617
96677
|
if (key.startsWith("childGroup:")) return "childGroup";
|
|
96618
96678
|
if (key.startsWith("childPaid:")) return "childPaid";
|
|
96679
|
+
if (key.startsWith("groupFirstReply:")) return "groupFirstReply";
|
|
96680
|
+
if (key.startsWith("groupChildStarted:")) return "groupChildStarted";
|
|
96619
96681
|
if (key.startsWith("friendActed:") || key.startsWith("hostPublished:")) return "friend";
|
|
96682
|
+
if (key.startsWith("friendAnswered:") || key.startsWith("friendOpened:") || key.startsWith("friendDwell:") || key.startsWith("friendExplored:"))
|
|
96683
|
+
return "friend";
|
|
96620
96684
|
return "groupActive";
|
|
96621
96685
|
}
|
|
96622
96686
|
function groupKeysCreditedCount(settings, rung) {
|
|
@@ -96670,6 +96734,11 @@ var init_capi_lead_ledger = __esm({
|
|
|
96670
96734
|
WEB_GROUP_LEDGER_CAPS = {
|
|
96671
96735
|
groupActive: WEB_GROUP_ACTIVE_CAP,
|
|
96672
96736
|
childGroup: WEB_CHILD_GROUP_CAP,
|
|
96737
|
+
// The group steps (Chris 2026-12-04), each under its own prefix so they never use up the rungs
|
|
96738
|
+
// they lead to: the first other writer, capped like `groupActive`, and a member's child started,
|
|
96739
|
+
// capped like `childGroup`.
|
|
96740
|
+
groupFirstReply: WEB_GROUP_ACTIVE_CAP,
|
|
96741
|
+
groupChildStarted: WEB_CHILD_GROUP_CAP,
|
|
96673
96742
|
// The child side of `childGroup` (#11551): `childPaid:<experiment>:<childDigest>` on the CHILD
|
|
96674
96743
|
// starter's row marks a child that has paid a parent, so a child pays at most one parent ever.
|
|
96675
96744
|
// A bound on how many such children one starter can start, generous because each is real spread.
|
|
@@ -140310,7 +140379,7 @@ var init_group_plan = __esm({
|
|
|
140310
140379
|
groupPlanConfig = {
|
|
140311
140380
|
name: "group-plan",
|
|
140312
140381
|
label: "Group plans",
|
|
140313
|
-
description:
|
|
140382
|
+
description: `A job a group does together that ends in one result or action: poll everyone then pick a date, shortlist everyone's top picks, a meeting point, items people claim, a group RSVP or order, each answer one row per person; name "access" beside it. Not a solo list or a poll with no decision`,
|
|
140314
140383
|
cues: ["poll everyone", "everyone's availability", "find a time that works", "plan for the group", "rsvp for"]
|
|
140315
140384
|
};
|
|
140316
140385
|
}
|
|
@@ -150259,7 +150328,8 @@ async function redeemInvite(vctx, req) {
|
|
|
150259
150328
|
inviteKey: inviteGrantKey(row),
|
|
150260
150329
|
redeemerId: req.redeemerId,
|
|
150261
150330
|
via: "grant",
|
|
150262
|
-
app: { ownerHandle: row.ownerHandle, appSlug: row.appSlug }
|
|
150331
|
+
app: { ownerHandle: row.ownerHandle, appSlug: row.appSlug },
|
|
150332
|
+
host: { userId: row.userId }
|
|
150263
150333
|
});
|
|
150264
150334
|
return Result.Ok(row);
|
|
150265
150335
|
}
|
|
@@ -154542,7 +154612,8 @@ async function bindPendingInvitesOnFirstAct(vctx, p2) {
|
|
|
154542
154612
|
inviteKey: inv.id,
|
|
154543
154613
|
redeemerId: p2.userId,
|
|
154544
154614
|
via: "first_act",
|
|
154545
|
-
app: { ownerHandle: inv.ownerHandle, appSlug: inv.appSlug }
|
|
154615
|
+
app: { ownerHandle: inv.ownerHandle, appSlug: inv.appSlug },
|
|
154616
|
+
host: { handle: inv.inviterHandle }
|
|
154546
154617
|
});
|
|
154547
154618
|
await grantBoundInvite(
|
|
154548
154619
|
vctx,
|
|
@@ -162582,12 +162653,15 @@ function visitorPaidOf(raw) {
|
|
|
162582
162653
|
const parsed2 = friendVisitorDoc(raw);
|
|
162583
162654
|
return parsed2 instanceof type.errors ? [] : parsed2.paid;
|
|
162584
162655
|
}
|
|
162656
|
+
function visitorDocId(args2) {
|
|
162657
|
+
return args2.rung === "friendAnswered" ? `friendAnswered:${args2.visitorDigest}` : args2.visitorDigest;
|
|
162658
|
+
}
|
|
162585
162659
|
async function claimVisitorRoot(sql2, args2) {
|
|
162586
162660
|
let claimed = false;
|
|
162587
162661
|
const r2 = await casStoreDoc(sql2, {
|
|
162588
162662
|
address: args2.address,
|
|
162589
162663
|
dbName: FRIEND_VISITORS_DB,
|
|
162590
|
-
docId: args2
|
|
162664
|
+
docId: visitorDocId(args2),
|
|
162591
162665
|
update: /* @__PURE__ */ __name((prev) => {
|
|
162592
162666
|
const paid = visitorPaidOf(prev).filter((p2) => Math.abs(args2.root.atMs - p2.atMs) <= VISITOR_KEEP_MS);
|
|
162593
162667
|
if (paid.some((p2) => p2.inviteId === args2.root.inviteId)) {
|
|
@@ -162609,7 +162683,7 @@ async function releaseVisitorRoot(sql2, args2) {
|
|
|
162609
162683
|
return casStoreDoc(sql2, {
|
|
162610
162684
|
address: args2.address,
|
|
162611
162685
|
dbName: FRIEND_VISITORS_DB,
|
|
162612
|
-
docId: args2
|
|
162686
|
+
docId: visitorDocId(args2),
|
|
162613
162687
|
update: /* @__PURE__ */ __name((prev) => {
|
|
162614
162688
|
const paid = visitorPaidOf(prev);
|
|
162615
162689
|
if (paid.some((p2) => p2.inviteId === args2.inviteId) === false) return void 0;
|
|
@@ -162783,7 +162857,19 @@ var init_friend_acted_store = __esm({
|
|
|
162783
162857
|
visitorDigest: "string",
|
|
162784
162858
|
answer: "string",
|
|
162785
162859
|
answeredAt: "string",
|
|
162786
|
-
event: friendActedEventMarker
|
|
162860
|
+
event: friendActedEventMarker,
|
|
162861
|
+
/**
|
|
162862
|
+
* The `friendAnswered` rung's own marker (Chris 2026-12-04): `pending` from the save of an answer
|
|
162863
|
+
* that may pay it (not rejected, not the host's own) until the queue consumer settles it. The door
|
|
162864
|
+
* enqueues `friend-answered` while it is pending, so a lost enqueue is retried by the card's next
|
|
162865
|
+
* tap; the consumer's ledger key keeps a double enqueue from paying twice. Absent on answers that
|
|
162866
|
+
* never pay it, and on answers saved before the marker existed.
|
|
162867
|
+
*/
|
|
162868
|
+
"answeredLead?": {
|
|
162869
|
+
credit: "'pending' | 'paid' | 'unpaid' | 'quarantined' | 'send-failed'",
|
|
162870
|
+
"outcome?": "string",
|
|
162871
|
+
"settledAt?": "string"
|
|
162872
|
+
}
|
|
162787
162873
|
})
|
|
162788
162874
|
);
|
|
162789
162875
|
__name(readFriendDocSql, "readFriendDocSql");
|
|
@@ -162798,13 +162884,14 @@ var init_friend_acted_store = __esm({
|
|
|
162798
162884
|
})
|
|
162799
162885
|
);
|
|
162800
162886
|
__name(visitorPaidOf, "visitorPaidOf");
|
|
162887
|
+
__name(visitorDocId, "visitorDocId");
|
|
162801
162888
|
VISITOR_KEEP_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
162802
162889
|
__name(claimVisitorRoot, "claimVisitorRoot");
|
|
162803
162890
|
__name(releaseVisitorRoot, "releaseVisitorRoot");
|
|
162804
162891
|
friendClickDoc = lazyType(
|
|
162805
162892
|
() => type({
|
|
162806
162893
|
type: "'friend-click'",
|
|
162807
|
-
paid: type({ rung: "'friendActed' | 'hostPublished'", inviteDigest: "string", atMs: "number" }).array()
|
|
162894
|
+
paid: type({ rung: "'friendActed' | 'hostPublished' | 'friendAnswered'", inviteDigest: "string", atMs: "number" }).array()
|
|
162808
162895
|
})
|
|
162809
162896
|
);
|
|
162810
162897
|
__name(clickPaidOf, "clickPaidOf");
|
|
@@ -163447,6 +163534,142 @@ async function postCapiWebChildGroupEvent(ctx, args2) {
|
|
|
163447
163534
|
});
|
|
163448
163535
|
if (r2.isErr()) console.error("[capi] web childGroup event failed", r2.Err());
|
|
163449
163536
|
}
|
|
163537
|
+
function stepRun(ctx, args2, step) {
|
|
163538
|
+
const { match: match4, nowMs } = args2;
|
|
163539
|
+
const experiment = match4.live.config.experiment;
|
|
163540
|
+
const memoKey3 = `${step}\0${match4.live.config.ownerHandle}/${match4.live.config.appSlug}\0${experiment}\0${match4.groupKey}`;
|
|
163541
|
+
const until = stepSkipUntil.get(memoKey3);
|
|
163542
|
+
const skip = /* @__PURE__ */ __name((forMs = GROUP_SKIP_MS) => {
|
|
163543
|
+
if (stepSkipUntil.size >= GROUP_SKIP_MAX) stepSkipUntil.clear();
|
|
163544
|
+
stepSkipUntil.set(memoKey3, nowMs + forMs);
|
|
163545
|
+
}, "skip");
|
|
163546
|
+
const done = /* @__PURE__ */ __name(async (outcome) => {
|
|
163547
|
+
skip();
|
|
163548
|
+
if (ctx.stepLineage === void 0) return;
|
|
163549
|
+
const fact = { experiment, groupKey: match4.groupKey, step, outcome };
|
|
163550
|
+
const r2 = await exception2Result(() => ctx.stepLineage(fact));
|
|
163551
|
+
if (r2.isErr()) console.error(`[capi] web ${step} lineage failed`, r2.Err());
|
|
163552
|
+
}, "done");
|
|
163553
|
+
return { skipped: until !== void 0 && until > nowMs, skip, done, experiment };
|
|
163554
|
+
}
|
|
163555
|
+
async function starterRefusal(ctx, userId, settings, nowMs) {
|
|
163556
|
+
if (settings === void 0 || isLeadClickInWindow(ctx, settings, nowMs) === false) return "no-click";
|
|
163557
|
+
if (isStaffAccount(userId, settings, await ctx.reads.handlesOf(userId))) return "staff";
|
|
163558
|
+
if (isTestTrafficSettings(settings)) return "test-traffic";
|
|
163559
|
+
return void 0;
|
|
163560
|
+
}
|
|
163561
|
+
async function payGroupStep(ctx, o3) {
|
|
163562
|
+
const groupDigest = await webGroupDigest(o3.experiment, o3.groupKey);
|
|
163563
|
+
const planned = planWebGroupFanout(ctx, {
|
|
163564
|
+
settings: o3.settings,
|
|
163565
|
+
externalId: await capiExternalId(o3.starter),
|
|
163566
|
+
experiment: o3.experiment,
|
|
163567
|
+
groupDigest,
|
|
163568
|
+
rung: o3.step,
|
|
163569
|
+
activatedAt: o3.atIso,
|
|
163570
|
+
nowMs: o3.nowMs
|
|
163571
|
+
});
|
|
163572
|
+
if ("refusal" in planned) return planned.refusal;
|
|
163573
|
+
if (await ctx.reads.claim(o3.starter, webGroupLedgerKey(o3.experiment, groupDigest, o3.step)) === false) return "not-claimed";
|
|
163574
|
+
return sendGroupFanout(ctx, planned.fan, o3.atIso, o3.nowMs, `web ${o3.step}`);
|
|
163575
|
+
}
|
|
163576
|
+
async function postCapiWebGroupFirstReplyEvent(ctx, args2) {
|
|
163577
|
+
const { match: match4, nowMs } = args2;
|
|
163578
|
+
const run = stepRun(ctx, args2, "groupFirstReply");
|
|
163579
|
+
if (run.skipped) return;
|
|
163580
|
+
const r2 = await exception2Result(async () => {
|
|
163581
|
+
if (leadLanesOn(ctx) === false) return;
|
|
163582
|
+
const rule = match4.live.config.derivedActivation;
|
|
163583
|
+
if (rule === void 0) return run.skip(NEVER_PAYS_MS);
|
|
163584
|
+
const head = await ctx.reads.groupHead(match4);
|
|
163585
|
+
if (head === void 0) return;
|
|
163586
|
+
if (groupNeverPays(match4, head, nowMs, META_CLICK_WINDOW_MS)) return run.skip(NEVER_PAYS_MS);
|
|
163587
|
+
const revisions = await ctx.reads.groupRevisions(match4);
|
|
163588
|
+
const raw = groupState({ match: match4, revisions });
|
|
163589
|
+
if (raw.groupDoc === void 0) return;
|
|
163590
|
+
if (isSeedGroup(match4, raw.groupDoc)) return run.done("seed");
|
|
163591
|
+
const starter = await resolveGroupStarter(ctx.reads.userIdOfHandle, match4, raw);
|
|
163592
|
+
if (starter === void 0) return run.done("no-starter");
|
|
163593
|
+
const excluded = await excludedWriters(ctx.reads, raw, starter);
|
|
163594
|
+
const closesAt = head.firstCreatedMs + rule.windowHours * 36e5;
|
|
163595
|
+
const first = raw.contributions.filter((d3) => isRealWriter(d3.firstUserId) && d3.firstUserId !== starter && excluded.has(d3.firstUserId) === false).map((d3) => Date.parse(d3.firstCreated)).filter((at3) => Number.isFinite(at3) && at3 <= closesAt).sort((a4, b4) => a4 - b4)[0];
|
|
163596
|
+
if (first === void 0) return;
|
|
163597
|
+
const settings = await ctx.reads.settingsOf(starter);
|
|
163598
|
+
const refusal = await starterRefusal(ctx, starter, settings, nowMs);
|
|
163599
|
+
if (refusal !== void 0 || settings === void 0) return run.done(refusal ?? "no-click");
|
|
163600
|
+
const digest2 = await webGroupDigest(run.experiment, match4.groupKey);
|
|
163601
|
+
if (isGroupKeyCredited(settings, webGroupLedgerKey(run.experiment, digest2, "groupFirstReply"))) return run.done("credited");
|
|
163602
|
+
await run.done(
|
|
163603
|
+
await payGroupStep(ctx, {
|
|
163604
|
+
starter,
|
|
163605
|
+
settings,
|
|
163606
|
+
experiment: run.experiment,
|
|
163607
|
+
groupKey: match4.groupKey,
|
|
163608
|
+
step: "groupFirstReply",
|
|
163609
|
+
atIso: new Date(first).toISOString(),
|
|
163610
|
+
nowMs
|
|
163611
|
+
})
|
|
163612
|
+
);
|
|
163613
|
+
});
|
|
163614
|
+
if (r2.isErr()) console.error("[capi] web groupFirstReply event failed", r2.Err());
|
|
163615
|
+
}
|
|
163616
|
+
async function postCapiWebChildStartedEvent(ctx, args2) {
|
|
163617
|
+
const { match: match4, nowMs } = args2;
|
|
163618
|
+
const run = stepRun(ctx, args2, "groupChildStarted");
|
|
163619
|
+
if (run.skipped) return;
|
|
163620
|
+
const r2 = await exception2Result(async () => {
|
|
163621
|
+
if (leadLanesOn(ctx) === false) return;
|
|
163622
|
+
if (match4.live.config.derivedActivation === void 0) return run.skip(NEVER_PAYS_MS);
|
|
163623
|
+
const head = await ctx.reads.groupHead(match4);
|
|
163624
|
+
if (head === void 0) return;
|
|
163625
|
+
const parentKey = parentKeyOf(match4, head.first);
|
|
163626
|
+
if (parentKey === void 0 || nowMs - head.firstCreatedMs > META_CLICK_WINDOW_MS) return run.skip(NEVER_PAYS_MS);
|
|
163627
|
+
const raw = groupState({ match: match4, revisions: await ctx.reads.groupRevisions(match4) });
|
|
163628
|
+
if (raw.groupDoc === void 0) return;
|
|
163629
|
+
if (isSeedGroup(match4, raw.groupDoc)) return run.done("seed");
|
|
163630
|
+
const childStarter = await resolveGroupStarter(ctx.reads.userIdOfHandle, match4, raw);
|
|
163631
|
+
if (childStarter === void 0) return run.done("child-starter-unresolved");
|
|
163632
|
+
const childSettings = await ctx.reads.settingsOf(childStarter) ?? [];
|
|
163633
|
+
if (isStaffAccount(childStarter, childSettings, await ctx.reads.handlesOf(childStarter))) return run.done("child-staff");
|
|
163634
|
+
if (isTestTrafficSettings(childSettings)) return run.done("child-test-traffic");
|
|
163635
|
+
const parentMatch = { live: match4.live, groupKey: parentKey };
|
|
163636
|
+
const parentRevisions = (await ctx.reads.groupRevisions(parentMatch)).filter((r3) => {
|
|
163637
|
+
const at3 = Date.parse(r3.created);
|
|
163638
|
+
return Number.isFinite(at3) && at3 <= head.firstCreatedMs;
|
|
163639
|
+
});
|
|
163640
|
+
const parent = groupState({ match: parentMatch, revisions: parentRevisions });
|
|
163641
|
+
if (parent.groupDoc === void 0 || parent.edge === void 0) return run.done("no-parent");
|
|
163642
|
+
if (isSeedGroup(parentMatch, parent.groupDoc)) return run.done("parent-seed");
|
|
163643
|
+
if (parent.edge.activatedAt === null) return run.done("parent-not-active");
|
|
163644
|
+
const starter = await resolveGroupStarter(ctx.reads.userIdOfHandle, parentMatch, parent);
|
|
163645
|
+
if (starter === void 0) return run.done("no-starter");
|
|
163646
|
+
if (childStarter === starter) return run.done("same-starter");
|
|
163647
|
+
if (writersOf(parentRevisions).has(childStarter) === false) return run.done("not-a-member");
|
|
163648
|
+
const parentExcluded = await excludedWriters(ctx.reads, parent, starter);
|
|
163649
|
+
const parentReal = parentExcluded.size === 0 ? parent : groupState({ match: parentMatch, revisions: parentRevisions, excluded: parentExcluded });
|
|
163650
|
+
if (liveDerivedActivatedAt({ match: parentMatch, state: parentReal, starter, excluded: parentExcluded }) === null)
|
|
163651
|
+
return run.done("parent-not-active");
|
|
163652
|
+
const settings = await ctx.reads.settingsOf(starter);
|
|
163653
|
+
const refusal = await starterRefusal(ctx, starter, settings, nowMs);
|
|
163654
|
+
if (refusal !== void 0 || settings === void 0) return run.done(refusal ?? "no-click");
|
|
163655
|
+
await run.done(
|
|
163656
|
+
await payGroupStep(ctx, {
|
|
163657
|
+
starter,
|
|
163658
|
+
settings,
|
|
163659
|
+
experiment: run.experiment,
|
|
163660
|
+
groupKey: match4.groupKey,
|
|
163661
|
+
step: "groupChildStarted",
|
|
163662
|
+
atIso: new Date(head.firstCreatedMs).toISOString(),
|
|
163663
|
+
nowMs
|
|
163664
|
+
})
|
|
163665
|
+
);
|
|
163666
|
+
});
|
|
163667
|
+
if (r2.isErr()) console.error("[capi] web groupChildStarted event failed", r2.Err());
|
|
163668
|
+
}
|
|
163669
|
+
function recordWebGroupStep(vctx, fact) {
|
|
163670
|
+
vctx.logger.Info().Str("experiment", fact.experiment).Str("groupKey", fact.groupKey).Str("step", fact.step).Str("outcome", fact.outcome).Msg(WEB_GROUP_STEP_EVENT);
|
|
163671
|
+
return Promise.resolve();
|
|
163672
|
+
}
|
|
163450
163673
|
async function recordWebChildGroupActive(vctx, fact) {
|
|
163451
163674
|
vctx.logger.Info().Str("experiment", fact.experiment).Str("groupKey", fact.groupKey).Str("parentKey", fact.parentKey).Str("activatedAt", fact.activatedAt).Uint64("newPeople", fact.newPeople).Str("outcome", fact.outcome).Msg(WEB_GROUP_CHILD_ACTIVE_EVENT);
|
|
163452
163675
|
await capturePostHogServerEvent(vctx, {
|
|
@@ -163488,6 +163711,8 @@ async function runWebGroupRungs(ctx, args2) {
|
|
|
163488
163711
|
const shared = { ...ctx, reads: taskWebGroupReads(ctx.reads) };
|
|
163489
163712
|
await postCapiWebGroupEvent(shared, args2);
|
|
163490
163713
|
await postCapiWebChildGroupEvent(shared, args2);
|
|
163714
|
+
await postCapiWebGroupFirstReplyEvent(shared, args2);
|
|
163715
|
+
await postCapiWebChildStartedEvent(shared, args2);
|
|
163491
163716
|
}
|
|
163492
163717
|
async function runWebGroupWrite(ctx, args2) {
|
|
163493
163718
|
const shared = { ...ctx, reads: taskWebGroupReads(ctx.reads) };
|
|
@@ -163541,7 +163766,8 @@ function scheduleWebGroupActive(vctx, write, live = LIVE_EXPERIMENTS, friendLive
|
|
|
163541
163766
|
...vctx.metaCapiSend === void 0 ? {} : { send: vctx.metaCapiSend },
|
|
163542
163767
|
...vctx.googleLeadSend === void 0 ? {} : { googleSend: vctx.googleLeadSend },
|
|
163543
163768
|
lineage: /* @__PURE__ */ __name((fact) => recordWebGroupActive(vctx, fact), "lineage"),
|
|
163544
|
-
childLineage: /* @__PURE__ */ __name((fact) => recordWebChildGroupActive(vctx, fact), "childLineage")
|
|
163769
|
+
childLineage: /* @__PURE__ */ __name((fact) => recordWebChildGroupActive(vctx, fact), "childLineage"),
|
|
163770
|
+
stepLineage: /* @__PURE__ */ __name((fact) => recordWebGroupStep(vctx, fact), "stepLineage")
|
|
163545
163771
|
},
|
|
163546
163772
|
{
|
|
163547
163773
|
...rungMatch === void 0 ? {} : { rungMatch },
|
|
@@ -163582,7 +163808,7 @@ function scheduleWebGroupActive(vctx, write, live = LIVE_EXPERIMENTS, friendLive
|
|
|
163582
163808
|
});
|
|
163583
163809
|
if (rSchedule.isErr()) console.error("[capi] web groupActive schedule failed", rSchedule.Err());
|
|
163584
163810
|
}
|
|
163585
|
-
var EVENT_TIME_MAX_AGE_MS, MAX_WRITER_CHECKS, GROUP_SKIP_MS, NEVER_PAYS_MS, GROUP_SKIP_MAX, groupSkipUntil, WEB_GROUP_ACTIVE_EVENT, childSkipUntil, WEB_GROUP_CHILD_ACTIVE_EVENT;
|
|
163811
|
+
var EVENT_TIME_MAX_AGE_MS, MAX_WRITER_CHECKS, GROUP_SKIP_MS, NEVER_PAYS_MS, GROUP_SKIP_MAX, groupSkipUntil, WEB_GROUP_ACTIVE_EVENT, childSkipUntil, stepSkipUntil, WEB_GROUP_STEP_EVENT, WEB_GROUP_CHILD_ACTIVE_EVENT;
|
|
163586
163812
|
var init_capi_web_group_event = __esm({
|
|
163587
163813
|
"../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/capi-web-group-event.ts"() {
|
|
163588
163814
|
"use strict";
|
|
@@ -163626,6 +163852,14 @@ var init_capi_web_group_event = __esm({
|
|
|
163626
163852
|
__name(childPaidLedgerKey, "childPaidLedgerKey");
|
|
163627
163853
|
__name(writersOf, "writersOf");
|
|
163628
163854
|
__name(postCapiWebChildGroupEvent, "postCapiWebChildGroupEvent");
|
|
163855
|
+
stepSkipUntil = /* @__PURE__ */ new Map();
|
|
163856
|
+
__name(stepRun, "stepRun");
|
|
163857
|
+
__name(starterRefusal, "starterRefusal");
|
|
163858
|
+
__name(payGroupStep, "payGroupStep");
|
|
163859
|
+
__name(postCapiWebGroupFirstReplyEvent, "postCapiWebGroupFirstReplyEvent");
|
|
163860
|
+
__name(postCapiWebChildStartedEvent, "postCapiWebChildStartedEvent");
|
|
163861
|
+
WEB_GROUP_STEP_EVENT = "web_group_step";
|
|
163862
|
+
__name(recordWebGroupStep, "recordWebGroupStep");
|
|
163629
163863
|
WEB_GROUP_CHILD_ACTIVE_EVENT = "web_group_child_active";
|
|
163630
163864
|
__name(recordWebChildGroupActive, "recordWebChildGroupActive");
|
|
163631
163865
|
__name(taskWebGroupReads, "taskWebGroupReads");
|
|
@@ -163716,6 +163950,9 @@ function clickGate(args2) {
|
|
|
163716
163950
|
function friendActedEventId(hostExternalId, inviteDigest2) {
|
|
163717
163951
|
return capiEventId("Lead", `friendacted:${hostExternalId}:${inviteDigest2}`);
|
|
163718
163952
|
}
|
|
163953
|
+
function friendAnsweredEventId(hostExternalId, inviteDigest2) {
|
|
163954
|
+
return capiEventId("Lead", `friendanswered:${hostExternalId}:${inviteDigest2}`);
|
|
163955
|
+
}
|
|
163719
163956
|
function hostGoogleClickGate(args2) {
|
|
163720
163957
|
const click = storedGoogleClick(args2.settings);
|
|
163721
163958
|
if (click === void 0) return void 0;
|
|
@@ -163724,6 +163961,7 @@ function hostGoogleClickGate(args2) {
|
|
|
163724
163961
|
return { gclid: click.gclid, clickedAt: click.clickedAt };
|
|
163725
163962
|
}
|
|
163726
163963
|
async function buildFriendActedLead(input3) {
|
|
163964
|
+
const answered = input3.rung === "friendAnswered";
|
|
163727
163965
|
const click = hostClickOf({ settings: input3.settings, ...input3.handed === void 0 ? {} : { handed: input3.handed } });
|
|
163728
163966
|
if (click === void 0) return void 0;
|
|
163729
163967
|
const contact = input3.settings.find(isUserSettingContactEmail);
|
|
@@ -163734,14 +163972,14 @@ async function buildFriendActedLead(input3) {
|
|
|
163734
163972
|
event_name: "Lead",
|
|
163735
163973
|
action_source: "system_generated",
|
|
163736
163974
|
event_time: Math.floor(webGroupEventTimeMs(new Date(input3.actionMs).toISOString(), input3.nowMs) / 1e3),
|
|
163737
|
-
event_id: friendActedEventId(input3.externalId, input3.inviteDigest),
|
|
163975
|
+
event_id: answered ? friendAnsweredEventId(input3.externalId, input3.inviteDigest) : friendActedEventId(input3.externalId, input3.inviteDigest),
|
|
163738
163976
|
user_data: {
|
|
163739
163977
|
fbc: click.fbc,
|
|
163740
163978
|
...click.fbp === void 0 ? {} : { fbp: click.fbp },
|
|
163741
163979
|
external_id: input3.externalId,
|
|
163742
163980
|
...em === void 0 ? {} : { em }
|
|
163743
163981
|
},
|
|
163744
|
-
custom_data: { value: LEAD_POINTS.friendActed, currency: "USD", lead_stage: "friend_acted" }
|
|
163982
|
+
custom_data: answered ? { value: LEAD_POINTS.friendAnswered, currency: "USD", lead_stage: "friend_answered" } : { value: LEAD_POINTS.friendActed, currency: "USD", lead_stage: "friend_acted" }
|
|
163745
163983
|
}
|
|
163746
163984
|
],
|
|
163747
163985
|
access_token: input3.capiToken
|
|
@@ -163971,6 +164209,7 @@ var init_friend_acted_event = __esm({
|
|
|
163971
164209
|
__name(parseKeys, "parseKeys");
|
|
163972
164210
|
__name(clickGate, "clickGate");
|
|
163973
164211
|
__name(friendActedEventId, "friendActedEventId");
|
|
164212
|
+
__name(friendAnsweredEventId, "friendAnsweredEventId");
|
|
163974
164213
|
__name(hostGoogleClickGate, "hostGoogleClickGate");
|
|
163975
164214
|
__name(buildFriendActedLead, "buildFriendActedLead");
|
|
163976
164215
|
__name(send2, "send");
|
|
@@ -164156,6 +164395,149 @@ var init_friend_acted_recorder = __esm({
|
|
|
164156
164395
|
}
|
|
164157
164396
|
});
|
|
164158
164397
|
|
|
164398
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/friend-step-event.ts
|
|
164399
|
+
function friendStepLedgerKey(args2) {
|
|
164400
|
+
return `${args2.step}:${args2.scopeDigest}:${args2.friendDigest.slice(0, 16)}:${args2.atMs}`;
|
|
164401
|
+
}
|
|
164402
|
+
function stepKeysOf(settings, step) {
|
|
164403
|
+
const out = [];
|
|
164404
|
+
for (const k2 of creditedLedgerKeys(settings)) {
|
|
164405
|
+
const parts = k2.split(":");
|
|
164406
|
+
if (parts.length !== 4 || parts[0] !== step) continue;
|
|
164407
|
+
const atMs = Number(parts[3]);
|
|
164408
|
+
if (Number.isFinite(atMs) === false) continue;
|
|
164409
|
+
out.push({ scope: parts[1], friend: parts[2], atMs });
|
|
164410
|
+
}
|
|
164411
|
+
return out;
|
|
164412
|
+
}
|
|
164413
|
+
function friendStepAdmits(settings, args2) {
|
|
164414
|
+
const keys = stepKeysOf(settings, args2.step);
|
|
164415
|
+
const friend = args2.friendDigest.slice(0, 16);
|
|
164416
|
+
if (keys.some((k2) => k2.scope === args2.scopeDigest && k2.friend === friend)) return "already-paid";
|
|
164417
|
+
const recent = keys.filter((k2) => Math.abs(args2.nowMs - k2.atMs) <= FRIEND_STEP_CAP_WINDOW_MS);
|
|
164418
|
+
return recent.length >= FRIEND_STEP_CAP ? "host-weekly-cap" : "admit";
|
|
164419
|
+
}
|
|
164420
|
+
function friendStepVendors(input3) {
|
|
164421
|
+
const metaClick = input3.settings.find(isUserSettingMetaClickId);
|
|
164422
|
+
const gClick = storedGoogleClick(input3.settings);
|
|
164423
|
+
const viewerUa = input3.viewerUserAgent;
|
|
164424
|
+
const agentOk = /* @__PURE__ */ __name((clickUa) => viewerUa === void 0 || clickUa !== void 0 && clickUa !== "" && clickUa !== viewerUa, "agentOk");
|
|
164425
|
+
if (viewerUa !== void 0) {
|
|
164426
|
+
const hostAgents = [metaClick?.userAgent, gClick?.userAgent].filter((ua) => ua !== void 0 && ua !== "");
|
|
164427
|
+
if (viewerUa === "" || hostAgents.includes(viewerUa)) return { meta: false, google: false };
|
|
164428
|
+
}
|
|
164429
|
+
const inWindow = /* @__PURE__ */ __name((clickedAt, windowMs) => input3.nowMs - clickedAt >= 0 && input3.nowMs - clickedAt <= windowMs, "inWindow");
|
|
164430
|
+
const meta3 = input3.metaOn && metaClick !== void 0 && metaClick.fbc !== "" && inWindow(metaClick.clickedAt, META_CLICK_WINDOW_MS) && agentOk(metaClick.userAgent);
|
|
164431
|
+
const google = input3.googleOn && gClick !== void 0 && inWindow(gClick.clickedAt, GOOGLE_IMPORT_WINDOW_MS) && agentOk(gClick.userAgent);
|
|
164432
|
+
return { meta: meta3, google };
|
|
164433
|
+
}
|
|
164434
|
+
function friendStepEventId(hostExternalId, step, scopeDigest, friendDigest) {
|
|
164435
|
+
return capiEventId("Lead", `${step.toLowerCase()}:${hostExternalId}:${scopeDigest}:${friendDigest}`);
|
|
164436
|
+
}
|
|
164437
|
+
async function friendAccountDigest(userId) {
|
|
164438
|
+
return (await capiSha256Hex(`friendstep:u:${userId}`)).slice(0, 32);
|
|
164439
|
+
}
|
|
164440
|
+
async function payFriendStep(ctx, args2) {
|
|
164441
|
+
const r2 = await exception2Result(async () => {
|
|
164442
|
+
if (leadLanesOn(ctx) === false) return "lanes-off";
|
|
164443
|
+
const host = args2.hostUserId;
|
|
164444
|
+
if (host === "") return "no-host";
|
|
164445
|
+
if (args2.viewerUserId !== void 0 && args2.viewerUserId === host) return "self";
|
|
164446
|
+
const settings = await readSettings(ctx.sql, host);
|
|
164447
|
+
if (settings === void 0) return "no-host";
|
|
164448
|
+
if (args2.testTraffic === true || isTestTrafficSettings(settings)) return "test-traffic";
|
|
164449
|
+
if (isStaffAccount(host, settings, [...args2.hostHandles ?? [], ...await handlesOf(ctx.sql, host)])) return "staff";
|
|
164450
|
+
if (args2.viewerUserId !== void 0) {
|
|
164451
|
+
const viewer = args2.viewerUserId;
|
|
164452
|
+
const viewerSettings = await readSettings(ctx.sql, viewer) ?? [];
|
|
164453
|
+
if (isTestTrafficSettings(viewerSettings)) return "test-traffic";
|
|
164454
|
+
if (isStaffAccount(viewer, viewerSettings, await handlesOf(ctx.sql, viewer))) return "staff";
|
|
164455
|
+
}
|
|
164456
|
+
const vendors = friendStepVendors({
|
|
164457
|
+
settings,
|
|
164458
|
+
nowMs: args2.nowMs,
|
|
164459
|
+
metaOn: metaLaneOn(ctx),
|
|
164460
|
+
googleOn: ctx.googleSend !== void 0,
|
|
164461
|
+
...args2.viewerUserAgent === void 0 ? {} : { viewerUserAgent: args2.viewerUserAgent }
|
|
164462
|
+
});
|
|
164463
|
+
if (vendors.meta === false && vendors.google === false) return "no-click";
|
|
164464
|
+
const admitArgs = { step: args2.step, scopeDigest: args2.scopeDigest, friendDigest: args2.friendDigest, nowMs: args2.nowMs };
|
|
164465
|
+
const admit = friendStepAdmits(settings, admitArgs);
|
|
164466
|
+
if (admit !== "admit") return admit;
|
|
164467
|
+
const externalId = await capiExternalId(host);
|
|
164468
|
+
const eventId = friendStepEventId(externalId, args2.step, args2.scopeDigest, args2.friendDigest);
|
|
164469
|
+
const value2 = LEAD_POINTS[args2.step];
|
|
164470
|
+
const click = settings.find(isUserSettingMetaClickId);
|
|
164471
|
+
const contact = settings.find(isUserSettingContactEmail);
|
|
164472
|
+
const meta3 = vendors.meta && click !== void 0 && ctx.capiToken !== void 0 && ctx.pixelId !== void 0 ? {
|
|
164473
|
+
eventName: "Lead",
|
|
164474
|
+
eventId,
|
|
164475
|
+
fbc: click.fbc,
|
|
164476
|
+
capiToken: ctx.capiToken,
|
|
164477
|
+
pixelId: ctx.pixelId,
|
|
164478
|
+
externalId,
|
|
164479
|
+
value: value2,
|
|
164480
|
+
...contact?.verified === true ? { email: contact.email } : {},
|
|
164481
|
+
...click.userAgent === void 0 ? {} : { userAgent: click.userAgent }
|
|
164482
|
+
} : void 0;
|
|
164483
|
+
const google = vendors.google ? googleLeadOf({
|
|
164484
|
+
settings,
|
|
164485
|
+
googleSend: ctx.googleSend,
|
|
164486
|
+
eventId,
|
|
164487
|
+
value: value2,
|
|
164488
|
+
eventTimeMs: args2.nowMs,
|
|
164489
|
+
windowMs: GOOGLE_IMPORT_WINDOW_MS
|
|
164490
|
+
}) : void 0;
|
|
164491
|
+
const fan = leadFanout(meta3, google);
|
|
164492
|
+
if (fan === void 0) return "no-click";
|
|
164493
|
+
const key = friendStepLedgerKey({ ...admitArgs, atMs: args2.nowMs });
|
|
164494
|
+
const claimed = await claimLeadKey(ctx.sql, {
|
|
164495
|
+
userId: host,
|
|
164496
|
+
key,
|
|
164497
|
+
admit: /* @__PURE__ */ __name((s2) => friendStepAdmits(s2, admitArgs) === "admit", "admit")
|
|
164498
|
+
});
|
|
164499
|
+
if (claimed === false) return "not-claimed";
|
|
164500
|
+
const sent = await sendLeadFanout(
|
|
164501
|
+
fan,
|
|
164502
|
+
{
|
|
164503
|
+
eventSourceUrl: ctx.eventSourceUrl,
|
|
164504
|
+
metaNowMs: args2.nowMs,
|
|
164505
|
+
...ctx.send === void 0 ? {} : { metaSend: ctx.send },
|
|
164506
|
+
...ctx.googleSend === void 0 ? {} : { googleSend: ctx.googleSend }
|
|
164507
|
+
},
|
|
164508
|
+
args2.step
|
|
164509
|
+
);
|
|
164510
|
+
return fanoutSent(sent) ? "sent" : "send-failed";
|
|
164511
|
+
});
|
|
164512
|
+
if (r2.isErr()) {
|
|
164513
|
+
console.error(`[capi] ${args2.step} event failed`, r2.Err());
|
|
164514
|
+
return "failed";
|
|
164515
|
+
}
|
|
164516
|
+
return r2.Ok();
|
|
164517
|
+
}
|
|
164518
|
+
var init_friend_step_event = __esm({
|
|
164519
|
+
"../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/friend-step-event.ts"() {
|
|
164520
|
+
"use strict";
|
|
164521
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
164522
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
164523
|
+
init_performance2();
|
|
164524
|
+
init_esm();
|
|
164525
|
+
init_types4();
|
|
164526
|
+
init_capi_lead_ledger();
|
|
164527
|
+
init_capi_share_event();
|
|
164528
|
+
init_google_lead();
|
|
164529
|
+
init_lead_fanout();
|
|
164530
|
+
init_test_traffic();
|
|
164531
|
+
__name(friendStepLedgerKey, "friendStepLedgerKey");
|
|
164532
|
+
__name(stepKeysOf, "stepKeysOf");
|
|
164533
|
+
__name(friendStepAdmits, "friendStepAdmits");
|
|
164534
|
+
__name(friendStepVendors, "friendStepVendors");
|
|
164535
|
+
__name(friendStepEventId, "friendStepEventId");
|
|
164536
|
+
__name(friendAccountDigest, "friendAccountDigest");
|
|
164537
|
+
__name(payFriendStep, "payFriendStep");
|
|
164538
|
+
}
|
|
164539
|
+
});
|
|
164540
|
+
|
|
164159
164541
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/email-invite-friend-acted.ts
|
|
164160
164542
|
function inviteGrantKey(row) {
|
|
164161
164543
|
return `grant:${row.userId}:${row.ownerHandle}:${row.appSlug}:${row.emailKey}`;
|
|
@@ -164345,8 +164727,60 @@ function scheduleEmailInviteFriendActed(vctx, write, nowMs = Date.now()) {
|
|
|
164345
164727
|
});
|
|
164346
164728
|
if (rSchedule.isErr()) console.error("[friend-acted] email invite act schedule failed", rSchedule.Err());
|
|
164347
164729
|
}
|
|
164730
|
+
async function payInviteFriendOpened(vctx, args2) {
|
|
164731
|
+
const r2 = await exception2Result(async () => {
|
|
164732
|
+
let hostUserId2;
|
|
164733
|
+
if ("userId" in args2.host) hostUserId2 = args2.host.userId;
|
|
164734
|
+
else {
|
|
164735
|
+
const t3 = vctx.sql.tables.handleBinding;
|
|
164736
|
+
const row = await vctx.sql.db.select({ userId: t3.userId }).from(t3).where(eq(t3.handle, args2.host.handle)).limit(1).then((rows) => rows[0]);
|
|
164737
|
+
hostUserId2 = row?.userId ?? void 0;
|
|
164738
|
+
}
|
|
164739
|
+
if (hostUserId2 === void 0 || hostUserId2 === "") return "no-host";
|
|
164740
|
+
const host = await followGuestPrincipal(vctx, hostUserId2);
|
|
164741
|
+
return payFriendStep(
|
|
164742
|
+
{
|
|
164743
|
+
sql: vctx.sql,
|
|
164744
|
+
capiToken: vctx.metaCapiToken,
|
|
164745
|
+
pixelId: vctx.metaPixelId,
|
|
164746
|
+
eventSourceUrl: vctx.params.vibes.env.VIBES_DIY_PUBLIC_BASE_URL,
|
|
164747
|
+
...vctx.metaCapiSend === void 0 ? {} : { send: vctx.metaCapiSend },
|
|
164748
|
+
...vctx.googleLeadSend === void 0 ? {} : { googleSend: vctx.googleLeadSend }
|
|
164749
|
+
},
|
|
164750
|
+
{
|
|
164751
|
+
hostUserId: host,
|
|
164752
|
+
step: "friendOpened",
|
|
164753
|
+
scopeDigest: await friendInviteDigest(args2.flow, args2.inviteKey),
|
|
164754
|
+
friendDigest: await friendAccountDigest(args2.redeemerId),
|
|
164755
|
+
nowMs: args2.nowMs,
|
|
164756
|
+
viewerUserId: args2.redeemerId,
|
|
164757
|
+
..."handle" in args2.host ? { hostHandles: [args2.host.handle] } : {}
|
|
164758
|
+
}
|
|
164759
|
+
);
|
|
164760
|
+
});
|
|
164761
|
+
if (r2.isErr()) {
|
|
164762
|
+
console.error("[friend-acted] invite friendOpened failed", r2.Err());
|
|
164763
|
+
return "failed";
|
|
164764
|
+
}
|
|
164765
|
+
return r2.Ok();
|
|
164766
|
+
}
|
|
164348
164767
|
function captureInviteRedeemed(vctx, args2) {
|
|
164349
164768
|
forgetEmailInviteActs(args2.redeemerId);
|
|
164769
|
+
const { sql: sql2, params } = vctx;
|
|
164770
|
+
if (args2.host !== void 0 && sql2 !== void 0 && params !== void 0) {
|
|
164771
|
+
const opened = payInviteFriendOpened(
|
|
164772
|
+
{
|
|
164773
|
+
sql: sql2,
|
|
164774
|
+
params,
|
|
164775
|
+
metaCapiToken: vctx.metaCapiToken,
|
|
164776
|
+
metaPixelId: vctx.metaPixelId,
|
|
164777
|
+
...vctx.metaCapiSend === void 0 ? {} : { metaCapiSend: vctx.metaCapiSend },
|
|
164778
|
+
...vctx.googleLeadSend === void 0 ? {} : { googleLeadSend: vctx.googleLeadSend }
|
|
164779
|
+
},
|
|
164780
|
+
{ flow: args2.flow, inviteKey: args2.inviteKey, redeemerId: args2.redeemerId, host: args2.host, nowMs: Date.now() }
|
|
164781
|
+
);
|
|
164782
|
+
vctx.waitUntil?.(opened);
|
|
164783
|
+
}
|
|
164350
164784
|
const promise2 = exception2Result(async () => {
|
|
164351
164785
|
const digest2 = await friendInviteDigest(args2.flow, args2.inviteKey);
|
|
164352
164786
|
await capturePostHogServerEvent(vctx, {
|
|
@@ -164380,6 +164814,8 @@ var init_email_invite_friend_acted = __esm({
|
|
|
164380
164814
|
init_analytics();
|
|
164381
164815
|
init_friend_acted_recorder();
|
|
164382
164816
|
init_friend_acted_store();
|
|
164817
|
+
init_friend_step_event();
|
|
164818
|
+
init_guest_principal_owner();
|
|
164383
164819
|
__name(inviteGrantKey, "inviteGrantKey");
|
|
164384
164820
|
__name(sentAtOf, "sentAtOf");
|
|
164385
164821
|
__name(recentEmailInvitesFor, "recentEmailInvitesFor");
|
|
@@ -164395,6 +164831,7 @@ var init_email_invite_friend_acted = __esm({
|
|
|
164395
164831
|
__name(runEmailInviteActTask, "runEmailInviteActTask");
|
|
164396
164832
|
__name(scheduleEmailInviteFriendActed, "scheduleEmailInviteFriendActed");
|
|
164397
164833
|
INVITE_REDEEMED_EVENT = "invite_redeemed";
|
|
164834
|
+
__name(payInviteFriendOpened, "payInviteFriendOpened");
|
|
164398
164835
|
__name(captureInviteRedeemed, "captureInviteRedeemed");
|
|
164399
164836
|
}
|
|
164400
164837
|
});
|