corebasic 1.0.45 → 1.0.47
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/libs/features.js +2 -1
- package/libs/utils.js +19 -0
- package/package.json +1 -1
package/libs/features.js
CHANGED
|
@@ -87,7 +87,8 @@ const commandAction = async (req, res, feature) => {
|
|
|
87
87
|
let txn = req.body.txn ?? Util.uid()
|
|
88
88
|
req.body.data._id = req.body.data._id ?? txn
|
|
89
89
|
try {
|
|
90
|
-
|
|
90
|
+
let {data, feature, app, user, client, version} = req.body
|
|
91
|
+
await Kafka.send(`Features.${feature.topic}`, { data, feature, app, user, client, version, txn, id: _id, date: new Date().getTime() }, _id)
|
|
91
92
|
|
|
92
93
|
} catch {
|
|
93
94
|
throw {status: 500, message: "Failed to queue the transaction"}
|
package/libs/utils.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import * as ObjectId from './ObjectId.js'
|
|
2
|
+
|
|
3
|
+
// Parse JSON file: fileToJson
|
|
2
4
|
import {readFile} from 'fs/promises';
|
|
3
5
|
import 'jsonminify'
|
|
4
6
|
|
|
7
|
+
// S3 Object Storage
|
|
8
|
+
import { S3Client, ListBucketsCommand, ListObjectsV2Command, GetObjectCommand, PutObjectCommand, CreateBucketCommand, DeleteObjectCommand } from '@aws-sdk/client-s3'
|
|
9
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
|
|
10
|
+
let bucketName = process.env.APP_DEPLOYMENT_NAME ?? ((global?.app?.name ?? "app") + '-dev')
|
|
11
|
+
let _ = (async () => { try { const data = await S3.send(new CreateBucketCommand({ Bucket: bucketName })) } catch { } })() // Create Bucket
|
|
12
|
+
|
|
13
|
+
|
|
5
14
|
export let pipeline = { execute: execute }
|
|
6
15
|
|
|
7
16
|
|
|
@@ -164,3 +173,13 @@ function startPipeline(pipeline, index, data, errfn) {
|
|
|
164
173
|
pipeline[index](data).then(data => startPipeline(pipeline, index + 1, data)).catch(err => { if (errfn) errfn(err) } )
|
|
165
174
|
}
|
|
166
175
|
|
|
176
|
+
// -----------------
|
|
177
|
+
// S3 Object Storage
|
|
178
|
+
// -----------------
|
|
179
|
+
|
|
180
|
+
export async function getUrl(path, expiry = 3600) { // expiry default: 1 Hour
|
|
181
|
+
return await getSignedUrl(S3, new GetObjectCommand({ Bucket: bucketName, Key: path }), { expiresIn: expiry })
|
|
182
|
+
}
|
|
183
|
+
export async function putUrl(path, expiry = 3600) { // expiry default: 1 Hour
|
|
184
|
+
return await getSignedUrl(S3, new PutObjectCommand({ Bucket: bucketName, Key: path }), { expiresIn: expiry })
|
|
185
|
+
}
|