@introspection-sdk/introspection-browser 0.5.6 → 0.5.8
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/.turbo/turbo-build.log +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +7 -5
- package/dist/api/client.js.map +1 -1
- package/dist/api/fetch.d.ts +23 -0
- package/dist/api/fetch.d.ts.map +1 -0
- package/dist/api/fetch.js +30 -0
- package/dist/api/fetch.js.map +1 -0
- package/dist/api/http.d.ts.map +1 -1
- package/dist/api/http.js +3 -1
- package/dist/api/http.js.map +1 -1
- package/package.json +3 -3
- package/src/api/client.ts +7 -7
- package/src/api/fetch.ts +31 -0
- package/src/api/http.ts +4 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @introspection-sdk/introspection-browser@0.5.
|
|
2
|
+
> @introspection-sdk/introspection-browser@0.5.8 build /home/runner/work/introspection-js-sdk/introspection-js-sdk/packages/introspection-browser
|
|
3
3
|
> tsc
|
|
4
4
|
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AASzC,MAAM,WAAW,6BAA6B;IAC5C;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C;AAED,qBAAa,sBAAsB;IAIrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gBAEjB,IAAI,EAAE,6BAA6B;IAuBhE,6DAA6D;IAC7D,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED,6DAA6D;IAC7D,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED,4EAA4E;IAC5E,IAAI,aAAa,IAAI,mBAAmB,CAEvC;IAED,oEAAoE;IACpE,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAIhB,QAAQ;IAiBtB,0EAA0E;YAC5D,UAAU;CAQzB"}
|
package/dist/api/client.js
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
* before retrying.
|
|
25
25
|
*/
|
|
26
26
|
import { BrowserHttpClient, stripTrailingSlash, toApiError } from "./http.js";
|
|
27
|
+
import { resolveBrowserFetch } from "./fetch.js";
|
|
27
28
|
import { ConversationsClient, FilesClient, SharesClient, } from "@introspection-sdk/http";
|
|
28
29
|
import { TasksClient } from "./tasks.js";
|
|
29
30
|
export class IntrospectionApiClient {
|
|
@@ -32,17 +33,18 @@ export class IntrospectionApiClient {
|
|
|
32
33
|
cookieClients;
|
|
33
34
|
constructor(opts) {
|
|
34
35
|
this.opts = opts;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// Native browser `fetch` throws "Illegal invocation" when called as a
|
|
37
|
+
// method of this client (`this.fetchImpl(...)`); resolveBrowserFetch
|
|
38
|
+
// returns a global-safe wrapper. The same impl backs the connect()
|
|
39
|
+
// exchange here and the cookie-session resource calls via BrowserHttpClient.
|
|
40
|
+
this.fetchImpl = resolveBrowserFetch(opts.fetch);
|
|
39
41
|
if (!opts.dpUrl) {
|
|
40
42
|
throw new Error("IntrospectionApiClient requires a dpUrl");
|
|
41
43
|
}
|
|
42
44
|
const http = new BrowserHttpClient({
|
|
43
45
|
apiUrl: opts.dpUrl,
|
|
44
46
|
additionalHeaders: opts.additionalHeaders,
|
|
45
|
-
fetch:
|
|
47
|
+
fetch: this.fetchImpl,
|
|
46
48
|
onUnauthorized: () => this.reexchange(),
|
|
47
49
|
});
|
|
48
50
|
this.cookieClients = {
|
package/dist/api/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA8BzC,MAAM,OAAO,sBAAsB;IAIJ;IAHZ,SAAS,CAAe;IACxB,aAAa,CAAgB;IAE9C,YAA6B,IAAmC;QAAnC,SAAI,GAAJ,IAAI,CAA+B;QAC9D,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the `fetch` implementation for browser Data Plane calls.
|
|
3
|
+
*
|
|
4
|
+
* The native browser `fetch` brand-checks its `this`: it must be the global
|
|
5
|
+
* (`window` / `WorkerGlobalScope`). Storing `globalThis.fetch` on an instance
|
|
6
|
+
* field and later calling it as a method — `this.fetchImpl(url, init)` — rebinds
|
|
7
|
+
* `this` to the client instance, so the browser throws
|
|
8
|
+
* `Failed to execute 'fetch' on 'Window': Illegal invocation`.
|
|
9
|
+
*
|
|
10
|
+
* When no custom `fetch` is supplied we therefore return a thin wrapper that
|
|
11
|
+
* invokes `globalThis.fetch(...)` **as a method of the global** (correct `this`)
|
|
12
|
+
* and resolves it **per call**. The per-call lookup is deliberate: the only
|
|
13
|
+
* reason to go through `globalThis.fetch` rather than the lexical `fetch` is so
|
|
14
|
+
* a swapped-in implementation is honored — that is the server-side proxy
|
|
15
|
+
* (`@introspection-sdk/introspection-proxy` monkeypatches `globalThis.fetch`),
|
|
16
|
+
* never a browser concern. A caller-supplied `fetch` is returned untouched.
|
|
17
|
+
*
|
|
18
|
+
* This lives in the browser package on purpose: Node's `fetch` (undici) has no
|
|
19
|
+
* such brand check, so the shared {@link BaseHttpClient} / Node client keep
|
|
20
|
+
* resolving `globalThis.fetch` directly (so the proxy override still applies).
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveBrowserFetch(custom?: typeof fetch): typeof fetch;
|
|
23
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,GAAG,OAAO,KAAK,CASvE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the `fetch` implementation for browser Data Plane calls.
|
|
3
|
+
*
|
|
4
|
+
* The native browser `fetch` brand-checks its `this`: it must be the global
|
|
5
|
+
* (`window` / `WorkerGlobalScope`). Storing `globalThis.fetch` on an instance
|
|
6
|
+
* field and later calling it as a method — `this.fetchImpl(url, init)` — rebinds
|
|
7
|
+
* `this` to the client instance, so the browser throws
|
|
8
|
+
* `Failed to execute 'fetch' on 'Window': Illegal invocation`.
|
|
9
|
+
*
|
|
10
|
+
* When no custom `fetch` is supplied we therefore return a thin wrapper that
|
|
11
|
+
* invokes `globalThis.fetch(...)` **as a method of the global** (correct `this`)
|
|
12
|
+
* and resolves it **per call**. The per-call lookup is deliberate: the only
|
|
13
|
+
* reason to go through `globalThis.fetch` rather than the lexical `fetch` is so
|
|
14
|
+
* a swapped-in implementation is honored — that is the server-side proxy
|
|
15
|
+
* (`@introspection-sdk/introspection-proxy` monkeypatches `globalThis.fetch`),
|
|
16
|
+
* never a browser concern. A caller-supplied `fetch` is returned untouched.
|
|
17
|
+
*
|
|
18
|
+
* This lives in the browser package on purpose: Node's `fetch` (undici) has no
|
|
19
|
+
* such brand check, so the shared {@link BaseHttpClient} / Node client keep
|
|
20
|
+
* resolving `globalThis.fetch` directly (so the proxy override still applies).
|
|
21
|
+
*/
|
|
22
|
+
export function resolveBrowserFetch(custom) {
|
|
23
|
+
if (custom)
|
|
24
|
+
return custom;
|
|
25
|
+
if (!globalThis.fetch) {
|
|
26
|
+
throw new Error("global fetch is unavailable; pass `fetch` or run in a modern browser");
|
|
27
|
+
}
|
|
28
|
+
return (input, init) => globalThis.fetch(input, init);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/api/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAqB;IACvD,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,sEAAsE,CACvE,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,KAAwB,EAAE,IAAkB,EAAE,EAAE,CACtD,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/api/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,UAAU,EACX,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,UAAU,EACX,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC;AAE1C,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,cAAc;gBACvC,GAAG,EAAE,iBAAiB;CAanC"}
|
package/dist/api/http.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* session cookie) triggers a single `onUnauthorized` refresh + retry.
|
|
12
12
|
*/
|
|
13
13
|
import { BaseHttpClient, stripTrailingSlash, toApiError, } from "@introspection-sdk/http";
|
|
14
|
+
import { resolveBrowserFetch } from "./fetch.js";
|
|
14
15
|
// Re-exported for `client.ts`, which redeems the DP session on `connect()`.
|
|
15
16
|
export { stripTrailingSlash, toApiError };
|
|
16
17
|
/**
|
|
@@ -21,8 +22,9 @@ export class BrowserHttpClient extends BaseHttpClient {
|
|
|
21
22
|
constructor(cfg) {
|
|
22
23
|
super({
|
|
23
24
|
apiUrl: cfg.apiUrl,
|
|
25
|
+
// Resolve a browser-safe `fetch` (native `fetch` brand-checks `this`).
|
|
26
|
+
fetch: resolveBrowserFetch(cfg.fetch),
|
|
24
27
|
additionalHeaders: cfg.additionalHeaders,
|
|
25
|
-
fetch: cfg.fetch,
|
|
26
28
|
transport: {
|
|
27
29
|
authHeaders: () => ({}),
|
|
28
30
|
credentials: "include",
|
package/dist/api/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,UAAU,GACX,MAAM,yBAAyB,CAAC;AAEjC,4EAA4E;AAC5E,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC;AAiB1C;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IACnD,YAAY,GAAsB;QAChC,KAAK,CAAC;YACJ,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,UAAU,GACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,4EAA4E;AAC5E,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC;AAiB1C;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IACnD,YAAY,GAAsB;QAChC,KAAK,CAAC;YACJ,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,uEAAuE;YACvE,KAAK,EAAE,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC;YACrC,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;YACxC,SAAS,EAAE;gBACT,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;gBACvB,WAAW,EAAE,SAAS;gBACtB,cAAc,EAAE,GAAG,CAAC,cAAc;aACnC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@introspection-sdk/introspection-browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Introspection observability SDK for the browser",
|
|
6
6
|
"engines": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@opentelemetry/api-logs": "^0.219.0",
|
|
32
32
|
"@opentelemetry/sdk-logs": "^0.219.0",
|
|
33
33
|
"@opentelemetry/exporter-logs-otlp-http": "^0.219.0",
|
|
34
|
-
"@introspection-sdk/
|
|
35
|
-
"@introspection-sdk/
|
|
34
|
+
"@introspection-sdk/http": "0.5.8",
|
|
35
|
+
"@introspection-sdk/types": "0.5.8"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"lint": "eslint . --max-warnings 0",
|
package/src/api/client.ts
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { BrowserHttpClient, stripTrailingSlash, toApiError } from "./http.js";
|
|
28
|
+
import { resolveBrowserFetch } from "./fetch.js";
|
|
28
29
|
import {
|
|
29
30
|
ConversationsClient,
|
|
30
31
|
FilesClient,
|
|
@@ -65,19 +66,18 @@ export class IntrospectionApiClient {
|
|
|
65
66
|
private readonly cookieClients: CookieClients;
|
|
66
67
|
|
|
67
68
|
constructor(private readonly opts: IntrospectionApiClientOptions) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
69
|
+
// Native browser `fetch` throws "Illegal invocation" when called as a
|
|
70
|
+
// method of this client (`this.fetchImpl(...)`); resolveBrowserFetch
|
|
71
|
+
// returns a global-safe wrapper. The same impl backs the connect()
|
|
72
|
+
// exchange here and the cookie-session resource calls via BrowserHttpClient.
|
|
73
|
+
this.fetchImpl = resolveBrowserFetch(opts.fetch);
|
|
74
74
|
if (!opts.dpUrl) {
|
|
75
75
|
throw new Error("IntrospectionApiClient requires a dpUrl");
|
|
76
76
|
}
|
|
77
77
|
const http = new BrowserHttpClient({
|
|
78
78
|
apiUrl: opts.dpUrl,
|
|
79
79
|
additionalHeaders: opts.additionalHeaders,
|
|
80
|
-
fetch:
|
|
80
|
+
fetch: this.fetchImpl,
|
|
81
81
|
onUnauthorized: () => this.reexchange(),
|
|
82
82
|
});
|
|
83
83
|
this.cookieClients = {
|
package/src/api/fetch.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the `fetch` implementation for browser Data Plane calls.
|
|
3
|
+
*
|
|
4
|
+
* The native browser `fetch` brand-checks its `this`: it must be the global
|
|
5
|
+
* (`window` / `WorkerGlobalScope`). Storing `globalThis.fetch` on an instance
|
|
6
|
+
* field and later calling it as a method — `this.fetchImpl(url, init)` — rebinds
|
|
7
|
+
* `this` to the client instance, so the browser throws
|
|
8
|
+
* `Failed to execute 'fetch' on 'Window': Illegal invocation`.
|
|
9
|
+
*
|
|
10
|
+
* When no custom `fetch` is supplied we therefore return a thin wrapper that
|
|
11
|
+
* invokes `globalThis.fetch(...)` **as a method of the global** (correct `this`)
|
|
12
|
+
* and resolves it **per call**. The per-call lookup is deliberate: the only
|
|
13
|
+
* reason to go through `globalThis.fetch` rather than the lexical `fetch` is so
|
|
14
|
+
* a swapped-in implementation is honored — that is the server-side proxy
|
|
15
|
+
* (`@introspection-sdk/introspection-proxy` monkeypatches `globalThis.fetch`),
|
|
16
|
+
* never a browser concern. A caller-supplied `fetch` is returned untouched.
|
|
17
|
+
*
|
|
18
|
+
* This lives in the browser package on purpose: Node's `fetch` (undici) has no
|
|
19
|
+
* such brand check, so the shared {@link BaseHttpClient} / Node client keep
|
|
20
|
+
* resolving `globalThis.fetch` directly (so the proxy override still applies).
|
|
21
|
+
*/
|
|
22
|
+
export function resolveBrowserFetch(custom?: typeof fetch): typeof fetch {
|
|
23
|
+
if (custom) return custom;
|
|
24
|
+
if (!globalThis.fetch) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"global fetch is unavailable; pass `fetch` or run in a modern browser",
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return (input: RequestInfo | URL, init?: RequestInit) =>
|
|
30
|
+
globalThis.fetch(input, init);
|
|
31
|
+
}
|
package/src/api/http.ts
CHANGED
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
toApiError,
|
|
18
18
|
} from "@introspection-sdk/http";
|
|
19
19
|
|
|
20
|
+
import { resolveBrowserFetch } from "./fetch.js";
|
|
21
|
+
|
|
20
22
|
// Re-exported for `client.ts`, which redeems the DP session on `connect()`.
|
|
21
23
|
export { stripTrailingSlash, toApiError };
|
|
22
24
|
|
|
@@ -43,8 +45,9 @@ export class BrowserHttpClient extends BaseHttpClient {
|
|
|
43
45
|
constructor(cfg: BrowserHttpConfig) {
|
|
44
46
|
super({
|
|
45
47
|
apiUrl: cfg.apiUrl,
|
|
48
|
+
// Resolve a browser-safe `fetch` (native `fetch` brand-checks `this`).
|
|
49
|
+
fetch: resolveBrowserFetch(cfg.fetch),
|
|
46
50
|
additionalHeaders: cfg.additionalHeaders,
|
|
47
|
-
fetch: cfg.fetch,
|
|
48
51
|
transport: {
|
|
49
52
|
authHeaders: () => ({}),
|
|
50
53
|
credentials: "include",
|