@payloadcms/ui 3.89.0 → 3.90.0
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/dist/elements/BulkUpload/FormsManager/createFormData.d.ts +1 -1
- package/dist/elements/BulkUpload/FormsManager/createFormData.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/createFormData.js +7 -3
- package/dist/elements/BulkUpload/FormsManager/createFormData.js.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +4 -2
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/elements/Spinner/index.d.ts +19 -0
- package/dist/elements/Spinner/index.d.ts.map +1 -0
- package/dist/elements/Spinner/index.js +51 -0
- package/dist/elements/Spinner/index.js.map +1 -0
- package/dist/elements/Spinner/index.scss +23 -0
- package/dist/exports/client/index.d.ts +4 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +12 -12
- package/dist/exports/client/index.js.map +4 -4
- package/dist/fields/Tabs/index.d.ts.map +1 -1
- package/dist/fields/Tabs/index.js +109 -234
- package/dist/fields/Tabs/index.js.map +1 -1
- package/dist/fields/Tabs/resolveRestoredTabIndex.d.ts +19 -0
- package/dist/fields/Tabs/resolveRestoredTabIndex.d.ts.map +1 -0
- package/dist/fields/Tabs/resolveRestoredTabIndex.js +20 -0
- package/dist/fields/Tabs/resolveRestoredTabIndex.js.map +1 -0
- package/dist/fields/Tabs/resolveRestoredTabIndex.spec.js +53 -0
- package/dist/fields/Tabs/resolveRestoredTabIndex.spec.js.map +1 -0
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +6 -2
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +3 -2
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.d.ts +12 -0
- package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.d.ts.map +1 -0
- package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.js +32 -0
- package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.js.map +1 -0
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.d.ts +8 -6
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js +25 -9
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js +179 -0
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js.map +1 -0
- package/dist/forms/fieldSchemasToFormState/types.d.ts +1 -0
- package/dist/forms/fieldSchemasToFormState/types.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.js.map +1 -1
- package/dist/icons/Eye/index.scss +1 -1
- package/dist/icons/Refresh/index.d.ts +7 -0
- package/dist/icons/Refresh/index.d.ts.map +1 -0
- package/dist/icons/Refresh/index.js +35 -0
- package/dist/icons/Refresh/index.js.map +1 -0
- package/dist/icons/Refresh/index.scss +11 -0
- package/dist/icons/Spinner/index.d.ts +8 -0
- package/dist/icons/Spinner/index.d.ts.map +1 -0
- package/dist/icons/Spinner/index.js +34 -0
- package/dist/icons/Spinner/index.js.map +1 -0
- package/dist/icons/Spinner/index.scss +12 -0
- package/dist/styles.css +1 -1
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +6 -2
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/schedulePublishHandler.d.ts.map +1 -1
- package/dist/utilities/schedulePublishHandler.js +4 -1
- package/dist/utilities/schedulePublishHandler.js.map +1 -1
- package/dist/views/Edit/Auth/APIKey.d.ts +1 -1
- package/dist/views/Edit/Auth/APIKey.d.ts.map +1 -1
- package/dist/views/Edit/Auth/APIKey.js +216 -59
- package/dist/views/Edit/Auth/APIKey.js.map +1 -1
- package/dist/views/Edit/Auth/APIKeyGenerationModal.d.ts +11 -0
- package/dist/views/Edit/Auth/APIKeyGenerationModal.d.ts.map +1 -0
- package/dist/views/Edit/Auth/APIKeyGenerationModal.js +113 -0
- package/dist/views/Edit/Auth/APIKeyGenerationModal.js.map +1 -0
- package/dist/views/Edit/Auth/index.d.ts.map +1 -1
- package/dist/views/Edit/Auth/index.js +10 -30
- package/dist/views/Edit/Auth/index.js.map +1 -1
- package/dist/views/Edit/Auth/index.scss +73 -36
- package/dist/views/Edit/Auth/types.d.ts +1 -1
- package/dist/views/Edit/Auth/types.d.ts.map +1 -1
- package/dist/views/Edit/Auth/types.js.map +1 -1
- package/package.json +5 -5
- package/dist/elements/GenerateConfirmation/index.d.ts +0 -7
- package/dist/elements/GenerateConfirmation/index.d.ts.map +0 -1
- package/dist/elements/GenerateConfirmation/index.js +0 -95
- package/dist/elements/GenerateConfirmation/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACf,MAAM,SAAS,CAAA;AAehB,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,KAAK,2BAA2B,GAAG;IACjC,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,2BAA2B,CAAA;AAE1F,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAChD,kBAAkB,EAClB,OAAO,CAAC,oBAAoB,CAAC,CAwB9B,CAAA;AAED,eAAO,MAAM,cAAc,SACnB,kBAAkB,KACvB,OAAO,CAAC,2BAA2B,
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACf,MAAM,SAAS,CAAA;AAehB,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,KAAK,2BAA2B,GAAG;IACjC,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,2BAA2B,CAAA;AAE1F,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAChD,kBAAkB,EAClB,OAAO,CAAC,oBAAoB,CAAC,CAwB9B,CAAA;AAED,eAAO,MAAM,cAAc,SACnB,kBAAkB,KACvB,OAAO,CAAC,2BAA2B,CAuNrC,CAAA"}
|
|
@@ -69,7 +69,8 @@ export const buildFormState = async args => {
|
|
|
69
69
|
select,
|
|
70
70
|
skipClientConfigAuth,
|
|
71
71
|
skipValidation,
|
|
72
|
-
updateLastEdited
|
|
72
|
+
updateLastEdited,
|
|
73
|
+
user
|
|
73
74
|
} = args;
|
|
74
75
|
const selectMode = select ? getSelectMode(select) : undefined;
|
|
75
76
|
if (!collectionSlug && !globalSlug && !widgetSlug) {
|
|
@@ -148,7 +149,10 @@ export const buildFormState = async args => {
|
|
|
148
149
|
previousFormState: formState,
|
|
149
150
|
readOnly,
|
|
150
151
|
renderAllFields,
|
|
151
|
-
renderFieldFn: renderField
|
|
152
|
+
renderFieldFn: renderFieldArgs => renderField({
|
|
153
|
+
...renderFieldArgs,
|
|
154
|
+
user
|
|
155
|
+
}),
|
|
152
156
|
req,
|
|
153
157
|
schemaPath,
|
|
154
158
|
select,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.js","names":["canAccessAdmin","formatErrors","UnauthorizedError","getSelectMode","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","handleLivePreview","handlePreview","handleStaleDataCheck","buildFormStateHandler","args","req","res","buildFormState","err","payload","logger","error","msg","message","id","idFromArgs","checkForStaleData","collectionSlug","data","incomingData","docPermissions","docPreferences","documentFormState","formState","globalSlug","initialBlockData","initialBlockFormState","mockRSCs","operation","originalUpdatedAt","readOnly","renderAllFields","i18n","config","returnLivePreviewURL","returnLockStatus","returnPreviewURL","widgetSlug","schemaPath","select","skipClientConfigAuth","skipValidation","updateLastEdited","selectMode","undefined","Error","schemaMap","clientSchemaMap","importMap","user","fieldOrEntityConfig","get","fields","length","type","documentData","blockData","Array","isArray","formStateResult","clientFieldSchemaMap","fieldSchemaMap","permissions","preferences","previousFormState","renderFieldFn","collections","upload","file","lockedStateResult","staleDataStateResult","lockedState","staleDataState","state","livePreviewURL","previewURL"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type {\n BuildFormStateArgs,\n ClientConfig,\n ClientUser,\n ErrorResult,\n FormState,\n ServerFunction,\n} from 'payload'\n\nimport { canAccessAdmin, formatErrors, UnauthorizedError } from 'payload'\nimport { getSelectMode, reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { getClientConfig } from './getClientConfig.js'\nimport { getClientSchemaMap } from './getClientSchemaMap.js'\nimport { getSchemaMap } from './getSchemaMap.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\nimport { handleLivePreview } from './handleLivePreview.js'\nimport { handlePreview } from './handlePreview.js'\nimport { handleStaleDataCheck } from './handleStaleDataCheck.js'\n\nexport type LockedState = {\n isLocked: boolean\n lastEditedAt: string\n user?: ClientUser | number | string\n}\n\nexport type StaleDataState = {\n currentUpdatedAt: string\n isStale: boolean\n}\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n livePreviewURL?: string\n lockedState?: LockedState\n previewURL?: string\n staleDataState?: StaleDataState\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n livePreviewURL?: never\n lockedState?: never\n previewURL?: never\n staleDataState?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler: ServerFunction<\n BuildFormStateArgs,\n Promise<BuildFormStateResult>\n> = async (args) => {\n const { req } = args\n\n try {\n await canAccessAdmin({ req })\n const res = await buildFormState(args)\n\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n throw new UnauthorizedError()\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n checkForStaleData,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n documentFormState,\n formState,\n globalSlug,\n initialBlockData,\n initialBlockFormState,\n mockRSCs,\n operation,\n originalUpdatedAt,\n readOnly,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLivePreviewURL,\n returnLockStatus,\n returnPreviewURL,\n widgetSlug,\n schemaPath = collectionSlug || globalSlug || widgetSlug,\n select,\n skipClientConfigAuth,\n skipValidation,\n updateLastEdited,\n } = args\n\n const selectMode = select ? getSelectMode(select) : undefined\n\n if (!collectionSlug && !globalSlug && !widgetSlug) {\n throw new Error('Either collectionSlug, globalSlug, or widgetSlug must be provided')\n }\n\n const schemaMap = getSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n widgetSlug,\n })\n\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug,\n config: getClientConfig({\n config,\n i18n,\n importMap: req.payload.importMap,\n user: skipClientConfigAuth ? true : req.user,\n }),\n globalSlug,\n i18n,\n payload,\n schemaMap,\n widgetSlug,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = schemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is form state but no data, deduce data from that form state, e.g. on initial load\n // Otherwise, use the incoming data as the source of truth, e.g. on subsequent saves\n const data = incomingData || reduceFieldsToValues(formState, true)\n\n let documentData = undefined\n\n if (documentFormState) {\n documentData = reduceFieldsToValues(documentFormState, true)\n }\n\n let blockData = initialBlockData\n\n if (initialBlockFormState) {\n blockData = reduceFieldsToValues(initialBlockFormState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n // Ensure data.id is present during form state requests, where the data\n // is passed from the client as an argument, without the ID\n if (!data.id && id) {\n data.id = id\n }\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug,\n data,\n documentData,\n fields,\n fieldSchemaMap: schemaMap,\n initialBlockData: blockData,\n mockRSCs,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n readOnly,\n renderAllFields,\n renderFieldFn: renderField,\n req,\n schemaPath,\n select,\n selectMode,\n skipValidation,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult: LockedState | undefined\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n let staleDataStateResult: StaleDataState | undefined\n\n if (checkForStaleData && originalUpdatedAt && ((collectionSlug && id) || globalSlug)) {\n staleDataStateResult = await handleStaleDataCheck({\n id,\n collectionSlug,\n globalSlug,\n originalUpdatedAt,\n req,\n })\n }\n\n const res: BuildFormStateSuccessResult = {\n lockedState: lockedStateResult,\n staleDataState: staleDataStateResult,\n state: formStateResult,\n }\n\n if (returnLivePreviewURL) {\n const { livePreviewURL } = await handleLivePreview({\n collectionSlug,\n config,\n data,\n globalSlug,\n req,\n })\n\n // Important: only set this when not undefined,\n // Otherwise it will travel through the network as `$undefined`\n if (livePreviewURL) {\n res.livePreviewURL = livePreviewURL\n }\n }\n\n if (returnPreviewURL) {\n const { previewURL } = await handlePreview({\n collectionSlug,\n config,\n data,\n globalSlug,\n req,\n })\n\n // Important: only set this when not undefined,\n // Otherwise it will travel through the network as `$undefined`\n if (previewURL) {\n res.previewURL = previewURL\n }\n }\n\n return res\n}\n"],"mappings":"AASA,SAASA,cAAc,EAAEC,YAAY,EAAEC,iBAAiB,QAA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CAAe,EAAEgB,MAAA,EAAQkC,MAAA,IAAU5C,SAAA,CAAU6C,IAAI,EAAE;MACzET,eAAA,CAAgBS,IAAI,GAAG7C,SAAA,CAAU6C,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAIlC,gBAAA,EAAkB;IACpBkC,iBAAA,GAAoB,MAAMtE,sBAAA,CAAuB;MAC/Ce,EAAA;MACAG,cAAA;MACAO,UAAA;MACAnB,GAAA;MACAqC;IACF;EACF;EAEA,IAAI4B,oBAAA;EAEJ,IAAItD,iBAAA,IAAqBa,iBAAA,KAAsBZ,cAAC,IAAkBH,EAAA,IAAOU,UAAS,GAAI;IACpF8C,oBAAA,GAAuB,MAAMpE,oBAAA,CAAqB;MAChDY,EAAA;MACAG,cAAA;MACAO,UAAA;MACAK,iBAAA;MACAxB;IACF;EACF;EAEA,MAAMC,GAAA,GAAmC;IACvCiE,WAAA,EAAaF,iBAAA;IACbG,cAAA,EAAgBF,oBAAA;IAChBG,KAAA,EAAOd;EACT;EAEA,IAAIzB,oBAAA,EAAsB;IACxB,MAAM;MAAEwC;IAAc,CAAE,GAAG,MAAM1E,iBAAA,CAAkB;MACjDiB,cAAA;MACAgB,MAAA;MACAf,IAAA;MACAM,UAAA;MACAnB;IACF;IAEA;IACA;IACA,IAAIqE,cAAA,EAAgB;MAClBpE,GAAA,CAAIoE,cAAc,GAAGA,cAAA;IACvB;EACF;EAEA,IAAItC,gBAAA,EAAkB;IACpB,MAAM;MAAEuC;IAAU,CAAE,GAAG,MAAM1E,aAAA,CAAc;MACzCgB,cAAA;MACAgB,MAAA;MACAf,IAAA;MACAM,UAAA;MACAnB;IACF;IAEA;IACA;IACA,IAAIsE,UAAA,EAAY;MACdrE,GAAA,CAAIqE,UAAU,GAAGA,UAAA;IACnB;EACF;EAEA,OAAOrE,GAAA;AACT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"buildFormState.js","names":["canAccessAdmin","formatErrors","UnauthorizedError","getSelectMode","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","handleLivePreview","handlePreview","handleStaleDataCheck","buildFormStateHandler","args","req","res","buildFormState","err","payload","logger","error","msg","message","id","idFromArgs","checkForStaleData","collectionSlug","data","incomingData","docPermissions","docPreferences","documentFormState","formState","globalSlug","initialBlockData","initialBlockFormState","mockRSCs","operation","originalUpdatedAt","readOnly","renderAllFields","i18n","config","returnLivePreviewURL","returnLockStatus","returnPreviewURL","widgetSlug","schemaPath","select","skipClientConfigAuth","skipValidation","updateLastEdited","user","selectMode","undefined","Error","schemaMap","clientSchemaMap","importMap","fieldOrEntityConfig","get","fields","length","type","documentData","blockData","Array","isArray","formStateResult","clientFieldSchemaMap","fieldSchemaMap","permissions","preferences","previousFormState","renderFieldFn","renderFieldArgs","collections","upload","file","lockedStateResult","staleDataStateResult","lockedState","staleDataState","state","livePreviewURL","previewURL"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type {\n BuildFormStateArgs,\n ClientConfig,\n ClientUser,\n ErrorResult,\n FormState,\n ServerFunction,\n} from 'payload'\n\nimport { canAccessAdmin, formatErrors, UnauthorizedError } from 'payload'\nimport { getSelectMode, reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { getClientConfig } from './getClientConfig.js'\nimport { getClientSchemaMap } from './getClientSchemaMap.js'\nimport { getSchemaMap } from './getSchemaMap.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\nimport { handleLivePreview } from './handleLivePreview.js'\nimport { handlePreview } from './handlePreview.js'\nimport { handleStaleDataCheck } from './handleStaleDataCheck.js'\n\nexport type LockedState = {\n isLocked: boolean\n lastEditedAt: string\n user?: ClientUser | number | string\n}\n\nexport type StaleDataState = {\n currentUpdatedAt: string\n isStale: boolean\n}\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n livePreviewURL?: string\n lockedState?: LockedState\n previewURL?: string\n staleDataState?: StaleDataState\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n livePreviewURL?: never\n lockedState?: never\n previewURL?: never\n staleDataState?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler: ServerFunction<\n BuildFormStateArgs,\n Promise<BuildFormStateResult>\n> = async (args) => {\n const { req } = args\n\n try {\n await canAccessAdmin({ req })\n const res = await buildFormState(args)\n\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n throw new UnauthorizedError()\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n checkForStaleData,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n documentFormState,\n formState,\n globalSlug,\n initialBlockData,\n initialBlockFormState,\n mockRSCs,\n operation,\n originalUpdatedAt,\n readOnly,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLivePreviewURL,\n returnLockStatus,\n returnPreviewURL,\n widgetSlug,\n schemaPath = collectionSlug || globalSlug || widgetSlug,\n select,\n skipClientConfigAuth,\n skipValidation,\n updateLastEdited,\n user,\n } = args\n\n const selectMode = select ? getSelectMode(select) : undefined\n\n if (!collectionSlug && !globalSlug && !widgetSlug) {\n throw new Error('Either collectionSlug, globalSlug, or widgetSlug must be provided')\n }\n\n const schemaMap = getSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n widgetSlug,\n })\n\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug,\n config: getClientConfig({\n config,\n i18n,\n importMap: req.payload.importMap,\n user: skipClientConfigAuth ? true : req.user,\n }),\n globalSlug,\n i18n,\n payload,\n schemaMap,\n widgetSlug,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = schemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is form state but no data, deduce data from that form state, e.g. on initial load\n // Otherwise, use the incoming data as the source of truth, e.g. on subsequent saves\n const data = incomingData || reduceFieldsToValues(formState, true)\n\n let documentData = undefined\n\n if (documentFormState) {\n documentData = reduceFieldsToValues(documentFormState, true)\n }\n\n let blockData = initialBlockData\n\n if (initialBlockFormState) {\n blockData = reduceFieldsToValues(initialBlockFormState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n // Ensure data.id is present during form state requests, where the data\n // is passed from the client as an argument, without the ID\n if (!data.id && id) {\n data.id = id\n }\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug,\n data,\n documentData,\n fields,\n fieldSchemaMap: schemaMap,\n initialBlockData: blockData,\n mockRSCs,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n readOnly,\n renderAllFields,\n renderFieldFn: (renderFieldArgs) => renderField({ ...renderFieldArgs, user }),\n req,\n schemaPath,\n select,\n selectMode,\n skipValidation,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult: LockedState | undefined\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n let staleDataStateResult: StaleDataState | undefined\n\n if (checkForStaleData && originalUpdatedAt && ((collectionSlug && id) || globalSlug)) {\n staleDataStateResult = await handleStaleDataCheck({\n id,\n collectionSlug,\n globalSlug,\n originalUpdatedAt,\n req,\n })\n }\n\n const res: BuildFormStateSuccessResult = {\n lockedState: lockedStateResult,\n staleDataState: staleDataStateResult,\n state: formStateResult,\n }\n\n if (returnLivePreviewURL) {\n const { livePreviewURL } = await handleLivePreview({\n collectionSlug,\n config,\n data,\n globalSlug,\n req,\n })\n\n // Important: only set this when not undefined,\n // Otherwise it will travel through the network as `$undefined`\n if (livePreviewURL) {\n res.livePreviewURL = livePreviewURL\n }\n }\n\n if (returnPreviewURL) {\n const { previewURL } = await handlePreview({\n collectionSlug,\n config,\n data,\n globalSlug,\n req,\n })\n\n // Important: only set this when not undefined,\n // Otherwise it will travel through the network as `$undefined`\n if (previewURL) {\n res.previewURL = previewURL\n }\n }\n\n return res\n}\n"],"mappings":"AASA,SAASA,cAAc,EAAEC,YAAY,EAAEC,iBAAiB,QAAQ;AAChE,SAASC,aAAa,EAAEC,oBAAoB,QAAQ;AAEpD,SAASC,uBAAuB,QAAQ;AACxC,SAASC,WAAW,QAAQ;AAC5B,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,iBAAiB,QAAQ;AAClC,SAASC,aAAa,QAAQ;AAC9B,SAASC,oBAAoB,QAA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MAAMvE,sBAAA,CAAuB;MAC/Ce,EAAA;MACAG,cAAA;MACAO,UAAA;MACAnB,GAAA;MACAqC;IACF;EACF;EAEA,IAAI6B,oBAAA;EAEJ,IAAIvD,iBAAA,IAAqBa,iBAAA,KAAsBZ,cAAC,IAAkBH,EAAA,IAAOU,UAAS,GAAI;IACpF+C,oBAAA,GAAuB,MAAMrE,oBAAA,CAAqB;MAChDY,EAAA;MACAG,cAAA;MACAO,UAAA;MACAK,iBAAA;MACAxB;IACF;EACF;EAEA,MAAMC,GAAA,GAAmC;IACvCkE,WAAA,EAAaF,iBAAA;IACbG,cAAA,EAAgBF,oBAAA;IAChBG,KAAA,EAAOf;EACT;EAEA,IAAIzB,oBAAA,EAAsB;IACxB,MAAM;MAAEyC;IAAc,CAAE,GAAG,MAAM3E,iBAAA,CAAkB;MACjDiB,cAAA;MACAgB,MAAA;MACAf,IAAA;MACAM,UAAA;MACAnB;IACF;IAEA;IACA;IACA,IAAIsE,cAAA,EAAgB;MAClBrE,GAAA,CAAIqE,cAAc,GAAGA,cAAA;IACvB;EACF;EAEA,IAAIvC,gBAAA,EAAkB;IACpB,MAAM;MAAEwC;IAAU,CAAE,GAAG,MAAM3E,aAAA,CAAc;MACzCgB,cAAA;MACAgB,MAAA;MACAf,IAAA;MACAM,UAAA;MACAnB;IACF;IAEA;IACA;IACA,IAAIuE,UAAA,EAAY;MACdtE,GAAA,CAAIsE,UAAU,GAAGA,UAAA;IACnB;EACF;EAEA,OAAOtE,GAAA;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedulePublishHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/schedulePublishHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAA;AAItF,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAA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B,CAAA;AAED,eAAO,MAAM,kCAAkC,EAAE,cAAc,CAC7D,sCAAsC,EACtC,OAAO,CAAC,aAAa,EAAE,CAAC,CA0DzB,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,cAAc,CAAC,0BAA0B,CA+D7E,CAAA"}
|
|
@@ -106,7 +106,10 @@ export const schedulePublishHandler = async ({
|
|
|
106
106
|
global,
|
|
107
107
|
locale: localeToPublish,
|
|
108
108
|
timezone,
|
|
109
|
-
user: user.
|
|
109
|
+
user: user && user.collection ? {
|
|
110
|
+
relationTo: user.collection,
|
|
111
|
+
value: user.id
|
|
112
|
+
} : undefined
|
|
110
113
|
},
|
|
111
114
|
task: 'schedulePublish',
|
|
112
115
|
waitUntil: date
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedulePublishHandler.js","names":["canAccessAdmin","docAccessOperation","docAccessOperationGlobal","Forbidden","hasScheduledPublishEnabled","buildUpcomingScheduleWhere","getUpcomingScheduledPublishHandler","id","collectionSlug","globalSlug","req","payload","collectionConfig","collections","config","undefined","globalConfig","globals","find","slug","entityConfig","hasValidTarget","Boolean","t","hasPublishPermission","collection","data","_status","update","docs","db","limit","sort","where","map","job","input","type","locale","timezone","waitUntil","schedulePublishHandler","date","deleteID","doc","global","localeToPublish","i18n","user","delete","and","equals","taskSlug","jobs","queue","
|
|
1
|
+
{"version":3,"file":"schedulePublishHandler.js","names":["canAccessAdmin","docAccessOperation","docAccessOperationGlobal","Forbidden","hasScheduledPublishEnabled","buildUpcomingScheduleWhere","getUpcomingScheduledPublishHandler","id","collectionSlug","globalSlug","req","payload","collectionConfig","collections","config","undefined","globalConfig","globals","find","slug","entityConfig","hasValidTarget","Boolean","t","hasPublishPermission","collection","data","_status","update","docs","db","limit","sort","where","map","job","input","type","locale","timezone","waitUntil","schedulePublishHandler","date","deleteID","doc","global","localeToPublish","i18n","user","delete","and","equals","taskSlug","jobs","queue","relationTo","value","task","err","error","logger","message"],"sources":["../../src/utilities/schedulePublishHandler.ts"],"sourcesContent":["import type { SchedulePublishTaskInput, ServerFunction } from 'payload'\n\nimport { canAccessAdmin, docAccessOperation, docAccessOperationGlobal, Forbidden } from 'payload'\nimport { hasScheduledPublishEnabled } from 'payload/shared'\n\nimport type { UpcomingEvent } from '../elements/PublishButton/ScheduleDrawer/types.js'\n\nimport { buildUpcomingScheduleWhere } from '../elements/PublishButton/ScheduleDrawer/buildUpcomingScheduleWhere.js'\n\nexport type SchedulePublishHandlerArgs = {\n date?: Date\n /**\n * The job id to delete to remove a scheduled publish event\n */\n deleteID?: number | string\n localeToPublish?: string\n timezone?: string\n} & Pick<SchedulePublishTaskInput, 'doc' | 'global' | 'type'>\n\nexport type GetUpcomingScheduledPublishHandlerArgs = {\n collectionSlug?: string\n globalSlug?: string\n id?: number | string\n}\n\nexport const getUpcomingScheduledPublishHandler: ServerFunction<\n GetUpcomingScheduledPublishHandlerArgs,\n Promise<UpcomingEvent[]>\n> = async ({ id, collectionSlug, globalSlug, req }) => {\n const { payload } = req\n\n await canAccessAdmin({ req })\n\n const collectionConfig = collectionSlug ? payload.collections[collectionSlug]?.config : undefined\n const globalConfig = globalSlug\n ? payload.config.globals.find(({ slug }) => slug === globalSlug)\n : undefined\n const entityConfig = collectionConfig || globalConfig\n const hasValidTarget = Boolean(\n entityConfig &&\n hasScheduledPublishEnabled(entityConfig) &&\n ((collectionConfig && id !== undefined && !globalSlug) || (globalConfig && !collectionSlug)),\n )\n\n if (!hasValidTarget) {\n throw new Forbidden(req.t)\n }\n\n const hasPublishPermission = collectionConfig\n ? (\n await docAccessOperation({\n id,\n collection: { config: collectionConfig },\n data: { _status: 'published' },\n req,\n })\n ).update\n : (\n await docAccessOperationGlobal({\n data: { _status: 'published' },\n globalConfig,\n req,\n })\n ).update\n\n if (!hasPublishPermission) {\n throw new Forbidden(req.t)\n }\n\n const { docs } = await payload.db.find<UpcomingEvent>({\n collection: 'payload-jobs',\n limit: 0,\n sort: 'waitUntil',\n where: buildUpcomingScheduleWhere({ id, collectionSlug, globalSlug }),\n })\n\n return docs.map((job) => ({\n id: job.id,\n input: {\n type: job.input?.type === 'unpublish' ? 'unpublish' : 'publish',\n locale: job.input?.locale,\n timezone: job.input?.timezone,\n },\n waitUntil: job.waitUntil,\n }))\n}\n\nexport const schedulePublishHandler: ServerFunction<SchedulePublishHandlerArgs> = async ({\n type,\n date,\n deleteID,\n doc,\n global,\n localeToPublish,\n req,\n timezone,\n}) => {\n const { i18n, payload, user } = req\n\n await canAccessAdmin({ req })\n\n try {\n if (deleteID) {\n await payload.delete({\n collection: 'payload-jobs',\n req,\n where: {\n and: [{ id: { equals: deleteID } }, { taskSlug: { equals: 'schedulePublish' } }],\n },\n })\n }\n\n await payload.jobs.queue({\n input: {\n type,\n doc,\n global,\n locale: localeToPublish,\n timezone,\n user:\n user && user.collection\n ? {\n relationTo: user.collection,\n value: user.id,\n }\n : undefined,\n },\n task: 'schedulePublish',\n waitUntil: date,\n })\n } catch (err) {\n let error\n\n if (deleteID) {\n error = `Error deleting scheduled publish event with ID ${deleteID}`\n } else {\n error = `Error scheduling ${type} for `\n if (doc) {\n error += `document with ID ${doc.value} in collection ${doc.relationTo}`\n }\n }\n\n payload.logger.error({ err }, error)\n\n return {\n error,\n }\n }\n\n return { message: i18n.t('general:success') }\n}\n"],"mappings":"AAEA,SAASA,cAAc,EAAEC,kBAAkB,EAAEC,wBAAwB,EAAEC,SAAS,QAAQ;AACxF,SAASC,0BAA0B,QAAQ;AAI3C,SAASC,0BAA0B,QAAQ;AAkB3C,OAAO,MAAMC,kCAAA,GAGT,MAAAA,CAAO;EAAEC,EAAE;EAAEC,cAAc;EAAEC,UAAU;EAAEC;AAAG,CAAE;EAChD,MAAM;IAAEC;EAAO,CAAE,GAAGD,GAAA;EAEpB,MAAMV,cAAA,CAAe;IAAEU;EAAI;EAE3B,MAAME,gBAAA,GAAmBJ,cAAA,GAAiBG,OAAA,CAAQE,WAAW,CAACL,cAAA,CAAe,EAAEM,MAAA,GAASC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DhB,QAAA,EAAU;IACtE,OAAO;MACLgB,KAAA,GAAQ,oBAAoBtB,IAAA,OAAW;MACvC,IAAIO,GAAA,EAAK;QACPe,KAAA,IAAS,oBAAoBf,GAAA,CAAIY,KAAK,kBAAkBZ,GAAA,CAAIW,UAAU,EAAE;MAC1E;IACF;IAEA5C,OAAA,CAAQiD,MAAM,CAACD,KAAK,CAAC;MAAED;IAAI,GAAGC,KAAA;IAE9B,OAAO;MACLA;IACF;EACF;EAEA,OAAO;IAAEE,OAAA,EAASd,IAAA,CAAKxB,CAAC,CAAC;EAAmB;AAC9C","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIKey.d.ts","sourceRoot":"","sources":["../../../../src/views/Edit/Auth/APIKey.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"APIKey.d.ts","sourceRoot":"","sources":["../../../../src/views/Edit/Auth/APIKey.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA+C,MAAM,OAAO,CAAA;AAwBnE,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAgUvF,CAAA"}
|
|
@@ -1,41 +1,65 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useModal } from '@faceless-ui/modal';
|
|
4
5
|
import { getTranslation } from '@payloadcms/translations';
|
|
5
|
-
import { text } from 'payload/shared';
|
|
6
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
6
|
+
import { formatAdminURL, text } from 'payload/shared';
|
|
7
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import { toast } from 'sonner';
|
|
7
9
|
import { v4 as uuidv4 } from 'uuid';
|
|
8
10
|
import { Button } from '../../../elements/Button/index.js';
|
|
11
|
+
import { ConfirmationModal } from '../../../elements/ConfirmationModal/index.js';
|
|
9
12
|
import { CopyToClipboard } from '../../../elements/CopyToClipboard/index.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
13
|
+
import { Spinner } from '../../../elements/Spinner/index.js';
|
|
14
|
+
import { FieldDescription } from '../../../fields/FieldDescription/index.js';
|
|
15
|
+
import { useFormFields, useFormModified } from '../../../forms/Form/context.js';
|
|
12
16
|
import { useField } from '../../../forms/useField/index.js';
|
|
13
17
|
import { EyeIcon } from '../../../icons/Eye/index.js';
|
|
18
|
+
import { RefreshIcon } from '../../../icons/Refresh/index.js';
|
|
14
19
|
import { useConfig } from '../../../providers/Config/index.js';
|
|
15
20
|
import { useDocumentInfo } from '../../../providers/DocumentInfo/index.js';
|
|
21
|
+
import { useLocale } from '../../../providers/Locale/index.js';
|
|
16
22
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
23
|
+
import { APIKeyGenerationModal } from './APIKeyGenerationModal.js';
|
|
17
24
|
const path = 'apiKey';
|
|
18
25
|
const baseClass = 'api-key';
|
|
19
26
|
const fieldBaseClass = 'field-type';
|
|
27
|
+
const maskedAPIKey = '•'.repeat(24);
|
|
20
28
|
export const APIKey = ({
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
readOnly,
|
|
30
|
+
reveal
|
|
23
31
|
}) => {
|
|
24
|
-
const [initialAPIKey] = useState(uuidv4());
|
|
25
32
|
const [highlightedField, setHighlightedField] = useState(false);
|
|
33
|
+
const [hasUpdatedPersistedAPIKey, setHasUpdatedPersistedAPIKey] = useState(null);
|
|
34
|
+
const [isRevealing, setIsRevealing] = useState(false);
|
|
35
|
+
const [revealedKey, setRevealedKey] = useState(null);
|
|
36
|
+
const [showCopyWarning, setShowCopyWarning] = useState(false);
|
|
26
37
|
const [showKey, setShowKey] = useState(false);
|
|
38
|
+
const modified = useFormModified();
|
|
39
|
+
const wasModified = useRef(modified);
|
|
27
40
|
const {
|
|
28
41
|
i18n,
|
|
29
42
|
t
|
|
30
43
|
} = useTranslation();
|
|
44
|
+
const {
|
|
45
|
+
toggleModal
|
|
46
|
+
} = useModal();
|
|
31
47
|
const {
|
|
32
48
|
config,
|
|
33
49
|
getEntityConfig
|
|
34
50
|
} = useConfig();
|
|
35
51
|
const {
|
|
36
|
-
|
|
52
|
+
id,
|
|
53
|
+
collectionSlug,
|
|
54
|
+
setData,
|
|
55
|
+
setLastUpdateTime
|
|
37
56
|
} = useDocumentInfo();
|
|
38
|
-
const
|
|
57
|
+
const {
|
|
58
|
+
code: locale
|
|
59
|
+
} = useLocale();
|
|
60
|
+
const revokeModalSlug = `revoke-api-key-${id}`;
|
|
61
|
+
const hasAPIKey = useFormFields(([fields]) => fields && fields.hasAPIKey || null);
|
|
62
|
+
const dispatchFields_0 = useFormFields(([, dispatchFields]) => dispatchFields);
|
|
39
63
|
const apiKeyField = getEntityConfig({
|
|
40
64
|
collectionSlug
|
|
41
65
|
})?.fields?.find(field => 'name' in field && field.name === 'apiKey');
|
|
@@ -59,7 +83,16 @@ export const APIKey = ({
|
|
|
59
83
|
},
|
|
60
84
|
siblingData: {}
|
|
61
85
|
});
|
|
62
|
-
const
|
|
86
|
+
const {
|
|
87
|
+
setValue,
|
|
88
|
+
value
|
|
89
|
+
} = useField({
|
|
90
|
+
path,
|
|
91
|
+
validate
|
|
92
|
+
});
|
|
93
|
+
const apiKeyValue = revealedKey || value;
|
|
94
|
+
const hasPersistedAPIKey = hasUpdatedPersistedAPIKey ?? Boolean(hasAPIKey?.value);
|
|
95
|
+
const canRevealPersistedAPIKey = reveal && hasPersistedAPIKey && !revealedKey;
|
|
63
96
|
const apiKeyLabel = useMemo(() => {
|
|
64
97
|
let label = 'API Key';
|
|
65
98
|
if (apiKeyField?.label) {
|
|
@@ -67,77 +100,201 @@ export const APIKey = ({
|
|
|
67
100
|
}
|
|
68
101
|
return getTranslation(label, i18n);
|
|
69
102
|
}, [apiKeyField, i18n]);
|
|
70
|
-
const APIKeyLabel = useMemo(() => /*#__PURE__*/_jsxs("label", {
|
|
71
|
-
className: `${baseClass}__label field-label`,
|
|
72
|
-
htmlFor: "apiKey",
|
|
73
|
-
children: [/*#__PURE__*/_jsx("span", {
|
|
74
|
-
children: apiKeyLabel
|
|
75
|
-
}), /*#__PURE__*/_jsx(CopyToClipboard, {
|
|
76
|
-
value: apiKeyValue
|
|
77
|
-
})]
|
|
78
|
-
}), [apiKeyLabel, apiKeyValue]);
|
|
79
|
-
const fieldType = useField({
|
|
80
|
-
path: 'apiKey',
|
|
81
|
-
validate
|
|
82
|
-
});
|
|
83
103
|
const highlightField = () => {
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
setHighlightedField(true);
|
|
105
|
+
};
|
|
106
|
+
const updateKey = async apiKey => {
|
|
107
|
+
if (!id) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const response = await fetch(formatAdminURL({
|
|
112
|
+
apiRoute: config.routes.api,
|
|
113
|
+
path: `/${collectionSlug}/${encodeURIComponent(String(id))}?depth=0&fallback-locale=null&locale=${locale}`
|
|
114
|
+
}), {
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
apiKey,
|
|
117
|
+
// The `enableAPIKey` field is for backward compatibility only and will be removed in v4.
|
|
118
|
+
enableAPIKey: Boolean(apiKey)
|
|
119
|
+
}),
|
|
120
|
+
headers: {
|
|
121
|
+
'Content-Type': 'application/json'
|
|
122
|
+
},
|
|
123
|
+
method: 'PATCH'
|
|
124
|
+
});
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
throw new Error('API key update failed');
|
|
127
|
+
}
|
|
128
|
+
const result = await response.json();
|
|
129
|
+
setHasUpdatedPersistedAPIKey(Boolean(apiKey));
|
|
130
|
+
dispatchFields_0({
|
|
131
|
+
type: 'REMOVE',
|
|
132
|
+
path
|
|
133
|
+
});
|
|
134
|
+
// The `enableAPIKey` field is for backward compatibility only and will be removed in v4.
|
|
135
|
+
dispatchFields_0({
|
|
136
|
+
type: 'REMOVE',
|
|
137
|
+
path: 'enableAPIKey'
|
|
138
|
+
});
|
|
139
|
+
if (result.doc?.updatedAt) {
|
|
140
|
+
setData(result.doc);
|
|
141
|
+
setLastUpdateTime(new Date(result.doc.updatedAt).getTime());
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
} catch {
|
|
145
|
+
toast.error('Failed to update the API key.');
|
|
146
|
+
return false;
|
|
86
147
|
}
|
|
87
|
-
setTimeout(() => {
|
|
88
|
-
setHighlightedField(true);
|
|
89
|
-
}, 1);
|
|
90
148
|
};
|
|
91
|
-
const {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
149
|
+
const generateKey = async () => {
|
|
150
|
+
const key = uuidv4();
|
|
151
|
+
if (!id) {
|
|
152
|
+
setValue(key, true);
|
|
153
|
+
setShowCopyWarning(true);
|
|
154
|
+
setShowKey(true);
|
|
155
|
+
highlightField();
|
|
156
|
+
return true;
|
|
98
157
|
}
|
|
99
|
-
if (!
|
|
100
|
-
|
|
158
|
+
if (!(await updateKey(key))) {
|
|
159
|
+
return false;
|
|
101
160
|
}
|
|
102
|
-
|
|
161
|
+
setRevealedKey(key);
|
|
162
|
+
setShowCopyWarning(true);
|
|
163
|
+
setShowKey(true);
|
|
164
|
+
highlightField();
|
|
165
|
+
return true;
|
|
166
|
+
};
|
|
167
|
+
const revokeKey = async () => {
|
|
168
|
+
if (!(await updateKey(null))) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
setRevealedKey(null);
|
|
172
|
+
setHasUpdatedPersistedAPIKey(false);
|
|
173
|
+
setHighlightedField(false);
|
|
174
|
+
setShowCopyWarning(false);
|
|
175
|
+
setShowKey(false);
|
|
176
|
+
toast.success('API key revoked successfully.');
|
|
177
|
+
};
|
|
178
|
+
const revealKey = async () => {
|
|
179
|
+
if (isRevealing) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
setIsRevealing(true);
|
|
183
|
+
try {
|
|
184
|
+
const response_0 = await fetch(formatAdminURL({
|
|
185
|
+
apiRoute: config.routes.api,
|
|
186
|
+
path: `/${collectionSlug}/${encodeURIComponent(String(id))}/api-key/reveal`
|
|
187
|
+
}), {
|
|
188
|
+
method: 'POST'
|
|
189
|
+
});
|
|
190
|
+
if (!response_0.ok) {
|
|
191
|
+
toast.error('Failed to reveal the API key.');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const result_0 = await response_0.json();
|
|
195
|
+
setRevealedKey(result_0.apiKey);
|
|
196
|
+
setShowCopyWarning(false);
|
|
197
|
+
setShowKey(true);
|
|
198
|
+
} catch {
|
|
199
|
+
toast.error('Failed to reveal the API key.');
|
|
200
|
+
} finally {
|
|
201
|
+
setIsRevealing(false);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
103
204
|
useEffect(() => {
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
205
|
+
if (wasModified.current && !modified && apiKeyValue) {
|
|
206
|
+
setHasUpdatedPersistedAPIKey(true);
|
|
207
|
+
setHighlightedField(false);
|
|
208
|
+
setRevealedKey(null);
|
|
209
|
+
setShowCopyWarning(false);
|
|
210
|
+
dispatchFields_0({
|
|
211
|
+
type: 'REMOVE',
|
|
212
|
+
path
|
|
213
|
+
});
|
|
214
|
+
setShowKey(false);
|
|
108
215
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
216
|
+
wasModified.current = modified;
|
|
217
|
+
}, [apiKeyValue, dispatchFields_0, modified]);
|
|
113
218
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
114
219
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
115
220
|
className: [fieldBaseClass, 'api-key', 'read-only'].filter(Boolean).join(' '),
|
|
116
|
-
children: [
|
|
117
|
-
className: `${baseClass}
|
|
221
|
+
children: [/*#__PURE__*/_jsxs("label", {
|
|
222
|
+
className: `${baseClass}__label field-label`,
|
|
223
|
+
htmlFor: "apiKey",
|
|
224
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
225
|
+
children: apiKeyLabel
|
|
226
|
+
}), apiKeyValue && /*#__PURE__*/_jsx(CopyToClipboard, {
|
|
227
|
+
value: apiKeyValue
|
|
228
|
+
})]
|
|
229
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
230
|
+
className: [`${baseClass}__input-wrap`, !readOnly && hasPersistedAPIKey && `${baseClass}__input-wrap--has-regenerate`, highlightedField && `${baseClass}__input-wrap--highlighted`].filter(Boolean).join(' '),
|
|
118
231
|
children: [/*#__PURE__*/_jsx("input", {
|
|
119
232
|
"aria-label": apiKeyLabel,
|
|
120
|
-
className: highlightedField ? 'highlight' : undefined,
|
|
121
233
|
disabled: true,
|
|
122
234
|
id: "apiKey",
|
|
123
235
|
name: "apiKey",
|
|
124
|
-
type: showKey ? '
|
|
125
|
-
value:
|
|
126
|
-
}), /*#__PURE__*/
|
|
236
|
+
type: apiKeyValue && !showKey ? 'password' : 'text',
|
|
237
|
+
value: apiKeyValue || (hasPersistedAPIKey ? maskedAPIKey : '')
|
|
238
|
+
}), (apiKeyValue || canRevealPersistedAPIKey || !readOnly && hasPersistedAPIKey) && /*#__PURE__*/_jsxs("div", {
|
|
127
239
|
className: `${baseClass}__toggle-button-wrap`,
|
|
128
|
-
children: /*#__PURE__*/_jsx(Button, {
|
|
240
|
+
children: [(apiKeyValue || canRevealPersistedAPIKey) && /*#__PURE__*/_jsx(Button, {
|
|
241
|
+
"aria-label": canRevealPersistedAPIKey ? 'Reveal API key' : 'Toggle API key visibility',
|
|
129
242
|
buttonStyle: "none",
|
|
130
|
-
className: `${baseClass}
|
|
131
|
-
|
|
243
|
+
className: [`${baseClass}__visibility-button`, !readOnly && hasPersistedAPIKey && `${baseClass}__visibility-button--with-regenerate`].filter(Boolean).join(' '),
|
|
244
|
+
disabled: isRevealing,
|
|
245
|
+
extraButtonProps: {
|
|
246
|
+
'aria-busy': isRevealing
|
|
247
|
+
},
|
|
248
|
+
icon: isRevealing ? /*#__PURE__*/_jsx(Spinner, {
|
|
249
|
+
loadingText: null,
|
|
250
|
+
size: "sm"
|
|
251
|
+
}) : /*#__PURE__*/_jsx(EyeIcon, {
|
|
132
252
|
active: showKey
|
|
133
253
|
}),
|
|
134
|
-
|
|
135
|
-
|
|
254
|
+
id: canRevealPersistedAPIKey ? 'reveal-api-key' : 'toggle-api-key-visibility',
|
|
255
|
+
onClick: canRevealPersistedAPIKey ? revealKey : () => setShowKey(previous => !previous)
|
|
256
|
+
}), !readOnly && hasPersistedAPIKey && /*#__PURE__*/_jsx(APIKeyGenerationModal, {
|
|
257
|
+
highlightField: highlightField,
|
|
258
|
+
icon: /*#__PURE__*/_jsx(RefreshIcon, {}),
|
|
259
|
+
id: "regenerate-api-key",
|
|
260
|
+
setKey: generateKey
|
|
261
|
+
})]
|
|
136
262
|
})]
|
|
263
|
+
}), apiKeyValue && showCopyWarning && /*#__PURE__*/_jsx(FieldDescription, {
|
|
264
|
+
description: reveal ? 'Make sure to copy your API key. You may not have access to reveal it again.' : 'Make sure to copy your API key. It will not be displayed again.',
|
|
265
|
+
path: path
|
|
137
266
|
})]
|
|
138
|
-
}), !readOnly && /*#__PURE__*/_jsx(
|
|
267
|
+
}), !readOnly && !apiKeyValue && !hasPersistedAPIKey && (id ? /*#__PURE__*/_jsx(APIKeyGenerationModal, {
|
|
139
268
|
highlightField: highlightField,
|
|
140
|
-
|
|
269
|
+
id: "generate-api-key",
|
|
270
|
+
setKey: generateKey,
|
|
271
|
+
willInvalidateExistingKey: false
|
|
272
|
+
}) : /*#__PURE__*/_jsx(Button, {
|
|
273
|
+
buttonStyle: "secondary",
|
|
274
|
+
id: "generate-api-key",
|
|
275
|
+
onClick: () => void generateKey(),
|
|
276
|
+
size: "small",
|
|
277
|
+
children: t('authentication:generateNewAPIKey')
|
|
278
|
+
})), !readOnly && hasPersistedAPIKey && /*#__PURE__*/_jsxs("div", {
|
|
279
|
+
className: `${baseClass}__actions`,
|
|
280
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
281
|
+
buttonStyle: "secondary",
|
|
282
|
+
className: `${baseClass}__revoke-button`,
|
|
283
|
+
id: "revoke-api-key",
|
|
284
|
+
onClick: () => toggleModal(revokeModalSlug),
|
|
285
|
+
size: "small",
|
|
286
|
+
children: "Revoke API key"
|
|
287
|
+
}), /*#__PURE__*/_jsx(ConfirmationModal, {
|
|
288
|
+
body: /*#__PURE__*/_jsxs("span", {
|
|
289
|
+
children: ["Are you sure you want to revoke the API key for user ", /*#__PURE__*/_jsx("strong", {
|
|
290
|
+
children: id
|
|
291
|
+
}), "? The key will no longer be usable, and this action cannot be undone."]
|
|
292
|
+
}),
|
|
293
|
+
confirmLabel: "Revoke",
|
|
294
|
+
heading: "Revoke API key?",
|
|
295
|
+
modalSlug: revokeModalSlug,
|
|
296
|
+
onConfirm: revokeKey
|
|
297
|
+
})]
|
|
141
298
|
})]
|
|
142
299
|
});
|
|
143
300
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIKey.js","names":["getTranslation","text","React","useEffect","useMemo","useState","v4","uuidv4","Button","CopyToClipboard","GenerateConfirmation","useFormFields","useField","EyeIcon","useConfig","useDocumentInfo","useTranslation","path","baseClass","fieldBaseClass","APIKey","enabled","readOnly","initialAPIKey","highlightedField","setHighlightedField","showKey","setShowKey","i18n","t","config","getEntityConfig","collectionSlug","apiKey","fields","apiKeyField","find","field","name","validate","val","type","blockData","data","event","maxLength","minLength","preferences","req","payload","siblingData","apiKeyValue","value","apiKeyLabel","label","APIKeyLabel","_jsxs","className","htmlFor","_jsx","fieldType","highlightField","setTimeout","setValue","Fragment","filter","Boolean","join","undefined","disabled","id","buttonStyle","icon","active","onClick","prev","setKey"],"sources":["../../../../src/views/Edit/Auth/APIKey.tsx"],"sourcesContent":["'use client'\nimport type { PayloadRequest, TextFieldClient } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { text } from 'payload/shared'\nimport React, { useEffect, useMemo, useState } from 'react'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { Button } from '../../../elements/Button/index.js'\nimport { CopyToClipboard } from '../../../elements/CopyToClipboard/index.js'\nimport { GenerateConfirmation } from '../../../elements/GenerateConfirmation/index.js'\nimport { useFormFields } from '../../../forms/Form/context.js'\nimport { useField } from '../../../forms/useField/index.js'\nimport { EyeIcon } from '../../../icons/Eye/index.js'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../../providers/DocumentInfo/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\n\nconst path = 'apiKey'\nconst baseClass = 'api-key'\nconst fieldBaseClass = 'field-type'\n\nexport const APIKey: React.FC<{ readonly enabled: boolean; readonly readOnly?: boolean }> = ({\n enabled,\n readOnly,\n}) => {\n const [initialAPIKey] = useState(uuidv4())\n const [highlightedField, setHighlightedField] = useState(false)\n const [showKey, setShowKey] = useState(false)\n const { i18n, t } = useTranslation()\n const { config, getEntityConfig } = useConfig()\n const { collectionSlug } = useDocumentInfo()\n\n const apiKey = useFormFields(([fields]) => (fields && fields[path]) || null)\n\n const apiKeyField: TextFieldClient = getEntityConfig({ collectionSlug })?.fields?.find(\n (field) => 'name' in field && field.name === 'apiKey',\n ) as TextFieldClient\n\n const validate = (val) =>\n text(val, {\n name: 'apiKey',\n type: 'text',\n blockData: {},\n data: {},\n event: 'onChange',\n maxLength: 48,\n minLength: 24,\n path: ['apiKey'],\n preferences: { fields: {} },\n req: {\n payload: {\n config,\n },\n t,\n } as unknown as PayloadRequest,\n siblingData: {},\n })\n\n const apiKeyValue = apiKey?.value\n\n const apiKeyLabel = useMemo(() => {\n let label: Record<string, string> | string = 'API Key'\n\n if (apiKeyField?.label) {\n label = apiKeyField.label\n }\n\n return getTranslation(label, i18n)\n }, [apiKeyField, i18n])\n\n const APIKeyLabel = useMemo(\n () => (\n <label className={`${baseClass}__label field-label`} htmlFor=\"apiKey\">\n <span>{apiKeyLabel}</span>\n <CopyToClipboard value={apiKeyValue as string} />\n </label>\n ),\n [apiKeyLabel, apiKeyValue],\n )\n\n const fieldType = useField({\n path: 'apiKey',\n validate,\n })\n\n const highlightField = () => {\n if (highlightedField) {\n setHighlightedField(false)\n }\n setTimeout(() => {\n setHighlightedField(true)\n }, 1)\n }\n\n const { setValue, value } = fieldType\n\n useEffect(() => {\n if (!apiKeyValue && enabled) {\n setValue(initialAPIKey)\n }\n if (!enabled && apiKeyValue) {\n setValue(null)\n }\n }, [apiKeyValue, enabled, setValue, initialAPIKey])\n\n useEffect(() => {\n if (highlightedField) {\n setTimeout(() => {\n setHighlightedField(false)\n }, 10000)\n }\n }, [highlightedField])\n\n if (!enabled) {\n return null\n }\n\n return (\n <React.Fragment>\n <div className={[fieldBaseClass, 'api-key', 'read-only'].filter(Boolean).join(' ')}>\n {APIKeyLabel}\n <div className={`${baseClass}__input-wrap`}>\n <input\n aria-label={apiKeyLabel}\n className={highlightedField ? 'highlight' : undefined}\n disabled\n id=\"apiKey\"\n name=\"apiKey\"\n type={showKey ? 'text' : 'password'}\n value={(value as string) || ''}\n />\n <div className={`${baseClass}__toggle-button-wrap`}>\n <Button\n buttonStyle=\"none\"\n className={`${baseClass}__toggle-button`}\n icon={<EyeIcon active={showKey} />}\n onClick={() => setShowKey((prev) => !prev)}\n />\n </div>\n </div>\n </div>\n {!readOnly && (\n <GenerateConfirmation highlightField={highlightField} setKey={() => setValue(uuidv4())} />\n )}\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,IAAI,QAAQ;AACrB,OAAOC,KAAA,IAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACpD,SAASC,EAAA,IAAMC,MAAM,QAAQ;AAE7B,SAASC,MAAM,QAAQ;AACvB,SAASC,eAAe,QAAQ;AAChC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,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,GAAG;IACL;EACF,GAAG,CAACD,gBAAA,CAAiB;EAErB,IAAI,CAACH,OAAA,EAAS;IACZ,OAAO;EACT;EAEA,oBACEmC,KAAA,CAACtD,KAAA,CAAM8D,QAAQ;4BACbR,KAAA,CAAC;MAAIC,SAAA,EAAW,CAACtC,cAAA,EAAgB,WAAW,YAAY,CAAC8C,MAAM,CAACC,OAAA,EAASC,IAAI,CAAC;iBAC3EZ,WAAA,E,aACDC,KAAA,CAAC;QAAIC,SAAA,EAAW,GAAGvC,SAAA,cAAuB;gCACxCyC,IAAA,CAAC;UACC,cAAYN,WAAA;UACZI,SAAA,EAAWjC,gBAAA,GAAmB,cAAc4C,SAAA;UAC5CC,QAAQ;UACRC,EAAA,EAAG;UACHhC,IAAA,EAAK;UACLG,IAAA,EAAMf,OAAA,GAAU,SAAS;UACzB0B,KAAA,EAAOA,KAAC,IAAoB;yBAE9BO,IAAA,CAAC;UAAIF,SAAA,EAAW,GAAGvC,SAAA,sBAA+B;oBAChD,aAAAyC,IAAA,CAACnD,MAAA;YACC+D,WAAA,EAAY;YACZd,SAAA,EAAW,GAAGvC,SAAA,iBAA0B;YACxCsD,IAAA,eAAMb,IAAA,CAAC9C,OAAA;cAAQ4D,MAAA,EAAQ/C;;YACvBgD,OAAA,EAASA,CAAA,KAAM/C,UAAA,CAAYgD,IAAA,IAAS,CAACA,IAAA;;;;QAK5C,CAACrD,QAAA,iBACAqC,IAAA,CAACjD,oBAAA;MAAqBmD,cAAA,EAAgBA,cAAA;MAAgBe,MAAA,EAAQA,CAAA,KAAMb,QAAA,CAASxD,MAAA;;;AAIrF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"APIKey.js","names":["useModal","getTranslation","formatAdminURL","text","React","useEffect","useMemo","useRef","useState","toast","v4","uuidv4","Button","ConfirmationModal","CopyToClipboard","Spinner","FieldDescription","useFormFields","useFormModified","useField","EyeIcon","RefreshIcon","useConfig","useDocumentInfo","useLocale","useTranslation","APIKeyGenerationModal","path","baseClass","fieldBaseClass","maskedAPIKey","repeat","APIKey","readOnly","reveal","highlightedField","setHighlightedField","hasUpdatedPersistedAPIKey","setHasUpdatedPersistedAPIKey","isRevealing","setIsRevealing","revealedKey","setRevealedKey","showCopyWarning","setShowCopyWarning","showKey","setShowKey","modified","wasModified","i18n","t","toggleModal","config","getEntityConfig","id","collectionSlug","setData","setLastUpdateTime","code","locale","revokeModalSlug","hasAPIKey","fields","dispatchFields","apiKeyField","find","field","name","validate","val","type","blockData","data","event","maxLength","minLength","preferences","req","payload","siblingData","setValue","value","apiKeyValue","hasPersistedAPIKey","Boolean","canRevealPersistedAPIKey","apiKeyLabel","label","highlightField","updateKey","apiKey","response","fetch","apiRoute","routes","api","encodeURIComponent","String","body","JSON","stringify","enableAPIKey","headers","method","ok","Error","result","json","doc","updatedAt","Date","getTime","error","generateKey","key","revokeKey","success","revealKey","current","_jsxs","Fragment","className","filter","join","htmlFor","_jsx","disabled","buttonStyle","extraButtonProps","icon","loadingText","size","active","onClick","previous","setKey","description","willInvalidateExistingKey","confirmLabel","heading","modalSlug","onConfirm"],"sources":["../../../../src/views/Edit/Auth/APIKey.tsx"],"sourcesContent":["'use client'\nimport type { PayloadRequest, TextFieldClient } from 'payload'\n\nimport { useModal } from '@faceless-ui/modal'\nimport { getTranslation } from '@payloadcms/translations'\nimport { formatAdminURL, text } from 'payload/shared'\nimport React, { useEffect, useMemo, useRef, useState } from 'react'\nimport { toast } from 'sonner'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { Button } from '../../../elements/Button/index.js'\nimport { ConfirmationModal } from '../../../elements/ConfirmationModal/index.js'\nimport { CopyToClipboard } from '../../../elements/CopyToClipboard/index.js'\nimport { Spinner } from '../../../elements/Spinner/index.js'\nimport { FieldDescription } from '../../../fields/FieldDescription/index.js'\nimport { useFormFields, useFormModified } from '../../../forms/Form/context.js'\nimport { useField } from '../../../forms/useField/index.js'\nimport { EyeIcon } from '../../../icons/Eye/index.js'\nimport { RefreshIcon } from '../../../icons/Refresh/index.js'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../../providers/Locale/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { APIKeyGenerationModal } from './APIKeyGenerationModal.js'\n\nconst path = 'apiKey'\nconst baseClass = 'api-key'\nconst fieldBaseClass = 'field-type'\nconst maskedAPIKey = '•'.repeat(24)\n\nexport const APIKey: React.FC<{ readonly readOnly?: boolean; readonly reveal?: boolean }> = ({\n readOnly,\n reveal,\n}) => {\n const [highlightedField, setHighlightedField] = useState(false)\n const [hasUpdatedPersistedAPIKey, setHasUpdatedPersistedAPIKey] = useState<boolean | null>(null)\n const [isRevealing, setIsRevealing] = useState(false)\n const [revealedKey, setRevealedKey] = useState<null | string>(null)\n const [showCopyWarning, setShowCopyWarning] = useState(false)\n const [showKey, setShowKey] = useState(false)\n const modified = useFormModified()\n const wasModified = useRef(modified)\n const { i18n, t } = useTranslation()\n const { toggleModal } = useModal()\n const { config, getEntityConfig } = useConfig()\n const { id, collectionSlug, setData, setLastUpdateTime } = useDocumentInfo()\n const { code: locale } = useLocale()\n const revokeModalSlug = `revoke-api-key-${id}`\n\n const hasAPIKey = useFormFields(([fields]) => (fields && fields.hasAPIKey) || null)\n const dispatchFields = useFormFields(([, dispatchFields]) => dispatchFields)\n\n const apiKeyField: TextFieldClient = getEntityConfig({ collectionSlug })?.fields?.find(\n (field) => 'name' in field && field.name === 'apiKey',\n ) as TextFieldClient\n const validate = (val) =>\n text(val, {\n name: 'apiKey',\n type: 'text',\n blockData: {},\n data: {},\n event: 'onChange',\n maxLength: 48,\n minLength: 24,\n path: ['apiKey'],\n preferences: { fields: {} },\n req: {\n payload: {\n config,\n },\n t,\n } as unknown as PayloadRequest,\n siblingData: {},\n })\n\n const { setValue, value } = useField({\n path,\n validate,\n })\n const apiKeyValue = revealedKey || (value as null | string | undefined)\n const hasPersistedAPIKey =\n hasUpdatedPersistedAPIKey ?? Boolean(hasAPIKey?.value as boolean | undefined)\n const canRevealPersistedAPIKey = reveal && hasPersistedAPIKey && !revealedKey\n\n const apiKeyLabel = useMemo(() => {\n let label: Record<string, string> | string = 'API Key'\n\n if (apiKeyField?.label) {\n label = apiKeyField.label\n }\n\n return getTranslation(label, i18n)\n }, [apiKeyField, i18n])\n\n const highlightField = () => {\n setHighlightedField(true)\n }\n\n const updateKey = async (apiKey: null | string) => {\n if (!id) {\n return false\n }\n\n try {\n const response = await fetch(\n formatAdminURL({\n apiRoute: config.routes.api,\n path: `/${collectionSlug}/${encodeURIComponent(String(id))}?depth=0&fallback-locale=null&locale=${locale}`,\n }),\n {\n body: JSON.stringify({\n apiKey,\n // The `enableAPIKey` field is for backward compatibility only and will be removed in v4.\n enableAPIKey: Boolean(apiKey),\n }),\n headers: { 'Content-Type': 'application/json' },\n method: 'PATCH',\n },\n )\n\n if (!response.ok) {\n throw new Error('API key update failed')\n }\n\n const result = await response.json()\n\n setHasUpdatedPersistedAPIKey(Boolean(apiKey))\n dispatchFields({ type: 'REMOVE', path })\n // The `enableAPIKey` field is for backward compatibility only and will be removed in v4.\n dispatchFields({ type: 'REMOVE', path: 'enableAPIKey' })\n\n if (result.doc?.updatedAt) {\n setData(result.doc)\n setLastUpdateTime(new Date(result.doc.updatedAt).getTime())\n }\n\n return true\n } catch {\n toast.error('Failed to update the API key.')\n return false\n }\n }\n\n const generateKey = async () => {\n const key = uuidv4()\n\n if (!id) {\n setValue(key, true)\n setShowCopyWarning(true)\n setShowKey(true)\n highlightField()\n\n return true\n }\n\n if (!(await updateKey(key))) {\n return false\n }\n\n setRevealedKey(key)\n setShowCopyWarning(true)\n setShowKey(true)\n highlightField()\n\n return true\n }\n\n const revokeKey = async () => {\n if (!(await updateKey(null))) {\n return\n }\n\n setRevealedKey(null)\n setHasUpdatedPersistedAPIKey(false)\n setHighlightedField(false)\n setShowCopyWarning(false)\n setShowKey(false)\n toast.success('API key revoked successfully.')\n }\n\n const revealKey = async () => {\n if (isRevealing) {\n return\n }\n\n setIsRevealing(true)\n\n try {\n const response = await fetch(\n formatAdminURL({\n apiRoute: config.routes.api,\n path: `/${collectionSlug}/${encodeURIComponent(String(id))}/api-key/reveal`,\n }),\n { method: 'POST' },\n )\n\n if (!response.ok) {\n toast.error('Failed to reveal the API key.')\n return\n }\n\n const result = await response.json()\n\n setRevealedKey(result.apiKey)\n setShowCopyWarning(false)\n setShowKey(true)\n } catch {\n toast.error('Failed to reveal the API key.')\n } finally {\n setIsRevealing(false)\n }\n }\n\n useEffect(() => {\n if (wasModified.current && !modified && apiKeyValue) {\n setHasUpdatedPersistedAPIKey(true)\n setHighlightedField(false)\n setRevealedKey(null)\n setShowCopyWarning(false)\n dispatchFields({ type: 'REMOVE', path })\n setShowKey(false)\n }\n\n wasModified.current = modified\n }, [apiKeyValue, dispatchFields, modified])\n\n return (\n <React.Fragment>\n <div className={[fieldBaseClass, 'api-key', 'read-only'].filter(Boolean).join(' ')}>\n <label className={`${baseClass}__label field-label`} htmlFor=\"apiKey\">\n <span>{apiKeyLabel}</span>\n {apiKeyValue && <CopyToClipboard value={apiKeyValue} />}\n </label>\n <div\n className={[\n `${baseClass}__input-wrap`,\n !readOnly && hasPersistedAPIKey && `${baseClass}__input-wrap--has-regenerate`,\n highlightedField && `${baseClass}__input-wrap--highlighted`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <input\n aria-label={apiKeyLabel}\n disabled\n id=\"apiKey\"\n name=\"apiKey\"\n type={apiKeyValue && !showKey ? 'password' : 'text'}\n value={apiKeyValue || (hasPersistedAPIKey ? maskedAPIKey : '')}\n />\n {(apiKeyValue || canRevealPersistedAPIKey || (!readOnly && hasPersistedAPIKey)) && (\n <div className={`${baseClass}__toggle-button-wrap`}>\n {(apiKeyValue || canRevealPersistedAPIKey) && (\n <Button\n aria-label={\n canRevealPersistedAPIKey ? 'Reveal API key' : 'Toggle API key visibility'\n }\n buttonStyle=\"none\"\n className={[\n `${baseClass}__visibility-button`,\n !readOnly &&\n hasPersistedAPIKey &&\n `${baseClass}__visibility-button--with-regenerate`,\n ]\n .filter(Boolean)\n .join(' ')}\n disabled={isRevealing}\n extraButtonProps={{ 'aria-busy': isRevealing }}\n icon={\n isRevealing ? (\n <Spinner loadingText={null} size=\"sm\" />\n ) : (\n <EyeIcon active={showKey} />\n )\n }\n id={canRevealPersistedAPIKey ? 'reveal-api-key' : 'toggle-api-key-visibility'}\n onClick={\n canRevealPersistedAPIKey ? revealKey : () => setShowKey((previous) => !previous)\n }\n />\n )}\n {!readOnly && hasPersistedAPIKey && (\n <APIKeyGenerationModal\n highlightField={highlightField}\n icon={<RefreshIcon />}\n id=\"regenerate-api-key\"\n setKey={generateKey}\n />\n )}\n </div>\n )}\n </div>\n {apiKeyValue && showCopyWarning && (\n <FieldDescription\n description={\n reveal\n ? 'Make sure to copy your API key. You may not have access to reveal it again.'\n : 'Make sure to copy your API key. It will not be displayed again.'\n }\n path={path}\n />\n )}\n </div>\n {!readOnly &&\n !apiKeyValue &&\n !hasPersistedAPIKey &&\n (id ? (\n <APIKeyGenerationModal\n highlightField={highlightField}\n id=\"generate-api-key\"\n setKey={generateKey}\n willInvalidateExistingKey={false}\n />\n ) : (\n <Button\n buttonStyle=\"secondary\"\n id=\"generate-api-key\"\n onClick={() => void generateKey()}\n size=\"small\"\n >\n {t('authentication:generateNewAPIKey')}\n </Button>\n ))}\n {!readOnly && hasPersistedAPIKey && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"secondary\"\n className={`${baseClass}__revoke-button`}\n id=\"revoke-api-key\"\n onClick={() => toggleModal(revokeModalSlug)}\n size=\"small\"\n >\n Revoke API key\n </Button>\n <ConfirmationModal\n body={\n <span>\n Are you sure you want to revoke the API key for user <strong>{id}</strong>? The key\n will no longer be usable, and this action cannot be undone.\n </span>\n }\n confirmLabel=\"Revoke\"\n heading=\"Revoke API key?\"\n modalSlug={revokeModalSlug}\n onConfirm={revokeKey}\n />\n </div>\n )}\n </React.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AACnG,qBAAA;YACC8D,cAAA,EAAgBA,cAAA;YAChByC,IAAA,eAAMJ,IAAA,CAACxG,WAAA;YACPiC,EAAA,EAAG;YACHiF,MAAA,EAAQtB;;;UAMjB/B,WAAA,IAAevC,eAAA,iBACdkF,IAAA,CAAC7G,gBAAA;QACCwH,WAAA,EACEtG,MAAA,GACI,gFACA;QAENP,IAAA,EAAMA;;QAIX,CAACM,QAAA,IACA,CAACiD,WAAA,IACD,CAACC,kBAAA,KACA7B,EAAA,gBACCuE,IAAA,CAACnG,qBAAA;MACC8D,cAAA,EAAgBA,cAAA;MAChBlC,EAAA,EAAG;MACHiF,MAAA,EAAQtB,WAAA;MACRwB,yBAAA,EAA2B;sBAG7BZ,IAAA,CAACjH,MAAA;MACCmH,WAAA,EAAY;MACZzE,EAAA,EAAG;MACH+E,OAAA,EAASA,CAAA,KAAM,KAAKpB,WAAA;MACpBkB,IAAA,EAAK;gBAEJjF,CAAA,CAAE;MAEP,GACD,CAACjB,QAAA,IAAYkD,kBAAA,iBACZoC,KAAA,CAAC;MAAIE,SAAA,EAAW,GAAG7F,SAAA,WAAoB;8BACrCiG,IAAA,CAACjH,MAAA;QACCmH,WAAA,EAAY;QACZN,SAAA,EAAW,GAAG7F,SAAA,iBAA0B;QACxC0B,EAAA,EAAG;QACH+E,OAAA,EAASA,CAAA,KAAMlF,WAAA,CAAYS,eAAA;QAC3BuE,IAAA,EAAK;kBACN;uBAGDN,IAAA,CAAChH,iBAAA;QACCqF,IAAA,eACEqB,KAAA,CAAC;qBAAK,yD,aACiDM,IAAA,CAAC;sBAAQvE;cAAY;;QAI9EoF,YAAA,EAAa;QACbC,OAAA,EAAQ;QACRC,SAAA,EAAWhF,eAAA;QACXiF,SAAA,EAAW1B;;;;AAMvB","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type APIKeyGenerationModalProps = {
|
|
3
|
+
highlightField: (Boolean: any) => void;
|
|
4
|
+
icon?: React.ReactNode;
|
|
5
|
+
id?: string;
|
|
6
|
+
setKey: () => boolean | Promise<boolean | void> | void;
|
|
7
|
+
willInvalidateExistingKey?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type GenerateConfirmationProps = APIKeyGenerationModalProps;
|
|
10
|
+
export declare function APIKeyGenerationModal(props: APIKeyGenerationModalProps): React.JSX.Element;
|
|
11
|
+
//# sourceMappingURL=APIKeyGenerationModal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"APIKeyGenerationModal.d.ts","sourceRoot":"","sources":["../../../../src/views/Edit/Auth/APIKeyGenerationModal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAS1C,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAA;IACjC,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACtB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;IACtD,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,0BAA0B,CAAA;AAElE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,qBAyDtE"}
|