@sheet2db/sdk 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/src/index.ts +5 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheet2db/sdk",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "dependencies": {
@@ -14,7 +14,8 @@
14
14
  "tsup": "^8.5.0",
15
15
  "jest": "^29.7.0",
16
16
  "ts-jest": "^29.3.4",
17
- "@types/jest": "^29.5.14"
17
+ "@types/jest": "^29.5.14",
18
+ "ts-node":"^10.9.2"
18
19
  },
19
20
  "scripts": {
20
21
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/index.ts CHANGED
@@ -7,8 +7,9 @@ export class Sheet2DBClient {
7
7
  axios: AxiosInstance
8
8
  constructor(apiId: string, version = 'v1' as const) {
9
9
  if (!apiId?.trim()) throw new Error('apiId is required to create a Sheet2DBClient.');
10
+ const baseURL = (typeof process != 'undefined' && process.env.SHEET2DB_BASE_URL) || 'https://api.sheet2db.io/' + version + '/data/' + apiId
10
11
  this.axios = axios.create({
11
- baseURL: (typeof process != 'undefined' && process.env.SHEET2DB_BASE_URL) || 'https://api.sheet2db.io/' + version + '/data/' + apiId,
12
+ baseURL: baseURL,
12
13
  paramsSerializer: {
13
14
  serialize: (params) => new URLSearchParams(params).toString()
14
15
  }
@@ -21,7 +22,7 @@ export class Sheet2DBClient {
21
22
  });
22
23
  }
23
24
  private endpoint(sheet?: string): string {
24
- return sheet ? `/${sheet}` : '/';
25
+ return sheet ? `/${sheet}` : '';
25
26
  }
26
27
  useBasicAuthentication(username: string, password: string) {
27
28
  const token = isNode ? Buffer.from(`${username}:${password}`).toString('base64') : btoa(`${username}:${password}`)
@@ -36,7 +37,7 @@ export class Sheet2DBClient {
36
37
  this.authentication = 'Bearer ' + token
37
38
  }
38
39
 
39
- async Read<T = any>(options: ReadOptions, sheet?: string): Promise<T> {
40
+ async Read<T = any>(options: Partial<ReadOptions>, sheet?: string): Promise<T> {
40
41
  return this.axios.get(this.endpoint(sheet), {
41
42
  params: options
42
43
  }).then((res) => res.data)
@@ -61,7 +62,7 @@ export class Sheet2DBClient {
61
62
  }
62
63
 
63
64
  async DeleteSheet(sheet: string): Promise<{ ok: true }> {
64
- if(!sheet) throw new Error("sheet is required to Delete Sheet")
65
+ if (!sheet) throw new Error("sheet is required to Delete Sheet")
65
66
  return this.axios.delete(this.endpoint(sheet)).then((res) => res.data)
66
67
  }
67
68
  }