@pagesolver/sdk 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/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # PageSolver SDK
2
+
3
+ Official TypeScript/JavaScript SDK for the PageSolver API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @pagesolver/sdk
9
+ # or
10
+ bun add @pagesolver/sdk
11
+ # or
12
+ yarn add @pagesolver/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { PageSolverClient } from "@pagesolver/sdk";
19
+
20
+ const client = new PageSolverClient("your-business-key");
21
+
22
+ // Get comparisons
23
+ const comparisons = await client.getComparisons();
24
+ if (comparisons.data) {
25
+ console.log(comparisons.data.comparisons);
26
+ }
27
+
28
+ // Get showcases
29
+ const showcases = await client.getShowcases();
30
+ if (showcases.data) {
31
+ console.log(showcases.data.showcases);
32
+ }
33
+
34
+ // Send contact form
35
+ const contactResult = await client.contact({
36
+ name: "John Doe",
37
+ email: "john@example.com",
38
+ message: "Hello from the SDK!",
39
+ });
40
+
41
+ if (contactResult.data?.success) {
42
+ console.log("Contact form sent successfully!");
43
+ }
44
+ ```
45
+
46
+ ## API Reference
47
+
48
+ ### PageSolverClient
49
+
50
+ #### Constructor
51
+
52
+ ```typescript
53
+ new PageSolverClient(businessKey: string)
54
+ ```
55
+
56
+ - `businessKey`: Your PageSolver business API key
57
+
58
+ #### Methods
59
+
60
+ ##### `getComparisons()`
61
+
62
+ Retrieves all comparison images for your business.
63
+
64
+ ```typescript
65
+ const result = await client.getComparisons();
66
+ // Returns: ApiResponse<{ comparisons: ComparisonImage[] }>
67
+ ```
68
+
69
+ ##### `getShowcases()`
70
+
71
+ Retrieves all showcase images for your business.
72
+
73
+ ```typescript
74
+ const result = await client.getShowcases();
75
+ // Returns: ApiResponse<{ showcases: ShowcaseImage[] }>
76
+ ```
77
+
78
+ ##### `contact(data: ContactData)`
79
+
80
+ Sends a contact form submission.
81
+
82
+ ```typescript
83
+ const result = await client.contact({
84
+ name: "John Doe",
85
+ email: "john@example.com",
86
+ phone: "+1234567890", // optional
87
+ message: "Hello!", // optional
88
+ });
89
+ // Returns: ApiResponse<ContactResponse>
90
+ ```
91
+
92
+ ## Types
93
+
94
+ ### ComparisonImage
95
+
96
+ ```typescript
97
+ interface ComparisonImage {
98
+ id: string;
99
+ url: string;
100
+ title?: string;
101
+ description?: string;
102
+ createdAt: string;
103
+ updatedAt: string;
104
+ }
105
+ ```
106
+
107
+ ### ShowcaseImage
108
+
109
+ ```typescript
110
+ interface ShowcaseImage {
111
+ id: string;
112
+ url: string;
113
+ title?: string;
114
+ description?: string;
115
+ createdAt: string;
116
+ updatedAt: string;
117
+ }
118
+ ```
119
+
120
+ ### ContactData
121
+
122
+ ```typescript
123
+ interface ContactData {
124
+ name: string;
125
+ email: string;
126
+ phone?: string;
127
+ message?: string;
128
+ }
129
+ ```
130
+
131
+ ### ApiResponse
132
+
133
+ ```typescript
134
+ interface ApiResponse<T> {
135
+ data?: T;
136
+ error?: string;
137
+ status: number;
138
+ }
139
+ ```
140
+
141
+ ## Error Handling
142
+
143
+ All methods return an `ApiResponse<T>` object that contains either:
144
+
145
+ - `data`: The successful response data
146
+ - `error`: An error message if the request failed
147
+ - `status`: HTTP status code
148
+
149
+ ```typescript
150
+ const result = await client.getComparisons();
151
+
152
+ if (result.error) {
153
+ console.error("Error:", result.error);
154
+ console.error("Status:", result.status);
155
+ } else {
156
+ console.log("Success:", result.data);
157
+ }
158
+ ```
159
+
160
+ ## Development
161
+
162
+ ### Building
163
+
164
+ ```bash
165
+ bun run build
166
+ ```
167
+
168
+ ### Testing
169
+
170
+ ```bash
171
+ bun test
172
+ ```
173
+
174
+ ### Linting
175
+
176
+ ```bash
177
+ bun run lint
178
+ bun run lint:fix
179
+ ```
180
+
181
+ ### Type Checking
182
+
183
+ ```bash
184
+ bun run type-check
185
+ ```
186
+
187
+ ## License
188
+
189
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ class o{baseUrl="https://pagesolver.com/api/v1";businessKey;constructor(e){this.businessKey=e}async request(e,t={}){try{let n=`${this.baseUrl}${e}`,i={"Content-Type":"application/json","x-business-key":this.businessKey,...t.headers},s=await fetch(n,{...t,headers:i}),r;if(s.headers.get("Content-Type")?.includes("application/json"))r=await s.json();else r=await s.text();if(!s.ok)return{error:r?.error||"An unknown error occurred",status:s.status};return{data:r,status:s.status}}catch(n){return{error:n instanceof Error?n.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 createQuickQuote(e){return this.request("/business/quick-quotes",{method:"POST",body:JSON.stringify(e)})}async updateQuickQuote(e,t){return this.request(`/business/quick-quotes/${e}`,{method:"PUT",body:JSON.stringify(t)})}async deleteQuickQuote(e){return this.request(`/business/quick-quotes/${e}`,{method:"DELETE"})}async contact(e){return this.request("/business/contact",{method:"POST",body:JSON.stringify(e)})}}export{o as PageSolverClient};
2
+
3
+ //# debugId=5AFD190CD8D6E0B664756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
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\ninterface QuickQuoteRequestData {\n name: string;\n description?: string;\n basePrice?: string;\n parentId?: string;\n enabled?: 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 async createQuickQuote(\n data: QuickQuoteRequestData\n ): Promise<ApiResponse<QuickQuote>> {\n return this.request<QuickQuote>(\"/business/quick-quotes\", {\n method: \"POST\",\n body: JSON.stringify(data),\n });\n }\n\n async updateQuickQuote(\n id: string,\n data: Partial<QuickQuoteRequestData>\n ): Promise<ApiResponse<QuickQuote>> {\n return this.request<QuickQuote>(`/business/quick-quotes/${id}`, {\n method: \"PUT\",\n body: JSON.stringify(data),\n });\n }\n\n async deleteQuickQuote(\n id: string\n ): Promise<ApiResponse<{ success: boolean }>> {\n return this.request<{ success: boolean }>(`/business/quick-quotes/${id}`, {\n method: \"DELETE\",\n });\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 {\n ApiResponse,\n ContactData,\n ContactResponse,\n QuickQuoteRequestData,\n};\n"
6
+ ],
7
+ "mappings": "AAyDO,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,eAAgB,mBAChB,iBAAkB,KAAK,eACpB,EAAQ,OACb,EAEM,EAAW,MAAM,MAAM,EAAK,IAC7B,EACH,SACF,CAAC,EAEG,EAEJ,GADoB,EAAS,QAAQ,IAAI,cAAc,GACtC,SAAS,kBAAkB,EAC1C,EAAO,MAAM,EAAS,KAAK,EAE3B,OAAO,MAAM,EAAS,KAAK,EAG7B,IAAK,EAAS,GACZ,MAAO,CACL,MACG,GAA6B,OAAS,4BACzC,OAAQ,EAAS,MACnB,EAGF,MAAO,CACL,KAAM,EACN,OAAQ,EAAS,MACnB,EACA,MAAO,EAAO,CACd,MAAO,CACL,MAAO,aAAiB,MAAQ,EAAM,QAAU,gBAChD,OAAQ,GACV,QAKE,eAAc,EAElB,CACA,OAAO,KAAK,QACV,uBACF,OAII,aAAY,EAAyD,CACzE,OAAO,KAAK,QAAwC,qBAAqB,OAIrE,eAAc,EAAmD,CACrE,OAAO,KAAK,QAAkC,wBAAwB,OAGlE,iBAAgB,CACpB,EACkC,CAClC,OAAO,KAAK,QAAoB,yBAA0B,CACxD,OAAQ,OACR,KAAM,KAAK,UAAU,CAAI,CAC3B,CAAC,OAGG,iBAAgB,CACpB,EACA,EACkC,CAClC,OAAO,KAAK,QAAoB,0BAA0B,IAAM,CAC9D,OAAQ,MACR,KAAM,KAAK,UAAU,CAAI,CAC3B,CAAC,OAGG,iBAAgB,CACpB,EAC4C,CAC5C,OAAO,KAAK,QAA8B,0BAA0B,IAAM,CACxE,OAAQ,QACV,CAAC,OAIG,QAAO,CAAC,EAA0D,CACtE,OAAO,KAAK,QAAyB,oBAAqB,CACxD,OAAQ,OACR,KAAM,KAAK,UAAU,CAAI,CAC3B,CAAC,EAEL",
8
+ "debugId": "5AFD190CD8D6E0B664756E2164756E21",
9
+ "names": []
10
+ }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@pagesolver/sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official SDK for PageSolver API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
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",
21
+ "dev": "bun --watch src/index.ts",
22
+ "test": "bun test",
23
+ "lint": "bunx @biomejs/biome check src",
24
+ "lint:fix": "bunx @biomejs/biome check --apply src",
25
+ "type-check": "bunx tsc --noEmit",
26
+ "prepare": "bun run build",
27
+ "prepublishOnly": "bun run lint && bun run type-check && bun run test && bun run build"
28
+ },
29
+ "keywords": [
30
+ "pagesolver",
31
+ "api",
32
+ "sdk",
33
+ "typescript",
34
+ "web-development"
35
+ ],
36
+ "author": "PageSolver Team",
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/pagesolver/pagesolver-sdk.git"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/pagesolver/pagesolver-sdk/issues"
44
+ },
45
+ "homepage": "https://github.com/pagesolver/pagesolver-sdk#readme",
46
+ "devDependencies": {
47
+ "@biomejs/biome": "^1.8.3",
48
+ "@types/bun": "latest",
49
+ "typescript": "^5.5.2"
50
+ },
51
+ "peerDependencies": {
52
+ "typescript": ">=4.0.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=18.0.0",
56
+ "bun": ">=1.0.0"
57
+ }
58
+ }