@curity/identityserver-haapi-web-driver
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -39,3 +39,3 @@ /** | ||
* | ||
* @beta | ||
* @public | ||
*/ | ||
@@ -50,4 +50,3 @@ export declare function createHaapiFetch(config: HaapiConfiguration): FetchLike; | ||
* | ||
* @beta | ||
* | ||
* @public | ||
*/ | ||
@@ -57,2 +56,3 @@ export declare type FetchLike = (link: string, init?: { | ||
body?: URLSearchParams | Record<string, string> | null; | ||
credentials?: RequestCredentials; | ||
headers?: HeadersInit; | ||
@@ -64,4 +64,3 @@ }) => Promise<Response>; | ||
* | ||
* @beta | ||
* | ||
* @public | ||
*/ | ||
@@ -68,0 +67,0 @@ export declare interface HaapiConfiguration { |
@@ -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,"createHaapiFetch",(function(){return g}));var i=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{d(i.next(e))}catch(e){o(e)}}function a(e){try{d(i.throw(e))}catch(e){o(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(s,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)}}))})()}}var o=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{d(i.next(e))}catch(e){o(e)}}function a(e){try{d(i.throw(e))}catch(e){o(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(s,a)}d((i=i.apply(e,t||[])).next())}))};class s{constructor(e,t,n,i){this.iframeFactory=e,this.timeout=t,this.onReload=n,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 o(this,void 0,void 0,(function*(){return yield this.ensureReady(),yield this.sendReceive("api-request",{href:e,init:t()},"api-response")}))}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 o(this,void 0,void 0,(function*(){yield new Promise((e,t)=>{const n=new a("loaded",()=>{this.handleProtocolMessage=e=>this.handlePendingResponse(e),e()},e=>{this.handleProtocolMessage=()=>this.logger.error("Previous setup has failed",e),this.iframe.dispose(),this.ready=()=>{const e=this.setup();return this.iframe=this.createIframeMessenger(),e},t(e)},this.timeout,this.logger);this.handleProtocolMessage=e=>n.handle(e)});try{yield this.sendReceive("setup",void 0,"ready")}catch(e){throw this.ready=()=>this.reload(),e}}))}reload(){return o(this,void 0,void 0,(function*(){this.logger.debug("Reloading CAT iframe"),this.send("reload"),yield this.setup(),this.onReload()}))}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()},o=new a(n,t=>{r(),e(t)},e=>{r(),t(e)},this.timeout,this.logger);this.pendingResponses.set(i,o)})}}class a{constructor(e,t,n,i,r){this.type=e,this.success=t,this.error=n,this.logger=r,this.timeoutHandle=setTimeout(()=>{this.error(new Error(`Timeout while waiting for message '${e}'`))},i)}handle(e){if(clearTimeout(this.timeoutHandle),"error"===e.type){let t=e.data;t instanceof Error||(t=new Error(""+t)),this.error(t)}else 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,n){this.logger=n,this.logger.debug("Initializing CAT iframe"),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.eventHandler=e=>this.handleMessageEvent(e,t),window.addEventListener("message",this.eventHandler),document.body.append(this.iframe)}dispose(){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 n of e)t[n[0]]=n[1];return t}const l={debug:console.log,error:console.error},f={debug:()=>{},error:()=>{}};var p=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{d(i.next(e))}catch(e){o(e)}}function a(e){try{d(i.throw(e))}catch(e){o(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(s,a)}d((i=i.apply(e,t||[])).next())}))};function g(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,minAccessTokenTtl:e.minAccessTokenTtl||10})}(e),n=(e=>e["se:curity:web-cat:debug"]?l:f)(window),i=new d(t,n),r=new s(i,1e3*t.timeout,()=>o=null,n);let o=null;return(e,i)=>p(this,void 0,void 0,(function*(){i=i||{};const s=new URL(e,t.baseUrl),a=i.method||"GET",d=new Headers(i.headers);d.set("Accept","application/vnd.auth+json");let c=void 0;if(i.body){if(i.body instanceof URLSearchParams)c=i.body;else{if(!(i.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}(i.body)}d.set("Content-Type","application/x-www-form-urlencoded")}o&&d.set("Session-Id",o);const h=yield r.fetch(s.href,()=>function(e,t,n){return o&&t.set("Session-Id",o),{method:e,headers:u(t),body:null==n?void 0:n.toString(),credentials:"omit"}}(a,d,c)),l=new Response(h.body,h.init),f=l.headers.get("Set-Session-Id");return f&&(n.debug("Setting session ID to "+f),o=f),l}))}}])})); | ||
!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,"createHaapiFetch",(function(){return p}));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)}}))})()}}var s=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 o{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 s(this,void 0,void 0,(function*(){return yield this.ensureReady(),yield this.sendReceive("api-request",{href:e,init:t()},"api-response")}))}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 s(this,void 0,void 0,(function*(){yield new Promise((e,t)=>{const n=new a("loaded",()=>{this.handleProtocolMessage=e=>this.handlePendingResponse(e),e()},e=>{this.handleProtocolMessage=()=>this.logger.error("Previous setup has failed",e),this.iframe.dispose(),this.ready=()=>{const e=this.setup();return this.iframe=this.createIframeMessenger(),e},t(e)},this.timeout,this.logger);this.handleProtocolMessage=e=>n.handle(e)});try{yield this.sendReceive("setup",void 0,"ready")}catch(e){throw this.ready=()=>this.reload(),e}}))}reload(){return s(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 a(n,t=>{r(),e(t)},e=>{r(),t(e)},this.timeout,this.logger);this.pendingResponses.set(i,s)})}}class a{constructor(e,t,n,i,r){this.type=e,this.success=t,this.error=n,this.logger=r,this.timeoutHandle=setTimeout(()=>{this.error(new Error(`Timeout while waiting for message '${e}'`))},i)}handle(e){if(clearTimeout(this.timeoutHandle),"error"===e.type){let t=e.data;t instanceof Error||(t=new Error(""+t)),this.error(t)}else 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,n){this.logger=n,this.logger.debug("Initializing CAT iframe"),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.eventHandler=e=>this.handleMessageEvent(e,t),window.addEventListener("message",this.eventHandler),document.body.append(this.iframe)}dispose(){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 n of e)t[n[0]]=n[1];return t}const l={debug:console.log,error:console.error},f={debug:()=>{},error:()=>{}};var g=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())}))};function p(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,minAccessTokenTtl:e.minAccessTokenTtl||10})}(e),n=(e=>e["se:curity:web-cat:debug"]?l:f)(window),i=new d(t,n),r=new o(i,1e3*t.timeout,n);let s=null;return(e,i)=>g(this,void 0,void 0,(function*(){i=i||{};const o=new URL(e,t.baseUrl),a=i.method||"GET",d=i.credentials||"same-origin",c=new Headers(i.headers);c.set("Accept","application/vnd.auth+json");let h=void 0;if(i.body){if(i.body instanceof URLSearchParams)h=i.body;else{if(!(i.body instanceof Object))throw new Error("Unsupported body type");h=function(e){const t=new URLSearchParams;return Object.entries(e).forEach(e=>t.append(e[0],e[1])),t}(i.body)}c.set("Content-Type","application/x-www-form-urlencoded")}s&&c.set("Session-Id",s);const l=yield r.fetch(o.href,()=>function(e,t,n,i){return s&&t.set("Session-Id",s),{method:e,headers:u(t),body:null==n?void 0:n.toString(),credentials:i}}(a,c,h,d)),f=new Response(l.body,l.init),g=f.headers.get("Set-Session-Id");return g&&(n.debug("Setting session ID to "+g),s=g),f}))}}])})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@curity/identityserver-haapi-web-driver", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
23936
118
1