@things-factory/integration-barobill 0.0.0-stage → 10.1.281

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 (47) hide show
  1. package/README.md +5 -2
  2. package/dist-server/engine/connector/barobill-client.d.ts +106 -0
  3. package/dist-server/engine/connector/barobill-client.js +180 -0
  4. package/dist-server/engine/connector/barobill-connector.d.ts +36 -0
  5. package/dist-server/engine/connector/barobill-connector.js +51 -0
  6. package/dist-server/engine/connector/soap-xml.d.ts +23 -0
  7. package/dist-server/engine/connector/soap-xml.js +94 -0
  8. package/dist-server/engine/index.d.ts +2 -0
  9. package/dist-server/engine/index.js +5 -0
  10. package/dist-server/engine/rules/bank-lines.d.ts +49 -0
  11. package/dist-server/engine/rules/bank-lines.js +77 -0
  12. package/dist-server/engine/rules/card-charges.d.ts +47 -0
  13. package/dist-server/engine/rules/card-charges.js +63 -0
  14. package/dist-server/engine/rules/period.d.ts +12 -0
  15. package/dist-server/engine/rules/period.js +31 -0
  16. package/dist-server/engine/rules/tax-invoices.d.ts +40 -0
  17. package/dist-server/engine/rules/tax-invoices.js +45 -0
  18. package/dist-server/engine/task/bank-lines.d.ts +22 -0
  19. package/dist-server/engine/task/bank-lines.js +28 -0
  20. package/dist-server/engine/task/card-charges.d.ts +19 -0
  21. package/dist-server/engine/task/card-charges.js +23 -0
  22. package/dist-server/engine/task/index.d.ts +3 -0
  23. package/dist-server/engine/task/index.js +6 -0
  24. package/dist-server/engine/task/task-input.d.ts +19 -0
  25. package/dist-server/engine/task/task-input.js +27 -0
  26. package/dist-server/engine/task/tax-invoices.d.ts +25 -0
  27. package/dist-server/engine/task/tax-invoices.js +28 -0
  28. package/dist-server/index.d.ts +7 -0
  29. package/dist-server/index.js +14 -0
  30. package/dist-server/service/barobill-setting-rules.d.ts +40 -0
  31. package/dist-server/service/barobill-setting-rules.js +71 -0
  32. package/dist-server/service/barobill-setting.d.ts +21 -0
  33. package/dist-server/service/barobill-setting.js +121 -0
  34. package/dist-server/service/index.d.ts +5 -0
  35. package/dist-server/service/index.js +10 -0
  36. package/helps/integration/connector/barobill-connector.md +21 -0
  37. package/helps/integration/task/barobill-bank-lines.md +5 -0
  38. package/helps/integration/task/barobill-card-charges.md +5 -0
  39. package/helps/integration/task/barobill-tax-invoices.md +5 -0
  40. package/package.json +41 -4
  41. package/things-factory.config.js +1 -0
  42. package/translations/en.json +16 -0
  43. package/translations/es.json +16 -0
  44. package/translations/ja.json +16 -0
  45. package/translations/ko.json +16 -0
  46. package/translations/ms.json +16 -0
  47. package/translations/zh.json +16 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Barobill's card approvals (`CardApprovalLog`) as card lines (ADR-0204 decision 2): an approval is a charge, a cancel
3
+ * gives it back (ADR-0178 decision 3). The card is said by its number; the books find it by its last four digits and
4
+ * card company.
5
+ *
6
+ * How the amounts come, read from the test server's BC card answers (2026-11-14):
7
+ * - `ApprovalAmount` is the charge in the card's currency - won for KRW, dollars for USD; a cancel's is negative.
8
+ * - `ForeignApprovalAmount`, despite its name, is the won a foreign charge came to (empty for KRW).
9
+ * - `Amount` and `Tax` split a won charge into supply and VAT (0 abroad). `TotalAmount` comes 0 and is not read.
10
+ */
11
+ export interface CardChargeLine {
12
+ kind: 'APPROVAL' | 'CANCEL';
13
+ /** The time the card was used, as the card company printed it - 'YYYY-MM-DD HH:mm:ss'. */
14
+ usedLocalTime: string;
15
+ approvalNumber: string;
16
+ /** What the company pays, in won - always positive, `kind` says which way; null when a foreign charge has no won yet. */
17
+ amount: number | null;
18
+ supplyAmount: number | null;
19
+ taxAmount: number | null;
20
+ serviceCharge: number | null;
21
+ /** A charge abroad: its own currency and amount (positive). */
22
+ currency: string | null;
23
+ foreignAmount: number | null;
24
+ merchantName: string | null;
25
+ merchantNumber: string | null;
26
+ merchantBizNumber: string | null;
27
+ merchantTaxType: string | null;
28
+ merchantCeo: string | null;
29
+ merchantAddress: string | null;
30
+ merchantBizType: string | null;
31
+ merchantTel: string | null;
32
+ paymentPlan: string | null;
33
+ installmentMonths: number | null;
34
+ collectorKey: string | null;
35
+ }
36
+ export interface CardChargeLines {
37
+ cardNumber: string;
38
+ periodStart: string;
39
+ periodEnd: string;
40
+ lines: CardChargeLine[];
41
+ }
42
+ /** Barobill's `ApprovalType` as the line's kind. A word it does not know is refused and named, never guessed. */
43
+ export declare function approvalKindOf(value: unknown): 'APPROVAL' | 'CANCEL';
44
+ export declare function cardChargesOf(cardNumber: string, items: readonly Record<string, any>[], period: {
45
+ from: string;
46
+ to: string;
47
+ }): CardChargeLines;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.approvalKindOf = approvalKindOf;
4
+ exports.cardChargesOf = cardChargesOf;
5
+ const bank_lines_1 = require("./bank-lines");
6
+ const text = (value) => {
7
+ const one = typeof value === 'string' ? value.trim() : '';
8
+ return one ? one : null;
9
+ };
10
+ const maybeMoney = (value, what) => (text(value) === null ? null : (0, bank_lines_1.moneyOf)(value, what));
11
+ /** Barobill's `ApprovalType` as the line's kind. A word it does not know is refused and named, never guessed. */
12
+ function approvalKindOf(value) {
13
+ const word = String(value ?? '').trim();
14
+ if (word === '승인')
15
+ return 'APPROVAL';
16
+ if (word === '취소')
17
+ return 'CANCEL';
18
+ throw new Error(`Barobill approval type '${word}' is neither 승인 nor 취소`);
19
+ }
20
+ function cardChargesOf(cardNumber, items, period) {
21
+ const card = String(cardNumber).replace(/\D/g, '');
22
+ const lines = items.map(item => {
23
+ const own = String(item.CardNum ?? '').replace(/\D/g, '');
24
+ if (own && own !== card)
25
+ throw new Error(`Barobill answered a charge of card ${own} for card ${card}`);
26
+ const months = Number(String(item.InstallmentMonths ?? '').trim());
27
+ const currency = text(item.CurrencyCode) ?? 'KRW';
28
+ const abroad = currency !== 'KRW';
29
+ const charged = Math.abs((0, bank_lines_1.moneyOf)(item.ApprovalAmount, 'approval amount'));
30
+ const won = abroad ? maybeMoney(item.ForeignApprovalAmount, 'won amount') : charged;
31
+ const split = (value, what) => {
32
+ const one = abroad ? null : maybeMoney(value, what);
33
+ return one === null ? null : Math.abs(one);
34
+ };
35
+ return {
36
+ kind: approvalKindOf(item.ApprovalType),
37
+ usedLocalTime: (0, bank_lines_1.localTimeOf)(item.UseDT, 'use time'),
38
+ approvalNumber: String(item.ApprovalNum ?? '').trim(),
39
+ amount: won === null ? null : Math.abs(won),
40
+ supplyAmount: split(item.Amount, 'amount'),
41
+ taxAmount: split(item.Tax, 'tax'),
42
+ serviceCharge: split(item.ServiceCharge, 'service charge'),
43
+ currency: abroad ? currency : null,
44
+ foreignAmount: abroad ? charged : null,
45
+ merchantName: text(item.UseStoreName),
46
+ merchantNumber: text(item.UseStoreNum),
47
+ merchantBizNumber: text(item.UseStoreCorpNum)?.replace(/\D/g, '') || null,
48
+ merchantTaxType: text(item.UseStoreTaxType),
49
+ merchantCeo: text(item.UseStoreCeo),
50
+ merchantAddress: text(item.UseStoreAddr),
51
+ merchantBizType: text(item.UseStoreBizType),
52
+ merchantTel: text(item.UseStoreTel),
53
+ paymentPlan: text(item.PaymentPlan),
54
+ installmentMonths: Number.isInteger(months) && months > 1 ? months : null,
55
+ collectorKey: text(item.UseKey)
56
+ };
57
+ });
58
+ for (const line of lines)
59
+ if (!line.approvalNumber)
60
+ throw new Error(`Barobill charge of card ${card} at ${line.usedLocalTime} has no approval number`);
61
+ return { cardNumber: card, periodStart: (0, bank_lines_1.dayOf)(period.from), periodEnd: (0, bank_lines_1.dayOf)(period.to), lines };
62
+ }
63
+ //# sourceMappingURL=card-charges.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The days a collecting task asks for, YYYYMMDD, in Korea's calendar (Barobill's): `from`/`to` when given, otherwise
3
+ * the last `days` days up to today. Days overlap from run to run on purpose - the books know a line they already have.
4
+ */
5
+ export declare function periodOf(params: {
6
+ from?: string;
7
+ to?: string;
8
+ days?: string | number;
9
+ }, now?: Date): {
10
+ from: string;
11
+ to: string;
12
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.periodOf = periodOf;
4
+ /**
5
+ * The days a collecting task asks for, YYYYMMDD, in Korea's calendar (Barobill's): `from`/`to` when given, otherwise
6
+ * the last `days` days up to today. Days overlap from run to run on purpose - the books know a line they already have.
7
+ */
8
+ function periodOf(params, now = new Date()) {
9
+ const korea = (date) => new Date(date.getTime() + 9 * 3600_000).toISOString().slice(0, 10).replace(/-/g, '');
10
+ const day = (value, what) => {
11
+ const digits = String(value ?? '').replace(/\D/g, '');
12
+ if (!digits)
13
+ return '';
14
+ if (!/^\d{8}$/.test(digits))
15
+ throw new Error(`the ${what} day '${value}' is not YYYY-MM-DD`);
16
+ return digits;
17
+ };
18
+ const to = day(params.to, 'last') || korea(now);
19
+ let from = day(params.from, 'first');
20
+ if (!from) {
21
+ const days = params.days === undefined || params.days === '' ? 7 : Number(params.days);
22
+ if (!Number.isInteger(days) || days < 1 || days > 366)
23
+ throw new Error(`'${params.days}' days is not 1 to 366`);
24
+ const end = new Date(Date.UTC(+to.slice(0, 4), +to.slice(4, 6) - 1, +to.slice(6, 8)));
25
+ from = new Date(end.getTime() - (days - 1) * 86400_000).toISOString().slice(0, 10).replace(/-/g, '');
26
+ }
27
+ if (from > to)
28
+ throw new Error(`the period ${from} ~ ${to} ends before it starts`);
29
+ return { from, to };
30
+ }
31
+ //# sourceMappingURL=period.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Barobill's tax invoice list (`SimpleTaxInvoiceEx2`) as the facts the books keep of an invoice (ADR-0204 decision 2):
3
+ * the National Tax Service approval number is what makes it that invoice.
4
+ */
5
+ export interface InvoiceParty {
6
+ bizNumber: string;
7
+ subId: string | null;
8
+ name: string | null;
9
+ ceo: string | null;
10
+ address: string | null;
11
+ bizType: string | null;
12
+ bizClass: string | null;
13
+ email: string | null;
14
+ }
15
+ export interface TaxInvoiceFacts {
16
+ side: 'sales' | 'purchase';
17
+ approvalNumber: string;
18
+ writeDate: string;
19
+ issuedLocalTime: string | null;
20
+ sentLocalTime: string | null;
21
+ modifyCode: string | null;
22
+ taxType: string | null;
23
+ purposeType: string | null;
24
+ supplier: InvoiceParty;
25
+ buyer: InvoiceParty;
26
+ supplyAmount: number;
27
+ taxAmount: number;
28
+ totalAmount: number;
29
+ itemName: string | null;
30
+ remarks: string[];
31
+ }
32
+ export declare function taxInvoicesOf(side: 'sales' | 'purchase', items: readonly Record<string, any>[], period: {
33
+ from: string;
34
+ to: string;
35
+ }): {
36
+ side: "sales" | "purchase";
37
+ periodStart: string;
38
+ periodEnd: string;
39
+ invoices: TaxInvoiceFacts[];
40
+ };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.taxInvoicesOf = taxInvoicesOf;
4
+ const bank_lines_1 = require("./bank-lines");
5
+ const text = (value) => {
6
+ const one = typeof value === 'string' ? value.trim() : '';
7
+ return one ? one : null;
8
+ };
9
+ const maybeTime = (value, what) => (text(value) === null ? null : (0, bank_lines_1.localTimeOf)(value, what));
10
+ const partyOf = (item, prefix) => ({
11
+ bizNumber: String(item[`${prefix}CorpNum`] ?? '').replace(/\D/g, ''),
12
+ subId: text(item[`${prefix}TaxRegID`]),
13
+ name: text(item[`${prefix}CorpName`]),
14
+ ceo: text(item[`${prefix}CEOName`]),
15
+ address: text(item[`${prefix}Addr`]),
16
+ bizType: text(item[`${prefix}BizType`]),
17
+ bizClass: text(item[`${prefix}BizClass`]),
18
+ email: text(item[`${prefix}Email`])
19
+ });
20
+ function taxInvoicesOf(side, items, period) {
21
+ const invoices = items.map(item => {
22
+ const approvalNumber = String(item.NTSSendKey ?? '').trim();
23
+ if (!approvalNumber)
24
+ throw new Error(`Barobill ${side} invoice written ${item.WriteDate ?? '?'} has no approval number`);
25
+ return {
26
+ side,
27
+ approvalNumber,
28
+ writeDate: (0, bank_lines_1.localTimeOf)(item.WriteDate, 'write date'),
29
+ issuedLocalTime: maybeTime(item.IssueDT, 'issue time'),
30
+ sentLocalTime: maybeTime(item.NTSSendDT, 'send time'),
31
+ modifyCode: text(item.ModifyCode),
32
+ taxType: text(item.TaxType),
33
+ purposeType: text(item.PurposeType),
34
+ supplier: partyOf(item, 'Invoicer'),
35
+ buyer: partyOf(item, 'Invoicee'),
36
+ supplyAmount: (0, bank_lines_1.moneyOf)(item.AmountTotal, 'supply amount'),
37
+ taxAmount: (0, bank_lines_1.moneyOf)(item.TaxTotal, 'tax amount'),
38
+ totalAmount: (0, bank_lines_1.moneyOf)(item.TotalAmount, 'total amount'),
39
+ itemName: text(item.ItemName),
40
+ remarks: [item.Remark1, item.Remark2, item.Remark3].map(text).filter((one) => !!one)
41
+ };
42
+ });
43
+ return { side, periodStart: (0, bank_lines_1.dayOf)(period.from), periodEnd: (0, bank_lines_1.dayOf)(period.to), invoices };
44
+ }
45
+ //# sourceMappingURL=tax-invoices.js.map
@@ -0,0 +1,22 @@
1
+ import { Context } from '@things-factory/integration-base';
2
+ import { StatementLines } from '../rules/bank-lines';
3
+ /**
4
+ * The lines of the accounts registered with Barobill (or the one account given) for a period, as statement lines
5
+ * (ADR-0204). A scenario hands them on to accounting `importBankLines`.
6
+ */
7
+ declare function BarobillBankLines(step: any, context: Context): Promise<{
8
+ data: {
9
+ collector: 'BAROBILL';
10
+ accounts: StatementLines[];
11
+ };
12
+ }>;
13
+ declare namespace BarobillBankLines {
14
+ var parameterSpec: {
15
+ type: string;
16
+ name: string;
17
+ label: string;
18
+ placeholder: string;
19
+ }[];
20
+ var help: string;
21
+ }
22
+ export default BarobillBankLines;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const bank_lines_1 = require("../rules/bank-lines");
5
+ const task_input_1 = require("./task-input");
6
+ /**
7
+ * The lines of the accounts registered with Barobill (or the one account given) for a period, as statement lines
8
+ * (ADR-0204). A scenario hands them on to accounting `importBankLines`.
9
+ */
10
+ async function BarobillBankLines(step, context) {
11
+ const { instance, given, period } = await (0, task_input_1.taskInput)(step, context, ['accountNumber']);
12
+ const { client, userId } = instance;
13
+ const numbers = given.accountNumber
14
+ ? [given.accountNumber]
15
+ : (await client.bankAccounts()).map(account => String(account.BankAccountNum ?? '')).filter(Boolean);
16
+ const accounts = [];
17
+ for (const accountNumber of numbers) {
18
+ const { items } = await client.bankLines({ userId, accountNumber, from: period.from, to: period.to });
19
+ accounts.push((0, bank_lines_1.bankLinesOf)(accountNumber, items, period));
20
+ context.logger?.info?.(`[barobill] bank ${accountNumber} ${period.from}~${period.to}: ${items.length} lines`);
21
+ }
22
+ return { data: { collector: 'BAROBILL', accounts } };
23
+ }
24
+ BarobillBankLines.parameterSpec = [{ type: 'string', name: 'accountNumber', label: 'barobill-account-number', placeholder: '비우면 등록된 모든 계좌' }, ...task_input_1.periodSpec];
25
+ BarobillBankLines.help = 'integration/task/barobill-bank-lines';
26
+ integration_base_1.TaskRegistry.registerTaskHandler('barobill-bank-lines', BarobillBankLines);
27
+ exports.default = BarobillBankLines;
28
+ //# sourceMappingURL=bank-lines.js.map
@@ -0,0 +1,19 @@
1
+ import { Context } from '@things-factory/integration-base';
2
+ import { CardChargeLines } from '../rules/card-charges';
3
+ /** The approvals and cancels of the cards registered with Barobill (or the one card given) for a period (ADR-0204). */
4
+ declare function BarobillCardCharges(step: any, context: Context): Promise<{
5
+ data: {
6
+ collector: 'BAROBILL';
7
+ cards: CardChargeLines[];
8
+ };
9
+ }>;
10
+ declare namespace BarobillCardCharges {
11
+ var parameterSpec: {
12
+ type: string;
13
+ name: string;
14
+ label: string;
15
+ placeholder: string;
16
+ }[];
17
+ var help: string;
18
+ }
19
+ export default BarobillCardCharges;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const card_charges_1 = require("../rules/card-charges");
5
+ const task_input_1 = require("./task-input");
6
+ /** The approvals and cancels of the cards registered with Barobill (or the one card given) for a period (ADR-0204). */
7
+ async function BarobillCardCharges(step, context) {
8
+ const { instance, given, period } = await (0, task_input_1.taskInput)(step, context, ['cardNumber']);
9
+ const { client, userId } = instance;
10
+ const numbers = given.cardNumber ? [given.cardNumber] : (await client.cards()).map(card => String(card.CardNum ?? '')).filter(Boolean);
11
+ const cards = [];
12
+ for (const cardNumber of numbers) {
13
+ const { items } = await client.cardApprovals({ userId, cardNumber, from: period.from, to: period.to });
14
+ cards.push((0, card_charges_1.cardChargesOf)(cardNumber, items, period));
15
+ context.logger?.info?.(`[barobill] card ****${cardNumber.slice(-4)} ${period.from}~${period.to}: ${items.length} charges`);
16
+ }
17
+ return { data: { collector: 'BAROBILL', cards } };
18
+ }
19
+ BarobillCardCharges.parameterSpec = [{ type: 'string', name: 'cardNumber', label: 'barobill-card-number', placeholder: '비우면 등록된 모든 카드' }, ...task_input_1.periodSpec];
20
+ BarobillCardCharges.help = 'integration/task/barobill-card-charges';
21
+ integration_base_1.TaskRegistry.registerTaskHandler('barobill-card-charges', BarobillCardCharges);
22
+ exports.default = BarobillCardCharges;
23
+ //# sourceMappingURL=card-charges.js.map
@@ -0,0 +1,3 @@
1
+ import './bank-lines';
2
+ import './card-charges';
3
+ import './tax-invoices';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./bank-lines");
4
+ require("./card-charges");
5
+ require("./tax-invoices");
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,19 @@
1
+ import { Context } from '@things-factory/integration-base';
2
+ import { BarobillConnectionInstance } from '../connector/barobill-connector';
3
+ /** The connection's client and the task's own inputs, each a template over the scenario's data. */
4
+ export declare function taskInput(step: any, context: Context, names: string[]): Promise<{
5
+ instance: BarobillConnectionInstance;
6
+ given: {
7
+ [k: string]: string;
8
+ };
9
+ period: {
10
+ from: string;
11
+ to: string;
12
+ };
13
+ }>;
14
+ export declare const periodSpec: {
15
+ type: string;
16
+ name: string;
17
+ label: string;
18
+ placeholder: string;
19
+ }[];
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.periodSpec = void 0;
4
+ exports.taskInput = taskInput;
5
+ const integration_base_1 = require("@things-factory/integration-base");
6
+ const period_1 = require("../rules/period");
7
+ /** The connection's client and the task's own inputs, each a template over the scenario's data. */
8
+ async function taskInput(step, context, names) {
9
+ const { connection: connectionName, params = {} } = step;
10
+ const { domain, user, data, variables, lng } = context;
11
+ const instance = await integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
12
+ if (!instance?.client)
13
+ throw new Error(`barobill connection '${connectionName}' is not established.`);
14
+ const scope = { domain, user, lng, data, variables, console };
15
+ const value = (name) => {
16
+ const raw = params[name];
17
+ return raw === undefined || raw === null || raw === '' ? '' : String((0, integration_base_1.evaluateTemplate)(String(raw), scope)).trim();
18
+ };
19
+ const given = Object.fromEntries(names.map(name => [name, value(name)]));
20
+ return { instance, given, period: (0, period_1.periodOf)({ from: value('from'), to: value('to'), days: value('days') }) };
21
+ }
22
+ exports.periodSpec = [
23
+ { type: 'string', name: 'days', label: 'barobill-days', placeholder: '7' },
24
+ { type: 'string', name: 'from', label: 'barobill-from', placeholder: 'YYYY-MM-DD' },
25
+ { type: 'string', name: 'to', label: 'barobill-to', placeholder: 'YYYY-MM-DD' }
26
+ ];
27
+ //# sourceMappingURL=task-input.js.map
@@ -0,0 +1,25 @@
1
+ import { Context } from '@things-factory/integration-base';
2
+ /** The company's sales and purchase tax invoices for a period (ADR-0204). `side` is sales, purchase or both (blank). */
3
+ declare function BarobillTaxInvoices(step: any, context: Context): Promise<{
4
+ data: {
5
+ collector: string;
6
+ lists: any[];
7
+ };
8
+ }>;
9
+ declare namespace BarobillTaxInvoices {
10
+ var parameterSpec: ({
11
+ type: string;
12
+ name: string;
13
+ label: string;
14
+ placeholder: string;
15
+ } | {
16
+ type: string;
17
+ name: string;
18
+ label: string;
19
+ property: {
20
+ options: string[];
21
+ };
22
+ })[];
23
+ var help: string;
24
+ }
25
+ export default BarobillTaxInvoices;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const integration_base_1 = require("@things-factory/integration-base");
4
+ const tax_invoices_1 = require("../rules/tax-invoices");
5
+ const task_input_1 = require("./task-input");
6
+ /** The company's sales and purchase tax invoices for a period (ADR-0204). `side` is sales, purchase or both (blank). */
7
+ async function BarobillTaxInvoices(step, context) {
8
+ const { instance, given, period } = await (0, task_input_1.taskInput)(step, context, ['side']);
9
+ const { client, userId } = instance;
10
+ if (given.side && given.side !== 'sales' && given.side !== 'purchase')
11
+ throw new Error(`barobill-tax-invoices: side '${given.side}' is neither sales nor purchase`);
12
+ const sides = (given.side ? [given.side] : ['sales', 'purchase']);
13
+ const lists = [];
14
+ for (const side of sides) {
15
+ const { items } = await client.taxInvoices({ side, userId, from: period.from, to: period.to });
16
+ lists.push((0, tax_invoices_1.taxInvoicesOf)(side, items, period));
17
+ context.logger?.info?.(`[barobill] ${side} invoices ${period.from}~${period.to}: ${items.length}`);
18
+ }
19
+ return { data: { collector: 'BAROBILL', lists } };
20
+ }
21
+ BarobillTaxInvoices.parameterSpec = [
22
+ { type: 'select', name: 'side', label: 'barobill-side', property: { options: ['', 'sales', 'purchase'] } },
23
+ ...task_input_1.periodSpec
24
+ ];
25
+ BarobillTaxInvoices.help = 'integration/task/barobill-tax-invoices';
26
+ integration_base_1.TaskRegistry.registerTaskHandler('barobill-tax-invoices', BarobillTaxInvoices);
27
+ exports.default = BarobillTaxInvoices;
28
+ //# sourceMappingURL=tax-invoices.js.map
@@ -0,0 +1,7 @@
1
+ import './engine';
2
+ export * from './service';
3
+ export { BarobillClient, BarobillError } from './engine/connector/barobill-client';
4
+ export * from './engine/rules/bank-lines';
5
+ export * from './engine/rules/card-charges';
6
+ export * from './engine/rules/tax-invoices';
7
+ export * from './engine/rules/period';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BarobillError = exports.BarobillClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ require("./engine");
6
+ tslib_1.__exportStar(require("./service"), exports);
7
+ var barobill_client_1 = require("./engine/connector/barobill-client");
8
+ Object.defineProperty(exports, "BarobillClient", { enumerable: true, get: function () { return barobill_client_1.BarobillClient; } });
9
+ Object.defineProperty(exports, "BarobillError", { enumerable: true, get: function () { return barobill_client_1.BarobillError; } });
10
+ tslib_1.__exportStar(require("./engine/rules/bank-lines"), exports);
11
+ tslib_1.__exportStar(require("./engine/rules/card-charges"), exports);
12
+ tslib_1.__exportStar(require("./engine/rules/tax-invoices"), exports);
13
+ tslib_1.__exportStar(require("./engine/rules/period"), exports);
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The Barobill setting of a domain (ADR-0204 decision 1 amendment 1): the partner key, the business number, the
3
+ * Barobill user id and the server. They are the attributes the `barobill` connection reads (`Connection::barobill::<param>`,
4
+ * `useDomainAttribute`), so the Settings screen and the connection hold one value, never two. EnvVar keeps every value
5
+ * encrypted at rest; the key never comes back out.
6
+ */
7
+ /** The connection the setting is for - scenarios name this connection. */
8
+ export declare const BAROBILL_CONNECTION = "barobill";
9
+ export declare const BAROBILL_PARAMS: readonly ["certKey", "corpNum", "userId", "server"];
10
+ export type BarobillParam = (typeof BAROBILL_PARAMS)[number];
11
+ export declare const attributeOf: (param: BarobillParam) => string;
12
+ export interface BarobillSettingState {
13
+ certKeySet: boolean;
14
+ /** The key as the framework shows a secret (`secretHint`) - enough to tell which key it is, never the key. */
15
+ certKeyHint: string | null;
16
+ corpNum: string | null;
17
+ userId: string | null;
18
+ server: string | null;
19
+ }
20
+ export interface BarobillSettingPatch {
21
+ certKey?: string | null;
22
+ corpNum?: string | null;
23
+ userId?: string | null;
24
+ server?: string | null;
25
+ }
26
+ export declare class BarobillSettingRefusal extends Error {
27
+ code: string;
28
+ field: string;
29
+ constructor(code: string, field: string, message: string);
30
+ }
31
+ /** What the screen may see of the attributes - whether the key is set, and the rest as they are. */
32
+ export declare function barobillSettingState(attributes: Record<string, string | undefined>, hint?: (secret: string) => string | undefined): BarobillSettingState;
33
+ /**
34
+ * The attribute writes of a patch: a field left out stays, an empty one is cleared. Each value is checked against what
35
+ * Barobill takes, and a refusal names the field.
36
+ */
37
+ export declare function barobillSettingWrites(patch: BarobillSettingPatch): {
38
+ name: string;
39
+ value: string | null;
40
+ }[];
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * The Barobill setting of a domain (ADR-0204 decision 1 amendment 1): the partner key, the business number, the
4
+ * Barobill user id and the server. They are the attributes the `barobill` connection reads (`Connection::barobill::<param>`,
5
+ * `useDomainAttribute`), so the Settings screen and the connection hold one value, never two. EnvVar keeps every value
6
+ * encrypted at rest; the key never comes back out.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BarobillSettingRefusal = exports.attributeOf = exports.BAROBILL_PARAMS = exports.BAROBILL_CONNECTION = void 0;
10
+ exports.barobillSettingState = barobillSettingState;
11
+ exports.barobillSettingWrites = barobillSettingWrites;
12
+ /** The connection the setting is for - scenarios name this connection. */
13
+ exports.BAROBILL_CONNECTION = 'barobill';
14
+ exports.BAROBILL_PARAMS = ['certKey', 'corpNum', 'userId', 'server'];
15
+ const attributeOf = (param) => `Connection::${exports.BAROBILL_CONNECTION}::${param}`;
16
+ exports.attributeOf = attributeOf;
17
+ class BarobillSettingRefusal extends Error {
18
+ constructor(code, field, message) {
19
+ super(message);
20
+ this.code = code;
21
+ this.field = field;
22
+ }
23
+ }
24
+ exports.BarobillSettingRefusal = BarobillSettingRefusal;
25
+ /** What the screen may see of the attributes - whether the key is set, and the rest as they are. */
26
+ function barobillSettingState(attributes, hint = () => undefined) {
27
+ const value = (param) => attributes[(0, exports.attributeOf)(param)] || null;
28
+ const key = value('certKey');
29
+ return { certKeySet: !!key, certKeyHint: key ? hint(key) ?? null : null, corpNum: value('corpNum'), userId: value('userId'), server: value('server') };
30
+ }
31
+ /**
32
+ * The attribute writes of a patch: a field left out stays, an empty one is cleared. Each value is checked against what
33
+ * Barobill takes, and a refusal names the field.
34
+ */
35
+ function barobillSettingWrites(patch) {
36
+ const writes = [];
37
+ for (const param of exports.BAROBILL_PARAMS) {
38
+ if (!(param in patch) || patch[param] === undefined)
39
+ continue;
40
+ const raw = String(patch[param] ?? '').trim();
41
+ if (!raw) {
42
+ writes.push({ name: (0, exports.attributeOf)(param), value: null });
43
+ continue;
44
+ }
45
+ writes.push({ name: (0, exports.attributeOf)(param), value: checked(param, raw) });
46
+ }
47
+ return writes;
48
+ }
49
+ function checked(param, raw) {
50
+ switch (param) {
51
+ case 'certKey':
52
+ if (!/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/.test(raw))
53
+ throw new BarobillSettingRefusal('barobill-cert-key-invalid', 'certKey', 'The Barobill key is the 36-character key (8-4-4-4-12) on the developer center');
54
+ return raw.toUpperCase();
55
+ case 'corpNum': {
56
+ const digits = raw.replace(/\D/g, '');
57
+ if (digits.length !== 10)
58
+ throw new BarobillSettingRefusal('barobill-corp-num-invalid', 'corpNum', 'The business number is 10 digits');
59
+ return digits;
60
+ }
61
+ case 'userId':
62
+ if (!/^[A-Za-z0-9_.@-]{6,20}$/.test(raw))
63
+ throw new BarobillSettingRefusal('barobill-user-id-invalid', 'userId', 'The Barobill user id is 6 to 20 letters, digits or - _ . @');
64
+ return raw;
65
+ case 'server':
66
+ if (raw !== 'test' && raw !== 'production')
67
+ throw new BarobillSettingRefusal('barobill-server-invalid', 'server', 'The server is test or production');
68
+ return raw;
69
+ }
70
+ }
71
+ //# sourceMappingURL=barobill-setting-rules.js.map
@@ -0,0 +1,21 @@
1
+ export declare class BarobillSetting {
2
+ certKeySet: boolean;
3
+ certKeyHint?: string;
4
+ corpNum?: string;
5
+ userId?: string;
6
+ server?: string;
7
+ }
8
+ export declare class BarobillSettingPatch {
9
+ certKey?: string;
10
+ corpNum?: string;
11
+ userId?: string;
12
+ server?: string;
13
+ }
14
+ /**
15
+ * The Settings screen's door to the Barobill setting. The values are domain attributes (EnvVar), so the EnvVar
16
+ * privilege opens them, as it does the notice channels.
17
+ */
18
+ export declare class BarobillSettingResolver {
19
+ barobillSetting(context: ResolverContext): Promise<BarobillSetting>;
20
+ updateBarobillSetting(patch: BarobillSettingPatch, context: ResolverContext): Promise<BarobillSetting>;
21
+ }