@bacano/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/media.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type MediaUrlVariant = 'original' | 'thumbnail' | 'card' | 'detail';
2
+ export type MediaTransformFormat = 'auto' | 'same' | 'jpeg' | 'webp' | 'png' | 'avif';
3
+ export declare function buildStorageFileUrl(storageUrl: string | undefined, fileId: string, variant?: MediaUrlVariant): string;
4
+ export declare function buildStorageMediaUrls(storageUrl: string | undefined, fileId: string): {
5
+ originalUrl: string;
6
+ thumbnailUrl: string;
7
+ cardUrl: string;
8
+ detailUrl: string;
9
+ };
@@ -0,0 +1,9 @@
1
+ import type { AccessTokenProvider, GetWebsitePublicConfigOptions, WebsitePublicConfig } from "../types";
2
+ /** Build a bearer header from a token without inspecting or storing it. */
3
+ export declare function createAuthHeaders(accessToken: string | null | undefined): Record<string, string>;
4
+ export declare function createRequestHeadersProvider(websiteSlug: string, getAccessToken?: AccessTokenProvider): () => Promise<Record<string, string>>;
5
+ /**
6
+ * Load the browser-safe buyer-auth bootstrap for the current storefront.
7
+ * Clerk secrets are intentionally never part of this response.
8
+ */
9
+ export declare function getWebsitePublicConfig(options: GetWebsitePublicConfigOptions): Promise<WebsitePublicConfig>;
@@ -0,0 +1,6 @@
1
+ import type { ProductAvailability, BacanoClientContext } from '../types';
2
+ import { type RequestHeadersProvider } from '../transport/graphql';
3
+ export interface AvailabilityModule {
4
+ checkAvailability(productVariantIds: string[]): Promise<ProductAvailability[]>;
5
+ }
6
+ export declare function createAvailabilityModule(graphqlUrl: string, getHeaders: RequestHeadersProvider, getContext: () => BacanoClientContext): AvailabilityModule;
@@ -0,0 +1,13 @@
1
+ import type { BacanoClientConfig } from '../types';
2
+ export interface CartSession {
3
+ orderId: string;
4
+ cartToken: string;
5
+ }
6
+ export interface CartSessionStorage {
7
+ get(): CartSession | null;
8
+ set(session: CartSession): void;
9
+ clear(): void;
10
+ }
11
+ type StorageKind = NonNullable<BacanoClientConfig['tokenStorage']>;
12
+ export declare function createCartSessionStorage(kind: StorageKind, getSlug: () => string): CartSessionStorage;
13
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { Cart, CartItem, StartGuestCheckoutInput, BacanoClientContext, WebsiteFulfillmentFamily, WebsiteGuestContact } from '../types';
2
+ import { type RequestHeadersProvider } from '../transport/graphql';
3
+ import type { CartSessionStorage } from './cart-session';
4
+ export interface CartModule {
5
+ getOrCreate(contact?: WebsiteGuestContact, fulfillmentFamily?: WebsiteFulfillmentFamily): Promise<Cart>;
6
+ startCheckout(input: StartGuestCheckoutInput): Promise<Cart>;
7
+ get(): Promise<Cart | null>;
8
+ setItem(productVariantId: string, quantity: number): Promise<Cart>;
9
+ addItem(productVariantId: string, quantity: number): Promise<CartItem>;
10
+ updateItem(cartItemId: string, quantity: number): Promise<{
11
+ id: string;
12
+ quantity: number;
13
+ }>;
14
+ removeItem(cartItemId: string): Promise<Cart>;
15
+ }
16
+ export declare function createCartModule(graphqlUrl: string, getHeaders: RequestHeadersProvider, getContext: () => BacanoClientContext, cartSessionStorage: CartSessionStorage): CartModule;
@@ -0,0 +1,24 @@
1
+ import type { Product, ProductPrice, ProductVariantPricing, ProductMedia, ProductMediaKind, ProductCategory, CatalogCategoryList, CatalogAttributeList, Brand, GetProductsOptions, GetCategoryListOptions, GetAttributeListOptions, GetCatalogPageOptions, CatalogPageResult, GetProductRecommendationsOptions, ProductRecommendationsResult, GetProductSeoEntriesOptions, ProductSeoEntriesResult, GetProductFiltersOptions, ProductFilters, SearchSuggestion, GetSearchSuggestionsOptions, BacanoClientContext } from '../types';
2
+ import { type RequestHeadersProvider } from '../transport/graphql';
3
+ export declare function getProductMediaKind(mimeType?: string | null): ProductMediaKind;
4
+ export declare function getProductMediaByKind(media: ProductMedia[] | null | undefined, kind: ProductMediaKind): ProductMedia[];
5
+ export declare function getProductImages(media: ProductMedia[] | null | undefined): ProductMedia[];
6
+ export declare function getProductVideos(media: ProductMedia[] | null | undefined): ProductMedia[];
7
+ export declare function getPrimaryProductImage(media: ProductMedia[] | null | undefined): ProductMedia | null;
8
+ export declare function resolveProductPricing(prices: ProductPrice[]): ProductVariantPricing;
9
+ export interface CatalogModule {
10
+ getCatalogPage(opts: GetCatalogPageOptions): Promise<CatalogPageResult>;
11
+ getProductRecommendations(opts: GetProductRecommendationsOptions): Promise<ProductRecommendationsResult>;
12
+ getProductSeoEntries(opts?: GetProductSeoEntriesOptions): Promise<ProductSeoEntriesResult>;
13
+ getProducts(opts?: GetProductsOptions): Promise<Product[]>;
14
+ getProduct(productId: string): Promise<Product | null>;
15
+ getProductBySlug(slug: string): Promise<Product | null>;
16
+ getCategories(): Promise<ProductCategory[]>;
17
+ getCategoryList(opts: GetCategoryListOptions): Promise<CatalogCategoryList | null>;
18
+ getAttributeList(opts: GetAttributeListOptions): Promise<CatalogAttributeList | null>;
19
+ getBrands(): Promise<Brand[]>;
20
+ getProductFilters(opts?: GetProductFiltersOptions): Promise<ProductFilters>;
21
+ getSearchSuggestions(opts: GetSearchSuggestionsOptions): Promise<SearchSuggestion[]>;
22
+ checkAvailability: never;
23
+ }
24
+ export declare function createCatalogModule(graphqlUrl: string, getHeaders: RequestHeadersProvider, getContext: () => BacanoClientContext, storageUrl?: string): Omit<CatalogModule, 'checkAvailability'>;
@@ -0,0 +1,42 @@
1
+ import { type RequestHeadersProvider } from "../transport/graphql";
2
+ import type { BacanoClientContext, CheckoutResult, CheckoutSubmission, WebsiteCheckoutAddress, WebsiteCheckoutItem, WebsiteCouponActionResult, WebsiteDeliveryOption, WebsiteFreeShippingProgress, WebsiteLocationOptions, WebsitePaymentMethod, WebsitePaymentOption, WebsitePaymentSessionResult, WebsiteShippingPolicy, WebsiteShippingQuote } from "../types";
3
+ import type { CartSessionStorage } from "./cart-session";
4
+ export interface CheckoutModule {
5
+ getLocationOptions(): Promise<WebsiteLocationOptions>;
6
+ getDeliveryOptions(): Promise<WebsiteDeliveryOption[]>;
7
+ getShippingQuotes(input: {
8
+ address: WebsiteCheckoutAddress;
9
+ items?: WebsiteCheckoutItem[];
10
+ }): Promise<WebsiteShippingQuote[]>;
11
+ getShippingPolicy(): Promise<WebsiteShippingPolicy>;
12
+ getFreeShippingProgress(input: {
13
+ items: WebsiteCheckoutItem[];
14
+ }): Promise<WebsiteFreeShippingProgress>;
15
+ getPaymentMethods(): Promise<WebsitePaymentMethod[]>;
16
+ getPaymentOptions(input: {
17
+ fulfillmentFamily: "PICKUP" | "SHIPPING";
18
+ }): Promise<WebsitePaymentOption[]>;
19
+ validateCoupon(input: {
20
+ code: string;
21
+ }): Promise<WebsiteCouponActionResult>;
22
+ applyCoupon(input: {
23
+ code: string;
24
+ }): Promise<WebsiteCouponActionResult>;
25
+ removeCoupon(input: {
26
+ couponId: string;
27
+ }): Promise<WebsiteCouponActionResult>;
28
+ submit(input: CheckoutSubmission): Promise<CheckoutResult>;
29
+ createPaymentSession(input: {
30
+ orderId?: string;
31
+ publicOrderToken?: string;
32
+ paymentMethodId: string;
33
+ returnUrl: string;
34
+ }): Promise<WebsitePaymentSessionResult>;
35
+ reconcilePaymentSession(input: {
36
+ orderId: string;
37
+ publicOrderToken: string;
38
+ paymentSessionId: string;
39
+ gatewayTransactionId: string;
40
+ }): Promise<WebsitePaymentSessionResult>;
41
+ }
42
+ export declare function createCheckoutModule(graphqlUrl: string, getHeaders: RequestHeadersProvider, getContext: () => BacanoClientContext, cartSessionStorage: CartSessionStorage): CheckoutModule;
@@ -0,0 +1,9 @@
1
+ import type { GetContentOptions, ContentEntry, ProductContentBlock, BacanoClientContext } from '../types';
2
+ import { type RequestHeadersProvider } from '../transport/graphql';
3
+ export interface ContentModule {
4
+ getByKey(key: string, opts?: GetContentOptions): Promise<ContentEntry | null>;
5
+ getByCategory(categoryKey: string, opts?: GetContentOptions): Promise<ContentEntry[]>;
6
+ getByTag(tag: string, opts?: GetContentOptions): Promise<ContentEntry[]>;
7
+ getForProduct(productId: string, opts?: GetContentOptions): Promise<ProductContentBlock[]>;
8
+ }
9
+ export declare function createContentModule(graphqlUrl: string, getHeaders: RequestHeadersProvider, getContext: () => BacanoClientContext, storageUrl?: string): ContentModule;
@@ -0,0 +1,9 @@
1
+ import type { BacanoClientContext, GetOrdersOptions, Order, PublicOrder, PublicOrderLookupInput, WaitForPublicOrderPaymentInput } from '../types';
2
+ import { type RequestHeadersProvider } from '../transport/graphql';
3
+ export interface OrdersModule {
4
+ list(opts?: GetOrdersOptions): Promise<Order[]>;
5
+ get(orderId: string): Promise<Order | null>;
6
+ getPublicOrder(input: PublicOrderLookupInput): Promise<PublicOrder | null>;
7
+ waitForPayment(input: WaitForPublicOrderPaymentInput): Promise<PublicOrder>;
8
+ }
9
+ export declare function createOrdersModule(graphqlUrl: string, getHeaders: RequestHeadersProvider, getContext: () => BacanoClientContext): OrdersModule;
@@ -0,0 +1,8 @@
1
+ import type { CustomerAddress, CustomerProfile, CustomerProfileUpdate } from "../types";
2
+ import { type RequestHeadersProvider } from "../transport/graphql";
3
+ export interface ProfileModule {
4
+ get(): Promise<CustomerProfile>;
5
+ getAddresses(): Promise<CustomerAddress[]>;
6
+ update(data: CustomerProfileUpdate): Promise<CustomerProfile>;
7
+ }
8
+ export declare function createProfileModule(graphqlUrl: string, getHeaders: RequestHeadersProvider): ProfileModule;
@@ -0,0 +1,3 @@
1
+ import type { BacanoClientContext } from "../types";
2
+ import { type RequestHeadersProvider } from "../transport/graphql";
3
+ export declare function resolveWebsite(graphqlUrl: string, slug: string, headers?: RequestHeadersProvider): Promise<BacanoClientContext>;
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@bacano/sdk",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript SDK for building websites on the Bacano ERP",
5
+ "main": "./index.cjs",
6
+ "module": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "import": "./index.js",
12
+ "require": "./index.cjs"
13
+ },
14
+ "./graphql": {
15
+ "types": "./graphql.d.ts",
16
+ "import": "./graphql.js",
17
+ "require": "./graphql.cjs"
18
+ },
19
+ "./react": {
20
+ "types": "./react.d.ts",
21
+ "import": "./react.js",
22
+ "require": "./react.cjs"
23
+ }
24
+ },
25
+ "sideEffects": false,
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/pulpo-labs/erp.git",
32
+ "directory": "libs/sdk"
33
+ },
34
+ "homepage": "https://github.com/pulpo-labs/erp/tree/main/libs/sdk#readme",
35
+ "peerDependencies": {
36
+ "react": ">=18.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "react": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "keywords": [
44
+ "bacano",
45
+ "erp",
46
+ "website",
47
+ "sdk",
48
+ "graphql",
49
+ "ecommerce"
50
+ ],
51
+ "license": "MIT"
52
+ }
@@ -0,0 +1,7 @@
1
+ import type { BacanoClient } from '../client';
2
+ export interface BacanoClientContextValue {
3
+ client: BacanoClient | null;
4
+ loading: boolean;
5
+ error: Error | null;
6
+ }
7
+ export declare const BacanoReactContext: import("react").Context<BacanoClientContextValue>;
@@ -0,0 +1,74 @@
1
+ import type { BacanoClient } from '../client';
2
+ import type { Product, ProductCategory, CatalogCategoryList, CatalogAttributeList, Brand, ProductAvailability, ProductFilters, GetProductsOptions, GetCategoryListOptions, GetAttributeListOptions, GetProductFiltersOptions, SearchSuggestion, GetSearchSuggestionsOptions, ContentEntry, GetContentOptions, Cart, CartItem, StartGuestCheckoutInput, WebsiteFulfillmentFamily, WebsiteGuestContact, CheckoutSubmission, CheckoutResult, Order, GetOrdersOptions, CustomerProfile, CustomerProfileUpdate, AsyncState } from '../types';
3
+ /** Returns the initialized BacanoClient instance */
4
+ export declare function useBacano(): BacanoClient;
5
+ /** Returns the initialization state (for loading/error handling) */
6
+ export declare function useBacanoState(): import("./context").BacanoClientContextValue;
7
+ export declare function useProducts(opts?: GetProductsOptions): AsyncState<Product[]> & {
8
+ refetch: () => void;
9
+ };
10
+ export declare function useProduct(productId: string | null): AsyncState<Product | null> & {
11
+ refetch: () => void;
12
+ };
13
+ export declare function useCategories(): AsyncState<ProductCategory[]> & {
14
+ refetch: () => void;
15
+ };
16
+ export declare function useCategoryList(opts: GetCategoryListOptions | null): AsyncState<CatalogCategoryList | null> & {
17
+ refetch: () => void;
18
+ };
19
+ export declare function useAttributeList(opts: GetAttributeListOptions | null): AsyncState<CatalogAttributeList | null> & {
20
+ refetch: () => void;
21
+ };
22
+ export declare function useBrands(): AsyncState<Brand[]> & {
23
+ refetch: () => void;
24
+ };
25
+ export declare function useProductFilters(opts?: GetProductFiltersOptions): AsyncState<ProductFilters> & {
26
+ refetch: () => void;
27
+ };
28
+ export declare function useSearchSuggestions(opts?: GetSearchSuggestionsOptions): AsyncState<SearchSuggestion[]> & {
29
+ refetch: () => void;
30
+ };
31
+ export declare function useAvailability(productVariantIds: string[]): AsyncState<ProductAvailability[]> & {
32
+ refetch: () => void;
33
+ };
34
+ export declare function useContentByKey(key: string | null, opts?: GetContentOptions): AsyncState<ContentEntry | null> & {
35
+ refetch: () => void;
36
+ };
37
+ export declare function useContentByCategory(categoryKey: string | null, opts?: GetContentOptions): AsyncState<ContentEntry[]> & {
38
+ refetch: () => void;
39
+ };
40
+ export declare function useContentByTag(tag: string | null, opts?: GetContentOptions): AsyncState<ContentEntry[]> & {
41
+ refetch: () => void;
42
+ };
43
+ export declare function useCart(): {
44
+ cart: Cart | null;
45
+ loading: boolean;
46
+ error: Error | null;
47
+ getOrCreate: (contact?: WebsiteGuestContact, fulfillmentFamily?: WebsiteFulfillmentFamily) => Promise<Cart>;
48
+ startCheckout: (input: StartGuestCheckoutInput) => Promise<Cart>;
49
+ addItem: (productVariantId: string, quantity: number) => Promise<CartItem>;
50
+ updateItem: (cartItemId: string, quantity: number) => Promise<{
51
+ id: string;
52
+ quantity: number;
53
+ }>;
54
+ removeItem: (cartItemId: string) => Promise<void>;
55
+ refresh: () => Promise<void>;
56
+ };
57
+ export declare function useCheckout(): {
58
+ checkout: (input: CheckoutSubmission) => Promise<CheckoutResult>;
59
+ loading: boolean;
60
+ error: Error | null;
61
+ };
62
+ export declare function useOrders(opts?: GetOrdersOptions): AsyncState<Order[]> & {
63
+ refetch: () => void;
64
+ };
65
+ export declare function useOrder(orderId: string | null): AsyncState<Order | null> & {
66
+ refetch: () => void;
67
+ };
68
+ export declare function useProfile(): {
69
+ profile: CustomerProfile | null;
70
+ loading: boolean;
71
+ error: Error | null;
72
+ updateProfile: (data: CustomerProfileUpdate) => Promise<CustomerProfile>;
73
+ refresh: () => void;
74
+ };
@@ -0,0 +1,7 @@
1
+ import { type JSX, type ReactNode } from "react";
2
+ import type { BacanoClientConfig } from "../types";
3
+ export interface BacanoProviderProps {
4
+ config: BacanoClientConfig;
5
+ children: ReactNode;
6
+ }
7
+ export declare function BacanoProvider({ config, children, }: BacanoProviderProps): JSX.Element;