openadminjs 0.1.15 → 0.1.17
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/dist/create-project.js +4 -1
- package/dist/index.js +127 -0
- package/package.json +2 -2
- package/template/apps/admin/.storybook/main.ts +12 -0
- package/template/apps/admin/.storybook/preview.ts +10 -0
- package/template/apps/admin/app/dashboard/page.tsx +357 -277
- package/template/apps/admin/app/layout.tsx +5 -1
- package/template/apps/admin/app/login/page.tsx +38 -0
- package/template/apps/admin/app/resources/[resource]/page.tsx +15 -1
- package/template/apps/admin/app/settings/page.tsx +40 -2
- package/template/apps/admin/app/system-logs/page.tsx +212 -0
- package/template/apps/admin/components/api-error-banner.tsx +26 -0
- package/template/apps/admin/components/app-shell.tsx +92 -18
- package/template/apps/admin/components/logo.stories.tsx +24 -0
- package/template/apps/admin/components/resource-form.tsx +47 -0
- package/template/apps/admin/components/resource-table.tsx +417 -44
- package/template/apps/admin/lib/api.ts +44 -1
- package/template/apps/admin/lib/resource-table-prefs.ts +57 -0
- package/template/apps/admin/package.json +6 -0
- package/template/apps/admin/storybook-static/370.e922f076.iframe.bundle.js +9 -0
- package/template/apps/admin/storybook-static/389.c0dd6bde.iframe.bundle.js +818 -0
- package/template/apps/admin/storybook-static/990.36428b6c.iframe.bundle.js +25 -0
- package/template/apps/admin/storybook-static/favicon-wrapper.svg +46 -0
- package/template/apps/admin/storybook-static/favicon.svg +1 -0
- package/template/apps/admin/storybook-static/iframe.html +560 -0
- package/template/apps/admin/storybook-static/index.html +139 -0
- package/template/apps/admin/storybook-static/index.json +1 -0
- package/template/apps/admin/storybook-static/logo-stories.c470fc8c.iframe.bundle.js +1 -0
- package/template/apps/admin/storybook-static/main.743ea6f2.iframe.bundle.js +2550 -0
- package/template/apps/admin/storybook-static/mocker-runtime-injected.js +2 -0
- package/template/apps/admin/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
- package/template/apps/admin/storybook-static/nunito-sans-bold.woff2 +0 -0
- package/template/apps/admin/storybook-static/nunito-sans-italic.woff2 +0 -0
- package/template/apps/admin/storybook-static/nunito-sans-regular.woff2 +0 -0
- package/template/apps/admin/storybook-static/project.json +1 -0
- package/template/apps/admin/storybook-static/runtime~main.6f822e3b.iframe.bundle.js +2 -0
- package/template/apps/admin/storybook-static/sb-addons/onboarding-1/manager-bundle.js +97 -0
- package/template/apps/admin/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +630 -0
- package/template/apps/admin/storybook-static/sb-common-assets/favicon-wrapper.svg +46 -0
- package/template/apps/admin/storybook-static/sb-common-assets/favicon.svg +1 -0
- package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/template/apps/admin/storybook-static/sb-manager/globals-runtime.js +76309 -0
- package/template/apps/admin/storybook-static/sb-manager/globals.js +24 -0
- package/template/apps/admin/storybook-static/sb-manager/manager-stores.js +23 -0
- package/template/apps/admin/storybook-static/sb-manager/runtime.js +26078 -0
- package/template/apps/admin/storybook-static/sb-preview/globals.js +20 -0
- package/template/apps/admin/storybook-static/sb-preview/runtime.js +35472 -0
- package/template/apps/api/package.json +13 -2
- package/template/apps/api/plugins.manifest.example.json +12 -0
- package/template/apps/api/src/admin/admin-logs.controller.ts +31 -0
- package/template/apps/api/src/admin/admin-plugins.controller.ts +5 -0
- package/template/apps/api/src/admin/admin-plugins.service.ts +11 -0
- package/template/apps/api/src/admin/admin-resource.service.ts +235 -1
- package/template/apps/api/src/admin/admin.controller.ts +35 -0
- package/template/apps/api/src/admin/admin.module.ts +6 -3
- package/template/apps/api/src/admin/dto/resource-bulk.dto.ts +17 -0
- package/template/apps/api/src/admin/dto/resource-reorder.dto.ts +17 -0
- package/template/apps/api/src/admin/dto/resource-upload.dto.ts +20 -0
- package/template/apps/api/src/app.module.ts +45 -5
- package/template/apps/api/src/auth/auth.module.ts +5 -3
- package/template/apps/api/src/auth/auth.service.test.ts +6 -3
- package/template/apps/api/src/auth/auth.service.ts +84 -0
- package/template/apps/api/src/auth/sso-oidc.controller.ts +78 -0
- package/template/apps/api/src/auth/sso-oidc.service.test.ts +84 -0
- package/template/apps/api/src/auth/sso-oidc.service.ts +281 -0
- package/template/apps/api/src/common/app-logger.service.ts +138 -0
- package/template/apps/api/src/common/auth.guard.test.ts +1 -0
- package/template/apps/api/src/common/auth.guard.ts +15 -1
- package/template/apps/api/src/common/current-user.decorator.ts +6 -2
- package/template/apps/api/src/common/logging.module.ts +10 -0
- package/template/apps/api/src/common/request-logging.interceptor.ts +70 -0
- package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +44 -0
- package/template/apps/api/src/graphql/admin-resources.resolver.ts +65 -0
- package/template/apps/api/src/graphql/graphql.module.ts +26 -0
- package/template/apps/api/src/main.ts +2 -0
- package/template/apps/api/src/plugins/bundled/registry.ts +3 -1
- package/template/apps/api/src/plugins/bundled/webhook.plugin.ts +64 -0
- package/template/apps/api/src/resources/categories.resource.ts +1 -0
- package/template/apps/api/src/resources/system.resource.ts +1 -0
- package/template/packages/core/src/index.ts +5 -0
- package/template/packages/core/vitest.config.ts +9 -0
- package/template/packages/resource/package.json +11 -0
- package/template/packages/resource/src/index.test.ts +45 -0
- package/template/packages/resource/src/index.ts +63 -0
- package/template/prisma/schema.prisma +5 -0
- package/template/packages/core/src/index.js +0 -1
- package/template/packages/permissions/src/blueprints.js +0 -57
- package/template/packages/permissions/src/index.js +0 -11
- package/template/packages/resource/src/index.js +0 -177
|
@@ -11,6 +11,26 @@ const rawApi = process.env.NEXT_PUBLIC_API_URL;
|
|
|
11
11
|
export const API_URL =
|
|
12
12
|
typeof rawApi === "string" && rawApi.trim().length > 0 ? rawApi.trim() : "http://localhost:4000";
|
|
13
13
|
|
|
14
|
+
export class ApiError extends Error {
|
|
15
|
+
status: number;
|
|
16
|
+
retryAfterSec?: number;
|
|
17
|
+
|
|
18
|
+
constructor(message: string, status: number, retryAfterSec?: number) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "ApiError";
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.retryAfterSec = retryAfterSec;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const API_ERROR_EVENT = "openadmin:api-error";
|
|
27
|
+
|
|
28
|
+
function emitApiError(error: ApiError): void {
|
|
29
|
+
if (typeof window === "undefined") return;
|
|
30
|
+
if (typeof window.dispatchEvent !== "function") return;
|
|
31
|
+
window.dispatchEvent(new CustomEvent<ApiError>(API_ERROR_EVENT, { detail: error }));
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
export type ResourceMeta = {
|
|
15
35
|
name: string;
|
|
16
36
|
label: string;
|
|
@@ -92,12 +112,35 @@ export async function api<T>(path: string, options: RequestInit = {}): Promise<T
|
|
|
92
112
|
const url = `${API_URL}${withAdminLocale(path)}`;
|
|
93
113
|
const response = await requestWithAuthRetry(url, options);
|
|
94
114
|
if (!response.ok) {
|
|
115
|
+
const retryAfterHeader = response.headers?.get?.("retry-after") ?? null;
|
|
116
|
+
const retryAfterSec = retryAfterHeader ? Number(retryAfterHeader) : undefined;
|
|
95
117
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
96
|
-
|
|
118
|
+
if (response.status === 429) {
|
|
119
|
+
const seconds = Number.isFinite(retryAfterSec) ? Math.max(1, Number(retryAfterSec)) : undefined;
|
|
120
|
+
const message = seconds
|
|
121
|
+
? `Too many requests. Try again in ${seconds}s.`
|
|
122
|
+
: "Too many requests. Please try again in a moment.";
|
|
123
|
+
const err = new ApiError(message, 429, seconds);
|
|
124
|
+
emitApiError(err);
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
const err = new ApiError((error as { message?: string }).message ?? "Request failed", response.status);
|
|
128
|
+
emitApiError(err);
|
|
129
|
+
throw err;
|
|
97
130
|
}
|
|
98
131
|
return response.json() as Promise<T>;
|
|
99
132
|
}
|
|
100
133
|
|
|
134
|
+
export function onApiError(listener: (error: ApiError) => void): () => void {
|
|
135
|
+
if (typeof window === "undefined") return () => {};
|
|
136
|
+
const handler = (event: Event) => {
|
|
137
|
+
const custom = event as CustomEvent<ApiError>;
|
|
138
|
+
if (custom.detail) listener(custom.detail);
|
|
139
|
+
};
|
|
140
|
+
window.addEventListener(API_ERROR_EVENT, handler as EventListener);
|
|
141
|
+
return () => window.removeEventListener(API_ERROR_EVENT, handler as EventListener);
|
|
142
|
+
}
|
|
143
|
+
|
|
101
144
|
async function requestWithAuthRetry(url: string, options: RequestInit): Promise<Response> {
|
|
102
145
|
const method = (options.method ?? "GET").toUpperCase();
|
|
103
146
|
const body =
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const PREFIX = "openadminjs.resourceTable.";
|
|
2
|
+
|
|
3
|
+
function keyColumnOrder(resourceName: string): string {
|
|
4
|
+
return `${PREFIX}${resourceName}.columnOrder`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function keyDensity(resourceName: string): string {
|
|
8
|
+
return `${PREFIX}${resourceName}.density`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type TableDensity = "comfortable" | "compact";
|
|
12
|
+
|
|
13
|
+
export function loadColumnOrder(resourceName: string, allowed: string[]): string[] {
|
|
14
|
+
if (typeof window === "undefined") return allowed;
|
|
15
|
+
try {
|
|
16
|
+
const raw = window.localStorage.getItem(keyColumnOrder(resourceName));
|
|
17
|
+
if (!raw) return allowed;
|
|
18
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
19
|
+
if (!Array.isArray(parsed)) return allowed;
|
|
20
|
+
const set = new Set(allowed);
|
|
21
|
+
const ordered = parsed.map(String).filter((n) => set.has(n));
|
|
22
|
+
for (const n of allowed) {
|
|
23
|
+
if (!ordered.includes(n)) ordered.push(n);
|
|
24
|
+
}
|
|
25
|
+
return ordered;
|
|
26
|
+
} catch {
|
|
27
|
+
return allowed;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function saveColumnOrder(resourceName: string, order: string[]): void {
|
|
32
|
+
if (typeof window === "undefined") return;
|
|
33
|
+
try {
|
|
34
|
+
window.localStorage.setItem(keyColumnOrder(resourceName), JSON.stringify(order));
|
|
35
|
+
} catch {
|
|
36
|
+
/* ignore */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function loadDensity(resourceName: string): TableDensity {
|
|
41
|
+
if (typeof window === "undefined") return "comfortable";
|
|
42
|
+
try {
|
|
43
|
+
const v = window.localStorage.getItem(keyDensity(resourceName));
|
|
44
|
+
return v === "compact" ? "compact" : "comfortable";
|
|
45
|
+
} catch {
|
|
46
|
+
return "comfortable";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function saveDensity(resourceName: string, density: TableDensity): void {
|
|
51
|
+
if (typeof window === "undefined") return;
|
|
52
|
+
try {
|
|
53
|
+
window.localStorage.setItem(keyDensity(resourceName), density);
|
|
54
|
+
} catch {
|
|
55
|
+
/* ignore */
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "next dev --port 3000",
|
|
8
|
+
"storybook": "storybook dev -p 6006",
|
|
9
|
+
"build-storybook": "storybook build",
|
|
8
10
|
"build": "next build",
|
|
9
11
|
"start": "next start --port 3000",
|
|
10
12
|
"lint": "tsc -p tsconfig.json --noEmit",
|
|
@@ -29,6 +31,9 @@
|
|
|
29
31
|
"zod": "^3.24.1"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
34
|
+
"@storybook/addon-docs": "^10.3.6",
|
|
35
|
+
"@storybook/addon-onboarding": "^10.3.6",
|
|
36
|
+
"@storybook/nextjs": "^10.3.6",
|
|
32
37
|
"@testing-library/jest-dom": "^6.9.1",
|
|
33
38
|
"@testing-library/react": "^16.3.2",
|
|
34
39
|
"@types/node": "^22.10.2",
|
|
@@ -37,6 +42,7 @@
|
|
|
37
42
|
"autoprefixer": "^10.4.20",
|
|
38
43
|
"jsdom": "^29.1.1",
|
|
39
44
|
"postcss": "^8.4.49",
|
|
45
|
+
"storybook": "^10.3.6",
|
|
40
46
|
"tailwindcss": "^3.4.17",
|
|
41
47
|
"typescript": "^5.7.2",
|
|
42
48
|
"vitest": "^2.1.8"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";(self.webpackChunk_openadminjs_admin=self.webpackChunk_openadminjs_admin||[]).push([[370],{"../../node_modules/.pnpm/next@15.5.15_@babel+core@7.29.0_react-dom@19.2.5_react@19.2.5__react@19.2.5/node_modules/next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js":((a,o,e)=>{var n=e("../../node_modules/.pnpm/console-browserify@1.2.0/node_modules/console-browserify/index.js");/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-dom-test-utils.production.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var s=e("../../node_modules/.pnpm/next@15.5.15_@babel+core@7.29.0_react-dom@19.2.5_react@19.2.5__react@19.2.5/node_modules/next/dist/compiled/react/index.js"),t=!1;o.act=function(d){return t===!1&&(t=!0,n.error("`ReactDOMTestUtils.act` is deprecated in favor of `React.act`. Import `act` from `react` instead of `react-dom/test-utils`. See https://react.dev/warnings/react-dom-test-utils for more info.")),s.act(d)}})}]);
|