@algolia/composition 0.0.1-beta.2

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.
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/compositionClient.ts
21
+ var compositionClient_exports = {};
22
+ __export(compositionClient_exports, {
23
+ apiClientVersion: () => apiClientVersion,
24
+ createCompositionClient: () => createCompositionClient
25
+ });
26
+ module.exports = __toCommonJS(compositionClient_exports);
27
+ var import_client_common = require("@algolia/client-common");
28
+ var apiClientVersion = "0.0.1-beta.2";
29
+ function getDefaultHosts(appId) {
30
+ return [
31
+ {
32
+ url: `${appId}-dsn.algolia.net`,
33
+ accept: "read",
34
+ protocol: "https"
35
+ },
36
+ {
37
+ url: `${appId}.algolia.net`,
38
+ accept: "write",
39
+ protocol: "https"
40
+ }
41
+ ].concat(
42
+ (0, import_client_common.shuffle)([
43
+ {
44
+ url: `${appId}-1.algolianet.com`,
45
+ accept: "readWrite",
46
+ protocol: "https"
47
+ },
48
+ {
49
+ url: `${appId}-2.algolianet.com`,
50
+ accept: "readWrite",
51
+ protocol: "https"
52
+ },
53
+ {
54
+ url: `${appId}-3.algolianet.com`,
55
+ accept: "readWrite",
56
+ protocol: "https"
57
+ }
58
+ ])
59
+ );
60
+ }
61
+ function createCompositionClient({
62
+ appId: appIdOption,
63
+ apiKey: apiKeyOption,
64
+ authMode,
65
+ algoliaAgents,
66
+ ...options
67
+ }) {
68
+ const auth = (0, import_client_common.createAuth)(appIdOption, apiKeyOption, authMode);
69
+ const transporter = (0, import_client_common.createTransporter)({
70
+ hosts: getDefaultHosts(appIdOption),
71
+ ...options,
72
+ algoliaAgent: (0, import_client_common.getAlgoliaAgent)({
73
+ algoliaAgents,
74
+ client: "Composition",
75
+ version: apiClientVersion
76
+ }),
77
+ baseHeaders: {
78
+ "content-type": "text/plain",
79
+ ...auth.headers(),
80
+ ...options.baseHeaders
81
+ },
82
+ baseQueryParameters: {
83
+ ...auth.queryParameters(),
84
+ ...options.baseQueryParameters
85
+ }
86
+ });
87
+ return {
88
+ transporter,
89
+ /**
90
+ * The `appId` currently in use.
91
+ */
92
+ appId: appIdOption,
93
+ /**
94
+ * The `apiKey` currently in use.
95
+ */
96
+ apiKey: apiKeyOption,
97
+ /**
98
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
99
+ */
100
+ clearCache() {
101
+ return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
102
+ },
103
+ /**
104
+ * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
105
+ */
106
+ get _ua() {
107
+ return transporter.algoliaAgent.value;
108
+ },
109
+ /**
110
+ * Adds a `segment` to the `x-algolia-agent` sent with every requests.
111
+ *
112
+ * @param segment - The algolia agent (user-agent) segment to add.
113
+ * @param version - The version of the agent.
114
+ */
115
+ addAlgoliaAgent(segment, version) {
116
+ transporter.algoliaAgent.add({ segment, version });
117
+ },
118
+ /**
119
+ * Helper method to switch the API key used to authenticate the requests.
120
+ *
121
+ * @param params - Method params.
122
+ * @param params.apiKey - The new API Key to use.
123
+ */
124
+ setClientApiKey({ apiKey }) {
125
+ if (!authMode || authMode === "WithinHeaders") {
126
+ transporter.baseHeaders["x-algolia-api-key"] = apiKey;
127
+ } else {
128
+ transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
129
+ }
130
+ },
131
+ /**
132
+ * Runs a query on a single composition and returns matching results.
133
+ *
134
+ * Required API Key ACLs:
135
+ * - search
136
+ * @param search - The search object.
137
+ * @param search.compositionID - Unique Composition ObjectID.
138
+ * @param search.requestBody - The requestBody object.
139
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
140
+ */
141
+ search({ compositionID, requestBody }, requestOptions) {
142
+ if (!compositionID) {
143
+ throw new Error("Parameter `compositionID` is required when calling `search`.");
144
+ }
145
+ if (!requestBody) {
146
+ throw new Error("Parameter `requestBody` is required when calling `search`.");
147
+ }
148
+ const requestPath = "/1/compositions/{compositionID}/run".replace(
149
+ "{compositionID}",
150
+ encodeURIComponent(compositionID)
151
+ );
152
+ const headers = {};
153
+ const queryParameters = {};
154
+ const request = {
155
+ method: "POST",
156
+ path: requestPath,
157
+ queryParameters,
158
+ headers,
159
+ data: requestBody,
160
+ useReadTransporter: true,
161
+ cacheable: true
162
+ };
163
+ return transporter.request(request, requestOptions);
164
+ },
165
+ /**
166
+ * Searches for values of a specified facet attribute on the composition\'s main source\'s index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn\'t work if you have **more than 65 searchable facets and searchable attributes combined**.
167
+ *
168
+ * Required API Key ACLs:
169
+ * - search
170
+ * @param searchForFacetValues - The searchForFacetValues object.
171
+ * @param searchForFacetValues.compositionID - Unique Composition ObjectID.
172
+ * @param searchForFacetValues.facetName - Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier.
173
+ * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object.
174
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
175
+ */
176
+ searchForFacetValues({ compositionID, facetName, searchForFacetValuesRequest }, requestOptions) {
177
+ if (!compositionID) {
178
+ throw new Error("Parameter `compositionID` is required when calling `searchForFacetValues`.");
179
+ }
180
+ if (!facetName) {
181
+ throw new Error("Parameter `facetName` is required when calling `searchForFacetValues`.");
182
+ }
183
+ const requestPath = "/1/compositions/{compositionID}/facets/{facetName}/query".replace("{compositionID}", encodeURIComponent(compositionID)).replace("{facetName}", encodeURIComponent(facetName));
184
+ const headers = {};
185
+ const queryParameters = {};
186
+ const request = {
187
+ method: "POST",
188
+ path: requestPath,
189
+ queryParameters,
190
+ headers,
191
+ data: searchForFacetValuesRequest ? searchForFacetValuesRequest : {},
192
+ useReadTransporter: true,
193
+ cacheable: true
194
+ };
195
+ return transporter.request(request, requestOptions);
196
+ }
197
+ };
198
+ }
199
+ // Annotate the CommonJS export names for ESM import in node:
200
+ 0 && (module.exports = {
201
+ apiClientVersion,
202
+ createCompositionClient
203
+ });
204
+ //# sourceMappingURL=compositionClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/compositionClient.ts"],"sourcesContent":["// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.\n\nimport type {\n CreateClientOptions,\n Headers,\n Host,\n QueryParameters,\n Request,\n RequestOptions,\n} from '@algolia/client-common';\nimport { createAuth, createTransporter, getAlgoliaAgent, shuffle } from '@algolia/client-common';\n\nimport type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse';\nimport type { SearchResponse } from '../model/searchResponse';\n\nimport type { SearchForFacetValuesProps, SearchProps } from '../model/clientMethodProps';\n\nexport const apiClientVersion = '0.0.1-beta.2';\n\nfunction getDefaultHosts(appId: string): Host[] {\n return (\n [\n {\n url: `${appId}-dsn.algolia.net`,\n accept: 'read',\n protocol: 'https',\n },\n {\n url: `${appId}.algolia.net`,\n accept: 'write',\n protocol: 'https',\n },\n ] as Host[]\n ).concat(\n shuffle([\n {\n url: `${appId}-1.algolianet.com`,\n accept: 'readWrite',\n protocol: 'https',\n },\n {\n url: `${appId}-2.algolianet.com`,\n accept: 'readWrite',\n protocol: 'https',\n },\n {\n url: `${appId}-3.algolianet.com`,\n accept: 'readWrite',\n protocol: 'https',\n },\n ]),\n );\n}\n\nexport function createCompositionClient({\n appId: appIdOption,\n apiKey: apiKeyOption,\n authMode,\n algoliaAgents,\n ...options\n}: CreateClientOptions) {\n const auth = createAuth(appIdOption, apiKeyOption, authMode);\n const transporter = createTransporter({\n hosts: getDefaultHosts(appIdOption),\n ...options,\n algoliaAgent: getAlgoliaAgent({\n algoliaAgents,\n client: 'Composition',\n version: apiClientVersion,\n }),\n baseHeaders: {\n 'content-type': 'text/plain',\n ...auth.headers(),\n ...options.baseHeaders,\n },\n baseQueryParameters: {\n ...auth.queryParameters(),\n ...options.baseQueryParameters,\n },\n });\n\n return {\n transporter,\n\n /**\n * The `appId` currently in use.\n */\n appId: appIdOption,\n\n /**\n * The `apiKey` currently in use.\n */\n apiKey: apiKeyOption,\n\n /**\n * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.\n */\n clearCache(): Promise<void> {\n return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined);\n },\n\n /**\n * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.\n */\n get _ua(): string {\n return transporter.algoliaAgent.value;\n },\n\n /**\n * Adds a `segment` to the `x-algolia-agent` sent with every requests.\n *\n * @param segment - The algolia agent (user-agent) segment to add.\n * @param version - The version of the agent.\n */\n addAlgoliaAgent(segment: string, version?: string): void {\n transporter.algoliaAgent.add({ segment, version });\n },\n\n /**\n * Helper method to switch the API key used to authenticate the requests.\n *\n * @param params - Method params.\n * @param params.apiKey - The new API Key to use.\n */\n setClientApiKey({ apiKey }: { apiKey: string }): void {\n if (!authMode || authMode === 'WithinHeaders') {\n transporter.baseHeaders['x-algolia-api-key'] = apiKey;\n } else {\n transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;\n }\n },\n\n /**\n * Runs a query on a single composition and returns matching results.\n *\n * Required API Key ACLs:\n * - search\n * @param search - The search object.\n * @param search.compositionID - Unique Composition ObjectID.\n * @param search.requestBody - The requestBody object.\n * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.\n */\n search<T>(\n { compositionID, requestBody }: SearchProps,\n requestOptions?: RequestOptions,\n ): Promise<SearchResponse<T>> {\n if (!compositionID) {\n throw new Error('Parameter `compositionID` is required when calling `search`.');\n }\n\n if (!requestBody) {\n throw new Error('Parameter `requestBody` is required when calling `search`.');\n }\n\n const requestPath = '/1/compositions/{compositionID}/run'.replace(\n '{compositionID}',\n encodeURIComponent(compositionID),\n );\n const headers: Headers = {};\n const queryParameters: QueryParameters = {};\n\n const request: Request = {\n method: 'POST',\n path: requestPath,\n queryParameters,\n headers,\n data: requestBody,\n useReadTransporter: true,\n cacheable: true,\n };\n\n return transporter.request(request, requestOptions);\n },\n\n /**\n * Searches for values of a specified facet attribute on the composition\\'s main source\\'s index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn\\'t work if you have **more than 65 searchable facets and searchable attributes combined**.\n *\n * Required API Key ACLs:\n * - search\n * @param searchForFacetValues - The searchForFacetValues object.\n * @param searchForFacetValues.compositionID - Unique Composition ObjectID.\n * @param searchForFacetValues.facetName - Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier.\n * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object.\n * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.\n */\n searchForFacetValues(\n { compositionID, facetName, searchForFacetValuesRequest }: SearchForFacetValuesProps,\n requestOptions?: RequestOptions,\n ): Promise<SearchForFacetValuesResponse> {\n if (!compositionID) {\n throw new Error('Parameter `compositionID` is required when calling `searchForFacetValues`.');\n }\n\n if (!facetName) {\n throw new Error('Parameter `facetName` is required when calling `searchForFacetValues`.');\n }\n\n const requestPath = '/1/compositions/{compositionID}/facets/{facetName}/query'\n .replace('{compositionID}', encodeURIComponent(compositionID))\n .replace('{facetName}', encodeURIComponent(facetName));\n const headers: Headers = {};\n const queryParameters: QueryParameters = {};\n\n const request: Request = {\n method: 'POST',\n path: requestPath,\n queryParameters,\n headers,\n data: searchForFacetValuesRequest ? searchForFacetValuesRequest : {},\n useReadTransporter: true,\n cacheable: true,\n };\n\n return transporter.request(request, requestOptions);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,2BAAwE;AAOjE,IAAM,mBAAmB;AAEhC,SAAS,gBAAgB,OAAuB;AAC9C,SACE;AAAA,IACE;AAAA,MACE,KAAK,GAAG,KAAK;AAAA,MACb,QAAQ;AAAA,MACR,UAAU;AAAA,IACZ;AAAA,IACA;AAAA,MACE,KAAK,GAAG,KAAK;AAAA,MACb,QAAQ;AAAA,MACR,UAAU;AAAA,IACZ;AAAA,EACF,EACA;AAAA,QACA,8BAAQ;AAAA,MACN;AAAA,QACE,KAAK,GAAG,KAAK;AAAA,QACb,QAAQ;AAAA,QACR,UAAU;AAAA,MACZ;AAAA,MACA;AAAA,QACE,KAAK,GAAG,KAAK;AAAA,QACb,QAAQ;AAAA,QACR,UAAU;AAAA,MACZ;AAAA,MACA;AAAA,QACE,KAAK,GAAG,KAAK;AAAA,QACb,QAAQ;AAAA,QACR,UAAU;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,SAAS,wBAAwB;AAAA,EACtC,OAAO;AAAA,EACP,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,QAAM,WAAO,iCAAW,aAAa,cAAc,QAAQ;AAC3D,QAAM,kBAAc,wCAAkB;AAAA,IACpC,OAAO,gBAAgB,WAAW;AAAA,IAClC,GAAG;AAAA,IACH,kBAAc,sCAAgB;AAAA,MAC5B;AAAA,MACA,QAAQ;AAAA,MACR,SAAS;AAAA,IACX,CAAC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YAAM,UAAmB,CAAC;AAC1B,YAAM,kBAAmC,CAAC;AAE1C,YAAM,UAAmB;AAAA,QACvB,QAAQ;AAAA,QACR,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,MAAM;AAAA,QACN,oBAAoB;AAAA,QACpB,WAAW;AAAA,MACb;AAEA,aAAO,YAAY,QAAQ,SAAS,cAAc;AAAA,IACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAaA,qBACE,EAAE,eAAe,WAAW,4BAA4B,GACxD,gBACuC;AACvC,UAAI,CAAC,eAAe;AAClB,cAAM,IAAI,MAAM,4EAA4E;AAAA,MAC9F;AAEA,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,wEAAwE;AAAA,MAC1F;AAEA,YAAM,cAAc,2DACjB,QAAQ,mBAAmB,mBAAmB,aAAa,CAAC,EAC5D,QAAQ,eAAe,mBAAmB,SAAS,CAAC;AACvD,YAAM,UAAmB,CAAC;AAC1B,YAAM,kBAAmC,CAAC;AAE1C,YAAM,UAAmB;AAAA,QACvB,QAAQ;AAAA,QACR,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,MAAM,8BAA8B,8BAA8B,CAAC;AAAA,QACnE,oBAAoB;AAAA,QACpB,WAAW;AAAA,MACb;AAEA,aAAO,YAAY,QAAQ,SAAS,cAAc;AAAA,IACpD;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,178 @@
1
+ // src/compositionClient.ts
2
+ import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common";
3
+ var apiClientVersion = "0.0.1-beta.2";
4
+ function getDefaultHosts(appId) {
5
+ return [
6
+ {
7
+ url: `${appId}-dsn.algolia.net`,
8
+ accept: "read",
9
+ protocol: "https"
10
+ },
11
+ {
12
+ url: `${appId}.algolia.net`,
13
+ accept: "write",
14
+ protocol: "https"
15
+ }
16
+ ].concat(
17
+ shuffle([
18
+ {
19
+ url: `${appId}-1.algolianet.com`,
20
+ accept: "readWrite",
21
+ protocol: "https"
22
+ },
23
+ {
24
+ url: `${appId}-2.algolianet.com`,
25
+ accept: "readWrite",
26
+ protocol: "https"
27
+ },
28
+ {
29
+ url: `${appId}-3.algolianet.com`,
30
+ accept: "readWrite",
31
+ protocol: "https"
32
+ }
33
+ ])
34
+ );
35
+ }
36
+ function createCompositionClient({
37
+ appId: appIdOption,
38
+ apiKey: apiKeyOption,
39
+ authMode,
40
+ algoliaAgents,
41
+ ...options
42
+ }) {
43
+ const auth = createAuth(appIdOption, apiKeyOption, authMode);
44
+ const transporter = createTransporter({
45
+ hosts: getDefaultHosts(appIdOption),
46
+ ...options,
47
+ algoliaAgent: getAlgoliaAgent({
48
+ algoliaAgents,
49
+ client: "Composition",
50
+ version: apiClientVersion
51
+ }),
52
+ baseHeaders: {
53
+ "content-type": "text/plain",
54
+ ...auth.headers(),
55
+ ...options.baseHeaders
56
+ },
57
+ baseQueryParameters: {
58
+ ...auth.queryParameters(),
59
+ ...options.baseQueryParameters
60
+ }
61
+ });
62
+ return {
63
+ transporter,
64
+ /**
65
+ * The `appId` currently in use.
66
+ */
67
+ appId: appIdOption,
68
+ /**
69
+ * The `apiKey` currently in use.
70
+ */
71
+ apiKey: apiKeyOption,
72
+ /**
73
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
74
+ */
75
+ clearCache() {
76
+ return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
77
+ },
78
+ /**
79
+ * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
80
+ */
81
+ get _ua() {
82
+ return transporter.algoliaAgent.value;
83
+ },
84
+ /**
85
+ * Adds a `segment` to the `x-algolia-agent` sent with every requests.
86
+ *
87
+ * @param segment - The algolia agent (user-agent) segment to add.
88
+ * @param version - The version of the agent.
89
+ */
90
+ addAlgoliaAgent(segment, version) {
91
+ transporter.algoliaAgent.add({ segment, version });
92
+ },
93
+ /**
94
+ * Helper method to switch the API key used to authenticate the requests.
95
+ *
96
+ * @param params - Method params.
97
+ * @param params.apiKey - The new API Key to use.
98
+ */
99
+ setClientApiKey({ apiKey }) {
100
+ if (!authMode || authMode === "WithinHeaders") {
101
+ transporter.baseHeaders["x-algolia-api-key"] = apiKey;
102
+ } else {
103
+ transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
104
+ }
105
+ },
106
+ /**
107
+ * Runs a query on a single composition and returns matching results.
108
+ *
109
+ * Required API Key ACLs:
110
+ * - search
111
+ * @param search - The search object.
112
+ * @param search.compositionID - Unique Composition ObjectID.
113
+ * @param search.requestBody - The requestBody object.
114
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
115
+ */
116
+ search({ compositionID, requestBody }, requestOptions) {
117
+ if (!compositionID) {
118
+ throw new Error("Parameter `compositionID` is required when calling `search`.");
119
+ }
120
+ if (!requestBody) {
121
+ throw new Error("Parameter `requestBody` is required when calling `search`.");
122
+ }
123
+ const requestPath = "/1/compositions/{compositionID}/run".replace(
124
+ "{compositionID}",
125
+ encodeURIComponent(compositionID)
126
+ );
127
+ const headers = {};
128
+ const queryParameters = {};
129
+ const request = {
130
+ method: "POST",
131
+ path: requestPath,
132
+ queryParameters,
133
+ headers,
134
+ data: requestBody,
135
+ useReadTransporter: true,
136
+ cacheable: true
137
+ };
138
+ return transporter.request(request, requestOptions);
139
+ },
140
+ /**
141
+ * Searches for values of a specified facet attribute on the composition\'s main source\'s index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn\'t work if you have **more than 65 searchable facets and searchable attributes combined**.
142
+ *
143
+ * Required API Key ACLs:
144
+ * - search
145
+ * @param searchForFacetValues - The searchForFacetValues object.
146
+ * @param searchForFacetValues.compositionID - Unique Composition ObjectID.
147
+ * @param searchForFacetValues.facetName - Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier.
148
+ * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object.
149
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
150
+ */
151
+ searchForFacetValues({ compositionID, facetName, searchForFacetValuesRequest }, requestOptions) {
152
+ if (!compositionID) {
153
+ throw new Error("Parameter `compositionID` is required when calling `searchForFacetValues`.");
154
+ }
155
+ if (!facetName) {
156
+ throw new Error("Parameter `facetName` is required when calling `searchForFacetValues`.");
157
+ }
158
+ const requestPath = "/1/compositions/{compositionID}/facets/{facetName}/query".replace("{compositionID}", encodeURIComponent(compositionID)).replace("{facetName}", encodeURIComponent(facetName));
159
+ const headers = {};
160
+ const queryParameters = {};
161
+ const request = {
162
+ method: "POST",
163
+ path: requestPath,
164
+ queryParameters,
165
+ headers,
166
+ data: searchForFacetValuesRequest ? searchForFacetValuesRequest : {},
167
+ useReadTransporter: true,
168
+ cacheable: true
169
+ };
170
+ return transporter.request(request, requestOptions);
171
+ }
172
+ };
173
+ }
174
+ export {
175
+ apiClientVersion,
176
+ createCompositionClient
177
+ };
178
+ //# sourceMappingURL=compositionClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/compositionClient.ts"],"sourcesContent":["// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.\n\nimport type {\n CreateClientOptions,\n Headers,\n Host,\n QueryParameters,\n Request,\n RequestOptions,\n} from '@algolia/client-common';\nimport { createAuth, createTransporter, getAlgoliaAgent, shuffle } from '@algolia/client-common';\n\nimport type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse';\nimport type { SearchResponse } from '../model/searchResponse';\n\nimport type { SearchForFacetValuesProps, SearchProps } from '../model/clientMethodProps';\n\nexport const apiClientVersion = '0.0.1-beta.2';\n\nfunction getDefaultHosts(appId: string): Host[] {\n return (\n [\n {\n url: `${appId}-dsn.algolia.net`,\n accept: 'read',\n protocol: 'https',\n },\n {\n url: `${appId}.algolia.net`,\n accept: 'write',\n protocol: 'https',\n },\n ] as Host[]\n ).concat(\n shuffle([\n {\n url: `${appId}-1.algolianet.com`,\n accept: 'readWrite',\n protocol: 'https',\n },\n {\n url: `${appId}-2.algolianet.com`,\n accept: 'readWrite',\n protocol: 'https',\n },\n {\n url: `${appId}-3.algolianet.com`,\n accept: 'readWrite',\n protocol: 'https',\n },\n ]),\n );\n}\n\nexport function createCompositionClient({\n appId: appIdOption,\n apiKey: apiKeyOption,\n authMode,\n algoliaAgents,\n ...options\n}: CreateClientOptions) {\n const auth = createAuth(appIdOption, apiKeyOption, authMode);\n const transporter = createTransporter({\n hosts: getDefaultHosts(appIdOption),\n ...options,\n algoliaAgent: getAlgoliaAgent({\n algoliaAgents,\n client: 'Composition',\n version: apiClientVersion,\n }),\n baseHeaders: {\n 'content-type': 'text/plain',\n ...auth.headers(),\n ...options.baseHeaders,\n },\n baseQueryParameters: {\n ...auth.queryParameters(),\n ...options.baseQueryParameters,\n },\n });\n\n return {\n transporter,\n\n /**\n * The `appId` currently in use.\n */\n appId: appIdOption,\n\n /**\n * The `apiKey` currently in use.\n */\n apiKey: apiKeyOption,\n\n /**\n * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.\n */\n clearCache(): Promise<void> {\n return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined);\n },\n\n /**\n * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.\n */\n get _ua(): string {\n return transporter.algoliaAgent.value;\n },\n\n /**\n * Adds a `segment` to the `x-algolia-agent` sent with every requests.\n *\n * @param segment - The algolia agent (user-agent) segment to add.\n * @param version - The version of the agent.\n */\n addAlgoliaAgent(segment: string, version?: string): void {\n transporter.algoliaAgent.add({ segment, version });\n },\n\n /**\n * Helper method to switch the API key used to authenticate the requests.\n *\n * @param params - Method params.\n * @param params.apiKey - The new API Key to use.\n */\n setClientApiKey({ apiKey }: { apiKey: string }): void {\n if (!authMode || authMode === 'WithinHeaders') {\n transporter.baseHeaders['x-algolia-api-key'] = apiKey;\n } else {\n transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;\n }\n },\n\n /**\n * Runs a query on a single composition and returns matching results.\n *\n * Required API Key ACLs:\n * - search\n * @param search - The search object.\n * @param search.compositionID - Unique Composition ObjectID.\n * @param search.requestBody - The requestBody object.\n * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.\n */\n search<T>(\n { compositionID, requestBody }: SearchProps,\n requestOptions?: RequestOptions,\n ): Promise<SearchResponse<T>> {\n if (!compositionID) {\n throw new Error('Parameter `compositionID` is required when calling `search`.');\n }\n\n if (!requestBody) {\n throw new Error('Parameter `requestBody` is required when calling `search`.');\n }\n\n const requestPath = '/1/compositions/{compositionID}/run'.replace(\n '{compositionID}',\n encodeURIComponent(compositionID),\n );\n const headers: Headers = {};\n const queryParameters: QueryParameters = {};\n\n const request: Request = {\n method: 'POST',\n path: requestPath,\n queryParameters,\n headers,\n data: requestBody,\n useReadTransporter: true,\n cacheable: true,\n };\n\n return transporter.request(request, requestOptions);\n },\n\n /**\n * Searches for values of a specified facet attribute on the composition\\'s main source\\'s index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn\\'t work if you have **more than 65 searchable facets and searchable attributes combined**.\n *\n * Required API Key ACLs:\n * - search\n * @param searchForFacetValues - The searchForFacetValues object.\n * @param searchForFacetValues.compositionID - Unique Composition ObjectID.\n * @param searchForFacetValues.facetName - Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier.\n * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object.\n * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.\n */\n searchForFacetValues(\n { compositionID, facetName, searchForFacetValuesRequest }: SearchForFacetValuesProps,\n requestOptions?: RequestOptions,\n ): Promise<SearchForFacetValuesResponse> {\n if (!compositionID) {\n throw new Error('Parameter `compositionID` is required when calling `searchForFacetValues`.');\n }\n\n if (!facetName) {\n throw new Error('Parameter `facetName` is required when calling `searchForFacetValues`.');\n }\n\n const requestPath = '/1/compositions/{compositionID}/facets/{facetName}/query'\n .replace('{compositionID}', encodeURIComponent(compositionID))\n .replace('{facetName}', encodeURIComponent(facetName));\n const headers: Headers = {};\n const queryParameters: QueryParameters = {};\n\n const request: Request = {\n method: 'POST',\n path: requestPath,\n queryParameters,\n headers,\n data: searchForFacetValuesRequest ? searchForFacetValuesRequest : {},\n useReadTransporter: true,\n cacheable: true,\n };\n\n return transporter.request(request, requestOptions);\n },\n };\n}\n"],"mappings":";AAUA,SAAS,YAAY,mBAAmB,iBAAiB,eAAe;AAOjE,IAAM,mBAAmB;AAEhC,SAAS,gBAAgB,OAAuB;AAC9C,SACE;AAAA,IACE;AAAA,MACE,KAAK,GAAG,KAAK;AAAA,MACb,QAAQ;AAAA,MACR,UAAU;AAAA,IACZ;AAAA,IACA;AAAA,MACE,KAAK,GAAG,KAAK;AAAA,MACb,QAAQ;AAAA,MACR,UAAU;AAAA,IACZ;AAAA,EACF,EACA;AAAA,IACA,QAAQ;AAAA,MACN;AAAA,QACE,KAAK,GAAG,KAAK;AAAA,QACb,QAAQ;AAAA,QACR,UAAU;AAAA,MACZ;AAAA,MACA;AAAA,QACE,KAAK,GAAG,KAAK;AAAA,QACb,QAAQ;AAAA,QACR,UAAU;AAAA,MACZ;AAAA,MACA;AAAA,QACE,KAAK,GAAG,KAAK;AAAA,QACb,QAAQ;AAAA,QACR,UAAU;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,SAAS,wBAAwB;AAAA,EACtC,OAAO;AAAA,EACP,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,QAAM,OAAO,WAAW,aAAa,cAAc,QAAQ;AAC3D,QAAM,cAAc,kBAAkB;AAAA,IACpC,OAAO,gBAAgB,WAAW;AAAA,IAClC,GAAG;AAAA,IACH,cAAc,gBAAgB;AAAA,MAC5B;A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