-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solution: sierra project and org api
- Loading branch information
1 parent
61756db
commit 6b0d536
Showing
14 changed files
with
372 additions
and
38 deletions.
There are no files selected for viewing
Submodule api-definitions
updated
3 files
+42 −3 | proto/sierra.message.proto | |
+19 −0 | proto/sierra.proto | |
+0 −9 | proto/sierra.stat.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/node/src/__integration-tests__/sierraProject.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}) | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<sierra.Project> { | ||
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<sierra.Project> { | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"), | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.