> ## Documentation Index
> Fetch the complete documentation index at: https://auth0-automated-translations-update.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Auth0 Dashboard で最初の Auth0 Action Module を作成し、シークレットと NPM 依存関係を追加してバージョンを公開し、外部サービスにログを送信する方法を説明します。

# はじめてのAction Moduleを作成する

export const AuthCodeGroup = ({children, dropdown}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        const processChildren = node => {
          if (typeof node === "string") {
            let processedNode = node;
            for (const [key, value] of window.rootStore.variableStore.values.entries()) {
              const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
              processedNode = processedNode.replaceAll(new RegExp(escapedKey, "g"), value);
            }
            return processedNode;
          } else if (Array.isArray(node)) {
            return node.map(processChildren);
          } else if (node && node.props && node.props.children) {
            return {
              ...node,
              props: {
                ...node.props,
                children: processChildren(node.props.children)
              }
            };
          }
          return node;
        };
        setProcessedChildren(processChildren(children));
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeGroup dropdown={dropdown}>{processedChildren}</CodeGroup>;
};

<h2 id="get-started">
  はじめに
</h2>

Quickstartを使ってAction Moduleを作成し、Actionからそれを利用してログを外部サービスに送信します。

<Steps titleSize="h3">
  <Step title="Action モジュールを作成">
    特定のActionからAction Moduleを使用するには、まずAction Moduleを作成し、その後Actionに追加して使用する必要があります。

    <Tabs>
      <Tab title="Auth0 Dashboard">
        1. [Auth0 Dashboard > Actions > Library](https://manage.auth0.com/#/actions/library) に移動し、**Modules** を選択します。
        2. **Create Module** を選択します。
        3. **Name** を入力します。
        4. **Create** を選択します。

        <Frame>
          <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-automated-translations-update/docs/images/customize/actions/modules/actions-modules-new-module.png" alt="Actions Modules - 新しいAction Module" />
        </Frame>
      </Tab>

      <Tab title="Management API">
        1. `create:actions` スコープを付与した [Management API アクセストークンを取得](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens) します。
        2. [Create an Actions Module](/docs/ja-jp/api/management/v2/actions/post-action-module) を呼び出します。

        ```shell theme={null}
        curl -L 'https://{yourDomain}/api/v2/actions/modules' \
          -H 'Content-Type: application/json' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
          -d '{
            "name": "logger",
            "code": "module.exports = {};",
            "api_version": "1",
            "publish": false
          }'
        ```

        Auth0 は新しい Action Module を返します。この中には `id` が含まれており、以降の手順でモジュールを参照する際に使用します。
      </Tab>

      <Tab title="Auth0 CLI">
        <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
          Actions Modules は `auth0-cli` のコマンドセットでは直接サポートされていないため、[`auth0 api`](https://auth0.github.io/auth0-cli/auth0_api.html) を使って Management API を直接呼び出します。一部の呼び出しには追加のスコープが必要です。必要に応じて、まず `auth0 login --scopes create:actions,read:actions,update:actions` を実行してください。
        </Callout>

        `auth0 api` で [Create an Actions Module](/docs/ja-jp/api/management/v2/actions/post-action-module) を呼び出します。

        ```shell theme={null}
        auth0 api post actions/modules --data '{
          "name": "logger",
          "code": "module.exports = {};",
          "api_version": "1",
          "publish": false
        }'
        ```

        Auth0 は新しい Action Module を返します。この中には `id` が含まれており、以降の手順でモジュールを参照する際に使用します。
      </Tab>

      <Tab title="Terraform">
        <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
          詳しくは [`auth0_action_module`](https://registry.terraform.io/providers/auth0/auth0/latest/docs/resources/action_module) リソースのドキュメントをご覧ください。
        </Callout>

        1. 次のリソースを `.tf` ファイルに追加し、モジュールのコードをファイルから参照します。

        ```terraform title="action-modules/logger.tf" theme={null}
        resource "auth0_action_module" "logger" {
          name = "logger"
          code = file("${path.module}/action-modules/logger/code.js")
        }
        ```

        2. モジュールのコードファイルを `action-modules/logger/code.js` に作成します。

        ```javascript title="action-modules/logger/code.js" theme={null}
        module.exports = {};
        ```

        3. `terraform apply` を実行します。

        このコードファイルとリソースは、以降の手順で Secrets を追加して拡張していきます。
      </Tab>

      <Tab title="Auth0 Deploy CLI">
        <Tabs>
          <Tab title="YAML">
            1. モジュールのコードファイルを `action-modules/logger/code.js` に作成します。

            ```javascript title="action-modules/logger/code.js" theme={null}
            module.exports = {};
            ```

            2. `tenant.yaml` に `actionModules` のエントリーを追加します。

            ```yaml title="tenant.yaml" theme={null}
            actionModules:
              - name: logger
                code: ./action-modules/logger/code.js
            ```

            3. 構成を導入します。

            ```shell theme={null}
            a0deploy import -c=config.json --input_file=tenant.yaml
            ```
          </Tab>

          <Tab title="Directory (JSON)">
            1. モジュールの構成ファイルを `action-modules/logger.json` に作成します。

            ```json title="action-modules/logger.json" theme={null}
            {
              "name": "logger",
              "code": "./action-modules/logger/code.js"
            }
            ```

            2. モジュールのコードファイルを `action-modules/logger/code.js` に作成します。

            ```javascript title="action-modules/logger/code.js" theme={null}
            module.exports = {};
            ```

            3. 構成を導入します。

            ```shell theme={null}
            a0deploy import -c=config.json --input_file=local.
            ```
          </Tab>
        </Tabs>
      </Tab>
    </Tabs>
  </Step>

  <Step title="Secretを追加">
    各 Action Module には、シークレットのキーと値のペアを含めることができます。これらを使って、API キーや証明書、環境ごとに変わる可能性のある値などの機密情報を保持します。

    <Tabs>
      <Tab title="Dashboard">
        次に、外部サービスの URL を Secret として保存します。

        1. コードエディターの左側のサイドバーにある **<svg style={{ display: 'inline' }} width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="sc-kJNqSH"><path fill-rule="evenodd" clip-rule="evenodd" d="M19.573 2.06l1.409 1.42-1.192 1.182L22.65 7.5l-4.756 4.72-2.86-2.838-2.783 2.764a6.196 6.196 0 011.196 3.63 6.172 6.172 0 01-1.832 4.41 6.277 6.277 0 01-8.853-.03l-.007-.008A6.183 6.183 0 011 15.782a6.184 6.184 0 011.831-4.335 6.271 6.271 0 017.987-.696l8.755-8.691zm-9.335 10.798l-.045-.043a4.264 4.264 0 00-2.987-1.182 4.262 4.262 0 00-2.966 1.233A4.184 4.184 0 003 15.8a4.183 4.183 0 001.185 2.95 4.276 4.276 0 006.022.016 4.2 4.2 0 001.24-2.984 4.171 4.171 0 00-1.21-2.924zm6.216-4.885l1.44 1.43L19.811 7.5l-1.44-1.43-1.917 1.903z" fill="inherit" /></svg>** アイコンを選択します。
        2. **Add Secret** を選択します。
        3. **Name** に `SERVICE_URL` と入力します。
        4. **Value** フィールドに外部サービスの URL を入力します。
        5. **Create** を選択します。

        <Frame>
          <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-automated-translations-update/docs/images/customize/actions/modules/actions-modules-secret.png" alt="Actions Modules - Secret added" />
        </Frame>

        Secret が Action Module の Secret 一覧に追加されます。
      </Tab>

      <Tab title="Management API">
        次に、外部サービスの URL を Secret として保存します。`update:actions` スコープを使って [Update an Actions Module](/docs/ja-jp/api/management/v2/actions/patch-action-module) を呼び出します。

        ```shell theme={null}
        curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
          -H 'Content-Type: application/json' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
          -d '{
            "secrets": [
              { "name": "SERVICE_URL", "value": "https://example.com/logs" }
            ]
          }'
        ```

        `PATCH` を呼び出すたびに、モジュールの下書きにある `secrets` 配列全体が置き換えられます。そのため、今回追加するものだけでなく、モジュールに必要なすべての Secret を含めてください。
      </Tab>

      <Tab title="Auth0 CLI">
        次に、外部サービスの URL を Secret として保存します。`auth0 api` で [Update an Actions Module](/docs/ja-jp/api/management/v2/actions/patch-action-module) を呼び出します。

        ```shell theme={null}
        auth0 api patch actions/modules/{moduleId} --data '{
          "secrets": [
            { "name": "SERVICE_URL", "value": "https://example.com/logs" }
          ]
        }'
        ```

        呼び出しのたびにモジュールの下書きの `secrets` 配列全体が置き換えられるため、今回追加するものだけでなく、そのモジュールに必要なすべての Secret を含めてください。
      </Tab>

      <Tab title="Terraform">
        次に、`secrets` ブロックを使って外部サービスの URL を Secret として保存します。

        ```terraform title="action-modules/logger.tf" theme={null}
        resource "auth0_action_module" "logger" {
          name = "logger"
          code = file("${path.module}/action-modules/logger/code.js")

          secrets {
            name  = "SERVICE_URL"
            value = "https://example.com/logs"
          }
        }
        ```

        <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
          `secrets` の部分的な管理はサポートしていません。`terraform apply` を実行するたびに、リソースに定義されたシークレットの完全な一覧が送信されます。
        </Callout>
      </Tab>

      <Tab title="Auth0 導入 CLI">
        次に、外部サービスの URL を Secret として保存します。

        <Tabs>
          <Tab title="YAML">
            `tenant.yaml` 内のモジュールのエントリに `secrets` 配列を追加します。

            ```yaml highlight={3-5} title="tenant.yaml" theme={null}
            actionModules:
              - name: logger
                secrets:
                  - name: SERVICE_URL
                    value: ##SERVICE_URL##
                code: ./action-modules/logger/code.js
            ```
          </Tab>

          <Tab title="Directory (JSON)">
            `action-modules/logger.json` に `secrets` 配列を追加します。

            ```json highlight={3-5} title="action-modules/logger.json" theme={null}
            {
              "name": "logger",
              "secrets": [
                { "name": "SERVICE_URL", "value": "##SERVICE_URL##" }
              ],
              "code": "./action-modules/logger/code.js"
            }
            ```
          </Tab>
        </Tabs>

        `##SERVICE_URL##` の placeholder は、導入時に [キーワード置換](https://github.com/auth0/auth0-deploy-cli/blob/master/docs/keyword-replacement.md) によって解決されるため、実際の値が設定ファイルに残ることはありません。
      </Tab>
    </Tabs>

    **追加の手順:** 同じ手順で `API_KEY` も Secret として保存します。これは、各リクエストで外部サービスに送信するヘッダーに含めるためのものです。

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      Secret は一度作成すると、その値が Auth0 から再表示されることはありません。Auth0 はすべての Secrets を暗号化して安全に保存します。
    </Callout>

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      各 **Action Module Secret** は、ほかの **Actions Modules** や **Actions Secrets** とは独立しています。
    </Callout>

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      Action Module で **Secrets** を使用するには、`actions.secrets.[secret_key]` と入力します。
    </Callout>
  </Step>

  <Step title="カスタムロジックを追加">
    次に、Action Module に以下のコードを追加します。

    <Tabs>
      <Tab title="Auth0 Dashboard">
        Action Module に以下のコードを追加します。

        ```javascript theme={null}
        module.exports = {
          sendLog: async (code, message) => {
            try {
              await fetch(actions.secrets.SERVICE_URL, {
                method: 'POST',
                headers: {
                  'X-API-Key': actions.secrets.API_KEY,
                },
                body: JSON.stringify({
                  code,
                  message
                }),
              });

              console.log({
                code,
                message
              });
            } catch (err) {
              throw new Error('External service failure');
            }

            return;
          }
        };
        ```
      </Tab>

      <Tab title="Management API">
        以下のリクエストで [Update an Actions Module](/docs/ja-jp/api/management/v2/actions/patch-action-module) を呼び出します。

        ```shell theme={null}
        curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
          -H 'Content-Type: application/json' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
          -d @code-update.json
        ```

        ここで `code-update.json` には、モジュールの `code` が JSON エスケープされた文字列として含まれます。

        ```json title="code-update.json" theme={null}
        {
          "code": "module.exports = {\n  sendLog: async (code, message) => {\n    try {\n      await fetch(actions.secrets.SERVICE_URL, {\n        method: 'POST',\n        headers: {\n          'X-API-Key': actions.secrets.API_KEY,\n        },\n        body: JSON.stringify({ code, message }),\n      });\n\n      console.log({ code, message });\n    } catch (err) {\n      throw new Error('External service failure');\n    }\n\n    return;\n  }\n};"
        }
        ```
      </Tab>

      <Tab title="Auth0 CLI">
        モジュールのコードを `code-update.json` に保存します。

        ```json title="code-update.json" theme={null}
        {
          "code": "module.exports = {\n  sendLog: async (code, message) => {\n    try {\n      await fetch(actions.secrets.SERVICE_URL, {\n        method: 'POST',\n        headers: {\n          'X-API-Key': actions.secrets.API_KEY,\n        },\n        body: JSON.stringify({ code, message }),\n      });\n\n      console.log({ code, message });\n    } catch (err) {\n      throw new Error('External service failure');\n    }\n\n    return;\n  }\n};"
        }
        ```

        次に、`auth0 api` を使って [Update an Actions Module](/docs/ja-jp/api/management/v2/actions/patch-action-module) にパイプで渡します。

        ```shell theme={null}
        cat code-update.json | auth0 api patch actions/modules/{moduleId}
        ```
      </Tab>

      <Tab title="Terraform">
        1. `action-modules/logger/code.js` にあるモジュールのコードファイルを更新します。

        ```javascript title="action-modules/logger/code.js" theme={null}
        module.exports = {
          sendLog: async (code, message) => {
            try {
              await fetch(actions.secrets.SERVICE_URL, {
                method: 'POST',
                headers: {
                  'X-API-Key': actions.secrets.API_KEY,
                },
                body: JSON.stringify({
                  code,
                  message
                }),
              });

              console.log({
                code,
                message
              });
            } catch (err) {
              throw new Error('External service failure');
            }

            return;
          }
        };
        ```

        2. `auth0_action_module` リソースの `code` 属性はすでにこのファイルを参照しているため、`terraform apply` を実行して変更を適用します。
      </Tab>

      <Tab title="Auth0 Deploy CLI">
        `action-modules/logger/code.js` をモジュールのロジックで更新します。

        ```javascript title="action-modules/logger/code.js" theme={null}
        module.exports = {
          sendLog: async (code, message) => {
            try {
              await fetch(actions.secrets.SERVICE_URL, {
                method: 'POST',
                headers: {
                  'X-API-Key': actions.secrets.API_KEY,
                },
                body: JSON.stringify({
                  code,
                  message
                }),
              });

              console.log({
                code,
                message
              });
            } catch (err) {
              throw new Error('External service failure');
            }

            return;
          }
        };
        ```
      </Tab>
    </Tabs>

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      以下の点に注意してください。

      * [コーディングガイドライン](/docs/ja-jp/customize/actions/action-coding-guidelines#actions-modules)
      * [制限事項](/docs/ja-jp/customize/actions/limitations#actions-modules)
    </Callout>
  </Step>

  <Step title="下書きを保存">
    Action Module のドラフトを保存できます。

    <Tabs>
      <Tab title="Auth0 Dashboard">
        1. **下書きとして保存** を選択します。

        <Frame>
          <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-automated-translations-update/docs/images/customize/actions/modules/actions-modules-draft.png" alt="Actions Modules - 下書きを保存済み" />
        </Frame>
      </Tab>

      <Tab title="Management API">
        "保存"のための個別の呼び出しはありません。前の手順で実行した [Update an Actions Module](/docs/ja-jp/api/management/v2/actions/patch-action-module) のリクエストはすべて、変更内容をすでにモジュールのドラフトに保存しています。これは [Get an Actions Module](/docs/ja-jp/api/management/v2/actions/get-action-module) で確認できます。

        ```shell theme={null}
        curl -L 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}'
        ```

        レスポンスの `all_changes_published` フィールドが `false` になっており、ドラフトに未公開の変更があることが確認できます。
      </Tab>

      <Tab title="Auth0 CLI">
        "保存"のための個別の呼び出しはありません。前の手順で実行した `auth0 api patch actions/modules/{moduleId}` のリクエストはすべて、変更内容をすでにモジュールのドラフトに保存しています。これは [Get an Actions Module](/docs/ja-jp/api/management/v2/actions/get-action-module) で確認できます。

        ```shell theme={null}
        auth0 api get actions/modules/{moduleId}
        ```

        レスポンスの `all_changes_published` フィールドが `false` になっており、ドラフトに未公開の変更があることが確認できます。
      </Tab>

      <Tab title="Terraform">
        "保存"のための個別の手順はありません。前の手順で実行した `terraform apply` によって、モジュールのドラフトはすでに更新されています。ドラフトは、モジュールの公開済みバージョンをすでに使用している Actions には影響しません。
      </Tab>

      <Tab title="Auth0 Deploy CLI">
        モジュールのエントリで `all_changes_published` を `false` に設定します。

        <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
          "保存"のための個別の手順はありません。
        </Callout>

        <Tabs>
          <Tab title="YAML">
            `tenant.yaml` を更新します。

            ```yaml highlight={3} title="tenant.yaml" theme={null}
            actionModules:
              - name: logger
                all_changes_published: false
                secrets:
                  - name: SERVICE_URL
                    value: ##SERVICE_URL##
                code: ./action-modules/logger/code.js
            ```

            変更を公開するために構成を再デプロイします。

            ```shell theme={null}
            a0deploy import -c=config.json --input_file=tenant.yaml
            ```
          </Tab>

          <Tab title="Directory (JSON)">
            `action-modules/logger.json` を更新します。

            ```json highlight={2} title="action-modules/logger.json" theme={null}
            {
              "all_changes_published": false,
              "name": "logger",
              "secrets": [
                { "name": "SERVICE_URL", "value": "##SERVICE_URL##" }
              ],
              "code": "./action-modules/logger/code.js"
            }
            ```

            変更を公開するために構成を再デプロイします。

            ```shell theme={null}
            a0deploy import -c=config.json --input_file=local.
            ```
          </Tab>
        </Tabs>
      </Tab>
    </Tabs>

    これにより、新しいバージョンを公開せずに Action Module が保存されるため、それを使用している Actions には影響しません。
  </Step>

  <Step title="Action モジュールを公開する">
    Action Module のコードに問題がなければ、**公開**します。

    <Tabs>
      <Tab title="Auth0 Dashboard">
        1. **公開**を選択します。

        <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
          Action Module を公開すると、その時点のスナップショットが取得され、**Action Module Version** として記録されます。
        </Callout>

        2. **バージョン履歴を表示**を選択します。

        <Frame>
          <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-automated-translations-update/docs/images/customize/actions/modules/actions-modules-published-version.png" alt="Actions Modules - Version History" />
        </Frame>

        下書きを含む Action Module Version の一覧が表示されます。
      </Tab>

      <Tab title="Management API">
        [Create an Actions Module Version](/docs/ja-jp/api/management/v2/actions/post-action-module-version) を呼び出します。これにより、現在の下書きのスナップショットが取得され、公開されます。

        ```shell theme={null}
        curl -L -X POST 'https://{yourDomain}/api/v2/actions/modules/{moduleId}/versions' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}'
        ```

        Auth0 は、`id` と `version_number` を含む新しい **Action Module Version** を返します。モジュールを Action に追加する際は、この `id` を `module_version_id` として参照します。
      </Tab>

      <Tab title="Auth0 CLI">
        `auth0 api` で [Create an Actions Module Version](/docs/ja-jp/api/management/v2/actions/post-action-module-version) を呼び出します。これにより、現在の下書きのスナップショットが取得され、公開されます。

        ```shell theme={null}
        auth0 api post actions/modules/{moduleId}/versions
        ```

        Auth0 は、`id` と `version_number` を含む新しい **Action Module Version** を返します。モジュールを Action に追加する際は、この `id` を `module_version_id` として参照します。
      </Tab>

      <Tab title="Terraform">
        リソースの `publish` を `true` に設定し、`terraform apply` を実行します。

        ```terraform highlight={4} title="action-modules/logger.tf" theme={null}
        resource "auth0_action_module" "logger" {
          name    = "logger"
          code    = file("${path.module}/action-modules/logger/code.js")
          publish = true

          secrets {
            name  = "SERVICE_URL"
            value = "https://example.com/logs"
          }
        }
        ```

        公開すると、現在の下書きから新しい **Action Module Version** が作成されます。Terraform は、公開されたバージョンの ID を `version_id` という算出属性として公開します。これを `auth0_action` リソースから `module_version_id` として参照します。
      </Tab>

      <Tab title="Auth0 Deploy CLI">
        モジュールのエントリーで `all_changes_published` を `true` に設定します。

        <Tabs>
          <Tab title="YAML">
            `tenant.yaml` を更新します。

            ```yaml highlight={3} title="tenant.yaml" theme={null}
            actionModules:
              - name: logger
                all_changes_published: true
                secrets:
                  - name: SERVICE_URL
                    value: ##SERVICE_URL##
                code: ./action-modules/logger/code.js
            ```

            変更を公開するために、構成を再デプロイします。

            ```shell theme={null}
            a0deploy import -c=config.json --input_file=tenant.yaml
            ```
          </Tab>

          <Tab title="Directory (JSON)">
            `action-modules/logger.json` を更新します。

            ```json highlight={2} title="action-modules/logger.json" theme={null}
            {
              "all_changes_published": true,
              "name": "logger",
              "secrets": [
                { "name": "SERVICE_URL", "value": "##SERVICE_URL##" }
              ],
              "code": "./action-modules/logger/code.js"
            }
            ```

            変更を公開するために、構成を再デプロイします。

            ```shell theme={null}
            a0deploy import -c=config.json --input_file=local.
            ```
          </Tab>
        </Tabs>

        これにより、変更が適用された後、現在の下書きから新しい **Action Module Version** が公開されます。
      </Tab>
    </Tabs>

    これで、Action で Action Module を使えるようになります。

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      各 **Action** では、**Action Module Version** を明示的に参照する必要があります。これにより、予期しないエラーにつながる自動アップグレードを防げます。
    </Callout>
  </Step>

  <Step title="Action 内に Action Module を追加する">
    次に、ActionにAction Moduleを追加します。

    <Tabs>
      <Tab title="Dashboard">
        1. [Auth0 Dashboard > Actions > ライブラリ](https://manage.auth0.com/#/actions/library) に移動して、特定の **Action** を選択します。
        2. Action エディタに移動したら、左側のサイドバーにある **<svg style={{ display: 'inline' }} width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="sc-hQYogJ"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.388 4.07A3.717 3.717 0 0112 3c.977 0 1.917.383 2.612 1.07A3.65 3.65 0 0115.7 6.667a3.65 3.65 0 01-1.028 2.537l1.683 2.778-1.71 1.036-1.701-2.806a3.733 3.733 0 01-3.556-.948A3.65 3.65 0 018.3 6.667c0-.977.393-1.91 1.088-2.597zM12 5c-.455 0-.889.179-1.207.493a1.65 1.65 0 00-.493 1.174c0 .438.176.86.493 1.174.318.314.752.492 1.207.492.455 0 .889-.178 1.207-.492a1.65 1.65 0 00.493-1.174c0-.438-.176-.86-.493-1.174A1.717 1.717 0 0012 5zM6.697 13.802l1.98-2.87 1.646 1.136-1.911 2.77c.633.677.988 1.567.988 2.495a3.65 3.65 0 01-1.088 2.597A3.717 3.717 0 015.7 21a3.717 3.717 0 01-2.612-1.07A3.65 3.65 0 012 17.333c0-.976.393-1.91 1.088-2.597a3.717 3.717 0 013.61-.934zM5.7 15.667c-.455 0-.889.178-1.206.492A1.65 1.65 0 004 17.333c0 .438.176.86.494 1.175.317.313.751.492 1.206.492.455 0 .889-.179 1.206-.492a1.65 1.65 0 00.494-1.175c0-.438-.176-.86-.494-1.174a1.717 1.717 0 00-1.206-.492zM15.688 14.736a3.717 3.717 0 012.612-1.07c.977 0 1.917.384 2.612 1.07A3.65 3.65 0 0122 17.333a3.65 3.65 0 01-1.088 2.597A3.717 3.717 0 0118.3 21a3.717 3.717 0 01-2.612-1.07 3.66 3.66 0 01-.948-1.597H11v-2h3.74c.172-.6.496-1.15.948-1.597zm2.612.93c-.455 0-.889.18-1.207.493a1.65 1.65 0 00-.493 1.174c0 .438.176.86.493 1.175.318.313.752.492 1.207.492.455 0 .889-.179 1.206-.492A1.65 1.65 0 0020 17.332c0-.438-.176-.86-.494-1.174a1.717 1.717 0 00-1.206-.492z" fill="inherit" /></svg>** アイコンを選択します。
        3. **モジュールを追加**を選択します。
        4. モジュールの**名前**と**バージョン**を選択します。
        5. **追加**を選択します。

        <Frame>
          <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-automated-translations-update/docs/images/customize/actions/modules/actions-modules-add-module.png" alt="Actions - Action モジュールの追加" />
        </Frame>
      </Tab>

      <Tab title="Management API">
        前の手順で取得したモジュールの `module_id` と `module_version_id` を指定して、[Update an Action](/docs/ja-jp/api/management/v2/actions/patch-action) を呼び出します。

        ```shell theme={null}
        curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/actions/{actionId}' \
          -H 'Content-Type: application/json' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
          -d '{
            "modules": [
              {
                "module_id": "{moduleId}",
                "module_version_id": "{moduleVersionId}"
              }
            ]
          }'
        ```
      </Tab>

      <Tab title="Auth0 CLI">
        <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
          [`auth0 actions update`](https://auth0.github.io/auth0-cli/auth0_actions_update.html) には Action Module 用のフラグがないため、前の手順で取得したモジュールの `module_id` と `module_version_id` を使い、`auth0 api` で [Update an Action](/docs/ja-jp/api/management/v2/actions/patch-action) を直接呼び出してください。
        </Callout>

        ```shell theme={null}
        auth0 api patch actions/actions/{actionId} --data '{
          "modules": [
            {
              "module_id": "{moduleId}",
              "module_version_id": "{moduleVersionId}"
            }
          ]
        }'
        ```
      </Tab>

      <Tab title="Terraform">
        `auth0_action` リソースに `modules` ブロックを追加し、モジュールとその公開済みバージョンを参照します。`code` 属性は、引き続き Action 自身のコードファイルを指すようにしておきます。

        ```terraform highlight={3,5-8} title="actions/my-action.tf" theme={null}
        resource "auth0_action" "my_action" {
          name = "my-action"
          code = file("${path.module}/actions/my-action/code.js")

          modules {
            module_id         = auth0_action_module.logger.id
            module_version_id = auth0_action_module.logger.version_id
          }

          supported_triggers {
            id      = "post-login"
            version = "v3"
          }
        }
        ```
      </Tab>

      <Tab title="Auth0 導入 CLI">
        Action の設定に `modules` 配列を追加し、モジュールを名前とバージョン番号で参照します。

        <Tabs>
          <Tab title="YAML">
            `tenant.yaml` の Action のエントリに `modules` 配列を追加します。

            ```yaml highlight={7-9} title="tenant.yaml" theme={null}
            actions:
              - name: my-action
                code: ./actions/my-action/code.js
                supported_triggers:
                  - id: post-login
                    version: v3
                modules:
                  - module_name: logger
                    module_version_number: 1
            ```
          </Tab>

          <Tab title="Directory (JSON)">
            Action の設定ファイル (例: `actions/my-action.json`) に `modules` 配列を追加します。

            ```json highlight={2-5} title="actions/my-action.json" theme={null}
            {
              "modules": [
                { "module_name": "logger", "module_version_number": 1 }
              ],
              "name": "my-action",
              "code": "./actions/my-action/code.js",
              "supported_triggers": [
                { "id": "post-login", "version": "v3" }
              ]
            }
            ```
          </Tab>
        </Tabs>

        Deploy CLI は、導入時に `module_name` と `module_version_number` をモジュールの実際の `module_id` と `module_version_id` に解決します。
      </Tab>
    </Tabs>
  </Step>

  <Step title="Action で Action Module を使う">
    次に、Action 内で Action Module を使ってみましょう。

    <Tabs>
      <Tab title="Dashboard">
        1. **require** 文を追加します。

        ```javascript theme={null}
        const logger = require('actions:logger');
        ```

        <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
          **require** 文では、**actions:\[module-name]** の形式で Action Module を参照します。
        </Callout>

        2. ログを送信したい箇所の **Action 関数** に、`logger.sendLog` の呼び出しを追加します。

        ```javascript theme={null}
        await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
        ```

        3. Action を **Deploy** します。

        <Frame>
          <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-automated-translations-update/docs/images/customize/actions/modules/actions-modules-use-module.png" alt="Actions - Use Action Module" />
        </Frame>
      </Tab>

      <Tab title="Management API">
        1. [Update an Action](/docs/ja-jp/api/management/v2/actions/patch-action) を呼び出して、Action の `code` に `require` 文と `logger.sendLog` の呼び出しを追加します。

        ```shell theme={null}
        curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/actions/{actionId}' \
          -H 'Content-Type: application/json' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
          -d @code-update.json
        ```

        `code-update.json` の内容は次のとおりです。

        ```json title="code-update.json" theme={null}
        {
          "code": "const logger = require('actions:logger');\n\nexports.onExecutePostLogin = async (event, api) => {\n  await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');\n};"
        }
        ```

        2. [Deploy an Action](/docs/ja-jp/api/management/v2/actions/post-deploy-action) を呼び出します。

        ```shell theme={null}
        curl -L -X POST 'https://{yourDomain}/api/v2/actions/actions/{actionId}/deploy' \
          -H 'Authorization: Bearer {yourMgmtApiAccessToken}'
        ```
      </Tab>

      <Tab title="Auth0 CLI">
        1. `actions/my-action/code.js` にある Action のコードファイルを更新し、`require` 文と `logger.sendLog` の呼び出しを追加します。

        ```javascript title="actions/my-action/code.js" theme={null}
        const logger = require('actions:logger');

        exports.onExecutePostLogin = async (event, api) => {
          await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
        };
        ```

        2. [`auth0 actions update`](https://auth0.github.io/auth0-cli/auth0_actions_update.html) で Action を更新し、[`auth0 actions deploy`](https://auth0.github.io/auth0-cli/auth0_actions_deploy.html) で導入します。

        ```shell theme={null}
        auth0 actions update {actionId} --code "$(cat actions/my-action/code.js)"
        auth0 actions deploy {actionId}
        ```
      </Tab>

      <Tab title="Terraform">
        1. `actions/my-action/code.js` にある Action のコードファイルを更新し、`require` 文と `logger.sendLog` の呼び出しを追加します。

        ```javascript title="actions/my-action/code.js" theme={null}
        const logger = require('actions:logger');

        exports.onExecutePostLogin = async (event, api) => {
          await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
        };
        ```

        2. `auth0_action` リソースの `deploy` を `true` に設定し、`terraform apply` を実行します。

        ```terraform highlight={3} title="actions/my-action.tf" theme={null}
        resource "auth0_action" "my_action" {
          name    = "my-action"
          deploy  = true
          code    = file("${path.module}/actions/my-action/code.js")

          modules {
            module_id         = auth0_action_module.logger.id
            module_version_id = auth0_action_module.logger.version_id
          }

          supported_triggers {
            id      = "post-login"
            version = "v3"
          }
        }
        ```

        `deploy = true` を設定すると、Action の新しいバージョンが即座に作成され、導入されます。
      </Tab>

      <Tab title="Auth0 導入 CLI">
        1. `actions/my-action/code.js` に `require` 文と `logger.sendLog` の呼び出しを追加します。

        ```javascript title="actions/my-action/code.js" theme={null}
        const logger = require('actions:logger');

        exports.onExecutePostLogin = async (event, api) => {
          await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
        };
        ```

        2. 構成を再導入します:

        ```shell theme={null}
        a0deploy import -c=config.json --input_file=local.
        ```
      </Tab>
    </Tabs>

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      Action をトリガーにバインドすることを忘れないでください。
    </Callout>
  </Step>
</Steps>

<Check>
  **チェックポイント**

  これで、完全に動作する **Action Module** を **Action** で使用できるようになっているはずです。
</Check>

***

<h2 id="advanced-usage">
  応用的な使い方
</h2>

<Accordion title="NPM依存関係">
  各 **Action Module** では、**[NPM依存関係](https://www.npmjs.com/)** を追加して利用できます。

  <Tabs>
    <Tab title="Dashboard">
      1. コードエディターの左側のサイドバーで、**<svg style={{ display: 'inline' }} width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="sc-lgWczb"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.543 5.02l7.197-3.715h.003a2.75 2.75 0 012.514 0h.003l7.197 3.715h.002A2.864 2.864 0 0122 7.573v8.853a2.866 2.866 0 01-1.543 2.553l-7.197 3.714a2.75 2.75 0 01-2.529 0l-7.2-3.715-.002-.002A2.865 2.865 0 012 16.413v-8.84A2.865 2.865 0 013.543 5.02zm8.113-1.937l-1.97 1.018L16.5 7.618l2.315-1.195-6.47-3.34h-.001a.75.75 0 00-.688 0zM20 8.063l-7 3.611v8.902l6.542-3.377h.003a.865.865 0 00.455-.774V8.062zM11 20.58v-8.905L4 8.062v8.36a.866.866 0 00.45.778h.001L11 20.58zM5.185 6.423L12 9.94l2.32-1.197-6.815-3.517-2.32 1.197z" fill="inherit" /></svg>** アイコンを選択します。
      2. **Add Dependency** を選択します。
      3. **NPM package** の **Name** を入力します。
      4. **NPM package** の **Version** を入力します。
      5. **Create** を選択します。

      <Frame>
        <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-automated-translations-update/docs/images/customize/actions/modules/actions-modules-dependency.png" alt="Actions Modules - 依存関係を追加済み" />
      </Frame>

      Auth0 によって、その依存関係が Action Module の依存関係一覧に追加されます。
    </Tab>

    <Tab title="Management API">
      `dependencies` 配列を指定して [Update an Actions Module](/docs/ja-jp/api/management/v2/actions/patch-action-module) を呼び出します。

      ```shell theme={null}
      curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
        -H 'Content-Type: application/json' \
        -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
        -d '{
          "dependencies": [
            { "name": "lodash", "version": "4.17.21" }
          ]
        }'
      ```

      `secrets` と同様に、`PATCH` を呼び出すたびに `dependencies` 配列全体が置き換えられるため、モジュールに必要なすべての依存関係を含めてください。
    </Tab>

    <Tab title="Auth0 CLI">
      `dependencies` 配列を使用して、`auth0 api` で [Update an Actions Module](/docs/ja-jp/api/management/v2/actions/patch-action-module) を呼び出します:

      ```shell theme={null}
      auth0 api patch actions/modules/{moduleId} --data '{
        "dependencies": [
          { "name": "lodash", "version": "4.17.21" }
        ]
      }'
      ```

      `secrets` と同様に、呼び出しごとに `dependencies` 配列全体が置き換えられるため、モジュールに必要なすべての依存関係を含めてください。
    </Tab>

    <Tab title="Terraform">
      `auth0_action_module` リソースに `dependencies` ブロックを追加し、`terraform apply` を実行します。

      ```terraform highlight={4-7} title="action-modules/logger.tf" theme={null}
      resource "auth0_action_module" "logger" {
        name = "logger"
        code = file("${path.module}/action-modules/logger/code.js")

        dependencies {
          name    = "lodash"
          version = "4.17.21"
        }
      }
      ```
    </Tab>

    <Tab title="Auth0 Deploy CLI">
      モジュールの設定に `dependencies` 配列を追加します。

      <Tabs>
        <Tab title="YAML">
          `tenant.yaml` 内のモジュールのエントリーに `dependencies` 配列を追加します。

          ```yaml highlight={3-5} title="tenant.yaml" theme={null}
          actionModules:
            - name: logger
              dependencies:
                - name: lodash
                  version: 4.17.21
              code: ./action-modules/logger/code.js
          ```
        </Tab>

        <Tab title="Directory (JSON)">
          `action-modules/logger.json` に `dependencies` 配列を追加します。

          ```json highlight={2-4} title="action-modules/logger.json" theme={null}
          {
            "dependencies": [
              { "name": "lodash", "version": "4.17.21" }
            ],
            "name": "logger",
            "code": "./action-modules/logger/code.js"
          }
          ```
        </Tab>
      </Tabs>
    </Tab>
  </Tabs>

  <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
    一覧に表示されている **依存関係** は、`require('[package-name]')` で読み込むことで Action Module 内で使用できます。
  </Callout>

  <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
    この Action を保存すると、Auth0 は依存関係の最新バージョンを解決し、今後のパッケージ更新によって Action が壊れないよう、特定のバージョン番号に置き換えます。

    latest の代わりに、特定のバージョンを指定することもできます。
  </Callout>
</Accordion>
