@rockcarver/frodo-lib 0.17.8-2 → 0.18.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/CHANGELOG.md CHANGED
@@ -7,6 +7,92 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.18.0] - 2023-01-13
11
+
12
+ ### Added
13
+
14
+ - \#68: Support final implementation of Identity Cloud service accounts. Service accounts are the future way for applications to authenticate to Identity Cloud environments without using a personal tenant admin account. Tenant admins can create any number of service accounts and assign sets of privileges to each account. Frodo Library can create service accounts with the required privileges or can use existing service accounts.
15
+
16
+ To create a service account use the new ServiceAccount API:
17
+
18
+ ```js
19
+ import { createJwkRsa, createJwks, getJwkRsaPublic } from './JoseOps';
20
+ import { createServiceAccount, isServiceAccountsFeatureAvailable } from './ServiceAccountOps';
21
+
22
+ // check if the tenant supports service accounts
23
+ if (isServiceAccountsFeatureAvailable()) {
24
+ const name = 'sa';
25
+ const description = 'service account';
26
+ const accountStatus = 'Active';
27
+ const scopes = ['fr:am:*', 'fr:idm:*', 'fr:idc:esv:*'];
28
+ // create a java web key (JWK) using RSA
29
+ const jwk = await createJwkRsa();
30
+ // extract only the public key as a JWK from the full JWK
31
+ const publicJwk = await getJwkRsaPublic(jwk);
32
+ // create a java wek key set (JWKS) from the public JWK
33
+ const jwks = await createJwks(publicJwk);
34
+ // create service account
35
+ const payload = await ServiceAccount.createServiceAccount(
36
+ name,
37
+ description,
38
+ accountStatus,
39
+ scopes,
40
+ jwks
41
+ );
42
+ // uuid of new service account if creation succeeded
43
+ const saId = payload._id;
44
+ }
45
+ ```
46
+
47
+ To use a service account set the following state variables:
48
+
49
+ ```js
50
+ import { state } from '@rockcarver/frodo-lib';
51
+
52
+ // setting both, id and jwk, instruct the library to use the service account
53
+ state.setServiceAccountId(saId);
54
+ state.setServiceAccountJwk(jwk);
55
+ ```
56
+
57
+ - Add support for additional environment variables:
58
+
59
+ - `FRODO_AUTHENTICATION_SERVICE=journey`: Specify a journey for frodo to use
60
+ - `FRODO_MOCK=1`: Enable mocking. If enabled, frodo-lib replays recorded API responses instead of connecting to a platform instance.
61
+ - `FRODO_POLLY_LOG_LEVEL=info`: Frodo mock engine log level (trace, debug, info, warn, error, silent). This is helpful for troubleshooting the mock capability, only.
62
+
63
+ Environment variables added in 0.17.1:
64
+
65
+ - `FRODO_HOST`
66
+ - `FRODO_REALM`
67
+ - `FRODO_USERNAME`
68
+ - `FRODO_PASSWORD`
69
+ - `FRODO_SA_ID`
70
+ - `FRODO_SA_JWK`
71
+ - `FRODO_LOG_KEY`
72
+ - `FRODO_LOG_SECRET`
73
+ - `FRODO_DEBUG`
74
+
75
+ - Add support to delete IDM config entities
76
+
77
+ - Add function to check RCS status
78
+
79
+ - Add mock mode for library to allow unit testing of clients using the library, like frodo-cli. This initial release contains minimal mock data. Enable mock mode using `FRODO_MOCK=1`.
80
+
81
+ - Updated list of contributors in package.json
82
+
83
+ - More automated tests
84
+
85
+ ### Changed
86
+
87
+ - Ongoing refactoring of code base:
88
+ - Migrate automated tests from ForgeRockApiMockEngine to Polly.js and snapshots.
89
+
90
+ ### Fixed
91
+
92
+ - Bug fixes
93
+
94
+ ## [0.17.8-3] - 2023-01-12
95
+
10
96
  ## [0.17.8-2] - 2023-01-12
11
97
 
12
98
  ## [0.17.8-1] - 2023-01-12
@@ -917,7 +1003,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
917
1003
  - Fixed problem with adding connection profiles
918
1004
  - Miscellaneous bug fixes
919
1005
 
920
- [Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.17.8-2...HEAD
1006
+ [Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.18.0...HEAD
1007
+
1008
+ [0.18.0]: https://github.com/rockcarver/frodo-lib/compare/v0.17.8-3...v0.18.0
1009
+
1010
+ [0.17.8-3]: https://github.com/rockcarver/frodo-lib/compare/v0.17.8-2...v0.17.8-3
921
1011
 
922
1012
  [0.17.8-2]: https://github.com/rockcarver/frodo-lib/compare/v0.17.8-1...v0.17.8-2
923
1013
 
@@ -10,6 +10,7 @@ var _core = require("@pollyjs/core");
10
10
  var _utils = require("@pollyjs/utils");
11
11
  var _adapterNodeHttp = _interopRequireDefault(require("@pollyjs/adapter-node-http"));
12
12
  var _persisterFs = _interopRequireDefault(require("@pollyjs/persister-fs"));
13
+ var _Console = require("../ops/utils/Console");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
16
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -131,7 +132,15 @@ function setupPollyForFrodoLib() {
131
132
  polly.server.host('https://registry.npmjs.org', () => {
132
133
  polly.server.any('/*').recordingName('npmjs');
133
134
  });
134
- if (mode === _utils.MODES.RECORD) scheduleShutdown(polly, 60);
135
+ if (mode === _utils.MODES.RECORD) {
136
+ scheduleShutdown(polly, 60);
137
+ } else {
138
+ // only output debug messages if not recording as this polly instance is
139
+ // primarily used by frodo-cli e2e tests, which capture stdout in snapshots.
140
+ // debug messages falsify the snapshot recordings.
141
+ (0, _Console.debugMessage)("Polly config:");
142
+ (0, _Console.debugMessage)(polly.config);
143
+ }
135
144
  return polly;
136
145
  }
137
146
  //# sourceMappingURL=SetupPollyForFrodoLib.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SetupPollyForFrodoLib.js","names":["__dirname","path","dirname","fileURLToPath","FRODO_MOCK_HOSTS","recordIfMissing","mode","MODES","REPLAY","recordingsDir","replace","process","env","FRODO_MOCK","Polly","register","NodeHttpAdapter","FSPersister","RECORD","defaultMatchRequestsBy","JSON","parse","stringify","method","headers","body","order","url","protocol","username","password","hostname","port","pathname","query","hash","authenticationMatchRequestsBy","matchRequestsBy","delay","ms","Promise","resolve","setTimeout","countdown","i","scheduleShutdown","polly","console","log","stop","setupPollyForFrodoLib","configure","adapters","flushRequestsOnStop","logLevel","FRODO_POLLY_LOG_LEVEL","recordFailedRequests","persister","persisterOptions","fs","host","server","any","recordingName","on","req"],"sources":["utils/SetupPollyForFrodoLib.ts"],"sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Polly } from '@pollyjs/core';\nimport { MODES } from '@pollyjs/utils';\nimport NodeHttpAdapter from '@pollyjs/adapter-node-http';\nimport FSPersister from '@pollyjs/persister-fs';\nimport { LogLevelDesc } from 'loglevel';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst FRODO_MOCK_HOSTS = [\n 'https://openam-frodo-dev.forgeblocks.com',\n 'https://openam-service-accounts.forgeblocks.com',\n 'https://openam-volker-dev.forgeblocks.com',\n];\n\nlet recordIfMissing = false;\nlet mode = MODES.REPLAY;\n\n// resolve \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/esm/api\" to\n// \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/src/test/recordings\"\nconst recordingsDir = __dirname.replace(\n /^(.*\\/frodo-\\w{3})(.*)$/gi,\n '$1/mocks'\n);\n\nif (process.env.FRODO_MOCK) {\n Polly.register(NodeHttpAdapter);\n Polly.register(FSPersister);\n if (process.env.FRODO_MOCK === 'record') {\n mode = MODES.RECORD;\n recordIfMissing = true;\n }\n}\n\nfunction defaultMatchRequestsBy() {\n return JSON.parse(\n JSON.stringify({\n method: true,\n headers: false, // do not match headers, because \"Authorization\" header is sent only at recording time\n body: true,\n order: false,\n url: {\n protocol: false,\n username: false,\n password: false,\n hostname: false, // we will record from different envs but run tests always against `frodo-dev`\n port: false,\n pathname: true,\n query: true,\n hash: true,\n },\n })\n );\n}\n\nfunction authenticationMatchRequestsBy() {\n const matchRequestsBy = defaultMatchRequestsBy();\n matchRequestsBy.body = false;\n matchRequestsBy.order = true;\n return matchRequestsBy;\n}\n\n// returns a delayed promise\nasync function delay(ms) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// performs a specific (mathematical) operation every \"ms\" (milliseconds)\nasync function countdown(i, ms) {\n await delay(ms);\n return --i;\n}\n\nasync function scheduleShutdown(polly: Polly, i = 30) {\n ++i;\n while ((i = await countdown(i, 1000)))\n console.log(`Polly stopping in ${i}s...`);\n await polly.stop();\n console.log(`Polly stopped.`);\n}\n\nexport function setupPollyForFrodoLib(\n matchRequestsBy = defaultMatchRequestsBy()\n): Polly {\n const polly = new Polly('default');\n\n polly.configure({\n adapters: ['node-http'],\n mode,\n recordIfMissing,\n flushRequestsOnStop: true,\n logLevel: (process.env.FRODO_POLLY_LOG_LEVEL as LogLevelDesc) || 'warn',\n recordFailedRequests: true,\n persister: 'fs',\n persisterOptions: {\n fs: {\n recordingsDir,\n },\n },\n matchRequestsBy,\n });\n\n for (const host of FRODO_MOCK_HOSTS) {\n if (mode === MODES.RECORD) console.log(`***** Host: ${host}`);\n polly.server.host(host, () => {\n polly.server\n .any('/am/oauth2/*')\n .recordingName('oauth2')\n .on('request', (req) => {\n req.configure({ matchRequestsBy: authenticationMatchRequestsBy() });\n });\n polly.server.any('/am/json/*').recordingName('am');\n polly.server.any('/openidm/*').recordingName('openidm');\n polly.server.any('/environment/*').recordingName('environment');\n polly.server.any('/monitoring/*').recordingName('monitoring');\n polly.server.any('/feature').recordingName('feature');\n polly.server.any('/dashboard/*').recordingName('dashboard');\n });\n }\n polly.server.host('https://api.github.com', () => {\n polly.server.any('/*').recordingName('github');\n });\n polly.server.host('https://registry.npmjs.org', () => {\n polly.server.any('/*').recordingName('npmjs');\n });\n\n if (mode === MODES.RECORD) scheduleShutdown(polly,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d,KAAK,CAACe,MAAM,CAACC,GAAG,CAAC,IAAI,CAAC,CAACC,aAAa,CAAC,OAAO,CAAC;EAC/C,CAAC,CAAC;EAEF,IAAIzD,IAAI,KAAKC,YAAK,CAACW,MAAM,EAAE2B,gBAAgB,CAACC,KAAK,EAAE,EAAE,CAAC;EAEtD,OAAOA,KAAK;AACd"}
1
+ {"version":3,"file":"SetupPollyForFrodoLib.js","names":["__dirname","path","dirname","fileURLToPath","FRODO_MOCK_HOSTS","recordIfMissing","mode","MODES","REPLAY","recordingsDir","replace","process","env","FRODO_MOCK","Polly","register","NodeHttpAdapter","FSPersister","RECORD","defaultMatchRequestsBy","JSON","parse","stringify","method","headers","body","order","url","protocol","username","password","hostname","port","pathname","query","hash","authenticationMatchRequestsBy","matchRequestsBy","delay","ms","Promise","resolve","setTimeout","countdown","i","scheduleShutdown","polly","console","log","stop","setupPollyForFrodoLib","configure","adapters","flushRequestsOnStop","logLevel","FRODO_POLLY_LOG_LEVEL","recordFailedRequests","persister","persisterOptions","fs","host","server","any","recordingName","on","req","debugMessage","config"],"sources":["utils/SetupPollyForFrodoLib.ts"],"sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Polly } from '@pollyjs/core';\nimport { MODES } from '@pollyjs/utils';\nimport NodeHttpAdapter from '@pollyjs/adapter-node-http';\nimport FSPersister from '@pollyjs/persister-fs';\nimport { LogLevelDesc } from 'loglevel';\nimport { debugMessage } from '../ops/utils/Console';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst FRODO_MOCK_HOSTS = [\n 'https://openam-frodo-dev.forgeblocks.com',\n 'https://openam-service-accounts.forgeblocks.com',\n 'https://openam-volker-dev.forgeblocks.com',\n];\n\nlet recordIfMissing = false;\nlet mode = MODES.REPLAY;\n\n// resolve \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/esm/api\" to\n// \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/src/test/recordings\"\nconst recordingsDir = __dirname.replace(\n /^(.*\\/frodo-\\w{3})(.*)$/gi,\n '$1/mocks'\n);\n\nif (process.env.FRODO_MOCK) {\n Polly.register(NodeHttpAdapter);\n Polly.register(FSPersister);\n if (process.env.FRODO_MOCK === 'record') {\n mode = MODES.RECORD;\n recordIfMissing = true;\n }\n}\n\nfunction defaultMatchRequestsBy() {\n return JSON.parse(\n JSON.stringify({\n method: true,\n headers: false, // do not match headers, because \"Authorization\" header is sent only at recording time\n body: true,\n order: false,\n url: {\n protocol: false,\n username: false,\n password: false,\n hostname: false, // we will record from different envs but run tests always against `frodo-dev`\n port: false,\n pathname: true,\n query: true,\n hash: true,\n },\n })\n );\n}\n\nfunction authenticationMatchRequestsBy() {\n const matchRequestsBy = defaultMatchRequestsBy();\n matchRequestsBy.body = false;\n matchRequestsBy.order = true;\n return matchRequestsBy;\n}\n\n// returns a delayed promise\nasync function delay(ms) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// performs a specific (mathematical) operation every \"ms\" (milliseconds)\nasync function countdown(i, ms) {\n await delay(ms);\n return --i;\n}\n\nasync function scheduleShutdown(polly: Polly, i = 30) {\n ++i;\n while ((i = await countdown(i, 1000)))\n console.log(`Polly stopping in ${i}s...`);\n await polly.stop();\n console.log(`Polly stopped.`);\n}\n\nexport function setupPollyForFrodoLib(\n matchRequestsBy = defaultMatchRequestsBy()\n): Polly {\n const polly = new Polly('default');\n\n polly.configure({\n adapters: ['node-http'],\n mode,\n recordIfMissing,\n flushRequestsOnStop: true,\n logLevel: (process.env.FRODO_POLLY_LOG_LEVEL as LogLevelDesc) || 'warn',\n recordFailedRequests: true,\n persister: 'fs',\n persisterOptions: {\n fs: {\n recordingsDir,\n },\n },\n matchRequestsBy,\n });\n\n for (const host of FRODO_MOCK_HOSTS) {\n if (mode === MODES.RECORD) console.log(`***** Host: ${host}`);\n polly.server.host(host, () => {\n polly.server\n .any('/am/oauth2/*')\n .recordingName('oauth2')\n .on('request', (req) => {\n req.configure({ matchRequestsBy: authenticationMatchRequestsBy() });\n });\n polly.server.any('/am/json/*').recordingName('am');\n polly.server.any('/openidm/*').recordingName('openidm');\n polly.server.any('/environment/*').recordingName('environment');\n polly.server.any('/monitoring/*').recordingName('monitoring');\n polly.server.any('/feature').recordingName('feature');\n polly.server.any('/dashboard/*').recordingName('dashboard');\n });\n }\n polly.server.host('https://api.github.com', () => {\n polly.server.any('/*').recordingName('github');\n });\n polly.server.host('https://registry.npmjs.org', () => {\n polly.server.any('/*').recordingName('npmjs');\n });\n\n if (mode === MODES.RECORD) {\n scheduleShutdown(polly, 60);\n } else {\n // only output debug messages if not recording as this polly instance is\n // primarily used by frodo-cli e2e tests, which capture stdout in snapshots.\n // debug messages falsify the snapshot recordings.\n debugMessage(`Polly config:`);\n debugMessage(polly.config);\n }\n\n return polly;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAEA;AAAoD;AAAA;AAAA;AAEpD,IAAMA,QAAS,GAAGC,aAAI,CAACC,OAAO,CAAC,IAAAC,kBAAa,sDAAiB,CAAC;AAE9D,IAAMC,gBAAgB,GAAG,CACvB,0CAA0C,EAC1C,iDAAiD,EACjD,2CAA2C,CAC5C;AAED,IAAIC,eAAe,GAAG,KAAK;AAC3B,IAAIC,IAAI,GAAGC,YAAK,CAACC,MAAM;;AAEvB;AACA;AACA,IAAMC,aAAa,GAAGT,QAAS,CAACU,OAAO,CACrC,2BAA2B,EAC3B,UAAU,CACX;AAED,IAAIC,OAAO,CAACC,GAAG,CAACC,UAAU,EAAE;EAC1BC,WAAK,CAACC,QAAQ,CAACC,wBAAe,CAAC;EAC/BF,WAAK,CAACC,QAAQ,CAACE,oBAAW,CAAC;EAC3B,IAAIN,OAAO,CAACC,GAAG,CAACC,UAAU,KAAK,QAAQ,EAAE;IACvCP,IAAI,GAAGC,YAAK,CAACW,MAAM;IACnBb,eAAe,GAAG,IAAI;EACxB;AACF;AAEA,SAASc,sBAAsB,GAAG;EAChC,OAAOC,IAAI,CAACC,KAAK,CAC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C,eAAe,CAAC,CAACC,aAAa,CAAC,YAAY,CAAC;MAC7DjB,KAAK,CAACe,MAAM,CAACC,GAAG,CAAC,UAAU,CAAC,CAACC,aAAa,CAAC,SAAS,CAAC;MACrDjB,KAAK,CAACe,MAAM,CAACC,GAAG,CAAC,cAAc,CAAC,CAACC,aAAa,CAAC,WAAW,CAAC;IAC7D,CAAC,CAAC;EACJ;EACAjB,KAAK,CAACe,MAAM,CAACD,IAAI,CAAC,wBAAwB,EAAE,MAAM;IAChDd,KAAK,CAACe,MAAM,CAACC,GAAG,CAAC,IAAI,CAAC,CAACC,aAAa,CAAC,QAAQ,CAAC;EAChD,CAAC,CAAC;EACFjB,KAAK,CAACe,MAAM,CAACD,IAAI,CAAC,4BAA4B,EAAE,MAAM;IACpDd,KAAK,CAACe,MAAM,CAACC,GAAG,CAAC,IAAI,CAAC,CAACC,aAAa,CAAC,OAAO,CAAC;EAC/C,CAAC,CAAC;EAEF,IAAIzD,IAAI,KAAKC,YAAK,CAACW,MAAM,EAAE;IACzB2B,gBAAgB,CAACC,KAAK,EAAE,EAAE,CAAC;EAC7B,CAAC,MAAM;IACL;IACA;IACA;IACA,IAAAoB,qBAAY,kBAAiB;IAC7B,IAAAA,qBAAY,EAACpB,KAAK,CAACqB,MAAM,CAAC;EAC5B;EAEA,OAAOrB,KAAK;AACd"}
@@ -4,6 +4,7 @@ import { Polly } from '@pollyjs/core';
4
4
  import { MODES } from '@pollyjs/utils';
5
5
  import NodeHttpAdapter from '@pollyjs/adapter-node-http';
6
6
  import FSPersister from '@pollyjs/persister-fs';
7
+ import { debugMessage } from '../ops/utils/Console';
7
8
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
9
  const FRODO_MOCK_HOSTS = ['https://openam-frodo-dev.forgeblocks.com', 'https://openam-service-accounts.forgeblocks.com', 'https://openam-volker-dev.forgeblocks.com'];
9
10
  let recordIfMissing = false;
@@ -102,7 +103,15 @@ export function setupPollyForFrodoLib(matchRequestsBy = defaultMatchRequestsBy()
102
103
  polly.server.host('https://registry.npmjs.org', () => {
103
104
  polly.server.any('/*').recordingName('npmjs');
104
105
  });
105
- if (mode === MODES.RECORD) scheduleShutdown(polly, 60);
106
+ if (mode === MODES.RECORD) {
107
+ scheduleShutdown(polly, 60);
108
+ } else {
109
+ // only output debug messages if not recording as this polly instance is
110
+ // primarily used by frodo-cli e2e tests, which capture stdout in snapshots.
111
+ // debug messages falsify the snapshot recordings.
112
+ debugMessage(`Polly config:`);
113
+ debugMessage(polly.config);
114
+ }
106
115
  return polly;
107
116
  }
108
117
  //# sourceMappingURL=SetupPollyForFrodoLib.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rockcarver/frodo-lib",
3
- "version": "0.17.8-2",
3
+ "version": "0.18.0",
4
4
  "type": "commonjs",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.mjs",
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/SetupPollyForFrodoLib.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAgFtC,wBAAgB,qBAAqB,CACnC,eAAe,MAA2B,GACzC,KAAK,CA8CP","file":"SetupPollyForFrodoLib.d.ts","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Polly } from '@pollyjs/core';\nimport { MODES } from '@pollyjs/utils';\nimport NodeHttpAdapter from '@pollyjs/adapter-node-http';\nimport FSPersister from '@pollyjs/persister-fs';\nimport { LogLevelDesc } from 'loglevel';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst FRODO_MOCK_HOSTS = [\n 'https://openam-frodo-dev.forgeblocks.com',\n 'https://openam-service-accounts.forgeblocks.com',\n 'https://openam-volker-dev.forgeblocks.com',\n];\n\nlet recordIfMissing = false;\nlet mode = MODES.REPLAY;\n\n// resolve \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/esm/api\" to\n// \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/src/test/recordings\"\nconst recordingsDir = __dirname.replace(\n /^(.*\\/frodo-\\w{3})(.*)$/gi,\n '$1/mocks'\n);\n\nif (process.env.FRODO_MOCK) {\n Polly.register(NodeHttpAdapter);\n Polly.register(FSPersister);\n if (process.env.FRODO_MOCK === 'record') {\n mode = MODES.RECORD;\n recordIfMissing = true;\n }\n}\n\nfunction defaultMatchRequestsBy() {\n return JSON.parse(\n JSON.stringify({\n method: true,\n headers: false, // do not match headers, because \"Authorization\" header is sent only at recording time\n body: true,\n order: false,\n url: {\n protocol: false,\n username: false,\n password: false,\n hostname: false, // we will record from different envs but run tests always against `frodo-dev`\n port: false,\n pathname: true,\n query: true,\n hash: true,\n },\n })\n );\n}\n\nfunction authenticationMatchRequestsBy() {\n const matchRequestsBy = defaultMatchRequestsBy();\n matchRequestsBy.body = false;\n matchRequestsBy.order = true;\n return matchRequestsBy;\n}\n\n// returns a delayed promise\nasync function delay(ms) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// performs a specific (mathematical) operation every \"ms\" (milliseconds)\nasync function countdown(i, ms) {\n await delay(ms);\n return --i;\n}\n\nasync function scheduleShutdown(polly: Polly, i = 30) {\n ++i;\n while ((i = await countdown(i, 1000)))\n console.log(`Polly stopping in ${i}s...`);\n await polly.stop();\n console.log(`Polly stopped.`);\n}\n\nexport function setupPollyForFrodoLib(\n matchRequestsBy = defaultMatchRequestsBy()\n): Polly {\n const polly = new Polly('default');\n\n polly.configure({\n adapters: ['node-http'],\n mode,\n recordIfMissing,\n flushRequestsOnStop: true,\n logLevel: (process.env.FRODO_POLLY_LOG_LEVEL as LogLevelDesc) || 'warn',\n recordFailedRequests: true,\n persister: 'fs',\n persisterOptions: {\n fs: {\n recordingsDir,\n },\n },\n matchRequestsBy,\n });\n\n for (const host of FRODO_MOCK_HOSTS) {\n if (mode === MODES.RECORD) console.log(`***** Host: ${host}`);\n polly.server.host(host, () => {\n polly.server\n .any('/am/oauth2/*')\n .recordingName('oauth2')\n .on('request', (req) => {\n req.configure({ matchRequestsBy: authenticationMatchRequestsBy() });\n });\n polly.server.any('/am/json/*').recordingName('am');\n polly.server.any('/openidm/*').recordingName('openidm');\n polly.server.any('/environment/*').recordingName('environment');\n polly.server.any('/monitoring/*').recordingName('monitoring');\n polly.server.any('/feature').recordingName('feature');\n polly.server.any('/dashboard/*').recordingName('dashboard');\n });\n }\n polly.server.host('https://api.github.com', () => {\n polly.server.any('/*').recordingName('github');\n });\n polly.server.host('https://registry.npmjs.org', () => {\n polly.server.any('/*').recordingName('npmjs');\n });\n\n if (mode === MODES.RECORD) scheduleShutdown(polly, 60);\n\n return polly;\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/SetupPollyForFrodoLib.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAiFtC,wBAAgB,qBAAqB,CACnC,eAAe,MAA2B,GACzC,KAAK,CAsDP","file":"SetupPollyForFrodoLib.d.ts","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Polly } from '@pollyjs/core';\nimport { MODES } from '@pollyjs/utils';\nimport NodeHttpAdapter from '@pollyjs/adapter-node-http';\nimport FSPersister from '@pollyjs/persister-fs';\nimport { LogLevelDesc } from 'loglevel';\nimport { debugMessage } from '../ops/utils/Console';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst FRODO_MOCK_HOSTS = [\n 'https://openam-frodo-dev.forgeblocks.com',\n 'https://openam-service-accounts.forgeblocks.com',\n 'https://openam-volker-dev.forgeblocks.com',\n];\n\nlet recordIfMissing = false;\nlet mode = MODES.REPLAY;\n\n// resolve \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/esm/api\" to\n// \"/home/sandeepc/work/ForgeRock/sources/frodo-lib/src/test/recordings\"\nconst recordingsDir = __dirname.replace(\n /^(.*\\/frodo-\\w{3})(.*)$/gi,\n '$1/mocks'\n);\n\nif (process.env.FRODO_MOCK) {\n Polly.register(NodeHttpAdapter);\n Polly.register(FSPersister);\n if (process.env.FRODO_MOCK === 'record') {\n mode = MODES.RECORD;\n recordIfMissing = true;\n }\n}\n\nfunction defaultMatchRequestsBy() {\n return JSON.parse(\n JSON.stringify({\n method: true,\n headers: false, // do not match headers, because \"Authorization\" header is sent only at recording time\n body: true,\n order: false,\n url: {\n protocol: false,\n username: false,\n password: false,\n hostname: false, // we will record from different envs but run tests always against `frodo-dev`\n port: false,\n pathname: true,\n query: true,\n hash: true,\n },\n })\n );\n}\n\nfunction authenticationMatchRequestsBy() {\n const matchRequestsBy = defaultMatchRequestsBy();\n matchRequestsBy.body = false;\n matchRequestsBy.order = true;\n return matchRequestsBy;\n}\n\n// returns a delayed promise\nasync function delay(ms) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// performs a specific (mathematical) operation every \"ms\" (milliseconds)\nasync function countdown(i, ms) {\n await delay(ms);\n return --i;\n}\n\nasync function scheduleShutdown(polly: Polly, i = 30) {\n ++i;\n while ((i = await countdown(i, 1000)))\n console.log(`Polly stopping in ${i}s...`);\n await polly.stop();\n console.log(`Polly stopped.`);\n}\n\nexport function setupPollyForFrodoLib(\n matchRequestsBy = defaultMatchRequestsBy()\n): Polly {\n const polly = new Polly('default');\n\n polly.configure({\n adapters: ['node-http'],\n mode,\n recordIfMissing,\n flushRequestsOnStop: true,\n logLevel: (process.env.FRODO_POLLY_LOG_LEVEL as LogLevelDesc) || 'warn',\n recordFailedRequests: true,\n persister: 'fs',\n persisterOptions: {\n fs: {\n recordingsDir,\n },\n },\n matchRequestsBy,\n });\n\n for (const host of FRODO_MOCK_HOSTS) {\n if (mode === MODES.RECORD) console.log(`***** Host: ${host}`);\n polly.server.host(host, () => {\n polly.server\n .any('/am/oauth2/*')\n .recordingName('oauth2')\n .on('request', (req) => {\n req.configure({ matchRequestsBy: authenticationMatchRequestsBy() });\n });\n polly.server.any('/am/json/*').recordingName('am');\n polly.server.any('/openidm/*').recordingName('openidm');\n polly.server.any('/environment/*').recordingName('environment');\n polly.server.any('/monitoring/*').recordingName('monitoring');\n polly.server.any('/feature').recordingName('feature');\n polly.server.any('/dashboard/*').recordingName('dashboard');\n });\n }\n polly.server.host('https://api.github.com', () => {\n polly.server.any('/*').recordingName('github');\n });\n polly.server.host('https://registry.npmjs.org', () => {\n polly.server.any('/*').recordingName('npmjs');\n });\n\n if (mode === MODES.RECORD) {\n scheduleShutdown(polly, 60);\n } else {\n // only output debug messages if not recording as this polly instance is\n // primarily used by frodo-cli e2e tests, which capture stdout in snapshots.\n // debug messages falsify the snapshot recordings.\n debugMessage(`Polly config:`);\n debugMessage(polly.config);\n }\n\n return polly;\n}\n"]}