law4devs 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 law4devs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # law4devs
2
+
3
+ Official TypeScript SDK for the [Law4Devs API](https://api.law4devs.eu) — structured EU regulatory compliance data for developers.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/law4devs.svg)](https://www.npmjs.com/package/law4devs)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - Full TypeScript types for all API resources
11
+ - Zero runtime dependencies (uses Node 18+ built-in `fetch`)
12
+ - Automatic pagination with `AsyncGenerator` (`iter()`)
13
+ - Automatic retry with exponential backoff on 429/5xx
14
+ - Dual CJS + ESM output
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install law4devs
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { Law4DevsClient } from 'law4devs';
26
+
27
+ const client = new Law4DevsClient();
28
+
29
+ // List all frameworks
30
+ const page = await client.frameworks.list();
31
+ console.log(page.data.map(f => f.slug));
32
+
33
+ // Get a specific framework
34
+ const gdpr = await client.frameworks.get('gdpr');
35
+ console.log(gdpr.name, gdpr.requirementCount);
36
+
37
+ // Iterate all articles in a framework (auto-pagination)
38
+ for await (const article of client.articles.iter('gdpr')) {
39
+ console.log(article.articleNumber, article.title);
40
+ }
41
+ ```
42
+
43
+ ## Authentication
44
+
45
+ No API key is required for public endpoints. To use an API key:
46
+
47
+ ```typescript
48
+ const client = new Law4DevsClient({ apiKey: 'your-key-here' });
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ ```typescript
54
+ const client = new Law4DevsClient({
55
+ baseUrl: 'https://api.law4devs.eu/api/v1', // default
56
+ apiKey: 'optional-key',
57
+ timeout: 30_000, // milliseconds, default 30s
58
+ maxRetries: 3, // default 3
59
+ });
60
+ ```
61
+
62
+ ## Resources
63
+
64
+ ### Frameworks
65
+
66
+ ```typescript
67
+ // List frameworks (paginated)
68
+ const page = await client.frameworks.list({ page: 1, perPage: 20 });
69
+
70
+ // Get framework detail
71
+ const fw = await client.frameworks.get('cra');
72
+
73
+ // Iterate all frameworks (auto-pagination)
74
+ for await (const fw of client.frameworks.iter()) {
75
+ console.log(fw.slug);
76
+ }
77
+ ```
78
+
79
+ ### Articles
80
+
81
+ ```typescript
82
+ // List articles in a framework
83
+ const page = await client.articles.list('gdpr', { page: 1, perPage: 20 });
84
+
85
+ // Get a specific article
86
+ const article = await client.articles.get('gdpr', 5);
87
+
88
+ // Get related articles
89
+ const related = await client.articles.related('gdpr', 5);
90
+
91
+ // Iterate all articles
92
+ for await (const article of client.articles.iter('gdpr')) {
93
+ console.log(article.articleNumber, article.title);
94
+ }
95
+ ```
96
+
97
+ ### Recitals
98
+
99
+ ```typescript
100
+ const page = await client.recitals.list('gdpr');
101
+ const recital = await client.recitals.get('gdpr', 1);
102
+ for await (const r of client.recitals.iter('gdpr')) { /* ... */ }
103
+ ```
104
+
105
+ ### Requirements
106
+
107
+ ```typescript
108
+ // All requirements
109
+ const page = await client.requirements.list();
110
+
111
+ // Filter by framework
112
+ const gdprReqs = await client.requirements.list({ frameworkSlug: 'gdpr' });
113
+
114
+ // Iterate
115
+ for await (const req of client.requirements.iter({ frameworkSlug: 'gdpr' })) {
116
+ console.log(req.requirementText);
117
+ }
118
+ ```
119
+
120
+ ### Tags
121
+
122
+ ```typescript
123
+ const page = await client.tags.list();
124
+ const tag = await client.tags.get('data-protection');
125
+ for await (const tag of client.tags.iter()) { /* ... */ }
126
+ ```
127
+
128
+ ### Compliance Deadlines
129
+
130
+ ```typescript
131
+ const page = await client.compliance.deadlines({ frameworkSlug: 'nis2' });
132
+ for await (const d of client.compliance.iterDeadlines({ frameworkSlug: 'nis2' })) {
133
+ console.log(d.deadlineDate, d.description);
134
+ }
135
+ ```
136
+
137
+ ### Annexes
138
+
139
+ ```typescript
140
+ const page = await client.annexes.list('cra');
141
+ const annex = await client.annexes.get('cra', 'I');
142
+ for await (const annex of client.annexes.iter('cra')) { /* ... */ }
143
+ ```
144
+
145
+ ### Search
146
+
147
+ ```typescript
148
+ const results = await client.search.query('data breach notification', {
149
+ framework: 'gdpr',
150
+ resultType: 'article',
151
+ });
152
+
153
+ for await (const result of client.search.iter('security requirements')) {
154
+ console.log(result.type, result.matchContext);
155
+ }
156
+ ```
157
+
158
+ ## Pagination
159
+
160
+ All `list()` methods return a `Page<T>` object:
161
+
162
+ ```typescript
163
+ const page = await client.frameworks.list({ page: 1, perPage: 10 });
164
+ console.log(page.meta.total); // total items
165
+ console.log(page.meta.pages); // total pages
166
+ console.log(page.links.next); // URL of next page, or null
167
+ console.log(page.data); // array of items
168
+ ```
169
+
170
+ For automatic iteration, use `iter()`:
171
+
172
+ ```typescript
173
+ for await (const item of client.frameworks.iter({ perPage: 50 })) {
174
+ // Automatically fetches next page when needed
175
+ }
176
+ ```
177
+
178
+ ## Error Handling
179
+
180
+ ```typescript
181
+ import { Law4DevsClient, NotFoundError, RateLimitError, ValidationError } from 'law4devs';
182
+
183
+ try {
184
+ const fw = await client.frameworks.get('unknown-slug');
185
+ } catch (err) {
186
+ if (err instanceof NotFoundError) {
187
+ console.error('Framework not found:', err.message);
188
+ } else if (err instanceof RateLimitError) {
189
+ console.error('Rate limited — will retry automatically');
190
+ } else if (err instanceof ValidationError) {
191
+ console.error('Bad request:', err.message, err.statusCode);
192
+ }
193
+ }
194
+ ```
195
+
196
+ Error classes: `Law4DevsError` (base), `NotFoundError`, `ValidationError`, `RateLimitError`, `ServerError`.
197
+
198
+ ## Available Frameworks
199
+
200
+ | Slug | Name | CELEX | Status |
201
+ |------|------|-------|--------|
202
+ | `gdpr` | General Data Protection Regulation | 32016R0679 | Active |
203
+ | `nis2` | Network and Information Security Directive 2 | 32022L2555 | Active |
204
+ | `cra` | Cyber Resilience Act | 32024R2847 | Active |
205
+ | `ai-act` | Artificial Intelligence Act | 32024R1689 | Active |
206
+ | `dora` | Digital Operational Resilience Act | 32022R2554 | Active |
207
+ | `dsa` | Digital Services Act | 32022R2065 | Active |
208
+ | `dma` | Digital Markets Act | 32022R1925 | Active |
209
+ | `eidas2` | eIDAS 2.0 | 32024R1183 | Active |
210
+ | `data-act` | Data Act | 32023R2854 | Active |
211
+ | `data-governance-act` | Data Governance Act | 32022R0868 | Active |
212
+ | `eu-ai-liability` | EU AI Liability Directive | — | Active |
213
+ | `product-liability` | Product Liability Directive | — | Active |
214
+ | `eprivacy` | ePrivacy Regulation | — | Active |
215
+ | `psd3` | Payment Services Directive 3 | — | Active |
216
+ | `micar` | Markets in Crypto-Assets Regulation | 32023R1114 | Active |
217
+ | `open-finance` | Open Finance Framework | — | Active |
218
+ | `fida` | Financial Data Access | — | Active |
219
+ | `nis1` | Network and Information Security Directive 1 | 32016L1148 | Superseded |
220
+ | `csd-r` | Cyber Security Delegated Regulation | — | Active |
221
+
222
+ ## License
223
+
224
+ MIT
@@ -0,0 +1,289 @@
1
+ declare const DEFAULT_BASE_URL = "https://api.law4devs.eu/api/v1";
2
+ interface HTTPClientOptions {
3
+ baseUrl?: string;
4
+ apiKey?: string;
5
+ timeout?: number;
6
+ maxRetries?: number;
7
+ }
8
+ declare class HTTPClient {
9
+ readonly baseUrl: string;
10
+ readonly timeout: number;
11
+ readonly maxRetries: number;
12
+ readonly _headers: Record<string, string>;
13
+ constructor(options?: HTTPClientOptions);
14
+ get<T = unknown>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
15
+ }
16
+
17
+ interface PageMeta {
18
+ apiVersion: string;
19
+ total: number;
20
+ page: number;
21
+ perPage: number;
22
+ pages: number;
23
+ }
24
+ interface PageLinks {
25
+ next: string | null;
26
+ prev: string | null;
27
+ }
28
+ interface Page<T> {
29
+ data: T[];
30
+ meta: PageMeta;
31
+ links: PageLinks;
32
+ }
33
+
34
+ declare abstract class BaseResource {
35
+ protected readonly _http: HTTPClient;
36
+ constructor(_http: HTTPClient);
37
+ protected parsePage<T>(raw: Record<string, unknown>, fromDict: (d: Record<string, unknown>) => T): Page<T>;
38
+ protected pageParams(page?: number, perPage?: number): Record<string, number | undefined>;
39
+ protected _iterPages<T>(listFn: (opts: {
40
+ page: number;
41
+ perPage: number;
42
+ }) => Promise<Page<T>>, perPage?: number): AsyncGenerator<T>;
43
+ }
44
+
45
+ interface Framework {
46
+ id: number;
47
+ slug: string;
48
+ name: string;
49
+ shortName: string;
50
+ celexNumber: string;
51
+ description: string | null;
52
+ isActive: boolean;
53
+ status: string;
54
+ expectedArticles: number;
55
+ expectedRecitals: number;
56
+ lastSyncedAt: string | null;
57
+ createdAt: string;
58
+ articleCount: number;
59
+ recitalCount: number;
60
+ }
61
+ interface FrameworkDetail extends Framework {
62
+ eurLexUrl: string;
63
+ requirementCount: number;
64
+ annexCount: number;
65
+ tagCount: number;
66
+ coverage: Record<string, unknown> | null;
67
+ }
68
+
69
+ declare class FrameworksResource extends BaseResource {
70
+ list(opts?: {
71
+ page?: number;
72
+ perPage?: number;
73
+ }): Promise<Page<Framework>>;
74
+ get(slug: string): Promise<FrameworkDetail>;
75
+ iter(opts?: {
76
+ perPage?: number;
77
+ }): AsyncGenerator<Framework>;
78
+ }
79
+
80
+ interface Tag {
81
+ id: number;
82
+ slug: string;
83
+ name: string;
84
+ description: string | null;
85
+ keywords: string[];
86
+ color: string | null;
87
+ createdAt: string;
88
+ }
89
+
90
+ interface ArticleParagraph {
91
+ paragraphRef: string;
92
+ content: string;
93
+ position: number;
94
+ }
95
+ interface ArticleSummary {
96
+ id: number;
97
+ frameworkSlug: string;
98
+ articleNumber: number;
99
+ title: string;
100
+ position: number;
101
+ paragraphCount: number;
102
+ tags: Tag[];
103
+ }
104
+ interface Article extends ArticleSummary {
105
+ content: string;
106
+ paragraphs: ArticleParagraph[];
107
+ }
108
+
109
+ declare class ArticlesResource extends BaseResource {
110
+ list(frameworkSlug: string, opts?: {
111
+ page?: number;
112
+ perPage?: number;
113
+ }): Promise<Page<ArticleSummary>>;
114
+ get(frameworkSlug: string, articleNumber: number | string): Promise<Article>;
115
+ related(frameworkSlug: string, articleNumber: number | string, opts?: {
116
+ page?: number;
117
+ perPage?: number;
118
+ }): Promise<Page<ArticleSummary>>;
119
+ iter(frameworkSlug: string, opts?: {
120
+ perPage?: number;
121
+ }): AsyncGenerator<ArticleSummary>;
122
+ }
123
+
124
+ interface Recital {
125
+ id: number;
126
+ frameworkSlug: string;
127
+ recitalNumber: number;
128
+ content: string;
129
+ position: number;
130
+ }
131
+
132
+ declare class RecitalsResource extends BaseResource {
133
+ list(frameworkSlug: string, opts?: {
134
+ page?: number;
135
+ perPage?: number;
136
+ }): Promise<Page<Recital>>;
137
+ get(frameworkSlug: string, recitalNumber: number | string): Promise<Recital>;
138
+ iter(frameworkSlug: string, opts?: {
139
+ perPage?: number;
140
+ }): AsyncGenerator<Recital>;
141
+ }
142
+
143
+ interface Requirement {
144
+ id: number;
145
+ frameworkSlug: string;
146
+ articleNumber: number | null;
147
+ paragraphRef: string | null;
148
+ paragraphContent: string | null;
149
+ requirementText: string;
150
+ requirementType: string;
151
+ complianceDeadline: string | null;
152
+ linkedArticleNumbers: number[];
153
+ stakeholderRoles: string[];
154
+ tags: Tag[];
155
+ createdAt: string;
156
+ }
157
+
158
+ declare class RequirementsResource extends BaseResource {
159
+ list(opts?: {
160
+ page?: number;
161
+ perPage?: number;
162
+ frameworkSlug?: string;
163
+ }): Promise<Page<Requirement>>;
164
+ iter(opts?: {
165
+ perPage?: number;
166
+ frameworkSlug?: string;
167
+ }): AsyncGenerator<Requirement>;
168
+ }
169
+
170
+ declare class TagsResource extends BaseResource {
171
+ list(opts?: {
172
+ page?: number;
173
+ perPage?: number;
174
+ }): Promise<Page<Tag>>;
175
+ get(slug: string): Promise<Tag>;
176
+ iter(opts?: {
177
+ perPage?: number;
178
+ }): AsyncGenerator<Tag>;
179
+ }
180
+
181
+ interface ComplianceDeadline {
182
+ id: number;
183
+ frameworkSlug: string;
184
+ articleNumber: string | null;
185
+ paragraphRef: string | null;
186
+ deadlineDate: string;
187
+ deadlineType: string;
188
+ description: string | null;
189
+ }
190
+
191
+ declare class ComplianceResource extends BaseResource {
192
+ deadlines(opts?: {
193
+ page?: number;
194
+ perPage?: number;
195
+ frameworkSlug?: string;
196
+ }): Promise<Page<ComplianceDeadline>>;
197
+ iterDeadlines(opts?: {
198
+ perPage?: number;
199
+ frameworkSlug?: string;
200
+ }): AsyncGenerator<ComplianceDeadline>;
201
+ }
202
+
203
+ interface AnnexSummary {
204
+ id: number;
205
+ frameworkSlug: string;
206
+ annexNumber: string;
207
+ title: string;
208
+ }
209
+ interface Annex extends AnnexSummary {
210
+ content: string;
211
+ }
212
+
213
+ declare class AnnexesResource extends BaseResource {
214
+ list(frameworkSlug: string, opts?: {
215
+ page?: number;
216
+ perPage?: number;
217
+ }): Promise<Page<AnnexSummary>>;
218
+ get(frameworkSlug: string, annexNumber: string): Promise<Annex>;
219
+ iter(frameworkSlug: string, opts?: {
220
+ perPage?: number;
221
+ }): AsyncGenerator<AnnexSummary>;
222
+ }
223
+
224
+ interface SearchResult {
225
+ type: string;
226
+ frameworkSlug: string;
227
+ frameworkName: string;
228
+ articleNumber: string | null;
229
+ recitalNumber: string | null;
230
+ paragraphRef: string | null;
231
+ title: string | null;
232
+ requirementType: string | null;
233
+ matchContext: string;
234
+ url: string;
235
+ }
236
+
237
+ declare class SearchResource extends BaseResource {
238
+ query(q: string, opts?: {
239
+ framework?: string;
240
+ resultType?: string;
241
+ page?: number;
242
+ perPage?: number;
243
+ }): Promise<Page<SearchResult>>;
244
+ iter(q: string, opts?: {
245
+ perPage?: number;
246
+ framework?: string;
247
+ resultType?: string;
248
+ }): AsyncGenerator<SearchResult>;
249
+ }
250
+
251
+ interface Law4DevsClientOptions {
252
+ baseUrl?: string;
253
+ apiKey?: string;
254
+ timeout?: number;
255
+ maxRetries?: number;
256
+ }
257
+ declare class Law4DevsClient {
258
+ readonly _http: HTTPClient;
259
+ readonly frameworks: FrameworksResource;
260
+ readonly articles: ArticlesResource;
261
+ readonly recitals: RecitalsResource;
262
+ readonly requirements: RequirementsResource;
263
+ readonly tags: TagsResource;
264
+ readonly compliance: ComplianceResource;
265
+ readonly annexes: AnnexesResource;
266
+ readonly search: SearchResource;
267
+ constructor(options?: Law4DevsClientOptions);
268
+ }
269
+
270
+ declare class Law4DevsError extends Error {
271
+ readonly statusCode?: number | undefined;
272
+ constructor(message: string, statusCode?: number | undefined);
273
+ }
274
+ declare class NotFoundError extends Law4DevsError {
275
+ constructor(msg: string, sc?: number);
276
+ }
277
+ declare class ValidationError extends Law4DevsError {
278
+ constructor(msg: string, sc?: number);
279
+ }
280
+ declare class RateLimitError extends Law4DevsError {
281
+ constructor(msg: string, sc?: number);
282
+ }
283
+ declare class ServerError extends Law4DevsError {
284
+ constructor(msg: string, sc?: number);
285
+ }
286
+
287
+ declare const VERSION = "0.1.0";
288
+
289
+ export { type Annex, type AnnexSummary, AnnexesResource, type Article, type ArticleParagraph, type ArticleSummary, ArticlesResource, type ComplianceDeadline, ComplianceResource, DEFAULT_BASE_URL, type Framework, type FrameworkDetail, FrameworksResource, HTTPClient, type HTTPClientOptions, Law4DevsClient, type Law4DevsClientOptions, Law4DevsError, NotFoundError, type Page, type PageLinks, type PageMeta, RateLimitError, type Recital, RecitalsResource, type Requirement, RequirementsResource, SearchResource, type SearchResult, ServerError, type Tag, TagsResource, VERSION, ValidationError };