Skip to content

Commit

Permalink
fix: prettier and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikZed committed May 11, 2022
1 parent b10c74e commit 11d9d91
Show file tree
Hide file tree
Showing 39 changed files with 7,419 additions and 7,164 deletions.
2 changes: 1 addition & 1 deletion .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
"extends": ["@commitlint/config-conventional"]
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

node_modules
dist
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: "@trieb.work/eslint-config-base",
extends: "@trieb.work/eslint-config-base",
};
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
...require("@trieb.work/prettier-base"),
...require("@trieb.work/prettier-base"),
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Zoho Inventory TS

A typescript library used to work with Zoho Inventory and Zoho Books API.
There are several functions already created, but in the end they are all custom. Some of them are documented and some are reverse-engineered and implemented in this library.
There are several functions already created, but in the end they are all custom. Some of them are documented and some are reverse-engineered and implemented in this library to have an optimised, easy way working with the Zoho APIs.

## Usage on server

Expand Down
8 changes: 4 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
65 changes: 32 additions & 33 deletions cmd/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,44 @@ import { ZohoApiClient } from "../src/v2/client/client";
import { Zoho } from "../src/v2/service";

async function main() {
const client = await ZohoApiClient.fromBrowserCookies({
orgId: "20070434578",
cookie:
"_iamadt=ae77f9993781cab3f707d0ca3d4dcc7c8c17eaf8a28f018591830e9481a25c62bfc27152e96048a1b22c868727fe7a4247cb857a8738e38255ae979e8790d614; _iambdt=04ddd2248638fdb3161c1f9252c44fa6a95772397f88c4761900ea6a622bbad2d17970333dc4066e57c92323c154a3dd1369959ff535e3e783c8b8d1107e2f75; BuildCookie_AssetType=modern; zohocares-_zldp=YfEOFpfOAG%2BhT3YzXAnuAKQBVvE9HYTh5b31kHjjc2e2RGIRFtjEZX%2FXt4msF6FbuUTTrkKWZt4%3D; zohocares-_uuid=1877bb12-835f-4eef-af6c-82ac319dcf2a_b732; 3deff6f94e=f587616fe4f86e9b5cd0e6b1849dec11; zomcscook=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; _zcsr_tmp=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; MU=2-e3dccad87c6655b8b4623635ae17312d9035a3ebf7d0e453; ad9736e59b=5f9fb8704e1c378e38cd14717691f85f; CT_CSRF_TOKEN=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; wms.agent=true; wms-tkp-token=20078972587-54e8ea4f-437f95d421dfa6e4e0185b9234a17ed7; 2175579276=821664cbd24f107b5b5fa1e2d7ec5333; CSRF_TOKEN=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; isiframeenabled=true; zohocares-_zldt=69d83961-ea67-48ff-829f-4d9a5ce91169-1; JSESSIONID=3435EE18BDC4815DA2945910AB39E8B4; com_chat_owner=1638885184516",
zsrfToken:
"zomcsparam=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1",
});
const client = await ZohoApiClient.fromCookies({
orgId: "20070434578",
cookie: "_iamadt=ae77f9993781cab3f707d0ca3d4dcc7c8c17eaf8a28f018591830e9481a25c62bfc27152e96048a1b22c868727fe7a4247cb857a8738e38255ae979e8790d614; _iambdt=04ddd2248638fdb3161c1f9252c44fa6a95772397f88c4761900ea6a622bbad2d17970333dc4066e57c92323c154a3dd1369959ff535e3e783c8b8d1107e2f75; BuildCookie_AssetType=modern; zohocares-_zldp=YfEOFpfOAG%2BhT3YzXAnuAKQBVvE9HYTh5b31kHjjc2e2RGIRFtjEZX%2FXt4msF6FbuUTTrkKWZt4%3D; zohocares-_uuid=1877bb12-835f-4eef-af6c-82ac319dcf2a_b732; 3deff6f94e=f587616fe4f86e9b5cd0e6b1849dec11; zomcscook=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; _zcsr_tmp=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; MU=2-e3dccad87c6655b8b4623635ae17312d9035a3ebf7d0e453; ad9736e59b=5f9fb8704e1c378e38cd14717691f85f; CT_CSRF_TOKEN=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; wms.agent=true; wms-tkp-token=20078972587-54e8ea4f-437f95d421dfa6e4e0185b9234a17ed7; 2175579276=821664cbd24f107b5b5fa1e2d7ec5333; CSRF_TOKEN=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1; isiframeenabled=true; zohocares-_zldt=69d83961-ea67-48ff-829f-4d9a5ce91169-1; JSESSIONID=3435EE18BDC4815DA2945910AB39E8B4; com_chat_owner=1638885184516",
zsrfToken:
"zomcsparam=1c6af2fcf50076a288ae251b35c6a58d1e94a190b3057cfbf491b257fa7aed426ff8020391feee31c38260653b2e9b621bd28afcd14c39df5e3c4f3a5446e1f1",
});

const zoho = new Zoho(client);
const zoho = new Zoho(client);

const salesOrder = await zoho.salesOrder.create({
salesorder_number: ["TEST", randomInt(90000)].join("-"),
customer_id: "116240000001023815",
line_items: [
{
item_id: "116240000000203041",
quantity: 5,
},
],
});
console.log(JSON.stringify({ salesOrder }, null, 2));
const salesOrder = await zoho.salesOrder.create({
salesorder_number: ["TEST", randomInt(90000)].join("-"),
customer_id: "116240000001023815",
line_items: [
{
item_id: "116240000000203041",
quantity: 5,
},
],
});
console.log(JSON.stringify({ salesOrder }, null, 2));

await zoho.salesOrder.setCustomFieldValue({
customFieldName: "cf_orderhash",
salesOrderIds: [salesOrder.salesorder_id],
value: "bcc",
});
await zoho.salesOrder.setCustomFieldValue({
customFieldName: "cf_ready_to_fulfill",
salesOrderIds: [salesOrder.salesorder_id],
value: "true",
});
await zoho.salesOrder.setCustomFieldValue({
customFieldName: "cf_orderhash",
salesOrderIds: [salesOrder.salesorder_id],
value: "bcc",
});
await zoho.salesOrder.setCustomFieldValue({
customFieldName: "cf_ready_to_fulfill",
salesOrderIds: [salesOrder.salesorder_id],
value: "true",
});

const found = await zoho.salesOrder.search("TEST-");
const found = await zoho.salesOrder.search("TEST-");

console.log(JSON.stringify({ found }, null, 2));
console.log(JSON.stringify({ found }, null, 2));
}

main().catch((err) => {
console.error(err);
process.exit(1);
console.error(err);
process.exit(1);
});
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
preset: "ts-jest",
testEnvironment: "node",
};
130 changes: 65 additions & 65 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
{
"name": "@trieb.work/zoho-ts",
"version": "0.4.0",
"description": "Our Typescript library helps you to work easily with the Zoho Inventory API. Most functions are generic and self-explanatory. Some are specific to our use-cases",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/trieb-work/zoho-ts.git"
},
"author": "Jannik Zinkl | trieb.work",
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "yarn tsc --watch --preserveWatchOutput",
"prepublish": "yarn build",
"format": "prettier --write .",
"fmt": "yarn lint && yarn format",
"lint": "eslint . --ext ts --ext tsx --ext js --fix",
"test": "jest"
},
"dependencies": {
"async-retry": "^1.3.1",
"await-timeout": "^1.1.1",
"axios": "^0.21.1",
"axios-retry": "^3.1.9",
"dayjs": "^1.10.4",
"form-data": "^3.0.0",
"http": "^0.0.1-security",
"https": "^1.0.0",
"simple-oauth2": "^4.2.0",
"stream": "^0.0.2",
"ts-mixer": "^5.4.0",
"zlib": "^1.0.5"
},
"devDependencies": {
"@babel/core": "^7.14.8",
"@babel/preset-env": "^7.14.8",
"@babel/preset-typescript": "^7.14.5",
"@commitlint/config-conventional": "^13.1.0",
"@trieb.work/eslint-config-base": "^1.8.14",
"@trieb.work/prettier-base": "^0.1.0-alpha.2",
"@trieb.work/tsconfig-base": "^1.6.2",
"@types/async-retry": "^1.4.2",
"@types/await-timeout": "^0.3.1",
"@types/jest": "^26.0.24",
"@types/node": "^14.14.19",
"@types/rimraf": "^3",
"@types/simple-oauth2": "^4.1.0",
"@typescript-eslint/parser": "^4.11.1",
"babel-jest": "^27.0.6",
"commitlint": "^13.1.0",
"dotenv": "^8.2.0",
"eslint": "^7.32.0",
"husky": "^7.0.2",
"jest": "^27.0.6",
"lint-staged": "^11.1.2",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.4",
"ts-node": "^9.1.1",
"typescript": "^4.4.3"
}
"name": "@trieb.work/zoho-ts",
"version": "0.4.0",
"description": "Our Typescript library helps you to work easily with the Zoho Inventory API. Most functions are generic and self-explanatory. Some are specific to our use-cases",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/trieb-work/zoho-ts.git"
},
"author": "Jannik Zinkl | trieb.work",
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "yarn tsc --watch --preserveWatchOutput",
"prepublish": "yarn build",
"format": "prettier --write .",
"fmt": "yarn lint && yarn format",
"lint": "eslint . --ext ts --ext tsx --ext js --fix",
"test": "jest"
},
"dependencies": {
"async-retry": "^1.3.1",
"await-timeout": "^1.1.1",
"axios": "^0.21.1",
"axios-retry": "^3.1.9",
"dayjs": "^1.10.4",
"form-data": "^3.0.0",
"http": "^0.0.1-security",
"https": "^1.0.0",
"simple-oauth2": "^4.2.0",
"stream": "^0.0.2",
"ts-mixer": "^5.4.0",
"zlib": "^1.0.5"
},
"devDependencies": {
"@babel/core": "^7.14.8",
"@babel/preset-env": "^7.14.8",
"@babel/preset-typescript": "^7.14.5",
"@commitlint/config-conventional": "^16.2.4",
"@trieb.work/eslint-config-base": "^1.10.1",
"@trieb.work/prettier-base": "^0.2.0",
"@trieb.work/tsconfig-base": "^1.6.4",
"@types/async-retry": "^1.4.2",
"@types/await-timeout": "^0.3.1",
"@types/jest": "^26.0.24",
"@types/node": "^14.14.19",
"@types/rimraf": "^3",
"@types/simple-oauth2": "^4.1.0",
"@typescript-eslint/parser": "^4.11.1",
"babel-jest": "^27.0.6",
"commitlint": "^16.2.4",
"dotenv": "^8.2.0",
"eslint": "^8.15.0",
"husky": "^8.0.1",
"jest": "^27.0.6",
"lint-staged": "^12.4.1",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.4",
"ts-node": "^9.1.1",
"typescript": "^4.6.4"
}
}
24 changes: 12 additions & 12 deletions src/browserInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import axios from "axios";
import { MultiMethods } from "./callZoho";

export class ZohoBrowserInstance extends MultiMethods {
constructor(config: { zohoOrgId: string; csrfToken: string }) {
super();
this.zohoOrgId = config.zohoOrgId;
this.instance = axios.create({
baseURL: "https://inventory.zoho.eu/api/v1",
timeout: 7000,
params: { organization_id: this.zohoOrgId },
headers: {
"X-ZCSRF-TOKEN": `zomcsparam=${config.csrfToken}`,
},
});
}
constructor(config: { zohoOrgId: string; csrfToken: string }) {
super();
this.zohoOrgId = config.zohoOrgId;
this.instance = axios.create({
baseURL: "https://inventory.zoho.eu/api/v1",
timeout: 7000,
params: { organization_id: this.zohoOrgId },
headers: {
"X-ZCSRF-TOKEN": `zomcsparam=${config.csrfToken}`,
},
});
}
}
Loading

0 comments on commit 11d9d91

Please sign in to comment.