From 601c9ab22e76ef160dab8302a8f342ee1b43acd5 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Tue, 30 Jan 2024 08:54:45 +0100 Subject: [PATCH] Add support for prompt partials --- .../__generated/managers/prompts-manager.ts | 69 ++++++++- src/management/__generated/models/index.ts | 49 +++++++ test/management/prompts.test.ts | 136 ++++++++++++++++++ 3 files changed, 250 insertions(+), 4 deletions(-) diff --git a/src/management/__generated/managers/prompts-manager.ts b/src/management/__generated/managers/prompts-manager.ts index 977ba2da9..e997e9c5c 100644 --- a/src/management/__generated/managers/prompts-manager.ts +++ b/src/management/__generated/managers/prompts-manager.ts @@ -4,7 +4,9 @@ import type { PromptsSettings, PromptsSettingsUpdate, GetCustomTextByLanguageRequest, + GetPartialsRequest, PutCustomTextByLanguageRequest, + PutPartialsRequest, } from '../models/index.js'; const { BaseAPI } = runtime; @@ -39,8 +41,34 @@ export class PromptsManager extends BaseAPI { } /** - * Retrieve prompts settings. - * Get prompts settings + * Get template partials for a prompt - In Early Access + * Get partials for a prompt + * + * @throws {RequiredError} + */ + async getPartials( + requestParameters: GetPartialsRequest, + 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); + } + + /** + * Retrieve details of the Universal Login configuration of your tenant. This includes the Identifier First Authentication and WebAuthn with Device Biometrics for MFA features. + * Get prompt settings * * @throws {RequiredError} */ @@ -57,8 +85,8 @@ export class PromptsManager extends BaseAPI { } /** - * Update prompts settings. - * Update prompts settings + * Update the Universal Login configuration of your tenant. This includes the Identifier First Authentication and WebAuthn with Device Biometrics for MFA features. + * Update prompt settings * * @throws {RequiredError} */ @@ -114,4 +142,37 @@ export class PromptsManager extends BaseAPI { return runtime.VoidApiResponse.fromResponse(response); } + + /** + * Set template partials for a prompt - In Early Access + * Set partials for a prompt + * + * @throws {RequiredError} + */ + async updatePartials( + requestParameters: PutPartialsRequest, + 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..d4662699a 100644 --- a/src/management/__generated/models/index.ts +++ b/src/management/__generated/models/index.ts @@ -13675,6 +13675,31 @@ export interface GetCustomTextByLanguageRequest { language: GetCustomTextByLanguageLanguageEnum; } +/** + * + */ +export const GetPartialsPromptEnum = { + login: 'login', + login_id: 'login-id', + login_password: 'login-password', + signup: 'signup', + signup_id: 'signup-id', + signup_password: 'signup-password', +} as const; +export type GetPartialsPromptEnum = + (typeof GetPartialsPromptEnum)[keyof typeof GetPartialsPromptEnum]; + +/** + * + */ +export interface GetPartialsRequest { + /** + * Name of the prompt. + * + */ + prompt: GetPartialsPromptEnum; +} + /** * */ @@ -13785,6 +13810,30 @@ export interface PutCustomTextByLanguageRequest { */ language: PutCustomTextByLanguageLanguageEnum; } +/** + * + */ +export const PutPartialsPromptEnum = { + login: 'login', + login_id: 'login-id', + login_password: 'login-password', + signup: 'signup', + signup_id: 'signup-id', + signup_password: 'signup-password', +} as const; +export type PutPartialsPromptEnum = + (typeof PutPartialsPromptEnum)[keyof typeof PutPartialsPromptEnum]; + +/** + * + */ +export interface PutPartialsRequest { + /** + * Name of the prompt. + * + */ + prompt: PutPartialsPromptEnum; +} /** * */ diff --git a/test/management/prompts.test.ts b/test/management/prompts.test.ts index e480de9c1..ff4658c41 100644 --- a/test/management/prompts.test.ts +++ b/test/management/prompts.test.ts @@ -10,6 +10,8 @@ import { PromptsSettingsUpdateUniversalLoginExperienceEnum, ManagementClient, RequiredError, + GetPartialsPromptEnum, + PutPartialsPromptEnum, } from '../../src/index.js'; describe('PromptsManager', () => { @@ -310,4 +312,138 @@ describe('PromptsManager', () => { }); }); }); + + describe('#getPartials', () => { + const params = { + prompt: GetPartialsPromptEnum.login, + }; + let request: nock.Scope; + + beforeEach(() => { + request = nock(API_URL).get('/prompts/login/partials').reply(200, {}); + }); + + it('should validate empty prompt parameter', async () => { + await expect(prompts.getPartials({} as any)).rejects.toThrowError(RequiredError); + }); + + it('should return a promise if no callback is given', (done) => { + prompts.getPartials(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.getPartials(params).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a GET request to /api/v2/prompts/login/partials', (done) => { + prompts.getPartials(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.getPartials(params).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#updatePartials', () => { + const params = { + prompt: PutPartialsPromptEnum.login, + }; + const body = { + 'form-content-start': '
HTML or Liquid
...', + }; + let request: nock.Scope; + + beforeEach(() => { + request = nock(API_URL).put('/prompts/login/partials').reply(200, {}); + }); + + it('should validate empty prompt parameter', async () => { + await expect(prompts.updatePartials({} as any, {})).rejects.toThrowError(RequiredError); + }); + + it('should return a promise if no callback is given', (done) => { + prompts.updatePartials(params, 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.updatePartials(params, body).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a PUT request to /api/v2/prompts/login/partials', (done) => { + prompts + .updatePartials(params, 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.updatePartials(params, 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 && + body['form-content-start'] && + body['form-content-start'] === '
HTML or Liquid
...' + ) + .reply(200, {}); + + prompts.updatePartials(params, body).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); });