🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@forge/react

Package Overview
Dependencies
Maintainers
2
Versions
429
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@forge/react - npm Package Compare versions

Comparing version
9.2.0-next.1
to
9.2.0-next.2
+2
out/hooks/__test__/jiraEntity.test.d.ts
export {};
//# sourceMappingURL=jiraEntity.test.d.ts.map
{"version":3,"file":"jiraEntity.test.d.ts","sourceRoot":"","sources":["../../../src/hooks/__test__/jiraEntity.test.ts"],"names":[],"mappings":""}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mockRequestJira = jest.fn();
const mockGetContext = jest.fn(async () => mockPropertyHook_1.mockJiraContext);
const jiraEntity_1 = require("../jiraEntity");
const mockPropertyHook_1 = require("./mockPropertyHook");
jest.mock('@forge/bridge', () => ({
requestJira: mockRequestJira,
view: { getContext: mockGetContext }
}));
describe('issueAPIEndpoints string generation, given an entityType, productContext and required property data', () => {
const issueEndpoints = (0, jiraEntity_1.issueAPIEndpoints)(mockPropertyHook_1.mockJiraContext);
it('should generate the expected property create URL', () => {
expect(issueEndpoints.create()).toEqual('/rest/api/2/issue/properties');
});
it('should generate the expected property get URL', () => {
expect(issueEndpoints.fetch('MOCK_PROP_KEY')).toEqual('/rest/api/2/issue/MOCK_ISSUE_ID/properties/MOCK_PROP_KEY');
});
it('should generate the expected property update URL', () => {
expect(issueEndpoints.update('MOCK_PROP_KEY')).toEqual('/rest/api/2/issue/MOCK_ISSUE_ID/properties/MOCK_PROP_KEY');
});
it('should generate the expected property delete URL', () => {
expect(issueEndpoints.delete('MOCK_PROP_KEY')).toEqual('/rest/api/2/issue/MOCK_ISSUE_ID/properties/MOCK_PROP_KEY');
});
it('should throw an error if issueId not available', () => {
expect(() => (0, jiraEntity_1.issueAPIEndpoints)({ extension: {} })).toThrow('Issue properties not available for this app.');
});
});
describe('jiraIssuePropsManager', () => {
const issueProps = (0, jiraEntity_1.jiraIssuePropsManager)({
entityType: 'Issue',
origPropertyKey: 'MOCK_PROP_KEY',
initValue: mockPropertyHook_1.DEFAULT_PROP_VALUE
});
const issueEndpoints = (0, jiraEntity_1.issueAPIEndpoints)(mockPropertyHook_1.mockJiraContext);
afterEach(() => jest.clearAllMocks());
describe('when running its get() output function', () => {
beforeAll(() => {
mockRequestJira.mockResolvedValue(mockPropertyHook_1.mockJiraGetExistingRes);
});
it('should make a GET request with the right URL', async () => {
const issueGetUrl = issueEndpoints.fetch('forge-MOCK_PROP_KEY');
const issueGetBody = expect.objectContaining({ method: 'GET' });
await issueProps.get();
expect(mockRequestJira).toHaveBeenNthCalledWith(1, issueGetUrl, issueGetBody);
});
it('if the property exists, it should return its value', async () => {
const output = await issueProps.get();
expect(output).toEqual(mockPropertyHook_1.EXISTING_PROP_VALUE);
expect(mockRequestJira).toHaveBeenCalledTimes(1);
});
it('should throw an error if the GET request fails', async () => {
mockRequestJira.mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(issueProps.get).rejects.toThrow(`The request to fetch the issue property (forge-MOCK_PROP_KEY) failed with status (400).`);
});
describe('if the property does not exist, it should create it', () => {
beforeEach(() => {
mockRequestJira.mockResolvedValueOnce(mockPropertyHook_1.mockJiraGetNonExistentRes).mockResolvedValueOnce(mockPropertyHook_1.mockJiraSuccessRes);
});
it('should make a POST request to the API with the right URL and body', async () => {
const issuePostUrl = issueEndpoints.create();
const issuePostBody = expect.objectContaining({
method: 'POST',
body: JSON.stringify({
entitiesIds: ['MOCK_ISSUE_ID'],
properties: { 'forge-MOCK_PROP_KEY': mockPropertyHook_1.DEFAULT_PROP_VALUE }
})
});
await issueProps.get();
expect(mockRequestJira).toHaveBeenCalledTimes(2);
expect(mockRequestJira).toHaveBeenNthCalledWith(2, issuePostUrl, issuePostBody);
});
it('should return the value of the created property (i.e. DEFAULT_PROP_VALUE value)', async () => {
const output = await issueProps.get();
expect(output).toEqual(mockPropertyHook_1.DEFAULT_PROP_VALUE);
});
it('should throw an error if the POST request fails', async () => {
mockRequestJira.mockReset();
mockRequestJira.mockResolvedValueOnce(mockPropertyHook_1.mockJiraGetNonExistentRes).mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(issueProps.get).rejects.toThrow(`The request to create the issue property (forge-MOCK_PROP_KEY) failed with status (400).`);
});
});
});
describe('when running its update() output function', () => {
beforeEach(() => {
mockRequestJira.mockResolvedValueOnce(mockPropertyHook_1.mockJiraGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockJiraSuccessRes);
});
it('should fetch the original property, then make a PUT request with the right url and body', async () => {
const issueGetUrl = issueEndpoints.fetch('forge-MOCK_PROP_KEY');
const issueGetBody = expect.objectContaining({ method: 'GET' });
const issuePutUrl = issueEndpoints.update('forge-MOCK_PROP_KEY');
const issuePutBody = expect.objectContaining({
body: JSON.stringify(mockPropertyHook_1.UPDATED_PROP_VALUE)
});
await issueProps.update(mockPropertyHook_1.UPDATED_PROP_VALUE);
expect(mockRequestJira).toHaveBeenCalledTimes(2);
expect(mockRequestJira).toHaveBeenNthCalledWith(1, issueGetUrl, issueGetBody);
expect(mockRequestJira).toHaveBeenNthCalledWith(2, issuePutUrl, issuePutBody);
});
it('should return the value of the UPDATED_PROP_VALUE property when updating with solid value', async () => {
const valUpdate = await issueProps.update(mockPropertyHook_1.UPDATED_PROP_VALUE);
expect(valUpdate).toEqual(mockPropertyHook_1.UPDATED_PROP_VALUE);
});
it('should return the value of the UPDATED_PROP_VALUE property when updating with setter function', async () => {
const updateCBFunc = (existingVal) => {
return existingVal * mockPropertyHook_1.UPDATED_PROP_VALUE;
};
const expectedResult = mockPropertyHook_1.EXISTING_PROP_VALUE * mockPropertyHook_1.UPDATED_PROP_VALUE;
const funcUpdate = await issueProps.update(updateCBFunc);
expect(funcUpdate).toEqual(expectedResult);
});
it('should throw an error if the PUT request fails', async () => {
mockRequestJira.mockReset();
mockRequestJira.mockResolvedValueOnce(mockPropertyHook_1.mockJiraGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(() => issueProps.update(mockPropertyHook_1.UPDATED_PROP_VALUE)).rejects.toThrow(`The request to update the issue property (forge-MOCK_PROP_KEY) failed with status (400).`);
});
});
describe('when running its delete() output function', () => {
beforeEach(() => {
mockRequestJira.mockResolvedValueOnce(mockPropertyHook_1.mockJiraGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockJiraSuccessRes);
});
it('should make a DELETE request to the API with the right url', async () => {
const issueDeleteUrl = issueEndpoints.delete('forge-MOCK_PROP_KEY');
const issueDeleteBody = expect.objectContaining({ method: 'DELETE' });
await issueProps.delete();
expect(mockRequestJira).toHaveBeenCalledTimes(1);
expect(mockRequestJira).toHaveBeenNthCalledWith(1, issueDeleteUrl, issueDeleteBody);
});
it('should throw an error if the DELETE request fails', async () => {
mockRequestJira.mockReset();
mockRequestJira.mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(issueProps.delete).rejects.toThrow(`The request to delete the issue property (forge-MOCK_PROP_KEY) failed with status (400).`);
});
});
});
import { EntityContext, ManagePropsData } from './types';
export declare const issueAPIEndpoints: (context: EntityContext) => {
create: () => string;
fetch: (propertyKey: string) => string;
update: (propertyKey: string) => string;
delete: (propertyKey: string) => string;
};
export declare const jiraIssuePropsManager: <PropValue>({ origPropertyKey, initValue }: ManagePropsData<PropValue>) => {
get: (...args: unknown[]) => Promise<any>;
update: (...args: unknown[]) => Promise<any>;
delete: (...args: unknown[]) => Promise<any>;
};
//# sourceMappingURL=jiraEntity.d.ts.map
{"version":3,"file":"jiraEntity.d.ts","sourceRoot":"","sources":["../../src/hooks/jiraEntity.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,aAAa,EAEb,eAAe,EAEhB,MAAM,SAAS,CAAC;AAMjB,eAAO,MAAM,iBAAiB,YAAa,aAAa;;yBAM/B,MAAM;0BACL,MAAM;0BACN,MAAM;CAE/B,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;CAoGjC,CAAC"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jiraIssuePropsManager = exports.issueAPIEndpoints = void 0;
const bridge_1 = require("@forge/bridge");
const apiRequestUtils_1 = require("./utils/apiRequestUtils");
const valueUtils_1 = require("./utils/valueUtils");
const types_1 = require("./types");
const issueAPIEndpoints = (context) => {
var _a;
const issueId = (_a = context.extension.issue) === null || _a === void 0 ? void 0 : _a.id;
if (!issueId)
throw new Error('Issue properties not available for this app.');
return {
create: () => `/rest/api/2/issue/properties`,
fetch: (propertyKey) => `/rest/api/2/issue/${issueId}/properties/${propertyKey}`,
update: (propertyKey) => `/rest/api/2/issue/${issueId}/properties/${propertyKey}`,
delete: (propertyKey) => `/rest/api/2/issue/${issueId}/properties/${propertyKey}`
};
};
exports.issueAPIEndpoints = issueAPIEndpoints;
const jiraIssuePropsManager = ({ origPropertyKey, initValue }) => {
const entityType = 'Issue';
const apiMethod = bridge_1.requestJira;
const withIssueContext = (originalOperation) => {
return (0, apiRequestUtils_1.withContext)({
originalOperation,
apiEndpoints: exports.issueAPIEndpoints,
entityType: 'Issue',
origPropertyKey
});
};
const fetchOriginal = async ({ endpointFactory, propertyKey }) => {
const url = endpointFactory.fetch(propertyKey);
const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'GET' });
try {
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'fetch', response });
}
catch (err) {
if (response.status === 404) {
return null;
}
else {
throw err;
}
}
const existingData = await (0, apiRequestUtils_1.getJSONData)(response);
return existingData;
};
const deleteProp = async ({ endpointFactory, propertyKey }) => {
const url = endpointFactory.delete(propertyKey);
const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'DELETE' });
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'delete', response });
};
const get = async ({ endpointFactory, propertyKey, context }) => {
var _a;
const existingProp = await fetchOriginal({ endpointFactory, propertyKey, context });
if (existingProp) {
return existingProp.value;
}
const resolvedInitVal = await (0, valueUtils_1.resolveValue)(initValue);
const url = endpointFactory.create();
const entityId = (_a = context.extension.issue) === null || _a === void 0 ? void 0 : _a.id;
const bodyData = {
entitiesIds: [entityId],
properties: {
[propertyKey]: resolvedInitVal
}
};
const response = await (0, apiRequestUtils_1.makeRequest)({
url,
apiMethod,
method: 'POST',
body: JSON.stringify(bodyData)
});
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'create', response });
return resolvedInitVal;
};
const update = async ({ endpointFactory, propertyKey, context }, valueUpdate) => {
const originalProp = await fetchOriginal({ endpointFactory, propertyKey, context });
if (!originalProp) {
throw new types_1.EntityPropertyRequestFailedError({
entityType,
propertyKey,
operation: 'update',
status: 404
});
}
const newValue = valueUpdate instanceof Function ? valueUpdate(originalProp.value) : valueUpdate;
const url = endpointFactory.update(propertyKey);
const body = JSON.stringify(newValue);
const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'PUT', body });
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'update', response });
return newValue;
};
return {
get: withIssueContext(get),
update: withIssueContext(update),
delete: withIssueContext(deleteProp)
};
};
exports.jiraIssuePropsManager = jiraIssuePropsManager;
export declare const useIssueProperty: <PropValue>(propertyKey: string, initValue: PropValue) => readonly [any, (valueUpdate: any, retryCount?: number) => Promise<void>, () => Promise<void>];
//# sourceMappingURL=useIssueProperty.d.ts.map
{"version":3,"file":"useIssueProperty.d.ts","sourceRoot":"","sources":["../../src/hooks/useIssueProperty.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,gBAAgB,2BAA4B,MAAM,wHAW9D,CAAC"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIssueProperty = void 0;
const react_1 = require("react");
const jiraEntity_1 = require("./jiraEntity");
const useEntityProperty_1 = require("./useEntityProperty");
const useIssueProperty = (propertyKey, initValue) => {
const entityManager = (0, react_1.useMemo)(() => (0, jiraEntity_1.jiraIssuePropsManager)({
entityType: 'Issue',
origPropertyKey: propertyKey,
initValue
}), []);
return (0, useEntityProperty_1.useEntityProperty)(entityManager);
};
exports.useIssueProperty = useIssueProperty;
+12
-0
# @forge/react
## 9.2.0-next.2
### Minor Changes
- f922a25: creates useIssueProperty hook for UI kit 2
- useIssueProperty:
- manages a Jira issue's property (via Jira v2 API)
- requires the following scopes:
- read:jira-work
- write:jira-work
## 9.2.0-next.1

@@ -4,0 +16,0 @@

+4
-4

@@ -59,3 +59,3 @@ "use strict";

it('should throw an error if the GET request fails', async () => {
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfFailedRes);
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(contentEntity.get).rejects.toThrow(`The request to fetch the content property (forge-undefined-MOCK_PROP_KEY) failed with status (400).`);

@@ -83,3 +83,3 @@ });

mockRequestConf.mockReset();
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetNonExistentRes).mockResolvedValueOnce(mockPropertyHook_1.mockConfFailedRes);
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetNonExistentRes).mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(contentEntity.get).rejects.toThrow(`The request to create the content property (forge-undefined-MOCK_PROP_KEY) failed with status (400).`);

@@ -125,3 +125,3 @@ });

mockRequestConf.mockReset();
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockConfFailedRes);
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(() => contentEntity.update(mockPropertyHook_1.UPDATED_PROP_VALUE)).rejects.toThrow(`The request to update the content property (forge-undefined-MOCK_PROP_KEY) failed with status (400).`);

@@ -147,3 +147,3 @@ });

mockRequestConf.mockReset();
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockConfFailedRes);
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
await expect(contentEntity.delete).rejects.toThrow(`The request to delete the content property (forge-undefined-MOCK_PROP_KEY) failed with status (400).`);

@@ -150,0 +150,0 @@ });

import { EntityContext } from '../types';
export declare const DEFAULT_PROP_VALUE: number, EXISTING_PROP_VALUE: number, UPDATED_PROP_VALUE: number;
export declare const mockConfContext: EntityContext;
export declare const mockConfFailedRes: {
export declare const mockJiraContext: EntityContext;
export declare const mockFailedRes: {
ok: boolean;

@@ -56,2 +57,18 @@ status: number;

};
export declare const mockJiraSuccessRes: {
ok: boolean;
status: number;
};
export declare const mockJiraGetExistingRes: {
ok: boolean;
status: number;
json: () => {
key: string;
value: number;
};
};
export declare const mockJiraGetNonExistentRes: {
ok: boolean;
status: number;
};
//# sourceMappingURL=mockPropertyHook.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"mockPropertyHook.d.ts","sourceRoot":"","sources":["../../../src/hooks/__test__/mockPropertyHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,eAAO,MAAO,kBAAkB,UAAE,mBAAmB,UAAE,kBAAkB,QAAa,CAAC;AAEvF,eAAO,MAAM,eAAe,EAAE,aAS7B,CAAC;AAKF,eAAO,MAAM,iBAAiB;;;CAG7B,CAAC;AACF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;CAMlC,CAAC;AACF,eAAO,MAAM,yBAAyB;;;;;;CAMrC,CAAC;AACF,eAAO,MAAM,iBAAiB;;;;;;;CAI7B,CAAC;AACF,eAAO,MAAM,sBAAsB;;;;;;;CAIlC,CAAC;AACF,eAAO,MAAM,yBAAyB;;;;;;;CAIrC,CAAC;AACF,eAAO,MAAM,iBAAiB;;;CAG7B,CAAC"}
{"version":3,"file":"mockPropertyHook.d.ts","sourceRoot":"","sources":["../../../src/hooks/__test__/mockPropertyHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,eAAO,MAAO,kBAAkB,UAAE,mBAAmB,UAAE,kBAAkB,QAAa,CAAC;AAEvF,eAAO,MAAM,eAAe,EAAE,aAS7B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,aAM7B,CAAC;AAKF,eAAO,MAAM,aAAa;;;CAGzB,CAAC;AACF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;CAMlC,CAAC;AACF,eAAO,MAAM,yBAAyB;;;;;;CAMrC,CAAC;AACF,eAAO,MAAM,iBAAiB;;;;;;;CAI7B,CAAC;AACF,eAAO,MAAM,sBAAsB;;;;;;;CAIlC,CAAC;AACF,eAAO,MAAM,yBAAyB;;;;;;;CAIrC,CAAC;AACF,eAAO,MAAM,iBAAiB;;;CAG7B,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;CAG9B,CAAC;AACF,eAAO,MAAM,sBAAsB;;;;;;;CAIlC,CAAC;AACF,eAAO,MAAM,yBAAyB;;;CAGrC,CAAC"}
"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mockConfDeleteRes = exports.mockConfUpdateFunctionRes = exports.mockConfUpdateValueRes = exports.mockConfCreateRes = exports.mockConfGetNonExistentRes = exports.mockConfGetExistingRes = exports.mockConfFailedRes = exports.mockConfContext = exports.UPDATED_PROP_VALUE = exports.EXISTING_PROP_VALUE = exports.DEFAULT_PROP_VALUE = void 0;
exports.mockJiraGetNonExistentRes = exports.mockJiraGetExistingRes = exports.mockJiraSuccessRes = exports.mockConfDeleteRes = exports.mockConfUpdateFunctionRes = exports.mockConfUpdateValueRes = exports.mockConfCreateRes = exports.mockConfGetNonExistentRes = exports.mockConfGetExistingRes = exports.mockFailedRes = exports.mockJiraContext = exports.mockConfContext = exports.UPDATED_PROP_VALUE = exports.EXISTING_PROP_VALUE = exports.DEFAULT_PROP_VALUE = void 0;
_a = [1, 2, 3], exports.DEFAULT_PROP_VALUE = _a[0], exports.EXISTING_PROP_VALUE = _a[1], exports.UPDATED_PROP_VALUE = _a[2];

@@ -16,3 +16,10 @@ exports.mockConfContext = {

};
exports.mockConfFailedRes = {
exports.mockJiraContext = {
extension: {
issue: {
id: 'MOCK_ISSUE_ID'
}
}
};
exports.mockFailedRes = {
ok: false,

@@ -54,1 +61,14 @@ status: 400

};
exports.mockJiraSuccessRes = {
ok: true,
status: 201
};
exports.mockJiraGetExistingRes = {
ok: true,
status: 204,
json: () => ({ key: 'MOCK_PROP_KEY', value: exports.EXISTING_PROP_VALUE })
};
exports.mockJiraGetNonExistentRes = {
ok: false,
status: 404
};

@@ -84,3 +84,3 @@ "use strict";

it('makes 2 retries (by default) when initial attempt fails', async () => {
mockRequest.mockResolvedValue(() => mockPropertyHook_1.mockConfFailedRes);
mockRequest.mockResolvedValue(() => mockPropertyHook_1.mockFailedRes);
await renderTest(renderActions.toUpdate);

@@ -93,3 +93,3 @@ expect(mockRequest).toHaveBeenNthCalledWith(2, 'update');

it('stops retrying when a previous retry succeeds', async () => {
mockRequest.mockResolvedValueOnce(() => mockPropertyHook_1.mockConfFailedRes).mockResolvedValueOnce(() => mockPropertyHook_1.mockConfUpdateValueRes);
mockRequest.mockResolvedValueOnce(() => mockPropertyHook_1.mockFailedRes).mockResolvedValueOnce(() => mockPropertyHook_1.mockConfUpdateValueRes);
await renderTest(renderActions.toUpdate);

@@ -102,3 +102,3 @@ expect(mockRequest).toHaveBeenNthCalledWith(2, 'update');

const retryCount = 5;
mockRequest.mockResolvedValue(() => mockPropertyHook_1.mockConfFailedRes);
mockRequest.mockResolvedValue(() => mockPropertyHook_1.mockFailedRes);
await renderTest(renderActions.toUpdate, retryCount);

@@ -105,0 +105,0 @@ for (let i = 2; i <= retryCount + 2; i++) {

@@ -36,7 +36,9 @@ "use strict";

const apiMethod = bridge_1.requestConfluence;
const withContext = (originalOperation) => async (...args) => {
const context = await bridge_1.view.getContext();
const endpointFactory = (0, exports.confAPIEndpoints)({ entityType, context });
const propertyKey = entityType === 'Content' ? `forge-${context.localId}-${origPropertyKey}` : `forge-${origPropertyKey}`;
return originalOperation({ endpointFactory, propertyKey }, ...args);
const withConfluenceContext = (originalOperation) => {
return (0, apiRequestUtils_1.withContext)({
originalOperation,
apiEndpoints: exports.confAPIEndpoints,
entityType,
origPropertyKey
});
};

@@ -104,4 +106,8 @@ const fetchOriginal = async ({ endpointFactory, propertyKey }) => {

};
return { get: withContext(get), update: withContext(update), delete: withContext(deleteProp) };
return {
get: withConfluenceContext(get),
update: withConfluenceContext(update),
delete: withConfluenceContext(deleteProp)
};
};
exports.confluenceEntity = confluenceEntity;

@@ -52,3 +52,9 @@ import { ConfluenceEntityType, JiraEntityType } from '.';

};
export declare type EndpointContextData = {
originalOperation: Function;
apiEndpoints: (...args: any[]) => EndpointStringFactory;
entityType: ConfluenceEntityType | JiraEntityType;
origPropertyKey: string;
};
export {};
//# sourceMappingURL=entityProps.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"entityProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/types/entityProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AAGzD,oBAAY,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErE,oBAAY,aAAa,CAAC,SAAS,IAAI;IACrC,GAAG,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9B,MAAM,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IACpE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AAEF,oBAAY,eAAe,CAAC,SAAS,IAAI;IACvC,UAAU,EAAE,oBAAoB,GAAG,cAAc,CAAC;IAClD,eAAe,EAA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,MAAM,CAAC;CACzB,CAAC"}

@@ -0,2 +1,8 @@

import { EndpointStringFactory, EntityContext } from '.';
export declare type JiraEntityType = 'Issue';
export declare type JiraPropOperationData = {
endpointFactory: EndpointStringFactory;
propertyKey: string;
context: EntityContext;
};
//# sourceMappingURL=jiraEntityProps.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"jiraEntityProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/types/jiraEntityProps.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc,GAAG,OAAO,CAAC"}
{"version":3,"file":"jiraEntityProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/types/jiraEntityProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAEzD,oBAAY,cAAc,GAAG,OAAO,CAAC;AAErC,oBAAY,qBAAqB,GAAG;IAClC,eAAe,EAAE,qBAAqB,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC"}
import { RequestData, ResponseAssertData } from '../types/entityProps';
import { EndpointContextData } from '../types';
export declare const FETCH_HEADERS: {

@@ -6,2 +7,3 @@ Accept: string;

};
export declare const withContext: ({ originalOperation, apiEndpoints, entityType, origPropertyKey }: EndpointContextData) => (...args: unknown[]) => Promise<any>;
export declare const makeRequest: ({ url, apiMethod, body, method }: RequestData) => Promise<Response>;

@@ -8,0 +10,0 @@ export declare const getJSONData: (response: Response) => Promise<any>;

@@ -1,1 +0,1 @@

{"version":3,"file":"apiRequestUtils.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/apiRequestUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,WAAW,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEzG,eAAO,MAAM,aAAa;;;CAGzB,CAAC;AAEF,eAAO,MAAM,WAAW,qCAA4C,WAAW,sBAQ9E,CAAC;AAEF,eAAO,MAAM,WAAW,aAAoB,QAAQ,iBAOnD,CAAC;AAGF,eAAO,MAAM,wBAAwB,qDAAsD,kBAAkB,SAI5G,CAAC"}
{"version":3,"file":"apiRequestUtils.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/apiRequestUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAoC,WAAW,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,aAAa;;;CAGzB,CAAC;AAGF,eAAO,MAAM,WAAW,qEAC6C,mBAAmB,eACtE,OAAO,EAAE,iBAexB,CAAC;AAEJ,eAAO,MAAM,WAAW,qCAA4C,WAAW,sBAQ9E,CAAC;AAEF,eAAO,MAAM,WAAW,aAAoB,QAAQ,iBAOnD,CAAC;AAGF,eAAO,MAAM,wBAAwB,qDAAsD,kBAAkB,SAI5G,CAAC"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertSuccessfulResponse = exports.getJSONData = exports.makeRequest = exports.FETCH_HEADERS = void 0;
exports.assertSuccessfulResponse = exports.getJSONData = exports.makeRequest = exports.withContext = exports.FETCH_HEADERS = void 0;
const bridge_1 = require("@forge/bridge");
const entityProps_1 = require("../types/entityProps");

@@ -9,2 +10,19 @@ exports.FETCH_HEADERS = {

};
const withContext = ({ originalOperation, apiEndpoints, entityType, origPropertyKey }) => async (...args) => {
const context = await bridge_1.view.getContext();
if (entityType === 'Space' || entityType === 'Content') {
const endpointFactory = apiEndpoints({ entityType, context });
const propertyKey = entityType === 'Content' ? `forge-${context.localId}-${origPropertyKey}` : `forge-${origPropertyKey}`;
return originalOperation({ endpointFactory, propertyKey }, ...args);
}
else if (entityType === 'Issue') {
const endpointFactory = apiEndpoints(context);
const propertyKey = `forge-${origPropertyKey}`;
return originalOperation({ endpointFactory, propertyKey, context }, ...args);
}
else {
throw new Error('Invalid entity type.');
}
};
exports.withContext = withContext;
const makeRequest = async ({ url, apiMethod, body, method }) => {

@@ -11,0 +29,0 @@ const fetchOptions = { headers: exports.FETCH_HEADERS, method, body };

@@ -7,2 +7,3 @@ export { useProductContext } from './hooks/useProductContext';

export { useSpaceProperty } from './hooks/useSpaceProperty';
export { useIssueProperty } from './hooks/useIssueProperty';
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSpaceProperty = exports.useContentProperty = exports.default = exports.useConfig = exports.useProductContext = void 0;
exports.useIssueProperty = exports.useSpaceProperty = exports.useContentProperty = exports.default = exports.useConfig = exports.useProductContext = void 0;
const tslib_1 = require("tslib");

@@ -16,1 +16,3 @@ var useProductContext_1 = require("./hooks/useProductContext");

Object.defineProperty(exports, "useSpaceProperty", { enumerable: true, get: function () { return useSpaceProperty_1.useSpaceProperty; } });
var useIssueProperty_1 = require("./hooks/useIssueProperty");
Object.defineProperty(exports, "useIssueProperty", { enumerable: true, get: function () { return useIssueProperty_1.useIssueProperty; } });
{
"name": "@forge/react",
"version": "9.2.0-next.1",
"version": "9.2.0-next.2",
"description": "Forge React reconciler",

@@ -5,0 +5,0 @@ "author": "Atlassian",

Sorry, the diff of this file is not supported yet