@dromney/mapthis 0.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.
Files changed (65) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +56 -0
  3. package/dist/ai/index.cjs +474 -0
  4. package/dist/ai/index.cjs.map +1 -0
  5. package/dist/ai/index.d.cts +117 -0
  6. package/dist/ai/index.d.ts +117 -0
  7. package/dist/ai/index.js +447 -0
  8. package/dist/ai/index.js.map +1 -0
  9. package/dist/domain-CZ-L-ntu.d.ts +163 -0
  10. package/dist/domain-Dc1wSTkf.d.cts +163 -0
  11. package/dist/errors-Bw97z_4m.d.cts +12 -0
  12. package/dist/errors-Bw97z_4m.d.ts +12 -0
  13. package/dist/generate/index.cjs +222 -0
  14. package/dist/generate/index.cjs.map +1 -0
  15. package/dist/generate/index.d.cts +140 -0
  16. package/dist/generate/index.d.ts +140 -0
  17. package/dist/generate/index.js +220 -0
  18. package/dist/generate/index.js.map +1 -0
  19. package/dist/geocoding/index.cjs +90 -0
  20. package/dist/geocoding/index.cjs.map +1 -0
  21. package/dist/geocoding/index.d.cts +36 -0
  22. package/dist/geocoding/index.d.ts +36 -0
  23. package/dist/geocoding/index.js +86 -0
  24. package/dist/geocoding/index.js.map +1 -0
  25. package/dist/index.cjs +546 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.cts +5 -0
  28. package/dist/index.d.ts +5 -0
  29. package/dist/index.js +469 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/parser-CzXzpmVv.d.cts +111 -0
  32. package/dist/parser-N7-fNxeu.d.ts +111 -0
  33. package/dist/react/index.cjs +394 -0
  34. package/dist/react/index.cjs.map +1 -0
  35. package/dist/react/index.js +383 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/schemas-Dy5coqXo.d.cts +484 -0
  38. package/dist/schemas-Dy5coqXo.d.ts +484 -0
  39. package/dist/scrape/index.cjs +133 -0
  40. package/dist/scrape/index.cjs.map +1 -0
  41. package/dist/scrape/index.d.cts +60 -0
  42. package/dist/scrape/index.d.ts +60 -0
  43. package/dist/scrape/index.js +125 -0
  44. package/dist/scrape/index.js.map +1 -0
  45. package/dist/search/index.cjs +76 -0
  46. package/dist/search/index.cjs.map +1 -0
  47. package/dist/search/index.d.cts +75 -0
  48. package/dist/search/index.d.ts +75 -0
  49. package/dist/search/index.js +71 -0
  50. package/dist/search/index.js.map +1 -0
  51. package/dist/types/index.cjs +215 -0
  52. package/dist/types/index.cjs.map +1 -0
  53. package/dist/types/index.d.cts +4 -0
  54. package/dist/types/index.d.ts +4 -0
  55. package/dist/types/index.js +171 -0
  56. package/dist/types/index.js.map +1 -0
  57. package/dist/types-BhqKlq0k.d.ts +31 -0
  58. package/dist/types-rFjK5YcJ.d.cts +31 -0
  59. package/dist/utils/index.cjs +335 -0
  60. package/dist/utils/index.cjs.map +1 -0
  61. package/dist/utils/index.d.cts +363 -0
  62. package/dist/utils/index.d.ts +363 -0
  63. package/dist/utils/index.js +301 -0
  64. package/dist/utils/index.js.map +1 -0
  65. package/package.json +150 -0
@@ -0,0 +1,484 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Runtime validation schemas and their inferred types.
5
+ *
6
+ * These schemas define the public contract between producers and consumers of
7
+ * mapthis data. They are intentionally framework-agnostic — no Prisma, no
8
+ * Next.js, no auth assumptions.
9
+ */
10
+ declare const llmProvider: z.ZodLiteral<"openai">;
11
+ type LlmProvider = z.infer<typeof llmProvider>;
12
+ declare const placeProvider: z.ZodUnion<[z.ZodLiteral<"google">, z.ZodLiteral<"locationiq">]>;
13
+ type PlaceProvider = z.infer<typeof placeProvider>;
14
+ declare const generationSourceType: z.ZodUnion<[z.ZodLiteral<"blank">, z.ZodLiteral<"autocomplete">, z.ZodLiteral<"url">, z.ZodLiteral<"text">, z.ZodLiteral<"list">]>;
15
+ type GenerationSourceType = z.infer<typeof generationSourceType>;
16
+ declare const latitude: z.ZodNumber;
17
+ declare const longitude: z.ZodNumber;
18
+ declare const coordinates: z.ZodObject<{
19
+ lat: z.ZodNumber;
20
+ lng: z.ZodNumber;
21
+ }, "strip", z.ZodTypeAny, {
22
+ lat: number;
23
+ lng: number;
24
+ }, {
25
+ lat: number;
26
+ lng: number;
27
+ }>;
28
+ type Coordinates = z.infer<typeof coordinates>;
29
+ declare const placesFromUrl: z.ZodString;
30
+ declare const placesFromList: z.ZodEffects<z.ZodEffects<z.ZodString, string, unknown>, string, unknown>;
31
+ declare const placesFromText: z.ZodString;
32
+ declare const mapExternalId: z.ZodString;
33
+ declare const mapTitle: z.ZodString;
34
+ declare const mapDescription: z.ZodString;
35
+ declare const mapCreationQuery: z.ZodString;
36
+ declare const groupName: z.ZodString;
37
+ declare const groupDescription: z.ZodString;
38
+ declare const groupColor: z.ZodString;
39
+ declare const placeName: z.ZodString;
40
+ declare const placeDescription: z.ZodString;
41
+ declare const createMapBase: z.ZodObject<{
42
+ title: z.ZodOptional<z.ZodString>;
43
+ description: z.ZodOptional<z.ZodString>;
44
+ externalId: z.ZodOptional<z.ZodString>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ title?: string | undefined;
47
+ description?: string | undefined;
48
+ externalId?: string | undefined;
49
+ }, {
50
+ title?: string | undefined;
51
+ description?: string | undefined;
52
+ externalId?: string | undefined;
53
+ }>;
54
+ declare const createMapSchema: z.ZodObject<{
55
+ title: z.ZodOptional<z.ZodString>;
56
+ description: z.ZodOptional<z.ZodString>;
57
+ externalId: z.ZodOptional<z.ZodString>;
58
+ } & {
59
+ sourceType: z.ZodUnion<[z.ZodLiteral<"blank">, z.ZodLiteral<"autocomplete">, z.ZodLiteral<"url">, z.ZodLiteral<"text">, z.ZodLiteral<"list">]>;
60
+ source: z.ZodOptional<z.ZodString>;
61
+ }, "strip", z.ZodTypeAny, {
62
+ sourceType: "blank" | "autocomplete" | "url" | "text" | "list";
63
+ title?: string | undefined;
64
+ description?: string | undefined;
65
+ externalId?: string | undefined;
66
+ source?: string | undefined;
67
+ }, {
68
+ sourceType: "blank" | "autocomplete" | "url" | "text" | "list";
69
+ title?: string | undefined;
70
+ description?: string | undefined;
71
+ externalId?: string | undefined;
72
+ source?: string | undefined;
73
+ }>;
74
+ declare const createBlankMapSchema: z.ZodObject<{
75
+ title: z.ZodOptional<z.ZodString>;
76
+ description: z.ZodOptional<z.ZodString>;
77
+ externalId: z.ZodOptional<z.ZodString>;
78
+ }, "strip", z.ZodTypeAny, {
79
+ title?: string | undefined;
80
+ description?: string | undefined;
81
+ externalId?: string | undefined;
82
+ }, {
83
+ title?: string | undefined;
84
+ description?: string | undefined;
85
+ externalId?: string | undefined;
86
+ }>;
87
+ declare const createMapFromUrlSchema: z.ZodObject<{
88
+ title: z.ZodOptional<z.ZodString>;
89
+ description: z.ZodOptional<z.ZodString>;
90
+ externalId: z.ZodOptional<z.ZodString>;
91
+ } & {
92
+ url: z.ZodString;
93
+ }, "strip", z.ZodTypeAny, {
94
+ url: string;
95
+ title?: string | undefined;
96
+ description?: string | undefined;
97
+ externalId?: string | undefined;
98
+ }, {
99
+ url: string;
100
+ title?: string | undefined;
101
+ description?: string | undefined;
102
+ externalId?: string | undefined;
103
+ }>;
104
+ declare const createMapFromListSchema: z.ZodObject<{
105
+ title: z.ZodOptional<z.ZodString>;
106
+ description: z.ZodOptional<z.ZodString>;
107
+ externalId: z.ZodOptional<z.ZodString>;
108
+ } & {
109
+ list: z.ZodEffects<z.ZodEffects<z.ZodString, string, unknown>, string, unknown>;
110
+ }, "strip", z.ZodTypeAny, {
111
+ list: string;
112
+ title?: string | undefined;
113
+ description?: string | undefined;
114
+ externalId?: string | undefined;
115
+ }, {
116
+ list?: unknown;
117
+ title?: string | undefined;
118
+ description?: string | undefined;
119
+ externalId?: string | undefined;
120
+ }>;
121
+ declare const createMapFromTextSchema: z.ZodObject<{
122
+ title: z.ZodOptional<z.ZodString>;
123
+ description: z.ZodOptional<z.ZodString>;
124
+ externalId: z.ZodOptional<z.ZodString>;
125
+ } & {
126
+ text: z.ZodString;
127
+ }, "strip", z.ZodTypeAny, {
128
+ text: string;
129
+ title?: string | undefined;
130
+ description?: string | undefined;
131
+ externalId?: string | undefined;
132
+ }, {
133
+ text: string;
134
+ title?: string | undefined;
135
+ description?: string | undefined;
136
+ externalId?: string | undefined;
137
+ }>;
138
+ declare const createMapFromQueryOrUrlSchema: z.ZodObject<{
139
+ title: z.ZodOptional<z.ZodString>;
140
+ description: z.ZodOptional<z.ZodString>;
141
+ externalId: z.ZodOptional<z.ZodString>;
142
+ } & {
143
+ queryOrUrl: z.ZodUnion<[z.ZodString, z.ZodString]>;
144
+ }, "strip", z.ZodTypeAny, {
145
+ queryOrUrl: string;
146
+ title?: string | undefined;
147
+ description?: string | undefined;
148
+ externalId?: string | undefined;
149
+ }, {
150
+ queryOrUrl: string;
151
+ title?: string | undefined;
152
+ description?: string | undefined;
153
+ externalId?: string | undefined;
154
+ }>;
155
+ declare const addPlacesBaseSchema: z.ZodObject<{
156
+ sourceType: z.ZodUnion<[z.ZodLiteral<"blank">, z.ZodLiteral<"autocomplete">, z.ZodLiteral<"url">, z.ZodLiteral<"text">, z.ZodLiteral<"list">]>;
157
+ source: z.ZodString;
158
+ }, "strip", z.ZodTypeAny, {
159
+ sourceType: "blank" | "autocomplete" | "url" | "text" | "list";
160
+ source: string;
161
+ }, {
162
+ sourceType: "blank" | "autocomplete" | "url" | "text" | "list";
163
+ source: string;
164
+ }>;
165
+ declare const addPlacesFromSourceSchema: z.ZodObject<{
166
+ sourceType: z.ZodUnion<[z.ZodLiteral<"blank">, z.ZodLiteral<"autocomplete">, z.ZodLiteral<"url">, z.ZodLiteral<"text">, z.ZodLiteral<"list">]>;
167
+ source: z.ZodString;
168
+ } & {
169
+ mapId: z.ZodString;
170
+ groupId: z.ZodOptional<z.ZodString>;
171
+ }, "strip", z.ZodTypeAny, {
172
+ sourceType: "blank" | "autocomplete" | "url" | "text" | "list";
173
+ source: string;
174
+ mapId: string;
175
+ groupId?: string | undefined;
176
+ }, {
177
+ sourceType: "blank" | "autocomplete" | "url" | "text" | "list";
178
+ source: string;
179
+ mapId: string;
180
+ groupId?: string | undefined;
181
+ }>;
182
+ declare const addPlacesFromUrlSchema: z.ZodObject<{
183
+ url: z.ZodString;
184
+ }, "strip", z.ZodTypeAny, {
185
+ url: string;
186
+ }, {
187
+ url: string;
188
+ }>;
189
+ declare const addPlacesFromListSchema: z.ZodObject<{
190
+ list: z.ZodEffects<z.ZodEffects<z.ZodString, string, unknown>, string, unknown>;
191
+ }, "strip", z.ZodTypeAny, {
192
+ list: string;
193
+ }, {
194
+ list?: unknown;
195
+ }>;
196
+ declare const addPlacesFromTextSchema: z.ZodObject<{
197
+ text: z.ZodString;
198
+ }, "strip", z.ZodTypeAny, {
199
+ text: string;
200
+ }, {
201
+ text: string;
202
+ }>;
203
+ declare const providerAutocompletePlace: z.ZodObject<{
204
+ query: z.ZodString;
205
+ provider: z.ZodLiteral<"google">;
206
+ providerId: z.ZodString;
207
+ name: z.ZodString;
208
+ description: z.ZodOptional<z.ZodString>;
209
+ address: z.ZodString;
210
+ lat: z.ZodNumber;
211
+ lng: z.ZodNumber;
212
+ }, "strip", z.ZodTypeAny, {
213
+ lat: number;
214
+ lng: number;
215
+ query: string;
216
+ provider: "google";
217
+ providerId: string;
218
+ name: string;
219
+ address: string;
220
+ description?: string | undefined;
221
+ }, {
222
+ lat: number;
223
+ lng: number;
224
+ query: string;
225
+ provider: "google";
226
+ providerId: string;
227
+ name: string;
228
+ address: string;
229
+ description?: string | undefined;
230
+ }>;
231
+ type ProviderAutocompletePlace = z.infer<typeof providerAutocompletePlace>;
232
+ declare const addPlacesFromClientAutocompleteSchema: z.ZodObject<{
233
+ query: z.ZodString;
234
+ provider: z.ZodLiteral<"google">;
235
+ providerId: z.ZodString;
236
+ name: z.ZodString;
237
+ description: z.ZodOptional<z.ZodString>;
238
+ address: z.ZodString;
239
+ lat: z.ZodNumber;
240
+ lng: z.ZodNumber;
241
+ } & {
242
+ mapId: z.ZodString;
243
+ groupId: z.ZodOptional<z.ZodString>;
244
+ }, "strip", z.ZodTypeAny, {
245
+ lat: number;
246
+ lng: number;
247
+ mapId: string;
248
+ query: string;
249
+ provider: "google";
250
+ providerId: string;
251
+ name: string;
252
+ address: string;
253
+ description?: string | undefined;
254
+ groupId?: string | undefined;
255
+ }, {
256
+ lat: number;
257
+ lng: number;
258
+ mapId: string;
259
+ query: string;
260
+ provider: "google";
261
+ providerId: string;
262
+ name: string;
263
+ address: string;
264
+ description?: string | undefined;
265
+ groupId?: string | undefined;
266
+ }>;
267
+ declare const updateMapSchema: z.ZodObject<{
268
+ title: z.ZodString;
269
+ description: z.ZodOptional<z.ZodString>;
270
+ userPublic: z.ZodOptional<z.ZodBoolean>;
271
+ partnerPublic: z.ZodOptional<z.ZodBoolean>;
272
+ url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
273
+ }, "strip", z.ZodTypeAny, {
274
+ title: string;
275
+ url?: string | null | undefined;
276
+ description?: string | undefined;
277
+ userPublic?: boolean | undefined;
278
+ partnerPublic?: boolean | undefined;
279
+ }, {
280
+ title: string;
281
+ url?: string | null | undefined;
282
+ description?: string | undefined;
283
+ userPublic?: boolean | undefined;
284
+ partnerPublic?: boolean | undefined;
285
+ }>;
286
+ declare const reorderMapSchema: z.ZodObject<{
287
+ groups: z.ZodArray<z.ZodObject<{
288
+ id: z.ZodNullable<z.ZodString>;
289
+ position: z.ZodNumber;
290
+ }, "strip", z.ZodTypeAny, {
291
+ id: string | null;
292
+ position: number;
293
+ }, {
294
+ id: string | null;
295
+ position: number;
296
+ }>, "many">;
297
+ places: z.ZodArray<z.ZodObject<{
298
+ id: z.ZodString;
299
+ groupId: z.ZodNullable<z.ZodString>;
300
+ position: z.ZodNumber;
301
+ }, "strip", z.ZodTypeAny, {
302
+ groupId: string | null;
303
+ id: string;
304
+ position: number;
305
+ }, {
306
+ groupId: string | null;
307
+ id: string;
308
+ position: number;
309
+ }>, "many">;
310
+ }, "strip", z.ZodTypeAny, {
311
+ groups: {
312
+ id: string | null;
313
+ position: number;
314
+ }[];
315
+ places: {
316
+ groupId: string | null;
317
+ id: string;
318
+ position: number;
319
+ }[];
320
+ }, {
321
+ groups: {
322
+ id: string | null;
323
+ position: number;
324
+ }[];
325
+ places: {
326
+ groupId: string | null;
327
+ id: string;
328
+ position: number;
329
+ }[];
330
+ }>;
331
+ declare const updatePlaceFormSchema: z.ZodObject<{
332
+ id: z.ZodString;
333
+ name: z.ZodString;
334
+ description: z.ZodOptional<z.ZodString>;
335
+ hidden: z.ZodBoolean;
336
+ }, "strip", z.ZodTypeAny, {
337
+ name: string;
338
+ id: string;
339
+ hidden: boolean;
340
+ description?: string | undefined;
341
+ }, {
342
+ name: string;
343
+ id: string;
344
+ hidden: boolean;
345
+ description?: string | undefined;
346
+ }>;
347
+ declare const searchSchema: z.ZodObject<{
348
+ query: z.ZodString;
349
+ }, "strip", z.ZodTypeAny, {
350
+ query: string;
351
+ }, {
352
+ query: string;
353
+ }>;
354
+ declare const createGroupSchema: z.ZodObject<{
355
+ name: z.ZodString;
356
+ description: z.ZodOptional<z.ZodString>;
357
+ parentGroupId: z.ZodOptional<z.ZodString>;
358
+ color: z.ZodOptional<z.ZodString>;
359
+ }, "strip", z.ZodTypeAny, {
360
+ name: string;
361
+ description?: string | undefined;
362
+ parentGroupId?: string | undefined;
363
+ color?: string | undefined;
364
+ }, {
365
+ name: string;
366
+ description?: string | undefined;
367
+ parentGroupId?: string | undefined;
368
+ color?: string | undefined;
369
+ }>;
370
+ declare const editGroupSchema: z.ZodObject<{
371
+ id: z.ZodString;
372
+ color: z.ZodNullable<z.ZodString>;
373
+ hidden: z.ZodBoolean;
374
+ name: z.ZodString;
375
+ description: z.ZodOptional<z.ZodString>;
376
+ }, "strip", z.ZodTypeAny, {
377
+ name: string;
378
+ id: string;
379
+ hidden: boolean;
380
+ color: string | null;
381
+ description?: string | undefined;
382
+ }, {
383
+ name: string;
384
+ id: string;
385
+ hidden: boolean;
386
+ color: string | null;
387
+ description?: string | undefined;
388
+ }>;
389
+ declare const placeMeta: z.ZodObject<{
390
+ id: z.ZodString;
391
+ updatedAt: z.ZodDate;
392
+ groupId: z.ZodNullable<z.ZodString>;
393
+ position: z.ZodNullable<z.ZodNumber>;
394
+ error: z.ZodNullable<z.ZodString>;
395
+ lat: z.ZodNullable<z.ZodNumber>;
396
+ lon: z.ZodNullable<z.ZodNumber>;
397
+ name: z.ZodNullable<z.ZodString>;
398
+ }, "strip", z.ZodTypeAny, {
399
+ lat: number | null;
400
+ groupId: string | null;
401
+ name: string | null;
402
+ id: string;
403
+ position: number | null;
404
+ updatedAt: Date;
405
+ error: string | null;
406
+ lon: number | null;
407
+ }, {
408
+ lat: number | null;
409
+ groupId: string | null;
410
+ name: string | null;
411
+ id: string;
412
+ position: number | null;
413
+ updatedAt: Date;
414
+ error: string | null;
415
+ lon: number | null;
416
+ }>;
417
+ type PlaceMeta = z.infer<typeof placeMeta>;
418
+ declare const positionedPlaceMeta: z.ZodObject<{
419
+ id: z.ZodString;
420
+ updatedAt: z.ZodDate;
421
+ groupId: z.ZodNullable<z.ZodString>;
422
+ error: z.ZodNullable<z.ZodString>;
423
+ lat: z.ZodNullable<z.ZodNumber>;
424
+ lon: z.ZodNullable<z.ZodNumber>;
425
+ name: z.ZodNullable<z.ZodString>;
426
+ } & {
427
+ position: z.ZodNumber;
428
+ }, "strip", z.ZodTypeAny, {
429
+ lat: number | null;
430
+ groupId: string | null;
431
+ name: string | null;
432
+ id: string;
433
+ position: number;
434
+ updatedAt: Date;
435
+ error: string | null;
436
+ lon: number | null;
437
+ }, {
438
+ lat: number | null;
439
+ groupId: string | null;
440
+ name: string | null;
441
+ id: string;
442
+ position: number;
443
+ updatedAt: Date;
444
+ error: string | null;
445
+ lon: number | null;
446
+ }>;
447
+ type PositionedPlaceMeta = z.infer<typeof positionedPlaceMeta>;
448
+ declare const mappablePlaceMeta: z.ZodObject<{
449
+ id: z.ZodString;
450
+ updatedAt: z.ZodDate;
451
+ groupId: z.ZodNullable<z.ZodString>;
452
+ position: z.ZodNullable<z.ZodNumber>;
453
+ name: z.ZodNullable<z.ZodString>;
454
+ } & {
455
+ lat: z.ZodNumber;
456
+ lon: z.ZodNumber;
457
+ error: z.ZodNull;
458
+ }, "strip", z.ZodTypeAny, {
459
+ lat: number;
460
+ groupId: string | null;
461
+ name: string | null;
462
+ id: string;
463
+ position: number | null;
464
+ updatedAt: Date;
465
+ error: null;
466
+ lon: number;
467
+ }, {
468
+ lat: number;
469
+ groupId: string | null;
470
+ name: string | null;
471
+ id: string;
472
+ position: number | null;
473
+ updatedAt: Date;
474
+ error: null;
475
+ lon: number;
476
+ }>;
477
+ type MappablePlaceMeta = z.infer<typeof mappablePlaceMeta>;
478
+ /**
479
+ * Filter a list of place projections down to those that are mappable
480
+ * (have coordinates and no error).
481
+ */
482
+ declare function getMappablePlaceMetas(places: (PlaceMeta | null | undefined)[]): MappablePlaceMeta[];
483
+
484
+ export { longitude as A, mapCreationQuery as B, type Coordinates as C, mapDescription as D, mapExternalId as E, mapTitle as F, type GenerationSourceType as G, mappablePlaceMeta as H, placeDescription as I, placeMeta as J, placeName as K, type LlmProvider as L, type MappablePlaceMeta as M, placeProvider as N, placesFromList as O, type PlaceMeta as P, placesFromText as Q, placesFromUrl as R, positionedPlaceMeta as S, providerAutocompletePlace as T, reorderMapSchema as U, searchSchema as V, updateMapSchema as W, updatePlaceFormSchema as X, type PlaceProvider as a, type PositionedPlaceMeta as b, type ProviderAutocompletePlace as c, addPlacesBaseSchema as d, addPlacesFromClientAutocompleteSchema as e, addPlacesFromListSchema as f, addPlacesFromSourceSchema as g, addPlacesFromTextSchema as h, addPlacesFromUrlSchema as i, coordinates as j, createBlankMapSchema as k, createGroupSchema as l, createMapBase as m, createMapFromListSchema as n, createMapFromQueryOrUrlSchema as o, createMapFromTextSchema as p, createMapFromUrlSchema as q, createMapSchema as r, editGroupSchema as s, generationSourceType as t, getMappablePlaceMetas as u, groupColor as v, groupDescription as w, groupName as x, latitude as y, llmProvider as z };
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+ var htmlToText$1 = require('html-to-text');
5
+
6
+ // src/types/errors.ts
7
+ var MapthisError = class extends Error {
8
+ constructor(message, options) {
9
+ super(message, options);
10
+ this.name = "MapthisError";
11
+ }
12
+ };
13
+
14
+ // src/scrape/errors.ts
15
+ var ScrapeError = class extends MapthisError {
16
+ constructor(message, options) {
17
+ super(message, options);
18
+ this.name = "ScrapeError";
19
+ }
20
+ };
21
+ var InvalidUrlError = class extends ScrapeError {
22
+ constructor(message, options) {
23
+ super(message, options);
24
+ this.name = "InvalidUrlError";
25
+ }
26
+ };
27
+ var HtmlUnauthorizedError = class extends ScrapeError {
28
+ constructor(message, options) {
29
+ super(message, options);
30
+ this.name = "HtmlUnauthorizedError";
31
+ }
32
+ };
33
+ var HtmlToTextError = class extends ScrapeError {
34
+ constructor(message, options) {
35
+ super(message, options);
36
+ this.name = "HtmlToTextError";
37
+ }
38
+ };
39
+ var withHttps = (url) => {
40
+ const hasHttp = /^http?:\/\//i.test(url);
41
+ const hasHttps = /^https?:\/\//i.test(url);
42
+ if (!hasHttp && !hasHttps) return `https://${url}`;
43
+ return url;
44
+ };
45
+ async function getHtmlFromUrl(url) {
46
+ const urlFixed = withHttps(url.toLowerCase());
47
+ const isUrl = zod.z.string().url().safeParse(urlFixed);
48
+ if (!isUrl.success) throw new InvalidUrlError(`Invalid URL: ${url}`);
49
+ try {
50
+ const response = await fetch(urlFixed);
51
+ const html = await response.text();
52
+ if (response.status === 403 || response.status === 401) {
53
+ throw new HtmlUnauthorizedError(
54
+ `${response.status} Not authorized to scrape this website`
55
+ );
56
+ }
57
+ if (!response.ok) {
58
+ throw new ScrapeError(
59
+ `Bad response when getting HTML. Status: ${response.status} ${response.statusText}`
60
+ );
61
+ }
62
+ return html;
63
+ } catch (error) {
64
+ if (error instanceof TypeError) {
65
+ throw new InvalidUrlError(`Invalid URL. Original error: ${error.message}`);
66
+ }
67
+ throw error;
68
+ }
69
+ }
70
+ var SKIP_SELECTORS = [
71
+ "img",
72
+ "header",
73
+ "footer",
74
+ "audio",
75
+ "button",
76
+ "canvas",
77
+ "code",
78
+ "nav",
79
+ "#nav",
80
+ "figure",
81
+ "figcaption",
82
+ ".comment",
83
+ ".comments",
84
+ "#comments",
85
+ "#related-posts",
86
+ "#related",
87
+ ".related",
88
+ ".related-posts"
89
+ ];
90
+ function htmlToText(html) {
91
+ try {
92
+ let out = htmlToText$1.convert(html, {
93
+ wordwrap: false,
94
+ selectors: [
95
+ {
96
+ selector: "a",
97
+ options: {
98
+ ignoreHref: true,
99
+ hideLinkHrefIfSameAsText: true
100
+ }
101
+ },
102
+ ...SKIP_SELECTORS.map((tag) => ({ selector: tag, format: "skip" }))
103
+ ]
104
+ });
105
+ out = out.replaceAll("\r\n", "\n");
106
+ for (let i = 0; i < 20; i++) {
107
+ out = out.replaceAll("\n\n\n", "\n\n");
108
+ out = out.replaceAll(" ", " ");
109
+ }
110
+ return out;
111
+ } catch (error) {
112
+ if (error instanceof Error) {
113
+ throw new HtmlToTextError(`HTML to text conversion failed: ${error.message}`, {
114
+ cause: error
115
+ });
116
+ }
117
+ throw new HtmlToTextError("HTML to text conversion failed");
118
+ }
119
+ }
120
+ async function getTextFromUrl(url) {
121
+ const html = await getHtmlFromUrl(url);
122
+ return htmlToText(html);
123
+ }
124
+
125
+ exports.HtmlToTextError = HtmlToTextError;
126
+ exports.HtmlUnauthorizedError = HtmlUnauthorizedError;
127
+ exports.InvalidUrlError = InvalidUrlError;
128
+ exports.ScrapeError = ScrapeError;
129
+ exports.getHtmlFromUrl = getHtmlFromUrl;
130
+ exports.getTextFromUrl = getTextFromUrl;
131
+ exports.htmlToText = htmlToText;
132
+ //# sourceMappingURL=index.cjs.map
133
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/errors.ts","../../src/scrape/errors.ts","../../src/scrape/html.ts","../../src/scrape/text.ts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BAAgB,gCAAgC,CAAA;AAAA,EAC9D;AACJ;AAOA,eAAsB,eAAe,GAAA,EAA8B;AAC/D,EAAA,MAAM,IAAA,GAAO,MAAM,cAAA,CAAe,GAAG,CAAA;AACrC,EAAA,OAAO,WAAW,IAAI,CAAA;AAC1B","file":"index.cjs","sourcesContent":["/**\n * Base error class for every error thrown by the mapthis package.\n *\n * All feature-specific error classes (scrape, search, ai, geocoding) extend\n * this, so consumers can do `catch (e) { if (e instanceof MapthisError) ... }`\n * to distinguish library errors from other exceptions.\n */\nexport class MapthisError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options)\n this.name = \"MapthisError\"\n }\n}\n","import { MapthisError } from \"../types/errors\"\n\nexport class ScrapeError extends MapthisError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options)\n this.name = \"ScrapeError\"\n }\n}\n\n/**\n * Thrown when a provided URL fails validation or cannot be parsed by `fetch`.\n */\nexport class InvalidUrlError extends ScrapeError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options)\n this.name = \"InvalidUrlError\"\n }\n}\n\n/**\n * Thrown when a remote server returns 401 or 403 for an HTML fetch, meaning\n * the page does not permit anonymous scraping.\n */\nexport class HtmlUnauthorizedError extends ScrapeError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options)\n this.name = \"HtmlUnauthorizedError\"\n }\n}\n\n/**\n * Thrown when the underlying `html-to-text` conversion fails.\n */\nexport class HtmlToTextError extends ScrapeError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options)\n this.name = \"HtmlToTextError\"\n }\n}\n","import { z } from \"zod\"\nimport { HtmlUnauthorizedError, InvalidUrlError, ScrapeError } from \"./errors\"\n\nconst withHttps = (url: string): string => {\n const hasHttp = /^http?:\\/\\//i.test(url)\n const hasHttps = /^https?:\\/\\//i.test(url)\n if (!hasHttp && !hasHttps) return `https://${url}`\n return url\n}\n\n/**\n * Fetch the raw HTML of a URL, performing light validation first.\n *\n * - URLs without a scheme are prefixed with `https://`.\n * - URL shape is validated via Zod before the network call.\n * - 401/403 responses throw {@link HtmlUnauthorizedError}.\n * - Other non-OK responses throw {@link ScrapeError} with the status text.\n * - `TypeError` from `fetch` (typically malformed URL) is rethrown as\n * {@link InvalidUrlError}.\n *\n * This function does not set any special headers, user agent, or cookies.\n * Sites with aggressive bot-detection may return empty bodies or errors; the\n * caller is responsible for retry / user-agent rotation strategies if needed.\n */\nexport async function getHtmlFromUrl(url: string): Promise<string> {\n const urlFixed = withHttps(url.toLowerCase())\n const isUrl = z.string().url().safeParse(urlFixed)\n if (!isUrl.success) throw new InvalidUrlError(`Invalid URL: ${url}`)\n\n try {\n const response = await fetch(urlFixed)\n const html = await response.text()\n if (response.status === 403 || response.status === 401) {\n throw new HtmlUnauthorizedError(\n `${response.status} Not authorized to scrape this website`,\n )\n }\n if (!response.ok) {\n throw new ScrapeError(\n `Bad response when getting HTML. Status: ${response.status} ${response.statusText}`,\n )\n }\n return html\n } catch (error) {\n if (error instanceof TypeError) {\n throw new InvalidUrlError(`Invalid URL. Original error: ${error.message}`)\n }\n throw error\n }\n}\n","import { convert } from \"html-to-text\"\nimport { HtmlToTextError } from \"./errors\"\nimport { getHtmlFromUrl } from \"./html\"\n\nconst SKIP_SELECTORS = [\n \"img\",\n \"header\",\n \"footer\",\n \"audio\",\n \"button\",\n \"canvas\",\n \"code\",\n \"nav\",\n \"#nav\",\n \"figure\",\n \"figcaption\",\n \".comment\",\n \".comments\",\n \"#comments\",\n \"#related-posts\",\n \"#related\",\n \".related\",\n \".related-posts\",\n] as const\n\n/**\n * Convert raw HTML to plain text suitable for LLM consumption.\n *\n * The converter is configured to:\n * - strip anchor hrefs when they duplicate the link text;\n * - skip navigation, footer, comments, related-post widgets, images, and\n * other non-content elements;\n * - collapse repeated blank lines and double spaces so token count doesn't\n * balloon from whitespace.\n */\nexport function htmlToText(html: string): string {\n try {\n let out = convert(html, {\n wordwrap: false,\n selectors: [\n {\n selector: \"a\",\n options: {\n ignoreHref: true,\n hideLinkHrefIfSameAsText: true,\n },\n },\n ...SKIP_SELECTORS.map((tag) => ({ selector: tag, format: \"skip\" })),\n ],\n })\n out = out.replaceAll(\"\\r\\n\", \"\\n\")\n // Iteratively collapse blank lines and double spaces. 20 passes is\n // overkill for any realistic input but cheap and bounds worst case.\n for (let i = 0; i < 20; i++) {\n out = out.replaceAll(\"\\n\\n\\n\", \"\\n\\n\")\n out = out.replaceAll(\" \", \" \")\n }\n return out\n } catch (error) {\n if (error instanceof Error) {\n throw new HtmlToTextError(`HTML to text conversion failed: ${error.message}`, {\n cause: error,\n })\n }\n throw new HtmlToTextError(\"HTML to text conversion failed\")\n }\n}\n\n/**\n * Convenience: fetch a URL and convert its HTML to plain text in one call.\n *\n * Equivalent to `htmlToText(await getHtmlFromUrl(url))`.\n */\nexport async function getTextFromUrl(url: string): Promise<string> {\n const html = await getHtmlFromUrl(url)\n return htmlToText(html)\n}\n"]}
@@ -0,0 +1,60 @@
1
+ import { M as MapthisError } from '../errors-Bw97z_4m.cjs';
2
+
3
+ declare class ScrapeError extends MapthisError {
4
+ constructor(message?: string, options?: ErrorOptions);
5
+ }
6
+ /**
7
+ * Thrown when a provided URL fails validation or cannot be parsed by `fetch`.
8
+ */
9
+ declare class InvalidUrlError extends ScrapeError {
10
+ constructor(message?: string, options?: ErrorOptions);
11
+ }
12
+ /**
13
+ * Thrown when a remote server returns 401 or 403 for an HTML fetch, meaning
14
+ * the page does not permit anonymous scraping.
15
+ */
16
+ declare class HtmlUnauthorizedError extends ScrapeError {
17
+ constructor(message?: string, options?: ErrorOptions);
18
+ }
19
+ /**
20
+ * Thrown when the underlying `html-to-text` conversion fails.
21
+ */
22
+ declare class HtmlToTextError extends ScrapeError {
23
+ constructor(message?: string, options?: ErrorOptions);
24
+ }
25
+
26
+ /**
27
+ * Fetch the raw HTML of a URL, performing light validation first.
28
+ *
29
+ * - URLs without a scheme are prefixed with `https://`.
30
+ * - URL shape is validated via Zod before the network call.
31
+ * - 401/403 responses throw {@link HtmlUnauthorizedError}.
32
+ * - Other non-OK responses throw {@link ScrapeError} with the status text.
33
+ * - `TypeError` from `fetch` (typically malformed URL) is rethrown as
34
+ * {@link InvalidUrlError}.
35
+ *
36
+ * This function does not set any special headers, user agent, or cookies.
37
+ * Sites with aggressive bot-detection may return empty bodies or errors; the
38
+ * caller is responsible for retry / user-agent rotation strategies if needed.
39
+ */
40
+ declare function getHtmlFromUrl(url: string): Promise<string>;
41
+
42
+ /**
43
+ * Convert raw HTML to plain text suitable for LLM consumption.
44
+ *
45
+ * The converter is configured to:
46
+ * - strip anchor hrefs when they duplicate the link text;
47
+ * - skip navigation, footer, comments, related-post widgets, images, and
48
+ * other non-content elements;
49
+ * - collapse repeated blank lines and double spaces so token count doesn't
50
+ * balloon from whitespace.
51
+ */
52
+ declare function htmlToText(html: string): string;
53
+ /**
54
+ * Convenience: fetch a URL and convert its HTML to plain text in one call.
55
+ *
56
+ * Equivalent to `htmlToText(await getHtmlFromUrl(url))`.
57
+ */
58
+ declare function getTextFromUrl(url: string): Promise<string>;
59
+
60
+ export { HtmlToTextError, HtmlUnauthorizedError, InvalidUrlError, ScrapeError, getHtmlFromUrl, getTextFromUrl, htmlToText };