@trackunit/react-core-hooks 0.2.205 → 0.2.208
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/index.cjs.js +60 -30
- package/index.esm.js +59 -31
- package/package.json +1 -1
- package/src/analytics/AnalyticsProvider.d.ts +3 -3
- package/src/fetchAssetBlobUrl.d.ts +5 -0
- package/src/images/useIrisAppImage.d.ts +23 -0
- package/src/index.d.ts +2 -0
- package/src/useFeatureBranchQueryString.d.ts +6 -0
package/index.cjs.js
CHANGED
|
@@ -135,6 +135,55 @@ const useEnvironment = () => {
|
|
|
135
135
|
return context;
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
+
/******************************************************************************
|
|
139
|
+
Copyright (c) Microsoft Corporation.
|
|
140
|
+
|
|
141
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
142
|
+
purpose with or without fee is hereby granted.
|
|
143
|
+
|
|
144
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
145
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
146
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
147
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
148
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
149
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
150
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
151
|
+
***************************************************************************** */
|
|
152
|
+
|
|
153
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
154
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
155
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
156
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
157
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
158
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
159
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
164
|
+
var e = new Error(message);
|
|
165
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Fetch any url as a blob and return a blob url.
|
|
170
|
+
* This is used to get and display logos and images related to Iris Apps.
|
|
171
|
+
*/
|
|
172
|
+
const fetchAssetBlobUrl = (fullUrl, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
try {
|
|
174
|
+
const result = yield fetch(fullUrl, {
|
|
175
|
+
method: "GET",
|
|
176
|
+
headers,
|
|
177
|
+
});
|
|
178
|
+
const blob = yield result.blob();
|
|
179
|
+
const assetUrl = URL.createObjectURL(blob);
|
|
180
|
+
return assetUrl;
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
138
187
|
const FilterBarContext = React__namespace.createContext(null);
|
|
139
188
|
/**
|
|
140
189
|
* This is a hook to use the FilterBarProvider.
|
|
@@ -287,36 +336,6 @@ const useModalDialogContext = () => {
|
|
|
287
336
|
return modalDialogContext;
|
|
288
337
|
};
|
|
289
338
|
|
|
290
|
-
/******************************************************************************
|
|
291
|
-
Copyright (c) Microsoft Corporation.
|
|
292
|
-
|
|
293
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
294
|
-
purpose with or without fee is hereby granted.
|
|
295
|
-
|
|
296
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
297
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
298
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
299
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
300
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
301
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
302
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
303
|
-
***************************************************************************** */
|
|
304
|
-
|
|
305
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
306
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
307
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
308
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
309
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
310
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
311
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
316
|
-
var e = new Error(message);
|
|
317
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
318
|
-
};
|
|
319
|
-
|
|
320
339
|
const NavigationContext = React.createContext(null);
|
|
321
340
|
/**
|
|
322
341
|
* This is a provider for the NavigationContext.
|
|
@@ -661,6 +680,15 @@ const useToast = () => {
|
|
|
661
680
|
return toastContext;
|
|
662
681
|
};
|
|
663
682
|
|
|
683
|
+
/**
|
|
684
|
+
* Returns the query string to be appended to the URL when the app is served from a Feature Branch.
|
|
685
|
+
*/
|
|
686
|
+
const useFeatureBranchQueryString = () => {
|
|
687
|
+
const { publicUrl, buildVersion } = useEnvironment();
|
|
688
|
+
const featureBranchQueryParam = React.useMemo(() => !publicUrl || publicUrl === "/" ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`, [publicUrl, buildVersion]);
|
|
689
|
+
return { featureBranchQueryParam };
|
|
690
|
+
};
|
|
691
|
+
|
|
664
692
|
/**
|
|
665
693
|
* Hook for filtering a list of items by text search, client side search in a list.
|
|
666
694
|
*
|
|
@@ -806,6 +834,7 @@ exports.OemBrandingContextProvider = OemBrandingContextProvider;
|
|
|
806
834
|
exports.ToastProvider = ToastProvider;
|
|
807
835
|
exports.TokenProvider = TokenProvider;
|
|
808
836
|
exports.UserSubscriptionProvider = UserSubscriptionProvider;
|
|
837
|
+
exports.fetchAssetBlobUrl = fetchAssetBlobUrl;
|
|
809
838
|
exports.useAnalytics = useAnalytics;
|
|
810
839
|
exports.useAssetRuntime = useAssetRuntime;
|
|
811
840
|
exports.useAssetSorting = useAssetSorting;
|
|
@@ -817,6 +846,7 @@ exports.useCurrentUserTimeZonePreference = useCurrentUserTimeZonePreference;
|
|
|
817
846
|
exports.useCustomerRuntime = useCustomerRuntime;
|
|
818
847
|
exports.useEnvironment = useEnvironment;
|
|
819
848
|
exports.useEventRuntime = useEventRuntime;
|
|
849
|
+
exports.useFeatureBranchQueryString = useFeatureBranchQueryString;
|
|
820
850
|
exports.useFilterBarContext = useFilterBarContext;
|
|
821
851
|
exports.useHasAccessTo = useHasAccessTo;
|
|
822
852
|
exports.useImageUploader = useImageUploader;
|
package/index.esm.js
CHANGED
|
@@ -112,6 +112,55 @@ const useEnvironment = () => {
|
|
|
112
112
|
return context;
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
+
/******************************************************************************
|
|
116
|
+
Copyright (c) Microsoft Corporation.
|
|
117
|
+
|
|
118
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
119
|
+
purpose with or without fee is hereby granted.
|
|
120
|
+
|
|
121
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
122
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
123
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
124
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
125
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
126
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
127
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
128
|
+
***************************************************************************** */
|
|
129
|
+
|
|
130
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
131
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
132
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
133
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
134
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
135
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
136
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
141
|
+
var e = new Error(message);
|
|
142
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Fetch any url as a blob and return a blob url.
|
|
147
|
+
* This is used to get and display logos and images related to Iris Apps.
|
|
148
|
+
*/
|
|
149
|
+
const fetchAssetBlobUrl = (fullUrl, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
try {
|
|
151
|
+
const result = yield fetch(fullUrl, {
|
|
152
|
+
method: "GET",
|
|
153
|
+
headers,
|
|
154
|
+
});
|
|
155
|
+
const blob = yield result.blob();
|
|
156
|
+
const assetUrl = URL.createObjectURL(blob);
|
|
157
|
+
return assetUrl;
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
115
164
|
const FilterBarContext = React.createContext(null);
|
|
116
165
|
/**
|
|
117
166
|
* This is a hook to use the FilterBarProvider.
|
|
@@ -264,36 +313,6 @@ const useModalDialogContext = () => {
|
|
|
264
313
|
return modalDialogContext;
|
|
265
314
|
};
|
|
266
315
|
|
|
267
|
-
/******************************************************************************
|
|
268
|
-
Copyright (c) Microsoft Corporation.
|
|
269
|
-
|
|
270
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
271
|
-
purpose with or without fee is hereby granted.
|
|
272
|
-
|
|
273
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
274
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
275
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
276
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
277
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
278
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
279
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
280
|
-
***************************************************************************** */
|
|
281
|
-
|
|
282
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
283
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
284
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
285
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
286
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
287
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
288
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
293
|
-
var e = new Error(message);
|
|
294
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
316
|
const NavigationContext = createContext(null);
|
|
298
317
|
/**
|
|
299
318
|
* This is a provider for the NavigationContext.
|
|
@@ -638,6 +657,15 @@ const useToast = () => {
|
|
|
638
657
|
return toastContext;
|
|
639
658
|
};
|
|
640
659
|
|
|
660
|
+
/**
|
|
661
|
+
* Returns the query string to be appended to the URL when the app is served from a Feature Branch.
|
|
662
|
+
*/
|
|
663
|
+
const useFeatureBranchQueryString = () => {
|
|
664
|
+
const { publicUrl, buildVersion } = useEnvironment();
|
|
665
|
+
const featureBranchQueryParam = useMemo(() => !publicUrl || publicUrl === "/" ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`, [publicUrl, buildVersion]);
|
|
666
|
+
return { featureBranchQueryParam };
|
|
667
|
+
};
|
|
668
|
+
|
|
641
669
|
/**
|
|
642
670
|
* Hook for filtering a list of items by text search, client side search in a list.
|
|
643
671
|
*
|
|
@@ -769,4 +797,4 @@ const useCurrentUser = () => {
|
|
|
769
797
|
return context;
|
|
770
798
|
};
|
|
771
799
|
|
|
772
|
-
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomerRuntime, useEnvironment, useEventRuntime, useFilterBarContext, useHasAccessTo, useImageUploader, useIrisAppId, useIrisAppName, useModalDialogContext, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
|
|
800
|
+
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, fetchAssetBlobUrl, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomerRuntime, useEnvironment, useEventRuntime, useFeatureBranchQueryString, useFilterBarContext, useHasAccessTo, useImageUploader, useIrisAppId, useIrisAppName, useModalDialogContext, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { BaseEvent, Event, IAnalyticsContext } from "@trackunit/react-core-contexts-api";
|
|
3
|
-
export declare const AnalyticsContext: import("react").Context<IAnalyticsContext<
|
|
4
|
-
export declare const AnalyticsContextProvider: import("react").Provider<IAnalyticsContext<
|
|
3
|
+
export declare const AnalyticsContext: import("react").Context<IAnalyticsContext<Record<string, never>> | null>;
|
|
4
|
+
export declare const AnalyticsContextProvider: import("react").Provider<IAnalyticsContext<Record<string, never>> | null>;
|
|
5
5
|
/**
|
|
6
6
|
* Hook to get the analytics context.
|
|
7
7
|
*
|
|
@@ -18,4 +18,4 @@ export declare const AnalyticsContextProvider: import("react").Provider<IAnalyti
|
|
|
18
18
|
* logEvent("Login", { loginPage: "New Manager" });
|
|
19
19
|
* @see {@link IAnalyticsContext}
|
|
20
20
|
*/
|
|
21
|
-
export declare const useAnalytics: <T extends Record<string, Event<BaseEvent | import("@trackunit/react-core-contexts-api").AdditionalProperties
|
|
21
|
+
export declare const useAnalytics: <T extends Record<string, Event<BaseEvent | import("@trackunit/react-core-contexts-api").AdditionalProperties>> = never>(type?: T) => IAnalyticsContext<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface GetIrisAppUrlParams {
|
|
2
|
+
irisAppId: string;
|
|
3
|
+
version: string;
|
|
4
|
+
}
|
|
5
|
+
interface GetImageAssetsParams {
|
|
6
|
+
irisAppUrl: string;
|
|
7
|
+
logoPath?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Provides functions to get the Iris App URL and logo image.
|
|
11
|
+
*
|
|
12
|
+
* @requires EnvironmentContextProvider, TokenProvider
|
|
13
|
+
* @returns {getAppUrl, getAppImage}
|
|
14
|
+
* @example
|
|
15
|
+
* const { getAppUrl, getAppImage } = useIrisAppImage();
|
|
16
|
+
* const irisAppUrl = getAppUrl({ irisAppId, version });
|
|
17
|
+
* const { logo } = await getAppImage({ irisAppUrl, logoPath });
|
|
18
|
+
*/
|
|
19
|
+
export declare const useIrisAppImage: () => {
|
|
20
|
+
getAppUrl: ({ irisAppId, version }: GetIrisAppUrlParams) => string;
|
|
21
|
+
getAppImage: ({ irisAppUrl, logoPath }: GetImageAssetsParams) => Promise<string | null>;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
package/src/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./analytics/AnalyticsProvider";
|
|
|
2
2
|
export * from "./assetSorting/AssetSortingProvider";
|
|
3
3
|
export * from "./confirmationDialog/ConfirmationDialogProvider";
|
|
4
4
|
export * from "./environment/EnvironmentContextProvider";
|
|
5
|
+
export * from "./fetchAssetBlobUrl";
|
|
5
6
|
export * from "./filter-bar/FilterBarProvider";
|
|
6
7
|
export * from "./images/useImageUploader";
|
|
7
8
|
export * from "./irisOemApp/IrisOemAppContextProvider";
|
|
@@ -15,6 +16,7 @@ export * from "./runtimes/useSiteRuntime";
|
|
|
15
16
|
export * from "./subscription/UserSubscriptionProvider";
|
|
16
17
|
export * from "./toast/ToastProvider";
|
|
17
18
|
export * from "./token/TokenProvider";
|
|
19
|
+
export * from "./useFeatureBranchQueryString";
|
|
18
20
|
export * from "./useTextSearch";
|
|
19
21
|
export * from "./user/CurrentUserPreferenceProvider";
|
|
20
22
|
export * from "./user/CurrentUserProvider";
|