fix: load tbank proto contracts at runtime
This commit is contained in:
parent
d01d2b9f7f
commit
b848d256d1
@ -1,4 +1,13 @@
|
|||||||
{
|
{
|
||||||
"collection": "@nestjs/schematics",
|
"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 () => {
|
it('throws integration unavailable when token is missing', async () => {
|
||||||
const missingConfig = {
|
const missingConfig = {
|
||||||
get: vi.fn((key: string, fallback?: unknown) =>
|
get: vi.fn((key: string, fallback?: unknown) =>
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
} from '@grpc/grpc-js';
|
} from '@grpc/grpc-js';
|
||||||
import { loadSync } from '@grpc/proto-loader';
|
import { loadSync } from '@grpc/proto-loader';
|
||||||
import PQueue from 'p-queue';
|
import PQueue from 'p-queue';
|
||||||
|
import { existsSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { TBANK_PROTO_FILES, TBANK_PROTO_PACKAGE } from '../tbank.config';
|
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),
|
intervalCap: this.configService.get<number>('app.tbank.rateLimitPerSecond', 5),
|
||||||
});
|
});
|
||||||
|
|
||||||
const protoRoot = join(__dirname, '..', 'proto', 'contracts');
|
const protoRoot = this.resolveProtoRoot();
|
||||||
const definition = loadSync(Object.values(TBANK_PROTO_FILES), {
|
const definition = loadSync(
|
||||||
includeDirs: [protoRoot],
|
Object.values(TBANK_PROTO_FILES).map((fileName) => join(protoRoot, fileName)),
|
||||||
keepCase: false,
|
{
|
||||||
longs: String,
|
includeDirs: [protoRoot],
|
||||||
enums: String,
|
keepCase: false,
|
||||||
defaults: true,
|
longs: String,
|
||||||
oneofs: true,
|
enums: String,
|
||||||
});
|
defaults: true,
|
||||||
|
oneofs: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
this.packageDefinition = loadPackageDefinition(definition);
|
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 {
|
createMetadata(): Metadata {
|
||||||
const token = this.configService.get<string>('app.tbank.token', '');
|
const token = this.configService.get<string>('app.tbank.token', '');
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user