@jargon/sdk-core
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -0,1 +1,8 @@ | ||
### 1.2.0 | ||
Expose variation selection logic in ResourceManager | ||
This is intended for use by Jargon's voxa plugin, so it can select | ||
variations after such things as selecting a platform specific message | ||
object. | ||
### 1.1.2 | ||
@@ -2,0 +9,0 @@ Fix bug returning selected variations |
@@ -13,2 +13,3 @@ import * as i18n from 'i18next'; | ||
renderObject<T>(item: RenderItem): Promise<T>; | ||
selectVariationFromObject(item: RenderItem, obj: any): Promise<string>; | ||
selectedVariation(item: RenderItem): Promise<SelectedVariation>; | ||
@@ -15,0 +16,0 @@ selectedVariations(): Promise<SelectedVariation[]>; |
@@ -76,3 +76,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var params, s, key, v, fk, sv; | ||
var params, s; | ||
return __generator(this, function (_a) { | ||
@@ -93,17 +93,3 @@ switch (_a.label) { | ||
else if (typeof s === 'object') { | ||
key = this.selectKey(Object.keys(s), item.options); | ||
v = s[key]; | ||
fk = item.key + "." + key; | ||
if (typeof v !== 'string') { | ||
return [2 /*return*/, Promise.reject(new Error("Unexpected type " + typeof v + " for item key " + fk))]; | ||
} | ||
if (this._opts.trackSelectedVariations) { | ||
sv = { | ||
item: item, | ||
key: fk, | ||
variationKey: key | ||
}; | ||
this._selectedVariants.push(sv); | ||
} | ||
return [2 /*return*/, Promise.resolve(v)]; | ||
return [2 /*return*/, this.selectVariationFromObject(item, s)]; | ||
} | ||
@@ -156,2 +142,19 @@ return [2 /*return*/, Promise.reject(new Error("Unexpected type " + typeof s + " for item key " + item.key))]; | ||
}; | ||
I18NextResourceManager.prototype.selectVariationFromObject = function (item, obj) { | ||
var key = this.selectKey(Object.keys(obj), item.options); | ||
var v = obj[key]; | ||
var fk = item.key + "." + key; | ||
if (typeof v !== 'string') { | ||
return Promise.reject(new Error("Unexpected type " + typeof v + " for item key " + fk)); | ||
} | ||
if (this._opts.trackSelectedVariations) { | ||
var sv = { | ||
item: item, | ||
key: fk, | ||
variationKey: key | ||
}; | ||
this._selectedVariants.push(sv); | ||
} | ||
return Promise.resolve(v); | ||
}; | ||
I18NextResourceManager.prototype.selectedVariation = function (item) { | ||
@@ -169,3 +172,3 @@ var v = this._selectedVariants.filter(function (i) { return i.item === item; }); | ||
var rv = this._rv; | ||
if (opts && opts.forceNewRandom || !this._opts.consistentRandom) { | ||
if ((opts && opts.forceNewRandom) || !this._opts.consistentRandom) { | ||
rv = Math.random(); | ||
@@ -172,0 +175,0 @@ } |
@@ -52,2 +52,10 @@ import { I18NextResourceManagerFactory } from './i18next'; | ||
renderObject<T>(item: RenderItem): Promise<T>; | ||
/** Selects a variation from an object. This method is intended to be used by frameworks | ||
* that layer additional semantics onto resources (e.g., Voxa) but wish to leverage Jargon's | ||
* variation selection logic. | ||
* @param {RenderItem} item The RenderItem originally used to render obj. Used only for selection tracking | ||
* @param {any} obj The object to select the variation from. While it's not required, this object presumably | ||
* came from a previous renderObject operation (or is a portion of such an object) | ||
*/ | ||
selectVariationFromObject(item: RenderItem, obj: any): Promise<string>; | ||
/** Retrieves information about the selected variant for a rendered item. This | ||
@@ -54,0 +62,0 @@ * will only return a result when rendering the item required a variation |
{ | ||
"name": "@jargon/sdk-core", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Core components of Jargon's NodeJS SDK", | ||
@@ -32,3 +32,3 @@ "author": "jargon.com", | ||
"nyc": "^13.0.1", | ||
"ts-node": "^7.0.1", | ||
"ts-mocha": "^6.0.0", | ||
"tslint": "^5.11.0", | ||
@@ -49,3 +49,4 @@ "tslint-config-standard": "^8.0.1", | ||
"scripts": { | ||
"gulp": "./node_modules/.bin/gulp" | ||
"gulp": "./node_modules/.bin/gulp", | ||
"test": "./node_modules/.bin/ts-mocha tst/**/*.spec.ts" | ||
}, | ||
@@ -52,0 +53,0 @@ "bugs": { |
@@ -165,2 +165,11 @@ # `@jargon/sdk-core` | ||
/** Selects a variation from an object. This method is intended to be used by frameworks | ||
* that layer additional semantics onto resources (e.g., Voxa) but wish to leverage Jargon's | ||
* variation selection logic. | ||
* @param {RenderItem} item The RenderItem originally used to render obj. Used only for selection tracking | ||
* @param {any} obj The object to select the variation from. While it's not required, this object presumably | ||
* came from a previous renderObject operation (or is a portion of such an object) | ||
*/ | ||
selectVariationFromObject (item: RenderItem, obj: any): Promise<string> | ||
/** Retrieves information about the selected variant for a rendered item. This | ||
@@ -167,0 +176,0 @@ * will only return a result when rendering the item required a variation |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68094
732
274