@powerhousedao/contributor-billing 0.0.76 → 0.0.77

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.
Files changed (176) hide show
  1. package/dist/document-models/billing-statement/gen/general/actions.d.ts +13 -4
  2. package/dist/document-models/billing-statement/gen/general/actions.d.ts.map +1 -1
  3. package/dist/document-models/billing-statement/gen/general/object.d.ts +3 -3
  4. package/dist/document-models/billing-statement/gen/general/object.d.ts.map +1 -1
  5. package/dist/document-models/billing-statement/gen/index.d.ts +2 -0
  6. package/dist/document-models/billing-statement/gen/index.d.ts.map +1 -1
  7. package/dist/document-models/billing-statement/gen/index.js +1 -0
  8. package/dist/document-models/billing-statement/gen/line-items/actions.d.ts +9 -3
  9. package/dist/document-models/billing-statement/gen/line-items/actions.d.ts.map +1 -1
  10. package/dist/document-models/billing-statement/gen/line-items/object.d.ts +3 -3
  11. package/dist/document-models/billing-statement/gen/line-items/object.d.ts.map +1 -1
  12. package/dist/document-models/billing-statement/gen/object.d.ts +4 -5
  13. package/dist/document-models/billing-statement/gen/object.d.ts.map +1 -1
  14. package/dist/document-models/billing-statement/gen/object.js +2 -2
  15. package/dist/document-models/billing-statement/gen/ph-factories.d.ts +27 -0
  16. package/dist/document-models/billing-statement/gen/ph-factories.d.ts.map +1 -0
  17. package/dist/document-models/billing-statement/gen/ph-factories.js +58 -0
  18. package/dist/document-models/billing-statement/gen/reducer.d.ts +4 -2
  19. package/dist/document-models/billing-statement/gen/reducer.d.ts.map +1 -1
  20. package/dist/document-models/billing-statement/gen/reducer.js +4 -1
  21. package/dist/document-models/billing-statement/gen/schema/types.d.ts +4 -0
  22. package/dist/document-models/billing-statement/gen/schema/types.d.ts.map +1 -1
  23. package/dist/document-models/billing-statement/gen/tags/actions.d.ts +5 -2
  24. package/dist/document-models/billing-statement/gen/tags/actions.d.ts.map +1 -1
  25. package/dist/document-models/billing-statement/gen/tags/object.d.ts +3 -3
  26. package/dist/document-models/billing-statement/gen/tags/object.d.ts.map +1 -1
  27. package/dist/document-models/billing-statement/gen/types.d.ts +4 -4
  28. package/dist/document-models/billing-statement/gen/types.d.ts.map +1 -1
  29. package/dist/document-models/billing-statement/gen/utils.d.ts +18 -3
  30. package/dist/document-models/billing-statement/gen/utils.d.ts.map +1 -1
  31. package/dist/document-models/billing-statement/gen/utils.js +33 -29
  32. package/dist/document-models/billing-statement/index.d.ts +8 -9
  33. package/dist/document-models/billing-statement/index.d.ts.map +1 -1
  34. package/dist/document-models/integrations/gen/index.d.ts +2 -0
  35. package/dist/document-models/integrations/gen/index.d.ts.map +1 -1
  36. package/dist/document-models/integrations/gen/index.js +1 -0
  37. package/dist/document-models/integrations/gen/integrations/actions.d.ts +13 -4
  38. package/dist/document-models/integrations/gen/integrations/actions.d.ts.map +1 -1
  39. package/dist/document-models/integrations/gen/integrations/object.d.ts +3 -3
  40. package/dist/document-models/integrations/gen/integrations/object.d.ts.map +1 -1
  41. package/dist/document-models/integrations/gen/object.d.ts +4 -5
  42. package/dist/document-models/integrations/gen/object.d.ts.map +1 -1
  43. package/dist/document-models/integrations/gen/object.js +2 -2
  44. package/dist/document-models/integrations/gen/ph-factories.d.ts +27 -0
  45. package/dist/document-models/integrations/gen/ph-factories.d.ts.map +1 -0
  46. package/dist/document-models/integrations/gen/ph-factories.js +75 -0
  47. package/dist/document-models/integrations/gen/reducer.d.ts +4 -2
  48. package/dist/document-models/integrations/gen/reducer.d.ts.map +1 -1
  49. package/dist/document-models/integrations/gen/reducer.js +4 -1
  50. package/dist/document-models/integrations/gen/schema/types.d.ts +4 -0
  51. package/dist/document-models/integrations/gen/schema/types.d.ts.map +1 -1
  52. package/dist/document-models/integrations/gen/types.d.ts +4 -4
  53. package/dist/document-models/integrations/gen/types.d.ts.map +1 -1
  54. package/dist/document-models/integrations/gen/utils.d.ts +18 -3
  55. package/dist/document-models/integrations/gen/utils.d.ts.map +1 -1
  56. package/dist/document-models/integrations/gen/utils.js +36 -32
  57. package/dist/document-models/integrations/index.d.ts +8 -9
  58. package/dist/document-models/integrations/index.d.ts.map +1 -1
  59. package/dist/document-models/invoice/gen/general/actions.d.ts +21 -6
  60. package/dist/document-models/invoice/gen/general/actions.d.ts.map +1 -1
  61. package/dist/document-models/invoice/gen/general/object.d.ts +3 -3
  62. package/dist/document-models/invoice/gen/general/object.d.ts.map +1 -1
  63. package/dist/document-models/invoice/gen/index.d.ts +2 -0
  64. package/dist/document-models/invoice/gen/index.d.ts.map +1 -1
  65. package/dist/document-models/invoice/gen/index.js +1 -0
  66. package/dist/document-models/invoice/gen/items/actions.d.ts +21 -6
  67. package/dist/document-models/invoice/gen/items/actions.d.ts.map +1 -1
  68. package/dist/document-models/invoice/gen/items/object.d.ts +3 -3
  69. package/dist/document-models/invoice/gen/items/object.d.ts.map +1 -1
  70. package/dist/document-models/invoice/gen/object.d.ts +4 -5
  71. package/dist/document-models/invoice/gen/object.d.ts.map +1 -1
  72. package/dist/document-models/invoice/gen/object.js +2 -2
  73. package/dist/document-models/invoice/gen/parties/actions.d.ts +25 -7
  74. package/dist/document-models/invoice/gen/parties/actions.d.ts.map +1 -1
  75. package/dist/document-models/invoice/gen/parties/object.d.ts +3 -3
  76. package/dist/document-models/invoice/gen/parties/object.d.ts.map +1 -1
  77. package/dist/document-models/invoice/gen/ph-factories.d.ts +27 -0
  78. package/dist/document-models/invoice/gen/ph-factories.d.ts.map +1 -0
  79. package/dist/document-models/invoice/gen/ph-factories.js +190 -0
  80. package/dist/document-models/invoice/gen/reducer.d.ts +4 -2
  81. package/dist/document-models/invoice/gen/reducer.d.ts.map +1 -1
  82. package/dist/document-models/invoice/gen/reducer.js +4 -1
  83. package/dist/document-models/invoice/gen/schema/types.d.ts +4 -0
  84. package/dist/document-models/invoice/gen/schema/types.d.ts.map +1 -1
  85. package/dist/document-models/invoice/gen/schema/zod.d.ts.map +1 -1
  86. package/dist/document-models/invoice/gen/transitions/actions.d.ts +49 -13
  87. package/dist/document-models/invoice/gen/transitions/actions.d.ts.map +1 -1
  88. package/dist/document-models/invoice/gen/transitions/object.d.ts +3 -3
  89. package/dist/document-models/invoice/gen/transitions/object.d.ts.map +1 -1
  90. package/dist/document-models/invoice/gen/types.d.ts +4 -4
  91. package/dist/document-models/invoice/gen/types.d.ts.map +1 -1
  92. package/dist/document-models/invoice/gen/utils.d.ts +18 -3
  93. package/dist/document-models/invoice/gen/utils.d.ts.map +1 -1
  94. package/dist/document-models/invoice/gen/utils.js +33 -29
  95. package/dist/document-models/invoice/index.d.ts +8 -9
  96. package/dist/document-models/invoice/index.d.ts.map +1 -1
  97. package/dist/editors/billing-statement/editor.d.ts +2 -3
  98. package/dist/editors/billing-statement/editor.d.ts.map +1 -1
  99. package/dist/editors/billing-statement/editor.js +11 -3
  100. package/dist/editors/billing-statement/index.d.ts +1 -2
  101. package/dist/editors/billing-statement/index.d.ts.map +1 -1
  102. package/dist/editors/billing-statement/lineItemTags/lineItemTags.js +1 -1
  103. package/dist/editors/contributor-billing/components/CreateDocument.d.ts +5 -7
  104. package/dist/editors/contributor-billing/components/CreateDocument.d.ts.map +1 -1
  105. package/dist/editors/contributor-billing/components/CreateDocument.js +18 -9
  106. package/dist/editors/contributor-billing/components/DriveExplorer.d.ts +6 -16
  107. package/dist/editors/contributor-billing/components/DriveExplorer.d.ts.map +1 -1
  108. package/dist/editors/contributor-billing/components/DriveExplorer.js +190 -89
  109. package/dist/editors/contributor-billing/components/EditorContainer.d.ts +9 -13
  110. package/dist/editors/contributor-billing/components/EditorContainer.d.ts.map +1 -1
  111. package/dist/editors/contributor-billing/components/EditorContainer.js +37 -26
  112. package/dist/editors/contributor-billing/components/FolderTree.d.ts +7 -3
  113. package/dist/editors/contributor-billing/components/FolderTree.d.ts.map +1 -1
  114. package/dist/editors/contributor-billing/components/FolderTree.js +11 -4
  115. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts +1 -2
  116. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts.map +1 -1
  117. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts +4 -8
  118. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts.map +1 -1
  119. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.js +125 -119
  120. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.d.ts +1 -2
  121. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.d.ts.map +1 -1
  122. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.js +24 -4
  123. package/dist/editors/contributor-billing/editor.d.ts +9 -4
  124. package/dist/editors/contributor-billing/editor.d.ts.map +1 -1
  125. package/dist/editors/contributor-billing/editor.js +15 -41
  126. package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts +1 -2
  127. package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts.map +1 -1
  128. package/dist/editors/contributor-billing/index.d.ts +1 -2
  129. package/dist/editors/contributor-billing/index.d.ts.map +1 -1
  130. package/dist/editors/integrations/editor.d.ts +1 -4
  131. package/dist/editors/integrations/editor.d.ts.map +1 -1
  132. package/dist/editors/integrations/editor.js +10 -1
  133. package/dist/editors/integrations/index.d.ts +1 -2
  134. package/dist/editors/integrations/index.d.ts.map +1 -1
  135. package/dist/editors/invoice/editor.d.ts +1 -4
  136. package/dist/editors/invoice/editor.d.ts.map +1 -1
  137. package/dist/editors/invoice/editor.js +10 -1
  138. package/dist/editors/invoice/index.d.ts +1 -2
  139. package/dist/editors/invoice/index.d.ts.map +1 -1
  140. package/dist/editors/invoice/ingestPDF.js +1 -1
  141. package/dist/editors/invoice/invoiceToGnosis.js +3 -3
  142. package/dist/editors/invoice/requestFinance.js +2 -2
  143. package/dist/editors/invoice/uploadPdfChunked.js +1 -1
  144. package/dist/index.d.ts +2 -2
  145. package/dist/index.d.ts.map +1 -1
  146. package/dist/reducers/general.d.ts +8 -0
  147. package/dist/reducers/general.d.ts.map +1 -0
  148. package/dist/reducers/general.js +73 -0
  149. package/dist/reducers/items.d.ts +8 -0
  150. package/dist/reducers/items.d.ts.map +1 -0
  151. package/dist/reducers/items.js +195 -0
  152. package/dist/reducers/parties.d.ts +8 -0
  153. package/dist/reducers/parties.d.ts.map +1 -0
  154. package/dist/reducers/parties.js +266 -0
  155. package/dist/reducers/transitions.d.ts +8 -0
  156. package/dist/reducers/transitions.d.ts.map +1 -0
  157. package/dist/reducers/transitions.js +162 -0
  158. package/dist/scripts/contributor-billing/createXeroCsv.js +2 -2
  159. package/dist/scripts/invoice/gnosisTransactionBuilder.js +1 -1
  160. package/dist/style.css +730 -108
  161. package/dist/subgraphs/billing-statement/index.d.ts +2 -1
  162. package/dist/subgraphs/billing-statement/index.d.ts.map +1 -1
  163. package/dist/subgraphs/billing-statement/resolvers.d.ts.map +1 -1
  164. package/dist/subgraphs/billing-statement/resolvers.js +101 -69
  165. package/dist/subgraphs/billing-statement/schema.js +3 -3
  166. package/dist/subgraphs/integrations/index.d.ts +2 -1
  167. package/dist/subgraphs/integrations/index.d.ts.map +1 -1
  168. package/dist/subgraphs/integrations/resolvers.d.ts.map +1 -1
  169. package/dist/subgraphs/integrations/resolvers.js +61 -46
  170. package/dist/subgraphs/integrations/schema.js +3 -3
  171. package/dist/subgraphs/invoice/index.d.ts +2 -1
  172. package/dist/subgraphs/invoice/index.d.ts.map +1 -1
  173. package/dist/subgraphs/invoice/resolvers.d.ts.map +1 -1
  174. package/dist/subgraphs/invoice/resolvers.js +323 -181
  175. package/dist/subgraphs/invoice/schema.js +3 -3
  176. package/package.json +14 -14
@@ -1,266 +1,408 @@
1
- import { addFile } from "document-drive";
2
- import { actions } from "../../document-models/invoice/index.js";
3
- import { generateId } from "document-model";
4
1
  import { Invoice_processGnosisPayment, Invoice_createRequestFinancePayment, Invoice_uploadInvoicePdfChunk } from "./customResolvers.js";
5
- const DEFAULT_DRIVE_ID = "powerhouse";
2
+ import { addFile } from "document-drive";
3
+ import { actions, } from "../../document-models/invoice/index.js";
4
+ import { setName } from "document-model";
6
5
  export const getResolvers = (subgraph) => {
7
6
  const reactor = subgraph.reactor;
8
7
  return {
9
8
  Query: {
10
- Invoice: async (_, args, ctx) => {
9
+ Invoice: async () => {
11
10
  return {
12
11
  getDocument: async (args) => {
13
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
14
- const docId = args.docId || "";
15
- const doc = await reactor.getDocument(driveId, docId);
12
+ const { docId, driveId } = args;
13
+ if (!docId) {
14
+ throw new Error("Document id is required");
15
+ }
16
+ if (driveId) {
17
+ const docIds = await reactor.getDocuments(driveId);
18
+ if (!docIds.includes(docId)) {
19
+ throw new Error(`Document with id ${docId} is not part of ${driveId}`);
20
+ }
21
+ }
22
+ const doc = await reactor.getDocument(docId);
16
23
  return {
17
24
  driveId: driveId,
18
25
  ...doc,
19
- state: doc?.state?.global ?? "",
20
- stateJSON: doc?.state?.global,
21
- revision: doc?.header?.revision?.global,
26
+ ...doc.header,
27
+ state: doc.state.global,
28
+ stateJSON: doc.state.global,
29
+ revision: doc.header?.revision?.global ?? 0,
22
30
  };
23
31
  },
24
32
  getDocuments: async (args) => {
25
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
33
+ const { driveId } = args;
26
34
  const docsIds = await reactor.getDocuments(driveId);
27
- const docs = await Promise.all((docsIds ?? []).map(async (docId) => {
28
- const doc = await reactor.getDocument(driveId, docId);
35
+ const docs = await Promise.all(docsIds.map(async (docId) => {
36
+ const doc = await reactor.getDocument(docId);
29
37
  return {
30
38
  driveId: driveId,
31
39
  ...doc,
32
- state: doc?.state?.global,
33
- stateJSON: doc?.state?.global,
34
- revision: doc?.header?.revision?.global,
40
+ ...doc.header,
41
+ state: doc.state.global,
42
+ stateJSON: doc.state.global,
43
+ revision: doc.header?.revision?.global ?? 0,
35
44
  };
36
45
  }));
37
- return docs.filter((doc) => doc.header?.documentType === "powerhouse/invoice");
46
+ return docs.filter((doc) => doc.header.documentType === "powerhouse/invoice");
38
47
  },
39
48
  };
40
49
  },
41
50
  },
42
51
  Mutation: {
43
52
  Invoice_createDocument: async (_, args) => {
44
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
45
- const docId = generateId();
46
- await reactor.addDriveAction(driveId, addFile({
47
- id: docId,
48
- name: args.name,
49
- documentType: "powerhouse/invoice",
50
- synchronizationUnits: [
51
- {
52
- branch: "main",
53
- scope: "global",
54
- syncId: generateId(),
55
- },
56
- {
57
- branch: "main",
58
- scope: "local",
59
- syncId: generateId(),
60
- },
61
- ],
62
- }));
63
- return docId;
53
+ const { driveId, name } = args;
54
+ const document = await reactor.addDocument("powerhouse/invoice");
55
+ if (driveId) {
56
+ await reactor.addAction(driveId, addFile({
57
+ name,
58
+ id: document.header.id,
59
+ documentType: "powerhouse/invoice",
60
+ }));
61
+ }
62
+ if (name) {
63
+ await reactor.addAction(document.header.id, setName(name));
64
+ }
65
+ return document.header.id;
64
66
  },
65
67
  Invoice_editInvoice: async (_, args) => {
66
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
67
- const docId = args.docId || "";
68
- const doc = await reactor.getDocument(driveId, docId);
69
- await reactor.addAction(driveId, docId, actions.editInvoice({ ...args.input }));
70
- return (doc?.header?.revision.global ?? 0) + 1;
68
+ const { docId, input } = args;
69
+ const doc = await reactor.getDocument(docId);
70
+ if (!doc) {
71
+ throw new Error("Document not found");
72
+ }
73
+ const result = await reactor.addAction(docId, actions.editInvoice(input));
74
+ if (result.status !== "SUCCESS") {
75
+ throw new Error(result.error?.message ?? "Failed to editInvoice");
76
+ }
77
+ return true;
71
78
  },
72
79
  Invoice_editStatus: async (_, args) => {
73
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
74
- const docId = args.docId || "";
75
- const doc = await reactor.getDocument(driveId, docId);
76
- await reactor.addAction(driveId, docId, actions.editStatus({ ...args.input }));
77
- return (doc?.header?.revision.global ?? 0) + 1;
80
+ const { docId, input } = args;
81
+ const doc = await reactor.getDocument(docId);
82
+ if (!doc) {
83
+ throw new Error("Document not found");
84
+ }
85
+ const result = await reactor.addAction(docId, actions.editStatus(input));
86
+ if (result.status !== "SUCCESS") {
87
+ throw new Error(result.error?.message ?? "Failed to editStatus");
88
+ }
89
+ return true;
78
90
  },
79
91
  Invoice_editPaymentData: async (_, args) => {
80
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
81
- const docId = args.docId || "";
82
- const doc = await reactor.getDocument(driveId, docId);
83
- await reactor.addAction(driveId, docId, actions.editPaymentData({ ...args.input }));
84
- return (doc?.header?.revision.global ?? 0) + 1;
92
+ const { docId, input } = args;
93
+ const doc = await reactor.getDocument(docId);
94
+ if (!doc) {
95
+ throw new Error("Document not found");
96
+ }
97
+ const result = await reactor.addAction(docId, actions.editPaymentData(input));
98
+ if (result.status !== "SUCCESS") {
99
+ throw new Error(result.error?.message ?? "Failed to editPaymentData");
100
+ }
101
+ return true;
85
102
  },
86
103
  Invoice_setExportedData: async (_, args) => {
87
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
88
- const docId = args.docId || "";
89
- const doc = await reactor.getDocument(driveId, docId);
90
- await reactor.addAction(driveId, docId, actions.setExportedData({ ...args.input }));
91
- return (doc?.header?.revision.global ?? 0) + 1;
104
+ const { docId, input } = args;
105
+ const doc = await reactor.getDocument(docId);
106
+ if (!doc) {
107
+ throw new Error("Document not found");
108
+ }
109
+ const result = await reactor.addAction(docId, actions.setExportedData(input));
110
+ if (result.status !== "SUCCESS") {
111
+ throw new Error(result.error?.message ?? "Failed to setExportedData");
112
+ }
113
+ return true;
92
114
  },
93
115
  Invoice_addPayment: async (_, args) => {
94
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
95
- const docId = args.docId || "";
96
- const doc = await reactor.getDocument(driveId, docId);
97
- await reactor.addAction(driveId, docId, actions.addPayment({ ...args.input }));
98
- return (doc?.header?.revision.global ?? 0) + 1;
116
+ const { docId, input } = args;
117
+ const doc = await reactor.getDocument(docId);
118
+ if (!doc) {
119
+ throw new Error("Document not found");
120
+ }
121
+ const result = await reactor.addAction(docId, actions.addPayment(input));
122
+ if (result.status !== "SUCCESS") {
123
+ throw new Error(result.error?.message ?? "Failed to addPayment");
124
+ }
125
+ return true;
99
126
  },
100
127
  Invoice_editIssuer: async (_, args) => {
101
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
102
- const docId = args.docId || "";
103
- const doc = await reactor.getDocument(driveId, docId);
104
- await reactor.addAction(driveId, docId, actions.editIssuer({ ...args.input }));
105
- return (doc?.header?.revision.global ?? 0) + 1;
128
+ const { docId, input } = args;
129
+ const doc = await reactor.getDocument(docId);
130
+ if (!doc) {
131
+ throw new Error("Document not found");
132
+ }
133
+ const result = await reactor.addAction(docId, actions.editIssuer(input));
134
+ if (result.status !== "SUCCESS") {
135
+ throw new Error(result.error?.message ?? "Failed to editIssuer");
136
+ }
137
+ return true;
106
138
  },
107
139
  Invoice_editIssuerBank: async (_, args) => {
108
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
109
- const docId = args.docId || "";
110
- const doc = await reactor.getDocument(driveId, docId);
111
- await reactor.addAction(driveId, docId, actions.editIssuerBank({ ...args.input }));
112
- return (doc?.header?.revision.global ?? 0) + 1;
140
+ const { docId, input } = args;
141
+ const doc = await reactor.getDocument(docId);
142
+ if (!doc) {
143
+ throw new Error("Document not found");
144
+ }
145
+ const result = await reactor.addAction(docId, actions.editIssuerBank(input));
146
+ if (result.status !== "SUCCESS") {
147
+ throw new Error(result.error?.message ?? "Failed to editIssuerBank");
148
+ }
149
+ return true;
113
150
  },
114
151
  Invoice_editIssuerWallet: async (_, args) => {
115
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
116
- const docId = args.docId || "";
117
- const doc = await reactor.getDocument(driveId, docId);
118
- await reactor.addAction(driveId, docId, actions.editIssuerWallet({ ...args.input }));
119
- return (doc?.header?.revision.global ?? 0) + 1;
152
+ const { docId, input } = args;
153
+ const doc = await reactor.getDocument(docId);
154
+ if (!doc) {
155
+ throw new Error("Document not found");
156
+ }
157
+ const result = await reactor.addAction(docId, actions.editIssuerWallet(input));
158
+ if (result.status !== "SUCCESS") {
159
+ throw new Error(result.error?.message ?? "Failed to editIssuerWallet");
160
+ }
161
+ return true;
120
162
  },
121
163
  Invoice_editPayer: async (_, args) => {
122
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
123
- const docId = args.docId || "";
124
- const doc = await reactor.getDocument(driveId, docId);
125
- await reactor.addAction(driveId, docId, actions.editPayer({ ...args.input }));
126
- return (doc?.header?.revision.global ?? 0) + 1;
164
+ const { docId, input } = args;
165
+ const doc = await reactor.getDocument(docId);
166
+ if (!doc) {
167
+ throw new Error("Document not found");
168
+ }
169
+ const result = await reactor.addAction(docId, actions.editPayer(input));
170
+ if (result.status !== "SUCCESS") {
171
+ throw new Error(result.error?.message ?? "Failed to editPayer");
172
+ }
173
+ return true;
127
174
  },
128
175
  Invoice_editPayerBank: async (_, args) => {
129
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
130
- const docId = args.docId || "";
131
- const doc = await reactor.getDocument(driveId, docId);
132
- await reactor.addAction(driveId, docId, actions.editPayerBank({ ...args.input }));
133
- return (doc?.header?.revision.global ?? 0) + 1;
176
+ const { docId, input } = args;
177
+ const doc = await reactor.getDocument(docId);
178
+ if (!doc) {
179
+ throw new Error("Document not found");
180
+ }
181
+ const result = await reactor.addAction(docId, actions.editPayerBank(input));
182
+ if (result.status !== "SUCCESS") {
183
+ throw new Error(result.error?.message ?? "Failed to editPayerBank");
184
+ }
185
+ return true;
134
186
  },
135
187
  Invoice_editPayerWallet: async (_, args) => {
136
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
137
- const docId = args.docId || "";
138
- const doc = await reactor.getDocument(driveId, docId);
139
- await reactor.addAction(driveId, docId, actions.editPayerWallet({ ...args.input }));
140
- return (doc?.header?.revision.global ?? 0) + 1;
188
+ const { docId, input } = args;
189
+ const doc = await reactor.getDocument(docId);
190
+ if (!doc) {
191
+ throw new Error("Document not found");
192
+ }
193
+ const result = await reactor.addAction(docId, actions.editPayerWallet(input));
194
+ if (result.status !== "SUCCESS") {
195
+ throw new Error(result.error?.message ?? "Failed to editPayerWallet");
196
+ }
197
+ return true;
141
198
  },
142
199
  Invoice_addLineItem: async (_, args) => {
143
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
144
- const docId = args.docId || "";
145
- const doc = await reactor.getDocument(driveId, docId);
146
- await reactor.addAction(driveId, docId, actions.addLineItem({ ...args.input }));
147
- return (doc?.header?.revision.global ?? 0) + 1;
200
+ const { docId, input } = args;
201
+ const doc = await reactor.getDocument(docId);
202
+ if (!doc) {
203
+ throw new Error("Document not found");
204
+ }
205
+ const result = await reactor.addAction(docId, actions.addLineItem(input));
206
+ if (result.status !== "SUCCESS") {
207
+ throw new Error(result.error?.message ?? "Failed to addLineItem");
208
+ }
209
+ return true;
148
210
  },
149
211
  Invoice_editLineItem: async (_, args) => {
150
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
151
- const docId = args.docId || "";
152
- const doc = await reactor.getDocument(driveId, docId);
153
- await reactor.addAction(driveId, docId, actions.editLineItem({ ...args.input }));
154
- return (doc?.header?.revision.global ?? 0) + 1;
212
+ const { docId, input } = args;
213
+ const doc = await reactor.getDocument(docId);
214
+ if (!doc) {
215
+ throw new Error("Document not found");
216
+ }
217
+ const result = await reactor.addAction(docId, actions.editLineItem(input));
218
+ if (result.status !== "SUCCESS") {
219
+ throw new Error(result.error?.message ?? "Failed to editLineItem");
220
+ }
221
+ return true;
155
222
  },
156
223
  Invoice_deleteLineItem: async (_, args) => {
157
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
158
- const docId = args.docId || "";
159
- const doc = await reactor.getDocument(driveId, docId);
160
- await reactor.addAction(driveId, docId, actions.deleteLineItem({ ...args.input }));
161
- return (doc?.header?.revision.global ?? 0) + 1;
224
+ const { docId, input } = args;
225
+ const doc = await reactor.getDocument(docId);
226
+ if (!doc) {
227
+ throw new Error("Document not found");
228
+ }
229
+ const result = await reactor.addAction(docId, actions.deleteLineItem(input));
230
+ if (result.status !== "SUCCESS") {
231
+ throw new Error(result.error?.message ?? "Failed to deleteLineItem");
232
+ }
233
+ return true;
162
234
  },
163
235
  Invoice_setLineItemTag: async (_, args) => {
164
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
165
- const docId = args.docId || "";
166
- const doc = await reactor.getDocument(driveId, docId);
167
- await reactor.addAction(driveId, docId, actions.setLineItemTag({ ...args.input }));
168
- return (doc?.header?.revision.global ?? 0) + 1;
236
+ const { docId, input } = args;
237
+ const doc = await reactor.getDocument(docId);
238
+ if (!doc) {
239
+ throw new Error("Document not found");
240
+ }
241
+ const result = await reactor.addAction(docId, actions.setLineItemTag(input));
242
+ if (result.status !== "SUCCESS") {
243
+ throw new Error(result.error?.message ?? "Failed to setLineItemTag");
244
+ }
245
+ return true;
169
246
  },
170
247
  Invoice_setInvoiceTag: async (_, args) => {
171
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
172
- const docId = args.docId || "";
173
- const doc = await reactor.getDocument(driveId, docId);
174
- await reactor.addAction(driveId, docId, actions.setInvoiceTag({ ...args.input }));
175
- return (doc?.header?.revision.global ?? 0) + 1;
248
+ const { docId, input } = args;
249
+ const doc = await reactor.getDocument(docId);
250
+ if (!doc) {
251
+ throw new Error("Document not found");
252
+ }
253
+ const result = await reactor.addAction(docId, actions.setInvoiceTag(input));
254
+ if (result.status !== "SUCCESS") {
255
+ throw new Error(result.error?.message ?? "Failed to setInvoiceTag");
256
+ }
257
+ return true;
176
258
  },
177
259
  Invoice_cancel: async (_, args) => {
178
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
179
- const docId = args.docId || "";
180
- const doc = await reactor.getDocument(driveId, docId);
181
- await reactor.addAction(driveId, docId, actions.cancel({ ...args.input }));
182
- return (doc?.header?.revision.global ?? 0) + 1;
260
+ const { docId, input } = args;
261
+ const doc = await reactor.getDocument(docId);
262
+ if (!doc) {
263
+ throw new Error("Document not found");
264
+ }
265
+ const result = await reactor.addAction(docId, actions.cancel(input));
266
+ if (result.status !== "SUCCESS") {
267
+ throw new Error(result.error?.message ?? "Failed to cancel");
268
+ }
269
+ return true;
183
270
  },
184
271
  Invoice_issue: async (_, args) => {
185
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
186
- const docId = args.docId || "";
187
- const doc = await reactor.getDocument(driveId, docId);
188
- await reactor.addAction(driveId, docId, actions.issue({ ...args.input }));
189
- return (doc?.header?.revision.global ?? 0) + 1;
272
+ const { docId, input } = args;
273
+ const doc = await reactor.getDocument(docId);
274
+ if (!doc) {
275
+ throw new Error("Document not found");
276
+ }
277
+ const result = await reactor.addAction(docId, actions.issue(input));
278
+ if (result.status !== "SUCCESS") {
279
+ throw new Error(result.error?.message ?? "Failed to issue");
280
+ }
281
+ return true;
190
282
  },
191
283
  Invoice_reset: async (_, args) => {
192
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
193
- const docId = args.docId || "";
194
- const doc = await reactor.getDocument(driveId, docId);
195
- await reactor.addAction(driveId, docId, actions.reset({ ...args.input }));
196
- return (doc?.header?.revision.global ?? 0) + 1;
284
+ const { docId, input } = args;
285
+ const doc = await reactor.getDocument(docId);
286
+ if (!doc) {
287
+ throw new Error("Document not found");
288
+ }
289
+ const result = await reactor.addAction(docId, actions.reset(input));
290
+ if (result.status !== "SUCCESS") {
291
+ throw new Error(result.error?.message ?? "Failed to reset");
292
+ }
293
+ return true;
197
294
  },
198
295
  Invoice_reject: async (_, args) => {
199
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
200
- const docId = args.docId || "";
201
- const doc = await reactor.getDocument(driveId, docId);
202
- await reactor.addAction(driveId, docId, actions.reject({ ...args.input }));
203
- return (doc?.header?.revision.global ?? 0) + 1;
296
+ const { docId, input } = args;
297
+ const doc = await reactor.getDocument(docId);
298
+ if (!doc) {
299
+ throw new Error("Document not found");
300
+ }
301
+ const result = await reactor.addAction(docId, actions.reject(input));
302
+ if (result.status !== "SUCCESS") {
303
+ throw new Error(result.error?.message ?? "Failed to reject");
304
+ }
305
+ return true;
204
306
  },
205
307
  Invoice_accept: async (_, args) => {
206
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
207
- const docId = args.docId || "";
208
- const doc = await reactor.getDocument(driveId, docId);
209
- await reactor.addAction(driveId, docId, actions.accept({ ...args.input }));
210
- return (doc?.header?.revision.global ?? 0) + 1;
308
+ const { docId, input } = args;
309
+ const doc = await reactor.getDocument(docId);
310
+ if (!doc) {
311
+ throw new Error("Document not found");
312
+ }
313
+ const result = await reactor.addAction(docId, actions.accept(input));
314
+ if (result.status !== "SUCCESS") {
315
+ throw new Error(result.error?.message ?? "Failed to accept");
316
+ }
317
+ return true;
211
318
  },
212
319
  Invoice_reinstate: async (_, args) => {
213
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
214
- const docId = args.docId || "";
215
- const doc = await reactor.getDocument(driveId, docId);
216
- await reactor.addAction(driveId, docId, actions.reinstate({ ...args.input }));
217
- return (doc?.header?.revision.global ?? 0) + 1;
320
+ const { docId, input } = args;
321
+ const doc = await reactor.getDocument(docId);
322
+ if (!doc) {
323
+ throw new Error("Document not found");
324
+ }
325
+ const result = await reactor.addAction(docId, actions.reinstate(input));
326
+ if (result.status !== "SUCCESS") {
327
+ throw new Error(result.error?.message ?? "Failed to reinstate");
328
+ }
329
+ return true;
218
330
  },
219
331
  Invoice_schedulePayment: async (_, args) => {
220
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
221
- const docId = args.docId || "";
222
- const doc = await reactor.getDocument(driveId, docId);
223
- await reactor.addAction(driveId, docId, actions.schedulePayment({ ...args.input }));
224
- return (doc?.header?.revision.global ?? 0) + 1;
332
+ const { docId, input } = args;
333
+ const doc = await reactor.getDocument(docId);
334
+ if (!doc) {
335
+ throw new Error("Document not found");
336
+ }
337
+ const result = await reactor.addAction(docId, actions.schedulePayment(input));
338
+ if (result.status !== "SUCCESS") {
339
+ throw new Error(result.error?.message ?? "Failed to schedulePayment");
340
+ }
341
+ return true;
225
342
  },
226
343
  Invoice_reapprovePayment: async (_, args) => {
227
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
228
- const docId = args.docId || "";
229
- const doc = await reactor.getDocument(driveId, docId);
230
- await reactor.addAction(driveId, docId, actions.reapprovePayment({ ...args.input }));
231
- return (doc?.header?.revision.global ?? 0) + 1;
344
+ const { docId, input } = args;
345
+ const doc = await reactor.getDocument(docId);
346
+ if (!doc) {
347
+ throw new Error("Document not found");
348
+ }
349
+ const result = await reactor.addAction(docId, actions.reapprovePayment(input));
350
+ if (result.status !== "SUCCESS") {
351
+ throw new Error(result.error?.message ?? "Failed to reapprovePayment");
352
+ }
353
+ return true;
232
354
  },
233
355
  Invoice_registerPaymentTx: async (_, args) => {
234
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
235
- const docId = args.docId || "";
236
- const doc = await reactor.getDocument(driveId, docId);
237
- await reactor.addAction(driveId, docId, actions.registerPaymentTx({ ...args.input }));
238
- return (doc?.header?.revision.global ?? 0) + 1;
356
+ const { docId, input } = args;
357
+ const doc = await reactor.getDocument(docId);
358
+ if (!doc) {
359
+ throw new Error("Document not found");
360
+ }
361
+ const result = await reactor.addAction(docId, actions.registerPaymentTx(input));
362
+ if (result.status !== "SUCCESS") {
363
+ throw new Error(result.error?.message ?? "Failed to registerPaymentTx");
364
+ }
365
+ return true;
239
366
  },
240
367
  Invoice_reportPaymentIssue: async (_, args) => {
241
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
242
- const docId = args.docId || "";
243
- const doc = await reactor.getDocument(driveId, docId);
244
- await reactor.addAction(driveId, docId, actions.reportPaymentIssue({ ...args.input }));
245
- return (doc?.header?.revision.global ?? 0) + 1;
368
+ const { docId, input } = args;
369
+ const doc = await reactor.getDocument(docId);
370
+ if (!doc) {
371
+ throw new Error("Document not found");
372
+ }
373
+ const result = await reactor.addAction(docId, actions.reportPaymentIssue(input));
374
+ if (result.status !== "SUCCESS") {
375
+ throw new Error(result.error?.message ?? "Failed to reportPaymentIssue");
376
+ }
377
+ return true;
246
378
  },
247
379
  Invoice_confirmPayment: async (_, args) => {
248
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
249
- const docId = args.docId || "";
250
- const doc = await reactor.getDocument(driveId, docId);
251
- await reactor.addAction(driveId, docId, actions.confirmPayment({ ...args.input }));
252
- return (doc?.header?.revision.global ?? 0) + 1;
380
+ const { docId, input } = args;
381
+ const doc = await reactor.getDocument(docId);
382
+ if (!doc) {
383
+ throw new Error("Document not found");
384
+ }
385
+ const result = await reactor.addAction(docId, actions.confirmPayment(input));
386
+ if (result.status !== "SUCCESS") {
387
+ throw new Error(result.error?.message ?? "Failed to confirmPayment");
388
+ }
389
+ return true;
253
390
  },
254
391
  Invoice_closePayment: async (_, args) => {
255
- const driveId = args.driveId || DEFAULT_DRIVE_ID;
256
- const docId = args.docId || "";
257
- const doc = await reactor.getDocument(driveId, docId);
258
- await reactor.addAction(driveId, docId, actions.closePayment({ ...args.input }));
259
- return (doc?.header?.revision.global ?? 0) + 1;
392
+ const { docId, input } = args;
393
+ const doc = await reactor.getDocument(docId);
394
+ if (!doc) {
395
+ throw new Error("Document not found");
396
+ }
397
+ const result = await reactor.addAction(docId, actions.closePayment(input));
398
+ if (result.status !== "SUCCESS") {
399
+ throw new Error(result.error?.message ?? "Failed to closePayment");
400
+ }
401
+ return true;
260
402
  },
261
- Invoice_processGnosisPayment,
262
- Invoice_createRequestFinancePayment,
263
- Invoice_uploadInvoicePdfChunk,
403
+ Invoice_processGnosisPayment: Invoice_processGnosisPayment,
404
+ Invoice_createRequestFinancePayment: Invoice_createRequestFinancePayment,
405
+ Invoice_uploadInvoicePdfChunk: Invoice_uploadInvoicePdfChunk,
264
406
  },
265
407
  };
266
408
  };
@@ -179,8 +179,8 @@ export const schema = gql `
179
179
  Queries: Invoice
180
180
  """
181
181
  type InvoiceQueries {
182
- getDocument(driveId: String, docId: PHID): Invoice
183
- getDocuments: [Invoice!]
182
+ getDocument(docId: PHID!, driveId: PHID): Invoice
183
+ getDocuments(driveId: String!): [Invoice!]
184
184
  }
185
185
 
186
186
  type Query {
@@ -191,7 +191,7 @@ export const schema = gql `
191
191
  Mutations: Invoice
192
192
  """
193
193
  type Mutation {
194
- Invoice_createDocument(driveId: String, name: String): String
194
+ Invoice_createDocument(name: String!, driveId: String): String
195
195
 
196
196
  Invoice_editInvoice(
197
197
  driveId: String