@stellar-snaps/sdk 0.3.1 → 0.3.2
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/README.md +30 -0
- package/dist/index.d.mts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -134,6 +134,20 @@ const { url } = await createSnap({
|
|
|
134
134
|
});
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
+
**Show the same modal overlay as the web app** (browser only): open the snap URL in a modal so users can pay without leaving your page:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { createSnap, openSnapModal, closeSnapModal } from '@stellar-snaps/sdk';
|
|
141
|
+
|
|
142
|
+
const { url } = await createSnap({ creator: 'G...', title: 'Tip', destination: 'G...' });
|
|
143
|
+
openSnapModal(url, {
|
|
144
|
+
width: 420,
|
|
145
|
+
height: 560,
|
|
146
|
+
onClose: () => console.log('Modal closed'),
|
|
147
|
+
});
|
|
148
|
+
// User sees the same payment UI as stellar-snaps.vercel.app/s/xxx in an overlay
|
|
149
|
+
```
|
|
150
|
+
|
|
137
151
|
### 5. Host Your Own Snap Endpoints
|
|
138
152
|
|
|
139
153
|
Create a discovery file to enable the browser extension to find your snaps:
|
|
@@ -225,6 +239,22 @@ interface Snap {
|
|
|
225
239
|
}
|
|
226
240
|
```
|
|
227
241
|
|
|
242
|
+
#### `openSnapModal(snapUrl, options?)`
|
|
243
|
+
|
|
244
|
+
Opens a snap URL in a full-screen modal overlay (iframe). Same payment UI as opening the link on the Stellar Snaps web app. **Browser only**; no-op in Node.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
interface OpenSnapModalOptions {
|
|
248
|
+
width?: number; // Default: 420
|
|
249
|
+
height?: number; // Default: 560
|
|
250
|
+
onClose?: () => void;
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### `closeSnapModal()`
|
|
255
|
+
|
|
256
|
+
Closes the snap modal if one is open. Safe to call anytime.
|
|
257
|
+
|
|
228
258
|
### SEP-0007 URI Functions
|
|
229
259
|
|
|
230
260
|
#### `createPaymentSnap(options)`
|
package/dist/index.d.mts
CHANGED
|
@@ -102,6 +102,40 @@ declare function deleteSnap(id: string, creator: string, options?: {
|
|
|
102
102
|
baseUrl?: string;
|
|
103
103
|
}): Promise<void>;
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Snap Modal Overlay
|
|
107
|
+
*
|
|
108
|
+
* Opens a snap URL (e.g. from createSnap) in a modal overlay so users can pay
|
|
109
|
+
* without leaving the page. Same payment UI as the web app, loaded in an iframe.
|
|
110
|
+
* Browser-only; no-op in Node.
|
|
111
|
+
*/
|
|
112
|
+
interface OpenSnapModalOptions {
|
|
113
|
+
/** Width of the iframe content area (default: 420) */
|
|
114
|
+
width?: number;
|
|
115
|
+
/** Height of the iframe (default: 560) */
|
|
116
|
+
height?: number;
|
|
117
|
+
/** Called when the user closes the modal */
|
|
118
|
+
onClose?: () => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Opens a snap URL in a modal overlay (iframe). Same experience as opening
|
|
122
|
+
* the link on the Stellar Snaps web app—payment form, Freighter, etc.
|
|
123
|
+
* Use the URL returned from createSnap(), e.g. result.url.
|
|
124
|
+
*
|
|
125
|
+
* Browser-only; does nothing in Node.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const { url } = await createSnap({ ... });
|
|
130
|
+
* openSnapModal(url, { onClose: () => console.log('Closed') });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function openSnapModal(snapUrl: string, options?: OpenSnapModalOptions): void;
|
|
134
|
+
/**
|
|
135
|
+
* Closes the snap modal if one is open. Safe to call anytime.
|
|
136
|
+
*/
|
|
137
|
+
declare function closeSnapModal(): void;
|
|
138
|
+
|
|
105
139
|
/**
|
|
106
140
|
* Snap ID Generation
|
|
107
141
|
*
|
|
@@ -1179,4 +1213,4 @@ declare class SnapApiError extends StellarSnapError {
|
|
|
1179
1213
|
constructor(message: string, statusCode?: number | undefined);
|
|
1180
1214
|
}
|
|
1181
1215
|
|
|
1182
|
-
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap$1 as Snap, SnapApiError, type SnapMetadata, SnapNotFoundError, type Snap as SnapRecord, SnapUnauthorizedError, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|
|
1216
|
+
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, type OpenSnapModalOptions, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap$1 as Snap, SnapApiError, type SnapMetadata, SnapNotFoundError, type Snap as SnapRecord, SnapUnauthorizedError, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, closeSnapModal, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, openSnapModal, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -102,6 +102,40 @@ declare function deleteSnap(id: string, creator: string, options?: {
|
|
|
102
102
|
baseUrl?: string;
|
|
103
103
|
}): Promise<void>;
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Snap Modal Overlay
|
|
107
|
+
*
|
|
108
|
+
* Opens a snap URL (e.g. from createSnap) in a modal overlay so users can pay
|
|
109
|
+
* without leaving the page. Same payment UI as the web app, loaded in an iframe.
|
|
110
|
+
* Browser-only; no-op in Node.
|
|
111
|
+
*/
|
|
112
|
+
interface OpenSnapModalOptions {
|
|
113
|
+
/** Width of the iframe content area (default: 420) */
|
|
114
|
+
width?: number;
|
|
115
|
+
/** Height of the iframe (default: 560) */
|
|
116
|
+
height?: number;
|
|
117
|
+
/** Called when the user closes the modal */
|
|
118
|
+
onClose?: () => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Opens a snap URL in a modal overlay (iframe). Same experience as opening
|
|
122
|
+
* the link on the Stellar Snaps web app—payment form, Freighter, etc.
|
|
123
|
+
* Use the URL returned from createSnap(), e.g. result.url.
|
|
124
|
+
*
|
|
125
|
+
* Browser-only; does nothing in Node.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const { url } = await createSnap({ ... });
|
|
130
|
+
* openSnapModal(url, { onClose: () => console.log('Closed') });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function openSnapModal(snapUrl: string, options?: OpenSnapModalOptions): void;
|
|
134
|
+
/**
|
|
135
|
+
* Closes the snap modal if one is open. Safe to call anytime.
|
|
136
|
+
*/
|
|
137
|
+
declare function closeSnapModal(): void;
|
|
138
|
+
|
|
105
139
|
/**
|
|
106
140
|
* Snap ID Generation
|
|
107
141
|
*
|
|
@@ -1179,4 +1213,4 @@ declare class SnapApiError extends StellarSnapError {
|
|
|
1179
1213
|
constructor(message: string, statusCode?: number | undefined);
|
|
1180
1214
|
}
|
|
1181
1215
|
|
|
1182
|
-
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap$1 as Snap, SnapApiError, type SnapMetadata, SnapNotFoundError, type Snap as SnapRecord, SnapUnauthorizedError, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|
|
1216
|
+
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, type OpenSnapModalOptions, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap$1 as Snap, SnapApiError, type SnapMetadata, SnapNotFoundError, type Snap as SnapRecord, SnapUnauthorizedError, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, closeSnapModal, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, openSnapModal, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|
package/dist/index.js
CHANGED
|
@@ -176,6 +176,74 @@ async function deleteSnap(id, creator, options = {}) {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
// src/snap-modal.ts
|
|
180
|
+
var MODAL_ID = "stellar-snap-modal";
|
|
181
|
+
var IFRAME_ID = "stellar-snap-modal-iframe";
|
|
182
|
+
function isBrowser() {
|
|
183
|
+
return typeof document !== "undefined" && typeof window !== "undefined";
|
|
184
|
+
}
|
|
185
|
+
function openSnapModal(snapUrl, options = {}) {
|
|
186
|
+
if (!isBrowser()) return;
|
|
187
|
+
closeSnapModal();
|
|
188
|
+
const { width = 420, height = 560, onClose } = options;
|
|
189
|
+
const overlay = document.createElement("div");
|
|
190
|
+
overlay.id = MODAL_ID;
|
|
191
|
+
overlay.setAttribute("role", "dialog");
|
|
192
|
+
overlay.setAttribute("aria-modal", "true");
|
|
193
|
+
overlay.setAttribute("aria-label", "Stellar Snap payment");
|
|
194
|
+
const styles = {
|
|
195
|
+
position: "fixed",
|
|
196
|
+
inset: "0",
|
|
197
|
+
zIndex: "2147483647",
|
|
198
|
+
display: "flex",
|
|
199
|
+
alignItems: "center",
|
|
200
|
+
justifyContent: "center",
|
|
201
|
+
backgroundColor: "rgba(0, 0, 0, 0.6)",
|
|
202
|
+
padding: "20px",
|
|
203
|
+
boxSizing: "border-box"
|
|
204
|
+
};
|
|
205
|
+
Object.assign(overlay.style, styles);
|
|
206
|
+
const container = document.createElement("div");
|
|
207
|
+
container.style.position = "relative";
|
|
208
|
+
container.style.width = `${width}px`;
|
|
209
|
+
container.style.maxWidth = "100%";
|
|
210
|
+
container.style.height = `${height}px`;
|
|
211
|
+
container.style.maxHeight = "90vh";
|
|
212
|
+
container.style.backgroundColor = "rgb(23, 23, 23)";
|
|
213
|
+
container.style.borderRadius = "16px";
|
|
214
|
+
container.style.boxShadow = "0 25px 50px -12px rgba(0, 0, 0, 0.5)";
|
|
215
|
+
container.style.overflow = "hidden";
|
|
216
|
+
const closeBtn = document.createElement("button");
|
|
217
|
+
closeBtn.type = "button";
|
|
218
|
+
closeBtn.setAttribute("aria-label", "Close");
|
|
219
|
+
closeBtn.textContent = "\xD7";
|
|
220
|
+
closeBtn.style.cssText = "position:absolute;top:12px;right:12px;z-index:10;width:32px;height:32px;border:none;border-radius:8px;background:rgba(255,255,255,0.1);color:#e5e5e5;font-size:24px;line-height:1;cursor:pointer;display:flex;align-items:center;justify-content:center;";
|
|
221
|
+
closeBtn.onclick = () => {
|
|
222
|
+
closeSnapModal();
|
|
223
|
+
onClose?.();
|
|
224
|
+
};
|
|
225
|
+
const iframe = document.createElement("iframe");
|
|
226
|
+
iframe.id = IFRAME_ID;
|
|
227
|
+
iframe.src = snapUrl;
|
|
228
|
+
iframe.title = "Stellar Snap payment";
|
|
229
|
+
iframe.style.cssText = "width:100%;height:100%;border:none;border-radius:16px;";
|
|
230
|
+
container.appendChild(closeBtn);
|
|
231
|
+
container.appendChild(iframe);
|
|
232
|
+
overlay.appendChild(container);
|
|
233
|
+
overlay.addEventListener("click", (e) => {
|
|
234
|
+
if (e.target === overlay) {
|
|
235
|
+
closeSnapModal();
|
|
236
|
+
onClose?.();
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
document.body.appendChild(overlay);
|
|
240
|
+
}
|
|
241
|
+
function closeSnapModal() {
|
|
242
|
+
if (!isBrowser()) return;
|
|
243
|
+
const el = document.getElementById(MODAL_ID);
|
|
244
|
+
if (el) el.remove();
|
|
245
|
+
}
|
|
246
|
+
|
|
179
247
|
// src/snap-id.ts
|
|
180
248
|
var ALPHABET = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
181
249
|
function generateSnapId(length = 8) {
|
|
@@ -1205,6 +1273,7 @@ exports.StellarSnapError = StellarSnapError;
|
|
|
1205
1273
|
exports.addDomain = addDomain;
|
|
1206
1274
|
exports.buildPaymentTransaction = buildPaymentTransaction;
|
|
1207
1275
|
exports.buildUrl = buildUrl;
|
|
1276
|
+
exports.closeSnapModal = closeSnapModal;
|
|
1208
1277
|
exports.connectFreighter = connectFreighter;
|
|
1209
1278
|
exports.createAsset = createAsset;
|
|
1210
1279
|
exports.createDiscoveryFile = createDiscoveryFile;
|
|
@@ -1242,6 +1311,7 @@ exports.isValidStellarAddress = isValidStellarAddress;
|
|
|
1242
1311
|
exports.listSnaps = listSnaps;
|
|
1243
1312
|
exports.matchUrlToRule = matchUrlToRule;
|
|
1244
1313
|
exports.metaTagsToHtml = metaTagsToHtml;
|
|
1314
|
+
exports.openSnapModal = openSnapModal;
|
|
1245
1315
|
exports.parseAddress = parseAddress;
|
|
1246
1316
|
exports.parseQueryParams = parseQueryParams;
|
|
1247
1317
|
exports.parseSnapUri = parseSnapUri;
|