princejs 1.7.0 → 1.7.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/helpers.d.ts CHANGED
@@ -1,17 +1,5 @@
1
1
  import type { PrinceRequest } from "./prince";
2
2
  export declare const cache: (ttl: number) => (handler: any) => (req: PrinceRequest) => Promise<any>;
3
3
  export declare const email: (to: string, subject: string, html: string) => Promise<void>;
4
- export declare const upload: (fieldName?: string) => (req: PrinceRequest) => Promise<{
5
- name: any;
6
- size: any;
7
- type: any;
8
- success: boolean;
9
- error?: undefined;
10
- } | {
11
- error: string;
12
- name?: undefined;
13
- size?: undefined;
14
- type?: undefined;
15
- success?: undefined;
16
- }>;
4
+ export declare const upload: () => (req: PrinceRequest) => Promise<Response>;
17
5
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,MAEvB,SAAS,GAAG,MAAY,KAAK,aAAa,iBASnD,CAAC;AAGF,eAAO,MAAM,KAAK,GAAU,IAAI,MAAM,EAAE,SAAS,MAAM,EAAE,MAAM,MAAM,kBAMpE,CAAC;AAGF,eAAO,MAAM,MAAM,GAAI,kBAAkB,MACzB,KAAK,aAAa;;;;;;;;;;;;EAiCjC,CAAC"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,MAEvB,SAAS,GAAG,MAAY,KAAK,aAAa,iBASnD,CAAC;AAGF,eAAO,MAAM,KAAK,GAAU,IAAI,MAAM,EAAE,SAAS,MAAM,EAAE,MAAM,MAAM,kBAMpE,CAAC;AAGF,eAAO,MAAM,MAAM,SACH,KAAK,aAAa,sBA4CjC,CAAC"}
package/dist/helpers.js CHANGED
@@ -20,31 +20,34 @@ var email = async (to, subject, html) => {
20
20
  body: JSON.stringify({ from: "no-reply@princejs.dev", to, subject, html })
21
21
  });
22
22
  };
23
- var upload = (fieldName = "file") => {
23
+ var upload = () => {
24
24
  return async (req) => {
25
25
  try {
26
- if (req.files && req.files[fieldName]) {
27
- const file = req.files[fieldName];
28
- return {
29
- name: file.name,
30
- size: file.size,
31
- type: file.type,
32
- success: true
33
- };
26
+ const contentType = req.headers.get("content-type") || "";
27
+ if (!contentType.includes("multipart/form-data")) {
28
+ return new Response(JSON.stringify({ error: "Expected multipart/form-data" }), { status: 400, headers: { "Content-Type": "application/json" } });
34
29
  }
35
- if (req.body && req.body.files && req.body.files[fieldName]) {
36
- const file = req.body.files[fieldName];
37
- return {
38
- name: file.name,
39
- size: file.size,
40
- type: file.type,
41
- success: true
42
- };
30
+ const formData = await req.formData();
31
+ const file = formData.get("file");
32
+ if (!file || !(file instanceof File)) {
33
+ return new Response(JSON.stringify({ error: "No file provided or invalid file" }), { status: 400, headers: { "Content-Type": "application/json" } });
43
34
  }
44
- return { error: `No file found with field name: ${fieldName}` };
35
+ const fileInfo = {
36
+ name: file.name,
37
+ size: file.size,
38
+ type: file.type,
39
+ lastModified: file.lastModified
40
+ };
41
+ return new Response(JSON.stringify(fileInfo), {
42
+ status: 200,
43
+ headers: { "Content-Type": "application/json" }
44
+ });
45
45
  } catch (error) {
46
- console.error("Upload processing error:", error);
47
- return { error: "File processing failed" };
46
+ console.error("Upload error:", error);
47
+ return new Response(JSON.stringify({ error: "Upload failed" }), {
48
+ status: 500,
49
+ headers: { "Content-Type": "application/json" }
50
+ });
48
51
  }
49
52
  };
50
53
  };
package/dist/jsx.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export interface JSXProps {
2
+ children?: any;
3
+ [key: string]: any;
4
+ }
5
+ export declare const jsx: (tag: string | Function, props: JSXProps, ...children: any[]) => any;
6
+ export declare const jsxs: (tag: string | Function, props: JSXProps, ...children: any[]) => any;
7
+ export declare const jsxDEV: (tag: string | Function, props: JSXProps, ...children: any[]) => any;
8
+ export declare const Fragment: (props: JSXProps) => any;
9
+ export declare const Html: (props: any) => string;
10
+ export declare const Head: (props: any) => string;
11
+ export declare const Body: (props: any) => string;
12
+ export declare const H1: (props: any) => string;
13
+ export declare const P: (props: any) => string;
14
+ export declare const Div: (props: any) => string;
15
+ export declare const render: (jsxContent: any) => Response;
16
+ //# sourceMappingURL=jsx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,eAAO,MAAM,GAAG,GAAI,KAAK,MAAM,GAAG,QAAQ,EAAE,OAAO,QAAQ,EAAE,GAAG,UAAU,GAAG,EAAE,KAAG,GAcjF,CAAC;AAEF,eAAO,MAAM,IAAI,QAhBQ,MAAM,GAAG,QAAQ,SAAS,QAAQ,eAAe,GAAG,EAAE,KAAG,GAgB3D,CAAC;AACxB,eAAO,MAAM,MAAM,QAjBM,MAAM,GAAG,QAAQ,SAAS,QAAQ,eAAe,GAAG,EAAE,KAAG,GAiBzD,CAAC;AAC1B,eAAO,MAAM,QAAQ,GAAI,OAAO,QAAQ,QAAmB,CAAC;AAI5D,eAAO,MAAM,IAAI,GAAI,OAAO,GAAG,WAE9B,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,OAAO,GAAG,WAE9B,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,OAAO,GAAG,WAE9B,CAAC;AAEF,eAAO,MAAM,EAAE,GAAI,OAAO,GAAG,WAE5B,CAAC;AAEF,eAAO,MAAM,CAAC,GAAI,OAAO,GAAG,WAE3B,CAAC;AAEF,eAAO,MAAM,GAAG,GAAI,OAAO,GAAG,WAU7B,CAAC;AAIF,eAAO,MAAM,MAAM,GAAI,YAAY,GAAG,aAKrC,CAAC"}
package/dist/jsx.js ADDED
@@ -0,0 +1,66 @@
1
+ // @bun
2
+ // src/jsx.ts
3
+ var jsx = (tag, props, ...children) => {
4
+ if (typeof tag === "function") {
5
+ return tag({ ...props, children });
6
+ }
7
+ const attrs = Object.entries(props || {}).filter(([key]) => key !== "children").map(([key, value]) => ` ${key}="${String(value).replace(/"/g, "&quot;")}"`).join("");
8
+ const content = children.flat().filter(Boolean).join("");
9
+ return `<${tag}${attrs}>${content}</${tag}>`;
10
+ };
11
+ var jsxs = jsx;
12
+ var jsxDEV = jsx;
13
+ var Fragment = (props) => props.children;
14
+ var Html = (props) => {
15
+ return `<html>${renderChildren(props.children)}</html>`;
16
+ };
17
+ var Head = (props) => {
18
+ return `<head>${renderChildren(props.children)}</head>`;
19
+ };
20
+ var Body = (props) => {
21
+ return `<body>${renderChildren(props.children)}</body>`;
22
+ };
23
+ var H1 = (props) => {
24
+ return `<h1>${renderChildren(props.children)}</h1>`;
25
+ };
26
+ var P = (props) => {
27
+ return `<p>${renderChildren(props.children)}</p>`;
28
+ };
29
+ var Div = (props) => {
30
+ const attrs = Object.keys(props).filter((key) => key !== "children").map((key) => {
31
+ if (key === "className")
32
+ return `class="${props[key]}"`;
33
+ return `${key}="${props[key]}"`;
34
+ }).join(" ");
35
+ return `<div ${attrs}>${renderChildren(props.children)}</div>`;
36
+ };
37
+ var render = (jsxContent) => {
38
+ const html = typeof jsxContent === "string" ? jsxContent : String(jsxContent);
39
+ return new Response(html, {
40
+ headers: { "Content-Type": "text/html; charset=utf-8" }
41
+ });
42
+ };
43
+ var renderChildren = (children) => {
44
+ if (!children)
45
+ return "";
46
+ if (Array.isArray(children))
47
+ return children.map(renderChildren).join("");
48
+ if (typeof children === "object") {
49
+ const rendered = render(children);
50
+ return typeof rendered === "string" ? rendered : "";
51
+ }
52
+ return String(children);
53
+ };
54
+ export {
55
+ render,
56
+ jsxs,
57
+ jsxDEV,
58
+ jsx,
59
+ P,
60
+ Html,
61
+ Head,
62
+ H1,
63
+ Fragment,
64
+ Div,
65
+ Body
66
+ };
@@ -1,11 +1,11 @@
1
1
  import type { PrinceRequest } from "./prince";
2
2
  import { z } from "zod";
3
3
  type Next = () => Promise<Response | undefined>;
4
- export declare const cors: (origin?: string) => (req: PrinceRequest, next: Next) => Promise<Response | undefined>;
4
+ export declare const cors: (origin?: string) => (req: any, next: Function) => Promise<any>;
5
5
  export declare const logger: () => (req: PrinceRequest, next: Next) => Promise<Response | undefined>;
6
- export declare const signJWT: (payload: object, key: Uint8Array, exp?: string) => Promise<string>;
6
+ export declare const signJWT: (payload: any, secret: Uint8Array, expiresIn: string) => Promise<string>;
7
7
  export declare const jwt: (key: Uint8Array) => (req: PrinceRequest, next: Next) => Promise<Response | undefined>;
8
8
  export declare const rateLimit: (max: number, window?: number) => (req: PrinceRequest, next: Next) => Promise<Response | undefined>;
9
- export declare const validate: <T>(schema: z.ZodSchema<T>) => (req: PrinceRequest, next: Next) => Promise<Response | undefined>;
9
+ export declare const validate: (schema: z.ZodSchema) => (req: any, next: Function) => Promise<any>;
10
10
  export {};
11
11
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,KAAK,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;AAIhD,eAAO,MAAM,IAAI,GAAI,eAAY,MACjB,KAAK,aAAa,EAAE,MAAM,IAAI,kCAgC7C,CAAC;AAGF,eAAO,MAAM,MAAM,SACH,KAAK,aAAa,EAAE,MAAM,IAAI,kCAM7C,CAAC;AAGF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