@os.io/nest-kit 0.0.1-alpha.0
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 +21 -0
- package/README.md +111 -0
- package/dist/auth/auth.constants.d.ts +19 -0
- package/dist/auth/auth.constants.d.ts.map +1 -0
- package/dist/auth/auth.constants.js +19 -0
- package/dist/auth/auth.constants.js.map +1 -0
- package/dist/auth/auth.guard.d.ts +20 -0
- package/dist/auth/auth.guard.d.ts.map +1 -0
- package/dist/auth/auth.guard.js +84 -0
- package/dist/auth/auth.guard.js.map +1 -0
- package/dist/auth/auth.module.d.ts +26 -0
- package/dist/auth/auth.module.d.ts.map +1 -0
- package/dist/auth/auth.module.js +344 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/auth/auth.options.d.ts +179 -0
- package/dist/auth/auth.options.d.ts.map +1 -0
- package/dist/auth/auth.options.js +2 -0
- package/dist/auth/auth.options.js.map +1 -0
- package/dist/auth/auth.service.d.ts +57 -0
- package/dist/auth/auth.service.d.ts.map +1 -0
- package/dist/auth/auth.service.js +175 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/auth/authorization/index.d.ts +3 -0
- package/dist/auth/authorization/index.d.ts.map +1 -0
- package/dist/auth/authorization/index.js +3 -0
- package/dist/auth/authorization/index.js.map +1 -0
- package/dist/auth/authorization/pbac/index.d.ts +6 -0
- package/dist/auth/authorization/pbac/index.d.ts.map +1 -0
- package/dist/auth/authorization/pbac/index.js +4 -0
- package/dist/auth/authorization/pbac/index.js.map +1 -0
- package/dist/auth/authorization/pbac/pbac.decorator.d.ts +18 -0
- package/dist/auth/authorization/pbac/pbac.decorator.d.ts.map +1 -0
- package/dist/auth/authorization/pbac/pbac.decorator.js +14 -0
- package/dist/auth/authorization/pbac/pbac.decorator.js.map +1 -0
- package/dist/auth/authorization/pbac/pbac.guard.d.ts +19 -0
- package/dist/auth/authorization/pbac/pbac.guard.d.ts.map +1 -0
- package/dist/auth/authorization/pbac/pbac.guard.js +60 -0
- package/dist/auth/authorization/pbac/pbac.guard.js.map +1 -0
- package/dist/auth/authorization/pbac/pbac.service.d.ts +44 -0
- package/dist/auth/authorization/pbac/pbac.service.d.ts.map +1 -0
- package/dist/auth/authorization/pbac/pbac.service.js +146 -0
- package/dist/auth/authorization/pbac/pbac.service.js.map +1 -0
- package/dist/auth/authorization/pbac/pbac.types.d.ts +47 -0
- package/dist/auth/authorization/pbac/pbac.types.d.ts.map +1 -0
- package/dist/auth/authorization/pbac/pbac.types.js +2 -0
- package/dist/auth/authorization/pbac/pbac.types.js.map +1 -0
- package/dist/auth/authorization/rbac/index.d.ts +4 -0
- package/dist/auth/authorization/rbac/index.d.ts.map +1 -0
- package/dist/auth/authorization/rbac/index.js +4 -0
- package/dist/auth/authorization/rbac/index.js.map +1 -0
- package/dist/auth/authorization/rbac/rbac.decorator.d.ts +18 -0
- package/dist/auth/authorization/rbac/rbac.decorator.d.ts.map +1 -0
- package/dist/auth/authorization/rbac/rbac.decorator.js +25 -0
- package/dist/auth/authorization/rbac/rbac.decorator.js.map +1 -0
- package/dist/auth/authorization/rbac/rbac.guard.d.ts +19 -0
- package/dist/auth/authorization/rbac/rbac.guard.d.ts.map +1 -0
- package/dist/auth/authorization/rbac/rbac.guard.js +50 -0
- package/dist/auth/authorization/rbac/rbac.guard.js.map +1 -0
- package/dist/auth/authorization/rbac/rbac.service.d.ts +43 -0
- package/dist/auth/authorization/rbac/rbac.service.d.ts.map +1 -0
- package/dist/auth/authorization/rbac/rbac.service.js +95 -0
- package/dist/auth/authorization/rbac/rbac.service.js.map +1 -0
- package/dist/auth/decorators/current-user.decorator.d.ts +17 -0
- package/dist/auth/decorators/current-user.decorator.d.ts.map +1 -0
- package/dist/auth/decorators/current-user.decorator.js +23 -0
- package/dist/auth/decorators/current-user.decorator.js.map +1 -0
- package/dist/auth/decorators/index.d.ts +3 -0
- package/dist/auth/decorators/index.d.ts.map +1 -0
- package/dist/auth/decorators/index.js +3 -0
- package/dist/auth/decorators/index.js.map +1 -0
- package/dist/auth/decorators/public.decorator.d.ts +13 -0
- package/dist/auth/decorators/public.decorator.d.ts.map +1 -0
- package/dist/auth/decorators/public.decorator.js +15 -0
- package/dist/auth/decorators/public.decorator.js.map +1 -0
- package/dist/auth/index.d.ts +63 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +65 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/interfaces/auth-request.interface.d.ts +18 -0
- package/dist/auth/interfaces/auth-request.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/auth-request.interface.js +2 -0
- package/dist/auth/interfaces/auth-request.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-result.interface.d.ts +28 -0
- package/dist/auth/interfaces/auth-result.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/auth-result.interface.js +2 -0
- package/dist/auth/interfaces/auth-result.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-strategy.interface.d.ts +37 -0
- package/dist/auth/interfaces/auth-strategy.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/auth-strategy.interface.js +16 -0
- package/dist/auth/interfaces/auth-strategy.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-user.interface.d.ts +25 -0
- package/dist/auth/interfaces/auth-user.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/auth-user.interface.js +2 -0
- package/dist/auth/interfaces/auth-user.interface.js.map +1 -0
- package/dist/auth/interfaces/cache-service.interface.d.ts +30 -0
- package/dist/auth/interfaces/cache-service.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/cache-service.interface.js +2 -0
- package/dist/auth/interfaces/cache-service.interface.js.map +1 -0
- package/dist/auth/interfaces/index.d.ts +8 -0
- package/dist/auth/interfaces/index.d.ts.map +1 -0
- package/dist/auth/interfaces/index.js +2 -0
- package/dist/auth/interfaces/index.js.map +1 -0
- package/dist/auth/interfaces/user-service.interface.d.ts +34 -0
- package/dist/auth/interfaces/user-service.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/user-service.interface.js +2 -0
- package/dist/auth/interfaces/user-service.interface.js.map +1 -0
- package/dist/auth/password/password.service.d.ts +23 -0
- package/dist/auth/password/password.service.d.ts.map +1 -0
- package/dist/auth/password/password.service.js +52 -0
- package/dist/auth/password/password.service.js.map +1 -0
- package/dist/auth/session/device-session.service.d.ts +43 -0
- package/dist/auth/session/device-session.service.d.ts.map +1 -0
- package/dist/auth/session/device-session.service.js +72 -0
- package/dist/auth/session/device-session.service.js.map +1 -0
- package/dist/auth/session/index.d.ts +5 -0
- package/dist/auth/session/index.d.ts.map +1 -0
- package/dist/auth/session/index.js +4 -0
- package/dist/auth/session/index.js.map +1 -0
- package/dist/auth/session/jwt.service.d.ts +37 -0
- package/dist/auth/session/jwt.service.d.ts.map +1 -0
- package/dist/auth/session/jwt.service.js +119 -0
- package/dist/auth/session/jwt.service.js.map +1 -0
- package/dist/auth/session/token-blacklist.service.d.ts +37 -0
- package/dist/auth/session/token-blacklist.service.d.ts.map +1 -0
- package/dist/auth/session/token-blacklist.service.js +70 -0
- package/dist/auth/session/token-blacklist.service.js.map +1 -0
- package/dist/auth/strategies/anonymous/anonymous.strategy.d.ts +19 -0
- package/dist/auth/strategies/anonymous/anonymous.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/anonymous/anonymous.strategy.js +49 -0
- package/dist/auth/strategies/anonymous/anonymous.strategy.js.map +1 -0
- package/dist/auth/strategies/base/base.strategy.d.ts +11 -0
- package/dist/auth/strategies/base/base.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/base/base.strategy.js +6 -0
- package/dist/auth/strategies/base/base.strategy.js.map +1 -0
- package/dist/auth/strategies/credentials/credentials.strategy.d.ts +21 -0
- package/dist/auth/strategies/credentials/credentials.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/credentials/credentials.strategy.js +67 -0
- package/dist/auth/strategies/credentials/credentials.strategy.js.map +1 -0
- package/dist/auth/strategies/index.d.ts +12 -0
- package/dist/auth/strategies/index.d.ts.map +1 -0
- package/dist/auth/strategies/index.js +12 -0
- package/dist/auth/strategies/index.js.map +1 -0
- package/dist/auth/strategies/magic-link/magic-link.strategy.d.ts +31 -0
- package/dist/auth/strategies/magic-link/magic-link.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/magic-link/magic-link.strategy.js +88 -0
- package/dist/auth/strategies/magic-link/magic-link.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/index.d.ts +3 -0
- package/dist/auth/strategies/oauth/index.d.ts.map +1 -0
- package/dist/auth/strategies/oauth/index.js +3 -0
- package/dist/auth/strategies/oauth/index.js.map +1 -0
- package/dist/auth/strategies/oauth/oauth-provider-registry.d.ts +13 -0
- package/dist/auth/strategies/oauth/oauth-provider-registry.d.ts.map +1 -0
- package/dist/auth/strategies/oauth/oauth-provider-registry.js +20 -0
- package/dist/auth/strategies/oauth/oauth-provider-registry.js.map +1 -0
- package/dist/auth/strategies/oauth/oauth.strategy.d.ts +23 -0
- package/dist/auth/strategies/oauth/oauth.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/oauth/oauth.strategy.js +79 -0
- package/dist/auth/strategies/oauth/oauth.strategy.js.map +1 -0
- package/dist/auth/strategies/onetap/onetap.strategy.d.ts +24 -0
- package/dist/auth/strategies/onetap/onetap.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/onetap/onetap.strategy.js +77 -0
- package/dist/auth/strategies/onetap/onetap.strategy.js.map +1 -0
- package/dist/auth/strategies/otp/otp.strategy.d.ts +31 -0
- package/dist/auth/strategies/otp/otp.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/otp/otp.strategy.js +93 -0
- package/dist/auth/strategies/otp/otp.strategy.js.map +1 -0
- package/dist/auth/strategies/passkey/passkey.strategy.d.ts +32 -0
- package/dist/auth/strategies/passkey/passkey.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/passkey/passkey.strategy.js +102 -0
- package/dist/auth/strategies/passkey/passkey.strategy.js.map +1 -0
- package/dist/auth/strategies/sso/sso.strategy.d.ts +25 -0
- package/dist/auth/strategies/sso/sso.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/sso/sso.strategy.js +80 -0
- package/dist/auth/strategies/sso/sso.strategy.js.map +1 -0
- package/dist/auth/strategies/totp/totp.strategy.d.ts +37 -0
- package/dist/auth/strategies/totp/totp.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/totp/totp.strategy.js +109 -0
- package/dist/auth/strategies/totp/totp.strategy.js.map +1 -0
- package/dist/auth/throttling/index.d.ts +2 -0
- package/dist/auth/throttling/index.d.ts.map +1 -0
- package/dist/auth/throttling/index.js +2 -0
- package/dist/auth/throttling/index.js.map +1 -0
- package/dist/auth/throttling/throttle.service.d.ts +27 -0
- package/dist/auth/throttling/throttle.service.d.ts.map +1 -0
- package/dist/auth/throttling/throttle.service.js +63 -0
- package/dist/auth/throttling/throttle.service.js.map +1 -0
- package/dist/bootstrap/cache/config.d.ts +135 -0
- package/dist/bootstrap/cache/config.d.ts.map +1 -0
- package/dist/bootstrap/cache/config.js +189 -0
- package/dist/bootstrap/cache/config.js.map +1 -0
- package/dist/bootstrap/cache/index.d.ts +11 -0
- package/dist/bootstrap/cache/index.d.ts.map +1 -0
- package/dist/bootstrap/cache/index.js +11 -0
- package/dist/bootstrap/cache/index.js.map +1 -0
- package/dist/bootstrap/index.d.ts +21 -0
- package/dist/bootstrap/index.d.ts.map +1 -0
- package/dist/bootstrap/index.js +21 -0
- package/dist/bootstrap/index.js.map +1 -0
- package/dist/bootstrap/scalar/api-docs.d.ts +39 -0
- package/dist/bootstrap/scalar/api-docs.d.ts.map +1 -0
- package/dist/bootstrap/scalar/api-docs.js +41 -0
- package/dist/bootstrap/scalar/api-docs.js.map +1 -0
- package/dist/bootstrap/scalar/index.d.ts +39 -0
- package/dist/bootstrap/scalar/index.d.ts.map +1 -0
- package/dist/bootstrap/scalar/index.js +41 -0
- package/dist/bootstrap/scalar/index.js.map +1 -0
- package/dist/bootstrap/swagger/api-docs.d.ts +73 -0
- package/dist/bootstrap/swagger/api-docs.d.ts.map +1 -0
- package/dist/bootstrap/swagger/api-docs.js +87 -0
- package/dist/bootstrap/swagger/api-docs.js.map +1 -0
- package/dist/bootstrap/swagger/index.d.ts +37 -0
- package/dist/bootstrap/swagger/index.d.ts.map +1 -0
- package/dist/bootstrap/swagger/index.js +36 -0
- package/dist/bootstrap/swagger/index.js.map +1 -0
- package/dist/bootstrap/typeorm/config/index.d.ts +12 -0
- package/dist/bootstrap/typeorm/config/index.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/config/index.js +62 -0
- package/dist/bootstrap/typeorm/config/index.js.map +1 -0
- package/dist/bootstrap/typeorm/crud/controller.d.ts +13 -0
- package/dist/bootstrap/typeorm/crud/controller.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/crud/controller.js +72 -0
- package/dist/bootstrap/typeorm/crud/controller.js.map +1 -0
- package/dist/bootstrap/typeorm/crud/index.d.ts +4 -0
- package/dist/bootstrap/typeorm/crud/index.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/crud/index.js +3 -0
- package/dist/bootstrap/typeorm/crud/index.js.map +1 -0
- package/dist/bootstrap/typeorm/crud/service.d.ts +10 -0
- package/dist/bootstrap/typeorm/crud/service.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/crud/service.js +21 -0
- package/dist/bootstrap/typeorm/crud/service.js.map +1 -0
- package/dist/bootstrap/typeorm/index.d.ts +18 -0
- package/dist/bootstrap/typeorm/index.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/index.js +18 -0
- package/dist/bootstrap/typeorm/index.js.map +1 -0
- package/dist/bootstrap/typeorm/uow/factory.d.ts +5 -0
- package/dist/bootstrap/typeorm/uow/factory.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/uow/factory.js +27 -0
- package/dist/bootstrap/typeorm/uow/factory.js.map +1 -0
- package/dist/bootstrap/typeorm/uow/index.d.ts +4 -0
- package/dist/bootstrap/typeorm/uow/index.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/uow/index.js +4 -0
- package/dist/bootstrap/typeorm/uow/index.js.map +1 -0
- package/dist/bootstrap/typeorm/uow/transactional.decorator.d.ts +62 -0
- package/dist/bootstrap/typeorm/uow/transactional.decorator.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/uow/transactional.decorator.js +114 -0
- package/dist/bootstrap/typeorm/uow/transactional.decorator.js.map +1 -0
- package/dist/bootstrap/typeorm/uow/unit-of-work.d.ts +11 -0
- package/dist/bootstrap/typeorm/uow/unit-of-work.d.ts.map +1 -0
- package/dist/bootstrap/typeorm/uow/unit-of-work.js +23 -0
- package/dist/bootstrap/typeorm/uow/unit-of-work.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -0
- package/dist/infra/audit-log/index.d.ts +12 -0
- package/dist/infra/audit-log/index.d.ts.map +1 -0
- package/dist/infra/audit-log/index.js +13 -0
- package/dist/infra/audit-log/index.js.map +1 -0
- package/dist/infra/index.d.ts +20 -0
- package/dist/infra/index.d.ts.map +1 -0
- package/dist/infra/index.js +21 -0
- package/dist/infra/index.js.map +1 -0
- package/dist/infra/logger/index.d.ts +12 -0
- package/dist/infra/logger/index.d.ts.map +1 -0
- package/dist/infra/logger/index.js +13 -0
- package/dist/infra/logger/index.js.map +1 -0
- package/dist/infra/metrics/index.d.ts +18 -0
- package/dist/infra/metrics/index.d.ts.map +1 -0
- package/dist/infra/metrics/index.js +19 -0
- package/dist/infra/metrics/index.js.map +1 -0
- package/dist/infra/notification/index.d.ts +12 -0
- package/dist/infra/notification/index.d.ts.map +1 -0
- package/dist/infra/notification/index.js +13 -0
- package/dist/infra/notification/index.js.map +1 -0
- package/dist/infra/storage/index.d.ts +12 -0
- package/dist/infra/storage/index.d.ts.map +1 -0
- package/dist/infra/storage/index.js +13 -0
- package/dist/infra/storage/index.js.map +1 -0
- package/dist/infra/stripe/index.d.ts +12 -0
- package/dist/infra/stripe/index.d.ts.map +1 -0
- package/dist/infra/stripe/index.js +13 -0
- package/dist/infra/stripe/index.js.map +1 -0
- package/dist/saas/index.d.ts +18 -0
- package/dist/saas/index.d.ts.map +1 -0
- package/dist/saas/index.js +19 -0
- package/dist/saas/index.js.map +1 -0
- package/package.json +165 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
|
2
|
+
/* Helpers */
|
|
3
|
+
/* ------------------------------------------------------------------ */
|
|
4
|
+
function readStr(get, name, ...suffixes) {
|
|
5
|
+
for (const suffix of suffixes) {
|
|
6
|
+
if (name) {
|
|
7
|
+
const v = get.str(`CACHE_${name.toUpperCase()}_${suffix}`);
|
|
8
|
+
if (v !== undefined)
|
|
9
|
+
return v;
|
|
10
|
+
}
|
|
11
|
+
const v = get.str(suffix);
|
|
12
|
+
if (v !== undefined)
|
|
13
|
+
return v;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
function readNum(get, name, ...suffixes) {
|
|
18
|
+
for (const suffix of suffixes) {
|
|
19
|
+
if (name) {
|
|
20
|
+
const v = get.num(`CACHE_${name.toUpperCase()}_${suffix}`);
|
|
21
|
+
if (v !== undefined)
|
|
22
|
+
return v;
|
|
23
|
+
}
|
|
24
|
+
const v = get.num(suffix);
|
|
25
|
+
if (v !== undefined)
|
|
26
|
+
return v;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function buildAdapterOptions(name, opt, get, prefix) {
|
|
31
|
+
const rds = opt?.rdsEnabled ?? get.bool('RDS_CACHE_ENABLED', false);
|
|
32
|
+
const keyPrefix = opt?.keyPrefix ?? readStr(get, name, 'KEY_PREFIX', `${prefix}_KEY_PREFIX`);
|
|
33
|
+
const url = opt?.url ?? readStr(get, name, 'URL', `${prefix}_URL`) ?? 'redis://localhost:6379/0';
|
|
34
|
+
return { url, keyPrefix, ...(rds ? { socket: { tls: true } } : {}) };
|
|
35
|
+
}
|
|
36
|
+
function parseStores(get, options) {
|
|
37
|
+
const userStores = options?.stores;
|
|
38
|
+
const raw = userStores?.map((s) => s.type).join(',') ?? get.str('CACHE_STORE') ?? 'memory';
|
|
39
|
+
const types = raw.split(',').map((s) => s.trim());
|
|
40
|
+
return types.map((type) => {
|
|
41
|
+
const opt = userStores?.find((s) => s.type === type);
|
|
42
|
+
const storeName = opt?.name;
|
|
43
|
+
const maxVal = opt?.max ?? readNum(get, storeName, 'MAX', 'CACHE_MAX') ?? 100;
|
|
44
|
+
const ttlVal = opt?.ttl ?? options?.ttl ?? readNum(get, storeName, 'TTL', 'CACHE_TTL') ?? 60;
|
|
45
|
+
const base = {
|
|
46
|
+
type,
|
|
47
|
+
name: storeName,
|
|
48
|
+
adapter: opt?.adapter,
|
|
49
|
+
max: maxVal,
|
|
50
|
+
ttl: ttlVal,
|
|
51
|
+
};
|
|
52
|
+
if (type === 'memory')
|
|
53
|
+
return base;
|
|
54
|
+
const prefix = type === 'redis' ? 'REDIS' : 'VALKEY';
|
|
55
|
+
return {
|
|
56
|
+
...base,
|
|
57
|
+
...buildAdapterOptions(storeName, opt, get, prefix),
|
|
58
|
+
rdsEnabled: opt?.rdsEnabled ?? get.bool('RDS_CACHE_ENABLED', false),
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function toMilliseconds(seconds) {
|
|
63
|
+
return seconds * 1000;
|
|
64
|
+
}
|
|
65
|
+
function buildCacheConfig(get, options) {
|
|
66
|
+
const KeyvClass = options?.keyv;
|
|
67
|
+
const stores = parseStores(get, options);
|
|
68
|
+
const base = {
|
|
69
|
+
ttl: options?.ttl ?? get.num('CACHE_TTL') ?? 60,
|
|
70
|
+
isGlobal: options?.isGlobal ?? get.bool('CACHE_IS_GLOBAL', false),
|
|
71
|
+
};
|
|
72
|
+
// When Keyv class is provided, build Keyv instances
|
|
73
|
+
if (KeyvClass) {
|
|
74
|
+
const keyvInstances = stores.map((s) => {
|
|
75
|
+
const ttlMs = toMilliseconds(s.ttl ?? 60);
|
|
76
|
+
if (s.type === 'memory') {
|
|
77
|
+
const adapterOptions = {};
|
|
78
|
+
if (s.max !== undefined)
|
|
79
|
+
adapterOptions.lruSize = s.max;
|
|
80
|
+
const adapter = s.adapter ? new s.adapter(adapterOptions) : undefined;
|
|
81
|
+
// In-memory without adapter → Keyv default (no explicit store)
|
|
82
|
+
if (!adapter) {
|
|
83
|
+
return { keyv: new KeyvClass({ ttl: ttlMs }), name: s.name };
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
keyv: new KeyvClass({ store: adapter, ttl: ttlMs }),
|
|
87
|
+
name: s.name,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// redis / valkey — always need adapter
|
|
91
|
+
if (!s.adapter) {
|
|
92
|
+
throw new Error(`Cache store "${s.type}" requires an adapter. ` +
|
|
93
|
+
`Install the package and pass adapter in config. ` +
|
|
94
|
+
`e.g. { type: "${s.type}", adapter: Keyv${s.type === 'redis' ? 'Redis' : 'Valkey'} }`);
|
|
95
|
+
}
|
|
96
|
+
const adapterOptions = buildAdapterOptions(s.name, s, get, s.type === 'redis' ? 'REDIS' : 'VALKEY');
|
|
97
|
+
const keyvAdapter = new s.adapter(adapterOptions.url, adapterOptions);
|
|
98
|
+
return {
|
|
99
|
+
keyv: new KeyvClass({ store: keyvAdapter, ttl: ttlMs }),
|
|
100
|
+
name: s.name,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
// Single store — flatten, include name if set
|
|
104
|
+
if (keyvInstances.length === 1) {
|
|
105
|
+
const entry = keyvInstances[0];
|
|
106
|
+
const out = { store: entry.keyv, ...base };
|
|
107
|
+
if (entry.name)
|
|
108
|
+
out.name = entry.name;
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
return { stores: keyvInstances, ...base };
|
|
112
|
+
}
|
|
113
|
+
// Without Keyv class — return raw config data
|
|
114
|
+
if (stores.length === 1) {
|
|
115
|
+
const out = { ...base, ...stores[0] };
|
|
116
|
+
if (stores[0].name)
|
|
117
|
+
out.name = stores[0].name;
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
return { ...base, stores };
|
|
121
|
+
}
|
|
122
|
+
/* ------------------------------------------------------------------ */
|
|
123
|
+
/* Public API */
|
|
124
|
+
/* ------------------------------------------------------------------ */
|
|
125
|
+
/**
|
|
126
|
+
* Build cache module options from environment variables.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import Keyv from 'keyv';
|
|
131
|
+
* import KeyvRedis from '@keyv/redis';
|
|
132
|
+
* import { KeyvCacheableMemory } from 'cacheable';
|
|
133
|
+
*
|
|
134
|
+
* const cfg = configCache({
|
|
135
|
+
* keyv: Keyv,
|
|
136
|
+
* stores: [
|
|
137
|
+
* { type: 'memory', adapter: KeyvCacheableMemory },
|
|
138
|
+
* { type: 'redis', adapter: KeyvRedis },
|
|
139
|
+
* ],
|
|
140
|
+
* });
|
|
141
|
+
* CacheModule.register(cfg);
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* Environment variables:
|
|
145
|
+
* | Variable | Default | Description |
|
|
146
|
+
* |---------------------------|----------------------------|-------------------------------------------|
|
|
147
|
+
* | `CACHE_STORE` | `memory` | Comma-separated store types |
|
|
148
|
+
* | `CACHE_TTL` | `60` | Default TTL (seconds) |
|
|
149
|
+
* | `CACHE_MAX` | `100` | Max items (memory store) |
|
|
150
|
+
* | `CACHE_IS_GLOBAL` | `false` | Register as global module |
|
|
151
|
+
* | `CACHE_{NAME}_URL` | — | Named-store URL (overrides `REDIS_URL`) |
|
|
152
|
+
* | `CACHE_{NAME}_KEY_PREFIX` | — | Named-store key prefix |
|
|
153
|
+
* | `CACHE_{NAME}_TTL` | — | Named-store TTL (overrides `CACHE_TTL`) |
|
|
154
|
+
* | `CACHE_{NAME}_MAX` | — | Named-store max (overrides `CACHE_MAX`) |
|
|
155
|
+
* | `REDIS_URL` | `redis://localhost:6379/0` | Redis connection URL |
|
|
156
|
+
* | `REDIS_KEY_PREFIX` | — | Redis key prefix |
|
|
157
|
+
* | `VALKEY_URL` | `redis://localhost:6379/0` | Valkey connection URL |
|
|
158
|
+
* | `VALKEY_KEY_PREFIX` | — | Valkey key prefix |
|
|
159
|
+
* | `RDS_CACHE_ENABLED` | `false` | Enable TLS for Redis / Valkey |
|
|
160
|
+
*/
|
|
161
|
+
export function configCache(options) {
|
|
162
|
+
return buildCacheConfig({
|
|
163
|
+
str: (key) => process.env[key],
|
|
164
|
+
num: (key) => (process.env[key] !== undefined ? Number(process.env[key]) : undefined),
|
|
165
|
+
bool: (key, def) => process.env[key] !== undefined
|
|
166
|
+
? process.env[key] === 'true' || process.env[key] === '1'
|
|
167
|
+
: def,
|
|
168
|
+
}, options);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Build cache module options from `ConfigService`.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* CacheModule.registerAsync({
|
|
176
|
+
* imports: [ConfigModule],
|
|
177
|
+
* inject: [ConfigService],
|
|
178
|
+
* useFactory: (cs) => configCacheAsync(cs, { keyv: Keyv, stores: [...] }),
|
|
179
|
+
* })
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export function configCacheAsync(configService, options) {
|
|
183
|
+
return buildCacheConfig({
|
|
184
|
+
str: (key) => configService.get(key),
|
|
185
|
+
num: (key) => configService.get(key),
|
|
186
|
+
bool: (key, def) => configService.get(key, def) ?? def,
|
|
187
|
+
}, options);
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../packages/bootstrap/cache/config.ts"],"names":[],"mappings":"AAkHA,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,SAAS,OAAO,CACd,GAAc,EACd,IAAwB,E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AC,GAAG,CAAC,GAAG,CAAC;QAC9B,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrF,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CACjB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;YAC5B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG;YACzD,CAAC,CAAC,GAAG;KACV,EACD,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,aAA4B,EAC5B,OAA4B;IAE5B,OAAO,gBAAgB,CACrB;QACE,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAS,GAAG,CAAC;QAC5C,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAS,GAAG,CAAC;QAC5C,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAU,GAAG,EAAE,GAAG,CAAC,IAAI,GAAG;KAChE,EACD,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @os.io/nest-kit/bootstrap/cache
|
|
3
|
+
*
|
|
4
|
+
* Cache module configuration bootstrapper for NestJS applications.
|
|
5
|
+
* Supports memory, Redis, Valkey, and multi-tier caching.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { configCache, configCacheAsync } from './config';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/bootstrap/cache/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @os.io/nest-kit/bootstrap/cache
|
|
3
|
+
*
|
|
4
|
+
* Cache module configuration bootstrapper for NestJS applications.
|
|
5
|
+
* Supports memory, Redis, Valkey, and multi-tier caching.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { configCache, configCacheAsync } from './config';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/bootstrap/cache/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @os.io/nest-kit/bootstrap
|
|
3
|
+
*
|
|
4
|
+
* Helpers and configuration bootstrappers for popular NestJS modules such as
|
|
5
|
+
* Swagger, Scalar, Cache, TypeORM, Mongoose, etc. Designed to be called directly from
|
|
6
|
+
* your application's `main.ts` or `app.module.ts`.
|
|
7
|
+
*
|
|
8
|
+
* ## Sub-modules
|
|
9
|
+
*
|
|
10
|
+
* - `@os.io/nest-kit/bootstrap/swagger` — Swagger UI
|
|
11
|
+
* - `@os.io/nest-kit/bootstrap/scalar` — Scalar API Reference
|
|
12
|
+
* - `@os.io/nest-kit/bootstrap/cache` — CacheModule setup
|
|
13
|
+
* - `@os.io/nest-kit/bootstrap/typeorm` — TypeORM setup, CRUD factories, Unit of Work
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export * from './swagger';
|
|
19
|
+
export * from './scalar';
|
|
20
|
+
export * from './cache';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/bootstrap/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @os.io/nest-kit/bootstrap
|
|
3
|
+
*
|
|
4
|
+
* Helpers and configuration bootstrappers for popular NestJS modules such as
|
|
5
|
+
* Swagger, Scalar, Cache, TypeORM, Mongoose, etc. Designed to be called directly from
|
|
6
|
+
* your application's `main.ts` or `app.module.ts`.
|
|
7
|
+
*
|
|
8
|
+
* ## Sub-modules
|
|
9
|
+
*
|
|
10
|
+
* - `@os.io/nest-kit/bootstrap/swagger` — Swagger UI
|
|
11
|
+
* - `@os.io/nest-kit/bootstrap/scalar` — Scalar API Reference
|
|
12
|
+
* - `@os.io/nest-kit/bootstrap/cache` — CacheModule setup
|
|
13
|
+
* - `@os.io/nest-kit/bootstrap/typeorm` — TypeORM setup, CRUD factories, Unit of Work
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export * from './swagger';
|
|
19
|
+
export * from './scalar';
|
|
20
|
+
export * from './cache';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../packages/bootstrap/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { INestApplication } from '@nestjs/common';
|
|
2
|
+
import type { SwaggerDocumentOptions } from '@nestjs/swagger';
|
|
3
|
+
import type { NestJSReferenceConfiguration } from '@scalar/nestjs-api-reference';
|
|
4
|
+
/**
|
|
5
|
+
* Options for {@link configScalarApiDoc}.
|
|
6
|
+
*/
|
|
7
|
+
export interface ConfigScalarOptions {
|
|
8
|
+
/** OpenAPI title (default: `'NestJS API'`). */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** OpenAPI description (default: `''`). */
|
|
11
|
+
description?: string;
|
|
12
|
+
/** OpenAPI version (default: `'1.0'`). */
|
|
13
|
+
version?: string;
|
|
14
|
+
/** Mount path (default: `'api/docs'`). */
|
|
15
|
+
path?: string;
|
|
16
|
+
/** Extra options forwarded to `apiReference()` from `@scalar/nestjs-api-reference`. */
|
|
17
|
+
scalarOptions?: NestJSReferenceConfiguration;
|
|
18
|
+
/** Extra options forwarded to `SwaggerModule.createDocument`. */
|
|
19
|
+
swaggerDocumentOptions?: SwaggerDocumentOptions;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configure Scalar API Reference on the NestJS app.
|
|
23
|
+
*
|
|
24
|
+
* Mounts the Scalar UI at the given `path` (default `api/docs`).
|
|
25
|
+
* Requires `@scalar/nestjs-api-reference` to be installed.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { configScalarApiDoc } from '@os.io/nest-kit/bootstrap/scalar';
|
|
30
|
+
*
|
|
31
|
+
* configScalarApiDoc(app);
|
|
32
|
+
* // Browse to http://localhost:3000/api/docs
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param app - The NestJS application instance.
|
|
36
|
+
* @param options - Configuration overrides.
|
|
37
|
+
*/
|
|
38
|
+
export declare function configScalarApiDoc(app: INestApplication, options?: ConfigScalarOptions): void;
|
|
39
|
+
//# sourceMappingURL=api-docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-docs.d.ts","sourceRoot":"","sources":["../../../packages/bootstrap/scalar/api-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAYjF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,aAAa,CAAC,EAAE,4BAA4B,CAAC;IAC7C,iEAAiE;IACjE,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,CA0B7F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
const _require = createRequire(__filename);
|
|
4
|
+
/**
|
|
5
|
+
* Configure Scalar API Reference on the NestJS app.
|
|
6
|
+
*
|
|
7
|
+
* Mounts the Scalar UI at the given `path` (default `api/docs`).
|
|
8
|
+
* Requires `@scalar/nestjs-api-reference` to be installed.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { configScalarApiDoc } from '@oxpo/nest-kit/bootstrap/scalar';
|
|
13
|
+
*
|
|
14
|
+
* configScalarApiDoc(app);
|
|
15
|
+
* // Browse to http://localhost:3000/api/docs
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param app - The NestJS application instance.
|
|
19
|
+
* @param options - Configuration overrides.
|
|
20
|
+
*/
|
|
21
|
+
export function configScalarApiDoc(app, options) {
|
|
22
|
+
const builder = new DocumentBuilder()
|
|
23
|
+
.setTitle(options?.title ?? 'NestJS API')
|
|
24
|
+
.setDescription(options?.description ?? '')
|
|
25
|
+
.setVersion(options?.version ?? '1.0')
|
|
26
|
+
.addBearerAuth();
|
|
27
|
+
const config = builder.build();
|
|
28
|
+
const document = SwaggerModule.createDocument(app, config, options?.swaggerDocumentOptions);
|
|
29
|
+
try {
|
|
30
|
+
const { apiReference } = _require('@scalar/nestjs-api-reference');
|
|
31
|
+
app.use(options?.path ?? 'api/docs', apiReference({
|
|
32
|
+
spec: { content: document },
|
|
33
|
+
...options?.scalarOptions,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
console.warn('[@oxpo/nest-kit] @scalar/nestjs-api-reference is not installed. ' +
|
|
38
|
+
'Skipping Scalar API docs setup.');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=api-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-docs.js","sourceRoot":"","sources":["../../../packages/bootstrap/scalar/api-docs.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,QAAQ,GAAG,aAAa,CAAC,UAAU,CAA4B,CAAC;AA0BtE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAqB,EAAE,OAA6B;IACrF,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE;SAClC,QAAQ,CAAC,OAAO,EAAE,KAAK,IAAI,YAAY,CAAC;SACxC,cAAc,CAAC,OAAO,EAAE,WAAW,IAAI,EAAE,CAAC;SAC1C,UAAU,CAAC,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;SACrC,aAAa,EAAE,CAAC;IAEnB,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,aAAa,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC;IAE5F,IAAI,CAAC;QACH,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,8BAA8B,CAAsB,CAAC;QAEvF,GAAG,CAAC,GAAG,CACL,OAAO,EAAE,IAAI,IAAI,UAAU,EAC3B,YAAY,CAAC;YACX,IAAI,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;YAC3B,GAAG,OAAO,EAAE,aAAa;SAC1B,CAAC,CACH,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,IAAI,CACV,kEAAkE;YAChE,iCAAiC,CACpC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { INestApplication } from '@nestjs/common';
|
|
2
|
+
import type { SwaggerDocumentOptions } from '@nestjs/swagger';
|
|
3
|
+
import type { NestJSReferenceConfiguration } from '@scalar/nestjs-api-reference';
|
|
4
|
+
/**
|
|
5
|
+
* Options for {@link configScalarApiDoc}.
|
|
6
|
+
*/
|
|
7
|
+
export interface ConfigScalarOptions {
|
|
8
|
+
/** OpenAPI title (default: `'NestJS API'`). */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** OpenAPI description (default: `''`). */
|
|
11
|
+
description?: string;
|
|
12
|
+
/** OpenAPI version (default: `'1.0'`). */
|
|
13
|
+
version?: string;
|
|
14
|
+
/** Mount path (default: `'api/docs'`). */
|
|
15
|
+
path?: string;
|
|
16
|
+
/** Extra options forwarded to `apiReference()` from `@scalar/nestjs-api-reference`. */
|
|
17
|
+
scalarOptions?: NestJSReferenceConfiguration;
|
|
18
|
+
/** Extra options forwarded to `SwaggerModule.createDocument`. */
|
|
19
|
+
swaggerDocumentOptions?: SwaggerDocumentOptions;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configure Scalar API Reference on the NestJS app.
|
|
23
|
+
*
|
|
24
|
+
* Mounts the Scalar UI at the given `path` (default `api/docs`).
|
|
25
|
+
* Requires `@scalar/nestjs-api-reference` to be installed.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { configScalarApiDoc } from '@os.io/nest-kit/bootstrap/scalar';
|
|
30
|
+
*
|
|
31
|
+
* configScalarApiDoc(app);
|
|
32
|
+
* // Browse to http://localhost:3000/api/docs
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param app - The NestJS application instance.
|
|
36
|
+
* @param options - Configuration overrides.
|
|
37
|
+
*/
|
|
38
|
+
export declare function configScalarApiDoc(app: INestApplication, options?: ConfigScalarOptions): void;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/bootstrap/scalar/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAYjF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,aAAa,CAAC,EAAE,4BAA4B,CAAC;IAC7C,iEAAiE;IACjE,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,CA0B7F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
const _require = createRequire(__filename);
|
|
4
|
+
/**
|
|
5
|
+
* Configure Scalar API Reference on the NestJS app.
|
|
6
|
+
*
|
|
7
|
+
* Mounts the Scalar UI at the given `path` (default `api/docs`).
|
|
8
|
+
* Requires `@scalar/nestjs-api-reference` to be installed.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { configScalarApiDoc } from '@os.io/nest-kit/bootstrap/scalar';
|
|
13
|
+
*
|
|
14
|
+
* configScalarApiDoc(app);
|
|
15
|
+
* // Browse to http://localhost:3000/api/docs
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param app - The NestJS application instance.
|
|
19
|
+
* @param options - Configuration overrides.
|
|
20
|
+
*/
|
|
21
|
+
export function configScalarApiDoc(app, options) {
|
|
22
|
+
const builder = new DocumentBuilder()
|
|
23
|
+
.setTitle(options?.title ?? 'NestJS API')
|
|
24
|
+
.setDescription(options?.description ?? '')
|
|
25
|
+
.setVersion(options?.version ?? '1.0')
|
|
26
|
+
.addBearerAuth();
|
|
27
|
+
const config = builder.build();
|
|
28
|
+
const document = SwaggerModule.createDocument(app, config, options?.swaggerDocumentOptions);
|
|
29
|
+
try {
|
|
30
|
+
const { apiReference } = _require('@scalar/nestjs-api-reference');
|
|
31
|
+
app.use(options?.path ?? 'api/docs', apiReference({
|
|
32
|
+
spec: { content: document },
|
|
33
|
+
...options?.scalarOptions,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
console.warn('[@os.io/nest-kit] @scalar/nestjs-api-reference is not installed. ' +
|
|
38
|
+
'Skipping Scalar API docs setup.');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/bootstrap/scalar/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,QAAQ,GAAG,aAAa,CAAC,UAAU,CAA4B,CAAC;AA0BtE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAqB,EAAE,OAA6B;IACrF,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE;SAClC,QAAQ,CAAC,OAAO,EAAE,KAAK,IAAI,YAAY,CAAC;SACxC,cAAc,CAAC,OAAO,EAAE,WAAW,IAAI,EAAE,CAAC;SAC1C,UAAU,CAAC,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;SACrC,aAAa,EAAE,CAAC;IAEnB,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,aAAa,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC;IAE5F,IAAI,CAAC;QACH,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,8BAA8B,CAAsB,CAAC;QAEvF,GAAG,CAAC,GAAG,CACL,OAAO,EAAE,IAAI,IAAI,UAAU,EAC3B,YAAY,CAAC;YACX,IAAI,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;YAC3B,GAAG,OAAO,EAAE,aAAa;SAC1B,CAAC,CACH,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,IAAI,CACV,mEAAmE;YACjE,iCAAiC,CACpC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { INestApplication } from '@nestjs/common';
|
|
2
|
+
import type { SwaggerCustomOptions, SwaggerDocumentOptions } from '@nestjs/swagger';
|
|
3
|
+
import type { NestJSReferenceConfiguration } from '@scalar/nestjs-api-reference';
|
|
4
|
+
/**
|
|
5
|
+
* Options for {@link configSwagger}.
|
|
6
|
+
*/
|
|
7
|
+
export interface ConfigSwaggerOptions {
|
|
8
|
+
/** OpenAPI title (default: `'NestJS API'`). */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** OpenAPI description (default: `''`). */
|
|
11
|
+
description?: string;
|
|
12
|
+
/** OpenAPI version (default: `'1.0'`). */
|
|
13
|
+
version?: string;
|
|
14
|
+
/** Mount path (default: `'api/docs'`). */
|
|
15
|
+
path?: string;
|
|
16
|
+
/** Extra options forwarded to `SwaggerModule.setup`. */
|
|
17
|
+
swaggerCustomOptions?: SwaggerCustomOptions;
|
|
18
|
+
/** Extra options forwarded to `SwaggerModule.createDocument`. */
|
|
19
|
+
swaggerDocumentOptions?: SwaggerDocumentOptions;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configure Swagger UI on the NestJS app.
|
|
23
|
+
*
|
|
24
|
+
* Mounts the Swagger UI at the given `path` (default `api/docs`).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { configSwagger } from '@os.io/nest-kit/bootstrap/swagger';
|
|
29
|
+
*
|
|
30
|
+
* configSwagger(app);
|
|
31
|
+
* // Browse to http://localhost:3000/api/docs
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param app - The NestJS application instance.
|
|
35
|
+
* @param options - Configuration overrides.
|
|
36
|
+
*/
|
|
37
|
+
export declare function configSwagger(app: INestApplication, options?: ConfigSwaggerOptions): void;
|
|
38
|
+
/**
|
|
39
|
+
* Options for {@link configScalarApiDoc}.
|
|
40
|
+
*/
|
|
41
|
+
export interface ConfigScalarOptions {
|
|
42
|
+
/** OpenAPI title (default: `'NestJS API'`). */
|
|
43
|
+
title?: string;
|
|
44
|
+
/** OpenAPI description (default: `''`). */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** OpenAPI version (default: `'1.0'`). */
|
|
47
|
+
version?: string;
|
|
48
|
+
/** Mount path (default: `'api/docs'`). */
|
|
49
|
+
path?: string;
|
|
50
|
+
/** Extra options forwarded to `apiReference()` from `@scalar/nestjs-api-reference`. */
|
|
51
|
+
scalarOptions?: NestJSReferenceConfiguration;
|
|
52
|
+
/** Extra options forwarded to `SwaggerModule.createDocument`. */
|
|
53
|
+
swaggerDocumentOptions?: SwaggerDocumentOptions;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Configure Scalar API Reference on the NestJS app.
|
|
57
|
+
*
|
|
58
|
+
* Mounts the Scalar UI at the given `path` (default `api/docs`).
|
|
59
|
+
* Requires `@scalar/nestjs-api-reference` to be installed.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { configScalarApiDoc } from '@os.io/nest-kit/bootstrap/swagger';
|
|
64
|
+
*
|
|
65
|
+
* configScalarApiDoc(app);
|
|
66
|
+
* // Browse to http://localhost:3000/api/docs
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param app - The NestJS application instance.
|
|
70
|
+
* @param options - Configuration overrides.
|
|
71
|
+
*/
|
|
72
|
+
export declare function configScalarApiDoc(app: INestApplication, options?: ConfigScalarOptions): void;
|
|
73
|
+
//# sourceMappingURL=api-docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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I,CAiD7F"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const DEFAULT_FAVICON_URL = 'https://scalar.com/favicon.svg';
|
|
2
|
+
/**
|
|
3
|
+
* Configure Swagger UI on the NestJS app.
|
|
4
|
+
*
|
|
5
|
+
* Mounts the Swagger UI at the given `path` (default `api/docs`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { configSwagger } from '@oxpo/nest-kit/bootstrap/swagger';
|
|
10
|
+
*
|
|
11
|
+
* configSwagger(app);
|
|
12
|
+
* // Browse to http://localhost:3000/api/docs
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param app - The NestJS application instance.
|
|
16
|
+
* @param options - Configuration overrides.
|
|
17
|
+
*/
|
|
18
|
+
export function configSwagger(app, options) {
|
|
19
|
+
try {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
21
|
+
const { DocumentBuilder, SwaggerModule } = require('@nestjs/swagger');
|
|
22
|
+
const builder = new DocumentBuilder()
|
|
23
|
+
.setTitle(options?.title ?? 'NestJS API')
|
|
24
|
+
.setDescription(options?.description ?? '')
|
|
25
|
+
.setVersion(options?.version ?? '1.0')
|
|
26
|
+
.addBearerAuth();
|
|
27
|
+
const config = builder.build();
|
|
28
|
+
const document = SwaggerModule.createDocument(app, config, options?.swaggerDocumentOptions);
|
|
29
|
+
SwaggerModule.setup(options?.path ?? 'api/docs', app, document, {
|
|
30
|
+
customfavIcon: options?.swaggerCustomOptions?.customfavIcon ?? DEFAULT_FAVICON_URL,
|
|
31
|
+
...options?.swaggerCustomOptions,
|
|
32
|
+
swaggerOptions: {
|
|
33
|
+
persistAuthorization: true,
|
|
34
|
+
...options?.swaggerCustomOptions?.swaggerOptions,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
console.warn('[@oxpo/nest-kit] @nestjs/swagger is not installed. Skipping Swagger UI setup.');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Configure Scalar API Reference on the NestJS app.
|
|
44
|
+
*
|
|
45
|
+
* Mounts the Scalar UI at the given `path` (default `api/docs`).
|
|
46
|
+
* Requires `@scalar/nestjs-api-reference` to be installed.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { configScalarApiDoc } from '@oxpo/nest-kit/bootstrap/swagger';
|
|
51
|
+
*
|
|
52
|
+
* configScalarApiDoc(app);
|
|
53
|
+
* // Browse to http://localhost:3000/api/docs
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param app - The NestJS application instance.
|
|
57
|
+
* @param options - Configuration overrides.
|
|
58
|
+
*/
|
|
59
|
+
export function configScalarApiDoc(app, options) {
|
|
60
|
+
try {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
62
|
+
const { DocumentBuilder, SwaggerModule } = require('@nestjs/swagger');
|
|
63
|
+
const builder = new DocumentBuilder()
|
|
64
|
+
.setTitle(options?.title ?? 'NestJS API')
|
|
65
|
+
.setDescription(options?.description ?? '')
|
|
66
|
+
.setVersion(options?.version ?? '1.0')
|
|
67
|
+
.addBearerAuth();
|
|
68
|
+
const config = builder.build();
|
|
69
|
+
const document = SwaggerModule.createDocument(app, config, options?.swaggerDocumentOptions);
|
|
70
|
+
try {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
72
|
+
const { apiReference } = require('@scalar/nestjs-api-reference');
|
|
73
|
+
app.use(options?.path ?? 'api/docs', apiReference({
|
|
74
|
+
spec: { content: document },
|
|
75
|
+
...options?.scalarOptions,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
console.warn('[@oxpo/nest-kit] @scalar/nestjs-api-reference is not installed. ' +
|
|
80
|
+
'Skipping Scalar API docs setup.');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
console.warn('[@oxpo/nest-kit] @nestjs/swagger is not installed. Skipping Scalar API docs setup.');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=api-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-docs.js","sourceRoot":"","sources":["../../../packages/bootstrap/swagger/api-docs.ts"],"names":[],"mappings":"AAYA,MAAM,mBAAmB,GAAG,gCAAgC,CAAC;AAsB7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAAC,GAAqB,EAAE,OAA8B;IACjF,IAAI,CAAC;QACH,iEAAiE;QACjE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAenE,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE;aAClC,QAAQ,CAAC,OAAO,EAAE,KAAK,IAAI,YAAY,CAAC;aACxC,cAAc,CAAC,OAAO,EAAE,WAAW,IAAI,EAAE,CAAC;aAC1C,UAAU,CAAC,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;aACrC,aAAa,EAAE,CAAC;QAEnB,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,aAAa,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC;QAE5F,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE;YAC9D,aAAa,EAAE,OAAO,EAAE,oBAAoB,EAAE,aAAa,IAAI,mBAAmB;YAClF,GAAG,OAAO,EAAE,oBAAoB;YAChC,cAAc,EAAE;gBACd,oBAAoB,EAAE,IAAI;gBAC1B,GAAG,OAAO,EAAE,oBAAoB,EAAE,cAAc;aACjD;SACF,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,O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