@wix/astro 1.0.34 → 1.0.35

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.
Files changed (115) hide show
  1. package/build/fsevents-X6WP4TKM.node +0 -0
  2. package/build/index.d.ts +9 -0
  3. package/build/index.js +17347 -0
  4. package/build/index.js.map +1 -0
  5. package/build-browser-runtime/setup.d.ts +5 -0
  6. package/build-browser-runtime/setup.js +963 -0
  7. package/build-runtime/auth.d.ts +5 -0
  8. package/build-runtime/auth.js +3557 -0
  9. package/build-runtime/chunk-24J7STEA.js +8 -0
  10. package/build-runtime/chunk-B6RICTPP.js +94 -0
  11. package/build-runtime/chunk-C3QOE2TZ.js +7 -0
  12. package/build-runtime/chunk-EK7YZVWJ.js +353 -0
  13. package/build-runtime/chunk-FR26HCAT.js +471 -0
  14. package/build-runtime/chunk-HDTWPOIV.js +811 -0
  15. package/build-runtime/chunk-HPW4ZAEJ.js +23 -0
  16. package/build-runtime/chunk-JODQ44LE.js +1079 -0
  17. package/build-runtime/chunk-MLKGABMK.js +9 -0
  18. package/build-runtime/chunk-NVTQFGTR.js +7 -0
  19. package/build-runtime/chunk-PSHIUVP2.js +131 -0
  20. package/build-runtime/chunk-Q3KPY4P2.js +3104 -0
  21. package/build-runtime/chunk-QRPWKJ4C.js +41 -0
  22. package/build-runtime/chunk-RKE6XT5Z.js +3104 -0
  23. package/build-runtime/chunk-UZPSWWI5.js +13 -0
  24. package/build-runtime/chunk-VMS3NKCF.js +18 -0
  25. package/build-runtime/chunk-W73LN534.js +24 -0
  26. package/build-runtime/chunk-WYNC47R3.js +7 -0
  27. package/build-runtime/chunk-YMZMZCBN.js +4063 -0
  28. package/build-runtime/chunk-YX6EVX5Q.js +11 -0
  29. package/build-runtime/context/elevated.d.ts +2 -0
  30. package/build-runtime/context/elevated.js +25 -0
  31. package/build-runtime/context/non-elevated.d.ts +2 -0
  32. package/build-runtime/context/non-elevated.js +32 -0
  33. package/build-runtime/context/nonElevated.d.ts +2 -0
  34. package/build-runtime/context/nonElevated.js +38 -0
  35. package/build-runtime/context/setupServicePlugin.d.ts +5 -0
  36. package/build-runtime/context/setupServicePlugin.js +16 -0
  37. package/build-runtime/context/setupWebhook.d.ts +5 -0
  38. package/build-runtime/context/setupWebhook.js +16 -0
  39. package/build-runtime/middleware/auth.d.ts +5 -0
  40. package/build-runtime/middleware/auth.js +74 -0
  41. package/build-runtime/middleware/html-embeds.d.ts +5 -0
  42. package/build-runtime/middleware/html-embeds.js +166 -0
  43. package/build-runtime/routes/auth/callback.d.ts +5 -0
  44. package/{src/routes/auth/callback.ts → build-runtime/routes/auth/callback.js} +30 -29
  45. package/build-runtime/routes/auth/login.d.ts +5 -0
  46. package/build-runtime/routes/auth/login.js +45 -0
  47. package/build-runtime/routes/auth/logout-callback.d.ts +5 -0
  48. package/build-runtime/routes/auth/logout-callback.js +23 -0
  49. package/build-runtime/routes/auth/logout.d.ts +5 -0
  50. package/build-runtime/routes/auth/logout.js +32 -0
  51. package/build-runtime/routes/paylink/checkout.d.ts +5 -0
  52. package/build-runtime/routes/paylink/checkout.js +35 -0
  53. package/build-runtime/routes/paylink/paylink.d.ts +5 -0
  54. package/build-runtime/routes/paylink/paylink.js +34 -0
  55. package/build-runtime/routes/robots/robots.d.ts +5 -0
  56. package/build-runtime/routes/robots/robots.js +44 -0
  57. package/build-runtime/routes/service-plugins.d.ts +5 -0
  58. package/build-runtime/routes/service-plugins.js +11 -0
  59. package/build-runtime/routes/servicePluginsDevRoute.d.ts +5 -0
  60. package/build-runtime/routes/servicePluginsDevRoute.js +13 -0
  61. package/build-runtime/routes/webhooks.d.ts +5 -0
  62. package/build-runtime/routes/webhooks.js +11 -0
  63. package/build-runtime/routes/webhooksDevRoute.d.ts +5 -0
  64. package/build-runtime/routes/webhooksDevRoute.js +13 -0
  65. package/build-runtime/routes/wix-apis/api.d.ts +5 -0
  66. package/build-runtime/routes/wix-apis/api.js +34 -0
  67. package/package.json +7 -1
  68. package/src/client-context/setup.ts +0 -14
  69. package/src/client-context/utils.ts +0 -59
  70. package/src/components.ts +0 -98
  71. package/src/constants.ts +0 -2
  72. package/src/context/elevated.ts +0 -20
  73. package/src/context/hostProxy.ts +0 -38
  74. package/src/context/nonElevated.ts +0 -42
  75. package/src/context/setupServicePlugin.ts +0 -13
  76. package/src/context/setupWebhook.ts +0 -13
  77. package/src/context/utils.ts +0 -32
  78. package/src/directories.ts +0 -5
  79. package/src/env.d.ts +0 -11
  80. package/src/index.ts +0 -302
  81. package/src/middleware/auth.ts +0 -38
  82. package/src/middleware/html-embeds.ts +0 -59
  83. package/src/plugins/patchAstroInlineScripts.ts +0 -27
  84. package/src/plugins/patchGlobal.ts +0 -20
  85. package/src/plugins/setupSsrContext.ts +0 -77
  86. package/src/routes/auth/login.ts +0 -42
  87. package/src/routes/auth/logout-callback.ts +0 -18
  88. package/src/routes/auth/logout.ts +0 -28
  89. package/src/routes/paylink/checkout.ts +0 -28
  90. package/src/routes/paylink/paylink.ts +0 -33
  91. package/src/routes/robots/robots.ts +0 -40
  92. package/src/routes/servicePluginsDevRoute.ts +0 -10
  93. package/src/routes/webhooksDevRoute.ts +0 -10
  94. package/src/routes/wix-apis/api.ts +0 -31
  95. package/src/schemas.ts +0 -227
  96. package/src/types.ts +0 -9
  97. package/src/utils/authAsyncLocalStorage.ts +0 -7
  98. package/src/utils/buildBackofficeComponent.ts +0 -64
  99. package/src/utils/buildComponents.ts +0 -182
  100. package/src/utils/buildServicePluginComponent.ts +0 -52
  101. package/src/utils/buildWebhookComponent.ts +0 -39
  102. package/src/utils/contextualAuth.ts +0 -4
  103. package/src/utils/createProjectModel.ts +0 -190
  104. package/src/utils/fs-utils.ts +0 -48
  105. package/src/utils/generateAppManifest.ts +0 -177
  106. package/src/utils/generateVisitorTokens.ts +0 -11
  107. package/src/utils/getSessionTokensFromCookie.ts +0 -38
  108. package/src/utils/loadEnvVars.ts +0 -47
  109. package/src/utils/normalizeWixRedirectUrl.ts +0 -11
  110. package/src/utils/removeUnusedCodegenFiles.ts +0 -34
  111. package/src/utils/resolveBuildMetadata.ts +0 -37
  112. package/src/utils/saveSessionTokensToCookie.ts +0 -27
  113. package/src/utils/transformStreamUtils.ts +0 -39
  114. package/tsconfig.json +0 -9
  115. package/tsup.config.mjs +0 -89
package/src/index.ts DELETED
@@ -1,302 +0,0 @@
1
- import { join } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import type { AstroConfig, AstroIntegration } from 'astro';
4
- import { envField, passthroughImageService } from 'astro/config';
5
- import chokidar from 'chokidar';
6
- import { outdent } from 'outdent';
7
- import { EXTENSIONS_DIR, GIT_IGNORED_DIR } from './directories.js';
8
- import { patchAstroInlineScripts } from './plugins/patchAstroInlineScripts.js';
9
- import { patchGlobal } from './plugins/patchGlobal.js';
10
- import { setupSsrContext } from './plugins/setupSsrContext.js';
11
- import { buildComponents } from './utils/buildComponents.js';
12
- import { createProjectModel } from './utils/createProjectModel.js';
13
- import { clearDir, writeJson } from './utils/fs-utils.js';
14
- import { generateAppManifest } from './utils/generateAppManifest.js';
15
- import { removeUnusedCodegenFiles } from './utils/removeUnusedCodegenFiles.js';
16
- import { resolveBuildMetadata } from './utils/resolveBuildMetadata.js';
17
-
18
- interface WixIntegrationOptions {
19
- enableAuthRoutes?: boolean;
20
- enableHtmlEmbeds?: boolean;
21
- }
22
-
23
- const createIntegration = (
24
- options: WixIntegrationOptions = {
25
- enableAuthRoutes: true,
26
- enableHtmlEmbeds: true,
27
- }
28
- ): AstroIntegration => {
29
- let _config: AstroConfig;
30
-
31
- return {
32
- hooks: {
33
- async 'astro:build:done'({ logger }) {
34
- const rootDir = fileURLToPath(_config.root);
35
-
36
- const model = await createProjectModel({ logger, rootDir });
37
- const appManifest = generateAppManifest(model);
38
-
39
- const outDir = fileURLToPath(_config.outDir);
40
-
41
- const appManifestPath = join(outDir, '_wix/app-manifest.json');
42
-
43
- await writeJson(appManifestPath, appManifest, { spaces: 2 });
44
-
45
- await writeJson(
46
- join(rootDir, GIT_IGNORED_DIR, 'build-metadata.json'),
47
- await resolveBuildMetadata(appManifestPath, _config),
48
- { spaces: 2 }
49
- );
50
- },
51
- 'astro:config:done': ({ config }) => {
52
- _config = config;
53
- },
54
- async 'astro:config:setup'({
55
- addMiddleware,
56
- command,
57
- config,
58
- createCodegenDir,
59
- injectRoute,
60
- injectScript,
61
- logger,
62
- updateConfig,
63
- }) {
64
- const isDev = command === 'dev';
65
-
66
- const codegenDirURL = createCodegenDir();
67
- const codegenDir = fileURLToPath(codegenDirURL);
68
- const rootDir = fileURLToPath(config.root);
69
- const extensionsDir = join(codegenDir, 'extensions');
70
-
71
- const model = await createProjectModel({ logger, rootDir });
72
-
73
- // support client-side context calls
74
- injectScript(
75
- 'before-hydration',
76
- outdent`
77
- import { WIX_CLIENT_ID } from 'astro:env/client';
78
- import { setup } from '@wix/astro/context/setup';
79
-
80
- setup({ clientId: WIX_CLIENT_ID });
81
- `
82
- );
83
-
84
- injectScript(
85
- 'page',
86
- outdent`
87
- import { WIX_CLIENT_ID } from 'astro:env/client';
88
- import { setup } from '@wix/astro/context/setup';
89
-
90
- setup({ clientId: WIX_CLIENT_ID });
91
- `
92
- );
93
-
94
- // support server side context calls
95
- addMiddleware({
96
- entrypoint: new URL(
97
- '../build-runtime/middleware/auth.js',
98
- import.meta.url
99
- ),
100
- order: 'pre',
101
- });
102
-
103
- // support HTML embeds
104
- if (options.enableHtmlEmbeds) {
105
- addMiddleware({
106
- entrypoint: new URL(
107
- '../build-runtime/middleware/html-embeds.js',
108
- import.meta.url
109
- ),
110
- order: 'post',
111
- });
112
- }
113
-
114
- // support auth routes
115
- if (options.enableAuthRoutes) {
116
- injectRoute({
117
- entrypoint: new URL(
118
- '../build-runtime/routes/auth/login.js',
119
- import.meta.url
120
- ),
121
- pattern: '/api/auth/login',
122
- prerender: false,
123
- });
124
-
125
- injectRoute({
126
- entrypoint: new URL(
127
- '../build-runtime/routes/auth/logout.js',
128
- import.meta.url
129
- ),
130
- pattern: '/api/auth/logout',
131
- prerender: false,
132
- });
133
-
134
- injectRoute({
135
- entrypoint: new URL(
136
- '../build-runtime/routes/auth/callback.js',
137
- import.meta.url
138
- ),
139
- pattern: '/api/auth/callback',
140
- prerender: false,
141
- });
142
-
143
- injectRoute({
144
- entrypoint: new URL(
145
- '../build-runtime/routes/auth/logout-callback.js',
146
- import.meta.url
147
- ),
148
- pattern: '/api/auth/logout-callback',
149
- prerender: false,
150
- });
151
- }
152
-
153
- injectRoute({
154
- entrypoint: new URL(
155
- '../build-runtime/routes/paylink/paylink.js',
156
- import.meta.url
157
- ),
158
- pattern: '/_paylink/[id]',
159
- prerender: false,
160
- });
161
-
162
- injectRoute({
163
- entrypoint: new URL(
164
- '../build-runtime/routes/paylink/checkout.js',
165
- import.meta.url
166
- ),
167
- pattern: '/checkout',
168
- prerender: false,
169
- });
170
-
171
- injectRoute({
172
- entrypoint: new URL(
173
- '../build-runtime/routes/paylink/checkout.js',
174
- import.meta.url
175
- ),
176
- // https://github.com/wix-private/wix-cli-one/pull/205/files#r2312298435
177
- pattern: '/__ecom/checkout',
178
- prerender: false,
179
- });
180
-
181
- injectRoute({
182
- entrypoint: new URL(
183
- '../build-runtime/routes/robots/robots.js',
184
- import.meta.url
185
- ),
186
- pattern: '/robots.txt',
187
- prerender: false,
188
- });
189
-
190
- injectRoute({
191
- entrypoint: new URL(
192
- '../build-runtime/routes/wix-apis/api.js',
193
- import.meta.url
194
- ),
195
- pattern: '/_api/[...path]',
196
- prerender: false,
197
- });
198
-
199
- updateConfig({
200
- env: {
201
- schema: {
202
- WIX_CLIENT_ID: envField.string({
203
- access: 'public',
204
- context: 'client',
205
- }),
206
- WIX_CLIENT_INSTANCE_ID: envField.string({
207
- access: 'secret',
208
- context: 'server',
209
- }),
210
- WIX_CLIENT_PUBLIC_KEY: envField.string({
211
- access: 'secret',
212
- context: 'server',
213
- }),
214
- WIX_CLIENT_SECRET: envField.string({
215
- access: 'secret',
216
- context: 'server',
217
- }),
218
- },
219
- },
220
- image: {
221
- domains: ['static.wixstatic.com'],
222
- service: passthroughImageService(),
223
- },
224
- vite: {
225
- plugins: [
226
- patchGlobal(),
227
- patchAstroInlineScripts(),
228
- setupSsrContext(rootDir),
229
- ],
230
- },
231
- });
232
-
233
- // build relevant wix extensions
234
- await clearDir(codegenDir);
235
- await buildComponents({ extensionsDir, injectRoute, isDev, model });
236
-
237
- if (isDev) {
238
- injectRoute({
239
- entrypoint: new URL('../runtime/entry.astro', import.meta.url),
240
- pattern: `/_wix/extensions/backoffice/[compId]`,
241
- prerender: false,
242
- });
243
-
244
- injectRoute({
245
- entrypoint: new URL(
246
- '../build-runtime/routes/webhooksDevRoute.js',
247
- import.meta.url
248
- ),
249
- pattern: `/_wix/extensions/webhooks/[compId]`,
250
- prerender: false,
251
- });
252
-
253
- injectRoute({
254
- entrypoint: new URL(
255
- '../build-runtime/routes/servicePluginsDevRoute.js',
256
- import.meta.url
257
- ),
258
- pattern: `/_wix/extensions/service-plugins/[compId]`,
259
- prerender: false,
260
- });
261
-
262
- chokidar
263
- .watch([EXTENSIONS_DIR], {
264
- cwd: rootDir,
265
- ignoreInitial: true,
266
- useFsEvents: false,
267
- })
268
- .on('all', async () => {
269
- const model = await createProjectModel({ logger, rootDir });
270
-
271
- await removeUnusedCodegenFiles({ extensionsDir, model });
272
-
273
- await buildComponents({
274
- extensionsDir,
275
- injectRoute,
276
- isDev,
277
- model,
278
- });
279
- });
280
- }
281
- },
282
- 'astro:server:setup': ({ logger, server }) => {
283
- const rootDir = fileURLToPath(_config.root);
284
-
285
- server.middlewares.use(async (req, res, next) => {
286
- if (req.url === '/_wix/app-manifest.json') {
287
- const model = await createProjectModel({ logger, rootDir });
288
- const appManifest = generateAppManifest(model);
289
- res.setHeader('Content-Type', 'application/json');
290
- res.end(JSON.stringify(appManifest));
291
- return;
292
- }
293
-
294
- next();
295
- });
296
- },
297
- },
298
- name: '@wix/astro',
299
- };
300
- };
301
-
302
- export default createIntegration;
@@ -1,38 +0,0 @@
1
- import type { APIContext, MiddlewareHandler } from 'astro';
2
- import { authAsyncLocalStorage } from '../utils/authAsyncLocalStorage.js';
3
- import { generateVisitorTokens } from '../utils/generateVisitorTokens.js';
4
- import { getSessionTokensFromCookie } from '../utils/getSessionTokensFromCookie.js';
5
- import { saveSessionTokensToCookie } from '../utils/saveSessionTokensToCookie.js';
6
-
7
- export const onRequest: MiddlewareHandler = async (context, next) => {
8
- const existingTokens = getExistingTokens(context);
9
- const usedTokens = existingTokens ?? (await generateVisitorTokens());
10
-
11
- const store = {
12
- request: context.request,
13
- sessionTokens: usedTokens,
14
- };
15
-
16
- const response = await authAsyncLocalStorage.run(store, async () => {
17
- return next();
18
- });
19
-
20
- if (!context.isPrerendered && existingTokens !== usedTokens) {
21
- saveSessionTokensToCookie(context, usedTokens);
22
- }
23
-
24
- return response;
25
- };
26
-
27
- function getExistingTokens(context: APIContext) {
28
- const existingTokens = getSessionTokensFromCookie(context);
29
-
30
- if (
31
- existingTokens &&
32
- existingTokens.accessToken.expiresAt + 600 > Date.now() / 1000
33
- ) {
34
- return existingTokens;
35
- }
36
-
37
- return null;
38
- }
@@ -1,59 +0,0 @@
1
- import type { MiddlewareHandler } from 'astro';
2
- import { scripts } from '@wix/headless-site-assets';
3
- import {
4
- injectAfterTransformStream,
5
- injectBeforeTransformStream,
6
- } from '../utils/transformStreamUtils.js';
7
-
8
- const bodyEndTransformStream = (htmlToInject: string) =>
9
- injectBeforeTransformStream('</body>', htmlToInject);
10
-
11
- const headTransformStream = (htmlToInject: string) =>
12
- injectBeforeTransformStream('</head>', htmlToInject);
13
-
14
- const bodyStartTransformStream = (htmlToInject: string) =>
15
- injectAfterTransformStream(/<body(?![^>]*\/>)[^>]*>/, htmlToInject);
16
-
17
- export const onRequest: MiddlewareHandler = async (context, next) => {
18
- const response = await next();
19
- const contentType = response.headers.get('Content-Type');
20
-
21
- if (contentType !== 'text/html') {
22
- return response;
23
- }
24
-
25
- if (context.url.pathname.startsWith('/_wix')) {
26
- return response;
27
- }
28
-
29
- const { siteScripts } = await scripts.listSiteScripts();
30
-
31
- if (siteScripts == null) {
32
- throw new Error('Could not fetch site scripts');
33
- }
34
-
35
- const headInjection = siteScripts
36
- .filter((x) => x.position === 'HEAD')
37
- .map((x) => x.html)
38
- .join('\n');
39
-
40
- const bodyStartInjection = siteScripts
41
- .filter((x) => x.position === 'BODY_START')
42
- .map((x) => x.html)
43
- .join('\n');
44
-
45
- const bodyEndInjection = siteScripts
46
- .filter((x) => x.position === 'BODY_END')
47
- .map((x) => x.html)
48
- .join('\n');
49
-
50
- return new Response(
51
- response.body
52
- ?.pipeThrough(new TextDecoderStream())
53
- .pipeThrough(headTransformStream(headInjection))
54
- .pipeThrough(bodyStartTransformStream(bodyStartInjection))
55
- .pipeThrough(bodyEndTransformStream(bodyEndInjection))
56
- .pipeThrough(new TextEncoderStream()),
57
- response
58
- );
59
- };
@@ -1,27 +0,0 @@
1
- import type { PluginOption } from 'vite';
2
- import { outdent } from 'outdent';
3
-
4
- export function patchAstroInlineScripts(): PluginOption {
5
- return {
6
- name: 'patch-astro-inline-scripts',
7
- transform(code, id) {
8
- const [_filename, rawQuery] = id.split(`?`, 2);
9
- const query = Object.fromEntries(new URLSearchParams(rawQuery).entries());
10
-
11
- if (
12
- query.astro == null ||
13
- query.type !== 'script' ||
14
- query['lang.ts'] == null ||
15
- code === ''
16
- ) {
17
- return null;
18
- }
19
-
20
- return outdent`
21
- import 'astro:scripts/page.js';
22
-
23
- ${code}
24
- `;
25
- },
26
- };
27
- }
@@ -1,20 +0,0 @@
1
- import type { PluginOption } from 'vite';
2
-
3
- // - https://github.com/facebookarchive/draft-js/issues/2127
4
- // - https://github.com/facebook/fbjs/issues/290
5
- const define = { global: 'window' } as const;
6
-
7
- export function patchGlobal(): PluginOption {
8
- return [
9
- {
10
- apply: 'serve',
11
- config: () => ({ optimizeDeps: { esbuildOptions: { define } } }),
12
- name: 'fix-draft-js',
13
- },
14
- {
15
- apply: 'build',
16
- config: () => ({ esbuild: { define } }),
17
- name: 'fix-draft-js',
18
- },
19
- ];
20
- }
@@ -1,77 +0,0 @@
1
- import { extname, join } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import type { PluginOption } from 'vite';
4
- import { outdent } from 'outdent';
5
- import { SRC_DIR } from '../directories.js';
6
-
7
- // injected routes
8
- const nonElevatedSetupUrl = new URL(
9
- '../build-runtime/context/nonElevated.js',
10
- import.meta.url
11
- );
12
- const elevatedSetupUrl = new URL(
13
- '../build-runtime/context/elevated.js',
14
- import.meta.url
15
- );
16
-
17
- // white-listed routes
18
- const whitelistedFilePaths = [
19
- fileURLToPath(
20
- new URL('../build-runtime/routes/auth/login.js', import.meta.url)
21
- ),
22
- fileURLToPath(
23
- new URL('../build-runtime/routes/auth/callback.js', import.meta.url)
24
- ),
25
- fileURLToPath(
26
- new URL('../build-runtime/routes/auth/logout.js', import.meta.url)
27
- ),
28
- fileURLToPath(
29
- new URL('../build-runtime/routes/auth/logout-callback.js', import.meta.url)
30
- ),
31
- fileURLToPath(
32
- new URL('../build-runtime/routes/paylink/paylink.js', import.meta.url)
33
- ),
34
- fileURLToPath(
35
- new URL('../build-runtime/routes/paylink/checkout.js', import.meta.url)
36
- ),
37
- fileURLToPath(
38
- new URL('../build-runtime/routes/robots/robots.js', import.meta.url)
39
- ),
40
- fileURLToPath(
41
- new URL('../build-runtime/routes/wix-apis/api.js', import.meta.url)
42
- ),
43
- ];
44
-
45
- export function setupSsrContext(rootDir: string): PluginOption {
46
- const srcDir = join(rootDir, SRC_DIR);
47
-
48
- return {
49
- applyToEnvironment(environment) {
50
- return environment.name === 'ssr';
51
- },
52
- name: 'setup-ssr-context',
53
- transform(code, id) {
54
- if (!id.startsWith(srcDir) && !whitelistedFilePaths.includes(id)) {
55
- return null;
56
- }
57
-
58
- const extension = extname(id);
59
-
60
- if (
61
- extension !== '.js' &&
62
- extension !== '.astro' &&
63
- extension !== '.ts' &&
64
- extension !== '.tsx'
65
- ) {
66
- return null;
67
- }
68
-
69
- return outdent`
70
- import '${nonElevatedSetupUrl}';
71
- import '${elevatedSetupUrl}';
72
-
73
- ${code}
74
- `;
75
- },
76
- };
77
- }
@@ -1,42 +0,0 @@
1
- import type { APIRoute } from 'astro';
2
- import * as z from 'zod/v4';
3
- import { oAuthStateCookieName } from '../../constants.js';
4
- import { auth } from '../../utils/contextualAuth.js';
5
-
6
- const loginSearchParams = z.object({
7
- prompt: z.enum(['login', 'none']).optional(),
8
- returnToUrl: z.string().optional(),
9
- });
10
-
11
- export const GET: APIRoute = async ({ request, url }) => {
12
- const { prompt, returnToUrl = '/' } = loginSearchParams.parse(
13
- Object.fromEntries(url.searchParams.entries())
14
- );
15
-
16
- const callbackUrl = new URL('/api/auth/callback', url);
17
- const referer = request.headers.get('referer');
18
-
19
- if (referer != null) {
20
- const originalUrl = new URL(referer);
21
- callbackUrl.protocol = originalUrl.protocol;
22
- }
23
-
24
- const oauthData = auth.generateOAuthData(callbackUrl.toString(), returnToUrl);
25
-
26
- const { authUrl } = await auth.getAuthUrl(oauthData, {
27
- prompt,
28
- responseMode: 'query',
29
- });
30
-
31
- const sameSite = import.meta.env.DEV ? 'None' : 'Lax';
32
-
33
- return new Response(null, {
34
- headers: {
35
- Location: authUrl,
36
- 'Set-Cookie': `${oAuthStateCookieName}=${JSON.stringify(
37
- oauthData
38
- )}; Max-Age=1800; Path=/; HttpOnly; Secure; SameSite=${sameSite}`,
39
- },
40
- status: 302,
41
- });
42
- };
@@ -1,18 +0,0 @@
1
- import type { APIRoute } from 'astro';
2
- import { returnToQueryParamName } from '../../constants.js';
3
- import { auth } from '../../utils/contextualAuth.js';
4
- import { saveSessionTokensToCookie } from '../../utils/saveSessionTokensToCookie.js';
5
-
6
- export const GET: APIRoute = async (context) => {
7
- const returnTo = context.url.searchParams.get(returnToQueryParamName) ?? '/';
8
-
9
- if (!returnTo.startsWith('/')) {
10
- throw new Error(
11
- `Invalid \`${returnToQueryParamName}\` query param, only relative URLs are allowed`
12
- );
13
- }
14
-
15
- saveSessionTokensToCookie(context, await auth.generateVisitorTokens());
16
-
17
- return context.redirect(returnTo);
18
- };
@@ -1,28 +0,0 @@
1
- import type { APIRoute } from 'astro';
2
- import * as z from 'zod/v4';
3
- import { returnToQueryParamName } from '../../constants.js';
4
- import { auth } from '../../utils/contextualAuth.js';
5
-
6
- const logoutSearchParams = z.object({
7
- returnToUrl: z.string().optional(),
8
- });
9
-
10
- export const POST: APIRoute = async ({ redirect, request, url }) => {
11
- const { returnToUrl = '/' } = logoutSearchParams.parse(
12
- Object.fromEntries(url.searchParams.entries())
13
- );
14
- const baseUrl = `${new URL(request.url).origin}/${import.meta.env.BASE_URL}`;
15
- const postFlowUrl = new URL('/api/auth/logout-callback', baseUrl);
16
- const referer = request.headers.get('referer');
17
-
18
- if (referer != null) {
19
- const originalUrl = new URL(referer);
20
- postFlowUrl.protocol = originalUrl.protocol;
21
- }
22
-
23
- postFlowUrl.searchParams.set(returnToQueryParamName, returnToUrl);
24
-
25
- const { logoutUrl } = await auth.logout(postFlowUrl.toString());
26
-
27
- return redirect(logoutUrl);
28
- };
@@ -1,28 +0,0 @@
1
- import type { APIRoute } from 'astro';
2
- import { oAuthApps } from '@wix/auth-management';
3
- import { auth } from '@wix/essentials';
4
- import { WIX_CLIENT_ID } from 'astro:env/client';
5
- import { normalizeWixRedirectUrl } from '../../utils/normalizeWixRedirectUrl.js';
6
-
7
- export const GET: APIRoute = async ({ url }) => {
8
- const { redirectUrlWixPages } = await auth.elevate(oAuthApps.getOAuthApp)(
9
- WIX_CLIENT_ID
10
- );
11
-
12
- if (redirectUrlWixPages == null) {
13
- throw new Error(`Invalid Redirect URL: '${redirectUrlWixPages}'`);
14
- }
15
-
16
- const baseUrl = normalizeWixRedirectUrl({
17
- wixRedirectUrl: redirectUrlWixPages,
18
- });
19
- const newCheckoutUrl = new URL(
20
- url.pathname.replace('/', '') + url.search,
21
- baseUrl
22
- );
23
-
24
- return new Response(null, {
25
- headers: { Location: newCheckoutUrl.toString() },
26
- status: 302,
27
- });
28
- };
@@ -1,33 +0,0 @@
1
- import type { APIRoute } from 'astro';
2
- import { oAuthApps } from '@wix/auth-management';
3
- import { auth } from '@wix/essentials';
4
- import { WIX_CLIENT_ID } from 'astro:env/client';
5
-
6
- export const GET: APIRoute = async ({ params }) => {
7
- try {
8
- const { redirectUrlWixPages } = await auth.elevate(oAuthApps.getOAuthApp)(
9
- WIX_CLIENT_ID
10
- );
11
-
12
- if (redirectUrlWixPages == null) {
13
- throw new Error(`Invalid Redirect URL: ${redirectUrlWixPages}`);
14
- }
15
-
16
- const paylinkId = params.id;
17
-
18
- const baseUrl = redirectUrlWixPages.endsWith('/')
19
- ? redirectUrlWixPages
20
- : `${redirectUrlWixPages}/`;
21
-
22
- const paylinkUrl = new URL(`_paylink/${paylinkId}`, baseUrl);
23
-
24
- return new Response(null, {
25
- headers: { Location: paylinkUrl.toString() },
26
- status: 302,
27
- });
28
- } catch (error) {
29
- throw new Error(
30
- `Error while constructing Paylink URL: ${JSON.stringify(error)}`
31
- );
32
- }
33
- };