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

transposit

Package Overview
Dependencies
Maintainers
6
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 1.0.0 to 1.0.1-rc1

11

dist/bundle.dev.js

@@ -257,4 +257,9 @@ (function webpackUniversalModuleDefinition(root, factory) {

};
Transposit.prototype.startLoginUri = function (redirectUri) {
return this.uri("/login/accounts?redirectUri=" + encodeURIComponent(redirectUri || window.location.href));
Transposit.prototype.startLoginUri = function (redirectUri, provider) {
var params = new URLSearchParams();
params.append("redirectUri", redirectUri || window.location.href);
if (provider) {
params.append("provider", provider);
}
return this.uri("/login/accounts?" + params.toString());
};

@@ -267,3 +272,3 @@ // Deprecated in favor of settingsUri

Transposit.prototype.getGoogleLoginLocation = function (redirectUri) {
return this.startLoginUri(redirectUri);
return this.startLoginUri(redirectUri, "google");
};

@@ -270,0 +275,0 @@ // Deprecated

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Transposit=e():t.Transposit=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);var r=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(a,s)}c((r=r.apply(t,e||[])).next())})},o=function(t,e){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=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=e.call(t,a)}catch(t){i=[6,t],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])}}};var i=function(){function t(t){void 0===t&&(t=""),this.hostedAppOrigin=t,this.claims=null,this.claims=this.loadClaims()}return t.prototype.uri=function(t){return void 0===t&&(t=""),""+this.hostedAppOrigin+t},t.prototype.loadClaims=function(){var t,e=localStorage.getItem("TRANSPOSIT_SESSION");if(!e)return null;try{t=JSON.parse(e)}catch(t){return null}return this.checkClaimsValid(t)?t:null},t.prototype.persistClaims=function(t){localStorage.setItem("TRANSPOSIT_SESSION",t)},t.prototype.clearClaims=function(){localStorage.removeItem("TRANSPOSIT_SESSION")},t.prototype.checkClaimsValid=function(t){return 1e3*t.exp>Date.now()},t.prototype.assertLoggedIn=function(){if(null===this.claims)throw new Error("No client claims found.")},t.prototype.isLoggedIn=function(){return null!==this.claims},t.prototype.handleLogin=function(t){var e=new URLSearchParams(window.location.search);if(!e.has("clientJwt"))throw new Error("clientJwt query parameter could not be found. This method should only be called after redirection during login.");var n=e.get("clientJwt");if(!e.has("needsKeys"))throw new Error("needsKeys query parameter could not be found. This is unexpected.");var r,o,i="true"===e.get("needsKeys"),a=n.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(t){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=JSON.parse(r)}catch(t){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.checkClaimsValid(o))throw new Error("clientJwt query parameter does not appear to be a valid JWT string. clientJwt is expired.");if(this.claims=o,this.persistClaims(r),t){if("function"!=typeof t)throw new Error("Provided callback is not a function.");t({needsKeys:i})}else i?window.location.href=this.settingsUri(""+window.location.origin+window.location.pathname):window.history.replaceState({},document.title,window.location.pathname)},t.prototype.logOut=function(t){this.clearClaims(),this.claims=null,window.location.href=this.uri("/logout?redirectUri="+encodeURIComponent(t))},t.prototype.settingsUri=function(t){return this.uri("/settings?redirectUri="+encodeURIComponent(t||window.location.href))},t.prototype.startLoginUri=function(t){return this.uri("/login/accounts?redirectUri="+encodeURIComponent(t||window.location.href))},t.prototype.getConnectLocation=function(t){return this.settingsUri(t)},t.prototype.getGoogleLoginLocation=function(t){return this.startLoginUri(t)},t.prototype.getLoginLocation=function(){return this.uri("/login")},t.prototype.getUserEmail=function(){return this.assertLoggedIn(),this.claims.email},t.prototype.getUserName=function(){return this.assertLoggedIn(),this.claims.name},t.prototype.runOperation=function(t,e){return void 0===e&&(e={}),r(this,void 0,void 0,function(){var n,r;return o(this,function(o){switch(o.label){case 0:return n={"Content-Type":"application/json"},this.claims&&(n["X-PUBLIC-TOKEN"]=this.claims.publicToken),[4,fetch(this.uri("/api/v1/execute/"+t),{credentials:"include",method:"POST",headers:n,body:JSON.stringify({parameters:e})})];case 1:return(r=o.sent()).status>=200&&r.status<300?[4,r.json()]:[3,3];case 2:return[2,o.sent()];case 3:throw r}})})},t}();n.d(e,"LOCAL_STORAGE_KEY",function(){return"TRANSPOSIT_SESSION"}),n.d(e,"Transposit",function(){return i})}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Transposit=e():t.Transposit=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);var r=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(a,s)}c((r=r.apply(t,e||[])).next())})},o=function(t,e){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=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=e.call(t,a)}catch(t){i=[6,t],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])}}};var i=function(){function t(t){void 0===t&&(t=""),this.hostedAppOrigin=t,this.claims=null,this.claims=this.loadClaims()}return t.prototype.uri=function(t){return void 0===t&&(t=""),""+this.hostedAppOrigin+t},t.prototype.loadClaims=function(){var t,e=localStorage.getItem("TRANSPOSIT_SESSION");if(!e)return null;try{t=JSON.parse(e)}catch(t){return null}return this.checkClaimsValid(t)?t:null},t.prototype.persistClaims=function(t){localStorage.setItem("TRANSPOSIT_SESSION",t)},t.prototype.clearClaims=function(){localStorage.removeItem("TRANSPOSIT_SESSION")},t.prototype.checkClaimsValid=function(t){return 1e3*t.exp>Date.now()},t.prototype.assertLoggedIn=function(){if(null===this.claims)throw new Error("No client claims found.")},t.prototype.isLoggedIn=function(){return null!==this.claims},t.prototype.handleLogin=function(t){var e=new URLSearchParams(window.location.search);if(!e.has("clientJwt"))throw new Error("clientJwt query parameter could not be found. This method should only be called after redirection during login.");var n=e.get("clientJwt");if(!e.has("needsKeys"))throw new Error("needsKeys query parameter could not be found. This is unexpected.");var r,o,i="true"===e.get("needsKeys"),a=n.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(t){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=JSON.parse(r)}catch(t){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.checkClaimsValid(o))throw new Error("clientJwt query parameter does not appear to be a valid JWT string. clientJwt is expired.");if(this.claims=o,this.persistClaims(r),t){if("function"!=typeof t)throw new Error("Provided callback is not a function.");t({needsKeys:i})}else i?window.location.href=this.settingsUri(""+window.location.origin+window.location.pathname):window.history.replaceState({},document.title,window.location.pathname)},t.prototype.logOut=function(t){this.clearClaims(),this.claims=null,window.location.href=this.uri("/logout?redirectUri="+encodeURIComponent(t))},t.prototype.settingsUri=function(t){return this.uri("/settings?redirectUri="+encodeURIComponent(t||window.location.href))},t.prototype.startLoginUri=function(t,e){var n=new URLSearchParams;return n.append("redirectUri",t||window.location.href),e&&n.append("provider",e),this.uri("/login/accounts?"+n.toString())},t.prototype.getConnectLocation=function(t){return this.settingsUri(t)},t.prototype.getGoogleLoginLocation=function(t){return this.startLoginUri(t,"google")},t.prototype.getLoginLocation=function(){return this.uri("/login")},t.prototype.getUserEmail=function(){return this.assertLoggedIn(),this.claims.email},t.prototype.getUserName=function(){return this.assertLoggedIn(),this.claims.name},t.prototype.runOperation=function(t,e){return void 0===e&&(e={}),r(this,void 0,void 0,function(){var n,r;return o(this,function(o){switch(o.label){case 0:return n={"Content-Type":"application/json"},this.claims&&(n["X-PUBLIC-TOKEN"]=this.claims.publicToken),[4,fetch(this.uri("/api/v1/execute/"+t),{credentials:"include",method:"POST",headers:n,body:JSON.stringify({parameters:e})})];case 1:return(r=o.sent()).status>=200&&r.status<300?[4,r.json()]:[3,3];case 2:return[2,o.sent()];case 3:throw r}})})},t}();n.d(e,"LOCAL_STORAGE_KEY",function(){return"TRANSPOSIT_SESSION"}),n.d(e,"Transposit",function(){return i})}])});
//# sourceMappingURL=bundle.prod.map

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

settingsUri(redirectUri?: string): string;
startLoginUri(redirectUri?: string): string;
startLoginUri(redirectUri?: string, provider?: "google" | "slack"): string;
getConnectLocation(redirectUri?: string): string;

@@ -35,0 +35,0 @@ getGoogleLoginLocation(redirectUri?: string): string;

@@ -61,5 +61,5 @@ ---

```
<button type="button" onclick="loginWithGoogle()">Login</button>
<button type="button" onclick="startLogin()">Login</button>
function loginWithGoogle() {
function startLogin() {
window.location.href =

@@ -71,3 +71,3 @@ transposit.startLoginUri(window.location.origin +

This kicks off the login flow with Transposit and Google. The provided URL tells Transposit where to send the user after a successful login. This is where the SDK comes into the picture. On the page that the user has been redirected to, simply call:
This kicks off the login flow with Transposit. The provided URL tells Transposit where to send the user after a successful login. This is where the SDK comes into the picture. On the page that the user has been redirected to, simply call:

@@ -74,0 +74,0 @@ ```javascript

@@ -9,3 +9,3 @@ # Reference

Reads login information from the url and stores the claims object in localStorage for use in subsequent api calls. This is used after google login redirect. This function redirects the user to authenticate if they are missing credentials.
Reads login information from the url and stores the claims object in localStorage for use in subsequent api calls. This is used after login redirect. This function redirects the user to authenticate if they are missing credentials.

@@ -90,5 +90,5 @@ If a callback is provided, it will be called after successful login.

## Get URI to start Google login
## Get URI to start login
`transposit.startLoginUri([redirectUri=window.location.href])`
`transposit.startLoginUri([redirectUri=window.location.href], [provider])`

@@ -98,4 +98,5 @@ | Argument | Type | |

| [redirectUri=window.location.href] | String | an optional param to specify an alternate redirectUri |
| [provider] | String | an optional param to specify a login provider |
**Returns** (String): A url to redirect to for google login.
**Returns** (String): Location to start login.

@@ -102,0 +103,0 @@ **Example**

{
"name": "transposit",
"version": "1.0.0",
"version": "1.0.1-rc1",
"author": "Transposit",

@@ -5,0 +5,0 @@ "description": "SDK for web apps using Transposit as a backend",

@@ -66,3 +66,3 @@ <img src="https://www.transposit.com/img/transposit-logo-black.png" width="182px" alt="Transposit"/>

Create a page that displays a sign-in button. Use the SDK to begin Google sign-in when the button is clicked.
Create a page that displays a sign-in button. Use the SDK to begin sign-in when the button is clicked.

@@ -69,0 +69,0 @@ ```html

@@ -262,3 +262,3 @@ /*

describe("startLoginUri", () => {
it("returns the correct location", () => {
it("returns the correct default location", () => {
const transposit: Transposit = new Transposit(ARBYS_ORIGIN);

@@ -269,7 +269,23 @@

);
});
it("returns the correct google location", () => {
const transposit: Transposit = new Transposit(ARBYS_ORIGIN);
expect(transposit.startLoginUri("https://altoids.com", "google")).toEqual(
"https://arbys-beef-xyz12.transposit.io/login/accounts?redirectUri=https%3A%2F%2Faltoids.com&provider=google",
);
expect(transposit.getGoogleLoginLocation("https://altoids.com")).toEqual(
"https://arbys-beef-xyz12.transposit.io/login/accounts?redirectUri=https%3A%2F%2Faltoids.com",
"https://arbys-beef-xyz12.transposit.io/login/accounts?redirectUri=https%3A%2F%2Faltoids.com&provider=google",
);
});
it("returns the correct slack location", () => {
const transposit: Transposit = new Transposit(ARBYS_ORIGIN);
expect(transposit.startLoginUri("https://altoids.com", "slack")).toEqual(
"https://arbys-beef-xyz12.transposit.io/login/accounts?redirectUri=https%3A%2F%2Faltoids.com&provider=slack",
);
});
});
});

@@ -187,8 +187,9 @@ /*

startLoginUri(redirectUri?: string): string {
return this.uri(
`/login/accounts?redirectUri=${encodeURIComponent(
redirectUri || window.location.href,
)}`,
);
startLoginUri(redirectUri?: string, provider?: "google" | "slack"): string {
const params = new URLSearchParams();
params.append("redirectUri", redirectUri || window.location.href);
if (provider) {
params.append("provider", provider);
}
return this.uri(`/login/accounts?${params.toString()}`);
}

@@ -203,3 +204,3 @@

getGoogleLoginLocation(redirectUri?: string): string {
return this.startLoginUri(redirectUri);
return this.startLoginUri(redirectUri, "google");
}

@@ -206,0 +207,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