@webbyon/promptly-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/dist/index.d.mts +998 -0
- package/dist/index.d.ts +998 -0
- package/dist/index.js +765 -0
- package/dist/index.mjs +737 -0
- package/package.json +49 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
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/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Promptly: () => Promptly,
|
|
24
|
+
PromptlyError: () => PromptlyError,
|
|
25
|
+
default: () => index_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/http.ts
|
|
30
|
+
var PromptlyError = class extends Error {
|
|
31
|
+
constructor(message, status, errors) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "PromptlyError";
|
|
34
|
+
this.status = status;
|
|
35
|
+
this.errors = errors;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var HttpClient = class {
|
|
39
|
+
constructor(config) {
|
|
40
|
+
this.token = null;
|
|
41
|
+
this.tenantId = config.tenantId;
|
|
42
|
+
this.baseUrl = (config.baseUrl || "https://promptly.webbyon.com").replace(/\/$/, "");
|
|
43
|
+
this.timeout = config.timeout || 3e4;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set authentication token
|
|
47
|
+
*/
|
|
48
|
+
setToken(token) {
|
|
49
|
+
this.token = token;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get current token
|
|
53
|
+
*/
|
|
54
|
+
getToken() {
|
|
55
|
+
return this.token;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if authenticated
|
|
59
|
+
*/
|
|
60
|
+
isAuthenticated() {
|
|
61
|
+
return this.token !== null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Build full URL with query params
|
|
65
|
+
*/
|
|
66
|
+
buildUrl(endpoint, params) {
|
|
67
|
+
const url = new URL(`${this.baseUrl}/api/${this.tenantId}${endpoint}`);
|
|
68
|
+
if (params) {
|
|
69
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
70
|
+
if (value !== void 0 && value !== null) {
|
|
71
|
+
url.searchParams.append(key, String(value));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return url.toString();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Build request headers
|
|
79
|
+
*/
|
|
80
|
+
buildHeaders(customHeaders) {
|
|
81
|
+
const headers = {
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
"Accept": "application/json",
|
|
84
|
+
...customHeaders
|
|
85
|
+
};
|
|
86
|
+
if (this.token) {
|
|
87
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
88
|
+
}
|
|
89
|
+
return headers;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Make HTTP request
|
|
93
|
+
*/
|
|
94
|
+
async request(endpoint, options = {}) {
|
|
95
|
+
const { method = "GET", body, params, headers } = options;
|
|
96
|
+
const url = this.buildUrl(endpoint, params);
|
|
97
|
+
const requestHeaders = this.buildHeaders(headers);
|
|
98
|
+
const controller = new AbortController();
|
|
99
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
100
|
+
try {
|
|
101
|
+
const response = await fetch(url, {
|
|
102
|
+
method,
|
|
103
|
+
headers: requestHeaders,
|
|
104
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
105
|
+
signal: controller.signal
|
|
106
|
+
});
|
|
107
|
+
clearTimeout(timeoutId);
|
|
108
|
+
const data = await response.json();
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
throw new PromptlyError(
|
|
111
|
+
data.message || "Request failed",
|
|
112
|
+
response.status,
|
|
113
|
+
data.errors
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return data.data !== void 0 ? data.data : data;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
clearTimeout(timeoutId);
|
|
119
|
+
if (error instanceof PromptlyError) {
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
if (error instanceof Error) {
|
|
123
|
+
if (error.name === "AbortError") {
|
|
124
|
+
throw new PromptlyError("Request timeout", 408);
|
|
125
|
+
}
|
|
126
|
+
throw new PromptlyError(error.message, 0);
|
|
127
|
+
}
|
|
128
|
+
throw new PromptlyError("Unknown error", 0);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* GET request
|
|
133
|
+
*/
|
|
134
|
+
get(endpoint, params) {
|
|
135
|
+
return this.request(endpoint, { method: "GET", params });
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* POST request
|
|
139
|
+
*/
|
|
140
|
+
post(endpoint, body) {
|
|
141
|
+
return this.request(endpoint, { method: "POST", body });
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* PUT request
|
|
145
|
+
*/
|
|
146
|
+
put(endpoint, body) {
|
|
147
|
+
return this.request(endpoint, { method: "PUT", body });
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* PATCH request
|
|
151
|
+
*/
|
|
152
|
+
patch(endpoint, body) {
|
|
153
|
+
return this.request(endpoint, { method: "PATCH", body });
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* DELETE request
|
|
157
|
+
*/
|
|
158
|
+
delete(endpoint) {
|
|
159
|
+
return this.request(endpoint, { method: "DELETE" });
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Upload file
|
|
163
|
+
*/
|
|
164
|
+
async upload(endpoint, file, fieldName = "file") {
|
|
165
|
+
const url = this.buildUrl(endpoint);
|
|
166
|
+
const formData = new FormData();
|
|
167
|
+
formData.append(fieldName, file);
|
|
168
|
+
const headers = {
|
|
169
|
+
"Accept": "application/json"
|
|
170
|
+
};
|
|
171
|
+
if (this.token) {
|
|
172
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
173
|
+
}
|
|
174
|
+
const controller = new AbortController();
|
|
175
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
176
|
+
try {
|
|
177
|
+
const response = await fetch(url, {
|
|
178
|
+
method: "POST",
|
|
179
|
+
headers,
|
|
180
|
+
body: formData,
|
|
181
|
+
signal: controller.signal
|
|
182
|
+
});
|
|
183
|
+
clearTimeout(timeoutId);
|
|
184
|
+
const data = await response.json();
|
|
185
|
+
if (!response.ok) {
|
|
186
|
+
throw new PromptlyError(
|
|
187
|
+
data.message || "Upload failed",
|
|
188
|
+
response.status,
|
|
189
|
+
data.errors
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return data.data !== void 0 ? data.data : data;
|
|
193
|
+
} catch (error) {
|
|
194
|
+
clearTimeout(timeoutId);
|
|
195
|
+
if (error instanceof PromptlyError) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
if (error instanceof Error) {
|
|
199
|
+
if (error.name === "AbortError") {
|
|
200
|
+
throw new PromptlyError("Upload timeout", 408);
|
|
201
|
+
}
|
|
202
|
+
throw new PromptlyError(error.message, 0);
|
|
203
|
+
}
|
|
204
|
+
throw new PromptlyError("Unknown error", 0);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/resources/auth.ts
|
|
210
|
+
var AuthResource = class {
|
|
211
|
+
constructor(http) {
|
|
212
|
+
this.http = http;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Login with email and password
|
|
216
|
+
*/
|
|
217
|
+
async login(credentials) {
|
|
218
|
+
const response = await this.http.post("/auth/login", credentials);
|
|
219
|
+
if (response.token) {
|
|
220
|
+
this.http.setToken(response.token);
|
|
221
|
+
}
|
|
222
|
+
return response;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Register new member
|
|
226
|
+
*/
|
|
227
|
+
async register(data) {
|
|
228
|
+
const response = await this.http.post("/auth/register", data);
|
|
229
|
+
if (response.token) {
|
|
230
|
+
this.http.setToken(response.token);
|
|
231
|
+
}
|
|
232
|
+
return response;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Logout current user
|
|
236
|
+
*/
|
|
237
|
+
async logout() {
|
|
238
|
+
try {
|
|
239
|
+
await this.http.post("/auth/logout");
|
|
240
|
+
} finally {
|
|
241
|
+
this.http.setToken(null);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get current user profile
|
|
246
|
+
*/
|
|
247
|
+
async me() {
|
|
248
|
+
return this.http.get("/profile");
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Update profile
|
|
252
|
+
*/
|
|
253
|
+
async updateProfile(data) {
|
|
254
|
+
return this.http.put("/profile", data);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Send password reset email
|
|
258
|
+
*/
|
|
259
|
+
async forgotPassword(data) {
|
|
260
|
+
return this.http.post("/auth/forgot-password", data);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Reset password with token
|
|
264
|
+
*/
|
|
265
|
+
async resetPassword(data) {
|
|
266
|
+
return this.http.post("/auth/reset-password", data);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get available social login providers
|
|
270
|
+
*/
|
|
271
|
+
async getSocialProviders() {
|
|
272
|
+
return this.http.get("/auth/social");
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get social login redirect URL
|
|
276
|
+
*/
|
|
277
|
+
async getSocialAuthUrl(provider) {
|
|
278
|
+
return this.http.get(`/auth/social/${provider}`);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Handle social login callback
|
|
282
|
+
*/
|
|
283
|
+
async socialCallback(provider, code) {
|
|
284
|
+
const response = await this.http.post(`/auth/social/${provider}/callback`, { code });
|
|
285
|
+
if (response.token) {
|
|
286
|
+
this.http.setToken(response.token);
|
|
287
|
+
}
|
|
288
|
+
return response;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Set token manually (e.g., from localStorage)
|
|
292
|
+
*/
|
|
293
|
+
setToken(token) {
|
|
294
|
+
this.http.setToken(token);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get current token
|
|
298
|
+
*/
|
|
299
|
+
getToken() {
|
|
300
|
+
return this.http.getToken();
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Check if user is authenticated
|
|
304
|
+
*/
|
|
305
|
+
isAuthenticated() {
|
|
306
|
+
return this.http.isAuthenticated();
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// src/resources/boards.ts
|
|
311
|
+
var BoardsResource = class {
|
|
312
|
+
constructor(http) {
|
|
313
|
+
this.http = http;
|
|
314
|
+
}
|
|
315
|
+
// ============================================
|
|
316
|
+
// Boards (Public)
|
|
317
|
+
// ============================================
|
|
318
|
+
/**
|
|
319
|
+
* List all boards
|
|
320
|
+
*/
|
|
321
|
+
async list(params) {
|
|
322
|
+
return this.http.get("/public/boards", params);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get board by ID or slug
|
|
326
|
+
*/
|
|
327
|
+
async get(idOrSlug) {
|
|
328
|
+
return this.http.get(`/public/boards/${idOrSlug}`);
|
|
329
|
+
}
|
|
330
|
+
// ============================================
|
|
331
|
+
// Posts (Public)
|
|
332
|
+
// ============================================
|
|
333
|
+
/**
|
|
334
|
+
* List posts in a board
|
|
335
|
+
*/
|
|
336
|
+
async listPosts(boardIdOrSlug, params) {
|
|
337
|
+
return this.http.get(`/public/boards/${boardIdOrSlug}/posts`, params);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Get post by ID
|
|
341
|
+
*/
|
|
342
|
+
async getPost(postId) {
|
|
343
|
+
return this.http.get(`/public/posts/${postId}`);
|
|
344
|
+
}
|
|
345
|
+
// ============================================
|
|
346
|
+
// Posts (Protected - requires auth)
|
|
347
|
+
// ============================================
|
|
348
|
+
/**
|
|
349
|
+
* Create new post
|
|
350
|
+
*/
|
|
351
|
+
async createPost(data) {
|
|
352
|
+
return this.http.post("/posts", data);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Update post
|
|
356
|
+
*/
|
|
357
|
+
async updatePost(postId, data) {
|
|
358
|
+
return this.http.put(`/posts/${postId}`, data);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Delete post
|
|
362
|
+
*/
|
|
363
|
+
async deletePost(postId) {
|
|
364
|
+
return this.http.delete(`/posts/${postId}`);
|
|
365
|
+
}
|
|
366
|
+
// ============================================
|
|
367
|
+
// Comments
|
|
368
|
+
// ============================================
|
|
369
|
+
/**
|
|
370
|
+
* List comments for a post
|
|
371
|
+
*/
|
|
372
|
+
async listComments(postId) {
|
|
373
|
+
return this.http.get(`/public/posts/${postId}/comments`);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Create comment on a post
|
|
377
|
+
*/
|
|
378
|
+
async createComment(postId, data) {
|
|
379
|
+
return this.http.post(`/posts/${postId}/comments`, data);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Update comment
|
|
383
|
+
*/
|
|
384
|
+
async updateComment(commentId, data) {
|
|
385
|
+
return this.http.put(`/comments/${commentId}`, data);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Delete comment
|
|
389
|
+
*/
|
|
390
|
+
async deleteComment(commentId) {
|
|
391
|
+
return this.http.delete(`/comments/${commentId}`);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// src/resources/blog.ts
|
|
396
|
+
var BlogResource = class {
|
|
397
|
+
constructor(http) {
|
|
398
|
+
this.http = http;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* List blog posts
|
|
402
|
+
*/
|
|
403
|
+
async list(params) {
|
|
404
|
+
return this.http.get("/public/blog", params);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Get blog post by slug
|
|
408
|
+
*/
|
|
409
|
+
async get(slug) {
|
|
410
|
+
return this.http.get(`/public/blog/${slug}`);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Get blog post by ID
|
|
414
|
+
*/
|
|
415
|
+
async getById(id) {
|
|
416
|
+
return this.http.get(`/public/blog/id/${id}`);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Get featured blog posts
|
|
420
|
+
*/
|
|
421
|
+
async featured(limit = 5) {
|
|
422
|
+
const response = await this.http.get("/public/blog", {
|
|
423
|
+
per_page: limit,
|
|
424
|
+
featured: true
|
|
425
|
+
});
|
|
426
|
+
return response.data;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Get blog posts by category
|
|
430
|
+
*/
|
|
431
|
+
async byCategory(category, params) {
|
|
432
|
+
return this.http.get("/public/blog", {
|
|
433
|
+
...params,
|
|
434
|
+
category
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Get blog posts by tag
|
|
439
|
+
*/
|
|
440
|
+
async byTag(tag, params) {
|
|
441
|
+
return this.http.get("/public/blog", {
|
|
442
|
+
...params,
|
|
443
|
+
tag
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Search blog posts
|
|
448
|
+
*/
|
|
449
|
+
async search(query, params) {
|
|
450
|
+
return this.http.get("/public/blog", {
|
|
451
|
+
...params,
|
|
452
|
+
search: query
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Get blog categories
|
|
457
|
+
*/
|
|
458
|
+
async categories() {
|
|
459
|
+
return this.http.get("/public/blog/categories");
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Get blog tags
|
|
463
|
+
*/
|
|
464
|
+
async tags() {
|
|
465
|
+
return this.http.get("/public/blog/tags");
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/resources/forms.ts
|
|
470
|
+
var FormsResource = class {
|
|
471
|
+
constructor(http) {
|
|
472
|
+
this.http = http;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* List all forms
|
|
476
|
+
*/
|
|
477
|
+
async list(params) {
|
|
478
|
+
return this.http.get("/public/forms", params);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Get form by ID or slug
|
|
482
|
+
*/
|
|
483
|
+
async get(idOrSlug) {
|
|
484
|
+
return this.http.get(`/public/forms/${idOrSlug}`);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Submit form data
|
|
488
|
+
*/
|
|
489
|
+
async submit(formIdOrSlug, data) {
|
|
490
|
+
return this.http.post(`/public/forms/${formIdOrSlug}/submit`, data);
|
|
491
|
+
}
|
|
492
|
+
// ============================================
|
|
493
|
+
// Protected endpoints (requires auth)
|
|
494
|
+
// ============================================
|
|
495
|
+
/**
|
|
496
|
+
* Get my form submissions
|
|
497
|
+
*/
|
|
498
|
+
async mySubmissions(params) {
|
|
499
|
+
return this.http.get("/form-submissions", params);
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Get specific submission
|
|
503
|
+
*/
|
|
504
|
+
async getSubmission(submissionId) {
|
|
505
|
+
return this.http.get(`/form-submissions/${submissionId}`);
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// src/resources/shop.ts
|
|
510
|
+
var ShopResource = class {
|
|
511
|
+
constructor(http) {
|
|
512
|
+
this.http = http;
|
|
513
|
+
}
|
|
514
|
+
// ============================================
|
|
515
|
+
// Products (Public)
|
|
516
|
+
// ============================================
|
|
517
|
+
/**
|
|
518
|
+
* List products
|
|
519
|
+
*/
|
|
520
|
+
async listProducts(params) {
|
|
521
|
+
return this.http.get("/public/products", params);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Get product by ID or slug
|
|
525
|
+
*/
|
|
526
|
+
async getProduct(idOrSlug) {
|
|
527
|
+
return this.http.get(`/public/products/${idOrSlug}`);
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Get featured products
|
|
531
|
+
*/
|
|
532
|
+
async featuredProducts(limit = 8) {
|
|
533
|
+
const response = await this.http.get("/public/products", {
|
|
534
|
+
per_page: limit,
|
|
535
|
+
is_featured: true
|
|
536
|
+
});
|
|
537
|
+
return response.data;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Search products
|
|
541
|
+
*/
|
|
542
|
+
async searchProducts(query, params) {
|
|
543
|
+
return this.http.get("/public/products", {
|
|
544
|
+
...params,
|
|
545
|
+
search: query
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
// ============================================
|
|
549
|
+
// Categories (Public)
|
|
550
|
+
// ============================================
|
|
551
|
+
/**
|
|
552
|
+
* List product categories
|
|
553
|
+
*/
|
|
554
|
+
async listCategories() {
|
|
555
|
+
return this.http.get("/public/categories");
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Get category by ID or slug
|
|
559
|
+
*/
|
|
560
|
+
async getCategory(idOrSlug) {
|
|
561
|
+
return this.http.get(`/public/categories/${idOrSlug}`);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Get products in category
|
|
565
|
+
*/
|
|
566
|
+
async categoryProducts(categoryIdOrSlug, params) {
|
|
567
|
+
return this.http.get(`/public/categories/${categoryIdOrSlug}/products`, params);
|
|
568
|
+
}
|
|
569
|
+
// ============================================
|
|
570
|
+
// Cart
|
|
571
|
+
// ============================================
|
|
572
|
+
/**
|
|
573
|
+
* Get current cart
|
|
574
|
+
*/
|
|
575
|
+
async getCart() {
|
|
576
|
+
return this.http.get("/cart");
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Add item to cart
|
|
580
|
+
*/
|
|
581
|
+
async addToCart(data) {
|
|
582
|
+
return this.http.post("/cart/items", data);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Update cart item quantity
|
|
586
|
+
*/
|
|
587
|
+
async updateCartItem(itemId, data) {
|
|
588
|
+
return this.http.put(`/cart/items/${itemId}`, data);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Remove item from cart
|
|
592
|
+
*/
|
|
593
|
+
async removeFromCart(itemId) {
|
|
594
|
+
return this.http.delete(`/cart/items/${itemId}`);
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Clear entire cart
|
|
598
|
+
*/
|
|
599
|
+
async clearCart() {
|
|
600
|
+
return this.http.delete("/cart");
|
|
601
|
+
}
|
|
602
|
+
// ============================================
|
|
603
|
+
// Orders (Protected)
|
|
604
|
+
// ============================================
|
|
605
|
+
/**
|
|
606
|
+
* List my orders
|
|
607
|
+
*/
|
|
608
|
+
async listOrders(params) {
|
|
609
|
+
return this.http.get("/orders", params);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Get order by ID or order number
|
|
613
|
+
*/
|
|
614
|
+
async getOrder(idOrNumber) {
|
|
615
|
+
return this.http.get(`/orders/${idOrNumber}`);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Create order from cart
|
|
619
|
+
*/
|
|
620
|
+
async createOrder(data) {
|
|
621
|
+
return this.http.post("/orders", data);
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Cancel order
|
|
625
|
+
*/
|
|
626
|
+
async cancelOrder(orderId) {
|
|
627
|
+
return this.http.post(`/orders/${orderId}/cancel`);
|
|
628
|
+
}
|
|
629
|
+
// ============================================
|
|
630
|
+
// Payments
|
|
631
|
+
// ============================================
|
|
632
|
+
/**
|
|
633
|
+
* Get payment for order
|
|
634
|
+
*/
|
|
635
|
+
async getPayment(orderId) {
|
|
636
|
+
return this.http.get(`/orders/${orderId}/payment`);
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Prepare payment (get payment key)
|
|
640
|
+
*/
|
|
641
|
+
async preparePayment(data) {
|
|
642
|
+
return this.http.post(`/payments/ready`, data);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Confirm payment (after Toss redirect)
|
|
646
|
+
*/
|
|
647
|
+
async confirmPayment(data) {
|
|
648
|
+
return this.http.post("/payments/confirm", data);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Cancel payment
|
|
652
|
+
*/
|
|
653
|
+
async cancelPayment(paymentId, data) {
|
|
654
|
+
return this.http.post(`/payments/${paymentId}/cancel`, data);
|
|
655
|
+
}
|
|
656
|
+
// ============================================
|
|
657
|
+
// Coupons
|
|
658
|
+
// ============================================
|
|
659
|
+
/**
|
|
660
|
+
* Validate coupon code
|
|
661
|
+
*/
|
|
662
|
+
async validateCoupon(code, orderAmount) {
|
|
663
|
+
return this.http.post("/coupons/validate", {
|
|
664
|
+
code,
|
|
665
|
+
order_amount: orderAmount
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Get available coupons for current user
|
|
670
|
+
*/
|
|
671
|
+
async myCoupons() {
|
|
672
|
+
return this.http.get("/coupons");
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// src/resources/media.ts
|
|
677
|
+
var MediaResource = class {
|
|
678
|
+
constructor(http) {
|
|
679
|
+
this.http = http;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* List my media files
|
|
683
|
+
*/
|
|
684
|
+
async list(params) {
|
|
685
|
+
return this.http.get("/media", params);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Get media by ID
|
|
689
|
+
*/
|
|
690
|
+
async get(mediaId) {
|
|
691
|
+
return this.http.get(`/media/${mediaId}`);
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Upload file
|
|
695
|
+
*/
|
|
696
|
+
async upload(file) {
|
|
697
|
+
return this.http.upload("/media", file, "file");
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Upload multiple files
|
|
701
|
+
*/
|
|
702
|
+
async uploadMultiple(files) {
|
|
703
|
+
const results = [];
|
|
704
|
+
for (const file of files) {
|
|
705
|
+
const media = await this.upload(file);
|
|
706
|
+
results.push(media);
|
|
707
|
+
}
|
|
708
|
+
return results;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Delete media
|
|
712
|
+
*/
|
|
713
|
+
async delete(mediaId) {
|
|
714
|
+
return this.http.delete(`/media/${mediaId}`);
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
// src/index.ts
|
|
719
|
+
var Promptly = class {
|
|
720
|
+
constructor(config) {
|
|
721
|
+
this.http = new HttpClient(config);
|
|
722
|
+
this.auth = new AuthResource(this.http);
|
|
723
|
+
this.boards = new BoardsResource(this.http);
|
|
724
|
+
this.blog = new BlogResource(this.http);
|
|
725
|
+
this.forms = new FormsResource(this.http);
|
|
726
|
+
this.shop = new ShopResource(this.http);
|
|
727
|
+
this.media = new MediaResource(this.http);
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Get site theme settings
|
|
731
|
+
*/
|
|
732
|
+
async getTheme() {
|
|
733
|
+
return this.http.get("/public/theme");
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Get site settings
|
|
737
|
+
*/
|
|
738
|
+
async getSettings() {
|
|
739
|
+
return this.http.get("/public/settings");
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Check if user is authenticated
|
|
743
|
+
*/
|
|
744
|
+
isAuthenticated() {
|
|
745
|
+
return this.auth.isAuthenticated();
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Set authentication token manually
|
|
749
|
+
*/
|
|
750
|
+
setToken(token) {
|
|
751
|
+
this.auth.setToken(token);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Get current authentication token
|
|
755
|
+
*/
|
|
756
|
+
getToken() {
|
|
757
|
+
return this.auth.getToken();
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
var index_default = Promptly;
|
|
761
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
762
|
+
0 && (module.exports = {
|
|
763
|
+
Promptly,
|
|
764
|
+
PromptlyError
|
|
765
|
+
});
|