strapi-plugin-document-metadata 1.0.1

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 (35) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +67 -0
  3. package/dist/_chunks/en-h9IAaoUJ.mjs +16 -0
  4. package/dist/_chunks/en-tDvQkVOI.js +16 -0
  5. package/dist/admin/index.js +311 -0
  6. package/dist/admin/index.mjs +312 -0
  7. package/dist/admin/src/components/DocumentMetadataCard/index.d.ts +10 -0
  8. package/dist/admin/src/components/DocumentMetadataGuard/index.d.ts +6 -0
  9. package/dist/admin/src/components/Initializer/index.d.ts +5 -0
  10. package/dist/admin/src/components/LastOpenedMetadataGuard/index.d.ts +10 -0
  11. package/dist/admin/src/components/LastOpenedMetadataLoader/index.d.ts +10 -0
  12. package/dist/admin/src/components/LastOpenedMetadataLoader/useLastOpened.d.ts +31 -0
  13. package/dist/admin/src/components/MetadataRow/index.d.ts +9 -0
  14. package/dist/admin/src/index.d.ts +10 -0
  15. package/dist/admin/src/pluginId.d.ts +1 -0
  16. package/dist/admin/src/utils/prefixKey.d.ts +2 -0
  17. package/dist/admin/src/utils/recentTimeFormatter.d.ts +16 -0
  18. package/dist/admin/src/utils/relativeDateFormatter.d.ts +30 -0
  19. package/dist/server/index.js +119 -0
  20. package/dist/server/index.mjs +120 -0
  21. package/dist/server/src/bootstrap.d.ts +5 -0
  22. package/dist/server/src/config/index.d.ts +5 -0
  23. package/dist/server/src/content-types/index.d.ts +2 -0
  24. package/dist/server/src/controllers/controller.d.ts +12 -0
  25. package/dist/server/src/controllers/index.d.ts +9 -0
  26. package/dist/server/src/destroy.d.ts +5 -0
  27. package/dist/server/src/index.d.ts +58 -0
  28. package/dist/server/src/middlewares/index.d.ts +2 -0
  29. package/dist/server/src/policies/index.d.ts +2 -0
  30. package/dist/server/src/register.d.ts +5 -0
  31. package/dist/server/src/routes/admin.d.ts +12 -0
  32. package/dist/server/src/routes/index.d.ts +14 -0
  33. package/dist/server/src/services/index.d.ts +19 -0
  34. package/dist/server/src/services/service.d.ts +35 -0
  35. package/package.json +78 -0
@@ -0,0 +1,120 @@
1
+ const bootstrap = ({ strapi }) => {
2
+ };
3
+ const destroy = ({ strapi }) => {
4
+ };
5
+ const register = ({ strapi }) => {
6
+ };
7
+ const config = {
8
+ default: {},
9
+ validator() {
10
+ }
11
+ };
12
+ const contentTypes = {};
13
+ const controller = ({ strapi }) => ({
14
+ /**
15
+ * Controller method for the route that fetches and updates the last-opened fields
16
+ * of a document with the given `uid` and `documentId` path parameters (GET request).
17
+ */
18
+ async lastOpened(ctx) {
19
+ const { uid, documentId } = ctx.params;
20
+ const { locale } = ctx.request.query;
21
+ const previousLastOpened = await strapi.plugin("document-metadata").service("service").fetchLastOpened({ uid, documentId, locale });
22
+ const openedAt = (/* @__PURE__ */ new Date()).toISOString();
23
+ const { user } = ctx.state;
24
+ const openedBy = `${user.firstname} ${user.lastname}`;
25
+ await strapi.plugin("document-metadata").service("service").updateLastOpened({ uid, documentId, locale, openedAt, openedBy });
26
+ ctx.response.body = previousLastOpened;
27
+ }
28
+ });
29
+ const controllers = {
30
+ controller
31
+ };
32
+ const middlewares = {};
33
+ const policies = {};
34
+ const admin = {
35
+ type: "admin",
36
+ routes: [
37
+ {
38
+ method: "GET",
39
+ path: "/last-opened/:uid/:documentId",
40
+ handler: "controller.lastOpened",
41
+ config: {
42
+ policies: []
43
+ }
44
+ }
45
+ ]
46
+ };
47
+ const routes = {
48
+ admin
49
+ };
50
+ const service = ({ strapi }) => ({
51
+ /**
52
+ * Fetches the last-opened fields for a specific document within a content type.
53
+ *
54
+ * @param uid - The unique identifier of the content type (e.g. 'api::products.products').
55
+ * @param documentId - The ID of the document to fetch.
56
+ * @param locale - The current locale of the content type / `undefined` if localization is turned off.
57
+ */
58
+ fetchLastOpened: async ({
59
+ uid,
60
+ documentId,
61
+ locale
62
+ }) => {
63
+ return await strapi.documents(uid).findOne({
64
+ documentId,
65
+ fields: ["openedAt", "openedBy"],
66
+ locale
67
+ });
68
+ },
69
+ /**
70
+ * Updates the last-opened fields for a specific document within a content type.
71
+ *
72
+ * @param uid - The unique identifier of the content type (e.g. 'api::products.products').
73
+ * @param documentId - The ID of the document to update.
74
+ * @param locale - The current locale of the content type / `undefined` if localization is turned off.
75
+ * @param openedAt - The date and time when the document was last opened.
76
+ * @param openedBy - The name of the user who last opened the document.
77
+ */
78
+ async updateLastOpened({
79
+ uid,
80
+ documentId,
81
+ locale,
82
+ openedAt,
83
+ openedBy
84
+ }) {
85
+ const tableName = strapi.getModel(uid).collectionName;
86
+ if (!tableName) {
87
+ throw new Error(
88
+ `Expected to have a collection name for the content type "${uid}" at this point.`
89
+ );
90
+ }
91
+ return await strapi.db.connection(tableName).update({
92
+ opened_at: openedAt,
93
+ opened_by: openedBy
94
+ }).where({
95
+ document_id: documentId,
96
+ // We explicitly need to provide `null` here, cause in the database
97
+ // the locale is stored as `NULL` when localization is turned off.
98
+ // Without this fallback, the query would not match any rows.
99
+ locale: locale || null
100
+ });
101
+ }
102
+ });
103
+ const services = {
104
+ service
105
+ };
106
+ const index = {
107
+ register,
108
+ bootstrap,
109
+ destroy,
110
+ config,
111
+ controllers,
112
+ routes,
113
+ services,
114
+ contentTypes,
115
+ policies,
116
+ middlewares
117
+ };
118
+ export {
119
+ index as default
120
+ };
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const bootstrap: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default bootstrap;
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ default: {};
3
+ validator(): void;
4
+ };
5
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import type { Context } from 'koa';
3
+ declare const controller: ({ strapi }: {
4
+ strapi: Core.Strapi;
5
+ }) => {
6
+ /**
7
+ * Controller method for the route that fetches and updates the last-opened fields
8
+ * of a document with the given `uid` and `documentId` path parameters (GET request).
9
+ */
10
+ lastOpened(ctx: Context): Promise<void>;
11
+ };
12
+ export default controller;
@@ -0,0 +1,9 @@
1
+ /// <reference types="koa" />
2
+ declare const _default: {
3
+ controller: ({ strapi }: {
4
+ strapi: import("@strapi/types/dist/core").Strapi;
5
+ }) => {
6
+ lastOpened(ctx: import("koa").Context): Promise<void>;
7
+ };
8
+ };
9
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const destroy: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default destroy;
@@ -0,0 +1,58 @@
1
+ /// <reference types="koa" />
2
+ declare const _default: {
3
+ register: ({ strapi }: {
4
+ strapi: import("@strapi/types/dist/core").Strapi;
5
+ }) => void;
6
+ bootstrap: ({ strapi }: {
7
+ strapi: import("@strapi/types/dist/core").Strapi;
8
+ }) => void;
9
+ destroy: ({ strapi }: {
10
+ strapi: import("@strapi/types/dist/core").Strapi;
11
+ }) => void;
12
+ config: {
13
+ default: {};
14
+ validator(): void;
15
+ };
16
+ controllers: {
17
+ controller: ({ strapi }: {
18
+ strapi: import("@strapi/types/dist/core").Strapi;
19
+ }) => {
20
+ lastOpened(ctx: import("koa").Context): Promise<void>;
21
+ };
22
+ };
23
+ routes: {
24
+ admin: {
25
+ type: string;
26
+ routes: {
27
+ method: string;
28
+ path: string;
29
+ handler: string;
30
+ config: {
31
+ policies: any[];
32
+ };
33
+ }[];
34
+ };
35
+ };
36
+ services: {
37
+ service: ({ strapi }: {
38
+ strapi: import("@strapi/types/dist/core").Strapi;
39
+ }) => {
40
+ fetchLastOpened: ({ uid, documentId, locale, }: {
41
+ uid: import("@strapi/types/dist/uid").ContentType;
42
+ documentId: string;
43
+ locale: any;
44
+ }) => Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
45
+ updateLastOpened({ uid, documentId, locale, openedAt, openedBy, }: {
46
+ uid: import("@strapi/types/dist/uid").ContentType;
47
+ documentId: string;
48
+ locale: any;
49
+ openedAt: string;
50
+ openedBy: string;
51
+ }): Promise<number>;
52
+ };
53
+ };
54
+ contentTypes: {};
55
+ policies: {};
56
+ middlewares: {};
57
+ };
58
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const register: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default register;
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ type: string;
3
+ routes: {
4
+ method: string;
5
+ path: string;
6
+ handler: string;
7
+ config: {
8
+ policies: any[];
9
+ };
10
+ }[];
11
+ };
12
+ export default _default;
@@ -0,0 +1,14 @@
1
+ declare const routes: {
2
+ admin: {
3
+ type: string;
4
+ routes: {
5
+ method: string;
6
+ path: string;
7
+ handler: string;
8
+ config: {
9
+ policies: any[];
10
+ };
11
+ }[];
12
+ };
13
+ };
14
+ export default routes;
@@ -0,0 +1,19 @@
1
+ declare const _default: {
2
+ service: ({ strapi }: {
3
+ strapi: import("@strapi/types/dist/core").Strapi;
4
+ }) => {
5
+ fetchLastOpened: ({ uid, documentId, locale, }: {
6
+ uid: import("@strapi/types/dist/uid").ContentType;
7
+ documentId: string;
8
+ locale: any;
9
+ }) => Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
10
+ updateLastOpened({ uid, documentId, locale, openedAt, openedBy, }: {
11
+ uid: import("@strapi/types/dist/uid").ContentType;
12
+ documentId: string;
13
+ locale: any;
14
+ openedAt: string;
15
+ openedBy: string;
16
+ }): Promise<number>;
17
+ };
18
+ };
19
+ export default _default;
@@ -0,0 +1,35 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import type { ContentTypeUID, DocumentID, Locale } from '../types';
3
+ declare const service: ({ strapi }: {
4
+ strapi: Core.Strapi;
5
+ }) => {
6
+ /**
7
+ * Fetches the last-opened fields for a specific document within a content type.
8
+ *
9
+ * @param uid - The unique identifier of the content type (e.g. 'api::products.products').
10
+ * @param documentId - The ID of the document to fetch.
11
+ * @param locale - The current locale of the content type / `undefined` if localization is turned off.
12
+ */
13
+ fetchLastOpened: ({ uid, documentId, locale, }: {
14
+ uid: ContentTypeUID;
15
+ documentId: DocumentID;
16
+ locale: Locale | undefined;
17
+ }) => Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
18
+ /**
19
+ * Updates the last-opened fields for a specific document within a content type.
20
+ *
21
+ * @param uid - The unique identifier of the content type (e.g. 'api::products.products').
22
+ * @param documentId - The ID of the document to update.
23
+ * @param locale - The current locale of the content type / `undefined` if localization is turned off.
24
+ * @param openedAt - The date and time when the document was last opened.
25
+ * @param openedBy - The name of the user who last opened the document.
26
+ */
27
+ updateLastOpened({ uid, documentId, locale, openedAt, openedBy, }: {
28
+ uid: ContentTypeUID;
29
+ documentId: DocumentID;
30
+ locale: Locale | undefined;
31
+ openedAt: string;
32
+ openedBy: string;
33
+ }): Promise<number>;
34
+ };
35
+ export default service;
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "strapi-plugin-document-metadata",
3
+ "version": "1.0.1",
4
+ "description": "Displays entity metadata, with an option to include \"last opened\" details.",
5
+ "keywords": [
6
+ "strapi",
7
+ "plugin",
8
+ "document",
9
+ "metadata",
10
+ "last",
11
+ "opened",
12
+ "date",
13
+ "user"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "Felix M. <me@felix.hamburg>",
17
+ "type": "commonjs",
18
+ "exports": {
19
+ "./package.json": "./package.json",
20
+ "./strapi-admin": {
21
+ "types": "./dist/admin/src/index.d.ts",
22
+ "source": "./admin/src/index.ts",
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/src/index.ts",
30
+ "import": "./dist/server/index.mjs",
31
+ "require": "./dist/server/index.js",
32
+ "default": "./dist/server/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "scripts": {
39
+ "build": "strapi-plugin build",
40
+ "test:ts:back": "run -T tsc -p server/tsconfig.json",
41
+ "test:ts:front": "run -T tsc -p admin/tsconfig.json",
42
+ "verify": "strapi-plugin verify",
43
+ "watch": "strapi-plugin watch",
44
+ "watch:link": "strapi-plugin watch:link"
45
+ },
46
+ "dependencies": {
47
+ "@strapi/design-system": "^2.1.0",
48
+ "@strapi/icons": "^2.1.0",
49
+ "react-intl": "^7.1.14"
50
+ },
51
+ "devDependencies": {
52
+ "@strapi/sdk-plugin": "^5.4.0",
53
+ "@strapi/strapi": "^5.33.2",
54
+ "@strapi/typescript-utils": "^5.31.0",
55
+ "@types/react": "^19.2.8",
56
+ "@types/react-dom": "^19.2.3",
57
+ "prettier": "^3.7.4",
58
+ "react": "^18.3.1",
59
+ "react-dom": "^18.3.1",
60
+ "react-router-dom": "^6.30.3",
61
+ "styled-components": "^6.3.5",
62
+ "typescript": "^5.9.3"
63
+ },
64
+ "peerDependencies": {
65
+ "@strapi/sdk-plugin": "^5.3.2",
66
+ "@strapi/strapi": "^5.31.0",
67
+ "react": "^18.3.1",
68
+ "react-dom": "^18.3.1",
69
+ "react-router-dom": "^6.30.2",
70
+ "styled-components": "^6.1.19"
71
+ },
72
+ "strapi": {
73
+ "kind": "plugin",
74
+ "name": "document-metadata",
75
+ "displayName": "Document Metadata",
76
+ "description": "Displays entity metadata, with an option to include \"last opened\" details."
77
+ }
78
+ }