lesgo 2.1.10 → 3.0.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.
@@ -89,7 +89,7 @@ const httpResponseMiddleware = (opts = {}) => {
89
89
  });
90
90
  const httpResponseMiddlewareOnError = request =>
91
91
  __awaiter(void 0, void 0, void 0, function* () {
92
- var _b;
92
+ var _a;
93
93
  const error = request.error;
94
94
  if (error.extra && error.extra.statusCode) {
95
95
  delete error.extra.statusCode;
@@ -98,9 +98,9 @@ const httpResponseMiddleware = (opts = {}) => {
98
98
  statusCode: error.statusCode || 500,
99
99
  headers: Object.assign(
100
100
  Object.assign({}, options.headers),
101
- (_b = request.response) === null || _b === void 0
101
+ (_a = request.response) === null || _a === void 0
102
102
  ? void 0
103
- : _b.headers
103
+ : _a.headers
104
104
  ),
105
105
  body: Object.assign(
106
106
  {
@@ -3,6 +3,7 @@ import { jwt as jwtConfig } from '../../config';
3
3
  import { generateUid } from '../../utils';
4
4
  import getJwtSecret from './getJwtSecret';
5
5
  const sign = (payload, secret, opts) => {
6
+ var _a;
6
7
  const jwtSecret = getJwtSecret({
7
8
  secret,
8
9
  keyid: opts === null || opts === void 0 ? void 0 : opts.keyid,
@@ -12,8 +13,10 @@ const sign = (payload, secret, opts) => {
12
13
  (opts === null || opts === void 0 ? void 0 : opts.algorithm) ||
13
14
  jwtConfig.algorithm,
14
15
  expiresIn:
15
- (opts === null || opts === void 0 ? void 0 : opts.expiresIn) ||
16
- jwtConfig.expiresIn,
16
+ (_a = opts === null || opts === void 0 ? void 0 : opts.expiresIn) !==
17
+ null && _a !== void 0
18
+ ? _a
19
+ : jwtConfig.expiresIn,
17
20
  issuer:
18
21
  (opts === null || opts === void 0 ? void 0 : opts.issuer) ||
19
22
  jwtConfig.issuer,
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { GetObjectCommandInput } from '@aws-sdk/client-s3';
3
2
  import { ClientOptions } from '../../types/aws';
4
3
  export interface GetObjectOptions extends Partial<Omit<GetObjectCommandInput, 'Key' | 'Bucket'>> {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { PutObjectCommandInput } from '@aws-sdk/client-s3';
3
2
  import { ClientOptions } from '../../types/aws';
4
3
  export interface PutObjectOptions extends Partial<Omit<PutObjectCommandInput, 'Key' | 'Bucket'>> {
@@ -26,5 +26,5 @@ import { ClientOptions } from '../../../types/aws';
26
26
  * await client.set(key, value);
27
27
  * ```
28
28
  */
29
- declare const getClient: (clientOpts?: ClientOptions) => Promise<import("ioredis/built/cluster").default>;
29
+ declare const getClient: (clientOpts?: ClientOptions) => Promise<import("ioredis").Cluster>;
30
30
  export default getClient;
@@ -8,3 +8,4 @@ export { default as isEmpty } from './isEmpty';
8
8
  export { default as logger } from './logger';
9
9
  export { default as validateFields } from './validateFields';
10
10
  export { default as safePromise } from './safePromise';
11
+ export { default as typeSafePromise } from './typeSafePromise';
@@ -8,3 +8,4 @@ export { default as isEmpty } from './isEmpty';
8
8
  export { default as logger } from './logger';
9
9
  export { default as validateFields } from './validateFields';
10
10
  export { default as safePromise } from './safePromise';
11
+ export { default as typeSafePromise } from './typeSafePromise';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { GetObjectOptions } from '../../services/S3Service/getObject';
3
2
  import { ClientOptions } from '../../types/aws';
4
3
  /**
@@ -9,5 +8,5 @@ import { ClientOptions } from '../../types/aws';
9
8
  * @param clientOpts - Optional client options for the S3 client.
10
9
  * @returns A Promise that resolves to the body of the retrieved object.
11
10
  */
12
- declare const getObject: (key: string, opts?: GetObjectOptions, clientOpts?: ClientOptions) => Promise<Buffer>;
11
+ declare const getObject: (key: string, opts?: GetObjectOptions, clientOpts?: ClientOptions) => Promise<Buffer<ArrayBufferLike>>;
13
12
  export default getObject;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { PutObjectOptions } from '../../services/S3Service/putObject';
3
2
  import { ClientOptions } from '../../types/aws';
4
3
  declare const putObject: (key: string, file: Buffer | Uint8Array | Blob | string, opts?: PutObjectOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
2
+ * @deprecated use typeSafePromise instead
3
3
  * @param promise
4
4
  * @returns [err, res]
5
5
  * @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
@@ -32,7 +32,7 @@ var __awaiter =
32
32
  });
33
33
  };
34
34
  /**
35
- *
35
+ * @deprecated use typeSafePromise instead
36
36
  * @param promise
37
37
  * @returns [err, res]
38
38
  * @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
@@ -0,0 +1,29 @@
1
+ /**
2
+ *
3
+ * @param promise
4
+ * @returns {success: true, data: TData} | {success: false, error: TError}
5
+ * @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { typeSafePromise } from 'lesgo/utils';
10
+ *
11
+ * const res = await typeSafePromise(fetch('https://example.com/'));
12
+ * if (res.success) {
13
+ * console.log(res.data);
14
+ * } else {
15
+ * console.error(res.error);
16
+ * }
17
+ * ```
18
+ */
19
+ type ReturnTypeSafePromise<TData, TError> = {
20
+ success: true;
21
+ data: TData;
22
+ error?: undefined;
23
+ } | {
24
+ success: false;
25
+ data?: undefined;
26
+ error: TError;
27
+ };
28
+ declare const typeSafePromise: <TData, TError = Error>(promise: Promise<TData>) => Promise<ReturnTypeSafePromise<TData, TError>>;
29
+ export default typeSafePromise;
@@ -0,0 +1,49 @@
1
+ var __awaiter =
2
+ (this && this.__awaiter) ||
3
+ function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P
6
+ ? value
7
+ : new P(function (resolve) {
8
+ resolve(value);
9
+ });
10
+ }
11
+ return new (P || (P = Promise))(function (resolve, reject) {
12
+ function fulfilled(value) {
13
+ try {
14
+ step(generator.next(value));
15
+ } catch (e) {
16
+ reject(e);
17
+ }
18
+ }
19
+ function rejected(value) {
20
+ try {
21
+ step(generator['throw'](value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ }
26
+ function step(result) {
27
+ result.done
28
+ ? resolve(result.value)
29
+ : adopt(result.value).then(fulfilled, rejected);
30
+ }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ const typeSafePromise = promise =>
35
+ __awaiter(void 0, void 0, void 0, function* () {
36
+ try {
37
+ const res = yield promise;
38
+ return {
39
+ success: true,
40
+ data: res,
41
+ };
42
+ } catch (err) {
43
+ return {
44
+ success: false,
45
+ error: err,
46
+ };
47
+ }
48
+ });
49
+ export default typeSafePromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lesgo",
3
- "version": "2.1.10",
3
+ "version": "3.0.0",
4
4
  "description": "Core framework for lesgo node.js serverless framework.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -177,7 +177,7 @@
177
177
  },
178
178
  "engineStrict": true,
179
179
  "engines": {
180
- "node": ">=18.0.0"
180
+ "node": ">=20.17.0"
181
181
  },
182
182
  "peerDependencies": {
183
183
  "serverless": "^3.0.0"