@strapi/strapi 4.11.0-beta.1 → 4.11.0-exp.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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { cloneDeep } = require('lodash/fp');
|
|
4
4
|
const _ = require('lodash');
|
|
5
|
-
const { hasDraftAndPublish
|
|
5
|
+
const { hasDraftAndPublish } = require('@strapi/utils').contentTypes;
|
|
6
6
|
const {
|
|
7
7
|
CREATED_AT_ATTRIBUTE,
|
|
8
8
|
UPDATED_AT_ATTRIBUTE,
|
|
@@ -58,12 +58,6 @@ const createContentType = (uid, definition) => {
|
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
Object.defineProperty(schema, 'privateAttributes', {
|
|
62
|
-
get() {
|
|
63
|
-
return getPrivateAttributes(schema);
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
61
|
// attributes
|
|
68
62
|
Object.assign(schema.attributes, {
|
|
69
63
|
[CREATED_AT_ATTRIBUTE]: {
|
|
@@ -4,11 +4,7 @@ const _ = require('lodash');
|
|
|
4
4
|
const delegate = require('delegates');
|
|
5
5
|
const { InvalidTimeError, InvalidDateError, InvalidDateTimeError, InvalidRelationError } =
|
|
6
6
|
require('@strapi/database').errors;
|
|
7
|
-
const {
|
|
8
|
-
webhook: webhookUtils,
|
|
9
|
-
contentTypes: contentTypesUtils,
|
|
10
|
-
sanitize,
|
|
11
|
-
} = require('@strapi/utils');
|
|
7
|
+
const { contentTypes: contentTypesUtils, sanitize } = require('@strapi/utils');
|
|
12
8
|
const { ValidationError } = require('@strapi/utils').errors;
|
|
13
9
|
const { isAnyToMany } = require('@strapi/utils').relations;
|
|
14
10
|
const { transformParamsToQuery } = require('@strapi/utils').convertQueryParams;
|
|
@@ -31,9 +27,6 @@ const transformLoadParamsToQuery = (uid, field, params = {}, pagination = {}) =>
|
|
|
31
27
|
};
|
|
32
28
|
};
|
|
33
29
|
|
|
34
|
-
// TODO: those should be strapi events used by the webhooks not the other way arround
|
|
35
|
-
const { ENTRY_CREATE, ENTRY_UPDATE, ENTRY_DELETE } = webhookUtils.webhookEvents;
|
|
36
|
-
|
|
37
30
|
const databaseErrorsToTransform = [
|
|
38
31
|
InvalidTimeError,
|
|
39
32
|
InvalidDateTimeError,
|
|
@@ -49,6 +42,12 @@ const updatePipeline = (data, context) => {
|
|
|
49
42
|
return applyTransforms(data, context);
|
|
50
43
|
};
|
|
51
44
|
|
|
45
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
|
46
|
+
ENTRY_CREATE: 'entry.create',
|
|
47
|
+
ENTRY_UPDATE: 'entry.update',
|
|
48
|
+
ENTRY_DELETE: 'entry.delete',
|
|
49
|
+
};
|
|
50
|
+
|
|
52
51
|
/**
|
|
53
52
|
* @type {import('.').default}
|
|
54
53
|
*/
|
|
@@ -180,6 +179,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|
|
180
179
|
|
|
181
180
|
entity = await this.wrapResult(entity, { uid, action: 'create' });
|
|
182
181
|
|
|
182
|
+
const { ENTRY_CREATE } = ALLOWED_WEBHOOK_EVENTS;
|
|
183
183
|
await this.emitEvent(uid, ENTRY_CREATE, entity);
|
|
184
184
|
|
|
185
185
|
return entity;
|
|
@@ -233,6 +233,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|
|
233
233
|
|
|
234
234
|
entity = await this.wrapResult(entity, { uid, action: 'update' });
|
|
235
235
|
|
|
236
|
+
const { ENTRY_UPDATE } = ALLOWED_WEBHOOK_EVENTS;
|
|
236
237
|
await this.emitEvent(uid, ENTRY_UPDATE, entity);
|
|
237
238
|
|
|
238
239
|
return entity;
|
|
@@ -260,6 +261,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|
|
260
261
|
|
|
261
262
|
entityToDelete = await this.wrapResult(entityToDelete, { uid, action: 'delete' });
|
|
262
263
|
|
|
264
|
+
const { ENTRY_DELETE } = ALLOWED_WEBHOOK_EVENTS;
|
|
263
265
|
await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);
|
|
264
266
|
|
|
265
267
|
return entityToDelete;
|
|
@@ -290,6 +292,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|
|
290
292
|
entitiesToDelete = await this.wrapResult(entitiesToDelete, { uid, action: 'delete' });
|
|
291
293
|
|
|
292
294
|
// Trigger webhooks. One for each entity
|
|
295
|
+
const { ENTRY_DELETE } = ALLOWED_WEBHOOK_EVENTS;
|
|
293
296
|
await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
|
|
294
297
|
|
|
295
298
|
return deletedEntities;
|
|
@@ -331,6 +334,10 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|
|
331
334
|
});
|
|
332
335
|
|
|
333
336
|
module.exports = (ctx) => {
|
|
337
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
338
|
+
ctx.strapi.webhookStore.addAllowedEvent(key, value);
|
|
339
|
+
});
|
|
340
|
+
|
|
334
341
|
const implementation = createDefaultImplementation(ctx);
|
|
335
342
|
|
|
336
343
|
const service = {
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
+
const { mapAsync } = require('@strapi/utils');
|
|
8
|
+
const { ValidationError } = require('@strapi/utils').errors;
|
|
9
|
+
|
|
7
10
|
const webhookModel = {
|
|
8
11
|
uid: 'webhook',
|
|
9
12
|
collectionName: 'strapi_webhooks',
|
|
@@ -47,30 +50,56 @@ const fromDBObject = (row) => {
|
|
|
47
50
|
};
|
|
48
51
|
};
|
|
49
52
|
|
|
53
|
+
const webhookEventValidator = async (allowedEvents, events) => {
|
|
54
|
+
const allowedValues = Array.from(allowedEvents.values());
|
|
55
|
+
|
|
56
|
+
await mapAsync(events, (event) => {
|
|
57
|
+
if (allowedValues.includes(event)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
throw new ValidationError(`Webhook event ${event} is not supported`);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
50
65
|
const createWebhookStore = ({ db }) => {
|
|
51
66
|
const webhookQueries = db.query('webhook');
|
|
52
67
|
|
|
53
68
|
return {
|
|
69
|
+
allowedEvents: new Map([]),
|
|
70
|
+
addAllowedEvent(key, value) {
|
|
71
|
+
this.allowedEvents.set(key, value);
|
|
72
|
+
},
|
|
73
|
+
removeAllowedEvent(key) {
|
|
74
|
+
this.allowedEvents.delete(key);
|
|
75
|
+
},
|
|
76
|
+
listAllowedEvents() {
|
|
77
|
+
return Array.from(this.allowedEvents.keys());
|
|
78
|
+
},
|
|
79
|
+
getAllowedEvent(key) {
|
|
80
|
+
return this.allowedEvents.get(key);
|
|
81
|
+
},
|
|
54
82
|
async findWebhooks() {
|
|
55
83
|
const results = await webhookQueries.findMany();
|
|
56
84
|
|
|
57
85
|
return results.map(fromDBObject);
|
|
58
86
|
},
|
|
59
|
-
|
|
60
87
|
async findWebhook(id) {
|
|
61
88
|
const result = await webhookQueries.findOne({ where: { id } });
|
|
62
89
|
return result ? fromDBObject(result) : null;
|
|
63
90
|
},
|
|
91
|
+
async createWebhook(data) {
|
|
92
|
+
await webhookEventValidator(this.allowedEvents, data.events);
|
|
64
93
|
|
|
65
|
-
createWebhook(data) {
|
|
66
94
|
return webhookQueries
|
|
67
95
|
.create({
|
|
68
96
|
data: toDBObject({ ...data, isEnabled: true }),
|
|
69
97
|
})
|
|
70
98
|
.then(fromDBObject);
|
|
71
99
|
},
|
|
72
|
-
|
|
73
100
|
async updateWebhook(id, data) {
|
|
101
|
+
await webhookEventValidator(this.allowedEvents, data.events);
|
|
102
|
+
|
|
74
103
|
const webhook = await webhookQueries.update({
|
|
75
104
|
where: { id },
|
|
76
105
|
data: toDBObject(data),
|
|
@@ -78,7 +107,6 @@ const createWebhookStore = ({ db }) => {
|
|
|
78
107
|
|
|
79
108
|
return webhook ? fromDBObject(webhook) : null;
|
|
80
109
|
},
|
|
81
|
-
|
|
82
110
|
async deleteWebhook(id) {
|
|
83
111
|
const webhook = await webhookQueries.delete({ where: { id } });
|
|
84
112
|
return webhook ? fromDBObject(webhook) : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/strapi",
|
|
3
|
-
"version": "4.11.0-
|
|
3
|
+
"version": "4.11.0-exp.2",
|
|
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",
|
|
@@ -81,19 +81,19 @@
|
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"@koa/cors": "3.4.3",
|
|
83
83
|
"@koa/router": "10.1.1",
|
|
84
|
-
"@strapi/admin": "4.11.0-
|
|
85
|
-
"@strapi/data-transfer": "4.11.0-
|
|
86
|
-
"@strapi/database": "4.11.0-
|
|
87
|
-
"@strapi/generate-new": "4.11.0-
|
|
88
|
-
"@strapi/generators": "4.11.0-
|
|
89
|
-
"@strapi/logger": "4.11.0-
|
|
90
|
-
"@strapi/permissions": "4.11.0-
|
|
91
|
-
"@strapi/plugin-content-manager": "4.11.0-
|
|
92
|
-
"@strapi/plugin-content-type-builder": "4.11.0-
|
|
93
|
-
"@strapi/plugin-email": "4.11.0-
|
|
94
|
-
"@strapi/plugin-upload": "4.11.0-
|
|
95
|
-
"@strapi/typescript-utils": "4.11.0-
|
|
96
|
-
"@strapi/utils": "4.11.0-
|
|
84
|
+
"@strapi/admin": "4.11.0-exp.2",
|
|
85
|
+
"@strapi/data-transfer": "4.11.0-exp.2",
|
|
86
|
+
"@strapi/database": "4.11.0-exp.2",
|
|
87
|
+
"@strapi/generate-new": "4.11.0-exp.2",
|
|
88
|
+
"@strapi/generators": "4.11.0-exp.2",
|
|
89
|
+
"@strapi/logger": "4.11.0-exp.2",
|
|
90
|
+
"@strapi/permissions": "4.11.0-exp.2",
|
|
91
|
+
"@strapi/plugin-content-manager": "4.11.0-exp.2",
|
|
92
|
+
"@strapi/plugin-content-type-builder": "4.11.0-exp.2",
|
|
93
|
+
"@strapi/plugin-email": "4.11.0-exp.2",
|
|
94
|
+
"@strapi/plugin-upload": "4.11.0-exp.2",
|
|
95
|
+
"@strapi/typescript-utils": "4.11.0-exp.2",
|
|
96
|
+
"@strapi/utils": "4.11.0-exp.2",
|
|
97
97
|
"bcryptjs": "2.4.3",
|
|
98
98
|
"boxen": "5.1.2",
|
|
99
99
|
"chalk": "4.1.2",
|
|
@@ -136,11 +136,11 @@
|
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
138
|
"supertest": "6.3.3",
|
|
139
|
-
"typescript": "5.
|
|
139
|
+
"typescript": "5.1.3"
|
|
140
140
|
},
|
|
141
141
|
"engines": {
|
|
142
142
|
"node": ">=14.19.1 <=18.x.x",
|
|
143
143
|
"npm": ">=6.0.0"
|
|
144
144
|
},
|
|
145
|
-
"gitHead": "
|
|
145
|
+
"gitHead": "d0785a2eb7588c1314108a40fee617bdfd3148e2"
|
|
146
146
|
}
|