@strapi/strapi 4.5.3 → 4.5.4

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/lib/Strapi.js CHANGED
@@ -242,11 +242,14 @@ class Strapi {
242
242
  sendStartupTelemetry() {
243
243
  // Emit started event.
244
244
  // do not await to avoid slower startup
245
+ // This event is anonymous
245
246
  this.telemetry.send('didStartServer', {
246
- database: strapi.config.get('database.connection.client'),
247
- plugins: Object.keys(strapi.plugins),
248
- // TODO: to add back
249
- // providers: this.config.installedProviders,
247
+ groupProperties: {
248
+ database: strapi.config.get('database.connection.client'),
249
+ plugins: Object.keys(strapi.plugins),
250
+ // TODO: to add back
251
+ // providers: this.config.installedProviders,
252
+ },
250
253
  });
251
254
  }
252
255
 
@@ -53,12 +53,12 @@ const generateNewPackageJSON = (packageObj) => {
53
53
 
54
54
  const sendEvent = async (uuid) => {
55
55
  try {
56
- await fetch('https://analytics.strapi.io/track', {
56
+ await fetch('https://analytics.strapi.io/api/v2/track', {
57
57
  method: 'POST',
58
58
  body: JSON.stringify({
59
59
  event: 'didOptInTelemetry',
60
- uuid,
61
60
  deviceId: machineID(),
61
+ groupProperties: { projectId: uuid },
62
62
  }),
63
63
  headers: { 'Content-Type': 'application/json' },
64
64
  });
@@ -28,12 +28,12 @@ const writePackageJSON = async (path, file, spacing) => {
28
28
 
29
29
  const sendEvent = async (uuid) => {
30
30
  try {
31
- await fetch('https://analytics.strapi.io/track', {
31
+ await fetch('https://analytics.strapi.io/api/v2/track', {
32
32
  method: 'POST',
33
33
  body: JSON.stringify({
34
34
  event: 'didOptOutTelemetry',
35
- uuid,
36
35
  deviceId: machineID(),
36
+ groupProperties: { projectId: uuid },
37
37
  }),
38
38
  headers: { 'Content-Type': 'application/json' },
39
39
  });
@@ -293,40 +293,48 @@ const buildRelationsStore = ({ uid, data }) => {
293
293
  break;
294
294
  }
295
295
  case 'component': {
296
- return castArray(value).reduce(
297
- (relationsStore, componentValue) =>
298
- mergeWith(
299
- relationsStore,
300
- buildRelationsStore({
301
- uid: attribute.component,
302
- data: componentValue,
303
- }),
304
- (objValue, srcValue) => {
305
- if (isArray(objValue)) {
306
- return objValue.concat(srcValue);
307
- }
296
+ return castArray(value).reduce((relationsStore, componentValue) => {
297
+ if (!attribute.component) {
298
+ throw new ValidationError(
299
+ `Cannot build relations store from component, component identifier is undefined`
300
+ );
301
+ }
302
+
303
+ return mergeWith(
304
+ relationsStore,
305
+ buildRelationsStore({
306
+ uid: attribute.component,
307
+ data: componentValue,
308
+ }),
309
+ (objValue, srcValue) => {
310
+ if (isArray(objValue)) {
311
+ return objValue.concat(srcValue);
308
312
  }
309
- ),
310
- result
311
- );
313
+ }
314
+ );
315
+ }, result);
312
316
  }
313
317
  case 'dynamiczone': {
314
- return value.reduce(
315
- (relationsStore, dzValue) =>
316
- mergeWith(
317
- relationsStore,
318
- buildRelationsStore({
319
- uid: dzValue.__component,
320
- data: dzValue,
321
- }),
322
- (objValue, srcValue) => {
323
- if (isArray(objValue)) {
324
- return objValue.concat(srcValue);
325
- }
318
+ return value.reduce((relationsStore, dzValue) => {
319
+ if (!dzValue.__component) {
320
+ throw new ValidationError(
321
+ `Cannot build relations store from dynamiczone, component identifier is undefined`
322
+ );
323
+ }
324
+
325
+ return mergeWith(
326
+ relationsStore,
327
+ buildRelationsStore({
328
+ uid: dzValue.__component,
329
+ data: dzValue,
330
+ }),
331
+ (objValue, srcValue) => {
332
+ if (isArray(objValue)) {
333
+ return objValue.concat(srcValue);
326
334
  }
327
- ),
328
- result
329
- );
335
+ }
336
+ );
337
+ }, result);
330
338
  }
331
339
  default:
332
340
  break;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const crypto = require('crypto');
4
+
5
+ const generateAdminUserHash = () => {
6
+ const ctx = strapi?.requestContext?.get();
7
+ if (!ctx?.state?.user) {
8
+ return '';
9
+ }
10
+ return crypto.createHash('sha256').update(ctx.state.user.email).digest('hex');
11
+ };
12
+
13
+ module.exports = {
14
+ generateAdminUserHash,
15
+ };
@@ -55,10 +55,12 @@ const createTelemetryInstance = (strapi) => {
55
55
  return sendEvent(
56
56
  'didCheckLicense',
57
57
  {
58
- licenseInfo: {
59
- ...ee.licenseInfo,
60
- projectHash: hashProject(strapi),
61
- dependencyHash: hashDep(strapi),
58
+ groupProperties: {
59
+ licenseInfo: {
60
+ ...ee.licenseInfo,
61
+ projectHash: hashProject(strapi),
62
+ dependencyHash: hashDep(strapi),
63
+ },
62
64
  },
63
65
  },
64
66
  {
@@ -19,7 +19,7 @@ const createMiddleware = ({ sendEvent }) => {
19
19
 
20
20
  // Send max. 1000 events per day.
21
21
  if (_state.counter < 1000) {
22
- sendEvent('didReceiveRequest', { url: ctx.request.url });
22
+ sendEvent('didReceiveRequest', { eventProperties: { url: ctx.request.url } });
23
23
 
24
24
  // Increase counter.
25
25
  _state.counter += 1;
@@ -10,7 +10,7 @@ const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
10
10
  const { env } = require('@strapi/utils');
11
11
  const ee = require('../../utils/ee');
12
12
  const machineID = require('../../utils/machine-id');
13
- const stringifyDeep = require('./stringify-deep');
13
+ const { generateAdminUserHash } = require('./admin-user-hash');
14
14
 
15
15
  const defaultQueryOpts = {
16
16
  timeout: 1000,
@@ -42,41 +42,49 @@ module.exports = (strapi) => {
42
42
  const serverRootPath = strapi.dirs.app.root;
43
43
  const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');
44
44
 
45
- const anonymousMetadata = {
45
+ const anonymousUserProperties = {
46
46
  environment: strapi.config.environment,
47
47
  os: os.type(),
48
48
  osPlatform: os.platform(),
49
49
  osArch: os.arch(),
50
50
  osRelease: os.release(),
51
51
  nodeVersion: process.versions.node,
52
+ };
53
+
54
+ const anonymousGroupProperties = {
52
55
  docker: process.env.DOCKER || isDocker(),
53
56
  isCI: ciEnv.isCI,
54
57
  version: strapi.config.get('info.strapi'),
55
58
  projectType: isEE ? 'Enterprise' : 'Community',
56
59
  useTypescriptOnServer: isUsingTypeScriptSync(serverRootPath),
57
60
  useTypescriptOnAdmin: isUsingTypeScriptSync(adminRootPath),
61
+ projectId: uuid,
58
62
  isHostedOnStrapiCloud: env('STRAPI_HOSTING', null) === 'strapi.cloud',
59
63
  };
60
64
 
61
- addPackageJsonStrapiMetadata(anonymousMetadata, strapi);
65
+ addPackageJsonStrapiMetadata(anonymousGroupProperties, strapi);
62
66
 
63
67
  return async (event, payload = {}, opts = {}) => {
68
+ const userId = generateAdminUserHash();
69
+
64
70
  const reqParams = {
65
71
  method: 'POST',
66
72
  body: JSON.stringify({
67
73
  event,
68
- uuid,
74
+ userId,
69
75
  deviceId,
70
- properties: stringifyDeep({
71
- ...payload,
72
- ...anonymousMetadata,
73
- }),
76
+ eventProperties: payload.eventProperties,
77
+ userProperties: userId ? { ...anonymousUserProperties, ...payload.userProperties } : {},
78
+ groupProperties: {
79
+ ...anonymousGroupProperties,
80
+ ...payload.groupProperties,
81
+ },
74
82
  }),
75
83
  ..._.merge({}, defaultQueryOpts, opts),
76
84
  };
77
85
 
78
86
  try {
79
- const res = await fetch(`${ANALYTICS_URI}/track`, reqParams);
87
+ const res = await fetch(`${ANALYTICS_URI}/api/v2/track`, reqParams);
80
88
  return res.ok;
81
89
  } catch (err) {
82
90
  return false;
@@ -17,7 +17,7 @@ try {
17
17
  process.env.npm_config_global === 'true' ||
18
18
  JSON.parse(process.env.npm_config_argv).original.includes('global')
19
19
  ) {
20
- fetch('https://analytics.strapi.io/track', {
20
+ fetch('https://analytics.strapi.io/api/v2/track', {
21
21
  method: 'POST',
22
22
  body: JSON.stringify({
23
23
  event: 'didInstallStrapi',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.5.3",
3
+ "version": "4.5.4",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -80,18 +80,18 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.4.3",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.5.3",
84
- "@strapi/database": "4.5.3",
85
- "@strapi/generate-new": "4.5.3",
86
- "@strapi/generators": "4.5.3",
87
- "@strapi/logger": "4.5.3",
88
- "@strapi/permissions": "4.5.3",
89
- "@strapi/plugin-content-manager": "4.5.3",
90
- "@strapi/plugin-content-type-builder": "4.5.3",
91
- "@strapi/plugin-email": "4.5.3",
92
- "@strapi/plugin-upload": "4.5.3",
93
- "@strapi/typescript-utils": "4.5.3",
94
- "@strapi/utils": "4.5.3",
83
+ "@strapi/admin": "4.5.4",
84
+ "@strapi/database": "4.5.4",
85
+ "@strapi/generate-new": "4.5.4",
86
+ "@strapi/generators": "4.5.4",
87
+ "@strapi/logger": "4.5.4",
88
+ "@strapi/permissions": "4.5.4",
89
+ "@strapi/plugin-content-manager": "4.5.4",
90
+ "@strapi/plugin-content-type-builder": "4.5.4",
91
+ "@strapi/plugin-email": "4.5.4",
92
+ "@strapi/plugin-upload": "4.5.4",
93
+ "@strapi/typescript-utils": "4.5.4",
94
+ "@strapi/utils": "4.5.4",
95
95
  "bcryptjs": "2.4.3",
96
96
  "boxen": "5.1.2",
97
97
  "chalk": "4.1.2",
@@ -100,7 +100,7 @@
100
100
  "cli-table3": "0.6.2",
101
101
  "commander": "8.2.0",
102
102
  "configstore": "5.0.1",
103
- "debug": "4.3.2",
103
+ "debug": "4.3.4",
104
104
  "delegates": "1.0.0",
105
105
  "dotenv": "10.0.0",
106
106
  "execa": "5.1.1",
@@ -140,5 +140,5 @@
140
140
  "node": ">=14.19.1 <=18.x.x",
141
141
  "npm": ">=6.0.0"
142
142
  },
143
- "gitHead": "5453885f7aa329f98d047a6030a8e98ba3cbdb41"
143
+ "gitHead": "8716ecc920130db5341b0904cf868c6e6b581a5d"
144
144
  }