parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.69k stars 4.76k forks source link

How about add DefineOptions(internal?: boolean) in define Cloud function ? #9138

Closed badboy-tian closed 1 month ago

badboy-tian commented 1 month ago

New Feature / Enhancement Checklist

Current Limitation

  1. I want to define a cloud function, but it is only for internal use and cannot be called by clients.

Feature / Enhancement Description

current define function

function define(
                name: string,
                func: (request: FunctionRequest) => any,
                validator?: Validator | ((request: FunctionRequest) => any),
            ): void;

and then add a DefineOptions

interface DefineOptions {
    internal?: boolean,
    //some else
  }

function define(
                name: string,
                func: (request: FunctionRequest) => any,
                 defineOptions: DefineOptions,
                validator?: Validator | ((request: FunctionRequest) => any),
            ): void;

Example Use Case

Parse.Cloud.define("internalFunc", { internal: true }, (request)=>{} )

Alternatives / Workarounds

no

3rd Party References

https://docs.leancloud.cn/en/sdk/engine/functions/guides/ image

parse-github-assistant[bot] commented 1 month ago

Thanks for opening this issue!

mtrezza commented 1 month ago

Could you please clarify the feature you are suggesting?

badboy-tian commented 1 month ago

for example: I define a cloud function

Parse.Cloud.define("internalFunc", { internal: true, fetchUser:false }, (request)=>{} )

I call the function use parse clicent sdk, for example flutter sdk. return "function not found".

when i call the function from express and parse-server, return normal result

mtrezza commented 1 month ago

Still don't understand it. What does this have to do with fetchUser?

badboy-tian commented 1 month ago
  1. fetchUser?: boolean: Whether to automatically fetch the user logged in on the client side. Defaults to true. When set to false, Request will not contain the currentUser property.

  2. internal?: boolean: Whether to only allow the function to be invoked within Cloud Function (with Parse.Cloud.run without enabling remote) or with the Master Key (by providing useMasterKey when calling Parse.Cloud.run). When set to true, the function cannot be invoked directly by the client. Defaults to false.

I'm just giving an example, it doesn't matter if fetchUser is used or not. I just feel that internal: true is very useful. It allows the cloud function to be called only internally on the server, not on the client.

mtrezza commented 1 month ago

(1) requieres a different discussion than (2), so I'd keep this issue focused on one of the two. If you find (2) important then I suggest to focus on only that for now and adapt the issue title and description to make it easier for readers to follow this.