Điểm qua saleor/saleor-sdk: 125 sao trên GitHub, viết chủ yếu bằng TypeScript, thuộc nhóm Frontend. Deprecated! See the announcement below. JavaScript/TypeScript SDK for building e-commerce experiences and checkouts with Saleor API.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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.
saleor/saleor-sdk thuộc nhóm Frontend trên TopGit, cùng 10 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về saleor/saleor-sdk ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/saleor/saleor-sdk là nguồn chính thức.
saleor/saleor-sdk có phải mã nguồn mở không?
Có — saleor/saleor-sdk phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/saleor/saleor-sdk.
saleor/saleor-sdk là gì?
saleor/saleor-sdk (saleor/saleor-sdk) là dự án TypeScript trên GitHub. Theo mô tả gốc: Deprecated! See the announcement below. JavaScript/TypeScript SDK for building e-commerce experiences and checkouts with Saleor API.
saleor/saleor-sdk so với các dự án Frontend khác thế nào?
saleor/saleor-sdk được TopGit xếp vào nhóm Frontend, với 125 sao GitHub và viết bằng TypeScript. Xem trang chủ đề Frontend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Vì sao saleor/saleor-sdk được xếp vào nhóm Frontend?
TopGit xếp saleor/saleor-sdk vào nhóm Frontend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "deprecated", "deprecated-repo", "e-commerce"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về saleor-sdk?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về saleor-sdk.