Skip to content

Commit 6cda6af

Browse files
feat: remove rollup, add nextjs support.
1 parent e164c94 commit 6cda6af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+14739
-44299
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,30 @@
1010
npm install --save use-pluggy-connect
1111
```
1212

13+
or
14+
15+
```bash
16+
pnpm install --save use-pluggy-connect
17+
```
18+
19+
or
20+
21+
```bash
22+
yarn add use-pluggy-connect
23+
```
24+
25+
or
26+
27+
```bash
28+
bun install --save use-pluggy-connect
29+
```
30+
1331
## Usage
1432

1533
```tsx
1634
import React, { useCallback } from 'react'
1735

18-
import { usePluggyConnect } from 'use-pluggy-connect'
36+
import usePluggyConnect from 'use-pluggy-connect'
1937

2038
const App = () => {
2139
const handleEvent = useCallback((payload) => {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use client'
22

3-
import { usePluggyConnect } from 'use-pluggy-connect'
3+
import usePluggyConnect from 'use-pluggy-connect'
44

55
export default function OpenPluggyButton() {
66
const { init } = usePluggyConnect({
77
connectToken:
88
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnRJZCI6IjBhZDdiMDNiLTUwZWQtNDc1OC04ODhkLTU2MGU1ZDVhYzBkYiIsImRhdGEiOiJjZDBlNjYxYTRlOWQ0N2Y1Y2Y3NWM0ZTI5YmQ4MTc1Yjo0ZGRhNDU4NjRkMDU2ZmY1ZWMzNWM1YTkwNzQ0MjBlZmJiM2E2ZjUyMjcyNThkN2Q3OWUxMGQ4ODQ3NzQ3NDllNTg2YTdhMzVlMTI1ZTRkMjQ1YTIwYjViYmRhNTQxZjdkYzFhNGEwMzhhNmEyNzhhYzFmNGVlZmZkNTFmMjlkNGNkYzgzZWZlMDdmMTg4ZWI4ZTIxYTgwYzM3YmI0MThiOTk3ZWE3MDg2NzYzYWVlZWM1MDg5NzkyMmFmZjI3NmVkYTMzMjlmNjc0NDBlMTdkOGJlMDZkMGYyZmQ4MzUyN2Y1ZTMxNjgxZjE4NDA2ZGVkMjY0YTZkMzQ2MDAwZGY1IiwiaWF0IjoxNzI0MjY3NjgzLCJleHAiOjE3MjQyNjk0ODN9.Wc3R8LQOP9KaI_7hR1EvhVPX73SdbMeF7VqBHnL7HLSnG3bv6WmFtYcyGVSBr_FEvN4q7vchDtJP1vNm0xV39NVbip8CtdYc8hraUiAZm1o-6ra0VVWB_rWciytPc7pX9CL9dhQNIwkVwhNqYNfJ6Pn6IMz_sT4_AA4AjKN2iJcjHA-ADpLJXfHWRbApxLwe-yDUANcR_34yJUm0TgJTX9zuxh9EP6T9scyWxnS40H7PkLu59KK-BNVmDJPXfatCue3wpwhl_vGYF3eP1kMROu-hfzQNBZ7toC7qtDqfzwW5hTmf9x_WH00BIYNaJrBgroA4lRBOCOAFjMB7EwTAdA',
99
})
10+
1011
return <button onClick={init}>Open Pluggy</button>
1112
}
File renamed without changes.

example-nextjs/package-lock.json examples/nextjs/package-lock.json

+5-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

example/package-lock.json examples/vite/package-lock.json

+7-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
File renamed without changes.

example/src/App.tsx examples/vite/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState } from 'react'
22
import reactLogo from './assets/react.svg'
33
import viteLogo from '/vite.svg'
44
import './App.css'
5-
import { usePluggyConnect } from 'use-pluggy-connect'
5+
import usePluggyConnect from 'use-pluggy-connect'
66

77
function App() {
88
const [count, setCount] = useState(0)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

example/tsconfig.app.json examples/vite/tsconfig.app.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"strict": true,
1919
"noUnusedLocals": true,
2020
"noUnusedParameters": true,
21-
"noFallthroughCasesInSwitch": true
21+
"noFallthroughCasesInSwitch": true,
22+
"esModuleInterop": true
2223
},
2324
"include": ["src"]
2425
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/index.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { PluggyConnectProps as PluggyConnectProps_ } from 'pluggy-connect-sdk';
2+
export type PluggyConnectProps = PluggyConnectProps_;
3+
declare const usePluggyConnect: (options: PluggyConnectProps) => {
4+
init: () => void;
5+
error: Error | null;
6+
ready: boolean;
7+
show: () => void;
8+
hide: () => void;
9+
};
10+
export default usePluggyConnect;

lib/index.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
var __generator = (this && this.__generator) || function (thisArg, body) {
11+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13+
function verb(n) { return function (v) { return step([n, v]); }; }
14+
function step(op) {
15+
if (f) throw new TypeError("Generator is already executing.");
16+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
17+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18+
if (y = 0, t) op = [op[0] & 2, t.value];
19+
switch (op[0]) {
20+
case 0: case 1: t = op; break;
21+
case 4: _.label++; return { value: op[1], done: false };
22+
case 5: _.label++; y = op[1]; op = [0]; continue;
23+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
24+
default:
25+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29+
if (t[2]) _.ops.pop();
30+
_.trys.pop(); continue;
31+
}
32+
op = body.call(thisArg, _);
33+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35+
}
36+
};
37+
import { useEffect, useState, useCallback, useRef } from 'react';
38+
var noop = function () { };
39+
var usePluggyConnect = function (options) {
40+
var _a = useState(null), error = _a[0], setError = _a[1];
41+
var _b = useState(null), pluggyConnect = _b[0], setPluggyConnect = _b[1];
42+
var pluggyConnectBase = useRef(null);
43+
useEffect(function () {
44+
var isBrowser = typeof window !== 'undefined';
45+
if (!isBrowser)
46+
return; // Exit the effect if not in the browser
47+
function loadPluggyConnect() {
48+
return __awaiter(this, void 0, void 0, function () {
49+
var PluggyConnect, pluggyConnect_;
50+
return __generator(this, function (_a) {
51+
switch (_a.label) {
52+
case 0:
53+
if (!options.connectToken) {
54+
throw new Error('use-pluggy-connect: You need a valid connectToken for usePluggyConnect.');
55+
}
56+
return [4 /*yield*/, import('pluggy-connect-sdk')];
57+
case 1:
58+
PluggyConnect = (_a.sent()).PluggyConnect;
59+
pluggyConnectBase.current = PluggyConnect;
60+
pluggyConnect_ = new PluggyConnect(options);
61+
setPluggyConnect(pluggyConnect_);
62+
return [2 /*return*/];
63+
}
64+
});
65+
});
66+
}
67+
loadPluggyConnect();
68+
}, [options.connectToken]);
69+
var init = useCallback(function () {
70+
if (!pluggyConnect) {
71+
throw new Error("use-pluggy-connect: PluggyConnect instance isn't ready yet.");
72+
}
73+
try {
74+
var containerElement = document.body ||
75+
document.documentElement ||
76+
document.getElementsByTagName('div')[0];
77+
pluggyConnect.init(containerElement);
78+
}
79+
catch (e) {
80+
if (e instanceof Error) {
81+
console.error('Failed to initialize PluggyConnect', e);
82+
setError(e);
83+
}
84+
}
85+
}, [pluggyConnect]);
86+
return {
87+
init: init,
88+
error: error,
89+
ready: Boolean(pluggyConnect),
90+
show: pluggyConnect ? pluggyConnect.show : noop,
91+
hide: pluggyConnect ? pluggyConnect.hide : noop,
92+
};
93+
};
94+
export default usePluggyConnect;

0 commit comments

Comments
 (0)