@backstage/plugin-catalog-import 0.12.12-next.0 → 0.12.12

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/CHANGELOG.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # @backstage/plugin-catalog-import
2
2
 
3
- ## 0.12.12-next.0
3
+ ## 0.12.12
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - e50a4f7: Expose the `UnpackNestedValue` type as it's been removed from `react-hook-form`
7
8
  - Updated dependencies
8
- - @backstage/plugin-catalog-react@1.16.1-next.0
9
- - @backstage/core-compat-api@0.4.1-next.0
10
9
  - @backstage/catalog-client@1.9.1
11
10
  - @backstage/catalog-model@1.7.3
12
11
  - @backstage/config@1.3.2
12
+ - @backstage/core-compat-api@0.4.0
13
13
  - @backstage/core-components@0.17.0
14
14
  - @backstage/core-plugin-api@1.10.5
15
15
  - @backstage/errors@1.2.7
@@ -17,6 +17,7 @@
17
17
  - @backstage/integration@1.16.2
18
18
  - @backstage/integration-react@1.2.5
19
19
  - @backstage/plugin-catalog-common@1.1.3
20
+ - @backstage/plugin-catalog-react@1.16.0
20
21
 
21
22
  ## 0.12.11
22
23
 
@@ -1 +1 @@
1
- {"version":3,"file":"StepPrepareCreatePullRequest.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity } from '@backstage/catalog-model';\nimport { errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport { assertError } from '@backstage/errors';\nimport {\n catalogApiRef,\n humanizeEntityRef,\n} from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport { UnpackNestedValue, UseFormReturn } from 'react-hook-form';\nimport useAsync from 'react-use/esm/useAsync';\nimport YAML from 'yaml';\nimport { AnalyzeResult, catalogImportApiRef } from '../../api';\nimport { useCatalogFilename } from '../../hooks';\nimport { PartialEntity } from '../../types';\nimport { BackButton, NextButton } from '../Buttons';\nimport { PrepareResult } from '../useImportState';\nimport { PreparePullRequestForm } from './PreparePullRequestForm';\nimport { PreviewCatalogInfoComponent } from './PreviewCatalogInfoComponent';\nimport { PreviewPullRequestComponent } from './PreviewPullRequestComponent';\n\nconst useStyles = makeStyles(theme => ({\n previewCard: {\n marginTop: theme.spacing(1),\n },\n previewCardContent: {\n paddingTop: 0,\n },\n}));\n\ntype FormData = {\n title: string;\n body: string;\n componentName: string;\n owner: string;\n useCodeowners: boolean;\n};\n\n/**\n * Props for {@link StepPrepareCreatePullRequest}.\n *\n * @public\n */\nexport interface StepPrepareCreatePullRequestProps {\n analyzeResult: Extract<AnalyzeResult, { type: 'repository' }>;\n onPrepare: (\n result: PrepareResult,\n opts?: { notRepeatable?: boolean },\n ) => void;\n onGoBack?: () => void;\n\n renderFormFields: (\n props: Pick<\n UseFormReturn<FormData>,\n 'register' | 'setValue' | 'formState'\n > & {\n values: UnpackNestedValue<FormData>;\n groups: string[];\n groupsLoading: boolean;\n },\n ) => React.ReactNode;\n}\n\nexport function generateEntities(\n entities: PartialEntity[],\n componentName: string,\n owner?: string,\n): Entity[] {\n return entities.map(e => ({\n ...e,\n apiVersion: e.apiVersion!,\n kind: e.kind!,\n metadata: {\n ...e.metadata,\n name: componentName,\n },\n spec: {\n ...e.spec,\n ...(owner ? { owner } : {}),\n },\n }));\n}\n\n/**\n * Prepares a pull request.\n *\n * @public\n */\nexport const StepPrepareCreatePullRequest = (\n props: StepPrepareCreatePullRequestProps,\n) => {\n const { analyzeResult, onPrepare, onGoBack, renderFormFields } = props;\n\n const classes = useStyles();\n const catalogApi = useApi(catalogApiRef);\n const catalogImportApi = useApi(catalogImportApiRef);\n const errorApi = useApi(errorApiRef);\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string>();\n\n const catalogFilename = useCatalogFilename();\n\n const {\n loading: prDefaultsLoading,\n value: prDefaults,\n error: prDefaultsError,\n } = useAsync(\n () => catalogImportApi.preparePullRequest!(),\n [catalogImportApi.preparePullRequest],\n );\n\n useEffect(() => {\n if (prDefaultsError) {\n errorApi.post(prDefaultsError);\n }\n }, [prDefaultsError, errorApi]);\n\n const { loading: groupsLoading, value: groups } = useAsync(async () => {\n const groupEntities = await catalogApi.getEntities({\n filter: { kind: 'group' },\n });\n\n return groupEntities.items\n .map(e => humanizeEntityRef(e, { defaultKind: 'group' }))\n .sort();\n });\n\n const handleResult = useCallback(\n async (data: FormData) => {\n setSubmitted(true);\n\n try {\n const pr = await catalogImportApi.submitPullRequest({\n repositoryUrl: analyzeResult.url,\n title: data.title,\n body: data.body,\n fileContent: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n )\n .map(e => YAML.stringify(e))\n .join('---\\n'),\n });\n\n onPrepare(\n {\n type: 'repository',\n url: analyzeResult.url,\n integrationType: analyzeResult.integrationType,\n pullRequest: {\n url: pr.link,\n },\n locations: [\n {\n target: pr.location,\n entities: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n ).map(e => ({\n kind: e.kind,\n namespace: e.metadata.namespace!,\n name: e.metadata.name,\n })),\n },\n ],\n },\n { notRepeatable: true },\n );\n } catch (e) {\n assertError(e);\n setError(e.message);\n setSubmitted(false);\n }\n },\n [\n analyzeResult.generatedEntities,\n analyzeResult.integrationType,\n analyzeResult.url,\n catalogImportApi,\n onPrepare,\n ],\n );\n\n return (\n <>\n <Typography>\n You entered a link to a {analyzeResult.integrationType} repository but a{' '}\n <code>{catalogFilename}</code> could not be found. Use this form to open\n a Pull Request that creates one.\n </Typography>\n\n {!prDefaultsLoading && (\n <PreparePullRequestForm<FormData>\n onSubmit={handleResult}\n defaultValues={{\n title: prDefaults?.title ?? '',\n body: prDefaults?.body ?? '',\n owner:\n (analyzeResult.generatedEntities[0]?.spec?.owner as string) || '',\n componentName:\n analyzeResult.generatedEntities[0]?.metadata?.name || '',\n useCodeowners: false,\n }}\n render={({ values, formState, register, setValue }) => (\n <>\n {renderFormFields({\n values,\n formState,\n register,\n setValue,\n groups: groups ?? [],\n groupsLoading,\n })}\n\n <Box marginTop={2}>\n <Typography variant=\"h6\">Preview Pull Request</Typography>\n </Box>\n\n <PreviewPullRequestComponent\n title={values.title}\n description={values.body}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n <Box marginTop={2} marginBottom={1}>\n <Typography variant=\"h6\">Preview Entities</Typography>\n </Box>\n\n <PreviewCatalogInfoComponent\n entities={generateEntities(\n analyzeResult.generatedEntities,\n values.componentName,\n values.owner,\n )}\n repositoryUrl={analyzeResult.url}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n {onGoBack && (\n <BackButton onClick={onGoBack} disabled={submitted} />\n )}\n <NextButton\n type=\"submit\"\n disabled={Boolean(\n formState.errors.title ||\n formState.errors.body ||\n formState.errors.owner,\n )}\n loading={submitted}\n >\n Create PR\n </NextButton>\n </Grid>\n </>\n )}\n />\n )}\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,WAAa,EAAA;AAAA,IACX,SAAA,EAAW,KAAM,CAAA,OAAA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,QAAU,EAAA,gBAAA;AAAA,YACR,aAAc,CAAA,iBAAA;AAAA,YACd,MAAO,CAAA,aAAA;AAAA,YACP,MAAO,CAAA;AAAA,WACT;AAAA,UACA,eAAe,aAAc,CAAA,GAAA;AAAA,UAC7B,OAAS,EAAA;AAAA,YACP,MAAM,OAAQ,CAAA,WAAA;AAAA,YACd,aAAa,OAAQ,CAAA;AAAA;AACvB;AAAA,OACF,EAEC,yBAAU,KAAA,CAAA,aAAA,CAAA,cAAA,EAAA,EAAe,OAAK,IAAE,EAAA,EAAA,KAAM,mBAEtC,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,WAAS,IAAC,EAAA,OAAA,EAAS,KACtB,QACC,oBAAA,KAAA,CAAA,aAAA,CAAC,cAAW,OAAS,EAAA,QAAA,EAAU,QAAU,EAAA,SAAA,EAAW,CAEtD,kBAAA,KAAA,CAAA,aAAA;AAAA,QAAC,UAAA;AAAA,QAAA;AAAA,UACC,IAAK,EAAA,QAAA;AAAA,UACL,QAAU,EAAA,OAAA;AAAA,YACR,UAAU,MAAO,CAAA,KAAA,IACf,UAAU,MAAO,CAAA,IAAA,IACjB,UAAU,MAAO,CAAA;AAAA,WACrB;AAAA,UACA,OAAS,EAAA;AAAA,SAAA;AAAA,QACV;AAAA,OAGH,CACF;AAAA;AAAA,GAIR,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"StepPrepareCreatePullRequest.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity } from '@backstage/catalog-model';\nimport { errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport { assertError } from '@backstage/errors';\nimport {\n catalogApiRef,\n humanizeEntityRef,\n} from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport { NestedValue, UseFormReturn } from 'react-hook-form';\nimport useAsync from 'react-use/esm/useAsync';\nimport YAML from 'yaml';\nimport { AnalyzeResult, catalogImportApiRef } from '../../api';\nimport { useCatalogFilename } from '../../hooks';\nimport { PartialEntity } from '../../types';\nimport { BackButton, NextButton } from '../Buttons';\nimport { PrepareResult } from '../useImportState';\nimport { PreparePullRequestForm } from './PreparePullRequestForm';\nimport { PreviewCatalogInfoComponent } from './PreviewCatalogInfoComponent';\nimport { PreviewPullRequestComponent } from './PreviewPullRequestComponent';\n\nconst useStyles = makeStyles(theme => ({\n previewCard: {\n marginTop: theme.spacing(1),\n },\n previewCardContent: {\n paddingTop: 0,\n },\n}));\n\ntype FormData = {\n title: string;\n body: string;\n componentName: string;\n owner: string;\n useCodeowners: boolean;\n};\n\n/**\n * Helper for unpacking NestedValue into the underlying type.\n *\n * @public\n * @deprecated This is a copy of the type from react-hook-form, and will be removed in a future release\n */\nexport type UnpackNestedValue<T> = T extends NestedValue<infer U>\n ? U\n : T extends Date | FileList | File | Blob\n ? T\n : T extends object\n ? {\n [K in keyof T]: UnpackNestedValue<T[K]>;\n }\n : T;\n\n/**\n * Props for {@link StepPrepareCreatePullRequest}.\n *\n * @public\n */\nexport interface StepPrepareCreatePullRequestProps {\n analyzeResult: Extract<AnalyzeResult, { type: 'repository' }>;\n onPrepare: (\n result: PrepareResult,\n opts?: { notRepeatable?: boolean },\n ) => void;\n onGoBack?: () => void;\n\n renderFormFields: (\n props: Pick<\n UseFormReturn<FormData>,\n 'register' | 'setValue' | 'formState'\n > & {\n values: UnpackNestedValue<FormData>;\n groups: string[];\n groupsLoading: boolean;\n },\n ) => React.ReactNode;\n}\n\nexport function generateEntities(\n entities: PartialEntity[],\n componentName: string,\n owner?: string,\n): Entity[] {\n return entities.map(e => ({\n ...e,\n apiVersion: e.apiVersion!,\n kind: e.kind!,\n metadata: {\n ...e.metadata,\n name: componentName,\n },\n spec: {\n ...e.spec,\n ...(owner ? { owner } : {}),\n },\n }));\n}\n\n/**\n * Prepares a pull request.\n *\n * @public\n */\nexport const StepPrepareCreatePullRequest = (\n props: StepPrepareCreatePullRequestProps,\n) => {\n const { analyzeResult, onPrepare, onGoBack, renderFormFields } = props;\n\n const classes = useStyles();\n const catalogApi = useApi(catalogApiRef);\n const catalogImportApi = useApi(catalogImportApiRef);\n const errorApi = useApi(errorApiRef);\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string>();\n\n const catalogFilename = useCatalogFilename();\n\n const {\n loading: prDefaultsLoading,\n value: prDefaults,\n error: prDefaultsError,\n } = useAsync(\n () => catalogImportApi.preparePullRequest!(),\n [catalogImportApi.preparePullRequest],\n );\n\n useEffect(() => {\n if (prDefaultsError) {\n errorApi.post(prDefaultsError);\n }\n }, [prDefaultsError, errorApi]);\n\n const { loading: groupsLoading, value: groups } = useAsync(async () => {\n const groupEntities = await catalogApi.getEntities({\n filter: { kind: 'group' },\n });\n\n return groupEntities.items\n .map(e => humanizeEntityRef(e, { defaultKind: 'group' }))\n .sort();\n });\n\n const handleResult = useCallback(\n async (data: FormData) => {\n setSubmitted(true);\n\n try {\n const pr = await catalogImportApi.submitPullRequest({\n repositoryUrl: analyzeResult.url,\n title: data.title,\n body: data.body,\n fileContent: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n )\n .map(e => YAML.stringify(e))\n .join('---\\n'),\n });\n\n onPrepare(\n {\n type: 'repository',\n url: analyzeResult.url,\n integrationType: analyzeResult.integrationType,\n pullRequest: {\n url: pr.link,\n },\n locations: [\n {\n target: pr.location,\n entities: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n ).map(e => ({\n kind: e.kind,\n namespace: e.metadata.namespace!,\n name: e.metadata.name,\n })),\n },\n ],\n },\n { notRepeatable: true },\n );\n } catch (e) {\n assertError(e);\n setError(e.message);\n setSubmitted(false);\n }\n },\n [\n analyzeResult.generatedEntities,\n analyzeResult.integrationType,\n analyzeResult.url,\n catalogImportApi,\n onPrepare,\n ],\n );\n\n return (\n <>\n <Typography>\n You entered a link to a {analyzeResult.integrationType} repository but a{' '}\n <code>{catalogFilename}</code> could not be found. Use this form to open\n a Pull Request that creates one.\n </Typography>\n\n {!prDefaultsLoading && (\n <PreparePullRequestForm<FormData>\n onSubmit={handleResult}\n defaultValues={{\n title: prDefaults?.title ?? '',\n body: prDefaults?.body ?? '',\n owner:\n (analyzeResult.generatedEntities[0]?.spec?.owner as string) || '',\n componentName:\n analyzeResult.generatedEntities[0]?.metadata?.name || '',\n useCodeowners: false,\n }}\n render={({ values, formState, register, setValue }) => (\n <>\n {renderFormFields({\n values,\n formState,\n register,\n setValue,\n groups: groups ?? [],\n groupsLoading,\n })}\n\n <Box marginTop={2}>\n <Typography variant=\"h6\">Preview Pull Request</Typography>\n </Box>\n\n <PreviewPullRequestComponent\n title={values.title}\n description={values.body}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n <Box marginTop={2} marginBottom={1}>\n <Typography variant=\"h6\">Preview Entities</Typography>\n </Box>\n\n <PreviewCatalogInfoComponent\n entities={generateEntities(\n analyzeResult.generatedEntities,\n values.componentName,\n values.owner,\n )}\n repositoryUrl={analyzeResult.url}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n {onGoBack && (\n <BackButton onClick={onGoBack} disabled={submitted} />\n )}\n <NextButton\n type=\"submit\"\n disabled={Boolean(\n formState.errors.title ||\n formState.errors.body ||\n formState.errors.owner,\n )}\n loading={submitted}\n >\n Create PR\n </NextButton>\n </Grid>\n </>\n )}\n />\n )}\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,WAAa,EAAA;AAAA,IACX,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC;AAAA,GAC5B;AAAA,EACA,kBAAoB,EAAA;AAAA,IAClB,UAAY,EAAA;AAAA;AAEhB,CAAE,CAAA,CAAA;AAmDc,SAAA,gBAAA,CACd,QACA,EAAA,aAAA,EACA,KACU,EAAA;AACV,EAAO,OAAA,QAAA,CAAS,IAAI,CAAM,CAAA,MAAA;AAAA,IACxB,GAAG,CAAA;AAAA,IACH,YAAY,CAAE,CAAA,UAAA;AAAA,IACd,MAAM,CAAE,CAAA,IAAA;AAAA,IACR,QAAU,EAAA;AAAA,MACR,GAAG,CAAE,CAAA,QAAA;AAAA,MACL,IAAM,EAAA;AAAA,KACR;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,GAAG,CAAE,CAAA,IAAA;AAAA,MACL,GAAI,KAAA,GAAQ,EAAE,KAAA,KAAU;AAAC;AAC3B,GACA,CAAA,CAAA;AACJ;AAOa,MAAA,4BAAA,GAA+B,CAC1C,KACG,KAAA;AACH,EAAA,MAAM,EAAE,aAAA,EAAe,SAAW,EAAA,QAAA,EAAU,kBAAqB,GAAA,KAAA;AAEjE,EAAA,MAAM,UAAU,SAAU,EAAA;AAC1B,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAM,MAAA,gBAAA,GAAmB,OAAO,mBAAmB,CAAA;AACnD,EAAM,MAAA,QAAA,GAAW,OAAO,WAAW,CAAA;AAEnC,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA;AACh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5
  import { Entity, CompoundEntityRef } from '@backstage/catalog-model';
6
6
  import { InfoCardVariants } from '@backstage/core-components';
7
7
  import { TextFieldProps } from '@material-ui/core/TextField/TextField';
8
- import { FieldErrors, Controller, UseFormProps, SubmitHandler, UseFormReturn, UnpackNestedValue } from 'react-hook-form';
8
+ import { FieldErrors, Controller, UseFormProps, SubmitHandler, UseFormReturn, NestedValue } from 'react-hook-form';
9
9
  import { CatalogApi } from '@backstage/catalog-client';
10
10
  import { ScmIntegrationRegistry } from '@backstage/integration';
11
11
  import { ScmAuthApi } from '@backstage/integration-react';
@@ -426,6 +426,15 @@ type FormData = {
426
426
  owner: string;
427
427
  useCodeowners: boolean;
428
428
  };
429
+ /**
430
+ * Helper for unpacking NestedValue into the underlying type.
431
+ *
432
+ * @public
433
+ * @deprecated This is a copy of the type from react-hook-form, and will be removed in a future release
434
+ */
435
+ type UnpackNestedValue<T> = T extends NestedValue<infer U> ? U : T extends Date | FileList | File | Blob ? T : T extends object ? {
436
+ [K in keyof T]: UnpackNestedValue<T[K]>;
437
+ } : T;
429
438
  /**
430
439
  * Props for {@link StepPrepareCreatePullRequest}.
431
440
  *
@@ -452,4 +461,4 @@ interface StepPrepareCreatePullRequestProps {
452
461
  */
453
462
  declare const StepPrepareCreatePullRequest: (props: StepPrepareCreatePullRequestProps) => React__default.JSX.Element;
454
463
 
455
- export { type AnalyzeResult, AutocompleteTextField, type AutocompleteTextFieldProps, type CatalogImportApi, CatalogImportClient, CatalogImportPage, DefaultImportPage, EntityListComponent, type EntityListComponentProps, type ImportFlows, ImportInfoCard, type ImportInfoCardProps, type ImportState, ImportStepper, type ImportStepperProps, PreparePullRequestForm, type PreparePullRequestFormProps, type PrepareResult, PreviewCatalogInfoComponent, type PreviewCatalogInfoComponentProps, PreviewPullRequestComponent, type PreviewPullRequestComponentProps, StepInitAnalyzeUrl, type StepInitAnalyzeUrlProps, StepPrepareCreatePullRequest, type StepPrepareCreatePullRequestProps, catalogImportApiRef, catalogImportPlugin, defaultGenerateStepper, catalogImportPlugin as plugin };
464
+ export { type AnalyzeResult, AutocompleteTextField, type AutocompleteTextFieldProps, type CatalogImportApi, CatalogImportClient, CatalogImportPage, DefaultImportPage, EntityListComponent, type EntityListComponentProps, type ImportFlows, ImportInfoCard, type ImportInfoCardProps, type ImportState, ImportStepper, type ImportStepperProps, PreparePullRequestForm, type PreparePullRequestFormProps, type PrepareResult, PreviewCatalogInfoComponent, type PreviewCatalogInfoComponentProps, PreviewPullRequestComponent, type PreviewPullRequestComponentProps, StepInitAnalyzeUrl, type StepInitAnalyzeUrlProps, StepPrepareCreatePullRequest, type StepPrepareCreatePullRequestProps, type UnpackNestedValue, catalogImportApiRef, catalogImportPlugin, defaultGenerateStepper, catalogImportPlugin as plugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-import",
3
- "version": "0.12.12-next.0",
3
+ "version": "0.12.12",
4
4
  "description": "A Backstage plugin the helps you import entities into your catalog",
5
5
  "backstage": {
6
6
  "role": "frontend-plugin",
@@ -66,18 +66,18 @@
66
66
  "test": "backstage-cli package test"
67
67
  },
68
68
  "dependencies": {
69
- "@backstage/catalog-client": "1.9.1",
70
- "@backstage/catalog-model": "1.7.3",
71
- "@backstage/config": "1.3.2",
72
- "@backstage/core-compat-api": "0.4.1-next.0",
73
- "@backstage/core-components": "0.17.0",
74
- "@backstage/core-plugin-api": "1.10.5",
75
- "@backstage/errors": "1.2.7",
76
- "@backstage/frontend-plugin-api": "0.10.0",
77
- "@backstage/integration": "1.16.2",
78
- "@backstage/integration-react": "1.2.5",
79
- "@backstage/plugin-catalog-common": "1.1.3",
80
- "@backstage/plugin-catalog-react": "1.16.1-next.0",
69
+ "@backstage/catalog-client": "^1.9.1",
70
+ "@backstage/catalog-model": "^1.7.3",
71
+ "@backstage/config": "^1.3.2",
72
+ "@backstage/core-compat-api": "^0.4.0",
73
+ "@backstage/core-components": "^0.17.0",
74
+ "@backstage/core-plugin-api": "^1.10.5",
75
+ "@backstage/errors": "^1.2.7",
76
+ "@backstage/frontend-plugin-api": "^0.10.0",
77
+ "@backstage/integration": "^1.16.2",
78
+ "@backstage/integration-react": "^1.2.5",
79
+ "@backstage/plugin-catalog-common": "^1.1.3",
80
+ "@backstage/plugin-catalog-react": "^1.16.0",
81
81
  "@material-ui/core": "^4.12.2",
82
82
  "@material-ui/icons": "^4.9.1",
83
83
  "@material-ui/lab": "4.0.0-alpha.61",
@@ -90,11 +90,11 @@
90
90
  "yaml": "^2.0.0"
91
91
  },
92
92
  "devDependencies": {
93
- "@backstage/cli": "0.32.0-next.0",
94
- "@backstage/core-app-api": "1.16.0",
95
- "@backstage/dev-utils": "1.1.9-next.0",
96
- "@backstage/plugin-catalog": "1.29.0-next.0",
97
- "@backstage/test-utils": "1.7.6",
93
+ "@backstage/cli": "^0.31.1",
94
+ "@backstage/core-app-api": "^1.16.0",
95
+ "@backstage/dev-utils": "^1.1.8",
96
+ "@backstage/plugin-catalog": "^1.28.0",
97
+ "@backstage/test-utils": "^1.7.6",
98
98
  "@testing-library/dom": "^10.0.0",
99
99
  "@testing-library/jest-dom": "^6.0.0",
100
100
  "@testing-library/react": "^16.0.0",