Skip to content

Commit

Permalink
fix(facade): sub-services need to follow snake_case identiy.o_auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Aug 26, 2024
1 parent 2359c1a commit 0effc1c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
45 changes: 30 additions & 15 deletions packages/facade/src/gql/protos/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { authSubjectType, type ProtoMetadata, type ServiceClient, type ServiceConfig, type SubSpaceServiceConfig } from './types.js';
import {
authSubjectType,
type ProtoMetadata,
type ServiceClient,
type ServiceConfig,
type SubSpaceServiceConfig
} from './types.js';
import flat from 'array.prototype.flat';
import { getTyping } from './registry.js';
import {
Expand All @@ -8,7 +14,6 @@ import {
import {
camelCase,
capitalize,
convertEnumToInt,
decodeBufferFields,
getKeys,
snakeToCamel,
Expand Down Expand Up @@ -123,7 +128,7 @@ export const getGQLResolverFunctions =
(obj as any)[methodName] = async (args: any, context: ServiceClient<CTX, keyof CTX, T>) => {
// remap namespace and serviceKey if given
key = cfg?.namespace ?? key;
serviceKey = cfg?.serviceKey ?? serviceKey;
serviceKey = cfg?.serviceKeyMap?.[serviceKey] ?? cfg?.serviceKey ?? serviceKey;
const client = context[key].client;
const service = client[serviceKey];
try {
Expand Down Expand Up @@ -306,7 +311,15 @@ export const registerResolverFunction = <T extends Record<string, any>, CTX exte
}
}
if (service) {
const key = namespace?.toLocaleLowerCase() + '.' + subspace?.toLocaleLowerCase() + '.' + name?.toLocaleLowerCase();
const key = [
namespace,
subspace,
name
].filter(
s => s
).join(
'.'
).toLocaleLowerCase();
const value = service.method.find((m) => m.name === name);
if (key && value?.inputType) {
inputMethodType.set(key, value.inputType);
Expand Down Expand Up @@ -370,7 +383,15 @@ export const generateResolver = (...namespaces: string[]) => {
return resolvers;
};

export const generateSubServiceResolvers = <T, M extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, M>>(subServices: ProtoMetadata[], config: SubSpaceServiceConfig, namespace: string): T => {
export const generateSubServiceResolvers = <
T,
M extends Record<string, any>,
CTX extends ServiceClient<CTX, keyof CTX, M>
>(
subServices: ProtoMetadata[],
config: SubSpaceServiceConfig,
namespace: string,
): T => {
subServices.forEach((meta) => {
meta.fileDescriptor.service.forEach(service => {
if (service.name) {
Expand Down Expand Up @@ -515,15 +536,9 @@ export const generateSubServiceResolvers = <T, M extends Record<string, any>, CT
return undefined;
}

// rename master_data and ostorage name space to actual service names in proto files
if (resolver.targetService == 'master_data') {
resolver.targetService = 'resource';
} else if (resolver.targetService == 'ostorage') {
resolver.targetSubService = 'ostorage';
}
const client = ctx[resolver.targetService as string].client;
const service = client[resolver.targetSubService as string];

resolver.targetService = config?.namespace ?? resolver.targetService
const client = ctx[resolver.targetService].client;
const service = client[resolver.targetSubService];
const idList: string[] = Array.isArray(parent[fieldJsonName]) ? parent[fieldJsonName] : [parent[fieldJsonName]];

// TODO Support custom input messages
Expand All @@ -550,7 +565,7 @@ export const generateSubServiceResolvers = <T, M extends Record<string, any>, CT
req.subject!.token = await fetchUnauthenticatedUserToken(ctx, (ctx as any).request!.req.headers['origin']);
}

const methodFunc = service[camelCase(resolver.targetMethod as string)] || service[resolver.targetMethod as string];
const methodFunc = service[camelCase(resolver.targetMethod)] || service[resolver.targetMethod];
const result = await methodFunc(req);

if (result && result.items && result.items.length) {
Expand Down
4 changes: 2 additions & 2 deletions packages/facade/src/modules/identity/grpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class IdentitySrvGrpcClient extends RestoreCommerceGrpcClient {
readonly role: RoleServiceClient;
readonly authentication_log: AuthenticationLogServiceClient;
readonly token: TokenServiceClient;
readonly oauth: OAuthServiceClient;
readonly o_auth: OAuthServiceClient;

constructor(address: string, cfg: GrpcClientConfig) {
super(address, cfg);
Expand All @@ -36,7 +36,7 @@ export class IdentitySrvGrpcClient extends RestoreCommerceGrpcClient {
this.role = this.createClient(cfg, RoleServiceDefinition, this.channel);
this.authentication_log = this.createClient(cfg, AuthenticationLogServiceDefinition, this.channel);
this.token = this.createClient(cfg, TokenServiceDefinition, this.channel);
this.oauth = this.createClient(cfg, OAuthServiceDefinition, this.channel);
this.o_auth = this.createClient(cfg, OAuthServiceDefinition, this.channel);
}

}

0 comments on commit 0effc1c

Please sign in to comment.