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

> Auth0 Actions Modulesの使用方法を説明します

# 初めての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>;
};

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

このクイックスタートでは、Action Module を作成し、Action から利用して外部サービスにログを送信する方法を説明します。

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

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

        Code Editor が表示されます

        <Frame>
          <img src="https://mintcdn.com/translations/xwVvTWJUElMm5YAK/docs/images/customize/actions/modules/actions-modules-new-module.png?fit=max&auto=format&n=xwVvTWJUElMm5YAK&q=85&s=67daedf547f0fc7311d40c080fb8b3fb" alt="Actions Modules - 新しいAction Module" width="1414" height="669" data-path="docs/images/customize/actions/modules/actions-modules-new-module.png" />
        </Frame>
      </Tab>
    </Tabs>
  </Step>

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

    <Tabs>
      <Tab title="ダッシュボード">
        外部サービスの URL をシークレットとして保存しましょう。

        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. **名前** に `SERVICE_URL` を入力します。
        4. **値** フィールドに外部サービスの URL を入力します。
        5. **Create** を選択します。

        <Frame>
          <img src="https://mintcdn.com/translations/xwVvTWJUElMm5YAK/docs/images/customize/actions/modules/actions-modules-secret.png?fit=max&auto=format&n=xwVvTWJUElMm5YAK&q=85&s=0575d00f98c2919bdb74252317b5e79a" alt="Actions Modules - シークレットを追加" width="1411" height="736" data-path="docs/images/customize/actions/modules/actions-modules-secret.png" />
        </Frame>

        Auth0 により、シークレットが Action Module のシークレット一覧に追加されます。
      </Tab>
    </Tabs>

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

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      シークレットを作成すると、Auth0 がその値を表示することはありません。Auth0 はすべてのシークレットを暗号化し、安全に保存します。
    </Callout>

    <Warning>
      各 **Action Module Secret** は、ほかの **Actions Modules** および **Actions Secrets** とは独立しています。
    </Warning>

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

  <Step title="カスタムロジックの追加" titleSize="h3" stepNumber={3}>
    次に、Action Module に次のコードを追加します。

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

        ```javascript lines 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">
      次の点に注意してください。

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

  <Step title="下書きを保存する" titleSize="h3" stepNumber={4}>
    Action Module の下書きを保存できます。

    <Tabs>
      <Tab title="ダッシュボード">
        1. **Save Draft** を選択します。

        <Frame>
          <img src="https://mintcdn.com/translations/xwVvTWJUElMm5YAK/docs/images/customize/actions/modules/actions-modules-draft.png?fit=max&auto=format&n=xwVvTWJUElMm5YAK&q=85&s=44d6d4a54d1c27138c3800b08235adea" alt="Actions Modules - 下書きを保存済み" width="1417" height="733" data-path="docs/images/customize/actions/modules/actions-modules-draft.png" />
        </Frame>
      </Tab>
    </Tabs>

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

  <Step title="Action モジュールを公開する" titleSize="h3" stepNumber={5}>
    Action Module のコードに問題がなければ、次はそれを**公開**します。

    <Tabs>
      <Tab title="ダッシュボード">
        1. **公開**を選択します。

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

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

        <Frame>
          <img src="https://mintcdn.com/translations/xwVvTWJUElMm5YAK/docs/images/customize/actions/modules/actions-modules-published-version.png?fit=max&auto=format&n=xwVvTWJUElMm5YAK&q=85&s=c5bd3cb6b2724ffc8b8054a21ae42f65" alt="Actions Modules - バージョン履歴" width="1431" height="735" data-path="docs/images/customize/actions/modules/actions-modules-published-version.png" />
        </Frame>

        Auth0 に、ドラフトを含む Action Module Version の一覧が表示されます。
      </Tab>
    </Tabs>

    これで、Action で Action Module を使い始めることができます。

    <Warning>
      各**Action**は**Action Module Version**を明示的に参照する必要があります。これにより、予期しないエラーにつながる可能性のある自動アップグレードを防げます。
    </Warning>
  </Step>

  <Step title="Action に Action Module を追加する" titleSize="h3" stepNumber={6}>
    Action に Action Module を追加してみましょう。

    <Tabs>
      <Tab title="ダッシュボード">
        1. [Auth0 Dashboard > Actions > Library](https://manage.auth0.com/#/actions/library) に移動し、目的の **Action** を選択します。
        2. Action Editor を開いたら、左側のサイドバーで **<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. **Add Module** を選択します。
        4. モジュールの**名前**と**バージョン**を選択します。
        5. **追加** を選択します。

        <Frame>
          <img src="https://mintcdn.com/translations/xwVvTWJUElMm5YAK/docs/images/customize/actions/modules/actions-modules-add-module.png?fit=max&auto=format&n=xwVvTWJUElMm5YAK&q=85&s=edfe210217e6d875a10eacea0dd2d213" alt="Actions - Actionモジュールの追加" width="1418" height="716" data-path="docs/images/customize/actions/modules/actions-modules-add-module.png" />
        </Frame>
      </Tab>
    </Tabs>
  </Step>

  <Step title="Action 内で Action Module を使用する" titleSize="h3" stepNumber={7}>
    それでは、Action 内で Action Module を使用してみましょう。

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

        ```javascript lines 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 lines theme={null}
        await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
        ```

        3. Action の **Deploy** を選択します。

        <Frame>
          <img src="https://mintcdn.com/translations/xwVvTWJUElMm5YAK/docs/images/customize/actions/modules/actions-modules-use-module.png?fit=max&auto=format&n=xwVvTWJUElMm5YAK&q=85&s=6b0d36fea2bfb8b4eeef8c46ec8b4b82" alt="Actions - Action Module を使用する" width="1418" height="674" data-path="docs/images/customize/actions/modules/actions-modules-use-module.png" />
        </Frame>
      </Tab>
    </Tabs>

    <Warning>
      Action は必ず Trigger にバインドしてください。
    </Warning>
  </Step>
</Steps>

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

  これで、**Action** で使用する、完全に機能する **Action Module** の準備が整いました。
</Check>

***

<div id="advanced-usage">
  ## 高度な使用方法
</div>

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

  <Tabs>
    <Tab title="ダッシュボード">
      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 パッケージ**の**名前**を入力します。
      4. **NPM パッケージ**の**バージョン**を入力します。
      5. **Create**を選択します。

      <Frame>
        <img src="https://mintcdn.com/translations/xwVvTWJUElMm5YAK/docs/images/customize/actions/modules/actions-modules-dependency.png?fit=max&auto=format&n=xwVvTWJUElMm5YAK&q=85&s=8446218fe5bd61de06e54c22d0d058a0" alt="Actions Modules - 依存関係を追加済み" width="1414" height="730" data-path="docs/images/customize/actions/modules/actions-modules-dependency.png" />
      </Frame>

      Auth0 によって、依存関係が Action Module の依存関係リストに追加されます。
    </Tab>
  </Tabs>

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

  <Warning>
    この Action を保存すると、Auth0 は依存関係の最新バージョンを解決し、今後のパッケージ更新で Action が動作しなくなるのを防ぐために、特定のバージョン番号に置き換えます。

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