lightrail-client
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -28,11 +28,11 @@ /// <reference types="superagent" /> | ||
* restricted to that particular shopper. The shopper can be defined by the | ||
* contactId, userSuppliedId, or shopperId. | ||
* contactId, or an empty string for anonymous. | ||
* | ||
* eg: `generateShopperToken({shopperId: "user-12345"});` | ||
* eg: `generateShopperToken({shopperId: "user-12345"}, {validityInSeconds: 43200});` | ||
* eg: `generateShopperToken("user-12345");` | ||
* eg: `generateShopperToken("user-12345", {validityInSeconds: 43200});` | ||
* | ||
* @param contact an object that defines one of: contactId, userSuppliedId or shopperId | ||
* @param contactId the ID of the contact | ||
* @param options the number of seconds the shopper token will be valid for *OR* a GenerateShopperTokenOptions object | ||
* @returns the shopper token | ||
*/ | ||
export declare function generateShopperToken(contact: model.ContactIdentifier, options?: number | GenerateShopperTokenOptions): string; | ||
export declare function generateShopperToken(contactId: string, options?: GenerateShopperTokenOptions): string; |
@@ -116,12 +116,12 @@ "use strict"; | ||
* restricted to that particular shopper. The shopper can be defined by the | ||
* contactId, userSuppliedId, or shopperId. | ||
* contactId, or an empty string for anonymous. | ||
* | ||
* eg: `generateShopperToken({shopperId: "user-12345"});` | ||
* eg: `generateShopperToken({shopperId: "user-12345"}, {validityInSeconds: 43200});` | ||
* eg: `generateShopperToken("user-12345");` | ||
* eg: `generateShopperToken("user-12345", {validityInSeconds: 43200});` | ||
* | ||
* @param contact an object that defines one of: contactId, userSuppliedId or shopperId | ||
* @param contactId the ID of the contact | ||
* @param options the number of seconds the shopper token will be valid for *OR* a GenerateShopperTokenOptions object | ||
* @returns the shopper token | ||
*/ | ||
function generateShopperToken(contact, options) { | ||
function generateShopperToken(contactId, options) { | ||
if (!exports.configuration.apiKey) { | ||
@@ -133,14 +133,8 @@ throw new Error("apiKey not set"); | ||
} | ||
if (!contact) { | ||
throw new Error("contact not set"); | ||
if (contactId == null) { | ||
throw new Error("contactId must be a string (can be empty)"); | ||
} | ||
if (!contact.contactId && !contact.userSuppliedId && contact.shopperId == null) { | ||
throw new Error("one of contact.contactId, contact.userSuppliedId or contact.shopperId must be set"); | ||
} | ||
let validityInSeconds = 43200; | ||
let metadata; | ||
if (typeof options === "number") { | ||
validityInSeconds = options; | ||
} | ||
else if (options) { | ||
if (options) { | ||
if (typeof options.validityInSeconds === "number") { | ||
@@ -165,5 +159,3 @@ validityInSeconds = options.validityInSeconds; | ||
gmi: merchantJwtPayload.g.gmi, | ||
coi: contact.contactId || undefined, | ||
cui: contact.userSuppliedId || undefined, | ||
shi: typeof (contact.shopperId) === "string" ? contact.shopperId : undefined | ||
coi: contactId | ||
}, | ||
@@ -170,0 +162,0 @@ metadata: metadata || undefined, |
export * from "./Contact"; | ||
export * from "./ContactIdentifier"; | ||
export * from "./PaginatedResponse"; | ||
export * from "./Program"; | ||
export * from "./Transaction"; |
{ | ||
"name": "lightrail-client", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "A Javascript and Typescript client for Lightrail", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
55207
89
1137