@graphcommerce/magento-graphql-rest 9.0.0-canary.64
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 +7 -0
- package/README.md +26 -0
- package/index.ts +1 -0
- package/m2-filtered-spec.json +9886 -0
- package/package.json +29 -0
- package/plugins/meshConfigM2Rest.ts +63 -0
- package/scripts/generate-spec.mts +74 -0
- package/scripts/m2rest-admin.json +66351 -0
- package/scripts/m2rest-customer.json +13289 -0
- package/scripts/m2rest-guest.json +10007 -0
- package/tsconfig.json +5 -0
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphcommerce/magento-graphql-rest",
|
|
3
|
+
"homepage": "https://www.graphcommerce.org/",
|
|
4
|
+
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
+
"version": "9.0.0-canary.64",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "index.ts",
|
|
8
|
+
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
9
|
+
"eslintConfig": {
|
|
10
|
+
"extends": "@graphcommerce/eslint-config-pwa",
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": "./tsconfig.json"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"generate": "tsx ./scripts/generate-spec.mts"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@graphcommerce/graphql-mesh": "^9.0.0-canary.64",
|
|
20
|
+
"@graphcommerce/magento-product": "^9.0.0-canary.64",
|
|
21
|
+
"@graphcommerce/magento-search": "^9.0.0-canary.64",
|
|
22
|
+
"@graphcommerce/next-config": "^9.0.0-canary.64",
|
|
23
|
+
"@graphcommerce/next-ui": "^9.0.0-canary.64"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"graphql": "^16.0.0",
|
|
27
|
+
"tsx": "^4.16.2"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { meshConfig as meshConfigBase } from '@graphcommerce/graphql-mesh/meshConfig'
|
|
2
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
|
|
4
|
+
export const config: PluginConfig = {
|
|
5
|
+
module: '@graphcommerce/graphql-mesh/meshConfig',
|
|
6
|
+
type: 'function',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const meshConfig: FunctionPlugin<typeof meshConfigBase> = (
|
|
10
|
+
prev,
|
|
11
|
+
baseConfig,
|
|
12
|
+
graphCommerceConfig,
|
|
13
|
+
) => {
|
|
14
|
+
const restEndpoint = `${graphCommerceConfig.magentoEndpoint.slice(0, -7)}rest/{context.headers.store}`
|
|
15
|
+
return prev(
|
|
16
|
+
{
|
|
17
|
+
...baseConfig,
|
|
18
|
+
sources: [
|
|
19
|
+
...baseConfig.sources,
|
|
20
|
+
{
|
|
21
|
+
name: 'm2rest',
|
|
22
|
+
handler: {
|
|
23
|
+
openapi: {
|
|
24
|
+
source: '@graphcommerce/magento-graphql-rest/m2-filtered-spec.json',
|
|
25
|
+
operationHeaders: {
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
Authorization: '{context.headers.authorization}',
|
|
28
|
+
},
|
|
29
|
+
endpoint: restEndpoint,
|
|
30
|
+
ignoreErrorResponses: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
transforms: [
|
|
34
|
+
{
|
|
35
|
+
prefix: {
|
|
36
|
+
value: 'm2rest_',
|
|
37
|
+
includeRootOperations: true,
|
|
38
|
+
includeTypes: false,
|
|
39
|
+
mode: 'bare',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
prefix: {
|
|
44
|
+
value: 'M2Rest_',
|
|
45
|
+
includeRootOperations: false,
|
|
46
|
+
includeTypes: true,
|
|
47
|
+
mode: 'bare',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
namingConvention: {
|
|
52
|
+
enumValues: 'constantCase',
|
|
53
|
+
typeNames: 'pascalCase',
|
|
54
|
+
mode: 'bare',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
graphCommerceConfig,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import yaml from 'js-yaml'
|
|
2
|
+
import { writeFile, readFile } from 'node:fs/promises'
|
|
3
|
+
import { OpenAPIV3 } from 'openapi-types'
|
|
4
|
+
import prettier from 'prettier'
|
|
5
|
+
import conf from '@graphcommerce/prettier-config-pwa'
|
|
6
|
+
|
|
7
|
+
function isRef(value: any): value is OpenAPIV3.ReferenceObject {
|
|
8
|
+
return typeof value === 'object' && '$ref' in value
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const response = await readFile('./scripts/m2rest-admin.json')
|
|
12
|
+
|
|
13
|
+
const allMethods = [
|
|
14
|
+
OpenAPIV3.HttpMethods.TRACE,
|
|
15
|
+
OpenAPIV3.HttpMethods.POST,
|
|
16
|
+
OpenAPIV3.HttpMethods.PUT,
|
|
17
|
+
OpenAPIV3.HttpMethods.GET,
|
|
18
|
+
OpenAPIV3.HttpMethods.DELETE,
|
|
19
|
+
OpenAPIV3.HttpMethods.PATCH,
|
|
20
|
+
OpenAPIV3.HttpMethods.OPTIONS,
|
|
21
|
+
OpenAPIV3.HttpMethods.HEAD,
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
const openApiSchema = JSON.parse(response.toString()) as OpenAPIV3.Document
|
|
25
|
+
|
|
26
|
+
const { info, openapi, components, tags, ...rest } = openApiSchema
|
|
27
|
+
|
|
28
|
+
function filterPaths(
|
|
29
|
+
paths: OpenAPIV3.PathsObject,
|
|
30
|
+
allow: Record<string, OpenAPIV3.HttpMethods[]>,
|
|
31
|
+
): OpenAPIV3.PathsObject {
|
|
32
|
+
const allowedEntries = Object.entries(allow)
|
|
33
|
+
|
|
34
|
+
return Object.fromEntries(
|
|
35
|
+
Object.entries(paths)
|
|
36
|
+
.map(([path, pathItem]) => {
|
|
37
|
+
if (!pathItem) return [path, pathItem]
|
|
38
|
+
const newValue = pathItem
|
|
39
|
+
|
|
40
|
+
const [allowedPath, allowedMethods] =
|
|
41
|
+
allowedEntries.find(([allowedPath]) => allowedPath === path) ?? []
|
|
42
|
+
|
|
43
|
+
if (!allowedPath || !allowedMethods) return [path, undefined]
|
|
44
|
+
|
|
45
|
+
allMethods
|
|
46
|
+
.filter((method) => !allowedMethods.includes(method))
|
|
47
|
+
.forEach((method) => {
|
|
48
|
+
newValue[method] = undefined
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return [path, newValue]
|
|
52
|
+
})
|
|
53
|
+
.filter(([path, pathItem]) => {
|
|
54
|
+
if (!pathItem) return false
|
|
55
|
+
if (allMethods.every((key) => !pathItem[key])) return false
|
|
56
|
+
return true
|
|
57
|
+
}),
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const newSchema: OpenAPIV3.Document = {
|
|
62
|
+
openapi,
|
|
63
|
+
info,
|
|
64
|
+
paths: filterPaths(openApiSchema.paths, { '/V1/customers/me': [OpenAPIV3.HttpMethods.GET] }),
|
|
65
|
+
components,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await writeFile(
|
|
69
|
+
'./m2-filtered-spec.json',
|
|
70
|
+
await prettier.format(JSON.stringify(newSchema), {
|
|
71
|
+
parser: 'json',
|
|
72
|
+
...conf,
|
|
73
|
+
}),
|
|
74
|
+
)
|