@dremio/js-sdk 0.12.1 → 0.12.2

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.
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Problem, ValidationProblem } from "./Problem.js";
17
+ import { RateLimitError } from "./problems.js";
17
18
  const extractResponseBody = async (res) => {
18
19
  if (res.headers.get("content-type")?.includes("application/json")) {
19
20
  return (await res.json());
@@ -26,7 +27,12 @@ export class HttpError extends Error {
26
27
  status;
27
28
  body;
28
29
  constructor(status, body) {
29
- if (isApiV1Error(body)) {
30
+ if (status === 429) {
31
+ const err = new RateLimitError();
32
+ super(err.title);
33
+ this.body = err;
34
+ }
35
+ else if (isApiV1Error(body)) {
30
36
  super(body.errorMessage);
31
37
  this.body = body;
32
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../../src/common/HttpError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,mBAAmB,GAAG,KAAK,EAAE,GAAa,EAAE,EAAE;IAClD,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAClE,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAqB,CAAC;IAChD,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,MAAM,CAAS;IACf,IAAI,CAAoD;IAEjE,YAAY,MAAc,EAAE,IAAa;QACvC,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACzB,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AAC,IAAI,IAAI,CAAC,KAAK,KAAK,oDAAoD,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Problem, ValidationProblem } from \"./Problem.ts\";\n\nconst extractResponseBody = async (res: Response) => {\n if (res.headers.get(\"content-type\")?.includes(\"application/json\")) {\n return (await res.json()) as Promise<unknown>;\n } else {\n return await res.text();\n }\n};\n\nexport class HttpError extends Error {\n readonly status: number;\n readonly body: ApiV1Error | Problem | ValidationProblem | string;\n\n constructor(status: number, body: unknown) {\n if (isApiV1Error(body)) {\n super(body.errorMessage);\n this.body = body;\n } else if (isProblem(body)) {\n super(body.title);\n this.body = body;\n } else if (typeof body === \"string\") {\n super(body);\n this.body = body;\n } else {\n super(\"An unexpected error occurred\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any\n this.body = body as any;\n }\n\n this.status = status;\n }\n\n static async fromResponse(res: Response) {\n return new HttpError(res.status, await extractResponseBody(res));\n }\n}\n\nexport const tokenInvalidError = new Problem({\n title:\n \"The provided authentication token was rejected because it was invalid or may have expired.\",\n type: \"https://api.dremio.dev/problems/auth/token-invalid\",\n});\n\ntype ApiV1Error = {\n errorMessage: string;\n moreInfo?: string;\n};\n\nconst isApiV1Error = (body: unknown): body is ApiV1Error =>\n typeof body === \"object\" && Object.prototype.hasOwnProperty.call(body, \"errorMessage\");\n\nexport const isProblem = (body: unknown): body is Problem =>\n body != null && typeof body === \"object\" && \"type\" in body && \"title\" in body;\n\nexport const isValidationProblem = (body: unknown): body is ValidationProblem =>\n isProblem(body) && body.title === \"https://api.dremio.dev/problems/validation-problem\";\n"]}
1
+ {"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../../src/common/HttpError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,mBAAmB,GAAG,KAAK,EAAE,GAAa,EAAE,EAAE;IAClD,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAClE,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAqB,CAAC;IAChD,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,MAAM,CAAS;IACf,IAAI,CAAoD;IAEjE,YAAY,MAAc,EAAE,IAAa;QACvC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;YACjC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAClB,CAAC;aAAM,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;aAAM,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,CAAC;YACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,8BAA8B,CAAC,CAAC;YACtC,uGAAuG;YACvG,IAAI,CAAC,IAAI,GAAG,IAAW,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,GAAa;QACrC,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IACnE,CAAC;CACF;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,OAAO,CAAC;IAC3C,KAAK,EACH,4FAA4F;IAC9F,IAAI,EAAE,oDAAoD;CAC3D,CAAC,CAAC;AAOH,MAAM,YAAY,GAAG,CAAC,IAAa,EAAsB,EAAE,CACzD,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AAEzF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAa,EAAmB,EAAE,CAC1D,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,CAAC;AAEhF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAa,EAA6B,EAAE,CAC9E,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,KAAK,oDAAoD,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Problem, ValidationProblem } from \"./Problem.ts\";\nimport { RateLimitError } from \"./problems.ts\";\n\nconst extractResponseBody = async (res: Response) => {\n if (res.headers.get(\"content-type\")?.includes(\"application/json\")) {\n return (await res.json()) as Promise<unknown>;\n } else {\n return await res.text();\n }\n};\n\nexport class HttpError extends Error {\n readonly status: number;\n readonly body: ApiV1Error | Problem | ValidationProblem | string;\n\n constructor(status: number, body: unknown) {\n if (status === 429) {\n const err = new RateLimitError();\n super(err.title);\n this.body = err;\n } else if (isApiV1Error(body)) {\n super(body.errorMessage);\n this.body = body;\n } else if (isProblem(body)) {\n super(body.title);\n this.body = body;\n } else if (typeof body === \"string\") {\n super(body);\n this.body = body;\n } else {\n super(\"An unexpected error occurred\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any\n this.body = body as any;\n }\n\n this.status = status;\n }\n\n static async fromResponse(res: Response) {\n return new HttpError(res.status, await extractResponseBody(res));\n }\n}\n\nexport const tokenInvalidError = new Problem({\n title:\n \"The provided authentication token was rejected because it was invalid or may have expired.\",\n type: \"https://api.dremio.dev/problems/auth/token-invalid\",\n});\n\ntype ApiV1Error = {\n errorMessage: string;\n moreInfo?: string;\n};\n\nconst isApiV1Error = (body: unknown): body is ApiV1Error =>\n typeof body === \"object\" && Object.prototype.hasOwnProperty.call(body, \"errorMessage\");\n\nexport const isProblem = (body: unknown): body is Problem =>\n body != null && typeof body === \"object\" && \"type\" in body && \"title\" in body;\n\nexport const isValidationProblem = (body: unknown): body is ValidationProblem =>\n isProblem(body) && body.title === \"https://api.dremio.dev/problems/validation-problem\";\n"]}
@@ -9,3 +9,6 @@ export declare class UnexpectedError extends Problem<"https://api.dremio.dev/pro
9
9
  export declare class VersionConflictError extends Problem<"https://api.dremio.dev/problems/version-conflict"> {
10
10
  constructor();
11
11
  }
12
+ export declare class RateLimitError extends Problem<"https://api.dremio.dev/problems/rate-limit"> {
13
+ constructor();
14
+ }
@@ -31,4 +31,12 @@ export class VersionConflictError extends Problem {
31
31
  });
32
32
  }
33
33
  }
34
+ export class RateLimitError extends Problem {
35
+ constructor() {
36
+ super({
37
+ title: "The maximum number of requests within the current time period has been exceeded.",
38
+ type: "https://api.dremio.dev/problems/rate-limit",
39
+ });
40
+ }
41
+ }
34
42
  //# sourceMappingURL=problems.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"problems.js","sourceRoot":"","sources":["../../src/common/problems.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,OAA2D;IAC9F,YAAY,KAAa;QACvB,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,kDAAkD,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,OAA2D;IACnG;QACE,KAAK,CAAC;YACJ,KAAK,EAAE,uEAAuE;YAC9E,IAAI,EAAE,kDAAkD;SACzD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Problem } from \"./Problem.js\";\n\n/**\n * Used for generic/untyped string errors from Dremio APIs, with the\n * error text placed in the `title` property.\n */\nexport class UnexpectedError extends Problem<\"https://api.dremio.dev/problems/unexpected-error\"> {\n constructor(title: string) {\n super({ title, type: \"https://api.dremio.dev/problems/unexpected-error\" });\n }\n}\n\nexport class VersionConflictError extends Problem<\"https://api.dremio.dev/problems/version-conflict\"> {\n constructor() {\n super({\n title: \"The version of the provided resource is older than the stored version\",\n type: \"https://api.dremio.dev/problems/version-conflict\",\n });\n }\n}\n"]}
1
+ {"version":3,"file":"problems.js","sourceRoot":"","sources":["../../src/common/problems.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,OAA2D;IAC9F,YAAY,KAAa;QACvB,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,kDAAkD,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,OAA2D;IACnG;QACE,KAAK,CAAC;YACJ,KAAK,EAAE,uEAAuE;YAC9E,IAAI,EAAE,kDAAkD;SACzD,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,OAAqD;IACvF;QACE,KAAK,CAAC;YACJ,KAAK,EAAE,kFAAkF;YACzF,IAAI,EAAE,4CAA4C;SACnD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Problem } from \"./Problem.js\";\n\n/**\n * Used for generic/untyped string errors from Dremio APIs, with the\n * error text placed in the `title` property.\n */\nexport class UnexpectedError extends Problem<\"https://api.dremio.dev/problems/unexpected-error\"> {\n constructor(title: string) {\n super({ title, type: \"https://api.dremio.dev/problems/unexpected-error\" });\n }\n}\n\nexport class VersionConflictError extends Problem<\"https://api.dremio.dev/problems/version-conflict\"> {\n constructor() {\n super({\n title: \"The version of the provided resource is older than the stored version\",\n type: \"https://api.dremio.dev/problems/version-conflict\",\n });\n }\n}\n\nexport class RateLimitError extends Problem<\"https://api.dremio.dev/problems/rate-limit\"> {\n constructor() {\n super({\n title: \"The maximum number of requests within the current time period has been exceeded.\",\n type: \"https://api.dremio.dev/problems/rate-limit\",\n });\n }\n}\n"]}
@@ -8,7 +8,7 @@ export declare class CatalogTags {
8
8
  constructor(properties: CatalogTagsProperties, config: SonarV3Config);
9
9
  update(properties: {
10
10
  tags: string[];
11
- }): Promise<import("ts-results-es").Result<CatalogTags, import("../index.ts").HttpError | VersionConflictError>>;
11
+ }): Promise<import("ts-results-es").Result<CatalogTags, VersionConflictError | import("../index.ts").HttpError>>;
12
12
  }
13
13
  export declare const catalogTagsEntityToProperties: (catalogReference: CatalogReference, entity: {
14
14
  tags: string[];
@@ -8,7 +8,7 @@ export declare class CatalogWiki {
8
8
  constructor(properties: CatalogWikiProperties, config: SonarV3Config);
9
9
  update(properties: {
10
10
  text: string;
11
- }): Promise<import("ts-results-es").Result<CatalogWiki, import("../index.ts").HttpError | VersionConflictError>>;
11
+ }): Promise<import("ts-results-es").Result<CatalogWiki, VersionConflictError | import("../index.ts").HttpError>>;
12
12
  }
13
13
  export declare const catalogWikiEntityToProperties: (catalogReference: CatalogReference, entity: {
14
14
  text: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dremio/js-sdk",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "JavaScript library for the Dremio API",
5
5
  "keywords": [
6
6
  "dremio",