@localazy/ts-api
Advanced tools
Comparing version
@@ -62,3 +62,3 @@ "use strict"; | ||
queryParams = options.options ? "?".concat(LocalazyAPI.getQueryString(options.options)) : ''; | ||
return [4 /*yield*/, fetch("/api".concat(options.url).concat(queryParams), { | ||
return [4 /*yield*/, fetch("".concat(options.url).concat(queryParams), { | ||
method: 'GET', | ||
@@ -88,3 +88,3 @@ headers: { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetch("/api".concat(options.url), { | ||
case 0: return [4 /*yield*/, fetch("".concat(options.url), { | ||
method: 'POST', | ||
@@ -91,0 +91,0 @@ headers: { |
@@ -12,2 +12,6 @@ import Constructor from './models/arguments/constructor'; | ||
import KeysInFile from './models/responses/keys-in-file'; | ||
import ListWebhooks from './models/arguments/list-webhooks'; | ||
import ListWebhooksResult from './models/responses/list-webhooks-result'; | ||
import PostWebhooks from './models/arguments/post-webhooks'; | ||
import PostWebhooksResult from './models/responses/post-webhooks-result'; | ||
declare class LocalazyService { | ||
@@ -42,4 +46,14 @@ private projectToken; | ||
listKeysInFileForLanguage(options: ListKeysInFile, config?: CommonConfig): Promise<KeysInFile>; | ||
/** | ||
* Retrieve list of webhooks for project. | ||
* @see https://localazy.com/docs/api/webhooks | ||
*/ | ||
listWebhooks(options: ListWebhooks, config?: CommonConfig): Promise<ListWebhooksResult>; | ||
/** | ||
* Store a new webhooks configuration for the project. | ||
* @see https://localazy.com/docs/api/webhooks | ||
*/ | ||
postWebhooks(options: PostWebhooks, config?: CommonConfig): Promise<PostWebhooksResult>; | ||
} | ||
export default function LocalazyServiceFactory(options: Constructor): LocalazyService; | ||
export {}; |
@@ -181,2 +181,47 @@ "use strict"; | ||
}); | ||
/** | ||
* Retrieve list of webhooks for project. | ||
* @see https://localazy.com/docs/api/webhooks | ||
*/ | ||
Object.defineProperty(LocalazyService.prototype, "listWebhooks", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (options, config) { | ||
if (config === void 0) { config = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var projectId; | ||
return __generator(this, function (_a) { | ||
projectId = options.projectId; | ||
return [2 /*return*/, api_1.default.get({ | ||
url: "".concat(config.baseUrl || this.baseUrl, "/projects/").concat(projectId, "/webhooks"), | ||
projectToken: config.projectToken || this.projectToken, | ||
})]; | ||
}); | ||
}); | ||
} | ||
}); | ||
/** | ||
* Store a new webhooks configuration for the project. | ||
* @see https://localazy.com/docs/api/webhooks | ||
*/ | ||
Object.defineProperty(LocalazyService.prototype, "postWebhooks", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (options, config) { | ||
if (config === void 0) { config = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var projectId; | ||
return __generator(this, function (_a) { | ||
projectId = options.projectId; | ||
return [2 /*return*/, api_1.default.post({ | ||
url: "".concat(config.baseUrl || this.baseUrl, "/projects/").concat(projectId, "/webhooks"), | ||
projectToken: config.projectToken || this.projectToken, | ||
options: options.webhooks, | ||
})]; | ||
}); | ||
}); | ||
} | ||
}); | ||
return LocalazyService; | ||
@@ -183,0 +228,0 @@ }()); |
{ | ||
"name": "@localazy/ts-api", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "This is a Typescript library facilitating usage of Localazy's API.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# @localazy/ts-api | ||
This is a Typescript library facilitating usage of Localazy's API. To better understand this library, it is recommended to study the [API documentation](https://localazy.com/docs/api/introduction) first. | ||
## Installation and usage | ||
## Installation and usage | ||
To install this library, run the following command | ||
``` | ||
@@ -12,2 +14,3 @@ npm i @localazy/ts-api | ||
Afterwards, import the library and initialize it. | ||
``` | ||
@@ -23,2 +26,3 @@ import LocalazyApi from '@localazy/ts-api'; | ||
### Project token | ||
In order to access anything from Localazy, you need to [sign up](https://localazy.com/register) and create a project. | ||
@@ -30,49 +34,90 @@ | ||
### Base url | ||
Optional `baseUrl` parameter. Add prefix for all api calls. Useful for proxying requests. | ||
## Methods overview | ||
### listProjects | ||
List projects related to the project token. | ||
```ts | ||
async listProjects(options: ListProjects = {}, config: CommonConfig = {}); | ||
async listProjects(options: ListProjects = {}, config: CommonConfig = {}) | ||
``` | ||
Documentation: https://localazy.com/docs/api/list-projects | ||
### import | ||
Import content into Localazy. | ||
```ts | ||
async import(options: Import, config: CommonConfig = {}) | ||
``` | ||
Documentation: https://localazy.com/docs/api/import | ||
### listFormats | ||
Retrieve list of available file formats and related options. | ||
```ts | ||
async listFormats(config: CommonConfig = {}) | ||
``` | ||
Documentation: https://localazy.com/docs/api/import#retrieve-a-list-of-available-file-types | ||
### listFiles | ||
### listFiles | ||
List Localazy files. | ||
```ts | ||
async listFiles(options: ListFiles, config: CommonConfig = {}) | ||
``` | ||
Documentation: https://localazy.com/docs/api/files | ||
### listKeysInFileForLanguage | ||
This is the main method for retrieving translated content from given project and localazy file for given language. | ||
```ts | ||
async listKeysInFileForLanguage(options: ListKeysInFile, config: CommonConfig = {}) | ||
``` | ||
Documentation: https://localazy.com/docs/api/files#retrieve-a-list-of-keys-and-translations-from-file | ||
### webhooks | ||
Returns the webhooks configuration for the given project. | ||
```ts | ||
async listWebhooks(options: ListWebhooks, config: CommonConfig = {}) | ||
``` | ||
Documentation: https://localazy.com/docs/api/webhooks | ||
### postWebhooks | ||
Store a new webhooks configuration for the project. | ||
```ts | ||
async postWebhooks(options: PostWebhooks, config: CommonConfig = {}) | ||
``` | ||
Documentation: https://localazy.com/docs/api/webhooks | ||
# FAQ | ||
## Localazy's API supports method that is not included in this library. | ||
It's possible as the API is still actively developed and it might take us some time to update all related projects. Feel free to create a new issue or pull request for this. | ||
It's possible as the API is still actively developed and it might take us some time to update all related projects. Feel free to create a new issue or pull request for this. | ||
## I'd like to import and use a type definition for one of the methods. Can I do that? | ||
Yes. We publish type definitions for arguments of all the methods to NPM. They reside in `@localazy/ts-api/dist/models`, e.g. | ||
```ts | ||
import ListProjects from '@localazy/ts-api/dist/models/arguments/list-projects'; | ||
``` | ||
import ListProjects from "@localazy/ts-api/dist/models/arguments/list-projects"; | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
40691
16.58%68
28.3%704
15.98%121
61.33%