@primershop/strapi-plugin-status-manager 0.0.4 → 0.0.5

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 (32) hide show
  1. package/package.json +3 -2
  2. package/dist/admin/src/components/Initializer.js +0 -13
  3. package/dist/admin/src/components/PluginIcon.js +0 -4
  4. package/dist/admin/src/components/ProductStatusField.js +0 -64
  5. package/dist/admin/src/components/StatusManager.js +0 -239
  6. package/dist/admin/src/index.js +0 -43
  7. package/dist/admin/src/listView/StatusFilter.js +0 -47
  8. package/dist/admin/src/listView/add-status-column-hook.js +0 -18
  9. package/dist/admin/src/listView/status-cell.js +0 -18
  10. package/dist/admin/src/pages/HomePage.js +0 -18
  11. package/dist/admin/src/pluginId.js +0 -1
  12. package/dist/server/src/bootstrap.js +0 -32
  13. package/dist/server/src/config/dev.js +0 -13
  14. package/dist/server/src/content-types/index.js +0 -15
  15. package/dist/server/src/content-types/status-link.js +0 -40
  16. package/dist/server/src/content-types/status.js +0 -47
  17. package/dist/server/src/controllers/content.js +0 -44
  18. package/dist/server/src/controllers/index.js +0 -9
  19. package/dist/server/src/controllers/status.js +0 -106
  20. package/dist/server/src/index.js +0 -23
  21. package/dist/server/src/middlewares/add-status-field.js +0 -51
  22. package/dist/server/src/middlewares/filter-by-status.js +0 -44
  23. package/dist/server/src/middlewares/filter-published.js +0 -31
  24. package/dist/server/src/permissions.js +0 -41
  25. package/dist/server/src/pluginId.js +0 -4
  26. package/dist/server/src/register.js +0 -28
  27. package/dist/server/src/routes/content-management.js +0 -34
  28. package/dist/server/src/routes/index.js +0 -15
  29. package/dist/server/src/routes/status-management.js +0 -109
  30. package/dist/server/src/services/index.js +0 -9
  31. package/dist/server/src/services/status-link.js +0 -33
  32. package/dist/server/src/services/status.js +0 -96
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.content = void 0;
4
- const content = ({ strapi }) => ({
5
- async getStatusForTarget(ctx) {
6
- var _a;
7
- const requestParams = ctx.request.URL.searchParams;
8
- const contentTypeUid = requestParams.get("contentTypeUid");
9
- if (!strapi.getModel(contentTypeUid))
10
- return ctx.notFound("Unknown contentTypeUid");
11
- const contentDocumentId = requestParams.get("contentDocumentId");
12
- const exists = await strapi
13
- .documents(contentTypeUid)
14
- .findOne({
15
- documentId: contentDocumentId,
16
- });
17
- if (!exists)
18
- return ctx.notFound("Target document not found");
19
- const link = await strapi
20
- .plugin("primershop-status-manager")
21
- .service("statusLink")
22
- .getForTarget(contentTypeUid, contentDocumentId);
23
- return ctx.send({ status: (_a = link === null || link === void 0 ? void 0 : link.status) !== null && _a !== void 0 ? _a : null });
24
- },
25
- async setStatusForTarget(ctx) {
26
- const { contentTypeUid, contentDocumentId, statusId } = ctx.request
27
- .body;
28
- if (!strapi.getModel(contentTypeUid))
29
- return ctx.notFound("Unknown contentTypeUid");
30
- const exists = await strapi
31
- .documents(contentTypeUid)
32
- .findOne({
33
- documentId: contentDocumentId,
34
- });
35
- if (!exists)
36
- return ctx.notFound("Target document not found");
37
- const link = await strapi
38
- .plugin("primershop-status-manager")
39
- .service("statusLink")
40
- .setForTarget(contentTypeUid, contentDocumentId, statusId);
41
- return ctx.send({ status: link.status });
42
- },
43
- });
44
- exports.content = content;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.controllers = void 0;
4
- const content_1 = require("./content");
5
- const status_1 = require("./status");
6
- exports.controllers = {
7
- status_controller: status_1.status,
8
- content_controller: content_1.content
9
- };
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.status = void 0;
4
- const status = ({ strapi }) => ({
5
- async listStatuses(ctx) {
6
- try {
7
- const statuses = await strapi
8
- .documents("plugin::primershop-status-manager.status")
9
- .findMany({
10
- sort: { order: "asc" },
11
- });
12
- return ctx.send(statuses);
13
- }
14
- catch (err) {
15
- console.error("❌ Status controller: find error:", err);
16
- ctx.throw(500, err);
17
- }
18
- },
19
- async create(ctx) {
20
- try {
21
- const { name, published = false } = ctx.request.body;
22
- // Validate name (only Latin characters)
23
- if (!/^[a-zA-Z\s]+$/.test(name)) {
24
- return ctx.badRequest("Status name must contain only Latin characters.");
25
- }
26
- // Get the highest order value
27
- const existingStatuses = await strapi
28
- .documents("plugin::primershop-status-manager.status")
29
- .findMany({
30
- orderBy: { order: "desc" },
31
- limit: 1,
32
- });
33
- const newOrder = existingStatuses.length > 0 ? existingStatuses[0].order + 1 : 0;
34
- // Create status
35
- const newStatus = await strapi
36
- .documents("plugin::primershop-status-manager.status")
37
- .create({
38
- data: {
39
- name,
40
- published,
41
- order: newOrder,
42
- },
43
- });
44
- return ctx.send(newStatus);
45
- }
46
- catch (error) {
47
- console.error("Status controller: create error:", error);
48
- ctx.internalServerError(`Error adding status: ${error}`);
49
- }
50
- },
51
- async reorder(ctx) {
52
- try {
53
- const { statuses } = ctx.request.body;
54
- if (!Array.isArray(statuses)) {
55
- return ctx.badRequest("Invalid data format");
56
- }
57
- // Update each status with new order
58
- await Promise.all(statuses.map(({ documentId, order }) => strapi.documents("plugin::primershop-status-manager.status").update({
59
- documentId,
60
- data: { order },
61
- })));
62
- ctx.send({ message: "Order updated successfully" });
63
- }
64
- catch (error) {
65
- console.error("Status controller: reorder error:", error);
66
- ctx.internalServerError(`Error updating order: ${error}`);
67
- }
68
- },
69
- async publish(ctx) {
70
- try {
71
- const { id } = ctx.params;
72
- const { published } = ctx.request.body;
73
- await strapi
74
- .documents("plugin::primershop-status-manager.status")
75
- .update({
76
- documentId: id,
77
- data: { published },
78
- });
79
- ctx.send({ message: "Status updated successfully" });
80
- }
81
- catch (error) {
82
- console.error("Status controller: publish error:", error);
83
- ctx.internalServerError(`Error updating status: ${error}`);
84
- }
85
- },
86
- async delete(ctx) {
87
- try {
88
- const { statusId } = ctx.request.body;
89
- if (!statusId) {
90
- return ctx.badRequest("Status ID is required.");
91
- }
92
- // Delete the status
93
- await strapi
94
- .documents("plugin::primershop-status-manager.status")
95
- .delete({
96
- documentId: statusId,
97
- });
98
- return ctx.send({ message: "Status deleted successfully" });
99
- }
100
- catch (error) {
101
- console.error("Status controller: delete error:", error);
102
- ctx.internalServerError(`Error deleting status: ${error}`);
103
- }
104
- },
105
- });
106
- exports.status = status;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const bootstrap_1 = require("./bootstrap");
7
- const index_1 = __importDefault(require("./content-types/index"));
8
- const controllers_1 = require("./controllers");
9
- const register_1 = require("./register");
10
- const routes_1 = require("./routes");
11
- const services_1 = require("./services");
12
- const plugin = () => {
13
- const pluginConfig = {
14
- register: register_1.register,
15
- controllers: controllers_1.controllers,
16
- contentTypes: index_1.default,
17
- routes: routes_1.routes,
18
- services: services_1.services,
19
- bootstrap: bootstrap_1.bootstrap,
20
- };
21
- return pluginConfig;
22
- };
23
- exports.default = plugin;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = async (context, next) => {
4
- var _a;
5
- const uid = context.uid;
6
- if (!uid.includes("api::")) {
7
- return next();
8
- }
9
- const result = await next();
10
- let documentIds = [];
11
- if (Array.isArray(result)) {
12
- documentIds = result
13
- .map((doc) => doc.documentId)
14
- .filter(Boolean);
15
- }
16
- else if (result && typeof result === "object" && "documentId" in result) {
17
- documentIds = [result.documentId].filter(Boolean);
18
- }
19
- if (documentIds.length === 0) {
20
- return result;
21
- }
22
- try {
23
- const statusLinks = await strapi.db
24
- .query("plugin::primershop-status-manager.status-link")
25
- .findMany({
26
- populate: {
27
- status: true,
28
- },
29
- where: {
30
- targetUid: uid,
31
- targetDocumentId: { $in: documentIds },
32
- },
33
- });
34
- if (Array.isArray(result)) {
35
- result.forEach((doc) => {
36
- var _a;
37
- doc.statusField =
38
- ((_a = statusLinks.find((link) => link.targetDocumentId === doc.documentId)) === null || _a === void 0 ? void 0 : _a.status) || undefined;
39
- });
40
- }
41
- if (result && typeof result === "object") {
42
- result.statusField =
43
- ((_a = statusLinks.find((link) => link.targetDocumentId === result.documentId)) === null || _a === void 0 ? void 0 : _a.status) || undefined;
44
- }
45
- }
46
- catch (error) {
47
- // If status enrichment fails, just return original result
48
- console.error("primershop-status-manager: status enrichment error", error);
49
- }
50
- return result;
51
- };
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@strapi/utils");
4
- exports.default = async (context, next) => {
5
- const uid = context.uid;
6
- if (!uid.includes("api::")) {
7
- return next();
8
- }
9
- const paramKeys = Object.keys(context.params || {});
10
- if (!paramKeys.includes("statusName")) {
11
- return next();
12
- }
13
- const desiredStatus = context.params["statusName"];
14
- if (!desiredStatus || desiredStatus === "all")
15
- return next();
16
- const isValid = await strapi
17
- .plugin("primershop-status-manager")
18
- .service("status")
19
- .isValidStatus(desiredStatus);
20
- if (!isValid)
21
- throw new utils_1.errors.ValidationError(`Invalid status: ${desiredStatus}`);
22
- const status = await strapi
23
- .plugin("primershop-status-manager")
24
- .service("status")
25
- .getStatusByName(desiredStatus);
26
- if (!status) {
27
- throw new utils_1.errors.ValidationError(`Status not found: ${desiredStatus}`);
28
- }
29
- const statusLinks = await strapi.db
30
- .query("plugin::primershop-status-manager.status-link")
31
- .findMany({
32
- where: {
33
- targetUid: uid,
34
- status: status.id,
35
- },
36
- select: ["targetDocumentId"],
37
- });
38
- const allowedDocumentIds = statusLinks.map((link) => link.targetDocumentId);
39
- context.params["filters"] = {
40
- ...context.params["filters"],
41
- documentId: { $in: allowedDocumentIds },
42
- };
43
- return next();
44
- };
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = async (context, next) => {
4
- const uid = context.uid;
5
- if (!uid.includes("api::")) {
6
- return next();
7
- }
8
- const params = context.params;
9
- if ((!params && !params["status"]) || params["statusName"])
10
- return next();
11
- const unpublishedStatusLinks = await strapi.db
12
- .query("plugin::primershop-status-manager.status-link")
13
- .findMany({
14
- populate: {
15
- status: true,
16
- },
17
- where: {
18
- targetUid: uid,
19
- status: {
20
- published: false,
21
- },
22
- },
23
- select: ["targetDocumentId"],
24
- });
25
- const unpublishedDocumentIds = unpublishedStatusLinks.map((link) => link.targetDocumentId);
26
- context.params["filters"] = {
27
- ...context.params["filters"],
28
- documentId: { $notIn: unpublishedDocumentIds },
29
- };
30
- return next();
31
- };
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- actions: [
5
- {
6
- // Roles
7
- section: "plugins",
8
- displayName: "Create",
9
- uid: "status.create",
10
- subCategory: "status",
11
- pluginName: "primershop-status-manager",
12
- },
13
- {
14
- section: "plugins",
15
- displayName: "Read",
16
- uid: "status.read",
17
- subCategory: "status",
18
- pluginName: "primershop-status-manager",
19
- aliases: [
20
- {
21
- actionId: "plugin::content-manager.explorer.read",
22
- subjects: ["plugin::primershop-status-manager.status"],
23
- },
24
- ],
25
- },
26
- {
27
- section: "plugins",
28
- displayName: "Update",
29
- uid: "status.update",
30
- subCategory: "status",
31
- pluginName: "primershop-status-manager",
32
- },
33
- {
34
- section: "plugins",
35
- displayName: "Delete",
36
- uid: "status.delete",
37
- subCategory: "status",
38
- pluginName: "primershop-status-manager",
39
- },
40
- ],
41
- };
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PLUGIN_ID = void 0;
4
- exports.PLUGIN_ID = "primershop-status-manager";
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.register = void 0;
7
- const pluginId_1 = require("./pluginId");
8
- const add_status_field_1 = __importDefault(require("./middlewares/add-status-field"));
9
- const filter_by_status_1 = __importDefault(require("./middlewares/filter-by-status"));
10
- const filter_published_1 = __importDefault(require("./middlewares/filter-published"));
11
- const register = ({ strapi }) => {
12
- strapi.customFields.register({
13
- name: "statusName",
14
- plugin: pluginId_1.PLUGIN_ID,
15
- type: "string",
16
- });
17
- // Register permissions
18
- strapi.admin.services.permission.actionProvider.register({
19
- section: "plugins",
20
- displayName: "Status Manager",
21
- uid: pluginId_1.PLUGIN_ID,
22
- pluginName: pluginId_1.PLUGIN_ID,
23
- });
24
- strapi.documents.use(filter_by_status_1.default);
25
- strapi.documents.use(add_status_field_1.default);
26
- strapi.documents.use(filter_published_1.default);
27
- };
28
- exports.register = register;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [
4
- {
5
- method: "GET",
6
- path: "/content-status",
7
- handler: "content_controller.getStatusForTarget",
8
- config: {
9
- policies: [
10
- {
11
- name: "admin::hasPermissions",
12
- config: {
13
- actions: ["plugin::primershop-status-manager.status.read"],
14
- },
15
- },
16
- ],
17
- },
18
- },
19
- {
20
- method: "PUT",
21
- path: "/content-status",
22
- handler: "content_controller.setStatusForTarget",
23
- config: {
24
- policies: [
25
- {
26
- name: "admin::hasPermissions",
27
- config: {
28
- actions: ["plugin::primershop-status-manager.status.update"],
29
- },
30
- },
31
- ],
32
- },
33
- },
34
- ];
@@ -1,15 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.routes = void 0;
7
- const status_management_1 = __importDefault(require("./status-management"));
8
- const content_management_1 = __importDefault(require("./content-management"));
9
- const routes = {
10
- admin: {
11
- type: "admin",
12
- routes: [...status_management_1.default, ...content_management_1.default],
13
- },
14
- };
15
- exports.routes = routes;
@@ -1,109 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [
4
- {
5
- method: "GET",
6
- path: "/statuses",
7
- handler: "status_controller.listStatuses",
8
- config: {
9
- policies: [
10
- {
11
- name: "admin::hasPermissions",
12
- config: {
13
- actions: ["plugin::primershop-status-manager.status.read"],
14
- },
15
- },
16
- ],
17
- },
18
- description: "Get all statuses",
19
- tag: {
20
- plugin: "primershop-status-manager",
21
- name: "statuses",
22
- actionType: "findMany",
23
- },
24
- },
25
- {
26
- method: "POST",
27
- path: "/status",
28
- handler: "status_controller.create",
29
- config: {
30
- policies: [
31
- {
32
- name: "admin::hasPermissions",
33
- config: {
34
- actions: ["plugin::primershop-status-manager.status.create"],
35
- },
36
- },
37
- ],
38
- },
39
- description: "Create a new status",
40
- tag: {
41
- plugin: "primershop-status-manager",
42
- name: "Status",
43
- actionType: "create",
44
- },
45
- },
46
- {
47
- method: "PUT",
48
- path: "/statuses/reorder",
49
- handler: "status_controller.reorder",
50
- config: {
51
- policies: [
52
- {
53
- name: "admin::hasPermissions",
54
- config: {
55
- actions: ["plugin::primershop-status-manager.status.update"],
56
- },
57
- },
58
- ],
59
- description: "Reorder statuses",
60
- tag: {
61
- plugin: "primershop-status-manager",
62
- name: "Status",
63
- actionType: "update",
64
- },
65
- },
66
- },
67
- {
68
- method: "PUT",
69
- path: "/statuses/delete",
70
- handler: "status_controller.delete",
71
- config: {
72
- policies: [
73
- {
74
- name: "admin::hasPermissions",
75
- config: {
76
- actions: ["plugin::primershop-status-manager.status.delete"],
77
- },
78
- },
79
- ],
80
- description: "Delete a status",
81
- tag: {
82
- plugin: "primershop-status-manager",
83
- name: "Status",
84
- actionType: "delete",
85
- },
86
- },
87
- },
88
- {
89
- method: "PUT",
90
- path: "/statuses/:id",
91
- handler: "status_controller.publish",
92
- config: {
93
- policies: [
94
- {
95
- name: "admin::hasPermissions",
96
- config: {
97
- actions: ["plugin::primershop-status-manager.status.update"],
98
- },
99
- },
100
- ],
101
- description: "Update status publish state",
102
- tag: {
103
- plugin: "primershop-status-manager",
104
- name: "Status",
105
- actionType: "update",
106
- },
107
- },
108
- },
109
- ];
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.services = void 0;
4
- const status_1 = require("./status");
5
- const status_link_1 = require("./status-link");
6
- exports.services = {
7
- status: status_1.statusService,
8
- statusLink: status_link_1.statusLinkService,
9
- };
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.statusLinkService = void 0;
4
- const statusLinkService = ({ strapi }) => ({
5
- async getForTarget(targetUid, targetDocumentId) {
6
- const link = await strapi.db
7
- .query("plugin::primershop-status-manager.status-link")
8
- .findOne({
9
- where: { targetUid, targetDocumentId },
10
- populate: { status: true },
11
- });
12
- return link !== null && link !== void 0 ? link : null;
13
- },
14
- async setForTarget(targetUid, targetDocumentId, statusDocumentId) {
15
- // Create status link
16
- await strapi.db
17
- .query("plugin::primershop-status-manager.status-link")
18
- .deleteMany({ where: { targetUid, targetDocumentId } });
19
- const created = await strapi
20
- .documents("plugin::primershop-status-manager.status-link")
21
- .create({
22
- data: {
23
- targetUid,
24
- targetDocumentId,
25
- status: {
26
- set: statusDocumentId,
27
- },
28
- },
29
- });
30
- return created;
31
- },
32
- });
33
- exports.statusLinkService = statusLinkService;