@ampless/admin 0.2.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +78 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.js +41 -0
- package/dist/chunk-BN6BW7MP.js +2074 -0
- package/dist/chunk-TJR3ALRJ.js +575 -0
- package/dist/components/index.d.ts +169 -0
- package/dist/components/index.js +44 -0
- package/dist/i18n-ByHM_Bho.d.ts +738 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +115 -0
- package/dist/pages/index.d.ts +90 -0
- package/dist/pages/index.js +839 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ampless contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @ampless/admin
|
|
2
|
+
|
|
3
|
+
Admin UI library for [ampless](https://github.com/heavymoons/ampless): post
|
|
4
|
+
editor (Tiptap + Markdown + HTML), media manager (S3 + image processing),
|
|
5
|
+
site/theme settings, locale-aware UI strings, and the Next.js page
|
|
6
|
+
factories that wire it all together.
|
|
7
|
+
|
|
8
|
+
> **Pre-release / alpha.** Breaking changes possible in any minor version until v1.0.
|
|
9
|
+
|
|
10
|
+
## Why a library?
|
|
11
|
+
|
|
12
|
+
The admin UI used to live in the template project. Every bug fix and
|
|
13
|
+
feature meant copy-pasting files between the template and downstream
|
|
14
|
+
sites. Extracting to `@ampless/admin` lets a project run
|
|
15
|
+
`npm update @ampless/admin` to pick up improvements — the same upgrade
|
|
16
|
+
flow as any other dependency.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @ampless/admin@alpha @ampless/runtime@alpha ampless@alpha
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Peer-installs: `next`, `react`, `react-dom`, `aws-amplify`,
|
|
25
|
+
`@aws-amplify/adapter-nextjs`.
|
|
26
|
+
|
|
27
|
+
## Wire-up
|
|
28
|
+
|
|
29
|
+
Create `lib/admin.ts` in your Next.js project:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import outputs from '../amplify_outputs.json'
|
|
33
|
+
import cmsConfig from '../cms.config'
|
|
34
|
+
import { createAdmin } from '@ampless/admin'
|
|
35
|
+
import { ampless } from './ampless'
|
|
36
|
+
|
|
37
|
+
export const admin = createAdmin({ outputs, cmsConfig, ampless })
|
|
38
|
+
export const t = admin.t
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then expose each admin route as a thin shell:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// app/(admin)/admin/posts/page.tsx
|
|
45
|
+
import { admin } from '@/lib/admin'
|
|
46
|
+
import { createPostsListPage } from '@ampless/admin/pages'
|
|
47
|
+
export default createPostsListPage(admin)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// app/api/media/[...path]/route.ts
|
|
52
|
+
import { admin } from '@/lib/admin'
|
|
53
|
+
import { createMediaProxyRoute } from '@ampless/admin/api'
|
|
54
|
+
export const { GET } = createMediaProxyRoute(admin)
|
|
55
|
+
export const runtime = 'nodejs'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Sub-paths
|
|
59
|
+
|
|
60
|
+
| Subpath | Contains |
|
|
61
|
+
| ----------------------------- | --------------------------------------------------- |
|
|
62
|
+
| `@ampless/admin` | `createAdmin` factory + `Admin` interface |
|
|
63
|
+
| `@ampless/admin/pages` | Page factories — one per admin route |
|
|
64
|
+
| `@ampless/admin/api` | API route factories (`createMediaProxyRoute`, ...) |
|
|
65
|
+
| `@ampless/admin/components` | Form / editor components for advanced wiring |
|
|
66
|
+
|
|
67
|
+
## Locale
|
|
68
|
+
|
|
69
|
+
`createAdmin({ locale: 'ja' })` switches admin UI strings to Japanese.
|
|
70
|
+
Pass an object literal to override individual strings:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
createAdmin({
|
|
74
|
+
outputs,
|
|
75
|
+
cmsConfig,
|
|
76
|
+
locale: { sidebar: { brand: 'MySite Admin' } },
|
|
77
|
+
})
|
|
78
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Admin } from '../index.js';
|
|
3
|
+
import 'ampless';
|
|
4
|
+
import '@ampless/runtime';
|
|
5
|
+
import '../i18n-ByHM_Bho.js';
|
|
6
|
+
import '@aws-amplify/adapter-nextjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Build the `/api/media/[...path]` route handler. Proxies uploaded
|
|
10
|
+
* media through Next.js so embedded `<img src>` URLs stay permanent.
|
|
11
|
+
* The browser hits `/api/media/<path>`, this route fetches the
|
|
12
|
+
* short-lived presigned URL via Amplify SSR, then redirects.
|
|
13
|
+
*
|
|
14
|
+
* Used when `cms.config.media.delivery !== 's3-direct'` (default).
|
|
15
|
+
*/
|
|
16
|
+
declare function createMediaProxyRoute(admin: Admin): {
|
|
17
|
+
GET: (_req: NextRequest, ctx: {
|
|
18
|
+
params: Promise<{
|
|
19
|
+
path: string[];
|
|
20
|
+
}>;
|
|
21
|
+
}) => Promise<NextResponse<unknown>>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { createMediaProxyRoute };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/api/media-proxy.ts
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
|
+
import { cookies } from "next/headers";
|
|
4
|
+
import { getUrl } from "aws-amplify/storage/server";
|
|
5
|
+
function createMediaProxyRoute(admin) {
|
|
6
|
+
const { runWithAmplifyServerContext } = admin.amplifyServer;
|
|
7
|
+
async function GET(_req, ctx) {
|
|
8
|
+
const { path } = await ctx.params;
|
|
9
|
+
if (!path.length || path.some(
|
|
10
|
+
(segment) => !segment || segment === "." || segment === ".." || segment.includes("/") || segment.includes("\\") || segment.includes("\0")
|
|
11
|
+
)) {
|
|
12
|
+
return NextResponse.json({ error: "Invalid path" }, { status: 400 });
|
|
13
|
+
}
|
|
14
|
+
const objectPath = `public/${path.join("/")}`;
|
|
15
|
+
try {
|
|
16
|
+
const url = await runWithAmplifyServerContext({
|
|
17
|
+
nextServerContext: { cookies },
|
|
18
|
+
operation: async (amplifyContext) => {
|
|
19
|
+
const result = await getUrl(amplifyContext, {
|
|
20
|
+
path: objectPath,
|
|
21
|
+
options: { expiresIn: 60 * 60 }
|
|
22
|
+
});
|
|
23
|
+
return result.url.toString();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return NextResponse.redirect(url, {
|
|
27
|
+
status: 302,
|
|
28
|
+
headers: { "Cache-Control": "public, max-age=300" }
|
|
29
|
+
});
|
|
30
|
+
} catch (err) {
|
|
31
|
+
return NextResponse.json(
|
|
32
|
+
{ error: err instanceof Error ? err.message : "Failed to fetch media" },
|
|
33
|
+
{ status: 404 }
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { GET };
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
createMediaProxyRoute
|
|
41
|
+
};
|