diff --git a/src/ocean/Compute.ts b/src/ocean/Compute.ts index 204044b5..d3d7f54c 100644 --- a/src/ocean/Compute.ts +++ b/src/ocean/Compute.ts @@ -140,6 +140,7 @@ export class Compute extends Instantiable { additionalInputs ) if (computeJobsList) return computeJobsList[0] as ComputeJob + else return null } return null } @@ -162,7 +163,8 @@ export class Compute extends Instantiable { const provider = await Provider.getInstance(this.instanceConfig) await provider.setBaseUrl(serviceEndpoint) const computeJobsList = await provider.computeStop(did, consumerAccount, jobId) - return computeJobsList[0] as ComputeJob + if (computeJobsList) return computeJobsList[0] as ComputeJob + return null } /** @@ -183,7 +185,8 @@ export class Compute extends Instantiable { const provider = await Provider.getInstance(this.instanceConfig) await provider.setBaseUrl(serviceEndpoint) const computeJobsList = await provider.computeDelete(did, consumerAccount, jobId) - return computeJobsList[0] as ComputeJob + if (computeJobsList) return computeJobsList[0] as ComputeJob + return null } /** @@ -220,7 +223,6 @@ export class Compute extends Instantiable { txId, sign ) - return computeJobsList as ComputeJob[] } diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index a10a5664..632998b4 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -115,9 +115,11 @@ export class Provider extends Instantiable { document: JSON.stringify(document), publisherAddress: account.getId() } + const path = this.getEncryptEndpoint() ? this.getEncryptEndpoint().urlPath : null + if (!path) return null try { const response = await this.ocean.utils.fetch.post( - this.getEncryptEndpoint().urlPath, + path, decodeURI(JSON.stringify(args)) ) return (await response.json()).encryptedDocument @@ -137,11 +139,10 @@ export class Provider extends Instantiable { if (url instanceof DID) { args = { did: url.getDid() } } else args = { url } + const path = this.getFileinfoEndpoint() ? this.getFileinfoEndpoint().urlPath : null + if (!path) return null try { - const response = await this.ocean.utils.fetch.post( - this.getFileinfoEndpoint().urlPath, - JSON.stringify(args) - ) + const response = await this.ocean.utils.fetch.post(path, JSON.stringify(args)) const results: File[] = await response.json() for (const result of results) { files.push(result) @@ -157,10 +158,12 @@ export class Provider extends Instantiable { * @return {Promise} string */ public async getNonce(consumerAddress: string): Promise { - let initializeUrl = this.getNonceEndpoint().urlPath - initializeUrl += `?userAddress=${consumerAddress}` + const path = this.getNonceEndpoint() ? this.getNonceEndpoint().urlPath : null + if (!path) return null try { - const response = await this.ocean.utils.fetch.get(initializeUrl) + const response = await this.ocean.utils.fetch.get( + path + `?userAddress=${consumerAddress}` + ) this.nonce = String((await response.json()).nonce) return this.nonce } catch (e) { @@ -183,8 +186,10 @@ export class Provider extends Instantiable { this.logger.error(e) throw new Error('Failed to resolve DID') } - - let initializeUrl = this.getInitializeEndpoint().urlPath + let initializeUrl = this.getInitializeEndpoint() + ? this.getInitializeEndpoint().urlPath + : null + if (!initializeUrl) return null initializeUrl += `?documentId=${did}` initializeUrl += `&serviceId=${serviceIndex}` initializeUrl += `&serviceType=${serviceType}` @@ -212,10 +217,12 @@ export class Provider extends Instantiable { ): Promise { await this.getNonce(account.getId()) const signature = await this.createSignature(account, did + this.nonce) + const path = this.getDownloadEndpoint() ? this.getDownloadEndpoint().urlPath : null + if (!path) return null const filesPromises = files .filter((_, i) => index === -1 || i === index) .map(async ({ index: i }) => { - let consumeUrl = this.getDownloadEndpoint().urlPath + let consumeUrl = path consumeUrl += `?fileIndex=${i}` consumeUrl += `&documentId=${did}` consumeUrl += `&serviceId=${serviceIndex}` @@ -282,10 +289,11 @@ export class Provider extends Instantiable { if (tokenAddress) payload.dataToken = tokenAddress if (additionalInputs) payload.additionalInputs = additionalInputs + const path = this.getComputeStartEndpoint() + ? this.getComputeStartEndpoint().urlPath + : null + if (!path) return null try { - let path = null - if (this.getComputeStartEndpoint().urlPath) - path = this.getComputeStartEndpoint().urlPath const response = await this.ocean.utils.fetch.post(path, JSON.stringify(payload)) if (response?.ok) { const params = await response.json() @@ -321,10 +329,11 @@ export class Provider extends Instantiable { payload.signature = signature payload.jobId = jobId payload.consumerAddress = address + const path = this.getComputeStopEndpoint() + ? this.getComputeStopEndpoint().urlPath + : null + if (!path) return null try { - let path = null - if (this.getComputeStopEndpoint().urlPath) - path = this.getComputeStopEndpoint().urlPath const response = await this.ocean.utils.fetch.put(path, JSON.stringify(payload)) if (response?.ok) { const params = await response.json() @@ -360,10 +369,11 @@ export class Provider extends Instantiable { payload.signature = signature payload.jobId = jobId payload.consumerAddress = address + const path = this.getComputeDeleteEndpoint() + ? this.getComputeDeleteEndpoint().urlPath + : null + if (!path) return null try { - let path = null - if (this.getComputeDeleteEndpoint().urlPath) - path = this.getComputeDeleteEndpoint().urlPath const response = await this.ocean.utils.fetch.delete(path, JSON.stringify(payload)) if (response?.ok) { const params = await response.json() @@ -407,11 +417,11 @@ export class Provider extends Instantiable { url += (jobId && `&jobId=${jobId}`) || '' url += `&consumerAddress=${address}` url += (txId && `&transferTxId=${txId}`) || '' - + const path = this.getComputeStatusEndpoint() + ? this.getComputeStatusEndpoint().urlPath + : null + if (!path) return null try { - let path = null - if (this.getComputeStatusEndpoint().urlPath) - path = this.getComputeStatusEndpoint().urlPath const response = await this.ocean.utils.fetch.get(path + url) /* response = await fetch(this.getComputeEndpoint() + url, { method: 'GET',