@raketa-cloud/admin 0.0.17 → 0.0.18

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.17",
3
+ "version": "0.0.18",
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",
@@ -99,6 +99,7 @@ export default class HonoAdapter extends Adapter {
99
99
  ctx.locales = this.globalConfig.i18n.locales;
100
100
  ctx.defaultLocale = this.globalConfig.i18n.defaultLocale;
101
101
  ctx.locale = currentLocale;
102
+ ctx.remoteConfig = { ...this.globalConfig.remoteConfig };
102
103
 
103
104
  const _context = {
104
105
  locales: ctx.locales,
@@ -31,8 +31,11 @@ const create = async (ctx, opts) => {
31
31
 
32
32
  if (params.redirect === "301" || params.redirect === "410") {
33
33
  redirect = {
34
- // TODO: fix url with consideration of locale & defaultLocale in the frontend project
35
- url: `/${article.slug}`,
34
+ url: ctx.remoteConfig.resourcePath(
35
+ article,
36
+ article.articleType.slug,
37
+ ctx.locale
38
+ ),
36
39
  destination: params.redirect === "301" ? params.destination : "/",
37
40
  httpResponseCode: Number.parseInt(params.redirect, 10),
38
41
  note: "Created via article deletion process",
@@ -33,7 +33,11 @@ const create = async (ctx, opts) => {
33
33
 
34
34
  if (change.redirect) {
35
35
  redirectParams = {
36
- // TODO: We need some config from the FE project on how to build paths here!
36
+ url: ctx.remoteConfig.resourcePath(
37
+ article,
38
+ article.articleType.slug,
39
+ ctx.locale
40
+ ),
37
41
  url: `/${article.slug}`,
38
42
  destination: change.slug,
39
43
  httpResponseCode: 301,
@@ -31,8 +31,11 @@ const create = async (ctx, opts) => {
31
31
 
32
32
  if (params.redirect === "301" || params.redirect === "410") {
33
33
  redirect = {
34
- // TODO: fix url with consideration of locale & defaultLocale in the frontend project
35
- url: `/${event.slug}`,
34
+ url: ctx.remoteConfig.resourcePath(
35
+ event,
36
+ event.eventType.slug,
37
+ ctx.locale
38
+ ),
36
39
  destination: params.redirect === "301" ? params.destination : "/",
37
40
  httpResponseCode: Number.parseInt(params.redirect, 10),
38
41
  note: "Created via event deletion process",
@@ -33,8 +33,11 @@ const create = async (ctx, opts) => {
33
33
 
34
34
  if (change.redirect) {
35
35
  redirectParams = {
36
- // TODO: We need some config from the FE project on how to build paths here!
37
- url: `/${event.slug}`,
36
+ url: ctx.remoteConfig.resourcePath(
37
+ event,
38
+ event.eventType.slug,
39
+ ctx.locale
40
+ ),
38
41
  destination: change.slug,
39
42
  httpResponseCode: 301,
40
43
  note: `Created with changed URL for a resource of type ${opts.eventType}`,
@@ -31,8 +31,7 @@ const create = async (ctx, opts) => {
31
31
 
32
32
  if (params.redirect === "301" || params.redirect === "410") {
33
33
  redirect = {
34
- // TODO: fix url with consideration of locale & defaultLocale in the frontend project
35
- url: `/${page.slug}`,
34
+ url: ctx.remoteConfig.resourcePath(page, page.pageType.slug, ctx.locale),
36
35
  destination: params.redirect === "301" ? params.destination : "/",
37
36
  httpResponseCode: Number.parseInt(params.redirect, 10),
38
37
  note: "Created via page deletion process",
@@ -33,8 +33,7 @@ const create = async (ctx, opts) => {
33
33
 
34
34
  if (change.redirect) {
35
35
  redirectParams = {
36
- // TODO: We need some config from the FE project on how to build paths here!
37
- url: `/${page.slug}`,
36
+ url: ctx.remoteConfig.resourcePath(page, page.pageType.slug, ctx.locale),
38
37
  destination: change.slug,
39
38
  httpResponseCode: 301,
40
39
  note: `Created with changed URL for a ${opts.pageType}`,
@@ -1,7 +1,7 @@
1
1
  import DeletesHandler from "../../../../handlers/articles/DeletesHandler";
2
2
  import Articles from "../../../../cloud/Articles";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test//handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test//handlersHelper";
5
5
 
6
6
  function buildCtx(article, updateSettings) {
7
7
  return {
@@ -13,6 +13,7 @@ function buildCtx(article, updateSettings) {
13
13
  deleteAction: updateSettings,
14
14
  },
15
15
  locale: "en",
16
+ remoteConfig: remoteConfig(),
16
17
  };
17
18
  }
18
19
 
@@ -40,7 +41,7 @@ describe("Article delete", () => {
40
41
 
41
42
  expect(mockFind).toHaveBeenCalledWith(article.id, "en");
42
43
  expect(mockDelete).toHaveBeenCalledWith(article.id, "en", {
43
- url: `/${article.slug}`,
44
+ url: `/en/blog/${article.slug}`,
44
45
  destination: updateSettings.destination,
45
46
  httpResponseCode: 301,
46
47
  note: "Created via article deletion process",
@@ -83,7 +84,7 @@ describe("Article delete", () => {
83
84
 
84
85
  expect(mockFind).toHaveBeenCalledWith(article.id, "en");
85
86
  expect(mockDelete).toHaveBeenCalledWith(article.id, "en", {
86
- url: `/${article.slug}`,
87
+ url: `/en/blog/${article.slug}`,
87
88
  destination: "/",
88
89
  httpResponseCode: 410,
89
90
  note: "Created via article deletion process",
@@ -1,7 +1,7 @@
1
1
  import DeletesHandler from "../../../../handlers/articles/DeletesHandler";
2
2
  import Articles from "../../../../cloud/Articles";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test//handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test//handlersHelper";
5
5
 
6
6
  function buildCtx(article) {
7
7
  return {
@@ -10,6 +10,7 @@ function buildCtx(article) {
10
10
  },
11
11
  params: { parent_id: article.id },
12
12
  locale: "en",
13
+ remoteConfig: remoteConfig(),
13
14
  };
14
15
  }
15
16
 
@@ -1,7 +1,7 @@
1
1
  import URLsHandler from "../../../../handlers/articles/URLsHandler";
2
2
  import Articles from "../../../../cloud/Articles";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test/handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test/handlersHelper";
5
5
 
6
6
  function buildCtx(article, updateSettings) {
7
7
  return {
@@ -13,6 +13,7 @@ function buildCtx(article, updateSettings) {
13
13
  change: updateSettings,
14
14
  },
15
15
  locale: "en",
16
+ remoteConfig: remoteConfig(),
16
17
  };
17
18
  }
18
19
 
@@ -1,7 +1,7 @@
1
1
  import DeletesHandler from "../../../../handlers/events/DeletesHandler";
2
2
  import Events from "../../../../cloud/Events";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test//handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test//handlersHelper";
5
5
 
6
6
  function buildCtx(event, updateSettings) {
7
7
  return {
@@ -13,6 +13,7 @@ function buildCtx(event, updateSettings) {
13
13
  deleteAction: updateSettings,
14
14
  },
15
15
  locale: "en",
16
+ remoteConfig: remoteConfig(),
16
17
  };
17
18
  }
18
19
 
@@ -40,7 +41,7 @@ describe("Event delete", () => {
40
41
 
41
42
  expect(mockFind).toHaveBeenCalledWith(event.id, "en");
42
43
  expect(mockDelete).toHaveBeenCalledWith(event.id, "en", {
43
- url: `/${event.slug}`,
44
+ url: `/en/events/${event.slug}`,
44
45
  destination: updateSettings.destination,
45
46
  httpResponseCode: 301,
46
47
  note: "Created via event deletion process",
@@ -83,7 +84,7 @@ describe("Event delete", () => {
83
84
 
84
85
  expect(mockFind).toHaveBeenCalledWith(event.id, "en");
85
86
  expect(mockDelete).toHaveBeenCalledWith(event.id, "en", {
86
- url: `/${event.slug}`,
87
+ url: `/en/events/${event.slug}`,
87
88
  destination: "/",
88
89
  httpResponseCode: 410,
89
90
  note: "Created via event deletion process",
@@ -1,7 +1,7 @@
1
1
  import DeletesHandler from "../../../../handlers/events/DeletesHandler";
2
2
  import Events from "../../../../cloud/Events";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test//handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test//handlersHelper";
5
5
 
6
6
  function buildCtx(event) {
7
7
  return {
@@ -10,6 +10,7 @@ function buildCtx(event) {
10
10
  },
11
11
  params: { parent_id: event.id },
12
12
  locale: "en",
13
+ remoteConfig: remoteConfig(),
13
14
  };
14
15
  }
15
16
 
@@ -1,7 +1,7 @@
1
1
  import URLsHandler from "../../../../handlers/events/URLsHandler";
2
2
  import Events from "../../../../cloud/Events";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test/handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test/handlersHelper";
5
5
 
6
6
  function buildCtx(event, updateSettings) {
7
7
  return {
@@ -13,6 +13,7 @@ function buildCtx(event, updateSettings) {
13
13
  change: updateSettings,
14
14
  },
15
15
  locale: "en",
16
+ remoteConfig: remoteConfig(),
16
17
  };
17
18
  }
18
19
 
@@ -44,7 +45,7 @@ describe("Event change url", () => {
44
45
  updateSettings.slug,
45
46
  "en",
46
47
  {
47
- url: `/${event.slug}`,
48
+ url: `/en/events/${event.slug}`,
48
49
  destination: updateSettings.slug,
49
50
  httpResponseCode: 301,
50
51
  note: "Created with changed URL for a resource of type event",
@@ -132,7 +133,7 @@ describe("Event change url", () => {
132
133
  updateSettings.slug,
133
134
  "en",
134
135
  {
135
- url: `/${event.slug}`,
136
+ url: `/en/events/${event.slug}`,
136
137
  destination: updateSettings.slug,
137
138
  httpResponseCode: 301,
138
139
  note: "Created with changed URL for a resource of type event",
@@ -1,7 +1,7 @@
1
1
  import DeletesHandler from "../../../../handlers/pages/DeletesHandler";
2
2
  import Pages from "../../../../cloud/Pages";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test//handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test//handlersHelper";
5
5
 
6
6
  function buildCtx(page, updateSettings) {
7
7
  return {
@@ -13,6 +13,7 @@ function buildCtx(page, updateSettings) {
13
13
  deleteAction: updateSettings,
14
14
  },
15
15
  locale: "en",
16
+ remoteConfig: remoteConfig(),
16
17
  };
17
18
  }
18
19
 
@@ -40,7 +41,7 @@ describe("Page delete", () => {
40
41
 
41
42
  expect(mockFind).toHaveBeenCalledWith(page.id, "en");
42
43
  expect(mockDelete).toHaveBeenCalledWith(page.id, "en", {
43
- url: `/${page.slug}`,
44
+ url: `/en/${page.slug}`,
44
45
  destination: updateSettings.destination,
45
46
  httpResponseCode: 301,
46
47
  note: "Created via page deletion process",
@@ -83,7 +84,7 @@ describe("Page delete", () => {
83
84
 
84
85
  expect(mockFind).toHaveBeenCalledWith(page.id, "en");
85
86
  expect(mockDelete).toHaveBeenCalledWith(page.id, "en", {
86
- url: `/${page.slug}`,
87
+ url: `/en/${page.slug}`,
87
88
  destination: "/",
88
89
  httpResponseCode: 410,
89
90
  note: "Created via page deletion process",
@@ -1,7 +1,7 @@
1
1
  import DeletesHandler from "../../../../handlers/pages/DeletesHandler";
2
2
  import Pages from "../../../../cloud/Pages";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test//handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test//handlersHelper";
5
5
 
6
6
  function buildCtx(page) {
7
7
  return {
@@ -10,6 +10,7 @@ function buildCtx(page) {
10
10
  },
11
11
  params: { parent_id: page.id },
12
12
  locale: "en",
13
+ remoteConfig: remoteConfig(),
13
14
  };
14
15
  }
15
16
 
@@ -1,7 +1,7 @@
1
1
  import URLsHandler from "../../../../handlers/pages/URLsHandler";
2
2
  import Pages from "../../../../cloud/Pages";
3
3
  import Factory from "../../../../../test/factory";
4
- import { testConfig } from "../../../../../test/handlersHelper";
4
+ import { testConfig, remoteConfig } from "../../../../../test/handlersHelper";
5
5
 
6
6
  function buildCtx(page, updateSettings) {
7
7
  return {
@@ -13,6 +13,7 @@ function buildCtx(page, updateSettings) {
13
13
  change: updateSettings,
14
14
  },
15
15
  locale: "en",
16
+ remoteConfig: remoteConfig(),
16
17
  };
17
18
  }
18
19
 
@@ -44,7 +45,7 @@ describe("Page change url", () => {
44
45
  updateSettings.slug,
45
46
  "en",
46
47
  {
47
- url: `/${page.slug}`,
48
+ url: `/en/${page.slug}`,
48
49
  destination: updateSettings.slug,
49
50
  httpResponseCode: 301,
50
51
  note: "Created with changed URL for a page",
@@ -132,7 +133,7 @@ describe("Page change url", () => {
132
133
  updateSettings.slug,
133
134
  "en",
134
135
  {
135
- url: `/${page.slug}`,
136
+ url: `/en/${page.slug}`,
136
137
  destination: updateSettings.slug,
137
138
  httpResponseCode: 301,
138
139
  note: "Created with changed URL for a page",
package/test/factory.js CHANGED
@@ -29,7 +29,7 @@ const PAGE = {
29
29
  originalId: null,
30
30
  insertedAt: "2024-08-30T19:05:00Z",
31
31
  tags: [],
32
- pageType: {},
32
+ pageType: { slug: "page" },
33
33
  categories: [],
34
34
  };
35
35
 
@@ -50,7 +50,7 @@ const ARTICLE = {
50
50
  originalId: null,
51
51
  insertedAt: "2024-08-30T19:05:00Z",
52
52
  tags: [],
53
- articleType: {},
53
+ articleType: { slug: "article" },
54
54
  categories: [],
55
55
  };
56
56
 
@@ -73,7 +73,7 @@ const EVENT = {
73
73
  originalId: null,
74
74
  insertedAt: "2024-08-30T19:05:00Z",
75
75
  tags: [],
76
- articleType: {},
76
+ eventType: { slug: "event" },
77
77
  categories: [],
78
78
  };
79
79
 
@@ -6,4 +6,26 @@ function testConfig() {
6
6
  };
7
7
  }
8
8
 
9
- export { testConfig };
9
+ function remoteConfig() {
10
+ return {
11
+ resourcePath: (resource, resourceType, locale) => {
12
+ const PREFIX_MAP = {
13
+ page: "/",
14
+ article: "/blog",
15
+ event: "/events",
16
+ };
17
+
18
+ const prefix = PREFIX_MAP[resourceType];
19
+
20
+ if (!prefix) {
21
+ throw new Error(`Unknown resource type: ${resourceType}`);
22
+ }
23
+
24
+ return [`/${locale}`, prefix, "/", resource.slug]
25
+ .join("")
26
+ .replace("//", "/");
27
+ },
28
+ };
29
+ }
30
+
31
+ export { testConfig, remoteConfig };