Skip to content

Commit 9385c85

Browse files
authored
Merge pull request #151 from codelitdev/gh-pages
Documentation site; Remove internal API keys concept
2 parents 5598d46 + aa277fc commit 9385c85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2875
-372
lines changed

.github/workflows/nextjs.yml renamed to .github/workflows/deploy-docs-to-pages.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,51 @@ jobs:
3434
- name: Detect package manager
3535
id: detect-package-manager
3636
run: |
37-
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
38-
echo "manager=yarn" >> $GITHUB_OUTPUT
39-
echo "command=install" >> $GITHUB_OUTPUT
40-
echo "runner=yarn" >> $GITHUB_OUTPUT
41-
exit 0
42-
elif [ -f "${{ github.workspace }}/package.json" ]; then
43-
echo "manager=npm" >> $GITHUB_OUTPUT
44-
echo "command=ci" >> $GITHUB_OUTPUT
45-
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46-
exit 0
47-
else
48-
echo "Unable to determine package manager"
49-
exit 1
50-
fi
37+
echo "manager=npm" >> $GITHUB_OUTPUT
38+
echo "command=ci" >> $GITHUB_OUTPUT
39+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
5140
- name: Setup Node
5241
uses: actions/setup-node@v4
5342
with:
5443
node-version: "20"
55-
cache: ${{ steps.detect-package-manager.outputs.manager }}
44+
- name: Setup pnpm
45+
uses: pnpm/action-setup@v2
46+
with:
47+
version: 8
5648
- name: Setup Pages
49+
id: pages
5750
uses: actions/configure-pages@v5
58-
with:
59-
# Automatically inject basePath in your Next.js configuration file and disable
60-
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
61-
#
62-
# You may remove this line if you want to manage the configuration yourself.
63-
static_site_generator: next
51+
# with:
52+
# # Automatically inject basePath in your Next.js configuration file and disable
53+
# # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
54+
# #
55+
# # You may remove this line if you want to manage the configuration yourself.
56+
# static_site_generator: next
57+
# generator_config_file: apps/docs/next.config.js
58+
- name: Dump Pages configuration
59+
run: |
60+
echo PAGES_BASE_URL: ${{ steps.pages.outputs.base_url }}
61+
echo PAGES_ORIGIN: ${{ steps.pages.outputs.origin }}
62+
echo PAGES_HOST: ${{ steps.pages.outputs.host }}
63+
echo PAGES_BASE_PATH: ${{ steps.pages.outputs.base_path }}
6464
- name: Restore cache
6565
uses: actions/cache@v4
6666
with:
6767
path: |
68-
.next/cache
68+
apps/docs/.next/cache
6969
# Generate a new cache whenever packages or source files change.
7070
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
7171
# If source files changed but packages didn't, rebuild from a prior cache.
7272
restore-keys: |
7373
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
7474
- name: Install dependencies
75-
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
75+
run: pnpm i
7676
- name: Build with Next.js
77-
run: ${{ steps.detect-package-manager.outputs.runner }} next build
77+
run: pnpm --filter @medialit/docs build
7878
- name: Upload artifact
7979
uses: actions/upload-pages-artifact@v3
8080
with:
81-
path: ./out
81+
path: ./apps/docs/out
8282

8383
# Deployment job
8484
deploy:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.apikeys.deleteMany({ name: "internal-apikey", internal: true });
2+
db.apikeys.updateMany({}, { $unset: { internal: "" } });

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
dist
3-
**/.next
3+
**/.next
4+
apps/docs/.source

apps/api/src/apikey/middleware.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ export default async function apikey(
2323
return res.status(401).json({ error: UNAUTHORISED });
2424
}
2525

26-
if (req.body.internalKey) {
27-
const internalApikey: Apikey | null = await getApiKeyUsingKeyId(
28-
req.body.internalKey,
29-
);
30-
if (!internalApikey) {
31-
return res.status(401).json({ error: UNAUTHORISED });
32-
}
33-
}
34-
3526
// const isSubscriptionValid = await validateSubscription(
3627
// apiKey!.userId.toString(),
3728
// );

apps/api/src/apikey/queries.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import { getUniqueId } from "@medialit/utils";
55
export async function createApiKey(
66
userId: string,
77
name: string,
8-
internal?: boolean,
98
): Promise<Apikey> {
109
return await ApikeyModel.create({
1110
name,
1211
key: getUniqueId(),
1312
userId,
14-
internal: internal || false,
1513
});
1614
}
1715

@@ -38,15 +36,11 @@ export async function getApiKeyByUserId(
3836
{
3937
key: keyId,
4038
userId,
41-
internal: false,
4239
},
4340
projections,
4441
);
4542
} else {
46-
result = await ApikeyModel.find(
47-
{ userId, internal: false },
48-
projections,
49-
);
43+
result = await ApikeyModel.find({ userId }, projections);
5044
}
5145

5246
return result;

apps/api/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,11 @@ async function createAdminUser() {
7878
const user: User | null = await findByEmail(email);
7979

8080
if (!user) {
81-
const user = await createUser(
82-
email,
83-
undefined,
84-
// new Date(
85-
// new Date().setFullYear(new Date().getFullYear() + 100),
86-
// ),
87-
"subscribed",
88-
);
81+
const user = await createUser(email, undefined, "subscribed");
8982
const apikey: Apikey = await createApiKey(user.id, "App 1");
9083
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
9184
console.log(`@ API key: ${apikey.key} @`);
9285
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
93-
await createApiKey(user.id, Constants.internalApikeyName, true);
9486
}
9587
} catch (error) {
9688
logger.error({ error }, "Failed to create admin user");

apps/docs/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# deps
2+
/node_modules
3+
4+
# generated content
5+
.contentlayer
6+
.content-collections
7+
.source
8+
9+
# test & build
10+
/coverage
11+
/.next/
12+
/out/
13+
/build
14+
*.tsbuildinfo
15+
16+
# misc
17+
.DS_Store
18+
*.pem
19+
/.pnp
20+
.pnp.js
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# others
26+
.env*.local
27+
.vercel
28+
next-env.d.ts

apps/docs/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# docs
2+
3+
This is a Next.js application generated with
4+
[Create Fumadocs](https://github.com/fuma-nama/fumadocs).
5+
6+
Run development server:
7+
8+
```bash
9+
npm run dev
10+
# or
11+
pnpm dev
12+
# or
13+
yarn dev
14+
```
15+
16+
Open http://localhost:3000 with your browser to see the result.
17+
18+
## Learn More
19+
20+
To learn more about Next.js and Fumadocs, take a look at the following
21+
resources:
22+
23+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js
24+
features and API.
25+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
26+
- [Fumadocs](https://fumadocs.vercel.app) - learn about Fumadocs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { ReactNode } from "react";
2+
import { HomeLayout } from "fumadocs-ui/layouts/home";
3+
import { baseOptions } from "@/app/layout.config";
4+
5+
export default function Layout({ children }: { children: ReactNode }) {
6+
return <HomeLayout {...baseOptions}>{children}</HomeLayout>;
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Link from "next/link";
2+
3+
export default function HomePage() {
4+
return (
5+
<main className="flex flex-1 flex-col justify-center text-center">
6+
<h1 className="mb-4 text-2xl font-bold">Hello World</h1>
7+
<p className="text-fd-muted-foreground">
8+
You can open{" "}
9+
<Link
10+
href="/docs"
11+
className="text-fd-foreground font-semibold underline"
12+
>
13+
/docs
14+
</Link>{" "}
15+
and see the documentation.
16+
</p>
17+
</main>
18+
);
19+
}

0 commit comments

Comments
 (0)