@longvansoftware/service-js-client 2.2.2 → 2.2.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.
- package/dist/src/graphql/storage_s3/queries.d.ts +2 -0
- package/dist/src/graphql/storage_s3/queries.js +25 -1
- package/dist/src/lib/storage_s3/index.d.ts +2 -0
- package/dist/src/lib/storage_s3/index.js +41 -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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
2
|
export declare const GET_LIST_S3_USER_BY_SERVICE_ID: (fields?: string[]) => DocumentNode;
|
|
3
|
+
export declare const GET_LIST_S3_USER_ACTIVE_BY_SERVICE_ID: (fields?: string[]) => DocumentNode;
|
|
3
4
|
export declare const GET_LIST_BUCKET_BY_S3_USER_ID: (fields?: string[]) => DocumentNode;
|
|
4
5
|
export declare const GET_LIST_OBJECT: (fields?: string[]) => DocumentNode;
|
|
5
6
|
export declare const GET_LIST_FILE_TRASH: (fields?: string[]) => DocumentNode;
|
|
@@ -8,3 +9,4 @@ export declare const GET_LIST_CORS_BY_S3_USER_ID: (fields?: string[]) => Documen
|
|
|
8
9
|
export declare const GET_LIST_FILE_OTHER_VERSION: (fields?: string[]) => DocumentNode;
|
|
9
10
|
export declare const CHART_IN_YEAR: (fields?: string[]) => DocumentNode;
|
|
10
11
|
export declare const GET_IP_CONSUL: DocumentNode;
|
|
12
|
+
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_ACTIVE_BY_SERVICE_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 ');
|
|
@@ -14,6 +14,18 @@ const GET_LIST_S3_USER_BY_SERVICE_ID = (fields = []) => {
|
|
|
14
14
|
`;
|
|
15
15
|
};
|
|
16
16
|
exports.GET_LIST_S3_USER_BY_SERVICE_ID = GET_LIST_S3_USER_BY_SERVICE_ID;
|
|
17
|
+
const GET_LIST_S3_USER_ACTIVE_BY_SERVICE_ID = (fields = []) => {
|
|
18
|
+
const fieldStr = fields.join('\n ');
|
|
19
|
+
const hasFields = fields.length > 0;
|
|
20
|
+
return (0, graphql_tag_1.gql) `
|
|
21
|
+
query GetListS3UserActiveByServiceId($serviceId: String!) {
|
|
22
|
+
getListS3UserActiveByServiceId(serviceId: $serviceId) {
|
|
23
|
+
${hasFields ? `${fieldStr}` : ''}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
};
|
|
28
|
+
exports.GET_LIST_S3_USER_ACTIVE_BY_SERVICE_ID = GET_LIST_S3_USER_ACTIVE_BY_SERVICE_ID;
|
|
17
29
|
const GET_LIST_BUCKET_BY_S3_USER_ID = (fields = []) => {
|
|
18
30
|
const fieldStr = fields.join('\n ');
|
|
19
31
|
const hasFields = fields.length > 0;
|
|
@@ -103,3 +115,15 @@ exports.GET_IP_CONSUL = (0, graphql_tag_1.gql) `
|
|
|
103
115
|
getIPConsul(userId: $userId)
|
|
104
116
|
}
|
|
105
117
|
`;
|
|
118
|
+
const FILTER_LIST_OBJECT = (fields = []) => {
|
|
119
|
+
const fieldStr = fields.join('\n ');
|
|
120
|
+
const hasFields = fields.length > 0;
|
|
121
|
+
return (0, graphql_tag_1.gql) `
|
|
122
|
+
query FilterListObject($s3UserId: String!, $bucketId: String!, $maxKeys: Int!, $key: String, $prefixSearch: String, $continuationToken: String) {
|
|
123
|
+
filterListObject(s3UserId: $s3UserId, bucketId: $bucketId, maxKeys: $maxKeys, key: $key, prefixSearch: $prefixSearch, continuationToken: $continuationToken){
|
|
124
|
+
${hasFields ? `${fieldStr}` : ''}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
`;
|
|
128
|
+
};
|
|
129
|
+
exports.FILTER_LIST_OBJECT = FILTER_LIST_OBJECT;
|
|
@@ -3,6 +3,7 @@ import { Service } from '../serviceSDK';
|
|
|
3
3
|
export declare class StorageS3Service extends Service {
|
|
4
4
|
constructor(endpoint: string, orgId: string, storeId: string);
|
|
5
5
|
getListS3UserByServiceId(serviceId: string, fields: string[]): Promise<any>;
|
|
6
|
+
getListS3UserActiveByServiceId(serviceId: string, fields: string[]): Promise<any>;
|
|
6
7
|
getListBucketByS3UserId(s3UserId: string, fields: string[]): Promise<any>;
|
|
7
8
|
getListObject(s3UserId: string, bucketId: string, key: string, fields: string[]): Promise<any>;
|
|
8
9
|
uploadFolder(userId: string, bucketId: string, fileInfo: [FileInfoInput], basePrefix: string, fields: string[]): Promise<any>;
|
|
@@ -37,4 +38,5 @@ export declare class StorageS3Service extends Service {
|
|
|
37
38
|
actionSyncUserFromS3(s3UserId: string, updateBy: string, fields: string[]): Promise<any>;
|
|
38
39
|
chartInYear(s3UserId: string, year: number, month: number, fields: string[]): Promise<any>;
|
|
39
40
|
getIPConsul(userId: string): Promise<any>;
|
|
41
|
+
filterListObject(s3UserId: string, bucketId: string, maxKeys: number, key: string, prefixSearch: string, continuationToken: string, fields: string[]): Promise<any>;
|
|
40
42
|
}
|
|
@@ -33,6 +33,22 @@ class StorageS3Service extends serviceSDK_1.Service {
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
getListS3UserActiveByServiceId(serviceId, fields) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const query = (0, queries_1.GET_LIST_S3_USER_ACTIVE_BY_SERVICE_ID)(fields);
|
|
39
|
+
const variables = {
|
|
40
|
+
serviceId,
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
const response = yield this.graphqlQueryV2(query, variables);
|
|
44
|
+
return response.getListS3UserActiveByServiceId;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.log(`Error in getListS3UserActiveByServiceId: ${error}`);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
36
52
|
getListBucketByS3UserId(s3UserId, fields) {
|
|
37
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
54
|
const query = (0, queries_1.GET_LIST_BUCKET_BY_S3_USER_ID)(fields);
|
|
@@ -422,14 +438,14 @@ class StorageS3Service extends serviceSDK_1.Service {
|
|
|
422
438
|
}
|
|
423
439
|
addS3Domain(s3UserId, domain, byUser, fields) {
|
|
424
440
|
return __awaiter(this, void 0, void 0, function* () {
|
|
425
|
-
const
|
|
441
|
+
const mutation = (0, mutations_1.ADD_S3_DOMAIN)(fields);
|
|
426
442
|
const variables = {
|
|
427
443
|
s3UserId,
|
|
428
444
|
domain,
|
|
429
445
|
byUser,
|
|
430
446
|
};
|
|
431
447
|
try {
|
|
432
|
-
const response = yield this.
|
|
448
|
+
const response = yield this.graphqlMutationV2(mutation, variables);
|
|
433
449
|
return response.addS3Domain;
|
|
434
450
|
}
|
|
435
451
|
catch (error) {
|
|
@@ -440,14 +456,14 @@ class StorageS3Service extends serviceSDK_1.Service {
|
|
|
440
456
|
}
|
|
441
457
|
removeS3Domain(s3UserId, domainId, byUser, fields) {
|
|
442
458
|
return __awaiter(this, void 0, void 0, function* () {
|
|
443
|
-
const
|
|
459
|
+
const mutation = (0, mutations_1.REMOVE_S3_DOMAIN)(fields);
|
|
444
460
|
const variables = {
|
|
445
461
|
s3UserId,
|
|
446
462
|
domainId,
|
|
447
463
|
byUser,
|
|
448
464
|
};
|
|
449
465
|
try {
|
|
450
|
-
const response = yield this.
|
|
466
|
+
const response = yield this.graphqlMutationV2(mutation, variables);
|
|
451
467
|
return response.removeS3Domain;
|
|
452
468
|
}
|
|
453
469
|
catch (error) {
|
|
@@ -662,5 +678,26 @@ class StorageS3Service extends serviceSDK_1.Service {
|
|
|
662
678
|
}
|
|
663
679
|
});
|
|
664
680
|
}
|
|
681
|
+
filterListObject(s3UserId, bucketId, maxKeys, key, prefixSearch, continuationToken, fields) {
|
|
682
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
683
|
+
const query = (0, queries_1.FILTER_LIST_OBJECT)(fields);
|
|
684
|
+
const variables = {
|
|
685
|
+
s3UserId,
|
|
686
|
+
bucketId,
|
|
687
|
+
maxKeys,
|
|
688
|
+
key,
|
|
689
|
+
prefixSearch,
|
|
690
|
+
continuationToken
|
|
691
|
+
};
|
|
692
|
+
try {
|
|
693
|
+
const response = yield this.graphqlQueryV2(query, variables);
|
|
694
|
+
return response.filterListObject;
|
|
695
|
+
}
|
|
696
|
+
catch (error) {
|
|
697
|
+
console.log(`Error in filterListObject: ${error}`);
|
|
698
|
+
throw error;
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
}
|
|
665
702
|
}
|
|
666
703
|
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;
|