@socket.tech/dl-common 1.0.5 → 1.0.7

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/index.js CHANGED
@@ -1,18 +1,34 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __exportStar =
26
+ (this && this.__exportStar) ||
27
+ function (m, exports) {
28
+ for (var p in m)
29
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
+ __createBinding(exports, m, p);
31
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./models"), exports);
18
34
  __exportStar(require("./services"), exports);
@@ -2,4 +2,10 @@ import { DeploymentMode } from "@socket.tech/dl-core";
2
2
  import { Accounts } from "..";
3
3
  export declare const initS3Client: (region: string) => void;
4
4
  export declare const getFileFromS3: (bucket: string, filePath: string) => Promise<any>;
5
+ export declare const uploadFileToS3: (bucket: string, filePath: string, jsonData: object) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
6
+ export declare const getBucketAndFileName: (deploymentMode: DeploymentMode, account?: Accounts.dl | Accounts.ll) => {
7
+ S3_BUCKET_NAME: string;
8
+ S3_RPC_CONFIG_FILE_PATH: string;
9
+ };
5
10
  export declare const getS3Config: (deploymentMode: DeploymentMode, region?: string, account?: Accounts.dl | Accounts.ll) => Promise<any>;
11
+ export declare const setS3Config: (jsonData: object, deploymentMode: DeploymentMode, region?: string, account?: Accounts.dl | Accounts.ll) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getS3Config = exports.getFileFromS3 = exports.initS3Client = void 0;
3
+ exports.setS3Config = exports.getS3Config = exports.getBucketAndFileName = exports.uploadFileToS3 = exports.getFileFromS3 = exports.initS3Client = void 0;
4
4
  const client_s3_1 = require("@aws-sdk/client-s3");
5
5
  const dl_core_1 = require("@socket.tech/dl-core");
6
6
  const __1 = require("..");
@@ -15,13 +15,10 @@ exports.initS3Client = initS3Client;
15
15
  const getFileFromS3 = async (bucket, filePath) => {
16
16
  var _a;
17
17
  try {
18
- // Create an S3 GET operation command
19
- const getObjectCommand = new client_s3_1.GetObjectCommand({
18
+ const s3Response = await s3Client.send(new client_s3_1.GetObjectCommand({
20
19
  Bucket: bucket,
21
20
  Key: filePath,
22
- });
23
- // Execute the command and get the response
24
- const s3Response = await s3Client.send(getObjectCommand);
21
+ }));
25
22
  const jsonStr = await ((_a = s3Response.Body) === null || _a === void 0 ? void 0 : _a.transformToString());
26
23
  let response;
27
24
  if (jsonStr)
@@ -34,13 +31,40 @@ const getFileFromS3 = async (bucket, filePath) => {
34
31
  }
35
32
  };
36
33
  exports.getFileFromS3 = getFileFromS3;
37
- const getS3Config = async (deploymentMode, region = "us-east-1", account = __1.Accounts.dl) => {
34
+ const uploadFileToS3 = async (bucket, filePath, jsonData) => {
35
+ try {
36
+ const response = await s3Client.send(new client_s3_1.PutObjectCommand({
37
+ Bucket: bucket,
38
+ Key: filePath,
39
+ Body: JSON.stringify(jsonData),
40
+ ContentType: "application/json",
41
+ }));
42
+ return response;
43
+ }
44
+ catch (error) {
45
+ console.error("Error uploading file to S3:", error);
46
+ throw error;
47
+ }
48
+ };
49
+ exports.uploadFileToS3 = uploadFileToS3;
50
+ const getBucketAndFileName = (deploymentMode, account = __1.Accounts.dl) => {
38
51
  const S3_BUCKET_NAME = deploymentMode === dl_core_1.DeploymentMode.SURGE ||
39
52
  deploymentMode == dl_core_1.DeploymentMode.PROD
40
- ? `socket-${account}-prod`
53
+ ? `socket-${account}-${deploymentMode}`
41
54
  : `socket-ll-${deploymentMode}`;
42
55
  const S3_RPC_CONFIG_FILE_PATH = deploymentMode + "RpcConfig.json";
56
+ return { S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH };
57
+ };
58
+ exports.getBucketAndFileName = getBucketAndFileName;
59
+ const getS3Config = async (deploymentMode, region = "us-east-1", account = __1.Accounts.dl) => {
60
+ const { S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH } = (0, exports.getBucketAndFileName)(deploymentMode, account);
43
61
  (0, exports.initS3Client)(region);
44
62
  return await (0, exports.getFileFromS3)(S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH);
45
63
  };
46
64
  exports.getS3Config = getS3Config;
65
+ const setS3Config = async (jsonData, deploymentMode, region = "us-east-1", account = __1.Accounts.dl) => {
66
+ const { S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH } = (0, exports.getBucketAndFileName)(deploymentMode, account);
67
+ (0, exports.initS3Client)(region);
68
+ return await (0, exports.uploadFileToS3)(S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH, jsonData);
69
+ };
70
+ exports.setS3Config = setS3Config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socket.tech/dl-common",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "description": "common utilities for socket data layer.",