@gravity-ui/gateway 4.6.0 → 4.7.1-alpha.0

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.
Files changed (95) hide show
  1. package/README.md +179 -3
  2. package/{build → dist/commonjs}/components/grpc.d.ts +5 -5
  3. package/{build → dist/commonjs}/components/grpc.js +109 -90
  4. package/{build → dist/commonjs}/components/mixed.d.ts +4 -4
  5. package/{build → dist/commonjs}/components/mixed.js +11 -12
  6. package/{build → dist/commonjs}/components/rest.d.ts +5 -5
  7. package/{build → dist/commonjs}/components/rest.js +42 -35
  8. package/{build → dist/commonjs}/constants.d.ts +2 -2
  9. package/{build → dist/commonjs}/constants.js +29 -19
  10. package/{build → dist/commonjs}/index.d.ts +9 -8
  11. package/{build → dist/commonjs}/index.js +35 -46
  12. package/{build → dist/commonjs}/models/common.d.ts +19 -8
  13. package/{build → dist/commonjs}/models/context.d.ts +0 -1
  14. package/dist/commonjs/package.json +3 -0
  15. package/dist/commonjs/utils/axios.d.ts +4 -0
  16. package/{build → dist/commonjs}/utils/axios.js +3 -4
  17. package/{build → dist/commonjs}/utils/common.d.ts +4 -3
  18. package/{build → dist/commonjs}/utils/common.js +19 -8
  19. package/{build → dist/commonjs}/utils/create-context-api.d.ts +2 -2
  20. package/{build → dist/commonjs}/utils/create-context-api.js +5 -6
  21. package/{build → dist/commonjs}/utils/grpc-reflection.js +15 -35
  22. package/{build → dist/commonjs}/utils/grpc.d.ts +1 -1
  23. package/{build → dist/commonjs}/utils/grpc.js +10 -11
  24. package/dist/commonjs/utils/overrideEndpoints/index.d.ts +2 -0
  25. package/dist/commonjs/utils/overrideEndpoints/index.js +4 -0
  26. package/{build → dist/commonjs}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
  27. package/{build → dist/commonjs}/utils/overrideEndpoints/overrideEndpoints.js +1 -2
  28. package/dist/commonjs/utils/package-root.d.ts +1 -0
  29. package/dist/commonjs/utils/package-root.js +44 -0
  30. package/{build → dist/commonjs}/utils/parse-error.d.ts +5 -5
  31. package/{build → dist/commonjs}/utils/parse-error.js +19 -19
  32. package/{build → dist/commonjs}/utils/proto-path-resolver.d.ts +1 -1
  33. package/{build → dist/commonjs}/utils/proto-path-resolver.js +24 -15
  34. package/{build → dist/commonjs}/utils/redact-sensitive-headers.d.ts +1 -2
  35. package/{build → dist/commonjs}/utils/redact-sensitive-headers.js +1 -2
  36. package/dist/commonjs/utils/source-dir.d.ts +1 -0
  37. package/dist/commonjs/utils/source-dir.js +41 -0
  38. package/{build → dist/commonjs}/utils/typed-api.d.ts +1 -1
  39. package/{build → dist/commonjs}/utils/typed-api.js +1 -2
  40. package/{build → dist/commonjs}/utils/validate.js +6 -10
  41. package/dist/esm/components/grpc.d.ts +24 -0
  42. package/dist/esm/components/grpc.js +691 -0
  43. package/dist/esm/components/mixed.d.ts +11 -0
  44. package/dist/esm/components/mixed.js +62 -0
  45. package/dist/esm/components/rest.d.ts +8 -0
  46. package/dist/esm/components/rest.js +357 -0
  47. package/dist/esm/constants.d.ts +53 -0
  48. package/dist/esm/constants.js +82 -0
  49. package/dist/esm/index.d.ts +13 -0
  50. package/dist/esm/index.js +274 -0
  51. package/dist/esm/models/common.d.ts +289 -0
  52. package/dist/esm/models/common.js +5 -0
  53. package/dist/esm/models/context.d.ts +22 -0
  54. package/dist/esm/models/context.js +1 -0
  55. package/dist/esm/models/error.d.ts +12 -0
  56. package/dist/esm/models/error.js +1 -0
  57. package/dist/esm/package.json +3 -0
  58. package/{build → dist/esm}/utils/axios.d.ts +1 -1
  59. package/dist/esm/utils/axios.js +24 -0
  60. package/dist/esm/utils/common.d.ts +16 -0
  61. package/dist/esm/utils/common.js +48 -0
  62. package/dist/esm/utils/create-context-api.d.ts +4 -0
  63. package/dist/esm/utils/create-context-api.js +38 -0
  64. package/dist/esm/utils/grpc-reflection.d.ts +28 -0
  65. package/dist/esm/utils/grpc-reflection.js +72 -0
  66. package/dist/esm/utils/grpc.d.ts +15 -0
  67. package/dist/esm/utils/grpc.js +72 -0
  68. package/dist/esm/utils/overrideEndpoints/index.d.ts +2 -0
  69. package/dist/esm/utils/overrideEndpoints/index.js +2 -0
  70. package/dist/esm/utils/overrideEndpoints/overrideEndpoints.d.ts +17 -0
  71. package/dist/esm/utils/overrideEndpoints/overrideEndpoints.js +96 -0
  72. package/dist/esm/utils/package-root.d.ts +1 -0
  73. package/dist/esm/utils/package-root.js +8 -0
  74. package/dist/esm/utils/parse-error.d.ts +30 -0
  75. package/dist/esm/utils/parse-error.js +214 -0
  76. package/dist/esm/utils/proto-path-resolver.d.ts +2 -0
  77. package/dist/esm/utils/proto-path-resolver.js +23 -0
  78. package/dist/esm/utils/redact-sensitive-headers.d.ts +3 -0
  79. package/dist/esm/utils/redact-sensitive-headers.js +12 -0
  80. package/dist/esm/utils/source-dir.d.ts +1 -0
  81. package/dist/esm/utils/source-dir.js +4 -0
  82. package/dist/esm/utils/typed-api.d.ts +2 -0
  83. package/dist/esm/utils/typed-api.js +3 -0
  84. package/dist/esm/utils/validate.d.ts +4 -0
  85. package/dist/esm/utils/validate.js +47 -0
  86. package/package.json +41 -16
  87. package/build/utils/overrideEndpoints/index.d.ts +0 -2
  88. package/build/utils/overrideEndpoints/index.js +0 -4
  89. /package/bin/{patch.js → patch.cjs} +0 -0
  90. /package/{build → dist/commonjs}/models/common.js +0 -0
  91. /package/{build → dist/commonjs}/models/context.js +0 -0
  92. /package/{build → dist/commonjs}/models/error.d.ts +0 -0
  93. /package/{build → dist/commonjs}/models/error.js +0 -0
  94. /package/{build → dist/commonjs}/utils/grpc-reflection.d.ts +0 -0
  95. /package/{build → dist/commonjs}/utils/validate.d.ts +0 -0
@@ -0,0 +1,23 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import protobufjs from 'protobufjs';
4
+ export function patchProtoPathResolver(root, includeDirs) {
5
+ const originalResolvePath = root.resolvePath;
6
+ root.resolvePath = function (origin, target) {
7
+ if (target in protobufjs.common || path.isAbsolute(target)) {
8
+ return target;
9
+ }
10
+ for (let i = 0; i < includeDirs.length; i++) {
11
+ const directory = includeDirs[i];
12
+ const fullPath = path.join(directory, target);
13
+ try {
14
+ fs.accessSync(fullPath, fs.constants.R_OK);
15
+ return fullPath;
16
+ }
17
+ catch (err) {
18
+ continue;
19
+ }
20
+ }
21
+ return originalResolvePath(origin, target);
22
+ };
23
+ }
@@ -0,0 +1,3 @@
1
+ import { IncomingHttpHeaders } from 'http';
2
+ import { GatewayContext } from '../models/context.js';
3
+ export declare function redactSensitiveHeaders(ctx: GatewayContext, headers: IncomingHttpHeaders): IncomingHttpHeaders;
@@ -0,0 +1,12 @@
1
+ export function redactSensitiveHeaders(ctx, headers) {
2
+ var _a, _b;
3
+ if ((_a = ctx.utils) === null || _a === void 0 ? void 0 : _a.redactSensitiveHeaders) {
4
+ return ctx.utils.redactSensitiveHeaders(headers);
5
+ }
6
+ else if ((_b = ctx.utils) === null || _b === void 0 ? void 0 : _b.redactSensitiveKeys) {
7
+ return ctx.utils.redactSensitiveKeys(headers);
8
+ }
9
+ else {
10
+ return headers;
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export declare const sourceDir: string;
@@ -0,0 +1,4 @@
1
+ import * as path from 'path';
2
+ import * as url from 'url';
3
+ // @ts-ignore to get the CommonJS build to ignore it
4
+ export const sourceDir = path.resolve(url.fileURLToPath(new URL('.', import.meta.url)), '..');
@@ -0,0 +1,2 @@
1
+ import { ContextApiWithRoot, SchemasByScope } from '../models/common.js';
2
+ export declare function getTypedApiFactory<TSchema extends SchemasByScope>(): (api: unknown) => ContextApiWithRoot<TSchema>;
@@ -0,0 +1,3 @@
1
+ export function getTypedApiFactory() {
2
+ return (api) => api;
3
+ }
@@ -0,0 +1,4 @@
1
+ export declare function validateArgs<TParams>(args: TParams, schema: object): string | false;
2
+ export declare function encodePathParams<TParams extends {}>(params: TParams): Record<string, any>;
3
+ export declare function getPathParam(value: string): string;
4
+ export declare function getPathArgsProxy<TParams extends {}>(args: TParams, encodePathArgs?: boolean): TParams;
@@ -0,0 +1,47 @@
1
+ import { Ajv } from 'ajv';
2
+ export function validateArgs(args, schema) {
3
+ const ajv = new Ajv();
4
+ const validate = ajv.compile(schema);
5
+ return validate(args) ? false : ajv.errorsText(validate.errors);
6
+ }
7
+ export function encodePathParams(params) {
8
+ const encodedParams = {};
9
+ Object.keys(params).forEach((key) => {
10
+ const value = params[key];
11
+ if (value instanceof Buffer) {
12
+ encodedParams[key] = value;
13
+ }
14
+ else if (typeof value === 'object' && value !== null) {
15
+ encodedParams[key] = encodePathParams(value);
16
+ }
17
+ else {
18
+ encodedParams[key] = encodeURIComponent(value);
19
+ }
20
+ });
21
+ return encodedParams;
22
+ }
23
+ export function getPathParam(value) {
24
+ return /^((?!(\.\.|\?|#|\\|\/)).)*$/i.test(value) ? value : 'GATEWAY_INVALID_PARAM_VALUE';
25
+ }
26
+ export function getPathArgsProxy(args, encodePathArgs) {
27
+ const encodePathArgsVal = encodePathArgs !== null && encodePathArgs !== void 0 ? encodePathArgs : true;
28
+ if (!args) {
29
+ return args;
30
+ }
31
+ return new Proxy(args, {
32
+ get: (object, key) => {
33
+ const value = object[key];
34
+ if (value instanceof Buffer) {
35
+ return value;
36
+ }
37
+ if (typeof value === 'object' && value !== null) {
38
+ return getPathArgsProxy(value);
39
+ }
40
+ if (typeof value === 'string') {
41
+ const pathParam = getPathParam(value);
42
+ return encodePathArgsVal ? encodeURIComponent(pathParam) : pathParam;
43
+ }
44
+ return value; // TODO return error INVALID_PARAMS
45
+ },
46
+ });
47
+ }
package/package.json CHANGED
@@ -1,18 +1,33 @@
1
1
  {
2
2
  "name": "@gravity-ui/gateway",
3
- "version": "4.6.0",
3
+ "version": "4.7.1-alpha.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
- "main": "build/index.js",
6
+ "type": "module",
7
+ "main": "./dist/commonjs/index.js",
8
+ "module": "./dist/esm/index.js",
9
+ "types": "./dist/commonjs/index.d.ts",
10
+ "exports": {
11
+ "./package.json": "./package.json",
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/esm/index.d.ts",
15
+ "default": "./dist/esm/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/commonjs/index.d.ts",
19
+ "default": "./dist/commonjs/index.js"
20
+ }
21
+ }
22
+ },
7
23
  "files": [
8
- "build",
24
+ "dist",
9
25
  "proto",
10
26
  "bin",
11
27
  "patches"
12
28
  ],
13
- "types": "build/index.d.ts",
14
29
  "bin": {
15
- "gateway-reflection-patch": "bin/patch.js"
30
+ "gateway-reflection-patch": "bin/patch.cjs"
16
31
  },
17
32
  "repository": {
18
33
  "type": "git",
@@ -24,13 +39,13 @@
24
39
  "homepage": "https://github.com/gravity-ui/gateway#readme",
25
40
  "scripts": {
26
41
  "prepare": "husky install",
27
- "build": "tsc",
42
+ "build": "tshy",
28
43
  "build-integration": "sh integration-test/build.sh",
29
- "start-integration-server": "node build-integration/integration-test/server",
44
+ "start-integration-server": "node build-integration/server",
30
45
  "build-and-run-integration": "npm run build-integration && npm run start-integration-server",
31
46
  "clean": "rm -rf build && rm -rf build-integration",
32
47
  "lint": "npm run lint:code && npm run lint:exports",
33
- "lint:code": "eslint \"lib/**/*.{js,ts}\" --quiet",
48
+ "lint:code": "eslint \"src/**/*.{js,ts}\" --quiet",
34
49
  "lint:exports": "npm run build && attw --pack .",
35
50
  "typecheck": "tsc --noEmit",
36
51
  "prepublishOnly": "npm run build",
@@ -41,9 +56,9 @@
41
56
  "dependencies": {
42
57
  "@grpc/grpc-js": "^1.9.9",
43
58
  "@grpc/proto-loader": "^0.7.8",
44
- "ajv": "^8.12.0",
59
+ "ajv": "^8.17.1",
45
60
  "axios": "^1.8.3",
46
- "axios-retry": "^3.9.1",
61
+ "axios-retry": "^4.5.0",
47
62
  "lodash": "^4.17.21",
48
63
  "object-sizeof": "^2.6.5",
49
64
  "protobufjs": "^7.2.5",
@@ -51,13 +66,13 @@
51
66
  },
52
67
  "devDependencies": {
53
68
  "@arethetypeswrong/cli": "^0.17.3",
54
- "@commitlint/cli": "^17.7.1",
55
- "@commitlint/config-conventional": "^17.7.0",
69
+ "@commitlint/cli": "^19.6.1",
70
+ "@commitlint/config-conventional": "^19.6.0",
56
71
  "@gravity-ui/eslint-config": "^2.0.0",
57
72
  "@gravity-ui/prettier-config": "^1.0.1",
58
73
  "@gravity-ui/tsconfig": "^1.0.0",
59
74
  "@types/express": "^4.17.17",
60
- "@types/jest": "^29.5.0",
75
+ "@types/jest": "^29.5.14",
61
76
  "@types/lodash": "^4.14.192",
62
77
  "@types/node": "^18.15.11",
63
78
  "@types/uuid": "^9.0.1",
@@ -68,13 +83,14 @@
68
83
  "grpc-server-reflection": "^0.1.5",
69
84
  "grpc-tools": "^1.12.4",
70
85
  "husky": "^8.0.3",
71
- "jest": "^29.5.0",
86
+ "jest": "^29.7.0",
72
87
  "nano-staged": "^0.8.0",
73
88
  "prettier": "^2.8.6",
74
89
  "start-server-and-test": "^2.0.0",
75
- "ts-jest": "^29.1.1",
90
+ "ts-jest": "^29.2.5",
76
91
  "tsc-watch": "^6.0.0",
77
- "typescript": "^5.0.2"
92
+ "tshy": "^3.0.2",
93
+ "typescript": "^5.7.3"
78
94
  },
79
95
  "peerDependencies": {
80
96
  "grpc-reflection-js": "^0.3.0"
@@ -91,5 +107,14 @@
91
107
  "*.md": [
92
108
  "prettier --write"
93
109
  ]
110
+ },
111
+ "tshy": {
112
+ "exclude": [
113
+ "src/**/*.test.ts"
114
+ ],
115
+ "exports": {
116
+ "./package.json": "./package.json",
117
+ ".": "./src/index.ts"
118
+ }
94
119
  }
95
120
  }
@@ -1,2 +0,0 @@
1
- import { overrideEndpoints } from './overrideEndpoints';
2
- export default overrideEndpoints;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const overrideEndpoints_1 = require("./overrideEndpoints");
4
- exports.default = overrideEndpoints_1.overrideEndpoints;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes