@salesforce/lds-drafts 1.443.0 → 1.445.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
|
@@ -259,7 +259,7 @@ function customActionHandler(executor, id, draftQueue) {
|
|
|
259
259
|
}, result.error.type === CustomActionErrorType.NETWORK_ERROR);
|
|
260
260
|
}
|
|
261
261
|
};
|
|
262
|
-
const buildPendingAction = (action, queue) => {
|
|
262
|
+
const buildPendingAction = (action, queue, observabilityContext) => {
|
|
263
263
|
const { data, tag, targetId, handler } = action;
|
|
264
264
|
const id = generateUniqueDraftActionId(queue.map((a) => a.id));
|
|
265
265
|
return Promise.resolve({
|
|
@@ -271,6 +271,7 @@ function customActionHandler(executor, id, draftQueue) {
|
|
|
271
271
|
timestamp: Date.now(),
|
|
272
272
|
metadata: data,
|
|
273
273
|
handler,
|
|
274
|
+
observabilityContext,
|
|
274
275
|
});
|
|
275
276
|
};
|
|
276
277
|
const getQueueOperationsForCompletingDrafts = (_queue, action) => {
|
|
@@ -306,6 +307,13 @@ function customActionHandler(executor, id, draftQueue) {
|
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
const DRAFT_SEGMENT = 'DRAFT';
|
|
310
|
+
/**
|
|
311
|
+
* Metadata key under which an action's upload retry-attempt count is persisted.
|
|
312
|
+
* Lives in the action's durable `metadata` bag so the count survives app restarts
|
|
313
|
+
* (the in-memory backoff interval resets on every startQueue()). Written by the
|
|
314
|
+
* action handler on each retry and cleared when an action is manually retried.
|
|
315
|
+
*/
|
|
316
|
+
const DRAFT_ACTION_RETRY_COUNT_METADATA_KEY = 'retryCount';
|
|
309
317
|
class DurableDraftQueue {
|
|
310
318
|
getHandler(id) {
|
|
311
319
|
const handler = this.handlers[id];
|
|
@@ -442,12 +450,12 @@ class DurableDraftQueue {
|
|
|
442
450
|
return aTime - bTime;
|
|
443
451
|
});
|
|
444
452
|
}
|
|
445
|
-
async enqueue(handlerId, data) {
|
|
453
|
+
async enqueue(handlerId, data, observabilityContext) {
|
|
446
454
|
return this.workerPool.push({
|
|
447
455
|
workFn: async () => {
|
|
448
456
|
let queue = await this.getQueueActions();
|
|
449
457
|
const handler = this.getHandler(handlerId);
|
|
450
|
-
const pendingAction = (await handler.buildPendingAction(data, queue));
|
|
458
|
+
const pendingAction = (await handler.buildPendingAction(data, queue, observabilityContext));
|
|
451
459
|
await this.draftStore.writeAction(pendingAction);
|
|
452
460
|
queue = await this.getQueueActions();
|
|
453
461
|
await this.notifyChangedListeners({
|
|
@@ -674,10 +682,14 @@ class DurableDraftQueue {
|
|
|
674
682
|
if (!isDraftError(target)) {
|
|
675
683
|
throw Error(`Action ${actionId} is not in Error state`);
|
|
676
684
|
}
|
|
685
|
+
// A manual retry is a fresh start: clear the persisted upload retry-attempt
|
|
686
|
+
// count so the action doesn't immediately re-cap after a single failure.
|
|
687
|
+
const { [DRAFT_ACTION_RETRY_COUNT_METADATA_KEY]: _retryCount, ...metadataWithoutRetryCount } = target.metadata || {};
|
|
677
688
|
let pendingAction = {
|
|
678
689
|
...target,
|
|
679
690
|
status: DraftActionStatus.Pending,
|
|
680
691
|
error: undefined,
|
|
692
|
+
metadata: metadataWithoutRetryCount,
|
|
681
693
|
};
|
|
682
694
|
await this.draftStore.writeAction(pendingAction);
|
|
683
695
|
await this.notifyChangedListeners({
|
|
@@ -1269,7 +1281,7 @@ class DraftManager {
|
|
|
1269
1281
|
}
|
|
1270
1282
|
buildDraftQueueItem(action) {
|
|
1271
1283
|
const operationType = getOperationTypeFrom(action);
|
|
1272
|
-
const { id, status, timestamp, targetId, metadata } = action;
|
|
1284
|
+
const { id, status, timestamp, targetId, metadata, observabilityContext } = action;
|
|
1273
1285
|
const item = {
|
|
1274
1286
|
id,
|
|
1275
1287
|
targetId,
|
|
@@ -1277,6 +1289,7 @@ class DraftManager {
|
|
|
1277
1289
|
timestamp,
|
|
1278
1290
|
operationType,
|
|
1279
1291
|
metadata,
|
|
1292
|
+
observabilityContext,
|
|
1280
1293
|
};
|
|
1281
1294
|
if (isDraftError(action)) {
|
|
1282
1295
|
// We should always return an array, if the body is just a dictionary,
|
|
@@ -1380,4 +1393,4 @@ function isResourceRequestAction(action) {
|
|
|
1380
1393
|
return (dataAsAny !== undefined && dataAsAny.method !== undefined && dataAsAny.body !== undefined);
|
|
1381
1394
|
}
|
|
1382
1395
|
|
|
1383
|
-
export { CustomActionResultType, DRAFT_ERROR_CODE, DRAFT_SEGMENT, DraftActionOperationType, DraftActionStatus, DraftErrorFetchResponse, DraftFetchResponse, DraftManager, DraftQueueEventType, DraftQueueState, DraftSynthesisError, DurableDraftQueue, DurableDraftStore, ProcessActionResult, QueueOperationType, createBadRequestResponse, createDeletedResponse, createDraftSynthesisErrorResponse, createInternalErrorResponse, createNotFoundResponse, createOkResponse, generateUniqueDraftActionId, isDraftSynthesisError, transformErrorToDraftSynthesisError };
|
|
1396
|
+
export { CustomActionResultType, DRAFT_ACTION_RETRY_COUNT_METADATA_KEY, DRAFT_ERROR_CODE, DRAFT_SEGMENT, DraftActionOperationType, DraftActionStatus, DraftErrorFetchResponse, DraftFetchResponse, DraftManager, DraftQueueEventType, DraftQueueState, DraftSynthesisError, DurableDraftQueue, DurableDraftStore, ProcessActionResult, QueueOperationType, createBadRequestResponse, createDeletedResponse, createDraftSynthesisErrorResponse, createInternalErrorResponse, createNotFoundResponse, createOkResponse, generateUniqueDraftActionId, isDraftSynthesisError, transformErrorToDraftSynthesisError };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CustomActionResult } from './actionHandlers/CustomActionHandler';
|
|
2
|
+
import type { ObservabilityContext } from '@salesforce/nimbus-plugin-lds';
|
|
2
3
|
import type { DraftQueue, DraftAction, DraftActionMetadata, PendingDraftAction, DraftQueueState } from './DraftQueue';
|
|
3
4
|
import { DraftActionStatus } from './DraftQueue';
|
|
4
5
|
import type { ResourceRequest } from '@luvio/engine';
|
|
@@ -37,6 +38,8 @@ export interface DraftQueueItem {
|
|
|
37
38
|
error?: undefined | DraftQueueItemError;
|
|
38
39
|
/** The stored metadata for the draft queue item */
|
|
39
40
|
metadata: DraftQueueItemMetadata;
|
|
41
|
+
/** o11y context from draft creation time, forwarded at replay */
|
|
42
|
+
observabilityContext?: ObservabilityContext;
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* An error of a draft action that was submitted and failed
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FetchResponse } from '@luvio/engine';
|
|
2
|
+
import type { ObservabilityContext } from '@salesforce/nimbus-plugin-lds';
|
|
2
3
|
import type { ActionHandler } from './actionHandlers/ActionHandler';
|
|
3
4
|
import type { CustomActionExecutor } from './actionHandlers/CustomActionHandler';
|
|
4
5
|
export declare enum DraftActionStatus {
|
|
@@ -25,6 +26,8 @@ interface BaseDraftAction<Data> {
|
|
|
25
26
|
/** the data being enqueued */
|
|
26
27
|
data: Data;
|
|
27
28
|
version: '242.0.0';
|
|
29
|
+
/** o11y context from draft creation time, forwarded verbatim at replay */
|
|
30
|
+
observabilityContext?: ObservabilityContext;
|
|
28
31
|
}
|
|
29
32
|
export interface CompletedDraftAction<Data, Response> extends BaseDraftAction<Data> {
|
|
30
33
|
status: DraftActionStatus.Completed;
|
|
@@ -162,10 +165,11 @@ export interface DraftQueue {
|
|
|
162
165
|
* Enqueues a draft action into the DraftQueue
|
|
163
166
|
* @param handlerId the id of the handler associated with the data
|
|
164
167
|
* @param data the data the handler will use to create the draft action with
|
|
168
|
+
* @param observabilityContext optional o11y context from the enqueuing call site, persisted for replay
|
|
165
169
|
* @returns A promise including the pending action created for the request and the data associated with the action
|
|
166
170
|
* @throws {Error} An error when a proper action handler is not found or conditions are not met to enqueue the action
|
|
167
171
|
*/
|
|
168
|
-
enqueue<Data>(handlerId: string, data: Data): Promise<PendingDraftAction<Data>>;
|
|
172
|
+
enqueue<Data>(handlerId: string, data: Data, observabilityContext?: ObservabilityContext): Promise<PendingDraftAction<Data>>;
|
|
169
173
|
/**
|
|
170
174
|
* add a new handler to the draft queue to process the data in the actions
|
|
171
175
|
* @param id identifier to the handler
|
|
@@ -3,7 +3,15 @@ import { ProcessActionResult, DraftQueueState } from './DraftQueue';
|
|
|
3
3
|
import type { CustomActionExecutor } from './actionHandlers/CustomActionHandler';
|
|
4
4
|
import type { ActionHandler } from './actionHandlers/ActionHandler';
|
|
5
5
|
import type { DraftStore } from './DraftStore';
|
|
6
|
+
import type { ObservabilityContext } from '@salesforce/nimbus-plugin-lds';
|
|
6
7
|
export declare const DRAFT_SEGMENT = "DRAFT";
|
|
8
|
+
/**
|
|
9
|
+
* Metadata key under which an action's upload retry-attempt count is persisted.
|
|
10
|
+
* Lives in the action's durable `metadata` bag so the count survives app restarts
|
|
11
|
+
* (the in-memory backoff interval resets on every startQueue()). Written by the
|
|
12
|
+
* action handler on each retry and cleared when an action is manually retried.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DRAFT_ACTION_RETRY_COUNT_METADATA_KEY = "retryCount";
|
|
7
15
|
export declare class DurableDraftQueue implements DraftQueue {
|
|
8
16
|
private retryIntervalMilliseconds;
|
|
9
17
|
private minimumRetryInterval;
|
|
@@ -33,7 +41,7 @@ export declare class DurableDraftQueue implements DraftQueue {
|
|
|
33
41
|
*/
|
|
34
42
|
private stopQueueManually;
|
|
35
43
|
getQueueActions<Data = unknown, Response = unknown>(): Promise<DraftAction<Data, Response>[]>;
|
|
36
|
-
enqueue<Data>(handlerId: string, data: unknown): Promise<PendingDraftAction<Data>>;
|
|
44
|
+
enqueue<Data>(handlerId: string, data: unknown, observabilityContext?: ObservabilityContext): Promise<PendingDraftAction<Data>>;
|
|
37
45
|
registerOnChangedListener(listener: DraftQueueChangeListener): () => Promise<void>;
|
|
38
46
|
actionCompleted(action: CompletedDraftAction<unknown, unknown>): Promise<void>;
|
|
39
47
|
actionFailed(action: DraftAction<unknown, unknown>, retry: boolean, retryDelayInMs?: number, actionDataChanged?: boolean): Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ObservabilityContext } from '@salesforce/nimbus-plugin-lds';
|
|
1
2
|
import type { CompletedDraftAction, DraftAction, DraftActionMetadata, PendingDraftAction, ProcessActionResult, QueueOperation } from '../DraftQueue';
|
|
2
3
|
export interface ReplacingActions<Response, Data> {
|
|
3
4
|
original: DraftAction<Response, Data>;
|
|
@@ -26,10 +27,11 @@ export interface ActionHandler<Data, Type> {
|
|
|
26
27
|
* Used to build a PendingDraftAction that is specific to the type of Data and Response.
|
|
27
28
|
* @param data
|
|
28
29
|
* @param queue
|
|
30
|
+
* @param observabilityContext optional o11y context to persist on the action for replay
|
|
29
31
|
*
|
|
30
32
|
* @throws {Error} if any preconditions to building the draft action are not satisfied
|
|
31
33
|
*/
|
|
32
|
-
buildPendingAction(data: unknown, queue: DraftAction<unknown, unknown>[]): Promise<PendingDraftAction<Data>>;
|
|
34
|
+
buildPendingAction(data: unknown, queue: DraftAction<unknown, unknown>[], observabilityContext?: ObservabilityContext): Promise<PendingDraftAction<Data>>;
|
|
33
35
|
/**
|
|
34
36
|
* Invoked after an action is enqueued into the draft queue
|
|
35
37
|
* @param action The action that was just enqueued
|
package/dist/types/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DraftQueue, DraftQueueState, DraftAction, ErrorDraftAction, PendingDraftAction, CompletedDraftAction, DraftActionStatus, ProcessActionResult, DraftQueueChangeListener, DraftActionMetadata, DraftQueueEventType, QueueOperation, UpdateQueueOperation, QueueOperationType, type DraftQueueEvent, type DraftQueueActionFailedEvent, } from './DraftQueue';
|
|
2
|
-
export { DurableDraftQueue, DRAFT_SEGMENT } from './DurableDraftQueue';
|
|
2
|
+
export { DurableDraftQueue, DRAFT_SEGMENT, DRAFT_ACTION_RETRY_COUNT_METADATA_KEY, } from './DurableDraftQueue';
|
|
3
3
|
export { generateUniqueDraftActionId, uuidv4 } from './utils/id';
|
|
4
4
|
export { DurableDraftStore } from './DurableDraftStore';
|
|
5
5
|
export { DraftStore } from './DraftStore';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/lds-drafts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.445.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"description": "LDS Drafts",
|
|
6
6
|
"main": "dist/ldsDrafts.js",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"release:corejar": "yarn build && ../core-build/scripts/core.js --adapter=lds-drafts"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@luvio/engine": "0.
|
|
28
|
-
"@luvio/environments": "0.
|
|
29
|
-
"@salesforce/lds-utils-adapters": "^1.
|
|
27
|
+
"@luvio/engine": "0.161.0",
|
|
28
|
+
"@luvio/environments": "0.161.0",
|
|
29
|
+
"@salesforce/lds-utils-adapters": "^1.445.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@salesforce/nimbus-plugin-lds": "^1.
|
|
32
|
+
"@salesforce/nimbus-plugin-lds": "^1.445.0"
|
|
33
33
|
},
|
|
34
34
|
"volta": {
|
|
35
35
|
"extends": "../../package.json"
|