@strapi/core 0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6 → 0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8

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 (129) hide show
  1. package/dist/Strapi.d.ts.map +1 -1
  2. package/dist/Strapi.js +2 -0
  3. package/dist/Strapi.js.map +1 -1
  4. package/dist/Strapi.mjs +2 -0
  5. package/dist/Strapi.mjs.map +1 -1
  6. package/dist/core-api/routes/index.d.ts +4 -22
  7. package/dist/core-api/routes/index.d.ts.map +1 -1
  8. package/dist/core-api/routes/index.js +150 -8
  9. package/dist/core-api/routes/index.js.map +1 -1
  10. package/dist/core-api/routes/index.mjs +131 -8
  11. package/dist/core-api/routes/index.mjs.map +1 -1
  12. package/dist/core-api/routes/validation/attributes.d.ts +244 -0
  13. package/dist/core-api/routes/validation/attributes.d.ts.map +1 -0
  14. package/dist/core-api/routes/validation/attributes.js +560 -0
  15. package/dist/core-api/routes/validation/attributes.js.map +1 -0
  16. package/dist/core-api/routes/validation/attributes.mjs +521 -0
  17. package/dist/core-api/routes/validation/attributes.mjs.map +1 -0
  18. package/dist/core-api/routes/validation/common.d.ts +105 -0
  19. package/dist/core-api/routes/validation/common.d.ts.map +1 -0
  20. package/dist/core-api/routes/validation/common.js +116 -0
  21. package/dist/core-api/routes/validation/common.js.map +1 -0
  22. package/dist/core-api/routes/validation/common.mjs +95 -0
  23. package/dist/core-api/routes/validation/common.mjs.map +1 -0
  24. package/dist/core-api/routes/validation/component.d.ts +34 -0
  25. package/dist/core-api/routes/validation/component.d.ts.map +1 -0
  26. package/dist/core-api/routes/validation/component.js +45 -0
  27. package/dist/core-api/routes/validation/component.js.map +1 -0
  28. package/dist/core-api/routes/validation/component.mjs +43 -0
  29. package/dist/core-api/routes/validation/component.mjs.map +1 -0
  30. package/dist/core-api/routes/validation/constants.d.ts +8 -0
  31. package/dist/core-api/routes/validation/constants.d.ts.map +1 -0
  32. package/dist/core-api/routes/validation/constants.js +18 -0
  33. package/dist/core-api/routes/validation/constants.js.map +1 -0
  34. package/dist/core-api/routes/validation/constants.mjs +16 -0
  35. package/dist/core-api/routes/validation/constants.mjs.map +1 -0
  36. package/dist/core-api/routes/validation/content-type.d.ts +128 -0
  37. package/dist/core-api/routes/validation/content-type.d.ts.map +1 -0
  38. package/dist/core-api/routes/validation/content-type.js +201 -0
  39. package/dist/core-api/routes/validation/content-type.js.map +1 -0
  40. package/dist/core-api/routes/validation/content-type.mjs +180 -0
  41. package/dist/core-api/routes/validation/content-type.mjs.map +1 -0
  42. package/dist/core-api/routes/validation/index.d.ts +5 -0
  43. package/dist/core-api/routes/validation/index.d.ts.map +1 -0
  44. package/dist/core-api/routes/validation/mappers.d.ts +105 -0
  45. package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
  46. package/dist/core-api/routes/validation/mappers.js +238 -0
  47. package/dist/core-api/routes/validation/mappers.js.map +1 -0
  48. package/dist/core-api/routes/validation/mappers.mjs +214 -0
  49. package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
  50. package/dist/core-api/routes/validation/utils.d.ts +47 -0
  51. package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
  52. package/dist/core-api/routes/validation/utils.js +112 -0
  53. package/dist/core-api/routes/validation/utils.js.map +1 -0
  54. package/dist/core-api/routes/validation/utils.mjs +90 -0
  55. package/dist/core-api/routes/validation/utils.mjs.map +1 -0
  56. package/dist/domain/module/index.d.ts.map +1 -1
  57. package/dist/domain/module/index.js +3 -0
  58. package/dist/domain/module/index.js.map +1 -1
  59. package/dist/domain/module/index.mjs +3 -0
  60. package/dist/domain/module/index.mjs.map +1 -1
  61. package/dist/factories.d.ts +3 -1
  62. package/dist/factories.d.ts.map +1 -1
  63. package/dist/factories.js +10 -2
  64. package/dist/factories.js.map +1 -1
  65. package/dist/factories.mjs +10 -3
  66. package/dist/factories.mjs.map +1 -1
  67. package/dist/middlewares/cors.d.ts +9 -1
  68. package/dist/middlewares/cors.d.ts.map +1 -1
  69. package/dist/middlewares/cors.js +39 -17
  70. package/dist/middlewares/cors.js.map +1 -1
  71. package/dist/middlewares/cors.mjs +39 -18
  72. package/dist/middlewares/cors.mjs.map +1 -1
  73. package/dist/package.json.js +15 -12
  74. package/dist/package.json.js.map +1 -1
  75. package/dist/package.json.mjs +15 -12
  76. package/dist/package.json.mjs.map +1 -1
  77. package/dist/services/document-service/entries.d.ts.map +1 -1
  78. package/dist/services/document-service/entries.js.map +1 -1
  79. package/dist/services/document-service/entries.mjs.map +1 -1
  80. package/dist/services/document-service/internationalization.d.ts +6 -1
  81. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  82. package/dist/services/document-service/internationalization.js +32 -0
  83. package/dist/services/document-service/internationalization.js.map +1 -1
  84. package/dist/services/document-service/internationalization.mjs +32 -1
  85. package/dist/services/document-service/internationalization.mjs.map +1 -1
  86. package/dist/services/document-service/repository.d.ts.map +1 -1
  87. package/dist/services/document-service/repository.js +5 -4
  88. package/dist/services/document-service/repository.js.map +1 -1
  89. package/dist/services/document-service/repository.mjs +6 -5
  90. package/dist/services/document-service/repository.mjs.map +1 -1
  91. package/dist/services/entity-validator/index.d.ts.map +1 -1
  92. package/dist/services/entity-validator/index.js +9 -0
  93. package/dist/services/entity-validator/index.js.map +1 -1
  94. package/dist/services/entity-validator/index.mjs +9 -0
  95. package/dist/services/entity-validator/index.mjs.map +1 -1
  96. package/dist/services/entity-validator/validators.d.ts +1 -0
  97. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  98. package/dist/services/entity-validator/validators.js.map +1 -1
  99. package/dist/services/entity-validator/validators.mjs.map +1 -1
  100. package/dist/services/metrics/index.d.ts +1 -1
  101. package/dist/services/metrics/index.d.ts.map +1 -1
  102. package/dist/services/metrics/index.js +9 -8
  103. package/dist/services/metrics/index.js.map +1 -1
  104. package/dist/services/metrics/index.mjs +9 -8
  105. package/dist/services/metrics/index.mjs.map +1 -1
  106. package/dist/services/metrics/sender.d.ts.map +1 -1
  107. package/dist/services/metrics/sender.js +2 -2
  108. package/dist/services/metrics/sender.js.map +1 -1
  109. package/dist/services/metrics/sender.mjs +2 -2
  110. package/dist/services/metrics/sender.mjs.map +1 -1
  111. package/dist/services/server/register-routes.js +22 -2
  112. package/dist/services/server/register-routes.js.map +1 -1
  113. package/dist/services/server/register-routes.mjs +22 -2
  114. package/dist/services/server/register-routes.mjs.map +1 -1
  115. package/dist/services/server/routing.d.ts +10 -0
  116. package/dist/services/server/routing.d.ts.map +1 -1
  117. package/dist/services/server/routing.js +7 -1
  118. package/dist/services/server/routing.js.map +1 -1
  119. package/dist/services/server/routing.mjs +7 -1
  120. package/dist/services/server/routing.mjs.map +1 -1
  121. package/dist/services/utils/conditional-fields.d.ts +3 -0
  122. package/dist/services/utils/conditional-fields.d.ts.map +1 -0
  123. package/dist/services/utils/conditional-fields.js +22 -0
  124. package/dist/services/utils/conditional-fields.js.map +1 -0
  125. package/dist/services/utils/conditional-fields.mjs +20 -0
  126. package/dist/services/utils/conditional-fields.mjs.map +1 -0
  127. package/dist/utils/transform-content-types-to-models.d.ts +196 -0
  128. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  129. package/package.json +15 -12
@@ -23,6 +23,42 @@ const defaults = {
23
23
  ],
24
24
  keepHeadersOnError: false
25
25
  };
26
+ /**
27
+ * Determines if a request origin is allowed based on the configured origin list
28
+ * @param requestOrigin - The origin from the request header
29
+ * @param configuredOrigin - The origin configuration (string, array, or function)
30
+ * @param ctx - The Koa context (for function-based origin)
31
+ * @returns The allowed origin string or empty string if blocked
32
+ */ const matchOrigin = async (requestOrigin, configuredOrigin, ctx)=>{
33
+ if (!requestOrigin) {
34
+ return '*';
35
+ }
36
+ let originList;
37
+ if (typeof configuredOrigin === 'function') {
38
+ originList = await configuredOrigin(ctx);
39
+ } else {
40
+ originList = configuredOrigin;
41
+ }
42
+ // Normalize originList into an array
43
+ let normalizedOrigins;
44
+ if (Array.isArray(originList)) {
45
+ normalizedOrigins = originList;
46
+ } else if (originList === undefined || originList === null) {
47
+ // Handle undefined/null - treat as wildcard
48
+ normalizedOrigins = [
49
+ '*'
50
+ ];
51
+ } else {
52
+ // Handle comma-separated string of origins
53
+ normalizedOrigins = originList.split(',').map((origin)=>origin.trim());
54
+ }
55
+ // Check if wildcard is in the normalized origins
56
+ if (normalizedOrigins.includes('*')) {
57
+ return requestOrigin;
58
+ }
59
+ // Check if request origin is in the normalized origins
60
+ return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';
61
+ };
26
62
  const cors = (config)=>{
27
63
  const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {
28
64
  ...defaults,
@@ -33,23 +69,8 @@ const cors = (config)=>{
33
69
  }
34
70
  return koaCors({
35
71
  async origin (ctx) {
36
- if (!ctx.get('Origin')) {
37
- return '*';
38
- }
39
- let originList;
40
- if (typeof origin === 'function') {
41
- originList = await origin(ctx);
42
- } else {
43
- originList = origin;
44
- }
45
- if (Array.isArray(originList)) {
46
- return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
47
- }
48
- const parsedOrigin = originList.split(',').map((origin)=>origin.trim());
49
- if (parsedOrigin.length > 1) {
50
- return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
51
- }
52
- return originList;
72
+ const requestOrigin = ctx.get('Origin');
73
+ return matchOrigin(requestOrigin, origin, ctx);
53
74
  },
54
75
  exposeHeaders: expose,
55
76
  maxAge,
@@ -61,4 +82,5 @@ const cors = (config)=>{
61
82
  };
62
83
 
63
84
  exports.cors = cors;
85
+ exports.matchOrigin = matchOrigin;
64
86
  //# sourceMappingURL=cors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n const parsedOrigin = originList.split(',').map((origin) => origin.trim());\n if (parsedOrigin.length > 1) {\n return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["defaults","origin","maxAge","credentials","methods","headers","keepHeadersOnError","cors","config","expose","enabled","undefined","strapi","log","warn","koaCors","ctx","get","originList","Array","isArray","includes","parsedOrigin","split","map","trim","length","exposeHeaders","allowMethods","allowHeaders"],"mappings":";;;;AAeA,MAAMA,QAAmB,GAAA;IACvBC,MAAQ,EAAA,GAAA;IACRC,MAAQ,EAAA,QAAA;IACRC,WAAa,EAAA,IAAA;IACbC,OAAS,EAAA;AAAC,QAAA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A,CAAA,CAAKC,GAAG,CAAC,CAACvB,MAAWA,GAAAA,MAAAA,CAAOwB,IAAI,EAAA,CAAA;YACtE,IAAIH,YAAAA,CAAaI,MAAM,GAAG,CAAG,EAAA;gBAC3B,OAAOJ,YAAAA,CAAaD,QAAQ,CAACL,GAAIC,CAAAA,GAAG,CAAC,QAAaD,CAAAA,CAAAA,GAAAA,GAAAA,CAAIC,GAAG,CAAC,QAAY,CAAA,GAAA,EAAA;AACxE;YAEA,OAAOC,UAAAA;AACT,SAAA;QACAS,aAAelB,EAAAA,MAAAA;AACfP,QAAAA,MAAAA;AACAC,QAAAA,WAAAA;QACAyB,YAAcxB,EAAAA,OAAAA;QACdyB,YAAcxB,EAAAA,OAAAA;AACdC,QAAAA;AACF,KAAA,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\n/**\n * Determines if a request origin is allowed based on the configured origin list\n * @param requestOrigin - The origin from the request header\n * @param configuredOrigin - The origin configuration (string, array, or function)\n * @param ctx - The Koa context (for function-based origin)\n * @returns The allowed origin string or empty string if blocked\n */\nexport const matchOrigin = async (\n requestOrigin: string | undefined,\n configuredOrigin:\n | string\n | string[]\n | ((ctx: any) => string | string[] | Promise<string | string[]>),\n ctx?: any\n): Promise<string> => {\n if (!requestOrigin) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof configuredOrigin === 'function') {\n originList = await configuredOrigin(ctx);\n } else {\n originList = configuredOrigin;\n }\n\n // Normalize originList into an array\n let normalizedOrigins: string[];\n if (Array.isArray(originList)) {\n normalizedOrigins = originList;\n } else if (originList === undefined || originList === null) {\n // Handle undefined/null - treat as wildcard\n normalizedOrigins = ['*'];\n } else {\n // Handle comma-separated string of origins\n normalizedOrigins = originList.split(',').map((origin) => origin.trim());\n }\n\n // Check if wildcard is in the normalized origins\n if (normalizedOrigins.includes('*')) {\n return requestOrigin;\n }\n\n // Check if request origin is in the normalized origins\n return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n const requestOrigin = ctx.get('Origin');\n return matchOrigin(requestOrigin, origin, ctx);\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["defaults","origin","maxAge","credentials","methods","headers","keepHeadersOnError","matchOrigin","requestOrigin","configuredOrigin","ctx","originList","normalizedOrigins","Array","isArray","undefined","split","map","trim","includes","cors","config","expose","enabled","strapi","log","warn","koaCors","get","exposeHeaders","allowMethods","allowHeaders"],"mappings":";;;;AAeA,MAAMA,QAAmB,GAAA;IACvBC,MAAQ,EAAA,GAAA;IACRC,MAAQ,EAAA,QAAA;IACRC,WAAa,EAAA,IAAA;IACbC,OAAS,EAAA;AAAC,QAAA,KAAA;AAAO,QAAA,MAAA;AAAQ,QAAA,KAAA;AAAO,QAAA,OAAA;AAAS,QAAA,QAAA;AAAU,QAAA,MAA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AG;AACpF,QAAA,GAAGN,QAAQ;AACX,QAAA,GAAGqB;AACL,KAAA;IAEA,IAAIA,MAAAA,CAAOE,OAAO,KAAKR,SAAW,EAAA;AAChCS,QAAAA,MAAAA,CAAOC,GAAG,CAACC,IAAI,CACb,kFACE,wGACA,GAAA,6CAAA,CAAA;AAEN;AAEA,IAAA,OAAOC,OAAQ,CAAA;AACb,QAAA,MAAM1B,QAAOS,GAAG,EAAA;YACd,MAAMF,aAAAA,GAAgBE,GAAIkB,CAAAA,GAAG,CAAC,QAAA,CAAA;YAC9B,OAAOrB,WAAAA,CAAYC,eAAeP,MAAQS,EAAAA,GAAAA,CAAAA;AAC5C,SAAA;QACAmB,aAAeP,EAAAA,MAAAA;AACfpB,QAAAA,MAAAA;AACAC,QAAAA,WAAAA;QACA2B,YAAc1B,EAAAA,OAAAA;QACd2B,YAAc1B,EAAAA,OAAAA;AACdC,QAAAA;AACF,KAAA,CAAA;AACF;;;;;"}
@@ -21,6 +21,42 @@ const defaults = {
21
21
  ],
22
22
  keepHeadersOnError: false
23
23
  };
24
+ /**
25
+ * Determines if a request origin is allowed based on the configured origin list
26
+ * @param requestOrigin - The origin from the request header
27
+ * @param configuredOrigin - The origin configuration (string, array, or function)
28
+ * @param ctx - The Koa context (for function-based origin)
29
+ * @returns The allowed origin string or empty string if blocked
30
+ */ const matchOrigin = async (requestOrigin, configuredOrigin, ctx)=>{
31
+ if (!requestOrigin) {
32
+ return '*';
33
+ }
34
+ let originList;
35
+ if (typeof configuredOrigin === 'function') {
36
+ originList = await configuredOrigin(ctx);
37
+ } else {
38
+ originList = configuredOrigin;
39
+ }
40
+ // Normalize originList into an array
41
+ let normalizedOrigins;
42
+ if (Array.isArray(originList)) {
43
+ normalizedOrigins = originList;
44
+ } else if (originList === undefined || originList === null) {
45
+ // Handle undefined/null - treat as wildcard
46
+ normalizedOrigins = [
47
+ '*'
48
+ ];
49
+ } else {
50
+ // Handle comma-separated string of origins
51
+ normalizedOrigins = originList.split(',').map((origin)=>origin.trim());
52
+ }
53
+ // Check if wildcard is in the normalized origins
54
+ if (normalizedOrigins.includes('*')) {
55
+ return requestOrigin;
56
+ }
57
+ // Check if request origin is in the normalized origins
58
+ return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';
59
+ };
24
60
  const cors = (config)=>{
25
61
  const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {
26
62
  ...defaults,
@@ -31,23 +67,8 @@ const cors = (config)=>{
31
67
  }
32
68
  return koaCors({
33
69
  async origin (ctx) {
34
- if (!ctx.get('Origin')) {
35
- return '*';
36
- }
37
- let originList;
38
- if (typeof origin === 'function') {
39
- originList = await origin(ctx);
40
- } else {
41
- originList = origin;
42
- }
43
- if (Array.isArray(originList)) {
44
- return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
45
- }
46
- const parsedOrigin = originList.split(',').map((origin)=>origin.trim());
47
- if (parsedOrigin.length > 1) {
48
- return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
49
- }
50
- return originList;
70
+ const requestOrigin = ctx.get('Origin');
71
+ return matchOrigin(requestOrigin, origin, ctx);
51
72
  },
52
73
  exposeHeaders: expose,
53
74
  maxAge,
@@ -58,5 +79,5 @@ const cors = (config)=>{
58
79
  });
59
80
  };
60
81
 
61
- export { cors };
82
+ export { cors, matchOrigin };
62
83
  //# sourceMappingURL=cors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n const parsedOrigin = originList.split(',').map((origin) => origin.trim());\n if (parsedOrigin.length > 1) {\n return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["defaults","origin","maxAge","credentials","methods","headers","keepHeadersOnError","cors","config","expose","enabled","undefined","strapi","log","warn","koaCors","ctx","get","originList","Array","isArray","includes","parsedOrigin","split","map","trim","length","exposeHeaders","allowMethods","allowHeaders"],"mappings":";;AAeA,MAAMA,QAAmB,GAAA;IACvBC,MAAQ,EAAA,GAAA;IACRC,MAAQ,EAAA,QAAA;IACRC,WAAa,EAAA,IAAA;IACbC,OAAS,EAAA;AAAC,QAAA,KAAA;AAAO,QAAA,MAAA;AAAQ,QAAA,KAAA;AAAO,QAAA,OAAA;AAAS,QAAA,QAAA;AAAU,QAAA,MAAA;AAAQ,QAAA;AAAU,KAAA;IACrEC,OAAS,EAAA;AAAC,QAAA,cAAA;AAAgB,QAAA,eAAA;AAAiB,QAAA,QAAA;AAAU,QAAA;AAAS,KA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CAAAA,GAAAA,GAAAA,CAAIC,GAAG,CAAC,QAAY,CAAA,GAAA,EAAA;AACxE;YAEA,OAAOC,UAAAA;AACT,SAAA;QACAS,aAAelB,EAAAA,MAAAA;AACfP,QAAAA,MAAAA;AACAC,QAAAA,WAAAA;QACAyB,YAAcxB,EAAAA,OAAAA;QACdyB,YAAcxB,EAAAA,OAAAA;AACdC,QAAAA;AACF,KAAA,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\n/**\n * Determines if a request origin is allowed based on the configured origin list\n * @param requestOrigin - The origin from the request header\n * @param configuredOrigin - The origin configuration (string, array, or function)\n * @param ctx - The Koa context (for function-based origin)\n * @returns The allowed origin string or empty string if blocked\n */\nexport const matchOrigin = async (\n requestOrigin: string | undefined,\n configuredOrigin:\n | string\n | string[]\n | ((ctx: any) => string | string[] | Promise<string | string[]>),\n ctx?: any\n): Promise<string> => {\n if (!requestOrigin) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof configuredOrigin === 'function') {\n originList = await configuredOrigin(ctx);\n } else {\n originList = configuredOrigin;\n }\n\n // Normalize originList into an array\n let normalizedOrigins: string[];\n if (Array.isArray(originList)) {\n normalizedOrigins = originList;\n } else if (originList === undefined || originList === null) {\n // Handle undefined/null - treat as wildcard\n normalizedOrigins = ['*'];\n } else {\n // Handle comma-separated string of origins\n normalizedOrigins = originList.split(',').map((origin) => origin.trim());\n }\n\n // Check if wildcard is in the normalized origins\n if (normalizedOrigins.includes('*')) {\n return requestOrigin;\n }\n\n // Check if request origin is in the normalized origins\n return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n const requestOrigin = ctx.get('Origin');\n return matchOrigin(requestOrigin, origin, ctx);\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["defaults","origin","maxAge","credentials","methods","headers","keepHeadersOnError","matchOrigin","requestOrigin","configuredOrigin","ctx","originList","normalizedOrigins","Array","isArray","undefined","split","map","trim","includes","cors","config","expose","enabled","strapi","log","warn","koaCors","get","exposeHeaders","allowMethods","allowHeaders"],"mappings":";;AAeA,MAAMA,QAAmB,GAAA;IACvBC,MAAQ,EAAA,GAAA;IACRC,MAAQ,EAAA,QAAA;IACRC,WAAa,EAAA,IAAA;IACbC,OAAS,EAAA;AAAC,QAAA,KAAA;AAAO,QAAA,MAAA;AAAQ,QAAA,KAAA;AAAO,QAAA,OAAA;AAAS,QAAA,QAAA;AAAU,QAAA,MAAA;AAAQ,QAAA;AAAU,KAAA;IACrEC,OAAS,EAAA;AAAC,QAAA,cAAA;AAAgB,QAAA,eAAA;AAAiB,QAAA,QAAA;AAAU,QAAA;AAAS,KAAA;IAC9DC,kBAAoB,EAAA;AACtB,CAAA;AAEA;;;;;;AAMC,IACM,MAAMC,WAAc,GAAA,OACzBC,eACAC,gB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,OAAQ,CAAA;AACb,QAAA,MAAM1B,QAAOS,GAAG,EAAA;YACd,MAAMF,aAAAA,GAAgBE,GAAIkB,CAAAA,GAAG,CAAC,QAAA,CAAA;YAC9B,OAAOrB,WAAAA,CAAYC,eAAeP,MAAQS,EAAAA,GAAAA,CAAAA;AAC5C,SAAA;QACAmB,aAAeP,EAAAA,MAAAA;AACfpB,QAAAA,MAAAA;AACAC,QAAAA,WAAAA;QACA2B,YAAc1B,EAAAA,OAAAA;QACd2B,YAAc1B,EAAAA,OAAAA;AACdC,QAAAA;AACF,KAAA,CAAA;AACF;;;;"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var name = "@strapi/core";
6
- var version = "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6";
6
+ var version = "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8";
7
7
  var description = "Core of Strapi";
8
8
  var homepage = "https://strapi.io";
9
9
  var bugs = {
@@ -59,14 +59,14 @@ var dependencies = {
59
59
  "@koa/cors": "5.0.0",
60
60
  "@koa/router": "12.0.2",
61
61
  "@paralleldrive/cuid2": "2.2.2",
62
- "@strapi/admin": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
63
- "@strapi/database": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
64
- "@strapi/generators": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
65
- "@strapi/logger": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
66
- "@strapi/permissions": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
67
- "@strapi/types": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
68
- "@strapi/typescript-utils": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
69
- "@strapi/utils": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
62
+ "@strapi/admin": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
63
+ "@strapi/database": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
64
+ "@strapi/generators": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
65
+ "@strapi/logger": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
66
+ "@strapi/permissions": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
67
+ "@strapi/types": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
68
+ "@strapi/typescript-utils": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
69
+ "@strapi/utils": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
70
70
  bcryptjs: "2.4.3",
71
71
  boxen: "5.1.2",
72
72
  chalk: "4.1.2",
@@ -85,6 +85,7 @@ var dependencies = {
85
85
  "http-errors": "2.0.0",
86
86
  inquirer: "8.2.5",
87
87
  "is-docker": "2.2.1",
88
+ "json-logic-js": "2.0.5",
88
89
  koa: "2.16.1",
89
90
  "koa-body": "6.0.1",
90
91
  "koa-compose": "4.1.0",
@@ -107,7 +108,8 @@ var dependencies = {
107
108
  statuses: "2.0.1",
108
109
  typescript: "5.4.4",
109
110
  undici: "6.21.2",
110
- yup: "0.32.9"
111
+ yup: "0.32.9",
112
+ zod: "3.25.67"
111
113
  };
112
114
  var devDependencies = {
113
115
  "@strapi/ts-zen": "^0.2.0",
@@ -119,6 +121,7 @@ var devDependencies = {
119
121
  "@types/global-agent": "2.1.3",
120
122
  "@types/http-errors": "2.0.4",
121
123
  "@types/jest": "29.5.2",
124
+ "@types/json-logic-js": "2.0.8",
122
125
  "@types/koa": "2.13.4",
123
126
  "@types/koa-compress": "4.0.3",
124
127
  "@types/koa-session": "6.4.1",
@@ -129,9 +132,9 @@ var devDependencies = {
129
132
  "@types/node": "18.19.24",
130
133
  "@types/node-schedule": "2.1.7",
131
134
  "@types/statuses": "2.0.1",
132
- "eslint-config-custom": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
135
+ "eslint-config-custom": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
133
136
  supertest: "6.3.3",
134
- tsconfig: "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6"
137
+ tsconfig: "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8"
135
138
  };
136
139
  var engines = {
137
140
  node: ">=18.0.0 <=22.x.x",
@@ -1 +1 @@
1
- {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  var name = "@strapi/core";
2
- var version = "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6";
2
+ var version = "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8";
3
3
  var description = "Core of Strapi";
4
4
  var homepage = "https://strapi.io";
5
5
  var bugs = {
@@ -55,14 +55,14 @@ var dependencies = {
55
55
  "@koa/cors": "5.0.0",
56
56
  "@koa/router": "12.0.2",
57
57
  "@paralleldrive/cuid2": "2.2.2",
58
- "@strapi/admin": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
59
- "@strapi/database": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
60
- "@strapi/generators": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
61
- "@strapi/logger": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
62
- "@strapi/permissions": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
63
- "@strapi/types": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
64
- "@strapi/typescript-utils": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
65
- "@strapi/utils": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
58
+ "@strapi/admin": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
59
+ "@strapi/database": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
60
+ "@strapi/generators": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
61
+ "@strapi/logger": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
62
+ "@strapi/permissions": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
63
+ "@strapi/types": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
64
+ "@strapi/typescript-utils": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
65
+ "@strapi/utils": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
66
66
  bcryptjs: "2.4.3",
67
67
  boxen: "5.1.2",
68
68
  chalk: "4.1.2",
@@ -81,6 +81,7 @@ var dependencies = {
81
81
  "http-errors": "2.0.0",
82
82
  inquirer: "8.2.5",
83
83
  "is-docker": "2.2.1",
84
+ "json-logic-js": "2.0.5",
84
85
  koa: "2.16.1",
85
86
  "koa-body": "6.0.1",
86
87
  "koa-compose": "4.1.0",
@@ -103,7 +104,8 @@ var dependencies = {
103
104
  statuses: "2.0.1",
104
105
  typescript: "5.4.4",
105
106
  undici: "6.21.2",
106
- yup: "0.32.9"
107
+ yup: "0.32.9",
108
+ zod: "3.25.67"
107
109
  };
108
110
  var devDependencies = {
109
111
  "@strapi/ts-zen": "^0.2.0",
@@ -115,6 +117,7 @@ var devDependencies = {
115
117
  "@types/global-agent": "2.1.3",
116
118
  "@types/http-errors": "2.0.4",
117
119
  "@types/jest": "29.5.2",
120
+ "@types/json-logic-js": "2.0.8",
118
121
  "@types/koa": "2.13.4",
119
122
  "@types/koa-compress": "4.0.3",
120
123
  "@types/koa-session": "6.4.1",
@@ -125,9 +128,9 @@ var devDependencies = {
125
128
  "@types/node": "18.19.24",
126
129
  "@types/node-schedule": "2.1.7",
127
130
  "@types/statuses": "2.0.1",
128
- "eslint-config-custom": "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6",
131
+ "eslint-config-custom": "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8",
129
132
  supertest: "6.3.3",
130
- tsconfig: "0.0.0-next.8d576f41729640e32a4a0cfcb258b6288e6631f6"
133
+ tsconfig: "0.0.0-next.8f0cdd4f9e4697ffed86c783465297fe532713f8"
131
134
  };
132
135
  var engines = {
133
136
  node: ">=18.0.0 <=22.x.x",
@@ -1 +1 @@
1
- {"version":3,"file":"package.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"package.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAYlD,QAAA,MAAM,oBAAoB,QACnB,IAAI,WAAW,mBACH,QAAQ,eAAe,CAAC,eAAe;;iBA4EzB,MAAM;4BAUK,GAAG;qBA4BV,GAAG;0BAaE,GAAG;CAoB5C,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAYlD,QAAA,MAAM,oBAAoB,QACnB,IAAI,WAAW,mBACH,QAAQ,eAAe,CAAC,eAAe;;iBA2EzB,MAAM;4BAUK,GAAG;qBA4BV,GAAG;0BAaE,GAAG;CAoB5C,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"entries.js","sources":["../../../src/services/document-service/entries.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\nimport { async, errors } from '@strapi/utils';\nimport { assoc, omit } from 'lodash/fp';\n\nimport * as components from './components';\n\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { transformParamsToQuery } from './transform/query';\nimport { pickSelectionParams } from './params';\nimport { applyTransforms } from './attributes';\nimport { transformData } from './transform/data';\n\nconst createEntriesService = (\n uid: UID.ContentType,\n entityValidator: Modules.EntityValidator.EntityValidator\n) => {\n const contentType = strapi.contentType(uid);\n\n async function createEntry(params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n // Validation\n if (!data) {\n throw new Error('Create requires data attribute');\n }\n\n // Check for uniqueness based on documentId and locale (if localized)\n if (data.documentId) {\n const i18nService = strapi.plugin('i18n')?.service('content-types');\n const isLocalized = i18nService?.isLocalizedContentType(contentType) ?? false;\n const hasDraftAndPublish = contentType.options?.draftAndPublish === true;\n\n const whereClause: Record<string, unknown> = { documentId: data.documentId };\n\n if (isLocalized) {\n whereClause.locale = data.locale;\n }\n\n let publishedStateDescription = '';\n\n if (hasDraftAndPublish) {\n if (data.publishedAt) {\n // Current entry is published, check for existing published entry\n whereClause.publishedAt = { $notNull: true };\n publishedStateDescription = 'published';\n } else {\n // Current entry is a draft, check for existing draft entry\n whereClause.publishedAt = { $null: true };\n publishedStateDescription = 'draft';\n }\n }\n\n const existingEntry = await strapi.db.query(uid).findOne({\n select: ['id'],\n where: whereClause,\n });\n\n if (existingEntry) {\n let errorMsg = `A ${publishedStateDescription} entry with documentId \"${data.documentId}\"`;\n if (isLocalized && data.locale) {\n errorMsg += ` and locale \"${data.locale}\"`;\n }\n errorMsg += ` already exists for UID \"${uid}\". This combination must be unique.`;\n throw new errors.ApplicationError(errorMsg);\n }\n }\n\n const validData = await entityValidator.validateEntityCreation(contentType, data, {\n // Note: publishedAt value will always be set when DP is disabled\n isDraft: !params?.data?.publishedAt,\n locale: params?.locale,\n });\n\n // Component handling\n const componentData = await components.createComponents(uid, validData);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n const doc = await strapi.db.query(uid).create({ ...query, data: entryData });\n\n return doc;\n }\n\n async function deleteEntry(id: number) {\n const componentsToDelete = await components.getComponents(uid, { id });\n\n const deletedEntry = await strapi.db.query(uid).delete({ where: { id } });\n\n await components.deleteComponents(uid, componentsToDelete as any, { loadComponents: false });\n\n return deletedEntry;\n }\n\n async function updateEntry(entryToUpdate: any, params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n const validData = await entityValidator.validateEntityUpdate(\n contentType,\n data,\n {\n isDraft: !params?.data?.publishedAt, // Always update the draft version\n locale: params?.locale,\n },\n entryToUpdate\n );\n // Component handling\n const componentData = await components.updateComponents(uid, entryToUpdate, validData as any);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n return strapi.db\n .query(uid)\n .update({ ...query, where: { id: entryToUpdate.id }, data: entryData });\n }\n\n async function publishEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', new Date()),\n (draft) => {\n const opts = { uid, locale: draft.locale, status: 'published', allowMissingId: true };\n return transformData(draft, opts);\n },\n // Create the published entry\n (draft) => createEntry({ ...params, data: draft, locale: draft.locale, status: 'published' })\n )(entry);\n }\n\n async function discardDraftEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', null),\n (entry) => {\n const opts = { uid, locale: entry.locale, status: 'draft', allowMissingId: true };\n return transformData(entry, opts);\n },\n // Create the draft entry\n (data) => createEntry({ ...params, locale: data.locale, data, status: 'draft' })\n )(entry);\n }\n\n return {\n create: createEntry,\n delete: deleteEntry,\n update: updateEntry,\n publish: publishEntry,\n discardDraft: discardDraftEntry,\n };\n};\n\nexport { createEntriesService };\n"],"names":["createEntriesService","uid","entityValidator","contentType","strapi","createEntry","params","data","restParams","transformParamsDocumentId","query","transformParamsToQuery","pickSelectionParams","Error","documentId","i18nService","plugin","service","isLocalized","isLocalizedContentType","hasDraftAndPublish","options","draftAndPublish","whereClause","locale","publishedStateDescription","publishedAt","$notNull","$null","existingEntry","db","findOne","select","where","errorMsg","errors","ApplicationError","validData","validateEntityCreation","isDraft","componentData","components","dataWithComponents","entryData","applyTransforms","doc","create","deleteEntry","id","componentsToDelete","deletedEntry","delete","loadComponents","updateEntry","entryToUpdate","validateEntityUpdate","update","publishEntry","entry","async","pipe","omit","assoc","Date","draft","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,MAAMO,IAAO,GAAA;AAAEhE,gBAAAA,GAAAA;AAAKuB,gBAAAA,MAAAA,EAAQkC,MAAMlC,MAAM;gBAAE0C,MAAQ,EAAA,OAAA;gBAASC,cAAgB,EAAA;AAAK,aAAA;AAChF,YAAA,OAAOC,mBAAcV,KAAOO,EAAAA,IAAAA,CAAAA;AAC9B,SAAA;AAEA,QAAA,CAAC1D,OAASF,WAAY,CAAA;AAAE,gBAAA,GAAGC,MAAM;AAAEkB,gBAAAA,MAAAA,EAAQjB,KAAKiB,MAAM;AAAEjB,gBAAAA,IAAAA;gBAAM2D,MAAQ,EAAA;aACtER,CAAAA,CAAAA,CAAAA,KAAAA,CAAAA;AACJ;IAEA,OAAO;QACLZ,MAAQzC,EAAAA,WAAAA;QACR8C,MAAQJ,EAAAA,WAAAA;QACRS,MAAQH,EAAAA,WAAAA;QACRiB,OAASb,EAAAA,YAAAA;QACTc,YAAcF,EAAAA;AAChB,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"entries.js","sources":["../../../src/services/document-service/entries.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\nimport { async, errors } from '@strapi/utils';\nimport { assoc, omit } from 'lodash/fp';\n\nimport * as components from './components';\n\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { transformParamsToQuery } from './transform/query';\nimport { pickSelectionParams } from './params';\nimport { applyTransforms } from './attributes';\nimport { transformData } from './transform/data';\n\nconst createEntriesService = (\n uid: UID.ContentType,\n entityValidator: Modules.EntityValidator.EntityValidator\n) => {\n const contentType = strapi.contentType(uid);\n\n async function createEntry(params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n // Validation\n if (!data) {\n throw new Error('Create requires data attribute');\n }\n\n // Check for uniqueness based on documentId and locale (if localized)\n if (data.documentId) {\n const i18nService = strapi.plugin('i18n')?.service('content-types');\n const isLocalized = i18nService?.isLocalizedContentType(contentType) ?? false;\n const hasDraftAndPublish = contentType.options?.draftAndPublish === true;\n\n const whereClause: Record<string, unknown> = { documentId: data.documentId };\n\n if (isLocalized) {\n whereClause.locale = data.locale;\n }\n\n let publishedStateDescription = '';\n\n if (hasDraftAndPublish) {\n if (data.publishedAt) {\n // Current entry is published, check for existing published entry\n whereClause.publishedAt = { $notNull: true };\n publishedStateDescription = 'published';\n } else {\n // Current entry is a draft, check for existing draft entry\n whereClause.publishedAt = { $null: true };\n publishedStateDescription = 'draft';\n }\n }\n\n const existingEntry = await strapi.db.query(uid).findOne({\n select: ['id'],\n where: whereClause,\n });\n\n if (existingEntry) {\n let errorMsg = `A ${publishedStateDescription} entry with documentId \"${data.documentId}\"`;\n if (isLocalized && data.locale) {\n errorMsg += ` and locale \"${data.locale}\"`;\n }\n errorMsg += ` already exists for UID \"${uid}\". This combination must be unique.`;\n throw new errors.ApplicationError(errorMsg);\n }\n }\n\n const validData = await entityValidator.validateEntityCreation(contentType, data, {\n // Note: publishedAt value will always be set when DP is disabled\n isDraft: !params?.data?.publishedAt,\n locale: params?.locale,\n });\n\n // Component handling\n const componentData = await components.createComponents(uid, validData);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n const doc = await strapi.db.query(uid).create({ ...query, data: entryData });\n\n return doc;\n }\n\n async function deleteEntry(id: number) {\n const componentsToDelete = await components.getComponents(uid, { id });\n\n const deletedEntry = await strapi.db.query(uid).delete({ where: { id } });\n\n await components.deleteComponents(uid, componentsToDelete as any, { loadComponents: false });\n\n return deletedEntry;\n }\n\n async function updateEntry(entryToUpdate: any, params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n const validData = await entityValidator.validateEntityUpdate(\n contentType,\n data,\n {\n isDraft: !params?.data?.publishedAt, // Always update the draft version\n locale: params?.locale,\n },\n entryToUpdate\n );\n // Component handling\n const componentData = await components.updateComponents(uid, entryToUpdate, validData as any);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n return strapi.db\n .query(uid)\n .update({ ...query, where: { id: entryToUpdate.id }, data: entryData });\n }\n\n async function publishEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', new Date()),\n (draft) => {\n const opts = { uid, locale: draft.locale, status: 'published', allowMissingId: true };\n return transformData(draft, opts);\n },\n // Create the published entry\n (draft) => createEntry({ ...params, data: draft, locale: draft.locale, status: 'published' })\n )(entry);\n }\n\n async function discardDraftEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', null),\n (entry) => {\n const opts = { uid, locale: entry.locale, status: 'draft', allowMissingId: true };\n return transformData(entry, opts);\n },\n // Create the draft entry\n (data) => createEntry({ ...params, locale: data.locale, data, status: 'draft' })\n )(entry);\n }\n\n return {\n create: createEntry,\n delete: deleteEntry,\n update: updateEntry,\n publish: publishEntry,\n discardDraft: discardDraftEntry,\n };\n};\n\nexport { createEntriesService };\n"],"names":["createEntriesService","uid","entityValidator","contentType","strapi","createEntry","params","data","restParams","transformParamsDocumentId","query","transformParamsToQuery","pickSelectionParams","Error","documentId","i18nService","plugin","service","isLocalized","isLocalizedContentType","hasDraftAndPublish","options","draftAndPublish","whereClause","locale","publishedStateDescription","publishedAt","$notNull","$null","existingEntry","db","findOne","select","where","errorMsg","errors","ApplicationError","validData","validateEntityCreation","isDraft","componentData","components","dataWithComponents","entryData","applyTransforms","doc","create","deleteEntry","id","componentsToDelete","deletedEntry","delete","loadComponents","updateEntry","entryToUpdate","validateEntityUpdate","update","publishEntry","entry","async","pipe","omit","assoc","Date","draft","opts","status","allowMissingId","transformData","discardDraftEntry","publish","discardDraft"],"mappings":";;;;;;;;;;;AAYMA,MAAAA,oBAAAA,GAAuB,CAC3BC,GACAC,EAAAA,eAAAA,GAAAA;IAEA,MAAM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A;AAAK,aAAA;AAChF,YAAA,OAAOC,mBAAcV,KAAOO,EAAAA,IAAAA,CAAAA;AAC9B,SAAA;AAEA,QAAA,CAAC1D,OAASF,WAAY,CAAA;AAAE,gBAAA,GAAGC,MAAM;AAAEkB,gBAAAA,MAAAA,EAAQjB,KAAKiB,MAAM;AAAEjB,gBAAAA,IAAAA;gBAAM2D,MAAQ,EAAA;aACtER,CAAAA,CAAAA,CAAAA,KAAAA,CAAAA;AACJ;IAEA,OAAO;QACLZ,MAAQzC,EAAAA,WAAAA;QACR8C,MAAQJ,EAAAA,WAAAA;QACRS,MAAQH,EAAAA,WAAAA;QACRiB,OAASb,EAAAA,YAAAA;QACTc,YAAcF,EAAAA;AAChB,KAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"entries.mjs","sources":["../../../src/services/document-service/entries.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\nimport { async, errors } from '@strapi/utils';\nimport { assoc, omit } from 'lodash/fp';\n\nimport * as components from './components';\n\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { transformParamsToQuery } from './transform/query';\nimport { pickSelectionParams } from './params';\nimport { applyTransforms } from './attributes';\nimport { transformData } from './transform/data';\n\nconst createEntriesService = (\n uid: UID.ContentType,\n entityValidator: Modules.EntityValidator.EntityValidator\n) => {\n const contentType = strapi.contentType(uid);\n\n async function createEntry(params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n // Validation\n if (!data) {\n throw new Error('Create requires data attribute');\n }\n\n // Check for uniqueness based on documentId and locale (if localized)\n if (data.documentId) {\n const i18nService = strapi.plugin('i18n')?.service('content-types');\n const isLocalized = i18nService?.isLocalizedContentType(contentType) ?? false;\n const hasDraftAndPublish = contentType.options?.draftAndPublish === true;\n\n const whereClause: Record<string, unknown> = { documentId: data.documentId };\n\n if (isLocalized) {\n whereClause.locale = data.locale;\n }\n\n let publishedStateDescription = '';\n\n if (hasDraftAndPublish) {\n if (data.publishedAt) {\n // Current entry is published, check for existing published entry\n whereClause.publishedAt = { $notNull: true };\n publishedStateDescription = 'published';\n } else {\n // Current entry is a draft, check for existing draft entry\n whereClause.publishedAt = { $null: true };\n publishedStateDescription = 'draft';\n }\n }\n\n const existingEntry = await strapi.db.query(uid).findOne({\n select: ['id'],\n where: whereClause,\n });\n\n if (existingEntry) {\n let errorMsg = `A ${publishedStateDescription} entry with documentId \"${data.documentId}\"`;\n if (isLocalized && data.locale) {\n errorMsg += ` and locale \"${data.locale}\"`;\n }\n errorMsg += ` already exists for UID \"${uid}\". This combination must be unique.`;\n throw new errors.ApplicationError(errorMsg);\n }\n }\n\n const validData = await entityValidator.validateEntityCreation(contentType, data, {\n // Note: publishedAt value will always be set when DP is disabled\n isDraft: !params?.data?.publishedAt,\n locale: params?.locale,\n });\n\n // Component handling\n const componentData = await components.createComponents(uid, validData);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n const doc = await strapi.db.query(uid).create({ ...query, data: entryData });\n\n return doc;\n }\n\n async function deleteEntry(id: number) {\n const componentsToDelete = await components.getComponents(uid, { id });\n\n const deletedEntry = await strapi.db.query(uid).delete({ where: { id } });\n\n await components.deleteComponents(uid, componentsToDelete as any, { loadComponents: false });\n\n return deletedEntry;\n }\n\n async function updateEntry(entryToUpdate: any, params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n const validData = await entityValidator.validateEntityUpdate(\n contentType,\n data,\n {\n isDraft: !params?.data?.publishedAt, // Always update the draft version\n locale: params?.locale,\n },\n entryToUpdate\n );\n // Component handling\n const componentData = await components.updateComponents(uid, entryToUpdate, validData as any);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n return strapi.db\n .query(uid)\n .update({ ...query, where: { id: entryToUpdate.id }, data: entryData });\n }\n\n async function publishEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', new Date()),\n (draft) => {\n const opts = { uid, locale: draft.locale, status: 'published', allowMissingId: true };\n return transformData(draft, opts);\n },\n // Create the published entry\n (draft) => createEntry({ ...params, data: draft, locale: draft.locale, status: 'published' })\n )(entry);\n }\n\n async function discardDraftEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', null),\n (entry) => {\n const opts = { uid, locale: entry.locale, status: 'draft', allowMissingId: true };\n return transformData(entry, opts);\n },\n // Create the draft entry\n (data) => createEntry({ ...params, locale: data.locale, data, status: 'draft' })\n )(entry);\n }\n\n return {\n create: createEntry,\n delete: deleteEntry,\n update: updateEntry,\n publish: publishEntry,\n discardDraft: discardDraftEntry,\n };\n};\n\nexport { createEntriesService };\n"],"names":["createEntriesService","uid","entityValidator","contentType","strapi","createEntry","params","data","restParams","transformParamsDocumentId","query","transformParamsToQuery","pickSelectionParams","Error","documentId","i18nService","plugin","service","isLocalized","isLocalizedContentType","hasDraftAndPublish","options","draftAndPublish","whereClause","locale","publishedStateDescription","publishedAt","$notNull","$null","existingEntry","db","findOne","select","where","errorMsg","errors","ApplicationError","validData","validateEntityCreation","isDraft","componentData","components","dataWithComponents","entryData","applyTransforms","doc","create","deleteEntry","id","componentsToDelete","deletedEntry","delete","loadComponents","updateEntry","entryToUpdate","validateEntityUpdate","update","publishEntry","entry","async","pipe","omit","assoc","Date","draft","opts","status","allowMissingId","transformData","discardDraftEntry","publish","discardDraft"],"mappings":";;;;;;;;;AAYMA,MAAAA,oBAAAA,GAAuB,CAC3BC,GACAC,EAAAA,eAAAA,GAAAA;IAEA,MAAMC,WAAAA,GAAcC,MAAOD,CAAAA,WAAW,CAACF,GAAAA,CAAAA;IAEvC,eAAeI,WAAAA,CAAYC,MAAS,GAAA,EAAS,EAAA;QAC3C,MAAM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BAAA,GAAGC,MAAM;AAAEkB,gBAAAA,MAAAA,EAAQjB,KAAKiB,MAAM;AAAEjB,gBAAAA,IAAAA;gBAAM2D,MAAQ,EAAA;aACtER,CAAAA,CAAAA,CAAAA,KAAAA,CAAAA;AACJ;IAEA,OAAO;QACLZ,MAAQzC,EAAAA,WAAAA;QACR8C,MAAQJ,EAAAA,WAAAA;QACRS,MAAQH,EAAAA,WAAAA;QACRiB,OAASb,EAAAA,YAAAA;QACTc,YAAcF,EAAAA;AAChB,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"entries.mjs","sources":["../../../src/services/document-service/entries.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\nimport { async, errors } from '@strapi/utils';\nimport { assoc, omit } from 'lodash/fp';\n\nimport * as components from './components';\n\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { transformParamsToQuery } from './transform/query';\nimport { pickSelectionParams } from './params';\nimport { applyTransforms } from './attributes';\nimport { transformData } from './transform/data';\n\nconst createEntriesService = (\n uid: UID.ContentType,\n entityValidator: Modules.EntityValidator.EntityValidator\n) => {\n const contentType = strapi.contentType(uid);\n\n async function createEntry(params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n // Validation\n if (!data) {\n throw new Error('Create requires data attribute');\n }\n\n // Check for uniqueness based on documentId and locale (if localized)\n if (data.documentId) {\n const i18nService = strapi.plugin('i18n')?.service('content-types');\n const isLocalized = i18nService?.isLocalizedContentType(contentType) ?? false;\n const hasDraftAndPublish = contentType.options?.draftAndPublish === true;\n\n const whereClause: Record<string, unknown> = { documentId: data.documentId };\n\n if (isLocalized) {\n whereClause.locale = data.locale;\n }\n\n let publishedStateDescription = '';\n\n if (hasDraftAndPublish) {\n if (data.publishedAt) {\n // Current entry is published, check for existing published entry\n whereClause.publishedAt = { $notNull: true };\n publishedStateDescription = 'published';\n } else {\n // Current entry is a draft, check for existing draft entry\n whereClause.publishedAt = { $null: true };\n publishedStateDescription = 'draft';\n }\n }\n\n const existingEntry = await strapi.db.query(uid).findOne({\n select: ['id'],\n where: whereClause,\n });\n\n if (existingEntry) {\n let errorMsg = `A ${publishedStateDescription} entry with documentId \"${data.documentId}\"`;\n if (isLocalized && data.locale) {\n errorMsg += ` and locale \"${data.locale}\"`;\n }\n errorMsg += ` already exists for UID \"${uid}\". This combination must be unique.`;\n throw new errors.ApplicationError(errorMsg);\n }\n }\n\n const validData = await entityValidator.validateEntityCreation(contentType, data, {\n // Note: publishedAt value will always be set when DP is disabled\n isDraft: !params?.data?.publishedAt,\n locale: params?.locale,\n });\n\n // Component handling\n const componentData = await components.createComponents(uid, validData);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n const doc = await strapi.db.query(uid).create({ ...query, data: entryData });\n\n return doc;\n }\n\n async function deleteEntry(id: number) {\n const componentsToDelete = await components.getComponents(uid, { id });\n\n const deletedEntry = await strapi.db.query(uid).delete({ where: { id } });\n\n await components.deleteComponents(uid, componentsToDelete as any, { loadComponents: false });\n\n return deletedEntry;\n }\n\n async function updateEntry(entryToUpdate: any, params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n const validData = await entityValidator.validateEntityUpdate(\n contentType,\n data,\n {\n isDraft: !params?.data?.publishedAt, // Always update the draft version\n locale: params?.locale,\n },\n entryToUpdate\n );\n // Component handling\n const componentData = await components.updateComponents(uid, entryToUpdate, validData as any);\n const dataWithComponents = components.assignComponentData(\n contentType,\n componentData,\n validData\n );\n\n const entryData = applyTransforms(contentType, dataWithComponents);\n\n return strapi.db\n .query(uid)\n .update({ ...query, where: { id: entryToUpdate.id }, data: entryData });\n }\n\n async function publishEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', new Date()),\n (draft) => {\n const opts = { uid, locale: draft.locale, status: 'published', allowMissingId: true };\n return transformData(draft, opts);\n },\n // Create the published entry\n (draft) => createEntry({ ...params, data: draft, locale: draft.locale, status: 'published' })\n )(entry);\n }\n\n async function discardDraftEntry(entry: any, params = {} as any) {\n return async.pipe(\n omit('id'),\n assoc('publishedAt', null),\n (entry) => {\n const opts = { uid, locale: entry.locale, status: 'draft', allowMissingId: true };\n return transformData(entry, opts);\n },\n // Create the draft entry\n (data) => createEntry({ ...params, locale: data.locale, data, status: 'draft' })\n )(entry);\n }\n\n return {\n create: createEntry,\n delete: deleteEntry,\n update: updateEntry,\n publish: publishEntry,\n discardDraft: discardDraftEntry,\n };\n};\n\nexport { createEntriesService };\n"],"names":["createEntriesService","uid","entityValidator","contentType","strapi","createEntry","params","data","restParams","transformParamsDocumentId","query","transformParamsToQuery","pickSelectionParams","Error","documentId","i18nService","plugin","service","isLocalized","isLocalizedContentType","hasDraftAndPublish","options","draftAndPublish","whereClause","locale","publishedStateDescription","publishedAt","$notNull","$null","existingEntry","db","findOne","select","where","errorMsg","errors","ApplicationError","validData","validateEntityCreation","isDraft","componentData","components","dataWithComponents","entryData","applyTransforms","doc","create","deleteEntry","id","componentsToDelete","deletedEntry","delete","loadComponents","updateEntry","entryToUpdate","validateEntityUpdate","update","publishEntry","entry","async","pipe","omit","assoc","Date","draft","opts","status","allowMissingId","transformData","discardDraftEntry","publish","discardDraft"],"mappings":";;;;;;;;;AAYMA,MAAAA,oBAAAA,GAAuB,CAC3BC,GACAC,EAAAA,eAAAA,GAAAA;IAEA,MAAMC,WAAAA,GAAcC,MAAOD,CAAAA,WAAW,CAACF,GAAAA,CAAAA;IAEvC,eAAeI,WAAAA,CAAYC,MAAS,GAAA,EAAS,EAAA;QAC3C,MAAM,EAAEC,IAAI,EAAE,GAAGC,YAAY,GAAG,MAAMC,iCAA0BR,GAAKK,EAAAA,MAAAA,CAAAA;AACrE,QAAA,MAAMI,KAAQC,GAAAA,sBAAAA,CAAuBV,GAAKW,EA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A,CAAAA;AACJ;IAEA,OAAO;QACLZ,MAAQzC,EAAAA,WAAAA;QACR8C,MAAQJ,EAAAA,WAAAA;QACRS,MAAQH,EAAAA,WAAAA;QACRiB,OAASb,EAAAA,YAAAA;QACTc,YAAcF,EAAAA;AAChB,KAAA;AACF;;;;"}
@@ -1,8 +1,13 @@
1
1
  /// <reference types="lodash" />
2
2
  import type { Struct, Modules } from '@strapi/types';
3
+ /**
4
+ * Copy non-localized fields from an existing entry to a new entry being created
5
+ * for a different locale of the same document. Returns a new object with the merged data.
6
+ */
7
+ declare const copyNonLocalizedFields: (contentType: Struct.SingleTypeSchema | Struct.CollectionTypeSchema, documentId: string, dataToCreate: Record<string, any>) => Promise<Record<string, any>>;
3
8
  declare const defaultLocaleCurry: import("lodash").CurriedFunction2<Struct.SingleTypeSchema | Struct.CollectionTypeSchema, Modules.Documents.Params.All, Promise<Modules.Documents.Params.All>>;
4
9
  declare const localeToLookupCurry: import("lodash").CurriedFunction2<Struct.SingleTypeSchema | Struct.CollectionTypeSchema, Modules.Documents.Params.All, Modules.Documents.Params.All>;
5
10
  declare const multiLocaleToLookupCurry: import("lodash").CurriedFunction2<Struct.SingleTypeSchema | Struct.CollectionTypeSchema, Modules.Documents.Params.All, Modules.Documents.Params.All>;
6
11
  declare const localeToDataCurry: import("lodash").CurriedFunction2<Struct.SingleTypeSchema | Struct.CollectionTypeSchema, Modules.Documents.Params.All, Modules.Documents.Params.All>;
7
- export { defaultLocaleCurry as defaultLocale, localeToLookupCurry as localeToLookup, localeToDataCurry as localeToData, multiLocaleToLookupCurry as multiLocaleToLookup, };
12
+ export { defaultLocaleCurry as defaultLocale, localeToLookupCurry as localeToLookup, localeToDataCurry as localeToData, multiLocaleToLookupCurry as multiLocaleToLookup, copyNonLocalizedFields, };
8
13
  //# sourceMappingURL=internationalization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internationalization.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/internationalization.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA8FrD,QAAA,MAAM,kBAAkB,+JAAuB,CAAC;AAChD,QAAA,MAAM,mBAAmB,sJAAwB,CAAC;AAClD,QAAA,MAAM,wBAAwB,sJAA6B,CAAC;AAC5D,QAAA,MAAM,iBAAiB,sJAAsB,CAAC;AAE9C,OAAO,EACL,kBAAkB,IAAI,aAAa,EACnC,mBAAmB,IAAI,cAAc,EACrC,iBAAiB,IAAI,YAAY,EACjC,wBAAwB,IAAI,mBAAmB,GAChD,CAAC"}
1
+ {"version":3,"file":"internationalization.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/internationalization.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA8FrD;;;GAGG;AACH,QAAA,MAAM,sBAAsB,gBACb,OAAO,gBAAgB,GAAG,OAAO,oBAAoB,cACtD,MAAM,gBACJ,OAAO,MAAM,EAAE,GAAG,CAAC,KAChC,QAAQ,OAAO,MAAM,EAAE,GAAG,CAAC,CAwB7B,CAAC;AAEF,QAAA,MAAM,kBAAkB,+JAAuB,CAAC;AAChD,QAAA,MAAM,mBAAmB,sJAAwB,CAAC;AAClD,QAAA,MAAM,wBAAwB,sJAA6B,CAAC;AAC5D,QAAA,MAAM,iBAAiB,sJAAsB,CAAC;AAE9C,OAAO,EACL,kBAAkB,IAAI,aAAa,EACnC,mBAAmB,IAAI,cAAc,EACrC,iBAAiB,IAAI,YAAY,EACjC,wBAAwB,IAAI,mBAAmB,EAC/C,sBAAsB,GACvB,CAAC"}
@@ -67,11 +67,43 @@ const defaultLocale = async (contentType, params)=>{
67
67
  }
68
68
  return params;
69
69
  };
70
+ /**
71
+ * Copy non-localized fields from an existing entry to a new entry being created
72
+ * for a different locale of the same document. Returns a new object with the merged data.
73
+ */ const copyNonLocalizedFields = async (contentType, documentId, dataToCreate)=>{
74
+ // Check if this is a localized content type and if i18n plugin is available
75
+ const i18nService = strapi.plugin('i18n')?.service('content-types');
76
+ if (!i18nService?.isLocalizedContentType(contentType)) {
77
+ return dataToCreate;
78
+ }
79
+ // Find an existing entry for the same document to copy unlocalized fields from
80
+ const existingEntry = await strapi.db.query(contentType.uid).findOne({
81
+ where: {
82
+ documentId
83
+ },
84
+ // Prefer published entry, but fall back to any entry
85
+ orderBy: {
86
+ publishedAt: 'desc'
87
+ }
88
+ });
89
+ // If an entry exists in another locale, copy its non-localized fields
90
+ if (existingEntry) {
91
+ const mergedData = {
92
+ ...dataToCreate
93
+ };
94
+ i18nService.fillNonLocalizedAttributes(mergedData, existingEntry, {
95
+ model: contentType.uid
96
+ });
97
+ return mergedData;
98
+ }
99
+ return dataToCreate;
100
+ };
70
101
  const defaultLocaleCurry = fp.curry(defaultLocale);
71
102
  const localeToLookupCurry = fp.curry(localeToLookup);
72
103
  const multiLocaleToLookupCurry = fp.curry(multiLocaleToLookup);
73
104
  const localeToDataCurry = fp.curry(localeToData);
74
105
 
106
+ exports.copyNonLocalizedFields = copyNonLocalizedFields;
75
107
  exports.defaultLocale = defaultLocaleCurry;
76
108
  exports.localeToData = localeToDataCurry;
77
109
  exports.localeToLookup = localeToLookupCurry;
@@ -1 +1 @@
1
- {"version":3,"file":"internationalization.js","sources":["../../../src/services/document-service/internationalization.ts"],"sourcesContent":["import type { Struct, Modules } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport { curry, assoc } from 'lodash/fp';\n\ntype Transform = (\n contentType: Struct.SingleTypeSchema | Struct.CollectionTypeSchema,\n params: Modules.Documents.Params.All\n) => Modules.Documents.Params.All;\n\ntype AsyncTransform = (\n contentType: Struct.SingleTypeSchema | Struct.CollectionTypeSchema,\n params: Modules.Documents.Params.All\n) => Promise<Modules.Documents.Params.All>;\n\nconst getDefaultLocale = async (): Promise<string> => {\n return strapi.plugin('i18n').service('locales').getDefaultLocale();\n};\n\nconst defaultLocale: AsyncTransform = async (contentType, params) => {\n if (!strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)) {\n return params;\n }\n\n if (!params.locale) {\n return assoc('locale', await getDefaultLocale(), params);\n }\n\n return params;\n};\n\n/**\n * Add locale lookup query to the params\n */\nconst localeToLookup: Transform = (contentType, params) => {\n if (\n !params.locale ||\n !strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)\n ) {\n return params;\n }\n\n if (typeof params.locale !== 'string') {\n // localeToLookup accepts locales of '*'. This is because the document\n // service functions that use this transform work with the '*' locale\n // to return all locales.\n throw new errors.ValidationError(\n `Invalid locale param ${String(params.locale)} provided. Document locales must be strings.`\n );\n }\n\n return assoc(['lookup', 'locale'], params.locale, params);\n};\n\n/**\n * Add locale lookup query to the params\n */\nconst multiLocaleToLookup: Transform = (contentType, params) => {\n if (!strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)) {\n return params;\n }\n\n if (params.locale) {\n if (params.locale === '*') {\n return params;\n }\n\n return assoc(['lookup', 'locale'], params.locale, params);\n }\n\n return params;\n};\n\n/**\n * Translate locale status parameter into the data that will be saved\n */\nconst localeToData: Transform = (contentType, params) => {\n if (!strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)) {\n return params;\n }\n\n if (params.locale) {\n const isValidLocale = typeof params.locale === 'string' && params.locale !== '*';\n if (isValidLocale) {\n return assoc(['data', 'locale'], params.locale, params);\n }\n\n throw new errors.ValidationError(\n `Invalid locale param ${params.locale} provided. Document locales must be strings.`\n );\n }\n\n return params;\n};\n\nconst defaultLocaleCurry = curry(defaultLocale);\nconst localeToLookupCurry = curry(localeToLookup);\nconst multiLocaleToLookupCurry = curry(multiLocaleToLookup);\nconst localeToDataCurry = curry(localeToData);\n\nexport {\n defaultLocaleCurry as defaultLocale,\n localeToLookupCurry as localeToLookup,\n localeToDataCurry as localeToData,\n multiLocaleToLookupCurry as multiLocaleToLookup,\n};\n"],"names":["getDefaultLocale","strapi","plugin","service","defaultLocale","contentType","params","isLocalizedContentType","locale","assoc","localeToLookup","errors","ValidationError","String","multiLocaleToLookup","localeToData","isValidLocale","defaultLocaleCurry","curry","localeToLookupCurry","multiLocaleToLookupCurry","localeToDataCurry"],"mappings":";;;;;AAcA,MAAMA,gBAAmB,GAAA,UAAA;AACvB,IAAA,OAAOC,OAAOC,MAAM,CAAC,QAAQC,OAAO,CAAC,WAAWH,gBAAgB,EAAA;AAClE,CAAA;AAEA,MAAMI,aAAAA,GAAgC,OAAOC,WAAaC,EAAAA,MAAAA,GAAAA;IACxD,IAAI,CAACL,MAAOC,CAAAA,MAAM,CAAC,MAAA,CAAA,CAAQC,OAAO,CAAC,eAAA,CAAA,CAAiBI,sBAAsB,CAACF,WAAc,CAAA,EAAA;QACvF,OAAOC,MAAAA;AACT;IAEA,IAAI,CAACA,MAAOE,CAAAA,MAAM,EAAE;QAClB,OAAOC,QAAAA,CAAM,QAAU,EAAA,MAAMT,gBAAoBM,EAAAA,EAAAA,MAAAA,CAAAA;AACnD;IAEA,OAAOA,MAAAA;AACT,CAAA;AAEA;;IAGA,MAAMI,cAA4B,GAAA,CAACL,WAAaC,EAAAA,MAAAA,GAAAA;AAC9C,IAAA,IACE,CAACA,MAAAA,CAAOE,MAAM,IACd,CAACP,MAAOC,CAAAA,MAAM,CAAC,MAAA,CAAA,CAAQC,OAAO,CAAC,eAAiBI,CAAAA,CAAAA,sBAAsB,CAACF,WACvE,CAAA,EAAA;QACA,OAAOC,MAAAA;AACT;AAEA,IAAA,IAAI,OAAOA,MAAAA,CAAOE,MAAM,KAAK,QAAU,EAAA;;;;AAIrC,QAAA,MAAM,IAAIG,kBAAAA,CAAOC,eAAe,CAC9B,CAAC,qBAAqB,EAAEC,MAAAA,CAAOP,MAAOE,CAAAA,MAAM,CAAE,CAAA,4CAA4C,CAAC,CAAA;AAE/F;AAEA,IAAA,OAAOC,QAAM,CAAA;AAAC,QAAA,QAAA;AAAU,QAAA;KAAS,EAAEH,MAAAA,CAAOE,MAAM,EAAEF,MAAAA,CAAAA;AACpD,CAAA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jC,MAAMe,sBAAsBD,QAAMR,CAAAA,cAAAA;AAClC,MAAMU,2BAA2BF,QAAMJ,CAAAA,mBAAAA;AACvC,MAAMO,oBAAoBH,QAAMH,CAAAA,YAAAA;;;;;;;"}
1
+ {"version":3,"file":"internationalization.js","sources":["../../../src/services/document-service/internationalization.ts"],"sourcesContent":["import type { Struct, Modules } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport { curry, assoc } from 'lodash/fp';\n\ntype Transform = (\n contentType: Struct.SingleTypeSchema | Struct.CollectionTypeSchema,\n params: Modules.Documents.Params.All\n) => Modules.Documents.Params.All;\n\ntype AsyncTransform = (\n contentType: Struct.SingleTypeSchema | Struct.CollectionTypeSchema,\n params: Modules.Documents.Params.All\n) => Promise<Modules.Documents.Params.All>;\n\nconst getDefaultLocale = async (): Promise<string> => {\n return strapi.plugin('i18n').service('locales').getDefaultLocale();\n};\n\nconst defaultLocale: AsyncTransform = async (contentType, params) => {\n if (!strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)) {\n return params;\n }\n\n if (!params.locale) {\n return assoc('locale', await getDefaultLocale(), params);\n }\n\n return params;\n};\n\n/**\n * Add locale lookup query to the params\n */\nconst localeToLookup: Transform = (contentType, params) => {\n if (\n !params.locale ||\n !strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)\n ) {\n return params;\n }\n\n if (typeof params.locale !== 'string') {\n // localeToLookup accepts locales of '*'. This is because the document\n // service functions that use this transform work with the '*' locale\n // to return all locales.\n throw new errors.ValidationError(\n `Invalid locale param ${String(params.locale)} provided. Document locales must be strings.`\n );\n }\n\n return assoc(['lookup', 'locale'], params.locale, params);\n};\n\n/**\n * Add locale lookup query to the params\n */\nconst multiLocaleToLookup: Transform = (contentType, params) => {\n if (!strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)) {\n return params;\n }\n\n if (params.locale) {\n if (params.locale === '*') {\n return params;\n }\n\n return assoc(['lookup', 'locale'], params.locale, params);\n }\n\n return params;\n};\n\n/**\n * Translate locale status parameter into the data that will be saved\n */\nconst localeToData: Transform = (contentType, params) => {\n if (!strapi.plugin('i18n').service('content-types').isLocalizedContentType(contentType)) {\n return params;\n }\n\n if (params.locale) {\n const isValidLocale = typeof params.locale === 'string' && params.locale !== '*';\n if (isValidLocale) {\n return assoc(['data', 'locale'], params.locale, params);\n }\n\n throw new errors.ValidationError(\n `Invalid locale param ${params.locale} provided. Document locales must be strings.`\n );\n }\n\n return params;\n};\n\n/**\n * Copy non-localized fields from an existing entry to a new entry being created\n * for a different locale of the same document. Returns a new object with the merged data.\n */\nconst copyNonLocalizedFields = async (\n contentType: Struct.SingleTypeSchema | Struct.CollectionTypeSchema,\n documentId: string,\n dataToCreate: Record<string, any>\n): Promise<Record<string, any>> => {\n // Check if this is a localized content type and if i18n plugin is available\n const i18nService = strapi.plugin('i18n')?.service('content-types');\n if (!i18nService?.isLocalizedContentType(contentType)) {\n return dataToCreate;\n }\n\n // Find an existing entry for the same document to copy unlocalized fields from\n const existingEntry = await strapi.db.query(contentType.uid).findOne({\n where: { documentId },\n // Prefer published entry, but fall back to any entry\n orderBy: { publishedAt: 'desc' },\n });\n\n // If an entry exists in another locale, copy its non-localized fields\n if (existingEntry) {\n const mergedData = { ...dataToCreate };\n i18nService.fillNonLocalizedAttributes(mergedData, existingEntry, {\n model: contentType.uid,\n });\n return mergedData;\n }\n\n return dataToCreate;\n};\n\nconst defaultLocaleCurry = curry(defaultLocale);\nconst localeToLookupCurry = curry(localeToLookup);\nconst multiLocaleToLookupCurry = curry(multiLocaleToLookup);\nconst localeToDataCurry = curry(localeToData);\n\nexport {\n defaultLocaleCurry as defaultLocale,\n localeToLookupCurry as localeToLookup,\n localeToDataCurry as localeToData,\n multiLocaleToLookupCurry as multiLocaleToLookup,\n copyNonLocalizedFields,\n};\n"],"names":["getDefaultLocale","strapi","plugin","service","defaultLocale","contentType","params","isLocalizedContentType","locale","assoc","localeToLookup","errors","ValidationError","String","multiLocaleToLookup","localeToData","isValidLocale","copyNonLocalizedFields","documentId","dataToCreate","i18nService","existingEntry","db","query","uid","findOne","where","orderBy","publishedAt","mergedData","fillNonLocalizedAttributes","model","defaultLocaleCurry","curry","localeToLookupCurry","multiLocaleToLookupCurry","localeToDataCurry"],"mappings":";;;;;AAcA,MAAMA,gBAAmB,GAAA,UAAA;AACvB,IAAA,OAAOC,OAAOC,MAAM,CAAC,QAAQC,OAAO,CAAC,WAAWH,gBAAgB,EAAA;AAClE,CAAA;AAEA,MAAMI,aAAAA,GAAgC,OAAOC,WAAaC,EAAAA,MAAAA,GAAAA;IACxD,IAAI,CAACL,MAAOC,CAAAA,MAAM,CAAC,MAAA,CAAA,CAAQC,OAAO,CAAC,eAAA,CAAA,CAAiBI,sBAAsB,CAACF,WAAc,CAAA,EAAA;QACvF,OAAOC,MAAAA;AACT;IAEA,IAAI,CAACA,MAAOE,CAAAA,MAAM,EAAE;QAClB,OAAOC,QAAAA,CAAM,QAAU,EAAA,MAAMT,gBAAoBM,EAAAA,EAAAA,MAAAA,CAAAA;AACnD;IAEA,OAAOA,MAAAA;AACT,CAAA;AAEA;;IAGA,MAAMI,cAA4B,GAAA,CAACL,WAAaC,EAAAA,MAAAA,GAAAA;AAC9C,IAAA,IACE,CAACA,MAAAA,CAAOE,MAAM,IACd,CAACP,MAAOC,CAAAA,MAAM,CAAC,MAAA,CAAA,CAAQC,OAAO,CAAC,eAAiBI,CAAAA,CAAAA,sBAAsB,CAACF,WACvE,CAAA,EAAA;QACA,OAAOC,MAAAA;AACT;AAEA,IAAA,IAAI,OAAOA,MAAAA,CAAOE,MAAM,KAAK,QAAU,EAAA;;;;AAIrC,QAAA,MAAM,IAAIG,kBAAAA,CAAOC,eAAe,CAC9B,CAAC,qBAAqB,EAAEC,MAAAA,CAAOP,MAAOE,CAAAA,MAAM,CAAE,CAAA,4CAA4C,CAAC,CAAA;AAE/F;AAEA,IAAA,OAAOC,QAAM,CAAA;AAAC,QAAA,QAAA;AAAU,QAAA;KAAS,EAAEH,MAA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