1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

add provider types

This commit is contained in:
alexcos20 2022-01-03 23:30:23 -08:00
parent f23e65f61b
commit ecc9988972
3 changed files with 25 additions and 5 deletions

16
src/@types/Provider.ts Normal file
View File

@ -0,0 +1,16 @@
export interface ProviderFees {
providerFeeAddress: string
providerFeeToken: string
providerFeeAmount: string
providerData: string
v: string
r: string
s: string
}
export interface ProviderInitialize {
dataToken: string
nonce: string
computeAddress: string
providerFee: ProviderFees
}

View File

@ -5,3 +5,4 @@ export * from './DDO/Credentials'
export * from './DDO/Metadata'
export * from './FileMetadata'
export * from './Compute'
export * from './Provider'

View File

@ -5,7 +5,8 @@ import {
FileMetadata,
ComputeJob,
ComputeOutput,
ComputeAlgorithm
ComputeAlgorithm,
ProviderInitialize
} from '../@types/'
import { noZeroX } from '../utils/ConversionTypeHelper'
import { signText, signWithHash } from '../utils/SignatureUtils'
@ -131,7 +132,9 @@ export class Provider {
if (!path) return null
try {
const response = await postMethod(path, decodeURI(JSON.stringify(data)))
const response = await postMethod(path, decodeURI(JSON.stringify(data)), {
'Content-Type': 'application/octet-stream'
})
return response
} catch (e) {
LoggerInstance.error(e)
@ -217,7 +220,7 @@ export class Provider {
* @param {UserCustomParameters} userCustomParameters
* @param {string} providerUri Identifier of the asset to be registered in ocean
* @param {string} fetchMethod fetch client instance
* @return {Promise<FileMetadata[]>} urlDetails
* @return {Promise<ProviderInitialize>} ProviderInitialize data
*/
public async initialize(
asset: Asset,
@ -227,7 +230,7 @@ export class Provider {
providerUri: string,
getMethod: any,
userCustomParameters?: UserCustomParameters
): Promise<string> {
): Promise<ProviderInitialize> {
const providerEndpoints = await this.getEndpoints(providerUri)
const serviceEndpoints = await this.getServiceEndpoints(
providerUri,
@ -247,7 +250,7 @@ export class Provider {
initializeUrl += '&userdata=' + encodeURI(JSON.stringify(userCustomParameters))
try {
const response = await getMethod(initializeUrl)
return await response
return (await response.json()) as ProviderInitialize
} catch (e) {
LoggerInstance.error(e)
throw new Error('Asset URL not found or not available.')