jxp-helper 2.0.0 → 3.2.0

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/MIGRATION.md CHANGED
@@ -1,53 +1,38 @@
1
- # Migration Guide: v1.x to v2.0
1
+ # Migration Guide: jxp-helper v2 to v3
2
2
 
3
3
  ## Overview
4
4
 
5
- JXP Helper v2.0 introduces full TypeScript support while maintaining backward compatibility with JavaScript projects. This guide will help you migrate from v1.x to v2.0.
5
+ JXP Helper v3 removes axios and sends API keys in the `X-API-Key` header. It targets Node.js 22 or later and is intended for JXP 6.
6
6
 
7
7
  ## Breaking Changes
8
8
 
9
- ### 1. Main Entry Point
10
- - **v1.x**: `jxp-helper.js`
11
- - **v2.0**: `dist/index.js` (built from TypeScript)
12
-
13
- The package.json automatically handles this change, so no code changes are required.
14
-
15
- ### 2. Constructor Requirements
16
- Both `server` and `apikey` are now required parameters:
9
+ ### 1. API key transport
10
+ The constructor remains the same:
17
11
 
18
12
  ```javascript
19
- // v1.x - apikey was optional in some cases
20
- const helper = new JXPHelper({ server: "http://localhost:2001" });
21
-
22
- // v2.0 - both server and apikey are required
23
13
  const helper = new JXPHelper({
24
14
  server: "http://localhost:2001",
25
15
  apikey: "your-api-key"
26
16
  });
27
17
  ```
28
18
 
29
- ### 3. Error Handling
30
- Error handling is now more consistent and type-safe:
19
+ Every request now sends `X-API-Key: your-api-key` and never appends `?apikey=` to a URL.
31
20
 
32
- ```javascript
33
- // v1.x - inconsistent error formats
34
- try {
35
- const result = await helper.get('users');
36
- } catch (err) {
37
- // err could be various formats
38
- }
21
+ ### 2. Error handling
22
+
23
+ Errors are now typed:
39
24
 
40
- // v2.0 - consistent error handling
25
+ ```javascript
41
26
  try {
42
27
  const result = await helper.get('users');
43
28
  } catch (err) {
44
- // err.response.data contains the error details
29
+ // err is a JXPError with status, body, url, and method
45
30
  }
46
31
  ```
47
32
 
48
33
  ## New Features
49
34
 
50
- ### 1. TypeScript Support
35
+ ### 1. Native fetch
51
36
  Full TypeScript definitions are now included:
52
37
 
53
38
  ```typescript
@@ -82,7 +67,7 @@ const articles = await helper.get<Article>('articles', { limit: 10 });
82
67
  ### 3. Enhanced IntelliSense
83
68
  IDEs now provide better autocomplete and error detection.
84
69
 
85
- ## Migration Steps
70
+ ## Migration steps
86
71
 
87
72
  ### For JavaScript Projects
88
73
 
@@ -90,12 +75,12 @@ IDEs now provide better autocomplete and error detection.
90
75
  ```json
91
76
  {
92
77
  "dependencies": {
93
- "jxp-helper": "^2.0.0"
78
+ "jxp-helper": "^3.0.0"
94
79
  }
95
80
  }
96
81
  ```
97
82
 
98
- 2. **Update constructor calls** to include apikey:
83
+ 2. **Update constructor calls** to include the API key:
99
84
  ```javascript
100
85
  const helper = new JXPHelper({
101
86
  server: "http://localhost:2001",
@@ -103,7 +88,7 @@ IDEs now provide better autocomplete and error detection.
103
88
  });
104
89
  ```
105
90
 
106
- 3. **Test your application** - most existing code should work without changes.
91
+ 3. **Remove any code that reads `err.response.data`** and use `err.body`.
107
92
 
108
93
  ### For TypeScript Projects
109
94
 
@@ -125,13 +110,13 @@ IDEs now provide better autocomplete and error detection.
125
110
 
126
111
  ## Compatibility
127
112
 
128
- - **Node.js**: Requires Node.js 14.0.0 or higher
129
- - **JavaScript**: Fully backward compatible (with constructor changes)
113
+ - **Node.js**: Requires Node.js 22.0.0 or higher
114
+ - **JavaScript**: CommonJS and ESM are supported
130
115
  - **TypeScript**: Full support with type definitions
131
116
  - **ES Modules**: Supported
132
117
  - **CommonJS**: Supported
133
118
 
134
- ## Development Changes
119
+ ## Development changes
135
120
 
136
121
  If you're contributing to the project:
137
122
 
@@ -140,11 +125,19 @@ If you're contributing to the project:
140
125
  3. **Development**: Use `npm run dev` for watch mode
141
126
  4. **Distribution**: Only `dist/` files are published to npm
142
127
 
128
+ ## v3.1 — Bearer sessions and MFA
129
+
130
+ - `token` constructor option sends `Authorization: Bearer` (preferred over `apikey` when both are set).
131
+ - Constructor no longer requires credentials (needed for password / MFA login).
132
+ - `login()` may return `{ status: "mfa_required", challenge, methods }` — use `isMfaRequired()` and `completeMfa()`.
133
+ - `refresh(refreshToken)` exchanges a refresh token for a new pair.
134
+ - Login no longer returns API keys; use the bearer `token` from the response.
135
+
143
136
  ## Need Help?
144
137
 
145
138
  If you encounter issues during migration:
146
139
 
147
- 1. Check that both `server` and `apikey` are provided in the constructor
148
- 2. Ensure you're using Node.js 14.0.0 or higher
140
+ 1. Provide `apikey` (machine) or `token` (user session) for `/api/*` calls
141
+ 2. Ensure you're using Node.js 22.0.0 or higher
149
142
  3. For TypeScript projects, make sure your tsconfig.json includes proper module resolution
150
143
  4. Open an issue on GitHub if you need assistance
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # JXP Helper
2
2
 
3
- A bunch of helpers to make it easier to read, write, delete and do other cool stuff with the [JXP API server](https://github.com/j-norwood-young/jexpress-2)
3
+ Helpers for reading, writing, and calling a [JXP](https://github.com/WorkSpaceMan/jxp) API server.
4
4
 
5
- **Now with full TypeScript support!** 🎉
5
+ Targets **JXP 6** (bearer tokens + X-API-Key, MFA / TOTP login). Requires **Node.js 22+**.
6
6
 
7
7
  ## Installation
8
8
 
@@ -10,86 +10,97 @@ A bunch of helpers to make it easier to read, write, delete and do other cool st
10
10
  npm install --save jxp-helper
11
11
  ```
12
12
 
13
- ## Usage
13
+ ## Authentication
14
14
 
15
- ### TypeScript
15
+ JXP supports two client credentials:
16
+
17
+ | Option | Header | Use |
18
+ | --- | --- | --- |
19
+ | `apikey` | `X-API-Key` | Long-lived machine / system keys |
20
+ | `token` | `Authorization: Bearer …` | Ephemeral access tokens from `/login` or `/login/mfa` |
21
+
22
+ Provide at least one for `/api/*` calls. Auth endpoints (`login`, `completeMfa`, `refresh`) work with neither.
23
+
24
+ When both are set, the **bearer token wins**.
16
25
 
17
26
  ```typescript
18
- import JXPHelper from 'jxp-helper';
19
- // or
20
- import { JXPHelper } from 'jxp-helper';
27
+ import { JXPHelper, isMfaRequired } from 'jxp-helper';
28
+
29
+ // System / machine client
30
+ const system = new JXPHelper({
31
+ server: 'http://localhost:4001',
32
+ apikey: process.env.JXP_API_KEY!
33
+ });
21
34
 
22
- const apihelper = new JXPHelper({
23
- server: "http://localhost:2001",
24
- apikey: "your-api-key"
35
+ // User session client (after login)
36
+ const user = new JXPHelper({
37
+ server: 'http://localhost:4001',
38
+ token: accessToken
25
39
  });
26
40
  ```
27
41
 
28
- ### JavaScript (CommonJS)
42
+ ### Login + MFA (TOTP)
29
43
 
30
- ```javascript
31
- const JXPHelper = require("jxp-helper");
32
- const apihelper = new JXPHelper({
33
- server: "http://localhost:2001",
34
- apikey: "your-api-key"
35
- });
44
+ ```typescript
45
+ const api = new JXPHelper({ server: 'http://localhost:4001' });
46
+
47
+ const step1 = await api.login(email, password);
48
+ if (isMfaRequired(step1)) {
49
+ const step2 = await api.completeMfa({
50
+ challenge: step1.challenge,
51
+ code: authenticatorCode // or backup code
52
+ });
53
+ // step2.data.token / step2.user — api.token is also set
54
+ } else {
55
+ // step1.data.token / step1.user
56
+ }
36
57
  ```
37
58
 
38
- ### JavaScript (ES Modules)
59
+ ### Refresh
39
60
 
40
- ```javascript
41
- import JXPHelper from 'jxp-helper';
42
- const apihelper = new JXPHelper({
43
- server: "http://localhost:2001",
44
- apikey: "your-api-key"
45
- });
61
+ ```typescript
62
+ const renewed = await api.refresh(refreshToken);
46
63
  ```
47
64
 
48
65
  ## Configuration Options
49
66
 
50
67
  ```typescript
51
68
  interface JXPHelperOptions {
52
- server: string; // Required: The JXP server URL
53
- apikey: string; // Required: Your API key
54
- debug?: boolean; // Optional: Enable debug logging (default: false)
55
- hideErrors?: boolean; // Optional: Hide error messages (default: false)
69
+ server: string; // Required
70
+ apikey?: string; // X-API-Key
71
+ token?: string; // Authorization: Bearer
72
+ debug?: boolean;
73
+ hideErrors?: boolean;
56
74
  }
57
75
  ```
58
76
 
59
- ## Config
77
+ ## TypeScript
60
78
 
61
- ### Config file
62
-
63
- Use [config](https://www.npmjs.com/package/config) and create `config/default.json` with your `jxp_server`.
79
+ ```typescript
80
+ import { JXPHelper } from 'jxp-helper';
64
81
 
65
- Eg. of `default.json`
82
+ const api = new JXPHelper({
83
+ server: 'http://localhost:4001',
84
+ apikey: process.env.JXP_API_KEY!
85
+ });
66
86
 
67
- ```json
68
- {
69
- "jxp_server": "http://localhost:2001"
70
- }
87
+ const user = await api.getOne<User>('user', userId);
88
+ const articles = await api.get<Article>('article', { limit: 10 });
71
89
  ```
72
90
 
73
- ### Pass in config
74
-
75
- When initialising the helper, just pass in `server` and `apikey`.
91
+ ## Tests
76
92
 
77
- ```typescript
78
- const apihelper = new JXPHelper({
79
- server: "http://localhost:2001",
80
- apikey: "your-api-key"
81
- });
93
+ ```bash
94
+ npm test
95
+ npm run test:coverage
82
96
  ```
83
97
 
84
- ## TypeScript Support
98
+ Uses Node's built-in test runner against a local mock HTTP server (no live JXP required).
85
99
 
86
- This package includes full TypeScript definitions and provides excellent IntelliSense support. All methods are properly typed with generics where appropriate:
100
+ ## Migration from v2
87
101
 
88
- ```typescript
89
- // Typed responses
90
- const user = await apihelper.getOne<User>('users', userId);
91
- const articles = await apihelper.get<Article>('articles', { limit: 10 });
102
+ See [MIGRATION.md](MIGRATION.md).
103
+
104
+ ## License
92
105
 
93
- // Type-safe bulk operations
94
- await apihelper.bulk_post('users', userData);
95
- ```
106
+ MIT
@@ -0,0 +1,15 @@
1
+ export declare class JXPError extends Error {
2
+ readonly status: number;
3
+ readonly statusText: string;
4
+ readonly body: unknown;
5
+ readonly url: string;
6
+ readonly method: string;
7
+ constructor(options: {
8
+ status: number;
9
+ statusText: string;
10
+ body: unknown;
11
+ url: string;
12
+ method: string;
13
+ });
14
+ }
15
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,OAAO,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;KAChB;CASF"}
package/dist/errors.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JXPError = void 0;
4
+ class JXPError extends Error {
5
+ status;
6
+ statusText;
7
+ body;
8
+ url;
9
+ method;
10
+ constructor(options) {
11
+ super(`JXP request failed with ${options.status} ${options.statusText}`);
12
+ this.name = 'JXPError';
13
+ this.status = options.status;
14
+ this.statusText = options.statusText;
15
+ this.body = options.body;
16
+ this.url = options.url;
17
+ this.method = options.method;
18
+ }
19
+ }
20
+ exports.JXPError = JXPError;
21
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAS,SAAQ,KAAK;IACxB,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,IAAI,CAAU;IACd,GAAG,CAAS;IACZ,MAAM,CAAS;IAExB,YAAY,OAMX;QACC,KAAK,CAAC,2BAA2B,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;CACF;AAtBD,4BAsBC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface RequestOptions {
2
+ method?: string;
3
+ body?: unknown;
4
+ signal?: AbortSignal;
5
+ }
6
+ export declare function jxpRequest<T>(url: string, apiKey: string | undefined, bearerToken: string | undefined, options?: RequestOptions): Promise<T>;
7
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAmCZ"}
package/dist/http.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jxpRequest = jxpRequest;
4
+ const errors_1 = require("./errors");
5
+ async function jxpRequest(url, apiKey, bearerToken, options = {}) {
6
+ const headers = { Accept: 'application/json' };
7
+ // Prefer bearer access tokens when both are present (post-login session).
8
+ if (bearerToken)
9
+ headers.Authorization = `Bearer ${bearerToken}`;
10
+ else if (apiKey)
11
+ headers['X-API-Key'] = apiKey;
12
+ let body;
13
+ if (options.body !== undefined) {
14
+ headers['Content-Type'] = 'application/json';
15
+ body = JSON.stringify(options.body);
16
+ }
17
+ const response = await fetch(url, {
18
+ method: options.method ?? 'GET',
19
+ headers,
20
+ body,
21
+ signal: options.signal ?? AbortSignal.timeout(30_000)
22
+ });
23
+ const contentType = response.headers.get('content-type') ?? '';
24
+ const result = contentType.includes('json')
25
+ ? await response.json()
26
+ : await response.text();
27
+ if (!response.ok) {
28
+ throw new errors_1.JXPError({
29
+ status: response.status,
30
+ statusText: response.statusText,
31
+ body: result,
32
+ url,
33
+ method: options.method ?? 'GET'
34
+ });
35
+ }
36
+ return result;
37
+ }
38
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";;AAQA,gCAwCC;AAhDD,qCAAoC;AAQ7B,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,MAA0B,EAC1B,WAA+B,EAC/B,UAA0B,EAAE;IAE5B,MAAM,OAAO,GAA2B,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IACvE,0EAA0E;IAC1E,IAAI,WAAW;QAAE,OAAO,CAAC,aAAa,GAAG,UAAU,WAAW,EAAE,CAAC;SAC5D,IAAI,MAAM;QAAE,OAAO,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC;IAE/C,IAAI,IAAwB,CAAC;IAC7B,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;QAC7C,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;QAC/B,OAAO;QACP,IAAI;QACJ,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;KACtD,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IAC/D,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QACzC,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE;QACvB,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAE1B,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,iBAAQ,CAAC;YACjB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,IAAI,EAAE,MAAM;YACZ,GAAG;YACH,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;SAChC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAW,CAAC;AACrB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { JXPHelper as default, JXPHelper } from './jxp-helper';
2
2
  export * from './types';
3
+ export * from './errors';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -19,4 +19,5 @@ var jxp_helper_1 = require("./jxp-helper");
19
19
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return jxp_helper_1.JXPHelper; } });
20
20
  Object.defineProperty(exports, "JXPHelper", { enumerable: true, get: function () { return jxp_helper_1.JXPHelper; } });
21
21
  __exportStar(require("./types"), exports);
22
+ __exportStar(require("./errors"), exports);
22
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAA+D;AAAtD,qGAAA,SAAS,OAAW;AAAE,uGAAA,SAAS,OAAA;AACxC,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAA+D;AAAtD,qGAAA,SAAS,OAAW;AAAE,uGAAA,SAAS,OAAA;AACxC,0CAAwB;AACxB,2CAAyB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { createRequire } from 'node:module';
2
+
3
+ const require = createRequire(import.meta.url);
4
+ const cjs = require('./index.js');
5
+
6
+ export const JXPHelper = cjs.JXPHelper;
7
+ export const JXPError = cjs.JXPError;
8
+ export default cjs.default ?? cjs.JXPHelper;
@@ -1,16 +1,19 @@
1
- import { JXPHelperOptions, LoginResponse, ApiResponse, BulkWriteOperation, QueryOptions, JWTResponse, ModelDefinition } from './types';
1
+ import { JXPHelperOptions, LoginResponse, MfaRequiredResponse, ApiResponse, BulkWriteOperation, QueryOptions, JWTResponse, ModelDefinition } from './types';
2
2
  /**
3
3
  * JXPHelper class for interacting with a JXP server.
4
4
  */
5
5
  export declare class JXPHelper {
6
6
  server: string;
7
- apikey: string;
7
+ apikey?: string;
8
+ token?: string;
8
9
  api: string;
9
10
  debug: boolean;
10
11
  hideErrors: boolean;
11
12
  /**
12
13
  * Creates a new instance of the JXP Helper class.
13
14
  * @param opts - The options for configuring the JXP Helper.
15
+ * Provide `apikey` and/or `token`. Credentials may be omitted when only calling
16
+ * unauthenticated auth endpoints (`login`, `completeMfa`, `refresh`).
14
17
  */
15
18
  constructor(opts: JXPHelperOptions);
16
19
  /**
@@ -18,17 +21,35 @@ export declare class JXPHelper {
18
21
  * @param opts - The options to configure.
19
22
  */
20
23
  config(opts: Partial<JXPHelperOptions>): void;
24
+ /** Prefer bearer access token for subsequent authenticated calls. */
25
+ useAccessToken(accessToken: string): this;
26
+ private _isPlainObject;
27
+ private _isEmptyParam;
28
+ private _encodeParam;
29
+ private _appendObjectEntries;
21
30
  private _configParams;
22
31
  private _randomString;
23
32
  private _displayError;
33
+ private _request;
34
+ private _hydrateLogin;
24
35
  url(type: string, opts?: QueryOptions, ep?: string): string;
25
36
  /**
26
- * Logs in a user with the provided email and password.
27
- * @param email - The user's email.
28
- * @param password - The user's password.
29
- * @returns A promise that resolves to an object containing the login data and user information, or rejects with an error object.
37
+ * Password login. May return an MFA challenge instead of tokens.
38
+ * On success, stores the access token on this helper for subsequent calls.
30
39
  */
31
- login(email: string, password: string): Promise<LoginResponse | any>;
40
+ login(email: string, password: string): Promise<LoginResponse | MfaRequiredResponse>;
41
+ /**
42
+ * Complete MFA after `login` returned `{ status: "mfa_required", challenge, methods }`.
43
+ */
44
+ completeMfa(opts: {
45
+ challenge: string;
46
+ code: string;
47
+ method?: string;
48
+ }): Promise<LoginResponse>;
49
+ /**
50
+ * Exchange a refresh token for a new access / refresh pair.
51
+ */
52
+ refresh(refreshToken: string): Promise<LoginResponse>;
32
53
  /**
33
54
  * Retrieves a single item of a specified type by its ID.
34
55
  * @param type - The type of the item.
@@ -200,6 +221,13 @@ export declare class JXPHelper {
200
221
  * @throws Throws an error if the request fails.
201
222
  */
202
223
  call<T = any>(type: string, cmd: string, data: any): Promise<T>;
224
+ /**
225
+ * Retrieves the groups for a user.
226
+ * @param user_id - The ID of the user.
227
+ * @returns A promise that resolves to the usergroup document (or `{ groups: [] }`).
228
+ * @throws If an error occurs during the request.
229
+ */
230
+ groups_get(user_id: string): Promise<any>;
203
231
  /**
204
232
  * Updates the groups for a user.
205
233
  * @param user_id - The ID of the user.
@@ -1 +1 @@
1
- {"version":3,"file":"jxp-helper.d.ts","sourceRoot":"","sources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