diff --git a/src/management/__generated/managers/prompts-manager.ts b/src/management/__generated/managers/prompts-manager.ts index 977ba2da9..55eda5bdd 100644 --- a/src/management/__generated/managers/prompts-manager.ts +++ b/src/management/__generated/managers/prompts-manager.ts @@ -5,6 +5,8 @@ import type { PromptsSettingsUpdate, GetCustomTextByLanguageRequest, PutCustomTextByLanguageRequest, + GetTeplatePartialsByPromptRequest, + PutTeplatePartialsByPromptRequest, } from '../models/index.js'; const { BaseAPI } = runtime; @@ -114,4 +116,63 @@ export class PromptsManager extends BaseAPI { return runtime.VoidApiResponse.fromResponse(response); } + + /** + * Retrieve template partials for a specific prompt. + * Get template partials for a prompt + * + * @throws {RequiredError} + */ + async getTemplatePartialsByPrompt( + requestParameters: GetTeplatePartialsByPromptRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['prompt']); + + const response = await this.request( + { + path: `/prompts/{prompt}/partials`.replace( + '{prompt}', + encodeURIComponent(String(requestParameters.prompt)) + ), + method: 'GET', + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } + + /** + * Set template partials for a specific prompt. Existing partials will be overwritten. + * Set template partials for a specific prompt + * + * @throws {RequiredError} + */ + async updateTemplatePartialsByPrompt( + requestParameters: PutTeplatePartialsByPromptRequest, + bodyParameters: { [key: string]: any }, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['prompt']); + + const headerParameters: runtime.HTTPHeaders = {}; + + headerParameters['Content-Type'] = 'application/json'; + + const response = await this.request( + { + path: `/prompts/{prompt}/partials`.replace( + '{prompt}', + encodeURIComponent(String(requestParameters.prompt)) + ), + method: 'PUT', + headers: headerParameters, + body: bodyParameters, + }, + initOverrides + ); + + return runtime.VoidApiResponse.fromResponse(response); + } } diff --git a/src/management/__generated/models/index.ts b/src/management/__generated/models/index.ts index e7d2d79fa..d4eaa4a72 100644 --- a/src/management/__generated/models/index.ts +++ b/src/management/__generated/models/index.ts @@ -13602,6 +13602,44 @@ export const GetCustomTextByLanguagePromptEnum = { export type GetCustomTextByLanguagePromptEnum = (typeof GetCustomTextByLanguagePromptEnum)[keyof typeof GetCustomTextByLanguagePromptEnum]; +/** + * + */ +export interface GetTeplatePartialsByPromptRequest { + /** + * Name of the prompt. + * + */ + prompt: GetTemplatePartialsByPromptEnum; +} + +/** + * + */ +export interface PutTeplatePartialsByPromptRequest { + /** + * Name of the prompt. + * + */ + prompt: GetTemplatePartialsByPromptEnum; +} + +/** + * + */ +export const GetTemplatePartialsByPromptEnum = { + login: 'login', + login_id: 'login-id', + login_password: 'login-password', + login_passwordless: 'login-passwordless', + signup: 'signup', + signup_id: 'signup-id', + signup_password: 'signup-password', +}; + +export type GetTemplatePartialsByPromptEnum = + (typeof GetTemplatePartialsByPromptEnum)[keyof typeof GetTemplatePartialsByPromptEnum]; + /** * */ diff --git a/test/management/prompts.test.ts b/test/management/prompts.test.ts index e480de9c1..280e27f50 100644 --- a/test/management/prompts.test.ts +++ b/test/management/prompts.test.ts @@ -5,10 +5,11 @@ const API_URL = 'https://tenant.auth0.com/api/v2'; import { GetCustomTextByLanguageLanguageEnum, GetCustomTextByLanguagePromptEnum, + GetTemplatePartialsByPromptEnum, + ManagementClient, PromptsManager, PromptsSettingsUniversalLoginExperienceEnum, PromptsSettingsUpdateUniversalLoginExperienceEnum, - ManagementClient, RequiredError, } from '../../src/index.js'; @@ -310,4 +311,142 @@ describe('PromptsManager', () => { }); }); }); + + describe('#getTemplatePartialsByPrompt', () => { + let request: nock.Scope; + const params = { + prompt: GetTemplatePartialsByPromptEnum.login, + }; + + beforeEach(() => { + request = nock(API_URL).get('/prompts/login/partials').reply(200, {}); + }); + + it('should validate empty prompt parameter', async () => { + await expect(prompts.getTemplatePartialsByPrompt({} as any)).rejects.toThrowError( + RequiredError + ); + }); + + it('should return a promise if no callback is given', (done) => { + prompts + .getTemplatePartialsByPrompt(params) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + + nock(API_URL).get('/prompts/login/partials').reply(500, {}); + + prompts.getTemplatePartialsByPrompt(params).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a GET request to /api/v2/prompts/login/partials', (done) => { + prompts.getTemplatePartialsByPrompt(params).then(() => { + expect(request.isDone()).toBe(true); + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .get('/prompts/login/partials') + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, {}); + + prompts.getTemplatePartialsByPrompt(params).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#updateTemplatePartialsByPrompt', () => { + let request: nock.Scope; + const prompt = GetTemplatePartialsByPromptEnum.login; + const body = { login: { 'form-content-start': '
TESTING
' } }; + + beforeEach(() => { + request = nock(API_URL).put('/prompts/login/partials').reply(200, {}); + console.log({ request }); + }); + + it('should validate empty prompt parameter', async () => { + await expect(prompts.updateTemplatePartialsByPrompt({} as any, {})).rejects.toThrowError( + RequiredError + ); + }); + + it('should return a promise if no callback is given', (done) => { + prompts + .updateTemplatePartialsByPrompt({ prompt }, body) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + + nock(API_URL).put('/prompts/login/partials').reply(500, {}); + + prompts.updateTemplatePartialsByPrompt({ prompt }, body).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a PUT request to /api/v2/prompts/login/partials', (done) => { + prompts + .updateTemplatePartialsByPrompt({ prompt }, body) + .then(() => { + expect(request.isDone()).toBe(true); + done(); + }) + .catch((e) => { + console.error(e); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .put('/prompts/login/partials') + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, {}); + + prompts.updateTemplatePartialsByPrompt({ prompt }, body).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should send the payload to the body', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .put( + '/prompts/login/partials', + (body) => body?.login?.['form-content-start'] === '
TESTING
' + ) + .reply(200, {}); + + prompts.updateTemplatePartialsByPrompt({ prompt }, body).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); });