chore(utils): update auth provider TSDocs + fix errors stopping references build (#9023)
- Updated the TSDocs of the auth provider - Update the Node version in the docs-util as the outdated version was causing TypeScript error - Add `@ts-ignore` for a line that was causing a typescript error. If there's a better fix here let me know
This commit is contained in:
@@ -118,6 +118,8 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
*
|
||||
* The authentication happens either by directly authenticating or returning a redirect URL to continue
|
||||
* the authentication with a third party provider.
|
||||
*
|
||||
* Related Read: [Learn about the different authentication flows in Medusa](https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route).
|
||||
*
|
||||
* @param {AuthenticationInput} data - The details of the authentication request.
|
||||
* @param {AuthIdentityProviderService} authIdentityProviderService - The service used to retrieve or
|
||||
@@ -126,9 +128,6 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
* using this service.
|
||||
* @returns {Promise<AuthenticationResponse>} The authentication response.
|
||||
*
|
||||
* @privateRemarks
|
||||
* TODO add a link to the authentication flow document once it's public.
|
||||
*
|
||||
* @example
|
||||
* For example, if your authentication provider doesn't require validating a callback:
|
||||
*
|
||||
@@ -148,7 +147,7 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
* ): Promise<AuthenticationResponse> {
|
||||
* const isAuthenticated = false
|
||||
* // TODO perform custom logic to authenticate the user
|
||||
* // ...
|
||||
* // for example, verifying a password
|
||||
*
|
||||
* if (!isAuthenticated) {
|
||||
* // if the authentication didn't succeed, return
|
||||
@@ -159,25 +158,11 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // authentication is successful, create an auth identity
|
||||
* // if doesn't exist
|
||||
* let authIdentity
|
||||
*
|
||||
* try {
|
||||
* authIdentity = await authIdentityProviderService.retrieve({
|
||||
* entity_id: data.body.email, // email or some ID
|
||||
* provider: this.provider
|
||||
* })
|
||||
* } catch (e) {
|
||||
* // The auth identity doesn't exist so create it
|
||||
* authIdentity = await authIdentityProviderService.create({
|
||||
* entity_id: data.body.email, // email or some ID
|
||||
* provider: this.provider,
|
||||
* provider_metadata: {
|
||||
* // can include password or any other relevant information
|
||||
* }
|
||||
* })
|
||||
* }
|
||||
* // authentication is successful, retrieve the identity
|
||||
* const authIdentity = await authIdentityProviderService.retrieve({
|
||||
* entity_id: data.body.email, // email or some ID
|
||||
* provider: this.provider
|
||||
* })
|
||||
*
|
||||
* return {
|
||||
* success: true,
|
||||
@@ -229,6 +214,70 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
authIdentityProviderService: AuthIdentityProviderService
|
||||
): Promise<AuthenticationResponse>
|
||||
|
||||
/**
|
||||
* This method receives credentails to create a new auth identity. It performs any validation necessary
|
||||
* before creating the auth identity.
|
||||
*
|
||||
* For example, in the `emailpass` provider, this method ensures that the provided email doesn't exist
|
||||
* before creating the auth identity.
|
||||
*
|
||||
* This method is only used in a basic authentication flow, such as when using an email and password
|
||||
* to register and authenticate a user.
|
||||
*
|
||||
* Related Read: [Learn about the different authentication flows in Medusa](https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route).
|
||||
*
|
||||
* @param {AuthenticationInput} data - The details of the authentication request.
|
||||
* @param {AuthIdentityProviderService} authIdentityProviderService - The service used to retrieve or
|
||||
* create an auth identity. It has two methods: `create` to create an auth identity,
|
||||
* and `retrieve` to retrieve an auth identity. When you authenticate the user, you can create an auth identity
|
||||
* using this service.
|
||||
* @returns The created authentication identity if no errors occur.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* AuthIdentityProviderService,
|
||||
* AuthenticationInput,
|
||||
* AuthenticationResponse
|
||||
* } from "@medusajs/types"
|
||||
* import { MedusaError } from "@medusajs/utils"
|
||||
* // ...
|
||||
*
|
||||
* class MyAuthProviderService extends AbstractAuthModuleProvider {
|
||||
* // ...
|
||||
* async register(
|
||||
* data: AuthenticationInput,
|
||||
* authIdentityProviderService: AuthIdentityProviderService
|
||||
* ): Promise<AuthenticationResponse> {
|
||||
* try {
|
||||
* await authIdentityService.retrieve({
|
||||
* entity_id: data.body.email, // email or some ID
|
||||
* })
|
||||
*
|
||||
* return {
|
||||
* success: false,
|
||||
* error: "Identity with email already exists",
|
||||
* }
|
||||
* } catch (error) {
|
||||
* if (error.type === MedusaError.Types.NOT_FOUND) {
|
||||
* const createdAuthIdentity = await authIdentityProviderService.create({
|
||||
* entity_id: data.body.email, // email or some ID
|
||||
* provider: this.provider,
|
||||
* provider_metadata: {
|
||||
* // can include password or any other relevant information
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* return {
|
||||
* success: true,
|
||||
* authIdentity: createdAuthIdentity,
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* return { success: false, error: error.message }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
register(
|
||||
data: AuthenticationInput,
|
||||
authIdentityProviderService: AuthIdentityProviderService
|
||||
@@ -238,6 +287,49 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to update an auth identity's details.
|
||||
*
|
||||
* For example, the `emailpass` provider's implementation of this method updates a user's password.
|
||||
*
|
||||
* @param data - Data relevant to identify the auth identity and what to update in it. For example,
|
||||
* the `emailpass` provider expects in this object an `email` and `password` properties.
|
||||
* @param authIdentityProviderService - The service used to retrieve or
|
||||
* create an auth identity. It has two methods: `create` to create an auth identity,
|
||||
* and `retrieve` to retrieve an auth identity. When you authenticate the user, you can create an auth identity
|
||||
* using this service.
|
||||
* @returns The updated authentication identity if no errors occur.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* AuthIdentityProviderService,
|
||||
* AuthenticationInput,
|
||||
* AuthenticationResponse
|
||||
* } from "@medusajs/types"
|
||||
* import { MedusaError } from "@medusajs/utils"
|
||||
* // ...
|
||||
*
|
||||
* class MyAuthProviderService extends AbstractAuthModuleProvider {
|
||||
* // ...
|
||||
* async update(
|
||||
* data: Record<string, unknown>,
|
||||
* authIdentityProviderService: AuthIdentityProviderService
|
||||
* ): Promise<AuthenticationResponse> {
|
||||
* try {
|
||||
* const authIdentity = await authIdentityService.update(
|
||||
* data.email, // email or some ID used to identify the auth identity
|
||||
* {
|
||||
* user: data.user // example
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* return { success: true, authIdentity }
|
||||
* } catch (error) {
|
||||
* return { success: false, error: error.message }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
update(
|
||||
data: Record<string, unknown>,
|
||||
authIdentityProviderService: AuthIdentityProviderService
|
||||
@@ -253,8 +345,19 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
* In an authentication flow that requires performing an action with a third-party service, such as login
|
||||
* with a social account, the {@link authenticate} method is called first.
|
||||
*
|
||||
* Then, the third-party service redirects to the Medusa application's validate callback API route.
|
||||
* That route uses this method to authenticate the user.
|
||||
* Then, the third-party service redirects to a frontend URL passing it a `code` query parameter.
|
||||
* The frontend should then send a request to the Medusa application's validate callback API route, passing it the code.
|
||||
* That route uses this method to verify the callback's code.
|
||||
*
|
||||
* If the callback is verified successfully, the provider creates an auth identity for the user, or updates the auth identity's user information.
|
||||
*
|
||||
* In the auth identity, yuse the following properties to store additional data:
|
||||
*
|
||||
* - `provider_metadata`: Store metadata useful for the provider, such as a password hash.
|
||||
* - `user_metadata`: Store metadata of the user's details. For example, if the third-party service returns the user's information such as email
|
||||
* or name, you store this data in this property.
|
||||
*
|
||||
* Related Guide: [Learn about the different authentication flows in Medusa](https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route).
|
||||
*
|
||||
* @param {AuthenticationInput} data - The details of the authentication request.
|
||||
* @param {AuthIdentityProviderService} authIdentityProviderService - The service used to retrieve or
|
||||
@@ -263,9 +366,6 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
* using this service.
|
||||
* @returns {Promise<AuthenticationResponse>} The authentication response.
|
||||
*
|
||||
* @privateRemarks
|
||||
* TODO add a link to the authentication flow document once it's public.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* AuthIdentityProviderService,
|
||||
@@ -309,6 +409,9 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
|
||||
* provider: this.provider,
|
||||
* provider_metadata: {
|
||||
* // can include password or any other relevant information
|
||||
* },
|
||||
* user_metadata: {
|
||||
* // can include data retrieved from the third-party service
|
||||
* }
|
||||
* })
|
||||
* }
|
||||
|
||||
@@ -176,6 +176,7 @@ export function defineJoinerConfig(
|
||||
return (Object.values(entityLinkConfig as any) as any[])
|
||||
.filter((linkableConfig) => isObject(linkableConfig))
|
||||
.map((linkableConfig) => {
|
||||
// @ts-ignore
|
||||
return linkableConfig.primaryKey
|
||||
})
|
||||
})
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"yaml": "^2.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.9.4",
|
||||
"@types/node": "^20.12.10",
|
||||
"@types/pluralize": "^0.0.33",
|
||||
"types": "*"
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"utils": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.9.4"
|
||||
"@types/node": "^20.12.10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typedoc": "0.25.x"
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
"@actions/core": "^1.10.1",
|
||||
"@linear/sdk": "^1.22.0",
|
||||
"@octokit/core": "^4.0.5",
|
||||
"@types/node": "^20.8.3",
|
||||
"chalk": "^5.3.0",
|
||||
"glob": "^10.3.10",
|
||||
"randomcolor": "^0.6.2",
|
||||
@@ -27,6 +26,7 @@
|
||||
"typescript": "5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.12.10",
|
||||
"@types/randomcolor": "^0.5.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"typedoc": "0.26.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.9.4",
|
||||
"@types/node": "^20.12.10",
|
||||
"@types/pluralize": "^0.0.33",
|
||||
"cross-env": "^7.0.3"
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/eslint": "^8.56.6",
|
||||
"@types/node": "^16.11.10",
|
||||
"@types/node": "^20.12.10",
|
||||
"types": "*",
|
||||
"typescript": "5.5"
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"typedoc": "0.26.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.10",
|
||||
"@types/node": "^20.12.10",
|
||||
"copyfiles": "^2.4.1",
|
||||
"typedoc": "^0.26.2",
|
||||
"types": "*",
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/eslint": "^8.56.6",
|
||||
"@types/node": "^16.11.10",
|
||||
"@types/node": "^20.12.10",
|
||||
"types": "*",
|
||||
"typescript": "5.5"
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"typedoc": "0.26.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.10",
|
||||
"@types/node": "^20.12.10",
|
||||
"typescript": "5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
"typescript": "5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.9.4"
|
||||
"@types/node": "^20.12.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1459,7 +1459,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:*, @types/node@npm:^20.8.3, @types/node@npm:^20.9.4":
|
||||
"@types/node@npm:*":
|
||||
version: 20.10.0
|
||||
resolution: "@types/node@npm:20.10.0"
|
||||
dependencies:
|
||||
@@ -1468,13 +1468,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:^16.11.10":
|
||||
version: 16.18.91
|
||||
resolution: "@types/node@npm:16.18.91"
|
||||
checksum: fcae3647e11477801061dc38e8137d4f2eb3da7e0d1995e7e5401aa56a099bc6d1c22bc5c27f22d983430bced0267e8ba1fc54b2cef22bee779e7a905779e72e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:^18.11.18":
|
||||
version: 18.19.26
|
||||
resolution: "@types/node@npm:18.19.26"
|
||||
@@ -1484,6 +1477,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:^20.12.10":
|
||||
version: 20.16.5
|
||||
resolution: "@types/node@npm:20.16.5"
|
||||
dependencies:
|
||||
undici-types: ~6.19.2
|
||||
checksum: 6af7994129815010bcbc4cf8221865559c8116ff43e74a6549525c2108267596fc2d18aff5d5ecfe089fb60a119f975631343e2c65c52bfa0955ed9dc56733d6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/pluralize@npm:^0.0.33":
|
||||
version: 0.0.33
|
||||
resolution: "@types/pluralize@npm:0.0.33"
|
||||
@@ -2373,7 +2375,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@faker-js/faker": ^8.4.0
|
||||
"@octokit/core": ^5.0.2
|
||||
"@types/node": ^20.9.4
|
||||
"@types/node": ^20.12.10
|
||||
"@types/pluralize": ^0.0.33
|
||||
commander: ^11.1.0
|
||||
dotenv: ^16.3.1
|
||||
@@ -4640,7 +4642,7 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "react-docs-generator@workspace:packages/react-docs-generator"
|
||||
dependencies:
|
||||
"@types/node": ^20.9.4
|
||||
"@types/node": ^20.12.10
|
||||
chalk: ^5.3.0
|
||||
commander: ^11.1.0
|
||||
glob: ^10.3.10
|
||||
@@ -4847,7 +4849,7 @@ __metadata:
|
||||
"@actions/core": ^1.10.1
|
||||
"@linear/sdk": ^1.22.0
|
||||
"@octokit/core": ^4.0.5
|
||||
"@types/node": ^20.8.3
|
||||
"@types/node": ^20.12.10
|
||||
"@types/randomcolor": ^0.5.8
|
||||
chalk: ^5.3.0
|
||||
glob: ^10.3.10
|
||||
@@ -5353,7 +5355,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@medusajs/core-flows": "link:../../../../packages/core/core-flows"
|
||||
"@medusajs/workflows-sdk": "link:../../../../packages/core/workflows-sdk"
|
||||
"@types/node": ^20.9.4
|
||||
"@types/node": ^20.12.10
|
||||
"@types/pluralize": ^0.0.33
|
||||
chalk: ^5.3.0
|
||||
commander: ^11.1.0
|
||||
@@ -5380,7 +5382,7 @@ __metadata:
|
||||
resolution: "typedoc-plugin-custom@workspace:packages/typedoc-plugin-custom"
|
||||
dependencies:
|
||||
"@types/eslint": ^8.56.6
|
||||
"@types/node": ^16.11.10
|
||||
"@types/node": ^20.12.10
|
||||
eslint: ^8.53.0
|
||||
glob: ^10.3.10
|
||||
minimatch: ^10.0.1
|
||||
@@ -5397,7 +5399,7 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "typedoc-plugin-markdown-medusa@workspace:packages/typedoc-plugin-markdown-medusa"
|
||||
dependencies:
|
||||
"@types/node": ^16.11.10
|
||||
"@types/node": ^20.12.10
|
||||
copyfiles: ^2.4.1
|
||||
handlebars: ^4.7.8
|
||||
typedoc: ^0.26.2
|
||||
@@ -5427,7 +5429,7 @@ __metadata:
|
||||
"@medusajs/core-flows": "link:../../../../packages/core/core-flows"
|
||||
"@medusajs/workflows-sdk": "link:../../../../packages/core/workflows-sdk"
|
||||
"@types/eslint": ^8.56.6
|
||||
"@types/node": ^16.11.10
|
||||
"@types/node": ^20.12.10
|
||||
eslint: ^8.53.0
|
||||
glob: ^10.3.10
|
||||
types: "*"
|
||||
@@ -5542,6 +5544,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"undici-types@npm:~6.19.2":
|
||||
version: 6.19.8
|
||||
resolution: "undici-types@npm:6.19.8"
|
||||
checksum: 078afa5990fba110f6824823ace86073b4638f1d5112ee26e790155f481f2a868cc3e0615505b6f4282bdf74a3d8caad715fd809e870c2bb0704e3ea6082f344
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"undici@npm:^5.25.4":
|
||||
version: 5.28.0
|
||||
resolution: "undici@npm:5.28.0"
|
||||
@@ -5623,7 +5632,7 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "utils@workspace:packages/utils"
|
||||
dependencies:
|
||||
"@types/node": ^16.11.10
|
||||
"@types/node": ^20.12.10
|
||||
octokit: ^3.1.2
|
||||
rimraf: ^5.0.5
|
||||
typescript: 5.5
|
||||
@@ -5710,7 +5719,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@medusajs/workflows-sdk": latest
|
||||
"@mermaid-js/mermaid-cli": ^10.6.1
|
||||
"@types/node": ^20.9.4
|
||||
"@types/node": ^20.12.10
|
||||
commander: ^11.1.0
|
||||
ts-node: ^10.9.1
|
||||
typescript: 5.5
|
||||
|
||||
Reference in New Issue
Block a user