Skip to content

Commit 89243ea

Browse files
Merge pull request #165 from PretendoNetwork/dev
Merge Dev to Master
2 parents 8c259c9 + bc406ec commit 89243ea

File tree

171 files changed

+58086
-9729
lines changed

Some content is hidden

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

171 files changed

+58086
-9729
lines changed

.dockerignore

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
.git
2-
config.json
3-
logs
4-
certs
5-
cdn
6-
node_modules
1+
.git
2+
.env
3+
node_modules
4+
dist
5+
logs

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
*.js

.eslintrc.json

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
"commonjs": true,
55
"es6": true
66
},
7-
"parserOptions": {
8-
"ecmaVersion": 2020
9-
},
7+
"parser": "@typescript-eslint/parser",
108
"globals": {
119
"BigInt": true
1210
},
13-
"extends": "eslint:recommended",
11+
"extends": [
12+
"eslint:recommended",
13+
"plugin:@typescript-eslint/recommended"
14+
],
15+
"plugins": [
16+
"@typescript-eslint"
17+
],
1418
"rules": {
1519
"require-atomic-updates": "warn",
1620
"no-case-declarations": "off",
@@ -20,6 +24,13 @@
2024
"no-global-assign": "off",
2125
"prefer-const": "error",
2226
"no-var": "error",
27+
"no-unused-vars": "off",
28+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
29+
"no-extra-semi": "off",
30+
"@typescript-eslint/no-extra-semi": "error",
31+
"@typescript-eslint/no-empty-interface": "warn",
32+
"@typescript-eslint/no-inferrable-types": "error",
33+
"@typescript-eslint/explicit-function-return-type": "error",
2334
"one-var": [
2435
"error",
2536
"never"

.github/workflows/docker.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build-publish:
14+
env:
15+
SHOULD_PUSH_IMAGE: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev')) || github.event_name == 'workflow_dispatch' }}
16+
runs-on: ubuntu-latest
17+
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
steps:
23+
- name: Set up QEMU for Docker
24+
uses: docker/setup-qemu-action@v3
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Log into the container registry
30+
if: ${{ env.SHOULD_PUSH_IMAGE == 'true' }}
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Extract Docker metadata
38+
id: meta
39+
uses: docker/metadata-action@v5
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
tags: |
43+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
44+
type=raw,value=edge,enable=${{ github.ref == 'refs/heads/dev' }}
45+
type=sha
46+
47+
- name: Build and push Docker image
48+
id: build-and-push
49+
uses: docker/build-push-action@v6
50+
with:
51+
platforms: linux/amd64,linux/arm64
52+
push: ${{ env.SHOULD_PUSH_IMAGE }}
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
cache-from: type=gha
56+
cache-to: type=gha,mode=max

.gitignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ typings/
5858
.env
5959

6060
# custom
61-
sign.js
62-
t.js
63-
p.js
6461
config.json
6562
certs
66-
/cdn
67-
dump.rdb
63+
cdn
64+
dist

Dockerfile

+47-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1-
FROM node:18-alpine
2-
3-
RUN apk add --no-cache python3 make gcc g++
4-
WORKDIR /app
5-
6-
COPY "docker/entrypoint.sh" ./
7-
8-
COPY package*.json ./
9-
RUN npm install bcrypt && npm rebuild bcrypt --build-from-source
10-
RUN npm install
11-
12-
COPY . ./
13-
14-
VOLUME [ "/app/config.json", "/app/certs" ]
15-
16-
CMD ["sh", "entrypoint.sh"]
1+
# syntax=docker/dockerfile:1
2+
3+
ARG app_dir="/home/node/app"
4+
5+
6+
# * Base Node.js image
7+
FROM node:20-alpine AS base
8+
ARG app_dir
9+
WORKDIR ${app_dir}
10+
11+
12+
# * Installing production dependencies
13+
FROM base AS dependencies
14+
15+
RUN --mount=type=bind,source=package.json,target=package.json \
16+
--mount=type=bind,source=package-lock.json,target=package-lock.json \
17+
--mount=type=cache,target=/root/.npm \
18+
npm ci --omit=dev
19+
20+
21+
# * Installing development dependencies and building the application
22+
FROM base AS build
23+
24+
RUN --mount=type=bind,source=package.json,target=package.json \
25+
--mount=type=bind,source=package-lock.json,target=package-lock.json \
26+
--mount=type=cache,target=/root/.npm \
27+
npm ci
28+
29+
COPY . .
30+
RUN npm run build
31+
32+
33+
# * Running the final application
34+
FROM base AS final
35+
ARG app_dir
36+
37+
RUN mkdir -p ${app_dir}/logs && chown node:node ${app_dir}/logs
38+
39+
ENV NODE_ENV=production
40+
USER node
41+
42+
COPY package.json .
43+
44+
COPY --from=dependencies ${app_dir}/node_modules ${app_dir}/node_modules
45+
COPY --from=build ${app_dir}/dist ${app_dir}/dist
46+
47+
CMD ["node", "."]

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Account server
22

3-
## What is this?
4-
The account server is a replacement for several account-based services used by the WiiU and 3DS. It replaces the NNID api as well as NASC for the 3DS. It also contains a dedicated PNID api service for getting details of PNIDs outside of the consoles
3+
Replacement for several account-based services used by the WiiU and 3DS. It replaces the NNID api as well as NASC for the 3DS. It also contains a dedicated PNID api service for getting details of PNIDs outside of the consoles (used by the website)
54

65
## Setup
7-
TODO
6+
See [SETUP.md](SETUP.md) for how to self host

SETUP.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Setup
2+
3+
- [Required software](#required-software)
4+
- [NodeJS](#nodejs)
5+
- [MongoDB](#mongodb)
6+
- [Optional features](#optional-features)
7+
- [Redis (optional)](#redis-optional)
8+
- [Email (optional)](#email-optional)
9+
- [Amazon s3 server (optional)](#amazon-s3-server-optional)
10+
- [hCaptcha (optional)](#hcaptcha-optional)
11+
- [Configuration](#configuration)
12+
13+
14+
## Required software
15+
16+
- [NodeJS](https://nodejs.org/)
17+
- [MongoDB](https://www.mongodb.com)
18+
19+
### NodeJS
20+
21+
Download and install the latest LTS version of [NodeJS](https://nodejs.org/). If using a Linux based operating system, using [nvm](https://github.com/nvm-sh/nvm) is the recommended method. _Tested on NodeJS version v18.20.5_
22+
23+
### MongoDB
24+
25+
Download and install the latest version of [MongoDB](https://www.mongodb.com)
26+
27+
The server assumes that MongoDB is running as a replica set, here's how to configure a basic replica set:
28+
1. Open /etc/mongod.conf with your preferred editor.
29+
30+
2. Add/modify the `replication` section with the following:
31+
```conf
32+
replication:
33+
replSetName: "rs0"
34+
```
35+
36+
3. Restart MongoDB and open a shell with `mongosh`.
37+
38+
4. Initiate the replica set with `rs.initiate()` and check its status with `rs.status()`.
39+
40+
## Optional features
41+
42+
- [Redis](https://redis.io/) file caching
43+
- Email address for sending automatic emails (tested with gmail)
44+
- Amazon s3, or compatible, server for CDN methods
45+
- [hCaptcha](https://hcaptcha.com/) for website API captcha verification
46+
47+
### Redis (optional)
48+
49+
Redis can be used to cache files read from disk. If Redis is not configured, then an in-memory object store is used instead.
50+
51+
### Email (optional)
52+
53+
Events such as account creation, email verification, etc, support sending emails to users. To enable email sending, you will need to use Amazon SES. Consult the Amazon SES documentation for more details.
54+
55+
### Amazon s3 server (optional)
56+
57+
Certain endpoints expect URLs for static CDN assets, such as pre-rendered Mii images. An [Amazon s3](https://aws.amazon.com/s3/) or compatible server, such as [Spaces by DigitalOcean](https://www.digitalocean.com/products/spaces), [Cloudflare R2](https://www.cloudflare.com/products/r2/), or [Backblaze B2](https://www.backblaze.com/b2/docs/), can optionally be used to store and upload these assets. If an s3 server is not configured, CDN contents will be stored on disk and served from this server. See [Configuration](#configuration) for more details.
58+
59+
### hCaptcha (optional)
60+
61+
The Pretendo Network website uses this server as an API for querying user information. Certain endpoints are considered more secure than others, such as registration, and can optionally be protected using [hCaptcha](https://hcaptcha.com/). If hCaptcha is not configured, no endpoints on the public facing API will be protected.
62+
63+
## Configuration
64+
65+
Configurations are loaded through environment variables. `.env` files are supported. All configuration options will be gone over, both required and optional. There also exists an example `.env` file
66+
67+
| Name | Description | Optional |
68+
|-----------------------------------------------|--------------------------------------------------------------------------------------------------|----------|
69+
| `PN_ACT_CONFIG_HTTP_PORT` | The HTTP port the server listens on | No |
70+
| `PN_ACT_CONFIG_MONGO_CONNECTION_STRING` | MongoDB connection string | No |
71+
| `PN_ACT_CONFIG_MONGOOSE_CONNECT_OPTIONS_PATH` | Path to a `.json` file containing Mongoose connection options | Yes |
72+
| `PN_ACT_CONFIG_REDIS_URL` | Redis URL | Yes |
73+
| `PN_ACT_CONFIG_EMAIL_SES_REGION` | Amazon SES Region | Yes |
74+
| `PN_ACT_CONFIG_EMAIL_SES_ACCESS_KEY` | Amazon SES Access Key | Yes |
75+
| `PN_ACT_CONFIG_EMAIL_SES_SECRET_KEY` | Amazon SES Access Secret | Yes |
76+
| `PN_ACT_CONFIG_EMAIL_FROM` | Email "from" address | Yes |
77+
| `PN_ACT_CONFIG_S3_ENDPOINT` | s3 server endpoint | Yes |
78+
| `PN_ACT_CONFIG_S3_ACCESS_KEY` | s3 secret key | Yes |
79+
| `PN_ACT_CONFIG_S3_ACCESS_SECRET` | s3 secret | Yes |
80+
| `PN_ACT_CONFIG_HCAPTCHA_SECRET` | hCaptcha secret (in the form `0x...`) | Yes |
81+
| `PN_ACT_CONFIG_CDN_SUBDOMAIN` | Subdomain used to serve CDN contents if s3 is disabled | Yes |
82+
| `PN_ACT_CONFIG_CDN_DISK_PATH` | File system path used to store CDN contents if s3 is disabled | Yes |
83+
| `PN_ACT_CONFIG_CDN_BASE_URL` | URL for serving CDN contents (usually the same as s3 endpoint) | No |
84+
| `PN_ACT_CONFIG_WEBSITE_BASE` | Website URL | Yes |
85+
| `PN_ACT_CONFIG_AES_KEY` | AES-256 key used for encrypting tokens | No |
86+
| `PN_ACT_CONFIG_DATASTORE_SIGNATURE_SECRET` | HMAC secret key (16 bytes in hex format) used to sign uploaded DataStore files | No |
87+
| `PN_ACT_CONFIG_GRPC_MASTER_API_KEY_ACCOUNT` | Master API key to interact with the account gRPC service | No |
88+
| `PN_ACT_CONFIG_GRPC_MASTER_API_KEY_API` | Master API key to interact with the API gRPC service | No |
89+
| `PN_ACT_CONFIG_GRPC_PORT` | gRPC server port | No |
90+
| `PN_ACT_CONFIG_STRIPE_SECRET_KEY` | Stripe API key. Used to cancel subscriptions when scrubbing PNIDs | Yes |
91+
| `PN_ACT_CONFIG_SERVER_ENVIRONMENT` | Server environment. Currently only used by the Wii U Account Settings app. `prod`/`test`/`dev` | Yes |

create-test-user.js

-79
This file was deleted.

0 commit comments

Comments
 (0)