@openfin/salesforce-lwc 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +16 -170
- package/openfin-salesforce-lwc-v1.1.0.tgz +0 -0
- package/openfin.salesforce-lwc.js +1 -0
- package/package.json +3 -3
- package/preload.js +1 -0
- package/{index.d.ts → types/index.d.ts} +0 -0
- package/types/lwc/lwc.d.ts +23 -0
- package/types/preload.d.ts +1 -0
- package/version.txt +1 -1
- package/api.js +0 -1
- package/lwc/lwc.d.ts +0 -14
- package/lwc/lwc.spec.d.ts +0 -1
- package/openfin-salesforce-lwc-v1.0.2.tgz +0 -0
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,170 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Salesforce Integration for Lightning Web Components
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
2
4
|
|
|
3
5
|
OpenFin’s Salesforce integration enables developers to create a two-way connection between [OpenFin Container](https://developers.openfin.co/of-docs/docs/container-overview) and [Salesforce](https://www.salesforce.com/). The integration consists of the following NPM packages:
|
|
4
6
|
|
|
5
7
|
- [@openfin/salesforce-lwc](https://www.npmjs.com/package/@openfin/salesforce-lwc): Connect custom Salesforce components with OpenFin Container (this package)
|
|
6
8
|
- [@openfin/salesforce](https://www.npmjs.com/package/@openfin/salesforce): Connect OpenFin Container with Salesforce
|
|
7
9
|
|
|
8
|
-
## Introduction
|
|
9
|
-
|
|
10
10
|
Running Salesforce in OpenFin is a popular requirement, with developers naturally wanting to take advantage of the extensive APIs provided by both Salesforce and OpenFin. However, Salesforce’s [Lightning Locker](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_code.htm) security feature restricts access to all non-core web APIs including those provided by [OpenFin Container](https://developers.openfin.co/of-docs/docs/container-overview).
|
|
11
11
|
|
|
12
|
-
To enable interoperability, OpenFin and Salesforce worked together to find a solution that enables custom Salesforce components to access OpenFin
|
|
13
|
-
|
|
14
|
-
## Prerequisites
|
|
15
|
-
|
|
16
|
-
### OpenFin
|
|
17
|
-
|
|
18
|
-
If you are not already familiar with building apps for OpenFin Container, follow this [guide](https://developers.openfin.co/of-docs/docs/set-up-your-dev-environment) to help you get started.
|
|
19
|
-
|
|
20
|
-
### Salesforce
|
|
21
|
-
|
|
22
|
-
The OpenFin Salesforce integration can be used with any Salesforce org, however you will need the admin role to apply the required configuration changes. Alternatively, sign up at [developer.salesforce.com](https://developer.salesforce.com/) for a free developer org which you can use without restriction.
|
|
23
|
-
|
|
24
|
-
If you are not already familiar with how to develop components for Salesforce, follow this [guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm) for an introduction.
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
27
|
-
|
|
28
|
-
First, add the package as a dependency for your app.
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
npm install @openfin/salesforce-lwc
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
or
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
yarn add @openfin/salesforce-lwc
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Using OpenFin APIs from Salesforce components
|
|
41
|
-
|
|
42
|
-
### Add this package to your Salesforce org as a static resource
|
|
43
|
-
|
|
44
|
-
To load this package from within a Salesforce component, you first need to add it as a [static resource](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_resources.htm) in your Salesforce org.
|
|
45
|
-
|
|
46
|
-
**Note**: The compiled JavaScript file can be found in the `@openfin/salesforce-lwc` folder within your OpenFin app’s `node_modules` folder after installing this package.
|
|
47
|
-
|
|
48
|
-
1. On the main Setup page for your org, search for "static resources" and click on the relevant result.
|
|
49
|
-
2. Click **New** to add a new static resource.
|
|
50
|
-
3. Complete the form as directed:
|
|
51
|
-
- **Name**: `openfin_salesforce_lwc`
|
|
52
|
-
- **Description**: "Client library for enabling the use of OpenFin’s Javascript APIs in Salesforce components."
|
|
53
|
-
- **File**: `<path_to_app_node_modules>/@openfin/salesforce-lwc/api.js`
|
|
54
|
-
- **Cache Control**: Public
|
|
55
|
-
4. Click **Save** to create the static resource.
|
|
12
|
+
To enable interoperability, OpenFin and Salesforce worked together to find a solution that enables custom Salesforce components to access OpenFin APIs and use them just like any other app. The result of this collaboration is the Salesforce integration for Lightning web components, which is supported by Salesforce for current and future versions of Lightning Locker.
|
|
56
13
|
|
|
57
|
-
|
|
14
|
+
## Code example
|
|
58
15
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
An app that uses this package needs to run a preload script that calls the `prepareFinApiInPreload()` function:
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
// preload.ts
|
|
65
|
-
|
|
66
|
-
import { prepareFinApiInPreload } from '@openfin/salesforce-lwc';
|
|
67
|
-
|
|
68
|
-
(() => {
|
|
69
|
-
// Prepare OpenFin LWC support
|
|
70
|
-
prepareFinApiInPreload();
|
|
71
|
-
})();
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Note**: Using a bundling tool such as [webpack](https://webpack.js.org/) ensures that required dependencies are included with your compiled preload script.
|
|
75
|
-
|
|
76
|
-
### Add the preload script to your app
|
|
77
|
-
|
|
78
|
-
To ensure the compiled preload script is run before app content is loaded, it must be added to your OpenFin app’s manifest.
|
|
79
|
-
|
|
80
|
-
#### For platform applications
|
|
81
|
-
|
|
82
|
-
When using a [platform](https://developers.openfin.co/of-docs/docs/platform-getting-started) application, preload scripts can be added in three places:
|
|
83
|
-
|
|
84
|
-
- Platform level: add `preloadScripts` to the `platform` property in the manifest:
|
|
85
|
-
|
|
86
|
-
```jsonc
|
|
87
|
-
{
|
|
88
|
-
"platform": {
|
|
89
|
-
"preloadScripts": [
|
|
90
|
-
{
|
|
91
|
-
"url": "https://path.to/your/preload_script.js"
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
// ...
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
- Window level: add `preloadScripts` to the `defaultWindowOptions` property in the manifest:
|
|
100
|
-
|
|
101
|
-
```jsonc
|
|
102
|
-
{
|
|
103
|
-
"platform": {
|
|
104
|
-
"defaultWindowOptions": {
|
|
105
|
-
"preloadScripts": [
|
|
106
|
-
{
|
|
107
|
-
"url": "https://path.to/your/preload_script.js"
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// ...
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
- View level: add `preloadScripts` to the `defaultViewOptions` property in the manifest:
|
|
117
|
-
|
|
118
|
-
```jsonc
|
|
119
|
-
{
|
|
120
|
-
"platform": {
|
|
121
|
-
"defaultViewOptions": {
|
|
122
|
-
"preloadScripts": [
|
|
123
|
-
{
|
|
124
|
-
"url": "https://path.to/your/preload_script.js"
|
|
125
|
-
}
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// ...
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
#### For non-platform applications
|
|
134
|
-
|
|
135
|
-
If your app is a traditional OpenFin app with a `startup_app` entry, add `preloadScripts` to the `startup_app` property in the manifest:
|
|
136
|
-
|
|
137
|
-
```jsonc
|
|
138
|
-
{
|
|
139
|
-
"startup_app": {
|
|
140
|
-
"preloadScripts": [
|
|
141
|
-
{
|
|
142
|
-
"url": "https://path.to/your/preload_script.js"
|
|
143
|
-
}
|
|
144
|
-
]
|
|
145
|
-
}
|
|
146
|
-
// ...
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
### Call the OpenFin API within a custom Salesforce component
|
|
152
|
-
|
|
153
|
-
#### For Lightning web components
|
|
154
|
-
|
|
155
|
-
To use the API in a Lightning web component, you must first load the static resource as a [third-party library](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_third_party_library).
|
|
156
|
-
|
|
157
|
-
With the static resource loaded, the API functions are added to `window.fin.salesforce`. Call the `initFinApiInLwc()` function before calling any OpenFin API functions via `window.fin`:
|
|
158
|
-
|
|
159
|
-
```ts
|
|
160
|
-
// Initialise window.fin for use
|
|
161
|
-
window.fin.salesforce.initFinApiInLwc();
|
|
162
|
-
|
|
163
|
-
// window.fin is now ready to use
|
|
164
|
-
const runtimeInfo = await window.fin.System.getRuntimeInfo();
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
Here is a complete example of a Lightning web component loading the static resource and using the OpenFin JS API:
|
|
16
|
+
Below is an example of a custom Lightning web component loading the Salesforce integration for Lightning web components as a static resource in order to access the OpenFin API:
|
|
168
17
|
|
|
169
18
|
```ts
|
|
170
19
|
// myComponent.js
|
|
@@ -176,29 +25,26 @@ import { LightningElement } from 'lwc';
|
|
|
176
25
|
export default class OpenfinIntegrationTest extends LightningElement {
|
|
177
26
|
async connectedCallback() {
|
|
178
27
|
try {
|
|
179
|
-
await loadScript(this,
|
|
28
|
+
await loadScript(this, finApi);
|
|
180
29
|
} catch (err) {
|
|
181
30
|
console.warn('Failed to load static resource, has it been added in Salesforce org settings?');
|
|
182
|
-
return;
|
|
183
31
|
}
|
|
184
32
|
|
|
185
|
-
//
|
|
33
|
+
// Initialize window.fin for use
|
|
186
34
|
window.fin.salesforce.initFinApiInLwc();
|
|
187
35
|
|
|
36
|
+
// Check that the OpenFin API is available before continuing
|
|
37
|
+
if (!window.fin.System?.isOpenFinEnvironment()) {
|
|
38
|
+
console.warn('OpenFin API not available, exiting');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
188
42
|
// Output the current OpenFin runtime info to the console
|
|
189
43
|
console.log(await window.fin.System.getRuntimeInfo());
|
|
190
44
|
}
|
|
191
45
|
}
|
|
192
46
|
```
|
|
193
47
|
|
|
194
|
-
|
|
48
|
+
## Getting started
|
|
195
49
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
```xml
|
|
199
|
-
<aura:component>
|
|
200
|
-
<ltng:require
|
|
201
|
-
scripts="{!$Resource.openfin_salesforce_lwc}"
|
|
202
|
-
afterScriptsLoaded="{!c.scriptsLoaded}" />
|
|
203
|
-
</aura:component>
|
|
204
|
-
```
|
|
50
|
+
Refer to the [developer documentation](https://developers.openfin.co/of-docs/docs/salesforce-integration) in order to begin using the Salesforce integration, where you will also find additional code examples and the full API reference.
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.fin=n():(e.fin=e.fin||{},e.fin.salesforce=n())}(self,(function(){return(()=>{"use strict";var e={d:(n,o)=>{for(var i in o)e.o(o,i)&&!e.o(n,i)&&Object.defineProperty(n,i,{enumerable:!0,get:o[i]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{initFinApiInLwc:()=>i,prepareFinApiInPreload:()=>o});const o=()=>{void 0!==window.fin&&(CustomEvent.prototype.fin=window.fin,CustomEvent.prototype.fdc3=window.fdc3)},i=()=>{const e=new CustomEvent(""),n=e.fin;if(void 0===n)return void console.warn("Unable to locate fin API. Ensure Salesforce is running in OpenFin and 'prepareFinApiInPreload' is run in a preload script before attempting to call 'initFinApiInLwc'.");void 0!==window.fin?Object.assign(window.fin,n):window.fin=n;const o=e.fdc3;void 0!==window.fdc3?Object.assign(window.fdc3,o):window.fdc3=o};return n})()}));
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfin/salesforce-lwc",
|
|
3
3
|
"description": "Connect custom Salesforce components with OpenFin Container",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"author": "OpenFin Inc.",
|
|
6
6
|
"homepage": "https://www.openfin.co/",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"main": "
|
|
9
|
-
"types": "index.d.ts"
|
|
8
|
+
"main": "openfin.salesforce-lwc.js",
|
|
9
|
+
"types": "types/index.d.ts"
|
|
10
10
|
}
|
package/preload.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.fin=o():(e.fin=e.fin||{},e.fin.salesforce=o())}(self,(function(){return(()=>{"use strict";var e={};return(e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})})(e),void 0!==window.fin&&(CustomEvent.prototype.fin=window.fin,CustomEvent.prototype.fdc3=window.fdc3),e})()}));
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="openfin" />
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
fdc3: typeof fdc3;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
export declare type CustomFinEvent = CustomEvent & {
|
|
11
|
+
fin: typeof fin;
|
|
12
|
+
fdc3: typeof fdc3;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Prepares the OpenFin API for use in custom Salesforce components.
|
|
16
|
+
*
|
|
17
|
+
* Note: This function must be run in a preload script before any Salesforce content is loaded.
|
|
18
|
+
*/
|
|
19
|
+
export declare const prepareFinApiInPreload: () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the OpenFin API for use in custom Salesforce components.
|
|
22
|
+
*/
|
|
23
|
+
export declare const initFinApiInLwc: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0
|
|
1
|
+
1.1.0
|
package/api.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.fin=n():(e.fin=e.fin||{},e.fin.salesforce=n())}(self,function(){return(()=>{"use strict";var t={114:function(e,n,i){var t=this&&this.__createBinding||(Object.create?function(e,n,i,t){void 0===t&&(t=i),Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[i]}})}:function(e,n,i,t){e[t=void 0===t?i:t]=n[i]}),o=this&&this.__exportStar||function(e,n){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(n,i)||t(n,e,i)};Object.defineProperty(n,"__esModule",{value:!0}),o(i(81),n)},81:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.initFinApiInLwc=n.prepareFinApiInPreload=void 0,n.prepareFinApiInPreload=()=>{void 0!==window.fin&&(CustomEvent.prototype.fin=window.fin)},n.initFinApiInLwc=()=>{var e=new CustomEvent("").fin;if(void 0===e)throw new Error("fin API is undefined. Ensure 'prepareFinApiInPreload' is run in a preload script before attempting to call 'initFinApiInLwc'.");void 0===window.fin?window.fin=e:Object.assign(window.fin,e)}}},o={};return function e(n){var i=o[n];if(void 0!==i)return i.exports;i=o[n]={exports:{}};return t[n].call(i.exports,i,i.exports,e),i.exports}(114)})()});
|
package/lwc/lwc.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="openfin" />
|
|
2
|
-
export declare type CustomFinEvent = CustomEvent & {
|
|
3
|
-
fin: typeof fin;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Prepares `fin` API to be used in a Lightning Web Component.
|
|
7
|
-
* This function should be run in a preload script before any Salesforce content is loaded.
|
|
8
|
-
*/
|
|
9
|
-
export declare const prepareFinApiInPreload: () => void;
|
|
10
|
-
/**
|
|
11
|
-
* Restores the `fin` API object to `window` in the context of a Lightning Web Component.
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
export declare const initFinApiInLwc: () => void;
|
package/lwc/lwc.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'jest';
|
|
Binary file
|