Extensions.yaml 的參考資料

擴充功能的規格檔案 (extension.yaml) 包含擴充功能的中繼資料、宣告擴充功能建立的資源、擴充功能所需的 API 和存取權,以及定義擴充功能提供的任何使用者設定參數。

本頁表格說明 extension.yaml 檔案可用的欄位。

基本和識別資訊

name: your-extension-name
version: 1.0.0         # Semantic versioning (semver)
specVersion: v1beta    # Always "v1beta"
license: Apache-2.0    # Always "Apache-2.0" (required to publish on extensions.dev)
billingRequired: true  # Always "true"

displayName: Your extension name
description: >-
  Description of the extension. (One or two
  sentences.)
icon: icon.png
tags: [tag, anothertag]

sourceUrl: https://github.com/your-org/your-repo   # GitHub repo URL
releaseNotesUrl: https://github.com/your-org/your-repo/blob/main/CHANGELOG.md

author:
  authorName: Your Company
  email: extensions@example.com
  url: https://example.com/
contributors:
  - authorName: Your Name
  - authorName: Another Contributor
    email: colleague@example.net
    url: https://github.com/their-org/
基本欄位
name
字串
(必填)

擴充功能的 ID。

只能使用小寫英文字母、數字和破折號,長度上限為 40 個字元。

注意:這個值會用於產生擴充功能的執行個體 ID (接著用於產生擴充功能的服務帳戶名稱和擴充功能專屬資源)。

version
字串
(必填)

擴充功能版本。

必須採用語意化版本編號 (例如 1.2.0)。

specVersion
字串
(必填)

Firebase Extensions 規格的版本。

目前的值:v1beta

license
字串
(選填)

擴充功能的授權。

擴充功能必須使用 Apache-2.0 授權。

billingRequired
boolean
(選填)

擴充功能使用的服務是否需要付費級 Firebase 帳單帳戶。

一律設為 true。

displayName
字串
(選填)

擴充功能的易記顯示名稱 (3 到 5 個字)。

字元限制為 40 個半形字元。

description
字串
(選填)
簡短說明擴充功能執行的工作 (約 1 句)。
icon
字串
(選填)

在 extensions.dev 和 Firebase 控制台中,做為擴充功能圖示的檔案。

這個檔案必須是正方形 PNG 圖片,尺寸介於 512x512 到 1024x1024 像素之間。 將檔案放在與 extension.yaml 相同的目錄中;您無法指定子目錄。

設計擴充功能圖示時,請遵守下列規範:

  • 選取適合品牌的背景和圖片顏色。
  • 圖示顏色應保持簡單,只使用 2 種顏色。多種顏色可能會讓圖示看起來過於雜亂。
  • 基於相同原因,請勿在圖示中使用漸層。漸層在小尺寸時難以辨識,且會使圖示在視覺上變得複雜。
  • 使用簡單、獨特的圖像,傳達擴充功能的功能。
  • 如果貴公司建構多個擴充功能,請勿使用貴公司的標誌做為圖示。使用者將難以區分您的擴充功能。
  • 圖片應醒目大膽。請勿使用精緻或複雜的圖片,因為這類圖片在較小的尺寸下無法正常顯示。
  • 請勿加入說明擴充功能用途的字詞。文字在較小的尺寸下通常難以辨識。
tags
字串清單
(選用)
可協助使用者找到擴充功能的標記。 下列標記會對應至 Extensions Hub 上的類別:marketing、messaging、payments、search、shipping、social、utilities、ai
sourceUrl
字串
(選填)
可存取擴充功能目錄的公開網址。
releaseNotesUrl
字串
(選填)
可存取擴充功能版本資訊的公開網址。
author
一個作者物件
(選用)

擴充功能的主要作者和聯絡窗口。

author:
  authorName: Your Company
  email: extensions@example.com
  url: https://example.com/
作者欄位
authorName
字串
(必填)

作者名稱。

可以是個人、公司、機構等。

email
字串
(選填)
作者的電子郵件地址。
url
字串
(選填)
可存取作者資訊的公開網址。
contributors
作者物件清單
(選用)

擴充功能的其他協作作者。

contributors:
  - authorName: Your Name
  - authorName: Another Contributor
    email: colleague@example.net
    url: https://github.com/their-org/
作者欄位
authorName
字串
(必填)

作者名稱。

可以是個人、公司、機構等。

email
字串
(選填)
作者的電子郵件地址。
url
字串
(選填)
可存取作者資訊的公開網址。

Firebase 和 Google Cloud API

這些欄位會指定擴充功能使用的 Firebase 和 Google API。使用者安裝擴充功能時,可以選擇在專案中自動啟用這些 API。

apis:
  - apiName: apiname.googleapis.com
    reason: Explanation of why the extension uses this API
  - apiName: anotherapiname.googleapis.com
    reason: Explanation of why the extension uses this API
API 欄位
apiName
字串
(必填)

Google API 名稱

必須與 Google Cloud API 程式庫中各 API 總覽頁面 (範例) 所列的「服務名稱」欄位相符

reason
字串
(必填)
簡短說明擴充功能為何需要使用這個 API

IAM 角色

這些欄位會指定擴充功能所需的 Cloud IAM 角色。為擴充功能佈建的服務帳戶會取得這些角色。

您只能指定其中一個支援的角色。

roles:
  - role: product.role
    reason: Explanation of why the extension needs this level of access
  - role: anotherproduct.role
    resource: projects/${project_id}/resource_type/*
    reason: Explanation of why the extension needs this level of access
角色欄位
role
字串
(必填)

擴充功能運作所需的 IAM 角色名稱

必須是支援的角色之一

reason
字串
(必填)
簡短說明擴充功能為何需要這個角色授予的存取權
resource
字串
(選填)

將角色的範圍限制在這項資源。

如省略,則預設為 projects/${project_id}。 請參閱「縮小角色範圍」。

外部服務

這些欄位會指定擴充功能使用的非 Firebase 和非 Google 服務 (通常是 REST API)。Firebase Extensions 平台不提供任何自動啟用或授權這些服務的方法。

externalServices:
  - name: Example API
    pricingUri: https://developers.example.com/pricing
  - name: Another Example API
    pricingUri: https://developers.example.com/pricing
外部服務欄位
name
字串
(必填)
擴充功能運作所需的外部服務名稱
pricingUri
字串
(必填)
服務定價資訊的 URI

使用者可設定的參數

這些欄位定義了擴充功能提供給使用者設定的參數。

params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      What do you want to set PARAM_ID to?
      This is a longer description of the parameter, often phrased as a prompt
      to the user.
  - param: ANOTHER_PARAM_ID
    label: Short description of the parameter
    description: >
      What do you want to set ANOTHER_PARAM_ID to?
      This is a longer description of the parameter.
    example: example-input
    validationRegex: "^[a-zA-Z][a-zA-Z-]*[a-zA-Z]?$"
    validationErrorMessage:
      Must be a hyphen-delimited string of alphabetic characters
    default: default-value
    required: false
    immutable: true
參數欄位
param
字串
(必填)
參數名稱。您可以使用這個名稱在程式碼中參照參數值。
label
字串
(必填)
參數的簡短說明。系統提示使用者輸入參數值時,會顯示這段文字。
description
字串
(選填)

參數的詳細說明。系統提示使用者輸入參數值時,會顯示這段文字。

支援 Markdown。

example
字串
(選填)
參數範例值。
default
字串
(選填)
如果使用者將參數值留空,則為參數的預設值。
validationRegex
字串
(選填)
用於驗證參數使用者設定值的規則運算式。Google RE2 語法。
validationErrorMessage
字串
(選填)
規則運算式驗證失敗時顯示的錯誤訊息。
required
boolean
(選填)
定義使用者在系統提示輸入參數值時,是否可以提交空白字串。預設為 true。
immutable
boolean
(選填)

定義使用者是否能在安裝後變更參數值 (例如重新設定擴充功能)。預設值為 false。

注意:如果您為擴充功能部署的函式定義了「location」參數,請將這個欄位設為 true。

type
字串
(選填)
參數類型。特殊參數類型可能會有額外規定或不同的 UI 呈現方式。請參閱下列各節。

可選取和多選的參數

可選取和多選參數會提示使用者從預先定義的選項清單中選擇。

params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      Do you want to enable the option?
    type: select
    options:
      - label: Yes
        value: true
      - label: No
        value: false
  - param: ANOTHER_PARAM_ID
    label: Short description of the parameter
    description: >-
      Which options do you want to enable?
    type: multiSelect
    options:
      - value: red
      - value: green
      - value: blue
複選參數欄位
type
字串

select或multiSelect

指定參數可以是一組預先定義選項中的一個值 (select) 或多個值 (multiSelect)

options
選項清單
(必填)

使用者可選擇的選項

選項欄位
value
字串
(必填)
使用者可選擇的值。在程式碼中讀取參數值時,您會取得這個值。
label
字串
(選填)
可選取選項的簡短說明。如省略,則預設為 value。

可選資源參數

可選取的資源參數會提示使用者從專案中選取資源 (資料庫執行個體、儲存空間 bucket 等)。

params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      Which resource do you want to use?
    type: selectresource
    resourceType: product.googleapis.com/ResourceType
資源參數欄位
type
字串

selectresource

指定參數代表專案資源

resourceType
字串
(必填)

提示使用者選取的資源類型。

有效值:

  • storage.googleapis.com/Bucket
  • firestore.googleapis.com/Database
  • firebasedatabase.googleapis.com/DatabaseInstance

不過,目前只有 Cloud Storage bucket 具備選取 UI (其他資源類型則會顯示為任意形式的文字輸入欄位)。

密鑰參數

使用者提供的密鑰值 (例如 API 金鑰) 則會以不同方式處理:

  • Secret 值會使用 Cloud Secret Manager 儲存。只有授權用戶端 (例如已安裝的擴充功能執行個體) 才能存取這些值。
  • 系統提示使用者提供這些值時,不會顯示他們輸入的內容。
params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      What is the secret value?
    type: secret
Secret 參數欄位
type
字串

secret

指定參數為密鑰值

Cloud 函式資源

這些欄位會宣告擴充功能中包含的 Cloud Functions。第 1 代和第 2 代函式的資源宣告語法略有不同,兩者可並存於擴充功能中。

第 1 代 Cloud Functions

resources:
  - name: functionName
    type: firebaseextensions.v1beta.function
    description: >-
      Description of what the function does. (One or two
      sentences.)
    properties:
      runtime: runtime-version
      eventTrigger:
        eventType: google.product.event
        resource: projects/_/resource/specifier
資源欄位
name
字串
(必填)

匯出函式的易記名稱。

如未指定 entryPoint 屬性 (請見下方說明),這個值必須與函式原始碼中的函式名稱相符。

「已部署」函式的最終名稱會採用下列格式:ext-extension-instance-id-name。

type
字串
(必填)
第 1 代函式資源: firebaseextensions.v1beta.function
description
字串
(必填)

簡短說明函式為擴充功能執行的工作。

properties
(必要)

第 1 代 Cloud Functions 屬性。以下列出最重要的屬性,但您可以在 Cloud Functions 參考資料中找到完整清單。

資源
location
(選填)

部署函式的位置。預設為 us-central1

entryPoint
(選填)
擴充功能應在函式原始碼中尋找的匯出函式名稱。預設為上述 name 的值。
sourceDirectory
(選填)

根目錄中包含 package.json 的目錄。函式原始碼檔案必須位於這個目錄中。預設為 functions

注意:package.json 的 main 欄位會指定函式原始碼的檔案 (例如 index.js)。

timeout
(選填)

函式的執行時間上限。

  • 預設:60s
  • 最大值:540s
availableMemoryMb
(選填)

函式可用的記憶體量 (MB)。

  • 預設:256
  • 有效值:128、256、512、1024 和 2048
runtime
(建議)

函式的執行階段環境。

httpsTrigger
或
eventTrigger
或
scheduleTrigger
或
taskQueueTrigger
(必須提供其中一種函式觸發條件類型)
如要瞭解各個觸發條件類型的具體資訊,請參閱「編寫擴充功能的 Cloud Functions」。

第 2 代 Cloud Functions

resources:
  - name: functionName
    type: firebaseextensions.v1beta.v2function
    description: >-
      Description of what the function does. (One or two
      sentences.)
    properties:
      buildConfig:
        runtime: nodejs16
      serviceConfig:
        availableMemory: 512M
      eventTrigger:
        eventType: google.firebase.firebasealerts.alerts.v1.published
        triggerRegion: global
        eventFilters:
          - attribute: alerttype
            value: crashlytics.newFatalIssue

資源欄位
name
字串
(必填)

匯出函式的易記名稱。

如未指定 entryPoint 屬性 (請見下方說明),這個值必須與函式原始碼中的函式名稱相符。

「已部署」函式的最終名稱會採用下列格式:ext-extension-instance-id-name。

type
字串
(必填)
第 2 代函式資源: firebaseextensions.v1beta.v2function
description
字串
(必填)

簡短說明函式為擴充功能執行的工作。

properties
(必要)

第 2 代 Cloud Functions 屬性。以下列出最重要的屬性,如需完整清單,請參閱 Cloud Functions 參考資料。

資源
location
(選填)

部署函式的位置。預設為 us-central1

sourceDirectory
(選填)

根目錄中包含 package.json 的目錄。函式原始碼檔案必須位於這個目錄中。預設為 functions

注意:package.json 的 main 欄位會指定函式原始碼的檔案 (例如 index.js)。

另外還有三個物件類型欄位,各有專屬屬性:

buildConfig 屬性
buildConfig.runtime
(建議)

函式的執行階段環境。

buildConfig.entryPoint
(選填)
擴充功能應在函式原始碼中尋找的匯出函式名稱。預設為上述 name 的值。
serviceConfig 屬性
serviceConfig.timeoutSeconds
(選填)

函式的執行時間上限。

  • 預設:60
  • 最大值:540
serviceConfig.availableMemory
(選填)
函式可用的記憶體量。預設值為 256M。支援的單位為 k、M、G、Mi、Gi。如未提供單位,系統會將值解讀為位元組。
eventTrigger 屬性
eventTrigger.eventType
(必填)
要監聽的事件類型。如要瞭解各項產品適用的事件類型,請參閱「編寫擴充功能的 Cloud Functions」。
eventTrigger.eventFilters
(選填)
進一步限制要監聽事件的篩選器。例如,您可以只監聽符合特定資源模式的事件。如要瞭解如何篩選各類事件,請參閱「編寫擴充功能的 Cloud Functions」。
eventTrigger.channel
(選填)
與觸發條件相關聯的管道名稱,格式為 projects/{project}/locations/{location}/channels/{channel}。如果省略這個屬性,函式會監聽專案預設管道中的事件。
eventTrigger.triggerRegion
(選填)
觸發條件只會接收源自這個區域的事件。 可以是與函式相同的區域、不同的區域或多區域,或是全球區域。如未提供,則預設為與函式相同的區域。

生命週期事件

生命週期事件可讓您指定在使用者安裝、更新或設定擴充功能執行個體時執行的函式。請參閱「處理擴充功能的生命週期事件」。

lifecycleEvents:
  onInstall:
    function: myTaskFunction
    processingMessage: Describes the task being completed
  onUpdate:
    function: myOtherTaskFunction
    processingMessage: Describes the task being completed
  onConfigure:
    function: myOtherTaskFunction
    processingMessage: Describes the task being completed
生命週期事件欄位
onInstall
(選填)

指定使用者安裝擴充功能時執行的函式。

函式規格
function
字串
(必填)

由工作佇列觸發、用於處理事件的函式名稱。

這個函式必須在 resources 區段中宣告,並定義 taskQueue。

processingMessage
字串
(必填)
工作進行期間,Firebase 控制台會顯示這則訊息。
onUpdate
(選填)

指定使用者更新擴充功能時執行的函式。

函式規格
function
字串
(必填)

由工作佇列觸發、用於處理事件的函式名稱。

這個函式必須在 resources 區段中宣告,並定義 taskQueue。

processingMessage
字串
(必填)
工作進行期間,Firebase 控制台會顯示這則訊息。
onConfigure
(選填)

指定使用者重新設定擴充功能時執行的函式。

函式規格
function
字串
(必填)

由工作佇列觸發、用於處理事件的函式名稱。

這個函式必須在 resources 區段中宣告,並定義 taskQueue。

processingMessage
字串
(必填)
工作進行期間,Firebase 控制台會顯示這則訊息。

自訂事件 (Eventarc)

自訂事件是擴充功能發出的事件,可讓使用者將自己的邏輯插入擴充功能。請參閱「在擴充功能中新增使用者掛鉤」的「Eventarc」一節。

events:
  - type: publisher-id.extension-name.version.event-name
    description: Description of the event
  - type: publisher-id.extension-name.version.another-event-name
    description: Description of the other event
自訂事件欄位
type
字串
(必填)
事件的類型 ID。請使用 3 到 4 個以點分隔的欄位建構 ID:發布商 ID、擴充功能名稱和事件名稱欄位為必填,建議填寫版本欄位。為發布的每種事件類型選擇不重複且具描述性的事件名稱。
description
字串
(必填)
事件說明。