Skip to content

Commit

Permalink
update to koa-router latest 12.x, fix some tests
Browse files Browse the repository at this point in the history
update open & rimraf, use fixed version for some dependencies,
update s3 upload plugin to v3 sdk, add base url support
  • Loading branch information
imaksp committed Jan 17, 2023
1 parent 349e9dd commit 85f1a08
Show file tree
Hide file tree
Showing 19 changed files with 718 additions and 355 deletions.
356 changes: 254 additions & 102 deletions packages/strapi-admin/tests/admin-permission.test.e2e.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/strapi-connector-bookshelf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lodash": "4.17.21",
"p-map": "4.0.0",
"pluralize": "^8.0.0",
"rimraf": "3.0.2"
"rimraf": "4.1.0"
},
"peerDependencies": {
"knex": "0.21.18"
Expand Down
2 changes: 1 addition & 1 deletion packages/strapi-helper-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@babel/preset-react": "^7.13.13",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.15.6",
"rimraf": "3.0.2",
"rimraf": "4.1.0",
"rollup": "^1.10.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.3.4",
Expand Down
15 changes: 8 additions & 7 deletions packages/strapi-hook-redis/lib/utils/connectivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ module.exports = (scope, success, error) => {

logger.info('The app has been connected to the database successfully!');

rimraf(scope.tmpPath, (err) => {
if (err) {
console.log(`Error removing connection test folder: ${scope.tmpPath}`);
rimraf(scope.tmpPath).then(
() => {
logger.info('Copying the dashboard...');
success();
},
(err) => {
console.log(`Error removing connection test folder: ${scope.tmpPath}`, err);
}
logger.info('Copying the dashboard...');

success();
});
);
});
};
2 changes: 1 addition & 1 deletion packages/strapi-hook-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@akemona-org/strapi-utils": "3.9.4",
"ioredis": "^4.27.1",
"lodash": "4.17.21",
"rimraf": "3.0.2",
"rimraf": "4.1.0",
"stack-trace": "0.0.10"
},
"author": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Content Type Builder - Content types Collection Types Get collection type returns full schema and information 1`] = `
Object {
"data": Object {
{
"data": {
"apiID": "test-collection-type",
"schema": Object {
"attributes": Object {
"title": Object {
"pluginOptions": Object {
"i18n": Object {
"schema": {
"attributes": {
"title": {
"pluginOptions": {
"i18n": {
"localized": true,
},
},
Expand All @@ -21,8 +21,8 @@ Object {
"draftAndPublish": false,
"kind": "collectionType",
"name": "Test Collection Type",
"pluginOptions": Object {
"i18n": Object {
"pluginOptions": {
"i18n": {
"localized": true,
},
},
Expand All @@ -35,12 +35,12 @@ Object {
`;

exports[`Content Type Builder - Content types Collection Types Get collection type returns full schema and informations with draftAndPublish 1`] = `
Object {
"data": Object {
{
"data": {
"apiID": "ct-with-dp",
"schema": Object {
"attributes": Object {
"title": Object {
"schema": {
"attributes": {
"title": {
"type": "string",
},
},
Expand All @@ -59,14 +59,14 @@ Object {
`;

exports[`Content Type Builder - Content types Single Types Get single type returns full schema and information 1`] = `
Object {
"data": Object {
{
"data": {
"apiID": "test-single-type",
"schema": Object {
"attributes": Object {
"title": Object {
"pluginOptions": Object {
"i18n": Object {
"schema": {
"attributes": {
"title": {
"pluginOptions": {
"i18n": {
"localized": true,
},
},
Expand All @@ -79,8 +79,8 @@ Object {
"draftAndPublish": false,
"kind": "singleType",
"name": "Test Single Type",
"pluginOptions": Object {
"i18n": Object {
"pluginOptions": {
"i18n": {
"localized": true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = (strapi) => {
}
);

strapi.router.get('/plugins/documentation/*', async (ctx, next) => {
strapi.router.get('/plugins/documentation/(.*)', async (ctx, next) => {
ctx.url = path.basename(ctx.url);

return await koaStatic(swaggerUi.getAbsoluteFSPath(), {
Expand Down
2 changes: 1 addition & 1 deletion packages/strapi-plugin-email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@akemona-org/strapi-helper-plugin": "3.9.4",
"rimraf": "3.0.2"
"rimraf": "4.1.0"
},
"author": {
"name": "Akemona team",
Expand Down
2 changes: 1 addition & 1 deletion packages/strapi-plugin-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"devDependencies": {
"cross-env": "^7.0.3",
"koa": "^2.13.1",
"rimraf": "3.0.2"
"rimraf": "4.1.0"
},
"engines": {
"node": ">=14.19.1 <=18.x.x",
Expand Down
34 changes: 9 additions & 25 deletions packages/strapi-plugin-users-permissions/config/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
"path": "/roles/:id",
"handler": "UsersPermissions.getRole",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.roles.read"]]
],
"policies": [["admin::hasPermissions", ["plugins::users-permissions.roles.read"]]],
"description": "Retrieve a role depending on its id",
"tag": {
"plugin": "users-permissions",
Expand All @@ -51,9 +49,7 @@
"path": "/roles",
"handler": "UsersPermissions.getRoles",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.roles.read"]]
],
"policies": [["admin::hasPermissions", ["plugins::users-permissions.roles.read"]]],
"description": "Retrieve all role documents",
"tag": {
"plugin": "users-permissions",
Expand All @@ -75,9 +71,7 @@
"path": "/email-templates",
"handler": "UsersPermissions.getEmailTemplate",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.email-templates.read"]]
]
"policies": [["admin::hasPermissions", ["plugins::users-permissions.email-templates.read"]]]
}
},
{
Expand Down Expand Up @@ -123,9 +117,7 @@
"path": "/providers",
"handler": "UsersPermissions.getProviders",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.providers.read"]]
]
"policies": [["admin::hasPermissions", ["plugins::users-permissions.providers.read"]]]
}
},

Expand All @@ -134,19 +126,15 @@
"path": "/providers",
"handler": "UsersPermissions.updateProviders",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.providers.update"]]
]
"policies": [["admin::hasPermissions", ["plugins::users-permissions.providers.update"]]]
}
},
{
"method": "POST",
"path": "/roles",
"handler": "UsersPermissions.createRole",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.roles.create"]]
],
"policies": [["admin::hasPermissions", ["plugins::users-permissions.roles.create"]]],
"description": "Create a new role",
"tag": {
"plugin": "users-permissions",
Expand All @@ -160,9 +148,7 @@
"path": "/roles/:role",
"handler": "UsersPermissions.updateRole",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.roles.update"]]
],
"policies": [["admin::hasPermissions", ["plugins::users-permissions.roles.update"]]],
"description": "Update a role",
"tag": {
"plugin": "users-permissions",
Expand All @@ -176,9 +162,7 @@
"path": "/roles/:role",
"handler": "UsersPermissions.deleteRole",
"config": {
"policies": [
["admin::hasPermissions", ["plugins::users-permissions.roles.delete"]]
],
"policies": [["admin::hasPermissions", ["plugins::users-permissions.roles.delete"]]],
"description": "Delete a role",
"tag": {
"plugin": "users-permissions",
Expand All @@ -189,7 +173,7 @@
},
{
"method": "GET",
"path": "/connect/*",
"path": "/connect/(.*)",
"handler": "Auth.connect",
"config": {
"policies": ["plugins::users-permissions.ratelimit"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
]
}
},
"/connect/*": {
"/connect/(.*)": {
"get": {
"summary": "Authenticate your user with a custom provider",
"tags": ["Authentication"],
Expand Down
90 changes: 46 additions & 44 deletions packages/strapi-provider-upload-aws-s3/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,64 @@
* Module dependencies
*/

/* eslint-disable no-unused-vars */
// Public node modules.
const _ = require('lodash');
const AWS = require('aws-sdk');
const { S3Client, PutObjectCommand, DeleteObjectCommand } = require('@aws-sdk/client-s3');

module.exports = {
init(config) {
const S3 = new AWS.S3({
apiVersion: '2006-03-01',
...config,
if (!config.params.Bucket || !config.region) {
throw new Error('Invalid config.');
}
const client = new S3Client({
region: config.region,
...(config.accessKeyId && {
credentials: {
accessKeyId: config.accessKeyId,
secretAccessKey: config.secretAccessKey,
},
}),
});

return {
upload(file, customParams = {}) {
return new Promise((resolve, reject) => {
// upload file on S3 bucket
const path = file.path ? `${file.path}/` : '';
S3.upload(
{
Key: `${path}${file.hash}${file.ext}`,
Body: Buffer.from(file.buffer, 'binary'),
ACL: 'public-read',
ContentType: file.mime,
...customParams,
},
(err, data) => {
if (err) {
return reject(err);
}

// set the bucket file url
file.url = data.Location;
async upload(file, customParams = {}) {
// upload file on S3 bucket
const path = file.path ? `${file.path}/` : '';

resolve();
}
);
});
try {
const command = new PutObjectCommand({
Bucket: config.params.Bucket,
Key: `${path}${file.hash}${file.ext}`,
Body: Buffer.from(file.buffer, 'binary'),
ACL: 'public-read',
ContentType: file.mime,
...customParams,
});
client.config.Bu;
const data = await client.send(command);
const location = `https://${command.input.Bucket}.s3.${config.region}.amazonaws.com/${command.input.Key}`;
file.url = config.baseUrl ? `${config.baseUrl}/${command.input.Key}` : location;
// console.log('s3 upload Success:', data);
return data;
} catch (err) {
console.log('s3 upload failed: ' + err);
throw err;
}
},
delete(file, customParams = {}) {
return new Promise((resolve, reject) => {
// delete file on S3 bucket
const path = file.path ? `${file.path}/` : '';
S3.deleteObject(
{
async delete(file, customParams = {}) {
// delete file on S3 bucket
const path = file.path ? `${file.path}/` : '';
try {
const data = await client.send(
new DeleteObjectCommand({
Key: `${path}${file.hash}${file.ext}`,
...customParams,
},
(err, data) => {
if (err) {
return reject(err);
}

resolve();
}
})
);
});
return data;
} catch (err) {
console.log('delete from S3 failed: ' + err);
throw err;
}
},
};
},
Expand Down
3 changes: 1 addition & 2 deletions packages/strapi-provider-upload-aws-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
},
"main": "./lib",
"dependencies": {
"aws-sdk": "2.892.0",
"lodash": "4.17.21"
"@aws-sdk/client-s3": "3.245.0"
},
"strapi": {
"isProvider": true
Expand Down
2 changes: 1 addition & 1 deletion packages/strapi/lib/Strapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const http = require('http');
const path = require('path');
const fse = require('fs-extra');
const Koa = require('koa');
const Router = require('koa-router');
const Router = require('@koa/router');
const _ = require('lodash');
const chalk = require('chalk');
const CLITable = require('cli-table3');
Expand Down
Loading

0 comments on commit 85f1a08

Please sign in to comment.