mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
linter fixes
This commit is contained in:
parent
6b3541bbc5
commit
0410793286
@ -1,9 +1,9 @@
|
|||||||
import Config from "../models/Config"
|
import save = require("save-file")
|
||||||
import { File } from "../ddo/MetaData"
|
import { File } from "../ddo/MetaData"
|
||||||
|
import Config from "../models/Config"
|
||||||
import Account from "../ocean/Account"
|
import Account from "../ocean/Account"
|
||||||
|
import Logger from "../utils/Logger"
|
||||||
import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
|
import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
|
||||||
import Logger from '../utils/Logger'
|
|
||||||
const { save } = require('save-file')
|
|
||||||
|
|
||||||
const apiPath = "/api/v1/brizo/services"
|
const apiPath = "/api/v1/brizo/services"
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ export default class Brizo {
|
|||||||
try {
|
try {
|
||||||
await this.downloadFile(
|
await this.downloadFile(
|
||||||
consumeUrl,
|
consumeUrl,
|
||||||
url.split('/').pop() || `file-${i}`,
|
url.split("/").pop() || `file-${i}`,
|
||||||
destination,
|
destination,
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -53,7 +53,6 @@ export class DDO {
|
|||||||
this.service = (ddo && ddo.service) || []
|
this.service = (ddo && ddo.service) || []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public shortId(): string {
|
public shortId(): string {
|
||||||
return this.id.replace("did:op:", "")
|
return this.id.replace("did:op:", "")
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ export default class Ocean {
|
|||||||
Logger.setLevel(
|
Logger.setLevel(
|
||||||
typeof config.verbose !== "number"
|
typeof config.verbose !== "number"
|
||||||
? (config.verbose ? LogLevel.Log : LogLevel.None)
|
? (config.verbose ? LogLevel.Log : LogLevel.None)
|
||||||
: <LogLevel>config.verbose
|
: config.verbose as LogLevel,
|
||||||
)
|
)
|
||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ export default class OceanAccounts {
|
|||||||
try {
|
try {
|
||||||
await account.requestTokens(amount)
|
await account.requestTokens(amount)
|
||||||
return true
|
return true
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import AquariusProvider from "../aquarius/AquariusProvider"
|
import AquariusProvider from "../aquarius/AquariusProvider"
|
||||||
import BrizoProvider from "../brizo/BrizoProvider"
|
import BrizoProvider from "../brizo/BrizoProvider"
|
||||||
import Account from "./Account"
|
|
||||||
import { generateId } from "../utils/GeneratorHelpers"
|
import { generateId } from "../utils/GeneratorHelpers"
|
||||||
|
import Account from "./Account"
|
||||||
import DID from "./DID"
|
import DID from "./DID"
|
||||||
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
||||||
|
|
||||||
|
@ -6,16 +6,16 @@ import { Condition } from "../ddo/Condition"
|
|||||||
import { DDO } from "../ddo/DDO"
|
import { DDO } from "../ddo/DDO"
|
||||||
import { MetaData } from "../ddo/MetaData"
|
import { MetaData } from "../ddo/MetaData"
|
||||||
import { Service, ServiceAuthorization } from "../ddo/Service"
|
import { Service, ServiceAuthorization } from "../ddo/Service"
|
||||||
|
import EventListener from "../keeper/EventListener"
|
||||||
import Keeper from "../keeper/Keeper"
|
import Keeper from "../keeper/Keeper"
|
||||||
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
||||||
|
import Logger from "../utils/Logger"
|
||||||
import Account from "./Account"
|
import Account from "./Account"
|
||||||
import DID from "./DID"
|
import DID from "./DID"
|
||||||
import OceanAgreements from "./OceanAgreements"
|
import OceanAgreements from "./OceanAgreements"
|
||||||
|
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
||||||
import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate"
|
import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate"
|
||||||
import Access from "./ServiceAgreements/Templates/Access"
|
import Access from "./ServiceAgreements/Templates/Access"
|
||||||
import EventListener from "../keeper/EventListener"
|
|
||||||
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
|
||||||
import Logger from '../utils/Logger'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assets submodule of Ocean Protocol.
|
* Assets submodule of Ocean Protocol.
|
||||||
@ -128,7 +128,7 @@ export default class OceanAssets {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "Authorization",
|
type: "Authorization",
|
||||||
services: 'SecretStore',
|
services: "SecretStore",
|
||||||
serviceEndpoint: secretStoreUri,
|
serviceEndpoint: secretStoreUri,
|
||||||
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||||
},
|
},
|
||||||
@ -181,9 +181,10 @@ export default class OceanAssets {
|
|||||||
return storedDdo
|
return storedDdo
|
||||||
}
|
}
|
||||||
|
|
||||||
public async consume (agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account, resultPath: string): Promise<string>
|
// tslint:disable-next-line
|
||||||
public async consume (agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account): Promise<true>
|
public async consume(agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account, resultPath: string): Promise<string>
|
||||||
public async consume (
|
public async consume(agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account): Promise<true>
|
||||||
|
public async consume(
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
did: string,
|
did: string,
|
||||||
serviceDefinitionId: string,
|
serviceDefinitionId: string,
|
||||||
@ -193,9 +194,9 @@ export default class OceanAssets {
|
|||||||
|
|
||||||
const brizo = BrizoProvider.getBrizo()
|
const brizo = BrizoProvider.getBrizo()
|
||||||
const ddo = await this.resolve(did)
|
const ddo = await this.resolve(did)
|
||||||
const {metadata} = ddo.findServiceByType('Metadata')
|
const {metadata} = ddo.findServiceByType("Metadata")
|
||||||
|
|
||||||
const authorizationService = ddo.findServiceByType('Authorization')
|
const authorizationService = ddo.findServiceByType("Authorization")
|
||||||
const accessService = ddo.findServiceById(serviceDefinitionId)
|
const accessService = ddo.findServiceById(serviceDefinitionId)
|
||||||
|
|
||||||
const files = metadata.base.encryptedFiles
|
const files = metadata.base.encryptedFiles
|
||||||
@ -203,7 +204,7 @@ export default class OceanAssets {
|
|||||||
const {serviceEndpoint} = accessService
|
const {serviceEndpoint} = accessService
|
||||||
|
|
||||||
if (!serviceEndpoint) {
|
if (!serviceEndpoint) {
|
||||||
throw new Error('Consume asset failed, service definition is missing the `serviceEndpoint`.')
|
throw new Error("Consume asset failed, service definition is missing the `serviceEndpoint`.")
|
||||||
}
|
}
|
||||||
|
|
||||||
const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint
|
const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint
|
||||||
|
@ -47,7 +47,7 @@ export default class OceanTokens {
|
|||||||
try {
|
try {
|
||||||
await account.requestTokens(amount)
|
await account.requestTokens(amount)
|
||||||
return true
|
return true
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,13 @@ export default class ServiceAgreement extends OceanBase {
|
|||||||
const valueHashes: string[] = ServiceAgreement.createValueHashes(values)
|
const valueHashes: string[] = ServiceAgreement.createValueHashes(values)
|
||||||
const timeoutValues: number[] = ServiceAgreement.getTimeoutValuesFromService(service)
|
const timeoutValues: number[] = ServiceAgreement.getTimeoutValuesFromService(service)
|
||||||
|
|
||||||
const serviceAgreementHashSignature = await ServiceAgreement.createSAHashSignature(service, serviceAgreementId, valueHashes, timeoutValues, consumer)
|
const serviceAgreementHashSignature = await ServiceAgreement.createSAHashSignature(
|
||||||
|
service,
|
||||||
|
serviceAgreementId,
|
||||||
|
valueHashes,
|
||||||
|
timeoutValues,
|
||||||
|
consumer,
|
||||||
|
)
|
||||||
|
|
||||||
Logger.log("SA hash signature:", serviceAgreementHashSignature)
|
Logger.log("SA hash signature:", serviceAgreementHashSignature)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ export default class SecretStoreProvider {
|
|||||||
config = {...config}
|
config = {...config}
|
||||||
// Cleaning undefined parameters
|
// Cleaning undefined parameters
|
||||||
Object.keys(config)
|
Object.keys(config)
|
||||||
.forEach(key => config[key] || delete config[key])
|
.forEach((key) => config[key] || delete config[key])
|
||||||
|
|
||||||
if (!Object.keys(config).length) {
|
if (!Object.keys(config).length) {
|
||||||
if (!SecretStoreProvider.secretStore) {
|
if (!SecretStoreProvider.secretStore) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import {v4} from "uuid"
|
import {v4} from "uuid"
|
||||||
|
|
||||||
export function generateId(length = 64) {
|
export function generateId(length = 64) {
|
||||||
let id = ''
|
let id = ""
|
||||||
while(id.length < length) {
|
while (id.length < length) {
|
||||||
id += v4().replace(/-/g, "")
|
id += v4().replace(/-/g, "")
|
||||||
}
|
}
|
||||||
return id.substr(0, length)
|
return id.substr(0, length)
|
||||||
|
@ -7,7 +7,6 @@ export enum LogLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class Logger {
|
export default class Logger {
|
||||||
private static logLevel: LogLevel = LogLevel.Verbose
|
|
||||||
|
|
||||||
public static setLevel(level: LogLevel) {
|
public static setLevel(level: LogLevel) {
|
||||||
this.logLevel = level
|
this.logLevel = level
|
||||||
@ -28,6 +27,7 @@ export default class Logger {
|
|||||||
public static error(...args: any[]) {
|
public static error(...args: any[]) {
|
||||||
Logger.dispatch("error", LogLevel.Error, ...args)
|
Logger.dispatch("error", LogLevel.Error, ...args)
|
||||||
}
|
}
|
||||||
|
private static logLevel: LogLevel = LogLevel.Verbose
|
||||||
|
|
||||||
private static dispatch(verb: string, level: LogLevel, ...args: any[]) {
|
private static dispatch(verb: string, level: LogLevel, ...args: any[]) {
|
||||||
if (this.logLevel >= level) {
|
if (this.logLevel >= level) {
|
||||||
|
@ -2,8 +2,8 @@ import {assert} from "chai"
|
|||||||
import ConfigProvider from "../../src/ConfigProvider"
|
import ConfigProvider from "../../src/ConfigProvider"
|
||||||
import DIDRegistry from "../../src/keeper/contracts/DIDRegistry"
|
import DIDRegistry from "../../src/keeper/contracts/DIDRegistry"
|
||||||
import Account from "../../src/ocean/Account"
|
import Account from "../../src/ocean/Account"
|
||||||
import { generateId } from "../../src/utils/GeneratorHelpers"
|
|
||||||
import Ocean from "../../src/ocean/Ocean"
|
import Ocean from "../../src/ocean/Ocean"
|
||||||
|
import { generateId } from "../../src/utils/GeneratorHelpers"
|
||||||
import Logger from "../../src/utils/Logger"
|
import Logger from "../../src/utils/Logger"
|
||||||
import config from "../config"
|
import config from "../config"
|
||||||
import TestContractHandler from "./TestContractHandler"
|
import TestContractHandler from "./TestContractHandler"
|
||||||
|
@ -20,9 +20,9 @@ describe("OceanAccounts", () => {
|
|||||||
|
|
||||||
describe("#getInstance()", () => {
|
describe("#getInstance()", () => {
|
||||||
it("should get an instance of OceanAccounts", async () => {
|
it("should get an instance of OceanAccounts", async () => {
|
||||||
const oceanAccounts: OceanAccounts = await OceanAccounts.getInstance()
|
const oceanAccountsInstance: OceanAccounts = await OceanAccounts.getInstance()
|
||||||
|
|
||||||
assert.instanceOf(oceanAccounts, OceanAccounts, "No returned OceanAccounts instance")
|
assert.instanceOf(oceanAccountsInstance, OceanAccounts, "No returned OceanAccounts instance")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -30,14 +30,14 @@ describe("OceanAccounts", () => {
|
|||||||
it("should return the list of accounts", async () => {
|
it("should return the list of accounts", async () => {
|
||||||
const accounts = await oceanAccounts.list()
|
const accounts = await oceanAccounts.list()
|
||||||
|
|
||||||
accounts.map(account => assert.instanceOf(account, Account))
|
accounts.map((account) => assert.instanceOf(account, Account))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#balance()", () => {
|
describe("#balance()", () => {
|
||||||
it("should return the balance of an account", async () => {
|
it("should return the balance of an account", async () => {
|
||||||
const [account] = await oceanAccounts.list()
|
const [account] = await oceanAccounts.list()
|
||||||
spy.on(account, 'getBalance', () => ({eth: 1, ocn: 5}))
|
spy.on(account, "getBalance", () => ({eth: 1, ocn: 5}))
|
||||||
const balance = await oceanAccounts.balance(account)
|
const balance = await oceanAccounts.balance(account)
|
||||||
|
|
||||||
assert.deepEqual(balance, {eth: 1, ocn: 5})
|
assert.deepEqual(balance, {eth: 1, ocn: 5})
|
||||||
@ -47,7 +47,7 @@ describe("OceanAccounts", () => {
|
|||||||
describe("#requestTokens()", () => {
|
describe("#requestTokens()", () => {
|
||||||
it("should return the balance of an account", async () => {
|
it("should return the balance of an account", async () => {
|
||||||
const [account] = await oceanAccounts.list()
|
const [account] = await oceanAccounts.list()
|
||||||
spy.on(account, 'requestTokens', () => 10)
|
spy.on(account, "requestTokens", () => 10)
|
||||||
const success = await oceanAccounts.requestTokens(account, 10)
|
const success = await oceanAccounts.requestTokens(account, 10)
|
||||||
|
|
||||||
assert.isTrue(success)
|
assert.isTrue(success)
|
||||||
|
@ -31,9 +31,9 @@ describe("OceanSecretStore", () => {
|
|||||||
|
|
||||||
describe("#getInstance()", () => {
|
describe("#getInstance()", () => {
|
||||||
it("should get an instance of OceanSecretStore", async () => {
|
it("should get an instance of OceanSecretStore", async () => {
|
||||||
const oceanSecretStore: OceanSecretStore = await OceanSecretStore.getInstance()
|
const oceanSecretStoreInstance: OceanSecretStore = await OceanSecretStore.getInstance()
|
||||||
|
|
||||||
assert.instanceOf(oceanSecretStore, OceanSecretStore, "No returned OceanSecretStore instance")
|
assert.instanceOf(oceanSecretStoreInstance, OceanSecretStore, "No returned OceanSecretStore instance")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -5,11 +5,11 @@ import { DDO } from "../../src/ddo/DDO"
|
|||||||
import { Service } from "../../src/ddo/Service"
|
import { Service } from "../../src/ddo/Service"
|
||||||
import Account from "../../src/ocean/Account"
|
import Account from "../../src/ocean/Account"
|
||||||
import DID from "../../src/ocean/DID"
|
import DID from "../../src/ocean/DID"
|
||||||
import { generateId } from "../../src/utils/GeneratorHelpers"
|
|
||||||
import Ocean from "../../src/ocean/Ocean"
|
import Ocean from "../../src/ocean/Ocean"
|
||||||
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
|
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
|
||||||
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
||||||
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
||||||
|
import { generateId } from "../../src/utils/GeneratorHelpers"
|
||||||
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
|
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
|
||||||
import config from "../config"
|
import config from "../config"
|
||||||
import TestContractHandler from "../keeper/TestContractHandler"
|
import TestContractHandler from "../keeper/TestContractHandler"
|
||||||
@ -164,7 +164,7 @@ describe("ServiceAgreement", () => {
|
|||||||
try {
|
try {
|
||||||
// Allowing 1 more retry
|
// Allowing 1 more retry
|
||||||
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
|
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
|
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user