@work-shape/catalyst-api-client 0.8.0-rc.4 → 0.8.0-rc.5

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ApiErrorCode, Operation, OperationPathParamName, OperationRequestHeader, apiOperations, ApiOperationName } from '@work-shape/catalyst-api-contract';
2
+ import { ApiErrorCode, LocaleCode, Operation, OperationPathParamName, OperationRequestHeader, apiOperations, ApiOperationName } from '@work-shape/catalyst-api-contract';
3
3
  export * from '@work-shape/catalyst-api-contract';
4
4
 
5
5
  /**
@@ -22,6 +22,8 @@ declare const authSessionSchema: z.ZodNullable<z.ZodObject<{
22
22
  type AuthSession = NonNullable<z.infer<typeof authSessionSchema>>;
23
23
  interface AuthResult {
24
24
  ok: boolean;
25
+ /** The sign-in library's code for a refusal, such as `INVALID_EMAIL_OR_PASSWORD`. */
26
+ code?: string;
25
27
  message?: string;
26
28
  }
27
29
  declare function getAuthSession(apiBaseUrl: string): Promise<AuthSession | null>;
@@ -82,6 +84,13 @@ interface ApiClientOptions {
82
84
  */
83
85
  getToken?: () => string | undefined | Promise<string | undefined>;
84
86
  fetchImpl?: typeof fetch;
87
+ /** Cancels this client's requests when its owning session ends. */
88
+ signal?: AbortSignal;
89
+ /**
90
+ * The language every request asks the server to answer in, read at each request. A browser's
91
+ * own Accept-Language names its settings, not the language a person chose in the interface.
92
+ */
93
+ locale?: LocaleCode;
85
94
  /** Only available without a token source; browser navigation cannot send a bearer token. */
86
95
  browserManagedDownloads?: boolean;
87
96
  /**
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var authSessionSchema = z.object({
6
6
  user: z.object({ id: z.string(), email: z.string(), name: z.string() })
7
7
  }).nullable();
8
8
  var authFailureSchema = z.object({
9
+ code: z.string().optional(),
9
10
  message: z.string().optional(),
10
11
  error: z.object({ message: z.string().optional() }).optional()
11
12
  });
@@ -37,6 +38,7 @@ async function signInWithEmail(input) {
37
38
  const failure = authFailureSchema.safeParse(await response.json().catch(() => void 0));
38
39
  return {
39
40
  ok: false,
41
+ ...failure.data?.code === void 0 ? {} : { code: failure.data.code },
40
42
  message: failure.data?.message ?? failure.data?.error?.message ?? "Sign in failed"
41
43
  };
42
44
  }
@@ -180,7 +182,9 @@ function readEventData(block) {
180
182
  }
181
183
 
182
184
  // src/transport.ts
183
- import { isUnknownOperationResponse } from "@work-shape/catalyst-api-contract";
185
+ import {
186
+ isUnknownOperationResponse
187
+ } from "@work-shape/catalyst-api-contract";
184
188
  function createApiTransport(options) {
185
189
  const baseUrl = options.baseUrl.replace(/\/$/u, "");
186
190
  const cookieMode = options.getToken === void 0;
@@ -213,9 +217,16 @@ function createApiTransport(options) {
213
217
  headers.set("catalyst-unattended", "1");
214
218
  }
215
219
  const token = await options.getToken?.();
220
+ const sessionSignal = options.signal;
221
+ const signal = sessionSignal && request.signal ? AbortSignal.any([sessionSignal, request.signal]) : sessionSignal ?? request.signal;
216
222
  if (token) {
217
223
  headers.set("authorization", `Bearer ${token}`);
218
224
  }
225
+ const locale = options.locale;
226
+ if (locale !== void 0) {
227
+ headers.set("accept-language", locale);
228
+ }
229
+ signal?.throwIfAborted();
219
230
  let response;
220
231
  try {
221
232
  response = await (options.fetchImpl ?? fetch)(url, {
@@ -223,10 +234,10 @@ function createApiTransport(options) {
223
234
  headers,
224
235
  body,
225
236
  credentials: cookieMode ? "include" : "omit",
226
- signal: request.signal
237
+ signal
227
238
  });
228
239
  } catch (error) {
229
- throw request.signal?.aborted ? error : transportError(error);
240
+ throw signal?.aborted ? error : transportError(error);
230
241
  }
231
242
  if (response.ok) {
232
243
  return response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@work-shape/catalyst-api-client",
3
- "version": "0.8.0-rc.4",
3
+ "version": "0.8.0-rc.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "zod": "4.4.3",
32
- "@work-shape/catalyst-api-contract": "0.8.0-rc.4"
32
+ "@work-shape/catalyst-api-contract": "0.8.0-rc.5"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^24.13.1",