@littlebox/strapi-suite 1.0.31 → 1.0.33
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/dist/server/index.js +57 -6
- package/dist/server/index.mjs +57 -6
- package/dist/server/src/index.d.ts +12 -3
- package/dist/server/src/middlewares/checkModuleIsActive.d.ts +4 -0
- package/dist/server/src/middlewares/index.d.ts +5 -1
- package/dist/server/src/policies/check-api-token.d.ts +4 -0
- package/dist/server/src/policies/index.d.ts +5 -1
- package/dist/server/src/routes/content-api.d.ts +2 -1
- package/dist/server/src/routes/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -1181,15 +1181,63 @@ const controllers = {
|
|
|
1181
1181
|
ParameterModuleController,
|
|
1182
1182
|
TranslationModuleController
|
|
1183
1183
|
};
|
|
1184
|
-
|
|
1185
|
-
|
|
1184
|
+
function getModuleName(url) {
|
|
1185
|
+
if (url.includes("/pages")) return "slug";
|
|
1186
|
+
if (url.includes("/parameters")) return "parameter";
|
|
1187
|
+
if (url.includes("/translations")) return "translation";
|
|
1188
|
+
if (url.includes("/menus")) return "menu";
|
|
1189
|
+
throw new Error("Module not found");
|
|
1190
|
+
}
|
|
1191
|
+
const CheckModuleIsActive = (config2, { strapi: strapi2 }) => {
|
|
1192
|
+
return async (ctx, next) => {
|
|
1193
|
+
const module2 = getModuleName(ctx.request.url);
|
|
1194
|
+
const config22 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1195
|
+
const setting = await strapi2.db.query(config22.uuid.app.setting).findOne({
|
|
1196
|
+
where: {
|
|
1197
|
+
module: module2,
|
|
1198
|
+
property: "active"
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
const isActive = setting.value === "true";
|
|
1202
|
+
if (!isActive) {
|
|
1203
|
+
return ctx.forbidden("Module is not active");
|
|
1204
|
+
}
|
|
1205
|
+
return next();
|
|
1206
|
+
};
|
|
1207
|
+
};
|
|
1208
|
+
const middlewares = {
|
|
1209
|
+
"check-module-is-active": CheckModuleIsActive
|
|
1210
|
+
};
|
|
1211
|
+
const CheckApiToken = async (policyContext, config2, { strapi: strapi2 }) => {
|
|
1212
|
+
const bearerToken = policyContext.request.header?.authorization?.substring("Bearer ".length);
|
|
1213
|
+
if (!bearerToken) {
|
|
1214
|
+
return false;
|
|
1215
|
+
}
|
|
1216
|
+
const apiTokenService = strapi2.services["admin::api-token"];
|
|
1217
|
+
const accessKey = await apiTokenService.hash(bearerToken);
|
|
1218
|
+
const storedToken = await apiTokenService.getBy({ accessKey });
|
|
1219
|
+
if (!storedToken) {
|
|
1220
|
+
return false;
|
|
1221
|
+
}
|
|
1222
|
+
if (storedToken.expiresAt && storedToken.expiresAt < /* @__PURE__ */ new Date()) {
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
if (storedToken.type !== "read-only") {
|
|
1226
|
+
return false;
|
|
1227
|
+
}
|
|
1228
|
+
return true;
|
|
1229
|
+
};
|
|
1230
|
+
const policies = {
|
|
1231
|
+
"check-api-token": CheckApiToken
|
|
1232
|
+
};
|
|
1186
1233
|
const contentAPIRoutes = [
|
|
1187
1234
|
{
|
|
1188
1235
|
method: "GET",
|
|
1189
1236
|
path: "/modules/pages",
|
|
1190
1237
|
handler: "SlugModuleController.getPages",
|
|
1191
1238
|
config: {
|
|
1192
|
-
|
|
1239
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1240
|
+
policies: ["check-api-token"],
|
|
1193
1241
|
auth: false
|
|
1194
1242
|
}
|
|
1195
1243
|
},
|
|
@@ -1198,7 +1246,8 @@ const contentAPIRoutes = [
|
|
|
1198
1246
|
path: "/modules/menus",
|
|
1199
1247
|
handler: "MenuModuleController.getMenus",
|
|
1200
1248
|
config: {
|
|
1201
|
-
|
|
1249
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1250
|
+
policies: ["check-api-token"],
|
|
1202
1251
|
auth: false
|
|
1203
1252
|
}
|
|
1204
1253
|
},
|
|
@@ -1207,7 +1256,8 @@ const contentAPIRoutes = [
|
|
|
1207
1256
|
path: "/modules/translations",
|
|
1208
1257
|
handler: "TranslationModuleController.getTranslations",
|
|
1209
1258
|
config: {
|
|
1210
|
-
|
|
1259
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1260
|
+
policies: ["check-api-token"],
|
|
1211
1261
|
auth: false
|
|
1212
1262
|
}
|
|
1213
1263
|
},
|
|
@@ -1216,7 +1266,8 @@ const contentAPIRoutes = [
|
|
|
1216
1266
|
path: "/modules/parameters",
|
|
1217
1267
|
handler: "ParameterModuleController.getParameters",
|
|
1218
1268
|
config: {
|
|
1219
|
-
|
|
1269
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1270
|
+
policies: ["check-api-token"],
|
|
1220
1271
|
auth: false
|
|
1221
1272
|
}
|
|
1222
1273
|
}
|
package/dist/server/index.mjs
CHANGED
|
@@ -1180,15 +1180,63 @@ const controllers = {
|
|
|
1180
1180
|
ParameterModuleController,
|
|
1181
1181
|
TranslationModuleController
|
|
1182
1182
|
};
|
|
1183
|
-
|
|
1184
|
-
|
|
1183
|
+
function getModuleName(url) {
|
|
1184
|
+
if (url.includes("/pages")) return "slug";
|
|
1185
|
+
if (url.includes("/parameters")) return "parameter";
|
|
1186
|
+
if (url.includes("/translations")) return "translation";
|
|
1187
|
+
if (url.includes("/menus")) return "menu";
|
|
1188
|
+
throw new Error("Module not found");
|
|
1189
|
+
}
|
|
1190
|
+
const CheckModuleIsActive = (config2, { strapi: strapi2 }) => {
|
|
1191
|
+
return async (ctx, next) => {
|
|
1192
|
+
const module = getModuleName(ctx.request.url);
|
|
1193
|
+
const config22 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1194
|
+
const setting = await strapi2.db.query(config22.uuid.app.setting).findOne({
|
|
1195
|
+
where: {
|
|
1196
|
+
module,
|
|
1197
|
+
property: "active"
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
const isActive = setting.value === "true";
|
|
1201
|
+
if (!isActive) {
|
|
1202
|
+
return ctx.forbidden("Module is not active");
|
|
1203
|
+
}
|
|
1204
|
+
return next();
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
const middlewares = {
|
|
1208
|
+
"check-module-is-active": CheckModuleIsActive
|
|
1209
|
+
};
|
|
1210
|
+
const CheckApiToken = async (policyContext, config2, { strapi: strapi2 }) => {
|
|
1211
|
+
const bearerToken = policyContext.request.header?.authorization?.substring("Bearer ".length);
|
|
1212
|
+
if (!bearerToken) {
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
const apiTokenService = strapi2.services["admin::api-token"];
|
|
1216
|
+
const accessKey = await apiTokenService.hash(bearerToken);
|
|
1217
|
+
const storedToken = await apiTokenService.getBy({ accessKey });
|
|
1218
|
+
if (!storedToken) {
|
|
1219
|
+
return false;
|
|
1220
|
+
}
|
|
1221
|
+
if (storedToken.expiresAt && storedToken.expiresAt < /* @__PURE__ */ new Date()) {
|
|
1222
|
+
return false;
|
|
1223
|
+
}
|
|
1224
|
+
if (storedToken.type !== "read-only") {
|
|
1225
|
+
return false;
|
|
1226
|
+
}
|
|
1227
|
+
return true;
|
|
1228
|
+
};
|
|
1229
|
+
const policies = {
|
|
1230
|
+
"check-api-token": CheckApiToken
|
|
1231
|
+
};
|
|
1185
1232
|
const contentAPIRoutes = [
|
|
1186
1233
|
{
|
|
1187
1234
|
method: "GET",
|
|
1188
1235
|
path: "/modules/pages",
|
|
1189
1236
|
handler: "SlugModuleController.getPages",
|
|
1190
1237
|
config: {
|
|
1191
|
-
|
|
1238
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1239
|
+
policies: ["check-api-token"],
|
|
1192
1240
|
auth: false
|
|
1193
1241
|
}
|
|
1194
1242
|
},
|
|
@@ -1197,7 +1245,8 @@ const contentAPIRoutes = [
|
|
|
1197
1245
|
path: "/modules/menus",
|
|
1198
1246
|
handler: "MenuModuleController.getMenus",
|
|
1199
1247
|
config: {
|
|
1200
|
-
|
|
1248
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1249
|
+
policies: ["check-api-token"],
|
|
1201
1250
|
auth: false
|
|
1202
1251
|
}
|
|
1203
1252
|
},
|
|
@@ -1206,7 +1255,8 @@ const contentAPIRoutes = [
|
|
|
1206
1255
|
path: "/modules/translations",
|
|
1207
1256
|
handler: "TranslationModuleController.getTranslations",
|
|
1208
1257
|
config: {
|
|
1209
|
-
|
|
1258
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1259
|
+
policies: ["check-api-token"],
|
|
1210
1260
|
auth: false
|
|
1211
1261
|
}
|
|
1212
1262
|
},
|
|
@@ -1215,7 +1265,8 @@ const contentAPIRoutes = [
|
|
|
1215
1265
|
path: "/modules/parameters",
|
|
1216
1266
|
handler: "ParameterModuleController.getParameters",
|
|
1217
1267
|
config: {
|
|
1218
|
-
|
|
1268
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1269
|
+
policies: ["check-api-token"],
|
|
1219
1270
|
auth: false
|
|
1220
1271
|
}
|
|
1221
1272
|
}
|
|
@@ -121,7 +121,8 @@ declare const _default: {
|
|
|
121
121
|
path: string;
|
|
122
122
|
handler: string;
|
|
123
123
|
config: {
|
|
124
|
-
|
|
124
|
+
middlewares: string[];
|
|
125
|
+
policies: string[];
|
|
125
126
|
auth: boolean;
|
|
126
127
|
};
|
|
127
128
|
}[];
|
|
@@ -648,7 +649,15 @@ declare const _default: {
|
|
|
648
649
|
};
|
|
649
650
|
};
|
|
650
651
|
};
|
|
651
|
-
policies: {
|
|
652
|
-
|
|
652
|
+
policies: {
|
|
653
|
+
'check-api-token': (policyContext: any, config: any, { strapi }: {
|
|
654
|
+
strapi: any;
|
|
655
|
+
}) => Promise<boolean>;
|
|
656
|
+
};
|
|
657
|
+
middlewares: {
|
|
658
|
+
'check-module-is-active': (config: any, { strapi }: {
|
|
659
|
+
strapi: any;
|
|
660
|
+
}) => (ctx: any, next: any) => Promise<any>;
|
|
661
|
+
};
|
|
653
662
|
};
|
|
654
663
|
export default _default;
|
package/package.json
CHANGED