@schemavaults/auth-server-sdk 0.22.29 → 0.22.32
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/README.md +27 -0
- package/dist/NextjsAppDirectoryPlugin/codegen.d.ts +14 -0
- package/dist/NextjsAppDirectoryPlugin/codegen.js +32 -20
- package/dist/NextjsAppDirectoryPlugin/codegen.js.map +1 -1
- package/dist/cli.cjs +61 -30
- package/dist/cli.js +29 -8
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
1
|
# @schemavaults/auth-server-sdk
|
|
2
2
|
|
|
3
3
|
TypeScript SDK for SchemaVaults Auth Server and Resource Server API backends.
|
|
4
|
+
|
|
5
|
+
## CLI
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bunx @schemavaults/auth-server-sdk codegen [options]
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Generates the auth pages (`login`, `register`, `logout`, `authorize`, `error`)
|
|
12
|
+
and the `auth-provider.tsx` into your Next.js App Router project.
|
|
13
|
+
|
|
14
|
+
### Options
|
|
15
|
+
|
|
16
|
+
- `--client-output-dir <path>` — Custom output directory for the generated
|
|
17
|
+
client `auth/` files. Defaults to `<app>/auth` (e.g. `src/app/auth` or
|
|
18
|
+
`app/auth`). When set, the path is treated as the auth directory itself, so
|
|
19
|
+
you can place the generated files inside a Next.js route group:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bunx @schemavaults/auth-server-sdk codegen --client-output-dir src/app/\(client\)/auth
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Relative paths are resolved against the current working directory.
|
|
26
|
+
- `--templates-dir <path>` — Use a custom codegen templates directory instead
|
|
27
|
+
of the templates bundled with the SDK.
|
|
28
|
+
- `--debug` — Enable debug logging.
|
|
29
|
+
- `--help`, `-h` — Show help.
|
|
30
|
+
- `--version`, `-v` — Show package name and version.
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
export interface IAuthResourceServerCodegenOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Custom output directory for the generated client `auth/` files.
|
|
4
|
+
*
|
|
5
|
+
* When provided, this is treated as the path to the auth directory itself
|
|
6
|
+
* (i.e., the directory in which `login/page.tsx`, `register/page.tsx`,
|
|
7
|
+
* `auth-provider.tsx`, etc. are written). Relative paths are resolved
|
|
8
|
+
* against the current working directory.
|
|
9
|
+
*
|
|
10
|
+
* When omitted, defaults to `<resolved-app-directory>/auth`.
|
|
11
|
+
*
|
|
12
|
+
* Example: `src/app/(client)/auth` to nest the generated routes inside a
|
|
13
|
+
* Next.js route group.
|
|
14
|
+
*/
|
|
15
|
+
clientOutputDirectory?: string;
|
|
2
16
|
codegenTemplatesDirectory?: string;
|
|
3
17
|
debug?: boolean;
|
|
4
18
|
}
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
-
import { dirname } from "path";
|
|
2
|
+
import { dirname, isAbsolute, resolve } from "path";
|
|
3
|
+
import { cwd } from "process";
|
|
3
4
|
import resolveAppDirectory from "./resolve-app-directory";
|
|
4
5
|
import { join } from "path";
|
|
5
6
|
import resolveCodegenTemplatesDirectory from "./resolve-codegen-templates-directory";
|
|
6
7
|
import { extractVersion, getCodegenMarkerComment, hasCodegenMarker, prependCodegenMarker } from "./codegen-marker";
|
|
7
8
|
const pagesToCreate = [
|
|
8
9
|
{
|
|
9
|
-
|
|
10
|
+
auth_relative_path: "login",
|
|
10
11
|
codegen_template_path: "auth/login/page.tsx",
|
|
11
12
|
},
|
|
12
13
|
{
|
|
13
|
-
|
|
14
|
+
auth_relative_path: "register",
|
|
14
15
|
codegen_template_path: "auth/register/page.tsx",
|
|
15
16
|
},
|
|
16
17
|
{
|
|
17
|
-
|
|
18
|
+
auth_relative_path: "logout",
|
|
18
19
|
codegen_template_path: "auth/logout/page.tsx",
|
|
19
20
|
},
|
|
20
21
|
{
|
|
21
|
-
|
|
22
|
+
auth_relative_path: "authorize",
|
|
22
23
|
codegen_template_path: "auth/authorize/page.tsx",
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
|
-
|
|
26
|
+
auth_relative_path: "error",
|
|
26
27
|
codegen_template_path: "auth/error/page.tsx",
|
|
27
28
|
},
|
|
28
29
|
];
|
|
@@ -44,10 +45,10 @@ function formatVersionTransition(oldVersion) {
|
|
|
44
45
|
}
|
|
45
46
|
return "";
|
|
46
47
|
}
|
|
47
|
-
function createClientPages(
|
|
48
|
+
function createClientPages(authDirectory, templatesDir) {
|
|
48
49
|
for (const page of pagesToCreate) {
|
|
49
|
-
const destPath = join(
|
|
50
|
-
const relPath =
|
|
50
|
+
const destPath = join(authDirectory, page.auth_relative_path, "page.tsx");
|
|
51
|
+
const relPath = `auth/${page.auth_relative_path}/page.tsx`;
|
|
51
52
|
if (existsSync(destPath)) {
|
|
52
53
|
if (isCodegenManagedFile(destPath)) {
|
|
53
54
|
const oldVersion = getExistingVersion(destPath);
|
|
@@ -85,10 +86,10 @@ function createClientPages(appDirectory, templatesDir) {
|
|
|
85
86
|
console.log(` - created '${relPath}'`);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
|
-
function createClientAuthProvider(
|
|
89
|
+
function createClientAuthProvider(authDirectory, templatesDir) {
|
|
89
90
|
const srcTemplatePath = join(templatesDir, "auth", "auth-provider.tsx");
|
|
90
|
-
const destPath = join(
|
|
91
|
-
const relPath = "
|
|
91
|
+
const destPath = join(authDirectory, "auth-provider.tsx");
|
|
92
|
+
const relPath = "auth/auth-provider.tsx";
|
|
92
93
|
if (existsSync(destPath)) {
|
|
93
94
|
if (isCodegenManagedFile(destPath)) {
|
|
94
95
|
const oldVersion = getExistingVersion(destPath);
|
|
@@ -123,25 +124,36 @@ function createClientAuthProvider(appDirectory, templatesDir) {
|
|
|
123
124
|
});
|
|
124
125
|
console.log(` - created '${relPath}'`);
|
|
125
126
|
}
|
|
127
|
+
function resolveClientAuthOutputDirectory(clientOutputDirectoryOption, debug) {
|
|
128
|
+
if (typeof clientOutputDirectoryOption === "string" &&
|
|
129
|
+
clientOutputDirectoryOption.length > 0) {
|
|
130
|
+
const resolved = isAbsolute(clientOutputDirectoryOption)
|
|
131
|
+
? clientOutputDirectoryOption
|
|
132
|
+
: resolve(cwd(), clientOutputDirectoryOption);
|
|
133
|
+
console.log(` - using custom client auth output directory '${resolved}'`);
|
|
134
|
+
return resolved;
|
|
135
|
+
}
|
|
136
|
+
const appDirectory = resolveAppDirectory(debug);
|
|
137
|
+
console.log(` - resolved /app directory at '${appDirectory}'`);
|
|
138
|
+
return join(appDirectory, "auth");
|
|
139
|
+
}
|
|
126
140
|
export default async function codegen(opts) {
|
|
127
141
|
console.log(`[@schemavaults/auth-server-sdk/NextjsAppDirectoryPlugin] Running codegen:`);
|
|
128
142
|
const debug = opts?.debug ?? false;
|
|
129
|
-
const
|
|
130
|
-
console.log(` - resolved /app directory at '${appDirectory}'`);
|
|
131
|
-
const authDirectory = join(appDirectory, "auth");
|
|
143
|
+
const authDirectory = resolveClientAuthOutputDirectory(opts?.clientOutputDirectory, debug);
|
|
132
144
|
if (!existsSync(authDirectory)) {
|
|
133
|
-
mkdirSync(authDirectory);
|
|
134
|
-
console.log(` - created
|
|
145
|
+
mkdirSync(authDirectory, { recursive: true });
|
|
146
|
+
console.log(` - created client auth output directory at '${authDirectory}'`);
|
|
135
147
|
}
|
|
136
148
|
else {
|
|
137
|
-
console.log(` -
|
|
149
|
+
console.log(` - client auth output directory already exists at '${authDirectory}'`);
|
|
138
150
|
}
|
|
139
151
|
const templatesDir = typeof opts?.codegenTemplatesDirectory === "string"
|
|
140
152
|
? opts.codegenTemplatesDirectory
|
|
141
153
|
: resolveCodegenTemplatesDirectory(debug);
|
|
142
154
|
console.log(` - resolved codegen templates directory at '${templatesDir}'`);
|
|
143
|
-
createClientPages(
|
|
144
|
-
createClientAuthProvider(
|
|
155
|
+
createClientPages(authDirectory, templatesDir);
|
|
156
|
+
createClientAuthProvider(authDirectory, templatesDir);
|
|
145
157
|
console.log(`[@schemavaults/auth-server-sdk/NextjsAppDirectoryPlugin] Codegen complete.`);
|
|
146
158
|
}
|
|
147
159
|
//# sourceMappingURL=codegen.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/NextjsAppDirectoryPlugin/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/NextjsAppDirectoryPlugin/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,mBAAmB,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,gCAAgC,MAAM,uCAAuC,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AA2BnH,MAAM,aAAa,GAAiC;IAClD;QACE,kBAAkB,EAAE,OAAO;QAC3B,qBAAqB,EAAE,qBAAqB;KAC7C;IACD;QACE,kBAAkB,EAAE,UAAU;QAC9B,qBAAqB,EAAE,wBAAwB;KAChD;IACD;QACE,kBAAkB,EAAE,QAAQ;QAC5B,qBAAqB,EAAE,sBAAsB;KAC9C;IACD;QACE,kBAAkB,EAAE,WAAW;QAC/B,qBAAqB,EAAE,y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a,GAAW,gCAAgC,CAC5D,IAAI,EAAE,qBAAqB,EAC3B,KAAK,CACN,CAAC;IACF,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAC/B,SAAS,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,+CAA+C,aAAa,GAAG,CAAC,CAAC;IAC/E,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CACT,sDAAsD,aAAa,GAAG,CACvE,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAChB,OAAO,IAAI,EAAE,yBAAyB,KAAK,QAAQ;QACjD,CAAC,CAAC,IAAI,CAAC,yBAAyB;QAChC,CAAC,CAAC,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,+CAA+C,YAAY,GAAG,CAAC,CAAC;IAE5E,iBAAiB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC/C,wBAAwB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAEtD,OAAO,CAAC,GAAG,CACT,4EAA4E,CAC7E,CAAC;AACJ,CAAC"}
|
package/dist/cli.cjs
CHANGED
|
@@ -89,7 +89,7 @@ var init_resolve_codegen_templates_directory = __esm({
|
|
|
89
89
|
|
|
90
90
|
// src/NextjsAppDirectoryPlugin/codegen-marker.ts
|
|
91
91
|
function getCodegenMarkerComment() {
|
|
92
|
-
const version = true ? "0.22.
|
|
92
|
+
const version = true ? "0.22.32" : "unknown";
|
|
93
93
|
return `${CODEGEN_MARKER_PREFIX}${version}`;
|
|
94
94
|
}
|
|
95
95
|
function hasCodegenMarker(firstLine) {
|
|
@@ -135,10 +135,10 @@ function formatVersionTransition(oldVersion) {
|
|
|
135
135
|
}
|
|
136
136
|
return "";
|
|
137
137
|
}
|
|
138
|
-
function createClientPages(
|
|
138
|
+
function createClientPages(authDirectory, templatesDir) {
|
|
139
139
|
for (const page of pagesToCreate) {
|
|
140
|
-
const destPath = (0, import_path4.join)(
|
|
141
|
-
const relPath =
|
|
140
|
+
const destPath = (0, import_path4.join)(authDirectory, page.auth_relative_path, "page.tsx");
|
|
141
|
+
const relPath = `auth/${page.auth_relative_path}/page.tsx`;
|
|
142
142
|
if ((0, import_fs3.existsSync)(destPath)) {
|
|
143
143
|
if (isCodegenManagedFile(destPath)) {
|
|
144
144
|
const oldVersion = getExistingVersion(destPath);
|
|
@@ -176,14 +176,14 @@ function createClientPages(appDirectory, templatesDir) {
|
|
|
176
176
|
console.log(` - created '${relPath}'`);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
function createClientAuthProvider(
|
|
179
|
+
function createClientAuthProvider(authDirectory, templatesDir) {
|
|
180
180
|
const srcTemplatePath = (0, import_path4.join)(
|
|
181
181
|
templatesDir,
|
|
182
182
|
"auth",
|
|
183
183
|
"auth-provider.tsx"
|
|
184
184
|
);
|
|
185
|
-
const destPath = (0, import_path4.join)(
|
|
186
|
-
const relPath = "
|
|
185
|
+
const destPath = (0, import_path4.join)(authDirectory, "auth-provider.tsx");
|
|
186
|
+
const relPath = "auth/auth-provider.tsx";
|
|
187
187
|
if ((0, import_fs3.existsSync)(destPath)) {
|
|
188
188
|
if (isCodegenManagedFile(destPath)) {
|
|
189
189
|
const oldVersion = getExistingVersion(destPath);
|
|
@@ -218,57 +218,71 @@ function createClientAuthProvider(appDirectory, templatesDir) {
|
|
|
218
218
|
});
|
|
219
219
|
console.log(` - created '${relPath}'`);
|
|
220
220
|
}
|
|
221
|
+
function resolveClientAuthOutputDirectory(clientOutputDirectoryOption, debug) {
|
|
222
|
+
if (typeof clientOutputDirectoryOption === "string" && clientOutputDirectoryOption.length > 0) {
|
|
223
|
+
const resolved = (0, import_path3.isAbsolute)(clientOutputDirectoryOption) ? clientOutputDirectoryOption : (0, import_path3.resolve)((0, import_process2.cwd)(), clientOutputDirectoryOption);
|
|
224
|
+
console.log(` - using custom client auth output directory '${resolved}'`);
|
|
225
|
+
return resolved;
|
|
226
|
+
}
|
|
227
|
+
const appDirectory = resolveAppDirectory(debug);
|
|
228
|
+
console.log(` - resolved /app directory at '${appDirectory}'`);
|
|
229
|
+
return (0, import_path4.join)(appDirectory, "auth");
|
|
230
|
+
}
|
|
221
231
|
async function codegen(opts) {
|
|
222
232
|
console.log(
|
|
223
233
|
`[@schemavaults/auth-server-sdk/NextjsAppDirectoryPlugin] Running codegen:`
|
|
224
234
|
);
|
|
225
235
|
const debug = opts?.debug ?? false;
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
236
|
+
const authDirectory = resolveClientAuthOutputDirectory(
|
|
237
|
+
opts?.clientOutputDirectory,
|
|
238
|
+
debug
|
|
239
|
+
);
|
|
229
240
|
if (!(0, import_fs3.existsSync)(authDirectory)) {
|
|
230
|
-
(0, import_fs3.mkdirSync)(authDirectory);
|
|
231
|
-
console.log(` - created
|
|
241
|
+
(0, import_fs3.mkdirSync)(authDirectory, { recursive: true });
|
|
242
|
+
console.log(` - created client auth output directory at '${authDirectory}'`);
|
|
232
243
|
} else {
|
|
233
|
-
console.log(
|
|
244
|
+
console.log(
|
|
245
|
+
` - client auth output directory already exists at '${authDirectory}'`
|
|
246
|
+
);
|
|
234
247
|
}
|
|
235
248
|
const templatesDir = typeof opts?.codegenTemplatesDirectory === "string" ? opts.codegenTemplatesDirectory : resolveCodegenTemplatesDirectory(debug);
|
|
236
249
|
console.log(` - resolved codegen templates directory at '${templatesDir}'`);
|
|
237
|
-
createClientPages(
|
|
238
|
-
createClientAuthProvider(
|
|
250
|
+
createClientPages(authDirectory, templatesDir);
|
|
251
|
+
createClientAuthProvider(authDirectory, templatesDir);
|
|
239
252
|
console.log(
|
|
240
253
|
`[@schemavaults/auth-server-sdk/NextjsAppDirectoryPlugin] Codegen complete.`
|
|
241
254
|
);
|
|
242
255
|
}
|
|
243
|
-
var import_fs3, import_path3, import_path4, pagesToCreate;
|
|
256
|
+
var import_fs3, import_path3, import_process2, import_path4, pagesToCreate;
|
|
244
257
|
var init_codegen = __esm({
|
|
245
258
|
"src/NextjsAppDirectoryPlugin/codegen.ts"() {
|
|
246
259
|
"use strict";
|
|
247
260
|
import_fs3 = require("fs");
|
|
248
261
|
import_path3 = require("path");
|
|
262
|
+
import_process2 = require("process");
|
|
249
263
|
init_resolve_app_directory();
|
|
250
264
|
import_path4 = require("path");
|
|
251
265
|
init_resolve_codegen_templates_directory();
|
|
252
266
|
init_codegen_marker();
|
|
253
267
|
pagesToCreate = [
|
|
254
268
|
{
|
|
255
|
-
|
|
269
|
+
auth_relative_path: "login",
|
|
256
270
|
codegen_template_path: "auth/login/page.tsx"
|
|
257
271
|
},
|
|
258
272
|
{
|
|
259
|
-
|
|
273
|
+
auth_relative_path: "register",
|
|
260
274
|
codegen_template_path: "auth/register/page.tsx"
|
|
261
275
|
},
|
|
262
276
|
{
|
|
263
|
-
|
|
277
|
+
auth_relative_path: "logout",
|
|
264
278
|
codegen_template_path: "auth/logout/page.tsx"
|
|
265
279
|
},
|
|
266
280
|
{
|
|
267
|
-
|
|
281
|
+
auth_relative_path: "authorize",
|
|
268
282
|
codegen_template_path: "auth/authorize/page.tsx"
|
|
269
283
|
},
|
|
270
284
|
{
|
|
271
|
-
|
|
285
|
+
auth_relative_path: "error",
|
|
272
286
|
codegen_template_path: "auth/error/page.tsx"
|
|
273
287
|
}
|
|
274
288
|
];
|
|
@@ -291,14 +305,25 @@ Commands:
|
|
|
291
305
|
codegen Generate auth pages for your Next.js app (default)
|
|
292
306
|
|
|
293
307
|
Options:
|
|
294
|
-
--
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
308
|
+
--client-output-dir <path> Custom output directory for the generated client
|
|
309
|
+
auth files (defaults to <app>/auth, e.g.
|
|
310
|
+
src/app/auth). Useful for nesting under a route
|
|
311
|
+
group, e.g. src/app/(client)/auth.
|
|
312
|
+
--templates-dir <path> Custom codegen templates directory
|
|
313
|
+
--debug Enable debug logging
|
|
314
|
+
--help, -h Show this help message
|
|
315
|
+
--version, -v Show package name
|
|
298
316
|
`;
|
|
299
317
|
function printHelp() {
|
|
300
318
|
console.log(HELP_TEXT);
|
|
301
319
|
}
|
|
320
|
+
function readStringFlag(args, flag) {
|
|
321
|
+
const index = args.indexOf(flag);
|
|
322
|
+
if (index === -1) {
|
|
323
|
+
return { present: false, value: void 0 };
|
|
324
|
+
}
|
|
325
|
+
return { present: true, value: args[index + 1] };
|
|
326
|
+
}
|
|
302
327
|
async function main() {
|
|
303
328
|
const args = process.argv.slice(2);
|
|
304
329
|
if (args.includes("--help") || args.includes("-h")) {
|
|
@@ -306,7 +331,7 @@ async function main() {
|
|
|
306
331
|
return;
|
|
307
332
|
}
|
|
308
333
|
if (args.includes("--version") || args.includes("-v")) {
|
|
309
|
-
console.log(`${PACKAGE_NAME}@${"0.22.
|
|
334
|
+
console.log(`${PACKAGE_NAME}@${"0.22.32"}`);
|
|
310
335
|
return;
|
|
311
336
|
}
|
|
312
337
|
const command = args.find((arg) => !arg.startsWith("-")) ?? "codegen";
|
|
@@ -316,16 +341,22 @@ async function main() {
|
|
|
316
341
|
printHelp();
|
|
317
342
|
process.exit(1);
|
|
318
343
|
}
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
if (templatesDirIndex !== -1 && !templatesDir) {
|
|
344
|
+
const templatesFlag = readStringFlag(args, "--templates-dir");
|
|
345
|
+
if (templatesFlag.present && !templatesFlag.value) {
|
|
322
346
|
console.error("Error: --templates-dir requires a path argument\n");
|
|
323
347
|
printHelp();
|
|
324
348
|
process.exit(1);
|
|
325
349
|
}
|
|
350
|
+
const clientOutputFlag = readStringFlag(args, "--client-output-dir");
|
|
351
|
+
if (clientOutputFlag.present && !clientOutputFlag.value) {
|
|
352
|
+
console.error("Error: --client-output-dir requires a path argument\n");
|
|
353
|
+
printHelp();
|
|
354
|
+
process.exit(1);
|
|
355
|
+
}
|
|
326
356
|
const debug = args.includes("--debug");
|
|
327
357
|
await NextjsAppDirectoryPlugin.codegen({
|
|
328
|
-
...
|
|
358
|
+
...templatesFlag.value ? { codegenTemplatesDirectory: templatesFlag.value } : {},
|
|
359
|
+
...clientOutputFlag.value ? { clientOutputDirectory: clientOutputFlag.value } : {},
|
|
329
360
|
debug
|
|
330
361
|
});
|
|
331
362
|
}
|
package/dist/cli.js
CHANGED
|
@@ -6,14 +6,25 @@ Commands:
|
|
|
6
6
|
codegen Generate auth pages for your Next.js app (default)
|
|
7
7
|
|
|
8
8
|
Options:
|
|
9
|
-
--
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
--client-output-dir <path> Custom output directory for the generated client
|
|
10
|
+
auth files (defaults to <app>/auth, e.g.
|
|
11
|
+
src/app/auth). Useful for nesting under a route
|
|
12
|
+
group, e.g. src/app/(client)/auth.
|
|
13
|
+
--templates-dir <path> Custom codegen templates directory
|
|
14
|
+
--debug Enable debug logging
|
|
15
|
+
--help, -h Show this help message
|
|
16
|
+
--version, -v Show package name
|
|
13
17
|
`;
|
|
14
18
|
function printHelp() {
|
|
15
19
|
console.log(HELP_TEXT);
|
|
16
20
|
}
|
|
21
|
+
function readStringFlag(args, flag) {
|
|
22
|
+
const index = args.indexOf(flag);
|
|
23
|
+
if (index === -1) {
|
|
24
|
+
return { present: false, value: undefined };
|
|
25
|
+
}
|
|
26
|
+
return { present: true, value: args[index + 1] };
|
|
27
|
+
}
|
|
17
28
|
async function main() {
|
|
18
29
|
const args = process.argv.slice(2);
|
|
19
30
|
if (args.includes("--help") || args.includes("-h")) {
|
|
@@ -30,16 +41,26 @@ async function main() {
|
|
|
30
41
|
printHelp();
|
|
31
42
|
process.exit(1);
|
|
32
43
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
if (templatesDirIndex !== -1 && !templatesDir) {
|
|
44
|
+
const templatesFlag = readStringFlag(args, "--templates-dir");
|
|
45
|
+
if (templatesFlag.present && !templatesFlag.value) {
|
|
36
46
|
console.error("Error: --templates-dir requires a path argument\n");
|
|
37
47
|
printHelp();
|
|
38
48
|
process.exit(1);
|
|
39
49
|
}
|
|
50
|
+
const clientOutputFlag = readStringFlag(args, "--client-output-dir");
|
|
51
|
+
if (clientOutputFlag.present && !clientOutputFlag.value) {
|
|
52
|
+
console.error("Error: --client-output-dir requires a path argument\n");
|
|
53
|
+
printHelp();
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
40
56
|
const debug = args.includes("--debug");
|
|
41
57
|
await NextjsAppDirectoryPlugin.codegen({
|
|
42
|
-
...(
|
|
58
|
+
...(templatesFlag.value
|
|
59
|
+
? { codegenTemplatesDirectory: templatesFlag.value }
|
|
60
|
+
: {}),
|
|
61
|
+
...(clientOutputFlag.value
|
|
62
|
+
? { clientOutputDirectory: clientOutputFlag.value }
|
|
63
|
+
: {}),
|
|
43
64
|
debug,
|
|
44
65
|
});
|
|
45
66
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,YAAY,GAAG,+BAA+B,CAAC;AAErD,MAAM,SAAS,GAAG,UAAU,YAAY
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,YAAY,GAAG,+BAA+B,CAAC;AAErD,MAAM,SAAS,GAAG,UAAU,YAAY;;;;;;;;;;;;;;CAcvC,CAAC;AAEF,SAAS,SAAS;IAChB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,cAAc,CACrB,IAAc,EACd,IAAY;IAEZ,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,C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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,gBAAgB,GAAG,cAAc,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IACrE,IAAI,gBAAgB,CAAC,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QACxD,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;QACvE,SAAS,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEvC,MAAM,wBAAwB,CAAC,OAAO,CAAC;QACrC,GAAG,CAAC,aAAa,CAAC,KAAK;YACrB,CAAC,CAAC,EAAE,yBAAyB,EAAE,aAAa,CAAC,KAAK,EAAE;YACpD,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,gBAAgB,CAAC,KAAK;YACxB,CAAC,CAAC,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,KAAK,EAAE;YACnD,CAAC,CAAC,EAAE,CAAC;QACP,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/auth-server-sdk",
|
|
3
3
|
"description": "TypeScript SDK for building authenticated endpoints/middlewares for the Auth Server and Resource Servers",
|
|
4
|
-
"version": "0.22.
|
|
4
|
+
"version": "0.22.32",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|