@graphcommerce/algolia-personalization 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 +39 -0
- package/README.md +3 -0
- package/index.ts +1 -0
- package/mesh/getUserToken.ts +12 -0
- package/package.json +33 -0
- package/plugins/InContextInputAlgoliaUserToken.ts +31 -0
- package/plugins/getSearchResultsInputPersonalization.ts +18 -0
- package/plugins/getSearchSuggestionsInputPersonalization.ts +16 -0
- package/schema/InContext_algoliaUserToken.graphqls +3 -0
- package/tsconfig.json +5 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @graphcommerce/algolia-personalization
|
|
2
|
+
|
|
3
|
+
## 9.0.0-canary.100
|
|
4
|
+
|
|
5
|
+
## 9.0.0-canary.99
|
|
6
|
+
|
|
7
|
+
## 9.0.0-canary.98
|
|
8
|
+
|
|
9
|
+
## 9.0.0-canary.97
|
|
10
|
+
|
|
11
|
+
## 9.0.0-canary.96
|
|
12
|
+
|
|
13
|
+
## 9.0.0-canary.95
|
|
14
|
+
|
|
15
|
+
## 9.0.0-canary.94
|
|
16
|
+
|
|
17
|
+
## 9.0.0-canary.93
|
|
18
|
+
|
|
19
|
+
## 9.0.0-canary.92
|
|
20
|
+
|
|
21
|
+
## 9.0.0-canary.91
|
|
22
|
+
|
|
23
|
+
## 9.0.0-canary.90
|
|
24
|
+
|
|
25
|
+
## 9.0.0-canary.89
|
|
26
|
+
|
|
27
|
+
## 9.0.0-canary.88
|
|
28
|
+
|
|
29
|
+
## 9.0.0-canary.87
|
|
30
|
+
|
|
31
|
+
## 9.0.0-canary.86
|
|
32
|
+
|
|
33
|
+
## 9.0.0-canary.85
|
|
34
|
+
|
|
35
|
+
## 9.0.0-canary.84
|
|
36
|
+
|
|
37
|
+
### Minor Changes
|
|
38
|
+
|
|
39
|
+
- [#2377](https://github.com/graphcommerce-org/graphcommerce/pull/2377) [`56fcc45`](https://github.com/graphcommerce-org/graphcommerce/commit/56fcc45b60e43574c64fcdd7b02f8062d677e250) - Integrated algolia personalisation and algolia analytics into graphql mesh. Built user profiles and gives user personalised results. Keep track of the user data and view in algolia analytics dashboard ([@Renzovh](https://github.com/Renzovh))
|
package/README.md
ADDED
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mesh/getUserToken'
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MeshContext } from '@graphcommerce/graphql-mesh'
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import { parse } from 'cookie'
|
|
4
|
+
|
|
5
|
+
const ALGOLIA_USER_TOKEN_COOKIE_NAME = '_algolia_userToken'
|
|
6
|
+
export function getUserToken(context: MeshContext): string | undefined {
|
|
7
|
+
const { headers } = context as MeshContext & { headers?: Record<string, string | undefined> }
|
|
8
|
+
|
|
9
|
+
const cookie = headers?.cookie
|
|
10
|
+
if (cookie) return parse(cookie)[ALGOLIA_USER_TOKEN_COOKIE_NAME]
|
|
11
|
+
return undefined
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphcommerce/algolia-personalization",
|
|
3
|
+
"homepage": "https://www.graphcommerce.org/",
|
|
4
|
+
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
+
"version": "9.0.0-canary.100",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
|
+
"eslintConfig": {
|
|
9
|
+
"extends": "@graphcommerce/eslint-config-pwa",
|
|
10
|
+
"parserOptions": {
|
|
11
|
+
"project": "./tsconfig.json"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"generate": "tsx scripts/generate-insights-spec.mts"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@graphcommerce/algolia-insights": "^9.0.0-canary.100",
|
|
19
|
+
"@graphcommerce/algolia-products": "^9.0.0-canary.100",
|
|
20
|
+
"@graphcommerce/google-datalayer": "^9.0.0-canary.100",
|
|
21
|
+
"@graphcommerce/graphql": "^9.0.0-canary.100",
|
|
22
|
+
"@graphcommerce/graphql-mesh": "^9.0.0-canary.100",
|
|
23
|
+
"@graphcommerce/magento-customer": "^9.0.0-canary.100",
|
|
24
|
+
"@graphcommerce/magento-product": "^9.0.0-canary.100",
|
|
25
|
+
"@graphcommerce/next-config": "^9.0.0-canary.100",
|
|
26
|
+
"@graphcommerce/next-ui": "^9.0.0-canary.100",
|
|
27
|
+
"react": "^18.2.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"graphql": "^16.0.0",
|
|
31
|
+
"tsx": "^4.16.2"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ALGOLIA_USER_TOKEN_COOKIE_NAME } from '@graphcommerce/algolia-insights'
|
|
2
|
+
import {
|
|
3
|
+
type getInContextInput as getInContextInputType,
|
|
4
|
+
type useInContextInput as useInContextInputType,
|
|
5
|
+
} from '@graphcommerce/graphql'
|
|
6
|
+
import type { InContextInput } from '@graphcommerce/graphql-mesh'
|
|
7
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
8
|
+
import { cookie } from '@graphcommerce/next-ui'
|
|
9
|
+
|
|
10
|
+
export const config: PluginConfig = {
|
|
11
|
+
type: 'function',
|
|
12
|
+
module: '@graphcommerce/graphql',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const getInContextInput: FunctionPlugin<typeof getInContextInputType> = (
|
|
16
|
+
prev,
|
|
17
|
+
client,
|
|
18
|
+
...args
|
|
19
|
+
) => {
|
|
20
|
+
const algoliaUserToken = cookie(ALGOLIA_USER_TOKEN_COOKIE_NAME)
|
|
21
|
+
const res = prev(client, ...args)
|
|
22
|
+
if (!algoliaUserToken) return res
|
|
23
|
+
return { ...res, algoliaUserToken } satisfies InContextInput
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const useInContextInput: FunctionPlugin<typeof useInContextInputType> = (prev, ...args) => {
|
|
27
|
+
const algoliaUserToken = cookie(ALGOLIA_USER_TOKEN_COOKIE_NAME)
|
|
28
|
+
const res = prev(...args)
|
|
29
|
+
if (!algoliaUserToken) return res
|
|
30
|
+
return { ...res, algoliaUserToken }
|
|
31
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { getSearchResultsInput as getSearchResultsInputType } from '@graphcommerce/algolia-products'
|
|
2
|
+
import { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
import { getUserToken } from '../mesh/getUserToken'
|
|
4
|
+
|
|
5
|
+
export const config: PluginConfig = {
|
|
6
|
+
type: 'function',
|
|
7
|
+
module: '@graphcommerce/algolia-products',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getSearchResultsInput: FunctionPlugin<typeof getSearchResultsInputType> = async (
|
|
11
|
+
prev,
|
|
12
|
+
args,
|
|
13
|
+
context,
|
|
14
|
+
) => ({
|
|
15
|
+
...(await prev(args, context)),
|
|
16
|
+
clickAnalytics: true,
|
|
17
|
+
userToken: getUserToken(context),
|
|
18
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { getSearchSuggestionsInput as getSearchSuggestionsInputType } from '@graphcommerce/algolia-products'
|
|
2
|
+
import { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
import { getUserToken } from '../mesh/getUserToken'
|
|
4
|
+
|
|
5
|
+
export const config: PluginConfig = {
|
|
6
|
+
type: 'function',
|
|
7
|
+
module: '@graphcommerce/algolia-products',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getSearchSuggestionsInput: FunctionPlugin<
|
|
11
|
+
typeof getSearchSuggestionsInputType
|
|
12
|
+
> = async (prev, search, context) => ({
|
|
13
|
+
...(await prev(search, context)),
|
|
14
|
+
clickAnalytics: true,
|
|
15
|
+
userToken: getUserToken(context),
|
|
16
|
+
})
|