diff --git a/.changeset/cold-sloths-arrive.md b/.changeset/cold-sloths-arrive.md new file mode 100644 index 00000000..e3d57f7c --- /dev/null +++ b/.changeset/cold-sloths-arrive.md @@ -0,0 +1,5 @@ +--- +'@bnb-chain/greenfield-js-sdk': patch +--- + +feat: Support source map diff --git a/.changeset/eight-comics-wait.md b/.changeset/eight-comics-wait.md new file mode 100644 index 00000000..9c4c3b89 --- /dev/null +++ b/.changeset/eight-comics-wait.md @@ -0,0 +1,5 @@ +--- +'@bnb-chain/greenfield-js-sdk': patch +--- + +feat: Verify Address diff --git a/packages/js-sdk/rollup.config.js b/packages/js-sdk/rollup.config.js index 6df2b29f..9c6c0651 100644 --- a/packages/js-sdk/rollup.config.js +++ b/packages/js-sdk/rollup.config.js @@ -21,6 +21,7 @@ export default async () => { output: { dir: './dist/esm', format: 'esm', + sourcemap: true, }, external: resolveExternal(), context: 'window', @@ -55,6 +56,7 @@ export default async () => { output: { dir: './dist/cjs', format: 'cjs', + sourcemap: true, }, external: resolveExternal(), plugins: [ diff --git a/packages/js-sdk/src/api/bucket.ts b/packages/js-sdk/src/api/bucket.ts index 43f3094b..dba8b0ce 100644 --- a/packages/js-sdk/src/api/bucket.ts +++ b/packages/js-sdk/src/api/bucket.ts @@ -93,7 +93,7 @@ import type { ReadQuotaRequest, SpResponse, } from '../types/sp'; -import { isValidAddress, verifyBucketName, verifyUrl } from '../utils/asserts/s3'; +import { verifyAddress, verifyBucketName, verifyUrl } from '../utils/asserts/s3'; import { decodeObjectFromHexString } from '../utils/encoding'; import { Sp } from './sp'; import { Storage } from './storage'; @@ -359,12 +359,9 @@ export class Bucket implements IBucket { public async listBuckets(configParam: GetUserBucketsRequest) { try { const { address, duration = 30000, endpoint } = configParam; - if (!isValidAddress(address)) { - throw new Error('Error address'); - } - if (!verifyUrl(endpoint)) { - throw new Error('Invalid endpoint'); - } + verifyAddress(address); + verifyUrl(endpoint); + const { url } = getUserBucketMetaInfo(endpoint); const headers = new Headers({ @@ -654,9 +651,7 @@ export class Bucket implements IBucket { if (!endpoint) { endpoint = await this.sp.getSPUrlByBucket(bucketName); } - if (!verifyUrl(endpoint)) { - throw new Error('Invalid endpoint'); - } + verifyUrl(endpoint); const { url, optionsWithOutHeaders, reqMeta } = getListBucketReadRecordMetaInfo( endpoint, diff --git a/packages/js-sdk/src/utils/asserts/s3.ts b/packages/js-sdk/src/utils/asserts/s3.ts index 471b8e20..536c1069 100644 --- a/packages/js-sdk/src/utils/asserts/s3.ts +++ b/packages/js-sdk/src/utils/asserts/s3.ts @@ -74,14 +74,9 @@ const verifyObjectName = (objectName?: string) => { } }; -const isValidAddress = (address?: string) => { - if (!address) { - throw new Error('Address is empty, please check.'); - } - if (address.length > 1024) { - throw new Error('Address is limited to 1024 at most, please check.'); - } - return true; +const verifyAddress = (address?: string) => { + if (!address) throw new Error('Address is empty, please check.'); + if (address.length > 1024) throw new Error('Address is limited to 1024 at most, please check.'); }; const verifyUrl = (url?: string) => { @@ -93,9 +88,9 @@ const verifyUrl = (url?: string) => { '(\\:\\d{1,5})?' + // 端口号 '(\\/[-a-zA-Z\\d%_.~+]*)*' + // 路径 '(\\?[;&a-zA-Z\\d%_.~+=-]*)?' + // 查询字符串 - '(\\#[-a-zA-Z\\d_]*)?$', + '(\\#[-a-zA-Z\\d_]*)?$', // 锚点 'i', - ); // 锚点 + ); if (!pattern.test(url)) throw new Error('Invalid endpoint'); }; @@ -122,7 +117,7 @@ const generateUrlByBucketName = (endpoint = '', bucketName: string) => { export { verifyBucketName, verifyObjectName, - isValidAddress, + verifyAddress, trimString, verifyUrl, generateUrlByBucketName,