@raketa-cloud/admin 0.0.9 → 0.0.10

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-cloud/admin",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "main": "src/index.js",
5
5
  "scripts": {
6
6
  "dev": "npx tailwindcss -i ./src/styles/application.css -o ../../apps/admin/static/application.css --watch",
@@ -28,11 +28,11 @@ function bodyToParams(req, parsedBody, adapter) {
28
28
  }
29
29
 
30
30
  export default class HonoAdapter extends Adapter {
31
- constructor(router) {
31
+ constructor(router, config) {
32
32
  super(router);
33
33
  this.globalCtx = (ctx) => ctx;
34
34
  this.router = router;
35
- this.globalConfig = {};
35
+ this.globalConfig = config;
36
36
 
37
37
  // TODO: Pass in a path to redirect to after login?
38
38
  setupAuthentication(router, {
@@ -48,10 +48,6 @@ export default class HonoAdapter extends Adapter {
48
48
  this.globalCtx = globalCtx;
49
49
  }
50
50
 
51
- setGlobalConfig(globalConfigCallback) {
52
- globalConfigCallback(this.globalConfig);
53
- }
54
-
55
51
  async createContext(router, next, verb, resource, action) {
56
52
  const body = await parseBody(router.req);
57
53
 
@@ -88,111 +84,113 @@ export default class HonoAdapter extends Adapter {
88
84
  ]) {
89
85
  const method = this.getMethod(verb);
90
86
 
91
- [...Object.keys(this.globalConfig.locales), ""].forEach((currentLocale) => {
92
- const completedPath = `/${currentLocale}${path}`;
93
-
94
- method(completedPath, async (routerCtx, next) => {
95
- const ctx = await this.createContext(
96
- routerCtx,
97
- next,
98
- verb,
99
- resource,
100
- action
101
- );
102
-
103
- ctx.locales = this.globalConfig.locales;
104
- ctx.defaultLocale = this.globalConfig.defaultLocale;
105
- ctx.locale = currentLocale;
106
-
107
- const _context = {
108
- locales: ctx.locales,
109
- locale: ctx.locale,
110
- defaultLocale: ctx.defaultLocale,
111
- path: ctx.req.path,
112
- query: ctx.query || {},
113
- };
114
-
115
- console.info(
116
- `\x1b[35m[${ctx.method}] ${ctx.rawPath}\x1b[0m -> ${resource}/${action} | ${JSON.stringify(ctx.params)}`
117
- );
118
-
119
- const assigns = {
120
- beforeFilterAssigns: {},
121
- actionAssigns: {},
122
- afterFilterAssigns: {},
123
- };
124
-
125
- // Initialize global context
126
- ctx.initGlobalContext();
127
-
128
- // Process before filters
129
- if (before_filter) {
87
+ [...Object.keys(this.globalConfig.i18n.locales), ""].forEach(
88
+ (currentLocale) => {
89
+ const completedPath = `/${currentLocale}${path}`;
90
+
91
+ method(completedPath, async (routerCtx, next) => {
92
+ const ctx = await this.createContext(
93
+ routerCtx,
94
+ next,
95
+ verb,
96
+ resource,
97
+ action
98
+ );
99
+
100
+ ctx.locales = this.globalConfig.i18n.locales;
101
+ ctx.defaultLocale = this.globalConfig.i18n.defaultLocale;
102
+ ctx.locale = currentLocale;
103
+
104
+ const _context = {
105
+ locales: ctx.locales,
106
+ locale: ctx.locale,
107
+ defaultLocale: ctx.defaultLocale,
108
+ path: ctx.req.path,
109
+ query: ctx.query || {},
110
+ };
111
+
112
+ console.info(
113
+ `\x1b[35m[${ctx.method}] ${ctx.rawPath}\x1b[0m -> ${resource}/${action} | ${JSON.stringify(ctx.params)}`
114
+ );
115
+
116
+ const assigns = {
117
+ beforeFilterAssigns: {},
118
+ actionAssigns: {},
119
+ afterFilterAssigns: {},
120
+ };
121
+
122
+ // Initialize global context
123
+ ctx.initGlobalContext();
124
+
125
+ // Process before filters
126
+ if (before_filter) {
127
+ const {
128
+ redirect,
129
+ json,
130
+ assigns: beforeFilterAssigns = {},
131
+ } = before_filter(ctx) || {};
132
+
133
+ if (redirect) return routerCtx.redirect(redirect);
134
+
135
+ if (json) {
136
+ return routerCtx.json(json);
137
+ }
138
+
139
+ assigns.beforeFilterAssigns = beforeFilterAssigns;
140
+ }
141
+
142
+ // Process action
130
143
  const {
144
+ headers,
131
145
  redirect,
132
146
  json,
133
- assigns: beforeFilterAssigns = {},
134
- } = before_filter(ctx) || {};
135
-
136
- if (redirect) return routerCtx.redirect(redirect);
147
+ assigns: actionAssigns = {},
148
+ } = (await handler(ctx)) || {};
149
+ assigns.actionAssigns = actionAssigns;
137
150
 
138
- if (json) {
139
- return routerCtx.json(json);
140
- }
151
+ this.applyHeaders(headers, routerCtx);
141
152
 
142
- assigns.beforeFilterAssigns = beforeFilterAssigns;
143
- }
153
+ if (redirect) return routerCtx.redirect(redirect);
144
154
 
145
- // Process action
146
- const {
147
- headers,
148
- redirect,
149
- json,
150
- assigns: actionAssigns = {},
151
- } = (await handler(ctx)) || {};
152
- assigns.actionAssigns = actionAssigns;
155
+ // Process after filters
156
+ if (after_filter) {
157
+ const {
158
+ redirect,
159
+ json,
160
+ assigns: afterFilterAssigns = {},
161
+ } = after_filter(ctx) || {};
153
162
 
154
- this.applyHeaders(headers, routerCtx);
163
+ if (redirect) return routerCtx.redirect(redirect);
155
164
 
156
- if (redirect) return routerCtx.redirect(redirect);
165
+ if (json) {
166
+ return routerCtx.json(json);
167
+ }
157
168
 
158
- // Process after filters
159
- if (after_filter) {
160
- const {
161
- redirect,
162
- json,
163
- assigns: afterFilterAssigns = {},
164
- } = after_filter(ctx) || {};
169
+ assigns.afterFilterAssigns = afterFilterAssigns;
170
+ }
165
171
 
166
- if (redirect) return routerCtx.redirect(redirect);
172
+ const fullAssigns = {
173
+ ...ctx.assigns,
174
+ ...assigns.beforeFilterAssigns,
175
+ ...assigns.actionAssigns,
176
+ ...assigns.afterFilterAssigns,
177
+ _context: _context,
178
+ };
167
179
 
168
180
  if (json) {
169
181
  return routerCtx.json(json);
170
182
  }
171
183
 
172
- assigns.afterFilterAssigns = afterFilterAssigns;
173
- }
174
-
175
- const fullAssigns = {
176
- ...ctx.assigns,
177
- ...assigns.beforeFilterAssigns,
178
- ...assigns.actionAssigns,
179
- ...assigns.afterFilterAssigns,
180
- _context: _context,
181
- };
182
-
183
- if (json) {
184
- return routerCtx.json(json);
185
- }
186
-
187
- const rendered = this.renderAction({
188
- views,
189
- action,
190
- assigns: fullAssigns,
191
- });
184
+ const rendered = this.renderAction({
185
+ views,
186
+ action,
187
+ assigns: fullAssigns,
188
+ });
192
189
 
193
- return routerCtx.html(rendered);
194
- });
195
- });
190
+ return routerCtx.html(rendered);
191
+ });
192
+ }
193
+ );
196
194
  }
197
195
 
198
196
  routeCollection(mapping) {
@@ -1,4 +1,4 @@
1
- import ClonesPage from "../../cloud/ClonesPage";
1
+ import ClonePage from "../../cloud/ClonePage";
2
2
  import PageCloneHandler from "../PageCloneHandler";
3
3
 
4
4
  import Factory from "../../../../../apps/admin/test/factory";
@@ -7,7 +7,7 @@ import { testConfig } from "../../../../../apps/admin/test/handlersHelper";
7
7
  function buildCtx(page) {
8
8
  return {
9
9
  client: {
10
- clonePage: new ClonesPage(testConfig, "token"),
10
+ clonePage: new ClonePage(testConfig, "token"),
11
11
  },
12
12
  params: { parent_id: page.id },
13
13
  locale: "en",
package/src/index.js CHANGED
@@ -4,7 +4,10 @@ export { default as routeNestedCollection } from "./routeNestedCollection";
4
4
  export { default as routeMember } from "./routeMember";
5
5
  export { default as routeNestedMember } from "./routeNestedMember";
6
6
  export { default as setGlobalContext } from "./setGlobalContext";
7
- export { default as setGlobalConfig } from "./setGlobalConfig";
7
+ export { default as routePages } from "./routePages";
8
+ export { default as routeSettings } from "./routeSettings";
9
+ export { default as setupCloud } from "./setupCloud";
10
+ export { default as routeStandard } from "./routeStandard";
8
11
 
9
12
  export { default as Redirects } from "./cloud/Redirects";
10
13
  export { default as RedirectsHandler } from "./handlers/RedirectsHandler";
@@ -15,7 +18,7 @@ export { default as SettingsGeneralHandler } from "./handlers/SettingsGeneralHan
15
18
  export { default as SettingsLayoutHandler } from "./handlers/SettingsLayoutHandler";
16
19
  export { default as SettingsMetaHandler } from "./handlers/SettingsMetaHandler";
17
20
  export { default as ChangePageURL } from "./cloud/ChangePageURL";
18
- export { default as ClonePage } from "./cloud/ClonesPage";
21
+ export { default as ClonePage } from "./cloud/ClonePage";
19
22
  export { default as DeletePage } from "./cloud/DeletePage";
20
23
  export { default as PageChanges } from "./cloud/PageChanges";
21
24
  export { default as PageRevisions } from "./cloud/PageRevisions";
@@ -0,0 +1,100 @@
1
+ import routeCollection from "./routeCollection";
2
+ import routeNestedCollection from "./routeNestedCollection";
3
+ import routeNestedMember from "./routeNestedMember";
4
+ import PageTranslationsHandler from "./handlers/PageTranslationsHandler";
5
+ import PageRevisionsHandler from "./handlers/PageRevisionsHandler";
6
+ import PageRevisionsGeneralHandler from "./handlers/PageRevisionsGeneralHandler";
7
+ import PageRevisionsVisualsHandler from "./handlers/PageRevisionsVisualsHandler";
8
+ import PageRevisionsCodesHandler from "./handlers/PageRevisionsCodesHandler";
9
+ import PageRevisionsMetaHandler from "./handlers/PageRevisionsMetaHandler";
10
+ import PageRevisionsTagsHandler from "./handlers/PageRevisionsTagsHandler";
11
+ import PageRevisionsLockHandler from "./handlers/PageRevisionsLockHandler";
12
+ import PageRevisionsUnlockHandler from "./handlers/PageRevisionsUnlockHandler";
13
+ import PageCloneHandler from "./handlers/PageCloneHandler";
14
+ import PageURLsHandler from "./handlers/PageURLsHandler";
15
+ import PageDeleteHandler from "./handlers/PageDeleteHandler";
16
+ import RevertPageRevisionHandler from "./handlers/RevertPageRevisionHandler";
17
+ import PublishPageRevisionHandler from "./handlers/PublishPageRevisionHandler";
18
+ import PageRevisionsWidgetsHandler from "./handlers/PageRevisionsWidgetsHandler";
19
+ import PagesHandler from "./handlers/PagesHandler";
20
+
21
+ function routePages(adapter) {
22
+ routeCollection(adapter, "pages", PagesHandler);
23
+ routeNestedCollection(
24
+ adapter,
25
+ "pages",
26
+ "page_translations",
27
+ PageTranslationsHandler
28
+ );
29
+ routeNestedCollection(
30
+ adapter,
31
+ "pages",
32
+ "page_revisions",
33
+ PageRevisionsHandler
34
+ );
35
+ routeNestedMember(
36
+ adapter,
37
+ "page_revisions",
38
+ "general",
39
+ PageRevisionsGeneralHandler
40
+ );
41
+ routeNestedMember(
42
+ adapter,
43
+ "page_revisions",
44
+ "visuals",
45
+ PageRevisionsVisualsHandler
46
+ );
47
+ routeNestedMember(
48
+ adapter,
49
+ "page_revisions",
50
+ "codes",
51
+ PageRevisionsCodesHandler
52
+ );
53
+ routeNestedMember(
54
+ adapter,
55
+ "page_revisions",
56
+ "meta",
57
+ PageRevisionsMetaHandler
58
+ );
59
+ routeNestedMember(
60
+ adapter,
61
+ "page_revisions",
62
+ "tags",
63
+ PageRevisionsTagsHandler
64
+ );
65
+ routeNestedCollection(
66
+ adapter,
67
+ "page_revisions",
68
+ "page_lock",
69
+ PageRevisionsLockHandler
70
+ );
71
+ routeNestedCollection(
72
+ adapter,
73
+ "page_revisions",
74
+ "page_unlock",
75
+ PageRevisionsUnlockHandler
76
+ );
77
+ routeNestedCollection(adapter, "pages", "clones", PageCloneHandler);
78
+ routeNestedCollection(adapter, "pages", "page_urls", PageURLsHandler);
79
+ routeNestedCollection(adapter, "pages", "page_deletes", PageDeleteHandler);
80
+ routeNestedCollection(
81
+ adapter,
82
+ "pages",
83
+ "page_changes/reverts",
84
+ RevertPageRevisionHandler
85
+ );
86
+ routeNestedCollection(
87
+ adapter,
88
+ "page_revisions",
89
+ "page_publish",
90
+ PublishPageRevisionHandler
91
+ );
92
+ routeNestedMember(
93
+ adapter,
94
+ "api/page_revisions",
95
+ "widgets",
96
+ PageRevisionsWidgetsHandler
97
+ );
98
+ }
99
+
100
+ export default routePages;
@@ -0,0 +1,12 @@
1
+ import routeMember from "./routeMember";
2
+ import SettingsLayoutHandler from "./handlers/SettingsLayoutHandler";
3
+ import SettingsMetaHandler from "./handlers/SettingsMetaHandler";
4
+ import SettingsGeneralHandler from "./handlers/SettingsGeneralHandler";
5
+
6
+ function routeSettings(adapter) {
7
+ routeMember(adapter, "settings/general", SettingsGeneralHandler);
8
+ routeMember(adapter, "settings/meta", SettingsMetaHandler);
9
+ routeMember(adapter, "settings/layout", SettingsLayoutHandler);
10
+ }
11
+
12
+ export default routeSettings;
@@ -0,0 +1,14 @@
1
+ import routeCollection from "./routeCollection";
2
+ import routeSettings from "./routeSettings";
3
+ import routePages from "./routePages";
4
+ import RedirectsHandler from "./handlers/RedirectsHandler";
5
+ import TagsHandler from "./handlers/TagsHandler";
6
+
7
+ function routeStandard(adapter) {
8
+ routeCollection(adapter, "redirects", RedirectsHandler);
9
+ routeCollection(adapter, "tags", TagsHandler);
10
+ routeSettings(adapter);
11
+ routePages(adapter);
12
+ }
13
+
14
+ export default routeStandard;
@@ -0,0 +1,43 @@
1
+ import Redirects from "./cloud/Redirects";
2
+ import Settings from "./cloud/Settings";
3
+ import Tags from "./cloud/Tags";
4
+ import Pages from "./cloud/Pages";
5
+ import PageRevisions from "./cloud/PageRevisions";
6
+ import PageTranslations from "./cloud/PageTranslations";
7
+ import PageChanges from "./cloud/PageChanges";
8
+ import ClonePage from "./cloud/ClonePage";
9
+ import DeletePage from "./cloud/DeletePage";
10
+ import ChangePageURL from "./cloud/ChangePageURL";
11
+ import RevertPageRevision from "./cloud/RevertPageRevision";
12
+
13
+ function setupCloud(ctx, getConfig) {
14
+ if (!ctx?.authentication?.token) return;
15
+
16
+ ctx.client = {};
17
+
18
+ ctx.client.redirects = new Redirects(getConfig, ctx.authentication.token);
19
+ ctx.client.settings = new Settings(getConfig, ctx.authentication.token);
20
+ ctx.client.tags = new Tags(getConfig, ctx.authentication.token);
21
+ ctx.client.pages = new Pages(getConfig, ctx.authentication.token);
22
+ ctx.client.pageRevisions = new PageRevisions(
23
+ getConfig,
24
+ ctx.authentication.token
25
+ );
26
+ ctx.client.pageTranslations = new PageTranslations(
27
+ getConfig,
28
+ ctx.authentication.token
29
+ );
30
+ ctx.client.pageChanges = new PageChanges(getConfig, ctx.authentication.token);
31
+ ctx.client.clonePage = new ClonePage(getConfig, ctx.authentication.token);
32
+ ctx.client.deletePage = new DeletePage(getConfig, ctx.authentication.token);
33
+ ctx.client.changePageURL = new ChangePageURL(
34
+ getConfig,
35
+ ctx.authentication.token
36
+ );
37
+ ctx.client.revertPageRevision = new RevertPageRevision(
38
+ getConfig,
39
+ ctx.authentication.token
40
+ );
41
+ }
42
+
43
+ export default setupCloud;
@@ -1,5 +0,0 @@
1
- const setGlobalConfig = (adapter, func) => {
2
- adapter.setGlobalConfig(func);
3
- };
4
-
5
- export default setGlobalConfig;
File without changes