Skip to content

Commit 52f33e9

Browse files
michelle0927lcaresia
authored andcommitted
New Components - lokalise (#14604)
* init * new components * pnpm-lock.yaml
1 parent e90eaad commit 52f33e9

File tree

13 files changed

+542
-59
lines changed

13 files changed

+542
-59
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import lokalise from "../../lokalise.app.mjs";
2+
3+
export default {
4+
key: "lokalise-create-project",
5+
name: "Create Project",
6+
description: "Initializes an empty project in Lokalise. [See the documentation](https://developers.lokalise.com/reference/create-a-project)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
lokalise,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "Name of the project",
15+
},
16+
description: {
17+
type: "string",
18+
label: "Description",
19+
description: "Description of the project",
20+
optional: true,
21+
},
22+
language: {
23+
propDefinition: [
24+
lokalise,
25+
"language",
26+
],
27+
optional: true,
28+
},
29+
projectType: {
30+
type: "string",
31+
label: "Project Type",
32+
description: "The type of project",
33+
options: [
34+
"localization_files",
35+
"paged_documents",
36+
],
37+
optional: true,
38+
},
39+
isSegmentationEnabled: {
40+
type: "boolean",
41+
label: "Is Segmentation Enabled",
42+
description: "Whether to enable Segmentation feature for project",
43+
optional: true,
44+
},
45+
},
46+
async run({ $ }) {
47+
const response = await this.lokalise.createProject({
48+
$,
49+
data: {
50+
name: this.name,
51+
description: this.description,
52+
base_lang_iso: this.language,
53+
project_type: this.projectType,
54+
is_segmentation_enabled: this.isSegmentationEnabled,
55+
},
56+
});
57+
$.export("$summary", `Successfully created project with ID: ${response.project_id}`);
58+
return response;
59+
},
60+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import lokalise from "../../lokalise.app.mjs";
2+
3+
export default {
4+
key: "lokalise-download-files",
5+
name: "Download Files",
6+
description: "Retrieves and downloads files from a specified Lokalise project. [See the documentation](https://developers.lokalise.com/reference/download-files)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
lokalise,
11+
projectId: {
12+
propDefinition: [
13+
lokalise,
14+
"projectId",
15+
],
16+
},
17+
fileFormat: {
18+
type: "string",
19+
label: "File Format",
20+
description: "File format (e.g. json, strings, xml). Must be file extension of any of the [supported file formats](https://docs.lokalise.com/en/collections/2909229-supported-file-formats). May also be `ios_sdk` or `android_sdk` for respective OTA SDK bundles.",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.lokalise.downloadFiles({
25+
$,
26+
projectId: this.projectId,
27+
data: {
28+
format: this.fileFormat,
29+
},
30+
});
31+
32+
$.export("$summary", `Successfully downloaded files from project ${this.projectId}`);
33+
return response;
34+
},
35+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import lokalise from "../../lokalise.app.mjs";
2+
import fs from "fs";
3+
4+
export default {
5+
key: "lokalise-upload-file",
6+
name: "Upload File",
7+
description: "Uploads a specified file to a Lokalise project. [See the documentation](https://developers.lokalise.com/reference/upload-a-file)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
lokalise,
12+
projectId: {
13+
propDefinition: [
14+
lokalise,
15+
"projectId",
16+
],
17+
},
18+
filePath: {
19+
type: "string",
20+
label: "File Path",
21+
description: "The path to a file of a [supported file format](https://docs.lokalise.com/en/collections/2909229-supported-file-formats) in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).",
22+
},
23+
language: {
24+
propDefinition: [
25+
lokalise,
26+
"language",
27+
],
28+
},
29+
filename: {
30+
type: "string",
31+
label: "Filename",
32+
description: "Set the filename. You may optionally use a relative path in the filename",
33+
},
34+
},
35+
async run({ $ }) {
36+
const fileData = fs.readFileSync(this.filePath.startsWith("/tmp")
37+
? this.filePath
38+
: `/tmp/${this.filePath}`, {
39+
encoding: "base64",
40+
});
41+
const response = await this.lokalise.uploadFile({
42+
$,
43+
projectId: this.projectId,
44+
data: {
45+
data: fileData,
46+
filename: this.filename,
47+
lang_iso: this.language,
48+
},
49+
});
50+
$.export("$summary", "Successfully uploaded file");
51+
return response;
52+
},
53+
};
Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,118 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "lokalise",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
projectId: {
8+
type: "string",
9+
label: "Project ID",
10+
description: "Identifier of a project",
11+
async options({ page }) {
12+
const { projects } = await this.listProjects({
13+
params: {
14+
page: page + 1,
15+
},
16+
});
17+
return projects?.map(({
18+
project_id: value, name: label,
19+
}) => ({
20+
value,
21+
label,
22+
})) || [];
23+
},
24+
},
25+
language: {
26+
type: "string",
27+
label: "Language",
28+
description: "Language/locale code of the project base language",
29+
async options({ page }) {
30+
const { languages } = await this.listLanguages({
31+
params: {
32+
page: page + 1,
33+
},
34+
});
35+
return languages?.map(({
36+
lang_iso: value, lang_name: label,
37+
}) => ({
38+
value,
39+
label,
40+
})) || [];
41+
},
42+
},
43+
},
544
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
45+
_baseUrl() {
46+
return "https://api.lokalise.com/api2";
47+
},
48+
_makeRequest(opts = {}) {
49+
const {
50+
$ = this,
51+
path,
52+
...otherOpts
53+
} = opts;
54+
return axios($, {
55+
...otherOpts,
56+
url: `${this._baseUrl()}${path}`,
57+
headers: {
58+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
59+
},
60+
});
61+
},
62+
createWebhook({
63+
projectId, ...opts
64+
}) {
65+
return this._makeRequest({
66+
method: "POST",
67+
path: `/projects/${projectId}/webhooks`,
68+
...opts,
69+
});
70+
},
71+
deleteWebhook({
72+
projectId, hookId, ...opts
73+
}) {
74+
return this._makeRequest({
75+
method: "DELETE",
76+
path: `/projects/${projectId}/webhooks/${hookId}`,
77+
...opts,
78+
});
79+
},
80+
listProjects(opts = {}) {
81+
return this._makeRequest({
82+
path: "/projects",
83+
...opts,
84+
});
85+
},
86+
listLanguages(opts = {}) {
87+
return this._makeRequest({
88+
path: "/system/languages",
89+
...opts,
90+
});
91+
},
92+
createProject(opts = {}) {
93+
return this._makeRequest({
94+
method: "POST",
95+
path: "/projects",
96+
...opts,
97+
});
98+
},
99+
uploadFile({
100+
projectId, ...opts
101+
}) {
102+
return this._makeRequest({
103+
method: "POST",
104+
path: `/projects/${projectId}/files/upload`,
105+
...opts,
106+
});
107+
},
108+
downloadFiles({
109+
projectId, ...opts
110+
}) {
111+
return this._makeRequest({
112+
method: "POST",
113+
path: `/projects/${projectId}/files/download`,
114+
...opts,
115+
});
9116
},
10117
},
11-
};
118+
};

components/lokalise/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/lokalise",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Lokalise Components",
55
"main": "lokalise.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.3"
1417
}
15-
}
18+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import lokalise from "../../lokalise.app.mjs";
2+
3+
export default {
4+
props: {
5+
lokalise,
6+
http: "$.interface.http",
7+
db: "$.service.db",
8+
projectId: {
9+
propDefinition: [
10+
lokalise,
11+
"projectId",
12+
],
13+
},
14+
},
15+
hooks: {
16+
async activate() {
17+
const { webhook } = await this.lokalise.createWebhook({
18+
projectId: this.projectId,
19+
data: {
20+
url: this.http.endpoint,
21+
events: this.getEvents(),
22+
},
23+
});
24+
this._setHookId(webhook.webhook_id);
25+
},
26+
async deactivate() {
27+
const hookId = this._getHookId();
28+
if (hookId) {
29+
await this.lokalise.deleteWebhook({
30+
projectId: this.projectId,
31+
hookId,
32+
});
33+
}
34+
},
35+
},
36+
methods: {
37+
_getHookId() {
38+
return this.db.get("hookId");
39+
},
40+
_setHookId(hookId) {
41+
this.db.set("hookId", hookId);
42+
},
43+
generateMeta(event) {
44+
return {
45+
id: `${event.event}-${event.created_at_timestamp}`,
46+
summary: this.getSummary(event),
47+
ts: event.created_at_timestamp,
48+
};
49+
},
50+
getEvents() {
51+
throw new Error("getEvents is not implemented");
52+
},
53+
getSummary() {
54+
throw new Error("getSummary is not implemented");
55+
},
56+
},
57+
async run(event) {
58+
const { body } = event;
59+
if (!body.event) {
60+
return;
61+
}
62+
const meta = this.generateMeta(body);
63+
this.$emit(body, meta);
64+
},
65+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "lokalise-new-task-closed-instant",
7+
name: "New Task Closed (Instant)",
8+
description: "Emit new event when a task is closed in Lokalise",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getEvents() {
15+
return [
16+
"project.task.closed",
17+
];
18+
},
19+
getSummary({ task }) {
20+
return `Task Closed with ID: ${task.id}`;
21+
},
22+
},
23+
sampleEmit,
24+
};

0 commit comments

Comments
 (0)