@smartbear/fake-ap
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [1.2.0] | ||
- Implement `AP.context.getContext` | ||
- For now only Jira projects and issues are supported | ||
- It is possible to configure the context returned by providing information to the Fake AP configuration | ||
- Update `AP.context.getToken` to include the context returned from `AP.context.getContext` | ||
- Remove the `moment` package dependency | ||
## [1.1.1] | ||
@@ -7,0 +15,0 @@ |
@@ -19,3 +19,3 @@ "use strict"; | ||
_defineProperty(this, "setConfig", config => { | ||
var _config$clientKey, _config$sharedSecret, _config$userId, _config$dialogUrls, _config$locale, _config$mountDialogs, _config$mountFlags; | ||
var _config$clientKey, _config$sharedSecret, _config$userId, _config$contextJiraPr, _config$contextJiraPr2, _config$contextJiraIs, _config$contextJiraIs2, _config$dialogUrls, _config$locale, _config$mountDialogs, _config$mountFlags; | ||
@@ -37,2 +37,6 @@ if (typeof config.notImplementedAction === 'function') { | ||
this.userId = (_config$userId = config.userId) !== null && _config$userId !== void 0 ? _config$userId : this.userId; | ||
this.contextJiraProjectId = (_config$contextJiraPr = config.contextJiraProjectId) !== null && _config$contextJiraPr !== void 0 ? _config$contextJiraPr : this.contextJiraProjectId; | ||
this.contextJiraProjectKey = (_config$contextJiraPr2 = config.contextJiraProjectKey) !== null && _config$contextJiraPr2 !== void 0 ? _config$contextJiraPr2 : this.contextJiraProjectKey; | ||
this.contextJiraIssueId = (_config$contextJiraIs = config.contextJiraIssueId) !== null && _config$contextJiraIs !== void 0 ? _config$contextJiraIs : this.contextJiraIssueId; | ||
this.contextJiraIssueKey = (_config$contextJiraIs2 = config.contextJiraIssueKey) !== null && _config$contextJiraIs2 !== void 0 ? _config$contextJiraIs2 : this.contextJiraIssueKey; | ||
this.dialogUrls = (_config$dialogUrls = config.dialogUrls) !== null && _config$dialogUrls !== void 0 ? _config$dialogUrls : this.dialogUrls; | ||
@@ -61,2 +65,6 @@ this.locale = (_config$locale = config.locale) !== null && _config$locale !== void 0 ? _config$locale : this.locale; | ||
this.userId = null; | ||
this.contextJiraProjectId = null; | ||
this.contextJiraProjectKey = null; | ||
this.contextJiraIssueId = null; | ||
this.contextJiraIssueKey = null; | ||
this.dialogUrls = {}; | ||
@@ -63,0 +71,0 @@ this.locale = null; |
@@ -10,4 +10,2 @@ "use strict"; | ||
var _moment = _interopRequireDefault(require("moment")); | ||
var _config = _interopRequireDefault(require("../config")); | ||
@@ -25,2 +23,4 @@ | ||
constructor() { | ||
var _this = this; | ||
_defineProperty(this, "getToken", async function () { | ||
@@ -41,3 +41,5 @@ let callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : () => {}; | ||
const now = (0, _moment.default)().utc(); | ||
const context = await _this.getContext(); | ||
const iat = Math.trunc(Date.now() / 1000); | ||
const exp = iat + 300; | ||
const payload = { | ||
@@ -47,4 +49,5 @@ iss: _config.default.clientKey, | ||
qsh: 'context-qsh', | ||
iat: now.unix(), | ||
exp: now.add(5, 'minutes').unix() | ||
context: context, | ||
iat: iat, | ||
exp: exp | ||
}; | ||
@@ -57,7 +60,36 @@ const token = jwt.encodeSymmetric(payload, _config.default.sharedSecret); | ||
_defineProperty(this, "getContext", async function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
let callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : () => {}; | ||
const context = {}; | ||
const jira = {}; | ||
if (_config.default.contextJiraProjectId || _config.default.contextJiraProjectKey) { | ||
jira.project = {}; | ||
if (_config.default.contextJiraProjectId) { | ||
jira.project.id = _config.default.contextJiraProjectId; | ||
} | ||
if (_config.default.contextJiraProjectKey) { | ||
jira.project.key = _config.default.contextJiraProjectKey; | ||
} | ||
} | ||
return _config.default.notImplemented.apply(_config.default, ['AP.context.getContext'].concat(args)); | ||
if (_config.default.contextJiraIssueId || _config.default.contextJiraIssueKey) { | ||
jira.issue = {}; | ||
if (_config.default.contextJiraIssueId) { | ||
jira.issue.id = _config.default.contextJiraIssueId; | ||
} | ||
if (_config.default.contextJiraIssueKey) { | ||
jira.issue.key = _config.default.contextJiraIssueKey; | ||
} | ||
} | ||
if (jira.project || jira.issue) { | ||
context.jira = jira; | ||
} | ||
callback(context); | ||
return context; | ||
}); | ||
@@ -64,0 +96,0 @@ } |
{ | ||
"name": "@smartbear/fake-ap", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A fake AP module to help develop and test Atlassian Connect applications.", | ||
@@ -26,10 +26,10 @@ "homepage": "https://github.com/SmartBear/fake-ap", | ||
"devDependencies": { | ||
"@babel/cli": "^7.13.16", | ||
"@babel/core": "^7.14.0", | ||
"@babel/eslint-parser": "^7.13.14", | ||
"@babel/cli": "^7.14.3", | ||
"@babel/core": "^7.14.3", | ||
"@babel/eslint-parser": "^7.14.3", | ||
"@babel/eslint-plugin": "^7.13.16", | ||
"@babel/preset-env": "^7.14.1", | ||
"@babel/preset-env": "^7.14.2", | ||
"@babel/preset-react": "^7.13.13", | ||
"@testing-library/jest-dom": "^5.12.0", | ||
"@testing-library/react": "^11.2.6", | ||
"@testing-library/react": "^11.2.7", | ||
"babel-loader": "^8.2.2", | ||
@@ -39,8 +39,8 @@ "babel-plugin-module-resolver": "^4.1.0", | ||
"crypto-browserify": "^3.12.0", | ||
"eslint": "^7.25.0", | ||
"eslint-config-standard": "^16.0.2", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint": "^7.27.0", | ||
"eslint-config-standard": "^16.0.3", | ||
"eslint-plugin-import": "^2.23.3", | ||
"eslint-plugin-jest": "^24.3.6", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.3.1", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-react": "^7.23.2", | ||
@@ -58,4 +58,4 @@ "html-webpack-plugin": "^5.3.1", | ||
"styled-components": "^5.3.0", | ||
"webpack": "^5.36.2", | ||
"webpack-cli": "^4.6.0", | ||
"webpack": "^5.38.1", | ||
"webpack-cli": "^4.7.0", | ||
"webpack-dev-server": "^3.11.2" | ||
@@ -67,3 +67,2 @@ }, | ||
"http-status-codes": "^2.1.4", | ||
"moment": "^2.29.1", | ||
"signals": "^1.0.0" | ||
@@ -70,0 +69,0 @@ }, |
@@ -91,2 +91,6 @@ # Fake AP | ||
| `userId` | `null` | The user ID for `AP.context.getToken` | | ||
| `contextJiraProjectId` | `null` | The project ID for `AP.context.getToken` | | ||
| `contextJiraProjectKey` | `null` | The project key for `AP.context.getToken` | | ||
| `contextJiraIssueId` | `null` | The issue ID for `AP.context.getToken` | | ||
| `contextJiraIssueKey` | `null` | The issue key for `AP.context.getToken` | | ||
| `dialogUrls` | `{}` | URLs to call when using `AP.dialog.create` | | ||
@@ -114,2 +118,19 @@ | `locale` | `en_US` | The user locale for `AP.user.getLocale` | | ||
You can also configure context information for the Jira project and the Jira issue (see `AP.context.getContext`). | ||
### `AP.context.getContext` | ||
To use `AP.context.getContext`, you can provide the ID and the key of a Jira project and of a Jira issue: | ||
```javascript | ||
AP.configure({ | ||
contextJiraProjectId: '10000', | ||
contextJiraProjectKey: 'PRO-1', | ||
contextJiraIssueId: '10001', | ||
contextJiraIssueKey: 'ISS-1' | ||
}) | ||
``` | ||
Providing all information is not mandatory, you can configure only one or several fields (for instance only the project ID and the issue ID). | ||
### `AP.dialog` | ||
@@ -116,0 +137,0 @@ |
77405
7
1187
392
- Removedmoment@^2.29.1
- Removedmoment@2.30.1(transitive)