@swp/ledger-sdk
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -7,6 +7,8 @@ export interface Model<DTO> { | ||
DESTROY_ACCOUNT = "DESTROY_ACCOUNT", | ||
NEW_ASSET = "NEW_ASSET", | ||
ISSUE_ASSET = "ISSUE_ASSET", | ||
BURN_ASSET = "BURN_ASSET", | ||
TRANSFER = "TRANSFER" | ||
} | ||
export declare type NewActionDTO = NewTransferDTO | NewAccountDTO | IssueAssetDTO | DestroyAccountDTO; | ||
export declare type NewActionDTO = NewTransferDTO | NewAccountDTO | NewAssetDTO | IssueAssetDTO | BurnAssetDTO | DestroyAccountDTO; | ||
export declare type ActionDTO = TransferDTO | AccountDTO | AssetDTO | DestroyAccountDTO; | ||
@@ -44,10 +46,20 @@ export declare type Fields = { | ||
} | ||
export interface IssueAssetDTO { | ||
type: ActionType.ISSUE_ASSET; | ||
export interface NewAssetDTO { | ||
type: ActionType.NEW_ASSET; | ||
code: string; | ||
fields?: Fields; | ||
} | ||
export interface AssetDTO extends IssueAssetDTO { | ||
export interface IssueAssetDTO { | ||
type: ActionType.ISSUE_ASSET; | ||
to: string; | ||
amount: string; | ||
assetId: string; | ||
} | ||
export interface BurnAssetDTO { | ||
type: ActionType.BURN_ASSET; | ||
id: string; | ||
} | ||
export interface AssetDTO extends NewAssetDTO { | ||
id: string; | ||
} | ||
export interface NewAccountDTO { | ||
@@ -54,0 +66,0 @@ type: ActionType.NEW_ACCOUNT; |
@@ -7,3 +7,5 @@ "use strict"; | ||
ActionType["DESTROY_ACCOUNT"] = "DESTROY_ACCOUNT"; | ||
ActionType["NEW_ASSET"] = "NEW_ASSET"; | ||
ActionType["ISSUE_ASSET"] = "ISSUE_ASSET"; | ||
ActionType["BURN_ASSET"] = "BURN_ASSET"; | ||
ActionType["TRANSFER"] = "TRANSFER"; | ||
@@ -10,0 +12,0 @@ })(ActionType = exports.ActionType || (exports.ActionType = {})); |
@@ -1,4 +0,3 @@ | ||
import { APIResponse, SwpResponse } from "./dto"; | ||
import { SwpResponse } from "./dto"; | ||
import { Model } from "../dto"; | ||
export declare function apiResponse<T>(res: SwpResponse<T>): APIResponse; | ||
export declare function newSuccessResponse<T>(data?: Model<T> | Model<T>[], lastCursor?: number): SwpResponse<T | T[]>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var codes_1 = require("./codes"); | ||
function apiResponse(res) { | ||
return { | ||
statusCode: res.status === codes_1.HttpCodes.NO_CONTENT | ||
? codes_1.HttpCodes.OK | ||
: res.status, | ||
body: JSON.stringify(res), | ||
headers: {} | ||
}; | ||
} | ||
exports.apiResponse = apiResponse; | ||
function newSuccessResponse(data, lastCursor) { | ||
@@ -15,0 +5,0 @@ return { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var success_1 = require("./success"); | ||
var http2_1 = require("http2"); | ||
var chai_1 = require("chai"); | ||
var codes_1 = require("./codes"); | ||
describe("apiResponse", function () { | ||
it('should return correctly', function () { | ||
var expectedRes = { status: http2_1.constants.HTTP_STATUS_UNAUTHORIZED }; | ||
var res = success_1.apiResponse(expectedRes); | ||
chai_1.expect(res.statusCode).to.equal(expectedRes.status); | ||
chai_1.expect(JSON.parse(res.body)).to.deep.equal(expectedRes); | ||
}); | ||
}); | ||
describe("newSuccessResponse", function () { | ||
@@ -16,0 +7,0 @@ it("should work with single Model", function () { |
@@ -14,3 +14,3 @@ "use strict"; | ||
any_1.castTo(10); | ||
chai_1.expect(true).to.equal(false); | ||
throw new Error("should have failed"); | ||
} | ||
@@ -17,0 +17,0 @@ catch (e) { |
@@ -1,2 +0,2 @@ | ||
import { DestroyAccountDTO, IssueAssetDTO, NewAccountDTO, NewTransferDTO } from "../common/dto"; | ||
import { BurnAssetDTO, DestroyAccountDTO, IssueAssetDTO, NewAccountDTO, NewAssetDTO, NewTransferDTO } from "../common/dto"; | ||
declare type Fields = { | ||
@@ -7,4 +7,6 @@ [key: string]: string; | ||
export declare const transferAction: (from: string, to: string, amount: string, assetId: string) => NewTransferDTO; | ||
export declare const issueAssetAction: (code: string, fields?: Fields | undefined) => IssueAssetDTO; | ||
export declare const newAssetAction: (code: string, fields?: Fields | undefined) => NewAssetDTO; | ||
export declare const issueAssetAction: (to: string, amount: string, assetId: string) => IssueAssetDTO; | ||
export declare const burnAssetAction: (id: string) => BurnAssetDTO; | ||
export declare const destroyAccountAction: (id: string) => DestroyAccountDTO; | ||
export {}; |
@@ -15,7 +15,17 @@ "use strict"; | ||
}); }; | ||
exports.issueAssetAction = function (code, fields) { return ({ | ||
type: dto_1.ActionType.ISSUE_ASSET, | ||
exports.newAssetAction = function (code, fields) { return ({ | ||
type: dto_1.ActionType.NEW_ASSET, | ||
code: code, | ||
fields: fields, | ||
}); }; | ||
exports.issueAssetAction = function (to, amount, assetId) { return ({ | ||
type: dto_1.ActionType.ISSUE_ASSET, | ||
to: to, | ||
amount: amount, | ||
assetId: assetId, | ||
}); }; | ||
exports.burnAssetAction = function (id) { return ({ | ||
type: dto_1.ActionType.BURN_ASSET, | ||
id: id, | ||
}); }; | ||
exports.destroyAccountAction = function (id) { return ({ | ||
@@ -22,0 +32,0 @@ type: dto_1.ActionType.DESTROY_ACCOUNT, |
@@ -28,11 +28,31 @@ "use strict"; | ||
}); | ||
describe("issueAssetAction", function () { | ||
describe("newAssetAction", function () { | ||
it("should work correctly", function () { | ||
var code = "CODE"; | ||
var fields = { one: "one", two: "two" }; | ||
var action = actions_1.issueAssetAction(code, fields); | ||
chai_1.expect(action.type).to.equal(dto_1.ActionType.ISSUE_ASSET); | ||
var action = actions_1.newAssetAction(code, fields); | ||
chai_1.expect(action.type).to.equal(dto_1.ActionType.NEW_ASSET); | ||
chai_1.expect(action.fields).to.deep.equal(fields); | ||
}); | ||
}); | ||
describe("issueAssetAction", function () { | ||
it("should work correctly", function () { | ||
var to = "to"; | ||
var amount = "10437"; | ||
var assetId = "assetId"; | ||
var action = actions_1.issueAssetAction(to, amount, assetId); | ||
chai_1.expect(action.type).to.equal(dto_1.ActionType.ISSUE_ASSET); | ||
chai_1.expect(action.assetId).to.deep.equal(assetId); | ||
chai_1.expect(action.to).to.deep.equal(to); | ||
chai_1.expect(action.amount).to.deep.equal(amount); | ||
}); | ||
}); | ||
describe("burnAssetAction", function () { | ||
it("should work correctly", function () { | ||
var id = "id"; | ||
var action = actions_1.burnAssetAction(id); | ||
chai_1.expect(action.type).to.equal(dto_1.ActionType.BURN_ASSET); | ||
chai_1.expect(action.id).to.deep.equal(id); | ||
}); | ||
}); | ||
describe("destroyAccountAction", function () { | ||
@@ -39,0 +59,0 @@ it("should work correctly", function () { |
{ | ||
"name": "@swp/ledger-sdk", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
120702
1880
0