corebasic 1.0.44 → 1.0.46

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/auth.js CHANGED
@@ -53,7 +53,7 @@ async function attemptLogin(req, res) {
53
53
  throw {...errMessage, mode: 'verify', info: "Invalid/Expired OTP"}
54
54
  } else { // generate login
55
55
  let otp = phone === '0123456789' ? '1234' : otpGenerator.generate(4, { upperCaseAlphabets: false, specialChars: false, digital: true, lowerCaseAlphabets: false });
56
- if (phone === '0123456789' || await sendOtp(phone, otp)) {
56
+ if (phone === '0123456789' || await sendOtp(phone, otp, req.body.app)) {
57
57
  let userId = req.body.userId ?? Utils.uid()
58
58
  let now = Utils.now().toISOString()
59
59
  let data = req.body.data ?? {}
@@ -66,10 +66,10 @@ async function attemptLogin(req, res) {
66
66
  }
67
67
 
68
68
 
69
- async function sendOtp(phone, otp) {
69
+ async function sendOtp(phone, otp, app) {
70
70
  try {
71
- let link = process.env.SMS_API + phone + "/" + otp
72
- await axios.get(link)
71
+ let api = process.env.SMS_API.replace(':phone', phone).replace(':otp', otp).replace(':app', app ?? 'app')
72
+ await axios.get(api)
73
73
  return true
74
74
  } catch {
75
75
  return false
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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.44",
4
+ "version": "1.0.46",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {