make-mp-data 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.
- package/.vscode/launch.json +25 -13
- package/components/project.js +155 -0
- package/{src → components}/utils.js +41 -36
- package/index.js +41 -24
- package/package.json +9 -6
- package/schemas/adspend.js +1 -1
- package/schemas/anon.js +1 -1
- package/schemas/big.js +1 -1
- package/schemas/business.js +327 -0
- package/schemas/complex.js +1 -1
- package/schemas/foobar.js +1 -1
- package/schemas/funnels.js +1 -1
- package/schemas/mirror.js +1 -1
- package/schemas/sanity.js +118 -0
- package/schemas/session-replay.js +136 -0
- package/schemas/simple.js +2 -2
- package/scripts/jsdoctest.js +1 -1
- package/scripts/{new.sh → new-dungeon.sh} +30 -7
- package/scripts/new-project.mjs +14 -0
- package/scripts/update-deps.sh +4 -0
- package/tests/int.test.js +11 -10
- package/tests/testCases.mjs +1 -1
- package/tests/testSoup.mjs +4 -3
- package/tests/unit.test.js +15 -14
- package/tsconfig.json +1 -1
- package/types.d.ts +1 -0
- package/scripts/deps.sh +0 -3
- /package/{src → components}/chart.js +0 -0
- /package/{src → components}/cli.js +0 -0
- /package/{src → components}/defaults.js +0 -0
- /package/scripts/{go.sh → run-index.sh} +0 -0
|
@@ -13,7 +13,7 @@ const dayjs = require("dayjs");
|
|
|
13
13
|
const utc = require("dayjs/plugin/utc");
|
|
14
14
|
dayjs.extend(utc);
|
|
15
15
|
require("dotenv").config();
|
|
16
|
-
const u = require("../
|
|
16
|
+
const u = require("../components/utils");
|
|
17
17
|
const v = require("ak-tools");
|
|
18
18
|
const chance = u.initChance(SEED);
|
|
19
19
|
const num_users = 25_000
|
|
@@ -26,9 +26,10 @@ const config = {
|
|
|
26
26
|
numDays: days,
|
|
27
27
|
numEvents: num_users * 100,
|
|
28
28
|
numUsers: num_users,
|
|
29
|
-
hasAnonIds:
|
|
30
|
-
hasSessionIds:
|
|
31
|
-
|
|
29
|
+
hasAnonIds: false,
|
|
30
|
+
hasSessionIds: false,
|
|
31
|
+
format: "json",
|
|
32
|
+
alsoInferFunnels: true,
|
|
32
33
|
hasLocation: true,
|
|
33
34
|
hasAndroidDevices: true,
|
|
34
35
|
hasIOSDevices: true,
|
|
@@ -54,9 +55,31 @@ const config = {
|
|
|
54
55
|
groupKeys: [],
|
|
55
56
|
groupProps: {},
|
|
56
57
|
lookupTables: [],
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
hook: function (record, type, meta) {
|
|
59
|
+
const NOW = dayjs.unix(global.NOW);
|
|
60
|
+
|
|
61
|
+
if (type === "event") {
|
|
62
|
+
const EVENT_TIME = dayjs(record.time);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (type === "user") {
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (type === "funnel-post") {
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (type === "funnel-pre") {
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (type === "scd") {
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return record;
|
|
82
|
+
}
|
|
60
83
|
};
|
|
61
84
|
|
|
62
85
|
module.exports = config;'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import project from "../components/project.js";
|
|
2
|
+
import dotenv from "dotenv";
|
|
3
|
+
|
|
4
|
+
dotenv.config();
|
|
5
|
+
const OAUTH_TOKEN = process.env.OAUTH_TOKEN || "";
|
|
6
|
+
|
|
7
|
+
if (!OAUTH_TOKEN) throw new Error('No OAUTH_TOKEN in .env');
|
|
8
|
+
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const createdProject = await project({
|
|
11
|
+
oauth: OAUTH_TOKEN
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
console.log(createdProject);
|
package/tests/int.test.js
CHANGED
|
@@ -23,7 +23,7 @@ const { generators, orchestrators, meta } = MAIN;
|
|
|
23
23
|
const { makeAdSpend, makeEvent, makeFunnel, makeProfile, makeSCD, makeMirror } = generators;
|
|
24
24
|
const { sendToMixpanel, userLoop, validateDungeonConfig } = orchestrators;
|
|
25
25
|
const { hookArray, inferFunnels } = meta;
|
|
26
|
-
const { validEvent } = require('../
|
|
26
|
+
const { validEvent } = require('../components/utils.js');
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
// Mock the global variables
|
|
@@ -31,7 +31,7 @@ let CAMPAIGNS;
|
|
|
31
31
|
let DEFAULTS;
|
|
32
32
|
let STORAGE;
|
|
33
33
|
let CONFIG;
|
|
34
|
-
const { campaigns, devices, locations } = require('../
|
|
34
|
+
const { campaigns, devices, locations } = require('../components/defaults.js');
|
|
35
35
|
|
|
36
36
|
beforeEach(async () => {
|
|
37
37
|
// Reset global variables before each test
|
|
@@ -72,7 +72,8 @@ beforeEach(async () => {
|
|
|
72
72
|
global.DEFAULTS = DEFAULTS;
|
|
73
73
|
global.STORAGE = STORAGE;
|
|
74
74
|
global.CONFIG = CONFIG;
|
|
75
|
-
|
|
75
|
+
const FIXED_NOW = dayjs('2024-02-02').unix();
|
|
76
|
+
global.FIXED_NOW = FIXED_NOW;
|
|
76
77
|
|
|
77
78
|
});
|
|
78
79
|
|
|
@@ -137,7 +138,7 @@ describe('generators', () => {
|
|
|
137
138
|
prop3: ["value5"]
|
|
138
139
|
},
|
|
139
140
|
};
|
|
140
|
-
const result = await makeEvent("known_id", dayjs().subtract(
|
|
141
|
+
const result = await makeEvent("known_id", dayjs.unix(global.FIXED_NOW).subtract(30, 'd').unix(), eventConfig, ["anon_id"], ["session_id"]);
|
|
141
142
|
expect(result).toHaveProperty('event', 'test_event');
|
|
142
143
|
expect(result).toHaveProperty('device_id', 'anon_id');
|
|
143
144
|
// expect(result).toHaveProperty('user_id', 'known_id'); // Known ID not always on the event
|
|
@@ -154,7 +155,7 @@ describe('generators', () => {
|
|
|
154
155
|
|
|
155
156
|
test('makeEvent: opt params', async () => {
|
|
156
157
|
const eventConfig = { event: "test_event", properties: {} };
|
|
157
|
-
const result = await makeEvent("known_id",
|
|
158
|
+
const result = await makeEvent("known_id",dayjs.unix(global.FIXED_NOW).subtract(30, 'd').unix(), eventConfig);
|
|
158
159
|
expect(result).toHaveProperty('event', 'test_event');
|
|
159
160
|
expect(result).toHaveProperty('user_id', 'known_id');
|
|
160
161
|
expect(result).toHaveProperty('source', 'dm4');
|
|
@@ -170,7 +171,7 @@ describe('generators', () => {
|
|
|
170
171
|
prop2: ["value3", "value4"]
|
|
171
172
|
},
|
|
172
173
|
};
|
|
173
|
-
const result = await makeEvent("known_id",
|
|
174
|
+
const result = await makeEvent("known_id",dayjs.unix(global.FIXED_NOW).subtract(30, 'd').unix(), eventConfig, ["anon_id"], ["session_id"]);
|
|
174
175
|
expect(result.prop1 === "value1" || result.prop1 === "value2").toBeTruthy();
|
|
175
176
|
expect(result.prop2 === "value3" || result.prop2 === "value4").toBeTruthy();
|
|
176
177
|
});
|
|
@@ -189,7 +190,7 @@ describe('generators', () => {
|
|
|
189
190
|
/** @type {Record<string, SCDSchema[]>} */
|
|
190
191
|
const scd = { "scd_example": [{ distinct_id: "user1", insertTime: dayjs().toISOString(), startTime: dayjs().toISOString() }] };
|
|
191
192
|
|
|
192
|
-
const [result, converted] = await makeFunnel(funnelConfig, user,
|
|
193
|
+
const [result, converted] = await makeFunnel(funnelConfig, user,dayjs.unix(global.FIXED_NOW).subtract(30, 'd').unix(), profile, scd, {});
|
|
193
194
|
expect(result.length).toBe(2);
|
|
194
195
|
expect(converted).toBe(true);
|
|
195
196
|
expect(result.every(e => validEvent(e))).toBeTruthy();
|
|
@@ -205,7 +206,7 @@ describe('generators', () => {
|
|
|
205
206
|
const profile = { created: dayjs().toISOString(), distinct_id: "user1" };
|
|
206
207
|
const scd = { "scd_example": [{ distinct_id: "user1", insertTime: dayjs().toISOString(), startTime: dayjs().toISOString() }] };
|
|
207
208
|
|
|
208
|
-
const [result, converted] = await makeFunnel(funnelConfig, user, dayjs().unix(), profile, scd, {});
|
|
209
|
+
const [result, converted] = await makeFunnel(funnelConfig, user, dayjs.unix(global.FIXED_NOW).subtract(30, 'd').unix(), profile, scd, {});
|
|
209
210
|
expect(result.length).toBeGreaterThanOrEqual(1);
|
|
210
211
|
expect(result.length).toBeLessThanOrEqual(3);
|
|
211
212
|
expect(result.every(e => validEvent(e))).toBeTruthy();
|
|
@@ -221,7 +222,7 @@ describe('generators', () => {
|
|
|
221
222
|
const profile = { created: dayjs().toISOString(), distinct_id: "user1" };
|
|
222
223
|
const scd = { "scd_example": [{ distinct_id: "user1", insertTime: dayjs().toISOString(), startTime: dayjs().toISOString() }] };
|
|
223
224
|
|
|
224
|
-
const [result, converted] = await makeFunnel(funnelConfig, user, dayjs().unix(), profile, scd, {});
|
|
225
|
+
const [result, converted] = await makeFunnel(funnelConfig, user, dayjs.unix(global.FIXED_NOW).subtract(30, 'd').unix(), profile, scd, {});
|
|
225
226
|
expect(result.length).toBe(3);
|
|
226
227
|
expect(converted).toBe(true);
|
|
227
228
|
expect(result.every(e => validEvent(e))).toBeTruthy();
|
|
@@ -490,7 +491,7 @@ describe('orchestrators', () => {
|
|
|
490
491
|
};
|
|
491
492
|
const result = await sendToMixpanel(CONFIG, STORAGE);
|
|
492
493
|
expect(result.events.success).toBe(0);
|
|
493
|
-
expect(result.users.success).toBe(0)
|
|
494
|
+
expect(result.users.success).toBe(0);
|
|
494
495
|
expect(result.groups).toHaveLength(0);
|
|
495
496
|
});
|
|
496
497
|
|
package/tests/testCases.mjs
CHANGED
package/tests/testSoup.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { generateLineChart } from '../
|
|
2
|
-
import { TimeSoup } from '../
|
|
1
|
+
import { generateLineChart } from '../components/chart.js';
|
|
2
|
+
import { TimeSoup } from '../components/utils.js';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import { progress } from 'ak-tools';
|
|
5
5
|
import TEST_CASES from './testCases.mjs';
|
|
6
|
+
|
|
6
7
|
import execSync from 'child_process';
|
|
7
8
|
|
|
8
9
|
async function genViz(soup) {
|
|
@@ -12,7 +13,7 @@ async function genViz(soup) {
|
|
|
12
13
|
const end = dayjs().unix();
|
|
13
14
|
console.log(`\n\nTEST CASE: ${name}\n\n`);
|
|
14
15
|
for (let i = 0; i < 100_000; i++) {
|
|
15
|
-
progress('processing', i);
|
|
16
|
+
progress([['processing', i]]);
|
|
16
17
|
const time = TimeSoup(start, end, peaks, deviation, mean);
|
|
17
18
|
data.push({ time });
|
|
18
19
|
}
|
package/tests/unit.test.js
CHANGED
|
@@ -57,7 +57,7 @@ const {
|
|
|
57
57
|
|
|
58
58
|
datesBetween,
|
|
59
59
|
weighChoices
|
|
60
|
-
} = require('../
|
|
60
|
+
} = require('../components/utils.js');
|
|
61
61
|
|
|
62
62
|
const main = require('../index.js');
|
|
63
63
|
//todo: test for funnel inference
|
|
@@ -283,7 +283,7 @@ describe('generation', () => {
|
|
|
283
283
|
const user = generateUser('uuid-123', { numDays });
|
|
284
284
|
const createdDate = dayjs(user.created, 'YYYY-MM-DD');
|
|
285
285
|
expect(createdDate.isValid()).toBeTruthy();
|
|
286
|
-
expect(createdDate.isBefore(dayjs
|
|
286
|
+
expect(createdDate.isBefore(dayjs())).toBeTruthy();
|
|
287
287
|
});
|
|
288
288
|
|
|
289
289
|
|
|
@@ -393,7 +393,8 @@ describe('generation', () => {
|
|
|
393
393
|
describe('validation', () => {
|
|
394
394
|
|
|
395
395
|
beforeAll(() => {
|
|
396
|
-
global.
|
|
396
|
+
global.FIXED_NOW = 1672531200; // fixed point in time for testing
|
|
397
|
+
global.FIXED_BEGIN = global.FIXED_NOW - (60 * 60 * 24 * 30); // 30 days ago
|
|
397
398
|
});
|
|
398
399
|
|
|
399
400
|
test('events: non arrays', () => {
|
|
@@ -438,33 +439,33 @@ describe('validation', () => {
|
|
|
438
439
|
});
|
|
439
440
|
|
|
440
441
|
test('time: between', () => {
|
|
441
|
-
const chosenTime = global.
|
|
442
|
-
const earliestTime = global.
|
|
443
|
-
const latestTime = global.
|
|
442
|
+
const chosenTime = global.FIXED_NOW - (60 * 60 * 24 * 15); // 15 days ago
|
|
443
|
+
const earliestTime = global.FIXED_NOW - (60 * 60 * 24 * 30); // 30 days ago
|
|
444
|
+
const latestTime = global.FIXED_NOW;
|
|
444
445
|
expect(validTime(chosenTime, earliestTime, latestTime)).toBe(true);
|
|
445
446
|
});
|
|
446
447
|
|
|
447
448
|
test('time: outside earliest', () => {
|
|
448
|
-
const chosenTime = global.
|
|
449
|
-
const earliestTime = global.
|
|
450
|
-
const latestTime = global.
|
|
449
|
+
const chosenTime = global.FIXED_NOW - (60 * 60 * 24 * 31); // 31 days ago
|
|
450
|
+
const earliestTime = global.FIXED_NOW - (60 * 60 * 24 * 30); // 30 days ago
|
|
451
|
+
const latestTime = global.FIXED_NOW;
|
|
451
452
|
expect(validTime(chosenTime, earliestTime, latestTime)).toBe(false);
|
|
452
453
|
});
|
|
453
454
|
|
|
454
455
|
test('time: outside latest', () => {
|
|
455
456
|
const chosenTime = -1;
|
|
456
|
-
const earliestTime = global.
|
|
457
|
-
const latestTime = global.
|
|
457
|
+
const earliestTime = global.FIXED_NOW - (60 * 60 * 24 * 30); // 30 days ago
|
|
458
|
+
const latestTime = global.FIXED_NOW;
|
|
458
459
|
expect(validTime(chosenTime, earliestTime, latestTime)).toBe(false);
|
|
459
460
|
});
|
|
460
461
|
|
|
461
462
|
test('time: inference in', () => {
|
|
462
|
-
const chosenTime = global.
|
|
463
|
+
const chosenTime = global.FIXED_NOW - (60 * 60 * 24 * 15); // 15 days ago
|
|
463
464
|
expect(validTime(chosenTime)).toBe(true);
|
|
464
465
|
});
|
|
465
466
|
|
|
466
467
|
test('time: inference out', () => {
|
|
467
|
-
const chosenTime = global.
|
|
468
|
+
const chosenTime = global.FIXED_NOW - (60 * 60 * 24 * 31); // 31 days ago
|
|
468
469
|
expect(validTime(chosenTime)).toBe(false);
|
|
469
470
|
});
|
|
470
471
|
});
|
|
@@ -547,7 +548,7 @@ describe('utilities', () => {
|
|
|
547
548
|
test('date: future', () => {
|
|
548
549
|
const futureDate = date(10, false, 'YYYY-MM-DD')();
|
|
549
550
|
expect(dayjs(futureDate, 'YYYY-MM-DD').isValid()).toBeTruthy();
|
|
550
|
-
expect(dayjs(futureDate).isAfter(dayjs.unix(global.
|
|
551
|
+
expect(dayjs(futureDate).isAfter(dayjs.unix(global.FIXED_NOW))).toBeTruthy();
|
|
551
552
|
});
|
|
552
553
|
|
|
553
554
|
test('dates: pairs', () => {
|
package/tsconfig.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"include": [
|
|
13
13
|
"**/*.js"
|
|
14
|
-
, "soupTemplates.mjs", "tests/testSoup.mjs", "tests/testCases.mjs", "tests/benchmark/concurrency.mjs" ],
|
|
14
|
+
, "soupTemplates.mjs", "tests/testSoup.mjs", "tests/testCases.mjs", "tests/benchmark/concurrency.mjs", "dungeons/pos.mjs", "scripts/new-project.mjs" ],
|
|
15
15
|
"exclude": [
|
|
16
16
|
"node_modules"
|
|
17
17
|
]
|
package/types.d.ts
CHANGED
package/scripts/deps.sh
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|