@payloadcms/figma 0.1.0-alpha.1 → 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 +6 -2
- package/dist/db-content-api/index.d.ts +1 -1
- package/dist/db-content-api/index.js +121 -72
- package/dist/db-content-api/utilities/data/index.js +2 -2
- 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/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- 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.js +5 -1
- 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/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 +2 -6
- package/dist/db-content-api/utilities/where.js +20 -9
- 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/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/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,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button, DialogBody, DialogCancel, DialogFooter, DialogHeader, DialogModal, useModal, useTranslation } from '@payloadcms/ui';
|
|
4
|
+
import { ExternalLinkIcon } from '../icons/ExternalLinkIcon.js';
|
|
5
|
+
import { cloudLimitDocumentCountModalSlug } from '../shared.js';
|
|
6
|
+
import './index.scss';
|
|
7
|
+
const baseClass = 'figma-cloud-limit-modal';
|
|
8
|
+
export function FigmaCloudLimitDocumentCountModal({ collectionLabel, collectionListURL, onRetry }) {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
const { closeModal } = useModal();
|
|
11
|
+
return /*#__PURE__*/ _jsxs(DialogModal, {
|
|
12
|
+
size: "small",
|
|
13
|
+
slug: cloudLimitDocumentCountModalSlug,
|
|
14
|
+
children: [
|
|
15
|
+
/*#__PURE__*/ _jsx(DialogHeader, {
|
|
16
|
+
showClose: true,
|
|
17
|
+
title: t('figma:cloudLimitModalHeading')
|
|
18
|
+
}),
|
|
19
|
+
/*#__PURE__*/ _jsx(DialogBody, {
|
|
20
|
+
children: /*#__PURE__*/ _jsx("p", {
|
|
21
|
+
className: `${baseClass}__body`,
|
|
22
|
+
children: t('figma:cloudLimitModalBody')
|
|
23
|
+
})
|
|
24
|
+
}),
|
|
25
|
+
/*#__PURE__*/ _jsx(DialogFooter, {
|
|
26
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
27
|
+
className: `${baseClass}__footer`,
|
|
28
|
+
children: [
|
|
29
|
+
collectionLabel && collectionListURL ? /*#__PURE__*/ _jsxs("a", {
|
|
30
|
+
className: `${baseClass}__review-btn`,
|
|
31
|
+
href: collectionListURL,
|
|
32
|
+
onClick: ()=>closeModal(cloudLimitDocumentCountModalSlug),
|
|
33
|
+
children: [
|
|
34
|
+
/*#__PURE__*/ _jsx("span", {
|
|
35
|
+
className: `${baseClass}__review-btn-label`,
|
|
36
|
+
children: t('figma:cloudLimitModalReviewCollection', {
|
|
37
|
+
collection: collectionLabel
|
|
38
|
+
})
|
|
39
|
+
}),
|
|
40
|
+
/*#__PURE__*/ _jsx(ExternalLinkIcon, {})
|
|
41
|
+
]
|
|
42
|
+
}) : null,
|
|
43
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
44
|
+
className: `${baseClass}__actions`,
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ _jsx(DialogCancel, {
|
|
47
|
+
label: t('figma:cloudLimitModalConfirm')
|
|
48
|
+
}),
|
|
49
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
50
|
+
buttonStyle: "primary",
|
|
51
|
+
margin: false,
|
|
52
|
+
onClick: ()=>{
|
|
53
|
+
closeModal(cloudLimitDocumentCountModalSlug);
|
|
54
|
+
onRetry();
|
|
55
|
+
},
|
|
56
|
+
size: "medium",
|
|
57
|
+
children: t('figma:cloudLimitModalRetry')
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.figma-cloud-limit-modal {
|
|
2
|
+
&__body {
|
|
3
|
+
margin: 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
&__footer {
|
|
7
|
+
align-items: center;
|
|
8
|
+
display: flex;
|
|
9
|
+
gap: var(--spacer-4);
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&__review-btn {
|
|
14
|
+
align-items: center;
|
|
15
|
+
background: none;
|
|
16
|
+
border: none;
|
|
17
|
+
color: var(--color-text-brand);
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
display: inline-flex;
|
|
20
|
+
flex-shrink: 1;
|
|
21
|
+
font-size: var(--text-body-medium-font-size);
|
|
22
|
+
gap: var(--spacer-1);
|
|
23
|
+
min-width: 0;
|
|
24
|
+
padding: 0;
|
|
25
|
+
|
|
26
|
+
.btn__content,
|
|
27
|
+
.btn__label {
|
|
28
|
+
min-width: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&:hover {
|
|
32
|
+
color: var(--ramp-blue-700);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&:active {
|
|
36
|
+
color: var(--ramp-blue-800);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&__review-btn-label {
|
|
41
|
+
overflow: hidden;
|
|
42
|
+
text-overflow: ellipsis;
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Prevents the icon from shrinking when the label ellipses.
|
|
47
|
+
&__review-btn svg {
|
|
48
|
+
flex-shrink: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&__actions {
|
|
52
|
+
display: flex;
|
|
53
|
+
gap: var(--spacer-2);
|
|
54
|
+
margin-inline-start: auto;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { getTranslation } from '@payloadcms/translations';
|
|
4
|
+
import { FormErrorHandlerContext, useConfig, useFormErrorHandler, useModal, useTranslation } from '@payloadcms/ui';
|
|
5
|
+
import { DrawerDepthContext } from '@payloadcms/ui/elements/Drawer';
|
|
6
|
+
import { formatAdminURL, hasAutosaveEnabled } from 'payload/shared';
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
8
|
+
import { FigmaCloudLimitDocumentCountModal } from '../CloudLimitModal/index.js';
|
|
9
|
+
import { cloudLimitDocumentCountModalSlug, cloudLimitErrorCodes, getCloudLimitErrorCode } from '../shared.js';
|
|
10
|
+
import { FigmaCloudLimitSlugRegistryContext } from '../SlugRegistryContext/index.js';
|
|
11
|
+
import { cloudLimitInterceptor } from '../utilities/cloudLimitInterceptor.js';
|
|
12
|
+
import { dismissSubmittingToast, showCloudLimitToast } from '../utilities/toasts.js';
|
|
13
|
+
export function FigmaCloudLimitProvider({ children }) {
|
|
14
|
+
const { openModal } = useModal();
|
|
15
|
+
const { i18n, t } = useTranslation();
|
|
16
|
+
const { config, getEntityConfig } = useConfig();
|
|
17
|
+
const parentErrorHandler = useFormErrorHandler();
|
|
18
|
+
const adminRoute = config.routes?.admin ?? '/admin';
|
|
19
|
+
const apiRoute = config.routes?.api ?? '/api';
|
|
20
|
+
const [modal, setModal] = useState({
|
|
21
|
+
drawerDepth: 0
|
|
22
|
+
});
|
|
23
|
+
const retryRef = useRef(undefined);
|
|
24
|
+
const registrationsRef = useRef([]);
|
|
25
|
+
const register = useCallback((registration)=>{
|
|
26
|
+
registrationsRef.current.push(registration);
|
|
27
|
+
return ()=>{
|
|
28
|
+
const index = registrationsRef.current.indexOf(registration);
|
|
29
|
+
if (index !== -1) {
|
|
30
|
+
registrationsRef.current.splice(index, 1);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
useEffect(()=>cloudLimitInterceptor(apiRoute, (key)=>t(key)), [
|
|
35
|
+
apiRoute,
|
|
36
|
+
t
|
|
37
|
+
]);
|
|
38
|
+
const handleNonFieldError = useCallback((err, retry)=>{
|
|
39
|
+
const code = getCloudLimitErrorCode({
|
|
40
|
+
errors: [
|
|
41
|
+
err
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
if (!code) {
|
|
45
|
+
return parentErrorHandler?.(err, retry) ?? false;
|
|
46
|
+
}
|
|
47
|
+
dismissSubmittingToast(t('general:submitting'));
|
|
48
|
+
if (code !== cloudLimitErrorCodes.documentCount) {
|
|
49
|
+
showCloudLimitToast(code, t);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const registrations = registrationsRef.current;
|
|
53
|
+
let activeRegistration;
|
|
54
|
+
for(let index = registrations.length - 1; index >= 0; index--){
|
|
55
|
+
if (registrations[index]?.isSubmitting) {
|
|
56
|
+
activeRegistration = registrations[index];
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
activeRegistration ??= registrations[registrations.length - 1];
|
|
61
|
+
const adminPath = formatAdminURL({
|
|
62
|
+
adminRoute,
|
|
63
|
+
includeBasePath: true
|
|
64
|
+
});
|
|
65
|
+
const slug = activeRegistration?.slug ?? /^\/collections\/([^/?#]+)/.exec(window.location.pathname.slice(adminPath.length))?.[1];
|
|
66
|
+
const collectionConfig = slug ? getEntityConfig({
|
|
67
|
+
collectionSlug: slug
|
|
68
|
+
}) : undefined;
|
|
69
|
+
if (collectionConfig && hasAutosaveEnabled(collectionConfig)) {
|
|
70
|
+
showCloudLimitToast(code, t);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
setModal({
|
|
74
|
+
collectionLabel: collectionConfig?.labels?.plural != null ? getTranslation(collectionConfig.labels.plural, i18n) : slug,
|
|
75
|
+
collectionListURL: slug ? formatAdminURL({
|
|
76
|
+
adminRoute,
|
|
77
|
+
includeBasePath: true,
|
|
78
|
+
path: `/collections/${slug}`
|
|
79
|
+
}) : undefined,
|
|
80
|
+
drawerDepth: activeRegistration?.drawerDepth ?? 0
|
|
81
|
+
});
|
|
82
|
+
retryRef.current = retry;
|
|
83
|
+
openModal(cloudLimitDocumentCountModalSlug);
|
|
84
|
+
return true;
|
|
85
|
+
}, [
|
|
86
|
+
adminRoute,
|
|
87
|
+
getEntityConfig,
|
|
88
|
+
i18n,
|
|
89
|
+
openModal,
|
|
90
|
+
parentErrorHandler,
|
|
91
|
+
t
|
|
92
|
+
]);
|
|
93
|
+
return /*#__PURE__*/ _jsx(FigmaCloudLimitSlugRegistryContext, {
|
|
94
|
+
value: register,
|
|
95
|
+
children: /*#__PURE__*/ _jsxs(FormErrorHandlerContext, {
|
|
96
|
+
value: handleNonFieldError,
|
|
97
|
+
children: [
|
|
98
|
+
children,
|
|
99
|
+
/*#__PURE__*/ _jsx(DrawerDepthContext, {
|
|
100
|
+
value: modal.drawerDepth,
|
|
101
|
+
children: /*#__PURE__*/ _jsx(FigmaCloudLimitDocumentCountModal, {
|
|
102
|
+
collectionLabel: modal.collectionLabel,
|
|
103
|
+
collectionListURL: modal.collectionListURL,
|
|
104
|
+
onRetry: ()=>retryRef.current?.()
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
]
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
.limit-hit-on-create {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
gap: var(--spacer-3);
|
|
7
|
+
min-block-size: calc(100dvh - var(--app-header-height, 0px));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.limit-hit-on-create__message {
|
|
11
|
+
margin: 0;
|
|
12
|
+
color: var(--color-text);
|
|
13
|
+
font-size: var(--text-body-medium-font-size);
|
|
14
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getTranslation } from '@payloadcms/translations';
|
|
3
|
+
import { Button, SetStepNav } from '@payloadcms/ui';
|
|
4
|
+
import { formatAdminURL } from 'payload/shared';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import './index.css';
|
|
7
|
+
const baseClass = 'limit-hit-on-create';
|
|
8
|
+
export const LimitReachedView = ({ collectionConfig, initPageResult })=>{
|
|
9
|
+
const { req } = initPageResult;
|
|
10
|
+
const adminRoute = req.payload.config.routes.admin;
|
|
11
|
+
const tFigma = req.t;
|
|
12
|
+
if (!collectionConfig) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const collectionLabel = getTranslation(collectionConfig.labels.plural, req.i18n);
|
|
16
|
+
const collectionListURL = formatAdminURL({
|
|
17
|
+
adminRoute,
|
|
18
|
+
includeBasePath: true,
|
|
19
|
+
path: `/collections/${collectionConfig.slug}`
|
|
20
|
+
});
|
|
21
|
+
return /*#__PURE__*/ _jsxs("main", {
|
|
22
|
+
className: baseClass,
|
|
23
|
+
children: [
|
|
24
|
+
/*#__PURE__*/ _jsx(SetStepNav, {
|
|
25
|
+
nav: [
|
|
26
|
+
{
|
|
27
|
+
label: collectionLabel,
|
|
28
|
+
url: collectionListURL
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: req.t('general:createNew')
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}),
|
|
35
|
+
/*#__PURE__*/ _jsx("p", {
|
|
36
|
+
className: `${baseClass}__message`,
|
|
37
|
+
children: tFigma('figma:cloudLimitDocumentCountError')
|
|
38
|
+
}),
|
|
39
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
40
|
+
buttonStyle: "primary",
|
|
41
|
+
el: "link",
|
|
42
|
+
margin: false,
|
|
43
|
+
size: "medium",
|
|
44
|
+
url: formatAdminURL({
|
|
45
|
+
adminRoute,
|
|
46
|
+
includeBasePath: true
|
|
47
|
+
}),
|
|
48
|
+
children: req.t('general:backToDashboard')
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type CollectionFormRegistration = {
|
|
2
|
+
drawerDepth: number;
|
|
3
|
+
isSubmitting: boolean;
|
|
4
|
+
slug: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
export type RegisterCollectionForm = (registration: CollectionFormRegistration) => () => void;
|
|
7
|
+
export declare const FigmaCloudLimitSlugRegistryContext: import("react").Context<RegisterCollectionForm>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function FigmaCloudLimitSlugTracker(): null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useDocumentInfo, useFormBackgroundProcessing, useFormProcessing } from '@payloadcms/ui';
|
|
3
|
+
import { useDrawerDepth } from '@payloadcms/ui/elements/Drawer';
|
|
4
|
+
import { use, useEffect } from 'react';
|
|
5
|
+
import { FigmaCloudLimitSlugRegistryContext } from '../SlugRegistryContext/index.js';
|
|
6
|
+
export function FigmaCloudLimitSlugTracker() {
|
|
7
|
+
const register = use(FigmaCloudLimitSlugRegistryContext);
|
|
8
|
+
const { collectionSlug } = useDocumentInfo();
|
|
9
|
+
const drawerDepth = useDrawerDepth();
|
|
10
|
+
const isBackgroundProcessing = useFormBackgroundProcessing();
|
|
11
|
+
const isProcessing = useFormProcessing();
|
|
12
|
+
useEffect(()=>{
|
|
13
|
+
const unregister = register({
|
|
14
|
+
slug: collectionSlug,
|
|
15
|
+
drawerDepth,
|
|
16
|
+
isSubmitting: isBackgroundProcessing || isProcessing
|
|
17
|
+
});
|
|
18
|
+
return unregister;
|
|
19
|
+
}, [
|
|
20
|
+
collectionSlug,
|
|
21
|
+
drawerDepth,
|
|
22
|
+
isBackgroundProcessing,
|
|
23
|
+
isProcessing,
|
|
24
|
+
register
|
|
25
|
+
]);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/** External link icon (box with arrow pointing out). Used in cloud-limit UI. */ export function ExternalLinkIcon() {
|
|
4
|
+
return /*#__PURE__*/ _jsxs("svg", {
|
|
5
|
+
"aria-hidden": "true",
|
|
6
|
+
fill: "none",
|
|
7
|
+
height: "14",
|
|
8
|
+
stroke: "currentColor",
|
|
9
|
+
strokeLinecap: "round",
|
|
10
|
+
strokeLinejoin: "round",
|
|
11
|
+
strokeWidth: "2",
|
|
12
|
+
viewBox: "0 0 24 24",
|
|
13
|
+
width: "14",
|
|
14
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
15
|
+
children: [
|
|
16
|
+
/*#__PURE__*/ _jsx("path", {
|
|
17
|
+
d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
|
|
18
|
+
}),
|
|
19
|
+
/*#__PURE__*/ _jsx("polyline", {
|
|
20
|
+
points: "15 3 21 3 21 9"
|
|
21
|
+
}),
|
|
22
|
+
/*#__PURE__*/ _jsx("line", {
|
|
23
|
+
x1: "10",
|
|
24
|
+
x2: "21",
|
|
25
|
+
y1: "14",
|
|
26
|
+
y2: "3"
|
|
27
|
+
})
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const LIMIT_REACHED_VIEW_KEY = 'figmaLimitReached';
|
|
2
|
+
// Reserved collection-level admin route. Applications using custom string IDs must not use
|
|
3
|
+
// "limit-reached"; the custom view intentionally takes precedence over a document edit route.
|
|
4
|
+
export const LIMIT_REACHED_VIEW_PATH = '/limit-reached';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Payload, PayloadRequest } from 'payload';
|
|
2
|
+
type Args = {
|
|
3
|
+
collectionSlug: string;
|
|
4
|
+
errorCode: unknown;
|
|
5
|
+
payload: Payload;
|
|
6
|
+
req?: Partial<Pick<PayloadRequest, 'pathname' | 'server'>>;
|
|
7
|
+
};
|
|
8
|
+
export declare function redirectInitialAutosaveCreate({ collectionSlug, errorCode, payload, req, }: Args): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { formatAdminURL, hasAutosaveEnabled } from 'payload/shared';
|
|
2
|
+
import { LIMIT_REACHED_VIEW_PATH } from '../routes.js';
|
|
3
|
+
import { cloudLimitErrorCodes } from '../shared.js';
|
|
4
|
+
export function redirectInitialAutosaveCreate({ collectionSlug, errorCode, payload, req }) {
|
|
5
|
+
// Initial autosave creates an empty document, so documentDataSize is not expected in
|
|
6
|
+
// production. Keep it as a defensive/test-only fallback and intentionally route it
|
|
7
|
+
// through the same terminal create-failure view.
|
|
8
|
+
const isSupportedLimit = errorCode === cloudLimitErrorCodes.documentCount || errorCode === cloudLimitErrorCodes.documentDataSize;
|
|
9
|
+
const collectionConfig = payload.collections[collectionSlug]?.config;
|
|
10
|
+
const server = req?.server;
|
|
11
|
+
if (!isSupportedLimit || !collectionConfig || !server || !hasAutosaveEnabled(collectionConfig)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const { admin: adminRoute } = payload.config.routes;
|
|
15
|
+
const createPath = formatAdminURL({
|
|
16
|
+
adminRoute,
|
|
17
|
+
includeBasePath: true,
|
|
18
|
+
path: `/collections/${collectionSlug}/create`
|
|
19
|
+
});
|
|
20
|
+
if (req.pathname?.replace(/\/$/, '') !== createPath.replace(/\/$/, '')) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
server.redirect(formatAdminURL({
|
|
24
|
+
adminRoute,
|
|
25
|
+
includeBasePath: true,
|
|
26
|
+
path: `/collections/${collectionSlug}${LIMIT_REACHED_VIEW_PATH}`
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const cloudLimitErrorCodes: {
|
|
2
|
+
readonly assetStorage: "cloud_limit.cms_assets_bytes_exceeded";
|
|
3
|
+
readonly documentCount: "cloud_limit.document_count_exceeded";
|
|
4
|
+
readonly documentDataSize: "cloud_limit.per_document_data_bytes_exceeded";
|
|
5
|
+
};
|
|
6
|
+
export type CloudLimitErrorCode = (typeof cloudLimitErrorCodes)[keyof typeof cloudLimitErrorCodes];
|
|
7
|
+
export declare function isCloudLimitErrorCode(code: unknown): code is CloudLimitErrorCode;
|
|
8
|
+
export declare function getCloudLimitErrorCode(json: unknown): CloudLimitErrorCode | undefined;
|
|
9
|
+
export declare const cloudLimitDocumentCountModalSlug = "figma-cloud-limit-document-count";
|
|
10
|
+
export declare const cloudLimitToastKeyByCode: Record<CloudLimitErrorCode, string>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const cloudLimitErrorCodes = {
|
|
2
|
+
assetStorage: 'cloud_limit.cms_assets_bytes_exceeded',
|
|
3
|
+
documentCount: 'cloud_limit.document_count_exceeded',
|
|
4
|
+
documentDataSize: 'cloud_limit.per_document_data_bytes_exceeded'
|
|
5
|
+
};
|
|
6
|
+
const knownCloudLimitCodes = Object.values(cloudLimitErrorCodes);
|
|
7
|
+
export function isCloudLimitErrorCode(code) {
|
|
8
|
+
return typeof code === 'string' && knownCloudLimitCodes.includes(code);
|
|
9
|
+
}
|
|
10
|
+
const cloudLimitCodeByMessagePattern = [
|
|
11
|
+
{
|
|
12
|
+
code: cloudLimitErrorCodes.documentCount,
|
|
13
|
+
pattern: /document count/i
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
code: cloudLimitErrorCodes.documentDataSize,
|
|
17
|
+
pattern: /document data size/i
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
code: cloudLimitErrorCodes.assetStorage,
|
|
21
|
+
pattern: /asset storage limit/i
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
export function getCloudLimitErrorCode(json) {
|
|
25
|
+
const errors = json?.errors;
|
|
26
|
+
if (!Array.isArray(errors)) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
for (const err of errors){
|
|
30
|
+
const code = err?.data?.code;
|
|
31
|
+
if (isCloudLimitErrorCode(code)) {
|
|
32
|
+
return code;
|
|
33
|
+
}
|
|
34
|
+
const message = err?.message;
|
|
35
|
+
if (message?.startsWith('Content API ')) {
|
|
36
|
+
// Payload's bulk-upload response currently drops APIError.data.code. Match only the
|
|
37
|
+
// identifying phrase from each Content API message so variable values and minor wording
|
|
38
|
+
// changes do not break the fallback. Prefer the structured code above whenever present.
|
|
39
|
+
const match = cloudLimitCodeByMessagePattern.find(({ pattern })=>pattern.test(message));
|
|
40
|
+
if (match) {
|
|
41
|
+
return match.code;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
export const cloudLimitDocumentCountModalSlug = 'figma-cloud-limit-document-count';
|
|
48
|
+
export const cloudLimitToastKeyByCode = {
|
|
49
|
+
[cloudLimitErrorCodes.assetStorage]: 'figma:cloudLimitAssetStorageError',
|
|
50
|
+
[cloudLimitErrorCodes.documentCount]: 'figma:cloudLimitDocumentCountError',
|
|
51
|
+
[cloudLimitErrorCodes.documentDataSize]: 'figma:cloudLimitDocumentDataSizeError'
|
|
52
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { toast } from '@payloadcms/ui';
|
|
3
|
+
import { formatAdminURL } from 'payload/shared';
|
|
4
|
+
import { getCloudLimitErrorCode } from '../shared.js';
|
|
5
|
+
import { showCloudLimitToast } from './toasts.js';
|
|
6
|
+
const ERROR_SUPPRESSION_MS = 1_000;
|
|
7
|
+
const SUMMARY_SUPPRESSION_MS = 60_000;
|
|
8
|
+
function restoreBulkErrorCodes(response, json) {
|
|
9
|
+
if (!json || typeof json !== 'object' || !Array.isArray(json.docs) || !Array.isArray(json.errors)) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
let hasLimitError = false;
|
|
13
|
+
const errors = json.errors.map((error)=>{
|
|
14
|
+
const code = getCloudLimitErrorCode({
|
|
15
|
+
errors: [
|
|
16
|
+
error
|
|
17
|
+
]
|
|
18
|
+
});
|
|
19
|
+
if (!code || !error || typeof error !== 'object') {
|
|
20
|
+
return error;
|
|
21
|
+
}
|
|
22
|
+
hasLimitError = true;
|
|
23
|
+
const data = error.data;
|
|
24
|
+
return {
|
|
25
|
+
...error,
|
|
26
|
+
data: {
|
|
27
|
+
...typeof data === 'object' && data ? data : {},
|
|
28
|
+
code
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
if (!hasLimitError) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const { message: _aggregateMessage, ...result } = json;
|
|
36
|
+
const headers = new Headers(response.headers);
|
|
37
|
+
headers.delete('content-encoding');
|
|
38
|
+
headers.delete('content-length');
|
|
39
|
+
return new Response(JSON.stringify({
|
|
40
|
+
...result,
|
|
41
|
+
errors
|
|
42
|
+
}), {
|
|
43
|
+
headers,
|
|
44
|
+
status: response.status,
|
|
45
|
+
statusText: response.statusText
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function cloudLimitInterceptor(apiRoute, translate) {
|
|
49
|
+
const originalFetch = window.fetch;
|
|
50
|
+
const originalToastError = toast.error;
|
|
51
|
+
const suppressions = new Map();
|
|
52
|
+
let suppressSummary = false;
|
|
53
|
+
let summaryTimeout;
|
|
54
|
+
const patchedToastError = (...args)=>{
|
|
55
|
+
const message = typeof args[0] === 'string' ? args[0] : args[0]?.props?.errorMessage ?? '';
|
|
56
|
+
const match = [
|
|
57
|
+
...suppressions
|
|
58
|
+
].find(([rawMessage])=>message.includes(rawMessage));
|
|
59
|
+
if (match) {
|
|
60
|
+
const [, suppression] = match;
|
|
61
|
+
// Keep the suppression for its full lifetime so overlapping requests with the same raw
|
|
62
|
+
// error cannot leak duplicate Payload error toasts. The stable info-toast ID deduplicates
|
|
63
|
+
// the replacement notification.
|
|
64
|
+
showCloudLimitToast(suppression.code, translate);
|
|
65
|
+
if (suppression.isBulkUpload) {
|
|
66
|
+
suppressSummary = true;
|
|
67
|
+
window.clearTimeout(summaryTimeout);
|
|
68
|
+
summaryTimeout = window.setTimeout(()=>suppressSummary = false, SUMMARY_SUPPRESSION_MS);
|
|
69
|
+
}
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
if (suppressSummary && /^Failed to save \d+ files$/.test(message)) {
|
|
73
|
+
suppressSummary = false;
|
|
74
|
+
window.clearTimeout(summaryTimeout);
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
return originalToastError(...args);
|
|
78
|
+
};
|
|
79
|
+
const patchedFetch = async (...args)=>{
|
|
80
|
+
const response = await originalFetch(...args);
|
|
81
|
+
if (response.status < 400) {
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const json = await response.clone().json();
|
|
86
|
+
const bulkResponse = response.status === 400 ? restoreBulkErrorCodes(response, json) : undefined;
|
|
87
|
+
if (bulkResponse) {
|
|
88
|
+
return bulkResponse;
|
|
89
|
+
}
|
|
90
|
+
const input = args[0];
|
|
91
|
+
const pathname = new URL(input instanceof Request ? input.url : String(input), window.location.origin).pathname;
|
|
92
|
+
const method = (input instanceof Request ? input.method : args[1]?.method ?? 'GET').toUpperCase();
|
|
93
|
+
const apiPath = formatAdminURL({
|
|
94
|
+
apiRoute,
|
|
95
|
+
path: ''
|
|
96
|
+
}).replace(/\/$/, '');
|
|
97
|
+
const endpoint = pathname.startsWith(`${apiPath}/`) ? pathname.slice(apiPath.length + 1) : '';
|
|
98
|
+
const isUploadInstructions = endpoint === 'upload-instructions';
|
|
99
|
+
const isCollectionCreate = method === 'POST' && endpoint !== '' && !endpoint.includes('/');
|
|
100
|
+
if (!isUploadInstructions && !isCollectionCreate) {
|
|
101
|
+
return response;
|
|
102
|
+
}
|
|
103
|
+
const code = getCloudLimitErrorCode(json);
|
|
104
|
+
const rawMessage = json?.errors?.[0]?.message;
|
|
105
|
+
if (code && rawMessage) {
|
|
106
|
+
const previous = suppressions.get(rawMessage);
|
|
107
|
+
window.clearTimeout(previous?.timeout);
|
|
108
|
+
const suppression = {
|
|
109
|
+
code,
|
|
110
|
+
isBulkUpload: isCollectionCreate,
|
|
111
|
+
timeout: 0
|
|
112
|
+
};
|
|
113
|
+
suppression.timeout = window.setTimeout(()=>suppressions.delete(rawMessage), ERROR_SUPPRESSION_MS);
|
|
114
|
+
suppressions.set(rawMessage, suppression);
|
|
115
|
+
}
|
|
116
|
+
} catch {
|
|
117
|
+
// Leave Payload's default handling intact for malformed error responses.
|
|
118
|
+
}
|
|
119
|
+
return response;
|
|
120
|
+
};
|
|
121
|
+
window.fetch = patchedFetch;
|
|
122
|
+
toast.error = patchedToastError;
|
|
123
|
+
return ()=>{
|
|
124
|
+
suppressions.forEach(({ timeout })=>window.clearTimeout(timeout));
|
|
125
|
+
window.clearTimeout(summaryTimeout);
|
|
126
|
+
if (window.fetch === patchedFetch) {
|
|
127
|
+
window.fetch = originalFetch;
|
|
128
|
+
}
|
|
129
|
+
if (toast.error === patchedToastError) {
|
|
130
|
+
;
|
|
131
|
+
toast.error = originalToastError;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CloudLimitErrorCode } from '../shared.js';
|
|
2
|
+
export type Translate = (key: string) => string;
|
|
3
|
+
export declare function dismissSubmittingToast(label: string): void;
|
|
4
|
+
export declare function showCloudLimitToast(code: CloudLimitErrorCode, translate: Translate): void;
|