@strapi/strapi 4.5.4 → 4.6.0-alpha.1

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
@@ -225,7 +225,7 @@ class Strapi {
225
225
 
226
226
  await this.runLifecyclesFunctions(LIFECYCLES.DESTROY);
227
227
 
228
- this.eventHub.removeAllListeners();
228
+ this.eventHub.destroy();
229
229
 
230
230
  if (_.has(this, 'db')) {
231
231
  await this.db.destroy();
@@ -242,14 +242,11 @@ class Strapi {
242
242
  sendStartupTelemetry() {
243
243
  // Emit started event.
244
244
  // do not await to avoid slower startup
245
- // This event is anonymous
246
245
  this.telemetry.send('didStartServer', {
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
- },
246
+ database: strapi.config.get('database.connection.client'),
247
+ plugins: Object.keys(strapi.plugins),
248
+ // TODO: to add back
249
+ // providers: this.config.installedProviders,
253
250
  });
254
251
  }
255
252
 
@@ -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/api/v2/track', {
56
+ await fetch('https://analytics.strapi.io/track', {
57
57
  method: 'POST',
58
58
  body: JSON.stringify({
59
59
  event: 'didOptInTelemetry',
60
+ uuid,
60
61
  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/api/v2/track', {
31
+ await fetch('https://analytics.strapi.io/track', {
32
32
  method: 'POST',
33
33
  body: JSON.stringify({
34
34
  event: 'didOptOutTelemetry',
35
+ uuid,
35
36
  deviceId: machineID(),
36
- groupProperties: { projectId: uuid },
37
37
  }),
38
38
  headers: { 'Content-Type': 'application/json' },
39
39
  });
@@ -293,48 +293,40 @@ const buildRelationsStore = ({ uid, data }) => {
293
293
  break;
294
294
  }
295
295
  case 'component': {
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);
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
+ }
312
308
  }
313
- }
314
- );
315
- }, result);
309
+ ),
310
+ result
311
+ );
316
312
  }
317
313
  case 'dynamiczone': {
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);
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
+ }
334
326
  }
335
- }
336
- );
337
- }, result);
327
+ ),
328
+ result
329
+ );
338
330
  }
339
331
  default:
340
332
  break;
@@ -1,16 +1,78 @@
1
+ 'use strict';
2
+
1
3
  /**
2
4
  * The event hub is Strapi's event control center.
3
5
  */
6
+ module.exports = function createEventHub() {
7
+ const listeners = new Map();
4
8
 
5
- 'use strict';
9
+ // Default subscriber to easily add listeners with the on() method
10
+ const defaultSubscriber = async (eventName, ...args) => {
11
+ if (listeners.has(eventName)) {
12
+ for (const listener of listeners.get(eventName)) {
13
+ await listener(...args);
14
+ }
15
+ }
16
+ };
6
17
 
7
- const EventEmitter = require('events');
18
+ // Store of subscribers that will be called when an event is emitted
19
+ const subscribers = [defaultSubscriber];
8
20
 
9
- class EventHub extends EventEmitter {}
21
+ const eventHub = {
22
+ async emit(eventName, ...args) {
23
+ for (const subscriber of subscribers) {
24
+ await subscriber(eventName, ...args);
25
+ }
26
+ },
10
27
 
11
- /**
12
- * Expose a factory function instead of the class
13
- */
14
- module.exports = function createEventHub(opts) {
15
- return new EventHub(opts);
28
+ subscribe(subscriber) {
29
+ subscribers.push(subscriber);
30
+
31
+ // Return a function to remove the subscriber
32
+ return () => {
33
+ eventHub.unsubscribe(subscriber);
34
+ };
35
+ },
36
+
37
+ unsubscribe(subscriber) {
38
+ subscribers.splice(subscribers.indexOf(subscriber), 1);
39
+ },
40
+
41
+ on(eventName, listener) {
42
+ if (!listeners.has(eventName)) {
43
+ listeners.set(eventName, []);
44
+ }
45
+
46
+ listeners.get(eventName).push(listener);
47
+
48
+ // Return a function to remove the listener
49
+ return () => {
50
+ eventHub.off(eventName, listener);
51
+ };
52
+ },
53
+
54
+ off(eventName, listener) {
55
+ listeners.get(eventName).splice(listeners.get(eventName).indexOf(listener), 1);
56
+ },
57
+
58
+ once(eventName, listener) {
59
+ return eventHub.on(eventName, async (...args) => {
60
+ eventHub.off(eventName, listener);
61
+ return listener(...args);
62
+ });
63
+ },
64
+
65
+ destroy() {
66
+ listeners.clear();
67
+ subscribers.length = 0;
68
+ return this;
69
+ },
70
+ };
71
+
72
+ return {
73
+ ...eventHub,
74
+ removeListener: eventHub.off,
75
+ removeAllListeners: eventHub.destroy,
76
+ addListener: eventHub.on,
77
+ };
16
78
  };
@@ -55,12 +55,10 @@ const createTelemetryInstance = (strapi) => {
55
55
  return sendEvent(
56
56
  'didCheckLicense',
57
57
  {
58
- groupProperties: {
59
- licenseInfo: {
60
- ...ee.licenseInfo,
61
- projectHash: hashProject(strapi),
62
- dependencyHash: hashDep(strapi),
63
- },
58
+ licenseInfo: {
59
+ ...ee.licenseInfo,
60
+ projectHash: hashProject(strapi),
61
+ dependencyHash: hashDep(strapi),
64
62
  },
65
63
  },
66
64
  {
@@ -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', { eventProperties: { url: ctx.request.url } });
22
+ sendEvent('didReceiveRequest', { 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 { generateAdminUserHash } = require('./admin-user-hash');
13
+ const stringifyDeep = require('./stringify-deep');
14
14
 
15
15
  const defaultQueryOpts = {
16
16
  timeout: 1000,
@@ -42,49 +42,41 @@ 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 anonymousUserProperties = {
45
+ const anonymousMetadata = {
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 = {
55
52
  docker: process.env.DOCKER || isDocker(),
56
53
  isCI: ciEnv.isCI,
57
54
  version: strapi.config.get('info.strapi'),
58
55
  projectType: isEE ? 'Enterprise' : 'Community',
59
56
  useTypescriptOnServer: isUsingTypeScriptSync(serverRootPath),
60
57
  useTypescriptOnAdmin: isUsingTypeScriptSync(adminRootPath),
61
- projectId: uuid,
62
58
  isHostedOnStrapiCloud: env('STRAPI_HOSTING', null) === 'strapi.cloud',
63
59
  };
64
60
 
65
- addPackageJsonStrapiMetadata(anonymousGroupProperties, strapi);
61
+ addPackageJsonStrapiMetadata(anonymousMetadata, strapi);
66
62
 
67
63
  return async (event, payload = {}, opts = {}) => {
68
- const userId = generateAdminUserHash();
69
-
70
64
  const reqParams = {
71
65
  method: 'POST',
72
66
  body: JSON.stringify({
73
67
  event,
74
- userId,
68
+ uuid,
75
69
  deviceId,
76
- eventProperties: payload.eventProperties,
77
- userProperties: userId ? { ...anonymousUserProperties, ...payload.userProperties } : {},
78
- groupProperties: {
79
- ...anonymousGroupProperties,
80
- ...payload.groupProperties,
81
- },
70
+ properties: stringifyDeep({
71
+ ...payload,
72
+ ...anonymousMetadata,
73
+ }),
82
74
  }),
83
75
  ..._.merge({}, defaultQueryOpts, opts),
84
76
  };
85
77
 
86
78
  try {
87
- const res = await fetch(`${ANALYTICS_URI}/api/v2/track`, reqParams);
79
+ const res = await fetch(`${ANALYTICS_URI}/track`, reqParams);
88
80
  return res.ok;
89
81
  } catch (err) {
90
82
  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/api/v2/track', {
20
+ fetch('https://analytics.strapi.io/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.4",
3
+ "version": "4.6.0-alpha.1",
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.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",
83
+ "@strapi/admin": "4.6.0-alpha.1",
84
+ "@strapi/database": "4.6.0-alpha.1",
85
+ "@strapi/generate-new": "4.6.0-alpha.1",
86
+ "@strapi/generators": "4.6.0-alpha.1",
87
+ "@strapi/logger": "4.6.0-alpha.1",
88
+ "@strapi/permissions": "4.6.0-alpha.1",
89
+ "@strapi/plugin-content-manager": "4.6.0-alpha.1",
90
+ "@strapi/plugin-content-type-builder": "4.6.0-alpha.1",
91
+ "@strapi/plugin-email": "4.6.0-alpha.1",
92
+ "@strapi/plugin-upload": "4.6.0-alpha.1",
93
+ "@strapi/typescript-utils": "4.6.0-alpha.1",
94
+ "@strapi/utils": "4.6.0-alpha.1",
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.4",
103
+ "debug": "4.3.2",
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": "8716ecc920130db5341b0904cf868c6e6b581a5d"
143
+ "gitHead": "9171c48104548f5f6da21abf2a8098009f1a40e9"
144
144
  }
@@ -1,15 +0,0 @@
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
- };