@things-factory/integration-barobill 10.1.282 → 10.1.288

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.
@@ -43,6 +43,12 @@ export declare const QUERY_CODES: {
43
43
  */
44
44
  readonly invoiceTax: readonly [1, 3];
45
45
  };
46
+ /**
47
+ * The longest period one card purchase query takes. The production server answers 201 days ending today and refuses 202
48
+ * (-10148 조회 기간이 잘못되었습니다, 2026-11-16); a period further back is answered, empty where nothing was kept.
49
+ * Kept under that edge.
50
+ */
51
+ export declare const PURCHASE_WINDOW_DAYS = 180;
46
52
  export declare class BarobillError extends Error {
47
53
  code: number;
48
54
  operation: string;
@@ -94,6 +100,28 @@ export declare class BarobillClient {
94
100
  from: string;
95
101
  to: string;
96
102
  }): Promise<BarobillPage<XmlNode>>;
103
+ /**
104
+ * A card's purchases - what the card company has settled of the approvals - between two days (YYYYMMDD). An approval
105
+ * with no purchase yet is not billed yet.
106
+ */
107
+ cardPurchases(query: {
108
+ userId: string;
109
+ cardNumber: string;
110
+ from: string;
111
+ to: string;
112
+ }): Promise<BarobillPage<XmlNode>>;
113
+ /**
114
+ * Every purchase Barobill keeps of a card up to a day (YYYYMMDD): window by window back from it, until a window has
115
+ * none - Barobill keeps a card's purchases from when it was registered, so an empty window is where they begin.
116
+ * `from` is the first day of the oldest window asked.
117
+ */
118
+ everyCardPurchase(query: {
119
+ userId: string;
120
+ cardNumber: string;
121
+ to: string;
122
+ }): Promise<BarobillPage<XmlNode> & {
123
+ from: string;
124
+ }>;
97
125
  /** The company's sales or purchase tax invoices between two days (YYYYMMDD), every tax type unless one is given. */
98
126
  taxInvoices(query: {
99
127
  side: 'sales' | 'purchase';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BarobillClient = exports.digitsOnly = exports.BarobillError = exports.QUERY_CODES = exports.READ_OPERATIONS = exports.BAROBILL_ORIGINS = void 0;
3
+ exports.BarobillClient = exports.digitsOnly = exports.BarobillError = exports.PURCHASE_WINDOW_DAYS = exports.QUERY_CODES = exports.READ_OPERATIONS = exports.BAROBILL_ORIGINS = void 0;
4
4
  const soap_xml_1 = require("./soap-xml");
5
5
  /**
6
6
  * Barobill's web services (SOAP 1.1 over HTTPS), read only.
@@ -18,7 +18,7 @@ exports.BAROBILL_ORIGINS = {
18
18
  };
19
19
  exports.READ_OPERATIONS = {
20
20
  BANKACCOUNT: ['CheckCERTIsValid', 'GetErrString', 'GetBankAccountEx2', 'GetPeriodBankAccountLogEx2'],
21
- CARD: ['CheckCERTIsValid', 'GetErrString', 'GetCardEx2', 'GetPeriodCardApprovalLog'],
21
+ CARD: ['CheckCERTIsValid', 'GetErrString', 'GetCardEx2', 'GetPeriodCardApprovalLog', 'GetPurchaseHistories'],
22
22
  TI: ['CheckCERTIsValid', 'GetErrString', 'GetPeriodTaxInvoiceSalesListEx', 'GetPeriodTaxInvoicePurchaseListEx']
23
23
  };
24
24
  /**
@@ -38,6 +38,17 @@ exports.QUERY_CODES = {
38
38
  */
39
39
  invoiceTax: [1, 3]
40
40
  };
41
+ /**
42
+ * The longest period one card purchase query takes. The production server answers 201 days ending today and refuses 202
43
+ * (-10148 조회 기간이 잘못되었습니다, 2026-11-16); a period further back is answered, empty where nothing was kept.
44
+ * Kept under that edge.
45
+ */
46
+ exports.PURCHASE_WINDOW_DAYS = 180;
47
+ /** How many windows back `everyCardPurchase` walks at most - about five years. */
48
+ const PURCHASE_WINDOW_LIMIT = 10;
49
+ const dayNumber = (yyyymmdd) => Date.UTC(+yyyymmdd.slice(0, 4), +yyyymmdd.slice(4, 6) - 1, +yyyymmdd.slice(6, 8));
50
+ const yyyymmddOf = (time) => new Date(time).toISOString().slice(0, 10).replace(/-/g, '');
51
+ const DAY = 86400_000;
41
52
  const PAGE = 100;
42
53
  /** Barobill answers a period list in pages; past this many something is wrong with the period, not the company. */
43
54
  const PAGE_LIMIT = 200;
@@ -159,6 +170,42 @@ class BarobillClient {
159
170
  async cardApprovals(query) {
160
171
  return this.allPages('CARD', 'GetPeriodCardApprovalLog', { ID: query.userId, CardNum: (0, exports.digitsOnly)(query.cardNumber), StartDate: query.from, EndDate: query.to, OrderDirection: exports.QUERY_CODES.order.oldestFirst }, 'CardLogList', 'CardApprovalLog');
161
172
  }
173
+ /**
174
+ * A card's purchases - what the card company has settled of the approvals - between two days (YYYYMMDD). An approval
175
+ * with no purchase yet is not billed yet.
176
+ */
177
+ async cardPurchases(query) {
178
+ /* A longer period is asked window by window, newest first, and joined oldest first. */
179
+ if ((dayNumber(query.to) - dayNumber(query.from)) / DAY + 1 > exports.PURCHASE_WINDOW_DAYS) {
180
+ const pages = [];
181
+ for (let end = dayNumber(query.to); end >= dayNumber(query.from); end -= exports.PURCHASE_WINDOW_DAYS * DAY) {
182
+ const start = Math.max(dayNumber(query.from), end - (exports.PURCHASE_WINDOW_DAYS - 1) * DAY);
183
+ pages.unshift(await this.cardPurchases({ ...query, from: yyyymmddOf(start), to: yyyymmddOf(end) }));
184
+ }
185
+ return { items: pages.flatMap(page => page.items), total: pages.reduce((sum, page) => sum + page.total, 0) };
186
+ }
187
+ return this.allPages('CARD', 'GetPurchaseHistories', { ID: query.userId, CardNum: (0, exports.digitsOnly)(query.cardNumber), StartDate: query.from, EndDate: query.to, OrderDirection: exports.QUERY_CODES.order.oldestFirst }, 'Histories', 'CardPurchaseHistory');
188
+ }
189
+ /**
190
+ * Every purchase Barobill keeps of a card up to a day (YYYYMMDD): window by window back from it, until a window has
191
+ * none - Barobill keeps a card's purchases from when it was registered, so an empty window is where they begin.
192
+ * `from` is the first day of the oldest window asked.
193
+ */
194
+ async everyCardPurchase(query) {
195
+ const pages = [];
196
+ let end = dayNumber(query.to);
197
+ let from = query.to;
198
+ for (let i = 0; i < PURCHASE_WINDOW_LIMIT; i++) {
199
+ const start = end - (exports.PURCHASE_WINDOW_DAYS - 1) * DAY;
200
+ from = yyyymmddOf(start);
201
+ const page = await this.cardPurchases({ ...query, from, to: yyyymmddOf(end) });
202
+ if (!page.items.length)
203
+ break;
204
+ pages.unshift(page);
205
+ end = start - DAY;
206
+ }
207
+ return { items: pages.flatMap(page => page.items), total: pages.reduce((sum, page) => sum + page.total, 0), from };
208
+ }
162
209
  /** The company's sales or purchase tax invoices between two days (YYYYMMDD), every tax type unless one is given. */
163
210
  async taxInvoices(query) {
164
211
  if (query.taxType === undefined) {
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Barobill's card purchases (`CardPurchaseHistory`) - the approvals the card company has settled, which are what its
3
+ * bill is made of. An approval with no purchase yet is not billed yet.
4
+ *
5
+ * How they come, read from the production server's IBK-issued BC card answers (2026-11-16):
6
+ * - `HistoryKey` is the purchase's own key; `ApprovalNum` and `ApprovalType` say which approval or cancel it settles.
7
+ * - `ApprovalDT` is the approval's time; `UseDate` is the purchase day (the day after the approval, as a rule).
8
+ * - `ApprovalAmount` is the amount in the card's currency, `ForeignApprovalAmount` the won of a foreign one - as the
9
+ * approvals. `Amount` comes 0; `Tax` is the VAT.
10
+ * - `IsPurchased` came true on every row.
11
+ */
12
+ export interface CardPurchaseLine {
13
+ historyKey: string;
14
+ kind: 'APPROVAL' | 'CANCEL';
15
+ approvalNumber: string;
16
+ /** The approval's time as the card company printed it - 'YYYY-MM-DD HH:mm:ss'. */
17
+ approvedLocalTime: string;
18
+ /** 'YYYY-MM-DD' */
19
+ purchasedOn: string;
20
+ /** Won, always positive; null when a foreign purchase has no won yet. */
21
+ amount: number | null;
22
+ taxAmount: number | null;
23
+ currency: string | null;
24
+ foreignAmount: number | null;
25
+ }
26
+ export interface CardPurchaseLines {
27
+ cardNumber: string;
28
+ periodStart: string;
29
+ periodEnd: string;
30
+ lines: CardPurchaseLine[];
31
+ }
32
+ export declare function cardPurchasesOf(cardNumber: string, items: readonly Record<string, any>[], period: {
33
+ from: string;
34
+ to: string;
35
+ }): CardPurchaseLines;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cardPurchasesOf = cardPurchasesOf;
4
+ const bank_lines_1 = require("./bank-lines");
5
+ const card_charges_1 = require("./card-charges");
6
+ const text = (value) => {
7
+ const one = typeof value === 'string' ? value.trim() : '';
8
+ return one ? one : null;
9
+ };
10
+ function cardPurchasesOf(cardNumber, items, period) {
11
+ const card = String(cardNumber).replace(/\D/g, '');
12
+ const lines = items
13
+ .filter(item => String(item.IsPurchased ?? 'true').trim() !== 'false')
14
+ .map(item => {
15
+ const own = String(item.CardNum ?? '').replace(/\D/g, '');
16
+ if (own && own !== card)
17
+ throw new Error(`Barobill answered a purchase of card ${own} for card ${card}`);
18
+ const currency = text(item.CurrencyCode) ?? 'KRW';
19
+ const abroad = currency !== 'KRW';
20
+ const charged = Math.abs((0, bank_lines_1.moneyOf)(item.ApprovalAmount, 'purchase amount'));
21
+ const won = abroad ? (text(item.ForeignApprovalAmount) === null ? null : Math.abs((0, bank_lines_1.moneyOf)(item.ForeignApprovalAmount, 'won amount'))) : charged;
22
+ const tax = abroad || text(item.Tax) === null ? null : Math.abs((0, bank_lines_1.moneyOf)(item.Tax, 'tax'));
23
+ return {
24
+ historyKey: String(item.HistoryKey ?? '').trim(),
25
+ kind: (0, card_charges_1.approvalKindOf)(item.ApprovalType),
26
+ approvalNumber: String(item.ApprovalNum ?? '').trim(),
27
+ approvedLocalTime: (0, bank_lines_1.localTimeOf)(item.ApprovalDT, 'approval time'),
28
+ purchasedOn: (0, bank_lines_1.localTimeOf)(item.UseDate, 'purchase day'),
29
+ amount: won,
30
+ taxAmount: tax,
31
+ currency: abroad ? currency : null,
32
+ foreignAmount: abroad ? charged : null
33
+ };
34
+ });
35
+ for (const line of lines) {
36
+ if (!line.historyKey)
37
+ throw new Error(`Barobill purchase of card ${card} on ${line.purchasedOn} has no history key`);
38
+ if (!line.approvalNumber)
39
+ throw new Error(`Barobill purchase of card ${card} on ${line.purchasedOn} has no approval number`);
40
+ }
41
+ return { cardNumber: card, periodStart: (0, bank_lines_1.dayOf)(period.from), periodEnd: (0, bank_lines_1.dayOf)(period.to), lines };
42
+ }
43
+ //# sourceMappingURL=card-purchases.js.map
@@ -3,5 +3,6 @@ export * from './service';
3
3
  export { BarobillClient, BarobillError } from './engine/connector/barobill-client';
4
4
  export * from './engine/rules/bank-lines';
5
5
  export * from './engine/rules/card-charges';
6
+ export * from './engine/rules/card-purchases';
6
7
  export * from './engine/rules/tax-invoices';
7
8
  export * from './engine/rules/period';
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "BarobillClient", { enumerable: true, get: functi
9
9
  Object.defineProperty(exports, "BarobillError", { enumerable: true, get: function () { return barobill_client_1.BarobillError; } });
10
10
  tslib_1.__exportStar(require("./engine/rules/bank-lines"), exports);
11
11
  tslib_1.__exportStar(require("./engine/rules/card-charges"), exports);
12
+ tslib_1.__exportStar(require("./engine/rules/card-purchases"), exports);
12
13
  tslib_1.__exportStar(require("./engine/rules/tax-invoices"), exports);
13
14
  tslib_1.__exportStar(require("./engine/rules/period"), exports);
14
15
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-barobill",
3
- "version": "10.1.282",
3
+ "version": "10.1.288",
4
4
  "main": "dist-server/index.js",
5
5
  "files": [
6
6
  "README.md",
@@ -36,8 +36,8 @@
36
36
  "probe": "tsc -p tsconfig.json && node scripts/probe.mjs"
37
37
  },
38
38
  "dependencies": {
39
- "@things-factory/integration-base": "^10.1.282",
40
- "@things-factory/shell": "^10.1.282"
39
+ "@things-factory/integration-base": "^10.1.283",
40
+ "@things-factory/shell": "^10.1.283"
41
41
  },
42
- "gitHead": "6a232e670bdb52e1420b1d33cdeeb37ceb0f26b8"
42
+ "gitHead": "78eaee46dd9b425ed845b02952b082f35a0faca7"
43
43
  }