@misterhomer1992/miit-bot-payment 1.0.0 → 1.0.2
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 +262 -146
- package/dist/index.d.ts +2 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -18
- package/dist/index.js.map +1 -1
- package/dist/modules/app/types.d.ts +2 -0
- package/dist/modules/app/types.d.ts.map +1 -0
- package/dist/modules/app/types.js +3 -0
- package/dist/modules/app/types.js.map +1 -0
- package/dist/modules/cancellableAPI/utils.d.ts +17 -0
- package/dist/modules/cancellableAPI/utils.d.ts.map +1 -0
- package/dist/modules/cancellableAPI/utils.js +43 -0
- package/dist/modules/cancellableAPI/utils.js.map +1 -0
- package/dist/modules/invoice/const.d.ts +4 -0
- package/dist/modules/invoice/const.d.ts.map +1 -0
- package/dist/modules/invoice/const.js +8 -0
- package/dist/modules/invoice/const.js.map +1 -0
- package/dist/modules/invoice/index.d.ts +5 -0
- package/dist/modules/invoice/index.d.ts.map +1 -0
- package/dist/modules/invoice/index.js +21 -0
- package/dist/modules/invoice/index.js.map +1 -0
- package/dist/modules/invoice/repository.d.ts +34 -0
- package/dist/modules/invoice/repository.d.ts.map +1 -0
- package/dist/modules/invoice/repository.js +68 -0
- package/dist/modules/invoice/repository.js.map +1 -0
- package/dist/modules/invoice/service.d.ts +29 -0
- package/dist/modules/invoice/service.d.ts.map +1 -0
- package/dist/modules/invoice/service.js +61 -0
- package/dist/modules/invoice/service.js.map +1 -0
- package/dist/modules/invoice/types.d.ts +14 -0
- package/dist/modules/invoice/types.d.ts.map +1 -0
- package/dist/modules/invoice/types.js +3 -0
- package/dist/modules/invoice/types.js.map +1 -0
- package/dist/modules/logger/types.d.ts +8 -0
- package/dist/modules/logger/types.d.ts.map +1 -0
- package/dist/modules/logger/types.js +3 -0
- package/dist/modules/logger/types.js.map +1 -0
- package/dist/modules/network/utils.d.ts +9 -0
- package/dist/modules/network/utils.d.ts.map +1 -0
- package/dist/modules/network/utils.js +20 -0
- package/dist/modules/network/utils.js.map +1 -0
- package/dist/modules/payments/const.d.ts +4 -0
- package/dist/modules/payments/const.d.ts.map +1 -0
- package/dist/modules/payments/const.js +11 -0
- package/dist/modules/payments/const.js.map +1 -0
- package/dist/modules/payments/index.d.ts +5 -0
- package/dist/modules/payments/index.d.ts.map +1 -0
- package/dist/modules/payments/index.js +21 -0
- package/dist/modules/payments/index.js.map +1 -0
- package/dist/modules/payments/repository.d.ts +82 -0
- package/dist/modules/payments/repository.d.ts.map +1 -0
- package/dist/modules/payments/repository.js +153 -0
- package/dist/modules/payments/repository.js.map +1 -0
- package/dist/modules/payments/service.d.ts +65 -0
- package/dist/modules/payments/service.d.ts.map +1 -0
- package/dist/modules/payments/service.js +132 -0
- package/dist/modules/payments/service.js.map +1 -0
- package/dist/modules/payments/types.d.ts +31 -0
- package/dist/modules/payments/types.d.ts.map +1 -0
- package/dist/modules/payments/types.js +3 -0
- package/dist/modules/payments/types.js.map +1 -0
- package/dist/modules/user/userModel.d.ts +78 -0
- package/dist/modules/user/userModel.d.ts.map +1 -0
- package/dist/modules/user/userModel.js +3 -0
- package/dist/modules/user/userModel.js.map +1 -0
- package/dist/modules/user/userRepository.d.ts +22 -0
- package/dist/modules/user/userRepository.d.ts.map +1 -0
- package/dist/modules/user/userRepository.js +47 -0
- package/dist/modules/user/userRepository.js.map +1 -0
- package/dist/types/function.d.ts +3 -0
- package/dist/types/function.d.ts.map +1 -0
- package/dist/types/function.js +3 -0
- package/dist/types/function.js.map +1 -0
- package/dist/types/utilities.d.ts +10 -0
- package/dist/types/utilities.d.ts.map +1 -0
- package/dist/types/utilities.js +3 -0
- package/dist/types/utilities.js.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +45 -0
- package/dist/utils.js.map +1 -0
- package/package.json +55 -45
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentRepository = void 0;
|
|
4
|
+
const firestore_1 = require("firebase-admin/firestore");
|
|
5
|
+
const const_1 = require("./const");
|
|
6
|
+
/**
|
|
7
|
+
* PaymentRepository class handles all database operations related to payments.
|
|
8
|
+
* Implements repository pattern for payment data access.
|
|
9
|
+
*/
|
|
10
|
+
class PaymentRepository {
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of PaymentRepository.
|
|
13
|
+
*/
|
|
14
|
+
constructor() {
|
|
15
|
+
this.collectionName = 'payments';
|
|
16
|
+
this.db = (0, firestore_1.getFirestore)();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves a payment by its order reference.
|
|
20
|
+
* @param orderReference - The unique order reference identifier
|
|
21
|
+
* @returns Promise resolving to PaymentEntity or null if not found
|
|
22
|
+
*/
|
|
23
|
+
async getByOrderReference(orderReference) {
|
|
24
|
+
const querySnapshot = await this.db
|
|
25
|
+
.collection(this.collectionName)
|
|
26
|
+
.where('orderReference', '==', orderReference)
|
|
27
|
+
.limit(1)
|
|
28
|
+
.get();
|
|
29
|
+
if (querySnapshot.empty) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const doc = querySnapshot.docs[0];
|
|
33
|
+
return this.mapDocumentToEntity(doc);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves all payments for a specific user.
|
|
37
|
+
* @param params - Query parameters
|
|
38
|
+
* @param params.userId - The user's unique identifier
|
|
39
|
+
* @param params.appNamespace - The application namespace/platform
|
|
40
|
+
* @param params.status - Optional payment status filter
|
|
41
|
+
* @returns Promise resolving to array of PaymentEntity
|
|
42
|
+
*/
|
|
43
|
+
async getByUserId(params) {
|
|
44
|
+
const { userId, appNamespace, status } = params;
|
|
45
|
+
let query = this.db
|
|
46
|
+
.collection(this.collectionName)
|
|
47
|
+
.where('platform', '==', appNamespace)
|
|
48
|
+
.where('userId', '==', userId);
|
|
49
|
+
if (status) {
|
|
50
|
+
query = query.where('status', '==', status);
|
|
51
|
+
}
|
|
52
|
+
const querySnapshot = await query.get();
|
|
53
|
+
if (querySnapshot.empty) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
return querySnapshot.docs.map((doc) => this.mapDocumentToEntity(doc));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new payment record in the database.
|
|
60
|
+
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
61
|
+
* @returns Promise resolving to created PaymentEntity with ID
|
|
62
|
+
* @throws Error if payment creation fails
|
|
63
|
+
*/
|
|
64
|
+
async create(paymentData) {
|
|
65
|
+
const paymentEntity = {
|
|
66
|
+
...const_1.DEFAULT_PAYMENT_ENTITY,
|
|
67
|
+
...paymentData,
|
|
68
|
+
};
|
|
69
|
+
const docRef = await this.db.collection(this.collectionName).add(paymentEntity);
|
|
70
|
+
if (!docRef.id) {
|
|
71
|
+
throw new Error(`Failed to create payment for orderReference: ${paymentData.orderReference}`);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
id: docRef.id,
|
|
75
|
+
...paymentEntity,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Updates specific fields of a payment identified by order reference.
|
|
80
|
+
* @param params - Update parameters
|
|
81
|
+
* @param params.orderReference - The order reference to identify the payment
|
|
82
|
+
* @param params.fields - Array of field paths and values to update
|
|
83
|
+
* @throws Error if payment not found or update fails
|
|
84
|
+
*/
|
|
85
|
+
async updateFields(params) {
|
|
86
|
+
const { orderReference, fields } = params;
|
|
87
|
+
const updateObject = this.buildUpdateObject(fields);
|
|
88
|
+
const querySnapshot = await this.db
|
|
89
|
+
.collection(this.collectionName)
|
|
90
|
+
.where('orderReference', '==', orderReference)
|
|
91
|
+
.limit(1)
|
|
92
|
+
.get();
|
|
93
|
+
if (querySnapshot.empty) {
|
|
94
|
+
throw new Error(`Payment not found for orderReference: ${orderReference}`);
|
|
95
|
+
}
|
|
96
|
+
await querySnapshot.docs[0].ref.update(updateObject);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves all pending payments that are older than specified hours.
|
|
100
|
+
* Used for cleaning up expired payment attempts.
|
|
101
|
+
* @param params - Query parameters
|
|
102
|
+
* @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
|
|
103
|
+
* @returns Promise resolving to array of expired PaymentEntity
|
|
104
|
+
*/
|
|
105
|
+
async getExpiredPendingPayments(params = {}) {
|
|
106
|
+
const { hoursOld = 24 } = params;
|
|
107
|
+
const cutoffTime = this.calculateCutoffTime(hoursOld);
|
|
108
|
+
const querySnapshot = await this.db
|
|
109
|
+
.collection(this.collectionName)
|
|
110
|
+
.where('status', '==', 'pending')
|
|
111
|
+
.where('createdAt', '<', cutoffTime.toISOString())
|
|
112
|
+
.get();
|
|
113
|
+
if (querySnapshot.empty) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
return querySnapshot.docs.map((doc) => this.mapDocumentToEntity(doc));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Maps a Firestore document to a PaymentEntity.
|
|
120
|
+
* @param doc - Firestore document snapshot
|
|
121
|
+
* @returns PaymentEntity with document ID
|
|
122
|
+
*/
|
|
123
|
+
mapDocumentToEntity(doc) {
|
|
124
|
+
return {
|
|
125
|
+
id: doc.id,
|
|
126
|
+
...doc.data(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Builds an update object from field tuples.
|
|
131
|
+
* @param fields - Array of field paths and values
|
|
132
|
+
* @returns Object with field paths as keys and values to update
|
|
133
|
+
*/
|
|
134
|
+
buildUpdateObject(fields) {
|
|
135
|
+
const updateObject = {};
|
|
136
|
+
fields.forEach(([fieldPath, value]) => {
|
|
137
|
+
updateObject[fieldPath] = value;
|
|
138
|
+
});
|
|
139
|
+
return updateObject;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Calculates the cutoff time for expired payments.
|
|
143
|
+
* @param hoursOld - Number of hours to subtract from current time
|
|
144
|
+
* @returns Date object representing the cutoff time
|
|
145
|
+
*/
|
|
146
|
+
calculateCutoffTime(hoursOld) {
|
|
147
|
+
const cutoffTime = new Date();
|
|
148
|
+
cutoffTime.setHours(cutoffTime.getHours() - hoursOld);
|
|
149
|
+
return cutoffTime;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.PaymentRepository = PaymentRepository;
|
|
153
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/modules/payments/repository.ts"],"names":[],"mappings":";;;AAAA,wDAAsG;AAEtG,mCAAiD;AAKjD;;;GAGG;AACH,MAAa,iBAAiB;IAI1B;;OAEG;IACH;QALiB,mBAAc,GAAG,UAAU,CAAC;QAMzC,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,mBAAmB,CAAC,cAAsB;QACnD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,EAAE;aAC9B,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;aAC/B,KAAK,CAAC,gBAAgB,EAAE,IAAI,EAAE,cAAc,CAAC;aAC7C,KAAK,CAAC,CAAC,CAAC;aACR,GAAG,EAAE,CAAC;QAEX,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,WAAW,CAAC,MAIxB;QACG,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;Q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EAAE;SACC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACK,iBAAiB,CAAC,MAA6B;QACnD,MAAM,YAAY,GAAwB,EAAE,CAAC;QAE7C,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;YAClC,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,YAAY,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACK,mBAAmB,CAAC,QAAgB;QACxC,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC9B,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;QACtD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAnLD,8CAmLC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Logger } from '../logger/types';
|
|
2
|
+
import { UpdateDBPaymentFields } from './repository';
|
|
3
|
+
import { PaymentEntity } from './types';
|
|
4
|
+
import { AppNamespace } from '../app/types';
|
|
5
|
+
/**
|
|
6
|
+
* PaymentService class handles business logic related to payments.
|
|
7
|
+
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PaymentService {
|
|
10
|
+
private readonly logger;
|
|
11
|
+
private readonly repository;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of PaymentService.
|
|
14
|
+
* @param logger - Application logger instance for logging operations
|
|
15
|
+
*/
|
|
16
|
+
constructor(logger: Logger);
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves a payment by its order reference.
|
|
19
|
+
* @param orderReference - The unique order reference identifier
|
|
20
|
+
* @returns Promise resolving to PaymentEntity or null if not found
|
|
21
|
+
*/
|
|
22
|
+
getByOrderReference(orderReference: string): Promise<PaymentEntity | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves all payments for a specific user.
|
|
25
|
+
* @param params - Query parameters
|
|
26
|
+
* @param params.userId - The user's unique identifier
|
|
27
|
+
* @param params.appNamespace - The application namespace/platform
|
|
28
|
+
* @param params.status - Optional payment status filter
|
|
29
|
+
* @returns Promise resolving to array of PaymentEntity
|
|
30
|
+
*/
|
|
31
|
+
getByUserId(params: {
|
|
32
|
+
userId: string;
|
|
33
|
+
appNamespace: AppNamespace;
|
|
34
|
+
status?: PaymentEntity['status'];
|
|
35
|
+
}): Promise<PaymentEntity[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new payment record in the database.
|
|
38
|
+
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
39
|
+
* @returns Promise resolving to created PaymentEntity with ID
|
|
40
|
+
* @throws Error if payment creation fails
|
|
41
|
+
*/
|
|
42
|
+
create(paymentData: Omit<PaymentEntity, 'id'>): Promise<PaymentEntity>;
|
|
43
|
+
/**
|
|
44
|
+
* Updates specific fields of a payment identified by order reference.
|
|
45
|
+
* @param params - Update parameters
|
|
46
|
+
* @param params.orderReference - The order reference to identify the payment
|
|
47
|
+
* @param params.fields - Array of field paths and values to update
|
|
48
|
+
* @throws Error if payment not found or update fails
|
|
49
|
+
*/
|
|
50
|
+
updateFields(params: {
|
|
51
|
+
orderReference: string;
|
|
52
|
+
fields: UpdateDBPaymentFields;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves all pending payments that are older than specified hours.
|
|
56
|
+
* Used for cleaning up expired payment attempts.
|
|
57
|
+
* @param params - Query parameters
|
|
58
|
+
* @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
|
|
59
|
+
* @returns Promise resolving to array of expired PaymentEntity
|
|
60
|
+
*/
|
|
61
|
+
getExpiredPendingPayments(params?: {
|
|
62
|
+
hoursOld?: number;
|
|
63
|
+
}): Promise<PaymentEntity[]>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAqB,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAE/C;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAK1B;;;;OAIG;IACU,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAevF;;;;;;;OAOG;IACU,WAAW,CAAC,MAAM,EAAE;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAiB5B;;;;;OAKG;IACU,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBnF;;;;;;OAMG;IACU,YAAY,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,qBAAqB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB3G;;;;;;OAMG;IACU,yBAAyB,CAClC,MAAM,GAAE;QACJ,QAAQ,CAAC,EAAE,MAAM,CAAC;KAChB,GACP,OAAO,CAAC,aAAa,EAAE,CAAC;CAc9B"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentService = void 0;
|
|
4
|
+
const repository_1 = require("./repository");
|
|
5
|
+
/**
|
|
6
|
+
* PaymentService class handles business logic related to payments.
|
|
7
|
+
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
8
|
+
*/
|
|
9
|
+
class PaymentService {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of PaymentService.
|
|
12
|
+
* @param logger - Application logger instance for logging operations
|
|
13
|
+
*/
|
|
14
|
+
constructor(logger) {
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.repository = new repository_1.PaymentRepository();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves a payment by its order reference.
|
|
20
|
+
* @param orderReference - The unique order reference identifier
|
|
21
|
+
* @returns Promise resolving to PaymentEntity or null if not found
|
|
22
|
+
*/
|
|
23
|
+
async getByOrderReference(orderReference) {
|
|
24
|
+
try {
|
|
25
|
+
return await this.repository.getByOrderReference(orderReference);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
this.logger.error({
|
|
29
|
+
message: 'Error in payment service getByOrderReference',
|
|
30
|
+
payload: {
|
|
31
|
+
orderReference,
|
|
32
|
+
error: JSON.stringify(error),
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves all payments for a specific user.
|
|
40
|
+
* @param params - Query parameters
|
|
41
|
+
* @param params.userId - The user's unique identifier
|
|
42
|
+
* @param params.appNamespace - The application namespace/platform
|
|
43
|
+
* @param params.status - Optional payment status filter
|
|
44
|
+
* @returns Promise resolving to array of PaymentEntity
|
|
45
|
+
*/
|
|
46
|
+
async getByUserId(params) {
|
|
47
|
+
try {
|
|
48
|
+
return await this.repository.getByUserId(params);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
this.logger.error({
|
|
52
|
+
message: 'Error in payment service getByUserId',
|
|
53
|
+
payload: {
|
|
54
|
+
userId: params.userId,
|
|
55
|
+
appNamespace: params.appNamespace,
|
|
56
|
+
status: params.status,
|
|
57
|
+
error: JSON.stringify(error),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new payment record in the database.
|
|
65
|
+
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
66
|
+
* @returns Promise resolving to created PaymentEntity with ID
|
|
67
|
+
* @throws Error if payment creation fails
|
|
68
|
+
*/
|
|
69
|
+
async create(paymentData) {
|
|
70
|
+
try {
|
|
71
|
+
return await this.repository.create(paymentData);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
this.logger.error({
|
|
75
|
+
message: 'Error in payment service create',
|
|
76
|
+
payload: {
|
|
77
|
+
orderReference: paymentData.orderReference,
|
|
78
|
+
userId: paymentData.userId,
|
|
79
|
+
error: JSON.stringify(error),
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Updates specific fields of a payment identified by order reference.
|
|
87
|
+
* @param params - Update parameters
|
|
88
|
+
* @param params.orderReference - The order reference to identify the payment
|
|
89
|
+
* @param params.fields - Array of field paths and values to update
|
|
90
|
+
* @throws Error if payment not found or update fails
|
|
91
|
+
*/
|
|
92
|
+
async updateFields(params) {
|
|
93
|
+
try {
|
|
94
|
+
await this.repository.updateFields(params);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
this.logger.error({
|
|
98
|
+
message: 'Error in payment service updateFields',
|
|
99
|
+
payload: {
|
|
100
|
+
orderReference: params.orderReference,
|
|
101
|
+
fields: JSON.stringify(params.fields),
|
|
102
|
+
error: JSON.stringify(error),
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves all pending payments that are older than specified hours.
|
|
110
|
+
* Used for cleaning up expired payment attempts.
|
|
111
|
+
* @param params - Query parameters
|
|
112
|
+
* @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
|
|
113
|
+
* @returns Promise resolving to array of expired PaymentEntity
|
|
114
|
+
*/
|
|
115
|
+
async getExpiredPendingPayments(params = {}) {
|
|
116
|
+
try {
|
|
117
|
+
return await this.repository.getExpiredPendingPayments(params);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
this.logger.error({
|
|
121
|
+
message: 'Error in payment service getExpiredPendingPayments',
|
|
122
|
+
payload: {
|
|
123
|
+
hoursOld: params.hoursOld,
|
|
124
|
+
error: JSON.stringify(error),
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.PaymentService = PaymentService;
|
|
132
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":";;;AACA,6CAAwE;AAIxE;;;GAGG;AACH,MAAa,cAAc;IAIvB;;;OAGG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,8BAAiB,EAAE,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,mBAAmB,CAAC,cAAsB;QACnD,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACrE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,8CAA8C;gBACvD,OAAO,EAAE;oBACL,cAAc;oBACd,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAA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EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,uCAAuC;gBAChD,OAAO,EAAE;oBACL,cAAc,EAAE,MAAM,CAAC,cAAc;oBACrC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;oBACrC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,yBAAyB,CAClC,SAEI,EAAE;QAEN,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;QACnE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,oDAAoD;gBAC7D,OAAO,EAAE;oBACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YACH,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;CACJ;AAtID,wCAsIC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
+
import { AppNamespace } from '../app/types';
|
|
3
|
+
type PaymentEntity = {
|
|
4
|
+
/** Auto-generated unique ID (document ID) */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** The unique ID you generate and send to Wayforpay. This is the key to match incoming webhooks to a payment attempt. */
|
|
7
|
+
orderReference: string;
|
|
8
|
+
/** The ID of the user initiating the payment */
|
|
9
|
+
userId: string;
|
|
10
|
+
/** The state of this payment attempt */
|
|
11
|
+
status: 'pending' | 'completed' | 'failed' | 'expired';
|
|
12
|
+
/** The URL from Wayforpay that is sent to the user */
|
|
13
|
+
paymentLink: string;
|
|
14
|
+
/** The plan the user is attempting to purchase */
|
|
15
|
+
planId: string;
|
|
16
|
+
/** The amount to be charged */
|
|
17
|
+
amount: number;
|
|
18
|
+
/** Currency of the payment */
|
|
19
|
+
currency: 'UAH' | 'USD';
|
|
20
|
+
/** When this payment attempt was created */
|
|
21
|
+
createdAt: string;
|
|
22
|
+
/** Optional. The ID of the corresponding document in the invoices collection, added after the webhook is processed */
|
|
23
|
+
invoiceId?: string;
|
|
24
|
+
/** Platform/app namespace */
|
|
25
|
+
platform: AppNamespace;
|
|
26
|
+
/** Payment provider */
|
|
27
|
+
provider: 'wayforpay';
|
|
28
|
+
};
|
|
29
|
+
type PaymentFieldPath = NestedPathsAccess<PaymentEntity>;
|
|
30
|
+
export type { PaymentEntity, PaymentFieldPath };
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,KAAK,aAAa,GAAG;IACjB,6CAA6C;IAC7C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yHAAyH;IACzH,cAAc,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACvD,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,sHAAsH;IACtH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,QAAQ,EAAE,YAAY,CAAC;IACvB,uBAAuB;IACvB,QAAQ,EAAE,WAAW,CAAC;CACzB,CAAC;AAEF,KAAK,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAEzD,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/payments/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
+
import { AppNamespace } from '../app/types';
|
|
3
|
+
export interface User {
|
|
4
|
+
user: {
|
|
5
|
+
id: string;
|
|
6
|
+
lastUpdate: null | string;
|
|
7
|
+
name: null | string;
|
|
8
|
+
};
|
|
9
|
+
subscription: {
|
|
10
|
+
isActive: boolean;
|
|
11
|
+
isTrial: boolean;
|
|
12
|
+
payments?: {
|
|
13
|
+
planId: string;
|
|
14
|
+
orderReference: string;
|
|
15
|
+
url: string;
|
|
16
|
+
createdDate: string;
|
|
17
|
+
}[];
|
|
18
|
+
paymentUrlMessageId?: number;
|
|
19
|
+
};
|
|
20
|
+
personality?: string;
|
|
21
|
+
messages: Record<string, Record<string, unknown>>;
|
|
22
|
+
commands?: Record<string, unknown>;
|
|
23
|
+
keyboardContext?: Record<string, unknown>;
|
|
24
|
+
settings: {
|
|
25
|
+
voiceResponse: boolean;
|
|
26
|
+
languageCode: string;
|
|
27
|
+
activeMessageThread: string;
|
|
28
|
+
requestCount: number;
|
|
29
|
+
imageAutoDetection: boolean;
|
|
30
|
+
imageResolution: string;
|
|
31
|
+
activeKeyboardMessageId?: number;
|
|
32
|
+
hasFakeImage?: boolean;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface UserAnalytics {
|
|
36
|
+
id: string;
|
|
37
|
+
platform: AppNamespace;
|
|
38
|
+
createdDate: string;
|
|
39
|
+
chatGPT: {
|
|
40
|
+
completions: Partial<Record<number, {
|
|
41
|
+
requestTokensCount: number;
|
|
42
|
+
responseTokensCount: number;
|
|
43
|
+
}>>;
|
|
44
|
+
image: {
|
|
45
|
+
create?: {
|
|
46
|
+
'11': {
|
|
47
|
+
count: number;
|
|
48
|
+
inputImageTokens: number;
|
|
49
|
+
outputImageTokens: number;
|
|
50
|
+
inputTextTokens: number;
|
|
51
|
+
};
|
|
52
|
+
'12': {
|
|
53
|
+
count: number;
|
|
54
|
+
};
|
|
55
|
+
'18': {
|
|
56
|
+
count: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
vision: Partial<Record<number, {
|
|
60
|
+
requestTokensCount: number;
|
|
61
|
+
responseTokensCount: number;
|
|
62
|
+
}>>;
|
|
63
|
+
};
|
|
64
|
+
speechToText: {
|
|
65
|
+
'whisper-1': {
|
|
66
|
+
seconds: number;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
textToSpeech: {
|
|
70
|
+
'tts-1': {
|
|
71
|
+
charsCount: number;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export type UserFieldPath = NestedPathsAccess<User>;
|
|
77
|
+
export type UserFieldAnalyticsPath = NestedPathsAccess<UserAnalytics>;
|
|
78
|
+
//# sourceMappingURL=userModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userModel.d.ts","sourceRoot":"","sources":["../../../src/modules/user/userModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,IAAI;IACjB,IAAI,EAAE;QACF,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;QAC1B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F,KAAK,EAAE,MAAM,CAAC;oBACd,gBAAgB,EAAE,MAAM,CAAC;oBACzB,iBAAiB,EAAE,MAAM,CAAC;oBAC1B,eAAe,EAAE,MAAM,CAAC;iBAC3B,CAAC;gBACF,IAAI,EAAE;oBACF,KAAK,EAAE,MAAM,CAAC;iBACjB,CAAC;gBACF,IAAI,EAAE;oBACF,KAAK,EAAE,MAAM,CAAC;iBACjB,CAAC;aACL,CAAC;YACF,MAAM,EAAE,OAAO,CACX,MAAM,CACF,MAAM,EACN;gBACI,kBAAkB,EAAE,MAAM,CAAC;gBAC3B,mBAAmB,EAAE,MAAM,CAAC;aAC/B,CACJ,CACJ,CAAC;SACL,CAAC;QACF,YAAY,EAAE;YACV,WAAW,EAAE;gBACT,OAAO,EAAE,MAAM,CAAC;aACnB,CAAC;SACL,CAAC;QACF,YAAY,EAAE;YACV,OAAO,EAAE;gBACL,UAAU,EAAE,MAAM,CAAC;aACtB,CAAC;SACL,CAAC;KACL,CAAC;CACL;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAEpD,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userModel.js","sourceRoot":"","sources":["../../../src/modules/user/userModel.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FieldValue } from 'firebase-admin/firestore';
|
|
2
|
+
import { User, UserFieldAnalyticsPath, UserFieldPath } from './userModel';
|
|
3
|
+
import { AppNamespace } from '../app/types';
|
|
4
|
+
export type PushDBUserAnalyticsFields = [
|
|
5
|
+
UserFieldAnalyticsPath,
|
|
6
|
+
FieldValue | string | number | boolean | Date | [] | object
|
|
7
|
+
][];
|
|
8
|
+
declare function getDBUser({ userId, appNamespace }: {
|
|
9
|
+
userId: string;
|
|
10
|
+
appNamespace: string;
|
|
11
|
+
}): Promise<User | null>;
|
|
12
|
+
declare function addDBUser({ appNamespace, user }: {
|
|
13
|
+
user: User;
|
|
14
|
+
appNamespace: string;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
declare function updateDBUser({ appNamespace, userId, fields, }: {
|
|
17
|
+
appNamespace: AppNamespace;
|
|
18
|
+
userId: string;
|
|
19
|
+
fields: [UserFieldPath, FieldValue | string | number | boolean | Date | [] | {}][];
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
export { getDBUser, addDBUser, updateDBUser };
|
|
22
|
+
//# sourceMappingURL=userRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRepository.d.ts","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgB,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,MAAM,yBAAyB,GAAG;IACpC,sBAAsB;IACtB,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,MAAM;CAC9D,EAAE,CAAC;AAEJ,iBAAe,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAiBjH;AAED,iBAAe,SAAS,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,iBAQpF;AAED,iBAAe,YAAY,CAAC,EACxB,YAAY,EACZ,MAAM,EACN,MAAM,GACT,EAAE;IACC,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CAAC,aAAa,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;CACtF,iBAqBA;AAED,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDBUser = getDBUser;
|
|
4
|
+
exports.addDBUser = addDBUser;
|
|
5
|
+
exports.updateDBUser = updateDBUser;
|
|
6
|
+
const firestore_1 = require("firebase-admin/firestore");
|
|
7
|
+
async function getDBUser({ userId, appNamespace }) {
|
|
8
|
+
const db = (0, firestore_1.getFirestore)();
|
|
9
|
+
try {
|
|
10
|
+
const querySnapshot = await db.collection(`platform/${appNamespace}/users`).doc(userId).get();
|
|
11
|
+
if (!querySnapshot.exists) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return querySnapshot.data();
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.log({
|
|
18
|
+
gerUserError: e,
|
|
19
|
+
});
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function addDBUser({ appNamespace, user }) {
|
|
24
|
+
const db = (0, firestore_1.getFirestore)();
|
|
25
|
+
const result = await db.collection(`platform/${appNamespace}/users`).doc(user.user.id).set(user);
|
|
26
|
+
if (!result) {
|
|
27
|
+
throw new Error(`Failed to add user, ${JSON.stringify(user)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function updateDBUser({ appNamespace, userId, fields, }) {
|
|
31
|
+
const db = (0, firestore_1.getFirestore)();
|
|
32
|
+
let updateObject = {};
|
|
33
|
+
fields
|
|
34
|
+
.filter((f) => Array.isArray(f))
|
|
35
|
+
.forEach((f) => {
|
|
36
|
+
updateObject[f[0]] = f[1];
|
|
37
|
+
});
|
|
38
|
+
const snapshot = await db.collection(`platform/${appNamespace}/users`).doc(userId).get();
|
|
39
|
+
if (!snapshot.exists) {
|
|
40
|
+
throw new Error('User not found');
|
|
41
|
+
}
|
|
42
|
+
const result = await snapshot.ref.update(updateObject);
|
|
43
|
+
if (!result) {
|
|
44
|
+
throw new Error(`Failed to update user, ${JSON.stringify(updateObject)}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=userRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRepository.js","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":";;AAqES,8BAAS;AAAE,8BAAS;AAAE,oCAAY;AArE3C,wDAAoE;AASpE,KAAK,UAAU,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAA4C;IACvF,MAAM,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;IAE1B,IAAI,CAAC;QACD,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,YAAY,YAAY,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAE9F,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,aAAa,CAAC,IAAI,EAAU,CAAC;IACxC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,GAAG,CAAC;YACR,YAAY,EAAE,CAAC;SAClB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,EAAE,YAAY,EAAE,IAAI,EAAwC;IACjF,MAAM,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;IAE1B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,YAAY,YAAY,QAAQ,CAAC,CAAC,GAAG,CAAC,I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AAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE/C,MAAM,MAAM,QAAQ,CAAC,EAAE,SAAS,QAAQ,GAAG,QAAQ,EAAE,CAAC,SAAS,GAAG,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,IAAI,CACrF,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,KACd,UAAU,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/types/function.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type NonFunctionPropertyNames<T> = {
|
|
2
|
+
[K in keyof T]: T[K] extends Function ? never : K;
|
|
3
|
+
}[keyof T];
|
|
4
|
+
export type Primitive = string | number | boolean;
|
|
5
|
+
export type IsArray<T> = T extends Array<any> ? true : false;
|
|
6
|
+
export type NestedPathsAccess<T, Prev extends string = ''> = T extends Primitive ? never : T extends Array<infer U> ? U extends Primitive ? `${Prev}[${number}]` : `${Prev}[${number}]` | NestedPathsAccess<U, `${Prev}[${number}].`> : {
|
|
7
|
+
[K in NonFunctionPropertyNames<T> & string]: T[K] extends Primitive ? `${Prev}${K}` : IsArray<T[K]> extends true ? `${Prev}${K}` | NestedPathsAccess<T[K], `${Prev}${K}`> : `${Prev}${K}` | NestedPathsAccess<T[K], `${Prev}${K}.`>;
|
|
8
|
+
}[NonFunctionPropertyNames<T> & string];
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/types/utilities.ts"],"names":[],"mappings":"AAAA,KAAK,wBAAwB,CAAC,CAAC,IAAI;KAE9B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC;CACpD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAE7D,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,SAAS,GAC1E,KAAK,GACL,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtB,CAAC,SAAS,SAAS,GACf,GAAG,IAAI,IAAI,MAAM,GAAG,GACpB,GAAG,IAAI,IAAI,MAAM,GAAG,GAAG,iBAAiB,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,MAAM,IAAI,CAAC,GACtE;KACK,CAAC,IAAI,wBAAwB,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GAC7D,GAAG,IAAI,GAAG,CAAC,EAAE,GACb,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACxB,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,GACtD,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC;CAClE,CAAC,wBAAwB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../src/types/utilities.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare function getGoogleServiceAccount(): any;
|
|
2
|
+
declare function isUndefined(val: unknown): val is undefined;
|
|
3
|
+
declare function isNull(val: unknown): val is null;
|
|
4
|
+
declare function isNullOrUndefined(val: unknown): val is null;
|
|
5
|
+
declare function isNumber(val: unknown): val is number;
|
|
6
|
+
declare function isObject(val: unknown): val is object;
|
|
7
|
+
declare function isError(val: unknown): val is Error;
|
|
8
|
+
declare function isBadOrEmptyString(val: unknown): boolean;
|
|
9
|
+
export { getGoogleServiceAccount, isUndefined, isNull, isNullOrUndefined, isNumber, isObject, isError, isBadOrEmptyString, };
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA,iBAAS,uBAAuB,QAE/B;AAED,iBAAS,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAEnD;AAED,iBAAS,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,IAAI,CAEzC;AAED,iBAAS,iBAAiB,CAAC,GAAG,EAAE,OAAO,eAEtC;AAED,iBAAS,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAE7C;AAED,iBAAS,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAE7C;AAED,iBAAS,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,KAAK,CAE3C;AAED,iBAAS,kBAAkB,CAAC,GAAG,EAAE,OAAO,WAMvC;AAED,OAAO,EACH,uBAAuB,EACvB,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,kBAAkB,GACrB,CAAC"}
|