@pelatform/storage 1.0.5 → 1.0.6

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,5 +1,11 @@
1
1
  // src/helpers.ts
2
2
  import { lookup } from "mime-types";
3
+ function getSupabasePublicUrl(key) {
4
+ const bucket = process.env.PELATFORM_S3_BUCKET || "";
5
+ const endpoint = process.env.PELATFORM_S3_ENDPOINT || "";
6
+ const publicUrl = endpoint.replace(/\.storage/, "").replace(/\/storage\/v1\/s3$/, "");
7
+ return `${publicUrl}/storage/v1/object/public/${bucket}/${key}?v=${Date.now()}`;
8
+ }
3
9
  function generateFileKey(originalName, prefix) {
4
10
  const timestamp = Date.now();
5
11
  const random = Math.random().toString(36).substring(2, 8);
@@ -378,6 +384,7 @@ function detectFileTypeFromContent(buffer) {
378
384
  }
379
385
 
380
386
  export {
387
+ getSupabasePublicUrl,
381
388
  generateFileKey,
382
389
  getMimeType,
383
390
  validateFileSize,
package/dist/helpers.d.ts CHANGED
@@ -2,6 +2,19 @@
2
2
  * Storage helper utilities
3
3
  * Provides utility functions for file operations, MIME type detection, and path manipulation
4
4
  */
5
+ /**
6
+ * Generate public URL for a storage key using environment variables
7
+ * @param key The storage key/path
8
+ * @returns Constructed public URL with timestamp versioning
9
+ * @public
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Requires env vars: PELATFORM_S3_BUCKET, PELATFORM_S3_ENDPOINT
14
+ * const url = getSupabasePublicUrl('folder/image.png');
15
+ * ```
16
+ */
17
+ declare function getSupabasePublicUrl(key: string): string;
5
18
  /**
6
19
  * Generate a unique file key with timestamp and random string
7
20
  * @param originalName Original file name
@@ -759,4 +772,4 @@ declare function validateBatchFiles(files: File[], options: {
759
772
  */
760
773
  declare function detectFileTypeFromContent(buffer: Buffer): string;
761
774
 
762
- export { base64ToBuffer, bufferToBase64, buildPublicUrl, detectFileTypeFromContent, extractS3Info, fileToBuffer, formatFileSize, generateBatchKeys, generateCacheControl, generateFileHash, generateFileKey, generateUniqueKey, getContentDisposition, getFileExtension, getFileInfo, getFileName, getMimeType, getParentPath, isAudioFile, isDocumentFile, isImageFile, isVideoFile, joinPath, normalizePath, parseS3Url, sanitizeFileName, validateBatchFiles, validateBucketName, validateFileSize, validateFileType, validateS3Config, validateS3Key };
775
+ export { base64ToBuffer, bufferToBase64, buildPublicUrl, detectFileTypeFromContent, extractS3Info, fileToBuffer, formatFileSize, generateBatchKeys, generateCacheControl, generateFileHash, generateFileKey, generateUniqueKey, getContentDisposition, getFileExtension, getFileInfo, getFileName, getMimeType, getParentPath, getSupabasePublicUrl, isAudioFile, isDocumentFile, isImageFile, isVideoFile, joinPath, normalizePath, parseS3Url, sanitizeFileName, validateBatchFiles, validateBucketName, validateFileSize, validateFileType, validateS3Config, validateS3Key };
package/dist/helpers.js CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  getFileName,
18
18
  getMimeType,
19
19
  getParentPath,
20
+ getSupabasePublicUrl,
20
21
  isAudioFile,
21
22
  isDocumentFile,
22
23
  isImageFile,
@@ -31,7 +32,7 @@ import {
31
32
  validateFileType,
32
33
  validateS3Config,
33
34
  validateS3Key
34
- } from "./chunk-KJMGBTTL.js";
35
+ } from "./chunk-CT5YOIGU.js";
35
36
  export {
36
37
  base64ToBuffer,
37
38
  bufferToBase64,
@@ -51,6 +52,7 @@ export {
51
52
  getFileName,
52
53
  getMimeType,
53
54
  getParentPath,
55
+ getSupabasePublicUrl,
54
56
  isAudioFile,
55
57
  isDocumentFile,
56
58
  isImageFile,
package/dist/s3.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StorageInterface, v as S3Config, U as UploadOptions, a as UploadResult, D as DownloadOptions, b as DownloadResult, c as DeleteOptions, d as DeleteResult, B as BatchDeleteOptions, e as BatchDeleteResult, L as ListOptions, f as ListResult, E as ExistsResult, g as CopyOptions, h as CopyResult, M as MoveOptions, i as MoveResult, j as DuplicateOptions, k as DuplicateResult, P as PresignedUrlOptions, l as PresignedUrlResult, m as CreateFolderOptions, n as CreateFolderResult, o as DeleteFolderOptions, p as DeleteFolderResult, q as ListFoldersOptions, r as ListFoldersResult, F as FolderExistsResult, R as RenameFolderOptions, s as RenameFolderResult, t as CopyFolderOptions, u as CopyFolderResult } from './storage-interface-CoYx1E3B.js';
1
+ import { S as StorageInterface, v as S3Config, U as UploadOptions, a as UploadResult, D as DownloadOptions, b as DownloadResult, c as DeleteOptions, d as DeleteResult, B as BatchDeleteOptions, e as BatchDeleteResult, L as ListOptions, f as ListResult, E as ExistsResult, g as CopyOptions, h as CopyResult, M as MoveOptions, i as MoveResult, j as DuplicateOptions, k as DuplicateResult, P as PresignedUrlOptions, l as PresignedUrlResult, m as CreateFolderOptions, n as CreateFolderResult, o as DeleteFolderOptions, p as DeleteFolderResult, q as ListFoldersOptions, r as ListFoldersResult, F as FolderExistsResult, R as RenameFolderOptions, s as RenameFolderResult, t as CopyFolderOptions, u as CopyFolderResult, x as S3ProviderType } from './storage-interface-CoYx1E3B.js';
2
2
 
3
3
  /**
4
4
  * S3 storage service implementation
@@ -55,6 +55,7 @@ declare class S3Service implements StorageInterface {
55
55
  copyFolderPath(sourcePath: string, destinationPath: string, recursive?: boolean): Promise<CopyFolderResult>;
56
56
  }
57
57
 
58
+ declare const S3_PROVIDER: S3ProviderType;
58
59
  /**
59
60
  * Create S3 service using environment variables or manual configuration
60
61
  * @param config Optional S3 configuration. If not provided, loads from environment variables
@@ -105,4 +106,4 @@ declare class S3Service implements StorageInterface {
105
106
  declare function createS3(): S3Service;
106
107
  declare function createS3(config: S3Config): S3Service;
107
108
 
108
- export { S3Service, createS3 };
109
+ export { S3Service, S3_PROVIDER, createS3 };
package/dist/s3.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildPublicUrl,
3
3
  getMimeType
4
- } from "./chunk-KJMGBTTL.js";
4
+ } from "./chunk-CT5YOIGU.js";
5
5
  import {
6
6
  loadS3Config
7
7
  } from "./chunk-ZTZZCC52.js";
@@ -786,6 +786,7 @@ var S3Service = class {
786
786
  };
787
787
 
788
788
  // src/s3.ts
789
+ var S3_PROVIDER = process.env.PELATFORM_S3_PROVIDER;
789
790
  function createS3(config) {
790
791
  if (config) {
791
792
  return new S3Service(config);
@@ -795,5 +796,6 @@ function createS3(config) {
795
796
  }
796
797
  export {
797
798
  S3Service,
799
+ S3_PROVIDER,
798
800
  createS3
799
801
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pelatform/storage",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Storage utilities for SaaS applications.",
5
5
  "author": "Pelatform",
6
6
  "license": "MIT",
@@ -28,10 +28,13 @@
28
28
  },
29
29
  "scripts": {
30
30
  "clean": "rimraf dist",
31
- "clean:all": "rimraf .turbo dist node_modules",
31
+ "clean:all": "rimraf .turbo coverage dist node_modules",
32
32
  "dev": "tsup --watch",
33
33
  "build": "tsup",
34
- "types:check": "tsc --noEmit"
34
+ "types:check": "tsc --noEmit",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest",
37
+ "test:coverage": "vitest run --coverage"
35
38
  },
36
39
  "repository": "github:devpelatform/toolkits",
37
40
  "homepage": "https://github.com/devpelatform/toolkits",
@@ -54,11 +57,11 @@
54
57
  "mime-types": "^3.0.2"
55
58
  },
56
59
  "devDependencies": {
57
- "@aws-sdk/client-s3": "^3.948.0",
58
- "@aws-sdk/s3-request-presigner": "^3.948.0",
60
+ "@aws-sdk/client-s3": "^3.953.0",
61
+ "@aws-sdk/s3-request-presigner": "^3.953.0",
59
62
  "@pelatform/tsconfig": "0.1.3",
60
63
  "@types/mime-types": "^3.0.1",
61
- "@types/node": "^25.0.1",
64
+ "@types/node": "^25.0.3",
62
65
  "cloudinary": "^2.8.0",
63
66
  "tsup": "^8.5.1",
64
67
  "typescript": "^5.9.3"