@sheet2db/sdk 1.0.4 → 1.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.
package/dist/index.d.ts CHANGED
@@ -77,7 +77,7 @@ export type CreateSheetOptions = {
77
77
  export type DeleteSheetOptions = {
78
78
  sheet: string;
79
79
  };
80
- export default class Sheet2DB {
80
+ export declare class Sheet2DB {
81
81
  private readonly options;
82
82
  private apiEndpoint;
83
83
  private fetchFn;
package/dist/index.js CHANGED
@@ -1,48 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __rest = (this && this.__rest) || function (s, e) {
35
- var t = {};
36
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
- t[p] = s[p];
38
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
- t[p[i]] = s[p[i]];
42
- }
43
- return t;
44
- };
45
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sheet2DB = void 0;
46
4
  let fetchFunction;
47
5
  if (typeof window !== 'undefined' && typeof window.fetch !== 'undefined') {
48
6
  // We are in a browser environment
@@ -50,12 +8,10 @@ if (typeof window !== 'undefined' && typeof window.fetch !== 'undefined') {
50
8
  }
51
9
  else {
52
10
  // We are in a Node.js environment
53
- //@ts-ignore
54
- fetchFunction = (...args) => __awaiter(void 0, void 0, void 0, function* () {
55
- const fetch = yield Promise.resolve().then(() => __importStar(require('node-fetch')));
56
- //@ts-ignore
57
- return fetch.default(...args);
58
- });
11
+ fetchFunction = async (...args) => {
12
+ const fetch = global.fetch;
13
+ return fetch.apply(null, args);
14
+ };
59
15
  }
60
16
  class Sheet2DB {
61
17
  constructor(options) {
@@ -63,41 +19,47 @@ class Sheet2DB {
63
19
  this.apiEndpoint = "https://api.sheet2db.com";
64
20
  this.fetchFn = options.fetchFn || fetchFunction;
65
21
  }
66
- fetch(path_1) {
67
- return __awaiter(this, arguments, void 0, function* (path, method = "GET", queryParams, body) {
68
- let endpoint = new URL(this.options.version, this.apiEndpoint);
69
- let headers = { "Content-Type": "application/json" };
70
- if (this.options.mode === 'connectionId') {
71
- endpoint.pathname = `/${this.options.connectionId}${path}`;
72
- if (this.options.basicAuth) {
73
- let authorization = Buffer.from(`${this.options.basicAuth.username}:${this.options.basicAuth.password}`).toString('base64');
74
- headers["Authorization"] = `Basic ${authorization}`;
75
- }
76
- else if (this.options.jwtAuth) {
77
- headers["Authorization"] = `Bearer ${this.options.jwtAuth.bearerToken}`;
78
- }
22
+ async fetch(path, method = "GET", queryParams, body) {
23
+ let endpoint = new URL(this.options.version, this.apiEndpoint);
24
+ let headers = { "Content-Type": "application/json" };
25
+ if (this.options.mode === 'connectionId') {
26
+ endpoint.pathname = `${endpoint.pathname}/${this.options.connectionId}${path}`;
27
+ if (this.options.basicAuth) {
28
+ let authorization = Buffer.from(`${this.options.basicAuth.username}:${this.options.basicAuth.password}`).toString('base64');
29
+ headers["Authorization"] = `Basic ${authorization}`;
79
30
  }
80
- else {
81
- endpoint.pathname = `/${this.options.apiKey}${path}`;
82
- endpoint.searchParams.set("__id", this.options.spreadsheetId);
31
+ else if (this.options.jwtAuth) {
32
+ headers["Authorization"] = `Bearer ${this.options.jwtAuth.bearerToken}`;
83
33
  }
84
- if (queryParams) {
34
+ }
35
+ else {
36
+ endpoint.pathname = `${endpoint.pathname}/${this.options.apiKey}${path}`;
37
+ endpoint.searchParams.set("__id", this.options.spreadsheetId);
38
+ }
39
+ if (queryParams) {
40
+ if (typeof queryParams != 'string') {
85
41
  queryParams.forEach((value, key) => {
86
42
  endpoint.searchParams.append(key, value);
87
43
  });
88
44
  }
89
- const response = yield this.fetchFn(endpoint.toString(), {
90
- headers,
91
- method,
92
- body: body ? JSON.stringify(body) : undefined
93
- });
94
- if (response.ok) {
95
- return response.json();
96
- }
97
45
  else {
98
- throw new Error(yield response.text());
46
+ endpoint.search = queryParams;
47
+ if (this.options.mode == 'apikey') {
48
+ endpoint.searchParams.set("__id", this.options.spreadsheetId);
49
+ }
99
50
  }
51
+ }
52
+ const response = await this.fetchFn(endpoint.toString(), {
53
+ headers,
54
+ method,
55
+ body: body ? JSON.stringify(body) : undefined
100
56
  });
57
+ if (response.ok) {
58
+ return response.json();
59
+ }
60
+ else {
61
+ throw new Error(await response.text());
62
+ }
101
63
  }
102
64
  ReadContent(options) {
103
65
  const query = new URLSearchParams(options);
@@ -122,49 +84,46 @@ class Sheet2DB {
122
84
  if (options.sheet) {
123
85
  path = `${path}/${options.sheet}`;
124
86
  }
125
- const query = new URLSearchParams({ query: options.query });
126
- return this.fetch(path, "GET", query);
87
+ return this.fetch(path, "GET", encodeURIComponent(options.query));
127
88
  }
128
89
  Insert(options) {
129
- const { data } = options, queryParams = __rest(options, ["data"]);
90
+ const { data, ...queryParams } = options;
130
91
  const query = new URLSearchParams(queryParams);
131
92
  return this.fetch('/', "POST", query, data);
132
93
  }
133
94
  UpdateRow(options) {
134
- const { row, data } = options, queryParams = __rest(options, ["row", "data"]);
95
+ const { row, data, ...queryParams } = options;
135
96
  const query = new URLSearchParams(queryParams);
136
97
  return this.fetch(`/row/${row}`, "PATCH", query, data);
137
98
  }
138
99
  UpdateWithQuery(options) {
139
- const { sheet, data, query: q } = options;
100
+ const { sheet, data, query } = options;
140
101
  let path = '';
141
102
  if (sheet) {
142
103
  path = `/${sheet}`;
143
104
  }
144
- const query = new URLSearchParams({ query: q });
145
- return this.fetch(path, "PATCH", query, data);
105
+ return this.fetch(path, "PATCH", encodeURIComponent(query), data);
146
106
  }
147
107
  BatchUpdate(options) {
148
108
  const { batches, sheet } = options;
149
- let path = '';
109
+ let path = '/batch';
150
110
  if (sheet) {
151
- path = `/${sheet}`;
111
+ path = path + '/' + sheet;
152
112
  }
153
113
  return this.fetch(path, "PATCH", undefined, batches);
154
114
  }
155
115
  DeleteRow(options) {
156
- const { row } = options, queryParams = __rest(options, ["row"]);
116
+ const { row, ...queryParams } = options;
157
117
  const query = new URLSearchParams(queryParams);
158
- return this.fetch(`/${row}`, "DELETE", query);
118
+ return this.fetch(`/row/${row}`, "DELETE", query);
159
119
  }
160
120
  DeleteWithQuery(options) {
161
- const { query: search, sheet } = options;
162
- const query = new URLSearchParams({ query: search });
121
+ const { query, sheet } = options;
163
122
  let path = '';
164
123
  if (sheet) {
165
124
  path = `/${sheet}`;
166
125
  }
167
- return this.fetch(path, "DELETE", query);
126
+ return this.fetch(path, "DELETE", encodeURIComponent(query));
168
127
  }
169
128
  Clear(options) {
170
129
  const path = `/clear/${options.sheet}`;
@@ -179,4 +138,4 @@ class Sheet2DB {
179
138
  return this.fetch(path, "DELETE");
180
139
  }
181
140
  }
182
- exports.default = Sheet2DB;
141
+ exports.Sheet2DB = Sheet2DB;
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@sheet2db/sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
- "build":"tsc"
8
+ "build":"tsc",
9
+ "prepublish": "tsc"
9
10
  },
10
11
  "exports":{
11
12
  ".":{
12
13
  "import":"./dist/index.js",
13
- "require":"./dist/index.cjs"
14
+ "require":"./dist/index.js"
14
15
  }
15
16
  },
16
17
  "author": "",
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ if (typeof window !== 'undefined' && typeof window.fetch !== 'undefined') {
7
7
  // We are in a Node.js environment
8
8
  fetchFunction = async (...args) => {
9
9
  const fetch = global.fetch;
10
- return fetch(...args);
10
+ return fetch.apply(null,args)
11
11
  };
12
12
  }
13
13
 
@@ -102,7 +102,7 @@ export type DeleteSheetOptions = {
102
102
  sheet: string;
103
103
  };
104
104
 
105
- export default class Sheet2DB {
105
+ export class Sheet2DB {
106
106
 
107
107
  private apiEndpoint: string = "https://api.sheet2db.com";
108
108
  // private apiEndpoint: string = "http://localhost:8787";
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, test } from '@jest/globals';
2
- import Sheet2DB, {
2
+ import {
3
+ Sheet2DB,
3
4
  Sheet2DBOptions,
4
5
  ReadOptions,
5
6
  GetKeysOptions,
package/tsconfig.json CHANGED
@@ -1,16 +1,11 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "CommonJS",
5
- "moduleResolution": "node",
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "declaration": true
12
- },
13
- "include": ["src/**/*"],
14
- "exclude": ["node_modules"]
15
- }
16
-
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es2019",
5
+ "declaration": true,
6
+ "outDir": "./dist"
7
+ },
8
+ "include": [
9
+ "src/**/*"
10
+ ]
11
+ }
@@ -1,2 +0,0 @@
1
- import Sheet2DB from "./index.js";
2
- export = Sheet2DB;
package/dist/index.cjs.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- const index_js_1 = __importDefault(require("./index.js"));
6
- module.exports = index_js_1.default;
package/src/index.cjs.ts DELETED
@@ -1,2 +0,0 @@
1
- import Sheet2DB from "./index.js";
2
- export = Sheet2DB