-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Add Insights client specs + javascript insights client #62
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b34adb2
feat: add Insight client specs + insights client for javascript
damcou bb064ee
feat: add test for insights client
damcou 4fe14e3
Merge branch 'main' into feat/APIC-205/insights-client
damcou 42a0dfd
fix: regenerate
damcou 9240fb6
fix: update typescript version
damcou 4692fbf
fix: yarn.lock
damcou a06227d
fix: update CI
damcou e79023c
fix: CI
damcou 568c353
Merge branch 'main' into feat/APIC-205/insights-client
damcou 810175d
merge main, update github actions
shortcuts 4c78394
add insights jobs
shortcuts 9e757b0
retrieve outputs variable
shortcuts 39eebf2
fix: last comments
damcou 2a66968
Merge branch 'main' into feat/APIC-205/insights-client
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
This file contains hidden or 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
4 changes: 4 additions & 0 deletions
4
clients/algoliasearch-client-javascript/client-insights/.gitignore
This file contains hidden or 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,4 @@ | ||
node_modules | ||
dist | ||
.openapi-generator | ||
.env |
23 changes: 23 additions & 0 deletions
23
clients/algoliasearch-client-javascript/client-insights/.openapi-generator-ignore
This file contains hidden or 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,23 @@ | ||
# OpenAPI Generator Ignore | ||
damcou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
3 changes: 3 additions & 0 deletions
3
clients/algoliasearch-client-javascript/client-insights/api.ts
This file contains hidden or 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,3 @@ | ||
// This is the entrypoint for the package | ||
export * from './src/apis'; | ||
export * from './model/models'; |
57 changes: 57 additions & 0 deletions
57
clients/algoliasearch-client-javascript/client-insights/git_push.sh
This file contains hidden or 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,57 @@ | ||
#!/bin/sh | ||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ | ||
# | ||
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" | ||
|
||
git_user_id=$1 | ||
git_repo_id=$2 | ||
release_note=$3 | ||
git_host=$4 | ||
|
||
if [ "$git_host" = "" ]; then | ||
git_host="algolia" | ||
echo "[INFO] No command line input provided. Set \$git_host to $git_host" | ||
fi | ||
|
||
if [ "$git_user_id" = "" ]; then | ||
git_user_id="algolia" | ||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" | ||
fi | ||
|
||
if [ "$git_repo_id" = "" ]; then | ||
git_repo_id="algoliasearch-client-javascript" | ||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" | ||
fi | ||
|
||
if [ "$release_note" = "" ]; then | ||
release_note="Minor update" | ||
echo "[INFO] No command line input provided. Set \$release_note to $release_note" | ||
fi | ||
|
||
# Initialize the local directory as a Git repository | ||
git init | ||
|
||
# Adds the files in the local repository and stages them for commit. | ||
git add . | ||
|
||
# Commits the tracked changes and prepares them to be pushed to a remote repository. | ||
git commit -m "$release_note" | ||
|
||
# Sets the new remote | ||
git_remote=$(git remote) | ||
if [ "$git_remote" = "" ]; then # git remote not defined | ||
|
||
if [ "$GIT_TOKEN" = "" ]; then | ||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." | ||
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git | ||
else | ||
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git | ||
fi | ||
|
||
fi | ||
|
||
git pull origin master | ||
|
||
# Pushes (Forces) the changes in the local repository up to the remote repository | ||
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" | ||
git push origin master 2>&1 | grep -v 'To https' |
6 changes: 6 additions & 0 deletions
6
clients/algoliasearch-client-javascript/client-insights/model/errorBase.ts
This file contains hidden or 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 @@ | ||
/** | ||
* Error. | ||
*/ | ||
export type ErrorBase = { | ||
message?: string; | ||
}; |
49 changes: 49 additions & 0 deletions
49
clients/algoliasearch-client-javascript/client-insights/model/insightEvent.ts
This file contains hidden or 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,49 @@ | ||
/** | ||
* Insights event. | ||
*/ | ||
export type InsightEvent = { | ||
/** | ||
* An eventType can be a click, a conversion, or a view. | ||
*/ | ||
eventType: InsightEvent.EventTypeEnum; | ||
/** | ||
* A user-defined string used to categorize events. | ||
*/ | ||
eventName: string; | ||
/** | ||
* Name of the targeted index. | ||
*/ | ||
index: string; | ||
/** | ||
* A user identifier. Depending if the user is logged-in or not, several strategies can be used from a sessionId to a technical identifier. | ||
*/ | ||
userToken: string; | ||
/** | ||
* Time of the event expressed in milliseconds since the Unix epoch. | ||
*/ | ||
timestamp?: number; | ||
/** | ||
* Algolia queryID. This is required when an event is tied to a search. | ||
*/ | ||
queryID?: string; | ||
/** | ||
* An array of index objectID. Limited to 20 objects. An event can’t have both objectIDs and filters at the same time. | ||
*/ | ||
objectIDs?: string[]; | ||
/** | ||
* An array of filters. Limited to 10 filters. An event can’t have both objectIDs and filters at the same time. | ||
*/ | ||
filters?: string[]; | ||
/** | ||
* Position of the click in the list of Algolia search results. This field is required if a queryID is provided. One position must be provided for each objectID. | ||
*/ | ||
positions?: number[]; | ||
}; | ||
|
||
export namespace InsightEvent { | ||
export enum EventTypeEnum { | ||
Click = 'click', | ||
Conversion = 'conversion', | ||
View = 'view', | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
clients/algoliasearch-client-javascript/client-insights/model/insightEvents.ts
This file contains hidden or 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,11 @@ | ||
import type { InsightEvent } from './insightEvent'; | ||
|
||
/** | ||
* Object containing the events sent to the Insights API. | ||
*/ | ||
export type InsightEvents = { | ||
/** | ||
* Array of events sent to the Insights API. | ||
*/ | ||
events: InsightEvent[]; | ||
}; |
46 changes: 46 additions & 0 deletions
46
clients/algoliasearch-client-javascript/client-insights/model/models.ts
This file contains hidden or 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,46 @@ | ||
/* eslint-disable no-param-reassign */ | ||
import type { RequestOptions } from '../utils/types'; | ||
|
||
export * from './errorBase'; | ||
export * from './insightEvent'; | ||
export * from './insightEvents'; | ||
export * from './pushEventsResponse'; | ||
|
||
export interface Authentication { | ||
/** | ||
* Apply authentication settings to header and query params. | ||
*/ | ||
applyToRequest: (requestOptions: RequestOptions) => Promise<void> | void; | ||
} | ||
|
||
export class ApiKeyAuth implements Authentication { | ||
apiKey: string = ''; | ||
|
||
constructor(private location: string, private paramName: string) {} | ||
|
||
applyToRequest(requestOptions: RequestOptions): void { | ||
if (this.location === 'query') { | ||
requestOptions.queryParameters[this.paramName] = this.apiKey; | ||
} else if ( | ||
this.location === 'header' && | ||
requestOptions && | ||
requestOptions.headers | ||
) { | ||
requestOptions.headers[this.paramName] = this.apiKey; | ||
} else if ( | ||
this.location === 'cookie' && | ||
requestOptions && | ||
requestOptions.headers | ||
) { | ||
if (requestOptions.headers.Cookie) { | ||
requestOptions.headers.Cookie += `; ${ | ||
this.paramName | ||
}=${encodeURIComponent(this.apiKey)}`; | ||
} else { | ||
requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( | ||
this.apiKey | ||
)}`; | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
clients/algoliasearch-client-javascript/client-insights/model/pushEventsResponse.ts
This file contains hidden or 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 @@ | ||
export type PushEventsResponse = { | ||
/** | ||
* A message confirming the event push. | ||
*/ | ||
message: string; | ||
}; |
24 changes: 24 additions & 0 deletions
24
clients/algoliasearch-client-javascript/client-insights/package.json
This file contains hidden or 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,24 @@ | ||
{ | ||
"name": "@algolia/client-insights", | ||
"version": "5.0.0", | ||
"description": "JavaScript client for @algolia/client-insights", | ||
"repository": "algolia/algoliasearch-client-javascript", | ||
"author": "Algolia", | ||
"private": true, | ||
"license": "MIT", | ||
"main": "dist/api.js", | ||
"types": "dist/api.d.ts", | ||
"scripts": { | ||
"clean": "rm -Rf node_modules/ *.js", | ||
"build": "tsc", | ||
"test": "yarn build && node dist/client.js" | ||
}, | ||
"engines": { | ||
"node": "^16.0.0", | ||
"yarn": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "16.11.11", | ||
"typescript": "4.5.4" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
clients/algoliasearch-client-javascript/client-insights/src/apis.ts
This file contains hidden or 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,7 @@ | ||
import { InsightsApi } from './insightsApi'; | ||
|
||
export * from './insightsApi'; | ||
export * from '../utils/errors'; | ||
export { EchoRequester } from '../utils/requester/EchoRequester'; | ||
|
||
export const APIS = [InsightsApi]; |
118 changes: 118 additions & 0 deletions
118
clients/algoliasearch-client-javascript/client-insights/src/insightsApi.ts
This file contains hidden or 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,118 @@ | ||
import type { InsightEvents } from '../model/insightEvents'; | ||
import { ApiKeyAuth } from '../model/models'; | ||
import type { PushEventsResponse } from '../model/pushEventsResponse'; | ||
import { Transporter } from '../utils/Transporter'; | ||
import type { Requester } from '../utils/requester/Requester'; | ||
import type { Headers, Host, Request, RequestOptions } from '../utils/types'; | ||
|
||
export enum InsightsApiKeys { | ||
apiKey, | ||
appId, | ||
} | ||
|
||
export class InsightsApi { | ||
protected authentications = { | ||
apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), | ||
appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), | ||
}; | ||
|
||
private transporter: Transporter; | ||
|
||
private sendRequest<TResponse>( | ||
request: Request, | ||
requestOptions: RequestOptions | ||
): Promise<TResponse> { | ||
if (this.authentications.apiKey.apiKey) { | ||
this.authentications.apiKey.applyToRequest(requestOptions); | ||
} | ||
|
||
if (this.authentications.appId.apiKey) { | ||
this.authentications.appId.applyToRequest(requestOptions); | ||
} | ||
|
||
return this.transporter.request(request, requestOptions); | ||
} | ||
|
||
constructor( | ||
appId: string, | ||
apiKey: string, | ||
options?: { requester?: Requester; hosts?: Host[] } | ||
) { | ||
this.setApiKey(InsightsApiKeys.appId, appId); | ||
this.setApiKey(InsightsApiKeys.apiKey, apiKey); | ||
|
||
this.transporter = new Transporter({ | ||
hosts: options?.hosts ?? this.getDefaultHosts(), | ||
baseHeaders: { | ||
'content-type': 'application/x-www-form-urlencoded', | ||
}, | ||
userAgent: 'Algolia for Javascript', | ||
timeouts: { | ||
connect: 2, | ||
read: 5, | ||
write: 30, | ||
}, | ||
requester: options?.requester, | ||
}); | ||
} | ||
|
||
getDefaultHosts(): Host[] { | ||
return [ | ||
{ url: `insights.algolia.io`, accept: 'readWrite', protocol: 'https' }, | ||
]; | ||
} | ||
|
||
setRequest(requester: Requester): void { | ||
this.transporter.setRequester(requester); | ||
} | ||
|
||
setHosts(hosts: Host[]): void { | ||
this.transporter.setHosts(hosts); | ||
} | ||
|
||
setApiKey(key: InsightsApiKeys, value: string): void { | ||
this.authentications[InsightsApiKeys[key]].apiKey = value; | ||
} | ||
|
||
/** | ||
* This command pushes an array of events to the Insights API. | ||
* | ||
* @summary This command pushes an array of events to the Insights API. | ||
* @param pushEvents - The pushEvents parameters. | ||
* @param pushEvents.insightEvents - The insightEvents. | ||
*/ | ||
pushEvents({ insightEvents }: PushEventsProps): Promise<PushEventsResponse> { | ||
const path = '/1/events'; | ||
const headers: Headers = { Accept: 'application/json' }; | ||
const queryParameters: Record<string, string> = {}; | ||
|
||
if (insightEvents === null || insightEvents === undefined) { | ||
throw new Error( | ||
'Required parameter insightEvents was null or undefined when calling pushEvents.' | ||
); | ||
} | ||
|
||
if (insightEvents.events === null || insightEvents.events === undefined) { | ||
throw new Error( | ||
'Required parameter insightEvents.events was null or undefined when calling pushEvents.' | ||
); | ||
} | ||
|
||
const request: Request = { | ||
method: 'POST', | ||
path, | ||
data: insightEvents, | ||
}; | ||
|
||
const requestOptions: RequestOptions = { | ||
headers, | ||
queryParameters, | ||
}; | ||
|
||
return this.sendRequest(request, requestOptions); | ||
} | ||
} | ||
|
||
export type PushEventsProps = { | ||
insightEvents: InsightEvents; | ||
}; |
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.
Uh oh!
There was an error while loading. Please reload this page.