@qualtrics/plugin-client 1.9.15-rc.2029.2a6f60 → 1.9.15-rc.2031.d40350

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/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Qualtrics Plugin Client
2
+
3
+ The Plugin Client provides a library of JavaScript methods that perform much of the low-level functionality common to all Qualtrics Plugins, including:
4
+
5
+ * [Message handling](#message-handlers)
6
+ * [External requests](#making-requests)
7
+ * [Text localization](#localization)
8
+
9
+ Ensure that your *index.html* file references the latest version of the Plugin Client in all your Plugins, both as you start a new project and before you submit your Extension.
10
+
11
+ ## Using the Plugin Client
12
+
13
+ To use the Plugin Client library in your XM Plugin, declare it as a dependency in your package.json file:
14
+
15
+ ```json
16
+ {
17
+ "name": "myPlugin",
18
+ "version": "0.0.1",
19
+ ...
20
+ "dependencies": {
21
+ "@qualtrics/plugin-client": "<version>"
22
+ }
23
+ }
24
+ ```
25
+
26
+ ## Message Handlers
27
+
28
+ Messages and Message Handlers are used to communicate between the Plugin Host
29
+ page and the Plugin (to save changes, validate data, etc).
30
+
31
+ For example, you could send a `canClose` message from the Host page to indicate that the Plugin is ready to close.
32
+
33
+ You would do this by adding a handler for this message to a `messageHandlers` object which is then passed in during the
34
+ initialization of the `PluginClient`.
35
+
36
+ ```javascript
37
+ const messageHandlers = {
38
+ canClose: (input) => {
39
+ // dataValid is a made-up function for this example
40
+ return {canClose: dataValid()}
41
+ },
42
+ }
43
+
44
+ // Initialize Plugin Client
45
+ window.PluginClient.initialize(eventHandlers).then((pluginClient) => {
46
+ // Use the client
47
+ })
48
+ ```
49
+
50
+ Based on the type of Plugin you are developing, your Plugin must handle various messages
51
+ sent from the Host page. For a full list of messages, read the [documentation](https://pdx1.qualtrics.com/developer/portal/documentation) for your Plugin Type.
52
+
53
+ > **NOTE** Only one handler can be registered for a given message.
54
+
55
+ ## Making Requests
56
+
57
+ Your Plugin may need information at run-time from the Host, from an
58
+ external API/resource, or from the Qualtrics API.
59
+
60
+ ### Supported Methods
61
+
62
+ The Plugin Client offers three methods to retrieve information:
63
+
64
+ * `postMessage` for Host requests
65
+ * `fetch2` for external third-party API requests
66
+ * `qualtricsApiFetch2` for Qualtrics API requests
67
+
68
+ ### Supported Host Messages
69
+
70
+ Messages specify functionality of requests to the Host&mdash;helper functions, data processing and storage, etc. To implement
71
+ them, use the `postMessage` function in the Plugin Client.
72
+
73
+ When you need to request data from the Host, first look at the supported messages for your Plugin type. These are messages that the Host already has registered handlers for. You can find a list of supported messages for each Plugin type in its respective guide.
74
+
75
+ #### Example Message Request
76
+
77
+ For example, a Plugin Host might publish a handler for a `getSurveyDef` message, which returns
78
+ the survey definition.
79
+
80
+ A Plugin could interface with that handler by sending a
81
+ message like so:
82
+
83
+ ```javascript
84
+ // Plugin Client was initialized earlier
85
+ try {
86
+ const surveyDef = await pluginClient
87
+ .postMessage('getSurveyDef', {surveyId: 'SV_123'})
88
+ // Use surveyDef
89
+ } catch (e) {
90
+ // Report error
91
+ }
92
+ ```
93
+
94
+ ## Localization
95
+
96
+ The Plugin Client provides helper functions for locating language-specific translations of Plugin
97
+ content.
98
+
99
+ ### Defining Localized Content
100
+
101
+ The first step is to define a translation file in the Plugin's *translations* folder.
102
+
103
+ These are JSON files, each named using the [Qualtrics Language Code](https://api.qualtrics.com/76d1dbf1c7f54-language-codes) for each language you intend to support. For example, the translation file for English is EN.json.
104
+
105
+ Below is an example translation file for English, EN.json.
106
+
107
+ ```json
108
+ {
109
+ "meta": {
110
+ "summary": "Plugin Language Strings - EN"
111
+ },
112
+ "strings": {
113
+ "name": {
114
+ "text": "Qualtrics Custom Plugin"
115
+ },
116
+ "description": {
117
+ "text": "Qualtrics Custom Plugin"
118
+ },
119
+ "longDescription": {
120
+ "text": "Qualtrics Plugin for experience management"
121
+ },
122
+ "title": {
123
+ "text": "Facebook Plugin"
124
+ },
125
+ "likes": {
126
+ "text": "You have {{number}} likes",
127
+ "context": "For listing the number of likes the post has"
128
+ },
129
+ "comments.notification": {
130
+ "text": "{{user}} got a comment from {{name}}"
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ You can use the meta section of the file to provide meta information about the
137
+ translation at your discretion.
138
+
139
+ > **NOTE** There is no enforced syntax for the `meta` section, only the requirement that it
140
+ > exists.
141
+
142
+ #### Reserved and Custom Keys
143
+
144
+ The `strings` section of the translation files is used to define templates for text that
145
+ appears in your Plugin. The `name`, `description`, and `longDescription`
146
+ keys are reserved for describing the Plugin to those who will be using it in
147
+ this language.
148
+
149
+ Otherwise, you are free to define your own template strings in
150
+ the `strings` section to provide localized content for your Plugin.
151
+
152
+ ### Fetching Localized Text
153
+
154
+ The platform automatically selects the appropriate .json file that matches the language selected at runtime.
155
+
156
+ Here are a few examples of how to read strings from the appropriate .json file in the *translations* folder:
157
+
158
+ ```javascript
159
+ client.getText('title')
160
+ // Returns "Facebook Plugin".
161
+
162
+ client.getText('likes', {number: 2})
163
+ // Returns "You have 2 likes".
164
+
165
+ client.getText('comments.notification', {user: 'Bob', name: 'Alice'})
166
+ // Returns "Bob got a comment from Alice".
167
+
168
+ client.getText('comments.reaction', {}, 'Thumbs Up')
169
+ // The translations don't include the key "comments.reaction", so this returns the provided default of "Thumbs Up".
170
+ ```
171
+
172
+ You have access to your translations and `getText` once the Plugin Client has been initialized.
173
+
174
+ For further details on Plugin Client functionality see its [method API documentation](https://pdx1.qualtrics.com/developer/portal/documentation/e14ccbcbe824f-plugin-client-methods).
175
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qualtrics/plugin-client",
3
- "version": "1.9.15-rc.2029.2a6f60",
3
+ "version": "1.9.15-rc.2031.d40350",
4
4
  "description": "Interface for XM Plugins to communicate with the environment they're rendered in",
5
5
  "scripts": {
6
6
  "ci-build": "yarn clean && yarn build",
@@ -1,3 +1,3 @@
1
1
  // Provide configuration that is supplied at build time.
2
- export var getClientVersion = function () { return "1.9.15-rc.2029.2a6f60"; };
2
+ export var getClientVersion = function () { return "1.9.15-rc.2031.d40350"; };
3
3
  //# sourceMappingURL=buildConfig.js.map