@jay-framework/wix-members 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.
- package/dist/index.client.js +3 -2
- package/dist/index.d.ts +12 -1
- package/dist/index.js +109 -4
- package/package.json +16 -14
- package/plugin.yaml +7 -0
package/dist/index.client.js
CHANGED
|
@@ -34,8 +34,9 @@ function provideWixMembersContext(initData) {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
function getCallbackUrl() {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const url = initData.authCallbackUrl || "/auth/callback";
|
|
38
|
+
if (url.startsWith("http")) return url;
|
|
39
|
+
return window.location.origin + url;
|
|
39
40
|
}
|
|
40
41
|
async function redirectToLogin(callbackUrl) {
|
|
41
42
|
const redirectUri = callbackUrl || getCallbackUrl();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { W as WixMembersService } from './index.client-lddj65uZ.js';
|
|
2
2
|
export { A as AuthCallbackResult, R as ReactiveMemberIndicator, b as WIX_MEMBERS_CONTEXT, a as WIX_MEMBERS_SERVICE, c as WixMembersContext, d as WixMembersInitData, e as authCallback, i as init, l as loginIndicator, f as protectedPage, p as provideWixMembersContext } from './index.client-lddj65uZ.js';
|
|
3
|
+
import { JayHtmlValidatorFn } from '@jay-framework/compiler-shared';
|
|
4
|
+
import { PluginSetupContext, PluginSetupResult } from '@jay-framework/stack-server-runtime';
|
|
3
5
|
import '@jay-framework/runtime';
|
|
4
6
|
import '@jay-framework/reactive';
|
|
5
7
|
import '@jay-framework/fullstack-component';
|
|
6
8
|
import '@jay-framework/component';
|
|
7
9
|
|
|
10
|
+
interface WixMembersConfig {
|
|
11
|
+
authCallbackUrl: string;
|
|
12
|
+
}
|
|
13
|
+
declare function loadWixMembersConfig(projectRoot?: string): WixMembersConfig;
|
|
14
|
+
|
|
8
15
|
declare function provideWixMembersService(): WixMembersService;
|
|
9
16
|
|
|
10
17
|
declare const AUTH_COOKIE_NAME = "wix_auth_role";
|
|
11
18
|
declare function setAuthCookie(role: 'member' | 'visitor'): void;
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
declare const validateAuthCallbackPage: JayHtmlValidatorFn;
|
|
21
|
+
|
|
22
|
+
declare function setupWixMembers(ctx: PluginSetupContext): Promise<PluginSetupResult>;
|
|
23
|
+
|
|
24
|
+
export { AUTH_COOKIE_NAME, type WixMembersConfig, WixMembersService, loadWixMembersConfig, provideWixMembersService, setAuthCookie, setupWixMembers, validateAuthCallbackPage };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,9 @@ import { createJayService, makeJayStackComponent, RenderPipeline, redirect3xx, m
|
|
|
3
3
|
import { createJayContext, useGlobalContext } from "@jay-framework/runtime";
|
|
4
4
|
import { registerReactiveGlobalContext, createSignal, useReactive, createEvent } from "@jay-framework/component";
|
|
5
5
|
import { WIX_CLIENT_CONTEXT, WIX_CLIENT_SERVICE } from "@jay-framework/wix-server-client";
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import * as yaml from "js-yaml";
|
|
6
9
|
const WIX_MEMBERS_SERVICE = createJayService("Wix Members Service");
|
|
7
10
|
function provideWixMembersService() {
|
|
8
11
|
const service = {};
|
|
@@ -41,8 +44,9 @@ function provideWixMembersContext(initData) {
|
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
function getCallbackUrl() {
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
const url = initData.authCallbackUrl || "/auth/callback";
|
|
48
|
+
if (url.startsWith("http")) return url;
|
|
49
|
+
return window.location.origin + url;
|
|
46
50
|
}
|
|
47
51
|
async function redirectToLogin(callbackUrl) {
|
|
48
52
|
const redirectUri = callbackUrl || getCallbackUrl();
|
|
@@ -156,22 +160,123 @@ async function renderFastChanging(props, _membersService) {
|
|
|
156
160
|
}));
|
|
157
161
|
}
|
|
158
162
|
const protectedPage = makeJayStackComponent().withProps().withServices(WIX_MEMBERS_SERVICE).withFastRender(renderFastChanging);
|
|
163
|
+
const DEFAULTS = {
|
|
164
|
+
authCallbackUrl: "/auth/callback"
|
|
165
|
+
};
|
|
166
|
+
function loadWixMembersConfig(projectRoot) {
|
|
167
|
+
const root = projectRoot ?? process.cwd();
|
|
168
|
+
const configPath = path.join(root, "config", ".wix-members.yaml");
|
|
169
|
+
if (!fs.existsSync(configPath)) {
|
|
170
|
+
return DEFAULTS;
|
|
171
|
+
}
|
|
172
|
+
const raw = yaml.load(fs.readFileSync(configPath, "utf8"));
|
|
173
|
+
if (!raw) {
|
|
174
|
+
return DEFAULTS;
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
authCallbackUrl: typeof raw.authCallbackUrl === "string" ? raw.authCallbackUrl : DEFAULTS.authCallbackUrl
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const MEMBERS_CONTRACTS = /* @__PURE__ */ new Set(["login-indicator", "auth-callback", "protected-page"]);
|
|
181
|
+
const checkedProjects = /* @__PURE__ */ new Set();
|
|
182
|
+
const validateAuthCallbackPage = (ctx) => {
|
|
183
|
+
const findings = [];
|
|
184
|
+
const usesMembers = ctx.headlessImports.some((imp) => MEMBERS_CONTRACTS.has(imp.contractName));
|
|
185
|
+
if (!usesMembers) return findings;
|
|
186
|
+
if (checkedProjects.has(ctx.projectRoot)) return findings;
|
|
187
|
+
checkedProjects.add(ctx.projectRoot);
|
|
188
|
+
const config = loadWixMembersConfig(ctx.projectRoot);
|
|
189
|
+
const callbackUrl = config.authCallbackUrl;
|
|
190
|
+
if (!callbackUrl.startsWith("/")) return findings;
|
|
191
|
+
const routeSegments = callbackUrl.replace(/^\//, "").split("/");
|
|
192
|
+
const pagesDir = path.join(ctx.projectRoot, "src", "pages");
|
|
193
|
+
const pagePath = path.join(pagesDir, ...routeSegments, "page.jay-html");
|
|
194
|
+
if (!fs.existsSync(pagePath)) {
|
|
195
|
+
findings.push({
|
|
196
|
+
severity: "error",
|
|
197
|
+
message: `wix-members requires an auth callback page at src/pages/${routeSegments.join("/")}/page.jay-html`,
|
|
198
|
+
suggestion: "Create the page using the auth-callback contract. See agent-kit/plugin/wix-members-setup.md for a template."
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return findings;
|
|
202
|
+
};
|
|
159
203
|
const init = makeJayInit().withServer(async () => {
|
|
160
204
|
console.log("[wix-members] Initializing Wix Members service...");
|
|
161
205
|
getService(WIX_CLIENT_SERVICE);
|
|
162
206
|
provideWixMembersService();
|
|
207
|
+
const config = loadWixMembersConfig();
|
|
208
|
+
console.log(`[wix-members] Auth callback URL: ${config.authCallbackUrl}`);
|
|
163
209
|
console.log("[wix-members] Server initialization complete");
|
|
164
|
-
return {
|
|
210
|
+
return {
|
|
211
|
+
authCallbackUrl: config.authCallbackUrl
|
|
212
|
+
};
|
|
165
213
|
});
|
|
214
|
+
const CONFIG_FILE_NAME = ".wix-members.yaml";
|
|
215
|
+
const CONFIG_TEMPLATE = `# Wix Members Configuration
|
|
216
|
+
#
|
|
217
|
+
# Auth callback URL — the route that handles the OAuth redirect after login/register.
|
|
218
|
+
# Must match a page in your site (e.g. src/pages/auth/callback/page.jay-html).
|
|
219
|
+
# Relative paths are resolved against the site origin at runtime.
|
|
220
|
+
authCallbackUrl: "/auth/callback"
|
|
221
|
+
`;
|
|
222
|
+
async function setupWixMembers(ctx) {
|
|
223
|
+
if (ctx.initError) {
|
|
224
|
+
return {
|
|
225
|
+
status: "error",
|
|
226
|
+
message: `Service init failed (is wix-server-client configured?). ${ctx.initError.message}`
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const configCreated = [];
|
|
230
|
+
const configPath = path.join(ctx.configDir, CONFIG_FILE_NAME);
|
|
231
|
+
if (!fs.existsSync(configPath)) {
|
|
232
|
+
if (!fs.existsSync(ctx.configDir)) {
|
|
233
|
+
fs.mkdirSync(ctx.configDir, { recursive: true });
|
|
234
|
+
}
|
|
235
|
+
fs.writeFileSync(configPath, CONFIG_TEMPLATE, "utf-8");
|
|
236
|
+
configCreated.push(`config/${CONFIG_FILE_NAME}`);
|
|
237
|
+
}
|
|
238
|
+
const config = loadWixMembersConfig(ctx.projectRoot);
|
|
239
|
+
const callbackUrl = config.authCallbackUrl;
|
|
240
|
+
if (!callbackUrl.startsWith("/")) {
|
|
241
|
+
return {
|
|
242
|
+
status: "configured",
|
|
243
|
+
configCreated,
|
|
244
|
+
message: `Wix Members configured (external callback: ${callbackUrl})`
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
const routeSegments = callbackUrl.replace(/^\//, "").split("/");
|
|
248
|
+
const pagesDir = path.join(ctx.projectRoot, "src", "pages");
|
|
249
|
+
const candidatePaths = [
|
|
250
|
+
path.join(pagesDir, ...routeSegments, "page.jay-html"),
|
|
251
|
+
path.join(pagesDir, ...routeSegments.slice(0, -1), routeSegments.at(-1) + ".jay-html")
|
|
252
|
+
];
|
|
253
|
+
const hasCallbackPage = candidatePaths.some((p) => fs.existsSync(p));
|
|
254
|
+
if (!hasCallbackPage) {
|
|
255
|
+
const expectedPath = `src/pages/${routeSegments.join("/")}/page.jay-html`;
|
|
256
|
+
return {
|
|
257
|
+
status: "needs-config",
|
|
258
|
+
configCreated,
|
|
259
|
+
message: `Auth callback page missing: create ${expectedPath} using the auth-callback contract. See agent-kit/plugin/wix-members-setup.md for details.`
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
status: "configured",
|
|
264
|
+
configCreated,
|
|
265
|
+
message: `Wix Members configured (callback: ${callbackUrl})`
|
|
266
|
+
};
|
|
267
|
+
}
|
|
166
268
|
export {
|
|
167
269
|
AUTH_COOKIE_NAME,
|
|
168
270
|
WIX_MEMBERS_CONTEXT,
|
|
169
271
|
WIX_MEMBERS_SERVICE,
|
|
170
272
|
authCallback,
|
|
171
273
|
init,
|
|
274
|
+
loadWixMembersConfig,
|
|
172
275
|
loginIndicator,
|
|
173
276
|
protectedPage,
|
|
174
277
|
provideWixMembersContext,
|
|
175
278
|
provideWixMembersService,
|
|
176
|
-
setAuthCookie
|
|
279
|
+
setAuthCookie,
|
|
280
|
+
setupWixMembers,
|
|
281
|
+
validateAuthCallbackPage
|
|
177
282
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/wix-members",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Wix Members authentication package for Jay Framework",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,26 +37,28 @@
|
|
|
37
37
|
"test": ":"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jay-framework/component": "^0.
|
|
41
|
-
"@jay-framework/fullstack-component": "^0.
|
|
42
|
-
"@jay-framework/reactive": "^0.
|
|
43
|
-
"@jay-framework/runtime": "^0.
|
|
44
|
-
"@jay-framework/secure": "^0.
|
|
45
|
-
"@jay-framework/stack-client-runtime": "^0.
|
|
46
|
-
"@jay-framework/stack-server-runtime": "^0.
|
|
47
|
-
"@jay-framework/wix-server-client": "^0.
|
|
48
|
-
"@jay-framework/wix-utils": "^0.
|
|
40
|
+
"@jay-framework/component": "^0.22.0",
|
|
41
|
+
"@jay-framework/fullstack-component": "^0.22.0",
|
|
42
|
+
"@jay-framework/reactive": "^0.22.0",
|
|
43
|
+
"@jay-framework/runtime": "^0.22.0",
|
|
44
|
+
"@jay-framework/secure": "^0.22.0",
|
|
45
|
+
"@jay-framework/stack-client-runtime": "^0.22.0",
|
|
46
|
+
"@jay-framework/stack-server-runtime": "^0.22.0",
|
|
47
|
+
"@jay-framework/wix-server-client": "^0.22.0",
|
|
48
|
+
"@jay-framework/wix-utils": "^0.22.0",
|
|
49
49
|
"@wix/redirects": "^1.0.88",
|
|
50
50
|
"@wix/sdk": "^1.21.5",
|
|
51
|
-
"@wix/sdk-runtime": "^1.0.11"
|
|
51
|
+
"@wix/sdk-runtime": "^1.0.11",
|
|
52
|
+
"js-yaml": "^4.1.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@babel/core": "^7.23.7",
|
|
55
56
|
"@babel/preset-env": "^7.23.8",
|
|
56
57
|
"@babel/preset-typescript": "^7.23.3",
|
|
57
|
-
"@jay-framework/compiler-jay-stack": "^0.
|
|
58
|
-
"@jay-framework/jay-cli": "^0.
|
|
59
|
-
"@jay-framework/
|
|
58
|
+
"@jay-framework/compiler-jay-stack": "^0.22.0",
|
|
59
|
+
"@jay-framework/jay-cli": "^0.22.0",
|
|
60
|
+
"@jay-framework/jay-stack-cli": "^0.22.0",
|
|
61
|
+
"@jay-framework/vite-plugin": "^0.22.0",
|
|
60
62
|
"@jay-framework/wix-dev-environment": "^0.6.12",
|
|
61
63
|
"nodemon": "^3.0.3",
|
|
62
64
|
"rimraf": "^5.0.5",
|
package/plugin.yaml
CHANGED
|
@@ -23,3 +23,10 @@ contexts:
|
|
|
23
23
|
- name: wix-members
|
|
24
24
|
marker: WIX_MEMBERS_CONTEXT
|
|
25
25
|
description: Client-side member auth state, redirect login/register/logout operations
|
|
26
|
+
|
|
27
|
+
validators:
|
|
28
|
+
- name: auth-callback-page
|
|
29
|
+
handler: validateAuthCallbackPage
|
|
30
|
+
description: Checks that the auth callback page exists for the OAuth redirect flow
|
|
31
|
+
|
|
32
|
+
setup: setupWixMembers
|