@ak--47/dungeon-master 1.5.0 → 1.5.1

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/HOOKS.md +13 -0
  3. package/dungeons/technical/ad-spend.js +41 -49
  4. package/dungeons/technical/anonymous-users.js +38 -36
  5. package/dungeons/technical/array-of-object-lookup.js +136 -153
  6. package/dungeons/technical/datagen-v15-verify.js +24 -11
  7. package/dungeons/technical/experiments.js +42 -40
  8. package/dungeons/technical/foobar.js +114 -118
  9. package/dungeons/technical/group-analytics.js +42 -40
  10. package/dungeons/technical/hook-helpers-verify.js +69 -50
  11. package/dungeons/technical/identity-model-verify.js +22 -12
  12. package/dungeons/technical/mirror-strategies.js +37 -39
  13. package/dungeons/technical/nested-objects.js +119 -118
  14. package/dungeons/technical/pattern-aggregate-by-bin.js +21 -8
  15. package/dungeons/technical/pattern-attributed-by-source.js +23 -9
  16. package/dungeons/technical/pattern-frequency-by-frequency.js +21 -8
  17. package/dungeons/technical/pattern-funnel-frequency.js +30 -15
  18. package/dungeons/technical/pattern-ttc-by-segment.js +21 -8
  19. package/dungeons/technical/retention-cadence.js +115 -112
  20. package/dungeons/technical/sanity.js +86 -80
  21. package/dungeons/technical/scale-test.js +34 -38
  22. package/dungeons/technical/scd.js +111 -128
  23. package/dungeons/technical/simple.js +134 -141
  24. package/dungeons/technical/simplest.js +54 -62
  25. package/dungeons/technical/text-generation.js +110 -146
  26. package/dungeons/vertical/ai-platform.js +296 -333
  27. package/dungeons/vertical/community.js +284 -255
  28. package/dungeons/vertical/crypto.js +395 -391
  29. package/dungeons/vertical/dating.js +411 -378
  30. package/dungeons/vertical/devtools.js +336 -298
  31. package/dungeons/vertical/ecommerce.js +316 -394
  32. package/dungeons/vertical/education.js +369 -325
  33. package/dungeons/vertical/fintech.js +358 -325
  34. package/dungeons/vertical/fitness.js +335 -291
  35. package/dungeons/vertical/food-delivery.js +343 -307
  36. package/dungeons/vertical/gaming.js +480 -444
  37. package/dungeons/vertical/healthcare.js +306 -262
  38. package/dungeons/vertical/insurance-application.js +427 -409
  39. package/dungeons/vertical/logistics.js +271 -252
  40. package/dungeons/vertical/marketplace.js +333 -323
  41. package/dungeons/vertical/media.js +382 -335
  42. package/dungeons/vertical/real-estate.js +395 -346
  43. package/dungeons/vertical/sass.js +319 -333
  44. package/dungeons/vertical/social.js +368 -316
  45. package/dungeons/vertical/travel.js +297 -295
  46. package/index.js +46 -4
  47. package/lib/core/config-validator.js +126 -28
  48. package/lib/generators/funnels.js +4 -1
  49. package/lib/orchestrators/mixpanel-sender.js +7 -0
  50. package/lib/orchestrators/user-loop.js +132 -31
  51. package/lib/templates/defaults.js +59 -59
  52. package/lib/templates/macro-presets.js +14 -2
  53. package/lib/utils/dataset-context.js +103 -0
  54. package/lib/utils/retention-curve.js +140 -0
  55. package/lib/utils/utils.js +149 -38
  56. package/lib/verify/counting.js +40 -0
  57. package/lib/verify/emulate-breakdown.js +20 -1
  58. package/lib/verify/index.js +1 -0
  59. package/lib/verify/schema-validator.js +3 -1
  60. package/package.json +11 -2
  61. package/scripts/run-dungeon.mjs +12 -1
  62. package/types.d.ts +117 -1
@@ -1,13 +1,4 @@
1
- // ── TWEAK THESE ──
2
- const SEED = "scale test";
3
- const num_days = 365;
4
- const num_users = 10_000;
5
- const avg_events_per_user_per_day = 0.14;
6
- let token = "";
7
-
8
- // ── env overrides ──
9
- if (process.env.MP_TOKEN) token = process.env.MP_TOKEN;
10
-
1
+ // ── IMPORTS ──
11
2
  import Chance from 'chance';
12
3
  let chance = new Chance();
13
4
  import dayjs from "dayjs";
@@ -15,26 +6,27 @@ import utc from "dayjs/plugin/utc.js";
15
6
  dayjs.extend(utc);
16
7
  import { uid, comma } from 'ak-tools';
17
8
  import { weighNumRange, date, integer, weighChoices } from "../../lib/utils/utils.js";
18
-
19
9
  /** @typedef {import("../../types").Dungeon} Config */
20
- /**
21
- * ═══════════════════════════════════════════════════════════════
22
- * TECHNICAL TEST: Scale & Performance
23
- * ═══════════════════════════════════════════════════════════════
24
- *
25
- * Tests high-volume generation, batch sizing, gzip compression.
26
- * - 10,000 users, 500K events, 365 days (1 year)
27
- * - gzip enabled, large batch size
28
- * - Minimal event schema (3 events, few properties)
29
- * - No hooks, no funnels, no extras
30
- *
31
- * Explicitly for performance benchmarking and verifying
32
- * large file output + batch splitting behavior.
10
+
11
+ // ── OVERVIEW ──
12
+ /*
13
+ * NAME: scale-test
14
+ * PURPOSE: High-volume scale fixture — exercises batch sizing, gzip, large file output, no hooks
15
+ * SCALE: 10,000 users, ~500K events, 365 days
16
+ * EVENTS (3): page view, click, api call
17
+ * FUNNELS (0): none
33
18
  */
34
19
 
35
- /** @type {import('../../types').Dungeon} */
20
+ // ── SCALE ──
21
+ const SEED = "scale test";
22
+ const num_days = 365;
23
+ const num_users = 10_000;
24
+ const avg_events_per_user_per_day = 0.14;
25
+ const token = process.env.MP_TOKEN || "";
26
+
27
+ // ── CONFIG ──
28
+ /** @type {Config} */
36
29
  const config = {
37
- token,
38
30
  seed: SEED,
39
31
  name: "scale-test",
40
32
  numDays: num_days,
@@ -43,18 +35,22 @@ const config = {
43
35
  format: 'json',
44
36
  gzip: true,
45
37
  concurrency: 1,
46
- region: "US",
47
- hasAnonIds: false,
48
- hasSessionIds: false,
49
- hasAdSpend: false,
50
- hasLocation: false,
51
- hasAndroidDevices: false,
52
- hasIOSDevices: false,
53
- hasDesktopDevices: false,
54
- hasBrowser: false,
55
- hasCampaigns: false,
56
- isAnonymous: false,
57
- alsoInferFunnels: false,
38
+ credentials: {
39
+ token,
40
+ region: "US",
41
+ },
42
+ switches: {
43
+ hasSessionIds: false,
44
+ hasAdSpend: false,
45
+ hasLocation: false,
46
+ hasAndroidDevices: false,
47
+ hasIOSDevices: false,
48
+ hasDesktopDevices: false,
49
+ hasBrowser: false,
50
+ hasCampaigns: false,
51
+ isAnonymous: false,
52
+ alsoInferFunnels: false,
53
+ },
58
54
  writeToDisk: false,
59
55
 
60
56
  events: [
@@ -1,42 +1,23 @@
1
- // ── TWEAK THESE ──
2
- const SEED = "simple is best";
3
- const num_days = 30;
4
- const num_users = 500;
5
- const avg_events_per_user_per_day = 3.33;
6
- let token = "";
7
-
8
- // ── env overrides ──
9
- if (process.env.MP_TOKEN) token = process.env.MP_TOKEN;
10
-
1
+ // ── IMPORTS ──
11
2
  import Chance from 'chance';
12
- const chance = new Chance();
13
3
  import dayjs from "dayjs";
14
4
  import utc from "dayjs/plugin/utc.js";
15
5
  dayjs.extend(utc);
16
- import { uid, comma } from 'ak-tools';
17
6
  import { pickAWinner, weighNumRange, date, integer, weighChoices } from "../../lib/utils/utils.js";
18
-
19
7
  /** @typedef {import("../../types").Dungeon} Config */
20
- const itemCategories = ["Books", "Movies", "Music", "Games", "Electronics", "Computers", "Smart Home", "Home", "Garden", "Pet", "Beauty", "Health", "Toys", "Kids", "Baby", "Handmade", "Sports", "Outdoors", "Automotive", "Industrial", "Entertainment", "Art", "Food", "Appliances", "Office", "Wedding", "Software"];
21
8
 
22
- const videoCategories = ["funny", "educational", "inspirational", "music", "news", "sports", "cooking", "DIY", "travel", "gaming"];
9
+ // ── OVERVIEW ──
10
+ /*
11
+ * NAME: scd
12
+ * PURPOSE: SCD-focused dungeon — user + group slowly-changing dimensions across e-commerce events
13
+ * SCALE: 500 users, ~50K events, 30 days (CSV format, 1,000 company groups)
14
+ * EVENTS (7): checkout, add to cart, page view, watch video, view item, save item, sign up, cart_abandoned
15
+ * FUNNELS (0): none
16
+ * SCDs: user — role (weekly), NPS (daily); company_id — MRR (monthly), AccountHealthScore (weekly), plan (monthly)
17
+ */
23
18
 
24
- /**
25
- * ═══════════════════════════════════════════════════════════════
26
- * DATASET OVERVIEW
27
- * ═══════════════════════════════════════════════════════════════
28
- *
29
- * SCD Test — dungeon focused on Slowly Changing Dimensions.
30
- * - 500 users over 30 days, ~50K events (CSV format)
31
- * - E-commerce events: checkout, add to cart, page view, watch video, view/save item
32
- * - User SCDs: role (weekly), NPS (daily)
33
- * - Group SCDs: MRR (monthly), AccountHealthScore (weekly), plan (monthly)
34
- * - 1,000 company groups with industry, segment, CSM assignments
35
- *
36
- * ═══════════════════════════════════════════════════════════════
37
- * ANALYTICS HOOKS (3 patterns)
38
- * ═══════════════════════════════════════════════════════════════
39
- *
19
+ // ── HOOK STORIES ──
20
+ /*
40
21
  * 1. SPEND TIERS (user hook)
41
22
  * Users with luckyNumber > 250 = "high_spender", else "budget".
42
23
  *
@@ -59,27 +40,101 @@ const videoCategories = ["funny", "educational", "inspirational", "music", "news
59
40
  * Expected: visible volume of abandoned cart events
60
41
  */
61
42
 
62
- /** @type {import('../../types').Dungeon} */
43
+ // ── SCALE ──
44
+ const SEED = "simple is best";
45
+ const NUM_DAYS = 30;
46
+ const NUM_USERS = 500;
47
+ const EVENTS_PER_DAY = 3.33;
48
+ const token = process.env.MP_TOKEN || "";
49
+
50
+ const chance = new Chance();
51
+
52
+ // ── KNOBS (tweak these to reshape stories) ──
53
+ const HIGH_SPENDER_THRESHOLD = 250;
54
+ const WEEKEND_WATCH_MULTIPLIER = 1.5;
55
+ const ABANDONMENT_DELAY_MINUTES = 30;
56
+
57
+ // ── DATA ARRAYS ──
58
+ const itemCategories = ["Books", "Movies", "Music", "Games", "Electronics", "Computers", "Smart Home", "Home", "Garden", "Pet", "Beauty", "Health", "Toys", "Kids", "Baby", "Handmade", "Sports", "Outdoors", "Automotive", "Industrial", "Entertainment", "Art", "Food", "Appliances", "Office", "Wedding", "Software"];
59
+ const videoCategories = ["funny", "educational", "inspirational", "music", "news", "sports", "cooking", "DIY", "travel", "gaming"];
60
+ const spiritAnimals = ["duck", "dog", "otter", "penguin", "cat", "elephant", "lion", "cheetah", "giraffe", "zebra", "rhino", "hippo", "whale", "dolphin", "shark", "octopus", "squid", "jellyfish", "starfish", "seahorse", "crab", "lobster", "shrimp", "clam", "snail", "slug", "butterfly", "moth", "bee", "wasp", "ant", "beetle", "ladybug", "caterpillar", "centipede", "millipede", "scorpion", "spider", "tarantula", "tick", "mite", "mosquito", "fly", "dragonfly", "damselfly", "grasshopper", "cricket", "locust", "mantis", "cockroach", "termite", "praying mantis", "walking stick", "stick bug", "leaf insect", "lacewing", "aphid", "cicada", "thrips", "psyllid", "scale insect", "whitefly", "mealybug", "planthopper", "leafhopper", "treehopper", "flea", "louse", "bedbug", "flea beetle", "weevil", "longhorn beetle", "leaf beetle", "tiger beetle", "ground beetle", "lady beetle", "firefly", "click beetle", "rove beetle", "scarab beetle", "dung beetle", "stag beetle", "rhinoceros beetle", "hercules beetle", "goliath beetle", "jewel beetle", "tortoise beetle"];
61
+ const industries = ["technology", "education", "finance", "healthcare", "retail", "manufacturing", "transportation", "entertainment", "media", "real estate", "construction", "hospitality", "energy", "utilities", "agriculture", "other"];
62
+ const csmNames = ["AK", "Neha", "Rajiv", "Deepak", "Justin", "Hans", "Katie", "Somya", "Tony", "Kaan"];
63
+
64
+ // ── HELPER FUNCTIONS ──
65
+ function handleUserHook(record) {
66
+ // classify users into spending tiers
67
+ record.spendTier = record.luckyNumber > HIGH_SPENDER_THRESHOLD ? "high_spender" : "budget";
68
+ return record;
69
+ }
70
+
71
+ function handleEventHook(record) {
72
+ // coupon users get discounted checkout amounts
73
+ if (record.event === "checkout" && record.coupon && record.coupon !== "none") {
74
+ const discountPct = parseInt(record.coupon) || 10;
75
+ record.amount = Math.round(record.amount * (1 - discountPct / 100));
76
+ record.discount_applied = true;
77
+ }
78
+ // weekend watchers get longer watch times
79
+ if (record.event === "watch video" && record.time) {
80
+ const day = dayjs(record.time).day();
81
+ if (day === 0 || day === 6) {
82
+ record.watchTimeSec = Math.round((record.watchTimeSec || 60) * WEEKEND_WATCH_MULTIPLIER);
83
+ record.is_weekend = true;
84
+ }
85
+ }
86
+ return record;
87
+ }
88
+
89
+ function handleEverythingHook(record, meta) {
90
+ // stamp superProps from profile for consistency
91
+ const profile = meta.profile;
92
+ record.forEach(e => {
93
+ e.platform = profile.platform;
94
+ e.currentTheme = profile.currentTheme;
95
+ });
96
+
97
+ const hasAddToCart = record.some(e => e.event === "add to cart");
98
+ const hasCheckout = record.some(e => e.event === "checkout");
99
+ // users who added to cart but never checked out: synthesize a cart_abandoned event
100
+ if (hasAddToCart && !hasCheckout && record.length > 2) {
101
+ const lastAdd = record.filter(e => e.event === "add to cart").pop();
102
+ if (lastAdd) {
103
+ record.push({
104
+ ...lastAdd,
105
+ event: "cart_abandoned",
106
+ time: dayjs(lastAdd.time).add(ABANDONMENT_DELAY_MINUTES, "minute").toISOString(),
107
+ user_id: lastAdd.user_id,
108
+ amount: lastAdd.amount,
109
+ });
110
+ }
111
+ }
112
+ return record;
113
+ }
114
+
115
+ // ── CONFIG ──
116
+ /** @type {Config} */
63
117
  const config = {
64
- token,
65
118
  seed: SEED,
66
- numDays: num_days,
67
- avgEventsPerUserPerDay: avg_events_per_user_per_day,
68
- numUsers: num_users,
119
+ numDays: NUM_DAYS,
120
+ avgEventsPerUserPerDay: EVENTS_PER_DAY,
121
+ numUsers: NUM_USERS,
69
122
  format: 'csv', //csv or json
70
- region: "US",
71
- hasAnonIds: false, //if true, anonymousIds are created for each user
72
- hasSessionIds: false, //if true, hasSessionIds are created for each user
73
- hasAdSpend: false,
74
- hasLocation: true,
75
- hasAndroidDevices: true,
76
- hasIOSDevices: true,
77
- hasDesktopDevices: true,
78
- hasBrowser: true,
79
- hasCampaigns: true,
80
- isAnonymous: false,
81
-
82
-
123
+ credentials: {
124
+ token,
125
+ region: "US",
126
+ },
127
+ switches: {
128
+ hasSessionIds: false, //if true, hasSessionIds are created for each user
129
+ hasAdSpend: false,
130
+ hasLocation: true,
131
+ hasAndroidDevices: true,
132
+ hasIOSDevices: true,
133
+ hasDesktopDevices: true,
134
+ hasBrowser: true,
135
+ hasCampaigns: true,
136
+ isAnonymous: false,
137
+ },
83
138
  events: [
84
139
  {
85
140
  event: "checkout",
@@ -168,14 +223,10 @@ const config = {
168
223
  platform: ["web", "mobile", "web", "mobile", "web", "web", "kiosk", "smartTV"],
169
224
  currentTheme: weighChoices(["light", "dark", "custom", "light", "dark"]),
170
225
  },
171
- /*
172
- user properties work the same as event properties
173
- each key should be an array or function reference
174
- */
175
226
  userProps: {
176
227
  title: chance.profession.bind(chance),
177
228
  luckyNumber: weighNumRange(42, 420, .3),
178
- spiritAnimal: ["duck", "dog", "otter", "penguin", "cat", "elephant", "lion", "cheetah", "giraffe", "zebra", "rhino", "hippo", "whale", "dolphin", "shark", "octopus", "squid", "jellyfish", "starfish", "seahorse", "crab", "lobster", "shrimp", "clam", "snail", "slug", "butterfly", "moth", "bee", "wasp", "ant", "beetle", "ladybug", "caterpillar", "centipede", "millipede", "scorpion", "spider", "tarantula", "tick", "mite", "mosquito", "fly", "dragonfly", "damselfly", "grasshopper", "cricket", "locust", "mantis", "cockroach", "termite", "praying mantis", "walking stick", "stick bug", "leaf insect", "lacewing", "aphid", "cicada", "thrips", "psyllid", "scale insect", "whitefly", "mealybug", "planthopper", "leafhopper", "treehopper", "flea", "louse", "bedbug", "flea beetle", "weevil", "longhorn beetle", "leaf beetle", "tiger beetle", "ground beetle", "lady beetle", "firefly", "click beetle", "rove beetle", "scarab beetle", "dung beetle", "stag beetle", "rhinoceros beetle", "hercules beetle", "goliath beetle", "jewel beetle", "tortoise beetle"],
229
+ spiritAnimal: spiritAnimals,
179
230
  spendTier: ["budget"],
180
231
  platform: ["web", "mobile", "web", "mobile", "web", "web", "kiosk", "smartTV"],
181
232
  currentTheme: weighChoices(["light", "dark", "custom", "light", "dark"]),
@@ -221,86 +272,18 @@ const config = {
221
272
  groupProps: {
222
273
  company_id: {
223
274
  name: () => { return chance.name(); },
224
- email: () => { return `CSM: ${chance.pickone(["AK", "Neha", "Rajiv", "Deepak", "Justin", "Hans", "Katie", "Somya", "Tony", "Kaan"])}`; },
225
- industry: [
226
- "technology",
227
- "education",
228
- "finance",
229
- "healthcare",
230
- "retail",
231
- "manufacturing",
232
- "transportation",
233
- "entertainment",
234
- "media",
235
- "real estate",
236
- "construction",
237
- "hospitality",
238
- "energy",
239
- "utilities",
240
- "agriculture",
241
- "other",
242
- ],
275
+ email: () => { return `CSM: ${chance.pickone(csmNames)}`; },
276
+ industry: industries,
243
277
  segment: ["SMB", "SMB", "SMB", "Mid Market", "Mid Market", "Enterprise"],
244
278
  "# active users": chance.integer({ min: 2, max: 20 })
245
279
  }
246
280
  },
247
281
  hook: function (record, type, meta) {
248
- // --- user hook: classify users into spending tiers ---
249
- if (type === "user") {
250
- record.spendTier = record.luckyNumber > 250 ? "high_spender" : "budget";
251
- return record;
252
- }
253
-
254
- // --- event hook: coupon users get discounted checkout amounts ---
255
- if (type === "event") {
256
- if (record.event === "checkout" && record.coupon && record.coupon !== "none") {
257
- const discountPct = parseInt(record.coupon) || 10;
258
- record.amount = Math.round(record.amount * (1 - discountPct / 100));
259
- record.discount_applied = true;
260
- }
261
- // weekend watchers get longer watch times
262
- if (record.event === "watch video" && record.time) {
263
- const day = dayjs(record.time).day();
264
- if (day === 0 || day === 6) {
265
- record.watchTimeSec = Math.round((record.watchTimeSec || 60) * 1.5);
266
- record.is_weekend = true;
267
- }
268
- }
269
- return record;
270
- }
271
-
272
- // --- everything hook: simulate cart abandonment ---
273
- if (type === "everything") {
274
- // stamp superProps from profile for consistency
275
- const profile = meta.profile;
276
- record.forEach(e => {
277
- e.platform = profile.platform;
278
- e.currentTheme = profile.currentTheme;
279
- });
280
-
281
- const hasAddToCart = record.some(e => e.event === "add to cart");
282
- const hasCheckout = record.some(e => e.event === "checkout");
283
- // users who added to cart but never checked out: remove checkout events (if any slipped through)
284
- // and mark them as abandoned
285
- if (hasAddToCart && !hasCheckout && record.length > 2) {
286
- const lastAdd = record.filter(e => e.event === "add to cart").pop();
287
- if (lastAdd) {
288
- record.push({
289
- ...lastAdd,
290
- event: "cart_abandoned",
291
- time: dayjs(lastAdd.time).add(30, "minute").toISOString(),
292
- user_id: lastAdd.user_id,
293
- amount: lastAdd.amount,
294
- });
295
- }
296
- }
297
- return record;
298
- }
299
-
282
+ if (type === "user") return handleUserHook(record);
283
+ if (type === "event") return handleEventHook(record);
284
+ if (type === "everything") return handleEverythingHook(record, meta);
300
285
  return record;
301
286
  }
302
287
  };
303
288
 
304
-
305
-
306
- export default config;
289
+ export default config;