From 1af584633c0f71018f1e371913969890556345b0 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 10 Nov 2020 16:06:28 +0100 Subject: [PATCH] simpler window-polyfill --- package.json | 1 - src/client.ts | 2 +- src/defs/roleRepresentation.ts | 2 +- src/resources/clients.ts | 68 +++++++++++++++++++++------------- src/utils/window-polyfill.ts | 2 + yarn.lock | 19 ---------- 6 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 src/utils/window-polyfill.ts diff --git a/package.json b/package.json index 856f2bfb..b54c4b2b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "camelize": "^1.0.0", "keycloak-js": "^11.0.3", "lodash": "^4.17.20", - "node-window-polyfill": "^1.0.0", "query-string": "^6.13.7", "url-join": "^4.0.0", "url-template": "^2.0.8" diff --git a/src/client.ts b/src/client.ts index 0fc086f9..3c0efd11 100644 --- a/src/client.ts +++ b/src/client.ts @@ -12,7 +12,7 @@ import {AuthenticationManagement} from './resources/authenticationManagement'; import {ServerInfo} from './resources/serverInfo'; import {WhoAmI} from './resources/whoAmI'; import {AxiosRequestConfig} from 'axios'; -import 'node-window-polyfill/register'; +import './utils/window-polyfill'; import Keycloak, { KeycloakConfig, KeycloakInitOptions, diff --git a/src/defs/roleRepresentation.ts b/src/defs/roleRepresentation.ts index 2783250b..a2c95ffe 100644 --- a/src/defs/roleRepresentation.ts +++ b/src/defs/roleRepresentation.ts @@ -13,7 +13,7 @@ export default interface RoleRepresentation { description?: string; id?: string; name?: string; - attributes?: Record>; + attributes?: Record; } // when requesting to role-mapping api (create, delete), id and name are required diff --git a/src/resources/clients.ts b/src/resources/clients.ts index 70f007a3..2a88746c 100644 --- a/src/resources/clients.ts +++ b/src/resources/clients.ts @@ -128,15 +128,19 @@ export class Clients extends Resource<{realm?: string}> { * Client secret */ - public generateNewClientSecret = this.makeRequest<{id: string}, CredentialRepresentation>( - { - method: 'POST', - path: '/{id}/client-secret', - urlParamKeys: ['id'], - }, - ); - - public generateRegistrationAccessToken = this.makeRequest<{id: string}, {registrationAccessToken: string}>({ + public generateNewClientSecret = this.makeRequest< + {id: string}, + CredentialRepresentation + >({ + method: 'POST', + path: '/{id}/client-secret', + urlParamKeys: ['id'], + }); + + public generateRegistrationAccessToken = this.makeRequest< + {id: string}, + {registrationAccessToken: string} + >({ method: 'POST', path: '/{id}/registration-access-token', urlParamKeys: ['id'], @@ -417,7 +421,7 @@ export class Clients extends Resource<{realm?: string}> { * Policy */ public findByName = this.makeRequest< - {id: string, name: string}, + {id: string; name: string}, PolicyRepresentation >({ method: 'GET', @@ -436,7 +440,7 @@ export class Clients extends Resource<{realm?: string}> { }); public createPolicy = this.makeUpdateRequest< - {id: string, type: string}, + {id: string; type: string}, PolicyRepresentation, PolicyRepresentation >({ @@ -455,24 +459,32 @@ export class Clients extends Resource<{realm?: string}> { catchNotFound: true, }); - public delPolicy = this.makeRequest< - {id: string, policyId: string}, - void - >({ + public delPolicy = this.makeRequest<{id: string; policyId: string}, void>({ method: 'DELETE', path: '{id}/authz/resource-server/policy/{policyId}', urlParamKeys: ['id', 'policyId'], }); - public async createOrUpdatePolicy( - payload: {id: string; policyName: string; policy: PolicyRepresentation} - ): Promise { - const policyFound = await this.findByName({id: payload.id, name: payload.policyName}); + public async createOrUpdatePolicy(payload: { + id: string; + policyName: string; + policy: PolicyRepresentation; + }): Promise { + const policyFound = await this.findByName({ + id: payload.id, + name: payload.policyName, + }); if (policyFound) { - await this.updatePolicy({id: payload.id, policyId: policyFound.id, type: payload.policy.type}, payload.policy); + await this.updatePolicy( + {id: payload.id, policyId: policyFound.id, type: payload.policy.type}, + payload.policy, + ); return this.findByName({id: payload.id, name: payload.policyName}); } else { - return this.createPolicy({id: payload.id, type: payload.policy.type}, payload.policy); + return this.createPolicy( + {id: payload.id, type: payload.policy.type}, + payload.policy, + ); } } @@ -480,8 +492,8 @@ export class Clients extends Resource<{realm?: string}> { * Scopes */ public listScopesByResource = this.makeRequest< - {id: string, resourceName: string}, - {id: string, name: string}[] + {id: string; resourceName: string}, + {id: string; name: string}[] >({ method: 'GET', path: '/{id}/authz/resource-server/resource/{resourceName}/scopes', @@ -528,13 +540,19 @@ export class Clients extends Resource<{realm?: string}> { urlParamKeys: ['id', 'type', 'permissionId'], }); - public getOfflineSessionCount = this.makeRequest<{id: string}, {count: number}>({ + public getOfflineSessionCount = this.makeRequest< + {id: string}, + {count: number} + >({ method: 'GET', path: '/{id}/offline-session-count', urlParamKeys: ['id'], }); - public getInstallationProviders = this.makeRequest<{id: string, providerId: string}, string>({ + public getInstallationProviders = this.makeRequest< + {id: string; providerId: string}, + string + >({ method: 'GET', path: '/{id}/installation/providers/{providerId}', urlParamKeys: ['id', 'providerId'], diff --git a/src/utils/window-polyfill.ts b/src/utils/window-polyfill.ts new file mode 100644 index 00000000..297e2c04 --- /dev/null +++ b/src/utils/window-polyfill.ts @@ -0,0 +1,2 @@ +const globalObject = global as any; +globalObject.window = globalObject.window || {}; diff --git a/yarn.lock b/yarn.lock index ca7e234b..1effd929 100644 --- a/yarn.lock +++ b/yarn.lock @@ -340,11 +340,6 @@ assertion-error@^1.1.0: resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== -async-limiter@~1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd" - integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ== - axios@*: version "0.19.2" resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" @@ -1119,13 +1114,6 @@ node-preload@^0.2.1: dependencies: process-on-spawn "^1.0.0" -node-window-polyfill@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/node-window-polyfill/-/node-window-polyfill-1.0.0.tgz#30426ff9f44d1ca0d83da4b6d1e244a80dc9e65e" - integrity sha1-MEJv+fRNHKDYPaS20eJEqA3J5l4= - dependencies: - ws "^5.1.1" - normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" @@ -1668,13 +1656,6 @@ write-file-atomic@^3.0.0: signal-exit "^3.0.2" typedarray-to-buffer "^3.1.5" -ws@^5.1.1: - version "5.2.2" - resolved "https://registry.yarnpkg.com/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f" - integrity sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA== - dependencies: - async-limiter "~1.0.0" - y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"