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

Commit

Permalink
simpler window-polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit committed Nov 10, 2020
1 parent 1576fde commit 1af5846
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/defs/roleRepresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default interface RoleRepresentation {
description?: string;
id?: string;
name?: string;
attributes?: Record<string, Array<string>>;
attributes?: Record<string, string[]>;
}

// when requesting to role-mapping api (create, delete), id and name are required
Expand Down
68 changes: 43 additions & 25 deletions src/resources/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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',
Expand All @@ -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
>({
Expand All @@ -455,33 +459,41 @@ 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<PolicyRepresentation> {
const policyFound = await this.findByName({id: payload.id, name: payload.policyName});
public async createOrUpdatePolicy(payload: {
id: string;
policyName: string;
policy: PolicyRepresentation;
}): Promise<PolicyRepresentation> {
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,
);
}
}

/**
* 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',
Expand Down Expand Up @@ -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'],
Expand Down
2 changes: 2 additions & 0 deletions src/utils/window-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const globalObject = global as any;
globalObject.window = globalObject.window || {};
19 changes: 0 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 1af5846

Please sign in to comment.