@verana-labs/vs-agent-nestjs-client 2.0.0-dev.7 → 2.0.0-dev.72
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 +61 -201
- package/build/app.module.js +26 -34
- package/build/app.module.js.map +1 -1
- package/build/connections/connection.entity.d.ts +4 -5
- package/build/connections/connection.entity.js +2 -10
- package/build/connections/connection.entity.js.map +1 -1
- package/build/connections/connection.repository.d.ts +6 -20
- package/build/connections/connection.repository.js +12 -40
- package/build/connections/connection.repository.js.map +1 -1
- package/build/connections/connection.service.d.ts +8 -17
- package/build/connections/connection.service.js +33 -54
- package/build/connections/connection.service.js.map +1 -1
- package/build/connections/index.d.ts +0 -2
- package/build/connections/index.js +0 -2
- package/build/connections/index.js.map +1 -1
- package/build/credentials/credential.entity.d.ts +1 -1
- package/build/credentials/credential.entity.js +1 -1
- package/build/credentials/credential.entity.js.map +1 -1
- package/build/credentials/credential.service.d.ts +22 -90
- package/build/credentials/credential.service.js +106 -205
- package/build/credentials/credential.service.js.map +1 -1
- package/build/credentials/index.d.ts +0 -1
- package/build/credentials/index.js +0 -1
- package/build/credentials/index.js.map +1 -1
- package/build/events.controller.d.ts +9 -0
- package/build/events.controller.js +47 -0
- package/build/events.controller.js.map +1 -0
- package/build/events.service.d.ts +12 -0
- package/build/events.service.js +80 -0
- package/build/events.service.js.map +1 -0
- package/build/index.d.ts +4 -3
- package/build/index.js +4 -3
- package/build/index.js.map +1 -1
- package/build/interfaces.d.ts +2 -28
- package/build/jms/index.d.ts +1 -1
- package/build/jms/index.js +4 -1
- package/build/jms/index.js.map +1 -1
- package/build/jms/stats-producer.service.d.ts +3 -4
- package/build/jms/stats-producer.service.js +3 -4
- package/build/jms/stats-producer.service.js.map +1 -1
- package/build/tokens.d.ts +3 -0
- package/build/tokens.js +7 -0
- package/build/tokens.js.map +1 -0
- package/build/types.d.ts +25 -53
- package/build/types.js +7 -1
- package/build/types.js.map +1 -1
- package/package.json +3 -9
- package/build/connections/connection.controller.d.ts +0 -10
- package/build/connections/connection.controller.js +0 -65
- package/build/connections/connection.controller.js.map +0 -1
- package/build/connections/connection.module.d.ts +0 -5
- package/build/connections/connection.module.js +0 -44
- package/build/connections/connection.module.js.map +0 -1
- package/build/credentials/credential.module.d.ts +0 -5
- package/build/credentials/credential.module.js +0 -34
- package/build/credentials/credential.module.js.map +0 -1
- package/build/jms/stats.module.d.ts +0 -5
- package/build/jms/stats.module.js +0 -34
- package/build/jms/stats.module.js.map +0 -1
- package/build/messages/index.d.ts +0 -3
- package/build/messages/index.js +0 -20
- package/build/messages/index.js.map +0 -1
- package/build/messages/message.controller.d.ts +0 -13
- package/build/messages/message.controller.js +0 -95
- package/build/messages/message.controller.js.map +0 -1
- package/build/messages/message.module.d.ts +0 -5
- package/build/messages/message.module.js +0 -41
- package/build/messages/message.module.js.map +0 -1
- package/build/messages/message.service.d.ts +0 -19
- package/build/messages/message.service.js +0 -104
- package/build/messages/message.service.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,222 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
1. Message Handling:
|
|
7
|
-
- Manages the events related to message states, including when a message is sent, delivered, or received.
|
|
8
|
-
- Use this module if you're integrating messaging functionality into your application.
|
|
9
|
-
2. Credential Management:
|
|
10
|
-
- Handles the lifecycle of credentials, including offering, accepting, rejecting, and revoking credentials.
|
|
11
|
-
- This module is typically used when you need to manage digital credentials for your application.
|
|
12
|
-
3. Connection Management:
|
|
13
|
-
- Manages events related to connection state changes.
|
|
14
|
-
|
|
15
|
-
## How to work
|
|
16
|
-
```mermaid
|
|
17
|
-
classDiagram
|
|
18
|
-
class VsAgent {
|
|
19
|
-
+ Handles DIDComm communication
|
|
20
|
-
+ Manages agent wallet and credentials
|
|
21
|
-
+ Exposes API for client interactions
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
class NestJSClient {
|
|
25
|
-
+ Plug-and-play integration
|
|
26
|
-
+ Selectable modules for various services
|
|
27
|
-
+ Modules:
|
|
28
|
-
-- MessageEventOptions: Configures message event handling
|
|
29
|
-
-- ConnectionEventOptions: Configures connection event handling
|
|
30
|
-
-- CredentialOptions: Configures credential management
|
|
31
|
-
-- StatsOptions: Configures stats management
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class Client {
|
|
35
|
-
+ Directly manages requests to SA
|
|
36
|
-
+ Facilitates reception of requests from modules
|
|
37
|
-
+ Provides an abstraction for service communication
|
|
38
|
-
+ Interfaces:
|
|
39
|
-
-- messages
|
|
40
|
-
-- credentialTypes
|
|
41
|
-
-- revocationRegistries
|
|
42
|
-
-- invitations
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
class ModelLibrary {
|
|
46
|
-
+ Defines required data models
|
|
47
|
-
+ Ensures type safety across services
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
%% Relations
|
|
51
|
-
NestJSClient --> VsAgent : Uses
|
|
52
|
-
Client --> VsAgent : Sends requests
|
|
53
|
-
Client --> VsAgent : Receives requests
|
|
54
|
-
Client --> ModelLibrary : Uses models
|
|
55
|
-
ModelLibrary --> VsAgent : Provides data models
|
|
56
|
-
NestJSClient --> ModelLibrary : Uses models
|
|
57
|
-
|
|
58
|
-
%% Style
|
|
59
|
-
style NestJSClient stroke:#333,stroke-width:4px
|
|
60
|
-
```
|
|
1
|
+
# @verana-labs/vs-agent-nestjs-client
|
|
2
|
+
|
|
3
|
+
NestJS module for hosts of a VS Agent. It mounts the Events API webhook, keeps a small table of connections and issued credentials, and provides a configured `ApiClient` from `@verana-labs/vs-agent-client` for injection. Everything the client exports is re-exported here.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
61
6
|
|
|
62
|
-
## Configuration
|
|
63
|
-
### Dynamic Module Setup
|
|
64
|
-
The `nestjs-client` allows dynamic configuration through various module options defined in `types.ts`. You can configure individual modules or the `EventsModule` for handling multiple events at once
|
|
65
|
-
### Key Configuration Options
|
|
66
|
-
- `eventHandler`: Specifies the event handler class to handle incoming events. It must implement the `EventHandler` interface.
|
|
67
|
-
- `imports`: An array of additional modules to import, such as service modules or other shared functionality.
|
|
68
|
-
- `url`: VS Agent Admin API URL
|
|
69
|
-
- `version`: Specifies the version of VS Agent API to use.
|
|
70
|
-
- `statOptions`: Configuration options for the **JMS (Jakarta Message Service) broker**, including host, port, queue name, authentication, and reconnection settings. The default broker used is **Apache Artemis**.
|
|
71
|
-
|
|
72
|
-
### `statOptions` Parameters
|
|
73
|
-
The `statOptions` object includes the following properties for configuring the message broker:
|
|
74
|
-
|
|
75
|
-
| Parameter | Type | Description |
|
|
76
|
-
|---------------|---------|-------------|
|
|
77
|
-
| `host` | `string` | The hostname or IP address of the JMS broker. |
|
|
78
|
-
| `port` | `number` | The port used to connect to the JMS broker. |
|
|
79
|
-
| `queue` | `string` | The name of the message queue to use. |
|
|
80
|
-
| `username` | `string` | The username for authenticating with the broker (if required). |
|
|
81
|
-
| `password` | `string` | The password for authentication (if required). |
|
|
82
|
-
| `reconnectLimit` | `number` | The maximum number of reconnection attempts in case of a connection failure. |
|
|
83
|
-
| `threads` | `number` | The number of worker threads for processing messages. |
|
|
84
|
-
| `delay` | `number` | The delay (in milliseconds) before retrying a failed connection or message processing. |
|
|
85
|
-
|
|
86
|
-
#### `MessageEventOptions`
|
|
87
|
-
Configures message event handling. The following properties are available:
|
|
88
|
-
- `eventHandler` (optional).
|
|
89
|
-
- `imports` (optional).
|
|
90
|
-
- `url` (mandatory).
|
|
91
|
-
- `version` (optional).
|
|
92
|
-
#### `ConnectionEventOptions`
|
|
93
|
-
Configures connection event handling. The following properties are available:
|
|
94
|
-
- `eventHandler` (optional).
|
|
95
|
-
- `imports` (optional).
|
|
96
|
-
|
|
97
|
-
#### `CredentialOptions`
|
|
98
|
-
Configures credential management. The following properties are available:
|
|
99
|
-
- `imports` (optional).
|
|
100
|
-
- `url` (mandatory).
|
|
101
|
-
- `version` (optional).
|
|
102
|
-
|
|
103
|
-
#### `StatsOptions`
|
|
104
|
-
Configures stats management. The following properties are available:
|
|
105
|
-
- `imports` (optional).
|
|
106
|
-
- `statOptions` (optional).
|
|
107
|
-
|
|
108
|
-
##### Example of Using the `StatEventModule`
|
|
109
|
-
|
|
110
|
-
This example demonstrates how to configure and use the `StatEventModule` to send and process statistics using a JMS broker:
|
|
111
|
-
|
|
112
|
-
- **AppModule**
|
|
113
7
|
```typescript
|
|
114
|
-
import {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
host: 'jms-broker.example.com',
|
|
125
|
-
port: 61616,
|
|
126
|
-
queue: 'stats-queue', // The queue must be unique
|
|
127
|
-
username: 'admin',
|
|
128
|
-
password: 'password123',
|
|
129
|
-
reconnectLimit: 5,
|
|
130
|
-
threads: 10,
|
|
131
|
-
delay: 1000,
|
|
132
|
-
},
|
|
133
|
-
eventHandler: CoreService,
|
|
134
|
-
url: 'http://localhost',
|
|
135
|
-
imports: [],
|
|
136
|
-
},
|
|
8
|
+
import { EventsModule } from '@verana-labs/vs-agent-nestjs-client'
|
|
9
|
+
|
|
10
|
+
@Module({
|
|
11
|
+
imports: [
|
|
12
|
+
EventsModule.register({
|
|
13
|
+
url: process.env.VS_AGENT_ADMIN_URL,
|
|
14
|
+
eventHandler: CoreService,
|
|
15
|
+
modules: { connections: true, credentials: true },
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
137
18
|
})
|
|
19
|
+
export class AppModule {}
|
|
138
20
|
```
|
|
139
21
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
22
|
+
Options:
|
|
23
|
+
|
|
24
|
+
| Option | Description |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `url` | Admin API origin, for example `http://localhost:3000`. The client appends `/v2` |
|
|
27
|
+
| `token` | Bearer token for corporation mode. Omit in internal mode |
|
|
28
|
+
| `webhookApiKey` | When set, `POST /events` requires `Authorization: Bearer <webhookApiKey>` |
|
|
29
|
+
| `eventHandler` | Class implementing `EventHandler`, registered as a provider |
|
|
30
|
+
| `modules.connections` | `true` or `{ requireProfile }`. Tracks connections and derives `newConnection` and `closeConnection`. With `requireProfile`, `newConnection` waits for a profile carrying `preferredLanguage` |
|
|
31
|
+
| `modules.credentials` | Tracks issued credentials and their revocation registries |
|
|
32
|
+
| `modules.stats` | Registers `StatProducerService` |
|
|
33
|
+
| `statOptions` | JMS broker settings for the stats producer (`host`, `port`, `queue`, `username`, `password`, `reconnectLimit`, `threads`, `delay`) |
|
|
34
|
+
|
|
35
|
+
The module is global. It exports `VS_AGENT_CLIENT` and whichever of `ConnectionsRepository`, `ConnectionsService`, `CredentialService` and `StatProducerService` are registered.
|
|
146
36
|
|
|
147
|
-
|
|
148
|
-
|
|
37
|
+
The host owns the database. Register the entities it uses with `TypeOrmModule.forFeature([ConnectionEntity, CredentialEntity, RevocationRegistryEntity])` in a module that exports `TypeOrmModule`. Migration based deployments coming from the v1 client write one migration for the `connections.status` enum (now `start`, `completed`, `terminated`), the dropped `connections.metadata` column and the `credentials.threadId` to `credentialExchangeId` rename.
|
|
38
|
+
|
|
39
|
+
## Webhook
|
|
40
|
+
|
|
41
|
+
The module mounts `POST /events` and answers 204. Point the agent's `EVENTS_WEBHOOK_URL` at it. A repeated envelope `id` is discarded before dispatch. Errors thrown by `onEvent` propagate, so the agent logs the delivery as failed.
|
|
42
|
+
|
|
43
|
+
## EventHandler
|
|
149
44
|
|
|
150
45
|
```typescript
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
constructor(
|
|
156
|
-
@InjectRepository(SessionEntity)
|
|
157
|
-
private readonly statProducer: StatProducerService,
|
|
158
|
-
) {}
|
|
159
|
-
|
|
160
|
-
await this.statProducer.spool(STAT_KPI.USER_CONNECTED, 'uuid', [new StatEnum(0, 'string')])
|
|
46
|
+
export interface EventHandler {
|
|
47
|
+
newConnection(connectionId: string): Promise<void> | void
|
|
48
|
+
closeConnection(connectionId: string): Promise<void> | void
|
|
49
|
+
onEvent(envelope: EventEnvelope | UnknownEventEnvelope): Promise<void> | void
|
|
161
50
|
}
|
|
162
51
|
```
|
|
163
52
|
|
|
53
|
+
`onEvent` receives every envelope after the module has acted on it. Check `isEventEnvelope(envelope)` first, then switch on `envelope.type` to get typed `envelope.data`. The else branch is reachable: extension modules emit types the map does not list, and there `envelope.data` is `unknown`.
|
|
164
54
|
|
|
165
|
-
|
|
166
|
-
This interface defines the configuration for enabling or disabling modules:
|
|
167
|
-
- `messages` (optional): Whether to enable the message handling module. Defaults to false.
|
|
168
|
-
- `connections` (optional): Whether to enable the connection management module. Defaults to false.
|
|
169
|
-
- `credentials` (optional): Whether to enable the credential management module. Defaults to false.
|
|
170
|
-
- `stats` (optional): Whether to enable the stats management module. Defaults to false.
|
|
55
|
+
## Connections
|
|
171
56
|
|
|
172
|
-
|
|
173
|
-
This configuration interface is used to configure multiple modules at once via the EventsModule:
|
|
174
|
-
- `modules`: Specifies which modules to enable (messages, connections, and credentials).
|
|
175
|
-
- `options`: Contains common configuration options that apply to each module, such as eventHandler, imports, url, and version.
|
|
57
|
+
`didcomm.connections.state-updated` with `state: 'completed'` creates the row. `didcomm.user-profile.profile-received` stores the profile. `newConnection` fires once per connection, once it is `completed` and a profile with `preferredLanguage` has been received when `requireProfile` is true (the default), or right after `completed` when it is false. `closeConnection` fires on `state: 'abandoned'`. A peer hangup by DID rotation emits no Events API event today, so it does not reach `closeConnection`.
|
|
176
58
|
|
|
59
|
+
`newConnection` also fires for the connection each accepted credential offer or proof request creates, since those go through an out of band invitation.
|
|
177
60
|
|
|
61
|
+
## Credentials
|
|
178
62
|
|
|
63
|
+
`CredentialService` wraps the v2 credential offer flow.
|
|
179
64
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
url: 'http://vsa-url.com',
|
|
189
|
-
version: ApiVersion.V1,
|
|
190
|
-
}),
|
|
191
|
-
CredentialManagementModule.forRoot({
|
|
192
|
-
// Configuration options
|
|
193
|
-
}),
|
|
194
|
-
],
|
|
195
|
-
})
|
|
196
|
-
export class AppModule {}
|
|
197
|
-
```
|
|
65
|
+
- `createCredentialDefinition(jsonSchemaCredentialId, { supportRevocation, maximumCredentialNumber })` returns the definition for that schema, creating it and two revocation registries when missing. Call it once at startup.
|
|
66
|
+
- `issue(claims, { connectionId, refId, credentialDefinitionId, jsonSchemaCredentialId, revokeIfAlreadyIssued })` picks a definition, reserves a revocation index and calls `createCredentialOffer` with `autoAccept: true`. It returns the offer, hand its `shortUrl` to the user. `connectionId` is bookkeeping only, it is the connection `revoke(connectionId)` looks up by. `issue` no longer registers a credential definition, run `createCredentialDefinition` first.
|
|
67
|
+
- `didcomm.credential-exchanges.state-updated` with `role: 'issuer'` marks the row accepted on `done` and rejected on `declined` or `abandoned`.
|
|
68
|
+
- `revoke(connectionId, credentialExchangeId?)` revokes the latest accepted credential of the connection, or the given exchange, through `revokeCredential`.
|
|
69
|
+
|
|
70
|
+
## Client
|
|
71
|
+
|
|
72
|
+
Inject the configured client anywhere:
|
|
198
73
|
|
|
199
|
-
### Example of Using the Recommended `EventsModule`
|
|
200
|
-
The recommended approach is to use the `EventsModule` to register multiple modules at once for easier configuration:
|
|
201
74
|
```typescript
|
|
202
|
-
@
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
modules: {
|
|
206
|
-
messages: true,
|
|
207
|
-
credentials: true,
|
|
208
|
-
},
|
|
209
|
-
options: {
|
|
210
|
-
eventHandler: CoreService,
|
|
211
|
-
imports: [],
|
|
212
|
-
url: process.env.VS_AGENT_ADMIN_URL,
|
|
213
|
-
version: ApiVersion.V1,
|
|
214
|
-
},
|
|
215
|
-
}),
|
|
216
|
-
],
|
|
217
|
-
})
|
|
218
|
-
export class AppModule {}
|
|
75
|
+
constructor(@Inject(VS_AGENT_CLIENT) private readonly client: ApiClient) {}
|
|
76
|
+
|
|
77
|
+
await this.client.didcomm.sendBasicMessage({ connectionId, content: 'hello' })
|
|
219
78
|
```
|
|
220
|
-
In this example, the `EventsModule` is used to register multiple modules simultaneously, which ensures better integration and streamlined configuration for common use cases.
|
|
221
79
|
|
|
222
|
-
|
|
80
|
+
## Stats
|
|
81
|
+
|
|
82
|
+
With `modules.stats` the `StatProducerService` sends `StatEvent` messages to a JMS queue. Call `spool(statClass, entityId, [new StatEnum(0, 'value')])` or `spoolSingle`.
|
package/build/app.module.js
CHANGED
|
@@ -9,48 +9,40 @@ var EventsModule_1;
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.EventsModule = void 0;
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
|
+
const vs_agent_client_1 = require("@verana-labs/vs-agent-client");
|
|
12
13
|
const connections_1 = require("./connections");
|
|
13
14
|
const credentials_1 = require("./credentials");
|
|
15
|
+
const events_controller_1 = require("./events.controller");
|
|
16
|
+
const events_service_1 = require("./events.service");
|
|
14
17
|
const jms_1 = require("./jms");
|
|
15
|
-
const
|
|
18
|
+
const tokens_1 = require("./tokens");
|
|
16
19
|
let EventsModule = EventsModule_1 = class EventsModule {
|
|
17
20
|
static register(options) {
|
|
18
|
-
var _a
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
const { connections, credentials, stats } = (_a = options.modules) !== null && _a !== void 0 ? _a : {};
|
|
23
|
+
const providers = [
|
|
24
|
+
{ provide: tokens_1.EVENTS_MODULE_OPTIONS, useValue: options },
|
|
25
|
+
{ provide: tokens_1.EVENT_HANDLER, useClass: options.eventHandler },
|
|
26
|
+
{
|
|
27
|
+
provide: tokens_1.VS_AGENT_CLIENT,
|
|
28
|
+
useFactory: () => new vs_agent_client_1.ApiClient(options.url, { token: options.token }),
|
|
29
|
+
},
|
|
30
|
+
events_service_1.EventsService,
|
|
31
|
+
];
|
|
32
|
+
const exports = [tokens_1.VS_AGENT_CLIENT];
|
|
33
|
+
if (connections) {
|
|
34
|
+
providers.push(connections_1.ConnectionsRepository, connections_1.ConnectionsService);
|
|
35
|
+
exports.push(connections_1.ConnectionsRepository, connections_1.ConnectionsService);
|
|
28
36
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
imports: (_b = moduleOptions.imports) !== null && _b !== void 0 ? _b : [],
|
|
33
|
-
useMessages: modules.messages,
|
|
34
|
-
}));
|
|
37
|
+
if (credentials) {
|
|
38
|
+
providers.push(credentials_1.CredentialService);
|
|
39
|
+
exports.push(credentials_1.CredentialService);
|
|
35
40
|
}
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
url: moduleOptions.url,
|
|
40
|
-
version: moduleOptions.version,
|
|
41
|
-
}));
|
|
41
|
+
if (stats) {
|
|
42
|
+
providers.push(jms_1.StatProducerService);
|
|
43
|
+
exports.push(jms_1.StatProducerService);
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
imports.push(jms_1.StatEventModule.forRoot({
|
|
45
|
-
imports: (_d = moduleOptions.imports) !== null && _d !== void 0 ? _d : [],
|
|
46
|
-
statOptions: moduleOptions.statOptions,
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
module: EventsModule_1,
|
|
51
|
-
imports,
|
|
52
|
-
exports: imports,
|
|
53
|
-
};
|
|
45
|
+
return { module: EventsModule_1, controllers: [events_controller_1.EventsController], providers, exports };
|
|
54
46
|
}
|
|
55
47
|
};
|
|
56
48
|
exports.EventsModule = EventsModule;
|
package/build/app.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAwE;AACxE,kEAAwD;AAExD,+CAAyE;AACzE,+CAAiD;AACjD,2DAAsD;AACtD,qDAAgD;AAChD,+BAA2C;AAC3C,qCAAgF;AAKzE,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAChB,MAAM,CAAC,QAAQ,CAAC,OAA4B;;QACjD,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAA;QACjE,MAAM,SAAS,GAAe;YAC5B,EAAE,OAAO,EAAE,8BAAqB,EAAE,QAAQ,EAAE,OAAO,EAAE;YACrD,EAAE,OAAO,EAAE,sBAAa,EAAE,QAAQ,EAAE,OAAO,CAAC,YAAY,EAAE;YAC1D;gBACE,OAAO,EAAE,wBAAe;gBACxB,UAAU,EAAE,GAAc,EAAE,CAAC,IAAI,2BAAS,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;aAClF;YACD,8BAAa;SACd,CAAA;QACD,MAAM,OAAO,GAA0C,CAAC,wBAAe,CAAC,CAAA;QAExE,IAAI,WAAW,EAAE,CAAC;YAChB,SAAS,CAAC,IAAI,CAAC,mCAAqB,EAAE,gCAAkB,CAAC,CAAA;YACzD,OAAO,CAAC,IAAI,CAAC,mCAAqB,EAAE,gCAAkB,CAAC,CAAA;QACzD,CAAC;QACD,IAAI,WAAW,EAAE,CAAC;YAChB,SAAS,CAAC,IAAI,CAAC,+BAAiB,CAAC,CAAA;YACjC,OAAO,CAAC,IAAI,CAAC,+BAAiB,CAAC,CAAA;QACjC,CAAC;QACD,IAAI,KAAK,EAAE,CAAC;YACV,SAAS,CAAC,IAAI,CAAC,yBAAmB,CAAC,CAAA;YACnC,OAAO,CAAC,IAAI,CAAC,yBAAmB,CAAC,CAAA;QACnC,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,cAAY,EAAE,WAAW,EAAE,CAAC,oCAAgB,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAA;IACtF,CAAC;CACF,CAAA;AA7BY,oCAAY;uBAAZ,YAAY;IAFxB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,YAAY,CA6BxB"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReceivedUserProfile } from '@verana-labs/vs-agent-client';
|
|
2
|
+
import { ConnectionStatus } from '../types';
|
|
3
3
|
export declare class ConnectionEntity {
|
|
4
4
|
id?: string;
|
|
5
|
-
status?:
|
|
6
|
-
userProfile?:
|
|
5
|
+
status?: ConnectionStatus;
|
|
6
|
+
userProfile?: ReceivedUserProfile;
|
|
7
7
|
createdTs?: Date;
|
|
8
8
|
updatedTs?: Date;
|
|
9
|
-
metadata?: Record<string, any>;
|
|
10
9
|
}
|
|
@@ -10,8 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ConnectionEntity = void 0;
|
|
13
|
-
const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
|
|
14
13
|
const typeorm_1 = require("typeorm");
|
|
14
|
+
const types_1 = require("../types");
|
|
15
15
|
let ConnectionEntity = class ConnectionEntity {
|
|
16
16
|
};
|
|
17
17
|
exports.ConnectionEntity = ConnectionEntity;
|
|
@@ -20,11 +20,7 @@ __decorate([
|
|
|
20
20
|
__metadata("design:type", String)
|
|
21
21
|
], ConnectionEntity.prototype, "id", void 0);
|
|
22
22
|
__decorate([
|
|
23
|
-
(0, typeorm_1.Column)({
|
|
24
|
-
type: 'enum',
|
|
25
|
-
enum: vs_agent_model_1.ExtendedDidExchangeState,
|
|
26
|
-
default: vs_agent_model_1.ExtendedDidExchangeState.Start,
|
|
27
|
-
}),
|
|
23
|
+
(0, typeorm_1.Column)({ type: 'enum', enum: types_1.ConnectionStatus, default: types_1.ConnectionStatus.Start }),
|
|
28
24
|
__metadata("design:type", String)
|
|
29
25
|
], ConnectionEntity.prototype, "status", void 0);
|
|
30
26
|
__decorate([
|
|
@@ -39,10 +35,6 @@ __decorate([
|
|
|
39
35
|
(0, typeorm_1.UpdateDateColumn)(),
|
|
40
36
|
__metadata("design:type", Date)
|
|
41
37
|
], ConnectionEntity.prototype, "updatedTs", void 0);
|
|
42
|
-
__decorate([
|
|
43
|
-
(0, typeorm_1.Column)('jsonb', { nullable: true }),
|
|
44
|
-
__metadata("design:type", Object)
|
|
45
|
-
], ConnectionEntity.prototype, "metadata", void 0);
|
|
46
38
|
exports.ConnectionEntity = ConnectionEntity = __decorate([
|
|
47
39
|
(0, typeorm_1.Entity)('connections')
|
|
48
40
|
], ConnectionEntity);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.entity.js","sourceRoot":"","sources":["../../src/connections/connection.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"connection.entity.js","sourceRoot":"","sources":["../../src/connections/connection.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAoG;AAEpG,oCAA2C;AAGpC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAe5B,CAAA;AAfY,4CAAgB;AAE3B;IADC,IAAA,gCAAsB,EAAC,MAAM,CAAC;;4CACpB;AAGX;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,wBAAgB,EAAE,OAAO,EAAE,wBAAgB,CAAC,KAAK,EAAE,CAAC;;gDACzD;AAGzB;IADC,IAAA,gBAAM,EAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;qDACH;AAGjC;IADC,IAAA,0BAAgB,GAAE;8BACP,IAAI;mDAAA;AAGhB;IADC,IAAA,0BAAgB,GAAE;8BACP,IAAI;mDAAA;2BAdL,gBAAgB;IAD5B,IAAA,gBAAM,EAAC,aAAa,CAAC;GACT,gBAAgB,CAe5B"}
|
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReceivedUserProfile } from '@verana-labs/vs-agent-client';
|
|
2
2
|
import { Repository } from 'typeorm';
|
|
3
|
-
import {
|
|
3
|
+
import { ConnectionStatus } from '../types';
|
|
4
4
|
import { ConnectionEntity } from './connection.entity';
|
|
5
5
|
export declare class ConnectionsRepository {
|
|
6
6
|
private readonly repository;
|
|
7
7
|
constructor(repository: Repository<ConnectionEntity>);
|
|
8
|
-
create(connection: Partial<ConnectionEntity>): Promise<
|
|
9
|
-
findAll(): Promise<ConnectionEntity[]>;
|
|
8
|
+
create(connection: Partial<ConnectionEntity>): Promise<void>;
|
|
10
9
|
findById(id: string): Promise<ConnectionEntity | undefined>;
|
|
11
|
-
updateStatus(id: string, status:
|
|
12
|
-
updateUserProfile(id: string, userProfile:
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a connection has been completed.
|
|
16
|
-
*
|
|
17
|
-
* This method verifies whether the connection's `lang` (if required)
|
|
18
|
-
* and `metadata` meet the completion criteria.
|
|
19
|
-
* @param id The unique identifier of the connection to validate
|
|
20
|
-
* @param requireLang If `true`, ensures that `lang` is not `null`
|
|
21
|
-
* @returns A promise that resolves to `true` if:
|
|
22
|
-
* - `metadata` is either `undefined` or a non-empty object.
|
|
23
|
-
* - If `requireLang` is `true`, `lang` must not be `null`.
|
|
24
|
-
* @throws Error if the connection is not found or if `createdTs` is missing.
|
|
25
|
-
*/
|
|
26
|
-
isCompleted(id: string, requireLang: boolean): Promise<boolean>;
|
|
10
|
+
updateStatus(id: string, status: ConnectionStatus): Promise<boolean>;
|
|
11
|
+
updateUserProfile(id: string, userProfile: ReceivedUserProfile): Promise<void>;
|
|
12
|
+
isCompleted(id: string, requireProfile: boolean): Promise<boolean>;
|
|
27
13
|
}
|
|
@@ -15,20 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.ConnectionsRepository = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
-
const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
|
|
19
18
|
const typeorm_2 = require("typeorm");
|
|
19
|
+
const types_1 = require("../types");
|
|
20
20
|
const connection_entity_1 = require("./connection.entity");
|
|
21
|
-
// TypeORM
|
|
22
21
|
let ConnectionsRepository = class ConnectionsRepository {
|
|
23
22
|
constructor(repository) {
|
|
24
23
|
this.repository = repository;
|
|
25
24
|
}
|
|
26
25
|
async create(connection) {
|
|
27
|
-
|
|
28
|
-
return await this.repository.save(entity);
|
|
29
|
-
}
|
|
30
|
-
async findAll() {
|
|
31
|
-
return await this.repository.find();
|
|
26
|
+
await this.repository.createQueryBuilder().insert().values(connection).orIgnore().execute();
|
|
32
27
|
}
|
|
33
28
|
async findById(id) {
|
|
34
29
|
var _a;
|
|
@@ -36,46 +31,23 @@ let ConnectionsRepository = class ConnectionsRepository {
|
|
|
36
31
|
}
|
|
37
32
|
async updateStatus(id, status) {
|
|
38
33
|
var _a;
|
|
39
|
-
await this.repository.update(id, { status });
|
|
40
|
-
return (_a =
|
|
34
|
+
const result = await this.repository.update(id, { status });
|
|
35
|
+
return ((_a = result.affected) !== null && _a !== void 0 ? _a : 0) > 0;
|
|
41
36
|
}
|
|
42
37
|
async updateUserProfile(id, userProfile) {
|
|
43
|
-
var _a;
|
|
44
38
|
await this.repository.update(id, { userProfile });
|
|
45
|
-
return (_a = (await this.repository.findOne({ where: { id } }))) !== null && _a !== void 0 ? _a : undefined;
|
|
46
|
-
}
|
|
47
|
-
async updateMetadata(id, metadata) {
|
|
48
|
-
var _a;
|
|
49
|
-
await this.repository.update(id, { metadata });
|
|
50
|
-
return (_a = (await this.repository.findOne({ where: { id } }))) !== null && _a !== void 0 ? _a : undefined;
|
|
51
39
|
}
|
|
52
|
-
|
|
53
|
-
* Checks if a connection has been completed.
|
|
54
|
-
*
|
|
55
|
-
* This method verifies whether the connection's `lang` (if required)
|
|
56
|
-
* and `metadata` meet the completion criteria.
|
|
57
|
-
* @param id The unique identifier of the connection to validate
|
|
58
|
-
* @param requireLang If `true`, ensures that `lang` is not `null`
|
|
59
|
-
* @returns A promise that resolves to `true` if:
|
|
60
|
-
* - `metadata` is either `undefined` or a non-empty object.
|
|
61
|
-
* - If `requireLang` is `true`, `lang` must not be `null`.
|
|
62
|
-
* @throws Error if the connection is not found or if `createdTs` is missing.
|
|
63
|
-
*/
|
|
64
|
-
async isCompleted(id, requireLang) {
|
|
40
|
+
async isCompleted(id, requireProfile) {
|
|
65
41
|
var _a;
|
|
66
42
|
const conn = await this.findById(id);
|
|
67
|
-
if (!(conn === null || conn === void 0 ? void 0 : conn.id))
|
|
68
|
-
throw new Error(`No connection found with id: ${id}
|
|
69
|
-
|
|
70
|
-
if (conn.status === vs_agent_model_1.ExtendedDidExchangeState.Completed)
|
|
43
|
+
if (!(conn === null || conn === void 0 ? void 0 : conn.id))
|
|
44
|
+
throw new Error(`No connection found with id: ${id}`);
|
|
45
|
+
if (conn.status === types_1.ConnectionStatus.Completed)
|
|
71
46
|
return false;
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
47
|
+
const completed = !requireProfile || ((_a = conn.userProfile) === null || _a === void 0 ? void 0 : _a.preferredLanguage) != null;
|
|
48
|
+
if (completed)
|
|
49
|
+
await this.updateStatus(conn.id, types_1.ConnectionStatus.Completed);
|
|
50
|
+
return completed;
|
|
79
51
|
}
|
|
80
52
|
};
|
|
81
53
|
exports.ConnectionsRepository = ConnectionsRepository;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.repository.js","sourceRoot":"","sources":["../../src/connections/connection.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2C;AAC3C,6CAAkD;
|
|
1
|
+
{"version":3,"file":"connection.repository.js","sourceRoot":"","sources":["../../src/connections/connection.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2C;AAC3C,6CAAkD;AAElD,qCAAoC;AAEpC,oCAA2C;AAE3C,2DAAsD;AAG/C,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAChC,YAEmB,UAAwC;QAAxC,eAAU,GAAV,UAAU,CAA8B;IACxD,CAAC;IAEG,KAAK,CAAC,MAAM,CAAC,UAAqC;QACvD,MAAM,IAAI,CAAC,UAAU,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAA;IAC7F,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,EAAU;;QAC9B,OAAO,MAAA,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,mCAAI,SAAS,CAAA;IACxE,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,MAAwB;;QAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;QAC3D,OAAO,CAAC,MAAA,MAAM,CAAC,QAAQ,mCAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IACnC,CAAC;IAEM,KAAK,CAAC,iBAAiB,CAAC,EAAU,EAAE,WAAgC;QACzE,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAA;IACnD,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,EAAU,EAAE,cAAuB;;QAC1D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACpC,IAAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,EAAE,CAAA;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,EAAE,EAAE,CAAC,CAAA;QACpE,IAAI,IAAI,CAAC,MAAM,KAAK,wBAAgB,CAAC,SAAS;YAAE,OAAO,KAAK,CAAA;QAE5D,MAAM,SAAS,GAAG,CAAC,cAAc,IAAI,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,iBAAiB,KAAI,IAAI,CAAA;QAChF,IAAI,SAAS;YAAE,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,wBAAgB,CAAC,SAAS,CAAC,CAAA;QAC3E,OAAO,SAAS,CAAA;IAClB,CAAC;CACF,CAAA;AAhCY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,oCAAgB,CAAC,CAAA;qCACN,oBAAU;GAH9B,qBAAqB,CAgCjC"}
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConnectionStateUpdatedData, ProfileReceivedData } from '@verana-labs/vs-agent-client';
|
|
2
2
|
import { EventHandler } from '../interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { EventsModuleOptions } from '../types';
|
|
4
4
|
import { ConnectionsRepository } from './connection.repository';
|
|
5
|
-
export declare class
|
|
6
|
-
private options;
|
|
5
|
+
export declare class ConnectionsService {
|
|
7
6
|
private readonly repository;
|
|
8
|
-
private eventHandler
|
|
7
|
+
private readonly eventHandler;
|
|
9
8
|
private readonly logger;
|
|
10
|
-
private readonly
|
|
11
|
-
constructor(options:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* Handles a new connection by verifying its completion status.
|
|
15
|
-
*
|
|
16
|
-
* If the connection is considered completed, it triggers the event handler
|
|
17
|
-
* and logs the connection initiation.
|
|
18
|
-
*
|
|
19
|
-
* @param connectionId The unique identifier of the connection.
|
|
20
|
-
* @returns A promise that resolves when the connection is processed.
|
|
21
|
-
*/
|
|
9
|
+
private readonly requireProfile;
|
|
10
|
+
constructor(options: EventsModuleOptions, repository: ConnectionsRepository, eventHandler: EventHandler);
|
|
11
|
+
handleStateUpdated(data: ConnectionStateUpdatedData, timestamp: string): Promise<void>;
|
|
12
|
+
handleProfileReceived(data: ProfileReceivedData): Promise<void>;
|
|
22
13
|
handleNewConnection(connectionId: string): Promise<void>;
|
|
23
14
|
}
|