@longvansoftware/storefront-js-client 0.0.3 → 1.0.1
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/dist/config/config.d.ts +18 -0
- package/dist/config/config.js +21 -0
- package/dist/{constants/graphql/mutations/crmMutations.d.ts → src/graphql/crm/mutations.d.ts} +0 -2
- package/dist/{constants/graphql/mutations/crmMutations.js → src/graphql/crm/mutations.js} +1 -111
- package/dist/src/graphql/crm/queries.d.ts +3 -0
- package/dist/src/graphql/crm/queries.js +155 -0
- package/dist/src/graphql/payment/mutations.d.ts +1 -0
- package/dist/src/graphql/payment/mutations.js +35 -0
- package/dist/src/graphql/payment/queries.d.ts +1 -0
- package/dist/src/graphql/payment/queries.js +12 -0
- package/dist/src/graphql/product/mutations.d.ts +0 -0
- package/dist/src/graphql/product/mutations.js +1 -0
- package/dist/{constants/graphql/queries/productQueries.d.ts → src/graphql/product/queries.d.ts} +2 -1
- package/dist/src/graphql/product/queries.js +415 -0
- package/dist/{constants/graphql/mutations/userMutations.d.ts → src/graphql/user/mutations.d.ts} +0 -1
- package/dist/{constants/graphql/mutations/userMutations.js → src/graphql/user/mutations.js} +4 -33
- package/dist/src/graphql/user/queries.d.ts +3 -0
- package/dist/src/graphql/user/queries.js +67 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/lib/SDK.d.ts +28 -0
- package/dist/src/lib/SDK.js +43 -0
- package/dist/src/lib/auth/index.d.ts +26 -0
- package/dist/src/lib/auth/index.js +54 -0
- package/dist/src/lib/crm/index.d.ts +14 -0
- package/dist/src/lib/crm/index.js +185 -0
- package/dist/src/lib/order/index.d.ts +87 -0
- package/dist/src/lib/order/index.js +209 -0
- package/dist/src/lib/payment/index.d.ts +6 -0
- package/dist/src/lib/payment/index.js +50 -0
- package/dist/src/lib/product/index.d.ts +36 -0
- package/dist/src/lib/product/index.js +116 -0
- package/dist/src/lib/service.d.ts +14 -0
- package/dist/src/lib/service.js +97 -0
- package/dist/src/lib/user/index.d.ts +11 -0
- package/dist/src/lib/user/index.js +135 -0
- package/dist/{constants/interfaces → src/types}/crm.d.ts +1 -0
- package/dist/src/types/order.d.ts +7 -0
- package/dist/src/types/user.js +2 -0
- package/dist/src/utils/helpers.d.ts +4 -0
- package/dist/src/utils/helpers.js +41 -0
- package/package.json +25 -19
- package/dist/constants/graphql/queries/crmQueries.d.ts +0 -1
- package/dist/constants/graphql/queries/crmQueries.js +0 -45
- package/dist/constants/graphql/queries/productQueries.js +0 -368
- package/dist/index.d.ts +0 -19
- package/dist/index.js +0 -17
- package/dist/modules/authorization/graphql.d.ts +0 -15
- package/dist/modules/authorization/graphql.js +0 -116
- package/dist/modules/crm/graphql.d.ts +0 -19
- package/dist/modules/crm/graphql.js +0 -291
- package/dist/modules/product/graphql.d.ts +0 -19
- package/dist/modules/product/graphql.js +0 -180
- package/dist/modules/user/graphql.d.ts +0 -14
- package/dist/modules/user/graphql.js +0 -156
- /package/dist/{constants/graphql/mutations/authorizationMutations.d.ts → src/graphql/auth/mutations.d.ts} +0 -0
- /package/dist/{constants/graphql/mutations/authorizationMutations.js → src/graphql/auth/mutations.js} +0 -0
- /package/dist/{constants/interfaces/authorization.d.ts → src/types/auth.d.ts} +0 -0
- /package/dist/{constants/interfaces/authorization.js → src/types/auth.js} +0 -0
- /package/dist/{constants/interfaces → src/types}/crm.js +0 -0
- /package/dist/{constants/interfaces/product.js → src/types/order.js} +0 -0
- /package/dist/{constants/interfaces → src/types}/product.d.ts +0 -0
- /package/dist/{constants/interfaces/user.js → src/types/product.js} +0 -0
- /package/dist/{constants/interfaces → src/types}/user.d.ts +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
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.ProductService = void 0;
|
|
13
|
+
const service_1 = require("../service");
|
|
14
|
+
const queries_1 = require("../../graphql/product/queries");
|
|
15
|
+
/**
|
|
16
|
+
* Service class for managing product-related operations.
|
|
17
|
+
*/
|
|
18
|
+
class ProductService extends service_1.Service {
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new ProductService instance.
|
|
21
|
+
* @param endpoint - The endpoint URL for the service.
|
|
22
|
+
* @param orgId - The organization ID.
|
|
23
|
+
* @param storeId - The store ID.
|
|
24
|
+
*/
|
|
25
|
+
constructor(endpoint, orgId, storeId) {
|
|
26
|
+
super(endpoint, orgId, storeId);
|
|
27
|
+
}
|
|
28
|
+
// ...
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves a product by its ID.
|
|
31
|
+
* @param productId - The ID of the product.
|
|
32
|
+
* @returns A promise that resolves to the product.
|
|
33
|
+
* @throws If an error occurs while fetching the product.
|
|
34
|
+
*/
|
|
35
|
+
getProductById(productId) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const query = queries_1.GET_PRODUCT_BY_ID_QUERY;
|
|
38
|
+
const variables = {
|
|
39
|
+
partnerId: this.orgId,
|
|
40
|
+
storeChannel: this.storeId,
|
|
41
|
+
productId,
|
|
42
|
+
};
|
|
43
|
+
try {
|
|
44
|
+
const response = yield this.graphqlQuery(query, variables);
|
|
45
|
+
return response.getProductById;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.log(`Error fetching product by ID: ${error}`);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves a product by its slug.
|
|
55
|
+
* @param slug - The slug of the product.
|
|
56
|
+
* @returns A promise that resolves to the product.
|
|
57
|
+
* @throws If an error occurs while fetching the product.
|
|
58
|
+
*/
|
|
59
|
+
getProductBySlug(slug) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const query = queries_1.GET_PRODUCT_BY_SLUG_QUERY;
|
|
62
|
+
const variables = {
|
|
63
|
+
partnerId: this.orgId,
|
|
64
|
+
storeChannel: this.storeId,
|
|
65
|
+
handle: slug,
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
const response = yield this.graphqlQuery(query, variables);
|
|
69
|
+
return response.getProductByHandle;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.log(`Error fetching product by slug: ${error}`);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves simple products based on the provided variables.
|
|
79
|
+
* @param variables - The variables for the query.
|
|
80
|
+
* @returns A promise that resolves to the simple products.
|
|
81
|
+
* @throws If an error occurs while fetching the simple products.
|
|
82
|
+
*/
|
|
83
|
+
getSimpleProducts(variables) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const query = queries_1.GET_SIMPLE_PRODUCTS_QUERY;
|
|
86
|
+
const variablesHandle = Object.assign({ partnerId: this.orgId, storeChannel: this.storeId }, variables);
|
|
87
|
+
try {
|
|
88
|
+
const response = yield this.graphqlQuery(query, variablesHandle);
|
|
89
|
+
return response.getSimpleProducts;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.log(`Error fetching simple products: ${error}`);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getProductOption(productId) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const query = queries_1.GET_PRODUCT_OPTION;
|
|
100
|
+
const variablesHandle = {
|
|
101
|
+
partnerId: this.orgId,
|
|
102
|
+
storeChannel: this.storeId,
|
|
103
|
+
productId,
|
|
104
|
+
};
|
|
105
|
+
try {
|
|
106
|
+
const response = yield this.graphqlQuery(query, variablesHandle);
|
|
107
|
+
return response.getProductOption;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.log(`Error fetching simple products: ${error}`);
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.ProductService = ProductService;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
graphqlQuery(query, variables) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
const { data, errors } = yield this.client.query({
|
|
42
|
+
query: (0, client_1.gql) `
|
|
43
|
+
${query}
|
|
44
|
+
`,
|
|
45
|
+
variables,
|
|
46
|
+
});
|
|
47
|
+
if (errors) {
|
|
48
|
+
throw new Error(`GraphQL error! errors: ${errors}`);
|
|
49
|
+
}
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.log(`Error in graphqlQuery: ${error}`);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
graphqlMutation(mutation, variables) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
try {
|
|
61
|
+
const { data, errors } = yield this.client.mutate({
|
|
62
|
+
mutation: (0, client_1.gql) `
|
|
63
|
+
${mutation}
|
|
64
|
+
`,
|
|
65
|
+
variables,
|
|
66
|
+
});
|
|
67
|
+
if (errors) {
|
|
68
|
+
throw new Error(`GraphQL error! errors: ${errors}`);
|
|
69
|
+
}
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.log(`Error in graphqlMutation: ${error}`);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
restApiCallWithToken(path, method, data, headers) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
try {
|
|
81
|
+
const modifiedHeaders = Object.assign(Object.assign({}, headers), { "Partner-Id": this.orgId, "X-Ecomos-Access-Token": this.token });
|
|
82
|
+
const response = yield (0, axios_1.default)({
|
|
83
|
+
url: this.endpoint + path,
|
|
84
|
+
method,
|
|
85
|
+
data,
|
|
86
|
+
headers: modifiedHeaders,
|
|
87
|
+
});
|
|
88
|
+
return response.data;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.log(`Error in restApiCallWithToken: ${error}`);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.Service = Service;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Service } from '../service';
|
|
2
|
+
import { createCompanyRequest, updateCustomerRequest } from '../../types/user';
|
|
3
|
+
export declare class UserService extends Service {
|
|
4
|
+
constructor(endpoint: string, orgId: string, storeId: string);
|
|
5
|
+
getPersonByPartyIds(partyIds: string[]): Promise<any>;
|
|
6
|
+
createCompany(payload: createCompanyRequest, createdBy: string): Promise<any>;
|
|
7
|
+
updateCompanyInfo(id: string, fieldName: string, valueUpdate: string, updatedBy: string): Promise<any>;
|
|
8
|
+
updateCustomerV2(id: string, customerItem: updateCustomerRequest, updatedBy: string): Promise<any>;
|
|
9
|
+
getCustomerById(id: string): Promise<any>;
|
|
10
|
+
searchCompany(keyword: string): Promise<any>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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.UserService = void 0;
|
|
13
|
+
const service_1 = require("../service");
|
|
14
|
+
const queries_1 = require("../../graphql/user/queries");
|
|
15
|
+
const mutations_1 = require("../../graphql/user/mutations");
|
|
16
|
+
class UserService extends service_1.Service {
|
|
17
|
+
constructor(endpoint, orgId, storeId) {
|
|
18
|
+
super(endpoint, orgId, storeId);
|
|
19
|
+
}
|
|
20
|
+
getPersonByPartyIds(partyIds) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const query = queries_1.GET_PERSON_BY_IDS_QUERY;
|
|
23
|
+
const variables = { partyIds };
|
|
24
|
+
try {
|
|
25
|
+
const response = yield this.graphqlQuery(query, variables);
|
|
26
|
+
return response.getPersonByPartyIds;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.log(`Error in getPersonByPartyIds: ${error}`);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
createCompany(payload, createdBy) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const mutation = mutations_1.CREATE_COMPANY;
|
|
37
|
+
const variables = {
|
|
38
|
+
orgId: this.orgId,
|
|
39
|
+
createCompanyRequest: {
|
|
40
|
+
name: payload === null || payload === void 0 ? void 0 : payload.name,
|
|
41
|
+
phone: payload === null || payload === void 0 ? void 0 : payload.phone,
|
|
42
|
+
address: payload === null || payload === void 0 ? void 0 : payload.address,
|
|
43
|
+
},
|
|
44
|
+
createTaxCodeRequest: null,
|
|
45
|
+
createdBy,
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
const response = yield this.graphqlMutation(mutation, variables);
|
|
49
|
+
return response.createCompany;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.log(`Error in createCompany: ${error}`);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
updateCompanyInfo(id, fieldName, valueUpdate, updatedBy) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const mutation = mutations_1.UPDATE_COMPANY_INFOR;
|
|
60
|
+
const variables = {
|
|
61
|
+
orgId: this.orgId,
|
|
62
|
+
id,
|
|
63
|
+
fieldName,
|
|
64
|
+
valueUpdate,
|
|
65
|
+
updatedBy,
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
const response = yield this.graphqlMutation(mutation, variables);
|
|
69
|
+
return response.updateCompanyInfo;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.log(`Error in updateCompanyInfo: ${error}`);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
updateCustomerV2(id, customerItem, updatedBy) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const mutation = mutations_1.UPDATE_CUSTOMER_V2;
|
|
80
|
+
const variables = {
|
|
81
|
+
tenantId: this.orgId,
|
|
82
|
+
id,
|
|
83
|
+
updateCustomerRequest: {
|
|
84
|
+
name: customerItem === null || customerItem === void 0 ? void 0 : customerItem.fullName,
|
|
85
|
+
phone: customerItem === null || customerItem === void 0 ? void 0 : customerItem.phone,
|
|
86
|
+
address: customerItem === null || customerItem === void 0 ? void 0 : customerItem.address
|
|
87
|
+
},
|
|
88
|
+
updatedBy,
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
const response = yield this.graphqlMutation(mutation, variables);
|
|
92
|
+
return response.updateCustomerV2;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.log(`Error in updateCustomerV2: ${error}`);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getCustomerById(id) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const query = queries_1.GET_CUSTOMER_BY_ID;
|
|
103
|
+
const variables = {
|
|
104
|
+
id
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
const response = yield this.graphqlQuery(query, variables);
|
|
108
|
+
return response.getCustomerById;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.log(`Error in getCustomerById: ${error}`);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
searchCompany(keyword) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const query = queries_1.SEARCH_COMPANY;
|
|
119
|
+
const variables = {
|
|
120
|
+
keyword,
|
|
121
|
+
orgId: this.orgId,
|
|
122
|
+
limit: 1,
|
|
123
|
+
};
|
|
124
|
+
try {
|
|
125
|
+
const response = yield this.graphqlQuery(query, variables);
|
|
126
|
+
return response.searchCompany;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.log(`Error in searchCompany: ${error}`);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.UserService = UserService;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Endpoints } from "../lib/SDK";
|
|
2
|
+
export declare function createToken(environment: string): string;
|
|
3
|
+
export declare function decodeToken(token: string): string | null;
|
|
4
|
+
export declare function validateStorefrontAccessToken(storefrontAccessToken: string): Endpoints;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateStorefrontAccessToken = exports.decodeToken = exports.createToken = void 0;
|
|
7
|
+
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
8
|
+
const config_1 = require("../../config/config");
|
|
9
|
+
function createToken(environment) {
|
|
10
|
+
const cipherText = crypto_js_1.default.AES.encrypt(environment, "lvs").toString();
|
|
11
|
+
console.log("🚀 ~ createToken ~ cipherText:", cipherText);
|
|
12
|
+
return cipherText;
|
|
13
|
+
}
|
|
14
|
+
exports.createToken = createToken;
|
|
15
|
+
function decodeToken(token) {
|
|
16
|
+
try {
|
|
17
|
+
const bytes = crypto_js_1.default.AES.decrypt(token, "lvs");
|
|
18
|
+
const decryptedData = bytes.toString(crypto_js_1.default.enc.Utf8);
|
|
19
|
+
return decryptedData;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.log("Invalid token");
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.decodeToken = decodeToken;
|
|
27
|
+
function validateStorefrontAccessToken(storefrontAccessToken) {
|
|
28
|
+
const environment = decodeToken(storefrontAccessToken) || ""; // Handle null case by providing a default value
|
|
29
|
+
console.log("🚀 ~ environment:", environment);
|
|
30
|
+
const validEnvironments = {
|
|
31
|
+
dev: "dev",
|
|
32
|
+
live: "live",
|
|
33
|
+
};
|
|
34
|
+
if (!Object.keys(validEnvironments).includes(environment)) {
|
|
35
|
+
throw new Error("Invalid storefrontAccessToken");
|
|
36
|
+
}
|
|
37
|
+
return environment == "dev"
|
|
38
|
+
? config_1.environmentEndpoints.dev
|
|
39
|
+
: config_1.environmentEndpoints.live;
|
|
40
|
+
}
|
|
41
|
+
exports.validateStorefrontAccessToken = validateStorefrontAccessToken;
|
package/package.json
CHANGED
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longvansoftware/storefront-js-client",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "dist/src/index.js",
|
|
5
|
+
"types": "dist/src/index.d.ts",
|
|
7
6
|
"files": [
|
|
8
|
-
"dist"
|
|
7
|
+
"dist/**/*.d.ts",
|
|
8
|
+
"dist/**/*.js"
|
|
9
9
|
],
|
|
10
|
+
"directories": {
|
|
11
|
+
"test": "jest"
|
|
12
|
+
},
|
|
10
13
|
"scripts": {
|
|
11
|
-
"dev": "nodemon .",
|
|
12
|
-
"build": "tsc",
|
|
13
14
|
"test": "jest",
|
|
15
|
+
"build": "tsc",
|
|
14
16
|
"publish": "npm run build && npm publish"
|
|
15
17
|
},
|
|
18
|
+
"keywords": [],
|
|
16
19
|
"author": "",
|
|
17
20
|
"license": "ISC",
|
|
18
|
-
"
|
|
19
|
-
"@
|
|
20
|
-
"
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@apollo/client": "3.9.11",
|
|
23
|
+
"apollo-boost": "^0.4.9",
|
|
21
24
|
"axios": "^1.6.8",
|
|
25
|
+
"crypto-js": "^4.2.0",
|
|
26
|
+
"graphql": "^15.8.0",
|
|
22
27
|
"graphql-request": "^6.1.0",
|
|
23
28
|
"graphql-tag": "^2.12.6",
|
|
29
|
+
"react": "^18.2.0",
|
|
30
|
+
"ts-node": "^10.9.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/axios": "^0.14.0",
|
|
34
|
+
"@types/crypto-js": "^4.2.2",
|
|
35
|
+
"@types/jest": "^29.5.12",
|
|
36
|
+
"@types/node": "^20.12.7",
|
|
24
37
|
"jest": "^29.7.0",
|
|
25
|
-
"nodemon": "^2.0.15",
|
|
26
38
|
"ts-jest": "^29.1.2",
|
|
27
|
-
"
|
|
28
|
-
"typescript": "^5.4.3",
|
|
29
|
-
"webpack-loader": "^0.0.1"
|
|
39
|
+
"typescript": "^5.4.5"
|
|
30
40
|
},
|
|
31
|
-
"
|
|
32
|
-
"graphql": "^16.8.1",
|
|
33
|
-
"graphql-request": "^6.1.0",
|
|
34
|
-
"graphql-tag": "^2.12.6"
|
|
35
|
-
}
|
|
41
|
+
"description": ""
|
|
36
42
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const GET_LIST_OPPORTUNITY_QUERY: import("graphql").DocumentNode;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GET_LIST_OPPORTUNITY_QUERY = void 0;
|
|
4
|
-
const graphql_tag_1 = require("graphql-tag");
|
|
5
|
-
exports.GET_LIST_OPPORTUNITY_QUERY = (0, graphql_tag_1.gql) `
|
|
6
|
-
query GetListOpportunity($partyId: String!, $performerId: String!, $getOpportunityRequest: GetOpportunityRequest!) {
|
|
7
|
-
getListOpportunity(
|
|
8
|
-
partyId: $partyId
|
|
9
|
-
performerId: $performerId
|
|
10
|
-
getOpportunityRequest: $getOpportunityRequest
|
|
11
|
-
) {
|
|
12
|
-
total
|
|
13
|
-
data {
|
|
14
|
-
goal
|
|
15
|
-
campaignId
|
|
16
|
-
valueReal
|
|
17
|
-
valueExpect
|
|
18
|
-
successRate
|
|
19
|
-
referName
|
|
20
|
-
referPhone
|
|
21
|
-
referEmail
|
|
22
|
-
id
|
|
23
|
-
createdBy
|
|
24
|
-
ownerId
|
|
25
|
-
workEffortTypeId
|
|
26
|
-
partyId
|
|
27
|
-
name
|
|
28
|
-
description
|
|
29
|
-
parentId
|
|
30
|
-
status
|
|
31
|
-
stmId
|
|
32
|
-
createdStamp
|
|
33
|
-
updatedStamp
|
|
34
|
-
endDateExpect
|
|
35
|
-
priorityName
|
|
36
|
-
targetId
|
|
37
|
-
targetType
|
|
38
|
-
targetUrl
|
|
39
|
-
extSource
|
|
40
|
-
connectorId
|
|
41
|
-
processResult
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
`;
|