@stacksjs/actions 0.70.257 → 0.70.259
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/dist/action.js +1 -80
- package/dist/actions.js +1 -2
- package/dist/add.js +1 -20
- package/dist/ai/request-model-access.js +1 -10
- package/dist/auth/client.js +2 -44
- package/dist/auth/prune.js +1 -35
- package/dist/auth/setup.js +33 -153
- package/dist/auth/token.js +1 -10
- package/dist/blog-admin.js +3 -151
- package/dist/blog.js +33 -271
- package/dist/build/cli.js +1 -6
- package/dist/build/component-library.js +1 -36
- package/dist/build/component-libs.js +1 -2
- package/dist/build/core.js +1 -55
- package/dist/build/desktop.js +4 -61
- package/dist/build/dmg.js +4 -68
- package/dist/build/docs.js +1 -5
- package/dist/build/frontend-static.js +6 -122
- package/dist/build/server.js +1 -6
- package/dist/build/stacks.js +1 -8
- package/dist/build/views.js +1 -16
- package/dist/build-web-component-lib.js +1 -2
- package/dist/build.js +1 -57
- package/dist/bump.js +9 -210
- package/dist/changelog.js +1 -27
- package/dist/check/ports.js +1 -16
- package/dist/clean.js +1 -4
- package/dist/commit.js +1 -12
- package/dist/copy-types.js +1 -9
- package/dist/database/seed.js +1 -26
- package/dist/deploy/create-receipt-rule.js +1 -36
- package/dist/deploy/index.js +29 -1306
- package/dist/dev/api.js +3 -94
- package/dist/dev/components.js +1 -7
- package/dist/dev/csrf.js +1 -28
- package/dist/dev/dashboard-request-routing.js +1 -10
- package/dist/dev/dashboard-utils.js +1 -380
- package/dist/dev/dashboard.js +7 -422
- package/dist/dev/desktop.js +1 -1
- package/dist/dev/docs.js +1 -24
- package/dist/dev/exit-with-parent.d.ts +6 -0
- package/dist/dev/exit-with-parent.js +1 -0
- package/dist/dev/index.js +1 -29
- package/dist/dev/migrate-watcher.js +1 -74
- package/dist/dev/system-tray.js +2 -172
- package/dist/dev/views.js +1 -169
- package/dist/discover-packages.js +1 -32
- package/dist/domains/add.js +1 -61
- package/dist/domains/purchase.js +1 -66
- package/dist/domains/remove.js +1 -24
- package/dist/examples.js +1 -34
- package/dist/find-projects.js +1 -16
- package/dist/fresh.js +1 -17
- package/dist/generate/action-types.js +3 -9
- package/dist/generate/component-meta.js +1 -9
- package/dist/generate/custom-cli-file.js +2 -20
- package/dist/generate/env-files.js +5 -46
- package/dist/generate/ide-helpers.js +1 -8
- package/dist/generate/images.js +1 -26
- package/dist/generate/index.js +1 -166
- package/dist/generate/lib-entries.js +1 -16
- package/dist/generate/pantry-file.js +1 -46
- package/dist/generate/symlink-core.js +1 -2
- package/dist/generate/types.js +1 -3
- package/dist/generate/vschema.js +2 -47
- package/dist/generate/vscode-custom-data.js +1 -9
- package/dist/helpers/api-host.js +1 -7
- package/dist/helpers/component-meta.js +5 -295
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/lib-entries.js +3 -73
- package/dist/helpers/package-json.js +2 -34
- package/dist/helpers/utils.js +1 -130
- package/dist/helpers/vscode-custom-data.js +3 -57
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -50
- package/dist/key-generate.js +1 -24
- package/dist/lint/fix.js +1 -4
- package/dist/lint/index.js +1 -4
- package/dist/lint/lint.js +1 -34
- package/dist/lint/stx-gate.d.ts +36 -0
- package/dist/lint/stx-gate.js +3 -0
- package/dist/make-command.js +4 -55
- package/dist/make-job.js +3 -29
- package/dist/make-policy.js +4 -53
- package/dist/make-resource.js +3 -33
- package/dist/make.js +7 -323
- package/dist/migrate/database.js +1 -16
- package/dist/migrate/fresh.js +1 -36
- package/dist/prepublish.js +1 -16
- package/dist/queue/clear.js +1 -42
- package/dist/queue/dlq-purge.js +1 -28
- package/dist/queue/dlq-retry.js +1 -35
- package/dist/queue/dlq.js +4 -55
- package/dist/queue/failed.js +4 -69
- package/dist/queue/flush.js +2 -49
- package/dist/queue/inspect.js +7 -154
- package/dist/queue/list.js +4 -69
- package/dist/queue/monitor.js +5 -94
- package/dist/queue/pause.js +1 -28
- package/dist/queue/quarantine.js +2 -42
- package/dist/queue/resume.js +1 -27
- package/dist/queue/retry.js +1 -41
- package/dist/queue/schedule-list.js +4 -33
- package/dist/queue/schedule.js +1 -12
- package/dist/queue/status.js +4 -68
- package/dist/queue/table.js +1 -10
- package/dist/queue/unquarantine.js +1 -27
- package/dist/queue/work.js +1 -57
- package/dist/release-preflight.js +3 -61
- package/dist/release.js +1 -29
- package/dist/route/list.js +2 -78
- package/dist/run-action.js +1 -1
- package/dist/saas/setup.js +1 -9
- package/dist/scaffold-crud.js +12 -137
- package/dist/schedule/run.js +1 -7
- package/dist/search/flush.js +1 -10
- package/dist/search/import.js +1 -10
- package/dist/search/settings-list.js +1 -10
- package/dist/search/settings.js +1 -9
- package/dist/serve/api.js +1 -37
- package/dist/setup/index.js +1 -1
- package/dist/setup/ssl.js +2 -268
- package/dist/stacks.js +1 -316
- package/dist/templates.js +20 -40
- package/dist/test/feature.js +1 -2
- package/dist/test/index.js +1 -2
- package/dist/test/runner.js +1 -38
- package/dist/test/runner.test.js +1 -29
- package/dist/test/ui.js +1 -2
- package/dist/test/unit.js +1 -2
- package/dist/typecheck.js +1 -4
- package/dist/types.js +1 -16
- package/dist/upgrade/binary.js +1 -29
- package/dist/upgrade/framework-hooks.js +1 -40
- package/dist/upgrade/framework-utils.js +2 -259
- package/dist/upgrade/framework.js +11 -484
- package/dist/upgrade/index.js +1 -17
- package/dist/upgrade/package-project.js +1 -150
- package/dist/upgrade/packages.js +17 -243
- package/dist/upgrade/shell.js +3 -40
- package/dist/upgrade.js +1 -38
- package/package.json +19 -19
package/dist/action.js
CHANGED
|
@@ -1,80 +1 @@
|
|
|
1
|
-
export class Action {
|
|
2
|
-
name;
|
|
3
|
-
description;
|
|
4
|
-
apiResponse;
|
|
5
|
-
rate;
|
|
6
|
-
tries;
|
|
7
|
-
backoff;
|
|
8
|
-
enabled;
|
|
9
|
-
path;
|
|
10
|
-
method;
|
|
11
|
-
validations;
|
|
12
|
-
requestFile;
|
|
13
|
-
skipCsrf;
|
|
14
|
-
csrf;
|
|
15
|
-
authorize;
|
|
16
|
-
before;
|
|
17
|
-
handle;
|
|
18
|
-
model;
|
|
19
|
-
modelDefinition;
|
|
20
|
-
_dependenciesFactory;
|
|
21
|
-
_resolvedDeps;
|
|
22
|
-
_depsOverrides;
|
|
23
|
-
constructor({
|
|
24
|
-
name,
|
|
25
|
-
description,
|
|
26
|
-
apiResponse,
|
|
27
|
-
validations,
|
|
28
|
-
handle,
|
|
29
|
-
rate,
|
|
30
|
-
tries,
|
|
31
|
-
backoff,
|
|
32
|
-
enabled,
|
|
33
|
-
path,
|
|
34
|
-
method,
|
|
35
|
-
requestFile,
|
|
36
|
-
model,
|
|
37
|
-
skipCsrf,
|
|
38
|
-
csrf,
|
|
39
|
-
authorize,
|
|
40
|
-
before,
|
|
41
|
-
dependencies
|
|
42
|
-
}) {
|
|
43
|
-
this.name = name;
|
|
44
|
-
this.description = description;
|
|
45
|
-
this.apiResponse = apiResponse;
|
|
46
|
-
this.validations = validations;
|
|
47
|
-
this.rate = rate;
|
|
48
|
-
this.tries = tries;
|
|
49
|
-
this.backoff = backoff;
|
|
50
|
-
this.enabled = enabled;
|
|
51
|
-
this.path = path;
|
|
52
|
-
this.method = method;
|
|
53
|
-
this.handle = handle;
|
|
54
|
-
this.requestFile = requestFile;
|
|
55
|
-
this.skipCsrf = skipCsrf;
|
|
56
|
-
this.csrf = csrf;
|
|
57
|
-
this.authorize = authorize;
|
|
58
|
-
this.before = before;
|
|
59
|
-
this._dependenciesFactory = dependencies;
|
|
60
|
-
this.modelDefinition = model;
|
|
61
|
-
if (model && typeof model === "object" && "name" in model)
|
|
62
|
-
this.model = model.name;
|
|
63
|
-
else if (typeof model === "string")
|
|
64
|
-
this.model = model;
|
|
65
|
-
}
|
|
66
|
-
get deps() {
|
|
67
|
-
if (!this._resolvedDeps)
|
|
68
|
-
this._resolvedDeps = this._dependenciesFactory?.() ?? {};
|
|
69
|
-
if (this._depsOverrides)
|
|
70
|
-
return { ...this._resolvedDeps, ...this._depsOverrides };
|
|
71
|
-
return this._resolvedDeps;
|
|
72
|
-
}
|
|
73
|
-
overrideDependencies(overrides) {
|
|
74
|
-
this._depsOverrides = { ...this._depsOverrides ?? {}, ...overrides };
|
|
75
|
-
}
|
|
76
|
-
resetDependencies() {
|
|
77
|
-
this._depsOverrides = void 0;
|
|
78
|
-
this._resolvedDeps = void 0;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
1
|
+
export class Action{name;description;apiResponse;rate;tries;backoff;enabled;path;method;validations;requestFile;skipCsrf;csrf;authorize;before;handle;model;modelDefinition;_dependenciesFactory;_resolvedDeps;_depsOverrides;constructor({name,description,apiResponse,validations,handle,rate,tries,backoff,enabled,path,method,requestFile,model,skipCsrf,csrf,authorize,before,dependencies}){this.name=name;this.description=description;this.apiResponse=apiResponse;this.validations=validations;this.rate=rate;this.tries=tries;this.backoff=backoff;this.enabled=enabled;this.path=path;this.method=method;this.handle=handle;this.requestFile=requestFile;this.skipCsrf=skipCsrf;this.csrf=csrf;this.authorize=authorize;this.before=before;this._dependenciesFactory=dependencies;this.modelDefinition=model;if(model&&typeof model==="object"&&"name"in model)this.model=model.name;else if(typeof model==="string")this.model=model}get deps(){if(!this._resolvedDeps)this._resolvedDeps=this._dependenciesFactory?.()??{};if(this._depsOverrides)return{...this._resolvedDeps,...this._depsOverrides};return this._resolvedDeps}overrideDependencies(overrides){this._depsOverrides={...this._depsOverrides??{},...overrides}}resetDependencies(){this._depsOverrides=void 0;this._resolvedDeps=void 0}}
|
package/dist/actions.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * as actions from "./helpers/utils";
|
|
1
|
+
export*from"./helpers/utils";export* as actions from"./helpers/utils";
|
package/dist/add.js
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export async function invoke(options) {
|
|
3
|
-
if (options?.table)
|
|
4
|
-
await addTable();
|
|
5
|
-
if (options?.calendar)
|
|
6
|
-
await addCalendar();
|
|
7
|
-
}
|
|
8
|
-
export async function add(options) {
|
|
9
|
-
return await invoke(options);
|
|
10
|
-
}
|
|
11
|
-
export async function addTable() {
|
|
12
|
-
await installPackage("@stacksjs/table");
|
|
13
|
-
}
|
|
14
|
-
export async function addCalendar() {
|
|
15
|
-
await installPackage("@stacksjs/calendar");
|
|
16
|
-
}
|
|
17
|
-
export async function installPackages(names) {
|
|
18
|
-
for (const name of names)
|
|
19
|
-
await installPackage(name);
|
|
20
|
-
}
|
|
1
|
+
import{installPackage}from"@stacksjs/cli";export async function invoke(options){if(options?.table)await addTable();if(options?.calendar)await addCalendar()}export async function add(options){return await invoke(options)}export async function addTable(){await installPackage("@stacksjs/table")}export async function addCalendar(){await installPackage("@stacksjs/calendar")}export async function installPackages(names){for(const name of names)await installPackage(name)}
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
var {require}=import.meta;import
|
|
2
|
-
async function main() {
|
|
3
|
-
try {
|
|
4
|
-
await requestModelAccess();
|
|
5
|
-
} catch (error) {
|
|
6
|
-
console.error("Error requesting model access:", error);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
if (import.meta.main)
|
|
10
|
-
main();
|
|
1
|
+
var {require}=import.meta;import{requestModelAccess}from"@stacksjs/ai";async function main(){try{await requestModelAccess()}catch(error){console.error("Error requesting model access:",error)}}if(import.meta.main)main();
|
package/dist/auth/client.js
CHANGED
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
|
|
3
|
-
import { db } from "@stacksjs/database";
|
|
4
|
-
import { HttpError } from "@stacksjs/error-handling";
|
|
5
|
-
import { log } from "@stacksjs/logging";
|
|
6
|
-
const args = process.argv.slice(2), getArg = (name) => {
|
|
7
|
-
const idx = args.findIndex((a) => a.startsWith(`--${name}=`) || a.startsWith(`-${name.charAt(0)}=`));
|
|
8
|
-
if (idx !== -1) {
|
|
9
|
-
const arg = args[idx];
|
|
10
|
-
if (!arg)
|
|
11
|
-
return;
|
|
12
|
-
const eqIdx = arg.indexOf("=");
|
|
13
|
-
return eqIdx >= 0 ? arg.slice(eqIdx + 1) : void 0;
|
|
14
|
-
}
|
|
15
|
-
const flagIdx = args.findIndex((a) => a === `--${name}` || a === `-${name.charAt(0)}`), value = flagIdx !== -1 ? args[flagIdx + 1] : void 0;
|
|
16
|
-
if (value && !value.startsWith("-"))
|
|
17
|
-
return value;
|
|
18
|
-
return;
|
|
19
|
-
}, hasFlag = (name) => {
|
|
20
|
-
return args.includes(`--${name}`);
|
|
21
|
-
}, name = getArg("name") || "OAuth Client", redirect = getArg("redirect") || "http://localhost", isPersonalAccess = hasFlag("personal"), isPasswordClient = hasFlag("password");
|
|
22
|
-
log.info(`Creating OAuth client: ${name}`);
|
|
23
|
-
const secret = randomBytes(40).toString("hex"), salt = randomBytes(16).toString("hex"), hashedSecret = `${salt}:${scryptSync(secret, salt, 64).toString("hex")}`, result = await db.insertInto("oauth_clients").values({
|
|
24
|
-
name,
|
|
25
|
-
secret: hashedSecret,
|
|
26
|
-
provider: "local",
|
|
27
|
-
redirect,
|
|
28
|
-
personal_access_client: isPersonalAccess,
|
|
29
|
-
password_client: isPasswordClient,
|
|
30
|
-
revoked: !1
|
|
31
|
-
}).executeTakeFirst(), insertId = result?.insertId || Number(result?.numInsertedOrUpdatedRows);
|
|
32
|
-
if (!insertId)
|
|
33
|
-
throw new HttpError(500, "Failed to create OAuth client");
|
|
34
|
-
log.success("OAuth client created successfully");
|
|
35
|
-
log.info("");
|
|
36
|
-
log.info("Client Details:");
|
|
37
|
-
log.info(` Client ID: ${insertId}`);
|
|
38
|
-
log.info(" Client Secret: [REDACTED]");
|
|
39
|
-
process.stdout.write(`Client Secret (save now, shown once): ${secret}
|
|
40
|
-
`);
|
|
41
|
-
log.info(` Redirect URI: ${redirect}`);
|
|
42
|
-
log.info("");
|
|
43
|
-
log.warn("Make sure to save the client secret. You will not be able to retrieve it again.");
|
|
44
|
-
process.exit(0);
|
|
1
|
+
import process from"node:process";import{randomBytes,scryptSync}from"node:crypto";import{db}from"@stacksjs/database";import{HttpError}from"@stacksjs/error-handling";import{log}from"@stacksjs/logging";const args=process.argv.slice(2),getArg=(name)=>{const idx=args.findIndex((a)=>a.startsWith(`--${name}=`)||a.startsWith(`-${name.charAt(0)}=`));if(idx!==-1){const arg=args[idx];if(!arg)return;const eqIdx=arg.indexOf("=");return eqIdx>=0?arg.slice(eqIdx+1):void 0}const flagIdx=args.findIndex((a)=>a===`--${name}`||a===`-${name.charAt(0)}`),value=flagIdx!==-1?args[flagIdx+1]:void 0;if(value&&!value.startsWith("-"))return value;return},hasFlag=(name)=>{return args.includes(`--${name}`)},name=getArg("name")||"OAuth Client",redirect=getArg("redirect")||"http://localhost",isPersonalAccess=hasFlag("personal"),isPasswordClient=hasFlag("password");log.info(`Creating OAuth client: ${name}`);const secret=randomBytes(40).toString("hex"),salt=randomBytes(16).toString("hex"),hashedSecret=`${salt}:${scryptSync(secret,salt,64).toString("hex")}`,result=await db.insertInto("oauth_clients").values({name,secret:hashedSecret,provider:"local",redirect,personal_access_client:isPersonalAccess,password_client:isPasswordClient,revoked:!1}).executeTakeFirst(),insertId=result?.insertId||Number(result?.numInsertedOrUpdatedRows);if(!insertId)throw new HttpError(500,"Failed to create OAuth client");log.success("OAuth client created successfully");log.info("");log.info("Client Details:");log.info(` Client ID: ${insertId}`);log.info(" Client Secret: [REDACTED]");process.stdout.write(`Client Secret (save now, shown once): ${secret}
|
|
2
|
+
`);log.info(` Redirect URI: ${redirect}`);log.info("");log.warn("Make sure to save the client secret. You will not be able to retrieve it again.");process.exit(0);
|
package/dist/auth/prune.js
CHANGED
|
@@ -1,35 +1 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
import { db, sql } from "@stacksjs/database";
|
|
3
|
-
import { log } from "@stacksjs/logging";
|
|
4
|
-
const args = process.argv.slice(2), hasFlag = (name) => {
|
|
5
|
-
return args.includes(`--${name}`);
|
|
6
|
-
}, getArg = (name) => {
|
|
7
|
-
const idx = args.findIndex((a) => a.startsWith(`--${name}=`) || a.startsWith(`-${name.charAt(0)}=`));
|
|
8
|
-
if (idx !== -1) {
|
|
9
|
-
const arg = args[idx];
|
|
10
|
-
if (!arg)
|
|
11
|
-
return;
|
|
12
|
-
const eqIdx = arg.indexOf("=");
|
|
13
|
-
return eqIdx >= 0 ? arg.slice(eqIdx + 1) : void 0;
|
|
14
|
-
}
|
|
15
|
-
const flagIdx = args.findIndex((a) => a === `--${name}` || a === `-${name.charAt(0)}`), value = flagIdx !== -1 ? args[flagIdx + 1] : void 0;
|
|
16
|
-
if (value && !value.startsWith("-"))
|
|
17
|
-
return value;
|
|
18
|
-
return;
|
|
19
|
-
}, pruneExpired = !hasFlag("no-expired"), pruneRevoked = !hasFlag("no-revoked"), daysOld = Number(getArg("days")) || 7;
|
|
20
|
-
log.info("Pruning authentication tokens...");
|
|
21
|
-
let expiredCount = 0, revokedCount = 0;
|
|
22
|
-
if (pruneExpired) {
|
|
23
|
-
log.info("Removing expired tokens...");
|
|
24
|
-
expiredCount = await db.deleteFrom("personal_access_tokens").where("expires_at", "<", sql.raw("NOW()")).execute();
|
|
25
|
-
log.success(`Removed ${expiredCount} expired token(s)`);
|
|
26
|
-
}
|
|
27
|
-
if (pruneRevoked) {
|
|
28
|
-
log.info(`Removing tokens revoked more than ${daysOld} day(s) ago...`);
|
|
29
|
-
const cutoffDate = new Date;
|
|
30
|
-
cutoffDate.setDate(cutoffDate.getDate() - daysOld);
|
|
31
|
-
revokedCount = await db.deleteFrom("personal_access_tokens").where("revoked_at", "is not", null).where("revoked_at", "<", cutoffDate.toISOString()).execute();
|
|
32
|
-
log.success(`Removed ${revokedCount} revoked token(s)`);
|
|
33
|
-
}
|
|
34
|
-
log.success(`Token pruning complete. Total removed: ${expiredCount + revokedCount}`);
|
|
35
|
-
process.exit(0);
|
|
1
|
+
import process from"node:process";import{db,sql}from"@stacksjs/database";import{log}from"@stacksjs/logging";const args=process.argv.slice(2),hasFlag=(name)=>{return args.includes(`--${name}`)},getArg=(name)=>{const idx=args.findIndex((a)=>a.startsWith(`--${name}=`)||a.startsWith(`-${name.charAt(0)}=`));if(idx!==-1){const arg=args[idx];if(!arg)return;const eqIdx=arg.indexOf("=");return eqIdx>=0?arg.slice(eqIdx+1):void 0}const flagIdx=args.findIndex((a)=>a===`--${name}`||a===`-${name.charAt(0)}`),value=flagIdx!==-1?args[flagIdx+1]:void 0;if(value&&!value.startsWith("-"))return value;return},pruneExpired=!hasFlag("no-expired"),pruneRevoked=!hasFlag("no-revoked"),daysOld=Number(getArg("days"))||7;log.info("Pruning authentication tokens...");let expiredCount=0,revokedCount=0;if(pruneExpired){log.info("Removing expired tokens...");expiredCount=await db.deleteFrom("personal_access_tokens").where("expires_at","<",sql.raw("NOW()")).execute();log.success(`Removed ${expiredCount} expired token(s)`)}if(pruneRevoked){log.info(`Removing tokens revoked more than ${daysOld} day(s) ago...`);const cutoffDate=new Date;cutoffDate.setDate(cutoffDate.getDate()-daysOld);revokedCount=await db.deleteFrom("personal_access_tokens").where("revoked_at","is not",null).where("revoked_at","<",cutoffDate.toISOString()).execute();log.success(`Removed ${revokedCount} revoked token(s)`)}log.success(`Token pruning complete. Total removed: ${expiredCount+revokedCount}`);process.exit(0);
|
package/dist/auth/setup.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
import { randomBytes } from "node:crypto";
|
|
3
|
-
import { db } from "@stacksjs/database";
|
|
4
|
-
import { log } from "@stacksjs/logging";
|
|
5
|
-
import { makeHash } from "@stacksjs/security";
|
|
6
|
-
import { env } from "@stacksjs/env";
|
|
7
|
-
import { sqlHelpers, usersEmailVerifiedAtSql, usersPasswordChangedAtSql } from "@stacksjs/database";
|
|
8
|
-
const dbDriver = env.DB_CONNECTION || "sqlite", sql = sqlHelpers(dbDriver), { isPostgres, isMysql, now, boolTrue, boolFalse: _boolFalse } = sql;
|
|
9
|
-
log.info("Setting up authentication...");
|
|
10
|
-
log.info(`Database driver: ${dbDriver}`);
|
|
11
|
-
log.info("Ensuring OAuth tables exist...");
|
|
12
|
-
try {
|
|
13
|
-
if (isPostgres)
|
|
14
|
-
await db.unsafe(`
|
|
1
|
+
import process from"node:process";import{randomBytes}from"node:crypto";import{db}from"@stacksjs/database";import{log}from"@stacksjs/logging";import{makeHash}from"@stacksjs/security";import{env}from"@stacksjs/env";import{sqlHelpers,usersEmailVerifiedAtSql,usersPasswordChangedAtSql}from"@stacksjs/database";const dbDriver=env.DB_CONNECTION||"sqlite",sql=sqlHelpers(dbDriver),{isPostgres,isMysql,now,boolTrue,boolFalse:_boolFalse}=sql;log.info("Setting up authentication...");log.info(`Database driver: ${dbDriver}`);log.info("Ensuring OAuth tables exist...");try{if(isPostgres)await db.unsafe(`
|
|
15
2
|
CREATE TABLE IF NOT EXISTS oauth_clients (
|
|
16
3
|
id SERIAL PRIMARY KEY,
|
|
17
4
|
name VARCHAR(255) NOT NULL,
|
|
@@ -24,9 +11,7 @@ try {
|
|
|
24
11
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
25
12
|
updated_at TIMESTAMP
|
|
26
13
|
)
|
|
27
|
-
`);
|
|
28
|
-
else if (isMysql)
|
|
29
|
-
await db.unsafe(`
|
|
14
|
+
`);else if(isMysql)await db.unsafe(`
|
|
30
15
|
CREATE TABLE IF NOT EXISTS oauth_clients (
|
|
31
16
|
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
32
17
|
name VARCHAR(255) NOT NULL,
|
|
@@ -39,9 +24,7 @@ try {
|
|
|
39
24
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
40
25
|
updated_at TIMESTAMP
|
|
41
26
|
)
|
|
42
|
-
`);
|
|
43
|
-
else
|
|
44
|
-
await db.unsafe(`
|
|
27
|
+
`);else await db.unsafe(`
|
|
45
28
|
CREATE TABLE IF NOT EXISTS oauth_clients (
|
|
46
29
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
47
30
|
name VARCHAR(255) NOT NULL,
|
|
@@ -54,9 +37,7 @@ try {
|
|
|
54
37
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
55
38
|
updated_at TIMESTAMP
|
|
56
39
|
)
|
|
57
|
-
`);
|
|
58
|
-
if (isPostgres)
|
|
59
|
-
await db.unsafe(`
|
|
40
|
+
`);if(isPostgres)await db.unsafe(`
|
|
60
41
|
CREATE TABLE IF NOT EXISTS oauth_access_tokens (
|
|
61
42
|
id SERIAL PRIMARY KEY,
|
|
62
43
|
user_id INTEGER NOT NULL,
|
|
@@ -69,9 +50,7 @@ try {
|
|
|
69
50
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
70
51
|
updated_at TIMESTAMP
|
|
71
52
|
)
|
|
72
|
-
`);
|
|
73
|
-
else if (isMysql)
|
|
74
|
-
await db.unsafe(`
|
|
53
|
+
`);else if(isMysql)await db.unsafe(`
|
|
75
54
|
CREATE TABLE IF NOT EXISTS oauth_access_tokens (
|
|
76
55
|
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
77
56
|
user_id INTEGER NOT NULL,
|
|
@@ -84,9 +63,7 @@ try {
|
|
|
84
63
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
85
64
|
updated_at TIMESTAMP NULL
|
|
86
65
|
)
|
|
87
|
-
`);
|
|
88
|
-
else
|
|
89
|
-
await db.unsafe(`
|
|
66
|
+
`);else await db.unsafe(`
|
|
90
67
|
CREATE TABLE IF NOT EXISTS oauth_access_tokens (
|
|
91
68
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
92
69
|
user_id INTEGER NOT NULL,
|
|
@@ -99,12 +76,9 @@ try {
|
|
|
99
76
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
100
77
|
updated_at TIMESTAMP
|
|
101
78
|
)
|
|
102
|
-
`);
|
|
103
|
-
await db.unsafe(`
|
|
79
|
+
`);await db.unsafe(`
|
|
104
80
|
CREATE INDEX IF NOT EXISTS idx_oauth_access_tokens_token ON oauth_access_tokens(token)
|
|
105
|
-
`);
|
|
106
|
-
if (isPostgres)
|
|
107
|
-
await db.unsafe(`
|
|
81
|
+
`);if(isPostgres)await db.unsafe(`
|
|
108
82
|
CREATE TABLE IF NOT EXISTS oauth_refresh_tokens (
|
|
109
83
|
id SERIAL PRIMARY KEY,
|
|
110
84
|
access_token_id INTEGER NOT NULL,
|
|
@@ -113,9 +87,7 @@ try {
|
|
|
113
87
|
expires_at TIMESTAMP,
|
|
114
88
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
115
89
|
)
|
|
116
|
-
`);
|
|
117
|
-
else if (isMysql)
|
|
118
|
-
await db.unsafe(`
|
|
90
|
+
`);else if(isMysql)await db.unsafe(`
|
|
119
91
|
CREATE TABLE IF NOT EXISTS oauth_refresh_tokens (
|
|
120
92
|
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
121
93
|
access_token_id INTEGER NOT NULL,
|
|
@@ -124,9 +96,7 @@ try {
|
|
|
124
96
|
expires_at TIMESTAMP NULL,
|
|
125
97
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
126
98
|
)
|
|
127
|
-
`);
|
|
128
|
-
else
|
|
129
|
-
await db.unsafe(`
|
|
99
|
+
`);else await db.unsafe(`
|
|
130
100
|
CREATE TABLE IF NOT EXISTS oauth_refresh_tokens (
|
|
131
101
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
132
102
|
access_token_id INTEGER NOT NULL,
|
|
@@ -135,19 +105,9 @@ try {
|
|
|
135
105
|
expires_at TIMESTAMP,
|
|
136
106
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
137
107
|
)
|
|
138
|
-
`);
|
|
139
|
-
await db.unsafe(`
|
|
108
|
+
`);await db.unsafe(`
|
|
140
109
|
CREATE INDEX IF NOT EXISTS idx_oauth_refresh_tokens_token ON oauth_refresh_tokens(token)
|
|
141
|
-
`);
|
|
142
|
-
log.success("OAuth tables ready");
|
|
143
|
-
} catch (error) {
|
|
144
|
-
log.error("Failed to create OAuth tables", error);
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
log.info("Ensuring password_resets table exists...");
|
|
148
|
-
try {
|
|
149
|
-
if (isPostgres)
|
|
150
|
-
await db.unsafe(`
|
|
110
|
+
`);log.success("OAuth tables ready")}catch(error){log.error("Failed to create OAuth tables",error);process.exit(1)}log.info("Ensuring password_resets table exists...");try{if(isPostgres)await db.unsafe(`
|
|
151
111
|
CREATE TABLE IF NOT EXISTS password_resets (
|
|
152
112
|
id SERIAL PRIMARY KEY,
|
|
153
113
|
email VARCHAR(255) NOT NULL,
|
|
@@ -155,9 +115,7 @@ try {
|
|
|
155
115
|
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
156
116
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
157
117
|
)
|
|
158
|
-
`);
|
|
159
|
-
else if (isMysql)
|
|
160
|
-
await db.unsafe(`
|
|
118
|
+
`);else if(isMysql)await db.unsafe(`
|
|
161
119
|
CREATE TABLE IF NOT EXISTS password_resets (
|
|
162
120
|
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
163
121
|
email VARCHAR(255) NOT NULL,
|
|
@@ -165,9 +123,7 @@ try {
|
|
|
165
123
|
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
166
124
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
167
125
|
)
|
|
168
|
-
`);
|
|
169
|
-
else
|
|
170
|
-
await db.unsafe(`
|
|
126
|
+
`);else await db.unsafe(`
|
|
171
127
|
CREATE TABLE IF NOT EXISTS password_resets (
|
|
172
128
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
173
129
|
email VARCHAR(255) NOT NULL,
|
|
@@ -175,25 +131,9 @@ try {
|
|
|
175
131
|
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
176
132
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
177
133
|
)
|
|
178
|
-
`);
|
|
179
|
-
try {
|
|
180
|
-
if (isPostgres)
|
|
181
|
-
await db.unsafe("ALTER TABLE password_resets ADD COLUMN IF NOT EXISTS expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");
|
|
182
|
-
else
|
|
183
|
-
await db.unsafe("ALTER TABLE password_resets ADD COLUMN expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");
|
|
184
|
-
} catch {}
|
|
185
|
-
await db.unsafe(`
|
|
134
|
+
`);try{if(isPostgres)await db.unsafe("ALTER TABLE password_resets ADD COLUMN IF NOT EXISTS expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");else await db.unsafe("ALTER TABLE password_resets ADD COLUMN expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP")}catch{}await db.unsafe(`
|
|
186
135
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_password_resets_email_unique ON password_resets(email)
|
|
187
|
-
`);
|
|
188
|
-
log.success("Password resets table ready");
|
|
189
|
-
} catch (error) {
|
|
190
|
-
log.error("Failed to create password_resets table", error);
|
|
191
|
-
process.exit(1);
|
|
192
|
-
}
|
|
193
|
-
log.info("Ensuring email_verifications table exists...");
|
|
194
|
-
try {
|
|
195
|
-
if (isPostgres)
|
|
196
|
-
await db.unsafe(`
|
|
136
|
+
`);log.success("Password resets table ready")}catch(error){log.error("Failed to create password_resets table",error);process.exit(1)}log.info("Ensuring email_verifications table exists...");try{if(isPostgres)await db.unsafe(`
|
|
197
137
|
CREATE TABLE IF NOT EXISTS email_verifications (
|
|
198
138
|
id SERIAL PRIMARY KEY,
|
|
199
139
|
user_id INTEGER NOT NULL,
|
|
@@ -201,9 +141,7 @@ try {
|
|
|
201
141
|
expires_at TIMESTAMP NOT NULL,
|
|
202
142
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
203
143
|
)
|
|
204
|
-
`);
|
|
205
|
-
else if (isMysql)
|
|
206
|
-
await db.unsafe(`
|
|
144
|
+
`);else if(isMysql)await db.unsafe(`
|
|
207
145
|
CREATE TABLE IF NOT EXISTS email_verifications (
|
|
208
146
|
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
209
147
|
user_id INTEGER NOT NULL,
|
|
@@ -211,9 +149,7 @@ try {
|
|
|
211
149
|
expires_at TIMESTAMP NOT NULL,
|
|
212
150
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
213
151
|
)
|
|
214
|
-
`);
|
|
215
|
-
else
|
|
216
|
-
await db.unsafe(`
|
|
152
|
+
`);else await db.unsafe(`
|
|
217
153
|
CREATE TABLE IF NOT EXISTS email_verifications (
|
|
218
154
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
219
155
|
user_id INTEGER NOT NULL,
|
|
@@ -221,25 +157,9 @@ try {
|
|
|
221
157
|
expires_at TIMESTAMP NOT NULL,
|
|
222
158
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
223
159
|
)
|
|
224
|
-
`);
|
|
225
|
-
await db.unsafe(`
|
|
160
|
+
`);await db.unsafe(`
|
|
226
161
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_email_verifications_user_id_unique ON email_verifications(user_id)
|
|
227
|
-
`);
|
|
228
|
-
try {
|
|
229
|
-
await db.unsafe(usersEmailVerifiedAtSql(sql));
|
|
230
|
-
} catch {}
|
|
231
|
-
try {
|
|
232
|
-
await db.unsafe(usersPasswordChangedAtSql(sql));
|
|
233
|
-
} catch {}
|
|
234
|
-
log.success("Email verifications table ready");
|
|
235
|
-
} catch (error) {
|
|
236
|
-
log.error("Failed to create email_verifications table", error);
|
|
237
|
-
process.exit(1);
|
|
238
|
-
}
|
|
239
|
-
log.info("Ensuring webauthn_challenges table exists...");
|
|
240
|
-
try {
|
|
241
|
-
if (isPostgres)
|
|
242
|
-
await db.unsafe(`
|
|
162
|
+
`);try{await db.unsafe(usersEmailVerifiedAtSql(sql))}catch{}try{await db.unsafe(usersPasswordChangedAtSql(sql))}catch{}log.success("Email verifications table ready")}catch(error){log.error("Failed to create email_verifications table",error);process.exit(1)}log.info("Ensuring webauthn_challenges table exists...");try{if(isPostgres)await db.unsafe(`
|
|
243
163
|
CREATE TABLE IF NOT EXISTS webauthn_challenges (
|
|
244
164
|
id SERIAL PRIMARY KEY,
|
|
245
165
|
user_id INTEGER NOT NULL,
|
|
@@ -248,9 +168,7 @@ try {
|
|
|
248
168
|
expires_at TIMESTAMP NOT NULL,
|
|
249
169
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
250
170
|
)
|
|
251
|
-
`);
|
|
252
|
-
else if (isMysql)
|
|
253
|
-
await db.unsafe(`
|
|
171
|
+
`);else if(isMysql)await db.unsafe(`
|
|
254
172
|
CREATE TABLE IF NOT EXISTS webauthn_challenges (
|
|
255
173
|
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
256
174
|
user_id INTEGER NOT NULL,
|
|
@@ -259,9 +177,7 @@ try {
|
|
|
259
177
|
expires_at TIMESTAMP NOT NULL,
|
|
260
178
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
261
179
|
)
|
|
262
|
-
`);
|
|
263
|
-
else
|
|
264
|
-
await db.unsafe(`
|
|
180
|
+
`);else await db.unsafe(`
|
|
265
181
|
CREATE TABLE IF NOT EXISTS webauthn_challenges (
|
|
266
182
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
267
183
|
user_id INTEGER NOT NULL,
|
|
@@ -270,56 +186,20 @@ try {
|
|
|
270
186
|
expires_at TIMESTAMP NOT NULL,
|
|
271
187
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
272
188
|
)
|
|
273
|
-
`);
|
|
274
|
-
await db.unsafe(`
|
|
189
|
+
`);await db.unsafe(`
|
|
275
190
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_webauthn_challenges_user_purpose ON webauthn_challenges(user_id, purpose)
|
|
276
|
-
`);
|
|
277
|
-
log.success("WebAuthn challenges table ready");
|
|
278
|
-
} catch (error) {
|
|
279
|
-
log.error("Failed to create webauthn_challenges table", error);
|
|
280
|
-
process.exit(1);
|
|
281
|
-
}
|
|
282
|
-
log.info("Creating personal access client...");
|
|
283
|
-
try {
|
|
284
|
-
if ((await db.unsafe(`
|
|
191
|
+
`);log.success("WebAuthn challenges table ready")}catch(error){log.error("Failed to create webauthn_challenges table",error);process.exit(1)}log.info("Creating personal access client...");try{if((await db.unsafe(`
|
|
285
192
|
SELECT id FROM oauth_clients WHERE personal_access_client = ${boolTrue} LIMIT 1
|
|
286
|
-
`))?.length
|
|
287
|
-
|
|
288
|
-
\u2713 Personal access client already exists`);
|
|
289
|
-
else {
|
|
290
|
-
const secret = randomBytes(40).toString("hex"), hashedSecret = await makeHash(secret, { algorithm: "bcrypt" });
|
|
291
|
-
if (isPostgres)
|
|
292
|
-
await db.unsafe(`
|
|
193
|
+
`))?.length>0)console.log(`
|
|
194
|
+
\u2713 Personal access client already exists`);else{const secret=randomBytes(40).toString("hex"),hashedSecret=await makeHash(secret,{algorithm:"bcrypt"});if(isPostgres)await db.unsafe(`
|
|
293
195
|
INSERT INTO oauth_clients (name, secret, provider, redirect, personal_access_client, password_client, revoked, created_at)
|
|
294
196
|
VALUES ($1, $2, $3, $4, $5, $6, $7, NOW())
|
|
295
|
-
`,
|
|
296
|
-
else
|
|
297
|
-
await db.unsafe(`
|
|
197
|
+
`,["Personal Access Client",hashedSecret,"local","http://localhost",!0,!1,!1]);else await db.unsafe(`
|
|
298
198
|
INSERT INTO oauth_clients (name, secret, provider, redirect, personal_access_client, password_client, revoked, created_at)
|
|
299
199
|
VALUES (?, ?, ?, ?, ?, ?, ?, ${now})
|
|
300
|
-
`,
|
|
301
|
-
|
|
302
|
-
\u2713
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
process.exit(1);
|
|
307
|
-
}
|
|
308
|
-
console.log(`
|
|
309
|
-
\u2713 Authentication setup complete!`);
|
|
310
|
-
console.log(`
|
|
311
|
-
Features enabled:`);
|
|
312
|
-
console.log(" - Token hashing (SHA-256) for secure storage");
|
|
313
|
-
console.log(" - Refresh tokens for seamless token renewal");
|
|
314
|
-
console.log(" - Scope-based authorization");
|
|
315
|
-
console.log(" - Password reset flow");
|
|
316
|
-
console.log(`
|
|
317
|
-
Next steps:`);
|
|
318
|
-
console.log(" 1. Use createToken(userId, name, scopes) to generate tokens");
|
|
319
|
-
console.log(" 2. Use refreshToken(token) to exchange refresh tokens");
|
|
320
|
-
console.log(' 3. Use the "auth" middleware to protect routes');
|
|
321
|
-
console.log(" 4. Use tokenCan(scope) for authorization checks");
|
|
322
|
-
console.log(" 5. POST /password/forgot to request password reset");
|
|
323
|
-
console.log(` 6. POST /password/reset to reset password with token
|
|
324
|
-
`);
|
|
325
|
-
process.exit(0);
|
|
200
|
+
`,["Personal Access Client",hashedSecret,"local","http://localhost",1,0,0]);console.log(`
|
|
201
|
+
\u2713 Personal access client created successfully`)}}catch(error){console.error("Failed to create personal access client:",error);process.exit(1)}console.log(`
|
|
202
|
+
\u2713 Authentication setup complete!`);console.log(`
|
|
203
|
+
Features enabled:`);console.log(" - Token hashing (SHA-256) for secure storage");console.log(" - Refresh tokens for seamless token renewal");console.log(" - Scope-based authorization");console.log(" - Password reset flow");console.log(`
|
|
204
|
+
Next steps:`);console.log(" 1. Use createToken(userId, name, scopes) to generate tokens");console.log(" 2. Use refreshToken(token) to exchange refresh tokens");console.log(' 3. Use the "auth" middleware to protect routes');console.log(" 4. Use tokenCan(scope) for authorization checks");console.log(" 5. POST /password/forgot to request password reset");console.log(` 6. POST /password/reset to reset password with token
|
|
205
|
+
`);process.exit(0);
|
package/dist/auth/token.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
import { createPersonalAccessClient } from "@stacksjs/auth";
|
|
3
|
-
import { log } from "@stacksjs/logging";
|
|
4
|
-
const result = await createPersonalAccessClient();
|
|
5
|
-
if (result?.isErr) {
|
|
6
|
-
console.error(result.error);
|
|
7
|
-
log.error("createPersonalAccessClient failed", result.error);
|
|
8
|
-
process.exit(1);
|
|
9
|
-
}
|
|
10
|
-
process.exit(0);
|
|
1
|
+
import process from"node:process";import{createPersonalAccessClient}from"@stacksjs/auth";import{log}from"@stacksjs/logging";const result=await createPersonalAccessClient();if(result?.isErr){console.error(result.error);log.error("createPersonalAccessClient failed",result.error);process.exit(1)}process.exit(0);
|