Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,42 @@
import app from "../../crowdpower.app.mjs";

export default {
key: "crowdpower-create-customer-charge",
name: "Create Customer Charge",
description: "Create a charge for a user. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#d89820d6-5d65-4ff7-87ba-6cddb359d8f3)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
app,
userId: {
propDefinition: [
app,
"userId",
],
},
amount: {
propDefinition: [
app,
"amount",
],
},
},
async run({ $ }) {
const response = await this.app.createCustomerCharge({
$,
data: {
user_id: this.userId,
amount: this.amount,
},
});
$.export("$summary", response.success
? `Request succeeded with code ${response.code}`
: `Request failed with code ${response.code}`);
Comment on lines +37 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the summaries intended to be like this? Usually we use more specific wording in each action, rather than a generic "request succeeded" or "request failed"

return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import app from "../../crowdpower.app.mjs";

export default {
key: "crowdpower-create-customer-event",
name: "Create Customer Event",
description: "Create a new event related to a customer. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#63159fcd-7df3-46c5-ac83-eeb72678b650)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
app,
userId: {
propDefinition: [
app,
"userId",
],
},
customAttributes: {
propDefinition: [
app,
"customAttributes",
],
description: "Custom attributes of the event",
},
action: {
propDefinition: [
app,
"action",
],
},
},
async run({ $ }) {
const response = await this.app.createCustomerEvent({
$,
data: {
user_id: this.userId,
custom_attributes: this.customAttributes,
action: this.action,
},
});
$.export("$summary", response.success
? `Request succeeded with code ${response.code}`
: `Request failed with code ${response.code}`);
return response;
},
};
57 changes: 57 additions & 0 deletions components/crowdpower/actions/upsert-customer/upsert-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import app from "../../crowdpower.app.mjs";

export default {
key: "crowdpower-upsert-customer",
name: "Upsert Customer",
description: "Create or update a customer. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#9415bd14-59ab-47b1-b0ec-73826d9cb5db)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
app,
userId: {
propDefinition: [
app,
"userId",
],
description: "ID of the customer that will be created or updated",
},
email: {
propDefinition: [
app,
"email",
],
},
name: {
propDefinition: [
app,
"name",
],
},
customAttributes: {
propDefinition: [
app,
"customAttributes",
],
},
},
async run({ $ }) {
const response = await this.app.upsertCustomer({
$,
data: {
user_id: this.userId,
email: this.email,
name: this.name,
custom_attributes: this.customAttributes,
},
});
$.export("$summary", response.success
? `Request succeeded with code ${response.code}`
: `Request failed with code ${response.code}`);
return response;
},
};
77 changes: 73 additions & 4 deletions components/crowdpower/crowdpower.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,80 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "crowdpower",
propDefinitions: {},
propDefinitions: {
userId: {
type: "string",
label: "User ID",
description: "ID of the user",
},
amount: {
type: "string",
label: "Amount",
description: "Amount of the charge",
},
email: {
type: "string",
label: "Email",
description: "Email of the customer",
},
name: {
type: "string",
label: "Name",
description: "Name of the customer",
},
customAttributes: {
type: "object",
label: "Custom Attributes",
description: "Custom attributes",
},
action: {
type: "string",
label: "Action",
description: "Action related to the event",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://beacon.crowdpower.io/";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
"Authorization": `Bearer ${this.$auth.application_key}`,
...headers,
},
});
Comment on lines +39 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid https://...//path (double slash) by fixing base URL / path join.

Right now _baseUrl() ends with / and path begins with /, producing // in the final URL. Safer to join with new URL() (and drop the trailing slash).

 _baseUrl() {
-  return "https://beacon.crowdpower.io/";
+  return "https://beacon.crowdpower.io";
 },
 async _makeRequest(opts = {}) {
   const {
     $ = this,
     path,
     headers,
     ...otherOpts
   } = opts;
+  if (!path) {
+    throw new Error("Missing required `path` in _makeRequest()");
+  }
   return axios($, {
     ...otherOpts,
-    url: this._baseUrl() + path,
+    url: new URL(path, this._baseUrl()).toString(),
     headers: {
       "Authorization": `Bearer ${this.$auth.application_key}`,
       ...headers,
     },
   });
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_baseUrl() {
return "https://beacon.crowdpower.io/";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
"Authorization": `Bearer ${this.$auth.application_key}`,
...headers,
},
});
_baseUrl() {
return "https://beacon.crowdpower.io";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
if (!path) {
throw new Error("Missing required `path` in _makeRequest()");
}
return axios($, {
...otherOpts,
url: new URL(path, this._baseUrl()).toString(),
headers: {
"Authorization": `Bearer ${this.$auth.application_key}`,
...headers,
},
});
},
🤖 Prompt for AI Agents
In components/crowdpower/crowdpower.app.mjs around lines 39 to 56, the
_baseUrl() returns a string with a trailing slash and _makeRequest concatenates
it with path which may start with a leading slash, producing a double-slash in
the final URL; fix by returning the base URL without the trailing slash or by
normalizing the join using new URL(path, this._baseUrl()) so the path and base
are combined safely (or strip a leading slash from path before concatenation)
and ensure axios receives a single well-formed URL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw the CodeRabbit comment here is correct, please fix the base URL or the endpoints, they're generating a double slash.

},
async createCustomerCharge(args = {}) {
return this._makeRequest({
path: "/charges",
method: "post",
...args,
});
},
async upsertCustomer(args = {}) {
return this._makeRequest({
path: "/customers",
method: "post",
...args,
});
},
async createCustomerEvent(args = {}) {
return this._makeRequest({
path: "/events",
method: "post",
...args,
});
},
},
};
5 changes: 4 additions & 1 deletion components/crowdpower/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/crowdpower",
"version": "0.0.4",
"version": "0.1.0",
"description": "Pipedream CrowdPower Components",
"main": "crowdpower.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.8"
}
}
Loading