edge-functions 1.0.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/.babelrc +13 -0
- package/.eslintignore +3 -0
- package/.eslintrc.json +42 -0
- package/.github/workflows/major.yml +28 -0
- package/.github/workflows/minor.yml +31 -0
- package/.vscode/settings.json +20 -0
- package/CODEOWNERS +2 -0
- package/CODE_OF_CONDUCT.md +73 -0
- package/CONTRIBUTING.md +90 -0
- package/LICENSE.md +21 -0
- package/README.md +60 -0
- package/aliases.js +13 -0
- package/docs/overview.md +36 -0
- package/docs/presets.md +115 -0
- package/examples/angular-static/.editorconfig +16 -0
- package/examples/angular-static/README.md +27 -0
- package/examples/angular-static/angular.json +98 -0
- package/examples/angular-static/package.json +39 -0
- package/examples/angular-static/src/app/app-routing.module.ts +10 -0
- package/examples/angular-static/src/app/app.component.css +0 -0
- package/examples/angular-static/src/app/app.component.html +484 -0
- package/examples/angular-static/src/app/app.component.spec.ts +29 -0
- package/examples/angular-static/src/app/app.component.ts +10 -0
- package/examples/angular-static/src/app/app.module.ts +18 -0
- package/examples/angular-static/src/assets/.gitkeep +0 -0
- package/examples/angular-static/src/favicon.ico +0 -0
- package/examples/angular-static/src/index.html +13 -0
- package/examples/angular-static/src/main.ts +7 -0
- package/examples/angular-static/src/styles.css +1 -0
- package/examples/angular-static/tsconfig.app.json +14 -0
- package/examples/angular-static/tsconfig.json +33 -0
- package/examples/angular-static/tsconfig.spec.json +14 -0
- package/examples/astro-static/README.md +55 -0
- package/examples/astro-static/astro.config.mjs +5 -0
- package/examples/astro-static/package.json +15 -0
- package/examples/astro-static/public/favicon.svg +9 -0
- package/examples/astro-static/src/components/Card.astro +63 -0
- package/examples/astro-static/src/env.d.ts +1 -0
- package/examples/astro-static/src/layouts/Layout.astro +36 -0
- package/examples/astro-static/src/pages/edge/index.astro +55 -0
- package/examples/astro-static/src/pages/index.astro +81 -0
- package/examples/astro-static/tsconfig.json +3 -0
- package/examples/hexo-static/.github/dependabot.yml +7 -0
- package/examples/hexo-static/_config.landscape.yml +0 -0
- package/examples/hexo-static/_config.yml +105 -0
- package/examples/hexo-static/package.json +26 -0
- package/examples/hexo-static/scaffolds/draft.md +4 -0
- package/examples/hexo-static/scaffolds/page.md +4 -0
- package/examples/hexo-static/scaffolds/post.md +5 -0
- package/examples/hexo-static/source/_posts/hello-world.md +38 -0
- package/examples/hexo-static/source/_posts/other-page.md +62 -0
- package/examples/hexo-static/themes/.gitkeep +0 -0
- package/examples/hexo-static/yarn.lock +1625 -0
- package/examples/next-12-static/.babelrc +3 -0
- package/examples/next-12-static/README.md +21 -0
- package/examples/next-12-static/components/post.jsx +27 -0
- package/examples/next-12-static/package-lock.json +6191 -0
- package/examples/next-12-static/package.json +18 -0
- package/examples/next-12-static/pages/index.jsx +34 -0
- package/examples/next-12-static/pages/post/[id].jsx +63 -0
- package/examples/next-static/README.md +34 -0
- package/examples/next-static/jsconfig.json +7 -0
- package/examples/next-static/next.config.js +9 -0
- package/examples/next-static/package.json +16 -0
- package/examples/next-static/public/next.svg +1 -0
- package/examples/next-static/public/vercel.svg +1 -0
- package/examples/next-static/src/app/blog/[slug]/page.js +27 -0
- package/examples/next-static/src/app/favicon.ico +0 -0
- package/examples/next-static/src/app/globals.css +107 -0
- package/examples/next-static/src/app/layout.js +17 -0
- package/examples/next-static/src/app/misty-mountains/moria/page.js +15 -0
- package/examples/next-static/src/app/page.js +96 -0
- package/examples/next-static/src/app/page.module.css +229 -0
- package/examples/next-static/yarn.lock +199 -0
- package/examples/react-static/README.md +70 -0
- package/examples/react-static/package.json +38 -0
- package/examples/react-static/public/favicon.ico +0 -0
- package/examples/react-static/public/index.html +43 -0
- package/examples/react-static/public/logo192.png +0 -0
- package/examples/react-static/public/logo512.png +0 -0
- package/examples/react-static/public/manifest.json +25 -0
- package/examples/react-static/public/robots.txt +3 -0
- package/examples/react-static/src/App.css +38 -0
- package/examples/react-static/src/App.js +25 -0
- package/examples/react-static/src/App.test.js +8 -0
- package/examples/react-static/src/index.css +13 -0
- package/examples/react-static/src/index.js +17 -0
- package/examples/react-static/src/logo.svg +1 -0
- package/examples/react-static/src/reportWebVitals.js +13 -0
- package/examples/react-static/src/setupTests.js +5 -0
- package/examples/simple-js-esm/main.js +14 -0
- package/examples/simple-js-esm/messages.js +7 -0
- package/examples/simple-js-node/main.js +18 -0
- package/examples/vue-static/README.md +24 -0
- package/examples/vue-static/babel.config.js +5 -0
- package/examples/vue-static/jsconfig.json +19 -0
- package/examples/vue-static/package.json +45 -0
- package/examples/vue-static/public/favicon.ico +0 -0
- package/examples/vue-static/public/index.html +17 -0
- package/examples/vue-static/src/App.vue +16 -0
- package/examples/vue-static/src/assets/logo.png +0 -0
- package/examples/vue-static/src/components/HelloWorld.vue +58 -0
- package/examples/vue-static/src/main.js +28 -0
- package/examples/vue-static/src/views/Home.vue +14 -0
- package/examples/vue-static/vue.config.js +4 -0
- package/jest.config.js +6 -0
- package/jsconfig.json +40 -0
- package/jsdoc.json +52 -0
- package/lib/build/bundlers/index.js +4 -0
- package/lib/build/bundlers/webpack/index.js +40 -0
- package/lib/build/bundlers/webpack/webpack.config.js +38 -0
- package/lib/build/dispatcher/dispatcher.js +211 -0
- package/lib/build/dispatcher/dispatcher.test.js +0 -0
- package/lib/build/dispatcher/index.js +3 -0
- package/lib/build/polyfills/index.js +0 -0
- package/lib/constants/azion-edges.constants.js +98 -0
- package/lib/constants/index.js +5 -0
- package/lib/constants/messages/build.messages.js +23 -0
- package/lib/constants/messages/env.messages.js +38 -0
- package/lib/constants/messages/global.messages.js +19 -0
- package/lib/constants/messages/index.js +10 -0
- package/lib/constants/messages/platform.messages.js +84 -0
- package/lib/constants/runtime-apis.constants.js +118 -0
- package/lib/env/index.js +5 -0
- package/lib/env/runtime.env.js +69 -0
- package/lib/env/server.env.js +90 -0
- package/lib/env/vulcan.env.js +93 -0
- package/lib/main.js +260 -0
- package/lib/notations/namespaces.js +30 -0
- package/lib/notations/typedef.js +10 -0
- package/lib/platform/actions/application/createApplication.actions.js +33 -0
- package/lib/platform/actions/application/enableEdgeFunctions.actions.js +34 -0
- package/lib/platform/actions/application/instantiateFunction.actions.js +37 -0
- package/lib/platform/actions/application/setFunctionAsDefaultRule.actions.js +33 -0
- package/lib/platform/actions/core/auth.actions.js +67 -0
- package/lib/platform/actions/core/deploy.actions.js +73 -0
- package/lib/platform/actions/core/propagation.actions.js +75 -0
- package/lib/platform/actions/core/storage.actions.js +84 -0
- package/lib/platform/actions/domain/createDomain.actions.js +42 -0
- package/lib/platform/actions/function/createFunction.actions.js +79 -0
- package/lib/platform/actions/function/showFunctionLogs.actions.js +149 -0
- package/lib/platform/edgehooks/ErrorHTML/ErrorHTML.hooks.js +101 -0
- package/lib/platform/edgehooks/ErrorHTML/index.js +3 -0
- package/lib/platform/edgehooks/index.js +5 -0
- package/lib/platform/edgehooks/mountSPA/index.js +3 -0
- package/lib/platform/edgehooks/mountSPA/mountSPA.hooks.js +55 -0
- package/lib/platform/edgehooks/mountSPA/mountSPA.hooks.test.js +19 -0
- package/lib/platform/edgehooks/mountSSG/index.js +3 -0
- package/lib/platform/edgehooks/mountSSG/mountSSG.hooks.js +61 -0
- package/lib/platform/edgehooks/mountSSG/mountSSG.hooks.test.js +0 -0
- package/lib/platform/index.js +65 -0
- package/lib/platform/services/application.service.js +140 -0
- package/lib/platform/services/base.service.js +200 -0
- package/lib/platform/services/domain.service.js +80 -0
- package/lib/platform/services/events.service.js +65 -0
- package/lib/platform/services/function.service.js +105 -0
- package/lib/platform/services/index.js +8 -0
- package/lib/platform/services/storage.service.js +59 -0
- package/lib/platform/services/tokens.service.js +55 -0
- package/lib/presets/custom/angular/deliver/config.js +12 -0
- package/lib/presets/custom/angular/deliver/handler.js +8 -0
- package/lib/presets/custom/angular/deliver/prebuild.js +20 -0
- package/lib/presets/custom/astro/deliver/config.js +12 -0
- package/lib/presets/custom/astro/deliver/handler.js +8 -0
- package/lib/presets/custom/astro/deliver/prebuild.js +37 -0
- package/lib/presets/custom/hexo/deliver/config.js +12 -0
- package/lib/presets/custom/hexo/deliver/handler.js +8 -0
- package/lib/presets/custom/hexo/deliver/prebuild.js +37 -0
- package/lib/presets/custom/next/deliver/config.js +14 -0
- package/lib/presets/custom/next/deliver/handler.js +9 -0
- package/lib/presets/custom/next/deliver/prebuild.js +193 -0
- package/lib/presets/custom/react/deliver/config.js +12 -0
- package/lib/presets/custom/react/deliver/handler.js +8 -0
- package/lib/presets/custom/react/deliver/prebuild.js +16 -0
- package/lib/presets/custom/vue/deliver/config.js +12 -0
- package/lib/presets/custom/vue/deliver/handler.js +8 -0
- package/lib/presets/custom/vue/deliver/prebuild.js +20 -0
- package/lib/presets/default/html/deliver/config.js +13 -0
- package/lib/presets/default/html/deliver/handler.js +9 -0
- package/lib/presets/default/html/deliver/prebuild.js +15 -0
- package/lib/presets/default/javascript/compute/config.js +13 -0
- package/lib/presets/default/javascript/compute/handler.js +5 -0
- package/lib/presets/default/javascript/compute/prebuild.js +6 -0
- package/lib/presets/default/typescript/compute/config.js +0 -0
- package/lib/presets/default/typescript/compute/handler.js +0 -0
- package/lib/presets/default/typescript/compute/prebuild.js +0 -0
- package/lib/providers/azion/worker.js +12 -0
- package/lib/utils/copyDirectory/copyDirectory.utils.js +54 -0
- package/lib/utils/copyDirectory/copyDirectory.utils.test.js +43 -0
- package/lib/utils/copyDirectory/index.js +3 -0
- package/lib/utils/debug/debug.utils.js +36 -0
- package/lib/utils/debug/debug.utils.test.js +43 -0
- package/lib/utils/debug/index.js +3 -0
- package/lib/utils/exec/exec.utils.js +58 -0
- package/lib/utils/exec/exec.utils.test.js +84 -0
- package/lib/utils/exec/index.js +3 -0
- package/lib/utils/feedback/feedback.utils.js +81 -0
- package/lib/utils/feedback/feedback.utils.test.js +11 -0
- package/lib/utils/feedback/index.js +3 -0
- package/lib/utils/generateTimestamp/generateTimestamp.utils.js +25 -0
- package/lib/utils/generateTimestamp/generateTimestamp.utils.test.js +10 -0
- package/lib/utils/generateTimestamp/index.js +3 -0
- package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.js +21 -0
- package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.test.js +13 -0
- package/lib/utils/getAbsoluteLibDirPath/index.js +3 -0
- package/lib/utils/getPackageManager/getPackageManager.utils.js +118 -0
- package/lib/utils/getPackageManager/getPackageManager.utils.test.js +35 -0
- package/lib/utils/getPackageManager/index.js +3 -0
- package/lib/utils/getPackageVersion/getPackageVersion.utils.js +25 -0
- package/lib/utils/getPackageVersion/getPackageVersion.utils.test.js +48 -0
- package/lib/utils/getPackageVersion/index.js +3 -0
- package/lib/utils/getPresetsList/getPresetsList.utils.js +50 -0
- package/lib/utils/getPresetsList/getPresetsList.utils.test.js +19 -0
- package/lib/utils/getPresetsList/index.js +3 -0
- package/lib/utils/getProjectJsonFile/getProjectJsonFile.utils.js +21 -0
- package/lib/utils/getProjectJsonFile/getProjectJsonFile.utils.test.js +39 -0
- package/lib/utils/getProjectJsonFile/index.js +3 -0
- package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.js +49 -0
- package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.test.js +36 -0
- package/lib/utils/getVulcanBuildId/index.js +3 -0
- package/lib/utils/index.js +29 -0
- package/lib/utils/overrideStaticOutputPath/index.js +3 -0
- package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.js +47 -0
- package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.test.js +35 -0
- package/lib/utils/readWorkerFile/index.js +3 -0
- package/lib/utils/readWorkerFile/readWorkerFile.utils.js +36 -0
- package/lib/utils/readWorkerFile/readWorkerFile.utils.test.js +24 -0
- package/package.json +99 -0
- package/releaserc.json +87 -0
- package/tasks/sync-aliases.js +115 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const AzionEdges = [
|
|
2
|
+
'Africa, Angola, Luanda (LAD)',
|
|
3
|
+
'Asia, China, Hong Kong - (HKG)',
|
|
4
|
+
'Europe, France, Paris (CDG)',
|
|
5
|
+
'Europe, Germany, Frankfurt (FRA)',
|
|
6
|
+
'Europe, Italy, Milan (MXP)',
|
|
7
|
+
'Europe, London, United Kingdom (LYC)',
|
|
8
|
+
'Europe, Spain, Madrid (MAD)',
|
|
9
|
+
'Europe, Sweden, Stockholm (ARN)',
|
|
10
|
+
'Latin America, Argentina, Buenos Aires 1 (AEP)',
|
|
11
|
+
'Latin America, Argentina, Buenos Aires 2 (AEP)',
|
|
12
|
+
'Latin America, Brazil, Aracaju 1 (AJU)',
|
|
13
|
+
'Latin America, Brazil, Aracaju 2 (AJU)',
|
|
14
|
+
'Latin America, Brazil, Barueri (CGH)',
|
|
15
|
+
'Latin America, Brazil, Belem (BEL)',
|
|
16
|
+
'Latin America, Brazil, Belo Horizonte 1 (PLU)',
|
|
17
|
+
'Latin America, Brazil, Belo Horizonte 2 (PLU)',
|
|
18
|
+
'Latin America, Brazil, Belo Horizonte 3 (PLU)',
|
|
19
|
+
'Latin America, Brazil, Brasília (BSB)',
|
|
20
|
+
'Latin America, Brazil, Campo Grande (CGR)',
|
|
21
|
+
'Latin America, Brazil, Campinas (VCP)',
|
|
22
|
+
'Latin America, Brazil, Cotia (CGH)',
|
|
23
|
+
'Latin America, Brazil, Cuiabá 1 (CGB)',
|
|
24
|
+
'Latin America, Brazil, Cuiabá 2 (CGB)',
|
|
25
|
+
'Latin America, Brazil, Curitiba 1 (CWB)',
|
|
26
|
+
'Latin America, Brazil, Curitiba 2 (CWB)',
|
|
27
|
+
'Latin America, Brazil, Florianópolis 1 (FLN)',
|
|
28
|
+
'Latin America, Brazil, Florianópolis 2 (FLN)',
|
|
29
|
+
'Latin America, Brazil, Fortaleza 1 (FOR)',
|
|
30
|
+
'Latin America, Brazil, Fortaleza 2 (FOR)',
|
|
31
|
+
'Latin America, Brazil, Fortaleza 3 (FOR)',
|
|
32
|
+
'Latin America, Brazil, Franca (FRC)',
|
|
33
|
+
'Latin America, Brazil, Goiania (GYN)',
|
|
34
|
+
'Latin America, Brazil, João Pessoa (JPA)',
|
|
35
|
+
'Latin America, Brazil, Juazeiro do Norte (JDO)',
|
|
36
|
+
'Latin America, Brazil, Linhares (VIX)',
|
|
37
|
+
'Latin America, Brazil, Londrina (LDB)',
|
|
38
|
+
'Latin America, Brazil, Macapá 1 (MCP)',
|
|
39
|
+
'Latin America, Brazil, Macapá 2 (MCP)',
|
|
40
|
+
'Latin America, Brazil, Maceió (MCZ)',
|
|
41
|
+
'Latin America, Brazil, Manaus 1 (MAO)',
|
|
42
|
+
'Latin America, Brazil, Manaus 2 (MAO)',
|
|
43
|
+
'Latin America, Brazil, Natal (NAT)',
|
|
44
|
+
'Latin America, Brazil, Osasco (CGH)',
|
|
45
|
+
'Latin America, Brazil, Porto Alegre 1 (POA)',
|
|
46
|
+
'Latin America, Brazil, Porto Alegre 2 (POA)',
|
|
47
|
+
'Latin America, Brazil, Porto Alegre 3 (POA)',
|
|
48
|
+
'Latin America, Brazil, Recife 1 (REC)',
|
|
49
|
+
'Latin America, Brazil, Recife 2 (REC)',
|
|
50
|
+
'Latin America, Brazil, Recife 3 (REC)',
|
|
51
|
+
'Latin America, Brazil, Rio Branco (RBR)',
|
|
52
|
+
'Latin America, Brazil, Rio de Janeiro 1 (SDU)',
|
|
53
|
+
'Latin America, Brazil, Rio de Janeiro 2 (SDU)',
|
|
54
|
+
'Latin America, Brazil, Rio de Janeiro 3 (SDU)',
|
|
55
|
+
'Latin America, Brazil, Rio de Janeiro 4 (GIG)',
|
|
56
|
+
'Latin America, Brazil, Rio de Janeiro 5 (GIG)',
|
|
57
|
+
'Latin America, Brazil, Rio de Janeiro 6 (SDU)',
|
|
58
|
+
'Latin America, Brazil, Salvador 1 (SSA)',
|
|
59
|
+
'Latin America, Brazil, Salvador 2 (SSA)',
|
|
60
|
+
'Latin America, Brazil, Salvador 4 (SSA)',
|
|
61
|
+
'Latin America, Brazil, São Luis (SLZ)',
|
|
62
|
+
'Latin America, Brazil, São Paulo 1 (CGH)',
|
|
63
|
+
'Latin America, Brazil, São Paulo 2 (CGH)',
|
|
64
|
+
'Latin America, Brazil, São Paulo 3 (CGH)',
|
|
65
|
+
'Latin America, Brazil, São Paulo 4 (CGH)',
|
|
66
|
+
'Latin America, Brazil, São Paulo 5 (CGH)',
|
|
67
|
+
'Latin America, Brazil, Sorocaba 1 (SOD)',
|
|
68
|
+
'Latin America, Brazil, Sorocaba 2 (SOD)',
|
|
69
|
+
'Latin America, Chile, Santiago (SCL)',
|
|
70
|
+
'Latin America, Brazil, Santos (SSZ)',
|
|
71
|
+
'Latin America, Brazil, Vitória (VIX)',
|
|
72
|
+
'Latin America, Colombia, Bogota (BOG)',
|
|
73
|
+
'Latin America, Mexico, Queretaro (QRO)',
|
|
74
|
+
'Latin America, Peru, Lima (LIM)',
|
|
75
|
+
'Latin America, Brazil, Manaus 3 (MAO)',
|
|
76
|
+
'North America, USA, Ashburn (IAD)',
|
|
77
|
+
'North America, USA, Atlanta (ATL)',
|
|
78
|
+
'North America, USA, Chicago (MDW)',
|
|
79
|
+
'North America, USA, Dallas (DAL)',
|
|
80
|
+
'North America, USA, Denver (DEN)',
|
|
81
|
+
'North America, USA, Los Angeles (LAX)',
|
|
82
|
+
'North America, USA, McAllen (MFE)',
|
|
83
|
+
'North America, USA, Miami (MIA)',
|
|
84
|
+
'North America, USA, New York (EWR)',
|
|
85
|
+
'North America, USA, Orlando (MCO)',
|
|
86
|
+
'North America, USA, Phoenix (PHX)',
|
|
87
|
+
'North America, USA, Santa Clara (SJC)',
|
|
88
|
+
'North America, USA, Seattle (SEA)',
|
|
89
|
+
'Oceania, Sydney, Australia - (SYD)',
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* List of Azion edges located in different regions around the world.
|
|
94
|
+
* These edges are used to serve content and optimize delivery for improved performance.
|
|
95
|
+
* Each entry represents a specific edge location, including the region and city.
|
|
96
|
+
* @type {string[]}
|
|
97
|
+
*/
|
|
98
|
+
export default AzionEdges;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Build messages object.
|
|
3
|
+
@property {object} success - Success messages.
|
|
4
|
+
@property {object} info - Information messages.
|
|
5
|
+
@property {object} error - Error messages.
|
|
6
|
+
*/
|
|
7
|
+
const build = {
|
|
8
|
+
success: {
|
|
9
|
+
prebuild_succeeded: 'Prebuild succeeded!',
|
|
10
|
+
vulcan_build_succeeded: 'Vulcan Build succeeded!',
|
|
11
|
+
},
|
|
12
|
+
info: {
|
|
13
|
+
prebuild_starting: 'Starting prebuild...',
|
|
14
|
+
vulcan_build_starting: 'Starting Vulcan build...',
|
|
15
|
+
|
|
16
|
+
},
|
|
17
|
+
error: {
|
|
18
|
+
vulcan_build_failed: 'Vulcan build failed.',
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default build;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Environment messages object.
|
|
3
|
+
@property {object} success - Success messages.
|
|
4
|
+
@property {object} info - Information messages.
|
|
5
|
+
@property {object} errors - Error messages.
|
|
6
|
+
@property {object} runtime - Runtime messages.
|
|
7
|
+
@property {object} server - Server messages.
|
|
8
|
+
*/
|
|
9
|
+
const env = {
|
|
10
|
+
success: {},
|
|
11
|
+
info: {},
|
|
12
|
+
errors: {
|
|
13
|
+
invalid_environment: 'Invalid environment. Please set ENV to either production, stage, or local.',
|
|
14
|
+
},
|
|
15
|
+
runtime: {
|
|
16
|
+
success: {},
|
|
17
|
+
info: {},
|
|
18
|
+
errors: {
|
|
19
|
+
unknown_error: 'An error occurred while executing the script',
|
|
20
|
+
fetch_event_missing: 'No fetch event handler was defined',
|
|
21
|
+
fetch_event_unknown_error: 'An error occurred while handling the fetch event:',
|
|
22
|
+
undefined_response: 'No response was defined',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
server: {
|
|
26
|
+
success: {
|
|
27
|
+
server_running: (port) => `Server running on port ${port}`,
|
|
28
|
+
},
|
|
29
|
+
info: {
|
|
30
|
+
code_change_detect: 'Code change detected. Restarting server...',
|
|
31
|
+
},
|
|
32
|
+
errors: {
|
|
33
|
+
load_worker_failed: 'Failed to load code:',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default env;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Global messages object.
|
|
3
|
+
@property {object} success - Success messages.
|
|
4
|
+
@property {object} info - Information messages.
|
|
5
|
+
@property {object} errors - Error messages.
|
|
6
|
+
*/
|
|
7
|
+
const global = {
|
|
8
|
+
success: {},
|
|
9
|
+
info: {},
|
|
10
|
+
errors: {
|
|
11
|
+
unknown_error: 'An error occurred.',
|
|
12
|
+
folder_creation_failed: (folder) => `An error occurred while creating the ${folder} folder.`,
|
|
13
|
+
write_file_failed: (file) => `An error occurred while writing the ${file} file.`,
|
|
14
|
+
file_doesnt_exist: (file) => `An error occurred while reading the ${file} file.`,
|
|
15
|
+
invalid_node_version: (minVersion) => `Invalid Node version. Node version must be greater than ${minVersion}.`,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default global;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import build from './build.messages.js';
|
|
2
|
+
import env from './env.messages.js';
|
|
3
|
+
import platform from './platform.messages.js';
|
|
4
|
+
import global from './global.messages.js'; // generic messages
|
|
5
|
+
|
|
6
|
+
const Messages = {
|
|
7
|
+
env, platform, build, ...global,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default Messages;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform messages object.
|
|
3
|
+
* @property {object} success - Success messages.
|
|
4
|
+
* @property {object} info - Information messages.
|
|
5
|
+
* @property {object} errors - Error messages.
|
|
6
|
+
* @property {object} auth - Authentication messages.
|
|
7
|
+
* @property {object} deploy - Deployment messages.
|
|
8
|
+
* @property {object} logs - Log messages.
|
|
9
|
+
* @property {object} storage - Storage messages.
|
|
10
|
+
* @property {object} propagation - Propagation messages.
|
|
11
|
+
*/
|
|
12
|
+
const platform = {
|
|
13
|
+
success: {},
|
|
14
|
+
info: {},
|
|
15
|
+
errors: {},
|
|
16
|
+
auth: {
|
|
17
|
+
success: {
|
|
18
|
+
auth_success: 'API authentication token saved successfully!',
|
|
19
|
+
},
|
|
20
|
+
info: {},
|
|
21
|
+
error: {
|
|
22
|
+
auth_failed: 'Authentication failed. Please check your credentials and try again.',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
deploy: {
|
|
26
|
+
success: {
|
|
27
|
+
created_edge_function: 'Worker successfully uploaded to Edge.',
|
|
28
|
+
created_application: 'Application deployed successfully.',
|
|
29
|
+
created_rule_engine: 'Rule Engine created.',
|
|
30
|
+
created_domain: 'Domain created.',
|
|
31
|
+
activated_edge_function: 'Activated Edge Function.',
|
|
32
|
+
instantiated_edge_function: 'Edge Function Instantiated.',
|
|
33
|
+
deploy_finished: 'Application successfully deployed to the edge network.',
|
|
34
|
+
},
|
|
35
|
+
info: {
|
|
36
|
+
creating_edge_function: 'Creating Edge Function (worker)...',
|
|
37
|
+
creating_edge_application: 'Creating Edge Application...',
|
|
38
|
+
creating_rule_engine: 'Creating Rule Engine...',
|
|
39
|
+
creating_domain: 'Creating Domain...',
|
|
40
|
+
activating_edge_function: 'Enabling Edge Function...',
|
|
41
|
+
instantiating_edge_function: 'Instantiating Edge Function...',
|
|
42
|
+
|
|
43
|
+
},
|
|
44
|
+
error: {
|
|
45
|
+
deploy_failed: 'An error occurred during deployment',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
logs: {
|
|
49
|
+
success: {},
|
|
50
|
+
info: {
|
|
51
|
+
watch_true: 'Waiting for the next request event...',
|
|
52
|
+
unsupported_log_type: 'Logs for applications are not yet supported. Please specify "function" instead.',
|
|
53
|
+
no_logs: 'There are no logs.',
|
|
54
|
+
},
|
|
55
|
+
errors: {
|
|
56
|
+
invalid_log_type: 'Invalid log type. Please specify either "function" or "application".',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
storage: {
|
|
60
|
+
success: {
|
|
61
|
+
file_uploaded_success: (filePath) => `Uploaded file: ${filePath}`,
|
|
62
|
+
statics_uploaded_finish: (successUploadCount) => `${successUploadCount} static assets successfully uploaded to Azion!`,
|
|
63
|
+
},
|
|
64
|
+
info: {},
|
|
65
|
+
errors: {
|
|
66
|
+
file_upload_failed: (filePath) => `Error uploading file: ${filePath}`,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
propagation: {
|
|
71
|
+
success: {
|
|
72
|
+
propagation_complete: 'Application has propagated to the edge networks and is ready to be accessed!',
|
|
73
|
+
},
|
|
74
|
+
info: {
|
|
75
|
+
propagating: (edge) => `Propagating to ${edge}...`,
|
|
76
|
+
},
|
|
77
|
+
errors: {
|
|
78
|
+
watch_propagation_failed: 'Error occurred while watching propagation.',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default platform;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const runtimeApis = [
|
|
2
|
+
'Object',
|
|
3
|
+
'Function',
|
|
4
|
+
'Array',
|
|
5
|
+
'Number',
|
|
6
|
+
'parseFloat',
|
|
7
|
+
'parseInt',
|
|
8
|
+
'Infinity',
|
|
9
|
+
'NaN',
|
|
10
|
+
'undefined',
|
|
11
|
+
'Boolean',
|
|
12
|
+
'String',
|
|
13
|
+
'Symbol',
|
|
14
|
+
'Date',
|
|
15
|
+
'Promise',
|
|
16
|
+
'RegExp',
|
|
17
|
+
'Error',
|
|
18
|
+
'AggregateError',
|
|
19
|
+
'EvalError',
|
|
20
|
+
'RangeError',
|
|
21
|
+
'ReferenceError',
|
|
22
|
+
'SyntaxError',
|
|
23
|
+
'TypeError',
|
|
24
|
+
'URIError',
|
|
25
|
+
'globalThis',
|
|
26
|
+
'JSON',
|
|
27
|
+
'Math',
|
|
28
|
+
'Intl',
|
|
29
|
+
'ArrayBuffer',
|
|
30
|
+
'Uint8Array',
|
|
31
|
+
'Int8Array',
|
|
32
|
+
'Uint16Array',
|
|
33
|
+
'Int16Array',
|
|
34
|
+
'Uint32Array',
|
|
35
|
+
'Int32Array',
|
|
36
|
+
'Float32Array',
|
|
37
|
+
'Float64Array',
|
|
38
|
+
'Uint8ClampedArray',
|
|
39
|
+
'BigUint64Array',
|
|
40
|
+
'BigInt64Array',
|
|
41
|
+
'DataView',
|
|
42
|
+
'Map',
|
|
43
|
+
'BigInt',
|
|
44
|
+
'Set',
|
|
45
|
+
'WeakMap',
|
|
46
|
+
'WeakSet',
|
|
47
|
+
'Proxy',
|
|
48
|
+
'Reflect',
|
|
49
|
+
'decodeURI',
|
|
50
|
+
'decodeURIComponent',
|
|
51
|
+
'encodeURI',
|
|
52
|
+
'encodeURIComponent',
|
|
53
|
+
'escape',
|
|
54
|
+
'unescape',
|
|
55
|
+
'isFinite',
|
|
56
|
+
'isNaN',
|
|
57
|
+
'console',
|
|
58
|
+
'Event',
|
|
59
|
+
'EventTarget',
|
|
60
|
+
'CustomEvent',
|
|
61
|
+
'dispatchEvent',
|
|
62
|
+
'addEventListener',
|
|
63
|
+
'removeEventListener',
|
|
64
|
+
'AbortSignal',
|
|
65
|
+
'AbortController',
|
|
66
|
+
'Blob',
|
|
67
|
+
'CryptoKey',
|
|
68
|
+
'Crypto',
|
|
69
|
+
'DOMException',
|
|
70
|
+
'FormData',
|
|
71
|
+
'Headers',
|
|
72
|
+
'ReadableStream',
|
|
73
|
+
'ReadableStreamBYOBReader',
|
|
74
|
+
'ReadableStreamDefaultReader',
|
|
75
|
+
'Request',
|
|
76
|
+
'Response',
|
|
77
|
+
'SubtleCrypto',
|
|
78
|
+
'TextDecoder',
|
|
79
|
+
'TextEncoder',
|
|
80
|
+
'TransformStream',
|
|
81
|
+
'URL',
|
|
82
|
+
'URLPattern',
|
|
83
|
+
'URLSearchParams',
|
|
84
|
+
'WritableStream',
|
|
85
|
+
'WritableStreamDefaultWriter',
|
|
86
|
+
'atob',
|
|
87
|
+
'btoa',
|
|
88
|
+
'clearTimeout',
|
|
89
|
+
'crypto',
|
|
90
|
+
'fetch',
|
|
91
|
+
'setTimeout',
|
|
92
|
+
'setInterval',
|
|
93
|
+
'structuredClone',
|
|
94
|
+
'self',
|
|
95
|
+
'EdgeRuntime',
|
|
96
|
+
'ExtendableEvent',
|
|
97
|
+
'FetchEvent',
|
|
98
|
+
'FirewallEvent',
|
|
99
|
+
'clearInterval',
|
|
100
|
+
'SharedArrayBuffer',
|
|
101
|
+
'Atomics',
|
|
102
|
+
'WebAssembly',
|
|
103
|
+
'hasOwnProperty',
|
|
104
|
+
'isPrototypeOf',
|
|
105
|
+
'propertyIsEnumerable',
|
|
106
|
+
'toString',
|
|
107
|
+
'valueOf',
|
|
108
|
+
'toLocaleString',
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* List of supported APIs available in the runtime of the edge.
|
|
113
|
+
* This list includes various built-in objects, functions, and properties.
|
|
114
|
+
* It serves as a whitelist for the allowed APIs in the edge runtime environment.
|
|
115
|
+
* @type {string[]}
|
|
116
|
+
*/
|
|
117
|
+
const Whitelist = new Set(runtimeApis);
|
|
118
|
+
export default Whitelist;
|
package/lib/env/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NodeVM } from 'vm2';
|
|
2
|
+
import { RuntimeApis, Messages } from '#constants';
|
|
3
|
+
import { feedback, debug } from '#utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Execute the specified code with the provided event object.
|
|
7
|
+
* @param {string} code - The JavaScript code to be executed.
|
|
8
|
+
* @param {object} event - The event object containing the request and other properties.
|
|
9
|
+
* @returns {Promise<object>} A Promise that resolves with the Response object.
|
|
10
|
+
*/
|
|
11
|
+
async function run(code, event) {
|
|
12
|
+
let fetchEventHandler = null;
|
|
13
|
+
let respondWithPromise = null;
|
|
14
|
+
|
|
15
|
+
const vm = new NodeVM({
|
|
16
|
+
console: 'inherit',
|
|
17
|
+
sandbox: {
|
|
18
|
+
Headers,
|
|
19
|
+
...event,
|
|
20
|
+
Response,
|
|
21
|
+
addEventListener: (type, handler) => {
|
|
22
|
+
if (type !== 'fetch') {
|
|
23
|
+
throw new Error(`Unsupported event type: ${type}`);
|
|
24
|
+
}
|
|
25
|
+
fetchEventHandler = handler;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
require: {
|
|
29
|
+
external: true,
|
|
30
|
+
builtin: RuntimeApis,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
vm.run(code);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
debug.error(error);
|
|
38
|
+
feedback.error(Messages.env.runtime.errors.unknown_error);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!fetchEventHandler) {
|
|
43
|
+
throw new Error(Messages.env.runtime.errors.fetch_event_missing);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let response;
|
|
47
|
+
try {
|
|
48
|
+
const fetchEvent = {
|
|
49
|
+
request: event.request,
|
|
50
|
+
respondWith: (responsePromise) => {
|
|
51
|
+
respondWithPromise = responsePromise;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
fetchEventHandler(fetchEvent);
|
|
55
|
+
response = respondWithPromise;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
debug.error(error);
|
|
58
|
+
feedback.error(Messages.env.runtime.errors.fetch_event_unknown_error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!response) {
|
|
63
|
+
throw new Error(Messages.env.runtime.errors.undefined_response);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return response;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default run;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import chokidar from 'chokidar';
|
|
3
|
+
|
|
4
|
+
import { debug, feedback, readWorkerFile } from '#utils';
|
|
5
|
+
import { Messages } from '#constants';
|
|
6
|
+
import run from './runtime.env.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a new HTTP server.
|
|
10
|
+
* @param {string} filePath - The path to the file containing the code.
|
|
11
|
+
* @returns {http.Server} The created server.
|
|
12
|
+
*/
|
|
13
|
+
function createServer(filePath) {
|
|
14
|
+
return http.createServer(async (request, response) => {
|
|
15
|
+
let code;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Load the code to be executed on the server for each request
|
|
19
|
+
code = await readWorkerFile(filePath);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
debug.error(error);
|
|
22
|
+
response.statusCode = 500;
|
|
23
|
+
response.setHeader('Content-Type', 'text/plain');
|
|
24
|
+
response.end(JSON.stringify({ error: error.message }));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const responseBody = await run(code, { request, response });
|
|
30
|
+
|
|
31
|
+
if (responseBody instanceof Response) {
|
|
32
|
+
responseBody.headers.forEach((value, name) => {
|
|
33
|
+
response.setHeader(name, value);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const body = await responseBody.text();
|
|
37
|
+
response.statusCode = responseBody.status;
|
|
38
|
+
response.end(body);
|
|
39
|
+
} else {
|
|
40
|
+
response.statusCode = 200;
|
|
41
|
+
response.setHeader('Content-Type', 'text/plain');
|
|
42
|
+
response.end(responseBody);
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
let errorMessage = error.message;
|
|
46
|
+
if (error.message.includes('is not defined')) {
|
|
47
|
+
errorMessage = `${error.message} in Edge runtime.`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
error.message = errorMessage;
|
|
51
|
+
debug.error(error);
|
|
52
|
+
feedback.error(Messages.env.server.errors.load_worker_failed);
|
|
53
|
+
response.statusCode = 500;
|
|
54
|
+
response.setHeader('Content-Type', 'text/plain');
|
|
55
|
+
response.end(JSON.stringify({ error: { message: errorMessage, status: 500 } }));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Start the HTTP server with the specified port and file path to load the code from.
|
|
62
|
+
* @param {string} filePath - The path to the file containing the code.
|
|
63
|
+
* @param {number} port - The port to listen on.
|
|
64
|
+
* @returns {http.Server} The created server.
|
|
65
|
+
*/
|
|
66
|
+
async function startServer(filePath, port) {
|
|
67
|
+
let server = createServer(filePath);
|
|
68
|
+
|
|
69
|
+
// Use chokidar to watch for changes in the file
|
|
70
|
+
const watcher = chokidar.watch(filePath);
|
|
71
|
+
|
|
72
|
+
watcher.on('change', async () => {
|
|
73
|
+
feedback.info(Messages.env.server.info.code_change_detect);
|
|
74
|
+
// Close the current server
|
|
75
|
+
server.close();
|
|
76
|
+
// And create a new one
|
|
77
|
+
server = createServer(filePath);
|
|
78
|
+
server.listen(port, () => {
|
|
79
|
+
feedback.success(Messages.env.server.success.server_running(port));
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
server.listen(port, () => {
|
|
84
|
+
feedback.success(Messages.env.server.success.server_running(port));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return server;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default startServer;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { feedback, debug } from '#utils';
|
|
2
|
+
import { Messages } from '#constants';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create or update the Vulcan environment file with the specified name and value.
|
|
8
|
+
* @param {string} name - The name of the variable.
|
|
9
|
+
* @param {string} value - The value of the variable.
|
|
10
|
+
*/
|
|
11
|
+
async function createVulcanEnv(name, value) {
|
|
12
|
+
const azionDirPath = path.join(process.env.HOME, '.azion');
|
|
13
|
+
const vulcanEnvPath = path.join(azionDirPath, 'vulcan.env');
|
|
14
|
+
|
|
15
|
+
// Create the .azion folder if it doesn't exist
|
|
16
|
+
try {
|
|
17
|
+
await fs.mkdir(azionDirPath, { recursive: true });
|
|
18
|
+
} catch (error) {
|
|
19
|
+
debug.error(error);
|
|
20
|
+
feedback.error(Messages.errors.folder_creation_failed(vulcanEnvPath));
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Read the existing Vulcan environment file if it exists
|
|
25
|
+
let envData = '';
|
|
26
|
+
try {
|
|
27
|
+
envData = await fs.readFile(vulcanEnvPath, 'utf8');
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// Ignore error if the file doesn't exist
|
|
30
|
+
if (error.code !== 'ENOENT') {
|
|
31
|
+
debug.error(error);
|
|
32
|
+
feedback.error(Messages.errors.file_doesnt_exist(vulcanEnvPath));
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Update or add the variable to the environment data
|
|
38
|
+
const variableLine = `${name}=${value}`;
|
|
39
|
+
const variableRegex = new RegExp(`${name}=.+`);
|
|
40
|
+
|
|
41
|
+
if (envData.match(variableRegex)) {
|
|
42
|
+
envData = envData.replace(variableRegex, variableLine);
|
|
43
|
+
} else {
|
|
44
|
+
envData += `${variableLine}\n`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Write the updated environment data to the file
|
|
48
|
+
try {
|
|
49
|
+
await fs.writeFile(vulcanEnvPath, envData);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
debug.error(error);
|
|
52
|
+
feedback.error(Messages.errors.write_file_failed(vulcanEnvPath));
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Reads the vulcan.env file and returns an object with the variables and their values.
|
|
59
|
+
* @returns {object|null} An object with the variables and their values,
|
|
60
|
+
* or null if the file doesn't exist.
|
|
61
|
+
*/
|
|
62
|
+
async function readVulcanEnv() {
|
|
63
|
+
const vulcanEnvPath = path.join(process.env.HOME, '.azion', 'vulcan.env');
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
// Check if the vulcan.env file exists
|
|
67
|
+
await fs.access(vulcanEnvPath);
|
|
68
|
+
|
|
69
|
+
// Read the file contents
|
|
70
|
+
const fileContents = await fs.readFile(vulcanEnvPath, 'utf8');
|
|
71
|
+
// Parse the variables from the file contents
|
|
72
|
+
const variables = {};
|
|
73
|
+
const variableRegex = /^([^=]+)=(.*)$/gm;
|
|
74
|
+
let match = variableRegex.exec(fileContents);
|
|
75
|
+
while (match !== null) {
|
|
76
|
+
const key = match[1].trim();
|
|
77
|
+
const value = match[2].trim();
|
|
78
|
+
variables[key] = value;
|
|
79
|
+
match = variableRegex.exec(fileContents);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return variables;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error.code === 'ENOENT') {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
debug.error(error);
|
|
88
|
+
feedback.error(Messages.errors.write_file_failed(vulcanEnvPath));
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default { createVulcanEnv, readVulcanEnv };
|