@flowselections/floriday-klanten-module 1.0.106 → 1.0.110

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.
@@ -1,4 +1,5 @@
1
1
  import type { AccountingProvider, AccountingSyncResult } from "../types.js";
2
+ export declare const OUDE_EXACT_OPGERUIMD = "De oude Exact Online-koppeling is opgeruimd. Exact-gegevens komen nu uit de Exact-auth-module.";
2
3
  export declare function syncAllExactCustomers(): Promise<AccountingSyncResult>;
3
4
  export declare const exactProvider: AccountingProvider;
4
5
  //# sourceMappingURL=sync.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync.server.d.ts","sourceRoot":"","sources":["../../../../src/lib/accounting/exact/sync.server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AA4KlB,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAwB3E;AAED,eAAO,MAAM,aAAa,EAAE,kBAW3B,CAAC"}
1
+ {"version":3,"file":"sync.server.d.ts","sourceRoot":"","sources":["../../../../src/lib/accounting/exact/sync.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAKzE,eAAO,MAAM,oBAAoB,mGACiE,CAAC;AAEnG,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAG3E;AAED,eAAO,MAAM,aAAa,EAAE,kBAQ3B,CAAC"}
@@ -1,181 +1,17 @@
1
- import { supabaseAdmin } from "../../../integrations/supabase/client.server.js";
2
- import { ensureValidAccessToken, exactFetch } from "./client.server.js";
3
- import { mapExactAccount } from "./mapping.js";
4
- const SELECT_FIELDS = [
5
- "ID",
6
- "Code",
7
- "Name",
8
- "Email",
9
- "Phone",
10
- "Website",
11
- "VATNumber",
12
- "ChamberOfCommerce",
13
- "AddressLine1",
14
- "AddressLine2",
15
- "AddressLine3",
16
- "Postcode",
17
- "City",
18
- "Country",
19
- "Status",
20
- "Modified",
21
- ].join(",");
22
- async function* iterateAccounts(conn, modifiedSince) {
23
- const MAX_PAGES = 200;
24
- let nextUrl = null;
25
- const query = {
26
- $select: SELECT_FIELDS,
27
- $top: "60",
28
- };
29
- if (modifiedSince) {
30
- const iso = new Date(modifiedSince).toISOString().replace(/\.\d{3}Z$/, "");
31
- query.$filter = `Modified gt datetime'${iso}'`;
32
- }
33
- for (let page = 0; page < MAX_PAGES; page++) {
34
- let res;
35
- if (nextUrl) {
36
- const token = await ensureValidAccessToken(conn);
37
- res = await fetch(nextUrl, {
38
- headers: {
39
- Authorization: `Bearer ${token}`,
40
- Accept: "application/json",
41
- },
42
- });
43
- }
44
- else {
45
- res = await exactFetch(conn, "/crm/Accounts", { query });
46
- }
47
- if (!res.ok) {
48
- throw new Error(`Exact /crm/Accounts ${res.status}: ${await res
49
- .text()
50
- .catch(() => "")}`);
51
- }
52
- const json = (await res.json());
53
- const results = json?.d?.results ?? [];
54
- for (const a of results)
55
- yield a;
56
- if (!json?.d?.__next || results.length === 0)
57
- return;
58
- nextUrl = json.d.__next;
59
- }
60
- }
61
- async function syncOneConnection(conn) {
62
- const { data: state } = await supabaseAdmin
63
- .from("exact_sync_state")
64
- .select("last_modified_cursor")
65
- .eq("connection_id", conn.id)
66
- .maybeSingle();
67
- await supabaseAdmin.from("exact_sync_state").upsert({
68
- connection_id: conn.id,
69
- status: "running",
70
- last_error: null,
71
- updated_at: new Date().toISOString(),
72
- });
73
- let synced = 0;
74
- let maxModified = state?.last_modified_cursor ?? null;
75
- const batch = [];
76
- async function flush() {
77
- const rows = batch.filter((r) => r !== null);
78
- batch.length = 0;
79
- if (rows.length === 0)
80
- return;
81
- const customerRows = rows.map((r) => ({
82
- company_name: r.company_name,
83
- email: r.email,
84
- phone: r.phone,
85
- website: r.website,
86
- vat_number: r.vat_number,
87
- street: r.street,
88
- house_number: r.house_number,
89
- postal_code: r.postal_code,
90
- city: r.city,
91
- country: r.country,
92
- is_active: r.is_active,
93
- source: r.source,
94
- external_id: r.external_id,
95
- sync_status: r.sync_status,
96
- sync_error: null,
97
- last_synced_at: r.last_synced_at,
98
- custom_fields: r.custom_fields,
99
- }));
100
- const { error } = await supabaseAdmin
101
- .from("customers")
102
- .upsert(customerRows, { onConflict: "source,external_id" });
103
- if (error)
104
- throw new Error(`customers upsert: ${error.message}`);
105
- const cacheRows = rows.map((r) => ({
106
- connection_id: conn.id,
107
- exact_id: r.external_id,
108
- data: r.custom_fields.exact_raw,
109
- fetched_at: new Date().toISOString(),
110
- }));
111
- await supabaseAdmin.from("exact_customers_cache").upsert(cacheRows);
112
- synced += rows.length;
113
- }
114
- try {
115
- for await (const acc of iterateAccounts(conn, state?.last_modified_cursor ?? null)) {
116
- const mapped = mapExactAccount(acc);
117
- batch.push(mapped);
118
- if (acc.Modified) {
119
- if (!maxModified || new Date(acc.Modified) > new Date(maxModified)) {
120
- maxModified = acc.Modified;
121
- }
122
- }
123
- if (batch.length >= 100)
124
- await flush();
125
- }
126
- await flush();
127
- await supabaseAdmin.from("exact_sync_state").upsert({
128
- connection_id: conn.id,
129
- status: "idle",
130
- last_error: null,
131
- last_synced_at: new Date().toISOString(),
132
- last_modified_cursor: maxModified,
133
- updated_at: new Date().toISOString(),
134
- });
135
- }
136
- catch (err) {
137
- await supabaseAdmin.from("exact_sync_state").upsert({
138
- connection_id: conn.id,
139
- status: "error",
140
- last_error: err instanceof Error ? err.message : String(err),
141
- updated_at: new Date().toISOString(),
142
- });
143
- throw err;
144
- }
145
- return { synced };
146
- }
1
+ // De oude Exact Online-koppeling (eigen OAuth, exact_credentials, exact_sync_state) is opgeruimd;
2
+ // die tabellen bestaan niet meer. Exact-gegevens komen voortaan alleen uit de Exact-auth-module.
3
+ // Deze provider blijft bestaan zodat de providerlijst gelijk blijft, maar doet niets en meldt dat duidelijk.
4
+ export const OUDE_EXACT_OPGERUIMD = "De oude Exact Online-koppeling is opgeruimd. Exact-gegevens komen nu uit de Exact-auth-module.";
147
5
  export async function syncAllExactCustomers() {
148
- const { data: connections, error } = await supabaseAdmin
149
- .from("exact_connections")
150
- .select("*")
151
- .eq("status", "connected");
152
- if (error)
153
- throw new Error(`Exact connections lookup: ${error.message}`);
154
- const errors = [];
155
- let total = 0;
156
- for (const conn of connections ?? []) {
157
- try {
158
- const { synced } = await syncOneConnection(conn);
159
- total += synced;
160
- }
161
- catch (err) {
162
- errors.push({
163
- connectionId: conn.id,
164
- message: err instanceof Error ? err.message : String(err),
165
- });
166
- }
167
- }
168
- return { providerId: "exact", synced: total, errors };
6
+ console.warn(`[exact] sync overgeslagen: ${OUDE_EXACT_OPGERUIMD}`);
7
+ return { providerId: "exact", synced: 0, errors: [{ connectionId: "-", message: OUDE_EXACT_OPGERUIMD }] };
169
8
  }
170
9
  export const exactProvider = {
171
10
  id: "exact",
172
11
  label: "Exact Online",
12
+ // Geen actieve oude koppelingen meer: nooit een sync aanbieden.
173
13
  async countActiveConnections() {
174
- const { count } = await supabaseAdmin
175
- .from("exact_connections")
176
- .select("id", { count: "exact", head: true })
177
- .eq("status", "connected");
178
- return count ?? 0;
14
+ return 0;
179
15
  },
180
16
  syncAllCustomers: syncAllExactCustomers,
181
17
  };
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Klanten doorzetten via de boekhoud vertaal module i.p.v. rechtstreeks
3
+ * Twinfield (stap 3.3-1). Geen eigen kolom: `twinfield_connections` hoort
4
+ * niet bij deze module (geen migratie hier ooit, geen CREATE TABLE in
5
+ * schema/klanten.sql — die tabel is van de Twinfield-authenticatiemodule),
6
+ * dus net als de andere instellingen hierboven via de gedeelde app_settings.
7
+ */
8
+ export declare function boekhoudVertaalModuleAan(): Promise<boolean>;
1
9
  export interface WorkerRunResult {
2
10
  claimed: number;
3
11
  succeeded: number;
@@ -1 +1 @@
1
- {"version":3,"file":"worker.server.d.ts","sourceRoot":"","sources":["../../../../src/lib/accounting/twinfield/worker.server.ts"],"names":[],"mappings":"AA2FA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrD;AAED,wBAAsB,6BAA6B,CACjD,KAAK,SAAK,EACV,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,OAAO,CAAC,eAAe,CAAC,CAkR1B"}
1
+ {"version":3,"file":"worker.server.d.ts","sourceRoot":"","sources":["../../../../src/lib/accounting/twinfield/worker.server.ts"],"names":[],"mappings":"AA8CA;;;;;;GAMG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC,CAEjE;AA+CD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrD;AAED,wBAAsB,6BAA6B,CACjD,KAAK,SAAK,EACV,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,OAAO,CAAC,eAAe,CAAC,CAoT1B"}
@@ -32,6 +32,16 @@ async function readFreshnessMinutes() {
32
32
  const n = Number(raw);
33
33
  return Number.isFinite(n) && n > 0 ? n : 10;
34
34
  }
35
+ /**
36
+ * Klanten doorzetten via de boekhoud vertaal module i.p.v. rechtstreeks
37
+ * Twinfield (stap 3.3-1). Geen eigen kolom: `twinfield_connections` hoort
38
+ * niet bij deze module (geen migratie hier ooit, geen CREATE TABLE in
39
+ * schema/klanten.sql — die tabel is van de Twinfield-authenticatiemodule),
40
+ * dus net als de andere instellingen hierboven via de gedeelde app_settings.
41
+ */
42
+ export async function boekhoudVertaalModuleAan() {
43
+ return (await readAppSetting("klanten_boekhoud_vertaal_module_aan")) === "true";
44
+ }
35
45
  /**
36
46
  * Veldindeling (labels + masker) voor een kantoor uit de cache. Deze module
37
47
  * leest de cache alleen; de Twinfield-authenticatiemodule vult hem.
@@ -89,6 +99,41 @@ export async function runTwinfieldPushQueueInternal(limit = 25, customerId) {
89
99
  result.claimed = rows.length;
90
100
  if (rows.length === 0)
91
101
  return result;
102
+ // Stap 3.3-1: klanten doorzetten via de boekhoud vertaal module i.p.v.
103
+ // rechtstreeks Twinfield. Geen van de Twinfield-voorwaarden hieronder is
104
+ // van toepassing (geen koppeling, geen DEB-veldindeling, geen schrijfpoort,
105
+ // geen leesronde nodig): de vertaalmodule heeft haar eigen klantpoort (al
106
+ // gebouwd, stap 3.1-1b), dus deze tak staat vóór "Voorwaarde a".
107
+ if (await boekhoudVertaalModuleAan()) {
108
+ const { pushCustomerViaVertaalmodule } = await import("../vertaalmodule/push.server.js");
109
+ for (const row of rows) {
110
+ try {
111
+ if (!row.customer_id) {
112
+ await markSuccess(row.id, null);
113
+ result.skipped += 1;
114
+ continue;
115
+ }
116
+ const { data: customer, error: cErr } = await supabaseAdmin.from("customers").select("*").eq("id", row.customer_id).maybeSingle();
117
+ if (cErr)
118
+ throw new Error(cErr.message);
119
+ if (!customer) {
120
+ await markSuccess(row.id, null);
121
+ result.skipped += 1;
122
+ continue;
123
+ }
124
+ await pushCustomerViaVertaalmodule(row.customer_id, customer);
125
+ await markSuccess(row.id, null);
126
+ result.succeeded += 1;
127
+ }
128
+ catch (e) {
129
+ const msg = e instanceof Error ? e.message : String(e);
130
+ await markFailed(row.id, row.attempts, msg);
131
+ result.failed += 1;
132
+ result.errors.push({ queueId: row.id, message: msg });
133
+ }
134
+ }
135
+ return result;
136
+ }
92
137
  // Voorwaarde a: actieve koppeling met administratie.
93
138
  const conn = await loadActiveConnection(rows[0].connection_id ?? undefined);
94
139
  if (!conn) {
@@ -0,0 +1,72 @@
1
+ export interface CanonicalCustomerPayload {
2
+ erpCustomerId: string | null;
3
+ name: string;
4
+ isActive: boolean;
5
+ email: string | null;
6
+ website: string | null;
7
+ vatNumber: string | null;
8
+ cocNumber: string | null;
9
+ language: string | null;
10
+ address: {
11
+ type: string | null;
12
+ attentionTo: string | null;
13
+ contactPerson: string | null;
14
+ street: string | null;
15
+ houseNumber: string | null;
16
+ line1: string | null;
17
+ line2: string | null;
18
+ postcode: string | null;
19
+ city: string | null;
20
+ country: string | null;
21
+ countryIso: string | null;
22
+ phone: string | null;
23
+ fax: string | null;
24
+ };
25
+ financial: {
26
+ paymentTermDays: number | null;
27
+ receivableLedger: string | null;
28
+ vatCode: string | null;
29
+ eInvoicing: boolean;
30
+ billingEmail: string | null;
31
+ discountDays: number | null;
32
+ discountPercentage: number | null;
33
+ };
34
+ bank: {
35
+ iban: string | null;
36
+ bic: string | null;
37
+ holder: string | null;
38
+ name: string | null;
39
+ accountNumber: string | null;
40
+ addressLine1: string | null;
41
+ houseNumber: string | null;
42
+ postcode: string | null;
43
+ city: string | null;
44
+ country: string | null;
45
+ } | null;
46
+ creditManagement: {
47
+ creditLimit: null;
48
+ blocked: false;
49
+ blockedLocked: null;
50
+ blockedModified: null;
51
+ sendReminder: null;
52
+ reminderEmail: null;
53
+ creditManager: null;
54
+ creditManagerName: null;
55
+ creditManagerShortname: null;
56
+ };
57
+ }
58
+ type Row = Record<string, unknown>;
59
+ /**
60
+ * CanonicalCustomer voor de boekhoud vertaal module, uit een rij van
61
+ * `customers`. `financial.vatCode`/`receivableLedger` komen rechtstreeks van
62
+ * `twinfield_vat_code`/`ledger_account` — vandaag al pakketspecifieke
63
+ * Twinfield-waarden (geen neutrale ERP-code), een bekende beperking, net als
64
+ * bij Facturatie's btw-codes vóór stap 3.2; wordt pas een probleem als een
65
+ * ander pakket dan Twinfield via de vertaalmodule actief is.
66
+ * `creditManagement` is altijd leeg/standaard: het pakket is daar eigenaar
67
+ * van en leest dit nooit terug van de ERP-kant (zie boekhoud-vertaal-module's
68
+ * CanonicalCreditManagement-documentatie: "nooit versturen").
69
+ */
70
+ export declare function buildCanonicalCustomerPayload(customer: Row): CanonicalCustomerPayload;
71
+ export {};
72
+ //# sourceMappingURL=customer-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customer-payload.d.ts","sourceRoot":"","sources":["../../../../src/lib/accounting/vertaalmodule/customer-payload.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,wBAAwB;IACvC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;KACpB,CAAC;IACF,SAAS,EAAE;QACT,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;QAChC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,UAAU,EAAE,OAAO,CAAC;QACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;KACnC,CAAC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QACnB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,GAAG,IAAI,CAAC;IACT,gBAAgB,EAAE;QAChB,WAAW,EAAE,IAAI,CAAC;QAClB,OAAO,EAAE,KAAK,CAAC;QACf,aAAa,EAAE,IAAI,CAAC;QACpB,eAAe,EAAE,IAAI,CAAC;QACtB,YAAY,EAAE,IAAI,CAAC;QACnB,aAAa,EAAE,IAAI,CAAC;QACpB,aAAa,EAAE,IAAI,CAAC;QACpB,iBAAiB,EAAE,IAAI,CAAC;QACxB,sBAAsB,EAAE,IAAI,CAAC;KAC9B,CAAC;CACH;AAED,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAInC;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,GAAG,GAAG,wBAAwB,CA6DrF"}
@@ -0,0 +1,80 @@
1
+ // Stap 3.3-1: klant van de ERP-rij naar de vorm die de boekhoud vertaal
2
+ // module verwacht (CanonicalCustomer, zie boekhoud-vertaal-module's models.ts
3
+ // — zelf gespiegeld, geen npm-afhankelijkheid, zelfde patroon als Facturatie).
4
+ // Puur: geen I/O, dus zonder een echte database te testen.
5
+ import { toIsoCountry } from "../../countries.js";
6
+ const str = (v) => (typeof v === "string" && v.trim() ? v : null);
7
+ const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : null);
8
+ /**
9
+ * CanonicalCustomer voor de boekhoud vertaal module, uit een rij van
10
+ * `customers`. `financial.vatCode`/`receivableLedger` komen rechtstreeks van
11
+ * `twinfield_vat_code`/`ledger_account` — vandaag al pakketspecifieke
12
+ * Twinfield-waarden (geen neutrale ERP-code), een bekende beperking, net als
13
+ * bij Facturatie's btw-codes vóór stap 3.2; wordt pas een probleem als een
14
+ * ander pakket dan Twinfield via de vertaalmodule actief is.
15
+ * `creditManagement` is altijd leeg/standaard: het pakket is daar eigenaar
16
+ * van en leest dit nooit terug van de ERP-kant (zie boekhoud-vertaal-module's
17
+ * CanonicalCreditManagement-documentatie: "nooit versturen").
18
+ */
19
+ export function buildCanonicalCustomerPayload(customer) {
20
+ const hasBank = str(customer.bank_iban) || str(customer.bank_account_number);
21
+ return {
22
+ erpCustomerId: str(customer.id),
23
+ name: String(customer.company_name ?? ""),
24
+ isActive: customer.is_active !== false,
25
+ email: str(customer.email),
26
+ website: str(customer.website),
27
+ vatNumber: str(customer.vat_number),
28
+ cocNumber: str(customer.coc_number),
29
+ language: str(customer.language),
30
+ address: {
31
+ type: str(customer.address_type),
32
+ attentionTo: str(customer.attention_to),
33
+ contactPerson: str(customer.contact_person),
34
+ street: str(customer.street),
35
+ houseNumber: str(customer.house_number),
36
+ line1: str(customer.address_line1),
37
+ line2: str(customer.address_line2),
38
+ postcode: str(customer.postal_code),
39
+ city: str(customer.city),
40
+ country: str(customer.country),
41
+ countryIso: toIsoCountry(customer.country),
42
+ phone: str(customer.phone),
43
+ fax: str(customer.fax),
44
+ },
45
+ financial: {
46
+ paymentTermDays: num(customer.payment_term_days),
47
+ receivableLedger: str(customer.ledger_account),
48
+ vatCode: str(customer.twinfield_vat_code),
49
+ eInvoicing: customer.e_invoicing === true,
50
+ billingEmail: str(customer.billing_email),
51
+ discountDays: num(customer.discount_days),
52
+ discountPercentage: num(customer.discount_percentage),
53
+ },
54
+ bank: hasBank
55
+ ? {
56
+ iban: str(customer.bank_iban),
57
+ bic: str(customer.bank_bic),
58
+ holder: str(customer.bank_account_holder),
59
+ name: str(customer.bank_name),
60
+ accountNumber: str(customer.bank_account_number),
61
+ addressLine1: str(customer.bank_address_line1),
62
+ houseNumber: str(customer.bank_house_number),
63
+ postcode: str(customer.bank_postal_code),
64
+ city: str(customer.bank_city),
65
+ country: str(customer.bank_country),
66
+ }
67
+ : null,
68
+ creditManagement: {
69
+ creditLimit: null,
70
+ blocked: false,
71
+ blockedLocked: null,
72
+ blockedModified: null,
73
+ sendReminder: null,
74
+ reminderEmail: null,
75
+ creditManager: null,
76
+ creditManagerName: null,
77
+ creditManagerShortname: null,
78
+ },
79
+ };
80
+ }
@@ -0,0 +1,12 @@
1
+ export declare function fnv1a64Hex(input: string): string;
2
+ /**
3
+ * Plaatst de klant in de wachtrij van de boekhoud vertaal module
4
+ * (`customer:push`, al gebouwd in die module). idem_key bevat een hash van
5
+ * de inhoud (zelfde opzet als Twinfield's eigen idempotency_key met
6
+ * md5(NEW::text)): dezelfde, ongewijzigde klant levert dezelfde regel terug;
7
+ * een echte wijziging krijgt een nieuwe regel. p_vervang_oudere=true
8
+ * annuleert een eventuele, nog niet verwerkte eerdere aanvraag voor deze
9
+ * klant, zodat er nooit twee tegelijk openstaan.
10
+ */
11
+ export declare function pushCustomerViaVertaalmodule(customerId: string, customer: Record<string, unknown>): Promise<void>;
12
+ //# sourceMappingURL=push.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push.server.d.ts","sourceRoot":"","sources":["../../../../src/lib/accounting/vertaalmodule/push.server.ts"],"names":[],"mappings":"AAUA,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAShD;AAED;;;;;;;;GAQG;AACH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAYvH"}
@@ -0,0 +1,42 @@
1
+ // Stap 3.3-1: klant doorzetten via de boekhoud vertaal module, i.p.v.
2
+ // rechtstreeks Twinfield. Geen npm-afhankelijkheid op die module (nog niet
3
+ // gepubliceerd): rechtstreekse RPC bij naam, zelfde patroon als Facturatie.
4
+ import { supabaseAdmin } from "../../../integrations/supabase/client.server.js";
5
+ import { buildCanonicalCustomerPayload } from "./customer-payload.js";
6
+ // Simple, dependency-free, synchronous 64-bit FNV-1a hash used only for
7
+ // change-detection (not cryptographic) — zelfde techniek als Twinfield's
8
+ // eigen twinfield_last_hash (mapping.ts), hier los gehouden van die
9
+ // pakketspecifieke code.
10
+ export function fnv1a64Hex(input) {
11
+ let h = 0xcbf29ce484222325n;
12
+ const prime = 0x100000001b3n;
13
+ const mask = 0xffffffffffffffffn;
14
+ for (let i = 0; i < input.length; i++) {
15
+ h ^= BigInt(input.charCodeAt(i));
16
+ h = (h * prime) & mask;
17
+ }
18
+ return h.toString(16).padStart(16, "0");
19
+ }
20
+ /**
21
+ * Plaatst de klant in de wachtrij van de boekhoud vertaal module
22
+ * (`customer:push`, al gebouwd in die module). idem_key bevat een hash van
23
+ * de inhoud (zelfde opzet als Twinfield's eigen idempotency_key met
24
+ * md5(NEW::text)): dezelfde, ongewijzigde klant levert dezelfde regel terug;
25
+ * een echte wijziging krijgt een nieuwe regel. p_vervang_oudere=true
26
+ * annuleert een eventuele, nog niet verwerkte eerdere aanvraag voor deze
27
+ * klant, zodat er nooit twee tegelijk openstaan.
28
+ */
29
+ export async function pushCustomerViaVertaalmodule(customerId, customer) {
30
+ const payload = buildCanonicalCustomerPayload(customer);
31
+ const hash = fnv1a64Hex(JSON.stringify(payload));
32
+ const { error } = await supabaseAdmin.rpc("boekhoud_vertaal_outbox_plaatsen", {
33
+ p_entity_type: "customer",
34
+ p_entity_id: customerId,
35
+ p_action: "push",
36
+ p_idem_key: `customer:${customerId}:push:${hash}`,
37
+ p_payload: payload,
38
+ p_vervang_oudere: true,
39
+ });
40
+ if (error)
41
+ throw new Error(`Boekhoud vertaal module niet bereikbaar: ${error.message}`);
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-klanten-module",
3
- "version": "1.0.106",
3
+ "version": "1.0.110",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",