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
18 changes: 18 additions & 0 deletions components/starloop/actions/list-ids/list-ids.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import app from "../../starloop.app.mjs";

export default {
key: "starloop-list-ids",
name: "List IDs",
description: "Returns your business id and a list of all profile id’s and names. [See the documentation](https://help.starloop.com/article/46-api-documentation)",
version: "0.0.1",
type: "action",
props: {
app,
},
run({ $: step }) {
return this.app.listIds({
step,
summary: () => "Successfully listed ids",
});
},
};
80 changes: 80 additions & 0 deletions components/starloop/actions/send-invite/send-invite.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import app from "../../starloop.app.mjs";

export default {
key: "starloop-send-invite",
name: "Send Invite",
description: "Creates a new recipient and sends a Starloop invite (Email | SMS | both) to your customer to leave a review. [See the documentation](https://help.starloop.com/article/46-api-documentation)",
version: "0.0.1",
type: "action",
props: {
app,
firstName: {
propDefinition: [
app,
"firstName",
],
},
email: {
propDefinition: [
app,
"email",
],
},
phone: {
propDefinition: [
app,
"phone",
],
},
businessId: {
propDefinition: [
app,
"businessId",
],
},
profileId: {
propDefinition: [
app,
"profileId",
],
},
testMode: {
propDefinition: [
app,
"testMode",
],
},
},
methods: {
sendInvite(args = {}) {
return this.app.post({
path: "/send_invite",
...args,
});
},
},
run({ $: step }) {
const {
sendInvite,
firstName,
email,
phone,
businessId,
profileId,
testMode,
} = this;

return sendInvite({
step,
params: {
first_name: firstName,
email,
phone,
business_id: businessId,
profile_id: profileId,
test_mode: testMode,
},
summary: () => "Successfully sent invite",
});
},
};
13 changes: 13 additions & 0 deletions components/starloop/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const SUMMARY_LABEL = "$summary";
const BASE_URL = "https://go.starloop.com";
const VERSION_PATH = "/api";
const LAST_CREATED_AT = "lastCreatedAt";
const DEFAULT_MAX = 600;

export default {
SUMMARY_LABEL,
BASE_URL,
VERSION_PATH,
DEFAULT_MAX,
LAST_CREATED_AT,
};
6 changes: 3 additions & 3 deletions components/starloop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pipedream/starloop",
"version": "0.0.1",
"description": "Pipedream Starloop Components",
"version": "0.1.0",
"description": "Pipedream Starloop Components",
"main": "starloop.app.mjs",
"keywords": [
"pipedream",
Expand All @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import app from "../../starloop.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
key: "starloop-new-profile-created",
name: "New Profile Created",
description: "This source triggers when a new profile is created in Starloop.",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
app,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
async run() {
const { profile_ids: profiles } = await this.app.listIds();

profiles.forEach((profile) => {
this.$emit(profile, {
id: profile.id,
summary: `New Profile: ${profile.id}`,
ts: Date.now(),
});
});
},
};
124 changes: 119 additions & 5 deletions components/starloop/starloop.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,125 @@
import {
axios, ConfigurationError,
} from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "starloop",
propDefinitions: {},
propDefinitions: {
businessId: {
type: "string",
label: "Business ID",
description: "The ID of the business",
optional: true,
async options() {
const { business_id: businessId } = await this.listIds();
return [
businessId,
];
},
},
profileId: {
type: "string",
label: "Profile ID",
description: "The ID of the profile",
optional: true,
async options() {
const { profile_ids: profileIds } = await this.listIds();
return profileIds.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
firstName: {
type: "string",
label: "First Name",
description: "The first name of the recipient",
},
email: {
type: "string",
label: "Email",
description: "The email of the recipient",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "The phone number of the recipient",
optional: true,
},
testMode: {
type: "boolean",
label: "Test Mode",
description: "If set to true, the invite will not be sent",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
exportSummary(step) {
if (!step?.export) {
throw new ConfigurationError("The summary method should be bind to the step object aka `$`");
}
return (msg = "") => step.export(constants.SUMMARY_LABEL, msg);
},
getUrl(path) {
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
},
getParams(params = {}) {
return {
token: this.$auth.api_key,
...params,
};
},
getHeaders(headers = {}) {
return {
"Content-Type": "application/x-www-form-urlencoded",
"accept": "application/json",
...headers,
};
},
async makeRequest({
step = this, path, headers, params, summary, ...args
} = {}) {
const {
getUrl,
getParams,
getHeaders,
} = this;

const config = {
url: getUrl(path),
params: getParams(params),
headers: getHeaders(headers),
...args,
};

const response = await axios(step, config);

if (typeof summary === "function") {
this.exportSummary(step)(summary(response));
}

if (response.error_msg) {
throw new Error(JSON.stringify(response, null, 2));
}

return response;
},
post(args = {}) {
return this.makeRequest({
method: "post",
...args,
});
},
listIds(args = {}) {
return this.post({
path: "/list_ids",
...args,
});
},
},
};
};
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.