Skip to content

Commit

Permalink
Add Support for Custom Prompts (#930)
Browse files Browse the repository at this point in the history
* Add Support for Custom Prompts

* Fixed Linting

* Fixed context.test.js

* Add E2e Test

* Fix E2e Test

* Fix E2e Test

* Fix E2E Tests

* Update structure

* Updated Testcase for checking the file.

* Update - Used _getRestClient for making requests.

* Added _getRestClient Mock

* Fixed Put Request.

* Bump chai from 4.4.1 to 4.5.0 (#932)

Bumps [chai](https://github.com/chaijs/chai) from 4.4.1 to 4.5.0.
- [Release notes](https://github.com/chaijs/chai/releases)
- [Changelog](https://github.com/chaijs/chai/blob/main/History.md)
- [Commits](chaijs/chai@v4.4.1...v4.5.0)

---
updated-dependencies:
- dependency-name: chai
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* FIx Formatting

* reverted prompt types

* Fixed Linting and schema

* Make changes in Schema for partial prompts

* Update codeowner file with new GitHub team name (#931)

Co-authored-by: KunalOfficial <[email protected]>

* Removed consolelogs

* Fix back codeowners

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: stevenwong-okta <[email protected]>
  • Loading branch information
3 people authored and kushalshit27 committed Sep 26, 2024
1 parent 891b332 commit c28b94f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
67 changes: 67 additions & 0 deletions src/tools/auth0/handlers/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,43 @@ export const schema = {
{}
),
},
partials: {
type: 'object',
properties: customPartialsPromptTypes.reduce((acc, customPartialsPromptType) => {
return {
...acc,
[customPartialsPromptType]: {
oneOf: [
{
type: 'object',
properties: customPartialsScreenTypes.reduce((screenAcc, customPartialsScreenType) => {
return {
...screenAcc,
[customPartialsScreenType]: {
oneOf: [
{
type: 'object',
properties: customPartialsInsertionPoints.reduce((insertionAcc, customPartialsInsertionPoint) => {
return {
...insertionAcc,
[customPartialsInsertionPoint]: {
type: 'string',
},
};
}, {}),
},
{ type: 'null' }
],
},
};
}, {}),
},
{ type: 'null' }
],
},
};
}, {}),
},
},
};

Expand Down Expand Up @@ -499,4 +536,34 @@ export default class PromptsHandler extends DefaultHandler {
})
.promise();
}

async updateCustomPartials({
prompt,
body,
}: {
prompt: CustomPartialsPromptTypes;
body: CustomPromptPartialsScreens;
}): Promise<void> {
if (!this.IsFeatureSupported) return;
await this.partialHttpRequest('put', [{ prompt: prompt }, body]); // Implement this method for making HTTP requests
}

async updateCustomPromptsPartials(partials: Prompts['partials']): Promise<void> {
/*
Note: deletes are not currently supported
*/
if (!partials) return;
await this.client.pool
.addEachTask({
data: Object.keys(partials).map((prompt: CustomPartialsPromptTypes) => {
const body = partials[prompt] || {};
return {
body,
prompt,
};
}),
generator: ({ prompt, body }) => this.updateCustomPartials({ prompt, body }),
})
.promise();
}
}
1 change: 0 additions & 1 deletion test/context/yaml/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ describe('#YAML context validation', () => {
},
}
);

await context.dump();
const yaml = jsYaml.load(fs.readFileSync(tenantFile));

Expand Down
4 changes: 3 additions & 1 deletion test/tools/auth0/handlers/prompts.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ describe('#prompts handler', () => {

return Promise.resolve({ data: customTextValue });
},

},
pool: new PromisePoolExecutor({
concurrencyLimit: 3,
Expand Down Expand Up @@ -151,6 +150,9 @@ describe('#prompts handler', () => {
expect(data).to.deep.equal(mockPromptsSettings);
return Promise.resolve({ data });
},
_getRestClient: (endpoint) => ({
get: (...options) => Promise.resolve({ endpoint, method: 'get', options }),
}),
},
};

Expand Down
5 changes: 5 additions & 0 deletions test/tools/auth0/validator.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ describe('#schema validation tests', () => {
get: (...options) => Promise.resolve({ endpoint, method: 'get', options }),
}),
},
prompts: {
_getRestClient: (endpoint) => ({
get: (...options) => Promise.resolve({ endpoint, method: 'get', options }),
}),
},
};

const failedCb = (done) => (err) => done(err || 'test failed');
Expand Down

0 comments on commit c28b94f

Please sign in to comment.