Skip to content

Commit

Permalink
feat: Update NPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
art7cf committed Feb 3, 2024
1 parent d7ae987 commit 74f79bf
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 47 deletions.
92 changes: 59 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,86 @@
<img alt="Nepflow widget with 6,000+ Zapier integrations" src="https://github.com/nepflow/integration-widget/raw/main/assets/intro-v3.png" style="max-width: 800px; width: 100%; margin-bottom: 24px;" />

# Integration Widget

The widget allows your users to explore **6,000+ Zapier integrations** right inside your app.

[![Production Deployment](https://github.com/nepflow/integration-widget/actions/workflows/production.yaml/badge.svg?branch=main)](https://github.com/nepflow/integration-widget/actions/workflows/production.yaml)
[![@nepflow/integration-widget.svg](https://img.shields.io/npm/v/@nepflow/integration-widget.svg)](https://www.npmjs.com/package/@nepflow/integration-widget)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

[Get started](#getting-started)[Live Demo](https://demo.nepflow.dev/)[Build Widget](https://demo.nepflow.dev/)[Documentation](https://docs.nepflow.dev/)
[Get started](#installation)[Live Demo](https://demo.nepflow.dev/)[Build Widget](https://demo.nepflow.dev/)[Documentation](https://docs.nepflow.dev/)

<img alt="Nepflow widget with 6,000+ Zapier integrations" src="https://raw.githubusercontent.com/nepflow/integration-widget/main/web/assets/intro-v3.png" style="max-width: 800px; width: 100%; margin: 12px 0;" />

## Getting started
## Installation

You can use [the online builder](https://demo.nepflow.dev) to customize the widget and get the installation code.

### Use installation script
### Node.js package

If your app is integrated with [Zapier](https://zapier.com/):
Install the package via NPM or Yarn

```bash
npm i @nepflow/integration-widget --save
```

Include module in your application

```
import IntegrationWidget from '@nepflow/integration-widget';
```

### Load from CDN

You can load specific version of package from [jsDelivr CDN](https://www.jsdelivr.com/package/npm/@nepflow/integration-widget).

```html
<script src="https://cdn.jsdelivr.net/npm/@nepflow/integration-widget@1/dist/cjs/index.min.js"></script>
```

## Configuration

### Add element

Create an element that should contain the widget
```html
<div id="integration-widget"></div>
```

### Initialization

If your app is integrated with [Zapier](https://zapier.com/):

<script src="https://widget.nepflow.dev/loader-v1.js"></script>
<script>
nepflowWidget.load('integration-widget', {
```javascript
const widget = IntegrationWidgetConfig(
'integration-widget', // Element ID
{
zapierAppId: '<ZAPIER APP ID>', // Your Zapier app ID or slug
backgroundColor: '#f5f5f5',
cardColor: '#fff',
cardBorderColor: '#fff',
innerSpace: 24,
autoVerticalResize: true
});
</script>
}
);
```

You can use `customIntegrations` parameter to show your native integrations:
You can use `customCards` parameter to show your native integrations:

```html
<div id="integration-widget"></div>

<script src="https://widget.nepflow.dev/loader-v1.js"></script>
<script>
nepflowWidget.load('integration-widget', {
```javascript
const widget = IntegrationWidgetConfig(
'integration-widget', // Element ID
{
zapierAppId: '<ZAPIER APP ID>', // Your Zapier app ID or slug
backgroundColor: '#f5f5f5',
cardColor: '#fff',
cardBorderColor: '#fff',
innerSpace: '24px',
autoVerticalResize: true,
customIntegrations: [
// Showing a new integration in the catalog
customCards: [
// Showing a custom integration in the catalog
{
id: 'new_integration',
name: 'New Integration',
iconURL: 'https://example.com/new_integration.png'
id: 'custom_integration',
name: 'Custom Integration',
iconURL: 'https://example.com/foobar.png'
},

// Replacing an existing Zapier app in the catalog
Expand All @@ -66,18 +94,16 @@ You can use `customIntegrations` parameter to show your native integrations:
onCardClick: function(id) {
alert(id + ' clicked!')
}
});
</script>
}
);
```

If your app is not integrated with Zapier yet:

```html
<div id="integration-widget"></div>

<script src="https://widget.nepflow.dev/loader-v1.js"></script>
<script>
nepflowWidget.load('integration-widget', {
```javascript
const widget = IntegrationWidgetConfig(
'integration-widget', // Element ID
{
backgroundColor: '#f5f5f5',
cardColor: '#fff',
cardBorderColor: '#fff',
Expand All @@ -86,8 +112,8 @@ If your app is not integrated with Zapier yet:
onCardClick: function(id) {
alert(id + ' clicked!')
}
});
</script>
}
);
```

### Use with your existing framework
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div id="app"></div>
<script>
window.$docsify = {
name: 'Integration Widget',
name: 'Integration Widget Docs',
repo: 'nepflow/integration-widget',
themeColor: '#265cff',
homepage: 'https://raw.githubusercontent.com/nepflow/integration-widget/main/README.md'
Expand Down
118 changes: 118 additions & 0 deletions package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<img alt="Nepflow widget with 6,000+ Zapier integrations" src="https://raw.githubusercontent.com/nepflow/integration-widget/main/web/assets/intro-v3.png" style="max-width: 800px; width: 100%; margin-bottom: 24px;" />

# Integration Widget

The widget allows your users to explore **6,000+ Zapier integrations** right inside your app.

[![Production Deployment](https://github.com/nepflow/integration-widget/actions/workflows/production.yaml/badge.svg?branch=main)](https://github.com/nepflow/integration-widget/actions/workflows/production.yaml)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

[Get started](#getting-started)[Live Demo](https://demo.nepflow.dev/)[Build Widget](https://demo.nepflow.dev/)[Documentation](https://docs.nepflow.dev/)

## Getting started

You can use [the online builder](https://demo.nepflow.dev) to customize the widget and get the installation code.

### Use installation script

If your app is integrated with [Zapier](https://zapier.com/):

```html
<div id="integration-widget"></div>

<script src="https://widget.nepflow.dev/loader-v1.js"></script>
<script>
nepflowWidget.load('integration-widget', {
zapierAppId: '<ZAPIER APP ID>', // Your Zapier app ID or slug
backgroundColor: '#f5f5f5',
cardColor: '#fff',
cardBorderColor: '#fff',
innerSpace: 24,
autoVerticalResize: true
});
</script>
```

You can use `customIntegrations` parameter to show your native integrations:

```html
<div id="integration-widget"></div>

<script src="https://widget.nepflow.dev/loader-v1.js"></script>
<script>
nepflowWidget.load('integration-widget', {
zapierAppId: '<ZAPIER APP ID>', // Your Zapier app ID or slug
backgroundColor: '#f5f5f5',
cardColor: '#fff',
cardBorderColor: '#fff',
innerSpace: '24px',
autoVerticalResize: true,
customIntegrations: [
// Showing a new integration in the catalog
{
id: 'new_integration',
name: 'New Integration',
iconURL: 'https://example.com/new_integration.png'
},
// Replacing an existing Zapier app in the catalog
{
id: 'gmail',
name: 'Gmail',
iconURL: 'https://example.com/gmail.png',
replacedZapierAppId: 'gmail'
},
],
onCardClick: function(id) {
alert(id + ' clicked!')
}
});
</script>
```

If your app is not integrated with Zapier yet:

```html
<div id="integration-widget"></div>

<script src="https://widget.nepflow.dev/loader-v1.js"></script>
<script>
nepflowWidget.load('integration-widget', {
backgroundColor: '#f5f5f5',
cardColor: '#fff',
cardBorderColor: '#fff',
innerSpace: 24,
autoVerticalResize: true,
onCardClick: function(id) {
alert(id + ' clicked!')
}
});
</script>
```

### Use with your existing framework

- [**React JS**](https://github.com/nepflow/react-integration-widget/)

## Parameters

You can pass any of these parameters for your widget:

| Parameter | Description | Type | Default |
|--------------------|----------------------------------------------------|----------------------------------------------------|-----------|
| zapierAppId | Your Zapier app ID or slug | `string` | #f5f5f5 |
| backgroundColor | The widget's background color (hex) | `string` | #ffffff |
| cardColor | The color for the card components (hex) | `string` | #ffffff |
| cardBorderColor | Card component border color (hex) | `string` | #ffffff |
| innerSpace | The padding inside the widget (px) | `number` | 24 |
| verticalAutoResize | Enables automatic vertical resizing for the iframe | `boolean` | false |
| onCardClick | Called when card is clicked | `(id: string) => void` | - |
| customIntegrations | Array of custom or native integrations | `{ id: string; name: string; iconURL: string; replacedZapierAppId: string; }[]` | [] |

## Technical Support or Questions

If you have questions or need help integrating the editor please [contact us](https://nepflow.dev/contact-us) instead of opening an issue.

## License

Apache License 2.0
9 changes: 5 additions & 4 deletions package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "integration-widget",
"version": "1.0.0",
"name": "@nepflow/integration-widget",
"version": "1.1.0",
"description": "",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand All @@ -13,8 +13,8 @@
"build": "yarn build:esm && yarn build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir dist/cjs",

"prepare": "npm run build"
"copy-readme": "cp ../README.md ./README.md",
"prepare": "npm run build && npm run copy-readme"
},
"files": [
"dist",
Expand All @@ -27,6 +27,7 @@
"integrations",
"widget"
],
"private": false,
"author": "",
"license": "Apache-2.0",
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions package/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import load from './utils/load'
import { IntegrationWidget } from './models/IntegrationWidget'
import { IntegrationWidgetConfig } from './models/IntegrationWidgetConfig'

export { load }
export { IntegrationWidgetConfig };
export default IntegrationWidget;
61 changes: 61 additions & 0 deletions package/src/models/IntegrationWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { IntegrationWidgetConfig } from "./IntegrationWidgetConfig";

export class IntegrationWidget {
private readonly baseUrl: string;

constructor(elementId: string, params: IntegrationWidgetConfig) {
this.baseUrl = 'https://widget.nepflow.dev';

const widgetElement = document.getElementById(elementId);
if (!widgetElement) {
console.error('Integration widget element not found.');
return;
}

// Create URLSearchParams from the params object
const searchParams = new URLSearchParams();
for (const [key, value] of Object.entries(params)) {
if (typeof value === 'boolean') {
searchParams.append(key, value ? 'true' : '');
} else if (typeof value === 'object') {
searchParams.append(key, JSON.stringify(value));
} else if (value) {
searchParams.append(key, value.toString());
}
}

// Create the iframe element
const iframe = document.createElement('iframe');
iframe.src = `${this.baseUrl}/${params.zapierAppId || ''}?${searchParams.toString()}`;
iframe.style.width = '100%';
iframe.style.height = '100%';
iframe.style.minHeight = '500px';
iframe.frameBorder = '0';

// Append the iframe to the integration-widget element
widgetElement.innerHTML = '';
widgetElement.appendChild(iframe);

// Handler for messages from the iframe
window.addEventListener('message', (event) => {
if (!event.origin.startsWith(this.baseUrl)) {
console.debug('[Nepflow] Received message from unknown origin:', event.origin);
return;
}

const { action, data } = event.data;
console.debug('[Nepflow] Received message:', action, data);

switch (action) {
case 'setWidgetHeight':
iframe.style.height = `${data.widgetHeight}px`;
break;
case 'handleCardClick':
if (typeof params.onCardClick === 'function') {
params.onCardClick(data.serviceId);
};
break;
}
});
}
}
10 changes: 10 additions & 0 deletions package/src/models/IntegrationWidgetConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
interface CustomCard {
id: string;
name: string;
iconURL: string;
replacedZapierAppId: string;
}

export interface IntegrationWidgetConfig {
zapierAppId: string;
backgroundColor: string;
cardColor: string;
cardBorderColor: string;
innerSpace: number;
autoVerticalResize: boolean;
onCardClick: (id: string) => void;
customCards: CustomCard[];
}
7 changes: 0 additions & 7 deletions package/src/utils/load.ts

This file was deleted.

0 comments on commit 74f79bf

Please sign in to comment.