prepare-package 1.1.4 → 1.1.5

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 (3) hide show
  1. package/dist/index.js +1 -161
  2. package/package.json +1 -2
  3. package/src/index.js +1 -161
package/dist/index.js CHANGED
@@ -74,13 +74,7 @@ module.exports = async function (options) {
74
74
  // Handle post install
75
75
  if (options.isPostInstall) {
76
76
  // Send analytics
77
- await sendAnalytics(thisPackageJSON, theirPackageJSON)
78
- .then((r) => {
79
- console.log(chalk.green(`[prepare-package]: Sent analytics code=${r.status}`));
80
- })
81
- .catch(e => {
82
- console.log(chalk.red(`[prepare-package]: Failed to send analytics`, e));
83
- });
77
+ // ... moveed to another package
84
78
  }
85
79
 
86
80
  // If purge is disabled, then return
@@ -101,157 +95,3 @@ module.exports = async function (options) {
101
95
  })
102
96
  }
103
97
 
104
- // Send analytics
105
- function sendAnalytics(thisPackageJSON, theirPackageJSON) {
106
- return new Promise(async function(resolve, reject) {
107
- const uuidv5 = require('uuid').v5;
108
- const os = require('os');
109
- const userInfo = os.userInfo();
110
-
111
- // Build url and body
112
- const analyticsId = 'G-9YP4NNBLY3';
113
- const analyticsSecret = 'w3Z2tfucR9KFPB8it5WkyQ';
114
- const url = `https://www.google-analytics.com/mp/collect?measurement_id=${analyticsId}&api_secret=${analyticsSecret}`;
115
- const mac = getDeviceUniqueId();
116
- const uuid = uuidv5(mac, '4caf995a-3d43-451b-b34d-e535d2663bc1');
117
- const simpleOS = getSimpleOS(os.platform());
118
- const name = (theirPackageJSON.name || 'unknown')
119
- // Replace anything not a letter, number, or underscore with an underscore
120
- .replace(/[^a-zA-Z0-9_]/g, '_')
121
- // Remove leading and trailing underscores
122
- .replace(/^_+|_+$/g, '')
123
- // Remove multiple underscores
124
- .replace(/_+/g, '_');
125
-
126
- // Build body
127
- const body = {
128
- client_id: uuid,
129
- user_id: uuid,
130
- // timestamp_micros: new Date().getTime() * 1000,
131
- user_properties: {
132
- // operating_system: simpleOS, // CAUSES EVENT TO NOT BE SENT
133
- },
134
- user_data: {
135
- },
136
- // consent: {},
137
- // non_personalized_ads: false,
138
- events: [{
139
- name: name,
140
- params: {
141
- packageName: theirPackageJSON.name,
142
- packageVersion: theirPackageJSON.version,
143
- preparePackageVersion: thisPackageJSON.version,
144
- os: simpleOS,
145
- platform: os.platform(),
146
- arch: os.arch(),
147
- release: os.release(),
148
- hostname: os.hostname(),
149
- cpus: os.cpus().length,
150
- memory: os.totalmem(),
151
- uptime: os.uptime(),
152
- username: userInfo.username,
153
- homedir: userInfo.homedir,
154
- shell: userInfo.shell,
155
- uid: userInfo.uid,
156
- gid: userInfo.gid,
157
- },
158
- }],
159
- }
160
-
161
- // Get the user's location
162
- const savePath = path.resolve(os.tmpdir(), 'prepare-package-geolocation-cache.json');
163
- const geolocation = await fetch('https://ipapi.co/json/', {
164
- response: 'json',
165
- tries: 2,
166
- timeout: 30000,
167
- })
168
- .then((r) => {
169
- // Save to tmpdir
170
- jetpack.write(savePath, JSON.stringify(r, null, 2));
171
-
172
- return r;
173
- })
174
- .catch((e) => {
175
- console.log(chalk.red(`[prepare-package]: Failed to get geolocation`, e));
176
-
177
- // Try to get from cache
178
- if (jetpack.exists(savePath)) {
179
- console.log(chalk.blue(`[prepare-package]: Used cached geolocation`));
180
-
181
- return JSON.parse(jetpack.read(savePath));
182
- }
183
- });
184
-
185
- // Add the geolocation to the body
186
- if (geolocation) {
187
- body.user_data.city = geolocation.city || 'Unknown';
188
- body.user_data.region = geolocation.region || 'Unknown';
189
- body.user_data.country = geolocation.country || 'Unknown';
190
-
191
- body.user_properties.language = (geolocation.languages || 'Unknown').split(',')[0];
192
- }
193
-
194
- // Log the options
195
- // console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`), body, body.events[0].params);
196
- console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`));
197
-
198
- // Send event
199
- fetch(url, {
200
- method: 'post',
201
- response: 'raw',
202
- tries: 2,
203
- timeout: 30000,
204
- body: body,
205
- })
206
- .then((r) => {
207
- resolve(r);
208
- })
209
- .catch((e) => {
210
- reject(e);
211
- });
212
- });
213
- }
214
-
215
- const getDeviceUniqueId = () => {
216
- const os = require('os');
217
- const interfaces = os.networkInterfaces();
218
-
219
- // Find the first valid MAC address
220
- for (const name in interfaces) {
221
- for (const net of interfaces[name]) {
222
- if (!net.internal && net.mac && net.mac !== '00:00:00:00:00:00') {
223
- return net.mac;
224
- }
225
- }
226
- }
227
-
228
- // Log
229
- console.warn('No valid MAC address found. Generating a random MAC address.');
230
-
231
- // Generate a random MAC address
232
- const hexDigits = '0123456789ABCDEF';
233
- let mac = '';
234
- for (let i = 0; i < 6; i++) {
235
- let byte = '';
236
- for (let j = 0; j < 2; j++) {
237
- byte += hexDigits.charAt(Math.floor(Math.random() * 16));
238
- }
239
- mac += byte;
240
- if (i !== 5) mac += ':';
241
- }
242
- return mac;
243
- };
244
-
245
- const getSimpleOS = (platform) => {
246
- switch (platform) {
247
- case 'darwin':
248
- return 'mac';
249
- case 'win32':
250
- return 'windows';
251
- case 'linux':
252
- return 'linux';
253
- default:
254
- return platform;
255
- }
256
- };
257
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Prepare a Node.js package before being published",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -37,7 +37,6 @@
37
37
  "dependencies": {
38
38
  "chalk": "^4.1.2",
39
39
  "fs-jetpack": "^4.3.1",
40
- "uuid": "^9.0.1",
41
40
  "wonderful-fetch": "^1.1.9"
42
41
  },
43
42
  "devDependencies": {
package/src/index.js CHANGED
@@ -74,13 +74,7 @@ module.exports = async function (options) {
74
74
  // Handle post install
75
75
  if (options.isPostInstall) {
76
76
  // Send analytics
77
- await sendAnalytics(thisPackageJSON, theirPackageJSON)
78
- .then((r) => {
79
- console.log(chalk.green(`[prepare-package]: Sent analytics code=${r.status}`));
80
- })
81
- .catch(e => {
82
- console.log(chalk.red(`[prepare-package]: Failed to send analytics`, e));
83
- });
77
+ // ... moveed to another package
84
78
  }
85
79
 
86
80
  // If purge is disabled, then return
@@ -101,157 +95,3 @@ module.exports = async function (options) {
101
95
  })
102
96
  }
103
97
 
104
- // Send analytics
105
- function sendAnalytics(thisPackageJSON, theirPackageJSON) {
106
- return new Promise(async function(resolve, reject) {
107
- const uuidv5 = require('uuid').v5;
108
- const os = require('os');
109
- const userInfo = os.userInfo();
110
-
111
- // Build url and body
112
- const analyticsId = 'G-9YP4NNBLY3';
113
- const analyticsSecret = 'w3Z2tfucR9KFPB8it5WkyQ';
114
- const url = `https://www.google-analytics.com/mp/collect?measurement_id=${analyticsId}&api_secret=${analyticsSecret}`;
115
- const mac = getDeviceUniqueId();
116
- const uuid = uuidv5(mac, '4caf995a-3d43-451b-b34d-e535d2663bc1');
117
- const simpleOS = getSimpleOS(os.platform());
118
- const name = (theirPackageJSON.name || 'unknown')
119
- // Replace anything not a letter, number, or underscore with an underscore
120
- .replace(/[^a-zA-Z0-9_]/g, '_')
121
- // Remove leading and trailing underscores
122
- .replace(/^_+|_+$/g, '')
123
- // Remove multiple underscores
124
- .replace(/_+/g, '_');
125
-
126
- // Build body
127
- const body = {
128
- client_id: uuid,
129
- user_id: uuid,
130
- // timestamp_micros: new Date().getTime() * 1000,
131
- user_properties: {
132
- // operating_system: simpleOS, // CAUSES EVENT TO NOT BE SENT
133
- },
134
- user_data: {
135
- },
136
- // consent: {},
137
- // non_personalized_ads: false,
138
- events: [{
139
- name: name,
140
- params: {
141
- packageName: theirPackageJSON.name,
142
- packageVersion: theirPackageJSON.version,
143
- preparePackageVersion: thisPackageJSON.version,
144
- os: simpleOS,
145
- platform: os.platform(),
146
- arch: os.arch(),
147
- release: os.release(),
148
- hostname: os.hostname(),
149
- cpus: os.cpus().length,
150
- memory: os.totalmem(),
151
- uptime: os.uptime(),
152
- username: userInfo.username,
153
- homedir: userInfo.homedir,
154
- shell: userInfo.shell,
155
- uid: userInfo.uid,
156
- gid: userInfo.gid,
157
- },
158
- }],
159
- }
160
-
161
- // Get the user's location
162
- const savePath = path.resolve(os.tmpdir(), 'prepare-package-geolocation-cache.json');
163
- const geolocation = await fetch('https://ipapi.co/json/', {
164
- response: 'json',
165
- tries: 2,
166
- timeout: 30000,
167
- })
168
- .then((r) => {
169
- // Save to tmpdir
170
- jetpack.write(savePath, JSON.stringify(r, null, 2));
171
-
172
- return r;
173
- })
174
- .catch((e) => {
175
- console.log(chalk.red(`[prepare-package]: Failed to get geolocation`, e));
176
-
177
- // Try to get from cache
178
- if (jetpack.exists(savePath)) {
179
- console.log(chalk.blue(`[prepare-package]: Used cached geolocation`));
180
-
181
- return JSON.parse(jetpack.read(savePath));
182
- }
183
- });
184
-
185
- // Add the geolocation to the body
186
- if (geolocation) {
187
- body.user_data.city = geolocation.city || 'Unknown';
188
- body.user_data.region = geolocation.region || 'Unknown';
189
- body.user_data.country = geolocation.country || 'Unknown';
190
-
191
- body.user_properties.language = (geolocation.languages || 'Unknown').split(',')[0];
192
- }
193
-
194
- // Log the options
195
- // console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`), body, body.events[0].params);
196
- console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`));
197
-
198
- // Send event
199
- fetch(url, {
200
- method: 'post',
201
- response: 'raw',
202
- tries: 2,
203
- timeout: 30000,
204
- body: body,
205
- })
206
- .then((r) => {
207
- resolve(r);
208
- })
209
- .catch((e) => {
210
- reject(e);
211
- });
212
- });
213
- }
214
-
215
- const getDeviceUniqueId = () => {
216
- const os = require('os');
217
- const interfaces = os.networkInterfaces();
218
-
219
- // Find the first valid MAC address
220
- for (const name in interfaces) {
221
- for (const net of interfaces[name]) {
222
- if (!net.internal && net.mac && net.mac !== '00:00:00:00:00:00') {
223
- return net.mac;
224
- }
225
- }
226
- }
227
-
228
- // Log
229
- console.warn('No valid MAC address found. Generating a random MAC address.');
230
-
231
- // Generate a random MAC address
232
- const hexDigits = '0123456789ABCDEF';
233
- let mac = '';
234
- for (let i = 0; i < 6; i++) {
235
- let byte = '';
236
- for (let j = 0; j < 2; j++) {
237
- byte += hexDigits.charAt(Math.floor(Math.random() * 16));
238
- }
239
- mac += byte;
240
- if (i !== 5) mac += ':';
241
- }
242
- return mac;
243
- };
244
-
245
- const getSimpleOS = (platform) => {
246
- switch (platform) {
247
- case 'darwin':
248
- return 'mac';
249
- case 'win32':
250
- return 'windows';
251
- case 'linux':
252
- return 'linux';
253
- default:
254
- return platform;
255
- }
256
- };
257
-