Skip to content

Commit

Permalink
Fix many bugs with imports and exports. Fix typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
phalestrivir committed Oct 31, 2024
1 parent ec915e8 commit 4710c55
Show file tree
Hide file tree
Showing 73 changed files with 175,526 additions and 100,324 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
testEnvironment: 'node',
snapshotResolver: '<rootDir>/snapshotResolve.js',
testMatch: ['**/?(*.)(test).ts'],
testTimeout: 90000,
testTimeout: 120000,
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.tsx?$': ['ts-jest', { useESM: true }]
Expand Down
42 changes: 25 additions & 17 deletions src/api/AgentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { State } from '../shared/State';
import { debugMessage } from '../utils/Console';
import { getCurrentRealmPath } from '../utils/ForgeRockUtils';
import { deleteDeepByKey } from '../utils/JsonUtils';
import { type AmConfigEntityInterface, EntityType } from './ApiTypes';
import {
type AmConfigEntityInterface,
EntityType,
PagedResult,
} from './ApiTypes';
import { generateAmApi } from './BaseApi';

const getAgentTypesURLTemplate =
Expand Down Expand Up @@ -64,15 +68,15 @@ export async function getAgentTypes({ state }: { state: State }) {
/**
* Get agents
* @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)
* @returns {Promise} a promise that resolves to an object containing an array of agent objects of the specified type
* @returns {Promise<PagedResult<AgentSkeleton>>} a promise that resolves to an object containing an array of agent objects of the specified type
*/
export async function getAgentsByType({
agentType,
state,
}: {
agentType: AgentType;
state: State;
}) {
}): Promise<PagedResult<AgentSkeleton>> {
debugMessage({ message: `AgentApi.getAgentsByType: start`, state });
const urlString = util.format(
agentListURLTemplate,
Expand All @@ -92,9 +96,13 @@ export async function getAgentsByType({

/**
* Get all agents
* @returns {Promise} a promise that resolves to an object containing an array of agent objects
* @returns {Promise<PagedResult<AgentSkeleton>>} a promise that resolves to an object containing an array of agent objects
*/
export async function getAgents({ state }: { state: State }) {
export async function getAgents({
state,
}: {
state: State;
}): Promise<PagedResult<AgentSkeleton>> {
debugMessage({ message: `AgentApi.getAgents: start`, state });
const urlString = util.format(
getAllAgentsURLTemplate,
Expand All @@ -118,15 +126,15 @@ export async function getAgents({ state }: { state: State }) {
/**
* Find agent by id
* @param {string} agentId agent id
* @returns {Promise} a promise that resolves to an array with one or zero agent objects
* @returns {Promise<AgentSkeleton[]>} a promise that resolves to an array with one or zero agent objects
*/
export async function findAgentById({
agentId,
state,
}: {
agentId: string;
state: State;
}) {
}): Promise<AgentSkeleton[]> {
debugMessage({ message: `AgentApi.findAgentById: start`, state });
const urlString = util.format(
queryAgentURLTemplate,
Expand All @@ -148,7 +156,7 @@ export async function findAgentById({
* Find agent by id
* @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)
* @param {string} agentId agent id
* @returns {Promise} a promise that resolves to an array with one or zero agent objects
* @returns {Promise<AgentSkeleton[]>} a promise that resolves to an array with one or zero agent objects
*/
export async function findAgentByTypeAndId({
agentType,
Expand All @@ -158,7 +166,7 @@ export async function findAgentByTypeAndId({
agentType: AgentType;
agentId: string;
state: State;
}) {
}): Promise<AgentSkeleton[]> {
debugMessage({ message: `AgentApi.findAgentById: start`, state });
const urlString = util.format(
queryAgentByTypeURLTemplate,
Expand All @@ -181,7 +189,7 @@ export async function findAgentByTypeAndId({
* Get agent
* @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)
* @param {string} agentId agent id
* @returns {Promise} a promise that resolves to an object containing an agent object of the specified type
* @returns {Promise<AgentSkeleton>} a promise that resolves to an object containing an agent object of the specified type
*/
export async function getAgentByTypeAndId({
agentType,
Expand Down Expand Up @@ -214,8 +222,8 @@ export async function getAgentByTypeAndId({
* Put agent
* @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)
* @param {string} agentId agent id
* @param {Object} agentData agent object
* @returns {Promise} a promise that resolves to an object containing an agent object
* @param {AgentSkeleton} agentData agent object
* @returns {Promise<AgentSkeleton>} a promise that resolves to an object containing an agent object
*/
export async function putAgentByTypeAndId({
agentType,
Expand All @@ -227,7 +235,7 @@ export async function putAgentByTypeAndId({
agentId: string;
agentData: AgentSkeleton;
state: State;
}) {
}): Promise<AgentSkeleton> {
debugMessage({ message: `AgentApi.putAgentByTypeAndId: start`, state });
// until we figure out a way to use transport keys in Frodo,
// we'll have to drop those encrypted attributes.
Expand All @@ -254,9 +262,9 @@ export async function putAgentByTypeAndId({

/**
* Delete agent
* @param agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)
* @param agentId agent id
* @returns a promise that resolves to an object containing an agent object
* @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)
* @param {string} agentId agent id
* @returns {Promise<AgentSkeleton>} a promise that resolves to an object containing an agent object
*/
export async function deleteAgentByTypeAndId({
agentType,
Expand All @@ -266,7 +274,7 @@ export async function deleteAgentByTypeAndId({
agentType: AgentType;
agentId: string;
state: State;
}) {
}): Promise<AgentSkeleton> {
debugMessage({ message: `AgentApi.deleteAgentByTypeAndId: start`, state });
const urlString = util.format(
agentURLTemplate,
Expand Down
1 change: 0 additions & 1 deletion src/api/CirclesOfTrustApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export async function getCircleOfTrust({

/**
* Create a circle of trust
* @param {string} cotId circle of trust id/name
* @param {CircleOfTrustSkeleton} cotData Object representing a SAML circle of trust
* @returns {Promise<CircleOfTrustSkeleton>} a promise that resolves to a saml2 circle of trust object
*/
Expand Down
5 changes: 5 additions & 0 deletions src/api/IdmConfigApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import util from 'util';

import { EMAIL_TEMPLATE_TYPE } from '../ops/EmailTemplateOps';
import { State } from '../shared/State';
import { getIdmBaseUrl } from '../utils/ForgeRockUtils';
import {
Expand Down Expand Up @@ -68,6 +69,10 @@ export async function getConfigEntitiesByType({
type: string;
state: State;
}): Promise<PagedResult<NoIdObjectSkeletonInterface>> {
// Due to a bug (as of Ping IDM 7.5.0) with the query filter for email templates (it happens using both sw or co), in order to get all the email templates you need to use 'emailTemplat' instead.
if (type === EMAIL_TEMPLATE_TYPE) {
type = EMAIL_TEMPLATE_TYPE.substring(0, EMAIL_TEMPLATE_TYPE.length - 1);
}
const urlString = util.format(
idmConfigEntityQueryTemplate,
getIdmBaseUrl(state),
Expand Down
18 changes: 9 additions & 9 deletions src/api/OAuth2TrustedJwtIssuerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { generateAmApi } from './BaseApi';
const oauth2TrustedJwtIssuerURLTemplate =
'%s/json%s/realm-config/agents/TrustedJwtIssuer/%s';
const oauth2TrustedJwtIssuerListURLTemplate =
'%s/json%s/realm-config/agents/OAuth2Client?_queryFilter=true';
'%s/json%s/realm-config/agents/TrustedJwtIssuer?_queryFilter=true';
const apiVersion = 'protocol=2.0,resource=1.0';
const getApiConfig = () => {
return {
Expand All @@ -41,7 +41,7 @@ export type OAuth2TrustedJwtIssuerSkeleton = IdObjectSkeletonInterface & {

/**
* Get OAuth2 Trusted JWT Issuers
* @returns {Promise<PagedResult>} a promise that resolves to a PagedResults object containing an array of oauth2client objects
* @returns {Promise<PagedResult>} a promise that resolves to a PagedResults object containing an array of oauth2TrustedJwtIssuer objects
*/
export async function getOAuth2TrustedJwtIssuers({
state,
Expand All @@ -64,8 +64,8 @@ export async function getOAuth2TrustedJwtIssuers({

/**
* Get OAuth2 Trusted JWT Issuer
* @param {string} id client id
* @returns {Promise<OAuth2TrustedJwtIssuerSkeleton>} a promise that resolves to an oauth2 client object
* @param {string} id oauth2 trusted jwt issuer id
* @returns {Promise<OAuth2TrustedJwtIssuerSkeleton>} a promise that resolves to an oauth2TrustedJwtIssuer object
*/
export async function getOAuth2TrustedJwtIssuer({
id,
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function getOAuth2TrustedJwtIssuer({
* Put OAuth2 Trusted JWT Issuer
* @param {string} id issuer id
* @param {OAuth2TrustedJwtIssuerSkeleton} issuerData TrustedJwtIssuer object
* @returns {Promise<OAuth2TrustedJwtIssuerSkeleton>} a promise that resolves to an oauth2 client object
* @returns {Promise<OAuth2TrustedJwtIssuerSkeleton>} a promise that resolves to an oauth2TrustedJwtIssuer object
*/
export async function putOAuth2TrustedJwtIssuer({
id,
Expand All @@ -106,9 +106,9 @@ export async function putOAuth2TrustedJwtIssuer({
}): Promise<OAuth2TrustedJwtIssuerSkeleton> {
// until we figure out a way to use transport keys in Frodo,
// we'll have to drop those encrypted attributes.
const client = deleteDeepByKey(issuerData, '-encrypted');
delete client._provider;
delete client._rev;
const issuer = deleteDeepByKey(issuerData, '-encrypted');
delete issuer._provider;
delete issuer._rev;
const urlString = util.format(
oauth2TrustedJwtIssuerURLTemplate,
state.getHost(),
Expand All @@ -117,7 +117,7 @@ export async function putOAuth2TrustedJwtIssuer({
);
const { data } = await generateAmApi({ resource: getApiConfig(), state }).put(
urlString,
client,
issuer,
{
withCredentials: true,
}
Expand Down
17 changes: 9 additions & 8 deletions src/api/ScriptApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export type ScriptContext =
| 'OIDC_CLAIMS'
| 'SAML2_IDP_ADAPTER'
| 'SAML2_IDP_ATTRIBUTE_MAPPER'
| 'OAUTH2_MAY_ACT';
| 'OAUTH2_MAY_ACT'
| 'LIBRARY';

export type ScriptSkeleton = IdObjectSkeletonInterface & {
name: string;
Expand Down Expand Up @@ -72,7 +73,7 @@ export async function getScripts({
/**
* Get script by name
* @param {String} scriptName script name
* @returns {Promise} a promise that resolves to an object containing a script object
* @returns {Promise<PagedResult<ScriptSkeleton>>} a promise that resolves to an object containing a script object
*/
export async function getScriptByName({
scriptName,
Expand All @@ -98,15 +99,15 @@ export async function getScriptByName({
/**
* Get script by id
* @param {String} scriptId script uuid/name
* @returns {Promise} a promise that resolves to a script object
* @returns {Promise<ScriptSkeleton>} a promise that resolves to a script object
*/
export async function getScript({
scriptId,
state,
}: {
scriptId: string;
state: State;
}) {
}): Promise<ScriptSkeleton> {
const urlString = util.format(
scriptURLTemplate,
state.getHost(),
Expand All @@ -126,7 +127,7 @@ export async function getScript({
* Put script
* @param {string} scriptId script uuid
* @param {Object} scriptData script object
* @returns {Promise} a promise that resolves to an object containing a script object
* @returns {Promise<ScriptSkeleton>} a promise that resolves to an object containing a script object
*/
export async function putScript({
scriptId,
Expand All @@ -136,7 +137,7 @@ export async function putScript({
scriptId: string;
scriptData: ScriptSkeleton;
state: State;
}) {
}): Promise<ScriptSkeleton> {
const urlString = util.format(
scriptURLTemplate,
state.getHost(),
Expand All @@ -156,7 +157,7 @@ export async function putScript({
/**
* Delete script by id
* @param {String} scriptId script uuid
* @returns {Promise<ScriptSkeleton>>} a promise that resolves to a script object
* @returns {Promise<ScriptSkeleton>} a promise that resolves to a script object
*/
export async function deleteScript({
scriptId,
Expand Down Expand Up @@ -205,7 +206,7 @@ export async function deleteScriptByName({

/**
* Delete all non-default scripts
* @returns {Promise<ScriptSkeleton[]>>} a promise that resolves to an array of script objects
* @returns {Promise<ScriptSkeleton[]>} a promise that resolves to an array of script objects
*/
export async function deleteScripts({
state,
Expand Down
28 changes: 14 additions & 14 deletions src/api/ServiceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ export async function putService({
getConfigPath(globalConfig),
serviceId
);
const { data } = await generateAmApi({ resource: getApiConfig(), state }).put(
urlString,
serviceData,
{
withCredentials: true,
}
);
const { data } = await generateAmApi({
resource: getApiConfig(),
state,
}).put(urlString, serviceData, {
withCredentials: true,
headers: serviceId.startsWith('federation/') ? { 'If-Match': '*' } : {},
});
return data;
}

Expand Down Expand Up @@ -194,13 +194,13 @@ export async function putServiceNextDescendent({
serviceType,
serviceNextDescendentId
);
const { data } = await generateAmApi({ resource: getApiConfig(), state }).put(
urlString,
serviceNextDescendentData,
{
withCredentials: true,
}
);
const { data } = await generateAmApi({
resource: getApiConfig(),
state,
}).put(urlString, serviceNextDescendentData, {
withCredentials: true,
headers: serviceId.startsWith('federation/') ? { 'If-Match': '*' } : {},
});
return data;
}

Expand Down
Loading

0 comments on commit 4710c55

Please sign in to comment.