@saasicat/nest 0.14.0 → 0.15.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/dist/_entries.cjs +1464 -1334
- package/dist/admin/index.d.cts +8 -6
- package/dist/admin/index.d.ts +8 -6
- package/dist/admin/index.js +13 -12
- package/dist/{admin-resources.module-Cms8MY6h.d.ts → admin-resources.module-BY5r_1MG.d.ts} +29 -3
- package/dist/{admin-resources.module-BZN_yBFj.d.cts → admin-resources.module-DGgGSdzN.d.cts} +29 -3
- package/dist/{admin-stats.module-15ac5KY3.d.ts → admin-stats.service-Db2exT_d.d.ts} +2 -23
- package/dist/{admin-stats.module-v4SVvWzj.d.cts → admin-stats.service-HUZIU448.d.cts} +2 -23
- package/dist/billing/index.d.cts +1 -1
- package/dist/billing/index.d.ts +1 -1
- package/dist/billing/index.js +3 -2
- package/dist/catalog/index.js +3 -2
- package/dist/checkout-offer/index.d.cts +2 -1
- package/dist/checkout-offer/index.d.ts +2 -1
- package/dist/checkout-offer/index.js +2 -1
- package/dist/checkout-offer.module-Ca3_TieR.d.ts +39 -0
- package/dist/checkout-offer.module-DmlpPevf.d.cts +39 -0
- package/dist/{checkout-offer.module-Y0hDOVrq.d.ts → checkout-offer.service-BX51dljL.d.cts} +1 -37
- package/dist/{checkout-offer.module-ZYF5IsDY.d.cts → checkout-offer.service-BX51dljL.d.ts} +1 -37
- package/dist/{chunk-2PNX2QL2.js → chunk-32EMXPU2.js} +1 -0
- package/dist/{chunk-RKVY775D.js → chunk-5KH2O4SF.js} +5 -1
- package/dist/{chunk-TXDH4FUA.js → chunk-7RRWI5LH.js} +1 -1
- package/dist/chunk-EWPF57AG.js +13 -0
- package/dist/{chunk-HBFU5AN3.js → chunk-GJBXOCRZ.js} +4 -0
- package/dist/{chunk-IRWZC3GC.js → chunk-GLLCB4BP.js} +4 -0
- package/dist/{chunk-33TP26MR.js → chunk-P3DP6GJE.js} +4 -0
- package/dist/{chunk-FVT7KTUI.js → chunk-PLJEAUFU.js} +275 -61
- package/dist/{chunk-I2EKGQUG.js → chunk-YITTE646.js} +462 -82
- package/dist/chunk-YSC46BGM.js +21 -0
- package/dist/define-saasicat-CeDBX9ji.d.cts +46 -0
- package/dist/define-saasicat-Rc0rXrYG.d.ts +46 -0
- package/dist/enforce-quota.interceptor-CmbWX39L.d.ts +60 -0
- package/dist/enforce-quota.interceptor-DMw-bPyk.d.cts +60 -0
- package/dist/index.d.cts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +33 -18
- package/dist/platform/index.d.cts +12 -16
- package/dist/platform/index.d.ts +12 -16
- package/dist/platform/index.js +24 -25
- package/dist/promo/index.js +2 -1
- package/dist/{enforce-quota.interceptor-Dse3jSpU.d.cts → saas-platform.module-D3rUTiho.d.cts} +69 -62
- package/dist/{enforce-quota.interceptor-DMEvL-bE.d.ts → saas-platform.module-DLhoqKNA.d.ts} +69 -62
- package/dist/subscription-contract/index.d.cts +1 -1
- package/dist/subscription-contract/index.d.ts +1 -1
- package/dist/subscription-contract/index.js +1 -1
- package/dist/{subscription-contract.module-CG9fPKAr.d.cts → subscription-contract.module-B2uNvUJL.d.cts} +3 -1
- package/dist/{subscription-contract.module-CVebZzHR.d.ts → subscription-contract.module-edyhBr4n.d.ts} +3 -1
- package/dist/{subscription-bundle-preview.service-BgQ776mv.d.ts → tenant-billing.controller-BwZRnJ3q.d.ts} +105 -105
- package/dist/{subscription-bundle-preview.service-B4Ye8L2F.d.cts → tenant-billing.controller-CG4CaFUP.d.cts} +105 -105
- package/dist/testing/index.d.cts +6 -3
- package/dist/testing/index.d.ts +6 -3
- package/dist/testing/index.js +8 -6
- package/package.json +3 -3
- package/dist/chunk-LZHLGUQI.js +0 -190
- package/dist/chunk-WJ6BMDL3.js +0 -313
- package/dist/setup.service-BPwJ7My_.d.cts +0 -45
- package/dist/setup.service-D2mrdDDB.d.ts +0 -45
package/dist/chunk-LZHLGUQI.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SuperAdminGuard
|
|
3
|
-
} from "./chunk-FVT7KTUI.js";
|
|
4
|
-
import {
|
|
5
|
-
asProvider
|
|
6
|
-
} from "./chunk-SABTXESR.js";
|
|
7
|
-
import {
|
|
8
|
-
__name
|
|
9
|
-
} from "./chunk-SHUYVCID.js";
|
|
10
|
-
|
|
11
|
-
// src/admin/admin-stats.tokens.ts
|
|
12
|
-
var SUBSCRIPTION_STATS_PORT_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/SubscriptionStatsPort");
|
|
13
|
-
var PROMO_CODE_STATS_PORT_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/PromoCodeStatsPort");
|
|
14
|
-
var AUDIT_STATS_PORT_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/AuditStatsPort");
|
|
15
|
-
var ADMIN_STATS_AUDIT_WINDOW_DAYS_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/AdminStatsAuditWindowDays");
|
|
16
|
-
|
|
17
|
-
// src/admin/admin-stats.service.ts
|
|
18
|
-
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
19
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
20
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
22
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
23
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
24
|
-
}
|
|
25
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
26
|
-
function _ts_metadata(k, v) {
|
|
27
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
28
|
-
}
|
|
29
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
30
|
-
function _ts_param(paramIndex, decorator) {
|
|
31
|
-
return function(target, key) {
|
|
32
|
-
decorator(target, key, paramIndex);
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
__name(_ts_param, "_ts_param");
|
|
36
|
-
var DAY_MS = 864e5;
|
|
37
|
-
var DEFAULT_AUDIT_WINDOW_DAYS = 7;
|
|
38
|
-
var AdminStatsService = class {
|
|
39
|
-
static {
|
|
40
|
-
__name(this, "AdminStatsService");
|
|
41
|
-
}
|
|
42
|
-
subscriptions;
|
|
43
|
-
promos;
|
|
44
|
-
audit;
|
|
45
|
-
auditWindowDays;
|
|
46
|
-
constructor(subscriptions, promos, audit, auditWindowDays = DEFAULT_AUDIT_WINDOW_DAYS) {
|
|
47
|
-
this.subscriptions = subscriptions;
|
|
48
|
-
this.promos = promos;
|
|
49
|
-
this.audit = audit;
|
|
50
|
-
this.auditWindowDays = auditWindowDays;
|
|
51
|
-
}
|
|
52
|
-
async getSnapshot() {
|
|
53
|
-
const since = new Date(Date.now() - this.auditWindowDays * DAY_MS);
|
|
54
|
-
const [subscriptions, promos, auditCount] = await Promise.all([
|
|
55
|
-
this.subscriptions.getStats(),
|
|
56
|
-
this.promos.getStats(),
|
|
57
|
-
this.audit.countSince(since)
|
|
58
|
-
]);
|
|
59
|
-
return {
|
|
60
|
-
subscriptions,
|
|
61
|
-
promos,
|
|
62
|
-
audit: {
|
|
63
|
-
countLastNDays: auditCount,
|
|
64
|
-
nDays: this.auditWindowDays
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
AdminStatsService = _ts_decorate([
|
|
70
|
-
Injectable(),
|
|
71
|
-
_ts_param(0, Inject(SUBSCRIPTION_STATS_PORT_TOKEN)),
|
|
72
|
-
_ts_param(1, Inject(PROMO_CODE_STATS_PORT_TOKEN)),
|
|
73
|
-
_ts_param(2, Inject(AUDIT_STATS_PORT_TOKEN)),
|
|
74
|
-
_ts_param(3, Optional()),
|
|
75
|
-
_ts_param(3, Inject(ADMIN_STATS_AUDIT_WINDOW_DAYS_TOKEN)),
|
|
76
|
-
_ts_metadata("design:type", Function),
|
|
77
|
-
_ts_metadata("design:paramtypes", [
|
|
78
|
-
typeof SubscriptionStatsPort === "undefined" ? Object : SubscriptionStatsPort,
|
|
79
|
-
typeof PromoCodeStatsPort === "undefined" ? Object : PromoCodeStatsPort,
|
|
80
|
-
typeof AuditStatsPort === "undefined" ? Object : AuditStatsPort,
|
|
81
|
-
Number
|
|
82
|
-
])
|
|
83
|
-
], AdminStatsService);
|
|
84
|
-
|
|
85
|
-
// src/admin/admin-stats.controller.ts
|
|
86
|
-
import { Controller, Get, Inject as Inject2, UseGuards } from "@nestjs/common";
|
|
87
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
88
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
89
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
90
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
91
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
92
|
-
}
|
|
93
|
-
__name(_ts_decorate2, "_ts_decorate");
|
|
94
|
-
function _ts_metadata2(k, v) {
|
|
95
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
96
|
-
}
|
|
97
|
-
__name(_ts_metadata2, "_ts_metadata");
|
|
98
|
-
function _ts_param2(paramIndex, decorator) {
|
|
99
|
-
return function(target, key) {
|
|
100
|
-
decorator(target, key, paramIndex);
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
__name(_ts_param2, "_ts_param");
|
|
104
|
-
var AdminStatsController = class {
|
|
105
|
-
static {
|
|
106
|
-
__name(this, "AdminStatsController");
|
|
107
|
-
}
|
|
108
|
-
stats;
|
|
109
|
-
// Explicit @Inject instead of type reflection: tsup/esbuild do not emit
|
|
110
|
-
// `design:paramtypes` metadata, so Nest could otherwise not resolve the
|
|
111
|
-
// service type at the constructor.
|
|
112
|
-
constructor(stats) {
|
|
113
|
-
this.stats = stats;
|
|
114
|
-
}
|
|
115
|
-
async getDashboardSnapshot() {
|
|
116
|
-
return this.stats.getSnapshot();
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
_ts_decorate2([
|
|
120
|
-
Get("dashboard"),
|
|
121
|
-
_ts_metadata2("design:type", Function),
|
|
122
|
-
_ts_metadata2("design:paramtypes", []),
|
|
123
|
-
_ts_metadata2("design:returntype", Promise)
|
|
124
|
-
], AdminStatsController.prototype, "getDashboardSnapshot", null);
|
|
125
|
-
AdminStatsController = _ts_decorate2([
|
|
126
|
-
Controller("admin/stats"),
|
|
127
|
-
UseGuards(SuperAdminGuard),
|
|
128
|
-
_ts_param2(0, Inject2(AdminStatsService)),
|
|
129
|
-
_ts_metadata2("design:type", Function),
|
|
130
|
-
_ts_metadata2("design:paramtypes", [
|
|
131
|
-
typeof AdminStatsService === "undefined" ? Object : AdminStatsService
|
|
132
|
-
])
|
|
133
|
-
], AdminStatsController);
|
|
134
|
-
|
|
135
|
-
// src/admin/admin-stats.module.ts
|
|
136
|
-
import { Module } from "@nestjs/common";
|
|
137
|
-
function _ts_decorate3(decorators, target, key, desc) {
|
|
138
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
139
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
140
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
141
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
142
|
-
}
|
|
143
|
-
__name(_ts_decorate3, "_ts_decorate");
|
|
144
|
-
var AdminStatsModule = class _AdminStatsModule {
|
|
145
|
-
static {
|
|
146
|
-
__name(this, "AdminStatsModule");
|
|
147
|
-
}
|
|
148
|
-
static forRoot(options) {
|
|
149
|
-
const providers = [
|
|
150
|
-
asProvider(SUBSCRIPTION_STATS_PORT_TOKEN, options.subscriptionStatsPort),
|
|
151
|
-
asProvider(PROMO_CODE_STATS_PORT_TOKEN, options.promoCodeStatsPort),
|
|
152
|
-
asProvider(AUDIT_STATS_PORT_TOKEN, options.auditStatsPort),
|
|
153
|
-
AdminStatsService,
|
|
154
|
-
SuperAdminGuard
|
|
155
|
-
];
|
|
156
|
-
if (options.auditWindowDays !== void 0) {
|
|
157
|
-
providers.push({
|
|
158
|
-
provide: ADMIN_STATS_AUDIT_WINDOW_DAYS_TOKEN,
|
|
159
|
-
useValue: options.auditWindowDays
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
if (options.extraProviders) providers.push(...options.extraProviders);
|
|
163
|
-
return {
|
|
164
|
-
module: _AdminStatsModule,
|
|
165
|
-
global: options.global ?? false,
|
|
166
|
-
imports: options.imports ?? [],
|
|
167
|
-
controllers: [
|
|
168
|
-
AdminStatsController
|
|
169
|
-
],
|
|
170
|
-
providers,
|
|
171
|
-
exports: [
|
|
172
|
-
AdminStatsService,
|
|
173
|
-
SuperAdminGuard
|
|
174
|
-
]
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
AdminStatsModule = _ts_decorate3([
|
|
179
|
-
Module({})
|
|
180
|
-
], AdminStatsModule);
|
|
181
|
-
|
|
182
|
-
export {
|
|
183
|
-
SUBSCRIPTION_STATS_PORT_TOKEN,
|
|
184
|
-
PROMO_CODE_STATS_PORT_TOKEN,
|
|
185
|
-
AUDIT_STATS_PORT_TOKEN,
|
|
186
|
-
ADMIN_STATS_AUDIT_WINDOW_DAYS_TOKEN,
|
|
187
|
-
AdminStatsService,
|
|
188
|
-
AdminStatsController,
|
|
189
|
-
AdminStatsModule
|
|
190
|
-
};
|
package/dist/chunk-WJ6BMDL3.js
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MfaService
|
|
3
|
-
} from "./chunk-FVT7KTUI.js";
|
|
4
|
-
import {
|
|
5
|
-
asProvider
|
|
6
|
-
} from "./chunk-SABTXESR.js";
|
|
7
|
-
import {
|
|
8
|
-
__name
|
|
9
|
-
} from "./chunk-SHUYVCID.js";
|
|
10
|
-
|
|
11
|
-
// src/setup/tokens.ts
|
|
12
|
-
var SETUP_PROVISIONING_PORT_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/SetupProvisioningPort");
|
|
13
|
-
var SETUP_CONFIG_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/SetupConfig");
|
|
14
|
-
|
|
15
|
-
// src/setup/setup.service.ts
|
|
16
|
-
import { BadRequestException, ConflictException, ForbiddenException, Inject, Injectable, UnauthorizedException } from "@nestjs/common";
|
|
17
|
-
import { isPlatformUserExistsError, SETUP_ERROR_CODES } from "@saasicat/types";
|
|
18
|
-
import { randomBytes, timingSafeEqual } from "crypto";
|
|
19
|
-
import QRCode from "qrcode";
|
|
20
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
21
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
22
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
23
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
-
}
|
|
26
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
27
|
-
function _ts_metadata(k, v) {
|
|
28
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
29
|
-
}
|
|
30
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
31
|
-
function _ts_param(paramIndex, decorator) {
|
|
32
|
-
return function(target, key) {
|
|
33
|
-
decorator(target, key, paramIndex);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
__name(_ts_param, "_ts_param");
|
|
37
|
-
var GENERATED_PASSWORD_BYTES = 12;
|
|
38
|
-
function timingSafeEqualStr(a, b) {
|
|
39
|
-
const ab = Buffer.from(a, "utf8");
|
|
40
|
-
const bb = Buffer.from(b, "utf8");
|
|
41
|
-
if (ab.length !== bb.length) return false;
|
|
42
|
-
return timingSafeEqual(ab, bb);
|
|
43
|
-
}
|
|
44
|
-
__name(timingSafeEqualStr, "timingSafeEqualStr");
|
|
45
|
-
var SetupService = class {
|
|
46
|
-
static {
|
|
47
|
-
__name(this, "SetupService");
|
|
48
|
-
}
|
|
49
|
-
users;
|
|
50
|
-
config;
|
|
51
|
-
mfa;
|
|
52
|
-
constructor(users, config, mfa) {
|
|
53
|
-
this.users = users;
|
|
54
|
-
this.config = config;
|
|
55
|
-
this.mfa = mfa;
|
|
56
|
-
}
|
|
57
|
-
async status() {
|
|
58
|
-
return {
|
|
59
|
-
needsSetup: await this.users.countSuperAdmins() === 0
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
async setup(req) {
|
|
63
|
-
this.assertToken(req.token);
|
|
64
|
-
await this.assertNoSuperAdmin();
|
|
65
|
-
const email = req.email.trim().toLowerCase();
|
|
66
|
-
if (!email.includes("@")) {
|
|
67
|
-
throw new BadRequestException({
|
|
68
|
-
code: SETUP_ERROR_CODES.INVALID_EMAIL
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const generated = !req.password;
|
|
72
|
-
const password = req.password ?? randomBytes(GENERATED_PASSWORD_BYTES).toString("base64url");
|
|
73
|
-
let user;
|
|
74
|
-
try {
|
|
75
|
-
user = await this.users.createSuperAdmin({
|
|
76
|
-
email,
|
|
77
|
-
password
|
|
78
|
-
});
|
|
79
|
-
} catch (err) {
|
|
80
|
-
if (isPlatformUserExistsError(err)) {
|
|
81
|
-
throw new ConflictException({
|
|
82
|
-
code: SETUP_ERROR_CODES.EMAIL_EXISTS,
|
|
83
|
-
message: err.message
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
throw err;
|
|
87
|
-
}
|
|
88
|
-
const totp = await this.mfa.setup(user.id, user.email, this.config.mfaIssuer);
|
|
89
|
-
const qrDataUrl = await QRCode.toDataURL(totp.otpauthUri, {
|
|
90
|
-
width: 220,
|
|
91
|
-
margin: 1
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
userId: user.id,
|
|
95
|
-
email: user.email,
|
|
96
|
-
otpauthUri: totp.otpauthUri,
|
|
97
|
-
qrDataUrl,
|
|
98
|
-
secret: totp.secret,
|
|
99
|
-
...generated ? {
|
|
100
|
-
generatedPassword: password
|
|
101
|
-
} : {}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
async confirmMfa(req) {
|
|
105
|
-
this.assertToken(req.token);
|
|
106
|
-
const ok = await this.mfa.verify({
|
|
107
|
-
userId: req.userId,
|
|
108
|
-
code: req.code
|
|
109
|
-
});
|
|
110
|
-
return {
|
|
111
|
-
ok
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
assertToken(token) {
|
|
115
|
-
const expected = process.env[this.config.setupTokenEnvVar]?.trim();
|
|
116
|
-
if (!expected) {
|
|
117
|
-
throw new ForbiddenException({
|
|
118
|
-
code: SETUP_ERROR_CODES.SETUP_DISABLED,
|
|
119
|
-
message: `${this.config.setupTokenEnvVar} ist nicht gesetzt \u2014 Setup ist deaktiviert.`
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
if (!token || !timingSafeEqualStr(token, expected)) {
|
|
123
|
-
throw new UnauthorizedException({
|
|
124
|
-
code: SETUP_ERROR_CODES.INVALID_SETUP_TOKEN
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async assertNoSuperAdmin() {
|
|
129
|
-
if (await this.users.countSuperAdmins() > 0) {
|
|
130
|
-
throw new ConflictException({
|
|
131
|
-
code: SETUP_ERROR_CODES.SETUP_ALREADY_DONE
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
SetupService = _ts_decorate([
|
|
137
|
-
Injectable(),
|
|
138
|
-
_ts_param(0, Inject(SETUP_PROVISIONING_PORT_TOKEN)),
|
|
139
|
-
_ts_param(1, Inject(SETUP_CONFIG_TOKEN)),
|
|
140
|
-
_ts_metadata("design:type", Function),
|
|
141
|
-
_ts_metadata("design:paramtypes", [
|
|
142
|
-
typeof SuperAdminProvisioningPort === "undefined" ? Object : SuperAdminProvisioningPort,
|
|
143
|
-
typeof SetupConfig === "undefined" ? Object : SetupConfig,
|
|
144
|
-
typeof MfaService === "undefined" ? Object : MfaService
|
|
145
|
-
])
|
|
146
|
-
], SetupService);
|
|
147
|
-
|
|
148
|
-
// src/setup/setup.controller.ts
|
|
149
|
-
import { Body, Controller, Get, Post } from "@nestjs/common";
|
|
150
|
-
import { IsEmail, IsNotEmpty, IsOptional, IsString, MinLength } from "class-validator";
|
|
151
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
152
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
153
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
154
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
155
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
156
|
-
}
|
|
157
|
-
__name(_ts_decorate2, "_ts_decorate");
|
|
158
|
-
function _ts_metadata2(k, v) {
|
|
159
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
160
|
-
}
|
|
161
|
-
__name(_ts_metadata2, "_ts_metadata");
|
|
162
|
-
function _ts_param2(paramIndex, decorator) {
|
|
163
|
-
return function(target, key) {
|
|
164
|
-
decorator(target, key, paramIndex);
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
__name(_ts_param2, "_ts_param");
|
|
168
|
-
var SetupDto = class SetupDto2 {
|
|
169
|
-
static {
|
|
170
|
-
__name(this, "SetupDto");
|
|
171
|
-
}
|
|
172
|
-
token;
|
|
173
|
-
email;
|
|
174
|
-
password;
|
|
175
|
-
};
|
|
176
|
-
_ts_decorate2([
|
|
177
|
-
IsString(),
|
|
178
|
-
IsNotEmpty(),
|
|
179
|
-
_ts_metadata2("design:type", String)
|
|
180
|
-
], SetupDto.prototype, "token", void 0);
|
|
181
|
-
_ts_decorate2([
|
|
182
|
-
IsEmail(),
|
|
183
|
-
_ts_metadata2("design:type", String)
|
|
184
|
-
], SetupDto.prototype, "email", void 0);
|
|
185
|
-
_ts_decorate2([
|
|
186
|
-
IsOptional(),
|
|
187
|
-
IsString(),
|
|
188
|
-
MinLength(8),
|
|
189
|
-
_ts_metadata2("design:type", String)
|
|
190
|
-
], SetupDto.prototype, "password", void 0);
|
|
191
|
-
var SetupConfirmMfaDto = class SetupConfirmMfaDto2 {
|
|
192
|
-
static {
|
|
193
|
-
__name(this, "SetupConfirmMfaDto");
|
|
194
|
-
}
|
|
195
|
-
token;
|
|
196
|
-
userId;
|
|
197
|
-
code;
|
|
198
|
-
};
|
|
199
|
-
_ts_decorate2([
|
|
200
|
-
IsString(),
|
|
201
|
-
IsNotEmpty(),
|
|
202
|
-
_ts_metadata2("design:type", String)
|
|
203
|
-
], SetupConfirmMfaDto.prototype, "token", void 0);
|
|
204
|
-
_ts_decorate2([
|
|
205
|
-
IsString(),
|
|
206
|
-
IsNotEmpty(),
|
|
207
|
-
_ts_metadata2("design:type", String)
|
|
208
|
-
], SetupConfirmMfaDto.prototype, "userId", void 0);
|
|
209
|
-
_ts_decorate2([
|
|
210
|
-
IsString(),
|
|
211
|
-
IsNotEmpty(),
|
|
212
|
-
_ts_metadata2("design:type", String)
|
|
213
|
-
], SetupConfirmMfaDto.prototype, "code", void 0);
|
|
214
|
-
var SetupController = class {
|
|
215
|
-
static {
|
|
216
|
-
__name(this, "SetupController");
|
|
217
|
-
}
|
|
218
|
-
setup;
|
|
219
|
-
constructor(setup) {
|
|
220
|
-
this.setup = setup;
|
|
221
|
-
}
|
|
222
|
-
status() {
|
|
223
|
-
return this.setup.status();
|
|
224
|
-
}
|
|
225
|
-
run(dto) {
|
|
226
|
-
return this.setup.setup(dto);
|
|
227
|
-
}
|
|
228
|
-
confirm(dto) {
|
|
229
|
-
return this.setup.confirmMfa(dto);
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
_ts_decorate2([
|
|
233
|
-
Get("status"),
|
|
234
|
-
_ts_metadata2("design:type", Function),
|
|
235
|
-
_ts_metadata2("design:paramtypes", []),
|
|
236
|
-
_ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
237
|
-
], SetupController.prototype, "status", null);
|
|
238
|
-
_ts_decorate2([
|
|
239
|
-
Post(),
|
|
240
|
-
_ts_param2(0, Body()),
|
|
241
|
-
_ts_metadata2("design:type", Function),
|
|
242
|
-
_ts_metadata2("design:paramtypes", [
|
|
243
|
-
typeof SetupDto === "undefined" ? Object : SetupDto
|
|
244
|
-
]),
|
|
245
|
-
_ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
246
|
-
], SetupController.prototype, "run", null);
|
|
247
|
-
_ts_decorate2([
|
|
248
|
-
Post("confirm-mfa"),
|
|
249
|
-
_ts_param2(0, Body()),
|
|
250
|
-
_ts_metadata2("design:type", Function),
|
|
251
|
-
_ts_metadata2("design:paramtypes", [
|
|
252
|
-
typeof SetupConfirmMfaDto === "undefined" ? Object : SetupConfirmMfaDto
|
|
253
|
-
]),
|
|
254
|
-
_ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
255
|
-
], SetupController.prototype, "confirm", null);
|
|
256
|
-
SetupController = _ts_decorate2([
|
|
257
|
-
Controller("admin/setup"),
|
|
258
|
-
_ts_metadata2("design:type", Function),
|
|
259
|
-
_ts_metadata2("design:paramtypes", [
|
|
260
|
-
typeof SetupService === "undefined" ? Object : SetupService
|
|
261
|
-
])
|
|
262
|
-
], SetupController);
|
|
263
|
-
|
|
264
|
-
// src/setup/setup.module.ts
|
|
265
|
-
import { Module } from "@nestjs/common";
|
|
266
|
-
function _ts_decorate3(decorators, target, key, desc) {
|
|
267
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
268
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
269
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
270
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
271
|
-
}
|
|
272
|
-
__name(_ts_decorate3, "_ts_decorate");
|
|
273
|
-
var DEFAULT_SETUP_TOKEN_ENV_VAR = "SETUP_TOKEN";
|
|
274
|
-
var DEFAULT_MFA_ISSUER = "SuperAdmin";
|
|
275
|
-
var SetupModule = class _SetupModule {
|
|
276
|
-
static {
|
|
277
|
-
__name(this, "SetupModule");
|
|
278
|
-
}
|
|
279
|
-
static forRoot(options) {
|
|
280
|
-
return {
|
|
281
|
-
module: _SetupModule,
|
|
282
|
-
global: options.global ?? false,
|
|
283
|
-
controllers: [
|
|
284
|
-
SetupController
|
|
285
|
-
],
|
|
286
|
-
providers: [
|
|
287
|
-
asProvider(SETUP_PROVISIONING_PORT_TOKEN, options.provisioningPort),
|
|
288
|
-
{
|
|
289
|
-
provide: SETUP_CONFIG_TOKEN,
|
|
290
|
-
useValue: {
|
|
291
|
-
setupTokenEnvVar: options.setupTokenEnvVar ?? DEFAULT_SETUP_TOKEN_ENV_VAR,
|
|
292
|
-
mfaIssuer: options.mfaIssuer ?? DEFAULT_MFA_ISSUER
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
SetupService
|
|
296
|
-
],
|
|
297
|
-
exports: [
|
|
298
|
-
SetupService
|
|
299
|
-
]
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
SetupModule = _ts_decorate3([
|
|
304
|
-
Module({})
|
|
305
|
-
], SetupModule);
|
|
306
|
-
|
|
307
|
-
export {
|
|
308
|
-
SETUP_PROVISIONING_PORT_TOKEN,
|
|
309
|
-
SETUP_CONFIG_TOKEN,
|
|
310
|
-
SetupService,
|
|
311
|
-
SetupController,
|
|
312
|
-
SetupModule
|
|
313
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { SuperAdminProvisioningPort, SetupStatusResponse, SetupRequest, SetupResult, SetupConfirmMfaRequest, SetupConfirmMfaResponse } from '@saasicat/types';
|
|
3
|
-
import { P as ProviderSpec } from './di-CcNeq9v-.cjs';
|
|
4
|
-
import { j as MfaService } from './admin-stats.module-v4SVvWzj.cjs';
|
|
5
|
-
|
|
6
|
-
interface SetupModuleOptions {
|
|
7
|
-
/**
|
|
8
|
-
* App adapter for the existence check + creation of the first SUPER_ADMIN. A
|
|
9
|
-
* full `UserManagementPort` adapter (CLI) satisfies this contract as well, so
|
|
10
|
-
* it can be reused.
|
|
11
|
-
*/
|
|
12
|
-
provisioningPort: ProviderSpec<SuperAdminProvisioningPort>;
|
|
13
|
-
/** Env-var name of the setup token. Default `SETUP_TOKEN`. */
|
|
14
|
-
setupTokenEnvVar?: string;
|
|
15
|
-
/** Authenticator issuer for MFA enrollment. Default `SuperAdmin`. */
|
|
16
|
-
mfaIssuer?: string;
|
|
17
|
-
/** Register the module globally — default `false`. */
|
|
18
|
-
global?: boolean;
|
|
19
|
-
}
|
|
20
|
-
declare class SetupModule {
|
|
21
|
-
static forRoot(options: SetupModuleOptions): DynamicModule;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare const SETUP_PROVISIONING_PORT_TOKEN: unique symbol;
|
|
25
|
-
declare const SETUP_CONFIG_TOKEN: unique symbol;
|
|
26
|
-
interface SetupConfig {
|
|
27
|
-
/** Env-var name of the setup token. Without the var set, setup is disabled. */
|
|
28
|
-
setupTokenEnvVar: string;
|
|
29
|
-
/** Authenticator issuer for the MFA enrollment in the wizard. */
|
|
30
|
-
mfaIssuer: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare class SetupService {
|
|
34
|
-
private readonly users;
|
|
35
|
-
private readonly config;
|
|
36
|
-
private readonly mfa;
|
|
37
|
-
constructor(users: SuperAdminProvisioningPort, config: SetupConfig, mfa: MfaService);
|
|
38
|
-
status(): Promise<SetupStatusResponse>;
|
|
39
|
-
setup(req: SetupRequest): Promise<SetupResult>;
|
|
40
|
-
confirmMfa(req: SetupConfirmMfaRequest): Promise<SetupConfirmMfaResponse>;
|
|
41
|
-
private assertToken;
|
|
42
|
-
private assertNoSuperAdmin;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { SetupService as S, SETUP_CONFIG_TOKEN as a, SETUP_PROVISIONING_PORT_TOKEN as b, type SetupConfig as c, SetupModule as d, type SetupModuleOptions as e };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { SuperAdminProvisioningPort, SetupStatusResponse, SetupRequest, SetupResult, SetupConfirmMfaRequest, SetupConfirmMfaResponse } from '@saasicat/types';
|
|
3
|
-
import { P as ProviderSpec } from './di-CcNeq9v-.js';
|
|
4
|
-
import { j as MfaService } from './admin-stats.module-15ac5KY3.js';
|
|
5
|
-
|
|
6
|
-
interface SetupModuleOptions {
|
|
7
|
-
/**
|
|
8
|
-
* App adapter for the existence check + creation of the first SUPER_ADMIN. A
|
|
9
|
-
* full `UserManagementPort` adapter (CLI) satisfies this contract as well, so
|
|
10
|
-
* it can be reused.
|
|
11
|
-
*/
|
|
12
|
-
provisioningPort: ProviderSpec<SuperAdminProvisioningPort>;
|
|
13
|
-
/** Env-var name of the setup token. Default `SETUP_TOKEN`. */
|
|
14
|
-
setupTokenEnvVar?: string;
|
|
15
|
-
/** Authenticator issuer for MFA enrollment. Default `SuperAdmin`. */
|
|
16
|
-
mfaIssuer?: string;
|
|
17
|
-
/** Register the module globally — default `false`. */
|
|
18
|
-
global?: boolean;
|
|
19
|
-
}
|
|
20
|
-
declare class SetupModule {
|
|
21
|
-
static forRoot(options: SetupModuleOptions): DynamicModule;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare const SETUP_PROVISIONING_PORT_TOKEN: unique symbol;
|
|
25
|
-
declare const SETUP_CONFIG_TOKEN: unique symbol;
|
|
26
|
-
interface SetupConfig {
|
|
27
|
-
/** Env-var name of the setup token. Without the var set, setup is disabled. */
|
|
28
|
-
setupTokenEnvVar: string;
|
|
29
|
-
/** Authenticator issuer for the MFA enrollment in the wizard. */
|
|
30
|
-
mfaIssuer: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare class SetupService {
|
|
34
|
-
private readonly users;
|
|
35
|
-
private readonly config;
|
|
36
|
-
private readonly mfa;
|
|
37
|
-
constructor(users: SuperAdminProvisioningPort, config: SetupConfig, mfa: MfaService);
|
|
38
|
-
status(): Promise<SetupStatusResponse>;
|
|
39
|
-
setup(req: SetupRequest): Promise<SetupResult>;
|
|
40
|
-
confirmMfa(req: SetupConfirmMfaRequest): Promise<SetupConfirmMfaResponse>;
|
|
41
|
-
private assertToken;
|
|
42
|
-
private assertNoSuperAdmin;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { SetupService as S, SETUP_CONFIG_TOKEN as a, SETUP_PROVISIONING_PORT_TOKEN as b, type SetupConfig as c, SetupModule as d, type SetupModuleOptions as e };
|