@gigadrive/network-config 3.3.2 → 3.4.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.d.mts +187 -1
- package/dist/index.d.ts +187 -1
- package/dist/index.js +280 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +279 -18
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs-adapter.d.mts +7 -33
- package/dist/nextjs-adapter.d.ts +6 -34
- package/dist/nextjs-adapter.js +324 -21
- package/dist/nextjs-adapter.js.map +1 -1
- package/dist/nextjs-adapter.mjs +324 -22
- package/dist/nextjs-adapter.mjs.map +1 -1
- package/dist/nextjs-cache-components-handler.d.mts +20 -0
- package/dist/nextjs-cache-components-handler.d.ts +20 -0
- package/dist/nextjs-cache-components-handler.js +200 -0
- package/dist/nextjs-cache-components-handler.js.map +1 -0
- package/dist/nextjs-cache-components-handler.mjs +177 -0
- package/dist/nextjs-cache-components-handler.mjs.map +1 -0
- package/dist/nextjs-cache-handler.d.mts +12 -0
- package/dist/nextjs-cache-handler.d.ts +12 -0
- package/dist/nextjs-cache-handler.js +141 -0
- package/dist/nextjs-cache-handler.js.map +1 -0
- package/dist/nextjs-cache-handler.mjs +118 -0
- package/dist/nextjs-cache-handler.mjs.map +1 -0
- package/dist/nextjs-image-loader.d.mts +9 -0
- package/dist/nextjs-image-loader.d.ts +9 -0
- package/dist/nextjs-image-loader.js +36 -0
- package/dist/nextjs-image-loader.js.map +1 -0
- package/dist/nextjs-image-loader.mjs +15 -0
- package/dist/nextjs-image-loader.mjs.map +1 -0
- package/dist/v4/schema.json +85 -0
- package/package.json +19 -3
- package/src/v4/schema.json +85 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/nextjs-runtime-cache-client.ts
|
|
2
|
+
var cachedToken;
|
|
3
|
+
var apiBaseUrl = () => (process.env.GIGADRIVE_API_URL ?? "https://api.gigadrive.network").replace(/\/$/, "");
|
|
4
|
+
var encodeBinary = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
5
|
+
if (value instanceof Uint8Array) {
|
|
6
|
+
return { __gigadriveType: "bytes", value: Buffer.from(value).toString("base64") };
|
|
7
|
+
}
|
|
8
|
+
if (value instanceof ArrayBuffer) {
|
|
9
|
+
return { __gigadriveType: "bytes", value: Buffer.from(value).toString("base64") };
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(value)) return value.map((item) => encodeBinary(item, seen));
|
|
12
|
+
if (typeof value !== "object" || value === null) return value;
|
|
13
|
+
if (seen.has(value)) throw new Error("Next.js cache entry contains a circular value");
|
|
14
|
+
seen.add(value);
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const [key, item] of Object.entries(value)) result[key] = encodeBinary(item, seen);
|
|
17
|
+
seen.delete(value);
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
var decodeBinary = (value) => {
|
|
21
|
+
if (Array.isArray(value)) return value.map(decodeBinary);
|
|
22
|
+
if (typeof value !== "object" || value === null) return value;
|
|
23
|
+
const record = value;
|
|
24
|
+
if (record.__gigadriveType === "bytes" && typeof record.value === "string")
|
|
25
|
+
return Buffer.from(record.value, "base64");
|
|
26
|
+
return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, decodeBinary(item)]));
|
|
27
|
+
};
|
|
28
|
+
var getAccessToken = async () => {
|
|
29
|
+
if (cachedToken && cachedToken.expiresAt > Date.now() + 3e4) return cachedToken.value;
|
|
30
|
+
const clientId = process.env.GIGADRIVE_CLIENT_ID;
|
|
31
|
+
const clientSecret = process.env.GIGADRIVE_CLIENT_SECRET;
|
|
32
|
+
if (!clientId || !clientSecret) throw new Error("Gigadrive workload credentials are unavailable");
|
|
33
|
+
const response = await fetch(`${apiBaseUrl()}/oauth2/token`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
37
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
38
|
+
},
|
|
39
|
+
body: "grant_type=client_credentials"
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) throw new Error(`Gigadrive workload authentication failed with status ${response.status}`);
|
|
42
|
+
const token = await response.json();
|
|
43
|
+
if (!token.access_token) throw new Error("Gigadrive workload authentication returned no access token");
|
|
44
|
+
cachedToken = {
|
|
45
|
+
value: token.access_token,
|
|
46
|
+
expiresAt: Date.now() + Math.max(60, token.expires_in ?? 300) * 1e3
|
|
47
|
+
};
|
|
48
|
+
return token.access_token;
|
|
49
|
+
};
|
|
50
|
+
var request = async (pathname, init, attempt = 0) => {
|
|
51
|
+
const token = await getAccessToken();
|
|
52
|
+
try {
|
|
53
|
+
const response = await fetch(`${apiBaseUrl()}${pathname}`, {
|
|
54
|
+
...init,
|
|
55
|
+
headers: {
|
|
56
|
+
authorization: `Bearer ${token}`,
|
|
57
|
+
"content-type": "application/json",
|
|
58
|
+
"x-gigadrive-deployment-id": process.env.GIGADRIVE_DEPLOYMENT_ID ?? process.env.NEBULA_DEPLOYMENT_ID ?? "",
|
|
59
|
+
"x-gigadrive-build-id": process.env.NEXT_BUILD_ID ?? "",
|
|
60
|
+
...init.headers
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (response.status === 401 && attempt === 0) {
|
|
64
|
+
cachedToken = void 0;
|
|
65
|
+
return request(pathname, init, attempt + 1);
|
|
66
|
+
}
|
|
67
|
+
if (response.status >= 500 && attempt < 2) return request(pathname, init, attempt + 1);
|
|
68
|
+
return response;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (attempt < 2) return request(pathname, init, attempt + 1);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var cachePath = (kind, key) => `/internal/runtime-cache/v1/entries/${encodeURIComponent(kind)}/${encodeURIComponent(key)}`;
|
|
75
|
+
var readRuntimeCache = async (kind, key) => {
|
|
76
|
+
try {
|
|
77
|
+
const response = await request(cachePath(kind, key), { method: "GET" });
|
|
78
|
+
if (response.status === 404) return void 0;
|
|
79
|
+
if (!response.ok) return void 0;
|
|
80
|
+
const envelope = await response.json();
|
|
81
|
+
return decodeBinary(envelope.value);
|
|
82
|
+
} catch {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var writeRuntimeCache = async (kind, key, value, tags = []) => {
|
|
87
|
+
const response = await request(cachePath(kind, key), {
|
|
88
|
+
method: "PUT",
|
|
89
|
+
body: JSON.stringify({ value: encodeBinary(value), tags })
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok) throw new Error(`Gigadrive runtime cache write failed with status ${response.status}`);
|
|
92
|
+
};
|
|
93
|
+
var revalidateRuntimeCacheTags = async (kind, tags, durations) => {
|
|
94
|
+
const response = await request("/internal/runtime-cache/v1/tags/revalidate", {
|
|
95
|
+
method: "POST",
|
|
96
|
+
body: JSON.stringify({ kind, tags, durations })
|
|
97
|
+
});
|
|
98
|
+
if (!response.ok) throw new Error(`Gigadrive runtime cache revalidation failed with status ${response.status}`);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/nextjs-cache-handler.ts
|
|
102
|
+
var GigadriveNextCacheHandler = class {
|
|
103
|
+
async get(key) {
|
|
104
|
+
return await readRuntimeCache("incremental", key) ?? null;
|
|
105
|
+
}
|
|
106
|
+
async set(key, data, context) {
|
|
107
|
+
await writeRuntimeCache("incremental", key, data, context.tags ?? []);
|
|
108
|
+
}
|
|
109
|
+
async revalidateTag(tags) {
|
|
110
|
+
await revalidateRuntimeCacheTags("incremental", Array.isArray(tags) ? tags : [tags]);
|
|
111
|
+
}
|
|
112
|
+
resetRequestCache() {
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
GigadriveNextCacheHandler as default
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=nextjs-cache-handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/nextjs-runtime-cache-client.ts","../src/nextjs-cache-handler.ts"],"sourcesContent":["interface RuntimeCacheEnvelope {\n value: unknown;\n}\n\ninterface AccessTokenResponse {\n access_token: string;\n expires_in?: number;\n}\n\nlet cachedToken: { value: string; expiresAt: number } | undefined;\n\nconst apiBaseUrl = (): string => (process.env.GIGADRIVE_API_URL ?? 'https://api.gigadrive.network').replace(/\\/$/, '');\n\nconst encodeBinary = (value: unknown, seen = new WeakSet<object>()): unknown => {\n if (value instanceof Uint8Array) {\n return { __gigadriveType: 'bytes', value: Buffer.from(value).toString('base64') };\n }\n if (value instanceof ArrayBuffer) {\n return { __gigadriveType: 'bytes', value: Buffer.from(value).toString('base64') };\n }\n if (Array.isArray(value)) return value.map((item) => encodeBinary(item, seen));\n if (typeof value !== 'object' || value === null) return value;\n if (seen.has(value)) throw new Error('Next.js cache entry contains a circular value');\n seen.add(value);\n const result: Record<string, unknown> = {};\n for (const [key, item] of Object.entries(value)) result[key] = encodeBinary(item, seen);\n seen.delete(value);\n return result;\n};\n\nconst decodeBinary = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(decodeBinary);\n if (typeof value !== 'object' || value === null) return value;\n const record = value as Record<string, unknown>;\n if (record.__gigadriveType === 'bytes' && typeof record.value === 'string')\n return Buffer.from(record.value, 'base64');\n return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, decodeBinary(item)]));\n};\n\nconst getAccessToken = async (): Promise<string> => {\n if (cachedToken && cachedToken.expiresAt > Date.now() + 30_000) return cachedToken.value;\n const clientId = process.env.GIGADRIVE_CLIENT_ID;\n const clientSecret = process.env.GIGADRIVE_CLIENT_SECRET;\n if (!clientId || !clientSecret) throw new Error('Gigadrive workload credentials are unavailable');\n\n const response = await fetch(`${apiBaseUrl()}/oauth2/token`, {\n method: 'POST',\n headers: {\n authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`,\n 'content-type': 'application/x-www-form-urlencoded',\n },\n body: 'grant_type=client_credentials',\n });\n if (!response.ok) throw new Error(`Gigadrive workload authentication failed with status ${response.status}`);\n const token = (await response.json()) as AccessTokenResponse;\n if (!token.access_token) throw new Error('Gigadrive workload authentication returned no access token');\n cachedToken = {\n value: token.access_token,\n expiresAt: Date.now() + Math.max(60, token.expires_in ?? 300) * 1000,\n };\n return token.access_token;\n};\n\nconst request = async (pathname: string, init: RequestInit, attempt = 0): Promise<Response> => {\n const token = await getAccessToken();\n try {\n const response = await fetch(`${apiBaseUrl()}${pathname}`, {\n ...init,\n headers: {\n authorization: `Bearer ${token}`,\n 'content-type': 'application/json',\n 'x-gigadrive-deployment-id': process.env.GIGADRIVE_DEPLOYMENT_ID ?? process.env.NEBULA_DEPLOYMENT_ID ?? '',\n 'x-gigadrive-build-id': process.env.NEXT_BUILD_ID ?? '',\n ...init.headers,\n },\n });\n if (response.status === 401 && attempt === 0) {\n cachedToken = undefined;\n return request(pathname, init, attempt + 1);\n }\n if (response.status >= 500 && attempt < 2) return request(pathname, init, attempt + 1);\n return response;\n } catch (error) {\n if (attempt < 2) return request(pathname, init, attempt + 1);\n throw error;\n }\n};\n\nconst cachePath = (kind: string, key: string): string =>\n `/internal/runtime-cache/v1/entries/${encodeURIComponent(kind)}/${encodeURIComponent(key)}`;\n\nexport const readRuntimeCache = async (kind: string, key: string): Promise<unknown | undefined> => {\n try {\n const response = await request(cachePath(kind, key), { method: 'GET' });\n if (response.status === 404) return undefined;\n if (!response.ok) return undefined;\n const envelope = (await response.json()) as RuntimeCacheEnvelope;\n return decodeBinary(envelope.value);\n } catch {\n return undefined;\n }\n};\n\nexport const writeRuntimeCache = async (\n kind: string,\n key: string,\n value: unknown,\n tags: readonly string[] = []\n): Promise<void> => {\n const response = await request(cachePath(kind, key), {\n method: 'PUT',\n body: JSON.stringify({ value: encodeBinary(value), tags }),\n });\n if (!response.ok) throw new Error(`Gigadrive runtime cache write failed with status ${response.status}`);\n};\n\nexport const revalidateRuntimeCacheTags = async (\n kind: string,\n tags: readonly string[],\n durations?: { expire?: number }\n): Promise<void> => {\n const response = await request('/internal/runtime-cache/v1/tags/revalidate', {\n method: 'POST',\n body: JSON.stringify({ kind, tags, durations }),\n });\n if (!response.ok) throw new Error(`Gigadrive runtime cache revalidation failed with status ${response.status}`);\n};\n\nexport const getRuntimeCacheTagExpiration = async (kind: string, tags: readonly string[]): Promise<number> => {\n try {\n const response = await request('/internal/runtime-cache/v1/tags/expiration', {\n method: 'POST',\n body: JSON.stringify({ kind, tags }),\n });\n if (!response.ok) return 0;\n const value = (await response.json()) as { expiration?: unknown };\n return typeof value.expiration === 'number' ? value.expiration : 0;\n } catch {\n return 0;\n }\n};\n\nexport const resetRuntimeCacheClientForTests = (): void => {\n cachedToken = undefined;\n};\n","import { readRuntimeCache, revalidateRuntimeCacheTags, writeRuntimeCache } from './nextjs-runtime-cache-client';\n\ninterface IncrementalCacheContext {\n tags?: string[];\n}\n\n/** Shared Network cache handler for ISR, server responses, fetches, and image metadata. */\nexport default class GigadriveNextCacheHandler {\n async get(key: string): Promise<unknown | null> {\n return (await readRuntimeCache('incremental', key)) ?? null;\n }\n\n async set(key: string, data: unknown, context: IncrementalCacheContext): Promise<void> {\n await writeRuntimeCache('incremental', key, data, context.tags ?? []);\n }\n\n async revalidateTag(tags: string | string[]): Promise<void> {\n await revalidateRuntimeCacheTags('incremental', Array.isArray(tags) ? tags : [tags]);\n }\n\n resetRequestCache(): void {}\n}\n"],"mappings":";AASA,IAAI;AAEJ,IAAM,aAAa,OAAe,QAAQ,IAAI,qBAAqB,iCAAiC,QAAQ,OAAO,EAAE;AAErH,IAAM,eAAe,CAAC,OAAgB,OAAO,oBAAI,QAAgB,MAAe;AAC9E,MAAI,iBAAiB,YAAY;AAC/B,WAAO,EAAE,iBAAiB,SAAS,OAAO,OAAO,KAAK,KAAK,EAAE,SAAS,QAAQ,EAAE;AAAA,EAClF;AACA,MAAI,iBAAiB,aAAa;AAChC,WAAO,EAAE,iBAAiB,SAAS,OAAO,OAAO,KAAK,KAAK,EAAE,SAAS,QAA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-0,0 +1,9 @@
|
|
|
1
|
+
interface NextImageLoaderOptions {
|
|
2
|
+
src: string;
|
|
3
|
+
width: number;
|
|
4
|
+
quality?: number;
|
|
5
|
+
}
|
|
6
|
+
/** Builds the stable app-host URL consumed by Gigadrive's managed image optimizer. */
|
|
7
|
+
declare function gigadriveNextImageLoader({ src, width, quality }: NextImageLoaderOptions): string;
|
|
8
|
+
|
|
9
|
+
export { gigadriveNextImageLoader as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface NextImageLoaderOptions {
|
|
2
|
+
src: string;
|
|
3
|
+
width: number;
|
|
4
|
+
quality?: number;
|
|
5
|
+
}
|
|
6
|
+
/** Builds the stable app-host URL consumed by Gigadrive's managed image optimizer. */
|
|
7
|
+
declare function gigadriveNextImageLoader({ src, width, quality }: NextImageLoaderOptions): string;
|
|
8
|
+
|
|
9
|
+
export = gigadriveNextImageLoader;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/nextjs-image-loader.ts
|
|
21
|
+
var nextjs_image_loader_exports = {};
|
|
22
|
+
__export(nextjs_image_loader_exports, {
|
|
23
|
+
default: () => gigadriveNextImageLoader
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(nextjs_image_loader_exports);
|
|
26
|
+
var filenameHint = (source) => {
|
|
27
|
+
const pathname = source.startsWith("http://") || source.startsWith("https://") ? new URL(source).pathname : source;
|
|
28
|
+
const candidate = pathname.split("/").filter(Boolean).at(-1)?.split("?")[0] ?? "image";
|
|
29
|
+
return /\.[A-Za-z0-9]{2,5}$/.test(candidate) ? candidate : `${candidate || "image"}.image`;
|
|
30
|
+
};
|
|
31
|
+
function gigadriveNextImageLoader({ src, width, quality }) {
|
|
32
|
+
const parameters = new URLSearchParams({ width: String(width) });
|
|
33
|
+
if (quality !== void 0) parameters.set("quality", String(quality));
|
|
34
|
+
return `/_gigadrive/image/${encodeURIComponent(src)}/${encodeURIComponent(filenameHint(src))}?${parameters}`;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=nextjs-image-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/nextjs-image-loader.ts"],"sourcesContent":["interface NextImageLoaderOptions {\n src: string;\n width: number;\n quality?: number;\n}\n\nconst filenameHint = (source: string): string => {\n const pathname = source.startsWith('http://') || source.startsWith('https://') ? new URL(source).pathname : source;\n const candidate = pathname.split('/').filter(Boolean).at(-1)?.split('?')[0] ?? 'image';\n return /\\.[A-Za-z0-9]{2,5}$/.test(candidate) ? candidate : `${candidate || 'image'}.image`;\n};\n\n/** Builds the stable app-host URL consumed by Gigadrive's managed image optimizer. */\nexport default function gigadriveNextImageLoader({ src, width, quality }: NextImageLoaderOptions): string {\n const parameters = new URLSearchParams({ width: String(width) });\n if (quality !== undefined) parameters.set('quality', String(quality));\n return `/_gigadrive/image/${encodeURIComponent(src)}/${encodeURIComponent(filenameHint(src))}?${parameters}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAM,eAAe,CAAC,WAA2B;AAC/C,QAAM,WAAW,OAAO,WAAW,SAAS,KAAK,OAAO,WAAW,UAAU,IAAI,IAAI,IAAI,MAAM,EAAE,WAAW;AAC5G,QAAM,YAAY,SAAS,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,GAAG,EAAE,CAAC,KAAK;AAC/E,SAAO,sBAAsB,KAAK,SAAS,IAAI,YAAY,GAAG,aAAa,OAAO;AACpF;AAGe,SAAR,yBAA0C,EAAE,KAAK,OAAO,QAAQ,GAAmC;AACxG,QAAM,aAAa,IAAI,gBAAgB,EAAE,OAAO,OAAO,KAAK,EAAE,CAAC;AAC/D,MAAI,YAAY,OAAW,YAAW,IAAI,WAAW,OAAO,OAAO,CAAC;AACpE,SAAO,qBAAqB,mBAAmB,GAAG,CAAC,IAAI,mBAAmB,aAAa,GAAG,CAAC,CAAC,IAAI,UAAU;AAC5G;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/nextjs-image-loader.ts
|
|
2
|
+
var filenameHint = (source) => {
|
|
3
|
+
const pathname = source.startsWith("http://") || source.startsWith("https://") ? new URL(source).pathname : source;
|
|
4
|
+
const candidate = pathname.split("/").filter(Boolean).at(-1)?.split("?")[0] ?? "image";
|
|
5
|
+
return /\.[A-Za-z0-9]{2,5}$/.test(candidate) ? candidate : `${candidate || "image"}.image`;
|
|
6
|
+
};
|
|
7
|
+
function gigadriveNextImageLoader({ src, width, quality }) {
|
|
8
|
+
const parameters = new URLSearchParams({ width: String(width) });
|
|
9
|
+
if (quality !== void 0) parameters.set("quality", String(quality));
|
|
10
|
+
return `/_gigadrive/image/${encodeURIComponent(src)}/${encodeURIComponent(filenameHint(src))}?${parameters}`;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
gigadriveNextImageLoader as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=nextjs-image-loader.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/nextjs-image-loader.ts"],"sourcesContent":["interface NextImageLoaderOptions {\n src: string;\n width: number;\n quality?: number;\n}\n\nconst filenameHint = (source: string): string => {\n const pathname = source.startsWith('http://') || source.startsWith('https://') ? new URL(source).pathname : source;\n const candidate = pathname.split('/').filter(Boolean).at(-1)?.split('?')[0] ?? 'image';\n return /\\.[A-Za-z0-9]{2,5}$/.test(candidate) ? candidate : `${candidate || 'image'}.image`;\n};\n\n/** Builds the stable app-host URL consumed by Gigadrive's managed image optimizer. */\nexport default function gigadriveNextImageLoader({ src, width, quality }: NextImageLoaderOptions): string {\n const parameters = new URLSearchParams({ width: String(width) });\n if (quality !== undefined) parameters.set('quality', String(quality));\n return `/_gigadrive/image/${encodeURIComponent(src)}/${encodeURIComponent(filenameHint(src))}?${parameters}`;\n}\n"],"mappings":";AAMA,IAAM,eAAe,CAAC,WAA2B;AAC/C,QAAM,WAAW,OAAO,WAAW,SAAS,KAAK,OAAO,WAAW,UAAU,IAAI,IAAI,IAAI,MAAM,EAAE,WAAW;AAC5G,QAAM,YAAY,SAAS,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,GAAG,EAAE,CAAC,KAAK;AAC/E,SAAO,sBAAsB,KAAK,SAAS,IAAI,YAAY,GAAG,aAAa,OAAO;AACpF;AAGe,SAAR,yBAA0C,EAAE,KAAK,OAAO,QAAQ,GAAmC;AACxG,QAAM,aAAa,IAAI,gBAAgB,EAAE,OAAO,OAAO,KAAK,EAAE,CAAC;AAC/D,MAAI,YAAY,OAAW,YAAW,IAAI,WAAW,OAAO,OAAO,CAAC;AACpE,SAAO,qBAAqB,mBAAmB,GAAG,CAAC,IAAI,mBAAmB,aAAa,GAAG,CAAC,CAAC,IAAI,UAAU;AAC5G;","names":[]}
|
package/dist/v4/schema.json
CHANGED
|
@@ -26,6 +26,91 @@
|
|
|
26
26
|
"type": ["boolean", "null"],
|
|
27
27
|
"description": "If true, the assets will be cached at the edge during deployment. This may increase the deployment time, depending on the size of the assets. Defaults to false."
|
|
28
28
|
},
|
|
29
|
+
"images": {
|
|
30
|
+
"type": ["object", "null"],
|
|
31
|
+
"description": "Managed image optimization policy for this deployment.",
|
|
32
|
+
"additionalProperties": false,
|
|
33
|
+
"properties": {
|
|
34
|
+
"localPatterns": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"maxItems": 64,
|
|
37
|
+
"items": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"additionalProperties": false,
|
|
40
|
+
"properties": {
|
|
41
|
+
"pathname": { "type": "string", "minLength": 1, "maxLength": 2048 },
|
|
42
|
+
"search": { "type": "string", "maxLength": 2048 }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"remotePatterns": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"maxItems": 64,
|
|
49
|
+
"items": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"required": ["hostname"],
|
|
52
|
+
"additionalProperties": false,
|
|
53
|
+
"properties": {
|
|
54
|
+
"protocol": { "type": "string", "enum": ["http", "https"] },
|
|
55
|
+
"hostname": { "type": "string", "minLength": 1, "maxLength": 253 },
|
|
56
|
+
"port": { "type": "string", "pattern": "^[0-9]{0,5}$" },
|
|
57
|
+
"pathname": { "type": "string", "minLength": 1, "maxLength": 2048 },
|
|
58
|
+
"search": { "type": "string", "maxLength": 2048 }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"widths": {
|
|
63
|
+
"type": "array",
|
|
64
|
+
"minItems": 1,
|
|
65
|
+
"maxItems": 64,
|
|
66
|
+
"uniqueItems": true,
|
|
67
|
+
"items": { "type": "integer", "minimum": 1, "maximum": 8192 }
|
|
68
|
+
},
|
|
69
|
+
"heights": {
|
|
70
|
+
"type": "array",
|
|
71
|
+
"maxItems": 64,
|
|
72
|
+
"uniqueItems": true,
|
|
73
|
+
"items": { "type": "integer", "minimum": 1, "maximum": 8192 }
|
|
74
|
+
},
|
|
75
|
+
"qualities": {
|
|
76
|
+
"type": "array",
|
|
77
|
+
"minItems": 1,
|
|
78
|
+
"maxItems": 100,
|
|
79
|
+
"uniqueItems": true,
|
|
80
|
+
"items": { "type": "integer", "minimum": 1, "maximum": 100 }
|
|
81
|
+
},
|
|
82
|
+
"formats": {
|
|
83
|
+
"type": "array",
|
|
84
|
+
"minItems": 1,
|
|
85
|
+
"maxItems": 4,
|
|
86
|
+
"uniqueItems": true,
|
|
87
|
+
"items": { "type": "string", "enum": ["image/avif", "image/webp", "image/jpeg", "image/png"] }
|
|
88
|
+
},
|
|
89
|
+
"minimumCacheTTL": { "type": "integer", "minimum": 0, "maximum": 31536000 },
|
|
90
|
+
"dangerouslyAllowSVG": { "type": "boolean" },
|
|
91
|
+
"contentSecurityPolicy": { "type": "string", "maxLength": 4096 },
|
|
92
|
+
"contentDispositionType": { "type": "string", "enum": ["inline", "attachment"] },
|
|
93
|
+
"maximumRedirects": { "type": "integer", "minimum": 0, "maximum": 10 },
|
|
94
|
+
"maximumResponseBody": { "type": "integer", "minimum": 1024, "maximum": 104857600 },
|
|
95
|
+
"variants": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"maxProperties": 100,
|
|
98
|
+
"propertyNames": { "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$" },
|
|
99
|
+
"additionalProperties": {
|
|
100
|
+
"type": "object",
|
|
101
|
+
"minProperties": 1,
|
|
102
|
+
"additionalProperties": false,
|
|
103
|
+
"properties": {
|
|
104
|
+
"width": { "type": "integer", "minimum": 1, "maximum": 8192 },
|
|
105
|
+
"height": { "type": "integer", "minimum": 1, "maximum": 8192 },
|
|
106
|
+
"quality": { "type": "integer", "minimum": 1, "maximum": 100 },
|
|
107
|
+
"format": { "type": "string", "enum": ["image/avif", "image/webp", "image/jpeg", "image/png"] },
|
|
108
|
+
"fit": { "type": "string", "enum": ["contain", "cover", "fill", "inside", "outside"] }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
29
114
|
"regions": {
|
|
30
115
|
"type": ["array", "null"],
|
|
31
116
|
"description": "The regions to which the project will be deployed. Use \"global\" to deploy to all regions. More regions will incur higher costs.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gigadrive/network-config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/Gigadrive/sdk.git",
|
|
@@ -18,6 +18,21 @@
|
|
|
18
18
|
"types": "./dist/nextjs-adapter.d.ts",
|
|
19
19
|
"require": "./dist/nextjs-adapter.cjs",
|
|
20
20
|
"import": "./dist/nextjs-adapter.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./nextjs-cache-handler": {
|
|
23
|
+
"types": "./dist/nextjs-cache-handler.d.ts",
|
|
24
|
+
"require": "./dist/nextjs-cache-handler.js",
|
|
25
|
+
"import": "./dist/nextjs-cache-handler.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./nextjs-cache-components-handler": {
|
|
28
|
+
"types": "./dist/nextjs-cache-components-handler.d.ts",
|
|
29
|
+
"require": "./dist/nextjs-cache-components-handler.js",
|
|
30
|
+
"import": "./dist/nextjs-cache-components-handler.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./nextjs-image-loader": {
|
|
33
|
+
"types": "./dist/nextjs-image-loader.d.ts",
|
|
34
|
+
"require": "./dist/nextjs-image-loader.js",
|
|
35
|
+
"import": "./dist/nextjs-image-loader.mjs"
|
|
21
36
|
}
|
|
22
37
|
},
|
|
23
38
|
"main": "dist/index.js",
|
|
@@ -33,7 +48,7 @@
|
|
|
33
48
|
"minimatch": "^10.0.3",
|
|
34
49
|
"safe-regex2": "^5.0.0",
|
|
35
50
|
"yaml": "^2.8.1",
|
|
36
|
-
"@gigadrive/build-utils": "1.0.
|
|
51
|
+
"@gigadrive/build-utils": "1.0.3",
|
|
37
52
|
"@gigadrive/commons": "2.1.1"
|
|
38
53
|
},
|
|
39
54
|
"devDependencies": {
|
|
@@ -41,7 +56,8 @@
|
|
|
41
56
|
"@effect/platform-node": "^0.107.0",
|
|
42
57
|
"@types/node": "^24.13.3",
|
|
43
58
|
"effect": "^3.19.17",
|
|
44
|
-
"esbuild": "^0.28.0"
|
|
59
|
+
"esbuild": "^0.28.0",
|
|
60
|
+
"next": "16.2.10"
|
|
45
61
|
},
|
|
46
62
|
"peerDependencies": {
|
|
47
63
|
"@effect/platform": "^0.94.5 || ^0.96.0",
|
package/src/v4/schema.json
CHANGED
|
@@ -26,6 +26,91 @@
|
|
|
26
26
|
"type": ["boolean", "null"],
|
|
27
27
|
"description": "If true, the assets will be cached at the edge during deployment. This may increase the deployment time, depending on the size of the assets. Defaults to false."
|
|
28
28
|
},
|
|
29
|
+
"images": {
|
|
30
|
+
"type": ["object", "null"],
|
|
31
|
+
"description": "Managed image optimization policy for this deployment.",
|
|
32
|
+
"additionalProperties": false,
|
|
33
|
+
"properties": {
|
|
34
|
+
"localPatterns": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"maxItems": 64,
|
|
37
|
+
"items": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"additionalProperties": false,
|
|
40
|
+
"properties": {
|
|
41
|
+
"pathname": { "type": "string", "minLength": 1, "maxLength": 2048 },
|
|
42
|
+
"search": { "type": "string", "maxLength": 2048 }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"remotePatterns": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"maxItems": 64,
|
|
49
|
+
"items": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"required": ["hostname"],
|
|
52
|
+
"additionalProperties": false,
|
|
53
|
+
"properties": {
|
|
54
|
+
"protocol": { "type": "string", "enum": ["http", "https"] },
|
|
55
|
+
"hostname": { "type": "string", "minLength": 1, "maxLength": 253 },
|
|
56
|
+
"port": { "type": "string", "pattern": "^[0-9]{0,5}$" },
|
|
57
|
+
"pathname": { "type": "string", "minLength": 1, "maxLength": 2048 },
|
|
58
|
+
"search": { "type": "string", "maxLength": 2048 }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"widths": {
|
|
63
|
+
"type": "array",
|
|
64
|
+
"minItems": 1,
|
|
65
|
+
"maxItems": 64,
|
|
66
|
+
"uniqueItems": true,
|
|
67
|
+
"items": { "type": "integer", "minimum": 1, "maximum": 8192 }
|
|
68
|
+
},
|
|
69
|
+
"heights": {
|
|
70
|
+
"type": "array",
|
|
71
|
+
"maxItems": 64,
|
|
72
|
+
"uniqueItems": true,
|
|
73
|
+
"items": { "type": "integer", "minimum": 1, "maximum": 8192 }
|
|
74
|
+
},
|
|
75
|
+
"qualities": {
|
|
76
|
+
"type": "array",
|
|
77
|
+
"minItems": 1,
|
|
78
|
+
"maxItems": 100,
|
|
79
|
+
"uniqueItems": true,
|
|
80
|
+
"items": { "type": "integer", "minimum": 1, "maximum": 100 }
|
|
81
|
+
},
|
|
82
|
+
"formats": {
|
|
83
|
+
"type": "array",
|
|
84
|
+
"minItems": 1,
|
|
85
|
+
"maxItems": 4,
|
|
86
|
+
"uniqueItems": true,
|
|
87
|
+
"items": { "type": "string", "enum": ["image/avif", "image/webp", "image/jpeg", "image/png"] }
|
|
88
|
+
},
|
|
89
|
+
"minimumCacheTTL": { "type": "integer", "minimum": 0, "maximum": 31536000 },
|
|
90
|
+
"dangerouslyAllowSVG": { "type": "boolean" },
|
|
91
|
+
"contentSecurityPolicy": { "type": "string", "maxLength": 4096 },
|
|
92
|
+
"contentDispositionType": { "type": "string", "enum": ["inline", "attachment"] },
|
|
93
|
+
"maximumRedirects": { "type": "integer", "minimum": 0, "maximum": 10 },
|
|
94
|
+
"maximumResponseBody": { "type": "integer", "minimum": 1024, "maximum": 104857600 },
|
|
95
|
+
"variants": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"maxProperties": 100,
|
|
98
|
+
"propertyNames": { "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$" },
|
|
99
|
+
"additionalProperties": {
|
|
100
|
+
"type": "object",
|
|
101
|
+
"minProperties": 1,
|
|
102
|
+
"additionalProperties": false,
|
|
103
|
+
"properties": {
|
|
104
|
+
"width": { "type": "integer", "minimum": 1, "maximum": 8192 },
|
|
105
|
+
"height": { "type": "integer", "minimum": 1, "maximum": 8192 },
|
|
106
|
+
"quality": { "type": "integer", "minimum": 1, "maximum": 100 },
|
|
107
|
+
"format": { "type": "string", "enum": ["image/avif", "image/webp", "image/jpeg", "image/png"] },
|
|
108
|
+
"fit": { "type": "string", "enum": ["contain", "cover", "fill", "inside", "outside"] }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
29
114
|
"regions": {
|
|
30
115
|
"type": ["array", "null"],
|
|
31
116
|
"description": "The regions to which the project will be deployed. Use \"global\" to deploy to all regions. More regions will incur higher costs.",
|