Skip to content

Commit 576854c

Browse files
chore: generated code for commit 0076edc. [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 0076edc commit 576854c

27 files changed

+600
-11
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { InitClientOptions } from '@algolia/client-common';
2+
import {
3+
DEFAULT_CONNECT_TIMEOUT_BROWSER,
4+
DEFAULT_READ_TIMEOUT_BROWSER,
5+
DEFAULT_WRITE_TIMEOUT_BROWSER,
6+
createMemoryCache,
7+
createFallbackableCache,
8+
createBrowserLocalStorageCache,
9+
} from '@algolia/client-common';
10+
import { createXhrRequester } from '@algolia/requester-browser-xhr';
11+
12+
import type { PredictClient, Region } from '../src/predictClient';
13+
import {
14+
createPredictClient,
15+
apiClientVersion,
16+
REGIONS,
17+
} from '../src/predictClient';
18+
19+
export { apiClientVersion, PredictClient } from '../src/predictClient';
20+
export * from '../model';
21+
22+
export function predictClient(
23+
appId: string,
24+
apiKey: string,
25+
region: Region,
26+
options?: InitClientOptions
27+
): PredictClient {
28+
if (!appId || typeof appId !== 'string') {
29+
throw new Error('`appId` is missing.');
30+
}
31+
32+
if (!apiKey || typeof apiKey !== 'string') {
33+
throw new Error('`apiKey` is missing.');
34+
}
35+
36+
if (!region) {
37+
throw new Error('`region` is missing.');
38+
}
39+
40+
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
41+
throw new Error(
42+
`\`region\` must be one of the following: ${REGIONS.join(', ')}`
43+
);
44+
}
45+
46+
return createPredictClient({
47+
appId,
48+
apiKey,
49+
region,
50+
timeouts: {
51+
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
52+
read: DEFAULT_READ_TIMEOUT_BROWSER,
53+
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
54+
},
55+
requester: createXhrRequester(),
56+
algoliaAgents: [{ segment: 'Browser' }],
57+
authMode: 'WithinQueryParameters',
58+
responsesCache: createMemoryCache(),
59+
requestsCache: createMemoryCache({ serializable: false }),
60+
hostsCache: createFallbackableCache({
61+
caches: [
62+
createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
63+
createMemoryCache(),
64+
],
65+
}),
66+
...options,
67+
});
68+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { InitClientOptions } from '@algolia/client-common';
2+
import {
3+
DEFAULT_CONNECT_TIMEOUT_NODE,
4+
DEFAULT_READ_TIMEOUT_NODE,
5+
DEFAULT_WRITE_TIMEOUT_NODE,
6+
createMemoryCache,
7+
createNullCache,
8+
} from '@algolia/client-common';
9+
import { createHttpRequester } from '@algolia/requester-node-http';
10+
11+
import type { PredictClient, Region } from '../src/predictClient';
12+
import { createPredictClient, REGIONS } from '../src/predictClient';
13+
14+
export { apiClientVersion, PredictClient } from '../src/predictClient';
15+
export * from '../model';
16+
17+
export function predictClient(
18+
appId: string,
19+
apiKey: string,
20+
region: Region,
21+
options?: InitClientOptions
22+
): PredictClient {
23+
if (!appId || typeof appId !== 'string') {
24+
throw new Error('`appId` is missing.');
25+
}
26+
27+
if (!apiKey || typeof apiKey !== 'string') {
28+
throw new Error('`apiKey` is missing.');
29+
}
30+
31+
if (!region) {
32+
throw new Error('`region` is missing.');
33+
}
34+
35+
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
36+
throw new Error(
37+
`\`region\` must be one of the following: ${REGIONS.join(', ')}`
38+
);
39+
}
40+
41+
return createPredictClient({
42+
appId,
43+
apiKey,
44+
region,
45+
timeouts: {
46+
connect: DEFAULT_CONNECT_TIMEOUT_NODE,
47+
read: DEFAULT_READ_TIMEOUT_NODE,
48+
write: DEFAULT_WRITE_TIMEOUT_NODE,
49+
},
50+
requester: createHttpRequester(),
51+
algoliaAgents: [{ segment: 'Node.js', version: process.versions.node }],
52+
responsesCache: createNullCache(),
53+
requestsCache: createNullCache(),
54+
hostsCache: createMemoryCache(),
55+
...options,
56+
});
57+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line import/no-unresolved
2+
export * from './dist/builds/node';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line import/no-commonjs,import/extensions
2+
module.exports = require('./dist/predict.cjs.js');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type Affinities = {
2+
name?: string;
3+
value?: string;
4+
probability?: number;
5+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { ModelsToRetrieve } from './modelsToRetrieve';
2+
import type { TypesToRetrieve } from './typesToRetrieve';
3+
4+
export type AllParams = ModelsToRetrieve & TypesToRetrieve;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { Params } from './params';
2+
3+
/**
4+
* Properties for the `del` method.
5+
*/
6+
export type DelProps = {
7+
/**
8+
* The path of the API endpoint to target, anything after the /1 needs to be specified.
9+
*/
10+
path: string;
11+
/**
12+
* Query parameters to be applied to the current query.
13+
*/
14+
parameters?: Record<string, any>;
15+
};
16+
17+
/**
18+
* Properties for the `fetchUserProfile` method.
19+
*/
20+
export type FetchUserProfileProps = {
21+
/**
22+
* User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors).
23+
*/
24+
userID: string;
25+
params: Params;
26+
};
27+
28+
/**
29+
* Properties for the `get` method.
30+
*/
31+
export type GetProps = {
32+
/**
33+
* The path of the API endpoint to target, anything after the /1 needs to be specified.
34+
*/
35+
path: string;
36+
/**
37+
* Query parameters to be applied to the current query.
38+
*/
39+
parameters?: Record<string, any>;
40+
};
41+
42+
/**
43+
* Properties for the `post` method.
44+
*/
45+
export type PostProps = {
46+
/**
47+
* The path of the API endpoint to target, anything after the /1 needs to be specified.
48+
*/
49+
path: string;
50+
/**
51+
* Query parameters to be applied to the current query.
52+
*/
53+
parameters?: Record<string, any>;
54+
/**
55+
* The parameters to send with the custom request.
56+
*/
57+
body?: Record<string, any>;
58+
};
59+
60+
/**
61+
* Properties for the `put` method.
62+
*/
63+
export type PutProps = {
64+
/**
65+
* The path of the API endpoint to target, anything after the /1 needs to be specified.
66+
*/
67+
path: string;
68+
/**
69+
* Query parameters to be applied to the current query.
70+
*/
71+
parameters?: Record<string, any>;
72+
/**
73+
* The parameters to send with the custom request.
74+
*/
75+
body?: Record<string, any>;
76+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Error.
3+
*/
4+
export type ErrorBase = Record<string, any> & {
5+
message?: string;
6+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Predictions } from './predictions';
2+
import type { Properties } from './properties';
3+
import type { Segments } from './segments';
4+
5+
export type FetchUserProfileResponse = {
6+
user: string;
7+
predictions?: Predictions;
8+
properties?: Properties;
9+
segments?: Segments;
10+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type FunnelStage = {
2+
name?: string;
3+
probability?: number;
4+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export * from './affinities';
2+
export * from './allParams';
3+
export * from './errorBase';
4+
export * from './fetchUserProfileResponse';
5+
export * from './funnelStage';
6+
export * from './modelsToRetrieve';
7+
export * from './modelsToRetrieveEnum';
8+
export * from './params';
9+
export * from './predictions';
10+
export * from './predictionsAffinities';
11+
export * from './predictionsFunnelStage';
12+
export * from './predictionsOrderValue';
13+
export * from './properties';
14+
export * from './segments';
15+
export * from './typesToRetrieve';
16+
export * from './typesToRetrieveEnum';
17+
export * from './clientMethodProps';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { ModelsToRetrieveEnum } from './modelsToRetrieveEnum';
2+
3+
export type ModelsToRetrieve = {
4+
modelsToRetrieve: ModelsToRetrieveEnum[];
5+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type ModelsToRetrieveEnum =
2+
| 'affinities'
3+
| 'funnel_stage'
4+
| 'order_value';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { AllParams } from './allParams';
2+
import type { ModelsToRetrieve } from './modelsToRetrieve';
3+
import type { TypesToRetrieve } from './typesToRetrieve';
4+
5+
export type Params = AllParams | ModelsToRetrieve | TypesToRetrieve;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { PredictionsAffinities } from './predictionsAffinities';
2+
import type { PredictionsFunnelStage } from './predictionsFunnelStage';
3+
import type { PredictionsOrderValue } from './predictionsOrderValue';
4+
5+
export type Predictions = {
6+
funnel_stage?: PredictionsFunnelStage;
7+
order_value?: PredictionsOrderValue;
8+
affinities?: PredictionsAffinities;
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Affinities } from './affinities';
2+
3+
/**
4+
* Prediction for the **affinities** model.
5+
*/
6+
export type PredictionsAffinities = {
7+
value?: Affinities[];
8+
lastUpdatedAt?: string;
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { FunnelStage } from './funnelStage';
2+
3+
/**
4+
* Prediction for the **funnel_stage** model.
5+
*/
6+
export type PredictionsFunnelStage = {
7+
value?: FunnelStage[];
8+
lastUpdatedAt?: string;
9+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Prediction for the **order_value** model.
3+
*/
4+
export type PredictionsOrderValue = {
5+
value?: number;
6+
lastUpdatedAt?: string;
7+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Properties for the user profile.
3+
*/
4+
export type Properties = {
5+
/**
6+
* Raw user properties (key-value pairs).
7+
*/
8+
raw?: Record<string, any>;
9+
/**
10+
* Computed user properties (key-value pairs).
11+
*/
12+
computed?: Record<string, any>;
13+
/**
14+
* Custom user properties (key-value pairs).
15+
*/
16+
custom?: Record<string, any>;
17+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Segments that the user belongs to.
3+
*/
4+
export type Segments = {
5+
/**
6+
* List of computed segments IDs.
7+
*/
8+
computed?: string[];
9+
/**
10+
* List of custom segments IDs.
11+
*/
12+
custom?: string[];
13+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { TypesToRetrieveEnum } from './typesToRetrieveEnum';
2+
3+
export type TypesToRetrieve = {
4+
typesToRetrieve: TypesToRetrieveEnum[];
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type TypesToRetrieveEnum = 'properties' | 'segments';

0 commit comments

Comments
 (0)