saleor/saleor-sdk is tracked by TopGit as a frontend project, with 125 stars on GitHub, written primarily in TypeScript. Deprecated! See the announcement below. JavaScript/TypeScript SDK for building e-commerce experiences and checkouts with Saleor API.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This package contains methods providing Saleor business logic for a storefront and apps. It handles Saleor GraphQL queries and mutations, manages Apollo cache, and provides an internal state to manage popular storefront use cases, like user authentication.
:warning: Note: Saleor SDK is DEPRECATED. See the announcement.
For authentication, follow the Saleor docs and use @saleor/auth-sdk.
Table of Contents
Setup
Features
Local development
Setup
There are two ways to use SDK - making custom implementation or using React components and hooks, which already has that implementation ready.
Using React
First install following dependencies to your project
npm install @saleor/sdk @apollo/client graphql
Use SaleorProvider with passed Saleor's client created by createSaleorClient in a prop. Then use React hooks in any component passed as child to SaleorProvider.
import {
SaleorProvider,
createSaleorClient,
useAuth,
useAuthState,
} from "@saleor/sdk";
const client = createSaleorClient({
apiUrl: "<SALEOR_GRAPHQL_URL>",
channel: "<CHANNEL>",
});
const rootElement = document.getElementById("root");
ReactDOM.render(
<SaleorProvider client={client}>
<App />
</SaleorProvider>,
rootElement
);
const App = () => {
const { login } = useAuth();
const { authenticated, user, authenticating } = useAuthState();
const handleSignIn = async () => {
const { data } = await login({
email: "[email protected]",
password: "admin",
});
if (data.tokenCreate.errors.length > 0) {
/**
* Unable to sign in.
**/
} else if (data) {
/**
* User signed in successfully.
**/
}
};
// Important: wait till the authentication process finishes
if (authenticating) {
return <div>Loading...</div>
}
if (authenticated && user) {
return <span>Signed in as {user.email}</span>;
}
return <button onClick={handleSignIn}>Sign in</button>;
};
Using with NodeJS and other frameworks
npm install @saleor/sdk @apollo/client graphql
Then use createSaleorClient to get Saleor api methods and internal config variables like channel and Apollo client.
const { data } = await auth.login({
email: "[email protected]",
password: "admin",
});
if (data.tokenCreate.errors.length > 0) {
/**
* Unable to sign in.
**/
} else if (data) {
/**
* User signed in successfully.
**/
const userData = api.auth.tokenCreate.user;
}
Custom HTTP communication with SDK authorization
SDK provides fetch method with all the necessary authorization headers assigned to HTTP requests and handled authorization token creation, verification and refresh inside, which you may use instead of built-in browser fetch. Using SDK auth login or logout methods will appropriately alter fetch behavior automatically, like including Authorization Bearer header in HTTP request.
import { createFetch } from "@saleor/sdk";
const authorizedFetch = createFetch();
const result = await authorizedFetch("https://example.com");
If you use GraphQL you may pass SDK fetch to the Apollo client:
const authorizationLink = new HttpLink({
fetch: authorizedFetch,
});
const apolloClient = new ApolloClient({
link: authorizationLink,
});
SDK fetch method uses cross-fetch under the hood.
Features
We provide an API with methods and fields, performing one, scoped type of work. You may access them straight from createSaleorClient() or use React hooks:
API object
React hook
Description
getState()
useAuthState()
Returns current SDK state: user, authenticated and authenticating.
auth
useAuth()
Handles user authentication methods.
user
useUser()
Handles user account methods.
config
useSaleorConfig()
Handles SDK configuration.
SDK supports OpenId Connect methods provided by Saleor API. They are under auth object and useAuth hook. For more usage details, please check https://docs.saleor.io/docs/3.0/developer/available-plugins/openid-connect.
Local development
Our aim it to build SDK, highly configurable, as a separate package, which you will not require modifications. Although if you want to alter the project, especially if you want to contribute, it is possible to develop storefront and SDK simultaneously. To do this, you need
to link it to the storefront's project.
$ cd lib
$ npm link
$ cd <your storefront path>
$ npm link @saleor/sdk
Notice that in our example storefront
webpack is configured to always resolve react to ./node_modules/react. It may
seem redundant for the most use cases, but helps in sdk's local development, because
it overcomes npm's limitations regarding peer dependencies hoisting, explicitly
telling webpack to always have one and only copy of react.
How does saleor/saleor-sdk compare to other Frontend projects?
saleor/saleor-sdk is tracked by TopGit in the Frontend category, with 125 GitHub stars and written in TypeScript. Browse the Frontend topic page on TopGit to compare it against similar projects by stars and activity.
Is saleor/saleor-sdk open source?
Yes — saleor/saleor-sdk ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/saleor/saleor-sdk.
What else is in the Frontend space?
saleor/saleor-sdk is tracked by TopGit under the Frontend category, alongside 10 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What is saleor/saleor-sdk?
saleor/saleor-sdk (saleor/saleor-sdk) is a TypeScript project on GitHub. From the project's own README: Deprecated! See the announcement below. JavaScript/TypeScript SDK for building e-commerce experiences and checkouts with Saleor API.
Where do I read more about saleor/saleor-sdk?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/saleor/saleor-sdk is the definitive source.
Why is saleor/saleor-sdk categorized under Frontend?
TopGit places saleor/saleor-sdk in the Frontend category based on its GitHub topics and description (tagged: "deprecated", "deprecated-repo", "e-commerce"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Is saleor-sdk worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of saleor-sdk.