genuka-api
Version:
Javascript(TS) Package to use Genuka API for a StoreFront website
603 lines (577 loc) • 15.8 kB
TypeScript
import * as axios from 'axios';
type QueryFilter = Record<string, any>;
type QuerySort = string[];
type QueryInclude = string[];
type QueryQueries = Record<string, any>;
type ClassicObject = Record<string, any>;
type ListProps = {
page?: number;
limit?: number;
filter?: QueryFilter;
sort?: QuerySort;
include?: QueryInclude;
queries?: QueryQueries;
};
type CustomerCreate = {
first_name?: string;
last_name?: string;
email: string;
phone?: string;
gender?: string;
password?: string;
password_confirmation?: string;
metadata?: Record<string, any>;
};
type Config = {
token?: string;
lang?: string;
companyId?: string;
shopId?: string;
adminMode?: boolean;
version?: string;
domain?: string;
id?: string;
apiBaseUrl?: string;
timezone?: string;
};
declare class AxiosConfig {
instance: axios.AxiosInstance;
token?: string;
companyId?: string;
shopId?: string;
lang: string;
private pendingRequests;
constructor({ version, adminMode, token, lang, companyId, shopId, apiBaseUrl, timezone, }?: Config);
setToken(t: string): void;
setCompanyId(id: string): void;
setShopId(id: string): void;
setLang(l: string): void;
private generateRequestKey;
cancelAllRequests(): void;
cancelRequest(method: string, url: string, params?: any, data?: any): void;
}
declare class AddressService {
private http;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
list(props: ListProps): Promise<any>;
retrieve({ id }: {
id: string;
}): Promise<any>;
create(data: ClassicObject): Promise<any>;
update({ id, ...data }: {
id: string;
[key: string]: any;
}): Promise<any>;
delete({ id }: {
id: string;
}): Promise<any>;
}
declare class ArticleService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
similar({ id, handle, limit, }: {
id?: string;
handle?: string;
limit?: number;
}): Promise<any>;
}
declare class BlogService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
similar({ id, handle, limit, }: {
id?: string;
handle?: string;
limit?: number;
}): Promise<any>;
}
type CartItem = {
variant_id?: string;
product_id?: string;
title?: string;
price: number;
quantity: number;
metadata?: Record<string, any>;
};
declare class CartService {
private http;
items: CartItem[];
total: number;
constructor(http: AxiosConfig);
evaluateTotal(): void;
set(items?: never[]): void;
add(item: CartItem): void;
checkAvailability(item: CartItem): Promise<boolean>;
remove(variant_id: string): void;
clear(): void;
retrieve(): CartItem[];
update(variant_id: string | undefined, itemObj: Partial<CartItem>): void;
}
declare class CollectionService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
similar({ id, handle, limit, }: {
id?: string;
handle?: string;
limit?: number;
}): Promise<any>;
}
declare class CompanyService {
private http;
constructor(http: AxiosConfig);
retrieve(): Promise<any>;
}
declare class CustomerService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
register({ first_name, last_name, email, phone, gender, password, password_confirmation, }: CustomerCreate): Promise<any>;
login({ email, phone, password, }: {
email?: string;
phone?: string;
password: string;
}): Promise<any>;
getResetLinkToken({ email }: {
email: string;
}): Promise<any>;
resetPassword({ email, token, password, password_confirmation, }: {
email: string;
token: string;
password: string;
password_confirmation?: string;
}): Promise<any>;
me(): Promise<any>;
retrieve(): Promise<any>;
update({ first_name, last_name, email, phone, gender, password, password_confirmation, }: CustomerCreate): Promise<any>;
changePassword({ current_password, new_password, }: {
current_password: string;
new_password: string;
}): Promise<any>;
logout(): Promise<any>;
list(props: ListProps): Promise<any>;
get(id: string): Promise<any>;
}
declare class DiscountService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
retrieve({ id, code }: {
id?: string;
code?: string;
}): Promise<any>;
getAutomatics(data: ClassicObject): Promise<any>;
}
declare class OrderService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(isAdmin?: boolean): Promise<any>;
list(props: ListProps & {
isAdmin?: boolean;
}): Promise<any>;
retrieve(id: string, isAdmin?: boolean, { include }?: {
include?: never[] | undefined;
}): Promise<any>;
create({ isAdmin, ...data }: {
[x: string]: any;
isAdmin?: boolean | undefined;
}): Promise<any>;
}
declare class DeliveryService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(isAdmin?: boolean): Promise<any>;
list(props: ListProps & {
isAdmin?: boolean;
}): Promise<any>;
retrieve(id: string, isAdmin?: boolean, { include }?: {
include?: never[] | undefined;
}): Promise<any>;
create({ isAdmin, ...data }: {
isAdmin?: boolean;
} & ClassicObject): Promise<any>;
}
declare class BillService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve(id: string, { include }?: {
include?: never[] | undefined;
}): Promise<any>;
create({ ...data }: ClassicObject): Promise<any>;
}
declare class PageService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
similar({ id, handle, limit, }: {
id?: string;
handle?: string;
limit?: number;
}): Promise<any>;
}
declare class PaymentMethodService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
}
declare class ProductVariantService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle, queries, }: {
id?: string;
handle?: string;
queries?: QueryQueries;
}): Promise<any>;
}
declare class ProductService {
private http;
productVariantService: ProductVariantService;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
get variants(): ProductVariantService;
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle, queries, }: {
id?: string;
handle?: string;
queries?: QueryQueries;
}): Promise<any>;
similar({ id, handle, limit, }: {
id?: string;
handle?: string;
limit?: number;
}): Promise<any>;
}
declare class ShippingService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
similar({ id, handle, limit, }: {
id?: string;
handle?: string;
limit?: number;
}): Promise<any>;
}
declare class PickupService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
similar({ id, handle, limit, }: {
id?: string;
handle?: string;
limit?: number;
}): Promise<any>;
}
declare class ShopService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve({ id, handle }: {
id?: string;
handle?: string;
}): Promise<any>;
}
declare class SubscriptionService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
retrieve({ id }: {
id: string;
}): Promise<any>;
list(props: ListProps): Promise<any>;
}
declare class ReturnsService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve(id: string, { include }?: {
include?: never[] | undefined;
}): Promise<any>;
create({ ...data }: {
[x: string]: any;
}): Promise<any>;
}
declare class InvoicesService {
private http;
model: string;
page: number;
limit: number;
filter: QueryFilter;
sort: QuerySort;
include: QueryInclude;
queries: QueryQueries;
constructor(http: AxiosConfig);
count(): Promise<any>;
list(props: ListProps): Promise<any>;
retrieve(id: string, { include }?: {
include?: never[] | undefined;
}): Promise<any>;
create({ ...data }: {
[x: string]: any;
}): Promise<any>;
}
declare class Genuka {
/** @type {AxiosConfig} */
http: AxiosConfig;
companyService: CompanyService;
shopService: ShopService;
subscriptionService: SubscriptionService;
discountService: DiscountService;
deliveryService: DeliveryService;
billService: BillService;
returnService: ReturnsService;
invoicesService: InvoicesService;
productService: ProductService;
pageService: PageService;
blogService: BlogService;
articleService: ArticleService;
collectionService: CollectionService;
paymentMethodService: PaymentMethodService;
customerService: CustomerService;
orderService: OrderService;
addressService: AddressService;
cartService: CartService;
shippingsService: ShippingService;
pickupsService: PickupService;
/** @type {string|null} */
companyId: string | null;
/** @type {string|null} */
shopId: string | null;
/**
* @param {AxiosConfig} http
*/
constructor(http: AxiosConfig);
/**
* Fabrique “propre” per-request.
* @param {object} config
* @returns {Genuka}
*/
static create(config?: Config): Genuka;
/**
* Compatibilité avec l’ancienne API: retourne **une nouvelle instance** (pas de singleton).
* Supporte: { version, adminMode, baseURL?, token?, domain?, id?, shopId?, lang? }
* @param {object} config
* @returns {Promise<Genuka>}
*/
static initialize(config?: Config): Promise<Genuka>;
/**
* Setup via domaine : récupère companyId (et shopId si resolveShop=true) puis set les headers.
* @param {{domain:string, resolveShop?:boolean}} params
*/
setup({ domain, resolveShop, }: {
domain: string;
resolveShop?: boolean;
}): Promise<void>;
/**
* @param {string} domain
* @returns {Promise<string>}
*/
getCompanyIdByDomain(domain: string): Promise<string>;
/**
* Essaie de trouver le shop correspondant au domaine (ou fallback 1er shop).
* @param {string} domain
* @returns {Promise<string|null>}
*/
getShopIdByDomain(domain: string): Promise<string | null>;
/**
* @param {string} token
*/
setToken(token: string): void;
/**
* @param {string} shopId
*/
setShopId(shopId: string): void;
/**
* @param {string} companyId
*/
setCompanyId(companyId: string): void;
/**
* Optionnel si ton AxiosConfig supporte la langue
* @param {string} lang
*/
setLang(lang: string): void;
get company(): CompanyService;
get shops(): ShopService;
get subscriptions(): SubscriptionService;
get discounts(): DiscountService;
get deliveries(): DeliveryService;
get bills(): BillService;
get returns(): ReturnsService;
get invoices(): InvoicesService;
get products(): ProductService;
get pages(): PageService;
get shippings(): ShippingService;
get pickups(): PickupService;
get articles(): ArticleService;
get blogs(): BlogService;
get collections(): CollectionService;
get paymentMethods(): PaymentMethodService;
get customers(): CustomerService;
get orders(): OrderService;
get addresses(): AddressService;
get cart(): CartService;
}
export { Genuka as default };