@salesforce/lds-drafts 1.303.0 → 1.304.0
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/dist/ldsDrafts.js
CHANGED
|
@@ -762,6 +762,31 @@ class DurableDraftQueue {
|
|
|
762
762
|
await this.startQueue();
|
|
763
763
|
}
|
|
764
764
|
}
|
|
765
|
+
async updateDraftAction(action) {
|
|
766
|
+
// stop queue manually
|
|
767
|
+
this.stopQueueManually();
|
|
768
|
+
const actionStatus = await this.statusOfAction(action.id);
|
|
769
|
+
if (actionStatus === DraftActionStatus.Uploading) {
|
|
770
|
+
return Promise.reject('cannot update an uploading action');
|
|
771
|
+
}
|
|
772
|
+
// save the action into the draft store
|
|
773
|
+
await this.draftStore.writeAction(action);
|
|
774
|
+
// make the handler replay these drafts on the record
|
|
775
|
+
const handler = this.getHandler(action.handler);
|
|
776
|
+
const queue = await this.getQueueActions();
|
|
777
|
+
await handler.handleActionEnqueued(action, queue);
|
|
778
|
+
// start queue safely
|
|
779
|
+
return this.startQueueSafe();
|
|
780
|
+
}
|
|
781
|
+
async statusOfAction(actionId) {
|
|
782
|
+
const queue = await this.getQueueActions();
|
|
783
|
+
const actions = queue.filter((action) => action.id === actionId);
|
|
784
|
+
if (actions.length === 0) {
|
|
785
|
+
return Promise.reject('cannot update non-existent action');
|
|
786
|
+
}
|
|
787
|
+
const action = actions[0];
|
|
788
|
+
return action.status;
|
|
789
|
+
}
|
|
765
790
|
replaceAction(targetActionId, sourceActionId) {
|
|
766
791
|
return this.replaceOrMergeActions(targetActionId, sourceActionId, false);
|
|
767
792
|
}
|
|
@@ -1765,6 +1790,60 @@ class DraftManager {
|
|
|
1765
1790
|
};
|
|
1766
1791
|
});
|
|
1767
1792
|
}
|
|
1793
|
+
async mergePerformQuickAction(actionId, fields) {
|
|
1794
|
+
if (!this.isValidFieldMap(fields)) {
|
|
1795
|
+
return Promise.reject('fields is not valid');
|
|
1796
|
+
}
|
|
1797
|
+
const queue = await this.draftQueue.getQueueActions();
|
|
1798
|
+
const actions = queue.filter((action) => action.id === actionId);
|
|
1799
|
+
if (actions.length === 0) {
|
|
1800
|
+
return Promise.reject('cannot edit non-existent action');
|
|
1801
|
+
}
|
|
1802
|
+
const action = actions[0];
|
|
1803
|
+
if (!this.isPerformQuickActionDraft(action, 'post')) {
|
|
1804
|
+
return Promise.reject('cannot edit incompatible action type or uploading actions');
|
|
1805
|
+
}
|
|
1806
|
+
action.data.body.fields = { ...action.data.body.fields, ...fields };
|
|
1807
|
+
await this.draftQueue.updateDraftAction(action);
|
|
1808
|
+
return this.buildDraftQueueItem(action);
|
|
1809
|
+
}
|
|
1810
|
+
isValidFieldMap(fields) {
|
|
1811
|
+
const keys$1 = keys(fields);
|
|
1812
|
+
const validTypes = ['string', 'number', 'null', 'boolean'];
|
|
1813
|
+
for (let i = 0; i < keys$1.length; i++) {
|
|
1814
|
+
const key = keys$1[i];
|
|
1815
|
+
const value = fields[key];
|
|
1816
|
+
if (!validTypes.includes(typeof value)) {
|
|
1817
|
+
return false;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
return true;
|
|
1821
|
+
}
|
|
1822
|
+
isPerformQuickActionDraft(action, method) {
|
|
1823
|
+
const data = action.data;
|
|
1824
|
+
const isPerformQuickAction = data.basePath.startsWith('/ui-api/actions/perform-quick-action/');
|
|
1825
|
+
const methodMatches = data.method === method;
|
|
1826
|
+
const notUploading = action.status !== DraftActionStatus.Uploading;
|
|
1827
|
+
return isPerformQuickAction && methodMatches && notUploading;
|
|
1828
|
+
}
|
|
1829
|
+
async mergePerformUpdateRecordQuickAction(actionId, fields) {
|
|
1830
|
+
if (!this.isValidFieldMap(fields)) {
|
|
1831
|
+
return Promise.reject('fields is not valid');
|
|
1832
|
+
}
|
|
1833
|
+
const queue = await this.draftQueue.getQueueActions();
|
|
1834
|
+
const actions = queue.filter((action) => action.id === actionId);
|
|
1835
|
+
if (actions.length === 0) {
|
|
1836
|
+
return Promise.reject('cannot edit non-existent action');
|
|
1837
|
+
}
|
|
1838
|
+
const action = actions[0];
|
|
1839
|
+
if (!this.isPerformQuickActionDraft(action, 'patch')) {
|
|
1840
|
+
return Promise.reject('cannot edit incompatible action type or uploading actions');
|
|
1841
|
+
}
|
|
1842
|
+
const data = action.data;
|
|
1843
|
+
data.body.fields = { ...data.body.fields, ...fields };
|
|
1844
|
+
await this.draftQueue.updateDraftAction(action);
|
|
1845
|
+
return this.buildDraftQueueItem(action);
|
|
1846
|
+
}
|
|
1768
1847
|
buildDraftQueueItem(action) {
|
|
1769
1848
|
const operationType = getOperationTypeFrom(action);
|
|
1770
1849
|
const { id, status, timestamp, targetId, metadata } = action;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { CustomActionResult } from './actionHandlers/CustomActionHandler';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DraftQueue, DraftAction, DraftActionMetadata, PendingDraftAction } from './DraftQueue';
|
|
3
|
+
import { DraftActionStatus } from './DraftQueue';
|
|
3
4
|
import { DraftQueueState } from './DraftQueue';
|
|
5
|
+
import type { ResourceRequest } from '@luvio/engine';
|
|
4
6
|
/**
|
|
5
7
|
* Representation of the current state of the draft queue.
|
|
6
8
|
* Includes the overall state as well as a list of draft
|
|
@@ -14,6 +16,9 @@ export type DraftQueueItemMetadata = {
|
|
|
14
16
|
[key: string]: string;
|
|
15
17
|
};
|
|
16
18
|
export type DraftManagerCustomActionExecutor = (item: DraftQueueItem, completed: (result: CustomActionResult) => void) => void;
|
|
19
|
+
export type FieldMap = {
|
|
20
|
+
[key: string]: string | number | null | boolean;
|
|
21
|
+
};
|
|
17
22
|
/**
|
|
18
23
|
* An item in the draft queue that loosely maps to
|
|
19
24
|
* a DraftAction
|
|
@@ -124,6 +129,10 @@ export declare class DraftManager {
|
|
|
124
129
|
* @returns
|
|
125
130
|
*/
|
|
126
131
|
setCustomActionExecutor(handlerId: string, executor: DraftManagerCustomActionExecutor): Promise<() => Promise<void>>;
|
|
132
|
+
mergePerformQuickAction(actionId: string, fields: FieldMap): Promise<DraftQueueItem>;
|
|
133
|
+
private isValidFieldMap;
|
|
134
|
+
isPerformQuickActionDraft(action: DraftAction<unknown, unknown>, method: string): action is PendingDraftAction<ResourceRequest>;
|
|
135
|
+
mergePerformUpdateRecordQuickAction(actionId: string, fields: FieldMap): Promise<DraftQueueItem>;
|
|
127
136
|
private buildDraftQueueItem;
|
|
128
137
|
private callListeners;
|
|
129
138
|
/**
|
|
@@ -204,6 +204,13 @@ export interface DraftQueue {
|
|
|
204
204
|
* @param actionId The action identifier
|
|
205
205
|
*/
|
|
206
206
|
removeDraftAction(actionId: string): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Saves the specified action into the queue, overwriting previous values
|
|
209
|
+
* of the action with the new ones
|
|
210
|
+
*
|
|
211
|
+
* @param action The action to update with the passed in values
|
|
212
|
+
*/
|
|
213
|
+
updateDraftAction<Data, Response>(action: DraftAction<Data, Response>): Promise<void>;
|
|
207
214
|
/**
|
|
208
215
|
* Replaces the resource request of `withActionId` for the resource request
|
|
209
216
|
* of `actionId`. Action ids cannot be equal. Both actions must be acting
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DraftQueue, DraftAction, CompletedDraftAction, DraftQueueChangeListener, DraftActionMetadata, EnqueueResult } from './DraftQueue';
|
|
1
|
+
import type { DraftQueue, DraftAction, CompletedDraftAction, PendingDraftAction, DraftQueueChangeListener, DraftActionMetadata, EnqueueResult } from './DraftQueue';
|
|
2
2
|
import { ProcessActionResult, DraftQueueState } from './DraftQueue';
|
|
3
3
|
import type { CustomActionExecutor } from './actionHandlers/CustomActionHandler';
|
|
4
4
|
import type { ActionHandler } from './actionHandlers/ActionHandler';
|
|
@@ -45,6 +45,8 @@ export declare class DurableDraftQueue implements DraftQueue {
|
|
|
45
45
|
*/
|
|
46
46
|
private startQueueSafe;
|
|
47
47
|
removeDraftAction(actionId: string): Promise<void>;
|
|
48
|
+
updateDraftAction<Data>(action: PendingDraftAction<Data>): Promise<void>;
|
|
49
|
+
private statusOfAction;
|
|
48
50
|
replaceAction<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
|
|
49
51
|
mergeActions<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
|
|
50
52
|
setMetadata(actionId: string, metadata: DraftActionMetadata): Promise<DraftAction<unknown, unknown>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/lds-drafts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.304.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"description": "LDS Drafts",
|
|
6
6
|
"main": "dist/ldsDrafts.js",
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@luvio/engine": "0.156.3",
|
|
28
28
|
"@luvio/environments": "0.156.3",
|
|
29
|
-
"@salesforce/lds-utils-adapters": "^1.
|
|
29
|
+
"@salesforce/lds-utils-adapters": "^1.304.0"
|
|
30
|
+
},
|
|
31
|
+
"volta": {
|
|
32
|
+
"extends": "../../package.json"
|
|
30
33
|
}
|
|
31
34
|
}
|