-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): runtime setting support
- Loading branch information
Showing
115 changed files
with
1,761 additions
and
1,018 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/backend/server/migrations/20240520055805_runtime_setting/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- CreateEnum | ||
CREATE TYPE "RuntimeConfigType" AS ENUM ('String', 'Number', 'Boolean', 'Object', 'Array'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "app_runtime_settings" ( | ||
"id" VARCHAR NOT NULL, | ||
"type" "RuntimeConfigType" NOT NULL, | ||
"module" VARCHAR NOT NULL, | ||
"key" VARCHAR NOT NULL, | ||
"value" JSON NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"updated_at" TIMESTAMPTZ(6) NOT NULL, | ||
"deleted_at" TIMESTAMPTZ(6), | ||
"last_updated_by" VARCHAR(36), | ||
|
||
CONSTRAINT "app_runtime_settings_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "app_runtime_settings_module_key_key" ON "app_runtime_settings"("module", "key"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "app_runtime_settings" ADD CONSTRAINT "app_runtime_settings_last_updated_by_fkey" FOREIGN KEY ("last_updated_by") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" | ||
provider = "postgresql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
defineRuntimeConfig, | ||
defineStartupConfig, | ||
ModuleConfig, | ||
} from '../../fundamentals/config'; | ||
|
||
export interface AuthStartupConfigurations { | ||
/** | ||
* auth session config | ||
*/ | ||
session: { | ||
/** | ||
* Application auth expiration time in seconds | ||
*/ | ||
ttl: number; | ||
/** | ||
* Application auth time to refresh in seconds | ||
*/ | ||
ttr: number; | ||
}; | ||
|
||
/** | ||
* Application access token config | ||
*/ | ||
accessToken: { | ||
/** | ||
* Application access token expiration time in seconds | ||
*/ | ||
ttl: number; | ||
/** | ||
* Application refresh token expiration time in seconds | ||
*/ | ||
refreshTokenTtl: number; | ||
}; | ||
} | ||
|
||
export interface AuthRuntimeConfigurations { | ||
/** | ||
* Whether allow anonymous users to sign up | ||
*/ | ||
allowSignup: boolean; | ||
/** | ||
* The minimum and maximum length of the password when registering new users | ||
*/ | ||
password: { | ||
min: number; | ||
max: number; | ||
}; | ||
} | ||
|
||
declare module '../../fundamentals/config' { | ||
interface AppConfig { | ||
auth: ModuleConfig<AuthStartupConfigurations, AuthRuntimeConfigurations>; | ||
} | ||
} | ||
|
||
defineStartupConfig('auth', { | ||
session: { | ||
ttl: 60 * 60 * 24 * 15, // 15 days | ||
ttr: 60 * 60 * 24 * 7, // 7 days | ||
}, | ||
accessToken: { | ||
ttl: 60 * 60 * 24 * 7, // 7 days | ||
refreshTokenTtl: 60 * 60 * 24 * 30, // 30 days | ||
}, | ||
}); | ||
|
||
defineRuntimeConfig('auth', { | ||
allowSignup: { | ||
desc: 'Whether allow new registrations', | ||
default: true, | ||
}, | ||
'password.min': { | ||
desc: 'The minimum length of user password', | ||
default: 8, | ||
}, | ||
'password.max': { | ||
desc: 'The maximum length of user password', | ||
default: 32, | ||
}, | ||
}); |
Oops, something went wrong.