@strapi/core 0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8 → 0.0.0-next.913e7071c9410ff8af2e776e25f9fb1c38cb59dd
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.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts +1 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +21 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +21 -2
- package/dist/Strapi.mjs.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +2 -1
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +2 -1
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +3 -2
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +13 -3
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +13 -3
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +1 -1
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +35 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.mjs +35 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -1
- package/dist/core-api/routes/validation/utils.js +22 -6
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/core-api/routes/validation/utils.mjs +22 -6
- package/dist/core-api/routes/validation/utils.mjs.map +1 -1
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +17 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +17 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/loaders/plugins/index.js +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +2 -15
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +2 -15
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/migrations/first-published-at.d.ts +4 -0
- package/dist/migrations/first-published-at.d.ts.map +1 -0
- package/dist/migrations/first-published-at.js +51 -0
- package/dist/migrations/first-published-at.js.map +1 -0
- package/dist/migrations/first-published-at.mjs +49 -0
- package/dist/migrations/first-published-at.mjs.map +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/package.json.js +13 -11
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +13 -11
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +2 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/session-manager.d.ts +3 -0
- package/dist/providers/session-manager.d.ts.map +1 -0
- package/dist/providers/session-manager.js +23 -0
- package/dist/providers/session-manager.js.map +1 -0
- package/dist/providers/session-manager.mjs +21 -0
- package/dist/providers/session-manager.mjs.map +1 -0
- package/dist/services/content-api/index.d.ts +1 -1
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +2 -2
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts +13 -0
- package/dist/services/content-source-maps.d.ts.map +1 -0
- package/dist/services/content-source-maps.js +108 -0
- package/dist/services/content-source-maps.js.map +1 -0
- package/dist/services/content-source-maps.mjs +106 -0
- package/dist/services/content-source-maps.mjs.map +1 -0
- package/dist/services/document-service/components.d.ts +31 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +109 -0
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +107 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/first-published-at.d.ts +7 -0
- package/dist/services/document-service/first-published-at.d.ts.map +1 -0
- package/dist/services/document-service/first-published-at.js +31 -0
- package/dist/services/document-service/first-published-at.js.map +1 -0
- package/dist/services/document-service/first-published-at.mjs +28 -0
- package/dist/services/document-service/first-published-at.mjs.map +1 -0
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +11 -4
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +12 -5
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/metrics/index.js +2 -1
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +2 -1
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -1
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js +2 -2
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs +2 -2
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +2 -1
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +2 -1
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/session-manager.d.ts +167 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +529 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/session-manager.mjs +526 -0
- package/dist/services/session-manager.mjs.map +1 -0
- package/package.json +13 -11
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { transformUidToValidOpenApiName } from '@strapi/utils';
|
|
2
2
|
import * as z from 'zod/v4';
|
|
3
3
|
|
|
4
|
+
// Schema generation happens on-demand when schemas don't exist in the registry
|
|
4
5
|
/**
|
|
5
6
|
* Safely adds or updates a schema in Zod's global registry.
|
|
6
7
|
*
|
|
@@ -18,13 +19,13 @@ import * as z from 'zod/v4';
|
|
|
18
19
|
try {
|
|
19
20
|
const { _idmap: idMap } = z.globalRegistry;
|
|
20
21
|
const transformedId = transformUidToValidOpenApiName(id);
|
|
21
|
-
|
|
22
|
+
const isReplacing = idMap.has(transformedId);
|
|
23
|
+
if (isReplacing) {
|
|
22
24
|
// Remove existing schema to prevent conflicts
|
|
23
|
-
strapi.log.debug(`Removing existing schema ${transformedId} from registry`);
|
|
24
25
|
idMap.delete(transformedId);
|
|
25
26
|
}
|
|
26
27
|
// Register the new schema with the transformed ID
|
|
27
|
-
strapi.log.debug(
|
|
28
|
+
strapi.log.debug(`${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`);
|
|
28
29
|
z.globalRegistry.add(schema, {
|
|
29
30
|
id: transformedId
|
|
30
31
|
});
|
|
@@ -67,10 +68,20 @@ import * as z from 'zod/v4';
|
|
|
67
68
|
// Return existing schema if already registered
|
|
68
69
|
const mapItem = idMap.get(transformedId);
|
|
69
70
|
if (mapItem) {
|
|
70
|
-
|
|
71
|
+
// Schema already exists, return it silently
|
|
71
72
|
return mapItem;
|
|
72
73
|
}
|
|
73
|
-
strapi.log.
|
|
74
|
+
strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
|
|
75
|
+
// Determine if this is a built-in schema or user content
|
|
76
|
+
const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
|
|
77
|
+
if (isBuiltInSchema) {
|
|
78
|
+
// Built-in schemas keep at debug level to avoid clutter
|
|
79
|
+
strapi.log.debug(`Initializing validation schema for ${transformedId}`);
|
|
80
|
+
} else {
|
|
81
|
+
// User content
|
|
82
|
+
const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
|
|
83
|
+
strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
|
|
84
|
+
}
|
|
74
85
|
// Temporary any placeholder before replacing with the actual schema type
|
|
75
86
|
// Used to prevent infinite loops in cyclical data structures
|
|
76
87
|
safeGlobalRegistrySet(id, z.any());
|
|
@@ -78,7 +89,12 @@ import * as z from 'zod/v4';
|
|
|
78
89
|
const schema = callback();
|
|
79
90
|
// Replace the placeholder with the real schema
|
|
80
91
|
safeGlobalRegistrySet(id, schema);
|
|
81
|
-
|
|
92
|
+
// Show completion for user content only
|
|
93
|
+
if (!isBuiltInSchema) {
|
|
94
|
+
const fieldCount = Object.keys(schema?._def?.shape || {}).length || 0;
|
|
95
|
+
const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
|
|
96
|
+
strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
|
|
97
|
+
}
|
|
82
98
|
return schema;
|
|
83
99
|
} catch (error) {
|
|
84
100
|
strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n // Built-in schemas keep at debug level to avoid clutter\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n // User content\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` ✅ \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","strapi","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,EAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,8BAA+BP,CAAAA,EAAAA,CAAAA;QAErD,MAAMQ,WAAAA,GAAcL,KAAMM,CAAAA,GAAG,CAACH,aAAAA,CAAAA;AAE9B,QAAA,IAAIE,WAAa,EAAA;;AAEfL,YAAAA,KAAAA,CAAMO,MAAM,CAACJ,aAAAA,CAAAA;AACf;;AAGAK,QAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CACd,CAAC,EAAEL,WAAc,GAAA,WAAA,GAAc,aAAc,CAAA,QAAQ,EAAEF,aAAAA,CAAc,mBAAmB,CAAC,CAAA;AAE3FF,QAAAA,CAAAA,CAAEC,cAAc,CAACS,GAAG,CAACb,MAAQ,EAAA;YAAED,EAAIM,EAAAA;AAAc,SAAA,CAAA;AACnD,KAAA,CAAE,OAAOS,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK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AAGflB,QAAAA,qBAAAA,CAAsBC,EAAIC,EAAAA,MAAAA,CAAAA;;AAG1B,QAAA,IAAI,CAACmB,eAAiB,EAAA;YACpB,MAAMM,UAAAA,GAAaC,MAAOC,CAAAA,IAAI,CAAE3B,MAAgB4B,EAAAA,IAAAA,EAAMC,KAAS,IAAA,EAAIC,CAAAA,CAAAA,MAAM,IAAI,CAAA;AAC7E,YAAA,MAAMT,UAAahB,GAAAA,aAAAA,CAChBiB,OAAO,CAAC,YAAY,EACpBA,CAAAA,CAAAA,OAAO,CAAC,OAAA,EAAS,EACjBA,CAAAA,CAAAA,OAAO,CAAC,UAAA,EAAY,OACpBC,IAAI,EAAA;AACPb,YAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CAAC,CAAC,MAAM,EAAES,UAAAA,CAAW,sBAAsB,EAAEI,UAAW,CAAA,OAAO,CAAC,CAAA;AAClF;QAEA,OAAOzB,MAAAA;AACT,KAAA,CAAE,OAAOc,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK,CAAC,CAAC,gDAAgD,EAAEf,GAAG,CAAC,CAAA;QAExE,MAAMe,KAAAA;AACR;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAWF,QAAA,MAAM,iBAAiB,QAAS,MAAM,cAAc,qBAAqB,0DAmCxE,CAAC;AA0EF,QAAA,MAAM,WAAW,WAAY,OAAO,WAAW,WAAW,MAAM,WAK/D,CAAC;AAmBF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -5,7 +5,7 @@ var _ = require('lodash');
|
|
|
5
5
|
var strapiUtils = require('@strapi/utils');
|
|
6
6
|
var validator = require('./validator.js');
|
|
7
7
|
|
|
8
|
-
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
|
8
|
+
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
|
9
9
|
const createContentType = (uid, definition)=>{
|
|
10
10
|
try {
|
|
11
11
|
validator.validateContentTypeDefinition(definition);
|
|
@@ -31,6 +31,7 @@ const createContentType = (uid, definition)=>{
|
|
|
31
31
|
// In case it is not enabled, value will be always published, and it will not contain a draft
|
|
32
32
|
addDraftAndPublish(schema);
|
|
33
33
|
addCreatorFields(schema);
|
|
34
|
+
addFirstPublishedAt(schema);
|
|
34
35
|
return schema;
|
|
35
36
|
};
|
|
36
37
|
const addTimestamps = (schema)=>{
|
|
@@ -59,6 +60,21 @@ const addDraftAndPublish = (schema)=>{
|
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
62
|
};
|
|
63
|
+
const addFirstPublishedAt = (schema)=>{
|
|
64
|
+
const isEnabled = strapiUtils.contentTypes.hasFirstPublishedAtField(schema);
|
|
65
|
+
// Note: As an expertimental feature, we are okay if this data is deleted if this feature is
|
|
66
|
+
// switched off. Once "preserve_attributes" come into play, this will be updated.
|
|
67
|
+
if (isEnabled) {
|
|
68
|
+
strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
|
|
69
|
+
schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
|
|
70
|
+
type: 'datetime',
|
|
71
|
+
configurable: false,
|
|
72
|
+
writable: true,
|
|
73
|
+
visible: false,
|
|
74
|
+
private: !isEnabled
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
62
78
|
const addCreatorFields = (schema)=>{
|
|
63
79
|
const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
|
|
64
80
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,yBAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,uCAA8BD,CAAAA,UAAAA,CAAAA;AAChC,KAAA,CAAE,OAAOE,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,eAAIC,CAAAA,eAAe,EAAE;YACpC,MAAM,IAAIC,KAAM,CAAA,CAAC,uCAAuC,EAAEN,GAAI,CAAA,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dC,QAAU,EAAA,KAAA;QACVC,OAAS,EAAA,KAAA;QACTc,YAAc,EAAA,KAAA;QACdL,OAASC,EAAAA;AACX,KAAA;AACF,CAAA;AAEMK,MAAAA,WAAAA,GAAc,CAACvC,MAA4BwC,EAAAA,MAAAA,GAAAA;AAC/C,IAAA,MAAM9B,SAAYV,GAAAA,MAAAA,CAAOW,IAAI,CAACC,YAAY;IAC1C,MAAM6B,QAAAA,GAAWD,SAAS,CAAC,EAAEA,OAAO,CAAC,EAAE9B,SAAU,CAAA,CAAC,GAAGA,SAAAA;IAErD,OAAOV,MAAAA,CAAOyC,QAAQ,IAAItB,CAAAA,CAAEuB,UAAU,CAACvB,CAAAA,CAAEwB,SAAS,CAACF,QAAAA,CAAAA,CAAAA;AACrD;AAEA,MAAMhC,aAAa,CAACmC,KAAAA,GAAAA;AAClB,IAAA,MAAM5C,SAASmB,CAAEhB,CAAAA,SAAS,CACxBgB,CAAE0B,CAAAA,IAAI,CAACD,KAAO,EAAA;AACZ,QAAA,YAAA;AACA,QAAA,gBAAA;AACA,QAAA,MAAA;AACA,QAAA,SAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAGH5C,IAAAA,MAAAA,CAAOO,IAAI,GAAGqC,KAAMrC,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;;"}
|
|
@@ -3,7 +3,7 @@ import _ from 'lodash';
|
|
|
3
3
|
import { contentTypes, yup } from '@strapi/utils';
|
|
4
4
|
import { validateContentTypeDefinition } from './validator.mjs';
|
|
5
5
|
|
|
6
|
-
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
|
6
|
+
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
|
7
7
|
const createContentType = (uid, definition)=>{
|
|
8
8
|
try {
|
|
9
9
|
validateContentTypeDefinition(definition);
|
|
@@ -29,6 +29,7 @@ const createContentType = (uid, definition)=>{
|
|
|
29
29
|
// In case it is not enabled, value will be always published, and it will not contain a draft
|
|
30
30
|
addDraftAndPublish(schema);
|
|
31
31
|
addCreatorFields(schema);
|
|
32
|
+
addFirstPublishedAt(schema);
|
|
32
33
|
return schema;
|
|
33
34
|
};
|
|
34
35
|
const addTimestamps = (schema)=>{
|
|
@@ -57,6 +58,21 @@ const addDraftAndPublish = (schema)=>{
|
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
};
|
|
61
|
+
const addFirstPublishedAt = (schema)=>{
|
|
62
|
+
const isEnabled = contentTypes.hasFirstPublishedAtField(schema);
|
|
63
|
+
// Note: As an expertimental feature, we are okay if this data is deleted if this feature is
|
|
64
|
+
// switched off. Once "preserve_attributes" come into play, this will be updated.
|
|
65
|
+
if (isEnabled) {
|
|
66
|
+
strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
|
|
67
|
+
schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
|
|
68
|
+
type: 'datetime',
|
|
69
|
+
configurable: false,
|
|
70
|
+
writable: true,
|
|
71
|
+
visible: false,
|
|
72
|
+
private: !isEnabled
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
60
76
|
const addCreatorFields = (schema)=>{
|
|
61
77
|
const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
|
|
62
78
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGl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IAAI,GAAGqC,KAAMrC,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;"}
|
|
@@ -117,7 +117,7 @@ async function loadPlugins(strapi1) {
|
|
|
117
117
|
try {
|
|
118
118
|
serverEntrypointPath = path.join(enabledPlugin.pathToPlugin, resolvedExport);
|
|
119
119
|
} catch (e) {
|
|
120
|
-
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove
|
|
120
|
+
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`);
|
|
121
121
|
}
|
|
122
122
|
// only load plugins with a server entrypoint
|
|
123
123
|
if (!await fse.pathExists(serverEntrypointPath)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA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3ER,YAAAA,MAAAA,EAAQ0D,WAAS9D,CAAAA,aAAAA,CAAcI,MAAM,EAAEuD,aAAavD,MAAM,CAAA;AAC1DG,YAAAA,MAAAA,EAAQoD,YAAapD,CAAAA,MAAM,IAAIP,aAAAA,CAAcO;AAC/C,SAAA;AACF;;AAGA,IAAA,MAAM2B,eAAgBpB,CAAAA,OAAAA,CAAAA;AACtB,IAAA,MAAMD,kBAAmBC,CAAAA,OAAAA,CAAAA;AAEzB,IAAA,KAAK,MAAMW,UAAAA,IAAcC,MAAOC,CAAAA,IAAI,CAACb,OAAU,CAAA,CAAA;QAC7CE,OAAOe,CAAAA,GAAG,CAAC,SAAWgC,CAAAA,CAAAA,GAAG,CAACtC,UAAYX,EAAAA,OAAO,CAACW,UAAW,CAAA,CAAA;AAC3D;AACF;AAEA,MAAMoC,kBAAAA,GAAqB,CACzBpC,UACAb,EAAAA,YAAAA,GAAAA;AAEAc,IAAAA,MAAAA,CAAOsC,MAAM,CAACpD,YAAcqD,CAAAA,CAAAA,OAAO,CAAC,CAACC,UAAAA,GAAAA;QACnC,MAAM,EAAElC,MAAM,EAAE,GAAGkC,UAAAA;QAEnBxC,MAAOyC,CAAAA,MAAM,CAACnC,MAAQ,EAAA;YACpBJ,MAAQH,EAAAA,UAAAA;AACR2C,YAAAA,cAAAA,EACEpC,MAAOoC,CAAAA,cAAc,IAAI,CAAC,EAAE3C,UAAW,CAAA,CAAC,EAAEO,MAAAA,CAAOqC,IAAI,CAACC,YAAY,CAAC,CAAC,CAACC,WAAW,EAAA;AAClFC,YAAAA,QAAAA,EAAUC,kBAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA,EAAS,EAAC;QACVC,SAAa,CAAA,GAAA;AACf,KAAA;AACAC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,YAAAA,EAAc;AAChB,CAAA;AAEA,MAAMC,qBAAqB,OAAOC,OAAAA,GAAAA;AAChC,IAAA,MAAMC,gBAAgBC,MAAOC,CAAAA,IAAI,CAACC,IAAI,CAACC,UAAU;AACjD,IAAA,IAAI,CAAE,MAAMC,GAAIC,CAAAA,UAAU,CAACN,aAAiB,CAAA,EAAA;AAC1C,QAAA;AACF;IAEA,MAAMO,eAAAA,GAAkB,MAAMC,mBAAAA,CAAUR,aAAe,EAAA,iCAAA,CAAA;IACvD,MAAMS,aAAAA,GAAgB,MAAMD,mBAAAA,CAAUR,aAAe,EAAA,qBAAA,CAAA;AAErD,IAAA,KAA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A,OAAO,CAAC,CAACC,UAAAA,GAAAA;QACnC,MAAM,EAAElC,MAAM,EAAE,GAAGkC,UAAAA;QAEnBxC,MAAOyC,CAAAA,MAAM,CAACnC,MAAQ,EAAA;YACpBJ,MAAQH,EAAAA,UAAAA;AACR2C,YAAAA,cAAAA,EACEpC,MAAOoC,CAAAA,cAAc,IAAI,CAAC,EAAE3C,UAAW,CAAA,CAAC,EAAEO,MAAAA,CAAOqC,IAAI,CAACC,YAAY,CAAC,CAAC,CAACC,WAAW,EAAA;AAClFC,YAAAA,QAAAA,EAAUC,kBAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
@@ -96,7 +96,7 @@ async function loadPlugins(strapi1) {
|
|
|
96
96
|
try {
|
|
97
97
|
serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);
|
|
98
98
|
} catch (e) {
|
|
99
|
-
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove
|
|
99
|
+
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`);
|
|
100
100
|
}
|
|
101
101
|
// only load plugins with a server entrypoint
|
|
102
102
|
if (!await fse.pathExists(serverEntrypointPath)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA,EAAS,EAAC;QACVC,SAAa,CAAA,GAAA;AACf,KAAA;AACAC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,YAAAA,EAAc;AAChB,CAAA;AAEA,MAAMC,qBAAqB,OAAOC,OAAAA,GAAAA;AAChC,IAAA,MAAMC,gBAAgBC,MAAOC,CAAAA,IAAI,CAACC,IAAI,CAACC,UAAU;AACjD,IAAA,IAAI,CAAE,MAAMC,GAAIC,CAAAA,UAAU,CAACN,aAAiB,CAAA,EAAA;AAC1C,QAAA;AACF;IAEA,MAAMO,eAAAA,GAAkB,MAAMC,SAAAA,CAAUR,aAAe,EAAA,iCAAA,CAAA;IACvD,MAAMS,aAAAA,GAAgB,MAAMD,SAAAA,CAAUR,aAAe,EAAA,qBAAA,CAAA;AAErD,IAAA,KAAK,MAAMU,UAAAA,IAAcC,MAAOC,CAAAA,IAAI,CAACb,OAAU,CAAA,CAAA;QAC7C,MAAMc,MAAAA,GAASd,OAAO,CAACW,UAAW,CAAA;;AAElC,QAAA,KAAK,MAAMI,MAAUH,IAAAA,MAAAA,CAAOC,IAAI,CAACC,MAAAA,CAAOhB,YAAY,CAAG,CAAA;AACrD,YAAA,MAAMkB,iBAAiBC,GAAI,CAAA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,CAAOqC,IAAI,CAACC,YAAY,CAAC,CAAC,CAACC,WAAW,EAAA;AAClFC,YAAAA,QAAAA,EAAUC,YAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA,EAAS,EAAC;QACVC,SAAa,CAAA,GAAA;AACf,KAAA;AACAC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,YAAAA,EAAc;AAChB,CAAA;AAEA,MAAMC,qBAAqB,OAAOC,OAAAA,GAAAA;AAChC,IAAA,MAAMC,gBAA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C,MAAOC,CAAAA,IAAI,CAACb,OAAU,CAAA,CAAA;QAC7CE,OAAOe,CAAAA,GAAG,CAAC,SAAWgC,CAAAA,CAAAA,GAAG,CAACtC,UAAYX,EAAAA,OAAO,CAACW,UAAW,CAAA,CAAA;AAC3D;AACF;AAEA,MAAMoC,kBAAAA,GAAqB,CACzBpC,UACAb,EAAAA,YAAAA,GAAAA;AAEAc,IAAAA,MAAAA,CAAOsC,MAAM,CAACpD,YAAcqD,CAAAA,CAAAA,OAAO,CAAC,CAACC,UAAAA,GAAAA;QACnC,MAAM,EAAElC,MAAM,EAAE,GAAGkC,UAAAA;QAEnBxC,MAAOyC,CAAAA,MAAM,CAACnC,MAAQ,EAAA;YACpBJ,MAAQH,EAAAA,UAAAA;AACR2C,YAAAA,cAAAA,EACEpC,MAAOoC,CAAAA,cAAc,IAAI,CAAC,EAAE3C,UAAW,CAAA,CAAC,EAAEO,MAAAA,CAAOqC,IAAI,CAACC,YAAY,CAAC,CAAC,CAACC,WAAW,EAAA;AAClFC,YAAAA,QAAAA,EAAUC,YAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/middlewares/security.ts"],"names":[],"mappings":"AACA,OAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/middlewares/security.ts"],"names":[],"mappings":"AACA,OAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAgC3D,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAkEjD,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var fp = require('lodash/fp');
|
|
4
4
|
var helmet = require('koa-helmet');
|
|
5
|
+
var strapiUtils = require('@strapi/utils');
|
|
5
6
|
|
|
6
7
|
const defaults = {
|
|
7
8
|
crossOriginEmbedderPolicy: false,
|
|
@@ -11,21 +12,7 @@ const defaults = {
|
|
|
11
12
|
contentSecurityPolicy: {
|
|
12
13
|
useDefaults: true,
|
|
13
14
|
directives: {
|
|
14
|
-
|
|
15
|
-
"'self'",
|
|
16
|
-
'https:'
|
|
17
|
-
],
|
|
18
|
-
'img-src': [
|
|
19
|
-
"'self'",
|
|
20
|
-
'data:',
|
|
21
|
-
'blob:',
|
|
22
|
-
'https://market-assets.strapi.io'
|
|
23
|
-
],
|
|
24
|
-
'media-src': [
|
|
25
|
-
"'self'",
|
|
26
|
-
'data:',
|
|
27
|
-
'blob:'
|
|
28
|
-
],
|
|
15
|
+
...strapiUtils.CSP_DEFAULTS,
|
|
29
16
|
upgradeInsecureRequests: null
|
|
30
17
|
}
|
|
31
18
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.js","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n
|
|
1
|
+
{"version":3,"file":"security.js","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\nimport { CSP_DEFAULTS } from '@strapi/utils';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n ...CSP_DEFAULTS,\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n ctx.path.startsWith(strapi.config.get('admin.path'))\n ) {\n helmetConfig = mergeConfig(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'http:', 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":["defaults","crossOriginEmbedderPolicy","crossOriginOpenerPolicy","crossOriginResourcePolicy","originAgentCluster","contentSecurityPolicy","useDefaults","directives","CSP_DEFAULTS","upgradeInsecureRequests","xssFilter","hsts","maxAge","includeSubDomains","frameguard","action","mergeConfig","existingConfig","newConfig","mergeWith","obj","src","Array","isArray","concat","undefined","security","config","strapi","ctx","next","helmetConfig","defaultsDeep","specialPaths","plugin","service","playground","isEnabled","gqlConfig","push","method","some","str","path","startsWith","includes","process","env","NODE_ENV","get","helmet"],"mappings":";;;;;;AAQA,MAAMA,QAAmB,GAAA;IACvBC,yBAA2B,EAAA,KAAA;IAC3BC,uBAAyB,EAAA,KAAA;IACzBC,yBAA2B,EAAA,KAAA;IAC3BC,kBAAoB,EAAA,KAAA;IACpBC,qBAAuB,EAAA;QACrBC,WAAa,EAAA,IAAA;QACbC,UAAY,EAAA;AACV,YAAA,GAAGC,wBAAY;YACfC,uBAAyB,EAAA;AAC3B;AACF,KAAA;IACAC,SAAW,EAAA,KAAA;IACXC,IAAM,EAAA;QACJC,MAAQ,EAAA,QAAA;QACRC,iBAAmB,EAAA;AACrB,KAAA;IACAC,UAAY,EAAA;QACVC,MAAQ,EAAA;AACV;A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A,OAAO2C,MAAAA,CAAOnB,cAAcF,GAAKC,EAAAA,IAAAA,CAAAA;;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defaultsDeep, mergeWith } from 'lodash/fp';
|
|
2
2
|
import helmet from 'koa-helmet';
|
|
3
|
+
import { CSP_DEFAULTS } from '@strapi/utils';
|
|
3
4
|
|
|
4
5
|
const defaults = {
|
|
5
6
|
crossOriginEmbedderPolicy: false,
|
|
@@ -9,21 +10,7 @@ const defaults = {
|
|
|
9
10
|
contentSecurityPolicy: {
|
|
10
11
|
useDefaults: true,
|
|
11
12
|
directives: {
|
|
12
|
-
|
|
13
|
-
"'self'",
|
|
14
|
-
'https:'
|
|
15
|
-
],
|
|
16
|
-
'img-src': [
|
|
17
|
-
"'self'",
|
|
18
|
-
'data:',
|
|
19
|
-
'blob:',
|
|
20
|
-
'https://market-assets.strapi.io'
|
|
21
|
-
],
|
|
22
|
-
'media-src': [
|
|
23
|
-
"'self'",
|
|
24
|
-
'data:',
|
|
25
|
-
'blob:'
|
|
26
|
-
],
|
|
13
|
+
...CSP_DEFAULTS,
|
|
27
14
|
upgradeInsecureRequests: null
|
|
28
15
|
}
|
|
29
16
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.mjs","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n
|
|
1
|
+
{"version":3,"file":"security.mjs","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\nimport { CSP_DEFAULTS } from '@strapi/utils';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n ...CSP_DEFAULTS,\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n ctx.path.startsWith(strapi.config.get('admin.path'))\n ) {\n helmetConfig = mergeConfig(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'http:', 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":["defaults","crossOriginEmbedderPolicy","crossOriginOpenerPolicy","crossOriginResourcePolicy","originAgentCluster","contentSecurityPolicy","useDefaults","directives","CSP_DEFAULTS","upgradeInsecureRequests","xssFilter","hsts","maxAge","includeSubDomains","frameguard","action","mergeConfig","existingConfig","newConfig","mergeWith","obj","src","Array","isArray","concat","undefined","security","config","strapi","ctx","next","helmetConfig","defaultsDeep","specialPaths","plugin","service","playground","isEnabled","gqlConfig","push","method","some","str","path","startsWith","includes","process","env","NODE_ENV","get","helmet"],"mappings":";;;;AAQA,MAAMA,QAAmB,GAAA;IACvBC,yBAA2B,EAAA,KAAA;IAC3BC,uBAAyB,EAAA,KAAA;IACzBC,yBAA2B,EAAA,KAAA;IAC3BC,kBAAoB,EAAA,KAAA;IACpBC,qBAAuB,EAAA;QACrBC,WAAa,EAAA,IAAA;QACbC,UAAY,EAAA;AACV,YAAA,GAAGC,YAAY;YACfC,uBAAyB,EAAA;AAC3B;AACF,KAAA;IACAC,SAAW,EAAA,KAAA;IACXC,IAAM,EAAA;QACJC,MAAQ,EAAA,QAAA;QACRC,iBAAmB,EAAA;AACrB,KAAA;IACAC,UA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rD;AACF;AACF,aAAA,CAAA;AACF;QAEA,OAAO2C,MAAAA,CAAOnB,cAAcF,GAAKC,EAAAA,IAAAA,CAAAA;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first-published-at.d.ts","sourceRoot":"","sources":["../../src/migrations/first-published-at.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAUxC,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBA6D7E,CAAC;AAEF,OAAO,EAAE,sBAAsB,IAAI,MAAM,EAAE,CAAC"}
|