repzo 1.0.230 → 1.0.233
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 +43 -0
- package/lib/index.js +110 -1
- package/lib/test.d.ts +1 -0
- package/lib/test.js +7 -0
- package/lib/types/index.d.ts +219 -1
- package/lib/types/index.js +0 -1
- package/package.json +3 -2
- package/src/helper.ts +32 -0
- package/src/index.ts +206 -1
- package/src/test.ts +8 -0
- package/src/types/index.ts +236 -2
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
|
@@ -39,6 +39,8 @@ export declare const end_points: {
|
|
|
39
39
|
readonly INVOICE: "fullinvoices";
|
|
40
40
|
readonly PROFORMA: "proforma";
|
|
41
41
|
readonly PRINT_SETTINGS: "print-settings";
|
|
42
|
+
readonly PDF_TEMPLATE_GALLERY: "pdf-template-gallery";
|
|
43
|
+
readonly PDF_TEMPLATE: "pdf-template";
|
|
42
44
|
readonly PAYMENT: "payments";
|
|
43
45
|
readonly REFUND: "refund";
|
|
44
46
|
readonly SETTLEMENT: "settlement";
|
|
@@ -116,6 +118,8 @@ export declare const end_points: {
|
|
|
116
118
|
readonly CLM_FETCH: "clm-fetch";
|
|
117
119
|
readonly PROMOTIONS: "promotions";
|
|
118
120
|
readonly COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse";
|
|
121
|
+
readonly AUTHENTICATE: "authenticate";
|
|
122
|
+
readonly OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service";
|
|
119
123
|
};
|
|
120
124
|
export type EndPoints = (typeof end_points)[keyof typeof end_points];
|
|
121
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"];
|
|
@@ -125,6 +129,9 @@ export default class Repzo {
|
|
|
125
129
|
headers: Headers;
|
|
126
130
|
private timeout;
|
|
127
131
|
private retryAttempts;
|
|
132
|
+
private refresh_token?;
|
|
133
|
+
private nameSpace?;
|
|
134
|
+
private reauthCallBackFn?;
|
|
128
135
|
constructor(apiKey: string, options?: Options);
|
|
129
136
|
private static _end_points;
|
|
130
137
|
static get END_POINTS(): {
|
|
@@ -167,6 +174,8 @@ export default class Repzo {
|
|
|
167
174
|
readonly INVOICE: "fullinvoices";
|
|
168
175
|
readonly PROFORMA: "proforma";
|
|
169
176
|
readonly PRINT_SETTINGS: "print-settings";
|
|
177
|
+
readonly PDF_TEMPLATE_GALLERY: "pdf-template-gallery";
|
|
178
|
+
readonly PDF_TEMPLATE: "pdf-template";
|
|
170
179
|
readonly PAYMENT: "payments";
|
|
171
180
|
readonly REFUND: "refund";
|
|
172
181
|
readonly SETTLEMENT: "settlement";
|
|
@@ -244,6 +253,8 @@ export default class Repzo {
|
|
|
244
253
|
readonly CLM_FETCH: "clm-fetch";
|
|
245
254
|
readonly PROMOTIONS: "promotions";
|
|
246
255
|
readonly COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse";
|
|
256
|
+
readonly AUTHENTICATE: "authenticate";
|
|
257
|
+
readonly OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service";
|
|
247
258
|
};
|
|
248
259
|
private _retryRequest;
|
|
249
260
|
private _fetch;
|
|
@@ -252,6 +263,18 @@ export default class Repzo {
|
|
|
252
263
|
private _patch;
|
|
253
264
|
private _delete;
|
|
254
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
|
+
};
|
|
255
278
|
client: {
|
|
256
279
|
_path: "client";
|
|
257
280
|
find: (params?: Service.Client.Find.Params) => Promise<Service.Client.Find.Result>;
|
|
@@ -1139,4 +1162,24 @@ export default class Repzo {
|
|
|
1139
1162
|
create: (body: Service.PrintSetting.Create.Body) => Promise<Service.PrintSetting.Create.Result>;
|
|
1140
1163
|
update: (id: Service.PrintSetting.Update.ID, body: Service.PrintSetting.Update.Body) => Promise<Service.PrintSetting.Update.Result>;
|
|
1141
1164
|
};
|
|
1165
|
+
pdfTemplateGallery: {
|
|
1166
|
+
_path: "pdf-template-gallery";
|
|
1167
|
+
find: (params?: Service.PdfTemplateGallery.Find.Params) => Promise<Service.PdfTemplateGallery.Find.Result>;
|
|
1168
|
+
get: (id: Service.PdfTemplateGallery.Get.ID, params?: Service.PdfTemplateGallery.Get.Params) => Promise<Service.PdfTemplateGallery.Get.Result>;
|
|
1169
|
+
create: (body: Service.PdfTemplateGallery.Create.Body) => Promise<Service.PdfTemplateGallery.Create.Result>;
|
|
1170
|
+
update: (id: Service.PdfTemplateGallery.Update.ID, body: Service.PdfTemplateGallery.Update.Body) => Promise<Service.PdfTemplateGallery.Update.Result>;
|
|
1171
|
+
remove: (id: Service.PdfTemplateGallery.Remove.ID) => Promise<Service.PdfTemplateGallery.Remove.Result>;
|
|
1172
|
+
};
|
|
1173
|
+
pdfTemplate: {
|
|
1174
|
+
_path: "pdf-template";
|
|
1175
|
+
find: (params?: Service.PdfTemplate.Find.Params) => Promise<Service.PdfTemplate.Find.Result>;
|
|
1176
|
+
get: (id: Service.PdfTemplate.Get.ID, params?: Service.PdfTemplate.Get.Params) => Promise<Service.PdfTemplate.Get.Result>;
|
|
1177
|
+
create: (body: Service.PdfTemplate.Create.Body) => Promise<Service.PdfTemplate.Create.Result>;
|
|
1178
|
+
update: (id: Service.PdfTemplate.Update.ID, body: Service.PdfTemplate.Update.Body) => Promise<Service.PdfTemplate.Update.Result>;
|
|
1179
|
+
remove: (id: Service.PdfTemplate.Remove.ID) => Promise<Service.PdfTemplate.Remove.Result>;
|
|
1180
|
+
};
|
|
1181
|
+
optionalBusinessAppService: {
|
|
1182
|
+
_path: "optional-business-app-service";
|
|
1183
|
+
find: () => Promise<Service.OptionalBusinessAppService.Find.Result>;
|
|
1184
|
+
};
|
|
1142
1185
|
}
|
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",
|
|
@@ -40,6 +41,8 @@ export const end_points = {
|
|
|
40
41
|
INVOICE: "fullinvoices",
|
|
41
42
|
PROFORMA: "proforma",
|
|
42
43
|
PRINT_SETTINGS: "print-settings",
|
|
44
|
+
PDF_TEMPLATE_GALLERY: "pdf-template-gallery",
|
|
45
|
+
PDF_TEMPLATE: "pdf-template",
|
|
43
46
|
PAYMENT: "payments",
|
|
44
47
|
REFUND: "refund",
|
|
45
48
|
SETTLEMENT: "settlement",
|
|
@@ -117,6 +120,8 @@ export const end_points = {
|
|
|
117
120
|
CLM_FETCH: "clm-fetch",
|
|
118
121
|
PROMOTIONS: "promotions",
|
|
119
122
|
COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse",
|
|
123
|
+
AUTHENTICATE: "authenticate",
|
|
124
|
+
OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service",
|
|
120
125
|
};
|
|
121
126
|
export const availableService = [
|
|
122
127
|
"client",
|
|
@@ -216,6 +221,43 @@ export const availableService = [
|
|
|
216
221
|
class Repzo {
|
|
217
222
|
constructor(apiKey, options) {
|
|
218
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
|
+
};
|
|
219
261
|
this.client = {
|
|
220
262
|
_path: Repzo._end_points.CLIENT,
|
|
221
263
|
find: async (params) => {
|
|
@@ -2336,6 +2378,57 @@ class Repzo {
|
|
|
2336
2378
|
return res;
|
|
2337
2379
|
},
|
|
2338
2380
|
};
|
|
2381
|
+
this.pdfTemplateGallery = {
|
|
2382
|
+
_path: Repzo._end_points.PDF_TEMPLATE_GALLERY,
|
|
2383
|
+
find: async (params) => {
|
|
2384
|
+
let res = await this._fetch(this.svAPIEndpoint, this.pdfTemplateGallery._path, params);
|
|
2385
|
+
return res;
|
|
2386
|
+
},
|
|
2387
|
+
get: async (id, params) => {
|
|
2388
|
+
return await this._fetch(this.svAPIEndpoint, this.pdfTemplateGallery._path + `/${id}`, params);
|
|
2389
|
+
},
|
|
2390
|
+
create: async (body) => {
|
|
2391
|
+
let res = await this._create(this.svAPIEndpoint, this.pdfTemplateGallery._path, body);
|
|
2392
|
+
return res;
|
|
2393
|
+
},
|
|
2394
|
+
update: async (id, body) => {
|
|
2395
|
+
let res = await this._update(this.svAPIEndpoint, this.pdfTemplateGallery._path + `/${id}`, body);
|
|
2396
|
+
return res;
|
|
2397
|
+
},
|
|
2398
|
+
remove: async (id) => {
|
|
2399
|
+
let res = await this._delete(this.svAPIEndpoint, this.pdfTemplateGallery._path + `/${id}`);
|
|
2400
|
+
return res;
|
|
2401
|
+
},
|
|
2402
|
+
};
|
|
2403
|
+
this.pdfTemplate = {
|
|
2404
|
+
_path: Repzo._end_points.PDF_TEMPLATE,
|
|
2405
|
+
find: async (params) => {
|
|
2406
|
+
let res = await this._fetch(this.svAPIEndpoint, this.pdfTemplate._path, params);
|
|
2407
|
+
return res;
|
|
2408
|
+
},
|
|
2409
|
+
get: async (id, params) => {
|
|
2410
|
+
return await this._fetch(this.svAPIEndpoint, this.pdfTemplate._path + `/${id}`, params);
|
|
2411
|
+
},
|
|
2412
|
+
create: async (body) => {
|
|
2413
|
+
let res = await this._create(this.svAPIEndpoint, this.pdfTemplate._path, body);
|
|
2414
|
+
return res;
|
|
2415
|
+
},
|
|
2416
|
+
update: async (id, body) => {
|
|
2417
|
+
let res = await this._update(this.svAPIEndpoint, this.pdfTemplate._path + `/${id}`, body);
|
|
2418
|
+
return res;
|
|
2419
|
+
},
|
|
2420
|
+
remove: async (id) => {
|
|
2421
|
+
let res = await this._delete(this.svAPIEndpoint, this.pdfTemplate._path + `/${id}`);
|
|
2422
|
+
return res;
|
|
2423
|
+
},
|
|
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
|
+
};
|
|
2339
2432
|
this.svAPIEndpoint =
|
|
2340
2433
|
!options?.env || options?.env == "production"
|
|
2341
2434
|
? "https://sv.api.repzo.me"
|
|
@@ -2349,6 +2442,12 @@ class Repzo {
|
|
|
2349
2442
|
"Content-Type": "application/json",
|
|
2350
2443
|
Accept: "application/json",
|
|
2351
2444
|
};
|
|
2445
|
+
if (options?.nameSpace)
|
|
2446
|
+
this.nameSpace = options.nameSpace;
|
|
2447
|
+
if (options?.refresh_token)
|
|
2448
|
+
this.refresh_token = options.refresh_token;
|
|
2449
|
+
if (options?.reauthCallBackFn)
|
|
2450
|
+
this.reauthCallBackFn = options.reauthCallBackFn;
|
|
2352
2451
|
if (options?.headers)
|
|
2353
2452
|
Object.assign(this.headers, options.headers);
|
|
2354
2453
|
if (options?.timeout) {
|
|
@@ -2368,7 +2467,17 @@ class Repzo {
|
|
|
2368
2467
|
}
|
|
2369
2468
|
catch (error) {
|
|
2370
2469
|
// Don't retry on 401 (Unauthorized) errors
|
|
2371
|
-
if (error?.response?.status === 401
|
|
2470
|
+
if (error?.response?.status === 401 &&
|
|
2471
|
+
this.refresh_token &&
|
|
2472
|
+
this.nameSpace) {
|
|
2473
|
+
try {
|
|
2474
|
+
await this.core.reauth();
|
|
2475
|
+
}
|
|
2476
|
+
catch (e) {
|
|
2477
|
+
throw error;
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
else {
|
|
2372
2481
|
throw error;
|
|
2373
2482
|
}
|
|
2374
2483
|
// 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;
|
|
@@ -240,7 +243,7 @@ export interface CalendarWeeklyGroup {
|
|
|
240
243
|
}
|
|
241
244
|
export type Model = "quickConvertToPdf" | "warehouses" | "transfers" | "transactions" | "taxes" | "productvariations" | "products" | "pricelistsitems" | "pricelists" | "payments" | "ledger_payments" | "mslsales" | "mslproducts" | "measureunits" | "measureunitfamilies" | "invoicesitems" | "invoices" | "ledger_goods" | "fullinvoices" | "checks" | "clients" | "activities" | "bigReports" | "admins";
|
|
242
245
|
export type DocumentTypes = "form" | "quickConvertToPdf" | "clients" | "asset" | "assetUnit" | "workorder" | "clientLocation" | "clientContact" | "commentsThread" | "workorderRequest" | "workorderPortal" | "invoice" | "products" | "productvariations" | "representatives" | "productcategories" | "productSubCategory" | "speciality" | "line" | "banner" | "intgAvailableApps" | "availability_msl" | "reminders" | "audits" | "availability" | "photos" | "planogram" | "tasks" | "checks" | "notificationsCenter" | "admins" | "settings" | "printWorkorderPortalLink" | "bulkExport" | "generateRule" | "scheduleEmail" | "custom-list-item" | "days" | "bulkImport" | "sv.activitiesstorechecks" | "retailExecutionPreset" | "paymentMethod" | "approvalRequest" | "activityFormV2Result" | "formV2" | "payments" | "ocrInvoiceJob" | "contract" | "contractInstallment" | "form" | "paymentMethod" | "aiObjectDetectionModelVersion" | "aiObjectDetectionTask" | "assetPart" | "assetPartReceival" | "assetPartUnit" | "returnAssetPartUnit" | "storeAssetPartUnit" | "activityAiSalesOrder" | "ocrInvoiceJobGroup";
|
|
243
|
-
export type PrintTypes = "workorder" | "form" | "invoice" | "proforma" | "settlement";
|
|
246
|
+
export type PrintTypes = "workorder" | "form" | "invoice" | "proforma" | "settlement" | "formV2";
|
|
244
247
|
export type InvoiceFontStyles = "InvoiceHeaderTitle" | "InvoiceTaxNumber" | "InvoiceType" | "InvoiceInfo" | "ItemsHeader" | "ItemLabel" | "ItemValue" | "ItemVariant" | "TotalItemsQty" | "TotalAmount" | "RepReciver" | "Address" | "PrintTime" | "InvoiceHeader" | "ClientBalance";
|
|
245
248
|
type Granularity = "Year" | "Year Month" | "Year Week" | "Month" | "Year Month Day" | "Year Month Day Time" | "Year Month Day Time Offset";
|
|
246
249
|
export interface MediaDoc {
|
|
@@ -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";
|
|
@@ -17357,6 +17391,190 @@ export declare namespace Service {
|
|
|
17357
17391
|
type Result = Data;
|
|
17358
17392
|
}
|
|
17359
17393
|
}
|
|
17394
|
+
namespace PdfTemplateGallery {
|
|
17395
|
+
export interface Data {
|
|
17396
|
+
_id: string;
|
|
17397
|
+
html_media?: string | MediaDoc;
|
|
17398
|
+
settings?: {
|
|
17399
|
+
[key: string]: any;
|
|
17400
|
+
};
|
|
17401
|
+
cover_photo?: string | MediaDoc;
|
|
17402
|
+
name: string;
|
|
17403
|
+
locale: "en" | "ar";
|
|
17404
|
+
ai_prompt?: string;
|
|
17405
|
+
document_type: PrintTypes;
|
|
17406
|
+
disabled: boolean;
|
|
17407
|
+
createdAt: string;
|
|
17408
|
+
updatedAt: string;
|
|
17409
|
+
}
|
|
17410
|
+
export interface CreateBody {
|
|
17411
|
+
html_media?: string;
|
|
17412
|
+
settings?: {
|
|
17413
|
+
[key: string]: any;
|
|
17414
|
+
};
|
|
17415
|
+
cover_photo?: string;
|
|
17416
|
+
name: string;
|
|
17417
|
+
locale: "en" | "ar";
|
|
17418
|
+
ai_prompt?: string;
|
|
17419
|
+
document_type: PrintTypes;
|
|
17420
|
+
disabled?: boolean;
|
|
17421
|
+
}
|
|
17422
|
+
export interface UpdateBody {
|
|
17423
|
+
html_media?: string;
|
|
17424
|
+
settings?: {
|
|
17425
|
+
[key: string]: any;
|
|
17426
|
+
};
|
|
17427
|
+
cover_photo?: string;
|
|
17428
|
+
name?: string;
|
|
17429
|
+
locale?: "en" | "ar";
|
|
17430
|
+
ai_prompt?: string;
|
|
17431
|
+
document_type?: PrintTypes;
|
|
17432
|
+
}
|
|
17433
|
+
export type PopulatedDoc = Data & {
|
|
17434
|
+
html_media_populated?: MediaDoc;
|
|
17435
|
+
cover_photo_populated?: MediaDoc;
|
|
17436
|
+
};
|
|
17437
|
+
type PopulatedKeys = "html_media" | "cover_photo";
|
|
17438
|
+
export namespace Find {
|
|
17439
|
+
type Params = DefaultPaginationQueryParams & {
|
|
17440
|
+
_id?: string | string[];
|
|
17441
|
+
name?: string;
|
|
17442
|
+
locale?: "en" | "ar";
|
|
17443
|
+
document_type?: PrintTypes;
|
|
17444
|
+
disabled?: boolean;
|
|
17445
|
+
};
|
|
17446
|
+
interface Result extends DefaultPaginationResult {
|
|
17447
|
+
data: PopulatedDoc[];
|
|
17448
|
+
}
|
|
17449
|
+
}
|
|
17450
|
+
export namespace Get {
|
|
17451
|
+
type ID = string;
|
|
17452
|
+
type Params = {
|
|
17453
|
+
populatedKeys?: PopulatedKeys[];
|
|
17454
|
+
};
|
|
17455
|
+
type Result = PopulatedDoc;
|
|
17456
|
+
}
|
|
17457
|
+
export namespace Create {
|
|
17458
|
+
type Body = CreateBody;
|
|
17459
|
+
type Result = Data;
|
|
17460
|
+
}
|
|
17461
|
+
export namespace Update {
|
|
17462
|
+
type ID = string;
|
|
17463
|
+
type Body = UpdateBody;
|
|
17464
|
+
type Result = Data;
|
|
17465
|
+
}
|
|
17466
|
+
export namespace Remove {
|
|
17467
|
+
type ID = string;
|
|
17468
|
+
type Result = Data;
|
|
17469
|
+
}
|
|
17470
|
+
export {};
|
|
17471
|
+
}
|
|
17472
|
+
namespace PdfTemplate {
|
|
17473
|
+
export interface Data {
|
|
17474
|
+
_id: string;
|
|
17475
|
+
html_media?: string | MediaDoc;
|
|
17476
|
+
settings?: {
|
|
17477
|
+
[key: string]: any;
|
|
17478
|
+
};
|
|
17479
|
+
cover_photo?: string | MediaDoc;
|
|
17480
|
+
name: string;
|
|
17481
|
+
is_default: boolean;
|
|
17482
|
+
creator: AdminCreator;
|
|
17483
|
+
editor?: AdminCreator;
|
|
17484
|
+
locale: "en" | "ar";
|
|
17485
|
+
pdf_template_gallery?: string;
|
|
17486
|
+
publish_time?: number | null;
|
|
17487
|
+
document_type: PrintTypes;
|
|
17488
|
+
disabled: boolean;
|
|
17489
|
+
company_namespace: string[];
|
|
17490
|
+
createdAt: string;
|
|
17491
|
+
updatedAt: string;
|
|
17492
|
+
}
|
|
17493
|
+
export interface CreateBody {
|
|
17494
|
+
html_media?: string;
|
|
17495
|
+
settings?: {
|
|
17496
|
+
[key: string]: any;
|
|
17497
|
+
};
|
|
17498
|
+
cover_photo?: string;
|
|
17499
|
+
name: string;
|
|
17500
|
+
is_default?: boolean;
|
|
17501
|
+
locale: "en" | "ar";
|
|
17502
|
+
pdf_template_gallery?: string;
|
|
17503
|
+
publish_time?: number | null;
|
|
17504
|
+
document_type: PrintTypes;
|
|
17505
|
+
}
|
|
17506
|
+
export interface UpdateBody {
|
|
17507
|
+
html_media?: string;
|
|
17508
|
+
settings?: {
|
|
17509
|
+
[key: string]: any;
|
|
17510
|
+
};
|
|
17511
|
+
cover_photo?: string;
|
|
17512
|
+
name?: string;
|
|
17513
|
+
is_default?: boolean;
|
|
17514
|
+
locale?: "en" | "ar";
|
|
17515
|
+
pdf_template_gallery?: string;
|
|
17516
|
+
publish_time?: number | null;
|
|
17517
|
+
document_type?: PrintTypes;
|
|
17518
|
+
}
|
|
17519
|
+
export type PopulatedDoc = Data & {
|
|
17520
|
+
html_media_populated?: MediaDoc;
|
|
17521
|
+
cover_photo_populated?: MediaDoc;
|
|
17522
|
+
pdf_template_gallery_populated?: PdfTemplateGallery.Data;
|
|
17523
|
+
};
|
|
17524
|
+
type PopulatedKeys = "html_media" | "cover_photo" | "pdf_template_gallery";
|
|
17525
|
+
export namespace Find {
|
|
17526
|
+
type Params = DefaultPaginationQueryParams & {
|
|
17527
|
+
name?: string | string[];
|
|
17528
|
+
locale?: "en" | "ar" | ("en" | "ar")[];
|
|
17529
|
+
document_type?: PrintTypes | PrintTypes[];
|
|
17530
|
+
is_default?: boolean;
|
|
17531
|
+
pdf_template_gallery?: string | string[];
|
|
17532
|
+
publish_time?: number | (number | null)[];
|
|
17533
|
+
disabled?: boolean;
|
|
17534
|
+
_id?: string | string[];
|
|
17535
|
+
"creator._id"?: string | string[];
|
|
17536
|
+
"editor._id"?: string | string[];
|
|
17537
|
+
};
|
|
17538
|
+
interface Result extends DefaultPaginationResult {
|
|
17539
|
+
data: PopulatedDoc[];
|
|
17540
|
+
}
|
|
17541
|
+
}
|
|
17542
|
+
export namespace Get {
|
|
17543
|
+
type ID = string;
|
|
17544
|
+
type Params = {
|
|
17545
|
+
populatedKeys?: PopulatedKeys[];
|
|
17546
|
+
};
|
|
17547
|
+
type Result = PopulatedDoc;
|
|
17548
|
+
}
|
|
17549
|
+
export namespace Create {
|
|
17550
|
+
type Body = CreateBody;
|
|
17551
|
+
type Result = Data;
|
|
17552
|
+
}
|
|
17553
|
+
export namespace Update {
|
|
17554
|
+
type ID = string;
|
|
17555
|
+
type Body = UpdateBody;
|
|
17556
|
+
type Result = Data;
|
|
17557
|
+
}
|
|
17558
|
+
export namespace Remove {
|
|
17559
|
+
type ID = string;
|
|
17560
|
+
type Result = Data;
|
|
17561
|
+
}
|
|
17562
|
+
export {};
|
|
17563
|
+
}
|
|
17564
|
+
namespace OptionalBusinessAppService {
|
|
17565
|
+
type SERVICE_NAMES = "transfer" | "warehouse" | "fullinvoices" | "client" | "product" | "rep" | "tag" | "asset-part-unit" | "asset-part-receival" | "asset-part-transfer" | "return-asset-part-unit" | "store-asset-part-unit" | "clm-presentation";
|
|
17566
|
+
export namespace Find {
|
|
17567
|
+
interface Result {
|
|
17568
|
+
code: string;
|
|
17569
|
+
services: {
|
|
17570
|
+
permission: StringId;
|
|
17571
|
+
name: SERVICE_NAMES;
|
|
17572
|
+
default_teams_shared: "shared" | "unshared";
|
|
17573
|
+
}[];
|
|
17574
|
+
}
|
|
17575
|
+
}
|
|
17576
|
+
export {};
|
|
17577
|
+
}
|
|
17360
17578
|
}
|
|
17361
17579
|
export type StringId = string;
|
|
17362
17580
|
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.233",
|
|
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",
|
|
@@ -50,6 +51,8 @@ export const end_points = {
|
|
|
50
51
|
INVOICE: "fullinvoices",
|
|
51
52
|
PROFORMA: "proforma",
|
|
52
53
|
PRINT_SETTINGS: "print-settings",
|
|
54
|
+
PDF_TEMPLATE_GALLERY: "pdf-template-gallery",
|
|
55
|
+
PDF_TEMPLATE: "pdf-template",
|
|
53
56
|
PAYMENT: "payments",
|
|
54
57
|
REFUND: "refund",
|
|
55
58
|
SETTLEMENT: "settlement",
|
|
@@ -127,6 +130,8 @@ export const end_points = {
|
|
|
127
130
|
CLM_FETCH: "clm-fetch",
|
|
128
131
|
PROMOTIONS: "promotions",
|
|
129
132
|
COMPARE_INVOICE_TO_WAREHOUSE: "compare-invoice-to-warehouse",
|
|
133
|
+
AUTHENTICATE: "authenticate",
|
|
134
|
+
OPTIONAL_BUSINESS_APP_SERVICE: "optional-business-app-service",
|
|
130
135
|
} as const;
|
|
131
136
|
export type EndPoints = (typeof end_points)[keyof typeof end_points];
|
|
132
137
|
|
|
@@ -232,6 +237,9 @@ export default class Repzo {
|
|
|
232
237
|
headers: Headers;
|
|
233
238
|
private timeout: number;
|
|
234
239
|
private retryAttempts: number;
|
|
240
|
+
private refresh_token?: string;
|
|
241
|
+
private nameSpace?: string;
|
|
242
|
+
private reauthCallBackFn?: (res: Service.Reauth.Result) => void;
|
|
235
243
|
constructor(apiKey: string, options?: Options) {
|
|
236
244
|
this.svAPIEndpoint =
|
|
237
245
|
!options?.env || options?.env == "production"
|
|
@@ -247,6 +255,10 @@ export default class Repzo {
|
|
|
247
255
|
"Content-Type": "application/json",
|
|
248
256
|
Accept: "application/json",
|
|
249
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;
|
|
250
262
|
if (options?.headers) Object.assign(this.headers, options.headers);
|
|
251
263
|
if (options?.timeout) {
|
|
252
264
|
this.timeout = options.timeout;
|
|
@@ -269,7 +281,17 @@ export default class Repzo {
|
|
|
269
281
|
return await requestFn();
|
|
270
282
|
} catch (error: any) {
|
|
271
283
|
// Don't retry on 401 (Unauthorized) errors
|
|
272
|
-
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 {
|
|
273
295
|
throw error;
|
|
274
296
|
}
|
|
275
297
|
|
|
@@ -361,6 +383,59 @@ export default class Repzo {
|
|
|
361
383
|
|
|
362
384
|
available_services = availableService;
|
|
363
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
|
+
|
|
364
439
|
client = {
|
|
365
440
|
_path: Repzo._end_points.CLIENT,
|
|
366
441
|
find: async (
|
|
@@ -5944,6 +6019,136 @@ export default class Repzo {
|
|
|
5944
6019
|
return res;
|
|
5945
6020
|
},
|
|
5946
6021
|
};
|
|
6022
|
+
|
|
6023
|
+
pdfTemplateGallery = {
|
|
6024
|
+
_path: Repzo._end_points.PDF_TEMPLATE_GALLERY,
|
|
6025
|
+
|
|
6026
|
+
find: async (
|
|
6027
|
+
params?: Service.PdfTemplateGallery.Find.Params,
|
|
6028
|
+
): Promise<Service.PdfTemplateGallery.Find.Result> => {
|
|
6029
|
+
let res: Service.PdfTemplateGallery.Find.Result = await this._fetch(
|
|
6030
|
+
this.svAPIEndpoint,
|
|
6031
|
+
this.pdfTemplateGallery._path,
|
|
6032
|
+
params,
|
|
6033
|
+
);
|
|
6034
|
+
return res;
|
|
6035
|
+
},
|
|
6036
|
+
|
|
6037
|
+
get: async (
|
|
6038
|
+
id: Service.PdfTemplateGallery.Get.ID,
|
|
6039
|
+
params?: Service.PdfTemplateGallery.Get.Params,
|
|
6040
|
+
): Promise<Service.PdfTemplateGallery.Get.Result> => {
|
|
6041
|
+
return await this._fetch(
|
|
6042
|
+
this.svAPIEndpoint,
|
|
6043
|
+
this.pdfTemplateGallery._path + `/${id}`,
|
|
6044
|
+
params,
|
|
6045
|
+
);
|
|
6046
|
+
},
|
|
6047
|
+
|
|
6048
|
+
create: async (
|
|
6049
|
+
body: Service.PdfTemplateGallery.Create.Body,
|
|
6050
|
+
): Promise<Service.PdfTemplateGallery.Create.Result> => {
|
|
6051
|
+
let res = await this._create(
|
|
6052
|
+
this.svAPIEndpoint,
|
|
6053
|
+
this.pdfTemplateGallery._path,
|
|
6054
|
+
body,
|
|
6055
|
+
);
|
|
6056
|
+
return res;
|
|
6057
|
+
},
|
|
6058
|
+
|
|
6059
|
+
update: async (
|
|
6060
|
+
id: Service.PdfTemplateGallery.Update.ID,
|
|
6061
|
+
body: Service.PdfTemplateGallery.Update.Body,
|
|
6062
|
+
): Promise<Service.PdfTemplateGallery.Update.Result> => {
|
|
6063
|
+
let res: Service.PdfTemplateGallery.Update.Result = await this._update(
|
|
6064
|
+
this.svAPIEndpoint,
|
|
6065
|
+
this.pdfTemplateGallery._path + `/${id}`,
|
|
6066
|
+
body,
|
|
6067
|
+
);
|
|
6068
|
+
return res;
|
|
6069
|
+
},
|
|
6070
|
+
|
|
6071
|
+
remove: async (
|
|
6072
|
+
id: Service.PdfTemplateGallery.Remove.ID,
|
|
6073
|
+
): Promise<Service.PdfTemplateGallery.Remove.Result> => {
|
|
6074
|
+
let res: Service.PdfTemplateGallery.Remove.Result = await this._delete(
|
|
6075
|
+
this.svAPIEndpoint,
|
|
6076
|
+
this.pdfTemplateGallery._path + `/${id}`,
|
|
6077
|
+
);
|
|
6078
|
+
return res;
|
|
6079
|
+
},
|
|
6080
|
+
};
|
|
6081
|
+
|
|
6082
|
+
pdfTemplate = {
|
|
6083
|
+
_path: Repzo._end_points.PDF_TEMPLATE,
|
|
6084
|
+
|
|
6085
|
+
find: async (
|
|
6086
|
+
params?: Service.PdfTemplate.Find.Params,
|
|
6087
|
+
): Promise<Service.PdfTemplate.Find.Result> => {
|
|
6088
|
+
let res: Service.PdfTemplate.Find.Result = await this._fetch(
|
|
6089
|
+
this.svAPIEndpoint,
|
|
6090
|
+
this.pdfTemplate._path,
|
|
6091
|
+
params,
|
|
6092
|
+
);
|
|
6093
|
+
return res;
|
|
6094
|
+
},
|
|
6095
|
+
|
|
6096
|
+
get: async (
|
|
6097
|
+
id: Service.PdfTemplate.Get.ID,
|
|
6098
|
+
params?: Service.PdfTemplate.Get.Params,
|
|
6099
|
+
): Promise<Service.PdfTemplate.Get.Result> => {
|
|
6100
|
+
return await this._fetch(
|
|
6101
|
+
this.svAPIEndpoint,
|
|
6102
|
+
this.pdfTemplate._path + `/${id}`,
|
|
6103
|
+
params,
|
|
6104
|
+
);
|
|
6105
|
+
},
|
|
6106
|
+
|
|
6107
|
+
create: async (
|
|
6108
|
+
body: Service.PdfTemplate.Create.Body,
|
|
6109
|
+
): Promise<Service.PdfTemplate.Create.Result> => {
|
|
6110
|
+
let res = await this._create(
|
|
6111
|
+
this.svAPIEndpoint,
|
|
6112
|
+
this.pdfTemplate._path,
|
|
6113
|
+
body,
|
|
6114
|
+
);
|
|
6115
|
+
return res;
|
|
6116
|
+
},
|
|
6117
|
+
|
|
6118
|
+
update: async (
|
|
6119
|
+
id: Service.PdfTemplate.Update.ID,
|
|
6120
|
+
body: Service.PdfTemplate.Update.Body,
|
|
6121
|
+
): Promise<Service.PdfTemplate.Update.Result> => {
|
|
6122
|
+
let res: Service.PdfTemplate.Update.Result = await this._update(
|
|
6123
|
+
this.svAPIEndpoint,
|
|
6124
|
+
this.pdfTemplate._path + `/${id}`,
|
|
6125
|
+
body,
|
|
6126
|
+
);
|
|
6127
|
+
return res;
|
|
6128
|
+
},
|
|
6129
|
+
|
|
6130
|
+
remove: async (
|
|
6131
|
+
id: Service.PdfTemplate.Remove.ID,
|
|
6132
|
+
): Promise<Service.PdfTemplate.Remove.Result> => {
|
|
6133
|
+
let res: Service.PdfTemplate.Remove.Result = await this._delete(
|
|
6134
|
+
this.svAPIEndpoint,
|
|
6135
|
+
this.pdfTemplate._path + `/${id}`,
|
|
6136
|
+
);
|
|
6137
|
+
return res;
|
|
6138
|
+
},
|
|
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
|
+
};
|
|
5947
6152
|
}
|
|
5948
6153
|
|
|
5949
6154
|
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;
|
|
@@ -382,7 +385,8 @@ export type PrintTypes =
|
|
|
382
385
|
| "form"
|
|
383
386
|
| "invoice"
|
|
384
387
|
| "proforma"
|
|
385
|
-
| "settlement"
|
|
388
|
+
| "settlement"
|
|
389
|
+
| "formV2";
|
|
386
390
|
|
|
387
391
|
export type InvoiceFontStyles =
|
|
388
392
|
| "InvoiceHeaderTitle"
|
|
@@ -462,7 +466,6 @@ interface GeoPoint {
|
|
|
462
466
|
coordinates: [number, number];
|
|
463
467
|
}
|
|
464
468
|
|
|
465
|
-
// <reference path = "vehicle.ts" />
|
|
466
469
|
export namespace Service {
|
|
467
470
|
export namespace Client {
|
|
468
471
|
interface Financials {
|
|
@@ -2848,6 +2851,9 @@ export namespace Service {
|
|
|
2848
2851
|
rep_must_end_day_after_specific_time: boolean;
|
|
2849
2852
|
rep_can_upload_media_on_payment?: boolean;
|
|
2850
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;
|
|
2851
2857
|
}
|
|
2852
2858
|
interface TargetResults {
|
|
2853
2859
|
totalPoints: number;
|
|
@@ -3128,6 +3134,9 @@ export namespace Service {
|
|
|
3128
3134
|
"permissions.rep_can_create_negative_invoices"?: boolean;
|
|
3129
3135
|
"permissions.rep_can_upload_media_on_payment"?: boolean;
|
|
3130
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;
|
|
3131
3140
|
"settings.rep_must_end_day_after"?: `${number}:${number}`;
|
|
3132
3141
|
"settings.allowable_accuracy"?: number;
|
|
3133
3142
|
"settings.is_item_status_per_visit_limited"?: boolean;
|
|
@@ -19057,6 +19066,32 @@ export namespace Service {
|
|
|
19057
19066
|
}
|
|
19058
19067
|
}
|
|
19059
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
|
+
|
|
19060
19095
|
export namespace PrintSetting {
|
|
19061
19096
|
export type ImageSize = "original" | "small" | "medium" | "large" | "extra";
|
|
19062
19097
|
export type QrCodeSize = "small" | "medium" | "large";
|
|
@@ -19415,6 +19450,205 @@ export namespace Service {
|
|
|
19415
19450
|
export type Result = Data;
|
|
19416
19451
|
}
|
|
19417
19452
|
}
|
|
19453
|
+
|
|
19454
|
+
export namespace PdfTemplateGallery {
|
|
19455
|
+
export interface Data {
|
|
19456
|
+
_id: string;
|
|
19457
|
+
html_media?: string | MediaDoc;
|
|
19458
|
+
settings?: { [key: string]: any };
|
|
19459
|
+
cover_photo?: string | MediaDoc;
|
|
19460
|
+
name: string;
|
|
19461
|
+
locale: "en" | "ar";
|
|
19462
|
+
ai_prompt?: string;
|
|
19463
|
+
document_type: PrintTypes;
|
|
19464
|
+
disabled: boolean;
|
|
19465
|
+
createdAt: string;
|
|
19466
|
+
updatedAt: string;
|
|
19467
|
+
}
|
|
19468
|
+
|
|
19469
|
+
export interface CreateBody {
|
|
19470
|
+
html_media?: string;
|
|
19471
|
+
settings?: { [key: string]: any };
|
|
19472
|
+
cover_photo?: string;
|
|
19473
|
+
name: string;
|
|
19474
|
+
locale: "en" | "ar";
|
|
19475
|
+
ai_prompt?: string;
|
|
19476
|
+
document_type: PrintTypes;
|
|
19477
|
+
disabled?: boolean;
|
|
19478
|
+
}
|
|
19479
|
+
|
|
19480
|
+
export interface UpdateBody {
|
|
19481
|
+
html_media?: string;
|
|
19482
|
+
settings?: { [key: string]: any };
|
|
19483
|
+
cover_photo?: string;
|
|
19484
|
+
name?: string;
|
|
19485
|
+
locale?: "en" | "ar";
|
|
19486
|
+
ai_prompt?: string;
|
|
19487
|
+
document_type?: PrintTypes;
|
|
19488
|
+
}
|
|
19489
|
+
|
|
19490
|
+
export type PopulatedDoc = Data & {
|
|
19491
|
+
html_media_populated?: MediaDoc;
|
|
19492
|
+
cover_photo_populated?: MediaDoc;
|
|
19493
|
+
};
|
|
19494
|
+
|
|
19495
|
+
type PopulatedKeys = "html_media" | "cover_photo";
|
|
19496
|
+
|
|
19497
|
+
export namespace Find {
|
|
19498
|
+
export type Params = DefaultPaginationQueryParams & {
|
|
19499
|
+
_id?: string | string[];
|
|
19500
|
+
name?: string;
|
|
19501
|
+
locale?: "en" | "ar";
|
|
19502
|
+
document_type?: PrintTypes;
|
|
19503
|
+
disabled?: boolean;
|
|
19504
|
+
};
|
|
19505
|
+
export interface Result extends DefaultPaginationResult {
|
|
19506
|
+
data: PopulatedDoc[];
|
|
19507
|
+
}
|
|
19508
|
+
}
|
|
19509
|
+
|
|
19510
|
+
export namespace Get {
|
|
19511
|
+
export type ID = string;
|
|
19512
|
+
export type Params = { populatedKeys?: PopulatedKeys[] };
|
|
19513
|
+
export type Result = PopulatedDoc;
|
|
19514
|
+
}
|
|
19515
|
+
|
|
19516
|
+
export namespace Create {
|
|
19517
|
+
export type Body = CreateBody;
|
|
19518
|
+
export type Result = Data;
|
|
19519
|
+
}
|
|
19520
|
+
|
|
19521
|
+
export namespace Update {
|
|
19522
|
+
export type ID = string;
|
|
19523
|
+
export type Body = UpdateBody;
|
|
19524
|
+
export type Result = Data;
|
|
19525
|
+
}
|
|
19526
|
+
|
|
19527
|
+
export namespace Remove {
|
|
19528
|
+
export type ID = string;
|
|
19529
|
+
export type Result = Data;
|
|
19530
|
+
}
|
|
19531
|
+
}
|
|
19532
|
+
|
|
19533
|
+
export namespace PdfTemplate {
|
|
19534
|
+
export interface Data {
|
|
19535
|
+
_id: string;
|
|
19536
|
+
html_media?: string | MediaDoc;
|
|
19537
|
+
settings?: { [key: string]: any };
|
|
19538
|
+
cover_photo?: string | MediaDoc;
|
|
19539
|
+
name: string;
|
|
19540
|
+
is_default: boolean;
|
|
19541
|
+
creator: AdminCreator;
|
|
19542
|
+
editor?: AdminCreator;
|
|
19543
|
+
locale: "en" | "ar";
|
|
19544
|
+
pdf_template_gallery?: string;
|
|
19545
|
+
publish_time?: number | null;
|
|
19546
|
+
document_type: PrintTypes;
|
|
19547
|
+
disabled: boolean;
|
|
19548
|
+
company_namespace: string[];
|
|
19549
|
+
createdAt: string;
|
|
19550
|
+
updatedAt: string;
|
|
19551
|
+
}
|
|
19552
|
+
|
|
19553
|
+
export interface CreateBody {
|
|
19554
|
+
html_media?: string;
|
|
19555
|
+
settings?: { [key: string]: any };
|
|
19556
|
+
cover_photo?: string;
|
|
19557
|
+
name: string;
|
|
19558
|
+
is_default?: boolean;
|
|
19559
|
+
locale: "en" | "ar";
|
|
19560
|
+
pdf_template_gallery?: string;
|
|
19561
|
+
publish_time?: number | null;
|
|
19562
|
+
document_type: PrintTypes;
|
|
19563
|
+
}
|
|
19564
|
+
|
|
19565
|
+
export interface UpdateBody {
|
|
19566
|
+
html_media?: string;
|
|
19567
|
+
settings?: { [key: string]: any };
|
|
19568
|
+
cover_photo?: string;
|
|
19569
|
+
name?: string;
|
|
19570
|
+
is_default?: boolean;
|
|
19571
|
+
locale?: "en" | "ar";
|
|
19572
|
+
pdf_template_gallery?: string;
|
|
19573
|
+
publish_time?: number | null;
|
|
19574
|
+
document_type?: PrintTypes;
|
|
19575
|
+
}
|
|
19576
|
+
|
|
19577
|
+
export type PopulatedDoc = Data & {
|
|
19578
|
+
html_media_populated?: MediaDoc;
|
|
19579
|
+
cover_photo_populated?: MediaDoc;
|
|
19580
|
+
pdf_template_gallery_populated?: PdfTemplateGallery.Data;
|
|
19581
|
+
};
|
|
19582
|
+
|
|
19583
|
+
type PopulatedKeys = "html_media" | "cover_photo" | "pdf_template_gallery";
|
|
19584
|
+
|
|
19585
|
+
export namespace Find {
|
|
19586
|
+
export type Params = DefaultPaginationQueryParams & {
|
|
19587
|
+
name?: string | string[];
|
|
19588
|
+
locale?: "en" | "ar" | ("en" | "ar")[];
|
|
19589
|
+
document_type?: PrintTypes | PrintTypes[];
|
|
19590
|
+
is_default?: boolean;
|
|
19591
|
+
pdf_template_gallery?: string | string[];
|
|
19592
|
+
publish_time?: number | (number | null)[];
|
|
19593
|
+
disabled?: boolean;
|
|
19594
|
+
_id?: string | string[];
|
|
19595
|
+
"creator._id"?: string | string[];
|
|
19596
|
+
"editor._id"?: string | string[];
|
|
19597
|
+
};
|
|
19598
|
+
export interface Result extends DefaultPaginationResult {
|
|
19599
|
+
data: PopulatedDoc[];
|
|
19600
|
+
}
|
|
19601
|
+
}
|
|
19602
|
+
|
|
19603
|
+
export namespace Get {
|
|
19604
|
+
export type ID = string;
|
|
19605
|
+
export type Params = { populatedKeys?: PopulatedKeys[] };
|
|
19606
|
+
export type Result = PopulatedDoc;
|
|
19607
|
+
}
|
|
19608
|
+
|
|
19609
|
+
export namespace Create {
|
|
19610
|
+
export type Body = CreateBody;
|
|
19611
|
+
export type Result = Data;
|
|
19612
|
+
}
|
|
19613
|
+
|
|
19614
|
+
export namespace Update {
|
|
19615
|
+
export type ID = string;
|
|
19616
|
+
export type Body = UpdateBody;
|
|
19617
|
+
export type Result = Data;
|
|
19618
|
+
}
|
|
19619
|
+
|
|
19620
|
+
export namespace Remove {
|
|
19621
|
+
export type ID = string;
|
|
19622
|
+
export type Result = Data;
|
|
19623
|
+
}
|
|
19624
|
+
}
|
|
19625
|
+
|
|
19626
|
+
export namespace OptionalBusinessAppService {
|
|
19627
|
+
type SERVICE_NAMES =
|
|
19628
|
+
| "transfer"
|
|
19629
|
+
| "warehouse"
|
|
19630
|
+
| "fullinvoices"
|
|
19631
|
+
| "client"
|
|
19632
|
+
| "product"
|
|
19633
|
+
| "rep"
|
|
19634
|
+
| "tag"
|
|
19635
|
+
| "asset-part-unit"
|
|
19636
|
+
| "asset-part-receival"
|
|
19637
|
+
| "asset-part-transfer"
|
|
19638
|
+
| "return-asset-part-unit"
|
|
19639
|
+
| "store-asset-part-unit"
|
|
19640
|
+
| "clm-presentation";
|
|
19641
|
+
export namespace Find {
|
|
19642
|
+
export interface Result {
|
|
19643
|
+
code: string;
|
|
19644
|
+
services: {
|
|
19645
|
+
permission: StringId;
|
|
19646
|
+
name: SERVICE_NAMES;
|
|
19647
|
+
default_teams_shared: "shared" | "unshared";
|
|
19648
|
+
}[];
|
|
19649
|
+
}
|
|
19650
|
+
}
|
|
19651
|
+
}
|
|
19418
19652
|
}
|
|
19419
19653
|
|
|
19420
19654
|
export type StringId = string;
|