profoundjs 6.6.0 → 7.0.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.
@@ -0,0 +1,470 @@
1
+ {
2
+ "text": "",
3
+ "logic": {
4
+ "start": {
5
+ "steps": [
6
+ {
7
+ "text": "init",
8
+ "answers": {
9
+ "plugin": "Custom:code",
10
+ "custom-code": "try {\r\n // In case the oa data was missing, the page will go to the redirect.\r\n const oautils = require(\"./oautils.js\");\r\n var oauthurl = oautils.startURI;\r\n\r\n pjs.session.provider = oautils.provider;\r\n}\r\ncatch(err){\r\n var message = String(err);\r\n}",
11
+ "comment": "and set oa_state"
12
+ }
13
+ },
14
+ {
15
+ "text": "Set screen field(s)",
16
+ "answers": {
17
+ "plugin": "Program Data:set-screen-fields",
18
+ "screen": "validating",
19
+ "source": "Specify each value individually",
20
+ "screen-values": {
21
+ "oauth_url": "oauthurl",
22
+ "message": "message"
23
+ },
24
+ "comment": "Pass on server-side data to where client-side can reach it."
25
+ }
26
+ }
27
+ ]
28
+ },
29
+ "Exit": {
30
+ "steps": [
31
+ {
32
+ "text": "Exit",
33
+ "answers": {
34
+ "plugin": "Client-side:client-side-code",
35
+ "code": "pui.confirmOnClose = false;\r\nwindow.location = \"/run/oauth2sample/authpage\";",
36
+ "comment": ""
37
+ }
38
+ }
39
+ ]
40
+ },
41
+ "make api request button click": {
42
+ "steps": [
43
+ {
44
+ "text": "httpRequest to API",
45
+ "answers": {
46
+ "plugin": "Custom:code",
47
+ "custom-code": "var oautils = require(\"./oautils.js\");\r\n\r\ntry {\r\n let respData = await pjs.httpRequest({\r\n method: \"POST\",\r\n uri: oautils.PROTOCOL_HOST_PORT +\"/run/oauth2sample/wsapi/postTestService\",\r\n headers: {\r\n \"Authorization\": \"Bearer \" + pjs.session.tokens.access_token\r\n },\r\n alwaysReadBody: true\r\n });\r\n\r\n let ajaxresponseObj = respData;\r\n usefulapp.apiresponse = JSON.stringify(ajaxresponseObj, null, 2);\r\n}\r\ncatch (err){\r\n usefulapp.apiresponse = String(err);\r\n}",
48
+ "comment": ""
49
+ }
50
+ }
51
+ ]
52
+ },
53
+ "app screen load": {
54
+ "steps": [
55
+ {
56
+ "text": "Set screen field(s)",
57
+ "answers": {
58
+ "plugin": "Program Data:set-screen-fields",
59
+ "screen": "usefulapp",
60
+ "source": "Specify each value individually",
61
+ "screen-values": {
62
+ "userfld": "pjs.session.user",
63
+ "emailfld": "pjs.session.email",
64
+ "fldOAProvider": "pjs.session.provider"
65
+ },
66
+ "comment": "Set the User and Email fields"
67
+ }
68
+ }
69
+ ]
70
+ },
71
+ "validation screen load": {
72
+ "code": "// Validation screen load.\r\nconst oautils = require(\"./oautils.js\");\r\n\r\n// Read Fields and Check Code\r\n// \"oa_data\" should be set if the app was started from a redirect from our sample authpage.js.\r\nconst oa_code = validating.oa_data;\r\nconst oa_codver = validating.oa_codver;\r\n\r\n// code valid?\r\nif (typeof oa_code === \"string\" && oa_code.length > 0) {\r\n try {\r\n // Exchange the code for a token.\r\n const tokens = await oautils.fetchTokensAsync(oa_code, oa_codver);\r\n \r\n if (typeof tokens.access_token !== \"string\" || tokens.access_token.length < 1) {\r\n // Token was not valid.\r\n throw new Error(\"Authentication token could not be fetched.\");\r\n }\r\n pjs.session.tokens = tokens;\r\n\r\n // Ask the OAuth2 server for user ID of the user associated with the token.\r\n pjs.session.user = await oautils.getUserIdAsync(tokens.access_token);\r\n\r\n // Show different screen\r\n screenHistory.push(\"usefulapp\");\r\n activeScreen = screens[\"usefulapp\"];\r\n }\r\n catch (err) {\r\n showErrorScreen(err);\r\n }\r\n}\r\n// Else: the code may not be set in a field, because this server side code runs before the\r\n// client-side code can run.\r\n\r\nfunction showErrorScreen(msg) {\r\n const cause = typeof msg.cause === \"object\" && msg.cause !== null ? \" \" + JSON.stringify(msg.cause) : \"\";\r\n Object.assign(error, { \"message\": msg.message + cause });\r\n screenHistory.push(\"error\");\r\n activeScreen = screens[\"error\"];\r\n}\r\n"
73
+ }
74
+ },
75
+ "start routine": "start",
76
+ "formats": [
77
+ {
78
+ "screen": {
79
+ "record format name": "validating",
80
+ "initial routine": {
81
+ "routine": "validation screen load",
82
+ "designValue": "validation screen load"
83
+ },
84
+ "onload": "// Pass on the OAuth2 data to the server, or send the user to the auth page.\nconst oa_data = localStorage.getItem(\"pjs_oadata\");\nconst oa_url = get(\"ofAuthURL\");\n\nif (typeof oa_data === \"string\" && oa_data.length > 0){\n pui.set(\"tb_oa_data\", oa_data);\n pui.set(\"tb_oa_codver\", localStorage.getItem(\"pjs_codver\"));\n localStorage.setItem(\"pjs_oadata\",\"\");\n localStorage.setItem(\"pjs_codver\",\"\");\n pui.click();\n}\nelse if(typeof oa_url === \"string\" && oa_url.length > 0) {\n localStorage.setItem(\"pjs_oadata\",\"\");\n window.location = oa_url + \"?error=Redirected+from+validation+page\";\n}\nelse {\n pui.set(\"message\", \"The required OAuth2 data was missing, and the sample application's start URI was not set in oautils.js\");\n}"
85
+ },
86
+ "items": [
87
+ {
88
+ "id": "OutputField1",
89
+ "field type": "output field",
90
+ "css class": "heading",
91
+ "value": "Validating...",
92
+ "left": "15px",
93
+ "top": "20px",
94
+ "css class 2": "blueprint-defaults",
95
+ "css class 3": "blueprint-text-header"
96
+ },
97
+ {
98
+ "id": "btnCancel",
99
+ "field type": "graphic button",
100
+ "css class": "pui-solid-button-no",
101
+ "value": "Exit",
102
+ "left": "15px",
103
+ "top": "170px",
104
+ "width": "100px",
105
+ "css class 2": "blueprint-defaults",
106
+ "height": "25px",
107
+ "onclick": {
108
+ "routine": "Exit",
109
+ "designValue": "Exit"
110
+ }
111
+ },
112
+ {
113
+ "id": "ofAuthURL",
114
+ "field type": "html container",
115
+ "css class": "outputField",
116
+ "left": "30px",
117
+ "top": "435px",
118
+ "css class 2": "blueprint-defaults",
119
+ "css class 3": "blueprint-output-field",
120
+ "visibility": "hidden",
121
+ "width": "610px",
122
+ "html": {
123
+ "fieldName": "oauth_url",
124
+ "trimLeading": "false",
125
+ "trimTrailing": "true",
126
+ "blankFill": "false",
127
+ "rjZeroFill": "false",
128
+ "dataType": "string",
129
+ "formatting": "Text",
130
+ "textTransform": "none",
131
+ "designValue": "[oauth_url]"
132
+ },
133
+ "white space": "pre-wrap",
134
+ "height": "95px"
135
+ },
136
+ {
137
+ "id": "tb_oa_data",
138
+ "field type": "textbox",
139
+ "css class": "blueprint-defaults",
140
+ "value": {
141
+ "fieldName": "oa_data",
142
+ "trimLeading": "false",
143
+ "trimTrailing": "true",
144
+ "blankFill": "false",
145
+ "rjZeroFill": "false",
146
+ "dataType": "string",
147
+ "formatting": "Text",
148
+ "textTransform": "none",
149
+ "designValue": "[oa_data]"
150
+ },
151
+ "left": "170px",
152
+ "top": "330px",
153
+ "width": "150px",
154
+ "height": "25px",
155
+ "css class 2": "blueprint-textbox",
156
+ "visibility": "hidden",
157
+ "read only": "true"
158
+ },
159
+ {
160
+ "id": "OutputField4",
161
+ "field type": "output field",
162
+ "css class": "label",
163
+ "value": "Code:",
164
+ "left": "30px",
165
+ "top": "330px",
166
+ "css class 2": "blueprint-defaults",
167
+ "css class 3": "blueprint-label",
168
+ "visibility": "hidden"
169
+ },
170
+ {
171
+ "id": "OutputField6",
172
+ "field type": "output field",
173
+ "css class": "label",
174
+ "value": "Auth URL in case of error",
175
+ "left": "20px",
176
+ "top": "410px",
177
+ "css class 2": "blueprint-defaults",
178
+ "css class 3": "blueprint-label",
179
+ "visibility": "hidden",
180
+ "width": "195px",
181
+ "height": "25px"
182
+ },
183
+ {
184
+ "id": "HtmlContainer1",
185
+ "field type": "html container",
186
+ "left": "15px",
187
+ "top": "45px",
188
+ "html": "Checking your user token with the OAuth2 provider configured in the openapi.json config file.",
189
+ "white space": "normal",
190
+ "width": "685px",
191
+ "height": "35px"
192
+ },
193
+ {
194
+ "id": "HtmlContainer2",
195
+ "field type": "html container",
196
+ "left": "15px",
197
+ "top": "85px",
198
+ "html": {
199
+ "fieldName": "message",
200
+ "trimLeading": "false",
201
+ "trimTrailing": "true",
202
+ "blankFill": "false",
203
+ "rjZeroFill": "false",
204
+ "dataType": "string",
205
+ "formatting": "Text",
206
+ "textTransform": "none",
207
+ "designValue": "[message]"
208
+ },
209
+ "white space": "normal",
210
+ "width": "520px",
211
+ "height": "75px"
212
+ },
213
+ {
214
+ "id": "Label1",
215
+ "field type": "output field",
216
+ "css class": "label",
217
+ "value": "Hidden Fields Used to relay OAuth2 data:",
218
+ "left": "25px",
219
+ "top": "290px",
220
+ "width": "150px",
221
+ "visibility": "hidden",
222
+ "text align": "left"
223
+ },
224
+ {
225
+ "id": "OutputField2",
226
+ "field type": "output field",
227
+ "css class": "label",
228
+ "value": "Code Verifier:",
229
+ "left": "30px",
230
+ "top": "360px",
231
+ "css class 2": "blueprint-defaults",
232
+ "css class 3": "blueprint-label",
233
+ "visibility": "hidden"
234
+ },
235
+ {
236
+ "id": "tb_oa_codver",
237
+ "field type": "textbox",
238
+ "css class": "blueprint-defaults",
239
+ "value": {
240
+ "fieldName": "oa_codver",
241
+ "trimLeading": "false",
242
+ "trimTrailing": "true",
243
+ "blankFill": "false",
244
+ "rjZeroFill": "false",
245
+ "dataType": "string",
246
+ "formatting": "Text",
247
+ "textTransform": "none",
248
+ "designValue": "[oa_codver]"
249
+ },
250
+ "left": "170px",
251
+ "top": "360px",
252
+ "width": "150px",
253
+ "height": "25px",
254
+ "css class 2": "blueprint-textbox",
255
+ "visibility": "hidden"
256
+ }
257
+ ]
258
+ },
259
+ {
260
+ "screen": {
261
+ "record format name": "usefulapp",
262
+ "initial routine": {
263
+ "routine": "app screen load",
264
+ "designValue": "app screen load"
265
+ }
266
+ },
267
+ "items": [
268
+ {
269
+ "id": "OutputField1",
270
+ "field type": "output field",
271
+ "css class": "heading",
272
+ "value": "I am Some Useful App that Requires Authentication",
273
+ "left": "25px",
274
+ "top": "25px",
275
+ "css class 2": "blueprint-defaults",
276
+ "css class 3": "blueprint-text-header"
277
+ },
278
+ {
279
+ "id": "HtmlContainer1",
280
+ "field type": "html container",
281
+ "css class": "blueprint-defaults",
282
+ "left": "25px",
283
+ "top": "55px",
284
+ "html": "You signed onto this app via:",
285
+ "white space": "normal",
286
+ "width": "190px",
287
+ "height": "25px",
288
+ "css class 2": "blueprint-wrapping-text"
289
+ },
290
+ {
291
+ "id": "btnMakeAPIReq",
292
+ "field type": "graphic button",
293
+ "css class": "blueprint-button",
294
+ "value": "Make API Request",
295
+ "icon position": "left",
296
+ "left": "10px",
297
+ "top": "220px",
298
+ "height": "25px",
299
+ "width": "155px",
300
+ "css class 2": "blueprint-alt-defaults",
301
+ "css class 3": "no-icon",
302
+ "onclick": {
303
+ "routine": "make api request button click",
304
+ "designValue": "make api request button click"
305
+ }
306
+ },
307
+ {
308
+ "id": "btnExit",
309
+ "field type": "graphic button",
310
+ "css class": "pui-solid-button-no",
311
+ "value": "Exit",
312
+ "icon position": "left",
313
+ "left": "210px",
314
+ "top": "220px",
315
+ "height": "25px",
316
+ "width": "100px",
317
+ "css class 2": "blueprint-defaults",
318
+ "onclick": {
319
+ "routine": "Exit",
320
+ "designValue": "Exit"
321
+ }
322
+ },
323
+ {
324
+ "id": "Layout1",
325
+ "field type": "layout",
326
+ "left": "10px",
327
+ "top": "260px",
328
+ "template": "fieldset",
329
+ "width": "625px",
330
+ "height": "320px",
331
+ "legend": "API Response"
332
+ },
333
+ {
334
+ "id": "OutputField2",
335
+ "field type": "output field",
336
+ "css class": "label",
337
+ "value": "User:",
338
+ "left": "30px",
339
+ "top": "95px",
340
+ "css class 2": "blueprint-defaults",
341
+ "css class 3": "blueprint-label"
342
+ },
343
+ {
344
+ "id": "OutputField3",
345
+ "field type": "output field",
346
+ "css class": "outputField",
347
+ "value": {
348
+ "fieldName": "userfld",
349
+ "trimLeading": "false",
350
+ "trimTrailing": "true",
351
+ "blankFill": "false",
352
+ "rjZeroFill": "false",
353
+ "dataType": "string",
354
+ "formatting": "Text",
355
+ "textTransform": "none",
356
+ "designValue": "[userfld]"
357
+ },
358
+ "left": "85px",
359
+ "top": "95px",
360
+ "css class 2": "blueprint-defaults",
361
+ "css class 3": "blueprint-output-field"
362
+ },
363
+ {
364
+ "id": "HtmlContainer3",
365
+ "field type": "html container",
366
+ "left": "10px",
367
+ "top": "130px",
368
+ "html": "Clicking \"Make API Request\" will call a sample API using an OAuth2 token associated with your username. The API Security Store must permit your username to access the API, or else a 403 error will be returned.",
369
+ "white space": "normal",
370
+ "width": "620px",
371
+ "height": "75px"
372
+ },
373
+ {
374
+ "id": "OutputField6",
375
+ "field type": "output field",
376
+ "css class": "outputField",
377
+ "value": {
378
+ "fieldName": "fldOAProvider",
379
+ "trimLeading": "false",
380
+ "trimTrailing": "true",
381
+ "blankFill": "false",
382
+ "rjZeroFill": "false",
383
+ "dataType": "string",
384
+ "formatting": "Text",
385
+ "textTransform": "none",
386
+ "designValue": "[fldOAProvider]"
387
+ },
388
+ "left": "215px",
389
+ "top": "60px"
390
+ },
391
+ {
392
+ "id": "ajaxresponse",
393
+ "field type": "html container",
394
+ "white space": "pre-wrap",
395
+ "html": {
396
+ "fieldName": "apiresponse",
397
+ "trimLeading": "false",
398
+ "trimTrailing": "true",
399
+ "blankFill": "false",
400
+ "rjZeroFill": "false",
401
+ "dataType": "string",
402
+ "formatting": "Text",
403
+ "textTransform": "none",
404
+ "designValue": "[apiresponse]"
405
+ },
406
+ "left": "5px",
407
+ "top": "5px",
408
+ "height": "calc(100% - 10px)",
409
+ "width": "calc(100% - 10px)",
410
+ "layout": "Layout1",
411
+ "container": "1"
412
+ }
413
+ ]
414
+ },
415
+ {
416
+ "screen": {
417
+ "record format name": "error"
418
+ },
419
+ "items": [
420
+ {
421
+ "id": "OutputField1",
422
+ "field type": "output field",
423
+ "css class": "heading",
424
+ "value": "Error",
425
+ "left": "10px",
426
+ "top": "10px",
427
+ "css class 2": "blueprint-defaults",
428
+ "css class 3": "blueprint-text-header"
429
+ },
430
+ {
431
+ "id": "HtmlContainer2",
432
+ "field type": "html container",
433
+ "white space": "normal",
434
+ "html": {
435
+ "fieldName": "message",
436
+ "trimLeading": "false",
437
+ "trimTrailing": "true",
438
+ "blankFill": "false",
439
+ "rjZeroFill": "false",
440
+ "dataType": "string",
441
+ "formatting": "Text",
442
+ "textTransform": "none",
443
+ "designValue": "[message]"
444
+ },
445
+ "left": "15px",
446
+ "top": "70px",
447
+ "height": "270px",
448
+ "width": "520px"
449
+ },
450
+ {
451
+ "id": "btnCancel",
452
+ "field type": "graphic button",
453
+ "css class": "pui-solid-button-no",
454
+ "value": "Exit",
455
+ "left": "15px",
456
+ "top": "40px",
457
+ "height": "25px",
458
+ "width": "100px",
459
+ "css class 2": "blueprint-defaults",
460
+ "onclick": {
461
+ "routine": "Exit",
462
+ "designValue": "Exit"
463
+ }
464
+ }
465
+ ]
466
+ }
467
+ ],
468
+ "keywords": [],
469
+ "long name aliases": true
470
+ }
Binary file
package/setup/setup.js CHANGED
@@ -53,7 +53,8 @@ let SILENT_MODE = false;
53
53
  "ibmi-connector-library",
54
54
  "ibmi-instance-autostart",
55
55
  "nodegit",
56
- "silent"
56
+ "silent",
57
+ "installSamples"
57
58
  ],
58
59
  string: [
59
60
  "c",
@@ -81,6 +82,7 @@ let SILENT_MODE = false;
81
82
  --ibmi-instance-autostart Autostart flag for STRTCPSVR instance.
82
83
  --ibmi-instance-ccsid=<ccsid> CCSID for STRTCPSVR instance.
83
84
  --ibmi-instance-node-path=<path> Node.js binary path for STRTCPSVR instance.
85
+ --samples Install sample code.
84
86
 
85
87
  Performs additional installation using config values and CLI options.
86
88
  Default config file is <INSTALL_DIRECTORY>/config.js.
@@ -289,28 +291,46 @@ let SILENT_MODE = false;
289
291
  copyFile(path.join(__dirname, "modules", "puidnlexit.js"), path.join(deployDir, "modules"), "utf8");
290
292
  }
291
293
 
292
- // Create mathoperation.js.
293
- if (fileExists(path.join(deployDir, "plugins", "mathoperation.js"))) {
294
- log("mathoperation.js file exists.");
295
- }
296
- else {
297
- log("Creating mathoperation.js.");
298
- copyFile(path.join(__dirname, "plugins", "mathoperation.js"), path.join(deployDir, "plugins"), "utf8");
299
- }
294
+ if (args["installSamples"]) {
295
+ // Create samples directory.
296
+ if (directoryExists(path.join(deployDir, "modules", "pjssamples"))) {
297
+ fs.removeSync(path.join(deployDir, "modules", "pjssamples"));
298
+ }
299
+ log("Copying pjssamples.");
300
+ copyDir(path.join(__dirname, "modules", "pjssamples"), path.join(deployDir, "modules"));
300
301
 
301
- // Create samples directory.
302
- if (directoryExists(path.join(deployDir, "modules", "pjssamples"))) {
303
- fs.removeSync(path.join(deployDir, "modules", "pjssamples"));
304
- }
305
- log("Copying pjssamples.");
306
- copyDir(path.join(__dirname, "modules", "pjssamples"), path.join(deployDir, "modules"));
302
+ const copyWSMsg = "Copying sample workspace into ";
303
+
304
+ // Create PAPI samples directory
305
+ let wsPath = path.join(deployDir, "modules", "papisamples");
306
+ if (directoryExists(wsPath)) {
307
+ log(`Skipping sample workspace, ${wsPath} -- directory exists.`);
308
+ }
309
+ else {
310
+ log(copyWSMsg + wsPath);
311
+ copyDir(path.join(__dirname, "modules", "papisamples"), path.join(deployDir, "modules"));
312
+ }
307
313
 
308
- // Create PAPI samples directory
309
- if (directoryExists(path.join(deployDir, "modules", "papisamples"))) {
310
- fs.removeSync(path.join(deployDir, "modules", "papisamples"));
314
+ // Create oauth2sample directory.
315
+ wsPath = path.join(deployDir, "modules", "oauth2sample");
316
+ if (directoryExists(wsPath)) {
317
+ log(`Skipping sample workspace, ${wsPath} -- directory exists.`);
318
+ }
319
+ else {
320
+ log(copyWSMsg + wsPath);
321
+ copyDir(path.join(__dirname, "modules", "oauth2sample"), path.join(deployDir, "modules"));
322
+ }
323
+
324
+ // Create mathoperation.js.
325
+ const fPath = path.join(deployDir, "plugins", "mathoperation.js");
326
+ if (fileExists(fPath)) {
327
+ log(`Skipping sample Low-code plugin: ${fPath} -- file exists.`);
328
+ }
329
+ else {
330
+ log(`Creating sample Low-code plugin: ${fPath}`);
331
+ copyFile(path.join(__dirname, "plugins", "mathoperation.js"), path.join(deployDir, "plugins"), "utf8");
332
+ }
311
333
  }
312
- log("Copying papisamples.");
313
- copyDir(path.join(__dirname, "modules", "papisamples"), path.join(deployDir, "modules"));
314
334
 
315
335
  // Create store_credentials.js.
316
336
  if (fileExists(path.join(deployDir, "store_credentials.js"))) {
@@ -330,17 +350,6 @@ let SILENT_MODE = false;
330
350
  log("store_options.js created.");
331
351
  }
332
352
 
333
- // Begin OAuth2 requirements.
334
- // Create encrypt_client_file.js.
335
- if (fileExists(path.join(deployDir, "encrypt_client_file.js"))) {
336
- log("encrypt_client_file.js file exists.");
337
- }
338
- else {
339
- copyFile(path.join(__dirname, "encrypt_client_file.js"), deployDir, "utf8");
340
- log("encrypt_client_file.js created.");
341
- }
342
- // End OAuth2 requirements.
343
-
344
353
  // Create call.js.
345
354
  if (fileExists(path.join(deployDir, "call.js"))) {
346
355
  log("call.js file exists.");
@@ -354,6 +363,24 @@ let SILENT_MODE = false;
354
363
  copyFile(path.join(__dirname, "lic_client.js"), deployDir, "utf8");
355
364
  log("lic_client.js created.");
356
365
 
366
+ // Create gen_key.js.
367
+ if (fileExists(path.join(deployDir, "gen_key.js"))) {
368
+ log("gen_key.js file exists.");
369
+ }
370
+ else {
371
+ copyFile(path.join(__dirname, "gen_key.js"), deployDir, "utf8");
372
+ log("gen_key.js created.");
373
+ }
374
+
375
+ // Create get_pjscall_key.js.
376
+ if (fileExists(path.join(deployDir, "get_pjscall_key.js"))) {
377
+ log("get_pjscall_key.js file exists.");
378
+ }
379
+ else {
380
+ copyFile(path.join(__dirname, "get_pjscall_key.js"), deployDir, "utf8");
381
+ log("get_pjscall_key.js created.");
382
+ }
383
+
357
384
  // Convert start.js to Promises, if necessary.
358
385
  const convertStartJS = require("./convertStartJS.js");
359
386
  if (convertStartJS(path.join(deployDir, "start.js"))) {
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var profoundjs = require("profoundjs");
4
- profoundjs.encryptClientFile();