@apimatic/cli 2.0.0-beta.3 → 2.0.0-beta.5

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.
Files changed (157) hide show
  1. package/README.md +18 -67
  2. package/apimatic.schema.json +2 -2
  3. package/lib/actions/action-result.d.ts +4 -2
  4. package/lib/actions/action-result.js +8 -3
  5. package/lib/actions/action-result.js.map +1 -1
  6. package/lib/actions/api/transform.d.ts +7 -6
  7. package/lib/actions/api/transform.js +12 -13
  8. package/lib/actions/api/transform.js.map +1 -1
  9. package/lib/actions/api/validate.d.ts +4 -5
  10. package/lib/actions/api/validate.js +30 -32
  11. package/lib/actions/api/validate.js.map +1 -1
  12. package/lib/actions/plugin/record-metadata.js +1 -1
  13. package/lib/actions/plugin/record-metadata.js.map +1 -1
  14. package/lib/actions/portal/generate.js +3 -3
  15. package/lib/actions/portal/generate.js.map +1 -1
  16. package/lib/actions/quickstart.d.ts +1 -9
  17. package/lib/actions/quickstart.js +122 -102
  18. package/lib/actions/quickstart.js.map +1 -1
  19. package/lib/commands/api/transform.d.ts +1 -1
  20. package/lib/commands/api/transform.js +2 -2
  21. package/lib/commands/api/transform.js.map +1 -1
  22. package/lib/commands/api/validate.d.ts +3 -3
  23. package/lib/commands/api/validate.js +28 -17
  24. package/lib/commands/api/validate.js.map +1 -1
  25. package/lib/commands/plugin/generate.d.ts +1 -1
  26. package/lib/commands/portal/generate.d.ts +2 -2
  27. package/lib/commands/portal/generate.js +1 -1
  28. package/lib/commands/portal/generate.js.map +1 -1
  29. package/lib/commands/portal/serve.d.ts +2 -2
  30. package/lib/commands/portal/serve.js +1 -1
  31. package/lib/commands/quickstart.d.ts +1 -1
  32. package/lib/commands/quickstart.js +1 -1
  33. package/lib/commands/quickstart.js.map +1 -1
  34. package/lib/commands/sdk/generate.d.ts +2 -2
  35. package/lib/commands/sdk/generate.js +4 -2
  36. package/lib/commands/sdk/generate.js.map +1 -1
  37. package/lib/infrastructure/file-service.d.ts +3 -0
  38. package/lib/infrastructure/file-service.js +24 -0
  39. package/lib/infrastructure/file-service.js.map +1 -1
  40. package/lib/infrastructure/portal-dev-server-service.js +2 -1
  41. package/lib/infrastructure/portal-dev-server-service.js.map +1 -1
  42. package/lib/infrastructure/portal-project-service.d.ts +1 -0
  43. package/lib/infrastructure/portal-project-service.js +7 -3
  44. package/lib/infrastructure/portal-project-service.js.map +1 -1
  45. package/lib/infrastructure/service-error.js +15 -15
  46. package/lib/infrastructure/service-error.js.map +1 -1
  47. package/lib/infrastructure/services/file-download-service.d.ts +4 -4
  48. package/lib/infrastructure/services/file-download-service.js +14 -14
  49. package/lib/infrastructure/services/file-download-service.js.map +1 -1
  50. package/lib/prompts/api/transform.d.ts +0 -2
  51. package/lib/prompts/api/transform.js +0 -3
  52. package/lib/prompts/api/transform.js.map +1 -1
  53. package/lib/prompts/api/validate.d.ts +2 -2
  54. package/lib/prompts/api/validate.js +35 -3
  55. package/lib/prompts/api/validate.js.map +1 -1
  56. package/lib/prompts/format.d.ts +1 -1
  57. package/lib/prompts/format.js.map +1 -1
  58. package/lib/prompts/plugin/record-metadata.d.ts +1 -1
  59. package/lib/prompts/plugin/record-metadata.js +2 -2
  60. package/lib/prompts/portal/generate.d.ts +2 -1
  61. package/lib/prompts/portal/generate.js +22 -6
  62. package/lib/prompts/portal/generate.js.map +1 -1
  63. package/lib/prompts/portal/prepare-project.js +5 -0
  64. package/lib/prompts/portal/prepare-project.js.map +1 -1
  65. package/lib/prompts/portal/serve.js +4 -3
  66. package/lib/prompts/portal/serve.js.map +1 -1
  67. package/lib/prompts/portal/source.d.ts +2 -5
  68. package/lib/prompts/portal/source.js +7 -17
  69. package/lib/prompts/portal/source.js.map +1 -1
  70. package/lib/prompts/publishing/links.d.ts +1 -1
  71. package/lib/prompts/publishing/links.js +1 -1
  72. package/lib/prompts/publishing/links.js.map +1 -1
  73. package/lib/prompts/quickstart.d.ts +14 -13
  74. package/lib/prompts/quickstart.js +44 -29
  75. package/lib/prompts/quickstart.js.map +1 -1
  76. package/lib/types/apimatic-config/document.d.ts +2 -0
  77. package/lib/types/apimatic-config/document.js +4 -0
  78. package/lib/types/apimatic-config/document.js.map +1 -1
  79. package/lib/types/apimatic-config-context.d.ts +1 -1
  80. package/lib/types/apimatic-config-context.js +1 -1
  81. package/lib/types/apimatic-config-context.js.map +1 -1
  82. package/lib/types/file/resource-input.d.ts +7 -5
  83. package/lib/types/file/resource-input.js +16 -15
  84. package/lib/types/file/resource-input.js.map +1 -1
  85. package/lib/types/flags-provider.d.ts +6 -1
  86. package/lib/types/flags-provider.js +22 -12
  87. package/lib/types/flags-provider.js.map +1 -1
  88. package/lib/types/plugin-config-context.d.ts +3 -0
  89. package/lib/types/plugin-config-context.js +33 -12
  90. package/lib/types/plugin-config-context.js.map +1 -1
  91. package/lib/types/portal/config/site-address.d.ts +16 -0
  92. package/lib/types/portal/config/site-address.js +67 -0
  93. package/lib/types/portal/config/site-address.js.map +1 -0
  94. package/lib/types/portal/config/site-config.d.ts +3 -5
  95. package/lib/types/portal/config/site-config.js +10 -33
  96. package/lib/types/portal/config/site-config.js.map +1 -1
  97. package/lib/types/portal/config/static-asset.d.ts +2 -2
  98. package/lib/types/portal/config/static-asset.js +2 -2
  99. package/lib/types/portal/config/static-asset.js.map +1 -1
  100. package/lib/types/portal/content-tree.d.ts +11 -4
  101. package/lib/types/portal/content-tree.js +19 -4
  102. package/lib/types/portal/content-tree.js.map +1 -1
  103. package/lib/types/portal/page.js +16 -1
  104. package/lib/types/portal/page.js.map +1 -1
  105. package/lib/types/portal/portal-config.d.ts +6 -3
  106. package/lib/types/portal/portal-config.js +8 -4
  107. package/lib/types/portal/portal-config.js.map +1 -1
  108. package/lib/types/portal/portal-languages.d.ts +2 -0
  109. package/lib/types/portal/portal-languages.js +5 -1
  110. package/lib/types/portal/portal-languages.js.map +1 -1
  111. package/lib/types/portal/portal-source.d.ts +9 -3
  112. package/lib/types/portal-source-context.d.ts +7 -8
  113. package/lib/types/portal-source-context.js +51 -26
  114. package/lib/types/portal-source-context.js.map +1 -1
  115. package/lib/types/project-context.d.ts +18 -0
  116. package/lib/types/project-context.js +18 -1
  117. package/lib/types/project-context.js.map +1 -1
  118. package/lib/types/resource-context.d.ts +25 -10
  119. package/lib/types/resource-context.js +40 -23
  120. package/lib/types/resource-context.js.map +1 -1
  121. package/lib/types/sdk/generate.d.ts +1 -4
  122. package/lib/types/sdk/generate.js +6 -6
  123. package/lib/types/sdk/generate.js.map +1 -1
  124. package/oclif.manifest.json +90 -72
  125. package/package.json +2 -2
  126. package/portal-template/dependency-directories.ts +45 -0
  127. package/portal-template/downloads.ts +6 -3
  128. package/portal-template/portal-config.ts +2 -0
  129. package/portal-template/prerender-pages.ts +8 -2
  130. package/portal-template/src/components/api-markdown.tsx +32 -0
  131. package/portal-template/src/components/api-page.tsx +8 -1
  132. package/portal-template/src/components/authorization-failure.tsx +63 -0
  133. package/portal-template/src/components/markdown-copy-button.tsx +60 -0
  134. package/portal-template/src/components/plugin-install.tsx +6 -5
  135. package/portal-template/src/components/sdk-actions.tsx +3 -2
  136. package/portal-template/src/components/sdk-cards.tsx +2 -1
  137. package/portal-template/src/components/search.tsx +9 -2
  138. package/portal-template/src/lib/base-path.ts +14 -0
  139. package/portal-template/src/lib/code-titles.ts +8 -0
  140. package/portal-template/src/lib/copy-markdown.ts +14 -0
  141. package/portal-template/src/lib/install-command.ts +5 -5
  142. package/portal-template/src/lib/layout.shared.tsx +5 -3
  143. package/portal-template/src/lib/llms.server.ts +29 -5
  144. package/portal-template/src/lib/oauth-callback.ts +63 -0
  145. package/portal-template/src/lib/portal-types.ts +3 -3
  146. package/portal-template/src/lib/rehype-code-titles.ts +3 -5
  147. package/portal-template/src/lib/remark-image-references.ts +35 -0
  148. package/portal-template/src/lib/search-content.ts +28 -0
  149. package/portal-template/src/lib/search-options.ts +7 -0
  150. package/portal-template/src/lib/source.server.ts +2 -0
  151. package/portal-template/src/router.tsx +3 -1
  152. package/portal-template/src/routes/$.tsx +6 -10
  153. package/portal-template/src/routes/__root.tsx +8 -1
  154. package/portal-template/src/routes/api/search[.]json.ts +23 -2
  155. package/portal-template/src/routes/oauth.callback.tsx +54 -0
  156. package/portal-template/static-functions-base.ts +41 -0
  157. package/portal-template/vite.config.ts +22 -2
@@ -0,0 +1,54 @@
1
+ import { createFileRoute } from '@tanstack/react-router';
2
+ import { HomeLayout } from 'fumadocs-ui/layouts/home';
3
+ import { useEffect, useState } from 'react';
4
+ import { AuthorizationFailure } from '@/components/authorization-failure';
5
+ import { baseOptions } from '@/lib/layout.shared';
6
+ import { forgetStartingPage, oauthCallback, type OAuthCallback, type OAuthCallbackFailure } from '@/lib/oauth-callback';
7
+ import { portal } from '@/lib/portal';
8
+
9
+ // Published portals are static, so this page does in the browser what Fumadocs'
10
+ // `createOAuthHandler()` route does on a server.
11
+ export const Route = createFileRoute('/oauth/callback')({
12
+ head: () => ({ meta: [{ title: `Authorization | ${portal.name}` }, { name: 'robots', content: 'noindex' }] }),
13
+ component: OAuthCallbackPage
14
+ });
15
+
16
+ let completion: OAuthCallback | undefined;
17
+
18
+ /**
19
+ * Reading the cookie and sending the browser on can each happen only once per page load, not
20
+ * once per mount: the StrictMode `portal serve` runs under mounts the page twice, and the second
21
+ * mount would find the cookie gone. The answer is kept, so a later mount in the same load, such
22
+ * as Back after leaving through the header, shows the same outcome. Every arrival from a provider
23
+ * is a new load.
24
+ */
25
+ function completeAuthorization(): OAuthCallback {
26
+ if (completion === undefined) {
27
+ completion = oauthCallback(document.cookie, window.location);
28
+ forgetStartingPage();
29
+ if (completion.kind === 'return') window.location.replace(completion.url);
30
+ }
31
+ return completion;
32
+ }
33
+
34
+ function OAuthCallbackPage() {
35
+ // Null until the effect has read the cookie, which the prerendered page cannot.
36
+ const [failure, setFailure] = useState<OAuthCallbackFailure | null>(null);
37
+
38
+ useEffect(() => {
39
+ const callback = completeAuthorization();
40
+ if (callback.kind !== 'return') setFailure(callback);
41
+ }, []);
42
+
43
+ return (
44
+ <HomeLayout {...baseOptions()}>
45
+ <div className="flex flex-col px-8 justify-center flex-1 text-center items-center gap-4">
46
+ {failure === null ? (
47
+ <p className="text-fd-muted-foreground">Completing authorization…</p>
48
+ ) : (
49
+ <AuthorizationFailure failure={failure} />
50
+ )}
51
+ </div>
52
+ </HomeLayout>
53
+ );
54
+ }
@@ -0,0 +1,41 @@
1
+ import type { Plugin } from 'vite';
2
+ import { withBasePath } from './src/lib/base-path';
3
+
4
+ /** The package whose browser half fetches a prerendered server function's result. */
5
+ const PACKAGE = /[\\/]@tanstack[\\/]start-static-server-functions[\\/]/;
6
+
7
+ /** Where it fetches that result from, opening backtick included so nothing else naming the folder matches. */
8
+ export const CACHE_ADDRESS = '`/__tsr/staticServerFnCache/';
9
+
10
+ /** Puts the browser's fetch of prerendered page data under the base, until TanStack/router#6152 does it itself. */
11
+ export function staticFunctionsBase(): Plugin {
12
+ let base = '/';
13
+ let found = false;
14
+ return {
15
+ name: 'apimatic:static-functions-base',
16
+ apply: 'build',
17
+ enforce: 'pre',
18
+ // The server writes the files under the output directory, which the host already serves at the base.
19
+ applyToEnvironment: (environment) => environment.name === 'client',
20
+ configResolved(config) {
21
+ base = config.base;
22
+ },
23
+ transform: {
24
+ filter: { id: PACKAGE, code: CACHE_ADDRESS },
25
+ handler(code) {
26
+ // Found at the root too, where the replacement is the address itself.
27
+ found = true;
28
+ return code.replaceAll(CACHE_ADDRESS, '`' + withBasePath(CACHE_ADDRESS.slice(1), base));
29
+ }
30
+ },
31
+ // An upgrade that moves the address fails the build, rather than every link in the portal.
32
+ buildEnd(error) {
33
+ if (error === undefined && !found) {
34
+ this.error(
35
+ `No module of @tanstack/start-static-server-functions holds ${CACHE_ADDRESS}, so a portal ` +
36
+ 'served under a path could not load the pages its links lead to. See portal-template/static-functions-base.ts.'
37
+ );
38
+ }
39
+ }
40
+ };
41
+ }
@@ -1,29 +1,40 @@
1
1
  import { fileURLToPath } from 'node:url';
2
2
  import react from '@vitejs/plugin-react';
3
3
  import { tanstackStart } from '@tanstack/react-start/plugin/vite';
4
- import { defineConfig } from 'vite';
4
+ import { defineConfig, searchForWorkspaceRoot } from 'vite';
5
5
  import tailwindcss from '@tailwindcss/vite';
6
6
  import { fumadocsMdx } from 'fumadocs-mdx/vite';
7
+ import { dependencyDirectories } from './dependency-directories.ts';
7
8
  import { downloads } from './downloads.ts';
8
9
  import { generatedPagesReload } from './generated-pages-reload.ts';
9
10
  import { readBuildPaths, readPortalIdentity } from './portal-config.ts';
10
11
  import { prerenderPages } from './prerender-pages.ts';
11
12
  import { specReload } from './spec-reload.ts';
13
+ import { remarkImageReferences } from './src/lib/remark-image-references.ts';
14
+ import { staticFunctionsBase } from './static-functions-base.ts';
12
15
 
13
16
  export default defineConfig(async () => {
14
17
  const [paths, identity] = await Promise.all([readBuildPaths(), readPortalIdentity()]);
15
18
  const pages = await prerenderPages(paths, identity.siteUrl);
16
19
  const publicDir: string | false = paths.staticDir ?? false;
20
+ const portalProjectDirectory = fileURLToPath(new URL('.', import.meta.url));
17
21
 
18
22
  return {
23
+ // TanStack Start derives the router's basepath and every asset URL from it.
24
+ base: paths.base,
19
25
  publicDir,
20
26
  plugins: [
21
27
  generatedPagesReload(),
22
28
  downloads(paths.downloadsDir),
29
+ staticFunctionsBase(),
23
30
  // `/images/logo.png` is read from the static directory, and a remote image is never fetched for its size.
24
31
  fumadocsMdx({
25
32
  globalOptions: {
26
- mdxOptions: { remarkImageOptions: { publicDir: publicDir || undefined, external: false } }
33
+ mdxOptions: {
34
+ remarkImageOptions: { publicDir: publicDir || undefined, external: false },
35
+ // A function, so it runs ahead of the preset's own plugins, `remarkImage` among them.
36
+ remarkPlugins: (plugins) => [remarkImageReferences, ...plugins]
37
+ }
27
38
  }
28
39
  }),
29
40
  specReload(paths.specs),
@@ -55,6 +66,15 @@ export default defineConfig(async () => {
55
66
  // listens on `::1` alone, a connect that stalls under load falls back to 127.0.0.1 and is
56
67
  // refused, failing the build; binding IPv4 leaves the fetch a single address to reach.
57
68
  preview: { host: '127.0.0.1' },
69
+ server: {
70
+ fs: {
71
+ allow: [
72
+ searchForWorkspaceRoot(portalProjectDirectory),
73
+ ...dependencyDirectories(portalProjectDirectory),
74
+ ...(paths.staticDir === null ? [] : [paths.staticDir])
75
+ ]
76
+ }
77
+ },
58
78
  resolve: {
59
79
  tsconfigPaths: true,
60
80
  alias: [