@curity/identityserver-haapi-web-driver
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -5,2 +5,6 @@ # Web CAT Driver | ||
## 1.1.1 (2021-10-04) | ||
- [HSW-9] Remove the `minAccessTokenTtl` configuration option as it wasn't used by the SDK | ||
## 1.1.0 (2021-08-12) | ||
@@ -7,0 +11,0 @@ |
@@ -32,3 +32,2 @@ /** | ||
/** | ||
@@ -59,3 +58,3 @@ * Creates a fetch-like function that can be used to perform HAAPI requests, managing attestation, access tokens, DPoP tokens, and Session-Id. | ||
* | ||
* @remarks | ||
* @remarks | ||
* The initialization of this function requires asynchronous steps. Errors during that phase are not reported when the function is created; instead, | ||
@@ -107,7 +106,2 @@ * the returned promise is rejected with an appropriate error (see {@link InitializationError}). Subsequent invocations will retry a failed initialization. | ||
/** | ||
* Minimum time to live (in seconds) that an access token must have to be used in a request, otherwise a new access token is retrieved and used. | ||
* @defaultValue 10 seconds. | ||
*/ | ||
minAccessTokenTtl?: number; | ||
/** | ||
* Timeout for the acquisition of the CAT, in seconds. | ||
@@ -114,0 +108,0 @@ * |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HaapiDriver=t():e.HaapiDriver=t()}(window,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t),n.d(t,"TimeoutError",(function(){return s})),n.d(t,"InitializationError",(function(){return o})),n.d(t,"createHaapiFetch",(function(){return v}));var i=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{d(i.next(e))}catch(e){s(e)}}function a(e){try{d(i.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}d((i=i.apply(e,t||[])).next())}))};class r{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}completeWith(e){if(!this.resolve||!this.reject)throw new Error("Deferred promise already used");const t=this.resolve,n=this.reject;this.resolve=this.reject=void 0,(()=>{i(this,void 0,void 0,(function*(){try{t(yield e())}catch(e){n(e)}}))})()}}class s extends Error{constructor(e){super(e),this.name="TimeoutError"}}class o extends Error{constructor(e){super(e.message),this.name="InitializationError"}}var a=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{d(i.next(e))}catch(e){s(e)}}function a(e){try{d(i.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}d((i=i.apply(e,t||[])).next())}))};class d{constructor(e,t,n){this.iframeFactory=e,this.timeout=t,this.logger=n,this.handleProtocolMessage=()=>{},this.pendingReload=void 0,this.pendingResponses=new Map,this.ready=this.setup(),this.iframe=this.createIframeMessenger()}get whenReady(){if(this.ready instanceof Promise)return this.ready;throw new Error("Called whenReady() but setup is not ongoing")}get pendingResponsesCount(){return this.pendingResponses.size}fetch(e,t){return a(this,void 0,void 0,(function*(){return yield this.ensureReady(),yield this.sendReceive("api-request",{href:e,init:t()},"api-response")}))}init(){return this.ensureReady()}dispose(){this.iframe.dispose(),this.ready=()=>Promise.reject(new Error("Already disposed"))}createIframeMessenger(){return this.iframeFactory.create(e=>{this.logger.debug("Received message",e),this.handleProtocolMessage(e)})}ensureReady(){return this.ready instanceof Function&&(this.ready=this.ready()),this.ready}setup(){return a(this,void 0,void 0,(function*(){const e=new Date;try{yield new Promise((e,t)=>{const n=new c("loaded",()=>{this.handleProtocolMessage=e=>this.handlePendingResponse(e),e()},e=>{this.handleProtocolMessage=()=>this.logger.error("Previous setup has failed",e),t(e)},this.timeout,this.logger);this.handleProtocolMessage=e=>n.handle(e)});const t=new Date;this.logger.debug("Loading took %s ms",t.getTime()-e.getTime()),yield this.sendReceive("setup",{startedLoadingAt:e,finishedLoadingAt:t,timeout:this.timeout},"ready"),this.logger.debug("Setup took %s ms",Date.now()-t.getTime())}catch(e){throw this.iframe.dispose(),this.ready=()=>{const e=this.setup();return this.iframe=this.createIframeMessenger(),e},new o(e)}}))}reload(){return a(this,void 0,void 0,(function*(){this.logger.debug("Reloading CAT iframe"),this.send("reload"),yield this.setup()}))}tryReload(){0===this.pendingResponses.size?this.ready=this.reload():(this.logger.debug("Delaying reload because there are pending responses"),this.pendingReload=new r,this.ready=this.pendingReload.promise)}tryScheduledReload(){this.pendingReload&&0===this.pendingResponses.size&&(this.pendingReload.completeWith(()=>this.reload()),this.pendingReload=void 0)}handlePendingResponse(e){if("reload"===e.type)return this.tryReload();if(e.traceId){const t=this.pendingResponses.get(e.traceId);if(t)return t.handle(e)}this.logger.debug("Received outdated message",e)}send(e,t,n){const i={type:e,data:t,traceId:n};this.logger.debug("Sending message",i),this.iframe.send(i)}sendReceive(e,t,n){const i=Math.random();return this.send(e,t,i),new Promise((e,t)=>{const r=()=>{this.pendingResponses.delete(i),this.tryScheduledReload()},s=new c(n,t=>{r(),e(t)},e=>{r(),t(e)},this.timeout,this.logger);this.pendingResponses.set(i,s)})}}class c{constructor(e,t,n,i,r){this.type=e,this.success=t,this.error=n,this.logger=r,this.timeoutHandle=setTimeout(()=>{this.error(new s(`Timeout while waiting for message '${e}'`))},i)}handle(e){clearTimeout(this.timeoutHandle),"error"===e.type?this.error(new Error(e.data.toString())):e.type!==this.type?(this.logger.error(`Expected message with type '${this.type}' but received '${e.type}'`,e),this.error(new Error("Received message with unexpected type"))):this.success(e.data)}}class u{constructor(e,t){this.configuration=e,this.logger=t}create(e){return new h(this.configuration,e,this.logger)}}class h{constructor(e,t,n){this.logger=n,this.iframeSource=new URL("cat",function(e){const t=new URL(e);t.pathname.endsWith("/")||(t.pathname+="/");return t}(e.tokenEndpoint)),this.iframeSource.searchParams.append("client_id",e.clientId),this.iframe=window.document.createElement("iframe"),this.iframe.src=this.iframeSource.href,this.iframe.style.display="none",this.iframe.id=Math.random().toString(),this.logger.debug("Initializing CAT iframe %s",this.iframe.id),this.eventHandler=e=>this.handleMessageEvent(e,t),window.addEventListener("message",this.eventHandler),document.body.append(this.iframe)}dispose(){this.logger.debug("Removing CAT iframe %s",this.iframe.id),window.removeEventListener("message",this.eventHandler),this.iframe.remove()}send(e){if(!this.iframe.parentElement)throw new Error("Already disposed");this.iframe.contentWindow.postMessage(e,this.iframeSource.origin)}handleMessageEvent(e,t){e.source===this.iframe.contentWindow?e.origin===this.iframeSource.origin?"object"==typeof e.data&&"string"==typeof e.data.type?t(e.data):this.logger.error("Received malformed message",e.data):this.logger.error("Received message from unexpected origin",e.origin):this.logger.debug("Received message from unexpected source",e.source)}}function l(e){throw new Error("config: missing or invalid "+e)}function g(e){const t={};for(var n of e)t[n[0]]=n[1];return t}const f={debug:console.log,error:console.error},p={debug:()=>{},error:()=>{}};var m=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{d(i.next(e))}catch(e){s(e)}}function a(e){try{d(i.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}d((i=i.apply(e,t||[])).next())}))};const y=(e=>e["se:curity:web-cat:debug"]?f:p)(window);let w=null;function v(e){const t=function(e){return e.clientId||l("clientId"),e.tokenEndpoint||l("tokenEndpoint"),Object.assign(Object.assign({},e),{baseUrl:e.baseUrl||new URL(e.tokenEndpoint).origin,timeout:e.timeout||5,minAccessTokenTtl:e.minAccessTokenTtl||10})}(e);w&&(w.dispose(),w=null);const n=new d(new u(t,y),1e3*t.timeout,y);let i=null;const r=(e,r)=>m(this,void 0,void 0,(function*(){r=r||{};const s=new URL(e,t.baseUrl),o=r.method||"GET",a=r.credentials||"same-origin",d=new Headers(r.headers);d.set("Accept","application/vnd.auth+json");let c=void 0;if(r.body){if(r.body instanceof URLSearchParams)c=r.body;else{if(!(r.body instanceof Object))throw new Error("Unsupported body type");c=function(e){const t=new URLSearchParams;return Object.entries(e).forEach(e=>t.append(e[0],e[1])),t}(r.body)}d.set("Content-Type","application/x-www-form-urlencoded")}i&&d.set("Session-Id",i);const u=yield n.fetch(s.href,()=>function(e,t,n,r){return i&&t.set("Session-Id",i),{method:e,headers:g(t),body:null==n?void 0:n.toString(),credentials:r}}(o,d,c,a)),h=new Response(u.body,u.init),l=h.headers.get("Set-Session-Id");return l&&(y.debug("Setting session ID to "+l),i=l),h}));return r.init=()=>m(this,void 0,void 0,(function*(){return yield n.init(),r})),w=n,r}}])})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HaapiDriver=t():e.HaapiDriver=t()}(self,(function(){return(()=>{"use strict";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{InitializationError:()=>s,TimeoutError:()=>n,createHaapiFetch:()=>y});class i{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}completeWith(e){if(!this.resolve||!this.reject)throw new Error("Deferred promise already used");const t=this.resolve,i=this.reject;this.resolve=this.reject=void 0,(()=>{var n,s,r,o;n=this,s=void 0,o=function*(){try{t(yield e())}catch(e){i(e)}},new((r=void 0)||(r=Promise))((function(e,t){function i(e){try{d(o.next(e))}catch(e){t(e)}}function a(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(e){e(n)}))).then(i,a)}d((o=o.apply(n,s||[])).next())}))})()}}class n extends Error{constructor(e){super(e),this.name="TimeoutError"}}class s extends Error{constructor(e){super(e.message),this.name="InitializationError"}}var r=function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{d(n.next(e))}catch(e){r(e)}}function a(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}d((n=n.apply(e,t||[])).next())}))};class o{constructor(e,t,i){this.iframeFactory=e,this.timeout=t,this.logger=i,this.handleProtocolMessage=()=>{},this.pendingReload=void 0,this.pendingResponses=new Map,this.ready=this.setup(),this.iframe=this.createIframeMessenger()}get whenReady(){if(this.ready instanceof Promise)return this.ready;throw new Error("Called whenReady() but setup is not ongoing")}get pendingResponsesCount(){return this.pendingResponses.size}fetch(e,t){return r(this,void 0,void 0,(function*(){return yield this.ensureReady(),yield this.sendReceive("api-request",{href:e,init:t()},"api-response")}))}init(){return this.ensureReady()}dispose(){this.iframe.dispose(),this.ready=()=>Promise.reject(new Error("Already disposed"))}createIframeMessenger(){return this.iframeFactory.create((e=>{this.logger.debug("Received message",e),this.handleProtocolMessage(e)}))}ensureReady(){return this.ready instanceof Function&&(this.ready=this.ready()),this.ready}setup(){return r(this,void 0,void 0,(function*(){const e=new Date;try{yield new Promise(((e,t)=>{const i=new a("loaded",(()=>{this.handleProtocolMessage=e=>this.handlePendingResponse(e),e()}),(e=>{this.handleProtocolMessage=()=>this.logger.error("Previous setup has failed",e),t(e)}),this.timeout,this.logger);this.handleProtocolMessage=e=>i.handle(e)}));const t=new Date;this.logger.debug("Loading took %s ms",t.getTime()-e.getTime()),yield this.sendReceive("setup",{startedLoadingAt:e,finishedLoadingAt:t,timeout:this.timeout},"ready"),this.logger.debug("Setup took %s ms",Date.now()-t.getTime())}catch(e){throw this.iframe.dispose(),this.ready=()=>{const e=this.setup();return this.iframe=this.createIframeMessenger(),e},new s(e)}}))}reload(){return r(this,void 0,void 0,(function*(){this.logger.debug("Reloading CAT iframe"),this.send("reload"),yield this.setup()}))}tryReload(){0===this.pendingResponses.size?this.ready=this.reload():(this.logger.debug("Delaying reload because there are pending responses"),this.pendingReload=new i,this.ready=this.pendingReload.promise)}tryScheduledReload(){this.pendingReload&&0===this.pendingResponses.size&&(this.pendingReload.completeWith((()=>this.reload())),this.pendingReload=void 0)}handlePendingResponse(e){if("reload"===e.type)return this.tryReload();if(e.traceId){const t=this.pendingResponses.get(e.traceId);if(t)return t.handle(e)}this.logger.debug("Received outdated message",e)}send(e,t,i){const n={type:e,data:t,traceId:i};this.logger.debug("Sending message",n),this.iframe.send(n)}sendReceive(e,t,i){const n=Math.random();return this.send(e,t,n),new Promise(((e,t)=>{const s=()=>{this.pendingResponses.delete(n),this.tryScheduledReload()},r=new a(i,(t=>{s(),e(t)}),(e=>{s(),t(e)}),this.timeout,this.logger);this.pendingResponses.set(n,r)}))}}class a{constructor(e,t,i,s,r){this.type=e,this.success=t,this.error=i,this.logger=r,this.timeoutHandle=setTimeout((()=>{this.error(new n(`Timeout while waiting for message '${e}'`))}),s)}handle(e){clearTimeout(this.timeoutHandle),"error"===e.type?this.error(new Error(e.data.toString())):e.type!==this.type?(this.logger.error(`Expected message with type '${this.type}' but received '${e.type}'`,e),this.error(new Error("Received message with unexpected type"))):this.success(e.data)}}class d{constructor(e,t){this.configuration=e,this.logger=t}create(e){return new c(this.configuration,e,this.logger)}}class c{constructor(e,t,i){this.logger=i,this.iframeSource=new URL("cat",function(e){const t=new URL(e);return t.pathname.endsWith("/")||(t.pathname+="/"),t}(e.tokenEndpoint)),this.iframeSource.searchParams.append("client_id",e.clientId),this.iframe=window.document.createElement("iframe"),this.iframe.src=this.iframeSource.href,this.iframe.style.display="none",this.iframe.id=Math.random().toString(),this.logger.debug("Initializing CAT iframe %s",this.iframe.id),this.eventHandler=e=>this.handleMessageEvent(e,t),window.addEventListener("message",this.eventHandler),document.body.append(this.iframe)}dispose(){this.logger.debug("Removing CAT iframe %s",this.iframe.id),window.removeEventListener("message",this.eventHandler),this.iframe.remove()}send(e){if(!this.iframe.parentElement)throw new Error("Already disposed");this.iframe.contentWindow.postMessage(e,this.iframeSource.origin)}handleMessageEvent(e,t){e.source===this.iframe.contentWindow?e.origin===this.iframeSource.origin?"object"==typeof e.data&&"string"==typeof e.data.type?t(e.data):this.logger.error("Received malformed message",e.data):this.logger.error("Received message from unexpected origin",e.origin):this.logger.debug("Received message from unexpected source",e.source)}}function h(e){throw new Error(`config: missing or invalid ${e}`)}function u(e){const t={};for(var i of e)t[i[0]]=i[1];return t}const l={debug:console.log,error:console.error},g={debug:()=>{},error:()=>{}};var p=function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{d(n.next(e))}catch(e){r(e)}}function a(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}d((n=n.apply(e,t||[])).next())}))};const f=(e=>e["se:curity:web-cat:debug"]?l:g)(window);let m=null;function y(e){const t=function(e){return e.clientId||h("clientId"),e.tokenEndpoint||h("tokenEndpoint"),Object.assign(Object.assign({},e),{baseUrl:e.baseUrl||new URL(e.tokenEndpoint).origin,timeout:e.timeout||5})}(e);m&&(m.dispose(),m=null);const i=new o(new d(t,f),1e3*t.timeout,f);let n=null;const s=(e,s)=>p(this,void 0,void 0,(function*(){s=s||{};const r=new URL(e,t.baseUrl),o=s.method||"GET",a=s.credentials||"same-origin",d=new Headers(s.headers);let c;if(d.set("Accept","application/vnd.auth+json"),s.body){if(s.body instanceof URLSearchParams)c=s.body;else{if(!(s.body instanceof Object))throw new Error("Unsupported body type");c=function(e){const t=new URLSearchParams;return Object.entries(e).forEach((e=>t.append(e[0],e[1]))),t}(s.body)}d.set("Content-Type","application/x-www-form-urlencoded")}n&&d.set("Session-Id",n);const h=yield i.fetch(r.href,(()=>function(e,t,i,s){return n&&t.set("Session-Id",n),{method:e,headers:u(t),body:null==i?void 0:i.toString(),credentials:s}}(o,d,c,a))),l=new Response(h.body,h.init),g=l.headers.get("Set-Session-Id");return g&&(f.debug(`Setting session ID to ${g}`),n=g),l}));return s.init=()=>p(this,void 0,void 0,(function*(){return yield i.init(),s})),m=i,s}return t})()})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@curity/identityserver-haapi-web-driver", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Curity Web CAT driver", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25993
155