From a710fd8c589d65d2a38843c3b27b9cadf4f18484 Mon Sep 17 00:00:00 2001 From: kan Date: Tue, 3 Dec 2024 13:34:19 +0400 Subject: [PATCH] solution: sierra project and org api --- api-definitions | 2 +- packages/core/src/typesSierra.ts | 108 +++++++++++++++--- packages/node/src/EmeraldApi.ts | 28 +++-- .../sierraProject.test.ts | 45 ++++++++ packages/node/src/wrapped/Factory.ts | 11 +- .../node/src/wrapped/SierraProjectClient.ts | 46 ++++++++ packages/web/src/EmeraldApi.ts | 12 +- .../__integration-tests__/sierraOrg.test.ts | 27 +++++ .../sierraProject.test.ts | 48 ++++++++ .../{sierra.test.ts => sierraStat.test.ts} | 8 +- packages/web/src/wrapped/Factory.ts | 19 ++- packages/web/src/wrapped/SierraOrgClient.ts | 28 +++++ .../web/src/wrapped/SierraProjectClient.ts | 37 ++++++ packages/web/src/wrapped/SierraStatClient.ts | 4 +- 14 files changed, 379 insertions(+), 44 deletions(-) create mode 100644 packages/node/src/__integration-tests__/sierraProject.test.ts create mode 100644 packages/node/src/wrapped/SierraProjectClient.ts create mode 100644 packages/web/src/__integration-tests__/sierraOrg.test.ts create mode 100644 packages/web/src/__integration-tests__/sierraProject.test.ts rename packages/web/src/__integration-tests__/{sierra.test.ts => sierraStat.test.ts} (81%) create mode 100644 packages/web/src/wrapped/SierraOrgClient.ts create mode 100644 packages/web/src/wrapped/SierraProjectClient.ts diff --git a/api-definitions b/api-definitions index dd7f501..dc01f5f 160000 --- a/api-definitions +++ b/api-definitions @@ -1 +1 @@ -Subproject commit dd7f501d93a6fca96c9d27743562e613101093fb +Subproject commit dc01f5fc1deca8036baf8c19d7f3915e36d081cf diff --git a/packages/core/src/typesSierra.ts b/packages/core/src/typesSierra.ts index e311294..c4149a7 100644 --- a/packages/core/src/typesSierra.ts +++ b/packages/core/src/typesSierra.ts @@ -1,7 +1,41 @@ -import * as sierra_stat_message_pb from './generated/sierra.stat.message_pb'; +import * as sierra_message_pb from './generated/sierra.message_pb'; import { DataMapper } from './Publisher'; +import { UUID } from "./typesCommon"; import { MessageFactory } from './typesConvert'; +export interface Project { + orgId: UUID; + projectId: UUID; + name: string; + description: string; + createdAt: Date; +} + +export interface Org { + orgId: UUID; + name: UUID; + description: string; + createdAt: Date; +} + +export interface CreateProjectRequest { + orgId: UUID; + name: string; + description: string; +} + +export interface CreateProjectResponse { + projectId: UUID; +} + +export interface ListProjectsRequest { + orgId: UUID; +} + +export interface GetOrgRequest { + orgId: UUID; +} + export enum Granularity { UNSPECIFIED = 0, SECOND = 1, @@ -17,14 +51,15 @@ export enum GroupBy { SERVICE = 1, PROJECT = 2, } + export interface GetRequestCountRequest { - orgId: string; + orgId: UUID; timestampFrom?: Date; timestampTo?: Date; - projectIds?: string[]; + projectIds?: UUID[]; services?: string[]; granularity?: Granularity; - GroupBy?: GroupBy; + groupBy?: GroupBy; } export interface RequestCount { @@ -37,7 +72,7 @@ export interface GroupService { } export interface GroupProjectId { - projectId: string; + projectId: UUID; } export interface GroupRequestCount { @@ -46,12 +81,12 @@ export interface GroupRequestCount { } export interface GetTokenStatRequest { - orgId: string; - tokenIds?: string[]; + orgId: UUID; + tokenIds?: UUID[]; } export interface TokenStat { - tokenId: string; + tokenId: UUID; lastTimestamp: Date; } @@ -62,8 +97,28 @@ export class ConvertSierra { this.factory = factory; } - public getRequestCountRequest(request: GetRequestCountRequest): sierra_stat_message_pb.GetRequestCountRequest { - const result: sierra_stat_message_pb.GetRequestCountRequest = this.factory('sierra_stat_message_pb.GetRequestCountRequest'); + public createProjectRequest(request: CreateProjectRequest): sierra_message_pb.CreateProjectRequest { + const result: sierra_message_pb.CreateProjectRequest = this.factory('sierra_message_pb.CreateProjectRequest'); + result.setOrgId(request.orgId); + result.setName(request.name); + result.setDescription(request.description); + return result; + } + + public listProjectsRequest(request: ListProjectsRequest): sierra_message_pb.ListProjectsRequest { + const result: sierra_message_pb.ListProjectsRequest = this.factory('sierra_message_pb.ListProjectsRequest'); + result.setOrgId(request.orgId); + return result; + } + + public getOrgRequest(request: GetOrgRequest): sierra_message_pb.GetOrgRequest { + const result: sierra_message_pb.GetOrgRequest = this.factory('sierra_message_pb.GetOrgRequest'); + result.setOrgId(request.orgId); + return result; + } + + public getRequestCountRequest(request: GetRequestCountRequest): sierra_message_pb.GetRequestCountRequest { + const result: sierra_message_pb.GetRequestCountRequest = this.factory('sierra_message_pb.GetRequestCountRequest'); result.setOrgId(request.orgId) if (request.timestampFrom) { result.setTimestampFrom(request.timestampFrom.getTime()); @@ -80,20 +135,39 @@ export class ConvertSierra { if (request.granularity) { result.setGranularity(request.granularity.valueOf()) } - if (request.GroupBy) { - result.setGroupBy(request.GroupBy.valueOf()); + if (request.groupBy) { + result.setGroupBy(request.groupBy.valueOf()); } return result; } - public requestCount(): DataMapper { + public project(): DataMapper { + return (response) => ({ + orgId: response.getOrgId(), + projectId: response.getProjectId(), + name: response.getName(), + description: response.getDescription(), + createdAt: new Date(response.getCreatedAt()), + }); + } + + public org(): DataMapper { + return (response) => ({ + orgId: response.getOrgId(), + name: response.getName(), + description: response.getDescription(), + createdAt: new Date(response.getCreatedAt()), + }); + } + + public requestCount(): DataMapper { return (response) => ({ timestamp: new Date(response.getTimestamp()), count: response.getCount(), }); } - public groupRequestCount(): DataMapper { + public groupRequestCount(): DataMapper { return (response) => { let group: GroupService | GroupProjectId; if (response.hasService()) { @@ -112,8 +186,8 @@ export class ConvertSierra { }; } - public getTokenStatRequest(request: GetTokenStatRequest): sierra_stat_message_pb.GetTokenStatRequest { - const result: sierra_stat_message_pb.GetTokenStatRequest = this.factory('sierra_stat_message_pb.GetTokenStatRequest'); + public getTokenStatRequest(request: GetTokenStatRequest): sierra_message_pb.GetTokenStatRequest { + const result: sierra_message_pb.GetTokenStatRequest = this.factory('sierra_message_pb.GetTokenStatRequest'); result.setOrgId(request.orgId); if (request.tokenIds) { result.setTokenIdsList(request.tokenIds); @@ -121,7 +195,7 @@ export class ConvertSierra { return result; } - public tokenStat(): DataMapper { + public tokenStat(): DataMapper { return (response) => { return { tokenId: response.getTokenId(), diff --git a/packages/node/src/EmeraldApi.ts b/packages/node/src/EmeraldApi.ts index 1e8d57a..0ba5ffc 100644 --- a/packages/node/src/EmeraldApi.ts +++ b/packages/node/src/EmeraldApi.ts @@ -1,13 +1,14 @@ -import { ChannelCredentials } from '@grpc/grpc-js'; -import { emeraldCredentials } from './credentials'; -import { AddressClient } from './wrapped/AddressClient'; -import { BlockchainClient } from './wrapped/BlockchainClient'; -import { MarketClient } from './wrapped/MarketClient'; -import { MonitoringClient } from './wrapped/MonitoringClient'; -import { TokenClient } from './wrapped/TokenClient'; -import { TransactionClient } from './wrapped/TransactionClient'; -import {SecretToken} from "@emeraldpay/api/lib/typesAuth"; +import {SecretToken} from "@emeraldpay/api"; +import {ChannelCredentials} from '@grpc/grpc-js'; +import {emeraldCredentials} from './credentials'; +import {AddressClient} from './wrapped/AddressClient'; import {AuthClient} from "./wrapped/Auth"; +import {BlockchainClient} from './wrapped/BlockchainClient'; +import {MarketClient} from './wrapped/MarketClient'; +import {MonitoringClient} from './wrapped/MonitoringClient'; +import {SierraProjectClient} from "./wrapped/SierraProjectClient"; +import {TokenClient} from './wrapped/TokenClient'; +import {TransactionClient} from './wrapped/TransactionClient'; export class EmeraldApi { private readonly agents: string[] = ['test-client/0.0.0']; @@ -22,13 +23,13 @@ export class EmeraldApi { static devApi(token?: SecretToken | undefined, credentials?: ChannelCredentials): EmeraldApi { // a dev token with access only from the internal network - let devToken = token ?? 'emrld_8ntrHbZN67DF8TWKgCMO1I9nSaMG0cpoMhj3GP'; + const devToken = token ?? 'emrld_8ntrHbZN67DF8TWKgCMO1I9nSaMG0cpoMhj3GP'; return new EmeraldApi('api.emeraldpay.dev:443', devToken, credentials); } static localApi(port = 50051, credentials?: ChannelCredentials): EmeraldApi { // just a random token, doesn't exist - let noToken = 'emrld_yKb3jXMKRJLUWFzL7wPrktkherocZCBy7W6qZH'; + const noToken = 'emrld_yKb3jXMKRJLUWFzL7wPrktkherocZCBy7W6qZH'; return new EmeraldApi(`localhost:${port}`, noToken, credentials); } @@ -63,4 +64,9 @@ export class EmeraldApi { auth(): AuthClient { return new AuthClient(this.hostname, this.credentials, this.agents); } + + sierraProject(): SierraProjectClient { + return new SierraProjectClient(this.hostname, this.credentials, this.agents); + } + } diff --git a/packages/node/src/__integration-tests__/sierraProject.test.ts b/packages/node/src/__integration-tests__/sierraProject.test.ts new file mode 100644 index 0000000..336f677 --- /dev/null +++ b/packages/node/src/__integration-tests__/sierraProject.test.ts @@ -0,0 +1,45 @@ +import {EmeraldApi} from "../EmeraldApi"; + +jest.setTimeout(35000); + +describe("SierraProjectClient", () => { + let api: EmeraldApi; + + beforeAll(() => { + // a dev token with user id: bada55a1-0000-4000-a000-000000000000 + api = EmeraldApi.devApi("emrld_fU88aIafXsCClerhyWtflBp1hH6h112ckzpSfP"); + }); + + test('createProject permission denied for the user', async () => { + const client = api.sierraProject(); + + try { + await client.createProject({ + orgId: "cafe0000-0000-4000-a000-000000000000", + name: "Test Project", + description: "Project for using in tests", + }) + } catch (e) { + console.log("createProject error: ", e) + expect(e.code).toEqual(7); // 7: PERMISSION_DENIED + } + }); + + test('listProjects', (done) => { + const client = api.sierraProject(); + + const call = client.listProjects({ + orgId: "cafe0000-0000-4000-a000-000000000000", + }) + call + .onData((data) => { + console.log("listProjects", data); + done(); + }) + .onError((error) => { + console.log("cancel: ", error.message); + done(error); + }) + }); + +}); \ No newline at end of file diff --git a/packages/node/src/wrapped/Factory.ts b/packages/node/src/wrapped/Factory.ts index a4f735c..4c7e387 100644 --- a/packages/node/src/wrapped/Factory.ts +++ b/packages/node/src/wrapped/Factory.ts @@ -1,11 +1,12 @@ -import { MessageFactory } from '@emeraldpay/api'; +import {MessageFactory} from '@emeraldpay/api'; import * as address_message_pb from '../generated/address.message_pb'; +import * as auth_message_pb from '../generated/auth_pb'; import * as blockchain_pb from '../generated/blockchain_pb'; import * as common_pb from '../generated/common_pb'; import * as market_pb from '../generated/market_pb'; +import * as sierra_message_pb from "../generated/sierra.message_pb"; import * as token_message_pb from '../generated/token.message_pb'; import * as transaction_message_pb from '../generated/transaction.message_pb'; -import * as auth_message_pb from '../generated/auth_pb'; export const classFactory: MessageFactory = (id: string) => { switch (id) { @@ -70,6 +71,12 @@ export const classFactory: MessageFactory = (id: string) => { return new transaction_message_pb.GetTransactionsRequest(); case 'transaction_message_pb.SubscribeTransactionsRequest': return new transaction_message_pb.SubscribeTransactionsRequest(); + // Sierra + case 'sierra_message_pb.CreateProjectRequest': + return new sierra_message_pb.CreateProjectRequest(); + case 'sierra_message_pb.ListProjectsRequest': + return new sierra_message_pb.ListProjectsRequest(); + default: throw Error(`Unsupported type: ${id}`); } diff --git a/packages/node/src/wrapped/SierraProjectClient.ts b/packages/node/src/wrapped/SierraProjectClient.ts new file mode 100644 index 0000000..1c8b96a --- /dev/null +++ b/packages/node/src/wrapped/SierraProjectClient.ts @@ -0,0 +1,46 @@ +import {ConnectionListener, Publisher, publishToPromise, readOnce, sierra,} from '@emeraldpay/api'; +import {ChannelCredentials} from '@grpc/grpc-js'; +import {NativeChannel, callSingle, callStream} from '../channel'; +import {ProjectClient} from '../generated/sierra_grpc_pb'; +import {classFactory} from './Factory'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { version: clientVersion } = require('../../package.json'); + +export class SierraProjectClient { + readonly client: ProjectClient; + readonly channel: NativeChannel; + readonly credentials: ChannelCredentials; + readonly retries: number; + + private readonly convert: sierra.ConvertSierra = new sierra.ConvertSierra(classFactory); + + constructor(address: string, credentials: ChannelCredentials, agents: string[], retries = 3) { + const agent = [...agents, `emerald-client-node/${clientVersion}`].join(' '); + + this.client = new ProjectClient(address, credentials, { 'grpc.primary_user_agent': agent }); + this.channel = new NativeChannel(this.client); + this.credentials = credentials; + this.retries = retries; + } + + public setConnectionListener(listener: ConnectionListener): void { + this.channel.setListener(listener); + } + + public createProject(request: sierra.CreateProjectRequest): Promise { + const req = this.convert.createProjectRequest(request); + const mapper = this.convert.project(); + + const call = callSingle(this.client.createProject.bind(this.client), mapper); + // disable retries for create + return publishToPromise(readOnce(this.channel, call, req, 1)); + } + + public listProjects(request: sierra.ListProjectsRequest): Publisher { + const req = this.convert.listProjectsRequest(request); + const mapper = this.convert.project(); + + const call = callStream(this.client.listProjects.bind(this.client), mapper); + return readOnce(this.channel, call, req, this.retries); + } +} diff --git a/packages/web/src/EmeraldApi.ts b/packages/web/src/EmeraldApi.ts index e16ed9c..d7cd553 100644 --- a/packages/web/src/EmeraldApi.ts +++ b/packages/web/src/EmeraldApi.ts @@ -1,11 +1,13 @@ import {SecretToken} from "@emeraldpay/api"; import {WebChannel} from "./channel"; import {CredentialsContext, emeraldCredentials} from "./credentials"; +import {AuthClient} from "./wrapped/AuthClient"; import {BlockchainClient} from "./wrapped/BlockchainClient"; import {InsightsClient} from "./wrapped/InsightsClient"; import {MarketClient} from "./wrapped/MarketClient"; +import {SierraOrgClient} from "./wrapped/SierraOrgClient"; +import {SierraProjectClient} from "./wrapped/SierraProjectClient"; import {SierraStatClient} from "./wrapped/SierraStatClient"; -import {AuthClient} from "./wrapped/AuthClient"; export class EmeraldApi { private readonly hostname: string; @@ -43,6 +45,14 @@ export class EmeraldApi { return new MarketClient(this.hostname, this.channel, this.credentials); } + get sierraProject(): SierraProjectClient { + return new SierraProjectClient(this.hostname, this.channel, this.credentials); + } + + get sierraOrg(): SierraOrgClient { + return new SierraOrgClient(this.hostname, this.channel, this.credentials); + } + get sierraStat(): SierraStatClient { return new SierraStatClient(this.hostname, this.channel, this.credentials); } diff --git a/packages/web/src/__integration-tests__/sierraOrg.test.ts b/packages/web/src/__integration-tests__/sierraOrg.test.ts new file mode 100644 index 0000000..732f544 --- /dev/null +++ b/packages/web/src/__integration-tests__/sierraOrg.test.ts @@ -0,0 +1,27 @@ +import {EmeraldApi} from "../EmeraldApi"; + +jest.setTimeout(35000); + +describe("SierraOrgClient", () => { + let api: EmeraldApi; + + beforeAll(() => { + // a dev token with user id: bada55a1-0000-4000-a000-000000000000 + api = EmeraldApi.devApi("emrld_fU88aIafXsCClerhyWtflBp1hH6h112ckzpSfP"); + }); + + test('getOrg', async () => { + const client = api.sierraOrg; + + const actual = await client.getOrg({ + orgId: "cafe0000-0000-4000-a000-000000000000", + }) + expect(actual).toEqual({ + orgId: "cafe0000-0000-4000-a000-000000000000", + name: "Test Org", + description: "Organization for using in tests", + createdAt: new Date("2024-11-21T22:32:41.173Z"), + }); + }); + +}); \ No newline at end of file diff --git a/packages/web/src/__integration-tests__/sierraProject.test.ts b/packages/web/src/__integration-tests__/sierraProject.test.ts new file mode 100644 index 0000000..a1e1b0b --- /dev/null +++ b/packages/web/src/__integration-tests__/sierraProject.test.ts @@ -0,0 +1,48 @@ +import {EmeraldApi} from "../EmeraldApi"; + +jest.setTimeout(35000); + +describe("SierraProjectClient", () => { + let api: EmeraldApi; + + beforeAll(() => { + // a dev token with user id: bada55a1-0000-4000-a000-000000000000 + api = EmeraldApi.devApi("emrld_fU88aIafXsCClerhyWtflBp1hH6h112ckzpSfP"); + }); + + test('createProject permission denied for the user', async () => { + const client = api.sierraProject; + + try { + await client.createProject({ + orgId: "cafe0000-0000-4000-a000-000000000000", + name: "Test Project", + description: "Project for using in tests", + }) + // return expect(call).rejects.toEqual({code: 7, message: ""}); // 7: PERMISSION_DENIED + } catch (e) { + console.log("createProject error: ", e) + expect(e).toEqual({code: 7, message: ""}); // 7: PERMISSION_DENIED + } + + // return expect(call).rejects.toEqual({code: 7, message: ""}); // 7: PERMISSION_DENIED + }); + + test('listProjects', (done) => { + const client = api.sierraProject; + + const call = client.listProjects({ + orgId: "cafe0000-0000-4000-a000-000000000000", + }) + call + .onData((data) => { + console.log("listProjects", data); + done(); + }) + .onError((error) => { + console.log("cancel: ", error.message); + done(error); + }) + }); + +}); \ No newline at end of file diff --git a/packages/web/src/__integration-tests__/sierra.test.ts b/packages/web/src/__integration-tests__/sierraStat.test.ts similarity index 81% rename from packages/web/src/__integration-tests__/sierra.test.ts rename to packages/web/src/__integration-tests__/sierraStat.test.ts index fc3081c..f5d6799 100644 --- a/packages/web/src/__integration-tests__/sierra.test.ts +++ b/packages/web/src/__integration-tests__/sierraStat.test.ts @@ -6,15 +6,15 @@ describe("SierraStatClient", () => { let api: EmeraldApi; beforeAll(() => { - // ORIGIN is set in jest.config.js - api = EmeraldApi.devApi(); + // a dev token with user id: bada55a1-0000-4000-a000-000000000000 + api = EmeraldApi.devApi("emrld_fU88aIafXsCClerhyWtflBp1hH6h112ckzpSfP"); }); test('getRequestCount', (done) => { const client = api.sierraStat; const call = client.getRequestCount({ - orgId: "test-org", + orgId: "cafe0000-0000-4000-a000-000000000000", }) call .onData((data) => { @@ -37,7 +37,7 @@ describe("SierraStatClient", () => { const client = api.sierraStat; const call = client.getTokenStat({ - orgId: "test-org", + orgId: "cafe0000-0000-4000-a000-000000000000", }) call .onData((data) => { diff --git a/packages/web/src/wrapped/Factory.ts b/packages/web/src/wrapped/Factory.ts index 7ce04aa..71d4df3 100644 --- a/packages/web/src/wrapped/Factory.ts +++ b/packages/web/src/wrapped/Factory.ts @@ -3,7 +3,7 @@ import * as auth_pb from "../generated/auth_pb"; import * as blockchain_pb from "../generated/blockchain_pb"; import * as common_pb from "../generated/common_pb"; import * as market_pb from "../generated/market_pb"; -import * as sierra_stat_message_pb from "../generated/sierra.stat.message_pb"; +import * as sierra_message_pb from "../generated/sierra.message_pb"; export const classFactory: MessageFactory = (id: string) => { if (id == "common_pb.Chain") { @@ -73,11 +73,20 @@ export const classFactory: MessageFactory = (id: string) => { return new market_pb.Pair(); } // Sierra - if (id == "sierra_stat_message_pb.GetRequestCountRequest") { - return new sierra_stat_message_pb.GetRequestCountRequest(); + if (id == "sierra_message_pb.CreateProjectRequest") { + return new sierra_message_pb.CreateProjectRequest(); } - if (id == "sierra_stat_message_pb.GetTokenStatRequest") { - return new sierra_stat_message_pb.GetTokenStatRequest(); + if (id == "sierra_message_pb.ListProjectsRequest") { + return new sierra_message_pb.ListProjectsRequest(); + } + if (id == "sierra_message_pb.GetOrgRequest") { + return new sierra_message_pb.GetOrgRequest() + } + if (id == "sierra_message_pb.GetRequestCountRequest") { + return new sierra_message_pb.GetRequestCountRequest(); + } + if (id == "sierra_message_pb.GetTokenStatRequest") { + return new sierra_message_pb.GetTokenStatRequest(); } throw Error("Unsupported type: " + id) diff --git a/packages/web/src/wrapped/SierraOrgClient.ts b/packages/web/src/wrapped/SierraOrgClient.ts new file mode 100644 index 0000000..94a8a36 --- /dev/null +++ b/packages/web/src/wrapped/SierraOrgClient.ts @@ -0,0 +1,28 @@ +import {publishToPromise, readOnce, sierra} from "@emeraldpay/api"; +import {WebChannel, callPromise} from "../channel"; +import {CredentialsContext} from "../credentials"; +import * as sierra_rpc from '../generated/SierraServiceClientPb'; +import {classFactory} from "./Factory"; + +export class SierraOrgClient { + readonly client: sierra_rpc.OrgClient; + readonly channel: WebChannel; + readonly retries: number; + + private readonly convert = new sierra.ConvertSierra(classFactory); + + constructor(hostname: string, channel: WebChannel, credentials: CredentialsContext, retries = 3) { + this.client = new sierra_rpc.OrgClient(hostname, null, credentials.options); + this.channel = channel; + this.retries = retries; + } + + public getOrg(request: sierra.GetOrgRequest): Promise { + const req = this.convert.getOrgRequest(request); + const mapper = this.convert.org(); + + const call = callPromise(this.client.getOrg.bind(this.client), mapper); + return publishToPromise(readOnce(this.channel, call, req, this.retries)); + } + +} diff --git a/packages/web/src/wrapped/SierraProjectClient.ts b/packages/web/src/wrapped/SierraProjectClient.ts new file mode 100644 index 0000000..ab884a0 --- /dev/null +++ b/packages/web/src/wrapped/SierraProjectClient.ts @@ -0,0 +1,37 @@ +import {Publisher, publishToPromise, readOnce, sierra} from "@emeraldpay/api"; +import {WebChannel, callPromise, callStream} from "../channel"; +import {CredentialsContext} from "../credentials"; +import * as sierra_rpc from '../generated/SierraServiceClientPb'; +import {classFactory} from "./Factory"; + +export class SierraProjectClient { + readonly client: sierra_rpc.ProjectClient; + readonly channel: WebChannel; + readonly retries: number; + + private readonly convert = new sierra.ConvertSierra(classFactory); + + constructor(hostname: string, channel: WebChannel, credentials: CredentialsContext, retries = 3) { + this.client = new sierra_rpc.ProjectClient(hostname, null, credentials.options); + this.channel = channel; + this.retries = retries; + } + + public createProject(request: sierra.CreateProjectRequest): Promise { + const req = this.convert.createProjectRequest(request); + const mapper = this.convert.project(); + + const call = callPromise(this.client.createProject.bind(this.client), mapper); + // disable retries for create + return publishToPromise(readOnce(this.channel, call, req, 1)); + } + + public listProjects(request: sierra.ListProjectsRequest): Publisher { + const req = this.convert.listProjectsRequest(request); + const mapper = this.convert.project(); + + const call = callStream(this.client.listProjects.bind(this.client), mapper); + return readOnce(this.channel, call, req, this.retries); + } + +} diff --git a/packages/web/src/wrapped/SierraStatClient.ts b/packages/web/src/wrapped/SierraStatClient.ts index ec7eb12..a50c597 100644 --- a/packages/web/src/wrapped/SierraStatClient.ts +++ b/packages/web/src/wrapped/SierraStatClient.ts @@ -1,7 +1,7 @@ import {Publisher, readOnce, sierra} from "@emeraldpay/api"; import {WebChannel, callStream} from "../channel"; import {CredentialsContext} from "../credentials"; -import * as sierra_rpc from '../generated/Sierra.statServiceClientPb'; +import * as sierra_rpc from '../generated/SierraServiceClientPb'; import {classFactory} from "./Factory"; export class SierraStatClient { @@ -33,6 +33,4 @@ export class SierraStatClient { return readOnce(this.channel, call, req, this.retries); } - - }