Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | 10x 10x 10x 10x 10x 10x 10x 77x 77x 77x 10x 20x 20x 20x 20x 20x 10x 24x 24x 10x 10x 46x 5x 5x 41x 41x 41x 41x 9x 41x 3x 38x 2x 36x 2x 34x 34x 34x 34x 34x 22x 22x 22x 22x 22x 14x 12x 12x 12x 8x 8x 4x 4x 4x 12x 68x 1x 1x 96x 51x 9x 147x 85x 197x 174x 194x 17x 100x 67x 67x 67x 67x 67x 67x | /* * Copyright 2025 SkillTree * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import log from 'js-logger'; import skillsService from '../SkillsService'; Iif (!window.process) { // workaround for sockjs-client relying on 'process' variable being defined. // similar issue with 'global' variable discussed here: // https://github.com/sockjs/sockjs-client/issues/401 window.process = { env: { DEBUG: undefined }, }; } const jsSkillsClientVersion = '__skillsClientVersion__'; let waitForInitializePromise = null; let initializedResolvers = null; let initialized = false; // used purely to validate that configure is called before any other components are utilized let configureCalled = false; const initializeAfterConfigurePromise = () => { Eif (!waitForInitializePromise) { waitForInitializePromise = new Promise((resolve, reject) => { initializedResolvers = { resolve, reject, }; }); } }; const setInitialized = (conf) => { log.debug('SkillsClient::SkillsConfiguration::calling initializedResolvers'); initializedResolvers.resolve(); skillsService.reportSkillsClientVersion(conf); initialized = true; log.debug('SkillsClient::SkillsConfiguration::initialized'); }; const setConfigureWasCalled = () => { log.info('SkillsClient::SkillConfiguration::configured'); configureCalled = true; }; initializeAfterConfigurePromise(); const exportObject = { configure({ serviceUrl, projectId, authenticator, authToken, oauthRedirect = false, enabled = true, }) { if (this.isInitialized()) { log.warn('SkillsConfiguration already initialized.'); return; } log.debug(`SkillsConfiguration::configure params serviceUrl=[${serviceUrl}], projectId=[${projectId}], ` + `authenticator=[${authenticator}], authToken=[${authToken}], oauthRedirect=${oauthRedirect}, enabled=${enabled}`) this.enabled = enabled Iif (!enabled) { log.useDefaults(); log.setLevel(log.TRACE) log.info('SkillsConfiguration is disabled.'); return Promise.resolve(); } if (!this.skillsClientVersion) { // this will be replaced at build time with the current skills-client-js // version. extensions of the plain JS client (vue, react, etc), should // override with their version before configure() is called this.skillsClientVersion = jsSkillsClientVersion; } if (!projectId || projectId === 'null') { throw new Error(`SkillTree: SkillsConfiguration.configure received invalid parameter for projectId=[${projectId}]`); } if (!serviceUrl || serviceUrl === 'null') { throw new Error(`SkillTree: SkillsConfiguration.configure received invalid parameter for serviceUrl=[${serviceUrl}]`); } if (!authToken && (!authenticator || authenticator === 'null')) { throw new Error(`SkillTree: SkillsConfiguration.configure received invalid parameter for authenticator=[${authenticator}]`); } this.projectId = projectId; this.serviceUrl = `${serviceUrl}`.trim().replace(/\/$/, ''); this.authenticator = authenticator; this.authToken = authToken; return skillsService.getServiceStatus(`${this.getServiceUrl()}/public/status`).then((response) => { this.status = response.status; skillsService.configureLogging(this.getServiceUrl(), response); log.info(`Returned status [${JSON.stringify(response)}]`); Iif (response.oAuthProviders && response.oAuthProviders.includes(authenticator)) { this.authenticator = `${this.getServiceUrl()}/oauth2/authorization/${authenticator}`; log.info(`Auto configured authenticator [${this.authenticator}] for provider [${authenticator}]`); } if (!this.isPKIMode() && !this.getAuthToken()) { return skillsService.getAuthenticationToken(this.getAuthenticator(), this.getServiceUrl(), this.getProjectId(), oauthRedirect) .then((token) => { this.setAuthToken(token); setInitialized(this); setConfigureWasCalled(); }); } else { setInitialized(this); setConfigureWasCalled(); } }).catch((error) => { // eslint-disable-next-line no-console console.error('Error getting service status', error); setConfigureWasCalled(); initializedResolvers.resolve(); }); }, afterConfigure() { return waitForInitializePromise; }, validate() { if (!this.serviceUrl || !this.projectId || !this.authenticator) { const errorMessage = `SkillTree: SkillsConfiguration was not configured and serviceUrl, projectId and authenticationUrl are missing. Please call: SkillsConfiguration.configure(serviceUrl, myProjectId, authenticator); SkillsConfiguration is a singleton and you only have to do this once. Please see the docs for more info.`; throw new Error(errorMessage); } }, isPKIMode() { return this.getAuthenticator() === 'pki' || this.getAuthToken() === 'pki'; }, isOAuthMode() { return skillsService.isOAuthMode(this.authenticator, this.serviceUrl); }, isInitialized() { return initialized; }, wasConfigureCalled() { return configureCalled; }, getProjectId() { return this.projectId; }, isDisabled() { return !this.enabled; }, getServiceUrl() { return this.serviceUrl; }, getAuthenticator() { return this.authenticator; }, getAuthToken() { return this.authToken; }, getServiceStatus() { return this.status; }, setAuthToken(authToken) { this.authToken = authToken; }, logout() { initializedResolvers = null; waitForInitializePromise = null; configureCalled = false; initialized = false; initializeAfterConfigurePromise(); this.setAuthToken(null); }, }; export default exportObject; |