Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jargon/alexa-skill-sdk

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jargon/alexa-skill-sdk - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

8

CHANGELOG.md

@@ -0,1 +1,9 @@

### 1.0.4
#### Suport RenderItem instances as RenderParams values
The use of a RenderItem instance as a parameter value makes it easy to compose multiple
resource together at runtime. This is useful when a parameter value varies across locales,
or when you want the SDK to select across multiple variations for a parameter value, and reduces
the need to chain together multiple calls into the ResourceManager.
### 1.0.3

@@ -2,0 +10,0 @@ * Add ResourceManager.selectedVariation\[s\]()

3

dist/resourceManager/i18next.d.ts
import * as i18n from 'i18next';
import { RenderItem, ResourceManager, ResourceManagerFactory, ResourceManagerOptions, RenderOptions, SelectedVariation } from '.';
import { RenderItem, ResourceManager, ResourceManagerFactory, ResourceManagerOptions, RenderOptions, SelectedVariation, RenderParams } from '.';
export declare class I18NextResourceManager implements ResourceManager {

@@ -16,2 +16,3 @@ protected _translator: i18n.i18n;

protected selectKey(keys: string[], opts?: RenderOptions): string;
protected processParams(params: RenderParams): Promise<RenderParams>;
}

@@ -18,0 +19,0 @@ export declare class I18NextResourceManagerFactory implements ResourceManagerFactory {

@@ -14,2 +14,37 @@ "use strict";

*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values = (this && this.__values) || function (o) {

@@ -40,24 +75,39 @@ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;

I18NextResourceManager.prototype.render = function (item) {
var s = this._translator.t(item.key, item.params);
if (typeof s === 'string') {
return Promise.resolve(s);
}
else if (typeof s === 'object') {
var key = this.selectKey(Object.keys(s), item.options);
var v = s[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: v
};
this._selectedVariants.push(sv);
}
return Promise.resolve(v);
}
return Promise.reject(new Error("Unexpected type " + typeof s + " for item key " + item.key));
return __awaiter(this, void 0, void 0, function () {
var params, s, key, v, fk, sv;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
params = item.params;
if (!params) return [3 /*break*/, 2];
return [4 /*yield*/, this.processParams(params)];
case 1:
params = _a.sent();
_a.label = 2;
case 2:
s = this._translator.t(item.key, params);
if (typeof s === 'string') {
return [2 /*return*/, Promise.resolve(s)];
}
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: v
};
this._selectedVariants.push(sv);
}
return [2 /*return*/, Promise.resolve(v)];
}
return [2 /*return*/, Promise.reject(new Error("Unexpected type " + typeof s + " for item key " + item.key))];
}
});
});
};

@@ -108,2 +158,37 @@ I18NextResourceManager.prototype.renderBatch = function (items) {

};
I18NextResourceManager.prototype.processParams = function (params) {
return __awaiter(this, void 0, void 0, function () {
var copied, _a, _b, _i, k, v, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
copied = false;
_a = [];
for (_b in params)
_a.push(_b);
_i = 0;
_e.label = 1;
case 1:
if (!(_i < _a.length)) return [3 /*break*/, 4];
k = _a[_i];
v = params[k];
if (!(typeof v === 'object')) return [3 /*break*/, 3];
if (!copied) {
params = Object.assign({}, params);
copied = true;
}
_c = params;
_d = k;
return [4 /*yield*/, this.render(v)];
case 2:
_c[_d] = _e.sent();
_e.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, params];
}
});
});
};
return I18NextResourceManager;

@@ -110,0 +195,0 @@ }());

@@ -75,3 +75,3 @@ export interface ResourceManagerOptions {

export interface RenderParams {
[param: string]: string | number;
[param: string]: string | number | RenderItem;
}

@@ -78,0 +78,0 @@ /**

{
"name": "@jargon/alexa-skill-sdk",
"version": "1.0.3",
"version": "1.0.4",
"description": "The Jargon Alexa Skill SDK makes it easy to manage the content of your custom Alexa skill",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -107,11 +107,35 @@ # Jargon SDK for Amazon Alexa (nodejs)

`RenderParams` have your parameter names as keys, and either a string or number for values.
`RenderParams` are a map from parameter name to a string, number, or `RenderItem` instance.
```typescript
interface RenderParams {
[param: string]: string | number | RenderItem
}
```
The `ri` helper function simplifies constructing a RenderItem:
```javascript
The use of a `RenderItem` instance as a parameter value makes it easy to compose multiple
resource together at runtime. This is useful when a parameter value varies across locales,
or when you want the SDK to select across multiple variations for a parameter value, and reduces
the need to chain together multiple calls into the `ResourceManager`.
The `ri` helper function simplifies constructing a `RenderItem`:
```typescript
function ri (key: string, params?: RenderParams, options?: RenderOptions): RenderItem
handlerInput.jrb.speak(ri('sayHello', { 'name': 'World' }))
```
`RenderOptions` allows fine-grained control of rendering behavior for a specific call, overriding
the configuration set at the `ResourceManager` level.
```typescript
interface RenderOptions {
/** When true, forces the use of a new random value for selecting variations,
* overriding consistentRandom
*/
readonly forceNewRandom?: boolean
}
```
### JargonSkillBuilder
This wraps the ASK skill builder, and handles all details of intializing the Jargon SDK,
`JargonSkillBuilder` wraps the ASK skill builder, and handles all details of intializing the Jargon SDK,
installing request and response interceptors, and so on.

@@ -211,3 +235,2 @@ ```javascript

## Setting up a new skill

@@ -214,0 +237,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc