@commercelayer/sdk
Version:
Commerce Layer Javascript SDK
1,163 lines (1,142 loc) • 763 kB
TypeScript
type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
type FetchResponse = any;
type FetchRequestOptions = RequestInit;
declare class FetchError extends Error {
#private;
static isFetchError: (error: any) => error is FetchError;
constructor(status: number, statusText: string, body?: any, request?: FetchRequestOptions);
get errors(): any[] | undefined;
get status(): number;
get statusText(): string;
get request(): Partial<FetchRequestOptions> | undefined;
}
type InterceptorEventManager<S extends (RequestInterceptor | ResponseInterceptor), F extends (ErrorInterceptor | ResponseInterceptor)> = {
onSuccess?: S;
onFailure?: F;
};
type RequestEventManager = InterceptorEventManager<RequestInterceptor, ErrorInterceptor>;
type ResponseEventManager = InterceptorEventManager<ResponseInterceptor, ErrorInterceptor>;
type ErrorEventManager = InterceptorEventManager<ResponseInterceptor, ResponseInterceptor>;
type InterceptorManager = {
request?: RequestEventManager;
response?: ResponseEventManager;
rawReader?: ErrorEventManager;
};
type RequestObj = {
url: URL;
options: FetchRequestOptions;
};
type RequestInterceptor = (request: RequestObj) => RequestObj | Promise<RequestObj>;
type ResponseObj = Response;
type ResponseInterceptor = (response: ResponseObj) => ResponseObj | Promise<ResponseObj>;
type ApiHeadersList = 'x-ratelimit-limit' | 'x-ratelimit-interval' | 'x-ratelimit-remaining';
type ApiHeaders = {
[key in ApiHeadersList]: string | number | boolean;
};
type HeadersObj = Record<string, string> | ApiHeaders;
type ErrorObj = FetchError;
type ErrorInterceptor = (error: ErrorObj) => ErrorObj | Promise<ErrorObj>;
type InterceptorType = 'request' | 'response';
type RawResponseReader = {
id: number;
rawResponse?: any;
headers?: HeadersObj;
ok: boolean;
};
type RequestParams = Record<string, string | number | boolean>;
type RequestHeaders = Record<string, string>;
type RefreshToken = (expiredToken: string) => Promise<string>;
type RequestConfig = {
timeout?: number;
params?: RequestParams;
headers?: RequestHeaders;
userAgent?: string;
fetch?: Fetch;
refreshToken?: RefreshToken;
};
type ApiConfig = {
organization?: string;
domain?: string;
accessToken: string;
};
type ApiClientInitConfig = ApiConfig & RequestConfig;
type ApiClientConfig = Partial<ApiClientInitConfig>;
type Method = 'GET' | 'DELETE' | 'POST' | 'PUT' | 'PATCH';
declare class ApiClient {
#private;
static create(options: ApiClientInitConfig): ApiClient;
private constructor();
get interceptors(): InterceptorManager;
get requestHeaders(): RequestHeaders;
config(config: ApiClientConfig): this;
userAgent(userAgent: string): this;
request(method: Method, path: string, body?: any, options?: ApiClientConfig): Promise<FetchResponse>;
private customHeaders;
get currentAccessToken(): string;
}
type CreateArrayWithLengthX<LENGTH extends number, ACC extends unknown[] = []> = ACC['length'] extends LENGTH ? ACC : CreateArrayWithLengthX<LENGTH, [...ACC, 1]>;
type NumericNumberRange<START_ARR extends number[], END extends number, ACC extends number = never> = START_ARR['length'] extends END ? ACC | END : NumericNumberRange<[...START_ARR, 1], END, ACC | START_ARR['length']>;
type PositiveNumberRange<MAX extends number> = NumericNumberRange<CreateArrayWithLengthX<1>, MAX>;
type StringKey<T> = Extract<keyof T, string>;
type QueryResType<T extends Resource> = T['type'];
type QueryInclude = string[];
type QueryResourceFields<R extends ResourceTypeLock> = keyof ResourceFields[R];
type QueryArrayFields<R extends Resource> = Array<QueryResourceFields<QueryResType<R>>>;
type QueryRecordFields = {
[key in keyof ResourceFields]?: Array<(QueryResourceFields<key>)>;
};
type QueryFields<R extends Resource> = QueryArrayFields<R> | QueryRecordFields;
interface QueryParamsRetrieve<R extends Resource = Resource> {
include?: QueryInclude;
fields?: QueryFields<R>;
}
type QuerySortType = 'asc' | 'desc';
type QueryResourceSortable<R extends Resource> = ResourceSortFields[QueryResType<R>];
type QueryResourceSortableFields<R extends Resource> = StringKey<QueryResourceSortable<R>>;
type QueryArraySortable<R extends Resource> = Array<QueryResourceSortableFields<R> | `-${QueryResourceSortableFields<R>}`>;
type QueryRecordSortable<R extends Resource> = Partial<Record<keyof QueryResourceSortable<R>, QuerySortType>>;
type QuerySort<R extends Resource> = QueryArraySortable<R> | QueryRecordSortable<R>;
type QueryFilter = Record<string, string | number | boolean | object | Array<string | number>>;
type QueryPageNumber = number;
type QueryPageSize = PositiveNumberRange<25>;
interface QueryParamsList<R extends Resource = Resource> extends QueryParamsRetrieve<R> {
sort?: QuerySort<R>;
filters?: QueryFilter;
pageNumber?: QueryPageNumber;
pageSize?: QueryPageSize;
}
type QueryParams<R extends Resource = Resource> = QueryParamsRetrieve<R> | QueryParamsList<R>;
declare const isParamsList: <R extends Resource>(params: any) => params is QueryParamsList<R>;
type QueryStringParams = Record<string, string>;
declare const generateQueryStringParams: <R extends Resource>(params: QueryParams<R> | undefined, res: string | ResourceType) => QueryStringParams;
declare const generateSearchString: (params?: QueryStringParams, questionMark?: boolean) => string;
type ResourceNull = {
id: null;
} & ResourceType;
type ResourceRel = ResourceId | ResourceNull;
type Metadata = Record<string, any>;
interface ResourceType {
readonly type: ResourceTypeLock;
}
interface ResourceId extends ResourceType {
readonly id: string;
}
interface ResourceBase {
reference?: string | null;
reference_origin?: string | null;
metadata?: Metadata;
}
interface Resource extends ResourceBase, ResourceId {
readonly created_at: string;
readonly updated_at: string;
}
interface ResourceCreate extends ResourceBase {
}
interface ResourceUpdate extends ResourceBase {
readonly id: string;
}
type ListMeta = {
readonly pageCount: number;
readonly recordCount: number;
readonly currentPage: number;
readonly recordsPerPage: number;
};
declare class ListResponse<R extends Resource = Resource> extends Array<R> {
readonly meta: ListMeta;
constructor(meta: ListMeta, data: R[]);
first(): R | undefined;
last(): R | undefined;
get(index: number): R | undefined;
hasNextPage(): boolean;
hasPrevPage(): boolean;
getRecordCount(): number;
getPageCount(): number;
get recordCount(): number;
get pageCount(): number;
}
type ResourceSort = Pick<Resource, 'id' | 'reference' | 'reference_origin' | 'created_at' | 'updated_at'>;
type ResourceFilter = Pick<Resource, 'id' | 'reference' | 'reference_origin' | 'metadata' | 'created_at' | 'updated_at'>;
type ResourceAdapterConfig = {};
type ResourcesInitConfig = ResourceAdapterConfig & ApiClientInitConfig;
type ResourcesConfig = Partial<ResourcesInitConfig>;
declare const apiResourceAdapter: (config: ResourcesInitConfig) => ResourceAdapter;
declare class ResourceAdapter {
#private;
constructor(config: ResourcesInitConfig);
private localConfig;
config(config: ResourcesConfig): this;
get client(): Readonly<ApiClient>;
singleton<R extends Resource>(resource: ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig, path?: string): Promise<R>;
retrieve<R extends Resource>(resource: ResourceId, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
list<R extends Resource>(resource: ResourceType, params?: QueryParamsList<R>, options?: ResourcesConfig): Promise<ListResponse<R>>;
create<C extends ResourceCreate, R extends Resource>(resource: C & ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
update<U extends ResourceUpdate, R extends Resource>(resource: U & ResourceId, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
delete(resource: ResourceId, options?: ResourcesConfig): Promise<void>;
fetch<R extends Resource>(resource: string | ResourceType, path: string, params?: QueryParams<R>, options?: ResourcesConfig): Promise<R | ListResponse<R>>;
}
declare abstract class ApiResourceBase<R extends Resource> {
static readonly TYPE: ResourceTypeLock;
protected readonly resources: ResourceAdapter;
constructor(adapter: ResourceAdapter);
abstract relationship(id: string | ResourceId | null): ResourceRel;
protected relationshipOneToOne<RR extends ResourceRel>(id: string | ResourceId | null): RR;
protected relationshipOneToMany<RR extends ResourceRel>(...ids: string[]): RR[];
abstract type(): ResourceTypeLock;
protected path(): string;
update(resource: ResourceUpdate, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
}
declare abstract class ApiResource<R extends Resource> extends ApiResourceBase<R> {
retrieve(id: string | ResourceId, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
list(params?: QueryParamsList<R>, options?: ResourcesConfig): Promise<ListResponse<R>>;
count(filter?: QueryFilter | QueryParamsList<R>, options?: ResourcesConfig): Promise<number>;
}
declare abstract class ApiSingleton<R extends Resource> extends ApiResourceBase<R> {
retrieve(params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
}
type TagType = 'tags';
type TagRel$l = ResourceRel & {
type: TagType;
};
type TagSort = Pick<Tag, 'id' | 'name'> & ResourceSort;
interface Tag extends Resource {
readonly type: TagType;
/**
* The tag name.
* @example ```"new_campaign"```
*/
name: string;
}
interface TagCreate extends ResourceCreate {
/**
* The tag name.
* @example ```"new_campaign"```
*/
name: string;
}
interface TagUpdate extends ResourceUpdate {
/**
* The tag name.
* @example ```"new_campaign"```
*/
name?: string | null;
}
declare class Tags extends ApiResource<Tag> {
static readonly TYPE: TagType;
create(resource: TagCreate, params?: QueryParamsRetrieve<Tag>, options?: ResourcesConfig): Promise<Tag>;
update(resource: TagUpdate, params?: QueryParamsRetrieve<Tag>, options?: ResourcesConfig): Promise<Tag>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
isTag(resource: any): resource is Tag;
relationship(id: string | ResourceId | null): TagRel$l;
relationshipToMany(...ids: string[]): TagRel$l[];
type(): TagType;
}
type VersionType = 'versions';
type VersionRel = ResourceRel & {
type: VersionType;
};
type VersionSort = Pick<Version, 'id'> & ResourceSort;
interface Version extends Resource {
readonly type: VersionType;
/**
* The type of the versioned resource.
* @example ```"orders"```
*/
resource_type?: string | null;
/**
* The versioned resource id.
* @example ```"PzdJhdLdYV"```
*/
resource_id?: string | null;
/**
* The event which generates the version.
* @example ```"update"```
*/
event?: string | null;
/**
* The object changes payload.
* @example ```{"status":["draft","placed"]}```
*/
changes?: Record<string, any> | null;
/**
* Information about who triggered the change.
* @example ```{"application":{"id":"DNOPYiZYpn","kind":"sales_channel","public":true},"owner":{"id":"yQQrBhLBmQ","type":"Customer"}}```
*/
who?: Record<string, any> | null;
}
declare class Versions extends ApiResource<Version> {
static readonly TYPE: VersionType;
isVersion(resource: any): resource is Version;
relationship(id: string | ResourceId | null): VersionRel;
relationshipToMany(...ids: string[]): VersionRel[];
type(): VersionType;
}
type ShippingCategoryType = 'shipping_categories';
type ShippingCategoryRel$4 = ResourceRel & {
type: ShippingCategoryType;
};
type ShippingCategorySort = Pick<ShippingCategory, 'id' | 'name' | 'code'> & ResourceSort;
interface ShippingCategory extends Resource {
readonly type: ShippingCategoryType;
/**
* The shipping category name.
* @example ```"Merchandise"```
*/
name: string;
/**
* A string that you can use to identify the shipping category (must be unique within the environment).
* @example ```"europe1"```
*/
code?: string | null;
skus?: Sku[] | null;
attachments?: Attachment[] | null;
versions?: Version[] | null;
}
interface ShippingCategoryCreate extends ResourceCreate {
/**
* The shipping category name.
* @example ```"Merchandise"```
*/
name: string;
/**
* A string that you can use to identify the shipping category (must be unique within the environment).
* @example ```"europe1"```
*/
code?: string | null;
}
interface ShippingCategoryUpdate extends ResourceUpdate {
/**
* The shipping category name.
* @example ```"Merchandise"```
*/
name?: string | null;
/**
* A string that you can use to identify the shipping category (must be unique within the environment).
* @example ```"europe1"```
*/
code?: string | null;
}
declare class ShippingCategories extends ApiResource<ShippingCategory> {
static readonly TYPE: ShippingCategoryType;
create(resource: ShippingCategoryCreate, params?: QueryParamsRetrieve<ShippingCategory>, options?: ResourcesConfig): Promise<ShippingCategory>;
update(resource: ShippingCategoryUpdate, params?: QueryParamsRetrieve<ShippingCategory>, options?: ResourcesConfig): Promise<ShippingCategory>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
skus(shippingCategoryId: string | ShippingCategory, params?: QueryParamsList<Sku>, options?: ResourcesConfig): Promise<ListResponse<Sku>>;
attachments(shippingCategoryId: string | ShippingCategory, params?: QueryParamsList<Attachment>, options?: ResourcesConfig): Promise<ListResponse<Attachment>>;
versions(shippingCategoryId: string | ShippingCategory, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isShippingCategory(resource: any): resource is ShippingCategory;
relationship(id: string | ResourceId | null): ShippingCategoryRel$4;
relationshipToMany(...ids: string[]): ShippingCategoryRel$4[];
type(): ShippingCategoryType;
}
type InventoryReturnLocationType = 'inventory_return_locations';
type InventoryReturnLocationRel = ResourceRel & {
type: InventoryReturnLocationType;
};
type StockLocationRel$a = ResourceRel & {
type: StockLocationType;
};
type InventoryModelRel$4 = ResourceRel & {
type: InventoryModelType;
};
type InventoryReturnLocationSort = Pick<InventoryReturnLocation, 'id' | 'priority'> & ResourceSort;
interface InventoryReturnLocation extends Resource {
readonly type: InventoryReturnLocationType;
/**
* The inventory return location priority within the associated invetory model.
* @example ```1```
*/
priority: number;
stock_location?: StockLocation | null;
inventory_model?: InventoryModel | null;
versions?: Version[] | null;
}
interface InventoryReturnLocationCreate extends ResourceCreate {
/**
* The inventory return location priority within the associated invetory model.
* @example ```1```
*/
priority: number;
stock_location: StockLocationRel$a;
inventory_model: InventoryModelRel$4;
}
interface InventoryReturnLocationUpdate extends ResourceUpdate {
/**
* The inventory return location priority within the associated invetory model.
* @example ```1```
*/
priority?: number | null;
stock_location?: StockLocationRel$a | null;
inventory_model?: InventoryModelRel$4 | null;
}
declare class InventoryReturnLocations extends ApiResource<InventoryReturnLocation> {
static readonly TYPE: InventoryReturnLocationType;
create(resource: InventoryReturnLocationCreate, params?: QueryParamsRetrieve<InventoryReturnLocation>, options?: ResourcesConfig): Promise<InventoryReturnLocation>;
update(resource: InventoryReturnLocationUpdate, params?: QueryParamsRetrieve<InventoryReturnLocation>, options?: ResourcesConfig): Promise<InventoryReturnLocation>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
stock_location(inventoryReturnLocationId: string | InventoryReturnLocation, params?: QueryParamsRetrieve<StockLocation>, options?: ResourcesConfig): Promise<StockLocation>;
inventory_model(inventoryReturnLocationId: string | InventoryReturnLocation, params?: QueryParamsRetrieve<InventoryModel>, options?: ResourcesConfig): Promise<InventoryModel>;
versions(inventoryReturnLocationId: string | InventoryReturnLocation, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isInventoryReturnLocation(resource: any): resource is InventoryReturnLocation;
relationship(id: string | ResourceId | null): InventoryReturnLocationRel;
relationshipToMany(...ids: string[]): InventoryReturnLocationRel[];
type(): InventoryReturnLocationType;
}
type InventoryModelType = 'inventory_models';
type InventoryModelRel$3 = ResourceRel & {
type: InventoryModelType;
};
type InventoryModelSort = Pick<InventoryModel, 'id' | 'name' | 'strategy' | 'stock_locations_cutoff' | 'stock_reservation_cutoff'> & ResourceSort;
interface InventoryModel extends Resource {
readonly type: InventoryModelType;
/**
* The inventory model's internal name.
* @example ```"EU Inventory Model"```
*/
name: string;
/**
* The inventory model's shipping strategy: one between 'no_split' (default), 'split_shipments', 'ship_from_primary' and 'ship_from_first_available_or_primary'.
* @example ```"no_split"```
*/
strategy?: string | null;
/**
* The maximum number of stock locations used for inventory computation.
* @example ```3```
*/
stock_locations_cutoff?: number | null;
/**
* The duration in seconds of the generated stock reservations.
* @example ```3600```
*/
stock_reservation_cutoff?: number | null;
/**
* Indicates if the the stock transfers must be put on hold automatically with the associated shipment.
* @example ```true```
*/
put_stock_transfers_on_hold?: boolean | null;
/**
* Indicates if the the stock will be decremented manually after the order approval.
* @example ```true```
*/
manual_stock_decrement?: boolean | null;
inventory_stock_locations?: InventoryStockLocation[] | null;
inventory_return_locations?: InventoryReturnLocation[] | null;
attachments?: Attachment[] | null;
versions?: Version[] | null;
}
interface InventoryModelCreate extends ResourceCreate {
/**
* The inventory model's internal name.
* @example ```"EU Inventory Model"```
*/
name: string;
/**
* The inventory model's shipping strategy: one between 'no_split' (default), 'split_shipments', 'ship_from_primary' and 'ship_from_first_available_or_primary'.
* @example ```"no_split"```
*/
strategy?: string | null;
/**
* The maximum number of stock locations used for inventory computation.
* @example ```3```
*/
stock_locations_cutoff?: number | null;
/**
* The duration in seconds of the generated stock reservations.
* @example ```3600```
*/
stock_reservation_cutoff?: number | null;
/**
* Indicates if the the stock transfers must be put on hold automatically with the associated shipment.
* @example ```true```
*/
put_stock_transfers_on_hold?: boolean | null;
/**
* Indicates if the the stock will be decremented manually after the order approval.
* @example ```true```
*/
manual_stock_decrement?: boolean | null;
}
interface InventoryModelUpdate extends ResourceUpdate {
/**
* The inventory model's internal name.
* @example ```"EU Inventory Model"```
*/
name?: string | null;
/**
* The inventory model's shipping strategy: one between 'no_split' (default), 'split_shipments', 'ship_from_primary' and 'ship_from_first_available_or_primary'.
* @example ```"no_split"```
*/
strategy?: string | null;
/**
* The maximum number of stock locations used for inventory computation.
* @example ```3```
*/
stock_locations_cutoff?: number | null;
/**
* The duration in seconds of the generated stock reservations.
* @example ```3600```
*/
stock_reservation_cutoff?: number | null;
/**
* Indicates if the the stock transfers must be put on hold automatically with the associated shipment.
* @example ```true```
*/
put_stock_transfers_on_hold?: boolean | null;
/**
* Indicates if the the stock will be decremented manually after the order approval.
* @example ```true```
*/
manual_stock_decrement?: boolean | null;
}
declare class InventoryModels extends ApiResource<InventoryModel> {
static readonly TYPE: InventoryModelType;
create(resource: InventoryModelCreate, params?: QueryParamsRetrieve<InventoryModel>, options?: ResourcesConfig): Promise<InventoryModel>;
update(resource: InventoryModelUpdate, params?: QueryParamsRetrieve<InventoryModel>, options?: ResourcesConfig): Promise<InventoryModel>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
inventory_stock_locations(inventoryModelId: string | InventoryModel, params?: QueryParamsList<InventoryStockLocation>, options?: ResourcesConfig): Promise<ListResponse<InventoryStockLocation>>;
inventory_return_locations(inventoryModelId: string | InventoryModel, params?: QueryParamsList<InventoryReturnLocation>, options?: ResourcesConfig): Promise<ListResponse<InventoryReturnLocation>>;
attachments(inventoryModelId: string | InventoryModel, params?: QueryParamsList<Attachment>, options?: ResourcesConfig): Promise<ListResponse<Attachment>>;
versions(inventoryModelId: string | InventoryModel, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isInventoryModel(resource: any): resource is InventoryModel;
relationship(id: string | ResourceId | null): InventoryModelRel$3;
relationshipToMany(...ids: string[]): InventoryModelRel$3[];
type(): InventoryModelType;
}
type InventoryStockLocationType = 'inventory_stock_locations';
type InventoryStockLocationRel$1 = ResourceRel & {
type: InventoryStockLocationType;
};
type StockLocationRel$9 = ResourceRel & {
type: StockLocationType;
};
type InventoryModelRel$2 = ResourceRel & {
type: InventoryModelType;
};
type InventoryStockLocationSort = Pick<InventoryStockLocation, 'id' | 'priority' | 'on_hold'> & ResourceSort;
interface InventoryStockLocation extends Resource {
readonly type: InventoryStockLocationType;
/**
* The stock location priority within the associated invetory model.
* @example ```1```
*/
priority: number;
/**
* Indicates if the shipment should be put on hold if fulfilled from the associated stock location. This is useful to manage use cases like back-orders, pre-orders or personalized orders that need to be customized before being fulfilled.
*/
on_hold?: boolean | null;
stock_location?: StockLocation | null;
inventory_model?: InventoryModel | null;
versions?: Version[] | null;
}
interface InventoryStockLocationCreate extends ResourceCreate {
/**
* The stock location priority within the associated invetory model.
* @example ```1```
*/
priority: number;
/**
* Indicates if the shipment should be put on hold if fulfilled from the associated stock location. This is useful to manage use cases like back-orders, pre-orders or personalized orders that need to be customized before being fulfilled.
*/
on_hold?: boolean | null;
stock_location: StockLocationRel$9;
inventory_model: InventoryModelRel$2;
}
interface InventoryStockLocationUpdate extends ResourceUpdate {
/**
* The stock location priority within the associated invetory model.
* @example ```1```
*/
priority?: number | null;
/**
* Indicates if the shipment should be put on hold if fulfilled from the associated stock location. This is useful to manage use cases like back-orders, pre-orders or personalized orders that need to be customized before being fulfilled.
*/
on_hold?: boolean | null;
stock_location?: StockLocationRel$9 | null;
inventory_model?: InventoryModelRel$2 | null;
}
declare class InventoryStockLocations extends ApiResource<InventoryStockLocation> {
static readonly TYPE: InventoryStockLocationType;
create(resource: InventoryStockLocationCreate, params?: QueryParamsRetrieve<InventoryStockLocation>, options?: ResourcesConfig): Promise<InventoryStockLocation>;
update(resource: InventoryStockLocationUpdate, params?: QueryParamsRetrieve<InventoryStockLocation>, options?: ResourcesConfig): Promise<InventoryStockLocation>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
stock_location(inventoryStockLocationId: string | InventoryStockLocation, params?: QueryParamsRetrieve<StockLocation>, options?: ResourcesConfig): Promise<StockLocation>;
inventory_model(inventoryStockLocationId: string | InventoryStockLocation, params?: QueryParamsRetrieve<InventoryModel>, options?: ResourcesConfig): Promise<InventoryModel>;
versions(inventoryStockLocationId: string | InventoryStockLocation, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isInventoryStockLocation(resource: any): resource is InventoryStockLocation;
relationship(id: string | ResourceId | null): InventoryStockLocationRel$1;
relationshipToMany(...ids: string[]): InventoryStockLocationRel$1[];
type(): InventoryStockLocationType;
}
type CustomerGroupType = 'customer_groups';
type CustomerGroupRel$3 = ResourceRel & {
type: CustomerGroupType;
};
type CustomerGroupSort = Pick<CustomerGroup, 'id' | 'name' | 'code'> & ResourceSort;
interface CustomerGroup extends Resource {
readonly type: CustomerGroupType;
/**
* The customer group's internal name.
* @example ```"VIP"```
*/
name: string;
/**
* A string that you can use to identify the customer group (must be unique within the environment).
* @example ```"vip1"```
*/
code?: string | null;
customers?: Customer[] | null;
markets?: Market[] | null;
attachments?: Attachment[] | null;
versions?: Version[] | null;
}
interface CustomerGroupCreate extends ResourceCreate {
/**
* The customer group's internal name.
* @example ```"VIP"```
*/
name: string;
/**
* A string that you can use to identify the customer group (must be unique within the environment).
* @example ```"vip1"```
*/
code?: string | null;
}
interface CustomerGroupUpdate extends ResourceUpdate {
/**
* The customer group's internal name.
* @example ```"VIP"```
*/
name?: string | null;
/**
* A string that you can use to identify the customer group (must be unique within the environment).
* @example ```"vip1"```
*/
code?: string | null;
}
declare class CustomerGroups extends ApiResource<CustomerGroup> {
static readonly TYPE: CustomerGroupType;
create(resource: CustomerGroupCreate, params?: QueryParamsRetrieve<CustomerGroup>, options?: ResourcesConfig): Promise<CustomerGroup>;
update(resource: CustomerGroupUpdate, params?: QueryParamsRetrieve<CustomerGroup>, options?: ResourcesConfig): Promise<CustomerGroup>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
customers(customerGroupId: string | CustomerGroup, params?: QueryParamsList<Customer>, options?: ResourcesConfig): Promise<ListResponse<Customer>>;
markets(customerGroupId: string | CustomerGroup, params?: QueryParamsList<Market>, options?: ResourcesConfig): Promise<ListResponse<Market>>;
attachments(customerGroupId: string | CustomerGroup, params?: QueryParamsList<Attachment>, options?: ResourcesConfig): Promise<ListResponse<Attachment>>;
versions(customerGroupId: string | CustomerGroup, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isCustomerGroup(resource: any): resource is CustomerGroup;
relationship(id: string | ResourceId | null): CustomerGroupRel$3;
relationshipToMany(...ids: string[]): CustomerGroupRel$3[];
type(): CustomerGroupType;
}
type EventCallbackType = 'event_callbacks';
type EventCallbackRel = ResourceRel & {
type: EventCallbackType;
};
type EventCallbackSort = Pick<EventCallback, 'id' | 'response_code' | 'response_message'> & ResourceSort;
interface EventCallback extends Resource {
readonly type: EventCallbackType;
/**
* The URI of the callback, inherited by the associated webhook.
* @example ```"https://yourapp.com/webhooks"```
*/
callback_url: string;
/**
* The payload sent to the callback endpoint, including the event affected resource and the specified includes.
* @example ```{"data":{"attributes":{"id":"PYWehaoXJj","type":"orders"}}}```
*/
payload?: Record<string, any> | null;
/**
* The HTTP response code of the callback endpoint.
* @example ```"200"```
*/
response_code?: string | null;
/**
* The HTTP response message of the callback endpoint.
* @example ```"OK"```
*/
response_message?: string | null;
webhook?: Webhook | null;
}
declare class EventCallbacks extends ApiResource<EventCallback> {
static readonly TYPE: EventCallbackType;
webhook(eventCallbackId: string | EventCallback, params?: QueryParamsRetrieve<Webhook>, options?: ResourcesConfig): Promise<Webhook>;
isEventCallback(resource: any): resource is EventCallback;
relationship(id: string | ResourceId | null): EventCallbackRel;
relationshipToMany(...ids: string[]): EventCallbackRel[];
type(): EventCallbackType;
}
type WebhookType = 'webhooks';
type WebhookRel = ResourceRel & {
type: WebhookType;
};
type WebhookSort = Pick<Webhook, 'id' | 'disabled_at' | 'circuit_state' | 'circuit_failure_count'> & ResourceSort;
interface Webhook extends Resource {
readonly type: WebhookType;
/**
* Unique name for the webhook.
* @example ```"myorg-orders.place"```
*/
name?: string | null;
/**
* The identifier of the resource/event that will trigger the webhook.
* @example ```"orders.place"```
*/
topic: string;
/**
* URI where the webhook subscription should send the POST request when the event occurs.
* @example ```"https://yourapp.com/webhooks"```
*/
callback_url: string;
/**
* List of related resources that should be included in the webhook body.
* @example ```["customer","shipping_address","billing_address"]```
*/
include_resources?: string[] | null;
/**
* Time at which this resource was disabled.
* @example ```"2018-01-01T12:00:00.000Z"```
*/
disabled_at?: string | null;
/**
* The circuit breaker state, by default it is 'closed'. It can become 'open' once the number of consecutive failures overlaps the specified threshold, in such case no further calls to the failing callback are made.
* @example ```"closed"```
*/
circuit_state?: string | null;
/**
* The number of consecutive failures recorded by the circuit breaker associated to this resource, will be reset on first successful call to callback.
* @example ```5```
*/
circuit_failure_count?: number | null;
/**
* The shared secret used to sign the external request payload.
* @example ```"1c0994cc4e996e8c6ee56a2198f66f3c"```
*/
shared_secret: string;
last_event_callbacks?: EventCallback[] | null;
versions?: Version[] | null;
}
interface WebhookCreate extends ResourceCreate {
/**
* Unique name for the webhook.
* @example ```"myorg-orders.place"```
*/
name?: string | null;
/**
* The identifier of the resource/event that will trigger the webhook.
* @example ```"orders.place"```
*/
topic: string;
/**
* URI where the webhook subscription should send the POST request when the event occurs.
* @example ```"https://yourapp.com/webhooks"```
*/
callback_url: string;
/**
* List of related resources that should be included in the webhook body.
* @example ```["customer","shipping_address","billing_address"]```
*/
include_resources?: string[] | null;
/**
* Send this attribute if you want to mark this resource as disabled.
* @example ```true```
*/
_disable?: boolean | null;
/**
* Send this attribute if you want to mark this resource as enabled.
* @example ```true```
*/
_enable?: boolean | null;
}
interface WebhookUpdate extends ResourceUpdate {
/**
* Unique name for the webhook.
* @example ```"myorg-orders.place"```
*/
name?: string | null;
/**
* The identifier of the resource/event that will trigger the webhook.
* @example ```"orders.place"```
*/
topic?: string | null;
/**
* URI where the webhook subscription should send the POST request when the event occurs.
* @example ```"https://yourapp.com/webhooks"```
*/
callback_url?: string | null;
/**
* List of related resources that should be included in the webhook body.
* @example ```["customer","shipping_address","billing_address"]```
*/
include_resources?: string[] | null;
/**
* Send this attribute if you want to mark this resource as disabled.
* @example ```true```
*/
_disable?: boolean | null;
/**
* Send this attribute if you want to mark this resource as enabled.
* @example ```true```
*/
_enable?: boolean | null;
/**
* Send this attribute if you want to reset the circuit breaker associated to this resource to 'closed' state and zero failures count. Cannot be passed by sales channels.
* @example ```true```
*/
_reset_circuit?: boolean | null;
}
declare class Webhooks extends ApiResource<Webhook> {
static readonly TYPE: WebhookType;
create(resource: WebhookCreate, params?: QueryParamsRetrieve<Webhook>, options?: ResourcesConfig): Promise<Webhook>;
update(resource: WebhookUpdate, params?: QueryParamsRetrieve<Webhook>, options?: ResourcesConfig): Promise<Webhook>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
last_event_callbacks(webhookId: string | Webhook, params?: QueryParamsList<EventCallback>, options?: ResourcesConfig): Promise<ListResponse<EventCallback>>;
versions(webhookId: string | Webhook, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
_disable(id: string | Webhook, params?: QueryParamsRetrieve<Webhook>, options?: ResourcesConfig): Promise<Webhook>;
_enable(id: string | Webhook, params?: QueryParamsRetrieve<Webhook>, options?: ResourcesConfig): Promise<Webhook>;
_reset_circuit(id: string | Webhook, params?: QueryParamsRetrieve<Webhook>, options?: ResourcesConfig): Promise<Webhook>;
isWebhook(resource: any): resource is Webhook;
relationship(id: string | ResourceId | null): WebhookRel;
relationshipToMany(...ids: string[]): WebhookRel[];
type(): WebhookType;
}
type EventType = 'events';
type EventRel = ResourceRel & {
type: EventType;
};
type EventSort = Pick<Event, 'id' | 'name'> & ResourceSort;
interface Event extends Resource {
readonly type: EventType;
/**
* The event's internal name.
* @example ```"orders.create"```
*/
name: string;
webhooks?: Webhook[] | null;
last_event_callbacks?: EventCallback[] | null;
}
interface EventUpdate extends ResourceUpdate {
/**
* Send this attribute if you want to force webhooks execution for this event. Cannot be passed by sales channels.
* @example ```true```
*/
_trigger?: boolean | null;
}
declare class Events extends ApiResource<Event> {
static readonly TYPE: EventType;
update(resource: EventUpdate, params?: QueryParamsRetrieve<Event>, options?: ResourcesConfig): Promise<Event>;
webhooks(eventId: string | Event, params?: QueryParamsList<Webhook>, options?: ResourcesConfig): Promise<ListResponse<Webhook>>;
last_event_callbacks(eventId: string | Event, params?: QueryParamsList<EventCallback>, options?: ResourcesConfig): Promise<ListResponse<EventCallback>>;
_trigger(id: string | Event, params?: QueryParamsRetrieve<Event>, options?: ResourcesConfig): Promise<Event>;
isEvent(resource: any): resource is Event;
relationship(id: string | ResourceId | null): EventRel;
relationshipToMany(...ids: string[]): EventRel[];
type(): EventType;
}
type CustomerAddressType = 'customer_addresses';
type CustomerAddressRel = ResourceRel & {
type: CustomerAddressType;
};
type CustomerRel$8 = ResourceRel & {
type: CustomerType;
};
type AddressRel$5 = ResourceRel & {
type: AddressType;
};
type CustomerAddressSort = Pick<CustomerAddress, 'id'> & ResourceSort;
interface CustomerAddress extends Resource {
readonly type: CustomerAddressType;
/**
* Returns the associated address' name.
* @example ```"John Smith, 2883 Geraldine Lane Apt.23, 10013 New York NY (US) (212) 646-338-1228"```
*/
name?: string | null;
/**
* The email of the customer associated to the address.
* @example ```"john@example.com"```
*/
customer_email: string;
customer?: Customer | null;
address?: Address | null;
events?: Event[] | null;
versions?: Version[] | null;
}
interface CustomerAddressCreate extends ResourceCreate {
/**
* The email of the customer associated to the address.
* @example ```"john@example.com"```
*/
customer_email: string;
customer: CustomerRel$8;
address: AddressRel$5;
}
interface CustomerAddressUpdate extends ResourceUpdate {
customer?: CustomerRel$8 | null;
address?: AddressRel$5 | null;
}
declare class CustomerAddresses extends ApiResource<CustomerAddress> {
static readonly TYPE: CustomerAddressType;
create(resource: CustomerAddressCreate, params?: QueryParamsRetrieve<CustomerAddress>, options?: ResourcesConfig): Promise<CustomerAddress>;
update(resource: CustomerAddressUpdate, params?: QueryParamsRetrieve<CustomerAddress>, options?: ResourcesConfig): Promise<CustomerAddress>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
customer(customerAddressId: string | CustomerAddress, params?: QueryParamsRetrieve<Customer>, options?: ResourcesConfig): Promise<Customer>;
address(customerAddressId: string | CustomerAddress, params?: QueryParamsRetrieve<Address>, options?: ResourcesConfig): Promise<Address>;
events(customerAddressId: string | CustomerAddress, params?: QueryParamsList<Event>, options?: ResourcesConfig): Promise<ListResponse<Event>>;
versions(customerAddressId: string | CustomerAddress, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isCustomerAddress(resource: any): resource is CustomerAddress;
relationship(id: string | ResourceId | null): CustomerAddressRel;
relationshipToMany(...ids: string[]): CustomerAddressRel[];
type(): CustomerAddressType;
}
type PaymentGatewayType = 'payment_gateways';
type PaymentGatewayRel$1 = ResourceRel & {
type: PaymentGatewayType;
};
type PaymentGatewaySort = Pick<PaymentGateway, 'id' | 'name'> & ResourceSort;
interface PaymentGateway extends Resource {
readonly type: PaymentGatewayType;
/**
* The payment gateway's internal name.
* @example ```"US payment gateway"```
*/
name: string;
payment_methods?: PaymentMethod[] | null;
versions?: Version[] | null;
}
declare class PaymentGateways extends ApiResource<PaymentGateway> {
static readonly TYPE: PaymentGatewayType;
payment_methods(paymentGatewayId: string | PaymentGateway, params?: QueryParamsList<PaymentMethod>, options?: ResourcesConfig): Promise<ListResponse<PaymentMethod>>;
versions(paymentGatewayId: string | PaymentGateway, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isPaymentGateway(resource: any): resource is PaymentGateway;
relationship(id: string | ResourceId | null): PaymentGatewayRel$1;
relationshipToMany(...ids: string[]): PaymentGatewayRel$1[];
type(): PaymentGatewayType;
}
type StoreType = 'stores';
type StoreRel$2 = ResourceRel & {
type: StoreType;
};
type MarketRel$j = ResourceRel & {
type: MarketType;
};
type MerchantRel$3 = ResourceRel & {
type: MerchantType;
};
type StockLocationRel$8 = ResourceRel & {
type: StockLocationType;
};
type StoreSort = Pick<Store, 'id' | 'name' | 'code'> & ResourceSort;
interface Store extends Resource {
readonly type: StoreType;
/**
* The store's internal name.
* @example ```"Rome Shop"```
*/
name: string;
/**
* A string that you can use to identify the store (must be unique within the environment).
* @example ```"europe1"```
*/
code?: string | null;
market?: Market | null;
merchant?: Merchant | null;
stock_location?: StockLocation | null;
orders?: Order[] | null;
payment_methods?: PaymentMethod[] | null;
events?: Event[] | null;
versions?: Version[] | null;
}
interface StoreCreate extends ResourceCreate {
/**
* The store's internal name.
* @example ```"Rome Shop"```
*/
name: string;
/**
* A string that you can use to identify the store (must be unique within the environment).
* @example ```"europe1"```
*/
code?: string | null;
market: MarketRel$j;
merchant?: MerchantRel$3 | null;
stock_location?: StockLocationRel$8 | null;
}
interface StoreUpdate extends ResourceUpdate {
/**
* The store's internal name.
* @example ```"Rome Shop"```
*/
name?: string | null;
/**
* A string that you can use to identify the store (must be unique within the environment).
* @example ```"europe1"```
*/
code?: string | null;
market?: MarketRel$j | null;
merchant?: MerchantRel$3 | null;
stock_location?: StockLocationRel$8 | null;
}
declare class Stores extends ApiResource<Store> {
static readonly TYPE: StoreType;
create(resource: StoreCreate, params?: QueryParamsRetrieve<Store>, options?: ResourcesConfig): Promise<Store>;
update(resource: StoreUpdate, params?: QueryParamsRetrieve<Store>, options?: ResourcesConfig): Promise<Store>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
market(storeId: string | Store, params?: QueryParamsRetrieve<Market>, options?: ResourcesConfig): Promise<Market>;
merchant(storeId: string | Store, params?: QueryParamsRetrieve<Merchant>, options?: ResourcesConfig): Promise<Merchant>;
stock_location(storeId: string | Store, params?: QueryParamsRetrieve<StockLocation>, options?: ResourcesConfig): Promise<StockLocation>;
orders(storeId: string | Store, params?: QueryParamsList<Order>, options?: ResourcesConfig): Promise<ListResponse<Order>>;
payment_methods(storeId: string | Store, params?: QueryParamsList<PaymentMethod>, options?: ResourcesConfig): Promise<ListResponse<PaymentMethod>>;
events(storeId: string | Store, params?: QueryParamsList<Event>, options?: ResourcesConfig): Promise<ListResponse<Event>>;
versions(storeId: string | Store, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isStore(resource: any): resource is Store;
relationship(id: string | ResourceId | null): StoreRel$2;
relationshipToMany(...ids: string[]): StoreRel$2[];
type(): StoreType;
}
type PaymentMethodType = 'payment_methods';
type PaymentMethodRel$5 = ResourceRel & {
type: PaymentMethodType;
};
type MarketRel$i = ResourceRel & {
type: MarketType;
};
type PaymentGatewayRel = ResourceRel & {
type: PaymentGatewayType;
};
type StoreRel$1 = ResourceRel & {
type: StoreType;
};
type PaymentMethodSort = Pick<PaymentMethod, 'id' | 'name' | 'payment_source_type' | 'currency_code' | 'price_amount_cents' | 'disabled_at'> & ResourceSort;
interface PaymentMethod extends Resource {
readonly type: PaymentMethodType;
/**
* The payment method's internal name.
* @example ```"Stripe Payment"```
*/
name?: string | null;
/**
* The payment source type. One of 'adyen_payments', 'axerve_payments', 'braintree_payments', 'checkout_com_payments', 'external_payments', 'klarna_payments', 'paypal_payments', 'satispay_payments', 'stripe_payments', or 'wire_transfers'.
* @example ```"stripe_payments"```
*/
payment_source_type: 'adyen_payments' | 'axerve_payments' | 'braintree_payments' | 'checkout_com_payments' | 'external_payments' | 'klarna_payments' | 'paypal_payments' | 'satispay_payments' | 'stripe_payments' | 'wire_transfers';
/**
* The international 3-letter currency code as defined by the ISO 4217 standard.
* @example ```"EUR"```
*/
currency_code?: string | null;
/**
* Send this attribute if you want to mark the payment as MOTO, must be supported by payment gateway.
*/
moto?: boolean | null;
/**
* Send this attribute if you want to require the payment capture before fulfillment.
* @example ```true```
*/
require_capture?: boolean | null;
/**
* Send this attribute if you want to automatically place the order upon authorization performed asynchronously.
* @example ```true```
*/
auto_place?: boolean | null;
/**
* Send this attribute if you want to automatically capture the payment upon authorization.
*/
auto_capture?: boolean | null;
/**
* The payment method's price, in cents.
*/
price_amount_cents: number;
/**
* The payment method's price, float.
*/
price_amount_float?: number | null;
/**
* The payment method's price, formatted.
* @example ```"€0,00"```
*/
formatted_price_amount?: string | null;
/**
* Send this attribute if you want to limit automatic capture to orders for which the total amount is equal or less than the specified value, in cents.
*/
auto_capture_max_amount_cents?: number | null;
/**
* The automatic capture max amount, float.
*/
auto_capture_max_amount_float?: number | null;
/**
* The automatic capture max amount, formatted.
* @example ```"€0,00"```
*/
formatted_auto_capture_max_amount?: string | null;
/**
* Time at which this resource was disabled.
* @example ```"2018-01-01T12:00:00.000Z"```
*/
disabled_at?: string | null;
market?: Market | null;
payment_gateway?: PaymentGateway | null;
store?: Store | null;
attachments?: Attachment[] | null;
versions?: Version[] | null;
}
interface PaymentMethodCreate extends ResourceCreate {
/**
* The payment method's internal name.
* @example ```"Stripe Payment"```
*/
name?: string | null;
/**
* The payment source type. One of 'adyen_payments', 'axerve_payments', 'braintree_payments', 'checkout_com_payments', 'external_payments', 'klarna_payments', 'paypal_payments', 'satispay_payments', 'stripe_payments', or 'wire_transfers'.
* @example ```"stripe_payments"```
*/
payment_source_type: 'adyen_payments' | 'axerve_payments' | 'braintree_payments' | 'checkout_com_payments' | 'external_payments' | 'klarna_payments' | 'paypal_payments' | 'satispay_payments' | 'stripe_payments' | 'wire_transfers';
/**
* The international 3-letter currency code as defined by the ISO 4217 standard.
* @example ```"EUR"```
*/
currency_code?: string | null;
/**
* Send this attribute if you want to mark the payment as MOTO, must be supported by payment gateway.
*/
moto?: boolean | null;
/**
* Send this attribute if you want to require the payment capture before fulfillment.
* @example ```true```
*/
require_capture?: boolean | null;
/**
* Send this attribute if you want to automatically place the order upon authorization performed asynchronously.
* @example ```true```
*/
auto_place?: boolean | null;
/**
* Send this attribute if you want to automatically capture the payment upon authorization.
*/
auto_capture?: boolean | null;
/**
* The payment method's price, in cents.
*/
price_amount_cents: number;
/**
* Send this attribute if you want to limit automatic capture to orders for which the total amount is equal or less than the specified value, in cents.
*/
auto_capture_max_amount_cents?: number | null;
/**
* Send this attribute if you want to mark this resource as disabled.
* @example ```true```
*/
_disable?: boolean | null;
/**
* Send this attribute if you want to mark this resource as enabled.
* @example ```true```
*/
_enable?: boolean | null;
market?: MarketRel$i | null;
payment_gateway: PaymentGatewayRel;
store?: StoreRel$1 | null;
}
interface PaymentMethodUpdate extends ResourceUpdate {
/**
* The payment method's internal name.
* @example ```"Stripe Payment"```
*/
name?: string | null;
/**
* The payment source type. One of 'adyen_payments', 'axerve_payments', 'braintree_payments', 'checkout_com_payments', 'external_payments', 'klarna_payments',