@cesar-richard/git-connector-sdk 1.48.5 → 1.49.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/README.md CHANGED
@@ -58,6 +58,21 @@ curl -X POST https://git-connector.example.com/admin/api-keys \
58
58
  # → { "token": "gck_…", "id": 12, "name": "my-integration", "createdAt": "…" }
59
59
  ```
60
60
 
61
+ ### Cookie auth (same-origin web UIs)
62
+
63
+ When the server has `WEB_UI_COOKIE_AUTH=1` and you're calling from the same origin as the git-connector deployment (e.g. its own SPA), you can omit `token` entirely — the server accepts the `gck_session` httpOnly cookie set on first proxy-authenticated request:
64
+
65
+ ```ts
66
+ const client = createGitConnectorClient({
67
+ baseUrl: window.location.origin,
68
+ // Custom fetch so the browser attaches the gck_session cookie.
69
+ fetch: (input, init) =>
70
+ globalThis.fetch(input, { ...init, credentials: "include" }),
71
+ });
72
+ ```
73
+
74
+ External SDK consumers (cross-origin scripts, CI integrations) should keep passing a Bearer `token`.
75
+
61
76
  Tokens with the `gck_` prefix are immutable once minted; revoke and reissue via the same endpoint.
62
77
 
63
78
  ---
package/dist/index.d.ts CHANGED
@@ -3,8 +3,14 @@ export type { paths, components } from "./schema";
3
3
  export interface GitConnectorClientOptions {
4
4
  /** Base URL of the git-connector server, e.g. `https://git-connector.example.com`. */
5
5
  baseUrl: string;
6
- /** API token issued via `POST /admin/api-keys` (format: `gck_*`). */
7
- token: string;
6
+ /**
7
+ * API token issued via `POST /admin/api-keys` (format: `gck_*`).
8
+ * Optional: when omitted, the client does NOT set an `Authorization`
9
+ * header — useful for same-origin web UIs that authenticate via the
10
+ * `gck_session` httpOnly cookie (CR-541). External SDK consumers SHOULD
11
+ * still pass a token.
12
+ */
13
+ token?: string;
8
14
  /** Optional custom fetch implementation (default: `globalThis.fetch`). */
9
15
  fetch?: typeof fetch;
10
16
  }
package/dist/index.js CHANGED
@@ -6,19 +6,18 @@ export function createGitConnectorClient(opts) {
6
6
  // Trim whitespace + strip an accidental "Bearer " prefix that users sometimes
7
7
  // paste in along with the token value.
8
8
  const token = opts.token?.trim().replace(/^Bearer\s+/i, "") ?? "";
9
- if (!token) {
10
- throw new Error("createGitConnectorClient: token is required (mint via POST /admin/api-keys)");
11
- }
12
9
  const client = createClient({
13
10
  baseUrl: opts.baseUrl.replace(/\/$/, ""),
14
11
  fetch: opts.fetch,
15
12
  });
16
- const auth = {
17
- onRequest({ request }) {
18
- request.headers.set("Authorization", `Bearer ${token}`);
19
- return request;
20
- },
21
- };
22
- client.use(auth);
13
+ if (token) {
14
+ const auth = {
15
+ onRequest({ request }) {
16
+ request.headers.set("Authorization", `Bearer ${token}`);
17
+ return request;
18
+ },
19
+ };
20
+ client.use(auth);
21
+ }
23
22
  return client;
24
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cesar-richard/git-connector-sdk",
3
- "version": "1.48.5",
3
+ "version": "1.49.0",
4
4
  "description": "TypeScript SDK for the git-connector v1 API (work items + iterations aggregated from GitHub/GitLab). Version published on npm tracks server releases.",
5
5
  "license": "MIT",
6
6
  "repository": {