@forge/react 9.1.4 → 9.2.0-next.1
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 +25 -0
- package/out/__test__/testUtils.d.ts.map +1 -1
- package/out/hooks/__test__/confluenceEntity.test.d.ts +2 -0
- package/out/hooks/__test__/confluenceEntity.test.d.ts.map +1 -0
- package/out/hooks/__test__/confluenceEntity.test.js +148 -0
- package/out/hooks/__test__/mockPropertyHook.d.ts +56 -0
- package/out/hooks/__test__/mockPropertyHook.d.ts.map +1 -0
- package/out/hooks/__test__/mockPropertyHook.js +52 -0
- package/out/hooks/__test__/useConfig.test.d.ts +2 -0
- package/out/hooks/__test__/useConfig.test.d.ts.map +1 -0
- package/out/hooks/__test__/useConfig.test.js +49 -0
- package/out/hooks/__test__/useEntityProperty.test.d.ts +2 -0
- package/out/hooks/__test__/useEntityProperty.test.d.ts.map +1 -0
- package/out/hooks/__test__/useEntityProperty.test.js +118 -0
- package/out/hooks/__test__/useProductContext.test.d.ts +2 -0
- package/out/hooks/__test__/useProductContext.test.d.ts.map +1 -0
- package/out/hooks/__test__/useProductContext.test.js +58 -0
- package/out/hooks/confluenceEntity.d.ts +11 -0
- package/out/hooks/confluenceEntity.d.ts.map +1 -0
- package/out/hooks/confluenceEntity.js +105 -0
- package/out/hooks/types/confEntityProps.d.ts +19 -0
- package/out/hooks/types/confEntityProps.d.ts.map +1 -0
- package/out/hooks/types/confEntityProps.js +2 -0
- package/out/hooks/types/entityProps.d.ts +53 -0
- package/out/hooks/types/entityProps.d.ts.map +1 -0
- package/out/hooks/types/entityProps.js +9 -0
- package/out/hooks/types/index.d.ts +4 -0
- package/out/hooks/types/index.d.ts.map +1 -0
- package/out/hooks/types/index.js +6 -0
- package/out/hooks/types/jiraEntityProps.d.ts +2 -0
- package/out/hooks/types/jiraEntityProps.d.ts.map +1 -0
- package/out/hooks/types/jiraEntityProps.js +2 -0
- package/out/hooks/useConfig.d.ts +2 -0
- package/out/hooks/useConfig.d.ts.map +1 -0
- package/out/hooks/useConfig.js +9 -0
- package/out/hooks/useContentProperty.d.ts +2 -0
- package/out/hooks/useContentProperty.d.ts.map +1 -0
- package/out/hooks/useContentProperty.js +15 -0
- package/out/hooks/useEntityProperty.d.ts +3 -0
- package/out/hooks/useEntityProperty.d.ts.map +1 -0
- package/out/hooks/useEntityProperty.js +38 -0
- package/out/hooks/useProductContext.d.ts +3 -0
- package/out/hooks/useProductContext.d.ts.map +1 -0
- package/out/hooks/useProductContext.js +18 -0
- package/out/hooks/useSpaceProperty.d.ts +2 -0
- package/out/hooks/useSpaceProperty.d.ts.map +1 -0
- package/out/hooks/useSpaceProperty.js +15 -0
- package/out/hooks/utils/apiRequestUtils.d.ts +9 -0
- package/out/hooks/utils/apiRequestUtils.d.ts.map +1 -0
- package/out/hooks/utils/apiRequestUtils.js +34 -0
- package/out/hooks/utils/valueUtils.d.ts +2 -0
- package/out/hooks/utils/valueUtils.d.ts.map +1 -0
- package/out/hooks/utils/valueUtils.js +8 -0
- package/out/index.d.ts +4 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +9 -1
- package/out/reconciler.d.ts +0 -1
- package/out/reconciler.d.ts.map +1 -1
- package/package.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.confluenceEntity = exports.confAPIEndpoints = void 0;
|
|
4
|
+
const bridge_1 = require("@forge/bridge");
|
|
5
|
+
const apiRequestUtils_1 = require("./utils/apiRequestUtils");
|
|
6
|
+
const valueUtils_1 = require("./utils/valueUtils");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
const confAPIEndpoints = ({ entityType, context }) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
let entityId, urlEntity;
|
|
11
|
+
switch (entityType) {
|
|
12
|
+
case 'Space':
|
|
13
|
+
entityId = (_a = context.extension.space) === null || _a === void 0 ? void 0 : _a.id;
|
|
14
|
+
urlEntity = 'spaces';
|
|
15
|
+
break;
|
|
16
|
+
case 'Content':
|
|
17
|
+
entityId = (_b = context.extension.content) === null || _b === void 0 ? void 0 : _b.id;
|
|
18
|
+
urlEntity = 'pages';
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
throw new Error('Invalid entity type.');
|
|
22
|
+
}
|
|
23
|
+
if (!entityId) {
|
|
24
|
+
throw new Error(`${entityType} properties not available for this app.`);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
create: () => `/wiki/api/v2/${urlEntity}/${entityId}/properties`,
|
|
28
|
+
fetch: (propertyKey) => `/wiki/api/v2/${urlEntity}/${entityId}/properties?key=${propertyKey}`,
|
|
29
|
+
update: (propertyId) => `/wiki/api/v2/${urlEntity}/${entityId}/properties/${propertyId}`,
|
|
30
|
+
delete: (propertyId) => `/wiki/api/v2/${urlEntity}/${entityId}/properties/${propertyId}`
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.confAPIEndpoints = confAPIEndpoints;
|
|
34
|
+
const confluenceEntity = ({ entityType, origPropertyKey, initValue }) => {
|
|
35
|
+
const apiMethod = bridge_1.requestConfluence;
|
|
36
|
+
const withContext = (originalOperation) => async (...args) => {
|
|
37
|
+
const context = await bridge_1.view.getContext();
|
|
38
|
+
const endpointFactory = (0, exports.confAPIEndpoints)({ entityType, context });
|
|
39
|
+
const propertyKey = entityType === 'Content' ? `forge-${context.localId}-${origPropertyKey}` : `forge-${origPropertyKey}`;
|
|
40
|
+
return originalOperation({ endpointFactory, propertyKey }, ...args);
|
|
41
|
+
};
|
|
42
|
+
const fetchOriginal = async ({ endpointFactory, propertyKey }) => {
|
|
43
|
+
const url = endpointFactory.fetch(propertyKey);
|
|
44
|
+
const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'GET' });
|
|
45
|
+
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'fetch', response });
|
|
46
|
+
const existingData = await (0, apiRequestUtils_1.getJSONData)(response);
|
|
47
|
+
return existingData.results[0];
|
|
48
|
+
};
|
|
49
|
+
const deleteProp = async ({ endpointFactory, propertyKey }) => {
|
|
50
|
+
const originalProp = await fetchOriginal({ endpointFactory, propertyKey });
|
|
51
|
+
if (!originalProp) {
|
|
52
|
+
throw new types_1.EntityPropertyRequestFailedError({
|
|
53
|
+
entityType,
|
|
54
|
+
propertyKey,
|
|
55
|
+
operation: 'delete',
|
|
56
|
+
status: 404
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const propertyId = originalProp.id;
|
|
60
|
+
const url = endpointFactory.delete(propertyId);
|
|
61
|
+
const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'DELETE' });
|
|
62
|
+
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'delete', response });
|
|
63
|
+
};
|
|
64
|
+
const get = async ({ endpointFactory, propertyKey }) => {
|
|
65
|
+
const existingProp = await fetchOriginal({ endpointFactory, propertyKey });
|
|
66
|
+
if (existingProp) {
|
|
67
|
+
return existingProp.value;
|
|
68
|
+
}
|
|
69
|
+
const resolvedInitVal = await (0, valueUtils_1.resolveValue)(initValue);
|
|
70
|
+
const url = endpointFactory.create();
|
|
71
|
+
const body = JSON.stringify({ key: propertyKey, value: resolvedInitVal });
|
|
72
|
+
const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'POST', body });
|
|
73
|
+
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'create', response });
|
|
74
|
+
return (await (0, apiRequestUtils_1.getJSONData)(response)).value;
|
|
75
|
+
};
|
|
76
|
+
const update = async ({ endpointFactory, propertyKey }, valueUpdate) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const originalProp = await fetchOriginal({ endpointFactory, propertyKey });
|
|
79
|
+
if (!originalProp) {
|
|
80
|
+
throw new types_1.EntityPropertyRequestFailedError({
|
|
81
|
+
entityType,
|
|
82
|
+
propertyKey,
|
|
83
|
+
operation: 'update',
|
|
84
|
+
status: 404
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const newValue = valueUpdate instanceof Function ? valueUpdate(originalProp.value) : valueUpdate;
|
|
88
|
+
const propertyId = originalProp.id;
|
|
89
|
+
const origVersion = (_a = originalProp === null || originalProp === void 0 ? void 0 : originalProp.version) === null || _a === void 0 ? void 0 : _a.number;
|
|
90
|
+
const url = endpointFactory.update(propertyId);
|
|
91
|
+
const body = JSON.stringify({
|
|
92
|
+
key: propertyKey,
|
|
93
|
+
value: newValue,
|
|
94
|
+
version: {
|
|
95
|
+
number: origVersion + 1,
|
|
96
|
+
message: `Update through UI Kit 2 use${entityType}Properties hook.`
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'PUT', body });
|
|
100
|
+
(0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'update', response });
|
|
101
|
+
return (await (0, apiRequestUtils_1.getJSONData)(response)).value;
|
|
102
|
+
};
|
|
103
|
+
return { get: withContext(get), update: withContext(update), delete: withContext(deleteProp) };
|
|
104
|
+
};
|
|
105
|
+
exports.confluenceEntity = confluenceEntity;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EndpointStringFactory, EntityContext, Property } from './entityProps';
|
|
2
|
+
export declare type ConfluenceEntityType = 'Space' | 'Content';
|
|
3
|
+
export declare type ConfEndpointInitializer = {
|
|
4
|
+
entityType: ConfluenceEntityType;
|
|
5
|
+
context: EntityContext;
|
|
6
|
+
};
|
|
7
|
+
export declare type ConfPropOperationData = {
|
|
8
|
+
endpointFactory: EndpointStringFactory;
|
|
9
|
+
propertyKey: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type ConfProperty<PropValue> = Property<PropValue> & {
|
|
12
|
+
id: string;
|
|
13
|
+
version: {
|
|
14
|
+
number: number;
|
|
15
|
+
message: string;
|
|
16
|
+
[versionKey: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=confEntityProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confEntityProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/types/confEntityProps.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/E,oBAAY,oBAAoB,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvD,oBAAY,uBAAuB,GAAG;IACpC,UAAU,EAAE,oBAAoB,CAAC;IACjC,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,oBAAY,qBAAqB,GAAG;IAClC,eAAe,EAAE,qBAAqB,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,oBAAY,YAAY,CAAC,SAAS,IAAI,QAAQ,CAAC,SAAS,CAAC,GAAG;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;KAC/B,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ConfluenceEntityType, JiraEntityType } from '.';
|
|
2
|
+
export declare type PropOperation = 'fetch' | 'create' | 'update' | 'delete';
|
|
3
|
+
export declare type EntityManager<PropValue> = {
|
|
4
|
+
get: () => Promise<PropValue>;
|
|
5
|
+
update: (valueUpdate: ValueUpdate<PropValue>) => Promise<PropValue>;
|
|
6
|
+
delete: () => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare type ManagePropsData<PropValue> = {
|
|
9
|
+
entityType: ConfluenceEntityType | JiraEntityType;
|
|
10
|
+
origPropertyKey: string;
|
|
11
|
+
initValue: PropValue;
|
|
12
|
+
};
|
|
13
|
+
export declare type ResponseAssertData = {
|
|
14
|
+
entityType: string;
|
|
15
|
+
propertyKey: string;
|
|
16
|
+
operation: PropOperation;
|
|
17
|
+
response: Response;
|
|
18
|
+
};
|
|
19
|
+
declare type EntityErrorData = {
|
|
20
|
+
entityType: string;
|
|
21
|
+
propertyKey: string;
|
|
22
|
+
operation: PropOperation;
|
|
23
|
+
status: number;
|
|
24
|
+
};
|
|
25
|
+
export declare class EntityPropertyRequestFailedError extends Error {
|
|
26
|
+
constructor({ entityType, propertyKey, operation, status }: EntityErrorData);
|
|
27
|
+
}
|
|
28
|
+
export declare type EntityContext = {
|
|
29
|
+
extension: {
|
|
30
|
+
[entityType: string]: {
|
|
31
|
+
id: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare type Property<PropValue> = {
|
|
36
|
+
key: string;
|
|
37
|
+
value: PropValue;
|
|
38
|
+
};
|
|
39
|
+
export declare type EndpointStringFactory = {
|
|
40
|
+
create: (...propIdentifier: string[]) => string;
|
|
41
|
+
fetch: (...propIdentifier: string[]) => string;
|
|
42
|
+
update: (...propIdentifier: string[]) => string;
|
|
43
|
+
delete: (...propIdentifier: string[]) => string;
|
|
44
|
+
};
|
|
45
|
+
export declare type ValueUpdate<PropValue> = PropValue | ((origValue: unknown) => PropValue);
|
|
46
|
+
export declare type RequestData = {
|
|
47
|
+
url: string;
|
|
48
|
+
apiMethod: (restPath: string, fetchOptions?: RequestInit) => Promise<Response>;
|
|
49
|
+
body?: string;
|
|
50
|
+
method: 'GET' | 'POST' | 'DELETE' | 'PUT';
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=entityProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/types/entityProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EA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,GAAG;IAClC,MAAM,EAAE,CAAC,GAAG,cAAc,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IAChD,KAAK,EAAE,CAAC,GAAG,cAAc,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IAC/C,MAAM,EAAE,CAAC,GAAG,cAAc,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IAChD,MAAM,EAAE,CAAC,GAAG,cAAc,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CACjD,CAAC;AAEF,oBAAY,WAAW,CAAC,SAAS,IAAI,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC;AAErF,oBAAY,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;CAC3C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityPropertyRequestFailedError = void 0;
|
|
4
|
+
class EntityPropertyRequestFailedError extends Error {
|
|
5
|
+
constructor({ entityType, propertyKey, operation, status }) {
|
|
6
|
+
super(`The request to ${operation} the ${entityType.toLowerCase()} property (${propertyKey}) failed with status (${status}).`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.EntityPropertyRequestFailedError = EntityPropertyRequestFailedError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./entityProps"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./confEntityProps"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./jiraEntityProps"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jiraEntityProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/types/jiraEntityProps.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConfig.d.ts","sourceRoot":"","sources":["../../src/hooks/useConfig.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,WAGrB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useConfig = void 0;
|
|
4
|
+
const useProductContext_1 = require("./useProductContext");
|
|
5
|
+
const useConfig = () => {
|
|
6
|
+
const context = (0, useProductContext_1.useProductContext)();
|
|
7
|
+
return context === null || context === void 0 ? void 0 : context.extension.config;
|
|
8
|
+
};
|
|
9
|
+
exports.useConfig = useConfig;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const useContentProperty: <PropValue>(propertyKey: string, initValue: PropValue) => readonly [PropValue | undefined, (valueUpdate: import("./types/entityProps").ValueUpdate<PropValue>, retryCount?: number) => Promise<void>, () => Promise<void>];
|
|
2
|
+
//# sourceMappingURL=useContentProperty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContentProperty.d.ts","sourceRoot":"","sources":["../../src/hooks/useContentProperty.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,kBAAkB,2BAA4B,MAAM,2LAWhE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useContentProperty = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const confluenceEntity_1 = require("./confluenceEntity");
|
|
6
|
+
const useEntityProperty_1 = require("./useEntityProperty");
|
|
7
|
+
const useContentProperty = (propertyKey, initValue) => {
|
|
8
|
+
const entityManager = (0, react_1.useMemo)(() => (0, confluenceEntity_1.confluenceEntity)({
|
|
9
|
+
entityType: 'Content',
|
|
10
|
+
origPropertyKey: propertyKey,
|
|
11
|
+
initValue
|
|
12
|
+
}), []);
|
|
13
|
+
return (0, useEntityProperty_1.useEntityProperty)(entityManager);
|
|
14
|
+
};
|
|
15
|
+
exports.useContentProperty = useContentProperty;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ValueUpdate, EntityManager } from './types';
|
|
2
|
+
export declare const useEntityProperty: <PropValue>(entityManager: EntityManager<PropValue>) => readonly [PropValue | undefined, (valueUpdate: ValueUpdate<PropValue>, retryCount?: number) => Promise<void>, () => Promise<void>];
|
|
3
|
+
//# sourceMappingURL=useEntityProperty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEntityProperty.d.ts","sourceRoot":"","sources":["../../src/hooks/useEntityProperty.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGrD,eAAO,MAAM,iBAAiB,4LAwC7B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useEntityProperty = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useEntityProperty = (entityManager) => {
|
|
6
|
+
const [propValue, setPropValue] = (0, react_1.useState)();
|
|
7
|
+
(0, react_1.useEffect)(() => {
|
|
8
|
+
entityManager
|
|
9
|
+
.get()
|
|
10
|
+
.then((val) => setPropValue(val))
|
|
11
|
+
.catch((err) => {
|
|
12
|
+
throw err;
|
|
13
|
+
});
|
|
14
|
+
}, []);
|
|
15
|
+
const updateProp = (0, react_1.useCallback)(async (valueUpdate, retryCount = 2) => {
|
|
16
|
+
let success = false;
|
|
17
|
+
let tryCounts = 0;
|
|
18
|
+
const attempt = async () => setPropValue(await entityManager.update(valueUpdate));
|
|
19
|
+
while (!success && tryCounts <= retryCount) {
|
|
20
|
+
try {
|
|
21
|
+
tryCounts++;
|
|
22
|
+
await attempt();
|
|
23
|
+
success = true;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
if (tryCounts > retryCount) {
|
|
27
|
+
console.error(err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}, [entityManager]);
|
|
32
|
+
const deleteProp = (0, react_1.useCallback)(async () => {
|
|
33
|
+
await entityManager.delete();
|
|
34
|
+
setPropValue(undefined);
|
|
35
|
+
}, [entityManager]);
|
|
36
|
+
return [propValue, updateProp, deleteProp];
|
|
37
|
+
};
|
|
38
|
+
exports.useEntityProperty = useEntityProperty;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProductContext.d.ts","sourceRoot":"","sources":["../../src/hooks/useProductContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,eAAO,MAAM,iBAAiB,+BAa7B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useProductContext = void 0;
|
|
4
|
+
const bridge_1 = require("@forge/bridge");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const useProductContext = () => {
|
|
7
|
+
const [productContext, setProductContext] = (0, react_1.useState)();
|
|
8
|
+
(0, react_1.useEffect)(() => {
|
|
9
|
+
bridge_1.view
|
|
10
|
+
.getContext()
|
|
11
|
+
.then(setProductContext)
|
|
12
|
+
.catch((err) => {
|
|
13
|
+
throw err;
|
|
14
|
+
});
|
|
15
|
+
}, []);
|
|
16
|
+
return productContext;
|
|
17
|
+
};
|
|
18
|
+
exports.useProductContext = useProductContext;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const useSpaceProperty: <PropValue>(propertyKey: string, initValue: PropValue) => readonly [PropValue | undefined, (valueUpdate: import("./types/entityProps").ValueUpdate<PropValue>, retryCount?: number) => Promise<void>, () => Promise<void>];
|
|
2
|
+
//# sourceMappingURL=useSpaceProperty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpaceProperty.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpaceProperty.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,gBAAgB,2BAA4B,MAAM,2LAW9D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSpaceProperty = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const confluenceEntity_1 = require("./confluenceEntity");
|
|
6
|
+
const useEntityProperty_1 = require("./useEntityProperty");
|
|
7
|
+
const useSpaceProperty = (propertyKey, initValue) => {
|
|
8
|
+
const entityManager = (0, react_1.useMemo)(() => (0, confluenceEntity_1.confluenceEntity)({
|
|
9
|
+
entityType: 'Space',
|
|
10
|
+
origPropertyKey: propertyKey,
|
|
11
|
+
initValue
|
|
12
|
+
}), []);
|
|
13
|
+
return (0, useEntityProperty_1.useEntityProperty)(entityManager);
|
|
14
|
+
};
|
|
15
|
+
exports.useSpaceProperty = useSpaceProperty;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RequestData, ResponseAssertData } from '../types/entityProps';
|
|
2
|
+
export declare const FETCH_HEADERS: {
|
|
3
|
+
Accept: string;
|
|
4
|
+
'Content-Type': string;
|
|
5
|
+
};
|
|
6
|
+
export declare const makeRequest: ({ url, apiMethod, body, method }: RequestData) => Promise<Response>;
|
|
7
|
+
export declare const getJSONData: (response: Response) => Promise<any>;
|
|
8
|
+
export declare const assertSuccessfulResponse: ({ entityType, propertyKey, operation, response }: ResponseAssertData) => void;
|
|
9
|
+
//# sourceMappingURL=apiRequestUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertSuccessfulResponse = exports.getJSONData = exports.makeRequest = exports.FETCH_HEADERS = void 0;
|
|
4
|
+
const entityProps_1 = require("../types/entityProps");
|
|
5
|
+
exports.FETCH_HEADERS = {
|
|
6
|
+
Accept: 'application/json',
|
|
7
|
+
'Content-Type': 'application/json'
|
|
8
|
+
};
|
|
9
|
+
const makeRequest = async ({ url, apiMethod, body, method }) => {
|
|
10
|
+
const fetchOptions = { headers: exports.FETCH_HEADERS, method, body };
|
|
11
|
+
try {
|
|
12
|
+
return await apiMethod(url, fetchOptions);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new Error('An unknown network error occurred.');
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.makeRequest = makeRequest;
|
|
19
|
+
const getJSONData = async (response) => {
|
|
20
|
+
try {
|
|
21
|
+
const data = await response.json();
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
throw new Error('An invalid response is received from the server');
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.getJSONData = getJSONData;
|
|
29
|
+
const assertSuccessfulResponse = ({ entityType, propertyKey, operation, response }) => {
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new entityProps_1.EntityPropertyRequestFailedError({ entityType, propertyKey, operation, status: response.status });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.assertSuccessfulResponse = assertSuccessfulResponse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valueUtils.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/valueUtils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,qEAGxB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveValue = void 0;
|
|
4
|
+
const resolveValue = async (defaultValue) => {
|
|
5
|
+
const value = defaultValue instanceof Function ? defaultValue() : defaultValue;
|
|
6
|
+
return await value;
|
|
7
|
+
};
|
|
8
|
+
exports.resolveValue = resolveValue;
|
package/out/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { useProductContext } from './hooks/useProductContext';
|
|
2
|
+
export { useConfig } from './hooks/useConfig';
|
|
1
3
|
export { ForgeReconciler as default } from './reconciler';
|
|
2
4
|
export * from './components';
|
|
5
|
+
export { useContentProperty } from './hooks/useContentProperty';
|
|
6
|
+
export { useSpaceProperty } from './hooks/useSpaceProperty';
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,cAAc,cAAc,CAAC"}
|
|
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"}
|
package/out/index.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = void 0;
|
|
3
|
+
exports.useSpaceProperty = exports.useContentProperty = exports.default = exports.useConfig = exports.useProductContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
var useProductContext_1 = require("./hooks/useProductContext");
|
|
6
|
+
Object.defineProperty(exports, "useProductContext", { enumerable: true, get: function () { return useProductContext_1.useProductContext; } });
|
|
7
|
+
var useConfig_1 = require("./hooks/useConfig");
|
|
8
|
+
Object.defineProperty(exports, "useConfig", { enumerable: true, get: function () { return useConfig_1.useConfig; } });
|
|
5
9
|
var reconciler_1 = require("./reconciler");
|
|
6
10
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return reconciler_1.ForgeReconciler; } });
|
|
7
11
|
tslib_1.__exportStar(require("./components"), exports);
|
|
12
|
+
var useContentProperty_1 = require("./hooks/useContentProperty");
|
|
13
|
+
Object.defineProperty(exports, "useContentProperty", { enumerable: true, get: function () { return useContentProperty_1.useContentProperty; } });
|
|
14
|
+
var useSpaceProperty_1 = require("./hooks/useSpaceProperty");
|
|
15
|
+
Object.defineProperty(exports, "useSpaceProperty", { enumerable: true, get: function () { return useSpaceProperty_1.useSpaceProperty; } });
|
package/out/reconciler.d.ts
CHANGED
package/out/reconciler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconciler.d.ts","sourceRoot":"","sources":["../src/reconciler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reconciler.d.ts","sourceRoot":"","sources":["../src/reconciler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAmB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI1D,aAAK,WAAW,GAAG,MAAM,CAAC;AAC1B,aAAK,YAAY,GAAG,aAAa,CAAC;AAElC,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,oBAAY,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,KAAK,IAAI,CAAC;AAC7E,eAAO,MAAM,UAAU,EAAE,UAIxB,CAAC;AAEF,aAAK,aAAa,GAAG,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,KAAK,QAAQ,CAAC;AAMrF,qBAAa,qBAAqB;IAChC,OAAO,CAAC,KAAK,CAAK;IAElB,OAAO,CAAC,QAAQ,CAAQ;IAExB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAwB;IAE/C,OAAO;WAUO,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,qBAAqB;IAO5D,SAAS,IAAI,IA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{
|
|
2
2
|
"name": "@forge/react",
|
|
3
|
-
"version": "9.1
|
|
3
|
+
"version": "9.2.0-next.1",
|
|
4
4
|
"description": "Forge React reconciler",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"pack": "./build/bundle-types.sh"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
+
"@forge/bridge": "3.2.0",
|
|
16
17
|
"@forge/ui": "1.10.4"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|