Skip to content

Commit

Permalink
Add support for prompt partials
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Jan 30, 2024
1 parent 04b109b commit 601c9ab
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 4 deletions.
69 changes: 65 additions & 4 deletions src/management/__generated/managers/prompts-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import type {
PromptsSettings,
PromptsSettingsUpdate,
GetCustomTextByLanguageRequest,
GetPartialsRequest,
PutCustomTextByLanguageRequest,
PutPartialsRequest,
} from '../models/index.js';

const { BaseAPI } = runtime;
Expand Down Expand Up @@ -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<ApiResponse<{ [key: string]: any }>> {
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<any>(response);
}

/**
* Retrieve details of the Universal Login configuration of your tenant. This includes the <a href="https://auth0.com/docs/authenticate/login/auth0-universal-login/identifier-first">Identifier First Authentication</a> and <a href="https://auth0.com/docs/secure/multi-factor-authentication/fido-authentication-with-webauthn/configure-webauthn-device-biometrics-for-mfa">WebAuthn with Device Biometrics for MFA</a> features.
* Get prompt settings
*
* @throws {RequiredError}
*/
Expand All @@ -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 <a href="https://auth0.com/docs/authenticate/login/auth0-universal-login/identifier-first">Identifier First Authentication</a> and <a href="https://auth0.com/docs/secure/multi-factor-authentication/fido-authentication-with-webauthn/configure-webauthn-device-biometrics-for-mfa">WebAuthn with Device Biometrics for MFA</a> features.
* Update prompt settings
*
* @throws {RequiredError}
*/
Expand Down Expand Up @@ -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<ApiResponse<void>> {
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);
}
}
49 changes: 49 additions & 0 deletions src/management/__generated/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
*
*/
Expand Down Expand Up @@ -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;
}
/**
*
*/
Expand Down
136 changes: 136 additions & 0 deletions test/management/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
PromptsSettingsUpdateUniversalLoginExperienceEnum,
ManagementClient,
RequiredError,
GetPartialsPromptEnum,
PutPartialsPromptEnum,
} from '../../src/index.js';

describe('PromptsManager', () => {
Expand Down Expand Up @@ -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': '<div>HTML or Liquid</div>...',
};
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'] === '<div>HTML or Liquid</div>...'
)
.reply(200, {});

prompts.updatePartials(params, body).then(() => {
expect(request.isDone()).toBe(true);

done();
});
});
});
});

0 comments on commit 601c9ab

Please sign in to comment.