@youdotcom-oss/api 0.2.2 → 0.3.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/bin/cli.js CHANGED
@@ -15,7 +15,7 @@ import { parseArgs as parseArgs2 } from "node:util";
15
15
  // package.json
16
16
  var package_default = {
17
17
  name: "@youdotcom-oss/api",
18
- version: "0.2.2",
18
+ version: "0.3.0",
19
19
  description: "You.com API client with bundled CLI for agents supporting Agent Skills",
20
20
  license: "MIT",
21
21
  engines: {
@@ -4768,9 +4768,9 @@ var ContentsItemSchema = object({
4768
4768
  var ContentsApiResponseSchema = array(ContentsItemSchema);
4769
4769
 
4770
4770
  // src/shared/api.constants.ts
4771
- var SEARCH_API_URL = "https://ydc-index.io/v1/search";
4772
- var DEEP_SEARCH_API_URL = "https://api.you.com/v1/deep_search";
4773
- var CONTENTS_API_URL = "https://ydc-index.io/v1/contents";
4771
+ var SEARCH_API_URL = process.env.YDC_SEARCH_API_URL || "https://ydc-index.io/v1/search";
4772
+ var DEEP_SEARCH_API_URL = process.env.YDC_DEEP_SEARCH_API_URL || "https://api.you.com/v1/deep_search";
4773
+ var CONTENTS_API_URL = process.env.YDC_CONTENTS_API_URL || "https://ydc-index.io/v1/contents";
4774
4774
 
4775
4775
  // src/shared/check-response-for-errors.ts
4776
4776
  var checkResponseForErrors = (responseData) => {
@@ -5044,6 +5044,23 @@ var fetchSearchResults = async ({
5044
5044
  throw new Error("Rate limited by You.com API. Please try again later.");
5045
5045
  } else if (errorCode === 403) {
5046
5046
  throw new Error("Forbidden. Please check your You.com API key.");
5047
+ } else if (errorCode === 402) {
5048
+ let errorMessage = "Free tier limit exceeded. Please upgrade to continue.";
5049
+ let upgradeUrl = "https://you.com/platform";
5050
+ try {
5051
+ const errorBody = await response.json();
5052
+ if (errorBody?.message) {
5053
+ errorMessage = errorBody.message;
5054
+ }
5055
+ if (errorBody?.upgrade_url) {
5056
+ upgradeUrl = errorBody.upgrade_url;
5057
+ }
5058
+ if (errorBody?.reset_at) {
5059
+ const resetDate = new Date(errorBody.reset_at).toLocaleDateString();
5060
+ errorMessage += ` Limit resets on ${resetDate}.`;
5061
+ }
5062
+ } catch {}
5063
+ throw new Error(`${errorMessage} Upgrade at: ${upgradeUrl}`);
5047
5064
  }
5048
5065
  throw new Error(`Failed to perform search. Error code: ${errorCode}`);
5049
5066
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@youdotcom-oss/api",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "You.com API client with bundled CLI for agents supporting Agent Skills",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -42,6 +42,27 @@ export const fetchSearchResults = async ({
42
42
  throw new Error('Rate limited by You.com API. Please try again later.')
43
43
  } else if (errorCode === 403) {
44
44
  throw new Error('Forbidden. Please check your You.com API key.')
45
+ } else if (errorCode === 402) {
46
+ let errorMessage = 'Free tier limit exceeded. Please upgrade to continue.'
47
+ let upgradeUrl = 'https://you.com/platform'
48
+
49
+ try {
50
+ const errorBody = (await response.json()) as any
51
+ if (errorBody?.message) {
52
+ errorMessage = errorBody.message
53
+ }
54
+ if (errorBody?.upgrade_url) {
55
+ upgradeUrl = errorBody.upgrade_url
56
+ }
57
+ if (errorBody?.reset_at) {
58
+ const resetDate = new Date(errorBody.reset_at).toLocaleDateString()
59
+ errorMessage += ` Limit resets on ${resetDate}.`
60
+ }
61
+ } catch {
62
+ // If parsing fails, use default message
63
+ }
64
+
65
+ throw new Error(`${errorMessage} Upgrade at: ${upgradeUrl}`)
45
66
  }
46
67
 
47
68
  throw new Error(`Failed to perform search. Error code: ${errorCode}`)
@@ -5,6 +5,6 @@
5
5
  * Exported for use in tests and external packages.
6
6
  */
7
7
 
8
- export const SEARCH_API_URL = 'https://ydc-index.io/v1/search'
9
- export const DEEP_SEARCH_API_URL = 'https://api.you.com/v1/deep_search'
10
- export const CONTENTS_API_URL = 'https://ydc-index.io/v1/contents'
8
+ export const SEARCH_API_URL = process.env.YDC_SEARCH_API_URL || 'https://ydc-index.io/v1/search'
9
+ export const DEEP_SEARCH_API_URL = process.env.YDC_DEEP_SEARCH_API_URL || 'https://api.you.com/v1/deep_search'
10
+ export const CONTENTS_API_URL = process.env.YDC_CONTENTS_API_URL || 'https://ydc-index.io/v1/contents'