google-sheets-mapper 2.1.0 → 2.1.1

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/README.md CHANGED
@@ -20,7 +20,7 @@ pnpm add google-sheets-mapper
20
20
  bun add google-sheets-mapper
21
21
  ```
22
22
 
23
- UMD build available on [unpkg](https://www.unpkg.com/browse/google-sheets-mapper@1.0.0/dist/google-sheets-mapper.cjs.production.min.js).
23
+ UMD build available on [unpkg](https://www.unpkg.com/browse/google-sheets-mapper/).
24
24
 
25
25
  ---
26
26
 
package/dist/index.cjs CHANGED
@@ -12,23 +12,15 @@ const getBatchUrl = (sheetId, ranges, apiKey)=>{
12
12
  const rangesQueryString = getRanges(ranges);
13
13
  return `${GOOGLE_API_URL}/${sheetId}?${rangesQueryString}&key=${apiKey}&includeGridData=true`;
14
14
  };
15
- class ApiResponseError extends Error {
16
- constructor(message, response){
17
- super(message);
18
- Object.setPrototypeOf(this, ApiResponseError.prototype);
19
- this.response = response;
20
- if (Error.captureStackTrace) {
21
- Error.captureStackTrace(this, ApiResponseError);
22
- }
23
- }
24
- }
25
15
  const makeFetch = async (url, config = {})=>{
26
16
  const response = await fetch(url, config);
27
17
  if (!response.ok) {
28
- throw new ApiResponseError(`Request to '${url}' failed with ${response.status}${response.statusText ? `: ${response.statusText}` : ""}`, {
29
- status: response.status,
30
- statusText: response.statusText,
31
- url: response.url
18
+ throw new Error(`Request to '${url}' failed with ${response.status}${response.statusText ? `: ${response.statusText}` : ""}`, {
19
+ cause: {
20
+ status: response.status,
21
+ statusText: response.statusText,
22
+ url: response.url
23
+ }
32
24
  });
33
25
  }
34
26
  return await response.json();
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export interface SheetsOption {\n id: string;\n headerRowIndex?: number;\n}\n\nexport interface MapperOptions {\n apiKey: string;\n sheetId: string;\n sheetsOptions?: SheetsOption[];\n}\n\nexport interface ValueRange {\n majorDimensions: string;\n range: string;\n values: string[][];\n}\n\nexport interface ValueRangesResponse {\n spreadsheetId: string;\n valueRanges: ValueRange[];\n}\n\nexport interface PropertiesFromResponse {\n title: string;\n}\n\nexport interface SheetFromResponse {\n properties: PropertiesFromResponse;\n}\n\nexport interface SheetsResponse {\n sheets: SheetFromResponse[];\n}\n\nexport interface MapperState {\n id: string;\n data: Record<string, string>[];\n}\n\nexport interface ApiResponse {\n url: string;\n status: number;\n statusText: string;\n}\n\nexport interface ErrorResponse {\n response: ApiResponse;\n}\n","import type { MapperOptions, MapperState, ValueRangesResponse } from \"./types\";\nimport { fetchBatchData, fetchAllSheetsData, mapData } from \"./utils\";\n\nconst GoogleSheetsMapper = {\n async fetchGoogleSheetsData({\n apiKey,\n sheetId,\n sheetsOptions = [],\n }: MapperOptions): Promise<MapperState[]> {\n const response: ValueRangesResponse =\n sheetsOptions.length === 0\n ? await fetchAllSheetsData({ apiKey, sheetId })\n : await fetchBatchData({ apiKey, sheetId, sheetsOptions });\n return mapData({ sheets: response.valueRanges, sheetsOptions });\n },\n};\n\nexport default GoogleSheetsMapper;\nexport const fetchGoogleSheetsData = GoogleSheetsMapper.fetchGoogleSheetsData;\n"],"names":[],"mappings":"AAAO,UAAA,YAAA;AACP;AACA;AACA;AACO,UAAA,aAAA;AACP;AACA;AACA,oBAAA,YAAA;AACA;AAmBO,UAAA,WAAA;AACP;AACA,UAAA,MAAA;AACA;;AC7BA,cAAA,kBAAA;AACA,+DAAA,aAAA,GAAA,OAAA,CAAA,WAAA;AACA;;AAEO,cAAA,qBAAA,wCAAA,aAAA,KAAA,OAAA,CAAA,WAAA;;;;"}
1
+ {"version":3,"file":"index.d.cts","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export interface SheetsOption {\n id: string;\n headerRowIndex?: number;\n}\n\nexport interface MapperOptions {\n apiKey: string;\n sheetId: string;\n sheetsOptions?: SheetsOption[];\n}\n\nexport interface ValueRange {\n majorDimensions: string;\n range: string;\n values: string[][];\n}\n\nexport interface ValueRangesResponse {\n spreadsheetId: string;\n valueRanges: ValueRange[];\n}\n\nexport interface PropertiesFromResponse {\n title: string;\n}\n\nexport interface SheetFromResponse {\n properties: PropertiesFromResponse;\n}\n\nexport interface SheetsResponse {\n sheets: SheetFromResponse[];\n}\n\nexport interface MapperState {\n id: string;\n data: Record<string, string>[];\n}\n","import type { MapperOptions, MapperState, ValueRangesResponse } from \"./types\";\nimport { fetchBatchData, fetchAllSheetsData, mapData } from \"./utils\";\n\nconst GoogleSheetsMapper = {\n async fetchGoogleSheetsData({\n apiKey,\n sheetId,\n sheetsOptions = [],\n }: MapperOptions): Promise<MapperState[]> {\n const response: ValueRangesResponse =\n sheetsOptions.length === 0\n ? await fetchAllSheetsData({ apiKey, sheetId })\n : await fetchBatchData({ apiKey, sheetId, sheetsOptions });\n return mapData({ sheets: response.valueRanges, sheetsOptions });\n },\n};\n\nexport default GoogleSheetsMapper;\nexport const fetchGoogleSheetsData = GoogleSheetsMapper.fetchGoogleSheetsData;\n"],"names":[],"mappings":"AAAO,UAAA,YAAA;AACP;AACA;AACA;AACO,UAAA,aAAA;AACP;AACA;AACA,oBAAA,YAAA;AACA;AAmBO,UAAA,WAAA;AACP;AACA,UAAA,MAAA;AACA;;AC7BA,cAAA,kBAAA;AACA,+DAAA,aAAA,GAAA,OAAA,CAAA,WAAA;AACA;;AAEO,cAAA,qBAAA,wCAAA,aAAA,KAAA,OAAA,CAAA,WAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export interface SheetsOption {\n id: string;\n headerRowIndex?: number;\n}\n\nexport interface MapperOptions {\n apiKey: string;\n sheetId: string;\n sheetsOptions?: SheetsOption[];\n}\n\nexport interface ValueRange {\n majorDimensions: string;\n range: string;\n values: string[][];\n}\n\nexport interface ValueRangesResponse {\n spreadsheetId: string;\n valueRanges: ValueRange[];\n}\n\nexport interface PropertiesFromResponse {\n title: string;\n}\n\nexport interface SheetFromResponse {\n properties: PropertiesFromResponse;\n}\n\nexport interface SheetsResponse {\n sheets: SheetFromResponse[];\n}\n\nexport interface MapperState {\n id: string;\n data: Record<string, string>[];\n}\n\nexport interface ApiResponse {\n url: string;\n status: number;\n statusText: string;\n}\n\nexport interface ErrorResponse {\n response: ApiResponse;\n}\n","import type { MapperOptions, MapperState, ValueRangesResponse } from \"./types\";\nimport { fetchBatchData, fetchAllSheetsData, mapData } from \"./utils\";\n\nconst GoogleSheetsMapper = {\n async fetchGoogleSheetsData({\n apiKey,\n sheetId,\n sheetsOptions = [],\n }: MapperOptions): Promise<MapperState[]> {\n const response: ValueRangesResponse =\n sheetsOptions.length === 0\n ? await fetchAllSheetsData({ apiKey, sheetId })\n : await fetchBatchData({ apiKey, sheetId, sheetsOptions });\n return mapData({ sheets: response.valueRanges, sheetsOptions });\n },\n};\n\nexport default GoogleSheetsMapper;\nexport const fetchGoogleSheetsData = GoogleSheetsMapper.fetchGoogleSheetsData;\n"],"names":[],"mappings":"AAAO,UAAA,YAAA;AACP;AACA;AACA;AACO,UAAA,aAAA;AACP;AACA;AACA,oBAAA,YAAA;AACA;AAmBO,UAAA,WAAA;AACP;AACA,UAAA,MAAA;AACA;;AC7BA,cAAA,kBAAA;AACA,+DAAA,aAAA,GAAA,OAAA,CAAA,WAAA;AACA;;AAEO,cAAA,qBAAA,wCAAA,aAAA,KAAA,OAAA,CAAA,WAAA;;;;"}
1
+ {"version":3,"file":"index.d.ts","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export interface SheetsOption {\n id: string;\n headerRowIndex?: number;\n}\n\nexport interface MapperOptions {\n apiKey: string;\n sheetId: string;\n sheetsOptions?: SheetsOption[];\n}\n\nexport interface ValueRange {\n majorDimensions: string;\n range: string;\n values: string[][];\n}\n\nexport interface ValueRangesResponse {\n spreadsheetId: string;\n valueRanges: ValueRange[];\n}\n\nexport interface PropertiesFromResponse {\n title: string;\n}\n\nexport interface SheetFromResponse {\n properties: PropertiesFromResponse;\n}\n\nexport interface SheetsResponse {\n sheets: SheetFromResponse[];\n}\n\nexport interface MapperState {\n id: string;\n data: Record<string, string>[];\n}\n","import type { MapperOptions, MapperState, ValueRangesResponse } from \"./types\";\nimport { fetchBatchData, fetchAllSheetsData, mapData } from \"./utils\";\n\nconst GoogleSheetsMapper = {\n async fetchGoogleSheetsData({\n apiKey,\n sheetId,\n sheetsOptions = [],\n }: MapperOptions): Promise<MapperState[]> {\n const response: ValueRangesResponse =\n sheetsOptions.length === 0\n ? await fetchAllSheetsData({ apiKey, sheetId })\n : await fetchBatchData({ apiKey, sheetId, sheetsOptions });\n return mapData({ sheets: response.valueRanges, sheetsOptions });\n },\n};\n\nexport default GoogleSheetsMapper;\nexport const fetchGoogleSheetsData = GoogleSheetsMapper.fetchGoogleSheetsData;\n"],"names":[],"mappings":"AAAO,UAAA,YAAA;AACP;AACA;AACA;AACO,UAAA,aAAA;AACP;AACA;AACA,oBAAA,YAAA;AACA;AAmBO,UAAA,WAAA;AACP;AACA,UAAA,MAAA;AACA;;AC7BA,cAAA,kBAAA;AACA,+DAAA,aAAA,GAAA,OAAA,CAAA,WAAA;AACA;;AAEO,cAAA,qBAAA,wCAAA,aAAA,KAAA,OAAA,CAAA,WAAA;;;;"}
package/dist/index.js CHANGED
@@ -10,23 +10,15 @@ const getBatchUrl = (sheetId, ranges, apiKey)=>{
10
10
  const rangesQueryString = getRanges(ranges);
11
11
  return `${GOOGLE_API_URL}/${sheetId}?${rangesQueryString}&key=${apiKey}&includeGridData=true`;
12
12
  };
13
- class ApiResponseError extends Error {
14
- constructor(message, response){
15
- super(message);
16
- Object.setPrototypeOf(this, ApiResponseError.prototype);
17
- this.response = response;
18
- if (Error.captureStackTrace) {
19
- Error.captureStackTrace(this, ApiResponseError);
20
- }
21
- }
22
- }
23
13
  const makeFetch = async (url, config = {})=>{
24
14
  const response = await fetch(url, config);
25
15
  if (!response.ok) {
26
- throw new ApiResponseError(`Request to '${url}' failed with ${response.status}${response.statusText ? `: ${response.statusText}` : ""}`, {
27
- status: response.status,
28
- statusText: response.statusText,
29
- url: response.url
16
+ throw new Error(`Request to '${url}' failed with ${response.status}${response.statusText ? `: ${response.statusText}` : ""}`, {
17
+ cause: {
18
+ status: response.status,
19
+ statusText: response.statusText,
20
+ url: response.url
21
+ }
30
22
  });
31
23
  }
32
24
  return await response.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-sheets-mapper",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "### A library for getting data from Google Sheets API v4",
5
5
  "keywords": [
6
6
  "google-sheets",
package/src/types.ts CHANGED
@@ -36,13 +36,3 @@ export interface MapperState {
36
36
  id: string;
37
37
  data: Record<string, string>[];
38
38
  }
39
-
40
- export interface ApiResponse {
41
- url: string;
42
- status: number;
43
- statusText: string;
44
- }
45
-
46
- export interface ErrorResponse {
47
- response: ApiResponse;
48
- }
package/src/utils.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  MapperOptions,
3
3
  MapperState,
4
- ApiResponse,
5
4
  ValueRange,
6
5
  SheetsResponse,
7
6
  SheetFromResponse,
@@ -26,30 +25,20 @@ const getBatchUrl = (sheetId: string, ranges: Array<string>, apiKey: string): st
26
25
  return `${GOOGLE_API_URL}/${sheetId}?${rangesQueryString}&key=${apiKey}&includeGridData=true`;
27
26
  };
28
27
 
29
- class ApiResponseError extends Error {
30
- response: ApiResponse;
31
- constructor(message: string, response: ApiResponse) {
32
- super(message);
33
- Object.setPrototypeOf(this, ApiResponseError.prototype);
34
- this.response = response;
35
- if (Error.captureStackTrace) {
36
- Error.captureStackTrace(this, ApiResponseError);
37
- }
38
- }
39
- }
40
-
41
28
  const makeFetch = async <T>(url: string, config = {}): Promise<T> => {
42
29
  const response = await fetch(url, config);
43
30
 
44
31
  if (!response.ok) {
45
- throw new ApiResponseError(
32
+ throw new Error(
46
33
  `Request to '${url}' failed with ${response.status}${
47
34
  response.statusText ? `: ${response.statusText}` : ""
48
35
  }`,
49
36
  {
50
- status: response.status,
51
- statusText: response.statusText,
52
- url: response.url,
37
+ cause: {
38
+ status: response.status,
39
+ statusText: response.statusText,
40
+ url: response.url,
41
+ },
53
42
  },
54
43
  );
55
44
  }