@open-mercato/gus-regon 0.0.0-stage → 0.11.1-develop.8910.1.d07a49d70a

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 (140) hide show
  1. package/.turbo/turbo-build.log +2 -0
  2. package/README.md +120 -2
  3. package/build.mjs +7 -0
  4. package/dist/index.js +2 -0
  5. package/dist/index.js.map +7 -0
  6. package/dist/modules/gus_regon/__integration__/TC-GUS-001.spec.js +22 -0
  7. package/dist/modules/gus_regon/__integration__/TC-GUS-001.spec.js.map +7 -0
  8. package/dist/modules/gus_regon/__integration__/TC-GUS-002.spec.js +15 -0
  9. package/dist/modules/gus_regon/__integration__/TC-GUS-002.spec.js.map +7 -0
  10. package/dist/modules/gus_regon/__integration__/TC-GUS-003.spec.js +32 -0
  11. package/dist/modules/gus_regon/__integration__/TC-GUS-003.spec.js.map +7 -0
  12. package/dist/modules/gus_regon/__integration__/TC-GUS-004.spec.js +37 -0
  13. package/dist/modules/gus_regon/__integration__/TC-GUS-004.spec.js.map +7 -0
  14. package/dist/modules/gus_regon/__integration__/TC-GUS-005.spec.js +74 -0
  15. package/dist/modules/gus_regon/__integration__/TC-GUS-005.spec.js.map +7 -0
  16. package/dist/modules/gus_regon/__integration__/helpers/fixtures.js +54 -0
  17. package/dist/modules/gus_regon/__integration__/helpers/fixtures.js.map +7 -0
  18. package/dist/modules/gus_regon/__integration__/meta.js +7 -0
  19. package/dist/modules/gus_regon/__integration__/meta.js.map +7 -0
  20. package/dist/modules/gus_regon/acl.js +9 -0
  21. package/dist/modules/gus_regon/acl.js.map +7 -0
  22. package/dist/modules/gus_regon/api/lookup/route.js +83 -0
  23. package/dist/modules/gus_regon/api/lookup/route.js.map +7 -0
  24. package/dist/modules/gus_regon/api/status/route.js +67 -0
  25. package/dist/modules/gus_regon/api/status/route.js.map +7 -0
  26. package/dist/modules/gus_regon/cli.js +102 -0
  27. package/dist/modules/gus_regon/cli.js.map +7 -0
  28. package/dist/modules/gus_regon/components/GusLookupFormWidget.js +78 -0
  29. package/dist/modules/gus_regon/components/GusLookupFormWidget.js.map +7 -0
  30. package/dist/modules/gus_regon/components/GusLookupPanel.js +94 -0
  31. package/dist/modules/gus_regon/components/GusLookupPanel.js.map +7 -0
  32. package/dist/modules/gus_regon/components/createGusLookupWidget.js +17 -0
  33. package/dist/modules/gus_regon/components/createGusLookupWidget.js.map +7 -0
  34. package/dist/modules/gus_regon/components/useGusStatus.js +40 -0
  35. package/dist/modules/gus_regon/components/useGusStatus.js.map +7 -0
  36. package/dist/modules/gus_regon/data/validators.js +38 -0
  37. package/dist/modules/gus_regon/data/validators.js.map +7 -0
  38. package/dist/modules/gus_regon/di.js +11 -0
  39. package/dist/modules/gus_regon/di.js.map +7 -0
  40. package/dist/modules/gus_regon/index.js +15 -0
  41. package/dist/modules/gus_regon/index.js.map +7 -0
  42. package/dist/modules/gus_regon/integration.js +62 -0
  43. package/dist/modules/gus_regon/integration.js.map +7 -0
  44. package/dist/modules/gus_regon/lib/client.js +116 -0
  45. package/dist/modules/gus_regon/lib/client.js.map +7 -0
  46. package/dist/modules/gus_regon/lib/config.js +30 -0
  47. package/dist/modules/gus_regon/lib/config.js.map +7 -0
  48. package/dist/modules/gus_regon/lib/health.js +62 -0
  49. package/dist/modules/gus_regon/lib/health.js.map +7 -0
  50. package/dist/modules/gus_regon/lib/lookup.js +43 -0
  51. package/dist/modules/gus_regon/lib/lookup.js.map +7 -0
  52. package/dist/modules/gus_regon/lib/mapping.js +54 -0
  53. package/dist/modules/gus_regon/lib/mapping.js.map +7 -0
  54. package/dist/modules/gus_regon/lib/nip.js +18 -0
  55. package/dist/modules/gus_regon/lib/nip.js.map +7 -0
  56. package/dist/modules/gus_regon/lib/parser.js +97 -0
  57. package/dist/modules/gus_regon/lib/parser.js.map +7 -0
  58. package/dist/modules/gus_regon/lib/preset.js +67 -0
  59. package/dist/modules/gus_regon/lib/preset.js.map +7 -0
  60. package/dist/modules/gus_regon/lib/status.js +30 -0
  61. package/dist/modules/gus_regon/lib/status.js.map +7 -0
  62. package/dist/modules/gus_regon/lib/types.js +1 -0
  63. package/dist/modules/gus_regon/lib/types.js.map +7 -0
  64. package/dist/modules/gus_regon/lib/visibility.js +12 -0
  65. package/dist/modules/gus_regon/lib/visibility.js.map +7 -0
  66. package/dist/modules/gus_regon/lib/widget-config.js +66 -0
  67. package/dist/modules/gus_regon/lib/widget-config.js.map +7 -0
  68. package/dist/modules/gus_regon/setup.js +33 -0
  69. package/dist/modules/gus_regon/setup.js.map +7 -0
  70. package/dist/modules/gus_regon/widgets/injection/company-lookup/widget.js +22 -0
  71. package/dist/modules/gus_regon/widgets/injection/company-lookup/widget.js.map +7 -0
  72. package/dist/modules/gus_regon/widgets/injection/integration-status/widget.client.js +43 -0
  73. package/dist/modules/gus_regon/widgets/injection/integration-status/widget.client.js.map +7 -0
  74. package/dist/modules/gus_regon/widgets/injection/integration-status/widget.js +16 -0
  75. package/dist/modules/gus_regon/widgets/injection/integration-status/widget.js.map +7 -0
  76. package/dist/modules/gus_regon/widgets/injection-table.js +16 -0
  77. package/dist/modules/gus_regon/widgets/injection-table.js.map +7 -0
  78. package/jest.config.cjs +32 -0
  79. package/package.json +99 -3
  80. package/src/index.ts +1 -0
  81. package/src/modules/gus_regon/__integration__/TC-GUS-001.spec.ts +30 -0
  82. package/src/modules/gus_regon/__integration__/TC-GUS-002.spec.ts +23 -0
  83. package/src/modules/gus_regon/__integration__/TC-GUS-003.spec.ts +48 -0
  84. package/src/modules/gus_regon/__integration__/TC-GUS-004.spec.ts +54 -0
  85. package/src/modules/gus_regon/__integration__/TC-GUS-005.spec.ts +98 -0
  86. package/src/modules/gus_regon/__integration__/helpers/fixtures.ts +68 -0
  87. package/src/modules/gus_regon/__integration__/meta.ts +3 -0
  88. package/src/modules/gus_regon/__tests__/client.test.ts +133 -0
  89. package/src/modules/gus_regon/__tests__/config.test.ts +33 -0
  90. package/src/modules/gus_regon/__tests__/fixtures/bir.ts +96 -0
  91. package/src/modules/gus_regon/__tests__/health.test.ts +45 -0
  92. package/src/modules/gus_regon/__tests__/injection-wiring.test.ts +25 -0
  93. package/src/modules/gus_regon/__tests__/integration-definition.test.ts +46 -0
  94. package/src/modules/gus_regon/__tests__/lookup.test.ts +177 -0
  95. package/src/modules/gus_regon/__tests__/mapping.test.ts +90 -0
  96. package/src/modules/gus_regon/__tests__/nip.test.ts +53 -0
  97. package/src/modules/gus_regon/__tests__/parser.test.ts +132 -0
  98. package/src/modules/gus_regon/__tests__/preset.test.ts +104 -0
  99. package/src/modules/gus_regon/__tests__/route.test.ts +101 -0
  100. package/src/modules/gus_regon/__tests__/status-route.test.ts +69 -0
  101. package/src/modules/gus_regon/__tests__/status.test.ts +64 -0
  102. package/src/modules/gus_regon/__tests__/useGusStatus.test.tsx +128 -0
  103. package/src/modules/gus_regon/__tests__/visibility.test.ts +24 -0
  104. package/src/modules/gus_regon/__tests__/widget-config.test.ts +96 -0
  105. package/src/modules/gus_regon/acl.ts +5 -0
  106. package/src/modules/gus_regon/api/lookup/route.ts +104 -0
  107. package/src/modules/gus_regon/api/status/route.ts +79 -0
  108. package/src/modules/gus_regon/cli.ts +117 -0
  109. package/src/modules/gus_regon/components/GusLookupFormWidget.tsx +115 -0
  110. package/src/modules/gus_regon/components/GusLookupPanel.tsx +135 -0
  111. package/src/modules/gus_regon/components/createGusLookupWidget.tsx +42 -0
  112. package/src/modules/gus_regon/components/useGusStatus.ts +50 -0
  113. package/src/modules/gus_regon/data/validators.ts +38 -0
  114. package/src/modules/gus_regon/di.ts +9 -0
  115. package/src/modules/gus_regon/i18n/de.json +44 -0
  116. package/src/modules/gus_regon/i18n/en.json +44 -0
  117. package/src/modules/gus_regon/i18n/es.json +44 -0
  118. package/src/modules/gus_regon/i18n/ko.json +44 -0
  119. package/src/modules/gus_regon/i18n/pl.json +44 -0
  120. package/src/modules/gus_regon/index.ts +13 -0
  121. package/src/modules/gus_regon/integration.ts +62 -0
  122. package/src/modules/gus_regon/lib/client.ts +157 -0
  123. package/src/modules/gus_regon/lib/config.ts +50 -0
  124. package/src/modules/gus_regon/lib/health.ts +77 -0
  125. package/src/modules/gus_regon/lib/lookup.ts +64 -0
  126. package/src/modules/gus_regon/lib/mapping.ts +100 -0
  127. package/src/modules/gus_regon/lib/nip.ts +28 -0
  128. package/src/modules/gus_regon/lib/parser.ts +130 -0
  129. package/src/modules/gus_regon/lib/preset.ts +107 -0
  130. package/src/modules/gus_regon/lib/status.ts +52 -0
  131. package/src/modules/gus_regon/lib/types.ts +14 -0
  132. package/src/modules/gus_regon/lib/visibility.ts +18 -0
  133. package/src/modules/gus_regon/lib/widget-config.ts +137 -0
  134. package/src/modules/gus_regon/setup.ts +33 -0
  135. package/src/modules/gus_regon/widgets/injection/company-lookup/widget.ts +29 -0
  136. package/src/modules/gus_regon/widgets/injection/integration-status/widget.client.tsx +57 -0
  137. package/src/modules/gus_regon/widgets/injection/integration-status/widget.ts +15 -0
  138. package/src/modules/gus_regon/widgets/injection-table.ts +22 -0
  139. package/tsconfig.json +9 -0
  140. package/watch.mjs +7 -0
@@ -0,0 +1,2 @@
1
+ [build:gus-regon] found 37 entry points
2
+ [build:gus-regon] built successfully
package/README.md CHANGED
@@ -1,3 +1,121 @@
1
- # Temporary Holding Version
1
+ # @open-mercato/gus-regon
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ GUS REGON company lookup for [Open Mercato](https://github.com/open-mercato/open-mercato): type a Polish NIP, click **Fetch from GUS** and get the company name and registered address (plus the REGON number) from the official GUS REGON registry (BIR1.1 API).
4
+
5
+ - Works for every registered entity — including businesses outside the VAT register (not covered by MF *Wykaz*).
6
+ - Fills **empty** fields only; values typed by the operator are never overwritten.
7
+ - Fail-open: when GUS is slow or down, the form keeps working and the operator fills fields manually.
8
+ - The API key is configured per organization in **Settings → Integrations**, stored encrypted, and never reaches the browser.
9
+
10
+ Spec: [`.ai/specs/2026-10-12-gus-regon-company-lookup.md`](https://github.com/open-mercato/open-mercato/blob/develop/.ai/specs/2026-10-12-gus-regon-company-lookup.md) · User guide: [`apps/docs/docs/user-guide/gus-regon.mdx`](https://github.com/open-mercato/open-mercato/blob/develop/apps/docs/docs/user-guide/gus-regon.mdx)
11
+
12
+ ## Install
13
+
14
+ The package ships with Open Mercato. In the monorepo app it is enabled in `apps/mercato/src/modules.ts`. In a standalone app created with `create-mercato-app`, uncomment it in `src/modules.ts`:
15
+
16
+ ```ts
17
+ { id: 'gus_regon', from: '@open-mercato/gus-regon' },
18
+ ```
19
+
20
+ Then run `yarn generate`. No migrations are needed — the package has no entities.
21
+
22
+ ## Configure
23
+
24
+ 1. Go to **Settings → Integrations → GUS REGON (BIR1)**.
25
+ 2. Choose the **Environment**:
26
+ - **Test** — GUS test registry with synthetic data. The API key is optional; without one the public GUS test key is used.
27
+ - **Production** — the real registry. Requires your own **BIR API key** (issued by GUS for the BIR1.1 API, see [api.stat.gov.pl](https://api.stat.gov.pl/Home/RegonApi)).
28
+ 3. **Show on CRM company forms** — off by default. Turn it on to add the "Fetch from GUS" card to the company create and edit forms. It only takes effect once an **API key is entered** (in Test you can enter the public GUS test key `abcde12345abcde12345`); the integration page shows why the card is hidden.
29
+ 4. Save and **enable** the integration. The health check logs in to BIR1 to confirm the key.
30
+
31
+ Users need the `gus_regon.lookup` feature (granted to superadmin, admin and employee by default).
32
+
33
+ ## Use
34
+
35
+ When **Show on CRM company forms** is on (and an API key is set), the customers company create and edit forms show a **Fetch data from GUS REGON** card above the fields (never on person forms). Enter a NIP (spaces, dashes and a `PL` prefix are accepted) and click **Fetch from GUS**:
36
+
37
+ | GUS | Company form |
38
+ |-----|--------------|
39
+ | `Nazwa` | Legal name, display name (when empty) |
40
+ | `Ulica`, `NrNieruchomosci`, `NrLokalu`, `KodPocztowy`, `Miejscowosc`, `Wojewodztwo` | One primary address — create form only, when no address exists yet |
41
+ | `Regon` | Shown in the card ("Found: … · REGON …"); the company form has no REGON field |
42
+
43
+ ## API
44
+
45
+ `GET /api/gus_regon/status` — requires `gus_regon.lookup`. Returns `{ enabled, environment, hasApiKey, lookupAvailable, companyFormsRequested, companyFormsActive }` (never the key). Widgets use it to stay hidden until the integration is usable.
46
+
47
+ `GET /api/gus_regon/lookup?nip=<nip>` — requires `gus_regon.lookup`.
48
+
49
+ | Status | Body |
50
+ |--------|------|
51
+ | 200 | `{ ok: true, company, candidates }` |
52
+ | 200 | `{ ok: false, reason: 'not_found' \| 'unavailable' \| 'not_configured' }` |
53
+ | 400 | Missing or invalid NIP, or user without an organization |
54
+ | 401 | Not authenticated |
55
+
56
+ `company`: `nip, regon, name, street, buildingNumber, flatNumber, postalCode, city, voivodeship, county, commune, type, endDate, country`.
57
+
58
+ ## Use in your own forms
59
+
60
+ The CRM company forms are built in (behind the switch above). To add the same "Fetch data from GUS REGON" card to **any other CrudForm** (e.g. a supplier form in your app module), declare a widget with a field map — no React code needed:
61
+
62
+ ```ts
63
+ // <your module>/widgets/injection/gus-supplier/widget.ts
64
+ import { createGusLookupWidget } from '@open-mercato/gus-regon/modules/gus_regon/components/createGusLookupWidget'
65
+
66
+ export default createGusLookupWidget({
67
+ id: 'purchasing.injection.gus-supplier',
68
+ nipField: 'taxId', // pre-fills the NIP input from the form
69
+ fields: {
70
+ name: 'name',
71
+ regon: 'regon',
72
+ streetLine: 'street', // "ul. Krucza 53/2"
73
+ postalCode: 'postalCode',
74
+ city: 'city',
75
+ country: 'country',
76
+ },
77
+ })
78
+ ```
79
+
80
+ ```ts
81
+ // <your module>/widgets/injection-table.ts
82
+ export const injectionTable = {
83
+ 'crud-form:purchasing.supplier': ['purchasing.injection.gus-supplier'],
84
+ }
85
+ ```
86
+
87
+ Run `yarn generate`. Mapped fields are filled only while empty. The card renders only when the GUS integration is enabled and usable for the organization (`gate: 'lookup'`, default); use `gate: 'companyForms'` to also require the switch and an API key.
88
+
89
+ | Config | Purpose |
90
+ |--------|---------|
91
+ | `id` | Widget id, `<module>.injection.<name>` |
92
+ | `fields` | GUS value → form field id(s): `name`, `nip`, `regon`, `street`, `streetLine`, `buildingNumber`, `flatNumber`, `postalCode`, `city`, `voivodeship`, `county`, `commune`, `country` |
93
+ | `apply` | Instead of `fields`: custom `(values, company, { t }) => { values, filled }` for complex forms |
94
+ | `nipField` | Form field that pre-fills the NIP input |
95
+ | `fieldLabels` | i18n keys for field names in the success message |
96
+ | `titleKey`, `descriptionKey` | i18n keys (or plain text) for the card heading and helper text |
97
+ | `visible` | `({ pathname, operation, values }) => boolean` when a spot is shared by several forms |
98
+ | `gate` | `'lookup'` (default) or `'companyForms'` |
99
+ | `features`, `requiredModules`, `priority` | ACL, module dependencies (always includes `gus_regon`, `integrations`), ordering |
100
+
101
+ For full control, embed the panel directly and map the result yourself:
102
+
103
+ ```tsx
104
+ import { GusLookupPanel } from '@open-mercato/gus-regon/modules/gus_regon/components/GusLookupPanel'
105
+
106
+ <GusLookupPanel initialNip={values.taxId} onCompany={(company) => { /* map onto your fields */ }} />
107
+ ```
108
+
109
+ ## Development
110
+
111
+ ```bash
112
+ yarn workspace @open-mercato/gus-regon build
113
+ yarn workspace @open-mercato/gus-regon typecheck
114
+ yarn workspace @open-mercato/gus-regon test
115
+ ```
116
+
117
+ Integration tests: `src/modules/gus_regon/__integration__/TC-GUS-001…005.spec.ts` (`yarn test:integration`).
118
+
119
+ ## License
120
+
121
+ MIT
package/build.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { dirname } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { buildPackage } from '../../scripts/build-package.mjs'
4
+
5
+ const packageDir = dirname(fileURLToPath(import.meta.url))
6
+
7
+ await buildPackage(packageDir, { name: 'gus-regon' })
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./modules/gus_regon/index.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export * from './modules/gus_regon/index'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,22 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { BAD_NIP, lookup, VALID_NIP } from "./helpers/fixtures.js";
4
+ test.describe("TC-GUS-001: GUS REGON lookup route guards", () => {
5
+ test("rejects unauthenticated requests", async ({ request }) => {
6
+ const response = await lookup(request, null, VALID_NIP);
7
+ expect(response.status()).toBe(401);
8
+ });
9
+ test("requires a nip query parameter", async ({ request }) => {
10
+ const token = await getAuthToken(request);
11
+ const response = await lookup(request, token);
12
+ expect(response.status()).toBe(400);
13
+ });
14
+ test("rejects a NIP with an invalid checksum", async ({ request }) => {
15
+ const token = await getAuthToken(request);
16
+ const response = await lookup(request, token, BAD_NIP);
17
+ expect(response.status()).toBe(400);
18
+ const body = await response.json();
19
+ expect(body.error).toMatch(/checksum/i);
20
+ });
21
+ });
22
+ //# sourceMappingURL=TC-GUS-001.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/gus_regon/__integration__/TC-GUS-001.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { BAD_NIP, lookup, VALID_NIP } from './helpers/fixtures'\n\n/**\n * TC-GUS-001: lookup route guards\n *\n * GET /api/gus_regon/lookup \u2014 401 without auth, 400 without a NIP,\n * 400 for a NIP with a bad checksum. No upstream call is made in any of these cases.\n */\ntest.describe('TC-GUS-001: GUS REGON lookup route guards', () => {\n test('rejects unauthenticated requests', async ({ request }) => {\n const response = await lookup(request, null, VALID_NIP)\n expect(response.status()).toBe(401)\n })\n\n test('requires a nip query parameter', async ({ request }) => {\n const token = await getAuthToken(request)\n const response = await lookup(request, token)\n expect(response.status()).toBe(400)\n })\n\n test('rejects a NIP with an invalid checksum', async ({ request }) => {\n const token = await getAuthToken(request)\n const response = await lookup(request, token, BAD_NIP)\n expect(response.status()).toBe(400)\n const body = (await response.json()) as { error?: string }\n expect(body.error).toMatch(/checksum/i)\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,SAAS,QAAQ,iBAAiB;AAQ3C,KAAK,SAAS,6CAA6C,MAAM;AAC/D,OAAK,oCAAoC,OAAO,EAAE,QAAQ,MAAM;AAC9D,UAAM,WAAW,MAAM,OAAO,SAAS,MAAM,SAAS;AACtD,WAAO,SAAS,OAAO,CAAC,EAAE,KAAK,GAAG;AAAA,EACpC,CAAC;AAED,OAAK,kCAAkC,OAAO,EAAE,QAAQ,MAAM;AAC5D,UAAM,QAAQ,MAAM,aAAa,OAAO;AACxC,UAAM,WAAW,MAAM,OAAO,SAAS,KAAK;AAC5C,WAAO,SAAS,OAAO,CAAC,EAAE,KAAK,GAAG;AAAA,EACpC,CAAC;AAED,OAAK,0CAA0C,OAAO,EAAE,QAAQ,MAAM;AACpE,UAAM,QAAQ,MAAM,aAAa,OAAO;AACxC,UAAM,WAAW,MAAM,OAAO,SAAS,OAAO,OAAO;AACrD,WAAO,SAAS,OAAO,CAAC,EAAE,KAAK,GAAG;AAClC,UAAM,OAAQ,MAAM,SAAS,KAAK;AAClC,WAAO,KAAK,KAAK,EAAE,QAAQ,WAAW;AAAA,EACxC,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,15 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { getIntegrationDetail } from "./helpers/fixtures.js";
4
+ test.describe("TC-GUS-002: GUS REGON integration registration", () => {
5
+ test("exposes environment, a secret API key and the company-forms switch as credential fields", async ({ request }) => {
6
+ const token = await getAuthToken(request, "superadmin");
7
+ const detail = await getIntegrationDetail(request, token);
8
+ expect(detail.integration.id).toBe("gus_regon");
9
+ const fields = detail.integration.credentials?.fields ?? [];
10
+ expect(fields.find((field) => field.key === "environment")?.type).toBe("select");
11
+ expect(fields.find((field) => field.key === "apiKey")?.type).toBe("secret");
12
+ expect(fields.find((field) => field.key === "showOnCompanyForms")?.type).toBe("boolean");
13
+ });
14
+ });
15
+ //# sourceMappingURL=TC-GUS-002.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/gus_regon/__integration__/TC-GUS-002.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { getIntegrationDetail } from './helpers/fixtures'\n\n/**\n * TC-GUS-002: integration registration\n *\n * The provider is registered in the integrations hub with the credential\n * fields rendered in Settings \u2192 Integrations (environment, secret API key,\n * \"Show on CRM company forms\" switch).\n */\ntest.describe('TC-GUS-002: GUS REGON integration registration', () => {\n test('exposes environment, a secret API key and the company-forms switch as credential fields', async ({ request }) => {\n const token = await getAuthToken(request, 'superadmin')\n const detail = await getIntegrationDetail(request, token)\n\n expect(detail.integration.id).toBe('gus_regon')\n const fields = detail.integration.credentials?.fields ?? []\n expect(fields.find((field) => field.key === 'environment')?.type).toBe('select')\n expect(fields.find((field) => field.key === 'apiKey')?.type).toBe('secret')\n expect(fields.find((field) => field.key === 'showOnCompanyForms')?.type).toBe('boolean')\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AASrC,KAAK,SAAS,kDAAkD,MAAM;AACpE,OAAK,2FAA2F,OAAO,EAAE,QAAQ,MAAM;AACrH,UAAM,QAAQ,MAAM,aAAa,SAAS,YAAY;AACtD,UAAM,SAAS,MAAM,qBAAqB,SAAS,KAAK;AAExD,WAAO,OAAO,YAAY,EAAE,EAAE,KAAK,WAAW;AAC9C,UAAM,SAAS,OAAO,YAAY,aAAa,UAAU,CAAC;AAC1D,WAAO,OAAO,KAAK,CAAC,UAAU,MAAM,QAAQ,aAAa,GAAG,IAAI,EAAE,KAAK,QAAQ;AAC/E,WAAO,OAAO,KAAK,CAAC,UAAU,MAAM,QAAQ,QAAQ,GAAG,IAAI,EAAE,KAAK,QAAQ;AAC1E,WAAO,OAAO,KAAK,CAAC,UAAU,MAAM,QAAQ,oBAAoB,GAAG,IAAI,EAAE,KAAK,SAAS;AAAA,EACzF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,32 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import {
4
+ lookup,
5
+ restoreIntegration,
6
+ saveCredentials,
7
+ setIntegrationEnabled,
8
+ snapshotIntegration,
9
+ VALID_NIP
10
+ } from "./helpers/fixtures.js";
11
+ test.describe("TC-GUS-003: GUS REGON fail-open lookup contract", () => {
12
+ test("reports not_configured for a disabled integration and for production without a key", async ({ request }) => {
13
+ const token = await getAuthToken(request, "superadmin");
14
+ const snapshot = await snapshotIntegration(request, token);
15
+ test.skip(snapshot.credentials === null, "Integration credentials cannot be read on this environment");
16
+ test.skip(snapshot.apiKeyConfigured, "A GUS API key is already configured on this environment");
17
+ try {
18
+ await setIntegrationEnabled(request, token, false);
19
+ const disabled = await lookup(request, token, VALID_NIP);
20
+ expect(disabled.status()).toBe(200);
21
+ expect(await disabled.json()).toEqual({ ok: false, reason: "not_configured" });
22
+ await saveCredentials(request, token, { environment: "production", apiKey: "" });
23
+ await setIntegrationEnabled(request, token, true);
24
+ const missingKey = await lookup(request, token, VALID_NIP);
25
+ expect(missingKey.status()).toBe(200);
26
+ expect(await missingKey.json()).toEqual({ ok: false, reason: "not_configured" });
27
+ } finally {
28
+ await restoreIntegration(request, token, snapshot);
29
+ }
30
+ });
31
+ });
32
+ //# sourceMappingURL=TC-GUS-003.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/gus_regon/__integration__/TC-GUS-003.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport {\n lookup,\n restoreIntegration,\n saveCredentials,\n setIntegrationEnabled,\n snapshotIntegration,\n VALID_NIP,\n} from './helpers/fixtures'\n\n/**\n * TC-GUS-003: fail-open lookup contract\n *\n * - Disabled integration \u2192 200 { ok:false, reason:'not_configured' }.\n * - Production without an API key \u2192 200 { ok:false, reason:'not_configured' }.\n *\n * Neither case reaches the GUS endpoint, so the test does not depend on the\n * external service. Rejected keys and upstream outages are covered by the unit\n * tests of the lookup and the route.\n *\n * Self-contained: the integration state and credentials are restored in `finally`.\n * Skips itself when a real API key is configured or credentials cannot be read,\n * so it never clobbers a shared environment.\n */\ntest.describe('TC-GUS-003: GUS REGON fail-open lookup contract', () => {\n test('reports not_configured for a disabled integration and for production without a key', async ({ request }) => {\n const token = await getAuthToken(request, 'superadmin')\n const snapshot = await snapshotIntegration(request, token)\n test.skip(snapshot.credentials === null, 'Integration credentials cannot be read on this environment')\n test.skip(snapshot.apiKeyConfigured, 'A GUS API key is already configured on this environment')\n\n try {\n await setIntegrationEnabled(request, token, false)\n const disabled = await lookup(request, token, VALID_NIP)\n expect(disabled.status()).toBe(200)\n expect(await disabled.json()).toEqual({ ok: false, reason: 'not_configured' })\n\n await saveCredentials(request, token, { environment: 'production', apiKey: '' })\n await setIntegrationEnabled(request, token, true)\n const missingKey = await lookup(request, token, VALID_NIP)\n expect(missingKey.status()).toBe(200)\n expect(await missingKey.json()).toEqual({ ok: false, reason: 'not_configured' })\n } finally {\n await restoreIntegration(request, token, snapshot)\n }\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgBP,KAAK,SAAS,mDAAmD,MAAM;AACrE,OAAK,sFAAsF,OAAO,EAAE,QAAQ,MAAM;AAChH,UAAM,QAAQ,MAAM,aAAa,SAAS,YAAY;AACtD,UAAM,WAAW,MAAM,oBAAoB,SAAS,KAAK;AACzD,SAAK,KAAK,SAAS,gBAAgB,MAAM,4DAA4D;AACrG,SAAK,KAAK,SAAS,kBAAkB,yDAAyD;AAE9F,QAAI;AACF,YAAM,sBAAsB,SAAS,OAAO,KAAK;AACjD,YAAM,WAAW,MAAM,OAAO,SAAS,OAAO,SAAS;AACvD,aAAO,SAAS,OAAO,CAAC,EAAE,KAAK,GAAG;AAClC,aAAO,MAAM,SAAS,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,OAAO,QAAQ,iBAAiB,CAAC;AAE7E,YAAM,gBAAgB,SAAS,OAAO,EAAE,aAAa,cAAc,QAAQ,GAAG,CAAC;AAC/E,YAAM,sBAAsB,SAAS,OAAO,IAAI;AAChD,YAAM,aAAa,MAAM,OAAO,SAAS,OAAO,SAAS;AACzD,aAAO,WAAW,OAAO,CAAC,EAAE,KAAK,GAAG;AACpC,aAAO,MAAM,WAAW,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,OAAO,QAAQ,iBAAiB,CAAC;AAAA,IACjF,UAAE;AACA,YAAM,mBAAmB,SAAS,OAAO,QAAQ;AAAA,IACnD;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,37 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { restoreIntegration, saveCredentials, setIntegrationEnabled, snapshotIntegration } from "./helpers/fixtures.js";
4
+ test.describe("TC-GUS-004: GUS REGON CRM company card gating", () => {
5
+ test("is off by default, requires an API key, and follows the integration state", async ({ request }) => {
6
+ const token = await getAuthToken(request, "superadmin");
7
+ const snapshot = await snapshotIntegration(request, token);
8
+ test.skip(snapshot.credentials === null, "Integration credentials cannot be read on this environment");
9
+ test.skip(snapshot.apiKeyConfigured, "A GUS API key is already configured on this environment");
10
+ const readStatus = async () => {
11
+ const response = await apiRequest(request, "GET", "/api/gus_regon/status", { token });
12
+ expect(response.status()).toBe(200);
13
+ const raw = await response.text();
14
+ return { raw, body: JSON.parse(raw) };
15
+ };
16
+ try {
17
+ await saveCredentials(request, token, { environment: "test" });
18
+ await setIntegrationEnabled(request, token, true);
19
+ let status = await readStatus();
20
+ expect(status.body).toMatchObject({ enabled: true, lookupAvailable: true, companyFormsRequested: false, companyFormsActive: false });
21
+ await saveCredentials(request, token, { environment: "test", showOnCompanyForms: true });
22
+ status = await readStatus();
23
+ expect(status.body).toMatchObject({ hasApiKey: false, companyFormsRequested: true, companyFormsActive: false });
24
+ const key = "abcde12345abcde12345";
25
+ await saveCredentials(request, token, { environment: "test", apiKey: key, showOnCompanyForms: true });
26
+ status = await readStatus();
27
+ expect(status.body).toMatchObject({ hasApiKey: true, companyFormsActive: true });
28
+ expect(status.raw).not.toContain(key);
29
+ await setIntegrationEnabled(request, token, false);
30
+ status = await readStatus();
31
+ expect(status.body).toMatchObject({ enabled: false, companyFormsActive: false });
32
+ } finally {
33
+ await restoreIntegration(request, token, snapshot);
34
+ }
35
+ });
36
+ });
37
+ //# sourceMappingURL=TC-GUS-004.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/gus_regon/__integration__/TC-GUS-004.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { restoreIntegration, saveCredentials, setIntegrationEnabled, snapshotIntegration } from './helpers/fixtures'\n\n/**\n * TC-GUS-004: CRM company card gating (GET /api/gus_regon/status)\n *\n * - Off by default (switch not set).\n * - Switch on without an API key \u2192 still off (missing key), even in Test.\n * - Switch on with an API key and the integration enabled \u2192 on.\n * - Integration disabled \u2192 off.\n * - The key is never returned.\n *\n * Self-contained: state and credentials are restored in `finally`; skips when a\n * real API key is configured or credentials cannot be read.\n */\ntest.describe('TC-GUS-004: GUS REGON CRM company card gating', () => {\n test('is off by default, requires an API key, and follows the integration state', async ({ request }) => {\n const token = await getAuthToken(request, 'superadmin')\n const snapshot = await snapshotIntegration(request, token)\n test.skip(snapshot.credentials === null, 'Integration credentials cannot be read on this environment')\n test.skip(snapshot.apiKeyConfigured, 'A GUS API key is already configured on this environment')\n\n const readStatus = async () => {\n const response = await apiRequest(request, 'GET', '/api/gus_regon/status', { token })\n expect(response.status()).toBe(200)\n const raw = await response.text()\n return { raw, body: JSON.parse(raw) as Record<string, unknown> }\n }\n\n try {\n await saveCredentials(request, token, { environment: 'test' })\n await setIntegrationEnabled(request, token, true)\n let status = await readStatus()\n expect(status.body).toMatchObject({ enabled: true, lookupAvailable: true, companyFormsRequested: false, companyFormsActive: false })\n\n await saveCredentials(request, token, { environment: 'test', showOnCompanyForms: true })\n status = await readStatus()\n expect(status.body).toMatchObject({ hasApiKey: false, companyFormsRequested: true, companyFormsActive: false })\n\n const key = 'abcde12345abcde12345'\n await saveCredentials(request, token, { environment: 'test', apiKey: key, showOnCompanyForms: true })\n status = await readStatus()\n expect(status.body).toMatchObject({ hasApiKey: true, companyFormsActive: true })\n expect(status.raw).not.toContain(key)\n\n await setIntegrationEnabled(request, token, false)\n status = await readStatus()\n expect(status.body).toMatchObject({ enabled: false, companyFormsActive: false })\n } finally {\n await restoreIntegration(request, token, snapshot)\n }\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,YAAY,oBAAoB;AACzC,SAAS,oBAAoB,iBAAiB,uBAAuB,2BAA2B;AAchG,KAAK,SAAS,iDAAiD,MAAM;AACnE,OAAK,6EAA6E,OAAO,EAAE,QAAQ,MAAM;AACvG,UAAM,QAAQ,MAAM,aAAa,SAAS,YAAY;AACtD,UAAM,WAAW,MAAM,oBAAoB,SAAS,KAAK;AACzD,SAAK,KAAK,SAAS,gBAAgB,MAAM,4DAA4D;AACrG,SAAK,KAAK,SAAS,kBAAkB,yDAAyD;AAE9F,U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from "@open-mercato/core/helpers/integration/auth";
3
+ import { getAuthToken } from "@open-mercato/core/helpers/integration/api";
4
+ import {
5
+ restoreIntegration,
6
+ saveCredentials,
7
+ setIntegrationEnabled,
8
+ snapshotIntegration,
9
+ VALID_NIP
10
+ } from "./helpers/fixtures.js";
11
+ const COMPANY_NAME = "GOOGLE POLAND SP\xD3\u0141KA Z OGRANICZON\u0104 ODPOWIEDZIALNO\u015ACI\u0104";
12
+ function crudField(page, fieldId) {
13
+ return page.locator(`[data-crud-field-id="${fieldId}"]`).getByRole("textbox");
14
+ }
15
+ function gusCard(page) {
16
+ return page.getByRole("region", { name: "Fetch data from GUS REGON" });
17
+ }
18
+ function stubLookup(page) {
19
+ return page.route("**/api/gus_regon/lookup?**", async (route) => {
20
+ const company = {
21
+ nip: VALID_NIP,
22
+ regon: "140182840",
23
+ name: COMPANY_NAME,
24
+ street: "ul. Test-Krucza",
25
+ buildingNumber: "53",
26
+ flatNumber: null,
27
+ postalCode: "00-113",
28
+ city: "Warszawa",
29
+ voivodeship: "MAZOWIECKIE",
30
+ county: "m. st. Warszawa",
31
+ commune: "\u015Ar\xF3dmie\u015Bcie",
32
+ type: "P",
33
+ endDate: null,
34
+ country: "PL"
35
+ };
36
+ await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ ok: true, company, candidates: [company] }) });
37
+ });
38
+ }
39
+ test.describe("TC-GUS-005: GUS REGON card on CRM company forms", () => {
40
+ let token = null;
41
+ let snapshot = null;
42
+ test.afterEach(async ({ request }) => {
43
+ if (token && snapshot) await restoreIntegration(request, token, snapshot);
44
+ token = null;
45
+ snapshot = null;
46
+ });
47
+ test("is opt-in, shown only on company forms, and fills empty fields", async ({ page, request }) => {
48
+ const authToken = await getAuthToken(request, "superadmin");
49
+ const initial = await snapshotIntegration(request, authToken);
50
+ test.skip(initial.credentials === null, "Integration credentials cannot be read on this environment");
51
+ test.skip(initial.apiKeyConfigured, "A GUS API key is already configured on this environment");
52
+ token = authToken;
53
+ snapshot = initial;
54
+ await saveCredentials(request, authToken, { environment: "test", apiKey: "abcde12345abcde12345", showOnCompanyForms: false });
55
+ await setIntegrationEnabled(request, authToken, true);
56
+ await login(page, "superadmin");
57
+ await page.goto("/backend/customers/companies/create");
58
+ await expect(crudField(page, "displayName")).toBeVisible();
59
+ await expect(gusCard(page)).toHaveCount(0);
60
+ await saveCredentials(request, authToken, { environment: "test", apiKey: "abcde12345abcde12345", showOnCompanyForms: true });
61
+ await stubLookup(page);
62
+ await page.goto("/backend/customers/people/create");
63
+ await expect(crudField(page, "firstName")).toBeVisible();
64
+ await expect(gusCard(page)).toHaveCount(0);
65
+ await page.goto("/backend/customers/companies/create");
66
+ await expect(gusCard(page)).toBeVisible();
67
+ await gusCard(page).getByLabel("NIP").fill(VALID_NIP);
68
+ await gusCard(page).getByRole("button", { name: "Fetch from GUS" }).click();
69
+ await expect(gusCard(page).getByText("REGON 140182840")).toBeVisible();
70
+ await expect(crudField(page, "displayName")).toHaveValue(COMPANY_NAME);
71
+ await expect(crudField(page, "legalName")).toHaveValue(COMPANY_NAME);
72
+ });
73
+ });
74
+ //# sourceMappingURL=TC-GUS-005.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/gus_regon/__integration__/TC-GUS-005.spec.ts"],
4
+ "sourcesContent": ["import { expect, test, type Page } from '@playwright/test'\nimport { login } from '@open-mercato/core/helpers/integration/auth'\nimport { getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport {\n restoreIntegration,\n saveCredentials,\n setIntegrationEnabled,\n snapshotIntegration,\n VALID_NIP,\n type IntegrationSnapshot,\n} from './helpers/fixtures'\n\n/**\n * TC-GUS-005: CRM company card (UI)\n *\n * - Switch off \u2192 no \"Fetch data from GUS REGON\" card on the company create form.\n * - Switch on + API key \u2192 card shown on the company create form, not on the person create form.\n * - \"Fetch from GUS\" fills empty Display name / Legal name.\n *\n * The lookup response is stubbed in the browser (`page.route`) with the\n * test-registry payload, so the test does not depend on GUS availability.\n * State and credentials are restored in `afterEach`; skips when a real key is configured.\n */\n\nconst COMPANY_NAME = 'GOOGLE POLAND SP\u00D3\u0141KA Z OGRANICZON\u0104 ODPOWIEDZIALNO\u015ACI\u0104'\n\n/** CrudForm labels are not bound to inputs; target the field wrapper by its id. */\nfunction crudField(page: Page, fieldId: string) {\n return page.locator(`[data-crud-field-id=\"${fieldId}\"]`).getByRole('textbox')\n}\n\nfunction gusCard(page: Page) {\n return page.getByRole('region', { name: 'Fetch data from GUS REGON' })\n}\n\nfunction stubLookup(page: Page) {\n return page.route('**/api/gus_regon/lookup?**', async (route) => {\n const company = {\n nip: VALID_NIP,\n regon: '140182840',\n name: COMPANY_NAME,\n street: 'ul. Test-Krucza',\n buildingNumber: '53',\n flatNumber: null,\n postalCode: '00-113',\n city: 'Warszawa',\n voivodeship: 'MAZOWIECKIE',\n county: 'm. st. Warszawa',\n commune: '\u015Ar\u00F3dmie\u015Bcie',\n type: 'P',\n endDate: null,\n country: 'PL',\n }\n await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ ok: true, company, candidates: [company] }) })\n })\n}\n\ntest.describe('TC-GUS-005: GUS REGON card on CRM company forms', () => {\n let token: string | null = null\n let snapshot: IntegrationSnapshot | null = null\n\n test.afterEach(async ({ request }) => {\n if (token && snapshot) await restoreIntegration(request, token, snapshot)\n token = null\n snapshot = null\n })\n\n test('is opt-in, shown only on company forms, and fills empty fields', async ({ page, request }) => {\n const authToken = await getAuthToken(request, 'superadmin')\n const initial = await snapshotIntegration(request, authToken)\n test.skip(initial.credentials === null, 'Integration credentials cannot be read on this environment')\n test.skip(initial.apiKeyConfigured, 'A GUS API key is already configured on this environment')\n token = authToken\n snapshot = initial\n\n await saveCredentials(request, authToken, { environment: 'test', apiKey: 'abcde12345abcde12345', showOnCompanyForms: false })\n await setIntegrationEnabled(request, authToken, true)\n\n await login(page, 'superadmin')\n await page.goto('/backend/customers/companies/create')\n await expect(crudField(page, 'displayName')).toBeVisible()\n await expect(gusCard(page)).toHaveCount(0)\n\n await saveCredentials(request, authToken, { environment: 'test', apiKey: 'abcde12345abcde12345', showOnCompanyForms: true })\n await stubLookup(page)\n await page.goto('/backend/customers/people/create')\n await expect(crudField(page, 'firstName')).toBeVisible()\n await expect(gusCard(page)).toHaveCount(0)\n\n await page.goto('/backend/customers/companies/create')\n await expect(gusCard(page)).toBeVisible()\n await gusCard(page).getByLabel('NIP').fill(VALID_NIP)\n await gusCard(page).getByRole('button', { name: 'Fetch from GUS' }).click()\n await expect(gusCard(page).getByText('REGON 140182840')).toBeVisible()\n await expect(crudField(page, 'displayName')).toHaveValue(COMPANY_NAME)\n await expect(crudField(page, 'legalName')).toHaveValue(COMPANY_NAME)\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAuB;AACxC,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAcP,MAAM,eAAe;AAGrB,SAAS,UAAU,MAAY,SAAiB;AAC9C,SAAO,KAAK,QAAQ,wBAAwB,OAAO,IAAI,EAAE,UAAU,SAAS;AAC9E;AAEA,SAAS,QAAQ,MAAY;AAC3B,SAAO,KAAK,UAAU,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACvE;AAEA,SAAS,WAAW,MAAY;AAC9B,SAAO,KAAK,MAAM,8BAA8B,OAAO,UAAU;AAC/D,UAAM,UAAU;AAAA,MACd,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,aAAa;AAAA,MACb,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AACA,UAAM,MAAM,QAAQ,EAAE,QAAQ,KAAK,aAAa,oBAAoB,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QAAQ,IAAI,EAAE,WAAW,KAAK,EAAE,KAAK,SAAS;AACpD,UAAM,QAAQ,IAAI,EAAE,UAAU,UAAU,EAAE,MAAM,iBAAiB,CAAC,EAAE,MAAM;AAC1E,UAAM,OAAO,QAAQ,IAAI,EAAE,UAAU,iBAAiB,CAAC,EAAE,YAAY;AACrE,UAAM,OAAO,UAAU,MAAM,aAAa,CAAC,EAAE,YAAY,YAAY;AACrE,UAAM,OAAO,UAAU,MAAM,WAAW,CAAC,EAAE,YAAY,YAAY;AAAA,EACrE,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,54 @@
1
+ import { expect } from "@playwright/test";
2
+ import { apiRequest } from "@open-mercato/core/helpers/integration/api";
3
+ const INTEGRATION_ID = "gus_regon";
4
+ const VALID_NIP = "5252344078";
5
+ const BAD_NIP = "5252344079";
6
+ async function getIntegrationDetail(request, token) {
7
+ const response = await apiRequest(request, "GET", `/api/integrations/${INTEGRATION_ID}`, { token });
8
+ expect(response.status()).toBe(200);
9
+ return await response.json();
10
+ }
11
+ async function snapshotIntegration(request, token) {
12
+ const detail = await getIntegrationDetail(request, token);
13
+ const credentialsResponse = await apiRequest(request, "GET", `/api/integrations/${INTEGRATION_ID}/credentials`, { token });
14
+ const credentialsBody = credentialsResponse.ok() ? await credentialsResponse.json() : null;
15
+ const apiKeyConfigured = credentialsBody?.secretFieldsConfigured?.apiKey === true;
16
+ const credentials = credentialsBody?.credentials ? { ...credentialsBody.credentials } : null;
17
+ if (credentials) delete credentials.apiKey;
18
+ return { isEnabled: detail.state.isEnabled, credentials, apiKeyConfigured };
19
+ }
20
+ async function setIntegrationEnabled(request, token, isEnabled) {
21
+ const response = await apiRequest(request, "PUT", `/api/integrations/${INTEGRATION_ID}/state`, {
22
+ token,
23
+ data: { isEnabled }
24
+ });
25
+ expect(response.ok()).toBe(true);
26
+ }
27
+ async function saveCredentials(request, token, credentials) {
28
+ const response = await apiRequest(request, "PUT", `/api/integrations/${INTEGRATION_ID}/credentials`, {
29
+ token,
30
+ data: { credentials }
31
+ });
32
+ expect(response.ok()).toBe(true);
33
+ }
34
+ async function restoreIntegration(request, token, snapshot) {
35
+ await saveCredentials(request, token, snapshot.credentials ?? {});
36
+ await setIntegrationEnabled(request, token, snapshot.isEnabled);
37
+ }
38
+ async function lookup(request, token, nip) {
39
+ const path = nip === void 0 ? "/api/gus_regon/lookup" : `/api/gus_regon/lookup?nip=${encodeURIComponent(nip)}`;
40
+ if (!token) return request.get(path.startsWith("http") ? path : `${process.env.BASE_URL?.trim() ?? ""}${path}`);
41
+ return apiRequest(request, "GET", path, { token });
42
+ }
43
+ export {
44
+ BAD_NIP,
45
+ INTEGRATION_ID,
46
+ VALID_NIP,
47
+ getIntegrationDetail,
48
+ lookup,
49
+ restoreIntegration,
50
+ saveCredentials,
51
+ setIntegrationEnabled,
52
+ snapshotIntegration
53
+ };
54
+ //# sourceMappingURL=fixtures.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/modules/gus_regon/__integration__/helpers/fixtures.ts"],
4
+ "sourcesContent": ["import { expect, type APIRequestContext } from '@playwright/test'\nimport { apiRequest } from '@open-mercato/core/helpers/integration/api'\n\nexport const INTEGRATION_ID = 'gus_regon'\n/** Valid checksum; the real NIP of a test-registry record. */\nexport const VALID_NIP = '5252344078'\n/** Invalid checksum. */\nexport const BAD_NIP = '5252344079'\n\nexport type IntegrationSnapshot = {\n isEnabled: boolean\n /** Non-secret credential values; `null` when they could not be read \u2014 callers must not mutate the environment then. */\n credentials: Record<string, unknown> | null\n /** The API key is write-only; a configured key cannot be restored, so tests skip instead of overwriting it. */\n apiKeyConfigured: boolean\n}\n\nexport async function getIntegrationDetail(request: APIRequestContext, token: string) {\n const response = await apiRequest(request, 'GET', `/api/integrations/${INTEGRATION_ID}`, { token })\n expect(response.status()).toBe(200)\n return (await response.json()) as {\n integration: { id: string; credentials?: { fields: Array<{ key: string; type: string }> } }\n state: { isEnabled: boolean }\n hasCredentials: boolean\n }\n}\n\nexport async function snapshotIntegration(request: APIRequestContext, token: string): Promise<IntegrationSnapshot> {\n const detail = await getIntegrationDetail(request, token)\n const credentialsResponse = await apiRequest(request, 'GET', `/api/integrations/${INTEGRATION_ID}/credentials`, { token })\n const credentialsBody = credentialsResponse.ok()\n ? ((await credentialsResponse.json()) as {\n credentials?: Record<string, unknown> | null\n secretFieldsConfigured?: Record<string, boolean>\n })\n : null\n const apiKeyConfigured = credentialsBody?.secretFieldsConfigured?.apiKey === true\n const credentials = credentialsBody?.credentials ? { ...credentialsBody.credentials } : null\n if (credentials) delete credentials.apiKey\n return { isEnabled: detail.state.isEnabled, credentials, apiKeyConfigured }\n}\n\nexport async function setIntegrationEnabled(request: APIRequestContext, token: string, isEnabled: boolean) {\n const response = await apiRequest(request, 'PUT', `/api/integrations/${INTEGRATION_ID}/state`, {\n token,\n data: { isEnabled },\n })\n expect(response.ok()).toBe(true)\n}\n\nexport async function saveCredentials(request: APIRequestContext, token: string, credentials: Record<string, unknown>) {\n const response = await apiRequest(request, 'PUT', `/api/integrations/${INTEGRATION_ID}/credentials`, {\n token,\n data: { credentials },\n })\n expect(response.ok()).toBe(true)\n}\n\nexport async function restoreIntegration(request: APIRequestContext, token: string, snapshot: IntegrationSnapshot) {\n await saveCredentials(request, token, snapshot.credentials ?? {})\n await setIntegrationEnabled(request, token, snapshot.isEnabled)\n}\n\nexport async function lookup(request: APIRequestContext, token: string | null, nip?: string) {\n const path = nip === undefined ? '/api/gus_regon/lookup' : `/api/gus_regon/lookup?nip=${encodeURIComponent(nip)}`\n if (!token) return request.get(path.startsWith('http') ? path : `${process.env.BASE_URL?.trim() ?? ''}${path}`)\n return apiRequest(request, 'GET', path, { token })\n}\n"],
5
+ "mappings": "AAAA,SAAS,cAAsC;AAC/C,SAAS,kBAAkB;AAEpB,MAAM,iBAAiB;AAEvB,MAAM,YAAY;AAElB,MAAM,UAAU;AAUvB,eAAsB,qBAAqB,SAA4B,OAAe;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AC3F,QAAM,OAAO,QAAQ,SAAY,0BAA0B,6BAA6B,mBAAmB,GAAG,CAAC;AAC/G,MAAI,CAAC,MAAO,QAAO,QAAQ,IAAI,KAAK,WAAW,MAAM,IAAI,OAAO,GAAG,QAAQ,IAAI,UAAU,KAAK,KAAK,EAAE,GAAG,IAAI,EAAE;AAC9G,SAAO,WAAW,SAAS,OAAO,MAAM,EAAE,MAAM,CAAC;AACnD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ const integrationMeta = {
2
+ dependsOnModules: ["customers", "integrations", "gus_regon"]
3
+ };
4
+ export {
5
+ integrationMeta
6
+ };
7
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/gus_regon/__integration__/meta.ts"],
4
+ "sourcesContent": ["export const integrationMeta = {\n dependsOnModules: ['customers', 'integrations', 'gus_regon'],\n}\n"],
5
+ "mappings": "AAAO,MAAM,kBAAkB;AAAA,EAC7B,kBAAkB,CAAC,aAAa,gBAAgB,WAAW;AAC7D;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ const features = [
2
+ { id: "gus_regon.lookup", title: "Look up companies in GUS REGON", module: "gus_regon" }
3
+ ];
4
+ var acl_default = features;
5
+ export {
6
+ acl_default as default,
7
+ features
8
+ };
9
+ //# sourceMappingURL=acl.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/modules/gus_regon/acl.ts"],
4
+ "sourcesContent": ["export const features = [\n { id: 'gus_regon.lookup', title: 'Look up companies in GUS REGON', module: 'gus_regon' },\n]\n\nexport default features\n"],
5
+ "mappings": "AAAO,MAAM,WAAW;AAAA,EACtB,EAAE,IAAI,oBAAoB,OAAO,kCAAkC,QAAQ,YAAY;AACzF;AAEA,IAAO,cAAQ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,83 @@
1
+ import { NextResponse } from "next/server";
2
+ import { z } from "zod";
3
+ import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
4
+ import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
5
+ import { organizationScopeRequiredResponse, resolveActiveOrganizationId } from "@open-mercato/shared/lib/auth/organizationScope";
6
+ import { CrudHttpError, isCrudHttpError } from "@open-mercato/shared/lib/crud/errors";
7
+ import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
8
+ import { createLogger } from "@open-mercato/shared/lib/logger";
9
+ import { getTelemetryRuntime } from "@open-mercato/shared/lib/telemetry/runtime";
10
+ import { lookupQuerySchema, lookupResponseSchema } from "../../data/validators.js";
11
+ import { GUS_REGON_INTEGRATION_ID } from "../../lib/config.js";
12
+ import { isValidNip, normalizeNip } from "../../lib/nip.js";
13
+ import { lookupCompanyByNip } from "../../lib/lookup.js";
14
+ const logger = createLogger("gus_regon");
15
+ const metadata = {
16
+ GET: { requireAuth: true, requireFeatures: ["gus_regon.lookup"] }
17
+ };
18
+ async function GET(req) {
19
+ const { translate } = await resolveTranslations();
20
+ try {
21
+ const auth = await getAuthFromRequest(req);
22
+ if (!auth || !auth.tenantId) throw new CrudHttpError(401, { error: translate("gus_regon.errors.unauthorized", "Unauthorized") });
23
+ const url = new URL(req.url);
24
+ const parsed = lookupQuerySchema.safeParse({ nip: url.searchParams.get("nip") ?? "" });
25
+ if (!parsed.success) throw new CrudHttpError(400, { error: translate("gus_regon.errors.nipRequired", "A nip query parameter is required") });
26
+ if (!isValidNip(parsed.data.nip)) {
27
+ throw new CrudHttpError(400, { error: translate("gus_regon.errors.nipInvalid", "The NIP is invalid (checksum failed)") });
28
+ }
29
+ const organizationId = resolveActiveOrganizationId(auth);
30
+ if (!organizationId) return organizationScopeRequiredResponse();
31
+ const integrationScope = { organizationId, tenantId: auth.tenantId };
32
+ const container = await createRequestContainer();
33
+ let credentials;
34
+ try {
35
+ const stateService = container.resolve("integrationStateService");
36
+ const enabled = await stateService.isEnabled(GUS_REGON_INTEGRATION_ID, integrationScope);
37
+ if (!enabled) return NextResponse.json({ ok: false, reason: "not_configured" });
38
+ const credentialsService = container.resolve("integrationCredentialsService");
39
+ credentials = await credentialsService.resolve(GUS_REGON_INTEGRATION_ID, integrationScope);
40
+ } catch (err) {
41
+ getTelemetryRuntime()?.reportError(err, { module: "gus_regon", code: "gus_regon.config_unreadable" });
42
+ logger.error("[internal] gus_regon.lookup could not read the integration configuration", { err });
43
+ return NextResponse.json({ ok: false, reason: "unavailable" });
44
+ }
45
+ const result = await lookupCompanyByNip(credentials, normalizeNip(parsed.data.nip));
46
+ return NextResponse.json(result);
47
+ } catch (err) {
48
+ if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status });
49
+ getTelemetryRuntime()?.reportError(err, { module: "gus_regon", code: "gus_regon.lookup_failed" });
50
+ logger.error("[internal] gus_regon.lookup errored", { err });
51
+ return NextResponse.json({ error: translate("gus_regon.errors.internal", "Internal server error") }, { status: 500 });
52
+ }
53
+ }
54
+ const errorSchema = z.object({ error: z.string() });
55
+ const openApi = {
56
+ tag: "GUS REGON",
57
+ summary: "Look up a Polish company by NIP in the GUS REGON registry",
58
+ methods: {
59
+ GET: {
60
+ summary: "Autofill company data from GUS REGON (BIR1) by NIP",
61
+ query: lookupQuerySchema,
62
+ description: `Validates the NIP checksum locally (400 on failure), then queries the GUS REGON BIR1.1 API server-side with the organization's credentials from Settings \u2192 Integrations. Fail-open: upstream errors and timeouts return 200 { ok:false, reason:"unavailable" }; a disabled or unconfigured integration returns { ok:false, reason:"not_configured" }. The API key is never exposed to the client and no tenant data is read or written.`,
63
+ responses: [
64
+ {
65
+ status: 200,
66
+ description: "Company found (ok:true) or a fail-open miss (ok:false)",
67
+ schema: lookupResponseSchema
68
+ }
69
+ ],
70
+ errors: [
71
+ { status: 400, description: "Missing or invalid NIP, or organization scope unresolved", schema: errorSchema },
72
+ { status: 401, description: "Unauthorized", schema: errorSchema },
73
+ { status: 500, description: "Unexpected server error", schema: errorSchema }
74
+ ]
75
+ }
76
+ }
77
+ };
78
+ export {
79
+ GET,
80
+ metadata,
81
+ openApi
82
+ };
83
+ //# sourceMappingURL=route.js.map