@tallyui/connector-medusa 3.0.0-next.0 → 3.0.0-next.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.
package/README.md CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  ## Errors
4
4
 
5
- Requests with expired or rejected credentials reject with `ConnectorUnauthorizedError` (`code: 'unauthorized'`), defined in `@tallyui/core` and re-exported by this connector. The app should sign in again.
5
+ Requests with expired or rejected credentials reject with `ConnectorUnauthorizedError`, defined in `@tallyui/core` and re-exported by this connector. `error.status` is `401` (`code: 'unauthorized'`, sign in again) or `403` (`code: 'forbidden'`, signed in but not allowed: the pull retries on the store schedule; don't sign out).
6
6
 
7
7
  Sign-in itself rejects with `SignInError`.
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ async function readCapabilities(baseUrl, headers, init = {}) {
19
19
  try {
20
20
  body = await res.json();
21
21
  } catch {
22
- return { orderCreate: 1 };
22
+ return void 0;
23
23
  }
24
24
  return parseInfoCapabilities(body, (reason) => console.warn(`@tallyui/connector-medusa: ${reason}`));
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/connector-medusa",
3
- "version": "3.0.0-next.0",
3
+ "version": "3.0.0-next.2",
4
4
  "type": "module",
5
5
  "description": "MedusaJS v2 connector for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -27,10 +27,10 @@
27
27
  "directory": "connectors/medusa"
28
28
  },
29
29
  "peerDependencies": {
30
- "@tallyui/core": "^3.0.0-next.0"
30
+ "@tallyui/core": "^3.0.0-next.2"
31
31
  },
32
32
  "devDependencies": {
33
- "@tallyui/database": "3.0.0-next.0",
33
+ "@tallyui/database": "3.0.0-next.2",
34
34
  "rxdb": "17.5.0"
35
35
  },
36
36
  "scripts": {
@@ -5,10 +5,9 @@ export const CAPABILITIES_PATH = '/tally/v1/info';
5
5
 
6
6
  /**
7
7
  * Reads the store's contract capabilities (ADR-062) and `taxRounding` (#287), with the
8
- * connector's usual injectable `fetch`. A 2xx gives `parseInfoCapabilities`; a 2xx with the field missing/malformed, a non-JSON body, or a 404
9
- * both mean an old plugin and give `{ orderCreate: 1 }`. A network failure,
10
- * a 5xx or any other non-2xx that isn't 404/401 is unknown and gives
11
- * `undefined`, never 1. A 401 means rejected/expired credentials and throws.
8
+ * connector's usual injectable `fetch`. A 404 means an old plugin and gives the default;
9
+ * a network failure, non-2xx other than 404/401, non-JSON 2xx or malformed `taxRounding`
10
+ * is unknown and gives `undefined`. A 401 means rejected/expired credentials and throws.
12
11
  */
13
12
  export async function readCapabilities(
14
13
  baseUrl: string,
@@ -29,7 +28,7 @@ export async function readCapabilities(
29
28
  try {
30
29
  body = await res.json();
31
30
  } catch {
32
- return { orderCreate: 1 };
31
+ return undefined;
33
32
  }
34
33
  return parseInfoCapabilities(body, (reason) => console.warn(`@tallyui/connector-medusa: ${reason}`));
35
34
  }
package/src/customers.ts CHANGED
@@ -30,7 +30,7 @@ async function customerRequest(url: string, key: 'customers' | 'customer', init:
30
30
  } catch (error) {
31
31
  throw new CustomerServiceError('network', errorMessage(error));
32
32
  }
33
- if (res.status === 401 || res.status === 403) throw new ConnectorUnauthorizedError(`Medusa rejected the credentials (HTTP ${res.status})`, res.status);
33
+ if (res.status === 401 || res.status === 403) throw new ConnectorUnauthorizedError(`Medusa rejected the credentials (HTTP ${res.status})`, res.status as 401 | 403);
34
34
  if (res.status === 404 && key === 'customer' && init.method === 'GET') return null;
35
35
  if (!res.ok && res.status !== 400) throw new CustomerServiceError('server', `HTTP ${res.status}`);
36
36
  let body;
@@ -20,7 +20,7 @@ async function get(path: string, context: SyncContext) {
20
20
  });
21
21
  if (!response.ok) {
22
22
  const error = await response.json().catch(() => ({}));
23
- if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status);
23
+ if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status as 401 | 403);
24
24
  throw new Error(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`);
25
25
  }
26
26
  return response.json();
@@ -17,7 +17,7 @@ async function get(path: string, context: SyncContext) {
17
17
  });
18
18
  if (!response.ok) {
19
19
  const error = await response.json().catch(() => ({}));
20
- if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status);
20
+ if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status as 401 | 403);
21
21
  throw new Error(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`);
22
22
  }
23
23
  return response.json();
@@ -30,7 +30,7 @@ export const medusaStockReconcile: StockReconcileAdapter = {
30
30
  });
31
31
  if (!response.ok) {
32
32
  const error = await response.json().catch(() => ({}));
33
- if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status);
33
+ if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status as 401 | 403);
34
34
  throw new Error(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`);
35
35
  }
36
36
  const data = await response.json() as { inventory_items: Array<{ id: string; location_levels?: Level[] }>; count: number };
@@ -70,7 +70,7 @@ export const medusaProductReplication: ReplicationAdapter<any, MedusaProductChec
70
70
  );
71
71
  if (!markResponse.ok) {
72
72
  const error = await markResponse.json().catch(() => ({}));
73
- if (markResponse.status === 401 || markResponse.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${markResponse.status}${error?.message ? `: ${error.message}` : ''}`, markResponse.status);
73
+ if (markResponse.status === 401 || markResponse.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${markResponse.status}${error?.message ? `: ${error.message}` : ''}`, markResponse.status as 401 | 403);
74
74
  throw new Error(`Medusa API error: ${markResponse.status}${error?.message ? `: ${error.message}` : ''}`);
75
75
  }
76
76
  const markData = await markResponse.json();
@@ -107,7 +107,7 @@ export const medusaProductReplication: ReplicationAdapter<any, MedusaProductChec
107
107
 
108
108
  if (!response.ok) {
109
109
  const error = await response.json().catch(() => ({}));
110
- if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status);
110
+ if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status as 401 | 403);
111
111
  throw new Error(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`);
112
112
  }
113
113
 
@@ -17,7 +17,7 @@ async function get(path: string, context: SyncContext) {
17
17
  });
18
18
  if (!response.ok) {
19
19
  const error = await response.json().catch(() => ({}));
20
- if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status);
20
+ if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`, response.status as 401 | 403);
21
21
  throw new Error(`Medusa API error: ${response.status}${error?.message ? `: ${error.message}` : ''}`);
22
22
  }
23
23
  return response.json();
@@ -18,7 +18,7 @@ async function get(context: SyncContext, path: string): Promise<any> {
18
18
  });
19
19
  if (!response.ok) {
20
20
  const body = await response.json().catch(() => ({}));
21
- if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa store settings request failed (HTTP ${response.status})${body?.message ? `: ${body.message}` : ''}`, response.status);
21
+ if (response.status === 401 || response.status === 403) throw new ConnectorUnauthorizedError(`Medusa store settings request failed (HTTP ${response.status})${body?.message ? `: ${body.message}` : ''}`, response.status as 401 | 403);
22
22
  throw new StoreSettingsError('failed', `Medusa store settings request failed (HTTP ${response.status})${body?.message ? `: ${body.message}` : ''}`);
23
23
  }
24
24
  return response.json();