Skip to content

Commit

Permalink
feat(js-api-client): allow passing extra headers in the fetch function
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Jan 6, 2025
1 parent 50b4711 commit e5ba781
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/js-api-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@crystallize/js-api-client",
"license": "MIT",
"version": "4.0.0",
"version": "4.1.0",
"type": "module",
"author": "Crystallize <hello@crystallize.com> (https://crystallize.com)",
"contributors": [
Expand Down
15 changes: 14 additions & 1 deletion components/js-api-client/src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ProfilingOptions = {
export type CreateClientOptions = {
useHttp2?: boolean;
profiling?: ProfilingOptions;
extraHeaders?: RequestInit['headers'];
shopApiToken?: {
doNotFetch?: boolean;
scopes?: string[];
Expand Down Expand Up @@ -183,7 +184,19 @@ function createApiCaller(
options?: CreateClientOptions,
): ApiCaller<any> {
return function callApi<T>(query: string, variables?: VariablesType): Promise<T> {
return post<T>(grab, uri, configuration, query, variables, undefined, options);
return post<T>(
grab,
uri,
configuration,
query,
variables,
options?.extraHeaders
? {
headers: options.extraHeaders,
}
: undefined,
options,
);
};
}

Expand Down

0 comments on commit e5ba781

Please sign in to comment.