Skip to content

Commit

Permalink
Pull from origin main
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehewitt15 committed Apr 13, 2021
2 parents bab7b46 + 66f3d66 commit ea22d15
Show file tree
Hide file tree
Showing 14 changed files with 11,815 additions and 22,048 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ before_script:
- git clone https://github.com/oceanprotocol/barge
- cd barge
- export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
- export AQUARIUS_VERSION=v2.2.5
- mkdir "${HOME}/.ocean/"
- mkdir "${HOME}/.ocean/ocean-contracts/"
- mkdir "${HOME}/.ocean/ocean-contracts/artifacts"
Expand Down
1,472 changes: 755 additions & 717 deletions CHANGELOG.md

Large diffs are not rendered by default.

31,965 changes: 10,690 additions & 21,275 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "@oceanprotocol/lib",
"version": "0.12.0",
"source": "./src/index.ts",
"version": "0.12.2",
"description": "JavaScript client library for Ocean Protocol",
"main": "./dist/node/lib.js",
"exports": "./dist/lib.modern.js",
"module": "dist/lib.module.js",
"typings": "./dist/node/lib.d.ts",
"umd:main": "dist/lib.umd.js",
"unpkg": "./dist/browser/lib.cjs2.min.js",
"scripts": {
"start": "npm run clean && npm run build:metadata && tsc -w",
"build": "npm run clean && npm run build:metadata && npm run build:tsc",
"build": "npm run clean && npm run build:metadata && microbundle build --format umd,cjs,es --compress --target node --tsconfig tsconfig.json",
"build:tsc": "tsc --sourceMap",
"build:metadata": "./scripts/get-metadata.js > src/metadata.json",
"clean": "rm -rf ./dist/ ./doc/ ./.nyc_output",
Expand Down Expand Up @@ -38,17 +42,18 @@
},
"homepage": "https://github.com/oceanprotocol/ocean.js#readme",
"peerDependencies": {
"web3": "^1.2.3"
"web3": "^1.3.4"
},
"dependencies": {
"@ethereum-navigator/navigator": "^0.5.2",
"@oceanprotocol/contracts": "^0.5.10",
"@types/crypto-js": "^4.0.1",
"cross-fetch": "^3.1.2",
"crypto-js": "^4.0.0",
"decimal.js": "^10.2.1",
"fs": "0.0.1-security",
"lzma": "^2.3.2",
"node-fetch": "^2.6.1",
"node-abort-controller": "^1.2.0",
"save-file": "^2.3.1",
"uuid": "^8.3.2",
"web3": "^1.3.4",
Expand All @@ -60,8 +65,8 @@
"@types/chai": "^4.2.11",
"@types/chai-spies": "^1.0.1",
"@types/mocha": "^8.0.3",
"@types/node": "^14.14.20",
"@types/node-fetch": "^2.5.5",
"@types/node": "^14.14.35",
"@types/node-fetch": "^2.5.8",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"auto-changelog": "^2.2.1",
Expand All @@ -73,6 +78,7 @@
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-prettier": "^3.3.1",
"lcov-result-merger": "^3.1.0",
"microbundle": "^0.13.0",
"mocha": "^8.2.1",
"mock-local-storage": "^1.1.15",
"nyc": "^15.1.0",
Expand Down
2 changes: 2 additions & 0 deletions src/ddo/interfaces/BestPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export interface BestPrice {
isConsumable?: 'true' | 'false' | ''
ocean?: number
datatoken?: number
// eslint-disable-next-line camelcase
exchange_id?: string
pools: string[]
}
15 changes: 12 additions & 3 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import Config from './models/Config'
import Account from './ocean/Account'
import DID from './ocean/DID'
import { Ocean } from './ocean/Ocean'
import { LoggerInstance as Logger } from './utils/Logger'
import { LoggerInstance as Logger, LogLevel } from './utils/Logger'
import { MetadataCache } from './metadatacache/MetadataCache'
import { DataTokens } from './datatokens/Datatokens'
import { ConfigHelper } from './utils/ConfigHelper'
import {
ConfigHelper,
ConfigHelperConfig,
ConfigHelperNetworkId,
ConfigHelperNetworkName
} from './utils/ConfigHelper'

import * as utils from './utils'

Expand All @@ -27,8 +32,12 @@ export {
Config,
DID,
Logger,
LogLevel,
MetadataCache,
DataTokens,
utils,
ConfigHelper
ConfigHelper,
ConfigHelperConfig,
ConfigHelperNetworkId,
ConfigHelperNetworkName
}
2 changes: 1 addition & 1 deletion src/metadatacache/MetadataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class MetadataCache {
.postWithOctet(fullUrl, ddo)
.then((response: Response) => {
if (response.ok) {
return response.buffer()
return response.blob()
}
this.logger.error('encryptDDO failed:', response.status, response.statusText, ddo)
return null
Expand Down
28 changes: 15 additions & 13 deletions src/metadatacache/OnChainMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MetadataCache } from '../metadatacache/MetadataCache'
// Using limited, compress-only version
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
import { LZMA } from 'lzma/src/lzma-c'
import { Response } from 'node-fetch'

export interface rawMetadata {
flags: number
Expand Down Expand Up @@ -74,12 +75,7 @@ export class OnChainMetadata {
encrypt: boolean = false
): Promise<TransactionReceipt> {
const rawData = await this.prepareRawData(ddo, encrypt)
return this.publishRaw(
didZeroX(did),
rawData.flags,
this.getHex(rawData.data),
consumerAccount
)
return this.publishRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
}

/**
Expand All @@ -96,12 +92,7 @@ export class OnChainMetadata {
encrypt: boolean = false
): Promise<TransactionReceipt> {
const rawData = await this.prepareRawData(ddo, encrypt)
return this.updateRaw(
didZeroX(did),
rawData.flags,
this.getHex(rawData.data),
consumerAccount
)
return this.updateRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
}

/**
Expand All @@ -116,8 +107,19 @@ export class OnChainMetadata {
if (encrypt === false) {
data = await this.compressDDO(data)
flags = flags | 1
data = this.getHex(data)
} else {
data = await this.metadataCache.encryptDDO(data)
const blob = await this.metadataCache.encryptDDO(data)
try {
const rawBuffer = (await new Response(blob).arrayBuffer()) as any
data =
'0x' +
Array.prototype.map
.call(new Uint8Array(rawBuffer), (x) => ('00' + x.toString(16)).slice(-2))
.join('')
} catch (e) {
console.error(e)
}
if (!data) return null
flags = flags | 2
}
Expand Down
22 changes: 10 additions & 12 deletions src/ocean/utils/WebServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { BodyInit, RequestInit, Response } from 'node-fetch'
import { Response } from 'node-fetch'
import fs from 'fs'
import { Logger } from '../../utils'
import save from 'save-file'
// import { createWriteStream } from 'streamsaver'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const fetch = require('node-fetch')
import timeoutSignal from '../../utils/Timeout'
const fetch = require('cross-fetch')

/**
* Provides a common interface to web services.
Expand Down Expand Up @@ -40,12 +38,12 @@ export class WebServiceConnector {
method: 'POST',
body: payload,
headers,
timeout: 5000
signal: timeoutSignal(5000)
})
} else {
return this.fetch(url, {
method: 'POST',
timeout: 5000
signal: timeoutSignal(5000)
})
}
}
Expand All @@ -56,7 +54,7 @@ export class WebServiceConnector {
headers: {
'Content-type': 'application/json'
},
timeout: 5000
signal: timeoutSignal(5000)
})
}

Expand All @@ -68,15 +66,15 @@ export class WebServiceConnector {
headers: {
'Content-type': 'application/json'
},
timeout: 5000
signal: timeoutSignal(5000)
})
} else {
return this.fetch(url, {
method: 'PUT',
headers: {
'Content-type': 'application/json'
},
timeout: 5000
signal: timeoutSignal(5000)
})
}
}
Expand All @@ -89,15 +87,15 @@ export class WebServiceConnector {
headers: {
'Content-type': 'application/json'
},
timeout: 5000
signal: timeoutSignal(5000)
})
} else {
return this.fetch(url, {
method: 'DELETE',
headers: {
'Content-type': 'application/json'
},
timeout: 5000
signal: timeoutSignal(5000)
})
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/provider/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import { ComputeInput } from '../ocean/interfaces/ComputeInput'
import { Output } from '../ocean/interfaces/ComputeOutput'
import { MetadataAlgorithm } from '../ddo/interfaces/MetadataAlgorithm'
import { Versions } from '../ocean/Versions'
import { Response } from 'node-fetch'
import { DDO } from '../ddo/DDO'
import DID from '../ocean/DID'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const fetch = require('node-fetch')

export interface ServiceEndpoint {
serviceName: string
method: string
Expand Down
17 changes: 17 additions & 0 deletions src/utils/Timeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import AbortController from 'node-abort-controller'

export default function timeoutSignal(timeout: number) {
if (!Number.isInteger(timeout)) {
throw new TypeError(`Expected an integer, got ${typeof timeout}`)
}
const signalMap = new WeakMap()
const controller = new AbortController()

const timeoutId = setTimeout(() => {
controller.abort()
}, timeout)

signalMap.set(controller.signal, timeoutId)
// any is needed due to some type incompatibility
return controller.signal as any
}
Loading

0 comments on commit ea22d15

Please sign in to comment.