@vwala/tooling-config 1.3.1 → 1.4.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) 2026 Vwala BV
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 CHANGED
@@ -19,6 +19,8 @@ src/
19
19
  │ └── hooks/
20
20
  ├── context/ Module domain-language policy (consumed via npm)
21
21
  │ └── _scripts/
22
+ ├── gcloud/ Local Google Cloud ADC helper (consumed via npm)
23
+ │ └── ensure-gcp-application-default-credentials.sh
22
24
  ├── monorepo/ Package-manifest conventions (consumed via npm)
23
25
  │ └── _scripts/
24
26
  │ └── check-exports.mjs
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@vwala/tooling-config",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "description": "Shared tooling configuration for Vwala repositories",
6
- "license": "UNLICENSED",
6
+ "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/vwala-be/tooling-config.git"
@@ -16,6 +16,9 @@
16
16
  "!src/**/__tests__",
17
17
  "!src/**/test-support"
18
18
  ],
19
+ "bin": {
20
+ "ensure-gcp-application-default-credentials": "./src/gcloud/ensure-gcp-application-default-credentials.sh"
21
+ },
19
22
  "exports": {
20
23
  "./biome": "./src/biome/biome.config.json",
21
24
  "./commitlint": "./src/commitlint/commitlint.config.js",
@@ -0,0 +1,19 @@
1
+ # Google Cloud Application Default Credentials
2
+
3
+ Install `@vwala/tooling-config` in the workspace that needs Google Cloud access:
4
+
5
+ ```bash
6
+ pnpm add -D @vwala/tooling-config
7
+ ```
8
+
9
+ Run the packaged command before the local service starts:
10
+
11
+ ```json
12
+ {
13
+ "scripts": {
14
+ "dev": "ensure-gcp-application-default-credentials && tsx watch --clear-screen=false src/server.ts"
15
+ }
16
+ }
17
+ ```
18
+
19
+ The command validates Application Default Credentials, opens an interactive `gcloud auth application-default login` when needed, and uses `GCP_PROJECT_ID` as the quota project with `vwala-dev` as the default. Set `SKIP_GCP_ADC_CHECK=1` to skip the check; `CI=true` skips it automatically.
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Ensures Google Application Default Credentials are valid before local development.
4
+ # Use this before starting services that call Google Cloud APIs with user credentials.
5
+ #
6
+ # Usage: ensure-gcp-application-default-credentials [--help]
7
+ #
8
+ # Environment:
9
+ # SKIP_GCP_ADC_CHECK=1 Skip this check
10
+ # GCP_PROJECT_ID Quota project for ADC (default: vwala-dev)
11
+ # CI=true Always skip (CI has its own credentials)
12
+
13
+ set -euo pipefail
14
+ IFS=$'\n\t'
15
+
16
+ readonly SCRIPT_NAME="${0##*/}"
17
+ readonly CLOUD_PLATFORM_SCOPE="https://www.googleapis.com/auth/cloud-platform"
18
+ readonly DEFAULT_QUOTA_PROJECT="vwala-dev"
19
+
20
+ if [[ -t 1 ]]; then
21
+ readonly C_RESET=$'\033[0m'
22
+ readonly C_RED=$'\033[31m'
23
+ readonly C_GREEN=$'\033[32m'
24
+ readonly C_YELLOW=$'\033[33m'
25
+ readonly C_CYAN=$'\033[36m'
26
+ else
27
+ readonly C_RESET="" C_RED="" C_GREEN="" C_YELLOW="" C_CYAN=""
28
+ fi
29
+
30
+ info() { printf "%s\n" "${C_CYAN}$*${C_RESET}"; }
31
+ success() { printf "%s\n" "${C_GREEN}✓ $*${C_RESET}"; }
32
+ warn() { printf "%s\n" "${C_YELLOW}⚠ $*${C_RESET}"; }
33
+ error() { printf "%s\n" "${C_RED}✗ $*${C_RESET}" >&2; }
34
+
35
+ trap 'error "Failed on line ${LINENO}"' ERR
36
+
37
+ usage() {
38
+ cat <<EOF
39
+ Usage: ${SCRIPT_NAME} [--help]
40
+
41
+ Ensures Google Application Default Credentials (ADC) are valid before starting
42
+ local development that calls Google Cloud APIs.
43
+
44
+ Environment:
45
+ SKIP_GCP_ADC_CHECK=1 Skip this check
46
+ GCP_PROJECT_ID ADC quota project (default: ${DEFAULT_QUOTA_PROJECT})
47
+ CI=true Skip in continuous integration
48
+
49
+ Examples:
50
+ ${SCRIPT_NAME}
51
+ SKIP_GCP_ADC_CHECK=1 pnpm dev
52
+ EOF
53
+ }
54
+
55
+ require_command() {
56
+ if command -v "$1" >/dev/null 2>&1; then
57
+ return 0
58
+ fi
59
+
60
+ error "Required command '$1' is not installed."
61
+ case "$1" in
62
+ gcloud)
63
+ error "Install it with: brew install --cask google-cloud-sdk"
64
+ ;;
65
+ esac
66
+ return 1
67
+ }
68
+
69
+ is_interactive_terminal() {
70
+ [[ -t 0 ]]
71
+ }
72
+
73
+ quota_project() {
74
+ printf "%s" "${GCP_PROJECT_ID:-${DEFAULT_QUOTA_PROJECT}}"
75
+ }
76
+
77
+ should_skip_check() {
78
+ if [[ "${CI:-}" == "true" ]]; then
79
+ info "CI=true — skipping Google Application Default Credentials check."
80
+ return 0
81
+ fi
82
+
83
+ if [[ "${SKIP_GCP_ADC_CHECK:-}" == "1" ]]; then
84
+ warn "SKIP_GCP_ADC_CHECK=1 — skipping Google Application Default Credentials check."
85
+ return 0
86
+ fi
87
+
88
+ return 1
89
+ }
90
+
91
+ adc_token_is_valid() {
92
+ gcloud auth application-default print-access-token >/dev/null 2>&1
93
+ }
94
+
95
+ print_fix_instructions() {
96
+ local project
97
+ project="$(quota_project)"
98
+
99
+ error "Google Application Default Credentials are missing or expired."
100
+ error "Local features that call Google Cloud APIs require valid ADC."
101
+ error ""
102
+ error "Run these commands, then restart dev:"
103
+ error ""
104
+ error " gcloud auth application-default login --scopes=${CLOUD_PLATFORM_SCOPE}"
105
+ error " gcloud auth application-default set-quota-project ${project}"
106
+ error ""
107
+ error "If you use Google Workspace and see invalid_rapt, complete the browser"
108
+ error "re-authentication flow during gcloud auth application-default login."
109
+ error ""
110
+ error "To skip this check when not working on Google Cloud-backed features:"
111
+ error " SKIP_GCP_ADC_CHECK=1 pnpm dev"
112
+ }
113
+
114
+ run_interactive_login() {
115
+ local project
116
+ project="$(quota_project)"
117
+
118
+ info "Starting interactive Application Default Credentials login…"
119
+ gcloud auth application-default login --scopes="${CLOUD_PLATFORM_SCOPE}"
120
+ gcloud auth application-default set-quota-project "${project}"
121
+ success "Application Default Credentials configured (quota project: ${project})."
122
+ }
123
+
124
+ ensure_application_default_credentials() {
125
+ if should_skip_check; then
126
+ return 0
127
+ fi
128
+
129
+ require_command gcloud
130
+
131
+ if adc_token_is_valid; then
132
+ success "Google Application Default Credentials are valid."
133
+ return 0
134
+ fi
135
+
136
+ warn "Application Default Credentials are missing or expired."
137
+
138
+ if is_interactive_terminal; then
139
+ run_interactive_login
140
+ if adc_token_is_valid; then
141
+ success "Google Application Default Credentials are valid."
142
+ return 0
143
+ fi
144
+
145
+ error "Login completed but credentials are still invalid."
146
+ print_fix_instructions
147
+ return 1
148
+ fi
149
+
150
+ print_fix_instructions
151
+ error "Non-interactive terminal — cannot run gcloud auth application-default login automatically."
152
+ return 1
153
+ }
154
+
155
+ main() {
156
+ case "${1:-}" in
157
+ -h | --help)
158
+ usage
159
+ exit 0
160
+ ;;
161
+ "")
162
+ ensure_application_default_credentials
163
+ ;;
164
+ *)
165
+ error "Unknown option: $1"
166
+ usage
167
+ exit 1
168
+ ;;
169
+ esac
170
+ }
171
+
172
+ main "$@"