@wix/sdk 1.2.5 → 1.2.6

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.
@@ -11,6 +11,12 @@ var getDefaultContentHeader = (options) => {
11
11
  };
12
12
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
13
13
 
14
+ // src/host-modules.ts
15
+ var isHostModule = (val) => isObject(val) && val.__type === "host";
16
+ function buildHostModule(val, host) {
17
+ return val.create(host);
18
+ }
19
+
14
20
  // src/bi/biHeaderGenerator.ts
15
21
  var WixBIHeaderName = "x-wix-bi-gateway";
16
22
  function biHeaderGenerator(apiMetadata, publicMetadata) {
@@ -102,12 +108,6 @@ var errorBuilder = (code, description, details, data) => {
102
108
  };
103
109
  };
104
110
 
105
- // src/host-modules.ts
106
- var isHostModule = (val) => isObject(val) && val.__type === "host";
107
- function buildHostModule(val, host) {
108
- return val.create(host);
109
- }
110
-
111
111
  // src/wixClient.ts
112
112
  function createClient(config) {
113
113
  const _headers = config.headers || { Authorization: "" };
@@ -128,7 +128,7 @@ function createClient(config) {
128
128
  });
129
129
  };
130
130
  const use = (modules, metadata) => {
131
- if (isHostModule(modules)) {
131
+ if (isHostModule(modules) && config.host) {
132
132
  return buildHostModule(modules, config.host);
133
133
  } else if (typeof modules === "function") {
134
134
  return buildRESTDescriptor(
package/build/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { HostModule, HostModuleAPI, RESTFunctionDescriptor, BuildRESTFunction, Host, AuthenticationStrategy } from '@wix/sdk-types';
1
+ import { Host, RESTFunctionDescriptor, BuildRESTFunction, HostModule, HostModuleAPI, AuthenticationStrategy } from '@wix/sdk-types';
2
2
  export * from '@wix/sdk-types';
3
3
  import { ConditionalExcept, EmptyObject } from 'type-fest';
4
4
  import { ImageTransformOptions } from '@wix/image-kit';
@@ -17,36 +17,40 @@ type Headers = {
17
17
  * Any non-descriptor properties are removed from the returned object, including descriptors that
18
18
  * do not match the given host (as they will not work with the given host).
19
19
  */
20
- type BuildDescriptors<T extends Descriptors<any>> = T extends HostModule<any, any> ? HostModuleAPI<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : ConditionalExcept<{
21
- [Key in keyof T]: T[Key] extends Descriptors<any> ? BuildDescriptors<T[Key]> : never;
20
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined> = BuildRESTDescriptors<T> & (H extends Host<any> ? BuildHostDescriptors<T> : {});
21
+ type BuildRESTDescriptors<T extends Descriptors> = T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : ConditionalExcept<{
22
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildRESTDescriptors<T[Key]> : never;
23
+ }, EmptyObject>;
24
+ type BuildHostDescriptors<T extends Descriptors> = T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
25
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildHostDescriptors<T[Key]> : never;
22
26
  }, EmptyObject>;
23
27
  /**
24
28
  * Descriptors are objects that describe the API of a module, and the module
25
29
  * can either be a REST module or a host module.
26
30
  * This type is recursive, so it can describe nested modules.
27
31
  */
28
- type Descriptors<H extends Host<any>> = RESTFunctionDescriptor | HostModule<any, H> | {
29
- [key: string]: Descriptors<H> | PublicMetadata | any;
32
+ type Descriptors = RESTFunctionDescriptor | HostModule<any, any> | {
33
+ [key: string]: Descriptors | PublicMetadata | any;
30
34
  };
31
35
  /**
32
36
  * This type is used in `createClient` to ensure that the given host matches the host of the given descriptors.
33
37
  * If the host does not match, the descriptor is replaced with a host module that will throw an error when used.
34
38
  */
35
- type AssertHostMatches<T extends Descriptors<any>, H extends Host<any>> = T extends HostModule<any, infer U> ? H extends undefined ? never : H extends U ? T : HostModule<any, H> : T extends RESTFunctionDescriptor<any> ? T : {
36
- [Key in keyof T]: T[Key] extends Descriptors<any> ? AssertHostMatches<T[Key], H> : T[Key];
39
+ type AssertHostMatches<T extends Descriptors, H extends Host<any>> = T extends HostModule<any, infer U> ? H extends undefined ? never : H extends U ? T : HostModule<any, H> : T extends RESTFunctionDescriptor<any> ? T : {
40
+ [Key in keyof T]: T[Key] extends Descriptors ? AssertHostMatches<T[Key], H> : T[Key];
37
41
  };
38
- type WixClient<T extends Descriptors<H> = Descriptors<Host>, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<unknown>, H extends Host<any> = undefined> = {
42
+ type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = Descriptors> = {
39
43
  setHeaders(headers: Headers): void;
40
44
  auth: Z;
41
45
  fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
42
- use<R extends Descriptors<H> = EmptyObject>(modules: AssertHostMatches<R, H>): BuildDescriptors<R>;
43
- } & BuildDescriptors<T>;
44
- declare function createClient<T extends Descriptors<H> = EmptyObject, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<unknown>, H extends Host<any> = undefined>(config: {
45
- modules?: AssertHostMatches<T, H>;
46
+ use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
47
+ } & BuildDescriptors<T, H>;
48
+ declare function createClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = EmptyObject>(config: {
49
+ modules?: H extends Host<any> ? AssertHostMatches<T, H> : T;
46
50
  auth?: Z;
47
51
  headers?: Headers;
48
52
  host?: H;
49
- }): WixClient<T, Z, H>;
53
+ }): WixClient<H, Z, T>;
50
54
 
51
55
  declare function getScaledToFillImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
52
56
  declare function getScaledToFitImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HostModule, HostModuleAPI, RESTFunctionDescriptor, BuildRESTFunction, Host, AuthenticationStrategy } from '@wix/sdk-types';
1
+ import { Host, RESTFunctionDescriptor, BuildRESTFunction, HostModule, HostModuleAPI, AuthenticationStrategy } from '@wix/sdk-types';
2
2
  export * from '@wix/sdk-types';
3
3
  import { ConditionalExcept, EmptyObject } from 'type-fest';
4
4
  import { ImageTransformOptions } from '@wix/image-kit';
@@ -17,36 +17,40 @@ type Headers = {
17
17
  * Any non-descriptor properties are removed from the returned object, including descriptors that
18
18
  * do not match the given host (as they will not work with the given host).
19
19
  */
20
- type BuildDescriptors<T extends Descriptors<any>> = T extends HostModule<any, any> ? HostModuleAPI<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : ConditionalExcept<{
21
- [Key in keyof T]: T[Key] extends Descriptors<any> ? BuildDescriptors<T[Key]> : never;
20
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined> = BuildRESTDescriptors<T> & (H extends Host<any> ? BuildHostDescriptors<T> : {});
21
+ type BuildRESTDescriptors<T extends Descriptors> = T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : ConditionalExcept<{
22
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildRESTDescriptors<T[Key]> : never;
23
+ }, EmptyObject>;
24
+ type BuildHostDescriptors<T extends Descriptors> = T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
25
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildHostDescriptors<T[Key]> : never;
22
26
  }, EmptyObject>;
23
27
  /**
24
28
  * Descriptors are objects that describe the API of a module, and the module
25
29
  * can either be a REST module or a host module.
26
30
  * This type is recursive, so it can describe nested modules.
27
31
  */
28
- type Descriptors<H extends Host<any>> = RESTFunctionDescriptor | HostModule<any, H> | {
29
- [key: string]: Descriptors<H> | PublicMetadata | any;
32
+ type Descriptors = RESTFunctionDescriptor | HostModule<any, any> | {
33
+ [key: string]: Descriptors | PublicMetadata | any;
30
34
  };
31
35
  /**
32
36
  * This type is used in `createClient` to ensure that the given host matches the host of the given descriptors.
33
37
  * If the host does not match, the descriptor is replaced with a host module that will throw an error when used.
34
38
  */
35
- type AssertHostMatches<T extends Descriptors<any>, H extends Host<any>> = T extends HostModule<any, infer U> ? H extends undefined ? never : H extends U ? T : HostModule<any, H> : T extends RESTFunctionDescriptor<any> ? T : {
36
- [Key in keyof T]: T[Key] extends Descriptors<any> ? AssertHostMatches<T[Key], H> : T[Key];
39
+ type AssertHostMatches<T extends Descriptors, H extends Host<any>> = T extends HostModule<any, infer U> ? H extends undefined ? never : H extends U ? T : HostModule<any, H> : T extends RESTFunctionDescriptor<any> ? T : {
40
+ [Key in keyof T]: T[Key] extends Descriptors ? AssertHostMatches<T[Key], H> : T[Key];
37
41
  };
38
- type WixClient<T extends Descriptors<H> = Descriptors<Host>, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<unknown>, H extends Host<any> = undefined> = {
42
+ type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = Descriptors> = {
39
43
  setHeaders(headers: Headers): void;
40
44
  auth: Z;
41
45
  fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
42
- use<R extends Descriptors<H> = EmptyObject>(modules: AssertHostMatches<R, H>): BuildDescriptors<R>;
43
- } & BuildDescriptors<T>;
44
- declare function createClient<T extends Descriptors<H> = EmptyObject, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<unknown>, H extends Host<any> = undefined>(config: {
45
- modules?: AssertHostMatches<T, H>;
46
+ use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
47
+ } & BuildDescriptors<T, H>;
48
+ declare function createClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = EmptyObject>(config: {
49
+ modules?: H extends Host<any> ? AssertHostMatches<T, H> : T;
46
50
  auth?: Z;
47
51
  headers?: Headers;
48
52
  host?: H;
49
- }): WixClient<T, Z, H>;
53
+ }): WixClient<H, Z, T>;
50
54
 
51
55
  declare function getScaledToFillImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
52
56
  declare function getScaledToFitImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
package/build/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -53,6 +54,12 @@ var getDefaultContentHeader = (options) => {
53
54
  };
54
55
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
55
56
 
57
+ // src/host-modules.ts
58
+ var isHostModule = (val) => isObject(val) && val.__type === "host";
59
+ function buildHostModule(val, host) {
60
+ return val.create(host);
61
+ }
62
+
56
63
  // src/bi/biHeaderGenerator.ts
57
64
  var WixBIHeaderName = "x-wix-bi-gateway";
58
65
  function biHeaderGenerator(apiMetadata, publicMetadata) {
@@ -142,12 +149,6 @@ var errorBuilder = (code, description, details, data) => {
142
149
  };
143
150
  };
144
151
 
145
- // src/host-modules.ts
146
- var isHostModule = (val) => isObject(val) && val.__type === "host";
147
- function buildHostModule(val, host) {
148
- return val.create(host);
149
- }
150
-
151
152
  // src/wixClient.ts
152
153
  function createClient(config) {
153
154
  const _headers = config.headers || { Authorization: "" };
@@ -168,7 +169,7 @@ function createClient(config) {
168
169
  });
169
170
  };
170
171
  const use = (modules, metadata) => {
171
- if (isHostModule(modules)) {
172
+ if (isHostModule(modules) && config.host) {
172
173
  return buildHostModule(modules, config.host);
173
174
  } else if (typeof modules === "function") {
174
175
  return buildRESTDescriptor(
package/build/index.mjs CHANGED
@@ -11,6 +11,12 @@ var getDefaultContentHeader = (options) => {
11
11
  };
12
12
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
13
13
 
14
+ // src/host-modules.ts
15
+ var isHostModule = (val) => isObject(val) && val.__type === "host";
16
+ function buildHostModule(val, host) {
17
+ return val.create(host);
18
+ }
19
+
14
20
  // src/bi/biHeaderGenerator.ts
15
21
  var WixBIHeaderName = "x-wix-bi-gateway";
16
22
  function biHeaderGenerator(apiMetadata, publicMetadata) {
@@ -100,12 +106,6 @@ var errorBuilder = (code, description, details, data) => {
100
106
  };
101
107
  };
102
108
 
103
- // src/host-modules.ts
104
- var isHostModule = (val) => isObject(val) && val.__type === "host";
105
- function buildHostModule(val, host) {
106
- return val.create(host);
107
- }
108
-
109
109
  // src/wixClient.ts
110
110
  function createClient(config) {
111
111
  const _headers = config.headers || { Authorization: "" };
@@ -126,7 +126,7 @@ function createClient(config) {
126
126
  });
127
127
  };
128
128
  const use = (modules, metadata) => {
129
- if (isHostModule(modules)) {
129
+ if (isHostModule(modules) && config.host) {
130
130
  return buildHostModule(modules, config.host);
131
131
  } else if (typeof modules === "function") {
132
132
  return buildRESTDescriptor(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -34,8 +34,8 @@
34
34
  "@types/grecaptcha": "^3.0.4",
35
35
  "@wix/identity": "^1.0.44",
36
36
  "@wix/image-kit": "^1.34.0",
37
- "@wix/redirects": "^1.0.21",
38
- "@wix/sdk-types": "1.2.5",
37
+ "@wix/redirects": "^1.0.22",
38
+ "@wix/sdk-types": "1.2.6",
39
39
  "pkce-challenge": "^3.1.0",
40
40
  "querystring": "^0.2.1",
41
41
  "type-fest": "^3.13.1"
@@ -45,8 +45,8 @@
45
45
  "@swc/jest": "^0.2.27",
46
46
  "@types/jest": "^27.5.2",
47
47
  "@types/node": "^16.18.39",
48
- "@wix/ecom": "^1.0.274",
49
- "@wix/events": "^1.0.107",
48
+ "@wix/ecom": "^1.0.283",
49
+ "@wix/events": "^1.0.108",
50
50
  "@wix/motion": "^1.0.26",
51
51
  "eslint": "^7.32.0",
52
52
  "eslint-config-sdk": "0.0.0",
@@ -80,5 +80,5 @@
80
80
  "wallaby": {
81
81
  "autoDetect": true
82
82
  },
83
- "falconPackageHash": "877aac46cdf9d0aa57c0b0a7739d777f1fda89bf48cacd716766956a"
83
+ "falconPackageHash": "7048af349d562f1a266e24414afdf85663bf1eb9bb3c2360c81e0b3d"
84
84
  }