@longvansoftware/service-js-client 2.8.4 → 2.8.6
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 +4 -0
- package/dist/config/config.js +6 -2
- package/dist/src/graphql/dynamic_collection/mutations.d.ts +0 -0
- package/dist/src/graphql/dynamic_collection/mutations.js +1 -0
- package/dist/src/graphql/dynamic_collection/queries.d.ts +0 -0
- package/dist/src/graphql/dynamic_collection/queries.js +1 -0
- package/dist/src/graphql/storefront/mutation.d.ts +2 -0
- package/dist/src/graphql/storefront/mutation.js +28 -0
- package/dist/src/lib/SDK.d.ts +6 -0
- package/dist/src/lib/SDK.js +9 -4
- package/dist/src/lib/dynamic_collection/index.d.ts +13 -0
- package/dist/src/lib/dynamic_collection/index.js +45 -0
- package/dist/src/lib/storefront/index.d.ts +7 -0
- package/dist/src/lib/storefront/index.js +44 -0
- package/dist/src/utils/helpers.d.ts +2 -0
- package/dist/src/utils/helpers.js +11 -5
- package/package.json +1 -1
package/dist/config/config.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare const environmentEndpoints: {
|
|
|
23
23
|
storage_s3: string;
|
|
24
24
|
content_api: string;
|
|
25
25
|
marketplace: string;
|
|
26
|
+
storefront: string;
|
|
27
|
+
dynamic_collection: string;
|
|
26
28
|
};
|
|
27
29
|
live: {
|
|
28
30
|
product: string;
|
|
@@ -48,5 +50,7 @@ export declare const environmentEndpoints: {
|
|
|
48
50
|
storage_s3: string;
|
|
49
51
|
content_api: string;
|
|
50
52
|
marketplace: string;
|
|
53
|
+
storefront: string;
|
|
54
|
+
dynamic_collection: string;
|
|
51
55
|
};
|
|
52
56
|
};
|
package/dist/config/config.js
CHANGED
|
@@ -26,7 +26,9 @@ exports.environmentEndpoints = {
|
|
|
26
26
|
// storage_s3: "https://portal.dev.longvan.vn/storage-s3-api/graphql",
|
|
27
27
|
storage_s3: "https://api-gateway.longvan.dev/storage-s3-api/graphql",
|
|
28
28
|
content_api: "https://api-gateway.longvan.dev/content-api/graphql",
|
|
29
|
-
marketplace: "https://api-gateway.longvan.dev/marketplace/graphql"
|
|
29
|
+
marketplace: "https://api-gateway.longvan.dev/marketplace/graphql",
|
|
30
|
+
storefront: "https://api-gateway.longvan.dev/storefront-service/graphql",
|
|
31
|
+
dynamic_collection: "https://api-gateway.longvan.dev/dynamic-collection"
|
|
30
32
|
},
|
|
31
33
|
live: {
|
|
32
34
|
product: "https://product-service.longvan.vn/product-service/graphql",
|
|
@@ -52,6 +54,8 @@ exports.environmentEndpoints = {
|
|
|
52
54
|
// storage_s3: "https://portal.longvan.vn/storage-s3-api/graphql",
|
|
53
55
|
storage_s3: "https://storage-s3-api.longvan.vn/storage-s3-api/graphql",
|
|
54
56
|
content_api: "https://portal.longvan.vn/content-api/graphql",
|
|
55
|
-
marketplace: "https://api-gateway.longvan.vn/marketplace/graphql"
|
|
57
|
+
marketplace: "https://api-gateway.longvan.vn/marketplace/graphql",
|
|
58
|
+
storefront: "https://api-gateway.longvan.vn/storefront-service/graphql",
|
|
59
|
+
dynamic_collection: "https://portal.longvan.vn/dynamic-collection"
|
|
56
60
|
}
|
|
57
61
|
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,28 @@
|
|
|
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.MERGE_ORDER_CART = void 0;
|
|
7
|
+
const helpers_1 = require("../../utils/helpers");
|
|
8
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
9
|
+
const MERGE_ORDER_CART = (fields = []) => {
|
|
10
|
+
return (0, graphql_tag_1.default) `
|
|
11
|
+
mutation MergeOrderCart(
|
|
12
|
+
$oldCartId: String!
|
|
13
|
+
$newCartId: String!
|
|
14
|
+
$actorId: String!
|
|
15
|
+
$isAllowedToMergeItem: Boolean!
|
|
16
|
+
) {
|
|
17
|
+
mergeOrderCart(
|
|
18
|
+
input: {
|
|
19
|
+
oldCartId: $oldCartId
|
|
20
|
+
newCartId: $newCartId
|
|
21
|
+
actorId: $actorId
|
|
22
|
+
isAllowedToMergeItem: $isAllowedToMergeItem
|
|
23
|
+
}
|
|
24
|
+
) ${(0, helpers_1.hasFields)(fields) ? `{ ${(0, helpers_1.joinField)(fields)} }` : ""}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
};
|
|
28
|
+
exports.MERGE_ORDER_CART = MERGE_ORDER_CART;
|
package/dist/src/lib/SDK.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ import { RemoteAccessService } from "./remote_access_service";
|
|
|
21
21
|
import { StorageS3Service } from "./storage_s3";
|
|
22
22
|
import { ContentApiService } from "./content_api";
|
|
23
23
|
import { MarketPlaceService } from "./marketplace";
|
|
24
|
+
import { StorefrontService } from "./storefront";
|
|
25
|
+
import { DynamicCollectionService } from "./dynamic_collection";
|
|
24
26
|
export interface Endpoints {
|
|
25
27
|
product: string;
|
|
26
28
|
crm: string;
|
|
@@ -45,6 +47,8 @@ export interface Endpoints {
|
|
|
45
47
|
storage_s3: string;
|
|
46
48
|
content_api: string;
|
|
47
49
|
marketplace: string;
|
|
50
|
+
storefront: string;
|
|
51
|
+
dynamic_collection: string;
|
|
48
52
|
}
|
|
49
53
|
export declare class SDK {
|
|
50
54
|
orgId: string;
|
|
@@ -73,7 +77,9 @@ export declare class SDK {
|
|
|
73
77
|
remote_access_service: RemoteAccessService;
|
|
74
78
|
storage_s3: StorageS3Service;
|
|
75
79
|
marketplace: MarketPlaceService;
|
|
80
|
+
storefront: StorefrontService;
|
|
76
81
|
content_api: ContentApiService;
|
|
82
|
+
dynamic_collection: DynamicCollectionService;
|
|
77
83
|
token: string | null;
|
|
78
84
|
private endpoints;
|
|
79
85
|
constructor(orgId: string, storeId: string, storefrontAccessToken: string, environment: string);
|
package/dist/src/lib/SDK.js
CHANGED
|
@@ -27,6 +27,8 @@ const remote_access_service_1 = require("./remote_access_service");
|
|
|
27
27
|
const storage_s3_1 = require("./storage_s3");
|
|
28
28
|
const content_api_1 = require("./content_api");
|
|
29
29
|
const marketplace_1 = require("./marketplace");
|
|
30
|
+
const storefront_1 = require("./storefront");
|
|
31
|
+
const dynamic_collection_1 = require("./dynamic_collection");
|
|
30
32
|
class SDK {
|
|
31
33
|
constructor(orgId, storeId, storefrontAccessToken, environment) {
|
|
32
34
|
this.orgId = orgId;
|
|
@@ -36,10 +38,7 @@ class SDK {
|
|
|
36
38
|
this.token = null;
|
|
37
39
|
console.log("🚀 ~ SDK ~ storeId:", storeId);
|
|
38
40
|
(0, helpers_1.validateStorefrontAccessToken)(storefrontAccessToken);
|
|
39
|
-
this.endpoints =
|
|
40
|
-
environment == "live"
|
|
41
|
-
? config_1.environmentEndpoints.live
|
|
42
|
-
: config_1.environmentEndpoints.dev;
|
|
41
|
+
this.endpoints = environment == "live" ? config_1.environmentEndpoints.live : config_1.environmentEndpoints.dev;
|
|
43
42
|
//console.log("🚀 ~ SDK ~ endpoints:", endpoints.computing);
|
|
44
43
|
this.product = new index_1.ProductService(this.endpoints.product, orgId, storeId);
|
|
45
44
|
this.auth = new index_2.AuthService(this.endpoints.auth, orgId, storeId);
|
|
@@ -64,7 +63,9 @@ class SDK {
|
|
|
64
63
|
this.storage_s3 = new storage_s3_1.StorageS3Service(this.endpoints.storage_s3, orgId, storeId);
|
|
65
64
|
this.content_api = new content_api_1.ContentApiService(this.endpoints.content_api, orgId, storeId);
|
|
66
65
|
this.marketplace = new marketplace_1.MarketPlaceService(this.endpoints.marketplace, orgId, storeId);
|
|
66
|
+
this.dynamic_collection = new dynamic_collection_1.DynamicCollectionService(this.endpoints.dynamic_collection, orgId, storeId);
|
|
67
67
|
// Initialize other services here
|
|
68
|
+
this.storefront = new storefront_1.StorefrontService(this.endpoints.storefront, orgId, storeId);
|
|
68
69
|
}
|
|
69
70
|
setToken(token) {
|
|
70
71
|
this.token = token;
|
|
@@ -92,6 +93,8 @@ class SDK {
|
|
|
92
93
|
this.storage_s3.setToken(token);
|
|
93
94
|
this.content_api.setToken(token);
|
|
94
95
|
this.marketplace.setToken(token);
|
|
96
|
+
this.storefront.setToken(token);
|
|
97
|
+
this.dynamic_collection.setToken(token);
|
|
95
98
|
// Set token for other services here
|
|
96
99
|
}
|
|
97
100
|
// các module export từ serviceSDK.ts set storeId vào serviceSDK.ts
|
|
@@ -122,6 +125,8 @@ class SDK {
|
|
|
122
125
|
this.storage_s3 = new storage_s3_1.StorageS3Service(this.endpoints.storage_s3, this.orgId, storeId);
|
|
123
126
|
this.content_api = new content_api_1.ContentApiService(this.endpoints.content_api, this.orgId, storeId);
|
|
124
127
|
this.marketplace = new marketplace_1.MarketPlaceService(this.endpoints.marketplace, this.orgId, storeId);
|
|
128
|
+
this.storefront = new storefront_1.StorefrontService(this.endpoints.storefront, this.orgId, storeId);
|
|
129
|
+
this.dynamic_collection = new dynamic_collection_1.DynamicCollectionService(this.endpoints.dynamic_collection, this.orgId, storeId);
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
exports.SDK = SDK;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Service } from "../serviceSDK";
|
|
2
|
+
export declare class DynamicCollectionService extends Service {
|
|
3
|
+
/**
|
|
4
|
+
* Constructs a new ProductService instance.
|
|
5
|
+
* @param endpoint - The endpoint URL for the service.
|
|
6
|
+
* @param orgId - The organization ID.
|
|
7
|
+
* @param storeId - The store ID.
|
|
8
|
+
*/
|
|
9
|
+
constructor(endpoint: string, orgId: string, storeId: string);
|
|
10
|
+
setToken(token: string): void;
|
|
11
|
+
setStoreId(storeId: string): void;
|
|
12
|
+
getSlugPathView(slug: string, type: string): Promise<any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.DynamicCollectionService = void 0;
|
|
13
|
+
const serviceSDK_1 = require("../serviceSDK");
|
|
14
|
+
class DynamicCollectionService extends serviceSDK_1.Service {
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new ProductService instance.
|
|
17
|
+
* @param endpoint - The endpoint URL for the service.
|
|
18
|
+
* @param orgId - The organization ID.
|
|
19
|
+
* @param storeId - The store ID.
|
|
20
|
+
*/
|
|
21
|
+
constructor(endpoint, orgId, storeId) {
|
|
22
|
+
super(endpoint, orgId, storeId);
|
|
23
|
+
}
|
|
24
|
+
setToken(token) {
|
|
25
|
+
this.token = token;
|
|
26
|
+
}
|
|
27
|
+
setStoreId(storeId) {
|
|
28
|
+
this.storeId = storeId;
|
|
29
|
+
}
|
|
30
|
+
getSlugPathView(slug, type) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const endpoint = `/public/v2/records/slug_path/slug_path_view?slug=${slug}&type=${type}&platform=${this.storeId}`;
|
|
33
|
+
const method = "GET";
|
|
34
|
+
try {
|
|
35
|
+
const response = yield this.restApiCallWithToken(endpoint, method);
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.log(`Error in getSlugPathView: ${error}`);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.DynamicCollectionService = DynamicCollectionService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Service } from "../serviceSDK";
|
|
2
|
+
export declare class StorefrontService extends Service {
|
|
3
|
+
constructor(endpoint: string, orgId: string, storeId: string);
|
|
4
|
+
setToken(token: string): void;
|
|
5
|
+
setStoreId(storeId: string): void;
|
|
6
|
+
mergeOrderCart(oldCartId: string, newCartId: string, actorId: string, isAllowedToMergeItem: boolean, fields?: string[]): Promise<any>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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.StorefrontService = void 0;
|
|
13
|
+
const mutation_1 = require("../../graphql/storefront/mutation");
|
|
14
|
+
const serviceSDK_1 = require("../serviceSDK");
|
|
15
|
+
class StorefrontService extends serviceSDK_1.Service {
|
|
16
|
+
constructor(endpoint, orgId, storeId) {
|
|
17
|
+
super(endpoint, orgId, storeId);
|
|
18
|
+
}
|
|
19
|
+
setToken(token) {
|
|
20
|
+
this.token = token;
|
|
21
|
+
}
|
|
22
|
+
setStoreId(storeId) {
|
|
23
|
+
this.storeId = storeId;
|
|
24
|
+
}
|
|
25
|
+
mergeOrderCart(oldCartId_1, newCartId_1, actorId_1, isAllowedToMergeItem_1) {
|
|
26
|
+
return __awaiter(this, arguments, void 0, function* (oldCartId, newCartId, actorId, isAllowedToMergeItem, fields = ["success", "movedItemCount", "skippedItemCount", "oldCartCanceled", "message"]) {
|
|
27
|
+
const mutation = (0, mutation_1.MERGE_ORDER_CART)(fields);
|
|
28
|
+
const variables = {
|
|
29
|
+
oldCartId,
|
|
30
|
+
newCartId,
|
|
31
|
+
actorId,
|
|
32
|
+
isAllowedToMergeItem
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
const response = yield this.graphqlMutationV2(mutation, variables);
|
|
36
|
+
return response.mergeOrderCart;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.StorefrontService = StorefrontService;
|
|
@@ -2,3 +2,5 @@ import { Endpoints } from "../lib/SDK";
|
|
|
2
2
|
export declare function createToken(environment: string): string;
|
|
3
3
|
export declare function decodeToken(token: string): string | null;
|
|
4
4
|
export declare function validateStorefrontAccessToken(storefrontAccessToken: string): Endpoints;
|
|
5
|
+
export declare function joinField(fields?: string[]): string;
|
|
6
|
+
export declare function hasFields(fields?: string[]): boolean;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateStorefrontAccessToken = exports.decodeToken = exports.createToken = void 0;
|
|
6
|
+
exports.hasFields = exports.joinField = exports.validateStorefrontAccessToken = exports.decodeToken = exports.createToken = void 0;
|
|
7
7
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
8
8
|
const config_1 = require("../../config/config");
|
|
9
9
|
function createToken(environment) {
|
|
@@ -29,13 +29,19 @@ function validateStorefrontAccessToken(storefrontAccessToken) {
|
|
|
29
29
|
console.log("🚀 ~ environment:", environment);
|
|
30
30
|
const validEnvironments = {
|
|
31
31
|
dev: "dev",
|
|
32
|
-
live: "live"
|
|
32
|
+
live: "live"
|
|
33
33
|
};
|
|
34
34
|
if (!Object.keys(validEnvironments).includes(environment)) {
|
|
35
35
|
throw new Error("Invalid storefrontAccessToken");
|
|
36
36
|
}
|
|
37
|
-
return environment == "dev"
|
|
38
|
-
? config_1.environmentEndpoints.dev
|
|
39
|
-
: config_1.environmentEndpoints.live;
|
|
37
|
+
return environment == "dev" ? config_1.environmentEndpoints.dev : config_1.environmentEndpoints.live;
|
|
40
38
|
}
|
|
41
39
|
exports.validateStorefrontAccessToken = validateStorefrontAccessToken;
|
|
40
|
+
function joinField(fields = []) {
|
|
41
|
+
return fields.join("\n ");
|
|
42
|
+
}
|
|
43
|
+
exports.joinField = joinField;
|
|
44
|
+
function hasFields(fields = []) {
|
|
45
|
+
return fields.length > 0;
|
|
46
|
+
}
|
|
47
|
+
exports.hasFields = hasFields;
|