Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gsheet-api

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gsheet-api - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

2

package.json
{
"name": "gsheet-api",
"version": "0.1.9",
"version": "0.1.10",
"description": "",

@@ -5,0 +5,0 @@ "main": "src/GoogleSheetService.ts",

@@ -11,203 +11,203 @@ import { Row } from "./model/RowModel";

async addItemGoogleSheet(spreadsheetID: string, sheetsTitle: string, clientEmail: string, privateKey: string, item: Array<SheetItemModel>, callback: () => void, error: (message: string) => void) {
const {GoogleSpreadsheet} = require('google-spreadsheet');
const doc = new GoogleSpreadsheet(spreadsheetID);
try {
await doc.useServiceAccountAuth({
client_email: clientEmail,
private_key: privateKey
});
await doc.loadInfo(); // loads document properties and worksheets
const sheet = doc.sheetsByTitle[sheetsTitle]; // or use doc.sheetsById[id] or doc.sheetsByTitle[title]
await sheet.loadHeaderRow(2)
// console.log("====== DOC TITLE : ", doc.title);
// console.log("====== SHEET TITLE : ", sheet.title);
// console.log("====== Header Value => ", sheet.headerValues);
const rows = await sheet.getRows();
let newRows: Array<Row> = []
item.map((i) => {
const rowsFilter = rows.filter((r: Row) => r.id === i.id)
if (rowsFilter.length > 0) {
rows.map((r: Row, index: number) => {
if (i.id === r.id) {
const title = i.data?.find(i => i.key === 'title')?.value
if (title) {
rows[index].title = title
}
const description = i.data?.find(i => i.key === 'description')?.value
if (description) {
rows[index].description = description
}
const availability = i.data?.find(i => i.key === 'availability')?.value
if (availability) {
rows[index].availability = availability
}
const condition = i.data?.find(i => i.key === 'condition')?.value
if (condition) {
rows[index].condition = condition
}
const price = i.data?.find(i => i.key === 'price')?.value
if (price) {
rows[index].price = price
}
const link = i.data?.find(i => i.key === 'link')?.value
if (link) {
rows[index].link = link
}
const image_link = i.data?.find(i => i.key === 'image_link')?.value
if (image_link) {
rows[index].image_link = image_link
}
const brand = i.data?.find(i => i.key === 'brand')?.value
if (brand) {
rows[index].brand = brand
}
const google_product_category = i.data?.find(i => i.key === 'google_product_category')?.value
if (google_product_category) {
rows[index].google_product_category = google_product_category
}
const fb_product_category = i.data?.find(i => i.key === 'fb_product_category')?.value
if (fb_product_category) {
rows[index].fb_product_category = fb_product_category
}
const quantity_to_sell_on_facebook = i.data?.find(i => i.key === 'quantity_to_sell_on_facebook')?.value
if (quantity_to_sell_on_facebook) {
rows[index].quantity_to_sell_on_facebook = quantity_to_sell_on_facebook
}
const sale_price = i.data?.find(i => i.key === 'sale_price')?.value
if (sale_price) {
rows[index].sale_price = sale_price
}
const sale_price_effective_date = i.data?.find(i => i.key === 'sale_price_effective_date')?.value
if (sale_price_effective_date) {
rows[index].sale_price_effective_date = sale_price_effective_date
}
const item_group_id = i.data?.find(i => i.key === 'item_group_id')?.value
if (item_group_id) {
rows[index].item_group_id = item_group_id
}
const gender = i.data?.find(i => i.key === 'gender')?.value
if (gender) {
rows[index].gender = gender
}
const color = i.data?.find(i => i.key === 'color')?.value
if (color) {
rows[index].color = color
}
const size = i.data?.find(i => i.key === 'size')?.value
if (size) {
rows[index].size = size
}
const age_group = i.data?.find(i => i.key === 'age_group')?.value
if (age_group) {
rows[index].age_group = age_group
}
const material = i.data?.find(i => i.key === 'material')?.value
if (material) {
rows[index].material = material
}
const pattern = i.data?.find(i => i.key === 'pattern')?.value
if (pattern) {
rows[index].pattern = pattern
}
const shipping = i.data?.find(i => i.key === 'shipping')?.value
if (shipping) {
rows[index].shipping = shipping
}
const shipping_weight = i.data?.find(i => i.key === 'shipping_weight')?.value
if (shipping_weight) {
rows[index].shipping_weight = shipping_weight
}
const status = i.data?.find(i => i.key === 'status')?.value
if (status) {
rows[index].status = status
}
const additional_image_link = i.data?.find(i => i.key === 'additional_image_link')?.value
if (additional_image_link) {
rows[index].additional_image_link = additional_image_link
}
const product_type = i.data?.find(i => i.key === 'product_type')?.value
if (product_type) {
rows[index].product_type = product_type
}
rows[index].save()
}
})
// console.log("====== Item Update ID => ", i.id)
} else {
const newItem = new Row()
newItem.id = i.id
newItem.title = i.data?.find(i => i.key === 'title')?.value ?? ''
newItem.description = i.data?.find(i => i.key === 'description')?.value ?? ''
newItem.availability = i.data?.find(i => i.key === 'availability')?.value ?? ''
newItem.condition = i.data?.find(i => i.key === 'condition')?.value ?? ''
newItem.price = i.data?.find(i => i.key === 'price')?.value ?? ''
newItem.link = i.data?.find(i => i.key === 'link')?.value ?? ''
newItem.image_link = i.data?.find(i => i.key === 'image_link')?.value ?? ''
newItem.brand = i.data?.find(i => i.key === 'brand')?.value ?? ''
newItem.google_product_category = i.data?.find(i => i.key === 'google_product_category')?.value ?? ''
newItem.fb_product_category = i.data?.find(i => i.key === 'fb_product_category')?.value ?? ''
newItem.quantity_to_sell_on_facebook = i.data?.find(i => i.key === 'quantity_to_sell_on_facebook')?.value ?? ''
newItem.sale_price = i.data?.find(i => i.key === 'sale_price')?.value ?? ''
newItem.sale_price_effective_date = i.data?.find(i => i.key === 'sale_price_effective_date')?.value ?? ''
newItem.item_group_id = i.data?.find(i => i.key === 'item_group_id')?.value ?? ''
newItem.gender = i.data?.find(i => i.key === 'gender')?.value ?? ''
newItem.color = i.data?.find(i => i.key === 'color')?.value ?? ''
newItem.size = i.data?.find(i => i.key === 'size')?.value ?? ''
newItem.age_group = i.data?.find(i => i.key === 'age_group')?.value ?? ''
newItem.material = i.data?.find(i => i.key === 'material')?.value ?? ''
newItem.pattern = i.data?.find(i => i.key === 'pattern')?.value ?? ''
newItem.shipping = i.data?.find(i => i.key === 'shipping')?.value ?? ''
newItem.shipping_weight = i.data?.find(i => i.key === 'shipping_weight')?.value ?? ''
newItem.status = i.data?.find(i => i.key === 'status')?.value ?? ''
newItem.additional_image_link = i.data?.find(i => i.key === 'additional_image_link')?.value ?? ''
newItem.product_type = i.data?.find(i => i.key === 'product_type')?.value ?? ''
newRows.push(newItem)
}
})
console.log("====== Add Rows => ", newRows)
await sheet.addRows(newRows);
callback()
} catch (e) {
// @ts-ignore
error(e.toString())
}
}
// async addItemGoogleSheet(spreadsheetID: string, sheetsTitle: string, clientEmail: string, privateKey: string, item: Array<SheetItemModel>, callback: () => void, error: (message: string) => void) {
// const {GoogleSpreadsheet} = require('google-spreadsheet');
// const doc = new GoogleSpreadsheet(spreadsheetID);
//
// try {
// await doc.useServiceAccountAuth({
// client_email: clientEmail,
// private_key: privateKey
// });
//
// await doc.loadInfo(); // loads document properties and worksheets
// const sheet = doc.sheetsByTitle[sheetsTitle]; // or use doc.sheetsById[id] or doc.sheetsByTitle[title]
// await sheet.loadHeaderRow(2)
//
// // console.log("====== DOC TITLE : ", doc.title);
// // console.log("====== SHEET TITLE : ", sheet.title);
// // console.log("====== Header Value => ", sheet.headerValues);
//
// const rows = await sheet.getRows();
// let newRows: Array<Row> = []
//
// item.map((i) => {
// const rowsFilter = rows.filter((r: Row) => r.id === i.id)
//
// if (rowsFilter.length > 0) {
// rows.map((r: Row, index: number) => {
// if (i.id === r.id) {
//
// const title = i.data?.find(i => i.key === 'title')?.value
// if (title) {
// rows[index].title = title
// }
//
// const description = i.data?.find(i => i.key === 'description')?.value
// if (description) {
// rows[index].description = description
// }
//
// const availability = i.data?.find(i => i.key === 'availability')?.value
// if (availability) {
// rows[index].availability = availability
// }
//
// const condition = i.data?.find(i => i.key === 'condition')?.value
// if (condition) {
// rows[index].condition = condition
// }
//
// const price = i.data?.find(i => i.key === 'price')?.value
// if (price) {
// rows[index].price = price
// }
//
// const link = i.data?.find(i => i.key === 'link')?.value
// if (link) {
// rows[index].link = link
// }
//
// const image_link = i.data?.find(i => i.key === 'image_link')?.value
// if (image_link) {
// rows[index].image_link = image_link
// }
//
// const brand = i.data?.find(i => i.key === 'brand')?.value
// if (brand) {
// rows[index].brand = brand
// }
//
// const google_product_category = i.data?.find(i => i.key === 'google_product_category')?.value
// if (google_product_category) {
// rows[index].google_product_category = google_product_category
// }
//
// const fb_product_category = i.data?.find(i => i.key === 'fb_product_category')?.value
// if (fb_product_category) {
// rows[index].fb_product_category = fb_product_category
// }
//
// const quantity_to_sell_on_facebook = i.data?.find(i => i.key === 'quantity_to_sell_on_facebook')?.value
// if (quantity_to_sell_on_facebook) {
// rows[index].quantity_to_sell_on_facebook = quantity_to_sell_on_facebook
// }
//
// const sale_price = i.data?.find(i => i.key === 'sale_price')?.value
// if (sale_price) {
// rows[index].sale_price = sale_price
// }
//
// const sale_price_effective_date = i.data?.find(i => i.key === 'sale_price_effective_date')?.value
// if (sale_price_effective_date) {
// rows[index].sale_price_effective_date = sale_price_effective_date
// }
//
// const item_group_id = i.data?.find(i => i.key === 'item_group_id')?.value
// if (item_group_id) {
// rows[index].item_group_id = item_group_id
// }
//
// const gender = i.data?.find(i => i.key === 'gender')?.value
// if (gender) {
// rows[index].gender = gender
// }
//
// const color = i.data?.find(i => i.key === 'color')?.value
// if (color) {
// rows[index].color = color
// }
//
// const size = i.data?.find(i => i.key === 'size')?.value
// if (size) {
// rows[index].size = size
// }
//
// const age_group = i.data?.find(i => i.key === 'age_group')?.value
// if (age_group) {
// rows[index].age_group = age_group
// }
//
// const material = i.data?.find(i => i.key === 'material')?.value
// if (material) {
// rows[index].material = material
// }
//
// const pattern = i.data?.find(i => i.key === 'pattern')?.value
// if (pattern) {
// rows[index].pattern = pattern
// }
//
// const shipping = i.data?.find(i => i.key === 'shipping')?.value
// if (shipping) {
// rows[index].shipping = shipping
// }
//
// const shipping_weight = i.data?.find(i => i.key === 'shipping_weight')?.value
// if (shipping_weight) {
// rows[index].shipping_weight = shipping_weight
// }
//
//
// const status = i.data?.find(i => i.key === 'status')?.value
// if (status) {
// rows[index].status = status
// }
//
// const additional_image_link = i.data?.find(i => i.key === 'additional_image_link')?.value
// if (additional_image_link) {
// rows[index].additional_image_link = additional_image_link
// }
//
// const product_type = i.data?.find(i => i.key === 'product_type')?.value
// if (product_type) {
// rows[index].product_type = product_type
// }
//
// rows[index].save()
// }
//
// })
// // console.log("====== Item Update ID => ", i.id)
// } else {
// const newItem = new Row()
// newItem.id = i.id
// newItem.title = i.data?.find(i => i.key === 'title')?.value ?? ''
// newItem.description = i.data?.find(i => i.key === 'description')?.value ?? ''
// newItem.availability = i.data?.find(i => i.key === 'availability')?.value ?? ''
// newItem.condition = i.data?.find(i => i.key === 'condition')?.value ?? ''
// newItem.price = i.data?.find(i => i.key === 'price')?.value ?? ''
// newItem.link = i.data?.find(i => i.key === 'link')?.value ?? ''
// newItem.image_link = i.data?.find(i => i.key === 'image_link')?.value ?? ''
// newItem.brand = i.data?.find(i => i.key === 'brand')?.value ?? ''
// newItem.google_product_category = i.data?.find(i => i.key === 'google_product_category')?.value ?? ''
// newItem.fb_product_category = i.data?.find(i => i.key === 'fb_product_category')?.value ?? ''
// newItem.quantity_to_sell_on_facebook = i.data?.find(i => i.key === 'quantity_to_sell_on_facebook')?.value ?? ''
// newItem.sale_price = i.data?.find(i => i.key === 'sale_price')?.value ?? ''
// newItem.sale_price_effective_date = i.data?.find(i => i.key === 'sale_price_effective_date')?.value ?? ''
// newItem.item_group_id = i.data?.find(i => i.key === 'item_group_id')?.value ?? ''
// newItem.gender = i.data?.find(i => i.key === 'gender')?.value ?? ''
// newItem.color = i.data?.find(i => i.key === 'color')?.value ?? ''
// newItem.size = i.data?.find(i => i.key === 'size')?.value ?? ''
// newItem.age_group = i.data?.find(i => i.key === 'age_group')?.value ?? ''
// newItem.material = i.data?.find(i => i.key === 'material')?.value ?? ''
// newItem.pattern = i.data?.find(i => i.key === 'pattern')?.value ?? ''
// newItem.shipping = i.data?.find(i => i.key === 'shipping')?.value ?? ''
// newItem.shipping_weight = i.data?.find(i => i.key === 'shipping_weight')?.value ?? ''
// newItem.status = i.data?.find(i => i.key === 'status')?.value ?? ''
// newItem.additional_image_link = i.data?.find(i => i.key === 'additional_image_link')?.value ?? ''
// newItem.product_type = i.data?.find(i => i.key === 'product_type')?.value ?? ''
//
// newRows.push(newItem)
// }
// })
//
// console.log("====== Add Rows => ", newRows)
//
// await sheet.addRows(newRows);
// callback()
// } catch (e) {
// // @ts-ignore
// error(e.toString())
// }
// }
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc