diff --git a/package-lock.json b/package-lock.json index 3426c0b031..c018767aa9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2090,6 +2090,12 @@ "@types/node": ">= 8" } }, + "@openapitools/openapi-generator-cli": { + "version": "1.0.10-4.2.3", + "resolved": "https://registry.npmjs.org/@openapitools/openapi-generator-cli/-/openapi-generator-cli-1.0.10-4.2.3.tgz", + "integrity": "sha512-Xo4rbz3aPiObpVS8oBUR0pHWYU5WBG/bmsJg16yCG7/vpGE8o1YsROTWMFfaMepWfxESrLP5XOqlBkZqbre7dw==", + "dev": true + }, "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", diff --git a/package.json b/package.json index d488b158e6..6b76c13217 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,14 @@ "scripts": { "configure": "lerna clean --yes && lerna bootstrap && npm run build && node ./tools/generate-api-server-config.js", "start:api-server": "node ./packages/bif-cmd-api-server/dist/lib/main/typescript/cmd/bif-api.js --config-file=.config.json", + "generate-sdk": "openapi-generator generate -i x.json -g typescript-axios -o packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/", "tsc": "lerna exec --stream --ignore '*/*cockpit' -- tsc --project ./tsconfig.json", - "clean": "lerna exec --stream --ignore '*/*cockpit' -- del-cli dist/**", - "build": "npm-run-all --parallel build:frontend build:backend", + "clean": "lerna exec --stream --ignore '*/*cockpit' -- del-cli dist/** && del-cli packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/*", + "build": "npm-run-all build:backend build:frontend", "build:frontend": "lerna exec --stream --scope '*/*cockpit' -- ng build --prod", - "build:backend": "npm-run-all clean tsc webpack", + "build:backend": "npm-run-all lint clean generate-sdk tsc webpack", "build:dev:pkg:cmd-api-server": "lerna exec --stream --scope '*/*api-server' -- 'del-cli dist/** && tsc --project ./tsconfig.json && webpack --env=dev --target=node --config ../../webpack.config.js'", + "build:dev:pkg:sdk": "lerna exec --stream --scope '*/*sdk' -- 'del-cli dist/** && tsc --project ./tsconfig.json && webpack --env=dev --target=node --config ../../webpack.config.js'", "webpack": "npm-run-all webpack:web:dev webpack:node:dev webpack:web:prod webpack:node:prod", "webpack:web:prod": "lerna exec --stream --ignore '*/*{cockpit,server}' -- webpack --env=prod --target=web --config ../../webpack.config.js", "webpack:web:dev": "lerna exec --stream --ignore '*/*{cockpit,server}' -- webpack --env=dev --target=web --config ../../webpack.config.js", @@ -19,7 +21,7 @@ "commit": "git-cz", "setup": "lerna exec --stream --ignore '*/*cockpit' -- rm -rf node_modules package-lock.json", "lint": "lerna exec --stream --ignore '*/*cockpit' -- cross-env DEBUG= tslint --project tsconfig.json", - "pretest": "npm run lint && npm run build", + "pretest": "npm run build", "test": "lerna exec --stream --ignore '*/*cockpit' -- tap --timeout=600 src/test/typescript/unit/", "test-coverage": "lerna exec --stream --ignore '*/*cockpit' -- tap --timeout=600 src/test/typescript/unit/ --cov", "test-coverage-html": "lerna exec --stream --ignore '*/*cockpit' -- tap --timeout=600 src/test/typescript/unit/ --cov --coverage-report=lcov", @@ -29,6 +31,7 @@ "devDependencies": { "@commitlint/cli": "8.1.0", "@commitlint/config-conventional": "8.0.0", + "@openapitools/openapi-generator-cli": "1.0.10-4.2.3", "@types/node-fetch": "2.5.4", "@types/uuid": "3.4.6", "commitizen": "4.0.3", diff --git a/packages/bif-cmd-api-server/src/main/typescript/consortium/routes/create-consortium-endpoint-v1.ts b/packages/bif-cmd-api-server/src/main/typescript/consortium/routes/create-consortium-endpoint-v1.ts index b0ed7c3023..20bbd292cc 100644 --- a/packages/bif-cmd-api-server/src/main/typescript/consortium/routes/create-consortium-endpoint-v1.ts +++ b/packages/bif-cmd-api-server/src/main/typescript/consortium/routes/create-consortium-endpoint-v1.ts @@ -35,24 +35,25 @@ export class CreateConsortiumEndpointV1 { const consortium: IConsortium = req.body; const idAlreadyExists = await this.options.storage.has(consortium.id); if (idAlreadyExists) { - res.json({ success: false, message: `Consortium with ID ${consortium.id} already exists.` }); res.status(400); + res.json({ success: false, message: `Consortium with ID ${consortium.id} already exists.` }); + } else { + // FIXME: We need a library handling the crypto, how about NodeJS bindings for Ursa? + const privateKey = this.options.config.get('privateKey'); + const privateKeyBytes = Uint8Array.from(Buffer.from(privateKey, 'hex')); + const consortiumJson: string = JSON.stringify(consortium); + const consortiumBytesHash = Uint8Array.from(keccak256.array(consortiumJson)); + const signatureWrapper = secp256k1.ecdsaSign(consortiumBytesHash, privateKeyBytes); + const signature = Buffer.from(signatureWrapper.signature).toString('hex'); + const consortiumWrapper: IConsortiumWrapper = { + signature, + consortiumJson, + }; + const wrapperJson = JSON.stringify(consortiumWrapper); + // tslint:disable-next-line: no-console + await this.options.storage.set(consortium.id, wrapperJson); + res.status(201); + res.json({ success: true, consortiumWrapper }); } - // FIXME: We need a library handling the crypto, how about NodeJS bindings for Ursa? - const privateKey = this.options.config.get('privateKey'); - const privateKeyBytes = Uint8Array.from(Buffer.from(privateKey, 'hex')); - const consortiumJson: string = JSON.stringify(consortium); - const consortiumBytesHash = Uint8Array.from(keccak256.array(consortiumJson)); - const signatureWrapper = secp256k1.ecdsaSign(consortiumBytesHash, privateKeyBytes); - const signature = Buffer.from(signatureWrapper.signature).toString('hex'); - const consortiumWrapper: IConsortiumWrapper = { - signature, - consortiumJson, - }; - const wrapperJson = JSON.stringify(consortiumWrapper); - // tslint:disable-next-line: no-console - await this.options.storage.set(consortium.id, wrapperJson); - res.json({ success: true, consortiumWrapper }); - res.status(201); } } diff --git a/packages/bif-cockpit/package.json b/packages/bif-cockpit/package.json index 915978291d..f904dad09a 100644 --- a/packages/bif-cockpit/package.json +++ b/packages/bif-cockpit/package.json @@ -23,6 +23,7 @@ "@angular/router": "8.2.14", "@capacitor/core": "1.5.1", "@hyperledger-labs/bif-common": "0.2.0", + "@hyperledger-labs/bif-sdk": "0.2.0", "@ionic-native/core": "5.0.0", "@ionic-native/splash-screen": "5.0.0", "@ionic-native/status-bar": "5.0.0", diff --git a/packages/bif-cockpit/src/app/app.component.ts b/packages/bif-cockpit/src/app/app.component.ts index 66ac7432f5..a9df6aa742 100644 --- a/packages/bif-cockpit/src/app/app.component.ts +++ b/packages/bif-cockpit/src/app/app.component.ts @@ -5,6 +5,7 @@ import { SplashScreen } from '@ionic-native/splash-screen/ngx'; import { StatusBar } from '@ionic-native/status-bar/ngx'; import { LoggerProvider, Logger } from '@hyperledger-labs/bif-common'; +import { DefaultApi, Configuration } from '@hyperledger-labs/bif-sdk'; @Component({ selector: 'app-root', @@ -72,5 +73,22 @@ export class AppComponent implements OnInit { if (path !== undefined) { this.selectedIndex = this.appPages.findIndex(page => page.title.toLowerCase() === path.toLowerCase()); } + this.testApi(); + } + + async testApi(): Promise { + const BIF_API_HOST = 'http://localhost:4000'; + const configuration = new Configuration({ basePath: BIF_API_HOST,}); + const api = new DefaultApi(configuration); + const response = await api.apiV1ConsortiumPost({ + configurationEndpoint: 'domain-and-an-http-endpoint', + id: 'asdf', + name: 'asdf', + bifNodes: [ + { + host: 'BIF-NODE-HOST-1', publicKey: 'FAKE-PUBLIC-KEY' + } + ] + }); } } diff --git a/packages/bif-sdk/README.md b/packages/bif-sdk/README.md new file mode 100644 index 0000000000..b26270ab95 --- /dev/null +++ b/packages/bif-sdk/README.md @@ -0,0 +1,9 @@ +# `@hyperledger-labs/bif-sdk` + +> TODO: description + +## Usage + +``` +// TODO: DEMONSTRATE API +``` diff --git a/packages/bif-sdk/package-lock.json b/packages/bif-sdk/package-lock.json new file mode 100644 index 0000000000..3deadf98c5 --- /dev/null +++ b/packages/bif-sdk/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "@hyperledger-labs/bif-sdk", + "version": "0.2.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "requires": { + "follow-redirects": "1.5.10" + } + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } +} diff --git a/packages/bif-sdk/package.json b/packages/bif-sdk/package.json new file mode 100644 index 0000000000..88ee716c12 --- /dev/null +++ b/packages/bif-sdk/package.json @@ -0,0 +1,52 @@ +{ + "name": "@hyperledger-labs/bif-sdk", + "version": "0.2.0", + "description": "Universal library used by both front end and back end components of BIF. Aims to be a developer swiss army knife.", + "main": "dist/bif-sdk.node.umd.js", + "mainMinified": "dist/bif-sdk.node.umd.min.js", + "browser": "dist/bif-sdk.web.umd.js", + "browserMinified": "dist/bif-sdk.web.umd.min.js", + "module": "dist/lib/main/typescript/index.js", + "types": "dist/types/main/typescript/index.d.ts", + "files": [ + "dist/*" + ], + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=10", + "npm": ">=6" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/hyperledger-labs/blockchain-integration-framework.git" + }, + "keywords": [ + "Hyperledger", + "Blockchain", + "Interoperability", + "Integration" + ], + "author": { + "name": "Peter Somogyvari", + "email": "peter.somogyvari@accenture.com", + "url": "https://accenture.com" + }, + "contributors": [ + { + "name": "Please add yourself to the list of contributors", + "email": "your.name@example.com", + "url": "https://example.com" + } + ], + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/hyperledger-labs/blockchain-integration-framework/issues" + }, + "homepage": "https://github.com/hyperledger-labs/blockchain-integration-framework#readme", + "dependencies": { + "@hyperledger-labs/bif-common": "0.2.0", + "axios": "0.19.2" + } +} diff --git a/packages/bif-sdk/src/main/typescript/api-client.ts b/packages/bif-sdk/src/main/typescript/api-client.ts new file mode 100644 index 0000000000..49ac7d6c15 --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/api-client.ts @@ -0,0 +1,19 @@ +import { Logger, LoggerProvider } from '@hyperledger-labs/bif-common'; + +export interface IApiClientOptions { + apiHost: string; + apiPort: number; +} + +export class ApiClient { + + private readonly log: Logger; + + constructor(public readonly options: IApiClientOptions) { + this.log = LoggerProvider.getOrCreate({ label: 'api-client ' }); + } + + public async call(): Promise { + this.log.debug(`call()`); + } +} diff --git a/packages/bif-sdk/src/main/typescript/consortium/consortium-service.ts b/packages/bif-sdk/src/main/typescript/consortium/consortium-service.ts new file mode 100644 index 0000000000..15b644c71c --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/consortium/consortium-service.ts @@ -0,0 +1,14 @@ +import { ApiClient } from "../api-client"; + +export interface IConsortiumServiceOptions { + apiClient: ApiClient; +} + +export class ConsortiumService { + constructor(public readonly options: IConsortiumServiceOptions) { + } + + async create(): Promise { + return; + } +} diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.gitignore b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.gitignore new file mode 100644 index 0000000000..149b576547 --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.gitignore @@ -0,0 +1,4 @@ +wwwroot/*.js +node_modules +typings +dist diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator-ignore b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator-ignore new file mode 100644 index 0000000000..7484ee590a --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/VERSION b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/VERSION new file mode 100644 index 0000000000..ec87108d82 --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.2.3 \ No newline at end of file diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/api.ts new file mode 100644 index 0000000000..9e3f6fa9a4 --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -0,0 +1,254 @@ +// tslint:disable +/** + * Hyperledger BIF API + * Interact with a BIF deployment through HTTP. + * + * The version of the OpenAPI document: 0.0.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import * as globalImportUrl from 'url'; +import { Configuration } from './configuration'; +import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +// Some imports not used depending on template conditions +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base'; + +/** + * + * @export + * @interface BifNode + */ +export interface BifNode { + /** + * + * @type {string} + * @memberof BifNode + */ + host: string; + /** + * + * @type {string} + * @memberof BifNode + */ + publicKey?: string; +} +/** + * + * @export + * @interface Consortium + */ +export interface Consortium { + /** + * + * @type {string} + * @memberof Consortium + */ + id: string; + /** + * + * @type {string} + * @memberof Consortium + */ + name: string; + /** + * + * @type {string} + * @memberof Consortium + */ + configurationEndpoint: string; + /** + * + * @type {Array} + * @memberof Consortium + */ + bifNodes?: Array; +} + +/** + * DefaultApi - axios parameter creator + * @export + */ +export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * The metadata of the consortium (minus the sensitive data) + * @summary Retrieves a consortium + * @param {string} consortiumId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ConsortiumConsortiumIdGet(consortiumId: string, options: any = {}): RequestArgs { + // verify required parameter 'consortiumId' is not null or undefined + if (consortiumId === null || consortiumId === undefined) { + throw new RequiredError('consortiumId','Required parameter consortiumId was null or undefined when calling apiV1ConsortiumConsortiumIdGet.'); + } + const localVarPath = `/api/v1/consortium/{consortiumId}` + .replace(`{${"consortiumId"}}`, encodeURIComponent(String(consortiumId))); + const localVarUrlObj = globalImportUrl.parse(localVarPath, true); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarUrlObj.query = {...localVarUrlObj.query, ...localVarQueryParameter, ...options.query}; + // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 + delete localVarUrlObj.search; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...options.headers}; + + return { + url: globalImportUrl.format(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Creates a new consortium from scratch based on the provided parameters. + * @param {Consortium} consortium + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ConsortiumPost(consortium: Consortium, options: any = {}): RequestArgs { + // verify required parameter 'consortium' is not null or undefined + if (consortium === null || consortium === undefined) { + throw new RequiredError('consortium','Required parameter consortium was null or undefined when calling apiV1ConsortiumPost.'); + } + const localVarPath = `/api/v1/consortium`; + const localVarUrlObj = globalImportUrl.parse(localVarPath, true); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + localVarUrlObj.query = {...localVarUrlObj.query, ...localVarQueryParameter, ...options.query}; + // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 + delete localVarUrlObj.search; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...options.headers}; + const needsSerialization = (typeof consortium !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; + localVarRequestOptions.data = needsSerialization ? JSON.stringify(consortium !== undefined ? consortium : {}) : (consortium || ""); + + return { + url: globalImportUrl.format(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * DefaultApi - functional programming interface + * @export + */ +export const DefaultApiFp = function(configuration?: Configuration) { + return { + /** + * The metadata of the consortium (minus the sensitive data) + * @summary Retrieves a consortium + * @param {string} consortiumId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ConsortiumConsortiumIdGet(consortiumId: string, options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise { + const localVarAxiosArgs = DefaultApiAxiosParamCreator(configuration).apiV1ConsortiumConsortiumIdGet(consortiumId, options); + return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; + return axios.request(axiosRequestArgs); + }; + }, + /** + * + * @summary Creates a new consortium from scratch based on the provided parameters. + * @param {Consortium} consortium + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ConsortiumPost(consortium: Consortium, options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise { + const localVarAxiosArgs = DefaultApiAxiosParamCreator(configuration).apiV1ConsortiumPost(consortium, options); + return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; + return axios.request(axiosRequestArgs); + }; + }, + } +}; + +/** + * DefaultApi - factory interface + * @export + */ +export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + return { + /** + * The metadata of the consortium (minus the sensitive data) + * @summary Retrieves a consortium + * @param {string} consortiumId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ConsortiumConsortiumIdGet(consortiumId: string, options?: any): AxiosPromise { + return DefaultApiFp(configuration).apiV1ConsortiumConsortiumIdGet(consortiumId, options)(axios, basePath); + }, + /** + * + * @summary Creates a new consortium from scratch based on the provided parameters. + * @param {Consortium} consortium + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ConsortiumPost(consortium: Consortium, options?: any): AxiosPromise { + return DefaultApiFp(configuration).apiV1ConsortiumPost(consortium, options)(axios, basePath); + }, + }; +}; + +/** + * DefaultApi - object-oriented interface + * @export + * @class DefaultApi + * @extends {BaseAPI} + */ +export class DefaultApi extends BaseAPI { + /** + * The metadata of the consortium (minus the sensitive data) + * @summary Retrieves a consortium + * @param {string} consortiumId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public apiV1ConsortiumConsortiumIdGet(consortiumId: string, options?: any) { + return DefaultApiFp(this.configuration).apiV1ConsortiumConsortiumIdGet(consortiumId, options)(this.axios, this.basePath); + } + + /** + * + * @summary Creates a new consortium from scratch based on the provided parameters. + * @param {Consortium} consortium + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public apiV1ConsortiumPost(consortium: Consortium, options?: any) { + return DefaultApiFp(this.configuration).apiV1ConsortiumPost(consortium, options)(this.axios, this.basePath); + } + +} + + diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/base.ts b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/base.ts new file mode 100644 index 0000000000..9e66589c46 --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/base.ts @@ -0,0 +1,70 @@ +// tslint:disable +/** + * Hyperledger BIF API + * Interact with a BIF deployment through HTTP. + * + * The version of the OpenAPI document: 0.0.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import { Configuration } from "./configuration"; +// Some imports not used depending on template conditions +// @ts-ignore +import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; + +export const BASE_PATH = "https://www.hlbif.win".replace(/\/+$/, ""); + +/** + * + * @export + */ +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +/** + * + * @export + * @interface RequestArgs + */ +export interface RequestArgs { + url: string; + options: any; +} + +/** + * + * @export + * @class BaseAPI + */ +export class BaseAPI { + protected configuration: Configuration | undefined; + + constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { + if (configuration) { + this.configuration = configuration; + this.basePath = configuration.basePath || this.basePath; + } + } +}; + +/** + * + * @export + * @class RequiredError + * @extends {Error} + */ +export class RequiredError extends Error { + name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + } +} diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/configuration.ts b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/configuration.ts new file mode 100644 index 0000000000..05e2079123 --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/configuration.ts @@ -0,0 +1,75 @@ +// tslint:disable +/** + * Hyperledger BIF API + * Interact with a BIF deployment through HTTP. + * + * The version of the OpenAPI document: 0.0.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface ConfigurationParameters { + apiKey?: string | ((name: string) => string); + username?: string; + password?: string; + accessToken?: string | ((name?: string, scopes?: string[]) => string); + basePath?: string; + baseOptions?: any; +} + +export class Configuration { + /** + * parameter for apiKey security + * @param name security name + * @memberof Configuration + */ + apiKey?: string | ((name: string) => string); + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + username?: string; + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + password?: string; + /** + * parameter for oauth2 security + * @param name security name + * @param scopes oauth2 scope + * @memberof Configuration + */ + accessToken?: string | ((name?: string, scopes?: string[]) => string); + /** + * override base path + * + * @type {string} + * @memberof Configuration + */ + basePath?: string; + /** + * base options for axios calls + * + * @type {any} + * @memberof Configuration + */ + baseOptions?: any; + + constructor(param: ConfigurationParameters = {}) { + this.apiKey = param.apiKey; + this.username = param.username; + this.password = param.password; + this.accessToken = param.accessToken; + this.basePath = param.basePath; + this.baseOptions = param.baseOptions; + } +} diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/git_push.sh b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/git_push.sh new file mode 100644 index 0000000000..ced3be2b0c --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/git_push.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/index.ts b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/index.ts new file mode 100644 index 0000000000..015d44e32a --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/generated/openapi/typescript-axios/index.ts @@ -0,0 +1,16 @@ +// tslint:disable +/** + * Hyperledger BIF API + * Interact with a BIF deployment through HTTP. + * + * The version of the OpenAPI document: 0.0.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export * from "./api"; +export * from "./configuration"; diff --git a/packages/bif-sdk/src/main/typescript/index.ts b/packages/bif-sdk/src/main/typescript/index.ts new file mode 100755 index 0000000000..7e1a213e3e --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/index.ts @@ -0,0 +1 @@ +export * from './public-api'; diff --git a/packages/bif-sdk/src/main/typescript/public-api.ts b/packages/bif-sdk/src/main/typescript/public-api.ts new file mode 100755 index 0000000000..2845ab9cb8 --- /dev/null +++ b/packages/bif-sdk/src/main/typescript/public-api.ts @@ -0,0 +1,3 @@ +export { ApiClient } from './api-client'; +export { ConsortiumService } from './consortium/consortium-service'; +export * from './generated/openapi/typescript-axios/index'; diff --git a/packages/bif-sdk/src/test/typescript/integration/api-surface.ts b/packages/bif-sdk/src/test/typescript/integration/api-surface.ts new file mode 100644 index 0000000000..9b61228723 --- /dev/null +++ b/packages/bif-sdk/src/test/typescript/integration/api-surface.ts @@ -0,0 +1,11 @@ +// tslint:disable-next-line: no-var-requires +const tap = require('tap'); +import { ApiClient, ConsortiumService } from '../../../main/typescript/public-api'; + +tap.pass('Test file can be executed'); + +tap.test('Library can be loaded', (assert: any) => { + assert.plan(2); + assert.ok(ApiClient); + assert.ok(ConsortiumService); +}); diff --git a/packages/bif-sdk/src/test/typescript/integration/tap-parallel-not-ok b/packages/bif-sdk/src/test/typescript/integration/tap-parallel-not-ok new file mode 100755 index 0000000000..e69de29bb2 diff --git a/packages/bif-sdk/src/test/typescript/unit/api-surface.ts b/packages/bif-sdk/src/test/typescript/unit/api-surface.ts new file mode 100644 index 0000000000..9b61228723 --- /dev/null +++ b/packages/bif-sdk/src/test/typescript/unit/api-surface.ts @@ -0,0 +1,11 @@ +// tslint:disable-next-line: no-var-requires +const tap = require('tap'); +import { ApiClient, ConsortiumService } from '../../../main/typescript/public-api'; + +tap.pass('Test file can be executed'); + +tap.test('Library can be loaded', (assert: any) => { + assert.plan(2); + assert.ok(ApiClient); + assert.ok(ConsortiumService); +}); diff --git a/packages/bif-sdk/tsconfig.json b/packages/bif-sdk/tsconfig.json new file mode 100644 index 0000000000..d90c929ef9 --- /dev/null +++ b/packages/bif-sdk/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist/lib/", /* Redirect output structure to the directory. */ + "declarationDir": "dist/types", + }, + "include": [ + "./src" + ] +} \ No newline at end of file diff --git a/tslint.json b/tslint.json index 32fa6e5e8d..2be1ce92a4 100644 --- a/tslint.json +++ b/tslint.json @@ -5,5 +5,11 @@ ], "jsRules": {}, "rules": {}, - "rulesDirectory": [] + "rulesDirectory": [], + "linterOptions": { + "exclude": [ + "packages/bif-sdk/src/main/typescript/generated/**/*.ts", + "packages/bif-sdk/src/main/typescript/public-api.ts" + ] + } } \ No newline at end of file diff --git a/x.json b/x.json new file mode 100644 index 0000000000..014e1bee0f --- /dev/null +++ b/x.json @@ -0,0 +1,123 @@ +{ + "openapi": "3.0.3", + "info": { + "title": "Hyperledger BIF API", + "description": "Interact with a BIF deployment through HTTP.", + "version": "0.0.1" + }, + "servers": [ + { + "url": "https://www.hlbif.win/{basePath}", + "description": "Public test instance", + "variables": { + "basePath": { + "default": "" + } + } + }, + { + "url": "http://localhost:4000/{basePath}", + "description": "Local test instance", + "variables": { + "basePath": { + "default": "" + } + } + } + ], + "components": { + "schemas": { + "Consortium": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "configurationEndpoint": { + "type": "string" + }, + "bifNodes": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/components/schemas/BifNode" + } + } + }, + "required": [ + "id", + "name", + "configurationEndpoint" + ] + }, + "BifNode": { + "type": "object", + "properties": { + "host": { + "type": "string" + }, + "publicKey": { + "type": "string" + } + }, + "required": [ + "host", + "publicKeyHex" + ] + } + } + }, + "paths": { + "/api/v1/consortium": { + "post": { + "summary": "Creates a new consortium from scratch based on the provided parameters.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Consortium" + } + } + } + }, + "responses": { + "201": { + "description": "Created" + } + } + } + }, + "/api/v1/consortium/{consortiumId}": { + "get": { + "summary": "Retrieves a consortium", + "description": "The metadata of the consortium (minus the sensitive data)", + "parameters": [ + { + "in": "path", + "name": "consortiumId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Consortium" + } + } + } + } + } + } + } + } +} \ No newline at end of file