@saasicat/adapter-drizzle 1.0.0-rc.21 → 1.0.0-rc.23
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/README.md +2 -1
- package/dist/.build-stamp +1 -1
- package/dist/index.cjs +791 -613
- package/dist/index.d.cts +498 -22
- package/dist/index.d.ts +498 -22
- package/dist/index.js +725 -549
- package/package.json +6 -5
- package/sql/1.0-a-redemption-is-redeemed-in-utc.postgres.sql +63 -0
package/dist/index.cjs
CHANGED
|
@@ -8,11 +8,11 @@ var __export = (target, all) => {
|
|
|
8
8
|
for (var name in all)
|
|
9
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
|
-
var __copyProps = (to, from, except,
|
|
11
|
+
var __copyProps = (to, from, except, desc11) => {
|
|
12
12
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
13
|
for (let key of __getOwnPropNames(from))
|
|
14
14
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc11 = __getOwnPropDesc(from, key)) || desc11.enumerable });
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
@@ -28,6 +28,7 @@ __export(index_exports, {
|
|
|
28
28
|
DrizzleAuditQueryAdapter: () => DrizzleAuditQueryAdapter,
|
|
29
29
|
DrizzleAuditStatsAdapter: () => DrizzleAuditStatsAdapter,
|
|
30
30
|
DrizzleBundleRepository: () => DrizzleBundleRepository,
|
|
31
|
+
DrizzleMaintenanceWindowRepository: () => DrizzleMaintenanceWindowRepository,
|
|
31
32
|
DrizzleMfaAdapter: () => DrizzleMfaAdapter,
|
|
32
33
|
DrizzlePaymentEventLog: () => DrizzlePaymentEventLog,
|
|
33
34
|
DrizzlePlanCatalogImportSink: () => DrizzlePlanCatalogImportSink,
|
|
@@ -39,6 +40,7 @@ __export(index_exports, {
|
|
|
39
40
|
DrizzlePromoCodeRepository: () => DrizzlePromoCodeRepository,
|
|
40
41
|
DrizzlePromoCodeValidationLogRepository: () => DrizzlePromoCodeValidationLogRepository,
|
|
41
42
|
DrizzlePromoSubscriptionLookup: () => DrizzlePromoSubscriptionLookup,
|
|
43
|
+
DrizzleSubscriberLedgerRepository: () => DrizzleSubscriberLedgerRepository,
|
|
42
44
|
DrizzleSubscriberPaymentMethodRepository: () => DrizzleSubscriberPaymentMethodRepository,
|
|
43
45
|
DrizzleSubscriberRepository: () => DrizzleSubscriberRepository,
|
|
44
46
|
DrizzleSubscriptionBundleRepository: () => DrizzleSubscriptionBundleRepository,
|
|
@@ -79,9 +81,9 @@ __name(escapeLikePattern, "escapeLikePattern");
|
|
|
79
81
|
// src/async-local-rls-bypass.adapter.ts
|
|
80
82
|
var import_common = require("@nestjs/common");
|
|
81
83
|
var import_node_async_hooks = require("node:async_hooks");
|
|
82
|
-
function _ts_decorate(decorators, target, key,
|
|
83
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
84
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
84
|
+
function _ts_decorate(decorators, target, key, desc11) {
|
|
85
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
86
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
85
87
|
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;
|
|
86
88
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
87
89
|
}
|
|
@@ -119,6 +121,7 @@ __export(schema_exports, {
|
|
|
119
121
|
bundles: () => bundles,
|
|
120
122
|
contractLineItems: () => contractLineItems,
|
|
121
123
|
featureCatalogEntries: () => featureCatalogEntries,
|
|
124
|
+
maintenanceWindows: () => maintenanceWindows,
|
|
122
125
|
paymentEventLog: () => paymentEventLog,
|
|
123
126
|
planVersions: () => planVersions,
|
|
124
127
|
plans: () => plans,
|
|
@@ -128,6 +131,7 @@ __export(schema_exports, {
|
|
|
128
131
|
promoCodes: () => promoCodes,
|
|
129
132
|
settingsChanges: () => settingsChanges,
|
|
130
133
|
subscriberCorrections: () => subscriberCorrections,
|
|
134
|
+
subscriberLedgerEntries: () => subscriberLedgerEntries,
|
|
131
135
|
subscriberPaymentMethodSetups: () => subscriberPaymentMethodSetups,
|
|
132
136
|
subscriberPaymentMethods: () => subscriberPaymentMethods,
|
|
133
137
|
subscriberTenants: () => subscriberTenants,
|
|
@@ -143,6 +147,7 @@ var ts = /* @__PURE__ */ __name((name) => (0, import_pg_core.timestamp)(name, {
|
|
|
143
147
|
precision: 3,
|
|
144
148
|
mode: "date"
|
|
145
149
|
}), "ts");
|
|
150
|
+
var writtenAt = /* @__PURE__ */ __name((name) => ts(name).notNull().$defaultFn(() => /* @__PURE__ */ new Date()), "writtenAt");
|
|
146
151
|
var subscriptions = (0, import_pg_core.pgTable)("subscriptions", {
|
|
147
152
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
148
153
|
tenantId: (0, import_pg_core.text)("tenantId").notNull(),
|
|
@@ -193,7 +198,7 @@ var subscriptions = (0, import_pg_core.pgTable)("subscriptions", {
|
|
|
193
198
|
pilotNote: (0, import_pg_core.text)("pilotNote"),
|
|
194
199
|
checkoutOfferId: (0, import_pg_core.text)("checkoutOfferId"),
|
|
195
200
|
packageSnapshot: (0, import_pg_core.jsonb)("packageSnapshot"),
|
|
196
|
-
createdAt:
|
|
201
|
+
createdAt: writtenAt("createdAt"),
|
|
197
202
|
updatedAt: ts("updatedAt").notNull()
|
|
198
203
|
});
|
|
199
204
|
var planVersions = (0, import_pg_core.pgTable)("plan_versions", {
|
|
@@ -225,7 +230,7 @@ var planVersions = (0, import_pg_core.pgTable)("plan_versions", {
|
|
|
225
230
|
endsAt: ts("endsAt"),
|
|
226
231
|
createdByUserId: (0, import_pg_core.text)("createdByUserId"),
|
|
227
232
|
publishedByUserId: (0, import_pg_core.text)("publishedByUserId"),
|
|
228
|
-
createdAt:
|
|
233
|
+
createdAt: writtenAt("createdAt"),
|
|
229
234
|
updatedAt: ts("updatedAt").notNull()
|
|
230
235
|
});
|
|
231
236
|
var plans = (0, import_pg_core.pgTable)("plans", {
|
|
@@ -235,7 +240,7 @@ var plans = (0, import_pg_core.pgTable)("plans", {
|
|
|
235
240
|
description: (0, import_pg_core.text)("description"),
|
|
236
241
|
icon: (0, import_pg_core.text)("icon"),
|
|
237
242
|
sortOrder: (0, import_pg_core.integer)("sortOrder").notNull().default(0),
|
|
238
|
-
createdAt:
|
|
243
|
+
createdAt: writtenAt("createdAt"),
|
|
239
244
|
updatedAt: ts("updatedAt").notNull(),
|
|
240
245
|
deletedAt: ts("deletedAt")
|
|
241
246
|
});
|
|
@@ -260,7 +265,7 @@ var subscriptionContracts = (0, import_pg_core.pgTable)("subscription_contracts"
|
|
|
260
265
|
subscriberSnapshot: (0, import_pg_core.jsonb)("subscriberSnapshot").notNull(),
|
|
261
266
|
issuerSnapshot: (0, import_pg_core.jsonb)("issuerSnapshot"),
|
|
262
267
|
partiesMigrated: (0, import_pg_core.boolean)("partiesMigrated").notNull().default(false),
|
|
263
|
-
createdAt:
|
|
268
|
+
createdAt: writtenAt("createdAt"),
|
|
264
269
|
updatedAt: ts("updatedAt").notNull()
|
|
265
270
|
});
|
|
266
271
|
var contractLineItems = (0, import_pg_core.pgTable)("contract_line_items", {
|
|
@@ -295,7 +300,7 @@ var contractLineItems = (0, import_pg_core.pgTable)("contract_line_items", {
|
|
|
295
300
|
featuresSnapshot: (0, import_pg_core.jsonb)("featuresSnapshot").notNull(),
|
|
296
301
|
quotaEffectsSnapshot: (0, import_pg_core.jsonb)("quotaEffectsSnapshot").notNull(),
|
|
297
302
|
metadata: (0, import_pg_core.jsonb)("metadata"),
|
|
298
|
-
createdAt:
|
|
303
|
+
createdAt: writtenAt("createdAt")
|
|
299
304
|
});
|
|
300
305
|
var featureCatalogEntries = (0, import_pg_core.pgTable)("feature_catalog_entries", {
|
|
301
306
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
@@ -317,7 +322,7 @@ var featureCatalogEntries = (0, import_pg_core.pgTable)("feature_catalog_entries
|
|
|
317
322
|
plannedOnly: (0, import_pg_core.boolean)("plannedOnly").notNull().default(false),
|
|
318
323
|
i18n: (0, import_pg_core.jsonb)("i18n").notNull().default({}),
|
|
319
324
|
sortOrder: (0, import_pg_core.integer)("sortOrder").notNull().default(0),
|
|
320
|
-
createdAt:
|
|
325
|
+
createdAt: writtenAt("createdAt"),
|
|
321
326
|
updatedAt: ts("updatedAt").notNull(),
|
|
322
327
|
deletedAt: ts("deletedAt")
|
|
323
328
|
});
|
|
@@ -349,7 +354,7 @@ var promoCodes = (0, import_pg_core.pgTable)("promo_codes", {
|
|
|
349
354
|
campaignTag: (0, import_pg_core.text)("campaignTag"),
|
|
350
355
|
revenueDeductionAccount: (0, import_pg_core.text)("revenueDeductionAccount"),
|
|
351
356
|
createdById: (0, import_pg_core.text)("createdById").notNull(),
|
|
352
|
-
createdAt:
|
|
357
|
+
createdAt: writtenAt("createdAt"),
|
|
353
358
|
updatedAt: ts("updatedAt").notNull(),
|
|
354
359
|
deletedAt: ts("deletedAt")
|
|
355
360
|
});
|
|
@@ -368,7 +373,7 @@ var promoCodeRedemptions = (0, import_pg_core.pgTable)("promo_code_redemptions",
|
|
|
368
373
|
startsAt: ts("startsAt").notNull(),
|
|
369
374
|
endsAt: ts("endsAt"),
|
|
370
375
|
status: (0, import_pg_core.text)("status").notNull().default("ACTIVE"),
|
|
371
|
-
redeemedAt:
|
|
376
|
+
redeemedAt: writtenAt("redeemedAt"),
|
|
372
377
|
reversedAt: ts("reversedAt")
|
|
373
378
|
});
|
|
374
379
|
var promoCodeHolds = (0, import_pg_core.pgTable)("promo_code_holds", {
|
|
@@ -379,7 +384,7 @@ var promoCodeHolds = (0, import_pg_core.pgTable)("promo_code_holds", {
|
|
|
379
384
|
handedOverTx: (0, import_pg_core.bigint)("handedOverTx", {
|
|
380
385
|
mode: "bigint"
|
|
381
386
|
}),
|
|
382
|
-
createdAt:
|
|
387
|
+
createdAt: writtenAt("createdAt")
|
|
383
388
|
});
|
|
384
389
|
var promoCodeValidationLogs = (0, import_pg_core.pgTable)("promo_code_validation_logs", {
|
|
385
390
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
@@ -388,7 +393,7 @@ var promoCodeValidationLogs = (0, import_pg_core.pgTable)("promo_code_validation
|
|
|
388
393
|
ipHash: (0, import_pg_core.text)("ipHash"),
|
|
389
394
|
sessionId: (0, import_pg_core.text)("sessionId"),
|
|
390
395
|
result: (0, import_pg_core.text)("result").notNull(),
|
|
391
|
-
createdAt:
|
|
396
|
+
createdAt: writtenAt("createdAt")
|
|
392
397
|
});
|
|
393
398
|
var auditLogs = (0, import_pg_core.pgTable)("audit_logs", {
|
|
394
399
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
@@ -401,7 +406,7 @@ var auditLogs = (0, import_pg_core.pgTable)("audit_logs", {
|
|
|
401
406
|
actorTag: (0, import_pg_core.text)("actorTag"),
|
|
402
407
|
ipAddress: (0, import_pg_core.text)("ipAddress"),
|
|
403
408
|
userAgent: (0, import_pg_core.text)("userAgent"),
|
|
404
|
-
createdAt:
|
|
409
|
+
createdAt: writtenAt("createdAt")
|
|
405
410
|
});
|
|
406
411
|
var superAdminUsers = (0, import_pg_core.pgTable)("super_admin_users", {
|
|
407
412
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
@@ -413,7 +418,7 @@ var superAdminUsers = (0, import_pg_core.pgTable)("super_admin_users", {
|
|
|
413
418
|
isActive: (0, import_pg_core.boolean)("isActive").notNull().default(true),
|
|
414
419
|
lastLoginAt: ts("lastLoginAt"),
|
|
415
420
|
deletedAt: ts("deletedAt"),
|
|
416
|
-
createdAt:
|
|
421
|
+
createdAt: writtenAt("createdAt"),
|
|
417
422
|
updatedAt: ts("updatedAt").notNull()
|
|
418
423
|
});
|
|
419
424
|
var superAdminMfa = (0, import_pg_core.pgTable)("super_admin_mfa", {
|
|
@@ -430,7 +435,7 @@ var bundles = (0, import_pg_core.pgTable)("bundles", {
|
|
|
430
435
|
icon: (0, import_pg_core.text)("icon"),
|
|
431
436
|
sortOrder: (0, import_pg_core.integer)("sortOrder").notNull().default(0),
|
|
432
437
|
i18n: (0, import_pg_core.jsonb)("i18n").notNull(),
|
|
433
|
-
createdAt:
|
|
438
|
+
createdAt: writtenAt("createdAt"),
|
|
434
439
|
updatedAt: ts("updatedAt").notNull(),
|
|
435
440
|
deletedAt: ts("deletedAt")
|
|
436
441
|
});
|
|
@@ -463,7 +468,7 @@ var bundleVersions = (0, import_pg_core.pgTable)("bundle_versions", {
|
|
|
463
468
|
validUntil: ts("validUntil"),
|
|
464
469
|
createdByUserId: (0, import_pg_core.text)("createdByUserId"),
|
|
465
470
|
publishedByUserId: (0, import_pg_core.text)("publishedByUserId"),
|
|
466
|
-
createdAt:
|
|
471
|
+
createdAt: writtenAt("createdAt"),
|
|
467
472
|
updatedAt: ts("updatedAt").notNull()
|
|
468
473
|
});
|
|
469
474
|
var subscriptionBundles = (0, import_pg_core.pgTable)("subscription_bundles", {
|
|
@@ -481,7 +486,7 @@ var subscriptionBundles = (0, import_pg_core.pgTable)("subscription_bundles", {
|
|
|
481
486
|
currentPeriodEnd: ts("currentPeriodEnd"),
|
|
482
487
|
canceledAt: ts("canceledAt"),
|
|
483
488
|
canceledEffectiveAt: ts("canceledEffectiveAt"),
|
|
484
|
-
createdAt:
|
|
489
|
+
createdAt: writtenAt("createdAt"),
|
|
485
490
|
updatedAt: ts("updatedAt").notNull()
|
|
486
491
|
});
|
|
487
492
|
var appliedSettings = (0, import_pg_core.pgTable)("applied_settings", {
|
|
@@ -503,6 +508,18 @@ var settingsChanges = (0, import_pg_core.pgTable)("settings_changes", {
|
|
|
503
508
|
acknowledgedAt: ts("acknowledgedAt"),
|
|
504
509
|
acknowledgedBy: (0, import_pg_core.text)("acknowledgedBy")
|
|
505
510
|
});
|
|
511
|
+
var maintenanceWindows = (0, import_pg_core.pgTable)("maintenance_windows", {
|
|
512
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
513
|
+
startsAt: ts("startsAt"),
|
|
514
|
+
endsAt: ts("endsAt"),
|
|
515
|
+
message: (0, import_pg_core.text)("message"),
|
|
516
|
+
createdAt: writtenAt("createdAt"),
|
|
517
|
+
createdBy: (0, import_pg_core.text)("createdBy").notNull(),
|
|
518
|
+
lockedAt: ts("lockedAt"),
|
|
519
|
+
lockedBy: (0, import_pg_core.text)("lockedBy"),
|
|
520
|
+
endedAt: ts("endedAt"),
|
|
521
|
+
endedBy: (0, import_pg_core.text)("endedBy")
|
|
522
|
+
});
|
|
506
523
|
var subscribers = (0, import_pg_core.pgTable)("subscribers", {
|
|
507
524
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
508
525
|
// Counted by the database, from where `constraints.postgres.sql` starts it.
|
|
@@ -519,14 +536,14 @@ var subscribers = (0, import_pg_core.pgTable)("subscribers", {
|
|
|
519
536
|
country: (0, import_pg_core.text)("country"),
|
|
520
537
|
invoiceEmail: (0, import_pg_core.text)("invoiceEmail"),
|
|
521
538
|
migrated: (0, import_pg_core.boolean)("migrated").notNull().default(false),
|
|
522
|
-
createdAt:
|
|
539
|
+
createdAt: writtenAt("createdAt"),
|
|
523
540
|
updatedAt: ts("updatedAt").notNull()
|
|
524
541
|
});
|
|
525
542
|
var subscriberTenants = (0, import_pg_core.pgTable)("subscriber_tenants", {
|
|
526
543
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
527
544
|
subscriberId: (0, import_pg_core.text)("subscriberId").notNull(),
|
|
528
545
|
tenantId: (0, import_pg_core.text)("tenantId").notNull(),
|
|
529
|
-
linkedAt:
|
|
546
|
+
linkedAt: writtenAt("linkedAt"),
|
|
530
547
|
unlinkedAt: ts("unlinkedAt")
|
|
531
548
|
});
|
|
532
549
|
var subscriberCorrections = (0, import_pg_core.pgTable)("subscriber_corrections", {
|
|
@@ -544,7 +561,7 @@ var subscriberPaymentMethodSetups = (0, import_pg_core.pgTable)("subscriber_paym
|
|
|
544
561
|
gatewayAccount: (0, import_pg_core.text)("gatewayAccount").notNull(),
|
|
545
562
|
sessionRef: (0, import_pg_core.text)("sessionRef").notNull(),
|
|
546
563
|
customerRef: (0, import_pg_core.text)("customerRef").notNull(),
|
|
547
|
-
startedAt:
|
|
564
|
+
startedAt: writtenAt("startedAt"),
|
|
548
565
|
completedAt: ts("completedAt")
|
|
549
566
|
});
|
|
550
567
|
var paymentEventLog = (0, import_pg_core.pgTable)("PaymentEventLog", {
|
|
@@ -555,7 +572,27 @@ var paymentEventLog = (0, import_pg_core.pgTable)("PaymentEventLog", {
|
|
|
555
572
|
sessionId: (0, import_pg_core.text)("sessionId"),
|
|
556
573
|
status: (0, import_pg_core.text)("status").notNull(),
|
|
557
574
|
payload: (0, import_pg_core.jsonb)("payload"),
|
|
558
|
-
processedAt:
|
|
575
|
+
processedAt: writtenAt("processedAt")
|
|
576
|
+
});
|
|
577
|
+
var subscriberLedgerEntries = (0, import_pg_core.pgTable)("subscriber_ledger_entries", {
|
|
578
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
579
|
+
subscriberId: (0, import_pg_core.text)("subscriberId").notNull(),
|
|
580
|
+
tenantId: (0, import_pg_core.text)("tenantId").notNull(),
|
|
581
|
+
subscriptionId: (0, import_pg_core.text)("subscriptionId").notNull(),
|
|
582
|
+
contractId: (0, import_pg_core.text)("contractId").notNull(),
|
|
583
|
+
contractLineItemId: (0, import_pg_core.text)("contractLineItemId").notNull(),
|
|
584
|
+
origin: (0, import_pg_core.text)("origin").notNull(),
|
|
585
|
+
source: (0, import_pg_core.text)("source").notNull(),
|
|
586
|
+
sourceRef: (0, import_pg_core.text)("sourceRef").notNull(),
|
|
587
|
+
periodStart: ts("periodStart").notNull(),
|
|
588
|
+
periodEnd: ts("periodEnd").notNull(),
|
|
589
|
+
currency: (0, import_pg_core.text)("currency").notNull(),
|
|
590
|
+
amountNet: (0, import_pg_core.numeric)("amountNet", {
|
|
591
|
+
precision: 10,
|
|
592
|
+
scale: 2
|
|
593
|
+
}).notNull(),
|
|
594
|
+
bookedAt: ts("bookedAt").notNull(),
|
|
595
|
+
createdAt: writtenAt("createdAt")
|
|
559
596
|
});
|
|
560
597
|
var subscriberPaymentMethods = (0, import_pg_core.pgTable)("subscriber_payment_methods", {
|
|
561
598
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
@@ -575,13 +612,13 @@ var subscriberPaymentMethods = (0, import_pg_core.pgTable)("subscriber_payment_m
|
|
|
575
612
|
status: (0, import_pg_core.text)("status").notNull().default("ACTIVE"),
|
|
576
613
|
confirmedAt: ts("confirmedAt").notNull(),
|
|
577
614
|
replacedAt: ts("replacedAt"),
|
|
578
|
-
createdAt:
|
|
615
|
+
createdAt: writtenAt("createdAt")
|
|
579
616
|
});
|
|
580
617
|
|
|
581
618
|
// src/drizzle-applied-settings.repository.ts
|
|
582
|
-
function _ts_decorate2(decorators, target, key,
|
|
583
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
584
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
619
|
+
function _ts_decorate2(decorators, target, key, desc11) {
|
|
620
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
621
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
585
622
|
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;
|
|
586
623
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
587
624
|
}
|
|
@@ -699,9 +736,9 @@ __name(toValues, "toValues");
|
|
|
699
736
|
// src/drizzle-audit.adapter.ts
|
|
700
737
|
var import_node_crypto2 = require("node:crypto");
|
|
701
738
|
var import_common3 = require("@nestjs/common");
|
|
702
|
-
function _ts_decorate3(decorators, target, key,
|
|
703
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
704
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
739
|
+
function _ts_decorate3(decorators, target, key, desc11) {
|
|
740
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
741
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
705
742
|
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;
|
|
706
743
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
707
744
|
}
|
|
@@ -753,9 +790,9 @@ DrizzleAuditAdapter = _ts_decorate3([
|
|
|
753
790
|
// src/drizzle-audit-query.adapter.ts
|
|
754
791
|
var import_common4 = require("@nestjs/common");
|
|
755
792
|
var import_drizzle_orm2 = require("drizzle-orm");
|
|
756
|
-
function _ts_decorate4(decorators, target, key,
|
|
757
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
758
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
793
|
+
function _ts_decorate4(decorators, target, key, desc11) {
|
|
794
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
795
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
759
796
|
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;
|
|
760
797
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
761
798
|
}
|
|
@@ -835,9 +872,9 @@ __name(toAuditEntry, "toAuditEntry");
|
|
|
835
872
|
// src/drizzle-audit-stats.adapter.ts
|
|
836
873
|
var import_common5 = require("@nestjs/common");
|
|
837
874
|
var import_drizzle_orm3 = require("drizzle-orm");
|
|
838
|
-
function _ts_decorate5(decorators, target, key,
|
|
839
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
840
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
875
|
+
function _ts_decorate5(decorators, target, key, desc11) {
|
|
876
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
877
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
841
878
|
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;
|
|
842
879
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
843
880
|
}
|
|
@@ -876,12 +913,14 @@ DrizzleAuditStatsAdapter = _ts_decorate5([
|
|
|
876
913
|
])
|
|
877
914
|
], DrizzleAuditStatsAdapter);
|
|
878
915
|
|
|
879
|
-
// src/drizzle-
|
|
916
|
+
// src/drizzle-maintenance-window.repository.ts
|
|
917
|
+
var import_node_crypto3 = require("node:crypto");
|
|
880
918
|
var import_common6 = require("@nestjs/common");
|
|
881
919
|
var import_drizzle_orm4 = require("drizzle-orm");
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
920
|
+
var import_core2 = require("@saasicat/core");
|
|
921
|
+
function _ts_decorate6(decorators, target, key, desc11) {
|
|
922
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
923
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
885
924
|
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;
|
|
886
925
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
887
926
|
}
|
|
@@ -896,6 +935,76 @@ function _ts_param5(paramIndex, decorator) {
|
|
|
896
935
|
};
|
|
897
936
|
}
|
|
898
937
|
__name(_ts_param5, "_ts_param");
|
|
938
|
+
var DrizzleMaintenanceWindowRepository = class {
|
|
939
|
+
static {
|
|
940
|
+
__name(this, "DrizzleMaintenanceWindowRepository");
|
|
941
|
+
}
|
|
942
|
+
db;
|
|
943
|
+
constructor(db) {
|
|
944
|
+
this.db = db;
|
|
945
|
+
}
|
|
946
|
+
async findOpen() {
|
|
947
|
+
const rows = await this.db.select().from(maintenanceWindows).where((0, import_drizzle_orm4.isNull)(maintenanceWindows.endedAt)).limit(1);
|
|
948
|
+
return rows[0] ? (0, import_core2.toMaintenanceWindowRecord)(rows[0]) : null;
|
|
949
|
+
}
|
|
950
|
+
async listRecent(limit) {
|
|
951
|
+
const rows = await this.db.select().from(maintenanceWindows).orderBy((0, import_drizzle_orm4.desc)(maintenanceWindows.createdAt), (0, import_drizzle_orm4.desc)(maintenanceWindows.id)).limit(limit);
|
|
952
|
+
return rows.map(import_core2.toMaintenanceWindowRecord);
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* `ON CONFLICT DO NOTHING` with no target, because the key it has to meet
|
|
956
|
+
* is the partial unique index on open windows, which has no columns to
|
|
957
|
+
* name. The id is a uuid made here, so the primary key cannot be the key it
|
|
958
|
+
* met: no row back means a window is already open.
|
|
959
|
+
*/
|
|
960
|
+
async open(window) {
|
|
961
|
+
const [row] = await this.db.insert(maintenanceWindows).values({
|
|
962
|
+
id: (0, import_node_crypto3.randomUUID)(),
|
|
963
|
+
...window,
|
|
964
|
+
endedAt: null,
|
|
965
|
+
endedBy: null
|
|
966
|
+
}).onConflictDoNothing().returning();
|
|
967
|
+
return row ? (0, import_core2.toMaintenanceWindowRecord)(row) : null;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* One guarded `UPDATE`: the stage the caller read is in the `WHERE`, so a
|
|
971
|
+
* window another operator moved on a moment earlier returns no row instead
|
|
972
|
+
* of being moved twice.
|
|
973
|
+
*/
|
|
974
|
+
async update(id, stage, changes) {
|
|
975
|
+
const [row] = await this.db.update(maintenanceWindows).set(changes).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(maintenanceWindows.id, id), (0, import_drizzle_orm4.isNull)(maintenanceWindows.endedAt), stage === "locked" ? (0, import_drizzle_orm4.isNotNull)(maintenanceWindows.lockedAt) : (0, import_drizzle_orm4.isNull)(maintenanceWindows.lockedAt))).returning();
|
|
976
|
+
return row ? (0, import_core2.toMaintenanceWindowRecord)(row) : null;
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
DrizzleMaintenanceWindowRepository = _ts_decorate6([
|
|
980
|
+
(0, import_common6.Injectable)(),
|
|
981
|
+
_ts_param5(0, (0, import_common6.Inject)(DRIZZLE_DB_TOKEN)),
|
|
982
|
+
_ts_metadata5("design:type", Function),
|
|
983
|
+
_ts_metadata5("design:paramtypes", [
|
|
984
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
985
|
+
])
|
|
986
|
+
], DrizzleMaintenanceWindowRepository);
|
|
987
|
+
|
|
988
|
+
// src/drizzle-mfa.adapter.ts
|
|
989
|
+
var import_common7 = require("@nestjs/common");
|
|
990
|
+
var import_drizzle_orm5 = require("drizzle-orm");
|
|
991
|
+
function _ts_decorate7(decorators, target, key, desc11) {
|
|
992
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
993
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
994
|
+
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;
|
|
995
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
996
|
+
}
|
|
997
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
998
|
+
function _ts_metadata6(k, v) {
|
|
999
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1000
|
+
}
|
|
1001
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
1002
|
+
function _ts_param6(paramIndex, decorator) {
|
|
1003
|
+
return function(target, key) {
|
|
1004
|
+
decorator(target, key, paramIndex);
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
__name(_ts_param6, "_ts_param");
|
|
899
1008
|
var DrizzleMfaAdapter = class {
|
|
900
1009
|
static {
|
|
901
1010
|
__name(this, "DrizzleMfaAdapter");
|
|
@@ -905,7 +1014,7 @@ var DrizzleMfaAdapter = class {
|
|
|
905
1014
|
this.db = db;
|
|
906
1015
|
}
|
|
907
1016
|
async getSecret(userId) {
|
|
908
|
-
const rows = await this.db.select().from(superAdminMfa).where((0,
|
|
1017
|
+
const rows = await this.db.select().from(superAdminMfa).where((0, import_drizzle_orm5.eq)(superAdminMfa.userId, userId)).limit(1);
|
|
909
1018
|
return rows[0]?.secret ?? null;
|
|
910
1019
|
}
|
|
911
1020
|
async setSecret(userId, secret) {
|
|
@@ -925,41 +1034,41 @@ var DrizzleMfaAdapter = class {
|
|
|
925
1034
|
});
|
|
926
1035
|
}
|
|
927
1036
|
async isEnabled(userId) {
|
|
928
|
-
const rows = await this.db.select().from(superAdminMfa).where((0,
|
|
1037
|
+
const rows = await this.db.select().from(superAdminMfa).where((0, import_drizzle_orm5.eq)(superAdminMfa.userId, userId)).limit(1);
|
|
929
1038
|
const row = rows[0];
|
|
930
1039
|
return !!row?.secret && !!row?.enabledAt;
|
|
931
1040
|
}
|
|
932
1041
|
};
|
|
933
|
-
DrizzleMfaAdapter =
|
|
934
|
-
(0,
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1042
|
+
DrizzleMfaAdapter = _ts_decorate7([
|
|
1043
|
+
(0, import_common7.Injectable)(),
|
|
1044
|
+
_ts_param6(0, (0, import_common7.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1045
|
+
_ts_metadata6("design:type", Function),
|
|
1046
|
+
_ts_metadata6("design:paramtypes", [
|
|
938
1047
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
939
1048
|
])
|
|
940
1049
|
], DrizzleMfaAdapter);
|
|
941
1050
|
|
|
942
1051
|
// src/drizzle-plan-catalog-import-sink.adapter.ts
|
|
943
|
-
var
|
|
944
|
-
var
|
|
945
|
-
var
|
|
946
|
-
function
|
|
947
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
948
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1052
|
+
var import_node_crypto4 = require("node:crypto");
|
|
1053
|
+
var import_common8 = require("@nestjs/common");
|
|
1054
|
+
var import_drizzle_orm6 = require("drizzle-orm");
|
|
1055
|
+
function _ts_decorate8(decorators, target, key, desc11) {
|
|
1056
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1057
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
949
1058
|
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;
|
|
950
1059
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
951
1060
|
}
|
|
952
|
-
__name(
|
|
953
|
-
function
|
|
1061
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1062
|
+
function _ts_metadata7(k, v) {
|
|
954
1063
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
955
1064
|
}
|
|
956
|
-
__name(
|
|
957
|
-
function
|
|
1065
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
1066
|
+
function _ts_param7(paramIndex, decorator) {
|
|
958
1067
|
return function(target, key) {
|
|
959
1068
|
decorator(target, key, paramIndex);
|
|
960
1069
|
};
|
|
961
1070
|
}
|
|
962
|
-
__name(
|
|
1071
|
+
__name(_ts_param7, "_ts_param");
|
|
963
1072
|
var DrizzlePlanCatalogImportSink = class {
|
|
964
1073
|
static {
|
|
965
1074
|
__name(this, "DrizzlePlanCatalogImportSink");
|
|
@@ -971,13 +1080,13 @@ var DrizzlePlanCatalogImportSink = class {
|
|
|
971
1080
|
async upsertPlan(input) {
|
|
972
1081
|
const existing = await this.db.select({
|
|
973
1082
|
id: plans.id
|
|
974
|
-
}).from(plans).where((0,
|
|
1083
|
+
}).from(plans).where((0, import_drizzle_orm6.eq)(plans.planKey, input.planKey)).limit(1);
|
|
975
1084
|
if (existing[0]) return {
|
|
976
1085
|
created: false,
|
|
977
1086
|
skipReason: "exists"
|
|
978
1087
|
};
|
|
979
1088
|
await this.db.insert(plans).values({
|
|
980
|
-
id: (0,
|
|
1089
|
+
id: (0, import_node_crypto4.randomUUID)(),
|
|
981
1090
|
planKey: input.planKey,
|
|
982
1091
|
label: input.label,
|
|
983
1092
|
description: input.description ?? null,
|
|
@@ -991,7 +1100,7 @@ var DrizzlePlanCatalogImportSink = class {
|
|
|
991
1100
|
async upsertPlanVersion(input) {
|
|
992
1101
|
const existing = await this.db.select({
|
|
993
1102
|
id: planVersions.id
|
|
994
|
-
}).from(planVersions).where((0,
|
|
1103
|
+
}).from(planVersions).where((0, import_drizzle_orm6.and)((0, import_drizzle_orm6.eq)(planVersions.planId, input.planKey), (0, import_drizzle_orm6.eq)(planVersions.version, input.version))).limit(1);
|
|
995
1104
|
if (existing[0]) return {
|
|
996
1105
|
created: false,
|
|
997
1106
|
skipReason: "exists"
|
|
@@ -1001,10 +1110,10 @@ var DrizzlePlanCatalogImportSink = class {
|
|
|
1001
1110
|
await this.db.update(planVersions).set({
|
|
1002
1111
|
supersededAt: now,
|
|
1003
1112
|
updatedAt: now
|
|
1004
|
-
}).where((0,
|
|
1113
|
+
}).where((0, import_drizzle_orm6.and)((0, import_drizzle_orm6.eq)(planVersions.planId, input.planKey), (0, import_drizzle_orm6.isNotNull)(planVersions.publishedAt), (0, import_drizzle_orm6.isNull)(planVersions.supersededAt), (0, import_drizzle_orm6.lt)(planVersions.version, input.version)));
|
|
1005
1114
|
}
|
|
1006
1115
|
await this.db.insert(planVersions).values({
|
|
1007
|
-
id: (0,
|
|
1116
|
+
id: (0, import_node_crypto4.randomUUID)(),
|
|
1008
1117
|
planId: input.planKey,
|
|
1009
1118
|
version: input.version,
|
|
1010
1119
|
features: input.features,
|
|
@@ -1023,13 +1132,13 @@ var DrizzlePlanCatalogImportSink = class {
|
|
|
1023
1132
|
async upsertFeatureCatalogEntry(input) {
|
|
1024
1133
|
const existing = await this.db.select({
|
|
1025
1134
|
id: featureCatalogEntries.id
|
|
1026
|
-
}).from(featureCatalogEntries).where((0,
|
|
1135
|
+
}).from(featureCatalogEntries).where((0, import_drizzle_orm6.and)((0, import_drizzle_orm6.eq)(featureCatalogEntries.featureKey, input.featureKey))).limit(1);
|
|
1027
1136
|
if (existing[0]) return {
|
|
1028
1137
|
created: false,
|
|
1029
1138
|
skipReason: "exists"
|
|
1030
1139
|
};
|
|
1031
1140
|
await this.db.insert(featureCatalogEntries).values({
|
|
1032
|
-
id: (0,
|
|
1141
|
+
id: (0, import_node_crypto4.randomUUID)(),
|
|
1033
1142
|
featureKey: input.featureKey,
|
|
1034
1143
|
label: input.label ?? input.featureKey,
|
|
1035
1144
|
icon: input.icon ?? null,
|
|
@@ -1043,36 +1152,36 @@ var DrizzlePlanCatalogImportSink = class {
|
|
|
1043
1152
|
};
|
|
1044
1153
|
}
|
|
1045
1154
|
};
|
|
1046
|
-
DrizzlePlanCatalogImportSink =
|
|
1047
|
-
(0,
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1155
|
+
DrizzlePlanCatalogImportSink = _ts_decorate8([
|
|
1156
|
+
(0, import_common8.Injectable)(),
|
|
1157
|
+
_ts_param7(0, (0, import_common8.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1158
|
+
_ts_metadata7("design:type", Function),
|
|
1159
|
+
_ts_metadata7("design:paramtypes", [
|
|
1051
1160
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1052
1161
|
])
|
|
1053
1162
|
], DrizzlePlanCatalogImportSink);
|
|
1054
1163
|
|
|
1055
1164
|
// src/drizzle-plan-catalog-read-sink.adapter.ts
|
|
1056
|
-
var
|
|
1057
|
-
var
|
|
1058
|
-
var
|
|
1059
|
-
function
|
|
1060
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1061
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1165
|
+
var import_common9 = require("@nestjs/common");
|
|
1166
|
+
var import_drizzle_orm7 = require("drizzle-orm");
|
|
1167
|
+
var import_core3 = require("@saasicat/core");
|
|
1168
|
+
function _ts_decorate9(decorators, target, key, desc11) {
|
|
1169
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1170
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1062
1171
|
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;
|
|
1063
1172
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1064
1173
|
}
|
|
1065
|
-
__name(
|
|
1066
|
-
function
|
|
1174
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1175
|
+
function _ts_metadata8(k, v) {
|
|
1067
1176
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1068
1177
|
}
|
|
1069
|
-
__name(
|
|
1070
|
-
function
|
|
1178
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
1179
|
+
function _ts_param8(paramIndex, decorator) {
|
|
1071
1180
|
return function(target, key) {
|
|
1072
1181
|
decorator(target, key, paramIndex);
|
|
1073
1182
|
};
|
|
1074
1183
|
}
|
|
1075
|
-
__name(
|
|
1184
|
+
__name(_ts_param8, "_ts_param");
|
|
1076
1185
|
var CATALOG_VERSION_FIELDS = {
|
|
1077
1186
|
validityWindows: false,
|
|
1078
1187
|
endsAt: false
|
|
@@ -1086,22 +1195,22 @@ var DrizzlePlanCatalogReadSink = class {
|
|
|
1086
1195
|
this.db = db;
|
|
1087
1196
|
}
|
|
1088
1197
|
async loadSnapshot() {
|
|
1089
|
-
const planRows = await this.db.select().from(plans).where((0,
|
|
1198
|
+
const planRows = await this.db.select().from(plans).where((0, import_drizzle_orm7.isNull)(plans.deletedAt)).orderBy((0, import_drizzle_orm7.asc)(plans.sortOrder));
|
|
1090
1199
|
const planKeys = planRows.map((plan) => plan.planKey);
|
|
1091
|
-
const liveVersionRows = planKeys.length === 0 ? [] : await this.db.select().from(planVersions).where((0,
|
|
1092
|
-
const featureRows = await this.db.select().from(featureCatalogEntries).where((0,
|
|
1200
|
+
const liveVersionRows = planKeys.length === 0 ? [] : await this.db.select().from(planVersions).where((0, import_drizzle_orm7.and)((0, import_drizzle_orm7.inArray)(planVersions.planId, planKeys), (0, import_drizzle_orm7.isNotNull)(planVersions.publishedAt), (0, import_drizzle_orm7.isNull)(planVersions.supersededAt)));
|
|
1201
|
+
const featureRows = await this.db.select().from(featureCatalogEntries).where((0, import_drizzle_orm7.isNull)(featureCatalogEntries.deletedAt)).orderBy((0, import_drizzle_orm7.asc)(featureCatalogEntries.sortOrder));
|
|
1093
1202
|
return {
|
|
1094
|
-
plans: planRows.map((row) => (0,
|
|
1095
|
-
livePlanVersions: liveVersionRows.map((row) => (0,
|
|
1203
|
+
plans: planRows.map((row) => (0, import_core3.toPlanRow)(row)),
|
|
1204
|
+
livePlanVersions: liveVersionRows.map((row) => (0, import_core3.toPlanVersionRow)(row, row.planId, CATALOG_VERSION_FIELDS)),
|
|
1096
1205
|
featureEntries: featureRows.map(toFeatureCatalogEntryRow)
|
|
1097
1206
|
};
|
|
1098
1207
|
}
|
|
1099
1208
|
};
|
|
1100
|
-
DrizzlePlanCatalogReadSink =
|
|
1101
|
-
(0,
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1209
|
+
DrizzlePlanCatalogReadSink = _ts_decorate9([
|
|
1210
|
+
(0, import_common9.Injectable)(),
|
|
1211
|
+
_ts_param8(0, (0, import_common9.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1212
|
+
_ts_metadata8("design:type", Function),
|
|
1213
|
+
_ts_metadata8("design:paramtypes", [
|
|
1105
1214
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1106
1215
|
])
|
|
1107
1216
|
], DrizzlePlanCatalogReadSink);
|
|
@@ -1134,26 +1243,26 @@ function toFeatureCatalogEntryRow(row) {
|
|
|
1134
1243
|
__name(toFeatureCatalogEntryRow, "toFeatureCatalogEntryRow");
|
|
1135
1244
|
|
|
1136
1245
|
// src/drizzle-payment-event-log.adapter.ts
|
|
1137
|
-
var
|
|
1138
|
-
var
|
|
1139
|
-
var
|
|
1140
|
-
function
|
|
1141
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1142
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1246
|
+
var import_node_crypto5 = require("node:crypto");
|
|
1247
|
+
var import_drizzle_orm8 = require("drizzle-orm");
|
|
1248
|
+
var import_common10 = require("@nestjs/common");
|
|
1249
|
+
function _ts_decorate10(decorators, target, key, desc11) {
|
|
1250
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1251
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1143
1252
|
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;
|
|
1144
1253
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1145
1254
|
}
|
|
1146
|
-
__name(
|
|
1147
|
-
function
|
|
1255
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1256
|
+
function _ts_metadata9(k, v) {
|
|
1148
1257
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1149
1258
|
}
|
|
1150
|
-
__name(
|
|
1151
|
-
function
|
|
1259
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1260
|
+
function _ts_param9(paramIndex, decorator) {
|
|
1152
1261
|
return function(target, key) {
|
|
1153
1262
|
decorator(target, key, paramIndex);
|
|
1154
1263
|
};
|
|
1155
1264
|
}
|
|
1156
|
-
__name(
|
|
1265
|
+
__name(_ts_param9, "_ts_param");
|
|
1157
1266
|
var DrizzlePaymentEventLog = class {
|
|
1158
1267
|
static {
|
|
1159
1268
|
__name(this, "DrizzlePaymentEventLog");
|
|
@@ -1164,7 +1273,7 @@ var DrizzlePaymentEventLog = class {
|
|
|
1164
1273
|
}
|
|
1165
1274
|
async claim(claim, tx) {
|
|
1166
1275
|
const inserted = await resolveDb(this.db, tx).insert(paymentEventLog).values({
|
|
1167
|
-
id: (0,
|
|
1276
|
+
id: (0, import_node_crypto5.randomUUID)(),
|
|
1168
1277
|
gatewayAccount: claim.gatewayAccount,
|
|
1169
1278
|
eventId: claim.eventId,
|
|
1170
1279
|
provider: claim.provider,
|
|
@@ -1179,38 +1288,38 @@ var DrizzlePaymentEventLog = class {
|
|
|
1179
1288
|
async releaseSession(gatewayAccount, eventId, tx) {
|
|
1180
1289
|
await resolveDb(this.db, tx).update(paymentEventLog).set({
|
|
1181
1290
|
sessionId: null
|
|
1182
|
-
}).where((0,
|
|
1291
|
+
}).where((0, import_drizzle_orm8.and)((0, import_drizzle_orm8.eq)(paymentEventLog.gatewayAccount, gatewayAccount), (0, import_drizzle_orm8.eq)(paymentEventLog.eventId, eventId)));
|
|
1183
1292
|
}
|
|
1184
1293
|
};
|
|
1185
|
-
DrizzlePaymentEventLog =
|
|
1186
|
-
(0,
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1294
|
+
DrizzlePaymentEventLog = _ts_decorate10([
|
|
1295
|
+
(0, import_common10.Injectable)(),
|
|
1296
|
+
_ts_param9(0, (0, import_common10.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1297
|
+
_ts_metadata9("design:type", Function),
|
|
1298
|
+
_ts_metadata9("design:paramtypes", [
|
|
1190
1299
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1191
1300
|
])
|
|
1192
1301
|
], DrizzlePaymentEventLog);
|
|
1193
1302
|
|
|
1194
1303
|
// src/drizzle-plan-version.repository.ts
|
|
1195
|
-
var
|
|
1196
|
-
var
|
|
1197
|
-
function
|
|
1198
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1199
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1304
|
+
var import_common11 = require("@nestjs/common");
|
|
1305
|
+
var import_drizzle_orm9 = require("drizzle-orm");
|
|
1306
|
+
function _ts_decorate11(decorators, target, key, desc11) {
|
|
1307
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1308
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1200
1309
|
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;
|
|
1201
1310
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1202
1311
|
}
|
|
1203
|
-
__name(
|
|
1204
|
-
function
|
|
1312
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1313
|
+
function _ts_metadata10(k, v) {
|
|
1205
1314
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1206
1315
|
}
|
|
1207
|
-
__name(
|
|
1208
|
-
function
|
|
1316
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
1317
|
+
function _ts_param10(paramIndex, decorator) {
|
|
1209
1318
|
return function(target, key) {
|
|
1210
1319
|
decorator(target, key, paramIndex);
|
|
1211
1320
|
};
|
|
1212
1321
|
}
|
|
1213
|
-
__name(
|
|
1322
|
+
__name(_ts_param10, "_ts_param");
|
|
1214
1323
|
var DrizzlePlanVersionRepository = class {
|
|
1215
1324
|
static {
|
|
1216
1325
|
__name(this, "DrizzlePlanVersionRepository");
|
|
@@ -1221,7 +1330,7 @@ var DrizzlePlanVersionRepository = class {
|
|
|
1221
1330
|
}
|
|
1222
1331
|
async findLatestLive(planId, tx) {
|
|
1223
1332
|
const db = resolveDb(this.db, tx);
|
|
1224
|
-
const rows = await db.select().from(planVersions).where((0,
|
|
1333
|
+
const rows = await db.select().from(planVersions).where((0, import_drizzle_orm9.and)((0, import_drizzle_orm9.eq)(planVersions.planId, planId), (0, import_drizzle_orm9.isNotNull)(planVersions.publishedAt), (0, import_drizzle_orm9.isNull)(planVersions.supersededAt))).orderBy((0, import_drizzle_orm9.desc)(planVersions.version)).limit(1);
|
|
1225
1334
|
const row = rows[0];
|
|
1226
1335
|
if (!row) return null;
|
|
1227
1336
|
return {
|
|
@@ -1231,41 +1340,41 @@ var DrizzlePlanVersionRepository = class {
|
|
|
1231
1340
|
};
|
|
1232
1341
|
}
|
|
1233
1342
|
};
|
|
1234
|
-
DrizzlePlanVersionRepository =
|
|
1235
|
-
(0,
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1343
|
+
DrizzlePlanVersionRepository = _ts_decorate11([
|
|
1344
|
+
(0, import_common11.Injectable)(),
|
|
1345
|
+
_ts_param10(0, (0, import_common11.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1346
|
+
_ts_metadata10("design:type", Function),
|
|
1347
|
+
_ts_metadata10("design:paramtypes", [
|
|
1239
1348
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1240
1349
|
])
|
|
1241
1350
|
], DrizzlePlanVersionRepository);
|
|
1242
1351
|
|
|
1243
1352
|
// src/drizzle-promo-code-hold.repository.ts
|
|
1353
|
+
var import_node_crypto7 = require("node:crypto");
|
|
1354
|
+
var import_common13 = require("@nestjs/common");
|
|
1355
|
+
var import_drizzle_orm11 = require("drizzle-orm");
|
|
1356
|
+
|
|
1357
|
+
// src/drizzle-promo-code.repository.ts
|
|
1244
1358
|
var import_node_crypto6 = require("node:crypto");
|
|
1245
1359
|
var import_common12 = require("@nestjs/common");
|
|
1246
1360
|
var import_drizzle_orm10 = require("drizzle-orm");
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
var import_common11 = require("@nestjs/common");
|
|
1251
|
-
var import_drizzle_orm9 = require("drizzle-orm");
|
|
1252
|
-
function _ts_decorate11(decorators, target, key, desc10) {
|
|
1253
|
-
var c = arguments.length, r = c < 3 ? target : desc10 === null ? desc10 = Object.getOwnPropertyDescriptor(target, key) : desc10, d;
|
|
1254
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc10);
|
|
1361
|
+
function _ts_decorate12(decorators, target, key, desc11) {
|
|
1362
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1363
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1255
1364
|
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;
|
|
1256
1365
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1257
1366
|
}
|
|
1258
|
-
__name(
|
|
1259
|
-
function
|
|
1367
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1368
|
+
function _ts_metadata11(k, v) {
|
|
1260
1369
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1261
1370
|
}
|
|
1262
|
-
__name(
|
|
1263
|
-
function
|
|
1371
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
1372
|
+
function _ts_param11(paramIndex, decorator) {
|
|
1264
1373
|
return function(target, key) {
|
|
1265
1374
|
decorator(target, key, paramIndex);
|
|
1266
1375
|
};
|
|
1267
1376
|
}
|
|
1268
|
-
__name(
|
|
1377
|
+
__name(_ts_param11, "_ts_param");
|
|
1269
1378
|
var DrizzlePromoCodeRepository = class {
|
|
1270
1379
|
static {
|
|
1271
1380
|
__name(this, "DrizzlePromoCodeRepository");
|
|
@@ -1275,30 +1384,30 @@ var DrizzlePromoCodeRepository = class {
|
|
|
1275
1384
|
this.db = db;
|
|
1276
1385
|
}
|
|
1277
1386
|
async findById(id) {
|
|
1278
|
-
const rows = await this.db.select().from(promoCodes).where((0,
|
|
1387
|
+
const rows = await this.db.select().from(promoCodes).where((0, import_drizzle_orm10.eq)(promoCodes.id, id)).limit(1);
|
|
1279
1388
|
const row = rows[0];
|
|
1280
1389
|
return row ? toRecord(row) : null;
|
|
1281
1390
|
}
|
|
1282
1391
|
async findByCode(code, tx) {
|
|
1283
1392
|
const db = resolveDb(this.db, tx);
|
|
1284
|
-
const rows = await db.select().from(promoCodes).where((0,
|
|
1393
|
+
const rows = await db.select().from(promoCodes).where((0, import_drizzle_orm10.eq)(promoCodes.code, normalizeCode(code))).limit(1);
|
|
1285
1394
|
const row = rows[0];
|
|
1286
1395
|
if (!row || row.deletedAt) return null;
|
|
1287
1396
|
return toRecord(row);
|
|
1288
1397
|
}
|
|
1289
1398
|
async findMany(filter) {
|
|
1290
1399
|
const conditions = [
|
|
1291
|
-
(0,
|
|
1292
|
-
filter.status ? (0,
|
|
1293
|
-
filter.campaignTag ? (0,
|
|
1294
|
-
filter.search ? (0,
|
|
1400
|
+
(0, import_drizzle_orm10.isNull)(promoCodes.deletedAt),
|
|
1401
|
+
filter.status ? (0, import_drizzle_orm10.eq)(promoCodes.status, filter.status) : void 0,
|
|
1402
|
+
filter.campaignTag ? (0, import_drizzle_orm10.eq)(promoCodes.campaignTag, filter.campaignTag) : void 0,
|
|
1403
|
+
filter.search ? (0, import_drizzle_orm10.like)(promoCodes.code, `%${escapeLikePattern(normalizeCode(filter.search))}%`) : void 0
|
|
1295
1404
|
];
|
|
1296
|
-
const rows = await this.db.select().from(promoCodes).where((0,
|
|
1405
|
+
const rows = await this.db.select().from(promoCodes).where((0, import_drizzle_orm10.and)(...conditions)).orderBy(import_drizzle_orm10.sql`${promoCodes.createdAt} DESC`);
|
|
1297
1406
|
return rows.map(toRecord);
|
|
1298
1407
|
}
|
|
1299
1408
|
async create(data) {
|
|
1300
1409
|
const rows = await this.db.insert(promoCodes).values({
|
|
1301
|
-
id: (0,
|
|
1410
|
+
id: (0, import_node_crypto6.randomUUID)(),
|
|
1302
1411
|
code: normalizeCode(data.code),
|
|
1303
1412
|
valueType: data.valueType,
|
|
1304
1413
|
value: data.value.toFixed(2),
|
|
@@ -1327,7 +1436,7 @@ var DrizzlePromoCodeRepository = class {
|
|
|
1327
1436
|
validUntil: data.validUntil,
|
|
1328
1437
|
maxRedemptions: data.maxRedemptions,
|
|
1329
1438
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1330
|
-
}).where((0,
|
|
1439
|
+
}).where((0, import_drizzle_orm10.eq)(promoCodes.id, id)).returning();
|
|
1331
1440
|
const row = rows[0];
|
|
1332
1441
|
if (!row) {
|
|
1333
1442
|
throw new Error(`PromoCode ${id} not found.`);
|
|
@@ -1338,12 +1447,12 @@ var DrizzlePromoCodeRepository = class {
|
|
|
1338
1447
|
await this.db.update(promoCodes).set({
|
|
1339
1448
|
deletedAt: /* @__PURE__ */ new Date(),
|
|
1340
1449
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1341
|
-
}).where((0,
|
|
1450
|
+
}).where((0, import_drizzle_orm10.eq)(promoCodes.id, id));
|
|
1342
1451
|
}
|
|
1343
1452
|
async claimSlot(id, tx) {
|
|
1344
1453
|
const db = resolveDb(this.db, tx);
|
|
1345
1454
|
const claimed = await db.update(promoCodes).set({
|
|
1346
|
-
redemptionsCount:
|
|
1455
|
+
redemptionsCount: import_drizzle_orm10.sql`${promoCodes.redemptionsCount} + 1`,
|
|
1347
1456
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1348
1457
|
}).where(hasFreeSlot(id)).returning({
|
|
1349
1458
|
id: promoCodes.id
|
|
@@ -1355,39 +1464,39 @@ var DrizzlePromoCodeRepository = class {
|
|
|
1355
1464
|
await db.update(promoCodes).set({
|
|
1356
1465
|
status: "EXHAUSTED",
|
|
1357
1466
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1358
|
-
}).where((0,
|
|
1467
|
+
}).where((0, import_drizzle_orm10.and)((0, import_drizzle_orm10.eq)(promoCodes.id, id), (0, import_drizzle_orm10.eq)(promoCodes.status, "ACTIVE"), (0, import_drizzle_orm10.isNotNull)(promoCodes.maxRedemptions), (0, import_drizzle_orm10.gte)(promoCodes.redemptionsCount, promoCodes.maxRedemptions)));
|
|
1359
1468
|
}
|
|
1360
1469
|
async releaseSlot(id, tx) {
|
|
1361
1470
|
const db = resolveDb(this.db, tx);
|
|
1362
1471
|
await db.update(promoCodes).set({
|
|
1363
|
-
redemptionsCount:
|
|
1364
|
-
status:
|
|
1472
|
+
redemptionsCount: import_drizzle_orm10.sql`GREATEST(${promoCodes.redemptionsCount} - 1, 0)`,
|
|
1473
|
+
status: import_drizzle_orm10.sql`CASE WHEN ${promoCodes.status} = 'EXHAUSTED' THEN 'ACTIVE' ELSE ${promoCodes.status} END`,
|
|
1365
1474
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1366
|
-
}).where((0,
|
|
1475
|
+
}).where((0, import_drizzle_orm10.eq)(promoCodes.id, id));
|
|
1367
1476
|
}
|
|
1368
1477
|
async expireDueCodes(now) {
|
|
1369
1478
|
const expired = await this.db.update(promoCodes).set({
|
|
1370
1479
|
status: "EXPIRED",
|
|
1371
1480
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1372
|
-
}).where((0,
|
|
1481
|
+
}).where((0, import_drizzle_orm10.and)((0, import_drizzle_orm10.inArray)(promoCodes.status, [
|
|
1373
1482
|
"ACTIVE",
|
|
1374
1483
|
"PAUSED"
|
|
1375
|
-
]), (0,
|
|
1484
|
+
]), (0, import_drizzle_orm10.lt)(promoCodes.validUntil, now))).returning({
|
|
1376
1485
|
id: promoCodes.id
|
|
1377
1486
|
});
|
|
1378
1487
|
return expired.length;
|
|
1379
1488
|
}
|
|
1380
1489
|
};
|
|
1381
|
-
DrizzlePromoCodeRepository =
|
|
1382
|
-
(0,
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1490
|
+
DrizzlePromoCodeRepository = _ts_decorate12([
|
|
1491
|
+
(0, import_common12.Injectable)(),
|
|
1492
|
+
_ts_param11(0, (0, import_common12.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1493
|
+
_ts_metadata11("design:type", Function),
|
|
1494
|
+
_ts_metadata11("design:paramtypes", [
|
|
1386
1495
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1387
1496
|
])
|
|
1388
1497
|
], DrizzlePromoCodeRepository);
|
|
1389
1498
|
function hasFreeSlot(id) {
|
|
1390
|
-
return (0,
|
|
1499
|
+
return (0, import_drizzle_orm10.and)((0, import_drizzle_orm10.eq)(promoCodes.id, id), (0, import_drizzle_orm10.eq)(promoCodes.status, "ACTIVE"), (0, import_drizzle_orm10.isNull)(promoCodes.deletedAt), (0, import_drizzle_orm10.or)((0, import_drizzle_orm10.isNull)(promoCodes.maxRedemptions), import_drizzle_orm10.sql`${promoCodes.redemptionsCount} + ${promoCodes.heldCount} < ${promoCodes.maxRedemptions}`));
|
|
1391
1500
|
}
|
|
1392
1501
|
__name(hasFreeSlot, "hasFreeSlot");
|
|
1393
1502
|
function normalizeCode(code) {
|
|
@@ -1425,23 +1534,23 @@ function toRecord(row) {
|
|
|
1425
1534
|
__name(toRecord, "toRecord");
|
|
1426
1535
|
|
|
1427
1536
|
// src/drizzle-promo-code-hold.repository.ts
|
|
1428
|
-
function
|
|
1429
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1430
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1537
|
+
function _ts_decorate13(decorators, target, key, desc11) {
|
|
1538
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1539
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1431
1540
|
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;
|
|
1432
1541
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1433
1542
|
}
|
|
1434
|
-
__name(
|
|
1435
|
-
function
|
|
1543
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1544
|
+
function _ts_metadata12(k, v) {
|
|
1436
1545
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1437
1546
|
}
|
|
1438
|
-
__name(
|
|
1439
|
-
function
|
|
1547
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
1548
|
+
function _ts_param12(paramIndex, decorator) {
|
|
1440
1549
|
return function(target, key) {
|
|
1441
1550
|
decorator(target, key, paramIndex);
|
|
1442
1551
|
};
|
|
1443
1552
|
}
|
|
1444
|
-
__name(
|
|
1553
|
+
__name(_ts_param12, "_ts_param");
|
|
1445
1554
|
var HOLD_FIELDS = {
|
|
1446
1555
|
id: promoCodeHolds.id,
|
|
1447
1556
|
promoCodeId: promoCodeHolds.promoCodeId,
|
|
@@ -1449,8 +1558,8 @@ var HOLD_FIELDS = {
|
|
|
1449
1558
|
expiresAt: promoCodeHolds.expiresAt,
|
|
1450
1559
|
createdAt: promoCodeHolds.createdAt
|
|
1451
1560
|
};
|
|
1452
|
-
var CURRENT_TRANSACTION =
|
|
1453
|
-
var atExpiry = /* @__PURE__ */ __name((expiresAt) =>
|
|
1561
|
+
var CURRENT_TRANSACTION = import_drizzle_orm11.sql`txid_current()`;
|
|
1562
|
+
var atExpiry = /* @__PURE__ */ __name((expiresAt) => import_drizzle_orm11.sql.param(expiresAt, promoCodeHolds.expiresAt), "atExpiry");
|
|
1454
1563
|
var DrizzlePromoCodeHoldRepository = class {
|
|
1455
1564
|
static {
|
|
1456
1565
|
__name(this, "DrizzlePromoCodeHoldRepository");
|
|
@@ -1460,25 +1569,25 @@ var DrizzlePromoCodeHoldRepository = class {
|
|
|
1460
1569
|
this.db = db;
|
|
1461
1570
|
}
|
|
1462
1571
|
async findByCheckoutOffer(checkoutOfferId, tx) {
|
|
1463
|
-
const rows = await resolveDb(this.db, tx).select(HOLD_FIELDS).from(promoCodeHolds).where((0,
|
|
1572
|
+
const rows = await resolveDb(this.db, tx).select(HOLD_FIELDS).from(promoCodeHolds).where((0, import_drizzle_orm11.eq)(promoCodeHolds.checkoutOfferId, checkoutOfferId)).limit(1);
|
|
1464
1573
|
return rows[0] ?? null;
|
|
1465
1574
|
}
|
|
1466
1575
|
async take(hold) {
|
|
1467
1576
|
return this.onTransaction(void 0, async (db) => {
|
|
1468
1577
|
const code = await db.select({
|
|
1469
1578
|
id: promoCodes.id
|
|
1470
|
-
}).from(promoCodes).where((0,
|
|
1579
|
+
}).from(promoCodes).where((0, import_drizzle_orm11.eq)(promoCodes.id, hold.promoCodeId)).for("update");
|
|
1471
1580
|
if (code.length === 0) return {
|
|
1472
1581
|
outcome: "no-slot"
|
|
1473
1582
|
};
|
|
1474
1583
|
const held = await db.select({
|
|
1475
1584
|
id: promoCodeHolds.id
|
|
1476
|
-
}).from(promoCodeHolds).where((0,
|
|
1585
|
+
}).from(promoCodeHolds).where((0, import_drizzle_orm11.eq)(promoCodeHolds.checkoutOfferId, hold.checkoutOfferId)).limit(1);
|
|
1477
1586
|
if (held.length > 0) return {
|
|
1478
1587
|
outcome: "offer-holds-one"
|
|
1479
1588
|
};
|
|
1480
1589
|
const counted = await db.update(promoCodes).set({
|
|
1481
|
-
heldCount:
|
|
1590
|
+
heldCount: import_drizzle_orm11.sql`${promoCodes.heldCount} + 1`,
|
|
1482
1591
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1483
1592
|
}).where(hasFreeSlot(hold.promoCodeId)).returning({
|
|
1484
1593
|
id: promoCodes.id
|
|
@@ -1487,7 +1596,7 @@ var DrizzlePromoCodeHoldRepository = class {
|
|
|
1487
1596
|
outcome: "no-slot"
|
|
1488
1597
|
};
|
|
1489
1598
|
const [created] = await db.insert(promoCodeHolds).values({
|
|
1490
|
-
id: (0,
|
|
1599
|
+
id: (0, import_node_crypto7.randomUUID)(),
|
|
1491
1600
|
...hold
|
|
1492
1601
|
}).returning(HOLD_FIELDS);
|
|
1493
1602
|
return {
|
|
@@ -1498,22 +1607,22 @@ var DrizzlePromoCodeHoldRepository = class {
|
|
|
1498
1607
|
}
|
|
1499
1608
|
async extend(checkoutOfferId, promoCodeId, expiresAt) {
|
|
1500
1609
|
const extended = await this.db.update(promoCodeHolds).set({
|
|
1501
|
-
expiresAt:
|
|
1502
|
-
}).where((0,
|
|
1610
|
+
expiresAt: import_drizzle_orm11.sql`GREATEST(${promoCodeHolds.expiresAt}, ${atExpiry(expiresAt)})`
|
|
1611
|
+
}).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(promoCodeHolds.checkoutOfferId, checkoutOfferId), (0, import_drizzle_orm11.eq)(promoCodeHolds.promoCodeId, promoCodeId))).returning({
|
|
1503
1612
|
id: promoCodeHolds.id
|
|
1504
1613
|
});
|
|
1505
1614
|
return extended.length === 1;
|
|
1506
1615
|
}
|
|
1507
1616
|
async release(checkoutOfferId, tx) {
|
|
1508
|
-
return this.releaseWhere((0,
|
|
1617
|
+
return this.releaseWhere((0, import_drizzle_orm11.eq)(promoCodeHolds.checkoutOfferId, checkoutOfferId), tx);
|
|
1509
1618
|
}
|
|
1510
1619
|
async releaseIfUnmoved(checkoutOfferId, expiresAt) {
|
|
1511
|
-
return this.releaseWhere((0,
|
|
1620
|
+
return this.releaseWhere((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(promoCodeHolds.checkoutOfferId, checkoutOfferId), (0, import_drizzle_orm11.eq)(promoCodeHolds.expiresAt, expiresAt)));
|
|
1512
1621
|
}
|
|
1513
1622
|
async handOver(checkoutOfferId, now, tx) {
|
|
1514
1623
|
const marked = await resolveDb(this.db, tx).update(promoCodeHolds).set({
|
|
1515
1624
|
handedOverTx: CURRENT_TRANSACTION
|
|
1516
|
-
}).where((0,
|
|
1625
|
+
}).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(promoCodeHolds.checkoutOfferId, checkoutOfferId), (0, import_drizzle_orm11.gt)(promoCodeHolds.expiresAt, now))).returning({
|
|
1517
1626
|
id: promoCodeHolds.id
|
|
1518
1627
|
});
|
|
1519
1628
|
return marked.length === 1;
|
|
@@ -1522,9 +1631,9 @@ var DrizzlePromoCodeHoldRepository = class {
|
|
|
1522
1631
|
const db = resolveDb(this.db, tx);
|
|
1523
1632
|
const handedOver = await db.select({
|
|
1524
1633
|
id: promoCodeHolds.id
|
|
1525
|
-
}).from(promoCodeHolds).where((0,
|
|
1634
|
+
}).from(promoCodeHolds).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(promoCodeHolds.promoCodeId, promoCodeId), (0, import_drizzle_orm11.eq)(promoCodeHolds.handedOverTx, CURRENT_TRANSACTION))).limit(1);
|
|
1526
1635
|
if (handedOver.length === 0) return false;
|
|
1527
|
-
const gone = await db.delete(promoCodeHolds).where((0,
|
|
1636
|
+
const gone = await db.delete(promoCodeHolds).where((0, import_drizzle_orm11.eq)(promoCodeHolds.id, handedOver[0].id)).returning({
|
|
1528
1637
|
promoCodeId: promoCodeHolds.promoCodeId
|
|
1529
1638
|
});
|
|
1530
1639
|
await giveBack(db, gone, {
|
|
@@ -1534,7 +1643,7 @@ var DrizzlePromoCodeHoldRepository = class {
|
|
|
1534
1643
|
}
|
|
1535
1644
|
async expireDue(now, promoCodeId, tx) {
|
|
1536
1645
|
return this.onTransaction(tx, async (db) => {
|
|
1537
|
-
const gone = await db.delete(promoCodeHolds).where((0,
|
|
1646
|
+
const gone = await db.delete(promoCodeHolds).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.lte)(promoCodeHolds.expiresAt, now), import_drizzle_orm11.sql`${promoCodeHolds.handedOverTx} IS DISTINCT FROM ${CURRENT_TRANSACTION}`, promoCodeId ? (0, import_drizzle_orm11.eq)(promoCodeHolds.promoCodeId, promoCodeId) : void 0)).returning({
|
|
1538
1647
|
promoCodeId: promoCodeHolds.promoCodeId
|
|
1539
1648
|
});
|
|
1540
1649
|
await giveBack(db, gone, {
|
|
@@ -1560,11 +1669,11 @@ var DrizzlePromoCodeHoldRepository = class {
|
|
|
1560
1669
|
return resolveDb(this.db, tx).transaction((transaction) => work(transaction));
|
|
1561
1670
|
}
|
|
1562
1671
|
};
|
|
1563
|
-
DrizzlePromoCodeHoldRepository =
|
|
1564
|
-
(0,
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1672
|
+
DrizzlePromoCodeHoldRepository = _ts_decorate13([
|
|
1673
|
+
(0, import_common13.Injectable)(),
|
|
1674
|
+
_ts_param12(0, (0, import_common13.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1675
|
+
_ts_metadata12("design:type", Function),
|
|
1676
|
+
_ts_metadata12("design:paramtypes", [
|
|
1568
1677
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1569
1678
|
])
|
|
1570
1679
|
], DrizzlePromoCodeHoldRepository);
|
|
@@ -1578,37 +1687,37 @@ async function giveBack(db, ended, { redeemed }) {
|
|
|
1578
1687
|
].sort()) {
|
|
1579
1688
|
const count4 = perCode.get(promoCodeId) ?? 0;
|
|
1580
1689
|
await db.update(promoCodes).set({
|
|
1581
|
-
heldCount:
|
|
1690
|
+
heldCount: import_drizzle_orm11.sql`GREATEST(${promoCodes.heldCount} - ${count4}, 0)`,
|
|
1582
1691
|
...redeemed ? {
|
|
1583
|
-
redemptionsCount:
|
|
1692
|
+
redemptionsCount: import_drizzle_orm11.sql`${promoCodes.redemptionsCount} + ${count4}`
|
|
1584
1693
|
} : {},
|
|
1585
1694
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1586
|
-
}).where((0,
|
|
1695
|
+
}).where((0, import_drizzle_orm11.eq)(promoCodes.id, promoCodeId));
|
|
1587
1696
|
}
|
|
1588
1697
|
}
|
|
1589
1698
|
__name(giveBack, "giveBack");
|
|
1590
1699
|
|
|
1591
1700
|
// src/drizzle-promo-code-redemption.repository.ts
|
|
1592
|
-
var
|
|
1593
|
-
var
|
|
1594
|
-
var
|
|
1595
|
-
function
|
|
1596
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1597
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1701
|
+
var import_node_crypto8 = require("node:crypto");
|
|
1702
|
+
var import_common14 = require("@nestjs/common");
|
|
1703
|
+
var import_drizzle_orm12 = require("drizzle-orm");
|
|
1704
|
+
function _ts_decorate14(decorators, target, key, desc11) {
|
|
1705
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1706
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1598
1707
|
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;
|
|
1599
1708
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1600
1709
|
}
|
|
1601
|
-
__name(
|
|
1602
|
-
function
|
|
1710
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
1711
|
+
function _ts_metadata13(k, v) {
|
|
1603
1712
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1604
1713
|
}
|
|
1605
|
-
__name(
|
|
1606
|
-
function
|
|
1714
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
1715
|
+
function _ts_param13(paramIndex, decorator) {
|
|
1607
1716
|
return function(target, key) {
|
|
1608
1717
|
decorator(target, key, paramIndex);
|
|
1609
1718
|
};
|
|
1610
1719
|
}
|
|
1611
|
-
__name(
|
|
1720
|
+
__name(_ts_param13, "_ts_param");
|
|
1612
1721
|
var DrizzlePromoCodeRedemptionRepository = class {
|
|
1613
1722
|
static {
|
|
1614
1723
|
__name(this, "DrizzlePromoCodeRedemptionRepository");
|
|
@@ -1619,14 +1728,14 @@ var DrizzlePromoCodeRedemptionRepository = class {
|
|
|
1619
1728
|
}
|
|
1620
1729
|
async findBySubscription(subscriptionId, tx) {
|
|
1621
1730
|
const db = resolveDb(this.db, tx);
|
|
1622
|
-
const rows = await db.select().from(promoCodeRedemptions).where((0,
|
|
1731
|
+
const rows = await db.select().from(promoCodeRedemptions).where((0, import_drizzle_orm12.eq)(promoCodeRedemptions.subscriptionId, subscriptionId)).limit(1);
|
|
1623
1732
|
const row = rows[0];
|
|
1624
1733
|
return row ? toRecord2(row) : null;
|
|
1625
1734
|
}
|
|
1626
1735
|
async create(data, tx) {
|
|
1627
1736
|
const db = resolveDb(this.db, tx);
|
|
1628
1737
|
const rows = await db.insert(promoCodeRedemptions).values({
|
|
1629
|
-
id: (0,
|
|
1738
|
+
id: (0, import_node_crypto8.randomUUID)(),
|
|
1630
1739
|
promoCodeId: data.promoCodeId,
|
|
1631
1740
|
subscriptionId: data.subscriptionId,
|
|
1632
1741
|
tenantId: data.tenantId,
|
|
@@ -1644,7 +1753,7 @@ var DrizzlePromoCodeRedemptionRepository = class {
|
|
|
1644
1753
|
const rows = await db.update(promoCodeRedemptions).set({
|
|
1645
1754
|
status: "REVERSED",
|
|
1646
1755
|
reversedAt: /* @__PURE__ */ new Date()
|
|
1647
|
-
}).where((0,
|
|
1756
|
+
}).where((0, import_drizzle_orm12.eq)(promoCodeRedemptions.id, id)).returning();
|
|
1648
1757
|
const row = rows[0];
|
|
1649
1758
|
if (!row) {
|
|
1650
1759
|
throw new Error(`PromoCodeRedemption ${id} not found.`);
|
|
@@ -1654,27 +1763,27 @@ var DrizzlePromoCodeRedemptionRepository = class {
|
|
|
1654
1763
|
async countByPromoCode(promoCodeId, status) {
|
|
1655
1764
|
const rows = await this.db.select({
|
|
1656
1765
|
id: promoCodeRedemptions.id
|
|
1657
|
-
}).from(promoCodeRedemptions).where((0,
|
|
1766
|
+
}).from(promoCodeRedemptions).where((0, import_drizzle_orm12.and)((0, import_drizzle_orm12.eq)(promoCodeRedemptions.promoCodeId, promoCodeId), status ? (0, import_drizzle_orm12.eq)(promoCodeRedemptions.status, status) : void 0));
|
|
1658
1767
|
return rows.length;
|
|
1659
1768
|
}
|
|
1660
1769
|
async listByPromoCode(promoCodeId) {
|
|
1661
|
-
const rows = await this.db.select().from(promoCodeRedemptions).where((0,
|
|
1770
|
+
const rows = await this.db.select().from(promoCodeRedemptions).where((0, import_drizzle_orm12.eq)(promoCodeRedemptions.promoCodeId, promoCodeId)).orderBy((0, import_drizzle_orm12.desc)(promoCodeRedemptions.redeemedAt));
|
|
1662
1771
|
return rows.map(toRecord2);
|
|
1663
1772
|
}
|
|
1664
1773
|
async expireDueRedemptions(now) {
|
|
1665
1774
|
const expired = await this.db.update(promoCodeRedemptions).set({
|
|
1666
1775
|
status: "EXPIRED"
|
|
1667
|
-
}).where((0,
|
|
1776
|
+
}).where((0, import_drizzle_orm12.and)((0, import_drizzle_orm12.eq)(promoCodeRedemptions.status, "ACTIVE"), (0, import_drizzle_orm12.lt)(promoCodeRedemptions.endsAt, now))).returning({
|
|
1668
1777
|
id: promoCodeRedemptions.id
|
|
1669
1778
|
});
|
|
1670
1779
|
return expired.length;
|
|
1671
1780
|
}
|
|
1672
1781
|
};
|
|
1673
|
-
DrizzlePromoCodeRedemptionRepository =
|
|
1674
|
-
(0,
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1782
|
+
DrizzlePromoCodeRedemptionRepository = _ts_decorate14([
|
|
1783
|
+
(0, import_common14.Injectable)(),
|
|
1784
|
+
_ts_param13(0, (0, import_common14.Inject)(DRIZZLE_DB_TOKEN)),
|
|
1785
|
+
_ts_metadata13("design:type", Function),
|
|
1786
|
+
_ts_metadata13("design:paramtypes", [
|
|
1678
1787
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
1679
1788
|
])
|
|
1680
1789
|
], DrizzlePromoCodeRedemptionRepository);
|
|
@@ -1698,27 +1807,27 @@ function toRecord2(row) {
|
|
|
1698
1807
|
__name(toRecord2, "toRecord");
|
|
1699
1808
|
|
|
1700
1809
|
// src/drizzle-bundle.repository.ts
|
|
1701
|
-
var
|
|
1702
|
-
var
|
|
1703
|
-
var
|
|
1704
|
-
var
|
|
1705
|
-
function
|
|
1706
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1707
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1810
|
+
var import_node_crypto9 = require("node:crypto");
|
|
1811
|
+
var import_common15 = require("@nestjs/common");
|
|
1812
|
+
var import_drizzle_orm13 = require("drizzle-orm");
|
|
1813
|
+
var import_core4 = require("@saasicat/core");
|
|
1814
|
+
function _ts_decorate15(decorators, target, key, desc11) {
|
|
1815
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
1816
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1708
1817
|
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;
|
|
1709
1818
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1710
1819
|
}
|
|
1711
|
-
__name(
|
|
1712
|
-
function
|
|
1820
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
1821
|
+
function _ts_metadata14(k, v) {
|
|
1713
1822
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1714
1823
|
}
|
|
1715
|
-
__name(
|
|
1716
|
-
function
|
|
1824
|
+
__name(_ts_metadata14, "_ts_metadata");
|
|
1825
|
+
function _ts_param14(paramIndex, decorator) {
|
|
1717
1826
|
return function(target, key) {
|
|
1718
1827
|
decorator(target, key, paramIndex);
|
|
1719
1828
|
};
|
|
1720
1829
|
}
|
|
1721
|
-
__name(
|
|
1830
|
+
__name(_ts_param14, "_ts_param");
|
|
1722
1831
|
var DrizzleBundleRepository = class {
|
|
1723
1832
|
static {
|
|
1724
1833
|
__name(this, "DrizzleBundleRepository");
|
|
@@ -1736,12 +1845,12 @@ var DrizzleBundleRepository = class {
|
|
|
1736
1845
|
// ─── Stems ───
|
|
1737
1846
|
async list(filter) {
|
|
1738
1847
|
const excludeDeleted = filter.excludeDeleted ?? true;
|
|
1739
|
-
const rows = await this.db.select().from(bundles).where(excludeDeleted ? (0,
|
|
1740
|
-
return rows.map(
|
|
1848
|
+
const rows = await this.db.select().from(bundles).where(excludeDeleted ? (0, import_drizzle_orm13.isNull)(bundles.deletedAt) : void 0).orderBy((0, import_drizzle_orm13.asc)(bundles.sortOrder), (0, import_drizzle_orm13.asc)(bundles.bundleKey));
|
|
1849
|
+
return rows.map(import_core4.toBundleStemRow);
|
|
1741
1850
|
}
|
|
1742
1851
|
async findById(bundleId) {
|
|
1743
|
-
const rows = await this.db.select().from(bundles).where((0,
|
|
1744
|
-
return rows[0] ? (0,
|
|
1852
|
+
const rows = await this.db.select().from(bundles).where((0, import_drizzle_orm13.eq)(bundles.id, bundleId)).limit(1);
|
|
1853
|
+
return rows[0] ? (0, import_core4.toBundleStemRow)(rows[0]) : null;
|
|
1745
1854
|
}
|
|
1746
1855
|
/**
|
|
1747
1856
|
* Whether this project already uses this bundle key — **including retired
|
|
@@ -1759,17 +1868,17 @@ var DrizzleBundleRepository = class {
|
|
|
1759
1868
|
* reading. `list` is that lookup, and it excludes retired rows by default.
|
|
1760
1869
|
*/
|
|
1761
1870
|
async findByKey(bundleKey) {
|
|
1762
|
-
const rows = await this.db.select().from(bundles).where((0,
|
|
1763
|
-
return rows[0] ? (0,
|
|
1871
|
+
const rows = await this.db.select().from(bundles).where((0, import_drizzle_orm13.eq)(bundles.bundleKey, bundleKey)).limit(1);
|
|
1872
|
+
return rows[0] ? (0, import_core4.toBundleStemRow)(rows[0]) : null;
|
|
1764
1873
|
}
|
|
1765
1874
|
async create(data) {
|
|
1766
1875
|
const now = /* @__PURE__ */ new Date();
|
|
1767
1876
|
const rows = await this.db.insert(bundles).values({
|
|
1768
|
-
id: (0,
|
|
1769
|
-
...(0,
|
|
1877
|
+
id: (0, import_node_crypto9.randomUUID)(),
|
|
1878
|
+
...(0, import_core4.bundleStemDefaults)(data),
|
|
1770
1879
|
updatedAt: now
|
|
1771
1880
|
}).returning();
|
|
1772
|
-
return (0,
|
|
1881
|
+
return (0, import_core4.toBundleStemRow)(rows[0]);
|
|
1773
1882
|
}
|
|
1774
1883
|
async update(bundleId, data) {
|
|
1775
1884
|
const patch = {
|
|
@@ -1780,34 +1889,34 @@ var DrizzleBundleRepository = class {
|
|
|
1780
1889
|
if (data.icon !== void 0) patch.icon = data.icon;
|
|
1781
1890
|
if (data.sortOrder !== void 0) patch.sortOrder = data.sortOrder;
|
|
1782
1891
|
if (data.i18n !== void 0) patch.i18n = data.i18n;
|
|
1783
|
-
const rows = await this.db.update(bundles).set(patch).where((0,
|
|
1892
|
+
const rows = await this.db.update(bundles).set(patch).where((0, import_drizzle_orm13.eq)(bundles.id, bundleId)).returning();
|
|
1784
1893
|
if (!rows[0]) throw new Error(`Bundle '${bundleId}' not found.`);
|
|
1785
|
-
return (0,
|
|
1894
|
+
return (0, import_core4.toBundleStemRow)(rows[0]);
|
|
1786
1895
|
}
|
|
1787
1896
|
async softDelete(bundleId) {
|
|
1788
1897
|
await this.db.update(bundles).set({
|
|
1789
1898
|
deletedAt: /* @__PURE__ */ new Date(),
|
|
1790
1899
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1791
|
-
}).where((0,
|
|
1900
|
+
}).where((0, import_drizzle_orm13.eq)(bundles.id, bundleId));
|
|
1792
1901
|
}
|
|
1793
1902
|
// ─── Versions ───
|
|
1794
1903
|
async listVersions(bundleId) {
|
|
1795
|
-
const rows = await this.db.select().from(bundleVersions).where((0,
|
|
1904
|
+
const rows = await this.db.select().from(bundleVersions).where((0, import_drizzle_orm13.eq)(bundleVersions.bundleId, bundleId)).orderBy((0, import_drizzle_orm13.asc)(bundleVersions.version));
|
|
1796
1905
|
const stem = await this.findById(bundleId);
|
|
1797
1906
|
return rows.map((row) => this.toVersionRow(row, stem));
|
|
1798
1907
|
}
|
|
1799
1908
|
async findVersionById(versionId, tx) {
|
|
1800
|
-
const rows = await resolveDb(this.db, tx).select().from(bundleVersions).where((0,
|
|
1909
|
+
const rows = await resolveDb(this.db, tx).select().from(bundleVersions).where((0, import_drizzle_orm13.eq)(bundleVersions.id, versionId)).limit(1);
|
|
1801
1910
|
if (!rows[0]) return null;
|
|
1802
1911
|
return this.toVersionRow(rows[0], await this.stemOn(resolveDb(this.db, tx), rows[0].bundleId));
|
|
1803
1912
|
}
|
|
1804
1913
|
async findCurrentDraft(bundleId) {
|
|
1805
|
-
const rows = await this.db.select().from(bundleVersions).where((0,
|
|
1914
|
+
const rows = await this.db.select().from(bundleVersions).where((0, import_drizzle_orm13.and)((0, import_drizzle_orm13.eq)(bundleVersions.bundleId, bundleId), (0, import_drizzle_orm13.isNull)(bundleVersions.publishedAt))).limit(1);
|
|
1806
1915
|
if (!rows[0]) return null;
|
|
1807
1916
|
return this.toVersionRow(rows[0], await this.findById(bundleId));
|
|
1808
1917
|
}
|
|
1809
1918
|
async findLatestLive(bundleId, tx) {
|
|
1810
|
-
const rows = await resolveDb(this.db, tx).select().from(bundleVersions).where((0,
|
|
1919
|
+
const rows = await resolveDb(this.db, tx).select().from(bundleVersions).where((0, import_drizzle_orm13.and)((0, import_drizzle_orm13.eq)(bundleVersions.bundleId, bundleId), import_drizzle_orm13.sql`${bundleVersions.publishedAt} IS NOT NULL`, (0, import_drizzle_orm13.isNull)(bundleVersions.supersededAt))).orderBy((0, import_drizzle_orm13.desc)(bundleVersions.version)).limit(1);
|
|
1811
1920
|
return this.withStem(rows[0], bundleId, tx);
|
|
1812
1921
|
}
|
|
1813
1922
|
/**
|
|
@@ -1821,7 +1930,7 @@ var DrizzleBundleRepository = class {
|
|
|
1821
1930
|
async activeVersionAt(bundleId, asOf, tx) {
|
|
1822
1931
|
const dayStart = new Date(asOf);
|
|
1823
1932
|
dayStart.setUTCHours(0, 0, 0, 0);
|
|
1824
|
-
const rows = await resolveDb(this.db, tx).select().from(bundleVersions).where((0,
|
|
1933
|
+
const rows = await resolveDb(this.db, tx).select().from(bundleVersions).where((0, import_drizzle_orm13.and)((0, import_drizzle_orm13.eq)(bundleVersions.bundleId, bundleId), import_drizzle_orm13.sql`${bundleVersions.publishedAt} IS NOT NULL`, (0, import_drizzle_orm13.or)((0, import_drizzle_orm13.isNull)(bundleVersions.validFrom), (0, import_drizzle_orm13.lte)(bundleVersions.validFrom, asOf)), (0, import_drizzle_orm13.or)((0, import_drizzle_orm13.isNull)(bundleVersions.validUntil), (0, import_drizzle_orm13.gte)(bundleVersions.validUntil, dayStart)))).orderBy(import_drizzle_orm13.sql`"validFrom" DESC NULLS LAST`, (0, import_drizzle_orm13.desc)(bundleVersions.version)).limit(1);
|
|
1825
1934
|
return this.withStem(rows[0], bundleId, tx);
|
|
1826
1935
|
}
|
|
1827
1936
|
async createDraft(data) {
|
|
@@ -1831,13 +1940,13 @@ var DrizzleBundleRepository = class {
|
|
|
1831
1940
|
}
|
|
1832
1941
|
const latest = await this.db.select({
|
|
1833
1942
|
version: bundleVersions.version
|
|
1834
|
-
}).from(bundleVersions).where((0,
|
|
1943
|
+
}).from(bundleVersions).where((0, import_drizzle_orm13.eq)(bundleVersions.bundleId, data.bundleId)).orderBy((0, import_drizzle_orm13.desc)(bundleVersions.version)).limit(1);
|
|
1835
1944
|
const now = /* @__PURE__ */ new Date();
|
|
1836
1945
|
const rows = await this.db.insert(bundleVersions).values({
|
|
1837
|
-
id: (0,
|
|
1946
|
+
id: (0, import_node_crypto9.randomUUID)(),
|
|
1838
1947
|
bundleId: data.bundleId,
|
|
1839
1948
|
version: latest[0] ? latest[0].version + 1 : 1,
|
|
1840
|
-
...(0,
|
|
1949
|
+
...(0, import_core4.bundleDraftDefaults)(data),
|
|
1841
1950
|
validFrom: this.validityWindows ? toNullableDate(data.validFrom) : null,
|
|
1842
1951
|
validUntil: this.validityWindows ? toNullableDate(data.validUntil) : null,
|
|
1843
1952
|
updatedAt: now
|
|
@@ -1860,7 +1969,7 @@ var DrizzleBundleRepository = class {
|
|
|
1860
1969
|
if (data.validFrom !== void 0) patch.validFrom = toNullableDate(data.validFrom);
|
|
1861
1970
|
if (data.validUntil !== void 0) patch.validUntil = toNullableDate(data.validUntil);
|
|
1862
1971
|
}
|
|
1863
|
-
const rows = await this.db.update(bundleVersions).set(patch).where((0,
|
|
1972
|
+
const rows = await this.db.update(bundleVersions).set(patch).where((0, import_drizzle_orm13.eq)(bundleVersions.id, versionId)).returning();
|
|
1864
1973
|
if (!rows[0]) throw new Error(`BundleVersion '${versionId}' not found.`);
|
|
1865
1974
|
return this.toVersionRow(rows[0], await this.findById(rows[0].bundleId));
|
|
1866
1975
|
}
|
|
@@ -1880,28 +1989,28 @@ var DrizzleBundleRepository = class {
|
|
|
1880
1989
|
validFrom: publishMeta.validFrom,
|
|
1881
1990
|
validUntil: publishMeta.validUntil
|
|
1882
1991
|
} : {}
|
|
1883
|
-
}).where((0,
|
|
1992
|
+
}).where((0, import_drizzle_orm13.and)((0, import_drizzle_orm13.eq)(bundleVersions.id, versionId), (0, import_drizzle_orm13.isNull)(bundleVersions.publishedAt))).returning();
|
|
1884
1993
|
if (!publishedRows[0]) {
|
|
1885
1994
|
throw new Error(`BundleVersion '${versionId}' not found or already published.`);
|
|
1886
1995
|
}
|
|
1887
1996
|
const draft = publishedRows[0];
|
|
1888
1997
|
await db.update(bundleVersions).set(this.validityWindows ? {
|
|
1889
1998
|
supersededAt: now,
|
|
1890
|
-
validUntil: (0,
|
|
1999
|
+
validUntil: (0, import_core4.previousUtcDay)(publishMeta.validFrom)
|
|
1891
2000
|
} : {
|
|
1892
2001
|
supersededAt: now
|
|
1893
|
-
}).where((0,
|
|
1894
|
-
const stemRows = await db.select().from(bundles).where((0,
|
|
1895
|
-
return this.toVersionRow(publishedRows[0], stemRows[0] ? (0,
|
|
2002
|
+
}).where((0, import_drizzle_orm13.and)((0, import_drizzle_orm13.eq)(bundleVersions.bundleId, draft.bundleId), import_drizzle_orm13.sql`${bundleVersions.publishedAt} IS NOT NULL`, (0, import_drizzle_orm13.isNull)(bundleVersions.supersededAt), (0, import_drizzle_orm13.ne)(bundleVersions.id, versionId)));
|
|
2003
|
+
const stemRows = await db.select().from(bundles).where((0, import_drizzle_orm13.eq)(bundles.id, draft.bundleId)).limit(1);
|
|
2004
|
+
return this.toVersionRow(publishedRows[0], stemRows[0] ? (0, import_core4.toBundleStemRow)(stemRows[0]) : null);
|
|
1896
2005
|
}
|
|
1897
2006
|
async deleteDraft(versionId) {
|
|
1898
|
-
const deleted = await this.db.delete(bundleVersions).where((0,
|
|
2007
|
+
const deleted = await this.db.delete(bundleVersions).where((0, import_drizzle_orm13.and)((0, import_drizzle_orm13.eq)(bundleVersions.id, versionId), (0, import_drizzle_orm13.isNull)(bundleVersions.publishedAt))).returning({
|
|
1899
2008
|
id: bundleVersions.id
|
|
1900
2009
|
});
|
|
1901
2010
|
if (deleted.length > 0) return;
|
|
1902
2011
|
const remaining = await this.db.select({
|
|
1903
2012
|
publishedAt: bundleVersions.publishedAt
|
|
1904
|
-
}).from(bundleVersions).where((0,
|
|
2013
|
+
}).from(bundleVersions).where((0, import_drizzle_orm13.eq)(bundleVersions.id, versionId)).limit(1);
|
|
1905
2014
|
if (!remaining[0]) return;
|
|
1906
2015
|
throw new Error(`BundleVersion '${versionId}' is already published and cannot be discarded (published versions are immutable \u2014 contract protection P1).`);
|
|
1907
2016
|
}
|
|
@@ -1927,8 +2036,8 @@ var DrizzleBundleRepository = class {
|
|
|
1927
2036
|
* does not is the shape that hides it: the deadlock needs load to appear.
|
|
1928
2037
|
*/
|
|
1929
2038
|
async stemOn(db, bundleId) {
|
|
1930
|
-
const rows = await db.select().from(bundles).where((0,
|
|
1931
|
-
return rows[0] ? (0,
|
|
2039
|
+
const rows = await db.select().from(bundles).where((0, import_drizzle_orm13.eq)(bundles.id, bundleId)).limit(1);
|
|
2040
|
+
return rows[0] ? (0, import_core4.toBundleStemRow)(rows[0]) : null;
|
|
1932
2041
|
}
|
|
1933
2042
|
toVersionRow(row, stem) {
|
|
1934
2043
|
return {
|
|
@@ -1962,12 +2071,12 @@ var DrizzleBundleRepository = class {
|
|
|
1962
2071
|
};
|
|
1963
2072
|
}
|
|
1964
2073
|
};
|
|
1965
|
-
DrizzleBundleRepository =
|
|
1966
|
-
(0,
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
2074
|
+
DrizzleBundleRepository = _ts_decorate15([
|
|
2075
|
+
(0, import_common15.Injectable)(),
|
|
2076
|
+
_ts_param14(0, (0, import_common15.Inject)(DRIZZLE_DB_TOKEN)),
|
|
2077
|
+
_ts_param14(1, (0, import_common15.Optional)()),
|
|
2078
|
+
_ts_metadata14("design:type", Function),
|
|
2079
|
+
_ts_metadata14("design:paramtypes", [
|
|
1971
2080
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient,
|
|
1972
2081
|
typeof DrizzleBundleRepositoryOptions === "undefined" ? Object : DrizzleBundleRepositoryOptions
|
|
1973
2082
|
])
|
|
@@ -1982,27 +2091,27 @@ function toNullableDate(value) {
|
|
|
1982
2091
|
__name(toNullableDate, "toNullableDate");
|
|
1983
2092
|
|
|
1984
2093
|
// src/drizzle-plan.repository.ts
|
|
1985
|
-
var
|
|
1986
|
-
var
|
|
1987
|
-
var
|
|
1988
|
-
var
|
|
1989
|
-
function
|
|
1990
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1991
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
2094
|
+
var import_node_crypto10 = require("node:crypto");
|
|
2095
|
+
var import_common16 = require("@nestjs/common");
|
|
2096
|
+
var import_drizzle_orm14 = require("drizzle-orm");
|
|
2097
|
+
var import_core5 = require("@saasicat/core");
|
|
2098
|
+
function _ts_decorate16(decorators, target, key, desc11) {
|
|
2099
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
2100
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
1992
2101
|
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;
|
|
1993
2102
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1994
2103
|
}
|
|
1995
|
-
__name(
|
|
1996
|
-
function
|
|
2104
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
2105
|
+
function _ts_metadata15(k, v) {
|
|
1997
2106
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1998
2107
|
}
|
|
1999
|
-
__name(
|
|
2000
|
-
function
|
|
2108
|
+
__name(_ts_metadata15, "_ts_metadata");
|
|
2109
|
+
function _ts_param15(paramIndex, decorator) {
|
|
2001
2110
|
return function(target, key) {
|
|
2002
2111
|
decorator(target, key, paramIndex);
|
|
2003
2112
|
};
|
|
2004
2113
|
}
|
|
2005
|
-
__name(
|
|
2114
|
+
__name(_ts_param15, "_ts_param");
|
|
2006
2115
|
var DrizzlePlanRepository = class {
|
|
2007
2116
|
static {
|
|
2008
2117
|
__name(this, "DrizzlePlanRepository");
|
|
@@ -2020,23 +2129,23 @@ var DrizzlePlanRepository = class {
|
|
|
2020
2129
|
// ─── Stem operations ───
|
|
2021
2130
|
async list(filter) {
|
|
2022
2131
|
const excludeDeleted = filter.excludeDeleted ?? true;
|
|
2023
|
-
const stems = await this.db.select().from(plans).where((0,
|
|
2024
|
-
(0,
|
|
2025
|
-
] : [])).orderBy((0,
|
|
2026
|
-
if (!filter.onlyPublished) return stems.map(
|
|
2132
|
+
const stems = await this.db.select().from(plans).where((0, import_drizzle_orm14.and)(...excludeDeleted ? [
|
|
2133
|
+
(0, import_drizzle_orm14.isNull)(plans.deletedAt)
|
|
2134
|
+
] : [])).orderBy((0, import_drizzle_orm14.asc)(plans.sortOrder), (0, import_drizzle_orm14.asc)(plans.planKey));
|
|
2135
|
+
if (!filter.onlyPublished) return stems.map(import_core5.toPlanRow);
|
|
2027
2136
|
if (stems.length === 0) return [];
|
|
2028
2137
|
const candidateKeys = [
|
|
2029
2138
|
...new Set(stems.map((stem) => stem.planKey))
|
|
2030
2139
|
];
|
|
2031
2140
|
const live = await this.db.select({
|
|
2032
2141
|
planId: planVersions.planId
|
|
2033
|
-
}).from(planVersions).where((0,
|
|
2142
|
+
}).from(planVersions).where((0, import_drizzle_orm14.and)((0, import_drizzle_orm14.inArray)(planVersions.planId, candidateKeys), import_drizzle_orm14.sql`${planVersions.publishedAt} IS NOT NULL`, (0, import_drizzle_orm14.isNull)(planVersions.supersededAt)));
|
|
2034
2143
|
const publishedKeys = new Set(live.map((row) => row.planId));
|
|
2035
|
-
return stems.filter((stem) => publishedKeys.has(stem.planKey)).map(
|
|
2144
|
+
return stems.filter((stem) => publishedKeys.has(stem.planKey)).map(import_core5.toPlanRow);
|
|
2036
2145
|
}
|
|
2037
2146
|
async findById(planId) {
|
|
2038
|
-
const rows = await this.db.select().from(plans).where((0,
|
|
2039
|
-
return rows[0] ? (0,
|
|
2147
|
+
const rows = await this.db.select().from(plans).where((0, import_drizzle_orm14.eq)(plans.id, planId)).limit(1);
|
|
2148
|
+
return rows[0] ? (0, import_core5.toPlanRow)(rows[0]) : null;
|
|
2040
2149
|
}
|
|
2041
2150
|
/**
|
|
2042
2151
|
* Whether this installation already uses this plan key — **including
|
|
@@ -2047,13 +2156,13 @@ var DrizzlePlanRepository = class {
|
|
|
2047
2156
|
* rather than the active catalogue's. `list` is that other lookup.
|
|
2048
2157
|
*/
|
|
2049
2158
|
async findByKey(planKey) {
|
|
2050
|
-
const rows = await this.db.select().from(plans).where((0,
|
|
2051
|
-
return rows[0] ? (0,
|
|
2159
|
+
const rows = await this.db.select().from(plans).where((0, import_drizzle_orm14.eq)(plans.planKey, planKey)).limit(1);
|
|
2160
|
+
return rows[0] ? (0, import_core5.toPlanRow)(rows[0]) : null;
|
|
2052
2161
|
}
|
|
2053
2162
|
async create(data) {
|
|
2054
2163
|
const now = /* @__PURE__ */ new Date();
|
|
2055
2164
|
const rows = await this.db.insert(plans).values({
|
|
2056
|
-
id: (0,
|
|
2165
|
+
id: (0, import_node_crypto10.randomUUID)(),
|
|
2057
2166
|
planKey: data.planKey,
|
|
2058
2167
|
label: data.label,
|
|
2059
2168
|
description: data.description ?? null,
|
|
@@ -2062,7 +2171,7 @@ var DrizzlePlanRepository = class {
|
|
|
2062
2171
|
createdAt: now,
|
|
2063
2172
|
updatedAt: now
|
|
2064
2173
|
}).returning();
|
|
2065
|
-
return (0,
|
|
2174
|
+
return (0, import_core5.toPlanRow)(rows[0]);
|
|
2066
2175
|
}
|
|
2067
2176
|
async update(planId, data) {
|
|
2068
2177
|
const rows = await this.db.update(plans).set({
|
|
@@ -2079,23 +2188,23 @@ var DrizzlePlanRepository = class {
|
|
|
2079
2188
|
sortOrder: data.sortOrder
|
|
2080
2189
|
} : {},
|
|
2081
2190
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2082
|
-
}).where((0,
|
|
2191
|
+
}).where((0, import_drizzle_orm14.eq)(plans.id, planId)).returning();
|
|
2083
2192
|
if (!rows[0]) throw new Error(`Plan '${planId}' not found.`);
|
|
2084
|
-
return (0,
|
|
2193
|
+
return (0, import_core5.toPlanRow)(rows[0]);
|
|
2085
2194
|
}
|
|
2086
2195
|
async softDelete(planId) {
|
|
2087
2196
|
const now = /* @__PURE__ */ new Date();
|
|
2088
2197
|
await this.db.update(plans).set({
|
|
2089
2198
|
deletedAt: now,
|
|
2090
2199
|
updatedAt: now
|
|
2091
|
-
}).where((0,
|
|
2200
|
+
}).where((0, import_drizzle_orm14.eq)(plans.id, planId));
|
|
2092
2201
|
}
|
|
2093
2202
|
async hardDelete(planId) {
|
|
2094
|
-
await this.db.delete(plans).where((0,
|
|
2203
|
+
await this.db.delete(plans).where((0, import_drizzle_orm14.eq)(plans.id, planId));
|
|
2095
2204
|
}
|
|
2096
2205
|
// ─── Version lifecycle — keyed by plan key ───
|
|
2097
2206
|
async listVersions(planKey) {
|
|
2098
|
-
const rows = await this.db.select().from(planVersions).where((0,
|
|
2207
|
+
const rows = await this.db.select().from(planVersions).where((0, import_drizzle_orm14.eq)(planVersions.planId, planKey)).orderBy((0, import_drizzle_orm14.asc)(planVersions.version));
|
|
2099
2208
|
return rows.map((row) => this.versionRow(row));
|
|
2100
2209
|
}
|
|
2101
2210
|
/**
|
|
@@ -2105,23 +2214,25 @@ var DrizzlePlanRepository = class {
|
|
|
2105
2214
|
* one-connection pool never returns.
|
|
2106
2215
|
*/
|
|
2107
2216
|
async findVersionById(versionId, tx) {
|
|
2108
|
-
const rows = await resolveDb(this.db, tx).select().from(planVersions).where((0,
|
|
2217
|
+
const rows = await resolveDb(this.db, tx).select().from(planVersions).where((0, import_drizzle_orm14.eq)(planVersions.id, versionId)).limit(1);
|
|
2109
2218
|
return rows[0] ? this.versionRow(rows[0]) : null;
|
|
2110
2219
|
}
|
|
2111
2220
|
async findCurrentDraft(planKey) {
|
|
2112
|
-
const rows = await this.db.select().from(planVersions).where((0,
|
|
2221
|
+
const rows = await this.db.select().from(planVersions).where((0, import_drizzle_orm14.and)((0, import_drizzle_orm14.eq)(planVersions.planId, planKey), (0, import_drizzle_orm14.isNull)(planVersions.publishedAt))).orderBy((0, import_drizzle_orm14.desc)(planVersions.version)).limit(1);
|
|
2113
2222
|
return rows[0] ? this.versionRow(rows[0]) : null;
|
|
2114
2223
|
}
|
|
2115
2224
|
async findLatestLivePlanVersion(planKey, tx) {
|
|
2116
|
-
const rows = await resolveDb(this.db, tx).select().from(planVersions).where((0,
|
|
2117
|
-
(0,
|
|
2118
|
-
|
|
2119
|
-
(0,
|
|
2225
|
+
const rows = await resolveDb(this.db, tx).select().from(planVersions).where((0, import_drizzle_orm14.and)(
|
|
2226
|
+
(0, import_drizzle_orm14.eq)(planVersions.planId, planKey),
|
|
2227
|
+
import_drizzle_orm14.sql`${planVersions.publishedAt} IS NOT NULL`,
|
|
2228
|
+
(0, import_drizzle_orm14.isNull)(planVersions.supersededAt),
|
|
2120
2229
|
// A version the operator terminated is not live, whatever
|
|
2121
2230
|
// its supersession says: `terminate` sets `endsAt` without
|
|
2122
|
-
// a successor to supersede it.
|
|
2123
|
-
|
|
2124
|
-
|
|
2231
|
+
// a successor to supersede it. Compared with the
|
|
2232
|
+
// application's clock, which wrote it: the database's
|
|
2233
|
+
// `NOW()` reads the column in the session's zone.
|
|
2234
|
+
(0, import_drizzle_orm14.or)((0, import_drizzle_orm14.isNull)(planVersions.endsAt), (0, import_drizzle_orm14.gt)(planVersions.endsAt, /* @__PURE__ */ new Date()))
|
|
2235
|
+
)).orderBy((0, import_drizzle_orm14.desc)(planVersions.version)).limit(1);
|
|
2125
2236
|
return rows[0] ? this.versionRow(rows[0]) : null;
|
|
2126
2237
|
}
|
|
2127
2238
|
/**
|
|
@@ -2135,16 +2246,16 @@ var DrizzlePlanRepository = class {
|
|
|
2135
2246
|
* `@saasicat/core` so the two halves cannot drift apart.
|
|
2136
2247
|
*/
|
|
2137
2248
|
async activeVersionAt(planKey, asOf, tx) {
|
|
2138
|
-
const rows = await resolveDb(this.db, tx).select().from(planVersions).where((0,
|
|
2249
|
+
const rows = await resolveDb(this.db, tx).select().from(planVersions).where((0, import_drizzle_orm14.and)((0, import_drizzle_orm14.eq)(planVersions.planId, planKey), import_drizzle_orm14.sql`${planVersions.publishedAt} IS NOT NULL`, (0, import_drizzle_orm14.or)((0, import_drizzle_orm14.isNull)(planVersions.validFrom), (0, import_drizzle_orm14.lte)(planVersions.validFrom, asOf)), (0, import_drizzle_orm14.or)((0, import_drizzle_orm14.isNull)(planVersions.validUntil), (0, import_drizzle_orm14.gte)(planVersions.validUntil, (0, import_core5.startOfUtcDay)(asOf))), (0, import_drizzle_orm14.or)((0, import_drizzle_orm14.isNull)(planVersions.endsAt), (0, import_drizzle_orm14.gt)(planVersions.endsAt, asOf)))).orderBy(import_drizzle_orm14.sql`"validFrom" DESC NULLS LAST`, (0, import_drizzle_orm14.desc)(planVersions.version)).limit(1);
|
|
2139
2250
|
return rows[0] ? this.versionRow(rows[0]) : null;
|
|
2140
2251
|
}
|
|
2141
2252
|
async createPlanVersionDraft(data) {
|
|
2142
2253
|
const now = /* @__PURE__ */ new Date();
|
|
2143
2254
|
const latest = await this.db.select({
|
|
2144
2255
|
version: planVersions.version
|
|
2145
|
-
}).from(planVersions).where((0,
|
|
2256
|
+
}).from(planVersions).where((0, import_drizzle_orm14.eq)(planVersions.planId, data.planId)).orderBy((0, import_drizzle_orm14.desc)(planVersions.version)).limit(1);
|
|
2146
2257
|
const rows = await this.db.insert(planVersions).values({
|
|
2147
|
-
id: (0,
|
|
2258
|
+
id: (0, import_node_crypto10.randomUUID)(),
|
|
2148
2259
|
planId: data.planId,
|
|
2149
2260
|
version: (latest[0]?.version ?? 0) + 1,
|
|
2150
2261
|
baseVersionId: data.baseVersionId ?? null,
|
|
@@ -2193,7 +2304,7 @@ var DrizzlePlanRepository = class {
|
|
|
2193
2304
|
validUntil: toNullableDate2(data.validUntil)
|
|
2194
2305
|
} : {},
|
|
2195
2306
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2196
|
-
}).where((0,
|
|
2307
|
+
}).where((0, import_drizzle_orm14.eq)(planVersions.id, versionId)).returning();
|
|
2197
2308
|
if (!rows[0]) {
|
|
2198
2309
|
throw new Error(`PlanVersion '${versionId}' not found.`);
|
|
2199
2310
|
}
|
|
@@ -2215,28 +2326,28 @@ var DrizzlePlanRepository = class {
|
|
|
2215
2326
|
validFrom: publishMeta.validFrom,
|
|
2216
2327
|
validUntil: publishMeta.validUntil
|
|
2217
2328
|
} : {}
|
|
2218
|
-
}).where((0,
|
|
2329
|
+
}).where((0, import_drizzle_orm14.and)((0, import_drizzle_orm14.eq)(planVersions.id, versionId), (0, import_drizzle_orm14.isNull)(planVersions.publishedAt))).returning();
|
|
2219
2330
|
if (!publishedRows[0]) {
|
|
2220
2331
|
throw new Error(`PlanVersion '${versionId}' not found or already published.`);
|
|
2221
2332
|
}
|
|
2222
2333
|
await db.update(planVersions).set(this.validityWindows ? {
|
|
2223
2334
|
supersededAt: now,
|
|
2224
|
-
validUntil: (0,
|
|
2335
|
+
validUntil: (0, import_core5.previousUtcDay)(publishMeta.validFrom),
|
|
2225
2336
|
updatedAt: now
|
|
2226
2337
|
} : {
|
|
2227
2338
|
supersededAt: now,
|
|
2228
2339
|
updatedAt: now
|
|
2229
|
-
}).where((0,
|
|
2340
|
+
}).where((0, import_drizzle_orm14.and)((0, import_drizzle_orm14.eq)(planVersions.planId, publishedRows[0].planId), import_drizzle_orm14.sql`${planVersions.publishedAt} IS NOT NULL`, (0, import_drizzle_orm14.isNull)(planVersions.supersededAt), (0, import_drizzle_orm14.ne)(planVersions.id, versionId)));
|
|
2230
2341
|
return this.versionRow(publishedRows[0]);
|
|
2231
2342
|
}
|
|
2232
2343
|
async deletePlanVersionDraft(versionId) {
|
|
2233
|
-
const deleted = await this.db.delete(planVersions).where((0,
|
|
2344
|
+
const deleted = await this.db.delete(planVersions).where((0, import_drizzle_orm14.and)((0, import_drizzle_orm14.eq)(planVersions.id, versionId), (0, import_drizzle_orm14.isNull)(planVersions.publishedAt))).returning({
|
|
2234
2345
|
id: planVersions.id
|
|
2235
2346
|
});
|
|
2236
2347
|
if (deleted.length > 0) return;
|
|
2237
2348
|
const existing = await this.db.select({
|
|
2238
2349
|
publishedAt: planVersions.publishedAt
|
|
2239
|
-
}).from(planVersions).where((0,
|
|
2350
|
+
}).from(planVersions).where((0, import_drizzle_orm14.eq)(planVersions.id, versionId)).limit(1);
|
|
2240
2351
|
if (existing[0]) {
|
|
2241
2352
|
throw new Error(`PlanVersion '${versionId}' is already published and cannot be discarded (published versions are immutable \u2014 contract protection P1).`);
|
|
2242
2353
|
}
|
|
@@ -2245,12 +2356,12 @@ var DrizzlePlanRepository = class {
|
|
|
2245
2356
|
const rows = await this.db.update(planVersions).set({
|
|
2246
2357
|
endsAt,
|
|
2247
2358
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2248
|
-
}).where((0,
|
|
2359
|
+
}).where((0, import_drizzle_orm14.eq)(planVersions.id, versionId)).returning();
|
|
2249
2360
|
if (!rows[0]) throw new Error(`PlanVersion '${versionId}' not found.`);
|
|
2250
2361
|
return this.versionRow(rows[0]);
|
|
2251
2362
|
}
|
|
2252
2363
|
versionRow(row) {
|
|
2253
|
-
return (0,
|
|
2364
|
+
return (0, import_core5.toPlanVersionRow)(row, row.planId, {
|
|
2254
2365
|
validityWindows: this.validityWindows,
|
|
2255
2366
|
// The canonical schema always has the column, so this adapter can
|
|
2256
2367
|
// always answer the question — unlike a Prisma consumer whose
|
|
@@ -2259,12 +2370,12 @@ var DrizzlePlanRepository = class {
|
|
|
2259
2370
|
});
|
|
2260
2371
|
}
|
|
2261
2372
|
};
|
|
2262
|
-
DrizzlePlanRepository =
|
|
2263
|
-
(0,
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2373
|
+
DrizzlePlanRepository = _ts_decorate16([
|
|
2374
|
+
(0, import_common16.Injectable)(),
|
|
2375
|
+
_ts_param15(0, (0, import_common16.Inject)(DRIZZLE_DB_TOKEN)),
|
|
2376
|
+
_ts_param15(1, (0, import_common16.Optional)()),
|
|
2377
|
+
_ts_metadata15("design:type", Function),
|
|
2378
|
+
_ts_metadata15("design:paramtypes", [
|
|
2268
2379
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient,
|
|
2269
2380
|
typeof DrizzlePlanRepositoryOptions === "undefined" ? Object : DrizzlePlanRepositoryOptions
|
|
2270
2381
|
])
|
|
@@ -2275,27 +2386,27 @@ function toNullableDate2(value) {
|
|
|
2275
2386
|
__name(toNullableDate2, "toNullableDate");
|
|
2276
2387
|
|
|
2277
2388
|
// src/drizzle-subscription-contract.repository.ts
|
|
2278
|
-
var
|
|
2279
|
-
var
|
|
2280
|
-
var
|
|
2281
|
-
var
|
|
2282
|
-
function
|
|
2283
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2284
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
2389
|
+
var import_node_crypto11 = require("node:crypto");
|
|
2390
|
+
var import_common17 = require("@nestjs/common");
|
|
2391
|
+
var import_drizzle_orm15 = require("drizzle-orm");
|
|
2392
|
+
var import_core6 = require("@saasicat/core");
|
|
2393
|
+
function _ts_decorate17(decorators, target, key, desc11) {
|
|
2394
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
2395
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
2285
2396
|
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;
|
|
2286
2397
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2287
2398
|
}
|
|
2288
|
-
__name(
|
|
2289
|
-
function
|
|
2399
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
2400
|
+
function _ts_metadata16(k, v) {
|
|
2290
2401
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2291
2402
|
}
|
|
2292
|
-
__name(
|
|
2293
|
-
function
|
|
2403
|
+
__name(_ts_metadata16, "_ts_metadata");
|
|
2404
|
+
function _ts_param16(paramIndex, decorator) {
|
|
2294
2405
|
return function(target, key) {
|
|
2295
2406
|
decorator(target, key, paramIndex);
|
|
2296
2407
|
};
|
|
2297
2408
|
}
|
|
2298
|
-
__name(
|
|
2409
|
+
__name(_ts_param16, "_ts_param");
|
|
2299
2410
|
var DrizzleSubscriptionContractRepository = class {
|
|
2300
2411
|
static {
|
|
2301
2412
|
__name(this, "DrizzleSubscriptionContractRepository");
|
|
@@ -2305,34 +2416,34 @@ var DrizzleSubscriptionContractRepository = class {
|
|
|
2305
2416
|
this.db = db;
|
|
2306
2417
|
}
|
|
2307
2418
|
async list(filter) {
|
|
2308
|
-
const rows = await this.db.select().from(subscriptionContracts).where((0,
|
|
2309
|
-
(0,
|
|
2419
|
+
const rows = await this.db.select().from(subscriptionContracts).where((0, import_drizzle_orm15.and)(...filter.tenantId ? [
|
|
2420
|
+
(0, import_drizzle_orm15.eq)(subscriptionContracts.tenantId, filter.tenantId)
|
|
2310
2421
|
] : [], ...filter.status ? [
|
|
2311
|
-
(0,
|
|
2422
|
+
(0, import_drizzle_orm15.eq)(subscriptionContracts.status, filter.status)
|
|
2312
2423
|
] : [], ...filter.asOf ? [
|
|
2313
2424
|
inWindowAt(filter.asOf)
|
|
2314
|
-
] : [])).orderBy((0,
|
|
2425
|
+
] : [])).orderBy((0, import_drizzle_orm15.desc)(subscriptionContracts.effectiveFrom), (0, import_drizzle_orm15.desc)(subscriptionContracts.createdAt));
|
|
2315
2426
|
return this.withLineItems(this.db, rows);
|
|
2316
2427
|
}
|
|
2317
2428
|
async findById(contractId) {
|
|
2318
|
-
const rows = await this.db.select().from(subscriptionContracts).where((0,
|
|
2429
|
+
const rows = await this.db.select().from(subscriptionContracts).where((0, import_drizzle_orm15.eq)(subscriptionContracts.id, contractId)).limit(1);
|
|
2319
2430
|
return (await this.withLineItems(this.db, rows))[0] ?? null;
|
|
2320
2431
|
}
|
|
2321
2432
|
async findActiveByTenantId(tenantId, asOf = /* @__PURE__ */ new Date(), tx) {
|
|
2322
2433
|
const db = resolveDb(this.db, tx);
|
|
2323
|
-
const rows = await db.select().from(subscriptionContracts).where((0,
|
|
2324
|
-
...
|
|
2325
|
-
]), inWindowAt(asOf))).orderBy((0,
|
|
2434
|
+
const rows = await db.select().from(subscriptionContracts).where((0, import_drizzle_orm15.and)((0, import_drizzle_orm15.eq)(subscriptionContracts.tenantId, tenantId), (0, import_drizzle_orm15.inArray)(subscriptionContracts.status, [
|
|
2435
|
+
...import_core6.ACTIVE_SUBSCRIPTION_CONTRACT_STATUSES
|
|
2436
|
+
]), inWindowAt(asOf))).orderBy((0, import_drizzle_orm15.desc)(subscriptionContracts.effectiveFrom), (0, import_drizzle_orm15.desc)(subscriptionContracts.createdAt)).limit(1);
|
|
2326
2437
|
return (await this.withLineItems(db, rows))[0] ?? null;
|
|
2327
2438
|
}
|
|
2328
2439
|
async findByOriginalOfferId(offerId, tx) {
|
|
2329
2440
|
const db = resolveDb(this.db, tx);
|
|
2330
|
-
const rows = await db.select().from(subscriptionContracts).where((0,
|
|
2441
|
+
const rows = await db.select().from(subscriptionContracts).where((0, import_drizzle_orm15.eq)(subscriptionContracts.originalOfferId, offerId)).orderBy((0, import_drizzle_orm15.asc)(subscriptionContracts.createdAt), (0, import_drizzle_orm15.asc)(subscriptionContracts.id)).limit(1);
|
|
2331
2442
|
return (await this.withLineItems(db, rows))[0] ?? null;
|
|
2332
2443
|
}
|
|
2333
2444
|
async create(data, tx) {
|
|
2334
2445
|
const now = /* @__PURE__ */ new Date();
|
|
2335
|
-
const contractId = (0,
|
|
2446
|
+
const contractId = (0, import_node_crypto11.randomUUID)();
|
|
2336
2447
|
return resolveDb(this.db, tx).transaction(async (transaction) => {
|
|
2337
2448
|
const db = transaction;
|
|
2338
2449
|
const rows = await db.insert(subscriptionContracts).values({
|
|
@@ -2352,20 +2463,21 @@ var DrizzleSubscriptionContractRepository = class {
|
|
|
2352
2463
|
subscriberId: data.parties.subscriberId,
|
|
2353
2464
|
subscriberSnapshot: data.parties.subscriber,
|
|
2354
2465
|
issuerSnapshot: data.parties.issuer,
|
|
2466
|
+
partiesMigrated: data.partiesMigrated ?? false,
|
|
2355
2467
|
createdAt: now,
|
|
2356
2468
|
updatedAt: now
|
|
2357
2469
|
}).returning();
|
|
2358
2470
|
const lineRows = data.lineItems.length === 0 ? [] : await db.insert(contractLineItems).values(data.lineItems.map((item) => toLineItemInsert(item, contractId, now))).returning();
|
|
2359
|
-
return (0,
|
|
2471
|
+
return (0, import_core6.toSubscriptionContractRecord)(rows[0], lineRows);
|
|
2360
2472
|
});
|
|
2361
2473
|
}
|
|
2362
2474
|
async listRunningIssuers(limit, asOf = /* @__PURE__ */ new Date()) {
|
|
2363
|
-
const running = (0,
|
|
2364
|
-
...
|
|
2365
|
-
]), (0,
|
|
2475
|
+
const running = (0, import_drizzle_orm15.and)((0, import_drizzle_orm15.inArray)(subscriptionContracts.status, [
|
|
2476
|
+
...import_core6.ACTIVE_SUBSCRIPTION_CONTRACT_STATUSES
|
|
2477
|
+
]), (0, import_drizzle_orm15.or)((0, import_drizzle_orm15.isNull)(subscriptionContracts.effectiveUntil), (0, import_drizzle_orm15.gt)(subscriptionContracts.effectiveUntil, asOf)));
|
|
2366
2478
|
const [totals, rows] = await Promise.all([
|
|
2367
2479
|
this.db.select({
|
|
2368
|
-
value: (0,
|
|
2480
|
+
value: (0, import_drizzle_orm15.count)()
|
|
2369
2481
|
}).from(subscriptionContracts).where(running),
|
|
2370
2482
|
// Oldest first, and `id` last so two contracts that start in the
|
|
2371
2483
|
// same moment are still listed in one order — a refusal that names
|
|
@@ -2376,11 +2488,11 @@ var DrizzleSubscriptionContractRepository = class {
|
|
|
2376
2488
|
tenantId: subscriptionContracts.tenantId,
|
|
2377
2489
|
issuerSnapshot: subscriptionContracts.issuerSnapshot,
|
|
2378
2490
|
effectiveFrom: subscriptionContracts.effectiveFrom
|
|
2379
|
-
}).from(subscriptionContracts).where(running).orderBy((0,
|
|
2491
|
+
}).from(subscriptionContracts).where(running).orderBy((0, import_drizzle_orm15.asc)(subscriptionContracts.effectiveFrom), (0, import_drizzle_orm15.asc)(subscriptionContracts.createdAt), (0, import_drizzle_orm15.asc)(subscriptionContracts.id)).limit(limit)
|
|
2380
2492
|
]);
|
|
2381
2493
|
return {
|
|
2382
2494
|
total: totals[0]?.value ?? 0,
|
|
2383
|
-
contracts: rows.map(
|
|
2495
|
+
contracts: rows.map(import_core6.toRunningContractIssuer)
|
|
2384
2496
|
};
|
|
2385
2497
|
}
|
|
2386
2498
|
async terminate(contractId, data) {
|
|
@@ -2394,10 +2506,22 @@ var DrizzleSubscriptionContractRepository = class {
|
|
|
2394
2506
|
status: data.status
|
|
2395
2507
|
},
|
|
2396
2508
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2397
|
-
}).where((0,
|
|
2509
|
+
}).where((0, import_drizzle_orm15.eq)(subscriptionContracts.id, contractId)).returning();
|
|
2398
2510
|
if (!rows[0]) throw new Error(`SubscriptionContract '${contractId}' not found.`);
|
|
2399
2511
|
return (await this.withLineItems(this.db, rows))[0];
|
|
2400
2512
|
}
|
|
2513
|
+
async supersede(contractId, data, tx) {
|
|
2514
|
+
const db = resolveDb(this.db, tx);
|
|
2515
|
+
const rows = await db.update(subscriptionContracts).set({
|
|
2516
|
+
effectiveUntil: data.at,
|
|
2517
|
+
status: "superseded",
|
|
2518
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
2519
|
+
}).where((0, import_drizzle_orm15.and)((0, import_drizzle_orm15.eq)(subscriptionContracts.id, contractId), (0, import_drizzle_orm15.inArray)(subscriptionContracts.status, [
|
|
2520
|
+
...import_core6.ACTIVE_SUBSCRIPTION_CONTRACT_STATUSES
|
|
2521
|
+
]), data.readEffectiveUntil === null ? (0, import_drizzle_orm15.isNull)(subscriptionContracts.effectiveUntil) : (0, import_drizzle_orm15.eq)(subscriptionContracts.effectiveUntil, data.readEffectiveUntil))).returning();
|
|
2522
|
+
if (!rows[0]) return null;
|
|
2523
|
+
return (await this.withLineItems(db, rows))[0];
|
|
2524
|
+
}
|
|
2401
2525
|
/**
|
|
2402
2526
|
* The lines for a batch of contracts in one query rather than one per
|
|
2403
2527
|
* contract: `list` is the operator's contract history and would otherwise
|
|
@@ -2405,7 +2529,7 @@ var DrizzleSubscriptionContractRepository = class {
|
|
|
2405
2529
|
*/
|
|
2406
2530
|
async withLineItems(db, rows) {
|
|
2407
2531
|
if (rows.length === 0) return [];
|
|
2408
|
-
const lines = await db.select().from(contractLineItems).where((0,
|
|
2532
|
+
const lines = await db.select().from(contractLineItems).where((0, import_drizzle_orm15.inArray)(contractLineItems.contractId, rows.map((row) => row.id)));
|
|
2409
2533
|
const byContract = /* @__PURE__ */ new Map();
|
|
2410
2534
|
for (const line of lines) {
|
|
2411
2535
|
const bucket = byContract.get(line.contractId);
|
|
@@ -2414,24 +2538,24 @@ var DrizzleSubscriptionContractRepository = class {
|
|
|
2414
2538
|
line
|
|
2415
2539
|
]);
|
|
2416
2540
|
}
|
|
2417
|
-
return rows.map((row) => (0,
|
|
2541
|
+
return rows.map((row) => (0, import_core6.toSubscriptionContractRecord)(row, byContract.get(row.id) ?? []));
|
|
2418
2542
|
}
|
|
2419
2543
|
};
|
|
2420
|
-
DrizzleSubscriptionContractRepository =
|
|
2421
|
-
(0,
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2544
|
+
DrizzleSubscriptionContractRepository = _ts_decorate17([
|
|
2545
|
+
(0, import_common17.Injectable)(),
|
|
2546
|
+
_ts_param16(0, (0, import_common17.Inject)(DRIZZLE_DB_TOKEN)),
|
|
2547
|
+
_ts_metadata16("design:type", Function),
|
|
2548
|
+
_ts_metadata16("design:paramtypes", [
|
|
2425
2549
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
2426
2550
|
])
|
|
2427
2551
|
], DrizzleSubscriptionContractRepository);
|
|
2428
2552
|
function inWindowAt(asOf) {
|
|
2429
|
-
return (0,
|
|
2553
|
+
return (0, import_drizzle_orm15.and)((0, import_drizzle_orm15.lte)(subscriptionContracts.effectiveFrom, asOf), (0, import_drizzle_orm15.or)((0, import_drizzle_orm15.isNull)(subscriptionContracts.effectiveUntil), (0, import_drizzle_orm15.gt)(subscriptionContracts.effectiveUntil, asOf)));
|
|
2430
2554
|
}
|
|
2431
2555
|
__name(inWindowAt, "inWindowAt");
|
|
2432
2556
|
function toLineItemInsert(item, contractId, createdAt) {
|
|
2433
2557
|
return {
|
|
2434
|
-
id: (0,
|
|
2558
|
+
id: (0, import_node_crypto11.randomUUID)(),
|
|
2435
2559
|
contractId,
|
|
2436
2560
|
kind: item.kind,
|
|
2437
2561
|
sourceKey: item.sourceKey,
|
|
@@ -2458,28 +2582,93 @@ function toLineItemInsert(item, contractId, createdAt) {
|
|
|
2458
2582
|
}
|
|
2459
2583
|
__name(toLineItemInsert, "toLineItemInsert");
|
|
2460
2584
|
|
|
2585
|
+
// src/drizzle-subscriber-ledger.repository.ts
|
|
2586
|
+
var import_node_crypto12 = require("node:crypto");
|
|
2587
|
+
var import_common18 = require("@nestjs/common");
|
|
2588
|
+
var import_drizzle_orm16 = require("drizzle-orm");
|
|
2589
|
+
var import_core7 = require("@saasicat/core");
|
|
2590
|
+
function _ts_decorate18(decorators, target, key, desc11) {
|
|
2591
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
2592
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
2593
|
+
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;
|
|
2594
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2595
|
+
}
|
|
2596
|
+
__name(_ts_decorate18, "_ts_decorate");
|
|
2597
|
+
function _ts_metadata17(k, v) {
|
|
2598
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2599
|
+
}
|
|
2600
|
+
__name(_ts_metadata17, "_ts_metadata");
|
|
2601
|
+
function _ts_param17(paramIndex, decorator) {
|
|
2602
|
+
return function(target, key) {
|
|
2603
|
+
decorator(target, key, paramIndex);
|
|
2604
|
+
};
|
|
2605
|
+
}
|
|
2606
|
+
__name(_ts_param17, "_ts_param");
|
|
2607
|
+
var DrizzleSubscriberLedgerRepository = class {
|
|
2608
|
+
static {
|
|
2609
|
+
__name(this, "DrizzleSubscriberLedgerRepository");
|
|
2610
|
+
}
|
|
2611
|
+
db;
|
|
2612
|
+
constructor(db) {
|
|
2613
|
+
this.db = db;
|
|
2614
|
+
}
|
|
2615
|
+
/**
|
|
2616
|
+
* One statement, `ON CONFLICT DO NOTHING` on the natural key: a charge
|
|
2617
|
+
* another caller wrote first — committed or still in flight — is waited for
|
|
2618
|
+
* and skipped rather than raised, and only what this call wrote comes back.
|
|
2619
|
+
*/
|
|
2620
|
+
async recordCharges(charges, tx) {
|
|
2621
|
+
if (charges.length === 0) return [];
|
|
2622
|
+
const rows = await resolveDb(this.db, tx).insert(subscriberLedgerEntries).values(charges.map((charge) => ({
|
|
2623
|
+
id: (0, import_node_crypto12.randomUUID)(),
|
|
2624
|
+
...(0, import_core7.subscriberChargeColumns)(charge)
|
|
2625
|
+
}))).onConflictDoNothing({
|
|
2626
|
+
target: [
|
|
2627
|
+
subscriberLedgerEntries.subscriptionId,
|
|
2628
|
+
subscriberLedgerEntries.source,
|
|
2629
|
+
subscriberLedgerEntries.sourceRef,
|
|
2630
|
+
subscriberLedgerEntries.periodStart,
|
|
2631
|
+
subscriberLedgerEntries.origin
|
|
2632
|
+
]
|
|
2633
|
+
}).returning();
|
|
2634
|
+
return rows.map(import_core7.toSubscriberChargeRecord);
|
|
2635
|
+
}
|
|
2636
|
+
async listBySubscription(subscriptionId, tx) {
|
|
2637
|
+
const rows = await resolveDb(this.db, tx).select().from(subscriberLedgerEntries).where((0, import_drizzle_orm16.eq)(subscriberLedgerEntries.subscriptionId, subscriptionId)).orderBy((0, import_drizzle_orm16.asc)(subscriberLedgerEntries.periodStart), (0, import_drizzle_orm16.asc)(subscriberLedgerEntries.source), (0, import_drizzle_orm16.asc)(subscriberLedgerEntries.sourceRef), (0, import_drizzle_orm16.asc)(subscriberLedgerEntries.origin));
|
|
2638
|
+
return rows.map(import_core7.toSubscriberChargeRecord);
|
|
2639
|
+
}
|
|
2640
|
+
};
|
|
2641
|
+
DrizzleSubscriberLedgerRepository = _ts_decorate18([
|
|
2642
|
+
(0, import_common18.Injectable)(),
|
|
2643
|
+
_ts_param17(0, (0, import_common18.Inject)(DRIZZLE_DB_TOKEN)),
|
|
2644
|
+
_ts_metadata17("design:type", Function),
|
|
2645
|
+
_ts_metadata17("design:paramtypes", [
|
|
2646
|
+
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
2647
|
+
])
|
|
2648
|
+
], DrizzleSubscriberLedgerRepository);
|
|
2649
|
+
|
|
2461
2650
|
// src/drizzle-subscriber-payment-method.repository.ts
|
|
2462
|
-
var
|
|
2463
|
-
var
|
|
2464
|
-
var
|
|
2465
|
-
var
|
|
2466
|
-
function
|
|
2467
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2468
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
2651
|
+
var import_node_crypto13 = require("node:crypto");
|
|
2652
|
+
var import_common19 = require("@nestjs/common");
|
|
2653
|
+
var import_drizzle_orm17 = require("drizzle-orm");
|
|
2654
|
+
var import_core8 = require("@saasicat/core");
|
|
2655
|
+
function _ts_decorate19(decorators, target, key, desc11) {
|
|
2656
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
2657
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
2469
2658
|
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;
|
|
2470
2659
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2471
2660
|
}
|
|
2472
|
-
__name(
|
|
2473
|
-
function
|
|
2661
|
+
__name(_ts_decorate19, "_ts_decorate");
|
|
2662
|
+
function _ts_metadata18(k, v) {
|
|
2474
2663
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2475
2664
|
}
|
|
2476
|
-
__name(
|
|
2477
|
-
function
|
|
2665
|
+
__name(_ts_metadata18, "_ts_metadata");
|
|
2666
|
+
function _ts_param18(paramIndex, decorator) {
|
|
2478
2667
|
return function(target, key) {
|
|
2479
2668
|
decorator(target, key, paramIndex);
|
|
2480
2669
|
};
|
|
2481
2670
|
}
|
|
2482
|
-
__name(
|
|
2671
|
+
__name(_ts_param18, "_ts_param");
|
|
2483
2672
|
var DrizzleSubscriberPaymentMethodRepository = class {
|
|
2484
2673
|
static {
|
|
2485
2674
|
__name(this, "DrizzleSubscriberPaymentMethodRepository");
|
|
@@ -2493,29 +2682,29 @@ var DrizzleSubscriberPaymentMethodRepository = class {
|
|
|
2493
2682
|
const db = transaction;
|
|
2494
2683
|
const locked = await db.select({
|
|
2495
2684
|
id: subscribers.id
|
|
2496
|
-
}).from(subscribers).where((0,
|
|
2685
|
+
}).from(subscribers).where((0, import_drizzle_orm17.eq)(subscribers.id, data.subscriberId)).for("update").limit(1);
|
|
2497
2686
|
if (locked.length === 0) {
|
|
2498
2687
|
throw new Error(`Subscriber '${data.subscriberId}' does not exist; its payment method cannot be recorded.`);
|
|
2499
2688
|
}
|
|
2500
2689
|
const [recorded] = await db.select().from(subscriberPaymentMethods).where(this.byReference(data.gatewayAccount, data.paymentMethodRef)).limit(1);
|
|
2501
2690
|
if (recorded) {
|
|
2502
|
-
(0,
|
|
2691
|
+
(0, import_core8.refuseForeignPaymentMethodReference)(recorded, data.subscriberId);
|
|
2503
2692
|
return {
|
|
2504
|
-
method: (0,
|
|
2693
|
+
method: (0, import_core8.toSubscriberPaymentMethodRecord)(recorded),
|
|
2505
2694
|
outcome: "already-recorded"
|
|
2506
2695
|
};
|
|
2507
2696
|
}
|
|
2508
2697
|
const [active] = await db.select().from(subscriberPaymentMethods).where(this.activeOf(data.subscriberId)).limit(1);
|
|
2509
2698
|
const replacedOnArrival = active && active.confirmedAt.getTime() > data.confirmedAt.getTime() ? active.confirmedAt : null;
|
|
2510
2699
|
const claimed = await this.claimReference(db, {
|
|
2511
|
-
...(0,
|
|
2512
|
-
id: (0,
|
|
2700
|
+
...(0, import_core8.subscriberPaymentMethodColumns)(data),
|
|
2701
|
+
id: (0, import_node_crypto13.randomUUID)(),
|
|
2513
2702
|
status: "REPLACED",
|
|
2514
2703
|
replacedAt: replacedOnArrival ?? data.confirmedAt
|
|
2515
2704
|
});
|
|
2516
2705
|
if (replacedOnArrival) {
|
|
2517
2706
|
return {
|
|
2518
|
-
method: (0,
|
|
2707
|
+
method: (0, import_core8.toSubscriberPaymentMethodRecord)(claimed),
|
|
2519
2708
|
outcome: "superseded"
|
|
2520
2709
|
};
|
|
2521
2710
|
}
|
|
@@ -2523,14 +2712,14 @@ var DrizzleSubscriberPaymentMethodRepository = class {
|
|
|
2523
2712
|
await db.update(subscriberPaymentMethods).set({
|
|
2524
2713
|
status: "REPLACED",
|
|
2525
2714
|
replacedAt: data.confirmedAt
|
|
2526
|
-
}).where((0,
|
|
2715
|
+
}).where((0, import_drizzle_orm17.eq)(subscriberPaymentMethods.id, active.id));
|
|
2527
2716
|
}
|
|
2528
2717
|
const [inUse] = await db.update(subscriberPaymentMethods).set({
|
|
2529
2718
|
status: "ACTIVE",
|
|
2530
2719
|
replacedAt: null
|
|
2531
|
-
}).where((0,
|
|
2720
|
+
}).where((0, import_drizzle_orm17.eq)(subscriberPaymentMethods.id, claimed.id)).returning();
|
|
2532
2721
|
return {
|
|
2533
|
-
method: (0,
|
|
2722
|
+
method: (0, import_core8.toSubscriberPaymentMethodRecord)(inUse),
|
|
2534
2723
|
outcome: "activated"
|
|
2535
2724
|
};
|
|
2536
2725
|
});
|
|
@@ -2558,27 +2747,27 @@ var DrizzleSubscriberPaymentMethodRepository = class {
|
|
|
2558
2747
|
]
|
|
2559
2748
|
}).returning();
|
|
2560
2749
|
if (!claimed) {
|
|
2561
|
-
throw new
|
|
2750
|
+
throw new import_core8.ForeignPaymentMethodReferenceError(values.gatewayAccount, values.paymentMethodRef);
|
|
2562
2751
|
}
|
|
2563
2752
|
return claimed;
|
|
2564
2753
|
}
|
|
2565
2754
|
async findActive(subscriberId, tx) {
|
|
2566
2755
|
const [row] = await resolveDb(this.db, tx).select().from(subscriberPaymentMethods).where(this.activeOf(subscriberId)).limit(1);
|
|
2567
|
-
return row ? (0,
|
|
2756
|
+
return row ? (0, import_core8.toSubscriberPaymentMethodRecord)(row) : null;
|
|
2568
2757
|
}
|
|
2569
2758
|
async findByReference(reference, tx) {
|
|
2570
|
-
const [row] = await resolveDb(this.db, tx).select().from(subscriberPaymentMethods).where((0,
|
|
2571
|
-
return row ? (0,
|
|
2759
|
+
const [row] = await resolveDb(this.db, tx).select().from(subscriberPaymentMethods).where((0, import_drizzle_orm17.and)((0, import_drizzle_orm17.eq)(subscriberPaymentMethods.subscriberId, reference.subscriberId), this.byReference(reference.gatewayAccount, reference.paymentMethodRef))).limit(1);
|
|
2760
|
+
return row ? (0, import_core8.toSubscriberPaymentMethodRecord)(row) : null;
|
|
2572
2761
|
}
|
|
2573
2762
|
async accountsInUse() {
|
|
2574
2763
|
const rows = await this.db.selectDistinct({
|
|
2575
2764
|
gatewayAccount: subscriberPaymentMethods.gatewayAccount
|
|
2576
|
-
}).from(subscriberPaymentMethods).where((0,
|
|
2765
|
+
}).from(subscriberPaymentMethods).where((0, import_drizzle_orm17.eq)(subscriberPaymentMethods.status, "ACTIVE")).orderBy((0, import_drizzle_orm17.asc)(subscriberPaymentMethods.gatewayAccount));
|
|
2577
2766
|
return rows.map((row) => row.gatewayAccount);
|
|
2578
2767
|
}
|
|
2579
2768
|
async recordSetup(data, tx) {
|
|
2580
2769
|
await resolveDb(this.db, tx).insert(subscriberPaymentMethodSetups).values({
|
|
2581
|
-
id: (0,
|
|
2770
|
+
id: (0, import_node_crypto13.randomUUID)(),
|
|
2582
2771
|
subscriberId: data.subscriberId,
|
|
2583
2772
|
gatewayAccount: data.gatewayAccount,
|
|
2584
2773
|
sessionRef: data.sessionRef,
|
|
@@ -2589,49 +2778,49 @@ var DrizzleSubscriberPaymentMethodRepository = class {
|
|
|
2589
2778
|
async completeSetup(match, completedAt, tx) {
|
|
2590
2779
|
const completed = await resolveDb(this.db, tx).update(subscriberPaymentMethodSetups).set({
|
|
2591
2780
|
completedAt
|
|
2592
|
-
}).where((0,
|
|
2781
|
+
}).where((0, import_drizzle_orm17.and)((0, import_drizzle_orm17.eq)(subscriberPaymentMethodSetups.gatewayAccount, match.gatewayAccount), (0, import_drizzle_orm17.eq)(subscriberPaymentMethodSetups.sessionRef, match.sessionRef), (0, import_drizzle_orm17.eq)(subscriberPaymentMethodSetups.subscriberId, match.subscriberId), (0, import_drizzle_orm17.isNull)(subscriberPaymentMethodSetups.completedAt))).returning({
|
|
2593
2782
|
id: subscriberPaymentMethodSetups.id
|
|
2594
2783
|
});
|
|
2595
2784
|
return completed.length === 1;
|
|
2596
2785
|
}
|
|
2597
2786
|
activeOf(subscriberId) {
|
|
2598
|
-
return (0,
|
|
2787
|
+
return (0, import_drizzle_orm17.and)((0, import_drizzle_orm17.eq)(subscriberPaymentMethods.subscriberId, subscriberId), (0, import_drizzle_orm17.eq)(subscriberPaymentMethods.status, "ACTIVE"));
|
|
2599
2788
|
}
|
|
2600
2789
|
byReference(gatewayAccount, paymentMethodRef) {
|
|
2601
|
-
return (0,
|
|
2790
|
+
return (0, import_drizzle_orm17.and)((0, import_drizzle_orm17.eq)(subscriberPaymentMethods.gatewayAccount, gatewayAccount), (0, import_drizzle_orm17.eq)(subscriberPaymentMethods.paymentMethodRef, paymentMethodRef));
|
|
2602
2791
|
}
|
|
2603
2792
|
};
|
|
2604
|
-
DrizzleSubscriberPaymentMethodRepository =
|
|
2605
|
-
(0,
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2793
|
+
DrizzleSubscriberPaymentMethodRepository = _ts_decorate19([
|
|
2794
|
+
(0, import_common19.Injectable)(),
|
|
2795
|
+
_ts_param18(0, (0, import_common19.Inject)(DRIZZLE_DB_TOKEN)),
|
|
2796
|
+
_ts_metadata18("design:type", Function),
|
|
2797
|
+
_ts_metadata18("design:paramtypes", [
|
|
2609
2798
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
2610
2799
|
])
|
|
2611
2800
|
], DrizzleSubscriberPaymentMethodRepository);
|
|
2612
2801
|
|
|
2613
2802
|
// src/drizzle-subscriber.repository.ts
|
|
2614
|
-
var
|
|
2615
|
-
var
|
|
2616
|
-
var
|
|
2617
|
-
var
|
|
2618
|
-
function
|
|
2619
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2620
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
2803
|
+
var import_node_crypto14 = require("node:crypto");
|
|
2804
|
+
var import_common20 = require("@nestjs/common");
|
|
2805
|
+
var import_drizzle_orm18 = require("drizzle-orm");
|
|
2806
|
+
var import_core9 = require("@saasicat/core");
|
|
2807
|
+
function _ts_decorate20(decorators, target, key, desc11) {
|
|
2808
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
2809
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
2621
2810
|
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;
|
|
2622
2811
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2623
2812
|
}
|
|
2624
|
-
__name(
|
|
2625
|
-
function
|
|
2813
|
+
__name(_ts_decorate20, "_ts_decorate");
|
|
2814
|
+
function _ts_metadata19(k, v) {
|
|
2626
2815
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2627
2816
|
}
|
|
2628
|
-
__name(
|
|
2629
|
-
function
|
|
2817
|
+
__name(_ts_metadata19, "_ts_metadata");
|
|
2818
|
+
function _ts_param19(paramIndex, decorator) {
|
|
2630
2819
|
return function(target, key) {
|
|
2631
2820
|
decorator(target, key, paramIndex);
|
|
2632
2821
|
};
|
|
2633
2822
|
}
|
|
2634
|
-
__name(
|
|
2823
|
+
__name(_ts_param19, "_ts_param");
|
|
2635
2824
|
var DrizzleSubscriberRepository = class {
|
|
2636
2825
|
static {
|
|
2637
2826
|
__name(this, "DrizzleSubscriberRepository");
|
|
@@ -2643,7 +2832,7 @@ var DrizzleSubscriberRepository = class {
|
|
|
2643
2832
|
async createForTenant(data, tx) {
|
|
2644
2833
|
const { tenantId, ...details } = data;
|
|
2645
2834
|
const now = /* @__PURE__ */ new Date();
|
|
2646
|
-
const subscriberId = (0,
|
|
2835
|
+
const subscriberId = (0, import_node_crypto14.randomUUID)();
|
|
2647
2836
|
return resolveDb(this.db, tx).transaction(async (transaction) => {
|
|
2648
2837
|
const db = transaction;
|
|
2649
2838
|
const [created] = await db.insert(subscribers).values({
|
|
@@ -2653,44 +2842,44 @@ var DrizzleSubscriberRepository = class {
|
|
|
2653
2842
|
updatedAt: now
|
|
2654
2843
|
}).returning();
|
|
2655
2844
|
const linked = await db.insert(subscriberTenants).values({
|
|
2656
|
-
id: (0,
|
|
2845
|
+
id: (0, import_node_crypto14.randomUUID)(),
|
|
2657
2846
|
subscriberId,
|
|
2658
2847
|
tenantId,
|
|
2659
2848
|
linkedAt: now
|
|
2660
2849
|
}).onConflictDoNothing().returning();
|
|
2661
2850
|
if (linked.length === 0) {
|
|
2662
|
-
await db.delete(subscribers).where((0,
|
|
2851
|
+
await db.delete(subscribers).where((0, import_drizzle_orm18.eq)(subscribers.id, subscriberId));
|
|
2663
2852
|
return null;
|
|
2664
2853
|
}
|
|
2665
|
-
return (0,
|
|
2854
|
+
return (0, import_core9.toSubscriberRecord)(created, tenantId);
|
|
2666
2855
|
});
|
|
2667
2856
|
}
|
|
2668
2857
|
async findById(subscriberId, tx) {
|
|
2669
2858
|
const db = resolveDb(this.db, tx);
|
|
2670
|
-
const rows = await db.select().from(subscribers).where((0,
|
|
2859
|
+
const rows = await db.select().from(subscribers).where((0, import_drizzle_orm18.eq)(subscribers.id, subscriberId)).limit(1);
|
|
2671
2860
|
return rows[0] ? this.withLiveTenant(db, rows[0]) : null;
|
|
2672
2861
|
}
|
|
2673
2862
|
async findByTenantId(tenantId, tx) {
|
|
2674
2863
|
const db = resolveDb(this.db, tx);
|
|
2675
2864
|
const rows = await db.select({
|
|
2676
2865
|
subscriber: subscribers
|
|
2677
|
-
}).from(subscriberTenants).innerJoin(subscribers, (0,
|
|
2678
|
-
return rows[0] ? (0,
|
|
2866
|
+
}).from(subscriberTenants).innerJoin(subscribers, (0, import_drizzle_orm18.eq)(subscribers.id, subscriberTenants.subscriberId)).where((0, import_drizzle_orm18.and)((0, import_drizzle_orm18.eq)(subscriberTenants.tenantId, tenantId), (0, import_drizzle_orm18.isNull)(subscriberTenants.unlinkedAt))).limit(1);
|
|
2867
|
+
return rows[0] ? (0, import_core9.toSubscriberRecord)(rows[0].subscriber, tenantId) : null;
|
|
2679
2868
|
}
|
|
2680
2869
|
async updateContact(subscriberId, change, tx) {
|
|
2681
2870
|
const db = resolveDb(this.db, tx);
|
|
2682
2871
|
const rows = await db.update(subscribers).set({
|
|
2683
2872
|
...change,
|
|
2684
2873
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2685
|
-
}).where((0,
|
|
2874
|
+
}).where((0, import_drizzle_orm18.eq)(subscribers.id, subscriberId)).returning();
|
|
2686
2875
|
return rows[0] ? this.withLiveTenant(db, rows[0]) : null;
|
|
2687
2876
|
}
|
|
2688
2877
|
async correctIdentity(subscriberId, data, tx) {
|
|
2689
2878
|
return resolveDb(this.db, tx).transaction(async (transaction) => {
|
|
2690
2879
|
const db = transaction;
|
|
2691
|
-
const [current] = await db.select().from(subscribers).where((0,
|
|
2880
|
+
const [current] = await db.select().from(subscribers).where((0, import_drizzle_orm18.eq)(subscribers.id, subscriberId)).for("update").limit(1);
|
|
2692
2881
|
if (!current) return null;
|
|
2693
|
-
const delta = (0,
|
|
2882
|
+
const delta = (0, import_core9.identityCorrectionDelta)(current, data.corrected);
|
|
2694
2883
|
if (Object.keys(delta.corrected).length === 0) {
|
|
2695
2884
|
return {
|
|
2696
2885
|
subscriber: await this.withLiveTenant(db, current),
|
|
@@ -2700,9 +2889,9 @@ var DrizzleSubscriberRepository = class {
|
|
|
2700
2889
|
const [updated] = await db.update(subscribers).set({
|
|
2701
2890
|
...delta.corrected,
|
|
2702
2891
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2703
|
-
}).where((0,
|
|
2892
|
+
}).where((0, import_drizzle_orm18.eq)(subscribers.id, subscriberId)).returning();
|
|
2704
2893
|
const [correction] = await db.insert(subscriberCorrections).values({
|
|
2705
|
-
id: (0,
|
|
2894
|
+
id: (0, import_node_crypto14.randomUUID)(),
|
|
2706
2895
|
subscriberId,
|
|
2707
2896
|
previous: delta.previous,
|
|
2708
2897
|
corrected: delta.corrected,
|
|
@@ -2712,50 +2901,50 @@ var DrizzleSubscriberRepository = class {
|
|
|
2712
2901
|
}).returning();
|
|
2713
2902
|
return {
|
|
2714
2903
|
subscriber: await this.withLiveTenant(db, updated),
|
|
2715
|
-
correction: (0,
|
|
2904
|
+
correction: (0, import_core9.toSubscriberCorrectionRecord)(correction)
|
|
2716
2905
|
};
|
|
2717
2906
|
});
|
|
2718
2907
|
}
|
|
2719
2908
|
async listCorrections(subscriberId) {
|
|
2720
|
-
const rows = await this.db.select().from(subscriberCorrections).where((0,
|
|
2721
|
-
return rows.map(
|
|
2909
|
+
const rows = await this.db.select().from(subscriberCorrections).where((0, import_drizzle_orm18.eq)(subscriberCorrections.subscriberId, subscriberId)).orderBy((0, import_drizzle_orm18.desc)(subscriberCorrections.correctedAt), (0, import_drizzle_orm18.desc)(subscriberCorrections.id));
|
|
2910
|
+
return rows.map(import_core9.toSubscriberCorrectionRecord);
|
|
2722
2911
|
}
|
|
2723
2912
|
async withLiveTenant(db, row) {
|
|
2724
2913
|
const links = await db.select({
|
|
2725
2914
|
tenantId: subscriberTenants.tenantId
|
|
2726
|
-
}).from(subscriberTenants).where((0,
|
|
2727
|
-
return (0,
|
|
2915
|
+
}).from(subscriberTenants).where((0, import_drizzle_orm18.and)((0, import_drizzle_orm18.eq)(subscriberTenants.subscriberId, row.id), (0, import_drizzle_orm18.isNull)(subscriberTenants.unlinkedAt))).limit(1);
|
|
2916
|
+
return (0, import_core9.toSubscriberRecord)(row, links[0]?.tenantId ?? null);
|
|
2728
2917
|
}
|
|
2729
2918
|
};
|
|
2730
|
-
DrizzleSubscriberRepository =
|
|
2731
|
-
(0,
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2919
|
+
DrizzleSubscriberRepository = _ts_decorate20([
|
|
2920
|
+
(0, import_common20.Injectable)(),
|
|
2921
|
+
_ts_param19(0, (0, import_common20.Inject)(DRIZZLE_DB_TOKEN)),
|
|
2922
|
+
_ts_metadata19("design:type", Function),
|
|
2923
|
+
_ts_metadata19("design:paramtypes", [
|
|
2735
2924
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
2736
2925
|
])
|
|
2737
2926
|
], DrizzleSubscriberRepository);
|
|
2738
2927
|
|
|
2739
2928
|
// src/drizzle-subscription-usage.adapter.ts
|
|
2740
|
-
var
|
|
2741
|
-
var
|
|
2742
|
-
function
|
|
2743
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2744
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
2929
|
+
var import_common21 = require("@nestjs/common");
|
|
2930
|
+
var import_drizzle_orm19 = require("drizzle-orm");
|
|
2931
|
+
function _ts_decorate21(decorators, target, key, desc11) {
|
|
2932
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
2933
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
2745
2934
|
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;
|
|
2746
2935
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2747
2936
|
}
|
|
2748
|
-
__name(
|
|
2749
|
-
function
|
|
2937
|
+
__name(_ts_decorate21, "_ts_decorate");
|
|
2938
|
+
function _ts_metadata20(k, v) {
|
|
2750
2939
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2751
2940
|
}
|
|
2752
|
-
__name(
|
|
2753
|
-
function
|
|
2941
|
+
__name(_ts_metadata20, "_ts_metadata");
|
|
2942
|
+
function _ts_param20(paramIndex, decorator) {
|
|
2754
2943
|
return function(target, key) {
|
|
2755
2944
|
decorator(target, key, paramIndex);
|
|
2756
2945
|
};
|
|
2757
2946
|
}
|
|
2758
|
-
__name(
|
|
2947
|
+
__name(_ts_param20, "_ts_param");
|
|
2759
2948
|
var DrizzleSubscriptionUsageAdapter = class {
|
|
2760
2949
|
static {
|
|
2761
2950
|
__name(this, "DrizzleSubscriptionUsageAdapter");
|
|
@@ -2765,13 +2954,13 @@ var DrizzleSubscriptionUsageAdapter = class {
|
|
|
2765
2954
|
this.db = db;
|
|
2766
2955
|
}
|
|
2767
2956
|
async findForTenant(tenantId) {
|
|
2768
|
-
const [subscription] = await this.db.select().from(subscriptions).where((0,
|
|
2957
|
+
const [subscription] = await this.db.select().from(subscriptions).where((0, import_drizzle_orm19.eq)(subscriptions.tenantId, tenantId)).limit(1);
|
|
2769
2958
|
if (!subscription) return null;
|
|
2770
|
-
const [planVersion] = await this.db.select().from(planVersions).where((0,
|
|
2959
|
+
const [planVersion] = await this.db.select().from(planVersions).where((0, import_drizzle_orm19.eq)(planVersions.id, subscription.planVersionId)).limit(1);
|
|
2771
2960
|
if (!planVersion) {
|
|
2772
2961
|
throw new Error(`Subscription ${subscription.id} references missing PlanVersion ${subscription.planVersionId}.`);
|
|
2773
2962
|
}
|
|
2774
|
-
const [pendingPlanVersion] = subscription.pendingPlanVersionId ? await this.db.select().from(planVersions).where((0,
|
|
2963
|
+
const [pendingPlanVersion] = subscription.pendingPlanVersionId ? await this.db.select().from(planVersions).where((0, import_drizzle_orm19.eq)(planVersions.id, subscription.pendingPlanVersionId)).limit(1) : [];
|
|
2775
2964
|
return {
|
|
2776
2965
|
id: subscription.id,
|
|
2777
2966
|
plan: planVersion.planId,
|
|
@@ -2806,11 +2995,11 @@ var DrizzleSubscriptionUsageAdapter = class {
|
|
|
2806
2995
|
};
|
|
2807
2996
|
}
|
|
2808
2997
|
};
|
|
2809
|
-
DrizzleSubscriptionUsageAdapter =
|
|
2810
|
-
(0,
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2998
|
+
DrizzleSubscriptionUsageAdapter = _ts_decorate21([
|
|
2999
|
+
(0, import_common21.Injectable)(),
|
|
3000
|
+
_ts_param20(0, (0, import_common21.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3001
|
+
_ts_metadata20("design:type", Function),
|
|
3002
|
+
_ts_metadata20("design:paramtypes", [
|
|
2814
3003
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
2815
3004
|
])
|
|
2816
3005
|
], DrizzleSubscriptionUsageAdapter);
|
|
@@ -2829,25 +3018,25 @@ function toUsagePlanVersion(row) {
|
|
|
2829
3018
|
__name(toUsagePlanVersion, "toUsagePlanVersion");
|
|
2830
3019
|
|
|
2831
3020
|
// src/drizzle-tenant-subscription-write.adapter.ts
|
|
2832
|
-
var
|
|
2833
|
-
var
|
|
2834
|
-
function
|
|
2835
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2836
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3021
|
+
var import_common22 = require("@nestjs/common");
|
|
3022
|
+
var import_drizzle_orm20 = require("drizzle-orm");
|
|
3023
|
+
function _ts_decorate22(decorators, target, key, desc11) {
|
|
3024
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3025
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
2837
3026
|
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;
|
|
2838
3027
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2839
3028
|
}
|
|
2840
|
-
__name(
|
|
2841
|
-
function
|
|
3029
|
+
__name(_ts_decorate22, "_ts_decorate");
|
|
3030
|
+
function _ts_metadata21(k, v) {
|
|
2842
3031
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2843
3032
|
}
|
|
2844
|
-
__name(
|
|
2845
|
-
function
|
|
3033
|
+
__name(_ts_metadata21, "_ts_metadata");
|
|
3034
|
+
function _ts_param21(paramIndex, decorator) {
|
|
2846
3035
|
return function(target, key) {
|
|
2847
3036
|
decorator(target, key, paramIndex);
|
|
2848
3037
|
};
|
|
2849
3038
|
}
|
|
2850
|
-
__name(
|
|
3039
|
+
__name(_ts_param21, "_ts_param");
|
|
2851
3040
|
var DrizzleTenantSubscriptionWrite = class {
|
|
2852
3041
|
static {
|
|
2853
3042
|
__name(this, "DrizzleTenantSubscriptionWrite");
|
|
@@ -2917,7 +3106,7 @@ var DrizzleTenantSubscriptionWrite = class {
|
|
|
2917
3106
|
pendingPlanVersionAcceptedAt: now,
|
|
2918
3107
|
pendingPlanVersionAcceptedByUserId: userId,
|
|
2919
3108
|
updatedAt: now
|
|
2920
|
-
}).where((0,
|
|
3109
|
+
}).where((0, import_drizzle_orm20.and)((0, import_drizzle_orm20.eq)(subscriptions.id, sub.id), (0, import_drizzle_orm20.eq)(subscriptions.pendingPlanVersionId, pendingPlanVersionId), (0, import_drizzle_orm20.eq)(subscriptions.pendingPlanVersionAccepted, false))).returning({
|
|
2921
3110
|
id: subscriptions.id
|
|
2922
3111
|
});
|
|
2923
3112
|
const updated = await this.requireSubscription(this.db, tenantId);
|
|
@@ -2953,7 +3142,7 @@ var DrizzleTenantSubscriptionWrite = class {
|
|
|
2953
3142
|
status: "CANCELED"
|
|
2954
3143
|
} : {},
|
|
2955
3144
|
updatedAt: now
|
|
2956
|
-
}).where((0,
|
|
3145
|
+
}).where((0, import_drizzle_orm20.and)((0, import_drizzle_orm20.eq)(subscriptions.tenantId, tenantId), (0, import_drizzle_orm20.isNull)(subscriptions.canceledAt), (0, import_drizzle_orm20.isNull)(subscriptions.canceledEffectiveAt))).returning({
|
|
2957
3146
|
id: subscriptions.id
|
|
2958
3147
|
});
|
|
2959
3148
|
const current = await this.requireSubscription(this.db, tenantId);
|
|
@@ -3013,7 +3202,7 @@ var DrizzleTenantSubscriptionWrite = class {
|
|
|
3013
3202
|
const claimed = await db.update(subscriptions).set({
|
|
3014
3203
|
...values,
|
|
3015
3204
|
updatedAt: /* @__PURE__ */ new Date()
|
|
3016
|
-
}).where((0,
|
|
3205
|
+
}).where((0, import_drizzle_orm20.and)((0, import_drizzle_orm20.eq)(subscriptions.tenantId, tenantId), canceledAtIs(expectedCanceledAt))).returning({
|
|
3017
3206
|
id: subscriptions.id
|
|
3018
3207
|
});
|
|
3019
3208
|
return claimed.length;
|
|
@@ -3025,7 +3214,7 @@ var DrizzleTenantSubscriptionWrite = class {
|
|
|
3025
3214
|
* released with the statement.
|
|
3026
3215
|
*/
|
|
3027
3216
|
async requireSubscription(db, tenantId, options = {}) {
|
|
3028
|
-
const query = db.select().from(subscriptions).where((0,
|
|
3217
|
+
const query = db.select().from(subscriptions).where((0, import_drizzle_orm20.eq)(subscriptions.tenantId, tenantId));
|
|
3029
3218
|
const rows = await (options.lock ? query.for("update") : query).limit(1);
|
|
3030
3219
|
if (!rows[0]) throw new Error(`No subscription for tenant ${tenantId}.`);
|
|
3031
3220
|
return rows[0];
|
|
@@ -3047,11 +3236,11 @@ var DrizzleTenantSubscriptionWrite = class {
|
|
|
3047
3236
|
return !pending || pending.planId !== targetPlanKey;
|
|
3048
3237
|
}
|
|
3049
3238
|
};
|
|
3050
|
-
DrizzleTenantSubscriptionWrite =
|
|
3051
|
-
(0,
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3239
|
+
DrizzleTenantSubscriptionWrite = _ts_decorate22([
|
|
3240
|
+
(0, import_common22.Injectable)(),
|
|
3241
|
+
_ts_param21(0, (0, import_common22.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3242
|
+
_ts_metadata21("design:type", Function),
|
|
3243
|
+
_ts_metadata21("design:paramtypes", [
|
|
3055
3244
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
3056
3245
|
])
|
|
3057
3246
|
], DrizzleTenantSubscriptionWrite);
|
|
@@ -3077,31 +3266,32 @@ function clearedPendingVersion() {
|
|
|
3077
3266
|
}
|
|
3078
3267
|
__name(clearedPendingVersion, "clearedPendingVersion");
|
|
3079
3268
|
function canceledAtIs(expected) {
|
|
3080
|
-
return expected === null ? (0,
|
|
3269
|
+
return expected === null ? (0, import_drizzle_orm20.isNull)(subscriptions.canceledAt) : (0, import_drizzle_orm20.eq)(subscriptions.canceledAt, expected);
|
|
3081
3270
|
}
|
|
3082
3271
|
__name(canceledAtIs, "canceledAtIs");
|
|
3083
3272
|
|
|
3084
3273
|
// src/drizzle-subscription-bundle.repository.ts
|
|
3085
|
-
var
|
|
3086
|
-
var
|
|
3087
|
-
var
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3274
|
+
var import_node_crypto15 = require("node:crypto");
|
|
3275
|
+
var import_common23 = require("@nestjs/common");
|
|
3276
|
+
var import_drizzle_orm21 = require("drizzle-orm");
|
|
3277
|
+
var import_core10 = require("@saasicat/core");
|
|
3278
|
+
function _ts_decorate23(decorators, target, key, desc11) {
|
|
3279
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3280
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
3091
3281
|
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;
|
|
3092
3282
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3093
3283
|
}
|
|
3094
|
-
__name(
|
|
3095
|
-
function
|
|
3284
|
+
__name(_ts_decorate23, "_ts_decorate");
|
|
3285
|
+
function _ts_metadata22(k, v) {
|
|
3096
3286
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3097
3287
|
}
|
|
3098
|
-
__name(
|
|
3099
|
-
function
|
|
3288
|
+
__name(_ts_metadata22, "_ts_metadata");
|
|
3289
|
+
function _ts_param22(paramIndex, decorator) {
|
|
3100
3290
|
return function(target, key) {
|
|
3101
3291
|
decorator(target, key, paramIndex);
|
|
3102
3292
|
};
|
|
3103
3293
|
}
|
|
3104
|
-
__name(
|
|
3294
|
+
__name(_ts_param22, "_ts_param");
|
|
3105
3295
|
var DrizzleSubscriptionBundleRepository = class {
|
|
3106
3296
|
static {
|
|
3107
3297
|
__name(this, "DrizzleSubscriptionBundleRepository");
|
|
@@ -3111,21 +3301,21 @@ var DrizzleSubscriptionBundleRepository = class {
|
|
|
3111
3301
|
this.db = db;
|
|
3112
3302
|
}
|
|
3113
3303
|
async listBySubscription(subscriptionId) {
|
|
3114
|
-
const rows = await this.db.select().from(subscriptionBundles).where((0,
|
|
3115
|
-
return rows.map(
|
|
3304
|
+
const rows = await this.db.select().from(subscriptionBundles).where((0, import_drizzle_orm21.eq)(subscriptionBundles.subscriptionId, subscriptionId)).orderBy((0, import_drizzle_orm21.desc)(subscriptionBundles.startedAt));
|
|
3305
|
+
return rows.map(import_core10.toSubscriptionBundleRecord);
|
|
3116
3306
|
}
|
|
3117
3307
|
async findById(subscriptionBundleId) {
|
|
3118
|
-
const rows = await this.db.select().from(subscriptionBundles).where((0,
|
|
3119
|
-
return rows[0] ?
|
|
3308
|
+
const rows = await this.db.select().from(subscriptionBundles).where((0, import_drizzle_orm21.eq)(subscriptionBundles.id, subscriptionBundleId)).limit(1);
|
|
3309
|
+
return rows[0] ? (0, import_core10.toSubscriptionBundleRecord)(rows[0]) : null;
|
|
3120
3310
|
}
|
|
3121
3311
|
async listActiveBySubscription(subscriptionId, asOf = /* @__PURE__ */ new Date(), tx) {
|
|
3122
|
-
const rows = await resolveDb(this.db, tx).select().from(subscriptionBundles).where((0,
|
|
3123
|
-
return rows.map(
|
|
3312
|
+
const rows = await resolveDb(this.db, tx).select().from(subscriptionBundles).where((0, import_drizzle_orm21.and)((0, import_drizzle_orm21.eq)(subscriptionBundles.subscriptionId, subscriptionId), stillActive(asOf)));
|
|
3313
|
+
return rows.map(import_core10.toSubscriptionBundleRecord);
|
|
3124
3314
|
}
|
|
3125
3315
|
async add(data) {
|
|
3126
3316
|
const now = /* @__PURE__ */ new Date();
|
|
3127
3317
|
const rows = await this.db.insert(subscriptionBundles).values({
|
|
3128
|
-
id: (0,
|
|
3318
|
+
id: (0, import_node_crypto15.randomUUID)(),
|
|
3129
3319
|
subscriptionId: data.subscriptionId,
|
|
3130
3320
|
bundleVersionId: data.bundleVersionId,
|
|
3131
3321
|
startedAt: data.startedAt ?? now,
|
|
@@ -3137,86 +3327,69 @@ var DrizzleSubscriptionBundleRepository = class {
|
|
|
3137
3327
|
canceledEffectiveAt: null,
|
|
3138
3328
|
updatedAt: now
|
|
3139
3329
|
}).returning();
|
|
3140
|
-
return
|
|
3330
|
+
return (0, import_core10.toSubscriptionBundleRecord)(rows[0]);
|
|
3141
3331
|
}
|
|
3142
3332
|
async cancel(subscriptionBundleId, data) {
|
|
3143
3333
|
const rows = await this.db.update(subscriptionBundles).set({
|
|
3144
3334
|
canceledAt: data.canceledAt,
|
|
3145
3335
|
canceledEffectiveAt: data.canceledEffectiveAt,
|
|
3146
3336
|
updatedAt: /* @__PURE__ */ new Date()
|
|
3147
|
-
}).where((0,
|
|
3337
|
+
}).where((0, import_drizzle_orm21.and)((0, import_drizzle_orm21.eq)(subscriptionBundles.id, subscriptionBundleId), (0, import_drizzle_orm21.isNull)(subscriptionBundles.canceledAt))).returning();
|
|
3148
3338
|
if (!rows[0]) {
|
|
3149
3339
|
throw new Error(`SubscriptionBundle '${subscriptionBundleId}' not found or already cancelled`);
|
|
3150
3340
|
}
|
|
3151
|
-
return
|
|
3341
|
+
return (0, import_core10.toSubscriptionBundleRecord)(rows[0]);
|
|
3152
3342
|
}
|
|
3153
3343
|
async reactivate(subscriptionBundleId) {
|
|
3154
3344
|
const rows = await this.db.update(subscriptionBundles).set({
|
|
3155
3345
|
canceledAt: null,
|
|
3156
3346
|
canceledEffectiveAt: null,
|
|
3157
3347
|
updatedAt: /* @__PURE__ */ new Date()
|
|
3158
|
-
}).where((0,
|
|
3348
|
+
}).where((0, import_drizzle_orm21.eq)(subscriptionBundles.id, subscriptionBundleId)).returning();
|
|
3159
3349
|
if (!rows[0]) throw new Error(`SubscriptionBundle '${subscriptionBundleId}' not found`);
|
|
3160
|
-
return
|
|
3350
|
+
return (0, import_core10.toSubscriptionBundleRecord)(rows[0]);
|
|
3161
3351
|
}
|
|
3162
3352
|
async countActiveByBundleVersionId(bundleVersionId, asOf = /* @__PURE__ */ new Date()) {
|
|
3163
3353
|
const rows = await this.db.select({
|
|
3164
3354
|
id: subscriptionBundles.id
|
|
3165
|
-
}).from(subscriptionBundles).where((0,
|
|
3355
|
+
}).from(subscriptionBundles).where((0, import_drizzle_orm21.and)((0, import_drizzle_orm21.eq)(subscriptionBundles.bundleVersionId, bundleVersionId), stillActive(asOf)));
|
|
3166
3356
|
return rows.length;
|
|
3167
3357
|
}
|
|
3168
3358
|
};
|
|
3169
|
-
DrizzleSubscriptionBundleRepository =
|
|
3170
|
-
(0,
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3359
|
+
DrizzleSubscriptionBundleRepository = _ts_decorate23([
|
|
3360
|
+
(0, import_common23.Injectable)(),
|
|
3361
|
+
_ts_param22(0, (0, import_common23.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3362
|
+
_ts_metadata22("design:type", Function),
|
|
3363
|
+
_ts_metadata22("design:paramtypes", [
|
|
3174
3364
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
3175
3365
|
])
|
|
3176
3366
|
], DrizzleSubscriptionBundleRepository);
|
|
3177
3367
|
function stillActive(asOf) {
|
|
3178
|
-
return (0,
|
|
3368
|
+
return (0, import_drizzle_orm21.or)((0, import_drizzle_orm21.isNull)(subscriptionBundles.canceledAt), (0, import_drizzle_orm21.gt)(subscriptionBundles.canceledEffectiveAt, asOf));
|
|
3179
3369
|
}
|
|
3180
3370
|
__name(stillActive, "stillActive");
|
|
3181
|
-
function toRecord3(row) {
|
|
3182
|
-
return {
|
|
3183
|
-
id: row.id,
|
|
3184
|
-
subscriptionId: row.subscriptionId,
|
|
3185
|
-
bundleVersionId: row.bundleVersionId,
|
|
3186
|
-
startedAt: row.startedAt,
|
|
3187
|
-
minimumTermEndsAt: row.minimumTermEndsAt,
|
|
3188
|
-
billingCycle: row.billingCycle,
|
|
3189
|
-
currentPeriodStart: row.currentPeriodStart,
|
|
3190
|
-
currentPeriodEnd: row.currentPeriodEnd,
|
|
3191
|
-
canceledAt: row.canceledAt,
|
|
3192
|
-
canceledEffectiveAt: row.canceledEffectiveAt,
|
|
3193
|
-
createdAt: row.createdAt,
|
|
3194
|
-
updatedAt: row.updatedAt
|
|
3195
|
-
};
|
|
3196
|
-
}
|
|
3197
|
-
__name(toRecord3, "toRecord");
|
|
3198
3371
|
|
|
3199
3372
|
// src/drizzle-promo-code-validation-log.repository.ts
|
|
3200
|
-
var
|
|
3201
|
-
var
|
|
3202
|
-
var
|
|
3203
|
-
function
|
|
3204
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3205
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3373
|
+
var import_node_crypto16 = require("node:crypto");
|
|
3374
|
+
var import_common24 = require("@nestjs/common");
|
|
3375
|
+
var import_drizzle_orm22 = require("drizzle-orm");
|
|
3376
|
+
function _ts_decorate24(decorators, target, key, desc11) {
|
|
3377
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3378
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
3206
3379
|
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;
|
|
3207
3380
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3208
3381
|
}
|
|
3209
|
-
__name(
|
|
3210
|
-
function
|
|
3382
|
+
__name(_ts_decorate24, "_ts_decorate");
|
|
3383
|
+
function _ts_metadata23(k, v) {
|
|
3211
3384
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3212
3385
|
}
|
|
3213
|
-
__name(
|
|
3214
|
-
function
|
|
3386
|
+
__name(_ts_metadata23, "_ts_metadata");
|
|
3387
|
+
function _ts_param23(paramIndex, decorator) {
|
|
3215
3388
|
return function(target, key) {
|
|
3216
3389
|
decorator(target, key, paramIndex);
|
|
3217
3390
|
};
|
|
3218
3391
|
}
|
|
3219
|
-
__name(
|
|
3392
|
+
__name(_ts_param23, "_ts_param");
|
|
3220
3393
|
var DrizzlePromoCodeValidationLogRepository = class {
|
|
3221
3394
|
static {
|
|
3222
3395
|
__name(this, "DrizzlePromoCodeValidationLogRepository");
|
|
@@ -3227,7 +3400,7 @@ var DrizzlePromoCodeValidationLogRepository = class {
|
|
|
3227
3400
|
}
|
|
3228
3401
|
async log(args) {
|
|
3229
3402
|
await this.db.insert(promoCodeValidationLogs).values({
|
|
3230
|
-
id: (0,
|
|
3403
|
+
id: (0, import_node_crypto16.randomUUID)(),
|
|
3231
3404
|
promoCodeId: args.promoCodeId,
|
|
3232
3405
|
codeAttempt: args.codeAttempt.trim().toUpperCase(),
|
|
3233
3406
|
result: args.result,
|
|
@@ -3238,39 +3411,39 @@ var DrizzlePromoCodeValidationLogRepository = class {
|
|
|
3238
3411
|
async countValid(promoCodeId) {
|
|
3239
3412
|
const rows = await this.db.select({
|
|
3240
3413
|
id: promoCodeValidationLogs.id
|
|
3241
|
-
}).from(promoCodeValidationLogs).where((0,
|
|
3414
|
+
}).from(promoCodeValidationLogs).where((0, import_drizzle_orm22.and)((0, import_drizzle_orm22.eq)(promoCodeValidationLogs.promoCodeId, promoCodeId), (0, import_drizzle_orm22.eq)(promoCodeValidationLogs.result, "VALID")));
|
|
3242
3415
|
return rows.length;
|
|
3243
3416
|
}
|
|
3244
3417
|
};
|
|
3245
|
-
DrizzlePromoCodeValidationLogRepository =
|
|
3246
|
-
(0,
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3418
|
+
DrizzlePromoCodeValidationLogRepository = _ts_decorate24([
|
|
3419
|
+
(0, import_common24.Injectable)(),
|
|
3420
|
+
_ts_param23(0, (0, import_common24.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3421
|
+
_ts_metadata23("design:type", Function),
|
|
3422
|
+
_ts_metadata23("design:paramtypes", [
|
|
3250
3423
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
3251
3424
|
])
|
|
3252
3425
|
], DrizzlePromoCodeValidationLogRepository);
|
|
3253
3426
|
|
|
3254
3427
|
// src/drizzle-promo-subscription-lookup.adapter.ts
|
|
3255
|
-
var
|
|
3256
|
-
var
|
|
3257
|
-
function
|
|
3258
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3259
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3428
|
+
var import_common25 = require("@nestjs/common");
|
|
3429
|
+
var import_drizzle_orm23 = require("drizzle-orm");
|
|
3430
|
+
function _ts_decorate25(decorators, target, key, desc11) {
|
|
3431
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3432
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
3260
3433
|
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;
|
|
3261
3434
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3262
3435
|
}
|
|
3263
|
-
__name(
|
|
3264
|
-
function
|
|
3436
|
+
__name(_ts_decorate25, "_ts_decorate");
|
|
3437
|
+
function _ts_metadata24(k, v) {
|
|
3265
3438
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3266
3439
|
}
|
|
3267
|
-
__name(
|
|
3268
|
-
function
|
|
3440
|
+
__name(_ts_metadata24, "_ts_metadata");
|
|
3441
|
+
function _ts_param24(paramIndex, decorator) {
|
|
3269
3442
|
return function(target, key) {
|
|
3270
3443
|
decorator(target, key, paramIndex);
|
|
3271
3444
|
};
|
|
3272
3445
|
}
|
|
3273
|
-
__name(
|
|
3446
|
+
__name(_ts_param24, "_ts_param");
|
|
3274
3447
|
var DrizzlePromoSubscriptionLookup = class {
|
|
3275
3448
|
static {
|
|
3276
3449
|
__name(this, "DrizzlePromoSubscriptionLookup");
|
|
@@ -3287,7 +3460,7 @@ var DrizzlePromoSubscriptionLookup = class {
|
|
|
3287
3460
|
plan: subscriptions.plan,
|
|
3288
3461
|
billingCycle: subscriptions.billingCycle,
|
|
3289
3462
|
startedAt: subscriptions.startedAt
|
|
3290
|
-
}).from(subscriptions).where((0,
|
|
3463
|
+
}).from(subscriptions).where((0, import_drizzle_orm23.eq)(subscriptions.id, subscriptionId)).limit(1);
|
|
3291
3464
|
const row = rows[0];
|
|
3292
3465
|
if (!row) return null;
|
|
3293
3466
|
return {
|
|
@@ -3299,35 +3472,35 @@ var DrizzlePromoSubscriptionLookup = class {
|
|
|
3299
3472
|
};
|
|
3300
3473
|
}
|
|
3301
3474
|
};
|
|
3302
|
-
DrizzlePromoSubscriptionLookup =
|
|
3303
|
-
(0,
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3475
|
+
DrizzlePromoSubscriptionLookup = _ts_decorate25([
|
|
3476
|
+
(0, import_common25.Injectable)(),
|
|
3477
|
+
_ts_param24(0, (0, import_common25.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3478
|
+
_ts_metadata24("design:type", Function),
|
|
3479
|
+
_ts_metadata24("design:paramtypes", [
|
|
3307
3480
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
3308
3481
|
])
|
|
3309
3482
|
], DrizzlePromoSubscriptionLookup);
|
|
3310
3483
|
|
|
3311
3484
|
// src/drizzle-subscription.repository.ts
|
|
3312
|
-
var
|
|
3313
|
-
var
|
|
3314
|
-
function
|
|
3315
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3316
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3485
|
+
var import_common26 = require("@nestjs/common");
|
|
3486
|
+
var import_drizzle_orm24 = require("drizzle-orm");
|
|
3487
|
+
function _ts_decorate26(decorators, target, key, desc11) {
|
|
3488
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3489
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
3317
3490
|
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;
|
|
3318
3491
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3319
3492
|
}
|
|
3320
|
-
__name(
|
|
3321
|
-
function
|
|
3493
|
+
__name(_ts_decorate26, "_ts_decorate");
|
|
3494
|
+
function _ts_metadata25(k, v) {
|
|
3322
3495
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3323
3496
|
}
|
|
3324
|
-
__name(
|
|
3325
|
-
function
|
|
3497
|
+
__name(_ts_metadata25, "_ts_metadata");
|
|
3498
|
+
function _ts_param25(paramIndex, decorator) {
|
|
3326
3499
|
return function(target, key) {
|
|
3327
3500
|
decorator(target, key, paramIndex);
|
|
3328
3501
|
};
|
|
3329
3502
|
}
|
|
3330
|
-
__name(
|
|
3503
|
+
__name(_ts_param25, "_ts_param");
|
|
3331
3504
|
var ACTIVE_STATUSES = [
|
|
3332
3505
|
"ACTIVE",
|
|
3333
3506
|
"TRIAL"
|
|
@@ -3347,27 +3520,27 @@ var DrizzleSubscriptionRepository = class {
|
|
|
3347
3520
|
const db = resolveDb(this.db, tx);
|
|
3348
3521
|
await db.select({
|
|
3349
3522
|
id: subscriptions.id
|
|
3350
|
-
}).from(subscriptions).where((0,
|
|
3523
|
+
}).from(subscriptions).where((0, import_drizzle_orm24.eq)(subscriptions.tenantId, tenantId)).for("update");
|
|
3351
3524
|
return this.loadByTenantId(db, tenantId);
|
|
3352
3525
|
}
|
|
3353
3526
|
async countByPlanVersionId(planVersionId) {
|
|
3354
3527
|
const rows = await this.db.select({
|
|
3355
3528
|
id: subscriptions.id
|
|
3356
|
-
}).from(subscriptions).where((0,
|
|
3529
|
+
}).from(subscriptions).where((0, import_drizzle_orm24.or)((0, import_drizzle_orm24.eq)(subscriptions.planVersionId, planVersionId), (0, import_drizzle_orm24.eq)(subscriptions.pendingPlanVersionId, planVersionId)));
|
|
3357
3530
|
return rows.length;
|
|
3358
3531
|
}
|
|
3359
3532
|
async countActiveByPlanKey() {
|
|
3360
3533
|
const now = /* @__PURE__ */ new Date();
|
|
3361
3534
|
const rows = await this.db.select({
|
|
3362
3535
|
plan: subscriptions.plan
|
|
3363
|
-
}).from(subscriptions).where((0,
|
|
3364
|
-
(0,
|
|
3365
|
-
(0,
|
|
3536
|
+
}).from(subscriptions).where((0, import_drizzle_orm24.and)((0, import_drizzle_orm24.inArray)(subscriptions.status, ACTIVE_STATUSES), (0, import_drizzle_orm24.or)(
|
|
3537
|
+
(0, import_drizzle_orm24.isNull)(subscriptions.canceledAt),
|
|
3538
|
+
(0, import_drizzle_orm24.gt)(subscriptions.canceledEffectiveAt, now),
|
|
3366
3539
|
// The pre-split row keeps its effective date in the
|
|
3367
3540
|
// first column; reading only the second drops that
|
|
3368
3541
|
// customer on the day they declare rather than the day
|
|
3369
3542
|
// they leave.
|
|
3370
|
-
(0,
|
|
3543
|
+
(0, import_drizzle_orm24.and)((0, import_drizzle_orm24.isNull)(subscriptions.canceledEffectiveAt), (0, import_drizzle_orm24.gt)(subscriptions.canceledAt, now))
|
|
3371
3544
|
)));
|
|
3372
3545
|
const counts = {};
|
|
3373
3546
|
for (const row of rows) {
|
|
@@ -3376,13 +3549,13 @@ var DrizzleSubscriptionRepository = class {
|
|
|
3376
3549
|
return counts;
|
|
3377
3550
|
}
|
|
3378
3551
|
async loadByTenantId(db, tenantId) {
|
|
3379
|
-
const rows = await db.select().from(subscriptions).where((0,
|
|
3552
|
+
const rows = await db.select().from(subscriptions).where((0, import_drizzle_orm24.eq)(subscriptions.tenantId, tenantId)).limit(1);
|
|
3380
3553
|
const row = rows[0];
|
|
3381
3554
|
if (!row) return null;
|
|
3382
3555
|
return this.toRecord(db, row);
|
|
3383
3556
|
}
|
|
3384
3557
|
async toRecord(db, row) {
|
|
3385
|
-
const versionRows = await db.select().from(planVersions).where((0,
|
|
3558
|
+
const versionRows = await db.select().from(planVersions).where((0, import_drizzle_orm24.eq)(planVersions.id, row.planVersionId)).limit(1);
|
|
3386
3559
|
const planVersion = versionRows[0];
|
|
3387
3560
|
if (!planVersion) {
|
|
3388
3561
|
throw new Error(`Subscription ${row.id} references missing PlanVersion ${row.planVersionId}.`);
|
|
@@ -3408,37 +3581,37 @@ var DrizzleSubscriptionRepository = class {
|
|
|
3408
3581
|
};
|
|
3409
3582
|
}
|
|
3410
3583
|
};
|
|
3411
|
-
DrizzleSubscriptionRepository =
|
|
3412
|
-
(0,
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3584
|
+
DrizzleSubscriptionRepository = _ts_decorate26([
|
|
3585
|
+
(0, import_common26.Injectable)(),
|
|
3586
|
+
_ts_param25(0, (0, import_common26.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3587
|
+
_ts_metadata25("design:type", Function),
|
|
3588
|
+
_ts_metadata25("design:paramtypes", [
|
|
3416
3589
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
3417
3590
|
])
|
|
3418
3591
|
], DrizzleSubscriptionRepository);
|
|
3419
3592
|
|
|
3420
3593
|
// src/drizzle-super-admin-bootstrap.adapter.ts
|
|
3421
|
-
var
|
|
3422
|
-
var
|
|
3423
|
-
var
|
|
3424
|
-
var
|
|
3425
|
-
function
|
|
3426
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3427
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3594
|
+
var import_node_crypto17 = require("node:crypto");
|
|
3595
|
+
var import_common27 = require("@nestjs/common");
|
|
3596
|
+
var import_drizzle_orm25 = require("drizzle-orm");
|
|
3597
|
+
var import_core11 = require("@saasicat/core");
|
|
3598
|
+
function _ts_decorate27(decorators, target, key, desc11) {
|
|
3599
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3600
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
3428
3601
|
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;
|
|
3429
3602
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3430
3603
|
}
|
|
3431
|
-
__name(
|
|
3432
|
-
function
|
|
3604
|
+
__name(_ts_decorate27, "_ts_decorate");
|
|
3605
|
+
function _ts_metadata26(k, v) {
|
|
3433
3606
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3434
3607
|
}
|
|
3435
|
-
__name(
|
|
3436
|
-
function
|
|
3608
|
+
__name(_ts_metadata26, "_ts_metadata");
|
|
3609
|
+
function _ts_param26(paramIndex, decorator) {
|
|
3437
3610
|
return function(target, key) {
|
|
3438
3611
|
decorator(target, key, paramIndex);
|
|
3439
3612
|
};
|
|
3440
3613
|
}
|
|
3441
|
-
__name(
|
|
3614
|
+
__name(_ts_param26, "_ts_param");
|
|
3442
3615
|
var PASSWORD_HASHER_TOKEN = /* @__PURE__ */ Symbol.for("saasicat/adapter-drizzle/PasswordHasher");
|
|
3443
3616
|
var DrizzleSuperAdminBootstrapAdapter = class {
|
|
3444
3617
|
static {
|
|
@@ -3452,18 +3625,18 @@ var DrizzleSuperAdminBootstrapAdapter = class {
|
|
|
3452
3625
|
}
|
|
3453
3626
|
async countSuperAdmins() {
|
|
3454
3627
|
const rows = await this.db.select({
|
|
3455
|
-
value: (0,
|
|
3456
|
-
}).from(superAdminUsers).where((0,
|
|
3628
|
+
value: (0, import_drizzle_orm25.count)()
|
|
3629
|
+
}).from(superAdminUsers).where((0, import_drizzle_orm25.and)((0, import_drizzle_orm25.eq)(superAdminUsers.isActive, true), (0, import_drizzle_orm25.isNull)(superAdminUsers.deletedAt)));
|
|
3457
3630
|
return rows[0]?.value ?? 0;
|
|
3458
3631
|
}
|
|
3459
3632
|
async createSuperAdmin(input) {
|
|
3460
3633
|
const email = input.email.trim().toLowerCase();
|
|
3461
|
-
const existing = await this.db.select().from(superAdminUsers).where((0,
|
|
3634
|
+
const existing = await this.db.select().from(superAdminUsers).where((0, import_drizzle_orm25.eq)(superAdminUsers.email, email)).limit(1);
|
|
3462
3635
|
if (existing[0]) {
|
|
3463
|
-
throw new
|
|
3636
|
+
throw new import_core11.PlatformUserExistsError(email, existing[0].platformRole);
|
|
3464
3637
|
}
|
|
3465
3638
|
const rows = await this.db.insert(superAdminUsers).values({
|
|
3466
|
-
id: (0,
|
|
3639
|
+
id: (0, import_node_crypto17.randomUUID)(),
|
|
3467
3640
|
email,
|
|
3468
3641
|
passwordHash: await this.passwordHasher.hash(input.password),
|
|
3469
3642
|
firstName: input.firstName ?? null,
|
|
@@ -3483,36 +3656,36 @@ var DrizzleSuperAdminBootstrapAdapter = class {
|
|
|
3483
3656
|
};
|
|
3484
3657
|
}
|
|
3485
3658
|
};
|
|
3486
|
-
DrizzleSuperAdminBootstrapAdapter =
|
|
3487
|
-
(0,
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3659
|
+
DrizzleSuperAdminBootstrapAdapter = _ts_decorate27([
|
|
3660
|
+
(0, import_common27.Injectable)(),
|
|
3661
|
+
_ts_param26(0, (0, import_common27.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3662
|
+
_ts_param26(1, (0, import_common27.Inject)(PASSWORD_HASHER_TOKEN)),
|
|
3663
|
+
_ts_metadata26("design:type", Function),
|
|
3664
|
+
_ts_metadata26("design:paramtypes", [
|
|
3492
3665
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient,
|
|
3493
3666
|
typeof PasswordHasher === "undefined" ? Object : PasswordHasher
|
|
3494
3667
|
])
|
|
3495
3668
|
], DrizzleSuperAdminBootstrapAdapter);
|
|
3496
3669
|
|
|
3497
3670
|
// src/drizzle-transaction-runner.adapter.ts
|
|
3498
|
-
var
|
|
3499
|
-
function
|
|
3500
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3501
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3671
|
+
var import_common28 = require("@nestjs/common");
|
|
3672
|
+
function _ts_decorate28(decorators, target, key, desc11) {
|
|
3673
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3674
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
3502
3675
|
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;
|
|
3503
3676
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3504
3677
|
}
|
|
3505
|
-
__name(
|
|
3506
|
-
function
|
|
3678
|
+
__name(_ts_decorate28, "_ts_decorate");
|
|
3679
|
+
function _ts_metadata27(k, v) {
|
|
3507
3680
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3508
3681
|
}
|
|
3509
|
-
__name(
|
|
3510
|
-
function
|
|
3682
|
+
__name(_ts_metadata27, "_ts_metadata");
|
|
3683
|
+
function _ts_param27(paramIndex, decorator) {
|
|
3511
3684
|
return function(target, key) {
|
|
3512
3685
|
decorator(target, key, paramIndex);
|
|
3513
3686
|
};
|
|
3514
3687
|
}
|
|
3515
|
-
__name(
|
|
3688
|
+
__name(_ts_param27, "_ts_param");
|
|
3516
3689
|
var DrizzleTransactionRunner = class {
|
|
3517
3690
|
static {
|
|
3518
3691
|
__name(this, "DrizzleTransactionRunner");
|
|
@@ -3525,24 +3698,24 @@ var DrizzleTransactionRunner = class {
|
|
|
3525
3698
|
return this.db.transaction((tx) => fn(tx));
|
|
3526
3699
|
}
|
|
3527
3700
|
};
|
|
3528
|
-
DrizzleTransactionRunner =
|
|
3529
|
-
(0,
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3701
|
+
DrizzleTransactionRunner = _ts_decorate28([
|
|
3702
|
+
(0, import_common28.Injectable)(),
|
|
3703
|
+
_ts_param27(0, (0, import_common28.Inject)(DRIZZLE_DB_TOKEN)),
|
|
3704
|
+
_ts_metadata27("design:type", Function),
|
|
3705
|
+
_ts_metadata27("design:paramtypes", [
|
|
3533
3706
|
typeof DrizzleClient === "undefined" ? Object : DrizzleClient
|
|
3534
3707
|
])
|
|
3535
3708
|
], DrizzleTransactionRunner);
|
|
3536
3709
|
|
|
3537
3710
|
// src/zero-promo-revenue-aggregator.adapter.ts
|
|
3538
|
-
var
|
|
3539
|
-
function
|
|
3540
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3541
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3711
|
+
var import_common29 = require("@nestjs/common");
|
|
3712
|
+
function _ts_decorate29(decorators, target, key, desc11) {
|
|
3713
|
+
var c = arguments.length, r = c < 3 ? target : desc11 === null ? desc11 = Object.getOwnPropertyDescriptor(target, key) : desc11, d;
|
|
3714
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc11);
|
|
3542
3715
|
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;
|
|
3543
3716
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3544
3717
|
}
|
|
3545
|
-
__name(
|
|
3718
|
+
__name(_ts_decorate29, "_ts_decorate");
|
|
3546
3719
|
var ZeroPromoRevenueDeductionAggregator = class {
|
|
3547
3720
|
static {
|
|
3548
3721
|
__name(this, "ZeroPromoRevenueDeductionAggregator");
|
|
@@ -3551,8 +3724,8 @@ var ZeroPromoRevenueDeductionAggregator = class {
|
|
|
3551
3724
|
return "0.00";
|
|
3552
3725
|
}
|
|
3553
3726
|
};
|
|
3554
|
-
ZeroPromoRevenueDeductionAggregator =
|
|
3555
|
-
(0,
|
|
3727
|
+
ZeroPromoRevenueDeductionAggregator = _ts_decorate29([
|
|
3728
|
+
(0, import_common29.Injectable)()
|
|
3556
3729
|
], ZeroPromoRevenueDeductionAggregator);
|
|
3557
3730
|
|
|
3558
3731
|
// src/drizzle-persistence.ts
|
|
@@ -3579,7 +3752,8 @@ function drizzlePersistence(options) {
|
|
|
3579
3752
|
auditQuery: provide((client) => new DrizzleAuditQueryAdapter(client)),
|
|
3580
3753
|
auditStats: provide((client) => new DrizzleAuditStatsAdapter(client)),
|
|
3581
3754
|
superAdminProvisioning: buildProvisioning(db, options.passwordHasher),
|
|
3582
|
-
appliedSettings: provide((client) => new DrizzleAppliedSettingsRepository(client))
|
|
3755
|
+
appliedSettings: provide((client) => new DrizzleAppliedSettingsRepository(client)),
|
|
3756
|
+
maintenanceWindows: provide((client) => new DrizzleMaintenanceWindowRepository(client))
|
|
3583
3757
|
},
|
|
3584
3758
|
entitlement: {
|
|
3585
3759
|
subscriptionRepository: provide((client) => new DrizzleSubscriptionRepository(client)),
|
|
@@ -3595,6 +3769,8 @@ function drizzlePersistence(options) {
|
|
|
3595
3769
|
subscriptionContractRepository: provide((client) => new DrizzleSubscriptionContractRepository(client)),
|
|
3596
3770
|
// The party each of those contracts is concluded with.
|
|
3597
3771
|
subscriberRepository: provide((client) => new DrizzleSubscriberRepository(client)),
|
|
3772
|
+
// The charges those contracts give rise to, written once each.
|
|
3773
|
+
subscriberLedgerRepository: provide((client) => new DrizzleSubscriberLedgerRepository(client)),
|
|
3598
3774
|
// The catalogue behind those bookings: entitlement resolves a
|
|
3599
3775
|
// booking's features by reading the pinned version.
|
|
3600
3776
|
bundleRepository: provide((client) => new DrizzleBundleRepository(client, options.bundle))
|
|
@@ -3678,6 +3854,7 @@ __name(buildProvisioning, "buildProvisioning");
|
|
|
3678
3854
|
DrizzleAuditQueryAdapter,
|
|
3679
3855
|
DrizzleAuditStatsAdapter,
|
|
3680
3856
|
DrizzleBundleRepository,
|
|
3857
|
+
DrizzleMaintenanceWindowRepository,
|
|
3681
3858
|
DrizzleMfaAdapter,
|
|
3682
3859
|
DrizzlePaymentEventLog,
|
|
3683
3860
|
DrizzlePlanCatalogImportSink,
|
|
@@ -3689,6 +3866,7 @@ __name(buildProvisioning, "buildProvisioning");
|
|
|
3689
3866
|
DrizzlePromoCodeRepository,
|
|
3690
3867
|
DrizzlePromoCodeValidationLogRepository,
|
|
3691
3868
|
DrizzlePromoSubscriptionLookup,
|
|
3869
|
+
DrizzleSubscriberLedgerRepository,
|
|
3692
3870
|
DrizzleSubscriberPaymentMethodRepository,
|
|
3693
3871
|
DrizzleSubscriberRepository,
|
|
3694
3872
|
DrizzleSubscriptionBundleRepository,
|