@wix/astro 1.0.21 → 1.0.23
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/build/index.js +3567 -4222
- package/build/index.js.map +1 -1
- package/build-browser-runtime/setup.js +3197 -3879
- package/build-runtime/chunk-MLKGABMK.js +9 -0
- package/build-runtime/chunk-RKE6XT5Z.js +3104 -0
- package/build-runtime/context/non-elevated.js +2 -1
- package/build-runtime/middleware/auth.js +14 -4
- package/build-runtime/middleware/html-embeds.d.ts +5 -0
- package/build-runtime/middleware/html-embeds.js +66 -0
- package/build-runtime/routes/auth/callback.js +10 -8
- package/build-runtime/routes/auth/login.js +16 -10
- package/build-runtime/routes/auth/logout-callback.js +1 -0
- package/build-runtime/routes/auth/logout.js +11 -4
- package/build-runtime/routes/service-plugins.js +2 -0
- package/build-runtime/routes/webhooks.js +2 -0
- package/package.json +3 -3
- package/src/context/non-elevated.ts +1 -1
- package/src/context/setup.ts +1 -1
- package/src/context/utils.ts +1 -1
- package/src/index.ts +9 -0
- package/src/middleware/auth.ts +20 -4
- package/src/middleware/html-embeds.ts +67 -0
- package/src/routes/auth/callback.ts +1 -1
- package/src/routes/auth/login.ts +11 -6
- package/src/routes/auth/logout.ts +8 -1
- package/src/schemas.ts +78 -69
- package/src/utils/authAsyncLocalStorage.ts +2 -2
- package/src/utils/createProjectModel.ts +1 -1
- package/src/utils/getSessionTokensFromCookie.ts +3 -6
- package/src/utils/loadEnvVars.ts +1 -1
- package/src/utils/transformStreamUtils.ts +39 -0
- package/src/utils/writeVirtualBackofficeExtensionFiles.ts +8 -3
- package/tsup.config.mjs +3 -0
- package/build-runtime/chunk-YMZMZCBN.js +0 -4063
package/src/schemas.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
2
|
|
|
3
3
|
export const baseDevCenterComponentSchema = z
|
|
4
4
|
.object({
|
|
@@ -7,190 +7,199 @@ export const baseDevCenterComponentSchema = z
|
|
|
7
7
|
compName: z.string().optional(),
|
|
8
8
|
compType: z.string(),
|
|
9
9
|
})
|
|
10
|
-
.
|
|
10
|
+
.loose();
|
|
11
11
|
|
|
12
12
|
export type BaseDevCenterComponent = z.TypeOf<
|
|
13
13
|
typeof baseDevCenterComponentSchema
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
const devCenterWebhookSchema =
|
|
17
|
-
|
|
16
|
+
const devCenterWebhookSchema = z.object({
|
|
17
|
+
...baseDevCenterComponentSchema.shape,
|
|
18
|
+
...z.object({
|
|
18
19
|
compData: z.object({
|
|
19
20
|
webhook: z
|
|
20
21
|
.object({
|
|
21
22
|
callbackUrl: z.string().optional(),
|
|
22
23
|
})
|
|
23
|
-
.
|
|
24
|
+
.loose(),
|
|
24
25
|
}),
|
|
25
26
|
compType: z.literal('WEBHOOK'),
|
|
26
|
-
})
|
|
27
|
-
);
|
|
27
|
+
}).shape,
|
|
28
|
+
});
|
|
28
29
|
|
|
29
30
|
export type DevCenterWebhook = z.TypeOf<typeof devCenterWebhookSchema>;
|
|
30
31
|
|
|
31
|
-
const devCenterBackofficeExtensionWidgetSchema =
|
|
32
|
-
baseDevCenterComponentSchema.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
const devCenterBackofficeExtensionWidgetSchema = z.object({
|
|
33
|
+
...baseDevCenterComponentSchema.shape,
|
|
34
|
+
...z.object({
|
|
35
|
+
compData: z.object({
|
|
36
|
+
backOfficeExtensionWidget: z
|
|
37
|
+
.object({
|
|
38
|
+
iframeUrl: z.string().optional(),
|
|
39
|
+
})
|
|
40
|
+
.loose(),
|
|
41
|
+
}),
|
|
42
|
+
compType: z.literal('BACK_OFFICE_EXTENSION_WIDGET'),
|
|
43
|
+
}).shape,
|
|
44
|
+
});
|
|
44
45
|
|
|
45
46
|
export type DevCenterBackofficeExtensionWidget = z.TypeOf<
|
|
46
47
|
typeof devCenterBackofficeExtensionWidgetSchema
|
|
47
48
|
>;
|
|
48
49
|
|
|
49
|
-
const devCenterBackofficeExtensionMenuPluginSchema =
|
|
50
|
-
baseDevCenterComponentSchema.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
const devCenterBackofficeExtensionMenuPluginSchema = z.object({
|
|
51
|
+
...baseDevCenterComponentSchema.shape,
|
|
52
|
+
...z.object({
|
|
53
|
+
compData: z.object({
|
|
54
|
+
backOfficeExtensionMenuItem: z.unknown().optional(),
|
|
55
|
+
}),
|
|
56
|
+
compType: z.literal('BACK_OFFICE_EXTENSION_MENU_ITEM'),
|
|
57
|
+
}).shape,
|
|
58
|
+
});
|
|
58
59
|
|
|
59
60
|
export type DevCenterBackofficeExtensionMenuItem = z.TypeOf<
|
|
60
61
|
typeof devCenterBackofficeExtensionMenuPluginSchema
|
|
61
62
|
>;
|
|
62
63
|
|
|
63
|
-
const devCenterBackofficeModalSchema =
|
|
64
|
-
|
|
64
|
+
const devCenterBackofficeModalSchema = z.object({
|
|
65
|
+
...baseDevCenterComponentSchema.shape,
|
|
66
|
+
...z.object({
|
|
65
67
|
compData: z.object({
|
|
66
68
|
backOfficeModal: z
|
|
67
69
|
.object({
|
|
68
70
|
iframeUrl: z.string().optional(),
|
|
69
71
|
})
|
|
70
|
-
.
|
|
72
|
+
.loose(),
|
|
71
73
|
}),
|
|
72
74
|
compType: z.literal('BACK_OFFICE_MODAL'),
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
+
}).shape,
|
|
76
|
+
});
|
|
75
77
|
|
|
76
78
|
export type DevCenterBackofficeModal = z.TypeOf<
|
|
77
79
|
typeof devCenterBackofficeModalSchema
|
|
78
80
|
>;
|
|
79
81
|
|
|
80
|
-
const devCenterBackofficePageSchema =
|
|
81
|
-
|
|
82
|
+
const devCenterBackofficePageSchema = z.object({
|
|
83
|
+
...baseDevCenterComponentSchema.shape,
|
|
84
|
+
...z.object({
|
|
82
85
|
compData: z.object({
|
|
83
86
|
backOfficePage: z
|
|
84
87
|
.object({
|
|
85
88
|
iframeUrl: z.string().optional(),
|
|
86
89
|
})
|
|
87
|
-
.
|
|
90
|
+
.loose(),
|
|
88
91
|
}),
|
|
89
92
|
compType: z.literal('BACK_OFFICE_PAGE'),
|
|
90
|
-
})
|
|
91
|
-
);
|
|
93
|
+
}).shape,
|
|
94
|
+
});
|
|
92
95
|
|
|
93
96
|
export type DevCenterBackofficePage = z.TypeOf<
|
|
94
97
|
typeof devCenterBackofficePageSchema
|
|
95
98
|
>;
|
|
96
99
|
|
|
97
|
-
const devCenterEcomAdditionalFeesSchema =
|
|
98
|
-
|
|
100
|
+
const devCenterEcomAdditionalFeesSchema = z.object({
|
|
101
|
+
...baseDevCenterComponentSchema.shape,
|
|
102
|
+
...z.object({
|
|
99
103
|
compData: z.object({
|
|
100
104
|
ecomAdditionalFees: z
|
|
101
105
|
.object({
|
|
102
106
|
deploymentUri: z.string().optional(),
|
|
103
107
|
})
|
|
104
|
-
.
|
|
108
|
+
.loose(),
|
|
105
109
|
}),
|
|
106
110
|
compType: z.literal('ECOM_ADDITIONAL_FEES'),
|
|
107
|
-
})
|
|
108
|
-
);
|
|
111
|
+
}).shape,
|
|
112
|
+
});
|
|
109
113
|
|
|
110
114
|
export type DevCenterEcomAdditionalFees = z.TypeOf<
|
|
111
115
|
typeof devCenterEcomAdditionalFeesSchema
|
|
112
116
|
>;
|
|
113
117
|
|
|
114
|
-
const devCenterEcomDiscountsTriggerSchema =
|
|
115
|
-
|
|
118
|
+
const devCenterEcomDiscountsTriggerSchema = z.object({
|
|
119
|
+
...baseDevCenterComponentSchema.shape,
|
|
120
|
+
...z.object({
|
|
116
121
|
compData: z.object({
|
|
117
122
|
ecomDiscountsTrigger: z
|
|
118
123
|
.object({
|
|
119
124
|
deploymentUri: z.string().optional(),
|
|
120
125
|
})
|
|
121
|
-
.
|
|
126
|
+
.loose(),
|
|
122
127
|
}),
|
|
123
128
|
compType: z.literal('ECOM_DISCOUNTS_TRIGGER'),
|
|
124
|
-
})
|
|
125
|
-
);
|
|
129
|
+
}).shape,
|
|
130
|
+
});
|
|
126
131
|
|
|
127
132
|
export type DevCenterEcomDiscountsTrigger = z.TypeOf<
|
|
128
133
|
typeof devCenterEcomDiscountsTriggerSchema
|
|
129
134
|
>;
|
|
130
135
|
|
|
131
|
-
const devCenterEcomPaymentSettingsSchema =
|
|
132
|
-
|
|
136
|
+
const devCenterEcomPaymentSettingsSchema = z.object({
|
|
137
|
+
...baseDevCenterComponentSchema.shape,
|
|
138
|
+
...z.object({
|
|
133
139
|
compData: z.object({
|
|
134
140
|
ecomPaymentSettings: z
|
|
135
141
|
.object({
|
|
136
142
|
deploymentUri: z.string().optional(),
|
|
137
143
|
})
|
|
138
|
-
.
|
|
144
|
+
.loose(),
|
|
139
145
|
}),
|
|
140
146
|
compType: z.literal('ECOM_PAYMENT_SETTINGS'),
|
|
141
|
-
})
|
|
142
|
-
);
|
|
147
|
+
}).shape,
|
|
148
|
+
});
|
|
143
149
|
|
|
144
150
|
export type DevCenterEcomPaymentSettings = z.TypeOf<
|
|
145
151
|
typeof devCenterEcomPaymentSettingsSchema
|
|
146
152
|
>;
|
|
147
153
|
|
|
148
|
-
const devCenterEcomShippingRatesSchema =
|
|
149
|
-
|
|
154
|
+
const devCenterEcomShippingRatesSchema = z.object({
|
|
155
|
+
...baseDevCenterComponentSchema.shape,
|
|
156
|
+
...z.object({
|
|
150
157
|
compData: z.object({
|
|
151
158
|
ecomShippingRates: z
|
|
152
159
|
.object({
|
|
153
160
|
deploymentUri: z.string().optional(),
|
|
154
161
|
})
|
|
155
|
-
.
|
|
162
|
+
.loose(),
|
|
156
163
|
}),
|
|
157
164
|
compType: z.literal('ECOM_SHIPPING_RATES'),
|
|
158
|
-
})
|
|
159
|
-
);
|
|
165
|
+
}).shape,
|
|
166
|
+
});
|
|
160
167
|
|
|
161
168
|
export type DevCenterEcomShippingRates = z.TypeOf<
|
|
162
169
|
typeof devCenterEcomShippingRatesSchema
|
|
163
170
|
>;
|
|
164
171
|
|
|
165
|
-
const devCenterEcomValidationsSchema =
|
|
166
|
-
|
|
172
|
+
const devCenterEcomValidationsSchema = z.object({
|
|
173
|
+
...baseDevCenterComponentSchema.shape,
|
|
174
|
+
...z.object({
|
|
167
175
|
compData: z.object({
|
|
168
176
|
ecomValidations: z
|
|
169
177
|
.object({
|
|
170
178
|
deploymentUri: z.string().optional(),
|
|
171
179
|
})
|
|
172
|
-
.
|
|
180
|
+
.loose(),
|
|
173
181
|
}),
|
|
174
182
|
compType: z.literal('ECOM_VALIDATIONS'),
|
|
175
|
-
})
|
|
176
|
-
);
|
|
183
|
+
}).shape,
|
|
184
|
+
});
|
|
177
185
|
|
|
178
186
|
export type DevCenterEcomValidations = z.TypeOf<
|
|
179
187
|
typeof devCenterEcomValidationsSchema
|
|
180
188
|
>;
|
|
181
189
|
|
|
182
|
-
const devCenterEcomGiftCardsProviderSchema =
|
|
183
|
-
|
|
190
|
+
const devCenterEcomGiftCardsProviderSchema = z.object({
|
|
191
|
+
...baseDevCenterComponentSchema.shape,
|
|
192
|
+
...z.object({
|
|
184
193
|
compData: z.object({
|
|
185
194
|
giftCardsProvider: z
|
|
186
195
|
.object({
|
|
187
196
|
deploymentUri: z.string().optional(),
|
|
188
197
|
})
|
|
189
|
-
.
|
|
198
|
+
.loose(),
|
|
190
199
|
}),
|
|
191
200
|
compType: z.literal('GIFT_CARDS_PROVIDER'),
|
|
192
|
-
})
|
|
193
|
-
);
|
|
201
|
+
}).shape,
|
|
202
|
+
});
|
|
194
203
|
|
|
195
204
|
export type DevCenterEcomGiftCardsProvider = z.TypeOf<
|
|
196
205
|
typeof devCenterEcomGiftCardsProviderSchema
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Tokens } from '@wix/sdk';
|
|
3
3
|
|
|
4
4
|
export const authAsyncLocalStorage = new AsyncLocalStorage<{
|
|
5
|
-
sessionTokens:
|
|
5
|
+
sessionTokens: Tokens;
|
|
6
6
|
}>();
|
|
@@ -139,7 +139,7 @@ function parseBaseExtensionManifest(extensionManifest: unknown) {
|
|
|
139
139
|
throw new Error(outdent`
|
|
140
140
|
Invalid extension configuration:
|
|
141
141
|
|
|
142
|
-
${appManifestResult.error.
|
|
142
|
+
${appManifestResult.error.issues
|
|
143
143
|
.map((e) => `${e.path.join('.')}: ${e.message}`)
|
|
144
144
|
.join('\n')}
|
|
145
145
|
`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Tokens } from '@wix/sdk';
|
|
1
2
|
import type { APIContext } from 'astro';
|
|
2
3
|
import { TokenRole } from '@wix/sdk';
|
|
3
4
|
import { z } from 'astro/zod';
|
|
@@ -17,11 +18,7 @@ const tokensSchema = z.object({
|
|
|
17
18
|
}),
|
|
18
19
|
});
|
|
19
20
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
export function getSessionTokensFromCookie(
|
|
23
|
-
context: APIContext
|
|
24
|
-
): null | SessionTokens {
|
|
21
|
+
export function getSessionTokensFromCookie(context: APIContext): null | Tokens {
|
|
25
22
|
if (!context.isPrerendered) {
|
|
26
23
|
const rawCookie = context.cookies.get('wixSession')?.json() as unknown;
|
|
27
24
|
|
|
@@ -32,7 +29,7 @@ export function getSessionTokensFromCookie(
|
|
|
32
29
|
tokensParseResult.success &&
|
|
33
30
|
tokensParseResult.data.clientId === WIX_CLIENT_ID
|
|
34
31
|
) {
|
|
35
|
-
return tokensParseResult.data;
|
|
32
|
+
return tokensParseResult.data.tokens;
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
}
|
package/src/utils/loadEnvVars.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function loadEnvVars(logger: AstroIntegrationLogger): {
|
|
|
20
20
|
wixClientIdEnvVar
|
|
21
21
|
)} environment variable.
|
|
22
22
|
💡 To pull the required environment variables from Wix, run:
|
|
23
|
-
${chalk.magenta('npx wix
|
|
23
|
+
${chalk.magenta('npx wix env pull')}
|
|
24
24
|
🔍 Need Help?
|
|
25
25
|
- Visit our docs: https://dev.wix.com/docs/go-headless
|
|
26
26
|
- Join the community: https://discord.com/channels/1114269395317968906/1288424190969511987
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function injectAfterTransformStream(
|
|
2
|
+
predicate: RegExp,
|
|
3
|
+
htmlToInject: string
|
|
4
|
+
): TransformStream<string> {
|
|
5
|
+
let hasInjected = false;
|
|
6
|
+
return new TransformStream<string>({
|
|
7
|
+
transform: (chunk, controller) => {
|
|
8
|
+
if (!hasInjected) {
|
|
9
|
+
const index = predicate.exec(chunk);
|
|
10
|
+
if (index) {
|
|
11
|
+
const position = index.index + index[0].length;
|
|
12
|
+
chunk =
|
|
13
|
+
chunk.slice(0, position) + htmlToInject + chunk.slice(position);
|
|
14
|
+
hasInjected = true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
controller.enqueue(chunk);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function injectBeforeTransformStream(
|
|
23
|
+
predicate: string,
|
|
24
|
+
htmlToInject: string
|
|
25
|
+
): TransformStream<string> {
|
|
26
|
+
let hasInjected = false;
|
|
27
|
+
return new TransformStream<string>({
|
|
28
|
+
transform: (chunk, controller) => {
|
|
29
|
+
if (!hasInjected) {
|
|
30
|
+
const index = chunk.indexOf(predicate);
|
|
31
|
+
if (index > -1) {
|
|
32
|
+
chunk = chunk.slice(0, index) + htmlToInject + chunk.slice(index);
|
|
33
|
+
hasInjected = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
controller.enqueue(chunk);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -64,9 +64,14 @@ export async function writeVirtualBackofficeExtensionFiles(
|
|
|
64
64
|
import { WrappedComponent } from '${toRelativePath(virtualEntrypoint, virtualHocEntrypoint)}';
|
|
65
65
|
---
|
|
66
66
|
|
|
67
|
-
<
|
|
68
|
-
<
|
|
69
|
-
|
|
67
|
+
<html lang="en">
|
|
68
|
+
<head></head>
|
|
69
|
+
<body>
|
|
70
|
+
<div>
|
|
71
|
+
<WrappedComponent client:only="react" />
|
|
72
|
+
</div>
|
|
73
|
+
</body>
|
|
74
|
+
</html>
|
|
70
75
|
`
|
|
71
76
|
);
|
|
72
77
|
}
|
package/tsup.config.mjs
CHANGED
|
@@ -52,6 +52,9 @@ export default defineConfig([
|
|
|
52
52
|
'src/routes/auth/logout.ts',
|
|
53
53
|
'src/routes/auth/callback.ts',
|
|
54
54
|
'src/routes/auth/logout-callback.ts',
|
|
55
|
+
|
|
56
|
+
// html embeds
|
|
57
|
+
'src/middleware/html-embeds.ts',
|
|
55
58
|
],
|
|
56
59
|
external: [...astroExternals, ...viteExternals],
|
|
57
60
|
format: ['esm'],
|