@longvansoftware/service-js-client 2.2.2 → 2.2.3
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/src/graphql/storage_s3/queries.d.ts +1 -0
- package/dist/src/graphql/storage_s3/queries.js +13 -1
- package/dist/src/lib/storage_s3/index.d.ts +1 -0
- package/dist/src/lib/storage_s3/index.js +25 -4
- package/package.json +1 -1
- package/dist/src/lib/service.d.ts +0 -14
- package/dist/src/lib/service.js +0 -101
- package/dist/src/utils/build-field-string.d.ts +0 -1
- package/dist/src/utils/build-field-string.js +0 -16
|
@@ -8,3 +8,4 @@ export declare const GET_LIST_CORS_BY_S3_USER_ID: (fields?: string[]) => Documen
|
|
|
8
8
|
export declare const GET_LIST_FILE_OTHER_VERSION: (fields?: string[]) => DocumentNode;
|
|
9
9
|
export declare const CHART_IN_YEAR: (fields?: string[]) => DocumentNode;
|
|
10
10
|
export declare const GET_IP_CONSUL: DocumentNode;
|
|
11
|
+
export declare const FILTER_LIST_OBJECT: (fields?: string[]) => DocumentNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GET_IP_CONSUL = exports.CHART_IN_YEAR = exports.GET_LIST_FILE_OTHER_VERSION = exports.GET_LIST_CORS_BY_S3_USER_ID = exports.GET_LIST_S3_DOMAIN_BY_S3_USER_ID = exports.GET_LIST_FILE_TRASH = exports.GET_LIST_OBJECT = exports.GET_LIST_BUCKET_BY_S3_USER_ID = exports.GET_LIST_S3_USER_BY_SERVICE_ID = void 0;
|
|
3
|
+
exports.FILTER_LIST_OBJECT = exports.GET_IP_CONSUL = exports.CHART_IN_YEAR = exports.GET_LIST_FILE_OTHER_VERSION = exports.GET_LIST_CORS_BY_S3_USER_ID = exports.GET_LIST_S3_DOMAIN_BY_S3_USER_ID = exports.GET_LIST_FILE_TRASH = exports.GET_LIST_OBJECT = exports.GET_LIST_BUCKET_BY_S3_USER_ID = exports.GET_LIST_S3_USER_BY_SERVICE_ID = void 0;
|
|
4
4
|
const graphql_tag_1 = require("graphql-tag");
|
|
5
5
|
const GET_LIST_S3_USER_BY_SERVICE_ID = (fields = []) => {
|
|
6
6
|
const fieldStr = fields.join('\n ');
|
|
@@ -103,3 +103,15 @@ exports.GET_IP_CONSUL = (0, graphql_tag_1.gql) `
|
|
|
103
103
|
getIPConsul(userId: $userId)
|
|
104
104
|
}
|
|
105
105
|
`;
|
|
106
|
+
const FILTER_LIST_OBJECT = (fields = []) => {
|
|
107
|
+
const fieldStr = fields.join('\n ');
|
|
108
|
+
const hasFields = fields.length > 0;
|
|
109
|
+
return (0, graphql_tag_1.gql) `
|
|
110
|
+
query FilterListObject($s3UserId: String!, $bucketId: String!, $maxKeys: Int!, $key: String, $prefixSearch: String, $continuationToken: String) {
|
|
111
|
+
filterListObject(s3UserId: $s3UserId, bucketId: $bucketId, maxKeys: $maxKeys, key: $key, prefixSearch: $prefixSearch, continuationToken: $continuationToken){
|
|
112
|
+
${hasFields ? `${fieldStr}` : ''}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
};
|
|
117
|
+
exports.FILTER_LIST_OBJECT = FILTER_LIST_OBJECT;
|
|
@@ -37,4 +37,5 @@ export declare class StorageS3Service extends Service {
|
|
|
37
37
|
actionSyncUserFromS3(s3UserId: string, updateBy: string, fields: string[]): Promise<any>;
|
|
38
38
|
chartInYear(s3UserId: string, year: number, month: number, fields: string[]): Promise<any>;
|
|
39
39
|
getIPConsul(userId: string): Promise<any>;
|
|
40
|
+
filterListObject(s3UserId: string, bucketId: string, maxKeys: number, key: string, prefixSearch: string, continuationToken: string, fields: string[]): Promise<any>;
|
|
40
41
|
}
|
|
@@ -422,14 +422,14 @@ class StorageS3Service extends serviceSDK_1.Service {
|
|
|
422
422
|
}
|
|
423
423
|
addS3Domain(s3UserId, domain, byUser, fields) {
|
|
424
424
|
return __awaiter(this, void 0, void 0, function* () {
|
|
425
|
-
const
|
|
425
|
+
const mutation = (0, mutations_1.ADD_S3_DOMAIN)(fields);
|
|
426
426
|
const variables = {
|
|
427
427
|
s3UserId,
|
|
428
428
|
domain,
|
|
429
429
|
byUser,
|
|
430
430
|
};
|
|
431
431
|
try {
|
|
432
|
-
const response = yield this.
|
|
432
|
+
const response = yield this.graphqlMutationV2(mutation, variables);
|
|
433
433
|
return response.addS3Domain;
|
|
434
434
|
}
|
|
435
435
|
catch (error) {
|
|
@@ -440,14 +440,14 @@ class StorageS3Service extends serviceSDK_1.Service {
|
|
|
440
440
|
}
|
|
441
441
|
removeS3Domain(s3UserId, domainId, byUser, fields) {
|
|
442
442
|
return __awaiter(this, void 0, void 0, function* () {
|
|
443
|
-
const
|
|
443
|
+
const mutation = (0, mutations_1.REMOVE_S3_DOMAIN)(fields);
|
|
444
444
|
const variables = {
|
|
445
445
|
s3UserId,
|
|
446
446
|
domainId,
|
|
447
447
|
byUser,
|
|
448
448
|
};
|
|
449
449
|
try {
|
|
450
|
-
const response = yield this.
|
|
450
|
+
const response = yield this.graphqlMutationV2(mutation, variables);
|
|
451
451
|
return response.removeS3Domain;
|
|
452
452
|
}
|
|
453
453
|
catch (error) {
|
|
@@ -662,5 +662,26 @@ class StorageS3Service extends serviceSDK_1.Service {
|
|
|
662
662
|
}
|
|
663
663
|
});
|
|
664
664
|
}
|
|
665
|
+
filterListObject(s3UserId, bucketId, maxKeys, key, prefixSearch, continuationToken, fields) {
|
|
666
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
667
|
+
const query = (0, queries_1.FILTER_LIST_OBJECT)(fields);
|
|
668
|
+
const variables = {
|
|
669
|
+
s3UserId,
|
|
670
|
+
bucketId,
|
|
671
|
+
maxKeys,
|
|
672
|
+
key,
|
|
673
|
+
prefixSearch,
|
|
674
|
+
continuationToken
|
|
675
|
+
};
|
|
676
|
+
try {
|
|
677
|
+
const response = yield this.graphqlQueryV2(query, variables);
|
|
678
|
+
return response.filterListObject;
|
|
679
|
+
}
|
|
680
|
+
catch (error) {
|
|
681
|
+
console.log(`Error in filterListObject: ${error}`);
|
|
682
|
+
throw error;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
665
686
|
}
|
|
666
687
|
exports.StorageS3Service = StorageS3Service;
|
package/package.json
CHANGED
|
@@ -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
|
-
}
|
package/dist/src/lib/service.js
DELETED
|
@@ -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;
|