Skip to content

Commit

Permalink
fix: fix deploy issue because botproject files structure changed (#3719)
Browse files Browse the repository at this point in the history
* fix files structure change

* add botProject interface and move some interface into shared folder

* fix lint

Co-authored-by: Chris Whitten <[email protected]>
  • Loading branch information
VanyLaw and cwhitten authored Jul 27, 2020
1 parent 0c274e0 commit 6f69c47
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { IconButton } from 'office-ui-fabric-react/lib/Button';
import { Stack } from 'office-ui-fabric-react/lib/Stack';
import { TooltipHost } from 'office-ui-fabric-react/lib/Tooltip';
import formatMessage from 'format-message';
import { ILuisConfig } from '@bfc/shared';

import { Text, Tips, Links, nameRegex } from '../../constants';
import { FieldConfig, useForm } from '../../hooks/useForm';
import { ILuisConfig } from '../../recoilModel/types';

// -------------------- Styles -------------------- //
const textFieldLabel = css`
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/pages/publish/Publish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import formatMessage from 'format-message';
import { Dialog, DialogType } from 'office-ui-fabric-react/lib/Dialog';
import { TextField } from 'office-ui-fabric-react/lib/TextField';
import { useRecoilValue } from 'recoil';
import { PublishTarget } from '@bfc/shared';

import settingsStorage from '../../utils/dialogSettingStorage';
import { projectContainer } from '../design/styles';
import { PublishTarget } from '../../recoilModel/types';
import {
settingsState,
botNameState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { Fragment, useState, useMemo } from 'react';
import { PrimaryButton, DefaultButton } from 'office-ui-fabric-react/lib/Button';
import { JsonEditor } from '@bfc/code-editor';
import { useRecoilValue } from 'recoil';
import { PublishTarget } from '@bfc/shared';

import { PublishTarget, PublishType } from '../../recoilModel/types';
import { PublishType } from '../../recoilModel/types';
import { userSettingsState } from '../../recoilModel';

import { label } from './styles';
Expand Down
3 changes: 1 addition & 2 deletions Composer/packages/client/src/pages/skills/skill-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { jsx } from '@emotion/core';
import React, { useState, useEffect } from 'react';
import formatMessage from 'format-message';
import { TextField } from 'office-ui-fabric-react/lib/TextField';

import { DialogSetting } from '../../recoilModel/types';
import { DialogSetting } from '@bfc/shared';

import { FormFieldAlignHorizontalBotSettings } from './styles';

Expand Down
4 changes: 2 additions & 2 deletions Composer/packages/client/src/recoilModel/atoms/botState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT License.

import { atom } from 'recoil';
import { DialogInfo, Diagnostic, LgFile, LuFile, BotSchemas, Skill } from '@bfc/shared';
import { DialogInfo, Diagnostic, LgFile, LuFile, BotSchemas, Skill, DialogSetting } from '@bfc/shared';

import { BotLoadError, DesignPageLocation } from '../../recoilModel/types';

import { PublishType, DialogSetting, BreadcrumbItem } from './../../recoilModel/types';
import { PublishType, BreadcrumbItem } from './../../recoilModel/types';
import { BotStatus } from './../../constants';

const getFullyQualifiedKey = (value: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { useRecoilCallback, CallbackInterface } from 'recoil';
import { dereferenceDefinitions, LuFile, DialogInfo, SensitiveProperties } from '@bfc/shared';
import { dereferenceDefinitions, LuFile, DialogInfo, SensitiveProperties, DialogSetting } from '@bfc/shared';
import { indexer, validateDialog } from '@bfc/indexers';
import objectGet from 'lodash/get';
import objectSet from 'lodash/set';
Expand All @@ -15,7 +15,6 @@ import httpClient from '../../utils/httpUtil';
import { BotStatus } from '../../constants';
import { getReferredFiles } from '../../utils/luUtil';
import luFileStatusStorage from '../../utils/luFileStatusStorage';
import { DialogSetting } from '../../recoilModel/types';
import settingStorage from '../../utils/dialogSettingStorage';
import filePersistence from '../persistence/FilePersistence';
import { navigateTo } from '../../utils/navigation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
/* eslint-disable react-hooks/rules-of-hooks */

import { CallbackInterface, useRecoilCallback } from 'recoil';
import { SensitiveProperties } from '@bfc/shared';
import { SensitiveProperties, DialogSetting, PublishTarget } from '@bfc/shared';
import get from 'lodash/get';
import has from 'lodash/has';

import settingStorage from '../../utils/dialogSettingStorage';
import { settingsState } from '../atoms/botState';
import { DialogSetting, PublishTarget } from '../../recoilModel/types';

export const settingsDispatcher = () => {
const setSettings = useRecoilCallback<[string, DialogSetting], Promise<void>>(
({ set }: CallbackInterface) => async (projectId: string, settings: DialogSetting) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import keys from 'lodash/keys';
import differenceWith from 'lodash/differenceWith';
import isEqual from 'lodash/isEqual';
import { DialogInfo } from '@bfc/shared';

import { DialogSetting } from '../../recoilModel/types';
import { DialogInfo, DialogSetting } from '@bfc/shared';

import { SkillManifest } from './../../pages/design/exportSkillModal/constants';
import { LuFile, LgFile } from './../../../../lib/shared/src/types/indexers';
Expand Down
49 changes: 9 additions & 40 deletions Composer/packages/client/src/recoilModel/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { JSONSchema7 } from '@bfc/extension';
import { AppUpdaterSettings, CodeEditorSettings, DialogInfo, LuFile, LgFile, PromptTab } from '@bfc/shared';
import {
AppUpdaterSettings,
CodeEditorSettings,
DialogInfo,
LuFile,
LgFile,
PromptTab,
DialogSetting,
} from '@bfc/shared';

import { AppUpdaterStatus } from '../constants';

Expand Down Expand Up @@ -58,17 +66,6 @@ export interface BotLoadError {
link?: { url: string; text: string };
}

export interface ILuisConfig {
name: string;
authoringKey: string;
endpointKey: string;
endpoint: string;
authoringEndpoint: string;
authoringRegion: string | 'westus';
defaultLanguage: string | 'en-us';
environment: string | 'composer';
}

export interface DesignPageLocation {
projectId: string;
dialogId: string;
Expand All @@ -86,40 +83,12 @@ export interface AppUpdateState {
version?: string;
}

export interface PublishTarget {
name: string;
type: string;
configuration: string;
lastPublished?: Date;
}

export interface BreadcrumbItem {
dialogId: string;
selected: string;
focused: string;
}

export interface DialogSetting {
MicrosoftAppId?: string;
MicrosoftAppPassword?: string;
luis: ILuisConfig;
publishTargets?: PublishTarget[];
runtime: {
customRuntime: boolean;
path: string;
command: string;
};
defaultLanguage: string;
languages: string[];
skill?: {
name: string;
manifestUrl: string;
}[];
botId?: string;
skillHostEndpoint?: string;
[key: string]: unknown;
}

export type dialogPayload = {
id: string;
content: any;
Expand Down
17 changes: 11 additions & 6 deletions Composer/packages/extensions/plugin-loader/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
import { RequestHandler } from 'express-serve-static-core';
import { JSONSchema7 } from 'json-schema';

import { IBotProject } from '@bfc/shared';
// TODO: this will be possible when ifilestorage is in a shared module
// import { IFileStorage } from '../../../server/src/models/storage/interface';

Expand Down Expand Up @@ -37,16 +37,21 @@ export interface BotTemplate {

// TODO: Add types for project, metadata
export interface PublishPlugin<Config = any> {
publish: (config: Config, project: any, metadata: any, user?: UserIdentity) => Promise<PublishResponse>;
getStatus?: (config: Config, project: any, user?: UserIdentity) => Promise<PublishResponse>;
getHistory?: (config: Config, project: any, user?: UserIdentity) => Promise<PublishResult[]>;
rollback?: (config: Config, project: any, rollbackToVersion: string, user?: UserIdentity) => Promise<PublishResponse>;
publish: (config: Config, project: IBotProject, metadata: any, user?: UserIdentity) => Promise<PublishResponse>;
getStatus?: (config: Config, project: IBotProject, user?: UserIdentity) => Promise<PublishResponse>;
getHistory?: (config: Config, project: IBotProject, user?: UserIdentity) => Promise<PublishResult[]>;
rollback?: (
config: Config,
project: IBotProject,
rollbackToVersion: string,
user?: UserIdentity
) => Promise<PublishResponse>;
[key: string]: any;
}

export interface RuntimeTemplate {
/** method used to eject the runtime into a project. returns resulting path of runtime! */
eject: (project: any, localDisk?: any) => Promise<string>;
eject: (project: IBotProject, localDisk?: any) => Promise<string>;

/** internal use key */
key: string;
Expand Down
38 changes: 38 additions & 0 deletions Composer/packages/lib/shared/src/types/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { Skill, FileInfo } from './indexers';
import { Diagnostic } from './diagnostic';
import { DialogSetting } from './settings';

export interface ProjectTemplate {
id: string;
Expand All @@ -12,3 +15,38 @@ export interface ProjectTemplate {
/* list of supported runtime versions */
support?: string[];
}

export interface IBotProject {
fileStorage: any;
dir: string;
dataDir: string;
id: string | undefined;
name: string;
luPublisher: any;
defaultSDKSchema: {
[key: string]: string;
};
defaultUISchema: {
[key: string]: string;
};
skills: Skill[];
diagnostics: Diagnostic[];
settingManager: ISettingManager;
settings: DialogSetting | null;
getProject: () => {
botName: string;
files: FileInfo[];
location: string;
schemas: any;
skills: Skill[];
diagnostics: Diagnostic[];
settings: DialogSetting | null;
};
[key: string]: any;
}

export interface ISettingManager {
get(obfuscate?: boolean): Promise<any | null>;
set(settings: any): Promise<void>;
getFileName: () => string;
}
39 changes: 39 additions & 0 deletions Composer/packages/lib/shared/src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,42 @@ export interface AppUpdaterSettings {
autoDownload: boolean;
useNightly: boolean;
}

export interface DialogSetting {
MicrosoftAppId?: string;
MicrosoftAppPassword?: string;
luis: ILuisConfig;
publishTargets?: PublishTarget[];
runtime: {
customRuntime: boolean;
path: string;
command: string;
};
defaultLanguage: string;
languages: string[];
skill?: {
name: string;
manifestUrl: string;
}[];
botId?: string;
skillHostEndpoint?: string;
[key: string]: any;
}

export interface ILuisConfig {
name: string;
endpoint: string;
authoringKey: string;
endpointKey: string;
authoringEndpoint: string;
authoringRegion: string | 'westus';
defaultLanguage: string | 'en-us';
environment: string | 'composer';
}

export interface PublishTarget {
name: string;
type: string;
configuration: string;
lastPublished?: Date;
}
20 changes: 11 additions & 9 deletions Composer/packages/server/src/controllers/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const PublishController = {
const profile = profiles.length ? profiles[0] : undefined;
const method = profile ? profile.type : undefined;

if (profile && pluginLoader?.extensions?.publish[method]?.methods?.publish) {
if (profile && method && pluginLoader?.extensions?.publish[method]?.methods?.publish) {
// append config from client(like sensitive settings)
const configuration = {
profileName: profile.name,
Expand Down Expand Up @@ -105,6 +105,7 @@ export const PublishController = {
const method = profile ? profile.type : undefined;
if (
profile &&
method &&
pluginLoader.extensions.publish[method] &&
pluginLoader.extensions.publish[method].methods &&
pluginLoader.extensions.publish[method].methods.getStatus
Expand Down Expand Up @@ -152,6 +153,7 @@ export const PublishController = {

if (
profile &&
method &&
pluginLoader.extensions.publish[method] &&
pluginLoader.extensions.publish[method].methods &&
pluginLoader.extensions.publish[method].methods.history
Expand Down Expand Up @@ -192,20 +194,20 @@ export const PublishController = {
const profile = profiles.length ? profiles[0] : undefined;
const method = profile ? profile.type : undefined;

// append config from client(like sensitive settings)
const configuration = {
profileName: profile.name,
fullSettings: merge({}, currentProject.settings, sensitiveSettings),
templatePath: path.resolve(runtimeFolder, DEFAULT_RUNTIME),
...JSON.parse(profile.configuration),
};

if (
profile &&
method &&
pluginLoader.extensions.publish[method] &&
pluginLoader.extensions.publish[method].methods &&
pluginLoader.extensions.publish[method].methods.rollback
) {
// append config from client(like sensitive settings)
const configuration = {
profileName: profile.name,
fullSettings: merge({}, currentProject.settings, sensitiveSettings),
templatePath: path.resolve(runtimeFolder, DEFAULT_RUNTIME),
...JSON.parse(profile.configuration),
};
// get the externally defined method
const pluginMethod = pluginLoader.extensions.publish[method].methods.rollback;
if (typeof pluginMethod === 'function') {
Expand Down
6 changes: 2 additions & 4 deletions Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs';

import axios from 'axios';
import { autofixReferInDialog } from '@bfc/indexers';
import { getNewDesigner, FileInfo, Skill, Diagnostic } from '@bfc/shared';
import { getNewDesigner, FileInfo, Skill, Diagnostic, IBotProject, DialogSetting, ILuisConfig } from '@bfc/shared';
import { UserIdentity, pluginLoader } from '@bfc/plugin-loader';

import { Path } from '../../utility/path';
Expand All @@ -17,13 +17,11 @@ import { DefaultSettingManager } from '../settings/defaultSettingManager';
import log from '../../logger';
import { BotProjectService } from '../../services/project';

import { ILuisConfig } from './interface';
import { ICrossTrainConfig } from './luPublisher';
import { IFileStorage } from './../storage/interface';
import { LocationRef } from './interface';
import { LuPublisher } from './luPublisher';
import { extractSkillManifestUrl } from './skillManager';
import { DialogSetting } from './interface';
import { defaultFilePath, serializeFiles } from './botStructure';

const debug = log.extend('bot-project');
Expand All @@ -36,7 +34,7 @@ const oauthInput = () => ({

const defaultLanguage = 'en-us'; // default value for settings.defaultLanguage

export class BotProject {
export class BotProject implements IBotProject {
public ref: LocationRef;
// TODO: address need to instantiate id - perhaps do so in constructor based on Store.get(projectLocationMap)
public id: string | undefined;
Expand Down
Loading

0 comments on commit 6f69c47

Please sign in to comment.