multivendor-wallet 0.0.1
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 +21 -0
- package/dist/hooks/index.cjs +681 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.mts +7 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.js +678 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.cjs +2194 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +131 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +2173 -0
- package/dist/index.js.map +1 -0
- package/dist/store-BQ3whei-.d.mts +140 -0
- package/dist/store-BQ3whei-.d.ts +140 -0
- package/dist/typeorm/index.cjs +768 -0
- package/dist/typeorm/index.cjs.map +1 -0
- package/dist/typeorm/index.d.mts +79 -0
- package/dist/typeorm/index.d.ts +79 -0
- package/dist/typeorm/index.js +764 -0
- package/dist/typeorm/index.js.map +1 -0
- package/dist/types-CrJxUVwX.d.mts +224 -0
- package/dist/types-iNUEzUgo.d.ts +224 -0
- package/package.json +118 -0
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typeorm = require('typeorm');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
+
}
|
|
15
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
16
|
+
function _ts_metadata(k, v) {
|
|
17
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
18
|
+
}
|
|
19
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
20
|
+
function nowTimestamp() {
|
|
21
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
|
|
22
|
+
}
|
|
23
|
+
__name(nowTimestamp, "nowTimestamp");
|
|
24
|
+
var _WalletAccountEntity = class _WalletAccountEntity {
|
|
25
|
+
constructor() {
|
|
26
|
+
__publicField(this, "id");
|
|
27
|
+
__publicField(this, "ownerType");
|
|
28
|
+
__publicField(this, "ownerId");
|
|
29
|
+
__publicField(this, "currency");
|
|
30
|
+
__publicField(this, "availableBalance");
|
|
31
|
+
__publicField(this, "heldBalance");
|
|
32
|
+
__publicField(this, "createdBy");
|
|
33
|
+
__publicField(this, "createdDate");
|
|
34
|
+
__publicField(this, "modifiedBy");
|
|
35
|
+
__publicField(this, "modifiedDate");
|
|
36
|
+
}
|
|
37
|
+
setCreated() {
|
|
38
|
+
this.createdDate = nowTimestamp();
|
|
39
|
+
this.modifiedDate = nowTimestamp();
|
|
40
|
+
}
|
|
41
|
+
setModified() {
|
|
42
|
+
this.modifiedDate = nowTimestamp();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
__name(_WalletAccountEntity, "WalletAccountEntity");
|
|
46
|
+
exports.WalletAccountEntity = _WalletAccountEntity;
|
|
47
|
+
_ts_decorate([
|
|
48
|
+
typeorm.PrimaryGeneratedColumn({
|
|
49
|
+
name: "id"
|
|
50
|
+
}),
|
|
51
|
+
_ts_metadata("design:type", Number)
|
|
52
|
+
], exports.WalletAccountEntity.prototype, "id", void 0);
|
|
53
|
+
_ts_decorate([
|
|
54
|
+
typeorm.Column({
|
|
55
|
+
name: "owner_type",
|
|
56
|
+
length: 32
|
|
57
|
+
}),
|
|
58
|
+
_ts_metadata("design:type", String)
|
|
59
|
+
], exports.WalletAccountEntity.prototype, "ownerType", void 0);
|
|
60
|
+
_ts_decorate([
|
|
61
|
+
typeorm.Column({
|
|
62
|
+
name: "owner_id"
|
|
63
|
+
}),
|
|
64
|
+
_ts_metadata("design:type", Number)
|
|
65
|
+
], exports.WalletAccountEntity.prototype, "ownerId", void 0);
|
|
66
|
+
_ts_decorate([
|
|
67
|
+
typeorm.Column({
|
|
68
|
+
name: "currency",
|
|
69
|
+
length: 8,
|
|
70
|
+
default: "INR"
|
|
71
|
+
}),
|
|
72
|
+
_ts_metadata("design:type", String)
|
|
73
|
+
], exports.WalletAccountEntity.prototype, "currency", void 0);
|
|
74
|
+
_ts_decorate([
|
|
75
|
+
typeorm.Column({
|
|
76
|
+
name: "available_balance",
|
|
77
|
+
type: "bigint",
|
|
78
|
+
default: 0
|
|
79
|
+
}),
|
|
80
|
+
_ts_metadata("design:type", String)
|
|
81
|
+
], exports.WalletAccountEntity.prototype, "availableBalance", void 0);
|
|
82
|
+
_ts_decorate([
|
|
83
|
+
typeorm.Column({
|
|
84
|
+
name: "held_balance",
|
|
85
|
+
type: "bigint",
|
|
86
|
+
default: 0
|
|
87
|
+
}),
|
|
88
|
+
_ts_metadata("design:type", String)
|
|
89
|
+
], exports.WalletAccountEntity.prototype, "heldBalance", void 0);
|
|
90
|
+
_ts_decorate([
|
|
91
|
+
typeorm.Column({
|
|
92
|
+
name: "created_by",
|
|
93
|
+
nullable: true
|
|
94
|
+
}),
|
|
95
|
+
_ts_metadata("design:type", Number)
|
|
96
|
+
], exports.WalletAccountEntity.prototype, "createdBy", void 0);
|
|
97
|
+
_ts_decorate([
|
|
98
|
+
typeorm.Column({
|
|
99
|
+
name: "created_date",
|
|
100
|
+
nullable: true
|
|
101
|
+
}),
|
|
102
|
+
_ts_metadata("design:type", String)
|
|
103
|
+
], exports.WalletAccountEntity.prototype, "createdDate", void 0);
|
|
104
|
+
_ts_decorate([
|
|
105
|
+
typeorm.Column({
|
|
106
|
+
name: "modified_by",
|
|
107
|
+
nullable: true
|
|
108
|
+
}),
|
|
109
|
+
_ts_metadata("design:type", Number)
|
|
110
|
+
], exports.WalletAccountEntity.prototype, "modifiedBy", void 0);
|
|
111
|
+
_ts_decorate([
|
|
112
|
+
typeorm.Column({
|
|
113
|
+
name: "modified_date",
|
|
114
|
+
nullable: true
|
|
115
|
+
}),
|
|
116
|
+
_ts_metadata("design:type", String)
|
|
117
|
+
], exports.WalletAccountEntity.prototype, "modifiedDate", void 0);
|
|
118
|
+
_ts_decorate([
|
|
119
|
+
typeorm.BeforeInsert(),
|
|
120
|
+
_ts_metadata("design:type", Function),
|
|
121
|
+
_ts_metadata("design:paramtypes", []),
|
|
122
|
+
_ts_metadata("design:returntype", void 0)
|
|
123
|
+
], exports.WalletAccountEntity.prototype, "setCreated", null);
|
|
124
|
+
_ts_decorate([
|
|
125
|
+
typeorm.BeforeUpdate(),
|
|
126
|
+
_ts_metadata("design:type", Function),
|
|
127
|
+
_ts_metadata("design:paramtypes", []),
|
|
128
|
+
_ts_metadata("design:returntype", void 0)
|
|
129
|
+
], exports.WalletAccountEntity.prototype, "setModified", null);
|
|
130
|
+
exports.WalletAccountEntity = _ts_decorate([
|
|
131
|
+
typeorm.Entity("wallet_account")
|
|
132
|
+
], exports.WalletAccountEntity);
|
|
133
|
+
var _WalletLedgerEntryEntity = class _WalletLedgerEntryEntity {
|
|
134
|
+
constructor() {
|
|
135
|
+
__publicField(this, "id");
|
|
136
|
+
__publicField(this, "accountId");
|
|
137
|
+
__publicField(this, "entryType");
|
|
138
|
+
__publicField(this, "amount");
|
|
139
|
+
__publicField(this, "balanceAfterAvailable");
|
|
140
|
+
__publicField(this, "balanceAfterHeld");
|
|
141
|
+
__publicField(this, "idempotencyKey");
|
|
142
|
+
__publicField(this, "referenceType");
|
|
143
|
+
__publicField(this, "referenceId");
|
|
144
|
+
__publicField(this, "metadata");
|
|
145
|
+
__publicField(this, "createdBy");
|
|
146
|
+
__publicField(this, "createdDate");
|
|
147
|
+
__publicField(this, "modifiedBy");
|
|
148
|
+
__publicField(this, "modifiedDate");
|
|
149
|
+
}
|
|
150
|
+
setCreated() {
|
|
151
|
+
this.createdDate = nowTimestamp();
|
|
152
|
+
this.modifiedDate = nowTimestamp();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
__name(_WalletLedgerEntryEntity, "WalletLedgerEntryEntity");
|
|
156
|
+
exports.WalletLedgerEntryEntity = _WalletLedgerEntryEntity;
|
|
157
|
+
_ts_decorate([
|
|
158
|
+
typeorm.PrimaryGeneratedColumn({
|
|
159
|
+
name: "id"
|
|
160
|
+
}),
|
|
161
|
+
_ts_metadata("design:type", Number)
|
|
162
|
+
], exports.WalletLedgerEntryEntity.prototype, "id", void 0);
|
|
163
|
+
_ts_decorate([
|
|
164
|
+
typeorm.Column({
|
|
165
|
+
name: "account_id"
|
|
166
|
+
}),
|
|
167
|
+
_ts_metadata("design:type", Number)
|
|
168
|
+
], exports.WalletLedgerEntryEntity.prototype, "accountId", void 0);
|
|
169
|
+
_ts_decorate([
|
|
170
|
+
typeorm.Column({
|
|
171
|
+
name: "entry_type",
|
|
172
|
+
length: 32
|
|
173
|
+
}),
|
|
174
|
+
_ts_metadata("design:type", String)
|
|
175
|
+
], exports.WalletLedgerEntryEntity.prototype, "entryType", void 0);
|
|
176
|
+
_ts_decorate([
|
|
177
|
+
typeorm.Column({
|
|
178
|
+
name: "amount",
|
|
179
|
+
type: "bigint"
|
|
180
|
+
}),
|
|
181
|
+
_ts_metadata("design:type", String)
|
|
182
|
+
], exports.WalletLedgerEntryEntity.prototype, "amount", void 0);
|
|
183
|
+
_ts_decorate([
|
|
184
|
+
typeorm.Column({
|
|
185
|
+
name: "balance_after_available",
|
|
186
|
+
type: "bigint"
|
|
187
|
+
}),
|
|
188
|
+
_ts_metadata("design:type", String)
|
|
189
|
+
], exports.WalletLedgerEntryEntity.prototype, "balanceAfterAvailable", void 0);
|
|
190
|
+
_ts_decorate([
|
|
191
|
+
typeorm.Column({
|
|
192
|
+
name: "balance_after_held",
|
|
193
|
+
type: "bigint"
|
|
194
|
+
}),
|
|
195
|
+
_ts_metadata("design:type", String)
|
|
196
|
+
], exports.WalletLedgerEntryEntity.prototype, "balanceAfterHeld", void 0);
|
|
197
|
+
_ts_decorate([
|
|
198
|
+
typeorm.Column({
|
|
199
|
+
name: "idempotency_key",
|
|
200
|
+
length: 255,
|
|
201
|
+
unique: true
|
|
202
|
+
}),
|
|
203
|
+
_ts_metadata("design:type", String)
|
|
204
|
+
], exports.WalletLedgerEntryEntity.prototype, "idempotencyKey", void 0);
|
|
205
|
+
_ts_decorate([
|
|
206
|
+
typeorm.Column({
|
|
207
|
+
name: "reference_type",
|
|
208
|
+
length: 64,
|
|
209
|
+
nullable: true
|
|
210
|
+
}),
|
|
211
|
+
_ts_metadata("design:type", String)
|
|
212
|
+
], exports.WalletLedgerEntryEntity.prototype, "referenceType", void 0);
|
|
213
|
+
_ts_decorate([
|
|
214
|
+
typeorm.Column({
|
|
215
|
+
name: "reference_id",
|
|
216
|
+
length: 128,
|
|
217
|
+
nullable: true
|
|
218
|
+
}),
|
|
219
|
+
_ts_metadata("design:type", String)
|
|
220
|
+
], exports.WalletLedgerEntryEntity.prototype, "referenceId", void 0);
|
|
221
|
+
_ts_decorate([
|
|
222
|
+
typeorm.Column({
|
|
223
|
+
name: "metadata",
|
|
224
|
+
type: "json",
|
|
225
|
+
nullable: true
|
|
226
|
+
}),
|
|
227
|
+
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
228
|
+
], exports.WalletLedgerEntryEntity.prototype, "metadata", void 0);
|
|
229
|
+
_ts_decorate([
|
|
230
|
+
typeorm.Column({
|
|
231
|
+
name: "created_by",
|
|
232
|
+
nullable: true
|
|
233
|
+
}),
|
|
234
|
+
_ts_metadata("design:type", Number)
|
|
235
|
+
], exports.WalletLedgerEntryEntity.prototype, "createdBy", void 0);
|
|
236
|
+
_ts_decorate([
|
|
237
|
+
typeorm.Column({
|
|
238
|
+
name: "created_date",
|
|
239
|
+
nullable: true
|
|
240
|
+
}),
|
|
241
|
+
_ts_metadata("design:type", String)
|
|
242
|
+
], exports.WalletLedgerEntryEntity.prototype, "createdDate", void 0);
|
|
243
|
+
_ts_decorate([
|
|
244
|
+
typeorm.Column({
|
|
245
|
+
name: "modified_by",
|
|
246
|
+
nullable: true
|
|
247
|
+
}),
|
|
248
|
+
_ts_metadata("design:type", Number)
|
|
249
|
+
], exports.WalletLedgerEntryEntity.prototype, "modifiedBy", void 0);
|
|
250
|
+
_ts_decorate([
|
|
251
|
+
typeorm.Column({
|
|
252
|
+
name: "modified_date",
|
|
253
|
+
nullable: true
|
|
254
|
+
}),
|
|
255
|
+
_ts_metadata("design:type", String)
|
|
256
|
+
], exports.WalletLedgerEntryEntity.prototype, "modifiedDate", void 0);
|
|
257
|
+
_ts_decorate([
|
|
258
|
+
typeorm.BeforeInsert(),
|
|
259
|
+
_ts_metadata("design:type", Function),
|
|
260
|
+
_ts_metadata("design:paramtypes", []),
|
|
261
|
+
_ts_metadata("design:returntype", void 0)
|
|
262
|
+
], exports.WalletLedgerEntryEntity.prototype, "setCreated", null);
|
|
263
|
+
exports.WalletLedgerEntryEntity = _ts_decorate([
|
|
264
|
+
typeorm.Entity("wallet_ledger_entry")
|
|
265
|
+
], exports.WalletLedgerEntryEntity);
|
|
266
|
+
var _WalletHoldEntity = class _WalletHoldEntity {
|
|
267
|
+
constructor() {
|
|
268
|
+
__publicField(this, "id");
|
|
269
|
+
__publicField(this, "sourceAccountId");
|
|
270
|
+
__publicField(this, "targetAccountId");
|
|
271
|
+
__publicField(this, "amount");
|
|
272
|
+
__publicField(this, "status");
|
|
273
|
+
__publicField(this, "referenceType");
|
|
274
|
+
__publicField(this, "referenceId");
|
|
275
|
+
__publicField(this, "idempotencyKey");
|
|
276
|
+
__publicField(this, "createdBy");
|
|
277
|
+
__publicField(this, "createdDate");
|
|
278
|
+
__publicField(this, "modifiedBy");
|
|
279
|
+
__publicField(this, "modifiedDate");
|
|
280
|
+
}
|
|
281
|
+
setCreated() {
|
|
282
|
+
this.createdDate = nowTimestamp();
|
|
283
|
+
this.modifiedDate = nowTimestamp();
|
|
284
|
+
}
|
|
285
|
+
setModified() {
|
|
286
|
+
this.modifiedDate = nowTimestamp();
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
__name(_WalletHoldEntity, "WalletHoldEntity");
|
|
290
|
+
exports.WalletHoldEntity = _WalletHoldEntity;
|
|
291
|
+
_ts_decorate([
|
|
292
|
+
typeorm.PrimaryGeneratedColumn({
|
|
293
|
+
name: "id"
|
|
294
|
+
}),
|
|
295
|
+
_ts_metadata("design:type", Number)
|
|
296
|
+
], exports.WalletHoldEntity.prototype, "id", void 0);
|
|
297
|
+
_ts_decorate([
|
|
298
|
+
typeorm.Column({
|
|
299
|
+
name: "source_account_id"
|
|
300
|
+
}),
|
|
301
|
+
_ts_metadata("design:type", Number)
|
|
302
|
+
], exports.WalletHoldEntity.prototype, "sourceAccountId", void 0);
|
|
303
|
+
_ts_decorate([
|
|
304
|
+
typeorm.Column({
|
|
305
|
+
name: "target_account_id"
|
|
306
|
+
}),
|
|
307
|
+
_ts_metadata("design:type", Number)
|
|
308
|
+
], exports.WalletHoldEntity.prototype, "targetAccountId", void 0);
|
|
309
|
+
_ts_decorate([
|
|
310
|
+
typeorm.Column({
|
|
311
|
+
name: "amount",
|
|
312
|
+
type: "bigint"
|
|
313
|
+
}),
|
|
314
|
+
_ts_metadata("design:type", String)
|
|
315
|
+
], exports.WalletHoldEntity.prototype, "amount", void 0);
|
|
316
|
+
_ts_decorate([
|
|
317
|
+
typeorm.Column({
|
|
318
|
+
name: "status",
|
|
319
|
+
length: 16,
|
|
320
|
+
default: "active"
|
|
321
|
+
}),
|
|
322
|
+
_ts_metadata("design:type", String)
|
|
323
|
+
], exports.WalletHoldEntity.prototype, "status", void 0);
|
|
324
|
+
_ts_decorate([
|
|
325
|
+
typeorm.Column({
|
|
326
|
+
name: "reference_type",
|
|
327
|
+
length: 64
|
|
328
|
+
}),
|
|
329
|
+
_ts_metadata("design:type", String)
|
|
330
|
+
], exports.WalletHoldEntity.prototype, "referenceType", void 0);
|
|
331
|
+
_ts_decorate([
|
|
332
|
+
typeorm.Column({
|
|
333
|
+
name: "reference_id",
|
|
334
|
+
length: 128
|
|
335
|
+
}),
|
|
336
|
+
_ts_metadata("design:type", String)
|
|
337
|
+
], exports.WalletHoldEntity.prototype, "referenceId", void 0);
|
|
338
|
+
_ts_decorate([
|
|
339
|
+
typeorm.Column({
|
|
340
|
+
name: "idempotency_key",
|
|
341
|
+
length: 255
|
|
342
|
+
}),
|
|
343
|
+
_ts_metadata("design:type", String)
|
|
344
|
+
], exports.WalletHoldEntity.prototype, "idempotencyKey", void 0);
|
|
345
|
+
_ts_decorate([
|
|
346
|
+
typeorm.Column({
|
|
347
|
+
name: "created_by",
|
|
348
|
+
nullable: true
|
|
349
|
+
}),
|
|
350
|
+
_ts_metadata("design:type", Number)
|
|
351
|
+
], exports.WalletHoldEntity.prototype, "createdBy", void 0);
|
|
352
|
+
_ts_decorate([
|
|
353
|
+
typeorm.Column({
|
|
354
|
+
name: "created_date",
|
|
355
|
+
nullable: true
|
|
356
|
+
}),
|
|
357
|
+
_ts_metadata("design:type", String)
|
|
358
|
+
], exports.WalletHoldEntity.prototype, "createdDate", void 0);
|
|
359
|
+
_ts_decorate([
|
|
360
|
+
typeorm.Column({
|
|
361
|
+
name: "modified_by",
|
|
362
|
+
nullable: true
|
|
363
|
+
}),
|
|
364
|
+
_ts_metadata("design:type", Number)
|
|
365
|
+
], exports.WalletHoldEntity.prototype, "modifiedBy", void 0);
|
|
366
|
+
_ts_decorate([
|
|
367
|
+
typeorm.Column({
|
|
368
|
+
name: "modified_date",
|
|
369
|
+
nullable: true
|
|
370
|
+
}),
|
|
371
|
+
_ts_metadata("design:type", String)
|
|
372
|
+
], exports.WalletHoldEntity.prototype, "modifiedDate", void 0);
|
|
373
|
+
_ts_decorate([
|
|
374
|
+
typeorm.BeforeInsert(),
|
|
375
|
+
_ts_metadata("design:type", Function),
|
|
376
|
+
_ts_metadata("design:paramtypes", []),
|
|
377
|
+
_ts_metadata("design:returntype", void 0)
|
|
378
|
+
], exports.WalletHoldEntity.prototype, "setCreated", null);
|
|
379
|
+
_ts_decorate([
|
|
380
|
+
typeorm.BeforeUpdate(),
|
|
381
|
+
_ts_metadata("design:type", Function),
|
|
382
|
+
_ts_metadata("design:paramtypes", []),
|
|
383
|
+
_ts_metadata("design:returntype", void 0)
|
|
384
|
+
], exports.WalletHoldEntity.prototype, "setModified", null);
|
|
385
|
+
exports.WalletHoldEntity = _ts_decorate([
|
|
386
|
+
typeorm.Entity("wallet_hold")
|
|
387
|
+
], exports.WalletHoldEntity);
|
|
388
|
+
|
|
389
|
+
// src/errors.ts
|
|
390
|
+
var _WalletError = class _WalletError extends Error {
|
|
391
|
+
constructor(message) {
|
|
392
|
+
super(message);
|
|
393
|
+
this.name = "WalletError";
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
__name(_WalletError, "WalletError");
|
|
397
|
+
var WalletError = _WalletError;
|
|
398
|
+
var _DuplicateOperationError = class _DuplicateOperationError extends WalletError {
|
|
399
|
+
constructor(message, existingEntry) {
|
|
400
|
+
super(message);
|
|
401
|
+
__publicField(this, "existingEntry");
|
|
402
|
+
this.name = "DuplicateOperationError";
|
|
403
|
+
this.existingEntry = existingEntry;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
__name(_DuplicateOperationError, "DuplicateOperationError");
|
|
407
|
+
var DuplicateOperationError = _DuplicateOperationError;
|
|
408
|
+
|
|
409
|
+
// src/typeorm/store.ts
|
|
410
|
+
function toNumber(value) {
|
|
411
|
+
if (value == null) {
|
|
412
|
+
return 0;
|
|
413
|
+
}
|
|
414
|
+
return Number(value);
|
|
415
|
+
}
|
|
416
|
+
__name(toNumber, "toNumber");
|
|
417
|
+
function toLedgerAccount(row) {
|
|
418
|
+
return {
|
|
419
|
+
id: row.id,
|
|
420
|
+
ownerType: row.ownerType,
|
|
421
|
+
ownerId: row.ownerId,
|
|
422
|
+
currency: row.currency,
|
|
423
|
+
availableBalance: toNumber(row.availableBalance),
|
|
424
|
+
heldBalance: toNumber(row.heldBalance)
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
__name(toLedgerAccount, "toLedgerAccount");
|
|
428
|
+
function toLedgerHold(row) {
|
|
429
|
+
return {
|
|
430
|
+
id: row.id,
|
|
431
|
+
sourceAccountId: row.sourceAccountId,
|
|
432
|
+
targetAccountId: row.targetAccountId,
|
|
433
|
+
amount: toNumber(row.amount),
|
|
434
|
+
status: row.status,
|
|
435
|
+
referenceType: row.referenceType,
|
|
436
|
+
referenceId: row.referenceId,
|
|
437
|
+
idempotencyKey: row.idempotencyKey,
|
|
438
|
+
createdAt: new Date(row.createdDate)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
__name(toLedgerHold, "toLedgerHold");
|
|
442
|
+
function toLedgerEntry(row) {
|
|
443
|
+
return {
|
|
444
|
+
id: row.id,
|
|
445
|
+
accountId: row.accountId,
|
|
446
|
+
entryType: row.entryType,
|
|
447
|
+
amount: toNumber(row.amount),
|
|
448
|
+
balanceAfterAvailable: toNumber(row.balanceAfterAvailable),
|
|
449
|
+
balanceAfterHeld: toNumber(row.balanceAfterHeld),
|
|
450
|
+
idempotencyKey: row.idempotencyKey,
|
|
451
|
+
referenceType: row.referenceType,
|
|
452
|
+
referenceId: row.referenceId,
|
|
453
|
+
metadata: row.metadata,
|
|
454
|
+
createdAt: new Date(row.createdDate)
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
__name(toLedgerEntry, "toLedgerEntry");
|
|
458
|
+
function isEntityManager(value) {
|
|
459
|
+
return value != null && typeof value === "object" && typeof value.getRepository === "function";
|
|
460
|
+
}
|
|
461
|
+
__name(isEntityManager, "isEntityManager");
|
|
462
|
+
var _a;
|
|
463
|
+
var TypeOrmWalletStoreTx = (_a = class {
|
|
464
|
+
constructor(em) {
|
|
465
|
+
__publicField(this, "em");
|
|
466
|
+
this.em = em;
|
|
467
|
+
}
|
|
468
|
+
async getOrCreateAccount(type, ownerId, currency) {
|
|
469
|
+
const repo = this.em.getRepository(exports.WalletAccountEntity);
|
|
470
|
+
let row = await repo.findOne({
|
|
471
|
+
where: {
|
|
472
|
+
ownerType: type,
|
|
473
|
+
ownerId,
|
|
474
|
+
currency
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
if (!row) {
|
|
478
|
+
row = repo.create({
|
|
479
|
+
ownerType: type,
|
|
480
|
+
ownerId,
|
|
481
|
+
currency,
|
|
482
|
+
availableBalance: "0",
|
|
483
|
+
heldBalance: "0"
|
|
484
|
+
});
|
|
485
|
+
row = await repo.save(row);
|
|
486
|
+
}
|
|
487
|
+
return toLedgerAccount(row);
|
|
488
|
+
}
|
|
489
|
+
async lockAccount(accountId) {
|
|
490
|
+
const row = await this.em.getRepository(exports.WalletAccountEntity).createQueryBuilder("wa").setLock("pessimistic_write").where("wa.id = :id", {
|
|
491
|
+
id: accountId
|
|
492
|
+
}).getOne();
|
|
493
|
+
if (!row) {
|
|
494
|
+
throw new Error(`Wallet account ${accountId} not found`);
|
|
495
|
+
}
|
|
496
|
+
return toLedgerAccount(row);
|
|
497
|
+
}
|
|
498
|
+
async getAccountById(accountId) {
|
|
499
|
+
const row = await this.em.getRepository(exports.WalletAccountEntity).findOne({
|
|
500
|
+
where: {
|
|
501
|
+
id: accountId
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
return row ? toLedgerAccount(row) : null;
|
|
505
|
+
}
|
|
506
|
+
async appendLedgerEntry(entry) {
|
|
507
|
+
const existing = await this.findLedgerByIdempotencyKey(entry.idempotencyKey);
|
|
508
|
+
if (existing) {
|
|
509
|
+
return existing;
|
|
510
|
+
}
|
|
511
|
+
const repo = this.em.getRepository(exports.WalletLedgerEntryEntity);
|
|
512
|
+
try {
|
|
513
|
+
const row = await repo.save(repo.create({
|
|
514
|
+
accountId: entry.accountId,
|
|
515
|
+
entryType: entry.entryType,
|
|
516
|
+
amount: String(entry.amount),
|
|
517
|
+
balanceAfterAvailable: String(entry.balanceAfterAvailable),
|
|
518
|
+
balanceAfterHeld: String(entry.balanceAfterHeld),
|
|
519
|
+
idempotencyKey: entry.idempotencyKey,
|
|
520
|
+
referenceType: entry.referenceType,
|
|
521
|
+
referenceId: entry.referenceId,
|
|
522
|
+
metadata: entry.metadata
|
|
523
|
+
}));
|
|
524
|
+
return toLedgerEntry(row);
|
|
525
|
+
} catch (error) {
|
|
526
|
+
const err = error;
|
|
527
|
+
const code = err?.code || err?.errno;
|
|
528
|
+
if (code === "ER_DUP_ENTRY" || code === 1062) {
|
|
529
|
+
const dup = await this.findLedgerByIdempotencyKey(entry.idempotencyKey);
|
|
530
|
+
if (dup) {
|
|
531
|
+
return dup;
|
|
532
|
+
}
|
|
533
|
+
throw new DuplicateOperationError("Duplicate idempotency key", null);
|
|
534
|
+
}
|
|
535
|
+
throw error;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
async updateBalances(accountId, deltas) {
|
|
539
|
+
const row = await this.em.getRepository(exports.WalletAccountEntity).createQueryBuilder("wa").setLock("pessimistic_write").where("wa.id = :id", {
|
|
540
|
+
id: accountId
|
|
541
|
+
}).getOne();
|
|
542
|
+
if (!row) {
|
|
543
|
+
throw new Error(`Wallet account ${accountId} not found`);
|
|
544
|
+
}
|
|
545
|
+
const available = toNumber(row.availableBalance) + (deltas.availableDelta ?? 0);
|
|
546
|
+
const held = toNumber(row.heldBalance) + (deltas.heldDelta ?? 0);
|
|
547
|
+
if (available < 0 || held < 0) {
|
|
548
|
+
throw new Error("Balance cannot be negative");
|
|
549
|
+
}
|
|
550
|
+
row.availableBalance = String(available);
|
|
551
|
+
row.heldBalance = String(held);
|
|
552
|
+
const saved = await this.em.getRepository(exports.WalletAccountEntity).save(row);
|
|
553
|
+
return toLedgerAccount(saved);
|
|
554
|
+
}
|
|
555
|
+
async findHoldByReference(ref) {
|
|
556
|
+
const row = await this.em.getRepository(exports.WalletHoldEntity).findOne({
|
|
557
|
+
where: {
|
|
558
|
+
referenceType: ref.referenceType,
|
|
559
|
+
referenceId: ref.referenceId
|
|
560
|
+
},
|
|
561
|
+
order: {
|
|
562
|
+
id: "DESC"
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
return row ? toLedgerHold(row) : null;
|
|
566
|
+
}
|
|
567
|
+
async upsertHold(hold) {
|
|
568
|
+
const repo = this.em.getRepository(exports.WalletHoldEntity);
|
|
569
|
+
let row;
|
|
570
|
+
if (hold.id != null) {
|
|
571
|
+
row = await repo.findOne({
|
|
572
|
+
where: {
|
|
573
|
+
id: hold.id
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
if (!row) {
|
|
578
|
+
row = await repo.findOne({
|
|
579
|
+
where: {
|
|
580
|
+
referenceType: hold.referenceType,
|
|
581
|
+
referenceId: hold.referenceId
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
if (!row) {
|
|
586
|
+
row = repo.create({
|
|
587
|
+
sourceAccountId: hold.sourceAccountId,
|
|
588
|
+
targetAccountId: hold.targetAccountId,
|
|
589
|
+
amount: String(hold.amount),
|
|
590
|
+
status: hold.status,
|
|
591
|
+
referenceType: hold.referenceType,
|
|
592
|
+
referenceId: hold.referenceId,
|
|
593
|
+
idempotencyKey: hold.idempotencyKey
|
|
594
|
+
});
|
|
595
|
+
} else {
|
|
596
|
+
row.sourceAccountId = hold.sourceAccountId;
|
|
597
|
+
row.targetAccountId = hold.targetAccountId;
|
|
598
|
+
row.amount = String(hold.amount);
|
|
599
|
+
row.status = hold.status;
|
|
600
|
+
row.idempotencyKey = hold.idempotencyKey;
|
|
601
|
+
}
|
|
602
|
+
const saved = await repo.save(row);
|
|
603
|
+
return toLedgerHold(saved);
|
|
604
|
+
}
|
|
605
|
+
async findLedgerByIdempotencyKey(key) {
|
|
606
|
+
const row = await this.em.getRepository(exports.WalletLedgerEntryEntity).findOne({
|
|
607
|
+
where: {
|
|
608
|
+
idempotencyKey: key
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
return row ? toLedgerEntry(row) : null;
|
|
612
|
+
}
|
|
613
|
+
async listLedgerEntries(accountId, limit, offset) {
|
|
614
|
+
const rows = await this.em.getRepository(exports.WalletLedgerEntryEntity).find({
|
|
615
|
+
where: {
|
|
616
|
+
accountId
|
|
617
|
+
},
|
|
618
|
+
order: {
|
|
619
|
+
id: "DESC"
|
|
620
|
+
},
|
|
621
|
+
take: limit,
|
|
622
|
+
skip: offset
|
|
623
|
+
});
|
|
624
|
+
return rows.map(toLedgerEntry);
|
|
625
|
+
}
|
|
626
|
+
}, __name(_a, "TypeOrmWalletStoreTx"), _a);
|
|
627
|
+
var _TypeOrmWalletStore = class _TypeOrmWalletStore {
|
|
628
|
+
constructor(connection) {
|
|
629
|
+
__publicField(this, "connection");
|
|
630
|
+
this.connection = connection;
|
|
631
|
+
}
|
|
632
|
+
async runInTransaction(fn, ctx) {
|
|
633
|
+
if (isEntityManager(ctx?.nativeTx)) {
|
|
634
|
+
return fn(new TypeOrmWalletStoreTx(ctx.nativeTx));
|
|
635
|
+
}
|
|
636
|
+
return this.connection.manager.transaction(async (em) => fn(new TypeOrmWalletStoreTx(em)));
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
__name(_TypeOrmWalletStore, "TypeOrmWalletStore");
|
|
640
|
+
var TypeOrmWalletStore = _TypeOrmWalletStore;
|
|
641
|
+
|
|
642
|
+
// src/typeorm/migrations/CreateWalletTables.ts
|
|
643
|
+
async function indexExists(queryRunner, tableName, indexName) {
|
|
644
|
+
const rows = await queryRunner.query(`SELECT COUNT(1) AS c
|
|
645
|
+
FROM information_schema.statistics
|
|
646
|
+
WHERE table_schema = DATABASE()
|
|
647
|
+
AND table_name = ?
|
|
648
|
+
AND index_name = ?`, [
|
|
649
|
+
tableName,
|
|
650
|
+
indexName
|
|
651
|
+
]);
|
|
652
|
+
return Number(rows[0]?.c ?? 0) > 0;
|
|
653
|
+
}
|
|
654
|
+
__name(indexExists, "indexExists");
|
|
655
|
+
var _CreateWalletTables1790000000000 = class _CreateWalletTables1790000000000 {
|
|
656
|
+
async up(queryRunner) {
|
|
657
|
+
if (!await queryRunner.hasTable("wallet_account")) {
|
|
658
|
+
await queryRunner.query(`
|
|
659
|
+
CREATE TABLE \`wallet_account\` (
|
|
660
|
+
\`id\` int NOT NULL AUTO_INCREMENT,
|
|
661
|
+
\`owner_type\` varchar(32) NOT NULL,
|
|
662
|
+
\`owner_id\` int NOT NULL,
|
|
663
|
+
\`currency\` varchar(8) NOT NULL DEFAULT 'INR',
|
|
664
|
+
\`available_balance\` bigint NOT NULL DEFAULT 0,
|
|
665
|
+
\`held_balance\` bigint NOT NULL DEFAULT 0,
|
|
666
|
+
\`created_by\` int NULL,
|
|
667
|
+
\`created_date\` datetime NULL,
|
|
668
|
+
\`modified_by\` int NULL,
|
|
669
|
+
\`modified_date\` datetime NULL,
|
|
670
|
+
PRIMARY KEY (\`id\`)
|
|
671
|
+
) ENGINE=InnoDB
|
|
672
|
+
`);
|
|
673
|
+
}
|
|
674
|
+
if (!await indexExists(queryRunner, "wallet_account", "IDX_wallet_account_owner_currency")) {
|
|
675
|
+
await queryRunner.query(`
|
|
676
|
+
CREATE UNIQUE INDEX \`IDX_wallet_account_owner_currency\`
|
|
677
|
+
ON \`wallet_account\` (\`owner_type\`, \`owner_id\`, \`currency\`)
|
|
678
|
+
`);
|
|
679
|
+
}
|
|
680
|
+
if (!await queryRunner.hasTable("wallet_ledger_entry")) {
|
|
681
|
+
await queryRunner.query(`
|
|
682
|
+
CREATE TABLE \`wallet_ledger_entry\` (
|
|
683
|
+
\`id\` int NOT NULL AUTO_INCREMENT,
|
|
684
|
+
\`account_id\` int NOT NULL,
|
|
685
|
+
\`entry_type\` varchar(32) NOT NULL,
|
|
686
|
+
\`amount\` bigint NOT NULL,
|
|
687
|
+
\`balance_after_available\` bigint NOT NULL,
|
|
688
|
+
\`balance_after_held\` bigint NOT NULL,
|
|
689
|
+
\`idempotency_key\` varchar(255) NOT NULL,
|
|
690
|
+
\`reference_type\` varchar(64) NULL,
|
|
691
|
+
\`reference_id\` varchar(128) NULL,
|
|
692
|
+
\`metadata\` json NULL,
|
|
693
|
+
\`created_by\` int NULL,
|
|
694
|
+
\`created_date\` datetime NULL,
|
|
695
|
+
\`modified_by\` int NULL,
|
|
696
|
+
\`modified_date\` datetime NULL,
|
|
697
|
+
PRIMARY KEY (\`id\`),
|
|
698
|
+
UNIQUE INDEX \`UQ_wallet_ledger_idempotency_key\` (\`idempotency_key\`)
|
|
699
|
+
) ENGINE=InnoDB
|
|
700
|
+
`);
|
|
701
|
+
}
|
|
702
|
+
if (!await indexExists(queryRunner, "wallet_ledger_entry", "IDX_wallet_ledger_account_id")) {
|
|
703
|
+
await queryRunner.query(`
|
|
704
|
+
CREATE INDEX \`IDX_wallet_ledger_account_id\`
|
|
705
|
+
ON \`wallet_ledger_entry\` (\`account_id\`)
|
|
706
|
+
`);
|
|
707
|
+
}
|
|
708
|
+
if (!await queryRunner.hasTable("wallet_hold")) {
|
|
709
|
+
await queryRunner.query(`
|
|
710
|
+
CREATE TABLE \`wallet_hold\` (
|
|
711
|
+
\`id\` int NOT NULL AUTO_INCREMENT,
|
|
712
|
+
\`source_account_id\` int NOT NULL,
|
|
713
|
+
\`target_account_id\` int NOT NULL,
|
|
714
|
+
\`amount\` bigint NOT NULL,
|
|
715
|
+
\`status\` varchar(16) NOT NULL DEFAULT 'active',
|
|
716
|
+
\`reference_type\` varchar(64) NOT NULL,
|
|
717
|
+
\`reference_id\` varchar(128) NOT NULL,
|
|
718
|
+
\`idempotency_key\` varchar(255) NOT NULL,
|
|
719
|
+
\`created_by\` int NULL,
|
|
720
|
+
\`created_date\` datetime NULL,
|
|
721
|
+
\`modified_by\` int NULL,
|
|
722
|
+
\`modified_date\` datetime NULL,
|
|
723
|
+
PRIMARY KEY (\`id\`)
|
|
724
|
+
) ENGINE=InnoDB
|
|
725
|
+
`);
|
|
726
|
+
}
|
|
727
|
+
if (!await indexExists(queryRunner, "wallet_hold", "IDX_wallet_hold_reference")) {
|
|
728
|
+
await queryRunner.query(`
|
|
729
|
+
CREATE INDEX \`IDX_wallet_hold_reference\`
|
|
730
|
+
ON \`wallet_hold\` (\`reference_type\`, \`reference_id\`)
|
|
731
|
+
`);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
async down(queryRunner) {
|
|
735
|
+
if (await queryRunner.hasTable("wallet_hold")) {
|
|
736
|
+
await queryRunner.query("DROP TABLE `wallet_hold`");
|
|
737
|
+
}
|
|
738
|
+
if (await queryRunner.hasTable("wallet_ledger_entry")) {
|
|
739
|
+
await queryRunner.query("DROP TABLE `wallet_ledger_entry`");
|
|
740
|
+
}
|
|
741
|
+
if (await queryRunner.hasTable("wallet_account")) {
|
|
742
|
+
await queryRunner.query("DROP TABLE `wallet_account`");
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
__name(_CreateWalletTables1790000000000, "CreateWalletTables1790000000000");
|
|
747
|
+
var CreateWalletTables1790000000000 = _CreateWalletTables1790000000000;
|
|
748
|
+
|
|
749
|
+
// src/typeorm/metadata.ts
|
|
750
|
+
function getWalletOrmMetadata() {
|
|
751
|
+
return {
|
|
752
|
+
entities: [
|
|
753
|
+
exports.WalletAccountEntity,
|
|
754
|
+
exports.WalletLedgerEntryEntity,
|
|
755
|
+
exports.WalletHoldEntity
|
|
756
|
+
],
|
|
757
|
+
migrations: [
|
|
758
|
+
CreateWalletTables1790000000000
|
|
759
|
+
]
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
__name(getWalletOrmMetadata, "getWalletOrmMetadata");
|
|
763
|
+
|
|
764
|
+
exports.CreateWalletTables1790000000000 = CreateWalletTables1790000000000;
|
|
765
|
+
exports.TypeOrmWalletStore = TypeOrmWalletStore;
|
|
766
|
+
exports.getWalletOrmMetadata = getWalletOrmMetadata;
|
|
767
|
+
//# sourceMappingURL=index.cjs.map
|
|
768
|
+
//# sourceMappingURL=index.cjs.map
|