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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/typeorm/entities.ts","../../src/errors.ts","../../src/typeorm/store.ts","../../src/typeorm/migrations/CreateWalletTables.ts","../../src/typeorm/metadata.ts"],"names":["nowTimestamp","Date","toISOString","slice","replace","WalletAccountEntity","id","ownerType","ownerId","currency","availableBalance","heldBalance","createdBy","createdDate","modifiedBy","modifiedDate","setCreated","setModified","name","length","default","type","nullable","WalletLedgerEntryEntity","accountId","entryType","amount","balanceAfterAvailable","balanceAfterHeld","idempotencyKey","referenceType","referenceId","metadata","unique","WalletHoldEntity","sourceAccountId","targetAccountId","status","WalletError","Error","message","DuplicateOperationError","existingEntry","toNumber","value","Number","toLedgerAccount","row","toLedgerHold","createdAt","toLedgerEntry","isEntityManager","getRepository","TypeOrmWalletStoreTx","em","getOrCreateAccount","repo","findOne","where","create","save","lockAccount","createQueryBuilder","setLock","getOne","getAccountById","appendLedgerEntry","entry","existing","findLedgerByIdempotencyKey","String","error","err","code","errno","dup","updateBalances","deltas","available","availableDelta","held","heldDelta","saved","findHoldByReference","ref","order","upsertHold","hold","key","listLedgerEntries","limit","offset","rows","find","take","skip","map","TypeOrmWalletStore","connection","runInTransaction","fn","ctx","nativeTx","manager","transaction","indexExists","queryRunner","tableName","indexName","query","c","CreateWalletTables1790000000000","up","hasTable","down","getWalletOrmMetadata","entities","migrations"],"mappings":";;;;;;;;;;;;;;;;;AAEA,SAASA,YAAAA,GAAAA;AACP,EAAA,OAAA,iBAAO,IAAIC,IAAAA,EAAAA,EAAOC,WAAAA,EAAW,CAAGC,KAAAA,CAAM,CAAA,EAAG,EAAA,CAAA,CAAIC,OAAAA,CAAQ,GAAA,EAAK,GAAA,CAAA;AAC5D;AAFSJ,MAAAA,CAAAA,YAAAA,EAAAA,cAAAA,CAAAA;AAKF,IAAMK,oBAAAA,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CAAM;;;;;;;;;;;;;;;;AAgBvB,MAAA,CAAA,CAAA;AACH,IAAA;AAEA,IAAA,IAAI,CAAE,MAAMJ,WAAAA,CAAYC,WAAAA,EAAa,aAAA,EAAe,2BAAA,CAAA,EAA+B;AACjF,MAAA,MAAMA,YAAYG,KAAAA,CAAM;;;AAGvB,MAAA,CAAA,CAAA;AACH,IAAA;AACF,EAAA;AAEA,EAAA,MAAaK,KAAKR,WAAAA,EAAyC;AACzD,IAAA,IAAI,MAAMA,WAAAA,CAAYO,QAAAA,CAAS,aAAA,CAAA,EAAgB;AAC7C,MAAA,MAAMP,WAAAA,CAAYG,MAAM,0BAAA,CAAA;AAC1B,IAAA;AACA,IAAA,IAAI,MAAMH,WAAAA,CAAYO,QAAAA,CAAS,qBAAA,CAAA,EAAwB;AACrD,MAAA,MAAMP,WAAAA,CAAYG,MAAM,kCAAA,CAAA;AAC1B,IAAA;AACA,IAAA,IAAI,MAAMH,WAAAA,CAAYO,QAAAA,CAAS,gBAAA,CAAA,EAAmB;AAChD,MAAA,MAAMP,WAAAA,CAAYG,MAAM,6BAAA,CAAA;AAC1B,IAAA;AACF,EAAA;AACF,CAAA;AAhGaE,MAAAA,CAAAA,gCAAAA,EAAAA,iCAAAA,CAAAA;AAAN,IAAMA,+BAAAA,GAAN;;;ACXA,SAASI,oBAAAA,GAAAA;AAId,EAAA,OAAO;IACLC,QAAAA,EAAU;AAAC/G,MAAAA,mBAAAA;AAAqBkB,MAAAA,uBAAAA;AAAyBW,MAAAA;;IACzDmF,UAAAA,EAAY;AAACN,MAAAA;;AACf,GAAA;AACF;AARgBI,MAAAA,CAAAA,oBAAAA,EAAAA,sBAAAA,CAAAA","file":"index.js","sourcesContent":["import { BeforeInsert, BeforeUpdate, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';\n\nfunction nowTimestamp(): string {\n return new Date().toISOString().slice(0, 19).replace('T', ' ');\n}\n\n@Entity('wallet_account')\nexport class WalletAccountEntity {\n @PrimaryGeneratedColumn({ name: 'id' })\n public id!: number;\n\n @Column({ name: 'owner_type', length: 32 })\n public ownerType!: string;\n\n @Column({ name: 'owner_id' })\n public ownerId!: number;\n\n @Column({ name: 'currency', length: 8, default: 'INR' })\n public currency!: string;\n\n @Column({ name: 'available_balance', type: 'bigint', default: 0 })\n public availableBalance!: string;\n\n @Column({ name: 'held_balance', type: 'bigint', default: 0 })\n public heldBalance!: string;\n\n @Column({ name: 'created_by', nullable: true })\n public createdBy?: number;\n\n @Column({ name: 'created_date', nullable: true })\n public createdDate!: string;\n\n @Column({ name: 'modified_by', nullable: true })\n public modifiedBy?: number;\n\n @Column({ name: 'modified_date', nullable: true })\n public modifiedDate!: string;\n\n @BeforeInsert()\n public setCreated(): void {\n this.createdDate = nowTimestamp();\n this.modifiedDate = nowTimestamp();\n }\n\n @BeforeUpdate()\n public setModified(): void {\n this.modifiedDate = nowTimestamp();\n }\n}\n\n@Entity('wallet_ledger_entry')\nexport class WalletLedgerEntryEntity {\n @PrimaryGeneratedColumn({ name: 'id' })\n public id!: number;\n\n @Column({ name: 'account_id' })\n public accountId!: number;\n\n @Column({ name: 'entry_type', length: 32 })\n public entryType!: string;\n\n @Column({ name: 'amount', type: 'bigint' })\n public amount!: string;\n\n @Column({ name: 'balance_after_available', type: 'bigint' })\n public balanceAfterAvailable!: string;\n\n @Column({ name: 'balance_after_held', type: 'bigint' })\n public balanceAfterHeld!: string;\n\n @Column({ name: 'idempotency_key', length: 255, unique: true })\n public idempotencyKey!: string;\n\n @Column({ name: 'reference_type', length: 64, nullable: true })\n public referenceType?: string;\n\n @Column({ name: 'reference_id', length: 128, nullable: true })\n public referenceId?: string;\n\n @Column({ name: 'metadata', type: 'json', nullable: true })\n public metadata?: Record<string, unknown>;\n\n @Column({ name: 'created_by', nullable: true })\n public createdBy?: number;\n\n @Column({ name: 'created_date', nullable: true })\n public createdDate!: string;\n\n @Column({ name: 'modified_by', nullable: true })\n public modifiedBy?: number;\n\n @Column({ name: 'modified_date', nullable: true })\n public modifiedDate!: string;\n\n @BeforeInsert()\n public setCreated(): void {\n this.createdDate = nowTimestamp();\n this.modifiedDate = nowTimestamp();\n }\n}\n\n@Entity('wallet_hold')\nexport class WalletHoldEntity {\n @PrimaryGeneratedColumn({ name: 'id' })\n public id!: number;\n\n @Column({ name: 'source_account_id' })\n public sourceAccountId!: number;\n\n @Column({ name: 'target_account_id' })\n public targetAccountId!: number;\n\n @Column({ name: 'amount', type: 'bigint' })\n public amount!: string;\n\n @Column({ name: 'status', length: 16, default: 'active' })\n public status!: string;\n\n @Column({ name: 'reference_type', length: 64 })\n public referenceType!: string;\n\n @Column({ name: 'reference_id', length: 128 })\n public referenceId!: string;\n\n @Column({ name: 'idempotency_key', length: 255 })\n public idempotencyKey!: string;\n\n @Column({ name: 'created_by', nullable: true })\n public createdBy?: number;\n\n @Column({ name: 'created_date', nullable: true })\n public createdDate!: string;\n\n @Column({ name: 'modified_by', nullable: true })\n public modifiedBy?: number;\n\n @Column({ name: 'modified_date', nullable: true })\n public modifiedDate!: string;\n\n @BeforeInsert()\n public setCreated(): void {\n this.createdDate = nowTimestamp();\n this.modifiedDate = nowTimestamp();\n }\n\n @BeforeUpdate()\n public setModified(): void {\n this.modifiedDate = nowTimestamp();\n }\n}\n","export class WalletError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'WalletError';\n }\n}\n\nexport class WalletConfigError extends WalletError {\n constructor(message: string) {\n super(message);\n this.name = 'WalletConfigError';\n }\n}\n\nexport class InsufficientBalanceError extends WalletError {\n constructor(message: string = 'Insufficient available balance') {\n super(message);\n this.name = 'InsufficientBalanceError';\n }\n}\n\nexport class HoldNotFoundError extends WalletError {\n constructor(message: string = 'Active hold not found for reference') {\n super(message);\n this.name = 'HoldNotFoundError';\n }\n}\n\nexport class DuplicateOperationError extends WalletError {\n public readonly existingEntry: unknown;\n\n constructor(message: string, existingEntry: unknown) {\n super(message);\n this.name = 'DuplicateOperationError';\n this.existingEntry = existingEntry;\n }\n}\n\nexport class InvalidAmountError extends WalletError {\n constructor(message: string = 'Amount must be a positive integer in minor units') {\n super(message);\n this.name = 'InvalidAmountError';\n }\n}\n","import type { EntityManager } from 'typeorm';\nimport { DuplicateOperationError } from '../errors';\nimport type { WalletHostConnection } from '../plugin-instance';\nimport type { IWalletStore, IWalletStoreTx, WalletStoreContext } from '../store';\nimport {\n HoldStatus,\n LedgerEntryType,\n type BalanceDeltas,\n type WalletAccount,\n type WalletAccountType,\n type WalletHold,\n type WalletLedgerEntry,\n type WalletReference,\n} from '../types';\nimport {\n WalletAccountEntity,\n WalletHoldEntity,\n WalletLedgerEntryEntity,\n} from './entities';\n\nfunction toNumber(value: string | number | null | undefined): number {\n if (value == null) {\n return 0;\n }\n return Number(value);\n}\n\nfunction toLedgerAccount(row: WalletAccountEntity): WalletAccount {\n return {\n id: row.id,\n ownerType: row.ownerType as WalletAccountType,\n ownerId: row.ownerId,\n currency: row.currency,\n availableBalance: toNumber(row.availableBalance),\n heldBalance: toNumber(row.heldBalance),\n };\n}\n\nfunction toLedgerHold(row: WalletHoldEntity): WalletHold {\n return {\n id: row.id,\n sourceAccountId: row.sourceAccountId,\n targetAccountId: row.targetAccountId,\n amount: toNumber(row.amount),\n status: row.status as HoldStatus,\n referenceType: row.referenceType,\n referenceId: row.referenceId,\n idempotencyKey: row.idempotencyKey,\n createdAt: new Date(row.createdDate),\n };\n}\n\nfunction toLedgerEntry(row: WalletLedgerEntryEntity): WalletLedgerEntry {\n return {\n id: row.id,\n accountId: row.accountId,\n entryType: row.entryType as LedgerEntryType,\n amount: toNumber(row.amount),\n balanceAfterAvailable: toNumber(row.balanceAfterAvailable),\n balanceAfterHeld: toNumber(row.balanceAfterHeld),\n idempotencyKey: row.idempotencyKey,\n referenceType: row.referenceType,\n referenceId: row.referenceId,\n metadata: row.metadata,\n createdAt: new Date(row.createdDate),\n };\n}\n\nfunction isEntityManager(value: unknown): value is EntityManager {\n return (\n value != null &&\n typeof value === 'object' &&\n typeof (value as EntityManager).getRepository === 'function'\n );\n}\n\nclass TypeOrmWalletStoreTx implements IWalletStoreTx {\n constructor(private readonly em: EntityManager) {}\n\n public async getOrCreateAccount(\n type: WalletAccountType,\n ownerId: number,\n currency: string\n ): Promise<WalletAccount> {\n const repo = this.em.getRepository(WalletAccountEntity);\n let row = await repo.findOne({ where: { ownerType: type, ownerId, currency } });\n if (!row) {\n row = repo.create({\n ownerType: type,\n ownerId,\n currency,\n availableBalance: '0',\n heldBalance: '0',\n });\n row = await repo.save(row);\n }\n return toLedgerAccount(row);\n }\n\n public async lockAccount(accountId: number): Promise<WalletAccount> {\n const row = await this.em\n .getRepository(WalletAccountEntity)\n .createQueryBuilder('wa')\n .setLock('pessimistic_write')\n .where('wa.id = :id', { id: accountId })\n .getOne();\n if (!row) {\n throw new Error(`Wallet account ${accountId} not found`);\n }\n return toLedgerAccount(row);\n }\n\n public async getAccountById(accountId: number): Promise<WalletAccount | null> {\n const row = await this.em.getRepository(WalletAccountEntity).findOne({ where: { id: accountId } });\n return row ? toLedgerAccount(row) : null;\n }\n\n public async appendLedgerEntry(\n entry: Omit<WalletLedgerEntry, 'id' | 'createdAt'>\n ): Promise<WalletLedgerEntry> {\n const existing = await this.findLedgerByIdempotencyKey(entry.idempotencyKey);\n if (existing) {\n return existing;\n }\n\n const repo = this.em.getRepository(WalletLedgerEntryEntity);\n try {\n const row = await repo.save(\n repo.create({\n accountId: entry.accountId,\n entryType: entry.entryType,\n amount: String(entry.amount),\n balanceAfterAvailable: String(entry.balanceAfterAvailable),\n balanceAfterHeld: String(entry.balanceAfterHeld),\n idempotencyKey: entry.idempotencyKey,\n referenceType: entry.referenceType,\n referenceId: entry.referenceId,\n metadata: entry.metadata,\n })\n );\n return toLedgerEntry(row);\n } catch (error: unknown) {\n const err = error as { code?: string | number; errno?: string | number };\n const code = err?.code || err?.errno;\n if (code === 'ER_DUP_ENTRY' || code === 1062) {\n const dup = await this.findLedgerByIdempotencyKey(entry.idempotencyKey);\n if (dup) {\n return dup;\n }\n throw new DuplicateOperationError('Duplicate idempotency key', null);\n }\n throw error;\n }\n }\n\n public async updateBalances(accountId: number, deltas: BalanceDeltas): Promise<WalletAccount> {\n const row = await this.em\n .getRepository(WalletAccountEntity)\n .createQueryBuilder('wa')\n .setLock('pessimistic_write')\n .where('wa.id = :id', { id: accountId })\n .getOne();\n if (!row) {\n throw new Error(`Wallet account ${accountId} not found`);\n }\n\n const available = toNumber(row.availableBalance) + (deltas.availableDelta ?? 0);\n const held = toNumber(row.heldBalance) + (deltas.heldDelta ?? 0);\n if (available < 0 || held < 0) {\n throw new Error('Balance cannot be negative');\n }\n\n row.availableBalance = String(available);\n row.heldBalance = String(held);\n const saved = await this.em.getRepository(WalletAccountEntity).save(row);\n return toLedgerAccount(saved);\n }\n\n public async findHoldByReference(ref: WalletReference): Promise<WalletHold | null> {\n const row = await this.em.getRepository(WalletHoldEntity).findOne({\n where: { referenceType: ref.referenceType, referenceId: ref.referenceId },\n order: { id: 'DESC' },\n });\n return row ? toLedgerHold(row) : null;\n }\n\n public async upsertHold(\n hold: Omit<WalletHold, 'id' | 'createdAt'> & { id?: number }\n ): Promise<WalletHold> {\n const repo = this.em.getRepository(WalletHoldEntity);\n let row: WalletHoldEntity | undefined;\n if (hold.id != null) {\n row = await repo.findOne({ where: { id: hold.id } });\n }\n if (!row) {\n row = await repo.findOne({\n where: { referenceType: hold.referenceType, referenceId: hold.referenceId },\n });\n }\n if (!row) {\n row = repo.create({\n sourceAccountId: hold.sourceAccountId,\n targetAccountId: hold.targetAccountId,\n amount: String(hold.amount),\n status: hold.status,\n referenceType: hold.referenceType,\n referenceId: hold.referenceId,\n idempotencyKey: hold.idempotencyKey,\n });\n } else {\n row.sourceAccountId = hold.sourceAccountId;\n row.targetAccountId = hold.targetAccountId;\n row.amount = String(hold.amount);\n row.status = hold.status;\n row.idempotencyKey = hold.idempotencyKey;\n }\n const saved = await repo.save(row);\n return toLedgerHold(saved);\n }\n\n public async findLedgerByIdempotencyKey(key: string): Promise<WalletLedgerEntry | null> {\n const row = await this.em.getRepository(WalletLedgerEntryEntity).findOne({\n where: { idempotencyKey: key },\n });\n return row ? toLedgerEntry(row) : null;\n }\n\n public async listLedgerEntries(\n accountId: number,\n limit: number,\n offset: number\n ): Promise<WalletLedgerEntry[]> {\n const rows = await this.em.getRepository(WalletLedgerEntryEntity).find({\n where: { accountId },\n order: { id: 'DESC' },\n take: limit,\n skip: offset,\n });\n return rows.map(toLedgerEntry);\n }\n}\n\nexport class TypeOrmWalletStore implements IWalletStore {\n constructor(private readonly connection: WalletHostConnection) {}\n\n public async runInTransaction<T>(\n fn: (tx: IWalletStoreTx) => Promise<T>,\n ctx?: WalletStoreContext\n ): Promise<T> {\n if (isEntityManager(ctx?.nativeTx)) {\n return fn(new TypeOrmWalletStoreTx(ctx.nativeTx));\n }\n\n return this.connection.manager.transaction(async (em) =>\n fn(new TypeOrmWalletStoreTx(em as EntityManager))\n );\n }\n}\n","import { MigrationInterface, QueryRunner } from 'typeorm';\n\nasync function indexExists(\n queryRunner: QueryRunner,\n tableName: string,\n indexName: string\n): Promise<boolean> {\n const rows: Array<{ c: number }> = await queryRunner.query(\n `SELECT COUNT(1) AS c\n FROM information_schema.statistics\n WHERE table_schema = DATABASE()\n AND table_name = ?\n AND index_name = ?`,\n [tableName, indexName]\n );\n return Number(rows[0]?.c ?? 0) > 0;\n}\n\nexport class CreateWalletTables1790000000000 implements MigrationInterface {\n public async up(queryRunner: QueryRunner): Promise<void> {\n if (!(await queryRunner.hasTable('wallet_account'))) {\n await queryRunner.query(`\n CREATE TABLE \\`wallet_account\\` (\n \\`id\\` int NOT NULL AUTO_INCREMENT,\n \\`owner_type\\` varchar(32) NOT NULL,\n \\`owner_id\\` int NOT NULL,\n \\`currency\\` varchar(8) NOT NULL DEFAULT 'INR',\n \\`available_balance\\` bigint NOT NULL DEFAULT 0,\n \\`held_balance\\` bigint NOT NULL DEFAULT 0,\n \\`created_by\\` int NULL,\n \\`created_date\\` datetime NULL,\n \\`modified_by\\` int NULL,\n \\`modified_date\\` datetime NULL,\n PRIMARY KEY (\\`id\\`)\n ) ENGINE=InnoDB\n `);\n }\n\n if (!(await indexExists(queryRunner, 'wallet_account', 'IDX_wallet_account_owner_currency'))) {\n await queryRunner.query(`\n CREATE UNIQUE INDEX \\`IDX_wallet_account_owner_currency\\`\n ON \\`wallet_account\\` (\\`owner_type\\`, \\`owner_id\\`, \\`currency\\`)\n `);\n }\n\n if (!(await queryRunner.hasTable('wallet_ledger_entry'))) {\n await queryRunner.query(`\n CREATE TABLE \\`wallet_ledger_entry\\` (\n \\`id\\` int NOT NULL AUTO_INCREMENT,\n \\`account_id\\` int NOT NULL,\n \\`entry_type\\` varchar(32) NOT NULL,\n \\`amount\\` bigint NOT NULL,\n \\`balance_after_available\\` bigint NOT NULL,\n \\`balance_after_held\\` bigint NOT NULL,\n \\`idempotency_key\\` varchar(255) NOT NULL,\n \\`reference_type\\` varchar(64) NULL,\n \\`reference_id\\` varchar(128) NULL,\n \\`metadata\\` json NULL,\n \\`created_by\\` int NULL,\n \\`created_date\\` datetime NULL,\n \\`modified_by\\` int NULL,\n \\`modified_date\\` datetime NULL,\n PRIMARY KEY (\\`id\\`),\n UNIQUE INDEX \\`UQ_wallet_ledger_idempotency_key\\` (\\`idempotency_key\\`)\n ) ENGINE=InnoDB\n `);\n }\n\n if (!(await indexExists(queryRunner, 'wallet_ledger_entry', 'IDX_wallet_ledger_account_id'))) {\n await queryRunner.query(`\n CREATE INDEX \\`IDX_wallet_ledger_account_id\\`\n ON \\`wallet_ledger_entry\\` (\\`account_id\\`)\n `);\n }\n\n if (!(await queryRunner.hasTable('wallet_hold'))) {\n await queryRunner.query(`\n CREATE TABLE \\`wallet_hold\\` (\n \\`id\\` int NOT NULL AUTO_INCREMENT,\n \\`source_account_id\\` int NOT NULL,\n \\`target_account_id\\` int NOT NULL,\n \\`amount\\` bigint NOT NULL,\n \\`status\\` varchar(16) NOT NULL DEFAULT 'active',\n \\`reference_type\\` varchar(64) NOT NULL,\n \\`reference_id\\` varchar(128) NOT NULL,\n \\`idempotency_key\\` varchar(255) NOT NULL,\n \\`created_by\\` int NULL,\n \\`created_date\\` datetime NULL,\n \\`modified_by\\` int NULL,\n \\`modified_date\\` datetime NULL,\n PRIMARY KEY (\\`id\\`)\n ) ENGINE=InnoDB\n `);\n }\n\n if (!(await indexExists(queryRunner, 'wallet_hold', 'IDX_wallet_hold_reference'))) {\n await queryRunner.query(`\n CREATE INDEX \\`IDX_wallet_hold_reference\\`\n ON \\`wallet_hold\\` (\\`reference_type\\`, \\`reference_id\\`)\n `);\n }\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n if (await queryRunner.hasTable('wallet_hold')) {\n await queryRunner.query('DROP TABLE `wallet_hold`');\n }\n if (await queryRunner.hasTable('wallet_ledger_entry')) {\n await queryRunner.query('DROP TABLE `wallet_ledger_entry`');\n }\n if (await queryRunner.hasTable('wallet_account')) {\n await queryRunner.query('DROP TABLE `wallet_account`');\n }\n }\n}\n","import {\n WalletAccountEntity,\n WalletHoldEntity,\n WalletLedgerEntryEntity,\n} from './entities';\nimport { CreateWalletTables1790000000000 } from './migrations/CreateWalletTables';\n\nexport function getWalletOrmMetadata(): {\n entities: Function[];\n migrations: Function[];\n} {\n return {\n entities: [WalletAccountEntity, WalletLedgerEntryEntity, WalletHoldEntity],\n migrations: [CreateWalletTables1790000000000],\n };\n}\n"]}
@@ -0,0 +1,224 @@
1
+ import { I as IWalletStore, W as WalletAccountType, a as WalletStoreContext, b as WalletAccount, c as WalletBalance, C as CreditParams, L as LedgerMutationResult, D as DebitParams, H as HoldParams, R as ReleaseParams, d as CancelHoldParams, T as TransferParams, G as GetTransactionsParams, e as WalletLedgerEntry } from './store-BQ3whei-.mjs';
2
+
3
+ interface WalletConfig {
4
+ /** Default currency when not specified (e.g. INR). */
5
+ defaultCurrency?: string;
6
+ /** Platform wallet owner id in the host system. */
7
+ platformOwnerId?: number;
8
+ }
9
+
10
+ declare class WalletLedgerClient {
11
+ private readonly store;
12
+ private readonly config;
13
+ constructor(store: IWalletStore, config?: WalletConfig);
14
+ getOrCreateAccount(type: WalletAccountType, ownerId: number, currency?: string, ctx?: WalletStoreContext): Promise<WalletAccount>;
15
+ getBalance(accountId: number, ctx?: WalletStoreContext): Promise<WalletBalance>;
16
+ credit(params: CreditParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
17
+ debit(params: DebitParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
18
+ hold(params: HoldParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
19
+ release(params: ReleaseParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
20
+ cancelHold(params: CancelHoldParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
21
+ transfer(params: TransferParams, ctx?: WalletStoreContext): Promise<{
22
+ debit: LedgerMutationResult;
23
+ credit: LedgerMutationResult;
24
+ }>;
25
+ getTransactions(params: GetTransactionsParams, ctx?: WalletStoreContext): Promise<WalletLedgerEntry[]>;
26
+ private creditInTx;
27
+ private debitInTx;
28
+ private holdInTx;
29
+ private releaseInTx;
30
+ private cancelHoldInTx;
31
+ private toBalance;
32
+ private assertPositiveAmount;
33
+ private requireActiveHold;
34
+ }
35
+
36
+ declare const PaymentProviderWallet: "wallet";
37
+ interface CreatePaymentInput {
38
+ orderId: number;
39
+ amount: number;
40
+ currency: string;
41
+ metadata?: Record<string, string>;
42
+ }
43
+ interface PaymentResult {
44
+ providerPaymentId: string;
45
+ provider: typeof PaymentProviderWallet;
46
+ raw: unknown;
47
+ }
48
+ interface PaymentStatusResult {
49
+ providerPaymentId: string;
50
+ status: string;
51
+ amount: number;
52
+ currency: string;
53
+ provider: typeof PaymentProviderWallet;
54
+ raw: unknown;
55
+ }
56
+ interface RefundInput {
57
+ providerPaymentId: string;
58
+ amount?: number;
59
+ }
60
+ interface RefundResult {
61
+ providerRefundId: string;
62
+ status: string;
63
+ amount: number;
64
+ currency: string;
65
+ provider: typeof PaymentProviderWallet;
66
+ raw: unknown;
67
+ }
68
+ interface WebhookVerificationResult {
69
+ isValid: boolean;
70
+ event?: unknown;
71
+ }
72
+ interface IWalletPaymentProvider {
73
+ readonly provider: typeof PaymentProviderWallet;
74
+ getPublicCredential(): string | null;
75
+ createPayment(input: CreatePaymentInput): Promise<PaymentResult>;
76
+ verifyPayment(providerPaymentId: string, ...args: unknown[]): Promise<PaymentStatusResult>;
77
+ fetchPaymentStatus(providerPaymentId: string): Promise<PaymentStatusResult>;
78
+ resolveProviderPaymentId(orderId: number): Promise<string | null>;
79
+ createRefund(input: RefundInput): Promise<RefundResult>;
80
+ verifyWebhook(payload: string | Buffer, signature: string): WebhookVerificationResult;
81
+ }
82
+
83
+ interface WalletParityDelta {
84
+ orderId: number;
85
+ vendorOrderId: number;
86
+ vendorPaymentRupees: number;
87
+ holdPaise: number;
88
+ deltaRupees: number;
89
+ }
90
+ interface WalletCacheMismatch {
91
+ accountId: number;
92
+ cachedAvailable: number;
93
+ cachedHeld: number;
94
+ ledgerAvailable: number;
95
+ ledgerHeld: number;
96
+ }
97
+ interface WalletReconciliationReport {
98
+ parityDeltas: WalletParityDelta[];
99
+ cacheMismatches: WalletCacheMismatch[];
100
+ }
101
+ declare function runWalletReconciliation(): Promise<WalletReconciliationReport>;
102
+
103
+ interface WalletFeatureFlags {
104
+ enabled: boolean;
105
+ ledgerWrites: boolean;
106
+ settlementDebit: boolean;
107
+ checkout: boolean;
108
+ }
109
+ interface WalletAdminMutationEvent {
110
+ event: string;
111
+ actorId?: number;
112
+ actorRole?: string;
113
+ amount?: number;
114
+ after?: Record<string, unknown>;
115
+ }
116
+ interface WalletHttpConfig {
117
+ mode: 'routing-controllers' | 'express-router' | 'none';
118
+ basePath?: string;
119
+ app?: {
120
+ use: (path: string, handler: unknown) => void;
121
+ };
122
+ }
123
+ interface WalletReconciliationConfig {
124
+ enabled: boolean;
125
+ cron?: string;
126
+ onMismatch?: (report: WalletReconciliationReport) => void;
127
+ onLog?: (level: 'info' | 'warn', message: string, data?: unknown) => void;
128
+ }
129
+ interface WalletPluginConfig {
130
+ dataSource: unknown;
131
+ platformOwnerId: number;
132
+ defaultCurrency?: string;
133
+ flags: WalletFeatureFlags;
134
+ http?: WalletHttpConfig;
135
+ reconciliation?: WalletReconciliationConfig;
136
+ onAdminMutation?: (event: WalletAdminMutationEvent) => Promise<void>;
137
+ resolveOrderCustomerId?: (orderId: number) => Promise<number | null>;
138
+ }
139
+ interface WalletPlugin {
140
+ readonly client: WalletLedgerClient;
141
+ readonly hooks: WalletLifecycleHooks;
142
+ readonly flags: WalletFeatureFlags;
143
+ readonly http: {
144
+ controllers?: Function[];
145
+ expressRouter?: unknown;
146
+ };
147
+ readonly payment: {
148
+ createWalletPaymentAdapter: () => IWalletPaymentProvider;
149
+ };
150
+ isEnabled(): boolean;
151
+ isLedgerWritesEnabled(): boolean;
152
+ isSettlementDebitEnabled(): boolean;
153
+ isCheckoutEnabled(): boolean;
154
+ resolveOrderCustomerId?: (orderId: number) => Promise<number | null>;
155
+ onAdminMutation?: (event: WalletAdminMutationEvent) => Promise<void>;
156
+ shutdown(): Promise<void>;
157
+ }
158
+ declare const WALLET_PLUGIN_TOKEN = "multivendor-wallet.plugin";
159
+
160
+ interface WalletOrderPaidLine {
161
+ vendorOrderId: number;
162
+ vendorId: number;
163
+ commissionBaseRupees: number;
164
+ commissionRupees: number;
165
+ }
166
+ interface OrderPaidContext {
167
+ nativeTx: unknown;
168
+ orderId: number;
169
+ paymentNumber: string;
170
+ orderTotalRupees: number;
171
+ currency: string;
172
+ paymentMethod?: string;
173
+ customerId?: number;
174
+ lines: WalletOrderPaidLine[];
175
+ /** Customer wallet debit amount; defaults to full order total for wallet-only payments. */
176
+ walletAmountRupees?: number;
177
+ /** When true, customer debit was already taken (e.g. split checkout wallet leg). */
178
+ skipCustomerDebit?: boolean;
179
+ }
180
+ interface DeliveredContext {
181
+ nativeTx?: unknown;
182
+ vendorOrderId: number;
183
+ }
184
+ interface RefundContext {
185
+ orderProductId: number;
186
+ vendorOrderId: number;
187
+ vendorId: number;
188
+ lineTotalRupees: number;
189
+ commissionBaseRupees: number;
190
+ commissionRupees: number;
191
+ currency: string;
192
+ paymentMethod?: string;
193
+ customerId?: number;
194
+ orderId?: number;
195
+ refundReason?: 'cancel' | 'return';
196
+ /** Scope for idempotency keys (defaults to orderProductId). */
197
+ idempotencyScope?: string;
198
+ /** When true, skip cancelHold (no vendor escrow row). */
199
+ skipEscrow?: boolean;
200
+ /** For split payments, credit only this wallet portion (defaults to lineTotal when wallet-only). */
201
+ walletRefundRupees?: number;
202
+ processExternalRefund: () => Promise<void>;
203
+ }
204
+ interface SettlementDebitContext {
205
+ nativeTx: unknown;
206
+ settlementId: number;
207
+ vendorId: number;
208
+ amountRupees: number;
209
+ currency: string;
210
+ }
211
+ interface WalletLifecycleHooks {
212
+ onOrderPaid(ctx: OrderPaidContext): Promise<void>;
213
+ onLineDelivered(ctx: DeliveredContext): Promise<void>;
214
+ onRefund(ctx: RefundContext): Promise<void>;
215
+ onSettlementDebit(ctx: SettlementDebitContext): Promise<void>;
216
+ }
217
+ interface HookRuntime {
218
+ client: WalletLedgerClient;
219
+ platformOwnerId: number;
220
+ defaultCurrency: string;
221
+ flags: WalletFeatureFlags;
222
+ }
223
+
224
+ export { type CreatePaymentInput as C, type DeliveredContext as D, type HookRuntime as H, type IWalletPaymentProvider as I, type OrderPaidContext as O, PaymentProviderWallet as P, type RefundContext as R, type SettlementDebitContext as S, type WalletLifecycleHooks as W, type WalletCacheMismatch as a, type WalletOrderPaidLine as b, type WalletParityDelta as c, type WalletReconciliationReport as d, type WalletPluginConfig as e, type WalletPlugin as f, WALLET_PLUGIN_TOKEN as g, type WalletAdminMutationEvent as h, type WalletConfig as i, type WalletFeatureFlags as j, type WalletHttpConfig as k, WalletLedgerClient as l, type WalletReconciliationConfig as m, runWalletReconciliation as r };
@@ -0,0 +1,224 @@
1
+ import { I as IWalletStore, W as WalletAccountType, a as WalletStoreContext, b as WalletAccount, c as WalletBalance, C as CreditParams, L as LedgerMutationResult, D as DebitParams, H as HoldParams, R as ReleaseParams, d as CancelHoldParams, T as TransferParams, G as GetTransactionsParams, e as WalletLedgerEntry } from './store-BQ3whei-.js';
2
+
3
+ interface WalletConfig {
4
+ /** Default currency when not specified (e.g. INR). */
5
+ defaultCurrency?: string;
6
+ /** Platform wallet owner id in the host system. */
7
+ platformOwnerId?: number;
8
+ }
9
+
10
+ declare class WalletLedgerClient {
11
+ private readonly store;
12
+ private readonly config;
13
+ constructor(store: IWalletStore, config?: WalletConfig);
14
+ getOrCreateAccount(type: WalletAccountType, ownerId: number, currency?: string, ctx?: WalletStoreContext): Promise<WalletAccount>;
15
+ getBalance(accountId: number, ctx?: WalletStoreContext): Promise<WalletBalance>;
16
+ credit(params: CreditParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
17
+ debit(params: DebitParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
18
+ hold(params: HoldParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
19
+ release(params: ReleaseParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
20
+ cancelHold(params: CancelHoldParams, ctx?: WalletStoreContext): Promise<LedgerMutationResult>;
21
+ transfer(params: TransferParams, ctx?: WalletStoreContext): Promise<{
22
+ debit: LedgerMutationResult;
23
+ credit: LedgerMutationResult;
24
+ }>;
25
+ getTransactions(params: GetTransactionsParams, ctx?: WalletStoreContext): Promise<WalletLedgerEntry[]>;
26
+ private creditInTx;
27
+ private debitInTx;
28
+ private holdInTx;
29
+ private releaseInTx;
30
+ private cancelHoldInTx;
31
+ private toBalance;
32
+ private assertPositiveAmount;
33
+ private requireActiveHold;
34
+ }
35
+
36
+ declare const PaymentProviderWallet: "wallet";
37
+ interface CreatePaymentInput {
38
+ orderId: number;
39
+ amount: number;
40
+ currency: string;
41
+ metadata?: Record<string, string>;
42
+ }
43
+ interface PaymentResult {
44
+ providerPaymentId: string;
45
+ provider: typeof PaymentProviderWallet;
46
+ raw: unknown;
47
+ }
48
+ interface PaymentStatusResult {
49
+ providerPaymentId: string;
50
+ status: string;
51
+ amount: number;
52
+ currency: string;
53
+ provider: typeof PaymentProviderWallet;
54
+ raw: unknown;
55
+ }
56
+ interface RefundInput {
57
+ providerPaymentId: string;
58
+ amount?: number;
59
+ }
60
+ interface RefundResult {
61
+ providerRefundId: string;
62
+ status: string;
63
+ amount: number;
64
+ currency: string;
65
+ provider: typeof PaymentProviderWallet;
66
+ raw: unknown;
67
+ }
68
+ interface WebhookVerificationResult {
69
+ isValid: boolean;
70
+ event?: unknown;
71
+ }
72
+ interface IWalletPaymentProvider {
73
+ readonly provider: typeof PaymentProviderWallet;
74
+ getPublicCredential(): string | null;
75
+ createPayment(input: CreatePaymentInput): Promise<PaymentResult>;
76
+ verifyPayment(providerPaymentId: string, ...args: unknown[]): Promise<PaymentStatusResult>;
77
+ fetchPaymentStatus(providerPaymentId: string): Promise<PaymentStatusResult>;
78
+ resolveProviderPaymentId(orderId: number): Promise<string | null>;
79
+ createRefund(input: RefundInput): Promise<RefundResult>;
80
+ verifyWebhook(payload: string | Buffer, signature: string): WebhookVerificationResult;
81
+ }
82
+
83
+ interface WalletParityDelta {
84
+ orderId: number;
85
+ vendorOrderId: number;
86
+ vendorPaymentRupees: number;
87
+ holdPaise: number;
88
+ deltaRupees: number;
89
+ }
90
+ interface WalletCacheMismatch {
91
+ accountId: number;
92
+ cachedAvailable: number;
93
+ cachedHeld: number;
94
+ ledgerAvailable: number;
95
+ ledgerHeld: number;
96
+ }
97
+ interface WalletReconciliationReport {
98
+ parityDeltas: WalletParityDelta[];
99
+ cacheMismatches: WalletCacheMismatch[];
100
+ }
101
+ declare function runWalletReconciliation(): Promise<WalletReconciliationReport>;
102
+
103
+ interface WalletFeatureFlags {
104
+ enabled: boolean;
105
+ ledgerWrites: boolean;
106
+ settlementDebit: boolean;
107
+ checkout: boolean;
108
+ }
109
+ interface WalletAdminMutationEvent {
110
+ event: string;
111
+ actorId?: number;
112
+ actorRole?: string;
113
+ amount?: number;
114
+ after?: Record<string, unknown>;
115
+ }
116
+ interface WalletHttpConfig {
117
+ mode: 'routing-controllers' | 'express-router' | 'none';
118
+ basePath?: string;
119
+ app?: {
120
+ use: (path: string, handler: unknown) => void;
121
+ };
122
+ }
123
+ interface WalletReconciliationConfig {
124
+ enabled: boolean;
125
+ cron?: string;
126
+ onMismatch?: (report: WalletReconciliationReport) => void;
127
+ onLog?: (level: 'info' | 'warn', message: string, data?: unknown) => void;
128
+ }
129
+ interface WalletPluginConfig {
130
+ dataSource: unknown;
131
+ platformOwnerId: number;
132
+ defaultCurrency?: string;
133
+ flags: WalletFeatureFlags;
134
+ http?: WalletHttpConfig;
135
+ reconciliation?: WalletReconciliationConfig;
136
+ onAdminMutation?: (event: WalletAdminMutationEvent) => Promise<void>;
137
+ resolveOrderCustomerId?: (orderId: number) => Promise<number | null>;
138
+ }
139
+ interface WalletPlugin {
140
+ readonly client: WalletLedgerClient;
141
+ readonly hooks: WalletLifecycleHooks;
142
+ readonly flags: WalletFeatureFlags;
143
+ readonly http: {
144
+ controllers?: Function[];
145
+ expressRouter?: unknown;
146
+ };
147
+ readonly payment: {
148
+ createWalletPaymentAdapter: () => IWalletPaymentProvider;
149
+ };
150
+ isEnabled(): boolean;
151
+ isLedgerWritesEnabled(): boolean;
152
+ isSettlementDebitEnabled(): boolean;
153
+ isCheckoutEnabled(): boolean;
154
+ resolveOrderCustomerId?: (orderId: number) => Promise<number | null>;
155
+ onAdminMutation?: (event: WalletAdminMutationEvent) => Promise<void>;
156
+ shutdown(): Promise<void>;
157
+ }
158
+ declare const WALLET_PLUGIN_TOKEN = "multivendor-wallet.plugin";
159
+
160
+ interface WalletOrderPaidLine {
161
+ vendorOrderId: number;
162
+ vendorId: number;
163
+ commissionBaseRupees: number;
164
+ commissionRupees: number;
165
+ }
166
+ interface OrderPaidContext {
167
+ nativeTx: unknown;
168
+ orderId: number;
169
+ paymentNumber: string;
170
+ orderTotalRupees: number;
171
+ currency: string;
172
+ paymentMethod?: string;
173
+ customerId?: number;
174
+ lines: WalletOrderPaidLine[];
175
+ /** Customer wallet debit amount; defaults to full order total for wallet-only payments. */
176
+ walletAmountRupees?: number;
177
+ /** When true, customer debit was already taken (e.g. split checkout wallet leg). */
178
+ skipCustomerDebit?: boolean;
179
+ }
180
+ interface DeliveredContext {
181
+ nativeTx?: unknown;
182
+ vendorOrderId: number;
183
+ }
184
+ interface RefundContext {
185
+ orderProductId: number;
186
+ vendorOrderId: number;
187
+ vendorId: number;
188
+ lineTotalRupees: number;
189
+ commissionBaseRupees: number;
190
+ commissionRupees: number;
191
+ currency: string;
192
+ paymentMethod?: string;
193
+ customerId?: number;
194
+ orderId?: number;
195
+ refundReason?: 'cancel' | 'return';
196
+ /** Scope for idempotency keys (defaults to orderProductId). */
197
+ idempotencyScope?: string;
198
+ /** When true, skip cancelHold (no vendor escrow row). */
199
+ skipEscrow?: boolean;
200
+ /** For split payments, credit only this wallet portion (defaults to lineTotal when wallet-only). */
201
+ walletRefundRupees?: number;
202
+ processExternalRefund: () => Promise<void>;
203
+ }
204
+ interface SettlementDebitContext {
205
+ nativeTx: unknown;
206
+ settlementId: number;
207
+ vendorId: number;
208
+ amountRupees: number;
209
+ currency: string;
210
+ }
211
+ interface WalletLifecycleHooks {
212
+ onOrderPaid(ctx: OrderPaidContext): Promise<void>;
213
+ onLineDelivered(ctx: DeliveredContext): Promise<void>;
214
+ onRefund(ctx: RefundContext): Promise<void>;
215
+ onSettlementDebit(ctx: SettlementDebitContext): Promise<void>;
216
+ }
217
+ interface HookRuntime {
218
+ client: WalletLedgerClient;
219
+ platformOwnerId: number;
220
+ defaultCurrency: string;
221
+ flags: WalletFeatureFlags;
222
+ }
223
+
224
+ export { type CreatePaymentInput as C, type DeliveredContext as D, type HookRuntime as H, type IWalletPaymentProvider as I, type OrderPaidContext as O, PaymentProviderWallet as P, type RefundContext as R, type SettlementDebitContext as S, type WalletLifecycleHooks as W, type WalletCacheMismatch as a, type WalletOrderPaidLine as b, type WalletParityDelta as c, type WalletReconciliationReport as d, type WalletPluginConfig as e, type WalletPlugin as f, WALLET_PLUGIN_TOKEN as g, type WalletAdminMutationEvent as h, type WalletConfig as i, type WalletFeatureFlags as j, type WalletHttpConfig as k, WalletLedgerClient as l, type WalletReconciliationConfig as m, runWalletReconciliation as r };
package/package.json ADDED
@@ -0,0 +1,118 @@
1
+ {
2
+ "name": "multivendor-wallet",
3
+ "version": "0.0.1",
4
+ "description": "Install-and-use wallet plugin with ledger engine, TypeORM store, lifecycle hooks, and HTTP routes for multi-vendor marketplaces",
5
+ "license": "MIT",
6
+ "author": "SmartByteLabs",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/SmartByteLabs/multivendor-saas-components.git",
10
+ "directory": "multivendor-wallet"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/index.d.cts",
26
+ "default": "./dist/index.cjs"
27
+ }
28
+ },
29
+ "./typeorm": {
30
+ "import": {
31
+ "types": "./dist/typeorm/index.d.ts",
32
+ "default": "./dist/typeorm/index.js"
33
+ },
34
+ "require": {
35
+ "types": "./dist/typeorm/index.d.cts",
36
+ "default": "./dist/typeorm/index.cjs"
37
+ }
38
+ },
39
+ "./hooks": {
40
+ "import": {
41
+ "types": "./dist/hooks/index.d.ts",
42
+ "default": "./dist/hooks/index.js"
43
+ },
44
+ "require": {
45
+ "types": "./dist/hooks/index.d.cts",
46
+ "default": "./dist/hooks/index.cjs"
47
+ }
48
+ }
49
+ },
50
+ "files": [
51
+ "dist"
52
+ ],
53
+ "peerDependencies": {
54
+ "typeorm": ">=0.2.45 <0.4",
55
+ "express": ">=4",
56
+ "routing-controllers": ">=0.10",
57
+ "class-validator": ">=0.14",
58
+ "class-transformer": ">=0.5",
59
+ "typedi": ">=0.8",
60
+ "reflect-metadata": ">=0.1.13",
61
+ "node-cron": ">=3"
62
+ },
63
+ "peerDependenciesMeta": {
64
+ "typeorm": {
65
+ "optional": true
66
+ },
67
+ "express": {
68
+ "optional": true
69
+ },
70
+ "routing-controllers": {
71
+ "optional": true
72
+ },
73
+ "class-validator": {
74
+ "optional": true
75
+ },
76
+ "class-transformer": {
77
+ "optional": true
78
+ },
79
+ "typedi": {
80
+ "optional": true
81
+ },
82
+ "reflect-metadata": {
83
+ "optional": true
84
+ },
85
+ "node-cron": {
86
+ "optional": true
87
+ }
88
+ },
89
+ "devDependencies": {
90
+ "@swc/core": "^1.10.0",
91
+ "@types/express": "^4.17.21",
92
+ "@types/node": "^20.11.0",
93
+ "class-transformer": "^0.5.1",
94
+ "class-validator": "^0.14.1",
95
+ "express": "^4.18.2",
96
+ "reflect-metadata": "^0.1.13",
97
+ "routing-controllers": "^0.10.4",
98
+ "tsup": "^8.4.0",
99
+ "typedi": "^0.10.0",
100
+ "typeorm": "^0.2.45",
101
+ "typescript": "^5.7.3",
102
+ "vitest": "^3.0.5"
103
+ },
104
+ "keywords": [
105
+ "wallet",
106
+ "ledger",
107
+ "escrow",
108
+ "hold",
109
+ "release",
110
+ "marketplace",
111
+ "plugin"
112
+ ],
113
+ "scripts": {
114
+ "build": "tsup",
115
+ "test": "vitest run",
116
+ "test:watch": "vitest"
117
+ }
118
+ }