@adobe/spacecat-shared-splunk-client 1.0.29 → 1.1.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 CHANGED
@@ -1,3 +1,16 @@
1
+ ## [@adobe/spacecat-shared-splunk-client-v1.1.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-splunk-client-v1.0.30...@adobe/spacecat-shared-splunk-client-v1.1.0) (2026-02-27)
2
+
3
+ ### Features
4
+
5
+ * add slack for redirects ([#1365](https://github.com/adobe/spacecat-shared/issues/1365)) ([7b8176e](https://github.com/adobe/spacecat-shared/commit/7b8176ec7e6788b60da7b76f8924c71f4ef0b26a))
6
+
7
+ # [@adobe/spacecat-shared-splunk-client-v1.0.30](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-splunk-client-v1.0.29...@adobe/spacecat-shared-splunk-client-v1.0.30) (2026-01-29)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * **deps:** update dependency @adobe/helix-universal to v5.4.0 ([#1295](https://github.com/adobe/spacecat-shared/issues/1295)) ([5c1595b](https://github.com/adobe/spacecat-shared/commit/5c1595bd7cba9b7053da867b8f46e302f8683eba))
13
+
1
14
  # [@adobe/spacecat-shared-splunk-client-v1.0.29](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-splunk-client-v1.0.28...@adobe/spacecat-shared-splunk-client-v1.0.29) (2025-11-28)
2
15
 
3
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-splunk-client",
3
- "version": "1.0.29",
3
+ "version": "1.1.0",
4
4
  "description": "Shared modules of the Spacecat Services - Splunk Client",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/fetch": "4.2.3",
38
- "@adobe/helix-universal": "5.3.0",
38
+ "@adobe/helix-universal": "5.4.0",
39
39
  "@adobe/spacecat-shared-utils": "1.81.1",
40
40
  "xml-js": "1.6.11"
41
41
  },
package/src/index.d.ts CHANGED
@@ -22,6 +22,14 @@ export interface SplunkAPIOptions {
22
22
  mode: string;
23
23
  output: string;
24
24
  }
25
+ export type SplunkLoginResult =
26
+ | { sessionId: string; cookie: string }
27
+ | { error: unknown };
28
+
29
+ export interface SplunkOneshotResponse {
30
+ results?: Array<Record<string, unknown>>;
31
+ [key: string]: unknown;
32
+ }
25
33
 
26
34
  export default class SplunkAPIClient {
27
35
  /**
@@ -45,7 +53,13 @@ export default class SplunkAPIClient {
45
53
  * @param password
46
54
  */
47
55
  login(username?: string, password?: string):
48
- Promise<{ result: object }>;
56
+ Promise<SplunkLoginResult>;
57
+
58
+ /**
59
+ * Execute an ad-hoc Splunk oneshot search.
60
+ * Throws on error.
61
+ */
62
+ oneshotSearch(searchString: string): Promise<SplunkOneshotResponse>;
49
63
 
50
64
  /**
51
65
  * Asynchronous method to check for Not Found errors
@@ -56,5 +70,8 @@ export default class SplunkAPIClient {
56
70
  * @param password
57
71
  */
58
72
  getNotFounds(minutes?: number, username?: string, password?: string):
59
- Promise<{ result: object }>;
73
+ Promise<
74
+ | { results: Array<Record<string, unknown>> }
75
+ | { error: unknown }
76
+ >;
60
77
  }
package/src/index.js CHANGED
@@ -144,4 +144,51 @@ export default class SplunkAPIClient {
144
144
 
145
145
  return returnObj;
146
146
  }
147
+
148
+ /**
149
+ * Execute an ad-hoc Splunk oneshot search and return the JSON payload.
150
+ *
151
+ * @param {string} searchString SPL query string (e.g. `search index=... | stats ...`)
152
+ * @returns {Promise<object>} Splunk oneshot search response JSON
153
+ */
154
+ async oneshotSearch(searchString) {
155
+ if (typeof searchString !== 'string' || searchString.trim().length === 0) {
156
+ throw new Error('Missing searchString');
157
+ }
158
+
159
+ // Additive behavior: reuse existing login state, otherwise login now.
160
+ if (!this.loginObj) {
161
+ this.loginObj = await this.login();
162
+ }
163
+ if (this.loginObj?.error) {
164
+ const err = this.loginObj.error;
165
+ this.loginObj = null;
166
+ throw (err instanceof Error ? err : new Error(String(err)));
167
+ }
168
+
169
+ const queryBody = new URLSearchParams({
170
+ search: searchString,
171
+ adhoc_search_level: 'fast',
172
+ exec_mode: 'oneshot',
173
+ output_mode: 'json',
174
+ });
175
+
176
+ const url = `${this.apiBaseUrl}/servicesNS/admin/search/search/jobs`;
177
+ const response = await this.fetchAPI(url, {
178
+ method: 'POST',
179
+ headers: {
180
+ 'Content-Type': 'application/json',
181
+ Authorization: `Splunk ${this.loginObj.sessionId}`,
182
+ Cookie: this.loginObj.cookie,
183
+ },
184
+ body: queryBody,
185
+ });
186
+
187
+ if (response.status !== 200) {
188
+ const body = await response.text();
189
+ throw new Error(`Splunk oneshot search failed. Status: ${response.status}. Body: ${body}`);
190
+ }
191
+
192
+ return response.json();
193
+ }
147
194
  }