@strapi/core 0.0.0-experimental.1e4c115f717b021ca11c139584d4519db28ba786 → 0.0.0-experimental.1f56e9319665c8cc385eb5e4178ceb6741c6d490
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 +23 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +23 -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/index.d.ts.map +1 -1
- package/dist/core-api/routes/index.js +28 -9
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +1 -1
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +243 -90
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -1
- package/dist/core-api/routes/validation/attributes.js +541 -564
- package/dist/core-api/routes/validation/attributes.js.map +1 -1
- package/dist/core-api/routes/validation/attributes.mjs +505 -564
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -1
- package/dist/core-api/routes/validation/common.d.ts +7 -5
- package/dist/core-api/routes/validation/common.d.ts.map +1 -1
- package/dist/core-api/routes/validation/common.js +29 -8
- package/dist/core-api/routes/validation/common.js.map +1 -1
- package/dist/core-api/routes/validation/common.mjs +6 -4
- package/dist/core-api/routes/validation/common.mjs.map +1 -1
- package/dist/core-api/routes/validation/component.d.ts +2 -10
- package/dist/core-api/routes/validation/component.d.ts.map +1 -1
- package/dist/core-api/routes/validation/component.js +3 -17
- package/dist/core-api/routes/validation/component.js.map +1 -1
- package/dist/core-api/routes/validation/component.mjs +3 -17
- package/dist/core-api/routes/validation/component.mjs.map +1 -1
- package/dist/core-api/routes/validation/constants.d.ts +6 -0
- package/dist/core-api/routes/validation/constants.d.ts.map +1 -1
- package/dist/core-api/routes/validation/constants.js +6 -1
- package/dist/core-api/routes/validation/constants.js.map +1 -1
- package/dist/core-api/routes/validation/constants.mjs +6 -1
- package/dist/core-api/routes/validation/constants.mjs.map +1 -1
- package/dist/core-api/routes/validation/content-type.d.ts +28 -71
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +67 -112
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.mjs +36 -100
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
- package/dist/core-api/routes/validation/index.d.ts +1 -1
- package/dist/core-api/routes/validation/index.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.d.ts +105 -0
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.js +273 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +249 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
- package/dist/core-api/routes/validation/utils.d.ts +47 -0
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
- package/dist/core-api/routes/validation/utils.js +128 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +106 -0
- package/dist/core-api/routes/validation/utils.mjs.map +1 -0
- 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/ee/index.d.ts +6 -0
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +29 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +30 -4
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.d.ts +3 -1
- package/dist/ee/license.d.ts.map +1 -1
- package/dist/ee/license.js +6 -1
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +6 -2
- package/dist/ee/license.mjs.map +1 -1
- package/dist/factories.js +1 -1
- package/dist/factories.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +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/cors.d.ts +9 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +39 -17
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +39 -18
- package/dist/middlewares/cors.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 +17 -13
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +17 -13
- 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/core-store.d.ts +2 -2
- package/dist/services/core-store.d.ts.map +1 -1
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/core-store.mjs.map +1 -1
- 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/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +42 -0
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +43 -1
- package/dist/services/document-service/entries.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/internationalization.d.ts +6 -1
- package/dist/services/document-service/internationalization.d.ts.map +1 -1
- package/dist/services/document-service/internationalization.js +32 -0
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs +32 -1
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +16 -8
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +18 -10
- 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/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +9 -0
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +9 -0
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +1 -0
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +3 -0
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +3 -0
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/metrics/index.d.ts +1 -1
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +11 -9
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +11 -9
- 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 +4 -3
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +4 -3
- 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/dist/services/utils/conditional-fields.d.ts +3 -0
- package/dist/services/utils/conditional-fields.d.ts.map +1 -0
- package/dist/services/utils/conditional-fields.js +22 -0
- package/dist/services/utils/conditional-fields.js.map +1 -0
- package/dist/services/utils/conditional-fields.mjs +20 -0
- package/dist/services/utils/conditional-fields.mjs.map +1 -0
- package/dist/utils/fetch.d.ts +5 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +8 -4
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +8 -4
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +197 -0
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/package.json +17 -13
package/dist/ee/index.mjs
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { pick, isEqual } from 'lodash/fp';
|
|
2
|
-
import {
|
|
2
|
+
import { createStrapiFetch } from '../utils/fetch.mjs';
|
|
3
|
+
import { readLicense, verifyLicense, LICENSE_REGISTRY_URI, LicenseCheckError, fetchLicense } from './license.mjs';
|
|
3
4
|
import { shiftCronExpression } from '../utils/cron.mjs';
|
|
4
5
|
|
|
5
6
|
const ONE_MINUTE = 1000 * 60;
|
|
6
7
|
const ee = {
|
|
7
8
|
enabled: false,
|
|
8
|
-
licenseInfo: {
|
|
9
|
+
licenseInfo: {
|
|
10
|
+
isTrial: false
|
|
11
|
+
}
|
|
9
12
|
};
|
|
10
13
|
const disable = (message)=>{
|
|
11
14
|
// Prevent emitting ee.disable if it was already disabled
|
|
12
15
|
const shouldEmitEvent = ee.enabled !== false;
|
|
13
16
|
ee.logger?.warn(`${message} Switching to CE.`);
|
|
14
|
-
// Only keep the license key for potential re-enabling during a later check
|
|
15
|
-
ee.licenseInfo = pick(
|
|
17
|
+
// Only keep the license key and isTrial for potential re-enabling during a later check
|
|
18
|
+
ee.licenseInfo = pick([
|
|
19
|
+
'licenseKey',
|
|
20
|
+
'isTrial'
|
|
21
|
+
], ee.licenseInfo);
|
|
22
|
+
ee.licenseInfo.isTrial = false;
|
|
16
23
|
ee.enabled = false;
|
|
17
24
|
if (shouldEmitEvent) {
|
|
18
25
|
// Notify EE features that they should be disabled
|
|
@@ -161,6 +168,21 @@ const checkLicense = async ({ strapi: strapi1 })=>{
|
|
|
161
168
|
validateInfo();
|
|
162
169
|
}
|
|
163
170
|
};
|
|
171
|
+
const getTrialEndDate = async ({ strapi: strapi1 })=>{
|
|
172
|
+
const silentFetch = createStrapiFetch(strapi1, {
|
|
173
|
+
logs: false
|
|
174
|
+
});
|
|
175
|
+
const res = await silentFetch(`${LICENSE_REGISTRY_URI}/api/licenses/${ee.licenseInfo.licenseKey}/trial-countdown`, {
|
|
176
|
+
method: 'GET',
|
|
177
|
+
headers: {
|
|
178
|
+
'Content-Type': 'application/json'
|
|
179
|
+
}
|
|
180
|
+
}).catch(()=>{
|
|
181
|
+
throw new LicenseCheckError('Could not proceed to retrieve the trial time left for your license.', true);
|
|
182
|
+
});
|
|
183
|
+
const data = await res.json();
|
|
184
|
+
return data;
|
|
185
|
+
};
|
|
164
186
|
const list = ()=>{
|
|
165
187
|
return ee.licenseInfo.features?.map((feature)=>typeof feature === 'object' ? feature : {
|
|
166
188
|
name: feature
|
|
@@ -170,6 +192,7 @@ const get = (featureName)=>list().find((feature)=>feature.name === featureName);
|
|
|
170
192
|
var index = Object.freeze({
|
|
171
193
|
init,
|
|
172
194
|
checkLicense,
|
|
195
|
+
getTrialEndDate,
|
|
173
196
|
get isEE () {
|
|
174
197
|
return ee.enabled;
|
|
175
198
|
},
|
|
@@ -179,6 +202,9 @@ var index = Object.freeze({
|
|
|
179
202
|
get type () {
|
|
180
203
|
return ee.licenseInfo.type;
|
|
181
204
|
},
|
|
205
|
+
get isTrial () {
|
|
206
|
+
return ee.licenseInfo.isTrial;
|
|
207
|
+
},
|
|
182
208
|
features: Object.freeze({
|
|
183
209
|
list,
|
|
184
210
|
get,
|
package/dist/ee/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/ee/index.ts"],"sourcesContent":["import { pick, isEqual } from 'lodash/fp';\nimport type { Logger } from '@strapi/logger';\nimport type { Core } from '@strapi/types';\n\nimport { readLicense, verifyLicense, fetchLicense, LicenseCheckError } from './license';\nimport { shiftCronExpression } from '../utils/cron';\n\nconst ONE_MINUTE = 1000 * 60;\n\ninterface EE {\n enabled: boolean;\n licenseInfo: {\n licenseKey?: string;\n features?: Array<{ name: string; [key: string]: any } | string>;\n expireAt?: string;\n seats?: number;\n type?: string;\n };\n logger?: Logger;\n}\n\nconst ee: EE = {\n enabled: false,\n licenseInfo: {},\n};\n\nconst disable = (message: string) => {\n // Prevent emitting ee.disable if it was already disabled\n const shouldEmitEvent = ee.enabled !== false;\n\n ee.logger?.warn(`${message} Switching to CE.`);\n // Only keep the license key for potential re-enabling during a later check\n ee.licenseInfo = pick('licenseKey', ee.licenseInfo);\n\n ee.enabled = false;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.disable');\n }\n};\n\nconst enable = () => {\n // Prevent emitting ee.enable if it was already enabled\n const shouldEmitEvent = ee.enabled !== true;\n\n ee.enabled = true;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.enable');\n }\n};\n\nlet initialized = false;\n\n/**\n * Optimistically enable EE if the format of the license is valid, only run once.\n */\nconst init = (licenseDir: string, logger?: Logger) => {\n if (initialized) {\n return;\n }\n\n initialized = true;\n ee.logger = logger;\n\n if (process.env.STRAPI_DISABLE_EE?.toLowerCase() === 'true') {\n return;\n }\n\n try {\n const license = process.env.STRAPI_LICENSE || readLicense(licenseDir);\n\n if (license) {\n ee.licenseInfo = verifyLicense(license);\n enable();\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n};\n\n/**\n * Contact the license registry to update the license to its latest state.\n *\n * Store the result in database to avoid unecessary requests, and will fallback to that in case of a network failure.\n */\nconst onlineUpdate = async ({ strapi }: { strapi: Core.Strapi }) => {\n const { get, commit, rollback } = (await strapi.db?.transaction()) as any;\n const transaction = get();\n\n try {\n const storedInfo = await strapi.db\n ?.queryBuilder('strapi::core-store')\n .where({ key: 'ee_information' })\n .select('value')\n .first()\n .transacting(transaction)\n .forUpdate()\n .execute()\n .then((result: any) => (result ? JSON.parse(result.value) : result));\n\n const shouldContactRegistry = (storedInfo?.lastCheckAt ?? 0) < Date.now() - ONE_MINUTE;\n const result: {\n license?: string | null;\n error?: string;\n lastCheckAt?: number;\n } = { lastCheckAt: Date.now() };\n\n const fallback = (error: Error) => {\n if (error instanceof LicenseCheckError && error.shouldFallback && storedInfo?.license) {\n ee.logger?.warn(\n `${error.message} The last stored one will be used as a potential fallback.`\n );\n return storedInfo.license;\n }\n\n result.error = error.message;\n disable(error.message);\n };\n\n if (!ee?.licenseInfo?.licenseKey) {\n throw new Error('Missing license key.');\n }\n\n const license = shouldContactRegistry\n ? await fetchLicense({ strapi }, ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(\n fallback\n )\n : storedInfo.license;\n\n if (license) {\n try {\n // Verify license and check if its info changed\n const newLicenseInfo = verifyLicense(license);\n const licenseInfoChanged =\n !isEqual(newLicenseInfo.features, ee.licenseInfo.features) ||\n newLicenseInfo.seats !== ee.licenseInfo.seats ||\n newLicenseInfo.type !== ee.licenseInfo.type;\n\n // Store the new license info\n ee.licenseInfo = newLicenseInfo;\n const wasEnabled = ee.enabled;\n validateInfo();\n\n // Notify EE features\n if (licenseInfoChanged && wasEnabled) {\n strapi.eventHub.emit('ee.update');\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n } else if (!shouldContactRegistry) {\n disable(storedInfo.error);\n }\n\n if (shouldContactRegistry) {\n result.license = license ?? null;\n const query = strapi.db.queryBuilder('strapi::core-store').transacting(transaction);\n\n if (!storedInfo) {\n query.insert({ key: 'ee_information', value: JSON.stringify(result) });\n } else {\n query.update({ value: JSON.stringify(result) }).where({ key: 'ee_information' });\n }\n\n await query.execute();\n }\n\n await commit();\n } catch (error) {\n // Example of errors: SQLite does not support FOR UPDATE\n await rollback();\n }\n};\n\nconst validateInfo = () => {\n if (typeof ee.licenseInfo.expireAt === 'undefined') {\n throw new Error('Missing license key.');\n }\n\n const expirationTime = new Date(ee.licenseInfo.expireAt).getTime();\n\n if (expirationTime < new Date().getTime()) {\n return disable('License expired.');\n }\n\n enable();\n};\n\nconst checkLicense = async ({ strapi }: { strapi: Core.Strapi }) => {\n const shouldStayOffline =\n ee.licenseInfo.type === 'gold' &&\n // This env variable support is temporarily used to ease the migration between online vs offline\n process.env.STRAPI_DISABLE_LICENSE_PING?.toLowerCase() === 'true';\n\n if (!shouldStayOffline) {\n await onlineUpdate({ strapi });\n\n strapi.cron.add({\n onlineUpdate: {\n task: () => onlineUpdate({ strapi }),\n options: shiftCronExpression('0 0 */12 * * *'),\n },\n });\n } else {\n if (!ee.licenseInfo.expireAt) {\n return disable('Your license does not have offline support.');\n }\n\n validateInfo();\n }\n};\n\nconst list = () => {\n return (\n ee.licenseInfo.features?.map((feature) =>\n typeof feature === 'object' ? feature : { name: feature }\n ) || []\n );\n};\n\nconst get = (featureName: string) => list().find((feature) => feature.name === featureName);\n\nexport default Object.freeze({\n init,\n checkLicense,\n\n get isEE() {\n return ee.enabled;\n },\n\n get seats() {\n return ee.licenseInfo.seats;\n },\n\n get type() {\n return ee.licenseInfo.type;\n },\n\n features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["ONE_MINUTE","ee","enabled","licenseInfo","disable","message","shouldEmitEvent","logger","warn","pick","strapi","eventHub","emit","enable","initialized","init","licenseDir","process","env","STRAPI_DISABLE_EE","toLowerCase","license","STRAPI_LICENSE","readLicense","verifyLicense","error","Error","onlineUpdate","get","commit","rollback","db","transaction","storedInfo","queryBuilder","where","key","select","first","transacting","forUpdate","execute","then","result","JSON","parse","value","shouldContactRegistry","lastCheckAt","Date","now","fallback","LicenseCheckError","shouldFallback","licenseKey","fetchLicense","config","catch","newLicenseInfo","licenseInfoChanged","isEqual","features","seats","type","wasEnabled","validateInfo","query","insert","stringify","update","expireAt","expirationTime","getTime","checkLicense","shouldStayOffline","STRAPI_DISABLE_LICENSE_PING","cron","add","task","options","shiftCronExpression","list","map","feature","name","featureName","find","Object","freeze","isEE","isEnabled","undefined"],"mappings":";;;;AAOA,MAAMA,aAAa,IAAO,GAAA,EAAA;AAc1B,MAAMC,EAAS,GAAA;IACbC,OAAS,EAAA,KAAA;AACTC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEA,MAAMC,UAAU,CAACC,OAAAA,GAAAA;;IAEf,MAAMC,eAAAA,GAAkBL,EAAGC,CAAAA,OAAO,KAAK,KAAA;AAEvCD,IAAAA,EAAAA,CAAGM,MAAM,EAAEC,IAAAA,CAAK,CAAC,EAAEH,OAAAA,CAAQ,iBAAiB,CAAC,CAAA;;AAE7CJ,IAAAA,EAAAA,CAAGE,WAAW,GAAGM,IAAK,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AA,YAAAA;AAEA,IAAA,IAAIgB,IAAO,CAAA,GAAA;AACT,QAAA,OAAOxF,GAAGC,OAAO;AACnB,KAAA;AAEA,IAAA,IAAI4D,KAAQ,CAAA,GAAA;QACV,OAAO7D,EAAAA,CAAGE,WAAW,CAAC2D,KAAK;AAC7B,KAAA;AAEA,IAAA,IAAIC,IAAO,CAAA,GAAA;QACT,OAAO9D,EAAAA,CAAGE,WAAW,CAAC4D,IAAI;AAC5B,KAAA;IAEAF,QAAU0B,EAAAA,MAAAA,CAAOC,MAAM,CAAC;AACtBP,QAAAA,IAAAA;AACArD,QAAAA,GAAAA;QACA8D,SAAW,EAAA,CAACL,WAAwBzD,GAAAA,GAAAA,CAAIyD,WAAiBM,CAAAA,KAAAA;AAC3D,KAAA;AACF,CAAG,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/ee/index.ts"],"sourcesContent":["import { pick, isEqual } from 'lodash/fp';\nimport type { Logger } from '@strapi/logger';\nimport type { Core } from '@strapi/types';\nimport { createStrapiFetch } from '../utils/fetch';\nimport {\n readLicense,\n verifyLicense,\n fetchLicense,\n LicenseCheckError,\n LICENSE_REGISTRY_URI,\n} from './license';\nimport { shiftCronExpression } from '../utils/cron';\n\nconst ONE_MINUTE = 1000 * 60;\n\ninterface EE {\n enabled: boolean;\n licenseInfo: {\n licenseKey?: string;\n features?: Array<{ name: string; [key: string]: any } | string>;\n expireAt?: string;\n seats?: number;\n type?: string;\n isTrial: boolean;\n };\n logger?: Logger;\n}\n\nconst ee: EE = {\n enabled: false,\n licenseInfo: {\n isTrial: false,\n },\n};\n\nconst disable = (message: string) => {\n // Prevent emitting ee.disable if it was already disabled\n const shouldEmitEvent = ee.enabled !== false;\n\n ee.logger?.warn(`${message} Switching to CE.`);\n // Only keep the license key and isTrial for potential re-enabling during a later check\n ee.licenseInfo = pick(['licenseKey', 'isTrial'], ee.licenseInfo);\n\n ee.licenseInfo.isTrial = false;\n\n ee.enabled = false;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.disable');\n }\n};\n\nconst enable = () => {\n // Prevent emitting ee.enable if it was already enabled\n const shouldEmitEvent = ee.enabled !== true;\n\n ee.enabled = true;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.enable');\n }\n};\n\nlet initialized = false;\n\n/**\n * Optimistically enable EE if the format of the license is valid, only run once.\n */\nconst init = (licenseDir: string, logger?: Logger) => {\n if (initialized) {\n return;\n }\n\n initialized = true;\n ee.logger = logger;\n\n if (process.env.STRAPI_DISABLE_EE?.toLowerCase() === 'true') {\n return;\n }\n\n try {\n const license = process.env.STRAPI_LICENSE || readLicense(licenseDir);\n\n if (license) {\n ee.licenseInfo = verifyLicense(license);\n enable();\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n};\n\n/**\n * Contact the license registry to update the license to its latest state.\n *\n * Store the result in database to avoid unecessary requests, and will fallback to that in case of a network failure.\n */\nconst onlineUpdate = async ({ strapi }: { strapi: Core.Strapi }) => {\n const { get, commit, rollback } = (await strapi.db?.transaction()) as any;\n const transaction = get();\n\n try {\n const storedInfo = await strapi.db\n ?.queryBuilder('strapi::core-store')\n .where({ key: 'ee_information' })\n .select('value')\n .first()\n .transacting(transaction)\n .forUpdate()\n .execute()\n .then((result: any) => (result ? JSON.parse(result.value) : result));\n\n const shouldContactRegistry = (storedInfo?.lastCheckAt ?? 0) < Date.now() - ONE_MINUTE;\n const result: {\n license?: string | null;\n error?: string;\n lastCheckAt?: number;\n } = { lastCheckAt: Date.now() };\n\n const fallback = (error: Error) => {\n if (error instanceof LicenseCheckError && error.shouldFallback && storedInfo?.license) {\n ee.logger?.warn(\n `${error.message} The last stored one will be used as a potential fallback.`\n );\n return storedInfo.license;\n }\n\n result.error = error.message;\n disable(error.message);\n };\n\n if (!ee?.licenseInfo?.licenseKey) {\n throw new Error('Missing license key.');\n }\n\n const license = shouldContactRegistry\n ? await fetchLicense({ strapi }, ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(\n fallback\n )\n : storedInfo.license;\n\n if (license) {\n try {\n // Verify license and check if its info changed\n const newLicenseInfo = verifyLicense(license);\n const licenseInfoChanged =\n !isEqual(newLicenseInfo.features, ee.licenseInfo.features) ||\n newLicenseInfo.seats !== ee.licenseInfo.seats ||\n newLicenseInfo.type !== ee.licenseInfo.type;\n\n // Store the new license info\n ee.licenseInfo = newLicenseInfo;\n const wasEnabled = ee.enabled;\n validateInfo();\n\n // Notify EE features\n if (licenseInfoChanged && wasEnabled) {\n strapi.eventHub.emit('ee.update');\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n } else if (!shouldContactRegistry) {\n disable(storedInfo.error);\n }\n\n if (shouldContactRegistry) {\n result.license = license ?? null;\n const query = strapi.db.queryBuilder('strapi::core-store').transacting(transaction);\n\n if (!storedInfo) {\n query.insert({ key: 'ee_information', value: JSON.stringify(result) });\n } else {\n query.update({ value: JSON.stringify(result) }).where({ key: 'ee_information' });\n }\n\n await query.execute();\n }\n\n await commit();\n } catch (error) {\n // Example of errors: SQLite does not support FOR UPDATE\n await rollback();\n }\n};\n\nconst validateInfo = () => {\n if (typeof ee.licenseInfo.expireAt === 'undefined') {\n throw new Error('Missing license key.');\n }\n\n const expirationTime = new Date(ee.licenseInfo.expireAt).getTime();\n\n if (expirationTime < new Date().getTime()) {\n return disable('License expired.');\n }\n\n enable();\n};\n\nconst checkLicense = async ({ strapi }: { strapi: Core.Strapi }) => {\n const shouldStayOffline =\n ee.licenseInfo.type === 'gold' &&\n // This env variable support is temporarily used to ease the migration between online vs offline\n process.env.STRAPI_DISABLE_LICENSE_PING?.toLowerCase() === 'true';\n\n if (!shouldStayOffline) {\n await onlineUpdate({ strapi });\n\n strapi.cron.add({\n onlineUpdate: {\n task: () => onlineUpdate({ strapi }),\n options: shiftCronExpression('0 0 */12 * * *'),\n },\n });\n } else {\n if (!ee.licenseInfo.expireAt) {\n return disable('Your license does not have offline support.');\n }\n\n validateInfo();\n }\n};\n\nconst getTrialEndDate = async ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): Promise<{ trialEndsAt: string } | null> => {\n const silentFetch = createStrapiFetch(strapi, {\n logs: false,\n });\n\n const res = await silentFetch(\n `${LICENSE_REGISTRY_URI}/api/licenses/${ee.licenseInfo.licenseKey}/trial-countdown`,\n {\n method: 'GET',\n headers: { 'Content-Type': 'application/json' },\n }\n ).catch(() => {\n throw new LicenseCheckError(\n 'Could not proceed to retrieve the trial time left for your license.',\n true\n );\n });\n\n const data = await res.json();\n\n return data;\n};\n\nconst list = () => {\n return (\n ee.licenseInfo.features?.map((feature) =>\n typeof feature === 'object' ? feature : { name: feature }\n ) || []\n );\n};\n\nconst get = (featureName: string) => list().find((feature) => feature.name === featureName);\n\nexport default Object.freeze({\n init,\n checkLicense,\n getTrialEndDate,\n\n get isEE() {\n return ee.enabled;\n },\n\n get seats() {\n return ee.licenseInfo.seats;\n },\n\n get type() {\n return ee.licenseInfo.type;\n },\n\n get isTrial() {\n return ee.licenseInfo.isTrial;\n },\n\n features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["ONE_MINUTE","ee","enabled","licenseInfo","isTrial","disable","message","shouldEmitEvent","logger","warn","pick","strapi","eventHub","emit","enable","initialized","init","licenseDir","process","env","STRAPI_DISABLE_EE","toLowerCase","license","STRAPI_LICENSE","readLicense","verifyLicense","error","Error","onlineUpdate","get","commit","rollback","db","transaction","storedInfo","queryBuilder","where","key","select","first","transacting","forUpdate","execute","then","result","JSON","parse","value","shouldContactRegistry","lastCheckAt","Date","now","fallback","LicenseCheckError","shouldFallback","licenseKey","fetchLicense","config","catch","newLicenseInfo","licenseInfoChanged","isEqual","features","seats","type","wasEnabled","validateInfo","query","insert","stringify","update","expireAt","expirationTime","getTime","checkLicense","shouldStayOffline","STRAPI_DISABLE_LICENSE_PING","cron","add","task","options","shiftCronExpression","getTrialEndDate","silentFetch","createStrapiFetch","logs","res","LICENSE_REGISTRY_URI","method","headers","data","json","list","map","feature","name","featureName","find","Object","freeze","isEE","isEnabled","undefined"],"mappings":";;;;;AAaA,MAAMA,aAAa,IAAO,GAAA,EAAA;AAe1B,MAAMC,EAAS,GAAA;IACbC,OAAS,EAAA,KAAA;IACTC,WAAa,EAAA;QACXC,OAAS,EAAA;AACX;AACF,CAAA;AAEA,MAAMC,UAAU,CAACC,OAAAA,GAAAA;;IAEf,MAAMC,eAAAA,GAAkBN,EAAGC,CAAAA,OAAO,KAAK,KAAA;AAEvCD,IAAAA,EAAAA,CAAGO,MAAM,EAAEC,IAAAA,CAAK,CAAC,EAAEH,OAAAA,CAAQ,iBAAiB,CAAC,CAAA;;IAE7CL,EAAGE,CAAAA,WAAW,GAAGO,IAAK,CAAA;AAAC,QAAA,YAAA;AAAc,QAAA;AAAU,KAAA,EAAET,GAAGE,WAAW,CAAA;IAE/DF,EAAGE,CAAAA,WAAW,CAACC,OAAO,GAAG,KAAA;AAEzBH,IAAAA,EAAAA,CAAGC,OAAO,GAAG,KAAA;AAEb,IAAA,IAAIK,eAAiB,EAAA;;QAEnBI,MAAOC,CAAAA,QAAQ,CAACC,IAAI,CAAC,YAAA,CAAA;AACvB;AACF,CAAA;AAEA,MAAMC,MAAS,GAAA,IAAA;;IAEb,MAAMP,eAAAA,GAAkBN,EAAGC,CAAAA,OAAO,KAAK,IAAA;AAEvCD,IAAAA,EAAAA,CAAGC,OAAO,GAAG,IAAA;AAEb,IAAA,IAAIK,eAAiB,EAAA;;QAEnBI,MAAOC,CAAAA,QAAQ,CAACC,IAAI,CAAC,WAAA,CAAA;AACvB;AACF,CAAA;AAEA,IAAIE,WAAc,GAAA,KAAA;AAElB;;IAGA,MAAMC,IAAO,GAAA,CAACC,UAAoBT,EAAAA,MAAAA,GAAAA;AAChC,IAAA,IAAIO,WAAa,EAAA;AACf,Q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A0D,IAAAA,YAAAA;AACAQ,IAAAA,eAAAA;AAEA,IAAA,IAAIkB,IAAO,CAAA,GAAA;AACT,QAAA,OAAOnG,GAAGC,OAAO;AACnB,KAAA;AAEA,IAAA,IAAI6D,KAAQ,CAAA,GAAA;QACV,OAAO9D,EAAAA,CAAGE,WAAW,CAAC4D,KAAK;AAC7B,KAAA;AAEA,IAAA,IAAIC,IAAO,CAAA,GAAA;QACT,OAAO/D,EAAAA,CAAGE,WAAW,CAAC6D,IAAI;AAC5B,KAAA;AAEA,IAAA,IAAI5D,OAAU,CAAA,GAAA;QACZ,OAAOH,EAAAA,CAAGE,WAAW,CAACC,OAAO;AAC/B,KAAA;IAEA0D,QAAUoC,EAAAA,MAAAA,CAAOC,MAAM,CAAC;AACtBP,QAAAA,IAAAA;AACA/D,QAAAA,GAAAA;QACAwE,SAAW,EAAA,CAACL,WAAwBnE,GAAAA,GAAAA,CAAImE,WAAiBM,CAAAA,KAAAA;AAC3D,KAAA;AACF,CAAG,CAAA;;;;"}
|
package/dist/ee/license.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Core } from '@strapi/types';
|
|
2
2
|
interface LicenseInfo {
|
|
3
3
|
type: 'bronze' | 'silver' | 'gold';
|
|
4
|
+
isTrial: boolean;
|
|
4
5
|
expireAt?: string;
|
|
5
6
|
seats?: number;
|
|
6
7
|
features?: Array<{
|
|
@@ -8,6 +9,7 @@ interface LicenseInfo {
|
|
|
8
9
|
options?: Record<string, unknown>;
|
|
9
10
|
}>;
|
|
10
11
|
}
|
|
12
|
+
declare const LICENSE_REGISTRY_URI = "https://license.strapi.io";
|
|
11
13
|
declare class LicenseCheckError extends Error {
|
|
12
14
|
shouldFallback: boolean;
|
|
13
15
|
constructor(message: string, shouldFallback?: boolean);
|
|
@@ -17,5 +19,5 @@ declare const verifyLicense: (license: string) => LicenseInfo;
|
|
|
17
19
|
declare const fetchLicense: ({ strapi }: {
|
|
18
20
|
strapi: Core.Strapi;
|
|
19
21
|
}, key: string, projectId: string) => Promise<any>;
|
|
20
|
-
export { readLicense, verifyLicense, fetchLicense, LicenseCheckError };
|
|
22
|
+
export { readLicense, verifyLicense, fetchLicense, LicenseCheckError, LICENSE_REGISTRY_URI };
|
|
21
23
|
//# sourceMappingURL=license.d.ts.map
|
package/dist/ee/license.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../../src/ee/license.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAI1C,UAAU,WAAW;IACnB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CACvE;
|
|
1
|
+
{"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../../src/ee/license.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAI1C,UAAU,WAAW;IACnB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CACvE;AAiBD,QAAA,MAAM,oBAAoB,8BAA8B,CAAC;AAIzD,cAAM,iBAAkB,SAAQ,KAAK;IACnC,cAAc,UAAS;gBAEX,OAAO,EAAE,MAAM,EAAE,cAAc,UAAQ;CAKpD;AAED,QAAA,MAAM,WAAW,cAAe,MAAM,uBASrC,CAAC;AAEF,QAAA,MAAM,aAAa,YAAa,MAAM,gBA+BrC,CAAC;AAMF,QAAA,MAAM,YAAY,eACJ;IAAE,MAAM,EAAE,KAAK,MAAM,CAAA;CAAE,OAC9B,MAAM,aACA,MAAM,iBAkClB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/ee/license.js
CHANGED
|
@@ -37,6 +37,7 @@ const DEFAULT_FEATURES = {
|
|
|
37
37
|
}
|
|
38
38
|
]
|
|
39
39
|
};
|
|
40
|
+
const LICENSE_REGISTRY_URI = 'https://license.strapi.io';
|
|
40
41
|
const publicKey = fs.readFileSync(path.resolve(__dirname, '../../resources/key.pub'));
|
|
41
42
|
class LicenseCheckError extends Error {
|
|
42
43
|
constructor(message, shouldFallback = false){
|
|
@@ -72,6 +73,9 @@ const verifyLicense = (license)=>{
|
|
|
72
73
|
if (!licenseInfo.features) {
|
|
73
74
|
licenseInfo.features = DEFAULT_FEATURES[licenseInfo.type];
|
|
74
75
|
}
|
|
76
|
+
if (!licenseInfo.isTrial) {
|
|
77
|
+
licenseInfo.isTrial = false;
|
|
78
|
+
}
|
|
75
79
|
Object.freeze(licenseInfo.features);
|
|
76
80
|
return licenseInfo;
|
|
77
81
|
};
|
|
@@ -80,7 +84,7 @@ const throwError = ()=>{
|
|
|
80
84
|
};
|
|
81
85
|
const fetchLicense = async ({ strapi }, key, projectId)=>{
|
|
82
86
|
const { installId: installIdFromPackageJson } = strapi.config;
|
|
83
|
-
const response = await strapi.fetch(
|
|
87
|
+
const response = await strapi.fetch(`${LICENSE_REGISTRY_URI}/api/licenses/validate`, {
|
|
84
88
|
method: 'POST',
|
|
85
89
|
headers: {
|
|
86
90
|
'Content-Type': 'application/json'
|
|
@@ -109,6 +113,7 @@ const fetchLicense = async ({ strapi }, key, projectId)=>{
|
|
|
109
113
|
}
|
|
110
114
|
};
|
|
111
115
|
|
|
116
|
+
exports.LICENSE_REGISTRY_URI = LICENSE_REGISTRY_URI;
|
|
112
117
|
exports.LicenseCheckError = LicenseCheckError;
|
|
113
118
|
exports.fetchLicense = fetchLicense;
|
|
114
119
|
exports.readLicense = readLicense;
|
package/dist/ee/license.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"license.js","sources":["../../src/ee/license.ts"],"sourcesContent":["import fs from 'fs';\nimport { join, resolve } from 'path';\nimport crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\nimport { generateInstallId } from '@strapi/utils';\n\ninterface LicenseInfo {\n type: 'bronze' | 'silver' | 'gold';\n expireAt?: string;\n seats?: number;\n features?: Array<{ name: string; options?: Record<string, unknown> }>;\n}\n\nconst DEFAULT_FEATURES = {\n bronze: [],\n silver: [],\n gold: [\n { name: 'sso' },\n // Set a null retention duration to allow the user to override it\n // The default of 90 days is set in the audit logs service\n { name: 'audit-logs', options: { retentionDays: null } },\n { name: 'review-workflows' },\n { name: 'cms-content-releases' },\n { name: 'cms-content-history', options: { retentionDays: 99999 } },\n { name: 'cms-advanced-preview' },\n ],\n};\n\nconst publicKey = fs.readFileSync(resolve(__dirname, '../../resources/key.pub'));\n\nclass LicenseCheckError extends Error {\n shouldFallback = false;\n\n constructor(message: string, shouldFallback = false) {\n super(message);\n\n this.shouldFallback = shouldFallback;\n }\n}\n\nconst readLicense = (directory: string) => {\n try {\n const path = join(directory, 'license.txt');\n return fs.readFileSync(path).toString();\n } catch (error) {\n if (typeof error === 'object' && error !== null && 'code' in error && error.code !== 'ENOENT') {\n throw Error('License file not readable, review its format and access rules.');\n }\n }\n};\n\nconst verifyLicense = (license: string) => {\n const [signature, base64Content] = Buffer.from(license, 'base64').toString().split('\\n');\n\n if (!signature || !base64Content) {\n throw new Error('Invalid license.');\n }\n\n const stringifiedContent = Buffer.from(base64Content, 'base64').toString();\n\n const verify = crypto.createVerify('RSA-SHA256');\n verify.update(stringifiedContent);\n verify.end();\n\n const verified = verify.verify(publicKey, signature, 'base64');\n\n if (!verified) {\n throw new Error('Invalid license.');\n }\n\n const licenseInfo: LicenseInfo = JSON.parse(stringifiedContent);\n\n if (!licenseInfo.features) {\n licenseInfo.features = DEFAULT_FEATURES[licenseInfo.type];\n }\n\n Object.freeze(licenseInfo.features);\n return licenseInfo;\n};\n\nconst throwError = () => {\n throw new LicenseCheckError('Could not proceed to the online validation of your license.', true);\n};\n\nconst fetchLicense = async (\n { strapi }: { strapi: Core.Strapi },\n key: string,\n projectId: string\n) => {\n const { installId: installIdFromPackageJson } = strapi.config;\n\n const response = await strapi\n .fetch(
|
|
1
|
+
{"version":3,"file":"license.js","sources":["../../src/ee/license.ts"],"sourcesContent":["import fs from 'fs';\nimport { join, resolve } from 'path';\nimport crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\nimport { generateInstallId } from '@strapi/utils';\n\ninterface LicenseInfo {\n type: 'bronze' | 'silver' | 'gold';\n isTrial: boolean;\n expireAt?: string;\n seats?: number;\n features?: Array<{ name: string; options?: Record<string, unknown> }>;\n}\n\nconst DEFAULT_FEATURES = {\n bronze: [],\n silver: [],\n gold: [\n { name: 'sso' },\n // Set a null retention duration to allow the user to override it\n // The default of 90 days is set in the audit logs service\n { name: 'audit-logs', options: { retentionDays: null } },\n { name: 'review-workflows' },\n { name: 'cms-content-releases' },\n { name: 'cms-content-history', options: { retentionDays: 99999 } },\n { name: 'cms-advanced-preview' },\n ],\n};\n\nconst LICENSE_REGISTRY_URI = 'https://license.strapi.io';\n\nconst publicKey = fs.readFileSync(resolve(__dirname, '../../resources/key.pub'));\n\nclass LicenseCheckError extends Error {\n shouldFallback = false;\n\n constructor(message: string, shouldFallback = false) {\n super(message);\n\n this.shouldFallback = shouldFallback;\n }\n}\n\nconst readLicense = (directory: string) => {\n try {\n const path = join(directory, 'license.txt');\n return fs.readFileSync(path).toString();\n } catch (error) {\n if (typeof error === 'object' && error !== null && 'code' in error && error.code !== 'ENOENT') {\n throw Error('License file not readable, review its format and access rules.');\n }\n }\n};\n\nconst verifyLicense = (license: string) => {\n const [signature, base64Content] = Buffer.from(license, 'base64').toString().split('\\n');\n\n if (!signature || !base64Content) {\n throw new Error('Invalid license.');\n }\n\n const stringifiedContent = Buffer.from(base64Content, 'base64').toString();\n\n const verify = crypto.createVerify('RSA-SHA256');\n verify.update(stringifiedContent);\n verify.end();\n\n const verified = verify.verify(publicKey, signature, 'base64');\n\n if (!verified) {\n throw new Error('Invalid license.');\n }\n\n const licenseInfo: LicenseInfo = JSON.parse(stringifiedContent);\n\n if (!licenseInfo.features) {\n licenseInfo.features = DEFAULT_FEATURES[licenseInfo.type];\n }\n\n if (!licenseInfo.isTrial) {\n licenseInfo.isTrial = false;\n }\n\n Object.freeze(licenseInfo.features);\n return licenseInfo;\n};\n\nconst throwError = () => {\n throw new LicenseCheckError('Could not proceed to the online validation of your license.', true);\n};\n\nconst fetchLicense = async (\n { strapi }: { strapi: Core.Strapi },\n key: string,\n projectId: string\n) => {\n const { installId: installIdFromPackageJson } = strapi.config;\n\n const response = await strapi\n .fetch(`${LICENSE_REGISTRY_URI}/api/licenses/validate`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n key,\n projectId,\n deviceId: generateInstallId(projectId, installIdFromPackageJson),\n }), // NOTE: Doing nothing on the LR with the installId\n })\n .catch(throwError);\n\n const contentType = response.headers.get('Content-Type');\n\n if (contentType?.includes('application/json')) {\n const { data, error } = await response.json();\n\n switch (response.status) {\n case 200:\n return data.license;\n case 400:\n throw new LicenseCheckError(error.message);\n case 404:\n throw new LicenseCheckError('The license used does not exists.');\n default:\n throwError();\n }\n } else {\n throwError();\n }\n};\n\nexport { readLicense, verifyLicense, fetchLicense, LicenseCheckError, LICENSE_REGISTRY_URI };\n"],"names":["DEFAULT_FEATURES","bronze","silver","gold","name","options","retentionDays","LICENSE_REGISTRY_URI","publicKey","fs","readFileSync","resolve","__dirname","LicenseCheckError","Error","constructor","message","shouldFallback","readLicense","directory","path","join","toString","error","code","verifyLicense","license","signature","base64Content","Buffer","from","split","stringifiedContent","verify","crypto","createVerify","update","end","verified","licenseInfo","JSON","parse","features","type","isTrial","Object","freeze","throwError","fetchLicense","strapi","key","projectId","installId","installIdFromPackageJson","config","response","fetch","method","headers","body","stringify","deviceId","generateInstallId","catch","contentType","get","includes","data","json","status"],"mappings":";;;;;;;AAeA,MAAMA,gBAAmB,GAAA;AACvBC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,MAAAA,EAAQ,EAAE;IACVC,IAAM,EAAA;AACJ,QAAA;YAAEC,IAAM,EAAA;AAAM,SAAA;;;AAGd,QAAA;YAAEA,IAAM,EAAA,YAAA;YAAcC,OAAS,EAAA;gBAAEC,aAAe,EAAA;AAAK;AAAE,SAAA;AACvD,QAAA;YAAEF,IAAM,EAAA;AAAmB,SAAA;AAC3B,QAAA;YAAEA,IAAM,EAAA;AAAuB,SAAA;AAC/B,QAAA;YAAEA,IAAM,EAAA,qBAAA;YAAuBC,OAAS,EAAA;gBAAEC,aAAe,EAAA;AAAM;AAAE,SAAA;AACjE,QAAA;YAAEF,IAAM,EAAA;AAAuB;AAChC;AACH,CAAA;AAEA,MAAMG,oBAAuB,GAAA;AAE7B,MAAMC,SAAYC,GAAAA,EAAAA,CAAGC,YAAY,CAACC,aAAQC,SAAW,EAAA,yBAAA,CAAA,CAAA;AAErD,MAAMC,iBAA0BC,SAAAA,KAAAA,CAAAA;AAG9BC,IAAAA,WAAAA,CAAYC,OAAe,EAAEC,cAAiB,GAAA,KAAK,CAAE;AACnD,QAAA,KAAK,CAACD,OAAAA,CAAAA;aAHRC,cAAiB,GAAA,KAAA;QAKf,IAAI,CAACA,cAAc,GAAGA,cAAAA;AACxB;AACF;AAEA,MAAMC,cAAc,CAACC,SAAAA,GAAAA;IACnB,IAAI;QACF,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AAKzC,OAAO;YACrB,KAAK,GAAA;gBACH,MAAM,IAAIb,iBAAkBU,CAAAA,KAAAA,CAAMP,OAAO,CAAA;YAC3C,KAAK,GAAA;AACH,gBAAA,MAAM,IAAIH,iBAAkB,CAAA,mCAAA,CAAA;AAC9B,YAAA;AACEkC,gBAAAA,UAAAA,EAAAA;AACJ;KACK,MAAA;AACLA,QAAAA,UAAAA,EAAAA;AACF;AACF;;;;;;;;"}
|
package/dist/ee/license.mjs
CHANGED
|
@@ -35,6 +35,7 @@ const DEFAULT_FEATURES = {
|
|
|
35
35
|
}
|
|
36
36
|
]
|
|
37
37
|
};
|
|
38
|
+
const LICENSE_REGISTRY_URI = 'https://license.strapi.io';
|
|
38
39
|
const publicKey = fs.readFileSync(resolve(__dirname, '../../resources/key.pub'));
|
|
39
40
|
class LicenseCheckError extends Error {
|
|
40
41
|
constructor(message, shouldFallback = false){
|
|
@@ -70,6 +71,9 @@ const verifyLicense = (license)=>{
|
|
|
70
71
|
if (!licenseInfo.features) {
|
|
71
72
|
licenseInfo.features = DEFAULT_FEATURES[licenseInfo.type];
|
|
72
73
|
}
|
|
74
|
+
if (!licenseInfo.isTrial) {
|
|
75
|
+
licenseInfo.isTrial = false;
|
|
76
|
+
}
|
|
73
77
|
Object.freeze(licenseInfo.features);
|
|
74
78
|
return licenseInfo;
|
|
75
79
|
};
|
|
@@ -78,7 +82,7 @@ const throwError = ()=>{
|
|
|
78
82
|
};
|
|
79
83
|
const fetchLicense = async ({ strapi }, key, projectId)=>{
|
|
80
84
|
const { installId: installIdFromPackageJson } = strapi.config;
|
|
81
|
-
const response = await strapi.fetch(
|
|
85
|
+
const response = await strapi.fetch(`${LICENSE_REGISTRY_URI}/api/licenses/validate`, {
|
|
82
86
|
method: 'POST',
|
|
83
87
|
headers: {
|
|
84
88
|
'Content-Type': 'application/json'
|
|
@@ -107,5 +111,5 @@ const fetchLicense = async ({ strapi }, key, projectId)=>{
|
|
|
107
111
|
}
|
|
108
112
|
};
|
|
109
113
|
|
|
110
|
-
export { LicenseCheckError, fetchLicense, readLicense, verifyLicense };
|
|
114
|
+
export { LICENSE_REGISTRY_URI, LicenseCheckError, fetchLicense, readLicense, verifyLicense };
|
|
111
115
|
//# sourceMappingURL=license.mjs.map
|
package/dist/ee/license.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"license.mjs","sources":["../../src/ee/license.ts"],"sourcesContent":["import fs from 'fs';\nimport { join, resolve } from 'path';\nimport crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\nimport { generateInstallId } from '@strapi/utils';\n\ninterface LicenseInfo {\n type: 'bronze' | 'silver' | 'gold';\n expireAt?: string;\n seats?: number;\n features?: Array<{ name: string; options?: Record<string, unknown> }>;\n}\n\nconst DEFAULT_FEATURES = {\n bronze: [],\n silver: [],\n gold: [\n { name: 'sso' },\n // Set a null retention duration to allow the user to override it\n // The default of 90 days is set in the audit logs service\n { name: 'audit-logs', options: { retentionDays: null } },\n { name: 'review-workflows' },\n { name: 'cms-content-releases' },\n { name: 'cms-content-history', options: { retentionDays: 99999 } },\n { name: 'cms-advanced-preview' },\n ],\n};\n\nconst publicKey = fs.readFileSync(resolve(__dirname, '../../resources/key.pub'));\n\nclass LicenseCheckError extends Error {\n shouldFallback = false;\n\n constructor(message: string, shouldFallback = false) {\n super(message);\n\n this.shouldFallback = shouldFallback;\n }\n}\n\nconst readLicense = (directory: string) => {\n try {\n const path = join(directory, 'license.txt');\n return fs.readFileSync(path).toString();\n } catch (error) {\n if (typeof error === 'object' && error !== null && 'code' in error && error.code !== 'ENOENT') {\n throw Error('License file not readable, review its format and access rules.');\n }\n }\n};\n\nconst verifyLicense = (license: string) => {\n const [signature, base64Content] = Buffer.from(license, 'base64').toString().split('\\n');\n\n if (!signature || !base64Content) {\n throw new Error('Invalid license.');\n }\n\n const stringifiedContent = Buffer.from(base64Content, 'base64').toString();\n\n const verify = crypto.createVerify('RSA-SHA256');\n verify.update(stringifiedContent);\n verify.end();\n\n const verified = verify.verify(publicKey, signature, 'base64');\n\n if (!verified) {\n throw new Error('Invalid license.');\n }\n\n const licenseInfo: LicenseInfo = JSON.parse(stringifiedContent);\n\n if (!licenseInfo.features) {\n licenseInfo.features = DEFAULT_FEATURES[licenseInfo.type];\n }\n\n Object.freeze(licenseInfo.features);\n return licenseInfo;\n};\n\nconst throwError = () => {\n throw new LicenseCheckError('Could not proceed to the online validation of your license.', true);\n};\n\nconst fetchLicense = async (\n { strapi }: { strapi: Core.Strapi },\n key: string,\n projectId: string\n) => {\n const { installId: installIdFromPackageJson } = strapi.config;\n\n const response = await strapi\n .fetch(
|
|
1
|
+
{"version":3,"file":"license.mjs","sources":["../../src/ee/license.ts"],"sourcesContent":["import fs from 'fs';\nimport { join, resolve } from 'path';\nimport crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\nimport { generateInstallId } from '@strapi/utils';\n\ninterface LicenseInfo {\n type: 'bronze' | 'silver' | 'gold';\n isTrial: boolean;\n expireAt?: string;\n seats?: number;\n features?: Array<{ name: string; options?: Record<string, unknown> }>;\n}\n\nconst DEFAULT_FEATURES = {\n bronze: [],\n silver: [],\n gold: [\n { name: 'sso' },\n // Set a null retention duration to allow the user to override it\n // The default of 90 days is set in the audit logs service\n { name: 'audit-logs', options: { retentionDays: null } },\n { name: 'review-workflows' },\n { name: 'cms-content-releases' },\n { name: 'cms-content-history', options: { retentionDays: 99999 } },\n { name: 'cms-advanced-preview' },\n ],\n};\n\nconst LICENSE_REGISTRY_URI = 'https://license.strapi.io';\n\nconst publicKey = fs.readFileSync(resolve(__dirname, '../../resources/key.pub'));\n\nclass LicenseCheckError extends Error {\n shouldFallback = false;\n\n constructor(message: string, shouldFallback = false) {\n super(message);\n\n this.shouldFallback = shouldFallback;\n }\n}\n\nconst readLicense = (directory: string) => {\n try {\n const path = join(directory, 'license.txt');\n return fs.readFileSync(path).toString();\n } catch (error) {\n if (typeof error === 'object' && error !== null && 'code' in error && error.code !== 'ENOENT') {\n throw Error('License file not readable, review its format and access rules.');\n }\n }\n};\n\nconst verifyLicense = (license: string) => {\n const [signature, base64Content] = Buffer.from(license, 'base64').toString().split('\\n');\n\n if (!signature || !base64Content) {\n throw new Error('Invalid license.');\n }\n\n const stringifiedContent = Buffer.from(base64Content, 'base64').toString();\n\n const verify = crypto.createVerify('RSA-SHA256');\n verify.update(stringifiedContent);\n verify.end();\n\n const verified = verify.verify(publicKey, signature, 'base64');\n\n if (!verified) {\n throw new Error('Invalid license.');\n }\n\n const licenseInfo: LicenseInfo = JSON.parse(stringifiedContent);\n\n if (!licenseInfo.features) {\n licenseInfo.features = DEFAULT_FEATURES[licenseInfo.type];\n }\n\n if (!licenseInfo.isTrial) {\n licenseInfo.isTrial = false;\n }\n\n Object.freeze(licenseInfo.features);\n return licenseInfo;\n};\n\nconst throwError = () => {\n throw new LicenseCheckError('Could not proceed to the online validation of your license.', true);\n};\n\nconst fetchLicense = async (\n { strapi }: { strapi: Core.Strapi },\n key: string,\n projectId: string\n) => {\n const { installId: installIdFromPackageJson } = strapi.config;\n\n const response = await strapi\n .fetch(`${LICENSE_REGISTRY_URI}/api/licenses/validate`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n key,\n projectId,\n deviceId: generateInstallId(projectId, installIdFromPackageJson),\n }), // NOTE: Doing nothing on the LR with the installId\n })\n .catch(throwError);\n\n const contentType = response.headers.get('Content-Type');\n\n if (contentType?.includes('application/json')) {\n const { data, error } = await response.json();\n\n switch (response.status) {\n case 200:\n return data.license;\n case 400:\n throw new LicenseCheckError(error.message);\n case 404:\n throw new LicenseCheckError('The license used does not exists.');\n default:\n throwError();\n }\n } else {\n throwError();\n }\n};\n\nexport { readLicense, verifyLicense, fetchLicense, LicenseCheckError, LICENSE_REGISTRY_URI };\n"],"names":["DEFAULT_FEATURES","bronze","silver","gold","name","options","retentionDays","LICENSE_REGISTRY_URI","publicKey","fs","readFileSync","resolve","__dirname","LicenseCheckError","Error","constructor","message","shouldFallback","readLicense","directory","path","join","toString","error","code","verifyLicense","license","signature","base64Content","Buffer","from","split","stringifiedContent","verify","crypto","createVerify","update","end","verified","licenseInfo","JSON","parse","features","type","isTrial","Object","freeze","throwError","fetchLicense","strapi","key","projectId","installId","installIdFromPackageJson","config","response","fetch","method","headers","body","stringify","deviceId","generateInstallId","catch","contentType","get","includes","data","json","status"],"mappings":";;;;;AAeA,MAAMA,gBAAmB,GAAA;AACvBC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,MAAAA,EAAQ,EAAE;IACVC,IAAM,EAAA;AACJ,QAAA;YAAEC,IAAM,EAAA;AAAM,SAAA;;;AAGd,QAAA;YAAEA,IAAM,EAAA,YAAA;YAAcC,OAAS,EAAA;gBAAEC,aAAe,EAAA;AAAK;AAAE,SAAA;AACvD,QAAA;YAAEF,IAAM,EAAA;AAAmB,SAAA;AAC3B,QAAA;YAAEA,IAAM,EAAA;AAAuB,SAAA;AAC/B,QAAA;YAAEA,IAAM,EAAA,qBAAA;YAAuBC,OAAS,EAAA;gBAAEC,aAAe,EAAA;AAAM;AAAE,SAAA;AACjE,QAAA;YAAEF,IAAM,EAAA;AAAuB;AAChC;AACH,CAAA;AAEA,MAAMG,oBAAuB,GAAA;AAE7B,MAAMC,SAAYC,GAAAA,EAAAA,CAAGC,YAAY,CAACC,QAAQC,SAAW,EAAA,yBAAA,CAAA,CAAA;AAErD,MAAMC,iBAA0BC,SAAAA,KAAAA,CAAAA;AAG9BC,IAAAA,WAAAA,CAAYC,OAAe,EAAEC,cAAiB,GAAA,KAAK,CAAE;AACnD,QAAA,KAAK,CAACD,OAAAA,CAAAA;aAHRC,cAAiB,GAAA,KAAA;QAKf,IAAI,CAACA,cAAc,GAAGA,cAAAA;AACxB;AACF;AAEA,MAAMC,cAAc,CAACC,SAAAA,GAAAA;IACnB,IAAI;QACF,MAAMC,IAAAA,GAAOC,KAAKF,SAAW,EAAA,aAAA,CAAA;AAC7B,QAAA,OAAOV,EAAGC,CAAA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O,CAAA;YAC3C,KAAK,GAAA;AACH,gBAAA,MAAM,IAAIH,iBAAkB,CAAA,mCAAA,CAAA;AAC9B,YAAA;AACEkC,gBAAAA,UAAAA,EAAAA;AACJ;KACK,MAAA;AACLA,QAAAA,UAAAA,EAAAA;AACF;AACF;;;;"}
|
package/dist/factories.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var fp = require('lodash/fp');
|
|
4
4
|
var index = require('./core-api/controller/index.js');
|
|
5
5
|
require('@strapi/utils');
|
|
6
|
-
require('zod');
|
|
6
|
+
require('zod/v4');
|
|
7
7
|
var contentType = require('./core-api/routes/validation/content-type.js');
|
|
8
8
|
var index$1 = require('./core-api/service/index.js');
|
|
9
9
|
var index$2 = require('./core-api/routes/index.js');
|
package/dist/factories.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pipe, omit, pick } from 'lodash/fp';
|
|
2
2
|
import { createController } from './core-api/controller/index.mjs';
|
|
3
3
|
import '@strapi/utils';
|
|
4
|
-
import 'zod';
|
|
4
|
+
import 'zod/v4';
|
|
5
5
|
import { CoreContentTypeRouteValidator } from './core-api/routes/validation/content-type.mjs';
|
|
6
6
|
import { createService } from './core-api/service/index.mjs';
|
|
7
7
|
import { createRoutes } from './core-api/routes/index.mjs';
|
package/dist/index.js
CHANGED
|
@@ -4,9 +4,9 @@ var Strapi = require('./Strapi.js');
|
|
|
4
4
|
require('open');
|
|
5
5
|
require('lodash/fp');
|
|
6
6
|
require('path');
|
|
7
|
+
require('undici');
|
|
7
8
|
require('./ee/license.js');
|
|
8
9
|
var index = require('./utils/update-notifier/index.js');
|
|
9
|
-
require('undici');
|
|
10
10
|
require('chalk');
|
|
11
11
|
require('cli-table3');
|
|
12
12
|
require('@paralleldrive/cuid2');
|
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import Strapi from './Strapi.mjs';
|
|
|
2
2
|
import 'open';
|
|
3
3
|
import 'lodash/fp';
|
|
4
4
|
import 'path';
|
|
5
|
+
import 'undici';
|
|
5
6
|
import './ee/license.mjs';
|
|
6
7
|
import { createUpdateNotifier } from './utils/update-notifier/index.mjs';
|
|
7
|
-
import 'undici';
|
|
8
8
|
import 'chalk';
|
|
9
9
|
import 'cli-table3';
|
|
10
10
|
import '@paralleldrive/cuid2';
|
|
@@ -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,GA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../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,EA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,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;;;;"}
|
|
@@ -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,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AAAA;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
|
+
{"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,EAA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AAA,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,YAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Core } from '@strapi/types';
|
|
2
2
|
export type Config = {
|
|
3
3
|
enabled?: boolean;
|
|
4
|
-
origin: string | string[] | ((ctx: any) => string | string[]);
|
|
4
|
+
origin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>);
|
|
5
5
|
expose?: string | string[];
|
|
6
6
|
maxAge?: number;
|
|
7
7
|
credentials?: boolean;
|
|
@@ -9,5 +9,13 @@ export type Config = {
|
|
|
9
9
|
headers?: string | string[];
|
|
10
10
|
keepHeadersOnError?: boolean;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Determines if a request origin is allowed based on the configured origin list
|
|
14
|
+
* @param requestOrigin - The origin from the request header
|
|
15
|
+
* @param configuredOrigin - The origin configuration (string, array, or function)
|
|
16
|
+
* @param ctx - The Koa context (for function-based origin)
|
|
17
|
+
* @returns The allowed origin string or empty string if blocked
|
|
18
|
+
*/
|
|
19
|
+
export declare const matchOrigin: (requestOrigin: string | undefined, configuredOrigin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>), ctx?: any) => Promise<string>;
|
|
12
20
|
export declare const cors: Core.MiddlewareFactory<Config>;
|
|
13
21
|
//# sourceMappingURL=cors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;IAC3F,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAWF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,kBACP,MAAM,GAAG,SAAS,oBAE7B,MAAM,GACN,MAAM,EAAE,GACR,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,QAAQ,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,QAC5D,GAAG,KACR,QAAQ,MAAM,CAgChB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CA0B/C,CAAC"}
|
package/dist/middlewares/cors.js
CHANGED
|
@@ -23,6 +23,42 @@ const defaults = {
|
|
|
23
23
|
],
|
|
24
24
|
keepHeadersOnError: false
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Determines if a request origin is allowed based on the configured origin list
|
|
28
|
+
* @param requestOrigin - The origin from the request header
|
|
29
|
+
* @param configuredOrigin - The origin configuration (string, array, or function)
|
|
30
|
+
* @param ctx - The Koa context (for function-based origin)
|
|
31
|
+
* @returns The allowed origin string or empty string if blocked
|
|
32
|
+
*/ const matchOrigin = async (requestOrigin, configuredOrigin, ctx)=>{
|
|
33
|
+
if (!requestOrigin) {
|
|
34
|
+
return '*';
|
|
35
|
+
}
|
|
36
|
+
let originList;
|
|
37
|
+
if (typeof configuredOrigin === 'function') {
|
|
38
|
+
originList = await configuredOrigin(ctx);
|
|
39
|
+
} else {
|
|
40
|
+
originList = configuredOrigin;
|
|
41
|
+
}
|
|
42
|
+
// Normalize originList into an array
|
|
43
|
+
let normalizedOrigins;
|
|
44
|
+
if (Array.isArray(originList)) {
|
|
45
|
+
normalizedOrigins = originList;
|
|
46
|
+
} else if (originList === undefined || originList === null) {
|
|
47
|
+
// Handle undefined/null - treat as wildcard
|
|
48
|
+
normalizedOrigins = [
|
|
49
|
+
'*'
|
|
50
|
+
];
|
|
51
|
+
} else {
|
|
52
|
+
// Handle comma-separated string of origins
|
|
53
|
+
normalizedOrigins = originList.split(',').map((origin)=>origin.trim());
|
|
54
|
+
}
|
|
55
|
+
// Check if wildcard is in the normalized origins
|
|
56
|
+
if (normalizedOrigins.includes('*')) {
|
|
57
|
+
return requestOrigin;
|
|
58
|
+
}
|
|
59
|
+
// Check if request origin is in the normalized origins
|
|
60
|
+
return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';
|
|
61
|
+
};
|
|
26
62
|
const cors = (config)=>{
|
|
27
63
|
const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {
|
|
28
64
|
...defaults,
|
|
@@ -33,23 +69,8 @@ const cors = (config)=>{
|
|
|
33
69
|
}
|
|
34
70
|
return koaCors({
|
|
35
71
|
async origin (ctx) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
let originList;
|
|
40
|
-
if (typeof origin === 'function') {
|
|
41
|
-
originList = await origin(ctx);
|
|
42
|
-
} else {
|
|
43
|
-
originList = origin;
|
|
44
|
-
}
|
|
45
|
-
if (Array.isArray(originList)) {
|
|
46
|
-
return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
|
|
47
|
-
}
|
|
48
|
-
const parsedOrigin = originList.split(',').map((origin)=>origin.trim());
|
|
49
|
-
if (parsedOrigin.length > 1) {
|
|
50
|
-
return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
|
|
51
|
-
}
|
|
52
|
-
return originList;
|
|
72
|
+
const requestOrigin = ctx.get('Origin');
|
|
73
|
+
return matchOrigin(requestOrigin, origin, ctx);
|
|
53
74
|
},
|
|
54
75
|
exposeHeaders: expose,
|
|
55
76
|
maxAge,
|
|
@@ -61,4 +82,5 @@ const cors = (config)=>{
|
|
|
61
82
|
};
|
|
62
83
|
|
|
63
84
|
exports.cors = cors;
|
|
85
|
+
exports.matchOrigin = matchOrigin;
|
|
64
86
|
//# sourceMappingURL=cors.js.map
|