@o3co/create-auth-policy-verifier 0.3.1
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 +201 -0
- package/README.ja.md +94 -0
- package/README.md +94 -0
- package/dist/__tests__/index.test.d.mts +2 -0
- package/dist/__tests__/index.test.d.mts.map +1 -0
- package/dist/__tests__/index.test.mjs +213 -0
- package/dist/cli.d.mts +3 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +5 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +169 -0
- package/package.json +31 -0
- package/templates/standalone/.dockerignore +9 -0
- package/templates/standalone/Dockerfile +55 -0
- package/templates/standalone/LICENSE +201 -0
- package/templates/standalone/Makefile +12 -0
- package/templates/standalone/README.ja.md +84 -0
- package/templates/standalone/README.md +84 -0
- package/templates/standalone/config/application.conf +35 -0
- package/templates/standalone/docker-compose.test.yml +5 -0
- package/templates/standalone/docker-compose.yml +13 -0
- package/templates/standalone/package.json +34 -0
- package/templates/standalone/src/__tests__/smoke.test.mts +103 -0
- package/templates/standalone/src/main.mts +35 -0
- package/templates/standalone/tsconfig.json +27 -0
- package/templates/standalone/vitest.config.mts +10 -0
- package/templates/versions.json +5 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 1o1 Co. Ltd.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { cpSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, resolve, sep } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const TEMPLATES_DIR = resolve(__dirname, "../templates/standalone");
|
|
8
|
+
/**
|
|
9
|
+
* Reads the embedded `versions.json` produced by the prebuild script. Returns
|
|
10
|
+
* an empty map if the file is absent (e.g. running from source without
|
|
11
|
+
* prebuild), so callers must treat "not found" as a separate branch.
|
|
12
|
+
*/
|
|
13
|
+
const getPackageVersions = () => {
|
|
14
|
+
const versionFile = resolve(__dirname, "../templates/versions.json");
|
|
15
|
+
if (existsSync(versionFile)) {
|
|
16
|
+
return JSON.parse(readFileSync(versionFile, "utf-8"));
|
|
17
|
+
}
|
|
18
|
+
return {};
|
|
19
|
+
};
|
|
20
|
+
const UNSCOPED_NAME_RE = /^[a-z0-9][a-z0-9-._~]*$/;
|
|
21
|
+
const SCOPED_NAME_RE = /^@[a-z0-9][a-z0-9-._~]*\/[a-z0-9][a-z0-9-._~]*$/;
|
|
22
|
+
const MAX_NAME_LEN = 214;
|
|
23
|
+
export const isValidProjectName = (name) => {
|
|
24
|
+
if (name.length === 0 || name.length > MAX_NAME_LEN)
|
|
25
|
+
return false;
|
|
26
|
+
if (name === "." || name === "..")
|
|
27
|
+
return false;
|
|
28
|
+
return UNSCOPED_NAME_RE.test(name) || SCOPED_NAME_RE.test(name);
|
|
29
|
+
};
|
|
30
|
+
export const isValidDirName = (name) => {
|
|
31
|
+
if (name.length === 0 || name.length > MAX_NAME_LEN)
|
|
32
|
+
return false;
|
|
33
|
+
if (name === "." || name === "..")
|
|
34
|
+
return false;
|
|
35
|
+
return UNSCOPED_NAME_RE.test(name);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Copies the bundled standalone template into `targetDir`, rewrites
|
|
39
|
+
* `package.json` with the new `projectName`, and replaces every `workspace:*`
|
|
40
|
+
* dependency with the concrete published version from `versions.json`.
|
|
41
|
+
*
|
|
42
|
+
* Throws if the template directory is missing (unprebuilt) or if any
|
|
43
|
+
* workspace dependency is not pinned in `versions.json`.
|
|
44
|
+
*/
|
|
45
|
+
export const scaffold = (targetDir, projectName) => {
|
|
46
|
+
if (!existsSync(TEMPLATES_DIR)) {
|
|
47
|
+
throw new Error(`Template directory not found at ${TEMPLATES_DIR}. If developing locally, run the prebuild script first.`);
|
|
48
|
+
}
|
|
49
|
+
// Copy template to target
|
|
50
|
+
const EXCLUDED_DIRS = new Set(["node_modules", "dist"]);
|
|
51
|
+
cpSync(TEMPLATES_DIR, targetDir, {
|
|
52
|
+
recursive: true,
|
|
53
|
+
filter: (source) => {
|
|
54
|
+
const segments = source.split(sep);
|
|
55
|
+
return !segments.some((s) => EXCLUDED_DIRS.has(s));
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
// Rewrite package.json
|
|
59
|
+
const pkgPath = resolve(targetDir, "package.json");
|
|
60
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
61
|
+
pkg.name = projectName;
|
|
62
|
+
delete pkg.private;
|
|
63
|
+
// Replace all workspace:* references with per-package published versions
|
|
64
|
+
const versions = getPackageVersions();
|
|
65
|
+
for (const section of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
66
|
+
const deps = pkg[section];
|
|
67
|
+
if (!deps)
|
|
68
|
+
continue;
|
|
69
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
70
|
+
if (version === "workspace:*") {
|
|
71
|
+
const resolved = versions[name];
|
|
72
|
+
if (!resolved) {
|
|
73
|
+
throw new Error(`Cannot resolve version for workspace dependency "${name}". Ensure versions.json includes this package.`);
|
|
74
|
+
}
|
|
75
|
+
deps[name] = `^${resolved}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
80
|
+
};
|
|
81
|
+
const parseArgs = (args) => {
|
|
82
|
+
const positionals = [];
|
|
83
|
+
let dir;
|
|
84
|
+
let dirSeen = false;
|
|
85
|
+
for (let i = 0; i < args.length; i++) {
|
|
86
|
+
const a = args[i];
|
|
87
|
+
if (a === "--dir") {
|
|
88
|
+
if (dirSeen)
|
|
89
|
+
throw new Error("--dir specified more than once");
|
|
90
|
+
if (i + 1 >= args.length)
|
|
91
|
+
throw new Error("--dir requires a value");
|
|
92
|
+
dir = args[i + 1];
|
|
93
|
+
dirSeen = true;
|
|
94
|
+
i++;
|
|
95
|
+
}
|
|
96
|
+
else if (a.startsWith("--dir=")) {
|
|
97
|
+
if (dirSeen)
|
|
98
|
+
throw new Error("--dir specified more than once");
|
|
99
|
+
dir = a.slice("--dir=".length);
|
|
100
|
+
dirSeen = true;
|
|
101
|
+
}
|
|
102
|
+
else if (a.startsWith("-")) {
|
|
103
|
+
// Treats `--` and any --unknown as an unknown flag.
|
|
104
|
+
throw new Error(`unknown flag: ${a}`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
positionals.push(a);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (positionals.length === 0)
|
|
111
|
+
throw new Error("missing <project-name>");
|
|
112
|
+
if (positionals.length > 1)
|
|
113
|
+
throw new Error("too many positional arguments");
|
|
114
|
+
return { projectName: positionals[0], dir };
|
|
115
|
+
};
|
|
116
|
+
const deriveDirName = (projectName, dir) => {
|
|
117
|
+
if (dir !== undefined)
|
|
118
|
+
return dir;
|
|
119
|
+
if (projectName.startsWith("@")) {
|
|
120
|
+
const pkgPart = projectName.split("/")[1];
|
|
121
|
+
if (!pkgPart) {
|
|
122
|
+
// Unreachable when projectName has passed isValidProjectName (SCOPED_NAME_RE
|
|
123
|
+
// guarantees a non-empty package segment after the single "/"). Guarded here
|
|
124
|
+
// so refactors that reorder validation cannot silently produce undefined.
|
|
125
|
+
throw new Error(`invariant: unvalidated scoped name ${projectName}`);
|
|
126
|
+
}
|
|
127
|
+
return pkgPart;
|
|
128
|
+
}
|
|
129
|
+
return projectName;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* CLI entry point: parses argv, validates project name and optional --dir flag,
|
|
133
|
+
* ensures the target directory does not exist, and scaffolds the template.
|
|
134
|
+
* Exits with non-zero on any validation failure.
|
|
135
|
+
*/
|
|
136
|
+
export const main = () => {
|
|
137
|
+
const args = process.argv.slice(2);
|
|
138
|
+
let parsed;
|
|
139
|
+
try {
|
|
140
|
+
parsed = parseArgs(args);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
console.error(`Error: ${e.message}`);
|
|
144
|
+
console.error("Usage: @o3co/create-auth-policy-verifier <project-name> [--dir <dir-name>]");
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
const { projectName, dir } = parsed;
|
|
148
|
+
if (!isValidProjectName(projectName)) {
|
|
149
|
+
console.error("Error: <project-name> must be a valid npm package name (scoped like @scope/pkg, or unscoped; max 214 chars; no backslashes; no extra '/' beyond the single scope separator).");
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
if (dir !== undefined && !isValidDirName(dir)) {
|
|
153
|
+
console.error("Error: --dir must be a valid unscoped package name (no '/', '\\', '@'; not '.' or '..'; max 214 chars).");
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
const dirName = deriveDirName(projectName, dir);
|
|
157
|
+
const targetDir = resolve(process.cwd(), dirName);
|
|
158
|
+
if (existsSync(targetDir)) {
|
|
159
|
+
console.error(`Error: Directory '${dirName}' already exists.`);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
console.log(`Creating ${projectName}...`);
|
|
163
|
+
scaffold(targetDir, projectName);
|
|
164
|
+
console.log(`\nDone! Created ${projectName} at ${targetDir}`);
|
|
165
|
+
console.log(`\nNext steps:`);
|
|
166
|
+
console.log(` cd ${dirName}`);
|
|
167
|
+
console.log(" npm install");
|
|
168
|
+
console.log(" npm run debug");
|
|
169
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@o3co/create-auth-policy-verifier",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Scaffold a new o3co/auth.policy-verifier project from the standalone template",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/o3co/auth.policy-verifier.git",
|
|
10
|
+
"directory": "create-app"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22.0.0"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"create-auth-policy-verifier": "./dist/cli.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"templates"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"prebuild": "node scripts/copy-templates.mjs",
|
|
25
|
+
"test": "vitest run"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^25.1.0",
|
|
29
|
+
"vitest": "^4.1.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
FROM node:24-alpine AS node-base
|
|
2
|
+
|
|
3
|
+
ENV HOME=/home/node
|
|
4
|
+
|
|
5
|
+
RUN apk add --no-cache tini \
|
|
6
|
+
&& npm install -g corepack --force \
|
|
7
|
+
&& corepack enable
|
|
8
|
+
|
|
9
|
+
WORKDIR /home/node
|
|
10
|
+
|
|
11
|
+
#############################################
|
|
12
|
+
FROM node-base AS deps
|
|
13
|
+
|
|
14
|
+
COPY package.json ./
|
|
15
|
+
|
|
16
|
+
RUN pnpm install
|
|
17
|
+
|
|
18
|
+
#############################################
|
|
19
|
+
FROM deps AS builder
|
|
20
|
+
|
|
21
|
+
COPY tsconfig.json ./
|
|
22
|
+
COPY config/ ./config/
|
|
23
|
+
COPY src/ ./src/
|
|
24
|
+
|
|
25
|
+
RUN pnpm run build
|
|
26
|
+
|
|
27
|
+
#############################################
|
|
28
|
+
FROM node-base AS runtime
|
|
29
|
+
|
|
30
|
+
ENV NODE_ENV=production
|
|
31
|
+
|
|
32
|
+
COPY --from=deps /home/node/package.json /home/node/pnpm-lock.yaml ./
|
|
33
|
+
|
|
34
|
+
RUN pnpm install --prod \
|
|
35
|
+
&& pnpm store prune
|
|
36
|
+
|
|
37
|
+
COPY --from=builder /home/node/dist/ ./dist/
|
|
38
|
+
COPY --from=builder /home/node/config/ ./config/
|
|
39
|
+
|
|
40
|
+
USER node
|
|
41
|
+
|
|
42
|
+
ENTRYPOINT ["tini", "--"]
|
|
43
|
+
CMD ["node", "dist/main.mjs"]
|
|
44
|
+
|
|
45
|
+
#############################################
|
|
46
|
+
FROM builder AS test
|
|
47
|
+
|
|
48
|
+
CMD ["pnpm", "run", "test", "--", "--passWithNoTests"]
|
|
49
|
+
|
|
50
|
+
#############################################
|
|
51
|
+
FROM builder AS develop
|
|
52
|
+
|
|
53
|
+
USER node
|
|
54
|
+
|
|
55
|
+
CMD ["pnpm", "run", "debug"]
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 1o1 Co. Ltd.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
IMAGE ?= auth-policy-verifier
|
|
2
|
+
|
|
3
|
+
.PHONY: dev test build
|
|
4
|
+
|
|
5
|
+
dev:
|
|
6
|
+
docker compose up --build
|
|
7
|
+
|
|
8
|
+
test:
|
|
9
|
+
docker compose -f docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from test
|
|
10
|
+
|
|
11
|
+
build:
|
|
12
|
+
docker build --target runtime -t $(IMAGE) .
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @o3co/auth-policy-verifier-standalone
|
|
2
|
+
|
|
3
|
+
auth.policy-verifier のデプロイ可能なサーバーテンプレートです。このパッケージはコンポジションルートとして機能し、設定の読み込み・モジュールのロード・Express サーバーの起動を担います。`@o3co/create-auth-policy-verifier` によって生成されます。
|
|
4
|
+
|
|
5
|
+
## 使い方
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm install
|
|
9
|
+
OAUTH_JWT_SECRET=your-secret pnpm run start
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 設定
|
|
13
|
+
|
|
14
|
+
設定は `config/application.conf`(HOCON 形式)から読み込まれます。個々の値は環境変数で上書きできます。
|
|
15
|
+
|
|
16
|
+
| 変数 | デフォルト | 説明 |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `HTTP_HOSTNAME` | `0.0.0.0` | バインドするホスト名 |
|
|
19
|
+
| `HTTP_PORT` | `3000` | バインドするポート番号 |
|
|
20
|
+
| `HTTP_PATH_PREFIX` | `""` | URL パスプレフィックス |
|
|
21
|
+
| `OAUTH_JWT_SECRET` | (必須) | HMAC-HS256 JWT 署名シークレット |
|
|
22
|
+
| `OAUTH_JWT_VALIDATE` | `true` | JWT 署名を検証するかどうか |
|
|
23
|
+
|
|
24
|
+
## デフォルトコレクター
|
|
25
|
+
|
|
26
|
+
以下のコレクターが `builtinCollectorsModule` を通じて登録されます。
|
|
27
|
+
|
|
28
|
+
**Attribute collectors**(JWT ペイロードから属性を抽出):
|
|
29
|
+
|
|
30
|
+
- `PayloadScopeCollector` — OAuth スコープを抽出する
|
|
31
|
+
- `PayloadSubjectIdCollector` — サブジェクト識別子を抽出する
|
|
32
|
+
|
|
33
|
+
**Rule collectors**(認可ルールを解決):
|
|
34
|
+
|
|
35
|
+
- `ResourceActionScopeRuleCollector` — リソース/アクションをスコープルールと照合する
|
|
36
|
+
- `ResourceActionPermissionRuleCollector` — リソース/アクションをパーミッションルールと照合する
|
|
37
|
+
|
|
38
|
+
使用されるリソースパーサーは `DotNotationResourceParser` です。
|
|
39
|
+
|
|
40
|
+
## カスタムモジュールの追加
|
|
41
|
+
|
|
42
|
+
`src/main.mts` を編集し、`createApp` に渡す `modules` 配列に独自モジュールを追加してください。
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { myModule } from "./my-module.mts";
|
|
46
|
+
|
|
47
|
+
const app = await createApp({
|
|
48
|
+
pathResolver: import.meta.resolve,
|
|
49
|
+
config,
|
|
50
|
+
modules: [builtinCollectorsModule, builtinKeyResolversModule, myModule],
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`builtinKeyResolversModule`(`@o3co/auth.policy-verifier.server` から import)は `HS256` / `RS256` / `ES256` / `EdDSA` の JWT 鍵解決に必須です。
|
|
55
|
+
|
|
56
|
+
## npm スクリプト
|
|
57
|
+
|
|
58
|
+
| スクリプト | コマンド | 説明 |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| `build` | `tsc` | TypeScript を `dist/` にコンパイルする |
|
|
61
|
+
| `start` | `node dist/main.mjs` | コンパイル済みサーバーを起動する |
|
|
62
|
+
| `debug` | `NODE_OPTIONS='--conditions=development' tsx watch src/main.mts` | ホットリロードで開発サーバーを起動する |
|
|
63
|
+
| `test` | `echo 'no tests configured'` | プレースホルダー(テスト未設定) |
|
|
64
|
+
|
|
65
|
+
## Docker
|
|
66
|
+
|
|
67
|
+
イメージをビルドしてコンテナを起動する:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
make build
|
|
71
|
+
docker run -e OAUTH_JWT_SECRET=secret auth-policy-verifier
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Docker Compose でローカル開発する場合:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
make dev
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 関連
|
|
81
|
+
|
|
82
|
+
- [`@o3co/auth.policy-verifier.server`](../../packages/server) — Express アプリファクトリと設定スキーマ
|
|
83
|
+
- [`@o3co/auth.policy-verifier.builtins`](../../packages/builtins) — 組み込みコレクター実装
|
|
84
|
+
- [`@o3co/create-auth-policy-verifier`](../../create-app) — このテンプレートを生成する CLI スキャフォルダー
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @o3co/auth-policy-verifier-standalone
|
|
2
|
+
|
|
3
|
+
Deployable server template for auth.policy-verifier. This is the composition root — it reads config, loads modules, and starts the Express server. Generated by `@o3co/create-auth-policy-verifier`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm install
|
|
9
|
+
OAUTH_JWT_SECRET=your-secret pnpm run start
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Configuration
|
|
13
|
+
|
|
14
|
+
Configuration is read from `config/application.conf` (HOCON format). Individual values can be overridden with environment variables.
|
|
15
|
+
|
|
16
|
+
| Variable | Default | Description |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `HTTP_HOSTNAME` | `0.0.0.0` | Bind hostname |
|
|
19
|
+
| `HTTP_PORT` | `3000` | Bind port |
|
|
20
|
+
| `HTTP_PATH_PREFIX` | `""` | URL path prefix |
|
|
21
|
+
| `OAUTH_JWT_SECRET` | (required) | HMAC-HS256 JWT signing secret |
|
|
22
|
+
| `OAUTH_JWT_VALIDATE` | `true` | Whether to verify JWT signature |
|
|
23
|
+
|
|
24
|
+
## Default Collectors
|
|
25
|
+
|
|
26
|
+
The following collectors are registered via `builtinCollectorsModule`:
|
|
27
|
+
|
|
28
|
+
**Attribute collectors** (extract attributes from the JWT payload):
|
|
29
|
+
|
|
30
|
+
- `PayloadScopeCollector` — extracts OAuth scopes
|
|
31
|
+
- `PayloadSubjectIdCollector` — extracts the subject identifier
|
|
32
|
+
|
|
33
|
+
**Rule collectors** (resolve authorization rules):
|
|
34
|
+
|
|
35
|
+
- `ResourceActionScopeRuleCollector` — matches resource/action against scope rules
|
|
36
|
+
- `ResourceActionPermissionRuleCollector` — matches resource/action against permission rules
|
|
37
|
+
|
|
38
|
+
The resource parser in use is `DotNotationResourceParser`.
|
|
39
|
+
|
|
40
|
+
## Adding Custom Modules
|
|
41
|
+
|
|
42
|
+
Edit `src/main.mts` and add your module to the `modules` array passed to `createApp`:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { myModule } from "./my-module.mts";
|
|
46
|
+
|
|
47
|
+
const app = await createApp({
|
|
48
|
+
pathResolver: import.meta.resolve,
|
|
49
|
+
config,
|
|
50
|
+
modules: [builtinCollectorsModule, builtinKeyResolversModule, myModule],
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`builtinKeyResolversModule` (from `@o3co/auth.policy-verifier.server`) must be present for the app to resolve JWT keys for `HS256` / `RS256` / `ES256` / `EdDSA`.
|
|
55
|
+
|
|
56
|
+
## npm Scripts
|
|
57
|
+
|
|
58
|
+
| Script | Command | Description |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| `build` | `tsc` | Compile TypeScript to `dist/` |
|
|
61
|
+
| `start` | `node dist/main.mjs` | Start the compiled server |
|
|
62
|
+
| `debug` | `NODE_OPTIONS='--conditions=development' tsx watch src/main.mts` | Start with hot-reload for development |
|
|
63
|
+
| `test` | `echo 'no tests configured'` | Placeholder (no tests configured) |
|
|
64
|
+
|
|
65
|
+
## Docker
|
|
66
|
+
|
|
67
|
+
Build the image and run the container:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
make build
|
|
71
|
+
docker run -e OAUTH_JWT_SECRET=secret auth-policy-verifier
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For local development with Docker Compose:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
make dev
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## See Also
|
|
81
|
+
|
|
82
|
+
- [`@o3co/auth.policy-verifier.server`](../../packages/server) — Express app factory and config schema
|
|
83
|
+
- [`@o3co/auth.policy-verifier.builtins`](../../packages/builtins) — built-in collector implementations
|
|
84
|
+
- [`@o3co/create-auth-policy-verifier`](../../create-app) — CLI scaffolder that generates this template
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
http {
|
|
2
|
+
hostname = "0.0.0.0"
|
|
3
|
+
hostname = ${?HTTP_HOSTNAME}
|
|
4
|
+
port = 3000
|
|
5
|
+
port = ${?HTTP_PORT}
|
|
6
|
+
pathPrefix = ""
|
|
7
|
+
pathPrefix = ${?HTTP_PATH_PREFIX}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
oauth {
|
|
11
|
+
jwt {
|
|
12
|
+
algorithm = "HS256"
|
|
13
|
+
algorithm = ${?OAUTH_JWT_ALGORITHM}
|
|
14
|
+
secret = ${?OAUTH_JWT_SECRET}
|
|
15
|
+
jwksUri = ${?OAUTH_JWT_JWKS_URI}
|
|
16
|
+
publicKey = ${?OAUTH_JWT_PUBLIC_KEY}
|
|
17
|
+
publicKeyPath = ${?OAUTH_JWT_PUBLIC_KEY_PATH}
|
|
18
|
+
validate = true
|
|
19
|
+
validate = ${?OAUTH_JWT_VALIDATE}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
attribute {
|
|
24
|
+
collectors = [
|
|
25
|
+
{ collector = "PayloadScopeCollector" }
|
|
26
|
+
{ collector = "PayloadSubjectIdCollector" }
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
rule {
|
|
31
|
+
collectors = [
|
|
32
|
+
{ collector = "ResourceActionScopeRuleCollector" }
|
|
33
|
+
{ collector = "ResourceActionPermissionRuleCollector" }
|
|
34
|
+
]
|
|
35
|
+
}
|