@pushwoosh/spa-context 1.7.2 → 1.8.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/approvals.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { ApprovalState } from '@pushwoosh/rpc-v2-http-api-data/approvals';
2
+ export type { ApprovalState };
3
+ /** The last approval request of an item, as `approvals.List` returns it. */
4
+ export type DecidedRequest = {
5
+ state: ApprovalState;
6
+ versionNo: number;
7
+ comment?: string;
8
+ };
9
+ /** What the UI shows for the current content of an item. */
10
+ export type VersionState = {
11
+ state: ApprovalState;
12
+ versionNo?: number;
13
+ /** Why the version was rejected; empty unless the decision belongs to the current content. */
14
+ comment: string;
15
+ };
16
+ export declare function stateOfVersion(request: DecidedRequest | null | undefined, latestVersionNo: number): VersionState;
package/approvals.js ADDED
@@ -0,0 +1,18 @@
1
+ // A decision belongs to the version it was made on: approve v4, save the content again and
2
+ // the gate refuses v5, so every place that shows the state reads it off the version.
3
+ // No versions at all is content from before the mode — there the request is all there is.
4
+ export function stateOfVersion(request, latestVersionNo) {
5
+ const decided = Boolean(request) && (latestVersionNo === 0 || request.versionNo >= latestVersionNo);
6
+ if (!decided) {
7
+ return {
8
+ state: 'APPROVAL_STATE_UNSPECIFIED',
9
+ versionNo: latestVersionNo || undefined,
10
+ comment: ''
11
+ };
12
+ }
13
+ return {
14
+ state: request.state,
15
+ versionNo: latestVersionNo || request.versionNo,
16
+ comment: request.state === 'APPROVAL_STATE_REJECTED' ? request.comment ?? '' : ''
17
+ };
18
+ }
package/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { stateOfVersion } from './approvals';
2
+ import type { ApprovalState, DecidedRequest, VersionState } from './approvals';
1
3
  import { SimpleEventEmitter } from './SimpleEventEmitter';
2
4
  import type { SPAContextType } from './types';
3
5
  import { UniversalKeyValueStore } from './UniversalKeyValueStore';
@@ -5,6 +7,6 @@ import { useEventValue } from './useEventValue';
5
7
  import { useMemoryKey, useMemoryKeySlim } from './useMemoryKey';
6
8
  import { useSession } from './useSession';
7
9
  import { useSPAContext } from './useSPAContext';
8
- export type { SPAContextType };
9
- export { useSPAContext, useSession, useEventValue, useMemoryKey, useMemoryKeySlim, SimpleEventEmitter, UniversalKeyValueStore, };
10
+ export type { SPAContextType, ApprovalState, DecidedRequest, VersionState };
11
+ export { useSPAContext, useSession, useEventValue, useMemoryKey, useMemoryKeySlim, SimpleEventEmitter, UniversalKeyValueStore, stateOfVersion, };
10
12
  export declare const SPAContextProvider: import("react").Provider<SPAContextType | undefined>;
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { stateOfVersion } from './approvals';
1
2
  import { SPAContext } from './context';
2
3
  import { SimpleEventEmitter } from './SimpleEventEmitter';
3
4
  import { UniversalKeyValueStore } from './UniversalKeyValueStore';
@@ -5,5 +6,5 @@ import { useEventValue } from './useEventValue';
5
6
  import { useMemoryKey, useMemoryKeySlim } from './useMemoryKey';
6
7
  import { useSession } from './useSession';
7
8
  import { useSPAContext } from './useSPAContext';
8
- export { useSPAContext, useSession, useEventValue, useMemoryKey, useMemoryKeySlim, SimpleEventEmitter, UniversalKeyValueStore };
9
+ export { useSPAContext, useSession, useEventValue, useMemoryKey, useMemoryKeySlim, SimpleEventEmitter, UniversalKeyValueStore, stateOfVersion };
9
10
  export const SPAContextProvider = SPAContext.Provider;
package/package.json CHANGED
@@ -25,6 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@pushwoosh/frontend-builder-engine": "^3.1.0",
27
27
  "@pushwoosh/http-client": "^2.10.0",
28
+ "@pushwoosh/rpc-v2-http-api-data": "^0.2.265",
28
29
  "@pushwoosh/session-store": "^2.8.0",
29
30
  "@types/history": "^4.7.11",
30
31
  "@types/react": "^18.3.27",
@@ -44,5 +45,5 @@
44
45
  "@pushwoosh/session-store": "^2.7.0",
45
46
  "react": "^16.14.0 || ^18.0.0"
46
47
  },
47
- "version": "1.7.2"
48
+ "version": "1.8.0"
48
49
  }