@wix/essentials 0.1.19 → 0.1.21

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.
Files changed (54) hide show
  1. package/build/bi.d.ts +1 -0
  2. package/build/bi.js +10 -0
  3. package/build/error-handler.d.ts +5 -0
  4. package/build/error-handler.js +18 -0
  5. package/build/experiments.d.ts +1 -0
  6. package/build/experiments.js +28 -0
  7. package/build/http-client.d.ts +1 -12
  8. package/build/index.d.ts +4 -1
  9. package/build/index.js +4 -1
  10. package/cjs/build/bi.d.ts +1 -0
  11. package/cjs/build/bi.js +13 -0
  12. package/cjs/build/error-handler.d.ts +5 -0
  13. package/cjs/build/error-handler.js +21 -0
  14. package/cjs/build/experiments.d.ts +1 -0
  15. package/cjs/build/experiments.js +31 -0
  16. package/cjs/build/http-client.d.ts +1 -12
  17. package/cjs/build/index.d.ts +4 -1
  18. package/cjs/build/index.js +7 -1
  19. package/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  20. package/internal/build/auth.d.ts +66 -0
  21. package/internal/build/auth.js +72 -0
  22. package/internal/build/bi.d.ts +7 -0
  23. package/internal/build/bi.js +13 -0
  24. package/internal/build/error-handler.d.ts +7 -0
  25. package/internal/build/error-handler.js +21 -0
  26. package/internal/build/experiments.d.ts +12 -0
  27. package/internal/build/experiments.js +31 -0
  28. package/internal/build/http-client.d.ts +30 -0
  29. package/internal/build/http-client.js +24 -0
  30. package/internal/build/i18n.d.ts +7 -0
  31. package/internal/build/i18n.js +20 -0
  32. package/internal/build/index.d.ts +8 -0
  33. package/internal/build/index.js +50 -0
  34. package/internal/build/monitoring.d.ts +6 -0
  35. package/internal/build/monitoring.js +13 -0
  36. package/internal/cjs/build/auth.d.ts +66 -0
  37. package/internal/cjs/build/auth.js +68 -0
  38. package/internal/cjs/build/bi.d.ts +7 -0
  39. package/internal/cjs/build/bi.js +10 -0
  40. package/internal/cjs/build/error-handler.d.ts +7 -0
  41. package/internal/cjs/build/error-handler.js +18 -0
  42. package/internal/cjs/build/experiments.d.ts +12 -0
  43. package/internal/cjs/build/experiments.js +28 -0
  44. package/internal/cjs/build/http-client.d.ts +30 -0
  45. package/internal/cjs/build/http-client.js +21 -0
  46. package/internal/cjs/build/i18n.d.ts +7 -0
  47. package/internal/cjs/build/i18n.js +17 -0
  48. package/internal/cjs/build/index.d.ts +8 -0
  49. package/internal/cjs/build/index.js +8 -0
  50. package/internal/cjs/build/monitoring.d.ts +6 -0
  51. package/internal/cjs/build/monitoring.js +10 -0
  52. package/internal/cjs/tsconfig.internal.tsbuildinfo +1 -0
  53. package/internal/tsconfig.internal.cjs.tsbuildinfo +1 -0
  54. package/package.json +12 -11
package/build/bi.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/build/bi.js ADDED
@@ -0,0 +1,10 @@
1
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
2
+ /** @internal */
3
+ export const bi = createHostModule({
4
+ getLogger: (host) => () => {
5
+ if (!host.getBiLogger) {
6
+ throw new Error('Host bi logger is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
7
+ }
8
+ return host.getBiLogger();
9
+ },
10
+ });
@@ -0,0 +1,5 @@
1
+ import type { ResolvedError, ErrorCodesMap, ErrorHandler } from '@wix/sdk-types';
2
+ export declare const withErrorHandler: <T>(fn: () => Promise<T>, errorCodesMap: ErrorCodesMap) => Promise<T>;
3
+ export declare const getResolvedError: <T>(error: unknown) => ResolvedError & Partial<T>;
4
+ export declare const showError: (error: unknown, props?: Partial<import("@wix/error-handler-types/dist/types/v2/ShowError.js").ShowErrorProps> | null) => void;
5
+ export type { ErrorHandler, ResolvedError, ErrorCodesMap };
@@ -0,0 +1,18 @@
1
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
2
+ const getFromHostErrorHandlerOrDefault = (fn) => (host) => {
3
+ if (!host.getErrorHandler) {
4
+ throw new Error('Error handler is not available. Make sure to include the error handler in the host.');
5
+ }
6
+ return fn(host.getErrorHandler());
7
+ };
8
+ const errorHandler = createHostModule({
9
+ withErrorHandler: getFromHostErrorHandlerOrDefault((e) => e.withErrorHandler),
10
+ getResolvedError: getFromHostErrorHandlerOrDefault((e) => e.getResolvedError),
11
+ showError: getFromHostErrorHandlerOrDefault((e) => e.showError),
12
+ reportRetryAttempt: getFromHostErrorHandlerOrDefault((e) => e.reportRetryAttempt),
13
+ });
14
+ export const withErrorHandler = errorHandler.withErrorHandler;
15
+ export const getResolvedError = errorHandler.getResolvedError;
16
+ export const showError = errorHandler.showError;
17
+ /** @internal */
18
+ export const reportRetryAttempt = errorHandler.reportRetryAttempt;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
2
+ /** @internal */
3
+ export const experiments = createHostModule({
4
+ isEnabled_legacy: (host) => (specName) => {
5
+ if (!host.getPetriExperimentsClient) {
6
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
7
+ }
8
+ return host.getPetriExperimentsClient().enabled(specName);
9
+ },
10
+ getValue_legacy: (host) => (specName) => {
11
+ if (!host.getPetriExperimentsClient) {
12
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
13
+ }
14
+ return host.getPetriExperimentsClient().get(specName);
15
+ },
16
+ isFeatureOn: (host) => (featureName) => {
17
+ if (!host.getConductorClient) {
18
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
19
+ }
20
+ return host.getConductorClient().isFeatureOn(featureName);
21
+ },
22
+ getABTestVariant: (host) => (abTestName) => {
23
+ if (!host.getConductorClient) {
24
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
25
+ }
26
+ return host.getConductorClient().getABTestVariant(abTestName);
27
+ },
28
+ });
@@ -16,15 +16,4 @@ export type TypedQueryInput<Result = {
16
16
  [key: string]: any;
17
17
  }, Variables = {
18
18
  [key: string]: any;
19
- }> = {
20
- /**
21
- * Type to support `@graphql-typed-document-node/core`
22
- * @internal
23
- */
24
- __apiType?: (variables: Variables) => Result;
25
- /**
26
- * Type to support `TypedQueryDocumentNode` from `graphql`
27
- * @internal
28
- */
29
- __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
30
- };
19
+ }> = {};
package/build/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import * as auth from './auth.js';
2
2
  import * as httpClient from './http-client.js';
3
- export { auth, httpClient };
3
+ import * as errorHandler from './error-handler.js';
4
+ export { auth, httpClient, errorHandler };
4
5
  export { i18n } from './i18n.js';
5
6
  export { monitoring } from './monitoring.js';
7
+ export { bi } from './bi.js';
8
+ export { experiments } from './experiments.js';
package/build/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import * as auth from './auth.js';
2
2
  import * as httpClient from './http-client.js';
3
- export { auth, httpClient };
3
+ import * as errorHandler from './error-handler.js';
4
+ export { auth, httpClient, errorHandler };
4
5
  export { i18n } from './i18n.js';
5
6
  export { monitoring } from './monitoring.js';
7
+ export { bi } from './bi.js';
8
+ export { experiments } from './experiments.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bi = void 0;
4
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
5
+ /** @internal */
6
+ exports.bi = (0, host_modules_1.createHostModule)({
7
+ getLogger: (host) => () => {
8
+ if (!host.getBiLogger) {
9
+ throw new Error('Host bi logger is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
10
+ }
11
+ return host.getBiLogger();
12
+ },
13
+ });
@@ -0,0 +1,5 @@
1
+ import type { ResolvedError, ErrorCodesMap, ErrorHandler } from '@wix/sdk-types';
2
+ export declare const withErrorHandler: <T>(fn: () => Promise<T>, errorCodesMap: ErrorCodesMap) => Promise<T>;
3
+ export declare const getResolvedError: <T>(error: unknown) => ResolvedError & Partial<T>;
4
+ export declare const showError: (error: unknown, props?: Partial<import("@wix/error-handler-types/dist/types/v2").ShowErrorProps> | null) => void;
5
+ export type { ErrorHandler, ResolvedError, ErrorCodesMap };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reportRetryAttempt = exports.showError = exports.getResolvedError = exports.withErrorHandler = void 0;
4
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
5
+ const getFromHostErrorHandlerOrDefault = (fn) => (host) => {
6
+ if (!host.getErrorHandler) {
7
+ throw new Error('Error handler is not available. Make sure to include the error handler in the host.');
8
+ }
9
+ return fn(host.getErrorHandler());
10
+ };
11
+ const errorHandler = (0, host_modules_1.createHostModule)({
12
+ withErrorHandler: getFromHostErrorHandlerOrDefault((e) => e.withErrorHandler),
13
+ getResolvedError: getFromHostErrorHandlerOrDefault((e) => e.getResolvedError),
14
+ showError: getFromHostErrorHandlerOrDefault((e) => e.showError),
15
+ reportRetryAttempt: getFromHostErrorHandlerOrDefault((e) => e.reportRetryAttempt),
16
+ });
17
+ exports.withErrorHandler = errorHandler.withErrorHandler;
18
+ exports.getResolvedError = errorHandler.getResolvedError;
19
+ exports.showError = errorHandler.showError;
20
+ /** @internal */
21
+ exports.reportRetryAttempt = errorHandler.reportRetryAttempt;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.experiments = void 0;
4
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
5
+ /** @internal */
6
+ exports.experiments = (0, host_modules_1.createHostModule)({
7
+ isEnabled_legacy: (host) => (specName) => {
8
+ if (!host.getPetriExperimentsClient) {
9
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
10
+ }
11
+ return host.getPetriExperimentsClient().enabled(specName);
12
+ },
13
+ getValue_legacy: (host) => (specName) => {
14
+ if (!host.getPetriExperimentsClient) {
15
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
16
+ }
17
+ return host.getPetriExperimentsClient().get(specName);
18
+ },
19
+ isFeatureOn: (host) => (featureName) => {
20
+ if (!host.getConductorClient) {
21
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
22
+ }
23
+ return host.getConductorClient().isFeatureOn(featureName);
24
+ },
25
+ getABTestVariant: (host) => (abTestName) => {
26
+ if (!host.getConductorClient) {
27
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
28
+ }
29
+ return host.getConductorClient().getABTestVariant(abTestName);
30
+ },
31
+ });
@@ -16,15 +16,4 @@ export type TypedQueryInput<Result = {
16
16
  [key: string]: any;
17
17
  }, Variables = {
18
18
  [key: string]: any;
19
- }> = {
20
- /**
21
- * Type to support `@graphql-typed-document-node/core`
22
- * @internal
23
- */
24
- __apiType?: (variables: Variables) => Result;
25
- /**
26
- * Type to support `TypedQueryDocumentNode` from `graphql`
27
- * @internal
28
- */
29
- __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
30
- };
19
+ }> = {};
@@ -1,5 +1,8 @@
1
1
  import * as auth from './auth.js';
2
2
  import * as httpClient from './http-client.js';
3
- export { auth, httpClient };
3
+ import * as errorHandler from './error-handler.js';
4
+ export { auth, httpClient, errorHandler };
4
5
  export { i18n } from './i18n.js';
5
6
  export { monitoring } from './monitoring.js';
7
+ export { bi } from './bi.js';
8
+ export { experiments } from './experiments.js';
@@ -33,12 +33,18 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.monitoring = exports.i18n = exports.httpClient = exports.auth = void 0;
36
+ exports.experiments = exports.bi = exports.monitoring = exports.i18n = exports.errorHandler = exports.httpClient = exports.auth = void 0;
37
37
  const auth = __importStar(require("./auth.js"));
38
38
  exports.auth = auth;
39
39
  const httpClient = __importStar(require("./http-client.js"));
40
40
  exports.httpClient = httpClient;
41
+ const errorHandler = __importStar(require("./error-handler.js"));
42
+ exports.errorHandler = errorHandler;
41
43
  var i18n_js_1 = require("./i18n.js");
42
44
  Object.defineProperty(exports, "i18n", { enumerable: true, get: function () { return i18n_js_1.i18n; } });
43
45
  var monitoring_js_1 = require("./monitoring.js");
44
46
  Object.defineProperty(exports, "monitoring", { enumerable: true, get: function () { return monitoring_js_1.monitoring; } });
47
+ var bi_js_1 = require("./bi.js");
48
+ Object.defineProperty(exports, "bi", { enumerable: true, get: function () { return bi_js_1.bi; } });
49
+ var experiments_js_1 = require("./experiments.js");
50
+ Object.defineProperty(exports, "experiments", { enumerable: true, get: function () { return experiments_js_1.experiments; } });
@@ -0,0 +1 @@
1
+ {"root":["../src/auth.ts","../src/bi.ts","../src/error-handler.ts","../src/experiments.ts","../src/http-client.ts","../src/i18n.ts","../src/index.ts","../src/monitoring.ts"],"version":"5.8.3"}
@@ -0,0 +1,66 @@
1
+ export declare function elevate<T>(restModule: T): T;
2
+ /**
3
+ * Returns the information encoded in the currently active token in API backend extensions.
4
+ *
5
+ * When developing API backend extensions you might need to access information about the session that is making the request.
6
+ *
7
+ * This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
8
+ * and can be accessed using this function.
9
+ * @returns A promise that resolves to the token info.
10
+ * @example
11
+ * ```ts
12
+ * // In an API backend extension in a Wix CLI project
13
+ * import { auth } from '@wix/essentials';
14
+ *
15
+ * export async function GET(req: Request) {
16
+ * const tokenInfo = await auth.getTokenInfo();
17
+ *
18
+ * if (tokenInfo.subjectType === 'USER') {
19
+ * return new Response(`Hello user ${tokenInfo.subjectId}`);
20
+ * } else if (tokenInfo.subjectType === 'APP') {
21
+ * return new Response('Hello app');
22
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
23
+ * return new Response(`Hello member ${tokenInfo.subjectId}`);
24
+ * } else {
25
+ * return new Response(`Hello visitor ${tokenInfo.subjectId}`);
26
+ * }
27
+ * }
28
+ * ```
29
+ * @example
30
+ * ```ts
31
+ * // In a Velo web method
32
+ * import { auth } from '@wix/essentials';
33
+ * import { Permissions, webMethod } from 'wix-web-module';
34
+ *
35
+ * export const sayHello = webMethod(Permimissions.Anyone, async () => {
36
+ * const tokenInfo = await auth.getTokenInfo();
37
+ *
38
+ * if (tokenInfo.subjectType === 'USER') {
39
+ * return `Hello user ${tokenInfo.subjectId}`;
40
+ * } else if (tokenInfo.subjectType === 'APP') {
41
+ * return 'Hello app';
42
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
43
+ * return `Hello member ${tokenInfo.subjectId}`;
44
+ * } else {
45
+ * return `Hello visitor ${tokenInfo.subjectId}`;
46
+ * }
47
+ */
48
+ export declare const getTokenInfo: (() => Promise<{
49
+ active: boolean;
50
+ subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
51
+ subjectId: string;
52
+ exp: number;
53
+ iat: number;
54
+ clientId?: string;
55
+ siteId: string;
56
+ instanceId?: string;
57
+ }>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
58
+ active: boolean;
59
+ subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
60
+ subjectId: string;
61
+ exp: number;
62
+ iat: number;
63
+ clientId?: string;
64
+ siteId: string;
65
+ instanceId?: string;
66
+ }>);
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTokenInfo = void 0;
4
+ exports.elevate = elevate;
5
+ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
6
+ function elevate(restModule) {
7
+ return (0, rest_modules_1.createRESTModule)(restModule, true);
8
+ }
9
+ /**
10
+ * Returns the information encoded in the currently active token in API backend extensions.
11
+ *
12
+ * When developing API backend extensions you might need to access information about the session that is making the request.
13
+ *
14
+ * This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
15
+ * and can be accessed using this function.
16
+ * @returns A promise that resolves to the token info.
17
+ * @example
18
+ * ```ts
19
+ * // In an API backend extension in a Wix CLI project
20
+ * import { auth } from '@wix/essentials';
21
+ *
22
+ * export async function GET(req: Request) {
23
+ * const tokenInfo = await auth.getTokenInfo();
24
+ *
25
+ * if (tokenInfo.subjectType === 'USER') {
26
+ * return new Response(`Hello user ${tokenInfo.subjectId}`);
27
+ * } else if (tokenInfo.subjectType === 'APP') {
28
+ * return new Response('Hello app');
29
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
30
+ * return new Response(`Hello member ${tokenInfo.subjectId}`);
31
+ * } else {
32
+ * return new Response(`Hello visitor ${tokenInfo.subjectId}`);
33
+ * }
34
+ * }
35
+ * ```
36
+ * @example
37
+ * ```ts
38
+ * // In a Velo web method
39
+ * import { auth } from '@wix/essentials';
40
+ * import { Permissions, webMethod } from 'wix-web-module';
41
+ *
42
+ * export const sayHello = webMethod(Permimissions.Anyone, async () => {
43
+ * const tokenInfo = await auth.getTokenInfo();
44
+ *
45
+ * if (tokenInfo.subjectType === 'USER') {
46
+ * return `Hello user ${tokenInfo.subjectId}`;
47
+ * } else if (tokenInfo.subjectType === 'APP') {
48
+ * return 'Hello app';
49
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
50
+ * return `Hello member ${tokenInfo.subjectId}`;
51
+ * } else {
52
+ * return `Hello visitor ${tokenInfo.subjectId}`;
53
+ * }
54
+ */
55
+ exports.getTokenInfo = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
56
+ return async () => {
57
+ if (!restModuleOpts.getActiveToken) {
58
+ throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
59
+ }
60
+ const res = await fetch('https://www.wixapis.com/oauth2/token-info', {
61
+ method: 'POST',
62
+ body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
63
+ headers: {
64
+ 'Content-Type': 'application/json',
65
+ },
66
+ });
67
+ if (!res.ok) {
68
+ throw new Error(`Failed to fetch token info: ${res.status} - ${res.statusText}. ${await res.text()}`);
69
+ }
70
+ return res.json();
71
+ };
72
+ });
@@ -0,0 +1,7 @@
1
+ import type { Host } from '@wix/sdk-types';
2
+ /** @internal */
3
+ export declare const bi: {
4
+ getLogger: () => ReturnType<NonNullable<Host["getBiLogger"]>>;
5
+ } & import("@wix/sdk-types").HostModule<{
6
+ getLogger: () => ReturnType<NonNullable<Host["getBiLogger"]>>;
7
+ }, Host>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bi = void 0;
4
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
5
+ /** @internal */
6
+ exports.bi = (0, host_modules_1.createHostModule)({
7
+ getLogger: (host) => () => {
8
+ if (!host.getBiLogger) {
9
+ throw new Error('Host bi logger is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
10
+ }
11
+ return host.getBiLogger();
12
+ },
13
+ });
@@ -0,0 +1,7 @@
1
+ import type { ResolvedError, ErrorCodesMap, ErrorHandler } from '@wix/sdk-types';
2
+ export declare const withErrorHandler: <T>(fn: () => Promise<T>, errorCodesMap: ErrorCodesMap) => Promise<T>;
3
+ export declare const getResolvedError: <T>(error: unknown) => ResolvedError & Partial<T>;
4
+ export declare const showError: (error: unknown, props?: Partial<import("@wix/error-handler-types/dist/types/v2").ShowErrorProps> | null) => void;
5
+ /** @internal */
6
+ export declare const reportRetryAttempt: (error: unknown) => void;
7
+ export type { ErrorHandler, ResolvedError, ErrorCodesMap };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reportRetryAttempt = exports.showError = exports.getResolvedError = exports.withErrorHandler = void 0;
4
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
5
+ const getFromHostErrorHandlerOrDefault = (fn) => (host) => {
6
+ if (!host.getErrorHandler) {
7
+ throw new Error('Error handler is not available. Make sure to include the error handler in the host.');
8
+ }
9
+ return fn(host.getErrorHandler());
10
+ };
11
+ const errorHandler = (0, host_modules_1.createHostModule)({
12
+ withErrorHandler: getFromHostErrorHandlerOrDefault((e) => e.withErrorHandler),
13
+ getResolvedError: getFromHostErrorHandlerOrDefault((e) => e.getResolvedError),
14
+ showError: getFromHostErrorHandlerOrDefault((e) => e.showError),
15
+ reportRetryAttempt: getFromHostErrorHandlerOrDefault((e) => e.reportRetryAttempt),
16
+ });
17
+ exports.withErrorHandler = errorHandler.withErrorHandler;
18
+ exports.getResolvedError = errorHandler.getResolvedError;
19
+ exports.showError = errorHandler.showError;
20
+ /** @internal */
21
+ exports.reportRetryAttempt = errorHandler.reportRetryAttempt;
@@ -0,0 +1,12 @@
1
+ /** @internal */
2
+ export declare const experiments: {
3
+ isEnabled_legacy: (specName: string) => boolean;
4
+ getValue_legacy: (specName: string) => any;
5
+ isFeatureOn: (featureName: string) => boolean;
6
+ getABTestVariant: (abTestName: string) => "a" | "b" | "c" | "d" | "e";
7
+ } & import("@wix/sdk-types").HostModule<{
8
+ isEnabled_legacy: (specName: string) => boolean;
9
+ getValue_legacy: (specName: string) => any;
10
+ isFeatureOn: (featureName: string) => boolean;
11
+ getABTestVariant: (abTestName: string) => "a" | "b" | "c" | "d" | "e";
12
+ }, import("@wix/sdk-types").Host>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.experiments = void 0;
4
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
5
+ /** @internal */
6
+ exports.experiments = (0, host_modules_1.createHostModule)({
7
+ isEnabled_legacy: (host) => (specName) => {
8
+ if (!host.getPetriExperimentsClient) {
9
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
10
+ }
11
+ return host.getPetriExperimentsClient().enabled(specName);
12
+ },
13
+ getValue_legacy: (host) => (specName) => {
14
+ if (!host.getPetriExperimentsClient) {
15
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
16
+ }
17
+ return host.getPetriExperimentsClient().get(specName);
18
+ },
19
+ isFeatureOn: (host) => (featureName) => {
20
+ if (!host.getConductorClient) {
21
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
22
+ }
23
+ return host.getConductorClient().isFeatureOn(featureName);
24
+ },
25
+ getABTestVariant: (host) => (abTestName) => {
26
+ if (!host.getConductorClient) {
27
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
28
+ }
29
+ return host.getConductorClient().getABTestVariant(abTestName);
30
+ },
31
+ });
@@ -0,0 +1,30 @@
1
+ import { DocumentNode, GraphQLFormattedError } from 'graphql';
2
+ import { RESTFunctionDescriptor } from '@wix/sdk-types';
3
+ export declare const fetchWithAuth: typeof fetch & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => typeof fetch);
4
+ export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
5
+ apiVersion: string;
6
+ }) => Promise<{
7
+ data: Result;
8
+ errors?: GraphQLFormattedError[];
9
+ }>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
10
+ apiVersion: string;
11
+ }) => Promise<{
12
+ data: Result;
13
+ errors?: GraphQLFormattedError[];
14
+ }>)>;
15
+ export type TypedQueryInput<Result = {
16
+ [key: string]: any;
17
+ }, Variables = {
18
+ [key: string]: any;
19
+ }> = {
20
+ /**
21
+ * Type to support `@graphql-typed-document-node/core`
22
+ * @internal
23
+ */
24
+ __apiType?: (variables: Variables) => Result;
25
+ /**
26
+ * Type to support `TypedQueryDocumentNode` from `graphql`
27
+ * @internal
28
+ */
29
+ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
30
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphql = exports.fetchWithAuth = void 0;
4
+ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
5
+ exports.fetchWithAuth = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
6
+ return ((url, options) => restModuleOpts.fetchWithAuth(url, options));
7
+ });
8
+ exports.graphql = (0, rest_modules_1.createRESTModule)(((restModuleOpts) => {
9
+ // eslint-disable-next-line @typescript-eslint/no-shadow
10
+ return async function graphql(query, variables, opts = {
11
+ apiVersion: 'alpha',
12
+ }) {
13
+ const result = await restModuleOpts.request(({ host }) => {
14
+ const basePath = host === 'www.wixapis.com' ? '/graphql' : '/_api/graphql';
15
+ return {
16
+ method: 'POST',
17
+ url: `${basePath}/${opts.apiVersion}`,
18
+ data: { query, variables },
19
+ packageName: '@wix/essentials',
20
+ };
21
+ });
22
+ return result.data;
23
+ };
24
+ }));
@@ -0,0 +1,7 @@
1
+ export declare const i18n: {
2
+ getLanguage: () => string;
3
+ getLocale: () => string;
4
+ } & import("@wix/sdk-types").HostModule<{
5
+ getLanguage: () => string;
6
+ getLocale: () => string;
7
+ }, import("@wix/sdk-types").Host>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.i18n = void 0;
4
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
5
+ exports.i18n = (0, host_modules_1.createHostModule)({
6
+ getLanguage: (host) => () => {
7
+ const language = host.essentials?.language;
8
+ if (!language) {
9
+ throw new Error('Host language is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
10
+ }
11
+ return language;
12
+ },
13
+ getLocale: (host) => () => {
14
+ const locale = host.essentials?.locale;
15
+ if (!locale) {
16
+ throw new Error('Host locale is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
17
+ }
18
+ return locale;
19
+ },
20
+ });
@@ -0,0 +1,8 @@
1
+ import * as auth from './auth.js';
2
+ import * as httpClient from './http-client.js';
3
+ import * as errorHandler from './error-handler.js';
4
+ export { auth, httpClient, errorHandler };
5
+ export { i18n } from './i18n.js';
6
+ export { monitoring } from './monitoring.js';
7
+ export { bi } from './bi.js';
8
+ export { experiments } from './experiments.js';
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.experiments = exports.bi = exports.monitoring = exports.i18n = exports.errorHandler = exports.httpClient = exports.auth = void 0;
37
+ const auth = __importStar(require("./auth.js"));
38
+ exports.auth = auth;
39
+ const httpClient = __importStar(require("./http-client.js"));
40
+ exports.httpClient = httpClient;
41
+ const errorHandler = __importStar(require("./error-handler.js"));
42
+ exports.errorHandler = errorHandler;
43
+ var i18n_js_1 = require("./i18n.js");
44
+ Object.defineProperty(exports, "i18n", { enumerable: true, get: function () { return i18n_js_1.i18n; } });
45
+ var monitoring_js_1 = require("./monitoring.js");
46
+ Object.defineProperty(exports, "monitoring", { enumerable: true, get: function () { return monitoring_js_1.monitoring; } });
47
+ var bi_js_1 = require("./bi.js");
48
+ Object.defineProperty(exports, "bi", { enumerable: true, get: function () { return bi_js_1.bi; } });
49
+ var experiments_js_1 = require("./experiments.js");
50
+ Object.defineProperty(exports, "experiments", { enumerable: true, get: function () { return experiments_js_1.experiments; } });
@@ -0,0 +1,6 @@
1
+ import type { Host } from '@wix/sdk-types';
2
+ export declare const monitoring: {
3
+ getMonitoringClient: () => ReturnType<NonNullable<Host["getMonitoringClient"]>>;
4
+ } & import("@wix/sdk-types").HostModule<{
5
+ getMonitoringClient: () => ReturnType<NonNullable<Host["getMonitoringClient"]>>;
6
+ }, Host>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.monitoring = void 0;
4
+ const monitoring_1 = require("@wix/monitoring");
5
+ const host_modules_1 = require("@wix/sdk-runtime/host-modules");
6
+ exports.monitoring = (0, host_modules_1.createHostModule)({
7
+ getMonitoringClient: (host) => () => {
8
+ if (!host.getMonitoringClient) {
9
+ return (0, monitoring_1.createFallbackMonitoringClient)('Host monitoring client is not available on the current host. Make sure to use an updated version of the host initialization package.');
10
+ }
11
+ return host.getMonitoringClient();
12
+ },
13
+ });
@@ -0,0 +1,66 @@
1
+ export declare function elevate<T>(restModule: T): T;
2
+ /**
3
+ * Returns the information encoded in the currently active token in API backend extensions.
4
+ *
5
+ * When developing API backend extensions you might need to access information about the session that is making the request.
6
+ *
7
+ * This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
8
+ * and can be accessed using this function.
9
+ * @returns A promise that resolves to the token info.
10
+ * @example
11
+ * ```ts
12
+ * // In an API backend extension in a Wix CLI project
13
+ * import { auth } from '@wix/essentials';
14
+ *
15
+ * export async function GET(req: Request) {
16
+ * const tokenInfo = await auth.getTokenInfo();
17
+ *
18
+ * if (tokenInfo.subjectType === 'USER') {
19
+ * return new Response(`Hello user ${tokenInfo.subjectId}`);
20
+ * } else if (tokenInfo.subjectType === 'APP') {
21
+ * return new Response('Hello app');
22
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
23
+ * return new Response(`Hello member ${tokenInfo.subjectId}`);
24
+ * } else {
25
+ * return new Response(`Hello visitor ${tokenInfo.subjectId}`);
26
+ * }
27
+ * }
28
+ * ```
29
+ * @example
30
+ * ```ts
31
+ * // In a Velo web method
32
+ * import { auth } from '@wix/essentials';
33
+ * import { Permissions, webMethod } from 'wix-web-module';
34
+ *
35
+ * export const sayHello = webMethod(Permimissions.Anyone, async () => {
36
+ * const tokenInfo = await auth.getTokenInfo();
37
+ *
38
+ * if (tokenInfo.subjectType === 'USER') {
39
+ * return `Hello user ${tokenInfo.subjectId}`;
40
+ * } else if (tokenInfo.subjectType === 'APP') {
41
+ * return 'Hello app';
42
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
43
+ * return `Hello member ${tokenInfo.subjectId}`;
44
+ * } else {
45
+ * return `Hello visitor ${tokenInfo.subjectId}`;
46
+ * }
47
+ */
48
+ export declare const getTokenInfo: (() => Promise<{
49
+ active: boolean;
50
+ subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
51
+ subjectId: string;
52
+ exp: number;
53
+ iat: number;
54
+ clientId?: string;
55
+ siteId: string;
56
+ instanceId?: string;
57
+ }>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
58
+ active: boolean;
59
+ subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
60
+ subjectId: string;
61
+ exp: number;
62
+ iat: number;
63
+ clientId?: string;
64
+ siteId: string;
65
+ instanceId?: string;
66
+ }>);
@@ -0,0 +1,68 @@
1
+ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
2
+ export function elevate(restModule) {
3
+ return createRESTModule(restModule, true);
4
+ }
5
+ /**
6
+ * Returns the information encoded in the currently active token in API backend extensions.
7
+ *
8
+ * When developing API backend extensions you might need to access information about the session that is making the request.
9
+ *
10
+ * This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
11
+ * and can be accessed using this function.
12
+ * @returns A promise that resolves to the token info.
13
+ * @example
14
+ * ```ts
15
+ * // In an API backend extension in a Wix CLI project
16
+ * import { auth } from '@wix/essentials';
17
+ *
18
+ * export async function GET(req: Request) {
19
+ * const tokenInfo = await auth.getTokenInfo();
20
+ *
21
+ * if (tokenInfo.subjectType === 'USER') {
22
+ * return new Response(`Hello user ${tokenInfo.subjectId}`);
23
+ * } else if (tokenInfo.subjectType === 'APP') {
24
+ * return new Response('Hello app');
25
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
26
+ * return new Response(`Hello member ${tokenInfo.subjectId}`);
27
+ * } else {
28
+ * return new Response(`Hello visitor ${tokenInfo.subjectId}`);
29
+ * }
30
+ * }
31
+ * ```
32
+ * @example
33
+ * ```ts
34
+ * // In a Velo web method
35
+ * import { auth } from '@wix/essentials';
36
+ * import { Permissions, webMethod } from 'wix-web-module';
37
+ *
38
+ * export const sayHello = webMethod(Permimissions.Anyone, async () => {
39
+ * const tokenInfo = await auth.getTokenInfo();
40
+ *
41
+ * if (tokenInfo.subjectType === 'USER') {
42
+ * return `Hello user ${tokenInfo.subjectId}`;
43
+ * } else if (tokenInfo.subjectType === 'APP') {
44
+ * return 'Hello app';
45
+ * } else if (tokenInfo.subjectType === 'MEMBER') {
46
+ * return `Hello member ${tokenInfo.subjectId}`;
47
+ * } else {
48
+ * return `Hello visitor ${tokenInfo.subjectId}`;
49
+ * }
50
+ */
51
+ export const getTokenInfo = createRESTModule((restModuleOpts) => {
52
+ return async () => {
53
+ if (!restModuleOpts.getActiveToken) {
54
+ throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
55
+ }
56
+ const res = await fetch('https://www.wixapis.com/oauth2/token-info', {
57
+ method: 'POST',
58
+ body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
59
+ headers: {
60
+ 'Content-Type': 'application/json',
61
+ },
62
+ });
63
+ if (!res.ok) {
64
+ throw new Error(`Failed to fetch token info: ${res.status} - ${res.statusText}. ${await res.text()}`);
65
+ }
66
+ return res.json();
67
+ };
68
+ });
@@ -0,0 +1,7 @@
1
+ import type { Host } from '@wix/sdk-types';
2
+ /** @internal */
3
+ export declare const bi: {
4
+ getLogger: () => ReturnType<NonNullable<Host["getBiLogger"]>>;
5
+ } & import("@wix/sdk-types").HostModule<{
6
+ getLogger: () => ReturnType<NonNullable<Host["getBiLogger"]>>;
7
+ }, Host>;
@@ -0,0 +1,10 @@
1
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
2
+ /** @internal */
3
+ export const bi = createHostModule({
4
+ getLogger: (host) => () => {
5
+ if (!host.getBiLogger) {
6
+ throw new Error('Host bi logger is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
7
+ }
8
+ return host.getBiLogger();
9
+ },
10
+ });
@@ -0,0 +1,7 @@
1
+ import type { ResolvedError, ErrorCodesMap, ErrorHandler } from '@wix/sdk-types';
2
+ export declare const withErrorHandler: <T>(fn: () => Promise<T>, errorCodesMap: ErrorCodesMap) => Promise<T>;
3
+ export declare const getResolvedError: <T>(error: unknown) => ResolvedError & Partial<T>;
4
+ export declare const showError: (error: unknown, props?: Partial<import("@wix/error-handler-types/dist/types/v2/ShowError.js").ShowErrorProps> | null) => void;
5
+ /** @internal */
6
+ export declare const reportRetryAttempt: (error: unknown) => void;
7
+ export type { ErrorHandler, ResolvedError, ErrorCodesMap };
@@ -0,0 +1,18 @@
1
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
2
+ const getFromHostErrorHandlerOrDefault = (fn) => (host) => {
3
+ if (!host.getErrorHandler) {
4
+ throw new Error('Error handler is not available. Make sure to include the error handler in the host.');
5
+ }
6
+ return fn(host.getErrorHandler());
7
+ };
8
+ const errorHandler = createHostModule({
9
+ withErrorHandler: getFromHostErrorHandlerOrDefault((e) => e.withErrorHandler),
10
+ getResolvedError: getFromHostErrorHandlerOrDefault((e) => e.getResolvedError),
11
+ showError: getFromHostErrorHandlerOrDefault((e) => e.showError),
12
+ reportRetryAttempt: getFromHostErrorHandlerOrDefault((e) => e.reportRetryAttempt),
13
+ });
14
+ export const withErrorHandler = errorHandler.withErrorHandler;
15
+ export const getResolvedError = errorHandler.getResolvedError;
16
+ export const showError = errorHandler.showError;
17
+ /** @internal */
18
+ export const reportRetryAttempt = errorHandler.reportRetryAttempt;
@@ -0,0 +1,12 @@
1
+ /** @internal */
2
+ export declare const experiments: {
3
+ isEnabled_legacy: (specName: string) => boolean;
4
+ getValue_legacy: (specName: string) => any;
5
+ isFeatureOn: (featureName: string) => boolean;
6
+ getABTestVariant: (abTestName: string) => "a" | "b" | "c" | "d" | "e";
7
+ } & import("@wix/sdk-types").HostModule<{
8
+ isEnabled_legacy: (specName: string) => boolean;
9
+ getValue_legacy: (specName: string) => any;
10
+ isFeatureOn: (featureName: string) => boolean;
11
+ getABTestVariant: (abTestName: string) => "a" | "b" | "c" | "d" | "e";
12
+ }, import("@wix/sdk-types").Host>;
@@ -0,0 +1,28 @@
1
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
2
+ /** @internal */
3
+ export const experiments = createHostModule({
4
+ isEnabled_legacy: (host) => (specName) => {
5
+ if (!host.getPetriExperimentsClient) {
6
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
7
+ }
8
+ return host.getPetriExperimentsClient().enabled(specName);
9
+ },
10
+ getValue_legacy: (host) => (specName) => {
11
+ if (!host.getPetriExperimentsClient) {
12
+ throw new Error('Host "PetriExperiments" are not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
13
+ }
14
+ return host.getPetriExperimentsClient().get(specName);
15
+ },
16
+ isFeatureOn: (host) => (featureName) => {
17
+ if (!host.getConductorClient) {
18
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
19
+ }
20
+ return host.getConductorClient().isFeatureOn(featureName);
21
+ },
22
+ getABTestVariant: (host) => (abTestName) => {
23
+ if (!host.getConductorClient) {
24
+ throw new Error('Host conductor client is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
25
+ }
26
+ return host.getConductorClient().getABTestVariant(abTestName);
27
+ },
28
+ });
@@ -0,0 +1,30 @@
1
+ import { DocumentNode, GraphQLFormattedError } from 'graphql';
2
+ import { RESTFunctionDescriptor } from '@wix/sdk-types';
3
+ export declare const fetchWithAuth: typeof fetch & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => typeof fetch);
4
+ export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
5
+ apiVersion: string;
6
+ }) => Promise<{
7
+ data: Result;
8
+ errors?: GraphQLFormattedError[];
9
+ }>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
10
+ apiVersion: string;
11
+ }) => Promise<{
12
+ data: Result;
13
+ errors?: GraphQLFormattedError[];
14
+ }>)>;
15
+ export type TypedQueryInput<Result = {
16
+ [key: string]: any;
17
+ }, Variables = {
18
+ [key: string]: any;
19
+ }> = {
20
+ /**
21
+ * Type to support `@graphql-typed-document-node/core`
22
+ * @internal
23
+ */
24
+ __apiType?: (variables: Variables) => Result;
25
+ /**
26
+ * Type to support `TypedQueryDocumentNode` from `graphql`
27
+ * @internal
28
+ */
29
+ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
30
+ };
@@ -0,0 +1,21 @@
1
+ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
2
+ export const fetchWithAuth = createRESTModule((restModuleOpts) => {
3
+ return ((url, options) => restModuleOpts.fetchWithAuth(url, options));
4
+ });
5
+ export const graphql = createRESTModule(((restModuleOpts) => {
6
+ // eslint-disable-next-line @typescript-eslint/no-shadow
7
+ return async function graphql(query, variables, opts = {
8
+ apiVersion: 'alpha',
9
+ }) {
10
+ const result = await restModuleOpts.request(({ host }) => {
11
+ const basePath = host === 'www.wixapis.com' ? '/graphql' : '/_api/graphql';
12
+ return {
13
+ method: 'POST',
14
+ url: `${basePath}/${opts.apiVersion}`,
15
+ data: { query, variables },
16
+ packageName: '@wix/essentials',
17
+ };
18
+ });
19
+ return result.data;
20
+ };
21
+ }));
@@ -0,0 +1,7 @@
1
+ export declare const i18n: {
2
+ getLanguage: () => string;
3
+ getLocale: () => string;
4
+ } & import("@wix/sdk-types").HostModule<{
5
+ getLanguage: () => string;
6
+ getLocale: () => string;
7
+ }, import("@wix/sdk-types").Host>;
@@ -0,0 +1,17 @@
1
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
2
+ export const i18n = createHostModule({
3
+ getLanguage: (host) => () => {
4
+ const language = host.essentials?.language;
5
+ if (!language) {
6
+ throw new Error('Host language is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
7
+ }
8
+ return language;
9
+ },
10
+ getLocale: (host) => () => {
11
+ const locale = host.essentials?.locale;
12
+ if (!locale) {
13
+ throw new Error('Host locale is not available on the current host. Make sure to use an updated version of the host initialization pacakge.');
14
+ }
15
+ return locale;
16
+ },
17
+ });
@@ -0,0 +1,8 @@
1
+ import * as auth from './auth.js';
2
+ import * as httpClient from './http-client.js';
3
+ import * as errorHandler from './error-handler.js';
4
+ export { auth, httpClient, errorHandler };
5
+ export { i18n } from './i18n.js';
6
+ export { monitoring } from './monitoring.js';
7
+ export { bi } from './bi.js';
8
+ export { experiments } from './experiments.js';
@@ -0,0 +1,8 @@
1
+ import * as auth from './auth.js';
2
+ import * as httpClient from './http-client.js';
3
+ import * as errorHandler from './error-handler.js';
4
+ export { auth, httpClient, errorHandler };
5
+ export { i18n } from './i18n.js';
6
+ export { monitoring } from './monitoring.js';
7
+ export { bi } from './bi.js';
8
+ export { experiments } from './experiments.js';
@@ -0,0 +1,6 @@
1
+ import type { Host } from '@wix/sdk-types';
2
+ export declare const monitoring: {
3
+ getMonitoringClient: () => ReturnType<NonNullable<Host["getMonitoringClient"]>>;
4
+ } & import("@wix/sdk-types").HostModule<{
5
+ getMonitoringClient: () => ReturnType<NonNullable<Host["getMonitoringClient"]>>;
6
+ }, Host>;
@@ -0,0 +1,10 @@
1
+ import { createFallbackMonitoringClient } from '@wix/monitoring';
2
+ import { createHostModule } from '@wix/sdk-runtime/host-modules';
3
+ export const monitoring = createHostModule({
4
+ getMonitoringClient: (host) => () => {
5
+ if (!host.getMonitoringClient) {
6
+ return createFallbackMonitoringClient('Host monitoring client is not available on the current host. Make sure to use an updated version of the host initialization package.');
7
+ }
8
+ return host.getMonitoringClient();
9
+ },
10
+ });
@@ -0,0 +1 @@
1
+ {"root":["../../src/auth.ts","../../src/bi.ts","../../src/error-handler.ts","../../src/experiments.ts","../../src/http-client.ts","../../src/i18n.ts","../../src/index.ts","../../src/monitoring.ts"],"version":"5.8.3"}
@@ -0,0 +1 @@
1
+ {"root":["../src/auth.ts","../src/bi.ts","../src/error-handler.ts","../src/experiments.ts","../src/http-client.ts","../src/i18n.ts","../src/index.ts","../src/monitoring.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/essentials",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "license": "MIT",
5
5
  "main": "cjs/build/index.js",
6
6
  "module": "build/index.mjs",
@@ -18,14 +18,15 @@
18
18
  ],
19
19
  "files": [
20
20
  "build",
21
- "cjs"
21
+ "cjs",
22
+ "internal"
22
23
  ],
23
24
  "publishConfig": {
24
25
  "registry": "https://registry.npmjs.org/",
25
26
  "access": "public"
26
27
  },
27
28
  "scripts": {
28
- "build": "tsc && tsc --project tsconfig.cjs.json",
29
+ "build": "tsc -b tsconfig.json tsconfig.cjs.json tsconfig.internal.json tsconfig.internal.cjs.json",
29
30
  "test": "vitest",
30
31
  "lint": "eslint --max-warnings=0 .",
31
32
  "lint:fix": "eslint --max-warnings=0 . --fix",
@@ -35,25 +36,25 @@
35
36
  "*.{js,ts}": "yarn lint"
36
37
  },
37
38
  "dependencies": {
38
- "@wix/monitoring": "^0.18.0",
39
- "@wix/sdk-runtime": "^0.3.38",
40
- "@wix/sdk-types": "^1.13.6"
39
+ "@wix/monitoring": "^0.21.0",
40
+ "@wix/sdk-runtime": "^0.3.52",
41
+ "@wix/sdk-types": "^1.13.25"
41
42
  },
42
43
  "optionalDependencies": {
43
44
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@types/is-ci": "^3.0.4",
47
- "@types/node": "^20.17.22",
48
+ "@types/node": "^20.17.47",
48
49
  "@vitest/ui": "^1.6.1",
49
- "@wix/sdk": "1.15.12",
50
+ "@wix/sdk": "1.15.22",
50
51
  "eslint": "^8.57.1",
51
52
  "eslint-config-sdk": "0.0.0",
52
53
  "graphql": "^16.8.0",
53
54
  "is-ci": "^3.0.1",
54
55
  "jsdom": "^22.1.0",
55
- "msw": "^2.7.3",
56
- "typescript": "^5.8.2",
56
+ "msw": "^2.8.3",
57
+ "typescript": "^5.8.3",
57
58
  "vitest": "^1.6.1",
58
59
  "vitest-teamcity-reporter": "^0.3.1"
59
60
  },
@@ -74,5 +75,5 @@
74
75
  ]
75
76
  }
76
77
  },
77
- "falconPackageHash": "db0e3821e8879a032b11ffe4a48267b2b48a65c18f2a0686aa744371"
78
+ "falconPackageHash": "acf8fdc9a191264c4e3c35fe2f1770f1722dffc7057ea2dd52c0380f"
78
79
  }