@moneymq/better-auth 0.2.1
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 +21 -0
- package/dist/client.d.mts +171 -0
- package/dist/client.d.ts +171 -0
- package/dist/client.js +118 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +93 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +421 -0
- package/dist/index.d.ts +421 -0
- package/dist/index.js +4557 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4532 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 MoneyMQ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as better_auth_client from 'better-auth/client';
|
|
2
|
+
import moneymq, { MoneyMQClientPluginOptions, RecordUsageParams, GetUsageParams, UsageSummary, CreateCheckoutParams } from './index.mjs';
|
|
3
|
+
import '@moneymq/sdk';
|
|
4
|
+
import 'better-auth';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* MoneyMQ client plugin for Better Auth
|
|
9
|
+
*
|
|
10
|
+
* Provides client-side methods for usage tracking, checkout creation,
|
|
11
|
+
* and customer management.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { createAuthClient } from 'better-auth/client';
|
|
16
|
+
* import { moneymqClient } from '@moneymq/better-auth/client';
|
|
17
|
+
*
|
|
18
|
+
* export const authClient = createAuthClient({
|
|
19
|
+
* plugins: [
|
|
20
|
+
* moneymqClient({
|
|
21
|
+
* usage: true,
|
|
22
|
+
* }),
|
|
23
|
+
* ],
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Record usage
|
|
27
|
+
* await authClient.moneymq.recordUsage({
|
|
28
|
+
* metric: 'api_calls',
|
|
29
|
+
* quantity: 1,
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Get usage summary
|
|
33
|
+
* const { usage } = await authClient.moneymq.getUsage();
|
|
34
|
+
*
|
|
35
|
+
* // Create checkout for usage
|
|
36
|
+
* const { url } = await authClient.moneymq.createUsageCheckout({
|
|
37
|
+
* successUrl: '/success',
|
|
38
|
+
* cancelUrl: '/cancel',
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare const moneymqClient: (options?: MoneyMQClientPluginOptions) => {
|
|
43
|
+
id: "moneymq";
|
|
44
|
+
$InferServerPlugin: ReturnType<typeof moneymq>;
|
|
45
|
+
getActions: ($fetch: better_auth_client.BetterFetch) => {
|
|
46
|
+
/**
|
|
47
|
+
* Record usage for a metric
|
|
48
|
+
*/
|
|
49
|
+
recordUsage: (params: RecordUsageParams, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
50
|
+
data: null;
|
|
51
|
+
error: {
|
|
52
|
+
message?: string | undefined;
|
|
53
|
+
status: number;
|
|
54
|
+
statusText: string;
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
data: {
|
|
58
|
+
success: boolean;
|
|
59
|
+
record: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
error: null;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Get usage summary for the current user
|
|
65
|
+
*/
|
|
66
|
+
getUsage: (params?: GetUsageParams, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
67
|
+
data: null;
|
|
68
|
+
error: {
|
|
69
|
+
message?: string | undefined;
|
|
70
|
+
status: number;
|
|
71
|
+
statusText: string;
|
|
72
|
+
};
|
|
73
|
+
} | {
|
|
74
|
+
data: {
|
|
75
|
+
usage: UsageSummary[];
|
|
76
|
+
};
|
|
77
|
+
error: null;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Create a checkout session for unbilled usage
|
|
81
|
+
*/
|
|
82
|
+
createUsageCheckout: (params: {
|
|
83
|
+
metrics?: string[];
|
|
84
|
+
successUrl: string;
|
|
85
|
+
cancelUrl: string;
|
|
86
|
+
}, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
87
|
+
data: null;
|
|
88
|
+
error: {
|
|
89
|
+
message?: string | undefined;
|
|
90
|
+
status: number;
|
|
91
|
+
statusText: string;
|
|
92
|
+
};
|
|
93
|
+
} | {
|
|
94
|
+
data: {
|
|
95
|
+
url: string;
|
|
96
|
+
sessionId: string;
|
|
97
|
+
lineItems: Array<{
|
|
98
|
+
price: string;
|
|
99
|
+
quantity: number;
|
|
100
|
+
}>;
|
|
101
|
+
totalRecords: number;
|
|
102
|
+
};
|
|
103
|
+
error: null;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Create a general checkout session
|
|
107
|
+
*/
|
|
108
|
+
createCheckout: (params: CreateCheckoutParams, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
109
|
+
data: null;
|
|
110
|
+
error: {
|
|
111
|
+
message?: string | undefined;
|
|
112
|
+
status: number;
|
|
113
|
+
statusText: string;
|
|
114
|
+
};
|
|
115
|
+
} | {
|
|
116
|
+
data: {
|
|
117
|
+
url: string;
|
|
118
|
+
sessionId: string;
|
|
119
|
+
};
|
|
120
|
+
error: null;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Get the current user's MoneyMQ customer
|
|
124
|
+
*/
|
|
125
|
+
getCustomer: (fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
126
|
+
data: null;
|
|
127
|
+
error: {
|
|
128
|
+
message?: string | undefined;
|
|
129
|
+
status: number;
|
|
130
|
+
statusText: string;
|
|
131
|
+
};
|
|
132
|
+
} | {
|
|
133
|
+
data: {
|
|
134
|
+
customer: Record<string, unknown> | null;
|
|
135
|
+
};
|
|
136
|
+
error: null;
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* Get available usage metrics
|
|
140
|
+
*/
|
|
141
|
+
getMetrics: (fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
142
|
+
data: null;
|
|
143
|
+
error: {
|
|
144
|
+
message?: string | undefined;
|
|
145
|
+
status: number;
|
|
146
|
+
statusText: string;
|
|
147
|
+
};
|
|
148
|
+
} | {
|
|
149
|
+
data: {
|
|
150
|
+
metrics: Array<{
|
|
151
|
+
name: string;
|
|
152
|
+
displayName?: string;
|
|
153
|
+
unit?: string;
|
|
154
|
+
aggregation: "sum" | "max" | "last";
|
|
155
|
+
}>;
|
|
156
|
+
};
|
|
157
|
+
error: null;
|
|
158
|
+
}>;
|
|
159
|
+
};
|
|
160
|
+
pathMethods: {
|
|
161
|
+
'/moneymq/usage/record': "POST";
|
|
162
|
+
'/moneymq/usage': "GET";
|
|
163
|
+
'/moneymq/usage/checkout': "POST";
|
|
164
|
+
'/moneymq/checkout': "POST";
|
|
165
|
+
'/moneymq/customer': "GET";
|
|
166
|
+
'/moneymq/metrics': "GET";
|
|
167
|
+
'/moneymq/webhook': "POST";
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export { CreateCheckoutParams, GetUsageParams, MoneyMQClientPluginOptions, RecordUsageParams, UsageSummary, moneymqClient as default, moneymqClient };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as better_auth_client from 'better-auth/client';
|
|
2
|
+
import moneymq, { MoneyMQClientPluginOptions, RecordUsageParams, GetUsageParams, UsageSummary, CreateCheckoutParams } from './index.js';
|
|
3
|
+
import '@moneymq/sdk';
|
|
4
|
+
import 'better-auth';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* MoneyMQ client plugin for Better Auth
|
|
9
|
+
*
|
|
10
|
+
* Provides client-side methods for usage tracking, checkout creation,
|
|
11
|
+
* and customer management.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { createAuthClient } from 'better-auth/client';
|
|
16
|
+
* import { moneymqClient } from '@moneymq/better-auth/client';
|
|
17
|
+
*
|
|
18
|
+
* export const authClient = createAuthClient({
|
|
19
|
+
* plugins: [
|
|
20
|
+
* moneymqClient({
|
|
21
|
+
* usage: true,
|
|
22
|
+
* }),
|
|
23
|
+
* ],
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Record usage
|
|
27
|
+
* await authClient.moneymq.recordUsage({
|
|
28
|
+
* metric: 'api_calls',
|
|
29
|
+
* quantity: 1,
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Get usage summary
|
|
33
|
+
* const { usage } = await authClient.moneymq.getUsage();
|
|
34
|
+
*
|
|
35
|
+
* // Create checkout for usage
|
|
36
|
+
* const { url } = await authClient.moneymq.createUsageCheckout({
|
|
37
|
+
* successUrl: '/success',
|
|
38
|
+
* cancelUrl: '/cancel',
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare const moneymqClient: (options?: MoneyMQClientPluginOptions) => {
|
|
43
|
+
id: "moneymq";
|
|
44
|
+
$InferServerPlugin: ReturnType<typeof moneymq>;
|
|
45
|
+
getActions: ($fetch: better_auth_client.BetterFetch) => {
|
|
46
|
+
/**
|
|
47
|
+
* Record usage for a metric
|
|
48
|
+
*/
|
|
49
|
+
recordUsage: (params: RecordUsageParams, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
50
|
+
data: null;
|
|
51
|
+
error: {
|
|
52
|
+
message?: string | undefined;
|
|
53
|
+
status: number;
|
|
54
|
+
statusText: string;
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
data: {
|
|
58
|
+
success: boolean;
|
|
59
|
+
record: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
error: null;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Get usage summary for the current user
|
|
65
|
+
*/
|
|
66
|
+
getUsage: (params?: GetUsageParams, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
67
|
+
data: null;
|
|
68
|
+
error: {
|
|
69
|
+
message?: string | undefined;
|
|
70
|
+
status: number;
|
|
71
|
+
statusText: string;
|
|
72
|
+
};
|
|
73
|
+
} | {
|
|
74
|
+
data: {
|
|
75
|
+
usage: UsageSummary[];
|
|
76
|
+
};
|
|
77
|
+
error: null;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Create a checkout session for unbilled usage
|
|
81
|
+
*/
|
|
82
|
+
createUsageCheckout: (params: {
|
|
83
|
+
metrics?: string[];
|
|
84
|
+
successUrl: string;
|
|
85
|
+
cancelUrl: string;
|
|
86
|
+
}, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
87
|
+
data: null;
|
|
88
|
+
error: {
|
|
89
|
+
message?: string | undefined;
|
|
90
|
+
status: number;
|
|
91
|
+
statusText: string;
|
|
92
|
+
};
|
|
93
|
+
} | {
|
|
94
|
+
data: {
|
|
95
|
+
url: string;
|
|
96
|
+
sessionId: string;
|
|
97
|
+
lineItems: Array<{
|
|
98
|
+
price: string;
|
|
99
|
+
quantity: number;
|
|
100
|
+
}>;
|
|
101
|
+
totalRecords: number;
|
|
102
|
+
};
|
|
103
|
+
error: null;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Create a general checkout session
|
|
107
|
+
*/
|
|
108
|
+
createCheckout: (params: CreateCheckoutParams, fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
109
|
+
data: null;
|
|
110
|
+
error: {
|
|
111
|
+
message?: string | undefined;
|
|
112
|
+
status: number;
|
|
113
|
+
statusText: string;
|
|
114
|
+
};
|
|
115
|
+
} | {
|
|
116
|
+
data: {
|
|
117
|
+
url: string;
|
|
118
|
+
sessionId: string;
|
|
119
|
+
};
|
|
120
|
+
error: null;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Get the current user's MoneyMQ customer
|
|
124
|
+
*/
|
|
125
|
+
getCustomer: (fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
126
|
+
data: null;
|
|
127
|
+
error: {
|
|
128
|
+
message?: string | undefined;
|
|
129
|
+
status: number;
|
|
130
|
+
statusText: string;
|
|
131
|
+
};
|
|
132
|
+
} | {
|
|
133
|
+
data: {
|
|
134
|
+
customer: Record<string, unknown> | null;
|
|
135
|
+
};
|
|
136
|
+
error: null;
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* Get available usage metrics
|
|
140
|
+
*/
|
|
141
|
+
getMetrics: (fetchOptions?: Parameters<typeof $fetch>[1]) => Promise<{
|
|
142
|
+
data: null;
|
|
143
|
+
error: {
|
|
144
|
+
message?: string | undefined;
|
|
145
|
+
status: number;
|
|
146
|
+
statusText: string;
|
|
147
|
+
};
|
|
148
|
+
} | {
|
|
149
|
+
data: {
|
|
150
|
+
metrics: Array<{
|
|
151
|
+
name: string;
|
|
152
|
+
displayName?: string;
|
|
153
|
+
unit?: string;
|
|
154
|
+
aggregation: "sum" | "max" | "last";
|
|
155
|
+
}>;
|
|
156
|
+
};
|
|
157
|
+
error: null;
|
|
158
|
+
}>;
|
|
159
|
+
};
|
|
160
|
+
pathMethods: {
|
|
161
|
+
'/moneymq/usage/record': "POST";
|
|
162
|
+
'/moneymq/usage': "GET";
|
|
163
|
+
'/moneymq/usage/checkout': "POST";
|
|
164
|
+
'/moneymq/checkout': "POST";
|
|
165
|
+
'/moneymq/customer': "GET";
|
|
166
|
+
'/moneymq/metrics': "GET";
|
|
167
|
+
'/moneymq/webhook': "POST";
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export { CreateCheckoutParams, GetUsageParams, MoneyMQClientPluginOptions, RecordUsageParams, UsageSummary, moneymqClient as default, moneymqClient };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
default: () => client_default,
|
|
24
|
+
moneymqClient: () => moneymqClient
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(client_exports);
|
|
27
|
+
var moneymqClient = (options) => {
|
|
28
|
+
return {
|
|
29
|
+
id: "moneymq",
|
|
30
|
+
$InferServerPlugin: {},
|
|
31
|
+
getActions: ($fetch) => ({
|
|
32
|
+
/**
|
|
33
|
+
* Record usage for a metric
|
|
34
|
+
*/
|
|
35
|
+
recordUsage: async (params, fetchOptions) => {
|
|
36
|
+
return $fetch(
|
|
37
|
+
"/moneymq/usage/record",
|
|
38
|
+
{
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: params,
|
|
41
|
+
...fetchOptions
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Get usage summary for the current user
|
|
47
|
+
*/
|
|
48
|
+
getUsage: async (params, fetchOptions) => {
|
|
49
|
+
const query = new URLSearchParams();
|
|
50
|
+
if (params?.metric) query.set("metric", params.metric);
|
|
51
|
+
if (params?.startDate) query.set("startDate", params.startDate.toISOString());
|
|
52
|
+
if (params?.endDate) query.set("endDate", params.endDate.toISOString());
|
|
53
|
+
if (params?.includeBilled) query.set("includeBilled", "true");
|
|
54
|
+
const queryString = query.toString();
|
|
55
|
+
return $fetch(
|
|
56
|
+
`/moneymq/usage${queryString ? `?${queryString}` : ""}`,
|
|
57
|
+
{
|
|
58
|
+
method: "GET",
|
|
59
|
+
...fetchOptions
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Create a checkout session for unbilled usage
|
|
65
|
+
*/
|
|
66
|
+
createUsageCheckout: async (params, fetchOptions) => {
|
|
67
|
+
return $fetch("/moneymq/usage/checkout", {
|
|
68
|
+
method: "POST",
|
|
69
|
+
body: params,
|
|
70
|
+
...fetchOptions
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Create a general checkout session
|
|
75
|
+
*/
|
|
76
|
+
createCheckout: async (params, fetchOptions) => {
|
|
77
|
+
return $fetch("/moneymq/checkout", {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: params,
|
|
80
|
+
...fetchOptions
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Get the current user's MoneyMQ customer
|
|
85
|
+
*/
|
|
86
|
+
getCustomer: async (fetchOptions) => {
|
|
87
|
+
return $fetch("/moneymq/customer", {
|
|
88
|
+
method: "GET",
|
|
89
|
+
...fetchOptions
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Get available usage metrics
|
|
94
|
+
*/
|
|
95
|
+
getMetrics: async (fetchOptions) => {
|
|
96
|
+
return $fetch("/moneymq/metrics", {
|
|
97
|
+
method: "GET",
|
|
98
|
+
...fetchOptions
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
pathMethods: {
|
|
103
|
+
"/moneymq/usage/record": "POST",
|
|
104
|
+
"/moneymq/usage": "GET",
|
|
105
|
+
"/moneymq/usage/checkout": "POST",
|
|
106
|
+
"/moneymq/checkout": "POST",
|
|
107
|
+
"/moneymq/customer": "GET",
|
|
108
|
+
"/moneymq/metrics": "GET",
|
|
109
|
+
"/moneymq/webhook": "POST"
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
var client_default = moneymqClient;
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
moneymqClient
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from 'better-auth/client';\nimport type { moneymq } from './index';\nimport type {\n MoneyMQClientPluginOptions,\n RecordUsageParams,\n GetUsageParams,\n UsageSummary,\n CreateCheckoutParams,\n} from './types';\n\nexport type { MoneyMQClientPluginOptions, RecordUsageParams, GetUsageParams, UsageSummary, CreateCheckoutParams };\n\n/**\n * MoneyMQ client plugin for Better Auth\n *\n * Provides client-side methods for usage tracking, checkout creation,\n * and customer management.\n *\n * @example\n * ```typescript\n * import { createAuthClient } from 'better-auth/client';\n * import { moneymqClient } from '@moneymq/better-auth/client';\n *\n * export const authClient = createAuthClient({\n * plugins: [\n * moneymqClient({\n * usage: true,\n * }),\n * ],\n * });\n *\n * // Record usage\n * await authClient.moneymq.recordUsage({\n * metric: 'api_calls',\n * quantity: 1,\n * });\n *\n * // Get usage summary\n * const { usage } = await authClient.moneymq.getUsage();\n *\n * // Create checkout for usage\n * const { url } = await authClient.moneymq.createUsageCheckout({\n * successUrl: '/success',\n * cancelUrl: '/cancel',\n * });\n * ```\n */\nexport const moneymqClient = (options?: MoneyMQClientPluginOptions) => {\n return {\n id: 'moneymq',\n $InferServerPlugin: {} as ReturnType<typeof moneymq>,\n\n getActions: ($fetch) => ({\n /**\n * Record usage for a metric\n */\n recordUsage: async (\n params: RecordUsageParams,\n fetchOptions?: Parameters<typeof $fetch>[1],\n ) => {\n return $fetch<{ success: boolean; record: Record<string, unknown> }>(\n '/moneymq/usage/record',\n {\n method: 'POST',\n body: params,\n ...fetchOptions,\n },\n );\n },\n\n /**\n * Get usage summary for the current user\n */\n getUsage: async (params?: GetUsageParams, fetchOptions?: Parameters<typeof $fetch>[1]) => {\n const query = new URLSearchParams();\n if (params?.metric) query.set('metric', params.metric);\n if (params?.startDate) query.set('startDate', params.startDate.toISOString());\n if (params?.endDate) query.set('endDate', params.endDate.toISOString());\n if (params?.includeBilled) query.set('includeBilled', 'true');\n\n const queryString = query.toString();\n return $fetch<{ usage: UsageSummary[] }>(\n `/moneymq/usage${queryString ? `?${queryString}` : ''}`,\n {\n method: 'GET',\n ...fetchOptions,\n },\n );\n },\n\n /**\n * Create a checkout session for unbilled usage\n */\n createUsageCheckout: async (\n params: {\n metrics?: string[];\n successUrl: string;\n cancelUrl: string;\n },\n fetchOptions?: Parameters<typeof $fetch>[1],\n ) => {\n return $fetch<{\n url: string;\n sessionId: string;\n lineItems: Array<{ price: string; quantity: number }>;\n totalRecords: number;\n }>('/moneymq/usage/checkout', {\n method: 'POST',\n body: params,\n ...fetchOptions,\n });\n },\n\n /**\n * Create a general checkout session\n */\n createCheckout: async (\n params: CreateCheckoutParams,\n fetchOptions?: Parameters<typeof $fetch>[1],\n ) => {\n return $fetch<{ url: string; sessionId: string }>('/moneymq/checkout', {\n method: 'POST',\n body: params,\n ...fetchOptions,\n });\n },\n\n /**\n * Get the current user's MoneyMQ customer\n */\n getCustomer: async (fetchOptions?: Parameters<typeof $fetch>[1]) => {\n return $fetch<{ customer: Record<string, unknown> | null }>('/moneymq/customer', {\n method: 'GET',\n ...fetchOptions,\n });\n },\n\n /**\n * Get available usage metrics\n */\n getMetrics: async (fetchOptions?: Parameters<typeof $fetch>[1]) => {\n return $fetch<{\n metrics: Array<{\n name: string;\n displayName?: string;\n unit?: string;\n aggregation: 'sum' | 'max' | 'last';\n }>;\n }>('/moneymq/metrics', {\n method: 'GET',\n ...fetchOptions,\n });\n },\n }),\n\n pathMethods: {\n '/moneymq/usage/record': 'POST',\n '/moneymq/usage': 'GET',\n '/moneymq/usage/checkout': 'POST',\n '/moneymq/checkout': 'POST',\n '/moneymq/customer': 'GET',\n '/moneymq/metrics': 'GET',\n '/moneymq/webhook': 'POST',\n },\n } satisfies BetterAuthClientPlugin;\n};\n\nexport default moneymqClient;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CO,IAAM,gBAAgB,CAAC,YAAyC;AACrE,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,oBAAoB,CAAC;AAAA,IAErB,YAAY,CAAC,YAAY;AAAA;AAAA;AAAA;AAAA,MAIvB,aAAa,OACX,QACA,iBACG;AACH,eAAO;AAAA,UACL;AAAA,UACA;AAAA,YACE,QAAQ;AAAA,YACR,MAAM;AAAA,YACN,GAAG;AAAA,UACL;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,UAAU,OAAO,QAAyB,iBAAgD;AACxF,cAAM,QAAQ,IAAI,gBAAgB;AAClC,YAAI,QAAQ,OAAQ,OAAM,IAAI,UAAU,OAAO,MAAM;AACrD,YAAI,QAAQ,UAAW,OAAM,IAAI,aAAa,OAAO,UAAU,YAAY,CAAC;AAC5E,YAAI,QAAQ,QAAS,OAAM,IAAI,WAAW,OAAO,QAAQ,YAAY,CAAC;AACtE,YAAI,QAAQ,cAAe,OAAM,IAAI,iBAAiB,MAAM;AAE5D,cAAM,cAAc,MAAM,SAAS;AACnC,eAAO;AAAA,UACL,iBAAiB,cAAc,IAAI,WAAW,KAAK,EAAE;AAAA,UACrD;AAAA,YACE,QAAQ;AAAA,YACR,GAAG;AAAA,UACL;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,qBAAqB,OACnB,QAKA,iBACG;AACH,eAAO,OAKJ,2BAA2B;AAAA,UAC5B,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA;AAAA;AAAA;AAAA,MAKA,gBAAgB,OACd,QACA,iBACG;AACH,eAAO,OAA2C,qBAAqB;AAAA,UACrE,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA;AAAA;AAAA;AAAA,MAKA,aAAa,OAAO,iBAAgD;AAClE,eAAO,OAAqD,qBAAqB;AAAA,UAC/E,QAAQ;AAAA,UACR,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA;AAAA;AAAA;AAAA,MAKA,YAAY,OAAO,iBAAgD;AACjE,eAAO,OAOJ,oBAAoB;AAAA,UACrB,QAAQ;AAAA,UACR,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IAEA,aAAa;AAAA,MACX,yBAAyB;AAAA,MACzB,kBAAkB;AAAA,MAClB,2BAA2B;AAAA,MAC3B,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,MACrB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,iBAAQ;","names":[]}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var moneymqClient = (options) => {
|
|
3
|
+
return {
|
|
4
|
+
id: "moneymq",
|
|
5
|
+
$InferServerPlugin: {},
|
|
6
|
+
getActions: ($fetch) => ({
|
|
7
|
+
/**
|
|
8
|
+
* Record usage for a metric
|
|
9
|
+
*/
|
|
10
|
+
recordUsage: async (params, fetchOptions) => {
|
|
11
|
+
return $fetch(
|
|
12
|
+
"/moneymq/usage/record",
|
|
13
|
+
{
|
|
14
|
+
method: "POST",
|
|
15
|
+
body: params,
|
|
16
|
+
...fetchOptions
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* Get usage summary for the current user
|
|
22
|
+
*/
|
|
23
|
+
getUsage: async (params, fetchOptions) => {
|
|
24
|
+
const query = new URLSearchParams();
|
|
25
|
+
if (params?.metric) query.set("metric", params.metric);
|
|
26
|
+
if (params?.startDate) query.set("startDate", params.startDate.toISOString());
|
|
27
|
+
if (params?.endDate) query.set("endDate", params.endDate.toISOString());
|
|
28
|
+
if (params?.includeBilled) query.set("includeBilled", "true");
|
|
29
|
+
const queryString = query.toString();
|
|
30
|
+
return $fetch(
|
|
31
|
+
`/moneymq/usage${queryString ? `?${queryString}` : ""}`,
|
|
32
|
+
{
|
|
33
|
+
method: "GET",
|
|
34
|
+
...fetchOptions
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Create a checkout session for unbilled usage
|
|
40
|
+
*/
|
|
41
|
+
createUsageCheckout: async (params, fetchOptions) => {
|
|
42
|
+
return $fetch("/moneymq/usage/checkout", {
|
|
43
|
+
method: "POST",
|
|
44
|
+
body: params,
|
|
45
|
+
...fetchOptions
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Create a general checkout session
|
|
50
|
+
*/
|
|
51
|
+
createCheckout: async (params, fetchOptions) => {
|
|
52
|
+
return $fetch("/moneymq/checkout", {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body: params,
|
|
55
|
+
...fetchOptions
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Get the current user's MoneyMQ customer
|
|
60
|
+
*/
|
|
61
|
+
getCustomer: async (fetchOptions) => {
|
|
62
|
+
return $fetch("/moneymq/customer", {
|
|
63
|
+
method: "GET",
|
|
64
|
+
...fetchOptions
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Get available usage metrics
|
|
69
|
+
*/
|
|
70
|
+
getMetrics: async (fetchOptions) => {
|
|
71
|
+
return $fetch("/moneymq/metrics", {
|
|
72
|
+
method: "GET",
|
|
73
|
+
...fetchOptions
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
pathMethods: {
|
|
78
|
+
"/moneymq/usage/record": "POST",
|
|
79
|
+
"/moneymq/usage": "GET",
|
|
80
|
+
"/moneymq/usage/checkout": "POST",
|
|
81
|
+
"/moneymq/checkout": "POST",
|
|
82
|
+
"/moneymq/customer": "GET",
|
|
83
|
+
"/moneymq/metrics": "GET",
|
|
84
|
+
"/moneymq/webhook": "POST"
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var client_default = moneymqClient;
|
|
89
|
+
export {
|
|
90
|
+
client_default as default,
|
|
91
|
+
moneymqClient
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from 'better-auth/client';\nimport type { moneymq } from './index';\nimport type {\n MoneyMQClientPluginOptions,\n RecordUsageParams,\n GetUsageParams,\n UsageSummary,\n CreateCheckoutParams,\n} from './types';\n\nexport type { MoneyMQClientPluginOptions, RecordUsageParams, GetUsageParams, UsageSummary, CreateCheckoutParams };\n\n/**\n * MoneyMQ client plugin for Better Auth\n *\n * Provides client-side methods for usage tracking, checkout creation,\n * and customer management.\n *\n * @example\n * ```typescript\n * import { createAuthClient } from 'better-auth/client';\n * import { moneymqClient } from '@moneymq/better-auth/client';\n *\n * export const authClient = createAuthClient({\n * plugins: [\n * moneymqClient({\n * usage: true,\n * }),\n * ],\n * });\n *\n * // Record usage\n * await authClient.moneymq.recordUsage({\n * metric: 'api_calls',\n * quantity: 1,\n * });\n *\n * // Get usage summary\n * const { usage } = await authClient.moneymq.getUsage();\n *\n * // Create checkout for usage\n * const { url } = await authClient.moneymq.createUsageCheckout({\n * successUrl: '/success',\n * cancelUrl: '/cancel',\n * });\n * ```\n */\nexport const moneymqClient = (options?: MoneyMQClientPluginOptions) => {\n return {\n id: 'moneymq',\n $InferServerPlugin: {} as ReturnType<typeof moneymq>,\n\n getActions: ($fetch) => ({\n /**\n * Record usage for a metric\n */\n recordUsage: async (\n params: RecordUsageParams,\n fetchOptions?: Parameters<typeof $fetch>[1],\n ) => {\n return $fetch<{ success: boolean; record: Record<string, unknown> }>(\n '/moneymq/usage/record',\n {\n method: 'POST',\n body: params,\n ...fetchOptions,\n },\n );\n },\n\n /**\n * Get usage summary for the current user\n */\n getUsage: async (params?: GetUsageParams, fetchOptions?: Parameters<typeof $fetch>[1]) => {\n const query = new URLSearchParams();\n if (params?.metric) query.set('metric', params.metric);\n if (params?.startDate) query.set('startDate', params.startDate.toISOString());\n if (params?.endDate) query.set('endDate', params.endDate.toISOString());\n if (params?.includeBilled) query.set('includeBilled', 'true');\n\n const queryString = query.toString();\n return $fetch<{ usage: UsageSummary[] }>(\n `/moneymq/usage${queryString ? `?${queryString}` : ''}`,\n {\n method: 'GET',\n ...fetchOptions,\n },\n );\n },\n\n /**\n * Create a checkout session for unbilled usage\n */\n createUsageCheckout: async (\n params: {\n metrics?: string[];\n successUrl: string;\n cancelUrl: string;\n },\n fetchOptions?: Parameters<typeof $fetch>[1],\n ) => {\n return $fetch<{\n url: string;\n sessionId: string;\n lineItems: Array<{ price: string; quantity: number }>;\n totalRecords: number;\n }>('/moneymq/usage/checkout', {\n method: 'POST',\n body: params,\n ...fetchOptions,\n });\n },\n\n /**\n * Create a general checkout session\n */\n createCheckout: async (\n params: CreateCheckoutParams,\n fetchOptions?: Parameters<typeof $fetch>[1],\n ) => {\n return $fetch<{ url: string; sessionId: string }>('/moneymq/checkout', {\n method: 'POST',\n body: params,\n ...fetchOptions,\n });\n },\n\n /**\n * Get the current user's MoneyMQ customer\n */\n getCustomer: async (fetchOptions?: Parameters<typeof $fetch>[1]) => {\n return $fetch<{ customer: Record<string, unknown> | null }>('/moneymq/customer', {\n method: 'GET',\n ...fetchOptions,\n });\n },\n\n /**\n * Get available usage metrics\n */\n getMetrics: async (fetchOptions?: Parameters<typeof $fetch>[1]) => {\n return $fetch<{\n metrics: Array<{\n name: string;\n displayName?: string;\n unit?: string;\n aggregation: 'sum' | 'max' | 'last';\n }>;\n }>('/moneymq/metrics', {\n method: 'GET',\n ...fetchOptions,\n });\n },\n }),\n\n pathMethods: {\n '/moneymq/usage/record': 'POST',\n '/moneymq/usage': 'GET',\n '/moneymq/usage/checkout': 'POST',\n '/moneymq/checkout': 'POST',\n '/moneymq/customer': 'GET',\n '/moneymq/metrics': 'GET',\n '/moneymq/webhook': 'POST',\n },\n } satisfies BetterAuthClientPlugin;\n};\n\nexport default moneymqClient;\n"],"mappings":";AA+CO,IAAM,gBAAgB,CAAC,YAAyC;AACrE,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,oBAAoB,CAAC;AAAA,IAErB,YAAY,CAAC,YAAY;AAAA;AAAA;AAAA;AAAA,MAIvB,aAAa,OACX,QACA,iBACG;AACH,eAAO;AAAA,UACL;AAAA,UACA;AAAA,YACE,QAAQ;AAAA,YACR,MAAM;AAAA,YACN,GAAG;AAAA,UACL;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,UAAU,OAAO,QAAyB,iBAAgD;AACxF,cAAM,QAAQ,IAAI,gBAAgB;AAClC,YAAI,QAAQ,OAAQ,OAAM,IAAI,UAAU,OAAO,MAAM;AACrD,YAAI,QAAQ,UAAW,OAAM,IAAI,aAAa,OAAO,UAAU,YAAY,CAAC;AAC5E,YAAI,QAAQ,QAAS,OAAM,IAAI,WAAW,OAAO,QAAQ,YAAY,CAAC;AACtE,YAAI,QAAQ,cAAe,OAAM,IAAI,iBAAiB,MAAM;AAE5D,cAAM,cAAc,MAAM,SAAS;AACnC,eAAO;AAAA,UACL,iBAAiB,cAAc,IAAI,WAAW,KAAK,EAAE;AAAA,UACrD;AAAA,YACE,QAAQ;AAAA,YACR,GAAG;AAAA,UACL;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,qBAAqB,OACnB,QAKA,iBACG;AACH,eAAO,OAKJ,2BAA2B;AAAA,UAC5B,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA;AAAA;AAAA;AAAA,MAKA,gBAAgB,OACd,QACA,iBACG;AACH,eAAO,OAA2C,qBAAqB;AAAA,UACrE,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA;AAAA;AAAA;AAAA,MAKA,aAAa,OAAO,iBAAgD;AAClE,eAAO,OAAqD,qBAAqB;AAAA,UAC/E,QAAQ;AAAA,UACR,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA;AAAA;AAAA;AAAA,MAKA,YAAY,OAAO,iBAAgD;AACjE,eAAO,OAOJ,oBAAoB;AAAA,UACrB,QAAQ;AAAA,UACR,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IAEA,aAAa;AAAA,MACX,yBAAyB;AAAA,MACzB,kBAAkB;AAAA,MAClB,2BAA2B;AAAA,MAC3B,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,MACrB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,iBAAQ;","names":[]}
|