@restorecommerce/facade 0.3.15 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,34 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.3.18](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.17...@restorecommerce/facade@0.3.18) (2022-04-25)
7
+
8
+ **Note:** Version bump only for package @restorecommerce/facade
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.3.17](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.16...@restorecommerce/facade@0.3.17) (2022-04-20)
15
+
16
+ **Note:** Version bump only for package @restorecommerce/facade
17
+
18
+
19
+
20
+
21
+
22
+ ## [0.3.16](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.15...@restorecommerce/facade@0.3.16) (2022-04-07)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **facade:** blacklist and whitelist config for sub service name space level ([6d737d6](https://github.com/restorecommerce/libs/commit/6d737d62a5395890e506a3fb76aa31f9e127d38e))
28
+ * **facade:** mask register resolver schema for blacklisted config ([8478590](https://github.com/restorecommerce/libs/commit/8478590bd994eedd3023a8e0f7f347a33f2019f1))
29
+
30
+
31
+
32
+
33
+
6
34
  ## [0.3.15](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.14...@restorecommerce/facade@0.3.15) (2022-04-05)
7
35
 
8
36
  **Note:** Version bump only for package @restorecommerce/facade
@@ -2,7 +2,6 @@ import { GraphQLInputField, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema
2
2
  import { GraphQLEnumType, GraphQLFieldConfig, GraphQLFieldConfigMap, GraphQLInputObjectType, GraphQLInputType } from "graphql/type/definition";
3
3
  import { ServiceConfig, SubService, SubSpaceServiceConfig } from "./types";
4
4
  import { MethodDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
5
- import { GrpcClientConfig } from "@restorecommerce/grpc-client";
6
5
  export declare const getGQLSchema: <TSource, TContext>(method: MethodDescriptorProto) => GraphQLFieldConfig<TSource, TContext, any>;
7
6
  export declare const getGQLSchemas: <TSource, TContext>(service: ServiceDescriptorProto) => GraphQLFieldConfigMap<TSource, TContext>;
8
7
  export declare const preprocessGQLInput: (data: any, model: GraphQLInputObjectType | GraphQLEnumType | GraphQLInputField | GraphQLInputType) => Promise<any>;
@@ -13,16 +12,16 @@ declare type ServiceClient<Context extends Pick<Context, Key>, Key extends keyof
13
12
  client: T;
14
13
  };
15
14
  };
16
- export declare const getGQLResolverFunctions: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>, SRV = any, R = ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, B extends keyof T = any, NS extends keyof CTX = any>(service: ServiceDescriptorProto, key: NS, serviceKey: B, grpcClientConfig: GrpcClientConfig) => { [key in keyof SRV]: R; };
15
+ export declare const getGQLResolverFunctions: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>, SRV = any, R = ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, B extends keyof T = any, NS extends keyof CTX = any>(service: ServiceDescriptorProto, key: NS, serviceKey: B, cfg: ServiceConfig) => { [key in keyof SRV]: R; };
17
16
  export declare const registerResolverFunction: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>>(namespace: string, name: string, func: ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, mutation?: boolean, subspace?: string | undefined, service?: ServiceDescriptorProto | undefined) => void;
18
17
  export declare const generateResolver: (...namespaces: string[]) => any;
19
18
  declare type SchemaBaseOrSub = ThunkObjMap<GraphQLFieldConfig<any, any>> | Map<string, ThunkObjMap<GraphQLFieldConfig<any, any>>>;
20
- export declare const registerResolverSchema: (namespace: string, name: string, schema: SchemaBaseOrSub, mutation?: boolean, subspace?: string | undefined) => void;
19
+ export declare const registerResolverSchema: (namespace: string, name: string, schema: SchemaBaseOrSub, mutation: boolean | undefined, subspace: string | undefined, config: ServiceConfig) => void;
21
20
  export declare const generateSchema: (setup: {
22
21
  prefix: string;
23
22
  namespace: string;
24
23
  }[]) => GraphQLSchema;
25
- export declare const getWhitelistBlacklistConfig: (metaService: ServiceDescriptorProto, queries: string[], config: ServiceConfig) => {
24
+ export declare const getWhitelistBlacklistConfig: (metaService: ServiceDescriptorProto, queries: string[], config: ServiceConfig, entity: string) => {
26
25
  queries: Set<string>;
27
26
  mutations: Set<string>;
28
27
  };
@@ -150,11 +150,18 @@ const postProcessGQLValue = (data, model) => {
150
150
  return data;
151
151
  };
152
152
  exports.postProcessGQLValue = postProcessGQLValue;
153
- const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) => {
153
+ const getGQLResolverFunctions = (service, key, serviceKey, cfg) => {
154
154
  if (!service.method) {
155
155
  return {};
156
156
  }
157
157
  return service.method.reduce((obj, method) => {
158
+ var _a, _b, _c, _d;
159
+ if ((_b = (_a = cfg[serviceKey]) === null || _a === void 0 ? void 0 : _a.methods) === null || _b === void 0 ? void 0 : _b.blacklist) {
160
+ const blacklistMethods = (_d = (_c = cfg[serviceKey]) === null || _c === void 0 ? void 0 : _c.methods) === null || _d === void 0 ? void 0 : _d.blacklist;
161
+ if (blacklistMethods.includes(method.name)) {
162
+ return {};
163
+ }
164
+ }
158
165
  const typing = (0, registry_1.getTyping)(method.inputType);
159
166
  const outputTyping = (0, registry_1.getTyping)(method.outputType);
160
167
  if (!typing) {
@@ -220,6 +227,7 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
220
227
  }
221
228
  const rawResult = await service[realMethod](req);
222
229
  const result = (0, exports.postProcessGQLValue)(rawResult, outputTyping.output);
230
+ const grpcClientConfig = cfg.client;
223
231
  const bufferFields = (0, utils_1.getKeys)(grpcClientConfig === null || grpcClientConfig === void 0 ? void 0 : grpcClientConfig.bufferFields);
224
232
  if (result instanceof stream.Readable) {
225
233
  let operationStatus = { code: 0, message: '' };
@@ -383,10 +391,16 @@ const generateResolver = (...namespaces) => {
383
391
  };
384
392
  exports.generateResolver = generateResolver;
385
393
  const namespaceResolverSchemaRegistry = new Map();
386
- const registerResolverSchema = (namespace, name, schema, mutation = false, subspace = undefined) => {
394
+ const registerResolverSchema = (namespace, name, schema, mutation = false, subspace = undefined, config) => {
387
395
  if (!namespaceResolverSchemaRegistry.has(namespace)) {
388
396
  namespaceResolverSchemaRegistry.set(namespace, new Map());
389
397
  }
398
+ if (subspace && config[subspace]) {
399
+ const blacklistMethods = config[subspace].methods.blacklist;
400
+ if (blacklistMethods.includes(name)) {
401
+ return;
402
+ }
403
+ }
390
404
  if (!namespaceResolverSchemaRegistry.get(namespace).has(mutation)) {
391
405
  namespaceResolverSchemaRegistry.get(namespace).set(mutation, new Map());
392
406
  }
@@ -482,12 +496,13 @@ const generateSchema = (setup) => {
482
496
  return new graphql_1.GraphQLSchema(config);
483
497
  };
484
498
  exports.generateSchema = generateSchema;
485
- const getWhitelistBlacklistConfig = (metaService, queries, config) => {
499
+ const getWhitelistBlacklistConfig = (metaService, queries, config, entity) => {
500
+ var _a, _b, _c, _d;
486
501
  const mut = new Set(metaService.method.map(m => m.name).filter(key => queries.indexOf(key) < 0));
487
502
  const que = new Set(metaService.method.map(m => m.name).filter(key => queries.indexOf(key) >= 0));
488
- if (config.methods) {
489
- if (config.methods.whitelist) {
490
- const whitelist = new Set(config.methods.whitelist);
503
+ if (config[entity]) {
504
+ if ((_b = (_a = config[entity]) === null || _a === void 0 ? void 0 : _a.methods) === null || _b === void 0 ? void 0 : _b.whitelist) {
505
+ const whitelist = new Set(config[entity].methods.whitelist);
491
506
  mut.forEach(key => {
492
507
  if (whitelist.has(key)) {
493
508
  whitelist.delete(key);
@@ -509,8 +524,8 @@ const getWhitelistBlacklistConfig = (metaService, queries, config) => {
509
524
  console.error('Whitelist contains undefined methods:', whitelist);
510
525
  }
511
526
  }
512
- else if (config.methods.blacklist) {
513
- const blacklist = new Set(config.methods.blacklist);
527
+ else if ((_d = (_c = config[entity]) === null || _c === void 0 ? void 0 : _c.methods) === null || _d === void 0 ? void 0 : _d.blacklist) {
528
+ const blacklist = new Set(config[entity].methods.blacklist);
514
529
  mut.forEach(key => {
515
530
  if (blacklist.has(key)) {
516
531
  blacklist.delete(key);
@@ -539,17 +554,17 @@ const getWhitelistBlacklistConfig = (metaService, queries, config) => {
539
554
  };
540
555
  exports.getWhitelistBlacklistConfig = getWhitelistBlacklistConfig;
541
556
  const getAndGenerateSchema = (service, namespace, prefix, cfg, queryList) => {
542
- const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, queryList, cfg);
557
+ const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, queryList, cfg, service.name);
543
558
  const schemas = (0, exports.getGQLSchemas)(service);
544
559
  Object.keys(schemas).forEach(key => {
545
- (0, exports.registerResolverSchema)(namespace, key, schemas[key], !queries.has(key) && mutations.has(key));
560
+ (0, exports.registerResolverSchema)(namespace, key, schemas[key], !queries.has(key) && mutations.has(key), undefined, cfg);
546
561
  });
547
562
  return (0, exports.generateSchema)([{ prefix, namespace }]);
548
563
  };
549
564
  exports.getAndGenerateSchema = getAndGenerateSchema;
550
565
  const getAndGenerateResolvers = (service, namespace, cfg, queryList, subspace = undefined, serviceKey = undefined) => {
551
- const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, queryList, cfg);
552
- const func = (0, exports.getGQLResolverFunctions)(service, namespace, serviceKey || subspace || namespace, cfg.client);
566
+ const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, queryList, cfg, service.name);
567
+ const func = (0, exports.getGQLResolverFunctions)(service, namespace, serviceKey || subspace || namespace, cfg);
553
568
  Object.keys(func).forEach(k => {
554
569
  (0, exports.registerResolverFunction)(namespace, k, func[k], !queries.has(k) && mutations.has(k), subspace, service);
555
570
  });
@@ -558,10 +573,10 @@ const getAndGenerateResolvers = (service, namespace, cfg, queryList, subspace =
558
573
  exports.getAndGenerateResolvers = getAndGenerateResolvers;
559
574
  const generateSubServiceSchemas = (subServices, config, namespace, prefix) => {
560
575
  subServices.forEach((sub) => {
561
- const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(sub.service, sub.queries, config);
576
+ const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(sub.service, sub.queries, config, sub.name);
562
577
  const schemas = (0, exports.getGQLSchemas)(sub.service);
563
578
  Object.keys(schemas).forEach(key => {
564
- (0, exports.registerResolverSchema)(config.root ? sub.name : namespace, key, schemas[key], !queries.has(key) && mutations.has(key), config.root ? undefined : sub.name);
579
+ (0, exports.registerResolverSchema)(config.root ? sub.name : namespace, key, schemas[key], !queries.has(key) && mutations.has(key), config.root ? undefined : sub.name, config);
565
580
  });
566
581
  });
567
582
  if (config.root) {
@@ -575,8 +590,8 @@ const generateSubServiceSchemas = (subServices, config, namespace, prefix) => {
575
590
  exports.generateSubServiceSchemas = generateSubServiceSchemas;
576
591
  const generateSubServiceResolvers = (subServices, config, namespace) => {
577
592
  subServices.forEach((sub) => {
578
- const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(sub.service, sub.queries, config);
579
- const func = (0, exports.getGQLResolverFunctions)(sub.service, namespace, sub.name || namespace, config.client);
593
+ const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(sub.service, sub.queries, config, sub.name);
594
+ const func = (0, exports.getGQLResolverFunctions)(sub.service, namespace, sub.name || namespace, config);
580
595
  Object.keys(func).forEach(k => {
581
596
  const regNamespace = config.root ? sub.name : namespace;
582
597
  const regSubspace = config.root ? undefined : sub.name;
@@ -8,13 +8,16 @@ export interface ProtoMetadata {
8
8
  };
9
9
  dependencies?: ProtoMetadata[];
10
10
  }
11
- export interface MethodConfig {
11
+ export interface BlackListWhiteListConfig {
12
12
  whitelist?: string[];
13
13
  blacklist?: string[];
14
14
  }
15
+ export interface MethodConfig {
16
+ methods?: BlackListWhiteListConfig;
17
+ }
15
18
  export interface ServiceConfig {
16
19
  client: GrpcClientConfig;
17
- methods?: MethodConfig;
20
+ [key: string]: any;
18
21
  }
19
22
  export interface SubSpaceServiceConfig extends ServiceConfig {
20
23
  root: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restorecommerce/facade",
3
- "version": "0.3.15",
3
+ "version": "0.3.18",
4
4
  "description": "Facade for Restorecommerce microservices",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "@restorecommerce/grpc-client": "^0.3.1",
28
28
  "@restorecommerce/kafka-client": "^0.3.1",
29
29
  "@restorecommerce/logger": "^0.12.1",
30
- "@restorecommerce/rc-grpc-clients": "^0.4.5",
30
+ "@restorecommerce/rc-grpc-clients": "^0.4.7",
31
31
  "@restorecommerce/service-config": "^0.4.25",
32
32
  "apollo-server-core": "^3.6.3",
33
33
  "apollo-server-koa": "^3.6.3",
@@ -108,5 +108,5 @@
108
108
  "publishConfig": {
109
109
  "access": "public"
110
110
  },
111
- "gitHead": "93ec5c59ff01e0292c56bb5161f63bb0df7e027b"
111
+ "gitHead": "600de085c57a766fb29a20b4b10c83e9235034ab"
112
112
  }