Back to Top

lucchetto master

Client side JavaScript helper utilities for working with pay2my.app widgets leveraging Armadietto+Lucchetto RS server implementations such as https://overhide.io#baas.

_applyRemainingDefaultOptions(opts)

Assigns options to the internal options object, and provides defaults.

Parameters

Name Type Description
opts Object
  • Options object

Returns

Void

this.isTouchDevice()

Checks to see if this device supports touch. Uses criteria pulled from Modernizr: https://github.com/Modernizr/Modernizr/blob/da22eb27631fc4957f67607fe6042e85c0a84656/feature-detects/touchevents.js#L40

Returns

Boolean

  • true if the current device supports touch.

this.add(selector)

Add anchor links to page elements.

Parameters

Name Type Description
selector String Array Nodelist
  • A CSS selector for targeting the elements you wish to add anchor links to. Also accepts an array or nodeList containing the relavant elements.

Returns

this

  • The AnchorJS object

this.remove(selector)

Removes all anchorjs-links from elements targed by the selector.

Parameters

Name Type Description
selector String Array Nodelist
  • A CSS selector string targeting elements with anchor links, OR a nodeList / array containing the DOM elements.

Returns

this

  • The AnchorJS object

this.removeAll()

Removes all anchorjs links. Mostly used for tests.

Returns

Void

this.urlify(text)

Urlify - Refine text so it makes a good ID.

To do this, we remove apostrophes, replace nonsafe characters with hyphens, remove extra hyphens, truncate, trim hyphens, and make lowercase.

Parameters

Name Type Description
text String
  • Any text. Usually pulled from the webpage element we are linking to.

Returns

String

  • hyphen-delimited text for use in IDs and URLs.

METADATA_REGEX()

Returns

Void

LUCCHETTO_PROVIDERS()

⚠ This may only be useful when connecting to users' remote-storage instances through a non-null remoteStorage constructor parameter.

List of lucchetto providing servers for production: these are shown as options in the RS widget dropdown, when the Lucchetto class is constructed with !isTest:

  • @rs.overhide.io

Returns

Void

LUCCHETTO_PROVIDERS_4_TEST()

⚠ This may only be useful when connecting to users' remote-storage instances through a non-null remoteStorage constructor parameter.

List of lucchetto providing servers for testnets: these are shown as options in the RS widget dropdown, when the Lucchetto class is constructed with isTest:

  • @test.rs.overhide.io
  • @localhost:8000

Returns

Void

new Lucchetto(options)

This class provides utility functions to fetch in-app purchase data from the app-developer's RS (+Lucchetto) connection. The in-app purchase data must first be onboarded onto a Lucchetto extended RS server.

A typical usage of this class with pay2my.app widgets might look like:


  var lucchetto = new Lucchetto({
      overhideIsTest: true, 
      pay2myAppHub: document.getElementById('hub-id-in-dom'),
      overhideApiKey: '0x42..cb'});
  ...
  window.addEventListener('pay2myapp-appsell-sku-clicked', async (e) => { 
    ...
    const result = await lucchetto.getSku(`https://test.rs.overhide.io`, e.detail);
    console.log(`got SKU results`, { sku: e.detail.sku , result });
    ...
 }, false);

  • Above, we're passing in the overhideApiKey for our use — get an API key for the right network, either testnet or mainnet. This is not a secret.

⚠ In the context of being connected to your users' remote-storage instances through a non-null remoteStorage constructor (first) parameter:

Reacts to remotestorage.js onConnected events to parse metadata out of newly available RS tokens.

If the connected RS server is Lucchetto extended, the token will provide metadata useful to pay2my.app in-app purchase widgets — making for a nicer end-user experience.

This class enriches the dropdown of the RS widget, if any, embedded in the DOM. The enrichment provides server hints as per LUCCHETTO_PROVIDERS and LUCCHETTO_PROVIDERS_4_TEST.

A typical usage of this class along with remotestorage.js and pay2my.app widgets might look like:


  var rsClient = new RemoteStorage();
  var lucchetto = new Lucchetto({
      remoteStorage: rsClient,
      overhideIsTest: true, 
      pay2myAppHub: document.getElementById('hub-id-in-dom'),
      overhideApiKey: '0x42..cb'});
  ...
  window.addEventListener('pay2myapp-appsell-sku-clicked', async (e) => { 
    ...
    const result = await lucchetto.getSku(`https://test.rs.overhide.io`, e.detail);
    console.log(`got SKU results`, { sku: e.detail.sku , result });
    ...
 }, false);

  • Above, we're also passing in the overhideApiKey for our use — get an API key for the right network, either testnet or mainnet. The overhideApiKey is optional since we'll usually leverage an overhide token from remoteStorage. But if the remoteStorage connected to our application is not to a Lucchetto extended RS server, it won't have the overhide token, and we need to fail back to this default key. This is not a secret.

Parameters

Name Type Description
options Object

the construction options

options.remoteStorage Object

the RS instance available from client. This is an RS instance connected to the the client-user's data. Set this to null if you're using lucchetto outside of a remote-storage app, just for the getSku(..) endpoint.

options.overhideIsTest bool

flag whether this is all working against testnets or mainnets/prod servers.

options.pay2myAppHub Object

pay2my.app hub to instrument with credentials coming out of the remoteStorage instance. If user connects with a Lucchetto extended remoteStorage, this hub will be instrumented. Otherwise the hub will need to ask for credentials on in-app purchase use.

options.overhideApiKey Object

the API key to use, get an API key for the right network, either testnet or mainnet. If the remoteStorage instance is provided and is a Lucchetto extended RS server, you may leave this as null: a Lucchetto extended RS server will provide a user-specific token to use with getSku(..) overhide connections. *

Returns

Void