Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Dev Guide
Dev GuideUser GuidesGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

OCP App SDK


OCP App SDK / Lifecycle

Class: abstract Lifecycle

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

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

Constructors

Constructor

new Lifecycle(): Lifecycle

Returns

Lifecycle

Methods

canUninstall()

canUninstall(): Promise<CanUninstallResult>

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

Called before an app is uninstalled.

Returns

Promise<CanUninstallResult>

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


onAfterUpgrade()

onAfterUpgrade(): Promise<LifecycleResult>

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

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.

Returns

Promise<LifecycleResult>

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


onAuthorizationGrant()

abstract onAuthorizationGrant(request): Promise<AuthorizationGrantResult>

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

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.

Parameters

request

Request

the details of the inbound http request

Returns

Promise<AuthorizationGrantResult>

with appropriate settings redirect and messaging


onAuthorizationRequest()

abstract onAuthorizationRequest(section, formData): Promise<LifecycleSettingsResult>

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

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.

Parameters

section

string

the name of the section in which the oauth_button was clicked

formData

SubmittedFormData

the data for the section as a hash of key/value pairs

Returns

Promise<LifecycleSettingsResult>

with a redirect to the external oauth endpoint


onFinalizeUpgrade()

abstract onFinalizeUpgrade(fromVersion): Promise<LifecycleResult>

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

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.

Parameters

fromVersion

string

the 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.


onInstall()

abstract onInstall(): Promise<LifecycleResult>

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

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.

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.


onSettingsForm()

abstract onSettingsForm(section, action, formData): Promise<LifecycleSettingsResult>

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

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.

Parameters

section

string

the name of the section submitted

action

string

the action of the button that triggered the call, or 'save' by default

formData

SubmittedFormData

the data for the section as a hash of key/value pairs

Returns

Promise<LifecycleSettingsResult>

with any errors that should be displayed to the user


onUninstall()

abstract onUninstall(): Promise<LifecycleResult>

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

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

Returns

Promise<LifecycleResult>

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


onUpgrade()

abstract onUpgrade(fromVersion): Promise<LifecycleResult>

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

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.

Parameters

fromVersion

string

the 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.