Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Distribute code with ES module syntax (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops authored Jul 11, 2022
1 parent 52d2245 commit 4a7c1e0
Show file tree
Hide file tree
Showing 70 changed files with 1,008 additions and 888 deletions.
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"node-option": [
"loader=ts-node/esm"
]
}
1,252 changes: 684 additions & 568 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,50 @@
"name": "@keycloak/keycloak-admin-client",
"version": "19.0.0-dev.16",
"description": "keycloak admin client",
"type": "module",
"main": "lib/index.js",
"files": [
"lib"
],
"types": "lib/index.d.ts",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"clean": "rimraf lib",
"lint": "tslint --force --format verbose \"src/**/*.ts\" \"test/*\"",
"build": "npm run clean && tsc -p ./tsconfig.release.json --pretty",
"test": "mocha --require ts-node/register --recursive \"test/**/*.spec.ts\"",
"test:subset": "mocha --require ts-node/register --recursive --",
"test:grep": "mocha --require ts-node/register",
"build": "npm run clean && tsc --pretty",
"test": "TS_NODE_PROJECT=tsconfig.test.json mocha --recursive \"test/**/*.spec.ts\"",
"test:subset": "TS_NODE_PROJECT=tsconfig.test.json mocha --recursive --",
"test:grep": "TS_NODE_PROJECT=tsconfig.test.json mocha",
"coverage": "nyc npm run test",
"watch": "npm run build -- --watch",
"watch:test": "npm run test -- --watch",
"prepublishOnly": "npm run build"
},
"dependencies": {
"axios": "^0.27.2",
"camelize-ts": "^1.0.8",
"camelize-ts": "^2.1.1",
"keycloak-js": "^18.0.0",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"query-string": "^7.0.1",
"url-join": "^4.0.0",
"url-template": "^2.0.8"
"url-join": "^5.0.0",
"url-template": "^3.0.0"
},
"devDependencies": {
"@faker-js/faker": "^7.1.0",
"@types/chai": "^4.2.14",
"@types/lodash": "^4.14.165",
"@types/lodash-es": "^4.17.5",
"@types/mocha": "^9.0.0",
"@types/node": "^18.0.0",
"@types/url-join": "^4.0.0",
"@types/url-template": "^2.0.28",
"@types/node": "^18.0.3",
"chai": "^4.1.2",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^2.1.2",
"rimraf": "^3.0.2",
"ts-node": "^10.2.1",
"tslint": "^6.1.3",
"typescript": "^4.0.5"
"typescript": "^4.7.4"
},
"author": "wwwy3y3",
"license": "Apache-2.0",
Expand Down
49 changes: 24 additions & 25 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import {getToken, Credentials} from './utils/auth';
import {defaultBaseUrl, defaultRealm} from './utils/constants';
import {Cache} from './resources/cache';
import {Users} from './resources/users';
import {Groups} from './resources/groups';
import {Roles} from './resources/roles';
import {Clients} from './resources/clients';
import {Realms} from './resources/realms';
import {ClientScopes} from './resources/clientScopes';
import {ClientPolicies} from './resources/clientPolicies';
import {IdentityProviders} from './resources/identityProviders';
import {Components} from './resources/components';
import {AuthenticationManagement} from './resources/authenticationManagement';
import {ServerInfo} from './resources/serverInfo';
import {WhoAmI} from './resources/whoAmI';
import {AttackDetection} from './resources/attackDetection';
import {AxiosRequestConfig} from 'axios';

import {Sessions} from './resources/sessions';
import {UserStorageProvider} from './resources/userStorageProvider';
import type {KeycloakInstance, KeycloakInitOptions, KeycloakConfig} from 'keycloak-js';
import {RequestArgs} from './resources/agent';
import type {AxiosRequestConfig} from 'axios';
import type {KeycloakConfig, KeycloakInitOptions, KeycloakInstance} from 'keycloak-js';
import type {RequestArgs} from './resources/agent.js';
import {AttackDetection} from './resources/attackDetection.js';
import {AuthenticationManagement} from './resources/authenticationManagement.js';
import {Cache} from './resources/cache.js';
import {ClientPolicies} from './resources/clientPolicies.js';
import {Clients} from './resources/clients.js';
import {ClientScopes} from './resources/clientScopes.js';
import {Components} from './resources/components.js';
import {Groups} from './resources/groups.js';
import {IdentityProviders} from './resources/identityProviders.js';
import {Realms} from './resources/realms.js';
import {Roles} from './resources/roles.js';
import {ServerInfo} from './resources/serverInfo.js';
import {Sessions} from './resources/sessions.js';
import {Users} from './resources/users.js';
import {UserStorageProvider} from './resources/userStorageProvider.js';
import {WhoAmI} from './resources/whoAmI.js';
import {Credentials, getToken} from './utils/auth.js';
import {defaultBaseUrl, defaultRealm} from './utils/constants.js';

export interface ConnectionConfig {
baseUrl?: string;
Expand Down Expand Up @@ -52,7 +51,7 @@ export class KeycloakAdminClient {
public realmName: string;
public accessToken?: string;
public refreshToken?: string;
public keycloak?: KeycloakInstance;
public keycloak!: KeycloakInstance;

private requestConfig?: AxiosRequestConfig;
private globalRequestArgOptions?: Pick<RequestArgs, 'catchNotFound'>;
Expand Down Expand Up @@ -100,8 +99,8 @@ export class KeycloakAdminClient {
return;
}

const Keycloak = (await import('keycloak-js')).default;
this.keycloak = Keycloak(config);
const Keycloak: any = (await import('keycloak-js')).default;
this.keycloak = new Keycloak(config);

if (init) {
await this.keycloak.init(init);
Expand Down
9 changes: 4 additions & 5 deletions src/defs/accessTokenRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import AccessTokenAccess from './AccessTokenAccess';
import AccessTokenCertConf from './accessTokenCertConf';
import AddressClaimSet from './addressClaimSet';
import PermissionRepresentation from './PermissonRepresentation';
import {Category} from './resourceServerRepresentation';
import type AccessTokenAccess from './AccessTokenAccess.js';
import type AccessTokenCertConf from './accessTokenCertConf.js';
import type AddressClaimSet from './addressClaimSet.js';
import type {Category} from './resourceServerRepresentation.js';

export default interface AccessTokenRepresentation {
acr?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/defs/adminEventRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AuthDetailsRepresentation from './authDetailsRepresentation';
import type AuthDetailsRepresentation from './authDetailsRepresentation.js';

export default interface AdminEventRepresentation {
authDetails?: AuthDetailsRepresentation;
Expand Down
3 changes: 1 addition & 2 deletions src/defs/authenticationFlowRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import AuthenticationExecutionExportRepresentation from './authenticationExecutionExportRepresentation';
import type AuthenticationExecutionExportRepresentation from './authenticationExecutionExportRepresentation.js';

/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_authenticationflowrepresentation
Expand Down
2 changes: 1 addition & 1 deletion src/defs/clientPoliciesRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ClientPolicyRepresentation from './clientPolicyRepresentation';
import type ClientPolicyRepresentation from './clientPolicyRepresentation.js';

/**
* https://www.keycloak.org/docs-api/15.0/rest-api/#_clientpoliciesrepresentation
Expand Down
2 changes: 1 addition & 1 deletion src/defs/clientPolicyRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ClientPolicyConditionRepresentation from './clientPolicyConditionRepresentation';
import type ClientPolicyConditionRepresentation from './clientPolicyConditionRepresentation.js';

/**
* https://www.keycloak.org/docs-api/15.0/rest-api/#_clientpolicyrepresentation
Expand Down
2 changes: 1 addition & 1 deletion src/defs/clientProfileRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ClientPolicyExecutorRepresentation from './clientPolicyExecutorRepresentation';
import type ClientPolicyExecutorRepresentation from './clientPolicyExecutorRepresentation.js';

/**
* https://www.keycloak.org/docs-api/15.0/rest-api/#_clientprofilerepresentation
Expand Down
2 changes: 1 addition & 1 deletion src/defs/clientProfilesRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ClientProfileRepresentation from './clientProfileRepresentation';
import type ClientProfileRepresentation from './clientProfileRepresentation.js';

/**
* https://www.keycloak.org/docs-api/15.0/rest-api/#_clientprofilesrepresentation
Expand Down
4 changes: 2 additions & 2 deletions src/defs/clientRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_clientrepresentation
*/
import ResourceServerRepresentation from './resourceServerRepresentation';
import ProtocolMapperRepresentation from './protocolMapperRepresentation';
import type ResourceServerRepresentation from './resourceServerRepresentation.js';
import type ProtocolMapperRepresentation from './protocolMapperRepresentation.js';

export default interface ClientRepresentation {
access?: Record<string, boolean>;
Expand Down
2 changes: 1 addition & 1 deletion src/defs/clientScopeRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_clientscoperepresentation
*/
import ProtocolMapperRepresentation from './protocolMapperRepresentation';
import type ProtocolMapperRepresentation from './protocolMapperRepresentation.js';

export default interface ClientScopeRepresentation {
attributes?: Record<string, any>;
Expand Down
2 changes: 1 addition & 1 deletion src/defs/componentTypeRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ConfigPropertyRepresentation} from './configPropertyRepresentation';
import type {ConfigPropertyRepresentation} from './configPropertyRepresentation.js';

/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_componenttyperepresentation
Expand Down
8 changes: 4 additions & 4 deletions src/defs/evaluationResultRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PolicyRepresentation, {DecisionEffect} from './policyRepresentation';
import PolicyResultRepresentation from './policyResultRepresentation';
import ResourceRepresentation from './resourceRepresentation';
import ScopeRepresentation from './scopeRepresentation';
import type {DecisionEffect} from './policyRepresentation.js';
import type PolicyResultRepresentation from './policyResultRepresentation.js';
import type ResourceRepresentation from './resourceRepresentation.js';
import type ScopeRepresentation from './scopeRepresentation.js';

export default interface EvaluationResultRepresentation {
resource?: ResourceRepresentation;
Expand Down
2 changes: 1 addition & 1 deletion src/defs/eventRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_eventrepresentation
*/
import EventType from './eventTypes';
import type EventType from './eventTypes.js';

export default interface EventRepresentation {
clientId?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/defs/identityProviderMapperTypeRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ConfigPropertyRepresentation} from './configPropertyRepresentation';
import type {ConfigPropertyRepresentation} from './configPropertyRepresentation.js';

export interface IdentityProviderMapperTypeRepresentation {
id?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/defs/mappingsRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_mappingsrepresentation
*/
import RoleRepresentation from './roleRepresentation';
import type RoleRepresentation from './roleRepresentation.js';

export default interface MappingsRepresentation {
clientMappings?: Record<string, any>;
Expand Down
6 changes: 3 additions & 3 deletions src/defs/policyEvaluationResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AccessTokenRepresentation from './accessTokenRepresentation';
import EvaluationResultRepresentation from './evaluationResultRepresentation';
import {DecisionEffect} from './policyRepresentation';
import type AccessTokenRepresentation from './accessTokenRepresentation.js';
import type EvaluationResultRepresentation from './evaluationResultRepresentation.js';
import type {DecisionEffect} from './policyRepresentation.js';

export default interface PolicyEvaluationResponse {
results?: EvaluationResultRepresentation[];
Expand Down
4 changes: 2 additions & 2 deletions src/defs/policyResultRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PolicyRepresentation, {DecisionEffect} from './policyRepresentation';
import ScopeRepresentation from './scopeRepresentation';
import type PolicyRepresentation from './policyRepresentation.js';
import type {DecisionEffect} from './policyRepresentation.js';

export default interface PolicyResultRepresentation {
policy?: PolicyRepresentation;
Expand Down
20 changes: 10 additions & 10 deletions src/defs/realmRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ClientRepresentation from './clientRepresentation';
import ComponentExportRepresentation from './componentExportRepresentation';
import UserRepresentation from './userRepresentation';
import GroupRepresentation from './groupRepresentation';
import IdentityProviderRepresentation from './identityProviderRepresentation';
import RequiredActionProviderRepresentation from './requiredActionProviderRepresentation';
import RolesRepresentation from './rolesRepresentation';
import ClientProfilesRepresentation from './clientProfilesRepresentation';
import ClientPoliciesRepresentation from './clientPoliciesRepresentation';
import RoleRepresentation from './roleRepresentation';
import type ClientRepresentation from './clientRepresentation.js';
import type ComponentExportRepresentation from './componentExportRepresentation.js';
import type UserRepresentation from './userRepresentation.js';
import type GroupRepresentation from './groupRepresentation.js';
import type IdentityProviderRepresentation from './identityProviderRepresentation.js';
import type RequiredActionProviderRepresentation from './requiredActionProviderRepresentation.js';
import type RolesRepresentation from './rolesRepresentation.js';
import type ClientProfilesRepresentation from './clientProfilesRepresentation.js';
import type ClientPoliciesRepresentation from './clientPoliciesRepresentation.js';
import type RoleRepresentation from './roleRepresentation.js';

/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_realmrepresentation
Expand Down
2 changes: 1 addition & 1 deletion src/defs/resourceEvaluation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ResourceRepresentation from './resourceRepresentation';
import type ResourceRepresentation from './resourceRepresentation.js';

export default interface ResourceEvaluation {
roleIds?: string[];
Expand Down
4 changes: 2 additions & 2 deletions src/defs/resourceRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_resourcerepresentation
*/
import {ResourceOwnerRepresentation} from './resourceServerRepresentation';
import ScopeRepresentation from './scopeRepresentation';
import type {ResourceOwnerRepresentation} from './resourceServerRepresentation.js';
import type ScopeRepresentation from './scopeRepresentation.js';

export default interface ResourceRepresentation {
name?: string;
Expand Down
6 changes: 3 additions & 3 deletions src/defs/resourceServerRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_policyrepresentation
*/
import PolicyRepresentation from './policyRepresentation';
import ResourceRepresentation from './resourceRepresentation';
import ScopeRepresentation from './scopeRepresentation';
import type PolicyRepresentation from './policyRepresentation.js';
import type ResourceRepresentation from './resourceRepresentation.js';
import type ScopeRepresentation from './scopeRepresentation.js';

export default interface ResourceServerRepresentation {
id?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/defs/rolesRepresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_rolesrepresentation
*/

import RoleRepresentation from './roleRepresentation';
import type RoleRepresentation from './roleRepresentation.js';

export default interface RolesRepresentation {
realm?: RoleRepresentation[];
Expand Down
4 changes: 2 additions & 2 deletions src/defs/scopeRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_scoperepresentation
*/
import PolicyRepresentation from './policyRepresentation';
import ResourceRepresentation from './resourceRepresentation';
import type PolicyRepresentation from './policyRepresentation.js';
import type ResourceRepresentation from './resourceRepresentation.js';

export default interface ScopeRepresentation {
displayName?: string;
Expand Down
12 changes: 6 additions & 6 deletions src/defs/serverInfoRepesentation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ComponentTypeRepresentation from './componentTypeRepresentation';
import {ConfigPropertyRepresentation} from './configPropertyRepresentation';
import PasswordPolicyTypeRepresentation from './passwordPolicyTypeRepresentation';
import ProfileInfoRepresentation from './profileInfoRepresentation';
import ProtocolMapperRepresentation from './protocolMapperRepresentation';
import SystemInfoRepresentation from './systemInfoRepersantation';
import type ComponentTypeRepresentation from './componentTypeRepresentation.js';
import type {ConfigPropertyRepresentation} from './configPropertyRepresentation.js';
import type PasswordPolicyTypeRepresentation from './passwordPolicyTypeRepresentation.js';
import type ProfileInfoRepresentation from './profileInfoRepresentation.js';
import type ProtocolMapperRepresentation from './protocolMapperRepresentation.js';
import type SystemInfoRepresentation from './systemInfoRepersantation.js';

/**
* https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_serverinforepresentation
Expand Down
8 changes: 4 additions & 4 deletions src/defs/userRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UserConsentRepresentation from './userConsentRepresentation';
import CredentialRepresentation from './credentialRepresentation';
import FederatedIdentityRepresentation from './federatedIdentityRepresentation';
import {RequiredActionAlias} from './requiredActionProviderRepresentation';
import type UserConsentRepresentation from './userConsentRepresentation.js';
import type CredentialRepresentation from './credentialRepresentation.js';
import type FederatedIdentityRepresentation from './federatedIdentityRepresentation.js';
import type {RequiredActionAlias} from './requiredActionProviderRepresentation.js';

export default interface UserRepresentation {
id?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RequiredActionAlias} from './defs/requiredActionProviderRepresentation';
import {KeycloakAdminClient} from './client';
import {RequiredActionAlias} from './defs/requiredActionProviderRepresentation.js';
import {KeycloakAdminClient} from './client.js';

export const requiredAction = RequiredActionAlias;
export default KeycloakAdminClient;
Loading

0 comments on commit 4a7c1e0

Please sign in to comment.