@graphcommerce/algolia-products 9.0.0-canary.100
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 +105 -0
- package/Config.graphqls +54 -0
- package/README.md +79 -0
- package/algolia-spec.yaml +4418 -0
- package/graphql/CustomerGroupId.graphql +3 -0
- package/graphql/GetAlgoliaSettings.graphql +122 -0
- package/graphql/ProductListItems_Algolia.graphql +3 -0
- package/hooks/useAlgoliaIndexName.ts +5 -0
- package/hooks/useAlgoliaQueryContext.ts +11 -0
- package/index.ts +8 -0
- package/link/customerGroupIdLink.ts +20 -0
- package/mesh/algoliaFacetsToAggregations.ts +209 -0
- package/mesh/algoliaHitToMagentoProduct.ts +201 -0
- package/mesh/getAlgoliaSettings.ts +21 -0
- package/mesh/getAttributeList.ts +31 -0
- package/mesh/getGroupId.ts +7 -0
- package/mesh/getIndexName.ts +11 -0
- package/mesh/getSearchResults.ts +35 -0
- package/mesh/getSearchResultsInput.ts +30 -0
- package/mesh/getSearchSuggestions.ts +27 -0
- package/mesh/getSearchSuggestionsInput.ts +21 -0
- package/mesh/getStoreConfig.ts +33 -0
- package/mesh/productFilterInputToAlgoliafacetFiltersInput.ts +81 -0
- package/mesh/resolvers.ts +126 -0
- package/mesh/sortOptions.ts +76 -0
- package/mesh/utils.ts +3 -0
- package/next-env.d.ts +4 -0
- package/package.json +32 -0
- package/plugins/GraphQLProviderAlgoliaCustomerGroupId.tsx +14 -0
- package/plugins/ProductListItemsBaseAlgolia.tsx +21 -0
- package/plugins/magentoProductApplyAlgoliaEngine.ts +25 -0
- package/plugins/magentoSearchApplyAlgoliaEngine.ts +26 -0
- package/plugins/meshConfigAlgolia.ts +66 -0
- package/schema/AlgoliaSchema.graphqls +60 -0
- package/schema/CustomerAlgoliaGroupId.graphqls +9 -0
- package/scripts/base-schema-filter.mts +45 -0
- package/scripts/generate-spec.mts +69 -0
- package/tsconfig.json +5 -0
- package/utils/applyCategoryEngineVariable.ts +11 -0
- package/utils/applyEngineVariable.ts +11 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from 'openapi-types'
|
|
2
|
+
|
|
3
|
+
function isRef(value: any): value is OpenAPIV3.ReferenceObject {
|
|
4
|
+
return typeof value === 'object' && '$ref' in value
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function algoliaSchemaBaseFilter(
|
|
8
|
+
schemaKey: string,
|
|
9
|
+
schema: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject,
|
|
10
|
+
): [string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject] {
|
|
11
|
+
if (isRef(schema)) return [schemaKey, schema]
|
|
12
|
+
|
|
13
|
+
if (
|
|
14
|
+
schema.oneOf &&
|
|
15
|
+
schema.oneOf[0]?.['$ref'] === '#/components/schemas/searchParamsString' &&
|
|
16
|
+
schema.oneOf[1]?.['$ref'] === '#/components/schemas/searchParamsObject'
|
|
17
|
+
) {
|
|
18
|
+
return [schemaKey, { $ref: '#/components/schemas/searchParamsObject' }]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (schemaKey === 'facetFilters') {
|
|
22
|
+
return [schemaKey, { ...schema, example: undefined, oneOf: undefined, type: 'object' }]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return [
|
|
26
|
+
schemaKey,
|
|
27
|
+
{
|
|
28
|
+
...schema,
|
|
29
|
+
default: undefined,
|
|
30
|
+
properties: schema.properties
|
|
31
|
+
? Object.fromEntries(
|
|
32
|
+
Object.entries(schema.properties).map(([propertyKey, property]) => {
|
|
33
|
+
if (isRef(property)) return [propertyKey, property]
|
|
34
|
+
|
|
35
|
+
if (propertyKey === 'customNormalization' || propertyKey === 'facets') {
|
|
36
|
+
return [propertyKey, { ...property, example: undefined }]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return [propertyKey, { ...property, default: undefined }]
|
|
40
|
+
}),
|
|
41
|
+
)
|
|
42
|
+
: undefined,
|
|
43
|
+
},
|
|
44
|
+
]
|
|
45
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import yaml from 'js-yaml'
|
|
2
|
+
import { writeFile } from 'node:fs/promises'
|
|
3
|
+
import type { OpenAPIV3 } from 'openapi-types'
|
|
4
|
+
import prettier from 'prettier'
|
|
5
|
+
import conf from '@graphcommerce/prettier-config-pwa'
|
|
6
|
+
import { algoliaSchemaBaseFilter } from './base-schema-filter.mjs'
|
|
7
|
+
|
|
8
|
+
const response = await fetch(
|
|
9
|
+
'https://raw.githubusercontent.com/algolia/api-clients-automation/main/specs/bundled/search.yml',
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
const openApiSchema = yaml.load(await response.text()) as OpenAPIV3.Document
|
|
13
|
+
|
|
14
|
+
const acl = ['search']
|
|
15
|
+
|
|
16
|
+
const newSchema: OpenAPIV3.Document = {
|
|
17
|
+
...openApiSchema,
|
|
18
|
+
components: {
|
|
19
|
+
...openApiSchema.components,
|
|
20
|
+
schemas: Object.fromEntries(
|
|
21
|
+
Object.entries(openApiSchema.components?.schemas ?? {}).map(([schemaKey, schema]) => {
|
|
22
|
+
return algoliaSchemaBaseFilter(schemaKey, schema)
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
},
|
|
26
|
+
paths: {
|
|
27
|
+
...Object.fromEntries(
|
|
28
|
+
Object.entries(openApiSchema.paths)
|
|
29
|
+
.map(([path, pathItem]) => {
|
|
30
|
+
if (!pathItem) return [path, pathItem]
|
|
31
|
+
const newValue = pathItem
|
|
32
|
+
|
|
33
|
+
const keys = ['post', 'get', 'put', 'delete', 'patch', 'options'] as const
|
|
34
|
+
|
|
35
|
+
keys.forEach((method) => {
|
|
36
|
+
if (!newValue[method]?.['x-acl']?.some((value: string) => acl.includes(value))) {
|
|
37
|
+
newValue[method] = undefined
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return [path, pathItem]
|
|
42
|
+
})
|
|
43
|
+
.filter(([path, pathItem]) => {
|
|
44
|
+
if (!pathItem) return
|
|
45
|
+
|
|
46
|
+
// Remove the search endpoint + remove the getObjects endpoint.
|
|
47
|
+
if (
|
|
48
|
+
path === '/1/indexes/*/queries' ||
|
|
49
|
+
path === '/1/indexes/*/objects' ||
|
|
50
|
+
path === '/1/indexes/{indexName}/{objectID}'
|
|
51
|
+
)
|
|
52
|
+
return false
|
|
53
|
+
|
|
54
|
+
const keys = ['post', 'get', 'put', 'delete', 'patch', 'options'] as const
|
|
55
|
+
if (keys.every((key) => !pathItem[key])) return false
|
|
56
|
+
|
|
57
|
+
return true
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await writeFile(
|
|
64
|
+
'./algolia-spec.yaml',
|
|
65
|
+
await prettier.format(yaml.dump(newSchema), {
|
|
66
|
+
parser: 'yaml',
|
|
67
|
+
...conf,
|
|
68
|
+
}),
|
|
69
|
+
)
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProductListQueryVariables } from '@graphcommerce/magento-product'
|
|
2
|
+
|
|
3
|
+
export function applyEngineVariables(variables: ProductListQueryVariables | undefined) {
|
|
4
|
+
return {
|
|
5
|
+
...variables,
|
|
6
|
+
filters: {
|
|
7
|
+
...variables?.filters,
|
|
8
|
+
engine: { eq: 'algolia' },
|
|
9
|
+
},
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProductListQueryVariables } from '@graphcommerce/magento-product'
|
|
2
|
+
|
|
3
|
+
export function applyEngineVariables(variables: ProductListQueryVariables | undefined) {
|
|
4
|
+
return {
|
|
5
|
+
...variables,
|
|
6
|
+
filters: {
|
|
7
|
+
...variables?.filters,
|
|
8
|
+
engine: { eq: 'algolia' },
|
|
9
|
+
},
|
|
10
|
+
}
|
|
11
|
+
}
|