@tallyui/connector-vendure 3.1.1 → 3.2.1

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
@@ -6,6 +6,14 @@ Requests with expired or rejected credentials reject with `ConnectorUnauthorized
6
6
 
7
7
  Sign-in itself rejects with `SignInError`.
8
8
 
9
+ ## Signing in
10
+
11
+ Vendure supports two credential kinds: email and password (`kind: 'password'`), which `signIn` exchanges for a bearer session `token`, and a device key (`kind: 'api-key'`, stored as `api_key`), a Vendure API key available in Vendure 3.6+.
12
+
13
+ Render `vendureAuth.fieldSets.password` or `vendureAuth.fieldSets['api-key']` (also exported as `vendureAuthFieldSets`) and store `kind` with the credentials. `vendureAuth.fields` remains the email and password form. Each kind sends only its chosen credential; when `kind` is absent, `api_key` wins over a session token as before.
14
+
15
+ `capabilities()` works with a device key and no sign-in. Signing out a device-key till forgets the key on the device; it does not revoke the key on the server. The store owner revokes the key in Vendure.
16
+
9
17
  ## Customers
10
18
 
11
19
  `searchCustomers`, `createCustomer` and `getCustomer` are online only and run in the session's channel, selected by the `vendure-token` header.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,23 @@
1
- import { ConnectorAuth, ProductTraits, CollectionSync, ReplicationAdapter, StockReconcileAdapter, SyncContext, StoreSettingsChoice, StoreSettings, CustomerInput, Customer, TallyConnector } from '@tallyui/core';
1
+ import { ConnectorAuth, AuthField, ProductTraits, CollectionSync, ReplicationAdapter, StockReconcileAdapter, SyncContext, StoreSettingsChoice, StoreSettings, CustomerInput, Customer, TallyConnector } from '@tallyui/core';
2
2
  export { ConnectorUnauthorizedError } from '@tallyui/core';
3
3
  import { RxJsonSchema } from 'rxdb';
4
4
 
5
5
  declare const vendureSignIn: NonNullable<ConnectorAuth['signIn']>;
6
- declare const vendureAuth: ConnectorAuth;
6
+ type VendureCredentialKind = 'password' | 'api-key';
7
+ /** What a Vendure till stores: `kind` says which credential it chose (absent on credentials saved before 3.2.0). */
8
+ interface VendureCredentials {
9
+ kind?: VendureCredentialKind;
10
+ url: string;
11
+ email?: string;
12
+ password?: string;
13
+ token?: string;
14
+ api_key?: string;
15
+ channel_token?: string;
16
+ }
17
+ declare const vendureAuthFieldSets: Record<VendureCredentialKind, AuthField[]>;
18
+ declare const vendureAuth: ConnectorAuth & {
19
+ fieldSets: Record<VendureCredentialKind, AuthField[]>;
20
+ };
7
21
 
8
22
  /**
9
23
  * RxDB schema for Vendure products.
@@ -151,4 +165,4 @@ declare const createVendureConnector: (options?: {
151
165
  */
152
166
  declare const vendureConnector: TallyConnector;
153
167
 
154
- export { VendureTimezoneConfigError, createVendureConnector, createVendureCustomer, createVendureProductReplication, createVendureVariantFeedReplication, getVendureCustomer, searchVendureCustomers, toVendureCustomer, vendureAuth, vendureConnector, vendureGlobalStockSettings, vendureProductReplication, vendureProductSchema, vendureProductSync, vendureProductTraits, vendureSignIn, vendureStockReconcile, vendureStoreSettings };
168
+ export { type VendureCredentialKind, type VendureCredentials, VendureTimezoneConfigError, createVendureConnector, createVendureCustomer, createVendureProductReplication, createVendureVariantFeedReplication, getVendureCustomer, searchVendureCustomers, toVendureCustomer, vendureAuth, vendureAuthFieldSets, vendureConnector, vendureGlobalStockSettings, vendureProductReplication, vendureProductSchema, vendureProductSync, vendureProductTraits, vendureSignIn, vendureStockReconcile, vendureStoreSettings };
package/dist/index.js CHANGED
@@ -106,24 +106,34 @@ var vendureSignIn = async (baseUrl, { email, password }, init = {}) => {
106
106
  return { token, expiresAt: void 0, capabilities };
107
107
  };
108
108
  var warnedAuthToken = false;
109
- var vendureAuth = {
110
- type: "Vendure Admin API",
111
- fields: [
109
+ var vendureAuthFieldSets = {
110
+ password: [
112
111
  { key: "url", label: "Backend URL", type: "url", placeholder: "https://my-vendure-server.com", required: true },
113
112
  { key: "email", label: "Email", type: "text", required: true },
114
113
  { key: "password", label: "Password", type: "password", required: true },
115
114
  { key: "channel_token", label: "Channel token (optional)", type: "text" }
116
115
  ],
117
- // An API key (Vendure 3.6+) wins over a signed-in session token; channel_token selects a non-default channel.
116
+ "api-key": [
117
+ { key: "url", label: "Backend URL", type: "url", placeholder: "https://my-vendure-server.com", required: true },
118
+ { key: "api_key", label: "Device key", type: "password", required: true },
119
+ { key: "channel_token", label: "Channel token (optional)", type: "text" }
120
+ ]
121
+ };
122
+ var vendureAuth = {
123
+ type: "Vendure Admin API",
124
+ fields: vendureAuthFieldSets.password,
125
+ fieldSets: vendureAuthFieldSets,
126
+ // Without kind, an API key (Vendure 3.6+) wins over a session token; channel_token selects a non-default channel.
118
127
  // auth_token is the deprecated name for token, kept so existing apps keep working.
119
128
  getHeaders: (credentials) => {
120
129
  if (credentials.token === void 0 && credentials.auth_token !== void 0 && !warnedAuthToken) {
121
130
  warnedAuthToken = true;
122
131
  console.warn("@tallyui/connector-vendure: the 'auth_token' credential is deprecated; store the credential as 'token' instead.");
123
132
  }
124
- const token = credentials.token ?? credentials.auth_token;
133
+ const token = credentials.kind === "api-key" ? void 0 : credentials.token ?? credentials.auth_token;
134
+ const apiKey = credentials.kind === "password" ? void 0 : credentials.api_key;
125
135
  return {
126
- ...credentials.api_key ? { "vendure-api-key": credentials.api_key } : token ? { Authorization: `Bearer ${token}` } : {},
136
+ ...apiKey ? { "vendure-api-key": apiKey } : token ? { Authorization: `Bearer ${token}` } : {},
127
137
  ...credentials.channel_token ? { "vendure-token": credentials.channel_token } : {}
128
138
  };
129
139
  },
@@ -1016,6 +1026,7 @@ export {
1016
1026
  searchVendureCustomers,
1017
1027
  toVendureCustomer,
1018
1028
  vendureAuth,
1029
+ vendureAuthFieldSets,
1019
1030
  vendureConnector,
1020
1031
  vendureGlobalStockSettings,
1021
1032
  vendureProductReplication,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/connector-vendure",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
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.1.1"
29
+ "@tallyui/core": "^3.2.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@tallyui/database": "3.1.1",
33
- "@tallyui/pos": "3.1.1",
32
+ "@tallyui/database": "3.2.1",
33
+ "@tallyui/pos": "3.2.1",
34
34
  "rxdb": "17.5.0"
35
35
  },
36
36
  "scripts": {
package/src/auth.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SignInError, type ConnectorAuth } from '@tallyui/core';
1
+ import { SignInError, type AuthField, type ConnectorAuth } from '@tallyui/core';
2
2
 
3
3
  import { readVendureCapabilities } from './capabilities';
4
4
 
@@ -54,24 +54,46 @@ export const vendureSignIn: NonNullable<ConnectorAuth['signIn']> = async (baseUr
54
54
  // Warns once per module lifetime when a caller still relies on the deprecated auth_token alias.
55
55
  let warnedAuthToken = false;
56
56
 
57
- export const vendureAuth: ConnectorAuth = {
58
- type: 'Vendure Admin API',
59
- fields: [
57
+ export type VendureCredentialKind = 'password' | 'api-key';
58
+ /** What a Vendure till stores: `kind` says which credential it chose (absent on credentials saved before 3.2.0). */
59
+ export interface VendureCredentials {
60
+ kind?: VendureCredentialKind;
61
+ url: string;
62
+ email?: string; password?: string; // sign-in form only, never sent as headers
63
+ token?: string; // from signIn, for kind 'password'
64
+ api_key?: string; // the device key, for kind 'api-key'
65
+ channel_token?: string;
66
+ }
67
+
68
+ export const vendureAuthFieldSets: Record<VendureCredentialKind, AuthField[]> = {
69
+ password: [
60
70
  { key: 'url', label: 'Backend URL', type: 'url', placeholder: 'https://my-vendure-server.com', required: true },
61
71
  { key: 'email', label: 'Email', type: 'text', required: true },
62
72
  { key: 'password', label: 'Password', type: 'password', required: true },
63
73
  { key: 'channel_token', label: 'Channel token (optional)', type: 'text' },
64
74
  ],
65
- // An API key (Vendure 3.6+) wins over a signed-in session token; channel_token selects a non-default channel.
75
+ 'api-key': [
76
+ { key: 'url', label: 'Backend URL', type: 'url', placeholder: 'https://my-vendure-server.com', required: true },
77
+ { key: 'api_key', label: 'Device key', type: 'password', required: true },
78
+ { key: 'channel_token', label: 'Channel token (optional)', type: 'text' },
79
+ ],
80
+ };
81
+
82
+ export const vendureAuth: ConnectorAuth & { fieldSets: Record<VendureCredentialKind, AuthField[]> } = {
83
+ type: 'Vendure Admin API',
84
+ fields: vendureAuthFieldSets.password,
85
+ fieldSets: vendureAuthFieldSets,
86
+ // Without kind, an API key (Vendure 3.6+) wins over a session token; channel_token selects a non-default channel.
66
87
  // auth_token is the deprecated name for token, kept so existing apps keep working.
67
88
  getHeaders: (credentials): Record<string, string> => {
68
89
  if (credentials.token === undefined && credentials.auth_token !== undefined && !warnedAuthToken) {
69
90
  warnedAuthToken = true;
70
91
  console.warn("@tallyui/connector-vendure: the 'auth_token' credential is deprecated; store the credential as 'token' instead.");
71
92
  }
72
- const token = credentials.token ?? credentials.auth_token;
93
+ const token = credentials.kind === 'api-key' ? undefined : credentials.token ?? credentials.auth_token;
94
+ const apiKey = credentials.kind === 'password' ? undefined : credentials.api_key;
73
95
  return {
74
- ...(credentials.api_key ? { 'vendure-api-key': credentials.api_key } : token ? { Authorization: `Bearer ${token}` } : {}),
96
+ ...(apiKey ? { 'vendure-api-key': apiKey } : token ? { Authorization: `Bearer ${token}` } : {}),
75
97
  ...(credentials.channel_token ? { 'vendure-token': credentials.channel_token } : {}),
76
98
  };
77
99
  },
package/src/index.ts CHANGED
@@ -104,7 +104,7 @@ export const createVendureConnector = (options: {
104
104
  export const vendureConnector = createVendureConnector();
105
105
 
106
106
  // Re-export pieces for advanced usage
107
- export { vendureAuth, vendureSignIn } from './auth';
107
+ export { vendureAuth, vendureAuthFieldSets, vendureSignIn, type VendureCredentialKind, type VendureCredentials } from './auth';
108
108
  export { vendureProductSchema } from './schemas/products';
109
109
  export { vendureProductTraits } from './traits/product';
110
110
  export { vendureProductSync } from './sync/products';