@sanvika/cloudinary 0.2.4 → 0.3.1
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/dist/index.js +42 -3
- package/package.json +6 -10
package/dist/index.js
CHANGED
|
@@ -186,10 +186,18 @@ var _appName = null;
|
|
|
186
186
|
var _configured = false;
|
|
187
187
|
var _cloudinary = null;
|
|
188
188
|
async function loadLegacyCloudinary() {
|
|
189
|
+
var _a;
|
|
189
190
|
if (_cloudinary) return _cloudinary;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
try {
|
|
192
|
+
const dynamicImport = new Function("m", "return import(m)");
|
|
193
|
+
const mod = await dynamicImport("cloudinary");
|
|
194
|
+
_cloudinary = mod.v2 || ((_a = mod.default) == null ? void 0 : _a.v2) || mod.default || mod;
|
|
195
|
+
return _cloudinary;
|
|
196
|
+
} catch (err) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
"@sanvika/cloudinary: legacy direct mode requires the 'cloudinary' npm package to be installed. Either install it (pnpm add cloudinary) OR (recommended) use gateway mode by setting CLOUDINARY_GATEWAY_URL + CLOUDINARY_TOKEN. Original error: " + err.message
|
|
199
|
+
);
|
|
200
|
+
}
|
|
193
201
|
}
|
|
194
202
|
async function configureSanvikaCloudinary({ appName, cloudName, apiKey, apiSecret } = {}) {
|
|
195
203
|
const resolvedApp = appName || process.env.CLOUDINARY_APP_NAME;
|
|
@@ -411,6 +419,36 @@ async function deleteImages(urls, options = {}) {
|
|
|
411
419
|
const failed = allResults.filter((r) => !r.success).length;
|
|
412
420
|
return { success: failed === 0, total: urls.length, processed: allResults.length, successful, failed };
|
|
413
421
|
}
|
|
422
|
+
async function renameImage(fromPublicId, toPublicId, options = {}) {
|
|
423
|
+
await ensureConfigured();
|
|
424
|
+
const { overwrite = true, resourceType = "image" } = options;
|
|
425
|
+
if (!fromPublicId || !toPublicId) {
|
|
426
|
+
throw new CloudinaryError("fromPublicId and toPublicId are required", "renameImage");
|
|
427
|
+
}
|
|
428
|
+
if (isProxyMode()) {
|
|
429
|
+
const result2 = await withRetry(
|
|
430
|
+
() => gatewayPost("/api/v1/rename", {
|
|
431
|
+
fromPublicId,
|
|
432
|
+
toPublicId,
|
|
433
|
+
options: { overwrite, resourceType }
|
|
434
|
+
}),
|
|
435
|
+
{ operationName: "renameImage", maxAttempts: 2 }
|
|
436
|
+
);
|
|
437
|
+
return {
|
|
438
|
+
url: (result2 == null ? void 0 : result2.secure_url) || (result2 == null ? void 0 : result2.url) || "",
|
|
439
|
+
publicId: (result2 == null ? void 0 : result2.public_id) || toPublicId
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
const cloudinary = await loadLegacyCloudinary();
|
|
443
|
+
const result = await withRetry(
|
|
444
|
+
() => cloudinary.uploader.rename(fromPublicId, toPublicId, {
|
|
445
|
+
overwrite,
|
|
446
|
+
resource_type: resourceType
|
|
447
|
+
}),
|
|
448
|
+
{ operationName: "renameImage", maxAttempts: 2 }
|
|
449
|
+
);
|
|
450
|
+
return { url: result.secure_url, publicId: result.public_id };
|
|
451
|
+
}
|
|
414
452
|
async function pingCloudinary() {
|
|
415
453
|
await ensureConfigured();
|
|
416
454
|
if (isProxyMode()) return gatewayGet("/api/v1/ping");
|
|
@@ -634,6 +672,7 @@ export {
|
|
|
634
672
|
isRetriableError,
|
|
635
673
|
normalizeFolderPath,
|
|
636
674
|
pingCloudinary,
|
|
675
|
+
renameImage,
|
|
637
676
|
runCloudinaryDiagnostics,
|
|
638
677
|
splitFileName,
|
|
639
678
|
testCloudinaryWebhookSignature,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanvika/cloudinary",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Centralized Cloudinary SDK for the Sanvika ecosystem — proxy gateway mode (zero credentials)
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Centralized Cloudinary SDK for the Sanvika ecosystem — proxy gateway mode (zero credentials). Legacy direct mode requires consumer to install 'cloudinary' npm package (not recommended).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -12,16 +12,9 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsup",
|
|
17
|
-
"prepublishOnly": "npm run build"
|
|
18
|
-
},
|
|
19
15
|
"devDependencies": {
|
|
20
16
|
"tsup": "^8.5.1"
|
|
21
17
|
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"cloudinary": "^2.5.0"
|
|
24
|
-
},
|
|
25
18
|
"keywords": [
|
|
26
19
|
"cloudinary",
|
|
27
20
|
"sanvika",
|
|
@@ -55,5 +48,8 @@
|
|
|
55
48
|
"type": "git",
|
|
56
49
|
"url": "https://github.com/sanvikaproduction/sanvika-cloudinary",
|
|
57
50
|
"directory": "packages/sanvika-cloudinary-sdk"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup"
|
|
58
54
|
}
|
|
59
|
-
}
|
|
55
|
+
}
|