0.17.0 • Published 7 months ago

@swishapp/node v0.17.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
7 months ago

Swish app proxy for Node.js

The Swish browser library requires a proxy service that operates on the same domain as the store. This service facilitates the loading of additional resources and ensures secure communication with the Swish API.

Installation

npm i @swishapp/node

Usage

The example below is for Remix and needs to be adjusted for other frameworks.

import { ActionFunction, LoaderFunction } from "@remix-run/node";
import { createAppProxy, MemoryStorage } from "@swishapp/node";

const swishProxy = createAppProxy({
  basePath: "/swish", // Needs to match the route path
  authToken: process.env.SWISH_API_TOKEN,
  storage: new MemoryStorage(), // Use MemoryStorage for development only!
  authenticate: async (request) => {
    // Authenticate the request and return customer id or null
    // Throw an error if the request cannot be authenticted
    return null;
  },
  onError: (error) => {
    console.error(error);
  },
});

export const loader: LoaderFunction = async ({ request }) =>
  swishProxy.forward(request);

export const action: ActionFunction = async ({ request }) =>
  swishProxy.forward(request);

The Swish app for browsers won't work on the server. Use it as a client only script!

// The proxy also serves the Swish brwoser app
import { createApp } from "/swish/assets/swish.js"; // Assuming the proxy runs on /swish

const swish = await createApp({
  proxy: {
    baseUrl: "/swish", // Use proxy route path
  },
});

Documentation

For more information visit Swish DEV docs.

0.17.0

7 months ago

0.16.1

7 months ago

0.15.0

8 months ago

0.14.0

8 months ago

0.13.0

8 months ago

0.12.0

8 months ago

0.11.0

9 months ago

0.10.1

9 months ago

0.10.0

9 months ago

0.9.0

9 months ago

0.8.0

9 months ago

0.7.0

10 months ago

0.6.1

10 months ago

0.6.0

10 months ago

0.5.0

10 months ago

0.4.0

10 months ago

0.3.0

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago