diff --git a/package-lock.json b/package-lock.json index 0afeb7c..b8947a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lightrail-client", - "version": "4.2.2", + "version": "4.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index fe57e8b..2d77fa2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lightrail-client", - "version": "4.2.2", + "version": "4.3.0", "description": "A Javascript and Typescript client for Lightrail", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 40182a5..6413e51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,7 +92,7 @@ export function request(method: string, path: string): superagent.Request { } if (!configuration.isBrowser) { // TODO@Dan Review Previous import of package.json to dynamically set this was breaking publish (dist included src/ & package.json file) - r.set("User-Agent", "Lightrail-JavaScript/4.2.2"); + r.set("User-Agent", "Lightrail-JavaScript/4.3.0"); } if (configuration.isBrowser) { r.set("X-Requested-With", "XMLHttpRequest"); diff --git a/src/model/DiscountSellerLiabilityRule.ts b/src/model/DiscountSellerLiabilityRule.ts new file mode 100644 index 0000000..e36a1d8 --- /dev/null +++ b/src/model/DiscountSellerLiabilityRule.ts @@ -0,0 +1,4 @@ +export interface DiscountSellerLiabilityRule { + rule: string; + explanation: string; +} diff --git a/src/model/Program.ts b/src/model/Program.ts index fdb0a9f..0e0d68b 100644 --- a/src/model/Program.ts +++ b/src/model/Program.ts @@ -1,12 +1,15 @@ import {BalanceRule} from "./BalanceRule"; import {RedemptionRule} from "./RedemptionRule"; +import {DiscountSellerLiabilityRule} from "./DiscountSellerLiabilityRule"; export interface Program { id: string; name: string; currency: string; discount: boolean; + /** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */ discountSellerLiability: number; + discountSellerLiabilityRule: DiscountSellerLiabilityRule; pretax: boolean; active: boolean; redemptionRule: RedemptionRule; diff --git a/src/model/Value.ts b/src/model/Value.ts index 98e2127..dc1c0d5 100644 --- a/src/model/Value.ts +++ b/src/model/Value.ts @@ -1,6 +1,7 @@ import {BalanceRule} from "./BalanceRule"; import {RedemptionRule} from "./RedemptionRule"; import {GenericCodeOptions} from "./GenericCodeOptions"; +import {DiscountSellerLiabilityRule} from "./DiscountSellerLiabilityRule"; export interface Value { id: string; @@ -20,7 +21,9 @@ export interface Value { canceled: boolean; redemptionRule: RedemptionRule; discount: boolean; + /** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */ discountSellerLiability: number; + discountSellerLiabilityRule: DiscountSellerLiabilityRule; startDate: string; endDate: string; tags: string[]; diff --git a/src/model/index.ts b/src/model/index.ts index a28ff2c..2959fcd 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -7,3 +7,4 @@ export * from "./RedemptionRule"; export * from "./Transaction"; export * from "./Value"; export * from "./GenericCodeOptions"; +export * from "./DiscountSellerLiabilityRule"; diff --git a/src/params/programs/CreateProgramParams.ts b/src/params/programs/CreateProgramParams.ts index 38da3b9..088ed0d 100644 --- a/src/params/programs/CreateProgramParams.ts +++ b/src/params/programs/CreateProgramParams.ts @@ -1,14 +1,17 @@ import {Program} from "../../model"; import {LightrailResponse} from "../LightrailResponse"; -import {BalanceRule} from "../../model/BalanceRule"; -import {RedemptionRule} from "../../model/RedemptionRule"; +import {BalanceRule} from "../../model"; +import {RedemptionRule} from "../../model"; +import {DiscountSellerLiabilityRule} from "../../model"; export interface CreateProgramParams { id: string; currency: string; name: string; discount?: boolean; + /** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */ discountSellerLiability?: number; + discountSellerLiabilityRule?: DiscountSellerLiabilityRule; pretax?: boolean; active?: boolean; redemptionRule?: RedemptionRule; diff --git a/src/params/programs/UpdateProgramParams.ts b/src/params/programs/UpdateProgramParams.ts index e93f37a..0e82655 100644 --- a/src/params/programs/UpdateProgramParams.ts +++ b/src/params/programs/UpdateProgramParams.ts @@ -1,10 +1,13 @@ import {BalanceRule, Program, RedemptionRule} from "../../model"; import {LightrailResponse} from "../LightrailResponse"; +import {DiscountSellerLiabilityRule} from "../../model"; export interface UpdateProgramParams { name?: string; discount?: boolean; + /** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */ discountSellerLiability?: number; + discountSellerLiabilityRule?: DiscountSellerLiabilityRule; pretax?: boolean; active?: boolean; redemptionRule?: RedemptionRule; diff --git a/src/params/values/CreateValueParams.ts b/src/params/values/CreateValueParams.ts index c5e470d..0a7c074 100644 --- a/src/params/values/CreateValueParams.ts +++ b/src/params/values/CreateValueParams.ts @@ -1,8 +1,9 @@ -import {Value} from "../../model/Value"; +import {Value} from "../../model"; import {LightrailResponse} from "../LightrailResponse"; -import {BalanceRule} from "../../model/BalanceRule"; -import {RedemptionRule} from "../../model/RedemptionRule"; -import {GenericCodeOptions} from "../../model/GenericCodeOptions"; +import {BalanceRule} from "../../model"; +import {RedemptionRule} from "../../model"; +import {GenericCodeOptions} from "../../model"; +import {DiscountSellerLiabilityRule} from "../../model"; export interface CreateValueParams { id: string; @@ -15,7 +16,9 @@ export interface CreateValueParams { active?: boolean; frozen?: boolean; discount?: boolean; + /** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */ discountSellerLiability?: number; + discountSellerLiabilityRule?: DiscountSellerLiabilityRule; genericCodeOptions?: GenericCodeOptions; redemptionRule?: RedemptionRule; balanceRule?: BalanceRule; diff --git a/src/params/values/UpdateValueParams.ts b/src/params/values/UpdateValueParams.ts index 9dbb495..3e3b55b 100644 --- a/src/params/values/UpdateValueParams.ts +++ b/src/params/values/UpdateValueParams.ts @@ -1,7 +1,8 @@ import {LightrailResponse} from "../LightrailResponse"; -import {Value} from "../../model/Value"; -import {BalanceRule} from "../../model/BalanceRule"; -import {RedemptionRule} from "../../model/RedemptionRule"; +import {Value} from "../../model"; +import {BalanceRule} from "../../model"; +import {RedemptionRule} from "../../model"; +import {DiscountSellerLiabilityRule} from "../../model"; export interface UpdateValueParams { contactId?: string; @@ -12,7 +13,9 @@ export interface UpdateValueParams { redemptionRule?: RedemptionRule; balanceRule?: BalanceRule; discount?: boolean; + /** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */ discountSellerLiability?: number; + discountSellerLiabilityRule?: DiscountSellerLiabilityRule; startDate?: string; endDate?: string; tags?: string[]; diff --git a/src/programs.test.ts b/src/programs.test.ts index a5f9f3d..1541f56 100644 --- a/src/programs.test.ts +++ b/src/programs.test.ts @@ -23,8 +23,7 @@ describe("programs", () => { id: testID, name: "javascript programs unit test", currency: "USD", - discount: false, - discountSellerLiability: null, + discount: true, pretax: false, active: true, redemptionRule: { @@ -35,6 +34,10 @@ describe("programs", () => { rule: "100", explanation: "$1", }, + discountSellerLiabilityRule: { + rule: "0.5", + explanation: "seller is 50% liable" + }, minInitialBalance: null, // must be null if balanceRule maxInitialBalance: null, // must be null if balanceRule fixedInitialBalances: null, // must be null if balanceRule @@ -47,9 +50,9 @@ describe("programs", () => { }; const program = await Lightrail.programs.createProgram(request); chai.assert.isNotNull(program); - chai.assert.deepEqualExcluding(program.body, request, + chai.assert.deepEqualExcluding(program.body, {...request, discountSellerLiability: 0.5}, [ - "startDate", "endDate", "createdBy", "createdDate", "updatedDate" + "startDate", "endDate", "createdBy", "createdDate", "updatedDate", ] as any); }); }); diff --git a/src/values.test.ts b/src/values.test.ts index 960de97..66fc90b 100644 --- a/src/values.test.ts +++ b/src/values.test.ts @@ -26,11 +26,14 @@ describe("values", () => { frozen: false, discount: true, pretax: true, - discountSellerLiability: 1, redemptionRule: { rule: "1 == 1", explanation: "true" }, + discountSellerLiabilityRule: { + rule: "0.5", + explanation: "seller is 50% liable" + }, balanceRule: null, usesRemaining: 1, startDate: new Date("3030-01-01").toISOString(), @@ -45,9 +48,9 @@ describe("values", () => { const value = await Lightrail.values.createValue(testValue); chai.assert.isNotNull(value); - chai.assert.deepEqualExcluding(value.body, testValue, + chai.assert.deepEqualExcluding(value.body, {...testValue, discountSellerLiability: 0.5}, [ - "startDate", "endDate", "createdBy", "createdDate", "updatedDate", "code", "issuanceId", "updatedContactIdDate", "canceled", "programId" + "startDate", "endDate", "createdBy", "createdDate", "updatedDate", "code", "issuanceId", "updatedContactIdDate", "canceled", "programId", ] as any); }); });