massimo 1.3.0 → 1.5.1
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/index.d.ts +1 -1
- package/index.js +12 -3
- package/lib/errors.js +4 -0
- package/package.json +9 -9
package/index.d.ts
CHANGED
|
@@ -84,10 +84,10 @@ export module errors {
|
|
|
84
84
|
export const OptionsUrlRequiredError: () => FastifyError
|
|
85
85
|
export const FormDataRequiredError: (value: string) => FastifyError
|
|
86
86
|
export const MissingParamsRequiredError: (value: string) => FastifyError
|
|
87
|
+
export const InvalidPathParameterError: (value: string) => FastifyError
|
|
87
88
|
export const WrongOptsTypeError: () => FastifyError
|
|
88
89
|
export const InvalidResponseSchemaError: (value: string) => FastifyError
|
|
89
90
|
export const InvalidContentTypeError: (value: string) => FastifyError
|
|
90
91
|
export const InvalidResponseFormatError: () => FastifyError
|
|
91
92
|
export const UnexpectedCallFailureError: (value: string) => FastifyError
|
|
92
93
|
}
|
|
93
|
-
|
package/index.js
CHANGED
|
@@ -39,6 +39,14 @@ function computeURLWithoutPath (url) {
|
|
|
39
39
|
return url.toString()
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function encodePathParameter (value, name) {
|
|
43
|
+
const encoded = encodeURIComponent(value)
|
|
44
|
+
if (encoded === '.' || encoded === '..') {
|
|
45
|
+
throw new errors.InvalidPathParameterError(name)
|
|
46
|
+
}
|
|
47
|
+
return encoded
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
async function buildCallFunction (
|
|
43
51
|
spec,
|
|
44
52
|
baseUrl,
|
|
@@ -62,7 +70,8 @@ async function buildCallFunction (
|
|
|
62
70
|
method = method.toUpperCase()
|
|
63
71
|
path = join(url.pathname, path)
|
|
64
72
|
|
|
65
|
-
const
|
|
73
|
+
const bodyMethods = ['POST', 'PUT', 'PATCH', 'OPTIONS', 'QUERY']
|
|
74
|
+
const canHaveBody = bodyMethods.includes(method)
|
|
66
75
|
const pathParams = methodMeta.parameters?.filter(p => p.in === 'path') || []
|
|
67
76
|
const queryParams = methodMeta.parameters?.filter(p => p.in === 'query') || []
|
|
68
77
|
const headerParams = methodMeta.parameters?.filter(p => p.in === 'header') || []
|
|
@@ -86,7 +95,7 @@ async function buildCallFunction (
|
|
|
86
95
|
if (args?.path[param.name] === undefined) {
|
|
87
96
|
throw new errors.MissingParamsRequiredError(param.name)
|
|
88
97
|
}
|
|
89
|
-
pathToCall = pathToCall.replace(`{${param.name}}`, args.path[param.name])
|
|
98
|
+
pathToCall = pathToCall.replace(`{${param.name}}`, encodePathParameter(args.path[param.name], param.name))
|
|
90
99
|
}
|
|
91
100
|
|
|
92
101
|
for (const param of queryParams) {
|
|
@@ -104,7 +113,7 @@ async function buildCallFunction (
|
|
|
104
113
|
if (body[param.name] === undefined) {
|
|
105
114
|
throw new errors.MissingParamsRequiredError(param.name)
|
|
106
115
|
}
|
|
107
|
-
pathToCall = pathToCall.replace(`{${param.name}}`, body[param.name])
|
|
116
|
+
pathToCall = pathToCall.replace(`{${param.name}}`, encodePathParameter(body[param.name], param.name))
|
|
108
117
|
body[param.name] = undefined
|
|
109
118
|
}
|
|
110
119
|
|
package/lib/errors.js
CHANGED
|
@@ -11,6 +11,10 @@ export const MissingParamsRequiredError = createError(
|
|
|
11
11
|
`${ERROR_PREFIX}_MISSING_PARAMS_REQUIRED`,
|
|
12
12
|
"Param %s is missing, and it's required"
|
|
13
13
|
)
|
|
14
|
+
export const InvalidPathParameterError = createError(
|
|
15
|
+
`${ERROR_PREFIX}_INVALID_PATH_PARAMETER`,
|
|
16
|
+
'Path parameter %s cannot be "." or ".."'
|
|
17
|
+
)
|
|
14
18
|
export const WrongOptsTypeError = createError(
|
|
15
19
|
`${ERROR_PREFIX}_WRONG_OPTS_TYPE`,
|
|
16
20
|
'opts.type must be either "openapi" or "graphql"'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "massimo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A client for HTTP services.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/platformatic/massimo#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@fastify/multipart": "^
|
|
42
|
-
"@platformatic/db": "3.
|
|
43
|
-
"@platformatic/foundation": "3.
|
|
44
|
-
"@platformatic/service": "3.
|
|
45
|
-
"@platformatic/telemetry": "3.
|
|
41
|
+
"@fastify/multipart": "^10.0.0",
|
|
42
|
+
"@platformatic/db": "3.67.0",
|
|
43
|
+
"@platformatic/foundation": "3.68.0",
|
|
44
|
+
"@platformatic/service": "3.67.0",
|
|
45
|
+
"@platformatic/telemetry": "3.68.0",
|
|
46
46
|
"c8": "^10.0.0",
|
|
47
47
|
"cleaner-spec-reporter": "^0.5.0",
|
|
48
48
|
"eslint": "9",
|
|
49
49
|
"execa": "^9.0.0",
|
|
50
|
-
"fastify": "^5.
|
|
51
|
-
"neostandard": "^0.
|
|
52
|
-
"tsd": "^0.
|
|
50
|
+
"fastify": "^5.12.0",
|
|
51
|
+
"neostandard": "^0.13.0",
|
|
52
|
+
"tsd": "^0.33.0",
|
|
53
53
|
"typescript": "^5.4.2"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|