berget 2.1.2 → 2.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.
@@ -1,11 +1,16 @@
1
1
  name: Publish to NPM
2
2
 
3
3
  on:
4
- push:
5
- branches:
6
- - main
7
- release:
8
- types: [published]
4
+ workflow_dispatch:
5
+ inputs:
6
+ bump:
7
+ description: 'Version bump type'
8
+ required: true
9
+ type: choice
10
+ options:
11
+ - patch
12
+ - minor
13
+ - major
9
14
 
10
15
  jobs:
11
16
  test:
@@ -32,10 +37,12 @@ jobs:
32
37
  publish:
33
38
  needs: test
34
39
  runs-on: ubuntu-latest
35
- if: github.ref == 'refs/heads/main' || github.event_name == 'release'
36
40
  steps:
37
41
  - name: Checkout code
38
42
  uses: actions/checkout@v4
43
+ with:
44
+ fetch-depth: 0
45
+ ref: main
39
46
 
40
47
  - name: Setup Node.js
41
48
  uses: actions/setup-node@v4
@@ -50,6 +57,13 @@ jobs:
50
57
  - name: Build project
51
58
  run: npm run build
52
59
 
60
+ - name: Bump version
61
+ run: |
62
+ git config user.name "github-actions[bot]"
63
+ git config user.email "github-actions[bot]@users.noreply.github.com"
64
+ npm version ${{ inputs.bump }} -m "release: %s"
65
+ git push --follow-tags
66
+
53
67
  - name: Publish to NPM
54
68
  run: npm publish
55
69
  env:
package/dist/index.js CHANGED
@@ -24,7 +24,8 @@ commander_1.program
24
24
  |___/ AI on European terms
25
25
  Version: ${package_json_1.version}`)
26
26
  .version(package_json_1.version, '-v, --version')
27
- .option('--local', 'Use local API endpoint (hidden)', false)
27
+ .addOption(new commander_1.Option('--local').default(false).hideHelp())
28
+ .addOption(new commander_1.Option('--stage').default(false).hideHelp())
28
29
  .option('--debug', 'Enable debug output', false);
29
30
  // Register all commands
30
31
  (0, commands_1.registerCommands)(commander_1.program);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "berget",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "berget": "dist/index.js"
@@ -19,12 +19,19 @@ const token_manager_1 = require("./utils/token-manager");
19
19
  const logger_1 = require("./utils/logger");
20
20
  // API Base URL
21
21
  // Use --local flag to test against local API
22
+ // Use --stage flag to test against stage API
22
23
  const isLocalMode = process.argv.includes('--local');
24
+ const isStageMode = process.argv.includes('--stage');
23
25
  exports.API_BASE_URL = process.env.BERGET_API_URL ||
24
- (isLocalMode ? 'http://localhost:3000' : 'https://api.berget.ai');
26
+ (isLocalMode ? 'http://localhost:3000' :
27
+ isStageMode ? 'https://api.stage.berget.ai' :
28
+ 'https://api.berget.ai'); // production default
25
29
  if (isLocalMode && !process.env.BERGET_API_URL) {
26
30
  logger_1.logger.debug('Using local API endpoint: http://localhost:3000');
27
31
  }
32
+ else if (isStageMode && !process.env.BERGET_API_URL) {
33
+ logger_1.logger.debug('Using stage API endpoint: https://api.stage.berget.ai');
34
+ }
28
35
  // Create a typed client for the Berget API
29
36
  exports.apiClient = (0, openapi_fetch_1.default)({
30
37
  baseUrl: exports.API_BASE_URL,
@@ -177,6 +184,12 @@ const createAuthenticatedClient = () => {
177
184
  });
178
185
  };
179
186
  exports.createAuthenticatedClient = createAuthenticatedClient;
187
+ // Keycloak configuration for token refresh (must match auth-service.ts)
188
+ const KEYCLOAK_URL = (isStageMode || isLocalMode)
189
+ ? 'https://keycloak.stage.berget.ai'
190
+ : 'https://keycloak.berget.ai';
191
+ const KEYCLOAK_REALM = 'berget';
192
+ const KEYCLOAK_CLIENT_ID = 'berget-code';
180
193
  // Helper function to refresh the access token
181
194
  function refreshAccessToken(tokenManager) {
182
195
  return __awaiter(this, void 0, void 0, function* () {
@@ -185,15 +198,18 @@ function refreshAccessToken(tokenManager) {
185
198
  if (!refreshToken)
186
199
  return false;
187
200
  logger_1.logger.debug('Attempting to refresh access token');
188
- // Use fetch directly since this endpoint might not be in the OpenAPI spec
201
+ // Refresh directly against Keycloak (berget-code is a public PKCE client)
189
202
  try {
190
- const response = yield fetch(`${exports.API_BASE_URL}/v1/auth/refresh`, {
203
+ const response = yield fetch(`${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/token`, {
191
204
  method: 'POST',
192
205
  headers: {
193
- 'Content-Type': 'application/json',
194
- Accept: 'application/json',
206
+ 'Content-Type': 'application/x-www-form-urlencoded',
195
207
  },
196
- body: JSON.stringify({ refresh_token: refreshToken }),
208
+ body: new URLSearchParams({
209
+ grant_type: 'refresh_token',
210
+ client_id: KEYCLOAK_CLIENT_ID,
211
+ refresh_token: refreshToken,
212
+ }),
197
213
  });
198
214
  // Handle HTTP errors
199
215
  if (!response.ok) {