@jay-framework/wix-server-client 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,7 +67,37 @@ const init = makeJayInit().withClient(async (data) => {
67
67
  await provideWixClientContext(oauthClientId);
68
68
  console.log("[wix-server-client] Client initialization complete");
69
69
  });
70
+ const WIX_API_BASE = "https://www.wixapis.com";
71
+ async function wixFetch(client, path, options = {}) {
72
+ const { method = "GET", body } = options;
73
+ const auth = await client.auth.getAuthHeaders();
74
+ const response = await fetch(`${WIX_API_BASE}${path}`, {
75
+ method,
76
+ headers: {
77
+ ...auth.headers,
78
+ "Content-Type": "application/json"
79
+ },
80
+ body: body ? JSON.stringify(body) : void 0
81
+ });
82
+ if (!response.ok) {
83
+ const text2 = await response.text();
84
+ throw new WixApiError(response.status, path, text2);
85
+ }
86
+ const text = await response.text();
87
+ return text ? JSON.parse(text) : {};
88
+ }
89
+ class WixApiError extends Error {
90
+ constructor(status, path, responseBody) {
91
+ super(`Wix API ${status}: ${path}`);
92
+ this.status = status;
93
+ this.path = path;
94
+ this.responseBody = responseBody;
95
+ this.name = "WixApiError";
96
+ }
97
+ }
70
98
  export {
71
99
  WIX_CLIENT_CONTEXT,
72
- init
100
+ WixApiError,
101
+ init,
102
+ wixFetch
73
103
  };
package/dist/index.d.ts CHANGED
@@ -59,4 +59,77 @@ declare const init: _jay_framework_fullstack_component.JayInit<{
59
59
 
60
60
  declare function setupWixServerClient(ctx: PluginSetupContext): Promise<PluginSetupResult>;
61
61
 
62
- export { type ApiKeyConfig, type OAuthConfig, WIX_CLIENT_CONTEXT, WIX_CLIENT_SERVICE, type WixClientContext, type WixClientService, type WixConfig, init, loadConfig, setupWixServerClient };
62
+ /**
63
+ * wixFetch — call Wix REST APIs using SDK auth headers.
64
+ *
65
+ * Works with both ApiKeyStrategy (server) and OAuthStrategy (client).
66
+ * The SDK client handles auth; this helper gets headers and calls fetch.
67
+ *
68
+ * Usage:
69
+ * import { wixFetch } from '@jay-framework/wix-server-client';
70
+ * const products = await wixFetch(client, '/stores/v3/products/query', {
71
+ * method: 'POST',
72
+ * body: { query: { paging: { limit: 10 } } },
73
+ * });
74
+ */
75
+
76
+ interface WixFetchOptions {
77
+ method?: string;
78
+ body?: any;
79
+ }
80
+ declare function wixFetch<T = any>(client: WixClient, path: string, options?: WixFetchOptions): Promise<T>;
81
+ /**
82
+ * Standard Wix API filter type.
83
+ * Supports operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin,
84
+ * $exists, $begins, $hasSome, $hasAll, $matchItems, $contains.
85
+ */
86
+ type FilterPrimitive = string | number | boolean | null;
87
+ type FilterOperator = {
88
+ $eq?: FilterPrimitive;
89
+ $ne?: FilterPrimitive;
90
+ $gt?: string | number;
91
+ $gte?: string | number;
92
+ $lt?: string | number;
93
+ $lte?: string | number;
94
+ $in?: Array<string | number>;
95
+ $nin?: Array<string | number>;
96
+ $exists?: boolean;
97
+ $begins?: string;
98
+ $startsWith?: string;
99
+ $hasSome?: Array<string | number>;
100
+ $hasAll?: Array<string | number>;
101
+ $contains?: string;
102
+ $matchItems?: WixFilter[];
103
+ };
104
+ interface WixFilter {
105
+ [key: string]: FilterPrimitive | FilterOperator | WixFilter[];
106
+ }
107
+ /**
108
+ * Standard Wix API sort type.
109
+ */
110
+ interface WixSort {
111
+ fieldName: string;
112
+ order?: 'ASC' | 'DESC';
113
+ }
114
+ /**
115
+ * Standard Wix API paging type.
116
+ */
117
+ interface WixPaging {
118
+ limit?: number;
119
+ offset?: number;
120
+ }
121
+ /**
122
+ * Standard Wix API cursor paging type.
123
+ */
124
+ interface WixCursorPaging {
125
+ cursor?: string;
126
+ limit?: number;
127
+ }
128
+ declare class WixApiError extends Error {
129
+ readonly status: number;
130
+ readonly path: string;
131
+ readonly responseBody: string;
132
+ constructor(status: number, path: string, responseBody: string);
133
+ }
134
+
135
+ export { type ApiKeyConfig, type OAuthConfig, WIX_CLIENT_CONTEXT, WIX_CLIENT_SERVICE, WixApiError, type WixClientContext, type WixClientService, type WixConfig, type WixCursorPaging, type WixFetchOptions, type WixFilter, type WixPaging, type WixSort, init, loadConfig, setupWixServerClient, wixFetch };
package/dist/index.js CHANGED
@@ -148,10 +148,40 @@ async function setupWixServerClient(ctx) {
148
148
  };
149
149
  }
150
150
  }
151
+ const WIX_API_BASE = "https://www.wixapis.com";
152
+ async function wixFetch(client, path2, options = {}) {
153
+ const { method = "GET", body } = options;
154
+ const auth = await client.auth.getAuthHeaders();
155
+ const response = await fetch(`${WIX_API_BASE}${path2}`, {
156
+ method,
157
+ headers: {
158
+ ...auth.headers,
159
+ "Content-Type": "application/json"
160
+ },
161
+ body: body ? JSON.stringify(body) : void 0
162
+ });
163
+ if (!response.ok) {
164
+ const text2 = await response.text();
165
+ throw new WixApiError(response.status, path2, text2);
166
+ }
167
+ const text = await response.text();
168
+ return text ? JSON.parse(text) : {};
169
+ }
170
+ class WixApiError extends Error {
171
+ constructor(status, path2, responseBody) {
172
+ super(`Wix API ${status}: ${path2}`);
173
+ this.status = status;
174
+ this.path = path2;
175
+ this.responseBody = responseBody;
176
+ this.name = "WixApiError";
177
+ }
178
+ }
151
179
  export {
152
180
  WIX_CLIENT_CONTEXT,
153
181
  WIX_CLIENT_SERVICE,
182
+ WixApiError,
154
183
  init,
155
184
  loadConfig,
156
- setupWixServerClient
185
+ setupWixServerClient,
186
+ wixFetch
157
187
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/wix-server-client",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "type": "module",
5
5
  "description": "Wix SDK client configuration and authentication for Jay Framework",
6
6
  "license": "Apache-2.0",
@@ -26,24 +26,23 @@
26
26
  "test": ":"
27
27
  },
28
28
  "dependencies": {
29
- "@jay-framework/component": "^0.20.0",
30
- "@jay-framework/fullstack-component": "^0.20.0",
31
- "@jay-framework/reactive": "^0.20.0",
32
- "@jay-framework/runtime": "^0.20.0",
33
- "@jay-framework/secure": "^0.20.0",
34
- "@jay-framework/stack-client-runtime": "^0.20.0",
35
- "@jay-framework/stack-server-runtime": "^0.20.0",
29
+ "@jay-framework/component": "^0.22.0",
30
+ "@jay-framework/fullstack-component": "^0.22.0",
31
+ "@jay-framework/reactive": "^0.22.0",
32
+ "@jay-framework/runtime": "^0.22.0",
33
+ "@jay-framework/secure": "^0.22.0",
34
+ "@jay-framework/stack-client-runtime": "^0.22.0",
35
+ "@jay-framework/stack-server-runtime": "^0.22.0",
36
36
  "@wix/sdk": "^1.21.5",
37
- "@wix/sdk-runtime": "^1.0.11",
38
37
  "js-yaml": "^4.1.0"
39
38
  },
40
39
  "devDependencies": {
41
40
  "@babel/core": "^7.23.7",
42
41
  "@babel/preset-env": "^7.23.8",
43
42
  "@babel/preset-typescript": "^7.23.3",
44
- "@jay-framework/compiler-jay-stack": "^0.20.0",
45
- "@jay-framework/jay-cli": "^0.20.0",
46
- "@jay-framework/vite-plugin": "^0.20.0",
43
+ "@jay-framework/compiler-jay-stack": "^0.22.0",
44
+ "@jay-framework/jay-cli": "^0.22.0",
45
+ "@jay-framework/vite-plugin": "^0.22.0",
47
46
  "@types/js-yaml": "^4.0.9",
48
47
  "@types/node": "^20.11.0",
49
48
  "nodemon": "^3.0.3",
package/plugin.yaml CHANGED
@@ -14,6 +14,5 @@ contexts:
14
14
  marker: WIX_CLIENT_CONTEXT
15
15
  description: Client-side OAuth authentication and token management
16
16
 
17
- setup:
18
- handler: setupWixServerClient
19
- description: Configure Wix API credentials (API key, site ID, OAuth client ID)
17
+ setup: setupWixServerClient
18
+ description: Configure Wix API credentials (API key, site ID, OAuth client ID)