Skip to content

Commit 53da41b

Browse files
committed
Add new event source and refactor API paths in OneLogin component
- Introduced a new event source for emitting events in OneLogin. - Added event type selection with dynamic options based on available event types. - Refactored API paths in the OneLogin app to remove redundant '/api' prefix. - Implemented a utility function to convert snake_case to Title Case for better display of event types.
1 parent 4844cc4 commit 53da41b

File tree

5 files changed

+71
-29
lines changed

5 files changed

+71
-29
lines changed

components/onelogin/common/utils.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ export const parseObject = (obj) => {
2222
}
2323
return obj;
2424
};
25+
26+
export const snakeCaseToTitleCase = (s) =>
27+
s.toLowerCase()
28+
.replace(/^_*(.)|_+(.)/g, (s, c, d) => c
29+
? c.toUpperCase()
30+
: " " + d.toUpperCase());

components/onelogin/onelogin.app.mjs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
STATE_OPTIONS,
66
STATUS_OPTIONS,
77
} from "./common/constants.mjs";
8+
import { snakeCaseToTitleCase } from "./common/utils.mjs";
89

910
export default {
1011
type: "app",
@@ -81,6 +82,25 @@ export default {
8182
}));
8283
},
8384
},
85+
eventType: {
86+
type: "string",
87+
label: "Event Type",
88+
description: "The type of event to emit",
89+
async options({ page }) {
90+
const { data } = await this.listEventTypes({
91+
params: {
92+
page,
93+
},
94+
});
95+
96+
return data.map(({
97+
id: value, name, description,
98+
}) => ({
99+
label: `${snakeCaseToTitleCase(name)}: ${description}`,
100+
value,
101+
}));
102+
},
103+
},
84104
username: {
85105
type: "string",
86106
label: "Username",
@@ -230,7 +250,7 @@ export default {
230250
},
231251
methods: {
232252
_baseUrl() {
233-
return `https://${this.$auth.subdomain}.onelogin.com`;
253+
return `https://${this.$auth.subdomain}.onelogin.com/api`;
234254
},
235255
_headers() {
236256
return {
@@ -248,26 +268,26 @@ export default {
248268
},
249269
listGroups(opts = {}) {
250270
return this._makeRequest({
251-
path: "/api/1/groups",
271+
path: "/1/groups",
252272
...opts,
253273
});
254274
},
255275
listRoles(opts = {}) {
256276
return this._makeRequest({
257-
path: "/api/1/roles",
277+
path: "/1/roles",
258278
...opts,
259279
});
260280
},
261281
listUsers(opts = {}) {
262282
return this._makeRequest({
263-
path: "/api/2/users",
283+
path: "/2/users",
264284
...opts,
265285
});
266286
},
267287
createUser(opts = {}) {
268288
return this._makeRequest({
269289
method: "POST",
270-
path: "/api/2/users",
290+
path: "/2/users",
271291
...opts,
272292
});
273293
},
@@ -276,13 +296,19 @@ export default {
276296
}) {
277297
return this._makeRequest({
278298
method: "PUT",
279-
path: `/api/2/users/${userId}`,
299+
path: `/2/users/${userId}`,
280300
...opts,
281301
});
282302
},
283303
listEvents(opts = {}) {
284304
return this._makeRequest({
285-
path: "/api/1/events",
305+
path: "/1/events",
306+
...opts,
307+
});
308+
},
309+
listEventTypes(opts = {}) {
310+
return this._makeRequest({
311+
path: "/1/events/types",
286312
...opts,
287313
});
288314
},
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "onelogin-new-event",
7+
name: "New Event",
8+
description: "Emit new event when a selected event occurs in OneLogin. [See the documentation](https://developers.onelogin.com/api-docs/1/events/get-events)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
...common.props,
14+
eventType: {
15+
propDefinition: [
16+
common.props.onelogin,
17+
"eventType",
18+
],
19+
withLabel: true,
20+
},
21+
},
22+
methods: {
23+
...common.methods,
24+
getEventType() {
25+
return this.eventType.value;
26+
},
27+
getSummary() {
28+
return `New event: ${this.eventType.label}`;
29+
},
30+
},
31+
sampleEmit,
32+
};

components/onelogin/sources/new-login-attempt/test-event.mjs renamed to components/onelogin/sources/new-event/test-event.mjs

File renamed without changes.

components/onelogin/sources/new-login-attempt/new-login-attempt.mjs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)