munim-billing 0.0.0-stage → 0.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/LICENSE +201 -0
- package/README.md +550 -2
- package/lib/cjs/client.js +233 -0
- package/lib/cjs/client.js.map +1 -0
- package/lib/cjs/errors.js +55 -0
- package/lib/cjs/errors.js.map +1 -0
- package/lib/cjs/index.js +28 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/react-native.js +118 -0
- package/lib/cjs/react-native.js.map +1 -0
- package/lib/cjs/types.js +21 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/cjs/version.js +6 -0
- package/lib/cjs/version.js.map +1 -0
- package/lib/cjs/web.js +157 -0
- package/lib/cjs/web.js.map +1 -0
- package/lib/cjs/webhooks.js +137 -0
- package/lib/cjs/webhooks.js.map +1 -0
- package/lib/esm/client.d.ts +131 -0
- package/lib/esm/client.d.ts.map +1 -0
- package/lib/esm/client.js +226 -0
- package/lib/esm/client.js.map +1 -0
- package/lib/esm/errors.d.ts +22 -0
- package/lib/esm/errors.d.ts.map +1 -0
- package/lib/esm/errors.js +50 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/index.d.ts +10 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +6 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/react-native.d.ts +72 -0
- package/lib/esm/react-native.d.ts.map +1 -0
- package/lib/esm/react-native.js +114 -0
- package/lib/esm/react-native.js.map +1 -0
- package/lib/esm/types.d.ts +303 -0
- package/lib/esm/types.d.ts.map +1 -0
- package/lib/esm/types.js +18 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/version.d.ts +3 -0
- package/lib/esm/version.d.ts.map +1 -0
- package/lib/esm/version.js +3 -0
- package/lib/esm/version.js.map +1 -0
- package/lib/esm/web.d.ts +40 -0
- package/lib/esm/web.d.ts.map +1 -0
- package/lib/esm/web.js +152 -0
- package/lib/esm/web.js.map +1 -0
- package/lib/esm/webhooks.d.ts +59 -0
- package/lib/esm/webhooks.d.ts.map +1 -0
- package/lib/esm/webhooks.js +129 -0
- package/lib/esm/webhooks.js.map +1 -0
- package/package.json +116 -4
- package/src/client.ts +314 -0
- package/src/errors.ts +74 -0
- package/src/index.ts +26 -0
- package/src/react-native.ts +154 -0
- package/src/types.ts +366 -0
- package/src/version.ts +2 -0
- package/src/web.ts +182 -0
- package/src/webhooks.ts +169 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MunimBilling_instances, _MunimBilling_secretKey, _MunimBilling_fetch, _MunimBilling_timeoutMs, _MunimBilling_get, _MunimBilling_post;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MunimBilling = exports.TEST_BASE_URL = exports.LIVE_BASE_URL = void 0;
|
|
16
|
+
exports.modeForKey = modeForKey;
|
|
17
|
+
exports.baseUrlForKey = baseUrlForKey;
|
|
18
|
+
exports.paginate = paginate;
|
|
19
|
+
const errors_js_1 = require("./errors.js");
|
|
20
|
+
const version_js_1 = require("./version.js");
|
|
21
|
+
const webhooks_js_1 = require("./webhooks.js");
|
|
22
|
+
exports.LIVE_BASE_URL = 'https://billing-api.munimtech.com';
|
|
23
|
+
exports.TEST_BASE_URL = 'https://billing-sandbox-api.munimtech.com';
|
|
24
|
+
/** `'test'` for `mb_test_…` keys, `'live'` for `mb_live_…`, `null` otherwise. */
|
|
25
|
+
function modeForKey(secretKey) {
|
|
26
|
+
if (secretKey.startsWith('mb_test_'))
|
|
27
|
+
return 'test';
|
|
28
|
+
if (secretKey.startsWith('mb_live_'))
|
|
29
|
+
return 'live';
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/** The API base for a key: the sandbox for `mb_test_…`, live for `mb_live_…`. */
|
|
33
|
+
function baseUrlForKey(secretKey) {
|
|
34
|
+
const mode = modeForKey(secretKey);
|
|
35
|
+
if (mode === 'test')
|
|
36
|
+
return exports.TEST_BASE_URL;
|
|
37
|
+
if (mode === 'live')
|
|
38
|
+
return exports.LIVE_BASE_URL;
|
|
39
|
+
throw new errors_js_1.MunimBillingError('Munim Billing secret keys start with mb_test_sk_ or mb_live_sk_. Find yours at https://munimtech.com/billing/dashboard.', { type: 'authentication' });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Walks every page of a list, starting from `params.cursor` (if any).
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* for await (const txn of paginate((p) => munim.transactions.list(p), { limit: 100 })) { … }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
async function* paginate(fetchPage, params = {}) {
|
|
49
|
+
let cursor = params.cursor;
|
|
50
|
+
for (;;) {
|
|
51
|
+
const page = await fetchPage({ ...params, cursor });
|
|
52
|
+
for (const item of page.data) {
|
|
53
|
+
yield item;
|
|
54
|
+
}
|
|
55
|
+
if (!page.has_more || !page.next_cursor)
|
|
56
|
+
return;
|
|
57
|
+
cursor = page.next_cursor;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function listMethod(fetchPage) {
|
|
61
|
+
const method = ((params) => fetchPage((params ?? {})));
|
|
62
|
+
method.all = (params) => paginate(fetchPage, (params ?? {}));
|
|
63
|
+
return method;
|
|
64
|
+
}
|
|
65
|
+
function isBrowserLike() {
|
|
66
|
+
const g = globalThis;
|
|
67
|
+
return ((typeof g.window !== 'undefined' && typeof g.document !== 'undefined') ||
|
|
68
|
+
g.navigator?.product === 'ReactNative');
|
|
69
|
+
}
|
|
70
|
+
function id(value) {
|
|
71
|
+
if (!value) {
|
|
72
|
+
throw new errors_js_1.MunimBillingError('An id is required.', { type: 'invalid_request', param: 'id' });
|
|
73
|
+
}
|
|
74
|
+
return encodeURIComponent(value);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The Munim Billing server client.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const munim = new MunimBilling(process.env.MUNIM_BILLING_SECRET_KEY!)
|
|
81
|
+
* const checkout = await munim.checkouts.create({ price_id: 'pri_…' })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
class MunimBilling {
|
|
85
|
+
constructor(secretKey, options = {}) {
|
|
86
|
+
_MunimBilling_instances.add(this);
|
|
87
|
+
this.webhooks = webhooks_js_1.webhooks;
|
|
88
|
+
_MunimBilling_secretKey.set(this, void 0);
|
|
89
|
+
_MunimBilling_fetch.set(this, void 0);
|
|
90
|
+
_MunimBilling_timeoutMs.set(this, void 0);
|
|
91
|
+
this.products = {
|
|
92
|
+
create: (params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, '/v1/products', params),
|
|
93
|
+
list: listMethod((params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/products', params)),
|
|
94
|
+
retrieve: (productId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, `/v1/products/${id(productId)}`),
|
|
95
|
+
update: (productId, params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, `/v1/products/${id(productId)}`, params),
|
|
96
|
+
};
|
|
97
|
+
this.prices = {
|
|
98
|
+
create: (params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, '/v1/prices', params),
|
|
99
|
+
list: listMethod((params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/prices', params)),
|
|
100
|
+
retrieve: (priceId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, `/v1/prices/${id(priceId)}`),
|
|
101
|
+
/** A price's amount can't change; make a new price instead. */
|
|
102
|
+
update: (priceId, params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, `/v1/prices/${id(priceId)}`, params),
|
|
103
|
+
};
|
|
104
|
+
this.checkouts = {
|
|
105
|
+
/** Creates a checkout. Send the customer to its `url`. */
|
|
106
|
+
create: (params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, '/v1/checkouts', params),
|
|
107
|
+
retrieve: (checkoutId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, `/v1/checkouts/${id(checkoutId)}`),
|
|
108
|
+
};
|
|
109
|
+
this.customers = {
|
|
110
|
+
list: listMethod((params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/customers', params)),
|
|
111
|
+
retrieve: (customerId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, `/v1/customers/${id(customerId)}`),
|
|
112
|
+
};
|
|
113
|
+
this.transactions = {
|
|
114
|
+
list: listMethod((params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/transactions', params)),
|
|
115
|
+
retrieve: (transactionId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, `/v1/transactions/${id(transactionId)}`),
|
|
116
|
+
/** Refunds `amount` cents, or everything not yet refunded. */
|
|
117
|
+
refund: (transactionId, params = {}) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, `/v1/transactions/${id(transactionId)}/refund`, params),
|
|
118
|
+
};
|
|
119
|
+
this.subscriptions = {
|
|
120
|
+
list: listMethod((params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/subscriptions', params)),
|
|
121
|
+
retrieve: (subscriptionId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, `/v1/subscriptions/${id(subscriptionId)}`),
|
|
122
|
+
/** Cancels at the end of the paid period by default; `{ at_period_end: false }` cancels now. */
|
|
123
|
+
cancel: (subscriptionId, params = {}) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, `/v1/subscriptions/${id(subscriptionId)}/cancel`, params),
|
|
124
|
+
/** A Munim-hosted page where the customer can see and cancel the subscription. */
|
|
125
|
+
manageUrl: (subscriptionId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, `/v1/subscriptions/${id(subscriptionId)}/manage_url`),
|
|
126
|
+
};
|
|
127
|
+
this.balance = {
|
|
128
|
+
retrieve: () => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/balance'),
|
|
129
|
+
};
|
|
130
|
+
this.payouts = {
|
|
131
|
+
list: listMethod((params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/payouts', params)),
|
|
132
|
+
};
|
|
133
|
+
/** Everything one of your users is entitled to, across web, App Store and Google Play. */
|
|
134
|
+
this.subscribers = {
|
|
135
|
+
retrieve: (appUserId) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, `/v1/subscribers/${id(appUserId)}`),
|
|
136
|
+
};
|
|
137
|
+
/** Verify a store purchase with Apple / Google and attach it to your user. */
|
|
138
|
+
this.receipts = {
|
|
139
|
+
apple: (params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, '/v1/receipts/apple', params),
|
|
140
|
+
google: (params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_post).call(this, '/v1/receipts/google', params),
|
|
141
|
+
};
|
|
142
|
+
this.storeSubscriptions = {
|
|
143
|
+
list: listMethod((params) => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/store_subscriptions', params)),
|
|
144
|
+
};
|
|
145
|
+
this.entitlements = {
|
|
146
|
+
list: () => __classPrivateFieldGet(this, _MunimBilling_instances, "m", _MunimBilling_get).call(this, '/v1/entitlements'),
|
|
147
|
+
};
|
|
148
|
+
if (!secretKey || typeof secretKey !== 'string') {
|
|
149
|
+
throw new errors_js_1.MunimBillingError('A Munim Billing secret key is required.', { type: 'authentication' });
|
|
150
|
+
}
|
|
151
|
+
if (!options.dangerouslyAllowBrowser && isBrowserLike()) {
|
|
152
|
+
throw new errors_js_1.MunimBillingError('MunimBilling uses your secret key and must run on your server. In a browser or app, create the checkout on your server and open its url with munim-billing/web or munim-billing/react-native.', { type: 'invalid_request' });
|
|
153
|
+
}
|
|
154
|
+
__classPrivateFieldSet(this, _MunimBilling_secretKey, secretKey, "f");
|
|
155
|
+
this.mode = modeForKey(secretKey);
|
|
156
|
+
this.baseUrl = (options.baseUrl ?? baseUrlForKey(secretKey)).replace(/\/+$/, '');
|
|
157
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
158
|
+
if (!fetchImpl) {
|
|
159
|
+
throw new errors_js_1.MunimBillingError('No fetch is available. Pass one with options.fetch.', { type: 'internal' });
|
|
160
|
+
}
|
|
161
|
+
__classPrivateFieldSet(this, _MunimBilling_fetch, fetchImpl, "f");
|
|
162
|
+
__classPrivateFieldSet(this, _MunimBilling_timeoutMs, options.timeoutMs ?? 30000, "f");
|
|
163
|
+
}
|
|
164
|
+
/** Sends one request to the API. The resource methods below are built on it. */
|
|
165
|
+
async request(method, path, options = {}) {
|
|
166
|
+
let url = `${this.baseUrl}${path}`;
|
|
167
|
+
if (options.query) {
|
|
168
|
+
const search = new URLSearchParams();
|
|
169
|
+
for (const [key, value] of Object.entries(options.query)) {
|
|
170
|
+
if (value !== undefined && value !== null)
|
|
171
|
+
search.append(key, String(value));
|
|
172
|
+
}
|
|
173
|
+
const encoded = search.toString();
|
|
174
|
+
if (encoded)
|
|
175
|
+
url += `?${encoded}`;
|
|
176
|
+
}
|
|
177
|
+
const headers = {
|
|
178
|
+
'Authorization': `Bearer ${__classPrivateFieldGet(this, _MunimBilling_secretKey, "f")}`,
|
|
179
|
+
'Accept': 'application/json',
|
|
180
|
+
'Munim-Billing-Client': `munim-billing-js/${version_js_1.VERSION}`,
|
|
181
|
+
};
|
|
182
|
+
let body;
|
|
183
|
+
if (method === 'POST') {
|
|
184
|
+
headers['Content-Type'] = 'application/json';
|
|
185
|
+
body = JSON.stringify(options.body ?? {});
|
|
186
|
+
}
|
|
187
|
+
const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
|
|
188
|
+
const timer = controller ? setTimeout(() => controller.abort(), __classPrivateFieldGet(this, _MunimBilling_timeoutMs, "f")) : undefined;
|
|
189
|
+
let response;
|
|
190
|
+
try {
|
|
191
|
+
response = await __classPrivateFieldGet(this, _MunimBilling_fetch, "f").call(this, url, { method, headers, body, signal: controller?.signal });
|
|
192
|
+
}
|
|
193
|
+
catch (cause) {
|
|
194
|
+
const timedOut = controller?.signal.aborted;
|
|
195
|
+
throw new errors_js_1.MunimBillingError(timedOut
|
|
196
|
+
? `Munim Billing request timed out after ${__classPrivateFieldGet(this, _MunimBilling_timeoutMs, "f")} ms.`
|
|
197
|
+
: 'Could not reach Munim Billing.', { type: 'connection', cause });
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
if (timer)
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
}
|
|
203
|
+
const text = await response.text();
|
|
204
|
+
let parsed = undefined;
|
|
205
|
+
if (text) {
|
|
206
|
+
try {
|
|
207
|
+
parsed = JSON.parse(text);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
parsed = undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!response.ok) {
|
|
214
|
+
throw (0, errors_js_1.errorFromResponse)(response.status, parsed);
|
|
215
|
+
}
|
|
216
|
+
if (parsed === undefined) {
|
|
217
|
+
throw new errors_js_1.MunimBillingError('Munim Billing returned a response that is not JSON.', {
|
|
218
|
+
type: 'internal',
|
|
219
|
+
status: response.status,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return parsed;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.MunimBilling = MunimBilling;
|
|
226
|
+
_MunimBilling_secretKey = new WeakMap(), _MunimBilling_fetch = new WeakMap(), _MunimBilling_timeoutMs = new WeakMap(), _MunimBilling_instances = new WeakSet(), _MunimBilling_get = function _MunimBilling_get(path, query) {
|
|
227
|
+
return this.request('GET', path, { query });
|
|
228
|
+
}, _MunimBilling_post = function _MunimBilling_post(path, body) {
|
|
229
|
+
return this.request('POST', path, { body });
|
|
230
|
+
};
|
|
231
|
+
/** Webhook helpers, also available as `munim.webhooks`. */
|
|
232
|
+
MunimBilling.webhooks = webhooks_js_1.webhooks;
|
|
233
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuCA,gCAIC;AAGD,sCAQC;AAqCD,4BAaC;AAxGD,2CAAkE;AAgClE,6CAAsC;AACtC,+CAAwC;AAE3B,QAAA,aAAa,GAAG,mCAAmC,CAAA;AACnD,QAAA,aAAa,GAAG,2C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AAE,YAAY,CAAC,KAAK,CAAC,CAAA;QAChC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClC,IAAI,MAAM,GAAY,SAAS,CAAA;QAC/B,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,GAAG,SAAS,CAAA;YACpB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAA,6BAAiB,EAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAClD,CAAC;QACD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,IAAI,6BAAiB,CAAC,qDAAqD,EAAE;gBACjF,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,QAAQ,CAAC,MAAM;aACxB,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,MAAW,CAAA;IACpB,CAAC;;AA7FH,oCAkLC;+MAnFS,IAAY,EAAE,KAAa;IACjC,OAAO,IAAI,CAAC,OAAO,CAAI,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;AAChD,CAAC,mDAEQ,IAAY,EAAE,IAAc;IACnC,OAAO,IAAI,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;AAChD,CAAC;AApGD,2DAA2D;AAC3C,qBAAQ,GAAG,sBAAQ,AAAX,CAAW"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MunimBillingError = void 0;
|
|
4
|
+
exports.errorFromResponse = errorFromResponse;
|
|
5
|
+
/** Every error the SDK throws. */
|
|
6
|
+
class MunimBillingError extends Error {
|
|
7
|
+
constructor(message, options) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'MunimBillingError';
|
|
10
|
+
this.type = options.type;
|
|
11
|
+
this.status = options.status ?? null;
|
|
12
|
+
this.param = options.param ?? null;
|
|
13
|
+
if (options.cause !== undefined) {
|
|
14
|
+
;
|
|
15
|
+
this.cause = options.cause;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.MunimBillingError = MunimBillingError;
|
|
20
|
+
const KNOWN_TYPES = new Set([
|
|
21
|
+
'invalid_request',
|
|
22
|
+
'authentication',
|
|
23
|
+
'not_found',
|
|
24
|
+
'conflict',
|
|
25
|
+
'processor',
|
|
26
|
+
'internal',
|
|
27
|
+
]);
|
|
28
|
+
function typeForStatus(status) {
|
|
29
|
+
if (status === 401 || status === 403)
|
|
30
|
+
return 'authentication';
|
|
31
|
+
if (status === 404)
|
|
32
|
+
return 'not_found';
|
|
33
|
+
if (status === 409)
|
|
34
|
+
return 'conflict';
|
|
35
|
+
if (status === 402 || status === 502)
|
|
36
|
+
return 'processor';
|
|
37
|
+
if (status >= 500)
|
|
38
|
+
return 'internal';
|
|
39
|
+
return 'invalid_request';
|
|
40
|
+
}
|
|
41
|
+
/** Builds the error for a non-2xx response from its parsed body (if any). */
|
|
42
|
+
function errorFromResponse(status, body) {
|
|
43
|
+
const error = body && typeof body === 'object' && 'error' in body
|
|
44
|
+
? body.error
|
|
45
|
+
: undefined;
|
|
46
|
+
const type = error?.type && KNOWN_TYPES.has(error.type)
|
|
47
|
+
? error.type
|
|
48
|
+
: typeForStatus(status);
|
|
49
|
+
return new MunimBillingError(error?.message || `Munim Billing request failed with status ${status}`, {
|
|
50
|
+
type,
|
|
51
|
+
status,
|
|
52
|
+
param: error?.param ?? null,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":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jD,CAAC,CAAE,IAAwE,CAAC,KAAK;QACjF,CAAC,CAAC,SAAS,CAAA;IACf,MAAM,IAAI,GACR,KAAK,EAAE,IAAI,IAAI,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,IAA6B,CAAC;QACjE,CAAC,CAAE,KAAK,CAAC,IAA8B;QACvC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,OAAO,IAAI,iBAAiB,CAAC,KAAK,EAAE,OAAO,IAAI,4CAA4C,MAAM,EAAE,EAAE;QACnG,IAAI;QACJ,MAAM;QACN,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,IAAI;KAC5B,CAAC,CAAA;AACJ,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION = exports.EVENT_TYPES = exports.DEFAULT_TOLERANCE_SECONDS = exports.EVENT_ID_HEADER = exports.SIGNATURE_HEADER = exports.webhooks = exports.timingSafeEqual = exports.parseSignatureHeader = exports.computeSignature = exports.signWebhookPayload = exports.verifyWebhook = exports.errorFromResponse = exports.MunimBillingError = exports.TEST_BASE_URL = exports.LIVE_BASE_URL = exports.paginate = exports.modeForKey = exports.baseUrlForKey = exports.MunimBilling = void 0;
|
|
4
|
+
var client_js_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "MunimBilling", { enumerable: true, get: function () { return client_js_1.MunimBilling; } });
|
|
6
|
+
Object.defineProperty(exports, "baseUrlForKey", { enumerable: true, get: function () { return client_js_1.baseUrlForKey; } });
|
|
7
|
+
Object.defineProperty(exports, "modeForKey", { enumerable: true, get: function () { return client_js_1.modeForKey; } });
|
|
8
|
+
Object.defineProperty(exports, "paginate", { enumerable: true, get: function () { return client_js_1.paginate; } });
|
|
9
|
+
Object.defineProperty(exports, "LIVE_BASE_URL", { enumerable: true, get: function () { return client_js_1.LIVE_BASE_URL; } });
|
|
10
|
+
Object.defineProperty(exports, "TEST_BASE_URL", { enumerable: true, get: function () { return client_js_1.TEST_BASE_URL; } });
|
|
11
|
+
var errors_js_1 = require("./errors.js");
|
|
12
|
+
Object.defineProperty(exports, "MunimBillingError", { enumerable: true, get: function () { return errors_js_1.MunimBillingError; } });
|
|
13
|
+
Object.defineProperty(exports, "errorFromResponse", { enumerable: true, get: function () { return errors_js_1.errorFromResponse; } });
|
|
14
|
+
var webhooks_js_1 = require("./webhooks.js");
|
|
15
|
+
Object.defineProperty(exports, "verifyWebhook", { enumerable: true, get: function () { return webhooks_js_1.verifyWebhook; } });
|
|
16
|
+
Object.defineProperty(exports, "signWebhookPayload", { enumerable: true, get: function () { return webhooks_js_1.signWebhookPayload; } });
|
|
17
|
+
Object.defineProperty(exports, "computeSignature", { enumerable: true, get: function () { return webhooks_js_1.computeSignature; } });
|
|
18
|
+
Object.defineProperty(exports, "parseSignatureHeader", { enumerable: true, get: function () { return webhooks_js_1.parseSignatureHeader; } });
|
|
19
|
+
Object.defineProperty(exports, "timingSafeEqual", { enumerable: true, get: function () { return webhooks_js_1.timingSafeEqual; } });
|
|
20
|
+
Object.defineProperty(exports, "webhooks", { enumerable: true, get: function () { return webhooks_js_1.webhooks; } });
|
|
21
|
+
Object.defineProperty(exports, "SIGNATURE_HEADER", { enumerable: true, get: function () { return webhooks_js_1.SIGNATURE_HEADER; } });
|
|
22
|
+
Object.defineProperty(exports, "EVENT_ID_HEADER", { enumerable: true, get: function () { return webhooks_js_1.EVENT_ID_HEADER; } });
|
|
23
|
+
Object.defineProperty(exports, "DEFAULT_TOLERANCE_SECONDS", { enumerable: true, get: function () { return webhooks_js_1.DEFAULT_TOLERANCE_SECONDS; } });
|
|
24
|
+
var types_js_1 = require("./types.js");
|
|
25
|
+
Object.defineProperty(exports, "EVENT_TYPES", { enumerable: true, get: function () { return types_js_1.EVENT_TYPES; } });
|
|
26
|
+
var version_js_1 = require("./version.js");
|
|
27
|
+
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } });
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAOoB;AANlB,yGAAA,YAAY,OAAA;AACZ,0GAAA,aAAa,OAAA;AACb,uGAAA,UAAU,OAAA;AACV,qGAAA,QAAQ,OAAA;AACR,0GAAA,aAAa,OAAA;AACb,0GAAA,aAAa,OAAA;AAGf,yCAAkE;AAAzD,8GAAA,iBAAiB,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAE7C,6CAUsB;AATpB,4GAAA,aAAa,OAAA;AACb,iHAAA,kBAAkB,OAAA;AAClB,+GAAA,gBAAgB,OAAA;AAChB,mHAAA,oBAAoB,OAAA;AACpB,8GAAA,eAAe,OAAA;AACf,uGAAA,QAAQ,OAAA;AACR,+GAAA,gBAAgB,OAAA;AAChB,8GAAA,eAAe,OAAA;AACf,wHAAA,yBAAyB,OAAA;AAG3B,uCAAwC;AAA/B,uGAAA,WAAW,OAAA;AAEpB,2CAAsC;AAA7B,qGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* munim-billing/react-native: open a Munim checkout from a React Native or
|
|
4
|
+
* Expo app.
|
|
5
|
+
*
|
|
6
|
+
* The checkout opens in an in-app sheet (ASWebAuthenticationSession on iOS,
|
|
7
|
+
* a Custom Tab on Android) through `expo-web-browser`, the same kind of
|
|
8
|
+
* sheet munim-venmo uses. The sheet closes when the checkout redirects to
|
|
9
|
+
* your app's scheme, so create the checkout **on your server** with
|
|
10
|
+
* `success_url` and `cancel_url` set to that scheme:
|
|
11
|
+
*
|
|
12
|
+
* success_url: 'myapp://billing/done'
|
|
13
|
+
* cancel_url: 'myapp://billing/canceled'
|
|
14
|
+
*
|
|
15
|
+
* Never ship your secret key in an app.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.parseCheckoutReturnUrl = parseCheckoutReturnUrl;
|
|
19
|
+
exports.openCheckout = openCheckout;
|
|
20
|
+
function loadWebBrowser() {
|
|
21
|
+
try {
|
|
22
|
+
// Optional peer dependency, looked up only when it's needed.
|
|
23
|
+
const mod = (typeof require === 'function' ? require('expo-web-browser') : undefined);
|
|
24
|
+
return mod && typeof mod.openAuthSessionAsync === 'function' ? mod : null;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function loadLinking() {
|
|
31
|
+
try {
|
|
32
|
+
const mod = (typeof require === 'function' ? require('react-native') : undefined);
|
|
33
|
+
return mod?.Linking ?? null;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Reads a URL's query (and fragment) without `URL.searchParams`, which React Native doesn't implement. */
|
|
40
|
+
function queryParams(url) {
|
|
41
|
+
const params = new Map();
|
|
42
|
+
const start = url.indexOf('?');
|
|
43
|
+
const hash = url.indexOf('#');
|
|
44
|
+
const parts = [];
|
|
45
|
+
if (start >= 0)
|
|
46
|
+
parts.push(url.slice(start + 1, hash > start ? hash : undefined));
|
|
47
|
+
if (hash >= 0)
|
|
48
|
+
parts.push(url.slice(hash + 1));
|
|
49
|
+
for (const part of parts) {
|
|
50
|
+
for (const pair of part.split('&')) {
|
|
51
|
+
if (!pair)
|
|
52
|
+
continue;
|
|
53
|
+
const eq = pair.indexOf('=');
|
|
54
|
+
const rawKey = eq >= 0 ? pair.slice(0, eq) : pair;
|
|
55
|
+
const rawValue = eq >= 0 ? pair.slice(eq + 1) : '';
|
|
56
|
+
try {
|
|
57
|
+
const key = decodeURIComponent(rawKey.replace(/\+/g, ' ')).toLowerCase();
|
|
58
|
+
if (!params.has(key))
|
|
59
|
+
params.set(key, decodeURIComponent(rawValue.replace(/\+/g, ' ')));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// A malformed escape: skip that pair.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return params;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Reads the URL the checkout returned to. `checkout_id` means it was paid;
|
|
70
|
+
* `canceled=true` (or no `checkout_id`) means it wasn't.
|
|
71
|
+
*/
|
|
72
|
+
function parseCheckoutReturnUrl(url) {
|
|
73
|
+
const params = queryParams(url);
|
|
74
|
+
const checkoutId = params.get('checkout_id') || undefined;
|
|
75
|
+
const canceled = params.get('canceled') ?? params.get('cancelled');
|
|
76
|
+
if (canceled === 'true' || canceled === '1' || !checkoutId) {
|
|
77
|
+
return checkoutId ? { status: 'canceled', checkoutId } : { status: 'canceled' };
|
|
78
|
+
}
|
|
79
|
+
return { status: 'completed', checkoutId };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Opens a checkout `url` (from `munim.checkouts.create` on your server) in an
|
|
83
|
+
* in-app sheet and resolves when the customer comes back.
|
|
84
|
+
*
|
|
85
|
+
* - `completed`: the checkout redirected to your `success_url`. Confirm on
|
|
86
|
+
* your server (the `checkout.completed` webhook, or
|
|
87
|
+
* `munim.checkouts.retrieve(checkoutId)`) before granting anything.
|
|
88
|
+
* - `canceled`: the customer closed the sheet or hit cancel.
|
|
89
|
+
* - `opened`: `expo-web-browser` isn't installed, so the checkout opened in
|
|
90
|
+
* the browser; the result arrives later as a deep link to your app.
|
|
91
|
+
*/
|
|
92
|
+
async function openCheckout(url, options) {
|
|
93
|
+
if (!url)
|
|
94
|
+
throw new Error('munim-billing: openCheckout needs the checkout url.');
|
|
95
|
+
if (!options?.returnUrl || !/^[a-z][a-z0-9+.-]*:/i.test(options.returnUrl)) {
|
|
96
|
+
throw new Error("munim-billing: openCheckout needs a returnUrl like 'myapp://billing'.");
|
|
97
|
+
}
|
|
98
|
+
const browser = options.webBrowser ?? loadWebBrowser();
|
|
99
|
+
if (browser) {
|
|
100
|
+
const result = await browser.openAuthSessionAsync(url, options.returnUrl, {
|
|
101
|
+
preferEphemeralSession: options.preferEphemeralSession ?? false,
|
|
102
|
+
});
|
|
103
|
+
if (result.type === 'success' && result.url) {
|
|
104
|
+
const parsed = parseCheckoutReturnUrl(result.url);
|
|
105
|
+
return parsed.status === 'completed'
|
|
106
|
+
? { status: 'completed', checkoutId: parsed.checkoutId, url: result.url }
|
|
107
|
+
: { status: 'canceled', checkoutId: parsed.checkoutId, url: result.url };
|
|
108
|
+
}
|
|
109
|
+
return { status: 'canceled' };
|
|
110
|
+
}
|
|
111
|
+
const linking = loadLinking();
|
|
112
|
+
if (!linking) {
|
|
113
|
+
throw new Error('munim-billing: install expo-web-browser (or run inside React Native) to open a checkout.');
|
|
114
|
+
}
|
|
115
|
+
await linking.openURL(url);
|
|
116
|
+
return { status: 'opened' };
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../../src/react-native.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AA4FH,wDAQC;AAaD,oCA0BC;AAnGD,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,6DAA6D;QAC7D,MAAM,GAAG,GAAG,CAAC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,CAEvE,CAAA;QACb,OAAO,GAAG,IAAI,OAAO,GAAG,CAAC,oBAAoB,KAAK,UAAU,CAAC,CAAC,CAAE,GAAsB,CAAC,CAAC,CAAC,IAAI,CAAA;IAC/F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED,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AAE,MAAM,EAAE,QAAQ,EAAE,CAAA;AAC7B,CAAC"}
|
package/lib/cjs/types.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Object types returned by the Munim Billing API (docs/API.md).
|
|
4
|
+
*
|
|
5
|
+
* Amounts are integers in cents, currencies are lowercase ISO 4217 codes
|
|
6
|
+
* (only `usd` for now), and timestamps are Unix milliseconds.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.EVENT_TYPES = void 0;
|
|
10
|
+
exports.EVENT_TYPES = [
|
|
11
|
+
'checkout.completed',
|
|
12
|
+
'transaction.completed',
|
|
13
|
+
'transaction.refunded',
|
|
14
|
+
'transaction.disputed',
|
|
15
|
+
'subscription.created',
|
|
16
|
+
'subscription.updated',
|
|
17
|
+
'subscription.canceled',
|
|
18
|
+
'payout.paid',
|
|
19
|
+
'payout.failed',
|
|
20
|
+
];
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAoMU,QAAA,WAAW,GAAyB;IAC/C,oBAAoB;IACpB,uBAAuB;IACvB,sBAAsB;IACtB,sBAAsB;IACtB,sBAAsB;IACtB,sBAAsB;IACtB,uBAAuB;IACvB,aAAa;IACb,eAAe;CAChB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,kEAAkE;AACrD,QAAA,OAAO,GAAG,OAAO,CAAA"}
|