@sholajegede/bright-data-sync 0.1.1-alpha.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 (58) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +182 -0
  3. package/dist/client/_generated/_ignore.d.ts +1 -0
  4. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  5. package/dist/client/_generated/_ignore.js +3 -0
  6. package/dist/client/_generated/_ignore.js.map +1 -0
  7. package/dist/client/index.d.ts +77 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +61 -0
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +34 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +67 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +121 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +78 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +3 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/lib.d.ts +83 -0
  32. package/dist/component/lib.d.ts.map +1 -0
  33. package/dist/component/lib.js +314 -0
  34. package/dist/component/lib.js.map +1 -0
  35. package/dist/component/schema.d.ts +47 -0
  36. package/dist/component/schema.d.ts.map +1 -0
  37. package/dist/component/schema.js +28 -0
  38. package/dist/component/schema.js.map +1 -0
  39. package/dist/react/index.d.ts +2 -0
  40. package/dist/react/index.d.ts.map +1 -0
  41. package/dist/react/index.js +6 -0
  42. package/dist/react/index.js.map +1 -0
  43. package/package.json +102 -0
  44. package/src/client/_generated/_ignore.ts +1 -0
  45. package/src/client/index.test.ts +13 -0
  46. package/src/client/index.ts +100 -0
  47. package/src/client/setup.test.ts +26 -0
  48. package/src/component/_generated/api.ts +50 -0
  49. package/src/component/_generated/component.ts +85 -0
  50. package/src/component/_generated/dataModel.ts +60 -0
  51. package/src/component/_generated/server.ts +156 -0
  52. package/src/component/convex.config.ts +3 -0
  53. package/src/component/lib.test.ts +21 -0
  54. package/src/component/lib.ts +375 -0
  55. package/src/component/schema.ts +30 -0
  56. package/src/component/setup.test.ts +11 -0
  57. package/src/react/index.ts +7 -0
  58. package/src/test.ts +18 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # @sholajegede/bright-data-sync
2
+
3
+ A [Convex component](https://www.convex.dev/components) that wraps [Bright Data's](https://brightdata.com) SERP API and Web Unlocker with reactive caching. Search results and scraped page content are stored in component-owned Convex tables with configurable TTLs — apps query cached results reactively, with no re-fetching if data is still fresh.
4
+
5
+ [![npm version](https://badge.fury.io/js/@sholajegede%2Fbright-data-sync.svg)](https://badge.fury.io/js/@sholajegede%2Fbright-data-sync)
6
+
7
+ Found a bug? Feature request? [File it here](https://github.com/sholajegede/bright-data-sync/issues).
8
+
9
+ <!-- START: Include on https://convex.dev/components -->
10
+
11
+ ## Features
12
+
13
+ - **SERP search** via Bright Data's SERP API — Google search results cached in Convex
14
+ - **Web scraping** via Bright Data's Web Unlocker — page content cached in Convex
15
+ - **Reactive queries** — `useQuery` on cached results, live updates when cache refreshes
16
+ - **Configurable TTLs** — per-request or global defaults for searches and pages
17
+ - **Cache invalidation** — force re-fetch any query or URL on demand
18
+ - **No re-fetching** — returns cached data instantly if still within TTL
19
+
20
+ ## Prerequisites
21
+
22
+ - A [Bright Data](https://brightdata.com) account with:
23
+ - A SERP API zone (default zone name: `serp_api1`)
24
+ - A Web Unlocker zone (default zone name: `web_unlocker1`)
25
+ - An API token
26
+
27
+ ## Installation
28
+ ```sh
29
+ npm install @sholajegede/bright-data-sync
30
+ ```
31
+
32
+ Add the component to your `convex/convex.config.ts`:
33
+ ```ts
34
+ import { defineApp } from "convex/server";
35
+ import brightDataSync from "@sholajegede/bright-data-sync/convex.config.js";
36
+
37
+ const app = defineApp();
38
+ app.use(brightDataSync);
39
+
40
+ export default app;
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ Instantiate the client in your Convex functions file, passing your Bright Data credentials:
46
+ ```ts
47
+ // convex/brightData.ts
48
+ import { components } from "./_generated/api.js";
49
+ import { BrightDataSync } from "@sholajegede/bright-data-sync";
50
+
51
+ export const brightData = new BrightDataSync(components.brightDataSync, {
52
+ BRIGHTDATA_API_TOKEN: process.env.BRIGHTDATA_API_TOKEN!,
53
+ BRIGHTDATA_SEARCH_ZONE: process.env.BRIGHTDATA_SEARCH_ZONE, // optional, default: "serp_api1"
54
+ BRIGHTDATA_WEB_UNLOCKER_ZONE: process.env.BRIGHTDATA_WEB_UNLOCKER_ZONE, // optional, default: "web_unlocker1"
55
+ DEFAULT_SEARCH_TTL_MS: 1000 * 60 * 60, // optional, default: 1 hour
56
+ DEFAULT_PAGE_TTL_MS: 1000 * 60 * 60 * 6, // optional, default: 6 hours
57
+ });
58
+ ```
59
+
60
+ ### Search the web
61
+ ```ts
62
+ // convex/myFunctions.ts
63
+ import { action, query } from "./_generated/server.js";
64
+ import { components } from "./_generated/api.js";
65
+ import { brightData } from "./brightData.js";
66
+ import { v } from "convex/values";
67
+
68
+ // Fetch (or return cached) search results
69
+ export const searchWeb = action({
70
+ args: { query: v.string() },
71
+ handler: async (ctx, args) => {
72
+ return await brightData.search(ctx, { query: args.query });
73
+ },
74
+ });
75
+
76
+ // Reactive query — subscribe to cached results from the frontend
77
+ export const getCachedSearch = query({
78
+ args: { query: v.string() },
79
+ handler: async (ctx, args) => {
80
+ return await ctx.runQuery(components.brightDataSync.lib.getSearch, {
81
+ query: args.query,
82
+ });
83
+ },
84
+ });
85
+ ```
86
+ ```tsx
87
+ // React component
88
+ const results = useQuery(api.myFunctions.getCachedSearch, { query: "convex database" });
89
+ // results.isFresh — true if within TTL
90
+ // results.results — JSON string of search results
91
+ // results.fetchedAt — timestamp of last fetch
92
+ ```
93
+
94
+ ### Scrape a page
95
+ ```ts
96
+ export const scrapePage = action({
97
+ args: { url: v.string() },
98
+ handler: async (ctx, args) => {
99
+ return await brightData.scrape(ctx, { url: args.url });
100
+ },
101
+ });
102
+
103
+ export const getCachedPage = query({
104
+ args: { url: v.string() },
105
+ handler: async (ctx, args) => {
106
+ return await ctx.runQuery(components.brightDataSync.lib.getPage, {
107
+ url: args.url,
108
+ });
109
+ },
110
+ });
111
+ ```
112
+
113
+ ### Invalidate cache
114
+ ```ts
115
+ export const invalidateCache = action({
116
+ args: {
117
+ query: v.optional(v.string()),
118
+ url: v.optional(v.string()),
119
+ },
120
+ handler: async (ctx, args) => {
121
+ return await brightData.invalidate(ctx, args);
122
+ },
123
+ });
124
+ ```
125
+
126
+ ## API
127
+
128
+ ### `BrightDataSync` class
129
+
130
+ | Method | Description |
131
+ |--------|-------------|
132
+ | `search(ctx, { query, vertical?, recency?, ttlMs? })` | Search via Bright Data SERP API. Returns cached results if fresh. |
133
+ | `scrape(ctx, { url, ttlMs? })` | Scrape a URL via Web Unlocker. Returns cached content if fresh. |
134
+ | `invalidate(ctx, { query?, url? })` | Delete cached entry to force re-fetch on next call. |
135
+
136
+ ### Reactive queries (call via `ctx.runQuery`)
137
+
138
+ | Function | Description |
139
+ |----------|-------------|
140
+ | `components.brightDataSync.lib.getSearch({ query })` | Get cached search result. Returns `null` if not yet fetched. |
141
+ | `components.brightDataSync.lib.getPage({ url })` | Get cached page content. Returns `null` if not yet fetched. |
142
+
143
+ Both return `{ results/content, fetchedAt, expiresAt, isFresh }`.
144
+
145
+ ### `search` verticals
146
+
147
+ Pass a `vertical` string to search specific Google verticals:
148
+
149
+ | Value | Vertical |
150
+ |-------|----------|
151
+ | _(omit)_ | Web search |
152
+ | `nws` | News |
153
+ | `shop` | Shopping |
154
+ | `isch` | Images |
155
+ | `vid` | Videos |
156
+
157
+ ### `search` recency
158
+
159
+ Pass a `recency` string to filter by date:
160
+
161
+ | Value | Range |
162
+ |-------|-------|
163
+ | `d` | Past day |
164
+ | `w` | Past week |
165
+ | `m` | Past month |
166
+ | `y` | Past year |
167
+
168
+ <!-- END: Include on https://convex.dev/components -->
169
+
170
+ ## Example app
171
+
172
+ See [`example/`](./example) for a working Vite + React demo showing live SERP search and page scraping with reactive cache display.
173
+
174
+ ## Development
175
+ ```sh
176
+ npm i
177
+ npm run dev
178
+ ```
179
+
180
+ ## License
181
+
182
+ Apache-2.0
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=_ignore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ignore.d.ts","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This is only here so convex-test can detect a _generated folder
3
+ //# sourceMappingURL=_ignore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ignore.js","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":";AAAA,kEAAkE"}
@@ -0,0 +1,77 @@
1
+ import type { GenericActionCtx, GenericDataModel } from "convex/server";
2
+ import type { ComponentApi } from "../component/_generated/component.js";
3
+ export type BrightDataSyncOptions = {
4
+ /** Your Bright Data API token */
5
+ BRIGHTDATA_API_TOKEN: string;
6
+ /** Bright Data SERP zone name (default: "serp_api1") */
7
+ BRIGHTDATA_SEARCH_ZONE?: string;
8
+ /** Bright Data Web Unlocker zone name (default: "web_unlocker1") */
9
+ BRIGHTDATA_WEB_UNLOCKER_ZONE?: string;
10
+ /** Default TTL for search results in ms (default: 1 hour) */
11
+ DEFAULT_SEARCH_TTL_MS?: number;
12
+ /** Default TTL for scraped pages in ms (default: 6 hours) */
13
+ DEFAULT_PAGE_TTL_MS?: number;
14
+ };
15
+ export type SearchArgs = {
16
+ query: string;
17
+ vertical?: string;
18
+ recency?: string;
19
+ ttlMs?: number;
20
+ };
21
+ export type ScrapeArgs = {
22
+ url: string;
23
+ ttlMs?: number;
24
+ };
25
+ /**
26
+ * Client wrapper for the BrightDataSync Convex component.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * // convex/brightData.ts
31
+ * import { components } from "./_generated/api.js";
32
+ * import { BrightDataSync } from "@sholajegede/bright-data-sync";
33
+ *
34
+ * export const brightData = new BrightDataSync(components.brightDataSync, {
35
+ * BRIGHTDATA_API_TOKEN: process.env.BRIGHTDATA_API_TOKEN!,
36
+ * });
37
+ *
38
+ * // In an action:
39
+ * export const mySearch = action({
40
+ * args: { q: v.string() },
41
+ * handler: async (ctx, args) => {
42
+ * return await brightData.search(ctx, { query: args.q });
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ export declare class BrightDataSync {
48
+ component: ComponentApi;
49
+ private options;
50
+ constructor(component: ComponentApi, options: BrightDataSyncOptions);
51
+ /**
52
+ * Search via Bright Data SERP API. Returns cached results if fresh.
53
+ */
54
+ search(ctx: ActionCtx, args: SearchArgs): Promise<{
55
+ fetchedAt: number;
56
+ fromCache: boolean;
57
+ results: string;
58
+ }>;
59
+ /**
60
+ * Scrape a URL via Bright Data Web Unlocker. Returns cached content if fresh.
61
+ */
62
+ scrape(ctx: ActionCtx, args: ScrapeArgs): Promise<{
63
+ content: string;
64
+ fetchedAt: number;
65
+ fromCache: boolean;
66
+ }>;
67
+ /**
68
+ * Invalidate cached search results or page content.
69
+ */
70
+ invalidate(ctx: ActionCtx, args: {
71
+ query?: string;
72
+ url?: string;
73
+ }): Promise<null>;
74
+ }
75
+ export type { ComponentApi };
76
+ type ActionCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation" | "runAction">;
77
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEzE,MAAM,MAAM,qBAAqB,GAAG;IAClC,iCAAiC;IACjC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,wDAAwD;IACxD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,oEAAoE;IACpE,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,6DAA6D;IAC7D,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,6DAA6D;IAC7D,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,cAAc;IAEhB,SAAS,EAAE,YAAY;IAC9B,OAAO,CAAC,OAAO;gBADR,SAAS,EAAE,YAAY,EACtB,OAAO,EAAE,qBAAqB;IAGxC;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU;;;;;IAW7C;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU;;;;;IAS7C;;OAEG;IACG,UAAU,CACd,GAAG,EAAE,SAAS,EACd,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE;CAIzC;AAGD,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B,KAAK,SAAS,GAAG,IAAI,CACnB,gBAAgB,CAAC,gBAAgB,CAAC,EAClC,UAAU,GAAG,aAAa,GAAG,WAAW,CACzC,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Client wrapper for the BrightDataSync Convex component.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * // convex/brightData.ts
7
+ * import { components } from "./_generated/api.js";
8
+ * import { BrightDataSync } from "@sholajegede/bright-data-sync";
9
+ *
10
+ * export const brightData = new BrightDataSync(components.brightDataSync, {
11
+ * BRIGHTDATA_API_TOKEN: process.env.BRIGHTDATA_API_TOKEN!,
12
+ * });
13
+ *
14
+ * // In an action:
15
+ * export const mySearch = action({
16
+ * args: { q: v.string() },
17
+ * handler: async (ctx, args) => {
18
+ * return await brightData.search(ctx, { query: args.q });
19
+ * },
20
+ * });
21
+ * ```
22
+ */
23
+ export class BrightDataSync {
24
+ component;
25
+ options;
26
+ constructor(component, options) {
27
+ this.component = component;
28
+ this.options = options;
29
+ }
30
+ /**
31
+ * Search via Bright Data SERP API. Returns cached results if fresh.
32
+ */
33
+ async search(ctx, args) {
34
+ return ctx.runAction(this.component.lib.search, {
35
+ query: args.query,
36
+ vertical: args.vertical,
37
+ recency: args.recency,
38
+ ttlMs: args.ttlMs ?? this.options.DEFAULT_SEARCH_TTL_MS,
39
+ brightdataApiToken: this.options.BRIGHTDATA_API_TOKEN,
40
+ brightdataSearchZone: this.options.BRIGHTDATA_SEARCH_ZONE,
41
+ });
42
+ }
43
+ /**
44
+ * Scrape a URL via Bright Data Web Unlocker. Returns cached content if fresh.
45
+ */
46
+ async scrape(ctx, args) {
47
+ return ctx.runAction(this.component.lib.scrape, {
48
+ url: args.url,
49
+ ttlMs: args.ttlMs ?? this.options.DEFAULT_PAGE_TTL_MS,
50
+ brightdataApiToken: this.options.BRIGHTDATA_API_TOKEN,
51
+ brightdataWebUnlockerZone: this.options.BRIGHTDATA_WEB_UNLOCKER_ZONE,
52
+ });
53
+ }
54
+ /**
55
+ * Invalidate cached search results or page content.
56
+ */
57
+ async invalidate(ctx, args) {
58
+ return ctx.runAction(this.component.lib.invalidate, args);
59
+ }
60
+ }
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,cAAc;IAEhB;IACC;IAFV,YACS,SAAuB,EACtB,OAA8B;QAD/B,cAAS,GAAT,SAAS,CAAc;QACtB,YAAO,GAAP,OAAO,CAAuB;IACrC,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,GAAc,EAAE,IAAgB;QAC3C,OAAO,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE;YAC9C,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,qBAAqB;YACvD,kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB;YACrD,oBAAoB,EAAE,IAAI,CAAC,OAAO,CAAC,sBAAsB;SAC1D,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,GAAc,EAAE,IAAgB;QAC3C,OAAO,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE;YAC9C,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,mBAAmB;YACrD,kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB;YACrD,yBAAyB,EAAE,IAAI,CAAC,OAAO,CAAC,4BAA4B;SACrE,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CACd,GAAc,EACd,IAAsC;QAEtC,OAAO,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;CACF"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Generated `api` utility.
3
+ *
4
+ * THIS CODE IS AUTOMATICALLY GENERATED.
5
+ *
6
+ * To regenerate, run `npx convex dev`.
7
+ * @module
8
+ */
9
+ import type * as lib from "../lib.js";
10
+ import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
11
+ declare const fullApi: ApiFromModules<{
12
+ lib: typeof lib;
13
+ }>;
14
+ /**
15
+ * A utility for referencing Convex functions in your app's public API.
16
+ *
17
+ * Usage:
18
+ * ```js
19
+ * const myFunctionReference = api.myModule.myFunction;
20
+ * ```
21
+ */
22
+ export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
23
+ /**
24
+ * A utility for referencing Convex functions in your app's internal API.
25
+ *
26
+ * Usage:
27
+ * ```js
28
+ * const myFunctionReference = internal.myModule.myFunction;
29
+ * ```
30
+ */
31
+ export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
32
+ export declare const components: {};
33
+ export {};
34
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,WAAW,CAAC;AAEtC,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,GAAG,EAAE,OAAO,GAAG,CAAC;CACjB,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+ import { anyApi, componentsGeneric } from "convex/server";
11
+ const fullApi = anyApi;
12
+ /**
13
+ * A utility for referencing Convex functions in your app's public API.
14
+ *
15
+ * Usage:
16
+ * ```js
17
+ * const myFunctionReference = api.myModule.myFunction;
18
+ * ```
19
+ */
20
+ export const api = anyApi;
21
+ /**
22
+ * A utility for referencing Convex functions in your app's internal API.
23
+ *
24
+ * Usage:
25
+ * ```js
26
+ * const myFunctionReference = internal.myModule.myFunction;
27
+ * ```
28
+ */
29
+ export const internal = anyApi;
30
+ export const components = componentsGeneric();
31
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AASH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAER,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAmB,CAAC"}