@tallyui/connector-vendure 3.0.0-next.1 → 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/dist/index.js +2 -2
- package/package.json +4 -4
- package/src/capabilities.ts +3 -3
- package/src/replication/products.ts +1 -0
- package/src/session-probe.ts +3 -3
- package/src/sync/products.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ async function forbiddenError(context, forbidden) {
|
|
|
31
31
|
const out = await signedOut(context);
|
|
32
32
|
if (out === true) return new ConnectorUnauthorizedError(`Vendure GraphQL error: ${forbidden[0].message}`, 401);
|
|
33
33
|
const what = forbidden.map(({ message, path }) => path?.length ? `${path.join(".")}: ${message}` : message).join("; ");
|
|
34
|
-
if (out === false) return new
|
|
34
|
+
if (out === false) return new ConnectorUnauthorizedError(`Vendure GraphQL error: FORBIDDEN: the store refused this request although the session is signed in (a permission is missing): ${what}`, 403);
|
|
35
35
|
return new Error(`Vendure GraphQL error: FORBIDDEN: ${what} (the session check failed, so this may be transient)`);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -48,7 +48,7 @@ async function readVendureCapabilities(baseUrl, headers, init = {}) {
|
|
|
48
48
|
if (res.status === 401 || res.status === 403) {
|
|
49
49
|
const out = await signedOut({ connectorId: "vendure", baseUrl, headers, signal: init.signal });
|
|
50
50
|
if (out === true) throw new ConnectorUnauthorizedError2(`Vendure refused ${CAPABILITIES_PATH}: the session is signed out`, 401);
|
|
51
|
-
if (out === false) throw new
|
|
51
|
+
if (out === false) throw new ConnectorUnauthorizedError2(`Vendure refused ${CAPABILITIES_PATH} although the session is signed in: the CreateOrder permission is missing (HTTP ${res.status})`, 403);
|
|
52
52
|
return void 0;
|
|
53
53
|
}
|
|
54
54
|
if (res.status === 404) return { orderCreate: 1 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/connector-vendure",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vendure connector for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"directory": "connectors/vendure"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@tallyui/core": "^3.0.0-next.
|
|
29
|
+
"@tallyui/core": "^3.0.0-next.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tallyui/database": "3.0.0-next.
|
|
33
|
-
"@tallyui/pos": "3.0.0-next.
|
|
32
|
+
"@tallyui/database": "3.0.0-next.2",
|
|
33
|
+
"@tallyui/pos": "3.0.0-next.2",
|
|
34
34
|
"rxdb": "17.5.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
package/src/capabilities.ts
CHANGED
|
@@ -11,8 +11,8 @@ export const CAPABILITIES_PATH = '/tally/v1/info';
|
|
|
11
11
|
* non-2xx other than 404/401/403, non-JSON 2xx or malformed `taxRounding` is unknown and gives
|
|
12
12
|
* `undefined`. The route answers a dead session and a missing
|
|
13
13
|
* `CreateOrder` permission alike with 403, so a 401/403 asks who is signed in (#279): nobody
|
|
14
|
-
* throws `ConnectorUnauthorizedError
|
|
15
|
-
* permission, and a failed check is unknown.
|
|
14
|
+
* throws `ConnectorUnauthorizedError` 401, an administrator throws `ConnectorUnauthorizedError`
|
|
15
|
+
* 403 naming the permission, and a failed check is unknown.
|
|
16
16
|
*/
|
|
17
17
|
export async function readVendureCapabilities(
|
|
18
18
|
baseUrl: string,
|
|
@@ -30,7 +30,7 @@ export async function readVendureCapabilities(
|
|
|
30
30
|
const out = await signedOut({ connectorId: 'vendure', baseUrl, headers, signal: init.signal });
|
|
31
31
|
// The probe confirms sign-out; the route's 403 also covers missing permissions.
|
|
32
32
|
if (out === true) throw new ConnectorUnauthorizedError(`Vendure refused ${CAPABILITIES_PATH}: the session is signed out`, 401);
|
|
33
|
-
if (out === false) throw new
|
|
33
|
+
if (out === false) throw new ConnectorUnauthorizedError(`Vendure refused ${CAPABILITIES_PATH} although the session is signed in: the CreateOrder permission is missing (HTTP ${res.status})`, 403);
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
36
36
|
if (res.status === 404) return { orderCreate: 1 };
|
|
@@ -81,6 +81,7 @@ export async function gql(
|
|
|
81
81
|
if (!res.ok) {
|
|
82
82
|
const body = await res.json().catch(() => undefined) as GqlBody | undefined;
|
|
83
83
|
const message = body?.errors?.[0]?.message;
|
|
84
|
+
// Vendure answers FORBIDDEN with HTTP 200; an HTTP 401/403 comes from a proxy or firewall and is taken at face value.
|
|
84
85
|
if (res.status === 401 || res.status === 403) throw new ConnectorUnauthorizedError(`Vendure API error: ${res.status}${message ? `: ${message}` : ''}`, res.status as 401 | 403);
|
|
85
86
|
throw new Error(`Vendure API error: ${res.status}${message ? `: ${message}` : ''}`);
|
|
86
87
|
}
|
package/src/session-probe.ts
CHANGED
|
@@ -26,8 +26,8 @@ export async function signedOut(context: SyncContext): Promise<boolean | undefin
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* The error for a `FORBIDDEN` answer:
|
|
30
|
-
*
|
|
29
|
+
* The error for a `FORBIDDEN` answer: a signed-out session is 401, a confirmed missing permission
|
|
30
|
+
* is 403, and a failed probe is a plain Error. Errors name everything refused in answer order (each GraphQL `path`, e.g. `product.variants`),
|
|
31
31
|
* for the store owner's log. One probe answers for the whole response.
|
|
32
32
|
*/
|
|
33
33
|
export async function forbiddenError(context: SyncContext, forbidden: Array<{ message?: string; path?: ReadonlyArray<string | number> }>): Promise<Error> {
|
|
@@ -35,6 +35,6 @@ export async function forbiddenError(context: SyncContext, forbidden: Array<{ me
|
|
|
35
35
|
// The probe confirmed a signed-out session even though Vendure answered FORBIDDEN.
|
|
36
36
|
if (out === true) return new ConnectorUnauthorizedError(`Vendure GraphQL error: ${forbidden[0].message}`, 401);
|
|
37
37
|
const what = forbidden.map(({ message, path }) => (path?.length ? `${path.join('.')}: ${message}` : message)).join('; ');
|
|
38
|
-
if (out === false) return new
|
|
38
|
+
if (out === false) return new ConnectorUnauthorizedError(`Vendure GraphQL error: FORBIDDEN: the store refused this request although the session is signed in (a permission is missing): ${what}`, 403);
|
|
39
39
|
return new Error(`Vendure GraphQL error: FORBIDDEN: ${what} (the session check failed, so this may be transient)`);
|
|
40
40
|
}
|
package/src/sync/products.ts
CHANGED
|
@@ -152,6 +152,7 @@ async function gql(
|
|
|
152
152
|
signal: context.signal,
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
+
// Vendure answers FORBIDDEN with HTTP 200; an HTTP 401/403 comes from a proxy or firewall and is taken at face value.
|
|
155
156
|
if (res.status === 401 || res.status === 403) throw new ConnectorUnauthorizedError(`Vendure API error: ${res.status}`, res.status as 401 | 403);
|
|
156
157
|
if (!res.ok) throw new Error(`Vendure API error: ${res.status}`);
|
|
157
158
|
const body: { data?: any; errors?: Array<{ message?: string; path?: Array<string | number>; extensions?: { code?: string } }> } = await res.json();
|