vicket 0.1.1 → 1.0.0
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/next.js +3 -3
- package/dist/nuxt.d.ts +6 -0
- package/dist/nuxt.js +66 -0
- package/dist/server.js +3 -3
- package/dist/sveltekit.d.ts +21 -0
- package/dist/sveltekit.js +54 -0
- package/package.json +14 -2
package/dist/next.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/next.ts
|
|
2
2
|
function createVicketProxy(options) {
|
|
3
3
|
return async function proxy(req, context) {
|
|
4
|
-
const apiUrl = (options?.apiUrl || process.env.VICKET_API_URL || "").replace(/\/+$/, "");
|
|
4
|
+
const apiUrl = (options?.apiUrl || process.env.VICKET_API_URL || "https://api.vicket.app/api/v1").replace(/\/+$/, "");
|
|
5
5
|
const apiKey = options?.apiKey || process.env.VICKET_API_KEY || "";
|
|
6
|
-
if (!
|
|
6
|
+
if (!apiKey) {
|
|
7
7
|
return Response.json(
|
|
8
|
-
{ error: "Missing
|
|
8
|
+
{ error: "Missing VICKET_API_KEY server environment variable." },
|
|
9
9
|
{ status: 500 }
|
|
10
10
|
);
|
|
11
11
|
}
|
package/dist/nuxt.d.ts
ADDED
package/dist/nuxt.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/nuxt.ts
|
|
2
|
+
function createVicketProxy(options) {
|
|
3
|
+
return async (event) => {
|
|
4
|
+
const h3 = await Function('return import("h3")')();
|
|
5
|
+
const { getQuery, readBody, readMultipartFormData, getMethod, createError } = h3;
|
|
6
|
+
const apiUrl = (options?.apiUrl || process.env.VICKET_API_URL || "https://api.vicket.app/api/v1").replace(/\/+$/, "");
|
|
7
|
+
const apiKey = options?.apiKey || process.env.VICKET_API_KEY || "";
|
|
8
|
+
if (!apiKey) {
|
|
9
|
+
throw createError({
|
|
10
|
+
statusCode: 500,
|
|
11
|
+
statusMessage: "Missing VICKET_API_KEY environment variable."
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const path = event.context.params?.path || "";
|
|
15
|
+
const method = getMethod(event);
|
|
16
|
+
const query = getQuery(event);
|
|
17
|
+
const queryString = new URLSearchParams(
|
|
18
|
+
Object.entries(query).reduce((acc, [k, v]) => {
|
|
19
|
+
if (v !== void 0 && v !== null) acc[k] = String(v);
|
|
20
|
+
return acc;
|
|
21
|
+
}, {})
|
|
22
|
+
).toString();
|
|
23
|
+
const targetUrl = `${apiUrl}/public/support/${path}${queryString ? `?${queryString}` : ""}`;
|
|
24
|
+
const contentType = event.node.req.headers["content-type"] || "";
|
|
25
|
+
const isMultipart = contentType.includes("multipart/form-data");
|
|
26
|
+
let fetchOptions;
|
|
27
|
+
if (method === "GET" || method === "HEAD") {
|
|
28
|
+
fetchOptions = {
|
|
29
|
+
method,
|
|
30
|
+
headers: { "X-Api-Key": apiKey, "Content-Type": "application/json" }
|
|
31
|
+
};
|
|
32
|
+
} else if (isMultipart) {
|
|
33
|
+
const parts = await readMultipartFormData(event);
|
|
34
|
+
const formData = new FormData();
|
|
35
|
+
if (parts) {
|
|
36
|
+
for (const part of parts) {
|
|
37
|
+
if (part.filename) {
|
|
38
|
+
const blob = new Blob([part.data], { type: part.type || "application/octet-stream" });
|
|
39
|
+
formData.append(part.name || "file", blob, part.filename);
|
|
40
|
+
} else {
|
|
41
|
+
formData.append(part.name || "field", part.data.toString("utf-8"));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
fetchOptions = {
|
|
46
|
+
method,
|
|
47
|
+
headers: { "X-Api-Key": apiKey },
|
|
48
|
+
body: formData
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
const body = await readBody(event);
|
|
52
|
+
fetchOptions = {
|
|
53
|
+
method,
|
|
54
|
+
headers: { "X-Api-Key": apiKey, "Content-Type": "application/json" },
|
|
55
|
+
body: body ? JSON.stringify(body) : void 0
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const response = await fetch(targetUrl, fetchOptions);
|
|
59
|
+
const data = await response.json();
|
|
60
|
+
event.node.res.statusCode = response.status;
|
|
61
|
+
return data;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
createVicketProxy
|
|
66
|
+
};
|
package/dist/server.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/server.ts
|
|
2
2
|
function createServerClient(options) {
|
|
3
|
-
const apiUrl = (options?.apiUrl || process.env.VICKET_API_URL || "").replace(/\/+$/, "");
|
|
3
|
+
const apiUrl = (options?.apiUrl || process.env.VICKET_API_URL || "https://api.vicket.app/api/v1").replace(/\/+$/, "");
|
|
4
4
|
const apiKey = options?.apiKey || process.env.VICKET_API_KEY || "";
|
|
5
5
|
async function fetchInit() {
|
|
6
|
-
if (!
|
|
6
|
+
if (!apiKey) throw new Error("Missing VICKET_API_KEY.");
|
|
7
7
|
const res = await fetch(`${apiUrl}/public/support/init`, {
|
|
8
8
|
method: "GET",
|
|
9
9
|
cache: "no-store",
|
|
@@ -16,7 +16,7 @@ function createServerClient(options) {
|
|
|
16
16
|
return payload.data;
|
|
17
17
|
}
|
|
18
18
|
async function fetchThread(token) {
|
|
19
|
-
if (!
|
|
19
|
+
if (!apiKey) throw new Error("Missing VICKET_API_KEY.");
|
|
20
20
|
const res = await fetch(
|
|
21
21
|
`${apiUrl}/public/support/ticket?token=${encodeURIComponent(token)}`,
|
|
22
22
|
{
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare function createVicketProxy(options?: {
|
|
2
|
+
apiUrl?: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
}): {
|
|
5
|
+
GET: ({ params, url }: {
|
|
6
|
+
params: {
|
|
7
|
+
path: string;
|
|
8
|
+
};
|
|
9
|
+
url: URL;
|
|
10
|
+
request: Request;
|
|
11
|
+
}) => Promise<Response>;
|
|
12
|
+
POST: ({ params, url, request }: {
|
|
13
|
+
params: {
|
|
14
|
+
path: string;
|
|
15
|
+
};
|
|
16
|
+
url: URL;
|
|
17
|
+
request: Request;
|
|
18
|
+
}) => Promise<Response>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { createVicketProxy };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/sveltekit.ts
|
|
2
|
+
function createVicketProxy(options) {
|
|
3
|
+
const getConfig = () => {
|
|
4
|
+
const apiUrl = (options?.apiUrl || process.env.VICKET_API_URL || "https://api.vicket.app/api/v1").replace(/\/+$/, "");
|
|
5
|
+
const apiKey = options?.apiKey || process.env.VICKET_API_KEY || "";
|
|
6
|
+
return { apiUrl, apiKey };
|
|
7
|
+
};
|
|
8
|
+
async function handle(request, params, url) {
|
|
9
|
+
const { apiUrl, apiKey } = getConfig();
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
return Response.json(
|
|
12
|
+
{ success: false, error: "Missing VICKET_API_KEY." },
|
|
13
|
+
{ status: 500 }
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const path = params.path || "";
|
|
17
|
+
const query = url.searchParams.toString();
|
|
18
|
+
const target = `${apiUrl}/public/support/${path}${query ? `?${query}` : ""}`;
|
|
19
|
+
const contentType = request.headers.get("Content-Type") || "";
|
|
20
|
+
const isFormData = contentType.includes("multipart/form-data");
|
|
21
|
+
let upstream;
|
|
22
|
+
if (request.method === "GET" || request.method === "HEAD") {
|
|
23
|
+
upstream = await fetch(target, {
|
|
24
|
+
method: request.method,
|
|
25
|
+
headers: { "X-Api-Key": apiKey, "Content-Type": "application/json" }
|
|
26
|
+
});
|
|
27
|
+
} else if (isFormData) {
|
|
28
|
+
const formData = await request.formData();
|
|
29
|
+
upstream = await fetch(target, {
|
|
30
|
+
method: request.method,
|
|
31
|
+
headers: { "X-Api-Key": apiKey },
|
|
32
|
+
body: formData
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
const body = await request.text();
|
|
36
|
+
upstream = await fetch(target, {
|
|
37
|
+
method: request.method,
|
|
38
|
+
headers: { "X-Api-Key": apiKey, "Content-Type": "application/json" },
|
|
39
|
+
body
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const responseBody = await upstream.text();
|
|
43
|
+
return new Response(responseBody, {
|
|
44
|
+
status: upstream.status,
|
|
45
|
+
headers: { "Content-Type": upstream.headers.get("Content-Type") || "application/json" }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const GET = ({ params, url }) => handle(new Request(url), params, url);
|
|
49
|
+
const POST = ({ params, url, request }) => handle(request, params, url);
|
|
50
|
+
return { GET, POST };
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
createVicketProxy
|
|
54
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vicket",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Vicket support widget SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
"./next": {
|
|
16
16
|
"import": "./dist/next.js",
|
|
17
17
|
"types": "./dist/next.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./nuxt": {
|
|
20
|
+
"import": "./dist/nuxt.js",
|
|
21
|
+
"types": "./dist/nuxt.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./sveltekit": {
|
|
24
|
+
"import": "./dist/sveltekit.js",
|
|
25
|
+
"types": "./dist/sveltekit.d.ts"
|
|
18
26
|
}
|
|
19
27
|
},
|
|
20
28
|
"files": [
|
|
@@ -30,11 +38,15 @@
|
|
|
30
38
|
"typescript": "^5.9.0"
|
|
31
39
|
},
|
|
32
40
|
"peerDependencies": {
|
|
33
|
-
"next": ">=14.0.0"
|
|
41
|
+
"next": ">=14.0.0",
|
|
42
|
+
"h3": ">=1.0.0"
|
|
34
43
|
},
|
|
35
44
|
"peerDependenciesMeta": {
|
|
36
45
|
"next": {
|
|
37
46
|
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"h3": {
|
|
49
|
+
"optional": true
|
|
38
50
|
}
|
|
39
51
|
}
|
|
40
52
|
}
|