make-mp-data 2.1.0 → 2.1.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/index.js CHANGED
@@ -188,22 +188,23 @@ async function main(config) {
188
188
 
189
189
  // ! DATA GENERATION ENDS HERE
190
190
 
191
- // Step 10: flush lookup tables to disk (always as CSVs)
191
+ // Step 10: Send to Mixpanel (if token provided)
192
+ // IMPORTANT: Must happen BEFORE flushing to disk, because flush() clears the arrays
193
+ let importResults;
194
+ if (validatedConfig.token) {
195
+ importResults = await sendToMixpanel(context);
196
+ }
197
+
198
+ // Step 11: Flush lookup tables to disk (always as CSVs)
192
199
  if (validatedConfig.writeToDisk) {
193
200
  await flushLookupTablesToDisk(storage, validatedConfig);
194
201
  }
195
202
 
196
- // Step 11: Flush other storage containers to disk (if writeToDisk enabled)
203
+ // Step 12: Flush other storage containers to disk (if writeToDisk enabled)
197
204
  if (validatedConfig.writeToDisk) {
198
205
  await flushStorageToDisk(storage, validatedConfig);
199
206
  }
200
207
 
201
- // Step 12: Send to Mixpanel (if token provided)
202
- let importResults;
203
- if (validatedConfig.token) {
204
- importResults = await sendToMixpanel(context);
205
- }
206
-
207
208
  // Step 13: Compile results
208
209
  jobTimer.stop(false);
209
210
  const { start, end, delta, human } = jobTimer.report(false);
@@ -28,22 +28,28 @@ export async function sendToMixpanel(context) {
28
28
  userProfilesData,
29
29
  groupEventData
30
30
  } = storage;
31
-
32
- const {
33
- token,
34
- region,
31
+
32
+ const {
33
+ token,
34
+ region,
35
35
  writeToDisk = true,
36
36
  format,
37
37
  serviceAccount,
38
38
  projectId,
39
- serviceSecret
39
+ serviceSecret,
40
+ verbose = false
40
41
  } = config;
41
-
42
+
42
43
  const importResults = { events: {}, users: {}, groups: [] };
43
44
  const isBATCH_MODE = context.isBatchMode();
44
45
  const isCLI = context.isCLI();
45
46
  const NODE_ENV = process.env.NODE_ENV || "unknown";
46
47
 
48
+ // Create verbose-aware log function
49
+ const log = (message) => {
50
+ if (verbose) console.log(message);
51
+ };
52
+
47
53
  /** @type {import('mixpanel-import').Creds} */
48
54
  const creds = { token };
49
55
  const mpImportFormat = format === "json" ? "jsonl" : "csv";
@@ -59,13 +65,11 @@ export async function sendToMixpanel(context) {
59
65
  dryRun: false,
60
66
  abridged: false,
61
67
  fixJson: false,
62
- showProgress: NODE_ENV === "dev" ? true : false,
68
+ showProgress: verbose,
63
69
  streamFormat: mpImportFormat,
64
- workers: 35
70
+ workers: 35
65
71
  };
66
72
 
67
- if (isCLI) commonOpts.showProgress = true;
68
-
69
73
  // Import events
70
74
  if (eventData || isBATCH_MODE) {
71
75
  log(`importing events to mixpanel...\n`);
@@ -224,10 +228,3 @@ export async function sendToMixpanel(context) {
224
228
  return importResults;
225
229
  }
226
230
 
227
- /**
228
- * Simple logging function
229
- * @param {string} message - Message to log
230
- */
231
- function log(message) {
232
- console.log(message);
233
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -63,14 +63,14 @@
63
63
  "@google-cloud/functions-framework": "^3.4.2",
64
64
  "@google-cloud/storage": "^7.14.0",
65
65
  "ak-fetch": "^2.0.12",
66
- "ak-gemini": "^1.0.59",
66
+ "ak-gemini": "^1.0.12",
67
67
  "ak-tools": "^1.1.12",
68
68
  "chance": "^1.1.11",
69
69
  "dayjs": "^1.11.11",
70
70
  "dotenv": "^16.4.5",
71
71
  "google-auth-library": "^9.15.0",
72
72
  "hyparquet-writer": "^0.6.1",
73
- "mixpanel-import": "^3.0.0",
73
+ "mixpanel-import": "^3.1.43",
74
74
  "p-limit": "^3.1.0",
75
75
  "seedrandom": "^3.0.5",
76
76
  "sentiment": "^5.0.2",