@payloadcms/figma 0.1.0-alpha.0 → 0.1.0-alpha.10
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/LICENSE.md +1 -1
- package/dist/{utils → adapters}/asset-collection.d.ts +17 -3
- package/dist/adapters/asset-collection.js +242 -0
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +8 -7
- package/dist/adapters/build-lambda-zip.js +111 -0
- package/dist/adapters/configureNextjsCache.d.ts +8 -0
- package/dist/adapters/configureNextjsCache.js +55 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +1 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +15 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.d.ts +12 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.js +28 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.d.ts +9 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.js +13 -0
- package/dist/adapters/deploy-output/isFile.d.ts +1 -0
- package/dist/adapters/deploy-output/isFile.js +4 -0
- package/dist/adapters/deploy-output/readJson.d.ts +1 -0
- package/dist/adapters/deploy-output/readJson.js +9 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.d.ts +8 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.js +16 -0
- package/dist/adapters/deploy-output/resolveOutputPath.d.ts +2 -0
- package/dist/adapters/deploy-output/resolveOutputPath.js +9 -0
- package/dist/adapters/deploy-output/resolveWithin.d.ts +1 -0
- package/dist/adapters/deploy-output/resolveWithin.js +12 -0
- package/dist/adapters/fs-utils.d.ts +39 -0
- package/dist/adapters/fs-utils.js +135 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
- package/dist/adapters/nextjs.d.ts +12 -0
- package/dist/adapters/nextjs.js +67 -0
- package/dist/adapters/nitro.d.ts +8 -0
- package/dist/adapters/nitro.js +193 -0
- package/dist/adapters/secret-files.d.ts +25 -0
- package/dist/adapters/secret-files.js +50 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.js +1 -0
- package/dist/{utils/adapters → adapters}/vite.d.ts +2 -2
- package/dist/adapters/vite.js +33 -0
- package/dist/api/check-project-subdomain-availability.d.ts +12 -0
- package/dist/api/check-project-subdomain-availability.js +32 -0
- package/dist/api/control-plane-error.d.ts +6 -0
- package/dist/api/control-plane-error.js +8 -0
- package/dist/api/control-plane-fetch.d.ts +7 -0
- package/dist/api/control-plane-fetch.js +37 -0
- package/dist/api/control-plane.d.ts +1 -9
- package/dist/api/control-plane.js +2 -48
- package/dist/api/create-project.d.ts +18 -0
- package/dist/api/create-project.js +37 -0
- package/dist/api/list-project-workspaces.d.ts +8 -0
- package/dist/api/list-project-workspaces.js +28 -0
- package/dist/api/project-resource-type.d.ts +1 -0
- package/dist/api/project-resource-type.js +1 -0
- package/dist/auth/headless-oauth-flow.d.ts +23 -0
- package/dist/auth/headless-oauth-flow.js +69 -0
- package/dist/auth/oauth-flow.d.ts +2 -0
- package/dist/auth/oauth-flow.js +13 -8
- package/dist/auth/token-store.d.ts +4 -1
- package/dist/auth/token-store.js +14 -0
- package/dist/auth/types.d.ts +12 -0
- package/dist/cli.d.ts +39 -0
- package/dist/cli.js +71 -36
- package/dist/commands/bootstrap.js +2 -1
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.d.ts +12 -0
- package/dist/commands/deploy.js +63 -25
- package/dist/commands/detect-project-resource-type.d.ts +3 -0
- package/dist/commands/detect-project-resource-type.js +28 -0
- package/dist/commands/init.d.ts +2 -2
- package/dist/commands/init.js +164 -79
- package/dist/commands/login.d.ts +11 -1
- package/dist/commands/login.js +66 -4
- package/dist/commands/prompt-to-create-project/format-project-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-project-subdomain.js +3 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.js +7 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.js +13 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.d.ts +7 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.js +32 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.d.ts +8 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.js +27 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.js +54 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.js +23 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.d.ts +12 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.js +36 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.js +9 -0
- package/dist/commands/prompt-to-create-project.d.ts +24 -0
- package/dist/commands/prompt-to-create-project.js +69 -0
- package/dist/commands/setup-agent.d.ts +12 -0
- package/dist/commands/setup-agent.js +123 -0
- package/dist/commands/write-project-configuration.d.ts +12 -0
- package/dist/commands/write-project-configuration.js +16 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +661 -16
- package/dist/db-content-api/index.d.ts +3 -0
- package/dist/db-content-api/index.js +155 -161
- package/dist/db-content-api/utilities/clientVersionHeaders.d.ts +7 -0
- package/dist/db-content-api/utilities/clientVersionHeaders.js +15 -0
- package/dist/db-content-api/utilities/data/atomicOperations.d.ts +16 -0
- package/dist/db-content-api/utilities/data/atomicOperations.js +48 -0
- package/dist/db-content-api/utilities/data/convertRelationshipIds.d.ts +25 -0
- package/dist/db-content-api/utilities/data/convertRelationshipIds.js +109 -0
- package/dist/db-content-api/utilities/data/index.js +73 -57
- package/dist/db-content-api/utilities/data/injectGlobalType.d.ts +6 -0
- package/dist/db-content-api/utilities/data/injectGlobalType.js +11 -0
- package/dist/db-content-api/utilities/data/isLocaleMap.d.ts +10 -0
- package/dist/db-content-api/utilities/data/isLocaleMap.js +13 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- package/dist/db-content-api/utilities/data/resolveFieldLocalization.d.ts +18 -0
- package/dist/db-content-api/utilities/data/resolveFieldLocalization.js +21 -0
- package/dist/db-content-api/utilities/data/validateRelationships.js +19 -12
- package/dist/db-content-api/utilities/isRecord.d.ts +9 -0
- package/dist/db-content-api/utilities/isRecord.js +19 -0
- package/dist/db-content-api/utilities/joins.d.ts +6 -8
- package/dist/db-content-api/utilities/joins.js +13 -22
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.js +95 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.d.ts +9 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.js +112 -0
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.d.ts +21 -4
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +118 -36
- package/dist/db-content-api/utilities/schema/getDocumentSchema.d.ts +3 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.js +24 -0
- package/dist/db-content-api/utilities/where.d.ts +3 -17
- package/dist/db-content-api/utilities/where.js +21 -21
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +2 -0
- package/dist/exports/views.d.ts +1 -0
- package/dist/exports/views.js +1 -0
- package/dist/imageSizeOptions.d.ts +23 -0
- package/dist/imageSizeOptions.js +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/write-agent-config.d.ts +12 -0
- package/dist/lib/write-agent-config.js +52 -0
- package/dist/next/image-loader.d.ts +6 -0
- package/dist/next/image-loader.js +14 -0
- package/dist/oauth/components/LoginButton/index.js +66 -19
- package/dist/oauth/components/LoginButton/index.scss +121 -15
- package/dist/oauth/defaults.js +4 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +5 -2
- package/dist/oauth/index.js +8 -7
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +1 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +5 -1
- package/dist/plugin/build-config.d.ts +4 -2
- package/dist/plugin/build-config.js +95 -31
- package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
- package/dist/plugin/cache-revalidation-hooks.js +69 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +8 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.js +66 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.scss +56 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.js +110 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.css +14 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.js +52 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.d.ts +7 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.js +3 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.d.ts +1 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.js +27 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.js +30 -0
- package/dist/plugin/cloud-limits/routes.d.ts +2 -0
- package/dist/plugin/cloud-limits/routes.js +4 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.d.ts +9 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.js +28 -0
- package/dist/plugin/cloud-limits/shared.d.ts +10 -0
- package/dist/plugin/cloud-limits/shared.js +52 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.d.ts +2 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.js +134 -0
- package/dist/plugin/cloud-limits/utilities/toasts.d.ts +4 -0
- package/dist/plugin/cloud-limits/utilities/toasts.js +19 -0
- package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
- package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
- package/dist/plugin/sandbox-upload-fetch.d.ts +32 -0
- package/dist/plugin/sandbox-upload-fetch.js +53 -0
- package/dist/skills/deploy-to-figma/SKILL.md +234 -0
- package/dist/skills/deploy-to-figma/references/cli-reference.md +146 -0
- package/dist/storage-content-api/client-uploads/generate.js +2 -1
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +27 -0
- package/dist/storage-content-api/index.js +1 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/staticHandler.js +2 -1
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/translations/ar.d.ts +12 -0
- package/dist/translations/ar.js +12 -0
- package/dist/translations/az.d.ts +12 -0
- package/dist/translations/az.js +12 -0
- package/dist/translations/bg.d.ts +12 -0
- package/dist/translations/bg.js +12 -0
- package/dist/translations/bnBd.d.ts +12 -0
- package/dist/translations/bnBd.js +12 -0
- package/dist/translations/bnIn.d.ts +12 -0
- package/dist/translations/bnIn.js +12 -0
- package/dist/translations/ca.d.ts +12 -0
- package/dist/translations/ca.js +12 -0
- package/dist/translations/cs.d.ts +12 -0
- package/dist/translations/cs.js +12 -0
- package/dist/translations/da.d.ts +12 -0
- package/dist/translations/da.js +12 -0
- package/dist/translations/de.d.ts +12 -0
- package/dist/translations/de.js +12 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/translations/en.js +12 -0
- package/dist/translations/es.d.ts +12 -0
- package/dist/translations/es.js +12 -0
- package/dist/translations/et.d.ts +12 -0
- package/dist/translations/et.js +12 -0
- package/dist/translations/fa.d.ts +12 -0
- package/dist/translations/fa.js +12 -0
- package/dist/translations/fr.d.ts +12 -0
- package/dist/translations/fr.js +12 -0
- package/dist/translations/he.d.ts +12 -0
- package/dist/translations/he.js +12 -0
- package/dist/translations/hr.d.ts +12 -0
- package/dist/translations/hr.js +12 -0
- package/dist/translations/hu.d.ts +12 -0
- package/dist/translations/hu.js +12 -0
- package/dist/translations/hy.d.ts +12 -0
- package/dist/translations/hy.js +12 -0
- package/dist/translations/id.d.ts +12 -0
- package/dist/translations/id.js +12 -0
- package/dist/translations/index.d.ts +533 -0
- package/dist/translations/index.js +90 -0
- package/dist/translations/is.d.ts +12 -0
- package/dist/translations/is.js +12 -0
- package/dist/translations/it.d.ts +12 -0
- package/dist/translations/it.js +12 -0
- package/dist/translations/ja.d.ts +12 -0
- package/dist/translations/ja.js +12 -0
- package/dist/translations/ko.d.ts +12 -0
- package/dist/translations/ko.js +12 -0
- package/dist/translations/lt.d.ts +12 -0
- package/dist/translations/lt.js +12 -0
- package/dist/translations/lv.d.ts +12 -0
- package/dist/translations/lv.js +12 -0
- package/dist/translations/my.d.ts +12 -0
- package/dist/translations/my.js +12 -0
- package/dist/translations/nb.d.ts +12 -0
- package/dist/translations/nb.js +12 -0
- package/dist/translations/nl.d.ts +12 -0
- package/dist/translations/nl.js +12 -0
- package/dist/translations/pl.d.ts +12 -0
- package/dist/translations/pl.js +12 -0
- package/dist/translations/pt.d.ts +12 -0
- package/dist/translations/pt.js +12 -0
- package/dist/translations/ro.d.ts +12 -0
- package/dist/translations/ro.js +12 -0
- package/dist/translations/rs.d.ts +12 -0
- package/dist/translations/rs.js +12 -0
- package/dist/translations/rsLatin.d.ts +12 -0
- package/dist/translations/rsLatin.js +12 -0
- package/dist/translations/ru.d.ts +12 -0
- package/dist/translations/ru.js +12 -0
- package/dist/translations/sk.d.ts +12 -0
- package/dist/translations/sk.js +12 -0
- package/dist/translations/sl.d.ts +12 -0
- package/dist/translations/sl.js +12 -0
- package/dist/translations/sv.d.ts +12 -0
- package/dist/translations/sv.js +12 -0
- package/dist/translations/ta.d.ts +12 -0
- package/dist/translations/ta.js +12 -0
- package/dist/translations/th.d.ts +12 -0
- package/dist/translations/th.js +12 -0
- package/dist/translations/tr.d.ts +12 -0
- package/dist/translations/tr.js +12 -0
- package/dist/translations/uk.d.ts +12 -0
- package/dist/translations/uk.js +12 -0
- package/dist/translations/vi.d.ts +12 -0
- package/dist/translations/vi.js +12 -0
- package/dist/translations/zh.d.ts +12 -0
- package/dist/translations/zh.js +12 -0
- package/dist/translations/zhTw.d.ts +12 -0
- package/dist/translations/zhTw.js +12 -0
- package/dist/types.d.ts +11 -0
- package/dist/utils/assert-never.d.ts +1 -0
- package/dist/utils/assert-never.js +3 -0
- package/dist/utils/build-detection.d.ts +6 -1
- package/dist/utils/build-detection.js +68 -89
- package/dist/utils/deploy-adapter.d.ts +3 -35
- package/dist/utils/deploy-adapter.js +25 -14
- package/dist/utils/lambda-config.js +18 -23
- package/dist/utils/load-payload-config.d.ts +2 -2
- package/dist/utils/messages.js +24 -3
- package/dist/utils/next-image-loader-config.d.ts +2 -0
- package/dist/utils/next-image-loader-config.js +63 -0
- package/dist/utils/next-image-loader-file.d.ts +2 -0
- package/dist/utils/next-image-loader-file.js +11 -0
- package/dist/utils/payload-generate.d.ts +10 -0
- package/dist/utils/payload-generate.js +59 -0
- package/dist/utils/pnpm-builds.d.ts +14 -0
- package/dist/utils/pnpm-builds.js +125 -0
- package/dist/utils/s3-upload.js +4 -1
- package/package.json +31 -7
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +0 -10
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +0 -71
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +0 -41
- package/dist/db-content-api/utilities/meta/buildMeta.js +0 -39
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +0 -16
- package/dist/db-content-api/utilities/meta/buildPathTypes.js +0 -243
- package/dist/db-content-api/utilities/meta/buildUniquePaths.d.ts +0 -12
- package/dist/db-content-api/utilities/meta/buildUniquePaths.js +0 -60
- package/dist/lib/download-skill.d.ts +0 -12
- package/dist/lib/download-skill.js +0 -77
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -61
- package/dist/utils/adapters/nitro.d.ts +0 -8
- package/dist/utils/adapters/nitro.js +0 -172
- package/dist/utils/adapters/vite.js +0 -31
- package/dist/utils/asset-collection.js +0 -144
- package/dist/utils/build-lambda-zip.js +0 -90
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import archiver from 'archiver';
|
|
2
|
+
import { createWriteStream } from 'fs';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { resolveNitroOutputLayout } from './deploy-output/resolveNitroOutputLayout.js';
|
|
6
|
+
import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
|
|
7
|
+
import { collectFilesRecursive, EscapingSymlinkError, walkBundleFiles } from './fs-utils.js';
|
|
8
|
+
import { isBundlableFile, isPublishableAsset } from './secret-files.js';
|
|
9
|
+
/** Framework asset directories that are not pre-rendered pages. */ const NON_PAGE_DIRS = new Set([
|
|
10
|
+
'_build',
|
|
11
|
+
'_nuxt',
|
|
12
|
+
'assets'
|
|
13
|
+
]);
|
|
14
|
+
export class NitroAdapter {
|
|
15
|
+
name = 'nitro';
|
|
16
|
+
async collectAssets(projectPath, output) {
|
|
17
|
+
const { publicPath } = await getLayout(projectPath, output);
|
|
18
|
+
const pageKeys = new Set((await scanForPages(publicPath, publicPath)).map(toPageUploadKey));
|
|
19
|
+
const assets = (await collectFilesRecursive(publicPath, publicPath)).filter((file)=>!pageKeys.has(file) && isPublishableAsset(file));
|
|
20
|
+
const pathMap = Object.fromEntries(assets.map((file)=>[
|
|
21
|
+
file,
|
|
22
|
+
path.relative(projectPath, path.join(publicPath, file))
|
|
23
|
+
]));
|
|
24
|
+
return {
|
|
25
|
+
pathMap,
|
|
26
|
+
routes: assets.map((k)=>`/${k}`),
|
|
27
|
+
uploadKeys: assets
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async collectPages(projectPath, output) {
|
|
31
|
+
const { publicPath } = await getLayout(projectPath, output);
|
|
32
|
+
const pages = (await scanForPages(publicPath, publicPath)).filter((page)=>isPublishableAsset(toPageUploadKey(page)));
|
|
33
|
+
const routes = pages.map((p)=>p === 'index' ? '/' : `/${p}`);
|
|
34
|
+
const uploadKeys = pages.map(toPageUploadKey);
|
|
35
|
+
const pathMap = {};
|
|
36
|
+
const routeAssetMap = {};
|
|
37
|
+
for(let i = 0; i < uploadKeys.length; i++){
|
|
38
|
+
pathMap[uploadKeys[i]] = path.relative(projectPath, path.join(publicPath, uploadKeys[i]));
|
|
39
|
+
routeAssetMap[routes[i]] = [
|
|
40
|
+
uploadKeys[i]
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
pathMap,
|
|
45
|
+
routeAssetMap,
|
|
46
|
+
routes,
|
|
47
|
+
uploadKeys
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async prepareLambdaBundle(projectPath, output, options = {}) {
|
|
51
|
+
const layout = await getLayout(projectPath, output);
|
|
52
|
+
try {
|
|
53
|
+
const stat = await fs.stat(layout.serverEntryPath);
|
|
54
|
+
if (!stat.isFile()) {
|
|
55
|
+
throw new Error('not a file');
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
throw new Error(`Nitro server build not found at ${layout.outputPath}`);
|
|
59
|
+
}
|
|
60
|
+
const serverDir = path.dirname(layout.serverEntryPath);
|
|
61
|
+
const serverPrefix = zipPrefix(path.relative(layout.outputPath, serverDir).split(path.sep).join('/'));
|
|
62
|
+
const publicPrefix = zipPrefix(path.relative(layout.outputPath, layout.publicPath).split(path.sep).join('/'));
|
|
63
|
+
const serverEntry = path.relative(layout.outputPath, layout.serverEntryPath).split(path.sep).join('/');
|
|
64
|
+
const runShPath = path.join(layout.outputPath, 'run.sh');
|
|
65
|
+
await fs.writeFile(runShPath, createRunScript(serverEntry), {
|
|
66
|
+
mode: 0o755
|
|
67
|
+
});
|
|
68
|
+
const artifactDir = options.artifactDir ?? projectPath;
|
|
69
|
+
await fs.mkdir(artifactDir, {
|
|
70
|
+
recursive: true
|
|
71
|
+
});
|
|
72
|
+
const zipPath = path.join(artifactDir, 'lambda.zip');
|
|
73
|
+
try {
|
|
74
|
+
const runShStat = await fs.stat(runShPath);
|
|
75
|
+
const [allServerFiles, publicFiles] = await Promise.all([
|
|
76
|
+
walkBundleFiles(serverDir),
|
|
77
|
+
walkPublicBundleFiles(layout.publicPath)
|
|
78
|
+
]);
|
|
79
|
+
const bundlableServerFiles = allServerFiles.filter((file)=>isBundlableFile(file.relativePath));
|
|
80
|
+
const unzippedBytes = bundlableServerFiles.reduce((total, file)=>total + file.size, 0) + publicFiles.reduce((total, file)=>total + file.size, 0) + runShStat.size;
|
|
81
|
+
await createZip(zipPath, [
|
|
82
|
+
{
|
|
83
|
+
files: bundlableServerFiles,
|
|
84
|
+
prefix: serverPrefix
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
files: publicFiles,
|
|
88
|
+
prefix: publicPrefix
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
files: [
|
|
92
|
+
{
|
|
93
|
+
relativePath: 'run.sh',
|
|
94
|
+
size: runShStat.size,
|
|
95
|
+
sourcePath: runShPath
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
prefix: ''
|
|
99
|
+
}
|
|
100
|
+
]);
|
|
101
|
+
return {
|
|
102
|
+
unzippedBytes,
|
|
103
|
+
zipPath
|
|
104
|
+
};
|
|
105
|
+
} finally{
|
|
106
|
+
await fs.rm(runShPath, {
|
|
107
|
+
force: true
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export const nitroAdapter = new NitroAdapter();
|
|
113
|
+
function getLayout(projectPath, output) {
|
|
114
|
+
const outputPath = resolveOutputPath(projectPath, 'nitro', output);
|
|
115
|
+
return resolveNitroOutputLayout(outputPath);
|
|
116
|
+
}
|
|
117
|
+
function createRunScript(serverEntry) {
|
|
118
|
+
const escapedEntry = serverEntry.replaceAll("'", "'\\''");
|
|
119
|
+
return `#!/bin/bash -x
|
|
120
|
+
[ ! -d '/tmp/cache' ] && mkdir -p /tmp/cache
|
|
121
|
+
NODE_ENV=production exec node '${escapedEntry}'
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Recursively scan for pre-rendered pages (directories containing index.html).
|
|
126
|
+
* Skips known framework asset directories.
|
|
127
|
+
*/ async function scanForPages(dir, baseDir) {
|
|
128
|
+
const pages = [];
|
|
129
|
+
// Check if this directory has an index.html (it's a page)
|
|
130
|
+
const indexPath = path.join(dir, 'index.html');
|
|
131
|
+
try {
|
|
132
|
+
await fs.stat(indexPath);
|
|
133
|
+
const relative = path.relative(baseDir, dir);
|
|
134
|
+
pages.push(relative || 'index'); // root dir -> 'index'
|
|
135
|
+
} catch {
|
|
136
|
+
// Not a page directory
|
|
137
|
+
}
|
|
138
|
+
// Recurse into subdirectories
|
|
139
|
+
try {
|
|
140
|
+
const entries = await fs.readdir(dir, {
|
|
141
|
+
withFileTypes: true
|
|
142
|
+
});
|
|
143
|
+
for (const entry of entries){
|
|
144
|
+
if (entry.isDirectory() && !NON_PAGE_DIRS.has(entry.name)) {
|
|
145
|
+
const subPages = await scanForPages(path.join(dir, entry.name), baseDir);
|
|
146
|
+
pages.push(...subPages);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} catch {
|
|
150
|
+
// Directory not readable
|
|
151
|
+
}
|
|
152
|
+
return pages;
|
|
153
|
+
}
|
|
154
|
+
function zipPrefix(relativeDir) {
|
|
155
|
+
return relativeDir ? `${relativeDir}/` : '';
|
|
156
|
+
}
|
|
157
|
+
function toPageUploadKey(page) {
|
|
158
|
+
return page === 'index' ? 'index.html' : `${page}/index.html`;
|
|
159
|
+
}
|
|
160
|
+
async function walkPublicBundleFiles(publicPath) {
|
|
161
|
+
try {
|
|
162
|
+
// The Nitro server serves this tree statically, so secrets copied into the
|
|
163
|
+
// public directory must not reach the Lambda bundle either.
|
|
164
|
+
const files = await walkBundleFiles(publicPath);
|
|
165
|
+
return files.filter((file)=>isPublishableAsset(file.relativePath));
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (error instanceof EscapingSymlinkError) {
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function createZip(zipPath, entries) {
|
|
174
|
+
return new Promise((resolve, reject)=>{
|
|
175
|
+
const output = createWriteStream(zipPath);
|
|
176
|
+
const archive = archiver('zip', {
|
|
177
|
+
zlib: {
|
|
178
|
+
level: 9
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
output.on('close', ()=>resolve());
|
|
182
|
+
archive.on('error', (err)=>reject(err));
|
|
183
|
+
archive.pipe(output);
|
|
184
|
+
for (const entry of entries){
|
|
185
|
+
for (const file of entry.files){
|
|
186
|
+
archive.file(file.sourcePath, {
|
|
187
|
+
name: entry.prefix + file.relativePath
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
void archive.finalize();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when a forward-slash asset key holds no secret or private-history path
|
|
3
|
+
* segment.
|
|
4
|
+
*
|
|
5
|
+
* A deploy can point `--output` at a directory that also holds those files (a
|
|
6
|
+
* buildless static root, or a framework output folder that copied them in).
|
|
7
|
+
* Every collected asset becomes a publicly reachable route, so `node_modules`
|
|
8
|
+
* is excluded here too.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isPublishableAsset(key: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* True when a forward-slash bundle path belongs in a Lambda zip.
|
|
13
|
+
*
|
|
14
|
+
* A server bundle needs its `node_modules`, but never the project's `.env`
|
|
15
|
+
* files or credentials: a deployed function reads its configuration from
|
|
16
|
+
* deploy environment variables, and a packed secret only widens the blast
|
|
17
|
+
* radius of any later path that serves bundle files. `.env.production` is the
|
|
18
|
+
* deliberate exception, an escape hatch for configuration too large for the
|
|
19
|
+
* Lambda environment-variable limit.
|
|
20
|
+
*
|
|
21
|
+
* Paths inside `node_modules` are kept as-is. A dependency's own dotfiles are
|
|
22
|
+
* not the developer's secrets, and removing files a package may read at
|
|
23
|
+
* runtime would break the bundle.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isBundlableFile(relativePath: string): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local secrets and private history that must never leave the developer's
|
|
3
|
+
* machine: environment files, git history, and credential files.
|
|
4
|
+
*/ const SECRET_NAMES = new Set([
|
|
5
|
+
'.git',
|
|
6
|
+
'.netrc',
|
|
7
|
+
'.npmrc',
|
|
8
|
+
'.ssh'
|
|
9
|
+
]);
|
|
10
|
+
/** Installed dependencies: private for static hosting, required by a server bundle. */ const DEPENDENCY_DIR = 'node_modules';
|
|
11
|
+
/**
|
|
12
|
+
* The one environment file a Lambda zip may carry. AWS caps a function's
|
|
13
|
+
* environment variables at 4 KB total, so a project with more configuration
|
|
14
|
+
* than that has no way to pass it except inside the bundle. It is still never
|
|
15
|
+
* publishable: `isPublishableAsset` rejects it like any other `.env` file.
|
|
16
|
+
*/ const BUNDLABLE_ENV_FILE = '.env.production';
|
|
17
|
+
/**
|
|
18
|
+
* True when a forward-slash asset key holds no secret or private-history path
|
|
19
|
+
* segment.
|
|
20
|
+
*
|
|
21
|
+
* A deploy can point `--output` at a directory that also holds those files (a
|
|
22
|
+
* buildless static root, or a framework output folder that copied them in).
|
|
23
|
+
* Every collected asset becomes a publicly reachable route, so `node_modules`
|
|
24
|
+
* is excluded here too.
|
|
25
|
+
*/ export function isPublishableAsset(key) {
|
|
26
|
+
return key.split('/').every((segment)=>segment !== DEPENDENCY_DIR && !isSecretName(segment));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* True when a forward-slash bundle path belongs in a Lambda zip.
|
|
30
|
+
*
|
|
31
|
+
* A server bundle needs its `node_modules`, but never the project's `.env`
|
|
32
|
+
* files or credentials: a deployed function reads its configuration from
|
|
33
|
+
* deploy environment variables, and a packed secret only widens the blast
|
|
34
|
+
* radius of any later path that serves bundle files. `.env.production` is the
|
|
35
|
+
* deliberate exception, an escape hatch for configuration too large for the
|
|
36
|
+
* Lambda environment-variable limit.
|
|
37
|
+
*
|
|
38
|
+
* Paths inside `node_modules` are kept as-is. A dependency's own dotfiles are
|
|
39
|
+
* not the developer's secrets, and removing files a package may read at
|
|
40
|
+
* runtime would break the bundle.
|
|
41
|
+
*/ export function isBundlableFile(relativePath) {
|
|
42
|
+
const segments = relativePath.split('/');
|
|
43
|
+
if (segments.includes(DEPENDENCY_DIR)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return segments.every((segment)=>segment === BUNDLABLE_ENV_FILE || !isSecretName(segment));
|
|
47
|
+
}
|
|
48
|
+
function isSecretName(segment) {
|
|
49
|
+
return SECRET_NAMES.has(segment) || segment.startsWith('.env');
|
|
50
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface PageCollection {
|
|
2
|
+
/** S3 key → relative filesystem path from project root */
|
|
3
|
+
pathMap: Record<string, string>;
|
|
4
|
+
/** Route → S3 upload keys for that route (e.g., { "/products": ["products.html", "products.rsc"] }) */
|
|
5
|
+
routeAssetMap: Record<string, string[]>;
|
|
6
|
+
/** Route paths for the manifest pages array (e.g., ["/products", "/blog"]) */
|
|
7
|
+
routes: string[];
|
|
8
|
+
/** S3 keys to upload (e.g., ["products.html", "products.rsc", "products.meta"]) */
|
|
9
|
+
uploadKeys: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface AssetCollection {
|
|
12
|
+
/** S3 key → relative filesystem path from project root */
|
|
13
|
+
pathMap: Record<string, string>;
|
|
14
|
+
/** Route paths for the manifest assets array (e.g., ["/favicon.ico"]) */
|
|
15
|
+
routes: string[];
|
|
16
|
+
/** S3 keys to upload (same as routes for assets, without leading slash) */
|
|
17
|
+
uploadKeys: string[];
|
|
18
|
+
}
|
|
19
|
+
export type AdapterName = 'nextjs' | 'nitro' | 'vite';
|
|
20
|
+
export interface AdapterLogger {
|
|
21
|
+
info(message: string): void;
|
|
22
|
+
warning(message: string): void;
|
|
23
|
+
}
|
|
24
|
+
export interface LambdaBundle {
|
|
25
|
+
/** Total size in bytes of the bundle contents before compression. */
|
|
26
|
+
unzippedBytes: number;
|
|
27
|
+
/** Absolute path to the built lambda.zip. */
|
|
28
|
+
zipPath: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PrepareLambdaBundleOptions {
|
|
31
|
+
/** Directory where lambda.zip is written. Defaults to the project root. */
|
|
32
|
+
artifactDir?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DeployAdapter {
|
|
35
|
+
collectAssets(projectPath: string, output?: string): Promise<AssetCollection>;
|
|
36
|
+
collectPages(projectPath: string, output?: string): Promise<PageCollection>;
|
|
37
|
+
/** SPA fallback path (e.g., "/index.html"). Undefined for SSR/SSG apps. */
|
|
38
|
+
fallback?: string;
|
|
39
|
+
name: AdapterName;
|
|
40
|
+
/** Assembles and zips the server bundle. Returns null if the adapter has no server. */
|
|
41
|
+
prepareLambdaBundle(projectPath: string, output?: string, options?: PrepareLambdaBundleOptions): Promise<LambdaBundle | null>;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AssetCollection, DeployAdapter, LambdaBundle, PageCollection } from '
|
|
1
|
+
import type { AssetCollection, DeployAdapter, LambdaBundle, PageCollection } from './types.js';
|
|
2
2
|
export declare class ViteAdapter implements DeployAdapter {
|
|
3
3
|
fallback: string;
|
|
4
4
|
name: "vite";
|
|
5
|
-
collectAssets(projectPath: string): Promise<AssetCollection>;
|
|
5
|
+
collectAssets(projectPath: string, output?: string): Promise<AssetCollection>;
|
|
6
6
|
collectPages(): Promise<PageCollection>;
|
|
7
7
|
prepareLambdaBundle(): Promise<LambdaBundle | null>;
|
|
8
8
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
|
|
3
|
+
import { collectFilesRecursive } from './fs-utils.js';
|
|
4
|
+
import { isPublishableAsset } from './secret-files.js';
|
|
5
|
+
export class ViteAdapter {
|
|
6
|
+
fallback = '/index.html';
|
|
7
|
+
name = 'vite';
|
|
8
|
+
async collectAssets(projectPath, output) {
|
|
9
|
+
const outputPath = resolveOutputPath(projectPath, 'vite', output);
|
|
10
|
+
const files = (await collectFilesRecursive(outputPath, outputPath)).filter(isPublishableAsset);
|
|
11
|
+
const pathMap = Object.fromEntries(files.map((file)=>[
|
|
12
|
+
file,
|
|
13
|
+
path.relative(projectPath, path.join(outputPath, file))
|
|
14
|
+
]));
|
|
15
|
+
return {
|
|
16
|
+
pathMap,
|
|
17
|
+
routes: files.map((k)=>`/${k}`),
|
|
18
|
+
uploadKeys: files
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
collectPages() {
|
|
22
|
+
return Promise.resolve({
|
|
23
|
+
pathMap: {},
|
|
24
|
+
routeAssetMap: {},
|
|
25
|
+
routes: [],
|
|
26
|
+
uploadKeys: []
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
prepareLambdaBundle() {
|
|
30
|
+
return Promise.resolve(null);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const viteAdapter = new ViteAdapter();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthCredential } from '../auth/credentials.js';
|
|
2
|
+
interface CheckProjectSubdomainAvailabilityArgs {
|
|
3
|
+
credential: AuthCredential;
|
|
4
|
+
subdomain: string;
|
|
5
|
+
}
|
|
6
|
+
interface ProjectSubdomainAvailability {
|
|
7
|
+
available: boolean;
|
|
8
|
+
domainName: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function checkProjectSubdomainAvailability({ credential, subdomain, }: CheckProjectSubdomainAvailabilityArgs): Promise<ProjectSubdomainAvailability>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getAuthHeaders } from '../auth/credentials.js';
|
|
2
|
+
import { getEnvConfig } from '../constants.js';
|
|
3
|
+
import { controlPlaneFetch } from './control-plane-fetch.js';
|
|
4
|
+
export async function checkProjectSubdomainAvailability({ credential, subdomain }) {
|
|
5
|
+
if (process.env.FIGMA_MOCK_CONTROL_PLANE === 'true') {
|
|
6
|
+
return {
|
|
7
|
+
available: true,
|
|
8
|
+
domainName: `${subdomain}.pung.site`,
|
|
9
|
+
reason: ''
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const response = await controlPlaneFetch({
|
|
13
|
+
context: 'check project subdomain availability',
|
|
14
|
+
options: {
|
|
15
|
+
body: JSON.stringify({
|
|
16
|
+
subdomain
|
|
17
|
+
}),
|
|
18
|
+
headers: {
|
|
19
|
+
...getAuthHeaders(credential),
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
},
|
|
22
|
+
method: 'POST'
|
|
23
|
+
},
|
|
24
|
+
url: `${getEnvConfig().apiBaseUrl}/v1/cms/check_domain_availability`
|
|
25
|
+
});
|
|
26
|
+
const availabilityResponse = await response.json();
|
|
27
|
+
return {
|
|
28
|
+
available: availabilityResponse.meta.available,
|
|
29
|
+
domainName: availabilityResponse.meta.domain_name,
|
|
30
|
+
reason: availabilityResponse.meta.reason
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Error thrown when Control Plane API calls fail. */
|
|
2
|
+
export declare class ControlPlaneError extends Error {
|
|
3
|
+
statusCode?: number | undefined;
|
|
4
|
+
cause?: Error | undefined;
|
|
5
|
+
constructor(message: string, statusCode?: number | undefined, cause?: Error | undefined);
|
|
6
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Error thrown when Control Plane API calls fail. */ export class ControlPlaneError extends Error {
|
|
2
|
+
statusCode;
|
|
3
|
+
cause;
|
|
4
|
+
constructor(message, statusCode, cause){
|
|
5
|
+
super(message), this.statusCode = statusCode, this.cause = cause;
|
|
6
|
+
this.name = 'ControlPlaneError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ControlPlaneError } from './control-plane-error.js';
|
|
2
|
+
import { parseControlPlaneApiError } from './error-response.js';
|
|
3
|
+
const MAX_RETRIES = 3;
|
|
4
|
+
const INITIAL_RETRY_DELAY = 1000;
|
|
5
|
+
export async function controlPlaneFetch({ context, options, url }) {
|
|
6
|
+
let lastError;
|
|
7
|
+
for(let attempt = 0; attempt < MAX_RETRIES; attempt++){
|
|
8
|
+
try {
|
|
9
|
+
const response = await fetch(url, options);
|
|
10
|
+
if (response.ok) {
|
|
11
|
+
return response;
|
|
12
|
+
}
|
|
13
|
+
if (response.status < 500) {
|
|
14
|
+
throw new ControlPlaneError(await parseControlPlaneApiError({
|
|
15
|
+
context,
|
|
16
|
+
response
|
|
17
|
+
}), response.status);
|
|
18
|
+
}
|
|
19
|
+
lastError = new ControlPlaneError(await parseControlPlaneApiError({
|
|
20
|
+
context,
|
|
21
|
+
response
|
|
22
|
+
}), response.status);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error instanceof ControlPlaneError) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
lastError = error instanceof Error ? error : new Error('Unknown error');
|
|
28
|
+
}
|
|
29
|
+
if (attempt < MAX_RETRIES - 1) {
|
|
30
|
+
await sleep(INITIAL_RETRY_DELAY * Math.pow(2, attempt));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new ControlPlaneError(`Network error while ${context}: ${lastError?.message || 'Unknown error'}`, undefined, lastError);
|
|
34
|
+
}
|
|
35
|
+
function sleep(ms) {
|
|
36
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
37
|
+
}
|
|
@@ -5,14 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { AuthCredential } from '../auth/credentials.js';
|
|
7
7
|
import type { Tenant } from '../types/config.js';
|
|
8
|
-
/**
|
|
9
|
-
* Error thrown when Control Plane API calls fail
|
|
10
|
-
*/
|
|
11
|
-
export declare class ControlPlaneError extends Error {
|
|
12
|
-
statusCode?: number | undefined;
|
|
13
|
-
cause?: Error | undefined;
|
|
14
|
-
constructor(message: string, statusCode?: number | undefined, cause?: Error | undefined);
|
|
15
|
-
}
|
|
16
8
|
/**
|
|
17
9
|
* Options for creating a new tenant
|
|
18
10
|
*/
|
|
@@ -77,7 +69,7 @@ export interface PerformDeploymentResponse {
|
|
|
77
69
|
deploymentId: string;
|
|
78
70
|
/** Status message */
|
|
79
71
|
message: string;
|
|
80
|
-
/**
|
|
72
|
+
/** SiteDomain hostnames returned through the compatibility tenant_domains key */
|
|
81
73
|
tenantDomains: string[];
|
|
82
74
|
}
|
|
83
75
|
export interface PerformDeploymentApiResponse {
|
|
@@ -5,22 +5,12 @@
|
|
|
5
5
|
*/ import { getAuthHeaders } from '../auth/credentials.js';
|
|
6
6
|
import { getEnvConfig } from '../constants.js';
|
|
7
7
|
import * as log from '../utils/log.js';
|
|
8
|
-
import {
|
|
8
|
+
import { controlPlaneFetch } from './control-plane-fetch.js';
|
|
9
9
|
/**
|
|
10
10
|
* Get the Control Plane API base URL based on environment
|
|
11
11
|
*/ function getControlPlaneBaseUrl() {
|
|
12
12
|
return getEnvConfig().apiBaseUrl;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Error thrown when Control Plane API calls fail
|
|
16
|
-
*/ export class ControlPlaneError extends Error {
|
|
17
|
-
statusCode;
|
|
18
|
-
cause;
|
|
19
|
-
constructor(message, statusCode, cause){
|
|
20
|
-
super(message), this.statusCode = statusCode, this.cause = cause;
|
|
21
|
-
this.name = 'ControlPlaneError';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
14
|
/**
|
|
25
15
|
* List all tenant instances for the authenticated user
|
|
26
16
|
* Maps to: GET /v1/tenant
|
|
@@ -234,7 +224,7 @@ import { parseControlPlaneApiError } from './error-response.js';
|
|
|
234
224
|
deploymentId: options.deploymentId,
|
|
235
225
|
message: 'Deployment initiated successfully',
|
|
236
226
|
tenantDomains: [
|
|
237
|
-
'example.
|
|
227
|
+
'example.figma.site'
|
|
238
228
|
]
|
|
239
229
|
};
|
|
240
230
|
}
|
|
@@ -316,39 +306,3 @@ import { parseControlPlaneApiError } from './error-response.js';
|
|
|
316
306
|
const data = await response.json();
|
|
317
307
|
return data.meta.cms_resource_id;
|
|
318
308
|
}
|
|
319
|
-
const MAX_RETRIES = 3;
|
|
320
|
-
const INITIAL_RETRY_DELAY = 1000;
|
|
321
|
-
function sleep(ms) {
|
|
322
|
-
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
323
|
-
}
|
|
324
|
-
async function controlPlaneFetch(params) {
|
|
325
|
-
const { context, options, url } = params;
|
|
326
|
-
let lastError;
|
|
327
|
-
for(let attempt = 0; attempt < MAX_RETRIES; attempt++){
|
|
328
|
-
try {
|
|
329
|
-
const response = await fetch(url, options);
|
|
330
|
-
if (response.ok) {
|
|
331
|
-
return response;
|
|
332
|
-
}
|
|
333
|
-
if (response.status < 500) {
|
|
334
|
-
throw new ControlPlaneError(await parseControlPlaneApiError({
|
|
335
|
-
context,
|
|
336
|
-
response
|
|
337
|
-
}), response.status);
|
|
338
|
-
}
|
|
339
|
-
lastError = new ControlPlaneError(await parseControlPlaneApiError({
|
|
340
|
-
context,
|
|
341
|
-
response
|
|
342
|
-
}), response.status);
|
|
343
|
-
} catch (error) {
|
|
344
|
-
if (error instanceof ControlPlaneError) {
|
|
345
|
-
throw error;
|
|
346
|
-
}
|
|
347
|
-
lastError = error instanceof Error ? error : new Error('Unknown error');
|
|
348
|
-
}
|
|
349
|
-
if (attempt < MAX_RETRIES - 1) {
|
|
350
|
-
await sleep(INITIAL_RETRY_DELAY * Math.pow(2, attempt));
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
throw new ControlPlaneError(`Network error while ${context}: ${lastError?.message || 'Unknown error'}`, undefined, lastError);
|
|
354
|
-
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AuthCredential } from '../auth/credentials.js';
|
|
2
|
+
import type { ProjectResourceType } from './project-resource-type.js';
|
|
3
|
+
interface CreateProjectArgs {
|
|
4
|
+
credential: AuthCredential;
|
|
5
|
+
description: string;
|
|
6
|
+
name: string;
|
|
7
|
+
parentPlanKey: string;
|
|
8
|
+
region: string;
|
|
9
|
+
resourceType: ProjectResourceType;
|
|
10
|
+
subdomain: string;
|
|
11
|
+
}
|
|
12
|
+
interface CreateProjectResponse {
|
|
13
|
+
domainName: string;
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function createProject({ name, credential, description, parentPlanKey, region, resourceType, subdomain, }: CreateProjectArgs): Promise<CreateProjectResponse>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getAuthHeaders } from '../auth/credentials.js';
|
|
2
|
+
import { getEnvConfig } from '../constants.js';
|
|
3
|
+
import { controlPlaneFetch } from './control-plane-fetch.js';
|
|
4
|
+
export async function createProject({ name, credential, description, parentPlanKey, region, resourceType, subdomain }) {
|
|
5
|
+
if (process.env.FIGMA_MOCK_CONTROL_PLANE === 'true') {
|
|
6
|
+
return {
|
|
7
|
+
id: `cms_${Math.random().toString(36).substring(2, 11)}`,
|
|
8
|
+
name,
|
|
9
|
+
domainName: `${subdomain}.figmasource.site`
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const response = await controlPlaneFetch({
|
|
13
|
+
context: 'create project',
|
|
14
|
+
options: {
|
|
15
|
+
body: JSON.stringify({
|
|
16
|
+
name,
|
|
17
|
+
description,
|
|
18
|
+
parent_plan_key: parentPlanKey,
|
|
19
|
+
region,
|
|
20
|
+
resource_type: resourceType,
|
|
21
|
+
subdomain
|
|
22
|
+
}),
|
|
23
|
+
headers: {
|
|
24
|
+
...getAuthHeaders(credential),
|
|
25
|
+
'Content-Type': 'application/json'
|
|
26
|
+
},
|
|
27
|
+
method: 'POST'
|
|
28
|
+
},
|
|
29
|
+
url: `${getEnvConfig().apiBaseUrl}/v1/cms`
|
|
30
|
+
});
|
|
31
|
+
const projectResponse = await response.json();
|
|
32
|
+
return {
|
|
33
|
+
id: projectResponse.meta.tenant.id,
|
|
34
|
+
name: projectResponse.meta.tenant.name,
|
|
35
|
+
domainName: projectResponse.meta.tenant.domain_name
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuthCredential } from '../auth/credentials.js';
|
|
2
|
+
interface ProjectWorkspace {
|
|
3
|
+
isDefault: boolean;
|
|
4
|
+
name: string;
|
|
5
|
+
planKey: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function listProjectWorkspaces(credential: AuthCredential): Promise<ProjectWorkspace[]>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getAuthHeaders } from '../auth/credentials.js';
|
|
2
|
+
import { getEnvConfig } from '../constants.js';
|
|
3
|
+
import { controlPlaneFetch } from './control-plane-fetch.js';
|
|
4
|
+
export async function listProjectWorkspaces(credential) {
|
|
5
|
+
if (process.env.FIGMA_MOCK_CONTROL_PLANE === 'true') {
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
name: 'Mock workspace',
|
|
9
|
+
isDefault: true,
|
|
10
|
+
planKey: 'team::mock-workspace'
|
|
11
|
+
}
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
const response = await controlPlaneFetch({
|
|
15
|
+
context: 'list project workspaces',
|
|
16
|
+
options: {
|
|
17
|
+
headers: getAuthHeaders(credential),
|
|
18
|
+
method: 'POST'
|
|
19
|
+
},
|
|
20
|
+
url: `${getEnvConfig().apiBaseUrl}/v1/cms/workspaces`
|
|
21
|
+
});
|
|
22
|
+
const workspaceResponse = await response.json();
|
|
23
|
+
return workspaceResponse.meta.workspaces.map((workspace)=>({
|
|
24
|
+
name: workspace.name,
|
|
25
|
+
isDefault: workspace.is_default,
|
|
26
|
+
planKey: workspace.plan_key
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ProjectResourceType = 'payload' | 'vite';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|