New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@ask-utils/isp

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ask-utils/isp

Alexa ISP utilities

latest
Source
npmnpm
Version
3.11.0
Version published
Maintainers
1
Created
Source

ASK-Utils - ISP helpers

npm version License: MIT Maintainability Test Coverage Build Status logo

https://ask-utils.dev

NPM: https://www.npmjs.com/package/@ask-utils/isp

Alexa ISP (In Skill Purchasing) helpers. Easy, Shot, Simply.

Getting started

$ npm i -S @ask-utils/isp

Before ISP Utils

We have to take care of a lot of case to make a buy request.

import { getLocale } from 'ask-sdk-core'

const beforeISPUtils = {
  handle() {
    return true
  },
  async handler(handlerInput) {
  if (!handlerInput.serviceClientFactory) throw new Error('No service client')
  const client = handlerInput.serviceClientFactory.getMonetizationServiceClient()
  const { inSkillProducts } = await client.getInSkillProducts(getLocale(handlerInput.requestEnvelope))
  if (!inSkillProducts) throw new Error('No product')
  const product = inSkillProducts.find(product => product.name === 'YOUR_PPRODUCT_NAME')
  if (!product) throw new Error('no product')
  return handlerInput.responseBuilder
      .addDirective({
        'type': 'Connections.SendRequest',
        'name': 'Buy',
        'payload': {
          'InSkillProduct': {
            'productId': product.productId
          }
        },
        'token': 'correlationToken'
      })
      .getResponse()
  }
}

We just call our client. Don't have to find or filter API response lists.

import { ISPProductClient, getBuyProductDirective } from '@ask-utils/isp'
const afterISPUtils = {
  handle() {
    return true
  },
  async handler(handlerInput) {
    const client = new ISPProductClient(handlerInput)
    const product = await client.searchProduct({
      productName: 'YOUR_PPRODUCT_NAME'
    })
    if (!product) throw new Error('no product')
    return handlerInput.responseBuilder
      .addDirective(getBuyProductDirective(product.productId))
      .getResponse()
  }
}

Interceptors

Load ISP data

If start a new Session, it call ISP API to get your products and set to the session attributes. The idea is from this blog post. https://developer.amazon.com/ja/blogs/alexa/post/75ee61df-8365-44bb-b28f-e708000891ad/how-to-use-interceptors-to-simplify-handler-code-and-cache-product-and-purchase-information-in-monetized-alexa-skills

import { loadISPDataInterceptor } from '@ask-utils/isp'

// add interceptor
.addRequestInteceptor(loadISPDataInterceptor)

You can get the products by the following code.


// get product from session attributes
import { getAllEntitledProducts } from '@ask-utils/isp'

const { inSkillProducts } = handlerInput.attributesManager.getSessionAttributes()
const entitledProducts = getAllEntitledProducts(inSkillProducts)

General Handlers

You can add several handlers for ISP request.

import { SkillBuilders } from 'ask-sdk'
import {
  ISPHandlers,
  loadISPDataInterceptor
} from '@ask-utils/isp'


SkillBuilders.standard()
  .addRequestHandlers(
    ...ISPHandlers,
  )
  .addRequestInterceptors(
    loadISPDataInterceptor
  )
  .lambda()

development

$ git clone git@github.com:ask-utils/isp.git
$ cd isp
$ npm i

test

$ npm test

Lint

$ npm run lint

or

$ npm run lint -- --fix

History

-> Release Note

Contributors

NameVersion

Keywords

alexa

FAQs

Package last updated on 27 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts