@twin.org/dataspace-data-plane-socket-client 0.0.3-next.15
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/LICENSE +201 -0
- package/README.md +21 -0
- package/dist/es/dataspaceDataPlaneSocketClient.js +236 -0
- package/dist/es/dataspaceDataPlaneSocketClient.js.map +1 -0
- package/dist/es/index.js +6 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IDataspaceDataPlaneSocketClientConfig.js +2 -0
- package/dist/es/models/IDataspaceDataPlaneSocketClientConfig.js.map +1 -0
- package/dist/es/models/IDataspaceDataPlaneSocketClientConstructorOptions.js +2 -0
- package/dist/es/models/IDataspaceDataPlaneSocketClientConstructorOptions.js.map +1 -0
- package/dist/types/dataspaceDataPlaneSocketClient.d.ts +89 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/models/IDataspaceDataPlaneSocketClientConfig.d.ts +6 -0
- package/dist/types/models/IDataspaceDataPlaneSocketClientConstructorOptions.d.ts +14 -0
- package/docs/changelog.md +306 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/DataspaceDataPlaneSocketClient.md +317 -0
- package/docs/reference/index.md +10 -0
- package/docs/reference/interfaces/IDataspaceDataPlaneSocketClientConfig.md +7 -0
- package/docs/reference/interfaces/IDataspaceDataPlaneSocketClientConstructorOptions.md +19 -0
- package/locales/en.json +15 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 IOTA Stiftung.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# TWIN Dataspace Data Plane Socket Client
|
|
2
|
+
|
|
3
|
+
Dataspace Data Plane contract implementation which can connect to WebSocket endpoints.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install @twin.org/dataspace-data-plane-socket-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
|
|
14
|
+
|
|
15
|
+
## Reference
|
|
16
|
+
|
|
17
|
+
Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
|
|
18
|
+
|
|
19
|
+
## Changelog
|
|
20
|
+
|
|
21
|
+
The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Copyright 2025 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseSocketClient } from "@twin.org/api-core";
|
|
4
|
+
import { BaseError, ComponentFactory, Converter, Guards, Is, NotImplementedError, NotSupportedError, RandomHelper } from "@twin.org/core";
|
|
5
|
+
/**
|
|
6
|
+
* Dataspace data plane client which publishes using REST API and websockets.
|
|
7
|
+
*/
|
|
8
|
+
export class DataspaceDataPlaneSocketClient extends BaseSocketClient {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static CLASS_NAME = "DataspaceDataPlaneSocketClient";
|
|
13
|
+
/**
|
|
14
|
+
* The topic for activity log events.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
static _ACTIVITY_LOG_TOPIC = "activity-log";
|
|
18
|
+
/**
|
|
19
|
+
* Activity processing details route.
|
|
20
|
+
*/
|
|
21
|
+
static _ACTIVITY_LOG_STATUS_ROUTE = "activity-logs/status";
|
|
22
|
+
/**
|
|
23
|
+
* The logging service for information.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
_logging;
|
|
27
|
+
/**
|
|
28
|
+
* Subscriptions to the events.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
_activityLogSubscriptions;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new instance of DataspaceDataPlaneSocketClient.
|
|
34
|
+
* @param options Options for the client.
|
|
35
|
+
*/
|
|
36
|
+
constructor(options) {
|
|
37
|
+
super("DataspaceDataPlaneSocketClient", options?.config, "dataspace-data-plane");
|
|
38
|
+
this._activityLogSubscriptions = {
|
|
39
|
+
subscriberCallbacks: {}
|
|
40
|
+
};
|
|
41
|
+
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
42
|
+
super.onEvent("publish", async (data) => this.incomingPublishActivityLog(data));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the class name of the component.
|
|
46
|
+
* @returns The class name of the component.
|
|
47
|
+
*/
|
|
48
|
+
className() {
|
|
49
|
+
return DataspaceDataPlaneSocketClient.CLASS_NAME;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Notify an Activity to the Dataspace Activity Stream - implemented in REST Client.
|
|
53
|
+
* @param activity The Activity notified.
|
|
54
|
+
* @returns The Activity's identifier.
|
|
55
|
+
*/
|
|
56
|
+
async notifyActivity(activity) {
|
|
57
|
+
// This method is in the REST client
|
|
58
|
+
throw new NotImplementedError(DataspaceDataPlaneSocketClient.CLASS_NAME, "notifyActivity");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Subscribes to the activity log.
|
|
62
|
+
* @param callback The callback to be called when Activity Log is called.
|
|
63
|
+
* @param subscriptionId The subscription Id.
|
|
64
|
+
* @returns The subscription Id.
|
|
65
|
+
*/
|
|
66
|
+
async subscribeToActivityLog(callback, subscriptionId) {
|
|
67
|
+
Guards.function(DataspaceDataPlaneSocketClient.CLASS_NAME, "callback", callback);
|
|
68
|
+
let needsConnect = false;
|
|
69
|
+
// If we don't yet have an activity log subscription id then create one.
|
|
70
|
+
// we will also need to connect to the socket.
|
|
71
|
+
if (!Is.stringValue(this._activityLogSubscriptions.subscriptionId)) {
|
|
72
|
+
this._activityLogSubscriptions.subscriptionId = Converter.bytesToHex(RandomHelper.generate(16));
|
|
73
|
+
needsConnect = true;
|
|
74
|
+
}
|
|
75
|
+
// Store the callback for the specific local subscription
|
|
76
|
+
const localSubscriptionId = subscriptionId ?? Converter.bytesToHex(RandomHelper.generate(16));
|
|
77
|
+
this._activityLogSubscriptions.subscriberCallbacks[localSubscriptionId] = callback;
|
|
78
|
+
// If this the first subscription for the activity logs then send a subscribe to the socket.
|
|
79
|
+
if (needsConnect && super.socketConnect()) {
|
|
80
|
+
const request = {
|
|
81
|
+
body: {
|
|
82
|
+
operation: "subscribe",
|
|
83
|
+
subscriptionId: this._activityLogSubscriptions.subscriptionId
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
super.sendEvent(DataspaceDataPlaneSocketClient._ACTIVITY_LOG_STATUS_ROUTE, request);
|
|
87
|
+
}
|
|
88
|
+
await this._logging?.log({
|
|
89
|
+
level: "info",
|
|
90
|
+
source: DataspaceDataPlaneSocketClient.CLASS_NAME,
|
|
91
|
+
ts: Date.now(),
|
|
92
|
+
message: "subscribeActivityLogs",
|
|
93
|
+
data: {
|
|
94
|
+
topic: DataspaceDataPlaneSocketClient._ACTIVITY_LOG_TOPIC,
|
|
95
|
+
subscriptionId: this._activityLogSubscriptions.subscriptionId
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return localSubscriptionId;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Unsubscribes to the activity log.
|
|
102
|
+
* @param subscriptionId The subscription Id.
|
|
103
|
+
* @returns The subscription Id.
|
|
104
|
+
*/
|
|
105
|
+
async unSubscribeToActivityLog(subscriptionId) {
|
|
106
|
+
Guards.stringValue(DataspaceDataPlaneSocketClient.CLASS_NAME, "subscriptionId", subscriptionId);
|
|
107
|
+
if (this._activityLogSubscriptions.subscriberCallbacks[subscriptionId]) {
|
|
108
|
+
await this._logging?.log({
|
|
109
|
+
level: "info",
|
|
110
|
+
source: DataspaceDataPlaneSocketClient.CLASS_NAME,
|
|
111
|
+
ts: Date.now(),
|
|
112
|
+
message: "unsubscribeActivityLogs",
|
|
113
|
+
data: {
|
|
114
|
+
subscriptionId
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
// We found the subscription id so remove it.
|
|
118
|
+
delete this._activityLogSubscriptions.subscriberCallbacks[subscriptionId];
|
|
119
|
+
// If there are no more subscriptions for the activity logs then send an unsubscribe to the socket.
|
|
120
|
+
if (super.socketConnect() && Is.stringValue(this._activityLogSubscriptions.subscriptionId)) {
|
|
121
|
+
const request = {
|
|
122
|
+
body: {
|
|
123
|
+
operation: "unsubscribe",
|
|
124
|
+
subscriptionId: this._activityLogSubscriptions.subscriptionId
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
super.sendEvent(DataspaceDataPlaneSocketClient._ACTIVITY_LOG_STATUS_ROUTE, request);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// There are no more subscriptions so disconnect the socket
|
|
131
|
+
if (Is.empty(this._activityLogSubscriptions.subscriptionId)) {
|
|
132
|
+
super.socketDisconnect();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns Activity Log Entry which contains the Activity processing details - implemented in REST Client.
|
|
137
|
+
* @param logEntryId The Id of the Activity Log Entry (a URI).
|
|
138
|
+
* @returns the Activity Log Entry with the processing details.
|
|
139
|
+
* @throws NotFoundError if activity log entry is not known.
|
|
140
|
+
*/
|
|
141
|
+
async getActivityLogEntry(logEntryId) {
|
|
142
|
+
// This method is in the REST client
|
|
143
|
+
throw new NotSupportedError(DataspaceDataPlaneSocketClient.CLASS_NAME, "notSupportedOnClient", {
|
|
144
|
+
methodName: "getActivityLogEntry"
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get Data Asset entities. Allows to retrieve entities by their type or id.
|
|
149
|
+
* @param entitySet The set of entities to be retrieved.
|
|
150
|
+
* @param entitySet.jsonLdContext The JSON-LD Context to be used to expand the referred entityType.
|
|
151
|
+
* @param consumerPid The consumer Process ID from the DSP Transfer Process.
|
|
152
|
+
* Used to resolve datasetId from the Transfer Process.
|
|
153
|
+
* @param cursor Pagination details - cursor.
|
|
154
|
+
* @param limit Pagination details - max number of entities.
|
|
155
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
156
|
+
* @returns The item list and optional cursor for pagination via Link headers.
|
|
157
|
+
*/
|
|
158
|
+
async getDataAssetEntities(entitySet, consumerPid, cursor, limit, trustPayload) {
|
|
159
|
+
throw new NotSupportedError(DataspaceDataPlaneSocketClient.CLASS_NAME, "notSupportedOnClient", {
|
|
160
|
+
methodName: "getDataAssetEntities"
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Queries a data asset controlled by this Dataspace App.
|
|
165
|
+
* @param consumerPid The consumer Process ID from the DSP Transfer Process.
|
|
166
|
+
* Used to resolve datasetId from the Transfer Process.
|
|
167
|
+
* @param query The filtering query.
|
|
168
|
+
* @param cursor Pagination details - cursor.
|
|
169
|
+
* @param limit Pagination details - max number of entities.
|
|
170
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
171
|
+
* @returns The item list and optional cursor for pagination via Link headers.
|
|
172
|
+
*/
|
|
173
|
+
async queryDataAsset(consumerPid, query, cursor, limit, trustPayload) {
|
|
174
|
+
throw new NotSupportedError(DataspaceDataPlaneSocketClient.CLASS_NAME, "notSupportedOnClient", {
|
|
175
|
+
methodName: "queryDataAsset"
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Handle the socket connection.
|
|
180
|
+
*/
|
|
181
|
+
async handleConnected() {
|
|
182
|
+
// The socket has reconnected so send subscribe requests
|
|
183
|
+
// for all the current subscriptions
|
|
184
|
+
if (Object.keys(this._activityLogSubscriptions.subscriberCallbacks).length > 0 &&
|
|
185
|
+
Is.stringValue(this._activityLogSubscriptions.subscriptionId)) {
|
|
186
|
+
const subscribeEmit = {
|
|
187
|
+
body: {
|
|
188
|
+
operation: "subscribe",
|
|
189
|
+
subscriptionId: this._activityLogSubscriptions.subscriptionId
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
super.sendEvent(DataspaceDataPlaneSocketClient._ACTIVITY_LOG_STATUS_ROUTE, subscribeEmit);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Handle an error.
|
|
197
|
+
* @param err The error to handle.
|
|
198
|
+
*/
|
|
199
|
+
async handleError(err) {
|
|
200
|
+
await this._logging?.log({
|
|
201
|
+
level: "error",
|
|
202
|
+
source: DataspaceDataPlaneSocketClient.CLASS_NAME,
|
|
203
|
+
ts: Date.now(),
|
|
204
|
+
message: "socketConnect",
|
|
205
|
+
error: err
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Handle an incoming publish event.
|
|
210
|
+
* @param topic The incoming topic.
|
|
211
|
+
* @param event The incoming data.
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
214
|
+
async incomingPublishActivityLog(event) {
|
|
215
|
+
if (!Is.empty(event.body)) {
|
|
216
|
+
for (const subscriptionId in this._activityLogSubscriptions.subscriberCallbacks) {
|
|
217
|
+
try {
|
|
218
|
+
await this._activityLogSubscriptions.subscriberCallbacks[subscriptionId](event.body);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
await this._logging?.log({
|
|
222
|
+
level: "error",
|
|
223
|
+
source: DataspaceDataPlaneSocketClient.CLASS_NAME,
|
|
224
|
+
ts: Date.now(),
|
|
225
|
+
message: "callback",
|
|
226
|
+
error: BaseError.fromError(error),
|
|
227
|
+
data: {
|
|
228
|
+
subscriptionId
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=dataspaceDataPlaneSocketClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataspaceDataPlaneSocketClient.js","sourceRoot":"","sources":["../../src/dataspaceDataPlaneSocketClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,MAAM,EAEN,EAAE,EACF,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,MAAM,gBAAgB,CAAC;AAgBxB;;GAEG;AACH,MAAM,OAAO,8BACZ,SAAQ,gBAAgB;IAGxB;;OAEG;IACI,MAAM,CAAU,UAAU,oCAAoD;IAErF;;;OAGG;IACK,MAAM,CAAU,mBAAmB,GAAG,cAAc,CAAC;IAE7D;;OAEG;IACK,MAAM,CAAU,0BAA0B,GAAG,sBAAsB,CAAC;IAE5E;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,yBAAyB,CAKxC;IAEF;;;OAGG;IACH,YAAY,OAA0D;QACrE,KAAK,mCAA2C,OAAO,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;QAEzF,IAAI,CAAC,yBAAyB,GAAG;YAChC,mBAAmB,EAAE,EAAE;SACvB,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAAC,CAAC;QAEzF,KAAK,CAAC,OAAO,CAAgD,SAAS,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE,CACpF,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,CACrC,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,8BAA8B,CAAC,UAAU,CAAC;IA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a,CAAC,CAAC;QAC3F,CAAC;IACF,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,WAAW,CAAC,GAAW;QACtC,MAAM,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC;YACxB,KAAK,EAAE,OAAO;YACd,MAAM,EAAE,8BAA8B,CAAC,UAAU;YACjD,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,eAAe;YACxB,KAAK,EAAE,GAAG;SACV,CAAC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,0BAA0B,CACvC,KAAoD;QAEpD,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,KAAK,MAAM,cAAc,IAAI,IAAI,CAAC,yBAAyB,CAAC,mBAAmB,EAAE,CAAC;gBACjF,IAAI,CAAC;oBACJ,MAAM,IAAI,CAAC,yBAAyB,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACtF,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,MAAM,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC;wBACxB,KAAK,EAAE,OAAO;wBACd,MAAM,EAAE,8BAA8B,CAAC,UAAU;wBACjD,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;wBACd,OAAO,EAAE,UAAU;wBACnB,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC;wBACjC,IAAI,EAAE;4BACL,cAAc;yBACd;qBACD,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseSocketClient } from \"@twin.org/api-core\";\nimport type { IHttpResponse } from \"@twin.org/api-models\";\nimport {\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGuards,\n\ttype IError,\n\tIs,\n\tNotImplementedError,\n\tNotSupportedError,\n\tRandomHelper\n} from \"@twin.org/core\";\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type {\n\tIActivityLogEntry,\n\tIActivityLogStatusNotification,\n\tIActivityLogStatusRequest,\n\tIDataAssetItemListResult,\n\tIDataspaceDataPlaneComponent,\n\tIEntitySet,\n\tIFilteringQuery\n} from \"@twin.org/dataspace-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IActivityStreamsActivity } from \"@twin.org/standards-w3c-activity-streams\";\nimport type { IDataspaceDataPlaneSocketClientConstructorOptions } from \"./models/IDataspaceDataPlaneSocketClientConstructorOptions.js\";\n\n/**\n * Dataspace data plane client which publishes using REST API and websockets.\n */\nexport class DataspaceDataPlaneSocketClient\n\textends BaseSocketClient\n\timplements IDataspaceDataPlaneComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DataspaceDataPlaneSocketClient>();\n\n\t/**\n\t * The topic for activity log events.\n\t * @internal\n\t */\n\tprivate static readonly _ACTIVITY_LOG_TOPIC = \"activity-log\";\n\n\t/**\n\t * Activity processing details route.\n\t */\n\tprivate static readonly _ACTIVITY_LOG_STATUS_ROUTE = \"activity-logs/status\";\n\n\t/**\n\t * The logging service for information.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * Subscriptions to the events.\n\t * @internal\n\t */\n\tprivate readonly _activityLogSubscriptions: {\n\t\tsubscriptionId?: string;\n\t\tsubscriberCallbacks: {\n\t\t\t[subscriptionId: string]: (notification: IActivityLogStatusNotification) => Promise<void>;\n\t\t};\n\t};\n\n\t/**\n\t * Create a new instance of DataspaceDataPlaneSocketClient.\n\t * @param options Options for the client.\n\t */\n\tconstructor(options: IDataspaceDataPlaneSocketClientConstructorOptions) {\n\t\tsuper(nameof<DataspaceDataPlaneSocketClient>(), options?.config, \"dataspace-data-plane\");\n\n\t\tthis._activityLogSubscriptions = {\n\t\t\tsubscriberCallbacks: {}\n\t\t};\n\n\t\tthis._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? \"logging\");\n\n\t\tsuper.onEvent<IHttpResponse<IActivityLogStatusNotification>>(\"publish\", async data =>\n\t\t\tthis.incomingPublishActivityLog(data)\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DataspaceDataPlaneSocketClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Notify an Activity to the Dataspace Activity Stream - implemented in REST Client.\n\t * @param activity The Activity notified.\n\t * @returns The Activity's identifier.\n\t */\n\tpublic async notifyActivity(activity: IActivityStreamsActivity): Promise<string> {\n\t\t// This method is in the REST client\n\t\tthrow new NotImplementedError(DataspaceDataPlaneSocketClient.CLASS_NAME, \"notifyActivity\");\n\t}\n\n\t/**\n\t * Subscribes to the activity log.\n\t * @param callback The callback to be called when Activity Log is called.\n\t * @param subscriptionId The subscription Id.\n\t * @returns The subscription Id.\n\t */\n\tpublic async subscribeToActivityLog(\n\t\tcallback: (notification: IActivityLogStatusNotification) => Promise<void>,\n\t\tsubscriptionId?: string\n\t): Promise<string> {\n\t\tGuards.function(DataspaceDataPlaneSocketClient.CLASS_NAME, nameof(callback), callback);\n\n\t\tlet needsConnect = false;\n\n\t\t// If we don't yet have an activity log subscription id then create one.\n\t\t// we will also need to connect to the socket.\n\t\tif (!Is.stringValue(this._activityLogSubscriptions.subscriptionId)) {\n\t\t\tthis._activityLogSubscriptions.subscriptionId = Converter.bytesToHex(\n\t\t\t\tRandomHelper.generate(16)\n\t\t\t);\n\t\t\tneedsConnect = true;\n\t\t}\n\n\t\t// Store the callback for the specific local subscription\n\t\tconst localSubscriptionId = subscriptionId ?? Converter.bytesToHex(RandomHelper.generate(16));\n\t\tthis._activityLogSubscriptions.subscriberCallbacks[localSubscriptionId] = callback;\n\n\t\t// If this the first subscription for the activity logs then send a subscribe to the socket.\n\t\tif (needsConnect && super.socketConnect()) {\n\t\t\tconst request: IActivityLogStatusRequest = {\n\t\t\t\tbody: {\n\t\t\t\t\toperation: \"subscribe\",\n\t\t\t\t\tsubscriptionId: this._activityLogSubscriptions.subscriptionId\n\t\t\t\t}\n\t\t\t};\n\t\t\tsuper.sendEvent(DataspaceDataPlaneSocketClient._ACTIVITY_LOG_STATUS_ROUTE, request);\n\t\t}\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: DataspaceDataPlaneSocketClient.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"subscribeActivityLogs\",\n\t\t\tdata: {\n\t\t\t\ttopic: DataspaceDataPlaneSocketClient._ACTIVITY_LOG_TOPIC,\n\t\t\t\tsubscriptionId: this._activityLogSubscriptions.subscriptionId\n\t\t\t}\n\t\t});\n\n\t\treturn localSubscriptionId;\n\t}\n\n\t/**\n\t * Unsubscribes to the activity log.\n\t * @param subscriptionId The subscription Id.\n\t * @returns The subscription Id.\n\t */\n\tpublic async unSubscribeToActivityLog(subscriptionId: string): Promise<void> {\n\t\tGuards.stringValue(\n\t\t\tDataspaceDataPlaneSocketClient.CLASS_NAME,\n\t\t\tnameof(subscriptionId),\n\t\t\tsubscriptionId\n\t\t);\n\n\t\tif (this._activityLogSubscriptions.subscriberCallbacks[subscriptionId]) {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: DataspaceDataPlaneSocketClient.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"unsubscribeActivityLogs\",\n\t\t\t\tdata: {\n\t\t\t\t\tsubscriptionId\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// We found the subscription id so remove it.\n\t\t\tdelete this._activityLogSubscriptions.subscriberCallbacks[subscriptionId];\n\n\t\t\t// If there are no more subscriptions for the activity logs then send an unsubscribe to the socket.\n\t\t\tif (super.socketConnect() && Is.stringValue(this._activityLogSubscriptions.subscriptionId)) {\n\t\t\t\tconst request: IActivityLogStatusRequest = {\n\t\t\t\t\tbody: {\n\t\t\t\t\t\toperation: \"unsubscribe\",\n\t\t\t\t\t\tsubscriptionId: this._activityLogSubscriptions.subscriptionId\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tsuper.sendEvent(DataspaceDataPlaneSocketClient._ACTIVITY_LOG_STATUS_ROUTE, request);\n\t\t\t}\n\t\t}\n\n\t\t// There are no more subscriptions so disconnect the socket\n\t\tif (Is.empty(this._activityLogSubscriptions.subscriptionId)) {\n\t\t\tsuper.socketDisconnect();\n\t\t}\n\t}\n\n\t/**\n\t * Returns Activity Log Entry which contains the Activity processing details - implemented in REST Client.\n\t * @param logEntryId The Id of the Activity Log Entry (a URI).\n\t * @returns the Activity Log Entry with the processing details.\n\t * @throws NotFoundError if activity log entry is not known.\n\t */\n\tpublic async getActivityLogEntry(logEntryId: string): Promise<IActivityLogEntry> {\n\t\t// This method is in the REST client\n\t\tthrow new NotSupportedError(DataspaceDataPlaneSocketClient.CLASS_NAME, \"notSupportedOnClient\", {\n\t\t\tmethodName: \"getActivityLogEntry\"\n\t\t});\n\t}\n\n\t/**\n\t * Get Data Asset entities. Allows to retrieve entities by their type or id.\n\t * @param entitySet The set of entities to be retrieved.\n\t * @param entitySet.jsonLdContext The JSON-LD Context to be used to expand the referred entityType.\n\t * @param consumerPid The consumer Process ID from the DSP Transfer Process.\n\t * Used to resolve datasetId from the Transfer Process.\n\t * @param cursor Pagination details - cursor.\n\t * @param limit Pagination details - max number of entities.\n\t * @param trustPayload Trust payload to verify the requesters identity.\n\t * @returns The item list and optional cursor for pagination via Link headers.\n\t */\n\tpublic async getDataAssetEntities(\n\t\tentitySet: IEntitySet & {\n\t\t\tjsonLdContext?: IJsonLdContextDefinitionElement[];\n\t\t},\n\t\tconsumerPid: string,\n\t\tcursor?: string,\n\t\tlimit?: number,\n\t\ttrustPayload?: unknown\n\t): Promise<IDataAssetItemListResult> {\n\t\tthrow new NotSupportedError(DataspaceDataPlaneSocketClient.CLASS_NAME, \"notSupportedOnClient\", {\n\t\t\tmethodName: \"getDataAssetEntities\"\n\t\t});\n\t}\n\n\t/**\n\t * Queries a data asset controlled by this Dataspace App.\n\t * @param consumerPid The consumer Process ID from the DSP Transfer Process.\n\t * Used to resolve datasetId from the Transfer Process.\n\t * @param query The filtering query.\n\t * @param cursor Pagination details - cursor.\n\t * @param limit Pagination details - max number of entities.\n\t * @param trustPayload Trust payload to verify the requesters identity.\n\t * @returns The item list and optional cursor for pagination via Link headers.\n\t */\n\tpublic async queryDataAsset(\n\t\tconsumerPid: string,\n\t\tquery: IFilteringQuery,\n\t\tcursor?: string,\n\t\tlimit?: number,\n\t\ttrustPayload?: unknown\n\t): Promise<IDataAssetItemListResult> {\n\t\tthrow new NotSupportedError(DataspaceDataPlaneSocketClient.CLASS_NAME, \"notSupportedOnClient\", {\n\t\t\tmethodName: \"queryDataAsset\"\n\t\t});\n\t}\n\n\t/**\n\t * Handle the socket connection.\n\t */\n\tprotected async handleConnected(): Promise<void> {\n\t\t// The socket has reconnected so send subscribe requests\n\t\t// for all the current subscriptions\n\t\tif (\n\t\t\tObject.keys(this._activityLogSubscriptions.subscriberCallbacks).length > 0 &&\n\t\t\tIs.stringValue(this._activityLogSubscriptions.subscriptionId)\n\t\t) {\n\t\t\tconst subscribeEmit: IActivityLogStatusRequest = {\n\t\t\t\tbody: {\n\t\t\t\t\toperation: \"subscribe\",\n\t\t\t\t\tsubscriptionId: this._activityLogSubscriptions.subscriptionId\n\t\t\t\t}\n\t\t\t};\n\t\t\tsuper.sendEvent(DataspaceDataPlaneSocketClient._ACTIVITY_LOG_STATUS_ROUTE, subscribeEmit);\n\t\t}\n\t}\n\n\t/**\n\t * Handle an error.\n\t * @param err The error to handle.\n\t */\n\tprotected async handleError(err: IError): Promise<void> {\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"error\",\n\t\t\tsource: DataspaceDataPlaneSocketClient.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"socketConnect\",\n\t\t\terror: err\n\t\t});\n\t}\n\n\t/**\n\t * Handle an incoming publish event.\n\t * @param topic The incoming topic.\n\t * @param event The incoming data.\n\t * @internal\n\t */\n\tprivate async incomingPublishActivityLog(\n\t\tevent: IHttpResponse<IActivityLogStatusNotification>\n\t): Promise<void> {\n\t\tif (!Is.empty(event.body)) {\n\t\t\tfor (const subscriptionId in this._activityLogSubscriptions.subscriberCallbacks) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this._activityLogSubscriptions.subscriberCallbacks[subscriptionId](event.body);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\t\tsource: DataspaceDataPlaneSocketClient.CLASS_NAME,\n\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\tmessage: \"callback\",\n\t\t\t\t\t\terror: BaseError.fromError(error),\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tsubscriptionId\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Copyright 2025 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./dataspaceDataPlaneSocketClient.js";
|
|
4
|
+
export * from "./models/IDataspaceDataPlaneSocketClientConfig.js";
|
|
5
|
+
export * from "./models/IDataspaceDataPlaneSocketClientConstructorOptions.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,qCAAqC,CAAC;AACpD,cAAc,mDAAmD,CAAC;AAClE,cAAc,+DAA+D,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./dataspaceDataPlaneSocketClient.js\";\nexport * from \"./models/IDataspaceDataPlaneSocketClientConfig.js\";\nexport * from \"./models/IDataspaceDataPlaneSocketClientConstructorOptions.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDataspaceDataPlaneSocketClientConfig.js","sourceRoot":"","sources":["../../../src/models/IDataspaceDataPlaneSocketClientConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseSocketClientConfig } from \"@twin.org/api-models\";\n\n/**\n * Definition of Dataspace Data Plane client configuration.\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IDataspaceDataPlaneSocketClientConfig extends IBaseSocketClientConfig {}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDataspaceDataPlaneSocketClientConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IDataspaceDataPlaneSocketClientConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDataspaceDataPlaneSocketClientConfig } from \"./IDataspaceDataPlaneSocketClientConfig.js\";\n\n/**\n * The options for the dataspace data plane socket client.\n */\nexport interface IDataspaceDataPlaneSocketClientConstructorOptions {\n\t/**\n\t * The type of logging component to use.\n\t */\n\tloggingComponentType?: string;\n\n\t/**\n\t * The configuration for the dataspace data plane socket client.\n\t */\n\tconfig: IDataspaceDataPlaneSocketClientConfig;\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BaseSocketClient } from "@twin.org/api-core";
|
|
2
|
+
import { type IError } from "@twin.org/core";
|
|
3
|
+
import type { IJsonLdContextDefinitionElement } from "@twin.org/data-json-ld";
|
|
4
|
+
import type { IActivityLogEntry, IActivityLogStatusNotification, IDataAssetItemListResult, IDataspaceDataPlaneComponent, IEntitySet, IFilteringQuery } from "@twin.org/dataspace-models";
|
|
5
|
+
import type { IActivityStreamsActivity } from "@twin.org/standards-w3c-activity-streams";
|
|
6
|
+
import type { IDataspaceDataPlaneSocketClientConstructorOptions } from "./models/IDataspaceDataPlaneSocketClientConstructorOptions.js";
|
|
7
|
+
/**
|
|
8
|
+
* Dataspace data plane client which publishes using REST API and websockets.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DataspaceDataPlaneSocketClient extends BaseSocketClient implements IDataspaceDataPlaneComponent {
|
|
11
|
+
/**
|
|
12
|
+
* Runtime name for the class.
|
|
13
|
+
*/
|
|
14
|
+
static readonly CLASS_NAME: string;
|
|
15
|
+
/**
|
|
16
|
+
* Activity processing details route.
|
|
17
|
+
*/
|
|
18
|
+
private static readonly _ACTIVITY_LOG_STATUS_ROUTE;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of DataspaceDataPlaneSocketClient.
|
|
21
|
+
* @param options Options for the client.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options: IDataspaceDataPlaneSocketClientConstructorOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Returns the class name of the component.
|
|
26
|
+
* @returns The class name of the component.
|
|
27
|
+
*/
|
|
28
|
+
className(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Notify an Activity to the Dataspace Activity Stream - implemented in REST Client.
|
|
31
|
+
* @param activity The Activity notified.
|
|
32
|
+
* @returns The Activity's identifier.
|
|
33
|
+
*/
|
|
34
|
+
notifyActivity(activity: IActivityStreamsActivity): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribes to the activity log.
|
|
37
|
+
* @param callback The callback to be called when Activity Log is called.
|
|
38
|
+
* @param subscriptionId The subscription Id.
|
|
39
|
+
* @returns The subscription Id.
|
|
40
|
+
*/
|
|
41
|
+
subscribeToActivityLog(callback: (notification: IActivityLogStatusNotification) => Promise<void>, subscriptionId?: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Unsubscribes to the activity log.
|
|
44
|
+
* @param subscriptionId The subscription Id.
|
|
45
|
+
* @returns The subscription Id.
|
|
46
|
+
*/
|
|
47
|
+
unSubscribeToActivityLog(subscriptionId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns Activity Log Entry which contains the Activity processing details - implemented in REST Client.
|
|
50
|
+
* @param logEntryId The Id of the Activity Log Entry (a URI).
|
|
51
|
+
* @returns the Activity Log Entry with the processing details.
|
|
52
|
+
* @throws NotFoundError if activity log entry is not known.
|
|
53
|
+
*/
|
|
54
|
+
getActivityLogEntry(logEntryId: string): Promise<IActivityLogEntry>;
|
|
55
|
+
/**
|
|
56
|
+
* Get Data Asset entities. Allows to retrieve entities by their type or id.
|
|
57
|
+
* @param entitySet The set of entities to be retrieved.
|
|
58
|
+
* @param entitySet.jsonLdContext The JSON-LD Context to be used to expand the referred entityType.
|
|
59
|
+
* @param consumerPid The consumer Process ID from the DSP Transfer Process.
|
|
60
|
+
* Used to resolve datasetId from the Transfer Process.
|
|
61
|
+
* @param cursor Pagination details - cursor.
|
|
62
|
+
* @param limit Pagination details - max number of entities.
|
|
63
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
64
|
+
* @returns The item list and optional cursor for pagination via Link headers.
|
|
65
|
+
*/
|
|
66
|
+
getDataAssetEntities(entitySet: IEntitySet & {
|
|
67
|
+
jsonLdContext?: IJsonLdContextDefinitionElement[];
|
|
68
|
+
}, consumerPid: string, cursor?: string, limit?: number, trustPayload?: unknown): Promise<IDataAssetItemListResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Queries a data asset controlled by this Dataspace App.
|
|
71
|
+
* @param consumerPid The consumer Process ID from the DSP Transfer Process.
|
|
72
|
+
* Used to resolve datasetId from the Transfer Process.
|
|
73
|
+
* @param query The filtering query.
|
|
74
|
+
* @param cursor Pagination details - cursor.
|
|
75
|
+
* @param limit Pagination details - max number of entities.
|
|
76
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
77
|
+
* @returns The item list and optional cursor for pagination via Link headers.
|
|
78
|
+
*/
|
|
79
|
+
queryDataAsset(consumerPid: string, query: IFilteringQuery, cursor?: string, limit?: number, trustPayload?: unknown): Promise<IDataAssetItemListResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Handle the socket connection.
|
|
82
|
+
*/
|
|
83
|
+
protected handleConnected(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Handle an error.
|
|
86
|
+
* @param err The error to handle.
|
|
87
|
+
*/
|
|
88
|
+
protected handleError(err: IError): Promise<void>;
|
|
89
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDataspaceDataPlaneSocketClientConfig } from "./IDataspaceDataPlaneSocketClientConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* The options for the dataspace data plane socket client.
|
|
4
|
+
*/
|
|
5
|
+
export interface IDataspaceDataPlaneSocketClientConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The type of logging component to use.
|
|
8
|
+
*/
|
|
9
|
+
loggingComponentType?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The configuration for the dataspace data plane socket client.
|
|
12
|
+
*/
|
|
13
|
+
config: IDataspaceDataPlaneSocketClientConfig;
|
|
14
|
+
}
|