@strapi/strapi 0.0.0-e6cac9fe30 → 0.0.0-fd8e4c6bfa

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/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  <img src="https://img.shields.io/npm/v/@strapi/strapi/latest.svg" alt="NPM Version" />
14
14
  </a>
15
15
  <a href="https://github.com/strapi/strapi/actions/workflows/tests.yml">
16
- <img src="https://github.com/strapi/strapi/actions/workflows/tests.yml/badge.svg?branch=master" alt="Tests" />
16
+ <img src="https://github.com/strapi/strapi/actions/workflows/tests.yml/badge.svg?branch=main" alt="Tests" />
17
17
  </a>
18
18
  <a href="https://discord.strapi.io">
19
19
  <img src="https://img.shields.io/discord/811989166782021633?label=Discord" alt="Strapi on Discord" />
@@ -12,11 +12,14 @@ export interface SingleTypeService extends BaseService {
12
12
 
13
13
  export interface CollectionTypeService extends BaseService {
14
14
  find?(params: object): Promise<Entity[]> | Entity;
15
- findOne?(entityId: string,params: object): Promise<Entity> | Entity;
15
+ findOne?(entityId: string, params: object): Promise<Entity> | Entity;
16
16
  create?(params: object): Promise<Entity> | Entity;
17
- update?(entityId: string,params: object): Promise<Entity> | Entity;
18
- delete?(entityId: string,params: object): Promise<Entity> | Entity;
17
+ update?(entityId: string, params: object): Promise<Entity> | Entity;
18
+ delete?(entityId: string, params: object): Promise<Entity> | Entity;
19
19
  }
20
20
 
21
21
  export type Service = SingleTypeService | CollectionTypeService;
22
22
 
23
+ export type GenericService = Partial<Service> & {
24
+ [method: string | number | symbol]: <T = any>(...args: any) => T;
25
+ };
@@ -23,12 +23,19 @@ function getFiles(ctx) {
23
23
  /**
24
24
  * @type {import('./').MiddlewareFactory}
25
25
  */
26
- module.exports = (config) => {
26
+
27
+ module.exports = (config, { strapi }) => {
27
28
  const bodyConfig = defaultsDeep(defaults, config);
28
29
 
30
+ let gqlEndpoint;
31
+ if (strapi.plugin('graphql')) {
32
+ const { config: gqlConfig } = strapi.plugin('graphql');
33
+ gqlEndpoint = gqlConfig('endpoint');
34
+ }
35
+
29
36
  return async (ctx, next) => {
30
37
  // TODO: find a better way later
31
- if (ctx.url === '/graphql') {
38
+ if (gqlEndpoint && ctx.url === gqlEndpoint) {
32
39
  await next();
33
40
  } else {
34
41
  try {
@@ -33,7 +33,7 @@ module.exports = (config) => {
33
33
 
34
34
  const requestOrigin = ctx.accept.headers.origin;
35
35
  if (whitelist.includes('*')) {
36
- return '*';
36
+ return credentials ? requestOrigin : '*';
37
37
  }
38
38
 
39
39
  if (!whitelist.includes(requestOrigin)) {
@@ -30,22 +30,28 @@ const defaults = {
30
30
  /**
31
31
  * @type {import('./').MiddlewareFactory}
32
32
  */
33
- module.exports = (config) => (ctx, next) => {
34
- let helmetConfig = defaultsDeep(defaults, config);
35
33
 
36
- if (
37
- ctx.method === 'GET' &&
38
- ['/graphql', '/documentation'].some((str) => ctx.path.startsWith(str))
39
- ) {
40
- helmetConfig = merge(helmetConfig, {
41
- contentSecurityPolicy: {
42
- directives: {
43
- 'script-src': ["'self'", "'unsafe-inline'", 'cdn.jsdelivr.net'],
44
- 'img-src': ["'self'", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],
34
+ module.exports =
35
+ (config, { strapi }) =>
36
+ (ctx, next) => {
37
+ let helmetConfig = defaultsDeep(defaults, config);
38
+ const specialPaths = ['/documentation'];
39
+
40
+ if (strapi.plugin('graphql')) {
41
+ const { config: gqlConfig } = strapi.plugin('graphql');
42
+ specialPaths.push(gqlConfig('endpoint'));
43
+ }
44
+
45
+ if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {
46
+ helmetConfig = merge(helmetConfig, {
47
+ contentSecurityPolicy: {
48
+ directives: {
49
+ 'script-src': ["'self'", "'unsafe-inline'", 'cdn.jsdelivr.net'],
50
+ 'img-src': ["'self'", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],
51
+ },
45
52
  },
46
- },
47
- });
48
- }
53
+ });
54
+ }
49
55
 
50
- return helmet(helmetConfig)(ctx, next);
51
- };
56
+ return helmet(helmetConfig)(ctx, next);
57
+ };
@@ -228,7 +228,19 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
228
228
  // select / populate
229
229
  const query = transformParamsToQuery(uid, wrappedParams);
230
230
 
231
- return db.query(uid).deleteMany(query);
231
+ const entitiesToDelete = await db.query(uid).findMany(query);
232
+
233
+ if (!entitiesToDelete.length) {
234
+ return null;
235
+ }
236
+
237
+ const deletedEntities = await db.query(uid).deleteMany(query);
238
+ await Promise.all(entitiesToDelete.map((entity) => deleteComponents(uid, entity)));
239
+
240
+ // Trigger webhooks. One for each entity
241
+ await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
242
+
243
+ return deletedEntities;
232
244
  },
233
245
 
234
246
  load(uid, entity, field, params = {}) {
@@ -2,7 +2,8 @@ import type Koa from 'koa';
2
2
  import { Database } from '@strapi/database';
3
3
 
4
4
  import type { StringMap } from './utils';
5
- import type { GenericController } from '../core-api/controller'
5
+ import type { GenericController } from '../../../core-api/controller'
6
+ import type { GenericService } from '../../../core-api/service'
6
7
 
7
8
  /**
8
9
  * The Strapi interface implemented by the main Strapi class.
@@ -33,12 +34,12 @@ export interface Strapi {
33
34
  *
34
35
  * It returns all the registered services
35
36
  */
36
- readonly services: StringMap<Service>;
37
+ readonly services: StringMap<GenericService>;
37
38
 
38
39
  /**
39
40
  * Find a service using its unique identifier
40
41
  */
41
- service<T extends Service = unknown>(uid: string): T | undefined;
42
+ service<T extends GenericService = GenericService>(uid: string): T | undefined;
42
43
 
43
44
  /**
44
45
  * Getter for the Strapi controllers container
@@ -1,4 +1,4 @@
1
- import { Service } from '../core-api/service';
1
+ import { Service,GenericService } from '../core-api/service';
2
2
  import { Controller, GenericController } from '../core-api/controller';
3
3
  import { Middleware } from '../middlewares';
4
4
  import { Policy } from '../core/registries/policies';
@@ -47,14 +47,14 @@ interface Router {
47
47
  type ControllerCallback<T extends GenericController = GenericController> = (params: {
48
48
  strapi: Strapi;
49
49
  }) => T;
50
- type ServiceCallback<T extends Service = Service> = (params: { strapi: Strapi }) => T;
50
+ type ServiceCallback<T extends GenericService = GenericService> = (params: { strapi: Strapi }) => T;
51
51
 
52
52
  export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
53
53
  export function createCoreController<T extends GenericController = GenericController>(
54
54
  uid: string,
55
55
  cfg?: ControllerCallback<T> | T = {}
56
56
  ): () => T & Controller;
57
- export function createCoreService<T extends Service = Service>(
57
+ export function createCoreService<T extends GenericService = GenericService>(
58
58
  uid: string,
59
59
  cfg?: ServiceCallback<T> | T = {}
60
60
  ): () => T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "0.0.0-e6cac9fe30",
3
+ "version": "0.0.0-fd8e4c6bfa",
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",
@@ -80,17 +80,17 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "0.0.0-e6cac9fe30",
84
- "@strapi/database": "0.0.0-e6cac9fe30",
85
- "@strapi/generate-new": "0.0.0-e6cac9fe30",
86
- "@strapi/generators": "0.0.0-e6cac9fe30",
87
- "@strapi/logger": "0.0.0-e6cac9fe30",
88
- "@strapi/plugin-content-manager": "0.0.0-e6cac9fe30",
89
- "@strapi/plugin-content-type-builder": "0.0.0-e6cac9fe30",
90
- "@strapi/plugin-email": "0.0.0-e6cac9fe30",
91
- "@strapi/plugin-upload": "0.0.0-e6cac9fe30",
92
- "@strapi/typescript-utils": "0.0.0-e6cac9fe30",
93
- "@strapi/utils": "0.0.0-e6cac9fe30",
83
+ "@strapi/admin": "0.0.0-fd8e4c6bfa",
84
+ "@strapi/database": "0.0.0-fd8e4c6bfa",
85
+ "@strapi/generate-new": "0.0.0-fd8e4c6bfa",
86
+ "@strapi/generators": "0.0.0-fd8e4c6bfa",
87
+ "@strapi/logger": "0.0.0-fd8e4c6bfa",
88
+ "@strapi/plugin-content-manager": "0.0.0-fd8e4c6bfa",
89
+ "@strapi/plugin-content-type-builder": "0.0.0-fd8e4c6bfa",
90
+ "@strapi/plugin-email": "0.0.0-fd8e4c6bfa",
91
+ "@strapi/plugin-upload": "0.0.0-fd8e4c6bfa",
92
+ "@strapi/typescript-utils": "0.0.0-fd8e4c6bfa",
93
+ "@strapi/utils": "0.0.0-fd8e4c6bfa",
94
94
  "bcryptjs": "2.4.3",
95
95
  "boxen": "5.1.2",
96
96
  "chalk": "4.1.2",
@@ -139,5 +139,5 @@
139
139
  "node": ">=14.19.1 <=16.x.x",
140
140
  "npm": ">=6.0.0"
141
141
  },
142
- "gitHead": "e6cac9fe309b80c9c59cde56d6b25fc6cd40bc8d"
142
+ "gitHead": "fd8e4c6bfa2fd687a3c62f8428e00f3b320c32c2"
143
143
  }