Skip to content
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

New Components - tinyurl #15456

Merged
merged 3 commits into from
Feb 5, 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,74 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseObject } from "../../common/utils.mjs";
import tinyurl from "../../tinyurl.app.mjs";

export default {
key: "tinyurl-create-shortened-link",
name: "Create Shortened Link",
description: "Creates a new shortened link. [See the documentation]()",
version: "0.0.1",
type: "action",
props: {
tinyurl,
url: {
propDefinition: [
tinyurl,
"url",
],
},
domain: {
propDefinition: [
tinyurl,
"domain",
],
optional: true,
},
alias: {
propDefinition: [
tinyurl,
"alias",
],
optional: true,
},
tags: {
propDefinition: [
tinyurl,
"tags",
],
optional: true,
},
expiresAt: {
propDefinition: [
tinyurl,
"expiresAt",
],
optional: true,
},
description: {
type: "string",
label: "Description",
description: "The alias description",
optional: true,
},
},
async run({ $ }) {
try {
const response = await this.tinyurl.createTinyURL({
$,
data: {
url: this.url,
domain: this.domain,
alias: this.alias,
tags: parseObject(this.tags)?.join(","),
expires_at: this.expiresAt,
description: this.description,
},
});
$.export("$summary", `Created TinyURL: ${response.data.tiny_url}`);
return response;
} catch ({ response }) {
throw new ConfigurationError(response?.data?.errors[0]);
}
},
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { ConfigurationError } from "@pipedream/platform";
import tinyurl from "../../tinyurl.app.mjs";

export default {
key: "tinyurl-retrieve-link-analytics",
name: "Retrieve Link Analytics",
description: "Retrieves analytics for a specific TinyURL link, including total clicks, geographic breakdowns, and device types. [See the documentation]()",
version: "0.0.1",
type: "action",
props: {
tinyurl,
alert: {

Check warning on line 12 in components/tinyurl/actions/retrieve-link-analytics/retrieve-link-analytics.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 12 in components/tinyurl/actions/retrieve-link-analytics/retrieve-link-analytics.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: "This action is only allowed for paid accounts.",
},
domain: {
propDefinition: [
tinyurl,
"domain",
],
},
urls: {
propDefinition: [
tinyurl,
"urls",
({ domain }) => ({
domain,
}),
],
},
from: {
type: "string",
label: "From",
description: "The start datetime of analitics report",
},
to: {
type: "string",
label: "To",
description: "The end datetime of analitics report. Default is now",
optional: true,
},
tag: {
type: "string",
label: "Tag",
description: "Tag to get analytics for",
optional: true,
},
},
async run({ $ }) {
try {
const analytics = await this.tinyurl.retrieveAnalytics({
$,
params: {
from: this.from,
to: this.to,
alias: this.urls,
tag: this.tag,
},
});
$.export("$summary", `Retrieved analytics for link ${this.urls}`);
return analytics;
} catch ({ response }) {
throw new ConfigurationError(response?.data?.errors[0]);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseObject } from "../../common/utils.mjs";
import tinyurl from "../../tinyurl.app.mjs";

export default {
key: "tinyurl-update-link-metadata",
name: "Update Link Metadata",
description: "Updates the metadata of an existing TinyURL. [See the documentation]()",
version: "0.0.1",
type: "action",
props: {
tinyurl,
domain: {
propDefinition: [
tinyurl,
"domain",
],
},
urls: {
propDefinition: [
tinyurl,
"urls",
({ domain }) => ({
domain,
}),
],
},
newDomain: {
type: "string",
label: "New Domain",
description: "The new domain you would like to switch to",
optional: true,
},
newAlias: {
type: "string",
label: "New Alias",
description: "The new alias you would like to switch to",
optional: true,
},
newStats: {
type: "boolean",
label: "New Stats",
description: "Turns on/off the collection of click analytics",
optional: true,
},
newTags: {
type: "string[]",
label: "New Tags",
description: "Tags you would like this TinyURL to have. Overwrites the existing tags. **Paid accounts only**",
optional: true,
},
newExpiresAt: {
type: "string",
label: "New Expires At",
description: "TinyURL expiration in ISO8601 format. If not set so TinyURL never expires, **Paid accounts only**",
optional: true,
},
newDescription: {
type: "string",
label: "New Description",
description: "The new description",
optional: true,
},
},
async run({ $ }) {
try {
const response = await this.tinyurl.updateTinyURLMetadata({
$,
data: {
domain: this.domain,
alias: this.urls,
new_domain: this.newDomain,
new_alias: this.newAlias,
new_stats: this.newStats,
new_tags: parseObject(this.newTags),
new_expires_at: this.newExpiresAt,
new_description: this.newDescription,
},
});
$.export("$summary", `Updated TinyURL metadata for link: ${response.data.tiny_url}`);
return response;
} catch ({ response }) {
throw new ConfigurationError(response?.data?.errors[0]);
}
},
};
24 changes: 24 additions & 0 deletions components/tinyurl/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
18 changes: 18 additions & 0 deletions components/tinyurl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@pipedream/tinyurl",
"version": "0.1.0",
"description": "Pipedream TinyURL Components",
"main": "tinyurl.app.mjs",
"keywords": [
"pipedream",
"tinyurl"
],
"homepage": "https://pipedream.com/apps/tinyurl",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
62 changes: 62 additions & 0 deletions components/tinyurl/sources/new-link-created/new-link-created.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import tinyurl from "../../tinyurl.app.mjs";

export default {
key: "tinyurl-new-link-created",
name: "New Shortened URL Created",
description: "Emit new event when a new shortened URL is created.",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
tinyurl,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || 0;
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate();

const { data } = await this.tinyurl.listURLs({
type: "available",
params: {
from: lastDate,
},
});

if (data.length) {
if (maxResults && (data.length > maxResults)) {
data.length = maxResults;
}
this._setLastDate(data[0].created_at);
}

for (const item of data.reverse()) {
this.$emit(item, {
id: item.alias,
summary: `New TinyURL: ${item.tiny_url}`,
ts: Date.parse(item.created_at),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
Loading
Loading