tienjs-chartbrew-plugin-strapi 0.1.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,3 @@
1
+ "use strict";
2
+ const index = require("../_chunks/index-Bk9ujIXz.js");
3
+ module.exports = index.index;
@@ -0,0 +1,4 @@
1
+ import { i } from "../_chunks/index-CXvgiYYO.mjs";
2
+ export {
3
+ i as default
4
+ };
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ const require$$0 = require("request-promise");
3
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
4
+ const require$$0__default = /* @__PURE__ */ _interopDefault(require$$0);
5
+ function getDefaultExportFromCjs(x) {
6
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
7
+ }
8
+ const bootstrap$1 = ({ strapi: strapi2 }) => {
9
+ };
10
+ var bootstrap_1 = bootstrap$1;
11
+ const destroy$1 = ({ strapi: strapi2 }) => {
12
+ };
13
+ var destroy_1 = destroy$1;
14
+ const register$1 = ({ strapi: strapi2 }) => {
15
+ };
16
+ var register_1 = register$1;
17
+ var config$1 = {
18
+ default: {},
19
+ validator() {
20
+ }
21
+ };
22
+ var contentTypes$1 = {};
23
+ const controller = ({ strapi: strapi2 }) => ({
24
+ index(ctx) {
25
+ ctx.body = strapi2.plugin("chartbrew").service("service").getWelcomeMessage();
26
+ },
27
+ async get() {
28
+ await strapi2.query("plugin::chartbrew.chartbrew").findMany();
29
+ },
30
+ async getSettings(ctx) {
31
+ try {
32
+ const settings = await strapi2.plugin("chartbrew").service("chartbrew").getSettings();
33
+ delete settings.strapiToken;
34
+ ctx.body = settings;
35
+ } catch (err) {
36
+ ctx.throw(500, err);
37
+ }
38
+ },
39
+ async setSettings(ctx) {
40
+ const { body } = ctx.request;
41
+ try {
42
+ await strapi2.plugin("chartbrew").service("chartbrew").setSettings(body);
43
+ const newSettings = await strapi2.plugin("chartbrew").service("chartbrew").getSettings();
44
+ delete newSettings.strapiToken;
45
+ ctx.body = newSettings;
46
+ } catch (err) {
47
+ ctx.throw(500, err);
48
+ }
49
+ },
50
+ async getModels(ctx) {
51
+ try {
52
+ const models = Object.keys(strapi2.contentTypes).map((key) => strapi2.contentTypes[key]);
53
+ const formattedModels = models.filter((m) => m.kind === "collectionType").map((model) => ({
54
+ ...model.info,
55
+ kind: model.kind,
56
+ attributes: model.attributes,
57
+ uid: model.uid
58
+ }));
59
+ ctx.body = formattedModels;
60
+ } catch (err) {
61
+ ctx.throw(400, err);
62
+ }
63
+ },
64
+ async generateTemplate(ctx) {
65
+ const { body } = ctx.request;
66
+ try {
67
+ const project = await strapi2.plugin("chartbrew").service("chartbrew").generate(body);
68
+ ctx.body = project;
69
+ } catch (err) {
70
+ ctx.throw(400, err);
71
+ }
72
+ }
73
+ });
74
+ var chartbrew$5 = controller;
75
+ const chartbrew$4 = chartbrew$5;
76
+ var controllers$1 = {
77
+ chartbrew: chartbrew$4
78
+ };
79
+ var middlewares$1 = {};
80
+ var policies$1 = {};
81
+ var chartbrew$3 = {
82
+ type: "admin",
83
+ routes: [
84
+ {
85
+ method: "GET",
86
+ path: "/",
87
+ handler: "chartbrew.get",
88
+ config: {
89
+ policies: []
90
+ }
91
+ },
92
+ {
93
+ method: "GET",
94
+ path: "/settings",
95
+ handler: "chartbrew.getSettings",
96
+ config: {
97
+ policies: []
98
+ }
99
+ },
100
+ {
101
+ method: "POST",
102
+ path: "/settings",
103
+ handler: "chartbrew.setSettings",
104
+ config: {
105
+ policies: []
106
+ }
107
+ },
108
+ {
109
+ method: "GET",
110
+ path: "/models",
111
+ handler: "chartbrew.getModels",
112
+ config: {
113
+ policies: []
114
+ }
115
+ },
116
+ {
117
+ method: "POST",
118
+ path: "/generate",
119
+ handler: "chartbrew.generateTemplate",
120
+ config: {
121
+ policies: []
122
+ }
123
+ }
124
+ ]
125
+ };
126
+ const chartbrew$2 = chartbrew$3;
127
+ var routes$1 = {
128
+ chartbrew: chartbrew$2
129
+ };
130
+ const request = require$$0__default.default;
131
+ function getPluginStore() {
132
+ return strapi.store({
133
+ environment: "",
134
+ type: "plugin",
135
+ name: "chartbrew"
136
+ });
137
+ }
138
+ async function createDefaultConfig() {
139
+ const pluginStore = getPluginStore();
140
+ const value = {
141
+ host: "https://api.chartbrew.com",
142
+ clientHost: "https://app.chartbrew.com",
143
+ strapiHost: process.env.STRAPI_ADMIN_BACKEND_URL || "",
144
+ token: "",
145
+ hasToken: false
146
+ };
147
+ await pluginStore.set({ key: "settings", value });
148
+ return pluginStore.get({ key: "settings" });
149
+ }
150
+ const service = ({ strapi: strapi2 }) => ({
151
+ getWelcomeMessage() {
152
+ return "Welcome to Strapi 🚀";
153
+ },
154
+ async getSettings() {
155
+ const pluginStore = getPluginStore();
156
+ let config2 = await pluginStore.get({ key: "settings" });
157
+ if (!config2) {
158
+ config2 = await createDefaultConfig();
159
+ }
160
+ return config2;
161
+ },
162
+ async setSettings(settings) {
163
+ const pluginStore = getPluginStore();
164
+ const config2 = await pluginStore.get({ key: "settings" });
165
+ const newConfig = { ...config2, ...settings.body };
166
+ if (newConfig.strapiToken) newConfig.hasToken = true;
167
+ if (!newConfig.strapiToken) {
168
+ newConfig.hasToken = false;
169
+ }
170
+ await pluginStore.set({ key: "settings", value: newConfig });
171
+ return pluginStore.get({ key: "settings" });
172
+ },
173
+ async generate(data) {
174
+ const templateData = data;
175
+ const pluginStore = getPluginStore();
176
+ const config2 = await pluginStore.get({ key: "settings" });
177
+ templateData.strapiToken = config2.strapiToken;
178
+ templateData.strapiHost = config2.strapiHost;
179
+ const apiEndpoint = strapi2.config.api?.rest?.prefix?.replace("/", "");
180
+ templateData.apiEndpoint = apiEndpoint;
181
+ let project;
182
+ if (!templateData.projectId) {
183
+ const createOpt = {
184
+ url: `${config2.host}/project`,
185
+ method: "POST",
186
+ form: {
187
+ name: `${templateData.collection} report`,
188
+ team_id: templateData.teamId
189
+ },
190
+ headers: {
191
+ accept: "application/json",
192
+ "content-type": "application/json",
193
+ authorization: `Bearer ${config2.token}`
194
+ },
195
+ json: true
196
+ };
197
+ project = await request(createOpt);
198
+ } else {
199
+ project = await request({
200
+ url: `${config2.host}/project/${templateData.projectId}`,
201
+ method: "GET",
202
+ headers: {
203
+ accept: "application/json",
204
+ authorization: `Bearer ${config2.token}`
205
+ },
206
+ json: true
207
+ });
208
+ }
209
+ const cbOptions = {
210
+ url: `${config2.host}/project/${project.id}/template/strapi`,
211
+ method: "POST",
212
+ form: templateData,
213
+ headers: {
214
+ accept: "application/json",
215
+ "content-type": "application/json",
216
+ authorization: `Bearer ${config2.token}`
217
+ },
218
+ json: true
219
+ };
220
+ await request(cbOptions);
221
+ return project;
222
+ }
223
+ });
224
+ var chartbrew$1 = service;
225
+ const chartbrew = chartbrew$1;
226
+ var services$1 = {
227
+ chartbrew
228
+ };
229
+ const bootstrap = bootstrap_1;
230
+ const destroy = destroy_1;
231
+ const register = register_1;
232
+ const config = config$1;
233
+ const contentTypes = contentTypes$1;
234
+ const controllers = controllers$1;
235
+ const middlewares = middlewares$1;
236
+ const policies = policies$1;
237
+ const routes = routes$1;
238
+ const services = services$1;
239
+ var src = {
240
+ bootstrap,
241
+ destroy,
242
+ register,
243
+ config,
244
+ controllers,
245
+ contentTypes,
246
+ middlewares,
247
+ policies,
248
+ routes,
249
+ services
250
+ };
251
+ const index = /* @__PURE__ */ getDefaultExportFromCjs(src);
252
+ module.exports = index;
@@ -0,0 +1,251 @@
1
+ import require$$0 from "request-promise";
2
+ function getDefaultExportFromCjs(x) {
3
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4
+ }
5
+ const bootstrap$1 = ({ strapi: strapi2 }) => {
6
+ };
7
+ var bootstrap_1 = bootstrap$1;
8
+ const destroy$1 = ({ strapi: strapi2 }) => {
9
+ };
10
+ var destroy_1 = destroy$1;
11
+ const register$1 = ({ strapi: strapi2 }) => {
12
+ };
13
+ var register_1 = register$1;
14
+ var config$1 = {
15
+ default: {},
16
+ validator() {
17
+ }
18
+ };
19
+ var contentTypes$1 = {};
20
+ const controller = ({ strapi: strapi2 }) => ({
21
+ index(ctx) {
22
+ ctx.body = strapi2.plugin("chartbrew").service("service").getWelcomeMessage();
23
+ },
24
+ async get() {
25
+ await strapi2.query("plugin::chartbrew.chartbrew").findMany();
26
+ },
27
+ async getSettings(ctx) {
28
+ try {
29
+ const settings = await strapi2.plugin("chartbrew").service("chartbrew").getSettings();
30
+ delete settings.strapiToken;
31
+ ctx.body = settings;
32
+ } catch (err) {
33
+ ctx.throw(500, err);
34
+ }
35
+ },
36
+ async setSettings(ctx) {
37
+ const { body } = ctx.request;
38
+ try {
39
+ await strapi2.plugin("chartbrew").service("chartbrew").setSettings(body);
40
+ const newSettings = await strapi2.plugin("chartbrew").service("chartbrew").getSettings();
41
+ delete newSettings.strapiToken;
42
+ ctx.body = newSettings;
43
+ } catch (err) {
44
+ ctx.throw(500, err);
45
+ }
46
+ },
47
+ async getModels(ctx) {
48
+ try {
49
+ const models = Object.keys(strapi2.contentTypes).map((key) => strapi2.contentTypes[key]);
50
+ const formattedModels = models.filter((m) => m.kind === "collectionType").map((model) => ({
51
+ ...model.info,
52
+ kind: model.kind,
53
+ attributes: model.attributes,
54
+ uid: model.uid
55
+ }));
56
+ ctx.body = formattedModels;
57
+ } catch (err) {
58
+ ctx.throw(400, err);
59
+ }
60
+ },
61
+ async generateTemplate(ctx) {
62
+ const { body } = ctx.request;
63
+ try {
64
+ const project = await strapi2.plugin("chartbrew").service("chartbrew").generate(body);
65
+ ctx.body = project;
66
+ } catch (err) {
67
+ ctx.throw(400, err);
68
+ }
69
+ }
70
+ });
71
+ var chartbrew$5 = controller;
72
+ const chartbrew$4 = chartbrew$5;
73
+ var controllers$1 = {
74
+ chartbrew: chartbrew$4
75
+ };
76
+ var middlewares$1 = {};
77
+ var policies$1 = {};
78
+ var chartbrew$3 = {
79
+ type: "admin",
80
+ routes: [
81
+ {
82
+ method: "GET",
83
+ path: "/",
84
+ handler: "chartbrew.get",
85
+ config: {
86
+ policies: []
87
+ }
88
+ },
89
+ {
90
+ method: "GET",
91
+ path: "/settings",
92
+ handler: "chartbrew.getSettings",
93
+ config: {
94
+ policies: []
95
+ }
96
+ },
97
+ {
98
+ method: "POST",
99
+ path: "/settings",
100
+ handler: "chartbrew.setSettings",
101
+ config: {
102
+ policies: []
103
+ }
104
+ },
105
+ {
106
+ method: "GET",
107
+ path: "/models",
108
+ handler: "chartbrew.getModels",
109
+ config: {
110
+ policies: []
111
+ }
112
+ },
113
+ {
114
+ method: "POST",
115
+ path: "/generate",
116
+ handler: "chartbrew.generateTemplate",
117
+ config: {
118
+ policies: []
119
+ }
120
+ }
121
+ ]
122
+ };
123
+ const chartbrew$2 = chartbrew$3;
124
+ var routes$1 = {
125
+ chartbrew: chartbrew$2
126
+ };
127
+ const request = require$$0;
128
+ function getPluginStore() {
129
+ return strapi.store({
130
+ environment: "",
131
+ type: "plugin",
132
+ name: "chartbrew"
133
+ });
134
+ }
135
+ async function createDefaultConfig() {
136
+ const pluginStore = getPluginStore();
137
+ const value = {
138
+ host: "https://api.chartbrew.com",
139
+ clientHost: "https://app.chartbrew.com",
140
+ strapiHost: process.env.STRAPI_ADMIN_BACKEND_URL || "",
141
+ token: "",
142
+ hasToken: false
143
+ };
144
+ await pluginStore.set({ key: "settings", value });
145
+ return pluginStore.get({ key: "settings" });
146
+ }
147
+ const service = ({ strapi: strapi2 }) => ({
148
+ getWelcomeMessage() {
149
+ return "Welcome to Strapi 🚀";
150
+ },
151
+ async getSettings() {
152
+ const pluginStore = getPluginStore();
153
+ let config2 = await pluginStore.get({ key: "settings" });
154
+ if (!config2) {
155
+ config2 = await createDefaultConfig();
156
+ }
157
+ return config2;
158
+ },
159
+ async setSettings(settings) {
160
+ const pluginStore = getPluginStore();
161
+ const config2 = await pluginStore.get({ key: "settings" });
162
+ const newConfig = { ...config2, ...settings.body };
163
+ if (newConfig.strapiToken) newConfig.hasToken = true;
164
+ if (!newConfig.strapiToken) {
165
+ newConfig.hasToken = false;
166
+ }
167
+ await pluginStore.set({ key: "settings", value: newConfig });
168
+ return pluginStore.get({ key: "settings" });
169
+ },
170
+ async generate(data) {
171
+ const templateData = data;
172
+ const pluginStore = getPluginStore();
173
+ const config2 = await pluginStore.get({ key: "settings" });
174
+ templateData.strapiToken = config2.strapiToken;
175
+ templateData.strapiHost = config2.strapiHost;
176
+ const apiEndpoint = strapi2.config.api?.rest?.prefix?.replace("/", "");
177
+ templateData.apiEndpoint = apiEndpoint;
178
+ let project;
179
+ if (!templateData.projectId) {
180
+ const createOpt = {
181
+ url: `${config2.host}/project`,
182
+ method: "POST",
183
+ form: {
184
+ name: `${templateData.collection} report`,
185
+ team_id: templateData.teamId
186
+ },
187
+ headers: {
188
+ accept: "application/json",
189
+ "content-type": "application/json",
190
+ authorization: `Bearer ${config2.token}`
191
+ },
192
+ json: true
193
+ };
194
+ project = await request(createOpt);
195
+ } else {
196
+ project = await request({
197
+ url: `${config2.host}/project/${templateData.projectId}`,
198
+ method: "GET",
199
+ headers: {
200
+ accept: "application/json",
201
+ authorization: `Bearer ${config2.token}`
202
+ },
203
+ json: true
204
+ });
205
+ }
206
+ const cbOptions = {
207
+ url: `${config2.host}/project/${project.id}/template/strapi`,
208
+ method: "POST",
209
+ form: templateData,
210
+ headers: {
211
+ accept: "application/json",
212
+ "content-type": "application/json",
213
+ authorization: `Bearer ${config2.token}`
214
+ },
215
+ json: true
216
+ };
217
+ await request(cbOptions);
218
+ return project;
219
+ }
220
+ });
221
+ var chartbrew$1 = service;
222
+ const chartbrew = chartbrew$1;
223
+ var services$1 = {
224
+ chartbrew
225
+ };
226
+ const bootstrap = bootstrap_1;
227
+ const destroy = destroy_1;
228
+ const register = register_1;
229
+ const config = config$1;
230
+ const contentTypes = contentTypes$1;
231
+ const controllers = controllers$1;
232
+ const middlewares = middlewares$1;
233
+ const policies = policies$1;
234
+ const routes = routes$1;
235
+ const services = services$1;
236
+ var src = {
237
+ bootstrap,
238
+ destroy,
239
+ register,
240
+ config,
241
+ controllers,
242
+ contentTypes,
243
+ middlewares,
244
+ policies,
245
+ routes,
246
+ services
247
+ };
248
+ const index = /* @__PURE__ */ getDefaultExportFromCjs(src);
249
+ export {
250
+ index as default
251
+ };
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "tienjs-chartbrew-plugin-strapi",
3
+ "version": "0.1.0",
4
+ "description": "Chartbrew brings data visualization to your Strapi dashboard",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/chartbrew/strapi-plugin-chartbrew#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/chartbrew/strapi-plugin-chartbrew/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+ssh://git@github.com/chartbrew/strapi-plugin-chartbrew.git"
13
+ },
14
+ "license": "MIT",
15
+ "author": "Razvan Ilin <raz@chartbrew.com>",
16
+ "type": "commonjs",
17
+ "exports": {
18
+ "./package.json": "./package.json",
19
+ "./strapi-admin": {
20
+ "source": "./admin/src/index.js",
21
+ "import": "./dist/admin/index.mjs",
22
+ "require": "./dist/admin/index.js",
23
+ "default": "./dist/admin/index.js"
24
+ },
25
+ "./strapi-server": {
26
+ "source": "./server/src/index.js",
27
+ "import": "./dist/server/index.mjs",
28
+ "require": "./dist/server/index.js",
29
+ "default": "./dist/server/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "scripts": {
36
+ "build": "strapi-plugin build",
37
+ "verify": "strapi-plugin verify",
38
+ "watch": "strapi-plugin watch",
39
+ "watch:link": "strapi-plugin watch:link"
40
+ },
41
+ "dependencies": {
42
+ "@strapi/design-system": "^2.0.0-rc.11",
43
+ "@strapi/icons": "^2.0.0-rc.11",
44
+ "js-cookie": "^3.0.5",
45
+ "moment": "^2.29.4",
46
+ "nanoid": "^5.0.7",
47
+ "react-intl": "^6.7.2",
48
+ "request": "^2.88.2",
49
+ "request-promise": "^4.2.6"
50
+ },
51
+ "devDependencies": {
52
+ "@strapi/sdk-plugin": "^5.3.2",
53
+ "@strapi/strapi": "^5.26.0",
54
+ "prettier": "^3.3.3",
55
+ "react": "^18.3.1",
56
+ "react-dom": "^18.3.1",
57
+ "react-router-dom": "^6.26.2",
58
+ "styled-components": "^6.1.13"
59
+ },
60
+ "peerDependencies": {
61
+ "@strapi/sdk-plugin": "^5.2.6",
62
+ "@strapi/strapi": "^5.0.5",
63
+ "eslint": "^8.17.0",
64
+ "react": "^18.3.1",
65
+ "react-dom": "^18.3.1",
66
+ "react-router-dom": "^6.26.2",
67
+ "styled-components": "^6.1.13"
68
+ },
69
+ "strapi": {
70
+ "kind": "plugin",
71
+ "name": "chartbrew",
72
+ "displayName": "Chartbrew",
73
+ "description": "Chartbrew brings data visualization to your Strapi dashboard"
74
+ }
75
+ }