@oceanprotocol/lib 10.0.0-next.1 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +213 -149
- package/dist/lib.modern.mjs +2 -2
- package/dist/lib.module.mjs +2 -2
- package/dist/types/@types/Provider.d.ts +12 -0
- package/dist/types/services/providers/BaseProvider.d.ts +14 -0
- package/dist/types/services/providers/HttpProvider.d.ts +26 -0
- package/dist/types/services/providers/P2pProvider.d.ts +37 -0
- package/dist/types/utils/ProviderErrors.d.ts +41 -0
- package/package.json +2 -2
|
@@ -50,6 +50,15 @@ export interface NodeStatusIndexer {
|
|
|
50
50
|
network: string;
|
|
51
51
|
block: string;
|
|
52
52
|
}
|
|
53
|
+
export interface NodeStatusMaintenance {
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
/** Detailed status only: compute jobs still running while draining. */
|
|
56
|
+
runningComputeJobs?: number;
|
|
57
|
+
/** Detailed status only: services still running while draining. */
|
|
58
|
+
runningServices?: number;
|
|
59
|
+
/** Detailed status only: unix seconds, drain ETA. */
|
|
60
|
+
latestExpectedEndTime?: number;
|
|
61
|
+
}
|
|
53
62
|
export interface NodeStatus {
|
|
54
63
|
id: string;
|
|
55
64
|
publicKey: string;
|
|
@@ -61,6 +70,8 @@ export interface NodeStatus {
|
|
|
61
70
|
provider: NodeStatusProvider[];
|
|
62
71
|
indexer: NodeStatusIndexer[];
|
|
63
72
|
escrowAddress: Record<string, string>;
|
|
73
|
+
/** Maintenance (drain) mode. Absent on nodes that predate the feature. */
|
|
74
|
+
maintenance?: NodeStatusMaintenance;
|
|
64
75
|
supportedStorage: Record<string, boolean>;
|
|
65
76
|
platform: {
|
|
66
77
|
cpus: number;
|
|
@@ -227,6 +238,7 @@ export declare const PROTOCOL_COMMANDS: {
|
|
|
227
238
|
FETCH_CONFIG: string;
|
|
228
239
|
PUSH_CONFIG: string;
|
|
229
240
|
GET_LOGS: string;
|
|
241
|
+
SET_MAINTENANCE: string;
|
|
230
242
|
JOBS: string;
|
|
231
243
|
PERSISTENT_STORAGE_CREATE_BUCKET: string;
|
|
232
244
|
PERSISTENT_STORAGE_UPDATE_BUCKET: string;
|
|
@@ -124,6 +124,20 @@ export declare class BaseProvider {
|
|
|
124
124
|
PolicyServerPassthrough(nodeUri: OceanNode, request: PolicyServerPassthroughCommand, signal?: AbortSignal): Promise<any>;
|
|
125
125
|
initializePSVerification(nodeUri: OceanNode, signerOrAuthToken: SignerOrAuthTokenOrSignature, request: PolicyServerInitializeCommand, signal?: AbortSignal): Promise<any>;
|
|
126
126
|
downloadNodeLogs(nodeUri: OceanNode, signerOrAuthToken: SignerOrAuthTokenOrSignature, startTime: string, endTime: string, maxLogs?: number, moduleName?: string, level?: string, page?: number, signal?: AbortSignal): Promise<NodeLogEntry[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Enables or disables the node's maintenance (drain) mode. Admin only.
|
|
129
|
+
* While enabled the node rejects new compute/service requests with
|
|
130
|
+
* `code: 'MAINTENANCE_MODE'` (detect with `isMaintenanceError`); running jobs continue.
|
|
131
|
+
* Works over HTTP (`POST /api/admin/maintenance`) and P2P.
|
|
132
|
+
* @param {OceanNode} nodeUri - The node URI / peerId / multiaddr.
|
|
133
|
+
* @param {SignerOrAuthTokenOrSignature} signerOrAuthToken - Admin signer / auth token.
|
|
134
|
+
* @param {boolean} enabled - true to start draining, false to resume.
|
|
135
|
+
* @param {AbortSignal} [signal] - An optional abort signal.
|
|
136
|
+
* @returns {Promise<{ maintenance: boolean }>} The node's resulting maintenance state.
|
|
137
|
+
*/
|
|
138
|
+
setMaintenance(nodeUri: OceanNode, signerOrAuthToken: SignerOrAuthTokenOrSignature, enabled: boolean, signal?: AbortSignal): Promise<{
|
|
139
|
+
maintenance: boolean;
|
|
140
|
+
}>;
|
|
127
141
|
getNodeStatus(nodeUri: OceanNode, signal?: AbortSignal): Promise<NodeStatus>;
|
|
128
142
|
getNodeJobs(nodeUri: OceanNode, fromTimestamp?: number, signal?: AbortSignal): Promise<NodeComputeJob[]>;
|
|
129
143
|
/**
|
|
@@ -285,6 +285,32 @@ export declare class HttpProvider {
|
|
|
285
285
|
* @returns {Promise<any>} The logs response body stream.
|
|
286
286
|
*/
|
|
287
287
|
downloadNodeLogs(nodeUri: string, signerOrAuthToken: SignerOrAuthTokenOrSignature, startTime: string, endTime: string, maxLogs?: number, moduleName?: string, level?: string, page?: number, signal?: AbortSignal): Promise<NodeLogEntry[]>;
|
|
288
|
+
/**
|
|
289
|
+
* Builds the typed error for a non-ok response whose body is read as text. The message
|
|
290
|
+
* stays the raw text (as before); `code`/`body` are populated when the text is JSON.
|
|
291
|
+
*/
|
|
292
|
+
private toProviderError;
|
|
293
|
+
/**
|
|
294
|
+
* Enables or disables the node's maintenance (drain) mode. Admin only: the caller must
|
|
295
|
+
* be in the node's ALLOWED_ADMINS / admin access list.
|
|
296
|
+
*
|
|
297
|
+
* While enabled the node rejects new commitment (`computeStart`, `freeComputeStart`,
|
|
298
|
+
* `initializeCompute`, `serviceStart`, `serviceExtend`) with HTTP 503 and
|
|
299
|
+
* `code: 'MAINTENANCE_MODE'` (see `isMaintenanceError`); running jobs and services
|
|
300
|
+
* continue. Read progress via `getNodeStatus` (`maintenance`).
|
|
301
|
+
*
|
|
302
|
+
* Calls `POST /api/admin/maintenance`. The request is signed over
|
|
303
|
+
* `address + nonce + 'setMaintenance'`; `enabled` is sent as a real JSON boolean, which
|
|
304
|
+
* the node requires.
|
|
305
|
+
* @param {string} nodeUri - The node URI.
|
|
306
|
+
* @param {SignerOrAuthTokenOrSignature} signerOrAuthToken - Admin signer / auth token.
|
|
307
|
+
* @param {boolean} enabled - true to start draining, false to resume.
|
|
308
|
+
* @param {AbortSignal} [signal] - An optional abort signal.
|
|
309
|
+
* @returns {Promise<{ maintenance: boolean }>} The node's resulting maintenance state.
|
|
310
|
+
*/
|
|
311
|
+
setMaintenance(nodeUri: string, signerOrAuthToken: SignerOrAuthTokenOrSignature, enabled: boolean, signal?: AbortSignal): Promise<{
|
|
312
|
+
maintenance: boolean;
|
|
313
|
+
}>;
|
|
288
314
|
private noZeroX;
|
|
289
315
|
private zeroXTransformer;
|
|
290
316
|
private inputMatch;
|
|
@@ -68,14 +68,29 @@ export declare class P2pError extends Error {
|
|
|
68
68
|
readonly peerResponse?: {
|
|
69
69
|
value: unknown;
|
|
70
70
|
};
|
|
71
|
+
/** HTTP status the peer reported in its status frame, when it reported one. */
|
|
72
|
+
readonly httpStatus?: number;
|
|
73
|
+
/** Machine-readable `code` from the peer's status frame (e.g. `MAINTENANCE_MODE`). */
|
|
74
|
+
readonly code?: string;
|
|
75
|
+
/** The peer's status frame / reply body, when it reported the failure itself. */
|
|
76
|
+
readonly body?: unknown;
|
|
71
77
|
constructor(type: P2pErrorType, message: string, options?: {
|
|
72
78
|
cause?: unknown;
|
|
73
79
|
peerId?: string;
|
|
74
80
|
peerResponse?: {
|
|
75
81
|
value: unknown;
|
|
76
82
|
};
|
|
83
|
+
httpStatus?: number;
|
|
84
|
+
code?: string;
|
|
85
|
+
body?: unknown;
|
|
77
86
|
});
|
|
78
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Wraps a peer-reported failure (a status frame with `httpStatus >= 400`) so the
|
|
90
|
+
* node's `code`, status and body survive. The message is the same text the untyped
|
|
91
|
+
* code threw; `asP2pCommandError` adds the usual `P2P command error:` prefix later.
|
|
92
|
+
*/
|
|
93
|
+
export declare function peerReportedError(frame: Record<string, any>, message: string): P2pError;
|
|
79
94
|
/**
|
|
80
95
|
* Classifies a thrown value.
|
|
81
96
|
*
|
|
@@ -89,6 +104,11 @@ export declare class P2pError extends Error {
|
|
|
89
104
|
*/
|
|
90
105
|
export declare function classifyP2pError(err: unknown): P2pErrorType;
|
|
91
106
|
export declare function isRetryableP2pError(type: P2pErrorType): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Final error for a failed command. Preserves the `P2P command error: <message>`
|
|
109
|
+
* shaping the untyped code produced — consumers match on it — and adds the type.
|
|
110
|
+
*/
|
|
111
|
+
export declare function asP2pCommandError(err: unknown, type: P2pErrorType): P2pError;
|
|
92
112
|
/**
|
|
93
113
|
* Optional request payload sent as LP frames after the command JSON; ends with an empty LP frame.
|
|
94
114
|
* This mirrors ocean-node's `p2pStreamBody` mechanism introduced for true streaming uploads.
|
|
@@ -667,6 +687,23 @@ export declare class P2pProvider {
|
|
|
667
687
|
* string: `consumerAddress + nonce + "PolicyServerInitialize"`.
|
|
668
688
|
*/
|
|
669
689
|
initializePSVerification(nodeUri: OceanNode, signerOrAuthToken: SignerOrAuthTokenOrSignature, request: PolicyServerInitializeCommand, signal?: AbortSignal): Promise<any>;
|
|
690
|
+
/**
|
|
691
|
+
* Enables or disables the node's maintenance (drain) mode via P2P. Admin only.
|
|
692
|
+
*
|
|
693
|
+
* While enabled the node rejects new `computeStart`, `freeComputeStart`,
|
|
694
|
+
* `initializeCompute`, `serviceStart` and `serviceExtend` with `code: 'MAINTENANCE_MODE'`
|
|
695
|
+
* (see `isMaintenanceError`); running jobs continue. The request is signed over
|
|
696
|
+
* `address + nonce + 'setMaintenance'` and `enabled` is sent as a real boolean, which the
|
|
697
|
+
* node requires.
|
|
698
|
+
* @param {OceanNode} nodeUri - The node peerId / multiaddr.
|
|
699
|
+
* @param {SignerOrAuthTokenOrSignature} signerOrAuthToken - Admin signer / auth token.
|
|
700
|
+
* @param {boolean} enabled - true to start draining, false to resume.
|
|
701
|
+
* @param {AbortSignal} [signal] - An optional abort signal.
|
|
702
|
+
* @returns {Promise<{ maintenance: boolean }>} The node's resulting maintenance state.
|
|
703
|
+
*/
|
|
704
|
+
setMaintenance(nodeUri: OceanNode, signerOrAuthToken: SignerOrAuthTokenOrSignature, enabled: boolean, signal?: AbortSignal): Promise<{
|
|
705
|
+
maintenance: boolean;
|
|
706
|
+
}>;
|
|
670
707
|
/**
|
|
671
708
|
* Download node logs via P2P.
|
|
672
709
|
*/
|
|
@@ -1 +1,42 @@
|
|
|
1
1
|
export declare function getErrorMessage(err: string): string;
|
|
2
|
+
/** Machine-readable `code` the node attaches to maintenance (drain mode) rejections. */
|
|
3
|
+
export declare const MAINTENANCE_MODE_CODE = "MAINTENANCE_MODE";
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when an Ocean Node answers a request with a non-ok response.
|
|
6
|
+
*
|
|
7
|
+
* Extends `Error` and keeps `message` byte-identical to what the library threw before
|
|
8
|
+
* (the JSON-stringified response body, or the raw text when that is what was read), so
|
|
9
|
+
* `e.message`, `instanceof Error` and `JSON.parse(e.message)` keep working. The extra
|
|
10
|
+
* fields let callers branch on a machine-readable `code` instead of matching text.
|
|
11
|
+
*/
|
|
12
|
+
export declare class OceanNodeProviderError extends Error {
|
|
13
|
+
/** HTTP status of the node's reply (also carried on the P2P status frame). */
|
|
14
|
+
readonly httpStatus?: number;
|
|
15
|
+
/** Machine-readable code from the node's body, e.g. `MAINTENANCE_MODE`. */
|
|
16
|
+
readonly code?: string;
|
|
17
|
+
/** The node's response body: parsed JSON when it was JSON, raw text otherwise. */
|
|
18
|
+
readonly body?: any;
|
|
19
|
+
/**
|
|
20
|
+
* @param resolved The node's response body (parsed JSON or raw text).
|
|
21
|
+
* @param httpStatus HTTP status of the response.
|
|
22
|
+
* @param message Optional message override; defaults to `JSON.stringify(resolved)`.
|
|
23
|
+
* Callers that read the body as text (e.g. `toProviderError`) pass that text here so
|
|
24
|
+
* the message stays byte-identical to the pre-existing `new Error(text)` throw.
|
|
25
|
+
*/
|
|
26
|
+
constructor(resolved: any, httpStatus?: number, message?: string);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* True when `e` is a node rejection caused by maintenance (drain) mode.
|
|
30
|
+
* Works for both transports: HTTP throws `OceanNodeProviderError`, P2P throws a
|
|
31
|
+
* `P2pError` that carries the same `code` field.
|
|
32
|
+
*
|
|
33
|
+
* A type guard: in the true branch `e` narrows to an `Error` whose `code` is
|
|
34
|
+
* `MAINTENANCE_MODE_CODE`. `httpStatus` and `body` are exposed as OPTIONAL because this
|
|
35
|
+
* check does not validate them — they are present on the errors the library throws, but
|
|
36
|
+
* the guard only asserts `code`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isMaintenanceError(e: unknown): e is Error & {
|
|
39
|
+
code: typeof MAINTENANCE_MODE_CODE;
|
|
40
|
+
httpStatus?: number;
|
|
41
|
+
body?: unknown;
|
|
42
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oceanprotocol/lib",
|
|
3
3
|
"source": "./src/index.ts",
|
|
4
|
-
"version": "10.0.0
|
|
4
|
+
"version": "10.0.0",
|
|
5
5
|
"description": "JavaScript client library for Ocean Protocol",
|
|
6
6
|
"module": "./dist/lib.module.mjs",
|
|
7
7
|
"type": "module",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@eslint/js": "^10.0.1",
|
|
108
108
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
109
|
-
"@oceanprotocol/contracts": "^3.2.0
|
|
109
|
+
"@oceanprotocol/contracts": "^3.2.0",
|
|
110
110
|
"@types/chai": "^5.2.3",
|
|
111
111
|
"@types/crypto-js": "^4.2.2",
|
|
112
112
|
"@types/jsonwebtoken": "^9.0.10",
|