@longvansoftware/service-js-client 1.16.2 → 1.16.4

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.
Files changed (79) hide show
  1. package/dist/src/graphql/campaign/mutations.d.ts +1 -0
  2. package/dist/src/graphql/campaign/mutations.js +34 -0
  3. package/dist/src/graphql/campaign/queries.d.ts +9 -0
  4. package/dist/src/graphql/campaign/queries.js +427 -0
  5. package/dist/src/graphql/cashbook/queries.d.ts +2 -0
  6. package/dist/src/graphql/cashbook/queries.js +99 -0
  7. package/dist/src/graphql/crm/mutations.d.ts +2 -0
  8. package/dist/src/graphql/crm/mutations.js +37 -1
  9. package/dist/src/graphql/crm/queries.d.ts +1 -0
  10. package/dist/src/graphql/crm/queries.js +35 -1
  11. package/dist/src/graphql/fragments/product.d.ts +38 -0
  12. package/dist/src/graphql/fragments/product.js +196 -0
  13. package/dist/src/graphql/paymentV2/mutations.d.ts +5 -0
  14. package/dist/src/graphql/paymentV2/mutations.js +120 -0
  15. package/dist/src/graphql/paymentV2/queries.d.ts +9 -0
  16. package/dist/src/graphql/paymentV2/queries.js +257 -0
  17. package/dist/src/graphql/product/queries.d.ts +1 -0
  18. package/dist/src/graphql/product/queries.js +14 -1
  19. package/dist/src/graphql/store/mutations.d.ts +1 -0
  20. package/dist/src/graphql/store/mutations.js +29 -0
  21. package/dist/src/graphql/store/queries.d.ts +1 -0
  22. package/dist/src/graphql/store/queries.js +29 -0
  23. package/dist/src/lib/accounting/index.d.ts +5 -0
  24. package/dist/src/lib/accounting/index.js +32 -0
  25. package/dist/src/lib/campaign/index.d.ts +20 -0
  26. package/dist/src/lib/campaign/index.js +218 -0
  27. package/dist/src/lib/cashbook/index.d.ts +6 -0
  28. package/dist/src/lib/cashbook/index.js +56 -0
  29. package/dist/src/lib/comhub/index.d.ts +6 -0
  30. package/dist/src/lib/comhub/index.js +50 -0
  31. package/dist/src/lib/crm/index.d.ts +3 -0
  32. package/dist/src/lib/crm/index.js +51 -0
  33. package/dist/src/lib/deepLinkVietQr/index.d.ts +7 -0
  34. package/dist/src/lib/deepLinkVietQr/index.js +58 -0
  35. package/dist/src/lib/fileService/index.d.ts +34 -0
  36. package/dist/src/lib/fileService/index.js +80 -0
  37. package/dist/src/lib/getImage/index.d.ts +4 -0
  38. package/dist/src/lib/getImage/index.js +10 -0
  39. package/dist/src/lib/image/index.d.ts +7 -0
  40. package/dist/src/lib/image/index.js +49 -0
  41. package/dist/src/lib/omnigateway/index.d.ts +7 -0
  42. package/dist/src/lib/omnigateway/index.js +58 -0
  43. package/dist/src/lib/paymentV2/index.d.ts +18 -0
  44. package/dist/src/lib/paymentV2/index.js +245 -0
  45. package/dist/src/lib/portal/index.d.ts +23 -0
  46. package/dist/src/lib/portal/index.js +255 -0
  47. package/dist/src/lib/product/index.d.ts +1 -0
  48. package/dist/src/lib/product/index.js +16 -0
  49. package/dist/src/lib/shareZalo/index.d.ts +5 -0
  50. package/dist/src/lib/shareZalo/index.js +32 -0
  51. package/dist/src/lib/store/index.d.ts +30 -0
  52. package/dist/src/lib/store/index.js +74 -0
  53. package/dist/src/lib/token/index.d.ts +5 -0
  54. package/dist/src/lib/token/index.js +32 -0
  55. package/dist/src/lib/upload/index.d.ts +5 -0
  56. package/dist/src/lib/upload/index.js +35 -0
  57. package/dist/src/lib/warehouseV2/index.d.ts +13 -0
  58. package/dist/src/lib/warehouseV2/index.js +54 -0
  59. package/dist/src/lib/zca/index.d.ts +12 -0
  60. package/dist/src/lib/zca/index.js +41 -0
  61. package/dist/src/types/campaign.d.ts +14 -0
  62. package/dist/src/types/campaign.js +2 -0
  63. package/dist/src/types/common.d.ts +264 -0
  64. package/dist/src/types/common.js +35 -0
  65. package/dist/src/types/invoice.d.ts +13 -0
  66. package/dist/src/types/invoice.js +2 -0
  67. package/dist/src/types/portal.d.ts +7 -0
  68. package/dist/src/types/portal.js +2 -0
  69. package/dist/src/types/store.d.ts +158 -0
  70. package/dist/src/types/store.js +3 -0
  71. package/dist/src/utils/errorHandler.d.ts +64 -0
  72. package/dist/src/utils/errorHandler.js +197 -0
  73. package/dist/src/utils/validatePhoneNumber.d.ts +1 -0
  74. package/dist/src/utils/validatePhoneNumber.js +20 -0
  75. package/package.json +1 -1
  76. package/dist/src/lib/service.d.ts +0 -14
  77. package/dist/src/lib/service.js +0 -101
  78. package/dist/src/utils/build-field-string.d.ts +0 -1
  79. package/dist/src/utils/build-field-string.js +0 -16
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RetryManager = exports.ErrorHandler = exports.EnhancedSDKError = exports.ErrorSeverity = exports.ErrorType = void 0;
13
+ const serviceSDK_1 = require("../lib/serviceSDK");
14
+ /**
15
+ * Error types for better categorization
16
+ */
17
+ var ErrorType;
18
+ (function (ErrorType) {
19
+ ErrorType["GRAPHQL_ERROR"] = "GRAPHQL_ERROR";
20
+ ErrorType["NETWORK_ERROR"] = "NETWORK_ERROR";
21
+ ErrorType["REST_API_ERROR"] = "REST_API_ERROR";
22
+ ErrorType["VALIDATION_ERROR"] = "VALIDATION_ERROR";
23
+ ErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
24
+ ErrorType["AUTHORIZATION_ERROR"] = "AUTHORIZATION_ERROR";
25
+ ErrorType["NOT_FOUND_ERROR"] = "NOT_FOUND_ERROR";
26
+ ErrorType["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
27
+ })(ErrorType || (exports.ErrorType = ErrorType = {}));
28
+ /**
29
+ * Error severity levels
30
+ */
31
+ var ErrorSeverity;
32
+ (function (ErrorSeverity) {
33
+ ErrorSeverity["LOW"] = "LOW";
34
+ ErrorSeverity["MEDIUM"] = "MEDIUM";
35
+ ErrorSeverity["HIGH"] = "HIGH";
36
+ ErrorSeverity["CRITICAL"] = "CRITICAL";
37
+ })(ErrorSeverity || (exports.ErrorSeverity = ErrorSeverity = {}));
38
+ /**
39
+ * Enhanced SDK Error with additional metadata
40
+ */
41
+ class EnhancedSDKError extends serviceSDK_1.SDKError {
42
+ constructor(message, type, originalError, severity = ErrorSeverity.MEDIUM, context, retryable = false) {
43
+ super(message, type, originalError);
44
+ this.severity = severity;
45
+ this.timestamp = new Date();
46
+ this.context = context;
47
+ this.retryable = retryable;
48
+ }
49
+ }
50
+ exports.EnhancedSDKError = EnhancedSDKError;
51
+ /**
52
+ * Error handler utility class
53
+ */
54
+ class ErrorHandler {
55
+ /**
56
+ * Create a standardized error from various error sources
57
+ */
58
+ static createError(error, context) {
59
+ var _a;
60
+ // Handle GraphQL errors
61
+ if (error.graphQLErrors && error.graphQLErrors.length > 0) {
62
+ const message = error.graphQLErrors.map((err) => err.message).join(', ');
63
+ return new EnhancedSDKError(message, ErrorType.GRAPHQL_ERROR, error, this.determineSeverity(error), context, this.isRetryable(error));
64
+ }
65
+ // Handle network errors
66
+ if (error.networkError) {
67
+ return new EnhancedSDKError(`Network Error: ${error.networkError.message}`, ErrorType.NETWORK_ERROR, error, ErrorSeverity.HIGH, context, true // Network errors are usually retryable
68
+ );
69
+ }
70
+ // Handle Axios errors (REST API)
71
+ if (error.response) {
72
+ const status = error.response.status;
73
+ let errorType = ErrorType.REST_API_ERROR;
74
+ let severity = ErrorSeverity.MEDIUM;
75
+ let retryable = false;
76
+ // Categorize by HTTP status code
77
+ if (status === 401) {
78
+ errorType = ErrorType.AUTHENTICATION_ERROR;
79
+ severity = ErrorSeverity.HIGH;
80
+ }
81
+ else if (status === 403) {
82
+ errorType = ErrorType.AUTHORIZATION_ERROR;
83
+ severity = ErrorSeverity.HIGH;
84
+ }
85
+ else if (status === 404) {
86
+ errorType = ErrorType.NOT_FOUND_ERROR;
87
+ severity = ErrorSeverity.LOW;
88
+ }
89
+ else if (status >= 500) {
90
+ severity = ErrorSeverity.HIGH;
91
+ retryable = true;
92
+ }
93
+ else if (status === 429) {
94
+ retryable = true;
95
+ }
96
+ return new EnhancedSDKError(`API Error (${status}): ${((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.message) || error.message}`, errorType, error, severity, Object.assign(Object.assign({}, context), { statusCode: status }), retryable);
97
+ }
98
+ // Handle validation errors
99
+ if (error.name === 'ValidationError') {
100
+ return new EnhancedSDKError(error.message, ErrorType.VALIDATION_ERROR, error, ErrorSeverity.LOW, context, false);
101
+ }
102
+ // Default unknown error
103
+ return new EnhancedSDKError(error.message || 'An unknown error occurred', ErrorType.UNKNOWN_ERROR, error, ErrorSeverity.MEDIUM, context, false);
104
+ }
105
+ /**
106
+ * Determine error severity based on error characteristics
107
+ */
108
+ static determineSeverity(error) {
109
+ var _a;
110
+ if (error.networkError)
111
+ return ErrorSeverity.HIGH;
112
+ if ((_a = error.graphQLErrors) === null || _a === void 0 ? void 0 : _a.some((e) => { var _a; return ((_a = e.extensions) === null || _a === void 0 ? void 0 : _a.code) === 'INTERNAL_ERROR'; })) {
113
+ return ErrorSeverity.CRITICAL;
114
+ }
115
+ return ErrorSeverity.MEDIUM;
116
+ }
117
+ /**
118
+ * Determine if an error is retryable
119
+ */
120
+ static isRetryable(error) {
121
+ var _a;
122
+ // Network errors are usually retryable
123
+ if (error.networkError)
124
+ return true;
125
+ // Some GraphQL errors are retryable
126
+ if ((_a = error.graphQLErrors) === null || _a === void 0 ? void 0 : _a.some((e) => {
127
+ var _a, _b;
128
+ return ((_a = e.extensions) === null || _a === void 0 ? void 0 : _a.code) === 'TIMEOUT' ||
129
+ ((_b = e.extensions) === null || _b === void 0 ? void 0 : _b.code) === 'RATE_LIMITED';
130
+ })) {
131
+ return true;
132
+ }
133
+ return false;
134
+ }
135
+ /**
136
+ * Log error with appropriate level
137
+ */
138
+ static logError(error, operation) {
139
+ const logData = {
140
+ operation,
141
+ type: error.type,
142
+ severity: error.severity,
143
+ message: error.message,
144
+ timestamp: error.timestamp,
145
+ context: error.context,
146
+ retryable: error.retryable
147
+ };
148
+ switch (error.severity) {
149
+ case ErrorSeverity.CRITICAL:
150
+ console.error('🚨 CRITICAL ERROR:', logData);
151
+ break;
152
+ case ErrorSeverity.HIGH:
153
+ console.error('❌ HIGH SEVERITY ERROR:', logData);
154
+ break;
155
+ case ErrorSeverity.MEDIUM:
156
+ console.warn('⚠️ MEDIUM SEVERITY ERROR:', logData);
157
+ break;
158
+ case ErrorSeverity.LOW:
159
+ console.info('ℹ️ LOW SEVERITY ERROR:', logData);
160
+ break;
161
+ }
162
+ }
163
+ /**
164
+ * Check if error should trigger retry logic
165
+ */
166
+ static shouldRetry(error, attemptCount, maxRetries = 3) {
167
+ return error.retryable && attemptCount < maxRetries;
168
+ }
169
+ }
170
+ exports.ErrorHandler = ErrorHandler;
171
+ /**
172
+ * Retry utility with exponential backoff
173
+ */
174
+ class RetryManager {
175
+ static withExponentialBackoff(operation_1) {
176
+ return __awaiter(this, arguments, void 0, function* (operation, maxRetries = 3, baseDelay = 1000) {
177
+ let lastError;
178
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
179
+ try {
180
+ return yield operation();
181
+ }
182
+ catch (error) {
183
+ lastError = error;
184
+ const enhancedError = ErrorHandler.createError(error);
185
+ if (attempt === maxRetries || !ErrorHandler.shouldRetry(enhancedError, attempt, maxRetries)) {
186
+ throw enhancedError;
187
+ }
188
+ // Exponential backoff with jitter
189
+ const delay = baseDelay * Math.pow(2, attempt) + Math.random() * 1000;
190
+ yield new Promise(resolve => setTimeout(resolve, delay));
191
+ }
192
+ }
193
+ throw ErrorHandler.createError(lastError);
194
+ });
195
+ }
196
+ }
197
+ exports.RetryManager = RetryManager;
@@ -0,0 +1 @@
1
+ export declare function validatePhoneNumber(phoneNumber: string): boolean;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validatePhoneNumber = void 0;
4
+ function validatePhoneNumber(phoneNumber) {
5
+ var _a;
6
+ const urlParams = new URLSearchParams(window.location.search);
7
+ const country = ((_a = urlParams.get("country")) === null || _a === void 0 ? void 0 : _a.trim()) || "default";
8
+ const pattern = (() => {
9
+ switch (country) {
10
+ case "vietnam":
11
+ return /^(0?)(3[2-9]|5[6|8|9]|7[0|6-9]|8[0-6|8|9]|9[0-4|6-9])[0-9]{7}$/;
12
+ case "quocte":
13
+ return /^(\+|00)[1-9][0-9]{1,3}[0-9]{4,14}$/;
14
+ default:
15
+ return /^(0?)(3[2-9]|5[6|8|9]|7[0|6-9]|8[0-6|8|9]|9[0-4|6-9])[0-9]{7}$|^(\+|00)[1-9][0-9]{1,3}[0-9]{4,14}$/;
16
+ }
17
+ })();
18
+ return pattern.test(phoneNumber);
19
+ }
20
+ exports.validatePhoneNumber = validatePhoneNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/service-js-client",
3
- "version": "1.16.2",
3
+ "version": "1.16.4",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [
@@ -1,14 +0,0 @@
1
- import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
2
- import { DocumentNode } from "graphql";
3
- export declare class Service {
4
- protected token: string | null;
5
- protected client: ApolloClient<NormalizedCacheObject>;
6
- protected orgId: string;
7
- protected storeId: string;
8
- protected endpoint: string;
9
- constructor(endpoint: string, orgId: string, storeId: string);
10
- setToken(token: string): void;
11
- protected graphqlQuery(query: DocumentNode, variables: any): Promise<any>;
12
- protected graphqlMutation(mutation: DocumentNode, variables: any): Promise<any>;
13
- protected restApiCallWithToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
14
- }
@@ -1,101 +0,0 @@
1
- "use strict";
2
- // src/service.ts
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Service = void 0;
17
- const client_1 = require("@apollo/client");
18
- const axios_1 = __importDefault(require("axios"));
19
- class Service {
20
- constructor(endpoint, orgId, storeId) {
21
- this.token = null;
22
- this.client = new client_1.ApolloClient({
23
- uri: endpoint,
24
- cache: new client_1.InMemoryCache(),
25
- defaultOptions: {
26
- query: {
27
- fetchPolicy: "network-only",
28
- },
29
- },
30
- });
31
- this.orgId = orgId;
32
- this.storeId = storeId;
33
- this.endpoint = endpoint;
34
- }
35
- setToken(token) {
36
- this.token = token;
37
- }
38
- // setOrgId(orgId: string) {
39
- // this.orgId = orgId;
40
- // }
41
- graphqlQuery(query, variables) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- try {
44
- const { data, errors } = yield this.client.query({
45
- query: (0, client_1.gql) `
46
- ${query}
47
- `,
48
- variables,
49
- });
50
- if (errors) {
51
- throw new Error(`GraphQL error! errors: ${errors}`);
52
- }
53
- return data;
54
- }
55
- catch (error) {
56
- console.log(`Error in graphqlQuery: ${error}`);
57
- throw error;
58
- }
59
- });
60
- }
61
- graphqlMutation(mutation, variables) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- try {
64
- const { data, errors } = yield this.client.mutate({
65
- mutation: (0, client_1.gql) `
66
- ${mutation}
67
- `,
68
- variables,
69
- });
70
- if (errors) {
71
- throw new Error(`GraphQL error! errors: ${errors}`);
72
- }
73
- return data;
74
- }
75
- catch (error) {
76
- console.log(`Error in graphqlMutation: ${error}`);
77
- throw error;
78
- }
79
- });
80
- }
81
- restApiCallWithToken(path, method, data, headers) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- try {
84
- const modifiedHeaders = Object.assign(Object.assign({}, headers), { "Partner-Id": this.orgId, "X-Ecomos-Access-Token": this.token });
85
- console.log("🚀 ~ Service ~ modifiedHeaders:", modifiedHeaders);
86
- const response = yield (0, axios_1.default)({
87
- url: this.endpoint + path,
88
- method,
89
- data,
90
- headers: modifiedHeaders,
91
- });
92
- return response.data;
93
- }
94
- catch (error) {
95
- console.log(`Error in restApiCallWithToken: ${error}`);
96
- throw error;
97
- }
98
- });
99
- }
100
- }
101
- exports.Service = Service;
@@ -1 +0,0 @@
1
- export declare function buildFieldString(fields: (string | Record<string, any>)[], indent?: number): string;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildFieldString = void 0;
4
- function buildFieldString(fields, indent = 6) {
5
- const space = " ".repeat(indent);
6
- return fields
7
- .map((field) => {
8
- if (typeof field === "string")
9
- return `${space}${field}`;
10
- const [key, value] = Object.entries(field)[0];
11
- const nested = buildFieldString(value, indent + 2);
12
- return `${space}${key} {\n${nested}\n${space}}`;
13
- })
14
- .join("\n");
15
- }
16
- exports.buildFieldString = buildFieldString;