transposit
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -113,4 +113,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
@@ -175,3 +175,3 @@ case 0: case 1: t = op; break; | ||
}; | ||
Transposit.prototype.handleLogin = function () { | ||
Transposit.prototype.handleLogin = function (callback) { | ||
// Read query parameters | ||
@@ -207,8 +207,16 @@ var maybeClientJwtString = getParameterByName("clientJwt"); | ||
this.persistClientClaims(clientClaimsJSON); | ||
// Redirect now that login has succeeded | ||
if (needsKeys) { | ||
window.location.assign(this.getConnectLocation(window.location.pathname)); | ||
// Login has succeeded, either callback or default path replacement | ||
if (callback) { | ||
if (typeof callback !== "function") { | ||
throw new Error("Provided callback is not a function."); | ||
} | ||
callback({ needsKeys: needsKeys }); | ||
} | ||
else { | ||
window.location.assign(window.location.pathname); | ||
if (needsKeys) { | ||
window.location.href = this.getConnectLocation(window.location.pathname); | ||
} | ||
else { | ||
window.history.replaceState({}, document.title, window.location.pathname); | ||
} | ||
} | ||
@@ -215,0 +223,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.Transposit=t():e.Transposit=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},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);var r=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(a,s)}l((r=r.apply(e,t||[])).next())})},o=function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=r[2&i[0]?"return":i[0]?"throw":"next"])&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[0,o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};function i(e){var t=window.location.href;e=e.replace(/[\[\]]/g,"\\$&");var n=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return n?n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):"":null}var a=function(){function e(e,t,n){this.serviceMaintainer=e,this.serviceName=t,this.transpositUrl=n}return e.prototype.getConsumeKey=function(){return"TRANSPOSIT_CONSUME_KEY/"+this.serviceMaintainer+"/"+this.serviceName},e.prototype.retrieveClientClaims=function(){var e=localStorage.getItem(this.getConsumeKey());return e?JSON.parse(e):null},e.prototype.persistClientClaims=function(e){localStorage.setItem(this.getConsumeKey(),e)},e.prototype.clearClientClaims=function(){localStorage.removeItem(this.getConsumeKey())},e.prototype.appUrl=function(e){return void 0===e&&(e=""),this.transpositUrl+"/app/"+this.serviceMaintainer+"/"+this.serviceName+e},e.prototype.handleLogin=function(){var e=i("clientJwt");if(null===e)throw new Error("clientJwt query parameter could not be found. This method should only be called after redirection during login.");var t=e,n=i("needsKeys");if(null===n)throw new Error("needsKeys query parameter could not be found. This is unexpected.");var r,o="true"===n,a=t.split(".");if(3!==a.length)throw new Error("clientJwt query parameter does not appear to be a valid JWT string. This method should only be called after redirection during login.");try{r=atob(a[1])}catch(e){throw new Error("clientJwt query parameter does not appear to be a valid JWT string. This method should only be called after redirection during login.")}try{JSON.parse(r)}catch(e){throw new Error("clientJwt query parameter does not appear to be a valid JWT string. This method should only be called after redirection during login.")}this.persistClientClaims(r),o?window.location.assign(this.getConnectLocation(window.location.pathname)):window.location.assign(window.location.pathname)},e.prototype.logOut=function(){return r(this,void 0,void 0,function(){var e;return o(this,function(t){switch(t.label){case 0:if(!(e=this.retrieveClientClaims()))return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,fetch(this.appUrl("/api/v1/logout"),{credentials:"include",method:"POST",headers:{"content-type":"application/json","X-PUBLIC-TOKEN":e.publicToken}})];case 2:return t.sent(),[3,4];case 3:return t.sent(),[3,4];case 4:return this.clearClientClaims(),[2]}})})},e.prototype.getConnectLocation=function(e){return this.appUrl("/connect?redirectUri="+encodeURIComponent(e||window.location.href))},e.prototype.getGoogleLoginLocation=function(e){return this.appUrl("/login/google?redirectUri="+encodeURIComponent(e||window.location.href))},e.prototype.getUserEmail=function(){var e=this.retrieveClientClaims();return e?e.email:null},e.prototype.getUserName=function(){var e=this.retrieveClientClaims();return e?e.name:null},e.prototype.isLoggedIn=function(){return!!this.retrieveClientClaims()},e.prototype.runOperation=function(e,t){return void 0===t&&(t={}),r(this,void 0,void 0,function(){var n,r,i;return o(this,function(o){switch(o.label){case 0:n={"content-type":"application/json"},(r=this.retrieveClientClaims())&&(n["X-PUBLIC-TOKEN"]=r.publicToken),o.label=1;case 1:return o.trys.push([1,6,,7]),[4,fetch(this.appUrl("/api/v1/execute/"+e),{credentials:"include",method:"POST",headers:n,body:JSON.stringify({parameters:t})})];case 2:return(i=o.sent()).status>=200&&i.status<300?[4,i.json()]:[3,4];case 3:return[2,o.sent()];case 4:throw i;case 5:return[3,7];case 6:throw o.sent();case 7:return[2]}})})},e}();n.d(t,"TRANSPOSIT_CONSUME_KEY_PREFIX",function(){return"TRANSPOSIT_CONSUME_KEY"}),n.d(t,"Transposit",function(){return a})}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Transposit=t():e.Transposit=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},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);var r=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function l(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(a,l)}c((r=r.apply(e,t||[])).next())})},o=function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}};function i(e){var t=window.location.href;e=e.replace(/[\[\]]/g,"\\$&");var n=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return n?n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):"":null}var a=function(){function e(e,t,n){this.serviceMaintainer=e,this.serviceName=t,this.transpositUrl=n}return e.prototype.getConsumeKey=function(){return"TRANSPOSIT_CONSUME_KEY/"+this.serviceMaintainer+"/"+this.serviceName},e.prototype.retrieveClientClaims=function(){var e=localStorage.getItem(this.getConsumeKey());return e?JSON.parse(e):null},e.prototype.persistClientClaims=function(e){localStorage.setItem(this.getConsumeKey(),e)},e.prototype.clearClientClaims=function(){localStorage.removeItem(this.getConsumeKey())},e.prototype.appUrl=function(e){return void 0===e&&(e=""),this.transpositUrl+"/app/"+this.serviceMaintainer+"/"+this.serviceName+e},e.prototype.handleLogin=function(e){var t=i("clientJwt");if(null===t)throw new Error("clientJwt query parameter could not be found. This method should only be called after redirection during login.");var n=t,r=i("needsKeys");if(null===r)throw new Error("needsKeys query parameter could not be found. This is unexpected.");var o,a="true"===r,l=n.split(".");if(3!==l.length)throw new Error("clientJwt query parameter does not appear to be a valid JWT string. This method should only be called after redirection during login.");try{o=atob(l[1])}catch(e){throw new Error("clientJwt query parameter does not appear to be a valid JWT string. This method should only be called after redirection during login.")}try{JSON.parse(o)}catch(e){throw new Error("clientJwt query parameter does not appear to be a valid JWT string. This method should only be called after redirection during login.")}if(this.persistClientClaims(o),e){if("function"!=typeof e)throw new Error("Provided callback is not a function.");e({needsKeys:a})}else a?window.location.href=this.getConnectLocation(window.location.pathname):window.history.replaceState({},document.title,window.location.pathname)},e.prototype.logOut=function(){return r(this,void 0,void 0,function(){var e;return o(this,function(t){switch(t.label){case 0:if(!(e=this.retrieveClientClaims()))return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,fetch(this.appUrl("/api/v1/logout"),{credentials:"include",method:"POST",headers:{"content-type":"application/json","X-PUBLIC-TOKEN":e.publicToken}})];case 2:return t.sent(),[3,4];case 3:return t.sent(),[3,4];case 4:return this.clearClientClaims(),[2]}})})},e.prototype.getConnectLocation=function(e){return this.appUrl("/connect?redirectUri="+encodeURIComponent(e||window.location.href))},e.prototype.getGoogleLoginLocation=function(e){return this.appUrl("/login/google?redirectUri="+encodeURIComponent(e||window.location.href))},e.prototype.getUserEmail=function(){var e=this.retrieveClientClaims();return e?e.email:null},e.prototype.getUserName=function(){var e=this.retrieveClientClaims();return e?e.name:null},e.prototype.isLoggedIn=function(){return!!this.retrieveClientClaims()},e.prototype.runOperation=function(e,t){return void 0===t&&(t={}),r(this,void 0,void 0,function(){var n,r,i;return o(this,function(o){switch(o.label){case 0:n={"content-type":"application/json"},(r=this.retrieveClientClaims())&&(n["X-PUBLIC-TOKEN"]=r.publicToken),o.label=1;case 1:return o.trys.push([1,6,,7]),[4,fetch(this.appUrl("/api/v1/execute/"+e),{credentials:"include",method:"POST",headers:n,body:JSON.stringify({parameters:t})})];case 2:return(i=o.sent()).status>=200&&i.status<300?[4,i.json()]:[3,4];case 3:return[2,o.sent()];case 4:throw i;case 5:return[3,7];case 6:throw o.sent();case 7:return[2]}})})},e}();n.d(t,"TRANSPOSIT_CONSUME_KEY_PREFIX",function(){return"TRANSPOSIT_CONSUME_KEY"}),n.d(t,"Transposit",function(){return a})}])}); | ||
//# sourceMappingURL=bundle.prod.map |
@@ -12,3 +12,3 @@ /** | ||
*/ | ||
status: "SUCCESS" | "ERROR"; | ||
status: "SUCCESS" | "ERROR" | "CANCELLED" | "TIMEOUT"; | ||
/** | ||
@@ -22,32 +22,2 @@ * | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
timestamp: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
serviceName: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
serviceMaintainer: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
operationId: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
resultActionId?: string; | ||
/** | ||
* | ||
* @type {EndRequestLogResult} | ||
@@ -89,95 +59,2 @@ * @memberof EndRequestLog | ||
message?: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof ExceptionLog | ||
*/ | ||
stackTrace?: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof ExceptionLog | ||
*/ | ||
exceptionClass?: string; | ||
/** | ||
* | ||
* @type {ExceptionLogDetails} | ||
* @memberof ExceptionLog | ||
*/ | ||
details?: ExceptionLogDetails; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface ExceptionLogDetails | ||
*/ | ||
export interface ExceptionLogDetails { | ||
/** | ||
* | ||
* @type {HttpLog} | ||
* @memberof ExceptionLogDetails | ||
*/ | ||
httpLog?: HttpLog; | ||
/** | ||
* | ||
* @type {ScriptExceptionLog} | ||
* @memberof ExceptionLogDetails | ||
*/ | ||
scriptExceptionLog?: ScriptExceptionLog; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof ExceptionLogDetails | ||
*/ | ||
type: "HTTP" | "SCRIPTEXCEPTION" | "DETAILSNOTSET"; | ||
} | ||
/** | ||
* Encapsulates information about an http request during a service query | ||
* @export | ||
* @interface HttpLog | ||
*/ | ||
export interface HttpLog { | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof HttpLog | ||
*/ | ||
uri: string; | ||
/** | ||
* | ||
* @type {number} | ||
* @memberof HttpLog | ||
*/ | ||
statusCode: number; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof HttpLog | ||
*/ | ||
response?: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof HttpLog | ||
*/ | ||
curlCommand?: string; | ||
} | ||
/** | ||
* Encapsulates information about a javascript exception during a service query | ||
* @export | ||
* @interface ScriptExceptionLog | ||
*/ | ||
export interface ScriptExceptionLog { | ||
/** | ||
* | ||
* @type {number} | ||
* @memberof ScriptExceptionLog | ||
*/ | ||
line: number; | ||
/** | ||
* | ||
* @type {number} | ||
* @memberof ScriptExceptionLog | ||
*/ | ||
column?: number; | ||
} |
@@ -21,8 +21,10 @@ import { EndRequestLog } from "."; | ||
constructor(serviceMaintainer: string, serviceName: string, transpositUrl: string); | ||
private getConsumeKey(); | ||
private retrieveClientClaims(); | ||
private persistClientClaims(clientClaimsJSON); | ||
private clearClientClaims(); | ||
private appUrl(relativePath?); | ||
handleLogin(): void; | ||
private getConsumeKey; | ||
private retrieveClientClaims; | ||
private persistClientClaims; | ||
private clearClientClaims; | ||
private appUrl; | ||
handleLogin(callback?: (info: { | ||
needsKeys: boolean; | ||
}) => void): void; | ||
logOut(): Promise<void>; | ||
@@ -29,0 +31,0 @@ getConnectLocation(requestUri?: string): string; |
@@ -8,9 +8,13 @@ /* | ||
roots: ["<rootDir>/src/"], | ||
transform: { | ||
"^.+\\.ts$": "<rootDir>/node_modules/ts-jest/preprocessor.js", | ||
}, | ||
testRegex: "(/__tests__/.*|\\.(test|spec))\\.ts$", | ||
testMatch: null, | ||
moduleFileExtensions: ["ts", "js", "json"], | ||
setupFiles: ["jest-localstorage-mock"], | ||
testEnvironment: "jest-environment-jsdom-global" | ||
}; | ||
preset: "ts-jest/presets/default", | ||
setupTestFrameworkScriptFile: "<rootDir>/src/test/test-setup.ts", | ||
verbose: false, | ||
globals: { | ||
"ts-jest": { | ||
diagnostics: false, | ||
}, | ||
}, | ||
}; |
{ | ||
"name": "transposit", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Library for building apps on top of Transposit", | ||
@@ -14,5 +14,5 @@ "main": "dist/bundle.dev.js", | ||
"build:prod": "webpack --config webpack.config.prod.js", | ||
"jest": "jest", | ||
"jest:ci": "JEST_JUNIT_OUTPUT=\"./target/surefire-reports/client-sdk-test-results.xml\" jest --ci --runInBand", | ||
"jest:watch": "jest --watch", | ||
"jest": "JEST_JUNIT_OUTPUT=\"./target/surefire-reports/client-sdk-test-results.xml\" jest", | ||
"jest:ci": "yarn run jest --ci --runInBand", | ||
"jest:watch": "yarn run jest --watch", | ||
"prettier:check": "prettier --list-different 'src/**/*.ts'", | ||
@@ -25,21 +25,19 @@ "prettier:fix": "prettier 'src/**/*.ts' --write", | ||
"prepublishOnly": "npm-run-all --parallel build test", | ||
"serve": "echo \"Request the SDK from https://monkey.transposit.com/bananas/sdk/dist/bundle.dev.js...\"; python -m SimpleHTTPServer 8066" | ||
"serve": "echo \"Request the SDK from https://monkey.transposit.com/bananas/sdk/dist/bundle.dev.js\"; python -m SimpleHTTPServer 8066" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/jest": "^22.1.2", | ||
"@types/jsdom": "^11.0.4", | ||
"jest": "^22.3.0", | ||
"jest-environment-jsdom": "^22.4.3", | ||
"jest-environment-jsdom-global": "^1.0.3", | ||
"@types/jest": "^23.3.10", | ||
"@types/jsdom": "^12.2.0", | ||
"jest": "^23.6.0", | ||
"jest-junit": "^5.2.0", | ||
"jest-localstorage-mock": "^2.2.0", | ||
"jest-localstorage-mock": "^2.3.0", | ||
"npm-run-all": "^4.1.2", | ||
"prettier": "^1.10.2", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "^22.0.4", | ||
"ts-jest": "^23.10.5", | ||
"ts-loader": "^4.0.1", | ||
"tslint": "^5.9.1", | ||
"tslint-config-prettier": "^1.8.0", | ||
"typescript": "^2.7.1", | ||
"typescript": "^3.2.1", | ||
"webpack": "^4.1.1", | ||
@@ -46,0 +44,0 @@ "webpack-cli": "^2.0.11" |
@@ -5,3 +5,2 @@ /* | ||
import { JSDOM } from "jsdom"; | ||
import { Transposit, TRANSPOSIT_CONSUME_KEY_PREFIX } from "../Transposit"; | ||
@@ -16,7 +15,5 @@ import DoneCallback = jest.DoneCallback; | ||
declare const jsdom: JSDOM; // Globally available in Jest | ||
describe("Transposit", () => { | ||
beforeEach(() => { | ||
window.location.assign = jest.fn(); | ||
jest.clearAllMocks(); | ||
}); | ||
@@ -44,6 +41,5 @@ | ||
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims); | ||
jsdom.reconfigure({ | ||
url: `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=false`, | ||
}); | ||
window.location.href = `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=false`; | ||
const transposit: Transposit = makeArbysTransposit(); | ||
@@ -59,3 +55,7 @@ transposit.handleLogin(); | ||
).toEqual(jplaceArbysClaims); | ||
expect(jsdom.window.location.assign).toHaveBeenCalledWith("/"); | ||
expect(window.history.replaceState).toHaveBeenCalledWith( | ||
{}, | ||
window.document.title, | ||
"/", | ||
); | ||
}); | ||
@@ -65,6 +65,5 @@ | ||
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims); | ||
jsdom.reconfigure({ | ||
url: `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=true`, | ||
}); | ||
window.location.href = `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=true`; | ||
const transposit: Transposit = makeArbysTransposit(); | ||
@@ -80,3 +79,3 @@ transposit.handleLogin(); | ||
).toEqual(jplaceArbysClaims); | ||
expect(jsdom.window.location.assign).toHaveBeenCalledWith( | ||
expect(window.location.href).toEqual( | ||
"https://monkey.transposit.com/app/jplace/arbys_beef/connect?redirectUri=%2F", | ||
@@ -86,6 +85,42 @@ ); | ||
it("calls callback on login", () => { | ||
const mockCallback = jest.fn(); | ||
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims); | ||
window.location.href = `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=true`; | ||
const transposit: Transposit = makeArbysTransposit(); | ||
transposit.handleLogin(mockCallback); | ||
expect( | ||
JSON.parse( | ||
localStorage.getItem( | ||
`${TRANSPOSIT_CONSUME_KEY_PREFIX}/jplace/arbys_beef`, | ||
)!, | ||
), | ||
).toEqual(jplaceArbysClaims); | ||
expect(mockCallback).toHaveBeenCalledWith({ needsKeys: true }); | ||
expect(window.history.replaceState).not.toHaveBeenCalled(); | ||
expect(window.location.href).toEqual( | ||
`https://arbys.com/?clientJwt=${clientJwt}&needsKeys=true`, | ||
); | ||
}); | ||
it("throws if callback is not a function", (done: DoneCallback) => { | ||
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims); | ||
window.location.href = `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=true`; | ||
const transposit: Transposit = makeArbysTransposit(); | ||
try { | ||
transposit.handleLogin("string" as any); | ||
done.fail(); | ||
} catch (err) { | ||
expect(err.message).toContain("Provided callback is not a function."); | ||
done(); | ||
} | ||
}); | ||
it("throws without jwt", (done: DoneCallback) => { | ||
jsdom.reconfigure({ | ||
url: `https://arbys.com/`, | ||
}); | ||
window.location.href = `https://arbys.com/`; | ||
@@ -106,6 +141,5 @@ const transposit: Transposit = makeArbysTransposit(); | ||
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims); | ||
jsdom.reconfigure({ | ||
url: `https://arbys.com/?clientJwt=${clientJwt}`, | ||
}); | ||
window.location.href = `https://arbys.com/?clientJwt=${clientJwt}`; | ||
const transposit: Transposit = makeArbysTransposit(); | ||
@@ -124,5 +158,3 @@ try { | ||
function testInvalidJwt(done: DoneCallback, invalidJwt: string) { | ||
jsdom.reconfigure({ | ||
url: `https://arbys.com/?clientJwt=${invalidJwt}&needsKeys=false`, | ||
}); | ||
window.location.href = `https://arbys.com/?clientJwt=${invalidJwt}&needsKeys=false`; | ||
@@ -166,6 +198,5 @@ const transposit: Transposit = makeArbysTransposit(); | ||
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims); | ||
jsdom.reconfigure({ | ||
url: `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=false`, | ||
}); | ||
window.location.href = `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=false`; | ||
transposit = makeArbysTransposit(); | ||
@@ -178,3 +209,5 @@ transposit.handleLogin(); | ||
jsdom.window.fetch = jest.fn(() => Promise.resolve()); | ||
(window.fetch as jest.Mock<{}>).mockImplementation(() => | ||
Promise.resolve(), | ||
); | ||
@@ -181,0 +214,0 @@ await transposit.logOut(); |
@@ -16,3 +16,3 @@ /* | ||
*/ | ||
status: "SUCCESS" | "ERROR"; | ||
status: "SUCCESS" | "ERROR" | "CANCELLED" | "TIMEOUT"; | ||
/** | ||
@@ -26,32 +26,2 @@ * | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
timestamp: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
serviceName: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
serviceMaintainer: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
operationId: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof EndRequestLog | ||
*/ | ||
resultActionId?: string; | ||
/** | ||
* | ||
* @type {EndRequestLogResult} | ||
@@ -62,2 +32,3 @@ * @memberof EndRequestLog | ||
} | ||
/** | ||
@@ -95,97 +66,2 @@ * | ||
message?: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof ExceptionLog | ||
*/ | ||
stackTrace?: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof ExceptionLog | ||
*/ | ||
exceptionClass?: string; | ||
/** | ||
* | ||
* @type {ExceptionLogDetails} | ||
* @memberof ExceptionLog | ||
*/ | ||
details?: ExceptionLogDetails; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface ExceptionLogDetails | ||
*/ | ||
export interface ExceptionLogDetails { | ||
/** | ||
* | ||
* @type {HttpLog} | ||
* @memberof ExceptionLogDetails | ||
*/ | ||
httpLog?: HttpLog; | ||
/** | ||
* | ||
* @type {ScriptExceptionLog} | ||
* @memberof ExceptionLogDetails | ||
*/ | ||
scriptExceptionLog?: ScriptExceptionLog; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof ExceptionLogDetails | ||
*/ | ||
type: "HTTP" | "SCRIPTEXCEPTION" | "DETAILSNOTSET"; | ||
} | ||
/** | ||
* Encapsulates information about an http request during a service query | ||
* @export | ||
* @interface HttpLog | ||
*/ | ||
export interface HttpLog { | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof HttpLog | ||
*/ | ||
uri: string; | ||
/** | ||
* | ||
* @type {number} | ||
* @memberof HttpLog | ||
*/ | ||
statusCode: number; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof HttpLog | ||
*/ | ||
response?: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof HttpLog | ||
*/ | ||
curlCommand?: string; | ||
} | ||
/** | ||
* Encapsulates information about a javascript exception during a service query | ||
* @export | ||
* @interface ScriptExceptionLog | ||
*/ | ||
export interface ScriptExceptionLog { | ||
/** | ||
* | ||
* @type {number} | ||
* @memberof ScriptExceptionLog | ||
*/ | ||
line: number; | ||
/** | ||
* | ||
* @type {number} | ||
* @memberof ScriptExceptionLog | ||
*/ | ||
column?: number; | ||
} |
@@ -75,3 +75,3 @@ /* | ||
handleLogin(): void { | ||
handleLogin(callback?: (info: { needsKeys: boolean }) => void): void { | ||
// Read query parameters | ||
@@ -121,8 +121,21 @@ | ||
// Redirect now that login has succeeded | ||
// Login has succeeded, either callback or default path replacement | ||
if (needsKeys) { | ||
window.location.assign(this.getConnectLocation(window.location.pathname)); | ||
if (callback) { | ||
if (typeof callback !== "function") { | ||
throw new Error("Provided callback is not a function."); | ||
} | ||
callback({ needsKeys }); | ||
} else { | ||
window.location.assign(window.location.pathname); | ||
if (needsKeys) { | ||
window.location.href = this.getConnectLocation( | ||
window.location.pathname, | ||
); | ||
} else { | ||
window.history.replaceState( | ||
{}, | ||
document.title, | ||
window.location.pathname, | ||
); | ||
} | ||
} | ||
@@ -129,0 +142,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15
23
74701
1245