@oceanprotocol/lib 10.0.0-next.1 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +213 -149
- package/dist/lib.modern.mjs +2 -2
- package/dist/lib.module.mjs +2 -2
- package/dist/types/@types/Compute.d.ts +14 -0
- package/dist/types/@types/Provider.d.ts +24 -0
- package/dist/types/@types/SubsidyEstimate.d.ts +112 -0
- package/dist/types/@types/index.d.ts +1 -0
- package/dist/types/contracts/Escrow.d.ts +3 -2
- 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/dist/types/utils/ServiceCost.d.ts +30 -0
- package/dist/types/utils/SubsidyEstimate.d.ts +41 -0
- package/dist/types/utils/SubsidyImage.d.ts +51 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/package.json +3 -3
|
@@ -22,6 +22,20 @@ export interface ComputeResourceRequest {
|
|
|
22
22
|
id: string;
|
|
23
23
|
amount: number;
|
|
24
24
|
}
|
|
25
|
+
/** Result of `estimateServiceCost` — mirrors ocean-node's `calculateResourcesCost`. */
|
|
26
|
+
export interface ServiceCostEstimate {
|
|
27
|
+
/** Cost in human token units, computed with the node's own arithmetic. */
|
|
28
|
+
costHuman: number;
|
|
29
|
+
/** `feeToken` verbatim as the env advertised it (send this back, not the caller's casing). */
|
|
30
|
+
feeToken: string;
|
|
31
|
+
/** Duration after the env minimum-duration floor clamp. */
|
|
32
|
+
effectiveDurationSeconds: number;
|
|
33
|
+
/** `ceil(effectiveDuration / 60)` — what the node actually bills. */
|
|
34
|
+
minutesBilled: number;
|
|
35
|
+
resources: ComputeResourceRequest[];
|
|
36
|
+
/** Resource ids the env has no price for; the node prices these at 0 silently. */
|
|
37
|
+
unpricedResourceIds: string[];
|
|
38
|
+
}
|
|
25
39
|
export interface ComputeResource {
|
|
26
40
|
id: string;
|
|
27
41
|
type?: ComputeResourceType;
|
|
@@ -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,20 @@ export interface NodeStatus {
|
|
|
61
70
|
provider: NodeStatusProvider[];
|
|
62
71
|
indexer: NodeStatusIndexer[];
|
|
63
72
|
escrowAddress: Record<string, string>;
|
|
73
|
+
/** chainId -> subsidy-provider contract addresses the node applies. Absent on older nodes. */
|
|
74
|
+
subsidyProviders?: Record<string, string[]>;
|
|
75
|
+
/**
|
|
76
|
+
* When true, a caller-supplied `subsidyProviders` list must be a subset of the node's
|
|
77
|
+
* `subsidyProviders` for the chain (the node rejects the request otherwise). Absent on older nodes.
|
|
78
|
+
*/
|
|
79
|
+
subsidyProviderFilter?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Per-provider-contract image allowlist (provider address -> allowed docker refs). A provider
|
|
82
|
+
* only subsidizes a job whose image matches; `{}` / absent = unrestricted. Absent on older nodes.
|
|
83
|
+
*/
|
|
84
|
+
subsidyProviderAllowedImages?: Record<string, string[]>;
|
|
85
|
+
/** Maintenance (drain) mode. Absent on nodes that predate the feature. */
|
|
86
|
+
maintenance?: NodeStatusMaintenance;
|
|
64
87
|
supportedStorage: Record<string, boolean>;
|
|
65
88
|
platform: {
|
|
66
89
|
cpus: number;
|
|
@@ -227,6 +250,7 @@ export declare const PROTOCOL_COMMANDS: {
|
|
|
227
250
|
FETCH_CONFIG: string;
|
|
228
251
|
PUSH_CONFIG: string;
|
|
229
252
|
GET_LOGS: string;
|
|
253
|
+
SET_MAINTENANCE: string;
|
|
230
254
|
JOBS: string;
|
|
231
255
|
PERSISTENT_STORAGE_CREATE_BUCKET: string;
|
|
232
256
|
PERSISTENT_STORAGE_UPDATE_BUCKET: string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Signer } from 'ethers';
|
|
2
|
+
import type { Config } from '../config/index.js';
|
|
3
|
+
import type { ComputeResourceRequest } from './Compute.js';
|
|
4
|
+
import type { OceanNode } from './Provider.js';
|
|
5
|
+
import type { SubsidyKind, SubsidyMode, SubsidyQuote } from './SubsidyView.js';
|
|
6
|
+
import type { SubsidyImageContainer } from '../utils/SubsidyImage.js';
|
|
7
|
+
import type { BaseProvider } from '../services/providers/BaseProvider.js';
|
|
8
|
+
/** Why a subsidy-provider candidate was excluded from the selection. */
|
|
9
|
+
export type SubsidyDropReason = 'image_not_allowed' | 'outside_node_set' | 'node_not_allowed' | 'user_not_allowed' | 'job_type_not_subsidized' | 'zero_quote' | 'error';
|
|
10
|
+
export interface EstimateJobSubsidyParams {
|
|
11
|
+
signer: Signer;
|
|
12
|
+
chainId: number;
|
|
13
|
+
/** Payer (consumer) address. */
|
|
14
|
+
payer: string;
|
|
15
|
+
/** Works over HTTP or P2P (the provider façade dispatches). */
|
|
16
|
+
node: OceanNode;
|
|
17
|
+
token: string;
|
|
18
|
+
environmentId: string;
|
|
19
|
+
/** Caller-supplied resources (no auto-selection). */
|
|
20
|
+
resources: ComputeResourceRequest[];
|
|
21
|
+
durationSeconds: number;
|
|
22
|
+
/** REQUIRED — ocean-node numbering: COMPUTE=1, SERVICE=2. */
|
|
23
|
+
jobType: number | string;
|
|
24
|
+
/** The image gate needs tag/checksum/dockerfile, not just an image name. */
|
|
25
|
+
container: SubsidyImageContainer;
|
|
26
|
+
/**
|
|
27
|
+
* Set true when the job must NOT be subsidized under a provider's image allowlist because the
|
|
28
|
+
* workload is not the trusted operator image. The caller computes it with the node's OWN predicate
|
|
29
|
+
* for the job type (the helper takes no algorithm/task object, so it cannot derive this):
|
|
30
|
+
* - service: `isNonEmpty(dockerEntrypoint) || isNonEmpty(dockerCmd)`
|
|
31
|
+
* - compute: `isNonEmpty(algorithm.meta.container.entrypoint) || hasUserSuppliedAlgorithm(algorithm)`
|
|
32
|
+
* where a user-supplied algorithm (rawcode, a `fileObject`, or a `documentId`/`serviceId` DID) is
|
|
33
|
+
* untrusted and must set this true. Omitting it for compute would subsidize an attacker algorithm
|
|
34
|
+
* run against a trusted image's allowlist. Default false.
|
|
35
|
+
*/
|
|
36
|
+
hasCustomEntrypoint?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Compute-only: the env's queue max wait (seconds). Added to the lock duration used for
|
|
39
|
+
* `minLockSeconds` (the node locks for job duration + queue wait), NOT to the billed cost.
|
|
40
|
+
* Default 0.
|
|
41
|
+
*/
|
|
42
|
+
queueMaxWaitTime?: number;
|
|
43
|
+
/** Added to what the node advertises (see the filter semantics on `estimateJobSubsidy`). */
|
|
44
|
+
customSubsidyProviders?: string[];
|
|
45
|
+
/** Human token units; default = the job cost. */
|
|
46
|
+
subsidyNeeded?: string;
|
|
47
|
+
tokenDecimals?: number;
|
|
48
|
+
config?: Config;
|
|
49
|
+
/** Defaults to the shared `ProviderInstance`. */
|
|
50
|
+
provider?: BaseProvider;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
}
|
|
53
|
+
export interface JobSubsidyProviderQuote {
|
|
54
|
+
/** Checksummed address (raw input when it was not a valid address). */
|
|
55
|
+
address: string;
|
|
56
|
+
subsidyKind: SubsidyKind | null;
|
|
57
|
+
version: number | null;
|
|
58
|
+
isV2: boolean;
|
|
59
|
+
gates: {
|
|
60
|
+
/** Gate off OR address unlisted OR an allowlist entry matches. */
|
|
61
|
+
imageAllowed: boolean;
|
|
62
|
+
/** null = the provider does not expose the check (unknown, NOT disqualifying). */
|
|
63
|
+
isNodeAllowed: boolean | null;
|
|
64
|
+
isUserAllowed: boolean | null;
|
|
65
|
+
isJobTypeSubsidized: boolean | null;
|
|
66
|
+
};
|
|
67
|
+
/** Image allowed AND no gate is an explicit false. */
|
|
68
|
+
eligible: boolean;
|
|
69
|
+
dropped?: SubsidyDropReason;
|
|
70
|
+
reason?: string;
|
|
71
|
+
/** Human token units; a v1 provider's prefunded leg is '0'. */
|
|
72
|
+
quotes: {
|
|
73
|
+
reimbursement: SubsidyQuote;
|
|
74
|
+
prefunded: SubsidyQuote;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface JobSubsidyScenario {
|
|
78
|
+
mode: SubsidyMode;
|
|
79
|
+
/** THE list to pass as `subsidyProviders` at start. */
|
|
80
|
+
selected: string[];
|
|
81
|
+
/** Sum of the selected providers under this mode, capped at the cost. */
|
|
82
|
+
projectedTotalSubsidy: string;
|
|
83
|
+
meetsSubsidyNeeded: boolean;
|
|
84
|
+
/** REIMBURSEMENT = cost; PREFUNDED = max(0, cost - projectedTotalSubsidy). */
|
|
85
|
+
escrowNeeded: string;
|
|
86
|
+
/** Payer's withdrawable escrow balance for the token. */
|
|
87
|
+
escrowAvailable: string;
|
|
88
|
+
/** max(0, escrowNeeded - escrowAvailable). */
|
|
89
|
+
escrowShortfall: string;
|
|
90
|
+
}
|
|
91
|
+
export interface JobSubsidyEstimate {
|
|
92
|
+
chainId: number;
|
|
93
|
+
/** Payee (node status `address`). */
|
|
94
|
+
node: string;
|
|
95
|
+
token: string;
|
|
96
|
+
/** Human token units (the node is authoritative at start). */
|
|
97
|
+
cost: string;
|
|
98
|
+
costBaseUnits: string;
|
|
99
|
+
minutesBilled: number;
|
|
100
|
+
minLockSeconds: number;
|
|
101
|
+
escrowAddress: string;
|
|
102
|
+
maxSponsorsPerLock: number;
|
|
103
|
+
subsidyProviderFilter: boolean;
|
|
104
|
+
subsidyNeeded: string;
|
|
105
|
+
unpricedResourceIds: string[];
|
|
106
|
+
providers: JobSubsidyProviderQuote[];
|
|
107
|
+
scenarios: {
|
|
108
|
+
reimbursement: JobSubsidyScenario;
|
|
109
|
+
prefunded: JobSubsidyScenario;
|
|
110
|
+
};
|
|
111
|
+
warnings: string[];
|
|
112
|
+
}
|
|
@@ -66,7 +66,8 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
66
66
|
* to check that the shortfall is affordable. The payee is (re-)authorized up to the funding
|
|
67
67
|
* target.
|
|
68
68
|
* @param {String} token as payment token for escrow
|
|
69
|
-
* @param {String}
|
|
69
|
+
* @param {String} payee the node's address acting as the escrow payee, i.e. the account being
|
|
70
|
+
* authorized to create locks against the payer's (signer's) escrow funds
|
|
70
71
|
* @param {String} amountToDeposit wanted deposit (human units). When omitted, the funding target
|
|
71
72
|
* defaults to maxLockedAmount; only the shortfall from current escrow funds is deposited.
|
|
72
73
|
* @param {String} maxLockedAmount amount necessary to be paid for starting compute job,
|
|
@@ -91,7 +92,7 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
91
92
|
* existing ceiling) and caps never lower than the existing record's (counts also leave a free slot).
|
|
92
93
|
* @return {Promise<ValidationResponse>} validation response
|
|
93
94
|
*/
|
|
94
|
-
verifyFundsForEscrowPayment(token: string,
|
|
95
|
+
verifyFundsForEscrowPayment(token: string, payee: string, amountToDeposit?: string, maxLockedAmount?: string, maxLockSeconds?: string, maxLockCounts?: string, tokenDecimals?: number, expiryTimestamp?: string): Promise<ValidationResponse>;
|
|
95
96
|
/**
|
|
96
97
|
* Pure helper: merges a required authorization with the prior record (authorize() overwrites in
|
|
97
98
|
* place, keeping currentLocked/currentLocks). Never shrinks the prior ceiling/caps, leaves room
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ComputeEnvironment, ComputeResourceRequest, ServiceCostEstimate } from '../@types/Compute.js';
|
|
2
|
+
/** Assumed `claimDurationTimeout` (seconds) — per-node config that no protocol command exposes. */
|
|
3
|
+
export declare const DEFAULT_CLAIM_DURATION_TIMEOUT_SECONDS = 3600;
|
|
4
|
+
/**
|
|
5
|
+
* Reimplementation of ocean-node's `C2DEngine.calculateResourcesCost` — there is no server-side
|
|
6
|
+
* quote command, so the cost has to be derived client-side:
|
|
7
|
+
* `cost = sum(price(id) * amount * ceil(effectiveDuration / 60))`, with
|
|
8
|
+
* `effectiveDuration = max(duration, floor)` where floor is `env.minJobDuration` for COMPUTE
|
|
9
|
+
* (`jobType` 1) and `env.minServiceDuration` otherwise (SERVICE, the default).
|
|
10
|
+
*
|
|
11
|
+
* `feeToken` is matched case-insensitively but the env's OWN spelling is returned (the node
|
|
12
|
+
* compares with `===`). An unknown resource id is priced 0 (as the node does) and reported in
|
|
13
|
+
* `unpricedResourceIds`. Returns `null` when the env advertises no fee schedule for
|
|
14
|
+
* `(chainId, token)`.
|
|
15
|
+
*
|
|
16
|
+
* Advisory: the node recomputes cost at start and is authoritative.
|
|
17
|
+
*/
|
|
18
|
+
export declare function estimateServiceCost(env: ComputeEnvironment, chainId: number, token: string, resources: ComputeResourceRequest[], durationSeconds: number, jobType?: number | string): ServiceCostEstimate | null;
|
|
19
|
+
/**
|
|
20
|
+
* Human token amount -> raw base units as a decimal STRING (never a JS number). When the value
|
|
21
|
+
* has more fraction digits than the token has decimals, the remainder is rounded UP by one base
|
|
22
|
+
* unit — an estimate that rounds down would under-authorize.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toRawAmount(costHuman: number, decimals: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* `minLockSeconds` for a service of `durationSeconds`. ocean-node's rule is
|
|
27
|
+
* `d + claimDurationTimeout` with a per-node, unexposed timeout (default 3600), so this is a
|
|
28
|
+
* padded lower bound: `d + max(3600, ceil(0.25 * d))`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function serviceMinLockSeconds(durationSeconds: number): number;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { EstimateJobSubsidyParams, JobSubsidyEstimate } from '../@types/SubsidyEstimate.js';
|
|
2
|
+
/**
|
|
3
|
+
* Absolute ceiling on how many candidate providers are examined (image gate + quoting), no matter
|
|
4
|
+
* how many a node advertises or the caller supplies. It is independent of the node-supplied
|
|
5
|
+
* `maxSponsorsPerLock`: a hostile node could otherwise make the client fire thousands of RPC
|
|
6
|
+
* reads. Only the first N candidates (advertised first, then custom) are considered beyond it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_SUBSIDY_CANDIDATES_QUOTED = 25;
|
|
9
|
+
/**
|
|
10
|
+
* Read-only pre-flight: how much subsidy would this job get, per subsidy-provider contract and
|
|
11
|
+
* delivery mode, and how much must the payer hold in escrow?
|
|
12
|
+
*
|
|
13
|
+
* Reads the node's status and compute environments (HTTP or P2P), derives the job cost with
|
|
14
|
+
* `estimateServiceCost`, resolves the candidate subsidy providers, applies the node's image
|
|
15
|
+
* gate, then quotes each provider through `SubsidyView` (v2 `quoteSubsidyModes`, else the v1
|
|
16
|
+
* `quoteSubsidy` as REIMBURSEMENT only). It builds one scenario per delivery mode.
|
|
17
|
+
*
|
|
18
|
+
* Candidate set (additive): `advertised ∪ customSubsidyProviders`, where advertised is
|
|
19
|
+
* `status.subsidyProviders[chainId]`. When the node's `subsidyProviderFilter` is on, a custom
|
|
20
|
+
* address outside the advertised set is dropped as `outside_node_set` (the node would reject the
|
|
21
|
+
* whole request). Pass a scenario's `selected` list as `subsidyProviders` at start: the node
|
|
22
|
+
* treats a non-empty list as a REPLACEMENT of its own set, so it then applies exactly that list.
|
|
23
|
+
* An empty `selected` means no subsidy — pass it verbatim as `subsidyProviders: []` (an explicit
|
|
24
|
+
* opt-out); OMITTING the argument instead makes the node fall back to its own configured providers.
|
|
25
|
+
*
|
|
26
|
+
* A gate that returns `null` (provider does not expose it) is unknown, NOT disqualifying; only
|
|
27
|
+
* an explicit `false` drops a provider. At most `min(escrow maxSponsorsPerLock, 10)` providers
|
|
28
|
+
* are selected per scenario.
|
|
29
|
+
*
|
|
30
|
+
* Untrusted node data: the node status is attacker-controlled when the caller points at an
|
|
31
|
+
* arbitrary node. Only the first {@link MAX_SUBSIDY_CANDIDATES_QUOTED} candidates (advertised
|
|
32
|
+
* first, then custom) are examined, with a warning when more exist. The returned `escrowAddress`
|
|
33
|
+
* is whatever the node advertised: it is verified only when `params.config.escrow` is set (a
|
|
34
|
+
* mismatch throws, fail-closed); otherwise a warning says it is unverified. RE-VERIFY it against
|
|
35
|
+
* your configured escrow before any deposit or authorization. Genuine RPC failures propagate;
|
|
36
|
+
* only "contract does not implement this" is degraded to a per-provider `error` drop.
|
|
37
|
+
*
|
|
38
|
+
* All amounts are human-readable token units. Advisory only: the node recomputes cost and the
|
|
39
|
+
* escrow/subsidy contracts settle subsidy at start. Never signs or sends a transaction.
|
|
40
|
+
*/
|
|
41
|
+
export declare function estimateJobSubsidy(params: EstimateJobSubsidyParams): Promise<JobSubsidyEstimate>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subsidy image gate — ported VERBATIM from ocean-node
|
|
3
|
+
* (`core/utils/subsidyProviders.ts` + `c2d/serviceResourceMatching.ts`). Keep the matching rules
|
|
4
|
+
* identical to the node: this is an exact-string matcher, not an image-reference parser.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The subset of a docker container spec the image gate matches against. A dockerfile-built image
|
|
8
|
+
* is user-built (NOT a trusted operator image), so a non-empty `dockerfile` always makes the gate
|
|
9
|
+
* match nothing — even when `image`/`tag` are also supplied.
|
|
10
|
+
*/
|
|
11
|
+
export interface SubsidyImageContainer {
|
|
12
|
+
image?: string;
|
|
13
|
+
tag?: string;
|
|
14
|
+
checksum?: string;
|
|
15
|
+
dockerfile?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the final Docker image reference from a service start spec.
|
|
19
|
+
* Priority: dockerfile > checksum > tag > default "latest".
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveServiceImage(image: string, tag?: string, checksum?: string, dockerfile?: string, serviceId?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* A docker entrypoint/cmd override is "custom" when it is non-empty. Handles both the service
|
|
24
|
+
* shape (`string[]`) and the compute container shape (`string`); whitespace-only strings count
|
|
25
|
+
* as empty.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isNonEmpty(value: string | string[] | null | undefined): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* True when `entry` (an operator allowlist docker reference) matches `container`.
|
|
30
|
+
*
|
|
31
|
+
* Compared against the SINGLE reference the node would resolve `container` to (dockerfile >
|
|
32
|
+
* checksum > tag): a non-empty `dockerfile` matches NOTHING; else a `checksum` gives
|
|
33
|
+
* `image@checksum` (tag ignored); else `image:${tag ?? 'latest'}`.
|
|
34
|
+
*
|
|
35
|
+
* WILDCARD TAG: an entry `name:*` matches ANY tag or digest of the exact image `name` (the name
|
|
36
|
+
* may contain a registry `host:port`; only the trailing `:*` is special). Case-sensitive.
|
|
37
|
+
*/
|
|
38
|
+
export declare function imageReferenceMatches(container: SubsidyImageContainer | null | undefined, entry: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Apply the per-address image gate (`subsidyProviderAllowedImages`) to an effective subsidy list.
|
|
41
|
+
*
|
|
42
|
+
* - `!allowedImages || zero keys` -> gate OFF; every address kept (`{}` means "no restrictions").
|
|
43
|
+
* - otherwise, per address: NOT a key in the map -> kept; a key -> kept ONLY when the job has
|
|
44
|
+
* no custom entrypoint/cmd AND its image matches one of that address's allowed refs.
|
|
45
|
+
*
|
|
46
|
+
* Map keys are checksum-normalized (and merged) before lookup. Pure: no network.
|
|
47
|
+
*/
|
|
48
|
+
export declare function filterSubsidyByAllowedImages(effective: string[], container: SubsidyImageContainer | null | undefined, hasCustomEntrypoint: boolean, allowedImages: Record<string, string[]> | null | undefined): {
|
|
49
|
+
kept: string[];
|
|
50
|
+
dropped: string[];
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oceanprotocol/lib",
|
|
3
3
|
"source": "./src/index.ts",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.1.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",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"prettier": "^3.9.6",
|
|
126
126
|
"release-it": "^21.0.2",
|
|
127
127
|
"source-map-support": "^0.5.21",
|
|
128
|
-
"tsup": "^
|
|
128
|
+
"tsup": "^9.0.0",
|
|
129
129
|
"tsx": "^4.23.12",
|
|
130
130
|
"typedoc": "^0.28.20",
|
|
131
131
|
"typedoc-plugin-markdown": "^4.12.0",
|