fix: load tbank proto contracts at runtime
This commit is contained in:
parent
d01d2b9f7f
commit
b848d256d1
@ -1,4 +1,13 @@
|
||||
{
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src"
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"assets": [
|
||||
{
|
||||
"include": "modules/tbank/proto/contracts/**/*",
|
||||
"outDir": "dist"
|
||||
}
|
||||
],
|
||||
"watchAssets": true
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,12 @@ describe('TBankClientService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('creates service clients from vendored proto contracts', () => {
|
||||
const service = new TBankClientService(config);
|
||||
|
||||
expect(() => service.getServiceClient('UsersService')).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws integration unavailable when token is missing', async () => {
|
||||
const missingConfig = {
|
||||
get: vi.fn((key: string, fallback?: unknown) =>
|
||||
|
||||
@ -17,6 +17,7 @@ import {
|
||||
} from '@grpc/grpc-js';
|
||||
import { loadSync } from '@grpc/proto-loader';
|
||||
import PQueue from 'p-queue';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { TBANK_PROTO_FILES, TBANK_PROTO_PACKAGE } from '../tbank.config';
|
||||
|
||||
@ -44,19 +45,29 @@ export class TBankClientService {
|
||||
intervalCap: this.configService.get<number>('app.tbank.rateLimitPerSecond', 5),
|
||||
});
|
||||
|
||||
const protoRoot = join(__dirname, '..', 'proto', 'contracts');
|
||||
const definition = loadSync(Object.values(TBANK_PROTO_FILES), {
|
||||
const protoRoot = this.resolveProtoRoot();
|
||||
const definition = loadSync(
|
||||
Object.values(TBANK_PROTO_FILES).map((fileName) => join(protoRoot, fileName)),
|
||||
{
|
||||
includeDirs: [protoRoot],
|
||||
keepCase: false,
|
||||
longs: String,
|
||||
enums: String,
|
||||
defaults: true,
|
||||
oneofs: true,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
this.packageDefinition = loadPackageDefinition(definition);
|
||||
}
|
||||
|
||||
private resolveProtoRoot(): string {
|
||||
const distProtoRoot = join(__dirname, '..', 'proto', 'contracts');
|
||||
if (existsSync(distProtoRoot)) return distProtoRoot;
|
||||
|
||||
return join(process.cwd(), 'src', 'modules', 'tbank', 'proto', 'contracts');
|
||||
}
|
||||
|
||||
createMetadata(): Metadata {
|
||||
const token = this.configService.get<string>('app.tbank.token', '');
|
||||
if (!token) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user