@saasicat/adapter-drizzle 0.4.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 +202 -0
- package/README.md +85 -0
- package/dist/index.cjs +1549 -0
- package/dist/index.d.cts +2750 -0
- package/dist/index.d.ts +2750 -0
- package/dist/index.js +1508 -0
- package/package.json +62 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1549 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc4) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc4 = __getOwnPropDesc(from, key)) || desc4.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
AsyncLocalRlsBypassAdapter: () => AsyncLocalRlsBypassAdapter,
|
|
25
|
+
DRIZZLE_DB_TOKEN: () => DRIZZLE_DB_TOKEN,
|
|
26
|
+
DrizzleAuditAdapter: () => DrizzleAuditAdapter,
|
|
27
|
+
DrizzleAuditQueryAdapter: () => DrizzleAuditQueryAdapter,
|
|
28
|
+
DrizzleAuditStatsAdapter: () => DrizzleAuditStatsAdapter,
|
|
29
|
+
DrizzleMfaAdapter: () => DrizzleMfaAdapter,
|
|
30
|
+
DrizzlePlanCatalogImportSink: () => DrizzlePlanCatalogImportSink,
|
|
31
|
+
DrizzlePlanCatalogReadSink: () => DrizzlePlanCatalogReadSink,
|
|
32
|
+
DrizzlePlanVersionRepository: () => DrizzlePlanVersionRepository,
|
|
33
|
+
DrizzlePromoCodeRedemptionRepository: () => DrizzlePromoCodeRedemptionRepository,
|
|
34
|
+
DrizzlePromoCodeRepository: () => DrizzlePromoCodeRepository,
|
|
35
|
+
DrizzlePromoCodeValidationLogRepository: () => DrizzlePromoCodeValidationLogRepository,
|
|
36
|
+
DrizzlePromoSubscriptionLookup: () => DrizzlePromoSubscriptionLookup,
|
|
37
|
+
DrizzleSubscriptionRepository: () => DrizzleSubscriptionRepository,
|
|
38
|
+
DrizzleSuperAdminBootstrapAdapter: () => DrizzleSuperAdminBootstrapAdapter,
|
|
39
|
+
DrizzleTransactionRunner: () => DrizzleTransactionRunner,
|
|
40
|
+
PASSWORD_HASHER_TOKEN: () => PASSWORD_HASHER_TOKEN,
|
|
41
|
+
ZeroPromoRevenueDeductionAggregator: () => ZeroPromoRevenueDeductionAggregator,
|
|
42
|
+
buildActorTag: () => buildActorTag,
|
|
43
|
+
drizzlePersistence: () => drizzlePersistence,
|
|
44
|
+
saasicatSchema: () => schema_exports
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// src/client.ts
|
|
49
|
+
var DRIZZLE_DB_TOKEN = /* @__PURE__ */ Symbol.for("saasicat/adapter-drizzle/DrizzleDb");
|
|
50
|
+
function resolveDb(client, tx) {
|
|
51
|
+
return tx ?? client;
|
|
52
|
+
}
|
|
53
|
+
__name(resolveDb, "resolveDb");
|
|
54
|
+
function toQuotaMap(value) {
|
|
55
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
__name(toQuotaMap, "toQuotaMap");
|
|
61
|
+
function toStringArray(value) {
|
|
62
|
+
return Array.isArray(value) ? value : [];
|
|
63
|
+
}
|
|
64
|
+
__name(toStringArray, "toStringArray");
|
|
65
|
+
function escapeLikePattern(value) {
|
|
66
|
+
return value.replace(/[\\%_]/g, "\\$&");
|
|
67
|
+
}
|
|
68
|
+
__name(escapeLikePattern, "escapeLikePattern");
|
|
69
|
+
|
|
70
|
+
// src/async-local-rls-bypass.adapter.ts
|
|
71
|
+
var import_common = require("@nestjs/common");
|
|
72
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
73
|
+
function _ts_decorate(decorators, target, key, desc4) {
|
|
74
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
75
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
76
|
+
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;
|
|
77
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
78
|
+
}
|
|
79
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
80
|
+
var AsyncLocalRlsBypassAdapter = class {
|
|
81
|
+
static {
|
|
82
|
+
__name(this, "AsyncLocalRlsBypassAdapter");
|
|
83
|
+
}
|
|
84
|
+
storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
85
|
+
async runWithBypass(fn) {
|
|
86
|
+
return this.storage.run({
|
|
87
|
+
bypass: true
|
|
88
|
+
}, fn);
|
|
89
|
+
}
|
|
90
|
+
/** `true` during the execution of a `runWithBypass(...)` callback. */
|
|
91
|
+
isBypassActive() {
|
|
92
|
+
return this.storage.getStore()?.bypass === true;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
AsyncLocalRlsBypassAdapter = _ts_decorate([
|
|
96
|
+
(0, import_common.Injectable)()
|
|
97
|
+
], AsyncLocalRlsBypassAdapter);
|
|
98
|
+
|
|
99
|
+
// src/drizzle-audit.adapter.ts
|
|
100
|
+
var import_node_crypto = require("node:crypto");
|
|
101
|
+
var import_common2 = require("@nestjs/common");
|
|
102
|
+
|
|
103
|
+
// src/schema.ts
|
|
104
|
+
var schema_exports = {};
|
|
105
|
+
__export(schema_exports, {
|
|
106
|
+
auditLogs: () => auditLogs,
|
|
107
|
+
featureCatalogEntries: () => featureCatalogEntries,
|
|
108
|
+
planVersions: () => planVersions,
|
|
109
|
+
plans: () => plans,
|
|
110
|
+
promoCodeRedemptions: () => promoCodeRedemptions,
|
|
111
|
+
promoCodeValidationLogs: () => promoCodeValidationLogs,
|
|
112
|
+
promoCodes: () => promoCodes,
|
|
113
|
+
subscriptions: () => subscriptions,
|
|
114
|
+
superAdminMfa: () => superAdminMfa,
|
|
115
|
+
superAdminUsers: () => superAdminUsers
|
|
116
|
+
});
|
|
117
|
+
var import_pg_core = require("drizzle-orm/pg-core");
|
|
118
|
+
var ts = /* @__PURE__ */ __name((name) => (0, import_pg_core.timestamp)(name, {
|
|
119
|
+
precision: 3,
|
|
120
|
+
mode: "date"
|
|
121
|
+
}), "ts");
|
|
122
|
+
var subscriptions = (0, import_pg_core.pgTable)("subscriptions", {
|
|
123
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
124
|
+
tenantId: (0, import_pg_core.text)("tenantId").notNull(),
|
|
125
|
+
plan: (0, import_pg_core.text)("plan").notNull(),
|
|
126
|
+
billingCycle: (0, import_pg_core.text)("billingCycle").notNull().default("YEARLY"),
|
|
127
|
+
status: (0, import_pg_core.text)("status").notNull().default("TRIAL"),
|
|
128
|
+
trialEntitlementPlan: (0, import_pg_core.text)("trialEntitlementPlan"),
|
|
129
|
+
pendingPlan: (0, import_pg_core.text)("pendingPlan"),
|
|
130
|
+
pendingEffectiveAt: ts("pendingEffectiveAt"),
|
|
131
|
+
customLimits: (0, import_pg_core.jsonb)("customLimits"),
|
|
132
|
+
planVersionId: (0, import_pg_core.text)("planVersionId"),
|
|
133
|
+
pendingPlanVersionId: (0, import_pg_core.text)("pendingPlanVersionId"),
|
|
134
|
+
isPilot: (0, import_pg_core.boolean)("isPilot").notNull().default(false),
|
|
135
|
+
startedAt: ts("startedAt"),
|
|
136
|
+
createdAt: ts("createdAt").notNull().defaultNow(),
|
|
137
|
+
updatedAt: ts("updatedAt").notNull()
|
|
138
|
+
});
|
|
139
|
+
var planVersions = (0, import_pg_core.pgTable)("plan_versions", {
|
|
140
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
141
|
+
planId: (0, import_pg_core.text)("planId").notNull(),
|
|
142
|
+
version: (0, import_pg_core.integer)("version").notNull(),
|
|
143
|
+
baseVersionId: (0, import_pg_core.text)("baseVersionId"),
|
|
144
|
+
features: (0, import_pg_core.jsonb)("features").notNull(),
|
|
145
|
+
quotas: (0, import_pg_core.jsonb)("quotas").notNull(),
|
|
146
|
+
monthlyNet: (0, import_pg_core.numeric)("monthlyNet", {
|
|
147
|
+
precision: 10,
|
|
148
|
+
scale: 2
|
|
149
|
+
}).notNull(),
|
|
150
|
+
yearlyNet: (0, import_pg_core.numeric)("yearlyNet", {
|
|
151
|
+
precision: 10,
|
|
152
|
+
scale: 2
|
|
153
|
+
}).notNull(),
|
|
154
|
+
marketed: (0, import_pg_core.boolean)("marketed").notNull().default(true),
|
|
155
|
+
publishedAt: ts("publishedAt"),
|
|
156
|
+
supersededAt: ts("supersededAt"),
|
|
157
|
+
publishedChanges: (0, import_pg_core.jsonb)("publishedChanges"),
|
|
158
|
+
changeNote: (0, import_pg_core.text)("changeNote").notNull(),
|
|
159
|
+
nonRegressive: (0, import_pg_core.boolean)("nonRegressive").notNull().default(true),
|
|
160
|
+
createdByUserId: (0, import_pg_core.text)("createdByUserId"),
|
|
161
|
+
publishedByUserId: (0, import_pg_core.text)("publishedByUserId"),
|
|
162
|
+
createdAt: ts("createdAt").notNull().defaultNow(),
|
|
163
|
+
updatedAt: ts("updatedAt").notNull()
|
|
164
|
+
});
|
|
165
|
+
var plans = (0, import_pg_core.pgTable)("plans", {
|
|
166
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
167
|
+
projectKey: (0, import_pg_core.text)("projectKey").notNull(),
|
|
168
|
+
planKey: (0, import_pg_core.text)("planKey").notNull(),
|
|
169
|
+
label: (0, import_pg_core.text)("label").notNull(),
|
|
170
|
+
description: (0, import_pg_core.text)("description"),
|
|
171
|
+
icon: (0, import_pg_core.text)("icon"),
|
|
172
|
+
sortOrder: (0, import_pg_core.integer)("sortOrder").notNull().default(0),
|
|
173
|
+
createdAt: ts("createdAt").notNull().defaultNow(),
|
|
174
|
+
updatedAt: ts("updatedAt").notNull(),
|
|
175
|
+
deletedAt: ts("deletedAt")
|
|
176
|
+
});
|
|
177
|
+
var featureCatalogEntries = (0, import_pg_core.pgTable)("feature_catalog_entries", {
|
|
178
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
179
|
+
projectKey: (0, import_pg_core.text)("projectKey").notNull(),
|
|
180
|
+
featureKey: (0, import_pg_core.text)("featureKey").notNull(),
|
|
181
|
+
label: (0, import_pg_core.text)("label").notNull(),
|
|
182
|
+
description: (0, import_pg_core.text)("description"),
|
|
183
|
+
marketingLabel: (0, import_pg_core.text)("marketingLabel"),
|
|
184
|
+
marketingDescription: (0, import_pg_core.text)("marketingDescription"),
|
|
185
|
+
icon: (0, import_pg_core.text)("icon"),
|
|
186
|
+
tier: (0, import_pg_core.text)("tier"),
|
|
187
|
+
core: (0, import_pg_core.boolean)("core").notNull().default(false),
|
|
188
|
+
requires: (0, import_pg_core.text)("requires").array(),
|
|
189
|
+
replaces: (0, import_pg_core.text)("replaces").array(),
|
|
190
|
+
successorKey: (0, import_pg_core.text)("successorKey"),
|
|
191
|
+
discoveryStatus: (0, import_pg_core.text)("discoveryStatus").notNull().default("pending"),
|
|
192
|
+
approvedAt: ts("approvedAt"),
|
|
193
|
+
approvedBy: (0, import_pg_core.text)("approvedBy"),
|
|
194
|
+
approvedSignature: (0, import_pg_core.text)("approvedSignature"),
|
|
195
|
+
plannedOnly: (0, import_pg_core.boolean)("plannedOnly").notNull().default(false),
|
|
196
|
+
i18n: (0, import_pg_core.jsonb)("i18n").notNull().default({}),
|
|
197
|
+
sortOrder: (0, import_pg_core.integer)("sortOrder").notNull().default(0),
|
|
198
|
+
createdAt: ts("createdAt").notNull().defaultNow(),
|
|
199
|
+
updatedAt: ts("updatedAt").notNull(),
|
|
200
|
+
deletedAt: ts("deletedAt")
|
|
201
|
+
});
|
|
202
|
+
var promoCodes = (0, import_pg_core.pgTable)("promo_codes", {
|
|
203
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
204
|
+
code: (0, import_pg_core.text)("code").notNull(),
|
|
205
|
+
valueType: (0, import_pg_core.text)("valueType").notNull(),
|
|
206
|
+
value: (0, import_pg_core.numeric)("value", {
|
|
207
|
+
precision: 8,
|
|
208
|
+
scale: 2
|
|
209
|
+
}).notNull(),
|
|
210
|
+
durationType: (0, import_pg_core.text)("durationType").notNull().default("ONCE"),
|
|
211
|
+
durationValue: (0, import_pg_core.integer)("durationValue"),
|
|
212
|
+
validFrom: ts("validFrom"),
|
|
213
|
+
validUntil: ts("validUntil"),
|
|
214
|
+
maxRedemptions: (0, import_pg_core.integer)("maxRedemptions"),
|
|
215
|
+
redemptionsCount: (0, import_pg_core.integer)("redemptionsCount").notNull().default(0),
|
|
216
|
+
appliesToPlans: (0, import_pg_core.text)("appliesToPlans").array(),
|
|
217
|
+
appliesToBilling: (0, import_pg_core.text)("appliesToBilling"),
|
|
218
|
+
firstTimeCustomersOnly: (0, import_pg_core.boolean)("firstTimeCustomersOnly").notNull().default(true),
|
|
219
|
+
minimumPlanAmountGross: (0, import_pg_core.numeric)("minimumPlanAmountGross", {
|
|
220
|
+
precision: 10,
|
|
221
|
+
scale: 2
|
|
222
|
+
}),
|
|
223
|
+
allowZeroInvoice: (0, import_pg_core.boolean)("allowZeroInvoice").notNull().default(false),
|
|
224
|
+
status: (0, import_pg_core.text)("status").notNull().default("ACTIVE"),
|
|
225
|
+
description: (0, import_pg_core.text)("description"),
|
|
226
|
+
campaignTag: (0, import_pg_core.text)("campaignTag"),
|
|
227
|
+
revenueDeductionAccount: (0, import_pg_core.text)("revenueDeductionAccount"),
|
|
228
|
+
createdById: (0, import_pg_core.text)("createdById").notNull(),
|
|
229
|
+
createdAt: ts("createdAt").notNull().defaultNow(),
|
|
230
|
+
updatedAt: ts("updatedAt").notNull(),
|
|
231
|
+
deletedAt: ts("deletedAt")
|
|
232
|
+
});
|
|
233
|
+
var promoCodeRedemptions = (0, import_pg_core.pgTable)("promo_code_redemptions", {
|
|
234
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
235
|
+
promoCodeId: (0, import_pg_core.text)("promoCodeId").notNull(),
|
|
236
|
+
subscriptionId: (0, import_pg_core.text)("subscriptionId").notNull(),
|
|
237
|
+
tenantId: (0, import_pg_core.text)("tenantId").notNull(),
|
|
238
|
+
appliedValueType: (0, import_pg_core.text)("appliedValueType").notNull(),
|
|
239
|
+
appliedValue: (0, import_pg_core.numeric)("appliedValue", {
|
|
240
|
+
precision: 8,
|
|
241
|
+
scale: 2
|
|
242
|
+
}).notNull(),
|
|
243
|
+
appliedDurationType: (0, import_pg_core.text)("appliedDurationType").notNull(),
|
|
244
|
+
appliedDurationValue: (0, import_pg_core.integer)("appliedDurationValue"),
|
|
245
|
+
startsAt: ts("startsAt").notNull(),
|
|
246
|
+
endsAt: ts("endsAt"),
|
|
247
|
+
status: (0, import_pg_core.text)("status").notNull().default("ACTIVE"),
|
|
248
|
+
redeemedAt: ts("redeemedAt").notNull().defaultNow(),
|
|
249
|
+
reversedAt: ts("reversedAt")
|
|
250
|
+
});
|
|
251
|
+
var promoCodeValidationLogs = (0, import_pg_core.pgTable)("promo_code_validation_logs", {
|
|
252
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
253
|
+
promoCodeId: (0, import_pg_core.text)("promoCodeId"),
|
|
254
|
+
codeAttempt: (0, import_pg_core.text)("codeAttempt").notNull(),
|
|
255
|
+
ipHash: (0, import_pg_core.text)("ipHash"),
|
|
256
|
+
sessionId: (0, import_pg_core.text)("sessionId"),
|
|
257
|
+
result: (0, import_pg_core.text)("result").notNull(),
|
|
258
|
+
createdAt: ts("createdAt").notNull().defaultNow()
|
|
259
|
+
});
|
|
260
|
+
var auditLogs = (0, import_pg_core.pgTable)("audit_logs", {
|
|
261
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
262
|
+
tenantId: (0, import_pg_core.text)("tenantId"),
|
|
263
|
+
userId: (0, import_pg_core.text)("userId"),
|
|
264
|
+
entity: (0, import_pg_core.text)("entity").notNull(),
|
|
265
|
+
entityId: (0, import_pg_core.text)("entityId").notNull(),
|
|
266
|
+
action: (0, import_pg_core.text)("action").notNull(),
|
|
267
|
+
changes: (0, import_pg_core.jsonb)("changes"),
|
|
268
|
+
actorTag: (0, import_pg_core.text)("actorTag"),
|
|
269
|
+
ipAddress: (0, import_pg_core.text)("ipAddress"),
|
|
270
|
+
userAgent: (0, import_pg_core.text)("userAgent"),
|
|
271
|
+
createdAt: ts("createdAt").notNull().defaultNow()
|
|
272
|
+
});
|
|
273
|
+
var superAdminUsers = (0, import_pg_core.pgTable)("super_admin_users", {
|
|
274
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
275
|
+
email: (0, import_pg_core.text)("email").notNull(),
|
|
276
|
+
passwordHash: (0, import_pg_core.text)("passwordHash").notNull(),
|
|
277
|
+
firstName: (0, import_pg_core.text)("firstName"),
|
|
278
|
+
lastName: (0, import_pg_core.text)("lastName"),
|
|
279
|
+
platformRole: (0, import_pg_core.text)("platformRole").notNull().default("SUPER_ADMIN"),
|
|
280
|
+
isActive: (0, import_pg_core.boolean)("isActive").notNull().default(true),
|
|
281
|
+
lastLoginAt: ts("lastLoginAt"),
|
|
282
|
+
deletedAt: ts("deletedAt"),
|
|
283
|
+
createdAt: ts("createdAt").notNull().defaultNow(),
|
|
284
|
+
updatedAt: ts("updatedAt").notNull()
|
|
285
|
+
});
|
|
286
|
+
var superAdminMfa = (0, import_pg_core.pgTable)("super_admin_mfa", {
|
|
287
|
+
userId: (0, import_pg_core.text)("userId").primaryKey(),
|
|
288
|
+
secret: (0, import_pg_core.text)("secret"),
|
|
289
|
+
enabledAt: ts("enabledAt"),
|
|
290
|
+
updatedAt: ts("updatedAt").notNull()
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// src/drizzle-audit.adapter.ts
|
|
294
|
+
function _ts_decorate2(decorators, target, key, desc4) {
|
|
295
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
296
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
297
|
+
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;
|
|
298
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
299
|
+
}
|
|
300
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
301
|
+
function _ts_metadata(k, v) {
|
|
302
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
303
|
+
}
|
|
304
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
305
|
+
function _ts_param(paramIndex, decorator) {
|
|
306
|
+
return function(target, key) {
|
|
307
|
+
decorator(target, key, paramIndex);
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
__name(_ts_param, "_ts_param");
|
|
311
|
+
function buildActorTag(actor) {
|
|
312
|
+
return `${actor.source}:${actor.email}:${actor.context}`;
|
|
313
|
+
}
|
|
314
|
+
__name(buildActorTag, "buildActorTag");
|
|
315
|
+
var DrizzleAuditAdapter = class {
|
|
316
|
+
static {
|
|
317
|
+
__name(this, "DrizzleAuditAdapter");
|
|
318
|
+
}
|
|
319
|
+
db;
|
|
320
|
+
constructor(db) {
|
|
321
|
+
this.db = db;
|
|
322
|
+
}
|
|
323
|
+
async write(input) {
|
|
324
|
+
await this.db.insert(auditLogs).values({
|
|
325
|
+
id: (0, import_node_crypto.randomUUID)(),
|
|
326
|
+
tenantId: null,
|
|
327
|
+
userId: input.actor.userId,
|
|
328
|
+
entity: input.entity,
|
|
329
|
+
entityId: input.entityId,
|
|
330
|
+
action: input.action,
|
|
331
|
+
changes: input.changes ?? {},
|
|
332
|
+
actorTag: buildActorTag(input.actor)
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
DrizzleAuditAdapter = _ts_decorate2([
|
|
337
|
+
(0, import_common2.Injectable)(),
|
|
338
|
+
_ts_param(0, (0, import_common2.Inject)(DRIZZLE_DB_TOKEN)),
|
|
339
|
+
_ts_metadata("design:type", Function),
|
|
340
|
+
_ts_metadata("design:paramtypes", [
|
|
341
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
342
|
+
])
|
|
343
|
+
], DrizzleAuditAdapter);
|
|
344
|
+
|
|
345
|
+
// src/drizzle-audit-query.adapter.ts
|
|
346
|
+
var import_common3 = require("@nestjs/common");
|
|
347
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
348
|
+
function _ts_decorate3(decorators, target, key, desc4) {
|
|
349
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
350
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
351
|
+
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;
|
|
352
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
353
|
+
}
|
|
354
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
355
|
+
function _ts_metadata2(k, v) {
|
|
356
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
357
|
+
}
|
|
358
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
359
|
+
function _ts_param2(paramIndex, decorator) {
|
|
360
|
+
return function(target, key) {
|
|
361
|
+
decorator(target, key, paramIndex);
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
__name(_ts_param2, "_ts_param");
|
|
365
|
+
var DEFAULT_PAGE_SIZE = 50;
|
|
366
|
+
var MAX_PAGE_SIZE = 200;
|
|
367
|
+
var DrizzleAuditQueryAdapter = class {
|
|
368
|
+
static {
|
|
369
|
+
__name(this, "DrizzleAuditQueryAdapter");
|
|
370
|
+
}
|
|
371
|
+
db;
|
|
372
|
+
constructor(db) {
|
|
373
|
+
this.db = db;
|
|
374
|
+
}
|
|
375
|
+
async list(filter) {
|
|
376
|
+
const page = Math.max(filter.page ?? 1, 1);
|
|
377
|
+
const pageSize = Math.min(Math.max(filter.pageSize ?? DEFAULT_PAGE_SIZE, 1), MAX_PAGE_SIZE);
|
|
378
|
+
const conditions = [
|
|
379
|
+
filter.tenantId ? (0, import_drizzle_orm.eq)(auditLogs.tenantId, filter.tenantId) : void 0,
|
|
380
|
+
filter.userId ? (0, import_drizzle_orm.eq)(auditLogs.userId, filter.userId) : void 0,
|
|
381
|
+
filter.entity ? (0, import_drizzle_orm.eq)(auditLogs.entity, filter.entity) : void 0,
|
|
382
|
+
filter.entityId ? (0, import_drizzle_orm.eq)(auditLogs.entityId, filter.entityId) : void 0,
|
|
383
|
+
filter.action ? (0, import_drizzle_orm.eq)(auditLogs.action, filter.action) : void 0,
|
|
384
|
+
toActorTagCondition(filter.actorTag),
|
|
385
|
+
filter.from ? (0, import_drizzle_orm.gte)(auditLogs.createdAt, new Date(filter.from)) : void 0,
|
|
386
|
+
filter.to ? (0, import_drizzle_orm.lte)(auditLogs.createdAt, new Date(filter.to)) : void 0
|
|
387
|
+
];
|
|
388
|
+
const rows = await this.db.select().from(auditLogs).where((0, import_drizzle_orm.and)(...conditions)).orderBy((0, import_drizzle_orm.desc)(auditLogs.createdAt)).limit(pageSize).offset((page - 1) * pageSize);
|
|
389
|
+
return rows.map(toAuditEntry);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
DrizzleAuditQueryAdapter = _ts_decorate3([
|
|
393
|
+
(0, import_common3.Injectable)(),
|
|
394
|
+
_ts_param2(0, (0, import_common3.Inject)(DRIZZLE_DB_TOKEN)),
|
|
395
|
+
_ts_metadata2("design:type", Function),
|
|
396
|
+
_ts_metadata2("design:paramtypes", [
|
|
397
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
398
|
+
])
|
|
399
|
+
], DrizzleAuditQueryAdapter);
|
|
400
|
+
function toActorTagCondition(actorTag) {
|
|
401
|
+
if (!actorTag) return void 0;
|
|
402
|
+
if (actorTag.endsWith("*")) {
|
|
403
|
+
return (0, import_drizzle_orm.like)(auditLogs.actorTag, `${escapeLikePattern(actorTag.slice(0, -1))}%`);
|
|
404
|
+
}
|
|
405
|
+
return (0, import_drizzle_orm.eq)(auditLogs.actorTag, actorTag);
|
|
406
|
+
}
|
|
407
|
+
__name(toActorTagCondition, "toActorTagCondition");
|
|
408
|
+
function toAuditEntry(row) {
|
|
409
|
+
return {
|
|
410
|
+
id: row.id,
|
|
411
|
+
tenantId: row.tenantId,
|
|
412
|
+
userId: row.userId,
|
|
413
|
+
// The schema does not persist the email — the actorTag carries it.
|
|
414
|
+
userEmail: row.actorTag?.split(":")[1] ?? null,
|
|
415
|
+
entity: row.entity,
|
|
416
|
+
entityId: row.entityId,
|
|
417
|
+
action: row.action,
|
|
418
|
+
changes: row.changes ?? null,
|
|
419
|
+
actorTag: row.actorTag,
|
|
420
|
+
ipAddress: row.ipAddress,
|
|
421
|
+
userAgent: row.userAgent,
|
|
422
|
+
createdAt: row.createdAt.toISOString()
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
__name(toAuditEntry, "toAuditEntry");
|
|
426
|
+
|
|
427
|
+
// src/drizzle-audit-stats.adapter.ts
|
|
428
|
+
var import_common4 = require("@nestjs/common");
|
|
429
|
+
var import_drizzle_orm2 = require("drizzle-orm");
|
|
430
|
+
function _ts_decorate4(decorators, target, key, desc4) {
|
|
431
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
432
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
433
|
+
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;
|
|
434
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
435
|
+
}
|
|
436
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
437
|
+
function _ts_metadata3(k, v) {
|
|
438
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
439
|
+
}
|
|
440
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
441
|
+
function _ts_param3(paramIndex, decorator) {
|
|
442
|
+
return function(target, key) {
|
|
443
|
+
decorator(target, key, paramIndex);
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
__name(_ts_param3, "_ts_param");
|
|
447
|
+
var DrizzleAuditStatsAdapter = class {
|
|
448
|
+
static {
|
|
449
|
+
__name(this, "DrizzleAuditStatsAdapter");
|
|
450
|
+
}
|
|
451
|
+
db;
|
|
452
|
+
constructor(db) {
|
|
453
|
+
this.db = db;
|
|
454
|
+
}
|
|
455
|
+
async countSince(since) {
|
|
456
|
+
const rows = await this.db.select({
|
|
457
|
+
value: (0, import_drizzle_orm2.count)()
|
|
458
|
+
}).from(auditLogs).where((0, import_drizzle_orm2.gte)(auditLogs.createdAt, since));
|
|
459
|
+
return rows[0]?.value ?? 0;
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
DrizzleAuditStatsAdapter = _ts_decorate4([
|
|
463
|
+
(0, import_common4.Injectable)(),
|
|
464
|
+
_ts_param3(0, (0, import_common4.Inject)(DRIZZLE_DB_TOKEN)),
|
|
465
|
+
_ts_metadata3("design:type", Function),
|
|
466
|
+
_ts_metadata3("design:paramtypes", [
|
|
467
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
468
|
+
])
|
|
469
|
+
], DrizzleAuditStatsAdapter);
|
|
470
|
+
|
|
471
|
+
// src/drizzle-mfa.adapter.ts
|
|
472
|
+
var import_common5 = require("@nestjs/common");
|
|
473
|
+
var import_drizzle_orm3 = require("drizzle-orm");
|
|
474
|
+
function _ts_decorate5(decorators, target, key, desc4) {
|
|
475
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
476
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
477
|
+
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;
|
|
478
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
479
|
+
}
|
|
480
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
481
|
+
function _ts_metadata4(k, v) {
|
|
482
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
483
|
+
}
|
|
484
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
485
|
+
function _ts_param4(paramIndex, decorator) {
|
|
486
|
+
return function(target, key) {
|
|
487
|
+
decorator(target, key, paramIndex);
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
__name(_ts_param4, "_ts_param");
|
|
491
|
+
var DrizzleMfaAdapter = class {
|
|
492
|
+
static {
|
|
493
|
+
__name(this, "DrizzleMfaAdapter");
|
|
494
|
+
}
|
|
495
|
+
db;
|
|
496
|
+
constructor(db) {
|
|
497
|
+
this.db = db;
|
|
498
|
+
}
|
|
499
|
+
async getSecret(userId) {
|
|
500
|
+
const rows = await this.db.select().from(superAdminMfa).where((0, import_drizzle_orm3.eq)(superAdminMfa.userId, userId)).limit(1);
|
|
501
|
+
return rows[0]?.secret ?? null;
|
|
502
|
+
}
|
|
503
|
+
async setSecret(userId, secret) {
|
|
504
|
+
const enabledAt = secret ? /* @__PURE__ */ new Date() : null;
|
|
505
|
+
await this.db.insert(superAdminMfa).values({
|
|
506
|
+
userId,
|
|
507
|
+
secret,
|
|
508
|
+
enabledAt,
|
|
509
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
510
|
+
}).onConflictDoUpdate({
|
|
511
|
+
target: superAdminMfa.userId,
|
|
512
|
+
set: {
|
|
513
|
+
secret,
|
|
514
|
+
enabledAt,
|
|
515
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
async isEnabled(userId) {
|
|
520
|
+
const rows = await this.db.select().from(superAdminMfa).where((0, import_drizzle_orm3.eq)(superAdminMfa.userId, userId)).limit(1);
|
|
521
|
+
const row = rows[0];
|
|
522
|
+
return !!row?.secret && !!row?.enabledAt;
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
DrizzleMfaAdapter = _ts_decorate5([
|
|
526
|
+
(0, import_common5.Injectable)(),
|
|
527
|
+
_ts_param4(0, (0, import_common5.Inject)(DRIZZLE_DB_TOKEN)),
|
|
528
|
+
_ts_metadata4("design:type", Function),
|
|
529
|
+
_ts_metadata4("design:paramtypes", [
|
|
530
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
531
|
+
])
|
|
532
|
+
], DrizzleMfaAdapter);
|
|
533
|
+
|
|
534
|
+
// src/drizzle-plan-catalog-import-sink.ts
|
|
535
|
+
var import_node_crypto2 = require("node:crypto");
|
|
536
|
+
var import_common6 = require("@nestjs/common");
|
|
537
|
+
var import_drizzle_orm4 = require("drizzle-orm");
|
|
538
|
+
function _ts_decorate6(decorators, target, key, desc4) {
|
|
539
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
540
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
541
|
+
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;
|
|
542
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
543
|
+
}
|
|
544
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
545
|
+
function _ts_metadata5(k, v) {
|
|
546
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
547
|
+
}
|
|
548
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
549
|
+
function _ts_param5(paramIndex, decorator) {
|
|
550
|
+
return function(target, key) {
|
|
551
|
+
decorator(target, key, paramIndex);
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
__name(_ts_param5, "_ts_param");
|
|
555
|
+
var DrizzlePlanCatalogImportSink = class {
|
|
556
|
+
static {
|
|
557
|
+
__name(this, "DrizzlePlanCatalogImportSink");
|
|
558
|
+
}
|
|
559
|
+
db;
|
|
560
|
+
constructor(db) {
|
|
561
|
+
this.db = db;
|
|
562
|
+
}
|
|
563
|
+
async upsertPlan(input) {
|
|
564
|
+
const existing = await this.db.select({
|
|
565
|
+
id: plans.id
|
|
566
|
+
}).from(plans).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(plans.projectKey, input.projectKey), (0, import_drizzle_orm4.eq)(plans.planKey, input.planKey))).limit(1);
|
|
567
|
+
if (existing[0]) return {
|
|
568
|
+
created: false,
|
|
569
|
+
skipReason: "exists"
|
|
570
|
+
};
|
|
571
|
+
await this.db.insert(plans).values({
|
|
572
|
+
id: (0, import_node_crypto2.randomUUID)(),
|
|
573
|
+
projectKey: input.projectKey,
|
|
574
|
+
planKey: input.planKey,
|
|
575
|
+
label: input.label,
|
|
576
|
+
description: input.description ?? null,
|
|
577
|
+
sortOrder: input.sortOrder ?? 0,
|
|
578
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
579
|
+
});
|
|
580
|
+
return {
|
|
581
|
+
created: true
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
async upsertPlanVersion(input) {
|
|
585
|
+
const existing = await this.db.select({
|
|
586
|
+
id: planVersions.id
|
|
587
|
+
}).from(planVersions).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(planVersions.planId, input.planKey), (0, import_drizzle_orm4.eq)(planVersions.version, input.version))).limit(1);
|
|
588
|
+
if (existing[0]) return {
|
|
589
|
+
created: false,
|
|
590
|
+
skipReason: "exists"
|
|
591
|
+
};
|
|
592
|
+
const now = /* @__PURE__ */ new Date();
|
|
593
|
+
if (input.publish) {
|
|
594
|
+
await this.db.update(planVersions).set({
|
|
595
|
+
supersededAt: now,
|
|
596
|
+
updatedAt: now
|
|
597
|
+
}).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(planVersions.planId, input.planKey), (0, import_drizzle_orm4.isNotNull)(planVersions.publishedAt), (0, import_drizzle_orm4.isNull)(planVersions.supersededAt), (0, import_drizzle_orm4.lt)(planVersions.version, input.version)));
|
|
598
|
+
}
|
|
599
|
+
await this.db.insert(planVersions).values({
|
|
600
|
+
id: (0, import_node_crypto2.randomUUID)(),
|
|
601
|
+
planId: input.planKey,
|
|
602
|
+
version: input.version,
|
|
603
|
+
features: input.features,
|
|
604
|
+
quotas: input.quotas,
|
|
605
|
+
monthlyNet: input.monthlyNet,
|
|
606
|
+
yearlyNet: input.yearlyNet,
|
|
607
|
+
marketed: input.marketed,
|
|
608
|
+
publishedAt: input.publish ? now : null,
|
|
609
|
+
changeNote: input.changeNote,
|
|
610
|
+
updatedAt: now
|
|
611
|
+
});
|
|
612
|
+
return {
|
|
613
|
+
created: true
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
async upsertFeatureCatalogEntry(input) {
|
|
617
|
+
const existing = await this.db.select({
|
|
618
|
+
id: featureCatalogEntries.id
|
|
619
|
+
}).from(featureCatalogEntries).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(featureCatalogEntries.projectKey, input.projectKey), (0, import_drizzle_orm4.eq)(featureCatalogEntries.featureKey, input.featureKey))).limit(1);
|
|
620
|
+
if (existing[0]) return {
|
|
621
|
+
created: false,
|
|
622
|
+
skipReason: "exists"
|
|
623
|
+
};
|
|
624
|
+
await this.db.insert(featureCatalogEntries).values({
|
|
625
|
+
id: (0, import_node_crypto2.randomUUID)(),
|
|
626
|
+
projectKey: input.projectKey,
|
|
627
|
+
featureKey: input.featureKey,
|
|
628
|
+
label: input.label ?? input.featureKey,
|
|
629
|
+
icon: input.icon ?? null,
|
|
630
|
+
tier: input.tier ?? null,
|
|
631
|
+
plannedOnly: input.plannedOnly ?? false,
|
|
632
|
+
core: input.core ?? false,
|
|
633
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
634
|
+
});
|
|
635
|
+
return {
|
|
636
|
+
created: true
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
DrizzlePlanCatalogImportSink = _ts_decorate6([
|
|
641
|
+
(0, import_common6.Injectable)(),
|
|
642
|
+
_ts_param5(0, (0, import_common6.Inject)(DRIZZLE_DB_TOKEN)),
|
|
643
|
+
_ts_metadata5("design:type", Function),
|
|
644
|
+
_ts_metadata5("design:paramtypes", [
|
|
645
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
646
|
+
])
|
|
647
|
+
], DrizzlePlanCatalogImportSink);
|
|
648
|
+
|
|
649
|
+
// src/drizzle-plan-catalog-read-sink.ts
|
|
650
|
+
var import_common7 = require("@nestjs/common");
|
|
651
|
+
var import_drizzle_orm5 = require("drizzle-orm");
|
|
652
|
+
function _ts_decorate7(decorators, target, key, desc4) {
|
|
653
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
654
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
655
|
+
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;
|
|
656
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
657
|
+
}
|
|
658
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
659
|
+
function _ts_metadata6(k, v) {
|
|
660
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
661
|
+
}
|
|
662
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
663
|
+
function _ts_param6(paramIndex, decorator) {
|
|
664
|
+
return function(target, key) {
|
|
665
|
+
decorator(target, key, paramIndex);
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
__name(_ts_param6, "_ts_param");
|
|
669
|
+
var DrizzlePlanCatalogReadSink = class {
|
|
670
|
+
static {
|
|
671
|
+
__name(this, "DrizzlePlanCatalogReadSink");
|
|
672
|
+
}
|
|
673
|
+
db;
|
|
674
|
+
constructor(db) {
|
|
675
|
+
this.db = db;
|
|
676
|
+
}
|
|
677
|
+
async loadSnapshot(projectKey) {
|
|
678
|
+
const planRows = await this.db.select().from(plans).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.eq)(plans.projectKey, projectKey), (0, import_drizzle_orm5.isNull)(plans.deletedAt))).orderBy((0, import_drizzle_orm5.asc)(plans.sortOrder));
|
|
679
|
+
const planKeys = planRows.map((plan) => plan.planKey);
|
|
680
|
+
const liveVersionRows = planKeys.length === 0 ? [] : await this.db.select().from(planVersions).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.inArray)(planVersions.planId, planKeys), (0, import_drizzle_orm5.isNotNull)(planVersions.publishedAt), (0, import_drizzle_orm5.isNull)(planVersions.supersededAt)));
|
|
681
|
+
const featureRows = await this.db.select().from(featureCatalogEntries).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.eq)(featureCatalogEntries.projectKey, projectKey), (0, import_drizzle_orm5.isNull)(featureCatalogEntries.deletedAt))).orderBy((0, import_drizzle_orm5.asc)(featureCatalogEntries.sortOrder));
|
|
682
|
+
return {
|
|
683
|
+
plans: planRows.map(toPlanRow),
|
|
684
|
+
livePlanVersions: liveVersionRows.map(toPlanVersionRow),
|
|
685
|
+
featureEntries: featureRows.map(toFeatureCatalogEntryRow)
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
DrizzlePlanCatalogReadSink = _ts_decorate7([
|
|
690
|
+
(0, import_common7.Injectable)(),
|
|
691
|
+
_ts_param6(0, (0, import_common7.Inject)(DRIZZLE_DB_TOKEN)),
|
|
692
|
+
_ts_metadata6("design:type", Function),
|
|
693
|
+
_ts_metadata6("design:paramtypes", [
|
|
694
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
695
|
+
])
|
|
696
|
+
], DrizzlePlanCatalogReadSink);
|
|
697
|
+
function toPlanRow(row) {
|
|
698
|
+
return {
|
|
699
|
+
id: row.id,
|
|
700
|
+
projectKey: row.projectKey,
|
|
701
|
+
planKey: row.planKey,
|
|
702
|
+
label: row.label,
|
|
703
|
+
description: row.description,
|
|
704
|
+
icon: row.icon,
|
|
705
|
+
sortOrder: row.sortOrder,
|
|
706
|
+
createdAt: row.createdAt.toISOString(),
|
|
707
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
708
|
+
deletedAt: row.deletedAt ? row.deletedAt.toISOString() : null
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
__name(toPlanRow, "toPlanRow");
|
|
712
|
+
function toPlanVersionRow(row) {
|
|
713
|
+
return {
|
|
714
|
+
id: row.id,
|
|
715
|
+
planId: row.planId,
|
|
716
|
+
version: row.version,
|
|
717
|
+
baseVersionId: row.baseVersionId,
|
|
718
|
+
publishedAt: row.publishedAt ? row.publishedAt.toISOString() : null,
|
|
719
|
+
supersededAt: row.supersededAt ? row.supersededAt.toISOString() : null,
|
|
720
|
+
publishedChanges: row.publishedChanges ?? null,
|
|
721
|
+
changeNote: row.changeNote,
|
|
722
|
+
nonRegressive: row.nonRegressive,
|
|
723
|
+
validFrom: null,
|
|
724
|
+
validUntil: null,
|
|
725
|
+
createdByUserId: row.createdByUserId,
|
|
726
|
+
publishedByUserId: row.publishedByUserId,
|
|
727
|
+
createdAt: row.createdAt.toISOString(),
|
|
728
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
729
|
+
features: toStringArray(row.features),
|
|
730
|
+
quotas: toQuotaMap(row.quotas),
|
|
731
|
+
monthlyNet: String(row.monthlyNet),
|
|
732
|
+
yearlyNet: String(row.yearlyNet),
|
|
733
|
+
marketed: row.marketed
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
__name(toPlanVersionRow, "toPlanVersionRow");
|
|
737
|
+
function toFeatureCatalogEntryRow(row) {
|
|
738
|
+
return {
|
|
739
|
+
id: row.id,
|
|
740
|
+
projectKey: row.projectKey,
|
|
741
|
+
featureKey: row.featureKey,
|
|
742
|
+
label: row.label,
|
|
743
|
+
description: row.description,
|
|
744
|
+
marketingLabel: row.marketingLabel,
|
|
745
|
+
marketingDescription: row.marketingDescription,
|
|
746
|
+
icon: row.icon,
|
|
747
|
+
tier: row.tier,
|
|
748
|
+
discoveryStatus: row.discoveryStatus,
|
|
749
|
+
requires: row.requires ?? [],
|
|
750
|
+
replaces: row.replaces ?? [],
|
|
751
|
+
successorKey: row.successorKey,
|
|
752
|
+
approvedAt: row.approvedAt ? row.approvedAt.toISOString() : null,
|
|
753
|
+
approvedBy: row.approvedBy,
|
|
754
|
+
approvedSignature: row.approvedSignature,
|
|
755
|
+
plannedOnly: row.plannedOnly,
|
|
756
|
+
core: row.core,
|
|
757
|
+
i18n: row.i18n ?? {},
|
|
758
|
+
sortOrder: row.sortOrder,
|
|
759
|
+
createdAt: row.createdAt.toISOString(),
|
|
760
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
761
|
+
deletedAt: row.deletedAt ? row.deletedAt.toISOString() : null
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
__name(toFeatureCatalogEntryRow, "toFeatureCatalogEntryRow");
|
|
765
|
+
|
|
766
|
+
// src/drizzle-plan-version.repository.ts
|
|
767
|
+
var import_common8 = require("@nestjs/common");
|
|
768
|
+
var import_drizzle_orm6 = require("drizzle-orm");
|
|
769
|
+
function _ts_decorate8(decorators, target, key, desc4) {
|
|
770
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
771
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
772
|
+
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;
|
|
773
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
774
|
+
}
|
|
775
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
776
|
+
function _ts_metadata7(k, v) {
|
|
777
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
778
|
+
}
|
|
779
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
780
|
+
function _ts_param7(paramIndex, decorator) {
|
|
781
|
+
return function(target, key) {
|
|
782
|
+
decorator(target, key, paramIndex);
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
__name(_ts_param7, "_ts_param");
|
|
786
|
+
var DrizzlePlanVersionRepository = class {
|
|
787
|
+
static {
|
|
788
|
+
__name(this, "DrizzlePlanVersionRepository");
|
|
789
|
+
}
|
|
790
|
+
db;
|
|
791
|
+
constructor(db) {
|
|
792
|
+
this.db = db;
|
|
793
|
+
}
|
|
794
|
+
async findLatestLive(planId, tx) {
|
|
795
|
+
const db = resolveDb(this.db, tx);
|
|
796
|
+
const rows = await db.select().from(planVersions).where((0, import_drizzle_orm6.and)((0, import_drizzle_orm6.eq)(planVersions.planId, planId), (0, import_drizzle_orm6.isNotNull)(planVersions.publishedAt), (0, import_drizzle_orm6.isNull)(planVersions.supersededAt))).orderBy((0, import_drizzle_orm6.desc)(planVersions.version)).limit(1);
|
|
797
|
+
const row = rows[0];
|
|
798
|
+
if (!row) return null;
|
|
799
|
+
return {
|
|
800
|
+
planId: row.planId,
|
|
801
|
+
quotas: toQuotaMap(row.quotas),
|
|
802
|
+
features: toStringArray(row.features)
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
DrizzlePlanVersionRepository = _ts_decorate8([
|
|
807
|
+
(0, import_common8.Injectable)(),
|
|
808
|
+
_ts_param7(0, (0, import_common8.Inject)(DRIZZLE_DB_TOKEN)),
|
|
809
|
+
_ts_metadata7("design:type", Function),
|
|
810
|
+
_ts_metadata7("design:paramtypes", [
|
|
811
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
812
|
+
])
|
|
813
|
+
], DrizzlePlanVersionRepository);
|
|
814
|
+
|
|
815
|
+
// src/drizzle-promo-code-redemption.repository.ts
|
|
816
|
+
var import_node_crypto3 = require("node:crypto");
|
|
817
|
+
var import_common9 = require("@nestjs/common");
|
|
818
|
+
var import_drizzle_orm7 = require("drizzle-orm");
|
|
819
|
+
function _ts_decorate9(decorators, target, key, desc4) {
|
|
820
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
821
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
822
|
+
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;
|
|
823
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
824
|
+
}
|
|
825
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
826
|
+
function _ts_metadata8(k, v) {
|
|
827
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
828
|
+
}
|
|
829
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
830
|
+
function _ts_param8(paramIndex, decorator) {
|
|
831
|
+
return function(target, key) {
|
|
832
|
+
decorator(target, key, paramIndex);
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
__name(_ts_param8, "_ts_param");
|
|
836
|
+
var DrizzlePromoCodeRedemptionRepository = class {
|
|
837
|
+
static {
|
|
838
|
+
__name(this, "DrizzlePromoCodeRedemptionRepository");
|
|
839
|
+
}
|
|
840
|
+
db;
|
|
841
|
+
constructor(db) {
|
|
842
|
+
this.db = db;
|
|
843
|
+
}
|
|
844
|
+
async findBySubscription(subscriptionId, tx) {
|
|
845
|
+
const db = resolveDb(this.db, tx);
|
|
846
|
+
const rows = await db.select().from(promoCodeRedemptions).where((0, import_drizzle_orm7.eq)(promoCodeRedemptions.subscriptionId, subscriptionId)).limit(1);
|
|
847
|
+
const row = rows[0];
|
|
848
|
+
return row ? toRecord(row) : null;
|
|
849
|
+
}
|
|
850
|
+
async create(data, tx) {
|
|
851
|
+
const db = resolveDb(this.db, tx);
|
|
852
|
+
const rows = await db.insert(promoCodeRedemptions).values({
|
|
853
|
+
id: (0, import_node_crypto3.randomUUID)(),
|
|
854
|
+
promoCodeId: data.promoCodeId,
|
|
855
|
+
subscriptionId: data.subscriptionId,
|
|
856
|
+
tenantId: data.tenantId,
|
|
857
|
+
appliedValueType: data.appliedValueType,
|
|
858
|
+
appliedValue: data.appliedValue,
|
|
859
|
+
appliedDurationType: data.appliedDurationType,
|
|
860
|
+
appliedDurationValue: data.appliedDurationValue,
|
|
861
|
+
startsAt: data.startsAt,
|
|
862
|
+
endsAt: data.endsAt
|
|
863
|
+
}).returning();
|
|
864
|
+
return toRecord(rows[0]);
|
|
865
|
+
}
|
|
866
|
+
async setReversed(id, tx) {
|
|
867
|
+
const db = resolveDb(this.db, tx);
|
|
868
|
+
const rows = await db.update(promoCodeRedemptions).set({
|
|
869
|
+
status: "REVERSED",
|
|
870
|
+
reversedAt: /* @__PURE__ */ new Date()
|
|
871
|
+
}).where((0, import_drizzle_orm7.eq)(promoCodeRedemptions.id, id)).returning();
|
|
872
|
+
const row = rows[0];
|
|
873
|
+
if (!row) {
|
|
874
|
+
throw new Error(`PromoCodeRedemption ${id} not found.`);
|
|
875
|
+
}
|
|
876
|
+
return toRecord(row);
|
|
877
|
+
}
|
|
878
|
+
async countByPromoCode(promoCodeId, status) {
|
|
879
|
+
const rows = await this.db.select({
|
|
880
|
+
id: promoCodeRedemptions.id
|
|
881
|
+
}).from(promoCodeRedemptions).where((0, import_drizzle_orm7.and)((0, import_drizzle_orm7.eq)(promoCodeRedemptions.promoCodeId, promoCodeId), status ? (0, import_drizzle_orm7.eq)(promoCodeRedemptions.status, status) : void 0));
|
|
882
|
+
return rows.length;
|
|
883
|
+
}
|
|
884
|
+
async listByPromoCode(promoCodeId) {
|
|
885
|
+
const rows = await this.db.select().from(promoCodeRedemptions).where((0, import_drizzle_orm7.eq)(promoCodeRedemptions.promoCodeId, promoCodeId)).orderBy((0, import_drizzle_orm7.desc)(promoCodeRedemptions.redeemedAt));
|
|
886
|
+
return rows.map(toRecord);
|
|
887
|
+
}
|
|
888
|
+
async expireDueRedemptions(now) {
|
|
889
|
+
const expired = await this.db.update(promoCodeRedemptions).set({
|
|
890
|
+
status: "EXPIRED"
|
|
891
|
+
}).where((0, import_drizzle_orm7.and)((0, import_drizzle_orm7.eq)(promoCodeRedemptions.status, "ACTIVE"), (0, import_drizzle_orm7.lt)(promoCodeRedemptions.endsAt, now))).returning({
|
|
892
|
+
id: promoCodeRedemptions.id
|
|
893
|
+
});
|
|
894
|
+
return expired.length;
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
DrizzlePromoCodeRedemptionRepository = _ts_decorate9([
|
|
898
|
+
(0, import_common9.Injectable)(),
|
|
899
|
+
_ts_param8(0, (0, import_common9.Inject)(DRIZZLE_DB_TOKEN)),
|
|
900
|
+
_ts_metadata8("design:type", Function),
|
|
901
|
+
_ts_metadata8("design:paramtypes", [
|
|
902
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
903
|
+
])
|
|
904
|
+
], DrizzlePromoCodeRedemptionRepository);
|
|
905
|
+
function toRecord(row) {
|
|
906
|
+
return {
|
|
907
|
+
id: row.id,
|
|
908
|
+
promoCodeId: row.promoCodeId,
|
|
909
|
+
subscriptionId: row.subscriptionId,
|
|
910
|
+
tenantId: row.tenantId,
|
|
911
|
+
appliedValueType: row.appliedValueType,
|
|
912
|
+
appliedValue: String(row.appliedValue),
|
|
913
|
+
appliedDurationType: row.appliedDurationType,
|
|
914
|
+
appliedDurationValue: row.appliedDurationValue,
|
|
915
|
+
startsAt: row.startsAt,
|
|
916
|
+
endsAt: row.endsAt,
|
|
917
|
+
status: row.status,
|
|
918
|
+
redeemedAt: row.redeemedAt,
|
|
919
|
+
reversedAt: row.reversedAt
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
__name(toRecord, "toRecord");
|
|
923
|
+
|
|
924
|
+
// src/drizzle-promo-code.repository.ts
|
|
925
|
+
var import_node_crypto4 = require("node:crypto");
|
|
926
|
+
var import_common10 = require("@nestjs/common");
|
|
927
|
+
var import_drizzle_orm8 = require("drizzle-orm");
|
|
928
|
+
function _ts_decorate10(decorators, target, key, desc4) {
|
|
929
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
930
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
931
|
+
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;
|
|
932
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
933
|
+
}
|
|
934
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
935
|
+
function _ts_metadata9(k, v) {
|
|
936
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
937
|
+
}
|
|
938
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
939
|
+
function _ts_param9(paramIndex, decorator) {
|
|
940
|
+
return function(target, key) {
|
|
941
|
+
decorator(target, key, paramIndex);
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
__name(_ts_param9, "_ts_param");
|
|
945
|
+
var DrizzlePromoCodeRepository = class {
|
|
946
|
+
static {
|
|
947
|
+
__name(this, "DrizzlePromoCodeRepository");
|
|
948
|
+
}
|
|
949
|
+
db;
|
|
950
|
+
constructor(db) {
|
|
951
|
+
this.db = db;
|
|
952
|
+
}
|
|
953
|
+
async findById(id) {
|
|
954
|
+
const rows = await this.db.select().from(promoCodes).where((0, import_drizzle_orm8.eq)(promoCodes.id, id)).limit(1);
|
|
955
|
+
const row = rows[0];
|
|
956
|
+
return row ? toRecord2(row) : null;
|
|
957
|
+
}
|
|
958
|
+
async findByCode(code, tx) {
|
|
959
|
+
const db = resolveDb(this.db, tx);
|
|
960
|
+
const rows = await db.select().from(promoCodes).where((0, import_drizzle_orm8.eq)(promoCodes.code, normalizeCode(code))).limit(1);
|
|
961
|
+
const row = rows[0];
|
|
962
|
+
if (!row || row.deletedAt) return null;
|
|
963
|
+
return toRecord2(row);
|
|
964
|
+
}
|
|
965
|
+
async findMany(filter) {
|
|
966
|
+
const conditions = [
|
|
967
|
+
(0, import_drizzle_orm8.isNull)(promoCodes.deletedAt),
|
|
968
|
+
filter.status ? (0, import_drizzle_orm8.eq)(promoCodes.status, filter.status) : void 0,
|
|
969
|
+
filter.campaignTag ? (0, import_drizzle_orm8.eq)(promoCodes.campaignTag, filter.campaignTag) : void 0,
|
|
970
|
+
filter.search ? (0, import_drizzle_orm8.like)(promoCodes.code, `%${escapeLikePattern(normalizeCode(filter.search))}%`) : void 0
|
|
971
|
+
];
|
|
972
|
+
const rows = await this.db.select().from(promoCodes).where((0, import_drizzle_orm8.and)(...conditions)).orderBy(import_drizzle_orm8.sql`${promoCodes.createdAt} DESC`);
|
|
973
|
+
return rows.map(toRecord2);
|
|
974
|
+
}
|
|
975
|
+
async create(data) {
|
|
976
|
+
const rows = await this.db.insert(promoCodes).values({
|
|
977
|
+
id: (0, import_node_crypto4.randomUUID)(),
|
|
978
|
+
code: normalizeCode(data.code),
|
|
979
|
+
valueType: data.valueType,
|
|
980
|
+
value: data.value.toFixed(2),
|
|
981
|
+
durationType: data.durationType,
|
|
982
|
+
durationValue: data.durationValue ?? null,
|
|
983
|
+
validFrom: data.validFrom ?? null,
|
|
984
|
+
validUntil: data.validUntil ?? null,
|
|
985
|
+
maxRedemptions: data.maxRedemptions ?? null,
|
|
986
|
+
appliesToPlans: data.appliesToPlans ?? [],
|
|
987
|
+
appliesToBilling: data.appliesToBilling ?? null,
|
|
988
|
+
firstTimeCustomersOnly: data.firstTimeCustomersOnly ?? true,
|
|
989
|
+
minimumPlanAmountGross: data.minimumPlanAmountGross?.toFixed(2) ?? null,
|
|
990
|
+
allowZeroInvoice: data.allowZeroInvoice ?? false,
|
|
991
|
+
description: data.description ?? null,
|
|
992
|
+
campaignTag: data.campaignTag ?? null,
|
|
993
|
+
revenueDeductionAccount: data.revenueDeductionAccount ?? null,
|
|
994
|
+
createdById: data.createdById,
|
|
995
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
996
|
+
}).returning();
|
|
997
|
+
return toRecord2(rows[0]);
|
|
998
|
+
}
|
|
999
|
+
async update(id, data) {
|
|
1000
|
+
const rows = await this.db.update(promoCodes).set({
|
|
1001
|
+
status: data.status,
|
|
1002
|
+
description: data.description,
|
|
1003
|
+
validUntil: data.validUntil,
|
|
1004
|
+
maxRedemptions: data.maxRedemptions,
|
|
1005
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1006
|
+
}).where((0, import_drizzle_orm8.eq)(promoCodes.id, id)).returning();
|
|
1007
|
+
const row = rows[0];
|
|
1008
|
+
if (!row) {
|
|
1009
|
+
throw new Error(`PromoCode ${id} not found.`);
|
|
1010
|
+
}
|
|
1011
|
+
return toRecord2(row);
|
|
1012
|
+
}
|
|
1013
|
+
async softDelete(id) {
|
|
1014
|
+
await this.db.update(promoCodes).set({
|
|
1015
|
+
deletedAt: /* @__PURE__ */ new Date(),
|
|
1016
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1017
|
+
}).where((0, import_drizzle_orm8.eq)(promoCodes.id, id));
|
|
1018
|
+
}
|
|
1019
|
+
async claimSlot(id, tx) {
|
|
1020
|
+
const db = resolveDb(this.db, tx);
|
|
1021
|
+
const claimed = await db.update(promoCodes).set({
|
|
1022
|
+
redemptionsCount: import_drizzle_orm8.sql`${promoCodes.redemptionsCount} + 1`,
|
|
1023
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1024
|
+
}).where((0, import_drizzle_orm8.and)((0, import_drizzle_orm8.eq)(promoCodes.id, id), (0, import_drizzle_orm8.eq)(promoCodes.status, "ACTIVE"), (0, import_drizzle_orm8.isNull)(promoCodes.deletedAt), (0, import_drizzle_orm8.or)((0, import_drizzle_orm8.isNull)(promoCodes.maxRedemptions), (0, import_drizzle_orm8.lt)(promoCodes.redemptionsCount, promoCodes.maxRedemptions)))).returning({
|
|
1025
|
+
id: promoCodes.id
|
|
1026
|
+
});
|
|
1027
|
+
return claimed.length === 1;
|
|
1028
|
+
}
|
|
1029
|
+
async markExhaustedIfFull(id, tx) {
|
|
1030
|
+
const db = resolveDb(this.db, tx);
|
|
1031
|
+
await db.update(promoCodes).set({
|
|
1032
|
+
status: "EXHAUSTED",
|
|
1033
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1034
|
+
}).where((0, import_drizzle_orm8.and)((0, import_drizzle_orm8.eq)(promoCodes.id, id), (0, import_drizzle_orm8.eq)(promoCodes.status, "ACTIVE"), (0, import_drizzle_orm8.isNotNull)(promoCodes.maxRedemptions), (0, import_drizzle_orm8.gte)(promoCodes.redemptionsCount, promoCodes.maxRedemptions)));
|
|
1035
|
+
}
|
|
1036
|
+
async releaseSlot(id, tx) {
|
|
1037
|
+
const db = resolveDb(this.db, tx);
|
|
1038
|
+
await db.update(promoCodes).set({
|
|
1039
|
+
redemptionsCount: import_drizzle_orm8.sql`GREATEST(${promoCodes.redemptionsCount} - 1, 0)`,
|
|
1040
|
+
status: import_drizzle_orm8.sql`CASE WHEN ${promoCodes.status} = 'EXHAUSTED' THEN 'ACTIVE' ELSE ${promoCodes.status} END`,
|
|
1041
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1042
|
+
}).where((0, import_drizzle_orm8.eq)(promoCodes.id, id));
|
|
1043
|
+
}
|
|
1044
|
+
async expireDueCodes(now) {
|
|
1045
|
+
const expired = await this.db.update(promoCodes).set({
|
|
1046
|
+
status: "EXPIRED",
|
|
1047
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1048
|
+
}).where((0, import_drizzle_orm8.and)((0, import_drizzle_orm8.inArray)(promoCodes.status, [
|
|
1049
|
+
"ACTIVE",
|
|
1050
|
+
"PAUSED"
|
|
1051
|
+
]), (0, import_drizzle_orm8.lt)(promoCodes.validUntil, now))).returning({
|
|
1052
|
+
id: promoCodes.id
|
|
1053
|
+
});
|
|
1054
|
+
return expired.length;
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
DrizzlePromoCodeRepository = _ts_decorate10([
|
|
1058
|
+
(0, import_common10.Injectable)(),
|
|
1059
|
+
_ts_param9(0, (0, import_common10.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1060
|
+
_ts_metadata9("design:type", Function),
|
|
1061
|
+
_ts_metadata9("design:paramtypes", [
|
|
1062
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1063
|
+
])
|
|
1064
|
+
], DrizzlePromoCodeRepository);
|
|
1065
|
+
function normalizeCode(code) {
|
|
1066
|
+
return code.trim().toUpperCase();
|
|
1067
|
+
}
|
|
1068
|
+
__name(normalizeCode, "normalizeCode");
|
|
1069
|
+
function toRecord2(row) {
|
|
1070
|
+
return {
|
|
1071
|
+
id: row.id,
|
|
1072
|
+
code: row.code,
|
|
1073
|
+
valueType: row.valueType,
|
|
1074
|
+
value: String(row.value),
|
|
1075
|
+
durationType: row.durationType,
|
|
1076
|
+
durationValue: row.durationValue,
|
|
1077
|
+
validFrom: row.validFrom,
|
|
1078
|
+
validUntil: row.validUntil,
|
|
1079
|
+
maxRedemptions: row.maxRedemptions,
|
|
1080
|
+
redemptionsCount: row.redemptionsCount,
|
|
1081
|
+
appliesToPlans: row.appliesToPlans ?? [],
|
|
1082
|
+
appliesToBilling: row.appliesToBilling ?? null,
|
|
1083
|
+
firstTimeCustomersOnly: row.firstTimeCustomersOnly,
|
|
1084
|
+
minimumPlanAmountGross: row.minimumPlanAmountGross === null ? null : String(row.minimumPlanAmountGross),
|
|
1085
|
+
allowZeroInvoice: row.allowZeroInvoice,
|
|
1086
|
+
status: row.status,
|
|
1087
|
+
description: row.description,
|
|
1088
|
+
campaignTag: row.campaignTag,
|
|
1089
|
+
revenueDeductionAccount: row.revenueDeductionAccount,
|
|
1090
|
+
createdById: row.createdById,
|
|
1091
|
+
createdAt: row.createdAt,
|
|
1092
|
+
updatedAt: row.updatedAt,
|
|
1093
|
+
deletedAt: row.deletedAt
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
__name(toRecord2, "toRecord");
|
|
1097
|
+
|
|
1098
|
+
// src/drizzle-promo-code-validation-log.repository.ts
|
|
1099
|
+
var import_node_crypto5 = require("node:crypto");
|
|
1100
|
+
var import_common11 = require("@nestjs/common");
|
|
1101
|
+
var import_drizzle_orm9 = require("drizzle-orm");
|
|
1102
|
+
function _ts_decorate11(decorators, target, key, desc4) {
|
|
1103
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
1104
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
1105
|
+
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;
|
|
1106
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1107
|
+
}
|
|
1108
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1109
|
+
function _ts_metadata10(k, v) {
|
|
1110
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1111
|
+
}
|
|
1112
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
1113
|
+
function _ts_param10(paramIndex, decorator) {
|
|
1114
|
+
return function(target, key) {
|
|
1115
|
+
decorator(target, key, paramIndex);
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
__name(_ts_param10, "_ts_param");
|
|
1119
|
+
var DrizzlePromoCodeValidationLogRepository = class {
|
|
1120
|
+
static {
|
|
1121
|
+
__name(this, "DrizzlePromoCodeValidationLogRepository");
|
|
1122
|
+
}
|
|
1123
|
+
db;
|
|
1124
|
+
constructor(db) {
|
|
1125
|
+
this.db = db;
|
|
1126
|
+
}
|
|
1127
|
+
async log(args) {
|
|
1128
|
+
await this.db.insert(promoCodeValidationLogs).values({
|
|
1129
|
+
id: (0, import_node_crypto5.randomUUID)(),
|
|
1130
|
+
promoCodeId: args.promoCodeId,
|
|
1131
|
+
codeAttempt: args.codeAttempt.trim().toUpperCase(),
|
|
1132
|
+
result: args.result,
|
|
1133
|
+
ipHash: args.ipHash ?? null,
|
|
1134
|
+
sessionId: args.sessionId ?? null
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
async countValid(promoCodeId) {
|
|
1138
|
+
const rows = await this.db.select({
|
|
1139
|
+
id: promoCodeValidationLogs.id
|
|
1140
|
+
}).from(promoCodeValidationLogs).where((0, import_drizzle_orm9.and)((0, import_drizzle_orm9.eq)(promoCodeValidationLogs.promoCodeId, promoCodeId), (0, import_drizzle_orm9.eq)(promoCodeValidationLogs.result, "VALID")));
|
|
1141
|
+
return rows.length;
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
DrizzlePromoCodeValidationLogRepository = _ts_decorate11([
|
|
1145
|
+
(0, import_common11.Injectable)(),
|
|
1146
|
+
_ts_param10(0, (0, import_common11.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1147
|
+
_ts_metadata10("design:type", Function),
|
|
1148
|
+
_ts_metadata10("design:paramtypes", [
|
|
1149
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1150
|
+
])
|
|
1151
|
+
], DrizzlePromoCodeValidationLogRepository);
|
|
1152
|
+
|
|
1153
|
+
// src/drizzle-promo-subscription-lookup.ts
|
|
1154
|
+
var import_common12 = require("@nestjs/common");
|
|
1155
|
+
var import_drizzle_orm10 = require("drizzle-orm");
|
|
1156
|
+
function _ts_decorate12(decorators, target, key, desc4) {
|
|
1157
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
1158
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
1159
|
+
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;
|
|
1160
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1161
|
+
}
|
|
1162
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1163
|
+
function _ts_metadata11(k, v) {
|
|
1164
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1165
|
+
}
|
|
1166
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
1167
|
+
function _ts_param11(paramIndex, decorator) {
|
|
1168
|
+
return function(target, key) {
|
|
1169
|
+
decorator(target, key, paramIndex);
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
__name(_ts_param11, "_ts_param");
|
|
1173
|
+
var DrizzlePromoSubscriptionLookup = class {
|
|
1174
|
+
static {
|
|
1175
|
+
__name(this, "DrizzlePromoSubscriptionLookup");
|
|
1176
|
+
}
|
|
1177
|
+
db;
|
|
1178
|
+
constructor(db) {
|
|
1179
|
+
this.db = db;
|
|
1180
|
+
}
|
|
1181
|
+
async findById(subscriptionId, tx) {
|
|
1182
|
+
const db = resolveDb(this.db, tx);
|
|
1183
|
+
const rows = await db.select({
|
|
1184
|
+
id: subscriptions.id,
|
|
1185
|
+
tenantId: subscriptions.tenantId,
|
|
1186
|
+
plan: subscriptions.plan,
|
|
1187
|
+
billingCycle: subscriptions.billingCycle,
|
|
1188
|
+
startedAt: subscriptions.startedAt
|
|
1189
|
+
}).from(subscriptions).where((0, import_drizzle_orm10.eq)(subscriptions.id, subscriptionId)).limit(1);
|
|
1190
|
+
const row = rows[0];
|
|
1191
|
+
if (!row) return null;
|
|
1192
|
+
return {
|
|
1193
|
+
id: row.id,
|
|
1194
|
+
tenantId: row.tenantId,
|
|
1195
|
+
plan: row.plan,
|
|
1196
|
+
billingCycle: row.billingCycle,
|
|
1197
|
+
startedAt: row.startedAt
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
DrizzlePromoSubscriptionLookup = _ts_decorate12([
|
|
1202
|
+
(0, import_common12.Injectable)(),
|
|
1203
|
+
_ts_param11(0, (0, import_common12.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1204
|
+
_ts_metadata11("design:type", Function),
|
|
1205
|
+
_ts_metadata11("design:paramtypes", [
|
|
1206
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1207
|
+
])
|
|
1208
|
+
], DrizzlePromoSubscriptionLookup);
|
|
1209
|
+
|
|
1210
|
+
// src/drizzle-subscription.repository.ts
|
|
1211
|
+
var import_common13 = require("@nestjs/common");
|
|
1212
|
+
var import_drizzle_orm11 = require("drizzle-orm");
|
|
1213
|
+
function _ts_decorate13(decorators, target, key, desc4) {
|
|
1214
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
1215
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
1216
|
+
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;
|
|
1217
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1218
|
+
}
|
|
1219
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1220
|
+
function _ts_metadata12(k, v) {
|
|
1221
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1222
|
+
}
|
|
1223
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
1224
|
+
function _ts_param12(paramIndex, decorator) {
|
|
1225
|
+
return function(target, key) {
|
|
1226
|
+
decorator(target, key, paramIndex);
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
__name(_ts_param12, "_ts_param");
|
|
1230
|
+
var ACTIVE_STATUSES = [
|
|
1231
|
+
"ACTIVE",
|
|
1232
|
+
"TRIAL"
|
|
1233
|
+
];
|
|
1234
|
+
var DrizzleSubscriptionRepository = class {
|
|
1235
|
+
static {
|
|
1236
|
+
__name(this, "DrizzleSubscriptionRepository");
|
|
1237
|
+
}
|
|
1238
|
+
db;
|
|
1239
|
+
constructor(db) {
|
|
1240
|
+
this.db = db;
|
|
1241
|
+
}
|
|
1242
|
+
async findByTenantId(tenantId) {
|
|
1243
|
+
return this.loadByTenantId(this.db, tenantId);
|
|
1244
|
+
}
|
|
1245
|
+
async findByTenantIdLocked(tenantId, tx) {
|
|
1246
|
+
const db = resolveDb(this.db, tx);
|
|
1247
|
+
await db.select({
|
|
1248
|
+
id: subscriptions.id
|
|
1249
|
+
}).from(subscriptions).where((0, import_drizzle_orm11.eq)(subscriptions.tenantId, tenantId)).for("update");
|
|
1250
|
+
return this.loadByTenantId(db, tenantId);
|
|
1251
|
+
}
|
|
1252
|
+
async countByPlanVersionId(planVersionId) {
|
|
1253
|
+
const rows = await this.db.select({
|
|
1254
|
+
id: subscriptions.id
|
|
1255
|
+
}).from(subscriptions).where((0, import_drizzle_orm11.or)((0, import_drizzle_orm11.eq)(subscriptions.planVersionId, planVersionId), (0, import_drizzle_orm11.eq)(subscriptions.pendingPlanVersionId, planVersionId)));
|
|
1256
|
+
return rows.length;
|
|
1257
|
+
}
|
|
1258
|
+
async countActiveByPlanKey(_projectKey) {
|
|
1259
|
+
const rows = await this.db.select({
|
|
1260
|
+
plan: subscriptions.plan
|
|
1261
|
+
}).from(subscriptions).where((0, import_drizzle_orm11.inArray)(subscriptions.status, ACTIVE_STATUSES));
|
|
1262
|
+
const counts = {};
|
|
1263
|
+
for (const row of rows) {
|
|
1264
|
+
counts[row.plan] = (counts[row.plan] ?? 0) + 1;
|
|
1265
|
+
}
|
|
1266
|
+
return counts;
|
|
1267
|
+
}
|
|
1268
|
+
async loadByTenantId(db, tenantId) {
|
|
1269
|
+
const rows = await db.select().from(subscriptions).where((0, import_drizzle_orm11.eq)(subscriptions.tenantId, tenantId)).limit(1);
|
|
1270
|
+
const row = rows[0];
|
|
1271
|
+
if (!row) return null;
|
|
1272
|
+
return this.toRecord(db, row);
|
|
1273
|
+
}
|
|
1274
|
+
async toRecord(db, row) {
|
|
1275
|
+
if (!row.planVersionId) {
|
|
1276
|
+
throw new Error(`Subscription ${row.id} binds no planVersionId (businessType-only composition). The shipped @saasicat/adapter-drizzle SubscriptionRepository does not support BusinessType aggregation \u2014 provide a custom SubscriptionRepository adapter.`);
|
|
1277
|
+
}
|
|
1278
|
+
const versionRows = await db.select().from(planVersions).where((0, import_drizzle_orm11.eq)(planVersions.id, row.planVersionId)).limit(1);
|
|
1279
|
+
const planVersion = versionRows[0];
|
|
1280
|
+
if (!planVersion) {
|
|
1281
|
+
throw new Error(`Subscription ${row.id} references missing PlanVersion ${row.planVersionId}.`);
|
|
1282
|
+
}
|
|
1283
|
+
return {
|
|
1284
|
+
id: row.id,
|
|
1285
|
+
tenantId: row.tenantId,
|
|
1286
|
+
plan: row.plan,
|
|
1287
|
+
status: row.status,
|
|
1288
|
+
isPilot: row.isPilot,
|
|
1289
|
+
trialEntitlementPlan: row.trialEntitlementPlan,
|
|
1290
|
+
pendingPlan: row.pendingPlan,
|
|
1291
|
+
pendingEffectiveAt: row.pendingEffectiveAt,
|
|
1292
|
+
customLimits: row.customLimits ?? null,
|
|
1293
|
+
planVersionId: row.planVersionId,
|
|
1294
|
+
planVersion: {
|
|
1295
|
+
planId: planVersion.planId,
|
|
1296
|
+
quotas: toQuotaMap(planVersion.quotas),
|
|
1297
|
+
features: toStringArray(planVersion.features)
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
DrizzleSubscriptionRepository = _ts_decorate13([
|
|
1303
|
+
(0, import_common13.Injectable)(),
|
|
1304
|
+
_ts_param12(0, (0, import_common13.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1305
|
+
_ts_metadata12("design:type", Function),
|
|
1306
|
+
_ts_metadata12("design:paramtypes", [
|
|
1307
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1308
|
+
])
|
|
1309
|
+
], DrizzleSubscriptionRepository);
|
|
1310
|
+
|
|
1311
|
+
// src/drizzle-super-admin-bootstrap.adapter.ts
|
|
1312
|
+
var import_node_crypto6 = require("node:crypto");
|
|
1313
|
+
var import_common14 = require("@nestjs/common");
|
|
1314
|
+
var import_drizzle_orm12 = require("drizzle-orm");
|
|
1315
|
+
var import_types = require("@saasicat/types");
|
|
1316
|
+
function _ts_decorate14(decorators, target, key, desc4) {
|
|
1317
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
1318
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
1319
|
+
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;
|
|
1320
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1321
|
+
}
|
|
1322
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
1323
|
+
function _ts_metadata13(k, v) {
|
|
1324
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1325
|
+
}
|
|
1326
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
1327
|
+
function _ts_param13(paramIndex, decorator) {
|
|
1328
|
+
return function(target, key) {
|
|
1329
|
+
decorator(target, key, paramIndex);
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
__name(_ts_param13, "_ts_param");
|
|
1333
|
+
var PASSWORD_HASHER_TOKEN = /* @__PURE__ */ Symbol.for("saasicat/adapter-drizzle/PasswordHasher");
|
|
1334
|
+
var DrizzleSuperAdminBootstrapAdapter = class {
|
|
1335
|
+
static {
|
|
1336
|
+
__name(this, "DrizzleSuperAdminBootstrapAdapter");
|
|
1337
|
+
}
|
|
1338
|
+
db;
|
|
1339
|
+
passwordHasher;
|
|
1340
|
+
constructor(db, passwordHasher) {
|
|
1341
|
+
this.db = db;
|
|
1342
|
+
this.passwordHasher = passwordHasher;
|
|
1343
|
+
}
|
|
1344
|
+
async countSuperAdmins() {
|
|
1345
|
+
const rows = await this.db.select({
|
|
1346
|
+
value: (0, import_drizzle_orm12.count)()
|
|
1347
|
+
}).from(superAdminUsers).where((0, import_drizzle_orm12.and)((0, import_drizzle_orm12.eq)(superAdminUsers.isActive, true), (0, import_drizzle_orm12.isNull)(superAdminUsers.deletedAt)));
|
|
1348
|
+
return rows[0]?.value ?? 0;
|
|
1349
|
+
}
|
|
1350
|
+
async createSuperAdmin(input) {
|
|
1351
|
+
const email = input.email.trim().toLowerCase();
|
|
1352
|
+
const existing = await this.db.select().from(superAdminUsers).where((0, import_drizzle_orm12.eq)(superAdminUsers.email, email)).limit(1);
|
|
1353
|
+
if (existing[0]) {
|
|
1354
|
+
throw new import_types.PlatformUserExistsError(email, existing[0].platformRole);
|
|
1355
|
+
}
|
|
1356
|
+
const rows = await this.db.insert(superAdminUsers).values({
|
|
1357
|
+
id: (0, import_node_crypto6.randomUUID)(),
|
|
1358
|
+
email,
|
|
1359
|
+
passwordHash: await this.passwordHasher.hash(input.password),
|
|
1360
|
+
firstName: input.firstName ?? null,
|
|
1361
|
+
lastName: input.lastName ?? null,
|
|
1362
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1363
|
+
}).returning();
|
|
1364
|
+
const row = rows[0];
|
|
1365
|
+
return {
|
|
1366
|
+
id: row.id,
|
|
1367
|
+
email: row.email,
|
|
1368
|
+
firstName: row.firstName ?? void 0,
|
|
1369
|
+
lastName: row.lastName ?? void 0,
|
|
1370
|
+
platformRole: row.platformRole,
|
|
1371
|
+
isActive: row.isActive,
|
|
1372
|
+
lastLoginAt: null,
|
|
1373
|
+
deletedAt: null
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
DrizzleSuperAdminBootstrapAdapter = _ts_decorate14([
|
|
1378
|
+
(0, import_common14.Injectable)(),
|
|
1379
|
+
_ts_param13(0, (0, import_common14.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1380
|
+
_ts_param13(1, (0, import_common14.Inject)(PASSWORD_HASHER_TOKEN)),
|
|
1381
|
+
_ts_metadata13("design:type", Function),
|
|
1382
|
+
_ts_metadata13("design:paramtypes", [
|
|
1383
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient,
|
|
1384
|
+
typeof PasswordHasher === "undefined" ? Object : PasswordHasher
|
|
1385
|
+
])
|
|
1386
|
+
], DrizzleSuperAdminBootstrapAdapter);
|
|
1387
|
+
|
|
1388
|
+
// src/drizzle-transaction-runner.ts
|
|
1389
|
+
var import_common15 = require("@nestjs/common");
|
|
1390
|
+
function _ts_decorate15(decorators, target, key, desc4) {
|
|
1391
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
1392
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
1393
|
+
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;
|
|
1394
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1395
|
+
}
|
|
1396
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
1397
|
+
function _ts_metadata14(k, v) {
|
|
1398
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1399
|
+
}
|
|
1400
|
+
__name(_ts_metadata14, "_ts_metadata");
|
|
1401
|
+
function _ts_param14(paramIndex, decorator) {
|
|
1402
|
+
return function(target, key) {
|
|
1403
|
+
decorator(target, key, paramIndex);
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
__name(_ts_param14, "_ts_param");
|
|
1407
|
+
var DrizzleTransactionRunner = class {
|
|
1408
|
+
static {
|
|
1409
|
+
__name(this, "DrizzleTransactionRunner");
|
|
1410
|
+
}
|
|
1411
|
+
db;
|
|
1412
|
+
constructor(db) {
|
|
1413
|
+
this.db = db;
|
|
1414
|
+
}
|
|
1415
|
+
async run(fn) {
|
|
1416
|
+
return this.db.transaction((tx) => fn(tx));
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
DrizzleTransactionRunner = _ts_decorate15([
|
|
1420
|
+
(0, import_common15.Injectable)(),
|
|
1421
|
+
_ts_param14(0, (0, import_common15.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1422
|
+
_ts_metadata14("design:type", Function),
|
|
1423
|
+
_ts_metadata14("design:paramtypes", [
|
|
1424
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1425
|
+
])
|
|
1426
|
+
], DrizzleTransactionRunner);
|
|
1427
|
+
|
|
1428
|
+
// src/zero-promo-revenue-aggregator.ts
|
|
1429
|
+
var import_common16 = require("@nestjs/common");
|
|
1430
|
+
function _ts_decorate16(decorators, target, key, desc4) {
|
|
1431
|
+
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
1432
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc4);
|
|
1433
|
+
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;
|
|
1434
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1435
|
+
}
|
|
1436
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
1437
|
+
var ZeroPromoRevenueDeductionAggregator = class {
|
|
1438
|
+
static {
|
|
1439
|
+
__name(this, "ZeroPromoRevenueDeductionAggregator");
|
|
1440
|
+
}
|
|
1441
|
+
async sumGrossForPromoCode(_promoCodeId) {
|
|
1442
|
+
return "0.00";
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
ZeroPromoRevenueDeductionAggregator = _ts_decorate16([
|
|
1446
|
+
(0, import_common16.Injectable)()
|
|
1447
|
+
], ZeroPromoRevenueDeductionAggregator);
|
|
1448
|
+
|
|
1449
|
+
// src/drizzle-persistence.ts
|
|
1450
|
+
function drizzlePersistence(options) {
|
|
1451
|
+
const { db } = options;
|
|
1452
|
+
const provide = /* @__PURE__ */ __name((build) => isInjectionToken(db) ? {
|
|
1453
|
+
useFactory: /* @__PURE__ */ __name((client) => build(client), "useFactory"),
|
|
1454
|
+
inject: [
|
|
1455
|
+
db
|
|
1456
|
+
]
|
|
1457
|
+
} : build(db), "provide");
|
|
1458
|
+
return {
|
|
1459
|
+
capabilities: {
|
|
1460
|
+
transactions: true,
|
|
1461
|
+
pessimisticLocking: true,
|
|
1462
|
+
rowLevelSecurity: options.rlsIntegration ?? false,
|
|
1463
|
+
advisoryLocks: false
|
|
1464
|
+
},
|
|
1465
|
+
core: {
|
|
1466
|
+
mfa: provide((client) => new DrizzleMfaAdapter(client)),
|
|
1467
|
+
audit: provide((client) => new DrizzleAuditAdapter(client)),
|
|
1468
|
+
rlsBypass: new AsyncLocalRlsBypassAdapter(),
|
|
1469
|
+
transactionRunner: provide((client) => new DrizzleTransactionRunner(client)),
|
|
1470
|
+
auditQuery: provide((client) => new DrizzleAuditQueryAdapter(client)),
|
|
1471
|
+
auditStats: provide((client) => new DrizzleAuditStatsAdapter(client)),
|
|
1472
|
+
superAdminProvisioning: buildProvisioning(db, options.passwordHasher)
|
|
1473
|
+
},
|
|
1474
|
+
entitlement: {
|
|
1475
|
+
subscriptionRepository: provide((client) => new DrizzleSubscriptionRepository(client)),
|
|
1476
|
+
planVersionRepository: provide((client) => new DrizzlePlanVersionRepository(client))
|
|
1477
|
+
},
|
|
1478
|
+
promo: {
|
|
1479
|
+
promoCodeRepository: provide((client) => new DrizzlePromoCodeRepository(client)),
|
|
1480
|
+
redemptionRepository: provide((client) => new DrizzlePromoCodeRedemptionRepository(client)),
|
|
1481
|
+
validationLogRepository: provide((client) => new DrizzlePromoCodeValidationLogRepository(client)),
|
|
1482
|
+
subscriptionLookup: provide((client) => new DrizzlePromoSubscriptionLookup(client)),
|
|
1483
|
+
revenueAggregator: new ZeroPromoRevenueDeductionAggregator()
|
|
1484
|
+
},
|
|
1485
|
+
planCatalogReadSink: provide((client) => new DrizzlePlanCatalogReadSink(client)),
|
|
1486
|
+
planCatalogImportSink: provide((client) => new DrizzlePlanCatalogImportSink(client))
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
__name(drizzlePersistence, "drizzlePersistence");
|
|
1490
|
+
function isInjectionToken(value) {
|
|
1491
|
+
return typeof value === "function" || typeof value === "symbol" || typeof value === "string";
|
|
1492
|
+
}
|
|
1493
|
+
__name(isInjectionToken, "isInjectionToken");
|
|
1494
|
+
function buildProvisioning(db, hasher) {
|
|
1495
|
+
if (hasher === void 0) return void 0;
|
|
1496
|
+
const dbIsToken = isInjectionToken(db);
|
|
1497
|
+
const hasherIsToken = isInjectionToken(hasher);
|
|
1498
|
+
if (dbIsToken && hasherIsToken) {
|
|
1499
|
+
return {
|
|
1500
|
+
useFactory: /* @__PURE__ */ __name((client, h) => new DrizzleSuperAdminBootstrapAdapter(client, h), "useFactory"),
|
|
1501
|
+
inject: [
|
|
1502
|
+
db,
|
|
1503
|
+
hasher
|
|
1504
|
+
]
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
if (dbIsToken) {
|
|
1508
|
+
return {
|
|
1509
|
+
useFactory: /* @__PURE__ */ __name((client) => new DrizzleSuperAdminBootstrapAdapter(client, hasher), "useFactory"),
|
|
1510
|
+
inject: [
|
|
1511
|
+
db
|
|
1512
|
+
]
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
if (hasherIsToken) {
|
|
1516
|
+
return {
|
|
1517
|
+
useFactory: /* @__PURE__ */ __name((h) => new DrizzleSuperAdminBootstrapAdapter(db, h), "useFactory"),
|
|
1518
|
+
inject: [
|
|
1519
|
+
hasher
|
|
1520
|
+
]
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
return new DrizzleSuperAdminBootstrapAdapter(db, hasher);
|
|
1524
|
+
}
|
|
1525
|
+
__name(buildProvisioning, "buildProvisioning");
|
|
1526
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1527
|
+
0 && (module.exports = {
|
|
1528
|
+
AsyncLocalRlsBypassAdapter,
|
|
1529
|
+
DRIZZLE_DB_TOKEN,
|
|
1530
|
+
DrizzleAuditAdapter,
|
|
1531
|
+
DrizzleAuditQueryAdapter,
|
|
1532
|
+
DrizzleAuditStatsAdapter,
|
|
1533
|
+
DrizzleMfaAdapter,
|
|
1534
|
+
DrizzlePlanCatalogImportSink,
|
|
1535
|
+
DrizzlePlanCatalogReadSink,
|
|
1536
|
+
DrizzlePlanVersionRepository,
|
|
1537
|
+
DrizzlePromoCodeRedemptionRepository,
|
|
1538
|
+
DrizzlePromoCodeRepository,
|
|
1539
|
+
DrizzlePromoCodeValidationLogRepository,
|
|
1540
|
+
DrizzlePromoSubscriptionLookup,
|
|
1541
|
+
DrizzleSubscriptionRepository,
|
|
1542
|
+
DrizzleSuperAdminBootstrapAdapter,
|
|
1543
|
+
DrizzleTransactionRunner,
|
|
1544
|
+
PASSWORD_HASHER_TOKEN,
|
|
1545
|
+
ZeroPromoRevenueDeductionAggregator,
|
|
1546
|
+
buildActorTag,
|
|
1547
|
+
drizzlePersistence,
|
|
1548
|
+
saasicatSchema
|
|
1549
|
+
});
|