@frigear-nu/payments 0.3.1 → 0.4.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/dist/module.d.mts +1 -10
- package/dist/module.json +1 -1
- package/dist/module.mjs +17 -8
- package/dist/runtime/i18n/lang/da.json +11 -0
- package/dist/runtime/i18n/lang/en.json +11 -0
- package/dist/runtime/server/mcp/tools/my-payments.js +1 -1
- package/dist/runtime/server/routes/admin/recent.get.js +1 -1
- package/dist/runtime/server/routes/admin/user-payments.get.js +1 -1
- package/dist/runtime/server/routes/me/payments.get.js +1 -1
- package/dist/runtime/server/routes/me/resume.post.js +1 -1
- package/dist/runtime/utils/index.d.ts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +7 -7
- package/dist/runtime/server/plugins/staff-scopes.d.ts +0 -2
- package/dist/runtime/server/plugins/staff-scopes.js +0 -1
- package/dist/runtime/server/utils/auth.d.ts +0 -5
- package/dist/runtime/server/utils/auth.js +0 -5
package/dist/module.d.mts
CHANGED
|
@@ -85,13 +85,6 @@ type CheckoutBeforeContext = {
|
|
|
85
85
|
type ResumeResponse = {
|
|
86
86
|
url: string;
|
|
87
87
|
};
|
|
88
|
-
/** Context of the `payments:authorize` hook. */
|
|
89
|
-
type AuthorizeContext = {
|
|
90
|
-
event: H3Event;
|
|
91
|
-
userId: number;
|
|
92
|
-
/** Set `ctx.allowed = true` to let the user see the dashboard's recent payments and revenue. Denied by default. */
|
|
93
|
-
allowed: boolean;
|
|
94
|
-
};
|
|
95
88
|
|
|
96
89
|
declare module '@nuxt/schema' {
|
|
97
90
|
interface NuxtConfig {
|
|
@@ -103,8 +96,6 @@ declare module '@nuxt/schema' {
|
|
|
103
96
|
}
|
|
104
97
|
declare module 'nitropack' {
|
|
105
98
|
interface NitroRuntimeHooks {
|
|
106
|
-
/** Staff gate (the dashboard's recent payments): set `ctx.allowed = true` to let the user in. Denied by default. */
|
|
107
|
-
'payments:authorize': (ctx: AuthorizeContext) => void | Promise<void>;
|
|
108
99
|
/** Policy hook: throw to deny a checkout, or adjust `ctx.params` before it reaches Stripe. */
|
|
109
100
|
'payments:checkout:before': (ctx: CheckoutBeforeContext) => void | Promise<void>;
|
|
110
101
|
/** A payment became `paid` (fired once, from the verified Stripe event). */
|
|
@@ -120,4 +111,4 @@ declare module 'nitropack' {
|
|
|
120
111
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
121
112
|
|
|
122
113
|
export { _default as default };
|
|
123
|
-
export type {
|
|
114
|
+
export type { CheckoutBeforeContext, CreatePaymentInput, CreatePaymentResult, InvoicePaymentInput, ModuleOptions, PaymentDto, PaymentHookContext, PaymentItem, PaymentReference, PaymentStatus, PaymentsRuntimeConfig, ResumeResponse };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, hasNuxtModule, addServerImportsDir, addServerPlugin, addImports } from '@nuxt/kit';
|
|
2
2
|
import { registerModule, registerTailwindSource, registerLocales, registerDatabaseTable, addModuleRoutes, inlineModuleRuntime } from '@frigear-nu/module-kit/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { addPermission, addScope } from '@frigear-nu/auth/utils';
|
|
4
4
|
import { extendUsersAdmin } from '@frigear-nu/users/utils';
|
|
5
5
|
import { addMcpDefinitions } from '@frigear-nu/mcp/utils';
|
|
6
6
|
import { registerStripeEventHandler } from '@frigear-nu/stripe/utils';
|
|
@@ -29,12 +29,20 @@ const module$1 = defineNuxtModule({
|
|
|
29
29
|
},
|
|
30
30
|
async setup(options, nuxt) {
|
|
31
31
|
registerModule(MODULE_NAME, nuxt);
|
|
32
|
-
|
|
32
|
+
addPermission(
|
|
33
33
|
nuxt,
|
|
34
|
-
{ name: "payments:read", description: "Read your payments",
|
|
35
|
-
{ name: "payments:write", description: "Resume your payments",
|
|
36
|
-
{ name: "payments:manage", description: "See recent payments and revenue
|
|
34
|
+
{ name: "payments:read", label: "Read your payments", labelKey: "payments.permissions.read", description: "Read your own payments.", descriptionKey: "payments.permissions.readDescription", group: "payments", implicit: true },
|
|
35
|
+
{ name: "payments:write", label: "Resume your payments", labelKey: "payments.permissions.write", description: "Resume paying for your own unpaid payments.", descriptionKey: "payments.permissions.writeDescription", group: "payments", implicit: true },
|
|
36
|
+
{ name: "payments:manage", label: "See recent payments", labelKey: "payments.permissions.manage", description: "See recent payments and revenue on the dashboard.", descriptionKey: "payments.permissions.manageDescription", group: "payments", grantTo: ["admin"] }
|
|
37
37
|
);
|
|
38
|
+
addScope(nuxt, {
|
|
39
|
+
name: "payments",
|
|
40
|
+
label: "Your payments",
|
|
41
|
+
labelKey: "payments.scopes.payments",
|
|
42
|
+
description: "Read your payments and resume unpaid ones.",
|
|
43
|
+
icon: "i-lucide-credit-card",
|
|
44
|
+
permissions: ["payments:read", "payments:write"]
|
|
45
|
+
});
|
|
38
46
|
const resolver = createResolver(import.meta.url);
|
|
39
47
|
registerTailwindSource(nuxt, resolver.resolve("./runtime/app"));
|
|
40
48
|
registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
|
|
@@ -67,13 +75,15 @@ const module$1 = defineNuxtModule({
|
|
|
67
75
|
order: 20,
|
|
68
76
|
label: "Payments",
|
|
69
77
|
labelKey: "payments.admin.tab",
|
|
70
|
-
icon: "i-lucide-credit-card"
|
|
78
|
+
icon: "i-lucide-credit-card",
|
|
79
|
+
permission: "payments:manage"
|
|
71
80
|
},
|
|
72
81
|
widget: {
|
|
73
82
|
id: "payments-last",
|
|
74
83
|
component: resolver.resolve("./runtime/app/widgets/AdminLastPayment.vue"),
|
|
75
84
|
order: 20,
|
|
76
|
-
span: 2
|
|
85
|
+
span: 2,
|
|
86
|
+
permission: "payments:manage"
|
|
77
87
|
}
|
|
78
88
|
});
|
|
79
89
|
addModuleRoutes(resolver, [
|
|
@@ -94,7 +104,6 @@ const module$1 = defineNuxtModule({
|
|
|
94
104
|
addServerImportsDir(resolver.resolve("./runtime/server/utils"));
|
|
95
105
|
inlineModuleRuntime(nuxt, resolver);
|
|
96
106
|
addServerPlugin(resolver.resolve("./runtime/server/plugins/invoice-payments"));
|
|
97
|
-
addServerPlugin(resolver.resolve("./runtime/server/plugins/staff-scopes"));
|
|
98
107
|
if (options.settings?.mcp === true) addMcpDefinitions(nuxt, resolver.resolve("./runtime/server/mcp"));
|
|
99
108
|
addImports([
|
|
100
109
|
{ name: "usePayments", from: resolver.resolve("./runtime/app/composables/usePayments") }
|
|
@@ -27,6 +27,17 @@
|
|
|
27
27
|
"transactions": "{count} transaktioner",
|
|
28
28
|
"recent": "Seneste transaktioner",
|
|
29
29
|
"viewUsers": "Se brugere"
|
|
30
|
+
},
|
|
31
|
+
"permissions": {
|
|
32
|
+
"read": "Se dine betalinger",
|
|
33
|
+
"readDescription": "Se dine egne betalinger.",
|
|
34
|
+
"write": "Genoptag dine betalinger",
|
|
35
|
+
"writeDescription": "Genoptag betaling af dine egne ubetalte betalinger.",
|
|
36
|
+
"manage": "Se seneste betalinger",
|
|
37
|
+
"manageDescription": "Se seneste betalinger og omsætning på dashboardet."
|
|
38
|
+
},
|
|
39
|
+
"scopes": {
|
|
40
|
+
"payments": "Dine betalinger"
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
43
|
}
|
|
@@ -27,6 +27,17 @@
|
|
|
27
27
|
"transactions": "{count} transactions",
|
|
28
28
|
"recent": "Recent transactions",
|
|
29
29
|
"viewUsers": "View users"
|
|
30
|
+
},
|
|
31
|
+
"permissions": {
|
|
32
|
+
"read": "Read your payments",
|
|
33
|
+
"readDescription": "Read your own payments.",
|
|
34
|
+
"write": "Resume your payments",
|
|
35
|
+
"writeDescription": "Resume paying for your own unpaid payments.",
|
|
36
|
+
"manage": "See recent payments",
|
|
37
|
+
"manageDescription": "See recent payments and revenue on the dashboard."
|
|
38
|
+
},
|
|
39
|
+
"scopes": {
|
|
40
|
+
"payments": "Your payments"
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
43
|
}
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { fieldsFromCents } from "@frigear-nu/mcp/utils";
|
|
3
3
|
export default defineScopedMcpTool({
|
|
4
4
|
description: "List your own payments, newest first: tickets, memberships and other charges with amount, status, refunds and what each was for. Amounts are in whole currency units (52.2 = 52.20), not cents.",
|
|
5
|
-
|
|
5
|
+
permission: "payments:read",
|
|
6
6
|
annotations: { readOnlyHint: true },
|
|
7
7
|
inputSchema: { limit: z.number().int().min(1).max(100).optional().describe("How many payments to return (default 50).") },
|
|
8
8
|
handler: async ({ limit }, { user }) => ({
|
|
@@ -3,7 +3,7 @@ import { and, count, desc, eq, gte, inArray, sql } from "drizzle-orm";
|
|
|
3
3
|
const DAYS = 30;
|
|
4
4
|
const LIMIT = 8;
|
|
5
5
|
export default defineEventHandler(async (event) => {
|
|
6
|
-
await
|
|
6
|
+
await authorize(event, "payments:manage");
|
|
7
7
|
const since = new Date(Date.now() - DAYS * 24 * 60 * 60 * 1e3);
|
|
8
8
|
const settled = inArray(schema.payments.status, ["paid", "partially_refunded"]);
|
|
9
9
|
const when = sql`coalesce(${schema.payments.paidAt}, ${schema.payments.createdAt})`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
const querySchema = z.object({ limit: z.coerce.number().int().min(1).max(500).default(100) });
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
const { target } = await loadUsersAdminTarget(event, "view");
|
|
4
|
+
const { target } = await loadUsersAdminTarget(event, "view", { permission: "payments:manage" });
|
|
5
5
|
const { limit } = await getValidatedQuery(event, querySchema.parse);
|
|
6
6
|
return listUserPayments(target.id, { limit });
|
|
7
7
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { idParams } from "@frigear-nu/module-kit/server";
|
|
2
2
|
export default defineEventHandler(async (event) => {
|
|
3
|
-
const user = await
|
|
3
|
+
const { user } = await authorize(event, "payments:write");
|
|
4
4
|
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
5
5
|
return resumePayment(id, user.id, event);
|
|
6
6
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PaymentItem } from '../../types.js';
|
|
2
2
|
export * from './api.js';
|
|
3
|
-
export type {
|
|
3
|
+
export type { CheckoutBeforeContext, CreatePaymentInput, CreatePaymentResult, ModuleOptions, PaymentDto, PaymentHookContext, PaymentItem, PaymentReference, PaymentStatus, RecentPaymentDto, RecentPaymentsDto, ResumeResponse, } from '../../types.js';
|
|
4
4
|
/** Total of a list of items in minor units. */
|
|
5
5
|
export declare function sumItems(items: PaymentItem[]): number;
|
package/dist/types.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from './module.mjs'
|
|
2
2
|
|
|
3
|
-
export { type
|
|
3
|
+
export { type CheckoutBeforeContext, type CreatePaymentInput, type CreatePaymentResult, type InvoicePaymentInput, type ModuleOptions, type PaymentDto, type PaymentHookContext, type PaymentItem, type PaymentReference, type PaymentStatus, type PaymentsRuntimeConfig, type ResumeResponse } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "One-time payments (Stripe Checkout, refunds and payment lifecycle hooks) for the frigear ecosystem, built on @frigear-nu/stripe.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/commerce/payments",
|
|
6
6
|
"repository": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"playground"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@frigear-nu/auth": "^0.
|
|
39
|
-
"@frigear-nu/mcp": "^0.
|
|
38
|
+
"@frigear-nu/auth": "^0.5.0",
|
|
39
|
+
"@frigear-nu/mcp": "^0.4.0",
|
|
40
40
|
"@frigear-nu/module-kit": "^1.3.5",
|
|
41
|
-
"@frigear-nu/stripe": "^0.
|
|
41
|
+
"@frigear-nu/stripe": "^0.4.0",
|
|
42
42
|
"@frigear-nu/ui": "^0.2.6",
|
|
43
|
-
"@frigear-nu/users": "^
|
|
43
|
+
"@frigear-nu/users": "^3.0.0",
|
|
44
44
|
"@libsql/client": "^0.18.0",
|
|
45
45
|
"@nuxt/kit": "^4.6.4",
|
|
46
46
|
"drizzle-kit": "^0.31.11",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"zod": "^4.6.7"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@frigear-nu/widget": "^0.
|
|
53
|
+
"@frigear-nu/widget": "^0.3.0",
|
|
54
54
|
"@nuxt/ui": "^4.12.0",
|
|
55
55
|
"@nuxthub/core": "^0.10.12"
|
|
56
56
|
},
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@frigear-nu/widget": "^0.
|
|
66
|
+
"@frigear-nu/widget": "^0.3.0",
|
|
67
67
|
"@nuxt/devtools": "^4.1.0",
|
|
68
68
|
"@nuxt/eslint-config": "^1.17.0",
|
|
69
69
|
"@nuxt/module-builder": "^1.0.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default defineStaffScopes(["payments:manage"], (event, userId) => paymentsStaff.can(event, userId));
|