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