@baseworks/invoice 0.1.0 → 0.1.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/dist/events.d.ts +4 -4
- package/dist/graphql.d.ts +36 -0
- package/dist/graphql.js +60 -0
- package/package.json +3 -2
- package/src/graphql.ts +62 -0
package/dist/events.d.ts
CHANGED
|
@@ -102,18 +102,18 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
102
102
|
reference: z.ZodString;
|
|
103
103
|
at: z.ZodNumber;
|
|
104
104
|
}, "strip", z.ZodTypeAny, {
|
|
105
|
-
method: string;
|
|
106
105
|
at: number;
|
|
107
106
|
status: "draft" | "finalized" | "paid" | "void";
|
|
108
107
|
amountCents: number;
|
|
109
108
|
amountPaidCents: number;
|
|
109
|
+
method: string;
|
|
110
110
|
reference: string;
|
|
111
111
|
}, {
|
|
112
|
-
method: string;
|
|
113
112
|
at: number;
|
|
114
113
|
status: "draft" | "finalized" | "paid" | "void";
|
|
115
114
|
amountCents: number;
|
|
116
115
|
amountPaidCents: number;
|
|
116
|
+
method: string;
|
|
117
117
|
reference: string;
|
|
118
118
|
}>;
|
|
119
119
|
InvoiceVoided: z.ZodObject<{
|
|
@@ -151,23 +151,23 @@ declare const TransactionEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
151
151
|
reference: z.ZodString;
|
|
152
152
|
at: z.ZodNumber;
|
|
153
153
|
}, "strip", z.ZodTypeAny, {
|
|
154
|
-
method: string;
|
|
155
154
|
at: number;
|
|
156
155
|
customerId: string;
|
|
157
156
|
customerName: string;
|
|
158
157
|
currency: string;
|
|
159
158
|
amountCents: number;
|
|
159
|
+
method: string;
|
|
160
160
|
reference: string;
|
|
161
161
|
invoiceId: string;
|
|
162
162
|
invoiceNumber: number;
|
|
163
163
|
kind: "payment" | "refund" | "adjustment";
|
|
164
164
|
}, {
|
|
165
|
-
method: string;
|
|
166
165
|
at: number;
|
|
167
166
|
customerId: string;
|
|
168
167
|
customerName: string;
|
|
169
168
|
currency: string;
|
|
170
169
|
amountCents: number;
|
|
170
|
+
method: string;
|
|
171
171
|
reference: string;
|
|
172
172
|
invoiceId: string;
|
|
173
173
|
invoiceNumber: number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createInvoiceClient, Invoice, Transaction } from './client.js';
|
|
2
|
+
import './events.js';
|
|
3
|
+
import '@baseworks/foldbase';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** GraphQL read module for invoices — invoices + transactions, `extend`s Customer. */
|
|
7
|
+
interface InvoiceGraphContext {
|
|
8
|
+
invoice: ReturnType<typeof createInvoiceClient>;
|
|
9
|
+
customerLoader: {
|
|
10
|
+
load(id: string): Promise<unknown>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare const typeDefs = "\n type Invoice {\n id: ID!\n number: Int\n status: String!\n currency: String!\n subtotalCents: Int!\n totalCents: Int!\n amountPaidCents: Int!\n balanceCents: Int!\n dueAt: Float\n createdAt: Float!\n lines: [InvoiceLine!]!\n customer: Customer\n transactions: [Transaction!]!\n }\n type InvoiceLine {\n description: String!\n quantity: Float!\n unitPriceCents: Int!\n amountCents: Int!\n }\n type Transaction {\n id: ID!\n kind: String!\n amountCents: Int!\n currency: String!\n method: String\n reference: String\n createdAt: Float!\n }\n extend type Query {\n invoice(ref: String!): Invoice\n invoices(status: String): [Invoice!]!\n }\n extend type Customer {\n invoices(status: String): [Invoice!]!\n }\n";
|
|
14
|
+
declare const resolvers: {
|
|
15
|
+
Query: {
|
|
16
|
+
invoice: (_: unknown, { ref }: {
|
|
17
|
+
ref: string;
|
|
18
|
+
}, ctx: InvoiceGraphContext) => Promise<Invoice | null>;
|
|
19
|
+
invoices: (_: unknown, { status }: {
|
|
20
|
+
status?: string;
|
|
21
|
+
}, ctx: InvoiceGraphContext) => Promise<Invoice[]>;
|
|
22
|
+
};
|
|
23
|
+
Customer: {
|
|
24
|
+
invoices: (parent: {
|
|
25
|
+
id: string;
|
|
26
|
+
}, { status }: {
|
|
27
|
+
status?: string;
|
|
28
|
+
}, ctx: InvoiceGraphContext) => Promise<Invoice[]>;
|
|
29
|
+
};
|
|
30
|
+
Invoice: {
|
|
31
|
+
customer: (parent: Invoice, _: unknown, ctx: InvoiceGraphContext) => Promise<unknown>;
|
|
32
|
+
transactions: (parent: Invoice, _: unknown, ctx: InvoiceGraphContext) => Promise<never[] | Transaction[]>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { type InvoiceGraphContext, resolvers, typeDefs };
|
package/dist/graphql.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/graphql.ts
|
|
2
|
+
var typeDefs = (
|
|
3
|
+
/* GraphQL */
|
|
4
|
+
`
|
|
5
|
+
type Invoice {
|
|
6
|
+
id: ID!
|
|
7
|
+
number: Int
|
|
8
|
+
status: String!
|
|
9
|
+
currency: String!
|
|
10
|
+
subtotalCents: Int!
|
|
11
|
+
totalCents: Int!
|
|
12
|
+
amountPaidCents: Int!
|
|
13
|
+
balanceCents: Int!
|
|
14
|
+
dueAt: Float
|
|
15
|
+
createdAt: Float!
|
|
16
|
+
lines: [InvoiceLine!]!
|
|
17
|
+
customer: Customer
|
|
18
|
+
transactions: [Transaction!]!
|
|
19
|
+
}
|
|
20
|
+
type InvoiceLine {
|
|
21
|
+
description: String!
|
|
22
|
+
quantity: Float!
|
|
23
|
+
unitPriceCents: Int!
|
|
24
|
+
amountCents: Int!
|
|
25
|
+
}
|
|
26
|
+
type Transaction {
|
|
27
|
+
id: ID!
|
|
28
|
+
kind: String!
|
|
29
|
+
amountCents: Int!
|
|
30
|
+
currency: String!
|
|
31
|
+
method: String
|
|
32
|
+
reference: String
|
|
33
|
+
createdAt: Float!
|
|
34
|
+
}
|
|
35
|
+
extend type Query {
|
|
36
|
+
invoice(ref: String!): Invoice
|
|
37
|
+
invoices(status: String): [Invoice!]!
|
|
38
|
+
}
|
|
39
|
+
extend type Customer {
|
|
40
|
+
invoices(status: String): [Invoice!]!
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
);
|
|
44
|
+
var resolvers = {
|
|
45
|
+
Query: {
|
|
46
|
+
invoice: (_, { ref }, ctx) => ctx.invoice.get(ref).catch(() => null),
|
|
47
|
+
invoices: (_, { status }, ctx) => ctx.invoice.list(status ? { status } : {})
|
|
48
|
+
},
|
|
49
|
+
Customer: {
|
|
50
|
+
invoices: async (parent, { status }, ctx) => (await ctx.invoice.list(status ? { status } : {})).filter((i) => i.customerId === parent.id)
|
|
51
|
+
},
|
|
52
|
+
Invoice: {
|
|
53
|
+
customer: (parent, _, ctx) => ctx.customerLoader.load(parent.customerId),
|
|
54
|
+
transactions: (parent, _, ctx) => ctx.invoice.invoiceTransactions(parent.id).catch(() => [])
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
resolvers,
|
|
59
|
+
typeDefs
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baseworks/invoice",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Invoice capability: typed HTTP client, event catalog, projections, and CLI plugin for invoice-service (AR ledger). Contract-first, versioned with the service.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
".": "./dist/client.js",
|
|
11
11
|
"./events": "./dist/events.js",
|
|
12
12
|
"./projections": "./dist/projections.js",
|
|
13
|
-
"./cli": "./dist/cli.js"
|
|
13
|
+
"./cli": "./dist/cli.js",
|
|
14
|
+
"./graphql": "./dist/graphql.js"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist",
|
package/src/graphql.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { createInvoiceClient, Invoice } from './client.js'
|
|
2
|
+
|
|
3
|
+
/** GraphQL read module for invoices — invoices + transactions, `extend`s Customer. */
|
|
4
|
+
export interface InvoiceGraphContext {
|
|
5
|
+
invoice: ReturnType<typeof createInvoiceClient>
|
|
6
|
+
customerLoader: { load(id: string): Promise<unknown> }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const typeDefs = /* GraphQL */ `
|
|
10
|
+
type Invoice {
|
|
11
|
+
id: ID!
|
|
12
|
+
number: Int
|
|
13
|
+
status: String!
|
|
14
|
+
currency: String!
|
|
15
|
+
subtotalCents: Int!
|
|
16
|
+
totalCents: Int!
|
|
17
|
+
amountPaidCents: Int!
|
|
18
|
+
balanceCents: Int!
|
|
19
|
+
dueAt: Float
|
|
20
|
+
createdAt: Float!
|
|
21
|
+
lines: [InvoiceLine!]!
|
|
22
|
+
customer: Customer
|
|
23
|
+
transactions: [Transaction!]!
|
|
24
|
+
}
|
|
25
|
+
type InvoiceLine {
|
|
26
|
+
description: String!
|
|
27
|
+
quantity: Float!
|
|
28
|
+
unitPriceCents: Int!
|
|
29
|
+
amountCents: Int!
|
|
30
|
+
}
|
|
31
|
+
type Transaction {
|
|
32
|
+
id: ID!
|
|
33
|
+
kind: String!
|
|
34
|
+
amountCents: Int!
|
|
35
|
+
currency: String!
|
|
36
|
+
method: String
|
|
37
|
+
reference: String
|
|
38
|
+
createdAt: Float!
|
|
39
|
+
}
|
|
40
|
+
extend type Query {
|
|
41
|
+
invoice(ref: String!): Invoice
|
|
42
|
+
invoices(status: String): [Invoice!]!
|
|
43
|
+
}
|
|
44
|
+
extend type Customer {
|
|
45
|
+
invoices(status: String): [Invoice!]!
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
|
|
49
|
+
export const resolvers = {
|
|
50
|
+
Query: {
|
|
51
|
+
invoice: (_: unknown, { ref }: { ref: string }, ctx: InvoiceGraphContext) => ctx.invoice.get(ref).catch(() => null),
|
|
52
|
+
invoices: (_: unknown, { status }: { status?: string }, ctx: InvoiceGraphContext) => ctx.invoice.list(status ? { status } : {}),
|
|
53
|
+
},
|
|
54
|
+
Customer: {
|
|
55
|
+
invoices: async (parent: { id: string }, { status }: { status?: string }, ctx: InvoiceGraphContext) =>
|
|
56
|
+
(await ctx.invoice.list(status ? { status } : {})).filter((i) => i.customerId === parent.id),
|
|
57
|
+
},
|
|
58
|
+
Invoice: {
|
|
59
|
+
customer: (parent: Invoice, _: unknown, ctx: InvoiceGraphContext) => ctx.customerLoader.load(parent.customerId),
|
|
60
|
+
transactions: (parent: Invoice, _: unknown, ctx: InvoiceGraphContext) => ctx.invoice.invoiceTransactions(parent.id).catch(() => []),
|
|
61
|
+
},
|
|
62
|
+
}
|