@things-factory/invoice 10.1.260 → 10.1.261

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.
@@ -34,10 +34,5 @@ async function changeInvoiceFiles(tx, domain, id, change, context) {
34
34
  return invoice;
35
35
  }
36
36
  /** An invoice's file opens to whoever may read invoices, as the invoice doors ask it. */
37
- (0, attachment_base_1.registerAttachmentReader)(exports.INVOICE_FILE_REF_TYPE, async (_attachment, context) => {
38
- const { domain, user, unsafeIP, prohibitedPrivileges } = context?.state ?? {};
39
- if (!domain || !user)
40
- return false;
41
- return await (0, auth_base_1.checkPermission)({ category: 'invoice', privilege: 'query', owner: true }, user, domain, unsafeIP, prohibitedPrivileges);
42
- });
37
+ (0, attachment_base_1.registerAttachmentReader)(exports.INVOICE_FILE_REF_TYPE, (_attachment, context) => (0, auth_base_1.requestHolds)(context, 'invoice', 'query'));
43
38
  //# sourceMappingURL=invoice-files.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoice-files.js","sourceRoot":"","sources":["../../../server/service/invoice/invoice-files.ts"],"names":[],"mappings":";;;AAgBA,0BAEC;AAGD,gDAkBC;AAvCD,qEAA0H;AAC1H,yDAA2D;AAC3D,iDAAuD;AACvD,qCAA2C;AAG3C,uDAAuE;AAEvE;;;GAGG;AAEU,QAAA,qBAAqB,GAAG,SAAS,CAAA;AAE9C,oDAAoD;AAC7C,KAAK,UAAU,OAAO,CAAC,EAAiB,EAAE,MAAsB,EAAE,SAAiB;IACxF,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,4BAAU,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,6BAAqB,EAAE,KAAK,EAAE,SAAS,EAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAS,EAAE,CAAC,CAAA;AACvL,CAAC;AAED,kGAAkG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CAAA;IACtL,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,yFAAyF;AACzF,IAAA,0CAAwB,EAAC,6BAAqB,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;IAC7E,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,OAAO,EAAE,KAAK,IAAI,EAAE,CAAA;IAC7E,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IAClC,OAAO,MAAM,IAAA,2BAAe,EAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAS,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAA;AAC7I,CAAC,CAAC,CAAA","sourcesContent":["import { Attachment, createAttachment, deleteAttachment, registerAttachmentReader } from '@things-factory/attachment-base'\nimport { checkPermission } from '@things-factory/auth-base'\nimport { Domain, Refusal } from '@things-factory/shell'\nimport { EntityManager, In } from 'typeorm'\n\nimport { Invoice } from './invoice'\nimport { invoiceInDomain, lockDocumentDomain } from './invoice-service'\n\n/*\n * The files an invoice keeps - the signed copy, the purchase order, the delivery note (2026-10-23). They are not the\n * printed document, so they come and go on a draft, an issued and a voided invoice alike.\n */\n\nexport const INVOICE_FILE_REF_TYPE = 'Invoice'\n\n/** An invoice's files, the first attached first. */\nexport async function filesOf(tx: EntityManager, domain: { id: string }, invoiceId: string): Promise<Attachment[]> {\n return await tx.getRepository(Attachment).find({ where: { domain: { id: domain.id }, refType: INVOICE_FILE_REF_TYPE, refBy: invoiceId } as any, order: { createdAt: 'ASC' } as any })\n}\n\n/** Attach files to an invoice and take others off it, in one go - a file taken off is deleted. */\nexport async function changeInvoiceFiles(\n tx: EntityManager,\n domain: Domain,\n id: string,\n change: { attach?: any[]; remove?: string[] },\n context: ResolverContext\n): Promise<Invoice> {\n await lockDocumentDomain(tx, domain)\n const invoice = await invoiceInDomain(tx, domain, id)\n\n const remove = [...new Set(change.remove ?? [])]\n if (remove.length) {\n const own = await tx.getRepository(Attachment).find({ where: { domain: { id: domain.id }, refType: INVOICE_FILE_REF_TYPE, refBy: invoice.id, id: In(remove) } as any })\n if (own.length !== remove.length) throw new Refusal('invoice-file-not-on-invoice', {}, 'a file is not on this invoice - reload and try again')\n for (const one of own) await deleteAttachment(null, { id: one.id }, context)\n }\n for (const file of change.attach ?? []) await createAttachment(null, { attachment: { file, refType: INVOICE_FILE_REF_TYPE, refBy: invoice.id, category: 'invoice' } } as any, context)\n return invoice\n}\n\n/** An invoice's file opens to whoever may read invoices, as the invoice doors ask it. */\nregisterAttachmentReader(INVOICE_FILE_REF_TYPE, async (_attachment, context) => {\n const { domain, user, unsafeIP, prohibitedPrivileges } = context?.state ?? {}\n if (!domain || !user) return false\n return await checkPermission({ category: 'invoice', privilege: 'query', owner: true } as any, user, domain, unsafeIP, prohibitedPrivileges)\n})\n"]}
1
+ {"version":3,"file":"invoice-files.js","sourceRoot":"","sources":["../../../server/service/invoice/invoice-files.ts"],"names":[],"mappings":";;;AAgBA,0BAEC;AAGD,gDAkBC;AAvCD,qEAA0H;AAC1H,yDAAwD;AACxD,iDAAuD;AACvD,qCAA2C;AAG3C,uDAAuE;AAEvE;;;GAGG;AAEU,QAAA,qBAAqB,GAAG,SAAS,CAAA;AAE9C,oDAAoD;AAC7C,KAAK,UAAU,OAAO,CAAC,EAAiB,EAAE,MAAsB,EAAE,SAAiB;IACxF,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,4BAAU,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,6BAAqB,EAAE,KAAK,EAAE,SAAS,EAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAS,EAAE,CAAC,CAAA;AACvL,CAAC;AAED,kGAA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C,CAAA;IACtL,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,yFAAyF;AACzF,IAAA,0CAAwB,EAAC,6BAAqB,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,IAAA,wBAAY,EAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAA","sourcesContent":["import { Attachment, createAttachment, deleteAttachment, registerAttachmentReader } from '@things-factory/attachment-base'\nimport { requestHolds } from '@things-factory/auth-base'\nimport { Domain, Refusal } from '@things-factory/shell'\nimport { EntityManager, In } from 'typeorm'\n\nimport { Invoice } from './invoice'\nimport { invoiceInDomain, lockDocumentDomain } from './invoice-service'\n\n/*\n * The files an invoice keeps - the signed copy, the purchase order, the delivery note (2026-10-23). They are not the\n * printed document, so they come and go on a draft, an issued and a voided invoice alike.\n */\n\nexport const INVOICE_FILE_REF_TYPE = 'Invoice'\n\n/** An invoice's files, the first attached first. */\nexport async function filesOf(tx: EntityManager, domain: { id: string }, invoiceId: string): Promise<Attachment[]> {\n return await tx.getRepository(Attachment).find({ where: { domain: { id: domain.id }, refType: INVOICE_FILE_REF_TYPE, refBy: invoiceId } as any, order: { createdAt: 'ASC' } as any })\n}\n\n/** Attach files to an invoice and take others off it, in one go - a file taken off is deleted. */\nexport async function changeInvoiceFiles(\n tx: EntityManager,\n domain: Domain,\n id: string,\n change: { attach?: any[]; remove?: string[] },\n context: ResolverContext\n): Promise<Invoice> {\n await lockDocumentDomain(tx, domain)\n const invoice = await invoiceInDomain(tx, domain, id)\n\n const remove = [...new Set(change.remove ?? [])]\n if (remove.length) {\n const own = await tx.getRepository(Attachment).find({ where: { domain: { id: domain.id }, refType: INVOICE_FILE_REF_TYPE, refBy: invoice.id, id: In(remove) } as any })\n if (own.length !== remove.length) throw new Refusal('invoice-file-not-on-invoice', {}, 'a file is not on this invoice - reload and try again')\n for (const one of own) await deleteAttachment(null, { id: one.id }, context)\n }\n for (const file of change.attach ?? []) await createAttachment(null, { attachment: { file, refType: INVOICE_FILE_REF_TYPE, refBy: invoice.id, category: 'invoice' } } as any, context)\n return invoice\n}\n\n/** An invoice's file opens to whoever may read invoices, as the invoice doors ask it. */\nregisterAttachmentReader(INVOICE_FILE_REF_TYPE, (_attachment, context) => requestHolds(context, 'invoice', 'query'))\n"]}