repzo 1.0.231 → 1.0.234
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/lib/helper.d.ts +1 -0
- package/lib/helper.js +17 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +68 -1
- package/lib/test.d.ts +1 -0
- package/lib/test.js +7 -0
- package/lib/types/index.d.ts +56 -0
- package/lib/types/index.js +0 -1
- package/package.json +3 -2
- package/src/helper.ts +32 -0
- package/src/index.ts +95 -1
- package/src/test.ts +8 -0
- package/src/types/index.ts +59 -1
package/lib/helper.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateUUID: (prefix?: string, suffix?: string, length?: number) => string;
|
package/lib/helper.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
export const generateUUID = (prefix = "", suffix = "", length = 8) => {
|
|
3
|
+
if ((prefix && typeof prefix !== "string") ||
|
|
4
|
+
(suffix && typeof suffix !== "string")) {
|
|
5
|
+
throw new Error("Prefix and suffix must be strings");
|
|
6
|
+
}
|
|
7
|
+
if (typeof crypto === "undefined" ||
|
|
8
|
+
typeof crypto.randomBytes !== "function") {
|
|
9
|
+
throw new Error("crypto module or randomBytes function is unavailable");
|
|
10
|
+
}
|
|
11
|
+
const randomPortion = BigInt(`0x${crypto.randomBytes(length).toString("hex")}`).toString(36);
|
|
12
|
+
const timestamp = Date.now().toString(36);
|
|
13
|
+
const formattedPrefix = prefix ? `${prefix}-` : "";
|
|
14
|
+
const formattedSuffix = suffix ? `-${suffix}` : "";
|
|
15
|
+
const uuid = `${formattedPrefix}${timestamp}${randomPortion}${formattedSuffix}`;
|
|
16
|
+
return uuid;
|
|
17
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -118,6 +118,8 @@ export declare const end_points: {
|
|
|
118
118
|
readonly CLM_FETCH: "clm-fetch";
|
|
119
119
|
readonly PROMOTIONS: "promotions";
|
|
120
120
|
readonly COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse";
|
|
121
|
+
readonly AUTHENTICATE: "authenticate";
|
|
122
|
+
readonly OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service";
|
|
121
123
|
};
|
|
122
124
|
export type EndPoints = (typeof end_points)[keyof typeof end_points];
|
|
123
125
|
export declare const availableService: readonly ["client", "product", "variant", "category", "sub_category", "brand", "product_group", "tax", "measureunit", "measureunitFamily", "media", "priceList", "priceListItem", "team", "returnReason", "rep", "tag", "warehouse", "route", "productModifiersGroup", "channel", "speciality", "clientContact", "paymentTerm", "bank", "bank_list", "customStatus", "customList", "customListItem", "inventoryAdjustmentReason", "workorder", "workorderRequest", "supplier", "quickConvertToPdf", "visit", "activityFeedback", "activityFeedbackV2", "feedbackOption", "invoice", "proforma", "payment", "refund", "settlement", "voidSettlement", "check", "day", "receivingMaterial", "adjustAccount", "transfer", "msl", "mslProduct", "mediaStorage", "storecheckTemplate", "activityStorecheck", "adjustInventory", "inventory", "integrationApp", "joinActionsWebHook", "patchAction", "updateIntegrationMeta", "assetPartType", "assetPart", "assetPartUnit", "assetPartReceival", "assetPartTransfer", "returnAssetPartUnit", "storeAssetPartUnit", "ocrInvoiceJobTemplate", "ocrInvoiceJobGroup", "activityAiSalesOrder", "ocrInvoiceJob", "ocrInvoiceJobPage", "settings", "mailUnsubscribe", "approvalRequest", "safeInvoiceSerialCounter", "clientLocation", "assetType", "asset", "assetUnit", "workorderPortal", "approval", "workorderCategory", "contract", "contractInstallment", "repBalanceSummary", "workorderPortalLink", "customField", "salesAnalyticsReport", "clmPresentation", "clmSequence", "clmSlide", "clmFetch"];
|
|
@@ -127,6 +129,9 @@ export default class Repzo {
|
|
|
127
129
|
headers: Headers;
|
|
128
130
|
private timeout;
|
|
129
131
|
private retryAttempts;
|
|
132
|
+
private refresh_token?;
|
|
133
|
+
private nameSpace?;
|
|
134
|
+
private reauthCallBackFn?;
|
|
130
135
|
constructor(apiKey: string, options?: Options);
|
|
131
136
|
private static _end_points;
|
|
132
137
|
static get END_POINTS(): {
|
|
@@ -248,6 +253,8 @@ export default class Repzo {
|
|
|
248
253
|
readonly CLM_FETCH: "clm-fetch";
|
|
249
254
|
readonly PROMOTIONS: "promotions";
|
|
250
255
|
readonly COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse";
|
|
256
|
+
readonly AUTHENTICATE: "authenticate";
|
|
257
|
+
readonly OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service";
|
|
251
258
|
};
|
|
252
259
|
private _retryRequest;
|
|
253
260
|
private _fetch;
|
|
@@ -256,6 +263,18 @@ export default class Repzo {
|
|
|
256
263
|
private _patch;
|
|
257
264
|
private _delete;
|
|
258
265
|
available_services: readonly ["client", "product", "variant", "category", "sub_category", "brand", "product_group", "tax", "measureunit", "measureunitFamily", "media", "priceList", "priceListItem", "team", "returnReason", "rep", "tag", "warehouse", "route", "productModifiersGroup", "channel", "speciality", "clientContact", "paymentTerm", "bank", "bank_list", "customStatus", "customList", "customListItem", "inventoryAdjustmentReason", "workorder", "workorderRequest", "supplier", "quickConvertToPdf", "visit", "activityFeedback", "activityFeedbackV2", "feedbackOption", "invoice", "proforma", "payment", "refund", "settlement", "voidSettlement", "check", "day", "receivingMaterial", "adjustAccount", "transfer", "msl", "mslProduct", "mediaStorage", "storecheckTemplate", "activityStorecheck", "adjustInventory", "inventory", "integrationApp", "joinActionsWebHook", "patchAction", "updateIntegrationMeta", "assetPartType", "assetPart", "assetPartUnit", "assetPartReceival", "assetPartTransfer", "returnAssetPartUnit", "storeAssetPartUnit", "ocrInvoiceJobTemplate", "ocrInvoiceJobGroup", "activityAiSalesOrder", "ocrInvoiceJob", "ocrInvoiceJobPage", "settings", "mailUnsubscribe", "approvalRequest", "safeInvoiceSerialCounter", "clientLocation", "assetType", "asset", "assetUnit", "workorderPortal", "approval", "workorderCategory", "contract", "contractInstallment", "repBalanceSummary", "workorderPortalLink", "customField", "salesAnalyticsReport", "clmPresentation", "clmSequence", "clmSlide", "clmFetch"];
|
|
266
|
+
generateUUID: ({ prefix, suffix, length, }: {
|
|
267
|
+
prefix?: string;
|
|
268
|
+
suffix?: string;
|
|
269
|
+
length: number;
|
|
270
|
+
}) => string;
|
|
271
|
+
core: {
|
|
272
|
+
updateHeader: (newHeaders: {
|
|
273
|
+
authorization?: string;
|
|
274
|
+
refresh_token?: string;
|
|
275
|
+
}) => void;
|
|
276
|
+
reauth: () => Promise<Service.Reauth.Result>;
|
|
277
|
+
};
|
|
259
278
|
client: {
|
|
260
279
|
_path: "client";
|
|
261
280
|
find: (params?: Service.Client.Find.Params) => Promise<Service.Client.Find.Result>;
|
|
@@ -1159,4 +1178,9 @@ export default class Repzo {
|
|
|
1159
1178
|
update: (id: Service.PdfTemplate.Update.ID, body: Service.PdfTemplate.Update.Body) => Promise<Service.PdfTemplate.Update.Result>;
|
|
1160
1179
|
remove: (id: Service.PdfTemplate.Remove.ID) => Promise<Service.PdfTemplate.Remove.Result>;
|
|
1161
1180
|
};
|
|
1181
|
+
optionalBusinessAppService: {
|
|
1182
|
+
_path: "optional-business-app-service";
|
|
1183
|
+
find: () => Promise<Service.OptionalBusinessAppService.Find.Result>;
|
|
1184
|
+
create: () => Promise<Service.OptionalBusinessAppService.Create.Result>;
|
|
1185
|
+
};
|
|
1162
1186
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { v4 as uuid } from "uuid";
|
|
3
|
+
import { generateUUID } from "./helper.js";
|
|
3
4
|
export const end_points = {
|
|
4
5
|
CLIENT: "client",
|
|
5
6
|
PRODUCT: "product",
|
|
@@ -119,6 +120,8 @@ export const end_points = {
|
|
|
119
120
|
CLM_FETCH: "clm-fetch",
|
|
120
121
|
PROMOTIONS: "promotions",
|
|
121
122
|
COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse",
|
|
123
|
+
AUTHENTICATE: "authenticate",
|
|
124
|
+
OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service",
|
|
122
125
|
};
|
|
123
126
|
export const availableService = [
|
|
124
127
|
"client",
|
|
@@ -218,6 +221,43 @@ export const availableService = [
|
|
|
218
221
|
class Repzo {
|
|
219
222
|
constructor(apiKey, options) {
|
|
220
223
|
this.available_services = availableService;
|
|
224
|
+
this.generateUUID = ({ prefix, suffix, length, }) => {
|
|
225
|
+
return generateUUID(prefix, suffix, length);
|
|
226
|
+
};
|
|
227
|
+
this.core = {
|
|
228
|
+
updateHeader: (newHeaders) => {
|
|
229
|
+
if (newHeaders?.authorization) {
|
|
230
|
+
this.headers["authorization"] = newHeaders.authorization;
|
|
231
|
+
}
|
|
232
|
+
if (newHeaders?.refresh_token) {
|
|
233
|
+
this.headers["refresh_token"] = newHeaders.refresh_token;
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
reauth: async () => {
|
|
237
|
+
const nameSpace = this.nameSpace;
|
|
238
|
+
const refreshToken = this.refresh_token;
|
|
239
|
+
if (!nameSpace || !refreshToken) {
|
|
240
|
+
throw new Error("Missing required parameters for reauth");
|
|
241
|
+
}
|
|
242
|
+
const headers = {
|
|
243
|
+
"Content-Type": "application/json",
|
|
244
|
+
Accept: "application/json",
|
|
245
|
+
"X-NAME-SPACE": nameSpace,
|
|
246
|
+
refresh_token: refreshToken,
|
|
247
|
+
};
|
|
248
|
+
const res = await axios.get(`${this.svAPIEndpoint}/${Repzo._end_points.AUTHENTICATE}`, { headers: headers, timeout: this.timeout });
|
|
249
|
+
const result = res.data;
|
|
250
|
+
if (result.login_status == "success") {
|
|
251
|
+
this.core.updateHeader({
|
|
252
|
+
authorization: result.access_token,
|
|
253
|
+
refresh_token: result.refresh_token,
|
|
254
|
+
});
|
|
255
|
+
if (this.reauthCallBackFn)
|
|
256
|
+
this.reauthCallBackFn(result);
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
},
|
|
260
|
+
};
|
|
221
261
|
this.client = {
|
|
222
262
|
_path: Repzo._end_points.CLIENT,
|
|
223
263
|
find: async (params) => {
|
|
@@ -2382,6 +2422,17 @@ class Repzo {
|
|
|
2382
2422
|
return res;
|
|
2383
2423
|
},
|
|
2384
2424
|
};
|
|
2425
|
+
this.optionalBusinessAppService = {
|
|
2426
|
+
_path: Repzo._end_points.OPTIONAL_BUSINESS_APP_SERVICE,
|
|
2427
|
+
find: async () => {
|
|
2428
|
+
let res = await this._fetch(this.svAPIEndpoint, this.optionalBusinessAppService._path);
|
|
2429
|
+
return res;
|
|
2430
|
+
},
|
|
2431
|
+
create: async () => {
|
|
2432
|
+
let res = await this._create(this.svAPIEndpoint, this.optionalBusinessAppService._path, {});
|
|
2433
|
+
return res;
|
|
2434
|
+
},
|
|
2435
|
+
};
|
|
2385
2436
|
this.svAPIEndpoint =
|
|
2386
2437
|
!options?.env || options?.env == "production"
|
|
2387
2438
|
? "https://sv.api.repzo.me"
|
|
@@ -2395,6 +2446,12 @@ class Repzo {
|
|
|
2395
2446
|
"Content-Type": "application/json",
|
|
2396
2447
|
Accept: "application/json",
|
|
2397
2448
|
};
|
|
2449
|
+
if (options?.nameSpace)
|
|
2450
|
+
this.nameSpace = options.nameSpace;
|
|
2451
|
+
if (options?.refresh_token)
|
|
2452
|
+
this.refresh_token = options.refresh_token;
|
|
2453
|
+
if (options?.reauthCallBackFn)
|
|
2454
|
+
this.reauthCallBackFn = options.reauthCallBackFn;
|
|
2398
2455
|
if (options?.headers)
|
|
2399
2456
|
Object.assign(this.headers, options.headers);
|
|
2400
2457
|
if (options?.timeout) {
|
|
@@ -2414,7 +2471,17 @@ class Repzo {
|
|
|
2414
2471
|
}
|
|
2415
2472
|
catch (error) {
|
|
2416
2473
|
// Don't retry on 401 (Unauthorized) errors
|
|
2417
|
-
if (error?.response?.status === 401
|
|
2474
|
+
if (error?.response?.status === 401 &&
|
|
2475
|
+
this.refresh_token &&
|
|
2476
|
+
this.nameSpace) {
|
|
2477
|
+
try {
|
|
2478
|
+
await this.core.reauth();
|
|
2479
|
+
}
|
|
2480
|
+
catch (e) {
|
|
2481
|
+
throw error;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
else {
|
|
2418
2485
|
throw error;
|
|
2419
2486
|
}
|
|
2420
2487
|
// Retry if we haven't exceeded the retry attempts
|
package/lib/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/test.js
ADDED
package/lib/types/index.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface Options {
|
|
|
13
13
|
};
|
|
14
14
|
timeout?: number | undefined;
|
|
15
15
|
retryAttempts?: number;
|
|
16
|
+
nameSpace?: string;
|
|
17
|
+
refresh_token?: string;
|
|
18
|
+
reauthCallBackFn?: (res: Service.Reauth.Result) => void;
|
|
16
19
|
}
|
|
17
20
|
export interface Headers {
|
|
18
21
|
"api-key": string;
|
|
@@ -2441,6 +2444,9 @@ export declare namespace Service {
|
|
|
2441
2444
|
rep_must_end_day_after_specific_time: boolean;
|
|
2442
2445
|
rep_can_upload_media_on_payment?: boolean;
|
|
2443
2446
|
rep_can_access_sales_reports?: boolean;
|
|
2447
|
+
rep_must_add_delivery_date_on_sales_order_and_invoice?: boolean;
|
|
2448
|
+
rep_can_view_stock_on_transfers?: boolean;
|
|
2449
|
+
rep_must_invoice_items_from_cross_inventory_and_msl?: boolean;
|
|
2444
2450
|
}
|
|
2445
2451
|
interface TargetResults {
|
|
2446
2452
|
totalPoints: number;
|
|
@@ -2697,6 +2703,9 @@ export declare namespace Service {
|
|
|
2697
2703
|
"permissions.rep_can_create_negative_invoices"?: boolean;
|
|
2698
2704
|
"permissions.rep_can_upload_media_on_payment"?: boolean;
|
|
2699
2705
|
"permissions.rep_can_access_sales_reports"?: boolean;
|
|
2706
|
+
"permissions.rep_must_add_delivery_date_on_sales_order_and_invoice"?: boolean;
|
|
2707
|
+
"permissions.rep_can_view_stock_on_transfers"?: boolean;
|
|
2708
|
+
"permissions.rep_must_invoice_items_from_cross_inventory_and_msl"?: boolean;
|
|
2700
2709
|
"settings.rep_must_end_day_after"?: `${number}:${number}`;
|
|
2701
2710
|
"settings.allowable_accuracy"?: number;
|
|
2702
2711
|
"settings.is_item_status_per_visit_limited"?: boolean;
|
|
@@ -17039,6 +17048,31 @@ export declare namespace Service {
|
|
|
17039
17048
|
}
|
|
17040
17049
|
}
|
|
17041
17050
|
}
|
|
17051
|
+
namespace Reauth {
|
|
17052
|
+
interface Result {
|
|
17053
|
+
access_token: string;
|
|
17054
|
+
refresh_token: string;
|
|
17055
|
+
login_status: "success";
|
|
17056
|
+
teams: StringId[];
|
|
17057
|
+
populated_teams?: Pick<Team.TeamSchema, "name" | "_id">[];
|
|
17058
|
+
permissions: Rep.Data["permissions"];
|
|
17059
|
+
rep: StringId;
|
|
17060
|
+
identifier: number;
|
|
17061
|
+
exp: number;
|
|
17062
|
+
modules: string[];
|
|
17063
|
+
realm_token: string;
|
|
17064
|
+
app_code: string;
|
|
17065
|
+
country: string;
|
|
17066
|
+
country_code: string[];
|
|
17067
|
+
is_test: boolean;
|
|
17068
|
+
suspended: boolean;
|
|
17069
|
+
nameSpace: string[];
|
|
17070
|
+
allow_treating_invoice_as_proforma_for_etax: boolean;
|
|
17071
|
+
time_zone: string;
|
|
17072
|
+
EOD: string;
|
|
17073
|
+
allow_offline_day: boolean;
|
|
17074
|
+
}
|
|
17075
|
+
}
|
|
17042
17076
|
namespace PrintSetting {
|
|
17043
17077
|
type ImageSize = "original" | "small" | "medium" | "large" | "extra";
|
|
17044
17078
|
type QrCodeSize = "small" | "medium" | "large";
|
|
@@ -17527,6 +17561,28 @@ export declare namespace Service {
|
|
|
17527
17561
|
}
|
|
17528
17562
|
export {};
|
|
17529
17563
|
}
|
|
17564
|
+
namespace OptionalBusinessAppService {
|
|
17565
|
+
namespace Find {
|
|
17566
|
+
interface Result {
|
|
17567
|
+
code: string;
|
|
17568
|
+
services: {
|
|
17569
|
+
permission: StringId;
|
|
17570
|
+
name: string;
|
|
17571
|
+
default_teams_shared: "shared" | "unshared";
|
|
17572
|
+
}[];
|
|
17573
|
+
}
|
|
17574
|
+
}
|
|
17575
|
+
namespace Create {
|
|
17576
|
+
interface Result {
|
|
17577
|
+
code: string;
|
|
17578
|
+
services: {
|
|
17579
|
+
permission: StringId;
|
|
17580
|
+
name: string;
|
|
17581
|
+
teams_shared: "shared" | "unshared";
|
|
17582
|
+
}[];
|
|
17583
|
+
}
|
|
17584
|
+
}
|
|
17585
|
+
}
|
|
17530
17586
|
}
|
|
17531
17587
|
export type StringId = string;
|
|
17532
17588
|
export type NameSpaces = string[];
|
package/lib/types/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repzo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.234",
|
|
4
4
|
"description": "Repzo TypeScript SDK",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"changelog.md"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"test": "npm run test",
|
|
16
|
+
"test": "npm run build && node ./lib/test.js",
|
|
17
17
|
"lint": "npx prettier --write .",
|
|
18
18
|
"build": "tsc --skipLibCheck && npm run lint",
|
|
19
19
|
"docs:generate": "node scripts/build-docs.js",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@apidevtools/swagger-parser": "^12.0.0",
|
|
59
59
|
"@redocly/openapi-cli": "^0.12.16",
|
|
60
|
+
"@types/node": "^24.10.0",
|
|
60
61
|
"@types/uuid": "^8.3.4",
|
|
61
62
|
"axios": "^0.26.1",
|
|
62
63
|
"js-yaml": "^4.1.0",
|
package/src/helper.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
export const generateUUID = (
|
|
4
|
+
prefix = "",
|
|
5
|
+
suffix = "",
|
|
6
|
+
length: number = 8,
|
|
7
|
+
): string => {
|
|
8
|
+
if (
|
|
9
|
+
(prefix && typeof prefix !== "string") ||
|
|
10
|
+
(suffix && typeof suffix !== "string")
|
|
11
|
+
) {
|
|
12
|
+
throw new Error("Prefix and suffix must be strings");
|
|
13
|
+
}
|
|
14
|
+
if (
|
|
15
|
+
typeof crypto === "undefined" ||
|
|
16
|
+
typeof crypto.randomBytes !== "function"
|
|
17
|
+
) {
|
|
18
|
+
throw new Error("crypto module or randomBytes function is unavailable");
|
|
19
|
+
}
|
|
20
|
+
const randomPortion = BigInt(
|
|
21
|
+
`0x${crypto.randomBytes(length).toString("hex")}`,
|
|
22
|
+
).toString(36);
|
|
23
|
+
|
|
24
|
+
const timestamp = Date.now().toString(36);
|
|
25
|
+
|
|
26
|
+
const formattedPrefix = prefix ? `${prefix}-` : "";
|
|
27
|
+
const formattedSuffix = suffix ? `-${suffix}` : "";
|
|
28
|
+
|
|
29
|
+
const uuid = `${formattedPrefix}${timestamp}${randomPortion}${formattedSuffix}`;
|
|
30
|
+
|
|
31
|
+
return uuid;
|
|
32
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
StringId,
|
|
10
10
|
NameSpaces,
|
|
11
11
|
} from "./types/index";
|
|
12
|
+
import { generateUUID } from "./helper.js";
|
|
12
13
|
|
|
13
14
|
export const end_points = {
|
|
14
15
|
CLIENT: "client",
|
|
@@ -129,6 +130,8 @@ export const end_points = {
|
|
|
129
130
|
CLM_FETCH: "clm-fetch",
|
|
130
131
|
PROMOTIONS: "promotions",
|
|
131
132
|
COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse",
|
|
133
|
+
AUTHENTICATE: "authenticate",
|
|
134
|
+
OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service",
|
|
132
135
|
} as const;
|
|
133
136
|
export type EndPoints = (typeof end_points)[keyof typeof end_points];
|
|
134
137
|
|
|
@@ -234,6 +237,9 @@ export default class Repzo {
|
|
|
234
237
|
headers: Headers;
|
|
235
238
|
private timeout: number;
|
|
236
239
|
private retryAttempts: number;
|
|
240
|
+
private refresh_token?: string;
|
|
241
|
+
private nameSpace?: string;
|
|
242
|
+
private reauthCallBackFn?: (res: Service.Reauth.Result) => void;
|
|
237
243
|
constructor(apiKey: string, options?: Options) {
|
|
238
244
|
this.svAPIEndpoint =
|
|
239
245
|
!options?.env || options?.env == "production"
|
|
@@ -249,6 +255,10 @@ export default class Repzo {
|
|
|
249
255
|
"Content-Type": "application/json",
|
|
250
256
|
Accept: "application/json",
|
|
251
257
|
};
|
|
258
|
+
if (options?.nameSpace) this.nameSpace = options.nameSpace;
|
|
259
|
+
if (options?.refresh_token) this.refresh_token = options.refresh_token;
|
|
260
|
+
if (options?.reauthCallBackFn)
|
|
261
|
+
this.reauthCallBackFn = options.reauthCallBackFn;
|
|
252
262
|
if (options?.headers) Object.assign(this.headers, options.headers);
|
|
253
263
|
if (options?.timeout) {
|
|
254
264
|
this.timeout = options.timeout;
|
|
@@ -271,7 +281,17 @@ export default class Repzo {
|
|
|
271
281
|
return await requestFn();
|
|
272
282
|
} catch (error: any) {
|
|
273
283
|
// Don't retry on 401 (Unauthorized) errors
|
|
274
|
-
if (
|
|
284
|
+
if (
|
|
285
|
+
error?.response?.status === 401 &&
|
|
286
|
+
this.refresh_token &&
|
|
287
|
+
this.nameSpace
|
|
288
|
+
) {
|
|
289
|
+
try {
|
|
290
|
+
await this.core.reauth();
|
|
291
|
+
} catch (e) {
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
275
295
|
throw error;
|
|
276
296
|
}
|
|
277
297
|
|
|
@@ -363,6 +383,59 @@ export default class Repzo {
|
|
|
363
383
|
|
|
364
384
|
available_services = availableService;
|
|
365
385
|
|
|
386
|
+
generateUUID = ({
|
|
387
|
+
prefix,
|
|
388
|
+
suffix,
|
|
389
|
+
length,
|
|
390
|
+
}: {
|
|
391
|
+
prefix?: string;
|
|
392
|
+
suffix?: string;
|
|
393
|
+
length: number;
|
|
394
|
+
}): string => {
|
|
395
|
+
return generateUUID(prefix, suffix, length);
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
core = {
|
|
399
|
+
updateHeader: (newHeaders: {
|
|
400
|
+
authorization?: string;
|
|
401
|
+
refresh_token?: string;
|
|
402
|
+
}) => {
|
|
403
|
+
if (newHeaders?.authorization) {
|
|
404
|
+
this.headers["authorization"] = newHeaders.authorization;
|
|
405
|
+
}
|
|
406
|
+
if (newHeaders?.refresh_token) {
|
|
407
|
+
this.headers["refresh_token"] = newHeaders.refresh_token;
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
reauth: async (): Promise<Service.Reauth.Result> => {
|
|
412
|
+
const nameSpace = this.nameSpace;
|
|
413
|
+
const refreshToken = this.refresh_token;
|
|
414
|
+
if (!nameSpace || !refreshToken) {
|
|
415
|
+
throw new Error("Missing required parameters for reauth");
|
|
416
|
+
}
|
|
417
|
+
const headers = {
|
|
418
|
+
"Content-Type": "application/json",
|
|
419
|
+
Accept: "application/json",
|
|
420
|
+
"X-NAME-SPACE": nameSpace,
|
|
421
|
+
refresh_token: refreshToken,
|
|
422
|
+
};
|
|
423
|
+
const res: any = await axios.get(
|
|
424
|
+
`${this.svAPIEndpoint}/${Repzo._end_points.AUTHENTICATE}`,
|
|
425
|
+
{ headers: headers, timeout: this.timeout },
|
|
426
|
+
);
|
|
427
|
+
const result: Service.Reauth.Result = res.data;
|
|
428
|
+
if (result.login_status == "success") {
|
|
429
|
+
this.core.updateHeader({
|
|
430
|
+
authorization: result.access_token,
|
|
431
|
+
refresh_token: result.refresh_token,
|
|
432
|
+
});
|
|
433
|
+
if (this.reauthCallBackFn) this.reauthCallBackFn(result);
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
|
|
366
439
|
client = {
|
|
367
440
|
_path: Repzo._end_points.CLIENT,
|
|
368
441
|
find: async (
|
|
@@ -6064,6 +6137,27 @@ export default class Repzo {
|
|
|
6064
6137
|
return res;
|
|
6065
6138
|
},
|
|
6066
6139
|
};
|
|
6140
|
+
|
|
6141
|
+
optionalBusinessAppService = {
|
|
6142
|
+
_path: Repzo._end_points.OPTIONAL_BUSINESS_APP_SERVICE,
|
|
6143
|
+
find: async (): Promise<Service.OptionalBusinessAppService.Find.Result> => {
|
|
6144
|
+
let res: Service.OptionalBusinessAppService.Find.Result =
|
|
6145
|
+
await this._fetch(
|
|
6146
|
+
this.svAPIEndpoint,
|
|
6147
|
+
this.optionalBusinessAppService._path,
|
|
6148
|
+
);
|
|
6149
|
+
return res;
|
|
6150
|
+
},
|
|
6151
|
+
create:
|
|
6152
|
+
async (): Promise<Service.OptionalBusinessAppService.Create.Result> => {
|
|
6153
|
+
let res = await this._create(
|
|
6154
|
+
this.svAPIEndpoint,
|
|
6155
|
+
this.optionalBusinessAppService._path,
|
|
6156
|
+
{},
|
|
6157
|
+
);
|
|
6158
|
+
return res;
|
|
6159
|
+
},
|
|
6160
|
+
};
|
|
6067
6161
|
}
|
|
6068
6162
|
|
|
6069
6163
|
function normalizeParams(params: Params): { [key: string]: any } {
|
package/src/test.ts
ADDED
package/src/types/index.ts
CHANGED
|
@@ -12,6 +12,9 @@ export interface Options {
|
|
|
12
12
|
headers?: { [key: string]: string };
|
|
13
13
|
timeout?: number | undefined;
|
|
14
14
|
retryAttempts?: number;
|
|
15
|
+
nameSpace?: string;
|
|
16
|
+
refresh_token?: string;
|
|
17
|
+
reauthCallBackFn?: (res: Service.Reauth.Result) => void;
|
|
15
18
|
}
|
|
16
19
|
export interface Headers {
|
|
17
20
|
"api-key": string;
|
|
@@ -463,7 +466,6 @@ interface GeoPoint {
|
|
|
463
466
|
coordinates: [number, number];
|
|
464
467
|
}
|
|
465
468
|
|
|
466
|
-
// <reference path = "vehicle.ts" />
|
|
467
469
|
export namespace Service {
|
|
468
470
|
export namespace Client {
|
|
469
471
|
interface Financials {
|
|
@@ -2849,6 +2851,9 @@ export namespace Service {
|
|
|
2849
2851
|
rep_must_end_day_after_specific_time: boolean;
|
|
2850
2852
|
rep_can_upload_media_on_payment?: boolean;
|
|
2851
2853
|
rep_can_access_sales_reports?: boolean;
|
|
2854
|
+
rep_must_add_delivery_date_on_sales_order_and_invoice?: boolean;
|
|
2855
|
+
rep_can_view_stock_on_transfers?: boolean;
|
|
2856
|
+
rep_must_invoice_items_from_cross_inventory_and_msl?: boolean;
|
|
2852
2857
|
}
|
|
2853
2858
|
interface TargetResults {
|
|
2854
2859
|
totalPoints: number;
|
|
@@ -3129,6 +3134,9 @@ export namespace Service {
|
|
|
3129
3134
|
"permissions.rep_can_create_negative_invoices"?: boolean;
|
|
3130
3135
|
"permissions.rep_can_upload_media_on_payment"?: boolean;
|
|
3131
3136
|
"permissions.rep_can_access_sales_reports"?: boolean;
|
|
3137
|
+
"permissions.rep_must_add_delivery_date_on_sales_order_and_invoice"?: boolean;
|
|
3138
|
+
"permissions.rep_can_view_stock_on_transfers"?: boolean;
|
|
3139
|
+
"permissions.rep_must_invoice_items_from_cross_inventory_and_msl"?: boolean;
|
|
3132
3140
|
"settings.rep_must_end_day_after"?: `${number}:${number}`;
|
|
3133
3141
|
"settings.allowable_accuracy"?: number;
|
|
3134
3142
|
"settings.is_item_status_per_visit_limited"?: boolean;
|
|
@@ -19058,6 +19066,32 @@ export namespace Service {
|
|
|
19058
19066
|
}
|
|
19059
19067
|
}
|
|
19060
19068
|
|
|
19069
|
+
export namespace Reauth {
|
|
19070
|
+
export interface Result {
|
|
19071
|
+
access_token: string;
|
|
19072
|
+
refresh_token: string;
|
|
19073
|
+
login_status: "success";
|
|
19074
|
+
teams: StringId[];
|
|
19075
|
+
populated_teams?: Pick<Team.TeamSchema, "name" | "_id">[];
|
|
19076
|
+
permissions: Rep.Data["permissions"];
|
|
19077
|
+
rep: StringId;
|
|
19078
|
+
identifier: number;
|
|
19079
|
+
exp: number; // timestamp
|
|
19080
|
+
modules: string[];
|
|
19081
|
+
realm_token: string;
|
|
19082
|
+
app_code: string;
|
|
19083
|
+
country: string;
|
|
19084
|
+
country_code: string[];
|
|
19085
|
+
is_test: boolean;
|
|
19086
|
+
suspended: boolean;
|
|
19087
|
+
nameSpace: string[];
|
|
19088
|
+
allow_treating_invoice_as_proforma_for_etax: boolean;
|
|
19089
|
+
time_zone: string;
|
|
19090
|
+
EOD: string;
|
|
19091
|
+
allow_offline_day: boolean;
|
|
19092
|
+
}
|
|
19093
|
+
}
|
|
19094
|
+
|
|
19061
19095
|
export namespace PrintSetting {
|
|
19062
19096
|
export type ImageSize = "original" | "small" | "medium" | "large" | "extra";
|
|
19063
19097
|
export type QrCodeSize = "small" | "medium" | "large";
|
|
@@ -19588,6 +19622,30 @@ export namespace Service {
|
|
|
19588
19622
|
export type Result = Data;
|
|
19589
19623
|
}
|
|
19590
19624
|
}
|
|
19625
|
+
|
|
19626
|
+
export namespace OptionalBusinessAppService {
|
|
19627
|
+
export namespace Find {
|
|
19628
|
+
export interface Result {
|
|
19629
|
+
code: string;
|
|
19630
|
+
services: {
|
|
19631
|
+
permission: StringId;
|
|
19632
|
+
name: string;
|
|
19633
|
+
default_teams_shared: "shared" | "unshared";
|
|
19634
|
+
}[];
|
|
19635
|
+
}
|
|
19636
|
+
}
|
|
19637
|
+
|
|
19638
|
+
export namespace Create {
|
|
19639
|
+
export interface Result {
|
|
19640
|
+
code: string;
|
|
19641
|
+
services: {
|
|
19642
|
+
permission: StringId;
|
|
19643
|
+
name: string;
|
|
19644
|
+
teams_shared: "shared" | "unshared";
|
|
19645
|
+
}[];
|
|
19646
|
+
}
|
|
19647
|
+
}
|
|
19648
|
+
}
|
|
19591
19649
|
}
|
|
19592
19650
|
|
|
19593
19651
|
export type StringId = string;
|