lucchetto (master) doxdox documentation

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

# _addBaselineStyles()

_addBaselineStyles Adds baseline styles to the page, used by all AnchorJS links irregardless of configuration.

# _applyRemainingDefaultOptions(opts)

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

Parameters

Name Types Description
opts Object - Options object

# _getElements(input)

Turns a selector, nodeList, or array of elements into an array of elements (so we can use array methods). It also throws errors on any other inputs. Used to handle inputs to .add and .remove.

Parameters

Name Types Description
input String Array

# this.add(selector)

Add anchor links to page elements.

Parameters

Name Types Description
selector String Array

# this.hasAnchorJSLink(el)

Determines if this element already has an AnchorJS link on it. Uses this technique: http://stackoverflow.com/a/5898748/1154642

Parameters

Name Types Description
el HTMLElemnt - a DOM node

# 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

# this.remove(selector)

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

Parameters

Name Types Description
selector String Array

# this.removeAll()

Removes all anchorjs links. Mostly used for tests.

# 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 Types Description
text String - Any text. Usually pulled from the webpage element we are linking to.

# async(url, detail)

Retrieve data for a SKU. The IAP SKU data (sku, price, within) must first be onboarded onto a Lucchetto extended RS server.

Parameters

Name Types Description
url string - the URL to your, the developer's, Lucchetto extended RS server that contains your IAP SKU definitions.
detail * - the detail object from the pay2myapp-appsell-sku-clicked event, see https://www.npmjs.com/package/pay2my.app

# Lucchetto(options, options.remoteStorage, options.overhideIsTest, options.pay2myAppHub, options.overhideApiKey)

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 Types 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. *

# 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

# 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

# METADATA_REGEX()

# pay2my.app()