@o861runners/nmp 1.26.13-0.11255

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.
@@ -0,0 +1,86 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import fetch from 'node-fetch';
4
+ import FormData from 'form-data';
5
+ import { BaseRegistry } from '../core/registry.js';
6
+
7
+ export class SupabaseRegistry extends BaseRegistry {
8
+ async validate() {
9
+ if (!this.config.url) {
10
+ throw new Error('Supabase registry requires url');
11
+ }
12
+ if (!this.config.bucket) {
13
+ throw new Error('Supabase registry requires bucket');
14
+ }
15
+ if (!this.config.serviceKey) {
16
+ throw new Error('Supabase registry requires serviceKey');
17
+ }
18
+ }
19
+
20
+ async authenticate() {
21
+ // Test connection
22
+ const response = await fetch(
23
+ `${this.config.url}/storage/v1/bucket/${this.config.bucket}`,
24
+ {
25
+ headers: {
26
+ Authorization: `Bearer ${this.config.serviceKey}`,
27
+ },
28
+ }
29
+ );
30
+
31
+ if (!response.ok) {
32
+ throw new Error(`Supabase auth failed: ${response.statusText}`);
33
+ }
34
+ }
35
+
36
+ async publish(artifactPath) {
37
+ const fileName = path.basename(artifactPath);
38
+ const fileStream = fs.createReadStream(artifactPath);
39
+
40
+ const form = new FormData();
41
+ form.append('file', fileStream);
42
+
43
+ console.log(`📦 Uploading to Supabase Storage...`);
44
+ console.log(` Bucket: ${this.config.bucket}`);
45
+ console.log(` File: ${fileName}`);
46
+
47
+ try {
48
+ const response = await fetch(
49
+ `${this.config.url}/storage/v1/object/${this.config.bucket}/${fileName}`,
50
+ {
51
+ method: 'POST',
52
+ headers: {
53
+ Authorization: `Bearer ${this.config.serviceKey}`,
54
+ ...form.getHeaders(),
55
+ },
56
+ body: form,
57
+ }
58
+ );
59
+
60
+ if (!response.ok) {
61
+ const error = await response.text();
62
+ throw new Error(`Upload failed: ${error}`);
63
+ }
64
+
65
+ const data = await response.json();
66
+
67
+ // Generate public URL if configured
68
+ let publicUrl = null;
69
+ if (this.config.public) {
70
+ publicUrl = `${this.config.url}/storage/v1/object/public/${this.config.bucket}/${fileName}`;
71
+ console.log(` Public URL: ${publicUrl}`);
72
+ }
73
+
74
+ return {
75
+ success: true,
76
+ url: publicUrl,
77
+ key: data.Key,
78
+ };
79
+ } catch (error) {
80
+ return {
81
+ success: false,
82
+ error: error.message,
83
+ };
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Build npm publish args từ registry config
3
+ * @param {object} registryConfig - Registry configuration
4
+ * @param {object} globalConfig - Global configuration
5
+ * @returns {array} - Array of npm args
6
+ */
7
+ export function buildNpmArgs(registryConfig, globalConfig) {
8
+ const args = ["publish"];
9
+
10
+ // 1. Default args (từ config hoặc built-in)
11
+ const defaultArgs = globalConfig.npm?.defaultArgs || ["--no-git-checks"];
12
+ args.push(...defaultArgs);
13
+
14
+ // 2. Registry-specific
15
+ if (registryConfig.registry && registryConfig.type !== "gitea") {
16
+ args.push(`--registry=${registryConfig.registry}`);
17
+ }
18
+
19
+ if (registryConfig.access) {
20
+ args.push(`--access=${registryConfig.access}`);
21
+ }
22
+
23
+ if (registryConfig.tag) {
24
+ args.push(`--tag=${registryConfig.tag}`);
25
+ }
26
+
27
+ // 3. Custom args (đã được replace {{VAR}})
28
+ const customArgs = globalConfig.npm?.customArgs || [];
29
+ args.push(...customArgs);
30
+
31
+ return args;
32
+ }
33
+
34
+ /**
35
+ * Parse CLI args để lấy pass-through args
36
+ * @param {array} argv - process.argv
37
+ * @returns {array} - Args to pass to npm
38
+ */
39
+ export function parseCLIArgs(argv) {
40
+ const doubleDashIndex = argv.indexOf("--");
41
+
42
+ if (doubleDashIndex === -1) {
43
+ return [];
44
+ }
45
+
46
+ // Tất cả args sau -- sẽ pass cho npm
47
+ return argv.slice(doubleDashIndex + 1);
48
+ }