-
Notifications
You must be signed in to change notification settings - Fork 20
feat(clients): add new realtime-personalization api #4613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
75fdf13
8828aa5
3dfbf35
2526e89
8ee8999
dedef01
ca169fe
283ce30
a2965f7
e54f457
0d9a3c8
9d48a55
af4f5ea
2b5bc83
533cf7b
16c351d
d84057a
b355500
ee86911
043b672
9d643d6
4f7426b
7ec3c20
efac20c
d9c9219
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
targets: | ||
$default: | ||
builders: | ||
json_serializable: | ||
options: | ||
any_map: false | ||
checked: true | ||
create_factory: true | ||
create_to_json: true | ||
disallow_unrecognized_keys: false | ||
explicit_to_json: true | ||
field_rename: none | ||
ignore_unannotated: false | ||
include_if_null: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"version": "0.0.1-alpha.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/algolia/algoliasearch-client-javascript.git" | ||
}, | ||
"homepage": "https://github.com/algolia/algoliasearch-client-javascript/packages/client-realtime-personalization#readme", | ||
"type": "module", | ||
"license": "MIT", | ||
"author": "Algolia", | ||
"scripts": { | ||
"build": "yarn clean && yarn tsup && yarn rollup -c rollup.config.js", | ||
"clean": "rm -rf ./dist || true", | ||
"test:bundle": "publint . && attw --pack ." | ||
}, | ||
"name": "@algolia/client-realtime-personalization", | ||
"description": "JavaScript client for client-realtime-personalization", | ||
"exports": { | ||
".": { | ||
"node": { | ||
"types": { | ||
"import": "./dist/node.d.ts", | ||
"module": "./dist/node.d.ts", | ||
"require": "./dist/node.d.cts" | ||
}, | ||
"import": "./dist/builds/node.js", | ||
"module": "./dist/builds/node.js", | ||
"require": "./dist/builds/node.cjs" | ||
}, | ||
"worker": { | ||
"types": "./dist/worker.d.ts", | ||
"default": "./dist/builds/worker.js" | ||
}, | ||
"default": { | ||
"types": "./dist/browser.d.ts", | ||
"module": "./dist/builds/browser.js", | ||
"import": "./dist/builds/browser.js", | ||
"default": "./dist/builds/browser.umd.js" | ||
} | ||
}, | ||
"./dist/builds/*": "./dist/builds/*.js" | ||
}, | ||
"jsdelivr": "./dist/builds/browser.umd.js", | ||
"unpkg": "./dist/builds/browser.umd.js", | ||
"react-native": "./dist/builds/browser.js", | ||
"files": [ | ||
"dist", | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"dependencies": { | ||
"@algolia/client-common": "5.22.0", | ||
"@algolia/requester-browser-xhr": "5.22.0", | ||
"@algolia/requester-fetch": "5.22.0", | ||
"@algolia/requester-node-http": "5.22.0" | ||
}, | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "0.17.4", | ||
"@types/node": "22.13.11", | ||
"publint": "0.3.9", | ||
"rollup": "4.36.0", | ||
"tsup": "8.4.0", | ||
"typescript": "5.7.3" | ||
}, | ||
"engines": { | ||
"node": ">= 14.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ApiError } from '@algolia/client-common'; | ||
import { realtimePersonalizationClient } from '@algolia/client-realtime-personalization'; | ||
|
||
const appId = process.env.METIS_APPLICATION_ID || '**** APP_ID *****'; | ||
const apiKey = process.env.METIS_API_KEY || '**** ADMIN_KEY *****'; | ||
|
||
// Init client with appId and apiKey | ||
const client = realtimePersonalizationClient(appId, apiKey, 'us'); | ||
|
||
async function testRealtimePersonalization() { | ||
try { | ||
console.log(appId, apiKey); | ||
|
||
const resp = await client.getUser({userToken: "foo"}); | ||
|
||
console.log(resp); | ||
|
||
} catch (e) { | ||
if (e instanceof ApiError) { | ||
return console.log(`[${e.status}] ${e.message}`, e.stackTrace, e); | ||
} | ||
|
||
console.log('[ERROR]', e); | ||
} | ||
} | ||
|
||
testRealtimePersonalization(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
strategy: | ||
type: string | ||
enum: | ||
- session | ||
- hybrid | ||
example: 'session' |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||
# path | ||||||
UserToken: | ||||||
name: userToken | ||||||
in: path | ||||||
required: true | ||||||
description: Unique identifier representing a user for which to fetch the personalization profile. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
schema: | ||||||
$ref: '../../common/schemas/SearchParams.yml#/userToken' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
user: | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- version | ||
- userID | ||
- search | ||
properties: | ||
version: | ||
type: string | ||
description: Version of the response format. | ||
userID: | ||
type: string | ||
description: User ID of the user. | ||
search: | ||
type: object | ||
description: | | ||
Index personalization filters by index name. | ||
additionalProperties: | ||
$ref: '#/searchFilters' | ||
|
||
searchFilters: | ||
type: object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The attribute I'm not fond of this method but we don't have too much choice to respect the response we want. ...
"search": [
{ "aliases": "abc", "strategy": "def", "filters": {...} }
]
... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the current specs the generated exemples looks like this : {
"version": "string",
"userID": "string",
"search": {
"additionalProp1": {
"indices": [
"storefront",
"storefront_price_asc",
"storefront_price_desc"
],
"strategy": "session",
"filters": {
"session": [
"brand:Dyson<score=12>"
],
"additionalProp1": {}
},
"additionalProp1": {}
},
"additionalProp2": {
"indices": [
"storefront",
"storefront_price_asc",
"storefront_price_desc"
],
"strategy": "session",
"filters": {
"session": [
"brand:Dyson<score=12>"
],
"additionalProp1": {}
},
"additionalProp1": {}
},
"additionalProp3": {
"indices": [
"storefront",
"storefront_price_asc",
"storefront_price_desc"
],
"strategy": "session",
"filters": {
"session": [
"brand:Dyson<score=12>"
],
"additionalProp1": {}
},
"additionalProp1": {}
}
},
"additionalProp1": {}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the reason for this structure was so that the FE could retrieve the required attributes as quick as possible (it's more time consuming to filter an array based on a key than it is to get a specific key from a map). This looks good for now, but if it causes issues we can rethink it |
||
additionalProperties: false | ||
properties: | ||
indices: | ||
type: array | ||
items: | ||
type: string | ||
example: ['storefront', 'storefront_price_asc', 'storefront_price_desc'] | ||
strategy: | ||
$ref: '../enums.yml#/strategy' | ||
filters: | ||
$ref: '#/searchFilter' | ||
|
||
searchFilter: | ||
type: object | ||
additionalProperties: false | ||
properties: | ||
session: | ||
type: array | ||
items: | ||
type: string | ||
example: ['brand:Dyson<score=12>'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call this
userID
in all the personalization APIs.