@cosmosapp/pay_sdk 1.0.1 → 1.2.0
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 +18 -8
- package/LICENSE +273 -18
- package/README.md +269 -8
- package/dist/chunk-TZDZBVFS.js +216 -0
- package/dist/chunk-TZDZBVFS.js.map +1 -0
- package/dist/index.cjs +333 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -427
- package/dist/index.d.ts +117 -427
- package/dist/index.js +162 -67
- package/dist/index.js.map +1 -1
- package/dist/intent-input-Ch8ogEg-.d.cts +750 -0
- package/dist/intent-input-Ch8ogEg-.d.ts +750 -0
- package/dist/web/index.cjs +1260 -0
- package/dist/web/index.cjs.map +1 -0
- package/dist/web/index.d.cts +758 -0
- package/dist/web/index.d.ts +758 -0
- package/dist/web/index.js +1015 -0
- package/dist/web/index.js.map +1 -0
- package/llms/00-overview.md +43 -0
- package/llms/01-installation.md +35 -0
- package/llms/02-authentication.md +48 -0
- package/llms/03-quickstart.md +57 -0
- package/llms/04-client.md +54 -0
- package/llms/05-payment-intents.md +79 -0
- package/llms/06-web-client.md +113 -0
- package/llms/07-webhooks.md +109 -0
- package/llms/08-products-customers.md +52 -0
- package/llms/09-analytics-health.md +25 -0
- package/llms/10-assets-wallets-addresses.md +57 -0
- package/llms/11-errors-observability.md +47 -0
- package/llms/12-configuration.md +43 -0
- package/llms/13-types-reference.md +78 -0
- package/llms/14-recipes.md +87 -0
- package/llms/README.md +40 -0
- package/llms/llms-full.txt +977 -0
- package/llms/llms.txt +45 -0
- package/package.json +44 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
All notable changes to
|
|
3
|
+
All notable changes to @cosmosapp/pay_sdk are documented here.
|
|
4
|
+
Generated from [Conventional Commits](https://www.conventionalcommits.org) by [git-cliff](https://git-cliff.org).
|
|
5
|
+
## [1.2.0] - 2026-07-11
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
### Features
|
|
8
|
+
- Implement SwapManager and Swap structure, add swap functionality to Client, and enhance testing (12d3bbd)
|
|
9
|
+
- Derive the release bump from Conventional Commits (auto-versioning) (d43ccb7)
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
- Sync src/util/Constants.ts version on release so tests pass (632c967)
|
|
13
|
+
|
|
14
|
+
### CI/CD
|
|
15
|
+
- Add Dependabot, unify changelog on git-cliff, modernize workflows (dae7b63)
|
|
16
|
+
- Fully automatic release on every push to main (skip when nothing to release) (8304ed7)
|
|
17
|
+
|
|
18
|
+
### Dependencies
|
|
19
|
+
- Update dependencies and fix the esbuild advisory (d3215c1)
|
|
20
|
+
|
|
21
|
+
## [1.0.1] - 2026-06-25
|
|
6
22
|
|
|
7
|
-
- Update package-lock.json and package.json to reflect package name change to "@cosmosapp/pay_sdk" and add "semver" as a dev dependency. Enhance GitHub Actions workflow for automated versioning and publishing, including a new script for version resolution. ([`ec09229`](https://github.com/CosmosPay/CosmosJS_SDK/commit/ec09229))
|
|
8
|
-
- Update default gateway URL in documentation and code; clarify usage for self-hosting and API key configuration ([`f3479df`](https://github.com/CosmosPay/CosmosJS_SDK/commit/f3479df))
|
|
9
|
-
- Add repository metadata and update CI badge in README ([`3d60008`](https://github.com/CosmosPay/CosmosJS_SDK/commit/3d60008))
|
|
10
|
-
- Rename package from "cosmospay.js" to "@cosmosapp/pay_sdk" and update all references in documentation, examples, and codebase. Adjust CI/CD workflow to enable automatic publishing on version changes. ([`0d8847a`](https://github.com/CosmosPay/CosmosJS_SDK/commit/0d8847a))
|
|
11
|
-
- Enhance testing and CI/CD setup: Updated test scripts in package.json to include specific test files, added CI and release workflows for automated testing and publishing, and improved README with CI/CD details. ([`3d55592`](https://github.com/CosmosPay/CosmosJS_SDK/commit/3d55592))
|
|
12
|
-
- First commit ([`23825de`](https://github.com/CosmosPay/CosmosJS_SDK/commit/23825de))
|
|
13
23
|
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,276 @@
|
|
|
1
|
-
|
|
1
|
+
Cosmos Pay Source-Available License
|
|
2
|
+
Version 1.0
|
|
2
3
|
|
|
3
4
|
Copyright (c) 2026 Cosmos Pay
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
This software is "source available." You may use it freely — including in
|
|
7
|
+
commercial products and services — subject to the terms below. It is licensed
|
|
8
|
+
under the Apache License, Version 2.0 (the "Apache License", reproduced in full
|
|
9
|
+
below), AS MODIFIED by the two Additional Restrictions set out in this preamble.
|
|
10
|
+
|
|
11
|
+
In case of any conflict between the Additional Restrictions and the Apache
|
|
12
|
+
License, the Additional Restrictions control. Every copy or substantial portion
|
|
13
|
+
of the software must retain this preamble (both Additional Restrictions) together
|
|
14
|
+
with the Apache License text.
|
|
15
|
+
|
|
16
|
+
================================================================================
|
|
17
|
+
Additional Restriction 1 — No Resale Without Modification ("Commons Clause")
|
|
18
|
+
================================================================================
|
|
19
|
+
|
|
20
|
+
The license granted under the Apache License does not include, and this
|
|
21
|
+
Additional Restriction removes, the right to Sell the Software.
|
|
22
|
+
|
|
23
|
+
"Sell" means practicing any or all of the rights granted to you under the Apache
|
|
24
|
+
License to provide to third parties, for a fee or other consideration (including
|
|
25
|
+
without limitation fees for hosting, support, or consulting services related to
|
|
26
|
+
the Software), a product or service whose value derives, entirely or
|
|
27
|
+
substantially, from the functionality of the Software in its original or
|
|
28
|
+
substantially unmodified form.
|
|
29
|
+
|
|
30
|
+
For clarity:
|
|
31
|
+
|
|
32
|
+
- You MAY use the Software, free of charge, in your own commercial and
|
|
33
|
+
non-commercial projects.
|
|
34
|
+
- You MAY build, sell, and operate products and services that include or are
|
|
35
|
+
built on top of the Software, provided your product or service adds
|
|
36
|
+
substantial independent value beyond the Software's own functionality.
|
|
37
|
+
- You MAY modify the Software and distribute your modifications under these
|
|
38
|
+
same terms.
|
|
39
|
+
- You MAY NOT resell or redistribute the Software substantially as-is (whether
|
|
40
|
+
standalone, rebranded, or as a hosted/managed offering) as your product or
|
|
41
|
+
service.
|
|
42
|
+
|
|
43
|
+
"Software" means the work of authorship made available under this license.
|
|
44
|
+
|
|
45
|
+
================================================================================
|
|
46
|
+
Additional Restriction 2 — Acceptable Use (No Malicious Use)
|
|
47
|
+
================================================================================
|
|
48
|
+
|
|
49
|
+
You may not use the Software:
|
|
50
|
+
|
|
51
|
+
(a) to commit, facilitate, or conceal any unlawful, fraudulent, or deceptive
|
|
52
|
+
activity;
|
|
53
|
+
(b) to harm, defraud, or steal from any person, including the theft or
|
|
54
|
+
unauthorized movement of funds, assets, or credentials;
|
|
55
|
+
(c) to develop, distribute, or operate malware, ransomware, phishing,
|
|
56
|
+
scams, or other malicious software or schemes; or
|
|
57
|
+
(d) in any manner that violates applicable law or infringes the human rights
|
|
58
|
+
of others.
|
|
59
|
+
|
|
60
|
+
Your rights under this license terminate automatically and immediately if you
|
|
61
|
+
breach this Additional Restriction.
|
|
62
|
+
|
|
63
|
+
================================================================================
|
|
64
|
+
NOTE ON OPEN SOURCE
|
|
65
|
+
================================================================================
|
|
66
|
+
|
|
67
|
+
Because of the Additional Restrictions above, this license is "source available"
|
|
68
|
+
and is NOT an Open Source license as defined by the Open Source Initiative, nor
|
|
69
|
+
"Free Software" as defined by the Free Software Foundation. Aside from those
|
|
70
|
+
Additional Restrictions, the terms of the Apache License, Version 2.0 apply.
|
|
71
|
+
|
|
72
|
+
================================================================================
|
|
73
|
+
Apache License, Version 2.0
|
|
74
|
+
================================================================================
|
|
75
|
+
|
|
76
|
+
Apache License
|
|
77
|
+
Version 2.0, January 2004
|
|
78
|
+
http://www.apache.org/licenses/
|
|
79
|
+
|
|
80
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
81
|
+
|
|
82
|
+
1. Definitions.
|
|
83
|
+
|
|
84
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
85
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
86
|
+
|
|
87
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
88
|
+
the copyright owner that is granting the License.
|
|
89
|
+
|
|
90
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
91
|
+
other entities that control, are controlled by, or are under common
|
|
92
|
+
control with that entity. For the purposes of this definition,
|
|
93
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
94
|
+
direction or management of such entity, whether by contract or
|
|
95
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
96
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
97
|
+
|
|
98
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
99
|
+
exercising permissions granted by this License.
|
|
100
|
+
|
|
101
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
102
|
+
including but not limited to software source code, documentation
|
|
103
|
+
source, and configuration files.
|
|
104
|
+
|
|
105
|
+
"Object" form shall mean any form resulting from mechanical
|
|
106
|
+
transformation or translation of a Source form, including but
|
|
107
|
+
not limited to compiled object code, generated documentation,
|
|
108
|
+
and conversions to other media types.
|
|
109
|
+
|
|
110
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
111
|
+
Object form, made available under the License, as indicated by a
|
|
112
|
+
copyright notice that is included in or attached to the work
|
|
113
|
+
(an example is provided in the Appendix below).
|
|
114
|
+
|
|
115
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
116
|
+
form, that is based on (or derived from) the Work and for which the
|
|
117
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
118
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
119
|
+
of this License, Derivative Works shall not include works that remain
|
|
120
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
121
|
+
the Work and Derivative Works thereof.
|
|
122
|
+
|
|
123
|
+
"Contribution" shall mean any work of authorship, including
|
|
124
|
+
the original version of the Work and any modifications or additions
|
|
125
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
126
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
127
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
128
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
129
|
+
means any form of electronic, verbal, or written communication sent
|
|
130
|
+
to the Licensor or its representatives, including but not limited to
|
|
131
|
+
communication on electronic mailing lists, source code control systems,
|
|
132
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
133
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
134
|
+
excluding communication that is conspicuously marked or otherwise
|
|
135
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
136
|
+
|
|
137
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
138
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
139
|
+
subsequently incorporated within the Work.
|
|
140
|
+
|
|
141
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
142
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
143
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
144
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
145
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
146
|
+
Work and such Derivative Works in Source or Object form.
|
|
147
|
+
|
|
148
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
149
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
150
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
151
|
+
(except as stated in this section) patent license to make, have made,
|
|
152
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
153
|
+
where such license applies only to those patent claims licensable
|
|
154
|
+
by such Contributor that are necessarily infringed by their
|
|
155
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
156
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
157
|
+
institute patent litigation against any entity (including a
|
|
158
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
159
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
160
|
+
or contributory patent infringement, then any patent licenses
|
|
161
|
+
granted to You under this License for that Work shall terminate
|
|
162
|
+
as of the date such litigation is filed.
|
|
163
|
+
|
|
164
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
165
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
166
|
+
modifications, and in Source or Object form, provided that You
|
|
167
|
+
meet the following conditions:
|
|
168
|
+
|
|
169
|
+
(a) You must give any other recipients of the Work or
|
|
170
|
+
Derivative Works a copy of this License; and
|
|
171
|
+
|
|
172
|
+
(b) You must cause any modified files to carry prominent notices
|
|
173
|
+
stating that You changed the files; and
|
|
174
|
+
|
|
175
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
176
|
+
that You distribute, all copyright, patent, trademark, and
|
|
177
|
+
attribution notices from the Source form of the Work,
|
|
178
|
+
excluding those notices that do not pertain to any part of
|
|
179
|
+
the Derivative Works; and
|
|
180
|
+
|
|
181
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
182
|
+
distribution, then any Derivative Works that You distribute must
|
|
183
|
+
include a readable copy of the attribution notices contained
|
|
184
|
+
within such NOTICE file, excluding those notices that do not
|
|
185
|
+
pertain to any part of the Derivative Works, in at least one
|
|
186
|
+
of the following places: within a NOTICE text file distributed
|
|
187
|
+
as part of the Derivative Works; within the Source form or
|
|
188
|
+
documentation, if provided along with the Derivative Works; or,
|
|
189
|
+
within a display generated by the Derivative Works, if and
|
|
190
|
+
wherever such third-party notices normally appear. The contents
|
|
191
|
+
of the NOTICE file are for informational purposes only and
|
|
192
|
+
do not modify the License. You may add Your own attribution
|
|
193
|
+
notices within Derivative Works that You distribute, alongside
|
|
194
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
195
|
+
that such additional attribution notices cannot be construed
|
|
196
|
+
as modifying the License.
|
|
197
|
+
|
|
198
|
+
You may add Your own copyright statement to Your modifications and
|
|
199
|
+
may provide additional or different license terms and conditions
|
|
200
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
201
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
202
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
203
|
+
the conditions stated in this License.
|
|
204
|
+
|
|
205
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
206
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
207
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
208
|
+
this License, without any additional terms or conditions.
|
|
209
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
210
|
+
the terms of any separate license agreement you may have executed
|
|
211
|
+
with Licensor regarding such Contributions.
|
|
212
|
+
|
|
213
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
214
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
215
|
+
except as required for reasonable and customary use in describing the
|
|
216
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
217
|
+
|
|
218
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
219
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
220
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
221
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
222
|
+
implied, including, without limitation, any warranties or conditions
|
|
223
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
224
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
225
|
+
appropriateness of using or redistributing the Work and assume any
|
|
226
|
+
risks associated with Your exercise of permissions under this License.
|
|
227
|
+
|
|
228
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
229
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
230
|
+
unless required by applicable law (such as deliberate and grossly
|
|
231
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
232
|
+
liable to You for damages, including any direct, indirect, special,
|
|
233
|
+
incidental, or consequential damages of any character arising as a
|
|
234
|
+
result of this License or out of the use or inability to use the
|
|
235
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
236
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
237
|
+
other commercial damages or losses), even if such Contributor
|
|
238
|
+
has been advised of the possibility of such damages.
|
|
239
|
+
|
|
240
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
241
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
242
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
243
|
+
or other liability obligations and/or rights consistent with this
|
|
244
|
+
License. However, in accepting such obligations, You may act only
|
|
245
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
246
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
247
|
+
defend, and hold each Contributor harmless for any liability
|
|
248
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
249
|
+
of your accepting any such warranty or additional liability.
|
|
250
|
+
|
|
251
|
+
END OF TERMS AND CONDITIONS
|
|
252
|
+
|
|
253
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
254
|
+
|
|
255
|
+
To apply the Apache License to your work, attach the following
|
|
256
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
257
|
+
replaced with your own identifying information. (Don't include
|
|
258
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
259
|
+
comment syntax for the file format. We also recommend that a
|
|
260
|
+
file or class name and description of purpose be included on the
|
|
261
|
+
same "printed page" as the copyright notice for easier
|
|
262
|
+
identification within third-party archives.
|
|
263
|
+
|
|
264
|
+
Copyright 2026 Cosmos Pay
|
|
265
|
+
|
|
266
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
267
|
+
you may not use this file except in compliance with the License.
|
|
268
|
+
You may obtain a copy of the License at
|
|
269
|
+
|
|
270
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
271
|
+
|
|
272
|
+
Unless required by applicable law or agreed to in writing, software
|
|
273
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
274
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
275
|
+
See the License for the specific language governing permissions and
|
|
276
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -11,16 +11,24 @@ Stellar **SEP-7 payment intents** · **webhooks** · **products** · **customers
|
|
|
11
11
|
[](https://www.npmjs.com/package/@cosmosapp/pay_sdk)
|
|
12
12
|
[](https://www.npmjs.com/package/@cosmosapp/pay_sdk)
|
|
13
13
|
[](https://nodejs.org)
|
|
14
|
-
[](./LICENSE)
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
-
Designed
|
|
21
|
-
|
|
20
|
+
Designed to be **atomic**: one `Client`, every resource split into its own manager, and rich
|
|
21
|
+
structure classes that can act on themselves.
|
|
22
|
+
|
|
23
|
+
The SDK ships **two entry points** for the two halves of a payment:
|
|
24
|
+
|
|
25
|
+
| Import | Where it runs | What it does |
|
|
26
|
+
| ------ | ------------- | ------------ |
|
|
27
|
+
| `@cosmosapp/pay_sdk` | **server** (Node ≥ 18) | Create & manage SEP-7 payment intents, webhooks, products, customers, analytics — everything that needs your secret API key. |
|
|
28
|
+
| `@cosmosapp/pay_sdk/web` | **browser** | *Complete* an intent: auto-detect the user's Stellar wallet (Freighter, xBull, Rabet, LOBSTR, Albedo…), adapt the response into a transaction, request a signature and submit — **provider-agnostic, no provider argument**. |
|
|
22
29
|
|
|
23
30
|
```ts
|
|
31
|
+
// ── server ──────────────────────────────────────────────────────────
|
|
24
32
|
import { Client } from '@cosmosapp/pay_sdk';
|
|
25
33
|
|
|
26
34
|
// You only bring your API key — the gateway URL and other internals are pre-configured for you.
|
|
@@ -30,14 +38,36 @@ const intent = await client.paymentIntents.createPay({ destination: 'G...', amou
|
|
|
30
38
|
console.log(intent.uri); // web+stellar:pay?destination=...
|
|
31
39
|
```
|
|
32
40
|
|
|
41
|
+
```ts
|
|
42
|
+
// ── browser ─────────────────────────────────────────────────────────
|
|
43
|
+
import { WebClient } from '@cosmosapp/pay_sdk/web';
|
|
44
|
+
|
|
45
|
+
// `intent` is the payload your server returned above. No wallet/provider to choose.
|
|
46
|
+
const webClient = new WebClient();
|
|
47
|
+
const { txHash, account, wallet } = await webClient.pay(intent);
|
|
48
|
+
console.log(`Paid via ${wallet} from ${account}: ${txHash}`);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> 📚 **Runnable examples** for every feature live in [`examples/`](./examples)
|
|
52
|
+
> (one file per area — payment intents, web client, webhooks, products, customers,
|
|
53
|
+
> analytics, errors, …). See [`examples/README.md`](./examples/README.md).
|
|
54
|
+
>
|
|
55
|
+
> 🤖 **Using an AI assistant?** Atomic, AI-readable docs live in the isolated
|
|
56
|
+
> [`llms/`](./llms) folder ([`llms.txt`](./llms/llms.txt) index + per-topic files +
|
|
57
|
+
> a combined [`llms-full.txt`](./llms/llms-full.txt)) — point your tool at them to
|
|
58
|
+
> make integrating the SDK much easier. After install they're at
|
|
59
|
+
> `node_modules/@cosmosapp/pay_sdk/llms/`.
|
|
60
|
+
|
|
33
61
|
## ✨ Features
|
|
34
62
|
|
|
35
63
|
- ✅ **TypeScript & JavaScript** — full typings, works in both **CJS** and **ESM**.
|
|
36
64
|
- ✅ **Zero runtime dependencies** — native `fetch` + `node:crypto`, nothing else.
|
|
37
|
-
- ✅ **Atomic
|
|
65
|
+
- ✅ **Atomic API** — one client, one manager per resource: `client.paymentIntents`, `client.webhooks`, …
|
|
38
66
|
- ✅ **Self-acting structures** — `intent.validate()`, `endpoint.rotateSecret()`, `product.deactivate()`.
|
|
39
67
|
- ✅ **Built-in webhook signature verification** + ready-made `http` / Express handlers.
|
|
40
68
|
- ✅ **Resilient by default** — automatic retries, timeouts and structured errors.
|
|
69
|
+
- ✅ **Browser web client** — auto-detects Freighter, xBull, Rabet, LOBSTR & Albedo, builds the
|
|
70
|
+
transaction from the SEP-7 response and signs it. Agnostic — you never pass a provider.
|
|
41
71
|
|
|
42
72
|
## 📑 Table of contents
|
|
43
73
|
|
|
@@ -45,7 +75,9 @@ console.log(intent.uri); // web+stellar:pay?destination=...
|
|
|
45
75
|
- [Authentication](#-authentication)
|
|
46
76
|
- [Quick start](#-quick-start)
|
|
47
77
|
- [The client at a glance](#-the-client-at-a-glance)
|
|
78
|
+
- [Web client (browser wallets)](#-web-client-browser-wallets)
|
|
48
79
|
- [Payment intents](#-payment-intents)
|
|
80
|
+
- [Typed assets, wallets & addresses](#-typed-assets-wallets--addresses)
|
|
49
81
|
- [Webhooks](#-webhooks)
|
|
50
82
|
- [Products & customers](#-products--customers)
|
|
51
83
|
- [Analytics & health](#-analytics--health)
|
|
@@ -150,6 +182,165 @@ if (outcome.valid) console.log('Settled!', outcome.status);
|
|
|
150
182
|
| `client.analytics` | Read-only metrics & logs | `summary` · `balances` · `apiLogs` · `webhookLogs` |
|
|
151
183
|
| `client.health` | Liveness / readiness probes | `liveness` · `readiness` |
|
|
152
184
|
|
|
185
|
+
## 🌐 Web client (browser wallets)
|
|
186
|
+
|
|
187
|
+
The server SDK *creates* intents. The **web client** *completes* them in the user's browser.
|
|
188
|
+
|
|
189
|
+
Stellar browser wallets (Freighter, xBull, Rabet, LOBSTR, Albedo…) **don't ingest SEP-7
|
|
190
|
+
`web+stellar:` URIs from a dapp** — each exposes its own JS API. The web client bridges that gap: it
|
|
191
|
+
**auto-detects** whichever wallet the user has, **adapts** the Cosmos Pay response into a concrete
|
|
192
|
+
Stellar transaction (building the payment for `pay` intents, reusing the XDR for `tx` intents), asks
|
|
193
|
+
the wallet to **sign**, and **submits** to Horizon (or POSTs to the SEP-7 `callback`). You never
|
|
194
|
+
*have to* pass a provider — it's fully agnostic — but you **can** pin one when you want (see
|
|
195
|
+
[Inspecting & choosing wallets](#inspecting--choosing-wallets)).
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# the web client builds/submits transactions, so it needs the Stellar SDK (optional peer dep)
|
|
199
|
+
npm install @cosmosapp/pay_sdk @stellar/stellar-sdk
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### The typical flow
|
|
203
|
+
|
|
204
|
+
1. **Server** creates the intent (with your secret key) and sends the payload to your frontend.
|
|
205
|
+
2. **Browser** completes it — one call:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { WebClient } from '@cosmosapp/pay_sdk/web';
|
|
209
|
+
|
|
210
|
+
const webClient = new WebClient(); // auto-detects the wallet
|
|
211
|
+
|
|
212
|
+
// `intent` may be the PaymentIntent payload from your server, a PaymentIntent
|
|
213
|
+
// instance, or even the raw `web+stellar:` URI string.
|
|
214
|
+
const result = await webClient.pay(intent);
|
|
215
|
+
|
|
216
|
+
console.log(result.wallet); // 'freighter' | 'xbull' | 'rabet' | 'lobstr' | 'albedo' | ...
|
|
217
|
+
console.log(result.account); // the G... account that signed
|
|
218
|
+
console.log(result.txHash); // the on-chain transaction hash
|
|
219
|
+
console.log(result.submitted); // true
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
3. Report `result.txHash` back to your server and finalize with `intent.validate(txHash)` (or call
|
|
223
|
+
`webClient.validate(...)`, see below).
|
|
224
|
+
|
|
225
|
+
### Supported wallets
|
|
226
|
+
|
|
227
|
+
Auto-detected with **zero config** (they inject a browser global):
|
|
228
|
+
|
|
229
|
+
| Wallet | id | Detection |
|
|
230
|
+
| ------ | -- | --------- |
|
|
231
|
+
| **Freighter** | `freighter` | `window.freighterApi` (extension) |
|
|
232
|
+
| **xBull** | `xbull` | `window.xBullSDK` (extension) |
|
|
233
|
+
| **Rabet** | `rabet` | `window.rabet` (extension) |
|
|
234
|
+
|
|
235
|
+
Enabled by **passing their library** (no reliable global to sniff):
|
|
236
|
+
|
|
237
|
+
| Wallet | id | How to enable |
|
|
238
|
+
| ------ | -- | ------------- |
|
|
239
|
+
| **Albedo** | `albedo` | `new WebClient({ albedo })` — `import albedo from '@albedo-link/intent'` |
|
|
240
|
+
| **LOBSTR** | `lobstr` | `new WebClient({ lobstr })` — `import * as lobstr from '@lobstrco/signer-extension-api'` |
|
|
241
|
+
|
|
242
|
+
Bring **any other** wallet (WalletConnect, Ledger, a custom signer) by implementing the small
|
|
243
|
+
`WalletAdapter` interface and registering it — see [Custom wallets](#custom-wallets).
|
|
244
|
+
|
|
245
|
+
### Inspecting & choosing wallets
|
|
246
|
+
|
|
247
|
+
Detection is automatic by default, **but the provider can also be defined** — per call, or as the
|
|
248
|
+
client's preferred order:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import { Wallets } from '@cosmosapp/pay_sdk/web';
|
|
252
|
+
|
|
253
|
+
const wallets = await webClient.getAvailableWallets();
|
|
254
|
+
// [{ id: 'freighter', name: 'Freighter', available: true }, { id: 'xbull', … }, …]
|
|
255
|
+
|
|
256
|
+
// Just connect (e.g. to show the address) without paying:
|
|
257
|
+
const { wallet, address, network } = await webClient.connect();
|
|
258
|
+
|
|
259
|
+
// Pin a specific provider for one call:
|
|
260
|
+
await webClient.pay(intent, { wallet: Wallets.XBULL });
|
|
261
|
+
|
|
262
|
+
// …or set the default order for this client:
|
|
263
|
+
const pinned = new WebClient({ preferredWallets: [Wallets.XBULL, Wallets.FREIGHTER] });
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### `tx` vs `pay` intents
|
|
267
|
+
|
|
268
|
+
- **`pay` intent** (no source): the client builds a payment transaction from the **connected account**
|
|
269
|
+
as source — loading its sequence from Horizon, adding the payment op + memo, fee and timebounds.
|
|
270
|
+
For an open-amount intent (e.g. a donation) pass the amount: `webClient.pay(intent, { amount: '5' })`.
|
|
271
|
+
- **`tx` intent** (source known, XDR present): the client signs the **returned XDR** as-is. If the
|
|
272
|
+
connected wallet isn't the intent's `source`, it throws a clear error so you can prompt an account
|
|
273
|
+
switch.
|
|
274
|
+
|
|
275
|
+
Want to show the user the transaction before signing? Build without prompting:
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
const { xdr, source, network } = await webClient.buildTransaction(intent);
|
|
279
|
+
// …render a confirmation…
|
|
280
|
+
const result = await webClient.pay(intent); // or sign the xdr yourself
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`webClient.pay(intent, { sign: true })` signs **without** submitting (returns `signedXdr`); `{ submit: false }`
|
|
284
|
+
also skips submission.
|
|
285
|
+
|
|
286
|
+
### Network detection
|
|
287
|
+
|
|
288
|
+
The network (mainnet/testnet), passphrase and Horizon endpoint are **inferred from the intent**
|
|
289
|
+
(its `network` field / the SEP-7 `network_passphrase`). Override if you self-host Horizon:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
new WebClient({ network: 'testnet', horizonUrl: 'https://horizon-testnet.stellar.org' });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Custom wallets
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
import { WebClient, type WalletAdapter } from '@cosmosapp/pay_sdk/web';
|
|
299
|
+
|
|
300
|
+
const myWallet: WalletAdapter = {
|
|
301
|
+
id: 'my-wallet',
|
|
302
|
+
name: 'My Wallet',
|
|
303
|
+
async isAvailable() { return Boolean(globalThis.myWallet); },
|
|
304
|
+
async getPublicKey() { return globalThis.myWallet.getAddress(); },
|
|
305
|
+
async signTransaction(xdr, { networkPassphrase }) {
|
|
306
|
+
return globalThis.myWallet.sign(xdr, networkPassphrase);
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const webClient = new WebClient();
|
|
311
|
+
webClient.registerWallet(myWallet, /* prepend (win auto-detection) */ true);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Talking to the API directly (optional — trusted environments only)
|
|
315
|
+
|
|
316
|
+
The web client can **also call the Cosmos Pay API directly** — creating and validating intents from
|
|
317
|
+
the browser — by passing an `apiKey`. This is handy for prototypes, internal tools and other
|
|
318
|
+
**trusted environments**.
|
|
319
|
+
|
|
320
|
+
> ⚠️ **Not recommended for public/production frontends.** Doing this ships your API key to the
|
|
321
|
+
> browser, where anyone can read it. Only enable it when the environment is trusted and the key is
|
|
322
|
+
> safe to expose (e.g. a scoped testnet `dv_` key). For production, **create and validate intents on
|
|
323
|
+
> your server** and let the web client only sign/submit.
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
const webClient = new WebClient({ apiKey: 'dv_test_only' }); // trusted env only
|
|
327
|
+
const intent = await webClient.createPay({ destination: 'G...', amount: '10' });
|
|
328
|
+
const result = await webClient.pay(intent);
|
|
329
|
+
const outcome = await webClient.validate(intent.id, result.txHash);
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Inject everything (advanced / SSR / bundle control)
|
|
333
|
+
|
|
334
|
+
Nothing is imported eagerly. You can inject the Stellar SDK and any wallet library so the bundler
|
|
335
|
+
sees explicit imports:
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
import * as StellarSdk from '@stellar/stellar-sdk';
|
|
339
|
+
import freighter from '@stellar/freighter-api';
|
|
340
|
+
|
|
341
|
+
const webClient = new WebClient({ stellarSdk: StellarSdk, freighter });
|
|
342
|
+
```
|
|
343
|
+
|
|
153
344
|
## 💳 Payment intents
|
|
154
345
|
|
|
155
346
|
```ts
|
|
@@ -162,8 +353,13 @@ const tx = await client.paymentIntents.createTx({
|
|
|
162
353
|
});
|
|
163
354
|
console.log(tx.xdr, tx.uri, tx.qr);
|
|
164
355
|
|
|
165
|
-
// pay intent (no source)
|
|
166
|
-
|
|
356
|
+
// pay intent (no source) — typed asset, no issuer to look up
|
|
357
|
+
import { Assets } from '@cosmosapp/pay_sdk';
|
|
358
|
+
const pay = await client.paymentIntents.createPay({
|
|
359
|
+
destination: 'G...',
|
|
360
|
+
amount: '10',
|
|
361
|
+
asset: Assets.USDC, // fills assetCode + the verified issuer for you
|
|
362
|
+
});
|
|
167
363
|
|
|
168
364
|
// fetch one
|
|
169
365
|
const intent = await client.paymentIntents.fetch('pi_123');
|
|
@@ -184,6 +380,58 @@ const outcome = await intent.validate('<txHash>');
|
|
|
184
380
|
Each `PaymentIntent` exposes typed helpers: `isTx`, `isPay`, `isSucceeded`, `isPending`, `assetLabel`,
|
|
185
381
|
and the action methods `fetch()`, `edit()`, `validate()`, `cancel()`, `delete()`.
|
|
186
382
|
|
|
383
|
+
## 🎨 Typed assets, wallets & addresses
|
|
384
|
+
|
|
385
|
+
So you never paste the wrong issuer or a magic string, the SDK ships small **typed, extensible
|
|
386
|
+
catalogs** — and a plain string still works everywhere. These are exported from **both** entry points
|
|
387
|
+
(`@cosmosapp/pay_sdk` and `@cosmosapp/pay_sdk/web`).
|
|
388
|
+
|
|
389
|
+
**Assets** — common assets with their **verified issuers** baked in (no contract/issuer hunting):
|
|
390
|
+
|
|
391
|
+
```ts
|
|
392
|
+
import { Assets, defineAsset, TestnetAssets } from '@cosmosapp/pay_sdk';
|
|
393
|
+
|
|
394
|
+
Assets.XLM; // native lumens
|
|
395
|
+
Assets.USDC; // { code: 'USDC', issuer: 'GA5Z…' } (Circle, mainnet — verified)
|
|
396
|
+
Assets.EURC; // { code: 'EURC', issuer: 'GDHU…' }
|
|
397
|
+
|
|
398
|
+
// Need another asset? Define it once (issuer/contract are validated):
|
|
399
|
+
const AQUA = defineAsset({ code: 'AQUA', issuer: 'GBNZ…ILCT', name: 'Aquarius' });
|
|
400
|
+
|
|
401
|
+
await client.paymentIntents.createPay({ destination: 'G...', amount: '5', asset: AQUA });
|
|
402
|
+
|
|
403
|
+
// Plain code strings still work (treated as code-only):
|
|
404
|
+
await client.paymentIntents.createPay({ destination: 'G...', amount: '5', assetCode: 'USDC', assetIssuer: 'G...' });
|
|
405
|
+
|
|
406
|
+
// Testnet issuers live in TestnetAssets.* (e.g. TestnetAssets.USDC).
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
> ⚠️ Issuers are network-specific. `Assets.*` targets **mainnet**; use `TestnetAssets.*` for testnet.
|
|
410
|
+
|
|
411
|
+
**Wallets** — typed ids instead of magic strings:
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
import { WebClient, Wallets } from '@cosmosapp/pay_sdk/web';
|
|
415
|
+
|
|
416
|
+
const webClient = new WebClient({ preferredWallets: [Wallets.XBULL, Wallets.FREIGHTER] });
|
|
417
|
+
await webClient.pay(intent, { wallet: Wallets.FREIGHTER }); // pin a provider for one call
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**Addresses** — name the accounts you use a lot and reference them by name; values are validated, and
|
|
421
|
+
anything unknown passes through unchanged (so raw `G…`, muxed `M…` and federation addresses keep
|
|
422
|
+
working):
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
import { addresses } from '@cosmosapp/pay_sdk';
|
|
426
|
+
|
|
427
|
+
addresses.define('merchant', 'GC...PAYOUT');
|
|
428
|
+
await client.paymentIntents.createPay({ destination: 'merchant', amount: '10' });
|
|
429
|
+
|
|
430
|
+
// validation helpers, too:
|
|
431
|
+
import { isStellarAddress } from '@cosmosapp/pay_sdk';
|
|
432
|
+
isStellarAddress('GC...'); // true
|
|
433
|
+
```
|
|
434
|
+
|
|
187
435
|
## 🔔 Webhooks
|
|
188
436
|
|
|
189
437
|
```ts
|
|
@@ -210,7 +458,7 @@ await endpoint.delete();
|
|
|
210
458
|
|
|
211
459
|
### Receiving events — `client.webhooks.on(...)`
|
|
212
460
|
|
|
213
|
-
Subscribe to events the
|
|
461
|
+
Subscribe to events with the atomic event API. You can listen with the raw type, its camelCase alias, or
|
|
214
462
|
`event` for everything:
|
|
215
463
|
|
|
216
464
|
```ts
|
|
@@ -456,4 +704,17 @@ pushing unrelated commits is always safe. Packages ship with
|
|
|
456
704
|
|
|
457
705
|
## 📄 License
|
|
458
706
|
|
|
459
|
-
[
|
|
707
|
+
**Cosmos Pay Source-Available License** — see [`LICENSE`](./LICENSE).
|
|
708
|
+
|
|
709
|
+
It's based on the **Apache License 2.0** with two additional restrictions, so in short:
|
|
710
|
+
|
|
711
|
+
- ✅ **Free to use**, including in **commercial** products and services.
|
|
712
|
+
- ✅ **Modify and distribute** your changes under the same terms.
|
|
713
|
+
- ❌ **No reselling the SDK as-is** — you can't redistribute or host it substantially
|
|
714
|
+
unmodified as your own product/service (Commons Clause). Building real products *on top of* it is
|
|
715
|
+
fine.
|
|
716
|
+
- ❌ **No malicious use** — no fraud, theft, malware/phishing, or uses that break the law or
|
|
717
|
+
violate others' rights.
|
|
718
|
+
|
|
719
|
+
> Because of those restrictions this is a **source-available** license, not an OSI-approved
|
|
720
|
+
> "open source" one. This is not legal advice.
|