Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/applicantstack/applicantstack.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/benchmarkone/benchmarkone.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/current_rms/current_rms.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/elastic_cloud/elastic_cloud.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/felt/felt.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/globalping/globalping.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/langfuse/langfuse.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/mailtrap/mailtrap.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/morgen/morgen.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
75 changes: 75 additions & 0 deletions components/motive/actions/find-user-details/find-user-details.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ConfigurationError } from "@pipedream/platform";
import { clearObj } from "../../common/util.mjs";
import motive from "../../motive.app.mjs";

export default {
key: "motive-find-user-details",
name: "Find User Details",
description: "Retrieve user details based on specific criteria. [See the documentation](https://developer.gomotive.com/reference/users-lookup)",
version: "0.0.1",
type: "action",
props: {
motive,
alert: {

Check warning on line 13 in components/motive/actions/find-user-details/find-user-details.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 13 in components/motive/actions/find-user-details/find-user-details.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "info",
content: "If you provide more than one prop, only one will be considered, the others will be ignored.",
},
username: {
type: "string",
label: "Username",
description: "Username to retrieve user details",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email to retrieve user details",
optional: true,
},
driverCompanyId: {
propDefinition: [
motive,
"driverCompanyId",
],
optional: true,
},
},
async run({ $ }) {
let response;
const criteria = [];

const {
username, email, driverCompanyId,
} = this;
if (!username && !email && !driverCompanyId) {
throw new Error("At least one of 'Username', 'Email', 'Driver Company Id' must be provided.");
}

if (username) criteria.push(`username: ${username}`);
if (email) criteria.push(`email: ${email}`);
if (driverCompanyId) criteria.push(`driverCompanyId: ${driverCompanyId}`);

try {
response = await this.motive.retrieveUserDetails({
$,
params: clearObj({
username,
email,
driver_company_id: driverCompanyId,
}),
});

} catch ({ response: { data } }) {
if (data.error_message === "user not found") {
response = {
user: null,
};
} else {
throw new ConfigurationError(data.error_message);
}
}
$.export("$summary", `Successfully retrieved user details for ${criteria.join(", ")}`);
return response;
},
};
16 changes: 16 additions & 0 deletions components/motive/common/util.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const clearObj = (obj) => {
return Object.entries(obj)
.filter(([
_,
v,
]) => (v != null && v != "" && _ != "$emit"))
.reduce((acc, [
k,
v,
]) => ({
...acc,
[k]: (!Array.isArray(v) && v === Object(v))
? clearObj(v)
: v,
}), {});
};
121 changes: 117 additions & 4 deletions components/motive/motive.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,124 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "motive",
propDefinitions: {},
propDefinitions: {
driverId: {
type: "string",
label: "Driver ID",
description: "Filter to a specific driver",
},
safetyCategory: {
type: "string",
label: "Safety Category",
description: "Filter to a specific safety category",
},
driverCompanyId: {
type: "string",
label: "Driver Company ID",
description: "Driver company ID to retrieve user details",
async options({ page }) {
const { users } = await this.listUsers({
params: {
page_no: page + 1,
role: "driver",
},
});

return users.map(({ user }) => ({
label: user.email || `${user.first_name} ${user.last_name}`,
value: user.driver_company_id,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.gomotive.com/v1";
},
_headers() {
return {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listHosViolations(opts = {}) {
return this._makeRequest({
method: "GET",
path: "/hos_violations",
...opts,
});
},
listUsers(opts = {}) {
return this._makeRequest({
path: "/users",
...opts,
});
},
createWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/company_webhooks",
...opts,
});
},
updateWebhook({
webhookId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/company_webhooks/${webhookId}`,
...opts,
});
},
listDriverPerformanceEvents(opts = {}) {
return this._makeRequest({
method: "GET",
path: "/driver_performance_events",
...opts,
});
},
retrieveUserDetails(opts = {}) {
return this._makeRequest({
method: "GET",
path: "/users/lookup",
...opts,
});
},
async *paginate({
fn, params = {}, fieldName, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.page = ++page;
const data = await fn({
params,
...opts,
});
const items = data[fieldName];
for (const d of items) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = items.length;

} while (hasMore);
},
},
};
8 changes: 6 additions & 2 deletions components/motive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/motive",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Motive Components",
"main": "motive.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3",
"uuid": "^11.0.4"
}
}
}
63 changes: 63 additions & 0 deletions components/motive/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import motive from "../../motive.app.mjs";

export default {
props: {
motive,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastId() {
return this.db.get("lastId") || 0;
},
_setLastId(lastId) {
this.db.set("lastId", lastId);
},
async emitEvent(maxResults = false) {
const lastId = this._getLastId();
const fieldName = this.getFieldName();

const response = this.motive.paginate({
fn: this.getFunction(),
fieldName: `${fieldName}s`,
});

let responseArray = [];
for await (const item of response) {
const data = item[fieldName];
if (data.id <= lastId) break;
responseArray.push(data);
}

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastId(responseArray[0].id);
}

for (const item of responseArray.reverse()) {
const data = item[fieldName];
this.$emit(data, {
id: data.id,
summary: this.getSummary(data),
ts: Date.parse(data.start_time || new Date()),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
Loading
Loading