blimu 0.0.1 → 0.6.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/README.md CHANGED
@@ -1,14 +1,41 @@
1
1
  # blimu
2
2
 
3
- This package is a placeholder to reserve the "blimu" package name on npm.
3
+ Blimu - Authorization as a Service. This package provides the Blimu CLI tool for managing your authorization configuration.
4
4
 
5
- For the actual Blimu SDK packages, please use:
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install blimu
9
+ # or
10
+ yarn add blimu
11
+ # or
12
+ pnpm add blimu
13
+ ```
6
14
 
7
- - `@blimu/backend` - TypeScript SDK for Blimu API
8
- - `@blimu/client` - Client SDK for Blimu
9
- - `@blimu/nestjs` - NestJS integration for Blimu
15
+ After installation, the Blimu CLI binary will be automatically downloaded and made available via the `blimu` command.
10
16
 
11
- ## Installation
17
+ ## Usage
18
+
19
+ Once installed, you can use the Blimu CLI to manage your authorization configuration:
20
+
21
+ ```bash
22
+ # Validate your Blimu configuration
23
+ blimu validate ./blimu/
24
+
25
+ # Push configuration to an environment
26
+ blimu push ./blimu/ --workspace-id <workspace-id> --environment-id <environment-id>
27
+
28
+ # Pull configuration from an environment
29
+ blimu pull ./blimu/ --workspace-id <workspace-id> --environment-id <environment-id>
30
+ ```
31
+
32
+ ## SDK Packages
33
+
34
+ For programmatic access to the Blimu API, use the following SDK packages:
35
+
36
+ - **`@blimu/backend`** - TypeScript SDK for Blimu Runtime API (resource management, roles, entitlements, usage tracking)
37
+ - **`@blimu/client`** - TypeScript SDK for Blimu Client API (authentication, session management)
38
+ - **`@blimu/nestjs`** - NestJS integration for Blimu
12
39
 
13
40
  ```bash
14
41
  npm install @blimu/backend
package/bin/blimu ADDED
Binary file
package/package.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "blimu",
3
- "licenses": "MIT",
4
- "version": "0.0.1",
3
+ "version": "0.6.1",
5
4
  "description": "Blimu - Authorization as a Service",
6
5
  "main": "index.js",
7
6
  "types": "index.d.ts",
7
+ "bin": "./bin/blimu",
8
8
  "files": [
9
9
  "index.js",
10
10
  "index.d.ts",
11
- "README.md"
11
+ "README.md",
12
+ "bin/**",
13
+ "scripts/**"
12
14
  ],
15
+ "scripts": {
16
+ "postinstall": "node scripts/postinstall.js"
17
+ },
13
18
  "repository": {
14
19
  "type": "git",
15
- "url": "https://github.com/blimu/blimu-ts"
20
+ "url": "https://github.com/blimu-dev/blimu-ts"
16
21
  },
17
22
  "author": "viniciusdacal",
18
23
  "license": "MIT",
@@ -0,0 +1,243 @@
1
+ #!/usr/bin/env node
2
+
3
+ const https = require('https');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { execSync } = require('child_process');
7
+
8
+ const BIN_DIR = path.join(__dirname, '..', 'bin');
9
+ const GITHUB_REPO = 'blimu-dev/blimu-cli';
10
+
11
+ // Platform mapping
12
+ const platformMap = {
13
+ darwin: 'darwin',
14
+ linux: 'linux',
15
+ win32: 'windows',
16
+ };
17
+
18
+ // Architecture mapping
19
+ const archMap = {
20
+ x64: 'amd64',
21
+ arm64: 'arm64',
22
+ };
23
+
24
+ function getPlatformInfo() {
25
+ const platform = process.platform;
26
+ const arch = process.arch;
27
+
28
+ const goPlatform = platformMap[platform];
29
+ const goArch = archMap[arch];
30
+
31
+ if (!goPlatform || !goArch) {
32
+ throw new Error(
33
+ `Unsupported platform: ${platform}/${arch}. Supported platforms: darwin, linux, win32. Supported architectures: x64, arm64`,
34
+ );
35
+ }
36
+
37
+ const binaryName = platform === 'win32' ? 'blimu.exe' : 'blimu';
38
+ const assetName = `blimu-${goPlatform}-${goArch}${platform === 'win32' ? '.exe' : ''}`;
39
+
40
+ return {
41
+ platform: goPlatform,
42
+ arch: goArch,
43
+ binaryName,
44
+ assetName,
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Verify that an existing binary matches the current platform/architecture
50
+ * Returns true if the binary is correct, false otherwise
51
+ */
52
+ function verifyBinaryArchitecture(binaryPath) {
53
+ try {
54
+ // Use 'file' command to check binary type (available on macOS and Linux)
55
+ const output = execSync(`file "${binaryPath}"`, { encoding: 'utf8' });
56
+
57
+ const platform = process.platform;
58
+ const arch = process.arch;
59
+
60
+ if (platform === 'darwin') {
61
+ // macOS: should be "Mach-O 64-bit executable arm64" or "Mach-O 64-bit executable x86_64"
62
+ const expectedArch = arch === 'arm64' ? 'arm64' : 'x86_64';
63
+ if (!output.includes('Mach-O') || !output.includes(expectedArch)) {
64
+ return false;
65
+ }
66
+ } else if (platform === 'linux') {
67
+ // Linux: should be "ELF 64-bit LSB executable, x86-64" or "ELF 64-bit LSB executable, ARM aarch64"
68
+ const expectedArch = arch === 'arm64' ? 'ARM aarch64' : 'x86-64';
69
+ if (!output.includes('ELF') || !output.includes(expectedArch)) {
70
+ return false;
71
+ }
72
+ } else if (platform === 'win32') {
73
+ // Windows: should be "PE32+ executable"
74
+ if (!output.includes('PE32+')) {
75
+ return false;
76
+ }
77
+ }
78
+
79
+ return true;
80
+ } catch (err) {
81
+ // If 'file' command fails or is not available, assume binary is incorrect to be safe
82
+ // This will trigger a re-download
83
+ return false;
84
+ }
85
+ }
86
+
87
+ function downloadFile(url, dest) {
88
+ return new Promise((resolve, reject) => {
89
+ const file = fs.createWriteStream(dest);
90
+ https
91
+ .get(url, (response) => {
92
+ if (response.statusCode === 302 || response.statusCode === 301) {
93
+ // Follow redirect
94
+ return downloadFile(response.headers.location, dest).then(resolve).catch(reject);
95
+ }
96
+ if (response.statusCode !== 200) {
97
+ file.close();
98
+ fs.unlinkSync(dest);
99
+ reject(new Error(`Failed to download: ${response.statusCode} ${response.statusMessage}`));
100
+ return;
101
+ }
102
+ response.pipe(file);
103
+ file.on('finish', () => {
104
+ file.close();
105
+ resolve();
106
+ });
107
+ })
108
+ .on('error', (err) => {
109
+ file.close();
110
+ if (fs.existsSync(dest)) {
111
+ fs.unlinkSync(dest);
112
+ }
113
+ reject(err);
114
+ });
115
+ });
116
+ }
117
+
118
+ function getReleaseUrl(version, assetName) {
119
+ return new Promise((resolve, reject) => {
120
+ // Always use latest release - version parameter is ignored
121
+ const tag = 'latest';
122
+ const url = `https://api.github.com/repos/${GITHUB_REPO}/releases/${tag}`;
123
+
124
+ https
125
+ .get(
126
+ url,
127
+ {
128
+ headers: {
129
+ 'User-Agent': 'blimu-installer',
130
+ Accept: 'application/vnd.github.v3+json',
131
+ },
132
+ },
133
+ (res) => {
134
+ let data = '';
135
+ res.on('data', (chunk) => {
136
+ data += chunk;
137
+ });
138
+ res.on('end', () => {
139
+ if (res.statusCode === 404) {
140
+ reject(
141
+ new Error(
142
+ `Latest CLI release not found. Please check the blimu-cli repository for available releases.`,
143
+ ),
144
+ );
145
+ return;
146
+ }
147
+ if (res.statusCode !== 200) {
148
+ reject(
149
+ new Error(`Failed to fetch latest release: ${res.statusCode} ${res.statusMessage}`),
150
+ );
151
+ return;
152
+ }
153
+ try {
154
+ const release = JSON.parse(data);
155
+ const asset = release.assets.find((a) => a.name === assetName);
156
+ if (!asset) {
157
+ reject(new Error(`Asset ${assetName} not found in latest release`));
158
+ return;
159
+ }
160
+ resolve(asset.browser_download_url);
161
+ } catch (err) {
162
+ reject(err);
163
+ }
164
+ });
165
+ },
166
+ )
167
+ .on('error', reject);
168
+ });
169
+ }
170
+
171
+ async function main(version) {
172
+ try {
173
+ // Always use latest version - version parameter is ignored for consistency
174
+ // This ensures users always get the latest CLI features and fixes
175
+ version = null;
176
+
177
+ const { binaryName, assetName } = getPlatformInfo();
178
+
179
+ // Create bin directory if it doesn't exist
180
+ if (!fs.existsSync(BIN_DIR)) {
181
+ fs.mkdirSync(BIN_DIR, { recursive: true });
182
+ }
183
+
184
+ const binaryPath = path.join(BIN_DIR, binaryName);
185
+
186
+ // Check if binary already exists and is executable
187
+ if (fs.existsSync(binaryPath)) {
188
+ // Verify the binary matches the current platform/architecture
189
+ const isCorrectArchitecture = verifyBinaryArchitecture(binaryPath);
190
+
191
+ if (isCorrectArchitecture) {
192
+ try {
193
+ // Try to make it executable (Unix only)
194
+ if (process.platform !== 'win32') {
195
+ fs.chmodSync(binaryPath, 0o755);
196
+ }
197
+ console.log(`✅ Blimu CLI binary already exists at ${binaryPath}`);
198
+ return;
199
+ } catch (err) {
200
+ // If we can't check/update permissions, continue to download
201
+ }
202
+ } else {
203
+ // Binary exists but is for wrong platform/architecture - delete it
204
+ console.log(`⚠️ Existing binary is for wrong platform/architecture, will re-download...`);
205
+ try {
206
+ fs.unlinkSync(binaryPath);
207
+ } catch (err) {
208
+ console.warn(`Warning: Could not delete incorrect binary: ${err.message}`);
209
+ }
210
+ }
211
+ }
212
+
213
+ console.log(
214
+ `📥 Downloading Blimu CLI binary (latest) for ${process.platform}/${process.arch}...`,
215
+ );
216
+
217
+ // Get release download URL
218
+ const downloadUrl = await getReleaseUrl(version, assetName);
219
+ console.log(`🔗 Download URL: ${downloadUrl}`);
220
+
221
+ // Download the binary
222
+ await downloadFile(downloadUrl, binaryPath);
223
+
224
+ // Make binary executable (Unix only)
225
+ if (process.platform !== 'win32') {
226
+ fs.chmodSync(binaryPath, 0o755);
227
+ }
228
+
229
+ console.log(`✅ Blimu CLI binary downloaded successfully to ${binaryPath}`);
230
+ } catch (error) {
231
+ console.error(`❌ Failed to download Blimu CLI binary: ${error.message}`);
232
+ console.error(`\nYou can manually install it by running:`);
233
+ console.error(` go install github.com/blimu-dev/blimu-cli/cmd/blimucli@latest`);
234
+ console.error(`\nOr download from: https://github.com/${GITHUB_REPO}/releases/latest`);
235
+ process.exit(1);
236
+ }
237
+ }
238
+
239
+ if (require.main === module) {
240
+ main();
241
+ }
242
+
243
+ module.exports = { main, getPlatformInfo };
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { main } = require('./download-binary');
4
+
5
+ // Only run download if we're in a production install (not in development)
6
+ // Check if we're in node_modules (production install) or in the repo (development)
7
+ const isProductionInstall = __dirname.includes('node_modules');
8
+
9
+ if (isProductionInstall || process.env.BLIMU_DOWNLOAD_CLI !== 'false') {
10
+ // Always download the latest CLI version
11
+ main(null).catch((error) => {
12
+ // Fail the install if binary download fails
13
+ console.error('Error: Failed to download Blimu CLI binary during install.');
14
+ console.error(error.message);
15
+ console.error('\nThe package will download the latest available CLI version.');
16
+ console.error('\nYou can manually install it by running:');
17
+ console.error(' go install github.com/blimu-dev/blimu-cli/cmd/blimucli@latest');
18
+ process.exit(1);
19
+ });
20
+ } else {
21
+ console.log('Skipping Blimu CLI binary download (development mode)');
22
+ }