-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat(clients): add new realtime-personalization api #4613
Open
benamib
wants to merge
16
commits into
main
Choose a base branch
from
PRED-3652/realtime-perso-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−15
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
75fdf13
feat(realtime-perso): add new realtime-perso api
8828aa5
update api url and path
3dfbf35
Merge remote-tracking branch 'origin/main' into PRED-3652/realtime-pe…
2526e89
update path and schemas
8ee8999
update clients config
dedef01
Merge remote-tracking branch 'origin/main' into PRED-3652/realtime-pe…
ca169fe
Merge remote-tracking branch 'origin/main' into PRED-3652/realtime-pe…
283ce30
try without additionalPropoerties
a2965f7
rollback change
e54f457
Merge branch 'main' into PRED-3652/realtime-perso-api
benamib 0d9a3c8
fix: go
shortcuts 9d48a55
chore: playground and javascript
shortcuts af4f5ea
chore: go cts
shortcuts 2b5bc83
chore: add a test
shortcuts 533cf7b
chore: dart
shortcuts 16c351d
chore: client tests
shortcuts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
clients/algoliasearch-client-dart/packages/client_composition/lib/src/extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
14 changes: 14 additions & 0 deletions
14
clients/algoliasearch-client-dart/packages/client_realtime_personalization/build.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
...algoliasearch-client-dart/packages/client_realtime_personalization/lib/src/extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
strategy: | ||
type: string | ||
enum: | ||
- session | ||
- hybrid | ||
example: 'session' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
schema: | ||
$ref: '../../common/schemas/SearchParams.yml#/userToken' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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>'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
get: | ||
tags: | ||
- users | ||
operationId: getUser | ||
x-acl: | ||
- recommendation | ||
summary: Retrieve the user's personalization profile | ||
description: Retrieves the user's personalization profiles containing search filters. | ||
parameters: | ||
- $ref: '../common/parameters.yml#/UserToken' | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../common/schemas/user.yml#/user' | ||
'400': | ||
$ref: '../../common/responses/BadRequest.yml' | ||
'402': | ||
$ref: '../../common/responses/FeatureNotEnabled.yml' | ||
'403': | ||
$ref: '../../common/responses/MethodNotAllowed.yml' | ||
'404': | ||
$ref: '../../common/responses/IndexNotFound.yml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
openapi: 3.0.2 | ||
info: | ||
title: Realtime Personalization API | ||
description: TODO | ||
version: 0.0.1 | ||
externalDocs: | ||
# TODO: Update the URL | ||
url: https://www.algolia.com/doc/guides/personalization/what-is-personalization/ | ||
description: | | ||
Related guide: Algolia Realtime Personalization. | ||
components: | ||
securitySchemes: | ||
appId: | ||
$ref: '../common/securitySchemes.yml#/appId' | ||
apiKey: | ||
$ref: '../common/securitySchemes.yml#/apiKey' | ||
servers: | ||
- url: https://ai-personalization.{region}.algolia.com | ||
benamib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
variables: | ||
region: | ||
description: | | ||
Use the URL that matches your [analytics region](https://dashboard.algolia.com/account/infrastructure/analytics). | ||
enum: [eu, us] | ||
default: eu | ||
security: | ||
- appId: [] | ||
apiKey: [] | ||
benamib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tags: | ||
- name: users | ||
x-displayName: Users | ||
description: | | ||
User profiles contains the search filters each user has for the different facets in your index. | ||
x-tagGroups: | ||
- name: General | ||
tags: | ||
- filters | ||
paths: | ||
# ###################### | ||
# ### Custom request ### | ||
# ###################### | ||
/{path}: | ||
$ref: '../common/paths/customRequest.yml' | ||
|
||
/2/realtime/users/{userToken}: | ||
$ref: 'paths/getUser.yml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[ | ||
{ | ||
"testName": "throws when region is not given", | ||
"autoCreateClient": false, | ||
"steps": [ | ||
{ | ||
"type": "createClient", | ||
"parameters": { | ||
"appId": "my-app-id", | ||
"apiKey": "my-api-key", | ||
"region": "" | ||
}, | ||
"expected": { | ||
"error": "`region` is required and must be one of the following: eu, us" | ||
} | ||
} | ||
] | ||
} | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this allow us to store search configurations for multiple groups of indices, and have a dynamic name?
Example extracted from Francois' presentation:

Not sure how we represent that in the spec though.
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.
The attribute
additionalProperties
allows us to tell the generator that the key of the object can be dynamic but that the format of the value should be of typesearchFilters
.I'm not fond of this method but we don't have too much choice to respect the response we want.
We could still challenge the response format to replace the objects by arrays which would make the specs clearer imo like:
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.
With the current specs the generated exemples looks like this :
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.
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