docs: generate + configure js sdk reference (#9714)

Manually generate the JS SDK reference + add it to the sidebar
This commit is contained in:
Shahed Nasser
2024-10-22 17:31:32 +00:00
committed by GitHub
parent af3c6b0d93
commit a1190b7208
476 changed files with 76450 additions and 189 deletions
@@ -0,0 +1,35 @@
---
slug: /references/js-sdk/auth/callback
sidebar_label: callback
---
import { TypeList } from "docs-ui"
# callback - JS SDK Auth Reference
This documentation provides a reference to the `sdk.auth.callback` method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.
This method is used to validate an Oauth callback from a third-party service, such as Google, for an admin user, customer, or custom actor types.
It sends a request to the [Validate Authentication Callback](https://docs.medusajs.com/v2/api/admin#auth\_postactor\_typeauth\_providercallback).
## Example
```ts
sdk.auth.callback(
"customer",
"google",
{
code: "123",
}
).then((token) => {
console.log(token)
})
```
## Parameters
<TypeList types={[{"name":"actor","type":"`string`","description":"The actor type. For example, `user` for admin user, or `customer` for customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"method","type":"`string`","description":"The authentication provider to use. For example, `google`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"`Record<string, unknown>`","description":"The query parameters from the Oauth callback, which should be passed to the API route.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="callback"/>
## Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;string&#62;","optional":false,"defaultValue":"","description":"The authentication JWT token","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="callback"/>
@@ -0,0 +1,42 @@
---
slug: /references/js-sdk/auth/login
sidebar_label: login
---
import { TypeList } from "docs-ui"
# login - JS SDK Auth Reference
This documentation provides a reference to the `sdk.auth.login` method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.
This method retrieves the JWT authenticated token for an admin user, customer, or custom
actor type. It sends a request to the [Authenticate API Route](https://docs.medusajs.com/v2/api/admin#auth\_postactor\_typeauth\_provider).
If the `auth.type` of the SDK is set to `session`, this method will also send a request to the
[Set Authentication Session API route](https://docs.medusajs.com/v2/api/admin#auth\_postsession).
Subsequent requests using the SDK will automatically have the necessary authentication headers / session
set.
## Example
```ts
sdk.auth.login(
"customer",
"emailpass",
{
email: "customer@gmail.com",
password: "supersecret"
}
).then((token) => {
console.log(token)
})
```
## Parameters
<TypeList types={[{"name":"actor","type":"`string`","description":"The actor type. For example, `user` for admin user, or `customer` for customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"method","type":"`string`","description":"The authentication provider to use. For example, `emailpass` or `google`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payload","type":"`AdminSignInWithEmailPassword` \\| `Record<string, unknown>`","description":"The data to pass in the request's body for authentication. When using the `emailpass` provider,\nyou pass the email and password.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="login"/>
## Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;string \\| object&#62;","optional":false,"defaultValue":"","description":"The authentication JWT token","expandable":false,"children":[{"name":"string \\| object","type":"`string` \\| `object`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="login"/>
@@ -0,0 +1,26 @@
---
slug: /references/js-sdk/auth/logout
sidebar_label: logout
---
import { TypeList } from "docs-ui"
# logout - JS SDK Auth Reference
This documentation provides a reference to the `sdk.auth.logout` method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.
This method deletes the authentication session of the currently logged-in user to log them out.
It sends a request to the [Delete Authentication Session API route](https://docs.medusajs.com/v2/api/admin#auth\_deletesession).
## Example
```ts
sdk.auth.logout()
.then(() => {
// user is logged out
})
```
## Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"This method deletes the authentication session of the currently logged-in user to log them out.\nIt sends a request to the [Delete Authentication Session API route](https://docs.medusajs.com/v2/api/admin#auth\\_deletesession).","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="logout"/>
@@ -0,0 +1,26 @@
---
slug: /references/js-sdk/auth/refresh
sidebar_label: refresh
---
import { TypeList } from "docs-ui"
# refresh - JS SDK Auth Reference
This documentation provides a reference to the `sdk.auth.refresh` method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.
This method refreshes a JWT authentication token, which is useful after validating the Oauth callback
with [callback](../js_sdk.auth.Auth.callback/page.mdx). It sends a request to the [Refresh Authentication Token API route](https://docs.medusajs.com/v2/api/admin#auth\_postadminauthtokenrefresh).
## Example
```ts
sdk.auth.refresh()
.then((token) => {
console.log(token)
})
```
## Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;string&#62;","optional":false,"defaultValue":"","description":"The refreshed JWT authentication token.","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="refresh"/>
@@ -0,0 +1,34 @@
---
slug: /references/js-sdk/auth/register
sidebar_label: register
---
import { TypeList } from "docs-ui"
# register - JS SDK Auth Reference
This documentation provides a reference to the `sdk.auth.register` method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.
This method is used to retrieve a registration JWT token for a user, customer, or custom actor type. It sends a request to the
[Retrieve Registration Token API route](https://docs.medusajs.com/v2/api/store#auth\_postactor\_typeauth\_provider\_register).
## Example
```ts
sdk.auth
.register("customer", "emailpass", {
email: "customer@gmail.com",
password: "supersecret",
}
.then((token) => {
console.log(token)
})
```
## Parameters
<TypeList types={[{"name":"actor","type":"`string`","description":"The actor type. For example, `user` for admin user, or `customer` for customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"method","type":"`string`","description":"The authentication provider to use. For example, `emailpass` or `google`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payload","type":"`AdminSignUpWithEmailPassword`","description":"The data to pass in the request's body for authentication. When using the `emailpass` provider,\nyou pass the email and password.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="register"/>
## Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;string&#62;","optional":false,"defaultValue":"","description":"The JWT token used for registration later.","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="register"/>
@@ -0,0 +1,40 @@
---
slug: /references/js-sdk/auth/resetPassword
sidebar_label: resetPassword
---
import { TypeList } from "docs-ui"
# resetPassword - JS SDK Auth Reference
This documentation provides a reference to the `sdk.auth.resetPassword` method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.
This method requests a reset password token for an admin user, customer, or custom actor type.
It sends a request to the [Generate Reset Password Token API route](https://docs.medusajs.com/v2/api/admin#auth\_postactor\_typeauth\_providerresetpassword).
To reset the password later using the token delivered to the user, use the [updateProvider](../js_sdk.auth.Auth.updateProvider/page.mdx) method.
Related guide: [How to allow customers to reset their passwords in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password).
## Example
```ts
sdk.auth.resetPassword(
"customer",
"emailpass",
{
identifier: "customer@gmail.com"
}
)
.then(() => {
// user receives token
})
```
## Parameters
<TypeList types={[{"name":"actor","type":"`string`","description":"The actor type. For example, `user` for admin user, or `customer` for customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"The authentication provider to use. For example, `emailpass`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"body","type":"`object`","description":"The data required to identify the user.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"identifier","type":"`string`","description":"The user's identifier. For example, when using the `emailpass` provider,\nthis would be the user's email.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="resetPassword"/>
## Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"This method requests a reset password token for an admin user, customer, or custom actor type.\nIt sends a request to the [Generate Reset Password Token API route](https://docs.medusajs.com/v2/api/admin#auth\\_postactor\\_typeauth\\_providerresetpassword).\n\nTo reset the password later using the token delivered to the user, use the [updateProvider](../js_sdk.auth.Auth.updateProvider/page.mdx) method.\n\nRelated guide: [How to allow customers to reset their passwords in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password).","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="resetPassword"/>
@@ -0,0 +1,43 @@
---
slug: /references/js-sdk/auth/updateProvider
sidebar_label: updateProvider
---
import { TypeList } from "docs-ui"
# updateProvider - JS SDK Auth Reference
This documentation provides a reference to the `sdk.auth.updateProvider` method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.
This method is used to update user-related data authentication data.
More specifically, use this method when updating the password of an admin user, customer, or
custom actor type after requesting to reset their password with [resetPassword](../js_sdk.auth.Auth.resetPassword/page.mdx).
This method sends a request to [this API route](https://docs.medusajs.com/v2/api/admin#auth\_postactor\_typeauth\_providerupdate).
Related guide: [How to allow customers to reset their passwords in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password).
## Example
```ts
sdk.auth.updateProvider(
"customer",
"emailpass",
{
email: "customer@gmail.com",
password: "supersecret"
}
)
.then(() => {
// password updated
})
```
## Parameters
<TypeList types={[{"name":"actor","type":"`string`","description":"The actor type. For example, `user` for admin user, or `customer` for customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"The authentication provider to use. For example, `emailpass`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"body","type":"`Record<string, unknown>`","description":"The data necessary to update the user's authentication data. When resetting the user's password, \nsend the `email` and `password` properties.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="updateProvider"/>
## Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"This method is used to update user-related data authentication data.\n\nMore specifically, use this method when updating the password of an admin user, customer, or \ncustom actor type after requesting to reset their password with [resetPassword](../js_sdk.auth.Auth.resetPassword/page.mdx).\n\nThis method sends a request to [this API route](https://docs.medusajs.com/v2/api/admin#auth\\_postactor\\_typeauth\\_providerupdate).\n\nRelated guide: [How to allow customers to reset their passwords in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password).","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="updateProvider"/>
@@ -0,0 +1,19 @@
---
slug: /references/js-sdk/auth
---
import { TypeList } from "docs-ui"
# JS SDK Auth Reference
The `sdk.auth` class provides methods to send requests to manage a user or customer's authentication
## Methods
- [register](../../Auth/methods/js_sdk.auth.Auth.register/page.mdx)
- [login](../../Auth/methods/js_sdk.auth.Auth.login/page.mdx)
- [callback](../../Auth/methods/js_sdk.auth.Auth.callback/page.mdx)
- [refresh](../../Auth/methods/js_sdk.auth.Auth.refresh/page.mdx)
- [logout](../../Auth/methods/js_sdk.auth.Auth.logout/page.mdx)
- [resetPassword](../../Auth/methods/js_sdk.auth.Auth.resetPassword/page.mdx)
- [updateProvider](../../Auth/methods/js_sdk.auth.Auth.updateProvider/page.mdx)