nosible 0.1.5

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 (44) hide show
  1. package/README.md +438 -0
  2. package/dist/index.cjs +1841 -0
  3. package/dist/index.cjs.map +29 -0
  4. package/dist/index.js +1815 -0
  5. package/dist/index.js.map +29 -0
  6. package/package.json +63 -0
  7. package/src/api/api.test.ts +366 -0
  8. package/src/api/index.ts +179 -0
  9. package/src/api/schemas.ts +152 -0
  10. package/src/client.test.ts +685 -0
  11. package/src/client.ts +762 -0
  12. package/src/index.ts +4 -0
  13. package/src/scrape/types.ts +119 -0
  14. package/src/scrape/webPageData.test.ts +302 -0
  15. package/src/scrape/webPageData.ts +103 -0
  16. package/src/search/analyze.test.ts +396 -0
  17. package/src/search/analyze.ts +151 -0
  18. package/src/search/bulkSearch.ts +62 -0
  19. package/src/search/result.test.ts +423 -0
  20. package/src/search/result.ts +391 -0
  21. package/src/search/result.types.ts +32 -0
  22. package/src/search/resultFactory.ts +21 -0
  23. package/src/search/resultSet.io.test.ts +320 -0
  24. package/src/search/resultSet.test.ts +368 -0
  25. package/src/search/resultSet.ts +387 -0
  26. package/src/search/resultSet.types.ts +3 -0
  27. package/src/search/search.test.ts +299 -0
  28. package/src/search/search.ts +187 -0
  29. package/src/search/searchSet.io.test.ts +321 -0
  30. package/src/search/searchSet.ts +122 -0
  31. package/src/search/sqlFilter.test.ts +129 -0
  32. package/src/search/sqlFilter.ts +147 -0
  33. package/src/test-utils/mocks.ts +159 -0
  34. package/src/topicTrend/topicTrend.ts +53 -0
  35. package/src/utils/browser.test.ts +209 -0
  36. package/src/utils/browser.ts +21 -0
  37. package/src/utils/fernet.ts +47 -0
  38. package/src/utils/file.test.ts +81 -0
  39. package/src/utils/file.ts +195 -0
  40. package/src/utils/index.ts +7 -0
  41. package/src/utils/llm.test.ts +279 -0
  42. package/src/utils/llm.ts +244 -0
  43. package/src/utils/userPlan.test.ts +332 -0
  44. package/src/utils/userPlan.ts +211 -0
@@ -0,0 +1,211 @@
1
+ import Bottleneck from "bottleneck";
2
+
3
+ type Limit = {
4
+ minute: number;
5
+ month: number;
6
+ };
7
+
8
+ export type Plan = {
9
+ key: string;
10
+ name: string;
11
+ rateLimits: {
12
+ scrapeUrl: Limit;
13
+ bulk: Limit;
14
+ fast: Limit;
15
+ };
16
+ };
17
+
18
+ const planLimits: Plan[] = [
19
+ {
20
+ key: "test",
21
+ name: "Test",
22
+ rateLimits: {
23
+ scrapeUrl: {minute: 60, month: 300},
24
+ bulk: {minute: 60, month: 300},
25
+ fast: {minute: 60, month: 3000},
26
+ },
27
+ },
28
+ {
29
+ key: "basic",
30
+ name: "Basic",
31
+ rateLimits: {
32
+ scrapeUrl: {minute: 60, month: 1400},
33
+ bulk: {minute: 60, month: 1400},
34
+ fast: {minute: 60, month: 14_000},
35
+ },
36
+ },
37
+ {
38
+ key: "pro",
39
+ name: "Pro",
40
+ rateLimits: {
41
+ scrapeUrl: {minute: 60, month: 6700},
42
+ bulk: {minute: 60, month: 6700},
43
+ fast: {minute: 60, month: 67_000},
44
+ },
45
+ },
46
+ {
47
+ key: "pro+",
48
+ name: "Pro+",
49
+ rateLimits: {
50
+ scrapeUrl: {minute: 60, month: 32_000},
51
+ bulk: {minute: 60, month: 32_000},
52
+ fast: {minute: 60, month: 320_000},
53
+ },
54
+ },
55
+ {
56
+ key: "bus",
57
+ name: "Business",
58
+ rateLimits: {
59
+ scrapeUrl: {minute: 60, month: 200_000},
60
+ bulk: {minute: 60, month: 200_000},
61
+ fast: {minute: 60, month: 2_000_000},
62
+ },
63
+ },
64
+ {
65
+ key: "bus+",
66
+ name: "Business+",
67
+ rateLimits: {
68
+ scrapeUrl: {minute: 60, month: 500_000},
69
+ bulk: {minute: 60, month: 500_000},
70
+ fast: {minute: 120, month: 5_000_000},
71
+ },
72
+ },
73
+ {
74
+ key: "ent",
75
+ name: "Enterprise",
76
+ rateLimits: {
77
+ scrapeUrl: {minute: 60, month: 1_500_000},
78
+ bulk: {minute: 60, month: 1_500_000},
79
+ fast: {minute: 360, month: 15_000_000},
80
+ },
81
+ },
82
+ {
83
+ key: "prod",
84
+ name: "Production",
85
+ rateLimits: {
86
+ scrapeUrl: {minute: 60, month: 1_500_000},
87
+ bulk: {minute: 60, month: 1_500_000},
88
+ fast: {minute: 360, month: 15_000_000},
89
+ },
90
+ },
91
+ {
92
+ key: "chat",
93
+ name: "Chat",
94
+ rateLimits: {
95
+ scrapeUrl: {minute: 60, month: 1_500_000},
96
+ bulk: {minute: 60, month: 1_500_000},
97
+ fast: {minute: 360, month: 15_000_000},
98
+ },
99
+ },
100
+ {
101
+ key: "self",
102
+ name: "Self",
103
+ rateLimits: {
104
+ scrapeUrl: {minute: 6000, month: 1_500_000},
105
+ bulk: {minute: 6000, month: 1_500_000},
106
+ fast: {minute: 36_000, month: 15_000_000},
107
+ },
108
+ },
109
+ {
110
+ key: "cons",
111
+ name: "Consumer",
112
+ rateLimits: {
113
+ scrapeUrl: {minute: 60, month: 3000},
114
+ bulk: {minute: 60, month: 3000},
115
+ fast: {minute: 120, month: 30_000},
116
+ },
117
+ },
118
+ {
119
+ key: "stup",
120
+ name: "Startup",
121
+ rateLimits: {
122
+ scrapeUrl: {minute: 60, month: 30_000},
123
+ bulk: {minute: 60, month: 30_000},
124
+ fast: {minute: 360, month: 300_000},
125
+ },
126
+ },
127
+ {
128
+ key: "busn",
129
+ name: "Business Network",
130
+ rateLimits: {
131
+ scrapeUrl: {minute: 60, month: 300_000},
132
+ bulk: {minute: 60, month: 300_000},
133
+ fast: {minute: 360, month: 3_000_000},
134
+ },
135
+ },
136
+ ];
137
+
138
+ export const getUserPlan = (apiKey: string): Plan => {
139
+ const planKey = apiKey.split("|")[0];
140
+ const plan = planLimits.find((p) => p.key === planKey);
141
+ if (!plan) {
142
+ throw new Error("Invalid API key");
143
+ }
144
+ return plan;
145
+ };
146
+
147
+ const minMs = 60 * 1000;
148
+ const monthMs = 60 * 60 * 24 * 30 * 1000;
149
+
150
+ export const getLimiters = (
151
+ planKey: string
152
+ ): {
153
+ scrapeUrl: Bottleneck;
154
+ bulk: Bottleneck;
155
+ fast: Bottleneck;
156
+ } => {
157
+ const plan = getUserPlan(planKey);
158
+
159
+ // TODO: Add max delay
160
+
161
+ // Create limiter for scrape-url method
162
+ const scrapeUrlMinLimiter = new Bottleneck({
163
+ reservoir: plan.rateLimits.scrapeUrl.minute, // Initial number of requests
164
+ reservoirRefreshAmount: plan.rateLimits.scrapeUrl.minute, // Refill amount
165
+ reservoirRefreshInterval: minMs, // Refill every minute (in ms)
166
+ });
167
+
168
+ const scrapeUrlMonthLimiter = new Bottleneck({
169
+ reservoir: plan.rateLimits.scrapeUrl.month,
170
+ reservoirRefreshAmount: plan.rateLimits.scrapeUrl.month,
171
+ reservoirRefreshInterval: monthMs,
172
+ });
173
+
174
+ const scrapeUrlLimiter = scrapeUrlMinLimiter.chain(scrapeUrlMonthLimiter);
175
+
176
+ // Create limiter for bulk method
177
+ const bulkMinLimiter = new Bottleneck({
178
+ reservoir: plan.rateLimits.bulk.minute,
179
+ reservoirRefreshAmount: plan.rateLimits.bulk.minute,
180
+ reservoirRefreshInterval: minMs,
181
+ });
182
+
183
+ const bulkMonthLimiter = new Bottleneck({
184
+ reservoir: plan.rateLimits.bulk.month,
185
+ reservoirRefreshAmount: plan.rateLimits.bulk.month,
186
+ reservoirRefreshInterval: monthMs,
187
+ });
188
+
189
+ const bulkLimiter = bulkMinLimiter.chain(bulkMonthLimiter);
190
+
191
+ // Create limiter for fast method
192
+ const fastMinLimiter = new Bottleneck({
193
+ reservoir: plan.rateLimits.fast.minute,
194
+ reservoirRefreshAmount: plan.rateLimits.fast.minute,
195
+ reservoirRefreshInterval: minMs,
196
+ });
197
+
198
+ const fastMonthLimiter = new Bottleneck({
199
+ reservoir: plan.rateLimits.fast.month,
200
+ reservoirRefreshAmount: plan.rateLimits.fast.month,
201
+ reservoirRefreshInterval: monthMs,
202
+ });
203
+
204
+ const fastLimiter = fastMinLimiter.chain(fastMonthLimiter);
205
+
206
+ return {
207
+ scrapeUrl: scrapeUrlLimiter,
208
+ bulk: bulkLimiter,
209
+ fast: fastLimiter,
210
+ };
211
+ };