google-sheets-mapper 2.1.1 → 2.2.0

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.cjs CHANGED
@@ -10,7 +10,7 @@ const getSheetsTitleUrl = (sheetId, apiKey)=>{
10
10
  };
11
11
  const getBatchUrl = (sheetId, ranges, apiKey)=>{
12
12
  const rangesQueryString = getRanges(ranges);
13
- return `${GOOGLE_API_URL}/${sheetId}?${rangesQueryString}&key=${apiKey}&includeGridData=true`;
13
+ return `${GOOGLE_API_URL}/${sheetId}/values:batchGet?${rangesQueryString}&key=${apiKey}`;
14
14
  };
15
15
  const makeFetch = async (url, config = {})=>{
16
16
  const response = await fetch(url, config);
@@ -34,7 +34,7 @@ const mapRecords = (records, headerData)=>{
34
34
  return obj;
35
35
  }, {}));
36
36
  };
37
- const mapData = ({ sheets, sheetsOptions = [] })=>{
37
+ const mapData = ({ sheets = [], sheetsOptions = [] })=>{
38
38
  return sheets.map((sheet)=>{
39
39
  const id = sheet.range.split("!")[0].replace(/'/g, "");
40
40
  const rows = sheet.values || [];
@@ -62,7 +62,7 @@ const fetchBatchData = async ({ apiKey, sheetId, sheetsOptions = [] })=>{
62
62
  };
63
63
  const fetchAllSheetsData = async ({ apiKey, sheetId })=>{
64
64
  const urlTitles = getSheetsTitleUrl(sheetId, apiKey);
65
- const { sheets } = await makeFetch(urlTitles);
65
+ const { sheets = [] } = await makeFetch(urlTitles);
66
66
  const sheetsOptions = sheets.map((sheet)=>({
67
67
  id: sheet.properties.title
68
68
  }));
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ const getSheetsTitleUrl = (sheetId, apiKey)=>{
8
8
  };
9
9
  const getBatchUrl = (sheetId, ranges, apiKey)=>{
10
10
  const rangesQueryString = getRanges(ranges);
11
- return `${GOOGLE_API_URL}/${sheetId}?${rangesQueryString}&key=${apiKey}&includeGridData=true`;
11
+ return `${GOOGLE_API_URL}/${sheetId}/values:batchGet?${rangesQueryString}&key=${apiKey}`;
12
12
  };
13
13
  const makeFetch = async (url, config = {})=>{
14
14
  const response = await fetch(url, config);
@@ -32,7 +32,7 @@ const mapRecords = (records, headerData)=>{
32
32
  return obj;
33
33
  }, {}));
34
34
  };
35
- const mapData = ({ sheets, sheetsOptions = [] })=>{
35
+ const mapData = ({ sheets = [], sheetsOptions = [] })=>{
36
36
  return sheets.map((sheet)=>{
37
37
  const id = sheet.range.split("!")[0].replace(/'/g, "");
38
38
  const rows = sheet.values || [];
@@ -60,7 +60,7 @@ const fetchBatchData = async ({ apiKey, sheetId, sheetsOptions = [] })=>{
60
60
  };
61
61
  const fetchAllSheetsData = async ({ apiKey, sheetId })=>{
62
62
  const urlTitles = getSheetsTitleUrl(sheetId, apiKey);
63
- const { sheets } = await makeFetch(urlTitles);
63
+ const { sheets = [] } = await makeFetch(urlTitles);
64
64
  const sheetsOptions = sheets.map((sheet)=>({
65
65
  id: sheet.properties.title
66
66
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-sheets-mapper",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "### A library for getting data from Google Sheets API v4",
5
5
  "keywords": [
6
6
  "google-sheets",
package/src/utils.ts CHANGED
@@ -22,7 +22,7 @@ const getSheetsTitleUrl = (sheetId: string, apiKey: string): string => {
22
22
  const getBatchUrl = (sheetId: string, ranges: Array<string>, apiKey: string): string => {
23
23
  const rangesQueryString = getRanges(ranges);
24
24
 
25
- return `${GOOGLE_API_URL}/${sheetId}?${rangesQueryString}&key=${apiKey}&includeGridData=true`;
25
+ return `${GOOGLE_API_URL}/${sheetId}/values:batchGet?${rangesQueryString}&key=${apiKey}`;
26
26
  };
27
27
 
28
28
  const makeFetch = async <T>(url: string, config = {}): Promise<T> => {
@@ -64,10 +64,10 @@ const mapRecords = (
64
64
  };
65
65
 
66
66
  export const mapData = ({
67
- sheets,
67
+ sheets = [],
68
68
  sheetsOptions = [],
69
69
  }: {
70
- sheets: ValueRange[];
70
+ sheets?: ValueRange[];
71
71
  sheetsOptions?: SheetsOption[];
72
72
  }): MapperState[] => {
73
73
  return sheets.map((sheet: ValueRange) => {
@@ -110,7 +110,7 @@ export const fetchAllSheetsData = async ({
110
110
  sheetId,
111
111
  }: MapperOptions): Promise<ValueRangesResponse> => {
112
112
  const urlTitles = getSheetsTitleUrl(sheetId, apiKey);
113
- const { sheets }: SheetsResponse = await makeFetch(urlTitles);
113
+ const { sheets = [] }: SheetsResponse = await makeFetch(urlTitles);
114
114
  const sheetsOptions = sheets.map((sheet: SheetFromResponse) => ({
115
115
  id: sheet.properties.title,
116
116
  }));