diff --git a/package.json b/package.json index 66153d4..839f804 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuxt-swell", - "version": "0.1.5", + "version": "0.1.6", "license": "MIT", "type": "module", "repository": { @@ -37,6 +37,7 @@ "@nuxt/module-builder": "^0.2.1", "@nuxt/schema": "^3.0.0", "@nuxtjs/eslint-config-typescript": "^11.0.0", + "@types/swell-js": "^3.18.0", "eslint": "^8.26.0", "nuxt": "^3.0.0" } diff --git a/src/module.ts b/src/module.ts index 547fdfe..9116e71 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,9 +1,7 @@ import { resolve } from 'path' import { fileURLToPath } from 'url' import { defineNuxtModule, addPlugin, addImportsDir, extendViteConfig } from '@nuxt/kit' -import { InitOptions } from './types/swell-js/index' -export * from './types/swell' -export * from './types/swell-js' +import { InitOptions } from 'swell-js' export interface ModuleOptions { storeId?: string, diff --git a/src/runtime/composables/useSwellCategories.ts b/src/runtime/composables/useSwellCategories.ts index e261e40..7fff99b 100644 --- a/src/runtime/composables/useSwellCategories.ts +++ b/src/runtime/composables/useSwellCategories.ts @@ -1,6 +1,6 @@ import { useState } from '#app' import { computed, ComputedRef } from 'vue' -import { Category } from '../../types/swell-js' +import { Category } from 'swell-js' import useSwell from './useSwell' export type UseCategoriesReturnType = { diff --git a/src/runtime/composables/useSwellProduct.ts b/src/runtime/composables/useSwellProduct.ts index 96d91d6..f931d41 100644 --- a/src/runtime/composables/useSwellProduct.ts +++ b/src/runtime/composables/useSwellProduct.ts @@ -1,6 +1,6 @@ import { useState } from '#app' import { computed, ComputedRef } from 'vue' -import { Product, Query } from '../../types/swell-js' +import { Product, Query } from 'swell-js' import useSwell from './useSwell' export type UseProductReturnType = { diff --git a/src/runtime/composables/useSwellProducts.ts b/src/runtime/composables/useSwellProducts.ts index c66246b..1b14527 100644 --- a/src/runtime/composables/useSwellProducts.ts +++ b/src/runtime/composables/useSwellProducts.ts @@ -1,7 +1,7 @@ import { useState } from '#app' import type { ComputedRef } from 'vue' import { computed } from 'vue' -import { ListResult, Product, Query, SearchQuery } from '../../types/swell-js' +import { ListResult, Product, Query, SearchQuery } from 'swell-js' import useSwell from './useSwell' export type UseProductsReturnType = { diff --git a/src/types/swell-js/index.ts b/src/types/swell-js/index.ts deleted file mode 100644 index 96ede00..0000000 --- a/src/types/swell-js/index.ts +++ /dev/null @@ -1,589 +0,0 @@ -// Type definitions for swell-js 3.17 -// Project: https://github.com/swellstores/swell-js#readme -// Definitions by: Gus Fune -// Markus -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -export interface Query { - limit?: number; - page?: number; - expand?: string[]; -} - -export interface SearchQuery extends Query { - search: string; -} - -export interface ProductQuery extends Query { - category?: string; - categories?: string[]; - $filters?: unknown; -} - -export interface CartOption { - name: string; - value: string; -} - -export interface CreateAccountInput { - email: string; - first_name?: string; - last_name?: string; - email_optin?: boolean; - password?: string; -} - -export interface ListResult { - count: number; - results: T[]; - page: number; - pages?: { - [key: string]: { - start: number; - end: number; - }; - }; -} - -export type PurchaseOptions = 'subscription' | 'standard'; - -export interface ImageCamelCase { - file: { - id: string; - dateUploaded: string; - length: number; - md5: string; - filename: string | null; - contentType: string; - metadata: unknown; - url: string; - width: number; - height: number; - }; - id: string; -} - -export interface ImageSnakeCase { - file: { - id: string; - date_uploaded: string; - length: number; - md5: string; - filename?: string | null; - content_type: string; - metadata: unknown; - url: string; - width: number; - height: number; - }; - id: string; -} - -export type Image = ImageCamelCase | ImageSnakeCase; - -export interface ProductCamelCase { - price: number; - sale: boolean; - salePrice?: number; - sku: unknown; - slug: string; - stockLevel: number; - stockPurchasable: boolean; - stockTracking: boolean; - options?: Array<{ - id: string; - values: [ - { - name: string; - id: string; - price: null; - shipmentWeight: null; - description: null; - }, - ]; - active: true; - description: null; - inputType: 'select'; - name: 'Size'; - required: true; - variant: true; - }>; - attributes: unknown; - content: any; - description: string; - id: string; - images: ImageCamelCase[]; - name: string; - variants?: { - count: number; - results: ProductCamelCase[]; - }; - crossSells?: Array<{ - id: string; - productId: string; - }>; - upSells?: Array<{ - id: string; - productId: string; - }>; -} - -export interface ProductSnakeCase { - price: number; - sale: boolean; - sale_price?: number; - sku: unknown; - slug: string; - stock_level: number; - stock_purchasable: boolean; - stock_tracking: boolean; - options?: Array<{ - id: string; - values: [ - { - name: string; - id: string; - price: null; - shipment_weight: null; - description: null; - }, - ]; - active: true; - description: null; - input_type: 'select'; - name: 'Size'; - required: true; - variant: true; - }>; - attributes: unknown; - content: any; - description: string; - id: string; - images: ImageSnakeCase[]; - name: string; - variants?: { - count: number; - results: ProductSnakeCase[]; - }; - cross_sells?: Array<{ - id: string; - product_id: string; - }>; - up_sells?: Array<{ - id: string; - product_id: string; - }>; -} - -export type Product = ProductCamelCase | ProductSnakeCase; - -export interface CartItemCamelCase { - discountEach: number; - discountTotal: number; - id: string; - origPrice: number; - price: number; - priceTotal: number; - productId: string; - quantity: number; - shipmentWeight: number; - taxEach: number; - taxTotal: number; - variant: null; - product: Product; -} - -export interface CartItemSnakeCase { - discount_each: number; - discount_total: number; - id: string; - orig_price: number; - price: number; - price_total: number; - product_id: string; - quantity: number; - shipment_weight: number; - tax_each: number; - tax_total: number; - variant: null; - product: Product; -} - -export type CartItem = CartItemCamelCase | CartItemSnakeCase; - -export interface Address { - address1: string; - address2?: string; - city: string; - state: string; - zip: string; - country: string; -} - -export interface AddressWithContact extends Address { - name: string; - phone: string; -} - -export interface BillingCamelCase extends AddressWithContact { - accountCardId: string | null; - firstName: string; - lastName: string; -} - -export interface BillingSnakeCase extends AddressWithContact { - account_card_id: string | null; - first_name: string; - last_name: string; -} - -export type Billing = BillingCamelCase | BillingSnakeCase; - -export interface ShippingCamelCase extends AddressWithContact { - accountAddressId: string | null; - firstName: string; - lastName: string; -} - -export interface ShippingSnakeCase extends AddressWithContact { - account_address_id: string | null; - first_name: string; - last_name: string; -} - -export type Shipping = ShippingCamelCase | ShippingSnakeCase; - -export interface CartCamelCase { - accountLoggedIn: unknown; - authTotal: number; - billing: Billing; - captureTotal: number; - checkoutId: string; - checkoutUrl: string; - coupon: unknown; - currency: string; - dateAbandoned: string; - dateCreated: string; - discounts: unknown; - discountTotal: number; - giftcardTotal: number; - grandTotal: number; - guest: true; - id: string; - itemDiscount: number; - itemQuantity: number; - items: CartItem[]; - itemShipmentWeight: number; - itemTax: number; - promotionIds: unknown; - promotions: unknown; - recovered: boolean; - shipmentDelivery: boolean; - shipmentDiscount: number; - shipmentPrice: number; - shipmentTotal: number; - shipping: unknown; - subTotal: number; - taxes: unknown; - taxIncludedTotal: number; - taxTotal: number; -} - -export interface CartSnakeCase { - account_logged_in: unknown; - auth_total: number; - billing: unknown; - capture_total: number; - checkout_id: string; - checkout_url: string; - coupon: unknown; - currency: string; - date_abandoned: string; - date_created: string; - discounts: unknown; - discount_total: number; - giftcard_total: number; - grand_total: number; - guest: boolean; - id: string; - item_discount: number; - item_quantity: number; - items: CartItem[]; - item_shipment_weight: number; - item_tax: number; - promotion_ids: unknown; - promotions: unknown; - recovered: boolean; - shipment_delivery: boolean; - shipment_discount: number; - shipment_price: number; - shipment_total: number; - shipping: unknown; - sub_total: number; - taxes: unknown; - tax_included_total: number; - tax_total: number; -} - -export type Cart = CartCamelCase | CartSnakeCase; - -export interface OrderCamelCase { - account: unknown; - accountCreditAmount: unknown; - accountCreditApplied: unknown; - accountId: string; - accountInfoSaved: unknown; - accountLoggedIn: unknown; - billing: Billing; - comments: unknown; - coupon: unknown; - couponCode: unknown; - currency: string; - dateCreated: string; - delivered: boolean; - discounts: unknown; - discountTotal: number; - gift: unknown; - giftcards: unknown; - giftcardTotal: number; - giftMessage: unknown; - grandTotal: number; - guest: boolean; - id: string; - itemDiscount: number; - itemQuantity: number; - itemQuantityCancelable: number; - itemQuantityCanceled: number; - itemQuantityDeliverable: number; - itemQuantityDelivered: number; - itemQuantityReturnable: number; - itemQuantityReturned: number; - items: CartItem[]; - itemShipmentWeight: number; - itemTax: number; - itemTaxIncluded: unknown; - metadata: unknown; - number: string; - paid: boolean; - promotionIds: unknown; - promotions: unknown; - shipmentDelivery: boolean; - shipmentDiscount: number; - shipmentPrice: number; - shipmentRating: unknown; - shipmentTax: unknown; - shipmentTaxIncluded: unknown; - shipmentTotal: number; - shipping: Shipping; - status: string; - subTotal: number; - taxes: unknown; - taxIncludedTotal: number; - taxTotal: number; -} - -export interface OrderSnakeCase { - account: unknown; - account_credit_amount: unknown; - account_credit_applied: unknown; - account_id: string; - account_info_saved: unknown; - account_logged_in: unknown; - billing: Billing; - comments: unknown; - coupon: unknown; - coupon_code: unknown; - currency: string; - date_created: string; - delivered: boolean; - discounts: unknown; - discount_total: number; - gift: unknown; - giftcards: unknown; - giftcard_total: number; - gift_message: unknown; - grand_total: number; - guest: boolean; - id: string; - item_discount: number; - item_quantity: number; - item_quantity_cancelable: number; - item_quantity_canceled: number; - item_quantity_deliverable: number; - item_quantity_delivered: number; - item_quantity_returnable: number; - item_quantity_returned: number; - items: CartItem[]; - item_shipment_weight: number; - item_tax: number; - item_tax_included: unknown; - metadata: unknown; - number: string; - paid: boolean; - promotion_ids: unknown; - promotions: unknown; - shipment_delivery: boolean; - shipment_discount: number; - shipment_price: number; - shipment_rating: unknown; - shipment_tax: unknown; - shipment_tax_included: unknown; - shipment_total: number; - shipping: Shipping; - status: string; - sub_total: number; - taxes: unknown; - tax_included_total: number; - tax_total: number; -} - -export type Order = OrderCamelCase | OrderSnakeCase; - -export interface CartInput { - product_id: string; - quantity?: number; - options?: CartOption[]; - purchase_option?: { - plan_id?: string; - type?: PurchaseOptions; - }; -} - -export interface InitOptions { - api?: string; - currency?: string; - locale?: string; - previewContent?: boolean | null; - session?: string; - timeout?: number; - url?: string | null; - useCamelCase?: boolean | null; - vaultUrl?: string; -} - -export interface CategoryCamelCase { - description?: string; - id: string; - images: Image[]; - metaDescription?: string; - name: string; - parentId?: string; - slug: string; - topId: string; -} - -export interface CategorySnakeCase { - description?: string; - id: string; - images: Image[]; - meta_description?: string; - name: string; - parent_id?: string; - slug: string; - topId: string; -} - -export type Category = CategoryCamelCase | CategorySnakeCase; - -export interface Attribute { - filterable: boolean; - id: string; - name: string; - searchable: boolean; - values: string[]; - visible: boolean; -} - -export interface account { - create(input: CreateAccountInput): Promise; - createAddress(input: AddressWithContact): Promise; - createCard(input: object): Promise; - deleteAddress(id: string): Promise; - deleteCard(id: string): Promise; - get(): Promise; - getAddresses(): Promise; - getOrder(id?: string): Promise; - listAddresses(): Promise; - listCards(): Promise; - listOrders(input: object): Promise; - login(user: string, password: string): Promise; - logout(): Promise; - recover(input: object): Promise; - update(input: object): Promise; - updateCard(input: object): Promise; - updateAddress(id: string, data: Address): Promise; -} - -export interface attributes { - get(input: string): Promise; - get(): Promise>; - list(input: Query): Promise>; -} - -export interface card { - createToken(input: object): Promise; - validateCVC(input: string): boolean; - validateExpiry(input: string): boolean; - validateNumber(input: string): boolean; -} - -export interface cart { - addItem(input: CartInput): Promise; - applyCoupon(input: string): Promise; - applyGiftcard(input: string): Promise; - get(): Promise; - getSettings(): Promise; - removeCoupon(): Promise; - removeGiftcard(itemId: string): Promise; - removeItem(itemId: string): Promise; - setItems(input: CartInput[]): Promise; - submitOrder(): Promise; - update(input: any): Promise; - updateItem(itemId: string, input: any): Promise; -} - -export interface categories { - get(input: string): Promise; - get(): Promise>; - list(input: object): Promise>; -} - -export interface currency { - format(input: number, format: object): string; - list(): Promise>; - select(input: string): Promise; - selected(): Promise; -} - -export interface locale { - selected(): Promise; - select(locale: string): Promise; -} - -export interface payment { - createElements(input: object): Promise; - tokenize(input: object): void; -} - -export interface products { - get(productId: string): Promise; - list(input: ProductQuery): Promise>; - variation(productId: string, options: CartOption): Promise; -} - -export interface settings { - get(): Promise; - load(): Promise; - menus(input?: string): Promise; - payments(): Promise; -} - -export interface subscriptions { - addItem(id: string, input: object): Promise; - create(input: object): Promise; - get(id: string): Promise; - list(): Promise>; - removeItem(id: string, itemId: string): Promise; - update(id: string, input: object): Promise; - updateItem(id: string, itemId: string, input: any): Promise; -} diff --git a/src/types/swell.ts b/src/types/swell.ts index 6aea2ae..a31c8f1 100644 --- a/src/types/swell.ts +++ b/src/types/swell.ts @@ -1,12 +1,20 @@ -import { - Address, AddressWithContact, Attribute, Cart, CartInput, CartOption, - Category, CreateAccountInput, InitOptions, ListResult, Order, Product, ProductQuery, - Query -} from './swell-js' - /** * Override namepsace swell to make composables typed. */ +import { + Address, + AddressWithContact, + Attribute, Cart, + CartInput, CartOption, Category, + CreateAccountInput, + InitOptions, + ListResult, Order, Product, ProductQuery, + Query, ShippingRates +} from 'swell-js' +import { Currency, CurrencySelect } from 'swell-js/currency' +import { Locale } from 'swell-js/locale' +import { Settings } from 'swell-js/settings' + export interface Swell { init(storeId: string, publicKey: string, options?: InitOptions): void get(url: string, query: object): Promise @@ -19,8 +27,8 @@ export interface Swell { deleteAddress(id: string): Promise; deleteCard(id: string): Promise; get(): Promise; - getAddresses(): Promise; - getOrder(id?: string): Promise; + getAddresses({}): Promise; + getOrder(id?: string): Promise; listAddresses(): Promise; listCards(): Promise; listOrders(input: object): Promise; @@ -48,6 +56,7 @@ export interface Swell { applyGiftcard(input: string): Promise; get(): Promise; getSettings(): Promise; + getShippingRates(): Promise; removeCoupon(): Promise; removeGiftcard(itemId: string): Promise; removeItem(itemId: string): Promise; @@ -63,13 +72,13 @@ export interface Swell { } currency: { format(input: number, format: object): string; - list(): Promise>; - select(input: string): Promise; - selected(): Promise; + list(): Promise; + select(input: string): Promise; + selected(): string; } locale: { - selected(): Promise; - select(locale: string): Promise; + selected(): string; + select(locale: string): Promise; } payment: { createElements(input: object): Promise; @@ -81,7 +90,7 @@ export interface Swell { variation(productId: string, options: CartOption): Promise; } settings: { - get(): Promise; + get(): Promise; load(): Promise; menus(input?: string): Promise; payments(): Promise; diff --git a/yarn.lock b/yarn.lock index 51fe147..a9e89bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -694,6 +694,11 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== +"@types/swell-js@^3.18.0": + version "3.18.0" + resolved "https://registry.yarnpkg.com/@types/swell-js/-/swell-js-3.18.0.tgz#62386c74876fccf5e9f28763dbd67c39a4fda5d6" + integrity sha512-uCUDFfefUz77Ohlji5pybPWeZWBARkmzp/nPp2WLcZNw42VObD6YhIRC9ElxMIWABOS7vGa9UJRe+L++0kfMAg== + "@typescript-eslint/eslint-plugin@^5.36.1": version "5.43.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.43.0.tgz#4a5248eb31b454715ddfbf8cfbf497529a0a78bc"