@strapi/core 0.0.0-experimental.1e4c115f717b021ca11c139584d4519db28ba786 → 0.0.0-experimental.1f56e9319665c8cc385eb5e4178ceb6741c6d490

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @strapi/core might be problematic. Click here for more details.

Files changed (230) hide show
  1. package/dist/Strapi.d.ts +1 -0
  2. package/dist/Strapi.d.ts.map +1 -1
  3. package/dist/Strapi.js +23 -2
  4. package/dist/Strapi.js.map +1 -1
  5. package/dist/Strapi.mjs +23 -2
  6. package/dist/Strapi.mjs.map +1 -1
  7. package/dist/constants.d.ts +3 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +6 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/constants.mjs +4 -0
  12. package/dist/constants.mjs.map +1 -0
  13. package/dist/core-api/controller/index.d.ts.map +1 -1
  14. package/dist/core-api/controller/index.js +2 -1
  15. package/dist/core-api/controller/index.js.map +1 -1
  16. package/dist/core-api/controller/index.mjs +2 -1
  17. package/dist/core-api/controller/index.mjs.map +1 -1
  18. package/dist/core-api/controller/transform.d.ts +3 -2
  19. package/dist/core-api/controller/transform.d.ts.map +1 -1
  20. package/dist/core-api/controller/transform.js +13 -3
  21. package/dist/core-api/controller/transform.js.map +1 -1
  22. package/dist/core-api/controller/transform.mjs +13 -3
  23. package/dist/core-api/controller/transform.mjs.map +1 -1
  24. package/dist/core-api/routes/index.d.ts.map +1 -1
  25. package/dist/core-api/routes/index.js +28 -9
  26. package/dist/core-api/routes/index.js.map +1 -1
  27. package/dist/core-api/routes/index.mjs +1 -1
  28. package/dist/core-api/routes/index.mjs.map +1 -1
  29. package/dist/core-api/routes/validation/attributes.d.ts +243 -90
  30. package/dist/core-api/routes/validation/attributes.d.ts.map +1 -1
  31. package/dist/core-api/routes/validation/attributes.js +541 -564
  32. package/dist/core-api/routes/validation/attributes.js.map +1 -1
  33. package/dist/core-api/routes/validation/attributes.mjs +505 -564
  34. package/dist/core-api/routes/validation/attributes.mjs.map +1 -1
  35. package/dist/core-api/routes/validation/common.d.ts +7 -5
  36. package/dist/core-api/routes/validation/common.d.ts.map +1 -1
  37. package/dist/core-api/routes/validation/common.js +29 -8
  38. package/dist/core-api/routes/validation/common.js.map +1 -1
  39. package/dist/core-api/routes/validation/common.mjs +6 -4
  40. package/dist/core-api/routes/validation/common.mjs.map +1 -1
  41. package/dist/core-api/routes/validation/component.d.ts +2 -10
  42. package/dist/core-api/routes/validation/component.d.ts.map +1 -1
  43. package/dist/core-api/routes/validation/component.js +3 -17
  44. package/dist/core-api/routes/validation/component.js.map +1 -1
  45. package/dist/core-api/routes/validation/component.mjs +3 -17
  46. package/dist/core-api/routes/validation/component.mjs.map +1 -1
  47. package/dist/core-api/routes/validation/constants.d.ts +6 -0
  48. package/dist/core-api/routes/validation/constants.d.ts.map +1 -1
  49. package/dist/core-api/routes/validation/constants.js +6 -1
  50. package/dist/core-api/routes/validation/constants.js.map +1 -1
  51. package/dist/core-api/routes/validation/constants.mjs +6 -1
  52. package/dist/core-api/routes/validation/constants.mjs.map +1 -1
  53. package/dist/core-api/routes/validation/content-type.d.ts +28 -71
  54. package/dist/core-api/routes/validation/content-type.d.ts.map +1 -1
  55. package/dist/core-api/routes/validation/content-type.js +67 -112
  56. package/dist/core-api/routes/validation/content-type.js.map +1 -1
  57. package/dist/core-api/routes/validation/content-type.mjs +36 -100
  58. package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
  59. package/dist/core-api/routes/validation/index.d.ts +1 -1
  60. package/dist/core-api/routes/validation/index.d.ts.map +1 -1
  61. package/dist/core-api/routes/validation/mappers.d.ts +105 -0
  62. package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
  63. package/dist/core-api/routes/validation/mappers.js +273 -0
  64. package/dist/core-api/routes/validation/mappers.js.map +1 -0
  65. package/dist/core-api/routes/validation/mappers.mjs +249 -0
  66. package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
  67. package/dist/core-api/routes/validation/utils.d.ts +47 -0
  68. package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
  69. package/dist/core-api/routes/validation/utils.js +128 -0
  70. package/dist/core-api/routes/validation/utils.js.map +1 -0
  71. package/dist/core-api/routes/validation/utils.mjs +106 -0
  72. package/dist/core-api/routes/validation/utils.mjs.map +1 -0
  73. package/dist/domain/content-type/index.d.ts.map +1 -1
  74. package/dist/domain/content-type/index.js +17 -1
  75. package/dist/domain/content-type/index.js.map +1 -1
  76. package/dist/domain/content-type/index.mjs +17 -1
  77. package/dist/domain/content-type/index.mjs.map +1 -1
  78. package/dist/ee/index.d.ts +6 -0
  79. package/dist/ee/index.d.ts.map +1 -1
  80. package/dist/ee/index.js +29 -3
  81. package/dist/ee/index.js.map +1 -1
  82. package/dist/ee/index.mjs +30 -4
  83. package/dist/ee/index.mjs.map +1 -1
  84. package/dist/ee/license.d.ts +3 -1
  85. package/dist/ee/license.d.ts.map +1 -1
  86. package/dist/ee/license.js +6 -1
  87. package/dist/ee/license.js.map +1 -1
  88. package/dist/ee/license.mjs +6 -2
  89. package/dist/ee/license.mjs.map +1 -1
  90. package/dist/factories.js +1 -1
  91. package/dist/factories.mjs +1 -1
  92. package/dist/index.js +1 -1
  93. package/dist/index.mjs +1 -1
  94. package/dist/loaders/plugins/index.js +1 -1
  95. package/dist/loaders/plugins/index.js.map +1 -1
  96. package/dist/loaders/plugins/index.mjs +1 -1
  97. package/dist/loaders/plugins/index.mjs.map +1 -1
  98. package/dist/middlewares/cors.d.ts +9 -1
  99. package/dist/middlewares/cors.d.ts.map +1 -1
  100. package/dist/middlewares/cors.js +39 -17
  101. package/dist/middlewares/cors.js.map +1 -1
  102. package/dist/middlewares/cors.mjs +39 -18
  103. package/dist/middlewares/cors.mjs.map +1 -1
  104. package/dist/migrations/first-published-at.d.ts +4 -0
  105. package/dist/migrations/first-published-at.d.ts.map +1 -0
  106. package/dist/migrations/first-published-at.js +51 -0
  107. package/dist/migrations/first-published-at.js.map +1 -0
  108. package/dist/migrations/first-published-at.mjs +49 -0
  109. package/dist/migrations/first-published-at.mjs.map +1 -0
  110. package/dist/migrations/index.d.ts.map +1 -1
  111. package/dist/migrations/index.js +5 -0
  112. package/dist/migrations/index.js.map +1 -1
  113. package/dist/migrations/index.mjs +5 -0
  114. package/dist/migrations/index.mjs.map +1 -1
  115. package/dist/package.json.js +17 -13
  116. package/dist/package.json.js.map +1 -1
  117. package/dist/package.json.mjs +17 -13
  118. package/dist/package.json.mjs.map +1 -1
  119. package/dist/providers/index.d.ts.map +1 -1
  120. package/dist/providers/index.js +2 -0
  121. package/dist/providers/index.js.map +1 -1
  122. package/dist/providers/index.mjs +2 -0
  123. package/dist/providers/index.mjs.map +1 -1
  124. package/dist/providers/session-manager.d.ts +3 -0
  125. package/dist/providers/session-manager.d.ts.map +1 -0
  126. package/dist/providers/session-manager.js +23 -0
  127. package/dist/providers/session-manager.js.map +1 -0
  128. package/dist/providers/session-manager.mjs +21 -0
  129. package/dist/providers/session-manager.mjs.map +1 -0
  130. package/dist/services/content-api/index.d.ts +1 -1
  131. package/dist/services/content-api/index.d.ts.map +1 -1
  132. package/dist/services/content-api/index.js +1 -1
  133. package/dist/services/content-api/index.js.map +1 -1
  134. package/dist/services/content-api/index.mjs +2 -2
  135. package/dist/services/content-api/index.mjs.map +1 -1
  136. package/dist/services/content-source-maps.d.ts +13 -0
  137. package/dist/services/content-source-maps.d.ts.map +1 -0
  138. package/dist/services/content-source-maps.js +108 -0
  139. package/dist/services/content-source-maps.js.map +1 -0
  140. package/dist/services/content-source-maps.mjs +106 -0
  141. package/dist/services/content-source-maps.mjs.map +1 -0
  142. package/dist/services/core-store.d.ts +2 -2
  143. package/dist/services/core-store.d.ts.map +1 -1
  144. package/dist/services/core-store.js.map +1 -1
  145. package/dist/services/core-store.mjs.map +1 -1
  146. package/dist/services/document-service/components.d.ts +31 -1
  147. package/dist/services/document-service/components.d.ts.map +1 -1
  148. package/dist/services/document-service/components.js +109 -0
  149. package/dist/services/document-service/components.js.map +1 -1
  150. package/dist/services/document-service/components.mjs +107 -1
  151. package/dist/services/document-service/components.mjs.map +1 -1
  152. package/dist/services/document-service/entries.d.ts.map +1 -1
  153. package/dist/services/document-service/entries.js +42 -0
  154. package/dist/services/document-service/entries.js.map +1 -1
  155. package/dist/services/document-service/entries.mjs +43 -1
  156. package/dist/services/document-service/entries.mjs.map +1 -1
  157. package/dist/services/document-service/first-published-at.d.ts +7 -0
  158. package/dist/services/document-service/first-published-at.d.ts.map +1 -0
  159. package/dist/services/document-service/first-published-at.js +31 -0
  160. package/dist/services/document-service/first-published-at.js.map +1 -0
  161. package/dist/services/document-service/first-published-at.mjs +28 -0
  162. package/dist/services/document-service/first-published-at.mjs.map +1 -0
  163. package/dist/services/document-service/internationalization.d.ts +6 -1
  164. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  165. package/dist/services/document-service/internationalization.js +32 -0
  166. package/dist/services/document-service/internationalization.js.map +1 -1
  167. package/dist/services/document-service/internationalization.mjs +32 -1
  168. package/dist/services/document-service/internationalization.mjs.map +1 -1
  169. package/dist/services/document-service/repository.d.ts.map +1 -1
  170. package/dist/services/document-service/repository.js +16 -8
  171. package/dist/services/document-service/repository.js.map +1 -1
  172. package/dist/services/document-service/repository.mjs +18 -10
  173. package/dist/services/document-service/repository.mjs.map +1 -1
  174. package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
  175. package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
  176. package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
  177. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
  178. package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
  179. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
  180. package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
  181. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
  182. package/dist/services/entity-validator/index.d.ts.map +1 -1
  183. package/dist/services/entity-validator/index.js +9 -0
  184. package/dist/services/entity-validator/index.js.map +1 -1
  185. package/dist/services/entity-validator/index.mjs +9 -0
  186. package/dist/services/entity-validator/index.mjs.map +1 -1
  187. package/dist/services/entity-validator/validators.d.ts +1 -0
  188. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  189. package/dist/services/entity-validator/validators.js +3 -0
  190. package/dist/services/entity-validator/validators.js.map +1 -1
  191. package/dist/services/entity-validator/validators.mjs +3 -0
  192. package/dist/services/entity-validator/validators.mjs.map +1 -1
  193. package/dist/services/metrics/index.d.ts +1 -1
  194. package/dist/services/metrics/index.d.ts.map +1 -1
  195. package/dist/services/metrics/index.js +11 -9
  196. package/dist/services/metrics/index.js.map +1 -1
  197. package/dist/services/metrics/index.mjs +11 -9
  198. package/dist/services/metrics/index.mjs.map +1 -1
  199. package/dist/services/metrics/middleware.d.ts +2 -1
  200. package/dist/services/metrics/middleware.d.ts.map +1 -1
  201. package/dist/services/metrics/middleware.js +2 -2
  202. package/dist/services/metrics/middleware.js.map +1 -1
  203. package/dist/services/metrics/middleware.mjs +2 -2
  204. package/dist/services/metrics/middleware.mjs.map +1 -1
  205. package/dist/services/metrics/sender.d.ts.map +1 -1
  206. package/dist/services/metrics/sender.js +4 -3
  207. package/dist/services/metrics/sender.js.map +1 -1
  208. package/dist/services/metrics/sender.mjs +4 -3
  209. package/dist/services/metrics/sender.mjs.map +1 -1
  210. package/dist/services/session-manager.d.ts +167 -0
  211. package/dist/services/session-manager.d.ts.map +1 -0
  212. package/dist/services/session-manager.js +529 -0
  213. package/dist/services/session-manager.js.map +1 -0
  214. package/dist/services/session-manager.mjs +526 -0
  215. package/dist/services/session-manager.mjs.map +1 -0
  216. package/dist/services/utils/conditional-fields.d.ts +3 -0
  217. package/dist/services/utils/conditional-fields.d.ts.map +1 -0
  218. package/dist/services/utils/conditional-fields.js +22 -0
  219. package/dist/services/utils/conditional-fields.js.map +1 -0
  220. package/dist/services/utils/conditional-fields.mjs +20 -0
  221. package/dist/services/utils/conditional-fields.mjs.map +1 -0
  222. package/dist/utils/fetch.d.ts +5 -1
  223. package/dist/utils/fetch.d.ts.map +1 -1
  224. package/dist/utils/fetch.js +8 -4
  225. package/dist/utils/fetch.js.map +1 -1
  226. package/dist/utils/fetch.mjs +8 -4
  227. package/dist/utils/fetch.mjs.map +1 -1
  228. package/dist/utils/transform-content-types-to-models.d.ts +197 -0
  229. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  230. package/package.json +17 -13
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var strapiUtils = require('@strapi/utils');
4
+ var z = require('zod/v4');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
24
+
25
+ // Schema generation happens on-demand when schemas don't exist in the registry
26
+ /**
27
+ * Safely adds or updates a schema in Zod's global registry.
28
+ *
29
+ * If a schema with the given `id` already exists, it will be removed before adding the new one.
30
+ *
31
+ * This is useful for hot-reloading or preventing issues with cyclical dependencies.
32
+ *
33
+ * @param id - The unique identifier for the schema in the global registry.
34
+ * @param schema - The Zod schema to register.
35
+ * @example
36
+ * ```typescript
37
+ * safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
38
+ * ```
39
+ */ const safeGlobalRegistrySet = (id, schema)=>{
40
+ try {
41
+ const { _idmap: idMap } = z__namespace.globalRegistry;
42
+ const transformedId = strapiUtils.transformUidToValidOpenApiName(id);
43
+ const isReplacing = idMap.has(transformedId);
44
+ if (isReplacing) {
45
+ // Remove existing schema to prevent conflicts
46
+ idMap.delete(transformedId);
47
+ }
48
+ // Register the new schema with the transformed ID
49
+ strapi.log.debug(`${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`);
50
+ z__namespace.globalRegistry.add(schema, {
51
+ id: transformedId
52
+ });
53
+ } catch (error) {
54
+ strapi.log.error(`Schema registration failed: Failed to register schema ${id} in global registry`);
55
+ throw error;
56
+ }
57
+ };
58
+ /**
59
+ * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
60
+ *
61
+ * If a schema with the given `id` already exists in the global registry, it returns the existing schema.
62
+ *
63
+ * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,
64
+ * and then replaces the temporary schema with the actual one in the registry.
65
+ *
66
+ * This prevents infinite loops in cases of cyclical dependencies.
67
+ *
68
+ * @param id - The unique identifier for the schema in the global registry.
69
+ * @param callback - A function that returns the Zod schema to be created and registered.
70
+ * @returns The created or retrieved Zod schema.
71
+ * @example
72
+ * ```typescript
73
+ * const CategorySchema = safeSchemaCreation("Category", () =>
74
+ * z.object({
75
+ * name: z.string(),
76
+ * products: z.array(safeSchemaCreation("Product", () =>
77
+ * z.object({
78
+ * name: z.string(),
79
+ * category: z.lazy(() => CategorySchema) // Cyclical reference
80
+ * })
81
+ * ))
82
+ * })
83
+ * );
84
+ * ```
85
+ */ const safeSchemaCreation = (id, callback)=>{
86
+ try {
87
+ const { _idmap: idMap } = z__namespace.globalRegistry;
88
+ const transformedId = strapiUtils.transformUidToValidOpenApiName(id);
89
+ // Return existing schema if already registered
90
+ const mapItem = idMap.get(transformedId);
91
+ if (mapItem) {
92
+ // Schema already exists, return it silently
93
+ return mapItem;
94
+ }
95
+ strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
96
+ // Determine if this is a built-in schema or user content
97
+ const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
98
+ if (isBuiltInSchema) {
99
+ // Built-in schemas keep at debug level to avoid clutter
100
+ strapi.log.debug(`Initializing validation schema for ${transformedId}`);
101
+ } else {
102
+ // User content
103
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
104
+ strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
105
+ }
106
+ // Temporary any placeholder before replacing with the actual schema type
107
+ // Used to prevent infinite loops in cyclical data structures
108
+ safeGlobalRegistrySet(id, z__namespace.any());
109
+ // Generate the actual schema using the callback
110
+ const schema = callback();
111
+ // Replace the placeholder with the real schema
112
+ safeGlobalRegistrySet(id, schema);
113
+ // Show completion for user content only
114
+ if (!isBuiltInSchema) {
115
+ const fieldCount = Object.keys(schema?._def?.shape || {}).length || 0;
116
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
117
+ strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
118
+ }
119
+ return schema;
120
+ } catch (error) {
121
+ strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
122
+ throw error;
123
+ }
124
+ };
125
+
126
+ exports.safeGlobalRegistrySet = safeGlobalRegistrySet;
127
+ exports.safeSchemaCreation = safeSchemaCreation;
128
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n // Built-in schemas keep at debug level to avoid clutter\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n // User content\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` ✅ \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","strapi","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,aAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,0CAA+BP,CAAAA,EAAAA,CAAAA;QAErD,MAAMQ,WAAAA,GAAcL,KAAMM,CAAAA,GAAG,CAACH,aAAAA,CAAAA;AAE9B,QAAA,IAAIE,WAAa,EAAA;;AAEfL,YAAAA,KAAAA,CAAMO,MAAM,CAACJ,aAAAA,CAAAA;AACf;;AAGAK,QAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CACd,CAAC,EAA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AAA,OAAO,CAAC,UAAA,EAAY,OACpBC,IAAI,EAAA;YACPb,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC,CAAC,qCAAqC,EAAES,UAAW,CAAA,CAAC,CAAC,CAAA;AACxE;;;QAIAvB,qBAAsBC,CAAAA,EAAAA,EAAII,aAAEqB,GAAG,EAAA,CAAA;;AAG/B,QAAA,MAAMxB,MAASgB,GAAAA,QAAAA,EAAAA;;AAGflB,QAAAA,qBAAAA,CAAsBC,EAAIC,EAAAA,MAAAA,CAAAA;;AAG1B,QAAA,IAAI,CAACmB,eAAiB,EAAA;YACpB,MAAMM,UAAAA,GAAaC,MAAOC,CAAAA,IAAI,CAAE3B,MAAgB4B,EAAAA,IAAAA,EAAMC,KAAS,IAAA,EAAIC,CAAAA,CAAAA,MAAM,IAAI,CAAA;AAC7E,YAAA,MAAMT,UAAahB,GAAAA,aAAAA,CAChBiB,OAAO,CAAC,YAAY,EACpBA,CAAAA,CAAAA,OAAO,CAAC,OAAA,EAAS,EACjBA,CAAAA,CAAAA,OAAO,CAAC,UAAA,EAAY,OACpBC,IAAI,EAAA;AACPb,YAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CAAC,CAAC,MAAM,EAAES,UAAAA,CAAW,sBAAsB,EAAEI,UAAW,CAAA,OAAO,CAAC,CAAA;AAClF;QAEA,OAAOzB,MAAAA;AACT,KAAA,CAAE,OAAOc,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK,CAAC,CAAC,gDAAgD,EAAEf,GAAG,CAAC,CAAA;QAExE,MAAMe,KAAAA;AACR;AACF;;;;;"}
@@ -0,0 +1,106 @@
1
+ import { transformUidToValidOpenApiName } from '@strapi/utils';
2
+ import * as z from 'zod/v4';
3
+
4
+ // Schema generation happens on-demand when schemas don't exist in the registry
5
+ /**
6
+ * Safely adds or updates a schema in Zod's global registry.
7
+ *
8
+ * If a schema with the given `id` already exists, it will be removed before adding the new one.
9
+ *
10
+ * This is useful for hot-reloading or preventing issues with cyclical dependencies.
11
+ *
12
+ * @param id - The unique identifier for the schema in the global registry.
13
+ * @param schema - The Zod schema to register.
14
+ * @example
15
+ * ```typescript
16
+ * safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
17
+ * ```
18
+ */ const safeGlobalRegistrySet = (id, schema)=>{
19
+ try {
20
+ const { _idmap: idMap } = z.globalRegistry;
21
+ const transformedId = transformUidToValidOpenApiName(id);
22
+ const isReplacing = idMap.has(transformedId);
23
+ if (isReplacing) {
24
+ // Remove existing schema to prevent conflicts
25
+ idMap.delete(transformedId);
26
+ }
27
+ // Register the new schema with the transformed ID
28
+ strapi.log.debug(`${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`);
29
+ z.globalRegistry.add(schema, {
30
+ id: transformedId
31
+ });
32
+ } catch (error) {
33
+ strapi.log.error(`Schema registration failed: Failed to register schema ${id} in global registry`);
34
+ throw error;
35
+ }
36
+ };
37
+ /**
38
+ * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
39
+ *
40
+ * If a schema with the given `id` already exists in the global registry, it returns the existing schema.
41
+ *
42
+ * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,
43
+ * and then replaces the temporary schema with the actual one in the registry.
44
+ *
45
+ * This prevents infinite loops in cases of cyclical dependencies.
46
+ *
47
+ * @param id - The unique identifier for the schema in the global registry.
48
+ * @param callback - A function that returns the Zod schema to be created and registered.
49
+ * @returns The created or retrieved Zod schema.
50
+ * @example
51
+ * ```typescript
52
+ * const CategorySchema = safeSchemaCreation("Category", () =>
53
+ * z.object({
54
+ * name: z.string(),
55
+ * products: z.array(safeSchemaCreation("Product", () =>
56
+ * z.object({
57
+ * name: z.string(),
58
+ * category: z.lazy(() => CategorySchema) // Cyclical reference
59
+ * })
60
+ * ))
61
+ * })
62
+ * );
63
+ * ```
64
+ */ const safeSchemaCreation = (id, callback)=>{
65
+ try {
66
+ const { _idmap: idMap } = z.globalRegistry;
67
+ const transformedId = transformUidToValidOpenApiName(id);
68
+ // Return existing schema if already registered
69
+ const mapItem = idMap.get(transformedId);
70
+ if (mapItem) {
71
+ // Schema already exists, return it silently
72
+ return mapItem;
73
+ }
74
+ strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
75
+ // Determine if this is a built-in schema or user content
76
+ const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
77
+ if (isBuiltInSchema) {
78
+ // Built-in schemas keep at debug level to avoid clutter
79
+ strapi.log.debug(`Initializing validation schema for ${transformedId}`);
80
+ } else {
81
+ // User content
82
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
83
+ strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
84
+ }
85
+ // Temporary any placeholder before replacing with the actual schema type
86
+ // Used to prevent infinite loops in cyclical data structures
87
+ safeGlobalRegistrySet(id, z.any());
88
+ // Generate the actual schema using the callback
89
+ const schema = callback();
90
+ // Replace the placeholder with the real schema
91
+ safeGlobalRegistrySet(id, schema);
92
+ // Show completion for user content only
93
+ if (!isBuiltInSchema) {
94
+ const fieldCount = Object.keys(schema?._def?.shape || {}).length || 0;
95
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
96
+ strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
97
+ }
98
+ return schema;
99
+ } catch (error) {
100
+ strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
101
+ throw error;
102
+ }
103
+ };
104
+
105
+ export { safeGlobalRegistrySet, safeSchemaCreation };
106
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n // Built-in schemas keep at debug level to avoid clutter\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n // User content\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` ✅ \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","strapi","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,EAAEC,cAAc;AAE1C,QAAA,MAAMC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AAA;QAExE,MAAMe,KAAAA;AACR;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAUF,QAAA,MAAM,iBAAiB,QAAS,MAAM,cAAc,qBAAqB,0DAiCxE,CAAC;AAyDF,QAAA,MAAM,WAAW,WAAY,OAAO,WAAW,WAAW,MAAM,WAK/D,CAAC;AAmBF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAWF,QAAA,MAAM,iBAAiB,QAAS,MAAM,cAAc,qBAAqB,0DAmCxE,CAAC;AA0EF,QAAA,MAAM,WAAW,WAAY,OAAO,WAAW,WAAW,MAAM,WAK/D,CAAC;AAmBF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
@@ -5,7 +5,7 @@ var _ = require('lodash');
5
5
  var strapiUtils = require('@strapi/utils');
6
6
  var validator = require('./validator.js');
7
7
 
8
- const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
8
+ const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
9
9
  const createContentType = (uid, definition)=>{
10
10
  try {
11
11
  validator.validateContentTypeDefinition(definition);
@@ -31,6 +31,7 @@ const createContentType = (uid, definition)=>{
31
31
  // In case it is not enabled, value will be always published, and it will not contain a draft
32
32
  addDraftAndPublish(schema);
33
33
  addCreatorFields(schema);
34
+ addFirstPublishedAt(schema);
34
35
  return schema;
35
36
  };
36
37
  const addTimestamps = (schema)=>{
@@ -59,6 +60,21 @@ const addDraftAndPublish = (schema)=>{
59
60
  }
60
61
  };
61
62
  };
63
+ const addFirstPublishedAt = (schema)=>{
64
+ const isEnabled = strapiUtils.contentTypes.hasFirstPublishedAtField(schema);
65
+ // Note: As an expertimental feature, we are okay if this data is deleted if this feature is
66
+ // switched off. Once "preserve_attributes" come into play, this will be updated.
67
+ if (isEnabled) {
68
+ strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
69
+ schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
70
+ type: 'datetime',
71
+ configurable: false,
72
+ writable: true,
73
+ visible: false,
74
+ private: !isEnabled
75
+ };
76
+ }
77
+ };
62
78
  const addCreatorFields = (schema)=>{
63
79
  const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
64
80
  schema.attributes[CREATED_BY_ATTRIBUTE] = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","private","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,yBAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,uCAA8BD,CAAAA,UAAAA,CAAAA;AAChC,KAAA,CAAE,OAAOE,CAA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UAAU,CAACjB,CAAAA,CAAEkB,SAAS,CAACF,QAAAA,CAAAA,CAAAA;AACrD;AAEA,MAAMzB,aAAa,CAAC4B,KAAAA,GAAAA;AAClB,IAAA,MAAMrC,SAASkB,CAAEf,CAAAA,SAAS,CACxBe,CAAEoB,CAAAA,IAAI,CAACD,KAAO,EAAA;AACZ,QAAA,YAAA;AACA,QAAA,gBAAA;AACA,QAAA,MAAA;AACA,QAAA,SAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAGHrC,IAAAA,MAAAA,CAAOO,IAAI,GAAG8B,KAAM9B,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,yBAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,uCAA8BD,CAAAA,UAAAA,CAAAA;AAChC,KAAA,CAAE,OAAOE,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,eAAIC,CAAAA,eAAe,EAAE;YACpC,MAAM,IAAIC,KAAM,CAAA,CAAC,uCAAuC,EAAEN,GAAI,CAAA,IAAI,EAAEG,CAAAA,CAAEI,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OAAS,EAAA,KAAA;QACTc,YAAc,EAAA,KAAA;QACdL,OAASC,EAAAA;AACX,KAAA;AACF,CAAA;AAEMK,MAAAA,WAAAA,GAAc,CAACvC,MAA4BwC,EAAAA,MAAAA,GAAAA;AAC/C,IAAA,MAAM9B,SAAYV,GAAAA,MAAAA,CAAOW,IAAI,CAACC,YAAY;IAC1C,MAAM6B,QAAAA,GAAWD,SAAS,CAAC,EAAEA,OAAO,CAAC,EAAE9B,SAAU,CAAA,CAAC,GAAGA,SAAAA;IAErD,OAAOV,MAAAA,CAAOyC,QAAQ,IAAItB,CAAAA,CAAEuB,UAAU,CAACvB,CAAAA,CAAEwB,SAAS,CAACF,QAAAA,CAAAA,CAAAA;AACrD;AAEA,MAAMhC,aAAa,CAACmC,KAAAA,GAAAA;AAClB,IAAA,MAAM5C,SAASmB,CAAEhB,CAAAA,SAAS,CACxBgB,CAAE0B,CAAAA,IAAI,CAACD,KAAO,EAAA;AACZ,QAAA,YAAA;AACA,QAAA,gBAAA;AACA,QAAA,MAAA;AACA,QAAA,SAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAGH5C,IAAAA,MAAAA,CAAOO,IAAI,GAAGqC,KAAMrC,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;;"}
@@ -3,7 +3,7 @@ import _ from 'lodash';
3
3
  import { contentTypes, yup } from '@strapi/utils';
4
4
  import { validateContentTypeDefinition } from './validator.mjs';
5
5
 
6
- const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
6
+ const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
7
7
  const createContentType = (uid, definition)=>{
8
8
  try {
9
9
  validateContentTypeDefinition(definition);
@@ -29,6 +29,7 @@ const createContentType = (uid, definition)=>{
29
29
  // In case it is not enabled, value will be always published, and it will not contain a draft
30
30
  addDraftAndPublish(schema);
31
31
  addCreatorFields(schema);
32
+ addFirstPublishedAt(schema);
32
33
  return schema;
33
34
  };
34
35
  const addTimestamps = (schema)=>{
@@ -57,6 +58,21 @@ const addDraftAndPublish = (schema)=>{
57
58
  }
58
59
  };
59
60
  };
61
+ const addFirstPublishedAt = (schema)=>{
62
+ const isEnabled = contentTypes.hasFirstPublishedAtField(schema);
63
+ // Note: As an expertimental feature, we are okay if this data is deleted if this feature is
64
+ // switched off. Once "preserve_attributes" come into play, this will be updated.
65
+ if (isEnabled) {
66
+ strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
67
+ schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
68
+ type: 'datetime',
69
+ configurable: false,
70
+ writable: true,
71
+ visible: false,
72
+ private: !isEnabled
73
+ };
74
+ }
75
+ };
60
76
  const addCreatorFields = (schema)=>{
61
77
  const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
62
78
  schema.attributes[CREATED_BY_ATTRIBUTE] = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","private","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,aAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,6BAA8BD,CAAAA,UAAAA,CAAAA;AAChC,KAAA,CAAE,OAAOE,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,GAAIC,CAAAA,eAAe,EAAE;YACpC,MAAM,IAAIC,KAAM,CAAA,CAAC,uCAAuC,EAAEN,GAAI,CAAA,IAAI,EAAEG,CAAAA,CAAEI,MAAM,CAAC,CAAC,CAAA;AAChF;QAEA,MAAMJ,CAAAA;AACR;IAEA,MAAM,EAAEK,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,SAAUV,CA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A,eAAA;AACA,QAAA,YAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAGHrC,IAAAA,MAAAA,CAAOO,IAAI,GAAG8B,KAAM9B,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,aAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,6BAA8BD,CAAAA,UAAAA,CAAAA;AAChC,KAAA,CAAE,OAAOE,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,GAAIC,CAAAA,eAAe,EAAE;YACpC,MAAM,IAAIC,KAAM,CAAA,CAAC,uCAAuC,EAAEN,GAAI,CAAA,IAAI,EAAEG,CAAAA,CAAEI,MAAM,CAAC,CAAC,CAAA;AAChF;QAEA,MAAMJ,CAAAA;AACR;IAEA,MAAM,EAAEK,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,SAAUV,CAAAA,UAAAA,CAAAA;;IAGlDW,MAAOC,CAAAA,MAAM,CAACL,MAAQ,EAAA;AACpBR,QAAAA,GAAAA;QACAc,SAAW,EAAA,aAAA;QACXC,IAAMP,EAAAA,MAAAA,CAAOO,IAAI,I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AAU,CAAA,CAAC,GAAGA,SAAAA;IAErD,OAAOV,MAAAA,CAAOyC,QAAQ,IAAItB,CAAAA,CAAEuB,UAAU,CAACvB,CAAAA,CAAEwB,SAAS,CAACF,QAAAA,CAAAA,CAAAA;AACrD;AAEA,MAAMhC,aAAa,CAACmC,KAAAA,GAAAA;AAClB,IAAA,MAAM5C,SAASmB,CAAEhB,CAAAA,SAAS,CACxBgB,CAAE0B,CAAAA,IAAI,CAACD,KAAO,EAAA;AACZ,QAAA,YAAA;AACA,QAAA,gBAAA;AACA,QAAA,MAAA;AACA,QAAA,SAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAGH5C,IAAAA,MAAAA,CAAOO,IAAI,GAAGqC,KAAMrC,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;"}
@@ -4,9 +4,15 @@ declare const _default: Readonly<{
4
4
  checkLicense: ({ strapi }: {
5
5
  strapi: Core.Strapi;
6
6
  }) => Promise<void>;
7
+ getTrialEndDate: ({ strapi, }: {
8
+ strapi: Core.Strapi;
9
+ }) => Promise<{
10
+ trialEndsAt: string;
11
+ } | null>;
7
12
  readonly isEE: boolean;
8
13
  readonly seats: number | undefined;
9
14
  readonly type: string | undefined;
15
+ readonly isTrial: boolean;
10
16
  features: Readonly<{
11
17
  list: () => {
12
18
  [key: string]: any;
@@ -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;;;;;;;;;;;;;;;;;;iCA0Pb,MAAM;;;AAnBnC,wBAqBG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ee/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;iCAqSb,MAAM;;;AAxBnC,wBA0BG"}
package/dist/ee/index.js CHANGED
@@ -1,20 +1,27 @@
1
1
  'use strict';
2
2
 
3
3
  var fp = require('lodash/fp');
4
+ var fetch = require('../utils/fetch.js');
4
5
  var license = require('./license.js');
5
6
  var cron = require('../utils/cron.js');
6
7
 
7
8
  const ONE_MINUTE = 1000 * 60;
8
9
  const ee = {
9
10
  enabled: false,
10
- licenseInfo: {}
11
+ licenseInfo: {
12
+ isTrial: false
13
+ }
11
14
  };
12
15
  const disable = (message)=>{
13
16
  // Prevent emitting ee.disable if it was already disabled
14
17
  const shouldEmitEvent = ee.enabled !== false;
15
18
  ee.logger?.warn(`${message} Switching to CE.`);
16
- // Only keep the license key for potential re-enabling during a later check
17
- ee.licenseInfo = fp.pick('licenseKey', ee.licenseInfo);
19
+ // Only keep the license key and isTrial for potential re-enabling during a later check
20
+ ee.licenseInfo = fp.pick([
21
+ 'licenseKey',
22
+ 'isTrial'
23
+ ], ee.licenseInfo);
24
+ ee.licenseInfo.isTrial = false;
18
25
  ee.enabled = false;
19
26
  if (shouldEmitEvent) {
20
27
  // Notify EE features that they should be disabled
@@ -163,6 +170,21 @@ const checkLicense = async ({ strapi: strapi1 })=>{
163
170
  validateInfo();
164
171
  }
165
172
  };
173
+ const getTrialEndDate = async ({ strapi: strapi1 })=>{
174
+ const silentFetch = fetch.createStrapiFetch(strapi1, {
175
+ logs: false
176
+ });
177
+ const res = await silentFetch(`${license.LICENSE_REGISTRY_URI}/api/licenses/${ee.licenseInfo.licenseKey}/trial-countdown`, {
178
+ method: 'GET',
179
+ headers: {
180
+ 'Content-Type': 'application/json'
181
+ }
182
+ }).catch(()=>{
183
+ throw new license.LicenseCheckError('Could not proceed to retrieve the trial time left for your license.', true);
184
+ });
185
+ const data = await res.json();
186
+ return data;
187
+ };
166
188
  const list = ()=>{
167
189
  return ee.licenseInfo.features?.map((feature)=>typeof feature === 'object' ? feature : {
168
190
  name: feature
@@ -172,6 +194,7 @@ const get = (featureName)=>list().find((feature)=>feature.name === featureName);
172
194
  var index = Object.freeze({
173
195
  init,
174
196
  checkLicense,
197
+ getTrialEndDate,
175
198
  get isEE () {
176
199
  return ee.enabled;
177
200
  },
@@ -181,6 +204,9 @@ var index = Object.freeze({
181
204
  get type () {
182
205
  return ee.licenseInfo.type;
183
206
  },
207
+ get isTrial () {
208
+ return ee.licenseInfo.isTrial;
209
+ },
184
210
  features: Object.freeze({
185
211
  list,
186
212
  get,
@@ -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\n strapi.cron.add({\n onlineUpdate: {\n task: () => onlineUpdate({ strapi }),\n options: shiftCronExpression('0 0 */12 * * *'),\n },\n });\n } else {\n if (!ee.licenseInfo.expireAt) {\n return disable('Your license does not have offline support.');\n }\n\n validateInfo();\n }\n};\n\nconst list = () => {\n return (\n ee.licenseInfo.features?.map((feature) =>\n typeof feature === 'object' ? feature : { name: feature }\n ) || []\n );\n};\n\nconst get = (featureName: string) => list().find((feature) => feature.name === featureName);\n\nexport default Object.freeze({\n init,\n checkLicense,\n\n get isEE() {\n return ee.enabled;\n },\n\n get seats() {\n return ee.licenseInfo.seats;\n },\n\n get type() {\n return ee.licenseInfo.type;\n },\n\n features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["ONE_MINUTE","ee","enabled","licenseInfo","disable","message","shouldEmitEvent","logger","warn","pick","strapi","eventHub","emit","enable","initialized","init","licenseDir","process","env","STRAPI_DISABLE_EE","toLowerCase","license","STRAPI_LICENSE","readLicense","verifyLicense","error","Error","onlineUpdate","get","commit","rollback","db","transaction","storedInfo","queryBuilder","where","key","select","first","transacting","forUpdate","execute","then","result","JSON","parse","value","shouldContactRegistry","lastCheckAt","Date","now","fallback","LicenseCheckError","shouldFallback","licenseKey","fetchLicense","config","catch","newLicenseInfo","licenseInfoChanged","isEqual","features","seats","type","wasEnabled","validateInfo","query","insert","stringify","update","expireAt","expirationTime","getTime","checkLicense","shouldStayOffline","STRAPI_DISABLE_LICENSE_PING","cron","add","task","options","shiftCronExpression","list","map","feature","name","featureName","find","Object","freeze","isEE","isEnabled","undefined"],"mappings":";;;;;;AAOA,MAAMA,aAAa,IAAO,GAAA,EAAA;AAc1B,MAAMC,EAAS,GAAA;IACbC,OAAS,EAAA,KAAA;AACTC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEA,MAAMC,UAAU,CAACC,OAAAA,GAAAA;;IAEf,MAAMC,eAAAA,GAAkBL,EAAGC,CAAAA,OAAO,KAAK,KAAA;AAEvCD,IAAAA,EAAAA,CAAGM,MAAM,EAAEC,IAAAA,CAAK,CAAC,EAAEH,OAAAA,CAAQ,iBAAiB,CAAC,CAAA;;AAE7CJ,IAAAA,EAAAA,CAAGE,WAAW,GAAGM,OAAK,CAAA,YAAA,EAAcR,GAAGE,WAAW,CAAA;AAElDF,IAAAA,EAAAA,CAAGC,OAAO,GAAG,KAAA;AAEb,IAAA,IAAII,eAAiB,EAAA;;QAEnBI,MAAOC,CAAAA,QAAQ,CAACC,IAAI,CAAC,YAAA,CAAA;AACvB;AACF,CAAA;AAEA,MAAMC,MAAS,GAAA,IAAA;;IAEb,MAAMP,eAAAA,GAAkBL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A,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.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';\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;IAC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