@strapi/core 0.0.0-experimental.fccfa141baa6df7776ec7cb83f7fe923626ba6f5 → 0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +6 -1
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +6 -1
- package/dist/ee/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/ee/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ee/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;;;;;;;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ee/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;;;;;;;;;;;;;;;;;iCAsPb,MAAM;;;AAfnC,wBAiBG"}
|
package/dist/ee/index.js
CHANGED
@@ -120,7 +120,12 @@ const checkLicense = async ({ strapi: strapi2 }) => {
|
|
120
120
|
process.env.STRAPI_DISABLE_LICENSE_PING?.toLowerCase() === "true";
|
121
121
|
if (!shouldStayOffline) {
|
122
122
|
await onlineUpdate({ strapi: strapi2 });
|
123
|
-
strapi2.cron.add({
|
123
|
+
strapi2.cron.add({
|
124
|
+
onlineUpdate: {
|
125
|
+
task: () => onlineUpdate({ strapi: strapi2 }),
|
126
|
+
options: cron.shiftCronExpression("0 0 */12 * * *")
|
127
|
+
}
|
128
|
+
});
|
124
129
|
} else {
|
125
130
|
if (!ee.licenseInfo.expireAt) {
|
126
131
|
return disable("Your license does not have offline support.");
|
package/dist/ee/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","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 strapi.cron.add({ [shiftCronExpression('0 0 */12 * * *')]: onlineUpdate });\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 features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["pick","license","readLicense","verifyLicense","strapi","get","result","LicenseCheckError","fetchLicense","isEqual","shiftCronExpression"],"mappings":";;;;AAOA,MAAM,aAAa,MAAO;AAc1B,MAAM,KAAS;AAAA,EACb,SAAS;AAAA,EACT,aAAa,CAAC;AAChB;AAEA,MAAM,UAAU,CAAC,YAAoB;AAE7B,QAAA,kBAAkB,GAAG,YAAY;AAEvC,KAAG,QAAQ,KAAK,GAAG,OAAO,mBAAmB;AAE7C,KAAG,cAAcA,GAAA,KAAK,cAAc,GAAG,WAAW;AAElD,KAAG,UAAU;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ACA;AAAA,IACA,WAAW,CAAC,gBAAwB,IAAI,WAAW,MAAM;AAAA,EAAA,CAC1D;AACH,CAAC;;"}
|
1
|
+
{"version":3,"file":"index.js","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 features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["pick","license","readLicense","verifyLicense","strapi","get","result","LicenseCheckError","fetchLicense","isEqual","shiftCronExpression"],"mappings":";;;;AAOA,MAAM,aAAa,MAAO;AAc1B,MAAM,KAAS;AAAA,EACb,SAAS;AAAA,EACT,aAAa,CAAC;AAChB;A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O,KAAK,CAAC,YAAY,QAAQ,SAAS,WAAW;AAE1F,MAAe,QAAA,OAAO,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,GAAG;AAAA,EACZ;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,GAAG,YAAY;AAAA,EACxB;AAAA,EAEA,UAAU,OAAO,OAAO;AAAA,IACtB;AAAA,IACA;AAAA,IACA,WAAW,CAAC,gBAAwB,IAAI,WAAW,MAAM;AAAA,EAAA,CAC1D;AACH,CAAC;;"}
|
package/dist/ee/index.mjs
CHANGED
@@ -119,7 +119,12 @@ const checkLicense = async ({ strapi: strapi2 }) => {
|
|
119
119
|
process.env.STRAPI_DISABLE_LICENSE_PING?.toLowerCase() === "true";
|
120
120
|
if (!shouldStayOffline) {
|
121
121
|
await onlineUpdate({ strapi: strapi2 });
|
122
|
-
strapi2.cron.add({
|
122
|
+
strapi2.cron.add({
|
123
|
+
onlineUpdate: {
|
124
|
+
task: () => onlineUpdate({ strapi: strapi2 }),
|
125
|
+
options: shiftCronExpression("0 0 */12 * * *")
|
126
|
+
}
|
127
|
+
});
|
123
128
|
} else {
|
124
129
|
if (!ee.licenseInfo.expireAt) {
|
125
130
|
return disable("Your license does not have offline support.");
|
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 strapi.cron.add({ [shiftCronExpression('0 0 */12 * * *')]: onlineUpdate });\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 features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["strapi","get","result"],"mappings":";;;AAOA,MAAM,aAAa,MAAO;AAc1B,MAAM,KAAS;AAAA,EACb,SAAS;AAAA,EACT,aAAa,CAAC;AAChB;AAEA,MAAM,UAAU,CAAC,YAAoB;AAE7B,QAAA,kBAAkB,GAAG,YAAY;AAEvC,KAAG,QAAQ,KAAK,GAAG,OAAO,mBAAmB;AAE7C,KAAG,cAAc,KAAK,cAAc,GAAG,WAAW;AAElD,KAAG,UAAU;AAEb,MAAI,iBAAiB;AAEZ,WAAA,SAAS,KAAK,YAAY;AAAA,EACnC;AACF;AAEA,MAAM,SAAS,MAAM;AAEb,QAAA,kBAAkB,GAAG,YAAY;AAEvC,KAAG,UAAU;AAEb,MAAI,iBAAiB;AAEZ,WAAA,SAAS,KAAK,WAAW;AAAA,EAClC;AACF;AAEA,IAAI,cAAc;AAKlB,MAAM,OAAO,CAAC,YAAoB,WAAoB;AACpD,MAAI,aAAa;AACf;AAAA,EACF;AAEc,gBAAA;AACd,KAAG,SAAS;AAEZ,MAAI,QAAQ,IAAI,mBAAmB,YAAA,MAAkB,QAAQ;AAC3D;AAAA,EACF;AA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D,QAAA,oBACJ,GAAG,YAAY,SAAS;AAAA,EAExB,QAAQ,IAAI,6BAA6B,YAAA,MAAkB;AAE7D,MAAI,CAAC,mBAAmB;AACtB,UAAM,aAAa,EAAE,QAAAA,QAAQ,CAAA;AAC7BA,YAAO,KAAK,IAAI,EAAE,CAAC,oBAAoB,gBAAgB,CAAC,GAAG,aAAA,CAAc;AAAA,EAAA,OACpE;AACD,QAAA,CAAC,GAAG,YAAY,UAAU;AAC5B,aAAO,QAAQ,6CAA6C;AAAA,IAC9D;AAEa;EACf;AACF;AAEA,MAAM,OAAO,MAAM;AAEf,SAAA,GAAG,YAAY,UAAU;AAAA,IAAI,CAAC,YAC5B,OAAO,YAAY,WAAW,UAAU,EAAE,MAAM,QAAQ;AAAA,OACrD;AAET;AAEA,MAAM,MAAM,CAAC,gBAAwB,OAAO,KAAK,CAAC,YAAY,QAAQ,SAAS,WAAW;AAE1F,MAAe,QAAA,OAAO,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,GAAG;AAAA,EACZ;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,GAAG,YAAY;AAAA,EACxB;AAAA,EAEA,UAAU,OAAO,OAAO;AAAA,IACtB;AAAA,IACA;AAAA,IACA,WAAW,CAAC,gBAAwB,IAAI,WAAW,MAAM;AAAA,EAAA,CAC1D;AACH,CAAC;"}
|
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 features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["strapi","get","result"],"mappings":";;;AAOA,MAAM,aAAa,MAAO;AAc1B,MAAM,KAAS;AAAA,EACb,SAAS;AAAA,EACT,aAAa,CAAC;AAChB;AAEA,MAAM,UAAU,CAAC,YAAoB;AAE7B,QAAA,kBAAkB,GAAG,YAAY;AAEvC,KAAG,QAAQ,KAAK,GAAG,OAAO,mBAAmB;AAE7C,KAAG,cAAc,KAAK,cAAc,GAAG,WAAW;AAElD,KAAG,UAAU;AAEb,MAAI,iBAAiB;AAEZ,WAAA,SAAS,KAAK,YAAY;AAAA,EACnC;AACF;AAEA,MAAM,SAAS,MAAM;AAEb,QAAA,kBAAkB,GAAG,YAAY;AAEvC,KAAG,UAAU;AAEb,MAAI,iBAAiB;AAEZ,WAAA,SAAS,KAAK,WAAW;AAAA,EAClC;AACF;AAEA,IAAI,cAAc;AAKlB,MAAM,OAAO,CAAC,YAAoB,WAAoB;AACpD,MAAI,aAAa;AACf;AAAA,EACF;AAEc,gBAAA;AACd,KAAG,SAAS;AAEZ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AA,EACnC;AAEO;AACT;AAEA,MAAM,eAAe,OAAO,EAAE,QAAAA,cAAsC;AAC5D,QAAA,oBACJ,GAAG,YAAY,SAAS;AAAA,EAExB,QAAQ,IAAI,6BAA6B,YAAA,MAAkB;AAE7D,MAAI,CAAC,mBAAmB;AACtB,UAAM,aAAa,EAAE,QAAAA,QAAQ,CAAA;AAE7BA,YAAO,KAAK,IAAI;AAAA,MACd,cAAc;AAAA,QACZ,MAAM,MAAM,aAAa,EAAE,QAAAA,SAAQ;AAAA,QACnC,SAAS,oBAAoB,gBAAgB;AAAA,MAC/C;AAAA,IAAA,CACD;AAAA,EAAA,OACI;AACD,QAAA,CAAC,GAAG,YAAY,UAAU;AAC5B,aAAO,QAAQ,6CAA6C;AAAA,IAC9D;AAEa;EACf;AACF;AAEA,MAAM,OAAO,MAAM;AAEf,SAAA,GAAG,YAAY,UAAU;AAAA,IAAI,CAAC,YAC5B,OAAO,YAAY,WAAW,UAAU,EAAE,MAAM,QAAQ;AAAA,OACrD;AAET;AAEA,MAAM,MAAM,CAAC,gBAAwB,OAAO,KAAK,CAAC,YAAY,QAAQ,SAAS,WAAW;AAE1F,MAAe,QAAA,OAAO,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,GAAG;AAAA,EACZ;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,GAAG,YAAY;AAAA,EACxB;AAAA,EAEA,UAAU,OAAO,OAAO;AAAA,IACtB;AAAA,IACA;AAAA,IACA,WAAW,CAAC,gBAAwB,IAAI,WAAW,MAAM;AAAA,EAAA,CAC1D;AACH,CAAC;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@strapi/core",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
4
4
|
"description": "Core of Strapi",
|
5
5
|
"homepage": "https://strapi.io",
|
6
6
|
"bugs": {
|
@@ -55,15 +55,15 @@
|
|
55
55
|
"@koa/cors": "5.0.0",
|
56
56
|
"@koa/router": "12.0.1",
|
57
57
|
"@paralleldrive/cuid2": "2.2.2",
|
58
|
-
"@strapi/admin": "0.0.0-
|
59
|
-
"@strapi/database": "0.0.0-
|
60
|
-
"@strapi/generators": "0.0.0-
|
61
|
-
"@strapi/logger": "0.0.0-
|
58
|
+
"@strapi/admin": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
59
|
+
"@strapi/database": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
60
|
+
"@strapi/generators": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
61
|
+
"@strapi/logger": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
62
62
|
"@strapi/pack-up": "5.0.0",
|
63
|
-
"@strapi/permissions": "0.0.0-
|
64
|
-
"@strapi/types": "0.0.0-
|
65
|
-
"@strapi/typescript-utils": "0.0.0-
|
66
|
-
"@strapi/utils": "0.0.0-
|
63
|
+
"@strapi/permissions": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
64
|
+
"@strapi/types": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
65
|
+
"@strapi/typescript-utils": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
66
|
+
"@strapi/utils": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
67
67
|
"bcryptjs": "2.4.3",
|
68
68
|
"boxen": "5.1.2",
|
69
69
|
"chalk": "4.1.2",
|
@@ -102,7 +102,7 @@
|
|
102
102
|
"resolve.exports": "2.0.2",
|
103
103
|
"semver": "7.5.4",
|
104
104
|
"statuses": "2.0.1",
|
105
|
-
"typescript": "5.
|
105
|
+
"typescript": "5.2.2",
|
106
106
|
"undici": "6.19.2",
|
107
107
|
"yup": "0.32.9"
|
108
108
|
},
|
@@ -126,13 +126,13 @@
|
|
126
126
|
"@types/node": "18.19.24",
|
127
127
|
"@types/node-schedule": "2.1.7",
|
128
128
|
"@types/statuses": "2.0.1",
|
129
|
-
"eslint-config-custom": "0.0.0-
|
129
|
+
"eslint-config-custom": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525",
|
130
130
|
"supertest": "6.3.3",
|
131
|
-
"tsconfig": "0.0.0-
|
131
|
+
"tsconfig": "0.0.0-next.3c5bc3f35387771b185349533729e99e6e59c525"
|
132
132
|
},
|
133
133
|
"engines": {
|
134
134
|
"node": ">=18.0.0 <=20.x.x",
|
135
135
|
"npm": ">=6.0.0"
|
136
136
|
},
|
137
|
-
"gitHead": "
|
137
|
+
"gitHead": "3c5bc3f35387771b185349533729e99e6e59c525"
|
138
138
|
}
|