Skip to content

New Components - channable #17630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 16, 2025
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
@@ -0,0 +1,56 @@
import channable from "../../channable.app.mjs";

export default {
key: "channable-list-stock-updates",
name: "List Stock Updates",
description: "List stock updates for a company and project. [See the documentation](https://api.channable.com/v1/docs#tag/stock_updates/operation/get_stock_updates_companies__company_id__projects__project_id__offers_get)",
version: "0.0.1",
type: "action",
props: {
channable,
search: {
type: "string",
label: "Search",
description: "A text based search query",
optional: true,
},
startDate: {
type: "string",
label: "Start Date",
description: "The start date of the stock updates",
optional: true,
},
endDate: {
type: "string",
label: "End Date",
description: "The end date of the stock updates",
optional: true,
},
max: {
type: "integer",
label: "Max",
description: "The maximum number of stock updates to return",
default: 100,
optional: true,
},
},
async run({ $ }) {
const stockUpdates = await this.channable.getPaginatedResources({
fn: this.channable.listStockUpdates,
args: {
$,
params: {
search: this.search,
start_date: this.startDate,
end_date: this.endDate,
},
max: this.max,
},
resourceKey: "offers",
});
$.export("$summary", `Found ${stockUpdates.length} stock update${stockUpdates.length === 1
? ""
: "s"}`);
return stockUpdates;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import channable from "../../channable.app.mjs";

export default {
key: "channable-update-stock-update",
name: "Update Stock Update",
description: "Update a stock update for a company and project. [See the documentation](https://api.channable.com/v1/docs#tag/stock_updates/operation/stock_updates_update_companies__company_id__projects__project_id__stock_updates_post)",
version: "0.0.1",
type: "action",
props: {
channable,
stockUpdateId: {
propDefinition: [
channable,
"stockUpdateId",
],
},
stock: {
type: "integer",
label: "Stock",
description: "Whole new stock value for the item, not a delta",
},
title: {
type: "string",
label: "Title",
description: "The title of the stock update",
},
gtin: {
type: "string",
label: "GTIN",
description: "The GTIN of the item",
},
},
async run({ $ }) {
const response = await this.channable.updateStockUpdate({
$,
data: [
{
id: this.stockUpdateId,
stock: this.stock,
title: this.title,
gtin: this.gtin,
},
],
});
$.export("$summary", `Updated stock update ${this.stockUpdateId}`);
return response;
},
};
92 changes: 88 additions & 4 deletions components/channable/channable.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,95 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "channable",
propDefinitions: {},
propDefinitions: {
stockUpdateId: {
type: "string",
label: "Stock Update ID",
description: "The ID of a stock update",
async options({ page }) {
const { offers } = await this.listStockUpdates({
params: {
limit: 100,
offset: page * 100,
},
});
return offers?.map((offer) => ({
label: offer.label,
value: offer.id,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.channable.com/v1";
},
_companyId() {
return this.$auth.company_id;
},
_projectId() {
return this.$auth.project_id;
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.api_token}`,
},
...opts,
});
},
listStockUpdates(opts = {}) {
return this._makeRequest({
path: `/companies/${this._companyId()}/projects/${this._projectId()}/offers`,
...opts,
});
},
updateStockUpdate(opts = {}) {
return this._makeRequest({
path: `/companies/${this._companyId()}/projects/${this._projectId()}/stock_updates`,
method: "POST",
...opts,
});
},
async *paginate({
fn, args, resourceKey, max,
}) {
args = {
...args,
params: {
...args?.params,
limit: 100,
offset: 0,
},
};
let total, count = 0;
do {
const response = await fn(args);
const items = response[resourceKey];
total = items?.length;
if (!total) {
return;
}
for (const item of items) {
yield item;
if (max && ++count >= max) {
return;
}
}
args.params.offset += args.params.limit;
} while (total === args.params.limit);
},
async getPaginatedResources(opts) {
const resources = [];
for await (const resource of this.paginate(opts)) {
resources.push(resource);
}
return resources;
},
},
};
7 changes: 5 additions & 2 deletions components/channable/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/channable",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Channable Components",
"main": "channable.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
84 changes: 84 additions & 0 deletions components/channable/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import channable from "../../channable.app.mjs";
import {
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
} from "@pipedream/platform";

export default {
props: {
channable,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs");
},
_setLastTs(ts) {
this.db.set("lastTs", ts);
},
getResourceKey() {
return "offers";
},
async processEvent(max) {
const lastTs = this._getLastTs();
let maxTs = lastTs;
const tsField = this.getTsField();

const results = await this.channable.paginate({
fn: this.getResourceFn(),
args: {
params: {
last_modified_after: lastTs,
},
},
resourceKey: this.getResourceKey(),
});

let items = [];
for await (const result of results) {
const ts = result[tsField];
if (!maxTs || Date.parse(ts) > Date.parse(maxTs)) {
maxTs = ts;
}
items.push(result);
}

if (!items.length) {
return;
}

this._setLastTs(maxTs);

if (max && items.length > max) {
items = items.slice(0, max);
}

items.forEach((item) => {
const meta = this.generateMeta(item);
this.$emit(item, meta);
});
},
getResourceFn() {
throw new ConfigurationError("getResourceFn must be implemented");
},
getTsField() {
throw new ConfigurationError("getTsField must be implemented");
},
generateMeta() {
throw new ConfigurationError("generateMeta must be implemented");
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
async run() {
await this.processEvent();
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import common from "../common/base.mjs";

export default {
...common,
key: "channable-new-stock-update-created",
name: "New Stock Update Created",
description: "Emit new event when a new stock update is created. [See the documentation](https://api.channable.com/v1/docs#tag/stock_updates/operation/get_stock_updates_companies__company_id__projects__project_id__offers_get)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.channable.listStockUpdates;
},
getTsField() {
return "created";
},
generateMeta(item) {
return {
id: item.id,
summary: `New stock update created: ${item.id}`,
ts: Date.parse(item.created),
};
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import common from "../common/base.mjs";

export default {
...common,
key: "channable-stock-update-updated",
name: "Stock Update Updated",

Check warning on line 6 in components/channable/sources/stock-update-updated/stock-update-updated.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
description: "Emit new event when a stock update is updated. [See the documentation](https://api.channable.com/v1/docs#tag/stock_updates/operation/get_stock_updates_companies__company_id__projects__project_id__offers_get)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.channable.listStockUpdates;
},
getTsField() {
return "modified";
},
generateMeta(item) {
const ts = Date.parse(item.modified);
return {
id: `${item.id}-${ts}`,
summary: `Stock update updated: ${item.id}`,
ts,
};
},
},
};
2 changes: 1 addition & 1 deletion components/memento_database/memento_database.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/robopost/robopost.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));
},
},
};
};
Loading
Loading