@bmostickit/common 1.0.20 → 1.0.21

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,6 +1,9 @@
1
- export declare const generateSignedUrl: (publicId: string, resourceType?: "image" | "raw" | "video") => {
2
- width: number;
3
- url: string;
4
- }[] | {
5
- url: string;
6
- }[];
1
+ interface SignedUrlOptions {
2
+ width?: number;
3
+ height?: number;
4
+ crop?: 'limit' | 'fill' | 'scale';
5
+ resourceType?: 'image' | 'raw' | 'video';
6
+ expiresInSeconds?: number;
7
+ }
8
+ export declare const generateSignedMediaUrl: (publicId: string, { width, height, crop, resourceType, expiresInSeconds, }?: SignedUrlOptions) => string;
9
+ export {};
@@ -1,28 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateSignedUrl = void 0;
3
+ exports.generateSignedMediaUrl = void 0;
4
4
  const cloudinary_1 = require("./cloudinary");
5
- const generateSignedUrl = (publicId, resourceType = 'image') => {
6
- if (resourceType === 'image') {
7
- const widths = [300, 600, 900];
8
- const urls = widths.map((w) => {
9
- const url = cloudinary_1.cloudinary.url(publicId, {
10
- secure: true,
11
- sign_url: true,
12
- transformation: [{ width: w, height: 550, crop: 'limit ' }],
13
- resource_type: resourceType,
14
- });
15
- return { width: w, url };
16
- });
17
- return urls;
18
- }
19
- else {
20
- const url = cloudinary_1.cloudinary.url(publicId, {
21
- secure: true,
22
- sign_url: true,
23
- resource_type: resourceType
24
- });
25
- return [{ url }];
26
- }
5
+ const generateSignedMediaUrl = (publicId, { width, height, crop = 'limit', resourceType = 'image', expiresInSeconds = 3600, // 1 hour
6
+ } = {}) => {
7
+ const timestamp = Math.floor(Date.now() / 1000) + expiresInSeconds;
8
+ const transformation = width || height
9
+ ? [{ width, height, crop }]
10
+ : undefined;
11
+ return cloudinary_1.cloudinary.url(publicId, {
12
+ secure: true,
13
+ sign_url: true,
14
+ resource_type: resourceType,
15
+ transformation,
16
+ timestamp,
17
+ });
27
18
  };
28
- exports.generateSignedUrl = generateSignedUrl;
19
+ exports.generateSignedMediaUrl = generateSignedMediaUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bmostickit/common",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",