@sanvika/cloudinary 0.3.1 → 0.3.2
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 +31 -12
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -108,20 +108,35 @@ var TRANSFORM_PRESETS = {
|
|
|
108
108
|
responsive: { w: "auto", dpr: "auto", q: "auto", f: "auto" }
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
// src/cloudinaryEnv.js
|
|
112
|
+
function resolveCloudinaryClientSecret() {
|
|
113
|
+
return (process.env.CLOUDINARY_CLIENT_SECRET || process.env.CLOUDINARY_TOKEN || "").trim();
|
|
114
|
+
}
|
|
115
|
+
function resolveCloudinaryClientId() {
|
|
116
|
+
return (process.env.CLOUDINARY_CLIENT_ID || process.env.CLOUDINARY_APP_NAME || process.env.PROJECT_NAME || process.env.NEXT_PUBLIC_PROJECT_NAME || "").trim();
|
|
117
|
+
}
|
|
118
|
+
function resolveCloudinaryGatewayUrl() {
|
|
119
|
+
const url = (process.env.CLOUDINARY_GATEWAY_URL || "https://cloudinary.sanvikaproduction.com").trim().replace(/\/+$/, "");
|
|
120
|
+
return url || "https://cloudinary.sanvikaproduction.com";
|
|
121
|
+
}
|
|
122
|
+
function isCloudinaryProxyConfigured() {
|
|
123
|
+
return Boolean(resolveCloudinaryGatewayUrl() && resolveCloudinaryClientSecret());
|
|
124
|
+
}
|
|
125
|
+
|
|
111
126
|
// src/gatewayClient.js
|
|
112
127
|
function isProxyMode() {
|
|
113
|
-
return
|
|
128
|
+
return isCloudinaryProxyConfigured();
|
|
114
129
|
}
|
|
115
130
|
function requireProxyEnv() {
|
|
116
|
-
const base =
|
|
117
|
-
const token =
|
|
131
|
+
const base = resolveCloudinaryGatewayUrl();
|
|
132
|
+
const token = resolveCloudinaryClientSecret();
|
|
118
133
|
if (!base || !token) {
|
|
119
134
|
throw new CloudinaryError(
|
|
120
|
-
"Proxy gateway env missing. Set CLOUDINARY_GATEWAY_URL and
|
|
135
|
+
"Proxy gateway env missing. Set CLOUDINARY_GATEWAY_URL and CLOUDINARY_CLIENT_SECRET.",
|
|
121
136
|
"gateway_env"
|
|
122
137
|
);
|
|
123
138
|
}
|
|
124
|
-
return { base
|
|
139
|
+
return { base, token };
|
|
125
140
|
}
|
|
126
141
|
async function handleResponse(operation, res) {
|
|
127
142
|
let body = null;
|
|
@@ -195,12 +210,12 @@ async function loadLegacyCloudinary() {
|
|
|
195
210
|
return _cloudinary;
|
|
196
211
|
} catch (err) {
|
|
197
212
|
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 +
|
|
213
|
+
"@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_CLIENT_SECRET. Original error: " + err.message
|
|
199
214
|
);
|
|
200
215
|
}
|
|
201
216
|
}
|
|
202
217
|
async function configureSanvikaCloudinary({ appName, cloudName, apiKey, apiSecret } = {}) {
|
|
203
|
-
const resolvedApp = appName ||
|
|
218
|
+
const resolvedApp = appName || resolveCloudinaryClientId();
|
|
204
219
|
if (!resolvedApp) throw new Error("appName is required for configureSanvikaCloudinary");
|
|
205
220
|
_appName = resolvedApp;
|
|
206
221
|
if (isProxyMode()) {
|
|
@@ -212,7 +227,7 @@ async function configureSanvikaCloudinary({ appName, cloudName, apiKey, apiSecre
|
|
|
212
227
|
const as = apiSecret || process.env.CLOUDINARY_API_SECRET;
|
|
213
228
|
if (!cn || !ak || !as) {
|
|
214
229
|
throw new Error(
|
|
215
|
-
"Cloudinary credentials missing. Either use proxy mode (CLOUDINARY_GATEWAY_URL +
|
|
230
|
+
"Cloudinary credentials missing. Either use proxy mode (CLOUDINARY_GATEWAY_URL + CLOUDINARY_CLIENT_SECRET) or legacy env (CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET)."
|
|
216
231
|
);
|
|
217
232
|
}
|
|
218
233
|
const cloudinary = await loadLegacyCloudinary();
|
|
@@ -222,12 +237,12 @@ async function configureSanvikaCloudinary({ appName, cloudName, apiKey, apiSecre
|
|
|
222
237
|
async function ensureConfigured() {
|
|
223
238
|
if (_configured) return;
|
|
224
239
|
if (isProxyMode()) {
|
|
225
|
-
_appName = _appName ||
|
|
240
|
+
_appName = _appName || resolveCloudinaryClientId() || "sanvika-app";
|
|
226
241
|
_configured = true;
|
|
227
242
|
return;
|
|
228
243
|
}
|
|
229
|
-
if (
|
|
230
|
-
await configureSanvikaCloudinary({ appName:
|
|
244
|
+
if (resolveCloudinaryClientId()) {
|
|
245
|
+
await configureSanvikaCloudinary({ appName: resolveCloudinaryClientId() });
|
|
231
246
|
return;
|
|
232
247
|
}
|
|
233
248
|
throw new Error("Call configureSanvikaCloudinary({ appName }) before using SDK operations.");
|
|
@@ -543,7 +558,7 @@ function verifySanvikaWebhookSignature({ headers, rawBody, secret, toleranceSec
|
|
|
543
558
|
};
|
|
544
559
|
const sig = String(getHeader("x-sanvika-signature") || "").trim();
|
|
545
560
|
const ts = String(getHeader("x-sanvika-timestamp") || "").trim();
|
|
546
|
-
const token = secret ||
|
|
561
|
+
const token = secret || resolveCloudinaryClientSecret();
|
|
547
562
|
if (!token) return { valid: false, reason: "missing_secret" };
|
|
548
563
|
if (!sig) return { valid: false, reason: "missing_signature" };
|
|
549
564
|
if (!ts) return { valid: false, reason: "missing_timestamp" };
|
|
@@ -667,12 +682,16 @@ export {
|
|
|
667
682
|
getCloudinaryUsage,
|
|
668
683
|
getFolderPath,
|
|
669
684
|
getOptimizedUrl,
|
|
685
|
+
isCloudinaryProxyConfigured,
|
|
670
686
|
isCloudinaryUrl,
|
|
671
687
|
isProxyMode,
|
|
672
688
|
isRetriableError,
|
|
673
689
|
normalizeFolderPath,
|
|
674
690
|
pingCloudinary,
|
|
675
691
|
renameImage,
|
|
692
|
+
resolveCloudinaryClientId,
|
|
693
|
+
resolveCloudinaryClientSecret,
|
|
694
|
+
resolveCloudinaryGatewayUrl,
|
|
676
695
|
runCloudinaryDiagnostics,
|
|
677
696
|
splitFileName,
|
|
678
697
|
testCloudinaryWebhookSignature,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanvika/cloudinary",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
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",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
15
19
|
"devDependencies": {
|
|
16
20
|
"tsup": "^8.5.1"
|
|
17
21
|
},
|
|
@@ -48,8 +52,5 @@
|
|
|
48
52
|
"type": "git",
|
|
49
53
|
"url": "https://github.com/sanvikaproduction/sanvika-cloudinary",
|
|
50
54
|
"directory": "packages/sanvika-cloudinary-sdk"
|
|
51
|
-
},
|
|
52
|
-
"scripts": {
|
|
53
|
-
"build": "tsup"
|
|
54
55
|
}
|
|
55
|
-
}
|
|
56
|
+
}
|