@jay-framework/wix-deploy 0.18.0 → 0.18.3

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,19 @@
1
+ /**
2
+ * wix-deploy setup hook
3
+ *
4
+ * Runs after wix-server-client setup. Reads wix.config.json to populate
5
+ * clientId and siteId in config/.wix.yaml (if they're still placeholders),
6
+ * then validates the data collection exists.
7
+ */
8
+ interface SetupContext {
9
+ configDir: string;
10
+ projectRoot: string;
11
+ initError?: Error;
12
+ }
13
+ interface SetupResult {
14
+ status: 'configured' | 'needs-config' | 'error';
15
+ message?: string;
16
+ configCreated?: string[];
17
+ }
18
+ export declare function setupWixDeploy(ctx: SetupContext): Promise<SetupResult>;
19
+ export {};
package/dist/setup.js ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * wix-deploy setup hook
3
+ *
4
+ * Runs after wix-server-client setup. Reads wix.config.json to populate
5
+ * clientId and siteId in config/.wix.yaml (if they're still placeholders),
6
+ * then validates the data collection exists.
7
+ */
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import yaml from 'js-yaml';
11
+ // @ts-ignore — no type declarations
12
+ import { getService } from '@jay-framework/stack-server-runtime';
13
+ import { WIX_CLIENT_SERVICE } from '@jay-framework/wix-server-client';
14
+ import { items } from '@wix/data';
15
+ import { DEFAULT_COLLECTION_ID } from './constants.js';
16
+ export async function setupWixDeploy(ctx) {
17
+ if (ctx.initError) {
18
+ return {
19
+ status: 'error',
20
+ message: `Service init failed: ${ctx.initError.message}`,
21
+ };
22
+ }
23
+ const wixConfigPath = path.join(ctx.projectRoot, 'wix.config.json');
24
+ const wixYamlPath = path.join(ctx.configDir, '.wix.yaml');
25
+ if (!fs.existsSync(wixConfigPath)) {
26
+ return {
27
+ status: 'needs-config',
28
+ message: 'wix.config.json not found. Run: npm create @wix/new@latest init',
29
+ };
30
+ }
31
+ const wixConfig = JSON.parse(fs.readFileSync(wixConfigPath, 'utf8'));
32
+ const appId = wixConfig.appId;
33
+ const siteId = wixConfig.siteId;
34
+ if (!appId) {
35
+ return {
36
+ status: 'error',
37
+ message: 'wix.config.json missing appId',
38
+ };
39
+ }
40
+ const configCreated = [];
41
+ if (fs.existsSync(wixYamlPath)) {
42
+ const content = fs.readFileSync(wixYamlPath, 'utf8');
43
+ const config = yaml.load(content);
44
+ if (config) {
45
+ let changed = false;
46
+ const currentClientId = config.oauthStrategy?.clientId || '';
47
+ if (!currentClientId || currentClientId.startsWith('<')) {
48
+ if (!config.oauthStrategy)
49
+ config.oauthStrategy = {};
50
+ config.oauthStrategy.clientId = appId;
51
+ changed = true;
52
+ configCreated.push('clientId');
53
+ }
54
+ const currentSiteId = config.apiKeyStrategy?.siteId || '';
55
+ if (siteId && (!currentSiteId || currentSiteId.startsWith('<'))) {
56
+ if (!config.apiKeyStrategy)
57
+ config.apiKeyStrategy = {};
58
+ config.apiKeyStrategy.siteId = siteId;
59
+ changed = true;
60
+ configCreated.push('siteId');
61
+ }
62
+ if (changed) {
63
+ fs.writeFileSync(wixYamlPath, yaml.dump(config, { lineWidth: -1 }), 'utf8');
64
+ }
65
+ }
66
+ }
67
+ // Check if API key is configured
68
+ if (fs.existsSync(wixYamlPath)) {
69
+ const config = yaml.load(fs.readFileSync(wixYamlPath, 'utf8'));
70
+ const apiKey = config?.apiKeyStrategy?.apiKey || '';
71
+ if (!apiKey || apiKey.startsWith('<')) {
72
+ return {
73
+ status: 'needs-config',
74
+ configCreated,
75
+ message: 'API key required — create one at https://manage.wix.com/ and add to config/.wix.yaml',
76
+ };
77
+ }
78
+ }
79
+ // Validate data collection exists
80
+ let collectionOk = false;
81
+ try {
82
+ const wixClient = getService(WIX_CLIENT_SERVICE);
83
+ if (wixClient) {
84
+ const dataClient = wixClient.use({ items });
85
+ await dataClient.items.query(DEFAULT_COLLECTION_ID).limit(1).find();
86
+ collectionOk = true;
87
+ }
88
+ }
89
+ catch {
90
+ return {
91
+ status: 'needs-config',
92
+ configCreated,
93
+ message: `Data collection "${DEFAULT_COLLECTION_ID}" not found. Create it in the Wix dashboard with fields: path (text), content (text), fileType (text), sizeBytes (number), category (text), version (text)`,
94
+ };
95
+ }
96
+ return {
97
+ status: 'configured',
98
+ configCreated,
99
+ message: `Deploy target: wix.config.json (appId: ${appId.slice(0, 8)}...). Collection: ${DEFAULT_COLLECTION_ID} ${collectionOk ? '✓' : ''}`,
100
+ };
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/wix-deploy",
3
- "version": "0.18.0",
3
+ "version": "0.18.3",
4
4
  "type": "module",
5
5
  "description": "Wix BaaS deployment adapter for Jay Framework — WixDataArtifactStore and entry builder",
6
6
  "license": "Apache-2.0",
@@ -25,21 +25,21 @@
25
25
  "test": ":"
26
26
  },
27
27
  "dependencies": {
28
- "@jay-framework/fullstack-component": "^0.18.0",
29
- "@jay-framework/production-server": "^0.18.0",
30
- "@jay-framework/stack-server-runtime": "^0.18.0",
31
- "@jay-framework/wix-server-client": "^0.18.0",
32
- "@wix/ambassador-ctp-gradual-rollout-v1-baas-release": "^1.0.12",
33
- "@wix/ambassador-devcenter-apps-v1-app-version": "^1.0.115",
34
- "@wix/ambassador-devcenter-components-overrides-v1-components-override": "^1.0.475",
35
- "@wix/ambassador-velo-backend-v1-app-deployment": "^1.0.55",
28
+ "@jay-framework/fullstack-component": "^0.18.3",
29
+ "@jay-framework/production-server": "^0.18.3",
30
+ "@jay-framework/stack-server-runtime": "^0.18.3",
31
+ "@jay-framework/wix-server-client": "^0.18.3",
36
32
  "@wix/data": "^1.0.433",
37
- "@wix/http-client": "^2.88.0",
38
33
  "@wix/sdk": "^1.21.5",
39
34
  "esbuild": "^0.21.0",
40
35
  "js-yaml": "^4.1.0"
41
36
  },
42
37
  "devDependencies": {
38
+ "@wix/ambassador-ctp-gradual-rollout-v1-baas-release": "^1.0.12",
39
+ "@wix/ambassador-devcenter-apps-v1-app-version": "^1.0.115",
40
+ "@wix/ambassador-devcenter-components-overrides-v1-components-override": "^1.0.475",
41
+ "@wix/ambassador-velo-backend-v1-app-deployment": "^1.0.55",
42
+ "@wix/http-client": "^2.88.0",
43
43
  "tsup": "^8.0.0",
44
44
  "typescript": "^5.3.3",
45
45
  "vite": "^5.0.0"