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,304 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const react = require("react");
5
+ const designSystem = require("@strapi/design-system");
6
+ const admin = require("@strapi/strapi/admin");
7
+ const icons = require("@strapi/icons");
8
+ const reactRouterDom = require("react-router-dom");
9
+ const index = require("./index-Bk9ujIXz.js");
10
+ const store = require("./store-B-zkLoDr.js");
11
+ const defaultHost = "https://api.chartbrew.com";
12
+ const defaultClientHost = "https://app.chartbrew.com";
13
+ const strapiHostEnv = process.env.STRAPI_ADMIN_BACKEND_URL;
14
+ const Setup = () => {
15
+ const [host, setHost] = react.useState(defaultHost);
16
+ const [clientHost, setClientHost] = react.useState(defaultClientHost);
17
+ const [strapiHost, setStrapiHost] = react.useState(strapiHostEnv || "");
18
+ const [token, setToken] = react.useState("");
19
+ const [loading, setLoading] = react.useState(false);
20
+ const [saved, setSaved] = react.useState(false);
21
+ const [error, setError] = react.useState(false);
22
+ const [chartbrewUser, setChartbrewUser] = react.useState({});
23
+ const [strapiToken, setStrapiToken] = react.useState("");
24
+ const [savingToken, setSavingToken] = react.useState(false);
25
+ const [hasToken, setHasToken] = react.useState(false);
26
+ const [localAlert, setLocalAlert] = react.useState(false);
27
+ const { toggleNotification } = admin.useNotification();
28
+ react.useEffect(() => {
29
+ store.getSettings().then((data) => {
30
+ setHost(data.host);
31
+ setClientHost(data.clientHost);
32
+ setToken(data.token);
33
+ setHasToken(data.hasToken);
34
+ setStrapiHost(data.strapiHost);
35
+ });
36
+ }, []);
37
+ const _onValidateData = () => {
38
+ return !host || host.indexOf("http") === -1 || !token || !clientHost;
39
+ };
40
+ const _onUseManagedClicked = () => {
41
+ setHost(defaultHost);
42
+ setClientHost(defaultClientHost);
43
+ };
44
+ const _onFormSubmit = () => {
45
+ setSaved(false);
46
+ setError(false);
47
+ setLoading(true);
48
+ store.setSettings({ clientHost, host, token, strapiHost }).then(() => {
49
+ return fetch(`${host}/user/relog`, {
50
+ method: "POST",
51
+ headers: new Headers({
52
+ accept: "application/json",
53
+ authorization: `Bearer ${token}`
54
+ })
55
+ });
56
+ }).then((response) => {
57
+ if (!response.ok) throw new Error(400);
58
+ return response.json();
59
+ }).then((user) => {
60
+ setSaved(true);
61
+ setLoading(false);
62
+ setChartbrewUser(user);
63
+ if (process.env.STRAPI_ADMIN_BACKEND_URL.indexOf("http://localhost") > -1 && host.indexOf("http://localhost") === -1) {
64
+ setLocalAlert(true);
65
+ }
66
+ }).catch(() => {
67
+ setSaved(false);
68
+ setError(true);
69
+ setLoading(false);
70
+ });
71
+ };
72
+ const _onSaveStrapiToken = () => {
73
+ if (!strapiToken) return;
74
+ setSavingToken(true);
75
+ store.setSettings({ strapiToken }).then((data) => {
76
+ setSavingToken(false);
77
+ setHasToken(data.hasToken);
78
+ setStrapiToken("");
79
+ toggleNotification({
80
+ message: "Strapi token saved",
81
+ type: "success"
82
+ });
83
+ }).catch(() => {
84
+ setSavingToken(false);
85
+ toggleNotification({
86
+ message: "Failed to save Strapi token",
87
+ type: "danger"
88
+ });
89
+ });
90
+ };
91
+ const _onRemoveStrapiToken = () => {
92
+ setSavingToken(true);
93
+ store.setSettings({ strapiToken: false }).then((data) => {
94
+ setSavingToken(false);
95
+ setHasToken(data.hasToken);
96
+ }).catch(() => setSavingToken(false));
97
+ };
98
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
99
+ /* @__PURE__ */ jsxRuntime.jsx(
100
+ admin.Layouts.Header,
101
+ {
102
+ title: "Chartbrew Setup",
103
+ subtitle: "Connect to Chartbrew to start visualizing your Strapi data",
104
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(
105
+ designSystem.LinkButton,
106
+ {
107
+ endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, { color: "white" }),
108
+ href: "https://chartbrew.com?utm_source=strapi_plugin",
109
+ target: "_blank",
110
+ rel: "noopener noreferrer",
111
+ children: "Learn more about Chartbrew"
112
+ }
113
+ )
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Content, { children: [
117
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", marginBottom: 6, children: [
118
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", children: "Get started with Chartbrew" }),
119
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: "Learn how to get started with Chartbrew using the managed service or by self-hosting" }) }),
120
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs.Root, { label: "Two ways to get started with Chartbrew", defaultValue: "managed", id: "tabs", variant: "simple", children: [
121
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs.List, { children: [
122
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Trigger, { value: "managed", children: "Managed service" }),
123
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Trigger, { value: "self", children: "Self-hosting" })
124
+ ] }),
125
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Content, { value: "managed", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { color: "neutral800", padding: 4, background: "neutral0", children: [
126
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: "While using the managed service, all you have to do is to create an account at chartbrew.com and then follow the instructions to create an API key: " }) }),
127
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { href: "https://app.chartbrew.com/signup", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {}), variant: "tertiary", children: "1. Create an account and activate your 30-day trial here " }) }),
128
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { href: "https://chartbrew.com/blog/how-to-create-api-keys-in-chartbrew/", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {}), variant: "tertiary", children: "2. How to get your Chartbrew API key " }) })
129
+ ] }) }),
130
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Content, { value: "self", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { color: "neutral800", padding: 4, background: "neutral0", children: [
131
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: "Chartbrew can be self-hosted in a number of ways. You can use the Docker image, a VPS, or plaforms like Heroku and Vercel. Below are some links to get you started: " }) }),
132
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { href: "https://github.com/chartbrew/chartbrew?utm_source=strapi-plugin", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {}), variant: "tertiary", children: "Chartbrew on GitHub " }) }),
133
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { href: "https://docs.chartbrew.com/deployment/#run-the-application-with-docker?utm_source=strapi-plugin", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {}), variant: "tertiary", children: "Run Chartbrew using the Docker image " }) }),
134
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { href: "https://chartbrew.com/blog/how-to-deploy-chartbrew-on-heroku-and-vercel?utm_source=strapi-plugin", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {}), variant: "tertiary", children: "Deploy Chartbrew on Heroku & Vercel " }) }),
135
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { href: "https://chartbrew.com/blog/how-to-create-api-keys-in-chartbrew/", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {}), variant: "tertiary", children: "How to get your Chartbrew API key " }) })
136
+ ] }) })
137
+ ] }) })
138
+ ] }),
139
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", marginBottom: 6, children: [
140
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", children: "Connect to Chartbrew" }) }),
141
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: "You can change this to your own instance of Chartbrew, or use the managed service to not have to host the platform yourself." }) }),
142
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "host", children: [
143
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Chartbrew application host (frontend URL)" }),
144
+ /* @__PURE__ */ jsxRuntime.jsx(
145
+ designSystem.Field.Input,
146
+ {
147
+ type: "text",
148
+ placeholder: "Enter your Chartbrew application host",
149
+ value: clientHost,
150
+ onChange: (e) => setClientHost(e.target.value)
151
+ }
152
+ )
153
+ ] }) }),
154
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "host", children: [
155
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Chartbrew API host (backend URL)" }),
156
+ /* @__PURE__ */ jsxRuntime.jsx(
157
+ designSystem.Field.Input,
158
+ {
159
+ type: "text",
160
+ placeholder: "Enter your Chartbrew API host",
161
+ value: host,
162
+ onChange: (e) => setHost(e.target.value)
163
+ }
164
+ )
165
+ ] }) }),
166
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "host", children: [
167
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Your Strapi backend URL" }),
168
+ /* @__PURE__ */ jsxRuntime.jsx(
169
+ designSystem.Field.Input,
170
+ {
171
+ type: "text",
172
+ placeholder: "'https://you-strapi-url.com' or 'http://localhost:1337' for local env",
173
+ value: strapiHost,
174
+ onChange: (e) => setStrapiHost(e.target.value)
175
+ }
176
+ )
177
+ ] }) }),
178
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
179
+ designSystem.Button,
180
+ {
181
+ variant: "tertiary",
182
+ endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Magic, {}),
183
+ onClick: _onUseManagedClicked,
184
+ size: "S",
185
+ children: "Use managed Chartbrew address"
186
+ }
187
+ ) }),
188
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "token", children: [
189
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Label, { children: [
190
+ "Chartbrew API Token - ",
191
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Link, { href: "https://chartbrew.com/blog/how-to-create-api-keys-in-chartbrew/", isExternal: true, children: " How to generate an API Token" })
192
+ ] }),
193
+ /* @__PURE__ */ jsxRuntime.jsx(
194
+ designSystem.Field.Input,
195
+ {
196
+ type: "password",
197
+ placeholder: "Enter your Chartbrew API Token",
198
+ value: token,
199
+ onChange: (e) => setToken(e.target.value)
200
+ }
201
+ )
202
+ ] }) }),
203
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, direction: "row", children: [
204
+ /* @__PURE__ */ jsxRuntime.jsx(
205
+ designSystem.Button,
206
+ {
207
+ variant: saved && "success-light" || error && "danger-light" || "default",
208
+ disabled: _onValidateData(),
209
+ loading,
210
+ endIcon: saved && /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) || error && /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}) || null,
211
+ onClick: _onFormSubmit,
212
+ children: "Save and check the connection"
213
+ }
214
+ ),
215
+ chartbrewUser.id && /* @__PURE__ */ jsxRuntime.jsx(
216
+ designSystem.LinkButton,
217
+ {
218
+ variant: "secondary",
219
+ endIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ChevronRight, {}),
220
+ tag: reactRouterDom.Link,
221
+ to: `/plugins/${index.PLUGIN_ID}`,
222
+ children: "Continue to your dashboard"
223
+ }
224
+ )
225
+ ] }) }),
226
+ error && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
227
+ designSystem.Alert,
228
+ {
229
+ closeLabel: "Close alert",
230
+ title: "Authentication failed",
231
+ variant: "danger",
232
+ onClose: () => setError(false),
233
+ children: "Something went wrong with the authentication. Please check the host and token are correct and try again."
234
+ }
235
+ ) }),
236
+ saved && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
237
+ designSystem.Alert,
238
+ {
239
+ closeLabel: "Close alert",
240
+ title: `Welcome ${chartbrewUser.name}!`,
241
+ variant: "success",
242
+ onClose: () => setSaved(false),
243
+ children: "Successfully authenticated with Chartbrew. Head over to your dashboard to get started. "
244
+ }
245
+ ) }),
246
+ localAlert && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
247
+ designSystem.Alert,
248
+ {
249
+ closeLabel: "Close alert",
250
+ title: "Chartbrew might not be able to create charts",
251
+ variant: "default",
252
+ onClose: () => setLocalAlert(false),
253
+ children: "It seems you are running Strapi on your local machine and you are connecting to a Chartbrew instance that is hosted on an external server. You might not be able to create new visualizations from your Strapi data, but you can create the charts in Chartbrew and then see them in your Strapi dashboard. "
254
+ }
255
+ ) })
256
+ ] }),
257
+ !hasToken && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", children: [
258
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Allow Chartbrew to create charts from Strapi data" }) }),
259
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "omega", children: [
260
+ "Create a Read-only API token and enter it in the field below. ",
261
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Link, { to: "/settings/api-tokens", children: "Click here to create an API token " })
262
+ ] }) }),
263
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "host", children: [
264
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Strapi API Token" }),
265
+ /* @__PURE__ */ jsxRuntime.jsx(
266
+ designSystem.Field.Input,
267
+ {
268
+ type: "password",
269
+ placeholder: "Enter a Strapi Read-Only token here",
270
+ value: strapiToken,
271
+ onChange: (e) => setStrapiToken(e.target.value)
272
+ }
273
+ ),
274
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", children: "You will not be able to see this token after you save it. " })
275
+ ] }) }),
276
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
277
+ designSystem.Button,
278
+ {
279
+ variant: saved && "success-light" || error && "danger-light" || "default",
280
+ disabled: !strapiToken && !hasToken,
281
+ loading: savingToken,
282
+ onClick: _onSaveStrapiToken,
283
+ children: "Save token"
284
+ }
285
+ ) })
286
+ ] }),
287
+ hasToken && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", children: [
288
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Chartbrew can now create charts from your Strapi data" }) }),
289
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: "Chartbrew uses your Strapi API token to create charts automatically from your Strapi dashboard. You can disallow this option by clicking the remove button below. " }) }),
290
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", onClick: _onRemoveStrapiToken, children: "Remove Chartbrew's access " }) }),
291
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
292
+ designSystem.Alert,
293
+ {
294
+ closeLabel: "Close alert",
295
+ title: "A note on Chartbrew's access",
296
+ variant: "default",
297
+ children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "All existing charts will still have read access for your Strapi data. When removing the access, this will only be applied to future charts. To stop existing charts from reading the data, please head over to the Chartbrew app and remove the charts from there. " })
298
+ }
299
+ ) })
300
+ ] })
301
+ ] })
302
+ ] });
303
+ };
304
+ exports.Setup = Setup;
@@ -0,0 +1,304 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { LinkButton, Box, Typography, Tabs, Field, Button, Link, Flex, Alert } from "@strapi/design-system";
4
+ import { useNotification, Layouts } from "@strapi/strapi/admin";
5
+ import { ExternalLink, Magic, Check, Cross, ChevronRight } from "@strapi/icons";
6
+ import { Link as Link$1 } from "react-router-dom";
7
+ import { P as PLUGIN_ID } from "./index-CXvgiYYO.mjs";
8
+ import { g as getSettings, s as setSettings } from "./store-CES_iNgI.mjs";
9
+ const defaultHost = "https://api.chartbrew.com";
10
+ const defaultClientHost = "https://app.chartbrew.com";
11
+ const strapiHostEnv = process.env.STRAPI_ADMIN_BACKEND_URL;
12
+ const Setup = () => {
13
+ const [host, setHost] = useState(defaultHost);
14
+ const [clientHost, setClientHost] = useState(defaultClientHost);
15
+ const [strapiHost, setStrapiHost] = useState(strapiHostEnv || "");
16
+ const [token, setToken] = useState("");
17
+ const [loading, setLoading] = useState(false);
18
+ const [saved, setSaved] = useState(false);
19
+ const [error, setError] = useState(false);
20
+ const [chartbrewUser, setChartbrewUser] = useState({});
21
+ const [strapiToken, setStrapiToken] = useState("");
22
+ const [savingToken, setSavingToken] = useState(false);
23
+ const [hasToken, setHasToken] = useState(false);
24
+ const [localAlert, setLocalAlert] = useState(false);
25
+ const { toggleNotification } = useNotification();
26
+ useEffect(() => {
27
+ getSettings().then((data) => {
28
+ setHost(data.host);
29
+ setClientHost(data.clientHost);
30
+ setToken(data.token);
31
+ setHasToken(data.hasToken);
32
+ setStrapiHost(data.strapiHost);
33
+ });
34
+ }, []);
35
+ const _onValidateData = () => {
36
+ return !host || host.indexOf("http") === -1 || !token || !clientHost;
37
+ };
38
+ const _onUseManagedClicked = () => {
39
+ setHost(defaultHost);
40
+ setClientHost(defaultClientHost);
41
+ };
42
+ const _onFormSubmit = () => {
43
+ setSaved(false);
44
+ setError(false);
45
+ setLoading(true);
46
+ setSettings({ clientHost, host, token, strapiHost }).then(() => {
47
+ return fetch(`${host}/user/relog`, {
48
+ method: "POST",
49
+ headers: new Headers({
50
+ accept: "application/json",
51
+ authorization: `Bearer ${token}`
52
+ })
53
+ });
54
+ }).then((response) => {
55
+ if (!response.ok) throw new Error(400);
56
+ return response.json();
57
+ }).then((user) => {
58
+ setSaved(true);
59
+ setLoading(false);
60
+ setChartbrewUser(user);
61
+ if (process.env.STRAPI_ADMIN_BACKEND_URL.indexOf("http://localhost") > -1 && host.indexOf("http://localhost") === -1) {
62
+ setLocalAlert(true);
63
+ }
64
+ }).catch(() => {
65
+ setSaved(false);
66
+ setError(true);
67
+ setLoading(false);
68
+ });
69
+ };
70
+ const _onSaveStrapiToken = () => {
71
+ if (!strapiToken) return;
72
+ setSavingToken(true);
73
+ setSettings({ strapiToken }).then((data) => {
74
+ setSavingToken(false);
75
+ setHasToken(data.hasToken);
76
+ setStrapiToken("");
77
+ toggleNotification({
78
+ message: "Strapi token saved",
79
+ type: "success"
80
+ });
81
+ }).catch(() => {
82
+ setSavingToken(false);
83
+ toggleNotification({
84
+ message: "Failed to save Strapi token",
85
+ type: "danger"
86
+ });
87
+ });
88
+ };
89
+ const _onRemoveStrapiToken = () => {
90
+ setSavingToken(true);
91
+ setSettings({ strapiToken: false }).then((data) => {
92
+ setSavingToken(false);
93
+ setHasToken(data.hasToken);
94
+ }).catch(() => setSavingToken(false));
95
+ };
96
+ return /* @__PURE__ */ jsxs("div", { children: [
97
+ /* @__PURE__ */ jsx(
98
+ Layouts.Header,
99
+ {
100
+ title: "Chartbrew Setup",
101
+ subtitle: "Connect to Chartbrew to start visualizing your Strapi data",
102
+ primaryAction: /* @__PURE__ */ jsx(
103
+ LinkButton,
104
+ {
105
+ endIcon: /* @__PURE__ */ jsx(ExternalLink, { color: "white" }),
106
+ href: "https://chartbrew.com?utm_source=strapi_plugin",
107
+ target: "_blank",
108
+ rel: "noopener noreferrer",
109
+ children: "Learn more about Chartbrew"
110
+ }
111
+ )
112
+ }
113
+ ),
114
+ /* @__PURE__ */ jsxs(Layouts.Content, { children: [
115
+ /* @__PURE__ */ jsxs(Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", marginBottom: 6, children: [
116
+ /* @__PURE__ */ jsx(Typography, { variant: "beta", children: "Get started with Chartbrew" }),
117
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: "Learn how to get started with Chartbrew using the managed service or by self-hosting" }) }),
118
+ /* @__PURE__ */ jsx(Box, { paddingTop: 6, children: /* @__PURE__ */ jsxs(Tabs.Root, { label: "Two ways to get started with Chartbrew", defaultValue: "managed", id: "tabs", variant: "simple", children: [
119
+ /* @__PURE__ */ jsxs(Tabs.List, { children: [
120
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "managed", children: "Managed service" }),
121
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "self", children: "Self-hosting" })
122
+ ] }),
123
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "managed", children: /* @__PURE__ */ jsxs(Box, { color: "neutral800", padding: 4, background: "neutral0", children: [
124
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Typography, { children: "While using the managed service, all you have to do is to create an account at chartbrew.com and then follow the instructions to create an API key: " }) }),
125
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(LinkButton, { href: "https://app.chartbrew.com/signup", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsx(ExternalLink, {}), variant: "tertiary", children: "1. Create an account and activate your 30-day trial here " }) }),
126
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(LinkButton, { href: "https://chartbrew.com/blog/how-to-create-api-keys-in-chartbrew/", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsx(ExternalLink, {}), variant: "tertiary", children: "2. How to get your Chartbrew API key " }) })
127
+ ] }) }),
128
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "self", children: /* @__PURE__ */ jsxs(Box, { color: "neutral800", padding: 4, background: "neutral0", children: [
129
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { children: "Chartbrew can be self-hosted in a number of ways. You can use the Docker image, a VPS, or plaforms like Heroku and Vercel. Below are some links to get you started: " }) }),
130
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(LinkButton, { href: "https://github.com/chartbrew/chartbrew?utm_source=strapi-plugin", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsx(ExternalLink, {}), variant: "tertiary", children: "Chartbrew on GitHub " }) }),
131
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(LinkButton, { href: "https://docs.chartbrew.com/deployment/#run-the-application-with-docker?utm_source=strapi-plugin", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsx(ExternalLink, {}), variant: "tertiary", children: "Run Chartbrew using the Docker image " }) }),
132
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(LinkButton, { href: "https://chartbrew.com/blog/how-to-deploy-chartbrew-on-heroku-and-vercel?utm_source=strapi-plugin", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsx(ExternalLink, {}), variant: "tertiary", children: "Deploy Chartbrew on Heroku & Vercel " }) }),
133
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(LinkButton, { href: "https://chartbrew.com/blog/how-to-create-api-keys-in-chartbrew/", target: "_blank", rel: "noopener", endIcon: /* @__PURE__ */ jsx(ExternalLink, {}), variant: "tertiary", children: "How to get your Chartbrew API key " }) })
134
+ ] }) })
135
+ ] }) })
136
+ ] }),
137
+ /* @__PURE__ */ jsxs(Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", marginBottom: 6, children: [
138
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "beta", children: "Connect to Chartbrew" }) }),
139
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: "You can change this to your own instance of Chartbrew, or use the managed service to not have to host the platform yourself." }) }),
140
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Field.Root, { name: "host", children: [
141
+ /* @__PURE__ */ jsx(Field.Label, { children: "Chartbrew application host (frontend URL)" }),
142
+ /* @__PURE__ */ jsx(
143
+ Field.Input,
144
+ {
145
+ type: "text",
146
+ placeholder: "Enter your Chartbrew application host",
147
+ value: clientHost,
148
+ onChange: (e) => setClientHost(e.target.value)
149
+ }
150
+ )
151
+ ] }) }),
152
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Field.Root, { name: "host", children: [
153
+ /* @__PURE__ */ jsx(Field.Label, { children: "Chartbrew API host (backend URL)" }),
154
+ /* @__PURE__ */ jsx(
155
+ Field.Input,
156
+ {
157
+ type: "text",
158
+ placeholder: "Enter your Chartbrew API host",
159
+ value: host,
160
+ onChange: (e) => setHost(e.target.value)
161
+ }
162
+ )
163
+ ] }) }),
164
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Field.Root, { name: "host", children: [
165
+ /* @__PURE__ */ jsx(Field.Label, { children: "Your Strapi backend URL" }),
166
+ /* @__PURE__ */ jsx(
167
+ Field.Input,
168
+ {
169
+ type: "text",
170
+ placeholder: "'https://you-strapi-url.com' or 'http://localhost:1337' for local env",
171
+ value: strapiHost,
172
+ onChange: (e) => setStrapiHost(e.target.value)
173
+ }
174
+ )
175
+ ] }) }),
176
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
177
+ Button,
178
+ {
179
+ variant: "tertiary",
180
+ endIcon: /* @__PURE__ */ jsx(Magic, {}),
181
+ onClick: _onUseManagedClicked,
182
+ size: "S",
183
+ children: "Use managed Chartbrew address"
184
+ }
185
+ ) }),
186
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Field.Root, { name: "token", children: [
187
+ /* @__PURE__ */ jsxs(Field.Label, { children: [
188
+ "Chartbrew API Token - ",
189
+ /* @__PURE__ */ jsx(Link, { href: "https://chartbrew.com/blog/how-to-create-api-keys-in-chartbrew/", isExternal: true, children: " How to generate an API Token" })
190
+ ] }),
191
+ /* @__PURE__ */ jsx(
192
+ Field.Input,
193
+ {
194
+ type: "password",
195
+ placeholder: "Enter your Chartbrew API Token",
196
+ value: token,
197
+ onChange: (e) => setToken(e.target.value)
198
+ }
199
+ )
200
+ ] }) }),
201
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, direction: "row", children: [
202
+ /* @__PURE__ */ jsx(
203
+ Button,
204
+ {
205
+ variant: saved && "success-light" || error && "danger-light" || "default",
206
+ disabled: _onValidateData(),
207
+ loading,
208
+ endIcon: saved && /* @__PURE__ */ jsx(Check, {}) || error && /* @__PURE__ */ jsx(Cross, {}) || null,
209
+ onClick: _onFormSubmit,
210
+ children: "Save and check the connection"
211
+ }
212
+ ),
213
+ chartbrewUser.id && /* @__PURE__ */ jsx(
214
+ LinkButton,
215
+ {
216
+ variant: "secondary",
217
+ endIcon: /* @__PURE__ */ jsx(ChevronRight, {}),
218
+ tag: Link$1,
219
+ to: `/plugins/${PLUGIN_ID}`,
220
+ children: "Continue to your dashboard"
221
+ }
222
+ )
223
+ ] }) }),
224
+ error && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
225
+ Alert,
226
+ {
227
+ closeLabel: "Close alert",
228
+ title: "Authentication failed",
229
+ variant: "danger",
230
+ onClose: () => setError(false),
231
+ children: "Something went wrong with the authentication. Please check the host and token are correct and try again."
232
+ }
233
+ ) }),
234
+ saved && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
235
+ Alert,
236
+ {
237
+ closeLabel: "Close alert",
238
+ title: `Welcome ${chartbrewUser.name}!`,
239
+ variant: "success",
240
+ onClose: () => setSaved(false),
241
+ children: "Successfully authenticated with Chartbrew. Head over to your dashboard to get started. "
242
+ }
243
+ ) }),
244
+ localAlert && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
245
+ Alert,
246
+ {
247
+ closeLabel: "Close alert",
248
+ title: "Chartbrew might not be able to create charts",
249
+ variant: "default",
250
+ onClose: () => setLocalAlert(false),
251
+ children: "It seems you are running Strapi on your local machine and you are connecting to a Chartbrew instance that is hosted on an external server. You might not be able to create new visualizations from your Strapi data, but you can create the charts in Chartbrew and then see them in your Strapi dashboard. "
252
+ }
253
+ ) })
254
+ ] }),
255
+ !hasToken && /* @__PURE__ */ jsxs(Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", children: [
256
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Allow Chartbrew to create charts from Strapi data" }) }),
257
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Typography, { variant: "omega", children: [
258
+ "Create a Read-only API token and enter it in the field below. ",
259
+ /* @__PURE__ */ jsx(Link, { to: "/settings/api-tokens", children: "Click here to create an API token " })
260
+ ] }) }),
261
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Field.Root, { name: "host", children: [
262
+ /* @__PURE__ */ jsx(Field.Label, { children: "Strapi API Token" }),
263
+ /* @__PURE__ */ jsx(
264
+ Field.Input,
265
+ {
266
+ type: "password",
267
+ placeholder: "Enter a Strapi Read-Only token here",
268
+ value: strapiToken,
269
+ onChange: (e) => setStrapiToken(e.target.value)
270
+ }
271
+ ),
272
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", children: "You will not be able to see this token after you save it. " })
273
+ ] }) }),
274
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
275
+ Button,
276
+ {
277
+ variant: saved && "success-light" || error && "danger-light" || "default",
278
+ disabled: !strapiToken && !hasToken,
279
+ loading: savingToken,
280
+ onClick: _onSaveStrapiToken,
281
+ children: "Save token"
282
+ }
283
+ ) })
284
+ ] }),
285
+ hasToken && /* @__PURE__ */ jsxs(Box, { padding: 6, paddingLeft: 8, paddingRight: 8, shadow: "filterShadow", background: "neutral0", children: [
286
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Chartbrew can now create charts from your Strapi data" }) }),
287
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: "Chartbrew uses your Strapi API token to create charts automatically from your Strapi dashboard. You can disallow this option by clicking the remove button below. " }) }),
288
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Button, { variant: "danger-light", onClick: _onRemoveStrapiToken, children: "Remove Chartbrew's access " }) }),
289
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
290
+ Alert,
291
+ {
292
+ closeLabel: "Close alert",
293
+ title: "A note on Chartbrew's access",
294
+ variant: "default",
295
+ children: /* @__PURE__ */ jsx("p", { children: "All existing charts will still have read access for your Strapi data. When removing the access, this will only be applied to future charts. To stop existing charts from reading the data, please head over to the Chartbrew app and remove the charts from there. " })
296
+ }
297
+ ) })
298
+ ] })
299
+ ] })
300
+ ] });
301
+ };
302
+ export {
303
+ Setup
304
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {};
4
+ exports.default = en;
@@ -0,0 +1,4 @@
1
+ const en = {};
2
+ export {
3
+ en as default
4
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fr = {};
4
+ exports.default = fr;
@@ -0,0 +1,4 @@
1
+ const fr = {};
2
+ export {
3
+ fr as default
4
+ };