Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export default {
description:
'username used to authenticate when publishing to registry'
},
token: {
description: 'token used to authenticate when publishing to registry'
},
skipPackage: {
boolean: true,
description: 'Skip packaging step',
Expand Down
7 changes: 6 additions & 1 deletion src/cli/domain/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ export default function registry(opts: RegistryOptions = {}) {
async putComponent(options: {
username?: string;
password?: string;
token?: string;
route: string;
path: string;
}): Promise<void> {
if (!!options.username && !!options.password) {
if (options.token) {
requestsHeaders = Object.assign(requestsHeaders, {
Authorization: `Bearer ${options.token}`
});
} else if (!!options.username && !!options.password) {
requestsHeaders = Object.assign(requestsHeaders, {
Authorization:
'Basic ' +
Expand Down
14 changes: 11 additions & 3 deletions src/cli/facade/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const publish = ({
dryRun?: boolean;
username?: string;
password?: string;
token?: string;
registries?: string[];
}): Promise<void> => {
const componentPath = opts.componentPath;
Expand All @@ -46,9 +47,15 @@ const publish = ({
fs.readJson(path.join(packageDir, 'package.json'));

const getCredentials = async (): Promise<{
username: string;
password: string;
username?: string;
password?: string;
token?: string;
}> => {
if (opts.token) {
logger.ok(strings.messages.cli.USING_CREDS);
return { token: opts.token };
}

if (opts.username && opts.password) {
logger.ok(strings.messages.cli.USING_CREDS);
const { username, password } = opts;
Expand Down Expand Up @@ -85,6 +92,7 @@ const publish = ({
path: string;
username?: string;
password?: string;
token?: string;
}): Promise<void> => {
logger.warn(strings.messages.cli.PUBLISHING(options.route, dryRun));

Expand All @@ -93,7 +101,7 @@ const publish = ({
logger.ok(strings.messages.cli.PUBLISHED(options.route, dryRun));
} catch (err: any) {
if (err === 'Unauthorized' || err.message === 'Unauthorized') {
if (!!options.username || !!options.password) {
if (!!options.username || !!options.password || !!options.token) {
logger.err(
strings.errors.cli.PUBLISHING_FAIL(
strings.errors.cli.INVALID_CREDENTIALS
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { NextFunction, Request, Response } from 'express';
import type { StorageAdapter } from 'oc-storage-adapters-utils';
import type { PackageJson } from 'type-fest';

type Middleware = (req: Request, res: Response, next: NextFunction) => void;

export interface Author {
email?: string;
name?: string;
Expand Down Expand Up @@ -134,7 +136,7 @@ export type Authentication<T = any> = {
isValid: boolean;
message: string;
};
middleware: (config: T) => any;
middleware: (config: T) => Middleware;
};

export type PublishAuthConfig =
Expand Down