Zapier StoreClient 未定义

Zapier StoreClient undefined

我正在尝试存储调用之间的状态,类似于此处的文档:https://zapier.com/apps/code/help#code-examples

但是,我尝试 运行 来自 Zap 的代码,我得到:

StoreClient is not defined

文档指出我不应该要求任何东西来使用 StoreClient:"There is no need to require it - it comes pre-imported in your Code environment."

我使用的是最新版本的 zapier-platform-core (8.3.0)。 我使用的是上面链接示例中的确切代码。

 const count = await store.get('some counter')
 const newCount = (count || 0) + 1;
 await store.set('some counter', count);
 return {count: newCount};

来自 Zapier Platform 团队的 David。好问题!

根据文档,这有点不清楚 - StoreClient 仅在代码应用程序(又名 Code by Zapier)中可用。如果您使用的是 zapier-platform-core,那么您正在创建一个 cli 应用程序,这是一个普通的 node.js 环境。如果你想在 cli 应用程序中与 Storage by Zapier 交互,你可以使用网站上的文档:https://store.zapier.com。即:

{
  "how does it work?": {
    "always provide either `?secret=12345` or `X-Secret: 12345`": "",
    "GET /api/secret": [
      "will return a random secret for you to use if you need one."
    ],
    "GET /api/records": [
      "will return a full object of all values stored by default.",
      "you can also specify only the keys you want via the",
      "querystring like`?key=color&key=age`."
    ],
    "POST /api/records": [
      "provide a body with a json object with keys/values you want",
      "to store like `{\"color\": \"blue\", \"age\": 29}`."
    ],
    "DELETE /api/records": ["completely clear all the records in this account"],
    "PATCH /api/records": [
      "A data with a particular schema needs to be received.",
      "The schema specifies which action to do and with what parameters.",
      "For example {\"action\": \"increment_by\", \"data\": {\"key\": \"<key_name>\", \"amount\": 1}} to increment the value specified by \"key\"."
    ]
  }
}

可以使用标准 z.request 向这些端点发出请求,该标准在此处有详细记录:https://github.com/zapier/zapier-platform/tree/master/packages/cli#making-http-requests