@forklaunch/implementation-billing-base 0.3.4 → 0.3.5
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/lib/domain/schemas/index.d.mts +336 -1146
- package/lib/domain/schemas/index.d.ts +336 -1146
- package/lib/domain/schemas/index.js +246 -385
- package/lib/domain/schemas/index.mjs +221 -277
- package/lib/eject/domain/schemas/billingPortal.schema.ts +7 -1
- package/lib/eject/domain/schemas/checkoutSession.schema.ts +1 -1
- package/lib/eject/domain/schemas/paymentLink.schema.ts +1 -1
- package/lib/eject/domain/schemas/plan.schema.ts +1 -1
- package/lib/eject/domain/schemas/subscription.schema.ts +1 -1
- package/lib/services/index.d.mts +206 -661
- package/lib/services/index.d.ts +206 -661
- package/lib/services/index.js +202 -262
- package/lib/services/index.mjs +206 -226
- package/package.json +1 -1
package/lib/services/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -8,18 +8,14 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
12
|
for (let key of __getOwnPropNames(from))
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
15
|
}
|
|
19
16
|
return to;
|
|
20
17
|
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, '__esModule', { value: true }), mod);
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
19
|
|
|
24
20
|
// services/index.ts
|
|
25
21
|
var services_exports = {};
|
|
@@ -33,60 +29,46 @@ __export(services_exports, {
|
|
|
33
29
|
module.exports = __toCommonJS(services_exports);
|
|
34
30
|
|
|
35
31
|
// services/billingPortal.service.ts
|
|
36
|
-
var import_cache = require(
|
|
37
|
-
var import_http = require(
|
|
38
|
-
var import_internal = require(
|
|
32
|
+
var import_cache = require("@forklaunch/core/cache");
|
|
33
|
+
var import_http = require("@forklaunch/core/http");
|
|
34
|
+
var import_internal = require("@forklaunch/internal");
|
|
39
35
|
var BaseBillingPortalService = class {
|
|
40
|
-
constructor(
|
|
41
|
-
em,
|
|
42
|
-
cache,
|
|
43
|
-
openTelemetryCollector,
|
|
44
|
-
schemaValidator,
|
|
45
|
-
mappers,
|
|
46
|
-
options
|
|
47
|
-
) {
|
|
36
|
+
constructor(em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
48
37
|
this.em = em;
|
|
49
38
|
this.cache = cache;
|
|
50
39
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
51
40
|
this.schemaValidator = schemaValidator;
|
|
52
41
|
this.mappers = mappers;
|
|
53
42
|
this.options = options;
|
|
54
|
-
this._mappers = (0, import_internal.transformIntoInternalMapper)(
|
|
55
|
-
mappers,
|
|
56
|
-
schemaValidator
|
|
57
|
-
);
|
|
43
|
+
this._mappers = (0, import_internal.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
58
44
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
59
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
60
|
-
|
|
61
|
-
:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
tracing: false
|
|
65
|
-
};
|
|
45
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
46
|
+
logging: false,
|
|
47
|
+
metrics: false,
|
|
48
|
+
tracing: false
|
|
49
|
+
};
|
|
66
50
|
}
|
|
67
51
|
_mappers;
|
|
68
52
|
evaluatedTelemetryOptions;
|
|
69
53
|
enableDatabaseBackup;
|
|
70
|
-
createCacheKey = (0, import_cache.createCacheKey)(
|
|
54
|
+
createCacheKey = (0, import_cache.createCacheKey)("billing_portal_session");
|
|
71
55
|
async createBillingPortalSession(billingPortalDto) {
|
|
72
56
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
73
57
|
this.openTelemetryCollector.info(
|
|
74
|
-
|
|
58
|
+
"Creating billing portal session",
|
|
75
59
|
billingPortalDto
|
|
76
60
|
);
|
|
77
61
|
}
|
|
78
|
-
const billingPortal =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
62
|
+
const billingPortal = await this._mappers.CreateBillingPortalMapper.deserializeDtoToEntity(
|
|
63
|
+
billingPortalDto,
|
|
64
|
+
this.em
|
|
65
|
+
);
|
|
83
66
|
if (this.enableDatabaseBackup) {
|
|
84
67
|
await this.em.persistAndFlush(billingPortal);
|
|
85
68
|
}
|
|
86
|
-
const createdBillingPortalDto =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
69
|
+
const createdBillingPortalDto = await this._mappers.BillingPortalMapper.serializeEntityToDto(
|
|
70
|
+
billingPortal
|
|
71
|
+
);
|
|
90
72
|
await this.cache.putRecord({
|
|
91
73
|
key: this.createCacheKey(createdBillingPortalDto.id),
|
|
92
74
|
value: createdBillingPortalDto,
|
|
@@ -96,34 +78,31 @@ var BaseBillingPortalService = class {
|
|
|
96
78
|
}
|
|
97
79
|
async getBillingPortalSession(idDto) {
|
|
98
80
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
99
|
-
this.openTelemetryCollector.info(
|
|
81
|
+
this.openTelemetryCollector.info("Getting billing portal session", idDto);
|
|
100
82
|
}
|
|
101
|
-
const billingPortalDetails = await this.cache.readRecord(
|
|
102
|
-
this.createCacheKey(idDto.id)
|
|
103
|
-
);
|
|
83
|
+
const billingPortalDetails = await this.cache.readRecord(this.createCacheKey(idDto.id));
|
|
104
84
|
if (!billingPortalDetails) {
|
|
105
|
-
throw new Error(
|
|
85
|
+
throw new Error("Session not found");
|
|
106
86
|
}
|
|
107
87
|
return billingPortalDetails.value;
|
|
108
88
|
}
|
|
109
89
|
async updateBillingPortalSession(billingPortalDto) {
|
|
110
90
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
111
91
|
this.openTelemetryCollector.info(
|
|
112
|
-
|
|
92
|
+
"Updating billing portal session",
|
|
113
93
|
billingPortalDto
|
|
114
94
|
);
|
|
115
95
|
}
|
|
116
|
-
const existingBillingPortal = (
|
|
117
|
-
|
|
118
|
-
)?.value;
|
|
96
|
+
const existingBillingPortal = (await this.cache.readRecord(
|
|
97
|
+
this.createCacheKey(billingPortalDto.id)
|
|
98
|
+
))?.value;
|
|
119
99
|
if (!existingBillingPortal) {
|
|
120
|
-
throw new Error(
|
|
100
|
+
throw new Error("Session not found");
|
|
121
101
|
}
|
|
122
|
-
const billingPortal =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
);
|
|
102
|
+
const billingPortal = await this._mappers.UpdateBillingPortalMapper.deserializeDtoToEntity(
|
|
103
|
+
billingPortalDto,
|
|
104
|
+
this.em
|
|
105
|
+
);
|
|
127
106
|
if (this.enableDatabaseBackup) {
|
|
128
107
|
await this.em.persistAndFlush({
|
|
129
108
|
billingPortal
|
|
@@ -131,9 +110,9 @@ var BaseBillingPortalService = class {
|
|
|
131
110
|
}
|
|
132
111
|
const updatedBillingPortalDto = {
|
|
133
112
|
...existingBillingPortal,
|
|
134
|
-
...
|
|
113
|
+
...await this._mappers.BillingPortalMapper.serializeEntityToDto(
|
|
135
114
|
billingPortal
|
|
136
|
-
)
|
|
115
|
+
)
|
|
137
116
|
};
|
|
138
117
|
await this.cache.putRecord({
|
|
139
118
|
key: this.createCacheKey(updatedBillingPortalDto.id),
|
|
@@ -145,7 +124,7 @@ var BaseBillingPortalService = class {
|
|
|
145
124
|
async expireBillingPortalSession(idDto) {
|
|
146
125
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
147
126
|
this.openTelemetryCollector.info(
|
|
148
|
-
|
|
127
|
+
"Expiring billing portal session",
|
|
149
128
|
idDto
|
|
150
129
|
);
|
|
151
130
|
}
|
|
@@ -153,64 +132,50 @@ var BaseBillingPortalService = class {
|
|
|
153
132
|
this.createCacheKey(idDto.id)
|
|
154
133
|
);
|
|
155
134
|
if (!sessionExists) {
|
|
156
|
-
throw new Error(
|
|
135
|
+
throw new Error("Session not found");
|
|
157
136
|
}
|
|
158
137
|
await this.cache.deleteRecord(this.createCacheKey(idDto.id));
|
|
159
138
|
}
|
|
160
139
|
};
|
|
161
140
|
|
|
162
141
|
// services/checkoutSession.service.ts
|
|
163
|
-
var import_cache2 = require(
|
|
164
|
-
var import_http2 = require(
|
|
165
|
-
var import_internal2 = require(
|
|
142
|
+
var import_cache2 = require("@forklaunch/core/cache");
|
|
143
|
+
var import_http2 = require("@forklaunch/core/http");
|
|
144
|
+
var import_internal2 = require("@forklaunch/internal");
|
|
166
145
|
var BaseCheckoutSessionService = class {
|
|
167
|
-
constructor(
|
|
168
|
-
em,
|
|
169
|
-
cache,
|
|
170
|
-
openTelemetryCollector,
|
|
171
|
-
schemaValidator,
|
|
172
|
-
mappers,
|
|
173
|
-
options
|
|
174
|
-
) {
|
|
146
|
+
constructor(em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
175
147
|
this.em = em;
|
|
176
148
|
this.cache = cache;
|
|
177
149
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
178
150
|
this.schemaValidator = schemaValidator;
|
|
179
151
|
this.mappers = mappers;
|
|
180
152
|
this.options = options;
|
|
181
|
-
this._mappers = (0, import_internal2.transformIntoInternalMapper)(
|
|
182
|
-
mappers,
|
|
183
|
-
schemaValidator
|
|
184
|
-
);
|
|
153
|
+
this._mappers = (0, import_internal2.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
185
154
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
186
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
187
|
-
|
|
188
|
-
:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
tracing: false
|
|
192
|
-
};
|
|
155
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http2.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
156
|
+
logging: false,
|
|
157
|
+
metrics: false,
|
|
158
|
+
tracing: false
|
|
159
|
+
};
|
|
193
160
|
}
|
|
194
161
|
_mappers;
|
|
195
162
|
evaluatedTelemetryOptions;
|
|
196
163
|
enableDatabaseBackup;
|
|
197
|
-
createCacheKey = (0, import_cache2.createCacheKey)(
|
|
164
|
+
createCacheKey = (0, import_cache2.createCacheKey)("checkout_session");
|
|
198
165
|
async createCheckoutSession(checkoutSessionDto) {
|
|
199
166
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
200
167
|
this.openTelemetryCollector.info(
|
|
201
|
-
|
|
168
|
+
"Creating checkout session",
|
|
202
169
|
checkoutSessionDto
|
|
203
170
|
);
|
|
204
171
|
}
|
|
205
|
-
const checkoutSession =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
checkoutSession
|
|
213
|
-
);
|
|
172
|
+
const checkoutSession = await this._mappers.CreateCheckoutSessionMapper.deserializeDtoToEntity(
|
|
173
|
+
checkoutSessionDto,
|
|
174
|
+
this.em
|
|
175
|
+
);
|
|
176
|
+
const createdCheckoutSessionDto = await this._mappers.CheckoutSessionMapper.serializeEntityToDto(
|
|
177
|
+
checkoutSession
|
|
178
|
+
);
|
|
214
179
|
if (this.enableDatabaseBackup) {
|
|
215
180
|
await this.em.persistAndFlush(checkoutSession);
|
|
216
181
|
}
|
|
@@ -221,12 +186,12 @@ var BaseCheckoutSessionService = class {
|
|
|
221
186
|
});
|
|
222
187
|
return createdCheckoutSessionDto;
|
|
223
188
|
}
|
|
224
|
-
async getCheckoutSession({
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
);
|
|
189
|
+
async getCheckoutSession({
|
|
190
|
+
id
|
|
191
|
+
}) {
|
|
192
|
+
const checkoutSessionDetails = await this.cache.readRecord(this.createCacheKey(id));
|
|
228
193
|
if (!checkoutSessionDetails) {
|
|
229
|
-
throw new Error(
|
|
194
|
+
throw new Error("Session not found");
|
|
230
195
|
}
|
|
231
196
|
return this._mappers.CheckoutSessionMapper.serializeEntityToDto(
|
|
232
197
|
checkoutSessionDetails.value
|
|
@@ -237,18 +202,18 @@ var BaseCheckoutSessionService = class {
|
|
|
237
202
|
this.createCacheKey(id)
|
|
238
203
|
);
|
|
239
204
|
if (!checkoutSessionDetails) {
|
|
240
|
-
throw new Error(
|
|
205
|
+
throw new Error("Session not found");
|
|
241
206
|
}
|
|
242
207
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
243
208
|
}
|
|
244
209
|
async handleCheckoutSuccess({ id }) {
|
|
245
210
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
246
|
-
this.openTelemetryCollector.info(
|
|
211
|
+
this.openTelemetryCollector.info("Checkout success", { id });
|
|
247
212
|
}
|
|
248
213
|
if (this.enableDatabaseBackup) {
|
|
249
|
-
const checkoutSession = await this.em.upsert(
|
|
214
|
+
const checkoutSession = await this.em.upsert("CheckoutSession", {
|
|
250
215
|
id,
|
|
251
|
-
status:
|
|
216
|
+
status: "SUCCESS"
|
|
252
217
|
});
|
|
253
218
|
await this.em.persistAndFlush(checkoutSession);
|
|
254
219
|
}
|
|
@@ -256,12 +221,12 @@ var BaseCheckoutSessionService = class {
|
|
|
256
221
|
}
|
|
257
222
|
async handleCheckoutFailure({ id }) {
|
|
258
223
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
259
|
-
this.openTelemetryCollector.info(
|
|
224
|
+
this.openTelemetryCollector.info("Checkout failure", { id });
|
|
260
225
|
}
|
|
261
226
|
if (this.enableDatabaseBackup) {
|
|
262
|
-
const checkoutSession = await this.em.upsert(
|
|
227
|
+
const checkoutSession = await this.em.upsert("CheckoutSession", {
|
|
263
228
|
id,
|
|
264
|
-
status:
|
|
229
|
+
status: "FAILED"
|
|
265
230
|
});
|
|
266
231
|
await this.em.persistAndFlush(checkoutSession);
|
|
267
232
|
}
|
|
@@ -270,56 +235,42 @@ var BaseCheckoutSessionService = class {
|
|
|
270
235
|
};
|
|
271
236
|
|
|
272
237
|
// services/paymentLink.service.ts
|
|
273
|
-
var import_cache3 = require(
|
|
274
|
-
var import_http3 = require(
|
|
275
|
-
var import_internal3 = require(
|
|
238
|
+
var import_cache3 = require("@forklaunch/core/cache");
|
|
239
|
+
var import_http3 = require("@forklaunch/core/http");
|
|
240
|
+
var import_internal3 = require("@forklaunch/internal");
|
|
276
241
|
var BasePaymentLinkService = class {
|
|
277
|
-
constructor(
|
|
278
|
-
em,
|
|
279
|
-
cache,
|
|
280
|
-
openTelemetryCollector,
|
|
281
|
-
schemaValidator,
|
|
282
|
-
mappers,
|
|
283
|
-
options
|
|
284
|
-
) {
|
|
242
|
+
constructor(em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
285
243
|
this.em = em;
|
|
286
244
|
this.cache = cache;
|
|
287
245
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
288
246
|
this.schemaValidator = schemaValidator;
|
|
289
247
|
this.mappers = mappers;
|
|
290
248
|
this.options = options;
|
|
291
|
-
this._mappers = (0, import_internal3.transformIntoInternalMapper)(
|
|
292
|
-
mappers,
|
|
293
|
-
schemaValidator
|
|
294
|
-
);
|
|
249
|
+
this._mappers = (0, import_internal3.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
295
250
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
296
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
297
|
-
|
|
298
|
-
:
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
tracing: false
|
|
302
|
-
};
|
|
251
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http3.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
252
|
+
logging: false,
|
|
253
|
+
metrics: false,
|
|
254
|
+
tracing: false
|
|
255
|
+
};
|
|
303
256
|
}
|
|
304
257
|
_mappers;
|
|
305
258
|
evaluatedTelemetryOptions;
|
|
306
259
|
enableDatabaseBackup;
|
|
307
|
-
cacheKeyPrefix =
|
|
260
|
+
cacheKeyPrefix = "payment_link";
|
|
308
261
|
createCacheKey = (0, import_cache3.createCacheKey)(this.cacheKeyPrefix);
|
|
309
262
|
async createPaymentLink(paymentLinkDto) {
|
|
310
263
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
311
|
-
this.openTelemetryCollector.info(
|
|
264
|
+
this.openTelemetryCollector.info("Creating payment link", paymentLinkDto);
|
|
312
265
|
}
|
|
313
|
-
const paymentLink =
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
);
|
|
266
|
+
const paymentLink = await this._mappers.CreatePaymentLinkMapper.deserializeDtoToEntity(
|
|
267
|
+
paymentLinkDto,
|
|
268
|
+
this.em
|
|
269
|
+
);
|
|
318
270
|
if (this.enableDatabaseBackup) {
|
|
319
271
|
await this.em.persistAndFlush(paymentLink);
|
|
320
272
|
}
|
|
321
|
-
const createdPaymentLinkDto =
|
|
322
|
-
await this._mappers.PaymentLinkMapper.serializeEntityToDto(paymentLink);
|
|
273
|
+
const createdPaymentLinkDto = await this._mappers.PaymentLinkMapper.serializeEntityToDto(paymentLink);
|
|
323
274
|
await this.cache.putRecord({
|
|
324
275
|
key: this.createCacheKey(createdPaymentLinkDto.id),
|
|
325
276
|
value: createdPaymentLinkDto,
|
|
@@ -329,26 +280,25 @@ var BasePaymentLinkService = class {
|
|
|
329
280
|
}
|
|
330
281
|
async updatePaymentLink(paymentLinkDto) {
|
|
331
282
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
332
|
-
this.openTelemetryCollector.info(
|
|
283
|
+
this.openTelemetryCollector.info("Updating payment link", paymentLinkDto);
|
|
333
284
|
}
|
|
334
285
|
const cacheKey = this.createCacheKey(paymentLinkDto.id);
|
|
335
286
|
const existingLink = (await this.cache.readRecord(cacheKey))?.value;
|
|
336
287
|
if (!existingLink) {
|
|
337
|
-
throw new Error(
|
|
288
|
+
throw new Error("Payment link not found");
|
|
338
289
|
}
|
|
339
|
-
const paymentLink =
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
);
|
|
290
|
+
const paymentLink = await this._mappers.UpdatePaymentLinkMapper.deserializeDtoToEntity(
|
|
291
|
+
paymentLinkDto,
|
|
292
|
+
this.em
|
|
293
|
+
);
|
|
344
294
|
if (this.enableDatabaseBackup) {
|
|
345
295
|
await this.em.persistAndFlush(paymentLink);
|
|
346
296
|
}
|
|
347
297
|
const updatedLinkDto = {
|
|
348
298
|
...existingLink,
|
|
349
|
-
...
|
|
299
|
+
...await this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
350
300
|
paymentLink
|
|
351
|
-
)
|
|
301
|
+
)
|
|
352
302
|
};
|
|
353
303
|
await this.cache.putRecord({
|
|
354
304
|
key: cacheKey,
|
|
@@ -359,61 +309,58 @@ var BasePaymentLinkService = class {
|
|
|
359
309
|
}
|
|
360
310
|
async getPaymentLink({ id }) {
|
|
361
311
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
362
|
-
this.openTelemetryCollector.info(
|
|
312
|
+
this.openTelemetryCollector.info("Getting payment link", { id });
|
|
363
313
|
}
|
|
364
314
|
const cacheKey = this.createCacheKey(id);
|
|
365
315
|
const paymentLink = await this.cache.readRecord(cacheKey);
|
|
366
316
|
if (!paymentLink) {
|
|
367
|
-
throw new Error(
|
|
317
|
+
throw new Error("Payment link not found");
|
|
368
318
|
}
|
|
369
319
|
return this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
370
320
|
paymentLink.value
|
|
371
321
|
);
|
|
372
322
|
}
|
|
373
323
|
async expirePaymentLink({ id }) {
|
|
374
|
-
this.openTelemetryCollector.info(
|
|
324
|
+
this.openTelemetryCollector.info("Payment link expired", { id });
|
|
375
325
|
if (this.enableDatabaseBackup) {
|
|
376
|
-
const paymentLink = await this.em.upsert(
|
|
326
|
+
const paymentLink = await this.em.upsert("PaymentLink", {
|
|
377
327
|
id,
|
|
378
|
-
status:
|
|
328
|
+
status: "EXPIRED"
|
|
379
329
|
});
|
|
380
330
|
await this.em.removeAndFlush(paymentLink);
|
|
381
331
|
}
|
|
382
332
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
383
333
|
}
|
|
384
334
|
async handlePaymentSuccess({ id }) {
|
|
385
|
-
this.openTelemetryCollector.info(
|
|
335
|
+
this.openTelemetryCollector.info("Payment link success", { id });
|
|
386
336
|
if (this.enableDatabaseBackup) {
|
|
387
|
-
const paymentLink = await this.em.upsert(
|
|
337
|
+
const paymentLink = await this.em.upsert("PaymentLink", {
|
|
388
338
|
id,
|
|
389
|
-
status:
|
|
339
|
+
status: "COMPLETED"
|
|
390
340
|
});
|
|
391
341
|
await this.em.removeAndFlush(paymentLink);
|
|
392
342
|
}
|
|
393
343
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
394
344
|
}
|
|
395
345
|
async handlePaymentFailure({ id }) {
|
|
396
|
-
this.openTelemetryCollector.info(
|
|
346
|
+
this.openTelemetryCollector.info("Payment link failure", { id });
|
|
397
347
|
if (this.enableDatabaseBackup) {
|
|
398
|
-
const paymentLink = await this.em.upsert(
|
|
348
|
+
const paymentLink = await this.em.upsert("PaymentLink", {
|
|
399
349
|
id,
|
|
400
|
-
status:
|
|
350
|
+
status: "FAILED"
|
|
401
351
|
});
|
|
402
352
|
await this.em.removeAndFlush(paymentLink);
|
|
403
353
|
}
|
|
404
354
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
405
355
|
}
|
|
406
356
|
async listPaymentLinks(idsDto) {
|
|
407
|
-
const keys =
|
|
408
|
-
idsDto?.ids.map((id) => this.createCacheKey(id)) ??
|
|
409
|
-
(await this.cache.listKeys(this.cacheKeyPrefix));
|
|
357
|
+
const keys = idsDto?.ids.map((id) => this.createCacheKey(id)) ?? await this.cache.listKeys(this.cacheKeyPrefix);
|
|
410
358
|
return Promise.all(
|
|
411
359
|
keys.map(async (key) => {
|
|
412
360
|
const paymentLink = await this.cache.readRecord(key);
|
|
413
|
-
const paymentLinkDto =
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
);
|
|
361
|
+
const paymentLinkDto = this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
362
|
+
paymentLink.value
|
|
363
|
+
);
|
|
417
364
|
return paymentLinkDto;
|
|
418
365
|
})
|
|
419
366
|
);
|
|
@@ -421,8 +368,8 @@ var BasePaymentLinkService = class {
|
|
|
421
368
|
};
|
|
422
369
|
|
|
423
370
|
// services/plan.service.ts
|
|
424
|
-
var import_http4 = require(
|
|
425
|
-
var import_internal4 = require(
|
|
371
|
+
var import_http4 = require("@forklaunch/core/http");
|
|
372
|
+
var import_internal4 = require("@forklaunch/internal");
|
|
426
373
|
var BasePlanService = class {
|
|
427
374
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
428
375
|
this.em = em;
|
|
@@ -430,35 +377,32 @@ var BasePlanService = class {
|
|
|
430
377
|
this.schemaValidator = schemaValidator;
|
|
431
378
|
this.mappers = mappers;
|
|
432
379
|
this.options = options;
|
|
433
|
-
this._mappers = (0, import_internal4.transformIntoInternalMapper)(
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
: {
|
|
440
|
-
logging: false,
|
|
441
|
-
metrics: false,
|
|
442
|
-
tracing: false
|
|
443
|
-
};
|
|
380
|
+
this._mappers = (0, import_internal4.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
381
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http4.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
382
|
+
logging: false,
|
|
383
|
+
metrics: false,
|
|
384
|
+
tracing: false
|
|
385
|
+
};
|
|
444
386
|
}
|
|
445
387
|
_mappers;
|
|
446
388
|
evaluatedTelemetryOptions;
|
|
447
389
|
async listPlans(idsDto, em) {
|
|
448
390
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
449
|
-
this.openTelemetryCollector.info(
|
|
391
|
+
this.openTelemetryCollector.info("Listing plans", idsDto);
|
|
450
392
|
}
|
|
451
393
|
return Promise.all(
|
|
452
|
-
(
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
394
|
+
(await (em ?? this.em).findAll("Plan", {
|
|
395
|
+
filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : void 0
|
|
396
|
+
})).map(
|
|
397
|
+
(plan) => this._mappers.PlanMapper.serializeEntityToDto(
|
|
398
|
+
plan
|
|
399
|
+
)
|
|
400
|
+
)
|
|
457
401
|
);
|
|
458
402
|
}
|
|
459
403
|
async createPlan(planDto, em) {
|
|
460
404
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
461
|
-
this.openTelemetryCollector.info(
|
|
405
|
+
this.openTelemetryCollector.info("Creating plan", planDto);
|
|
462
406
|
}
|
|
463
407
|
const plan = await this._mappers.CreatePlanMapper.deserializeDtoToEntity(
|
|
464
408
|
planDto,
|
|
@@ -471,14 +415,16 @@ var BasePlanService = class {
|
|
|
471
415
|
}
|
|
472
416
|
async getPlan(idDto, em) {
|
|
473
417
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
474
|
-
this.openTelemetryCollector.info(
|
|
418
|
+
this.openTelemetryCollector.info("Getting plan", idDto);
|
|
475
419
|
}
|
|
476
|
-
const plan = await (em ?? this.em).findOneOrFail(
|
|
477
|
-
return this._mappers.PlanMapper.serializeEntityToDto(
|
|
420
|
+
const plan = await (em ?? this.em).findOneOrFail("Plan", idDto);
|
|
421
|
+
return this._mappers.PlanMapper.serializeEntityToDto(
|
|
422
|
+
plan
|
|
423
|
+
);
|
|
478
424
|
}
|
|
479
425
|
async updatePlan(planDto, em) {
|
|
480
426
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
481
|
-
this.openTelemetryCollector.info(
|
|
427
|
+
this.openTelemetryCollector.info("Updating plan", planDto);
|
|
482
428
|
}
|
|
483
429
|
const plan = await this._mappers.UpdatePlanMapper.deserializeDtoToEntity(
|
|
484
430
|
planDto,
|
|
@@ -488,21 +434,20 @@ var BasePlanService = class {
|
|
|
488
434
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
489
435
|
await innerEm.persist(plan);
|
|
490
436
|
});
|
|
491
|
-
const updatedPlanDto =
|
|
492
|
-
await this._mappers.PlanMapper.serializeEntityToDto(updatedPlan);
|
|
437
|
+
const updatedPlanDto = await this._mappers.PlanMapper.serializeEntityToDto(updatedPlan);
|
|
493
438
|
return updatedPlanDto;
|
|
494
439
|
}
|
|
495
440
|
async deletePlan(idDto, em) {
|
|
496
441
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
497
|
-
this.openTelemetryCollector.info(
|
|
442
|
+
this.openTelemetryCollector.info("Deleting plan", idDto);
|
|
498
443
|
}
|
|
499
|
-
await (em ?? this.em).nativeDelete(
|
|
444
|
+
await (em ?? this.em).nativeDelete("Plan", idDto);
|
|
500
445
|
}
|
|
501
446
|
};
|
|
502
447
|
|
|
503
448
|
// services/subscription.service.ts
|
|
504
|
-
var import_http5 = require(
|
|
505
|
-
var import_internal5 = require(
|
|
449
|
+
var import_http5 = require("@forklaunch/core/http");
|
|
450
|
+
var import_internal5 = require("@forklaunch/internal");
|
|
506
451
|
var BaseSubscriptionService = class {
|
|
507
452
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
508
453
|
this.em = em;
|
|
@@ -510,131 +455,127 @@ var BaseSubscriptionService = class {
|
|
|
510
455
|
this.schemaValidator = schemaValidator;
|
|
511
456
|
this.mappers = mappers;
|
|
512
457
|
this.options = options;
|
|
513
|
-
this._mappers = (0, import_internal5.transformIntoInternalMapper)(
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
: {
|
|
520
|
-
logging: false,
|
|
521
|
-
metrics: false,
|
|
522
|
-
tracing: false
|
|
523
|
-
};
|
|
458
|
+
this._mappers = (0, import_internal5.transformIntoInternalMapper)(mappers, this.schemaValidator);
|
|
459
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http5.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
460
|
+
logging: false,
|
|
461
|
+
metrics: false,
|
|
462
|
+
tracing: false
|
|
463
|
+
};
|
|
524
464
|
}
|
|
525
465
|
_mappers;
|
|
526
466
|
evaluatedTelemetryOptions;
|
|
527
467
|
async createSubscription(subscriptionDto, em) {
|
|
528
468
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
529
469
|
this.openTelemetryCollector.info(
|
|
530
|
-
|
|
470
|
+
"Creating subscription",
|
|
531
471
|
subscriptionDto
|
|
532
472
|
);
|
|
533
473
|
}
|
|
534
|
-
const subscription =
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
);
|
|
474
|
+
const subscription = await this._mappers.CreateSubscriptionMapper.deserializeDtoToEntity(
|
|
475
|
+
subscriptionDto,
|
|
476
|
+
em ?? this.em
|
|
477
|
+
);
|
|
539
478
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
540
479
|
await innerEm.persist(subscription);
|
|
541
480
|
});
|
|
542
|
-
const createdSubscriptionDto =
|
|
543
|
-
await this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
481
|
+
const createdSubscriptionDto = await this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
544
482
|
return createdSubscriptionDto;
|
|
545
483
|
}
|
|
546
484
|
async getSubscription(idDto, em) {
|
|
547
485
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
548
|
-
this.openTelemetryCollector.info(
|
|
486
|
+
this.openTelemetryCollector.info("Getting subscription", idDto);
|
|
549
487
|
}
|
|
550
488
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
551
|
-
|
|
489
|
+
"Subscription",
|
|
552
490
|
idDto
|
|
553
491
|
);
|
|
554
|
-
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
492
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
493
|
+
subscription
|
|
494
|
+
);
|
|
555
495
|
}
|
|
556
496
|
async getUserSubscription({ id }, em) {
|
|
557
497
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
558
|
-
this.openTelemetryCollector.info(
|
|
498
|
+
this.openTelemetryCollector.info("Getting user subscription", id);
|
|
559
499
|
}
|
|
560
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
500
|
+
const subscription = await (em ?? this.em).findOneOrFail("Subscription", {
|
|
561
501
|
partyId: id,
|
|
562
|
-
partyType:
|
|
502
|
+
partyType: "USER",
|
|
563
503
|
active: true
|
|
564
504
|
});
|
|
565
|
-
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
505
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
506
|
+
subscription
|
|
507
|
+
);
|
|
566
508
|
}
|
|
567
509
|
async getOrganizationSubscription({ id }, em) {
|
|
568
510
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
569
|
-
this.openTelemetryCollector.info(
|
|
511
|
+
this.openTelemetryCollector.info("Getting organization subscription", id);
|
|
570
512
|
}
|
|
571
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
513
|
+
const subscription = await (em ?? this.em).findOneOrFail("Subscription", {
|
|
572
514
|
partyId: id,
|
|
573
|
-
partyType:
|
|
515
|
+
partyType: "ORGANIZATION",
|
|
574
516
|
active: true
|
|
575
517
|
});
|
|
576
|
-
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
518
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
519
|
+
subscription
|
|
520
|
+
);
|
|
577
521
|
}
|
|
578
522
|
async updateSubscription(subscriptionDto, em) {
|
|
579
523
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
580
524
|
this.openTelemetryCollector.info(
|
|
581
|
-
|
|
525
|
+
"Updating subscription",
|
|
582
526
|
subscriptionDto
|
|
583
527
|
);
|
|
584
528
|
}
|
|
585
|
-
const subscription =
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
);
|
|
529
|
+
const subscription = this._mappers.UpdateSubscriptionMapper.deserializeDtoToEntity(
|
|
530
|
+
subscriptionDto,
|
|
531
|
+
em ?? this.em
|
|
532
|
+
);
|
|
590
533
|
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
591
534
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
592
535
|
await innerEm.persist(updatedSubscription);
|
|
593
536
|
});
|
|
594
|
-
const updatedSubscriptionDto =
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
);
|
|
537
|
+
const updatedSubscriptionDto = await this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
538
|
+
updatedSubscription
|
|
539
|
+
);
|
|
598
540
|
return updatedSubscriptionDto;
|
|
599
541
|
}
|
|
600
542
|
async deleteSubscription(idDto, em) {
|
|
601
543
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
602
|
-
this.openTelemetryCollector.info(
|
|
544
|
+
this.openTelemetryCollector.info("Deleting subscription", idDto);
|
|
603
545
|
}
|
|
604
|
-
const subscription = await (em ?? this.em).findOne(
|
|
546
|
+
const subscription = await (em ?? this.em).findOne("Subscription", idDto);
|
|
605
547
|
if (!subscription) {
|
|
606
|
-
throw new Error(
|
|
548
|
+
throw new Error("Subscription not found");
|
|
607
549
|
}
|
|
608
550
|
await (em ?? this.em).removeAndFlush(subscription);
|
|
609
551
|
}
|
|
610
552
|
async listSubscriptions(idsDto, em) {
|
|
611
553
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
612
|
-
this.openTelemetryCollector.info(
|
|
613
|
-
}
|
|
614
|
-
const subscriptions = await (em ?? this.em).findAll(
|
|
615
|
-
where: idsDto.ids
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
621
|
-
: void 0
|
|
554
|
+
this.openTelemetryCollector.info("Listing subscriptions", idsDto);
|
|
555
|
+
}
|
|
556
|
+
const subscriptions = await (em ?? this.em).findAll("Subscription", {
|
|
557
|
+
where: idsDto.ids ? {
|
|
558
|
+
id: {
|
|
559
|
+
$in: idsDto.ids
|
|
560
|
+
}
|
|
561
|
+
} : void 0
|
|
622
562
|
});
|
|
623
563
|
return Promise.all(
|
|
624
564
|
subscriptions.map((subscription) => {
|
|
625
|
-
const subscriptionDto =
|
|
626
|
-
|
|
565
|
+
const subscriptionDto = this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
566
|
+
subscription
|
|
567
|
+
);
|
|
627
568
|
return subscriptionDto;
|
|
628
569
|
})
|
|
629
570
|
);
|
|
630
571
|
}
|
|
631
572
|
async cancelSubscription(idDto, em) {
|
|
632
573
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
633
|
-
this.openTelemetryCollector.info(
|
|
574
|
+
this.openTelemetryCollector.info("Canceling subscription", idDto);
|
|
634
575
|
}
|
|
635
|
-
const subscription = await (em ?? this.em).findOne(
|
|
576
|
+
const subscription = await (em ?? this.em).findOne("Subscription", idDto);
|
|
636
577
|
if (!subscription) {
|
|
637
|
-
throw new Error(
|
|
578
|
+
throw new Error("Subscription not found");
|
|
638
579
|
}
|
|
639
580
|
subscription.active = false;
|
|
640
581
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
@@ -643,11 +584,11 @@ var BaseSubscriptionService = class {
|
|
|
643
584
|
}
|
|
644
585
|
async resumeSubscription(idDto, em) {
|
|
645
586
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
646
|
-
this.openTelemetryCollector.info(
|
|
587
|
+
this.openTelemetryCollector.info("Resuming subscription", idDto);
|
|
647
588
|
}
|
|
648
|
-
const subscription = await (em ?? this.em).findOne(
|
|
589
|
+
const subscription = await (em ?? this.em).findOne("Subscription", idDto);
|
|
649
590
|
if (!subscription) {
|
|
650
|
-
throw new Error(
|
|
591
|
+
throw new Error("Subscription not found");
|
|
651
592
|
}
|
|
652
593
|
subscription.active = true;
|
|
653
594
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
@@ -656,11 +597,10 @@ var BaseSubscriptionService = class {
|
|
|
656
597
|
}
|
|
657
598
|
};
|
|
658
599
|
// Annotate the CommonJS export names for ESM import in node:
|
|
659
|
-
0 &&
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
});
|
|
600
|
+
0 && (module.exports = {
|
|
601
|
+
BaseBillingPortalService,
|
|
602
|
+
BaseCheckoutSessionService,
|
|
603
|
+
BasePaymentLinkService,
|
|
604
|
+
BasePlanService,
|
|
605
|
+
BaseSubscriptionService
|
|
606
|
+
});
|