@longvansoftware/service-js-client 1.19.1 → 1.20.0

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.
@@ -20,6 +20,7 @@ export declare const environmentEndpoints: {
20
20
  accounting_service: string;
21
21
  quicklab_service: string;
22
22
  remote_access_service: string;
23
+ storage_s3: string;
23
24
  };
24
25
  live: {
25
26
  product: string;
@@ -42,5 +43,6 @@ export declare const environmentEndpoints: {
42
43
  accounting_service: string;
43
44
  quicklab_service: string;
44
45
  remote_access_service: string;
46
+ storage_s3: string;
45
47
  };
46
48
  };
@@ -22,7 +22,9 @@ exports.environmentEndpoints = {
22
22
  cloud_rest: "https://api-gateway.dev.longvan.vn/cloud-service-api/v1",
23
23
  accounting_service: "https://api-gateway.dev.longvan.vn/accounting-service/graphql/",
24
24
  quicklab_service: "https://portal.dev.longvan.vn/quicklab-api/graphql",
25
- remote_access_service: "https://api-gateway.dev.longvan.vn/remote-access-service/graphql"
25
+ remote_access_service: "https://api-gateway.dev.longvan.vn/remote-access-service/graphql",
26
+ // storage_s3: "https://portal.dev.longvan.vn/storage-s3-api/graphql",
27
+ storage_s3: "https://storage-s3-api.dev.longvan.vn/storage-s3-api/graphql",
26
28
  },
27
29
  live: {
28
30
  product: "https://product-service.longvan.vn/product-service/graphql",
@@ -44,6 +46,8 @@ exports.environmentEndpoints = {
44
46
  cloud_rest: "https://api-gateway.longvan.vn/cloud-service-api/v1",
45
47
  accounting_service: "https://api-gateway.longvan.vn/accounting-service/graphql/",
46
48
  quicklab_service: "https://portal.longvan.vn/quicklab-api/graphql",
47
- remote_access_service: "https://api-gateway.longvan.vn/remote-access-service/graphql"
49
+ remote_access_service: "https://api-gateway.longvan.vn/remote-access-service/graphql",
50
+ // storage_s3: "https://portal.longvan.vn/storage-s3-api/graphql",
51
+ storage_s3: "https://storage-s3-api.longvan.vn/storage-s3-api/graphql",
48
52
  },
49
53
  };
@@ -0,0 +1,13 @@
1
+ import { DocumentNode } from 'graphql';
2
+ export declare const CREATE_BUCKET: (fields?: string[]) => DocumentNode;
3
+ export declare const DELETE_BUCKET: (fields?: string[]) => DocumentNode;
4
+ export declare const CREATE_FOLDER: (fields?: string[]) => DocumentNode;
5
+ export declare const REMOVE_FOLDER: (fields?: string[]) => DocumentNode;
6
+ export declare const UPLOAD_FOLDER: (fields?: string[]) => DocumentNode;
7
+ export declare const UPDATE_ACL_PERMISSION_FILE: (fields?: string[]) => DocumentNode;
8
+ export declare const RENAME_FILE: (fields?: string[]) => DocumentNode;
9
+ export declare const SHARE_LINK_FILE_BY_TIME_DYNAMIC: (fields?: string[]) => DocumentNode;
10
+ export declare const SHARE_LINK_FILE_BY_TIME: DocumentNode;
11
+ export declare const COPY_FILE: (fields?: string[]) => DocumentNode;
12
+ export declare const MOVE_FILE: (fields?: string[]) => DocumentNode;
13
+ export declare const REMOVE_FILE: (fields?: string[]) => DocumentNode;
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REMOVE_FILE = exports.MOVE_FILE = exports.COPY_FILE = exports.SHARE_LINK_FILE_BY_TIME = exports.SHARE_LINK_FILE_BY_TIME_DYNAMIC = exports.RENAME_FILE = exports.UPDATE_ACL_PERMISSION_FILE = exports.UPLOAD_FOLDER = exports.REMOVE_FOLDER = exports.CREATE_FOLDER = exports.DELETE_BUCKET = exports.CREATE_BUCKET = void 0;
4
+ const graphql_tag_1 = require("graphql-tag");
5
+ const CREATE_BUCKET = (fields = []) => {
6
+ const fieldStr = fields.join('\n ');
7
+ const hasFields = fields.length > 0;
8
+ return (0, graphql_tag_1.gql) `
9
+ mutation CreateBucket(
10
+ $s3UserId: String!,
11
+ $bucketName: String!,
12
+ $enableObjectLock: Boolean!,
13
+ $enableBucketVersioning: Boolean!
14
+ ) {
15
+ createBucket(
16
+ s3UserId: $s3UserId,
17
+ bucketName: $bucketName,
18
+ enableObjectLock: $enableObjectLock,
19
+ enableBucketVersioning: $enableBucketVersioning
20
+ ) {
21
+ ${hasFields ? `${fieldStr}` : ''}
22
+ }
23
+ }
24
+ `;
25
+ };
26
+ exports.CREATE_BUCKET = CREATE_BUCKET;
27
+ const DELETE_BUCKET = (fields = []) => {
28
+ const fieldStr = fields.join('\n ');
29
+ const hasFields = fields.length > 0;
30
+ return (0, graphql_tag_1.gql) `
31
+ mutation DeleteBucket(
32
+ $bucketId: String!,
33
+ $updateBy: String!
34
+ ) {
35
+ deleteBucket(
36
+ bucketId: $bucketId,
37
+ updateBy: $updateBy
38
+ ) {
39
+ ${hasFields ? `${fieldStr}` : ''}
40
+ }
41
+ }
42
+ `;
43
+ };
44
+ exports.DELETE_BUCKET = DELETE_BUCKET;
45
+ const CREATE_FOLDER = (fields = []) => {
46
+ const fieldStr = fields.join('\n ');
47
+ const hasFields = fields.length > 0;
48
+ return (0, graphql_tag_1.gql) `
49
+ mutation CreateFolder(
50
+ $s3UserId: String!,
51
+ $bucketId: String!,
52
+ $folderName: String!
53
+ ) {
54
+ createFolder(
55
+ s3UserId: $s3UserId,
56
+ bucketId: $bucketId,
57
+ folderName: $folderName
58
+ ) {
59
+ ${hasFields ? `${fieldStr}` : ''}
60
+ }
61
+ }
62
+ `;
63
+ };
64
+ exports.CREATE_FOLDER = CREATE_FOLDER;
65
+ const REMOVE_FOLDER = (fields = []) => {
66
+ const fieldStr = fields.join('\n ');
67
+ const hasFields = fields.length > 0;
68
+ return (0, graphql_tag_1.gql) `
69
+ mutation RemoveFolder(
70
+ $s3UserId: String!,
71
+ $bucketId: String!,
72
+ $key: String!
73
+ ) {
74
+ removeFolder(
75
+ s3UserId: $s3UserId,
76
+ bucketId: $bucketId,
77
+ key: $key
78
+ ) {
79
+ ${hasFields ? `${fieldStr}` : ''}
80
+ }
81
+ }
82
+ `;
83
+ };
84
+ exports.REMOVE_FOLDER = REMOVE_FOLDER;
85
+ const UPLOAD_FOLDER = (fields = []) => {
86
+ const fieldStr = fields.join('\n ');
87
+ const hasFields = fields.length > 0;
88
+ return (0, graphql_tag_1.gql) `
89
+ mutation UploadFolder(
90
+ $userId: String!,
91
+ $bucketId: String!,
92
+ $fileInfo: [FileInfoInput!]!,
93
+ $basePrefix: String!
94
+ ) {
95
+ uploadFolder(
96
+ userId: $userId,
97
+ bucketId: $bucketId,
98
+ fileInfo: $fileInfo,
99
+ basePrefix: $basePrefix
100
+ ) {
101
+ ${hasFields ? `${fieldStr}` : ''}
102
+ }
103
+ }
104
+ `;
105
+ };
106
+ exports.UPLOAD_FOLDER = UPLOAD_FOLDER;
107
+ const UPDATE_ACL_PERMISSION_FILE = (fields = []) => {
108
+ const fieldStr = fields.join('\n ');
109
+ const hasFields = fields.length > 0;
110
+ return (0, graphql_tag_1.gql) `
111
+ mutation UpdateAclPermissionFile(
112
+ $s3UserId: String!,
113
+ $bucketId: String!,
114
+ $key: String!,
115
+ $isPublic: Boolean!
116
+ ) {
117
+ updateAclPermissionFile(
118
+ s3UserId: $s3UserId,
119
+ bucketId: $bucketId,
120
+ key: $key,
121
+ isPublic: $isPublic
122
+ ) {
123
+ ${hasFields ? `${fieldStr}` : ''}
124
+ }
125
+ }
126
+ `;
127
+ };
128
+ exports.UPDATE_ACL_PERMISSION_FILE = UPDATE_ACL_PERMISSION_FILE;
129
+ const RENAME_FILE = (fields = []) => {
130
+ const fieldStr = fields.join('\n ');
131
+ const hasFields = fields.length > 0;
132
+ return (0, graphql_tag_1.gql) `
133
+ mutation RenameFile(
134
+ $s3UserId: String!,
135
+ $bucketId: String!,
136
+ $key: String!,
137
+ $fileNewName: String!
138
+ ) {
139
+ renameFile(
140
+ s3UserId: $s3UserId,
141
+ bucketId: $bucketId,
142
+ key: $key,
143
+ fileNewName: $fileNewName
144
+ ) {
145
+ ${hasFields ? `${fieldStr}` : ''}
146
+ }
147
+ }
148
+ `;
149
+ };
150
+ exports.RENAME_FILE = RENAME_FILE;
151
+ const SHARE_LINK_FILE_BY_TIME_DYNAMIC = (fields = []) => {
152
+ const fieldStr = fields.join('\n ');
153
+ const hasFields = fields.length > 0;
154
+ return (0, graphql_tag_1.gql) `
155
+ mutation ShareLinkFileByTime(
156
+ $s3UserId: String!,
157
+ $bucketId: String!,
158
+ $key: String!,
159
+ $quantityHour: Int!
160
+ ) {
161
+ shareLinkFileByTime(
162
+ s3UserId: $s3UserId,
163
+ bucketId: $bucketId,
164
+ key: $key,
165
+ quantityHour: $quantityHour
166
+ ) {
167
+ ${hasFields ? `${fieldStr}` : ''}
168
+ }
169
+ }
170
+ `;
171
+ };
172
+ exports.SHARE_LINK_FILE_BY_TIME_DYNAMIC = SHARE_LINK_FILE_BY_TIME_DYNAMIC;
173
+ exports.SHARE_LINK_FILE_BY_TIME = (0, graphql_tag_1.gql) `
174
+ mutation ShareLinkFileByTime($s3UserId: String!, $bucketId: String!, $key: String!, $quantityHour: Int!) {
175
+ shareLinkFileByTime(s3UserId: $s3UserId, bucketId: $bucketId, key: $key, quantityHour: $quantityHour)
176
+ }
177
+ `;
178
+ const COPY_FILE = (fields = []) => {
179
+ const fieldStr = fields.join('\n ');
180
+ const hasFields = fields.length > 0;
181
+ return (0, graphql_tag_1.gql) `
182
+ mutation CopyFile(
183
+ $s3UserId: String!,
184
+ $bucketId: String!,
185
+ $srcFileKey: String!,
186
+ $dstFileKey: String!
187
+ ) {
188
+ copyFile(
189
+ s3UserId: $s3UserId,
190
+ bucketId: $bucketId,
191
+ srcFileKey: $srcFileKey,
192
+ dstFileKey: $dstFileKey
193
+ ) {
194
+ ${hasFields ? `${fieldStr}` : ''}
195
+ }
196
+ }
197
+ `;
198
+ };
199
+ exports.COPY_FILE = COPY_FILE;
200
+ const MOVE_FILE = (fields = []) => {
201
+ const fieldStr = fields.join('\n ');
202
+ const hasFields = fields.length > 0;
203
+ return (0, graphql_tag_1.gql) `
204
+ mutation MoveFile(
205
+ $s3UserId: String!,
206
+ $bucketId: String!,
207
+ $srcFileKey: String!,
208
+ $dstFileKey: String!
209
+ ) {
210
+ moveFile(
211
+ s3UserId: $s3UserId,
212
+ bucketId: $bucketId,
213
+ srcFileKey: $srcFileKey,
214
+ dstFileKey: $dstFileKey
215
+ ) {
216
+ ${hasFields ? `${fieldStr}` : ''}
217
+ }
218
+ }
219
+ `;
220
+ };
221
+ exports.MOVE_FILE = MOVE_FILE;
222
+ const REMOVE_FILE = (fields = []) => {
223
+ const fieldStr = fields.join('\n ');
224
+ const hasFields = fields.length > 0;
225
+ return (0, graphql_tag_1.gql) `
226
+ mutation RemoveFile(
227
+ $s3UserId: String!,
228
+ $bucketId: String!,
229
+ $keys: [String!]!
230
+ ) {
231
+ removeFile(
232
+ s3UserId: $s3UserId,
233
+ bucketId: $bucketId,
234
+ keys: $keys
235
+ ) {
236
+ ${hasFields ? `${fieldStr}` : ''}
237
+ }
238
+ }
239
+ `;
240
+ };
241
+ exports.REMOVE_FILE = REMOVE_FILE;
@@ -0,0 +1,4 @@
1
+ import { DocumentNode } from 'graphql';
2
+ export declare const GET_LIST_S3_USER_BY_SERVICE_ID: (fields?: string[]) => DocumentNode;
3
+ export declare const GET_LIST_BUCKET_BY_S3_USER_ID: (fields?: string[]) => DocumentNode;
4
+ export declare const GET_LIST_OBJECT: (fields?: string[]) => DocumentNode;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET_LIST_OBJECT = exports.GET_LIST_BUCKET_BY_S3_USER_ID = exports.GET_LIST_S3_USER_BY_SERVICE_ID = void 0;
4
+ const graphql_tag_1 = require("graphql-tag");
5
+ const GET_LIST_S3_USER_BY_SERVICE_ID = (fields = []) => {
6
+ const fieldStr = fields.join('\n ');
7
+ const hasFields = fields.length > 0;
8
+ return (0, graphql_tag_1.gql) `
9
+ query GetListS3UserByServiceId($serviceId: String!) {
10
+ getListS3UserByServiceId(serviceId: $serviceId) {
11
+ ${hasFields ? `${fieldStr}` : ''}
12
+ }
13
+ }
14
+ `;
15
+ };
16
+ exports.GET_LIST_S3_USER_BY_SERVICE_ID = GET_LIST_S3_USER_BY_SERVICE_ID;
17
+ const GET_LIST_BUCKET_BY_S3_USER_ID = (fields = []) => {
18
+ const fieldStr = fields.join('\n ');
19
+ const hasFields = fields.length > 0;
20
+ return (0, graphql_tag_1.gql) `
21
+ query GetListBucketByS3UserId($s3UserId: String!) {
22
+ getListBucketByS3UserId(s3UserId: $s3UserId) {
23
+ ${hasFields ? `${fieldStr}` : ''}
24
+ }
25
+ }
26
+ `;
27
+ };
28
+ exports.GET_LIST_BUCKET_BY_S3_USER_ID = GET_LIST_BUCKET_BY_S3_USER_ID;
29
+ const GET_LIST_OBJECT = (fields = []) => {
30
+ const fieldStr = fields.join('\n ');
31
+ const hasFields = fields.length > 0;
32
+ return (0, graphql_tag_1.gql) `
33
+ query GetListObject($s3UserId: String!, $bucketId: String!, $key: String!) {
34
+ getListObject(s3UserId: $s3UserId, bucketId: $bucketId, key: $key) {
35
+ ${hasFields ? `${fieldStr}` : ''}
36
+ }
37
+ }
38
+ `;
39
+ };
40
+ exports.GET_LIST_OBJECT = GET_LIST_OBJECT;
@@ -18,6 +18,7 @@ import { OrderCloudRestService } from "./order_cloud_rest";
18
18
  import { AccountingService } from "./accounting_service";
19
19
  import { QuicklabService } from "./quicklab_service";
20
20
  import { RemoteAccessService } from "./remote_access_service";
21
+ import { StorageS3Service } from "./storage_s3";
21
22
  export interface Endpoints {
22
23
  product: string;
23
24
  crm: string;
@@ -39,6 +40,7 @@ export interface Endpoints {
39
40
  accounting_service: string;
40
41
  quicklab_service: string;
41
42
  remote_access_service: string;
43
+ storage_s3: string;
42
44
  }
43
45
  export declare class SDK {
44
46
  orgId: string;
@@ -65,6 +67,7 @@ export declare class SDK {
65
67
  accounting_service: AccountingService;
66
68
  quicklab_service: QuicklabService;
67
69
  remote_access_service: RemoteAccessService;
70
+ storage_s3: StorageS3Service;
68
71
  token: string | null;
69
72
  private endpoints;
70
73
  constructor(orgId: string, storeId: string, storefrontAccessToken: string, environment: string);
@@ -24,6 +24,7 @@ const order_cloud_rest_1 = require("./order_cloud_rest");
24
24
  const accounting_service_1 = require("./accounting_service");
25
25
  const quicklab_service_1 = require("./quicklab_service");
26
26
  const remote_access_service_1 = require("./remote_access_service");
27
+ const storage_s3_1 = require("./storage_s3");
27
28
  class SDK {
28
29
  constructor(orgId, storeId, storefrontAccessToken, environment) {
29
30
  this.orgId = orgId;
@@ -58,6 +59,7 @@ class SDK {
58
59
  this.accounting_service = new accounting_service_1.AccountingService(this.endpoints.accounting_service, orgId, storeId);
59
60
  this.quicklab_service = new quicklab_service_1.QuicklabService(this.endpoints.quicklab_service, orgId, storeId);
60
61
  this.remote_access_service = new remote_access_service_1.RemoteAccessService(this.endpoints.remote_access_service, orgId, storeId);
62
+ this.storage_s3 = new storage_s3_1.StorageS3Service(this.endpoints.storage_s3, orgId, storeId);
61
63
  // Initialize other services here
62
64
  }
63
65
  setToken(token) {
@@ -83,6 +85,7 @@ class SDK {
83
85
  this.accounting_service.setToken(token);
84
86
  this.quicklab_service.setToken(token);
85
87
  this.remote_access_service.setToken(token);
88
+ this.storage_s3.setToken(token);
86
89
  // Set token for other services here
87
90
  }
88
91
  // các module export từ serviceSDK.ts set storeId vào serviceSDK.ts
@@ -110,6 +113,7 @@ class SDK {
110
113
  this.accounting_service = new accounting_service_1.AccountingService(this.endpoints.accounting_service, this.orgId, storeId);
111
114
  this.quicklab_service = new quicklab_service_1.QuicklabService(this.endpoints.quicklab_service, this.orgId, storeId);
112
115
  this.remote_access_service = new remote_access_service_1.RemoteAccessService(this.endpoints.remote_access_service, this.orgId, storeId);
116
+ this.storage_s3 = new storage_s3_1.StorageS3Service(this.endpoints.storage_s3, this.orgId, storeId);
113
117
  }
114
118
  }
115
119
  exports.SDK = SDK;
@@ -0,0 +1,18 @@
1
+ import { FileInfoInput } from '../../types/storage_s3';
2
+ import { Service } from '../serviceSDK';
3
+ export declare class StorageS3Service extends Service {
4
+ constructor(endpoint: string, orgId: string, storeId: string);
5
+ getListS3UserByServiceId(serviceId: string, fields: string[]): Promise<any>;
6
+ getListBucketByS3UserId(s3UserId: string, fields: string[]): Promise<any>;
7
+ getListObject(s3UserId: string, bucketId: string, key: string, fields: string[]): Promise<any>;
8
+ uploadFolder(userId: string, bucketId: string, fileInfo: [FileInfoInput], basePrefix: string, fields: string[]): Promise<any>;
9
+ uploadFile(s3UserId: string, bucketId: string, key: string, fields: string[]): Promise<any>;
10
+ updateAclPermissionFile(s3UserId: string, bucketId: string, key: string, isPublic: boolean, fields: string[]): Promise<any>;
11
+ renameFile(s3UserId: string, bucketId: string, key: string, fileNewName: boolean, fields: string[]): Promise<any>;
12
+ shareLinkFileByTime(s3UserId: string, bucketId: string, key: string, quantityHour: number): Promise<any>;
13
+ copyFile(s3UserId: string, bucketId: string, srcFileKey: string, dstFileKey: string, fields: string[]): Promise<any>;
14
+ moveFile(s3UserId: string, bucketId: string, srcFileKey: string, dstFileKey: string, fields: string[]): Promise<any>;
15
+ removeFile(s3UserId: string, bucketId: string, keys: string[], fields: string[]): Promise<any>;
16
+ createFolder(s3UserId: string, bucketId: string, folderName: string, key: string, fields: string[]): Promise<any>;
17
+ removeFolder(s3UserId: string, bucketId: string, key: string, fields: string[]): Promise<any>;
18
+ }
@@ -0,0 +1,259 @@
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.StorageS3Service = void 0;
13
+ const mutations_1 = require("../../graphql/storage_s3/mutations");
14
+ const queries_1 = require("../../graphql/storage_s3/queries");
15
+ const serviceSDK_1 = require("../serviceSDK");
16
+ class StorageS3Service extends serviceSDK_1.Service {
17
+ constructor(endpoint, orgId, storeId) {
18
+ super(endpoint, orgId, storeId);
19
+ }
20
+ getListS3UserByServiceId(serviceId, fields) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const query = (0, queries_1.GET_LIST_S3_USER_BY_SERVICE_ID)(fields);
23
+ const variables = {
24
+ serviceId,
25
+ };
26
+ try {
27
+ const response = yield this.graphqlQueryV2(query, variables);
28
+ return response.getListS3UserByServiceId;
29
+ }
30
+ catch (error) {
31
+ console.log(`Error in getListS3UserByServiceId: ${error}`);
32
+ throw error;
33
+ }
34
+ });
35
+ }
36
+ getListBucketByS3UserId(s3UserId, fields) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const query = (0, queries_1.GET_LIST_BUCKET_BY_S3_USER_ID)(fields);
39
+ const variables = {
40
+ s3UserId,
41
+ };
42
+ try {
43
+ const response = yield this.graphqlQueryV2(query, variables);
44
+ return response.getListBucketByS3UserId;
45
+ }
46
+ catch (error) {
47
+ console.log(`Error in getListBucketByS3UserId: ${error}`);
48
+ throw error;
49
+ }
50
+ });
51
+ }
52
+ getListObject(s3UserId, bucketId, key, fields) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const query = (0, queries_1.GET_LIST_OBJECT)(fields);
55
+ const variables = {
56
+ s3UserId,
57
+ bucketId,
58
+ key,
59
+ };
60
+ try {
61
+ const response = yield this.graphqlQueryV2(query, variables);
62
+ return response.getListObject;
63
+ }
64
+ catch (error) {
65
+ console.log(`Error in getListObject: ${error}`);
66
+ throw error;
67
+ }
68
+ });
69
+ }
70
+ uploadFolder(userId, bucketId, fileInfo, basePrefix, fields) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const mutation = (0, mutations_1.UPLOAD_FOLDER)(fields);
73
+ const variables = {
74
+ userId,
75
+ bucketId,
76
+ fileInfo,
77
+ basePrefix,
78
+ };
79
+ console.log("variables", variables);
80
+ try {
81
+ const response = yield this.graphqlMutationV2(mutation, variables);
82
+ return response.uploadFolder;
83
+ }
84
+ catch (error) {
85
+ console.log(`Error in uploadFolder: ${error}`);
86
+ throw error;
87
+ }
88
+ });
89
+ }
90
+ uploadFile(s3UserId, bucketId, key, fields) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const query = (0, queries_1.GET_LIST_OBJECT)(fields);
93
+ const variables = {
94
+ s3UserId,
95
+ bucketId,
96
+ key,
97
+ };
98
+ try {
99
+ const response = yield this.graphqlQueryV2(query, variables);
100
+ return response.getListObject;
101
+ }
102
+ catch (error) {
103
+ console.log(`Error in getListObject: ${error}`);
104
+ throw error;
105
+ }
106
+ });
107
+ }
108
+ updateAclPermissionFile(s3UserId, bucketId, key, isPublic, fields) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const query = (0, mutations_1.UPDATE_ACL_PERMISSION_FILE)(fields);
111
+ const variables = {
112
+ s3UserId,
113
+ bucketId,
114
+ key,
115
+ isPublic,
116
+ };
117
+ try {
118
+ const response = yield this.graphqlQueryV2(query, variables);
119
+ return response.updateAclPermissionFile;
120
+ }
121
+ catch (error) {
122
+ console.log(`Error in updateAclPermissionFile: ${error}`);
123
+ throw error;
124
+ }
125
+ });
126
+ }
127
+ renameFile(s3UserId, bucketId, key, fileNewName, fields) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const mutation = (0, mutations_1.RENAME_FILE)(fields);
130
+ const variables = {
131
+ s3UserId,
132
+ bucketId,
133
+ key,
134
+ fileNewName,
135
+ };
136
+ try {
137
+ const response = yield this.graphqlMutationV2(mutation, variables);
138
+ return response.renameFile;
139
+ }
140
+ catch (error) {
141
+ console.log(`Error in renameFile: ${error}`);
142
+ throw error;
143
+ }
144
+ });
145
+ }
146
+ shareLinkFileByTime(s3UserId, bucketId, key, quantityHour) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const mutation = mutations_1.SHARE_LINK_FILE_BY_TIME;
149
+ const variables = {
150
+ s3UserId,
151
+ bucketId,
152
+ key,
153
+ quantityHour,
154
+ };
155
+ try {
156
+ const response = yield this.graphqlMutationV2(mutation, variables);
157
+ return response.shareLinkFileByTime;
158
+ }
159
+ catch (error) {
160
+ console.log(`Error in shareLinkFileByTime: ${error}`);
161
+ throw error;
162
+ }
163
+ });
164
+ }
165
+ copyFile(s3UserId, bucketId, srcFileKey, dstFileKey, fields) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const mutation = (0, mutations_1.COPY_FILE)(fields);
168
+ const variables = {
169
+ s3UserId,
170
+ bucketId,
171
+ srcFileKey,
172
+ dstFileKey,
173
+ };
174
+ try {
175
+ const response = yield this.graphqlMutationV2(mutation, variables);
176
+ return response.copyFile;
177
+ }
178
+ catch (error) {
179
+ console.log(`Error in copyFile: ${error}`);
180
+ throw error;
181
+ }
182
+ });
183
+ }
184
+ moveFile(s3UserId, bucketId, srcFileKey, dstFileKey, fields) {
185
+ return __awaiter(this, void 0, void 0, function* () {
186
+ const mutation = (0, mutations_1.MOVE_FILE)(fields);
187
+ const variables = {
188
+ s3UserId,
189
+ bucketId,
190
+ srcFileKey,
191
+ dstFileKey,
192
+ };
193
+ try {
194
+ const response = yield this.graphqlMutationV2(mutation, variables);
195
+ return response.moveFile;
196
+ }
197
+ catch (error) {
198
+ console.log(`Error in moveFile: ${error}`);
199
+ throw error;
200
+ }
201
+ });
202
+ }
203
+ removeFile(s3UserId, bucketId, keys, fields) {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ const mutation = (0, mutations_1.REMOVE_FILE)(fields);
206
+ const variables = {
207
+ s3UserId,
208
+ bucketId,
209
+ keys,
210
+ };
211
+ try {
212
+ const response = yield this.graphqlMutationV2(mutation, variables);
213
+ return response.removeFile;
214
+ }
215
+ catch (error) {
216
+ console.log(`Error in removeFile: ${error}`);
217
+ throw error;
218
+ }
219
+ });
220
+ }
221
+ createFolder(s3UserId, bucketId, folderName, key, fields) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ const mutation = (0, mutations_1.CREATE_FOLDER)(fields);
224
+ const variables = {
225
+ s3UserId,
226
+ bucketId,
227
+ folderName,
228
+ key
229
+ };
230
+ try {
231
+ const response = yield this.graphqlMutationV2(mutation, variables);
232
+ return response.createFolder;
233
+ }
234
+ catch (error) {
235
+ console.log(`Error in createFolder: ${error}`);
236
+ throw error;
237
+ }
238
+ });
239
+ }
240
+ removeFolder(s3UserId, bucketId, key, fields) {
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ const mutation = (0, mutations_1.REMOVE_FOLDER)(fields);
243
+ const variables = {
244
+ s3UserId,
245
+ bucketId,
246
+ key,
247
+ };
248
+ try {
249
+ const response = yield this.graphqlMutationV2(mutation, variables);
250
+ return response.removeFolder;
251
+ }
252
+ catch (error) {
253
+ console.log(`Error in removeFolder: ${error}`);
254
+ throw error;
255
+ }
256
+ });
257
+ }
258
+ }
259
+ exports.StorageS3Service = StorageS3Service;
@@ -0,0 +1,6 @@
1
+ export interface FileInfoInput {
2
+ name: string;
3
+ relativePath: string;
4
+ size: number;
5
+ contentType: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/service-js-client",
3
- "version": "1.19.1",
3
+ "version": "1.20.0",
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;