Skip to content

Commit 5582bd2

Browse files
authored
chore(core-flows,types): improve TSDocs of user-related workflows (#11017)
1 parent bae3ddc commit 5582bd2

24 files changed

+378
-17
lines changed

packages/core/core-flows/src/auth/steps/set-auth-app-metadata.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,36 @@ export type SetAuthAppMetadataStepInput = {
1111

1212
export const setAuthAppMetadataStepId = "set-auth-app-metadata"
1313
/**
14-
* This step sets the `app_metadata` property of an auth identity.
14+
* This step sets the `app_metadata` property of an auth identity. This is useful to
15+
* associate a user (whether it's an admin user or customer) with an auth identity
16+
* that allows them to authenticate into Medusa.
17+
*
18+
* You can learn more about auth identites in
19+
* [this documentation](https://docs.medusajs.com/resources/commerce-modules/auth/auth-identity-and-actor-types).
20+
*
21+
* To use this for a custom actor type, check out [this guide](https://docs.medusajs.com/resources/commerce-modules/auth/create-actor-type)
22+
* that explains how to create a custom `manager` actor type and manage its users.
23+
*
24+
* @example
25+
* To associate an auth identity with an actor type (user, customer, or other actor types):
26+
*
27+
* ```ts
28+
* const data = setAuthAppMetadataStep({
29+
* authIdentityId: "au_1234",
30+
* actorType: "user", // or `customer`, or custom type
31+
* value: "user_123"
32+
* })
33+
* ```
34+
*
35+
* To remove the association with an actor type, such as when deleting the user:
36+
*
37+
* ```ts
38+
* const data = setAuthAppMetadataStep({
39+
* authIdentityId: "au_1234",
40+
* actorType: "user", // or `customer`, or custom type
41+
* value: null
42+
* })
43+
* ```
1544
*/
1645
export const setAuthAppMetadataStep = createStep(
1746
setAuthAppMetadataStepId,

packages/core/core-flows/src/auth/workflows/generate-reset-password-token.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@ import {
1010
} from "@medusajs/framework/workflows-sdk"
1111
import { emitEventStep, useRemoteQueryStep } from "../../common"
1212

13+
/**
14+
* This workflow generates a reset password token for a user. It's used by the
15+
* [Generate Reset Password Token for Admin](https://docs.medusajs.com/api/admin#auth_postactor_typeauth_providerresetpassword)
16+
* and [Generate Reset Password Token for Customer](https://docs.medusajs.com/api/store#auth_postactor_typeauth_providerresetpassword)
17+
* API Routes.
18+
*
19+
* The workflow emits the `auth.password_reset` event, which you can listen to in
20+
* a [subscriber](https://docs.medusajs.com/learn/fundamentals/events-and-subscribers). Follow
21+
* [this guide](https://docs.medusajs.com/resources/commerce-modules/auth/reset-password) to learn
22+
* how to handle this event.
23+
*
24+
* You can use this workflow within your customizations or your own custom workflows, allowing you to
25+
* generate reset password tokens within your custom flows.
26+
*
27+
* @example
28+
* const { result } = await generateResetPasswordTokenWorkflow(container)
29+
* .run({
30+
* input: {
31+
* entityId: "example@gmail.com",
32+
* actorType: "customer",
33+
* provider: "emailpass",
34+
* secret: "jwt_123" // jwt secret
35+
* }
36+
* })
37+
*
38+
* @summary
39+
*
40+
* Generate a reset password token for a user or customer.
41+
*/
1342
export const generateResetPasswordTokenWorkflow = createWorkflow(
1443
"generate-reset-password-token",
1544
(input: {

packages/core/core-flows/src/invite/steps/create-invites.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
55
export const createInviteStepId = "create-invite-step"
66
/**
77
* This step creates one or more invites.
8+
*
9+
* @example
10+
* const data = createInviteStep([
11+
* {
12+
* email: "example@gmail.com"
13+
* }
14+
* ])
815
*/
916
export const createInviteStep = createStep(
1017
createInviteStepId,

packages/core/core-flows/src/invite/steps/delete-invites.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import { IUserModuleService } from "@medusajs/framework/types"
22
import { Modules } from "@medusajs/framework/utils"
33
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
44

5+
/**
6+
* The IDs of the invites to delete.
7+
*/
8+
export type DeleteInvitesStepInput = string[]
9+
510
export const deleteInvitesStepId = "delete-invites-step"
611
/**
712
* This step deletes one or more invites.
813
*/
914
export const deleteInvitesStep = createStep(
1015
deleteInvitesStepId,
11-
async (input: string[], { container }) => {
16+
async (input: DeleteInvitesStepInput, { container }) => {
1217
const service: IUserModuleService = container.resolve(Modules.USER)
1318

1419
await service.softDeleteInvites(input)

packages/core/core-flows/src/invite/steps/refresh-invite-tokens.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
33

44
import { Modules } from "@medusajs/framework/utils"
55

6+
/**
7+
* The IDs of the invites to refresh.
8+
*/
9+
export type RefreshInviteTokensStepInput = string[]
10+
611
export const refreshInviteTokensStepId = "refresh-invite-tokens-step"
712
/**
813
* This step refreshes the tokens of one or more invites.
914
*/
1015
export const refreshInviteTokensStep = createStep(
1116
refreshInviteTokensStepId,
12-
async (input: string[], { container }) => {
17+
async (input: RefreshInviteTokensStepInput, { container }) => {
1318
const service: IUserModuleService = container.resolve(Modules.USER)
1419

1520
const invites = await service.refreshInviteTokens(input)

packages/core/core-flows/src/invite/steps/validate-token.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import { IUserModuleService } from "@medusajs/framework/types"
22
import { Modules } from "@medusajs/framework/utils"
33
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
44

5+
/**
6+
* The token to validate.
7+
*/
8+
export type ValidateTokenStepInput = string
9+
510
export const validateTokenStepId = "validate-invite-token-step"
611
/**
712
* This step validates a specified token and returns its associated invite.
13+
* If not valid, the step throws an error.
814
*/
915
export const validateTokenStep = createStep(
1016
validateTokenStepId,
11-
async (input: string, { container }) => {
17+
async (input: ValidateTokenStepInput, { container }) => {
1218
const userModuleService: IUserModuleService = container.resolve(
1319
Modules.USER
1420
)

packages/core/core-flows/src/invite/workflows/accept-invite.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,33 @@ import { validateTokenStep } from "../steps/validate-token"
1515

1616
export const acceptInviteWorkflowId = "accept-invite-workflow"
1717
/**
18-
* This workflow accepts an invite and creates a user.
18+
* This workflow accepts an invite and creates a user. It's used by the
19+
* [Accept Invite Admin API Route](https://docs.medusajs.com/api/admin#invites_postinvitesaccept).
20+
*
21+
* The workflow throws an error if the specified token is not valid. Also, the workflow
22+
* requires an auth identity to be created previously. You can create an auth identity
23+
* using the [Retrieve Registration JWT Token API Route](https://docs.medusajs.com/api/admin#auth_postactor_typeauth_provider_register).
24+
*
25+
* You can use this workflow within your customizations or your own custom workflows, allowing you to
26+
* accept invites within your custom flows.
27+
*
28+
* @example
29+
* const { result } = await acceptInviteWorkflow(container)
30+
* .run({
31+
* input: {
32+
* invite_token: "sk_123",
33+
* auth_identity_id: "au_123",
34+
* user: {
35+
* email: "example@gmail.com",
36+
* first_name: "John",
37+
* last_name: "Doe",
38+
* }
39+
* }
40+
* })
41+
*
42+
* @summary
43+
*
44+
* Accept invite and create user.
1945
*/
2046
export const acceptInviteWorkflow = createWorkflow(
2147
acceptInviteWorkflowId,

packages/core/core-flows/src/invite/workflows/create-invites.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,27 @@ import { emitEventStep } from "../../common/steps/emit-event"
1010
import { createInviteStep } from "../steps"
1111
export const createInvitesWorkflowId = "create-invite-step"
1212
/**
13-
* This workflow creates one or more invites.
13+
* This workflow creates one or more user invites. It's used by the
14+
* [Create Invite Admin API Route](https://docs.medusajs.com/api/admin#invites_postinvites).
15+
*
16+
* You can use this workflow within your customizations or your own custom workflows, allowing you to
17+
* create invites within your custom flows.
18+
*
19+
* @example
20+
* const { result } = await createInvitesWorkflow(container)
21+
* .run({
22+
* input: {
23+
* invites: [
24+
* {
25+
* email: "example@gmail.com"
26+
* }
27+
* ]
28+
* }
29+
* })
30+
*
31+
* @summary
32+
*
33+
* Create one or more user invites.
1434
*/
1535
export const createInvitesWorkflow = createWorkflow(
1636
createInvitesWorkflowId,

packages/core/core-flows/src/invite/workflows/delete-invites.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,23 @@ import { deleteInvitesStep } from "../steps"
1010

1111
export const deleteInvitesWorkflowId = "delete-invites-workflow"
1212
/**
13-
* This workflow deletes one or more invites.
13+
* This workflow deletes one or more user invites. It's used by the
14+
* [Delete Invites Admin API Route](https://docs.medusajs.com/api/admin#invites_deleteinvitesid).
15+
*
16+
* You can use this workflow within your customizations or your own custom workflows, allowing you to
17+
* delete invites within your custom flows.
18+
*
19+
* @example
20+
* const { result } = await deleteInvitesWorkflow(container)
21+
* .run({
22+
* input: {
23+
* ids: ["invite_123"]
24+
* }
25+
* })
26+
*
27+
* @summary
28+
*
29+
* Delete one or more user invites.
1430
*/
1531
export const deleteInvitesWorkflow = createWorkflow(
1632
deleteInvitesWorkflowId,

packages/core/core-flows/src/invite/workflows/refresh-invite-tokens.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,27 @@ import { refreshInviteTokensStep } from "../steps/refresh-invite-tokens"
1212

1313
export const refreshInviteTokensWorkflowId = "refresh-invite-tokens-workflow"
1414
/**
15-
* This workflow refreshes the token of one or more invites.
15+
* This workflow refreshes the token of one or more user invites, updating the
16+
* token and the expiry date. It's used by the
17+
* [Refresh Invite Token Admin API Route](https://docs.medusajs.com/api/admin#invites_postinvitesidresend).
18+
*
19+
* This workflow is useful to trigger resending invite tokens. It emits the `invite.resent` event,
20+
* which you can listen to in a [Subscriber](https://docs.medusajs.com/learn/fundamentals/events-and-subscribers).
21+
*
22+
* You can use this workflow within your customizations or your own custom workflows, allowing you to
23+
* refresh invite tokens within your custom flows.
24+
*
25+
* @example
26+
* const { result } = await refreshInviteTokensWorkflow(container)
27+
* .run({
28+
* input: {
29+
* invite_ids: ["invite_123"]
30+
* }
31+
* })
32+
*
33+
* @summary
34+
*
35+
* Refresh user invite tokens.
1636
*/
1737
export const refreshInviteTokensWorkflow = createWorkflow(
1838
refreshInviteTokensWorkflowId,

0 commit comments

Comments
 (0)