refactor: remove query-string dependency

This commit is contained in:
janniks
2023-01-30 18:13:49 +01:00
committed by janniks
parent 08e80efb90
commit da20e74bf9
4 changed files with 10 additions and 23 deletions

4
package-lock.json generated
View File

@@ -25002,8 +25002,7 @@
"@stacks/network": "^6.1.1",
"@stacks/profile": "^6.1.1",
"cross-fetch": "^3.1.5",
"jsontokens": "^4.0.1",
"query-string": "^6.13.1"
"jsontokens": "^4.0.1"
},
"devDependencies": {
"process": "^0.11.10",
@@ -29952,7 +29951,6 @@
"cross-fetch": "^3.1.5",
"jsontokens": "^4.0.1",
"process": "^0.11.10",
"query-string": "^6.13.1",
"rimraf": "^3.0.2"
}
},

View File

@@ -25,8 +25,7 @@
"@stacks/network": "^6.1.1",
"@stacks/profile": "^6.1.1",
"cross-fetch": "^3.1.5",
"jsontokens": "^4.0.1",
"query-string": "^6.13.1"
"jsontokens": "^4.0.1"
},
"devDependencies": {
"process": "^0.11.10",

View File

@@ -1,4 +1,3 @@
import * as queryString from 'query-string';
import { decodeToken } from 'jsontokens';
import { BLOCKSTACK_HANDLER, getGlobalObject } from '@stacks/common';
import { createFetchFn, FetchFn } from '@stacks/network';
@@ -10,21 +9,14 @@ import { createFetchFn, FetchFn } from '@stacks/network';
* @private
* @ignore
*/
export function getAuthRequestFromURL() {
export function getAuthRequestFromURL(): string | null {
const location = getGlobalObject('location', {
throwIfUnavailable: true,
usageDesc: 'getAuthRequestFromURL',
});
if (location?.search) {
const queryDict = queryString.parse(location?.search);
if (queryDict.authRequest) {
return (queryDict.authRequest as string).split(`${BLOCKSTACK_HANDLER}:`).join('');
} else {
return null;
}
} else {
return null;
}
const params = new URLSearchParams(location?.search);
return params.get('authRequest')?.replaceAll(`${BLOCKSTACK_HANDLER}:`, '') ?? null;
}
/**

View File

@@ -23,7 +23,7 @@ import {
} from '@stacks/common';
import { extractProfile } from '@stacks/profile';
import { AuthScope, DEFAULT_PROFILE } from './constants';
import * as queryString from 'query-string';
import { UserData } from './userData';
import { createFetchFn, FetchFn, StacksMainnet } from '@stacks/network';
import { protocolEchoReplyDetection } from './protocolEchoDetection';
@@ -162,11 +162,9 @@ export class UserSession {
throwIfUnavailable: true,
usageDesc: 'getAuthResponseToken',
})?.search;
if (search) {
const queryDict = queryString.parse(search);
return queryDict.authResponse ? (queryDict.authResponse as string) : '';
}
return '';
const params = new URLSearchParams(search);
return params.get('authResponse') ?? '';
}
/**