@strapi/content-releases 0.0.0-experimental.check-license → 4.16.0

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.
Files changed (89) hide show
  1. package/dist/_chunks/App-b6df6b60.js +797 -0
  2. package/dist/_chunks/App-b6df6b60.js.map +1 -0
  3. package/dist/_chunks/App-b83f4a97.mjs +775 -0
  4. package/dist/_chunks/App-b83f4a97.mjs.map +1 -0
  5. package/dist/_chunks/en-b5dfabe6.js +47 -0
  6. package/dist/_chunks/en-b5dfabe6.js.map +1 -0
  7. package/dist/_chunks/en-d837b82d.mjs +47 -0
  8. package/dist/_chunks/en-d837b82d.mjs.map +1 -0
  9. package/dist/_chunks/index-28e99164.js +784 -0
  10. package/dist/_chunks/index-28e99164.js.map +1 -0
  11. package/dist/_chunks/index-c39292e3.mjs +763 -0
  12. package/dist/_chunks/index-c39292e3.mjs.map +1 -0
  13. package/dist/admin/index.js +16 -35
  14. package/dist/admin/index.js.map +1 -1
  15. package/dist/admin/index.mjs +16 -35
  16. package/dist/admin/index.mjs.map +1 -1
  17. package/dist/admin/src/components/CMReleasesContainer.d.ts +1 -0
  18. package/dist/admin/src/components/ReleaseActionMenu.d.ts +7 -0
  19. package/dist/admin/src/components/ReleaseActionOptions.d.ts +8 -0
  20. package/dist/admin/src/components/ReleaseModal.d.ts +11 -0
  21. package/dist/admin/src/constants.d.ts +13 -0
  22. package/dist/admin/src/index.d.ts +3 -15
  23. package/dist/admin/src/pages/App.d.ts +1 -0
  24. package/dist/admin/src/pages/ReleaseDetailsPage.d.ts +10 -0
  25. package/dist/admin/src/pages/ReleasesPage.d.ts +11 -0
  26. package/dist/admin/src/pages/tests/mockReleaseDetailsPageData.d.ts +104 -0
  27. package/dist/admin/src/pages/tests/mockReleasesPageData.d.ts +38 -0
  28. package/dist/admin/src/pluginId.d.ts +1 -0
  29. package/dist/admin/src/services/axios.d.ts +29 -0
  30. package/dist/admin/src/services/release.d.ts +348 -0
  31. package/dist/server/index.js +861 -6
  32. package/dist/server/index.js.map +1 -1
  33. package/dist/server/index.mjs +842 -6
  34. package/dist/server/index.mjs.map +1 -1
  35. package/dist/server/src/constants.d.ts +9 -0
  36. package/dist/server/src/constants.d.ts.map +1 -0
  37. package/dist/server/src/content-types/index.d.ts +82 -0
  38. package/dist/server/src/content-types/index.d.ts.map +1 -0
  39. package/dist/server/src/content-types/release/index.d.ts +37 -0
  40. package/dist/server/src/content-types/release/index.d.ts.map +1 -0
  41. package/dist/server/src/content-types/release/schema.d.ts +36 -0
  42. package/dist/server/src/content-types/release/schema.d.ts.map +1 -0
  43. package/dist/server/src/content-types/release-action/index.d.ts +44 -0
  44. package/dist/server/src/content-types/release-action/index.d.ts.map +1 -0
  45. package/dist/server/src/content-types/release-action/schema.d.ts +43 -0
  46. package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -0
  47. package/dist/server/src/controllers/index.d.ts +18 -0
  48. package/dist/server/src/controllers/index.d.ts.map +1 -0
  49. package/dist/server/src/controllers/release-action.d.ts +9 -0
  50. package/dist/server/src/controllers/release-action.d.ts.map +1 -0
  51. package/dist/server/src/controllers/release.d.ts +11 -0
  52. package/dist/server/src/controllers/release.d.ts.map +1 -0
  53. package/dist/server/src/controllers/validation/release-action.d.ts +3 -0
  54. package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -0
  55. package/dist/server/src/controllers/validation/release.d.ts +2 -0
  56. package/dist/server/src/controllers/validation/release.d.ts.map +1 -0
  57. package/dist/server/src/index.d.ts +298 -1
  58. package/dist/server/src/index.d.ts.map +1 -0
  59. package/dist/server/src/register.d.ts +5 -1
  60. package/dist/server/src/register.d.ts.map +1 -0
  61. package/dist/server/src/routes/index.d.ts +35 -0
  62. package/dist/server/src/routes/index.d.ts.map +1 -0
  63. package/dist/server/src/routes/release-action.d.ts +18 -0
  64. package/dist/server/src/routes/release-action.d.ts.map +1 -0
  65. package/dist/server/src/routes/release.d.ts +18 -0
  66. package/dist/server/src/routes/release.d.ts.map +1 -0
  67. package/dist/server/src/services/index.d.ts +77 -0
  68. package/dist/server/src/services/index.d.ts.map +1 -0
  69. package/dist/server/src/services/release.d.ts +55 -0
  70. package/dist/server/src/services/release.d.ts.map +1 -0
  71. package/dist/server/src/services/validation.d.ts +10 -0
  72. package/dist/server/src/services/validation.d.ts.map +1 -0
  73. package/dist/server/src/utils/index.d.ts +4 -0
  74. package/dist/server/src/utils/index.d.ts.map +1 -0
  75. package/dist/shared/contracts/release-actions.d.ts +95 -0
  76. package/dist/shared/contracts/release-actions.d.ts.map +1 -0
  77. package/dist/shared/contracts/releases.d.ts +153 -0
  78. package/dist/shared/contracts/releases.d.ts.map +1 -0
  79. package/dist/shared/types.d.ts +24 -0
  80. package/dist/shared/types.d.ts.map +1 -0
  81. package/dist/shared/validation-schemas.d.ts +2 -0
  82. package/dist/shared/validation-schemas.d.ts.map +1 -0
  83. package/package.json +29 -18
  84. package/dist/_chunks/en-21947221.js +0 -5
  85. package/dist/_chunks/en-21947221.js.map +0 -1
  86. package/dist/_chunks/en-92157b33.mjs +0 -5
  87. package/dist/_chunks/en-92157b33.mjs.map +0 -1
  88. package/dist/admin/src/tests/index.test.d.ts +0 -0
  89. package/dist/server/src/__tests__/index.test.d.ts +0 -2
@@ -1,12 +1,848 @@
1
- const { features } = require("@strapi/strapi/dist/utils/ee");
2
- const register = () => {
3
- if (features.isEnabled("cms-content-releases")) {
4
- console.log("cms-content-releases is enabled");
1
+ import { setCreatorFields, errors, validateYupSchema, yup as yup$1 } from "@strapi/utils";
2
+ import * as yup from "yup";
3
+ const RELEASE_MODEL_UID = "plugin::content-releases.release";
4
+ const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
5
+ const ACTIONS = [
6
+ {
7
+ section: "plugins",
8
+ displayName: "Read",
9
+ uid: "read",
10
+ pluginName: "content-releases"
11
+ },
12
+ {
13
+ section: "plugins",
14
+ displayName: "Create",
15
+ uid: "create",
16
+ pluginName: "content-releases"
17
+ },
18
+ {
19
+ section: "plugins",
20
+ displayName: "Edit",
21
+ uid: "update",
22
+ pluginName: "content-releases"
23
+ },
24
+ {
25
+ section: "plugins",
26
+ displayName: "Delete",
27
+ uid: "delete",
28
+ pluginName: "content-releases"
29
+ },
30
+ {
31
+ section: "plugins",
32
+ displayName: "Publish",
33
+ uid: "publish",
34
+ pluginName: "content-releases"
35
+ },
36
+ {
37
+ section: "plugins",
38
+ displayName: "Remove an entry from a release",
39
+ uid: "delete-action",
40
+ pluginName: "content-releases"
41
+ },
42
+ {
43
+ section: "plugins",
44
+ displayName: "Add an entry to a release",
45
+ uid: "create-action",
46
+ pluginName: "content-releases"
47
+ }
48
+ ];
49
+ const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
50
+ const register = async ({ strapi: strapi2 }) => {
51
+ if (features$1.isEnabled("cms-content-releases") && strapi2.features.future.isEnabled("contentReleases")) {
52
+ await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
53
+ }
54
+ };
55
+ const schema$1 = {
56
+ collectionName: "strapi_releases",
57
+ info: {
58
+ singularName: "release",
59
+ pluralName: "releases",
60
+ displayName: "Release"
61
+ },
62
+ options: {
63
+ draftAndPublish: false
64
+ },
65
+ pluginOptions: {
66
+ "content-manager": {
67
+ visible: false
68
+ },
69
+ "content-type-builder": {
70
+ visible: false
71
+ }
72
+ },
73
+ attributes: {
74
+ name: {
75
+ type: "string",
76
+ required: true
77
+ },
78
+ releasedAt: {
79
+ type: "datetime"
80
+ },
81
+ actions: {
82
+ type: "relation",
83
+ relation: "oneToMany",
84
+ target: RELEASE_ACTION_MODEL_UID,
85
+ mappedBy: "release"
86
+ }
5
87
  }
6
88
  };
7
- const index = {
8
- register
89
+ const release$1 = {
90
+ schema: schema$1
91
+ };
92
+ const schema = {
93
+ collectionName: "strapi_release_actions",
94
+ info: {
95
+ singularName: "release-action",
96
+ pluralName: "release-actions",
97
+ displayName: "Release Action"
98
+ },
99
+ options: {
100
+ draftAndPublish: false
101
+ },
102
+ pluginOptions: {
103
+ "content-manager": {
104
+ visible: false
105
+ },
106
+ "content-type-builder": {
107
+ visible: false
108
+ }
109
+ },
110
+ attributes: {
111
+ type: {
112
+ type: "enumeration",
113
+ enum: ["publish", "unpublish"],
114
+ required: true
115
+ },
116
+ entry: {
117
+ type: "relation",
118
+ relation: "morphToOne",
119
+ configurable: false
120
+ },
121
+ contentType: {
122
+ type: "string",
123
+ required: true
124
+ },
125
+ release: {
126
+ type: "relation",
127
+ relation: "manyToOne",
128
+ target: RELEASE_MODEL_UID,
129
+ inversedBy: "actions"
130
+ }
131
+ }
132
+ };
133
+ const releaseAction$1 = {
134
+ schema
135
+ };
136
+ const contentTypes = {
137
+ release: release$1,
138
+ "release-action": releaseAction$1
139
+ };
140
+ const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
141
+ return strapi2.plugin("content-releases").service(name);
142
+ };
143
+ const createReleaseService = ({ strapi: strapi2 }) => ({
144
+ async create(releaseData, { user }) {
145
+ const releaseWithCreatorFields = await setCreatorFields({ user })(releaseData);
146
+ return strapi2.entityService.create(RELEASE_MODEL_UID, {
147
+ data: releaseWithCreatorFields
148
+ });
149
+ },
150
+ async findOne(id, query = {}) {
151
+ const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
152
+ ...query
153
+ });
154
+ return release2;
155
+ },
156
+ findPage(query) {
157
+ return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
158
+ ...query,
159
+ populate: {
160
+ actions: {
161
+ // @ts-expect-error Ignore missing properties
162
+ count: true
163
+ }
164
+ }
165
+ });
166
+ },
167
+ async findManyForContentTypeEntry(contentTypeUid, entryId, {
168
+ hasEntryAttached
169
+ } = {
170
+ hasEntryAttached: false
171
+ }) {
172
+ const whereActions = hasEntryAttached ? {
173
+ // Find all Releases where the content type entry is present
174
+ actions: {
175
+ target_type: contentTypeUid,
176
+ target_id: entryId
177
+ }
178
+ } : {
179
+ // Find all Releases where the content type entry is not present
180
+ $or: [
181
+ {
182
+ $not: {
183
+ actions: {
184
+ target_type: contentTypeUid,
185
+ target_id: entryId
186
+ }
187
+ }
188
+ },
189
+ {
190
+ actions: null
191
+ }
192
+ ]
193
+ };
194
+ const populateAttachedAction = hasEntryAttached ? {
195
+ // Filter the action to get only the content type entry
196
+ actions: {
197
+ where: {
198
+ target_type: contentTypeUid,
199
+ target_id: entryId
200
+ }
201
+ }
202
+ } : {};
203
+ const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
204
+ where: {
205
+ ...whereActions,
206
+ releasedAt: {
207
+ $null: true
208
+ }
209
+ },
210
+ populate: {
211
+ ...populateAttachedAction
212
+ }
213
+ });
214
+ return releases.map((release2) => {
215
+ if (release2.actions?.length) {
216
+ const [actionForEntry] = release2.actions;
217
+ delete release2.actions;
218
+ return {
219
+ ...release2,
220
+ action: actionForEntry
221
+ };
222
+ }
223
+ return release2;
224
+ });
225
+ },
226
+ async update(id, releaseData, { user }) {
227
+ const updatedRelease = await setCreatorFields({ user, isEdition: true })(releaseData);
228
+ const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
229
+ /*
230
+ * The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
231
+ * is not compatible with the type we are passing here: UpdateRelease.Request['body']
232
+ */
233
+ // @ts-expect-error see above
234
+ data: updatedRelease
235
+ });
236
+ if (!release2) {
237
+ throw new errors.NotFoundError(`No release found for id ${id}`);
238
+ }
239
+ return release2;
240
+ },
241
+ async createAction(releaseId, action) {
242
+ const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
243
+ strapi: strapi2
244
+ });
245
+ await Promise.all([
246
+ validateEntryContentType(action.entry.contentType),
247
+ validateUniqueEntry(releaseId, action)
248
+ ]);
249
+ const { entry, type } = action;
250
+ return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
251
+ data: {
252
+ type,
253
+ contentType: entry.contentType,
254
+ entry: {
255
+ id: entry.id,
256
+ __type: entry.contentType,
257
+ __pivot: { field: "entry" }
258
+ },
259
+ release: releaseId
260
+ },
261
+ populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
262
+ });
263
+ },
264
+ async findActions(releaseId, query) {
265
+ const result = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
266
+ if (!result) {
267
+ throw new errors.NotFoundError(`No release found for id ${releaseId}`);
268
+ }
269
+ return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
270
+ ...query,
271
+ populate: {
272
+ entry: true
273
+ },
274
+ filters: {
275
+ release: releaseId
276
+ }
277
+ });
278
+ },
279
+ async countActions(query) {
280
+ return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
281
+ },
282
+ async getAllContentTypeUids(releaseId) {
283
+ const contentTypesFromReleaseActions = await strapi2.db.queryBuilder(RELEASE_ACTION_MODEL_UID).select("content_type").where({
284
+ $and: [
285
+ {
286
+ release: releaseId
287
+ }
288
+ ]
289
+ }).groupBy("content_type").execute();
290
+ return contentTypesFromReleaseActions.map(({ contentType: contentTypeUid }) => contentTypeUid);
291
+ },
292
+ async getContentTypesDataForActions(releaseId) {
293
+ const contentTypesUids = await this.getAllContentTypeUids(releaseId);
294
+ const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
295
+ const contentTypesData = {};
296
+ for (const contentTypeUid of contentTypesUids) {
297
+ const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
298
+ uid: contentTypeUid
299
+ });
300
+ contentTypesData[contentTypeUid] = {
301
+ mainField: contentTypeConfig.settings.mainField,
302
+ displayName: strapi2.getModel(contentTypeUid).info.displayName
303
+ };
304
+ }
305
+ return contentTypesData;
306
+ },
307
+ async delete(releaseId) {
308
+ const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
309
+ populate: {
310
+ actions: {
311
+ fields: ["id"]
312
+ }
313
+ }
314
+ });
315
+ if (!release2) {
316
+ throw new errors.NotFoundError(`No release found for id ${releaseId}`);
317
+ }
318
+ if (release2.releasedAt) {
319
+ throw new errors.ValidationError("Release already published");
320
+ }
321
+ await strapi2.db.transaction(async () => {
322
+ await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
323
+ where: {
324
+ id: {
325
+ $in: release2.actions.map((action) => action.id)
326
+ }
327
+ }
328
+ });
329
+ await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
330
+ });
331
+ return release2;
332
+ },
333
+ async publish(releaseId) {
334
+ const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
335
+ RELEASE_MODEL_UID,
336
+ releaseId,
337
+ {
338
+ populate: {
339
+ actions: {
340
+ populate: {
341
+ entry: true
342
+ }
343
+ }
344
+ }
345
+ }
346
+ );
347
+ if (!releaseWithPopulatedActionEntries) {
348
+ throw new errors.NotFoundError(`No release found for id ${releaseId}`);
349
+ }
350
+ if (releaseWithPopulatedActionEntries.releasedAt) {
351
+ throw new errors.ValidationError("Release already published");
352
+ }
353
+ if (releaseWithPopulatedActionEntries.actions.length === 0) {
354
+ throw new errors.ValidationError("No entries to publish");
355
+ }
356
+ const actions = {};
357
+ for (const action of releaseWithPopulatedActionEntries.actions) {
358
+ const contentTypeUid = action.contentType;
359
+ if (!actions[contentTypeUid]) {
360
+ actions[contentTypeUid] = {
361
+ publish: [],
362
+ unpublish: []
363
+ };
364
+ }
365
+ if (action.type === "publish") {
366
+ actions[contentTypeUid].publish.push(action.entry);
367
+ } else {
368
+ actions[contentTypeUid].unpublish.push(action.entry);
369
+ }
370
+ }
371
+ const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
372
+ await strapi2.db.transaction(async () => {
373
+ for (const contentTypeUid of Object.keys(actions)) {
374
+ const { publish, unpublish } = actions[contentTypeUid];
375
+ if (publish.length > 0) {
376
+ await entityManagerService.publishMany(publish, contentTypeUid);
377
+ }
378
+ if (unpublish.length > 0) {
379
+ await entityManagerService.unpublishMany(unpublish, contentTypeUid);
380
+ }
381
+ }
382
+ });
383
+ const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
384
+ data: {
385
+ /*
386
+ * The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
387
+ */
388
+ // @ts-expect-error see above
389
+ releasedAt: /* @__PURE__ */ new Date()
390
+ }
391
+ });
392
+ return release2;
393
+ },
394
+ async updateAction(actionId, releaseId, update) {
395
+ const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
396
+ where: {
397
+ id: actionId,
398
+ release: releaseId
399
+ },
400
+ data: update
401
+ });
402
+ if (!updatedAction) {
403
+ throw new errors.NotFoundError(
404
+ `Action with id ${actionId} not found in release with id ${releaseId}`
405
+ );
406
+ }
407
+ return updatedAction;
408
+ },
409
+ async deleteAction(actionId, releaseId) {
410
+ const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
411
+ where: {
412
+ id: actionId,
413
+ release: releaseId
414
+ }
415
+ });
416
+ if (!deletedAction) {
417
+ throw new errors.NotFoundError(
418
+ `Action with id ${actionId} not found in release with id ${releaseId}`
419
+ );
420
+ }
421
+ return deletedAction;
422
+ }
423
+ });
424
+ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
425
+ async validateUniqueEntry(releaseId, releaseActionArgs) {
426
+ const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
427
+ populate: { actions: { populate: { entry: { fields: ["id"] } } } }
428
+ });
429
+ if (!release2) {
430
+ throw new errors.NotFoundError(`No release found for id ${releaseId}`);
431
+ }
432
+ const isEntryInRelease = release2.actions.some(
433
+ (action) => Number(action.entry.id) === Number(releaseActionArgs.entry.id) && action.contentType === releaseActionArgs.entry.contentType
434
+ );
435
+ if (isEntryInRelease) {
436
+ throw new errors.ValidationError(
437
+ `Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
438
+ );
439
+ }
440
+ },
441
+ validateEntryContentType(contentTypeUid) {
442
+ const contentType = strapi2.contentType(contentTypeUid);
443
+ if (!contentType) {
444
+ throw new errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
445
+ }
446
+ if (!contentType.options?.draftAndPublish) {
447
+ throw new errors.ValidationError(
448
+ `Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
449
+ );
450
+ }
451
+ }
452
+ });
453
+ const services = { release: createReleaseService, "release-validation": createReleaseValidationService };
454
+ const RELEASE_SCHEMA = yup.object().shape({
455
+ name: yup.string().trim().required()
456
+ }).required().noUnknown();
457
+ const validateRelease = validateYupSchema(RELEASE_SCHEMA);
458
+ const releaseController = {
459
+ async findMany(ctx) {
460
+ const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
461
+ ability: ctx.state.userAbility,
462
+ model: RELEASE_MODEL_UID
463
+ });
464
+ await permissionsManager.validateQuery(ctx.query);
465
+ const releaseService = getService("release", { strapi });
466
+ const isFindManyForContentTypeEntry = Boolean(ctx.query?.contentTypeUid && ctx.query?.entryId);
467
+ if (isFindManyForContentTypeEntry) {
468
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
469
+ const contentTypeUid = query.contentTypeUid;
470
+ const entryId = query.entryId;
471
+ const hasEntryAttached = typeof query.hasEntryAttached === "string" ? JSON.parse(query.hasEntryAttached) : false;
472
+ const data = await releaseService.findManyForContentTypeEntry(contentTypeUid, entryId, {
473
+ hasEntryAttached
474
+ });
475
+ ctx.body = { data };
476
+ } else {
477
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
478
+ const { results, pagination } = await releaseService.findPage(query);
479
+ const data = results.map((release2) => {
480
+ const { actions, ...releaseData } = release2;
481
+ return {
482
+ ...releaseData,
483
+ actions: {
484
+ meta: {
485
+ count: actions.count
486
+ }
487
+ }
488
+ };
489
+ });
490
+ ctx.body = { data, meta: { pagination } };
491
+ }
492
+ },
493
+ async findOne(ctx) {
494
+ const id = ctx.params.id;
495
+ const releaseService = getService("release", { strapi });
496
+ const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
497
+ const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
498
+ ability: ctx.state.userAbility,
499
+ model: RELEASE_MODEL_UID
500
+ });
501
+ const sanitizedRelease = await permissionsManager.sanitizeOutput(release2);
502
+ const count = await releaseService.countActions({
503
+ filters: {
504
+ release: id
505
+ }
506
+ });
507
+ if (!release2) {
508
+ throw new errors.NotFoundError(`Release not found for id: ${id}`);
509
+ }
510
+ const data = {
511
+ ...sanitizedRelease,
512
+ actions: {
513
+ meta: {
514
+ count
515
+ }
516
+ }
517
+ };
518
+ ctx.body = { data };
519
+ },
520
+ async create(ctx) {
521
+ const user = ctx.state.user;
522
+ const releaseArgs = ctx.request.body;
523
+ await validateRelease(releaseArgs);
524
+ const releaseService = getService("release", { strapi });
525
+ const release2 = await releaseService.create(releaseArgs, { user });
526
+ const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
527
+ ability: ctx.state.userAbility,
528
+ model: RELEASE_MODEL_UID
529
+ });
530
+ ctx.body = {
531
+ data: await permissionsManager.sanitizeOutput(release2)
532
+ };
533
+ },
534
+ async update(ctx) {
535
+ const user = ctx.state.user;
536
+ const releaseArgs = ctx.request.body;
537
+ const id = ctx.params.id;
538
+ await validateRelease(releaseArgs);
539
+ const releaseService = getService("release", { strapi });
540
+ const release2 = await releaseService.update(id, releaseArgs, { user });
541
+ const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
542
+ ability: ctx.state.userAbility,
543
+ model: RELEASE_MODEL_UID
544
+ });
545
+ ctx.body = {
546
+ data: await permissionsManager.sanitizeOutput(release2)
547
+ };
548
+ },
549
+ async delete(ctx) {
550
+ const id = ctx.params.id;
551
+ const releaseService = getService("release", { strapi });
552
+ const release2 = await releaseService.delete(id);
553
+ ctx.body = {
554
+ data: release2
555
+ };
556
+ },
557
+ async publish(ctx) {
558
+ const user = ctx.state.user;
559
+ const id = ctx.params.id;
560
+ const releaseService = getService("release", { strapi });
561
+ const release2 = await releaseService.publish(id, { user });
562
+ ctx.body = {
563
+ data: release2
564
+ };
565
+ }
566
+ };
567
+ const RELEASE_ACTION_SCHEMA = yup$1.object().shape({
568
+ entry: yup$1.object().shape({
569
+ id: yup$1.strapiID().required(),
570
+ contentType: yup$1.string().required()
571
+ }).required(),
572
+ type: yup$1.string().oneOf(["publish", "unpublish"]).required()
573
+ });
574
+ const RELEASE_ACTION_UPDATE_SCHEMA = yup$1.object().shape({
575
+ type: yup$1.string().oneOf(["publish", "unpublish"]).required()
576
+ });
577
+ const validateReleaseAction = validateYupSchema(RELEASE_ACTION_SCHEMA);
578
+ const validateReleaseActionUpdateSchema = validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
579
+ const releaseActionController = {
580
+ async create(ctx) {
581
+ const releaseId = ctx.params.releaseId;
582
+ const releaseActionArgs = ctx.request.body;
583
+ await validateReleaseAction(releaseActionArgs);
584
+ const releaseService = getService("release", { strapi });
585
+ const releaseAction2 = await releaseService.createAction(releaseId, releaseActionArgs);
586
+ ctx.body = {
587
+ data: releaseAction2
588
+ };
589
+ },
590
+ async findMany(ctx) {
591
+ const releaseId = ctx.params.releaseId;
592
+ const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
593
+ ability: ctx.state.userAbility,
594
+ model: RELEASE_ACTION_MODEL_UID
595
+ });
596
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
597
+ const releaseService = getService("release", { strapi });
598
+ const { results, pagination } = await releaseService.findActions(releaseId, query);
599
+ const allReleaseContentTypesDictionary = await releaseService.getContentTypesDataForActions(
600
+ releaseId
601
+ );
602
+ const allLocales = await strapi.plugin("i18n").service("locales").find();
603
+ const allLocalesDictionary = allLocales.reduce((acc, locale) => {
604
+ acc[locale.code] = { name: locale.name, code: locale.code };
605
+ return acc;
606
+ }, {});
607
+ const data = results.map((action) => {
608
+ const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
609
+ return {
610
+ ...action,
611
+ entry: {
612
+ id: action.entry.id,
613
+ contentType: {
614
+ displayName,
615
+ mainFieldValue: action.entry[mainField]
616
+ },
617
+ locale: allLocalesDictionary[action.entry.locale]
618
+ }
619
+ };
620
+ });
621
+ ctx.body = {
622
+ data,
623
+ meta: {
624
+ pagination
625
+ }
626
+ };
627
+ },
628
+ async update(ctx) {
629
+ const actionId = ctx.params.actionId;
630
+ const releaseId = ctx.params.releaseId;
631
+ const releaseActionUpdateArgs = ctx.request.body;
632
+ await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
633
+ const releaseService = getService("release", { strapi });
634
+ const updatedAction = await releaseService.updateAction(
635
+ actionId,
636
+ releaseId,
637
+ releaseActionUpdateArgs
638
+ );
639
+ ctx.body = {
640
+ data: updatedAction
641
+ };
642
+ },
643
+ async delete(ctx) {
644
+ const actionId = ctx.params.actionId;
645
+ const releaseId = ctx.params.releaseId;
646
+ const deletedReleaseAction = await getService("release", { strapi }).deleteAction(
647
+ actionId,
648
+ releaseId
649
+ );
650
+ ctx.body = {
651
+ data: deletedReleaseAction
652
+ };
653
+ }
654
+ };
655
+ const controllers = { release: releaseController, "release-action": releaseActionController };
656
+ const release = {
657
+ type: "admin",
658
+ routes: [
659
+ {
660
+ method: "POST",
661
+ path: "/",
662
+ handler: "release.create",
663
+ config: {
664
+ policies: [
665
+ "admin::isAuthenticatedAdmin",
666
+ {
667
+ name: "admin::hasPermissions",
668
+ config: {
669
+ actions: ["plugin::content-releases.create"]
670
+ }
671
+ }
672
+ ]
673
+ }
674
+ },
675
+ {
676
+ method: "GET",
677
+ path: "/",
678
+ handler: "release.findMany",
679
+ config: {
680
+ policies: [
681
+ "admin::isAuthenticatedAdmin",
682
+ {
683
+ name: "admin::hasPermissions",
684
+ config: {
685
+ actions: ["plugin::content-releases.read"]
686
+ }
687
+ }
688
+ ]
689
+ }
690
+ },
691
+ {
692
+ method: "GET",
693
+ path: "/:id",
694
+ handler: "release.findOne",
695
+ config: {
696
+ policies: [
697
+ "admin::isAuthenticatedAdmin",
698
+ {
699
+ name: "admin::hasPermissions",
700
+ config: {
701
+ actions: ["plugin::content-releases.read"]
702
+ }
703
+ }
704
+ ]
705
+ }
706
+ },
707
+ {
708
+ method: "PUT",
709
+ path: "/:id",
710
+ handler: "release.update",
711
+ config: {
712
+ policies: [
713
+ "admin::isAuthenticatedAdmin",
714
+ {
715
+ name: "admin::hasPermissions",
716
+ config: {
717
+ actions: ["plugin::content-releases.update"]
718
+ }
719
+ }
720
+ ]
721
+ }
722
+ },
723
+ {
724
+ method: "DELETE",
725
+ path: "/:id",
726
+ handler: "release.delete",
727
+ config: {
728
+ policies: [
729
+ "admin::isAuthenticatedAdmin",
730
+ {
731
+ name: "admin::hasPermissions",
732
+ config: {
733
+ actions: ["plugin::content-releases.delete"]
734
+ }
735
+ }
736
+ ]
737
+ }
738
+ },
739
+ {
740
+ method: "POST",
741
+ path: "/:id/publish",
742
+ handler: "release.publish",
743
+ config: {
744
+ policies: [
745
+ "admin::isAuthenticatedAdmin",
746
+ {
747
+ name: "admin::hasPermissions",
748
+ config: {
749
+ actions: ["plugin::content-releases.publish"]
750
+ }
751
+ }
752
+ ]
753
+ }
754
+ }
755
+ ]
756
+ };
757
+ const releaseAction = {
758
+ type: "admin",
759
+ routes: [
760
+ {
761
+ method: "POST",
762
+ path: "/:releaseId/actions",
763
+ handler: "release-action.create",
764
+ config: {
765
+ policies: [
766
+ "admin::isAuthenticatedAdmin",
767
+ {
768
+ name: "admin::hasPermissions",
769
+ config: {
770
+ actions: ["plugin::content-releases.create-action"]
771
+ }
772
+ }
773
+ ]
774
+ }
775
+ },
776
+ {
777
+ method: "GET",
778
+ path: "/:releaseId/actions",
779
+ handler: "release-action.findMany",
780
+ config: {
781
+ policies: [
782
+ "admin::isAuthenticatedAdmin",
783
+ {
784
+ name: "admin::hasPermissions",
785
+ config: {
786
+ actions: ["plugin::content-releases.read"]
787
+ }
788
+ }
789
+ ]
790
+ }
791
+ },
792
+ {
793
+ method: "PUT",
794
+ path: "/:releaseId/actions/:actionId",
795
+ handler: "release-action.update",
796
+ config: {
797
+ policies: [
798
+ "admin::isAuthenticatedAdmin",
799
+ {
800
+ name: "admin::hasPermissions",
801
+ config: {
802
+ actions: ["plugin::content-releases.update"]
803
+ }
804
+ }
805
+ ]
806
+ }
807
+ },
808
+ {
809
+ method: "DELETE",
810
+ path: "/:releaseId/actions/:actionId",
811
+ handler: "release-action.delete",
812
+ config: {
813
+ policies: [
814
+ "admin::isAuthenticatedAdmin",
815
+ {
816
+ name: "admin::hasPermissions",
817
+ config: {
818
+ actions: ["plugin::content-releases.delete-action"]
819
+ }
820
+ }
821
+ ]
822
+ }
823
+ }
824
+ ]
825
+ };
826
+ const routes = {
827
+ release,
828
+ "release-action": releaseAction
829
+ };
830
+ const { features } = require("@strapi/strapi/dist/utils/ee");
831
+ const getPlugin = () => {
832
+ if (features.isEnabled("cms-content-releases") && strapi.features.future.isEnabled("contentReleases")) {
833
+ return {
834
+ register,
835
+ contentTypes,
836
+ services,
837
+ controllers,
838
+ routes
839
+ };
840
+ }
841
+ return {
842
+ contentTypes
843
+ };
9
844
  };
845
+ const index = getPlugin();
10
846
  export {
11
847
  index as default
12
848
  };