Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down
6 changes: 5 additions & 1 deletion lib/internal/reference/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down
6 changes: 5 additions & 1 deletion lib/management/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down
3 changes: 2 additions & 1 deletion lib/management/v3/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RemoveStart } from "../../internal/type-utils";
export declare type Operations = reference.Operation;
export declare type RequestLine = keyof Operations;
export declare type NoParamsRequestLine = keyof OperationIndex.FilterOptionalParams<Operations>;
export declare type InferResponse<ReqLine extends RequestLine, Params> = NarrowResponse<Operations, Request<ReqLine, Params>, Operations[ReqLine]['response']>;
export declare type InferResponse<ReqLine extends RequestLine, Params extends Parameters> = NarrowResponse<Operations, Request<ReqLine, Params>, Operations[ReqLine]['response']>;
export declare type ResponseData<ReqLine extends RequestLine, Params = unknown> = Response.Success<ResolveResponse<ReqLine, Params>> extends {
readonly body: {
readonly data?: infer Data;
Expand All @@ -15,6 +15,7 @@ export declare type ResponseData<ReqLine extends RequestLine, Params = unknown>
export declare type Config = Omit<FetchTransportOptions, 'baseUrl' | 'headers'> & {
readonly storeHash: string;
readonly accessToken: string;
readonly customHeaders?: Record<string, string>;
};
export declare class Client<CustomEndpoints extends string = never> {
constructor(config: Config);
Expand Down
2 changes: 1 addition & 1 deletion lib/management/v3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Client {
typeof configOrTransport === 'function'
? configOrTransport
: (0, operation_1.fetchTransport)({
headers: { "X-Auth-Token": configOrTransport.accessToken },
headers: { "X-Auth-Token": configOrTransport.accessToken, ...(configOrTransport.customHeaders || {}) },
baseUrl: `https://api.bigcommerce.com/stores/${configOrTransport.storeHash}/v3`,
agent: configOrTransport.agent,
});
Expand Down
4 changes: 1 addition & 3 deletions lib/storefront/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ import { Const } from "../internal/type-utils";
export declare type Operations = reference.Operation;
export declare type RequestLine = keyof Operations;
export declare type NoParamsRequestLine = keyof OperationIndex.FilterOptionalParams<Operations>;
export declare type InferResponse<ReqLine extends RequestLine, Params> = NarrowResponse<Operations, Request<ReqLine, Params>, Operations[ReqLine]['response']>;
export declare type InferResponse<ReqLine extends RequestLine, Params extends Parameters> = NarrowResponse<Operations, Request<ReqLine, Params>, Operations[ReqLine]['response']>;
export declare type ResponseData<ReqLine extends RequestLine, Params = unknown> = Response.Success<ResolveResponse<ReqLine, Params>> extends {
readonly body: infer Data;
} ? Data : never;
export interface Client {
send<ReqLine extends NoParamsRequestLine>(requestLine: ReqLine): Promise<InferResponse<ReqLine, {}>>;
send<ReqLine extends RequestLine, Params extends Operation.MinimalInput<Operations[ReqLine]>>(requestLine: ReqLine, params: Const<Params & Operation.MinimalInput<Operations[ReqLine]>>): Promise<InferResponse<ReqLine, Params>>;
delete<Path extends NoParamsRequestPath<'DELETE'>>(requestLine: Path): Promise<ResponseData<`DELETE ${Path}`, {}> | null>;
delete<Path extends RequestPath<'DELETE'>, Params extends Operation.MinimalInput<Operations[`DELETE ${Path}`]>>(path: Path, params: Const<Params & Operation.MinimalInput<Operations[`DELETE ${Path}`]>>): Promise<ResponseData<`DELETE ${Path}`, Params> | null>;
get<Path extends NoParamsRequestPath<'GET'>>(requestLine: Path): Promise<ResponseData<`GET ${Path}`, {}> | null>;
get<Path extends RequestPath<'GET'>, Params extends Operation.MinimalInput<Operations[`GET ${Path}`]>>(path: Path, params: Const<Params & Operation.MinimalInput<Operations[`GET ${Path}`]>>): Promise<ResponseData<`GET ${Path}`, Params> | null>;
post<Path extends NoParamsRequestPath<'POST'>>(requestLine: Path): Promise<ResponseData<`POST ${Path}`, {}>>;
post<Path extends RequestPath<'POST'>, Params extends Operation.MinimalInput<Operations[`POST ${Path}`]>>(path: Path, params: Const<Params & Operation.MinimalInput<Operations[`POST ${Path}`]>>): Promise<ResponseData<`POST ${Path}`, Params>>;
put<Path extends NoParamsRequestPath<'PUT'>>(requestLine: Path): Promise<ResponseData<`PUT ${Path}`, {}>>;
put<Path extends RequestPath<'PUT'>, Params extends Operation.MinimalInput<Operations[`PUT ${Path}`]>>(path: Path, params: Const<Params & Operation.MinimalInput<Operations[`PUT ${Path}`]>>): Promise<ResponseData<`PUT ${Path}`, Params>>;
}
declare type ResolveResponse<ReqLine extends RequestLine, Params = unknown> = unknown extends Params ? Operations[ReqLine]['response'] : Params extends Parameters ? InferResponse<ReqLine, Params> : never;
Expand Down
2 changes: 1 addition & 1 deletion src/management/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type InferResponse<ReqLine extends RequestLine, Params extends Parameters
Operations[ReqLine]['response']
>;

export type ResponseData<ReqLine extends RequestLine, Params = unknown> =
export type ResponseData<ReqLine extends RequestLine, Params extends Parameters> =
Response.Success<ResolveResponse<ReqLine, Params>> extends { readonly body: infer Data }
? Data
: never;
Expand Down
3 changes: 2 additions & 1 deletion src/management/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type ResponseData<ReqLine extends RequestLine, Params = unknown> =
export type Config = Omit<FetchTransportOptions, 'baseUrl' | 'headers'> & {
readonly storeHash: string
readonly accessToken: string
readonly customHeaders?: Record<string, string>
};

export class Client<CustomEndpoints extends string = never> {
Expand All @@ -37,7 +38,7 @@ export class Client<CustomEndpoints extends string = never> {
typeof configOrTransport === 'function'
? configOrTransport
: fetchTransport({
headers: { "X-Auth-Token": configOrTransport.accessToken },
headers: { "X-Auth-Token": configOrTransport.accessToken, ...(configOrTransport.customHeaders || {}) },
baseUrl: `https://api.bigcommerce.com/stores/${configOrTransport.storeHash}/v3`,
agent: configOrTransport.agent,
});
Expand Down