@openfin/salesforce-lwc 1.0.0 → 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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 OpenFin Ltd
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 OpenFin Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,196 +1,50 @@
1
- # OpenFin Salesforce Integration
2
-
3
- ## Introduction
4
-
5
- Running Salesforce’s modular components in OpenFin windows is a popular requirement. 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 OpenFin's [JavaScript API](https://developers.openfin.co/docs/javascript-api).
6
-
7
- To enable this interoperability, OpenFin and Salesforce worked together to produce this API that enables custom Salesforce components to access OpenFin's JavaScript API as normal. As a result, the solution offered by this API is supported by Salesforce for current and future versions of Lightning Locker.
8
-
9
- ## Prerequisites
10
-
11
- ### OpenFin
12
-
13
- Download the latest version of the OpenFin RVM [here](https://developer.openfin.co/versions/?product=RVM) and follow the [getting started guide](https://developers.openfin.co/docs/getting-started).
14
-
15
- ### Salesforce
16
-
17
- Use an existing Salesforce org, or Salesforce offers [a free development environment](https://developer.salesforce.com/signup). To do development work with Salesforce (including setting up the CLI so you can write apps), follow [these instructions](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm).
18
-
19
- ## Installation
20
-
21
- First, add the package as a dependency for your app.
22
-
23
- ```
24
- npm install @openfin/salesforce-lwc
25
- ```
26
-
27
- or
28
-
29
- ```
30
- yarn add @openfin/salesforce-lwc
31
- ```
32
-
33
- ## Using the API
34
-
35
- ### Create a preload script
36
-
37
- The OpenFin app that Salesforce will be running in will need to run a preload script that calls the `prepareFinApiInPreload` API function:
38
-
39
- ```ts
40
- // preload.ts
41
-
42
- import { prepareFinApiInPreload } from '@openfin/salesforce-lwc';
43
-
44
- (() => {
45
- // Prepare OpenFin LWC support
46
- prepareFinApiInPreload();
47
- })();
48
- ```
49
-
50
- Note: Using a bundling tool such as [webpack](https://webpack.js.org/) will ensure that required dependencies are included with your compiled preload script.
51
-
52
- ### Add the preload script to your app
53
-
54
- To ensure the compiled preload script is run before app content is loaded, it must be added to your OpenFin app's manifest.
55
-
56
- #### **For platform applications**
57
-
58
- When using a [platform](https://developers.openfin.co/docs/platform-api) application, preload scripts can be added in three places:
59
-
60
- - Platform level - add `preloadScripts` to the `platform` property in your config:
61
-
62
- ```jsonc
63
- {
64
- "platform": {
65
- "preloadScripts": [
66
- {
67
- "url": "https://path.to/your/preload_script.js"
68
- }
69
- ]
70
- }
71
- // ...
72
- }
73
- ```
74
-
75
- - Window level - add `preloadScripts` to the `defaultWindowOptions` property in your config:
76
-
77
- ```jsonc
78
- {
79
- "platform": {
80
- "defaultWindowOptions": {
81
- "preloadScripts": [
82
- {
83
- "url": "https://path.to/your/preload_script.js"
84
- }
85
- ]
86
- }
87
- }
88
- // ...
89
- }
90
- ```
91
-
92
- - View level - add `preloadScripts` to the `defaultViewOptions` property in your config:
93
-
94
- ```jsonc
95
- {
96
- "platform": {
97
- "defaultViewOptions": {
98
- "preloadScripts": [
99
- {
100
- "url": "https://path.to/your/preload_script.js"
101
- }
102
- ]
103
- }
104
- }
105
- // ...
106
- }
107
- ```
108
-
109
- Use the relevant option for where you intend to load the Salesforce org in your application - in the window or in a view.
110
-
111
- #### **For non-platform applications**
112
-
113
- If it is a traditional OpenFin app with a `startup_app` entry then add add `preloadScripts` to the `startup_app` property in your config:
114
-
115
- ```jsonc
116
- {
117
- "startup_app": {
118
- "preloadScripts": [
119
- {
120
- "url": "https://path.to/your/preload_script.js"
121
- }
122
- ]
123
- }
124
- // ...
125
- }
126
- ```
127
-
128
- ### Add the API to your Salesforce org as a static resource
129
-
130
- To load this API from within a Salesforce component you will 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.
131
-
132
- _Note: the compiled API JS file can be found in the `@openfin/salesforce-lwc` folder within your OpenFin app's `node_modules` folder after installing this package_.
133
-
134
- 1. On the main Setup page for your org, search for "static resources" and click on the relevant result.
135
- 2. Click the "New" button to add a new static resource.
136
- 3. Complete the form as directed:
137
- - Name: "openfin_salesforce_lwc"
138
- - Description: "Client library for enabling the use of OpenFin's Javascript API in Salesforce components."
139
- - File: "<path_to_app_node_modules>/@openfin/salesforce-lwc/api.js"
140
- - Cache Control: "Public"
141
- 4. Click "Save" to create the static resource.
142
-
143
- ### Call the API within a custom Salesforce component
144
-
145
- #### **For Lightning web components**
146
-
147
- To use the API in your lLightning 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).
148
-
149
- Once the static resource has been loaded, the API functions will have been added to `window.fin.salesforce`. Call the `initFinApiInLwc` API function before calling any OpenFin JS API functions in `window.fin`:
150
-
151
- ```ts
152
- // Initialise window.fin for use
153
- window.fin.salesforce.initFinApiInLwc();
154
-
155
- // window.fin is now ready to use
156
- const runtimeInfo = await window.fin.System.getRuntimeInfo();
157
- ```
158
-
159
- Here is a complete example of a lightning web component loading the static resource and using the OpenFin JS API:
160
-
161
- ```ts
162
- // myComponent.js
163
-
164
- import api from '@salesforce/resourceUrl/openfin_salesforce_lwc';
165
- import { loadScript } from 'lightning/platformResourceLoader';
166
- import { LightningElement } from 'lwc';
167
-
168
- export default class OpenfinIntegrationTest extends LightningElement {
169
- async connectedCallback() {
170
- try {
171
- await loadScript(this, api);
172
- } catch (err) {
173
- console.warn('Failed to load static resource, has it been added in Salesforce org settings?');
174
- return;
175
- }
176
-
177
- // Initialise window.fin for use
178
- window.fin.salesforce.initFinApiInLwc();
179
-
180
- // Output the current OpenFin runtime info to the console
181
- console.log(await window.fin.System.getRuntimeInfo());
182
- }
183
- }
184
- ```
185
-
186
- #### **For Aura components**
187
-
188
- To use the API in your Aura component, add a `<ltng:require>` tag to your component and use the [`$Resource`](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_resource_value_provider.htm) global value provider to reference the static resource:
189
-
190
- ```xml
191
- <aura:component>
192
- <ltng:require
193
- scripts="{!$Resource.openfin_salesforce_lwc}"
194
- afterScriptsLoaded="{!c.scriptsLoaded}" />
195
- </aura:component>
196
- ```
1
+ # Salesforce Integration for Lightning Web Components
2
+
3
+ ## Overview
4
+
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:
6
+
7
+ - [@openfin/salesforce-lwc](https://www.npmjs.com/package/@openfin/salesforce-lwc): Connect custom Salesforce components with OpenFin Container (this package)
8
+ - [@openfin/salesforce](https://www.npmjs.com/package/@openfin/salesforce): Connect OpenFin Container with Salesforce
9
+
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
+
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.
13
+
14
+ ## Code example
15
+
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:
17
+
18
+ ```ts
19
+ // myComponent.js
20
+
21
+ import api from '@salesforce/resourceUrl/openfin_salesforce_lwc';
22
+ import { loadScript } from 'lightning/platformResourceLoader';
23
+ import { LightningElement } from 'lwc';
24
+
25
+ export default class OpenfinIntegrationTest extends LightningElement {
26
+ async connectedCallback() {
27
+ try {
28
+ await loadScript(this, finApi);
29
+ } catch (err) {
30
+ console.warn('Failed to load static resource, has it been added in Salesforce org settings?');
31
+ }
32
+
33
+ // Initialize window.fin for use
34
+ window.fin.salesforce.initFinApiInLwc();
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
+
42
+ // Output the current OpenFin runtime info to the console
43
+ console.log(await window.fin.System.getRuntimeInfo());
44
+ }
45
+ }
46
+ ```
47
+
48
+ ## Getting started
49
+
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.
@@ -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,9 +1,10 @@
1
1
  {
2
2
  "name": "@openfin/salesforce-lwc",
3
- "description": "Client library for enabling the use of OpenFin's Javascript API in Salesforce components.",
4
- "version": "1.0.0",
3
+ "description": "Connect custom Salesforce components with OpenFin Container",
4
+ "version": "1.1.0",
5
5
  "author": "OpenFin Inc.",
6
+ "homepage": "https://www.openfin.co/",
6
7
  "license": "MIT",
7
- "main": "api.js",
8
- "types": "index.d.ts"
8
+ "main": "openfin.salesforce-lwc.js",
9
+ "types": "types/index.d.ts"
9
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})()}));
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Connect custom [Salesforce](https://www.salesforce.com/) components with [OpenFin Container](https://www.openfin.co/container/).
3
+ *
4
+ * @module @openfin/salesforce-lwc
5
+ */
6
+ export * from './lwc/lwc';
@@ -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.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={607: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(527),n)},527:(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}(607)})()});
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './lwc/lwc';
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';