From 687e68d5de9539700f91cdb56ccbb59720d54abe Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 11 Aug 2022 16:39:37 +0200 Subject: [PATCH] Extracted shared API framework to separate package refs https://github.com/TryGhost/Toolbox/issues/363 - this API framework is standalone and should be pulled out into a separate package so we can define its boundaries more clearly, and promote better testing of smaller parts --- ghost/api-framework/.eslintrc.js | 6 + ghost/api-framework/README.md | 23 ++++ ghost/api-framework/index.js | 1 + .../lib/api-framework.js} | 4 + .../api/shared => api-framework/lib}/frame.js | 0 .../shared => api-framework/lib}/headers.js | 0 .../api/shared => api-framework/lib}/http.js | 0 .../shared => api-framework/lib}/pipeline.js | 0 .../lib}/serializers/handle.js | 0 .../lib}/serializers/index.js | 0 .../lib}/serializers/input/all.js | 0 .../lib}/serializers/input/index.js | 0 .../lib}/serializers/output/index.js | 0 .../lib}/utils/index.js | 0 .../lib}/utils/options.js | 0 .../lib}/validators/handle.js | 0 .../lib}/validators/index.js | 0 .../lib}/validators/input/all.js | 0 .../lib}/validators/input/index.js | 0 ghost/api-framework/package.json | 34 ++++++ ghost/api-framework/test/.eslintrc.js | 6 + .../test}/frame.test.js | 6 +- .../test}/headers.test.js | 9 +- .../test}/http.test.js | 4 +- .../test}/pipeline.test.js | 3 +- .../test}/serializers/handle.test.js | 3 +- .../test}/serializers/input/all.test.js | 2 +- .../test}/util/options.test.js | 3 +- .../test}/validators/handle.test.js | 2 +- .../test}/validators/input/all.test.js | 8 +- ghost/core/.c8rc.json | 2 +- ghost/core/core/server/api/endpoints/index.js | 104 +++++++++--------- .../endpoints/utils/serializers/input/db.js | 2 +- .../utils/serializers/output/tiers.js | 2 +- ghost/core/core/server/api/index.js | 2 - .../services/mega/post-email-serializer.js | 4 +- .../server/services/webhooks/serialize.js | 6 +- .../server/web/api/endpoints/admin/routes.js | 2 +- .../web/api/endpoints/content/routes.js | 2 +- ghost/core/core/server/web/comments/routes.js | 2 +- ghost/core/package.json | 1 + 41 files changed, 156 insertions(+), 87 deletions(-) create mode 100644 ghost/api-framework/.eslintrc.js create mode 100644 ghost/api-framework/README.md create mode 100644 ghost/api-framework/index.js rename ghost/{core/core/server/api/shared/index.js => api-framework/lib/api-framework.js} (87%) rename ghost/{core/core/server/api/shared => api-framework/lib}/frame.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/headers.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/http.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/pipeline.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/serializers/handle.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/serializers/index.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/serializers/input/all.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/serializers/input/index.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/serializers/output/index.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/utils/index.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/utils/options.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/validators/handle.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/validators/index.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/validators/input/all.js (100%) rename ghost/{core/core/server/api/shared => api-framework/lib}/validators/input/index.js (100%) create mode 100644 ghost/api-framework/package.json create mode 100644 ghost/api-framework/test/.eslintrc.js rename ghost/{core/test/unit/api/shared => api-framework/test}/frame.test.js (95%) rename ghost/{core/test/unit/api/shared => api-framework/test}/headers.test.js (96%) rename ghost/{core/test/unit/api/shared => api-framework/test}/http.test.js (95%) rename ghost/{core/test/unit/api/shared => api-framework/test}/pipeline.test.js (98%) rename ghost/{core/test/unit/api/shared => api-framework/test}/serializers/handle.test.js (99%) rename ghost/{core/test/unit/api/shared => api-framework/test}/serializers/input/all.test.js (97%) rename ghost/{core/test/unit/api/shared => api-framework/test}/util/options.test.js (87%) rename ghost/{core/test/unit/api/shared => api-framework/test}/validators/handle.test.js (96%) rename ghost/{core/test/unit/api/shared => api-framework/test}/validators/input/all.test.js (98%) diff --git a/ghost/api-framework/.eslintrc.js b/ghost/api-framework/.eslintrc.js new file mode 100644 index 0000000000..c9c1bcb522 --- /dev/null +++ b/ghost/api-framework/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/node' + ] +}; diff --git a/ghost/api-framework/README.md b/ghost/api-framework/README.md new file mode 100644 index 0000000000..64191b307a --- /dev/null +++ b/ghost/api-framework/README.md @@ -0,0 +1,23 @@ +# Api Framework + +API framework used by Ghost + + +## Usage + + +## Develop + +This is a monorepo package. + +Follow the instructions for the top-level repo. +1. `git clone` this repo & `cd` into it as usual +2. Run `yarn` to install top-level dependencies. + + + +## Test + +- `yarn lint` run just eslint +- `yarn test` run lint and tests + diff --git a/ghost/api-framework/index.js b/ghost/api-framework/index.js new file mode 100644 index 0000000000..373c844ba2 --- /dev/null +++ b/ghost/api-framework/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/api-framework'); diff --git a/ghost/core/core/server/api/shared/index.js b/ghost/api-framework/lib/api-framework.js similarity index 87% rename from ghost/core/core/server/api/shared/index.js rename to ghost/api-framework/lib/api-framework.js index 33bc92fc70..fdda5f7d74 100644 --- a/ghost/core/core/server/api/shared/index.js +++ b/ghost/api-framework/lib/api-framework.js @@ -21,5 +21,9 @@ module.exports = { get serializers() { return require('./serializers'); + }, + + get utils() { + return require('./utils'); } }; diff --git a/ghost/core/core/server/api/shared/frame.js b/ghost/api-framework/lib/frame.js similarity index 100% rename from ghost/core/core/server/api/shared/frame.js rename to ghost/api-framework/lib/frame.js diff --git a/ghost/core/core/server/api/shared/headers.js b/ghost/api-framework/lib/headers.js similarity index 100% rename from ghost/core/core/server/api/shared/headers.js rename to ghost/api-framework/lib/headers.js diff --git a/ghost/core/core/server/api/shared/http.js b/ghost/api-framework/lib/http.js similarity index 100% rename from ghost/core/core/server/api/shared/http.js rename to ghost/api-framework/lib/http.js diff --git a/ghost/core/core/server/api/shared/pipeline.js b/ghost/api-framework/lib/pipeline.js similarity index 100% rename from ghost/core/core/server/api/shared/pipeline.js rename to ghost/api-framework/lib/pipeline.js diff --git a/ghost/core/core/server/api/shared/serializers/handle.js b/ghost/api-framework/lib/serializers/handle.js similarity index 100% rename from ghost/core/core/server/api/shared/serializers/handle.js rename to ghost/api-framework/lib/serializers/handle.js diff --git a/ghost/core/core/server/api/shared/serializers/index.js b/ghost/api-framework/lib/serializers/index.js similarity index 100% rename from ghost/core/core/server/api/shared/serializers/index.js rename to ghost/api-framework/lib/serializers/index.js diff --git a/ghost/core/core/server/api/shared/serializers/input/all.js b/ghost/api-framework/lib/serializers/input/all.js similarity index 100% rename from ghost/core/core/server/api/shared/serializers/input/all.js rename to ghost/api-framework/lib/serializers/input/all.js diff --git a/ghost/core/core/server/api/shared/serializers/input/index.js b/ghost/api-framework/lib/serializers/input/index.js similarity index 100% rename from ghost/core/core/server/api/shared/serializers/input/index.js rename to ghost/api-framework/lib/serializers/input/index.js diff --git a/ghost/core/core/server/api/shared/serializers/output/index.js b/ghost/api-framework/lib/serializers/output/index.js similarity index 100% rename from ghost/core/core/server/api/shared/serializers/output/index.js rename to ghost/api-framework/lib/serializers/output/index.js diff --git a/ghost/core/core/server/api/shared/utils/index.js b/ghost/api-framework/lib/utils/index.js similarity index 100% rename from ghost/core/core/server/api/shared/utils/index.js rename to ghost/api-framework/lib/utils/index.js diff --git a/ghost/core/core/server/api/shared/utils/options.js b/ghost/api-framework/lib/utils/options.js similarity index 100% rename from ghost/core/core/server/api/shared/utils/options.js rename to ghost/api-framework/lib/utils/options.js diff --git a/ghost/core/core/server/api/shared/validators/handle.js b/ghost/api-framework/lib/validators/handle.js similarity index 100% rename from ghost/core/core/server/api/shared/validators/handle.js rename to ghost/api-framework/lib/validators/handle.js diff --git a/ghost/core/core/server/api/shared/validators/index.js b/ghost/api-framework/lib/validators/index.js similarity index 100% rename from ghost/core/core/server/api/shared/validators/index.js rename to ghost/api-framework/lib/validators/index.js diff --git a/ghost/core/core/server/api/shared/validators/input/all.js b/ghost/api-framework/lib/validators/input/all.js similarity index 100% rename from ghost/core/core/server/api/shared/validators/input/all.js rename to ghost/api-framework/lib/validators/input/all.js diff --git a/ghost/core/core/server/api/shared/validators/input/index.js b/ghost/api-framework/lib/validators/input/index.js similarity index 100% rename from ghost/core/core/server/api/shared/validators/input/index.js rename to ghost/api-framework/lib/validators/input/index.js diff --git a/ghost/api-framework/package.json b/ghost/api-framework/package.json new file mode 100644 index 0000000000..585a942106 --- /dev/null +++ b/ghost/api-framework/package.json @@ -0,0 +1,34 @@ +{ + "name": "@tryghost/api-framework", + "version": "0.0.0", + "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/api-framework", + "author": "Ghost Foundation", + "private": true, + "main": "index.js", + "scripts": { + "dev": "echo \"Implement me!\"", + "test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" + }, + "files": [ + "index.js", + "lib" + ], + "devDependencies": { + "c8": "7.12.0", + "mocha": "10.0.0", + "should": "13.2.3", + "sinon": "14.0.0" + }, + "dependencies": { + "@tryghost/debug": "0.1.18", + "@tryghost/errors": "1.2.15", + "@tryghost/promise": "0.1.21", + "@tryghost/tpl": "0.1.18", + "@tryghost/validator": "0.1.27", + "jsonpath": "1.1.1", + "lodash": "4.17.21" + } +} diff --git a/ghost/api-framework/test/.eslintrc.js b/ghost/api-framework/test/.eslintrc.js new file mode 100644 index 0000000000..829b601eb0 --- /dev/null +++ b/ghost/api-framework/test/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/test' + ] +}; diff --git a/ghost/core/test/unit/api/shared/frame.test.js b/ghost/api-framework/test/frame.test.js similarity index 95% rename from ghost/core/test/unit/api/shared/frame.test.js rename to ghost/api-framework/test/frame.test.js index 6c96d6729b..bdbd645aa2 100644 --- a/ghost/core/test/unit/api/shared/frame.test.js +++ b/ghost/api-framework/test/frame.test.js @@ -1,5 +1,5 @@ const should = require('should'); -const shared = require('../../../../core/server/api/shared'); +const shared = require('../'); describe('Unit: api/shared/frame', function () { it('constructor', function () { @@ -37,7 +37,7 @@ describe('Unit: api/shared/frame', function () { should.exist(frame.data.posts); }); - it('transform', function () { + it('transform with query', function () { const original = { context: {user: 'id'}, body: {posts: []}, @@ -78,7 +78,7 @@ describe('Unit: api/shared/frame', function () { should.exist(frame.options.slug); }); - it('transform', function () { + it('transform with data', function () { const original = { context: {user: 'id'}, options: { diff --git a/ghost/core/test/unit/api/shared/headers.test.js b/ghost/api-framework/test/headers.test.js similarity index 96% rename from ghost/core/test/unit/api/shared/headers.test.js rename to ghost/api-framework/test/headers.test.js index 93cba1d8a8..ecdbf5c2d3 100644 --- a/ghost/core/test/unit/api/shared/headers.test.js +++ b/ghost/api-framework/test/headers.test.js @@ -1,5 +1,4 @@ -const should = require('should'); -const shared = require('../../../../core/server/api/shared'); +const shared = require('../'); describe('Unit: api/shared/headers', function () { it('empty headers config', function () { @@ -13,7 +12,7 @@ describe('Unit: api/shared/headers', function () { return shared.headers.get({}, {disposition: {type: 'json', value: 'value'}}) .then((result) => { result.should.eql({ - 'Content-Disposition': 'Attachment; filename=\"value\"', + 'Content-Disposition': 'Attachment; filename="value"', 'Content-Type': 'application/json', 'Content-Length': 2 }); @@ -24,7 +23,7 @@ describe('Unit: api/shared/headers', function () { return shared.headers.get({}, {disposition: {type: 'csv', value: 'my.csv'}}) .then((result) => { result.should.eql({ - 'Content-Disposition': 'Attachment; filename=\"my.csv\"', + 'Content-Disposition': 'Attachment; filename="my.csv"', 'Content-Type': 'text/csv' }); }); @@ -34,7 +33,7 @@ describe('Unit: api/shared/headers', function () { return shared.headers.get('yaml file', {disposition: {type: 'yaml', value: 'my.yaml'}}) .then((result) => { result.should.eql({ - 'Content-Disposition': 'Attachment; filename=\"my.yaml\"', + 'Content-Disposition': 'Attachment; filename="my.yaml"', 'Content-Type': 'application/yaml', 'Content-Length': 11 }); diff --git a/ghost/core/test/unit/api/shared/http.test.js b/ghost/api-framework/test/http.test.js similarity index 95% rename from ghost/core/test/unit/api/shared/http.test.js rename to ghost/api-framework/test/http.test.js index 6793234def..7de8495fde 100644 --- a/ghost/core/test/unit/api/shared/http.test.js +++ b/ghost/api-framework/test/http.test.js @@ -1,6 +1,6 @@ const should = require('should'); const sinon = require('sinon'); -const shared = require('../../../../core/server/api/shared'); +const shared = require('../'); describe('Unit: api/shared/http', function () { let req; @@ -73,7 +73,7 @@ describe('Unit: api/shared/http', function () { shared.http(apiImpl)(req, res, next); }); - it('api response is fn', function (done) { + it('api response is fn (data)', function (done) { const apiImpl = sinon.stub().resolves('data'); next.callsFake(done); diff --git a/ghost/core/test/unit/api/shared/pipeline.test.js b/ghost/api-framework/test/pipeline.test.js similarity index 98% rename from ghost/core/test/unit/api/shared/pipeline.test.js rename to ghost/api-framework/test/pipeline.test.js index 3906868c83..4f139d864e 100644 --- a/ghost/core/test/unit/api/shared/pipeline.test.js +++ b/ghost/api-framework/test/pipeline.test.js @@ -1,8 +1,7 @@ const errors = require('@tryghost/errors'); const should = require('should'); const sinon = require('sinon'); -const Promise = require('bluebird'); -const shared = require('../../../../core/server/api/shared'); +const shared = require('../'); describe('Unit: api/shared/pipeline', function () { afterEach(function () { diff --git a/ghost/core/test/unit/api/shared/serializers/handle.test.js b/ghost/api-framework/test/serializers/handle.test.js similarity index 99% rename from ghost/core/test/unit/api/shared/serializers/handle.test.js rename to ghost/api-framework/test/serializers/handle.test.js index 508de49258..c00b364132 100644 --- a/ghost/core/test/unit/api/shared/serializers/handle.test.js +++ b/ghost/api-framework/test/serializers/handle.test.js @@ -1,8 +1,7 @@ const errors = require('@tryghost/errors'); -const should = require('should'); const Promise = require('bluebird'); const sinon = require('sinon'); -const shared = require('../../../../../core/server/api/shared'); +const shared = require('../../'); describe('Unit: api/shared/serializers/handle', function () { afterEach(function () { diff --git a/ghost/core/test/unit/api/shared/serializers/input/all.test.js b/ghost/api-framework/test/serializers/input/all.test.js similarity index 97% rename from ghost/core/test/unit/api/shared/serializers/input/all.test.js rename to ghost/api-framework/test/serializers/input/all.test.js index 1525df8218..b24cefb9bb 100644 --- a/ghost/core/test/unit/api/shared/serializers/input/all.test.js +++ b/ghost/api-framework/test/serializers/input/all.test.js @@ -1,5 +1,5 @@ const should = require('should'); -const shared = require('../../../../../../core/server/api/shared'); +const shared = require('../../../'); describe('Unit: utils/serializers/input/all', function () { describe('all', function () { diff --git a/ghost/core/test/unit/api/shared/util/options.test.js b/ghost/api-framework/test/util/options.test.js similarity index 87% rename from ghost/core/test/unit/api/shared/util/options.test.js rename to ghost/api-framework/test/util/options.test.js index b47b902f8f..a2d10f5d0f 100644 --- a/ghost/core/test/unit/api/shared/util/options.test.js +++ b/ghost/api-framework/test/util/options.test.js @@ -1,5 +1,4 @@ -const should = require('should'); -const optionsUtil = require('../../../../../core/server/api/shared/utils/options'); +const optionsUtil = require('../../lib/utils/options'); describe('Unit: api/shared/util/options', function () { it('returns an array with empty string when no parameters are passed', function () { diff --git a/ghost/core/test/unit/api/shared/validators/handle.test.js b/ghost/api-framework/test/validators/handle.test.js similarity index 96% rename from ghost/core/test/unit/api/shared/validators/handle.test.js rename to ghost/api-framework/test/validators/handle.test.js index 41dfefd003..bf28a5ffb0 100644 --- a/ghost/core/test/unit/api/shared/validators/handle.test.js +++ b/ghost/api-framework/test/validators/handle.test.js @@ -1,7 +1,7 @@ const errors = require('@tryghost/errors'); const Promise = require('bluebird'); const sinon = require('sinon'); -const shared = require('../../../../../core/server/api/shared'); +const shared = require('../../'); describe('Unit: api/shared/validators/handle', function () { afterEach(function () { diff --git a/ghost/core/test/unit/api/shared/validators/input/all.test.js b/ghost/api-framework/test/validators/input/all.test.js similarity index 98% rename from ghost/core/test/unit/api/shared/validators/input/all.test.js rename to ghost/api-framework/test/validators/input/all.test.js index bc1b07fc30..0f9a53169c 100644 --- a/ghost/core/test/unit/api/shared/validators/input/all.test.js +++ b/ghost/api-framework/test/validators/input/all.test.js @@ -2,7 +2,7 @@ const errors = require('@tryghost/errors'); const should = require('should'); const sinon = require('sinon'); const Promise = require('bluebird'); -const shared = require('../../../../../../core/server/api/shared'); +const shared = require('../../../'); describe('Unit: api/shared/validators/input/all', function () { afterEach(function () { @@ -287,7 +287,7 @@ describe('Unit: api/shared/validators/input/all', function () { }); }); - it('fails', function () { + it('fails with docName', function () { const frame = { data: { docName: true @@ -305,7 +305,7 @@ describe('Unit: api/shared/validators/input/all', function () { }); }); - it('fails', function () { + it('fails for required field', function () { const frame = { data: { docName: [{ @@ -331,7 +331,7 @@ describe('Unit: api/shared/validators/input/all', function () { }); }); - it('fails', function () { + it('fails for invalid field', function () { const frame = { data: { docName: [{ diff --git a/ghost/core/.c8rc.json b/ghost/core/.c8rc.json index f24460937d..5e4be32a62 100644 --- a/ghost/core/.c8rc.json +++ b/ghost/core/.c8rc.json @@ -8,7 +8,7 @@ ], "statements": 57, "branches": 85, - "functions": 52, + "functions": 51, "lines": 57, "include": [ "core/{*.js,frontend,server,shared}" diff --git a/ghost/core/core/server/api/endpoints/index.js b/ghost/core/core/server/api/endpoints/index.js index 8985b0da7d..5b2fc5cba7 100644 --- a/ghost/core/core/server/api/endpoints/index.js +++ b/ghost/core/core/server/api/endpoints/index.js @@ -1,4 +1,4 @@ -const shared = require('../shared'); +const apiFramework = require('@tryghost/api-framework'); const localUtils = require('./utils'); // ESLint Override Notice @@ -9,19 +9,19 @@ const localUtils = require('./utils'); module.exports = { get authentication() { - return shared.pipeline(require('./authentication'), localUtils); + return apiFramework.pipeline(require('./authentication'), localUtils); }, get db() { - return shared.pipeline(require('./db'), localUtils); + return apiFramework.pipeline(require('./db'), localUtils); }, get identities() { - return shared.pipeline(require('./identities'), localUtils); + return apiFramework.pipeline(require('./identities'), localUtils); }, get integrations() { - return shared.pipeline(require('./integrations'), localUtils); + return apiFramework.pipeline(require('./integrations'), localUtils); }, // @TODO: transform @@ -30,147 +30,147 @@ module.exports = { }, get schedules() { - return shared.pipeline(require('./schedules'), localUtils); + return apiFramework.pipeline(require('./schedules'), localUtils); }, get pages() { - return shared.pipeline(require('./pages'), localUtils); + return apiFramework.pipeline(require('./pages'), localUtils); }, get redirects() { - return shared.pipeline(require('./redirects'), localUtils); + return apiFramework.pipeline(require('./redirects'), localUtils); }, get roles() { - return shared.pipeline(require('./roles'), localUtils); + return apiFramework.pipeline(require('./roles'), localUtils); }, get slugs() { - return shared.pipeline(require('./slugs'), localUtils); + return apiFramework.pipeline(require('./slugs'), localUtils); }, get webhooks() { - return shared.pipeline(require('./webhooks'), localUtils); + return apiFramework.pipeline(require('./webhooks'), localUtils); }, get posts() { - return shared.pipeline(require('./posts'), localUtils); + return apiFramework.pipeline(require('./posts'), localUtils); }, get invites() { - return shared.pipeline(require('./invites'), localUtils); + return apiFramework.pipeline(require('./invites'), localUtils); }, get mail() { - return shared.pipeline(require('./mail'), localUtils); + return apiFramework.pipeline(require('./mail'), localUtils); }, get notifications() { - return shared.pipeline(require('./notifications'), localUtils); + return apiFramework.pipeline(require('./notifications'), localUtils); }, get settings() { - return shared.pipeline(require('./settings'), localUtils); + return apiFramework.pipeline(require('./settings'), localUtils); }, get membersStripeConnect() { - return shared.pipeline(require('./members-stripe-connect'), localUtils); + return apiFramework.pipeline(require('./members-stripe-connect'), localUtils); }, get members() { - return shared.pipeline(require('./members'), localUtils); + return apiFramework.pipeline(require('./members'), localUtils); }, get offers() { - return shared.pipeline(require('./offers'), localUtils); + return apiFramework.pipeline(require('./offers'), localUtils); }, get tiers() { - return shared.pipeline(require('./tiers'), localUtils); + return apiFramework.pipeline(require('./tiers'), localUtils); }, get memberSigninUrls() { - return shared.pipeline(require('./member-signin-urls.js'), localUtils); + return apiFramework.pipeline(require('./member-signin-urls.js'), localUtils); }, get labels() { - return shared.pipeline(require('./labels'), localUtils); + return apiFramework.pipeline(require('./labels'), localUtils); }, get images() { - return shared.pipeline(require('./images'), localUtils); + return apiFramework.pipeline(require('./images'), localUtils); }, get media() { - return shared.pipeline(require('./media'), localUtils); + return apiFramework.pipeline(require('./media'), localUtils); }, get files() { - return shared.pipeline(require('./files'), localUtils); + return apiFramework.pipeline(require('./files'), localUtils); }, get tags() { - return shared.pipeline(require('./tags'), localUtils); + return apiFramework.pipeline(require('./tags'), localUtils); }, get users() { - return shared.pipeline(require('./users'), localUtils); + return apiFramework.pipeline(require('./users'), localUtils); }, get previews() { - return shared.pipeline(require('./previews'), localUtils); + return apiFramework.pipeline(require('./previews'), localUtils); }, get emailPost() { - return shared.pipeline(require('./email-post'), localUtils); + return apiFramework.pipeline(require('./email-post'), localUtils); }, get oembed() { - return shared.pipeline(require('./oembed'), localUtils); + return apiFramework.pipeline(require('./oembed'), localUtils); }, get slack() { - return shared.pipeline(require('./slack'), localUtils); + return apiFramework.pipeline(require('./slack'), localUtils); }, get config() { - return shared.pipeline(require('./config'), localUtils); + return apiFramework.pipeline(require('./config'), localUtils); }, get explore() { - return shared.pipeline(require('./explore'), localUtils); + return apiFramework.pipeline(require('./explore'), localUtils); }, get themes() { - return shared.pipeline(require('./themes'), localUtils); + return apiFramework.pipeline(require('./themes'), localUtils); }, get actions() { - return shared.pipeline(require('./actions'), localUtils); + return apiFramework.pipeline(require('./actions'), localUtils); }, get email_previews() { - return shared.pipeline(require('./email-previews'), localUtils); + return apiFramework.pipeline(require('./email-previews'), localUtils); }, get emails() { - return shared.pipeline(require('./emails'), localUtils); + return apiFramework.pipeline(require('./emails'), localUtils); }, get site() { - return shared.pipeline(require('./site'), localUtils); + return apiFramework.pipeline(require('./site'), localUtils); }, get snippets() { - return shared.pipeline(require('./snippets'), localUtils); + return apiFramework.pipeline(require('./snippets'), localUtils); }, get stats() { - return shared.pipeline(require('./stats'), localUtils); + return apiFramework.pipeline(require('./stats'), localUtils); }, get customThemeSettings() { - return shared.pipeline(require('./custom-theme-settings'), localUtils); + return apiFramework.pipeline(require('./custom-theme-settings'), localUtils); }, get serializers() { @@ -178,11 +178,11 @@ module.exports = { }, get newsletters() { - return shared.pipeline(require('./newsletters'), localUtils); + return apiFramework.pipeline(require('./newsletters'), localUtils); }, get comments() { - return shared.pipeline(require('./comments'), localUtils); + return apiFramework.pipeline(require('./comments'), localUtils); }, /** @@ -194,38 +194,38 @@ module.exports = { * `api.admin` soon. Need to figure out how serializers & validation works then. */ get pagesPublic() { - return shared.pipeline(require('./pages-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./pages-public'), localUtils, 'content'); }, get tagsPublic() { - return shared.pipeline(require('./tags-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./tags-public'), localUtils, 'content'); }, get publicSettings() { - return shared.pipeline(require('./settings-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./settings-public'), localUtils, 'content'); }, get postsPublic() { - return shared.pipeline(require('./posts-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./posts-public'), localUtils, 'content'); }, get authorsPublic() { - return shared.pipeline(require('./authors-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./authors-public'), localUtils, 'content'); }, get tiersPublic() { - return shared.pipeline(require('./tiers-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./tiers-public'), localUtils, 'content'); }, get newslettersPublic() { - return shared.pipeline(require('./newsletters-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./newsletters-public'), localUtils, 'content'); }, get offersPublic() { - return shared.pipeline(require('./offers-public'), localUtils, 'content'); + return apiFramework.pipeline(require('./offers-public'), localUtils, 'content'); }, get commentsMembers() { - return shared.pipeline(require('./comments-members'), localUtils, 'members'); + return apiFramework.pipeline(require('./comments-members'), localUtils, 'members'); } }; diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/input/db.js b/ghost/core/core/server/api/endpoints/utils/serializers/input/db.js index 506cdc31b8..78925373ba 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/input/db.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/input/db.js @@ -1,6 +1,6 @@ const _ = require('lodash'); const debug = require('@tryghost/debug')('api:endpoints:utils:serializers:input:db'); -const optionsUtil = require('../../../../shared/utils/options'); +const optionsUtil = require('@tryghost/api-framework').utils.options; const INTERNAL_OPTIONS = ['transacting', 'forUpdate']; diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js b/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js index 182a946d29..4ec2139d52 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js @@ -3,7 +3,7 @@ const debug = require('@tryghost/debug')('api:endpoints:utils:serializers:output const allowedIncludes = ['monthly_price', 'yearly_price']; const localUtils = require('../../index'); -const utils = require('../../../../shared/utils'); +const {utils} = require('@tryghost/api-framework'); const labs = require('../../../../../../shared/labs'); module.exports = { diff --git a/ghost/core/core/server/api/index.js b/ghost/core/core/server/api/index.js index 1389e6c17c..a12b531bc1 100644 --- a/ghost/core/core/server/api/index.js +++ b/ghost/core/core/server/api/index.js @@ -1,3 +1 @@ module.exports.endpoints = require('./endpoints'); - -module.exports.shared = require('./shared'); diff --git a/ghost/core/core/server/services/mega/post-email-serializer.js b/ghost/core/core/server/services/mega/post-email-serializer.js index 3d8d8f33d4..dad330e4b8 100644 --- a/ghost/core/core/server/services/mega/post-email-serializer.js +++ b/ghost/core/core/server/services/mega/post-email-serializer.js @@ -5,7 +5,7 @@ const urlUtils = require('../../../shared/url-utils'); const labs = require('../../../shared/labs'); const moment = require('moment-timezone'); const api = require('../../api').endpoints; -const apiShared = require('../../api').shared; +const apiFramework = require('@tryghost/api-framework'); const {URL} = require('url'); const mobiledocLib = require('../../lib/mobiledoc'); const htmlToPlaintext = require('@tryghost/html-to-plaintext'); @@ -104,7 +104,7 @@ const serializePostModel = async (model) => { const frame = {options: {context: {user: true}, formats: 'mobiledoc'}}; const docName = 'posts'; - await apiShared + await apiFramework .serializers .handle .output(model, {docName: docName, method: 'read'}, api.serializers.output, frame); diff --git a/ghost/core/core/server/services/webhooks/serialize.js b/ghost/core/core/server/services/webhooks/serialize.js index f36dfece34..794e41c329 100644 --- a/ghost/core/core/server/services/webhooks/serialize.js +++ b/ghost/core/core/server/services/webhooks/serialize.js @@ -2,7 +2,7 @@ module.exports = (event, model) => { const _ = require('lodash'); const {sequence} = require('@tryghost/promise'); const api = require('../../api').endpoints; - const apiShared = require('../../api').shared; + const apiFramework = require('@tryghost/api-framework'); const resourceName = event.match(/(\w+)\./)[1]; const docName = `${resourceName}s`; @@ -23,7 +23,7 @@ module.exports = (event, model) => { }; } - return apiShared + return apiFramework .serializers .handle .output(model, {docName: docName, method: 'read'}, api.serializers.output, frame) @@ -46,7 +46,7 @@ module.exports = (event, model) => { frame.options.withRelated = ['tags', 'authors']; } - return apiShared + return apiFramework .serializers .handle .output(model, {docName: docName, method: 'read'}, api.serializers.output, frame) diff --git a/ghost/core/core/server/web/api/endpoints/admin/routes.js b/ghost/core/core/server/web/api/endpoints/admin/routes.js index 3be9c71274..a7a4567145 100644 --- a/ghost/core/core/server/web/api/endpoints/admin/routes.js +++ b/ghost/core/core/server/web/api/endpoints/admin/routes.js @@ -1,6 +1,6 @@ const express = require('../../../../../shared/express'); const api = require('../../../../api').endpoints; -const http = require('../../../../api').shared.http; +const {http} = require('@tryghost/api-framework'); const apiMw = require('../../middleware'); const mw = require('./middleware'); diff --git a/ghost/core/core/server/web/api/endpoints/content/routes.js b/ghost/core/core/server/web/api/endpoints/content/routes.js index f87c37a4a0..bc15a0823d 100644 --- a/ghost/core/core/server/web/api/endpoints/content/routes.js +++ b/ghost/core/core/server/web/api/endpoints/content/routes.js @@ -1,7 +1,7 @@ const express = require('../../../../../shared/express'); const cors = require('cors'); const api = require('../../../../api').endpoints; -const http = require('../../../../api').shared.http; +const {http} = require('@tryghost/api-framework'); const mw = require('./middleware'); const config = require('../../../../../shared/config'); diff --git a/ghost/core/core/server/web/comments/routes.js b/ghost/core/core/server/web/comments/routes.js index f06ff79875..0e3cfa795e 100644 --- a/ghost/core/core/server/web/comments/routes.js +++ b/ghost/core/core/server/web/comments/routes.js @@ -1,6 +1,6 @@ const express = require('../../../shared/express'); const api = require('../../api').endpoints; -const http = require('../../api').shared.http; +const {http} = require('@tryghost/api-framework'); const bodyParser = require('body-parser'); const membersService = require('../../../server/services/members'); diff --git a/ghost/core/package.json b/ghost/core/package.json index 13d5871deb..ddb6b60d34 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -55,6 +55,7 @@ "@sentry/node": "7.9.0", "@tryghost/adapter-manager": "0.0.0", "@tryghost/admin-api-schema": "4.1.1", + "@tryghost/api-framework": "0.0.0", "@tryghost/api-version-compatibility-service": "0.0.0", "@tryghost/bookshelf-plugins": "0.5.0", "@tryghost/bootstrap-socket": "0.0.0",