Skip to content
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
60 changes: 60 additions & 0 deletions components/lokalise/actions/create-project/create-project.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import lokalise from "../../lokalise.app.mjs";

export default {
key: "lokalise-create-project",
name: "Create Project",
description: "Initializes an empty project in Lokalise. [See the documentation](https://developers.lokalise.com/reference/create-a-project)",
version: "0.0.1",
type: "action",
props: {
lokalise,
name: {
type: "string",
label: "Name",
description: "Name of the project",
},
description: {
type: "string",
label: "Description",
description: "Description of the project",
optional: true,
},
language: {
propDefinition: [
lokalise,
"language",
],
optional: true,
},
projectType: {
type: "string",
label: "Project Type",
description: "The type of project",
options: [
"localization_files",
"paged_documents",
],
optional: true,
},
isSegmentationEnabled: {
type: "boolean",
label: "Is Segmentation Enabled",
description: "Whether to enable Segmentation feature for project",
optional: true,
},
},
async run({ $ }) {
const response = await this.lokalise.createProject({
$,
data: {
name: this.name,
description: this.description,
base_lang_iso: this.language,
project_type: this.projectType,
is_segmentation_enabled: this.isSegmentationEnabled,
},
});
$.export("$summary", `Successfully created project with ID: ${response.project_id}`);
return response;
},
};
35 changes: 35 additions & 0 deletions components/lokalise/actions/download-files/download-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import lokalise from "../../lokalise.app.mjs";

export default {
key: "lokalise-download-files",
name: "Download Files",
description: "Retrieves and downloads files from a specified Lokalise project. [See the documentation](https://developers.lokalise.com/reference/download-files)",
version: "0.0.1",
type: "action",
props: {
lokalise,
projectId: {
propDefinition: [
lokalise,
"projectId",
],
},
fileFormat: {
type: "string",
label: "File Format",
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.",
},
},
async run({ $ }) {
const response = await this.lokalise.downloadFiles({
$,
projectId: this.projectId,
data: {
format: this.fileFormat,
},
});

$.export("$summary", `Successfully downloaded files from project ${this.projectId}`);
return response;
},
};
53 changes: 53 additions & 0 deletions components/lokalise/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import lokalise from "../../lokalise.app.mjs";
import fs from "fs";

export default {
key: "lokalise-upload-file",
name: "Upload File",
description: "Uploads a specified file to a Lokalise project. [See the documentation](https://developers.lokalise.com/reference/upload-a-file)",
version: "0.0.1",
type: "action",
props: {
lokalise,
projectId: {
propDefinition: [
lokalise,
"projectId",
],
},
filePath: {
type: "string",
label: "File Path",
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).",
},
language: {
propDefinition: [
lokalise,
"language",
],
},
filename: {
type: "string",
label: "Filename",
description: "Set the filename. You may optionally use a relative path in the filename",
},
},
async run({ $ }) {
const fileData = fs.readFileSync(this.filePath.startsWith("/tmp")
? this.filePath
: `/tmp/${this.filePath}`, {
encoding: "base64",
});
const response = await this.lokalise.uploadFile({
$,
projectId: this.projectId,
data: {
data: fileData,
filename: this.filename,
lang_iso: this.language,
},
});
$.export("$summary", "Successfully uploaded file");
return response;
},
};
117 changes: 112 additions & 5 deletions components/lokalise/lokalise.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,118 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "lokalise",
propDefinitions: {},
propDefinitions: {
projectId: {
type: "string",
label: "Project ID",
description: "Identifier of a project",
async options({ page }) {
const { projects } = await this.listProjects({
params: {
page: page + 1,
},
});
return projects?.map(({
project_id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
language: {
type: "string",
label: "Language",
description: "Language/locale code of the project base language",
async options({ page }) {
const { languages } = await this.listLanguages({
params: {
page: page + 1,
},
});
return languages?.map(({
lang_iso: value, lang_name: label,
}) => ({
value,
label,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.lokalise.com/api2";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
},
});
},
createWebhook({
projectId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/projects/${projectId}/webhooks`,
...opts,
});
},
deleteWebhook({
projectId, hookId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/projects/${projectId}/webhooks/${hookId}`,
...opts,
});
},
listProjects(opts = {}) {
return this._makeRequest({
path: "/projects",
...opts,
});
},
listLanguages(opts = {}) {
return this._makeRequest({
path: "/system/languages",
...opts,
});
},
createProject(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/projects",
...opts,
});
},
uploadFile({
projectId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/projects/${projectId}/files/upload`,
...opts,
});
},
downloadFiles({
projectId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/projects/${projectId}/files/download`,
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/lokalise/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/lokalise",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Lokalise Components",
"main": "lokalise.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
65 changes: 65 additions & 0 deletions components/lokalise/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import lokalise from "../../lokalise.app.mjs";

export default {
props: {
lokalise,
http: "$.interface.http",
db: "$.service.db",
projectId: {
propDefinition: [
lokalise,
"projectId",
],
},
},
hooks: {
async activate() {
const { webhook } = await this.lokalise.createWebhook({
projectId: this.projectId,
data: {
url: this.http.endpoint,
events: this.getEvents(),
},
});
this._setHookId(webhook.webhook_id);
},
async deactivate() {
const hookId = this._getHookId();
if (hookId) {
await this.lokalise.deleteWebhook({
projectId: this.projectId,
hookId,
});
}
},
},
methods: {
_getHookId() {
return this.db.get("hookId");
},
_setHookId(hookId) {
this.db.set("hookId", hookId);
},
generateMeta(event) {
return {
id: `${event.event}-${event.created_at_timestamp}`,
summary: this.getSummary(event),
ts: event.created_at_timestamp,
};
},
getEvents() {
throw new Error("getEvents is not implemented");
},
getSummary() {
throw new Error("getSummary is not implemented");
},
},
async run(event) {
const { body } = event;
if (!body.event) {
return;
}
const meta = this.generateMeta(body);
this.$emit(body, meta);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "lokalise-new-task-closed-instant",
name: "New Task Closed (Instant)",
description: "Emit new event when a task is closed in Lokalise",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEvents() {
return [
"project.task.closed",
];
},
getSummary({ task }) {
return `Task Closed with ID: ${task.id}`;
},
},
sampleEmit,
};
Loading
Loading