{"version":3,"file":"users.cjs","names":[],"sources":["../../../../src/rest/commands/utils/users.ts"],"sourcesContent":["import type { RestCommand } from '../../types.js';\n\n/**\n * Invite a new user by email.\n *\n * @param email User email to invite.\n * @param role Role of the new user.\n * @param invite_url Provide a custom invite url which the link in the email will lead to. The invite token will be passed as a parameter.\n *\n * @returns Nothing\n */\nexport const inviteUser =\n\t<Schema>(email: string, role: string, invite_url?: string): RestCommand<void, Schema> =>\n\t() => ({\n\t\tpath: `/users/invite`,\n\t\tmethod: 'POST',\n\t\tbody: JSON.stringify({\n\t\t\temail,\n\t\t\trole,\n\t\t\t...(invite_url ? { invite_url } : {}),\n\t\t}),\n\t});\n\n/**\n * Accept your invite. The invite user endpoint sends the email a link to the Admin App.\n *\n * @param token Accept invite token.\n * @param password Password for the user.\n *\n * @returns Nothing\n */\nexport const acceptUserInvite =\n\t<Schema>(token: string, password: string): RestCommand<void, Schema> =>\n\t() => ({\n\t\tpath: `/users/invite/accept`,\n\t\tmethod: 'POST',\n\t\tbody: JSON.stringify({\n\t\t\ttoken,\n\t\t\tpassword,\n\t\t}),\n\t});\n\n/**\n * Register a new user.\n *\n * @param email The new user email.\n * @param password The new user password.\n * @param options Optional registration fields.\n *\n * @returns Nothing\n */\nexport const registerUser =\n\t<Schema>(\n\t\temail: string,\n\t\tpassword: string,\n\t\toptions: { verification_url?: string; first_name?: string; last_name?: string } = {},\n\t): RestCommand<void, Schema> =>\n\t() => ({\n\t\tpath: `/users/register`,\n\t\tmethod: 'POST',\n\t\tbody: JSON.stringify({\n\t\t\temail,\n\t\t\tpassword,\n\t\t\t...options,\n\t\t}),\n\t});\n\n/**\n * Verify a registered user email using a token sent to the address.\n *\n * @param token Accept registration token.\n *\n * @returns Nothing\n */\nexport const registerUserVerify =\n\t<Schema>(token: string): RestCommand<void, Schema> =>\n\t() => ({\n\t\tpath: `/users/register/verify-email`,\n\t\tparams: { token },\n\t\tmethod: 'GET',\n\t});\n\n/**\n * Generates a secret and returns the URL to be used in an authenticator app.\n *\n * @param password The user's password.\n *\n * @returns A two-factor secret\n */\nexport const generateTwoFactorSecret =\n\t<Schema>(password: string): RestCommand<{ secret: string; otpauth_url: string }, Schema> =>\n\t() => ({\n\t\tpath: `/users/me/tfa/generate`,\n\t\tmethod: 'POST',\n\t\tbody: JSON.stringify({\n\t\t\tpassword,\n\t\t}),\n\t});\n\n/**\n * Adds a TFA secret to the user account.\n *\n * @param secret The TFA secret from tfa/generate.\n * @param otp OTP generated with the secret, to recheck if the user has a correct TFA setup\n *\n * @returns Nothing\n */\nexport const enableTwoFactor =\n\t<Schema>(secret: string, otp: string): RestCommand<void, Schema> =>\n\t() => ({\n\t\tpath: `/users/me/tfa/enable`,\n\t\tmethod: 'POST',\n\t\tbody: JSON.stringify({\n\t\t\tsecret,\n\t\t\totp,\n\t\t}),\n\t});\n\n/**\n * Disables two-factor authentication by removing the OTP secret from the user.\n *\n * @param otp One-time password generated by the authenticator app.\n *\n * @returns Nothing\n */\nexport const disableTwoFactor =\n\t<Schema>(otp: string): RestCommand<void, Schema> =>\n\t() => ({\n\t\tpath: `/users/me/tfa/disable`,\n\t\tmethod: 'POST',\n\t\tbody: JSON.stringify({ otp }),\n\t});\n"],"mappings":"AAWA,MAAa,GACH,EAAe,EAAc,SAC/B,CACN,KAAM,gBACN,OAAQ,OACR,KAAM,KAAK,UAAU,CACpB,QACA,OACA,GAAI,EAAa,CAAE,aAAY,CAAG,EAAE,CACpC,CAAC,CACF,EAUW,GACH,EAAe,SACjB,CACN,KAAM,uBACN,OAAQ,OACR,KAAM,KAAK,UAAU,CACpB,QACA,WACA,CAAC,CACF,EAWW,GAEX,EACA,EACA,EAAkF,EAAE,QAE9E,CACN,KAAM,kBACN,OAAQ,OACR,KAAM,KAAK,UAAU,CACpB,QACA,WACA,GAAG,EACH,CAAC,CACF,EASW,EACH,QACF,CACN,KAAM,+BACN,OAAQ,CAAE,QAAO,CACjB,OAAQ,MACR,EASW,EACH,QACF,CACN,KAAM,yBACN,OAAQ,OACR,KAAM,KAAK,UAAU,CACpB,WACA,CAAC,CACF,EAUW,GACH,EAAgB,SAClB,CACN,KAAM,uBACN,OAAQ,OACR,KAAM,KAAK,UAAU,CACpB,SACA,MACA,CAAC,CACF,EASW,EACH,QACF,CACN,KAAM,wBACN,OAAQ,OACR,KAAM,KAAK,UAAU,CAAE,MAAK,CAAC,CAC7B"}