cozy-client 46.7.1 → 46.9.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/CozyClient.js +90 -13
- package/dist/__tests__/mocks.js +2 -1
- package/dist/helpers/index.js +33 -1
- package/dist/helpers/settings.js +311 -0
- package/dist/helpers/settings.spec.js +493 -0
- package/dist/hooks/index.js +9 -1
- package/dist/hooks/useSetting.js +64 -0
- package/dist/models/document/locales/fr.json +1 -1
- package/dist/types.js +44 -4
- package/package.json +2 -2
- package/types/CozyClient.d.ts +29 -0
- package/types/__tests__/mocks.d.ts +1 -0
- package/types/helpers/index.d.ts +1 -0
- package/types/helpers/settings.d.ts +7 -0
- package/types/hooks/index.d.ts +1 -0
- package/types/hooks/useSetting.d.ts +1 -0
- package/types/types.d.ts +40 -8
package/types/CozyClient.d.ts
CHANGED
|
@@ -414,6 +414,10 @@ declare class CozyClient {
|
|
|
414
414
|
* `getQueryFromState` or directly using `<Query />`. `<Query />` automatically
|
|
415
415
|
* executes its query when mounted if no fetch policy has been indicated.
|
|
416
416
|
*
|
|
417
|
+
* If the query is called under the fetch policy's delay, then the query
|
|
418
|
+
* is not executed and nothing is returned. If you need a result anyway,
|
|
419
|
+
* please use `fetchQueryAndGetFromState` instead
|
|
420
|
+
*
|
|
417
421
|
* @param {QueryDefinition} queryDefinition - Definition that will be executed
|
|
418
422
|
* @param {import("./types").QueryOptions} [options] - Options
|
|
419
423
|
* @returns {Promise<import("./types").QueryResult>}
|
|
@@ -713,6 +717,31 @@ declare class CozyClient {
|
|
|
713
717
|
* @param {import("./types").AppMetadata} newAppMetadata AppMetadata to update
|
|
714
718
|
*/
|
|
715
719
|
setAppMetadata(newAppMetadata: import("./types").AppMetadata): void;
|
|
720
|
+
/**
|
|
721
|
+
* Query the cozy-app settings corresponding to the given slug and
|
|
722
|
+
* extract the value corresponding to the given `key`
|
|
723
|
+
*
|
|
724
|
+
* @template {string} T
|
|
725
|
+
*
|
|
726
|
+
* @param {string} slug - the cozy-app's slug containing the setting (can be 'instance' for global settings)
|
|
727
|
+
* @param {T[]} keys - The names of the settings to retrieve
|
|
728
|
+
* @returns {Promise<any>} - The value of the requested setting
|
|
729
|
+
*/
|
|
730
|
+
getSettings<T extends string>(slug: string, keys: T[]): Promise<any>;
|
|
731
|
+
/**
|
|
732
|
+
* Save the given value into the corresponding cozy-app setting
|
|
733
|
+
*
|
|
734
|
+
* This methods will first query the cozy-app's settings before injecting the new value and then
|
|
735
|
+
* save the new resulting settings into database
|
|
736
|
+
*
|
|
737
|
+
* @template {string} T
|
|
738
|
+
*
|
|
739
|
+
* @param {string} slug - the cozy-app's slug containing the setting (can be 'instance' for global settings)
|
|
740
|
+
* @param {Record<string, any> | ((oldValue) => Record<T, any>)} itemsOrSetter - The new values of the settings to save. It can be a raw dictionnary, or a callback that should return a new dictionnary
|
|
741
|
+
* @param {T[]=} setterKeys - The new values of the settings to save. It can be a raw dictionnary, or a callback that should return a new dictionnary
|
|
742
|
+
* @returns {Promise<any>} - The result of the `client.save()` call
|
|
743
|
+
*/
|
|
744
|
+
saveAfterFetchSettings<T_1 extends string>(slug: string, itemsOrSetter: Record<string, any> | ((oldValue: any) => Record<T_1, any>), setterKeys?: T_1[]): Promise<any>;
|
|
716
745
|
}
|
|
717
746
|
declare namespace CozyClient {
|
|
718
747
|
export const hooks: {};
|
|
@@ -8,6 +8,7 @@ export function client(implementations: any): {
|
|
|
8
8
|
requestQuery: jest.Mock<any, any>;
|
|
9
9
|
all: jest.Mock<any, any>;
|
|
10
10
|
setStore: jest.Mock<any, any>;
|
|
11
|
+
fetchQueryAndGetFromState: jest.Mock<any, any>;
|
|
11
12
|
};
|
|
12
13
|
export function observableQuery(implementations: any): {
|
|
13
14
|
currentResult: jest.Mock<any, any>;
|
package/types/helpers/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { dehydrate } from "./dehydrateHelper";
|
|
2
2
|
export { deconstructCozyWebLinkWithSlug, deconstructRedirectLink, generateWebLink, ensureFirstSlash, rootCozyUrl, InvalidRedirectLinkError, InvalidCozyUrlError, InvalidProtocolError, BlockedCozyError } from "./urlHelper";
|
|
3
|
+
export { editSettings, getQuery, getSettings, normalizeSettings, saveAfterFetchSettings } from "./settings";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function getSettings<T extends string>(client: CozyClient, slug: string, keys: T[]): Promise<Record<T, any>>;
|
|
2
|
+
export function saveAfterFetchSettings<T extends string>(client: CozyClient, slug: string, itemsOrSetter: Record<string, any> | ((oldValue: any) => Record<T, any>), setterKeys?: T[]): Promise<any>;
|
|
3
|
+
export function normalizeSettings(data: any[] | any): any;
|
|
4
|
+
export function editSettings(slug: string, currentSettings: any, items: Record<string, unknown>): any;
|
|
5
|
+
export function extractKeys<T extends string>(settings: Record<T, any>, keys: T[]): Record<T, any>;
|
|
6
|
+
export function getQuery(slug: string): import('../types').Query;
|
|
7
|
+
import CozyClient from "../CozyClient";
|
package/types/hooks/index.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export { default as useAppsInMaintenance } from "./useAppsInMaintenance";
|
|
|
6
6
|
export { default as useQueryAll } from "./useQueryAll";
|
|
7
7
|
export { useMutation } from "./useMutation";
|
|
8
8
|
export { useInstanceInfo } from "./useInstanceInfo";
|
|
9
|
+
export { useSettings } from "./useSetting";
|
|
9
10
|
export { default as useQuery, useQueries } from "./useQuery";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function useSettings<T extends string>(slug: string, keys: T[]): import("../types").UseSettingsReturnValue<T>;
|
package/types/types.d.ts
CHANGED
|
@@ -481,7 +481,7 @@ export type IndexedDocuments = {
|
|
|
481
481
|
export type DocumentsStateSlice = {
|
|
482
482
|
[x: string]: Record<string, CozyClientDocument>;
|
|
483
483
|
};
|
|
484
|
-
export type
|
|
484
|
+
export type QueryStateWithoutData = {
|
|
485
485
|
id: string;
|
|
486
486
|
definition: QueryDefinition;
|
|
487
487
|
fetchStatus: QueryFetchStatus;
|
|
@@ -493,11 +493,14 @@ export type QueryState = {
|
|
|
493
493
|
hasMore: boolean;
|
|
494
494
|
count: number;
|
|
495
495
|
fetchedPagesCount: number;
|
|
496
|
-
data: object | any[];
|
|
497
496
|
bookmark: string;
|
|
498
497
|
execution_stats?: object;
|
|
499
498
|
options?: QueryOptions;
|
|
500
499
|
};
|
|
500
|
+
export type QueryStateData = {
|
|
501
|
+
data: object | any[];
|
|
502
|
+
};
|
|
503
|
+
export type QueryState = QueryStateWithoutData & QueryStateData;
|
|
501
504
|
export type AutoUpdateOptions = any;
|
|
502
505
|
export type QueryOptions = {
|
|
503
506
|
/**
|
|
@@ -539,18 +542,18 @@ export type QueryOptions = {
|
|
|
539
542
|
*/
|
|
540
543
|
singleDocData?: boolean;
|
|
541
544
|
};
|
|
545
|
+
export type Query = {
|
|
546
|
+
definition: QueryDefinition;
|
|
547
|
+
options: QueryOptions;
|
|
548
|
+
};
|
|
542
549
|
export type FetchMoreAble = {
|
|
543
550
|
fetchMore: Function;
|
|
544
551
|
};
|
|
545
552
|
export type FetchAble = {
|
|
546
553
|
fetch: Function;
|
|
547
554
|
};
|
|
548
|
-
export type UseQueryReturnValue =
|
|
549
|
-
export type
|
|
550
|
-
/**
|
|
551
|
-
* - Function to save the document
|
|
552
|
-
*/
|
|
553
|
-
mutate: Function;
|
|
555
|
+
export type UseQueryReturnValue = QueryStateWithoutData & QueryStateData & FetchMoreAble & FetchAble;
|
|
556
|
+
export type UseMutationWithoutMutate = {
|
|
554
557
|
/**
|
|
555
558
|
* - Status of the current mutation
|
|
556
559
|
*/
|
|
@@ -564,6 +567,35 @@ export type UseMutationReturnValue = {
|
|
|
564
567
|
*/
|
|
565
568
|
data?: object;
|
|
566
569
|
};
|
|
570
|
+
export type UseMutationMutate = {
|
|
571
|
+
/**
|
|
572
|
+
* - Function to save the document
|
|
573
|
+
*/
|
|
574
|
+
mutate: Function;
|
|
575
|
+
};
|
|
576
|
+
export type UseMutationReturnValue = UseMutationWithoutMutate & UseMutationMutate;
|
|
577
|
+
/**
|
|
578
|
+
* Update the setting with corresponding value and save it.
|
|
579
|
+
*/
|
|
580
|
+
export type SaveSettingsFunction<T extends string> = (items: Partial<Record<T, any>>) => any;
|
|
581
|
+
export type UseSettingsReturnValue<T extends string> = {
|
|
582
|
+
/**
|
|
583
|
+
* - The setting's value
|
|
584
|
+
*/
|
|
585
|
+
values: Record<T, any>;
|
|
586
|
+
/**
|
|
587
|
+
* - Function to edit the setting
|
|
588
|
+
*/
|
|
589
|
+
save: SaveSettingsFunction<T>;
|
|
590
|
+
/**
|
|
591
|
+
* - Function to edit the setting
|
|
592
|
+
*/
|
|
593
|
+
query: QueryStateWithoutData;
|
|
594
|
+
/**
|
|
595
|
+
* - Status of the current mutation
|
|
596
|
+
*/
|
|
597
|
+
mutation: UseMutationWithoutMutate;
|
|
598
|
+
};
|
|
567
599
|
/**
|
|
568
600
|
* A reference to a document
|
|
569
601
|
*/
|