jmap-kit
    Preparing search index...
    • Factory function to create read-only account validation plugins.

      This factory reduces code duplication by centralising the common pattern of validating that an account is not read-only before allowing write operations.

      The factory automatically asserts the invocation type based on the trigger configuration:

      • If both dataType and method are specified, uses assertInvocation()
      • If only method is specified, uses assertInvocationMethod()
      • If only dataType is specified, uses assertInvocationDataType()

      Type Parameters

      Parameters

      • config: {
            name: string;
            trigger: {
                capabilityUri?: keyof JMAPServerCapabilities;
                dataType?: JMAPDataType;
                method?: JMAPMethodName;
            };
        }

        Configuration for the validator

        • name: string

          Unique name for the validation plugin

        • trigger: {
              capabilityUri?: keyof JMAPServerCapabilities;
              dataType?: JMAPDataType;
              method?: JMAPMethodName;
          }

          Trigger conditions defining when the validator runs

          • OptionalcapabilityUri?: keyof JMAPServerCapabilities

            The capability URI of the invocation being processed.

            This differs from requiredCapabilityUri in that it is the capability URI of the specific invocation, rather than a general support requirement.

          • OptionaldataType?: JMAPDataType

            The data type of the invocation being processed.

          • Optionalmethod?: JMAPMethodName

            The method name of the invocation being processed.

      Returns {
          hook: "invocation";
          name: string;
          trigger: {
              capabilityUri?: keyof JMAPServerCapabilities;
              dataType?: JMAPDataType;
              method?: JMAPMethodName;
          };
          validate(
              this: void,
              context: BasePluginContext & { invocation: Invocation<TArgs> },
          ): MaybePromise<ValidationResult>;
      }

      A ValidationPlugin that checks if the account is read-only

      // For a specific method call like Blob/upload
      const validator = createReadOnlyAccountValidator({
      name: "blob-prevent-upload-on-readonly-account",
      trigger: { dataType: "Blob", method: "upload" },
      });

      // For all methods of a data type
      const validator = createReadOnlyAccountValidator({
      name: "example-prevent-write-on-readonly",
      trigger: { dataType: "Example" },
      });

      // For a specific method across data types
      const validator = createReadOnlyAccountValidator({
      name: "prevent-set-on-readonly",
      trigger: { method: "set" },
      });