@things-factory/attachment-base 4.3.281 → 4.3.344

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.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ATTACHMENT_PATH = exports.AWBSTORAGE = exports.STORAGE = void 0;
3
+ exports.ATTACHMENT_PATH = exports.INVSTORAGE = exports.AWBSTORAGE = exports.STORAGE = void 0;
4
4
  const env_1 = require("@things-factory/env");
5
5
  exports.STORAGE = env_1.config.get('storage');
6
6
  exports.AWBSTORAGE = env_1.config.get('awbFileStorage');
7
+ exports.INVSTORAGE = env_1.config.get('invoiceFileStorage');
7
8
  exports.ATTACHMENT_PATH = env_1.config.get('attachmentPath', 'attachment');
8
9
  //# sourceMappingURL=attachment-const.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attachment-const.js","sourceRoot":"","sources":["../server/attachment-const.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAEjC,QAAA,OAAO,GAAQ,YAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AACpC,QAAA,UAAU,GAAQ,YAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;AAC5C,QAAA,eAAe,GAAW,YAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAA"}
1
+ {"version":3,"file":"attachment-const.js","sourceRoot":"","sources":["../server/attachment-const.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAEjC,QAAA,OAAO,GAAQ,YAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AACpC,QAAA,UAAU,GAAQ,YAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;AAC9C,QAAA,UAAU,GAAQ,YAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;AAChD,QAAA,eAAe,GAAW,YAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAA"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const client_s3_1 = require("@aws-sdk/client-s3");
4
+ const lib_storage_1 = require("@aws-sdk/lib-storage");
5
+ const env_1 = require("@things-factory/env");
6
+ const attachment_const_1 = require("./attachment-const");
7
+ if (attachment_const_1.INVSTORAGE && attachment_const_1.INVSTORAGE.type == 's3') {
8
+ const client = new client_s3_1.S3Client({
9
+ credentials: {
10
+ accessKeyId: attachment_const_1.INVSTORAGE.accessKeyId,
11
+ secretAccessKey: attachment_const_1.INVSTORAGE.secretAccessKey
12
+ },
13
+ region: attachment_const_1.INVSTORAGE.region
14
+ });
15
+ // Upload Invoice File
16
+ attachment_const_1.INVSTORAGE.uploadInvoiceS3 = async ({ stream, filename }) => {
17
+ const upload = new lib_storage_1.Upload({
18
+ client,
19
+ params: {
20
+ Bucket: attachment_const_1.INVSTORAGE.invoiceBucket,
21
+ Key: `${filename}.pdf`,
22
+ Body: stream,
23
+ ContentType: 'application/pdf'
24
+ }
25
+ });
26
+ let result;
27
+ let url;
28
+ try {
29
+ result = (await upload.done());
30
+ url = `https://${attachment_const_1.INVSTORAGE.invoiceBucket}.s3.${attachment_const_1.INVSTORAGE.region}.amazonaws.com/${filename}.pdf`;
31
+ }
32
+ catch (e) {
33
+ console.log(e);
34
+ }
35
+ return {
36
+ result,
37
+ url
38
+ };
39
+ };
40
+ env_1.logger.info('operato-invoice: S3 Bucket Storage is Ready');
41
+ }
42
+ //# sourceMappingURL=invoice-storage-s3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-storage-s3.js","sourceRoot":"","sources":["../server/invoice-storage-s3.ts"],"names":[],"mappings":";;AAAA,kDAA6C;AAC7C,sDAA6C;AAC7C,6CAA4C;AAE5C,yDAA+C;AAE/C,IAAI,6BAAU,IAAI,6BAAU,CAAC,IAAI,IAAI,IAAI,EAAE;IACzC,MAAM,MAAM,GAAG,IAAI,oBAAQ,CAAC;QAC1B,WAAW,EAAE;YACX,WAAW,EAAE,6BAAU,CAAC,WAAW;YACnC,eAAe,EAAE,6BAAU,CAAC,eAAe;SAC5C;QACD,MAAM,EAAE,6BAAU,CAAC,MAAM;KAC1B,CAAC,CAAA;IAEF,sBAAsB;IACtB,6BAAU,CAAC,eAAe,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC1D,MAAM,MAAM,GAAG,IAAI,oBAAM,CAAC;YACxB,MAAM;YACN,MAAM,EAAE;gBACN,MAAM,EAAE,6BAAU,CAAC,aAAa;gBAChC,GAAG,EAAE,GAAG,QAAQ,MAAM;gBACtB,IAAI,EAAE,MAAM;gBACZ,WAAW,EAAE,iBAAiB;aAC/B;SACF,CAAC,CAAA;QAEF,IAAI,MAAM,CAAA;QACV,IAAI,GAAG,CAAA;QACP,IAAI;YACF,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAQ,CAAA;YACrC,GAAG,GAAG,WAAW,6BAAU,CAAC,aAAa,OAAO,6BAAU,CAAC,MAAM,kBAAkB,QAAQ,MAAM,CAAA;SAClG;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;SACf;QAED,OAAO;YACL,MAAM;YACN,GAAG;SACJ,CAAA;IACH,CAAC,CAAA;IAED,YAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAA;CAC3D"}
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./upload-awb"), exports);
18
+ __exportStar(require("./upload-invoice"), exports);
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,mDAAgC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadInvoice = void 0;
4
+ require("../invoice-storage-s3");
5
+ const attachment_const_1 = require("../attachment-const");
6
+ async function uploadInvoice(param) {
7
+ const { content, title } = param;
8
+ let result = await attachment_const_1.INVSTORAGE.uploadInvoiceS3({ stream: content, filename: title });
9
+ return result;
10
+ }
11
+ exports.uploadInvoice = uploadInvoice;
12
+ //# sourceMappingURL=upload-invoice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-invoice.js","sourceRoot":"","sources":["../../server/util/upload-invoice.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,0DAAgD;AAEzC,KAAK,UAAU,aAAa,CAAC,KAAU;IAC1C,MAAM,EAAC,OAAO,EAAE,KAAK,EAAC,GAAG,KAAK,CAAA;IAE9B,IAAI,MAAM,GAAG,MAAM,6BAAU,CAAC,eAAe,CAAC,EAAE,MAAM,EAAG,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;IAEpF,OAAO,MAAM,CAAA;AAEjB,CAAC;AAPD,sCAOC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/attachment-base",
3
- "version": "4.3.281",
3
+ "version": "4.3.344",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -33,5 +33,5 @@
33
33
  "mime": "^2.4.4",
34
34
  "multer": "^1.3.0"
35
35
  },
36
- "gitHead": "188bb788d3bf0de2e9ae82ac0433e8f08b979bfc"
36
+ "gitHead": "3b273a578f2060cafb10611127c7f40e7de20b99"
37
37
  }
@@ -2,4 +2,5 @@ import { config } from '@things-factory/env'
2
2
 
3
3
  export var STORAGE: any = config.get('storage')
4
4
  export var AWBSTORAGE: any = config.get('awbFileStorage')
5
+ export var INVSTORAGE: any = config.get('invoiceFileStorage')
5
6
  export const ATTACHMENT_PATH: string = config.get('attachmentPath', 'attachment')
@@ -0,0 +1,44 @@
1
+ import { S3Client } from '@aws-sdk/client-s3'
2
+ import { Upload } from '@aws-sdk/lib-storage'
3
+ import { logger } from '@things-factory/env'
4
+
5
+ import { INVSTORAGE } from './attachment-const'
6
+
7
+ if (INVSTORAGE && INVSTORAGE.type == 's3') {
8
+ const client = new S3Client({
9
+ credentials: {
10
+ accessKeyId: INVSTORAGE.accessKeyId,
11
+ secretAccessKey: INVSTORAGE.secretAccessKey
12
+ },
13
+ region: INVSTORAGE.region
14
+ })
15
+
16
+ // Upload Invoice File
17
+ INVSTORAGE.uploadInvoiceS3 = async ({ stream, filename }) => {
18
+ const upload = new Upload({
19
+ client,
20
+ params: {
21
+ Bucket: INVSTORAGE.invoiceBucket,
22
+ Key: `${filename}.pdf`,
23
+ Body: stream,
24
+ ContentType: 'application/pdf'
25
+ }
26
+ })
27
+
28
+ let result
29
+ let url
30
+ try {
31
+ result = (await upload.done()) as any
32
+ url = `https://${INVSTORAGE.invoiceBucket}.s3.${INVSTORAGE.region}.amazonaws.com/${filename}.pdf`
33
+ } catch (e) {
34
+ console.log(e)
35
+ }
36
+
37
+ return {
38
+ result,
39
+ url
40
+ }
41
+ }
42
+
43
+ logger.info('operato-invoice: S3 Bucket Storage is Ready')
44
+ }
@@ -1 +1,2 @@
1
- export * from './upload-awb'
1
+ export * from './upload-awb'
2
+ export * from './upload-invoice'
@@ -0,0 +1,11 @@
1
+ import '../invoice-storage-s3'
2
+ import { INVSTORAGE } from '../attachment-const'
3
+
4
+ export async function uploadInvoice(param: any) {
5
+ const {content, title} = param
6
+
7
+ let result = await INVSTORAGE.uploadInvoiceS3({ stream : content, filename: title })
8
+
9
+ return result
10
+
11
+ }