@pagesolver/sdk 1.0.5 → 1.1.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/README.md CHANGED
@@ -19,34 +19,36 @@ import { PageSolverClient } from "@pagesolver/sdk";
19
19
 
20
20
  const client = new PageSolverClient("your-business-key");
21
21
 
22
- // Get comparisons
22
+ // Get comparisons - returns array directly
23
23
  const comparisons = await client.getComparisons();
24
- if (comparisons.data) {
25
- console.log(comparisons.data.comparisons);
26
- }
24
+ console.log(comparisons); // ComparisonImage[]
27
25
 
28
- // Get showcases
26
+ // Get showcases - returns array directly
29
27
  const showcases = await client.getShowcases();
30
- if (showcases.data) {
31
- console.log(showcases.data.showcases);
32
- }
28
+ console.log(showcases); // ShowcaseImage[]
33
29
 
34
- // Get quick quotes
30
+ // Get quick quotes - returns array directly
35
31
  const quickQuotes = await client.getQuickQuotes();
36
- if (quickQuotes.data) {
37
- console.log(quickQuotes.data.quotes);
38
- }
32
+ console.log(quickQuotes); // QuickQuote[]
39
33
 
40
- // Send contact form
41
- const contactResult = await client.contact({
34
+ // Send contact form - returns boolean
35
+ const success = await client.contact({
42
36
  name: "John Doe",
43
37
  email: "john@example.com",
44
38
  message: "Hello from the SDK!",
45
39
  });
46
40
 
47
- if (contactResult.data?.success) {
41
+ if (success) {
48
42
  console.log("Contact form sent successfully!");
49
43
  }
44
+
45
+ // Error handling with try/catch
46
+ try {
47
+ const comparisons = await client.getComparisons();
48
+ console.log(`Found ${comparisons.length} comparisons`);
49
+ } catch (error) {
50
+ console.error("Failed to get comparisons:", error.message);
51
+ }
50
52
  ```
51
53
 
52
54
  ## API Reference
@@ -68,8 +70,8 @@ new PageSolverClient(businessKey: string)
68
70
  Retrieves all comparison images for your business.
69
71
 
70
72
  ```typescript
71
- const result = await client.getComparisons();
72
- // Returns: ApiResponse<{ comparisons: ComparisonImage[] }>
73
+ const comparisons = await client.getComparisons();
74
+ // Returns: ComparisonImage[]
73
75
  ```
74
76
 
75
77
  ##### `getShowcases()`
@@ -77,8 +79,8 @@ const result = await client.getComparisons();
77
79
  Retrieves all showcase images for your business.
78
80
 
79
81
  ```typescript
80
- const result = await client.getShowcases();
81
- // Returns: ApiResponse<{ showcases: ShowcaseImage[] }>
82
+ const showcases = await client.getShowcases();
83
+ // Returns: ShowcaseImage[]
82
84
  ```
83
85
 
84
86
  ##### `getQuickQuotes()`
@@ -86,8 +88,8 @@ const result = await client.getShowcases();
86
88
  Retrieves all quick quotes for your business.
87
89
 
88
90
  ```typescript
89
- const result = await client.getQuickQuotes();
90
- // Returns: ApiResponse<{ quotes: QuickQuote[] }>
91
+ const quotes = await client.getQuickQuotes();
92
+ // Returns: QuickQuote[]
91
93
  ```
92
94
 
93
95
  ##### `contact(data: ContactData)`
@@ -95,13 +97,13 @@ const result = await client.getQuickQuotes();
95
97
  Sends a contact form submission.
96
98
 
97
99
  ```typescript
98
- const result = await client.contact({
100
+ const success = await client.contact({
99
101
  name: "John Doe",
100
102
  email: "john@example.com",
101
103
  phone: "+1234567890", // optional
102
104
  message: "Hello!", // optional
103
105
  });
104
- // Returns: ApiResponse<ContactResponse>
106
+ // Returns: boolean
105
107
  ```
106
108
 
107
109
  ## Types
@@ -0,0 +1,49 @@
1
+ export interface ComparisonImage {
2
+ id: string;
3
+ businessId: string;
4
+ beforeUrl: string;
5
+ afterUrl: string;
6
+ description: string | null;
7
+ createdAt: Date;
8
+ title: string;
9
+ }
10
+ export interface ShowcaseImage {
11
+ id: string;
12
+ businessId: string;
13
+ blobUrl: string[];
14
+ createdAt: Date;
15
+ description: string | null;
16
+ title: string;
17
+ }
18
+ export interface QuickQuote {
19
+ id: string;
20
+ businessId: string;
21
+ parentId: string | null;
22
+ name: string;
23
+ description: string | null;
24
+ basePrice: string | null;
25
+ enabled: boolean;
26
+ createdAt: Date;
27
+ updatedAt: Date;
28
+ }
29
+ interface ContactData {
30
+ name: string;
31
+ email: string;
32
+ phone?: string;
33
+ message?: string;
34
+ }
35
+ interface ContactResponse {
36
+ success: boolean;
37
+ }
38
+ export declare class PageSolverClient {
39
+ private baseUrl;
40
+ private businessKey;
41
+ constructor(businessKey: string);
42
+ private request;
43
+ getComparisons(): Promise<ComparisonImage[]>;
44
+ getShowcases(): Promise<ShowcaseImage[]>;
45
+ getQuickQuotes(): Promise<QuickQuote[]>;
46
+ contact(data: ContactData): Promise<boolean>;
47
+ }
48
+ export type { ContactData, ContactResponse };
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAQD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,WAAW,CAAS;gBAEhB,WAAW,EAAE,MAAM;YAIjB,OAAO;IA0Cf,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAQ5C,YAAY,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAQxC,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAQvC,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CAOnD;AAGD,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- class i{baseUrl="https://pagesolver.com/api/v1";businessKey;constructor(s){this.businessKey=s}async request(s,r={}){try{let t=`${this.baseUrl}${s}`,a={"Content-Type":"application/json","x-business-key":this.businessKey,...r.headers},e=await fetch(t,{...r,headers:a}),n;if(e.headers.get("Content-Type")?.includes("application/json"))n=await e.json();else n=await e.text();if(!e.ok)return{error:n?.error||"An unknown error occurred",status:e.status};return{data:n,status:e.status}}catch(t){return{error:t instanceof Error?t.message:"Network error",status:500}}}async getComparisons(){return this.request("/business/comparisons")}async getShowcases(){return this.request("/business/showcases")}async getQuickQuotes(){return this.request("/business/quick-quotes")}async contact(s){return this.request("/business/contact",{method:"POST",body:JSON.stringify(s)})}}export{i as PageSolverClient};
1
+ class i{baseUrl="https://pagesolver.com/api/v1";businessKey;constructor(e){this.businessKey=e}async request(e,n={}){try{let t=`${this.baseUrl}${e}`,o={"Content-Type":"application/json","x-business-key":this.businessKey,...n.headers},s=await fetch(t,{...n,headers:o}),r;if(s.headers.get("Content-Type")?.includes("application/json"))r=await s.json();else r=await s.text();if(!s.ok){let a=r?.error||"An unknown error occurred";throw new Error(`API Error (${s.status}): ${a}`)}return r}catch(t){if(t instanceof Error)throw t;throw new Error("Network error occurred")}}async getComparisons(){return(await this.request("/business/comparisons")).comparisons}async getShowcases(){return(await this.request("/business/showcases")).showcases}async getQuickQuotes(){return(await this.request("/business/quick-quotes")).quotes}async contact(e){return(await this.request("/business/contact",{method:"POST",body:JSON.stringify(e)})).success}}export{i as PageSolverClient};
2
2
 
3
- //# debugId=7DE63FC008843B0364756E2164756E21
3
+ //# debugId=BD13C04526AB4A5864756E2164756E21
package/dist/index.js.map CHANGED
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
4
  "sourcesContent": [
5
- "// Database schema types\nexport interface ComparisonImage {\n id: string;\n businessId: string;\n beforeUrl: string;\n afterUrl: string;\n description: string | null;\n createdAt: Date;\n title: string;\n}\n\nexport interface ShowcaseImage {\n id: string;\n businessId: string;\n blobUrl: string[];\n createdAt: Date;\n description: string | null;\n title: string;\n}\n\nexport interface QuickQuote {\n id: string;\n businessId: string;\n parentId: string | null;\n name: string;\n description: string | null;\n basePrice: string | null;\n enabled: boolean;\n createdAt: Date;\n updatedAt: Date;\n}\n\ninterface ApiResponse<T> {\n data?: T;\n error?: string;\n status: number;\n}\n\ninterface ContactData {\n name: string;\n email: string;\n phone?: string;\n message?: string;\n}\n\ninterface ContactResponse {\n success: boolean;\n}\n\nexport class PageSolverClient {\n private baseUrl = \"https://pagesolver.com/api/v1\";\n private businessKey: string;\n\n constructor(businessKey: string) {\n this.businessKey = businessKey;\n }\n\n private async request<T>(\n endpoint: string,\n options: RequestInit = {}\n ): Promise<ApiResponse<T>> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n\n const headers = {\n \"Content-Type\": \"application/json\",\n \"x-business-key\": this.businessKey,\n ...options.headers,\n };\n\n const response = await fetch(url, {\n ...options,\n headers,\n });\n\n let data: unknown;\n const contentType = response.headers.get(\"Content-Type\");\n if (contentType?.includes(\"application/json\")) {\n data = await response.json();\n } else {\n data = await response.text();\n }\n\n if (!response.ok) {\n return {\n error:\n (data as { error?: string })?.error || \"An unknown error occurred\",\n status: response.status,\n };\n }\n\n return {\n data: data as T,\n status: response.status,\n };\n } catch (error) {\n return {\n error: error instanceof Error ? error.message : \"Network error\",\n status: 500,\n };\n }\n }\n\n // Comparison Images\n async getComparisons(): Promise<\n ApiResponse<{ comparisons: ComparisonImage[] }>\n > {\n return this.request<{ comparisons: ComparisonImage[] }>(\n \"/business/comparisons\"\n );\n }\n\n // Showcase Images\n async getShowcases(): Promise<ApiResponse<{ showcases: ShowcaseImage[] }>> {\n return this.request<{ showcases: ShowcaseImage[] }>(\"/business/showcases\");\n }\n\n // Quick Quotes\n async getQuickQuotes(): Promise<ApiResponse<{ quotes: QuickQuote[] }>> {\n return this.request<{ quotes: QuickQuote[] }>(\"/business/quick-quotes\");\n }\n\n // Contact\n async contact(data: ContactData): Promise<ApiResponse<ContactResponse>> {\n return this.request<ContactResponse>(\"/business/contact\", {\n method: \"POST\",\n body: JSON.stringify(data),\n });\n }\n}\n\n// Export types for consumers\nexport type { ApiResponse, ContactData, ContactResponse };\n"
5
+ "// Database schema types\nexport interface ComparisonImage {\n id: string;\n businessId: string;\n beforeUrl: string;\n afterUrl: string;\n description: string | null;\n createdAt: Date;\n title: string;\n}\n\nexport interface ShowcaseImage {\n id: string;\n businessId: string;\n blobUrl: string[];\n createdAt: Date;\n description: string | null;\n title: string;\n}\n\nexport interface QuickQuote {\n id: string;\n businessId: string;\n parentId: string | null;\n name: string;\n description: string | null;\n basePrice: string | null;\n enabled: boolean;\n createdAt: Date;\n updatedAt: Date;\n}\n\ninterface ApiResponse<T> {\n data?: T;\n error?: string;\n status: number;\n}\n\ninterface ContactData {\n name: string;\n email: string;\n phone?: string;\n message?: string;\n}\n\ninterface ContactResponse {\n success: boolean;\n}\n\nexport class PageSolverClient {\n private baseUrl = \"https://pagesolver.com/api/v1\";\n private businessKey: string;\n\n constructor(businessKey: string) {\n this.businessKey = businessKey;\n }\n\n private async request<T>(\n endpoint: string,\n options: RequestInit = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n\n const headers = {\n \"Content-Type\": \"application/json\",\n \"x-business-key\": this.businessKey,\n ...options.headers,\n };\n\n const response = await fetch(url, {\n ...options,\n headers,\n });\n\n let data: unknown;\n const contentType = response.headers.get(\"Content-Type\");\n if (contentType?.includes(\"application/json\")) {\n data = await response.json();\n } else {\n data = await response.text();\n }\n\n if (!response.ok) {\n const errorMessage =\n (data as { error?: string })?.error || \"An unknown error occurred\";\n throw new Error(`API Error (${response.status}): ${errorMessage}`);\n }\n\n return data as T;\n } catch (error) {\n if (error instanceof Error) {\n throw error;\n }\n throw new Error(\"Network error occurred\");\n }\n }\n\n // Comparison Images\n async getComparisons(): Promise<ComparisonImage[]> {\n const response = await this.request<{ comparisons: ComparisonImage[] }>(\n \"/business/comparisons\"\n );\n return response.comparisons;\n }\n\n // Showcase Images\n async getShowcases(): Promise<ShowcaseImage[]> {\n const response = await this.request<{ showcases: ShowcaseImage[] }>(\n \"/business/showcases\"\n );\n return response.showcases;\n }\n\n // Quick Quotes\n async getQuickQuotes(): Promise<QuickQuote[]> {\n const response = await this.request<{ quotes: QuickQuote[] }>(\n \"/business/quick-quotes\"\n );\n return response.quotes;\n }\n\n // Contact\n async contact(data: ContactData): Promise<boolean> {\n const response = await this.request<ContactResponse>(\"/business/contact\", {\n method: \"POST\",\n body: JSON.stringify(data),\n });\n return response.success;\n }\n}\n\n// Export types for consumers\nexport type { ContactData, ContactResponse };\n"
6
6
  ],
7
- "mappings": "AAiDO,MAAM,CAAiB,CACpB,QAAU,gCACV,YAER,WAAW,CAAC,EAAqB,CAC/B,KAAK,YAAc,OAGP,QAAU,CACtB,EACA,EAAuB,CAAC,EACC,CACzB,GAAI,CACF,IAAM,EAAM,GAAG,KAAK,UAAU,IAExB,EAAU,CACd,eAA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C,MAAM,IAAI,MAAM,cAAc,EAAS,YAAY,GAAc,EAGnE,OAAO,EACP,MAAO,EAAO,CACd,GAAI,aAAiB,MACnB,MAAM,EAER,MAAM,IAAI,MAAM,wBAAwB,QAKtC,eAAc,EAA+B,CAIjD,OAHiB,MAAM,KAAK,QAC1B,uBACF,GACgB,iBAIZ,aAAY,EAA6B,CAI7C,OAHiB,MAAM,KAAK,QAC1B,qBACF,GACgB,eAIZ,eAAc,EAA0B,CAI5C,OAHiB,MAAM,KAAK,QAC1B,wBACF,GACgB,YAIZ,QAAO,CAAC,EAAqC,CAKjD,OAJiB,MAAM,KAAK,QAAyB,oBAAqB,CACxE,OAAQ,OACR,KAAM,KAAK,UAAU,CAAI,CAC3B,CAAC,GACe,QAEpB",
8
+ "debugId": "BD13C04526AB4A5864756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagesolver/sdk",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "Official SDK for PageSolver API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "bun build src/index.ts --outdir dist --target node --minify --sourcemap=external && bun run build:types",
20
- "build:types": "bunx tsc --emitDeclarationOnly --outDir dist",
20
+ "build:types": "bunx tsc --project tsconfig.build.json",
21
21
  "dev": "bun --watch src/index.ts",
22
22
  "test": "bun test",
23
23
  "lint": "bunx @biomejs/biome check src",