npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arc-publishing/sdk-swg

v1.79.0

Published

SDK for using Subscribe with Google with Arc Subscriptions

Downloads

275

Readme

@arc-publishing/sdk-swg

The Arc SwG SDK is an out of the box SDK to integrate Subscribe with Google with your Front End article/paywall, checkout and login pages.

This SDK is responsible for the following:

  • initializes SwG.js when a visitor loads the page
  • handles various Subscribe with Google flows:
    • Syncing entitlements between Arc and Google & vice versa on article reads and on login
    • Handle purchase responses from Google’s web Subscribe with Google flows to sync Subscribe with Google purchases with Arc
  • provides callbacks for your application to use to: - handle syncing on login - linking an Arc purchase of a SwG enabled product with SwG - pass to Arc Paywall to check Google entitlements for paywalling purposes

Pre-requisites

  • Article pages are annotated with SwG JSON-LD annotations
  • swg.js is loaded on the page
<script
  async
  subscriptions-control="manual"
  src="https://news.google.com/swg/js/v1/swg.js"
></script>
  • Google's Auth2 SDK is loaded on the page
<script>
  window.ongoogleload = function() {
    window.gapi.load('auth2');
  };
</script>
<script src="https://apis.google.com/js/platform.js" onload="window.ongoogleload()"></script>
  • Arc Identity and Sales SDKs are installed in your application and used for auth and checkout.

Usage

import initSwg from '@arc-publishing/sdk-swg/lib';
initSwg({
  Identity, // required: fully initialized Arc Identity SDK
  Sales, // required: fully initialized Arc Sales SDK
  googleAuth, // required: fully initialized Google Auth2 SDK
  swgSku, // required: swg sku, in this format: "{site}:{sku}", i.e. "example.com:premium"
  onSwgPaymentSuccess, // required: callback function for when a user successfully checks out from Subscribe with Google dialogs. Usually used to reroute the user to the homepage, or the
  onLoginRequest, // required: callback function for when a user clicks "already subscribed" on SwG checkout screens. This should direct the user to the login screen on your site.
  customOnRejectConsent, // optional: custom handler for user rejecting consent
  customEntitlementsHandler, // optional: custom handler for comparing swg entitlement to user entitlements which should take care of any necessary logging in, linking or creating new accounts to ensure user is allowed access if the entitlement exists.
  customSwgPaymentHandler, // optional: custom handler for ensuring Arc and google are aware of swg subscription purchases
  customLoginHandler, // optional: custom handler for linking Arc subscriptions to SwG or vice versa when a user logs in.
  customIsSwgEntitledCheck, // optional: custom handler for checking whether or not a logged in user has a SwG entitlement.
  customLinkToSwgHandler //optional: custom handler for linking an Arc purchase of a SwG enabled product to a user's Google account
}).then(
  ({
    swg, // swg subscriptions object. see: https://github.com/subscriptions-project/swg-js/blob/master/docs/core-apis.md
    entitlementsHandler, // returns either the default SwG entitlements handler, or your custom entitlements handler
    isSwgEntitledCheck, // returns either the default isSwgEntitledCheck, or your custom check. This should be passed to ArcP.run() as an option for checking whether or not a logged in user has a SwG entitlement.
    loginHandler, // returns either the default loginHandler, or your custom login handler. This is used to link Arc subscriptions to SwG or vice versa when a user logs in.
    linkToSwgHandler // returns either the default linkToSwgHandler, or your custom linkToSwgHandler. This is used to link an Arc purchase of a SwG enabled product to a user's Google account
  }) => {
    // render your application
  }
);