@smartsoft001/trans-shell-app-services 2.76.0 → 2.80.0

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/index.js ADDED
@@ -0,0 +1,110 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
13
+
14
+ // packages/trans/shell/app-services/src/lib/services/trans/trans.service.ts
15
+ import { Injectable, Optional } from "@nestjs/common";
16
+
17
+ // packages/trans/shell/app-services/src/lib/services/internal/internal.service.ts
18
+ var TRANS_TOKEN_INTERNAL_SERVICE = "TRANS_TOKEN_INTERNAL_SERVICE";
19
+
20
+ // packages/trans/shell/app-services/src/lib/services/trans/trans.service.ts
21
+ var TransService = class {
22
+ constructor(moduleRef, creatorService, refresherService, refundService, httpService, config, repository, payuService, paynowService, paypalService, revolutService) {
23
+ this.moduleRef = moduleRef;
24
+ this.creatorService = creatorService;
25
+ this.refresherService = refresherService;
26
+ this.refundService = refundService;
27
+ this.httpService = httpService;
28
+ this.config = config;
29
+ this.repository = repository;
30
+ this.payuService = payuService;
31
+ this.paynowService = paynowService;
32
+ this.paypalService = paypalService;
33
+ this.revolutService = revolutService;
34
+ this._paymentService = {
35
+ payu: this.payuService,
36
+ paypal: this.paypalService,
37
+ paynow: this.paynowService,
38
+ revolut: this.revolutService
39
+ };
40
+ this._internalService = {
41
+ create: (trans) => {
42
+ if (!this.config.internalApiUrl)
43
+ return Promise.resolve({
44
+ date: /* @__PURE__ */ new Date(),
45
+ req: trans
46
+ });
47
+ return this.httpService.post(this.config.internalApiUrl, trans).toPromise().then((res) => res.data);
48
+ },
49
+ refresh: (trans) => {
50
+ if (!this.config.internalApiUrl)
51
+ return Promise.resolve({
52
+ date: /* @__PURE__ */ new Date(),
53
+ req: trans,
54
+ id: trans.id
55
+ });
56
+ return this.httpService.put(this.config.internalApiUrl + "/" + trans.id, trans).toPromise().then((res) => res.data);
57
+ }
58
+ };
59
+ }
60
+ create(ops) {
61
+ return this.creatorService.create(
62
+ ops,
63
+ this.getInternalService(),
64
+ this._paymentService
65
+ );
66
+ }
67
+ async refresh(transId, data = {}) {
68
+ await this.refresherService.refresh(
69
+ transId,
70
+ this.getInternalService(),
71
+ this._paymentService,
72
+ data
73
+ );
74
+ }
75
+ async refund(transId, comment = "Refund") {
76
+ await this.refundService.refund(
77
+ transId,
78
+ this.getInternalService(),
79
+ this._paymentService,
80
+ comment
81
+ );
82
+ }
83
+ async getById(id) {
84
+ return await this.repository.getById(id);
85
+ }
86
+ getInternalService() {
87
+ try {
88
+ return this.moduleRef.get(TRANS_TOKEN_INTERNAL_SERVICE, {
89
+ strict: false
90
+ });
91
+ } catch (e) {
92
+ return this._internalService;
93
+ }
94
+ }
95
+ };
96
+ TransService = __decorateClass([
97
+ Injectable(),
98
+ __decorateParam(7, Optional()),
99
+ __decorateParam(8, Optional()),
100
+ __decorateParam(9, Optional()),
101
+ __decorateParam(10, Optional())
102
+ ], TransService);
103
+
104
+ // packages/trans/shell/app-services/src/lib/services/index.ts
105
+ var SERVICES = [TransService];
106
+ export {
107
+ SERVICES,
108
+ TRANS_TOKEN_INTERNAL_SERVICE,
109
+ TransService
110
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartsoft001/trans-shell-app-services",
3
- "version": "2.76.0",
3
+ "version": "2.80.0",
4
4
  "description": "This library was generated with [Nx](https://nx.dev).",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,6 +1,4 @@
1
1
  import { TransService } from './trans/trans.service';
2
-
3
2
  export * from './trans/trans.service';
4
3
  export * from './internal/internal.service';
5
-
6
- export const SERVICES = [TransService];
4
+ export declare const SERVICES: (typeof TransService)[];
@@ -0,0 +1 @@
1
+ export declare const TRANS_TOKEN_INTERNAL_SERVICE = "TRANS_TOKEN_INTERNAL_SERVICE";
@@ -0,0 +1,33 @@
1
+ import { HttpService } from '@nestjs/axios';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ import { IItemRepository } from '@smartsoft001/domain-core';
4
+ import { PaynowService } from '@smartsoft001/paynow';
5
+ import { PaypalService } from '@smartsoft001/paypal';
6
+ import { PayuService } from '@smartsoft001/payu';
7
+ import { RevolutService } from '@smartsoft001/revolut';
8
+ import { ITransCreate, Trans, TransConfig, CreatorService, RefresherService, RefundService } from '@smartsoft001/trans-domain';
9
+ export declare class TransService {
10
+ private moduleRef;
11
+ private creatorService;
12
+ private refresherService;
13
+ private refundService;
14
+ private httpService;
15
+ private config;
16
+ private repository;
17
+ private payuService;
18
+ private paynowService;
19
+ private paypalService;
20
+ private revolutService;
21
+ private _paymentService;
22
+ private _internalService;
23
+ constructor(moduleRef: ModuleRef, creatorService: CreatorService<any>, refresherService: RefresherService<any>, refundService: RefundService<any>, httpService: HttpService, config: TransConfig, repository: IItemRepository<Trans<any>>, payuService: PayuService, paynowService: PaynowService, paypalService: PaypalService, revolutService: RevolutService);
24
+ create<T>(ops: ITransCreate<T>): Promise<{
25
+ orderId: string;
26
+ redirectUrl?: string;
27
+ responseData?: any;
28
+ }>;
29
+ refresh(transId: string, data?: {}): Promise<void>;
30
+ refund(transId: string, comment?: string): Promise<void>;
31
+ getById(id: any): Promise<Trans<any>>;
32
+ private getInternalService;
33
+ }
package/.eslintrc.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../../../.eslintrc",
3
- "rules": {},
4
- "ignorePatterns": ["!**/*"],
5
- "overrides": [
6
- {
7
- "files": ["*.json"],
8
- "parser": "jsonc-eslint-parser"
9
- }
10
- ]
11
- }
package/jest.config.ts DELETED
@@ -1,27 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- globals: {},
4
- transform: {
5
- '^.+\\.[tj]sx?$': [
6
- 'ts-jest',
7
- {
8
- tsConfig: '<rootDir>/tsconfig.spec.json',
9
- },
10
- ],
11
- },
12
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
13
- coverageDirectory: '../../../../coverage/packages/trans/shell/app-services',
14
- displayName: 'trans-shell-app-services',
15
- testEnvironment: 'node',
16
- preset: '../../../../jest.preset.js',
17
- /* TODO: Update to latest Jest snapshotFormat
18
- * By default Nx has kept the older style of Jest Snapshot formats
19
- * to prevent breaking of any existing tests with snapshots.
20
- * It's recommend you update to the latest format.
21
- * You can do this by removing snapshotFormat property
22
- * and running tests with --update-snapshot flag.
23
- * Example: From within the project directory, run "nx test --update-snapshot"
24
- * More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
25
- */
26
- snapshotFormat: { escapeString: true, printBasicPrototype: true },
27
- };
package/project.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "name": "trans-shell-app-services",
3
- "$schema": "../../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "packages/trans/shell/app-services/src",
5
- "projectType": "library",
6
- "tags": ["scope:trans", "type:shell"],
7
- "generators": {},
8
- "targets": {
9
- "lint": {
10
- "executor": "@nx/eslint:lint",
11
- "outputs": ["{options.outputFile}"],
12
- "options": {
13
- "lintFilePatterns": [
14
- "packages/trans/shell/app-services/**/*.{ts,tsx,js,jsx}",
15
- "packages/trans/shell/app-services/package.json"
16
- ]
17
- }
18
- },
19
- "test": {
20
- "executor": "@nx/jest:jest",
21
- "options": {
22
- "jestConfig": "packages/trans/shell/app-services/jest.config.ts",
23
- "passWithNoTests": true
24
- },
25
- "outputs": ["{workspaceRoot}/coverage/packages/trans/shell/app-services"]
26
- },
27
- "build": {
28
- "executor": "@nx/esbuild:esbuild",
29
- "outputs": ["{options.outputPath}"],
30
- "options": {
31
- "outputPath": "dist/packages/trans/shell/app-services",
32
- "tsConfig": "packages/trans/shell/app-services/tsconfig.lib.json",
33
- "packageJson": "packages/trans/shell/app-services/package.json",
34
- "main": "packages/trans/shell/app-services/src/index.ts",
35
- "assets": ["packages/trans/shell/app-services/*.md"]
36
- }
37
- }
38
- }
39
- }
@@ -1 +0,0 @@
1
- export const TRANS_TOKEN_INTERNAL_SERVICE = 'TRANS_TOKEN_INTERNAL_SERVICE';
@@ -1,266 +0,0 @@
1
- import { HttpService } from '@nestjs/axios';
2
- import { ModuleRef } from '@nestjs/core';
3
- import { Test, TestingModule } from '@nestjs/testing';
4
-
5
- import { IItemRepository } from '@smartsoft001/domain-core';
6
- import { PaynowService } from '@smartsoft001/paynow';
7
- import { PaypalService } from '@smartsoft001/paypal';
8
- import { PayuService } from '@smartsoft001/payu';
9
- import { RevolutService } from '@smartsoft001/revolut';
10
- import {
11
- CreatorService,
12
- RefresherService,
13
- RefundService,
14
- Trans,
15
- TransConfig,
16
- TransSystem,
17
- } from '@smartsoft001/trans-domain';
18
-
19
- import { TransService } from './trans.service';
20
-
21
- // Mock PayPal SDK before importing it
22
- jest.mock('paypal-rest-sdk', () => ({
23
- payment: {
24
- create: jest.fn(),
25
- execute: jest.fn(),
26
- get: jest.fn(),
27
- },
28
- sale: {
29
- refund: jest.fn(),
30
- },
31
- configure: jest.fn(),
32
- }));
33
-
34
- describe('trans: TransService', () => {
35
- let service: TransService;
36
- let mockModuleRef: jest.Mocked<ModuleRef>;
37
- let mockCreatorService: jest.Mocked<CreatorService<any>>;
38
- let mockRefresherService: jest.Mocked<RefresherService<any>>;
39
- let mockRefundService: jest.Mocked<RefundService<any>>;
40
- let mockHttpService: jest.Mocked<HttpService>;
41
- let mockConfig: TransConfig;
42
- let mockRepository: jest.Mocked<IItemRepository<Trans<any>>>;
43
- let mockPayuService: jest.Mocked<PayuService>;
44
- let mockPaynowService: jest.Mocked<PaynowService>;
45
- let mockPaypalService: jest.Mocked<PaypalService>;
46
- let mockRevolutService: jest.Mocked<RevolutService>;
47
- let mockInternalService: any;
48
-
49
- beforeEach(async () => {
50
- mockModuleRef = {
51
- get: jest.fn(),
52
- } as any;
53
-
54
- mockCreatorService = {
55
- create: jest.fn(),
56
- } as any;
57
-
58
- mockRefresherService = {
59
- refresh: jest.fn(),
60
- } as any;
61
-
62
- mockRefundService = {
63
- refund: jest.fn(),
64
- } as any;
65
-
66
- mockHttpService = {
67
- post: jest.fn(),
68
- put: jest.fn(),
69
- } as any;
70
-
71
- mockConfig = {
72
- internalApiUrl: 'http://test-api.com',
73
- } as any;
74
-
75
- mockRepository = {
76
- getById: jest.fn(),
77
- } as any;
78
-
79
- mockPayuService = {
80
- create: jest.fn(),
81
- getStatus: jest.fn(),
82
- refund: jest.fn(),
83
- } as any;
84
-
85
- mockPaynowService = {
86
- create: jest.fn(),
87
- getStatus: jest.fn(),
88
- refund: jest.fn(),
89
- } as any;
90
-
91
- mockPaypalService = {
92
- create: jest.fn(),
93
- getStatus: jest.fn(),
94
- refund: jest.fn(),
95
- } as any;
96
-
97
- mockRevolutService = {
98
- create: jest.fn(),
99
- getStatus: jest.fn(),
100
- refund: jest.fn(),
101
- } as any;
102
-
103
- mockInternalService = {
104
- create: jest.fn(),
105
- refresh: jest.fn(),
106
- };
107
-
108
- const module: TestingModule = await Test.createTestingModule({
109
- providers: [
110
- TransService,
111
- {
112
- provide: ModuleRef,
113
- useValue: mockModuleRef,
114
- },
115
- {
116
- provide: CreatorService,
117
- useValue: mockCreatorService,
118
- },
119
- {
120
- provide: RefresherService,
121
- useValue: mockRefresherService,
122
- },
123
- {
124
- provide: RefundService,
125
- useValue: mockRefundService,
126
- },
127
- {
128
- provide: HttpService,
129
- useValue: mockHttpService,
130
- },
131
- {
132
- provide: TransConfig,
133
- useValue: mockConfig,
134
- },
135
- {
136
- provide: IItemRepository,
137
- useValue: mockRepository,
138
- },
139
- {
140
- provide: PayuService,
141
- useValue: mockPayuService,
142
- },
143
- {
144
- provide: PaynowService,
145
- useValue: mockPaynowService,
146
- },
147
- {
148
- provide: PaypalService,
149
- useValue: mockPaypalService,
150
- },
151
- {
152
- provide: RevolutService,
153
- useValue: mockRevolutService,
154
- },
155
- ],
156
- }).compile();
157
-
158
- service = module.get<TransService>(TransService);
159
- });
160
-
161
- it('should be defined', () => {
162
- expect(service).toBeDefined();
163
- });
164
-
165
- describe('create', () => {
166
- it('should call creator service with correct parameters', async () => {
167
- const mockOps = {
168
- amount: 100,
169
- system: 'payu' as TransSystem,
170
- name: 'Test Transaction',
171
- firstName: 'John',
172
- lastName: 'Doe',
173
- email: 'john@example.com',
174
- contactPhone: '123456789',
175
- data: {},
176
- options: {},
177
- clientIp: '127.0.0.1',
178
- };
179
- const mockResult = {
180
- orderId: 'test-order',
181
- redirectUrl: 'http://test.com',
182
- };
183
- mockCreatorService.create.mockResolvedValue(mockResult);
184
- mockModuleRef.get.mockReturnValue(mockInternalService);
185
-
186
- const result = await service.create(mockOps);
187
-
188
- expect(result).toEqual(mockResult);
189
- });
190
- });
191
-
192
- describe('refresh', () => {
193
- it('should call refresher service with correct parameters', async () => {
194
- const transId = 'test-trans-id';
195
- const mockData = { status: 'completed' };
196
- mockModuleRef.get.mockReturnValue(mockInternalService);
197
-
198
- await service.refresh(transId, mockData);
199
-
200
- expect(mockRefresherService.refresh).toHaveBeenCalledWith(
201
- transId,
202
- mockInternalService,
203
- expect.any(Object),
204
- mockData,
205
- );
206
- });
207
- });
208
-
209
- describe('refund', () => {
210
- it('should call refund service with correct parameters', async () => {
211
- const transId = 'test-trans-id';
212
- const comment = 'Test refund';
213
- mockModuleRef.get.mockReturnValue(mockInternalService);
214
-
215
- await service.refund(transId, comment);
216
-
217
- expect(mockRefundService.refund).toHaveBeenCalledWith(
218
- transId,
219
- mockInternalService,
220
- expect.any(Object),
221
- comment,
222
- );
223
- });
224
- });
225
-
226
- describe('getById', () => {
227
- it('should return transaction by id', async () => {
228
- const mockTrans = { id: 'test-id', status: 'completed' } as Trans<any>;
229
- mockRepository.getById.mockResolvedValue(mockTrans);
230
-
231
- const result = await service.getById('test-id');
232
-
233
- expect(result).toEqual(mockTrans);
234
- });
235
- });
236
-
237
- describe('getInternalService', () => {
238
- it('should return internal service from module ref when available', () => {
239
- mockModuleRef.get.mockReturnValue(mockInternalService);
240
-
241
- const result = (service as any).getInternalService();
242
-
243
- expect(result).toBe(mockInternalService);
244
- });
245
-
246
- it('should return fallback internal service with create method when module ref fails', () => {
247
- mockModuleRef.get.mockImplementation(() => {
248
- throw new Error('Service not found');
249
- });
250
-
251
- const result = (service as any).getInternalService();
252
-
253
- expect(result).toHaveProperty('create');
254
- });
255
-
256
- it('should return fallback internal service with refresh method when module ref fails', () => {
257
- mockModuleRef.get.mockImplementation(() => {
258
- throw new Error('Service not found');
259
- });
260
-
261
- const result = (service as any).getInternalService();
262
-
263
- expect(result).toHaveProperty('refresh');
264
- });
265
- });
266
- });
@@ -1,118 +0,0 @@
1
- import { HttpService } from '@nestjs/axios';
2
- import { Injectable, Optional } from '@nestjs/common';
3
- import { ModuleRef } from '@nestjs/core';
4
-
5
- import { IItemRepository } from '@smartsoft001/domain-core';
6
- import { PaynowService } from '@smartsoft001/paynow';
7
- import { PaypalService } from '@smartsoft001/paypal';
8
- import { PayuService } from '@smartsoft001/payu';
9
- import { RevolutService } from '@smartsoft001/revolut';
10
- import {
11
- ITransCreate,
12
- Trans,
13
- TransConfig,
14
- CreatorService,
15
- RefresherService,
16
- ITransPaymentSingleService,
17
- ITransInternalService,
18
- RefundService,
19
- } from '@smartsoft001/trans-domain';
20
-
21
- import { TRANS_TOKEN_INTERNAL_SERVICE } from '../internal/internal.service';
22
-
23
- @Injectable()
24
- export class TransService {
25
- private _paymentService: {
26
- [key: string]: ITransPaymentSingleService;
27
- } = {
28
- payu: this.payuService,
29
- paypal: this.paypalService,
30
- paynow: this.paynowService,
31
- revolut: this.revolutService,
32
- };
33
-
34
- private _internalService = {
35
- create: (trans: Trans<any>) => {
36
- if (!this.config.internalApiUrl)
37
- return Promise.resolve({
38
- date: new Date(),
39
- req: trans,
40
- });
41
-
42
- return this.httpService
43
- .post(this.config.internalApiUrl, trans)
44
- .toPromise()
45
- .then((res) => res.data);
46
- },
47
-
48
- refresh: (trans: Trans<any>) => {
49
- if (!this.config.internalApiUrl)
50
- return Promise.resolve({
51
- date: new Date(),
52
- req: trans,
53
- id: trans.id,
54
- });
55
-
56
- return this.httpService
57
- .put(this.config.internalApiUrl + '/' + trans.id, trans)
58
- .toPromise()
59
- .then((res) => res.data);
60
- },
61
- };
62
-
63
- constructor(
64
- private moduleRef: ModuleRef,
65
- private creatorService: CreatorService<any>,
66
- private refresherService: RefresherService<any>,
67
- private refundService: RefundService<any>,
68
- private httpService: HttpService,
69
- private config: TransConfig,
70
- private repository: IItemRepository<Trans<any>>,
71
- @Optional() private payuService: PayuService,
72
- @Optional() private paynowService: PaynowService,
73
- @Optional() private paypalService: PaypalService,
74
- @Optional() private revolutService: RevolutService,
75
- ) {}
76
-
77
- create<T>(
78
- ops: ITransCreate<T>,
79
- ): Promise<{ orderId: string; redirectUrl?: string; responseData?: any }> {
80
- return this.creatorService.create(
81
- ops,
82
- this.getInternalService(),
83
- this._paymentService,
84
- );
85
- }
86
-
87
- async refresh(transId: string, data = {}): Promise<void> {
88
- await this.refresherService.refresh(
89
- transId,
90
- this.getInternalService(),
91
- this._paymentService,
92
- data,
93
- );
94
- }
95
-
96
- async refund(transId: string, comment = 'Refund'): Promise<void> {
97
- await this.refundService.refund(
98
- transId,
99
- this.getInternalService(),
100
- this._paymentService,
101
- comment,
102
- );
103
- }
104
-
105
- async getById(id: any): Promise<Trans<any>> {
106
- return await this.repository.getById(id);
107
- }
108
-
109
- private getInternalService(): ITransInternalService<any> {
110
- try {
111
- return this.moduleRef.get(TRANS_TOKEN_INTERNAL_SERVICE, {
112
- strict: false,
113
- });
114
- } catch (e) {
115
- return this._internalService;
116
- }
117
- }
118
- }
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.base.json",
3
- "files": [],
4
- "include": [],
5
- "references": [
6
- {
7
- "path": "./tsconfig.lib.json"
8
- },
9
- {
10
- "path": "./tsconfig.spec.json"
11
- }
12
- ]
13
- }
package/tsconfig.lib.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "outDir": "../../../../dist/out-tsc",
6
- "declaration": true,
7
- "types": ["node"]
8
- },
9
- "exclude": ["**/*.spec.ts", "**/*.test.ts", "jest.config.ts"],
10
- "include": ["**/*.ts"]
11
- }
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "**/*.spec.ts",
10
- "**/*.test.ts",
11
- "**/*.spec.tsx",
12
- "**/*.test.tsx",
13
- "**/*.spec.js",
14
- "**/*.test.js",
15
- "**/*.spec.jsx",
16
- "**/*.test.jsx",
17
- "**/*.d.ts",
18
- "jest.config.ts"
19
- ]
20
- }
File without changes
File without changes