@timo-bank/nestjs 0.1.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/README.md +150 -0
- package/dist/index.d.mts +134 -0
- package/dist/index.d.ts +134 -0
- package/dist/index.js +188 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +180 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# @timo-bank/nestjs
|
|
2
|
+
|
|
3
|
+
NestJS module for Timo Bank SDK integration.
|
|
4
|
+
|
|
5
|
+
> **Warning**: This is an unofficial package. See [DISCLAIMER](../../DISCLAIMER.md).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @timo-bank/core @timo-bank/nestjs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
First, run the core setup CLI:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx @timo-bank/core setup
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Add the credential token to your `.env`:
|
|
22
|
+
|
|
23
|
+
```env
|
|
24
|
+
TIMO_CREDENTIALS=timo_v1_eyJ1c2VybmFtZSI6...
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Setup
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// app.module.ts
|
|
33
|
+
import { Module } from '@nestjs/common';
|
|
34
|
+
import { TimoModule } from '@timo-bank/nestjs';
|
|
35
|
+
|
|
36
|
+
@Module({
|
|
37
|
+
imports: [
|
|
38
|
+
TimoModule.forRoot({
|
|
39
|
+
credentials: process.env.TIMO_CREDENTIALS!,
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
export class AppModule {}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Async Configuration
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// app.module.ts
|
|
50
|
+
import { Module } from '@nestjs/common';
|
|
51
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
52
|
+
import { TimoModule } from '@timo-bank/nestjs';
|
|
53
|
+
|
|
54
|
+
@Module({
|
|
55
|
+
imports: [
|
|
56
|
+
ConfigModule.forRoot(),
|
|
57
|
+
TimoModule.forRootAsync({
|
|
58
|
+
imports: [ConfigModule],
|
|
59
|
+
useFactory: (config: ConfigService) => ({
|
|
60
|
+
credentials: config.get('TIMO_CREDENTIALS')!,
|
|
61
|
+
autoLogin: true, // default
|
|
62
|
+
}),
|
|
63
|
+
inject: [ConfigService],
|
|
64
|
+
}),
|
|
65
|
+
],
|
|
66
|
+
})
|
|
67
|
+
export class AppModule {}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Using the Client
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// payment.service.ts
|
|
74
|
+
import { Injectable } from '@nestjs/common';
|
|
75
|
+
import { InjectTimo, TimoClient } from '@timo-bank/nestjs';
|
|
76
|
+
|
|
77
|
+
@Injectable()
|
|
78
|
+
export class PaymentService {
|
|
79
|
+
constructor(@InjectTimo() private readonly timo: TimoClient) {}
|
|
80
|
+
|
|
81
|
+
async getBalance() {
|
|
82
|
+
return this.timo.getBalance();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async getRecentTransactions() {
|
|
86
|
+
return this.timo.getTransactions({
|
|
87
|
+
limit: 10,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Module Options
|
|
94
|
+
|
|
95
|
+
### TimoModuleOptions
|
|
96
|
+
|
|
97
|
+
| Option | Type | Required | Description |
|
|
98
|
+
|--------|------|----------|-------------|
|
|
99
|
+
| `credentials` | `string` | Yes | Credential token from CLI |
|
|
100
|
+
| `logger` | `Logger` | No | Custom logger |
|
|
101
|
+
| `autoLogin` | `boolean` | No | Auto-login on init (default: true) |
|
|
102
|
+
|
|
103
|
+
### TimoModuleAsyncOptions
|
|
104
|
+
|
|
105
|
+
| Option | Type | Description |
|
|
106
|
+
|--------|------|-------------|
|
|
107
|
+
| `imports` | `any[]` | Modules to import |
|
|
108
|
+
| `useFactory` | `Function` | Factory function |
|
|
109
|
+
| `useClass` | `Type` | Options provider class |
|
|
110
|
+
| `useExisting` | `Type` | Existing options provider |
|
|
111
|
+
| `inject` | `any[]` | Dependencies to inject |
|
|
112
|
+
|
|
113
|
+
## Exports
|
|
114
|
+
|
|
115
|
+
### From @timo-bank/nestjs
|
|
116
|
+
|
|
117
|
+
- `TimoModule` - Main NestJS module
|
|
118
|
+
- `InjectTimo()` - Decorator to inject TimoClient
|
|
119
|
+
- `TimoClient` - Re-exported from core
|
|
120
|
+
- Types: `Balance`, `Transaction`, `AccountInfo`, `UserProfile`
|
|
121
|
+
|
|
122
|
+
## Auto-Login
|
|
123
|
+
|
|
124
|
+
By default, the module automatically calls `client.login()` during initialization. This means your service can immediately use the client methods.
|
|
125
|
+
|
|
126
|
+
To disable auto-login:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
TimoModule.forRoot({
|
|
130
|
+
credentials: process.env.TIMO_CREDENTIALS!,
|
|
131
|
+
autoLogin: false,
|
|
132
|
+
}),
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Then manually login when needed:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
@Injectable()
|
|
139
|
+
export class PaymentService implements OnModuleInit {
|
|
140
|
+
constructor(@InjectTimo() private readonly timo: TimoClient) {}
|
|
141
|
+
|
|
142
|
+
async onModuleInit() {
|
|
143
|
+
await this.timo.login();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ModuleMetadata, Type, InjectionToken, DynamicModule, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { Logger, TimoClient } from '@timo-bank/core';
|
|
3
|
+
export { AccountInfo, Balance, Logger, TimoClient, Transaction, TransactionOptions, UserProfile } from '@timo-bank/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for TimoModule.forRoot()
|
|
7
|
+
*/
|
|
8
|
+
interface TimoModuleOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Credential token from CLI setup
|
|
11
|
+
* Format: timo_v1_<base64>
|
|
12
|
+
*/
|
|
13
|
+
credentials: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional logger
|
|
16
|
+
*/
|
|
17
|
+
logger?: Logger;
|
|
18
|
+
/**
|
|
19
|
+
* Auto-login on module init (default: true)
|
|
20
|
+
*/
|
|
21
|
+
autoLogin?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Factory interface for async options
|
|
25
|
+
*/
|
|
26
|
+
interface TimoOptionsFactory {
|
|
27
|
+
createTimoOptions(): Promise<TimoModuleOptions> | TimoModuleOptions;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for TimoModule.forRootAsync()
|
|
31
|
+
*/
|
|
32
|
+
interface TimoModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
33
|
+
/**
|
|
34
|
+
* Use existing provider
|
|
35
|
+
*/
|
|
36
|
+
useExisting?: Type<TimoOptionsFactory>;
|
|
37
|
+
/**
|
|
38
|
+
* Use class for options
|
|
39
|
+
*/
|
|
40
|
+
useClass?: Type<TimoOptionsFactory>;
|
|
41
|
+
/**
|
|
42
|
+
* Use factory function
|
|
43
|
+
*/
|
|
44
|
+
useFactory?: (...args: any[]) => Promise<TimoModuleOptions> | TimoModuleOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Inject dependencies for factory
|
|
47
|
+
*/
|
|
48
|
+
inject?: InjectionToken[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare class TimoModule {
|
|
52
|
+
/**
|
|
53
|
+
* Register TimoModule with synchronous options
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* @Module({
|
|
58
|
+
* imports: [
|
|
59
|
+
* TimoModule.forRoot({
|
|
60
|
+
* credentials: process.env.TIMO_CREDENTIALS!,
|
|
61
|
+
* }),
|
|
62
|
+
* ],
|
|
63
|
+
* })
|
|
64
|
+
* export class AppModule {}
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
static forRoot(options: TimoModuleOptions): DynamicModule;
|
|
68
|
+
/**
|
|
69
|
+
* Register TimoModule with asynchronous options
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* @Module({
|
|
74
|
+
* imports: [
|
|
75
|
+
* TimoModule.forRootAsync({
|
|
76
|
+
* imports: [ConfigModule],
|
|
77
|
+
* useFactory: (config: ConfigService) => ({
|
|
78
|
+
* credentials: config.get('TIMO_CREDENTIALS'),
|
|
79
|
+
* }),
|
|
80
|
+
* inject: [ConfigService],
|
|
81
|
+
* }),
|
|
82
|
+
* ],
|
|
83
|
+
* })
|
|
84
|
+
* export class AppModule {}
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class TimoCoreModule implements OnModuleInit {
|
|
91
|
+
private readonly client;
|
|
92
|
+
private readonly options;
|
|
93
|
+
private readonly logger;
|
|
94
|
+
constructor(client: TimoClient, options: TimoModuleOptions);
|
|
95
|
+
onModuleInit(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Synchronous configuration
|
|
98
|
+
*/
|
|
99
|
+
static forRoot(options: TimoModuleOptions): DynamicModule;
|
|
100
|
+
/**
|
|
101
|
+
* Asynchronous configuration
|
|
102
|
+
*/
|
|
103
|
+
static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule;
|
|
104
|
+
private static createClientProvider;
|
|
105
|
+
private static createAsyncProviders;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Injects the TimoClient instance
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* @Injectable()
|
|
114
|
+
* export class PaymentService {
|
|
115
|
+
* constructor(@InjectTimo() private readonly timo: TimoClient) {}
|
|
116
|
+
*
|
|
117
|
+
* async getBalance() {
|
|
118
|
+
* return this.timo.getBalance();
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare const InjectTimo: () => PropertyDecorator & ParameterDecorator;
|
|
124
|
+
|
|
125
|
+
declare const TIMO_CLIENT_TOKEN: unique symbol;
|
|
126
|
+
declare const TIMO_MODULE_OPTIONS: unique symbol;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @timo-bank/nestjs
|
|
130
|
+
* NestJS module for Timo Bank SDK
|
|
131
|
+
*/
|
|
132
|
+
declare const VERSION = "0.1.0";
|
|
133
|
+
|
|
134
|
+
export { InjectTimo, TIMO_CLIENT_TOKEN, TIMO_MODULE_OPTIONS, TimoCoreModule, TimoModule, type TimoModuleAsyncOptions, type TimoModuleOptions, type TimoOptionsFactory, VERSION };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ModuleMetadata, Type, InjectionToken, DynamicModule, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { Logger, TimoClient } from '@timo-bank/core';
|
|
3
|
+
export { AccountInfo, Balance, Logger, TimoClient, Transaction, TransactionOptions, UserProfile } from '@timo-bank/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for TimoModule.forRoot()
|
|
7
|
+
*/
|
|
8
|
+
interface TimoModuleOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Credential token from CLI setup
|
|
11
|
+
* Format: timo_v1_<base64>
|
|
12
|
+
*/
|
|
13
|
+
credentials: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional logger
|
|
16
|
+
*/
|
|
17
|
+
logger?: Logger;
|
|
18
|
+
/**
|
|
19
|
+
* Auto-login on module init (default: true)
|
|
20
|
+
*/
|
|
21
|
+
autoLogin?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Factory interface for async options
|
|
25
|
+
*/
|
|
26
|
+
interface TimoOptionsFactory {
|
|
27
|
+
createTimoOptions(): Promise<TimoModuleOptions> | TimoModuleOptions;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for TimoModule.forRootAsync()
|
|
31
|
+
*/
|
|
32
|
+
interface TimoModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
33
|
+
/**
|
|
34
|
+
* Use existing provider
|
|
35
|
+
*/
|
|
36
|
+
useExisting?: Type<TimoOptionsFactory>;
|
|
37
|
+
/**
|
|
38
|
+
* Use class for options
|
|
39
|
+
*/
|
|
40
|
+
useClass?: Type<TimoOptionsFactory>;
|
|
41
|
+
/**
|
|
42
|
+
* Use factory function
|
|
43
|
+
*/
|
|
44
|
+
useFactory?: (...args: any[]) => Promise<TimoModuleOptions> | TimoModuleOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Inject dependencies for factory
|
|
47
|
+
*/
|
|
48
|
+
inject?: InjectionToken[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare class TimoModule {
|
|
52
|
+
/**
|
|
53
|
+
* Register TimoModule with synchronous options
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* @Module({
|
|
58
|
+
* imports: [
|
|
59
|
+
* TimoModule.forRoot({
|
|
60
|
+
* credentials: process.env.TIMO_CREDENTIALS!,
|
|
61
|
+
* }),
|
|
62
|
+
* ],
|
|
63
|
+
* })
|
|
64
|
+
* export class AppModule {}
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
static forRoot(options: TimoModuleOptions): DynamicModule;
|
|
68
|
+
/**
|
|
69
|
+
* Register TimoModule with asynchronous options
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* @Module({
|
|
74
|
+
* imports: [
|
|
75
|
+
* TimoModule.forRootAsync({
|
|
76
|
+
* imports: [ConfigModule],
|
|
77
|
+
* useFactory: (config: ConfigService) => ({
|
|
78
|
+
* credentials: config.get('TIMO_CREDENTIALS'),
|
|
79
|
+
* }),
|
|
80
|
+
* inject: [ConfigService],
|
|
81
|
+
* }),
|
|
82
|
+
* ],
|
|
83
|
+
* })
|
|
84
|
+
* export class AppModule {}
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class TimoCoreModule implements OnModuleInit {
|
|
91
|
+
private readonly client;
|
|
92
|
+
private readonly options;
|
|
93
|
+
private readonly logger;
|
|
94
|
+
constructor(client: TimoClient, options: TimoModuleOptions);
|
|
95
|
+
onModuleInit(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Synchronous configuration
|
|
98
|
+
*/
|
|
99
|
+
static forRoot(options: TimoModuleOptions): DynamicModule;
|
|
100
|
+
/**
|
|
101
|
+
* Asynchronous configuration
|
|
102
|
+
*/
|
|
103
|
+
static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule;
|
|
104
|
+
private static createClientProvider;
|
|
105
|
+
private static createAsyncProviders;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Injects the TimoClient instance
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* @Injectable()
|
|
114
|
+
* export class PaymentService {
|
|
115
|
+
* constructor(@InjectTimo() private readonly timo: TimoClient) {}
|
|
116
|
+
*
|
|
117
|
+
* async getBalance() {
|
|
118
|
+
* return this.timo.getBalance();
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare const InjectTimo: () => PropertyDecorator & ParameterDecorator;
|
|
124
|
+
|
|
125
|
+
declare const TIMO_CLIENT_TOKEN: unique symbol;
|
|
126
|
+
declare const TIMO_MODULE_OPTIONS: unique symbol;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @timo-bank/nestjs
|
|
130
|
+
* NestJS module for Timo Bank SDK
|
|
131
|
+
*/
|
|
132
|
+
declare const VERSION = "0.1.0";
|
|
133
|
+
|
|
134
|
+
export { InjectTimo, TIMO_CLIENT_TOKEN, TIMO_MODULE_OPTIONS, TimoCoreModule, TimoModule, type TimoModuleAsyncOptions, type TimoModuleOptions, type TimoOptionsFactory, VERSION };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var common = require('@nestjs/common');
|
|
4
|
+
var core = require('@timo-bank/core');
|
|
5
|
+
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
8
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
9
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
10
|
+
if (decorator = decorators[i])
|
|
11
|
+
result = (decorator(result)) || result;
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
15
|
+
|
|
16
|
+
// src/constants/injection-tokens.ts
|
|
17
|
+
var TIMO_CLIENT_TOKEN = /* @__PURE__ */ Symbol("TIMO_CLIENT_TOKEN");
|
|
18
|
+
var TIMO_MODULE_OPTIONS = /* @__PURE__ */ Symbol("TIMO_MODULE_OPTIONS");
|
|
19
|
+
|
|
20
|
+
// src/timo-core.module.ts
|
|
21
|
+
exports.TimoCoreModule = class TimoCoreModule {
|
|
22
|
+
constructor(client, options) {
|
|
23
|
+
this.client = client;
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
26
|
+
logger = new common.Logger(exports.TimoCoreModule.name);
|
|
27
|
+
async onModuleInit() {
|
|
28
|
+
if (this.options.autoLogin !== false) {
|
|
29
|
+
try {
|
|
30
|
+
await this.client.login();
|
|
31
|
+
this.logger.log("Timo client authenticated successfully");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
this.logger.error("Timo client authentication failed", error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Synchronous configuration
|
|
40
|
+
*/
|
|
41
|
+
static forRoot(options) {
|
|
42
|
+
const clientProvider = this.createClientProvider();
|
|
43
|
+
const optionsProvider = {
|
|
44
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
45
|
+
useValue: options
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
module: exports.TimoCoreModule,
|
|
49
|
+
providers: [optionsProvider, clientProvider],
|
|
50
|
+
exports: [TIMO_CLIENT_TOKEN]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Asynchronous configuration
|
|
55
|
+
*/
|
|
56
|
+
static forRootAsync(options) {
|
|
57
|
+
const clientProvider = this.createClientProvider();
|
|
58
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
59
|
+
return {
|
|
60
|
+
module: exports.TimoCoreModule,
|
|
61
|
+
imports: options.imports || [],
|
|
62
|
+
providers: [...asyncProviders, clientProvider],
|
|
63
|
+
exports: [TIMO_CLIENT_TOKEN]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
static createClientProvider() {
|
|
67
|
+
return {
|
|
68
|
+
provide: TIMO_CLIENT_TOKEN,
|
|
69
|
+
useFactory: (options) => {
|
|
70
|
+
return new core.TimoClient({
|
|
71
|
+
credentials: options.credentials,
|
|
72
|
+
logger: options.logger
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
inject: [TIMO_MODULE_OPTIONS]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
static createAsyncProviders(options) {
|
|
79
|
+
if (options.useFactory) {
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
83
|
+
useFactory: options.useFactory,
|
|
84
|
+
inject: options.inject ?? []
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
if (options.useClass) {
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
provide: options.useClass,
|
|
92
|
+
useClass: options.useClass
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
96
|
+
useFactory: async (factory) => factory.createTimoOptions(),
|
|
97
|
+
inject: [options.useClass]
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
if (options.useExisting) {
|
|
102
|
+
return [
|
|
103
|
+
{
|
|
104
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
105
|
+
useFactory: async (factory) => factory.createTimoOptions(),
|
|
106
|
+
inject: [options.useExisting]
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
throw new Error(
|
|
111
|
+
"Invalid TimoModuleAsyncOptions: provide useFactory, useClass, or useExisting"
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.TimoCoreModule = __decorateClass([
|
|
116
|
+
common.Global(),
|
|
117
|
+
common.Module({}),
|
|
118
|
+
__decorateParam(0, common.Inject(TIMO_CLIENT_TOKEN)),
|
|
119
|
+
__decorateParam(1, common.Inject(TIMO_MODULE_OPTIONS))
|
|
120
|
+
], exports.TimoCoreModule);
|
|
121
|
+
|
|
122
|
+
// src/timo.module.ts
|
|
123
|
+
exports.TimoModule = class TimoModule {
|
|
124
|
+
/**
|
|
125
|
+
* Register TimoModule with synchronous options
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* @Module({
|
|
130
|
+
* imports: [
|
|
131
|
+
* TimoModule.forRoot({
|
|
132
|
+
* credentials: process.env.TIMO_CREDENTIALS!,
|
|
133
|
+
* }),
|
|
134
|
+
* ],
|
|
135
|
+
* })
|
|
136
|
+
* export class AppModule {}
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
static forRoot(options) {
|
|
140
|
+
return {
|
|
141
|
+
module: exports.TimoModule,
|
|
142
|
+
imports: [exports.TimoCoreModule.forRoot(options)],
|
|
143
|
+
exports: [exports.TimoCoreModule]
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Register TimoModule with asynchronous options
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* @Module({
|
|
152
|
+
* imports: [
|
|
153
|
+
* TimoModule.forRootAsync({
|
|
154
|
+
* imports: [ConfigModule],
|
|
155
|
+
* useFactory: (config: ConfigService) => ({
|
|
156
|
+
* credentials: config.get('TIMO_CREDENTIALS'),
|
|
157
|
+
* }),
|
|
158
|
+
* inject: [ConfigService],
|
|
159
|
+
* }),
|
|
160
|
+
* ],
|
|
161
|
+
* })
|
|
162
|
+
* export class AppModule {}
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
static forRootAsync(options) {
|
|
166
|
+
return {
|
|
167
|
+
module: exports.TimoModule,
|
|
168
|
+
imports: [exports.TimoCoreModule.forRootAsync(options)],
|
|
169
|
+
exports: [exports.TimoCoreModule]
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
exports.TimoModule = __decorateClass([
|
|
174
|
+
common.Module({})
|
|
175
|
+
], exports.TimoModule);
|
|
176
|
+
var InjectTimo = () => common.Inject(TIMO_CLIENT_TOKEN);
|
|
177
|
+
var VERSION = "0.1.0";
|
|
178
|
+
|
|
179
|
+
Object.defineProperty(exports, "TimoClient", {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function () { return core.TimoClient; }
|
|
182
|
+
});
|
|
183
|
+
exports.InjectTimo = InjectTimo;
|
|
184
|
+
exports.TIMO_CLIENT_TOKEN = TIMO_CLIENT_TOKEN;
|
|
185
|
+
exports.TIMO_MODULE_OPTIONS = TIMO_MODULE_OPTIONS;
|
|
186
|
+
exports.VERSION = VERSION;
|
|
187
|
+
//# sourceMappingURL=index.js.map
|
|
188
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants/injection-tokens.ts","../src/timo-core.module.ts","../src/timo.module.ts","../src/decorators/inject-timo.decorator.ts","../src/index.ts"],"names":["TimoCoreModule","Logger","TimoClient","Global","Module","TimoModule","Inject"],"mappings":";;;;;;;;;;;;;;;;AAAO,IAAM,iBAAA,0BAA2B,mBAAmB;AACpD,IAAM,mBAAA,0BAA6B,qBAAqB;;;ACkBlDA,yBAAN,oBAAA,CAA6C;AAAA,EAGlD,WAAA,CAC8C,QACE,OAAA,EAC9C;AAF4C,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACE,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA,EAC7C;AAAA,EALc,MAAA,GAAS,IAAIC,aAAA,CAAOD,sBAAA,CAAe,IAAI,CAAA;AAAA,EAOxD,MAAM,YAAA,GAA8B;AAClC,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,SAAA,KAAc,KAAA,EAAO;AACpC,MAAA,IAAI;AACF,QAAA,MAAM,IAAA,CAAK,OAAO,KAAA,EAAM;AACxB,QAAA,IAAA,CAAK,MAAA,CAAO,IAAI,wCAAwC,CAAA;AAAA,MAC1D,SAAS,KAAA,EAAO;AACd,QAAA,IAAA,C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,OAAO,QAAQ,OAAA,EAA2C;AACxD,IAAA,OAAO;AAAA,MACL,MAAA,EAAQA,kBAAA;AAAA,MACR,OAAA,EAAS,CAACL,sBAAA,CAAe,OAAA,CAAQ,OAAO,CAAC,CAAA;AAAA,MACzC,OAAA,EAAS,CAACA,sBAAc;AAAA,KAC1B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBA,OAAO,aAAa,OAAA,EAAgD;AAClE,IAAA,OAAO;AAAA,MACL,MAAA,EAAQK,kBAAA;AAAA,MACR,OAAA,EAAS,CAACL,sBAAA,CAAe,YAAA,CAAa,OAAO,CAAC,CAAA;AAAA,MAC9C,OAAA,EAAS,CAACA,sBAAc;AAAA,KAC1B;AAAA,EACF;AACF;AAlDaK,kBAAA,GAAN,eAAA,CAAA;AAAA,EADND,aAAAA,CAAO,EAAE;AAAA,CAAA,EACGC,kBAAA,CAAA;ACaN,IAAM,UAAA,GAAa,MACxBC,aAAAA,CAAO,iBAAiB;ACdnB,IAAM,OAAA,GAAU","file":"index.js","sourcesContent":["export const TIMO_CLIENT_TOKEN = Symbol('TIMO_CLIENT_TOKEN');\nexport const TIMO_MODULE_OPTIONS = Symbol('TIMO_MODULE_OPTIONS');\n","import {\n Global,\n Module,\n DynamicModule,\n Provider,\n OnModuleInit,\n Inject,\n Logger,\n} from '@nestjs/common';\nimport { TimoClient } from '@timo-bank/core';\nimport { TIMO_CLIENT_TOKEN, TIMO_MODULE_OPTIONS } from './constants/injection-tokens.js';\nimport type {\n TimoModuleOptions,\n TimoModuleAsyncOptions,\n TimoOptionsFactory,\n} from './interfaces/timo-options.interface.js';\n\n@Global()\n@Module({})\nexport class TimoCoreModule implements OnModuleInit {\n private readonly logger = new Logger(TimoCoreModule.name);\n\n constructor(\n @Inject(TIMO_CLIENT_TOKEN) private readonly client: TimoClient,\n @Inject(TIMO_MODULE_OPTIONS) private readonly options: TimoModuleOptions\n ) {}\n\n async onModuleInit(): Promise<void> {\n if (this.options.autoLogin !== false) {\n try {\n await this.client.login();\n this.logger.log('Timo client authenticated successfully');\n } catch (error) {\n this.logger.error('Timo client authentication failed', error);\n throw error;\n }\n }\n }\n\n /**\n * Synchronous configuration\n */\n static forRoot(options: TimoModuleOptions): DynamicModule {\n const clientProvider = this.createClientProvider();\n const optionsProvider: Provider = {\n provide: TIMO_MODULE_OPTIONS,\n useValue: options,\n };\n\n return {\n module: TimoCoreModule,\n providers: [optionsProvider, clientProvider],\n exports: [TIMO_CLIENT_TOKEN],\n };\n }\n\n /**\n * Asynchronous configuration\n */\n static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule {\n const clientProvider = this.createClientProvider();\n const asyncProviders = this.createAsyncProviders(options);\n\n return {\n module: TimoCoreModule,\n imports: options.imports || [],\n providers: [...asyncProviders, clientProvider],\n exports: [TIMO_CLIENT_TOKEN],\n };\n }\n\n private static createClientProvider(): Provider {\n return {\n provide: TIMO_CLIENT_TOKEN,\n useFactory: (options: TimoModuleOptions) => {\n return new TimoClient({\n credentials: options.credentials,\n logger: options.logger,\n });\n },\n inject: [TIMO_MODULE_OPTIONS],\n };\n }\n\n private static createAsyncProviders(options: TimoModuleAsyncOptions): Provider[] {\n if (options.useFactory) {\n return [\n {\n provide: TIMO_MODULE_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject ?? [],\n },\n ];\n }\n\n if (options.useClass) {\n return [\n {\n provide: options.useClass,\n useClass: options.useClass,\n },\n {\n provide: TIMO_MODULE_OPTIONS,\n useFactory: async (factory: TimoOptionsFactory) => factory.createTimoOptions(),\n inject: [options.useClass],\n },\n ];\n }\n\n if (options.useExisting) {\n return [\n {\n provide: TIMO_MODULE_OPTIONS,\n useFactory: async (factory: TimoOptionsFactory) => factory.createTimoOptions(),\n inject: [options.useExisting],\n },\n ];\n }\n\n throw new Error(\n 'Invalid TimoModuleAsyncOptions: provide useFactory, useClass, or useExisting'\n );\n }\n}\n","import { Module, DynamicModule } from '@nestjs/common';\nimport { TimoCoreModule } from './timo-core.module.js';\nimport type { TimoModuleOptions, TimoModuleAsyncOptions } from './interfaces/timo-options.interface.js';\n\n@Module({})\nexport class TimoModule {\n /**\n * Register TimoModule with synchronous options\n *\n * @example\n * ```typescript\n * @Module({\n * imports: [\n * TimoModule.forRoot({\n * credentials: process.env.TIMO_CREDENTIALS!,\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n static forRoot(options: TimoModuleOptions): DynamicModule {\n return {\n module: TimoModule,\n imports: [TimoCoreModule.forRoot(options)],\n exports: [TimoCoreModule],\n };\n }\n\n /**\n * Register TimoModule with asynchronous options\n *\n * @example\n * ```typescript\n * @Module({\n * imports: [\n * TimoModule.forRootAsync({\n * imports: [ConfigModule],\n * useFactory: (config: ConfigService) => ({\n * credentials: config.get('TIMO_CREDENTIALS'),\n * }),\n * inject: [ConfigService],\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule {\n return {\n module: TimoModule,\n imports: [TimoCoreModule.forRootAsync(options)],\n exports: [TimoCoreModule],\n };\n }\n}\n","import { Inject } from '@nestjs/common';\nimport { TIMO_CLIENT_TOKEN } from '../constants/injection-tokens.js';\n\n/**\n * Injects the TimoClient instance\n *\n * @example\n * ```typescript\n * @Injectable()\n * export class PaymentService {\n * constructor(@InjectTimo() private readonly timo: TimoClient) {}\n *\n * async getBalance() {\n * return this.timo.getBalance();\n * }\n * }\n * ```\n */\nexport const InjectTimo = (): PropertyDecorator & ParameterDecorator =>\n Inject(TIMO_CLIENT_TOKEN);\n","/**\n * @timo-bank/nestjs\n * NestJS module for Timo Bank SDK\n */\n\nexport const VERSION = '0.1.0';\n\n// Module\nexport { TimoModule } from './timo.module.js';\nexport { TimoCoreModule } from './timo-core.module.js';\n\n// Decorators\nexport { InjectTimo } from './decorators/inject-timo.decorator.js';\n\n// Constants\nexport { TIMO_CLIENT_TOKEN, TIMO_MODULE_OPTIONS } from './constants/injection-tokens.js';\n\n// Interfaces\nexport type {\n TimoModuleOptions,\n TimoModuleAsyncOptions,\n TimoOptionsFactory,\n} from './interfaces/index.js';\n\n// Re-export core types\nexport { TimoClient } from '@timo-bank/core';\nexport type {\n Balance,\n Transaction,\n TransactionOptions,\n AccountInfo,\n UserProfile,\n Logger,\n} from '@timo-bank/core';\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Global, Module, Inject, Logger } from '@nestjs/common';
|
|
2
|
+
import { TimoClient } from '@timo-bank/core';
|
|
3
|
+
export { TimoClient } from '@timo-bank/core';
|
|
4
|
+
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
9
|
+
if (decorator = decorators[i])
|
|
10
|
+
result = (decorator(result)) || result;
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
14
|
+
|
|
15
|
+
// src/constants/injection-tokens.ts
|
|
16
|
+
var TIMO_CLIENT_TOKEN = /* @__PURE__ */ Symbol("TIMO_CLIENT_TOKEN");
|
|
17
|
+
var TIMO_MODULE_OPTIONS = /* @__PURE__ */ Symbol("TIMO_MODULE_OPTIONS");
|
|
18
|
+
|
|
19
|
+
// src/timo-core.module.ts
|
|
20
|
+
var TimoCoreModule = class {
|
|
21
|
+
constructor(client, options) {
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
logger = new Logger(TimoCoreModule.name);
|
|
26
|
+
async onModuleInit() {
|
|
27
|
+
if (this.options.autoLogin !== false) {
|
|
28
|
+
try {
|
|
29
|
+
await this.client.login();
|
|
30
|
+
this.logger.log("Timo client authenticated successfully");
|
|
31
|
+
} catch (error) {
|
|
32
|
+
this.logger.error("Timo client authentication failed", error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Synchronous configuration
|
|
39
|
+
*/
|
|
40
|
+
static forRoot(options) {
|
|
41
|
+
const clientProvider = this.createClientProvider();
|
|
42
|
+
const optionsProvider = {
|
|
43
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
44
|
+
useValue: options
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
module: TimoCoreModule,
|
|
48
|
+
providers: [optionsProvider, clientProvider],
|
|
49
|
+
exports: [TIMO_CLIENT_TOKEN]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Asynchronous configuration
|
|
54
|
+
*/
|
|
55
|
+
static forRootAsync(options) {
|
|
56
|
+
const clientProvider = this.createClientProvider();
|
|
57
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
58
|
+
return {
|
|
59
|
+
module: TimoCoreModule,
|
|
60
|
+
imports: options.imports || [],
|
|
61
|
+
providers: [...asyncProviders, clientProvider],
|
|
62
|
+
exports: [TIMO_CLIENT_TOKEN]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static createClientProvider() {
|
|
66
|
+
return {
|
|
67
|
+
provide: TIMO_CLIENT_TOKEN,
|
|
68
|
+
useFactory: (options) => {
|
|
69
|
+
return new TimoClient({
|
|
70
|
+
credentials: options.credentials,
|
|
71
|
+
logger: options.logger
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
inject: [TIMO_MODULE_OPTIONS]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
static createAsyncProviders(options) {
|
|
78
|
+
if (options.useFactory) {
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
82
|
+
useFactory: options.useFactory,
|
|
83
|
+
inject: options.inject ?? []
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
if (options.useClass) {
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
provide: options.useClass,
|
|
91
|
+
useClass: options.useClass
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
95
|
+
useFactory: async (factory) => factory.createTimoOptions(),
|
|
96
|
+
inject: [options.useClass]
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
if (options.useExisting) {
|
|
101
|
+
return [
|
|
102
|
+
{
|
|
103
|
+
provide: TIMO_MODULE_OPTIONS,
|
|
104
|
+
useFactory: async (factory) => factory.createTimoOptions(),
|
|
105
|
+
inject: [options.useExisting]
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
throw new Error(
|
|
110
|
+
"Invalid TimoModuleAsyncOptions: provide useFactory, useClass, or useExisting"
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
TimoCoreModule = __decorateClass([
|
|
115
|
+
Global(),
|
|
116
|
+
Module({}),
|
|
117
|
+
__decorateParam(0, Inject(TIMO_CLIENT_TOKEN)),
|
|
118
|
+
__decorateParam(1, Inject(TIMO_MODULE_OPTIONS))
|
|
119
|
+
], TimoCoreModule);
|
|
120
|
+
|
|
121
|
+
// src/timo.module.ts
|
|
122
|
+
var TimoModule = class {
|
|
123
|
+
/**
|
|
124
|
+
* Register TimoModule with synchronous options
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* @Module({
|
|
129
|
+
* imports: [
|
|
130
|
+
* TimoModule.forRoot({
|
|
131
|
+
* credentials: process.env.TIMO_CREDENTIALS!,
|
|
132
|
+
* }),
|
|
133
|
+
* ],
|
|
134
|
+
* })
|
|
135
|
+
* export class AppModule {}
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
static forRoot(options) {
|
|
139
|
+
return {
|
|
140
|
+
module: TimoModule,
|
|
141
|
+
imports: [TimoCoreModule.forRoot(options)],
|
|
142
|
+
exports: [TimoCoreModule]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Register TimoModule with asynchronous options
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* @Module({
|
|
151
|
+
* imports: [
|
|
152
|
+
* TimoModule.forRootAsync({
|
|
153
|
+
* imports: [ConfigModule],
|
|
154
|
+
* useFactory: (config: ConfigService) => ({
|
|
155
|
+
* credentials: config.get('TIMO_CREDENTIALS'),
|
|
156
|
+
* }),
|
|
157
|
+
* inject: [ConfigService],
|
|
158
|
+
* }),
|
|
159
|
+
* ],
|
|
160
|
+
* })
|
|
161
|
+
* export class AppModule {}
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
static forRootAsync(options) {
|
|
165
|
+
return {
|
|
166
|
+
module: TimoModule,
|
|
167
|
+
imports: [TimoCoreModule.forRootAsync(options)],
|
|
168
|
+
exports: [TimoCoreModule]
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
TimoModule = __decorateClass([
|
|
173
|
+
Module({})
|
|
174
|
+
], TimoModule);
|
|
175
|
+
var InjectTimo = () => Inject(TIMO_CLIENT_TOKEN);
|
|
176
|
+
var VERSION = "0.1.0";
|
|
177
|
+
|
|
178
|
+
export { InjectTimo, TIMO_CLIENT_TOKEN, TIMO_MODULE_OPTIONS, TimoCoreModule, TimoModule, VERSION };
|
|
179
|
+
//# sourceMappingURL=index.mjs.map
|
|
180
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants/injection-tokens.ts","../src/timo-core.module.ts","../src/timo.module.ts","../src/decorators/inject-timo.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AAAA,CAAA,EACG,UAAA,CAAA;ACaN,IAAM,UAAA,GAAa,MACxBC,MAAAA,CAAO,iBAAiB;ACdnB,IAAM,OAAA,GAAU","file":"index.mjs","sourcesContent":["export const TIMO_CLIENT_TOKEN = Symbol('TIMO_CLIENT_TOKEN');\nexport const TIMO_MODULE_OPTIONS = Symbol('TIMO_MODULE_OPTIONS');\n","import {\n Global,\n Module,\n DynamicModule,\n Provider,\n OnModuleInit,\n Inject,\n Logger,\n} from '@nestjs/common';\nimport { TimoClient } from '@timo-bank/core';\nimport { TIMO_CLIENT_TOKEN, TIMO_MODULE_OPTIONS } from './constants/injection-tokens.js';\nimport type {\n TimoModuleOptions,\n TimoModuleAsyncOptions,\n TimoOptionsFactory,\n} from './interfaces/timo-options.interface.js';\n\n@Global()\n@Module({})\nexport class TimoCoreModule implements OnModuleInit {\n private readonly logger = new Logger(TimoCoreModule.name);\n\n constructor(\n @Inject(TIMO_CLIENT_TOKEN) private readonly client: TimoClient,\n @Inject(TIMO_MODULE_OPTIONS) private readonly options: TimoModuleOptions\n ) {}\n\n async onModuleInit(): Promise<void> {\n if (this.options.autoLogin !== false) {\n try {\n await this.client.login();\n this.logger.log('Timo client authenticated successfully');\n } catch (error) {\n this.logger.error('Timo client authentication failed', error);\n throw error;\n }\n }\n }\n\n /**\n * Synchronous configuration\n */\n static forRoot(options: TimoModuleOptions): DynamicModule {\n const clientProvider = this.createClientProvider();\n const optionsProvider: Provider = {\n provide: TIMO_MODULE_OPTIONS,\n useValue: options,\n };\n\n return {\n module: TimoCoreModule,\n providers: [optionsProvider, clientProvider],\n exports: [TIMO_CLIENT_TOKEN],\n };\n }\n\n /**\n * Asynchronous configuration\n */\n static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule {\n const clientProvider = this.createClientProvider();\n const asyncProviders = this.createAsyncProviders(options);\n\n return {\n module: TimoCoreModule,\n imports: options.imports || [],\n providers: [...asyncProviders, clientProvider],\n exports: [TIMO_CLIENT_TOKEN],\n };\n }\n\n private static createClientProvider(): Provider {\n return {\n provide: TIMO_CLIENT_TOKEN,\n useFactory: (options: TimoModuleOptions) => {\n return new TimoClient({\n credentials: options.credentials,\n logger: options.logger,\n });\n },\n inject: [TIMO_MODULE_OPTIONS],\n };\n }\n\n private static createAsyncProviders(options: TimoModuleAsyncOptions): Provider[] {\n if (options.useFactory) {\n return [\n {\n provide: TIMO_MODULE_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject ?? [],\n },\n ];\n }\n\n if (options.useClass) {\n return [\n {\n provide: options.useClass,\n useClass: options.useClass,\n },\n {\n provide: TIMO_MODULE_OPTIONS,\n useFactory: async (factory: TimoOptionsFactory) => factory.createTimoOptions(),\n inject: [options.useClass],\n },\n ];\n }\n\n if (options.useExisting) {\n return [\n {\n provide: TIMO_MODULE_OPTIONS,\n useFactory: async (factory: TimoOptionsFactory) => factory.createTimoOptions(),\n inject: [options.useExisting],\n },\n ];\n }\n\n throw new Error(\n 'Invalid TimoModuleAsyncOptions: provide useFactory, useClass, or useExisting'\n );\n }\n}\n","import { Module, DynamicModule } from '@nestjs/common';\nimport { TimoCoreModule } from './timo-core.module.js';\nimport type { TimoModuleOptions, TimoModuleAsyncOptions } from './interfaces/timo-options.interface.js';\n\n@Module({})\nexport class TimoModule {\n /**\n * Register TimoModule with synchronous options\n *\n * @example\n * ```typescript\n * @Module({\n * imports: [\n * TimoModule.forRoot({\n * credentials: process.env.TIMO_CREDENTIALS!,\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n static forRoot(options: TimoModuleOptions): DynamicModule {\n return {\n module: TimoModule,\n imports: [TimoCoreModule.forRoot(options)],\n exports: [TimoCoreModule],\n };\n }\n\n /**\n * Register TimoModule with asynchronous options\n *\n * @example\n * ```typescript\n * @Module({\n * imports: [\n * TimoModule.forRootAsync({\n * imports: [ConfigModule],\n * useFactory: (config: ConfigService) => ({\n * credentials: config.get('TIMO_CREDENTIALS'),\n * }),\n * inject: [ConfigService],\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n static forRootAsync(options: TimoModuleAsyncOptions): DynamicModule {\n return {\n module: TimoModule,\n imports: [TimoCoreModule.forRootAsync(options)],\n exports: [TimoCoreModule],\n };\n }\n}\n","import { Inject } from '@nestjs/common';\nimport { TIMO_CLIENT_TOKEN } from '../constants/injection-tokens.js';\n\n/**\n * Injects the TimoClient instance\n *\n * @example\n * ```typescript\n * @Injectable()\n * export class PaymentService {\n * constructor(@InjectTimo() private readonly timo: TimoClient) {}\n *\n * async getBalance() {\n * return this.timo.getBalance();\n * }\n * }\n * ```\n */\nexport const InjectTimo = (): PropertyDecorator & ParameterDecorator =>\n Inject(TIMO_CLIENT_TOKEN);\n","/**\n * @timo-bank/nestjs\n * NestJS module for Timo Bank SDK\n */\n\nexport const VERSION = '0.1.0';\n\n// Module\nexport { TimoModule } from './timo.module.js';\nexport { TimoCoreModule } from './timo-core.module.js';\n\n// Decorators\nexport { InjectTimo } from './decorators/inject-timo.decorator.js';\n\n// Constants\nexport { TIMO_CLIENT_TOKEN, TIMO_MODULE_OPTIONS } from './constants/injection-tokens.js';\n\n// Interfaces\nexport type {\n TimoModuleOptions,\n TimoModuleAsyncOptions,\n TimoOptionsFactory,\n} from './interfaces/index.js';\n\n// Re-export core types\nexport { TimoClient } from '@timo-bank/core';\nexport type {\n Balance,\n Transaction,\n TransactionOptions,\n AccountInfo,\n UserProfile,\n Logger,\n} from '@timo-bank/core';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@timo-bank/nestjs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Unofficial Timo Bank SDK - NestJS module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"clean": "rimraf dist",
|
|
22
|
+
"typecheck": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"timo",
|
|
26
|
+
"bank",
|
|
27
|
+
"vietnam",
|
|
28
|
+
"banking",
|
|
29
|
+
"sdk",
|
|
30
|
+
"nestjs",
|
|
31
|
+
"module"
|
|
32
|
+
],
|
|
33
|
+
"author": "quanganh208",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"homepage": "https://github.com/quanganh208/timo-bank#readme",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/quanganh208/timo-bank.git",
|
|
39
|
+
"directory": "packages/nestjs"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/quanganh208/timo-bank/issues"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@timo-bank/core": "workspace:*"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@nestjs/common": ">=9.0.0",
|
|
52
|
+
"@nestjs/core": ">=9.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@nestjs/common": "^10.0.0",
|
|
56
|
+
"@nestjs/core": "^10.0.0",
|
|
57
|
+
"reflect-metadata": "^0.2.0",
|
|
58
|
+
"rimraf": "^5.0.0",
|
|
59
|
+
"rxjs": "^7.8.0",
|
|
60
|
+
"tsup": "^8.0.0",
|
|
61
|
+
"typescript": "^5.4.0"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18.0.0"
|
|
65
|
+
}
|
|
66
|
+
}
|