@sphereon/ssi-sdk.agent-config 0.33.1-next.2 → 0.33.1-next.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,186 @@
1
+ import { IPluginMethodMap, IAgentContext, IKeyManager, IResolver, IDIDManager, ICredentialIssuer, ICredentialVerifier, ICredentialStatusVerifier, IDataStore, IDataStoreORM, TAgent, IAgentOptions } from '@veramo/core';
2
+ import { DataSource } from 'typeorm/data-source/DataSource.js';
3
+ import { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js';
4
+ import { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js';
5
+
6
+ /**
7
+ * Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)
8
+ * @param context Tje agent context to check against
9
+ * @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence
10
+ */
11
+ declare function contextHasPlugin<Plugins extends IPluginMethodMap>(context: IAgentContext<any>, requiredMethod: string | string[]): context is IAgentContext<Plugins>;
12
+ /**
13
+ * The below methods are convenience methods to directly get the appropriate context after calling the respective method
14
+ *
15
+ * @param context
16
+ */
17
+ declare function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager>;
18
+ declare function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager>;
19
+ declare function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver>;
20
+ declare function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer>;
21
+ declare function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier>;
22
+ declare function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier>;
23
+ declare function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore>;
24
+ declare function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM>;
25
+
26
+ declare class DataSources {
27
+ get defaultDbType(): SupportedDatabaseType;
28
+ set defaultDbType(value: SupportedDatabaseType);
29
+ private dataSources;
30
+ private configs;
31
+ private _defaultDbType;
32
+ private static singleton;
33
+ static singleInstance(): DataSources;
34
+ static newInstance(configs?: Map<string, DataSourceOptions>): DataSources;
35
+ private constructor();
36
+ addConfig(dbName: string, config: DataSourceOptions): this;
37
+ deleteConfig(dbName: string): this;
38
+ has(dbName: string): boolean;
39
+ delete(dbName: string): this;
40
+ getConfig(dbName: string): BaseDataSourceOptions;
41
+ getDbNames(): string[];
42
+ getDbConnection(dbName: string): Promise<DataSource>;
43
+ }
44
+ type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native';
45
+ type DateTimeType = 'timestamp' | 'datetime';
46
+ type DateType = 'date';
47
+ /**
48
+ * Gets the database connection.
49
+ *
50
+ * Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time
51
+ *
52
+ * @param connectionName The database name
53
+ * @param opts
54
+ */
55
+ declare const getDbConnection: (connectionName: string, opts?: {
56
+ config: BaseDataSourceOptions | any;
57
+ }) => Promise<DataSource>;
58
+ declare const dropDatabase: (dbName: string, opts?: {
59
+ removeDataSource?: boolean;
60
+ }) => Promise<void>;
61
+ /**
62
+ * Runs a migration down (drops DB schema)
63
+ * @param dataSource
64
+ */
65
+ declare const revertMigration: (dataSource: DataSource) => Promise<void>;
66
+ declare const resetDatabase: (dbName: string) => Promise<void>;
67
+
68
+ /**
69
+ * Creates a Veramo agent from a config object containing an `/agent` pointer.
70
+ * @param config - The configuration object
71
+ *
72
+ * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
73
+ * the configuration options.
74
+ *
75
+ * @beta - This API may change without a major version bump
76
+ */
77
+ declare function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>>;
78
+ /**
79
+ * Helper function to create a new instance of the {@link Agent} class with correct type
80
+ *
81
+ * @remarks
82
+ * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
87
+ * import { AgentRestClient } from '@veramo/remote-client'
88
+ * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
89
+ * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
90
+ * plugins: [
91
+ * new CredentialIssuer(),
92
+ * new AgentRestClient({
93
+ * url: 'http://localhost:3002/agent',
94
+ * enabledMethods: [
95
+ * 'resolveDid',
96
+ * 'handleMessage',
97
+ * ],
98
+ * }),
99
+ * ],
100
+ * })
101
+ * ```
102
+ * @param options - Agent configuration options
103
+ * @returns configured agent
104
+ * @public
105
+ */
106
+ declare function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(options: IAgentOptions & {
107
+ context?: C;
108
+ }): Promise<TAgent<T> & {
109
+ context?: C;
110
+ }>;
111
+ /**
112
+ * Parses a yaml config file and returns a config object
113
+ * @param filePath
114
+ */
115
+ declare const getConfig: (filePath: string | Buffer | URL) => Promise<{
116
+ version?: number;
117
+ [x: string]: any;
118
+ }>;
119
+ declare function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>>;
120
+
121
+ /**
122
+ * Creates objects from a configuration object and a set of pointers.
123
+ *
124
+ * Example:
125
+ * ```ts
126
+ * const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
127
+ * ```
128
+ *
129
+ * The config can contain references (`$ref`) to other objects within using JSON pointers.
130
+ * Example:
131
+ * ```json
132
+ * {
133
+ * "rpcUrl": "http://localhost:8545",
134
+ * "endpoint": {
135
+ * "url": {
136
+ * "$ref": "/rpcUrl"
137
+ * }
138
+ * }
139
+ * }
140
+ * ```
141
+ *
142
+ * The config object can also contain references to NPM modules using the `$require` property.
143
+ * Example:
144
+ * ```json
145
+ * {
146
+ * "agent": {
147
+ * "$require": "@veramo/core#Agent",
148
+ * "$args": {
149
+ * "plugins": [
150
+ * { "$require": "@veramo/did-comm#DIDComm" },
151
+ * ]
152
+ * }
153
+ * }
154
+ * }
155
+ * ```
156
+ *
157
+ * Environment variables can also be specified using the `$env` property.
158
+ *
159
+ * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
160
+ * more information.
161
+ *
162
+ * @param config - The configuration object
163
+ * @param pointers - A map of JSON pointers to objects within that config that you wish to create
164
+ *
165
+ * @beta - This API may change without a major version bump
166
+ */
167
+ declare function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>>;
168
+
169
+ /**
170
+ * Accept a Type or a Promise of that Type.
171
+ *
172
+ * @internal
173
+ */
174
+ type OrPromise<T> = T | Promise<T>;
175
+
176
+ declare const getDbType: (opts?: {
177
+ defaultType: SupportedDatabaseType;
178
+ }) => SupportedDatabaseType;
179
+ declare const typeOrmDateTime: (opts?: {
180
+ defaultType: SupportedDatabaseType;
181
+ }) => DateTimeType;
182
+ declare const typeormDate: (opts?: {
183
+ defaultType: SupportedDatabaseType;
184
+ }) => DateType;
185
+
186
+ export { DataSources, type DateTimeType, type DateType, type OrPromise, type SupportedDatabaseType, contextHasCredentialIssuer, contextHasCredentialStatusVerifier, contextHasCredentialVerifier, contextHasDataStore, contextHasDataStoreORM, contextHasDidManager, contextHasDidResolver, contextHasKeyManager, contextHasPlugin, createAgent, createAgentFromConfig, createObjects, dropDatabase, getAgent, getConfig, getDbConnection, getDbType, resetDatabase, revertMigration, typeOrmDateTime, typeormDate };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,186 @@
1
+ import { IPluginMethodMap, IAgentContext, IKeyManager, IResolver, IDIDManager, ICredentialIssuer, ICredentialVerifier, ICredentialStatusVerifier, IDataStore, IDataStoreORM, TAgent, IAgentOptions } from '@veramo/core';
2
+ import { DataSource } from 'typeorm/data-source/DataSource.js';
3
+ import { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js';
4
+ import { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js';
5
+
1
6
  /**
7
+ * Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)
8
+ * @param context Tje agent context to check against
9
+ * @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence
10
+ */
11
+ declare function contextHasPlugin<Plugins extends IPluginMethodMap>(context: IAgentContext<any>, requiredMethod: string | string[]): context is IAgentContext<Plugins>;
12
+ /**
13
+ * The below methods are convenience methods to directly get the appropriate context after calling the respective method
14
+ *
15
+ * @param context
16
+ */
17
+ declare function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager>;
18
+ declare function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager>;
19
+ declare function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver>;
20
+ declare function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer>;
21
+ declare function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier>;
22
+ declare function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier>;
23
+ declare function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore>;
24
+ declare function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM>;
25
+
26
+ declare class DataSources {
27
+ get defaultDbType(): SupportedDatabaseType;
28
+ set defaultDbType(value: SupportedDatabaseType);
29
+ private dataSources;
30
+ private configs;
31
+ private _defaultDbType;
32
+ private static singleton;
33
+ static singleInstance(): DataSources;
34
+ static newInstance(configs?: Map<string, DataSourceOptions>): DataSources;
35
+ private constructor();
36
+ addConfig(dbName: string, config: DataSourceOptions): this;
37
+ deleteConfig(dbName: string): this;
38
+ has(dbName: string): boolean;
39
+ delete(dbName: string): this;
40
+ getConfig(dbName: string): BaseDataSourceOptions;
41
+ getDbNames(): string[];
42
+ getDbConnection(dbName: string): Promise<DataSource>;
43
+ }
44
+ type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native';
45
+ type DateTimeType = 'timestamp' | 'datetime';
46
+ type DateType = 'date';
47
+ /**
48
+ * Gets the database connection.
49
+ *
50
+ * Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time
51
+ *
52
+ * @param connectionName The database name
53
+ * @param opts
54
+ */
55
+ declare const getDbConnection: (connectionName: string, opts?: {
56
+ config: BaseDataSourceOptions | any;
57
+ }) => Promise<DataSource>;
58
+ declare const dropDatabase: (dbName: string, opts?: {
59
+ removeDataSource?: boolean;
60
+ }) => Promise<void>;
61
+ /**
62
+ * Runs a migration down (drops DB schema)
63
+ * @param dataSource
64
+ */
65
+ declare const revertMigration: (dataSource: DataSource) => Promise<void>;
66
+ declare const resetDatabase: (dbName: string) => Promise<void>;
67
+
68
+ /**
69
+ * Creates a Veramo agent from a config object containing an `/agent` pointer.
70
+ * @param config - The configuration object
71
+ *
72
+ * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
73
+ * the configuration options.
74
+ *
75
+ * @beta - This API may change without a major version bump
76
+ */
77
+ declare function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>>;
78
+ /**
79
+ * Helper function to create a new instance of the {@link Agent} class with correct type
80
+ *
81
+ * @remarks
82
+ * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
87
+ * import { AgentRestClient } from '@veramo/remote-client'
88
+ * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
89
+ * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
90
+ * plugins: [
91
+ * new CredentialIssuer(),
92
+ * new AgentRestClient({
93
+ * url: 'http://localhost:3002/agent',
94
+ * enabledMethods: [
95
+ * 'resolveDid',
96
+ * 'handleMessage',
97
+ * ],
98
+ * }),
99
+ * ],
100
+ * })
101
+ * ```
102
+ * @param options - Agent configuration options
103
+ * @returns configured agent
2
104
  * @public
3
105
  */
4
- export * from './agentContextUtils';
5
- export * from './dataSources';
6
- export * from './agentCreator';
7
- export * from './objectCreator';
8
- export * from './generic';
9
- export * from './typeormTypes';
10
- //# sourceMappingURL=index.d.ts.map
106
+ declare function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(options: IAgentOptions & {
107
+ context?: C;
108
+ }): Promise<TAgent<T> & {
109
+ context?: C;
110
+ }>;
111
+ /**
112
+ * Parses a yaml config file and returns a config object
113
+ * @param filePath
114
+ */
115
+ declare const getConfig: (filePath: string | Buffer | URL) => Promise<{
116
+ version?: number;
117
+ [x: string]: any;
118
+ }>;
119
+ declare function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>>;
120
+
121
+ /**
122
+ * Creates objects from a configuration object and a set of pointers.
123
+ *
124
+ * Example:
125
+ * ```ts
126
+ * const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
127
+ * ```
128
+ *
129
+ * The config can contain references (`$ref`) to other objects within using JSON pointers.
130
+ * Example:
131
+ * ```json
132
+ * {
133
+ * "rpcUrl": "http://localhost:8545",
134
+ * "endpoint": {
135
+ * "url": {
136
+ * "$ref": "/rpcUrl"
137
+ * }
138
+ * }
139
+ * }
140
+ * ```
141
+ *
142
+ * The config object can also contain references to NPM modules using the `$require` property.
143
+ * Example:
144
+ * ```json
145
+ * {
146
+ * "agent": {
147
+ * "$require": "@veramo/core#Agent",
148
+ * "$args": {
149
+ * "plugins": [
150
+ * { "$require": "@veramo/did-comm#DIDComm" },
151
+ * ]
152
+ * }
153
+ * }
154
+ * }
155
+ * ```
156
+ *
157
+ * Environment variables can also be specified using the `$env` property.
158
+ *
159
+ * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
160
+ * more information.
161
+ *
162
+ * @param config - The configuration object
163
+ * @param pointers - A map of JSON pointers to objects within that config that you wish to create
164
+ *
165
+ * @beta - This API may change without a major version bump
166
+ */
167
+ declare function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>>;
168
+
169
+ /**
170
+ * Accept a Type or a Promise of that Type.
171
+ *
172
+ * @internal
173
+ */
174
+ type OrPromise<T> = T | Promise<T>;
175
+
176
+ declare const getDbType: (opts?: {
177
+ defaultType: SupportedDatabaseType;
178
+ }) => SupportedDatabaseType;
179
+ declare const typeOrmDateTime: (opts?: {
180
+ defaultType: SupportedDatabaseType;
181
+ }) => DateTimeType;
182
+ declare const typeormDate: (opts?: {
183
+ defaultType: SupportedDatabaseType;
184
+ }) => DateType;
185
+
186
+ export { DataSources, type DateTimeType, type DateType, type OrPromise, type SupportedDatabaseType, contextHasCredentialIssuer, contextHasCredentialStatusVerifier, contextHasCredentialVerifier, contextHasDataStore, contextHasDataStoreORM, contextHasDidManager, contextHasDidResolver, contextHasKeyManager, contextHasPlugin, createAgent, createAgentFromConfig, createObjects, dropDatabase, getAgent, getConfig, getDbConnection, getDbType, resetDatabase, revertMigration, typeOrmDateTime, typeormDate };