@qubic-connect/redirect
Advanced tools
Comparing version 0.8.5 to 0.8.6
@@ -10,4 +10,5 @@ import { LoginRedirectWalletType, QubicSignInProvider } from './types'; | ||
dataString: string; | ||
action?: 'login' | 'bind'; | ||
} | ||
export interface ResponsePassToConnectSuccess { | ||
export interface ResponsePassToConnectLoginSuccess { | ||
accountAddress: string; | ||
@@ -17,4 +18,11 @@ signature: string; | ||
isQubicUser: boolean; | ||
action?: 'login'; | ||
} | ||
type ResponsePassToConnect = ResponseFail | ResponsePassToConnectSuccess; | ||
export interface ResponsePassToConnectBindSuccess { | ||
bindTicket: string; | ||
expiredAt: number; | ||
action: 'bind'; | ||
} | ||
export type ResponsePassToConnectSuccess = ResponsePassToConnectLoginSuccess | ResponsePassToConnectBindSuccess; | ||
export type ResponsePassToConnect = ResponseFail | ResponsePassToConnectLoginSuccess | ResponsePassToConnectBindSuccess; | ||
export interface RequestPassToWallet { | ||
@@ -26,7 +34,7 @@ ticketRedirectUrl: string; | ||
ticket: string; | ||
expiredAt: string; | ||
expiredAt: number; | ||
address: string; | ||
} | ||
export type ResponseWalletToPassFail = ResponseFail & Partial<RequestConnectToPass>; | ||
type ResponseWalletToPass = ResponseWalletToPassSuccess | ResponseFail; | ||
export type ResponseWalletToPass = ResponseWalletToPassSuccess | ResponseFail; | ||
export declare function createUrlRequestConnectToPass(url: string, options: RequestConnectToPass): string; | ||
@@ -43,2 +51,1 @@ export declare function getResponsePassToConnect(url: string): ResponsePassToConnect; | ||
export declare function createUrlResponseWalletToPassOrConnect(url: string, options: ResponseWalletToPass): string; | ||
export {}; |
@@ -36,2 +36,3 @@ "use strict"; | ||
dataString: encodeURIComponent(options.dataString), | ||
action: options.action, | ||
}; | ||
@@ -51,3 +52,11 @@ return query_string_1.default.stringifyUrl({ | ||
} | ||
if (query.action === 'bind') { | ||
return { | ||
action: 'bind', | ||
bindTicket: query.bindTicket, | ||
expiredAt: Number(query.expiredAt), | ||
}; | ||
} | ||
return { | ||
action: 'login', | ||
accountAddress: query.accountAddress, | ||
@@ -63,4 +72,5 @@ signature: query.signature, | ||
// remove previous result, key of LoginRequest and errorMessage but keep other query params | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
_b = _a.query, accountAddress = _b.accountAddress, signature = _b.signature, dataString = _b.dataString, isQubicUser = _b.isQubicUser, errorMessage = _b.errorMessage, restQuery = __rest(_b, ["accountAddress", "signature", "dataString", "isQubicUser", "errorMessage"]), fragmentIdentifier = _a.fragmentIdentifier; | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
_b = _a.query, accountAddress = _b.accountAddress, signature = _b.signature, dataString = _b.dataString, isQubicUser = _b.isQubicUser, errorMessage = _b.errorMessage, action = _b.action, expiredAt = _b.expiredAt, bindTicket = _b.bindTicket, restQuery = __rest(_b, ["accountAddress", "signature", "dataString", "isQubicUser", "errorMessage", "action", "expiredAt", "bindTicket"]), fragmentIdentifier = _a.fragmentIdentifier; | ||
/* eslint-enable */ | ||
var removedResultUrl = query_string_1.default.stringifyUrl({ | ||
@@ -85,2 +95,3 @@ url: url, | ||
dataString: decodeURIComponent(query.dataString), | ||
action: query.action, | ||
}; | ||
@@ -105,6 +116,7 @@ } | ||
errorMessage: query.errorMessage, | ||
redirectUrl: query.redirectUrl, | ||
}; | ||
} | ||
var ticketRedirectUrlParams = getRequestConnectToPass(url); | ||
return __assign({ ticket: query.ticket, expiredAt: query.expiredAt, address: query.address }, ((ticketRedirectUrlParams === null || ticketRedirectUrlParams === void 0 ? void 0 : ticketRedirectUrlParams.dataString) ? ticketRedirectUrlParams : {})); | ||
return __assign({ ticket: query.ticket, expiredAt: Number(query.expiredAt), address: query.address }, ((ticketRedirectUrlParams === null || ticketRedirectUrlParams === void 0 ? void 0 : ticketRedirectUrlParams.dataString) ? ticketRedirectUrlParams : {})); | ||
} | ||
@@ -125,20 +137,5 @@ exports.getResponseWalletToPass = getResponseWalletToPass; | ||
function createUrlResponsePassToConnect(url, options) { | ||
if ('errorMessage' in options) { | ||
var query_1 = { | ||
errorMessage: options.errorMessage, | ||
}; | ||
return query_string_1.default.stringifyUrl({ | ||
url: url, | ||
query: query_1, | ||
}); | ||
} | ||
var query = { | ||
accountAddress: options.accountAddress, | ||
signature: options.signature, | ||
dataString: options.dataString, | ||
isQubicUser: options.isQubicUser, | ||
}; | ||
return query_string_1.default.stringifyUrl({ | ||
url: url, | ||
query: query, | ||
query: options, | ||
}); | ||
@@ -180,10 +177,7 @@ } | ||
var params = getResponseWalletToPass(nextUrl); | ||
if (!('redirectUrl' in params)) { | ||
if (!('redirectUrl' in params) || !params.redirectUrl || params.action === 'bind') { | ||
// not detecting url just go back to pass | ||
return nextUrl; | ||
} | ||
if (!params.redirectUrl) { | ||
return nextUrl; | ||
} | ||
// go back to connect directly | ||
// if we detect redirectUrl we skip pass web, go to connect sdk directly | ||
if ('errorMessage' in params) { | ||
@@ -195,3 +189,3 @@ return createUrlResponsePassToConnect(params.redirectUrl, { | ||
if (!params.dataString) { | ||
throw Error('params data sting Not found'); | ||
throw Error('params data string Not found'); | ||
} | ||
@@ -203,4 +197,5 @@ return createUrlResponsePassToConnect(params.redirectUrl, { | ||
isQubicUser: true, | ||
action: 'login', | ||
}); | ||
} | ||
exports.createUrlResponseWalletToPassOrConnect = createUrlResponseWalletToPassOrConnect; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils_1 = require("./utils"); | ||
var MOCK_EXPIRED_AT = 1683601793; | ||
describe('utils', function () { | ||
@@ -17,2 +18,15 @@ test('createUrlRequestConnectToPass', function () { | ||
}); | ||
test('createUrlRequestConnectToPass - bind', function () { | ||
var requestConnectToPass = { | ||
walletType: 'qubic', | ||
qubicSignInProvider: 'google', | ||
redirectUrl: 'https://www.mydapp.com', | ||
dataString: JSON.stringify({ foo: 1, bar: 2 }), | ||
action: 'bind', | ||
}; | ||
var targetUrl = (0, utils_1.createUrlRequestConnectToPass)('https://pass.qubic.app', requestConnectToPass); | ||
expect(targetUrl).toBeDefined(); | ||
var result = (0, utils_1.getRequestConnectToPass)(targetUrl); | ||
expect(result).toEqual(requestConnectToPass); | ||
}); | ||
test('createUrlRequestPassToWallet', function () { | ||
@@ -28,6 +42,26 @@ var RequestPassToWallet = { | ||
}); | ||
test('createUrlRequestPassToWallet - incorrect url', function () { | ||
var result = (0, utils_1.getRequestPassToWallet)('https://pass.qubic.app'); | ||
expect(result).toEqual(undefined); | ||
}); | ||
test('createUrlResponseWalletToPassOrConnect - utils incorrect url', function () { | ||
var result = (0, utils_1.createUrlResponseWalletToPassOrConnect)('https://pass.qubic.app', { | ||
ticket: 'mockTicket', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
address: 'mockAddress', | ||
}); | ||
expect(result).toEqual('https://pass.qubic.app?address=mockAddress&expiredAt=mockExpiredAt&ticket=mockTicket'); | ||
}); | ||
test('createUrlResponseWalletToPassOrConnect - utils errorMessage', function () { | ||
var result = (0, utils_1.createUrlResponseWalletToPassOrConnect)('https://pass.qubic.app?errorMessage=hello&redirectUrl=https://myapp.com', { | ||
ticket: 'mockTicket', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
address: 'mockAddress', | ||
}); | ||
expect(result).toEqual('https://myapp.com?errorMessage=hello'); | ||
}); | ||
test('createUrlResponseWalletToPass success', function () { | ||
var responseWalletToPassSuccess = { | ||
ticket: 'ticket', | ||
expiredAt: '123', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
address: '0x123', | ||
@@ -72,3 +106,18 @@ }; | ||
}); | ||
test('createUrlResponsePassToConnect fail', function () { | ||
test('createUrlResponsePassToConnect success - bind', function () { | ||
var responsePassToConnectSuccess = { | ||
action: 'bind', | ||
bindTicket: 'bindTicket', | ||
expiredAt: 1683601582875, | ||
}; | ||
var targetUrl = (0, utils_1.createUrlResponsePassToConnect)('https://pass.qubic.app', responsePassToConnectSuccess); | ||
expect(targetUrl).toBeDefined(); | ||
var result = (0, utils_1.getResponsePassToConnect)(targetUrl); | ||
expect(result).toEqual(responsePassToConnectSuccess); | ||
var cleanedUrl = (0, utils_1.cleanResponsePassToConnect)(targetUrl); | ||
expect(cleanedUrl).not.toContain('action'); | ||
expect(cleanedUrl).not.toContain('bindTicket'); | ||
expect(cleanedUrl).not.toContain('expiredAt'); | ||
}); | ||
test('createUrlResponsePassToConnect fail - utils', function () { | ||
var responseFail = { | ||
@@ -92,2 +141,3 @@ errorMessage: 'Something Wrong', | ||
url = (0, utils_1.createUrlRequestConnectToPass)('https://pass.qubic.app', { | ||
action: 'login', | ||
walletType: 'qubic', | ||
@@ -120,3 +170,3 @@ qubicSignInProvider: 'google', | ||
ticket: 'mockTicket', | ||
expiredAt: 'mockExpiredAt', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
address: 'mockAddress', | ||
@@ -151,2 +201,3 @@ }); | ||
expect(params4).toEqual({ | ||
action: 'login', | ||
accountAddress: 'mockAddress', | ||
@@ -164,2 +215,3 @@ signature: 'mockTicket', | ||
url = (0, utils_1.createUrlRequestConnectToPass)('https://pass.qubic.app', { | ||
action: 'login', | ||
walletType: 'qubic', | ||
@@ -192,3 +244,3 @@ qubicSignInProvider: 'google', | ||
ticket: 'mockTicket', | ||
expiredAt: 'mockExpiredAt', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
address: 'mockAddress', | ||
@@ -202,2 +254,3 @@ }); | ||
expect(params3).toEqual({ | ||
action: 'login', | ||
accountAddress: 'mockAddress', | ||
@@ -209,2 +262,71 @@ signature: 'mockTicket', | ||
}); | ||
test('full flow - bind', function () { | ||
var url = 'https://www.mydapp.com'; | ||
// code connect sdk, dApp | ||
// console.log('--- Qubic Connect SDK ---'); | ||
// console.log(url); | ||
url = (0, utils_1.createUrlRequestConnectToPass)('https://pass.qubic.app', { | ||
walletType: 'qubic', | ||
qubicSignInProvider: 'google', | ||
redirectUrl: url, | ||
dataString: JSON.stringify({ foo: 1, bar: 2 }), | ||
action: 'bind', | ||
}); | ||
// code in pass | ||
var params1 = (0, utils_1.getRequestConnectToPass)(url); | ||
// console.log('--- Qubic Pass ---'); | ||
// console.log(url); | ||
// console.log(params1); | ||
if (!(params1 === null || params1 === void 0 ? void 0 : params1.qubicSignInProvider)) { | ||
throw Error('qubicSignInProvider not exists'); | ||
} | ||
url = (0, utils_1.createUrlRequestPassToWallet)('https://wallet.qubic.app', { | ||
ticketRedirectUrl: url, | ||
provider: params1.qubicSignInProvider, | ||
}); | ||
// wallet | ||
var params2 = (0, utils_1.getRequestPassToWallet)(url); | ||
// console.log('--- Qubic Wallet ---'); | ||
// console.log(url); | ||
if (!params2) { | ||
throw Error('invalid params'); | ||
} | ||
url = (0, utils_1.createUrlResponseWalletToPass)(params2.ticketRedirectUrl, { | ||
ticket: 'mockTicket', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
address: 'mockAddress', | ||
}); | ||
// pass | ||
var params3 = (0, utils_1.getResponseWalletToPass)(url); | ||
// console.log('--- Qubic Pass ---'); | ||
// console.log(url); | ||
// console.log(params3); | ||
if ('errorMessage' in params3) { | ||
throw Error(params3.errorMessage); | ||
} | ||
if (!params3.redirectUrl) { | ||
throw Error('redirectUrl not found'); | ||
} | ||
if (!params3.dataString) { | ||
throw Error('dataString not found'); | ||
} | ||
if (params3.action !== 'bind') { | ||
throw Error('should be bind action'); | ||
} | ||
url = (0, utils_1.createUrlResponsePassToConnect)(params3.redirectUrl, { | ||
action: params3.action, | ||
bindTicket: 'mockedBindTicket', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
}); | ||
// code connect sdk, dApp | ||
var params4 = (0, utils_1.getResponsePassToConnect)(url); | ||
// console.log('--- Qubic Connect SDK ---'); | ||
// console.log(url); | ||
// console.log(params4); | ||
expect(params4).toEqual({ | ||
bindTicket: 'mockedBindTicket', | ||
expiredAt: MOCK_EXPIRED_AT, | ||
action: 'bind', | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "@qubic-connect/redirect", | ||
"version": "0.8.5", | ||
"version": "0.8.6", | ||
"homepage": "https://github.com/getamis/qubic-creator-sdk/tree/main/packages/redirect#readme", | ||
@@ -31,3 +31,3 @@ "license": "ISC", | ||
}, | ||
"gitHead": "1061e65b940eafc6dfff32e4ac1f6c5401de264f" | ||
"gitHead": "e8fc3cf5e74fe6d0f0b616b8197ba5e95c8d6be2" | ||
} |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
30782
10
613
1
75