anz-legislation 1.2.1
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 +201 -0
- package/README.md +23 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +198 -0
- package/dist/client.d.ts +84 -0
- package/dist/client.js +492 -0
- package/dist/commands/batch.d.ts +5 -0
- package/dist/commands/batch.js +121 -0
- package/dist/commands/cache.d.ts +5 -0
- package/dist/commands/cache.js +43 -0
- package/dist/commands/cite.d.ts +5 -0
- package/dist/commands/cite.js +68 -0
- package/dist/commands/config.d.ts +5 -0
- package/dist/commands/config.js +56 -0
- package/dist/commands/export.d.ts +8 -0
- package/dist/commands/export.js +169 -0
- package/dist/commands/generate.d.ts +10 -0
- package/dist/commands/generate.js +320 -0
- package/dist/commands/get.d.ts +5 -0
- package/dist/commands/get.js +99 -0
- package/dist/commands/help.d.ts +13 -0
- package/dist/commands/help.js +298 -0
- package/dist/commands/search.d.ts +5 -0
- package/dist/commands/search.js +96 -0
- package/dist/commands/stream.d.ts +5 -0
- package/dist/commands/stream.js +100 -0
- package/dist/config.d.ts +81 -0
- package/dist/config.js +209 -0
- package/dist/errors.d.ts +108 -0
- package/dist/errors.js +173 -0
- package/dist/mcp/server.d.ts +13 -0
- package/dist/mcp/server.js +428 -0
- package/dist/mcp-cli.d.ts +6 -0
- package/dist/mcp-cli.js +37 -0
- package/dist/models/canonical.d.ts +423 -0
- package/dist/models/canonical.js +92 -0
- package/dist/models/index.d.ts +892 -0
- package/dist/models/index.js +223 -0
- package/dist/output/index.d.ts +34 -0
- package/dist/output/index.js +195 -0
- package/dist/output/legal-metadata-publication.d.ts +18 -0
- package/dist/output/legal-metadata-publication.js +23 -0
- package/dist/providers/canonical-metadata.d.ts +3 -0
- package/dist/providers/canonical-metadata.js +202 -0
- package/dist/providers/commonwealth-provider.d.ts +27 -0
- package/dist/providers/commonwealth-provider.js +81 -0
- package/dist/providers/index.d.ts +20 -0
- package/dist/providers/index.js +27 -0
- package/dist/providers/legislation-provider.d.ts +227 -0
- package/dist/providers/legislation-provider.js +308 -0
- package/dist/providers/nz-provider.d.ts +36 -0
- package/dist/providers/nz-provider.js +130 -0
- package/dist/providers/output-adapters.d.ts +14 -0
- package/dist/providers/output-adapters.js +116 -0
- package/dist/providers/plugin-discovery.d.ts +39 -0
- package/dist/providers/plugin-discovery.js +91 -0
- package/dist/providers/plugin-loader.d.ts +86 -0
- package/dist/providers/plugin-loader.js +219 -0
- package/dist/providers/queensland-provider.d.ts +42 -0
- package/dist/providers/queensland-provider.js +105 -0
- package/dist/utils/api-optimization.d.ts +92 -0
- package/dist/utils/api-optimization.js +276 -0
- package/dist/utils/batch.d.ts +110 -0
- package/dist/utils/batch.js +269 -0
- package/dist/utils/branded-types.d.ts +0 -0
- package/dist/utils/branded-types.js +1 -0
- package/dist/utils/compatibility-matrix.d.ts +89 -0
- package/dist/utils/compatibility-matrix.js +214 -0
- package/dist/utils/config-validator.d.ts +39 -0
- package/dist/utils/config-validator.js +197 -0
- package/dist/utils/env-loader.d.ts +55 -0
- package/dist/utils/env-loader.js +77 -0
- package/dist/utils/health-monitor.d.ts +93 -0
- package/dist/utils/health-monitor.js +209 -0
- package/dist/utils/invocation.d.ts +4 -0
- package/dist/utils/invocation.js +33 -0
- package/dist/utils/logger.d.ts +94 -0
- package/dist/utils/logger.js +220 -0
- package/dist/utils/plugin-marketplace.d.ts +77 -0
- package/dist/utils/plugin-marketplace.js +191 -0
- package/dist/utils/presentation.d.ts +2 -0
- package/dist/utils/presentation.js +32 -0
- package/dist/utils/rate-limiter.d.ts +100 -0
- package/dist/utils/rate-limiter.js +256 -0
- package/dist/utils/scraper-cache.d.ts +115 -0
- package/dist/utils/scraper-cache.js +229 -0
- package/dist/utils/secure-config.d.ts +40 -0
- package/dist/utils/secure-config.js +195 -0
- package/dist/utils/streaming.d.ts +121 -0
- package/dist/utils/streaming.js +333 -0
- package/dist/utils/validation.d.ts +190 -0
- package/dist/utils/validation.js +209 -0
- package/dist/utils/version.d.ts +13 -0
- package/dist/utils/version.js +46 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# ANZ Legislation
|
|
2
|
+
|
|
3
|
+
This package publishes the ANZ-first install path for the **ANZ Legislation**
|
|
4
|
+
product while preserving the same runtime payload as `nz-legislation-tool`.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install -g anz-legislation
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Binaries
|
|
13
|
+
|
|
14
|
+
- `anzlegislation`
|
|
15
|
+
- `anzlegislation-mcp`
|
|
16
|
+
- `nzlegislation`
|
|
17
|
+
- `nzlegislation-mcp`
|
|
18
|
+
|
|
19
|
+
The legacy binary names remain available during the compatibility window.
|
|
20
|
+
|
|
21
|
+
## Repository
|
|
22
|
+
|
|
23
|
+
Current repository: https://github.com/edithatogo/anz-legislation.git
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ANZ Legislation CLI
|
|
4
|
+
* Command-line interface for searching and retrieving legislation data
|
|
5
|
+
*/
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import { Command } from 'commander';
|
|
8
|
+
import { batchCommand } from './commands/batch.js';
|
|
9
|
+
import { cacheCommand } from './commands/cache.js';
|
|
10
|
+
import { citeCommand } from './commands/cite.js';
|
|
11
|
+
import { configCommand } from './commands/config.js';
|
|
12
|
+
import { exportCommand } from './commands/export.js';
|
|
13
|
+
import { createGenerateCommand } from './commands/generate.js';
|
|
14
|
+
import { getCommand } from './commands/get.js';
|
|
15
|
+
import { createInteractiveHelpCommand, createContextualHelpCommand } from './commands/help.js';
|
|
16
|
+
import { searchCommand } from './commands/search.js';
|
|
17
|
+
import { streamCommand } from './commands/stream.js';
|
|
18
|
+
import { getConfig } from './config.js';
|
|
19
|
+
import { ApplicationError, ErrorCode, getUserFriendlyMessage } from './errors.js';
|
|
20
|
+
import { initializeProviders } from './providers/index.js';
|
|
21
|
+
import { detectCliBinaryName, getAlternateCliBinaryName } from './utils/invocation.js';
|
|
22
|
+
import { logger } from './utils/logger.js';
|
|
23
|
+
import { buildCliHelpFooter } from './utils/presentation.js';
|
|
24
|
+
// Get package version from package.json
|
|
25
|
+
const pkg = await import('../package.json', { with: { type: 'json' } });
|
|
26
|
+
// Initialize providers with config
|
|
27
|
+
initializeProviders({
|
|
28
|
+
commonwealthApiKey: process.env.COMMONWEALTH_API_KEY,
|
|
29
|
+
queenslandApiKey: process.env.QUEENSLAND_API_KEY,
|
|
30
|
+
});
|
|
31
|
+
// Create main CLI program
|
|
32
|
+
const program = new Command();
|
|
33
|
+
const invokedCliName = detectCliBinaryName();
|
|
34
|
+
const alternateCliName = getAlternateCliBinaryName(invokedCliName);
|
|
35
|
+
program
|
|
36
|
+
.name(invokedCliName)
|
|
37
|
+
.description('Search and retrieve legislation data across jurisdictions')
|
|
38
|
+
.version(pkg.default.version)
|
|
39
|
+
.configureHelp({
|
|
40
|
+
sortOptions: true,
|
|
41
|
+
sortSubcommands: true,
|
|
42
|
+
})
|
|
43
|
+
.addHelpText('after', buildCliHelpFooter(invokedCliName, alternateCliName));
|
|
44
|
+
// Add global options
|
|
45
|
+
program
|
|
46
|
+
.option('--verbose', 'Enable verbose output')
|
|
47
|
+
.option('--quiet', 'Suppress non-essential output')
|
|
48
|
+
.option('-j, --jurisdiction <id>', 'Jurisdiction identifier (nz, au-comm, au-qld)', 'nz');
|
|
49
|
+
// Add commands
|
|
50
|
+
program
|
|
51
|
+
.addCommand(searchCommand)
|
|
52
|
+
.addCommand(getCommand)
|
|
53
|
+
.addCommand(exportCommand)
|
|
54
|
+
.addCommand(citeCommand)
|
|
55
|
+
.addCommand(configCommand)
|
|
56
|
+
.addCommand(cacheCommand)
|
|
57
|
+
.addCommand(batchCommand)
|
|
58
|
+
.addCommand(streamCommand)
|
|
59
|
+
.addCommand(createInteractiveHelpCommand())
|
|
60
|
+
.addCommand(createContextualHelpCommand())
|
|
61
|
+
.addCommand(createGenerateCommand());
|
|
62
|
+
// Pre-command hook to check configuration
|
|
63
|
+
program.hook('preAction', (thisCommand, actionCommand) => {
|
|
64
|
+
// Skip config check for config command itself
|
|
65
|
+
if (actionCommand.name() === 'config') {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const config = getConfig();
|
|
69
|
+
if (!config.apiKey || config.apiKey === 'your_api_key_here') {
|
|
70
|
+
logger.warn('API key not configured.');
|
|
71
|
+
logger.warn(`Run "${invokedCliName} config" to set up your API key.\n`);
|
|
72
|
+
}
|
|
73
|
+
// Apply global options
|
|
74
|
+
if (thisCommand.opts().verbose) {
|
|
75
|
+
logger.setVerbose(true);
|
|
76
|
+
config.verbose = true;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Global error boundary - catches all unhandled errors
|
|
81
|
+
*/
|
|
82
|
+
function handleError(error) {
|
|
83
|
+
logger.clearOldLogs(7);
|
|
84
|
+
if (error instanceof ApplicationError) {
|
|
85
|
+
logger.error(getUserFriendlyMessage(error), error);
|
|
86
|
+
displayErrorWithSuggestions(error);
|
|
87
|
+
process.exit(getExitCode(error.code));
|
|
88
|
+
}
|
|
89
|
+
if (error instanceof Error) {
|
|
90
|
+
logger.error('An unexpected error occurred', error);
|
|
91
|
+
console.error(chalk.red('\n💥 Unexpected error:'), error.message);
|
|
92
|
+
console.error(chalk.yellow('\nSuggestions:'));
|
|
93
|
+
console.error(chalk.white(' 1. Run with --verbose for more details'));
|
|
94
|
+
console.error(chalk.white(' 2. Check the log file:'), chalk.gray(logger.getLogFile()));
|
|
95
|
+
console.error(chalk.white(' 3. If the issue persists, report it on GitHub'));
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
logger.error('An unknown error occurred');
|
|
99
|
+
console.error(chalk.red('\n💥 An unknown error occurred'));
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Display error with actionable suggestions based on error type
|
|
104
|
+
*/
|
|
105
|
+
function displayErrorWithSuggestions(error) {
|
|
106
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`));
|
|
107
|
+
console.error(chalk.yellow('Suggestions:'));
|
|
108
|
+
switch (error.code) {
|
|
109
|
+
case ErrorCode.CONFIG_API_KEY_MISSING:
|
|
110
|
+
case ErrorCode.CONFIG_NOT_FOUND:
|
|
111
|
+
console.error(chalk.white(' 1. Run ') +
|
|
112
|
+
chalk.cyan(`${invokedCliName} config`) +
|
|
113
|
+
chalk.white(' to set up your API key'));
|
|
114
|
+
console.error(chalk.white(' 2. Or set environment variable ') + chalk.cyan('NZ_LEGISLATION_API_KEY'));
|
|
115
|
+
console.error(chalk.white(' 3. Get your API key from https://api.legislation.govt.nz'));
|
|
116
|
+
break;
|
|
117
|
+
case ErrorCode.API_AUTHENTICATION_FAILED:
|
|
118
|
+
console.error(chalk.white(' 1. Check your API key is correct'));
|
|
119
|
+
console.error(chalk.white(' 2. Run ') +
|
|
120
|
+
chalk.cyan(`${invokedCliName} config --show`) +
|
|
121
|
+
chalk.white(' to verify'));
|
|
122
|
+
console.error(chalk.white(' 3. Contact API support if the issue persists'));
|
|
123
|
+
break;
|
|
124
|
+
case ErrorCode.API_NOT_FOUND:
|
|
125
|
+
console.error(chalk.white(' 1. Check the work ID is correct'));
|
|
126
|
+
console.error(chalk.white(' 2. Use ') +
|
|
127
|
+
chalk.cyan(`${invokedCliName} search`) +
|
|
128
|
+
chalk.white(' to find the correct ID'));
|
|
129
|
+
console.error(chalk.white(' 3. Verify the legislation exists on the NZ Legislation website'));
|
|
130
|
+
break;
|
|
131
|
+
case ErrorCode.API_RATE_LIMIT_EXCEEDED:
|
|
132
|
+
console.error(chalk.white(' 1. Wait a few minutes before trying again'));
|
|
133
|
+
console.error(chalk.white(' 2. Reduce the frequency of your requests'));
|
|
134
|
+
console.error(chalk.white(' 3. Consider using the --limit flag to batch requests'));
|
|
135
|
+
break;
|
|
136
|
+
case ErrorCode.API_TIMEOUT:
|
|
137
|
+
case ErrorCode.NETWORK_OFFLINE:
|
|
138
|
+
case ErrorCode.NETWORK_CONNECTION_REFUSED:
|
|
139
|
+
console.error(chalk.white(' 1. Check your internet connection'));
|
|
140
|
+
console.error(chalk.white(' 2. Verify the API is accessible at ') +
|
|
141
|
+
chalk.cyan('https://api.legislation.govt.nz'));
|
|
142
|
+
console.error(chalk.white(' 3. Try again in a few moments'));
|
|
143
|
+
break;
|
|
144
|
+
case ErrorCode.FILE_WRITE_FAILED:
|
|
145
|
+
case ErrorCode.FILE_NOT_FOUND:
|
|
146
|
+
console.error(chalk.white(' 1. Check the file path is correct'));
|
|
147
|
+
console.error(chalk.white(' 2. Verify you have write permissions'));
|
|
148
|
+
console.error(chalk.white(' 3. Ensure the output directory exists'));
|
|
149
|
+
break;
|
|
150
|
+
case ErrorCode.VALIDATION_FAILED:
|
|
151
|
+
case ErrorCode.VALIDATION_INVALID_ID:
|
|
152
|
+
console.error(chalk.white(' 1. Check the format of your input'));
|
|
153
|
+
console.error(chalk.white(' 2. Use ') + chalk.cyan('--help') + chalk.white(' to see valid options'));
|
|
154
|
+
console.error(chalk.white(' 3. Example: ') +
|
|
155
|
+
chalk.cyan(`${invokedCliName} get "act_public_1989_18"`));
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
console.error(chalk.white(' 1. Run with ') + chalk.cyan('--verbose') + chalk.white(' for more details'));
|
|
159
|
+
console.error(chalk.white(' 2. Check the log file: ') + chalk.gray(logger.getLogFile()));
|
|
160
|
+
console.error(chalk.white(' 3. Report the issue on GitHub with the error details'));
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
console.error(chalk.gray(`\nError Code: ${ErrorCode[error.code]} (${error.code})`));
|
|
164
|
+
console.error(chalk.gray(`Log File: ${logger.getLogFile()}`));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get exit code based on error type
|
|
168
|
+
*/
|
|
169
|
+
function getExitCode(code) {
|
|
170
|
+
if (code >= ErrorCode.API_AUTHENTICATION_FAILED && code < ErrorCode.CONFIG_NOT_FOUND) {
|
|
171
|
+
return 1; // API errors (1000-1999)
|
|
172
|
+
}
|
|
173
|
+
if (code >= ErrorCode.CONFIG_NOT_FOUND && code < ErrorCode.VALIDATION_FAILED) {
|
|
174
|
+
return 2; // Config errors (2000-2999)
|
|
175
|
+
}
|
|
176
|
+
if (code >= ErrorCode.VALIDATION_FAILED && code < ErrorCode.FILE_NOT_FOUND) {
|
|
177
|
+
return 3; // Validation errors (3000-3999)
|
|
178
|
+
}
|
|
179
|
+
if (code >= ErrorCode.FILE_NOT_FOUND && code < ErrorCode.NETWORK_OFFLINE) {
|
|
180
|
+
return 4; // File system errors (4000-4999)
|
|
181
|
+
}
|
|
182
|
+
if (code >= ErrorCode.NETWORK_OFFLINE && code < ErrorCode.UNKNOWN) {
|
|
183
|
+
return 5; // Network errors (5000-5999)
|
|
184
|
+
}
|
|
185
|
+
return 1; // Default
|
|
186
|
+
}
|
|
187
|
+
// Set up global error handler
|
|
188
|
+
process.on('uncaughtException', handleError);
|
|
189
|
+
process.on('unhandledRejection', reason => {
|
|
190
|
+
handleError(reason instanceof Error ? reason : new Error(String(reason)));
|
|
191
|
+
});
|
|
192
|
+
// Parse command line arguments
|
|
193
|
+
program.parse();
|
|
194
|
+
// Show help if no command provided
|
|
195
|
+
if (!process.argv.slice(2).length) {
|
|
196
|
+
program.outputHelp();
|
|
197
|
+
process.exit(0);
|
|
198
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client for NZ Legislation API
|
|
3
|
+
* Handles HTTP requests, authentication, rate limiting, and caching
|
|
4
|
+
*/
|
|
5
|
+
import { type LegislationVersion, type SearchResults, type Version, type Work } from '@models';
|
|
6
|
+
/**
|
|
7
|
+
* Cache metrics for observability
|
|
8
|
+
*/
|
|
9
|
+
interface CacheMetrics {
|
|
10
|
+
hits: number;
|
|
11
|
+
misses: number;
|
|
12
|
+
evictions: number;
|
|
13
|
+
sets: number;
|
|
14
|
+
}
|
|
15
|
+
declare const cacheMetrics: CacheMetrics;
|
|
16
|
+
interface HttpResponseLike {
|
|
17
|
+
json(): Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
interface HttpClientLike {
|
|
20
|
+
get(url: string, options?: Record<string, unknown>): HttpResponseLike;
|
|
21
|
+
}
|
|
22
|
+
type HttpClientFactory = () => HttpClientLike;
|
|
23
|
+
/**
|
|
24
|
+
* Clear cache (optionally by pattern)
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearCache(pattern?: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get cache statistics
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCacheStats(): {
|
|
31
|
+
size: number;
|
|
32
|
+
maxSize: number;
|
|
33
|
+
metrics: typeof cacheMetrics;
|
|
34
|
+
hitRate: string;
|
|
35
|
+
keys: string[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Reset cache metrics (for testing)
|
|
39
|
+
*/
|
|
40
|
+
export declare function resetCacheMetrics(): void;
|
|
41
|
+
export declare function setHttpClientFactoryForTesting(factory?: HttpClientFactory): void;
|
|
42
|
+
/**
|
|
43
|
+
* Search for legislation works
|
|
44
|
+
*/
|
|
45
|
+
export declare function searchWorks(params: {
|
|
46
|
+
query?: string;
|
|
47
|
+
type?: string;
|
|
48
|
+
status?: string;
|
|
49
|
+
from?: string;
|
|
50
|
+
to?: string;
|
|
51
|
+
limit?: number;
|
|
52
|
+
offset?: number;
|
|
53
|
+
}): Promise<SearchResults>;
|
|
54
|
+
/**
|
|
55
|
+
* Get a specific work by ID
|
|
56
|
+
*/
|
|
57
|
+
export declare function getWork(workId: string): Promise<Work>;
|
|
58
|
+
/**
|
|
59
|
+
* Get all versions of a work
|
|
60
|
+
*/
|
|
61
|
+
export declare function getWorkVersions(workId: string): Promise<Version[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Get a specific version of a work
|
|
64
|
+
*/
|
|
65
|
+
export declare function getVersion(versionId: string): Promise<LegislationVersion>;
|
|
66
|
+
/**
|
|
67
|
+
* Get rate limit status
|
|
68
|
+
*/
|
|
69
|
+
export declare function getRateLimitStatus(): {
|
|
70
|
+
remaining: number;
|
|
71
|
+
resetTime: Date;
|
|
72
|
+
burstRemaining: number;
|
|
73
|
+
burstResetTime: Date;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Get cache metrics
|
|
77
|
+
*/
|
|
78
|
+
export declare function getCacheMetrics(): {
|
|
79
|
+
hits: number;
|
|
80
|
+
misses: number;
|
|
81
|
+
evictions: number;
|
|
82
|
+
sets: number;
|
|
83
|
+
};
|
|
84
|
+
export {};
|