@wix/sdk-react 0.3.8 → 0.4.1

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.
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.tsx
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ WixProvider: () => WixProvider,
35
+ useEnvironment: () => useEnvironment,
36
+ useWix: () => useWix,
37
+ useWixAuth: () => useWixAuth,
38
+ useWixFetch: () => useWixFetch,
39
+ useWixModules: () => useWixModules
40
+ });
41
+ module.exports = __toCommonJS(src_exports);
42
+ var import_sdk = require("@wix/sdk");
43
+ var React = __toESM(require("react"), 1);
44
+ var import_react = require("react");
45
+ __reExport(src_exports, require("@wix/sdk"), module.exports);
46
+ var WixContext = (0, import_react.createContext)(void 0);
47
+ var HostEnvironmentContext = (0, import_react.createContext)(void 0);
48
+ function WixProvider(props) {
49
+ const { children, auth, modules, host } = props;
50
+ const client = (0, import_react.useMemo)(
51
+ () => (0, import_sdk.createClient)({
52
+ auth,
53
+ modules,
54
+ host
55
+ }),
56
+ [auth, modules, host]
57
+ );
58
+ return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, host ? /* @__PURE__ */ React.createElement(HostEnvironmentProvider, { host }, children) : children);
59
+ }
60
+ function HostEnvironmentProvider(props) {
61
+ const [environment, setEnvironment] = React.useState(null);
62
+ (0, import_react.useEffect)(() => {
63
+ if (props.host.environment) {
64
+ setEnvironment(props.host.environment);
65
+ } else {
66
+ const handle = props.host.channel.observeState(
67
+ (_, env) => setEnvironment(env)
68
+ );
69
+ return () => {
70
+ Promise.resolve(handle).then((h) => h.disconnect());
71
+ };
72
+ }
73
+ }, [props.host.environment, props.host.channel]);
74
+ if (!environment) {
75
+ return null;
76
+ }
77
+ return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
78
+ }
79
+ function useWix() {
80
+ const sdk = React.useContext(WixContext);
81
+ if (!sdk) {
82
+ throw new Error(
83
+ "SDK context not found. Make sure to render SDKProvider in the component tree"
84
+ );
85
+ }
86
+ return sdk;
87
+ }
88
+ function useWixFetch() {
89
+ const sdk = useWix();
90
+ return sdk.fetch;
91
+ }
92
+ function useWixAuth() {
93
+ const sdk = useWix();
94
+ return sdk.auth;
95
+ }
96
+ function useWixModules(modules) {
97
+ const sdk = useWix();
98
+ return (0, import_react.useMemo)(() => sdk.use(modules), [sdk, modules]);
99
+ }
100
+ function useEnvironment() {
101
+ const environment = React.useContext(HostEnvironmentContext);
102
+ if (!environment) {
103
+ throw new Error(
104
+ "Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
105
+ );
106
+ }
107
+ return environment;
108
+ }
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ WixProvider,
112
+ useEnvironment,
113
+ useWix,
114
+ useWixAuth,
115
+ useWixFetch,
116
+ useWixModules,
117
+ ...require("@wix/sdk")
118
+ });
package/build/index.js CHANGED
@@ -1,54 +1,16 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
1
  // src/index.tsx
32
- var src_exports = {};
33
- __export(src_exports, {
34
- WixProvider: () => WixProvider,
35
- useEnvironment: () => useEnvironment,
36
- useWix: () => useWix,
37
- useWixAuth: () => useWixAuth,
38
- useWixFetch: () => useWixFetch,
39
- useWixModules: () => useWixModules
40
- });
41
- module.exports = __toCommonJS(src_exports);
42
- var import_sdk = require("@wix/sdk");
43
- var React = __toESM(require("react"));
44
- var import_react = require("react");
45
- __reExport(src_exports, require("@wix/sdk"), module.exports);
46
- var WixContext = (0, import_react.createContext)(void 0);
47
- var HostEnvironmentContext = (0, import_react.createContext)(void 0);
2
+ import {
3
+ createClient
4
+ } from "@wix/sdk";
5
+ import * as React from "react";
6
+ import { createContext, useEffect, useMemo } from "react";
7
+ export * from "@wix/sdk";
8
+ var WixContext = createContext(void 0);
9
+ var HostEnvironmentContext = createContext(void 0);
48
10
  function WixProvider(props) {
49
11
  const { children, auth, modules, host } = props;
50
- const client = (0, import_react.useMemo)(
51
- () => (0, import_sdk.createClient)({
12
+ const client = useMemo(
13
+ () => createClient({
52
14
  auth,
53
15
  modules,
54
16
  host
@@ -59,7 +21,7 @@ function WixProvider(props) {
59
21
  }
60
22
  function HostEnvironmentProvider(props) {
61
23
  const [environment, setEnvironment] = React.useState(null);
62
- (0, import_react.useEffect)(() => {
24
+ useEffect(() => {
63
25
  if (props.host.environment) {
64
26
  setEnvironment(props.host.environment);
65
27
  } else {
@@ -95,7 +57,7 @@ function useWixAuth() {
95
57
  }
96
58
  function useWixModules(modules) {
97
59
  const sdk = useWix();
98
- return (0, import_react.useMemo)(() => sdk.use(modules), [sdk, modules]);
60
+ return useMemo(() => sdk.use(modules), [sdk, modules]);
99
61
  }
100
62
  function useEnvironment() {
101
63
  const environment = React.useContext(HostEnvironmentContext);
@@ -106,13 +68,11 @@ function useEnvironment() {
106
68
  }
107
69
  return environment;
108
70
  }
109
- // Annotate the CommonJS export names for ESM import in node:
110
- 0 && (module.exports = {
71
+ export {
111
72
  WixProvider,
112
73
  useEnvironment,
113
74
  useWix,
114
75
  useWixAuth,
115
76
  useWixFetch,
116
- useWixModules,
117
- ...require("@wix/sdk")
118
- });
77
+ useWixModules
78
+ };
package/package.json CHANGED
@@ -1,12 +1,21 @@
1
1
  {
2
2
  "name": "@wix/sdk-react",
3
- "version": "0.3.8",
3
+ "version": "0.4.1",
4
4
  "license": "UNLICENSED",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.mjs",
7
7
  "browser": "build/browser/index.mjs",
8
8
  "sideEffects": false,
9
9
  "types": "build/index.d.ts",
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./build/index.mjs",
14
+ "browser": "./build/browser/index.mjs",
15
+ "require": "./build/index.js",
16
+ "types": "./build/index.d.mts"
17
+ }
18
+ },
10
19
  "files": [
11
20
  "build"
12
21
  ],
@@ -21,7 +30,7 @@
21
30
  "typecheck": "tsc --noEmit"
22
31
  },
23
32
  "dependencies": {
24
- "@wix/sdk": "^1.5.9"
33
+ "@wix/sdk": "^1.6.2"
25
34
  },
26
35
  "peerDependencies": {
27
36
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0"
@@ -29,9 +38,9 @@
29
38
  "devDependencies": {
30
39
  "@testing-library/jest-dom": "^6.1.5",
31
40
  "@testing-library/react": "^14.1.2",
32
- "@types/react": "^18.2.42",
33
- "@wix/ecom": "^1.0.385",
34
- "eslint": "^7.32.0",
41
+ "@types/react": "^18.2.45",
42
+ "@wix/ecom": "^1.0.435",
43
+ "eslint": "^8.56.0",
35
44
  "eslint-config-sdk": "0.0.0",
36
45
  "is-ci": "^3.0.1",
37
46
  "jsdom": "^22.1.0",
@@ -40,7 +49,7 @@
40
49
  "tsup": "^7.3.0",
41
50
  "typescript": "^5.3.3",
42
51
  "vitest": "^0.34.6",
43
- "vitest-teamcity-reporter": "^0.2.1"
52
+ "vitest-teamcity-reporter": "^0.2.2"
44
53
  },
45
54
  "wix": {
46
55
  "artifact": {
@@ -59,5 +68,5 @@
59
68
  "eslintConfig": {
60
69
  "extends": "sdk"
61
70
  },
62
- "falconPackageHash": "6241d4e72c07dc46a1b7d5147b6bb88be5257d9e774395ccd7dafd84"
71
+ "falconPackageHash": "b57c9fb8c4d6e1e770cd6db92ec18be2fb85d4826262c05a89547e83"
63
72
  }
package/build/index.mjs DELETED
@@ -1,78 +0,0 @@
1
- // src/index.tsx
2
- import {
3
- createClient
4
- } from "@wix/sdk";
5
- import * as React from "react";
6
- import { createContext, useEffect, useMemo } from "react";
7
- export * from "@wix/sdk";
8
- var WixContext = createContext(void 0);
9
- var HostEnvironmentContext = createContext(void 0);
10
- function WixProvider(props) {
11
- const { children, auth, modules, host } = props;
12
- const client = useMemo(
13
- () => createClient({
14
- auth,
15
- modules,
16
- host
17
- }),
18
- [auth, modules, host]
19
- );
20
- return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, host ? /* @__PURE__ */ React.createElement(HostEnvironmentProvider, { host }, children) : children);
21
- }
22
- function HostEnvironmentProvider(props) {
23
- const [environment, setEnvironment] = React.useState(null);
24
- useEffect(() => {
25
- if (props.host.environment) {
26
- setEnvironment(props.host.environment);
27
- } else {
28
- const handle = props.host.channel.observeState(
29
- (_, env) => setEnvironment(env)
30
- );
31
- return () => {
32
- Promise.resolve(handle).then((h) => h.disconnect());
33
- };
34
- }
35
- }, [props.host.environment, props.host.channel]);
36
- if (!environment) {
37
- return null;
38
- }
39
- return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
40
- }
41
- function useWix() {
42
- const sdk = React.useContext(WixContext);
43
- if (!sdk) {
44
- throw new Error(
45
- "SDK context not found. Make sure to render SDKProvider in the component tree"
46
- );
47
- }
48
- return sdk;
49
- }
50
- function useWixFetch() {
51
- const sdk = useWix();
52
- return sdk.fetch;
53
- }
54
- function useWixAuth() {
55
- const sdk = useWix();
56
- return sdk.auth;
57
- }
58
- function useWixModules(modules) {
59
- const sdk = useWix();
60
- return useMemo(() => sdk.use(modules), [sdk, modules]);
61
- }
62
- function useEnvironment() {
63
- const environment = React.useContext(HostEnvironmentContext);
64
- if (!environment) {
65
- throw new Error(
66
- "Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
67
- );
68
- }
69
- return environment;
70
- }
71
- export {
72
- WixProvider,
73
- useEnvironment,
74
- useWix,
75
- useWixAuth,
76
- useWixFetch,
77
- useWixModules
78
- };
File without changes
File without changes