@zachacious/protoc-gen-connect-vue 1.0.20 → 1.0.21

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
@@ -16,6 +16,17 @@ Protoc-gen-connect-vue attempts to create the full SDK - The client and API Wrap
16
16
  - **Message Initializers:** A createEmpty utility to generate default objects for any Protobuf message type.
17
17
  - **Query Key Factory:** Centralized query keys to simplify manual cache invalidation.
18
18
 
19
+ ## **Compatibility**
20
+
21
+ | Dependency | Supported versions |
22
+ | --- | --- |
23
+ | `@connectrpc/connect` / `@connectrpc/connect-web` | v1.6+ and v2 |
24
+ | `@bufbuild/protobuf` / `protoc-gen-es` codegen | v2 |
25
+ | `@tanstack/vue-query` | v5 |
26
+ | Vue | 3 |
27
+
28
+ The generated client configures credentials through a `fetch` override rather than the version-specific `credentials` transport option, so the same generated code type-checks against both connect-web v1.6+ and v2. See the [CHANGELOG](CHANGELOG.md) for the 1.0.21 upgrade notes.
29
+
19
30
  ## **Installation**
20
31
 
21
32
  ```bash
@@ -93,6 +104,22 @@ setSDKErrorCallback((err, url) => {
93
104
  });
94
105
  ```
95
106
 
107
+ ### **3. Credentials / Cookies**
108
+
109
+ The generated transport sends cookies cross-origin by default (`credentials: "include"`), applied through a `fetch` override so it works with both `@connectrpc/connect-web` v1 (>= 1.6) and v2 — v2 removed the `credentials` transport option, and the `fetch` override is the recommended replacement.
110
+
111
+ If your backend's CORS configuration doesn't allow credentials, change the mode at runtime:
112
+
113
+ ```TypeScript
114
+
115
+ import { setFetchCredentials } from '@/api/generated';
116
+
117
+ // "include" (default) | "same-origin" | "omit"
118
+ setFetchCredentials('same-origin');
119
+ ```
120
+
121
+ > **Upgrading from 1.0.20 or earlier:** previous releases passed a `fetchOptions` option that connect-web silently ignored, so credentials were never actually applied. From 1.0.21 the `"include"` default genuinely takes effect — if a cross-origin backend's CORS isn't configured for credentials, set `"same-origin"` at startup to keep the old behavior. Details in the [CHANGELOG](CHANGELOG.md).
122
+
96
123
  ## **Usage**
97
124
 
98
125
  ### **Using Hooks and Manual Wrappers**
package/dist/generator.js CHANGED
@@ -77276,7 +77276,7 @@ ${lanes.join(`
77276
77276
  if (!links2.hasReportedStatementInAmbientContext) {
77277
77277
  return links2.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
77278
77278
  }
77279
- } else {}
77279
+ }
77280
77280
  }
77281
77281
  return false;
77282
77282
  }
@@ -86926,7 +86926,7 @@ ${lanes.join(`
86926
86926
  ], 2));
86927
86927
  setParentRecursive(requireStatement, false);
86928
86928
  statements = insertStatementAfterCustomPrologue(statements.slice(), requireStatement);
86929
- } else {}
86929
+ }
86930
86930
  }
86931
86931
  }
86932
86932
  if (statements !== visited.statements) {
@@ -246201,7 +246201,7 @@ ${lanes.join(`
246201
246201
  if (!links2.hasReportedStatementInAmbientContext) {
246202
246202
  return links2.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
246203
246203
  }
246204
- } else {}
246204
+ }
246205
246205
  }
246206
246206
  return false;
246207
246207
  }
@@ -255665,7 +255665,7 @@ ${lanes.join(`
255665
255665
  ], 2));
255666
255666
  setParentRecursive(requireStatement, false);
255667
255667
  statements = insertStatementAfterCustomPrologue(statements.slice(), requireStatement);
255668
- } else {}
255668
+ }
255669
255669
  }
255670
255670
  }
255671
255671
  if (statements !== visited.statements) {
@@ -336813,6 +336813,7 @@ var KNOWN_WKT = [
336813
336813
  ];
336814
336814
  var currentDir = new URL(".", import.meta.url).pathname;
336815
336815
  var templateDir = path.join(currentDir, "..", "templates");
336816
+ var pkg = JSON.parse(fs.readFileSync(path.join(currentDir, "..", "package.json"), "utf-8"));
336816
336817
  var templates = {
336817
336818
  client: fs.readFileSync(path.join(templateDir, "client.ts.mustache"), "utf-8"),
336818
336819
  api: fs.readFileSync(path.join(templateDir, "api.ts.mustache"), "utf-8"),
@@ -336922,7 +336923,7 @@ function processService(service) {
336922
336923
  }
336923
336924
  var plugin = createEcmaScriptPlugin({
336924
336925
  name: "protoc-gen-connect-vue",
336925
- version: "v1.10.0",
336926
+ version: `v${pkg.version}`,
336926
336927
  generateTs: (schema) => {
336927
336928
  const service = schema.files.flatMap((f) => f.services)[0];
336928
336929
  if (!service)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachacious/protoc-gen-connect-vue",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Smart TanStack Query & ConnectRPC SDK generator for Vue.js",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,6 +32,23 @@ export type ErrorCallback = (error: ConnectError, url: string) => void;
32
32
  let onError: ErrorCallback = () => {};
33
33
  export const setSDKErrorCallback = (cb: ErrorCallback) => { onError = cb; };
34
34
 
35
+ // --- FETCH CREDENTIALS ---
36
+ // connect-web v1 exposed a `credentials` option on the transport; v2 removed it
37
+ // in favor of overriding `fetch`. Wrapping fetch works on both major versions.
38
+ const credentialsMode = ref<RequestCredentials>("include");
39
+
40
+ /**
41
+ * Set the fetch credentials mode ("include" | "same-origin" | "omit").
42
+ * Defaults to "include" so cookie-based auth works cross-origin.
43
+ * Takes effect on the next request; no transport rebuild required.
44
+ */
45
+ export const setFetchCredentials = (mode: RequestCredentials) => {
46
+ credentialsMode.value = mode;
47
+ };
48
+
49
+ const fetchWithCredentials: typeof globalThis.fetch = (input, init) =>
50
+ globalThis.fetch(input, { ...init, credentials: credentialsMode.value });
51
+
35
52
  const transportInterceptor: Interceptor = (next) => async (req) => {
36
53
  const token = await resolveToken();
37
54
  if (token) req.header.set("x-api-key", token);
@@ -54,7 +71,7 @@ export const useGrpcClient = () => {
54
71
  const transport = computed(() => createConnectTransport({
55
72
  baseUrl: baseUrl.value,
56
73
  interceptors: [transportInterceptor],
57
- fetchOptions: { credentials: "include" },
74
+ fetch: fetchWithCredentials,
58
75
  }));
59
76
 
60
77
  const client = computed(() => createClient({{serviceName}}, transport.value));
@@ -103,6 +120,11 @@ async function handleUpdate() {
103
120
  <p>{{ manualResult }}</p>
104
121
  </template>
105
122
 
123
+ // Cookies are sent cross-origin by default (credentials: "include").
124
+ // If your backend's CORS config doesn't allow credentials, opt out with:
125
+ // import { setFetchCredentials } from '@/api';
126
+ // setFetchCredentials("same-origin");
127
+
106
128
  // use this to set the error interceptor - for instance to log to sentry or something
107
129
  import { setAuthResolver, setSDKErrorCallback } from '@/api';
108
130
  import { useAuthStore } from '@/stores/auth';