@frameless/strapi-plugin-notes 1.0.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.
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ const strapi = require("@strapi/strapi");
3
+ const noteContentType = {
4
+ kind: "collectionType",
5
+ collectionName: "notes",
6
+ info: {
7
+ singularName: "note",
8
+ pluralName: "notes",
9
+ displayName: "notes"
10
+ },
11
+ pluginOptions: {
12
+ "content-manager": {
13
+ visible: false
14
+ },
15
+ "content-type-builder": {
16
+ visible: false
17
+ }
18
+ },
19
+ options: {
20
+ draftAndPublish: false,
21
+ comment: ""
22
+ },
23
+ attributes: {
24
+ title: {
25
+ type: "string"
26
+ },
27
+ content: {
28
+ type: "text"
29
+ },
30
+ entitySlug: {
31
+ type: "string"
32
+ },
33
+ entityId: {
34
+ type: "string"
35
+ }
36
+ }
37
+ };
38
+ const contentTypes = {
39
+ note: { schema: noteContentType }
40
+ };
41
+ const noteController = strapi.factories.createCoreController("plugin::entity-notes.note", ({ strapi: strapi2 }) => ({
42
+ async findByDocument(ctx) {
43
+ const { entitySlug, documentId } = ctx.query;
44
+ if (!entitySlug || !documentId) {
45
+ return ctx.badRequest("entitySlug and documentId are required");
46
+ }
47
+ try {
48
+ let legacyId = null;
49
+ try {
50
+ const document = await strapi2.db.query(entitySlug).findOne({
51
+ where: { documentId }
52
+ });
53
+ legacyId = document?.id;
54
+ } catch (error) {
55
+ console.error(`Error fetching document for ${entitySlug} with documentId ${documentId}:`, error);
56
+ }
57
+ const entityIdFilters = [documentId];
58
+ if (legacyId) {
59
+ entityIdFilters.push(legacyId, String(legacyId));
60
+ }
61
+ const notes = await strapi2.db.query("plugin::entity-notes.note").findMany({
62
+ where: {
63
+ entitySlug: { $eq: entitySlug },
64
+ entityId: { $in: entityIdFilters }
65
+ },
66
+ orderBy: { title: "asc" }
67
+ });
68
+ return { data: notes };
69
+ } catch (error) {
70
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
71
+ return ctx.internalServerError("Failed to fetch notes", { error: errorMessage });
72
+ }
73
+ }
74
+ }));
75
+ const controllers = {
76
+ noteController
77
+ };
78
+ const noteRoutes = [
79
+ {
80
+ method: "GET",
81
+ path: "/notes",
82
+ handler: "noteController.find"
83
+ },
84
+ {
85
+ method: "GET",
86
+ path: "/notes/by-document",
87
+ handler: "noteController.findByDocument"
88
+ },
89
+ {
90
+ method: "POST",
91
+ path: "/notes",
92
+ handler: "noteController.create"
93
+ },
94
+ {
95
+ method: "DELETE",
96
+ path: "/notes/:id",
97
+ handler: "noteController.delete"
98
+ },
99
+ {
100
+ method: "PUT",
101
+ path: "/notes/:id",
102
+ handler: "noteController.update"
103
+ }
104
+ ];
105
+ const routes = [...noteRoutes];
106
+ const note = strapi.factories.createCoreService("plugin::entity-notes.note");
107
+ const services = {
108
+ note
109
+ };
110
+ const index = {
111
+ controllers,
112
+ routes,
113
+ services,
114
+ contentTypes
115
+ };
116
+ module.exports = index;
@@ -0,0 +1,117 @@
1
+ import { factories } from "@strapi/strapi";
2
+ const noteContentType = {
3
+ kind: "collectionType",
4
+ collectionName: "notes",
5
+ info: {
6
+ singularName: "note",
7
+ pluralName: "notes",
8
+ displayName: "notes"
9
+ },
10
+ pluginOptions: {
11
+ "content-manager": {
12
+ visible: false
13
+ },
14
+ "content-type-builder": {
15
+ visible: false
16
+ }
17
+ },
18
+ options: {
19
+ draftAndPublish: false,
20
+ comment: ""
21
+ },
22
+ attributes: {
23
+ title: {
24
+ type: "string"
25
+ },
26
+ content: {
27
+ type: "text"
28
+ },
29
+ entitySlug: {
30
+ type: "string"
31
+ },
32
+ entityId: {
33
+ type: "string"
34
+ }
35
+ }
36
+ };
37
+ const contentTypes = {
38
+ note: { schema: noteContentType }
39
+ };
40
+ const noteController = factories.createCoreController("plugin::entity-notes.note", ({ strapi }) => ({
41
+ async findByDocument(ctx) {
42
+ const { entitySlug, documentId } = ctx.query;
43
+ if (!entitySlug || !documentId) {
44
+ return ctx.badRequest("entitySlug and documentId are required");
45
+ }
46
+ try {
47
+ let legacyId = null;
48
+ try {
49
+ const document = await strapi.db.query(entitySlug).findOne({
50
+ where: { documentId }
51
+ });
52
+ legacyId = document?.id;
53
+ } catch (error) {
54
+ console.error(`Error fetching document for ${entitySlug} with documentId ${documentId}:`, error);
55
+ }
56
+ const entityIdFilters = [documentId];
57
+ if (legacyId) {
58
+ entityIdFilters.push(legacyId, String(legacyId));
59
+ }
60
+ const notes = await strapi.db.query("plugin::entity-notes.note").findMany({
61
+ where: {
62
+ entitySlug: { $eq: entitySlug },
63
+ entityId: { $in: entityIdFilters }
64
+ },
65
+ orderBy: { title: "asc" }
66
+ });
67
+ return { data: notes };
68
+ } catch (error) {
69
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
70
+ return ctx.internalServerError("Failed to fetch notes", { error: errorMessage });
71
+ }
72
+ }
73
+ }));
74
+ const controllers = {
75
+ noteController
76
+ };
77
+ const noteRoutes = [
78
+ {
79
+ method: "GET",
80
+ path: "/notes",
81
+ handler: "noteController.find"
82
+ },
83
+ {
84
+ method: "GET",
85
+ path: "/notes/by-document",
86
+ handler: "noteController.findByDocument"
87
+ },
88
+ {
89
+ method: "POST",
90
+ path: "/notes",
91
+ handler: "noteController.create"
92
+ },
93
+ {
94
+ method: "DELETE",
95
+ path: "/notes/:id",
96
+ handler: "noteController.delete"
97
+ },
98
+ {
99
+ method: "PUT",
100
+ path: "/notes/:id",
101
+ handler: "noteController.update"
102
+ }
103
+ ];
104
+ const routes = [...noteRoutes];
105
+ const note = factories.createCoreService("plugin::entity-notes.note");
106
+ const services = {
107
+ note
108
+ };
109
+ const index = {
110
+ controllers,
111
+ routes,
112
+ services,
113
+ contentTypes
114
+ };
115
+ export {
116
+ index as default
117
+ };
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "@frameless/strapi-plugin-notes",
3
+ "version": "1.0.0",
4
+ "description": "A plugin for Strapi CMS that provides the ability to add notes to entity records.",
5
+ "strapi": {
6
+ "displayName": "Notes",
7
+ "description": "A plugin for Strapi Headless CMS that provides the ability to add notes to entity records.",
8
+ "name": "entity-notes",
9
+ "kind": "plugin"
10
+ },
11
+ "author": {
12
+ "name": "Frameless"
13
+ },
14
+ "license": "EUPL-1.2",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "exports": {
19
+ "./package.json": "./package.json",
20
+ "./strapi-admin": {
21
+ "types": "./dist/admin/src/index.d.ts",
22
+ "source": "./admin/src/index.tsx",
23
+ "import": "./dist/admin/index.mjs",
24
+ "require": "./dist/admin/index.js",
25
+ "default": "./dist/admin/index.js"
26
+ },
27
+ "./strapi-server": {
28
+ "types": "./dist/server/src/index.d.ts",
29
+ "source": "./server/index.ts",
30
+ "import": "./dist/server/index.mjs",
31
+ "require": "./dist/server/index.js",
32
+ "default": "./dist/server/index.js"
33
+ }
34
+ },
35
+ "repository": {
36
+ "type": "git+ssh",
37
+ "url": "git@github.com:frameless/strapi-v5-extensions.git",
38
+ "directory": "packages/strapi-plugin-notes"
39
+ },
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org",
42
+ "access": "public",
43
+ "provenance": true
44
+ },
45
+ "dependencies": {
46
+ "react-intl": "8.1.3",
47
+ "@tanstack/react-query": "5.90.21"
48
+ },
49
+ "devDependencies": {
50
+ "@babel/preset-typescript": "7.28.5",
51
+ "@strapi/design-system": "2.1.2",
52
+ "@strapi/icons": "2.1.2",
53
+ "@strapi/sdk-plugin": "5.4.0",
54
+ "@strapi/strapi": "5.33.4",
55
+ "@strapi/typescript-utils": "5.33.4",
56
+ "@testing-library/jest-dom": "6.9.1",
57
+ "@testing-library/react": "16.3.2",
58
+ "@types/jest": "29.5.12",
59
+ "@types/node": "24.10.9",
60
+ "@types/react": "18.3.27",
61
+ "@types/react-dom": "18.3.7",
62
+ "@types/styled-components": "5.1.36",
63
+ "identity-obj-proxy": "3.0.0",
64
+ "jest": "29.7.0",
65
+ "jest-environment-jsdom": "29.7.0",
66
+ "koa": "3.1.2",
67
+ "rimraf": "6.1.3",
68
+ "ts-jest": "29.4.6",
69
+ "ts-node": "10.9.2",
70
+ "typescript": "5.9.3",
71
+ "@frameless/eslint-config": "1.1.2",
72
+ "@frameless/typescript-config": "1.0.1"
73
+ },
74
+ "peerDependencies": {
75
+ "@strapi/design-system": ">=2.0.0",
76
+ "@strapi/icons": ">=2.0.0",
77
+ "@strapi/strapi": ">=5.0.0",
78
+ "react": "^18.0.0",
79
+ "react-dom": "^18.0.0"
80
+ },
81
+ "engines": {
82
+ "node": ">=22.0.0 <25",
83
+ "pnpm": ">=10.0.0"
84
+ },
85
+ "keywords": [
86
+ "strapi",
87
+ "strapi-plugin",
88
+ "plugin",
89
+ "strapi plugin",
90
+ "notes"
91
+ ],
92
+ "scripts": {
93
+ "build": "strapi-plugin build",
94
+ "watch": "strapi-plugin watch",
95
+ "watch:link": "strapi-plugin watch:link",
96
+ "verify": "strapi-plugin verify",
97
+ "lint-build": "tsc --noEmit --project tsconfig.json && tsc --noEmit --project tsconfig.server.json",
98
+ "lint": "eslint .",
99
+ "lint-fix": "eslint . --fix",
100
+ "clean": "rimraf .next .strapi dist",
101
+ "test": "jest --passWithNoTests"
102
+ }
103
+ }