lightrail-client
Advanced tools
Comparing version 2.0.30 to 2.0.31
@@ -6,6 +6,10 @@ import { CreateContactParams, CreateContactResponse, ListContactsParams, ListContactsResponse, UpdateContactParams } from "./params"; | ||
import { GetContactResponse } from "./params/contacts/GetContactParams"; | ||
import { ListContactsValuesParams, ListContactsValuesResponse } from "./params/contacts/ListContactsValuesParams"; | ||
import { AttachContactToValueParams, AttachContactToValueResponse } from "./params/contacts/AttachContactToValueParams"; | ||
export declare function createContact(params: CreateContactParams): Promise<CreateContactResponse>; | ||
export declare function getContact(contact: string | Contact): Promise<GetContactResponse>; | ||
export declare function listContacts(params?: ListContactsParams): Promise<ListContactsResponse>; | ||
export declare function getContact(contact: string | Contact): Promise<GetContactResponse>; | ||
export declare function listContactsValues(contact: string | Contact, params?: ListContactsValuesParams): Promise<ListContactsValuesResponse>; | ||
export declare function updateContact(contact: string | Contact, params: UpdateContactParams): Promise<UpdateContactResponse>; | ||
export declare function attachContactToValue(contact: string | Contact, params: AttachContactToValueParams): Promise<AttachContactToValueResponse>; | ||
export declare function deleteContact(contact: string | Contact): Promise<DeleteContactResponse>; | ||
@@ -12,0 +16,0 @@ /** |
@@ -32,2 +32,16 @@ "use strict"; | ||
// READ | ||
function getContact(contact) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const contactId = getContactId(contact); | ||
const resp = yield lightrail.request("GET", `contacts/${encodeURIComponent(contactId)}`); | ||
if (resp.status === 200) { | ||
return (requestUtils_1.formatResponse(resp)); | ||
} | ||
else if (resp.status === 404) { | ||
return null; | ||
} | ||
throw new LightrailRequestError_1.LightrailRequestError(resp); | ||
}); | ||
} | ||
exports.getContact = getContact; | ||
function listContacts(params) { | ||
@@ -43,6 +57,6 @@ return __awaiter(this, void 0, void 0, function* () { | ||
exports.listContacts = listContacts; | ||
function getContact(contact) { | ||
function listContactsValues(contact, params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const contactId = getContactId(contact); | ||
const resp = yield lightrail.request("GET", `contacts/${encodeURIComponent(contactId)}`); | ||
const resp = yield lightrail.request("GET", `contacts/${encodeURIComponent(contactId)}/values`).query(params); | ||
if (resp.status === 200) { | ||
@@ -57,3 +71,3 @@ return (requestUtils_1.formatResponse(resp)); | ||
} | ||
exports.getContact = getContact; | ||
exports.listContactsValues = listContactsValues; | ||
// UPDATE | ||
@@ -71,2 +85,13 @@ function updateContact(contact, params) { | ||
exports.updateContact = updateContact; | ||
function attachContactToValue(contact, params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const contactId = getContactId(contact); | ||
const resp = yield lightrail.request("POST", `contacts/${encodeURIComponent(contactId)}/values/attach`).send(params); | ||
if (resp.status === 200) { | ||
return requestUtils_1.formatResponse(resp); | ||
} | ||
throw new LightrailRequestError_1.LightrailRequestError(resp); | ||
}); | ||
} | ||
exports.attachContactToValue = attachContactToValue; | ||
// DELETE | ||
@@ -73,0 +98,0 @@ function deleteContact(contact) { |
import { CreateCurrencyParams, CreateCurrencyResponse } from "./params/currencies/CreateCurrencyParams"; | ||
import { Currency } from "./model/Currency"; | ||
import { ListCurreniesResponse } from "./params"; | ||
import { GetCurrencyResponse } from "./params/currencies/GetCurrencyParams"; | ||
import { UpdateCurrencyParams, UpdateCurrencyResponse } from "./params/currencies/UpdateCurrencyParams"; | ||
import { DeleteCurrencyRequest } from "./params/currencies/DeleteCurrencyParms"; | ||
export declare function createCurrency(params: CreateCurrencyParams): Promise<CreateCurrencyResponse>; | ||
export declare function listCurrencies(): Promise<ListCurreniesResponse>; | ||
export declare function getCurrency(currency: string | Currency): Promise<GetCurrencyResponse>; | ||
export declare function updateCurrency(currency: string | Currency, params: UpdateCurrencyParams): Promise<UpdateCurrencyResponse>; | ||
export declare function deleteCurrency(currency: string | Currency): Promise<DeleteCurrencyRequest>; | ||
/** | ||
* Get currency code from the string (as the ID itself) or Currency object. | ||
*/ | ||
export declare function getCurrencyCode(currency: string | Currency): string; |
@@ -14,2 +14,3 @@ "use strict"; | ||
const lightrail = require("./index"); | ||
// CREATE | ||
function createCurrency(params) { | ||
@@ -31,1 +32,80 @@ return __awaiter(this, void 0, void 0, function* () { | ||
exports.createCurrency = createCurrency; | ||
// READ | ||
function listCurrencies() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const resp = yield lightrail.request("GET", `currencies`); | ||
if (resp.status === 200) { | ||
return requestUtils_1.formatResponse(resp); | ||
} | ||
throw new LightrailRequestError_1.LightrailRequestError(resp); | ||
}); | ||
} | ||
exports.listCurrencies = listCurrencies; | ||
function getCurrency(currency) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const currencyCode = getCurrencyCode(currency); | ||
if (!currencyCode) { | ||
throw new Error("currencyCode missing from getCurrency(currency)!"); | ||
} | ||
const resp = yield lightrail.request("GET", `currencies/${encodeURIComponent(currencyCode)}`); | ||
if (resp.status === 200) { | ||
return requestUtils_1.formatResponse(resp); | ||
} | ||
throw new LightrailRequestError_1.LightrailRequestError(resp); | ||
}); | ||
} | ||
exports.getCurrency = getCurrency; | ||
// UPDATE | ||
function updateCurrency(currency, params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const currencyCode = getCurrencyCode(currency); | ||
if (!currencyCode) { | ||
throw new Error("currencyCode missing from updateCurrency(currency, params)!"); | ||
} | ||
if (!params) { | ||
throw new Error("params sent to updateCurrency(currency, params)"); | ||
} | ||
const resp = yield lightrail.request("PATCH", `currencies/${encodeURIComponent(currencyCode)}`).send(params); | ||
if (resp.status === 200) { | ||
return requestUtils_1.formatResponse(resp); | ||
} | ||
else if (resp.status === 404) { | ||
return null; | ||
} | ||
throw new LightrailRequestError_1.LightrailRequestError(resp); | ||
}); | ||
} | ||
exports.updateCurrency = updateCurrency; | ||
// DELETE | ||
function deleteCurrency(currency) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const currencyCode = getCurrencyCode(currency); | ||
const resp = yield lightrail.request("DELETE", `currencies/${encodeURIComponent(currencyCode)}`); | ||
if (resp.status === 200) { | ||
return requestUtils_1.formatResponse(resp); | ||
} | ||
else if (resp.status === 404) { | ||
return null; | ||
} | ||
throw new LightrailRequestError_1.LightrailRequestError(resp); | ||
}); | ||
} | ||
exports.deleteCurrency = deleteCurrency; | ||
/** | ||
* Get currency code from the string (as the ID itself) or Currency object. | ||
*/ | ||
function getCurrencyCode(currency) { | ||
if (!currency) { | ||
throw new Error("currency issuance not set"); | ||
} | ||
else if (typeof currency === "string") { | ||
return currency; | ||
} | ||
else if (currency.code) { | ||
return currency.code; | ||
} | ||
else { | ||
throw new Error("issuance must be a string for issuanceId or a Issuance object"); | ||
} | ||
} | ||
exports.getCurrencyCode = getCurrencyCode; |
import { LightrailResponse } from "../LightrailResponse"; | ||
import { Currency } from "../../model/Currency"; | ||
import { PaginationParams } from "../PaginationParams"; | ||
export interface ListCurrenciesParams extends PaginationParams { | ||
} | ||
export interface ListCurreniesResponse extends LightrailResponse<Currency[]> { | ||
} |
{ | ||
"name": "lightrail-client", | ||
"version": "2.0.30", | ||
"version": "2.0.31", | ||
"description": "A Javascript and Typescript client for Lightrail", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
81564
119
1814