@sanvika/cloudinary 0.3.0 → 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.
Files changed (2) hide show
  1. package/dist/index.js +41 -14
  2. package/package.json +2 -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 Boolean(process.env.CLOUDINARY_GATEWAY_URL && process.env.CLOUDINARY_TOKEN);
128
+ return isCloudinaryProxyConfigured();
114
129
  }
115
130
  function requireProxyEnv() {
116
- const base = process.env.CLOUDINARY_GATEWAY_URL;
117
- const token = process.env.CLOUDINARY_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 CLOUDINARY_TOKEN.",
135
+ "Proxy gateway env missing. Set CLOUDINARY_GATEWAY_URL and CLOUDINARY_CLIENT_SECRET.",
121
136
  "gateway_env"
122
137
  );
123
138
  }
124
- return { base: base.replace(/\/+$/, ""), token };
139
+ return { base, token };
125
140
  }
126
141
  async function handleResponse(operation, res) {
127
142
  let body = null;
@@ -186,13 +201,21 @@ var _appName = null;
186
201
  var _configured = false;
187
202
  var _cloudinary = null;
188
203
  async function loadLegacyCloudinary() {
204
+ var _a;
189
205
  if (_cloudinary) return _cloudinary;
190
- const mod = await import("cloudinary");
191
- _cloudinary = mod.v2;
192
- return _cloudinary;
206
+ try {
207
+ const dynamicImport = new Function("m", "return import(m)");
208
+ const mod = await dynamicImport("cloudinary");
209
+ _cloudinary = mod.v2 || ((_a = mod.default) == null ? void 0 : _a.v2) || mod.default || mod;
210
+ return _cloudinary;
211
+ } catch (err) {
212
+ throw new Error(
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
214
+ );
215
+ }
193
216
  }
194
217
  async function configureSanvikaCloudinary({ appName, cloudName, apiKey, apiSecret } = {}) {
195
- const resolvedApp = appName || process.env.CLOUDINARY_APP_NAME;
218
+ const resolvedApp = appName || resolveCloudinaryClientId();
196
219
  if (!resolvedApp) throw new Error("appName is required for configureSanvikaCloudinary");
197
220
  _appName = resolvedApp;
198
221
  if (isProxyMode()) {
@@ -204,7 +227,7 @@ async function configureSanvikaCloudinary({ appName, cloudName, apiKey, apiSecre
204
227
  const as = apiSecret || process.env.CLOUDINARY_API_SECRET;
205
228
  if (!cn || !ak || !as) {
206
229
  throw new Error(
207
- "Cloudinary credentials missing. Either use proxy mode (CLOUDINARY_GATEWAY_URL + CLOUDINARY_TOKEN) or legacy env (CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET)."
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)."
208
231
  );
209
232
  }
210
233
  const cloudinary = await loadLegacyCloudinary();
@@ -214,12 +237,12 @@ async function configureSanvikaCloudinary({ appName, cloudName, apiKey, apiSecre
214
237
  async function ensureConfigured() {
215
238
  if (_configured) return;
216
239
  if (isProxyMode()) {
217
- _appName = _appName || process.env.CLOUDINARY_APP_NAME || "sanvika-app";
240
+ _appName = _appName || resolveCloudinaryClientId() || "sanvika-app";
218
241
  _configured = true;
219
242
  return;
220
243
  }
221
- if (process.env.CLOUDINARY_APP_NAME) {
222
- await configureSanvikaCloudinary({ appName: process.env.CLOUDINARY_APP_NAME });
244
+ if (resolveCloudinaryClientId()) {
245
+ await configureSanvikaCloudinary({ appName: resolveCloudinaryClientId() });
223
246
  return;
224
247
  }
225
248
  throw new Error("Call configureSanvikaCloudinary({ appName }) before using SDK operations.");
@@ -535,7 +558,7 @@ function verifySanvikaWebhookSignature({ headers, rawBody, secret, toleranceSec
535
558
  };
536
559
  const sig = String(getHeader("x-sanvika-signature") || "").trim();
537
560
  const ts = String(getHeader("x-sanvika-timestamp") || "").trim();
538
- const token = secret || process.env.CLOUDINARY_TOKEN;
561
+ const token = secret || resolveCloudinaryClientSecret();
539
562
  if (!token) return { valid: false, reason: "missing_secret" };
540
563
  if (!sig) return { valid: false, reason: "missing_signature" };
541
564
  if (!ts) return { valid: false, reason: "missing_timestamp" };
@@ -659,12 +682,16 @@ export {
659
682
  getCloudinaryUsage,
660
683
  getFolderPath,
661
684
  getOptimizedUrl,
685
+ isCloudinaryProxyConfigured,
662
686
  isCloudinaryUrl,
663
687
  isProxyMode,
664
688
  isRetriableError,
665
689
  normalizeFolderPath,
666
690
  pingCloudinary,
667
691
  renameImage,
692
+ resolveCloudinaryClientId,
693
+ resolveCloudinaryClientSecret,
694
+ resolveCloudinaryGatewayUrl,
668
695
  runCloudinaryDiagnostics,
669
696
  splitFileName,
670
697
  testCloudinaryWebhookSignature,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanvika/cloudinary",
3
- "version": "0.3.0",
4
- "description": "Centralized Cloudinary SDK for the Sanvika ecosystem — proxy gateway mode (zero credentials) + legacy direct mode",
3
+ "version": "0.3.2",
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",
@@ -19,9 +19,6 @@
19
19
  "devDependencies": {
20
20
  "tsup": "^8.5.1"
21
21
  },
22
- "dependencies": {
23
- "cloudinary": "^2.5.0"
24
- },
25
22
  "keywords": [
26
23
  "cloudinary",
27
24
  "sanvika",