Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit ad7efca

Browse files
committed
Add v2.3.0
1 parent 86037d8 commit ad7efca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+818
-192
lines changed

core/built/assets/ghost.min-ca2efe7259fcf85fe0bb3c18071da850.js core/built/assets/ghost.min-cb9cedd474b87c1e57a494b014040dcb.js

+52-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/server/api/v0.1/webhooks.js

-57
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,10 @@ const Promise = require('bluebird'),
77
localUtils = require('./utils'),
88
models = require('../../models'),
99
common = require('../../lib/common'),
10-
request = require('../../lib/request'),
1110
docName = 'webhooks';
1211

1312
let webhooks;
1413

15-
function makeRequest(webhook, payload, options) {
16-
let event = webhook.get('event'),
17-
targetUrl = webhook.get('target_url'),
18-
webhookId = webhook.get('id'),
19-
reqPayload = JSON.stringify(payload);
20-
21-
common.logging.info('webhook.trigger', event, targetUrl);
22-
23-
request(targetUrl, {
24-
body: reqPayload,
25-
headers: {
26-
'Content-Length': Buffer.byteLength(reqPayload),
27-
'Content-Type': 'application/json'
28-
},
29-
timeout: 2 * 1000,
30-
retries: 5
31-
}).catch((err) => {
32-
// when a webhook responds with a 410 Gone response we should remove the hook
33-
if (err.statusCode === 410) {
34-
common.logging.info('webhook.destroy (410 response)', event, targetUrl);
35-
return models.Webhook.destroy({id: webhookId}, options);
36-
}
37-
38-
common.logging.error(new common.errors.GhostError({
39-
err: err,
40-
context: {
41-
id: webhookId,
42-
event: event,
43-
target_url: targetUrl,
44-
payload: payload
45-
}
46-
}));
47-
});
48-
}
49-
50-
function makeRequests(webhooksCollection, payload, options) {
51-
_.each(webhooksCollection.models, (webhook) => {
52-
makeRequest(webhook, payload, options);
53-
});
54-
}
55-
5614
/**
5715
* ## Webhook API Methods
5816
*
@@ -130,21 +88,6 @@ webhooks = {
13088
];
13189

13290
// Pipeline calls each task passing the result of one to be the arguments for the next
133-
return pipeline(tasks, options);
134-
},
135-
136-
trigger(event, payload, options) {
137-
let tasks;
138-
139-
function doQuery(options) {
140-
return models.Webhook.findAllByEvent(event, options);
141-
}
142-
143-
tasks = [
144-
doQuery,
145-
_.partialRight(makeRequests, payload, options)
146-
];
147-
14891
return pipeline(tasks, options);
14992
}
15093
};

core/server/api/v2/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ module.exports = {
66
return shared.http;
77
},
88

9+
get integrations() {
10+
return shared.pipeline(require('./integrations'), localUtils);
11+
},
12+
913
// @TODO: transform
1014
get session() {
1115
return require('./session');
@@ -61,5 +65,9 @@ module.exports = {
6165

6266
get users() {
6367
return shared.pipeline(require('./users'), localUtils);
68+
},
69+
70+
get preview() {
71+
return shared.pipeline(require('./preview'), localUtils);
6472
}
6573
};

core/server/api/v2/integrations.js

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
const common = require('../../lib/common');
2+
const models = require('../../models');
3+
4+
module.exports = {
5+
docName: 'integrations',
6+
browse: {
7+
permissions: true,
8+
options: [
9+
'include',
10+
'limit'
11+
],
12+
validation: {
13+
options: {
14+
include: {
15+
values: ['api_keys', 'webhooks']
16+
}
17+
}
18+
},
19+
query({options}) {
20+
return models.Integration.findPage(options);
21+
}
22+
},
23+
read: {
24+
permissions: true,
25+
data: [
26+
'id'
27+
],
28+
options: [
29+
'include'
30+
],
31+
validation: {
32+
data: {
33+
id: {
34+
required: true
35+
}
36+
},
37+
options: {
38+
include: {
39+
values: ['api_keys', 'webhooks']
40+
}
41+
}
42+
},
43+
query({data, options}) {
44+
return models.Integration.findOne(data, Object.assign(options, {require: true}))
45+
.catch(models.Integration.NotFoundError, () => {
46+
throw new common.errors.NotFoundError({
47+
message: common.i18n.t('errors.api.resource.resourceNotFound', {
48+
resource: 'Integration'
49+
})
50+
});
51+
});
52+
}
53+
},
54+
edit: {
55+
permissions: true,
56+
data: [
57+
'name',
58+
'icon_image',
59+
'description',
60+
'webhooks'
61+
],
62+
options: [
63+
'id',
64+
'include'
65+
],
66+
validation: {
67+
options: {
68+
id: {
69+
required: true
70+
},
71+
include: {
72+
values: ['api_keys', 'webhooks']
73+
}
74+
}
75+
},
76+
query({data, options}) {
77+
return models.Integration.edit(data, Object.assign(options, {require: true}))
78+
.catch(models.Integration.NotFoundError, () => {
79+
throw new common.errors.NotFoundError({
80+
message: common.i18n.t('errors.api.resource.resourceNotFound', {
81+
resource: 'Integration'
82+
})
83+
});
84+
});
85+
}
86+
},
87+
add: {
88+
statusCode: 201,
89+
permissions: true,
90+
data: [
91+
'name',
92+
'icon_image',
93+
'description',
94+
'webhooks'
95+
],
96+
options: [
97+
'include'
98+
],
99+
validation: {
100+
data: {
101+
name: {
102+
required: true
103+
}
104+
},
105+
options: {
106+
include: {
107+
values: ['api_keys', 'webhooks']
108+
}
109+
}
110+
},
111+
query({data, options}) {
112+
const dataWithApiKeys = Object.assign({
113+
api_keys: [
114+
{type: 'content'},
115+
{type: 'admin'}
116+
]
117+
}, data);
118+
return models.Integration.add(dataWithApiKeys, options);
119+
}
120+
},
121+
destroy: {
122+
statusCode: 204,
123+
permissions: true,
124+
options: [
125+
'id'
126+
],
127+
validation: {
128+
options: {
129+
id: {
130+
required: true
131+
}
132+
}
133+
},
134+
query({options}) {
135+
return models.Integration.destroy(Object.assign(options, {require: true}))
136+
.catch(models.Integration.NotFoundError, () => {
137+
throw new common.errors.NotFoundError({
138+
message: common.i18n.t('errors.api.resource.resourceNotFound', {
139+
resource: 'Integration'
140+
})
141+
});
142+
});
143+
}
144+
}
145+
};

core/server/api/v2/pages.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
const common = require('../../lib/common');
12
const models = require('../../models');
3+
const ALLOWED_INCLUDES = ['created_by', 'updated_by', 'published_by', 'author', 'tags', 'authors', 'authors.roles'];
24

35
module.exports = {
46
docName: 'pages',
@@ -18,7 +20,7 @@ module.exports = {
1820
validation: {
1921
options: {
2022
include: {
21-
values: ['created_by', 'updated_by', 'published_by', 'author', 'tags', 'authors', 'authors.roles']
23+
values: ALLOWED_INCLUDES
2224
},
2325
formats: {
2426
values: models.Post.allowedFormats
@@ -29,5 +31,44 @@ module.exports = {
2931
query(frame) {
3032
return models.Post.findPage(frame.options);
3133
}
34+
},
35+
36+
read: {
37+
options: [
38+
'include',
39+
'fields',
40+
'status',
41+
'formats',
42+
'debug'
43+
],
44+
data: [
45+
'id',
46+
'slug',
47+
'status',
48+
'uuid'
49+
],
50+
validation: {
51+
options: {
52+
include: {
53+
values: ALLOWED_INCLUDES
54+
},
55+
formats: {
56+
values: models.Post.allowedFormats
57+
}
58+
}
59+
},
60+
permissions: true,
61+
query(frame) {
62+
return models.Post.findOne(frame.data, frame.options)
63+
.then((model) => {
64+
if (!model) {
65+
throw new common.errors.NotFoundError({
66+
message: common.i18n.t('errors.api.pages.pageNotFound')
67+
});
68+
}
69+
70+
return model;
71+
});
72+
}
3273
}
3374
};

core/server/api/v2/posts.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ module.exports = {
3939
read: {
4040
options: [
4141
'include',
42-
'filter',
4342
'fields',
4443
'status',
4544
'formats',

core/server/api/v2/preview.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const common = require('../../lib/common');
2+
const models = require('../../models');
3+
const ALLOWED_INCLUDES = ['author', 'authors', 'tags'];
4+
5+
module.exports = {
6+
docName: 'preview',
7+
8+
read: {
9+
permissions: true,
10+
options: [
11+
'include'
12+
],
13+
data: [
14+
'uuid'
15+
],
16+
validation: {
17+
options: {
18+
include: {
19+
values: ALLOWED_INCLUDES
20+
}
21+
},
22+
data: {
23+
uuid: {
24+
required: true
25+
}
26+
}
27+
},
28+
query(frame) {
29+
return models.Post.findOne(Object.assign({status: 'all'}, frame.data), frame.options)
30+
.then((model) => {
31+
if (!model) {
32+
throw new common.errors.NotFoundError({
33+
message: common.i18n.t('errors.api.posts.postNotFound')
34+
});
35+
}
36+
37+
return model;
38+
});
39+
}
40+
}
41+
};

core/server/api/v2/utils/serializers/input/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
2+
get integrations() {
3+
return require('./integrations');
4+
},
25
get pages() {
36
return require('./pages');
47
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const _ = require('lodash');
2+
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:integrations');
3+
4+
module.exports = {
5+
add(apiConfig, frame) {
6+
debug('add');
7+
8+
frame.data = _.pick(frame.data.integrations[0], apiConfig.data);
9+
},
10+
edit(apiConfig, frame) {
11+
debug('edit');
12+
13+
frame.data = _.pick(frame.data.integrations[0], apiConfig.data);
14+
}
15+
};

0 commit comments

Comments
 (0)