@swirepay-developer/sparo-embed-sdk 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/GATEWAY-REACT-GUIDE.md +107 -45
- package/README.md +6 -6
- package/SPARO-EMBEDDING.md +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -0
- package/package.json +4 -182
- package/dist/index.cjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
- Fix DevOps publish: rename `eslint.config.js` → `eslint.config.mjs` and `vitest.config.js` → `vitest.config.mjs` (ESM configs without `"type": "module"` on package).
|
|
6
|
+
- Add `scripts/check-publish-manifest.mjs` and `scripts/ensure-dev-deps.mjs` (clear error if `npm ci` was skipped).
|
|
7
|
+
- Lint uses explicit `node_modules/eslint` path so publish fails with a clear message when devDeps are missing.
|
|
8
|
+
- `check-publish-manifest.mjs` blocks publish if `npm init` added bogus `dependencies` (restore with `git checkout -- package.json`).
|
|
9
|
+
- Added `scripts/devops-publish.sh` for one-command DevOps publish.
|
|
10
|
+
- `publishConfig.access` set to **`public`** (fixes npm `402 Payment Required` for private packages).
|
|
11
|
+
- Gateway should use `@swirepay-developer/sparo-embed-sdk@^1.0.5` after publish.
|
|
12
|
+
|
|
3
13
|
## 1.0.4
|
|
4
14
|
|
|
5
|
-
-
|
|
15
|
+
- Published on npm as **`@swirepay-developer/sparo-embed-sdk`** (org scope `swirepay-developer`).
|
|
16
|
+
- Gateway must import `@swirepay-developer/sparo-embed-sdk` — **not** `@swirepay/sparo-embed-sdk`.
|
|
17
|
+
- Target release for gateway npm install (`@swirepay-developer/sparo-embed-sdk@^1.0.4`).
|
|
6
18
|
- Includes publish pipeline fixes and correct `dist/index.js` / `dist/index.mjs` entry points.
|
|
7
19
|
|
|
8
20
|
## 1.0.1
|
package/GATEWAY-REACT-GUIDE.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# Gateway Frontend — SPARO SDK Integration Guide (React)
|
|
2
2
|
|
|
3
|
-
Step-by-step guide for **gateway-frontend** React developers integrating `@swirepay/sparo-embed-sdk` from npm.
|
|
3
|
+
Step-by-step guide for **gateway-frontend** React developers integrating `@swirepay-developer/sparo-embed-sdk` from npm.
|
|
4
4
|
|
|
5
5
|
> **Prerequisite:** DevOps must publish the SDK from Bitbucket first.
|
|
6
6
|
> Repo: https://bitbucket.org/zetametrics/sparo-swirepay-frontend.git — runbook: [DEVOPS-NPM-PUBLISH.md](./DEVOPS-NPM-PUBLISH.md)
|
|
7
7
|
>
|
|
8
|
-
>
|
|
8
|
+
> ### Wrong package name (most common after publish)
|
|
9
|
+
>
|
|
10
|
+
> npm package is **`@swirepay-developer/sparo-embed-sdk`** (scope `swirepay-developer`).
|
|
11
|
+
> If your code imports **`@swirepay/sparo-embed-sdk`** (no `-developer`), webpack will always show **Module not found** even after `npm install` and cache clear.
|
|
12
|
+
>
|
|
13
|
+
> **Fix:** change import + `package.json` dependency to `@swirepay-developer/sparo-embed-sdk` (see Step 1).
|
|
14
|
+
>
|
|
15
|
+
> **`Module not found`** with the correct name usually means not installed — run `npm view @swirepay-developer/sparo-embed-sdk version` (DevOps screenshot should show `1.0.5`).
|
|
9
16
|
|
|
10
17
|
---
|
|
11
18
|
|
|
@@ -31,7 +38,7 @@ Before starting, confirm with your team:
|
|
|
31
38
|
|
|
32
39
|
| Item | Owner | Notes |
|
|
33
40
|
|------|--------|-------|
|
|
34
|
-
| npm access to `@swirepay/sparo-embed-sdk` | DevOps / npm org | `npm login` if private scope |
|
|
41
|
+
| npm access to `@swirepay-developer/sparo-embed-sdk` | DevOps / npm org | `npm login` if private scope |
|
|
35
42
|
| `SPARO_ADMIN_KEY` | Backend | Never in React code or `.env` with `REACT_APP_` |
|
|
36
43
|
| Merchant enabled in SPARO | SPARO admin | Deny-by-default allowlist |
|
|
37
44
|
| Backend route `/sparo/token` | Backend | Returns guest JWT for logged-in user |
|
|
@@ -44,7 +51,7 @@ Before starting, confirm with your team:
|
|
|
44
51
|
From the **gateway-frontend** project root:
|
|
45
52
|
|
|
46
53
|
```bash
|
|
47
|
-
npm install @swirepay/sparo-embed-sdk
|
|
54
|
+
npm install @swirepay-developer/sparo-embed-sdk
|
|
48
55
|
```
|
|
49
56
|
|
|
50
57
|
Or add to `package.json`:
|
|
@@ -52,7 +59,7 @@ Or add to `package.json`:
|
|
|
52
59
|
```json
|
|
53
60
|
{
|
|
54
61
|
"dependencies": {
|
|
55
|
-
"@swirepay/sparo-embed-sdk": "^1.0.
|
|
62
|
+
"@swirepay-developer/sparo-embed-sdk": "^1.0.5"
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
```
|
|
@@ -66,12 +73,12 @@ npm install
|
|
|
66
73
|
### Verify install
|
|
67
74
|
|
|
68
75
|
```bash
|
|
69
|
-
npm ls @swirepay/sparo-embed-sdk
|
|
76
|
+
npm ls @swirepay-developer/sparo-embed-sdk
|
|
70
77
|
```
|
|
71
78
|
|
|
72
79
|
You should see the package listed. If not:
|
|
73
80
|
|
|
74
|
-
-
|
|
81
|
+
- Add `.npmrc` with `@swirepay-developer:registry` (see [.npmrc.example](../.npmrc.example)) and `npm login` if needed
|
|
75
82
|
- Remove any old `"file:..."` path dependency for this package
|
|
76
83
|
- Delete `node_modules` and `package-lock.json`, then `npm install` again
|
|
77
84
|
|
|
@@ -146,42 +153,46 @@ Create a route component, e.g. `src/routes/SparoChat/index.js`:
|
|
|
146
153
|
|
|
147
154
|
```jsx
|
|
148
155
|
import React, { useEffect, useRef, useState } from 'react';
|
|
149
|
-
import {
|
|
156
|
+
import { Alert, Spin } from 'antd';
|
|
157
|
+
import { embed } from '@swirepay-developer/sparo-embed-sdk';
|
|
150
158
|
|
|
151
159
|
const SPARO_DOMAIN = process.env.REACT_APP_SPARO_DOMAIN || 'https://sparo.swirepay.com';
|
|
152
160
|
|
|
153
|
-
|
|
161
|
+
function SparoChat() {
|
|
154
162
|
const mountRef = useRef(null);
|
|
155
163
|
const handleRef = useRef(null);
|
|
156
|
-
const [
|
|
157
|
-
const [
|
|
164
|
+
const [loading, setLoading] = useState(true);
|
|
165
|
+
const [error, setError] = useState('');
|
|
158
166
|
|
|
159
167
|
useEffect(() => {
|
|
160
|
-
const
|
|
161
|
-
if (!
|
|
168
|
+
const mountElement = mountRef.current;
|
|
169
|
+
if (!mountElement) return undefined;
|
|
162
170
|
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
setLoading(true);
|
|
172
|
+
setError('');
|
|
165
173
|
|
|
166
174
|
handleRef.current = embed({
|
|
167
175
|
id: 'sparo-chat',
|
|
168
176
|
sparoDomain: SPARO_DOMAIN,
|
|
169
|
-
mountPoint:
|
|
177
|
+
mountPoint: mountElement,
|
|
170
178
|
fetchGuestToken: async () => {
|
|
171
|
-
const
|
|
179
|
+
const response = await fetch('/sparo/token', {
|
|
180
|
+
method: 'GET',
|
|
172
181
|
credentials: 'include',
|
|
173
182
|
});
|
|
174
|
-
if (
|
|
183
|
+
if (response.status === 401) {
|
|
175
184
|
window.location.href = '/login';
|
|
176
185
|
throw new Error('Unauthorized');
|
|
177
186
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
187
|
+
const payload = await response.json();
|
|
188
|
+
if (!response.ok) {
|
|
189
|
+
const apiError = new Error(
|
|
190
|
+
payload?.message || payload?.error || 'Unable to fetch SPARO token',
|
|
191
|
+
);
|
|
192
|
+
apiError.code = payload?.code || 'fetch_failed';
|
|
193
|
+
throw apiError;
|
|
183
194
|
}
|
|
184
|
-
return
|
|
195
|
+
return payload; // { token, expiresIn, account }
|
|
185
196
|
},
|
|
186
197
|
uiConfig: {
|
|
187
198
|
theme: 'light',
|
|
@@ -189,15 +200,31 @@ export default function SparoChat() {
|
|
|
189
200
|
showSuggestions: true,
|
|
190
201
|
hideSidebar: false,
|
|
191
202
|
},
|
|
192
|
-
onReady: () =>
|
|
203
|
+
onReady: () => setLoading(false),
|
|
193
204
|
onError: (err) => {
|
|
194
|
-
console.error('[SPARO]', err
|
|
195
|
-
|
|
205
|
+
console.error('[SPARO]', err);
|
|
206
|
+
setLoading(false);
|
|
207
|
+
switch (err?.code) {
|
|
208
|
+
case 'merchant_not_enabled':
|
|
209
|
+
setError('Your merchant account is not enabled for SPARO.');
|
|
210
|
+
break;
|
|
211
|
+
case 'rate_limited':
|
|
212
|
+
setError('Too many requests. Please try again shortly.');
|
|
213
|
+
break;
|
|
214
|
+
case 'invalid_token':
|
|
215
|
+
setError('Invalid authentication token received.');
|
|
216
|
+
break;
|
|
217
|
+
case 'iframe_load_failed':
|
|
218
|
+
setError('Unable to load SPARO assistant.');
|
|
219
|
+
break;
|
|
220
|
+
default:
|
|
221
|
+
setError(err?.message || 'Failed to initialize SPARO.');
|
|
222
|
+
}
|
|
196
223
|
},
|
|
197
224
|
});
|
|
198
225
|
|
|
199
226
|
return () => {
|
|
200
|
-
if (handleRef.current) {
|
|
227
|
+
if (handleRef.current?.unmount) {
|
|
201
228
|
handleRef.current.unmount();
|
|
202
229
|
handleRef.current = null;
|
|
203
230
|
}
|
|
@@ -205,29 +232,32 @@ export default function SparoChat() {
|
|
|
205
232
|
}, []);
|
|
206
233
|
|
|
207
234
|
return (
|
|
208
|
-
<div style={{ padding:
|
|
209
|
-
<
|
|
210
|
-
{
|
|
211
|
-
<
|
|
235
|
+
<div style={{ padding: 20 }}>
|
|
236
|
+
<h2>SPARO Assistant</h2>
|
|
237
|
+
{loading && (
|
|
238
|
+
<div style={{ marginBottom: 16, textAlign: 'center' }}>
|
|
239
|
+
<Spin size="large" />
|
|
240
|
+
</div>
|
|
212
241
|
)}
|
|
213
242
|
{error && (
|
|
214
|
-
<
|
|
215
|
-
{error}
|
|
216
|
-
</p>
|
|
243
|
+
<Alert type="error" showIcon message={error} style={{ marginBottom: 16 }} />
|
|
217
244
|
)}
|
|
218
245
|
<div
|
|
219
246
|
ref={mountRef}
|
|
220
247
|
style={{
|
|
221
248
|
width: '100%',
|
|
222
249
|
height: '720px',
|
|
223
|
-
minHeight:
|
|
224
|
-
border: '1px solid #
|
|
250
|
+
minHeight: '480px',
|
|
251
|
+
border: '1px solid #d9d9d9',
|
|
225
252
|
borderRadius: 8,
|
|
253
|
+
overflow: 'hidden',
|
|
226
254
|
}}
|
|
227
255
|
/>
|
|
228
256
|
</div>
|
|
229
257
|
);
|
|
230
258
|
}
|
|
259
|
+
|
|
260
|
+
export default SparoChat;
|
|
231
261
|
```
|
|
232
262
|
|
|
233
263
|
### If your API base URL is not same-origin
|
|
@@ -280,7 +310,7 @@ npm start
|
|
|
280
310
|
3. Open DevTools → **Network**:
|
|
281
311
|
- Confirm `GET /sparo/token` returns `200` with `token`, `expiresIn`, `account`.
|
|
282
312
|
4. Open DevTools → **Console**:
|
|
283
|
-
- No `Module not found` for `@swirepay/sparo-embed-sdk`.
|
|
313
|
+
- No `Module not found` for `@swirepay-developer/sparo-embed-sdk`.
|
|
284
314
|
5. Confirm iframe loads (Elements tab → `iframe` under your mount div).
|
|
285
315
|
6. SPARO UI should appear without a SPARO login page.
|
|
286
316
|
|
|
@@ -348,6 +378,38 @@ Token refresh is **automatic** ~30 seconds before expiry.
|
|
|
348
378
|
|
|
349
379
|
### `Module not found: Can't resolve '@swirepay/sparo-embed-sdk'`
|
|
350
380
|
|
|
381
|
+
**Wrong package name.** DevOps published `@swirepay-developer/sparo-embed-sdk@1.0.5`, not `@swirepay/sparo-embed-sdk`.
|
|
382
|
+
|
|
383
|
+
Update **both**:
|
|
384
|
+
|
|
385
|
+
```js
|
|
386
|
+
// SparoChat.js — change this line
|
|
387
|
+
import { embed } from '@swirepay-developer/sparo-embed-sdk';
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
```json
|
|
391
|
+
// package.json
|
|
392
|
+
"@swirepay-developer/sparo-embed-sdk": "^1.0.5"
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Then:
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
npm uninstall @swirepay/sparo-embed-sdk
|
|
399
|
+
npm install @swirepay-developer/sparo-embed-sdk
|
|
400
|
+
npm start
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
Add to gateway `.npmrc` (no token in git — use env in CI):
|
|
404
|
+
|
|
405
|
+
```ini
|
|
406
|
+
@swirepay-developer:registry=https://registry.npmjs.org/
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
### `Module not found: Can't resolve '@swirepay-developer/sparo-embed-sdk'`
|
|
412
|
+
|
|
351
413
|
Webpack shows this when the package is **not installed** under `node_modules` (install failed or was never run).
|
|
352
414
|
|
|
353
415
|
**Step 0 — verify the package exists on your registry**
|
|
@@ -355,25 +417,25 @@ Webpack shows this when the package is **not installed** under `node_modules` (i
|
|
|
355
417
|
From `gateway-frontend`:
|
|
356
418
|
|
|
357
419
|
```bash
|
|
358
|
-
npm view @swirepay/sparo-embed-sdk version
|
|
420
|
+
npm view @swirepay-developer/sparo-embed-sdk version
|
|
359
421
|
```
|
|
360
422
|
|
|
361
423
|
| Result | Meaning |
|
|
362
424
|
|--------|---------|
|
|
363
|
-
| `1.0.
|
|
425
|
+
| `1.0.5` (or similar) | Published — go to Step 1 |
|
|
364
426
|
| `404 Not Found` | **Not on registry.npmjs.org** (or wrong scope/name). `npm install` will not add the package → this error persists |
|
|
365
427
|
|
|
366
|
-
If you see **404**, DevOps has not published yet (or gateway
|
|
428
|
+
If you see **404**, DevOps has not published yet (or gateway lacks npm read access to `@swirepay-developer`). Do not merge gateway code that imports the SDK until `npm view` returns a version.
|
|
367
429
|
|
|
368
430
|
**Step 1 — install and confirm**
|
|
369
431
|
|
|
370
432
|
```bash
|
|
371
433
|
cd gateway-frontend
|
|
372
|
-
npm install @swirepay/sparo-embed-sdk
|
|
373
|
-
dir node_modules\@swirepay\sparo-embed-sdk\dist
|
|
434
|
+
npm install @swirepay-developer/sparo-embed-sdk
|
|
435
|
+
dir node_modules\@swirepay-developer\sparo-embed-sdk\dist
|
|
374
436
|
```
|
|
375
437
|
|
|
376
|
-
You must see `index.
|
|
438
|
+
You must see `index.js` and `index.mjs` in that folder. If the folder is missing, the install did not succeed.
|
|
377
439
|
|
|
378
440
|
**Step 2**
|
|
379
441
|
|
|
@@ -408,7 +470,7 @@ You must see `index.cjs` and `index.js` in that folder. If the folder is missing
|
|
|
408
470
|
|
|
409
471
|
## Minimal checklist
|
|
410
472
|
|
|
411
|
-
- [ ] `npm install @swirepay/sparo-embed-sdk`
|
|
473
|
+
- [ ] `npm install @swirepay-developer/sparo-embed-sdk`
|
|
412
474
|
- [ ] `REACT_APP_SPARO_DOMAIN` set per environment
|
|
413
475
|
- [ ] Backend `/sparo/token` implemented and tested
|
|
414
476
|
- [ ] `SparoChat` component with `useEffect` + `unmount` cleanup
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SPARO Embed SDK
|
|
2
2
|
|
|
3
|
-
`@swirepay/sparo-embed-sdk` embeds SPARO in web apps (including gateway React) using guest-token auth and an iframe.
|
|
3
|
+
`@swirepay-developer/sparo-embed-sdk` embeds SPARO in web apps (including gateway React) using guest-token auth and an iframe.
|
|
4
4
|
|
|
5
5
|
**Bitbucket:** https://bitbucket.org/zetametrics/sparo-swirepay-frontend.git
|
|
6
6
|
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
|------|--------|
|
|
13
13
|
| **You (SDK)** | Push this repo to Bitbucket (`sdkmaster` or release branch). Bump version in `package.json` for each release. |
|
|
14
14
|
| **DevOps** | Clone repo → `npm ci` → `npm publish`. See **[DEVOPS-NPM-PUBLISH.md](./DEVOPS-NPM-PUBLISH.md)**. |
|
|
15
|
-
| **Gateway developer** | After publish: `npm install @swirepay/sparo-embed-sdk` and follow **[GATEWAY-REACT-GUIDE.md](./GATEWAY-REACT-GUIDE.md)**. |
|
|
15
|
+
| **Gateway developer** | After publish: `npm install @swirepay-developer/sparo-embed-sdk` and follow **[GATEWAY-REACT-GUIDE.md](./GATEWAY-REACT-GUIDE.md)**. |
|
|
16
16
|
|
|
17
17
|
Until DevOps publishes, gateway will show:
|
|
18
18
|
|
|
19
|
-
`Module not found: Can't resolve '@swirepay/sparo-embed-sdk'`
|
|
19
|
+
`Module not found: Can't resolve '@swirepay-developer/sparo-embed-sdk'`
|
|
20
20
|
|
|
21
21
|
That is expected — the package is not on npm yet.
|
|
22
22
|
|
|
@@ -25,13 +25,13 @@ That is expected — the package is not on npm yet.
|
|
|
25
25
|
## Gateway install (after DevOps publish)
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npm install @swirepay/sparo-embed-sdk
|
|
28
|
+
npm install @swirepay-developer/sparo-embed-sdk
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
```json
|
|
32
32
|
{
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@swirepay/sparo-embed-sdk": "^1.0.
|
|
34
|
+
"@swirepay-developer/sparo-embed-sdk": "^1.0.5"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
```
|
|
@@ -43,7 +43,7 @@ Private package: use [.npmrc.example](./.npmrc.example) with org `NPM_TOKEN` (De
|
|
|
43
43
|
## Quick Start
|
|
44
44
|
|
|
45
45
|
```js
|
|
46
|
-
import { embed } from '@swirepay/sparo-embed-sdk';
|
|
46
|
+
import { embed } from '@swirepay-developer/sparo-embed-sdk';
|
|
47
47
|
|
|
48
48
|
const handle = embed({
|
|
49
49
|
id: 'sparo-chat',
|
package/SPARO-EMBEDDING.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Embed the SPARO assistant into your application with short-lived guest JWTs, no SPARO login screen, and automatic token refresh.
|
|
4
4
|
|
|
5
|
-
- SDK: `@swirepay/sparo-embed-sdk`
|
|
5
|
+
- SDK: `@swirepay-developer/sparo-embed-sdk`
|
|
6
6
|
- SPARO backend: `v1.10.1+`
|
|
7
7
|
|
|
8
8
|
## Architecture
|
|
@@ -56,7 +56,7 @@ Response:
|
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
|
-
import { embed } from '@swirepay/sparo-embed-sdk';
|
|
59
|
+
import { embed } from '@swirepay-developer/sparo-embed-sdk';
|
|
60
60
|
|
|
61
61
|
const handle = embed({
|
|
62
62
|
id: 'sparo-chat',
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
var E=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var i in t)E(e,i,{get:t[i],enumerable:!0})},F=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of M(t))!A.call(e,c)&&c!==i&&E(e,c,{get:()=>t[c],enumerable:!(s=L(t,c))||s.enumerable});return e};var G=e=>F(E({},"__esModule",{value:!0}),e);var P={};I(P,{default:()=>x,embed:()=>g});module.exports=G(P);function C(e){try{return new URL(e).origin}catch{throw new Error("Invalid sparoDomain. Expected absolute URL, e.g. https://sparo.swirepay.com")}}function a(e,t,i){let s=new Error(t||e);return s.code=e,typeof i=="number"&&(s.status=i),s}function H(e){if(!e||typeof e!="object")throw a("fetch_failed","fetchGuestToken must return an object");if(!e.token||typeof e.token!="string")throw a("invalid_token","Missing token in fetchGuestToken response");if(!e.account||typeof e.account!="string")throw a("invalid_token","Missing account in fetchGuestToken response");let t=Number(e.expiresIn||900);if(!Number.isFinite(t)||t<=0)throw a("invalid_token","Invalid expiresIn in fetchGuestToken response");return{token:e.token,account:e.account,expiresIn:t}}function N(e,t){let i=new URLSearchParams({embed:"true",account:t});return`${e}/embed.html?${i.toString()}`}function g(e){let{id:t="sparo-embed",sparoDomain:i,mountPoint:s,fetchGuestToken:c,uiConfig:v={},onReady:k,onError:b}=e||{};if(!s||!(s instanceof HTMLElement))throw new Error("mountPoint must be a valid HTMLElement");if(typeof c!="function")throw new Error("fetchGuestToken must be a function");let d=C(i),o=document.createElement("iframe");o.id=t,o.title="SPARO Assistant",o.style.width="100%",o.style.height="100%",o.style.border="0",o.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups allow-modals"),o.setAttribute("referrerpolicy","no-referrer");let l=!0,T=!1,m=null,p=null,y=()=>{p&&(window.clearTimeout(p),p=null)},h=n=>{b&&b(n)},S=()=>{if(!l||!T||!m)return;let n=o.contentWindow;!n||typeof n.postMessage!="function"||n.postMessage({type:"sparo:auth",token:m.token,account:m.account,uiConfig:v},d)},D=n=>{y();let r=Math.max(5,n-30);p=window.setTimeout(()=>{w().catch(()=>{})},r*1e3)},w=async()=>{if(!l)return;let n;try{n=await c()}catch(f){let R=a("fetch_failed",(f==null?void 0:f.message)||"Failed to fetch guest token");throw h(R),R}let r=H(n);m=r,D(r.expiresIn);let u=N(d,r.account);!o.src||o.src!==u?o.src=u:S()},_=n=>{if(!l||n.origin!==d)return;let r=n.data;if(!(!r||typeof r!="object"||typeof r.type!="string")){if(r.type==="sparo:ready"||r.type==="SPARO_EMBED_READY"){T=!0,S(),k&&k();return}if(r.type==="sparo:error"){let u=r.code||"iframe_error",f=a(u,r.message||u,r.status);h(f)}}};return window.addEventListener("message",_),s.innerHTML="",s.appendChild(o),w().catch(n=>{h(n)}),{refresh:()=>w(),unmount:()=>{l=!1,y(),window.removeEventListener("message",_),o.parentNode===s&&s.removeChild(o)}}}var x=g;0&&(module.exports={embed});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function v(e){try{return new URL(e).origin}catch{throw new Error("Invalid sparoDomain. Expected absolute URL, e.g. https://sparo.swirepay.com")}}function c(e,o,i){let s=new Error(o||e);return s.code=e,typeof i=="number"&&(s.status=i),s}function D(e){if(!e||typeof e!="object")throw c("fetch_failed","fetchGuestToken must return an object");if(!e.token||typeof e.token!="string")throw c("invalid_token","Missing token in fetchGuestToken response");if(!e.account||typeof e.account!="string")throw c("invalid_token","Missing account in fetchGuestToken response");let o=Number(e.expiresIn||900);if(!Number.isFinite(o)||o<=0)throw c("invalid_token","Invalid expiresIn in fetchGuestToken response");return{token:e.token,account:e.account,expiresIn:o}}function L(e,o){let i=new URLSearchParams({embed:"true",account:o});return`${e}/embed.html?${i.toString()}`}function _(e){let{id:o="sparo-embed",sparoDomain:i,mountPoint:s,fetchGuestToken:w,uiConfig:R={},onReady:E,onError:g}=e||{};if(!s||!(s instanceof HTMLElement))throw new Error("mountPoint must be a valid HTMLElement");if(typeof w!="function")throw new Error("fetchGuestToken must be a function");let p=v(i),r=document.createElement("iframe");r.id=o,r.title="SPARO Assistant",r.style.width="100%",r.style.height="100%",r.style.border="0",r.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups allow-modals"),r.setAttribute("referrerpolicy","no-referrer");let f=!0,k=!1,l=null,m=null,b=()=>{m&&(window.clearTimeout(m),m=null)},d=t=>{g&&g(t)},T=()=>{if(!f||!k||!l)return;let t=r.contentWindow;!t||typeof t.postMessage!="function"||t.postMessage({type:"sparo:auth",token:l.token,account:l.account,uiConfig:R},p)},x=t=>{b();let n=Math.max(5,t-30);m=window.setTimeout(()=>{h().catch(()=>{})},n*1e3)},h=async()=>{if(!f)return;let t;try{t=await w()}catch(u){let S=c("fetch_failed",(u==null?void 0:u.message)||"Failed to fetch guest token");throw d(S),S}let n=D(t);l=n,x(n.expiresIn);let a=L(p,n.account);!r.src||r.src!==a?r.src=a:T()},y=t=>{if(!f||t.origin!==p)return;let n=t.data;if(!(!n||typeof n!="object"||typeof n.type!="string")){if(n.type==="sparo:ready"||n.type==="SPARO_EMBED_READY"){k=!0,T(),E&&E();return}if(n.type==="sparo:error"){let a=n.code||"iframe_error",u=c(a,n.message||a,n.status);d(u)}}};return window.addEventListener("message",y),s.innerHTML="",s.appendChild(r),h().catch(t=>{d(t)}),{refresh:()=>h(),unmount:()=>{f=!1,b(),window.removeEventListener("message",y),r.parentNode===s&&s.removeChild(r)}}}var M=_;export{M as default,_ as embed};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swirepay-developer/sparo-embed-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "SPARO embedding SDK for guest-token based iframe integration",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
11
11
|
"types": "./types/index.d.ts",
|
|
12
12
|
"unpkg": "./dist/sparo-embed-sdk.global.js",
|
|
13
|
-
"type": "module",
|
|
14
13
|
"jsdelivr": "./dist/sparo-embed-sdk.global.js",
|
|
15
14
|
"exports": {
|
|
16
15
|
".": {
|
|
@@ -59,9 +58,9 @@
|
|
|
59
58
|
"build:sdk": "npm run build",
|
|
60
59
|
"test": "vitest run",
|
|
61
60
|
"test:watch": "vitest",
|
|
62
|
-
"lint": "eslint src",
|
|
63
|
-
"verify": "npm run lint && npm run test && npm run build",
|
|
64
|
-
"prepublishOnly": "npm run verify"
|
|
61
|
+
"lint": "node ./node_modules/eslint/bin/eslint.js src",
|
|
62
|
+
"verify": "node scripts/ensure-dev-deps.mjs && npm run lint && npm run test && npm run build",
|
|
63
|
+
"prepublishOnly": "npm run verify && node scripts/check-publish-manifest.mjs"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
66
|
"@testing-library/dom": "^10.4.0",
|
|
@@ -80,182 +79,5 @@
|
|
|
80
79
|
"eslint --fix",
|
|
81
80
|
"prettier --write"
|
|
82
81
|
]
|
|
83
|
-
},
|
|
84
|
-
"dependencies": {
|
|
85
|
-
"acorn": "^8.16.0",
|
|
86
|
-
"acorn-jsx": "^5.3.2",
|
|
87
|
-
"agent-base": "^7.1.4",
|
|
88
|
-
"ajv": "^6.15.0",
|
|
89
|
-
"ansi-regex": "^5.0.1",
|
|
90
|
-
"ansi-styles": "^4.3.0",
|
|
91
|
-
"any-promise": "^1.3.0",
|
|
92
|
-
"argparse": "^2.0.1",
|
|
93
|
-
"assertion-error": "^2.0.1",
|
|
94
|
-
"balanced-match": "^1.0.2",
|
|
95
|
-
"brace-expansion": "^1.1.14",
|
|
96
|
-
"braces": "^3.0.3",
|
|
97
|
-
"buffer-from": "^1.1.2",
|
|
98
|
-
"bundle-require": "^5.1.0",
|
|
99
|
-
"cac": "^6.7.14",
|
|
100
|
-
"callsites": "^3.1.0",
|
|
101
|
-
"chai": "^5.3.3",
|
|
102
|
-
"chalk": "^4.1.2",
|
|
103
|
-
"check-error": "^2.1.3",
|
|
104
|
-
"cli-cursor": "^5.0.0",
|
|
105
|
-
"cli-truncate": "^4.0.0",
|
|
106
|
-
"color-convert": "^2.0.1",
|
|
107
|
-
"color-name": "^1.1.4",
|
|
108
|
-
"colorette": "^2.0.20",
|
|
109
|
-
"commander": "^4.1.1",
|
|
110
|
-
"concat-map": "^0.0.1",
|
|
111
|
-
"confbox": "^0.1.8",
|
|
112
|
-
"consola": "^3.4.2",
|
|
113
|
-
"cross-spawn": "^7.0.6",
|
|
114
|
-
"cssstyle": "^4.6.0",
|
|
115
|
-
"data-urls": "^5.0.0",
|
|
116
|
-
"debug": "^4.4.3",
|
|
117
|
-
"decimal.js": "^10.6.0",
|
|
118
|
-
"deep-eql": "^5.0.2",
|
|
119
|
-
"deep-is": "^0.1.4",
|
|
120
|
-
"dequal": "^2.0.3",
|
|
121
|
-
"environment": "^1.1.0",
|
|
122
|
-
"escape-string-regexp": "^4.0.0",
|
|
123
|
-
"eslint-scope": "^8.4.0",
|
|
124
|
-
"eslint-visitor-keys": "^3.4.3",
|
|
125
|
-
"espree": "^10.4.0",
|
|
126
|
-
"esquery": "^1.7.0",
|
|
127
|
-
"esrecurse": "^4.3.0",
|
|
128
|
-
"estraverse": "^5.3.0",
|
|
129
|
-
"esutils": "^2.0.3",
|
|
130
|
-
"expect-type": "^1.3.0",
|
|
131
|
-
"fast-deep-equal": "^3.1.3",
|
|
132
|
-
"fast-json-stable-stringify": "^2.1.0",
|
|
133
|
-
"fast-levenshtein": "^2.0.6",
|
|
134
|
-
"file-entry-cache": "^8.0.0",
|
|
135
|
-
"fill-range": "^7.1.1",
|
|
136
|
-
"find-up": "^5.0.0",
|
|
137
|
-
"fix-dts-default-cjs-exports": "^1.0.1",
|
|
138
|
-
"flat-cache": "^4.0.1",
|
|
139
|
-
"flatted": "^3.4.2",
|
|
140
|
-
"get-east-asian-width": "^1.6.0",
|
|
141
|
-
"glob-parent": "^6.0.2",
|
|
142
|
-
"has-flag": "^4.0.0",
|
|
143
|
-
"html-encoding-sniffer": "^4.0.0",
|
|
144
|
-
"http-proxy-agent": "^7.0.2",
|
|
145
|
-
"https-proxy-agent": "^7.0.6",
|
|
146
|
-
"iconv-lite": "^0.6.3",
|
|
147
|
-
"ignore": "^5.3.2",
|
|
148
|
-
"import-fresh": "^3.3.1",
|
|
149
|
-
"imurmurhash": "^0.1.4",
|
|
150
|
-
"is-extglob": "^2.1.1",
|
|
151
|
-
"is-glob": "^4.0.3",
|
|
152
|
-
"is-number": "^7.0.0",
|
|
153
|
-
"is-potential-custom-element-name": "^1.0.1",
|
|
154
|
-
"isexe": "^2.0.0",
|
|
155
|
-
"jiti": "^1.21.7",
|
|
156
|
-
"joycon": "^3.1.1",
|
|
157
|
-
"js-tokens": "^4.0.0",
|
|
158
|
-
"js-yaml": "^4.1.1",
|
|
159
|
-
"json-buffer": "^3.0.1",
|
|
160
|
-
"json-schema-traverse": "^0.4.1",
|
|
161
|
-
"json-stable-stringify-without-jsonify": "^1.0.1",
|
|
162
|
-
"keyv": "^4.5.4",
|
|
163
|
-
"levn": "^0.4.1",
|
|
164
|
-
"lines-and-columns": "^1.2.4",
|
|
165
|
-
"listr2": "^8.3.3",
|
|
166
|
-
"load-tsconfig": "^0.2.5",
|
|
167
|
-
"locate-path": "^6.0.0",
|
|
168
|
-
"lodash.merge": "^4.6.2",
|
|
169
|
-
"log-update": "^6.1.0",
|
|
170
|
-
"loupe": "^3.2.1",
|
|
171
|
-
"lz-string": "^1.5.0",
|
|
172
|
-
"merge-stream": "^2.0.0",
|
|
173
|
-
"micromatch": "^4.0.8",
|
|
174
|
-
"mimic-function": "^5.0.1",
|
|
175
|
-
"minimatch": "^3.1.5",
|
|
176
|
-
"minipass": "^7.1.3",
|
|
177
|
-
"mlly": "^1.8.2",
|
|
178
|
-
"ms": "^2.1.3",
|
|
179
|
-
"mz": "^2.7.0",
|
|
180
|
-
"nanoid": "^3.3.12",
|
|
181
|
-
"natural-compare": "^1.4.0",
|
|
182
|
-
"nwsapi": "^2.2.23",
|
|
183
|
-
"object-assign": "^4.1.1",
|
|
184
|
-
"optionator": "^0.9.4",
|
|
185
|
-
"p-limit": "^3.1.0",
|
|
186
|
-
"p-locate": "^5.0.0",
|
|
187
|
-
"package-json-from-dist": "^1.0.1",
|
|
188
|
-
"parent-module": "^1.0.1",
|
|
189
|
-
"parse5": "^7.3.0",
|
|
190
|
-
"path-exists": "^4.0.0",
|
|
191
|
-
"path-key": "^3.1.1",
|
|
192
|
-
"path-scurry": "^2.0.2",
|
|
193
|
-
"pathe": "^2.0.3",
|
|
194
|
-
"pathval": "^2.0.1",
|
|
195
|
-
"picocolors": "^1.1.1",
|
|
196
|
-
"picomatch": "^2.3.2",
|
|
197
|
-
"pidtree": "^0.6.0",
|
|
198
|
-
"pirates": "^4.0.7",
|
|
199
|
-
"pkg-types": "^1.3.1",
|
|
200
|
-
"postcss": "^8.5.15",
|
|
201
|
-
"prelude-ls": "^1.2.1",
|
|
202
|
-
"pretty-format": "^27.5.1",
|
|
203
|
-
"punycode": "^2.3.1",
|
|
204
|
-
"react-is": "^17.0.2",
|
|
205
|
-
"resolve-from": "^4.0.0",
|
|
206
|
-
"restore-cursor": "^5.1.0",
|
|
207
|
-
"rfdc": "^1.4.1",
|
|
208
|
-
"rrweb-cssom": "^0.8.0",
|
|
209
|
-
"safer-buffer": "^2.1.2",
|
|
210
|
-
"saxes": "^6.0.0",
|
|
211
|
-
"shebang-command": "^2.0.0",
|
|
212
|
-
"shebang-regex": "^3.0.0",
|
|
213
|
-
"siginfo": "^2.0.0",
|
|
214
|
-
"slice-ansi": "^5.0.0",
|
|
215
|
-
"source-map": "^0.7.6",
|
|
216
|
-
"source-map-js": "^1.2.1",
|
|
217
|
-
"source-map-support": "^0.5.21",
|
|
218
|
-
"stackback": "^0.0.2",
|
|
219
|
-
"std-env": "^3.10.0",
|
|
220
|
-
"string-argv": "^0.3.2",
|
|
221
|
-
"strip-json-comments": "^3.1.1",
|
|
222
|
-
"strip-literal": "^3.1.0",
|
|
223
|
-
"sucrase": "^3.35.1",
|
|
224
|
-
"supports-color": "^7.2.0",
|
|
225
|
-
"symbol-tree": "^3.2.4",
|
|
226
|
-
"terser": "^5.47.1",
|
|
227
|
-
"thenify": "^3.3.1",
|
|
228
|
-
"thenify-all": "^1.6.0",
|
|
229
|
-
"tinybench": "^2.9.0",
|
|
230
|
-
"tinyexec": "^0.3.2",
|
|
231
|
-
"tinyglobby": "^0.2.16",
|
|
232
|
-
"tinypool": "^1.1.1",
|
|
233
|
-
"tinyrainbow": "^2.0.0",
|
|
234
|
-
"tinyspy": "^4.0.4",
|
|
235
|
-
"tldts": "^6.1.86",
|
|
236
|
-
"tldts-core": "^6.1.86",
|
|
237
|
-
"to-regex-range": "^5.0.1",
|
|
238
|
-
"tough-cookie": "^5.1.2",
|
|
239
|
-
"tr46": "^5.1.1",
|
|
240
|
-
"tree-kill": "^1.2.2",
|
|
241
|
-
"ts-interface-checker": "^0.1.13",
|
|
242
|
-
"type-check": "^0.4.0",
|
|
243
|
-
"typescript": "^4.9.5",
|
|
244
|
-
"ufo": "^1.6.4",
|
|
245
|
-
"undici-types": "^7.24.6",
|
|
246
|
-
"uri-js": "^4.4.1",
|
|
247
|
-
"vite-node": "^3.2.4",
|
|
248
|
-
"w3c-xmlserializer": "^5.0.0",
|
|
249
|
-
"webidl-conversions": "^7.0.0",
|
|
250
|
-
"whatwg-encoding": "^3.1.1",
|
|
251
|
-
"whatwg-mimetype": "^4.0.0",
|
|
252
|
-
"whatwg-url": "^14.2.0",
|
|
253
|
-
"which": "^2.0.2",
|
|
254
|
-
"why-is-node-running": "^2.3.0",
|
|
255
|
-
"word-wrap": "^1.2.5",
|
|
256
|
-
"ws": "^8.21.0",
|
|
257
|
-
"xml-name-validator": "^5.0.0",
|
|
258
|
-
"xmlchars": "^2.2.0",
|
|
259
|
-
"yocto-queue": "^0.1.0"
|
|
260
82
|
}
|
|
261
83
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var E=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var i in t)E(e,i,{get:t[i],enumerable:!0})},F=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of M(t))!A.call(e,c)&&c!==i&&E(e,c,{get:()=>t[c],enumerable:!(s=L(t,c))||s.enumerable});return e};var G=e=>F(E({},"__esModule",{value:!0}),e);var P={};I(P,{default:()=>x,embed:()=>g});module.exports=G(P);function C(e){try{return new URL(e).origin}catch{throw new Error("Invalid sparoDomain. Expected absolute URL, e.g. https://sparo.swirepay.com")}}function a(e,t,i){let s=new Error(t||e);return s.code=e,typeof i=="number"&&(s.status=i),s}function H(e){if(!e||typeof e!="object")throw a("fetch_failed","fetchGuestToken must return an object");if(!e.token||typeof e.token!="string")throw a("invalid_token","Missing token in fetchGuestToken response");if(!e.account||typeof e.account!="string")throw a("invalid_token","Missing account in fetchGuestToken response");let t=Number(e.expiresIn||900);if(!Number.isFinite(t)||t<=0)throw a("invalid_token","Invalid expiresIn in fetchGuestToken response");return{token:e.token,account:e.account,expiresIn:t}}function N(e,t){let i=new URLSearchParams({embed:"true",account:t});return`${e}/embed.html?${i.toString()}`}function g(e){let{id:t="sparo-embed",sparoDomain:i,mountPoint:s,fetchGuestToken:c,uiConfig:v={},onReady:k,onError:b}=e||{};if(!s||!(s instanceof HTMLElement))throw new Error("mountPoint must be a valid HTMLElement");if(typeof c!="function")throw new Error("fetchGuestToken must be a function");let d=C(i),o=document.createElement("iframe");o.id=t,o.title="SPARO Assistant",o.style.width="100%",o.style.height="100%",o.style.border="0",o.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups allow-modals"),o.setAttribute("referrerpolicy","no-referrer");let l=!0,T=!1,m=null,p=null,y=()=>{p&&(window.clearTimeout(p),p=null)},h=n=>{b&&b(n)},S=()=>{if(!l||!T||!m)return;let n=o.contentWindow;!n||typeof n.postMessage!="function"||n.postMessage({type:"sparo:auth",token:m.token,account:m.account,uiConfig:v},d)},D=n=>{y();let r=Math.max(5,n-30);p=window.setTimeout(()=>{w().catch(()=>{})},r*1e3)},w=async()=>{if(!l)return;let n;try{n=await c()}catch(f){let R=a("fetch_failed",(f==null?void 0:f.message)||"Failed to fetch guest token");throw h(R),R}let r=H(n);m=r,D(r.expiresIn);let u=N(d,r.account);!o.src||o.src!==u?o.src=u:S()},_=n=>{if(!l||n.origin!==d)return;let r=n.data;if(!(!r||typeof r!="object"||typeof r.type!="string")){if(r.type==="sparo:ready"||r.type==="SPARO_EMBED_READY"){T=!0,S(),k&&k();return}if(r.type==="sparo:error"){let u=r.code||"iframe_error",f=a(u,r.message||u,r.status);h(f)}}};return window.addEventListener("message",_),s.innerHTML="",s.appendChild(o),w().catch(n=>{h(n)}),{refresh:()=>w(),unmount:()=>{l=!1,y(),window.removeEventListener("message",_),o.parentNode===s&&s.removeChild(o)}}}var x=g;0&&(module.exports={embed});
|