Skip to content

Commit b4c5190

Browse files
authored
Merge branch 'master' into issue-14132
2 parents b5c8861 + bfbec2e commit b4c5190

File tree

5 files changed

+147
-7
lines changed

5 files changed

+147
-7
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import l2s from "../../l2s.app.mjs";
3+
4+
export default {
5+
key: "l2s-create-shortened-url",
6+
name: "Create Shortened URL",
7+
description: "Generates a shortened URL utilizing L2S capabilities. [See the documentation](https://docs.l2s.is/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
l2s,
12+
url: {
13+
type: "string",
14+
label: "URL",
15+
description: "The URL to be shortened",
16+
},
17+
customKey: {
18+
type: "string",
19+
label: "Custom Key",
20+
description: "Custom key for the shortened URL",
21+
optional: true,
22+
},
23+
utmSource: {
24+
type: "string",
25+
label: "UTM Source",
26+
description: "UTM source parameter",
27+
optional: true,
28+
},
29+
utmMedium: {
30+
type: "string",
31+
label: "UTM Medium",
32+
description: "UTM medium parameter",
33+
optional: true,
34+
},
35+
utmCampaign: {
36+
type: "string",
37+
label: "UTM Campaign",
38+
description: "UTM campaign parameter",
39+
optional: true,
40+
},
41+
utmTerm: {
42+
type: "string",
43+
label: "UTM Term",
44+
description: "UTM term parameter",
45+
optional: true,
46+
},
47+
utmContent: {
48+
type: "string",
49+
label: "UTM Content",
50+
description: "UTM content parameter",
51+
optional: true,
52+
},
53+
title: {
54+
type: "string",
55+
label: "Title",
56+
description: "Title for the shortened URL",
57+
optional: true,
58+
},
59+
tags: {
60+
type: "string[]",
61+
label: "Tags",
62+
description: "Tags associated with the URL",
63+
optional: true,
64+
},
65+
},
66+
async run({ $ }) {
67+
const {
68+
l2s,
69+
tags,
70+
...data
71+
} = this;
72+
73+
if (tags) {
74+
data.tags = parseObject(tags);
75+
}
76+
77+
const { response: { data: response } } = await l2s.shortenUrl({
78+
$,
79+
data,
80+
});
81+
82+
const shortUrl = `https://l2s.is/${response.key}`;
83+
$.export("$summary", "URL shortened successfully");
84+
return {
85+
short_url: shortUrl,
86+
...response,
87+
};
88+
},
89+
};

components/l2s/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/l2s/l2s.app.mjs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "l2s",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return "https://api.l2s.is";
9+
},
10+
_headers() {
11+
return {
12+
Authorization: `Bearer ${this.$auth.api_key}`,
13+
};
14+
},
15+
_makeRequest({
16+
$ = this, path, ...opts
17+
}) {
18+
return axios($, {
19+
url: this._baseUrl() + path,
20+
headers: this._headers(),
21+
...opts,
22+
});
23+
},
24+
shortenUrl(opts = {}) {
25+
return this._makeRequest({
26+
method: "POST",
27+
path: "/url",
28+
...opts,
29+
});
930
},
1031
},
1132
};

components/l2s/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/l2s",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream L2S Components",
55
"main": "l2s.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)