npm package diff

Package: @forge/react

Versions: 10.10.2-next.0-experimental-d6acbbd - 10.10.3-next.0

Modified: package/out/hooks/confluenceEntity.js

Index: package/out/hooks/confluenceEntity.js
===================================================================
--- package/out/hooks/confluenceEntity.js
+++ package/out/hooks/confluenceEntity.js
@@ -68,32 +68,28 @@
         const url = endpointFactory.delete(propertyId);
         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 }) => {
+    const getProp = async ({ endpointFactory, propertyKey }) => {
         const existingProp = await fetchOriginal({ endpointFactory, propertyKey });
         if (existingProp) {
-            return existingProp.value;
+            return existingProp;
         }
         // if property doesn't exist, create it
         const resolvedInitVal = await (0, valueUtils_1.resolveValue)(initValue);
         const url = endpointFactory.create();
         const body = JSON.stringify({ key: propertyKey, value: resolvedInitVal });
         const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'POST', body });
         (0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'create', response });
-        return (await (0, apiRequestUtils_1.getJSONData)(response)).value;
+        return await (0, apiRequestUtils_1.getJSONData)(response);
     };
+    const get = async ({ endpointFactory, propertyKey }) => {
+        const propData = await getProp({ endpointFactory, propertyKey });
+        return propData.value;
+    };
     const update = async ({ endpointFactory, propertyKey }, valueUpdate) => {
         // fetch original prop first to update based on its value + version + id
-        const originalProp = await fetchOriginal({ endpointFactory, propertyKey });
-        if (!originalProp) {
-            throw new types_1.EntityPropertyRequestFailedError({
-                entityType,
-                propertyKey,
-                operation: 'update',
-                status: 404
-            });
-        }
+        const originalProp = await getProp({ endpointFactory, propertyKey });
         const newValue = valueUpdate instanceof Function ? valueUpdate(originalProp.value) : valueUpdate;
         const propertyId = originalProp.id;
         const origVersion = originalProp?.version?.number;
         const url = endpointFactory.update(propertyId);

Modified: package/out/hooks/__test__/confluenceEntity.test.js

Index: package/out/hooks/__test__/confluenceEntity.test.js
===================================================================
--- package/out/hooks/__test__/confluenceEntity.test.js
+++ package/out/hooks/__test__/confluenceEntity.test.js
@@ -125,8 +125,38 @@
             mockRequestConf.mockReset();
             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-MOCK_LOCAL_ID-MOCK_PROP_KEY) failed with status (400).`);
         });
+        describe('if the property does not exist, it should create it', () => {
+            beforeEach(() => {
+                mockRequestConf.mockReset();
+                mockRequestConf
+                    .mockResolvedValueOnce(mockPropertyHook_1.mockConfGetNonExistentRes)
+                    .mockResolvedValueOnce(mockPropertyHook_1.mockConfCreateRes)
+                    .mockResolvedValueOnce(mockPropertyHook_1.mockConfUpdateValueRes);
+            });
+            it('should make a POST request to the API with the right URL and body', async () => {
+                const contentGetUrl = contentEndpoints.fetch('forge-MOCK_LOCAL_ID-MOCK_PROP_KEY');
+                const contentGetBody = expect.objectContaining({ method: 'GET' });
+                const contentPutUrl = contentEndpoints.update('MOCK_PROP_ID');
+                const contentPostUrl = contentEndpoints.create();
+                const contentPostBody = expect.objectContaining({
+                    method: 'POST',
+                    body: JSON.stringify({ key: 'forge-MOCK_LOCAL_ID-MOCK_PROP_KEY', value: mockPropertyHook_1.DEFAULT_PROP_VALUE })
+                });
+                // both value & version props need to be present in body string
+                const valueUpdateStr = `"value":${mockPropertyHook_1.UPDATED_PROP_VALUE}`;
+                const contentPutBody = (updateStr) => expect.objectContaining({
+                    body: expect.stringContaining(updateStr)
+                });
+                const valUpdate = await contentEntity.update(mockPropertyHook_1.UPDATED_PROP_VALUE);
+                expect(valUpdate).toEqual(mockPropertyHook_1.UPDATED_PROP_VALUE);
+                expect(mockRequestConf).toHaveBeenCalledTimes(3);
+                expect(mockRequestConf).toHaveBeenNthCalledWith(1, contentGetUrl, contentGetBody);
+                expect(mockRequestConf).toHaveBeenNthCalledWith(2, contentPostUrl, contentPostBody);
+                expect(mockRequestConf).toHaveBeenNthCalledWith(3, contentPutUrl, contentPutBody(valueUpdateStr));
+            });
+        });
     });
     describe('when running its delete() output function', () => {
         beforeEach(() => {
             mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockConfDeleteRes);

Modified: package/package.json

Index: package/package.json
===================================================================
--- package/package.json
+++ package/package.json
@@ -1,7 +1,7 @@
 {
   "name": "@forge/react",
-  "version": "10.10.2-next.0-experimental-d6acbbd",
+  "version": "10.10.3-next.0",
   "description": "Forge React reconciler",
   "author": "Atlassian",
   "license": "UNLICENSED",
   "main": "out/index.js",
@@ -19,9 +19,9 @@
   "dependencies": {
     "@atlaskit/adf-schema": "^46.0.0",
     "@atlaskit/adf-utils": "^19.12.0",
     "@atlaskit/forge-react-types": "^0.34.0",
-    "@forge/bridge": "^4.3.0-next.0-experimental-d6acbbd",
+    "@forge/bridge": "^4.3.0",
     "@forge/i18n": "0.0.2",
     "@types/react-reconciler": "^0.28.8",
     "lodash": "^4.17.21",
     "react": "^18.2.0",

Modified: package/out/hooks/confluenceEntity.d.ts.map

Index: package/out/hooks/confluenceEntity.d.ts.map
===================================================================
--- package/out/hooks/confluenceEntity.d.ts.map
+++ package/out/hooks/confluenceEntity.d.ts.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"confluenceEntity.d.ts","sourceRoot":"","sources":["../../src/hooks/confluenceEntity.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,uBAAuB,EAEvB,eAAe,EACf,oBAAoB,EACpB,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,4BAA6B,uBAAuB;;yBAqBxD,MAAM;yBACN,MAAM;yBACN,MAAM;CAE9B,CAAC;AAEF,eAAO,MAAM,gBAAgB;gBAIiB,oBAAoB;8BAqGjE,CAAC"}
\ No newline at end of file
+{"version":3,"file":"confluenceEntity.d.ts","sourceRoot":"","sources":["../../src/hooks/confluenceEntity.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,uBAAuB,EAEvB,eAAe,EACf,oBAAoB,EACpB,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,4BAA6B,uBAAuB;;yBAqBxD,MAAM;yBACN,MAAM;yBACN,MAAM;CAE9B,CAAC;AAEF,eAAO,MAAM,gBAAgB;gBAIiB,oBAAoB;8BAkGjE,CAAC"}
\ No newline at end of file

Modified: package/CHANGELOG.md

Index: package/CHANGELOG.md
===================================================================
--- package/CHANGELOG.md
+++ package/CHANGELOG.md
@@ -1,13 +1,18 @@
 # @forge/react
 
-## 10.10.2-next.0-experimental-d6acbbd
+## 10.10.3-next.0
 
 ### Patch Changes
 
-- Updated dependencies [d516a64]
+- ea9fa2a: Fix update method in useSpaceProperty to ensure it works as expect when value does not exist
+
+## 10.10.2
+
+### Patch Changes
+
 - Updated dependencies [e771326]
-  - @forge/[email protected]
+  - @forge/[email protected]
 
 ## 10.10.2-next.0
 
 ### Patch Changes

Modified: package/tsconfig.tsbuildinfo

Large diffs are not rendered by default.