47 lines
1.8 KiB
JavaScript
47 lines
1.8 KiB
JavaScript
import {
|
|
normalizeContentPasswordRecoveryCapability,
|
|
normalizeContentPasswordResetPayload,
|
|
normalizeContentPasswordResource
|
|
} from './content-password-recovery-contract.js'
|
|
import { normalizeGenealogyPathId } from './genealogy-contract.js'
|
|
import { requestStrict } from './request-client.js'
|
|
|
|
const recoveryPath = (genealogyId, resourceType, resourceId) => {
|
|
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
|
const resource = normalizeContentPasswordResource(resourceType, resourceId)
|
|
return `/genealogy/app/genealogies/${normalizedGenealogyId}/content-password-recovery/${resource.resourceType}/${resource.resourceId}`
|
|
}
|
|
|
|
export const contentPasswordRecoveryApi = {
|
|
async getCapability(genealogyId, resourceType, resourceId, requestOptions = {}) {
|
|
const capability = await requestStrict({
|
|
url: `${recoveryPath(genealogyId, resourceType, resourceId)}/capability`,
|
|
method: 'GET'
|
|
}, { requestController: requestOptions.requestController ?? null })
|
|
return normalizeContentPasswordRecoveryCapability(capability)
|
|
},
|
|
|
|
async sendCode(genealogyId, resourceType, resourceId, requestOptions = {}) {
|
|
await requestStrict({
|
|
url: `${recoveryPath(genealogyId, resourceType, resourceId)}/code`,
|
|
method: 'POST'
|
|
}, {
|
|
requireData: false,
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return { cooldownSeconds: 60 }
|
|
},
|
|
|
|
async resetPassword(genealogyId, resourceType, resourceId, payload, requestOptions = {}) {
|
|
await requestStrict({
|
|
url: `${recoveryPath(genealogyId, resourceType, resourceId)}/reset`,
|
|
method: 'POST',
|
|
data: normalizeContentPasswordResetPayload(payload)
|
|
}, {
|
|
requireData: false,
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return null
|
|
}
|
|
}
|