@adsk-platform/httpclient 0.1.0 → 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessTokenProvider.d.ts","sourceRoot":"","sources":["../src/accessTokenProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,oBAAoB,EAAE,qBAAqB,EAAsB,MAAM,+BAA+B,CAAC;AACvI,qBAAa,mBAAoB,YAAW,oBAAoB;IAChD,OAAO,CAAC,cAAc;gBAAd,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC;IACnD,qBAAqB,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAGrH,wBAAwB,IAAI,qBAAqB;CAIpD"}
@@ -0,0 +1,13 @@
1
+ export class AccessTokenProvider {
2
+ getAccessToken;
3
+ constructor(getAccessToken) {
4
+ this.getAccessToken = getAccessToken;
5
+ }
6
+ async getAuthorizationToken(url, additionalAuthenticationContext) {
7
+ return await this.getAccessToken();
8
+ }
9
+ getAllowedHostsValidator() {
10
+ throw new Error('Method not implemented.');
11
+ }
12
+ }
13
+ //# sourceMappingURL=accessTokenProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessTokenProvider.js","sourceRoot":"","sources":["../src/accessTokenProvider.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,mBAAmB;IACR;IAApB,YAAoB,cAAqC;QAArC,mBAAc,GAAd,cAAc,CAAuB;IAAI,CAAC;IAC9D,KAAK,CAAC,qBAAqB,CAAC,GAAY,EAAE,+BAAyD;QAC/F,OAAO,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IACvC,CAAC;IACD,wBAAwB;QACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CAEJ"}
@@ -2,5 +2,6 @@ import { HttpClient, FetchRequestAdapter } from '@microsoft/kiota-http-fetchlibr
2
2
  export declare class HttpClientFactory {
3
3
  static create(customFetch?: (request: string, init: RequestInit) => Promise<Response>): HttpClient;
4
4
  static createFetchRequestAdapter(getAccessToken: () => Promise<string>, httpClient: HttpClient): FetchRequestAdapter;
5
+ private test;
5
6
  }
6
7
  //# sourceMappingURL=httpClientFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpClientFactory.d.ts","sourceRoot":"","sources":["../src/httpClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAIxG,qBAAa,iBAAiB;IAC1B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,UAAU;IAOlG,MAAM,CAAC,yBAAyB,CAAC,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,UAAU,GAAG,mBAAmB;IASpH,OAAO,CAAC,IAAI;CAGf"}
@@ -0,0 +1,18 @@
1
+ import { HttpClient, MiddlewareFactory, FetchRequestAdapter } from '@microsoft/kiota-http-fetchlibrary';
2
+ import { BaseBearerTokenAuthenticationProvider } from '@microsoft/kiota-abstractions';
3
+ import { ErrorHandler } from './middleware/errorHandler.js';
4
+ import { AccessTokenProvider } from './accessTokenProvider.js';
5
+ export class HttpClientFactory {
6
+ static create(customFetch) {
7
+ const middlewares = [new ErrorHandler(), ...MiddlewareFactory.getDefaultMiddlewares(customFetch)];
8
+ return new HttpClient(customFetch, ...middlewares);
9
+ }
10
+ static createFetchRequestAdapter(getAccessToken, httpClient) {
11
+ const auth = new BaseBearerTokenAuthenticationProvider(new AccessTokenProvider(getAccessToken));
12
+ return new FetchRequestAdapter(auth, undefined, undefined, httpClient);
13
+ }
14
+ test() {
15
+ console.log('test');
16
+ }
17
+ }
18
+ //# sourceMappingURL=httpClientFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpClientFactory.js","sourceRoot":"","sources":["../src/httpClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,qCAAqC,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,MAAM,OAAO,iBAAiB;IAC1B,MAAM,CAAC,MAAM,CAAC,WAAuE;QAEjF,MAAM,WAAW,GAAG,CAAC,IAAI,YAAY,EAAE,EAAE,GAAG,iBAAiB,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC,CAAC;QAElG,OAAO,IAAI,UAAU,CAAC,WAAW,EAAE,GAAG,WAAW,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,CAAC,yBAAyB,CAAC,cAAqC,EAAE,UAAsB;QAC1F,MAAM,IAAI,GAAG,IAAI,qCAAqC,CAAC,IAAI,mBAAmB,CAAC,cAAc,CAAC,CAAC,CAAC;QAEhG,OAAO,IAAI,mBAAmB,CAC1B,IAAI,EACJ,SAAS,EACT,SAAS,EACT,UAAU,CAAC,CAAC;IACpB,CAAC;IACO,IAAI;QACR,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;CACJ"}
@@ -1,6 +1,9 @@
1
- import { RequestOption } from '@microsoft/kiota-abstractions';
2
- import { Middleware } from '@microsoft/kiota-http-fetchlibrary';
3
- import { ErrorHandlerOptions } from './options/errorHandlerOptions.js';
1
+ /**
2
+ * @module ErrorHandler
3
+ */
4
+ import { type RequestOption } from "@microsoft/kiota-abstractions";
5
+ import { type Middleware } from "@microsoft/kiota-http-fetchlibrary";
6
+ import { ErrorHandlerOptions } from "./options/errorHandlerOptions.js";
4
7
  /**
5
8
  * Middleware
6
9
  * Class for ErrorHandler
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAsC,KAAK,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACzG,OAAO,EAAyB,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAE9F;;;GAGG;AACH,qBAAa,YAAa,YAAW,UAAU;IAcxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZ3C;;;OAGG;IACH,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAE7B;;;;;OAKG;gBACiC,OAAO,GAAE,mBAA+C;IAE5F;;;;;;OAMG;IACU,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqC9H,OAAO,CAAC,mBAAmB;CAG9B;AACD,qBAAa,gBAAiB,SAAQ,KAAK;IAEH,UAAU,CAAC,EAAE,MAAM;gBAA3C,OAAO,EAAE,MAAM,EAAS,UAAU,CAAC,EAAE,MAAM,YAAA,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAE;CAU/H"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @module ErrorHandler
3
+ */
4
+ import { trace } from "@opentelemetry/api";
5
+ import { getObservabilityOptionsFromRequest } from "@microsoft/kiota-http-fetchlibrary";
6
+ import { ErrorHandlerOptionKey, ErrorHandlerOptions } from "./options/errorHandlerOptions.js";
7
+ /**
8
+ * Middleware
9
+ * Class for ErrorHandler
10
+ */
11
+ export class ErrorHandler {
12
+ options;
13
+ /**
14
+ *
15
+ * The next middleware in the middleware chain
16
+ */
17
+ next;
18
+ /**
19
+ *
20
+ * To create an instance of ErrorHandler
21
+ * @param [options] - The error handler options value
22
+ * @returns An instance of ErrorHandler
23
+ */
24
+ constructor(options = new ErrorHandlerOptions()) {
25
+ this.options = options;
26
+ }
27
+ /**
28
+ * To execute the current middleware
29
+ * @param url - The request url
30
+ * @param requestInit - The request options
31
+ * @param requestOptions - The request options
32
+ * @returns A Promise that resolves to nothing
33
+ */
34
+ async execute(url, requestInit, requestOptions) {
35
+ const response = await this.next?.execute(url, requestInit, requestOptions);
36
+ if (!response) {
37
+ throw new Error("Response is undefined");
38
+ }
39
+ let currentOptions = this.options;
40
+ if (requestOptions?.[ErrorHandlerOptionKey]) {
41
+ currentOptions = requestOptions[ErrorHandlerOptionKey];
42
+ }
43
+ if (currentOptions.enabled === false || this.isSuccessStatusCode(response)) {
44
+ return response;
45
+ }
46
+ const obsOptions = getObservabilityOptionsFromRequest(requestOptions);
47
+ if (obsOptions) {
48
+ trace.getTracer(obsOptions.getTracerInstrumentationName()).startActiveSpan("retryHandler - execute", (span) => {
49
+ span.setAttribute("com.microsoft.kiota.handler.error.enable", true);
50
+ span.setAttribute("http.response.status_code", response.status);
51
+ span.setAttribute("http.response.status_text", response.statusText);
52
+ span.setAttribute("http.response.url", response.url);
53
+ span.end();
54
+ });
55
+ }
56
+ // Throw error, to avoid default handling of non-success status codes
57
+ // in the kiota core (which is to return the response as is).
58
+ // This allows the consumers to handle errors via try/catch.
59
+ const err = new HttpRequestError(`Request to ${url} failed with status code ${response.status}`, response.status, { url, request: requestInit, response });
60
+ throw err;
61
+ }
62
+ isSuccessStatusCode(response) {
63
+ return response.status >= 200 && response.status < 300;
64
+ }
65
+ }
66
+ export class HttpRequestError extends Error {
67
+ statusCode;
68
+ constructor(message, statusCode, context) {
69
+ super(message);
70
+ this.statusCode = statusCode;
71
+ this.name = 'HttpRequestError';
72
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
73
+ if (Error.captureStackTrace) {
74
+ Error.captureStackTrace(this, HttpRequestError);
75
+ }
76
+ }
77
+ }
78
+ //# sourceMappingURL=errorHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,kCAAkC,EAAmB,MAAM,oCAAoC,CAAC;AACzG,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAE9F;;;GAGG;AACH,MAAM,OAAO,YAAY;IAce;IAZpC;;;OAGG;IACH,IAAI,CAAyB;IAE7B;;;;;OAKG;IACH,YAAoC,UAA+B,IAAI,mBAAmB,EAAE;QAAxD,YAAO,GAAP,OAAO,CAAiD;IAAI,CAAC;IAEjG;;;;;;OAMG;IACI,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,WAAwB,EAAE,cAA8C;QACtG,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE,WAA0B,EAAE,cAAc,CAAC,CAAC;QAC3F,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC7C,CAAC;QAED,IAAI,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,IAAI,cAAc,EAAE,CAAC,qBAAqB,CAAC,EAAE,CAAC;YAC1C,cAAc,GAAG,cAAc,CAAC,qBAAqB,CAAwB,CAAC;QAClF,CAAC;QAED,IAAI,cAAc,CAAC,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzE,OAAO,QAAQ,CAAC;QACpB,CAAC;QAED,MAAM,UAAU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K,CAAC,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;QACpD,CAAC;IACL,CAAC;CACJ"}
@@ -1,4 +1,4 @@
1
- import { RequestOption } from '@microsoft/kiota-abstractions';
1
+ import { type RequestOption } from "@microsoft/kiota-abstractions";
2
2
  export declare const ErrorHandlerOptionKey = "ErrorHandlerOptionKey";
3
3
  export declare class ErrorHandlerOptions implements RequestOption {
4
4
  enabled: boolean;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHandlerOptions.d.ts","sourceRoot":"","sources":["../../../src/middleware/options/errorHandlerOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAC7D,qBAAa,mBAAoB,YAAW,aAAa;IAClC,OAAO,EAAE,OAAO;gBAAhB,OAAO,GAAE,OAAc;IAE1C,MAAM,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,11 @@
1
+ export const ErrorHandlerOptionKey = "ErrorHandlerOptionKey";
2
+ export class ErrorHandlerOptions {
3
+ enabled;
4
+ constructor(enabled = true) {
5
+ this.enabled = enabled;
6
+ }
7
+ getKey() {
8
+ return ErrorHandlerOptionKey;
9
+ }
10
+ }
11
+ //# sourceMappingURL=errorHandlerOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHandlerOptions.js","sourceRoot":"","sources":["../../../src/middleware/options/errorHandlerOptions.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAC7D,MAAM,OAAO,mBAAmB;IACT;IAAnB,YAAmB,UAAmB,IAAI;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAI,CAAC;IAE/C,MAAM;QACF,OAAO,qBAAqB,CAAC;IACjC,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adsk-platform/httpclient",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "author": "duszykf",
6
6
  "description": "Resilient HttpClient serving the Adsk Toolkit SDKs",
7
7
  "engines": {
@@ -9,17 +9,14 @@
9
9
  },
10
10
  "license": "MIT",
11
11
  "scripts": {
12
- "build": "tsc --noEmit && vite build",
12
+ "build": "rimraf ./_dist && tsc -p tsconfig.build.json",
13
13
  "prepublishOnly": "bun run build",
14
+ "publish": "bun publish --production",
14
15
  "test": "bun test"
15
16
  },
16
17
  "type": "module",
17
18
  "exports": {
18
- ".": {
19
- "types": "./src/index.ts",
20
- "import": "./_dist/index.es.js",
21
- "default": "./_dist/index.umd.js"
22
- }
19
+ "./*": "./_dist/*"
23
20
  },
24
21
  "files": [
25
22
  "_dist"
@@ -28,6 +25,8 @@
28
25
  "@microsoft/kiota-bundle": "^1.0.0-preview.98"
29
26
  },
30
27
  "devDependencies": {
31
- "bun-fetch-mock": "1.0.0"
28
+ "bun-fetch-mock": "1.0.0",
29
+ "rimraf": "^6.0.1",
30
+ "typescript": "^5.9.2"
32
31
  }
33
32
  }