make-mp-data 2.1.11 → 3.0.2
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/README.md +31 -0
- package/dungeons/adspend.js +35 -1
- package/dungeons/anon.js +25 -1
- package/dungeons/array-of-object-lookup.js +201 -0
- package/dungeons/benchmark-heavy.js +241 -0
- package/dungeons/benchmark-light.js +141 -0
- package/dungeons/big.js +10 -9
- package/dungeons/business.js +60 -12
- package/dungeons/complex.js +35 -1
- package/dungeons/copilot.js +383 -0
- package/dungeons/education.js +1005 -0
- package/dungeons/experiments.js +18 -4
- package/dungeons/fintech.js +976 -0
- package/dungeons/foobar.js +32 -0
- package/dungeons/food.js +988 -0
- package/dungeons/funnels.js +38 -1
- package/dungeons/gaming.js +26 -5
- package/dungeons/media.js +861 -270
- package/dungeons/mil.js +31 -3
- package/dungeons/mirror.js +33 -1
- package/dungeons/retention-cadence.js +211 -0
- package/dungeons/rpg.js +1178 -0
- package/dungeons/sanity.js +32 -2
- package/dungeons/sass.js +923 -0
- package/dungeons/scd.js +47 -1
- package/dungeons/simple.js +29 -14
- package/dungeons/social.js +928 -0
- package/dungeons/streaming.js +373 -0
- package/dungeons/strict-event-test.js +30 -0
- package/dungeons/student-teacher.js +19 -5
- package/dungeons/text-generation.js +120 -84
- package/dungeons/too-big-events.js +203 -0
- package/dungeons/{userAgent.js → user-agent.js} +23 -2
- package/entry.js +5 -4
- package/index.js +41 -54
- package/lib/core/config-validator.js +122 -7
- package/lib/core/context.js +7 -14
- package/lib/core/storage.js +57 -25
- package/lib/generators/adspend.js +12 -12
- package/lib/generators/events.js +6 -5
- package/lib/generators/funnels.js +32 -10
- package/lib/generators/product-lookup.js +262 -0
- package/lib/generators/product-names.js +195 -0
- package/lib/generators/profiles.js +3 -3
- package/lib/generators/scd.js +13 -3
- package/lib/generators/text.js +17 -4
- package/lib/orchestrators/mixpanel-sender.js +244 -204
- package/lib/orchestrators/user-loop.js +54 -16
- package/lib/templates/phrases.js +473 -16
- package/lib/templates/schema.d.ts +173 -0
- package/lib/templates/verbose-schema.js +140 -206
- package/lib/utils/chart.js +210 -0
- package/lib/utils/function-registry.js +285 -0
- package/lib/utils/json-evaluator.js +172 -0
- package/lib/utils/logger.js +34 -0
- package/lib/utils/utils.js +41 -4
- package/package.json +12 -21
- package/types.d.ts +15 -5
- package/dungeons/ai-chat-analytics-ed.js +0 -274
- package/dungeons/money2020-ed-also.js +0 -277
- package/dungeons/money2020-ed.js +0 -579
- package/lib/generators/text-bak-old.js +0 -1121
- package/lib/orchestrators/worker-manager.js +0 -203
- package/lib/templates/hooks-instructions.txt +0 -434
- package/lib/templates/phrases-bak.js +0 -925
- package/lib/templates/prompt (old).txt +0 -98
- package/lib/templates/schema-instructions.txt +0 -155
- package/lib/templates/scratch-dungeon-template.js +0 -116
- package/lib/templates/textQuickTest.js +0 -172
- package/lib/utils/ai.js +0 -120
- package/lib/utils/project.js +0 -166
package/lib/utils/project.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
import * as akTools from 'ak-tools';
|
|
3
|
-
const { rand, makeName } = akTools;
|
|
4
|
-
let { OAUTH_TOKEN = "" } = process.env;
|
|
5
|
-
const { NODE_ENV = "unknown" } = process.env;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Main function to create a project and add group keys to it.
|
|
9
|
-
*
|
|
10
|
-
* @param {Object} params - Parameters for the function.
|
|
11
|
-
* @param {string} [params.oauth=""] - OAuth token for authentication.
|
|
12
|
-
* @param {string} [params.orgId=""] - Organization ID.
|
|
13
|
-
* @param {Array<Object>} [params.groups=[]] - List of groups to add to the project.
|
|
14
|
-
* @param {string} [params.name=""] - Name of the user.
|
|
15
|
-
* @param {string} [params.email=""] - Email of the user.
|
|
16
|
-
* @param {string} [params.projectName=""] - Name of the project.
|
|
17
|
-
* @returns {Promise<Object>} The created project with additional group keys.
|
|
18
|
-
* @throws Will throw an error if OAUTH_TOKEN is not set.
|
|
19
|
-
* @throws Will throw an error if orgId is not found.
|
|
20
|
-
*/
|
|
21
|
-
async function main(params = {}) {
|
|
22
|
-
let { oauth = "", orgId = "", groups = [], name = "", email = "", projectName } = params;
|
|
23
|
-
if (oauth) OAUTH_TOKEN = oauth;
|
|
24
|
-
if (!OAUTH_TOKEN) throw new Error('No OAUTH_TOKEN in .env');
|
|
25
|
-
if (!orgId) {
|
|
26
|
-
({ orgId, name, email } = await getUser());
|
|
27
|
-
}
|
|
28
|
-
if (!orgId) throw new Error('No orgId found');
|
|
29
|
-
if (!projectName) projectName = makeName();
|
|
30
|
-
const project = await makeProject(orgId);
|
|
31
|
-
project.user = name;
|
|
32
|
-
project.email = email;
|
|
33
|
-
project.groups = groups;
|
|
34
|
-
project.orgId = orgId;
|
|
35
|
-
const groupKeys = [
|
|
36
|
-
// { display_name: 'Account', property_name: 'account_id' },
|
|
37
|
-
];
|
|
38
|
-
groupKeys.push(...groups);
|
|
39
|
-
const addedGroupKeys = await addGroupKeys(groupKeys, project.id);
|
|
40
|
-
project.groupsAdded = addedGroupKeys;
|
|
41
|
-
|
|
42
|
-
return project;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
async function makeProject(orgId, oauthToken = OAUTH_TOKEN) {
|
|
47
|
-
const excludedOrgs = [
|
|
48
|
-
1, // Mixpanel
|
|
49
|
-
328203, // Mixpanel Demo
|
|
50
|
-
1673847, // SE Demo
|
|
51
|
-
1866253 // Demo Projects
|
|
52
|
-
];
|
|
53
|
-
if (!orgId || !oauthToken) throw new Error('Missing orgId or oauthToken');
|
|
54
|
-
const url = `https://mixpanel.com/api/app/organizations/${orgId}/create-project`;
|
|
55
|
-
const projectPayload = {
|
|
56
|
-
"cluster_id": 1,
|
|
57
|
-
"project_name": `GTM Metrics: Test Env ${rand(1000, 9999)}`,
|
|
58
|
-
"timezone_id": 404
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const payload = {
|
|
62
|
-
method: 'POST',
|
|
63
|
-
|
|
64
|
-
headers: {
|
|
65
|
-
Authorization: `Bearer ${oauthToken}`,
|
|
66
|
-
},
|
|
67
|
-
body: JSON.stringify(projectPayload)
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const projectsReq = await fetch(url, payload);
|
|
72
|
-
const projectsRes = await projectsReq.json();
|
|
73
|
-
const { api_secret, id, name, token } = projectsRes.results;
|
|
74
|
-
|
|
75
|
-
const data = {
|
|
76
|
-
api_secret,
|
|
77
|
-
id,
|
|
78
|
-
name,
|
|
79
|
-
token,
|
|
80
|
-
url: `https://mixpanel.com/project/${id}/app/settings#project/${id}`
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return data;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function getUser(oauthToken = OAUTH_TOKEN) {
|
|
88
|
-
const user = {};
|
|
89
|
-
try {
|
|
90
|
-
if (oauthToken) {
|
|
91
|
-
const info = await fetch(`https://mixpanel.com/api/app/me/?include_workspace_users=false`, { headers: { Authorization: `Bearer ${oauthToken}` } });
|
|
92
|
-
const data = await info.json();
|
|
93
|
-
if (data?.results) {
|
|
94
|
-
const { user_name = "", user_email = "" } = data.results;
|
|
95
|
-
if (user_name) user.name = user_name;
|
|
96
|
-
if (user_email) user.email = user_email;
|
|
97
|
-
const foundOrg = Object.values(data.results.organizations).filter(o => o.name.includes(user_name))?.pop();
|
|
98
|
-
if (foundOrg) {
|
|
99
|
-
user.orgId = foundOrg.id?.toString();
|
|
100
|
-
user.orgName = foundOrg.name;
|
|
101
|
-
}
|
|
102
|
-
if (!foundOrg) {
|
|
103
|
-
// the name is not in the orgs, so we need to find the org in which the user is the owner
|
|
104
|
-
const ignoreProjects = [1673847, 1866253, 328203];
|
|
105
|
-
const possibleOrg = Object.values(data.results.organizations)
|
|
106
|
-
.filter(o => o.role === 'owner')
|
|
107
|
-
.filter(o => !ignoreProjects.includes(o.id))?.pop();
|
|
108
|
-
if (possibleOrg) {
|
|
109
|
-
user.orgId = possibleOrg?.id?.toString();
|
|
110
|
-
user.orgName = possibleOrg.name;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (err) {
|
|
117
|
-
console.error('get user err', err);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return user;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
async function addGroupKeys(groupKeyDfns = [], projectId, oauthToken = OAUTH_TOKEN) {
|
|
125
|
-
const url = `https://mixpanel.com/api/app/projects/${projectId}/data-groups/`;
|
|
126
|
-
const results = [];
|
|
127
|
-
loopKeys: for (const { display_name, property_name } of groupKeyDfns) {
|
|
128
|
-
const body = {
|
|
129
|
-
display_name,
|
|
130
|
-
property_name
|
|
131
|
-
};
|
|
132
|
-
const payload = {
|
|
133
|
-
method: 'POST',
|
|
134
|
-
headers: {
|
|
135
|
-
Authorization: `Bearer ${oauthToken}`,
|
|
136
|
-
'Content-Type': 'application/json'
|
|
137
|
-
},
|
|
138
|
-
body: JSON.stringify(body)
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
const res = await fetch(url, payload);
|
|
143
|
-
const data = await res.json();
|
|
144
|
-
results.push(data?.results);
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
console.error('add group keys err', err);
|
|
148
|
-
continue loopKeys;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
return results;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
157
|
-
main()
|
|
158
|
-
.then((result)=>{
|
|
159
|
-
if (NODE_ENV === "dev") debugger;
|
|
160
|
-
})
|
|
161
|
-
.catch((error)=>{
|
|
162
|
-
if (NODE_ENV === "dev") debugger;
|
|
163
|
-
})
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export default main;
|