@commercelayer/provisioning-sdk
Version:
Commerce Layer Provisioning SDK
1,197 lines (1,180 loc) • 64.7 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);
get errors(): any[] | undefined;
get status(): number;
get statusText(): string;
}
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 = {
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 Nullable<T> = T | null;
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>)>;
};
interface QueryParamsRetrieve<R extends Resource = Resource> {
include?: QueryInclude;
fields?: QueryArrayFields<R> | QueryRecordFields;
}
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 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?: QueryArraySortable<R> | QueryRecordSortable<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?: Nullable<string>;
reference_origin?: Nullable<string>;
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;
}
interface SingletonUpdate extends ResourceBase {
}
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>;
retrieve<R extends Resource>(resource: ResourceId | ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig, path?: string): 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 | SingletonUpdate), R extends Resource>(resource: U & ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig, path?: string): 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>>;
action(cmd: Extract<Method, 'POST' | 'PATCH'>, path: string, payload?: any, options?: ResourcesConfig): Promise<void>;
}
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;
parse(resource: string): R | R[];
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 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 ```"roles"```
*/
resource_type: string;
/**
* The versioned resource ID.
* @example ```"PzdJhdLdYV"```
*/
resource_id: string;
/**
* The event which generates the version.
* @example ```"update"```
*/
event: string;
/**
* The object changes payload.
* @example ```{"name":["previous","new"]}```
*/
changes: Record<string, any>;
/**
* Information about who triggered the change, only showed when it's from a JWT token.
* @example ```{"application":{"id":"DNOPYiZYpn","kind":"integration","public":true}}```
*/
who: Record<string, any>;
}
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 PermissionType = 'permissions';
type PermissionRel = ResourceRel & {
type: PermissionType;
};
type RoleRel$4 = ResourceRel & {
type: RoleType;
};
type PermissionSort = Pick<Permission, 'id'> & ResourceSort;
interface Permission extends Resource {
readonly type: PermissionType;
/**
* Determines if the permission have access to create rights.
*/
can_create: boolean;
/**
* Determines if the permission have access to read rights.
*/
can_read: boolean;
/**
* Determines if the permission have access to update rights.
*/
can_update: boolean;
/**
* Determines if the permission have access to destroy rights.
*/
can_destroy: boolean;
/**
* The resource where this permission is applied.
*/
subject: string;
/**
* An object that contains additional restrictions.
* @example ```{"foo":"bar"}```
*/
restrictions: Record<string, any>;
organization?: Nullable<Organization>;
role?: Nullable<Role>;
versions?: Nullable<Version[]>;
}
interface PermissionCreate extends ResourceCreate {
/**
* Determines if the permission have access to create rights.
*/
can_create: boolean;
/**
* Determines if the permission have access to read rights.
*/
can_read: boolean;
/**
* Determines if the permission have access to update rights.
*/
can_update: boolean;
/**
* Determines if the permission have access to destroy rights.
*/
can_destroy: boolean;
/**
* The resource where this permission is applied.
*/
subject: string;
role: RoleRel$4;
}
interface PermissionUpdate extends ResourceUpdate {
/**
* Determines if the permission have access to create rights.
*/
can_create?: Nullable<boolean>;
/**
* Determines if the permission have access to read rights.
*/
can_read?: Nullable<boolean>;
/**
* Determines if the permission have access to update rights.
*/
can_update?: Nullable<boolean>;
/**
* Determines if the permission have access to destroy rights.
*/
can_destroy?: Nullable<boolean>;
}
declare class Permissions extends ApiResource<Permission> {
static readonly TYPE: PermissionType;
create(resource: PermissionCreate, params?: QueryParamsRetrieve<Permission>, options?: ResourcesConfig): Promise<Permission>;
update(resource: PermissionUpdate, params?: QueryParamsRetrieve<Permission>, options?: ResourcesConfig): Promise<Permission>;
organization(permissionId: string | Permission, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
role(permissionId: string | Permission, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
versions(permissionId: string | Permission, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isPermission(resource: any): resource is Permission;
relationship(id: string | ResourceId | null): PermissionRel;
relationshipToMany(...ids: string[]): PermissionRel[];
type(): PermissionType;
}
type RoleType = 'roles';
type RoleRel$3 = ResourceRel & {
type: RoleType;
};
type OrganizationRel$5 = ResourceRel & {
type: OrganizationType;
};
type RoleSort = Pick<Role, 'id'> & ResourceSort;
interface Role extends Resource {
readonly type: RoleType;
/**
* The role name.
* @example ```"Custom role"```
*/
name: string;
/**
* The kind of role, one of: `custom`, `admin`, `read_only`.
* @example ```"custom"```
*/
kind: string;
organization?: Nullable<Organization>;
permissions?: Nullable<Permission[]>;
memberships?: Nullable<Membership[]>;
api_credentials?: Nullable<ApiCredential[]>;
versions?: Nullable<Version[]>;
}
interface RoleCreate extends ResourceCreate {
/**
* The role name.
* @example ```"Custom role"```
*/
name: string;
organization: OrganizationRel$5;
}
interface RoleUpdate extends ResourceUpdate {
/**
* The role name.
* @example ```"Custom role"```
*/
name?: Nullable<string>;
/**
* Send this attribute if you want to update the role base permissions.
* @example ```"true"```
*/
_add_missing_base_permissions?: Nullable<boolean>;
}
declare class Roles extends ApiResource<Role> {
static readonly TYPE: RoleType;
create(resource: RoleCreate, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
update(resource: RoleUpdate, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
organization(roleId: string | Role, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
permissions(roleId: string | Role, params?: QueryParamsList<Permission>, options?: ResourcesConfig): Promise<ListResponse<Permission>>;
memberships(roleId: string | Role, params?: QueryParamsList<Membership>, options?: ResourcesConfig): Promise<ListResponse<Membership>>;
api_credentials(roleId: string | Role, params?: QueryParamsList<ApiCredential>, options?: ResourcesConfig): Promise<ListResponse<ApiCredential>>;
versions(roleId: string | Role, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
_add_missing_base_permissions(id: string | Role, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
isRole(resource: any): resource is Role;
relationship(id: string | ResourceId | null): RoleRel$3;
relationshipToMany(...ids: string[]): RoleRel$3[];
type(): RoleType;
}
type MembershipProfileType = 'membership_profiles';
type MembershipProfileRel$2 = ResourceRel & {
type: MembershipProfileType;
};
type OrganizationRel$4 = ResourceRel & {
type: OrganizationType;
};
type ApplicationMembershipRel$2 = ResourceRel & {
type: ApplicationMembershipType;
};
type MembershipProfileSort = Pick<MembershipProfile, 'id' | 'name'> & ResourceSort;
interface MembershipProfile extends Resource {
readonly type: MembershipProfileType;
/**
* The membership profile name.
* @example ```"Marketing group"```
*/
name: string;
/**
* Used to enable test mode on the accessible apps.
*/
test_enabled: boolean;
organization?: Nullable<Organization>;
application_memberships?: Nullable<ApplicationMembership[]>;
}
interface MembershipProfileCreate extends ResourceCreate {
/**
* The membership profile name.
* @example ```"Marketing group"```
*/
name: string;
/**
* Used to enable test mode on the accessible apps.
*/
test_enabled: boolean;
organization: OrganizationRel$4;
application_memberships?: Nullable<ApplicationMembershipRel$2[]>;
}
interface MembershipProfileUpdate extends ResourceUpdate {
/**
* The membership profile name.
* @example ```"Marketing group"```
*/
name?: Nullable<string>;
/**
* Used to enable test mode on the accessible apps.
*/
test_enabled?: Nullable<boolean>;
application_memberships?: Nullable<ApplicationMembershipRel$2[]>;
}
declare class MembershipProfiles extends ApiResource<MembershipProfile> {
static readonly TYPE: MembershipProfileType;
create(resource: MembershipProfileCreate, params?: QueryParamsRetrieve<MembershipProfile>, options?: ResourcesConfig): Promise<MembershipProfile>;
update(resource: MembershipProfileUpdate, params?: QueryParamsRetrieve<MembershipProfile>, options?: ResourcesConfig): Promise<MembershipProfile>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
organization(membershipProfileId: string | MembershipProfile, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
application_memberships(membershipProfileId: string | MembershipProfile, params?: QueryParamsList<ApplicationMembership>, options?: ResourcesConfig): Promise<ListResponse<ApplicationMembership>>;
isMembershipProfile(resource: any): resource is MembershipProfile;
relationship(id: string | ResourceId | null): MembershipProfileRel$2;
relationshipToMany(...ids: string[]): MembershipProfileRel$2[];
type(): MembershipProfileType;
}
type ApplicationMembershipType = 'application_memberships';
type ApplicationMembershipRel$1 = ResourceRel & {
type: ApplicationMembershipType;
};
type ApiCredentialRel$1 = ResourceRel & {
type: ApiCredentialType;
};
type MembershipRel$1 = ResourceRel & {
type: MembershipType;
};
type MembershipProfileRel$1 = ResourceRel & {
type: MembershipProfileType;
};
type OrganizationRel$3 = ResourceRel & {
type: OrganizationType;
};
type RoleRel$2 = ResourceRel & {
type: RoleType;
};
type ApplicationMembershipSort = Pick<ApplicationMembership, 'id'> & ResourceSort;
interface ApplicationMembership extends Resource {
readonly type: ApplicationMembershipType;
/**
* Set of key-value pairs that contains restrictions and scopes of the application membership.
* @example ```{"market_id_in":[202,203]}```
*/
filters?: Nullable<Record<string, any>>;
api_credential?: Nullable<ApiCredential>;
membership?: Nullable<Membership>;
membership_profile?: Nullable<MembershipProfile>;
organization?: Nullable<Organization>;
role?: Nullable<Role>;
}
interface ApplicationMembershipCreate extends ResourceCreate {
/**
* Set of key-value pairs that contains restrictions and scopes of the application membership.
* @example ```{"market_id_in":[202,203]}```
*/
filters?: Nullable<Record<string, any>>;
api_credential: ApiCredentialRel$1;
membership?: Nullable<MembershipRel$1>;
membership_profile?: Nullable<MembershipProfileRel$1>;
organization: OrganizationRel$3;
role: RoleRel$2;
}
interface ApplicationMembershipUpdate extends ResourceUpdate {
/**
* Set of key-value pairs that contains restrictions and scopes of the application membership.
* @example ```{"market_id_in":[202,203]}```
*/
filters?: Nullable<Record<string, any>>;
membership_profile?: Nullable<MembershipProfileRel$1>;
role?: Nullable<RoleRel$2>;
}
declare class ApplicationMemberships extends ApiResource<ApplicationMembership> {
static readonly TYPE: ApplicationMembershipType;
create(resource: ApplicationMembershipCreate, params?: QueryParamsRetrieve<ApplicationMembership>, options?: ResourcesConfig): Promise<ApplicationMembership>;
update(resource: ApplicationMembershipUpdate, params?: QueryParamsRetrieve<ApplicationMembership>, options?: ResourcesConfig): Promise<ApplicationMembership>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
api_credential(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve<ApiCredential>, options?: ResourcesConfig): Promise<ApiCredential>;
membership(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve<Membership>, options?: ResourcesConfig): Promise<Membership>;
membership_profile(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve<MembershipProfile>, options?: ResourcesConfig): Promise<MembershipProfile>;
organization(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
role(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
isApplicationMembership(resource: any): resource is ApplicationMembership;
relationship(id: string | ResourceId | null): ApplicationMembershipRel$1;
relationshipToMany(...ids: string[]): ApplicationMembershipRel$1[];
type(): ApplicationMembershipType;
}
type MembershipType = 'memberships';
type MembershipRel = ResourceRel & {
type: MembershipType;
};
type OrganizationRel$2 = ResourceRel & {
type: OrganizationType;
};
type RoleRel$1 = ResourceRel & {
type: RoleType;
};
type ApplicationMembershipRel = ResourceRel & {
type: ApplicationMembershipType;
};
type MembershipProfileRel = ResourceRel & {
type: MembershipProfileType;
};
type MembershipSort = Pick<Membership, 'id' | 'status'> & ResourceSort;
interface Membership extends Resource {
readonly type: MembershipType;
/**
* The user email.
* @example ```"commercelayer@commercelayer.io"```
*/
user_email: string;
/**
* The user first name.
* @example ```"John"```
*/
user_first_name: string;
/**
* The user last name.
* @example ```"Doe"```
*/
user_last_name: string;
/**
* The memberships status. One of `pending` (default), `active`.
* @example ```"pending"```
*/
status: 'pending' | 'active';
/**
* Indicates if the user it's the owner of the organization.
* @example ```"true"```
*/
owner: boolean;
/**
* Used to enable test mode on the accessible apps.
*/
test_enabled?: Nullable<boolean>;
organization?: Nullable<Organization>;
role?: Nullable<Role>;
application_memberships?: Nullable<ApplicationMembership[]>;
membership_profile?: Nullable<MembershipProfile>;
versions?: Nullable<Version[]>;
}
interface MembershipCreate extends ResourceCreate {
/**
* The user email.
* @example ```"commercelayer@commercelayer.io"```
*/
user_email: string;
/**
* Used to enable test mode on the accessible apps.
*/
test_enabled?: Nullable<boolean>;
organization: OrganizationRel$2;
role: RoleRel$1;
application_memberships?: Nullable<ApplicationMembershipRel[]>;
membership_profile?: Nullable<MembershipProfileRel>;
}
interface MembershipUpdate extends ResourceUpdate {
/**
* Used to enable test mode on the accessible apps.
*/
test_enabled?: Nullable<boolean>;
role?: Nullable<RoleRel$1>;
application_memberships?: Nullable<ApplicationMembershipRel[]>;
membership_profile?: Nullable<MembershipProfileRel>;
}
declare class Memberships extends ApiResource<Membership> {
static readonly TYPE: MembershipType;
create(resource: MembershipCreate, params?: QueryParamsRetrieve<Membership>, options?: ResourcesConfig): Promise<Membership>;
update(resource: MembershipUpdate, params?: QueryParamsRetrieve<Membership>, options?: ResourcesConfig): Promise<Membership>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
resend(membershipId: string | Membership, options?: ResourcesConfig): Promise<void>;
organization(membershipId: string | Membership, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
role(membershipId: string | Membership, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
application_memberships(membershipId: string | Membership, params?: QueryParamsList<ApplicationMembership>, options?: ResourcesConfig): Promise<ListResponse<ApplicationMembership>>;
membership_profile(membershipId: string | Membership, params?: QueryParamsRetrieve<MembershipProfile>, options?: ResourcesConfig): Promise<MembershipProfile>;
versions(membershipId: string | Membership, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
isMembership(resource: any): resource is Membership;
relationship(id: string | ResourceId | null): MembershipRel;
relationshipToMany(...ids: string[]): MembershipRel[];
type(): MembershipType;
}
type OrganizationType = 'organizations';
type OrganizationRel$1 = ResourceRel & {
type: OrganizationType;
};
type OrganizationSort = Pick<Organization, 'id' | 'name' | 'slug' | 'domain'> & ResourceSort;
interface Organization extends Resource {
readonly type: OrganizationType;
/**
* The organization's internal name.
* @example ```"The Blue Brand"```
*/
name: string;
/**
* The organization's slug name.
* @example ```"the-blue-brand"```
*/
slug: string;
/**
* The organization's domain.
* @example ```"the-blue-brand.commercelayer.io"```
*/
domain: string;
/**
* The organization's support phone.
* @example ```"+01 30800857"```
*/
support_phone?: Nullable<string>;
/**
* The organization's support email.
* @example ```"support@bluebrand.com"```
*/
support_email?: Nullable<string>;
/**
* The URL to the organization's logo.
* @example ```"https://bluebrand.com/img/logo.svg"```
*/
logo_url?: Nullable<string>;
/**
* The URL to the organization's favicon.
* @example ```"https://bluebrand.com/img/favicon.ico"```
*/
favicon_url?: Nullable<string>;
/**
* The organization's primary color.
* @example ```"#C8984E"```
*/
primary_color?: Nullable<string>;
/**
* The organization's contrast color. Format is HEX (starts with `#` and is followed by six letters and/or numbers).
* @example ```"#FFFFCC"```
*/
contrast_color?: Nullable<string>;
/**
* The organization's Google Tag Manager ID.
* @example ```"GTM-5FJXX6"```
*/
gtm_id?: Nullable<string>;
/**
* The organization's Google Tag Manager ID for test.
* @example ```"GTM-5FJXX7"```
*/
gtm_id_test?: Nullable<string>;
/**
* The region where the organization is located. The default value is `eu-west-1`.
* @example ```"eu-west-1"```
*/
region?: Nullable<string>;
/**
* Indicates if the organization can switch to live mode.
*/
can_switch_live: boolean;
/**
* Information about the current subscription such as the plan type, limits, and subscription totals counter.
* @example ```{"plan_type":"growth","limits":{"markets":5,"skus":10000,"organizations":2,"memberships":5},"totals":{"organizations":1,"markets":0,"memberships":2,"skus":0}}```
*/
subscription_info: Record<string, any>;
/**
* The organization's configuration.
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
*/
config?: Nullable<Record<string, any>>;
/**
* Enables the redirect on the new Auth API.
* @example ```"true"```
*/
api_auth_redirect: boolean;
/**
* Enables the rules engine for flex promotions and price list rules.
*/
api_rules_engine: boolean;
/**
* The fallback maximum number of conditions within a rules payload on a ruleable object, default is 150.
* @example ```"150"```
*/
api_rules_engine_max_conditions_size: number;
/**
* The fallback maximum number of rules within a rules payload on a ruleable object, default is 15.
* @example ```"15"```
*/
api_rules_engine_max_rules_size: number;
/**
* Forces the usage of the new Authentication API.
* @example ```"true"```
*/
api_new_auth: boolean;
/**
* Enables the purge of cached single resources when list is purged.
*/
api_purge_single_resource: boolean;
/**
* The maximum length for the regular expressions, default is 5000.
* @example ```"5000"```
*/
api_max_regex_length: number;
/**
* Indicates if the phone attribute is required for addresses, default is true.
* @example ```"true"```
*/
addresses_phone_required: boolean;
/**
* The minimum lapse in fraction of seconds to be observed between two consecutive order refreshes. If refresh is triggered within the minimum lapse, the update is performed, but no order refresh is done, until the lapse is observed.
*/
orders_min_refresh_lapse: number;
/**
* The maximum number line items allowed for a test order before disabling the autorefresh option.
* @example ```"50"```
*/
orders_autorefresh_cutoff_test: number;
/**
* The maximum number line items allowed for a live order before disabling the autorefresh option.
* @example ```"500"```
*/
orders_autorefresh_cutoff_live: number;
/**
* Enables orders number editing as a string in test (for enterprise plans only).
*/
orders_number_editable_test: boolean;
/**
* Enables orders number editing as a string in live (for enterprise plans only).
*/
orders_number_editable_live: boolean;
/**
* Enables to use the order number as payment reference on supported gateways.
* @example ```"true"```
*/
orders_number_as_reference: boolean;
/**
* Enables raising of API errors in case the provided coupon code is invalid, default is true.
* @example ```"true"```
*/
orders_invalid_coupon_errors: boolean;
/**
* The maximum number of SKUs allowed for bundles, default is 10.
* @example ```"10"```
*/
bundles_max_items_count: number;
/**
* The minimum length for coupon code, default is 8.
* @example ```"8"```
*/
coupons_min_code_length: number;
/**
* The maximum length for coupon code, default is 40.
* @example ```"40"```
*/
coupons_max_code_length: number;
/**
* The minimum length for gift card code, default is 8.
* @example ```"8"```
*/
gift_cards_min_code_length: number;
/**
* The maximum length for gift card code, default is 40.
* @example ```"40"```
*/
gift_cards_max_code_length: number;
/**
* The maximum number of concurrent cleanups allowed for your organization, default is 10.
* @example ```"10"```
*/
cleanups_max_concurrent_count: number;
/**
* The maximum number of concurrent exports allowed for your organization, default is 10.
* @example ```"10"```
*/
exports_max_concurrent_count: number;
/**
* The maximum number of concurrent imports allowed for your organization, default is 10.
* @example ```"10"```
*/
imports_max_concurrent_count: number;
/**
* Enables purging of cached resources upon succeeded imports.
* @example ```"true"```
*/
imports_purge_cache: boolean;
/**
* Disables the interruption of the import in case its errors exceeds the 10% threshold, default is false.
*/
imports_skip_errors: boolean;
/**
* The maximum number of active concurrent promotions allowed for your organization, default is 10.
* @example ```"10"```
*/
promotions_max_concurrent_count: number;
/**
* The maximum number of conditions within a rules payload on a promotion object, default is 150.
* @example ```"150"```
*/
promotions_max_conditions_size: number;
/**
* The maximum number of rules within a rules payload on a promotion object, default is 15.
* @example ```"15"```
*/
promotions_max_rules_size: number;
/**
* The maximum number of conditions within a rules payload on a price list object, default is 150.
* @example ```"150"```
*/
price_lists_max_conditions_size: number;
/**
* The maximum number of rules within a rules payload on a price list object, default is 15.
* @example ```"15"```
*/
price_lists_max_rules_size: number;
/**
* Enables triggering of webhooks during imports, default is false.
*/
imports_trigger_webhooks: number;
/**
* Enables the use of an external discount engine in place of the standard one, default is false.
*/
discount_engines_enabled: boolean;
/**
* Enables raising of API errors in case of discount engine failure, default is false.
*/
discount_engines_errors: boolean;
/**
* The maximum length for the tag name, default is 25.
* @example ```"25"```
*/
tags_max_name_length: number;
/**
* The maximum allowed number of tags for each resource, default is 10.
* @example ```"10"```
*/
tags_max_allowed_number: number;
/**
* Enables raising of API errors in case of tax calculation failure, default is false.
*/
tax_calculators_errors: boolean;
/**
* Enables raising of API errors in case of external promotion failure, default is false.
*/
external_promotions_errors: boolean;
memberships?: Nullable<Membership[]>;
roles?: Nullable<Role[]>;
permissions?: Nullable<Permission[]>;
api_credentials?: Nullable<ApiCredential[]>;
}
interface OrganizationCreate extends ResourceCreate {
/**
* The organization's internal name.
* @example ```"The Blue Brand"```
*/
name: string;
/**
* The organization's support phone.
* @example ```"+01 30800857"```
*/
support_phone?: Nullable<string>;
/**
* The organization's support email.
* @example ```"support@bluebrand.com"```
*/
support_email?: Nullable<string>;
/**
* The URL to the organization's logo.
* @example ```"https://bluebrand.com/img/logo.svg"```
*/
logo_url?: Nullable<string>;
/**
* The URL to the organization's favicon.
* @example ```"https://bluebrand.com/img/favicon.ico"```
*/
favicon_url?: Nullable<string>;
/**
* The organization's primary color.
* @example ```"#C8984E"```
*/
primary_color?: Nullable<string>;
/**
* The organization's contrast color. Format is HEX (starts with `#` and is followed by six letters and/or numbers).
* @example ```"#FFFFCC"```
*/
contrast_color?: Nullable<string>;
/**
* The organization's Google Tag Manager ID.
* @example ```"GTM-5FJXX6"```
*/
gtm_id?: Nullable<string>;
/**
* The organization's Google Tag Manager ID for test.
* @example ```"GTM-5FJXX7"```
*/
gtm_id_test?: Nullable<string>;
/**
* The region where the organization is located. The default value is `eu-west-1`.
* @example ```"eu-west-1"```
*/
region?: Nullable<string>;
/**
* The organization's configuration.
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
*/
config?: Nullable<Record<string, any>>;
}
interface OrganizationUpdate extends ResourceUpdate {
/**
* The organization's internal name.
* @example ```"The Blue Brand"```
*/
name?: Nullable<string>;
/**
* The organization's support phone.
* @example ```"+01 30800857"```
*/
support_phone?: Nullable<string>;
/**
* The organization's support email.
* @example ```"support@bluebrand.com"```
*/
support_email?: Nullable<string>;
/**
* The URL to the organization's logo.
* @example ```"https://bluebrand.com/img/logo.svg"```
*/
logo_url?: Nullable<string>;
/**
* The URL to the organization's favicon.
* @example ```"https://bluebrand.com/img/favicon.ico"```
*/
favicon_url?: Nullable<string>;
/**
* The organization's primary color.
* @example ```"#C8984E"```
*/
primary_color?: Nullable<string>;
/**
* The organization's contrast color. Format is HEX (starts with `#` and is followed by six letters and/or numbers).
* @example ```"#FFFFCC"```
*/
contrast_color?: Nullable<string>;
/**
* The organization's Google Tag Manager ID.
* @example ```"GTM-5FJXX6"```
*/
gtm_id?: Nullable<string>;
/**
* The organization's Google Tag Manager ID for test.
* @example ```"GTM-5FJXX7"```
*/
gtm_id_test?: Nullable<string>;
/**
* The organization's configuration.
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
*/
config?: Nullable<Record<string, any>>;
}
declare class Organizations extends ApiResource<Organization> {
static readonly TYPE: OrganizationType;
create(resource: OrganizationCreate, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
update(resource: OrganizationUpdate, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
transfer_ownership(organizationId: string | Organization, payload: TransferOwnershipDataType, options?: ResourcesConfig): Promise<void>;
memberships(organizationId: string | Organization, params?: QueryParamsList<Membership>, options?: ResourcesConfig): Promise<ListResponse<Membership>>;
roles(organizationId: string | Organization, params?: QueryParamsList<Role>, options?: ResourcesConfig): Promise<ListResponse<Role>>;
permissions(organizationId: string | Organization, params?: QueryParamsList<Permission>, options?: ResourcesConfig): Promise<ListResponse<Permission>>;
api_credentials(organizationId: string | Organization, params?: QueryParamsList<ApiCredential>, options?: ResourcesConfig): Promise<ListResponse<ApiCredential>>;
isOrganization(resource: any): resource is Organization;
relationship(id: string | ResourceId | null): OrganizationRel$1;
relationshipToMany(...ids: string[]): OrganizationRel$1[];
type(): OrganizationType;
}
type TransferOwnershipDataType = {
type: 'organizations';
id: string;
new_owner_email: string;
};
type ApiCredentialType = 'api_credentials';
type ApiCredentialRel = ResourceRel & {
type: ApiCredentialType;
};
type OrganizationRel = ResourceRel & {
type: OrganizationType;
};
type RoleRel = ResourceRel & {
type: RoleType;
};
type ApiCredentialSort = Pick<ApiCredential, 'id' | 'mode'> & ResourceSort;
interface ApiCredential extends Resource {
readonly type: ApiCredentialType;
/**
* The API credential internal name.
* @example ```"My app"```
*/
name: string;
/**
* The API credential kind, can be one of: `webapp`, `sales_channel`, `integration` or the kind of app you want to fork (e.g. `orders`, `imports`, etc.).
* @example ```"sales_channel"```
*/
kind: string;
/**
* Indicates if the API credential it's confidential.
* @example ```"true"```
*/
confidential: boolean;
/**
* The API credential redirect URI.
* @example ```"https://bluebrand.com/img/logo.svg"```
*/
redirect_uri?: Nullable<string>;
/**
* The API credential unique ID.
* @example ```"xxxx-yyyy-zzzz"```
*/
client_id: string;
/**
* The API credential unique secret.
* @example ```"xxxx-yyyy-zzzz"```
*/
client_secret: string;
/**
* The API credential scopes.
* @example ```"market:all market:9 market:122 market:6 stock_location:6 stock_location:33"```
*/
scopes: string;
/**
* The lifetime of the access token in seconds (min. `7200`, max. `31536000`. Default is `14400` for Sales channels and `7200` for other client types).
* @example ```"7200"```
*/
expires_in?: Nullable<number>;
/**
* Indicates the environment the resource belongs to (one of `test` or `live`).
* @example ```"test"```
*/
mode?: Nullable<string>;
/**
* Indicates if the API credential is used to create a custom app (e.g. fork a hosted app).
*/
custom?: Nullable<boolean>;
organization?: Nullable<Organization>;
role?: Nullable<Role>;
}
interface ApiCredentialCreate extends ResourceCreate {
/**
* The API credential internal name.
* @example ```"My app"```
*/
name: string;
/**
* The API credential kind, can be one of: `webapp`, `sales_channel`, `integration` or the kind of app you want to fork (e.g. `orders`, `imports`, etc.).
* @example ```"sales_channel"```
*/
kind: string;
/**
* The API credential redirect URI.
* @example ```"https://bluebrand.com/img/logo.svg"```
*/
redirect_uri?: Nullable<string>;
/**
* The lifetime of the access token in seconds (min. `7200`, max. `31536000`. Default is `14400` for Sales channels and `7200` for other client types).
* @example ```"7200"```
*/
expires_in?: Nullable<number>;
/**
* Indicates the environment the resource belongs to (one of `test` or `live`).
* @example ```"test"```
*/
mode?: Nullable<string>;
/**
* Indicates if the API credential is used to create a custom app (e.g. fork a hosted app).
*/
custom?: Nullable<boolean>;
organization: OrganizationRel;
role?: Nullable<RoleRel>;
}
interface ApiCredentialUpdate extends ResourceUpdate {
/**
* The API credential internal name.
* @example ```"My app"```
*/
name?: Nullable<string>;
/**
* The API credential redirect URI.
* @example ```"https://bluebrand.com/img/logo.svg"```
*/
redirect_uri?: Nullable<string>;
/**
* The lifetime of the access token in seconds (min. `7200`, max. `31536000`. Default is `14400` for Sales channels and `7200` for other client types).
* @example ```"7200"```
*/
expires_in?: Nullable<number>;
role?: Nullable<RoleRel>;
}
declare class ApiCredentials extends ApiResource<ApiCredential> {
static readonly TYPE: ApiCredentialType;
create(resource: ApiCredentialCreate, params?: QueryParamsRetrieve<ApiCredential>, options?: ResourcesConfig): Promise<ApiCredential>;
update(resource: ApiCredentialUpdate, params?: QueryParamsRetrieve<ApiCredential>, options?: ResourcesConfig): Promise<ApiCredential>;
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
organization(apiCredentialId: string | ApiCredential, params?: QueryParamsRetrieve<Organization>, options?: ResourcesConfig): Promise<Organization>;
role(apiCredentialId: string | ApiCredential, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
isApiCredential(resource: any): resource is ApiCredential;
relationship(id: string | ResourceId | null): ApiCredentialRel;
relationshipToMany(...ids: string[]): ApiCredentialRel[];
type(): ApiCredentialType;
}
type UserType = 'users';
type UserRel = ResourceRel & {
type: UserType;
};
type UserSort = Pick<User, 'id' | 'email' | 'first_name' | 'last_name'> & ResourceSort;
interface User extends Resource {
readonly type: UserType;
/**
* The user email.
* @example ```"user@commercelayer.io"```
*/
email: string;
/**
* The user first name.
* @example ```"John"```
*/
first_name: string;
/**
* The user last name.
* @example ```"Doe"```
*/
last_name: string;
/**
* The user preferred timezone.
* @example ```"UTC"```
*/
time_zone?: Nullable<string>;
/**
* The user 2FA setting.
*/
otp_required_for_login: boolean;
}
interface UserUpdate extends SingletonUpdate {
/**
* The user email.
* @example ```"user@commercelayer.io"```
*/
email?: Nullable<string>;
/**
* The user first name.
* @example ```"John"```
*/
first_name?: Nullable<string>;
/**
* The user last name.
* @example ```"Doe"```
*/
last_name?: Nullable<string>;
/**
* The user preferred timezone.
* @example ```"UTC"``