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.2.1 to 0.2.2

.idea/gsheet-api.iml

26

package.json
{
"name": "gsheet-api",
"version": "0.2.1",
"version": "0.2.2",
"description": "",
"main": "src/GoogleSheetService.ts",
"files": [
"src"
],
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc --module commonjs"
"build": "npx tsc"
},
"repository": {
"type": "git",
"url": "git+https://gitlab.com/sarinthonton/gsheet-api.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gitlab.com/sarinthonton/gsheet-api/issues"
},
"homepage": "https://gitlab.com/sarinthonton/gsheet-api#readme",
"keywords": [],
"devDependencies": {
"@types/node": "^18.11.18",
"@types/webpack": "^5.28.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"google-spreadsheet": "^3.3.0",
"gsheet-api": "^0.1.0"
"google-spreadsheet": "^3.3.0"
}
}

@@ -1,242 +0,277 @@

import {SheetItemModel} from "./model/SheetItemModel";
import {Row} from "./model/RowModel";
const { GoogleSpreadsheet } = require('google-spreadsheet');
export async function 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);
class Row {
id?: string
title?: string
description?: string
rich_text_description?: string
availability?: string
condition?: string
price?: string
link?: string
image_link?: string
brand?: string
google_product_category?: string
fb_product_category?: string
quantity_to_sell_on_facebook?: string
sale_price?: string
sale_price_effective_date?: string
item_group_id?: string
gender?: string
color?: string
size?: string
age_group?: string
material?: string
pattern?: string
shipping?: string
shipping_weight?: string
status?: string
additional_image_link?: string
product_type?: string
custom_label_0?: string
custom_label_1?: string
custom_label_2?: string
custom_label_3?: string
custom_label_4?: string
}
try {
await doc.useServiceAccountAuth({
client_email: clientEmail,
private_key: privateKey
});
export class GoogleSheetService {
async addItem(spreadsheetID: string, sheetsTitle: string, clientEmail: string, privateKey: string, item: Array<any>, callback: () => void, error: (message: string) => void) {
const doc = new GoogleSpreadsheet(spreadsheetID);
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)
try {
await doc.useServiceAccountAuth({
client_email: clientEmail,
private_key: privateKey
});
// console.log("====== DOC TITLE : ", doc.title);
// console.log("====== SHEET TITLE : ", sheet.title);
// console.log("====== Header Value => ", sheet.headerValues);
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)
const rows = await sheet.getRows();
let newRows: Array<Row> = []
// console.log("====== DOC TITLE : ", doc.title);
// console.log("====== SHEET TITLE : ", sheet.title);
// console.log("====== Header Value => ", sheet.headerValues);
item.map((i) => {
const rowsFilter = rows.filter((r: Row) => r.id === i.id)
const rows = await sheet.getRows();
let newRows: Array<Row> = []
if (rowsFilter.length > 0) {
rows.map((r: Row, index: number) => {
if (i.id === r.id) {
item.map((i) => {
const rowsFilter = rows.filter((r: Row) => r.id === i.id)
const title = i.data?.find(i => i.key === 'title')?.value
if (title) {
rows[index].title = title
}
if (rowsFilter.length > 0) {
rows.map((r: Row, index: number) => {
if (i.id === r.id) {
const description = i.data?.find(i => i.key === 'description')?.value
if (description) {
rows[index].description = description
}
const title = i.data?.find(i => i.key === 'title')?.value
if (title) {
rows[index].title = title
}
const rich_text_description = i.data?.find(i => i.key === 'rich_text_description')?.value
if (rich_text_description) {
rows[index].rich_text_description = rich_text_description
}
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 rich_text_description = i.data?.find(i => i.key === 'rich_text_description')?.value
if (rich_text_description) {
rows[index].rich_text_description = rich_text_description
}
const condition = i.data?.find(i => i.key === 'condition')?.value
if (condition) {
rows[index].condition = condition
}
const availability = i.data?.find(i => i.key === 'availability')?.value
if (availability) {
rows[index].availability = availability
}
const price = i.data?.find(i => i.key === 'price')?.value
if (price) {
rows[index].price = price
}
const condition = i.data?.find(i => i.key === 'condition')?.value
if (condition) {
rows[index].condition = condition
}
const link = i.data?.find(i => i.key === 'link')?.value
if (link) {
rows[index].link = link
}
const price = i.data?.find(i => i.key === 'price')?.value
if (price) {
rows[index].price = price
}
const image_link = i.data?.find(i => i.key === 'image_link')?.value
if (image_link) {
rows[index].image_link = image_link
}
const link = i.data?.find(i => i.key === 'link')?.value
if (link) {
rows[index].link = link
}
const brand = i.data?.find(i => i.key === 'brand')?.value
if (brand) {
rows[index].brand = brand
}
const image_link = i.data?.find(i => i.key === 'image_link')?.value
if (image_link) {
rows[index].image_link = image_link
}
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 brand = i.data?.find(i => i.key === 'brand')?.value
if (brand) {
rows[index].brand = brand
}
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 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 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 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 sale_price = i.data?.find(i => i.key === 'sale_price')?.value
if (sale_price) {
rows[index].sale_price = sale_price
}
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_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 sale_price = i.data?.find(i => i.key === 'sale_price')?.value
if (sale_price) {
rows[index].sale_price = sale_price
}
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 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 gender = i.data?.find(i => i.key === 'gender')?.value
if (gender) {
rows[index].gender = gender
}
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 color = i.data?.find(i => i.key === 'color')?.value
if (color) {
rows[index].color = color
}
const gender = i.data?.find(i => i.key === 'gender')?.value
if (gender) {
rows[index].gender = gender
}
const size = i.data?.find(i => i.key === 'size')?.value
if (size) {
rows[index].size = size
}
const color = i.data?.find(i => i.key === 'color')?.value
if (color) {
rows[index].color = color
}
const age_group = i.data?.find(i => i.key === 'age_group')?.value
if (age_group) {
rows[index].age_group = age_group
}
const size = i.data?.find(i => i.key === 'size')?.value
if (size) {
rows[index].size = size
}
const material = i.data?.find(i => i.key === 'material')?.value
if (material) {
rows[index].material = material
}
const age_group = i.data?.find(i => i.key === 'age_group')?.value
if (age_group) {
rows[index].age_group = age_group
}
const pattern = i.data?.find(i => i.key === 'pattern')?.value
if (pattern) {
rows[index].pattern = pattern
}
const material = i.data?.find(i => i.key === 'material')?.value
if (material) {
rows[index].material = material
}
const shipping = i.data?.find(i => i.key === 'shipping')?.value
if (shipping) {
rows[index].shipping = shipping
}
const pattern = i.data?.find(i => i.key === 'pattern')?.value
if (pattern) {
rows[index].pattern = pattern
}
const shipping_weight = i.data?.find(i => i.key === 'shipping_weight')?.value
if (shipping_weight) {
rows[index].shipping_weight = shipping_weight
}
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 status = i.data?.find(i => i.key === 'status')?.value
if (status) {
rows[index].status = status
}
const product_type = i.data?.find(i => i.key === 'product_type')?.value
if (product_type) {
rows[index].product_type = product_type
}
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 custom_label_0 = i.data?.find(i => i.key === 'custom_label_0')?.value
if (custom_label_0) {
rows[index].custom_label_0 = custom_label_0
}
const product_type = i.data?.find(i => i.key === 'product_type')?.value
if (product_type) {
rows[index].product_type = product_type
}
const custom_label_1 = i.data?.find(i => i.key === 'custom_label_1')?.value
if (custom_label_1) {
rows[index].custom_label_1 = custom_label_1
}
const custom_label_0 = i.data?.find(i => i.key === 'custom_label_0')?.value
if (custom_label_0) {
rows[index].custom_label_0 = custom_label_0
}
const custom_label_2 = i.data?.find(i => i.key === 'custom_label_2')?.value
if (custom_label_2) {
rows[index].custom_label_2 = custom_label_2
}
const custom_label_1 = i.data?.find(i => i.key === 'custom_label_1')?.value
if (custom_label_1) {
rows[index].custom_label_1 = custom_label_1
}
const custom_label_3 = i.data?.find(i => i.key === 'custom_label_3')?.value
if (custom_label_3) {
rows[index].custom_label_3 = custom_label_3
}
const custom_label_2 = i.data?.find(i => i.key === 'custom_label_2')?.value
if (custom_label_2) {
rows[index].custom_label_2 = custom_label_2
}
const custom_label_4 = i.data?.find(i => i.key === 'custom_label_4')?.value
if (custom_label_4) {
rows[index].custom_label_4 = custom_label_4
}
const custom_label_3 = i.data?.find(i => i.key === 'custom_label_3')?.value
if (custom_label_3) {
rows[index].custom_label_3 = custom_label_3
}
const custom_label_4 = i.data?.find(i => i.key === 'custom_label_4')?.value
if (custom_label_4) {
rows[index].custom_label_4 = custom_label_4
}
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.rich_text_description = i.data?.find(i => i.key === 'rich_text_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 ?? ''
rows[index].save()
}
newItem.custom_label_0 = i.data?.find(i => i.key === 'custom_label_0')?.value ?? ''
newItem.custom_label_1 = i.data?.find(i => i.key === 'custom_label_1')?.value ?? ''
newItem.custom_label_2 = i.data?.find(i => i.key === 'custom_label_2')?.value ?? ''
newItem.custom_label_3 = i.data?.find(i => i.key === 'custom_label_3')?.value ?? ''
newItem.custom_label_4 = i.data?.find(i => i.key === 'custom_label_4')?.value ?? ''
})
// 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.rich_text_description = i.data?.find(i => i.key === 'rich_text_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)
}
})
newItem.custom_label_0 = i.data?.find(i => i.key === 'custom_label_0')?.value ?? ''
newItem.custom_label_1 = i.data?.find(i => i.key === 'custom_label_1')?.value ?? ''
newItem.custom_label_2 = i.data?.find(i => i.key === 'custom_label_2')?.value ?? ''
newItem.custom_label_3 = i.data?.find(i => i.key === 'custom_label_3')?.value ?? ''
newItem.custom_label_4 = i.data?.find(i => i.key === 'custom_label_4')?.value ?? ''
console.log("====== Add Rows => ", newRows)
newRows.push(newItem)
}
})
await sheet.addRows(newRows);
callback()
} catch (e) {
// @ts-ignore
error(e.toString())
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