├── .circleci ├── config.yml └── load-nvm.sh ├── .codeclimate.yml ├── .dockerignore ├── .eslintignore ├── .eslintrc ├── .github ├── CONTRIBUTING.md └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .npmignore ├── .prettierrc ├── Dockerfile.test-runtime ├── LICENSE.md ├── README.md ├── docker-compose-cypress.yml ├── docker-compose-spree.yml ├── docker-compose-test-runtime.yml ├── docker └── express │ ├── .eslintrc │ ├── Dockerfile.express │ ├── express-docker-entrypoint.sh │ ├── index.js │ └── package.json ├── package-lock.json ├── package.json ├── packages ├── sdk-core │ ├── README.md │ ├── package.json │ ├── src │ │ ├── Client.ts │ │ ├── Http.ts │ │ ├── errors │ │ │ ├── BasicSpreeError.ts │ │ │ ├── CastError.ts │ │ │ ├── DeserializeError.ts │ │ │ ├── DocumentRelationshipError.ts │ │ │ ├── ExpandedSpreeError.ts │ │ │ ├── FetchError.ts │ │ │ ├── MisconfigurationError.ts │ │ │ ├── NoResponseError.ts │ │ │ ├── SpreeError.ts │ │ │ ├── SpreeSDKError.ts │ │ │ └── index.ts │ │ ├── helpers │ │ │ ├── index.ts │ │ │ ├── jsonApi.ts │ │ │ ├── request.ts │ │ │ ├── result.ts │ │ │ └── squashAndPreparePositionalArguments.ts │ │ ├── index.ts │ │ └── interfaces │ │ │ ├── ClientConfig.ts │ │ │ ├── CreateCustomizedFetchFetcher.ts │ │ │ ├── DeepAnyObject.ts │ │ │ ├── EmptyObject.ts │ │ │ ├── ErrorClass.ts │ │ │ ├── ErrorType.ts │ │ │ ├── Errors.ts │ │ │ ├── FetchConfig.ts │ │ │ ├── ImageTransformation.ts │ │ │ ├── JsonApi.ts │ │ │ ├── LocalizedSlugs.ts │ │ │ ├── NoContent.ts │ │ │ ├── Query.ts │ │ │ ├── RawFetchRequest.ts │ │ │ ├── RawFetchResponse.ts │ │ │ ├── Relationships.ts │ │ │ ├── Result.ts │ │ │ ├── ResultResponse.ts │ │ │ ├── Token.ts │ │ │ ├── WithCommonOptions.ts │ │ │ ├── globals.d.ts │ │ │ └── index.ts │ ├── tsconfig.json │ └── webpack.config.mjs ├── sdk-fetcher-axios │ ├── README.md │ ├── globals.d.ts │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.ts │ ├── tsconfig-client.json │ ├── tsconfig-server.json │ ├── tsconfig.json │ ├── webpack.client.mjs │ ├── webpack.common.maker.mjs │ ├── webpack.config.mjs │ └── webpack.server.mjs ├── sdk-fetcher-node │ ├── README.md │ ├── globals.d.ts │ ├── package.json │ ├── src │ │ └── index.ts │ ├── tsconfig-client.json │ ├── tsconfig-server.json │ ├── tsconfig.json │ ├── webpack.client.mjs │ ├── webpack.common.maker.mjs │ ├── webpack.config.mjs │ └── webpack.server.mjs ├── sdk-platform │ ├── README.md │ ├── package.json │ ├── rollup.config.mjs │ ├── src │ │ ├── endpoints │ │ │ ├── Addresses.ts │ │ │ ├── Adjustments.ts │ │ │ ├── Authentication.ts │ │ │ ├── Classifications.ts │ │ │ ├── Countries.ts │ │ │ ├── Digitals.ts │ │ │ ├── Items.ts │ │ │ ├── Links.ts │ │ │ ├── MenuItems.ts │ │ │ ├── Menus.ts │ │ │ ├── OptionTypes.ts │ │ │ ├── OptionValues.ts │ │ │ ├── Orders.ts │ │ │ ├── Pages.ts │ │ │ ├── PaymentMethods.ts │ │ │ ├── Payments.ts │ │ │ ├── Products.ts │ │ │ ├── PromotionActions.ts │ │ │ ├── PromotionCategories.ts │ │ │ ├── PromotionRules.ts │ │ │ ├── Promotions.ts │ │ │ ├── Roles.ts │ │ │ ├── Sections.ts │ │ │ ├── Shipments.ts │ │ │ ├── ShippingCategories.ts │ │ │ ├── ShippingMethods.ts │ │ │ ├── States.ts │ │ │ ├── StockItems.ts │ │ │ ├── StockLocations.ts │ │ │ ├── StoreCreditCategories.ts │ │ │ ├── StoreCreditTypes.ts │ │ │ ├── StoreCredits.ts │ │ │ ├── TaxCategories.ts │ │ │ ├── TaxRates.ts │ │ │ ├── Taxonomies.ts │ │ │ ├── Taxons.ts │ │ │ ├── Users.ts │ │ │ ├── Variants.ts │ │ │ ├── WebhookEvents.ts │ │ │ ├── WebhookSubscribers.ts │ │ │ ├── WishedItems.ts │ │ │ ├── Wishlists.ts │ │ │ ├── Zones.ts │ │ │ └── index.ts │ │ ├── helpers │ │ │ └── auth.ts │ │ ├── index.ts │ │ ├── interfaces │ │ │ ├── Addresses.ts │ │ │ ├── Adjustments.ts │ │ │ ├── Authentication.ts │ │ │ ├── Classifications.ts │ │ │ ├── Countries.ts │ │ │ ├── DigitalAsset.ts │ │ │ ├── Digitals.ts │ │ │ ├── Items.ts │ │ │ ├── Links.ts │ │ │ ├── MenuItems.ts │ │ │ ├── Menus.ts │ │ │ ├── OptionTypes.ts │ │ │ ├── OptionValues.ts │ │ │ ├── Orders.ts │ │ │ ├── Pages.ts │ │ │ ├── PaymentMethods.ts │ │ │ ├── Payments.ts │ │ │ ├── Products.ts │ │ │ ├── PromotionActions.ts │ │ │ ├── PromotionCategories.ts │ │ │ ├── PromotionRules.ts │ │ │ ├── Promotions.ts │ │ │ ├── Roles.ts │ │ │ ├── Sections.ts │ │ │ ├── Shipments.ts │ │ │ ├── ShippingCategories.ts │ │ │ ├── ShippingMethods.ts │ │ │ ├── States.ts │ │ │ ├── StockItems.ts │ │ │ ├── StockLocations.ts │ │ │ ├── StoreCreditCategories.ts │ │ │ ├── StoreCreditTypes.ts │ │ │ ├── StoreCredits.ts │ │ │ ├── TaxCategories.ts │ │ │ ├── TaxRates.ts │ │ │ ├── Taxonomies.ts │ │ │ ├── Taxons.ts │ │ │ ├── Users.ts │ │ │ ├── Variants.ts │ │ │ ├── Vendor.ts │ │ │ ├── WebhookEvents.ts │ │ │ ├── WebhookSubscribers.ts │ │ │ ├── WishedItems.ts │ │ │ ├── Wishlists.ts │ │ │ └── Zones.ts │ │ ├── makeClient.ts │ │ └── routes.ts │ ├── tsconfig-client.json │ ├── tsconfig-server.json │ ├── tsconfig.json │ ├── webpack.client.mjs │ ├── webpack.common.maker.mjs │ ├── webpack.config.mjs │ └── webpack.server.mjs └── sdk-storefront │ ├── README.md │ ├── package.json │ ├── rollup.config.mjs │ ├── src │ ├── endpoints │ │ ├── Account.ts │ │ ├── Authentication.ts │ │ ├── Cart.ts │ │ ├── Checkout.ts │ │ ├── Countries.ts │ │ ├── DigitalAssets.ts │ │ ├── Menus.ts │ │ ├── Order.ts │ │ ├── Pages.ts │ │ ├── Products.ts │ │ ├── Taxons.ts │ │ ├── Vendors.ts │ │ ├── Wishlists.ts │ │ └── index.ts │ ├── helpers │ │ └── auth.ts │ ├── index.ts │ ├── interfaces │ │ ├── Account.ts │ │ ├── Authentication.ts │ │ ├── Cart.ts │ │ ├── Checkout.ts │ │ ├── Country.ts │ │ ├── CreditCard.ts │ │ ├── DigitalAsset.ts │ │ ├── EstimatedShippingMethod.ts │ │ ├── Menu.ts │ │ ├── Order.ts │ │ ├── Page.ts │ │ ├── PaymentMethod.ts │ │ ├── Product.ts │ │ ├── ShippingMethod.ts │ │ ├── StripeCheckoutSessionSummary.ts │ │ ├── Taxon.ts │ │ ├── Vendor.ts │ │ ├── WishedItem.ts │ │ ├── Wishlist.ts │ │ ├── attributes │ │ │ ├── Address.ts │ │ │ ├── Payment.ts │ │ │ ├── PaymentSource.ts │ │ │ └── Shipment.ts │ │ └── endpoints │ │ │ ├── CartClass.ts │ │ │ └── CheckoutClass.ts │ ├── makeClient.ts │ └── routes.ts │ ├── tsconfig-client.json │ ├── tsconfig-server.json │ ├── tsconfig.json │ ├── webpack.client.mjs │ ├── webpack.common.maker.mjs │ ├── webpack.config.mjs │ └── webpack.server.mjs ├── pages ├── alternative-setups.md ├── checkout-flow.md ├── helpers.md ├── quick-start.md ├── response-schema.md ├── switching-the-fetcher.md └── tokens.md ├── test.sh ├── tests ├── .eslintrc ├── Dockerfile.cypress ├── cypress-docker-entrypoint.sh ├── cypress.json ├── e2e │ └── spec.ts ├── fixtures │ └── order-full-address.json ├── package-lock.json ├── package.json ├── plugins │ └── index.js ├── support │ └── commands.js ├── tsconfig.json └── webpack.config.js ├── typedoc.json ├── wait-for-it.sh └── webpack-plugins ├── DeleteBeforeRun.mjs └── ProgressBar.mjs /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | jobs: 4 | build-and-test: 5 | machine: 6 | # Available machine images: https://circleci.com/docs/2.0/configuration-reference/#available-machine-images 7 | image: ubuntu-2004:202111-01 8 | working_directory: ~/app 9 | resource_class: large 10 | steps: 11 | - checkout 12 | - run: 13 | # Based on https://www.cloudesire.com/how-to-upgrade-node-on-circleci-machine-executor/ 14 | name: Install NVM NodeJS 15 | command: | 16 | . .circleci/load-nvm.sh 17 | nvm install 16 18 | nvm alias default 16 19 | - run: 20 | name: Test 21 | command: | 22 | . .circleci/load-nvm.sh 23 | echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_LOGIN" --password-stdin >/dev/null 2>&1 24 | npm run test 25 | 26 | workflows: 27 | everything: 28 | jobs: 29 | - build-and-test 30 | -------------------------------------------------------------------------------- /.circleci/load-nvm.sh: -------------------------------------------------------------------------------- 1 | export NVM_DIR="/opt/circleci/.nvm" 2 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm 3 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | checks: 3 | argument-count: 4 | config: 5 | threshold: 4 6 | complex-logic: 7 | config: 8 | threshold: 4 9 | file-lines: 10 | config: 11 | threshold: 250 12 | method-complexity: 13 | config: 14 | threshold: 12 15 | method-count: 16 | config: 17 | threshold: 20 18 | method-lines: 19 | config: 20 | threshold: 50 21 | function-lines: 22 | config: 23 | threshold: 100 24 | nested-control-flow: 25 | config: 26 | threshold: 10 27 | return-statements: 28 | config: 29 | threshold: 4 30 | plugins: 31 | eslint: 32 | enabled: true 33 | channel: "eslint-6" 34 | config: 35 | extensions: 36 | - .es6 37 | - .js 38 | - .ts 39 | duplication: 40 | enabled: true 41 | config: 42 | languages: 43 | javascript: 44 | count_threshold: 3 45 | exclude_patterns: 46 | - config/ 47 | - db/ 48 | - dist/ 49 | - features/ 50 | - "**/node_modules/" 51 | - script/ 52 | - "**/spec/" 53 | - "**/test/" 54 | - "**/tests/" 55 | - "**/vendor/" 56 | - "**/*.d.ts" 57 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | types 3 | *.tgz 4 | 5 | packages/sdk-core/dist 6 | packages/sdk-core/types 7 | packages/sdk-fetcher/dist 8 | packages/sdk-fetcher/types 9 | packages/sdk-fetcher-node-fetch/dist 10 | packages/sdk-fetcher-node-fetch/types -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | webpack.* 3 | types 4 | webpack-plugins 5 | tests/plugins 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": ["@typescript-eslint"], 5 | "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], 6 | "parserOptions": { 7 | "ecmaVersion": 6, 8 | "sourceType": "module", 9 | "ecmaFeatures": { 10 | "jsx": true 11 | } 12 | }, 13 | "rules": { 14 | "no-unused-vars": "off", 15 | "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "ignoreRestSiblings": true }], 16 | "no-duplicate-imports": "error", 17 | "@typescript-eslint/no-empty-interface": "off", 18 | "semi": "off", 19 | "@typescript-eslint/semi": ["error", "never"], 20 | "quotes": "off", 21 | "@typescript-eslint/quotes": ["error", "single", { "allowTemplateLiterals": true, "avoidEscape": true }], 22 | "object-curly-spacing": ["error", "always"], 23 | "computed-property-spacing": ["error", "never"], 24 | "@typescript-eslint/no-explicit-any": "off", 25 | "@typescript-eslint/member-delimiter-style": [ 26 | "error", 27 | { 28 | "multiline": { "delimiter": "none", "requireLast": false }, 29 | "singleline": { "delimiter": "semi", "requireLast": false } 30 | } 31 | ], 32 | "@typescript-eslint/no-namespace": "off", 33 | "@typescript-eslint/camelcase": "off", 34 | "max-lines-per-function": ["error", 100], 35 | "@typescript-eslint/explicit-function-return-type": "off" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Pull requests 2 | 3 | We gladly accept pull requests to add new features, bug fixes, documentation updates and overall any improvements to the codebase. All contributions (even the smallest ones) are welcome! 4 | 5 | Here's a quick guide: 6 | 7 | 1. Fork the repo (=**base**). 8 | 1. Clone the fork to your local machine. 9 | 1. Run `npm install` (`yarn install`). 10 | 1. Run `npm run build` (`yarn run build`) to generate the package. Alternatively, to have Webpack rebuild on every change in sources (/src), run `npm run watch` (`yarn run watch`). 11 | 1. Create a new git branch and apply the necessary changes. When updating source files, make sure to follow the [ESLint][1] rules for the project. Also, please update the README if necessary. 12 | 1. Commit and push to your fork. 13 | 1. Submit a [pull request](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork) to the **base**'s master branch. GitHub will warn of conflicts with the latest changes in the **base** repo. If there are any, please remove them and update your PR. 14 | 1. Once the PR is ready, it will appear in the **base** repo and await review from other developers. There may be comments and change requests. Try to regularly check how the PR is doing. Take part in any discussions about it. Doing so will increase the chances of it being accepted and accepted faster. Including a rich description of the change with the PR helps a lot as well. 15 | 16 | We always try to quickly respond to new submissions. That being said, it may sometimes take longer than usual due to other PRs having priority. 17 | 18 | [1]: https://eslint.org/ 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: Needs Confirmation 6 | assignees: '' 7 | --- 8 | 9 | 10 | 11 | ## Context 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ## Expected Behavior 22 | 23 | 24 | 25 | ## Possible Fix 26 | 27 | 28 | 29 | ## Your Environment 30 | 31 | 32 | * Library version: 33 | * Node and yarn/npm version: 34 | * Browser version: 35 | * Operating system: 36 | 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: 'New Feature' 6 | assignees: '' 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | 11 | A clear and concise description of what the problem is, ex. "I'm always frustrated when [...]". 12 | 13 | **Describe the solution you'd like.** 14 | 15 | A clear and concise description of what you want to happen. 16 | 17 | **Describe alternatives you've considered.** 18 | 19 | A clear and concise description of any alternative solutions or features you've considered. 20 | 21 | **Additional context** 22 | 23 | Add any other context or screenshots about the feature request here. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | yarn-error.log 4 | /dist 5 | /.vscode 6 | /.env 7 | /types 8 | *.tgz 9 | 10 | /docs 11 | /packages/sdk-core/dist 12 | /packages/sdk-core/types 13 | /packages/sdk-core/*.html 14 | /packages/sdk-storefront/dist 15 | /packages/sdk-storefront/types 16 | /packages/sdk-storefront/*.html 17 | /packages/sdk-platform/dist 18 | /packages/sdk-platform/types 19 | /packages/sdk-platform/*.html 20 | /packages/sdk-fetcher-axios/dist 21 | /packages/sdk-fetcher-axios/types 22 | /packages/sdk-fetcher-axios/*.html 23 | /packages/sdk-fetcher-node/dist 24 | /packages/sdk-fetcher-node/types 25 | /packages/sdk-fetcher-node/*.html -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | yarn-error.log 4 | /.vscode 5 | /.env 6 | *.tgz 7 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "trailingComma": "none", 4 | "singleQuote": true, 5 | "printWidth": 120, 6 | "tabWidth": 2, 7 | "arrowParens": "always" 8 | } 9 | -------------------------------------------------------------------------------- /Dockerfile.test-runtime: -------------------------------------------------------------------------------- 1 | FROM node:14.18.3 2 | 3 | WORKDIR /sdk 4 | 5 | COPY . /sdk 6 | 7 | RUN npm install npm@8.19.2 -g 8 | RUN npm install 9 | RUN npm run build 10 | RUN npm run pack 11 | 12 | FROM alpine 13 | 14 | WORKDIR /sdk 15 | 16 | COPY --from=0 /sdk/packages/sdk-storefront/spree-storefront-api-v2-sdk-*.tgz /sdk/storefront-api-v2-sdk.tgz 17 | COPY --from=0 /sdk/packages/sdk-fetcher-axios/spree-axios-fetcher-*.tgz /sdk/axios-fetcher.tgz 18 | COPY --from=0 /sdk/packages/sdk-fetcher-node/spree-node-fetcher-*.tgz /sdk/node-fetcher.tgz 19 | 20 | COPY ./wait-for-it.sh /sdk/ 21 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Spark Solutions Sp. z o.o. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spree Commerce API v2 JavaScript / TypeScript SDK 2 | 3 | A set of packages to easily integrate your JavaScript or TypeScript application with [Spree API](https://api.spreecommerce.org). You can create an entirely custom Storefront in JS/TS with Storefront SDK package including one page checkout, Single Page Apps, PWAs and so on. 4 | 5 | Developed and maintained by: 6 | 7 | ![Vendo](https://assets-global.website-files.com/6230c485f2c32ea1b0daa438/623372f40a8c54ca9aea34e8_vendo%202.svg) 8 | 9 | > All-in-one platform for all your Marketplace and B2B eCommerce needs. [Start your 30-day free trial](https://e98esoirr8c.typeform.com/contactvendo?typeform-source=spree_sdk_github) 10 | 11 | ## Documentation 12 | 13 | To check out the docs, visit [spree-sdk.upsidelab.io](https://spree-sdk.upsidelab.io/). 14 | 15 | ## About Vendo 16 | 17 | 18 | 19 | 20 | 21 | > [Vendo](https://getvendo.com?utm_source=spree_sdk_github") is a great fit for marketplaces of all sizes - either with own fulfillment and multiple warehouses or in a dropshipping model. Vendo **automates everything** from **vendor onboarding**, accepting buyer **payments in over 135 currencies**, to supplier **payouts in 50 countries**. 22 | 23 | > Vendo ensures excellent buyer experience with smooth product discovery and search, a multitude of payment methods and optimal shipping cost calculation. Vendo keeps suppliers happy with easy onboarding, automated products sync using their preferred method and easy payouts. 24 | 25 | > [Start your 30-day free trial](https://e98esoirr8c.typeform.com/contactvendo?typeform-source=spree_sdk_github) 26 | -------------------------------------------------------------------------------- /docker-compose-cypress.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | express: 5 | build: 6 | context: . 7 | dockerfile: ./docker/express/Dockerfile.express 8 | cypress: 9 | build: 10 | context: . 11 | dockerfile: ./tests/Dockerfile.cypress 12 | docker-host: 13 | image: qoomon/docker-host:3.0.3 14 | cap_add: ['NET_ADMIN', 'NET_RAW'] 15 | restart: on-failure 16 | -------------------------------------------------------------------------------- /docker-compose-spree.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | postgres: 5 | image: postgres:13-alpine 6 | environment: 7 | POSTGRES_HOST_AUTH_METHOD: trust 8 | ports: 9 | - '5432:5432' 10 | volumes: 11 | - 'postgres:/var/lib/postgresql/data' 12 | redis: 13 | image: redis:6.2-alpine 14 | volumes: 15 | - 'redis:/data' 16 | spree: # Runs production Spree 17 | depends_on: 18 | - 'postgres' 19 | - 'redis' 20 | image: sparksolutions/spree-commerce:latest 21 | entrypoint: ['/usr/bin/env'] 22 | command: bash -c "rm -rf tmp/pids/server.pid && bundle exec rails s -b 0.0.0.0 -p 3000" 23 | ports: 24 | - '3000:3000' 25 | volumes: 26 | - 'spree:/app/' 27 | - 'bundle_cache:/bundle' 28 | environment: 29 | REDIS_URL: redis://redis:6379/0 30 | DB_HOST: postgres 31 | DB_PORT: 5432 32 | DISABLE_SPRING: 1 33 | BROWSER: /dev/null 34 | SECRET_KEY_BASE: skb 35 | ALLOWED_ORIGIN_HOSTS: '*' 36 | RACK_CORS_DEBUG: 'true' 37 | 38 | volumes: 39 | spree: 40 | bundle_cache: 41 | redis: 42 | postgres: 43 | -------------------------------------------------------------------------------- /docker-compose-test-runtime.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | test-runtime: 5 | image: spree/test-runtime 6 | build: 7 | context: . 8 | dockerfile: ./Dockerfile.test-runtime 9 | -------------------------------------------------------------------------------- /docker/express/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /docker/express/Dockerfile.express: -------------------------------------------------------------------------------- 1 | FROM spree/test-runtime 2 | 3 | FROM node:14.15.4 4 | 5 | COPY --from=0 /sdk /sdk 6 | 7 | WORKDIR /app 8 | 9 | COPY ./docker/express /app 10 | 11 | RUN npm install 12 | 13 | ENTRYPOINT ./express-docker-entrypoint.sh 14 | -------------------------------------------------------------------------------- /docker/express/express-docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | /sdk/wait-for-it.sh http://docker-host:3000/api/v2/storefront/products?per_page=1 -t 300 6 | 7 | node /app/index.js 8 | -------------------------------------------------------------------------------- /docker/express/index.js: -------------------------------------------------------------------------------- 1 | import express from 'express' 2 | import bodyParser from 'body-parser' 3 | import sdk from '@spree/storefront-api-v2-sdk' 4 | import createAxiosFetcher from '@spree/axios-fetcher/dist/server/index.js' 5 | import createFetchFetcher from '@spree/node-fetcher/dist/server/index.js' 6 | 7 | const { makeClient, toJson } = sdk 8 | 9 | const app = express() 10 | 11 | app.use(bodyParser.json()) 12 | 13 | app.get('/ping', (_request, response) => { 14 | response.send('up') 15 | }) 16 | 17 | app.all('/', async (request, response, next) => { 18 | try { 19 | console.log('The Express server received a new request. Arguments: ', request.body) 20 | 21 | const { clientMethodPath, argumentsList, fetcherType } = request.body 22 | 23 | let createFetcher 24 | 25 | switch (fetcherType) { 26 | case 'axios': 27 | createFetcher = createAxiosFetcher.default 28 | break 29 | case 'fetch': 30 | createFetcher = createFetchFetcher.default 31 | break 32 | default: 33 | throw new Error(`${fetcherType} not recognized.`) 34 | } 35 | 36 | const localClient = makeClient({ host: 'http://docker-host:3000', createFetcher }) 37 | const finalNode = clientMethodPath.reduce((node, pathPart) => { 38 | if (typeof node[pathPart] === 'function') { 39 | return node[pathPart].bind(node) 40 | } 41 | 42 | return node[pathPart] 43 | }, localClient) 44 | 45 | const spreeResponse = await finalNode(...argumentsList) 46 | 47 | response.json(toJson(spreeResponse)) 48 | } catch (error) { 49 | next(error) 50 | } 51 | }) 52 | 53 | app.listen(5000, '0.0.0.0', () => { 54 | console.log('Listening at localhost and port 5000.') 55 | }) 56 | -------------------------------------------------------------------------------- /docker/express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cy-express", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "MIT", 12 | "dependencies": { 13 | "@spree/storefront-api-v2-sdk": "file:/sdk/storefront-api-v2-sdk.tgz", 14 | "@spree/axios-fetcher": "file:/sdk/axios-fetcher.tgz", 15 | "@spree/node-fetcher": "file:/sdk/node-fetcher.tgz", 16 | "axios": "^0.25.0", 17 | "express": "^4.17.1", 18 | "node-fetch": "^2.6.7" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spree-sdk", 3 | "private": true, 4 | "scripts": { 5 | "build:sdk-core": "npm run build --workspace=@spree/core-api-v2-sdk", 6 | "build:sdk-storefront": "npm run build --workspace=@spree/storefront-api-v2-sdk", 7 | "build:sdk-platform": "npm run build --workspace=@spree/platform-api-v2-sdk", 8 | "build:sdk-axios-fetcher": "npm run build --workspace=@spree/axios-fetcher", 9 | "build:sdk-node-fetcher": "npm run build --workspace=@spree/node-fetcher", 10 | "build": "npm run build:sdk-core && npm run build:sdk-storefront && npm run build:sdk-platform && npm run build:sdk-axios-fetcher && npm run build:sdk-node-fetcher", 11 | "pack:sdk-storefront": "npm pack --workspace=@spree/storefront-api-v2-sdk --pack-destination=packages/sdk-storefront", 12 | "pack:sdk-axios-fetcher": "npm pack --workspace=@spree/axios-fetcher --pack-destination=packages/sdk-fetcher-axios", 13 | "pack:sdk-node-fetcher": "npm pack --workspace=@spree/node-fetcher --pack-destination=packages/sdk-fetcher-node", 14 | "pack": "npm run pack:sdk-storefront && npm run pack:sdk-axios-fetcher && npm run pack:sdk-node-fetcher", 15 | "lint": "eslint --ext .ts .", 16 | "test": "./test.sh", 17 | "docs": "typedoc" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/spark-solutions/spree-storefront-api-v2-js-sdk.git" 22 | }, 23 | "author": "Spark Solutions (https://sparksolutions.co)", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/spark-solutions/spree-storefront-api-v2-js-sdk/issues" 27 | }, 28 | "homepage": "https://guides.spreecommerce.org/api/v2", 29 | "sideEffects": false, 30 | "workspaces": [ 31 | "packages/sdk-core", 32 | "packages/sdk-storefront", 33 | "packages/sdk-platform", 34 | "packages/sdk-fetcher-axios", 35 | "packages/sdk-fetcher-node" 36 | ], 37 | "dependencies": { 38 | "npm": "^8.19.2" 39 | }, 40 | "devDependencies": { 41 | "typedoc": "^0.23.16", 42 | "@knodes/typedoc-plugin-pages": "^0.23.1" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/sdk-core/README.md: -------------------------------------------------------------------------------- 1 | Spree Storefront API SDK contains each endpoint according to [Spree Guides](https://api.spreecommerce.org/docs/api-v2/c230c08afa8e4-storefront-api). -------------------------------------------------------------------------------- /packages/sdk-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@spree/core-api-v2-sdk", 3 | "version": "1.0.2", 4 | "private": true, 5 | "description": "Core SDK package containing the HTTP client, helper functions, typescript interfaces and more.", 6 | "engines": { 7 | "node": ">=14.17.0" 8 | }, 9 | "main": "dist/index.js", 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "prepare": "npm run build", 13 | "build": "webpack", 14 | "watch": "webpack --watch", 15 | "lint": "eslint --ext .ts .", 16 | "lint:fix": "eslint src/**/*.ts --fix" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/spark-solutions/spree-storefront-api-v2-js-sdk.git" 21 | }, 22 | "author": "Spark Solutions (https://sparksolutions.co)", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/spark-solutions/spree-storefront-api-v2-js-sdk/issues" 26 | }, 27 | "homepage": "https://guides.spreecommerce.org/api/v2", 28 | "devDependencies": { 29 | "@types/node": "^14.17.11", 30 | "@typescript-eslint/eslint-plugin": "^5.5.0", 31 | "@typescript-eslint/parser": "^5.5.0", 32 | "del": "^6.0.0", 33 | "eslint": "^7.32.0", 34 | "eslint-config-prettier": "^8.3.0", 35 | "eslint-plugin-import": "^2.24.1", 36 | "prettier": "^2.3.2", 37 | "progress-bar-webpack-plugin": "^2.1.0", 38 | "source-map-loader": "^2.0.2", 39 | "ts-loader": "^8.3.0", 40 | "typescript": "^4.5.2", 41 | "webpack": "^5.76.0", 42 | "webpack-cli": "^4.9.1", 43 | "webpack-node-externals": "^3.0.0" 44 | }, 45 | "sideEffects": false 46 | } 47 | -------------------------------------------------------------------------------- /packages/sdk-core/src/Client.ts: -------------------------------------------------------------------------------- 1 | import type { CreateFetcherConfig, Fetcher, IClientConfig } from './interfaces/ClientConfig' 2 | 3 | interface IEndpoints { 4 | [key: string]: any 5 | } 6 | 7 | class Client { 8 | protected host: string 9 | protected fetcher: Fetcher 10 | 11 | constructor(customOptions: IClientConfig, endpoints: IEndpoints) { 12 | const spreeHostEnvironmentValue: string | null = (globalThis.process && globalThis.process.env.SPREE_HOST) || null 13 | 14 | const defaultOptions: Partial = { 15 | host: spreeHostEnvironmentValue || 'http://localhost:3000/' 16 | } 17 | 18 | const options: IClientConfig = { 19 | ...defaultOptions, 20 | ...customOptions 21 | } 22 | 23 | const fetcherOptions: CreateFetcherConfig = { host: options.host } 24 | 25 | this.fetcher = options.createFetcher(fetcherOptions) 26 | 27 | for (const endpoint in endpoints) { 28 | this[endpoint] = new endpoints[endpoint]({ fetcher: this.fetcher }) 29 | } 30 | } 31 | } 32 | 33 | export default Client 34 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/BasicSpreeError.ts: -------------------------------------------------------------------------------- 1 | import type { RawFetchResponse } from '../interfaces/RawFetchResponse' 2 | import SpreeError from './SpreeError' 3 | 4 | class BasicSpreeError extends SpreeError { 5 | public summary: string 6 | 7 | constructor(serverResponse: RawFetchResponse, errorsSummary: string) { 8 | super(serverResponse) 9 | Object.setPrototypeOf(this, BasicSpreeError.prototype) 10 | this.name = 'BasicSpreeError' 11 | this.summary = errorsSummary 12 | } 13 | } 14 | 15 | export default BasicSpreeError 16 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/CastError.ts: -------------------------------------------------------------------------------- 1 | import SpreeSDKError from './SpreeSDKError' 2 | 3 | export default class CastError extends SpreeSDKError { 4 | constructor(message: string) { 5 | super(message) 6 | Object.setPrototypeOf(this, CastError.prototype) 7 | this.name = 'CastError' 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/DeserializeError.ts: -------------------------------------------------------------------------------- 1 | import SpreeSDKError from './SpreeSDKError' 2 | 3 | export default class DeserializeError extends SpreeSDKError { 4 | constructor(message: string) { 5 | super(message) 6 | Object.setPrototypeOf(this, DeserializeError.prototype) 7 | this.name = 'DeserializeError' 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/DocumentRelationshipError.ts: -------------------------------------------------------------------------------- 1 | import SpreeSDKError from './SpreeSDKError' 2 | 3 | export default class DocumentRelationshipError extends SpreeSDKError { 4 | constructor(message: string) { 5 | super(message) 6 | Object.setPrototypeOf(this, DocumentRelationshipError.prototype) 7 | this.name = 'DocumentRelationshipError' 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/ExpandedSpreeError.ts: -------------------------------------------------------------------------------- 1 | import { Errors, FieldErrors } from '../interfaces/Errors' 2 | import type { RawFetchResponse } from '../interfaces/RawFetchResponse' 3 | import BasicSpreeError from './BasicSpreeError' 4 | 5 | export default class ExpandedSpreeError extends BasicSpreeError { 6 | public errors: Errors 7 | 8 | constructor(serverResponse: RawFetchResponse, errorsSummary: string, errors: { [fieldPath: string]: FieldErrors }) { 9 | super(serverResponse, errorsSummary) 10 | Object.setPrototypeOf(this, ExpandedSpreeError.prototype) 11 | this.name = 'ExpandedSpreeError' 12 | this.errors = Object.keys(errors).reduce((acc, fieldPath) => { 13 | const keys = fieldPath.split('.') 14 | let key = keys.shift() 15 | let node = acc 16 | 17 | while (key) { 18 | if (!node[key]) { 19 | if (keys.length === 0) { 20 | node[key] = errors[fieldPath] 21 | } else { 22 | node[key] = {} 23 | } 24 | } 25 | 26 | node = node[key] 27 | key = keys.shift() 28 | } 29 | 30 | return acc 31 | }, {}) 32 | } 33 | 34 | /** 35 | * @deprecated This method will be removed in future versions. 36 | * Use optional chaining, lodash/get, Final Form's getIn or another 37 | * 3rd party library to recreate the behavior of this method. 38 | */ 39 | public getErrors(path: string[]): Errors | FieldErrors | null { 40 | let pathPartIndex = 0 41 | let node: any = this.errors 42 | let pathPossible = true 43 | 44 | while (pathPartIndex < path.length && pathPossible) { 45 | const pathPart = path[pathPartIndex] 46 | 47 | if (!(pathPart in Object(node))) { 48 | pathPossible = false 49 | } else { 50 | node = node[pathPart] 51 | pathPartIndex += 1 52 | } 53 | } 54 | 55 | if (!pathPossible) { 56 | return null 57 | } 58 | 59 | return node 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/FetchError.ts: -------------------------------------------------------------------------------- 1 | import type { RawFetchRequest } from '../interfaces/RawFetchRequest' 2 | import type { RawFetchResponse } from '../interfaces/RawFetchResponse' 3 | import SpreeSDKError from './SpreeSDKError' 4 | 5 | export default class FetchError extends SpreeSDKError { 6 | public response?: RawFetchResponse 7 | public request?: RawFetchRequest 8 | public data?: any 9 | 10 | constructor(response?: RawFetchResponse, request?: unknown, data?: unknown, message?: string) { 11 | super(message) 12 | Object.setPrototypeOf(this, FetchError.prototype) 13 | this.name = 'FetchError' 14 | this.response = response 15 | this.request = request 16 | this.data = data 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/MisconfigurationError.ts: -------------------------------------------------------------------------------- 1 | import SpreeSDKError from './SpreeSDKError' 2 | 3 | export default class MisconfigurationError extends SpreeSDKError { 4 | constructor(message: string) { 5 | super(`Incorrect request setup: ${message}`) 6 | Object.setPrototypeOf(this, MisconfigurationError.prototype) 7 | this.name = 'MisconfigurationError' 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/NoResponseError.ts: -------------------------------------------------------------------------------- 1 | import SpreeSDKError from './SpreeSDKError' 2 | 3 | export default class NoResponseError extends SpreeSDKError { 4 | constructor() { 5 | super('No response received from Spree') 6 | Object.setPrototypeOf(this, NoResponseError.prototype) 7 | this.name = 'NoResponseError' 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/SpreeError.ts: -------------------------------------------------------------------------------- 1 | import type { RawFetchResponse } from '../interfaces/RawFetchResponse' 2 | import SpreeSDKError from './SpreeSDKError' 3 | 4 | export default class SpreeError extends SpreeSDKError { 5 | public serverResponse: RawFetchResponse 6 | 7 | constructor(serverResponse: RawFetchResponse) { 8 | super(`Spree returned a HTTP ${serverResponse.status} error code`) 9 | Object.setPrototypeOf(this, SpreeError.prototype) 10 | this.name = 'SpreeError' 11 | this.serverResponse = serverResponse 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/SpreeSDKError.ts: -------------------------------------------------------------------------------- 1 | export default class SpreeSDKError extends Error { 2 | constructor(message: string) { 3 | super(message) 4 | Object.setPrototypeOf(this, SpreeSDKError.prototype) 5 | this.name = 'SpreeSDKError' 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/sdk-core/src/errors/index.ts: -------------------------------------------------------------------------------- 1 | import BasicSpreeError from './BasicSpreeError' 2 | import ExpandedSpreeError from './ExpandedSpreeError' 3 | import MisconfigurationError from './MisconfigurationError' 4 | import NoResponseError from './NoResponseError' 5 | import SpreeError from './SpreeError' 6 | import SpreeSDKError from './SpreeSDKError' 7 | import FetchError from './FetchError' 8 | import DocumentRelationshipError from './DocumentRelationshipError' 9 | 10 | export { 11 | BasicSpreeError, 12 | ExpandedSpreeError, 13 | MisconfigurationError, 14 | NoResponseError, 15 | SpreeError, 16 | SpreeSDKError, 17 | FetchError, 18 | DocumentRelationshipError 19 | } 20 | -------------------------------------------------------------------------------- /packages/sdk-core/src/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './jsonApi' 2 | export * from './request' 3 | export * from './result' 4 | export * from './squashAndPreparePositionalArguments' -------------------------------------------------------------------------------- /packages/sdk-core/src/helpers/jsonApi.ts: -------------------------------------------------------------------------------- 1 | import type { JsonApiDocument, JsonApiResponse } from '../interfaces/JsonApi' 2 | import type { RelationType } from '../interfaces/Relationships' 3 | import { DocumentRelationshipError } from '../errors' 4 | 5 | const findDocument = ( 6 | spreeSuccessResponse: JsonApiResponse, 7 | relationType: RelationType 8 | ): DocumentType | null => { 9 | if (!spreeSuccessResponse.included) { 10 | return null 11 | } 12 | 13 | return ( 14 | (spreeSuccessResponse.included.find( 15 | (includedObject) => includedObject.type === relationType.type && includedObject.id === relationType.id 16 | ) as DocumentType) || null 17 | ) 18 | } 19 | 20 | const findRelationshipDocuments = ( 21 | spreeSuccessResponse: JsonApiResponse, 22 | sourceDocument: JsonApiDocument, 23 | relationshipName: string 24 | ): DocumentType[] => { 25 | if (!spreeSuccessResponse.included) { 26 | return [] 27 | } 28 | 29 | const oneOrManyDocumentReferences = (sourceDocument.relationships[relationshipName] || {}).data 30 | 31 | if (!oneOrManyDocumentReferences) { 32 | throw new DocumentRelationshipError(`Incorrect relationship ${relationshipName}.`) 33 | } 34 | 35 | let documentReferences: RelationType[] 36 | 37 | if (Array.isArray(oneOrManyDocumentReferences)) { 38 | documentReferences = oneOrManyDocumentReferences 39 | } else { 40 | documentReferences = [oneOrManyDocumentReferences] 41 | } 42 | 43 | return documentReferences 44 | .map((relationType: RelationType) => findDocument(spreeSuccessResponse, relationType)) 45 | .filter(Boolean) 46 | } 47 | 48 | const findSingleRelationshipDocument = ( 49 | spreeSuccessResponse: JsonApiResponse, 50 | sourceDocument: JsonApiDocument, 51 | relationshipName: string 52 | ): DocumentType | null => { 53 | const documents = findRelationshipDocuments(spreeSuccessResponse, sourceDocument, relationshipName) 54 | 55 | if (documents.length === 0) { 56 | return null 57 | } 58 | 59 | return documents[0] 60 | } 61 | 62 | export { findDocument, findRelationshipDocuments, findSingleRelationshipDocument } 63 | -------------------------------------------------------------------------------- /packages/sdk-core/src/index.ts: -------------------------------------------------------------------------------- 1 | import Client from './Client' 2 | import Http from './Http' 3 | 4 | export * from './errors' 5 | export * from './helpers' 6 | 7 | export type { 8 | Fetcher, 9 | CreateFetcher, 10 | CreateFetcherConfig, 11 | FetcherConfig, 12 | IClientConfig, 13 | CreateFetchFetcherConfig, 14 | CreateCustomizedFetchFetcher, 15 | DeepAnyObject, 16 | EmptyObjectResponse, 17 | EmptyObjectResult, 18 | FieldErrors, 19 | Errors, 20 | ErrorType, 21 | HttpMethod, 22 | AutomaticResponseParsing, 23 | ResponseParsing, 24 | FetchConfig, 25 | ImageTransformation, 26 | JsonApiDocument, 27 | JsonApiResponse, 28 | JsonApiListResponse, 29 | JsonApiSingleResponse, 30 | LocalizedSlugs, 31 | NoContentResponse, 32 | NoContentResult, 33 | IQuery, 34 | IProductsQuery, 35 | RawFetchRequest, 36 | RawFetchResponse, 37 | RelationType, 38 | IRelationships, 39 | Result, 40 | ResultResponse, 41 | IToken, 42 | RequiredAnyToken, 43 | OptionalAnyToken, 44 | RequiredAccountToken, 45 | OptionalAccountToken, 46 | IOAuthToken, 47 | IOAuthTokenResult, 48 | IPlatformToken, 49 | IPlatformTokenResult, 50 | IPlatformUserToken, 51 | IPlatformUserTokenResult, 52 | AllowedCustomizations, 53 | DefaultCustomizations, 54 | WithCommonOptions 55 | } from './interfaces' 56 | 57 | export { 58 | Client, 59 | Http 60 | } 61 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/ClientConfig.ts: -------------------------------------------------------------------------------- 1 | import type { FetchConfig } from './FetchConfig' 2 | 3 | export type Fetcher = { 4 | fetch: (options: FetchConfig) => Promise<{ data: any }> 5 | } 6 | 7 | export type CreateFetcher = (options: CreateFetcherConfig) => Fetcher 8 | 9 | export type CreateFetcherConfig = { 10 | host: string 11 | } 12 | 13 | export type FetcherConfig = { 14 | createFetcher: CreateFetcher 15 | } 16 | 17 | export type IClientConfig = CreateFetcherConfig & FetcherConfig 18 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/CreateCustomizedFetchFetcher.ts: -------------------------------------------------------------------------------- 1 | import type { CreateFetcherConfig, Fetcher } from './ClientConfig' 2 | 3 | // CreateFetchFetcherConfig allows any type for fetch and requestConstructor. 4 | // This is done to allow fetch implementations not covering the complete, browser-side fetch interface. 5 | // For example, node-fetch doesn't allow some browser-side configuration which would be 6 | // ignored server-side anyway. 7 | export type CreateFetchFetcherConfig = CreateFetcherConfig & { 8 | fetch: typeof globalThis.fetch | any 9 | requestConstructor: typeof globalThis.Request | any 10 | } 11 | 12 | export type CreateCustomizedFetchFetcher = (options: CreateFetchFetcherConfig) => Fetcher 13 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/DeepAnyObject.ts: -------------------------------------------------------------------------------- 1 | // Based on https://github.com/piotrwitek/utility-types/blob/df2502ef504c4ba8bd9de81a45baef112b7921d0/src/mapped-types.ts#L504 2 | export type DeepAnyObject = T extends (...args: any[]) => any 3 | ? T 4 | : T extends Array 5 | ? _DeepAnyObjectArray 6 | : T extends object 7 | ? _DeepAnyObjectObject 8 | : T | undefined 9 | 10 | interface _DeepAnyObjectArray extends Array> {} 11 | 12 | type _DeepAnyObjectObject = { [P in keyof T]: DeepAnyObject } & Record 13 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/EmptyObject.ts: -------------------------------------------------------------------------------- 1 | import { ResultResponse } from './ResultResponse' 2 | 3 | export type EmptyObjectResponse = Record 4 | 5 | export interface EmptyObjectResult extends ResultResponse {} 6 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/ErrorClass.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @deprecated Use {@link ErrorType} instead. 3 | */ 4 | export enum ErrorClass { 5 | BASIC, 6 | FULL, 7 | LIMITED 8 | } 9 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/ErrorType.ts: -------------------------------------------------------------------------------- 1 | export type ErrorType = 'basic' | 'full' | 'limited' 2 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/Errors.ts: -------------------------------------------------------------------------------- 1 | export type FieldErrors = unknown[] 2 | 3 | export interface Errors { 4 | [key: string]: Errors | FieldErrors 5 | } 6 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/FetchConfig.ts: -------------------------------------------------------------------------------- 1 | export type HttpMethod = 2 | | 'get' 3 | | 'GET' 4 | | 'delete' 5 | | 'DELETE' 6 | | 'head' 7 | | 'HEAD' 8 | | 'options' 9 | | 'OPTIONS' 10 | | 'post' 11 | | 'POST' 12 | | 'put' 13 | | 'PUT' 14 | | 'patch' 15 | | 'PATCH' 16 | | 'purge' 17 | | 'PURGE' 18 | | 'link' 19 | | 'LINK' 20 | | 'unlink' 21 | | 'UNLINK' 22 | 23 | /** 24 | * @deprecated Automatic parsing will be removed in the future to ensure the same behavior of different Fetchers. 25 | */ 26 | export type AutomaticResponseParsing = 'automatic' 27 | 28 | export type ResponseParsing = AutomaticResponseParsing | 'text' | 'json' | 'stream' 29 | 30 | export type FetchConfig = { 31 | url: string 32 | params: { [key: string]: any } 33 | method: HttpMethod 34 | headers: { [key: string]: string } 35 | responseParsing: ResponseParsing 36 | } 37 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/ImageTransformation.ts: -------------------------------------------------------------------------------- 1 | export type ImageTransformation = { 2 | size?: string 3 | quality?: number 4 | } 5 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/JsonApi.ts: -------------------------------------------------------------------------------- 1 | export interface JsonApiDocument { 2 | id: string 3 | type: string 4 | attributes: any 5 | relationships: any 6 | } 7 | export interface JsonApiResponse { 8 | data: JsonApiDocument | JsonApiDocument[] 9 | included?: JsonApiDocument[] 10 | } 11 | export interface JsonApiListResponse extends JsonApiResponse { 12 | data: JsonApiDocument[] 13 | meta?: { 14 | total_pages: number 15 | total_count: number 16 | count: number 17 | } 18 | } 19 | export interface JsonApiSingleResponse extends JsonApiResponse { 20 | data: JsonApiDocument 21 | } 22 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/LocalizedSlugs.ts: -------------------------------------------------------------------------------- 1 | export interface LocalizedSlugs { 2 | [key: string]: string 3 | } 4 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/NoContent.ts: -------------------------------------------------------------------------------- 1 | import { ResultResponse } from './ResultResponse' 2 | 3 | export type NoContentResponse = '' 4 | 5 | export interface NoContentResult extends ResultResponse {} 6 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/Query.ts: -------------------------------------------------------------------------------- 1 | export interface IQuery { 2 | currency?: string 3 | locale?: string 4 | include?: string 5 | fields?: { 6 | [key: string]: string 7 | } 8 | filter?: { 9 | [key: string]: number | string 10 | } 11 | page?: number 12 | per_page?: number 13 | sort?: string 14 | [customSpreeExtensionKey: string]: any 15 | } 16 | 17 | /** 18 | * @deprecated Use {@link ListOptions} instead. 19 | */ 20 | export interface IProductsQuery extends IQuery { 21 | image_transformation?: { 22 | size?: string 23 | quality?: number 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/RawFetchRequest.ts: -------------------------------------------------------------------------------- 1 | export type RawFetchRequest = Request | any 2 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/RawFetchResponse.ts: -------------------------------------------------------------------------------- 1 | import type { AxiosResponse } from 'axios' 2 | 3 | export type RawFetchResponse = AxiosResponse | Response | any 4 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/Relationships.ts: -------------------------------------------------------------------------------- 1 | export interface RelationType { 2 | id: string 3 | type: string 4 | } 5 | 6 | export interface IRelationships { 7 | [key: string]: { 8 | data: RelationType | RelationType[] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/Result.ts: -------------------------------------------------------------------------------- 1 | export interface Result { 2 | isSuccess(): boolean 3 | isFail(): boolean 4 | success(): S 5 | fail(): F 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/ResultResponse.ts: -------------------------------------------------------------------------------- 1 | import type { SpreeSDKError } from '../errors' 2 | import type { Result } from './Result' 3 | 4 | export interface ResultResponse extends Result {} 5 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/Token.ts: -------------------------------------------------------------------------------- 1 | import { ResultResponse } from './ResultResponse' 2 | 3 | /** 4 | * @deprecated Use 5 | * {@link RequiredAnyToken}, 6 | * {@link OptionalAnyToken}, 7 | * {@link RequiredAccountToken}, 8 | * {@link OptionalAccountToken} or 9 | * {@link WithCommonOptions} specific to the endpoint you're attempting to call 10 | * instead. 11 | */ 12 | export interface IToken { 13 | orderToken?: string 14 | bearerToken?: string 15 | } 16 | 17 | export type RequiredAnyToken = 18 | | { order_token: string; bearer_token?: never } 19 | | { order_token?: never; bearer_token: string } 20 | 21 | export type OptionalAnyToken = 22 | | { order_token?: string; bearer_token?: never } 23 | | { order_token?: never; bearer_token?: string } 24 | 25 | export type RequiredAccountToken = { bearer_token: string } 26 | 27 | export type OptionalAccountToken = { bearer_token?: string } 28 | 29 | export interface IOAuthToken { 30 | access_token: string 31 | token_type: 'Bearer' 32 | expires_in: number 33 | refresh_token: string 34 | created_at: number 35 | } 36 | 37 | export interface IPlatformToken { 38 | access_token: string 39 | token_type: 'Bearer' 40 | expires_in: number 41 | scope: string 42 | created_at: number 43 | } 44 | 45 | export interface IPlatformUserToken extends IPlatformToken { 46 | refresh_token: string 47 | } 48 | 49 | export interface IOAuthTokenResult extends ResultResponse {} 50 | 51 | export interface IPlatformTokenResult extends ResultResponse {} 52 | 53 | export interface IPlatformUserTokenResult extends ResultResponse {} 54 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/WithCommonOptions.ts: -------------------------------------------------------------------------------- 1 | import type { DeepAnyObject } from './DeepAnyObject' 2 | import type { IQuery } from './Query' 3 | import type { OptionalAccountToken, OptionalAnyToken, RequiredAccountToken, RequiredAnyToken } from './Token' 4 | 5 | export type AllowedCustomizations = { 6 | suggestToken: boolean 7 | suggestQuery: boolean 8 | optionalToken: boolean 9 | onlyAccountToken: boolean 10 | } 11 | 12 | export type DefaultCustomizations = AllowedCustomizations & { 13 | suggestToken: false 14 | suggestQuery: false 15 | optionalToken: false 16 | onlyAccountToken: false 17 | } 18 | 19 | export type WithCommonOptions< 20 | CustomizationsOrNull extends Partial | null = Partial | null, 21 | CustomOptions extends Record = Record, 22 | Customizations extends CustomizationsOrNull extends null 23 | ? Record 24 | : CustomizationsOrNull = CustomizationsOrNull extends null ? Record : CustomizationsOrNull, 25 | IntersectedCustomizations extends Customizations & DefaultCustomizations = Customizations & DefaultCustomizations, 26 | FinalCustomizations extends { 27 | [P in keyof AllowedCustomizations]: IntersectedCustomizations[P] extends never 28 | ? Customizations[P] 29 | : DefaultCustomizations[P] 30 | } = { 31 | [P in keyof AllowedCustomizations]: IntersectedCustomizations[P] extends never 32 | ? Customizations[P] 33 | : DefaultCustomizations[P] 34 | } 35 | > = DeepAnyObject< 36 | ((FinalCustomizations['suggestToken'] extends true 37 | ? FinalCustomizations['onlyAccountToken'] extends true 38 | ? FinalCustomizations['optionalToken'] extends true 39 | ? OptionalAccountToken 40 | : RequiredAccountToken 41 | : FinalCustomizations['optionalToken'] extends true 42 | ? OptionalAnyToken 43 | : RequiredAnyToken 44 | : Record) & 45 | (FinalCustomizations['suggestQuery'] extends true ? IQuery : Record)) & 46 | CustomOptions 47 | > 48 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/globals.d.ts: -------------------------------------------------------------------------------- 1 | declare const RUNTIME_TYPE: 'browser' | 'node' 2 | -------------------------------------------------------------------------------- /packages/sdk-core/src/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ClientConfig' 2 | export * from './CreateCustomizedFetchFetcher' 3 | export * from './DeepAnyObject' 4 | export * from './EmptyObject' 5 | export * from './ErrorClass' 6 | export * from './Errors' 7 | export * from './ErrorType' 8 | export * from './FetchConfig' 9 | export * from './ImageTransformation' 10 | export * from './JsonApi' 11 | export * from './LocalizedSlugs' 12 | export * from './NoContent' 13 | export * from './Query' 14 | export * from './RawFetchRequest' 15 | export * from './RawFetchResponse' 16 | export * from './Relationships' 17 | export * from './Result' 18 | export * from './ResultResponse' 19 | export * from './Token' 20 | export * from './WithCommonOptions' 21 | -------------------------------------------------------------------------------- /packages/sdk-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "lib": ["dom", "es2016"], 5 | "moduleResolution": "node", 6 | "noUnusedParameters": true, 7 | "sourceMap": true, 8 | "allowSyntheticDefaultImports": true, 9 | "module": "commonjs", 10 | "esModuleInterop": true, 11 | "declaration": true, 12 | "declarationDir": "./types", 13 | "importsNotUsedAsValues": "preserve", 14 | "composite": true, 15 | "rootDir": "src" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/sdk-core/webpack.config.mjs: -------------------------------------------------------------------------------- 1 | import webpack from 'webpack' 2 | import { resolve, dirname } from 'path' 3 | import { fileURLToPath } from 'url' 4 | import nodeExternals from 'webpack-node-externals' 5 | import ProgressBar from './../../webpack-plugins/ProgressBar.mjs' 6 | import DeleteBeforeRun from './../../webpack-plugins/DeleteBeforeRun.mjs' 7 | 8 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 9 | const __dirname = dirname(fileURLToPath(import.meta.url)) 10 | const baseDirectoryPath = __dirname 11 | const srcDirectoryPath = resolve(baseDirectoryPath, 'src') 12 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 13 | const { WatchIgnorePlugin } = webpack 14 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig.json') 15 | 16 | export default { 17 | context: baseDirectoryPath, 18 | plugins: [ 19 | new ProgressBar(), 20 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'dist')), 21 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'types')), 22 | new WatchIgnorePlugin({ paths: [resolve(baseDirectoryPath, 'types')] }), 23 | ], 24 | entry: { 25 | index: { 26 | import: resolve(srcDirectoryPath, 'index.ts'), 27 | library: { 28 | name: 'SpreeSDKCore', 29 | type: 'umd' 30 | } 31 | }, 32 | }, 33 | output: { 34 | filename: '[name].js', 35 | path: distDirectoryPath, 36 | globalObject: 'this' 37 | }, 38 | mode: 'production', 39 | devtool: 'source-map', 40 | module: { 41 | rules: [ 42 | { 43 | test: /\.tsx?$/, 44 | loader: 'ts-loader', 45 | exclude: /node_modules/, 46 | include: srcDirectoryPath, 47 | options: { 48 | configFile: typeScriptConfigFilePath, 49 | onlyCompileBundledFiles: true 50 | } 51 | }, 52 | { 53 | test: /\.js$/, 54 | loader: 'source-map-loader', 55 | include: /node_modules/, 56 | enforce: 'pre' 57 | } 58 | ] 59 | }, 60 | resolveLoader: { 61 | modules: [srcDirectoryPath, 'node_modules'] 62 | }, 63 | resolve: { 64 | symlinks: false, 65 | extensions: ['.tsx', '.ts', '.js'] 66 | }, 67 | externals: [ 68 | nodeExternals({ 69 | modulesFromFile: { 70 | excludeFromBundle: ['devDependencies'], 71 | includeInBundle: ['dependencies'] 72 | } 73 | }) 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/README.md: -------------------------------------------------------------------------------- 1 | **Spree SDK in NodeJS using Axios** 2 | 3 | To use Spree SDK with Axios in NodeJS, install Axios along with the fetcher using NPM: 4 | 5 | ``` 6 | npm install @spree/axios-fetcher axios 7 | ``` 8 | 9 | Set the fetcher to axios when creating the Spree SDK client: 10 | 11 | ```js 12 | const createAxiosFetcher = require('@spree/axios-fetcher/dist/server/index').default 13 | const { makeClient } = require('@spree/storefront-api-v2-sdk') 14 | const client = makeClient({ 15 | host: 'http://localhost:3000', 16 | createFetcher: createAxiosFetcher 17 | }) 18 | ``` 19 | 20 | **Spree SDK in the browser using Axios** 21 | 22 | To use Spree SDK with Axios in the browser, include axios as a ` 26 | 27 | 28 | 29 | 35 | ``` 36 | 37 | Spree SDK will automatically detect that Axios is available and use it to make requests to Spree. -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/globals.d.ts: -------------------------------------------------------------------------------- 1 | declare const RUNTIME_TYPE: 'browser' | 'node' -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@spree/axios-fetcher", 3 | "version": "1.0.0", 4 | "description": "Axios fetcher for Spree api SDK.", 5 | "main": "dist/server/index.js", 6 | "export": { 7 | "./server/*": "./dist/server/*.js", 8 | "./client/*": "./dist/client/*.js" 9 | }, 10 | "typesVersions": { 11 | "*": { 12 | "dist/server/index": [ 13 | "types/index.d.ts" 14 | ] 15 | } 16 | }, 17 | "scripts": { 18 | "build": "webpack", 19 | "build:server": "webpack --config-name server", 20 | "build:client": "webpack --config-name client", 21 | "watch": "webpack --watch", 22 | "watch:server": "webpack --watch --config-name server", 23 | "watch:client": "webpack --watch --config-name client", 24 | "lint": "eslint --ext .ts .", 25 | "lint:fix": "eslint src/**/*.ts --fix" 26 | }, 27 | "sideEffects": false, 28 | "peerDependencies": { 29 | "axios": "^0.25.0" 30 | }, 31 | "typedoc": { 32 | "entryPoint": "./src/index.ts" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/tsconfig-client.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es6" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/tsconfig-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es2020" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "node", 4 | "noUnusedParameters": true, 5 | "sourceMap": true, 6 | "allowSyntheticDefaultImports": true, 7 | "module": "commonjs", 8 | "esModuleInterop": true, 9 | "declaration": true, 10 | "declarationDir": "./types", 11 | "importsNotUsedAsValues": "preserve" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/webpack.client.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const clientDistDirectoryPath = resolve(distDirectoryPath, 'client') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'client', 16 | target: ['web', 'es6'], 17 | output: { 18 | path: clientDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'browser'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-client.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/webpack.common.maker.mjs: -------------------------------------------------------------------------------- 1 | import webpack from 'webpack' 2 | import { resolve, dirname } from 'path' 3 | import { fileURLToPath } from 'url' 4 | import nodeExternals from 'webpack-node-externals' 5 | import ProgressBar from './../../webpack-plugins/ProgressBar.mjs' 6 | import DeleteBeforeRun from './../../webpack-plugins/DeleteBeforeRun.mjs' 7 | 8 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 9 | const __dirname = dirname(fileURLToPath(import.meta.url)) 10 | const baseDirectoryPath = __dirname 11 | const srcDirectoryPath = resolve(baseDirectoryPath, 'src') 12 | const { WatchIgnorePlugin } = webpack 13 | 14 | export default ({ typeScriptConfigFilePath }) => ({ 15 | context: baseDirectoryPath, 16 | plugins: [ 17 | new ProgressBar(), 18 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'types')), 19 | new WatchIgnorePlugin({ paths: [resolve(baseDirectoryPath, 'types')] }) 20 | ], 21 | entry: { 22 | index: { 23 | import: resolve(srcDirectoryPath, 'index.ts'), 24 | library: { 25 | name: ['SpreeSDK', 'createAxiosFetcher'], 26 | type: 'umd' 27 | } 28 | } 29 | }, 30 | output: { 31 | filename: '[name].js' 32 | }, 33 | mode: 'production', 34 | devtool: 'source-map', 35 | module: { 36 | rules: [ 37 | { 38 | test: /\.tsx?$/, 39 | loader: 'ts-loader', 40 | exclude: /node_modules/, 41 | include: srcDirectoryPath, 42 | options: { 43 | configFile: typeScriptConfigFilePath, 44 | onlyCompileBundledFiles: true 45 | } 46 | }, 47 | { 48 | test: /\.js$/, 49 | loader: 'source-map-loader', 50 | include: /node_modules/, 51 | enforce: 'pre' 52 | } 53 | ] 54 | }, 55 | resolveLoader: { 56 | modules: [srcDirectoryPath, 'node_modules'] 57 | }, 58 | resolve: { 59 | symlinks: false, 60 | extensions: ['.tsx', '.ts', '.js'] 61 | }, 62 | externals: [nodeExternals({ modulesFromFile: true })] 63 | }) 64 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/webpack.config.mjs: -------------------------------------------------------------------------------- 1 | import serverConfig from './webpack.server.mjs' 2 | import clientConfig from './webpack.client.mjs' 3 | 4 | export default [serverConfig, clientConfig] 5 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-axios/webpack.server.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const serverDistDirectoryPath = resolve(distDirectoryPath, 'server') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'server', 16 | target: 'node14', 17 | output: { 18 | path: serverDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'node'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-server.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/README.md: -------------------------------------------------------------------------------- 1 | **Spree SDK in NodeJS using fetch** 2 | 3 | To use Spree SDK with [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) in NodeJS, install Node Fetch along with the fetcher using NPM: 4 | 5 | ``` 6 | npm install @spree/node-fetcher node-fetch 7 | ``` 8 | 9 | Set the fetcher to fetch: 10 | 11 | ```js 12 | const createFetchFetcher = require('@spree/node-fetcher/dist/server/index').default 13 | const { makeClient } = require('@spree/storefront-api-v2-sdk') 14 | const client = makeClient({ 15 | host: 'http://localhost:3000', 16 | createFetcher: createFetchFetcher 17 | }) 18 | ``` 19 | 20 | **Spree SDK in the browser using fetch** 21 | 22 | Modern web browsers include fetch natively. To use Spree SDK with native fetch, it's enough to set `fetcherType` to `'fetch'` when creating the Spree SDK Client: 23 | 24 | ```html 25 | 26 | 27 | 28 | 34 | ``` -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/globals.d.ts: -------------------------------------------------------------------------------- 1 | declare const RUNTIME_TYPE: 'browser' | 'node' -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@spree/node-fetcher", 3 | "version": "1.0.0", 4 | "description": "Node fetch fetcher for Spree api SDK.", 5 | "main": "dist/server/index.js", 6 | "export": { 7 | "./server/*": "./dist/server/*.js", 8 | "./client/*": "./dist/client/*.js" 9 | }, 10 | "typesVersions": { 11 | "*": { 12 | "dist/server/index": [ 13 | "types/index.d.ts" 14 | ] 15 | } 16 | }, 17 | "scripts": { 18 | "build": "webpack", 19 | "build:server": "webpack --config-name server", 20 | "build:client": "webpack --config-name client", 21 | "watch": "webpack --watch", 22 | "watch:server": "webpack --watch --config-name server", 23 | "watch:client": "webpack --watch --config-name client", 24 | "lint": "eslint --ext .ts .", 25 | "lint:fix": "eslint src/**/*.ts --fix" 26 | }, 27 | "sideEffects": false, 28 | "peerDependencies": { 29 | "node-fetch": "^2.6.6" 30 | }, 31 | "typedoc": { 32 | "entryPoint": "./src/index.ts" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/tsconfig-client.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es6" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/tsconfig-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es2020" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "node", 4 | "noUnusedParameters": true, 5 | "sourceMap": true, 6 | "allowSyntheticDefaultImports": true, 7 | "module": "commonjs", 8 | "esModuleInterop": true, 9 | "declaration": true, 10 | "declarationDir": "./types", 11 | "importsNotUsedAsValues": "preserve" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/webpack.client.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const clientDistDirectoryPath = resolve(distDirectoryPath, 'client') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'client', 16 | target: ['web', 'es6'], 17 | output: { 18 | path: clientDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'browser'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-client.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/webpack.common.maker.mjs: -------------------------------------------------------------------------------- 1 | import webpack from 'webpack' 2 | import { resolve, dirname } from 'path' 3 | import { fileURLToPath } from 'url' 4 | import nodeExternals from 'webpack-node-externals' 5 | import ProgressBar from './../../webpack-plugins/ProgressBar.mjs' 6 | import DeleteBeforeRun from './../../webpack-plugins/DeleteBeforeRun.mjs' 7 | 8 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 9 | const __dirname = dirname(fileURLToPath(import.meta.url)) 10 | const baseDirectoryPath = __dirname 11 | const srcDirectoryPath = resolve(baseDirectoryPath, 'src') 12 | const { WatchIgnorePlugin } = webpack 13 | 14 | export default ({ typeScriptConfigFilePath }) => ({ 15 | context: baseDirectoryPath, 16 | plugins: [ 17 | new ProgressBar(), 18 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'types')), 19 | new WatchIgnorePlugin({ paths: [resolve(baseDirectoryPath, 'types')] }) 20 | ], 21 | entry: { 22 | index: { 23 | import: resolve(srcDirectoryPath, 'index.ts'), 24 | library: { 25 | name: ['SpreeSDK', 'createFetchFetcher'], 26 | type: 'umd' 27 | } 28 | } 29 | }, 30 | output: { 31 | filename: '[name].js' 32 | }, 33 | mode: 'production', 34 | devtool: 'source-map', 35 | module: { 36 | rules: [ 37 | { 38 | test: /\.tsx?$/, 39 | loader: 'ts-loader', 40 | exclude: /node_modules/, 41 | include: srcDirectoryPath, 42 | options: { 43 | configFile: typeScriptConfigFilePath, 44 | onlyCompileBundledFiles: true 45 | } 46 | }, 47 | { 48 | test: /\.js$/, 49 | loader: 'source-map-loader', 50 | include: /node_modules/, 51 | enforce: 'pre' 52 | } 53 | ] 54 | }, 55 | resolveLoader: { 56 | modules: [srcDirectoryPath, 'node_modules'] 57 | }, 58 | resolve: { 59 | symlinks: false, 60 | extensions: ['.tsx', '.ts', '.js'] 61 | }, 62 | externals: [nodeExternals({ modulesFromFile: true })] 63 | }) 64 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/webpack.config.mjs: -------------------------------------------------------------------------------- 1 | import serverConfig from './webpack.server.mjs' 2 | import clientConfig from './webpack.client.mjs' 3 | 4 | export default [serverConfig, clientConfig] 5 | -------------------------------------------------------------------------------- /packages/sdk-fetcher-node/webpack.server.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const serverDistDirectoryPath = resolve(distDirectoryPath, 'server') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'server', 16 | target: 'node14', 17 | output: { 18 | path: serverDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'node'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-server.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /packages/sdk-platform/README.md: -------------------------------------------------------------------------------- 1 | Spree Platform API SDK contains each endpoint according to [Spree Guides](https://api.spreecommerce.org/docs/api-v2/0e192836641aa-platform-api). -------------------------------------------------------------------------------- /packages/sdk-platform/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@spree/platform-api-v2-sdk", 3 | "version": "2.0.0", 4 | "description": "Node module to easily integrate your JavaScript or TypeScript application with Spree Platform API V2.", 5 | "engines": { 6 | "node": ">=14.17.0" 7 | }, 8 | "main": "./dist/server/index.js", 9 | "types": "./dist/index.d.ts", 10 | "typesVersions": { 11 | "*": { 12 | "dist/*": ["./dist/index.d.ts"] 13 | } 14 | }, 15 | "scripts": { 16 | "build": "webpack", 17 | "build:server": "webpack --config-name server", 18 | "build:client": "webpack --config-name client", 19 | "build:types": "rollup -c", 20 | "postbuild": "npm run build:types", 21 | "watch": "webpack --watch", 22 | "watch:server": "webpack --watch --config-name server", 23 | "watch:client": "webpack --watch --config-name client", 24 | "lint": "eslint --ext .ts .", 25 | "lint:fix": "eslint src/**/*.ts --fix" 26 | }, 27 | "repository": { 28 | "type": "git", 29 | "url": "git+https://github.com/spark-solutions/spree-storefront-api-v2-js-sdk.git" 30 | }, 31 | "author": "Spark Solutions (https://sparksolutions.co)", 32 | "license": "MIT", 33 | "bugs": { 34 | "url": "https://github.com/spark-solutions/spree-storefront-api-v2-js-sdk/issues" 35 | }, 36 | "homepage": "https://guides.spreecommerce.org/api/v2", 37 | "devDependencies": { 38 | "@spree/core-api-v2-sdk": "^1.0.2", 39 | "@types/node": "^14.17.11", 40 | "@typescript-eslint/eslint-plugin": "^5.5.0", 41 | "@typescript-eslint/parser": "^5.5.0", 42 | "axios": "^0.25.0", 43 | "del": "^6.0.0", 44 | "eslint": "^7.32.0", 45 | "eslint-config-prettier": "^8.3.0", 46 | "eslint-plugin-import": "^2.24.1", 47 | "node-fetch": "^2.6.7", 48 | "prettier": "^2.3.2", 49 | "progress-bar-webpack-plugin": "^2.1.0", 50 | "rollup": "^3.20.2", 51 | "rollup-plugin-dts": "^5.3.0", 52 | "source-map-loader": "^2.0.2", 53 | "ts-loader": "^8.3.0", 54 | "typescript": "^4.5.2", 55 | "webpack": "^5.76.0", 56 | "webpack-cli": "^4.9.1", 57 | "webpack-merge": "^5.8.0", 58 | "webpack-node-externals": "^3.0.0" 59 | }, 60 | "sideEffects": false, 61 | "peerDependencies": { 62 | "axios": "^0.25.0", 63 | "node-fetch": "^2.6.6" 64 | }, 65 | "peerDependenciesMeta": { 66 | "node-fetch": { 67 | "optional": true 68 | }, 69 | "axios": { 70 | "optional": true 71 | } 72 | }, 73 | "typedoc": { 74 | "entryPoint": "./src/endpoints/index.ts" 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /packages/sdk-platform/rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import dts from 'rollup-plugin-dts' 2 | 3 | export default { 4 | input: './types/index.d.ts', 5 | output: [{ file: 'dist/index.d.ts', format: 'es' }], 6 | plugins: [dts({ 7 | respectExternal: true 8 | })], 9 | } 10 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/endpoints/Countries.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Http, 3 | squashAndPreparePositionalArguments 4 | } from '@spree/core-api-v2-sdk' 5 | import type { 6 | ICountries, 7 | ICountriesResult, 8 | ICountry, 9 | ICountryResult, 10 | ListOptions, 11 | ShowOptions 12 | } from '../interfaces/Countries' 13 | import routes from '../routes' 14 | 15 | export default class Countries extends Http { 16 | /** 17 | * Returns a list of Countries. See [api docs](https://api.spreecommerce.org/docs/api-v2/104e8104bf29f-returns-a-list-of-countries). 18 | * 19 | * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) 20 | * 21 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 22 | * 23 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 24 | * 25 | * **Example:** 26 | * ```ts 27 | * const response = await client.countries.list({ 28 | * bearer_token: '7381273269536713689562374856' 29 | * }) 30 | * ``` 31 | */ 32 | public async list(options: ListOptions): Promise { 33 | const { token, params } = squashAndPreparePositionalArguments([options], []) 34 | 35 | return await this.spreeResponse('get', routes.countriesPath(), token, params) 36 | } 37 | 38 | /** 39 | * Returns a single Country. See [api docs](https://api.spreecommerce.org/docs/api-v2/b41a83f139baf-returns-a-country). 40 | * 41 | * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) 42 | * 43 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 44 | * 45 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 46 | * 47 | * **Example:** 48 | * ```ts 49 | * const response = await client.countries.show({ 50 | * bearer_token: '7381273269536713689562374856', 51 | * id: '1' 52 | * }) 53 | * ``` 54 | */ 55 | public async show(options: ShowOptions): Promise { 56 | const { id, token, params } = squashAndPreparePositionalArguments([options], ['id']) 57 | 58 | return await this.spreeResponse('get', routes.countryPath(id), token, params) 59 | } 60 | } -------------------------------------------------------------------------------- /packages/sdk-platform/src/endpoints/Digitals.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Http, 3 | squashAndPreparePositionalArguments 4 | } from '@spree/core-api-v2-sdk' 5 | import type { 6 | IDigitals, 7 | IDigitalsResult, 8 | IDigital, 9 | IDigitalResult, 10 | ListOptions, 11 | ShowOptions 12 | } from '../interfaces/Digitals' 13 | import routes from '../routes' 14 | 15 | export default class Digitals extends Http { 16 | /** 17 | * Returns a list of all Digital Assets. See [api docs](https://api.spreecommerce.org/docs/api-v2/2219ac1d1dc01-return-a-list-of-digital-assets). 18 | * 19 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 20 | * 21 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 22 | * 23 | * **Example:** 24 | * ```ts 25 | * const response = await client.digitals.list({ 26 | * bearer_token: '7381273269536713689562374856' 27 | * }) 28 | * ``` 29 | */ 30 | public async list(options: ListOptions): Promise { 31 | const { token, params } = squashAndPreparePositionalArguments([options], []) 32 | 33 | return await this.spreeResponse('get', routes.digitalsPath(), token, params) 34 | } 35 | 36 | /** 37 | * Returns a single Digital Asset by its ID. See [api docs](https://api.spreecommerce.org/docs/api-v2/edd5849a688e5-return-a-digital-asset). 38 | * 39 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 40 | * 41 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 42 | * 43 | * **Example:** 44 | * ```ts 45 | * const response = await client.digitals.show({ 46 | * bearer_token: '7381273269536713689562374856' 47 | * id: '1' 48 | * }) 49 | * ``` 50 | */ 51 | public async show(options: ShowOptions): Promise { 52 | const { id, token, params } = squashAndPreparePositionalArguments([options], ['id']) 53 | 54 | return await this.spreeResponse('get', routes.digitalPath(id), token, params) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/endpoints/States.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Http, 3 | squashAndPreparePositionalArguments 4 | } from '@spree/core-api-v2-sdk' 5 | import type { 6 | IState, 7 | IStateResult, 8 | IStates, 9 | IStatesResult, 10 | ListOptions, 11 | ShowOptions 12 | } from '../interfaces/States' 13 | import routes from '../routes' 14 | 15 | export default class States extends Http { 16 | /** 17 | * Returns a list of States. See [api docs](https://api.spreecommerce.org/docs/api-v2/f6c382d5fe26d-returns-a-list-of-states). 18 | * 19 | * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) 20 | * 21 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 22 | * 23 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 24 | * 25 | * **Example:** 26 | * ```ts 27 | * const response = await client.states.list({ 28 | * bearer_token: '7381273269536713689562374856' 29 | * }) 30 | * ``` 31 | */ 32 | public async list(options: ListOptions): Promise { 33 | const { token, params } = squashAndPreparePositionalArguments([options], []) 34 | 35 | return await this.spreeResponse('get', routes.statesPath(), token, params) 36 | } 37 | 38 | /** 39 | * Returns a single State by its ID. See [api docs](https://api.spreecommerce.org/docs/api-v2/fadd391c739d4-returns-a-state). 40 | * 41 | * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) 42 | * 43 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 44 | * 45 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 46 | * 47 | * **Example:** 48 | * ```ts 49 | * const response = await client.states.show({ 50 | * bearer_token: '7381273269536713689562374856' 51 | * id: '1' 52 | * }) 53 | * ``` 54 | */ 55 | public async show(options: ShowOptions): Promise { 56 | const { id, token, params } = squashAndPreparePositionalArguments([options], ['id']) 57 | 58 | return await this.spreeResponse('get', routes.statePath(id), token, params) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/endpoints/WebhookEvents.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Http, 3 | squashAndPreparePositionalArguments 4 | } from '@spree/core-api-v2-sdk' 5 | import type { 6 | IWebhookEvents, 7 | IWebhookEventsResult, 8 | ListOptions, 9 | } from '../interfaces/WebhookEvents' 10 | import routes from '../routes' 11 | 12 | export default class WebhookEvents extends Http { 13 | /** 14 | * Returns a list of Webhook Events. See [api docs](https://api.spreecommerce.org/docs/api-v2/987b4c4690542-return-a-list-of-webhook-events). 15 | * 16 | * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) 17 | * 18 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 19 | * 20 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 21 | * 22 | * **Example:** 23 | * ```ts 24 | * const response = await client.webhookEvents.list({ 25 | * bearer_token: '7381273269536713689562374856' 26 | * }) 27 | * ``` 28 | */ 29 | public async list(options: ListOptions): Promise { 30 | const { token, params } = squashAndPreparePositionalArguments([options], []) 31 | 32 | return await this.spreeResponse('get', routes.webhookEventsPath(), token, params) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/helpers/auth.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AuthApplicationTokenAttr, 3 | AuthApplicationTokenParams, 4 | AuthUserTokenAttr, 5 | AuthUserTokenParams, 6 | AuthRefreshTokenAttr, 7 | AuthRefreshTokenParams 8 | } from '../interfaces/Authentication' 9 | 10 | export const applicationAuthParams = ({ client_id, client_secret }: AuthApplicationTokenAttr): AuthApplicationTokenParams => ({ 11 | client_id, 12 | client_secret, 13 | grant_type: 'client_credentials', 14 | scope: 'admin' 15 | }) 16 | 17 | export const userAuthParams = ({ 18 | client_id, 19 | client_secret, 20 | username, 21 | password 22 | }: AuthUserTokenAttr): AuthUserTokenParams => ({ 23 | client_id, 24 | client_secret, 25 | username, 26 | password, 27 | grant_type: 'password', 28 | scope: 'admin' 29 | }) 30 | 31 | export const refreshParams = ({ refresh_token }: AuthRefreshTokenAttr): AuthRefreshTokenParams => ({ 32 | refresh_token, 33 | grant_type: 'refresh_token' 34 | }) 35 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Addresses.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface AddressAttr { 11 | country_id: string 12 | state_id: string 13 | state_name: string 14 | address1: string 15 | address2: string 16 | city: string 17 | zipcode: string 18 | phone: string 19 | alternative_phone: string 20 | firstname: string 21 | lastname: string 22 | label: string 23 | company: string 24 | user_id: string 25 | public_metadata?: { 26 | [key: string]: string 27 | } 28 | private_metadata?: { 29 | [key: string]: string 30 | } 31 | } 32 | 33 | export interface AddressData extends JsonApiDocument { 34 | type: string 35 | id: string 36 | attributes: AddressAttr 37 | relationships: IRelationships 38 | } 39 | 40 | export interface AddressParams { 41 | address: AddressAttr 42 | } 43 | 44 | export interface IAddress extends JsonApiSingleResponse { 45 | data: AddressData 46 | } 47 | 48 | export interface IAddresses extends JsonApiListResponse { 49 | data: AddressData[] 50 | } 51 | 52 | export interface IAddressResult extends ResultResponse {} 53 | 54 | export interface IAddressesResult extends ResultResponse {} 55 | 56 | export type ListOptions = WithCommonOptions< 57 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 58 | > 59 | 60 | export type ShowOptions = WithCommonOptions< 61 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 62 | { id: string; } 63 | > 64 | 65 | export type CreateOptions = WithCommonOptions< 66 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 67 | AddressParams 68 | > 69 | 70 | export type UpdateOptions = WithCommonOptions< 71 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 72 | AddressParams & { id: string } 73 | > 74 | 75 | export type RemoveOptions = WithCommonOptions< 76 | { suggestToken: true; onlyAccountToken: true }, 77 | { id: string } 78 | > 79 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Adjustments.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface AdjustmentAttr { 11 | source_type: string 12 | adjustable_type: string 13 | amount: string 14 | label: string 15 | mandatory: boolean | null 16 | eligible: boolean 17 | created_at: string 18 | updated_at: string 19 | state: string 20 | included: boolean 21 | display_amount: string 22 | } 23 | 24 | export interface AdjustmentData extends JsonApiDocument { 25 | type: string 26 | id: string 27 | attributes: AdjustmentAttr 28 | relationships: IRelationships 29 | } 30 | 31 | export interface AdjustmentParams { 32 | adjustment: { 33 | order_id: string 34 | label: string 35 | adjustable_id: string 36 | adjustable_type: string 37 | source_id: string 38 | source_type: string 39 | amount: number 40 | mandatory: boolean 41 | eligible: boolean 42 | state: string 43 | included: boolean 44 | } 45 | } 46 | 47 | export interface IAdjustment extends JsonApiSingleResponse { 48 | data: AdjustmentData 49 | } 50 | 51 | export interface IAdjustments extends JsonApiListResponse { 52 | data: AdjustmentData[] 53 | } 54 | 55 | export interface IAdjustmentResult extends ResultResponse {} 56 | 57 | export interface IAdjustmentsResult extends ResultResponse {} 58 | 59 | export type ListOptions = WithCommonOptions< 60 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 61 | > 62 | 63 | export type ShowOptions = WithCommonOptions< 64 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 65 | { id: string; } 66 | > 67 | 68 | export type CreateOptions = WithCommonOptions< 69 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 70 | AdjustmentParams 71 | > 72 | 73 | export type UpdateOptions = WithCommonOptions< 74 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 75 | AdjustmentParams & { id: string } 76 | > 77 | 78 | export type RemoveOptions = WithCommonOptions< 79 | { suggestToken: true; onlyAccountToken: true }, 80 | { id: string } 81 | > 82 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Authentication.ts: -------------------------------------------------------------------------------- 1 | import { WithCommonOptions } from '@spree/core-api-v2-sdk' 2 | 3 | export interface AuthApplicationTokenAttr { 4 | client_id: string 5 | client_secret: string 6 | } 7 | 8 | export interface AuthUserTokenAttr extends AuthApplicationTokenAttr { 9 | username: string 10 | password: string 11 | } 12 | 13 | export interface AuthRefreshTokenAttr { 14 | refresh_token: string 15 | } 16 | 17 | export interface AuthApplicationTokenParams { 18 | grant_type: 'client_credentials' 19 | scope: 'admin' 20 | client_id: string 21 | client_secret: string 22 | } 23 | 24 | export interface AuthUserTokenParams { 25 | grant_type: 'password' 26 | scope: 'admin' 27 | client_id: string 28 | client_secret: string 29 | username: string 30 | password: string 31 | } 32 | 33 | export interface AuthRefreshTokenParams { 34 | grant_type: 'refresh_token' 35 | refresh_token: string 36 | } 37 | 38 | export type GetApplicationTokenOptions = WithCommonOptions 39 | 40 | export type GetUserTokenOptions = WithCommonOptions 41 | 42 | export type RefreshTokenOptions = WithCommonOptions 43 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Classifications.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface ClassificationAttr { 11 | position: number 12 | created_at: string 13 | updated_at: string 14 | } 15 | 16 | export interface ClassificationData extends JsonApiDocument { 17 | type: string 18 | id: string 19 | attributes: ClassificationAttr 20 | relationships: IRelationships 21 | } 22 | 23 | export interface ClassificationParams { 24 | classification: { 25 | product_id: string 26 | taxon_id: string 27 | position: number 28 | } 29 | } 30 | 31 | export interface IClassification extends JsonApiSingleResponse { 32 | data: ClassificationData 33 | } 34 | 35 | export interface IClassifications extends JsonApiListResponse { 36 | data: ClassificationData[] 37 | } 38 | 39 | export interface IClassificationResult extends ResultResponse {} 40 | 41 | export interface IClassificationsResult extends ResultResponse {} 42 | 43 | export type ListOptions = WithCommonOptions< 44 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 45 | > 46 | 47 | export type ShowOptions = WithCommonOptions< 48 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 49 | { id: string; } 50 | > 51 | 52 | export type CreateOptions = WithCommonOptions< 53 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 54 | ClassificationParams 55 | > 56 | 57 | export type UpdateOptions = WithCommonOptions< 58 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 59 | ClassificationParams & { id: string } 60 | > 61 | 62 | export type RemoveOptions = WithCommonOptions< 63 | { suggestToken: true; onlyAccountToken: true }, 64 | { id: string } 65 | > 66 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Countries.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface CountriesAttr { 11 | iso_name: string 12 | iso: string 13 | iso3: string 14 | name: string 15 | numcode: number 16 | states_required: boolean 17 | updated_at: string 18 | zipcode_required: boolean 19 | created_at: string 20 | } 21 | 22 | export interface CountryData extends JsonApiDocument { 23 | type: string 24 | id: string 25 | attributes: CountriesAttr 26 | relationships: IRelationships 27 | } 28 | export interface ICountry extends JsonApiSingleResponse { 29 | data: CountryData 30 | } 31 | 32 | export interface ICountries extends JsonApiListResponse { 33 | data: CountryData[] 34 | } 35 | 36 | export interface ICountryResult extends ResultResponse {} 37 | 38 | export interface ICountriesResult extends ResultResponse {} 39 | 40 | export type ListOptions = WithCommonOptions< 41 | { suggestToken: true; onlyAccountToken: true } 42 | > 43 | 44 | export type ShowOptions = WithCommonOptions< 45 | { suggestToken: true; onlyAccountToken: true }, 46 | { id: string; } 47 | > -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/DigitalAsset.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | ResultResponse, 3 | WithCommonOptions 4 | } from '@spree/core-api-v2-sdk' 5 | 6 | export interface DigitalAsset extends ReadableStream {} 7 | 8 | export interface DigitalAssetResult extends ResultResponse {} 9 | 10 | export type DownloadOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }, { asset_token: string }> 11 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Digitals.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface DigitalAttr { 11 | url: string 12 | content_type: string 13 | filename: string 14 | byte_size: number 15 | } 16 | 17 | export interface DigitalData extends JsonApiDocument { 18 | type: string 19 | id: string 20 | attributes: DigitalAttr 21 | relationships: IRelationships 22 | } 23 | 24 | export interface IDigital extends JsonApiSingleResponse { 25 | data: DigitalData 26 | } 27 | 28 | export interface IDigitals extends JsonApiListResponse { 29 | data: DigitalData[] 30 | } 31 | 32 | export interface IDigitalResult extends ResultResponse {} 33 | 34 | export interface IDigitalsResult extends ResultResponse {} 35 | 36 | export type ListOptions = WithCommonOptions< 37 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 38 | > 39 | 40 | export type ShowOptions = WithCommonOptions< 41 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 42 | { id: string } 43 | > 44 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Links.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface LinkAttr { 11 | token: string 12 | access_counter: number 13 | } 14 | 15 | export interface LinkData extends JsonApiDocument { 16 | type: string 17 | id: string 18 | attributes: LinkAttr 19 | relationships: IRelationships 20 | } 21 | 22 | export interface LinkParams { 23 | digital_link: { 24 | access_counter: number 25 | line_item_id: string 26 | digital_id: string 27 | } 28 | } 29 | 30 | export interface ILink extends JsonApiSingleResponse { 31 | data: LinkData 32 | } 33 | 34 | export interface ILinks extends JsonApiListResponse { 35 | data: LinkData[] 36 | } 37 | 38 | export interface ILinkResult extends ResultResponse {} 39 | 40 | export interface ILinksResult extends ResultResponse {} 41 | 42 | export type ListOptions = WithCommonOptions< 43 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 44 | > 45 | 46 | export type ShowOptions = WithCommonOptions< 47 | { suggestToken: true; onlyAccountToken: true }, 48 | { id: string } 49 | > 50 | 51 | export type CreateOptions = WithCommonOptions< 52 | { suggestToken: true; onlyAccountToken: true }, 53 | LinkParams 54 | > 55 | 56 | export type UpdateOptions = WithCommonOptions< 57 | { suggestToken: true; onlyAccountToken: true }, 58 | LinkParams & { id: string } 59 | > 60 | 61 | export type RemoveOptions = WithCommonOptions< 62 | { suggestToken: true; onlyAccountToken: true }, 63 | { id: string } 64 | > 65 | 66 | export type ResetOptions = WithCommonOptions< 67 | { suggestToken: true; onlyAccountToken: true }, 68 | { id: string } 69 | > 70 | 71 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Menus.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface MenuAttr { 11 | name: string 12 | location: 'header' | 'footer' | string 13 | locale: string 14 | created_at: string 15 | updated_at: string 16 | } 17 | 18 | export interface MenuData extends JsonApiDocument { 19 | type: string 20 | id: string 21 | attributes: MenuAttr 22 | relationships: IRelationships 23 | } 24 | 25 | export interface MenuParams { 26 | menu: { 27 | name: string 28 | location: 'header' | 'footer' | string 29 | locale: string 30 | } 31 | } 32 | 33 | export interface IMenu extends JsonApiSingleResponse { 34 | data: MenuData 35 | } 36 | 37 | export interface IMenus extends JsonApiListResponse { 38 | data: MenuData[] 39 | } 40 | 41 | export interface IMenuResult extends ResultResponse {} 42 | 43 | export interface IMenusResult extends ResultResponse {} 44 | 45 | export type ListOptions = WithCommonOptions< 46 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 47 | > 48 | 49 | export type ShowOptions = WithCommonOptions< 50 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 51 | { id: string } 52 | > 53 | 54 | export type CreateOptions = WithCommonOptions< 55 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 56 | MenuParams 57 | > 58 | 59 | export type UpdateOptions = WithCommonOptions< 60 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 61 | MenuParams & { id: string } 62 | > 63 | 64 | export type RemoveOptions = WithCommonOptions< 65 | { suggestToken: true; onlyAccountToken: true }, 66 | { id: string } 67 | > 68 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/OptionTypes.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface OptionTypeAttr { 11 | name: string 12 | presentation: string 13 | position: number 14 | created_at: string 15 | updated_at: string 16 | filterable: boolean 17 | public_metadata?: { 18 | [key: string]: string 19 | } 20 | private_metadata?: { 21 | [key: string]: string 22 | } 23 | } 24 | 25 | export interface OptionTypeData extends JsonApiDocument { 26 | type: string 27 | id: string 28 | attributes: OptionTypeAttr 29 | relationships: IRelationships 30 | } 31 | 32 | export interface OptionTypeParams { 33 | option_type: { 34 | name: 'color' 35 | presentation: 'Color' 36 | public_metadata?: { 37 | [key: string]: string 38 | } 39 | private_metadata?: { 40 | [key: string]: string 41 | } 42 | } 43 | } 44 | 45 | export interface IOptionType extends JsonApiSingleResponse { 46 | data: OptionTypeData 47 | } 48 | 49 | export interface IOptionTypes extends JsonApiListResponse { 50 | data: OptionTypeData[] 51 | } 52 | 53 | export interface IOptionTypeResult extends ResultResponse {} 54 | 55 | export interface IOptionTypesResult extends ResultResponse {} 56 | 57 | export type ListOptions = WithCommonOptions< 58 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 59 | > 60 | 61 | export type ShowOptions = WithCommonOptions< 62 | { suggestToken: true; onlyAccountToken: true }, 63 | { id: string } 64 | > 65 | 66 | export type CreateOptions = WithCommonOptions< 67 | { suggestToken: true; onlyAccountToken: true }, 68 | OptionTypeParams 69 | > 70 | 71 | export type UpdateOptions = WithCommonOptions< 72 | { suggestToken: true; onlyAccountToken: true }, 73 | OptionTypeParams & { id: string } 74 | > 75 | 76 | export type RemoveOptions = WithCommonOptions< 77 | { suggestToken: true; onlyAccountToken: true }, 78 | { id: string } 79 | > 80 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/OptionValues.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface OptionValueAttr { 11 | position: number 12 | name: string 13 | presentation: string 14 | created_at: string 15 | updated_at: string 16 | public_metadata?: { 17 | [key: string]: string 18 | } 19 | private_metadata?: { 20 | [key: string]: string 21 | } 22 | } 23 | 24 | export interface OptionValueData extends JsonApiDocument { 25 | type: string 26 | id: string 27 | attributes: OptionValueAttr 28 | relationships: IRelationships 29 | } 30 | 31 | export interface OptionValueParams { 32 | option_value: { 33 | name: string 34 | presentation: string 35 | public_metadata?: { 36 | [key: string]: string 37 | } 38 | private_metadata?: { 39 | [key: string]: string 40 | } 41 | } 42 | } 43 | 44 | export interface IOptionValue extends JsonApiSingleResponse { 45 | data: OptionValueData 46 | } 47 | 48 | export interface IOptionValues extends JsonApiListResponse { 49 | data: OptionValueData[] 50 | } 51 | 52 | export interface IOptionValueResult extends ResultResponse {} 53 | 54 | export interface IOptionValuesResult extends ResultResponse {} 55 | 56 | export type ListOptions = WithCommonOptions< 57 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 58 | > 59 | 60 | export type ShowOptions = WithCommonOptions< 61 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 62 | { id: string } 63 | > 64 | 65 | export type CreateOptions = WithCommonOptions< 66 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 67 | OptionValueParams 68 | > 69 | 70 | export type UpdateOptions = WithCommonOptions< 71 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 72 | OptionValueParams & { id: string } 73 | > 74 | 75 | export type RemoveOptions = WithCommonOptions< 76 | { suggestToken: true; onlyAccountToken: true }, 77 | { id: string } 78 | > 79 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Pages.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface PageAttr { 11 | title: string 12 | meta_title: string 13 | content: string 14 | meta_description: string 15 | visible: boolean 16 | slug: string 17 | type: string 18 | locale: string 19 | deleted_at: string 20 | created_at: string 21 | updated_at: string 22 | } 23 | 24 | export interface PageData extends JsonApiDocument { 25 | type: string 26 | id: string 27 | attributes: PageAttr 28 | relationships: IRelationships 29 | } 30 | 31 | export interface PageParams { 32 | cms_page: { 33 | title: string 34 | type: string 35 | meta_title: string 36 | content: string 37 | meta_description: string 38 | visible: boolean 39 | slug: string 40 | locale: string 41 | } 42 | } 43 | 44 | export interface IPage extends JsonApiSingleResponse { 45 | data: PageData 46 | } 47 | 48 | export interface IPages extends JsonApiListResponse { 49 | data: PageData[] 50 | } 51 | 52 | export interface IPageResult extends ResultResponse {} 53 | 54 | export interface IPagesResult extends ResultResponse {} 55 | 56 | export type ListOptions = WithCommonOptions< 57 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 58 | > 59 | 60 | export type ShowOptions = WithCommonOptions< 61 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 62 | { id: string } 63 | > 64 | 65 | export type CreateOptions = WithCommonOptions< 66 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 67 | PageParams 68 | > 69 | 70 | export type UpdateOptions = WithCommonOptions< 71 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 72 | PageParams & { id: string } 73 | > 74 | 75 | export type RemoveOptions = WithCommonOptions< 76 | { suggestToken: true; onlyAccountToken: true }, 77 | { id: string } 78 | > 79 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/PaymentMethods.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface PaymentMethodAttr { 11 | name: string 12 | type: string 13 | description: any 14 | active: boolean 15 | display_on: string 16 | auto_capture: any 17 | position: number 18 | created_at: string 19 | updated_at: string 20 | deleted_at: any 21 | public_metadata?: { 22 | [key: string]: string 23 | } 24 | private_metadata?: { 25 | [key: string]: string 26 | } 27 | preferences: { 28 | [key: string]: string 29 | } 30 | } 31 | 32 | export interface PaymentMethodData extends JsonApiDocument { 33 | type: string 34 | id: string 35 | attributes: PaymentMethodAttr 36 | relationships: IRelationships 37 | } 38 | 39 | export interface PaymentMethodParams { 40 | payment_method: { 41 | name: string 42 | active: boolean 43 | auto_capture: boolean 44 | description: string 45 | type: string 46 | display_on: string 47 | store_ids: string[] 48 | public_metadata?: { 49 | [key: string]: string 50 | } 51 | private_metadata?: { 52 | [key: string]: string 53 | } 54 | } 55 | } 56 | 57 | export interface IPaymentMethod extends JsonApiSingleResponse { 58 | data: PaymentMethodData 59 | } 60 | 61 | export interface IPaymentMethods extends JsonApiListResponse { 62 | data: PaymentMethodData[] 63 | } 64 | 65 | export interface IPaymentMethodResult extends ResultResponse {} 66 | 67 | export interface IPaymentMethodsResult extends ResultResponse {} 68 | 69 | export type ListOptions = WithCommonOptions< 70 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 71 | > 72 | 73 | export type ShowOptions = WithCommonOptions< 74 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 75 | { id: string } 76 | > 77 | 78 | export type CreateOptions = WithCommonOptions< 79 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 80 | PaymentMethodParams 81 | > 82 | 83 | export type UpdateOptions = WithCommonOptions< 84 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 85 | PaymentMethodParams & { id: string } 86 | > 87 | 88 | export type RemoveOptions = WithCommonOptions< 89 | { suggestToken: true; onlyAccountToken: true }, 90 | { id: string } 91 | > 92 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Payments.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface PaymentAttr { 11 | amount: string 12 | source_type: string 13 | state: string 14 | response_code: string 15 | avs_response: string 16 | created_at: string 17 | updated_at: string 18 | number: string 19 | cvv_response_code: string 20 | cvv_response_message: string 21 | display_amount: string 22 | } 23 | 24 | export interface PaymentData extends JsonApiDocument { 25 | type: string 26 | id: string 27 | attributes: PaymentAttr 28 | relationships: IRelationships 29 | } 30 | 31 | export interface IPayment extends JsonApiSingleResponse { 32 | data: PaymentData 33 | } 34 | 35 | export interface IPayments extends JsonApiListResponse { 36 | data: PaymentData[] 37 | } 38 | 39 | export interface IPaymentResult extends ResultResponse {} 40 | 41 | export interface IPaymentsResult extends ResultResponse {} 42 | 43 | export type ListOptions = WithCommonOptions< 44 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 45 | > 46 | 47 | export type ShowOptions = WithCommonOptions< 48 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 49 | { id: string } 50 | > 51 | 52 | export type RemoveOptions = WithCommonOptions< 53 | { suggestToken: true; onlyAccountToken: true }, 54 | { id: string } 55 | > 56 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/PromotionActions.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface PromotionActionAttr { 11 | position: any 12 | type: any 13 | deleted_at: any 14 | created_at: string 15 | updated_at: string 16 | } 17 | 18 | export interface PromotionActionData extends JsonApiDocument { 19 | type: string 20 | id: string 21 | attributes: PromotionActionAttr 22 | relationships: IRelationships 23 | } 24 | 25 | export interface PromotionActionParams { 26 | promotion_action: { 27 | type: string 28 | promotion_id: string 29 | } 30 | } 31 | 32 | export interface IPromotionAction extends JsonApiSingleResponse { 33 | data: PromotionActionData 34 | } 35 | 36 | export interface IPromotionActions extends JsonApiListResponse { 37 | data: PromotionActionData[] 38 | } 39 | 40 | export interface IPromotionActionResult extends ResultResponse {} 41 | 42 | export interface IPromotionActionsResult extends ResultResponse {} 43 | 44 | export type ListOptions = WithCommonOptions< 45 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 46 | > 47 | 48 | export type ShowOptions = WithCommonOptions< 49 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 50 | { id: string } 51 | > 52 | 53 | export type CreateOptions = WithCommonOptions< 54 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 55 | PromotionActionParams 56 | > 57 | 58 | export type UpdateOptions = WithCommonOptions< 59 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 60 | PromotionActionParams & { id: string } 61 | > 62 | 63 | export type RemoveOptions = WithCommonOptions< 64 | { suggestToken: true; onlyAccountToken: true }, 65 | { id: string } 66 | > 67 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/PromotionCategories.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface PromotionCategoryAttr { 11 | name: string 12 | created_at: string 13 | updated_at: string 14 | code: string 15 | } 16 | 17 | export interface PromotionCategoryData extends JsonApiDocument { 18 | type: string 19 | id: string 20 | attributes: PromotionCategoryAttr 21 | relationships: IRelationships 22 | } 23 | 24 | export interface PromotionCategoryParams { 25 | promotion_category: { 26 | name: string 27 | code: string 28 | } 29 | } 30 | 31 | export interface IPromotionCategory extends JsonApiSingleResponse { 32 | data: PromotionCategoryData 33 | } 34 | 35 | export interface IPromotionCategories extends JsonApiListResponse { 36 | data: PromotionCategoryData[] 37 | } 38 | 39 | export interface IPromotionCategoryResult extends ResultResponse {} 40 | 41 | export interface IPromotionCategoriesResult extends ResultResponse {} 42 | 43 | export type ListOptions = WithCommonOptions< 44 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 45 | > 46 | 47 | export type ShowOptions = WithCommonOptions< 48 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 49 | { id: string } 50 | > 51 | 52 | export type CreateOptions = WithCommonOptions< 53 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 54 | PromotionCategoryParams 55 | > 56 | 57 | export type UpdateOptions = WithCommonOptions< 58 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 59 | PromotionCategoryParams & { id: string } 60 | > 61 | 62 | export type RemoveOptions = WithCommonOptions< 63 | { suggestToken: true; onlyAccountToken: true }, 64 | { id: string } 65 | > 66 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/PromotionRules.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface PromotionRuleAttr { 11 | type: any 12 | created_at: string 13 | updated_at: string 14 | code: any 15 | preferences: { 16 | [key: string]: string 17 | } 18 | } 19 | 20 | export interface PromotionRuleData extends JsonApiDocument { 21 | type: string 22 | id: string 23 | attributes: PromotionRuleAttr 24 | relationships: IRelationships 25 | } 26 | 27 | export interface PromotionRuleParams { 28 | promotion_rule: { 29 | promotion_id: string 30 | type: string 31 | } 32 | } 33 | 34 | export interface IPromotionRule extends JsonApiSingleResponse { 35 | data: PromotionRuleData 36 | } 37 | 38 | export interface IPromotionRules extends JsonApiListResponse { 39 | data: PromotionRuleData[] 40 | } 41 | 42 | export interface IPromotionRuleResult extends ResultResponse {} 43 | 44 | export interface IPromotionRulesResult extends ResultResponse {} 45 | 46 | export type ListOptions = WithCommonOptions< 47 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 48 | > 49 | 50 | export type ShowOptions = WithCommonOptions< 51 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 52 | { id: string } 53 | > 54 | 55 | export type CreateOptions = WithCommonOptions< 56 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 57 | PromotionRuleParams 58 | > 59 | 60 | export type UpdateOptions = WithCommonOptions< 61 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 62 | PromotionRuleParams & { id: string } 63 | > 64 | 65 | export type RemoveOptions = WithCommonOptions< 66 | { suggestToken: true; onlyAccountToken: true }, 67 | { id: string } 68 | > 69 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Promotions.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface PromotionAttr { 11 | description: any 12 | expires_at: any 13 | starts_at: any 14 | name: string 15 | type: any 16 | usage_limit: any 17 | match_policy: string 18 | code: any 19 | advertise: boolean 20 | path: any 21 | created_at: string 22 | updated_at: string 23 | public_metadata?: { 24 | [key: string]: string 25 | } 26 | private_metadata?: { 27 | [key: string]: string 28 | } 29 | } 30 | 31 | export interface PromotionData extends JsonApiDocument { 32 | type: string 33 | id: string 34 | attributes: PromotionAttr 35 | relationships: IRelationships 36 | } 37 | 38 | export interface PromotionParams { 39 | promotion: { 40 | name: string 41 | code: string 42 | description: string 43 | usage_limit: number 44 | advertise: boolean 45 | starts_at: string 46 | ends_at: string 47 | store_ids: string[] 48 | } 49 | } 50 | 51 | export interface IPromotion extends JsonApiSingleResponse { 52 | data: PromotionData 53 | } 54 | 55 | export interface IPromotions extends JsonApiListResponse { 56 | data: PromotionData[] 57 | } 58 | 59 | export interface IPromotionResult extends ResultResponse {} 60 | 61 | export interface IPromotionsResult extends ResultResponse {} 62 | 63 | export type ListOptions = WithCommonOptions< 64 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 65 | > 66 | 67 | export type ShowOptions = WithCommonOptions< 68 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 69 | { id: string } 70 | > 71 | 72 | export type CreateOptions = WithCommonOptions< 73 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 74 | PromotionParams 75 | > 76 | 77 | export type UpdateOptions = WithCommonOptions< 78 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 79 | PromotionParams & { id: string } 80 | > 81 | 82 | export type RemoveOptions = WithCommonOptions< 83 | { suggestToken: true; onlyAccountToken: true }, 84 | { id: string } 85 | > 86 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Roles.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface RoleAttr { 11 | name: string 12 | created_at: string 13 | updated_at: string 14 | } 15 | 16 | export interface RoleData extends JsonApiDocument { 17 | type: string 18 | id: string 19 | attributes: RoleAttr 20 | relationships: IRelationships 21 | } 22 | 23 | export interface RoleParams { 24 | name: string 25 | } 26 | 27 | export interface IRole extends JsonApiSingleResponse { 28 | data: RoleData 29 | } 30 | 31 | export interface IRoles extends JsonApiListResponse { 32 | data: RoleData[] 33 | } 34 | 35 | export interface IRoleResult extends ResultResponse {} 36 | 37 | export interface IRolesResult extends ResultResponse {} 38 | 39 | export type ListOptions = WithCommonOptions< 40 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 41 | > 42 | 43 | export type ShowOptions = WithCommonOptions< 44 | { suggestToken: true; onlyAccountToken: true }, 45 | { id: string } 46 | > 47 | 48 | export type CreateOptions = WithCommonOptions< 49 | { suggestToken: true; onlyAccountToken: true }, 50 | RoleParams 51 | > 52 | 53 | export type UpdateOptions = WithCommonOptions< 54 | { suggestToken: true; onlyAccountToken: true }, 55 | RoleParams & { id: string } 56 | > 57 | 58 | export type RemoveOptions = WithCommonOptions< 59 | { suggestToken: true; onlyAccountToken: true }, 60 | { id: string } 61 | > 62 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Sections.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface SectionAttr { 11 | name: string 12 | content: any 13 | settings: { 14 | gutters: string 15 | } 16 | fit: string 17 | destination: string 18 | type: string 19 | position: number 20 | linked_resource_type: string 21 | created_at: string 22 | updated_at: string 23 | } 24 | 25 | export interface SectionData extends JsonApiDocument { 26 | type: string 27 | id: string 28 | attributes: SectionAttr 29 | relationships: IRelationships 30 | } 31 | 32 | export interface SectionParams { 33 | cms_page: { 34 | name: string 35 | cms_page_id: string 36 | type: string 37 | linked_resource_type: string 38 | linked_resource_id: string 39 | fit: string 40 | position: number 41 | gutters: string 42 | button_text: string 43 | title: string 44 | } 45 | } 46 | 47 | export interface ISection extends JsonApiSingleResponse { 48 | data: SectionData 49 | } 50 | 51 | export interface ISections extends JsonApiListResponse { 52 | data: SectionData[] 53 | } 54 | 55 | export interface ISectionResult extends ResultResponse {} 56 | 57 | export interface ISectionsResult extends ResultResponse {} 58 | 59 | export type ListOptions = WithCommonOptions< 60 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 61 | > 62 | 63 | export type ShowOptions = WithCommonOptions< 64 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 65 | { id: string } 66 | > 67 | 68 | export type CreateOptions = WithCommonOptions< 69 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 70 | SectionParams 71 | > 72 | 73 | export type UpdateOptions = WithCommonOptions< 74 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 75 | SectionParams & { id: string } 76 | > 77 | 78 | export type RemoveOptions = WithCommonOptions< 79 | { suggestToken: true; onlyAccountToken: true }, 80 | { id: string } 81 | > 82 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/ShippingCategories.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface ShippingCategoryAttr { 11 | name: string 12 | created_at: string 13 | updated_at: string 14 | } 15 | 16 | export interface ShippingCategoryData extends JsonApiDocument { 17 | type: string 18 | id: string 19 | attributes: ShippingCategoryAttr 20 | relationships: IRelationships 21 | } 22 | 23 | export interface ShippingCategoryParams { 24 | name: string 25 | } 26 | 27 | export interface IShippingCategory extends JsonApiSingleResponse { 28 | data: ShippingCategoryData 29 | } 30 | 31 | export interface IShippingCategories extends JsonApiListResponse { 32 | data: ShippingCategoryData[] 33 | } 34 | 35 | export interface IShippingCategoryResult extends ResultResponse {} 36 | 37 | export interface IShippingCategoriesResult extends ResultResponse {} 38 | 39 | export type ListOptions = WithCommonOptions< 40 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 41 | > 42 | 43 | export type ShowOptions = WithCommonOptions< 44 | { suggestToken: true; onlyAccountToken: true }, 45 | { id: string } 46 | > 47 | 48 | export type CreateOptions = WithCommonOptions< 49 | { suggestToken: true; onlyAccountToken: true }, 50 | ShippingCategoryParams 51 | > 52 | 53 | export type UpdateOptions = WithCommonOptions< 54 | { suggestToken: true; onlyAccountToken: true }, 55 | ShippingCategoryParams & { id: string } 56 | > 57 | 58 | export type RemoveOptions = WithCommonOptions< 59 | { suggestToken: true; onlyAccountToken: true }, 60 | { id: string } 61 | > 62 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/ShippingMethods.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface ShippingMethodAttr { 11 | name: string 12 | admin_name: string 13 | code: string 14 | tracking_url: string 15 | display_on: string 16 | tax_category_id: string 17 | shipping_category_ids: string[] 18 | calculator_attributes: { 19 | type: string 20 | } 21 | public_metadata?: { 22 | [key: string]: string 23 | } 24 | private_metadata?: { 25 | [key: string]: string 26 | } 27 | } 28 | 29 | export interface ShippingMethodData extends JsonApiDocument { 30 | type: string 31 | id: string 32 | attributes: ShippingMethodAttr 33 | relationships: IRelationships 34 | } 35 | 36 | export interface ShippingMethodParams { 37 | name: string 38 | admin_name: string 39 | code: string 40 | tracking_url: string 41 | display_on: string 42 | tax_category_id: string 43 | shipping_category_ids: string[] 44 | calculator_attributes: { 45 | type: string 46 | } 47 | public_metadata?: { 48 | [key: string]: string 49 | } 50 | private_metadata?: { 51 | [key: string]: string 52 | } 53 | } 54 | 55 | export interface IShippingMethod extends JsonApiSingleResponse { 56 | data: ShippingMethodData 57 | } 58 | 59 | export interface IShippingMethods extends JsonApiListResponse { 60 | data: ShippingMethodData[] 61 | } 62 | 63 | export interface IShippingMethodResult extends ResultResponse {} 64 | 65 | export interface IShippingMethodsResult extends ResultResponse {} 66 | 67 | export type ListOptions = WithCommonOptions< 68 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 69 | > 70 | 71 | export type ShowOptions = WithCommonOptions< 72 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 73 | { id: string } 74 | > 75 | 76 | export type CreateOptions = WithCommonOptions< 77 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 78 | ShippingMethodParams 79 | > 80 | 81 | export type UpdateOptions = WithCommonOptions< 82 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 83 | ShippingMethodParams & { id: string } 84 | > 85 | 86 | export type RemoveOptions = WithCommonOptions< 87 | { suggestToken: true; onlyAccountToken: true }, 88 | { id: string } 89 | > 90 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/States.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface StateAttr { 11 | name: string 12 | abbr: string 13 | updated_at: string 14 | created_at: string 15 | } 16 | 17 | export interface StateData extends JsonApiDocument { 18 | type: string 19 | id: string 20 | attributes: StateAttr 21 | relationships: IRelationships 22 | } 23 | 24 | export interface IState extends JsonApiSingleResponse { 25 | data: StateData 26 | } 27 | 28 | export interface IStates extends JsonApiListResponse { 29 | data: StateData[] 30 | } 31 | 32 | export interface IStateResult extends ResultResponse {} 33 | 34 | export interface IStatesResult extends ResultResponse {} 35 | 36 | export type ListOptions = WithCommonOptions< 37 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 38 | > 39 | 40 | export type ShowOptions = WithCommonOptions< 41 | { suggestToken: true; onlyAccountToken: true }, 42 | { id: string } 43 | > 44 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/StockItems.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface StockItemAttr { 11 | count_on_hand: number 12 | created_at: string 13 | updated_at: string 14 | backorderable: boolean 15 | deleted_at: any 16 | is_available: boolean 17 | public_metadata?: { 18 | [key: string]: string 19 | } 20 | private_metadata?: { 21 | [key: string]: string 22 | } 23 | } 24 | 25 | export interface StockItemData extends JsonApiDocument { 26 | type: string 27 | id: string 28 | attributes: StockItemAttr 29 | relationships: IRelationships 30 | } 31 | 32 | export interface StockItemParams { 33 | stock_item: { 34 | variant_id: string 35 | stock_location_id: string 36 | count_on_hand: number 37 | backorderable: boolean 38 | } 39 | } 40 | 41 | export interface IStockItem extends JsonApiSingleResponse { 42 | data: StockItemData 43 | } 44 | 45 | export interface IStockItems extends JsonApiListResponse { 46 | data: StockItemData[] 47 | } 48 | 49 | export interface IStockItemResult extends ResultResponse {} 50 | 51 | export interface IStockItemsResult extends ResultResponse {} 52 | 53 | export type ListOptions = WithCommonOptions< 54 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 55 | > 56 | 57 | export type ShowOptions = WithCommonOptions< 58 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 59 | { id: string } 60 | > 61 | 62 | export type CreateOptions = WithCommonOptions< 63 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 64 | StockItemParams 65 | > 66 | 67 | export type UpdateOptions = WithCommonOptions< 68 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 69 | StockItemParams & { id: string } 70 | > 71 | 72 | export type RemoveOptions = WithCommonOptions< 73 | { suggestToken: true; onlyAccountToken: true }, 74 | { id: string } 75 | > 76 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/StockLocations.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface StockLocationAttr { 11 | name: string 12 | created_at: string 13 | updated_at: string 14 | default: boolean 15 | address1: string 16 | address2: any 17 | city: string 18 | state_name: any 19 | zipcode: string 20 | phone: string 21 | active: boolean 22 | backorderable_default: boolean 23 | propagate_all_variants: boolean 24 | admin_name: any 25 | } 26 | 27 | export interface StockLocationData extends JsonApiDocument { 28 | type: string 29 | id: string 30 | attributes: StockLocationAttr 31 | relationships: IRelationships 32 | } 33 | 34 | export interface StockLocationParams { 35 | stock_location: { 36 | name: string 37 | default: boolean 38 | address1: string 39 | address2: string 40 | country_id: string 41 | state_id: string 42 | city: string 43 | state_name: string 44 | zipcode: string 45 | phone: string 46 | active: boolean 47 | backorderable_default: boolean 48 | propagate_all_variants: boolean 49 | admin_name: string 50 | } 51 | } 52 | 53 | export interface IStockLocation extends JsonApiSingleResponse { 54 | data: StockLocationData 55 | } 56 | 57 | export interface IStockLocations extends JsonApiListResponse { 58 | data: StockLocationData[] 59 | } 60 | 61 | export interface IStockLocationResult extends ResultResponse {} 62 | 63 | export interface IStockLocationsResult extends ResultResponse {} 64 | 65 | export type ListOptions = WithCommonOptions< 66 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 67 | > 68 | 69 | export type ShowOptions = WithCommonOptions< 70 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 71 | { id: string } 72 | > 73 | 74 | export type CreateOptions = WithCommonOptions< 75 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 76 | StockLocationParams 77 | > 78 | 79 | export type UpdateOptions = WithCommonOptions< 80 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 81 | StockLocationParams & { id: string } 82 | > 83 | 84 | export type RemoveOptions = WithCommonOptions< 85 | { suggestToken: true; onlyAccountToken: true }, 86 | { id: string } 87 | > 88 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/StoreCreditCategories.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface StoreCreditCategoryAttr { 11 | name: string 12 | created_at: string 13 | updated_at: string 14 | } 15 | 16 | export interface StoreCreditCategoryData extends JsonApiDocument { 17 | type: string 18 | id: string 19 | attributes: StoreCreditCategoryAttr 20 | relationships: IRelationships 21 | } 22 | 23 | export interface StoreCreditCategoryParams { 24 | store_credit_category: { 25 | name: string 26 | } 27 | } 28 | 29 | export interface IStoreCreditCategory extends JsonApiSingleResponse { 30 | data: StoreCreditCategoryData 31 | } 32 | 33 | export interface IStoreCreditCategories extends JsonApiListResponse { 34 | data: StoreCreditCategoryData[] 35 | } 36 | 37 | export interface IStoreCreditCategoryResult extends ResultResponse {} 38 | 39 | export interface IStoreCreditCategoriesResult extends ResultResponse {} 40 | 41 | export type ListOptions = WithCommonOptions< 42 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 43 | > 44 | 45 | export type ShowOptions = WithCommonOptions< 46 | { suggestToken: true; onlyAccountToken: true }, 47 | { id: string } 48 | > 49 | 50 | export type CreateOptions = WithCommonOptions< 51 | { suggestToken: true; onlyAccountToken: true }, 52 | StoreCreditCategoryParams 53 | > 54 | 55 | export type UpdateOptions = WithCommonOptions< 56 | { suggestToken: true; onlyAccountToken: true }, 57 | StoreCreditCategoryParams & { id: string } 58 | > 59 | 60 | export type RemoveOptions = WithCommonOptions< 61 | { suggestToken: true; onlyAccountToken: true }, 62 | { id: string } 63 | > 64 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/StoreCreditTypes.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface StoreCreditTypeAttr { 11 | name: string 12 | priority: number 13 | created_at: string 14 | updated_at: string 15 | } 16 | 17 | export interface StoreCreditTypeData extends JsonApiDocument { 18 | type: string 19 | id: string 20 | attributes: StoreCreditTypeAttr 21 | relationships: IRelationships 22 | } 23 | 24 | export interface StoreCreditTypeParams { 25 | name: string 26 | priority: number 27 | } 28 | 29 | export interface IStoreCreditType extends JsonApiSingleResponse { 30 | data: StoreCreditTypeData 31 | } 32 | 33 | export interface IStoreCreditTypes extends JsonApiListResponse { 34 | data: StoreCreditTypeData[] 35 | } 36 | 37 | export interface IStoreCreditTypeResult extends ResultResponse {} 38 | 39 | export interface IStoreCreditTypesResult extends ResultResponse {} 40 | 41 | export type ListOptions = WithCommonOptions< 42 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 43 | > 44 | 45 | export type ShowOptions = WithCommonOptions< 46 | { suggestToken: true; onlyAccountToken: true }, 47 | { id: string } 48 | > 49 | 50 | export type CreateOptions = WithCommonOptions< 51 | { suggestToken: true; onlyAccountToken: true }, 52 | StoreCreditTypeParams 53 | > 54 | 55 | export type UpdateOptions = WithCommonOptions< 56 | { suggestToken: true; onlyAccountToken: true }, 57 | StoreCreditTypeParams & { id: string } 58 | > 59 | 60 | export type RemoveOptions = WithCommonOptions< 61 | { suggestToken: true; onlyAccountToken: true }, 62 | { id: string } 63 | > 64 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/StoreCredits.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface StoreCreditAttr { 11 | amount: string 12 | amount_used: string 13 | memo: any 14 | deleted_at: any 15 | currency: string 16 | amount_authorized: string 17 | originator_type: any 18 | created_at: string 19 | updated_at: string 20 | display_amount: string 21 | display_amount_used: string 22 | public_metadata?: { 23 | [key: string]: string 24 | } 25 | private_metadata?: { 26 | [key: string]: string 27 | } 28 | } 29 | 30 | export interface StoreCreditData extends JsonApiDocument { 31 | type: string 32 | id: string 33 | attributes: StoreCreditAttr 34 | relationships: IRelationships 35 | } 36 | 37 | export interface StoreCreditParams { 38 | store_credit: { 39 | user_id: string 40 | category_id: string 41 | created_by_id: string 42 | amount: number 43 | amount_used: number 44 | memo: string 45 | currency: string 46 | amount_authorized: number 47 | originator_id: string 48 | originator_type: string 49 | type_id: string 50 | store_id: string 51 | public_metadata?: { 52 | [key: string]: string 53 | } 54 | private_metadata?: { 55 | [key: string]: string 56 | } 57 | } 58 | } 59 | 60 | export interface IStoreCredit extends JsonApiSingleResponse { 61 | data: StoreCreditData 62 | } 63 | 64 | export interface IStoreCredits extends JsonApiListResponse { 65 | data: StoreCreditData[] 66 | } 67 | 68 | export interface IStoreCreditResult extends ResultResponse {} 69 | 70 | export interface IStoreCreditsResult extends ResultResponse {} 71 | 72 | export type ListOptions = WithCommonOptions< 73 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 74 | > 75 | 76 | export type ShowOptions = WithCommonOptions< 77 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 78 | { id: string } 79 | > 80 | 81 | export type CreateOptions = WithCommonOptions< 82 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 83 | StoreCreditParams 84 | > 85 | 86 | export type UpdateOptions = WithCommonOptions< 87 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 88 | StoreCreditParams & { id: string } 89 | > 90 | 91 | export type RemoveOptions = WithCommonOptions< 92 | { suggestToken: true; onlyAccountToken: true }, 93 | { id: string } 94 | > 95 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/TaxCategories.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface TaxCategoryAttr { 11 | name: string 12 | is_default: boolean 13 | tax_code: string 14 | description: string 15 | } 16 | 17 | export interface TaxCategoryData extends JsonApiDocument { 18 | type: string 19 | id: string 20 | attributes: TaxCategoryAttr 21 | relationships: IRelationships 22 | } 23 | 24 | export interface TaxCategoryParams { 25 | tax_category: { 26 | name: string 27 | is_default: boolean 28 | tax_code: string 29 | description: string 30 | } 31 | } 32 | 33 | export interface ITaxCategory extends JsonApiSingleResponse { 34 | data: TaxCategoryData 35 | } 36 | 37 | export interface ITaxCategories extends JsonApiListResponse { 38 | data: TaxCategoryData[] 39 | } 40 | 41 | export interface ITaxCategoryResult extends ResultResponse {} 42 | 43 | export interface ITaxCategoriesResult extends ResultResponse {} 44 | 45 | export type ListOptions = WithCommonOptions< 46 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 47 | > 48 | 49 | export type ShowOptions = WithCommonOptions< 50 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 51 | { id: string } 52 | > 53 | 54 | export type CreateOptions = WithCommonOptions< 55 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 56 | TaxCategoryParams 57 | > 58 | 59 | export type UpdateOptions = WithCommonOptions< 60 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 61 | TaxCategoryParams & { id: string } 62 | > 63 | 64 | export type RemoveOptions = WithCommonOptions< 65 | { suggestToken: true; onlyAccountToken: true }, 66 | { id: string } 67 | > 68 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/TaxRates.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface TaxRateAttr { 11 | amount: string 12 | included_in_price: boolean 13 | created_at: string 14 | updated_at: string 15 | name: string 16 | show_rate_in_label: boolean 17 | deleted_at: any 18 | public_metadata?: { 19 | [key: string]: string 20 | } 21 | private_metadata?: { 22 | [key: string]: string 23 | } 24 | } 25 | 26 | export interface TaxRateData extends JsonApiDocument { 27 | type: string 28 | id: string 29 | attributes: TaxRateAttr 30 | relationships: IRelationships 31 | } 32 | 33 | export interface TaxRateParams { 34 | tax_rate: { 35 | amount: number 36 | zone_id: string 37 | tax_category_id: string 38 | included_in_price: boolean 39 | name: string 40 | show_rate_in_label: boolean 41 | calculator_attributes: { 42 | type: string, 43 | preferences: { 44 | amount: number, 45 | currency: string 46 | } 47 | } 48 | } 49 | } 50 | 51 | export interface ITaxRate extends JsonApiSingleResponse { 52 | data: TaxRateData 53 | } 54 | 55 | export interface ITaxRates extends JsonApiListResponse { 56 | data: TaxRateData[] 57 | } 58 | 59 | export interface ITaxRateResult extends ResultResponse {} 60 | 61 | export interface ITaxRatesResult extends ResultResponse {} 62 | 63 | export type ListOptions = WithCommonOptions< 64 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 65 | > 66 | 67 | export type ShowOptions = WithCommonOptions< 68 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 69 | { id: string } 70 | > 71 | 72 | export type CreateOptions = WithCommonOptions< 73 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 74 | TaxRateParams 75 | > 76 | 77 | export type UpdateOptions = WithCommonOptions< 78 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 79 | TaxRateParams & { id: string } 80 | > 81 | 82 | export type RemoveOptions = WithCommonOptions< 83 | { suggestToken: true; onlyAccountToken: true }, 84 | { id: string } 85 | > 86 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Taxonomies.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface TaxonomyAttr { 11 | name: string 12 | created_at: string 13 | updated_at: string 14 | position: number 15 | public_metadata?: { 16 | [key: string]: string 17 | } 18 | private_metadata?: { 19 | [key: string]: string 20 | } 21 | } 22 | 23 | export interface TaxonomyData extends JsonApiDocument { 24 | type: string 25 | id: string 26 | attributes: TaxonomyAttr 27 | relationships: IRelationships 28 | } 29 | 30 | export interface TaxonomyParams { 31 | taxonomy: { 32 | name: string 33 | position: number 34 | public_metadata?: { 35 | [key: string]: string 36 | } 37 | private_metadata?: { 38 | [key: string]: string 39 | } 40 | } 41 | } 42 | 43 | export interface ITaxonomy extends JsonApiSingleResponse { 44 | data: TaxonomyData 45 | } 46 | 47 | export interface ITaxonomies extends JsonApiListResponse { 48 | data: TaxonomyData[] 49 | } 50 | 51 | export interface ITaxonomyResult extends ResultResponse {} 52 | 53 | export interface ITaxonomiesResult extends ResultResponse {} 54 | 55 | export type ListOptions = WithCommonOptions< 56 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 57 | > 58 | 59 | export type ShowOptions = WithCommonOptions< 60 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 61 | { id: string } 62 | > 63 | 64 | export type CreateOptions = WithCommonOptions< 65 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 66 | TaxonomyParams 67 | > 68 | 69 | export type UpdateOptions = WithCommonOptions< 70 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 71 | TaxonomyParams & { id: string } 72 | > 73 | 74 | export type RemoveOptions = WithCommonOptions< 75 | { suggestToken: true; onlyAccountToken: true }, 76 | { id: string } 77 | > 78 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Users.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface UserAttr { 11 | email: string 12 | first_name: string 13 | last_name: string 14 | created_at: string 15 | updated_at: string 16 | average_order_value: any[] 17 | lifetime_value: any[] 18 | store_credits: any[] 19 | public_metadata?: { 20 | [key: string]: string 21 | } 22 | private_metadata?: { 23 | [key: string]: string 24 | } 25 | } 26 | 27 | export interface UserData extends JsonApiDocument { 28 | type: string 29 | id: string 30 | attributes: UserAttr 31 | relationships: IRelationships 32 | } 33 | 34 | export interface UserParams { 35 | user: { 36 | email: string 37 | first_name: string 38 | last_name: string 39 | password: string 40 | password_confirmation: string 41 | ship_address_id: string 42 | bill_address_id: string 43 | public_metadata?: { 44 | [key: string]: string 45 | } 46 | private_metadata?: { 47 | [key: string]: string 48 | } 49 | } 50 | } 51 | 52 | export interface IUser extends JsonApiSingleResponse { 53 | data: UserData 54 | } 55 | 56 | export interface IUsers extends JsonApiListResponse { 57 | data: UserData[] 58 | } 59 | 60 | export interface IUserResult extends ResultResponse {} 61 | 62 | export interface IUsersResult extends ResultResponse {} 63 | 64 | export type ListOptions = WithCommonOptions< 65 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 66 | > 67 | 68 | export type ShowOptions = WithCommonOptions< 69 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 70 | { id: string } 71 | > 72 | 73 | export type CreateOptions = WithCommonOptions< 74 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 75 | UserParams 76 | > 77 | 78 | export type UpdateOptions = WithCommonOptions< 79 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 80 | UserParams & { id: string } 81 | > 82 | 83 | export type RemoveOptions = WithCommonOptions< 84 | { suggestToken: true; onlyAccountToken: true }, 85 | { id: string } 86 | > 87 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Variants.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface VariantAttr { 11 | sku: string 12 | weight: string 13 | height: any 14 | depth: any 15 | deleted_at: any 16 | is_master: boolean 17 | cost_price: string 18 | position: number 19 | cost_currency: string 20 | track_inventory: boolean 21 | updated_at: string 22 | discontinue_on: any 23 | created_at: string 24 | barcode: any 25 | display_price: string 26 | display_compare_at_price: any 27 | name: string 28 | options_text: string 29 | total_on_hand: number 30 | purchasable: boolean 31 | in_stock: boolean 32 | backorderable: boolean 33 | available: boolean 34 | currency: string 35 | price: string 36 | compare_at_price: any 37 | public_metadata?: { 38 | [key: string]: string 39 | } 40 | private_metadata?: { 41 | [key: string]: string 42 | } 43 | } 44 | 45 | export interface VariantData extends JsonApiDocument { 46 | type: string 47 | id: string 48 | attributes: VariantAttr 49 | relationships: IRelationships 50 | } 51 | 52 | export interface IVariant extends JsonApiSingleResponse { 53 | data: VariantData 54 | } 55 | 56 | export interface IVariants extends JsonApiListResponse { 57 | data: VariantData[] 58 | } 59 | 60 | export interface IVariantResult extends ResultResponse {} 61 | 62 | export interface IVariantsResult extends ResultResponse {} 63 | 64 | export type ListOptions = WithCommonOptions< 65 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 66 | > 67 | 68 | export type ShowOptions = WithCommonOptions< 69 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 70 | { id: string } 71 | > 72 | 73 | export type RemoveOptions = WithCommonOptions< 74 | { suggestToken: true; onlyAccountToken: true }, 75 | { id: string } 76 | > 77 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Vendor.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface VendorAttr extends JsonApiDocument { 11 | type: string 12 | id: string 13 | attributes: { 14 | name: string 15 | slug: string 16 | instagram: string | null 17 | facebook: string | null 18 | twitter: string | null 19 | about_us: string | null 20 | logo_url: string | null 21 | logo_small_url: string | null 22 | logo_medium_url: string | null 23 | logo_large_url: string | null 24 | cover_photo_url: string | null 25 | cover_photo_small_url: string | null 26 | cover_photo_medium_url: string | null 27 | cover_photo_large_url: string | null 28 | } 29 | relationships: IRelationships 30 | } 31 | 32 | export interface Vendor extends JsonApiSingleResponse { 33 | data: VendorAttr 34 | } 35 | 36 | export interface Vendors extends JsonApiListResponse { 37 | data: VendorAttr[] 38 | } 39 | 40 | export interface VendorResult extends ResultResponse {} 41 | 42 | export interface VendorsResult extends ResultResponse {} 43 | 44 | export type ListOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; optionalToken: true }> 45 | 46 | export type ShowOptions = WithCommonOptions< 47 | { suggestToken: true; suggestQuery: true; optionalToken: true }, 48 | { id: string } 49 | > 50 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/WebhookEvents.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | IRelationships, 5 | ResultResponse, 6 | WithCommonOptions 7 | } from '@spree/core-api-v2-sdk' 8 | 9 | export interface WebhookEventsAttr { 10 | execution_time: number 11 | name: string 12 | request_errors: string 13 | response_code: string 14 | success: boolean 15 | url: string 16 | created_at: string 17 | updated_at: string 18 | } 19 | 20 | export interface WebhookEventsData extends JsonApiDocument { 21 | type: string 22 | id: string 23 | attributes: WebhookEventsAttr 24 | relationships: IRelationships 25 | } 26 | 27 | export interface IWebhookEvents extends JsonApiListResponse { 28 | data: WebhookEventsData[] 29 | } 30 | 31 | export interface IWebhookEventsResult extends ResultResponse {} 32 | 33 | export type ListOptions = WithCommonOptions< 34 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 35 | > -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/WebhookSubscribers.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface WebhookSubscriberAttr { 11 | url: string 12 | active: boolean 13 | subscriptions: string[] 14 | created_at: string 15 | updated_at: string 16 | } 17 | 18 | export interface WebhookSubscriberData extends JsonApiDocument { 19 | type: string 20 | id: string 21 | attributes: WebhookSubscriberAttr 22 | relationships: IRelationships 23 | } 24 | 25 | export interface WebhookSubscriberParams { 26 | subscriber: { 27 | active: boolean 28 | subscriptions: any[] 29 | url: string 30 | } 31 | } 32 | 33 | export interface IWebhookSubscriber extends JsonApiSingleResponse { 34 | data: WebhookSubscriberData 35 | } 36 | 37 | export interface IWebhookSubscribers extends JsonApiListResponse { 38 | data: WebhookSubscriberData[] 39 | } 40 | 41 | export interface IWebhookSubscriberResult extends ResultResponse {} 42 | 43 | export interface IWebhookSubscribersResult extends ResultResponse {} 44 | 45 | export type ListOptions = WithCommonOptions< 46 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 47 | > 48 | 49 | export type ShowOptions = WithCommonOptions< 50 | { suggestToken: true; onlyAccountToken: true }, 51 | { id: string } 52 | > 53 | 54 | export type CreateOptions = WithCommonOptions< 55 | { suggestToken: true; onlyAccountToken: true }, 56 | WebhookSubscriberParams 57 | > 58 | 59 | export type UpdateOptions = WithCommonOptions< 60 | { suggestToken: true; onlyAccountToken: true }, 61 | WebhookSubscriberParams & { id: string } 62 | > 63 | 64 | export type RemoveOptions = WithCommonOptions< 65 | { suggestToken: true; onlyAccountToken: true }, 66 | { id: string } 67 | > 68 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/WishedItems.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface WishedItemAttr { 11 | quantity: number 12 | created_at: string 13 | updated_at: string 14 | display_total: string 15 | display_price: string 16 | price: string 17 | total: string 18 | } 19 | 20 | export interface WishedItemData extends JsonApiDocument { 21 | type: string 22 | id: string 23 | attributes: WishedItemAttr 24 | relationships: IRelationships 25 | } 26 | 27 | export interface WishedItemParams { 28 | wished_item: { 29 | wishlist_id: string 30 | variant_id: string 31 | quantity: number 32 | } 33 | } 34 | 35 | export interface IWishedItem extends JsonApiSingleResponse { 36 | data: WishedItemData 37 | } 38 | 39 | export interface IWishedItems extends JsonApiListResponse { 40 | data: WishedItemData[] 41 | } 42 | 43 | export interface IWishedItemResult extends ResultResponse {} 44 | 45 | export interface IWishedItemsResult extends ResultResponse {} 46 | 47 | export type ListOptions = WithCommonOptions< 48 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 49 | > 50 | 51 | export type ShowOptions = WithCommonOptions< 52 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 53 | { id: string } 54 | > 55 | 56 | export type CreateOptions = WithCommonOptions< 57 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 58 | WishedItemParams 59 | > 60 | 61 | export type UpdateOptions = WithCommonOptions< 62 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 63 | WishedItemParams & { id: string } 64 | > 65 | 66 | export type RemoveOptions = WithCommonOptions< 67 | { suggestToken: true; onlyAccountToken: true }, 68 | { id: string } 69 | > 70 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Wishlists.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface WishlistAttr { 11 | name: string 12 | is_private: boolean 13 | is_default: boolean 14 | created_at: string 15 | updated_at: string 16 | token: string 17 | variant_included: boolean 18 | } 19 | 20 | export interface WishlistData extends JsonApiDocument { 21 | type: string 22 | id: string 23 | attributes: WishlistAttr 24 | relationships: IRelationships 25 | } 26 | 27 | export interface WishlistParams { 28 | wishlist: { 29 | name: string 30 | user_id: string 31 | is_default: boolean 32 | is_private: boolean 33 | } 34 | } 35 | 36 | export interface IWishlist extends JsonApiSingleResponse { 37 | data: WishlistData 38 | } 39 | 40 | export interface IWishlists extends JsonApiListResponse { 41 | data: WishlistData[] 42 | } 43 | 44 | export interface IWishlistResult extends ResultResponse {} 45 | 46 | export interface IWishlistsResult extends ResultResponse {} 47 | 48 | export type ListOptions = WithCommonOptions< 49 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 50 | > 51 | 52 | export type ShowOptions = WithCommonOptions< 53 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 54 | { id: string } 55 | > 56 | 57 | export type CreateOptions = WithCommonOptions< 58 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 59 | WishlistParams 60 | > 61 | 62 | export type UpdateOptions = WithCommonOptions< 63 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 64 | WishlistParams & { id: string } 65 | > 66 | 67 | export type RemoveOptions = WithCommonOptions< 68 | { suggestToken: true; onlyAccountToken: true }, 69 | { id: string } 70 | > 71 | -------------------------------------------------------------------------------- /packages/sdk-platform/src/interfaces/Zones.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | ResultResponse, 7 | WithCommonOptions 8 | } from '@spree/core-api-v2-sdk' 9 | 10 | export interface ZoneAttr { 11 | name: string 12 | description: string 13 | default_tax: boolean 14 | zone_members_count: number 15 | created_at: string 16 | updated_at: string 17 | kind: string 18 | } 19 | 20 | export interface ZoneData extends JsonApiDocument { 21 | type: string 22 | id: string 23 | attributes: ZoneAttr 24 | relationships: IRelationships 25 | } 26 | 27 | export interface ZoneParams { 28 | zone: { 29 | name: string 30 | description: string 31 | default_tax: boolean 32 | kind: string 33 | } 34 | } 35 | 36 | export interface IZone extends JsonApiSingleResponse { 37 | data: ZoneData 38 | } 39 | 40 | export interface IZones extends JsonApiListResponse { 41 | data: ZoneData[] 42 | } 43 | 44 | export interface IZoneResult extends ResultResponse {} 45 | 46 | export interface IZonesResult extends ResultResponse {} 47 | 48 | export type ListOptions = WithCommonOptions< 49 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true } 50 | > 51 | 52 | export type ShowOptions = WithCommonOptions< 53 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 54 | { id: string } 55 | > 56 | 57 | export type CreateOptions = WithCommonOptions< 58 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 59 | ZoneParams 60 | > 61 | 62 | export type UpdateOptions = WithCommonOptions< 63 | { suggestToken: true; onlyAccountToken: true; suggestQuery: true }, 64 | ZoneParams & { id: string } 65 | > 66 | 67 | export type RemoveOptions = WithCommonOptions< 68 | { suggestToken: true; onlyAccountToken: true }, 69 | { id: string } 70 | > 71 | -------------------------------------------------------------------------------- /packages/sdk-platform/tsconfig-client.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es6" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-platform/tsconfig-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es2020" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-platform/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "node", 4 | "lib": ["dom", "es2016"], 5 | "noUnusedParameters": true, 6 | "sourceMap": true, 7 | "allowSyntheticDefaultImports": true, 8 | "module": "commonjs", 9 | "esModuleInterop": true, 10 | "declaration": true, 11 | "declarationDir": "./types", 12 | "importsNotUsedAsValues": "preserve" 13 | }, 14 | "references": [ 15 | { "path": "./../sdk-core" } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/sdk-platform/webpack.client.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const clientDistDirectoryPath = resolve(distDirectoryPath, 'client') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'client', 16 | target: ['web', 'es6'], 17 | output: { 18 | path: clientDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'browser'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-client.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /packages/sdk-platform/webpack.common.maker.mjs: -------------------------------------------------------------------------------- 1 | import webpack from 'webpack' 2 | import { resolve, dirname } from 'path' 3 | import { fileURLToPath } from 'url' 4 | import nodeExternals from 'webpack-node-externals' 5 | import ProgressBar from './../../webpack-plugins/ProgressBar.mjs' 6 | import DeleteBeforeRun from './../../webpack-plugins/DeleteBeforeRun.mjs' 7 | 8 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 9 | const __dirname = dirname(fileURLToPath(import.meta.url)) 10 | const baseDirectoryPath = __dirname 11 | const srcDirectoryPath = resolve(baseDirectoryPath, 'src') 12 | const { WatchIgnorePlugin } = webpack 13 | 14 | export default ({ typeScriptConfigFilePath }) => ({ 15 | context: baseDirectoryPath, 16 | plugins: [ 17 | new ProgressBar(), 18 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'dist')), 19 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'types')), 20 | new WatchIgnorePlugin({ paths: [resolve(baseDirectoryPath, 'types')] }) 21 | ], 22 | entry: { 23 | index: { 24 | import: resolve(srcDirectoryPath, 'index.ts'), 25 | library: { 26 | name: 'SpreePlatformSDK', 27 | type: 'umd' 28 | } 29 | }, 30 | }, 31 | output: { 32 | filename: '[name].js' 33 | }, 34 | mode: 'production', 35 | devtool: 'source-map', 36 | module: { 37 | rules: [ 38 | { 39 | test: /\.tsx?$/, 40 | loader: 'ts-loader', 41 | exclude: /node_modules/, 42 | include: srcDirectoryPath, 43 | options: { 44 | configFile: typeScriptConfigFilePath, 45 | onlyCompileBundledFiles: true 46 | } 47 | }, 48 | { 49 | test: /\.js$/, 50 | loader: 'source-map-loader', 51 | include: /node_modules/, 52 | enforce: 'pre' 53 | } 54 | ] 55 | }, 56 | resolveLoader: { 57 | modules: [srcDirectoryPath, 'node_modules'] 58 | }, 59 | resolve: { 60 | symlinks: false, 61 | extensions: ['.tsx', '.ts', '.js'] 62 | }, 63 | externals: [ 64 | nodeExternals({ 65 | allowlist: ['@spree/core-api-v2-sdk'], 66 | modulesFromFile: { 67 | excludeFromBundle: ['devDependencies'], 68 | includeInBundle: ['dependencies'] 69 | } 70 | }) 71 | ] 72 | }) 73 | -------------------------------------------------------------------------------- /packages/sdk-platform/webpack.config.mjs: -------------------------------------------------------------------------------- 1 | import serverConfig from './webpack.server.mjs' 2 | import clientConfig from './webpack.client.mjs' 3 | 4 | export default [serverConfig, clientConfig] 5 | -------------------------------------------------------------------------------- /packages/sdk-platform/webpack.server.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const serverDistDirectoryPath = resolve(distDirectoryPath, 'server') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'server', 16 | target: 'node14', 17 | output: { 18 | path: serverDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'node'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-server.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /packages/sdk-storefront/README.md: -------------------------------------------------------------------------------- 1 | Spree Storefront API SDK contains each endpoint according to [Spree Guides](https://api.spreecommerce.org/docs/api-v2/c230c08afa8e4-storefront-api). -------------------------------------------------------------------------------- /packages/sdk-storefront/rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import dts from 'rollup-plugin-dts' 2 | 3 | export default { 4 | input: './types/index.d.ts', 5 | output: [{ file: 'dist/index.d.ts', format: 'es' }], 6 | plugins: [dts({ 7 | respectExternal: true 8 | })], 9 | } 10 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/endpoints/Order.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Http, 3 | squashAndPreparePositionalArguments 4 | } from '@spree/core-api-v2-sdk' 5 | import type { 6 | IQuery, 7 | IToken 8 | } from '@spree/core-api-v2-sdk' 9 | import type { IOrder, IOrderResult, StatusOptions } from '../interfaces/Order' 10 | import routes from '../routes' 11 | 12 | export default class Order extends Http { 13 | /** 14 | * Returns a placed Order. 15 | * 16 | * **Required token:** [Order token](../pages/tokens.html#order-token) 17 | * 18 | * **Options schema:** 19 | * ```ts 20 | * interface options { 21 | * order_number: string 22 | * } 23 | * ``` 24 | * 25 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 26 | * 27 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 28 | * 29 | * **Example:** 30 | * ```ts 31 | * const response = await client.order.status({ 32 | * order_token: '7381273269536713689562374856', 33 | * order_number: 'R653163382' 34 | * }) 35 | * ``` 36 | */ 37 | public async status(options: StatusOptions): Promise 38 | /** 39 | * @hidden 40 | * @deprecated Use the combined options signature instead. 41 | */ 42 | public async status(token: IToken, orderNumber: string, params?: IQuery): Promise 43 | public async status(...allArguments: any[]): Promise { 44 | const [tokenOrOptions, positionalOrderNumber, positionalParams = {}] = allArguments 45 | const { order_number, token, params } = squashAndPreparePositionalArguments( 46 | [tokenOrOptions, { order_number: positionalOrderNumber }, positionalParams], 47 | ['order_number'] 48 | ) 49 | 50 | return await this.spreeResponse('get', routes.orderStatusPath(order_number), token, params) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/endpoints/Vendors.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Http, 3 | squashAndPreparePositionalArguments 4 | } from '@spree/core-api-v2-sdk' 5 | import type { 6 | ListOptions, 7 | ShowOptions, 8 | VendorResult, 9 | VendorsResult, 10 | Vendors as VendorsType, 11 | Vendor 12 | } from '../interfaces/Vendor' 13 | import routes from '../routes' 14 | 15 | /** 16 | * The multi-vendor marketplace feature is only available via [Vendo](https://www.getvendo.com). 17 | */ 18 | export default class Vendors extends Http { 19 | /** 20 | * Returns a list of Vendors in a Spree marketplace. 21 | * 22 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 23 | * 24 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 25 | * 26 | * **Example:** 27 | * ```ts 28 | * const vendors = await client.vendors.list({ 29 | * include: 'products' 30 | * }) 31 | * ``` 32 | */ 33 | public async list(options: ListOptions = {}): Promise { 34 | const { token, params } = squashAndPreparePositionalArguments([options], []) 35 | 36 | return await this.spreeResponse('get', routes.vendorsPath(), token, params) 37 | } 38 | 39 | /** 40 | * Returns a single Vendor in a Spree marketplace. 41 | * 42 | * **Options schema:** 43 | * ```ts 44 | * interface options { 45 | * id: string 46 | * } 47 | * ``` 48 | * 49 | * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) 50 | * 51 | * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) 52 | * 53 | * **Example:** 54 | * ```ts 55 | * const vendor = await client.vendors.show({ id: '123' }) 56 | * ``` 57 | */ 58 | public async show(options: ShowOptions): Promise { 59 | const { id, token, params } = squashAndPreparePositionalArguments([options], ['id']) 60 | 61 | return await this.spreeResponse('get', routes.vendorPath(id), token, params) 62 | } 63 | } -------------------------------------------------------------------------------- /packages/sdk-storefront/src/endpoints/index.ts: -------------------------------------------------------------------------------- 1 | import Account from './Account' 2 | import Authentication from './Authentication' 3 | import Cart from './Cart' 4 | import Checkout from './Checkout' 5 | import Countries from './Countries' 6 | import DigitalAssets from './DigitalAssets' 7 | import Menus from './Menus' 8 | import Order from './Order' 9 | import Pages from './Pages' 10 | import Products from './Products' 11 | import Taxons from './Taxons' 12 | import Vendors from './Vendors' 13 | import Wishlists from './Wishlists' 14 | 15 | export { 16 | Account, 17 | Authentication, 18 | Cart, 19 | Checkout, 20 | Countries, 21 | DigitalAssets, 22 | Menus, 23 | Order, 24 | Pages, 25 | Products, 26 | Taxons, 27 | Vendors, 28 | Wishlists 29 | } 30 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/helpers/auth.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AuthTokenAttr, 3 | AuthTokenParams, 4 | RefreshTokenAttr, 5 | RefreshTokenParams, 6 | RevokeTokenAttr, 7 | RevokeTokenParams 8 | } from '../interfaces/Authentication' 9 | 10 | export const authParams = ({ username, password }: AuthTokenAttr): AuthTokenParams => ({ 11 | username, 12 | password, 13 | grant_type: 'password' 14 | }) 15 | 16 | export const refreshParams = ({ refresh_token }: RefreshTokenAttr): RefreshTokenParams => ({ 17 | refresh_token, 18 | grant_type: 'refresh_token' 19 | }) 20 | 21 | export const revokeParams = ({ token }: RevokeTokenAttr): RevokeTokenParams => ({ 22 | token 23 | }) 24 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Authentication.ts: -------------------------------------------------------------------------------- 1 | import { WithCommonOptions } from '@spree/core-api-v2-sdk' 2 | 3 | export interface AuthTokenAttr { 4 | username: string 5 | password: string 6 | } 7 | 8 | export interface RefreshTokenAttr { 9 | refresh_token: string 10 | } 11 | 12 | export interface RevokeTokenAttr { 13 | token: string 14 | } 15 | 16 | export interface AuthTokenParams { 17 | username: string 18 | password: string 19 | grant_type: 'password' 20 | } 21 | 22 | export interface RefreshTokenParams { 23 | refresh_token: string 24 | grant_type: 'refresh_token' 25 | } 26 | 27 | export interface RevokeTokenParams { 28 | token: string 29 | } 30 | 31 | export type GetTokenOptions = WithCommonOptions 32 | 33 | export type RefreshTokenOptions = WithCommonOptions 34 | 35 | export type RevokeTokenOptions = WithCommonOptions 36 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Cart.ts: -------------------------------------------------------------------------------- 1 | import type { WithCommonOptions } from '@spree/core-api-v2-sdk' 2 | 3 | import type * as RestCheckoutTypes from './endpoints/CartClass' 4 | 5 | export * from './endpoints/CartClass' 6 | 7 | export type ShowOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 8 | 9 | export type CreateOptions = WithCommonOptions<{ 10 | suggestToken: true 11 | onlyAccountToken: true 12 | optionalToken: true 13 | suggestQuery: true 14 | }> 15 | 16 | export type AddItemOptions = WithCommonOptions< 17 | { 18 | suggestToken: true 19 | suggestQuery: true 20 | }, 21 | RestCheckoutTypes.AddItem 22 | > 23 | 24 | export type RemoveItemOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }, { id: string }> 25 | 26 | export type EmptyCartOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 27 | 28 | export type RemoveOptions = WithCommonOptions<{ suggestToken: true }> 29 | 30 | export type SetQuantityOptions = WithCommonOptions< 31 | { suggestToken: true; suggestQuery: true }, 32 | RestCheckoutTypes.SetQuantity 33 | > 34 | 35 | export type ApplyCouponCodeOptions = WithCommonOptions< 36 | { suggestToken: true; suggestQuery: true }, 37 | RestCheckoutTypes.CouponCode 38 | > 39 | 40 | export type RemoveCouponCodeOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }, { code?: string }> 41 | 42 | export type RemoveAllCouponsOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 43 | 44 | export type EstimateShippingRatesOptions = WithCommonOptions< 45 | { suggestToken: true; suggestQuery: true }, 46 | RestCheckoutTypes.EstimateShippingRates 47 | > 48 | 49 | export type AssociateGuestCartOptions = WithCommonOptions< 50 | { suggestToken: true; suggestQuery: true }, 51 | RestCheckoutTypes.AssociateCart 52 | > 53 | 54 | export type ChangeCurrencyOptions = WithCommonOptions< 55 | { suggestToken: true; suggestQuery: true }, 56 | RestCheckoutTypes.ChangeCurrency 57 | > 58 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Checkout.ts: -------------------------------------------------------------------------------- 1 | import type { WithCommonOptions } from '@spree/core-api-v2-sdk' 2 | 3 | import type * as RestCheckoutTypes from './endpoints/CheckoutClass' 4 | 5 | export * from './endpoints/CheckoutClass' 6 | 7 | export type CreateStripeSessionOptions = WithCommonOptions< 8 | { suggestToken: true }, 9 | { 10 | success_url: string 11 | cancel_url: string 12 | } 13 | > 14 | 15 | export type AddPaymentOptions = WithCommonOptions< 16 | { suggestToken: true; suggestQuery: true }, 17 | RestCheckoutTypes.AddFullPayment & { 18 | source_id?: string 19 | amount?: number 20 | } 21 | > 22 | 23 | export type SelectShippingMethodOptions = WithCommonOptions< 24 | { suggestToken: true; suggestQuery: true }, 25 | { 26 | shipping_method_id: string 27 | shipment_id?: string 28 | } 29 | > 30 | 31 | export type ShippingRatesOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 32 | 33 | export type PaymentMethodsOptions = WithCommonOptions<{ suggestToken: true }> 34 | 35 | export type RemoveStoreCreditsOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 36 | 37 | export type AddStoreCreditOptions = WithCommonOptions< 38 | { suggestToken: true; suggestQuery: true }, 39 | { 40 | amount: number 41 | } 42 | > 43 | 44 | export type CompleteOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 45 | 46 | export type AdvanceOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 47 | 48 | export type OrderUpdateOptions = WithCommonOptions< 49 | { suggestToken: true; suggestQuery: true }, 50 | RestCheckoutTypes.OrderUpdate 51 | > 52 | 53 | export type OrderNextOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }> 54 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Country.ts: -------------------------------------------------------------------------------- 1 | import type { JsonApiDocument, JsonApiListResponse, JsonApiSingleResponse } from '@spree/core-api-v2-sdk' 2 | import type { IRelationships } from '@spree/core-api-v2-sdk' 3 | import type { ResultResponse } from '@spree/core-api-v2-sdk' 4 | import type { WithCommonOptions } from '@spree/core-api-v2-sdk' 5 | 6 | export interface CountryAttr extends JsonApiDocument { 7 | type: string 8 | id: string 9 | attributes: { 10 | iso: string 11 | iso3: string 12 | iso_name: string 13 | name: string 14 | states_required: boolean 15 | zipcode_required: boolean 16 | default: boolean 17 | } 18 | 19 | relationships: IRelationships 20 | } 21 | 22 | export interface ICountry extends JsonApiSingleResponse { 23 | data: CountryAttr 24 | } 25 | 26 | export interface ICountries extends JsonApiListResponse { 27 | data: CountryAttr[] 28 | } 29 | 30 | export interface ICountryResult extends ResultResponse {} 31 | 32 | export interface ICountriesResult extends ResultResponse {} 33 | 34 | export type ListOptions = WithCommonOptions 35 | 36 | export type ShowOptions = WithCommonOptions<{ suggestQuery: true }, { iso: string }> 37 | 38 | export type DefaultOptions = WithCommonOptions<{ suggestQuery: true }> 39 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/CreditCard.ts: -------------------------------------------------------------------------------- 1 | import { JsonApiDocument, JsonApiListResponse, JsonApiSingleResponse } from '@spree/core-api-v2-sdk' 2 | import { IRelationships } from '@spree/core-api-v2-sdk' 3 | import { ResultResponse } from '@spree/core-api-v2-sdk' 4 | 5 | export interface CreditCardAttr extends JsonApiDocument { 6 | type: string 7 | id: string 8 | attributes: { 9 | cc_type: string 10 | last_digits: string 11 | month: number 12 | year: number 13 | name: string 14 | default: boolean 15 | } 16 | relationships: IRelationships 17 | } 18 | 19 | export interface ICreditCard extends JsonApiSingleResponse { 20 | data: CreditCardAttr 21 | } 22 | 23 | export interface ICreditCards extends JsonApiListResponse { 24 | data: CreditCardAttr[] 25 | } 26 | 27 | export interface ICreditCardResult extends ResultResponse {} 28 | 29 | export interface ICreditCardsResult extends ResultResponse {} 30 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/DigitalAsset.ts: -------------------------------------------------------------------------------- 1 | import { ResultResponse } from '@spree/core-api-v2-sdk' 2 | import { WithCommonOptions } from '@spree/core-api-v2-sdk' 3 | 4 | export interface DigitalAsset extends ReadableStream {} 5 | 6 | export interface DigitalAssetResult extends ResultResponse {} 7 | 8 | export type DownloadOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }, { asset_token: string }> 9 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/EstimatedShippingMethod.ts: -------------------------------------------------------------------------------- 1 | import { JsonApiDocument, JsonApiListResponse } from '@spree/core-api-v2-sdk' 2 | import { ResultResponse } from '@spree/core-api-v2-sdk' 3 | 4 | export interface EstimatedShippingMethodAttr extends JsonApiDocument { 5 | type: 'shipping_rate' 6 | id: string 7 | attributes: { 8 | name: string 9 | selected: boolean 10 | cost: string 11 | tax_amount: string 12 | shipping_method_id: number 13 | final_price: string 14 | display_cost: string 15 | display_final_price: string 16 | display_tax_amount: string 17 | free: boolean 18 | } 19 | } 20 | 21 | /** 22 | * @deprecated Use {@link EstimatedShippingRates} instead. 23 | */ 24 | export interface IEstimatedShippingMethods extends JsonApiListResponse { 25 | data: EstimatedShippingMethodAttr[] 26 | } 27 | 28 | /** 29 | * @deprecated Use {@link EstimatedShippingRatesResult} instead. 30 | */ 31 | export interface IEstimatedShippingMethodsResult extends ResultResponse {} 32 | 33 | export interface EstimatedShippingRates extends JsonApiListResponse { 34 | data: EstimatedShippingMethodAttr[] 35 | } 36 | 37 | export interface EstimatedShippingRatesResult extends ResultResponse {} 38 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Menu.ts: -------------------------------------------------------------------------------- 1 | import { JsonApiDocument, JsonApiListResponse, JsonApiSingleResponse } from '@spree/core-api-v2-sdk' 2 | import { IQuery } from '@spree/core-api-v2-sdk' 3 | import { IRelationships } from '@spree/core-api-v2-sdk' 4 | import { ResultResponse } from '@spree/core-api-v2-sdk' 5 | import { WithCommonOptions } from '@spree/core-api-v2-sdk' 6 | 7 | export interface MenuAttr extends JsonApiDocument { 8 | type: string 9 | id: string 10 | attributes: { 11 | name: string 12 | location: 'header' | 'footer' | string 13 | locale: string 14 | } 15 | relationships: IRelationships 16 | } 17 | 18 | export interface Menu extends JsonApiSingleResponse { 19 | data: MenuAttr 20 | } 21 | 22 | export interface Menus extends JsonApiListResponse { 23 | data: MenuAttr[] 24 | } 25 | 26 | export interface MenuResult extends ResultResponse {} 27 | 28 | export interface MenusResult extends ResultResponse {} 29 | 30 | /** 31 | * @deprecated Use {@link ListOptions} instead. 32 | */ 33 | export interface MenusList extends IQuery { 34 | locale?: string 35 | filter?: IQuery['filter'] & { 36 | location?: string 37 | } 38 | } 39 | 40 | export type ListOptions = WithCommonOptions<{ suggestQuery: true }, MenusList> 41 | 42 | export type ShowOptions = WithCommonOptions<{ suggestQuery: true }, { id: string }> 43 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Order.ts: -------------------------------------------------------------------------------- 1 | import { JsonApiDocument, JsonApiListResponse, JsonApiSingleResponse } from '@spree/core-api-v2-sdk' 2 | import { IRelationships } from '@spree/core-api-v2-sdk' 3 | import { ResultResponse } from '@spree/core-api-v2-sdk' 4 | import { WithCommonOptions } from '@spree/core-api-v2-sdk' 5 | 6 | export interface OrderAttr extends JsonApiDocument { 7 | type: string 8 | id: string 9 | attributes: { 10 | number: string 11 | item_total: string 12 | total: string 13 | ship_total: string 14 | adjustment_total: string 15 | included_tax_total: string 16 | additional_tax_total: string 17 | display_additional_tax_total: string 18 | display_included_tax_total: string 19 | tax_total: string 20 | currency: string 21 | state: string 22 | token: string 23 | email: string 24 | display_item_total: string 25 | display_ship_total: string 26 | display_adjustment_total: string 27 | display_tax_total: string 28 | promo_total: string 29 | display_promo_total: string 30 | item_count: number 31 | special_instructions: string 32 | display_total: string 33 | created_at: Date 34 | updated_at: Date 35 | completed_at: Date 36 | } 37 | 38 | relationships: IRelationships 39 | } 40 | 41 | export interface IOrder extends JsonApiSingleResponse { 42 | data: OrderAttr 43 | } 44 | 45 | export interface IOrders extends JsonApiListResponse { 46 | data: OrderAttr[] 47 | } 48 | 49 | export interface IOrderResult extends ResultResponse {} 50 | 51 | export interface IOrdersResult extends ResultResponse {} 52 | 53 | export type StatusOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true }, { order_number: string }> 54 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Page.ts: -------------------------------------------------------------------------------- 1 | import { JsonApiDocument, JsonApiListResponse, JsonApiSingleResponse } from '@spree/core-api-v2-sdk' 2 | import { IRelationships } from '@spree/core-api-v2-sdk' 3 | import { ResultResponse } from '@spree/core-api-v2-sdk' 4 | import { WithCommonOptions } from '@spree/core-api-v2-sdk' 5 | 6 | export interface PageAttr extends JsonApiDocument { 7 | type: string 8 | id: string 9 | attributes: { 10 | title: string 11 | content: string 12 | locale: string 13 | meta_description: string | null 14 | meta_title: string | null 15 | slug: string 16 | type: string 17 | } 18 | relationships: IRelationships 19 | } 20 | 21 | export interface IPage extends JsonApiSingleResponse { 22 | data: PageAttr 23 | } 24 | 25 | export interface IPages extends JsonApiListResponse { 26 | data: PageAttr[] 27 | } 28 | 29 | export interface IPageResult extends ResultResponse {} 30 | 31 | export interface IPagesResult extends ResultResponse {} 32 | 33 | export type ListOptions = WithCommonOptions<{ suggestQuery: true }> 34 | 35 | export type ShowOptions = WithCommonOptions<{ suggestQuery: true }, { id: string }> 36 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/PaymentMethod.ts: -------------------------------------------------------------------------------- 1 | import { JsonApiDocument, JsonApiListResponse } from '@spree/core-api-v2-sdk' 2 | import { ResultResponse } from '@spree/core-api-v2-sdk' 3 | 4 | export interface PaymentMethodAttr extends JsonApiDocument { 5 | type: string 6 | id: string 7 | attributes: { 8 | type: string 9 | name: string 10 | description: string 11 | preferences: { 12 | [key: string]: string 13 | } 14 | } 15 | } 16 | 17 | export interface IPaymentMethods extends JsonApiListResponse { 18 | data: PaymentMethodAttr[] 19 | } 20 | 21 | export interface IPaymentMethodsResult extends ResultResponse {} 22 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Product.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | WithCommonOptions, 3 | ImageTransformation, 4 | JsonApiDocument, 5 | JsonApiListResponse, 6 | JsonApiSingleResponse, 7 | IRelationships, 8 | LocalizedSlugs, 9 | ResultResponse 10 | } from '@spree/core-api-v2-sdk' 11 | 12 | export interface ProductAttr extends JsonApiDocument { 13 | type: string 14 | id: string 15 | attributes: { 16 | name: string 17 | description: string 18 | available_on: string 19 | slug: string 20 | meta_description: string | null 21 | meta_keywords: string | null 22 | updated_at: string 23 | sku: string 24 | purchasable: boolean 25 | in_stock: boolean 26 | backorderable: boolean 27 | available: boolean 28 | currency: string 29 | price: string 30 | display_price: string 31 | compare_at_price: string | null 32 | display_compare_at_price: string | null 33 | localized_slugs: LocalizedSlugs 34 | } 35 | relationships: IRelationships 36 | } 37 | 38 | export interface IProduct extends JsonApiSingleResponse { 39 | data: ProductAttr 40 | } 41 | 42 | export interface IProducts extends JsonApiListResponse { 43 | data: ProductAttr[] 44 | } 45 | 46 | export interface IProductResult extends ResultResponse {} 47 | 48 | export interface IProductsResult extends ResultResponse {} 49 | 50 | export type ListOptions = WithCommonOptions< 51 | { suggestToken: true; suggestQuery: true; optionalToken: true }, 52 | { 53 | image_transformation?: ImageTransformation 54 | } 55 | > 56 | 57 | export type ShowOptions = WithCommonOptions< 58 | { suggestToken: true; suggestQuery: true; optionalToken: true }, 59 | { id: string; image_transformation?: ImageTransformation } 60 | > 61 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/ShippingMethod.ts: -------------------------------------------------------------------------------- 1 | import { JsonApiDocument, JsonApiListResponse } from '@spree/core-api-v2-sdk' 2 | import { IRelationships } from '@spree/core-api-v2-sdk' 3 | import { ResultResponse } from '@spree/core-api-v2-sdk' 4 | 5 | /** 6 | * @deprecated Use {@link ShippingRateAttr} instead. 7 | */ 8 | export interface ShippingMethodAttr extends JsonApiDocument { 9 | type: string 10 | id: string 11 | attributes: { 12 | number: string 13 | free: boolean 14 | final_price: string 15 | display_final_price: string 16 | tracking_url: string 17 | state: string 18 | shipped_at: Date 19 | } 20 | relationships: IRelationships 21 | } 22 | 23 | /** 24 | * @deprecated Use {@link ShippingRates} instead. 25 | */ 26 | export interface IShippingMethods extends JsonApiListResponse { 27 | data: ShippingMethodAttr[] 28 | } 29 | 30 | /** 31 | * @deprecated Use {@link ShippingRatesResult} instead. 32 | */ 33 | export interface IShippingMethodsResult extends ResultResponse {} 34 | 35 | export interface ShippingRateAttr extends JsonApiDocument { 36 | type: string 37 | id: string 38 | attributes: { 39 | number: string 40 | free: boolean 41 | final_price: string 42 | display_final_price: string 43 | tracking_url: string 44 | state: string 45 | shipped_at: Date 46 | } 47 | relationships: IRelationships 48 | } 49 | 50 | export interface ShippingRates extends JsonApiListResponse { 51 | data: ShippingRateAttr[] 52 | } 53 | 54 | export interface ShippingRatesResult extends ResultResponse {} 55 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/StripeCheckoutSessionSummary.ts: -------------------------------------------------------------------------------- 1 | import type { ResultResponse } from '@spree/core-api-v2-sdk' 2 | 3 | export type StripeCheckoutSessionSummary = { 4 | session_id: string 5 | session_url: string 6 | } 7 | 8 | export type StripeCheckoutSessionSummaryResult = ResultResponse 9 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Taxon.ts: -------------------------------------------------------------------------------- 1 | import { 2 | JsonApiDocument, 3 | JsonApiListResponse, 4 | JsonApiSingleResponse, 5 | IRelationships, 6 | LocalizedSlugs, 7 | ResultResponse, 8 | WithCommonOptions 9 | } from '@spree/core-api-v2-sdk' 10 | 11 | export interface TaxonAttr extends JsonApiDocument { 12 | type: string 13 | id: string 14 | attributes: { 15 | name: string 16 | pretty_name: string 17 | permalink: string 18 | seo_title: string 19 | meta_title: string | null 20 | meta_description: string | null 21 | meta_keywords: string | null 22 | left: number 23 | right: number 24 | position: number 25 | depth: number 26 | is_root: boolean 27 | is_child: boolean 28 | is_leaf: string 29 | localized_slugs: LocalizedSlugs 30 | updated_at: Date 31 | } 32 | 33 | relationships: IRelationships 34 | } 35 | 36 | export interface ITaxon extends JsonApiSingleResponse { 37 | data: TaxonAttr 38 | } 39 | 40 | export interface ITaxons extends JsonApiListResponse { 41 | data: TaxonAttr[] 42 | } 43 | 44 | export interface ITaxonResult extends ResultResponse {} 45 | 46 | export interface ITaxonsResult extends ResultResponse {} 47 | 48 | export type ListOptions = WithCommonOptions<{ suggestQuery: true }> 49 | 50 | export type ShowOptions = WithCommonOptions<{ suggestQuery: true }, { id: string }> 51 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/Vendor.ts: -------------------------------------------------------------------------------- 1 | import type { JsonApiDocument, JsonApiListResponse, JsonApiSingleResponse } from '@spree/core-api-v2-sdk' 2 | import type { IRelationships } from '@spree/core-api-v2-sdk' 3 | import type { ResultResponse } from '@spree/core-api-v2-sdk' 4 | import type { WithCommonOptions } from '@spree/core-api-v2-sdk' 5 | 6 | export interface VendorAttr extends JsonApiDocument { 7 | type: string 8 | id: string 9 | attributes: { 10 | name: string 11 | slug: string 12 | instagram: string | null 13 | facebook: string | null 14 | twitter: string | null 15 | about_us: string | null 16 | logo_url: string | null 17 | logo_small_url: string | null 18 | logo_medium_url: string | null 19 | logo_large_url: string | null 20 | cover_photo_url: string | null 21 | cover_photo_small_url: string | null 22 | cover_photo_medium_url: string | null 23 | cover_photo_large_url: string | null 24 | } 25 | relationships: IRelationships 26 | } 27 | 28 | export interface Vendor extends JsonApiSingleResponse { 29 | data: VendorAttr 30 | } 31 | 32 | export interface Vendors extends JsonApiListResponse { 33 | data: VendorAttr[] 34 | } 35 | 36 | export interface VendorResult extends ResultResponse {} 37 | 38 | export interface VendorsResult extends ResultResponse {} 39 | 40 | export type ListOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; optionalToken: true }> 41 | 42 | export type ShowOptions = WithCommonOptions< 43 | { suggestToken: true; suggestQuery: true; optionalToken: true }, 44 | { id: string } 45 | > 46 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/WishedItem.ts: -------------------------------------------------------------------------------- 1 | import type { JsonApiDocument, JsonApiSingleResponse } from '@spree/core-api-v2-sdk' 2 | import type { IQuery } from '@spree/core-api-v2-sdk' 3 | import type { IRelationships } from '@spree/core-api-v2-sdk' 4 | import type { ResultResponse } from '@spree/core-api-v2-sdk' 5 | import type { WithCommonOptions } from '@spree/core-api-v2-sdk' 6 | 7 | export interface WishedItemAttr extends JsonApiDocument { 8 | type: string 9 | id: string 10 | attributes: { 11 | variant_id: string 12 | quantity: number 13 | } 14 | relationships: IRelationships 15 | } 16 | 17 | export interface WishedItem extends JsonApiSingleResponse { 18 | data: WishedItemAttr 19 | } 20 | 21 | export interface WishedItemResult extends ResultResponse {} 22 | 23 | /** 24 | * @deprecated Use {@link AddWishedItemOptions} instead. 25 | */ 26 | export interface WishlistsAddWishedItem extends IQuery { 27 | variant_id: string 28 | quantity: number 29 | } 30 | 31 | /** 32 | * @deprecated Use {@link UpdateWishedItemOptions} instead. 33 | */ 34 | export interface WishlistsUpdateWishedItem extends IQuery { 35 | quantity: number 36 | } 37 | 38 | export type AddWishedItemOptions = WithCommonOptions< 39 | { suggestToken: true; suggestQuery: true }, 40 | { wishlist_token: string } & WishlistsAddWishedItem 41 | > 42 | 43 | export type UpdateWishedItemOptions = WithCommonOptions< 44 | { suggestToken: true; suggestQuery: true }, 45 | { wishlist_token: string; id: string } & WishlistsUpdateWishedItem 46 | > 47 | 48 | export type RemoveWishedItemOptions = WithCommonOptions<{ suggestToken: true }, { wishlist_token: string; id: string }> 49 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/attributes/Address.ts: -------------------------------------------------------------------------------- 1 | export interface IAddress { 2 | firstname: string 3 | lastname: string 4 | address1: string 5 | address2?: string 6 | city: string 7 | zipcode: string 8 | state_name: string 9 | country_iso: string 10 | phone?: string 11 | company?: string 12 | } 13 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/attributes/Payment.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @deprecated This type is no longer used 3 | */ 4 | 5 | export interface IPayment { 6 | payment_method_id: string 7 | } 8 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/attributes/PaymentSource.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @deprecated This type is no longer used 3 | */ 4 | 5 | export interface IPaymentSource { 6 | [key: string]: { 7 | gateway_payment_profile_id?: string 8 | number?: string 9 | last_digits?: number 10 | month: number | string 11 | year: number | string 12 | verification_value?: string 13 | cc_type?: string 14 | name: string 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/attributes/Shipment.ts: -------------------------------------------------------------------------------- 1 | export interface IShipment { 2 | id: string 3 | selected_shipping_rate_id: string 4 | } 5 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/endpoints/CartClass.ts: -------------------------------------------------------------------------------- 1 | // IMPORTANT: Place all new checkout types inside src/interfaces/Cart instead of this file. 2 | // TODO: Transfer all existing types inside this file to src/interfaces/Cart. 3 | 4 | import { IQuery } from '@spree/core-api-v2-sdk' 5 | 6 | /** 7 | * @deprecated Use {@link AddItemOptions} instead. 8 | */ 9 | export interface AddItem extends IQuery { 10 | variant_id: string 11 | quantity: number 12 | options?: { 13 | [key: string]: string 14 | } 15 | } 16 | 17 | /** 18 | * @deprecated Use {@link SetQuantityOptions} instead. 19 | */ 20 | export interface SetQuantity extends IQuery { 21 | line_item_id: string 22 | quantity: number 23 | } 24 | 25 | /** 26 | * @deprecated Use {@link ApplyCouponCodeOptions} instead. 27 | */ 28 | export interface CouponCode extends IQuery { 29 | coupon_code: string 30 | } 31 | 32 | /** 33 | * @deprecated Use {@link EstimateShippingRates} instead. 34 | */ 35 | export interface EstimateShippingMethods extends IQuery { 36 | country_iso: string 37 | } 38 | 39 | /** 40 | * @deprecated Use {@link EstimateShippingRatesOptions} instead. 41 | */ 42 | export interface EstimateShippingRates extends IQuery { 43 | country_iso: string 44 | } 45 | 46 | /** 47 | * @deprecated Use {@link AssociateGuestCartOptions} instead. 48 | */ 49 | export interface AssociateCart extends IQuery { 50 | guest_order_token: string 51 | } 52 | 53 | /** 54 | * @deprecated Use {@link ChangeCurrencyOptions} instead. 55 | */ 56 | export interface ChangeCurrency extends IQuery { 57 | new_currency: string 58 | } 59 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/interfaces/endpoints/CheckoutClass.ts: -------------------------------------------------------------------------------- 1 | // IMPORTANT: Place all new checkout types inside src/interfaces/Checkout instead of this file. 2 | // TODO: Transfer all existing types inside this file to src/interfaces/Checkout. 3 | 4 | import { IAddress } from '../attributes/Address' 5 | import { IPayment } from '../attributes/Payment' 6 | import { IPaymentSource } from '../attributes/PaymentSource' 7 | import { IShipment } from '../attributes/Shipment' 8 | import { IQuery } from '@spree/core-api-v2-sdk' 9 | 10 | /** 11 | * @deprecated Use {@link AddStoreCreditOptions} instead. 12 | */ 13 | export interface AddStoreCredit extends IQuery { 14 | amount: number 15 | } 16 | 17 | /** 18 | * @deprecated Use {@link OrderUpdateOptions} instead. 19 | */ 20 | export interface OrderUpdate extends IQuery { 21 | order?: { 22 | email?: string 23 | special_instructions?: string 24 | bill_address_attributes?: IAddress 25 | ship_address_attributes?: IAddress 26 | payments_attributes?: AddFullPayment[] 27 | shipments_attributes?: IShipment[] 28 | } 29 | } 30 | 31 | /** 32 | * @deprecated This type is no longer used 33 | */ 34 | export interface NestedAttributes extends IQuery { 35 | order?: { 36 | email?: string 37 | special_instructions?: string 38 | bill_address_attributes?: IAddress 39 | ship_address_attributes?: IAddress 40 | payments_attributes?: IPayment[] 41 | shipments_attributes?: IShipment[] 42 | } 43 | payment_source?: IPaymentSource 44 | } 45 | 46 | export interface AddFullPayment { 47 | payment_method_id: string 48 | source_attributes?: { 49 | gateway_payment_profile_id: string 50 | cc_type?: string 51 | last_digits?: string 52 | month?: string 53 | year?: string 54 | name: string 55 | } 56 | } 57 | 58 | /** 59 | * @deprecated Use {@link SelectShippingMethodOptions} instead. 60 | */ 61 | export interface SelectShippingMethod extends IQuery { 62 | shipping_method_id: string 63 | shipment_id?: string 64 | } 65 | 66 | /** 67 | * @deprecated Use {@link AddPaymentOptions} instead. 68 | */ 69 | export interface AddPayment extends AddFullPayment, IQuery { 70 | source_id?: string 71 | amount?: number 72 | } 73 | -------------------------------------------------------------------------------- /packages/sdk-storefront/src/makeClient.ts: -------------------------------------------------------------------------------- 1 | import { Client as CoreClient } from '@spree/core-api-v2-sdk' 2 | import type { IClientConfig } from '@spree/core-api-v2-sdk' 3 | import { 4 | Account, 5 | Authentication, 6 | Cart, 7 | Checkout, 8 | Countries, 9 | DigitalAssets, 10 | Menus, 11 | Order, 12 | Pages, 13 | Products, 14 | Taxons, 15 | Vendors, 16 | Wishlists 17 | } from './endpoints' 18 | 19 | const endpoints = { 20 | account: Account, 21 | authentication: Authentication, 22 | cart: Cart, 23 | checkout: Checkout, 24 | countries: Countries, 25 | digitalAssets: DigitalAssets, 26 | menus: Menus, 27 | order: Order, 28 | pages: Pages, 29 | products: Products, 30 | taxons: Taxons, 31 | vendors: Vendors, 32 | wishlists: Wishlists 33 | } 34 | 35 | type Endpoints = { 36 | [key in keyof typeof endpoints]: InstanceType 37 | } 38 | type Client = CoreClient & Endpoints 39 | 40 | const makeClient = (config: IClientConfig): Client => new CoreClient(config, endpoints) as Client 41 | 42 | export type { Client, Endpoints } 43 | export default makeClient 44 | -------------------------------------------------------------------------------- /packages/sdk-storefront/tsconfig-client.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es6" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-storefront/tsconfig-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es2020" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/sdk-storefront/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "node", 4 | "lib": ["dom", "es2016"], 5 | "noUnusedParameters": true, 6 | "sourceMap": true, 7 | "allowSyntheticDefaultImports": true, 8 | "module": "commonjs", 9 | "esModuleInterop": true, 10 | "declaration": true, 11 | "declarationDir": "./types", 12 | "importsNotUsedAsValues": "preserve" 13 | }, 14 | "references": [ 15 | { "path": "./../sdk-core" } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/sdk-storefront/webpack.client.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const clientDistDirectoryPath = resolve(distDirectoryPath, 'client') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'client', 16 | target: ['web', 'es6'], 17 | output: { 18 | path: clientDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'browser'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-client.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /packages/sdk-storefront/webpack.common.maker.mjs: -------------------------------------------------------------------------------- 1 | import webpack from 'webpack' 2 | import { resolve, dirname } from 'path' 3 | import { fileURLToPath } from 'url' 4 | import nodeExternals from 'webpack-node-externals' 5 | import ProgressBar from './../../webpack-plugins/ProgressBar.mjs' 6 | import DeleteBeforeRun from './../../webpack-plugins/DeleteBeforeRun.mjs' 7 | 8 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 9 | const __dirname = dirname(fileURLToPath(import.meta.url)) 10 | const baseDirectoryPath = __dirname 11 | const srcDirectoryPath = resolve(baseDirectoryPath, 'src') 12 | const { WatchIgnorePlugin } = webpack 13 | 14 | export default ({ typeScriptConfigFilePath }) => ({ 15 | context: baseDirectoryPath, 16 | plugins: [ 17 | new ProgressBar(), 18 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'dist')), 19 | new DeleteBeforeRun(resolve(baseDirectoryPath, 'types')), 20 | new WatchIgnorePlugin({ paths: [resolve(baseDirectoryPath, 'types')] }) 21 | ], 22 | entry: { 23 | index: { 24 | import: resolve(srcDirectoryPath, 'index.ts'), 25 | library: { 26 | name: 'SpreeSDK', 27 | type: 'umd' 28 | } 29 | }, 30 | }, 31 | output: { 32 | filename: '[name].js', 33 | globalObject: 'this' 34 | }, 35 | mode: 'production', 36 | devtool: 'source-map', 37 | module: { 38 | rules: [ 39 | { 40 | test: /\.tsx?$/, 41 | loader: 'ts-loader', 42 | exclude: /node_modules/, 43 | include: srcDirectoryPath, 44 | options: { 45 | configFile: typeScriptConfigFilePath, 46 | onlyCompileBundledFiles: true 47 | } 48 | }, 49 | { 50 | test: /\.js$/, 51 | loader: 'source-map-loader', 52 | include: /node_modules/, 53 | enforce: 'pre' 54 | } 55 | ] 56 | }, 57 | resolveLoader: { 58 | modules: [srcDirectoryPath, 'node_modules'] 59 | }, 60 | resolve: { 61 | symlinks: false, 62 | extensions: ['.tsx', '.ts', '.js'] 63 | }, 64 | externals: [ 65 | nodeExternals({ 66 | allowlist: ['@spree/core-api-v2-sdk'], 67 | modulesFromFile: { 68 | excludeFromBundle: ['devDependencies'], 69 | includeInBundle: ['dependencies'] 70 | } 71 | }) 72 | ] 73 | }) 74 | -------------------------------------------------------------------------------- /packages/sdk-storefront/webpack.config.mjs: -------------------------------------------------------------------------------- 1 | import serverConfig from './webpack.server.mjs' 2 | import clientConfig from './webpack.client.mjs' 3 | 4 | export default [serverConfig, clientConfig] 5 | -------------------------------------------------------------------------------- /packages/sdk-storefront/webpack.server.mjs: -------------------------------------------------------------------------------- 1 | import { resolve, dirname } from 'path' 2 | import webpackMerge from 'webpack-merge' 3 | import { fileURLToPath } from 'url' 4 | import webpack from 'webpack' 5 | import commonConfigMaker from './webpack.common.maker.mjs' 6 | 7 | // Redefining __dirname is a temporary solution, due to https://github.com/nodejs/help/issues/2907 8 | const __dirname = dirname(fileURLToPath(import.meta.url)) 9 | const baseDirectoryPath = __dirname 10 | const distDirectoryPath = resolve(baseDirectoryPath, 'dist') 11 | const serverDistDirectoryPath = resolve(distDirectoryPath, 'server') 12 | const { merge } = webpackMerge 13 | 14 | const config = { 15 | name: 'server', 16 | target: 'node14', 17 | output: { 18 | path: serverDistDirectoryPath 19 | }, 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | RUNTIME_TYPE: "'node'" 23 | }) 24 | ] 25 | } 26 | 27 | const typeScriptConfigFilePath = resolve(baseDirectoryPath, 'tsconfig-server.json') 28 | 29 | export default merge(commonConfigMaker({ typeScriptConfigFilePath }), config) 30 | -------------------------------------------------------------------------------- /pages/alternative-setups.md: -------------------------------------------------------------------------------- 1 | ## TypeScript and `import` 2 | 3 | In TypeScript, you can import Spree Storefront SDK as follows: 4 | 5 | ```js 6 | // Set `"esModuleInterop": true` in tsconfig.json 7 | import createAxiosFetcher from '@spree/axios-fetcher/dist/server' 8 | import { makeClient } from '@spree/storefront-api-v2-sdk' 9 | ``` 10 | 11 | TypeScript definitions are included in the module and should be automatically used by any editor that supports them. 12 | 13 | ## CDN-hosted Spree Storefront SDK 14 | 15 | The Storefront SDK is hosted by the [UNPKG](https://unpkg.com/) CDN. [Follow this link to download version 6.0.0](https://unpkg.com/@spree/storefront-api-v2-sdk@6.0.0/dist/client/index.js) and [this link to download the newest version](https://unpkg.com/@spree/storefront-api-v2-sdk/dist/client/index.js). Include the SDK on a website like so: 16 | 17 | ```html 18 | 19 | 20 | 21 | 22 | 29 | ``` 30 | 31 | ## CDN-hosted Spree Platform SDK 32 | 33 | The Platform SDK is hosted by the [UNPKG](https://unpkg.com/) CDN. [Follow this link to download version 6.0.0](https://unpkg.com/@spree/storefront-api-v2-sdk@6.0.0/dist/client/index.js) and [this link to download the newest version](https://unpkg.com/@spree/storefront-api-v2-sdk/dist/client/index.js). Include the SDK on a website like so: 34 | 35 | ```html 36 | 37 | 38 | 39 | 40 | 47 | ``` -------------------------------------------------------------------------------- /pages/checkout-flow.md: -------------------------------------------------------------------------------- 1 | ```ts 2 | const cartCreateResponse = await client.cart.create() 3 | const orderToken = cartCreateResponse.success().data.attributes.token 4 | await client.cart.addItem({ 5 | order_token: orderToken, 6 | variant_id: '1' 7 | }) 8 | // Step one - save email, billing and shipping addresses 9 | await client.checkout.orderUpdate({ 10 | order_token: orderToken, 11 | order: { 12 | email, 13 | bill_address_attributes: {...}, 14 | ship_address_attributes: {...} 15 | } 16 | }) 17 | await client.checkout.orderNext({ order_token: orderToken }) 18 | // Step two - pick a shipping method 19 | const shipping = (await client.checkout.shippingRates({ order_token: orderToken })).success() 20 | await client.checkout.orderUpdate({ 21 | order_token: orderToken, 22 | order: { 23 | shipments_attributes: [{ 24 | id: shipping.data[0].id, 25 | selected_shipping_rate_id: shipping.data[0].relationships.shipping_rates.data[0].id 26 | }] 27 | } 28 | }) 29 | await client.checkout.orderNext({ order_token: orderToken }) 30 | // Step three - pick a payment method 31 | const payment = (await client.checkout.paymentMethods({ order_token: orderToken })).success() 32 | await client.checkout.addPayment({ 33 | order_token: orderToken, 34 | payment_method_id: payment.data[0].id, 35 | source_attributes: { 36 | gateway_payment_profile_id: "card_1JqvNB2eZvKYlo2C5OlqLV7S", 37 | cc_type: "visa", 38 | last_digits: "1111", 39 | month: "10", 40 | year: "2026", 41 | name: "John Snow" 42 | } 43 | }) 44 | await client.checkout.orderNext({ order_token: orderToken }) 45 | // Place the order 46 | await client.checkout.complete({ order_token: orderToken }) 47 | ``` -------------------------------------------------------------------------------- /pages/helpers.md: -------------------------------------------------------------------------------- 1 | The SDK comes with a number of helper functions making consuming responses from the Spree API easier. 2 | 3 | `extractSuccess()` unwraps Spree responses and throws errors. 4 | 5 | **Example:** 6 | 7 | ```ts 8 | import { extractSuccess } from '@spree/storefront-api-v2-sdk' 9 | try { 10 | const cartResponse = await extractSuccess(client.cart.create()) 11 | console.log('Created a new cart having token: ', cartResponse.data.attributes.token) 12 | } catch (error) { 13 | console.error('Creating a cart failed. Reason: ', error) 14 | } 15 | ``` 16 | 17 | `findRelationshipDocuments()` finds related records included in a response and `findSingleRelationshipDocument()` finds a single included record. 18 | 19 | **Example:** 20 | 21 | ```ts 22 | import { 23 | findSingleRelationshipDocument, 24 | findRelationshipDocuments 25 | } from '@spree/storefront-api-v2-sdk' 26 | const productResult = await client.products.show({ 27 | id: '1', 28 | include: 'primary_variant,variants,images' 29 | }) 30 | const productResponse = productResult.success() 31 | const primaryVariant = findSingleRelationshipDocument(productResponse, productResponse.data, 'primary_variant') 32 | const variants = findRelationshipDocuments(productResponse, productResponse.data, 'variants') 33 | const images = findRelationshipDocuments(productResponse, productResponse.data, 'images') 34 | ``` -------------------------------------------------------------------------------- /pages/quick-start.md: -------------------------------------------------------------------------------- 1 | ## Storefront SDK 2 | 3 | Install the NPM package: 4 | 5 | ``` 6 | npm install --save @spree/storefront-api-v2-sdk 7 | ``` 8 | 9 | Install the [Node Fetch](https://www.npmjs.com/package/node-fetch) HTTP client and the Node Fetch fetcher to be able to use it: 10 | 11 | ``` 12 | npm install --save @spree/node-fetcher node-fetch 13 | ``` 14 | 15 | _If you want to use the Spree SDK for a browser implementation you can use the native fetch without the need to install anything ([see here](../modules/_spree_node_fetcher.html))._ 16 | 17 | Create a client and use it to call Spree: 18 | 19 | ```js 20 | const createFetchFetcher = require('@spree/node-fetcher/dist/server/index').default 21 | const { makeClient } = require('@spree/storefront-api-v2-sdk') 22 | const client = makeClient({ 23 | host: 'http://localhost:3000', 24 | createFetcher: createFetchFetcher 25 | }) 26 | 27 | client.products.list({ 28 | include: 'default_variant', 29 | page: 1 30 | }) 31 | .then((spreeResponse) => { 32 | console.log(spreeResponse.success()) 33 | }) 34 | ``` 35 | 36 | _Spree Storefront SDK can also be imported using `import` and `