@espressif/rainmaker-admin-sdk 1.2.0 → 1.3.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/CHANGELOG.md +107 -0
- package/README.md +2 -1
- package/dist/cjs/ESPRMBase.cjs +1 -0
- package/dist/cjs/ESPRMClaim.cjs +16 -0
- package/dist/cjs/entries/ESPRMAdminCommonCustomData.cjs +1 -0
- package/dist/cjs/entries/ESPRMAdminNode.cjs +1 -0
- package/dist/cjs/entries/ESPRMClaim.cjs +14 -0
- package/dist/cjs/index.cjs +7 -0
- package/dist/cjs/methods/ESPRMAdminCommonCustomData/DeleteCommonCustomData.cjs +24 -0
- package/dist/cjs/methods/ESPRMAdminCommonCustomData/SetCommonCustomData.cjs +7 -0
- package/dist/cjs/methods/ESPRMAdminNode/ActivateDeactivateNodes.cjs +11 -1
- package/dist/cjs/methods/ESPRMAdminNode/DeleteNode.cjs +24 -0
- package/dist/cjs/methods/ESPRMClaim/InitiateClaim.cjs +28 -0
- package/dist/cjs/methods/ESPRMClaim/VerifyClaim.cjs +28 -0
- package/dist/cjs/services/ESPRMAPIManager.cjs +15 -1
- package/dist/cjs/utils/constants.cjs +14 -0
- package/dist/cjs/utils/error/errorMessages.cjs +9 -0
- package/dist/cjs/utils/validator/ConfigValidator.cjs +9 -0
- package/dist/esm/ESPRMBase.js +1 -0
- package/dist/esm/ESPRMClaim.js +14 -0
- package/dist/esm/entries/ESPRMAdminCommonCustomData.js +1 -0
- package/dist/esm/entries/ESPRMAdminNode.js +1 -0
- package/dist/esm/entries/ESPRMClaim.js +8 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/methods/ESPRMAdminCommonCustomData/DeleteCommonCustomData.js +22 -0
- package/dist/esm/methods/ESPRMAdminCommonCustomData/SetCommonCustomData.js +8 -1
- package/dist/esm/methods/ESPRMAdminNode/ActivateDeactivateNodes.js +12 -2
- package/dist/esm/methods/ESPRMAdminNode/DeleteNode.js +22 -0
- package/dist/esm/methods/ESPRMClaim/InitiateClaim.js +26 -0
- package/dist/esm/methods/ESPRMClaim/VerifyClaim.js +26 -0
- package/dist/esm/services/ESPRMAPIManager.js +15 -1
- package/dist/esm/utils/constants.js +14 -1
- package/dist/esm/utils/error/errorMessages.js +9 -0
- package/dist/esm/utils/validator/ConfigValidator.js +9 -0
- package/dist/types/ESPRMClaim.d.ts +12 -0
- package/dist/types/entries/ESPRMClaim.d.ts +7 -0
- package/dist/types/methods/ESPRMAdminCommonCustomData/DeleteCommonCustomData.d.ts +22 -0
- package/dist/types/methods/ESPRMAdminCommonCustomData/SetCommonCustomData.d.ts +6 -1
- package/dist/types/methods/ESPRMAdminCommonCustomData/index.d.ts +1 -0
- package/dist/types/methods/ESPRMAdminEventFilter/UpdateEventFilter.d.ts +5 -0
- package/dist/types/methods/ESPRMAdminNode/ActivateDeactivateNodes.d.ts +9 -6
- package/dist/types/methods/ESPRMAdminNode/DeleteNode.d.ts +19 -0
- package/dist/types/methods/ESPRMAdminNode/index.d.ts +1 -0
- package/dist/types/methods/ESPRMAdminWebhook/GetWebhookIntegrations.d.ts +2 -1
- package/dist/types/methods/ESPRMClaim/InitiateClaim.d.ts +21 -0
- package/dist/types/methods/ESPRMClaim/VerifyClaim.d.ts +21 -0
- package/dist/types/methods/ESPRMClaim/index.d.ts +7 -0
- package/dist/types/methods/export.d.ts +1 -0
- package/dist/types/services/ESPRMAPIManager.d.ts +6 -0
- package/dist/types/types/claim.d.ts +45 -0
- package/dist/types/types/common_custom_data.d.ts +32 -5
- package/dist/types/types/config.d.ts +9 -0
- package/dist/types/types/event_filter.d.ts +17 -3
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/input.d.ts +2 -1
- package/dist/types/types/mainTypes.d.ts +2 -1
- package/dist/types/types/node.d.ts +33 -3
- package/dist/types/types/output.d.ts +2 -1
- package/dist/types/types/webhook.d.ts +5 -2
- package/dist/types/utils/constants.d.ts +14 -1
- package/dist/types/utils/error/errorMessages.d.ts +9 -0
- package/dist/types/utils/validator/ConfigValidator.d.ts +1 -0
- package/dist/types-cjs/ESPRMClaim.d.cts +12 -0
- package/dist/types-cjs/entries/ESPRMClaim.d.cts +7 -0
- package/dist/types-cjs/methods/ESPRMAdminCommonCustomData/DeleteCommonCustomData.d.cts +22 -0
- package/dist/types-cjs/methods/ESPRMAdminCommonCustomData/SetCommonCustomData.d.cts +6 -1
- package/dist/types-cjs/methods/ESPRMAdminCommonCustomData/index.d.cts +1 -0
- package/dist/types-cjs/methods/ESPRMAdminEventFilter/UpdateEventFilter.d.cts +5 -0
- package/dist/types-cjs/methods/ESPRMAdminNode/ActivateDeactivateNodes.d.cts +9 -6
- package/dist/types-cjs/methods/ESPRMAdminNode/DeleteNode.d.cts +19 -0
- package/dist/types-cjs/methods/ESPRMAdminNode/index.d.cts +1 -0
- package/dist/types-cjs/methods/ESPRMAdminWebhook/GetWebhookIntegrations.d.cts +2 -1
- package/dist/types-cjs/methods/ESPRMClaim/InitiateClaim.d.cts +21 -0
- package/dist/types-cjs/methods/ESPRMClaim/VerifyClaim.d.cts +21 -0
- package/dist/types-cjs/methods/ESPRMClaim/index.d.cts +7 -0
- package/dist/types-cjs/methods/export.d.cts +1 -0
- package/dist/types-cjs/services/ESPRMAPIManager.d.cts +6 -0
- package/dist/types-cjs/types/claim.d.cts +45 -0
- package/dist/types-cjs/types/common_custom_data.d.cts +32 -5
- package/dist/types-cjs/types/config.d.cts +9 -0
- package/dist/types-cjs/types/event_filter.d.cts +17 -3
- package/dist/types-cjs/types/index.d.cts +1 -0
- package/dist/types-cjs/types/input.d.cts +2 -1
- package/dist/types-cjs/types/mainTypes.d.cts +2 -1
- package/dist/types-cjs/types/node.d.cts +33 -3
- package/dist/types-cjs/types/output.d.cts +2 -1
- package/dist/types-cjs/types/webhook.d.cts +5 -2
- package/dist/types-cjs/utils/constants.d.cts +14 -1
- package/dist/types-cjs/utils/error/errorMessages.d.cts +9 -0
- package/dist/types-cjs/utils/validator/ConfigValidator.d.cts +1 -0
- package/package.json +11 -1
|
@@ -5,9 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ESPRMAdminCommonCustomData } from '../../ESPRMAdminCommonCustomData.js';
|
|
7
7
|
import { ESPRMAPIManager } from '../../services/ESPRMAPIManager.js';
|
|
8
|
-
import { HTTPMethods, APIEndpoints } from '../../utils/constants.js';
|
|
8
|
+
import { APICallValidationErrorCodes, HTTPMethods, APIEndpoints } from '../../utils/constants.js';
|
|
9
|
+
import { ESPAPICallValidationError } from '../../utils/error/ESPAPICallValidationError.js';
|
|
9
10
|
|
|
10
11
|
ESPRMAdminCommonCustomData.prototype.setCommonCustomData = async function (params) {
|
|
12
|
+
if (!params.name) {
|
|
13
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.MISSING_COMMON_CUSTOM_DATA_NAME);
|
|
14
|
+
}
|
|
15
|
+
if (params.value === null || params.value === undefined) {
|
|
16
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.MISSING_COMMON_CUSTOM_DATA_VALUE);
|
|
17
|
+
}
|
|
11
18
|
const requestConfig = {
|
|
12
19
|
url: APIEndpoints.ADMIN_COMMON_CUSTOM_DATA,
|
|
13
20
|
method: HTTPMethods.PUT,
|
|
@@ -5,13 +5,23 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ESPRMAdminNode } from '../../ESPRMAdminNode.js';
|
|
7
7
|
import { ESPRMAPIManager } from '../../services/ESPRMAPIManager.js';
|
|
8
|
-
import { HTTPMethods, APIEndpoints } from '../../utils/constants.js';
|
|
8
|
+
import { APICallValidationErrorCodes, MAX_NODE_ACTIVATION_BATCH_SIZE, HTTPMethods, APIEndpoints } from '../../utils/constants.js';
|
|
9
|
+
import { ESPAPICallValidationError } from '../../utils/error/ESPAPICallValidationError.js';
|
|
9
10
|
|
|
10
11
|
ESPRMAdminNode.prototype.activateDeactivateNodes = async function (params) {
|
|
12
|
+
const nodeIds = params.node_ids?.filter(Boolean) ?? [];
|
|
13
|
+
if (nodeIds.length === 0) {
|
|
14
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.MISSING_NODE_IDS);
|
|
15
|
+
}
|
|
16
|
+
if (nodeIds.length > MAX_NODE_ACTIVATION_BATCH_SIZE) {
|
|
17
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.TOO_MANY_NODE_IDS);
|
|
18
|
+
}
|
|
19
|
+
// The backend reads both values from the query string only; a JSON body
|
|
20
|
+
// on this endpoint is parsed as node tags.
|
|
11
21
|
const requestConfig = {
|
|
12
22
|
url: APIEndpoints.ADMIN_NODES,
|
|
13
23
|
method: HTTPMethods.PUT,
|
|
14
|
-
|
|
24
|
+
params: { node_id: nodeIds.join(","), activate: params.activate },
|
|
15
25
|
};
|
|
16
26
|
const response = await ESPRMAPIManager.authorizeRequest(requestConfig);
|
|
17
27
|
return response;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ESPRMAdminNode } from '../../ESPRMAdminNode.js';
|
|
7
|
+
import { ESPRMAPIManager } from '../../services/ESPRMAPIManager.js';
|
|
8
|
+
import { APICallValidationErrorCodes, HTTPMethods, APIEndpoints } from '../../utils/constants.js';
|
|
9
|
+
import { ESPAPICallValidationError } from '../../utils/error/ESPAPICallValidationError.js';
|
|
10
|
+
|
|
11
|
+
ESPRMAdminNode.prototype.deleteNode = async function (nodeId) {
|
|
12
|
+
if (!nodeId) {
|
|
13
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.MISSING_NODE_ID);
|
|
14
|
+
}
|
|
15
|
+
const requestConfig = {
|
|
16
|
+
url: APIEndpoints.ADMIN_NODES,
|
|
17
|
+
method: HTTPMethods.DELETE,
|
|
18
|
+
params: { node_id: nodeId, delete_node: true },
|
|
19
|
+
};
|
|
20
|
+
const response = await ESPRMAPIManager.authorizeRequest(requestConfig);
|
|
21
|
+
return response;
|
|
22
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ESPRMClaim } from '../../ESPRMClaim.js';
|
|
7
|
+
import { ESPRMAPIManager } from '../../services/ESPRMAPIManager.js';
|
|
8
|
+
import { APICallValidationErrorCodes, HTTPMethods, APIEndpoints } from '../../utils/constants.js';
|
|
9
|
+
import { ESPAPICallValidationError } from '../../utils/error/ESPAPICallValidationError.js';
|
|
10
|
+
|
|
11
|
+
ESPRMClaim.prototype.initiateClaim = async function (params) {
|
|
12
|
+
if (!params.mac_addr) {
|
|
13
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.MISSING_MAC_ADDRESS);
|
|
14
|
+
}
|
|
15
|
+
if (!params.platform) {
|
|
16
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.MISSING_CLAIM_PLATFORM);
|
|
17
|
+
}
|
|
18
|
+
const requestConfig = {
|
|
19
|
+
baseURL: ESPRMAPIManager.getClaimingBaseUrl(),
|
|
20
|
+
url: APIEndpoints.CLAIM_INITIATE,
|
|
21
|
+
method: HTTPMethods.POST,
|
|
22
|
+
data: params,
|
|
23
|
+
};
|
|
24
|
+
const response = await ESPRMAPIManager.authorizeRequest(requestConfig);
|
|
25
|
+
return response;
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ESPRMClaim } from '../../ESPRMClaim.js';
|
|
7
|
+
import { ESPRMAPIManager } from '../../services/ESPRMAPIManager.js';
|
|
8
|
+
import { APICallValidationErrorCodes, HTTPMethods, APIEndpoints } from '../../utils/constants.js';
|
|
9
|
+
import { ESPAPICallValidationError } from '../../utils/error/ESPAPICallValidationError.js';
|
|
10
|
+
|
|
11
|
+
ESPRMClaim.prototype.verifyClaim = async function (params, options = {}) {
|
|
12
|
+
if (!params.csr) {
|
|
13
|
+
throw new ESPAPICallValidationError(APICallValidationErrorCodes.MISSING_CSR);
|
|
14
|
+
}
|
|
15
|
+
const matter = options.matter ?? false;
|
|
16
|
+
const requestConfig = {
|
|
17
|
+
baseURL: ESPRMAPIManager.getClaimingBaseUrl(),
|
|
18
|
+
url: APIEndpoints.CLAIM_VERIFY,
|
|
19
|
+
method: HTTPMethods.POST,
|
|
20
|
+
data: params,
|
|
21
|
+
// The service ignores `test` unless `matter` is true.
|
|
22
|
+
params: matter ? { matter, test: options.test ?? false } : { matter },
|
|
23
|
+
};
|
|
24
|
+
const response = await ESPRMAPIManager.authorizeRequest(requestConfig);
|
|
25
|
+
return response;
|
|
26
|
+
};
|
|
@@ -19,10 +19,12 @@ class ESPRMAPIManager {
|
|
|
19
19
|
static #instance;
|
|
20
20
|
#baseUrl;
|
|
21
21
|
#timeoutMs;
|
|
22
|
+
#claimingBaseUrl;
|
|
22
23
|
constructor(config) {
|
|
23
|
-
const { baseUrl, version, timeoutMs } = config;
|
|
24
|
+
const { baseUrl, version, timeoutMs, claimingBaseUrl } = config;
|
|
24
25
|
this.#baseUrl = `${baseUrl}/${version}`;
|
|
25
26
|
this.#timeoutMs = timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
27
|
+
this.#claimingBaseUrl = claimingBaseUrl?.replace(/\/+$/, "");
|
|
26
28
|
}
|
|
27
29
|
static initialize(config) {
|
|
28
30
|
ESPRMAPIManager.#instance = new ESPRMAPIManager(config);
|
|
@@ -33,6 +35,18 @@ class ESPRMAPIManager {
|
|
|
33
35
|
}
|
|
34
36
|
return ESPRMAPIManager.#instance;
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Base URL of the claiming service set through `claimingBaseUrl`.
|
|
40
|
+
*
|
|
41
|
+
* @throws ESPConfigError `CLAIMING_NOT_CONFIGURED` when it was not configured.
|
|
42
|
+
*/
|
|
43
|
+
static getClaimingBaseUrl() {
|
|
44
|
+
const claimingBaseUrl = ESPRMAPIManager.#getInstance().#claimingBaseUrl;
|
|
45
|
+
if (!claimingBaseUrl) {
|
|
46
|
+
throw new ESPConfigError(ConfigErrorCodes.CLAIMING_NOT_CONFIGURED);
|
|
47
|
+
}
|
|
48
|
+
return claimingBaseUrl;
|
|
49
|
+
}
|
|
36
50
|
/**
|
|
37
51
|
* Send a request with the current user's access token in the
|
|
38
52
|
* `Authorization` header, refreshing the token first if it has expired.
|
|
@@ -94,6 +94,8 @@ const APIEndpoints = {
|
|
|
94
94
|
ADMIN_MATTER_BATCH: "admin/matter/batch",
|
|
95
95
|
ADMIN_MATTER_BATCH_NODES: "admin/matter/batch/nodes",
|
|
96
96
|
ADMIN_MAIL_FAILURES: "admin/mail_failures",
|
|
97
|
+
CLAIM_INITIATE: "claim/initiate",
|
|
98
|
+
CLAIM_VERIFY: "claim/verify",
|
|
97
99
|
};
|
|
98
100
|
const StorageKeys = {
|
|
99
101
|
ACCESSTOKEN: "com.esprmbase.accessToken",
|
|
@@ -104,6 +106,8 @@ const ConfigErrorCodes = {
|
|
|
104
106
|
SDK_NOT_CONFIGURED: "SDK_NOT_CONFIGURED",
|
|
105
107
|
INVALID_CONFIG_OBJECT: "INVALID_CONFIG_OBJECT",
|
|
106
108
|
INVALID_BASE_URL: "INVALID_BASE_URL",
|
|
109
|
+
INVALID_CLAIMING_BASE_URL: "INVALID_CLAIMING_BASE_URL",
|
|
110
|
+
CLAIMING_NOT_CONFIGURED: "CLAIMING_NOT_CONFIGURED",
|
|
107
111
|
};
|
|
108
112
|
const ValidationErrorCodes = {
|
|
109
113
|
MISSING_LOGIN_PASSWORD: "MISSING_LOGIN_PASSWORD",
|
|
@@ -151,6 +155,13 @@ const APICallValidationErrorCodes = {
|
|
|
151
155
|
MISSING_BATCH_ID: "MISSING_BATCH_ID",
|
|
152
156
|
MISSING_CANCEL_COMMAND_SCOPE: "MISSING_CANCEL_COMMAND_SCOPE",
|
|
153
157
|
CMD_ID_REQUIRES_NODE_ID: "CMD_ID_REQUIRES_NODE_ID",
|
|
158
|
+
MISSING_COMMON_CUSTOM_DATA_NAME: "MISSING_COMMON_CUSTOM_DATA_NAME",
|
|
159
|
+
MISSING_COMMON_CUSTOM_DATA_VALUE: "MISSING_COMMON_CUSTOM_DATA_VALUE",
|
|
160
|
+
MISSING_MAC_ADDRESS: "MISSING_MAC_ADDRESS",
|
|
161
|
+
MISSING_CLAIM_PLATFORM: "MISSING_CLAIM_PLATFORM",
|
|
162
|
+
MISSING_CSR: "MISSING_CSR",
|
|
163
|
+
MISSING_NODE_IDS: "MISSING_NODE_IDS",
|
|
164
|
+
TOO_MANY_NODE_IDS: "TOO_MANY_NODE_IDS",
|
|
154
165
|
};
|
|
155
166
|
const TokenErrorCodes = {
|
|
156
167
|
MISSING_ACCESS_TOKEN: "MISSING_ACCESS_TOKEN",
|
|
@@ -176,10 +187,12 @@ const DEFAULT_REST_API_VERSION = "v1";
|
|
|
176
187
|
const DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
177
188
|
/** Tokens expiring within this many seconds are refreshed proactively. */
|
|
178
189
|
const TOKEN_EXPIRY_MARGIN_SECONDS = 30;
|
|
190
|
+
/** Backend limit on node IDs per `PUT admin/nodes` activation request. */
|
|
191
|
+
const MAX_NODE_ACTIVATION_BATCH_SIZE = 25;
|
|
179
192
|
/** errorCode values the SDK itself sets on ESPAPIError for non-HTTP failures. */
|
|
180
193
|
const APIErrorCodes = {
|
|
181
194
|
REQUEST_TIMEOUT: "REQUEST_TIMEOUT",
|
|
182
195
|
NETWORK_ERROR: "NETWORK_ERROR",
|
|
183
196
|
};
|
|
184
197
|
|
|
185
|
-
export { APICallValidationErrorCodes, APIEndpoints, APIErrorCodes, AdditionalInfo, ConfigErrorCodes, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_REST_API_VERSION, ErrorLabels, HTTPMethods, HTTPStatusCodes, StorageAdapterErrorCodes, StorageKeys, TOKEN_EXPIRY_MARGIN_SECONDS, TokenErrorCodes, ValidationErrorCodes };
|
|
198
|
+
export { APICallValidationErrorCodes, APIEndpoints, APIErrorCodes, AdditionalInfo, ConfigErrorCodes, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_REST_API_VERSION, ErrorLabels, HTTPMethods, HTTPStatusCodes, MAX_NODE_ACTIVATION_BATCH_SIZE, StorageAdapterErrorCodes, StorageKeys, TOKEN_EXPIRY_MARGIN_SECONDS, TokenErrorCodes, ValidationErrorCodes };
|
|
@@ -7,6 +7,8 @@ const configErrorMessages = {
|
|
|
7
7
|
SDK_NOT_CONFIGURED: "ESPRMBase is not configured yet",
|
|
8
8
|
INVALID_CONFIG_OBJECT: "Configuration Error: Config must be a non-null object.",
|
|
9
9
|
INVALID_BASE_URL: "Configuration Error: BaseUrl must be a non-empty valid URL string.",
|
|
10
|
+
INVALID_CLAIMING_BASE_URL: "Configuration Error: claimingBaseUrl must be a non-empty valid URL string.",
|
|
11
|
+
CLAIMING_NOT_CONFIGURED: "Configuration Error: claimingBaseUrl is not configured. Pass it to ESPRMBase.configure to use ESPRMClaim.",
|
|
10
12
|
};
|
|
11
13
|
const validationErrorMessages = {
|
|
12
14
|
MISSING_LOGIN_PASSWORD: "Validation Error: Password is required.",
|
|
@@ -18,6 +20,8 @@ const storageAdapterErrorMessages = {
|
|
|
18
20
|
};
|
|
19
21
|
const apiCallValidationErrorMessages = {
|
|
20
22
|
MISSING_NODE_ID: "ESPAPICallValidationError: Node ID is required.",
|
|
23
|
+
MISSING_NODE_IDS: "ESPAPICallValidationError: At least one node ID is required.",
|
|
24
|
+
TOO_MANY_NODE_IDS: "ESPAPICallValidationError: Too many node IDs; at most 25 are allowed per request.",
|
|
21
25
|
MISSING_OTA_IMAGE_ID: "ESPAPICallValidationError: OTA image ID is required.",
|
|
22
26
|
MISSING_ARCHIVE_FLAG: "ESPAPICallValidationError: Archive flag is required and must be a boolean.",
|
|
23
27
|
MISSING_OTA_JOB_ID: "ESPAPICallValidationError: OTA job ID is required.",
|
|
@@ -54,6 +58,11 @@ const apiCallValidationErrorMessages = {
|
|
|
54
58
|
MISSING_BATCH_ID: "ESPAPICallValidationError: Batch ID is required.",
|
|
55
59
|
MISSING_CANCEL_COMMAND_SCOPE: "ESPAPICallValidationError: Request ID or node ID is required.",
|
|
56
60
|
CMD_ID_REQUIRES_NODE_ID: "ESPAPICallValidationError: Command ID can only be used together with a node ID.",
|
|
61
|
+
MISSING_COMMON_CUSTOM_DATA_NAME: "ESPAPICallValidationError: Common custom data name is required.",
|
|
62
|
+
MISSING_COMMON_CUSTOM_DATA_VALUE: "ESPAPICallValidationError: Common custom data value is required. Use deleteCommonCustomData to delete an entry.",
|
|
63
|
+
MISSING_MAC_ADDRESS: "ESPAPICallValidationError: MAC address is required (12 uppercase hex characters, no separators).",
|
|
64
|
+
MISSING_CLAIM_PLATFORM: "ESPAPICallValidationError: Claim platform is required.",
|
|
65
|
+
MISSING_CSR: "ESPAPICallValidationError: Certificate signing request (CSR) is required.",
|
|
57
66
|
};
|
|
58
67
|
const tokenErrorMessages = {
|
|
59
68
|
MISSING_ACCESS_TOKEN: "ESPTokenError: Access token is missing. User needs to authenticate.",
|
|
@@ -11,12 +11,21 @@ class ConfigValidator {
|
|
|
11
11
|
static validateConfig(config) {
|
|
12
12
|
ConfigValidator.validateConfigObject(config);
|
|
13
13
|
ConfigValidator.validateBaseUrl(config.baseUrl);
|
|
14
|
+
ConfigValidator.validateClaimingBaseUrl(config.claimingBaseUrl);
|
|
14
15
|
}
|
|
15
16
|
static validateConfigObject(config) {
|
|
16
17
|
if (!isValidObject(config)) {
|
|
17
18
|
throw new ESPConfigError(ConfigErrorCodes.INVALID_CONFIG_OBJECT);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
static validateClaimingBaseUrl(claimingBaseUrl) {
|
|
22
|
+
if (claimingBaseUrl === undefined) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!isNonEmptyString(claimingBaseUrl) || !isValidUrl(claimingBaseUrl)) {
|
|
26
|
+
throw new ESPConfigError(ConfigErrorCodes.INVALID_CLAIMING_BASE_URL);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
20
29
|
static validateBaseUrl(baseUrl) {
|
|
21
30
|
if (!isNonEmptyString(baseUrl) || !isValidUrl(baseUrl)) {
|
|
22
31
|
throw new ESPConfigError(ConfigErrorCodes.INVALID_BASE_URL);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Shell class for the standalone ESP RainMaker claiming service.
|
|
8
|
+
* Requires `claimingBaseUrl` in {@link ESPRMBase.configure}.
|
|
9
|
+
* Methods are added via prototype augmentation in methods/ESPRMClaim/*.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ESPRMClaim {
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { DeleteCommonCustomDataRequest } from "../../types/common_custom_data.js";
|
|
7
|
+
import { ESPAPISuccessResponse } from "../../types/api.js";
|
|
8
|
+
declare module "../../ESPRMAdminCommonCustomData.js" {
|
|
9
|
+
interface ESPRMAdminCommonCustomData {
|
|
10
|
+
/**
|
|
11
|
+
* Deletes a common custom data entry.
|
|
12
|
+
*
|
|
13
|
+
* The backend has no DELETE method for this resource; an entry is deleted
|
|
14
|
+
* by sending `PUT admin/common_custom_data` with `value: null`.
|
|
15
|
+
*
|
|
16
|
+
* @param params - The name of the entry to delete.
|
|
17
|
+
* @returns A success response confirming the entry was deleted.
|
|
18
|
+
* @throws ESPAPICallValidationError when `name` is empty.
|
|
19
|
+
*/
|
|
20
|
+
deleteCommonCustomData(params: DeleteCommonCustomDataRequest): Promise<ESPAPISuccessResponse>;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -8,10 +8,15 @@ import { ESPAPISuccessResponse } from "../../types/api.js";
|
|
|
8
8
|
declare module "../../ESPRMAdminCommonCustomData.js" {
|
|
9
9
|
interface ESPRMAdminCommonCustomData {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Adds or updates a common custom data entry shared across users.
|
|
12
|
+
*
|
|
13
|
+
* JSON object values are deep merged into the stored object; other value
|
|
14
|
+
* types replace it. See {@link SetCommonCustomDataRequest}.
|
|
12
15
|
*
|
|
13
16
|
* @param params - The common custom data payload to set.
|
|
14
17
|
* @returns A success response confirming the data was set.
|
|
18
|
+
* @throws ESPAPICallValidationError when `name` is empty, or when `value`
|
|
19
|
+
* is `null` or `undefined` (the backend would delete the entry).
|
|
15
20
|
*/
|
|
16
21
|
setCommonCustomData(params: SetCommonCustomDataRequest): Promise<ESPAPISuccessResponse>;
|
|
17
22
|
}
|
|
@@ -10,6 +10,11 @@ declare module "../../ESPRMAdminEventFilter.js" {
|
|
|
10
10
|
/**
|
|
11
11
|
* Updates an existing event filter configuration.
|
|
12
12
|
*
|
|
13
|
+
* `enabled_for_integrations` adds or removes integrations instead of
|
|
14
|
+
* replacing the stored list; see {@link UpdateEventFilterRequest}. Omit it
|
|
15
|
+
* to change only `enabled`. Fails with error code `113109` when the
|
|
16
|
+
* mapping does not exist (this call never creates one).
|
|
17
|
+
*
|
|
13
18
|
* @param params - The updated event filter properties.
|
|
14
19
|
* @returns A success response confirming the event filter was updated.
|
|
15
20
|
*/
|
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { ActivateDeactivateNodesParams } from "../../types/node.js";
|
|
7
|
-
import { ESPAPISuccessResponse } from "../../types/api.js";
|
|
6
|
+
import { ActivateDeactivateNodesParams, ActivateDeactivateNodesResponse } from "../../types/node.js";
|
|
8
7
|
declare module "../../ESPRMAdminNode.js" {
|
|
9
8
|
interface ESPRMAdminNode {
|
|
10
9
|
/**
|
|
11
|
-
* Activates or deactivates nodes
|
|
10
|
+
* Activates or deactivates up to 25 nodes in one request. Supported only
|
|
11
|
+
* on private (customer) deployments.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* The backend returns a single success when every node has the same
|
|
14
|
+
* outcome, and a 207 response with per-node results when they differ.
|
|
15
|
+
*
|
|
16
|
+
* @param params - Node IDs and whether to activate or deactivate them.
|
|
17
|
+
* @returns A success response, or per-node results on mixed outcomes.
|
|
15
18
|
*/
|
|
16
|
-
activateDeactivateNodes(params: ActivateDeactivateNodesParams): Promise<
|
|
19
|
+
activateDeactivateNodes(params: ActivateDeactivateNodesParams): Promise<ActivateDeactivateNodesResponse>;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ESPAPISuccessResponse } from "../../types/api.js";
|
|
7
|
+
declare module "../../ESPRMAdminNode.js" {
|
|
8
|
+
interface ESPRMAdminNode {
|
|
9
|
+
/**
|
|
10
|
+
* Permanently deletes a node: its IoT certificates and thing, its data,
|
|
11
|
+
* and its user and group mappings. Cannot be undone. Supported only on
|
|
12
|
+
* public deployments; the backend accepts one node per request.
|
|
13
|
+
*
|
|
14
|
+
* @param nodeId - The ID of the node to delete.
|
|
15
|
+
* @returns A success response confirming the node was deleted.
|
|
16
|
+
*/
|
|
17
|
+
deleteNode(nodeId: string): Promise<ESPAPISuccessResponse>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -11,7 +11,8 @@ declare module "../../ESPRMAdminWebhook.js" {
|
|
|
11
11
|
* Retrieves the list of configured webhook integrations.
|
|
12
12
|
*
|
|
13
13
|
* @param params - Optional filtering parameters for the webhook integrations query.
|
|
14
|
-
* @returns The response containing webhook integration details
|
|
14
|
+
* @returns The response containing webhook integration details in
|
|
15
|
+
* `integration_info_list`, which is `null` when none are configured.
|
|
15
16
|
*/
|
|
16
17
|
getWebhookIntegrations(params?: GetWebhookIntegrationsParams): Promise<GetWebhookIntegrationsResponse>;
|
|
17
18
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { InitiateClaimRequest, InitiateClaimResponse } from "../../types/claim.js";
|
|
7
|
+
declare module "../../ESPRMClaim.js" {
|
|
8
|
+
interface ESPRMClaim {
|
|
9
|
+
/**
|
|
10
|
+
* Starts authenticated claiming of a node for the signed in user.
|
|
11
|
+
* The claim expires a few minutes after it is created, so call
|
|
12
|
+
* {@link ESPRMClaim.verifyClaim} promptly.
|
|
13
|
+
*
|
|
14
|
+
* @param params - MAC address and platform of the node.
|
|
15
|
+
* @returns The node ID assigned to the node.
|
|
16
|
+
* @throws ESPConfigError `CLAIMING_NOT_CONFIGURED` without `claimingBaseUrl`.
|
|
17
|
+
* @throws ESPAPICallValidationError when `mac_addr` or `platform` is empty.
|
|
18
|
+
*/
|
|
19
|
+
initiateClaim(params: InitiateClaimRequest): Promise<InitiateClaimResponse>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { VerifyClaimOptions, VerifyClaimRequest, VerifyClaimResponse } from "../../types/claim.js";
|
|
7
|
+
declare module "../../ESPRMClaim.js" {
|
|
8
|
+
interface ESPRMClaim {
|
|
9
|
+
/**
|
|
10
|
+
* Completes a claim started with {@link ESPRMClaim.initiateClaim} by
|
|
11
|
+
* submitting the node's CSR, and returns the signed node certificate.
|
|
12
|
+
*
|
|
13
|
+
* @param params - CSR plus optional node policies and MQTT host request.
|
|
14
|
+
* @param options - Matter and Matter test CA flags.
|
|
15
|
+
* @returns The node certificate, and MQTT hosts when requested.
|
|
16
|
+
* @throws ESPConfigError `CLAIMING_NOT_CONFIGURED` without `claimingBaseUrl`.
|
|
17
|
+
* @throws ESPAPICallValidationError when `csr` is empty.
|
|
18
|
+
*/
|
|
19
|
+
verifyClaim(params: VerifyClaimRequest, options?: VerifyClaimOptions): Promise<VerifyClaimResponse>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -40,6 +40,7 @@ import "./ESPRMAdminMobilePlatform/index.js";
|
|
|
40
40
|
import "./ESPRMAdminPublishMessage/index.js";
|
|
41
41
|
import "./ESPRMAdminPassthrough/index.js";
|
|
42
42
|
import "./ESPRMAdminNodeCertificateCA/index.js";
|
|
43
|
+
import "./ESPRMClaim/index.js";
|
|
43
44
|
import "./ESPRMAdminWebhook/index.js";
|
|
44
45
|
import "./ESPRMAdminStatisticalService/index.js";
|
|
45
46
|
import "./ESPRMAdminMailFailure/index.js";
|
|
@@ -13,6 +13,12 @@ export declare class ESPRMAPIManager {
|
|
|
13
13
|
#private;
|
|
14
14
|
private constructor();
|
|
15
15
|
static initialize(config: ESPRMAPIManagerConfig): void;
|
|
16
|
+
/**
|
|
17
|
+
* Base URL of the claiming service set through `claimingBaseUrl`.
|
|
18
|
+
*
|
|
19
|
+
* @throws ESPConfigError `CLAIMING_NOT_CONFIGURED` when it was not configured.
|
|
20
|
+
*/
|
|
21
|
+
static getClaimingBaseUrl(): string;
|
|
16
22
|
/**
|
|
17
23
|
* Send a request with the current user's access token in the
|
|
18
24
|
* `Authorization` header, refreshing the token first if it has expired.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/** Request body for `POST claim/initiate` (authenticated claiming). */
|
|
7
|
+
export interface InitiateClaimRequest {
|
|
8
|
+
/** Node MAC address: 12 uppercase hex characters, no separators, e.g. `7CDFA100033B`. */
|
|
9
|
+
mac_addr: string;
|
|
10
|
+
/** Platform the node is claimed for, e.g. `ESP32` or `ESP32S3`. */
|
|
11
|
+
platform: string;
|
|
12
|
+
}
|
|
13
|
+
/** Response of `POST claim/initiate` for authenticated claiming. */
|
|
14
|
+
export interface InitiateClaimResponse {
|
|
15
|
+
/** Node ID assigned to the claimed node. */
|
|
16
|
+
node_id: string;
|
|
17
|
+
}
|
|
18
|
+
/** Request body for `POST claim/verify` (authenticated claiming). */
|
|
19
|
+
export interface VerifyClaimRequest {
|
|
20
|
+
/** PEM encoded certificate signing request for the node key, with `CN=<node_id>`. */
|
|
21
|
+
csr: string;
|
|
22
|
+
/** When true, the response also carries `mqtt_host` and `mqtt_cred_host`. */
|
|
23
|
+
send_mqtt_host?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Comma separated node policies to attach, e.g. `videostream`. The
|
|
26
|
+
* `mqtt` policy is always attached by the backend.
|
|
27
|
+
*/
|
|
28
|
+
node_policies?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Query options for `POST claim/verify`. */
|
|
31
|
+
export interface VerifyClaimOptions {
|
|
32
|
+
/** Issue a Matter compliant node certificate. Defaults to false. */
|
|
33
|
+
matter?: boolean;
|
|
34
|
+
/** Use the Matter test CA. Only sent when `matter` is true. */
|
|
35
|
+
test?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Response of `POST claim/verify`. */
|
|
38
|
+
export interface VerifyClaimResponse {
|
|
39
|
+
/** PEM encoded node certificate chain. */
|
|
40
|
+
certificate: string;
|
|
41
|
+
/** MQTT endpoint, present when `send_mqtt_host` was true. */
|
|
42
|
+
mqtt_host?: string;
|
|
43
|
+
/** MQTT credentials endpoint, present when `send_mqtt_host` was true. */
|
|
44
|
+
mqtt_cred_host?: string;
|
|
45
|
+
}
|
|
@@ -3,19 +3,46 @@
|
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Request body for adding or updating a common custom data entry.
|
|
8
|
+
*
|
|
9
|
+
* `PUT admin/common_custom_data` is an upsert with merge semantics:
|
|
10
|
+
* - When the stored value and `value` are both JSON objects, they are deep
|
|
11
|
+
* merged. Keys omitted from `value` are kept, and a nested `null` deletes
|
|
12
|
+
* that key.
|
|
13
|
+
* - Arrays, strings, numbers and booleans replace the stored value.
|
|
14
|
+
* - A `null` or missing `value` deletes the whole entry, so `value` must be
|
|
15
|
+
* defined here. Use `deleteCommonCustomData` to delete.
|
|
16
|
+
*/
|
|
7
17
|
export interface SetCommonCustomDataRequest {
|
|
8
18
|
/** Name of the custom data entry. */
|
|
9
19
|
name: string;
|
|
10
|
-
/** Value to assign to the custom data entry. */
|
|
20
|
+
/** Value to assign to the custom data entry. Must not be `null` or `undefined`. */
|
|
11
21
|
value: unknown;
|
|
12
22
|
}
|
|
23
|
+
/** Request for deleting a common custom data entry. */
|
|
24
|
+
export interface DeleteCommonCustomDataRequest {
|
|
25
|
+
/** Name of the custom data entry to delete. */
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
13
28
|
/** Parameters for retrieving common custom data. */
|
|
14
29
|
export interface GetCommonCustomDataParams {
|
|
15
30
|
/** Name of the custom data entry to retrieve. */
|
|
16
31
|
name?: string;
|
|
17
32
|
}
|
|
18
|
-
/**
|
|
19
|
-
export interface
|
|
20
|
-
|
|
33
|
+
/** A single common custom data entry. */
|
|
34
|
+
export interface CommonCustomDataItem {
|
|
35
|
+
/** Name of the custom data entry. */
|
|
36
|
+
name: string;
|
|
37
|
+
/** Stored value: a JSON object, array, string, number or boolean. */
|
|
38
|
+
value: unknown;
|
|
39
|
+
/** RBAC permissions attached to the entry, when any were set. */
|
|
40
|
+
perms?: unknown[];
|
|
21
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Response of `GET admin/common_custom_data`.
|
|
44
|
+
*
|
|
45
|
+
* Always an array: every entry when `name` is omitted, or a single-element
|
|
46
|
+
* array when `name` is given.
|
|
47
|
+
*/
|
|
48
|
+
export type GetCommonCustomDataResponse = CommonCustomDataItem[];
|
|
@@ -21,12 +21,21 @@ export interface ESPRMBaseConfig {
|
|
|
21
21
|
* `errorCode` is `REQUEST_TIMEOUT`. Defaults to 30000. Set to `0` to disable.
|
|
22
22
|
*/
|
|
23
23
|
timeoutMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Base URL of the standalone ESP RainMaker claiming service, e.g.
|
|
26
|
+
* `https://esp-claiming.rainmaker.espressif.com`. Required only for
|
|
27
|
+
* `ESPRMClaim`; the service is available on public deployments only.
|
|
28
|
+
* The user's access token is sent to this host, so only set it to a
|
|
29
|
+
* trusted Espressif claiming endpoint.
|
|
30
|
+
*/
|
|
31
|
+
claimingBaseUrl?: string;
|
|
24
32
|
}
|
|
25
33
|
/** Configuration for the ESPRMAPIManager. */
|
|
26
34
|
export interface ESPRMAPIManagerConfig {
|
|
27
35
|
baseUrl: string;
|
|
28
36
|
version: string;
|
|
29
37
|
timeoutMs?: number;
|
|
38
|
+
claimingBaseUrl?: string;
|
|
30
39
|
}
|
|
31
40
|
/** Configuration for an API request made through ESPRMAPIManager. */
|
|
32
41
|
export interface ESPRMRequestConfig {
|
|
@@ -24,10 +24,24 @@ export interface UpdateEventFilterRequest {
|
|
|
24
24
|
entity_id: string;
|
|
25
25
|
/** Type of entity. */
|
|
26
26
|
entity_type: string;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Whether this filter is enabled. When `enabled_for_integrations` is
|
|
29
|
+
* omitted or empty, this value is stored as sent. When it is non-empty,
|
|
30
|
+
* the backend derives `enabled` itself (see `enabled_for_integrations`).
|
|
31
|
+
*/
|
|
28
32
|
enabled: boolean;
|
|
29
|
-
/**
|
|
30
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Integrations to add or remove. This is **not** a replacement list:
|
|
35
|
+
* - omitted or `[]`: the stored list is kept unchanged.
|
|
36
|
+
* - with `enabled: true`: the listed integrations are added to the stored list.
|
|
37
|
+
* - with `enabled: false`: the listed integrations are removed from the stored list.
|
|
38
|
+
*
|
|
39
|
+
* When a non-empty list is sent, the backend overrides `enabled`: it becomes
|
|
40
|
+
* `false` if the resulting list is empty, otherwise `true`, except that a
|
|
41
|
+
* filter already stored as disabled (with a non-empty list) stays disabled.
|
|
42
|
+
* To set `enabled` explicitly, send a separate update without this field.
|
|
43
|
+
*/
|
|
44
|
+
enabled_for_integrations?: string[];
|
|
31
45
|
}
|
|
32
46
|
/** Parameters for listing event filters. */
|
|
33
47
|
export interface GetEventFiltersParams {
|
|
@@ -44,6 +44,7 @@ export * from "./mobile_platform.js";
|
|
|
44
44
|
export * from "./publish_message.js";
|
|
45
45
|
export * from "./passthrough.js";
|
|
46
46
|
export * from "./node_certificate_ca.js";
|
|
47
|
+
export * from "./claim.js";
|
|
47
48
|
export * from "./webhook.js";
|
|
48
49
|
export * from "./statistical_service.js";
|
|
49
50
|
export * from "./mail_failure.js";
|