neonctl 2.27.0 → 2.28.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.md +178 -0
- package/README.md +33 -1
- package/{analytics.js → dist/analytics.js} +21 -5
- package/dist/api.js +665 -0
- package/dist/cli.js +9 -0
- package/{commands → dist/commands}/auth.js +7 -0
- package/{commands → dist/commands}/branches.js +7 -4
- package/{commands → dist/commands}/bucket.js +69 -37
- package/{commands → dist/commands}/checkout.js +3 -3
- package/{commands → dist/commands}/config.js +22 -0
- package/{commands → dist/commands}/connection_string.js +1 -1
- package/{commands → dist/commands}/data_api.js +5 -6
- package/{commands → dist/commands}/databases.js +6 -3
- package/{commands → dist/commands}/functions.js +7 -9
- package/{commands → dist/commands}/index.js +2 -0
- package/{commands → dist/commands}/link.js +10 -17
- package/{commands → dist/commands}/neon_auth.js +8 -11
- package/{commands → dist/commands}/projects.js +4 -4
- package/{commands → dist/commands}/psql.js +1 -1
- package/{commands → dist/commands}/roles.js +6 -3
- package/{commands → dist/commands}/schema_diff.js +3 -4
- package/dist/commands/status.js +40 -0
- package/{context.js → dist/context.js} +16 -0
- package/dist/current_branch_fast_path.js +55 -0
- package/dist/errors.js +80 -0
- package/{functions_api.js → dist/functions_api.js} +1 -1
- package/{index.js → dist/index.js} +21 -20
- package/{parameters.gen.js → dist/parameters.gen.js} +14 -14
- package/{psql → dist/psql}/cli.js +0 -0
- package/{storage_api.js → dist/storage_api.js} +7 -8
- package/{test_utils → dist/test_utils}/fixtures.js +45 -15
- package/dist/utils/api_enums.js +33 -0
- package/{utils → dist/utils}/branch_picker.js +1 -1
- package/{utils → dist/utils}/enrichers.js +11 -4
- package/package.json +64 -67
- package/api.js +0 -35
- package/cli.js +0 -2
- package/errors.js +0 -17
- /package/{auth.js → dist/auth.js} +0 -0
- /package/{callback.html → dist/callback.html} +0 -0
- /package/{commands → dist/commands}/bootstrap.js +0 -0
- /package/{commands → dist/commands}/deploy.js +0 -0
- /package/{commands → dist/commands}/dev.js +0 -0
- /package/{commands → dist/commands}/env.js +0 -0
- /package/{commands → dist/commands}/init.js +0 -0
- /package/{commands → dist/commands}/ip_allow.js +0 -0
- /package/{commands → dist/commands}/operations.js +0 -0
- /package/{commands → dist/commands}/orgs.js +0 -0
- /package/{commands → dist/commands}/set_context.js +0 -0
- /package/{commands → dist/commands}/user.js +0 -0
- /package/{commands → dist/commands}/vpc_endpoints.js +0 -0
- /package/{config.js → dist/config.js} +0 -0
- /package/{config_format.js → dist/config_format.js} +0 -0
- /package/{dev → dist/dev}/env.js +0 -0
- /package/{dev → dist/dev}/functions.js +0 -0
- /package/{dev → dist/dev}/inputs.js +0 -0
- /package/{dev → dist/dev}/runtime.js +0 -0
- /package/{env.js → dist/env.js} +0 -0
- /package/{env_file.js → dist/env_file.js} +0 -0
- /package/{help.js → dist/help.js} +0 -0
- /package/{log.js → dist/log.js} +0 -0
- /package/{pkg.js → dist/pkg.js} +0 -0
- /package/{psql → dist/psql}/command/cmd_cond.js +0 -0
- /package/{psql → dist/psql}/command/cmd_connect.js +0 -0
- /package/{psql → dist/psql}/command/cmd_copy.js +0 -0
- /package/{psql → dist/psql}/command/cmd_describe.js +0 -0
- /package/{psql → dist/psql}/command/cmd_format.js +0 -0
- /package/{psql → dist/psql}/command/cmd_io.js +0 -0
- /package/{psql → dist/psql}/command/cmd_lo.js +0 -0
- /package/{psql → dist/psql}/command/cmd_meta.js +0 -0
- /package/{psql → dist/psql}/command/cmd_misc.js +0 -0
- /package/{psql → dist/psql}/command/cmd_pipeline.js +0 -0
- /package/{psql → dist/psql}/command/cmd_restrict.js +0 -0
- /package/{psql → dist/psql}/command/cmd_show.js +0 -0
- /package/{psql → dist/psql}/command/dispatch.js +0 -0
- /package/{psql → dist/psql}/command/inputQueue.js +0 -0
- /package/{psql → dist/psql}/command/shared.js +0 -0
- /package/{psql → dist/psql}/complete/filenames.js +0 -0
- /package/{psql → dist/psql}/complete/index.js +0 -0
- /package/{psql → dist/psql}/complete/matcher.js +0 -0
- /package/{psql → dist/psql}/complete/psqlVars.js +0 -0
- /package/{psql → dist/psql}/complete/queries.js +0 -0
- /package/{psql → dist/psql}/complete/rules.js +0 -0
- /package/{psql → dist/psql}/core/common.js +0 -0
- /package/{psql → dist/psql}/core/help.js +0 -0
- /package/{psql → dist/psql}/core/mainloop.js +0 -0
- /package/{psql → dist/psql}/core/prompt.js +0 -0
- /package/{psql → dist/psql}/core/settings.js +0 -0
- /package/{psql → dist/psql}/core/sqlHelp.js +0 -0
- /package/{psql → dist/psql}/core/startup.js +0 -0
- /package/{psql → dist/psql}/core/syncVars.js +0 -0
- /package/{psql → dist/psql}/core/variables.js +0 -0
- /package/{psql → dist/psql}/describe/formatters.js +0 -0
- /package/{psql → dist/psql}/describe/processNamePattern.js +0 -0
- /package/{psql → dist/psql}/describe/queries.js +0 -0
- /package/{psql → dist/psql}/describe/versionGate.js +0 -0
- /package/{psql → dist/psql}/index.js +0 -0
- /package/{psql → dist/psql}/io/history.js +0 -0
- /package/{psql → dist/psql}/io/input.js +0 -0
- /package/{psql → dist/psql}/io/lineEditor/buffer.js +0 -0
- /package/{psql → dist/psql}/io/lineEditor/complete.js +0 -0
- /package/{psql → dist/psql}/io/lineEditor/filename.js +0 -0
- /package/{psql → dist/psql}/io/lineEditor/index.js +0 -0
- /package/{psql → dist/psql}/io/lineEditor/keymap.js +0 -0
- /package/{psql → dist/psql}/io/lineEditor/vt100.js +0 -0
- /package/{psql → dist/psql}/io/pgpass.js +0 -0
- /package/{psql → dist/psql}/io/pgservice.js +0 -0
- /package/{psql → dist/psql}/io/psqlrc.js +0 -0
- /package/{psql → dist/psql}/print/aligned.js +0 -0
- /package/{psql → dist/psql}/print/asciidoc.js +0 -0
- /package/{psql → dist/psql}/print/crosstab.js +0 -0
- /package/{psql → dist/psql}/print/csv.js +0 -0
- /package/{psql → dist/psql}/print/html.js +0 -0
- /package/{psql → dist/psql}/print/json.js +0 -0
- /package/{psql → dist/psql}/print/latex.js +0 -0
- /package/{psql → dist/psql}/print/pager.js +0 -0
- /package/{psql → dist/psql}/print/troff.js +0 -0
- /package/{psql → dist/psql}/print/unaligned.js +0 -0
- /package/{psql → dist/psql}/print/units.js +0 -0
- /package/{psql → dist/psql}/scanner/slash.js +0 -0
- /package/{psql → dist/psql}/scanner/sql.js +0 -0
- /package/{psql → dist/psql}/scanner/stringutils.js +0 -0
- /package/{psql → dist/psql}/types/backslash.js +0 -0
- /package/{psql → dist/psql}/types/connection.js +0 -0
- /package/{psql → dist/psql}/types/index.js +0 -0
- /package/{psql → dist/psql}/types/printer.js +0 -0
- /package/{psql → dist/psql}/types/repl.js +0 -0
- /package/{psql → dist/psql}/types/scanner.js +0 -0
- /package/{psql → dist/psql}/types/settings.js +0 -0
- /package/{psql → dist/psql}/types/variables.js +0 -0
- /package/{psql → dist/psql}/wire/connection.js +0 -0
- /package/{psql → dist/psql}/wire/copy.js +0 -0
- /package/{psql → dist/psql}/wire/notify.js +0 -0
- /package/{psql → dist/psql}/wire/pipeline.js +0 -0
- /package/{psql → dist/psql}/wire/protocol.js +0 -0
- /package/{psql → dist/psql}/wire/sasl.js +0 -0
- /package/{psql → dist/psql}/wire/tls.js +0 -0
- /package/{test_utils → dist/test_utils}/oauth_server.js +0 -0
- /package/{types.js → dist/types.js} +0 -0
- /package/{utils → dist/utils}/auth.js +0 -0
- /package/{utils → dist/utils}/branch_notice.js +0 -0
- /package/{utils → dist/utils}/compute_units.js +0 -0
- /package/{utils → dist/utils}/esbuild.js +0 -0
- /package/{utils → dist/utils}/formats.js +0 -0
- /package/{utils → dist/utils}/middlewares.js +0 -0
- /package/{utils → dist/utils}/point_in_time.js +0 -0
- /package/{utils → dist/utils}/psql.js +0 -0
- /package/{utils → dist/utils}/string.js +0 -0
- /package/{utils → dist/utils}/ui.js +0 -0
- /package/{utils → dist/utils}/zip.js +0 -0
- /package/{writer.js → dist/writer.js} +0 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -388,12 +388,15 @@ export default defineConfig({
|
|
|
388
388
|
});
|
|
389
389
|
```
|
|
390
390
|
|
|
391
|
-
Three sub-commands plus
|
|
391
|
+
Three sub-commands plus two top-level aliases drive it:
|
|
392
392
|
|
|
393
393
|
```bash
|
|
394
394
|
# Inspect the branch's live Neon state (read-only — never mutates)
|
|
395
395
|
neon config status
|
|
396
396
|
|
|
397
|
+
# `neon status` is an alias for `neon config status`
|
|
398
|
+
neon status
|
|
399
|
+
|
|
397
400
|
# Dry-run diff: show exactly what `apply` would change
|
|
398
401
|
neon config plan
|
|
399
402
|
|
|
@@ -419,6 +422,35 @@ The branch is chosen with `--branch <id|name>`; without it the project's default
|
|
|
419
422
|
|
|
420
423
|
**Output**: `status` prints the project, branch, and reverse-engineered config; `plan` / `apply` print the planned/applied changes and any conflicts as tables. Pass `--output json` (or `--output yaml`) to emit the full machine-readable result (`PushResult`) for piping into other tools or CI.
|
|
421
424
|
|
|
425
|
+
**`config status --current-branch`** (alias `neon status --current-branch`) prints _only_ the branch pinned in the local `.neon` file — no network, no auth, no analytics — and exits non-zero when none is pinned. This behavior lets it safely drive a shell prompt. Example [starship](https://starship.rs) segment:
|
|
426
|
+
|
|
427
|
+
```toml
|
|
428
|
+
[custom.neon]
|
|
429
|
+
description = "Current Neon database branch"
|
|
430
|
+
format = "[$symbol$output]($style) "
|
|
431
|
+
style = "bold green"
|
|
432
|
+
# `symbol` below uses a Nerd Font glyph; swap it for a plain
|
|
433
|
+
# label/emoji if you don't have a Nerd Font installed.
|
|
434
|
+
symbol = " "
|
|
435
|
+
command = "neon status --current-branch"
|
|
436
|
+
# Starship evaluates this on EVERY prompt render. To keep prompts instant
|
|
437
|
+
# everywhere outside a Neon project, do a zero-subprocess walk-up for an
|
|
438
|
+
# ancestor `.neon` first (the same walk the CLI does, stopping at $HOME and /).
|
|
439
|
+
# Only when one is found do we invoke the CLI, whose exit code is the real
|
|
440
|
+
# gate: non-zero (no branch pinned) hides the segment cleanly.
|
|
441
|
+
when = '''
|
|
442
|
+
d="$PWD"
|
|
443
|
+
while [ "$d" != "$HOME" ] && [ "$d" != / ]; do
|
|
444
|
+
if [ -e "$d/.neon" ]; then
|
|
445
|
+
neon status --current-branch >/dev/null 2>&1
|
|
446
|
+
exit $?
|
|
447
|
+
fi
|
|
448
|
+
d=$(dirname "$d")
|
|
449
|
+
done
|
|
450
|
+
exit 1
|
|
451
|
+
'''
|
|
452
|
+
```
|
|
453
|
+
|
|
422
454
|
```bash
|
|
423
455
|
# CI gate: fail the build if the branch has drifted from the policy
|
|
424
456
|
neon config plan --project-id polished-snowflake-12345678 --output json
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { Analytics } from '@segment/analytics-node';
|
|
4
|
-
import { isAxiosError } from 'axios';
|
|
5
4
|
import { CREDENTIALS_FILE } from './config.js';
|
|
5
|
+
import { isCurrentBranchProbe } from './context.js';
|
|
6
6
|
import { getGithubEnvVars, isCi } from './env.js';
|
|
7
7
|
import { log } from './log.js';
|
|
8
8
|
import pkg from './pkg.js';
|
|
9
|
-
import { getApiClient } from './api.js';
|
|
9
|
+
import { getApiClient, isNeonApiError } from './api.js';
|
|
10
10
|
const WRITE_KEY = '3SQXn5ejjXWLEJ8xU2PRYhAotLtTaeeV';
|
|
11
|
+
/**
|
|
12
|
+
* Raw-argv fallback for the offline `--current-branch` probe. The init
|
|
13
|
+
* middleware runs before validation, where the parsed `currentBranch` flag may
|
|
14
|
+
* not be populated yet, so we also scan `process.argv` directly to be safe.
|
|
15
|
+
*/
|
|
16
|
+
const hasCurrentBranchArgv = () => process.argv.includes('--current-branch');
|
|
11
17
|
let client;
|
|
12
18
|
let clientInitialized = false;
|
|
13
19
|
let userId = '';
|
|
@@ -20,6 +26,13 @@ export const initAnalyticsClientMiddleware = (args) => {
|
|
|
20
26
|
if (!args.analytics || clientInitialized) {
|
|
21
27
|
return;
|
|
22
28
|
}
|
|
29
|
+
// The offline `--current-branch` probe must make zero network calls. This
|
|
30
|
+
// middleware runs before validation, so guard on the raw argv too (in case
|
|
31
|
+
// the parsed `currentBranch` flag isn't populated this early): never create
|
|
32
|
+
// the Segment client, which keeps trackEvent/closeAnalytics no-ops downstream.
|
|
33
|
+
if (isCurrentBranchProbe(args) || hasCurrentBranchArgv()) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
23
36
|
clientInitialized = true;
|
|
24
37
|
client = new Analytics({
|
|
25
38
|
writeKey: WRITE_KEY,
|
|
@@ -38,6 +51,9 @@ export const analyticsMiddleware = async (args) => {
|
|
|
38
51
|
if (!client || !args.analytics) {
|
|
39
52
|
return;
|
|
40
53
|
}
|
|
54
|
+
if (isCurrentBranchProbe(args)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
41
57
|
try {
|
|
42
58
|
const credentialsPath = join(args.configDir, CREDENTIALS_FILE);
|
|
43
59
|
const credentials = readFileSync(credentialsPath, { encoding: 'utf-8' });
|
|
@@ -98,8 +114,8 @@ export const sendError = (err, errCode) => {
|
|
|
98
114
|
if (!client) {
|
|
99
115
|
return;
|
|
100
116
|
}
|
|
101
|
-
const
|
|
102
|
-
const requestId =
|
|
117
|
+
const apiError = isNeonApiError(err) ? err : undefined;
|
|
118
|
+
const requestId = apiError?.headers?.['x-neon-ret-request-id'];
|
|
103
119
|
if (requestId) {
|
|
104
120
|
log.debug('Failed request ID: %s', requestId);
|
|
105
121
|
}
|
|
@@ -110,7 +126,7 @@ export const sendError = (err, errCode) => {
|
|
|
110
126
|
message: err.message,
|
|
111
127
|
stack: err.stack,
|
|
112
128
|
errCode,
|
|
113
|
-
statusCode:
|
|
129
|
+
statusCode: apiError?.status,
|
|
114
130
|
requestId: requestId,
|
|
115
131
|
},
|
|
116
132
|
});
|