make-mp-data 3.0.6 → 3.1.0

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.
@@ -66,8 +66,7 @@ export async function sendToMixpanel(context) {
66
66
  log(`${'─'.repeat(50)}\n`);
67
67
 
68
68
  // Import events
69
- if (eventData?.length > 0 || isBATCH_MODE) {
70
- log(` Events`);
69
+ if (eventData?.length > 0 || isBATCH_MODE || (writeToDisk && eventData)) {
71
70
  let eventDataToImport = u.deepClone(eventData);
72
71
  const shouldReadFromFiles = isBATCH_MODE || (writeToDisk && eventData && eventData.length === 0);
73
72
  if (shouldReadFromFiles && eventData?.getWriteDir) {
@@ -76,17 +75,19 @@ export async function sendToMixpanel(context) {
76
75
  // @ts-ignore
77
76
  eventDataToImport = files.filter(f => f.includes('-EVENTS'));
78
77
  }
79
- const imported = await mp(creds, eventDataToImport, {
80
- recordType: "event",
81
- ...commonOpts,
82
- });
83
- log(` -> ${comma(imported.success)} events sent\n`);
84
- importResults.events = imported;
78
+ if (eventDataToImport?.length > 0) {
79
+ log(` Events`);
80
+ const imported = await mp(creds, eventDataToImport, {
81
+ recordType: "event",
82
+ ...commonOpts,
83
+ });
84
+ log(` -> ${comma(imported.success)} events sent\n`);
85
+ importResults.events = imported;
86
+ }
85
87
  }
86
88
 
87
89
  // Import user profiles
88
- if (userProfilesData?.length > 0 || isBATCH_MODE) {
89
- log(` User Profiles`);
90
+ if (userProfilesData?.length > 0 || isBATCH_MODE || (writeToDisk && userProfilesData)) {
90
91
  let userProfilesToImport = u.deepClone(userProfilesData);
91
92
  const shouldReadFromFiles = isBATCH_MODE || (writeToDisk && userProfilesData && userProfilesData.length === 0);
92
93
  if (shouldReadFromFiles && userProfilesData?.getWriteDir) {
@@ -95,17 +96,19 @@ export async function sendToMixpanel(context) {
95
96
  // @ts-ignore
96
97
  userProfilesToImport = files.filter(f => f.includes('-USERS'));
97
98
  }
98
- const imported = await mp(creds, userProfilesToImport, {
99
- recordType: "user",
100
- ...commonOpts,
101
- });
102
- log(` -> ${comma(imported.success)} user profiles sent\n`);
103
- importResults.users = imported;
99
+ if (userProfilesToImport?.length > 0) {
100
+ log(` User Profiles`);
101
+ const imported = await mp(creds, userProfilesToImport, {
102
+ recordType: "user",
103
+ ...commonOpts,
104
+ });
105
+ log(` -> ${comma(imported.success)} user profiles sent\n`);
106
+ importResults.users = imported;
107
+ }
104
108
  }
105
109
 
106
- // Import ad spend data
107
- if (adSpendData?.length > 0 || isBATCH_MODE) {
108
- log(` Ad Spend`);
110
+ // Import ad spend data (only when feature enabled)
111
+ if (config.hasAdSpend && (adSpendData?.length > 0 || isBATCH_MODE || (writeToDisk && adSpendData))) {
109
112
  let adSpendDataToImport = u.deepClone(adSpendData);
110
113
  const shouldReadFromFiles = isBATCH_MODE || (writeToDisk && adSpendData && adSpendData.length === 0);
111
114
  if (shouldReadFromFiles && adSpendData?.getWriteDir) {
@@ -114,20 +117,23 @@ export async function sendToMixpanel(context) {
114
117
  // @ts-ignore
115
118
  adSpendDataToImport = files.filter(f => f.includes('-ADSPEND'));
116
119
  }
117
- const imported = await mp(creds, adSpendDataToImport, {
118
- recordType: "event",
119
- ...commonOpts,
120
- });
121
- log(` -> ${comma(imported.success)} ad spend events sent\n`);
122
- importResults.adSpend = imported;
120
+ if (adSpendDataToImport?.length > 0) {
121
+ log(` Ad Spend`);
122
+ const imported = await mp(creds, adSpendDataToImport, {
123
+ recordType: "event",
124
+ ...commonOpts,
125
+ });
126
+ log(` -> ${comma(imported.success)} ad spend events sent\n`);
127
+ importResults.adSpend = imported;
128
+ }
123
129
  }
124
130
 
125
131
  // Import group profiles
126
132
  if (groupProfilesData && Array.isArray(groupProfilesData) && groupProfilesData.length > 0) {
127
133
  for (const groupEntity of groupProfilesData) {
128
- if (!groupEntity || groupEntity.length === 0) continue;
134
+ if (!groupEntity) continue;
135
+ if (groupEntity.length === 0 && !isBATCH_MODE && !writeToDisk) continue;
129
136
  const groupKey = groupEntity?.groupKey;
130
- log(` Group Profiles (${groupKey})`);
131
137
  let groupProfilesToImport = u.deepClone(groupEntity);
132
138
  const shouldReadFromFiles = isBATCH_MODE || (writeToDisk && groupEntity.length === 0);
133
139
  if (shouldReadFromFiles && groupEntity?.getWriteDir) {
@@ -136,6 +142,8 @@ export async function sendToMixpanel(context) {
136
142
  // @ts-ignore
137
143
  groupProfilesToImport = files.filter(f => f.includes(`-${groupKey}-GROUPS`));
138
144
  }
145
+ if (!groupProfilesToImport?.length) continue;
146
+ log(` Group Profiles (${groupKey})`);
139
147
  const imported = await mp({ token, groupKey }, groupProfilesToImport, {
140
148
  recordType: "group",
141
149
  ...commonOpts,
@@ -147,8 +155,7 @@ export async function sendToMixpanel(context) {
147
155
  }
148
156
 
149
157
  // Import group events
150
- if (groupEventData?.length > 0) {
151
- log(` Group Events`);
158
+ if (groupEventData?.length > 0 || isBATCH_MODE || (writeToDisk && groupEventData)) {
152
159
  let groupEventDataToImport = u.deepClone(groupEventData);
153
160
  const shouldReadFromFiles = isBATCH_MODE || (writeToDisk && groupEventData.length === 0);
154
161
  if (shouldReadFromFiles && groupEventData?.getWriteDir) {
@@ -157,13 +164,17 @@ export async function sendToMixpanel(context) {
157
164
  // @ts-ignore
158
165
  groupEventDataToImport = files.filter(f => f.includes('-GROUP-EVENTS'));
159
166
  }
160
- const imported = await mp(creds, groupEventDataToImport, {
161
- recordType: "event",
162
- ...commonOpts,
163
- strict: false
164
- });
165
- log(` -> ${comma(imported.success)} group events sent\n`);
166
- importResults.groupEvents = imported;
167
+ // Skip if no data to import (avoids mp() throwing on empty input)
168
+ if (groupEventDataToImport?.length > 0) {
169
+ log(` Group Events`);
170
+ const imported = await mp(creds, groupEventDataToImport, {
171
+ recordType: "event",
172
+ ...commonOpts,
173
+ strict: false
174
+ });
175
+ log(` -> ${comma(imported.success)} group events sent\n`);
176
+ importResults.groupEvents = imported;
177
+ }
167
178
  }
168
179
 
169
180
  // Import SCD data (requires service account)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "3.0.6",
3
+ "version": "3.1.0",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -60,7 +60,7 @@
60
60
  "dotenv": "^16.4.5",
61
61
  "hyparquet-writer": "^0.6.1",
62
62
  "mixpanel": "^0.18.0",
63
- "mixpanel-import": "^3.2.9",
63
+ "mixpanel-import": "^3.3.1",
64
64
  "p-limit": "^3.1.0",
65
65
  "pino": "^9.0.0",
66
66
  "pino-pretty": "^11.0.0",