@powerhousedao/contributor-billing 0.1.53 → 1.0.0-dev.3

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 (125) hide show
  1. package/dist/document-models/account-transactions/gen/schema/zod.d.ts.map +1 -1
  2. package/dist/document-models/account-transactions/gen/schema/zod.js +3 -3
  3. package/dist/document-models/account-transactions/module.d.ts +1 -1
  4. package/dist/document-models/account-transactions/module.d.ts.map +1 -1
  5. package/dist/document-models/account-transactions/module.js +1 -1
  6. package/dist/document-models/accounts/gen/schema/zod.d.ts.map +1 -1
  7. package/dist/document-models/accounts/module.d.ts +1 -1
  8. package/dist/document-models/accounts/module.d.ts.map +1 -1
  9. package/dist/document-models/accounts/module.js +1 -1
  10. package/dist/document-models/billing-statement/gen/schema/zod.d.ts.map +1 -1
  11. package/dist/document-models/billing-statement/gen/schema/zod.js +4 -4
  12. package/dist/document-models/billing-statement/module.d.ts +1 -1
  13. package/dist/document-models/billing-statement/module.d.ts.map +1 -1
  14. package/dist/document-models/billing-statement/module.js +1 -1
  15. package/dist/document-models/expense-report/gen/schema/zod.d.ts.map +1 -1
  16. package/dist/document-models/expense-report/gen/schema/zod.js +38 -18
  17. package/dist/document-models/expense-report/module.d.ts +1 -1
  18. package/dist/document-models/expense-report/module.d.ts.map +1 -1
  19. package/dist/document-models/expense-report/module.js +1 -1
  20. package/dist/document-models/invoice/gen/document-model.d.ts.map +1 -1
  21. package/dist/document-models/invoice/gen/document-model.js +150 -150
  22. package/dist/document-models/invoice/gen/schema/types.d.ts +3 -6
  23. package/dist/document-models/invoice/gen/schema/types.d.ts.map +1 -1
  24. package/dist/document-models/invoice/gen/schema/zod.d.ts +2 -8
  25. package/dist/document-models/invoice/gen/schema/zod.d.ts.map +1 -1
  26. package/dist/document-models/invoice/gen/schema/zod.js +14 -25
  27. package/dist/document-models/invoice/module.d.ts +1 -1
  28. package/dist/document-models/invoice/module.d.ts.map +1 -1
  29. package/dist/document-models/invoice/module.js +1 -1
  30. package/dist/document-models/invoice/src/reducers/items.d.ts.map +1 -1
  31. package/dist/document-models/invoice/src/reducers/items.js +2 -1
  32. package/dist/document-models/invoice/src/reducers/parties.d.ts.map +1 -1
  33. package/dist/document-models/invoice/src/reducers/parties.js +6 -2
  34. package/dist/document-models/invoice/src/reducers/transitions.d.ts +0 -5
  35. package/dist/document-models/invoice/src/reducers/transitions.d.ts.map +1 -1
  36. package/dist/document-models/invoice/src/reducers/transitions.js +12 -6
  37. package/dist/document-models/invoice/tests/general.test.js +1 -1
  38. package/dist/document-models/invoice/tests/items.test.js +1 -1
  39. package/dist/document-models/invoice/tests/parties.test.js +1 -1
  40. package/dist/document-models/invoice/tests/transitions.test.js +1 -1
  41. package/dist/document-models/operational-hub-profile/module.d.ts +1 -1
  42. package/dist/document-models/operational-hub-profile/module.d.ts.map +1 -1
  43. package/dist/document-models/operational-hub-profile/module.js +1 -1
  44. package/dist/document-models/snapshot-report/gen/schema/zod.d.ts.map +1 -1
  45. package/dist/document-models/snapshot-report/gen/schema/zod.js +12 -12
  46. package/dist/document-models/snapshot-report/module.d.ts +1 -1
  47. package/dist/document-models/snapshot-report/module.d.ts.map +1 -1
  48. package/dist/document-models/snapshot-report/module.js +1 -1
  49. package/dist/editors/accounts-editor/editor.d.ts.map +1 -1
  50. package/dist/editors/accounts-editor/editor.js +2 -2
  51. package/dist/editors/contributor-billing/components/DocumentDropZone.d.ts.map +1 -1
  52. package/dist/editors/contributor-billing/components/DocumentDropZone.js +37 -8
  53. package/dist/editors/contributor-billing/components/DriveContents.d.ts.map +1 -1
  54. package/dist/editors/contributor-billing/components/DriveContents.js +4 -1
  55. package/dist/editors/contributor-billing/components/DriveExplorer.d.ts.map +1 -1
  56. package/dist/editors/contributor-billing/components/DriveExplorer.js +2 -2
  57. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts +2 -1
  58. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts.map +1 -1
  59. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.js +41 -6
  60. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts +1 -1
  61. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts.map +1 -1
  62. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.js +16 -1
  63. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableContainer.d.ts +3 -1
  64. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableContainer.d.ts.map +1 -1
  65. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableContainer.js +13 -11
  66. package/dist/editors/contributor-billing/components/ToastRenderer.d.ts +2 -0
  67. package/dist/editors/contributor-billing/components/ToastRenderer.d.ts.map +1 -0
  68. package/dist/editors/contributor-billing/components/ToastRenderer.js +14 -0
  69. package/dist/editors/contributor-billing/components/cbToast.d.ts +16 -0
  70. package/dist/editors/contributor-billing/components/cbToast.d.ts.map +1 -0
  71. package/dist/editors/contributor-billing/components/cbToast.js +29 -0
  72. package/dist/editors/invoice/InvoicePDF.d.ts.map +1 -1
  73. package/dist/editors/invoice/InvoicePDF.js +12 -9
  74. package/dist/editors/invoice/editor.d.ts.map +1 -1
  75. package/dist/editors/invoice/editor.js +3 -8
  76. package/dist/editors/invoice/exportUBL.d.ts.map +1 -1
  77. package/dist/editors/invoice/exportUBL.js +1 -2
  78. package/dist/editors/invoice/ingestPDF.js +1 -1
  79. package/dist/editors/invoice/invoiceToGnosis.d.ts.map +1 -1
  80. package/dist/editors/invoice/invoiceToGnosis.js +25 -22
  81. package/dist/editors/invoice/invoiceToast.d.ts +4 -0
  82. package/dist/editors/invoice/invoiceToast.d.ts.map +1 -0
  83. package/dist/editors/invoice/invoiceToast.js +6 -0
  84. package/dist/editors/invoice/legalEntity/legalEntity.d.ts.map +1 -1
  85. package/dist/editors/invoice/legalEntity/legalEntity.js +1 -12
  86. package/dist/editors/invoice/lineItems.js +1 -1
  87. package/dist/editors/invoice/requestFinance.d.ts +3 -2
  88. package/dist/editors/invoice/requestFinance.d.ts.map +1 -1
  89. package/dist/editors/invoice/requestFinance.js +38 -42
  90. package/dist/editors/invoice/validation/validationHandler.js +1 -1
  91. package/dist/scripts/download-all-drive-documents/download-drive-documents.d.ts +33 -0
  92. package/dist/scripts/download-all-drive-documents/download-drive-documents.d.ts.map +1 -0
  93. package/dist/scripts/download-all-drive-documents/download-drive-documents.js +583 -0
  94. package/dist/scripts/invoice/requestFinance.d.ts +18 -1
  95. package/dist/scripts/invoice/requestFinance.d.ts.map +1 -1
  96. package/dist/scripts/invoice/requestFinance.js +17 -5
  97. package/dist/scripts/upload-phd-documents/upload-phd-documents.d.ts +20 -0
  98. package/dist/scripts/upload-phd-documents/upload-phd-documents.d.ts.map +1 -0
  99. package/dist/scripts/upload-phd-documents/upload-phd-documents.js +313 -0
  100. package/dist/style.css +21 -0
  101. package/dist/subgraphs/invoice-addon/customResolvers.d.ts +70 -11
  102. package/dist/subgraphs/invoice-addon/customResolvers.d.ts.map +1 -1
  103. package/dist/subgraphs/invoice-addon/customResolvers.js +12 -27
  104. package/package.json +33 -26
  105. package/dist/document-models/invoice/src/tests/document-model.test.d.ts +0 -10
  106. package/dist/document-models/invoice/src/tests/document-model.test.d.ts.map +0 -1
  107. package/dist/document-models/invoice/src/tests/document-model.test.js +0 -104
  108. package/dist/document-models/invoice/src/tests/general.test.d.ts +0 -6
  109. package/dist/document-models/invoice/src/tests/general.test.d.ts.map +0 -1
  110. package/dist/document-models/invoice/src/tests/general.test.js +0 -49
  111. package/dist/document-models/invoice/src/tests/items.test.d.ts +0 -6
  112. package/dist/document-models/invoice/src/tests/items.test.d.ts.map +0 -1
  113. package/dist/document-models/invoice/src/tests/items.test.js +0 -59
  114. package/dist/document-models/invoice/src/tests/parties.test.d.ts +0 -6
  115. package/dist/document-models/invoice/src/tests/parties.test.d.ts.map +0 -1
  116. package/dist/document-models/invoice/src/tests/parties.test.js +0 -69
  117. package/dist/document-models/invoice/src/tests/transitions.test.d.ts +0 -6
  118. package/dist/document-models/invoice/src/tests/transitions.test.d.ts.map +0 -1
  119. package/dist/document-models/invoice/src/tests/transitions.test.js +0 -59
  120. package/dist/document-models/invoice/utils/statusTransitions.d.ts +0 -13
  121. package/dist/document-models/invoice/utils/statusTransitions.d.ts.map +0 -1
  122. package/dist/document-models/invoice/utils/statusTransitions.js +0 -13
  123. package/dist/editors/builder-team-admin/components/overview/SubscriptionsStats.d.ts +0 -15
  124. package/dist/editors/builder-team-admin/components/overview/SubscriptionsStats.d.ts.map +0 -1
  125. package/dist/editors/builder-team-admin/components/overview/SubscriptionsStats.js +0 -61
@@ -0,0 +1,313 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Upload local .phd documents to a Powerhouse switchboard.
4
+ *
5
+ * Works with ANY document type — reads header.json and operations.json from
6
+ * the .phd file, auto-detects the document type, creates a new document via
7
+ * the matching _createDocument mutation, then replays all operations via
8
+ * pushUpdates on the drive endpoint.
9
+ *
10
+ * REQUIRES: Bun runtime (https://bun.sh)
11
+ *
12
+ * Usage:
13
+ * bun scripts/upload-phd-documents/upload-phd-documents.ts <switchboard-url> <drive-id> <file.phd> [file2.phd ...]
14
+ *
15
+ * Examples:
16
+ * bun scripts/upload-phd-documents/upload-phd-documents.ts http://localhost:4001 preview-f80015b9 "op hub.phd" "oh service.phd"
17
+ * bun scripts/upload-phd-documents/upload-phd-documents.ts http://localhost:4001 preview-f80015b9 invoice.phd
18
+ */
19
+ import { inflateRawSync } from "node:zlib";
20
+ import fs from "node:fs";
21
+ // ---------------------------------------------------------------------------
22
+ // ZIP reader (from download script)
23
+ // ---------------------------------------------------------------------------
24
+ function readZipEntry(zipBuf, entryName) {
25
+ let offset = 0;
26
+ while (offset + 30 <= zipBuf.length) {
27
+ const sig = zipBuf.readUInt32LE(offset);
28
+ if (sig !== 0x04034b50)
29
+ break;
30
+ const compressionMethod = zipBuf.readUInt16LE(offset + 8);
31
+ const compressedSize = zipBuf.readUInt32LE(offset + 18);
32
+ const nameLen = zipBuf.readUInt16LE(offset + 26);
33
+ const extraLen = zipBuf.readUInt16LE(offset + 28);
34
+ const nameStart = offset + 30;
35
+ const name = zipBuf
36
+ .subarray(nameStart, nameStart + nameLen)
37
+ .toString("utf-8");
38
+ const dataStart = nameStart + nameLen + extraLen;
39
+ const dataEnd = dataStart + compressedSize;
40
+ if (name === entryName) {
41
+ const raw = zipBuf.subarray(dataStart, dataEnd);
42
+ if (compressionMethod === 8) {
43
+ return Buffer.from(inflateRawSync(raw));
44
+ }
45
+ return Buffer.from(raw);
46
+ }
47
+ offset = dataEnd;
48
+ }
49
+ return null;
50
+ }
51
+ function readPhdJson(filePath, entryName) {
52
+ const zipBuf = fs.readFileSync(filePath);
53
+ const buf = readZipEntry(zipBuf, entryName);
54
+ if (!buf)
55
+ throw new Error(`${entryName} not found in ${filePath}`);
56
+ return JSON.parse(buf.toString("utf-8"));
57
+ }
58
+ // ---------------------------------------------------------------------------
59
+ // GraphQL helper
60
+ // ---------------------------------------------------------------------------
61
+ const REQUEST_DELAY_MS = 200;
62
+ const PUSH_BATCH_SIZE = 50;
63
+ function sleep(ms) {
64
+ return new Promise((resolve) => setTimeout(resolve, ms));
65
+ }
66
+ async function gql(endpoint, query, variables) {
67
+ const res = await fetch(endpoint, {
68
+ method: "POST",
69
+ headers: { "Content-Type": "application/json" },
70
+ body: JSON.stringify({ query, variables }),
71
+ });
72
+ if (!res.ok) {
73
+ const body = await res.text().catch(() => "");
74
+ throw new Error(`GraphQL ${res.status}: ${body.slice(0, 500)}`);
75
+ }
76
+ const json = (await res.json());
77
+ if (json.errors?.length) {
78
+ throw new Error(`GraphQL errors:\n${json.errors.map((e) => ` - ${e.message}`).join("\n")}`);
79
+ }
80
+ if (!json.data)
81
+ throw new Error("No data returned from GraphQL");
82
+ return json.data;
83
+ }
84
+ // ---------------------------------------------------------------------------
85
+ // Document type -> mutation prefix mapping
86
+ // ---------------------------------------------------------------------------
87
+ /**
88
+ * Discover available _createDocument mutations by introspecting the API.
89
+ * Returns a map of documentType -> mutation prefix.
90
+ * e.g. "powerhouse/resource-template" -> "ResourceTemplate"
91
+ */
92
+ async function discoverDocumentTypes(endpoint) {
93
+ const data = await gql(endpoint, `{ __schema { mutationType { fields { name } } } }`);
94
+ const map = new Map();
95
+ for (const field of data.__schema.mutationType.fields) {
96
+ if (!field.name.endsWith("_createDocument"))
97
+ continue;
98
+ const prefix = field.name.replace("_createDocument", "");
99
+ // Convert PascalCase prefix to kebab-case document type
100
+ const kebab = prefix.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
101
+ const docType = `powerhouse/${kebab}`;
102
+ map.set(docType, prefix);
103
+ }
104
+ return map;
105
+ }
106
+ // ---------------------------------------------------------------------------
107
+ // Create document via type-specific _createDocument mutation
108
+ // ---------------------------------------------------------------------------
109
+ async function createDocument(endpoint, driveId, mutationPrefix, name) {
110
+ const mutationName = `${mutationPrefix}_createDocument`;
111
+ const data = await gql(endpoint, `mutation ($name: String!, $driveId: String) {
112
+ ${mutationName}(name: $name, driveId: $driveId)
113
+ }`, { name, driveId });
114
+ return data[mutationName];
115
+ }
116
+ // ---------------------------------------------------------------------------
117
+ // Push operations via pushUpdates on the drive endpoint
118
+ // ---------------------------------------------------------------------------
119
+ async function pushOperations(driveEndpoint, driveId, docId, documentType, operations) {
120
+ let totalPushed = 0;
121
+ for (const scope of ["global", "local"]) {
122
+ const scopeOps = operations[scope];
123
+ if (!scopeOps?.length)
124
+ continue;
125
+ console.log(` Pushing ${scopeOps.length} ${scope} operations...`);
126
+ for (let i = 0; i < scopeOps.length; i += PUSH_BATCH_SIZE) {
127
+ const batch = scopeOps.slice(i, i + PUSH_BATCH_SIZE);
128
+ const inputOps = batch.map((op) => ({
129
+ index: op.index,
130
+ skip: op.skip,
131
+ type: op.action.type,
132
+ id: op.id,
133
+ actionId: op.action.id || op.id,
134
+ input: JSON.stringify(op.action.input),
135
+ hash: op.hash,
136
+ timestampUtcMs: op.timestampUtcMs,
137
+ error: op.error ?? null,
138
+ }));
139
+ const strand = {
140
+ driveId,
141
+ documentId: docId,
142
+ documentType,
143
+ scope,
144
+ branch: "main",
145
+ operations: inputOps,
146
+ };
147
+ if (i > 0)
148
+ await sleep(REQUEST_DELAY_MS);
149
+ const result = await gql(driveEndpoint, `mutation ($strands: [InputStrandUpdate!]) {
150
+ pushUpdates(strands: $strands) { revision status error }
151
+ }`, { strands: [strand] });
152
+ const update = result.pushUpdates[0];
153
+ if (update.status !== "SUCCESS") {
154
+ throw new Error(`pushUpdates failed at batch ${Math.floor(i / PUSH_BATCH_SIZE) + 1}: ` +
155
+ `status=${update.status}, error=${update.error}`);
156
+ }
157
+ totalPushed += batch.length;
158
+ const batchNum = Math.floor(i / PUSH_BATCH_SIZE) + 1;
159
+ const totalBatches = Math.ceil(scopeOps.length / PUSH_BATCH_SIZE);
160
+ console.log(` [${batchNum}/${totalBatches}] ${batch.length} ops -> revision ${update.revision}`);
161
+ }
162
+ }
163
+ return totalPushed;
164
+ }
165
+ // ---------------------------------------------------------------------------
166
+ // State verification
167
+ // ---------------------------------------------------------------------------
168
+ async function verifyState(driveEndpoint, docId, expectedGlobal) {
169
+ const data = await gql(driveEndpoint, `query ($id: String!) { document(id: $id) { stateJSON } }`, { id: docId });
170
+ const actual = data.document.stateJSON;
171
+ const expectedStr = JSON.stringify(expectedGlobal, Object.keys(expectedGlobal).sort());
172
+ const actualStr = JSON.stringify(actual, Object.keys(actual).sort());
173
+ if (expectedStr === actualStr)
174
+ return true;
175
+ // Count differences for reporting
176
+ const allKeys = new Set([
177
+ ...Object.keys(expectedGlobal),
178
+ ...Object.keys(actual),
179
+ ]);
180
+ let diffs = 0;
181
+ for (const key of allKeys) {
182
+ const ev = JSON.stringify(expectedGlobal[key], null, 0);
183
+ const av = JSON.stringify(actual[key], null, 0);
184
+ if (ev !== av) {
185
+ diffs++;
186
+ if (diffs <= 5) {
187
+ const evShort = (ev || "undefined").slice(0, 60);
188
+ const avShort = (av || "undefined").slice(0, 60);
189
+ console.log(` DIFF: ${key}: expected=${evShort} actual=${avShort}`);
190
+ }
191
+ }
192
+ }
193
+ if (diffs > 5) {
194
+ console.log(` ... and ${diffs - 5} more differences`);
195
+ }
196
+ return false;
197
+ }
198
+ // ---------------------------------------------------------------------------
199
+ // Upload a single .phd file
200
+ // ---------------------------------------------------------------------------
201
+ async function uploadPhdFile(baseUrl, driveId, filePath, typeMap) {
202
+ const endpoint = `${baseUrl}/graphql`;
203
+ const driveEndpoint = `${baseUrl}/d/${driveId}`;
204
+ // 1. Read .phd contents
205
+ const header = readPhdJson(filePath, "header.json");
206
+ const operations = readPhdJson(filePath, "operations.json");
207
+ const currentState = readPhdJson(filePath, "current-state.json");
208
+ const docType = header.documentType;
209
+ const docName = header.name || filePath.replace(/^.*\//, "").replace(/\.phd$/, "");
210
+ const globalOpsCount = operations.global?.length ?? 0;
211
+ const localOpsCount = operations.local?.length ?? 0;
212
+ console.log(`\n${"─".repeat(60)}`);
213
+ console.log(` File: ${filePath}`);
214
+ console.log(` Type: ${docType}`);
215
+ console.log(` Name: ${docName || "(unnamed)"}`);
216
+ console.log(` Ops: ${globalOpsCount} global, ${localOpsCount} local`);
217
+ // 2. Find the matching _createDocument mutation
218
+ const mutationPrefix = typeMap.get(docType);
219
+ if (!mutationPrefix) {
220
+ throw new Error(`No _createDocument mutation found for type "${docType}". ` +
221
+ `Available types: ${[...typeMap.keys()].join(", ")}`);
222
+ }
223
+ // 3. Create the document
224
+ console.log(` Creating ${mutationPrefix} document...`);
225
+ const docId = await createDocument(endpoint, driveId, mutationPrefix, docName || "Untitled");
226
+ console.log(` Created: ${docId}`);
227
+ // 4. Push operations
228
+ let totalPushed = 0;
229
+ if (globalOpsCount + localOpsCount > 0) {
230
+ await sleep(REQUEST_DELAY_MS);
231
+ totalPushed = await pushOperations(driveEndpoint, driveId, docId, docType, operations);
232
+ console.log(` Pushed: ${totalPushed} operations`);
233
+ }
234
+ else {
235
+ console.log(` No operations to push`);
236
+ }
237
+ // 5. Verify state
238
+ await sleep(REQUEST_DELAY_MS);
239
+ console.log(` Verifying state...`);
240
+ const stateMatch = await verifyState(driveEndpoint, docId, currentState.global);
241
+ if (stateMatch) {
242
+ console.log(` State: EXACT MATCH`);
243
+ }
244
+ else {
245
+ console.log(` State: MISMATCH (see diffs above — may be expected with schema changes)`);
246
+ }
247
+ return {
248
+ file: filePath,
249
+ documentType: docType,
250
+ docId,
251
+ name: docName,
252
+ operationsPushed: totalPushed,
253
+ stateMatch,
254
+ };
255
+ }
256
+ // ---------------------------------------------------------------------------
257
+ // Main
258
+ // ---------------------------------------------------------------------------
259
+ async function main() {
260
+ const args = process.argv.slice(2);
261
+ if (args.length < 3) {
262
+ console.log("Usage: bun scripts/upload-phd-documents/upload-phd-documents.ts <switchboard-url> <drive-id> <file.phd> [file2.phd ...]");
263
+ console.log("\nExamples:" +
264
+ '\n bun scripts/upload-phd-documents/upload-phd-documents.ts http://localhost:4001 preview-f80015b9 "op hub.phd" "oh service.phd"' +
265
+ "\n bun scripts/upload-phd-documents/upload-phd-documents.ts http://localhost:4001 preview-f80015b9 invoice.phd");
266
+ process.exit(1);
267
+ }
268
+ const [rawBaseUrl, driveId, ...phdFiles] = args;
269
+ const baseUrl = rawBaseUrl.replace(/\/+$/, "").replace(/\/graphql$/i, "");
270
+ console.log(`Switchboard: ${baseUrl}`);
271
+ console.log(`Drive: ${driveId}`);
272
+ console.log(`Files: ${phdFiles.length}`);
273
+ // Discover available document types from the API
274
+ console.log(`\nDiscovering document types...`);
275
+ const typeMap = await discoverDocumentTypes(`${baseUrl}/graphql`);
276
+ console.log(` Found ${typeMap.size} types: ${[...typeMap.keys()].join(", ")}`);
277
+ // Upload each .phd file
278
+ const results = [];
279
+ const failures = [];
280
+ for (const file of phdFiles) {
281
+ try {
282
+ const result = await uploadPhdFile(baseUrl, driveId, file, typeMap);
283
+ results.push(result);
284
+ }
285
+ catch (err) {
286
+ const reason = err instanceof Error ? err.message : String(err);
287
+ console.error(`\n FAILED: ${file}`);
288
+ console.error(` Reason: ${reason}`);
289
+ failures.push({ file, reason });
290
+ }
291
+ }
292
+ // Summary
293
+ console.log(`\n${"=".repeat(60)}`);
294
+ console.log(`DONE`);
295
+ console.log(`${"=".repeat(60)}`);
296
+ console.log(` Drive: ${driveId}`);
297
+ console.log(` Uploaded: ${results.length}`);
298
+ console.log(` Failed: ${failures.length}`);
299
+ for (const r of results) {
300
+ const stateIcon = r.stateMatch ? "OK" : "~";
301
+ console.log(` [${stateIcon}] ${r.name || r.file} (${r.documentType}) -> ${r.docId} (${r.operationsPushed} ops)`);
302
+ }
303
+ for (const f of failures) {
304
+ console.log(` [X] ${f.file}: ${f.reason}`);
305
+ }
306
+ if (failures.length > 0) {
307
+ process.exit(1);
308
+ }
309
+ }
310
+ main().catch((err) => {
311
+ console.error(err);
312
+ process.exit(1);
313
+ });
package/dist/style.css CHANGED
@@ -124,6 +124,7 @@
124
124
  --color-white: hsl(0 0% 100%);
125
125
  --spacing: 0.25rem;
126
126
  --container-xs: 20rem;
127
+ --container-sm: 24rem;
127
128
  --container-md: 28rem;
128
129
  --container-lg: 32rem;
129
130
  --container-2xl: 42rem;
@@ -764,6 +765,9 @@
764
765
  .max-w-none {
765
766
  max-width: none;
766
767
  }
768
+ .max-w-sm {
769
+ max-width: var(--container-sm);
770
+ }
767
771
  .max-w-xs {
768
772
  max-width: var(--container-xs);
769
773
  }
@@ -835,6 +839,9 @@
835
839
  .transform {
836
840
  transform: var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,);
837
841
  }
842
+ .animate-\[slideIn_0\.2s_ease-out\] {
843
+ animation: slideIn 0.2s ease-out;
844
+ }
838
845
  .animate-pulse {
839
846
  animation: var(--animate-pulse);
840
847
  }
@@ -1699,6 +1706,10 @@
1699
1706
  .text-\[11px\] {
1700
1707
  font-size: 11px;
1701
1708
  }
1709
+ .leading-none {
1710
+ --tw-leading: 1;
1711
+ line-height: 1;
1712
+ }
1702
1713
  .leading-relaxed {
1703
1714
  --tw-leading: var(--leading-relaxed);
1704
1715
  line-height: var(--leading-relaxed);
@@ -1942,6 +1953,9 @@
1942
1953
  .opacity-60 {
1943
1954
  opacity: 60%;
1944
1955
  }
1956
+ .opacity-70 {
1957
+ opacity: 70%;
1958
+ }
1945
1959
  .opacity-75 {
1946
1960
  opacity: 75%;
1947
1961
  }
@@ -2649,6 +2663,13 @@
2649
2663
  }
2650
2664
  }
2651
2665
  }
2666
+ .hover\:opacity-100 {
2667
+ &:hover {
2668
+ @media (hover: hover) {
2669
+ opacity: 100%;
2670
+ }
2671
+ }
2672
+ }
2652
2673
  .hover\:shadow-md {
2653
2674
  &:hover {
2654
2675
  @media (hover: hover) {
@@ -1,9 +1,68 @@
1
- declare const pendingTransactions: Record<string, {
1
+ import { type PaymentDetail, type TransferResult } from "../../scripts/invoice/gnosisTransactionBuilder.js";
2
+ interface GnosisPaymentArgs {
3
+ chainName: string;
4
+ paymentDetails: PaymentDetail;
5
+ invoiceNo: string;
6
+ }
7
+ interface RequestFinancePaymentArgs {
8
+ paymentData: Record<string, unknown>;
9
+ }
10
+ interface GnosisPaymentResult {
11
+ success: boolean;
12
+ data?: TransferResult;
13
+ error?: string;
14
+ }
15
+ interface PendingTransaction {
2
16
  invoiceNo: string;
3
17
  chainName: string;
4
- paymentDetails: any;
18
+ paymentDetails: PaymentDetail | PaymentDetail[];
5
19
  timestamp: number;
6
- }>;
20
+ }
21
+ interface DriveNode {
22
+ id: string;
23
+ documentType: string;
24
+ }
25
+ interface ReactorInstance {
26
+ getDrive(driveId: string): Promise<{
27
+ state: {
28
+ global: {
29
+ nodes: DriveNode[];
30
+ };
31
+ };
32
+ }>;
33
+ getDocument(driveId: string, documentId: string): Promise<{
34
+ state: {
35
+ global: {
36
+ invoiceNo: string;
37
+ };
38
+ };
39
+ }>;
40
+ addAction(driveId: string, documentId: string, action: unknown): Promise<void>;
41
+ }
42
+ interface AlchemyActivity {
43
+ category: string;
44
+ fromAddress: string;
45
+ toAddress: string;
46
+ rawContract: {
47
+ address: string;
48
+ };
49
+ hash?: string;
50
+ value?: number;
51
+ }
52
+ interface AlchemyWebhookPayload {
53
+ event?: {
54
+ activity?: AlchemyActivity | AlchemyActivity[];
55
+ };
56
+ }
57
+ interface WebhookRequest {
58
+ body: AlchemyWebhookPayload;
59
+ headers: Record<string, string | undefined>;
60
+ }
61
+ interface WebhookResponse {
62
+ status(code: number): WebhookResponse;
63
+ json(body: Record<string, unknown>): WebhookResponse;
64
+ }
65
+ declare const pendingTransactions: Record<string, PendingTransaction>;
7
66
  interface UploadInvoicePdfChunkArgs {
8
67
  chunk: string;
9
68
  chunkIndex: number;
@@ -11,23 +70,23 @@ interface UploadInvoicePdfChunkArgs {
11
70
  fileName: string;
12
71
  sessionId: string;
13
72
  }
14
- export declare const Invoice_processGnosisPayment: (_: any, args: any) => Promise<any>;
15
- export declare const Invoice_createRequestFinancePayment: (_: any, args: any) => Promise<{
73
+ export declare const Invoice_processGnosisPayment: (_: unknown, args: GnosisPaymentArgs) => Promise<GnosisPaymentResult>;
74
+ export declare const Invoice_createRequestFinancePayment: (_: unknown, args: RequestFinancePaymentArgs) => Promise<{
16
75
  success: boolean;
17
- error: any;
76
+ error: string;
18
77
  data?: undefined;
19
78
  } | {
20
79
  success: boolean;
21
80
  data: {
22
81
  message: string;
23
- response: any;
82
+ response: import("../../scripts/invoice/requestFinance.js").RequestFinanceResponse;
24
83
  };
25
84
  error?: undefined;
26
85
  }>;
27
- export declare const Invoice_uploadInvoicePdfChunk: (_: any, args: UploadInvoicePdfChunkArgs) => Promise<{
86
+ export declare const Invoice_uploadInvoicePdfChunk: (_: unknown, args: UploadInvoicePdfChunkArgs) => Promise<{
28
87
  success: boolean;
29
88
  data: {
30
- invoiceData: any;
89
+ invoiceData: Record<string, unknown>;
31
90
  processingMetadata: {
32
91
  provider: string;
33
92
  processingTimeMs: number;
@@ -47,8 +106,8 @@ export declare const Invoice_uploadInvoicePdfChunk: (_: any, args: UploadInvoice
47
106
  };
48
107
  error?: undefined;
49
108
  }>;
50
- export declare const setReactor: (reactorInstance: any) => void;
109
+ export declare const setReactor: (reactorInstance: ReactorInstance) => void;
51
110
  export { pendingTransactions };
52
111
  export declare const cleanupOldPendingTransactions: () => void;
53
- export declare const handleWebhook: (req: any, res: any) => Promise<any>;
112
+ export declare const handleWebhook: (req: WebhookRequest, res: WebhookResponse) => Promise<WebhookResponse>;
54
113
  //# sourceMappingURL=customResolvers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"customResolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/invoice-addon/customResolvers.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,mBAAmB,EAAE,MAAM,CAC/B,MAAM,EACN;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,GAAG,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CACG,CAAC;AAQP,UAAU,yBAAyB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAaD,eAAO,MAAM,4BAA4B,GAAU,GAAG,GAAG,EAAE,MAAM,GAAG,iBA8EnE,CAAC;AAEF,eAAO,MAAM,mCAAmC,GAC9C,GAAG,GAAG,EACN,MAAM,GAAG;;;;;;;;;;;EAoCV,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,GAAG,GAAG,EACN,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;EAgFhC,CAAC;AAGF,eAAO,MAAM,UAAU,GAAI,iBAAiB,GAAG,SAE9C,CAAC;AAGF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAG/B,eAAO,MAAM,6BAA6B,YA2BzC,CAAC;AAmDF,eAAO,MAAM,aAAa,GAAU,KAAK,GAAG,EAAE,KAAK,GAAG,iBAsLrD,CAAC"}
1
+ {"version":3,"file":"customResolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/invoice-addon/customResolvers.ts"],"names":[],"mappings":"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"}
@@ -1,4 +1,4 @@
1
- import { executeTransferProposal } from "../../scripts/invoice/gnosisTransactionBuilder.js";
1
+ import { executeTransferProposal, } from "../../scripts/invoice/gnosisTransactionBuilder.js";
2
2
  import { requestDirectPayment } from "../../scripts/invoice/requestFinance.js";
3
3
  import { actions } from "../../document-models/invoice/index.js";
4
4
  import { uploadPdfAndGetJsonClaude } from "../../scripts/invoice/pdfToClaudeAI.js";
@@ -238,24 +238,19 @@ const updateDocumentStatus = async (invoiceNo) => {
238
238
  }
239
239
  catch (error) {
240
240
  console.error(`Error finding document for invoice ${invoiceNo}:`, error);
241
- return Promise.reject(error);
241
+ return Promise.reject(new Error(error));
242
242
  }
243
243
  };
244
244
  // Webhook handler method
245
245
  export const handleWebhook = async (req, res) => {
246
246
  try {
247
247
  console.log("Webhook received");
248
- // Log all headers to debug
249
- // console.log('Webhook request headers:', req.headers);
250
- // console.log('Webhook request body:', req.body);
251
248
  // Get the request body and signature
252
249
  const payload = req.body;
253
250
  const rawBody = JSON.stringify(payload);
254
251
  const signature = req.headers["x-alchemy-signature"];
255
252
  if (!signature) {
256
253
  console.warn("Missing signature header");
257
- // For testing, continue anyway
258
- // return res.status(400).json({ error: 'Missing signature header' });
259
254
  }
260
255
  else {
261
256
  // Validate the signature
@@ -263,13 +258,8 @@ export const handleWebhook = async (req, res) => {
263
258
  const isValid = isValidSignatureForStringBody(rawBody, signature, signingKey);
264
259
  if (!isValid) {
265
260
  console.warn("Invalid signature");
266
- // For testing, continue anyway
267
- // return res.status(401).json({ error: 'Invalid signature' });
268
261
  }
269
262
  }
270
- // Process the webhook
271
- // console.log('Processing webhook test button:', payload.event);
272
- // console.log('Processing webhook payload:', payload.event.activity);
273
263
  // Check if this is a transaction confirmation webhook
274
264
  if (payload.event && payload.event.activity) {
275
265
  const activities = Array.isArray(payload.event.activity)
@@ -297,24 +287,19 @@ export const handleWebhook = async (req, res) => {
297
287
  let matchedInvoiceNo = null;
298
288
  let matchedTxHash = null;
299
289
  for (const [txHash, txInfo] of Object.entries(pendingTransactions)) {
300
- const paymentDetails = Array.isArray(txInfo.paymentDetails)
290
+ const paymentDetailsList = Array.isArray(txInfo.paymentDetails)
301
291
  ? txInfo.paymentDetails
302
292
  : [txInfo.paymentDetails];
303
- // Safe transactions may be sent from a different address than the Safe itself
304
- // So we'll focus on recipient, token, and amount
305
- for (const payment of paymentDetails) {
306
- // Cast payment to any to access its properties
307
- const typedPayment = payment;
293
+ for (const payment of paymentDetailsList) {
308
294
  // Check if recipient address matches
309
- if (typedPayment.payeeWallet &&
310
- typedPayment.payeeWallet.address.toLowerCase() === toAddress) {
295
+ if (payment.payeeWallet &&
296
+ payment.payeeWallet.address.toLowerCase() === toAddress) {
311
297
  // Check if token address matches
312
- if (typedPayment.token &&
313
- typedPayment.token.evmAddress.toLowerCase() === tokenAddress) {
298
+ if (payment.token &&
299
+ payment.token.evmAddress.toLowerCase() === tokenAddress) {
314
300
  // Check if amount is similar (allowing for some precision loss)
315
- // Convert both to a common format for comparison
316
- const expectedAmount = parseFloat(typedPayment.amount);
317
- const actualAmount = parseFloat(tokenValue);
301
+ const expectedAmount = parseFloat(String(payment.amount));
302
+ const actualAmount = parseFloat(String(tokenValue));
318
303
  // Allow for a small difference due to precision issues
319
304
  const amountDifference = Math.abs(expectedAmount - actualAmount);
320
305
  const isAmountSimilar = amountDifference < 0.0001 ||
@@ -332,11 +317,11 @@ export const handleWebhook = async (req, res) => {
332
317
  }
333
318
  }
334
319
  else {
335
- console.log(`Token addresses don't match. Expected: ${typedPayment.token?.evmAddress}, Actual: ${tokenAddress}`);
320
+ console.log(`Token addresses don't match. Expected: ${payment.token?.evmAddress}, Actual: ${tokenAddress}`);
336
321
  }
337
322
  }
338
323
  else {
339
- console.log(`Recipient addresses don't match. Expected: ${typedPayment.payeeWallet?.address}, Actual: ${toAddress}`);
324
+ console.log(`Recipient addresses don't match. Expected: ${payment.payeeWallet?.address}, Actual: ${toAddress}`);
340
325
  }
341
326
  }
342
327
  if (matchedInvoiceNo)