@forge/api
Advanced tools
Comparing version 0.4.0-next.0 to 0.4.0-next.1
# @forge/api | ||
## 0.4.0-next.1 | ||
### Patch Changes | ||
- 8a41f17: Make Global Storage implementation compatible with snapshot | ||
## 0.4.0-next.0 | ||
@@ -4,0 +10,0 @@ |
@@ -16,12 +16,5 @@ "use strict"; | ||
global.api = { | ||
__getAppAri: () => 'app-ari' | ||
__getAppAri: jest.fn().mockReturnValue('app-ari') | ||
}; | ||
}); | ||
describe('constructor', () => { | ||
it('should not throw an exception if the __getAppAri method is not available', () => { | ||
delete global.api.__getAppAri; | ||
const apiClientMock = getApiClientMock(); | ||
expect(getStorage(apiClientMock)).toBeInstanceOf(global_storage_1.GlobalStorage); | ||
}); | ||
}); | ||
describe('get', () => { | ||
@@ -156,2 +149,17 @@ it('should call the storage API, passing the provided key and returning the stored value', async () => { | ||
}); | ||
describe('getAppContextAri', () => { | ||
it('should not throw an exception if the __getAppAri runtime method is not available', () => { | ||
delete global.api.__getAppAri; | ||
const apiClientMock = getApiClientMock(); | ||
const globalStorage = getStorage(apiClientMock); | ||
expect(globalStorage.getAppContextAri()).toBeUndefined(); | ||
}); | ||
it('should properly return the apps context ari and cache the result', () => { | ||
const apiClientMock = getApiClientMock(); | ||
const globalStorage = getStorage(apiClientMock); | ||
expect(globalStorage.getAppContextAri()).toEqual('app-ari'); | ||
expect(globalStorage.getAppContextAri()).toEqual('app-ari'); | ||
expect(global.api.__getAppAri).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
@@ -8,2 +8,3 @@ import { StorageAdapter } from '../storage-adapter'; | ||
constructor(apiClient: FetchMethod); | ||
getAppContextAri(): string; | ||
get(key: string): Promise<any>; | ||
@@ -10,0 +11,0 @@ set(key: string, value: any): Promise<void>; |
@@ -7,9 +7,14 @@ "use strict"; | ||
constructor(apiClient) { | ||
var _a, _b; | ||
this.apiClient = apiClient; | ||
this.endpoint = '/forge/entities/graphql'; | ||
this.appContextAri = (_b = (_a = global.api).__getAppAri) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
} | ||
getAppContextAri() { | ||
var _a, _b; | ||
if (!this.appContextAri) { | ||
this.appContextAri = (_b = (_a = global.api).__getAppAri) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
} | ||
return this.appContextAri; | ||
} | ||
async get(key) { | ||
const requestBody = queries_1.getQuery(this.appContextAri, key); | ||
const requestBody = queries_1.getQuery(this.getAppContextAri(), key); | ||
const response = await this.apiClient(this.endpoint, this.buildRequest(requestBody)); | ||
@@ -25,3 +30,3 @@ const { data, errors } = await response.json(); | ||
async set(key, value) { | ||
const requestBody = queries_1.setQuery(this.appContextAri, key, value); | ||
const requestBody = queries_1.setQuery(this.getAppContextAri(), key, value); | ||
const response = await this.apiClient(this.endpoint, this.buildRequest(requestBody)); | ||
@@ -34,3 +39,3 @@ const success = this.isSuccessfulResponse(await response.json(), 'setAppStoredEntity'); | ||
async delete(key) { | ||
const requestBody = queries_1.deleteQuery(this.appContextAri, key); | ||
const requestBody = queries_1.deleteQuery(this.getAppContextAri(), key); | ||
const response = await this.apiClient(this.endpoint, this.buildRequest(requestBody)); | ||
@@ -37,0 +42,0 @@ const success = this.isSuccessfulResponse(await response.json(), 'deleteAppStoredEntity'); |
{ | ||
"name": "@forge/api", | ||
"version": "0.4.0-next.0", | ||
"version": "0.4.0-next.1", | ||
"description": "Forge API methods", | ||
@@ -5,0 +5,0 @@ "author": "Atlassian", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48308
869