Dev Guide
Dev GuideUser GuideGitHubNuGetDevCommunitySubmit a ticketLog In
GitHubNuGetDevCommunitySubmit a ticket

Lifecycle

OCP App SDK / Lifecycle

Lifecycle

Handler for all application lifecycle events, such as install, uninstall, etc

Index

Constructors

Methods

Constructors

constructor()

Signature

new Lifecycle(): Lifecycle;

Returns

Lifecycle

Methods

canUninstall()

Called before an app is uninstalled.

Signature

canUninstall(): Promise<CanUninstallResult>;

Returns

Promise<CanUninstallResult>

specifying if the app can be uninstalled and an optional user facing message.

Defined in: src/app/Lifecycle.ts:73

onAfterUpgrade()

Perform any actions, such as one scheduling one-time jobs, that can only be preformed after
the upgrade was successfully completed. This function is called after onFinalizeUpgrade
when the installation has been fully upgraded.

Signature

onAfterUpgrade(): Promise<LifecycleResult>;

Returns

Promise<LifecycleResult>

e.g., {success: true} if the call was successful.
If false, the app will remain at the new version?

Defined in: src/app/Lifecycle.ts:65

onAuthorizationGrant()

Handles inbound OAuth grants. This is triggered after a user grants access via an external OAuth endpoint. If
everything is in order, the result should provide a success message via toast and redirect to the next relevant
section of the settings form. If something went wrong, the result must provide appropriate error messages
and/or toasts and redirect to the originating settings form section.

Signature

Abstract onAuthorizationGrant(request: Request): Promise<AuthorizationGrantResult>;

Parameters

NameTypeDescription
requestRequestthe details of the inbound http request

Returns

Promise<AuthorizationGrantResult>

with appropriate settings redirect and messaging

Defined in: src/app/Lifecycle.ts:105

onAuthorizationRequest()

Handles outbound OAuth requests. This is triggered by an oauth_button on the settings form. The section of the
form and its data are given here, and this method should perform any necessary validation, persist changes to the
settings store, etc. If everything is in order, the result must provide a redirect to the external OAuth endpoint.
Otherwise, the result should provide appropriate error messages and/or toasts.

Signature

Abstract onAuthorizationRequest(section: string, formData: SubmittedFormData): Promise<LifecycleSettingsResult>;

Parameters

NameTypeDescription
sectionstringthe name of the section in which the oauth_button was clicked
formDataSubmittedFormDatathe data for the section as a hash of key/value pairs

Returns

Promise<LifecycleSettingsResult>

with a redirect to the external oauth endpoint

Defined in: src/app/Lifecycle.ts:93

onFinalizeUpgrade()

Perform any final actions, such as registering new functions that were added to this version.
This function is called after all functions have been created and migrated to this version.

Signature

Abstract onFinalizeUpgrade(fromVersion: string): Promise<LifecycleResult>;

Parameters

NameTypeDescription
fromVersionstringthe previous version of the app we are upgrading from

Returns

Promise<LifecycleResult>

e.g., {success: true} if the upgrade was successful.
If false, the app will be rolled back to the fromVersion.

Defined in: src/app/Lifecycle.ts:56

onInstall()

Called when an app is installed, before any other lifecycle methods can be used.
Peform any app specific pre-requisites here before the user is able to use or configure the app.

Signature

Abstract onInstall(): Promise<LifecycleResult>;

Returns

Promise<LifecycleResult>

e.g., {success: true} if the install was successful.
If false, the app will not be installed and any data stored will be deleted, however,
schema or other account changes are not transactional and will not be undone.

Defined in: src/app/Lifecycle.ts:25

onSettingsForm()

Handle a submission of a form section. You are responsible for performing any validation or
changes to the form data and then writing it to the settings store for the section.

Signature

Abstract onSettingsForm(section: string, action: string, formData: SubmittedFormData): Promise<LifecycleSettingsResult>;

Parameters

NameTypeDescription
sectionstringthe name of the section submitted
actionstringthe action of the button that triggered the call, or 'save' by default
formDataSubmittedFormDatathe data for the section as a hash of key/value pairs

Returns

Promise<LifecycleSettingsResult>

with any errors that should be displayed to the user

Defined in: src/app/Lifecycle.ts:35

onUninstall()

Perform any actions on the integrations platform to complete an uninstall, such as removing
webhooks pointing at this installation.

Signature

Abstract onUninstall(): Promise<LifecycleResult>;

Returns

Promise<LifecycleResult>

specify if the uninstall was successful. If false, it may be retried.

Defined in: src/app/Lifecycle.ts:82

onUpgrade()

Handle an upgrade. Perform any upgrade tasks here. All actions must be idempotent
and backwards compatible in case of an upgrade failure. This function is called before
functions are migrated to the new version.

Signature

Abstract onUpgrade(fromVersion: string): Promise<LifecycleResult>;

Parameters

NameTypeDescription
fromVersionstringthe previous version of the app we are upgrading from

Returns

Promise<LifecycleResult>

e.g., {success: true} if the upgrade was successful.
If false, the app will be rolled back to the fromVersion.

Defined in: src/app/Lifecycle.ts:47