craftFunctions
craftFunctionsモジュールは、Craft Functionsの操作に関わる機能を提供します。
サンプルコード
const LOG_LEVEL = "DEBUG";
export default async function (data, { MODULES }) { const { res } = data; const { initLogger, craftFunctions } = MODULES; const logger = initLogger({ logLevel: LOG_LEVEL });
try { const response = await craftFunctions.invoke({ functionId: "{実行するファンクションID}", data: {{ 送信するデータ }}, }); res.send(response); } catch (error) { logger.error("error:", error); res.status(500).send(error); }}
メソッド
craftFunctions
モジュールで利用できるメソッドについて説明します。
invoke
/** * イベント駆動タイプのファンクションを実行する * @param {Object} param * @param {string} param.functionId 実行するファンクションID * @param {Object} param.data ファンクションに渡すデータ * @returns {Promise<Object>} リクエストIDを含むオブジェクト */craftFunctions.invoke({ functionId, data });
指定されたイベント駆動ファンクションを実行します。
functionId
で実行するファンクションIDを指定します。ファンクションIDは管理画面のURLに含まれるIDです。このメソッドを呼び出しているファンクション自身のIDは指定できません。data
でファンクションに渡すデータを指定します。
返り値はリクエストIDを含むオブジェクトです。リクエストIDは、リクエスト先のファンクションが受け取るデータに含まれる id
と同じ値です。
{ "requestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",}