New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

transposit

Package Overview
Dependencies
Maintainers
5
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

transposit - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

21

dist/bundle.dev.js

@@ -175,3 +175,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

Transposit.prototype.handleLogin = function () {
// Read clientJwt query parameter
// Read query parameters
var maybeClientJwtString = getParameterByName("clientJwt");

@@ -182,3 +182,8 @@ if (maybeClientJwtString === null) {

var clientJwtString = maybeClientJwtString;
// Parse JWT string
var maybeNeedsKeys = getParameterByName("needsKeys");
if (maybeNeedsKeys === null) {
throw new Error("needsKeys query parameter could not be found. This is unexpected.");
}
var needsKeys = maybeNeedsKeys === "true";
// Parse JWT string and persist claims
var jwtParts = clientJwtString.split(".");

@@ -195,5 +200,4 @@ if (jwtParts.length !== 3) {

}
var clientClaimsObj;
try {
clientClaimsObj = JSON.parse(clientClaimsJSON);
JSON.parse(clientClaimsJSON); // validate JSON
}

@@ -203,5 +207,10 @@ catch (err) {

}
// Persist in local storage
this.persistClientClaims(clientClaimsJSON);
return clientClaimsObj.sub;
// Redirect now that login has succeeded
if (needsKeys) {
window.location.assign(this.getConnectLocation(window.location.pathname));
}
else {
window.location.assign(window.location.pathname);
}
};

@@ -208,0 +217,0 @@ Transposit.prototype.logOut = function () {

@@ -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{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(a,l)}s((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=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,l])}}};var i=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=function(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}("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,n,r=e.split(".");if(3!==r.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{t=atob(r[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{n=JSON.parse(t)}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.")}return this.persistClientClaims(t),n.sub},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 i})}])});
!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})}])});
//# sourceMappingURL=bundle.prod.map

@@ -26,3 +26,3 @@ import { EndRequestLog } from ".";

private appUrl(relativePath?);
handleLogin(): string;
handleLogin(): void;
logOut(): Promise<void>;

@@ -29,0 +29,0 @@ getConnectLocation(requestUri?: string): string;

{
"name": "transposit",
"version": "0.4.2",
"version": "0.5.0",
"description": "Library for building apps on top of Transposit",

@@ -5,0 +5,0 @@ "main": "dist/bundle.dev.js",

@@ -18,2 +18,6 @@ /*

describe("Transposit", () => {
beforeEach(() => {
window.location.assign = jest.fn();
});
const jplaceArbysClaims: any = Object.freeze({

@@ -37,12 +41,11 @@ iss: "https://monkey.transposit.com",

describe("login", () => {
it("handles valid login", () => {
it("redirects on login", () => {
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims);
jsdom.reconfigure({
url: `https://arbys.com/?clientJwt=${clientJwt}`,
url: `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=false`,
});
const transposit: Transposit = makeArbysTransposit();
const sub: string = transposit.handleLogin();
transposit.handleLogin();
expect(sub).toBe(jplaceArbysClaims.sub);
expect(

@@ -55,6 +58,28 @@ JSON.parse(

).toEqual(jplaceArbysClaims);
expect(jsdom.window.location.assign).toHaveBeenCalledWith("/");
});
it("handles login without jwt", (done: DoneCallback) => {
it("redirects when needs keys", () => {
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims);
jsdom.reconfigure({
url: `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=true`,
});
const transposit: Transposit = makeArbysTransposit();
transposit.handleLogin();
expect(
JSON.parse(
localStorage.getItem(
`${TRANSPOSIT_CONSUME_KEY_PREFIX}/jplace/arbys_beef`,
)!,
),
).toEqual(jplaceArbysClaims);
expect(jsdom.window.location.assign).toHaveBeenCalledWith(
"https://monkey.transposit.com/app/jplace/arbys_beef/connect?redirectUri=%2F",
);
});
it("throws without jwt", (done: DoneCallback) => {
jsdom.reconfigure({
url: `https://arbys.com/`,

@@ -75,5 +100,23 @@ });

it("throws without needsKeys", (done: DoneCallback) => {
const clientJwt: string = createUnsignedJwt(jplaceArbysClaims);
jsdom.reconfigure({
url: `https://arbys.com/?clientJwt=${clientJwt}`,
});
const transposit: Transposit = makeArbysTransposit();
try {
transposit.handleLogin();
done.fail();
} catch (err) {
expect(err.message).toContain(
"needsKeys query parameter could not be found. This is unexpected.",
);
done();
}
});
function testInvalidJwt(done: DoneCallback, invalidJwt: string) {
jsdom.reconfigure({
url: `https://arbys.com/?clientJwt=${invalidJwt}`,
url: `https://arbys.com/?clientJwt=${invalidJwt}&needsKeys=false`,
});

@@ -93,15 +136,15 @@

it("handles login with invalid jwt (empty)", (done: DoneCallback) => {
it("throws with invalid jwt (empty)", (done: DoneCallback) => {
testInvalidJwt(done, "");
});
it("handles login with invalid jwt (not-properly formatted jwt)", (done: DoneCallback) => {
it("throws with invalid jwt (not-properly formatted jwt)", (done: DoneCallback) => {
testInvalidJwt(done, "adsfasfdfd.fdsafadfsf");
});
it("handles login with invalid jwt (not-base64 jwt)", (done: DoneCallback) => {
it("throws with invalid jwt (not-base64 jwt)", (done: DoneCallback) => {
testInvalidJwt(done, "dffgdf--6667.fdsaf#f.");
});
it("handles login with invalid jwt (not-json jwt)", (done: DoneCallback) => {
it("throws with invalid jwt (not-json jwt)", (done: DoneCallback) => {
testInvalidJwt(

@@ -120,3 +163,3 @@ done,

jsdom.reconfigure({
url: `https://arbys.com/?clientJwt=${clientJwt}`,
url: `https://arbys.com/?clientJwt=${clientJwt}&needsKeys=false`,
});

@@ -123,0 +166,0 @@

@@ -75,4 +75,5 @@ /*

handleLogin(): string {
// Read clientJwt query parameter
handleLogin(): void {
// Read query parameters
const maybeClientJwtString = getParameterByName("clientJwt");

@@ -86,3 +87,12 @@ if (maybeClientJwtString === null) {

// Parse JWT string
const maybeNeedsKeys = getParameterByName("needsKeys");
if (maybeNeedsKeys === null) {
throw new Error(
"needsKeys query parameter could not be found. This is unexpected.",
);
}
const needsKeys = maybeNeedsKeys === "true";
// Parse JWT string and persist claims
const jwtParts: string[] = clientJwtString.split(".");

@@ -102,5 +112,4 @@ if (jwtParts.length !== 3) {

}
let clientClaimsObj: ClientClaims;
try {
clientClaimsObj = JSON.parse(clientClaimsJSON);
JSON.parse(clientClaimsJSON); // validate JSON
} catch (err) {

@@ -112,6 +121,11 @@ throw new Error(

// Persist in local storage
this.persistClientClaims(clientClaimsJSON);
return clientClaimsObj.sub;
// Redirect now that login has succeeded
if (needsKeys) {
window.location.assign(this.getConnectLocation(window.location.pathname));
} else {
window.location.assign(window.location.pathname);
}
}

@@ -118,0 +132,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc