@strapi/core 0.0.0-experimental.c72b48da735f44a3ccafb7a6dc9ba5213f3844db → 0.0.0-experimental.ca5f02ef2ec166e219546983049c0543bed92f8d
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.map +1 -1
- package/dist/Strapi.js +4 -1
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +4 -1
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/index.d.ts +3 -0
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +3 -0
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/index.mjs +3 -0
- package/dist/configuration/index.mjs.map +1 -1
- package/dist/core-api/controller/collection-type.d.ts.map +1 -1
- package/dist/core-api/controller/collection-type.js +1 -1
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/collection-type.mjs +1 -1
- package/dist/core-api/controller/collection-type.mjs.map +1 -1
- 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/single-type.js +1 -1
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/single-type.mjs +1 -1
- package/dist/core-api/controller/single-type.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 +9 -3
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +9 -3
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/index.d.ts +4 -22
- package/dist/core-api/routes/index.d.ts.map +1 -1
- package/dist/core-api/routes/index.js +150 -8
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +131 -8
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +244 -0
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -0
- package/dist/core-api/routes/validation/attributes.js +560 -0
- package/dist/core-api/routes/validation/attributes.js.map +1 -0
- package/dist/core-api/routes/validation/attributes.mjs +521 -0
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -0
- package/dist/core-api/routes/validation/common.d.ts +105 -0
- package/dist/core-api/routes/validation/common.d.ts.map +1 -0
- package/dist/core-api/routes/validation/common.js +116 -0
- package/dist/core-api/routes/validation/common.js.map +1 -0
- package/dist/core-api/routes/validation/common.mjs +95 -0
- package/dist/core-api/routes/validation/common.mjs.map +1 -0
- package/dist/core-api/routes/validation/component.d.ts +34 -0
- package/dist/core-api/routes/validation/component.d.ts.map +1 -0
- package/dist/core-api/routes/validation/component.js +45 -0
- package/dist/core-api/routes/validation/component.js.map +1 -0
- package/dist/core-api/routes/validation/component.mjs +43 -0
- package/dist/core-api/routes/validation/component.mjs.map +1 -0
- package/dist/core-api/routes/validation/constants.d.ts +8 -0
- package/dist/core-api/routes/validation/constants.d.ts.map +1 -0
- package/dist/core-api/routes/validation/constants.js +18 -0
- package/dist/core-api/routes/validation/constants.js.map +1 -0
- package/dist/core-api/routes/validation/constants.mjs +16 -0
- package/dist/core-api/routes/validation/constants.mjs.map +1 -0
- package/dist/core-api/routes/validation/content-type.d.ts +128 -0
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -0
- package/dist/core-api/routes/validation/content-type.js +201 -0
- package/dist/core-api/routes/validation/content-type.js.map +1 -0
- package/dist/core-api/routes/validation/content-type.mjs +180 -0
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -0
- package/dist/core-api/routes/validation/index.d.ts +5 -0
- package/dist/core-api/routes/validation/index.d.ts.map +1 -0
- 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 +238 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +214 -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 +112 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +90 -0
- package/dist/core-api/routes/validation/utils.mjs.map +1 -0
- package/dist/domain/module/index.d.ts.map +1 -1
- package/dist/domain/module/index.js +3 -0
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs +3 -0
- package/dist/domain/module/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.d.ts +3 -1
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +10 -2
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs +10 -3
- package/dist/factories.mjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +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/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/services/content-source-maps.d.ts +8 -0
- package/dist/services/content-source-maps.d.ts.map +1 -0
- package/dist/services/content-source-maps.js +119 -0
- package/dist/services/content-source-maps.js.map +1 -0
- package/dist/services/content-source-maps.mjs +117 -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/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/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 +5 -4
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +6 -5
- package/dist/services/document-service/repository.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 +9 -8
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +9 -8
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +2 -2
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +2 -2
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/server/register-routes.js +22 -2
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +22 -2
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.d.ts +10 -0
- package/dist/services/server/routing.d.ts.map +1 -1
- package/dist/services/server/routing.js +7 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs +7 -1
- package/dist/services/server/routing.mjs.map +1 -1
- 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.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","shiftCronEx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gB,IAAO,GAAA,IAAA;IACX,OACEhF,EAAAA,CAAGE,WAAW,CAAC0D,QAAQ,EAAEqB,GAAI,CAAA,CAACC,OAC5B,GAAA,OAAOA,OAAY,KAAA,QAAA,GAAWA,OAAU,GAAA;YAAEC,IAAMD,EAAAA;AAAQ,SAAA,CAAA,IACrD,EAAE;AAEX,CAAA;AAEA,MAAMvD,GAAAA,GAAM,CAACyD,WAAAA,GAAwBJ,IAAOK,EAAAA,CAAAA,IAAI,CAAC,CAACH,OAAAA,GAAYA,OAAQC,CAAAA,IAAI,KAAKC,WAAAA,CAAAA;AAE/E,YAAeE,MAAAA,CAAOC,MAAM,CAAC;AAC3BzE,IAAAA,IAAAA;AACA0D,IAAAA,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,Q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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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AAA,GAAAA;AACAC,YAAAA,SAAAA;AACAU,YAAAA,QAAAA,EAAUC,8BAAkBX,SAAWE,EAAAA,wBAAAA;AACzC,SAAA;AACF,KAAA,CAAA,CACCU,KAAK,CAAChB,UAAAA,CAAAA;AAET,IAAA,MAAMiB,WAAcT,GAAAA,QAAAA,CAASG,OAAO,CAACO,GAAG,CAAC,cAAA,CAAA;IAEzC,IAAID,WAAAA,EAAaE,SAAS,kBAAqB,CAAA,EAAA;QAC7C,MAAM,EAAEC,IAAI,EAAE5C,KAAK,EAAE,GAAG,MAAMgC,SAASa,IAAI,EAAA;AAE3C,QAAA,OAAQb,SAASc,MAAM;YACrB,KAAK,GAAA;AACH,gBAAA,OAAOF,KAAKzC,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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BAAAA;AACzC,SAAA;AACF,KAAA,CAAA,CACCU,KAAK,CAAChB,UAAAA,CAAAA;AAET,IAAA,MAAMiB,WAAcT,GAAAA,QAAAA,CAASG,OAAO,CAACO,GAAG,CAAC,cAAA,CAAA;IAEzC,IAAID,WAAAA,EAAaE,SAAS,kBAAqB,CAAA,EAAA;QAC7C,MAAM,EAAEC,IAAI,EAAE5C,KAAK,EAAE,GAAG,MAAMgC,SAASa,IAAI,EAAA;AAE3C,QAAA,OAAQb,SAASc,MAAM;YACrB,KAAK,GAAA;AACH,gBAAA,OAAOF,KAAKzC,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/factories.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Core, UID, Utils } from '@strapi/types';
|
|
2
|
+
import { CoreContentTypeRouteValidator } from './core-api/routes/validation';
|
|
2
3
|
type WithStrapiCallback<T> = T | (<S extends {
|
|
3
4
|
strapi: Core.Strapi;
|
|
4
5
|
}>(params: S) => T);
|
|
@@ -9,6 +10,7 @@ declare function createCoreService<TUID extends UID.ContentType, TService extend
|
|
|
9
10
|
strapi: Core.Strapi;
|
|
10
11
|
}) => TService & Core.CoreAPI.Service.ContentType<TUID>;
|
|
11
12
|
declare function createCoreRouter<T extends UID.ContentType>(uid: T, cfg?: Core.CoreAPI.Router.RouterConfig<T>): Core.CoreAPI.Router.Router;
|
|
13
|
+
declare const createCoreValidator: <T extends UID.ContentType>(uid: T, strapi: Core.Strapi) => CoreContentTypeRouteValidator;
|
|
12
14
|
declare const isCustomController: <T extends Core.Controller>(controller: T) => boolean;
|
|
13
|
-
export { createCoreController, createCoreService, createCoreRouter, isCustomController };
|
|
15
|
+
export { createCoreController, createCoreService, createCoreRouter, createCoreValidator, isCustomController, };
|
|
14
16
|
//# sourceMappingURL=factories.d.ts.map
|
package/dist/factories.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../src/factories.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../src/factories.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAQ7E,KAAK,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAEvF,QAAA,MAAM,oBAAoB,oGAInB,IAAI,QACH,mBACJ,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAC9E,mBAIE;IACD,MAAM,EAAE,KAAK,MAAM,CAAC;CACrB,KAAG,WAAW,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAwB3D,CAAC;AAEF,iBAAS,iBAAiB,CACxB,IAAI,SAAS,GAAG,CAAC,WAAW,EAC5B,QAAQ,SAAS,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAEtD,GAAG,EAAE,IAAI,EACT,GAAG,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,iBAI9F;IACD,MAAM,EAAE,KAAK,MAAM,CAAC;CACrB,KAAG,QAAQ,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CActD;AAED,iBAAS,gBAAgB,CAAC,CAAC,SAAS,GAAG,CAAC,WAAW,EACjD,GAAG,EAAE,CAAC,EACN,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,GACxC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CA+B5B;AAED,QAAA,MAAM,mBAAmB,mCAClB,CAAC,UACE,KAAK,MAAM,KAClB,6BAEF,CAAC;AAEF,QAAA,MAAM,kBAAkB,0CAA2C,CAAC,KAAG,OAEtE,CAAC;AAEF,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,CAAC"}
|
package/dist/factories.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var fp = require('lodash/fp');
|
|
4
4
|
var index = require('./core-api/controller/index.js');
|
|
5
|
+
require('@strapi/utils');
|
|
6
|
+
require('zod/v4');
|
|
7
|
+
var contentType = require('./core-api/routes/validation/content-type.js');
|
|
5
8
|
var index$1 = require('./core-api/service/index.js');
|
|
6
9
|
var index$2 = require('./core-api/routes/index.js');
|
|
7
10
|
|
|
@@ -60,12 +63,13 @@ function createCoreRouter(uid, cfg) {
|
|
|
60
63
|
if (!routes) {
|
|
61
64
|
const contentType = strapi.contentType(uid);
|
|
62
65
|
const defaultRoutes = index$2.createRoutes({
|
|
63
|
-
contentType
|
|
66
|
+
contentType,
|
|
67
|
+
strapi
|
|
64
68
|
});
|
|
65
69
|
const keys = Object.keys(defaultRoutes);
|
|
66
70
|
keys.forEach((routeName)=>{
|
|
67
71
|
const defaultRoute = defaultRoutes[routeName];
|
|
68
|
-
|
|
72
|
+
defaultRoute.config = config[routeName] ?? {};
|
|
69
73
|
});
|
|
70
74
|
const selectedRoutes = fp.pipe((routes)=>except ? fp.omit(except, routes) : routes, (routes)=>only ? fp.pick(only, routes) : routes)(defaultRoutes);
|
|
71
75
|
routes = Object.values(selectedRoutes);
|
|
@@ -74,6 +78,9 @@ function createCoreRouter(uid, cfg) {
|
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
80
|
}
|
|
81
|
+
const createCoreValidator = (uid, strapi1)=>{
|
|
82
|
+
return new contentType.CoreContentTypeRouteValidator(strapi1, uid);
|
|
83
|
+
};
|
|
77
84
|
const isCustomController = (controller)=>{
|
|
78
85
|
return symbols.CustomController in controller;
|
|
79
86
|
};
|
|
@@ -81,5 +88,6 @@ const isCustomController = (controller)=>{
|
|
|
81
88
|
exports.createCoreController = createCoreController;
|
|
82
89
|
exports.createCoreRouter = createCoreRouter;
|
|
83
90
|
exports.createCoreService = createCoreService;
|
|
91
|
+
exports.createCoreValidator = createCoreValidator;
|
|
84
92
|
exports.isCustomController = isCustomController;
|
|
85
93
|
//# sourceMappingURL=factories.js.map
|
package/dist/factories.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.js","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n
|
|
1
|
+
{"version":3,"file":"factories.js","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { CoreContentTypeRouteValidator } from './core-api/routes/validation';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType, strapi });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n defaultRoute.config = (config[routeName] ?? {}) as Core.RouteConfig;\n });\n\n const selectedRoutes = pipe(\n (routes) => (except ? omit(except, routes) : routes),\n (routes) => (only ? pick(only, routes) : routes)\n )(defaultRoutes);\n\n routes = Object.values(selectedRoutes);\n }\n\n return routes;\n },\n };\n}\n\nconst createCoreValidator = <T extends UID.ContentType>(\n uid: T,\n strapi: Core.Strapi\n): CoreContentTypeRouteValidator => {\n return new CoreContentTypeRouteValidator(strapi, uid);\n};\n\nconst isCustomController = <T extends Core.Controller>(controller: T): boolean => {\n return symbols.CustomController in controller;\n};\n\nexport {\n createCoreController,\n createCoreService,\n createCoreRouter,\n createCoreValidator,\n isCustomController,\n};\n"],"names":["symbols","CustomController","Symbol","createCoreController","uid","cfg","strapi","baseController","createController","contentType","userCtrl","methodName","Object","keys","undefined","setPrototypeOf","isCustom","defineProperty","writable","configurable","enumerable","createCoreService","baseService","createService","userService","createCoreRouter","prefix","config","only","except","type","routes","defaultRoutes","createRoutes","forEach","routeName","defaultRoute","selectedRoutes","pipe","omit","pick","values","createCoreValidator","CoreContentTypeRouteValidator","isCustomController","controller"],"mappings":";;;;;;;;;;AAQA,MAAMA,OAAU,GAAA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YAAAA,CAAaT,MAAM,GAAIA,MAAM,CAACQ,SAAAA,CAAU,IAAI,EAAC;AAC/C,iBAAA,CAAA;AAEA,gBAAA,MAAME,cAAiBC,GAAAA,OAAAA,CACrB,CAACP,MAAAA,GAAYF,SAASU,OAAKV,CAAAA,MAAAA,EAAQE,MAAUA,CAAAA,GAAAA,MAAAA,EAC7C,CAACA,MAAYH,GAAAA,IAAAA,GAAOY,OAAKZ,CAAAA,IAAAA,EAAMG,UAAUA,MACzCC,CAAAA,CAAAA,aAAAA,CAAAA;gBAEFD,MAASnB,GAAAA,MAAAA,CAAO6B,MAAM,CAACJ,cAAAA,CAAAA;AACzB;YAEA,OAAON,MAAAA;AACT;AACF,KAAA;AACF;AAEMW,MAAAA,mBAAAA,GAAsB,CAC1BtC,GACAE,EAAAA,OAAAA,GAAAA;IAEA,OAAO,IAAIqC,0CAA8BrC,OAAQF,EAAAA,GAAAA,CAAAA;AACnD;AAEA,MAAMwC,qBAAqB,CAA4BC,UAAAA,GAAAA;IACrD,OAAO7C,OAAAA,CAAQC,gBAAgB,IAAI4C,UAAAA;AACrC;;;;;;;;"}
|
package/dist/factories.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { pipe, omit, pick } from 'lodash/fp';
|
|
2
2
|
import { createController } from './core-api/controller/index.mjs';
|
|
3
|
+
import '@strapi/utils';
|
|
4
|
+
import 'zod/v4';
|
|
5
|
+
import { CoreContentTypeRouteValidator } from './core-api/routes/validation/content-type.mjs';
|
|
3
6
|
import { createService } from './core-api/service/index.mjs';
|
|
4
7
|
import { createRoutes } from './core-api/routes/index.mjs';
|
|
5
8
|
|
|
@@ -58,12 +61,13 @@ function createCoreRouter(uid, cfg) {
|
|
|
58
61
|
if (!routes) {
|
|
59
62
|
const contentType = strapi.contentType(uid);
|
|
60
63
|
const defaultRoutes = createRoutes({
|
|
61
|
-
contentType
|
|
64
|
+
contentType,
|
|
65
|
+
strapi
|
|
62
66
|
});
|
|
63
67
|
const keys = Object.keys(defaultRoutes);
|
|
64
68
|
keys.forEach((routeName)=>{
|
|
65
69
|
const defaultRoute = defaultRoutes[routeName];
|
|
66
|
-
|
|
70
|
+
defaultRoute.config = config[routeName] ?? {};
|
|
67
71
|
});
|
|
68
72
|
const selectedRoutes = pipe((routes)=>except ? omit(except, routes) : routes, (routes)=>only ? pick(only, routes) : routes)(defaultRoutes);
|
|
69
73
|
routes = Object.values(selectedRoutes);
|
|
@@ -72,9 +76,12 @@ function createCoreRouter(uid, cfg) {
|
|
|
72
76
|
}
|
|
73
77
|
};
|
|
74
78
|
}
|
|
79
|
+
const createCoreValidator = (uid, strapi1)=>{
|
|
80
|
+
return new CoreContentTypeRouteValidator(strapi1, uid);
|
|
81
|
+
};
|
|
75
82
|
const isCustomController = (controller)=>{
|
|
76
83
|
return symbols.CustomController in controller;
|
|
77
84
|
};
|
|
78
85
|
|
|
79
|
-
export { createCoreController, createCoreRouter, createCoreService, isCustomController };
|
|
86
|
+
export { createCoreController, createCoreRouter, createCoreService, createCoreValidator, isCustomController };
|
|
80
87
|
//# sourceMappingURL=factories.mjs.map
|
package/dist/factories.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.mjs","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n
|
|
1
|
+
{"version":3,"file":"factories.mjs","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { CoreContentTypeRouteValidator } from './core-api/routes/validation';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType, strapi });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n defaultRoute.config = (config[routeName] ?? {}) as Core.RouteConfig;\n });\n\n const selectedRoutes = pipe(\n (routes) => (except ? omit(except, routes) : routes),\n (routes) => (only ? pick(only, routes) : routes)\n )(defaultRoutes);\n\n routes = Object.values(selectedRoutes);\n }\n\n return routes;\n },\n };\n}\n\nconst createCoreValidator = <T extends UID.ContentType>(\n uid: T,\n strapi: Core.Strapi\n): CoreContentTypeRouteValidator => {\n return new CoreContentTypeRouteValidator(strapi, uid);\n};\n\nconst isCustomController = <T extends Core.Controller>(controller: T): boolean => {\n return symbols.CustomController in controller;\n};\n\nexport {\n createCoreController,\n createCoreService,\n createCoreRouter,\n createCoreValidator,\n isCustomController,\n};\n"],"names":["symbols","CustomController","Symbol","createCoreController","uid","cfg","strapi","baseController","createController","contentType","userCtrl","methodName","Object","keys","undefined","setPrototypeOf","isCustom","defineProperty","writable","configurable","enumerable","createCoreService","baseService","createService","userService","createCoreRouter","prefix","config","only","except","type","routes","defaultRoutes","createRoutes","forEach","routeName","defaultRoute","selectedRoutes","pipe","omit","pick","values","createCoreValidator","CoreContentTypeRouteValidator","isCustomController","controller"],"mappings":";;;;;;;;AAQA,MAAMA,OAAU,GAAA;AACdC,IAAAA,gBAAAA,EAAkBC,MAAO,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,SAAAA,CAAU,IAAI,EAAC;AAC/C,iBAAA,CAAA;AAEA,gBAAA,MAAME,cAAiBC,GAAAA,IAAAA,CACrB,CAACP,MAAAA,GAAYF,SAASU,IAAKV,CAAAA,MAAAA,EAAQE,MAAUA,CAAAA,GAAAA,MAAAA,EAC7C,CAACA,MAAYH,GAAAA,IAAAA,GAAOY,IAAKZ,CAAAA,IAAAA,EAAMG,UAAUA,MACzCC,CAAAA,CAAAA,aAAAA,CAAAA;gBAEFD,MAASnB,GAAAA,MAAAA,CAAO6B,MAAM,CAACJ,cAAAA,CAAAA;AACzB;YAEA,OAAON,MAAAA;AACT;AACF,KAAA;AACF;AAEMW,MAAAA,mBAAAA,GAAsB,CAC1BtC,GACAE,EAAAA,OAAAA,GAAAA;IAEA,OAAO,IAAIqC,8BAA8BrC,OAAQF,EAAAA,GAAAA,CAAAA;AACnD;AAEA,MAAMwC,qBAAqB,CAA4BC,UAAAA,GAAAA;IACrD,OAAO7C,OAAAA,CAAQC,gBAAgB,IAAI4C,UAAAA;AACrC;;;;"}
|
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';
|
|
@@ -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
|