@raketa-cloud/admin 0.0.2 → 0.0.4

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 (50) hide show
  1. package/babel.config.js +6 -0
  2. package/bin/tailwind +2 -0
  3. package/package.json +22 -29
  4. package/src/Adapter.js +105 -0
  5. package/src/HonoAdapter.js +120 -0
  6. package/src/RaketaContext.js +33 -0
  7. package/src/createNestedResource.js +83 -0
  8. package/src/createResource.js +83 -0
  9. package/src/index.js +3 -0
  10. package/src/styles/application.css +17 -0
  11. package/src/tests/HonoAdapter.test.js +33 -0
  12. package/src/tests/createNestedResource.test.js +150 -0
  13. package/src/tests/createResource.test.js +115 -0
  14. package/src/views/layouts/application.ejs +22 -0
  15. package/src/views/redirects/index.ejs +1 -0
  16. package/tailwind.config.js +8 -0
  17. package/tsconfig.json +14 -14
  18. package/tsconfig.lint.json +8 -0
  19. package/biome.json +0 -6
  20. package/jest.config.js +0 -15
  21. package/src/app.tsx +0 -19
  22. package/src/crud/login.tsx +0 -99
  23. package/src/crud/logout.tsx +0 -14
  24. package/src/crud/tags.tsx +0 -235
  25. package/src/index.ts +0 -1
  26. package/src/lib/dxp/private/tags.ts +0 -106
  27. package/src/lib/dxp/protocol.ts +0 -32
  28. package/src/lib/gateway/login.ts +0 -44
  29. package/src/lib/gateway/protocol.ts +0 -8
  30. package/src/lib/gqlEngine.ts +0 -17
  31. package/src/lib/logger.tsx +0 -149
  32. package/src/middleware/authentication.ts +0 -62
  33. package/src/middleware/http_logger.ts +0 -41
  34. package/src/middleware/logger.ts +0 -9
  35. package/src/shared/Layout.tsx +0 -50
  36. package/tests/integration/authentication/middleware.test.ts +0 -100
  37. package/tests/integration/login/create.test.ts +0 -117
  38. package/tests/integration/login/index.test.ts +0 -16
  39. package/tests/integration/logout/delete.test.ts +0 -17
  40. package/tests/integration/tags/create.test.ts +0 -66
  41. package/tests/integration/tags/delete.test.ts +0 -74
  42. package/tests/integration/tags/edit.test.ts +0 -43
  43. package/tests/integration/tags/index.test.ts +0 -66
  44. package/tests/integration/tags/new.test.ts +0 -16
  45. package/tests/integration/tags/update.test.ts +0 -87
  46. package/tests/support/helpers.ts +0 -53
  47. package/tests/support/setup.js +0 -9
  48. package/turbo/generators/config.ts +0 -30
  49. package/turbo/generators/templates/component.hbs +0 -14
  50. package/turbo.json +0 -9
@@ -1,66 +0,0 @@
1
- import { describe, expect, test } from "@jest/globals";
2
- import app from "src/crud/tags";
3
- import {
4
- mockGraphql,
5
- assertPrivateRequestCalled,
6
- assertEmptyBody,
7
- } from "tests/support/helpers";
8
-
9
- const TAG_MUTATION = `
10
- mutation CreateTag($input: CreateTagInput!) {
11
- createTag(input: $input) {
12
- tag {
13
- id
14
- slug
15
- name
16
- }
17
- errors {
18
- key
19
- message
20
- codes {
21
- key
22
- placeholders
23
- }
24
- }
25
- }
26
- }
27
- `;
28
-
29
- describe("Tag create endpoint", () => {
30
- test("GET /tags/:id/edit", async () => {
31
- const tag = {
32
- id: 1,
33
- name: "Tag 1",
34
- slug: "tag-1",
35
- };
36
-
37
- const requestsMock = mockGraphql(
38
- Promise.resolve({
39
- createTag: {
40
- tag: tag,
41
- errors: null,
42
- },
43
- }),
44
- );
45
-
46
- const formData = new FormData();
47
- formData.set("name", "Tag 1");
48
- formData.set("slug", "tag-1");
49
-
50
- const res = await app.request("/tags", { method: "POST", body: formData });
51
-
52
- assertPrivateRequestCalled(requestsMock, TAG_MUTATION, {
53
- input: {
54
- locale: "en",
55
- tag: {
56
- name: "Tag 1",
57
- slug: "tag-1",
58
- },
59
- },
60
- });
61
-
62
- expect(res.status).toBe(301);
63
- expect(res.headers.get("Location")).toBe("/tags");
64
- await assertEmptyBody(res);
65
- });
66
- });
@@ -1,74 +0,0 @@
1
- import { describe, expect, test } from "@jest/globals";
2
- import app from "src/crud/tags";
3
- import {
4
- mockMultipleGraphql,
5
- assertPrivateRequestCalled,
6
- assertJSONContent,
7
- } from "tests/support/helpers";
8
-
9
- const TAG_QUERY = `
10
- query TagByID($input: IdInput!) {
11
- tag(input: $input) {
12
- id
13
- slug
14
- name
15
- }
16
- }
17
- `;
18
-
19
- const DELETE_TAG_MUTATION = `
20
- mutation DeleteTag($input: IdInput!) {
21
- deleteTag(input: $input) {
22
- tag {
23
- id
24
- slug
25
- name
26
- }
27
- errors {
28
- key
29
- message
30
- codes {
31
- key
32
- placeholders
33
- }
34
- }
35
- }
36
- }
37
- `;
38
-
39
- describe("Tag delete endpoint", () => {
40
- test("DELETE /tags/:id", async () => {
41
- const tag = {
42
- id: 1,
43
- name: "Tag 1",
44
- slug: "tag-1",
45
- };
46
-
47
- const requestsMock = mockMultipleGraphql([
48
- Promise.resolve({
49
- tag: tag,
50
- }),
51
- Promise.resolve({
52
- deleteTag: {
53
- tag: tag,
54
- errors: null,
55
- },
56
- }),
57
- ]);
58
-
59
- const res = await app.request("/tags/1", { method: "DELETE" });
60
-
61
- assertPrivateRequestCalled(requestsMock, TAG_QUERY, {
62
- input: { locale: "en", id: 1 },
63
- });
64
-
65
- assertPrivateRequestCalled(requestsMock, DELETE_TAG_MUTATION, {
66
- input: { locale: "en", id: 1 },
67
- });
68
-
69
- expect(res.status).toBe(201);
70
- expect(res.headers.get("HX-Redirect")).toBe("/tags");
71
-
72
- await assertJSONContent(res, tag);
73
- });
74
- });
@@ -1,43 +0,0 @@
1
- import { describe, expect, test } from "@jest/globals";
2
- import app from "src/crud/tags";
3
- import { mockGraphql, assertPrivateRequestCalled } from "tests/support/helpers";
4
-
5
- const TAG_QUERY = `
6
- query TagByID($input: IdInput!) {
7
- tag(input: $input) {
8
- id
9
- slug
10
- name
11
- }
12
- }
13
- `;
14
-
15
- describe("Tag edit endpoint", () => {
16
- test("GET /tags/:id/edit", async () => {
17
- const tag = {
18
- id: 1,
19
- name: "Tag 1",
20
- slug: "tag-1",
21
- };
22
-
23
- const requestsMock = mockGraphql(
24
- Promise.resolve({
25
- tag: tag,
26
- }),
27
- );
28
-
29
- const res = await app.request("/tags/1/edit");
30
-
31
- assertPrivateRequestCalled(requestsMock, TAG_QUERY, {
32
- input: { locale: "en", id: 1 },
33
- });
34
-
35
- expect(res.status).toBe(200);
36
-
37
- const content = await res.text();
38
-
39
- expect(content).toContain("Tags");
40
- expect(content).toContain("Tag 1");
41
- expect(content).toContain("tag-1");
42
- });
43
- });
@@ -1,66 +0,0 @@
1
- import { describe, expect, test } from "@jest/globals";
2
- import app from "src/crud/tags";
3
- import { mockGraphql, assertPrivateRequestCalled } from "../../support/helpers";
4
-
5
- const TAGS_QUERY = `
6
- query Tags($input: TagsInput!) {
7
- tags(input: $input) {
8
- list {
9
- id
10
- name
11
- slug
12
- }
13
- pagination {
14
- currentPage
15
- pagesCount
16
- entriesCount
17
- pageSize
18
- }
19
- }
20
- }
21
- `;
22
-
23
- describe("Tags list endpoint", () => {
24
- test("GET /tags", async () => {
25
- const mockRequest = mockGraphql(
26
- Promise.resolve({
27
- tags: {
28
- list: [
29
- {
30
- id: 1,
31
- name: "Tag 1",
32
- slug: "tag-1",
33
- },
34
- {
35
- id: 2,
36
- name: "Tag 2",
37
- slug: "tag-2",
38
- },
39
- ],
40
- pagination: {
41
- currentPage: 1,
42
- pagesCount: 1,
43
- entriesCount: 2,
44
- pageSize: 25,
45
- },
46
- },
47
- }),
48
- );
49
-
50
- const res = await app.request("/tags");
51
-
52
- assertPrivateRequestCalled(mockRequest, TAGS_QUERY, {
53
- input: { locale: "en" },
54
- });
55
-
56
- expect(res.status).toBe(200);
57
-
58
- const content = await res.text();
59
-
60
- expect(content).toContain("Tags");
61
- expect(content).toContain("Tag 1");
62
- expect(content).toContain("tag-1");
63
- expect(content).toContain("Tag 2");
64
- expect(content).toContain("tag-2");
65
- });
66
- });
@@ -1,16 +0,0 @@
1
- import { describe, expect, test } from "@jest/globals";
2
- import app from "src/crud/tags";
3
-
4
- describe("Tags new endpoint", () => {
5
- test("GET /tags/new", async () => {
6
- const res = await app.request("/tags/new");
7
-
8
- expect(res.status).toBe(200);
9
-
10
- const content = await res.text();
11
-
12
- expect(content).toContain("Tags");
13
- expect(content).toContain("Name");
14
- expect(content).toContain("URL");
15
- });
16
- });
@@ -1,87 +0,0 @@
1
- import { describe, expect, test } from "@jest/globals";
2
- import app from "src/crud/tags";
3
- import {
4
- mockMultipleGraphql,
5
- assertPrivateRequestCalled,
6
- assertEmptyBody,
7
- } from "tests/support/helpers";
8
-
9
- const TAG_QUERY = `
10
- query TagByID($input: IdInput!) {
11
- tag(input: $input) {
12
- id
13
- slug
14
- name
15
- }
16
- }
17
- `;
18
-
19
- const UPDATE_TAG_MUTATION = `
20
- mutation UpdateTag($input: UpdateTagInput!) {
21
- updateTag(input: $input) {
22
- tag {
23
- id
24
- slug
25
- name
26
- }
27
- errors {
28
- key
29
- message
30
- codes {
31
- key
32
- placeholders
33
- }
34
- }
35
- }
36
- }
37
- `;
38
-
39
- describe("Tag update endpoint", () => {
40
- test("POST /tags/:id", async () => {
41
- const tag = {
42
- id: 1,
43
- name: "Tag 1",
44
- slug: "tag-1",
45
- };
46
-
47
- const requestsMock = mockMultipleGraphql([
48
- Promise.resolve({
49
- tag: tag,
50
- }),
51
- Promise.resolve({
52
- updateTag: {
53
- tag: tag,
54
- errors: null,
55
- },
56
- }),
57
- ]);
58
-
59
- const formData = new FormData();
60
- formData.set("name", "Updated name");
61
- formData.set("slug", "updated-slug");
62
-
63
- const res = await app.request("/tags/1", {
64
- method: "POST",
65
- body: formData,
66
- });
67
-
68
- assertPrivateRequestCalled(requestsMock, TAG_QUERY, {
69
- input: { locale: "en", id: 1 },
70
- });
71
-
72
- assertPrivateRequestCalled(requestsMock, UPDATE_TAG_MUTATION, {
73
- input: {
74
- locale: "en",
75
- id: 1,
76
- tag: {
77
- name: "Updated name",
78
- slug: "updated-slug",
79
- },
80
- },
81
- });
82
-
83
- expect(res.status).toBe(301);
84
- expect(res.headers.get("Location")).toBe("/tags");
85
- await assertEmptyBody(res);
86
- });
87
- });
@@ -1,53 +0,0 @@
1
- import { expect } from "@jest/globals";
2
- import * as gqlEngine from "../../src/lib/gqlEngine";
3
-
4
- export function mockGraphql(response: any) {
5
- return jest.spyOn(gqlEngine, "gqlRequest").mockImplementation(() => response);
6
- }
7
-
8
- export function mockMultipleGraphql(responses: any) {
9
- let mock = jest.spyOn(gqlEngine, "gqlRequest");
10
-
11
- responses.forEach((response: any) => {
12
- mock = mock.mockImplementationOnce(() => response);
13
- });
14
-
15
- return mock;
16
- }
17
-
18
- export function assertPrivateRequestCalled(
19
- mockRequest: jest.SpyInstance,
20
- query: string,
21
- input: any,
22
- ) {
23
- expect(mockRequest).toBeCalledWith(
24
- "http://gateway.example.com",
25
- query,
26
- input,
27
- {
28
- "x-raketa-identity": undefined,
29
- "x-raketa-project": "1-raketa-gw-priject",
30
- "x-raketa-service": "dxp-private-service",
31
- },
32
- );
33
- }
34
-
35
- export function assertAuthRequestCalled(
36
- mockRequest: jest.SpyInstance,
37
- query: string,
38
- input: any,
39
- ) {
40
- expect(mockRequest).toBeCalledWith(
41
- "https://gateway.raketa.cloud/auth",
42
- query,
43
- input,
44
- );
45
- }
46
-
47
- export async function assertJSONContent(res: Response, content: any) {
48
- expect(await res.text()).toBe(JSON.stringify(content));
49
- }
50
-
51
- export async function assertEmptyBody(res: Response) {
52
- expect(await res.text()).toBe("");
53
- }
@@ -1,9 +0,0 @@
1
- async function jestSetup() {
2
- process.env.RAKETA_GATEWAY_DISPATCH_URL = "http://gateway.example.com";
3
- process.env.RAKETA_GATEWAY_AUTH_URL = "https://gateway.raketa.cloud/auth";
4
- process.env.RAKETA_GATEWAY_PROJECT = "1-raketa-gw-priject";
5
- process.env.RAKETA_DXP_PRIVATE_SERVICE = "dxp-private-service";
6
- process.env.RAKETA_GATEWAY_PRIMARY_USER_POOL = "primary-user-pool";
7
- }
8
-
9
- module.exports = jestSetup;
@@ -1,30 +0,0 @@
1
- import type { PlopTypes } from "@turbo/gen";
2
-
3
- // Learn more about Turborepo Generators at https://turbo.build/repo/docs/core-concepts/monorepos/code-generation
4
-
5
- export default function generator(plop: PlopTypes.NodePlopAPI): void {
6
- // A simple generator to add a new React component to the internal UI library
7
- plop.setGenerator("react-component", {
8
- description: "Adds a new react component",
9
- prompts: [
10
- {
11
- type: "input",
12
- name: "name",
13
- message: "What is the name of the component?",
14
- },
15
- ],
16
- actions: [
17
- {
18
- type: "add",
19
- path: "{{pascalCase name}}.tsx",
20
- templateFile: "templates/component.hbs",
21
- },
22
- {
23
- type: "append",
24
- path: "index.tsx",
25
- pattern: /(?<insertion>\/\/ component exports)/g,
26
- template: 'export * from "./{{pascalCase name}}";',
27
- },
28
- ],
29
- });
30
- }
@@ -1,14 +0,0 @@
1
- import * as React from "react";
2
-
3
- interface Props {
4
- children?: React.ReactNode;
5
- }
6
-
7
- export const {{ pascalCase name }} = ({ children }: Props) => {
8
- return (
9
- <div>
10
- <h1>{{ name }}</h1>
11
- {children}
12
- </div>
13
- );
14
- };
package/turbo.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "$schema": "https://turbo.build/schema.json",
3
- "extends": ["//"],
4
- "pipeline": {
5
- "build": {
6
- "outputs": ["dist/**"]
7
- }
8
- }
9
- }