@kern-di/trust-carousel 0.1.7 → 0.1.8

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/server.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import { VercelRequest, VercelResponse } from '@vercel/node';
2
2
 
3
- /** Production host for `@kern/api` (company central API). Override via `apiUrl` in `createVercelHandler`. */
3
+ /** Production host for `@kern/api` (company central API). */
4
4
  declare const DEFAULT_KERN_CENTRAL_API_URL = "https://api.kern-di.de";
5
+ /**
6
+ * Resolves central API origin for `createVercelHandler`:
7
+ * `config.apiUrl` → `process.env.KERN_API_URL` (local / preview) → {@link DEFAULT_KERN_CENTRAL_API_URL}.
8
+ */
9
+ declare function resolveKernCentralApiUrl(configApiUrl?: string): string;
5
10
  type CreateVercelHandlerConfig = {
6
11
  apiKey: string;
7
12
  placeId: string;
@@ -10,7 +15,9 @@ type CreateVercelHandlerConfig = {
10
15
  /**
11
16
  * Vercel Node serverless handler that proxies to the company central API
12
17
  * `GET /api/google-reviews` with bearer auth. Use as `api/reviews.ts` on fleet sites.
18
+ *
19
+ * Base URL: `config.apiUrl`, else **`KERN_API_URL`** (e.g. `http://localhost:7072` for local `pnpm dev:kern-api`), else production default.
13
20
  */
14
21
  declare function createVercelHandler(config: CreateVercelHandlerConfig): (req: VercelRequest, res: VercelResponse) => Promise<void>;
15
22
 
16
- export { type CreateVercelHandlerConfig, DEFAULT_KERN_CENTRAL_API_URL, createVercelHandler };
23
+ export { type CreateVercelHandlerConfig, DEFAULT_KERN_CENTRAL_API_URL, createVercelHandler, resolveKernCentralApiUrl };
package/dist/server.js CHANGED
@@ -1,5 +1,12 @@
1
1
  // src/server.ts
2
2
  var DEFAULT_KERN_CENTRAL_API_URL = "https://api.kern-di.de";
3
+ function resolveKernCentralApiUrl(configApiUrl) {
4
+ const fromConfig = configApiUrl?.trim();
5
+ if (fromConfig) return fromConfig.replace(/\/$/, "");
6
+ const fromEnv = process.env.KERN_API_URL?.trim();
7
+ if (fromEnv) return fromEnv.replace(/\/$/, "");
8
+ return DEFAULT_KERN_CENTRAL_API_URL.replace(/\/$/, "");
9
+ }
3
10
  function createVercelHandler(config) {
4
11
  return async (req, res) => {
5
12
  if (req.method === "OPTIONS") {
@@ -16,10 +23,7 @@ function createVercelHandler(config) {
16
23
  res.status(503).json({ error: "Reviews API is not configured." });
17
24
  return;
18
25
  }
19
- const base = (config.apiUrl ?? DEFAULT_KERN_CENTRAL_API_URL).replace(
20
- /\/$/,
21
- ""
22
- );
26
+ const base = resolveKernCentralApiUrl(config.apiUrl);
23
27
  const url = `${base}/api/google-reviews?placeId=${encodeURIComponent(placeId)}`;
24
28
  try {
25
29
  const upstream = await fetch(url, {
@@ -41,6 +45,7 @@ function createVercelHandler(config) {
41
45
  }
42
46
  export {
43
47
  DEFAULT_KERN_CENTRAL_API_URL,
44
- createVercelHandler
48
+ createVercelHandler,
49
+ resolveKernCentralApiUrl
45
50
  };
46
51
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import type { VercelRequest, VercelResponse } from \"@vercel/node\";\n\n/** Production host for `@kern/api` (company central API). Override via `apiUrl` in `createVercelHandler`. */\nexport const DEFAULT_KERN_CENTRAL_API_URL = \"https://api.kern-di.de\";\n\nexport type CreateVercelHandlerConfig = {\n\tapiKey: string;\n\tplaceId: string;\n\tapiUrl?: string;\n};\n\n/**\n * Vercel Node serverless handler that proxies to the company central API\n * `GET /api/google-reviews` with bearer auth. Use as `api/reviews.ts` on fleet sites.\n */\nexport function createVercelHandler(\n\tconfig: CreateVercelHandlerConfig,\n): (req: VercelRequest, res: VercelResponse) => Promise<void> {\n\treturn async (req: VercelRequest, res: VercelResponse) => {\n\t\tif (req.method === \"OPTIONS\") {\n\t\t\tres.status(204).end();\n\t\t\treturn;\n\t\t}\n\t\tif (req.method !== \"GET\") {\n\t\t\tres.status(405).json({ error: \"Method not allowed\" });\n\t\t\treturn;\n\t\t}\n\n\t\tconst apiKey = config.apiKey?.trim();\n\t\tconst placeId = config.placeId?.trim();\n\t\tif (!apiKey || !placeId) {\n\t\t\tres.status(503).json({ error: \"Reviews API is not configured.\" });\n\t\t\treturn;\n\t\t}\n\n\t\tconst base = (config.apiUrl ?? DEFAULT_KERN_CENTRAL_API_URL).replace(\n\t\t\t/\\/$/,\n\t\t\t\"\",\n\t\t);\n\t\tconst url = `${base}/api/google-reviews?placeId=${encodeURIComponent(placeId)}`;\n\n\t\ttry {\n\t\t\tconst upstream = await fetch(url, {\n\t\t\t\theaders: { Authorization: `Bearer ${apiKey}` },\n\t\t\t});\n\n\t\t\tconst cacheControl =\n\t\t\t\t\"public, max-age=0, s-maxage=3600, stale-while-revalidate=86400, must-revalidate\";\n\t\t\tres.setHeader(\"Cache-Control\", cacheControl);\n\n\t\t\tconst ct = upstream.headers.get(\"content-type\");\n\t\t\tif (ct) {\n\t\t\t\tres.setHeader(\"Content-Type\", ct);\n\t\t\t}\n\n\t\t\tres.status(upstream.status);\n\t\t\tconst buf = Buffer.from(await upstream.arrayBuffer());\n\t\t\tres.send(buf);\n\t\t} catch {\n\t\t\tres.status(502).json({ error: \"Could not load reviews.\" });\n\t\t}\n\t};\n}\n"],"mappings":";AAGO,IAAM,+BAA+B;AAYrC,SAAS,oBACf,QAC6D;AAC7D,SAAO,OAAO,KAAoB,QAAwB;AACzD,QAAI,IAAI,WAAW,WAAW;AAC7B,UAAI,OAAO,GAAG,EAAE,IAAI;AACpB;AAAA,IACD;AACA,QAAI,IAAI,WAAW,OAAO;AACzB,UAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,qBAAqB,CAAC;AACpD;AAAA,IACD;AAEA,UAAM,SAAS,OAAO,QAAQ,KAAK;AACnC,UAAM,UAAU,OAAO,SAAS,KAAK;AACrC,QAAI,CAAC,UAAU,CAAC,SAAS;AACxB,UAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,iCAAiC,CAAC;AAChE;AAAA,IACD;AAEA,UAAM,QAAQ,OAAO,UAAU,8BAA8B;AAAA,MAC5D;AAAA,MACA;AAAA,IACD;AACA,UAAM,MAAM,GAAG,IAAI,+BAA+B,mBAAmB,OAAO,CAAC;AAE7E,QAAI;AACH,YAAM,WAAW,MAAM,MAAM,KAAK;AAAA,QACjC,SAAS,EAAE,eAAe,UAAU,MAAM,GAAG;AAAA,MAC9C,CAAC;AAED,YAAM,eACL;AACD,UAAI,UAAU,iBAAiB,YAAY;AAE3C,YAAM,KAAK,SAAS,QAAQ,IAAI,cAAc;AAC9C,UAAI,IAAI;AACP,YAAI,UAAU,gBAAgB,EAAE;AAAA,MACjC;AAEA,UAAI,OAAO,SAAS,MAAM;AAC1B,YAAM,MAAM,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC;AACpD,UAAI,KAAK,GAAG;AAAA,IACb,QAAQ;AACP,UAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,0BAA0B,CAAC;AAAA,IAC1D;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import type { VercelRequest, VercelResponse } from \"@vercel/node\";\n\n/** Production host for `@kern/api` (company central API). */\nexport const DEFAULT_KERN_CENTRAL_API_URL = \"https://api.kern-di.de\";\n\n/**\n * Resolves central API origin for `createVercelHandler`:\n * `config.apiUrl` → `process.env.KERN_API_URL` (local / preview) → {@link DEFAULT_KERN_CENTRAL_API_URL}.\n */\nexport function resolveKernCentralApiUrl(configApiUrl?: string): string {\n\tconst fromConfig = configApiUrl?.trim();\n\tif (fromConfig) return fromConfig.replace(/\\/$/, \"\");\n\tconst fromEnv = process.env.KERN_API_URL?.trim();\n\tif (fromEnv) return fromEnv.replace(/\\/$/, \"\");\n\treturn DEFAULT_KERN_CENTRAL_API_URL.replace(/\\/$/, \"\");\n}\n\nexport type CreateVercelHandlerConfig = {\n\tapiKey: string;\n\tplaceId: string;\n\tapiUrl?: string;\n};\n\n/**\n * Vercel Node serverless handler that proxies to the company central API\n * `GET /api/google-reviews` with bearer auth. Use as `api/reviews.ts` on fleet sites.\n *\n * Base URL: `config.apiUrl`, else **`KERN_API_URL`** (e.g. `http://localhost:7072` for local `pnpm dev:kern-api`), else production default.\n */\nexport function createVercelHandler(\n\tconfig: CreateVercelHandlerConfig,\n): (req: VercelRequest, res: VercelResponse) => Promise<void> {\n\treturn async (req: VercelRequest, res: VercelResponse) => {\n\t\tif (req.method === \"OPTIONS\") {\n\t\t\tres.status(204).end();\n\t\t\treturn;\n\t\t}\n\t\tif (req.method !== \"GET\") {\n\t\t\tres.status(405).json({ error: \"Method not allowed\" });\n\t\t\treturn;\n\t\t}\n\n\t\tconst apiKey = config.apiKey?.trim();\n\t\tconst placeId = config.placeId?.trim();\n\t\tif (!apiKey || !placeId) {\n\t\t\tres.status(503).json({ error: \"Reviews API is not configured.\" });\n\t\t\treturn;\n\t\t}\n\n\t\tconst base = resolveKernCentralApiUrl(config.apiUrl);\n\t\tconst url = `${base}/api/google-reviews?placeId=${encodeURIComponent(placeId)}`;\n\n\t\ttry {\n\t\t\tconst upstream = await fetch(url, {\n\t\t\t\theaders: { Authorization: `Bearer ${apiKey}` },\n\t\t\t});\n\n\t\t\tconst cacheControl =\n\t\t\t\t\"public, max-age=0, s-maxage=3600, stale-while-revalidate=86400, must-revalidate\";\n\t\t\tres.setHeader(\"Cache-Control\", cacheControl);\n\n\t\t\tconst ct = upstream.headers.get(\"content-type\");\n\t\t\tif (ct) {\n\t\t\t\tres.setHeader(\"Content-Type\", ct);\n\t\t\t}\n\n\t\t\tres.status(upstream.status);\n\t\t\tconst buf = Buffer.from(await upstream.arrayBuffer());\n\t\t\tres.send(buf);\n\t\t} catch {\n\t\t\tres.status(502).json({ error: \"Could not load reviews.\" });\n\t\t}\n\t};\n}\n"],"mappings":";AAGO,IAAM,+BAA+B;AAMrC,SAAS,yBAAyB,cAA+B;AACvE,QAAM,aAAa,cAAc,KAAK;AACtC,MAAI,WAAY,QAAO,WAAW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
  {
2
2
  "name": "@kern-di/trust-carousel",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Drop-in Google Reviews carousel component for embedding social proof on any site",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",