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.
Files changed (230) hide show
  1. package/.babelrc +13 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.json +42 -0
  4. package/.github/workflows/major.yml +28 -0
  5. package/.github/workflows/minor.yml +31 -0
  6. package/.vscode/settings.json +20 -0
  7. package/CODEOWNERS +2 -0
  8. package/CODE_OF_CONDUCT.md +73 -0
  9. package/CONTRIBUTING.md +90 -0
  10. package/LICENSE.md +21 -0
  11. package/README.md +60 -0
  12. package/aliases.js +13 -0
  13. package/docs/overview.md +36 -0
  14. package/docs/presets.md +115 -0
  15. package/examples/angular-static/.editorconfig +16 -0
  16. package/examples/angular-static/README.md +27 -0
  17. package/examples/angular-static/angular.json +98 -0
  18. package/examples/angular-static/package.json +39 -0
  19. package/examples/angular-static/src/app/app-routing.module.ts +10 -0
  20. package/examples/angular-static/src/app/app.component.css +0 -0
  21. package/examples/angular-static/src/app/app.component.html +484 -0
  22. package/examples/angular-static/src/app/app.component.spec.ts +29 -0
  23. package/examples/angular-static/src/app/app.component.ts +10 -0
  24. package/examples/angular-static/src/app/app.module.ts +18 -0
  25. package/examples/angular-static/src/assets/.gitkeep +0 -0
  26. package/examples/angular-static/src/favicon.ico +0 -0
  27. package/examples/angular-static/src/index.html +13 -0
  28. package/examples/angular-static/src/main.ts +7 -0
  29. package/examples/angular-static/src/styles.css +1 -0
  30. package/examples/angular-static/tsconfig.app.json +14 -0
  31. package/examples/angular-static/tsconfig.json +33 -0
  32. package/examples/angular-static/tsconfig.spec.json +14 -0
  33. package/examples/astro-static/README.md +55 -0
  34. package/examples/astro-static/astro.config.mjs +5 -0
  35. package/examples/astro-static/package.json +15 -0
  36. package/examples/astro-static/public/favicon.svg +9 -0
  37. package/examples/astro-static/src/components/Card.astro +63 -0
  38. package/examples/astro-static/src/env.d.ts +1 -0
  39. package/examples/astro-static/src/layouts/Layout.astro +36 -0
  40. package/examples/astro-static/src/pages/edge/index.astro +55 -0
  41. package/examples/astro-static/src/pages/index.astro +81 -0
  42. package/examples/astro-static/tsconfig.json +3 -0
  43. package/examples/hexo-static/.github/dependabot.yml +7 -0
  44. package/examples/hexo-static/_config.landscape.yml +0 -0
  45. package/examples/hexo-static/_config.yml +105 -0
  46. package/examples/hexo-static/package.json +26 -0
  47. package/examples/hexo-static/scaffolds/draft.md +4 -0
  48. package/examples/hexo-static/scaffolds/page.md +4 -0
  49. package/examples/hexo-static/scaffolds/post.md +5 -0
  50. package/examples/hexo-static/source/_posts/hello-world.md +38 -0
  51. package/examples/hexo-static/source/_posts/other-page.md +62 -0
  52. package/examples/hexo-static/themes/.gitkeep +0 -0
  53. package/examples/hexo-static/yarn.lock +1625 -0
  54. package/examples/next-12-static/.babelrc +3 -0
  55. package/examples/next-12-static/README.md +21 -0
  56. package/examples/next-12-static/components/post.jsx +27 -0
  57. package/examples/next-12-static/package-lock.json +6191 -0
  58. package/examples/next-12-static/package.json +18 -0
  59. package/examples/next-12-static/pages/index.jsx +34 -0
  60. package/examples/next-12-static/pages/post/[id].jsx +63 -0
  61. package/examples/next-static/README.md +34 -0
  62. package/examples/next-static/jsconfig.json +7 -0
  63. package/examples/next-static/next.config.js +9 -0
  64. package/examples/next-static/package.json +16 -0
  65. package/examples/next-static/public/next.svg +1 -0
  66. package/examples/next-static/public/vercel.svg +1 -0
  67. package/examples/next-static/src/app/blog/[slug]/page.js +27 -0
  68. package/examples/next-static/src/app/favicon.ico +0 -0
  69. package/examples/next-static/src/app/globals.css +107 -0
  70. package/examples/next-static/src/app/layout.js +17 -0
  71. package/examples/next-static/src/app/misty-mountains/moria/page.js +15 -0
  72. package/examples/next-static/src/app/page.js +96 -0
  73. package/examples/next-static/src/app/page.module.css +229 -0
  74. package/examples/next-static/yarn.lock +199 -0
  75. package/examples/react-static/README.md +70 -0
  76. package/examples/react-static/package.json +38 -0
  77. package/examples/react-static/public/favicon.ico +0 -0
  78. package/examples/react-static/public/index.html +43 -0
  79. package/examples/react-static/public/logo192.png +0 -0
  80. package/examples/react-static/public/logo512.png +0 -0
  81. package/examples/react-static/public/manifest.json +25 -0
  82. package/examples/react-static/public/robots.txt +3 -0
  83. package/examples/react-static/src/App.css +38 -0
  84. package/examples/react-static/src/App.js +25 -0
  85. package/examples/react-static/src/App.test.js +8 -0
  86. package/examples/react-static/src/index.css +13 -0
  87. package/examples/react-static/src/index.js +17 -0
  88. package/examples/react-static/src/logo.svg +1 -0
  89. package/examples/react-static/src/reportWebVitals.js +13 -0
  90. package/examples/react-static/src/setupTests.js +5 -0
  91. package/examples/simple-js-esm/main.js +14 -0
  92. package/examples/simple-js-esm/messages.js +7 -0
  93. package/examples/simple-js-node/main.js +18 -0
  94. package/examples/vue-static/README.md +24 -0
  95. package/examples/vue-static/babel.config.js +5 -0
  96. package/examples/vue-static/jsconfig.json +19 -0
  97. package/examples/vue-static/package.json +45 -0
  98. package/examples/vue-static/public/favicon.ico +0 -0
  99. package/examples/vue-static/public/index.html +17 -0
  100. package/examples/vue-static/src/App.vue +16 -0
  101. package/examples/vue-static/src/assets/logo.png +0 -0
  102. package/examples/vue-static/src/components/HelloWorld.vue +58 -0
  103. package/examples/vue-static/src/main.js +28 -0
  104. package/examples/vue-static/src/views/Home.vue +14 -0
  105. package/examples/vue-static/vue.config.js +4 -0
  106. package/jest.config.js +6 -0
  107. package/jsconfig.json +40 -0
  108. package/jsdoc.json +52 -0
  109. package/lib/build/bundlers/index.js +4 -0
  110. package/lib/build/bundlers/webpack/index.js +40 -0
  111. package/lib/build/bundlers/webpack/webpack.config.js +38 -0
  112. package/lib/build/dispatcher/dispatcher.js +211 -0
  113. package/lib/build/dispatcher/dispatcher.test.js +0 -0
  114. package/lib/build/dispatcher/index.js +3 -0
  115. package/lib/build/polyfills/index.js +0 -0
  116. package/lib/constants/azion-edges.constants.js +98 -0
  117. package/lib/constants/index.js +5 -0
  118. package/lib/constants/messages/build.messages.js +23 -0
  119. package/lib/constants/messages/env.messages.js +38 -0
  120. package/lib/constants/messages/global.messages.js +19 -0
  121. package/lib/constants/messages/index.js +10 -0
  122. package/lib/constants/messages/platform.messages.js +84 -0
  123. package/lib/constants/runtime-apis.constants.js +118 -0
  124. package/lib/env/index.js +5 -0
  125. package/lib/env/runtime.env.js +69 -0
  126. package/lib/env/server.env.js +90 -0
  127. package/lib/env/vulcan.env.js +93 -0
  128. package/lib/main.js +260 -0
  129. package/lib/notations/namespaces.js +30 -0
  130. package/lib/notations/typedef.js +10 -0
  131. package/lib/platform/actions/application/createApplication.actions.js +33 -0
  132. package/lib/platform/actions/application/enableEdgeFunctions.actions.js +34 -0
  133. package/lib/platform/actions/application/instantiateFunction.actions.js +37 -0
  134. package/lib/platform/actions/application/setFunctionAsDefaultRule.actions.js +33 -0
  135. package/lib/platform/actions/core/auth.actions.js +67 -0
  136. package/lib/platform/actions/core/deploy.actions.js +73 -0
  137. package/lib/platform/actions/core/propagation.actions.js +75 -0
  138. package/lib/platform/actions/core/storage.actions.js +84 -0
  139. package/lib/platform/actions/domain/createDomain.actions.js +42 -0
  140. package/lib/platform/actions/function/createFunction.actions.js +79 -0
  141. package/lib/platform/actions/function/showFunctionLogs.actions.js +149 -0
  142. package/lib/platform/edgehooks/ErrorHTML/ErrorHTML.hooks.js +101 -0
  143. package/lib/platform/edgehooks/ErrorHTML/index.js +3 -0
  144. package/lib/platform/edgehooks/index.js +5 -0
  145. package/lib/platform/edgehooks/mountSPA/index.js +3 -0
  146. package/lib/platform/edgehooks/mountSPA/mountSPA.hooks.js +55 -0
  147. package/lib/platform/edgehooks/mountSPA/mountSPA.hooks.test.js +19 -0
  148. package/lib/platform/edgehooks/mountSSG/index.js +3 -0
  149. package/lib/platform/edgehooks/mountSSG/mountSSG.hooks.js +61 -0
  150. package/lib/platform/edgehooks/mountSSG/mountSSG.hooks.test.js +0 -0
  151. package/lib/platform/index.js +65 -0
  152. package/lib/platform/services/application.service.js +140 -0
  153. package/lib/platform/services/base.service.js +200 -0
  154. package/lib/platform/services/domain.service.js +80 -0
  155. package/lib/platform/services/events.service.js +65 -0
  156. package/lib/platform/services/function.service.js +105 -0
  157. package/lib/platform/services/index.js +8 -0
  158. package/lib/platform/services/storage.service.js +59 -0
  159. package/lib/platform/services/tokens.service.js +55 -0
  160. package/lib/presets/custom/angular/deliver/config.js +12 -0
  161. package/lib/presets/custom/angular/deliver/handler.js +8 -0
  162. package/lib/presets/custom/angular/deliver/prebuild.js +20 -0
  163. package/lib/presets/custom/astro/deliver/config.js +12 -0
  164. package/lib/presets/custom/astro/deliver/handler.js +8 -0
  165. package/lib/presets/custom/astro/deliver/prebuild.js +37 -0
  166. package/lib/presets/custom/hexo/deliver/config.js +12 -0
  167. package/lib/presets/custom/hexo/deliver/handler.js +8 -0
  168. package/lib/presets/custom/hexo/deliver/prebuild.js +37 -0
  169. package/lib/presets/custom/next/deliver/config.js +14 -0
  170. package/lib/presets/custom/next/deliver/handler.js +9 -0
  171. package/lib/presets/custom/next/deliver/prebuild.js +193 -0
  172. package/lib/presets/custom/react/deliver/config.js +12 -0
  173. package/lib/presets/custom/react/deliver/handler.js +8 -0
  174. package/lib/presets/custom/react/deliver/prebuild.js +16 -0
  175. package/lib/presets/custom/vue/deliver/config.js +12 -0
  176. package/lib/presets/custom/vue/deliver/handler.js +8 -0
  177. package/lib/presets/custom/vue/deliver/prebuild.js +20 -0
  178. package/lib/presets/default/html/deliver/config.js +13 -0
  179. package/lib/presets/default/html/deliver/handler.js +9 -0
  180. package/lib/presets/default/html/deliver/prebuild.js +15 -0
  181. package/lib/presets/default/javascript/compute/config.js +13 -0
  182. package/lib/presets/default/javascript/compute/handler.js +5 -0
  183. package/lib/presets/default/javascript/compute/prebuild.js +6 -0
  184. package/lib/presets/default/typescript/compute/config.js +0 -0
  185. package/lib/presets/default/typescript/compute/handler.js +0 -0
  186. package/lib/presets/default/typescript/compute/prebuild.js +0 -0
  187. package/lib/providers/azion/worker.js +12 -0
  188. package/lib/utils/copyDirectory/copyDirectory.utils.js +54 -0
  189. package/lib/utils/copyDirectory/copyDirectory.utils.test.js +43 -0
  190. package/lib/utils/copyDirectory/index.js +3 -0
  191. package/lib/utils/debug/debug.utils.js +36 -0
  192. package/lib/utils/debug/debug.utils.test.js +43 -0
  193. package/lib/utils/debug/index.js +3 -0
  194. package/lib/utils/exec/exec.utils.js +58 -0
  195. package/lib/utils/exec/exec.utils.test.js +84 -0
  196. package/lib/utils/exec/index.js +3 -0
  197. package/lib/utils/feedback/feedback.utils.js +81 -0
  198. package/lib/utils/feedback/feedback.utils.test.js +11 -0
  199. package/lib/utils/feedback/index.js +3 -0
  200. package/lib/utils/generateTimestamp/generateTimestamp.utils.js +25 -0
  201. package/lib/utils/generateTimestamp/generateTimestamp.utils.test.js +10 -0
  202. package/lib/utils/generateTimestamp/index.js +3 -0
  203. package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.js +21 -0
  204. package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.test.js +13 -0
  205. package/lib/utils/getAbsoluteLibDirPath/index.js +3 -0
  206. package/lib/utils/getPackageManager/getPackageManager.utils.js +118 -0
  207. package/lib/utils/getPackageManager/getPackageManager.utils.test.js +35 -0
  208. package/lib/utils/getPackageManager/index.js +3 -0
  209. package/lib/utils/getPackageVersion/getPackageVersion.utils.js +25 -0
  210. package/lib/utils/getPackageVersion/getPackageVersion.utils.test.js +48 -0
  211. package/lib/utils/getPackageVersion/index.js +3 -0
  212. package/lib/utils/getPresetsList/getPresetsList.utils.js +50 -0
  213. package/lib/utils/getPresetsList/getPresetsList.utils.test.js +19 -0
  214. package/lib/utils/getPresetsList/index.js +3 -0
  215. package/lib/utils/getProjectJsonFile/getProjectJsonFile.utils.js +21 -0
  216. package/lib/utils/getProjectJsonFile/getProjectJsonFile.utils.test.js +39 -0
  217. package/lib/utils/getProjectJsonFile/index.js +3 -0
  218. package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.js +49 -0
  219. package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.test.js +36 -0
  220. package/lib/utils/getVulcanBuildId/index.js +3 -0
  221. package/lib/utils/index.js +29 -0
  222. package/lib/utils/overrideStaticOutputPath/index.js +3 -0
  223. package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.js +47 -0
  224. package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.test.js +35 -0
  225. package/lib/utils/readWorkerFile/index.js +3 -0
  226. package/lib/utils/readWorkerFile/readWorkerFile.utils.js +36 -0
  227. package/lib/utils/readWorkerFile/readWorkerFile.utils.test.js +24 -0
  228. package/package.json +99 -0
  229. package/releaserc.json +87 -0
  230. package/tasks/sync-aliases.js +115 -0
@@ -0,0 +1,140 @@
1
+ import BaseService from './base.service.js';
2
+
3
+ /**
4
+ * Class representing the Application Service.
5
+ * @augments BaseService
6
+ */
7
+ class ApplicationService extends BaseService {
8
+ /**
9
+ * Create an instance of the ApplicationService.
10
+ */
11
+ constructor() {
12
+ super('/edge_applications');
13
+ }
14
+
15
+ /**
16
+ * Get all applications.
17
+ * @returns {Promise} A Promise representing the result of the API call.
18
+ */
19
+ getAll() {
20
+ return super.get();
21
+ }
22
+
23
+ /**
24
+ * Get an application by ID.
25
+ * @param {string} id - The ID of the application.
26
+ * @returns {Promise} A Promise representing the result of the API call.
27
+ */
28
+ getById(id) {
29
+ return super.get(`/${id}`);
30
+ }
31
+
32
+ /**
33
+ * Create a new application.
34
+ * @param {object} payload - The payload for creating the application.
35
+ * @param {string} payload.name - The name of the application.
36
+ * @param {string} payload.delivery_protocol - The delivery protocol for the application.
37
+ * @returns {Promise} A Promise representing the result of the API call.
38
+ */
39
+ create(payload) {
40
+ return super.post('', JSON.stringify(payload));
41
+ }
42
+
43
+ /**
44
+ * Update an application.
45
+ * @param {string} id - The ID of the application to update.
46
+ * @param {object} payload - The payload for updating the application.
47
+ * @param {string} payload.name - The updated name of the application.
48
+ * @param {string} payload.delivery_protocol - The updated delivery protocol for the application.
49
+ * @returns {Promise} A Promise representing the result of the API call.
50
+ */
51
+ update(id, payload) {
52
+ return super.patch(`/${id}`, JSON.stringify(payload));
53
+ }
54
+
55
+ /**
56
+ * Delete an application.
57
+ * @param {string} id - The ID of the application to delete.
58
+ * @returns {Promise} A Promise representing the result of the API call.
59
+ */
60
+ delete(id) {
61
+ return super.delete(`/${id}`);
62
+ }
63
+
64
+ /**
65
+ * Instantiate a function instance for an application.
66
+ * @param {string} applicationId - The ID of the application.
67
+ * @param {object} payload - The payload for instantiating the function instance.
68
+ * @param {number} payload.edge_function_id - The ID of the edge function to be instantiated.
69
+ * @param {object} payload.args - Additional arguments for the function instance.
70
+ * @returns {Promise} A Promise representing the result of the API call.
71
+ */
72
+ instantiate(applicationId, payload) {
73
+ return super.post(`/${applicationId}/functions_instances`, JSON.stringify(payload));
74
+ }
75
+
76
+ /**
77
+ * Create a rule for an application.
78
+ * @param {string} applicationId - The ID of the application.
79
+ * @param {object} payload - The payload for creating the rule.
80
+ * @returns {Promise} A Promise representing the result of the API call.
81
+ */
82
+ createRule(applicationId, payload) {
83
+ return super.post(`/${applicationId}/rules_engine/request/rules`, JSON.stringify(payload));
84
+ }
85
+
86
+ /**
87
+ * Update a rule for an application.
88
+ * @param {string} applicationId - The ID of the application.
89
+ * @param {string} ruleId - The ID of the rule to update.
90
+ * @param {object} payload - The payload for updating the rule.
91
+ * @returns {Promise} A Promise representing the result of the API call.
92
+ */
93
+ updateRule(applicationId, ruleId, payload) {
94
+ return super.patch(`/${applicationId}/rules_engine/request/rules/${ruleId}`, JSON.stringify(payload));
95
+ }
96
+
97
+ /**
98
+ * Get an application rules.
99
+ * @param {string} applicationId - The ID of the application to get rules.
100
+ * @returns {Promise} A Promise representing the result of the API call.
101
+ */
102
+ getRules(applicationId) {
103
+ return super.get(`/${applicationId}/rules_engine/request/rules`);
104
+ }
105
+ }
106
+
107
+ /**
108
+ * @name ApplicationService
109
+ * Instance of the Application Service.
110
+ * This instance provides methods to interact with Azion's Application service,
111
+ * such as creating, updating, and deleting applications, as well as retrieving application details.
112
+ * @type {BaseService}
113
+ * @memberof Services
114
+ * @function create
115
+ * @function update
116
+ * @function getAll
117
+ * @function getById
118
+ * @function delete
119
+ * @function instantiate
120
+ * @function createRule
121
+ * @function updateRule
122
+ * @function getRules
123
+ * @example
124
+ *
125
+ * // Example usage
126
+ * const payload = {
127
+ * name: "My Application",
128
+ * delivery_protocol: "http,https"
129
+ * };
130
+ *
131
+ * ApplicationService.create(payload)
132
+ * .then((response) => {
133
+ * console.log(response);
134
+ * })
135
+ * .catch((error) => {
136
+ * feedback.error(error);
137
+ * });
138
+ */
139
+ const ApplicationServiceInstance = new ApplicationService();
140
+ export default ApplicationServiceInstance;
@@ -0,0 +1,200 @@
1
+ import { vulcan } from '#env';
2
+ import _ from 'lodash';
3
+
4
+ const env = globalThis.vulcan?.env ? globalThis.vulcan.env : 'production';
5
+
6
+ const APIS = {
7
+ local: 'http://localhost:8082',
8
+ stage: 'https://stage-api.azion.net',
9
+ production: 'https://api.azionapi.net',
10
+ };
11
+
12
+ /**
13
+ * Removes leading and trailing slashes from a resource string.
14
+ * @param {string} resource - The resource string to process.
15
+ * @returns {string} The processed resource string without leading and trailing slashes.
16
+ */
17
+ const removeLeadingAndTrailingSlashes = (resource) => (resource ? `/${resource.toString().replace(/^\/|\/$/g, '')}` : '');
18
+
19
+ /**
20
+ * Reads the API token from the Vulcan environment.
21
+ * @async
22
+ * @returns {Promise<string>} A Promise that resolves to the API token.
23
+ */
24
+ /**
25
+ /**
26
+ Retrieves the API authentication token from the Vulcan environment
27
+ and returns it as a header object.
28
+ * @returns {Promise<object>} A Promise that resolves to an object
29
+ * containing the token in the format { headers: { Authorization: 'Token ${value}' } }.
30
+ */
31
+ const getAuthHeaders = async () => {
32
+ const token = (await vulcan.readVulcanEnv()).API_TOKEN;
33
+ return { headers: { Authorization: `Token ${token}` } };
34
+ };
35
+
36
+ /**
37
+ * The BaseService class provides a foundation for communicating with the Azion platform.
38
+ * It enables the sending of HTTP requests to various APIs,
39
+ * including local, staging, and production endpoints.
40
+ * In addition to standard GET, POST, PUT, PATCH, and DELETE requests,
41
+ * BaseService also supports GraphQL queries
42
+ * BaseService includes methods for GET, POST, PUT, PATCH, DELETE, and GraphQL requests.
43
+ * @namespace Services
44
+ * @class BaseService
45
+ * @type {BaseService}
46
+ * @example
47
+ * class FrodoService extends BaseService {
48
+ * constructor() {
49
+ * super('frodoApi', '/v3', { headers: { 'Content-Type': 'text/plain' } });
50
+ * }
51
+ *
52
+ * getRing() {
53
+ * return super.get('/rings');
54
+ * }
55
+ * postLembas(lembas){
56
+ * return super.post('/lembas', lembas)
57
+ * }
58
+ * }
59
+ */
60
+ class BaseService {
61
+ /**
62
+ * Create a base service.
63
+ * @param {string} resource - @param {string} resource - The resource of the API. If it starts with "http://" or "https://", it will be used as is. Otherwise, it will be concatenated with the API based on the environment.
64
+ * @param {object} config - The configuration for the service.
65
+ */
66
+ constructor(resource, config) {
67
+ if (resource && /^(https?:\/\/)/.test(resource)) this.base = resource;
68
+ else this.base = APIS[env] + (resource || '');
69
+
70
+ this.config = {
71
+ timeout: 90000,
72
+ headers: {
73
+ 'Content-Type': 'application/json',
74
+ Accept: 'application/json; version=3',
75
+ },
76
+ ...config,
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Send a GET request.
82
+ * @param {string} resource - The Resource to request.
83
+ * @param {object} config - The configuration for the request.
84
+ * @returns {Promise} The Promise object representing the fetch operation.
85
+ */
86
+ async get(resource, config) {
87
+ const fullUrl = this.base + removeLeadingAndTrailingSlashes(resource);
88
+ const authHeaders = config?.headers?.Authorization
89
+ ? {}
90
+ : await getAuthHeaders();
91
+ const mergedConfig = _.merge({}, authHeaders, this.config, config);
92
+ return fetch(fullUrl, {
93
+ method: 'GET',
94
+ ...mergedConfig,
95
+ });
96
+ }
97
+
98
+ /**
99
+ * Send a GraphQL GET request.
100
+ * @param {string} resource - The resource path of the GraphQL endpoint.
101
+ * @param {object} config - The configuration for the request.
102
+ * @param {string} query - The GraphQL query string.
103
+ * @returns {Promise} The Promise object representing the fetch operation.
104
+ */
105
+ async graphQl(resource, config, query) {
106
+ const fullUrl = this.base + removeLeadingAndTrailingSlashes(resource);
107
+ const authHeaders = config?.headers?.Authorization
108
+ ? {}
109
+ : await getAuthHeaders();
110
+ const mergedConfig = _.merge({}, authHeaders, this.config, config);
111
+ const payload = {
112
+ query,
113
+ };
114
+ return fetch(fullUrl, {
115
+ method: 'POST',
116
+ body: JSON.stringify(payload),
117
+ ...mergedConfig,
118
+ });
119
+ }
120
+
121
+ /**
122
+ * Send a POST request.
123
+ * @param {string} resource - The Resource to request.
124
+ * @param {object} data - The data to send in the body of the request.
125
+ * @param {object} config - The configuration for the request.
126
+ * @returns {Promise} The Promise object representing the fetch operation.
127
+ */
128
+ async post(resource, data, config) {
129
+ const fullUrl = this.base + removeLeadingAndTrailingSlashes(resource);
130
+ const authHeaders = config?.headers?.Authorization
131
+ ? {}
132
+ : await getAuthHeaders();
133
+ const mergedConfig = _.merge({}, authHeaders, this.config, config);
134
+ return fetch(fullUrl, {
135
+ method: 'POST',
136
+ body: data,
137
+ ...mergedConfig,
138
+ });
139
+ }
140
+
141
+ /**
142
+ * Send a PUT request.
143
+ * @param {string} resource - The Resource to request.
144
+ * @param {object} data - The data to send in the body of the request.
145
+ * @param {object} config - The configuration for the request.
146
+ * @returns {Promise} The Promise object representing the fetch operation.
147
+ */
148
+ async put(resource, data, config) {
149
+ const fullUrl = this.base + removeLeadingAndTrailingSlashes(resource);
150
+ const authHeaders = config?.headers?.Authorization
151
+ ? {}
152
+ : await getAuthHeaders();
153
+ const mergedConfig = _.merge({}, authHeaders, this.config, config);
154
+ return fetch(fullUrl, {
155
+ method: 'PUT',
156
+ body: data,
157
+ ...mergedConfig,
158
+ });
159
+ }
160
+
161
+ /**
162
+ * Send a PATCH request.
163
+ * @param {string} resource - The Resource to request.
164
+ * @param {object} data - The data to send in the body of the request.
165
+ * @param {object} config - The configuration for the request.
166
+ * @returns {Promise} The Promise object representing the fetch operation.
167
+ */
168
+ async patch(resource, data, config) {
169
+ const fullUrl = this.base + removeLeadingAndTrailingSlashes(resource);
170
+ const authHeaders = config?.headers?.Authorization
171
+ ? {}
172
+ : await getAuthHeaders();
173
+ const mergedConfig = _.merge({}, authHeaders, this.config, config);
174
+ return fetch(fullUrl, {
175
+ method: 'PATCH',
176
+ body: data,
177
+ ...mergedConfig,
178
+ });
179
+ }
180
+
181
+ /**
182
+ * Send a DELETE request.
183
+ * @param {string} resource - The Resource to request.
184
+ * @param {object} config - The configuration for the request.
185
+ * @returns {Promise} The Promise object representing the fetch operation.
186
+ */
187
+ async delete(resource, config) {
188
+ const fullUrl = this.base + removeLeadingAndTrailingSlashes(resource);
189
+ const authHeaders = config?.headers?.Authorization
190
+ ? {}
191
+ : await getAuthHeaders();
192
+ const mergedConfig = _.merge({}, authHeaders, this.config, config);
193
+ return fetch(fullUrl, {
194
+ method: 'DELETE',
195
+ ...mergedConfig,
196
+ });
197
+ }
198
+ }
199
+
200
+ export default BaseService;
@@ -0,0 +1,80 @@
1
+ import BaseService from './base.service.js';
2
+
3
+ /**
4
+ * Class representing the Domain Service.
5
+ * @augments BaseService
6
+ */
7
+ class DomainService extends BaseService {
8
+ /**
9
+ * Create an instance of the DomainService.
10
+ */
11
+ constructor() {
12
+ super('/domains');
13
+ }
14
+
15
+ /**
16
+ * Get all domains.
17
+ * @returns {Promise} A Promise representing the result of the API call.
18
+ */
19
+ getAll() {
20
+ return super.get();
21
+ }
22
+
23
+ /**
24
+ * Get a domain by ID.
25
+ * @param {string} id - The ID of the domain.
26
+ * @returns {Promise} A Promise representing the result of the API call.
27
+ */
28
+ getById(id) {
29
+ return super.get(`/${id}`);
30
+ }
31
+
32
+ /**
33
+ * Create a new domain.
34
+ * @param {object} payload - The payload for creating the domain.
35
+ * @param {string} payload.name - The name of the domain.
36
+ * @param {boolean} payload.cname_access_only - Whether the domain should
37
+ * be accessed only via CNAME.
38
+ * @param {number|null} payload.digital_certificate_id - The ID of the digital certificate
39
+ * to be associated with the domain.
40
+ * @param {number} payload.edge_application_id - The ID of the edge application
41
+ * to which the domain belongs.
42
+ * @param {boolean} payload.is_active - Whether the domain is active.
43
+ * @returns {Promise} A Promise representing the result of the API call.
44
+ */
45
+ create(payload) {
46
+ return super.post('', JSON.stringify(payload));
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Instance of the Domain Service.
52
+ * This instance provides methods to interact with the Azion Domain API,
53
+ * such as retrieving domains, getting domain details, and creating new domains.
54
+ * @type {BaseService}
55
+ * @memberof Services
56
+ * @function DomainService.getAll
57
+ * @function DomainService.getById
58
+ * @function DomainService.create
59
+ * @example
60
+ *
61
+ * // Example usage
62
+ * const payload = {
63
+ * name: 'example.com',
64
+ * cname_access_only: true,
65
+ * digital_certificate_id: 12345,
66
+ * edge_application_id: 67890,
67
+ * is_active: true
68
+ * };
69
+ *
70
+ * DomainService.create(payload)
71
+ * .then((response) => {
72
+ * console.log(response);
73
+ * })
74
+ * .catch((error) => {
75
+ * feedback.error(error);
76
+ * });
77
+ */
78
+ const DomainServiceInstance = new DomainService();
79
+
80
+ export default DomainServiceInstance;
@@ -0,0 +1,65 @@
1
+ import BaseService from './base.service.js';
2
+
3
+ /**
4
+ * Class representing the Events Service.
5
+ * @augments BaseService
6
+ */
7
+ class EventsService extends BaseService {
8
+ /**
9
+ * Create an instance of the EventsService.
10
+ */
11
+ constructor() {
12
+ super('/events/graphql');
13
+ }
14
+
15
+ /**
16
+ * Get the console logs for a specific function.
17
+ * @param {string} functionId - The ID of the function.
18
+ * @returns {Promise} A Promise representing the result of the API call.
19
+ */
20
+ getFunctionsLogs(functionId) {
21
+ const filter = functionId ? `functionId: "${functionId}"` : '';
22
+
23
+ return super.graphQl('', '', `
24
+ query ConsoleLog {
25
+ cellsConsoleEvents(
26
+ limit: 10
27
+ ${filter ? `filter: { ${filter} }` : ''}
28
+ orderBy: [ts_DESC]
29
+ ) {
30
+ ts
31
+ solutionId
32
+ configurationId
33
+ functionId
34
+ id
35
+ lineSource
36
+ level
37
+ line
38
+ }
39
+ }
40
+ `);
41
+ }
42
+ }
43
+ /**
44
+ * @name EventsService
45
+ * @memberof Services
46
+ * Instance of the Events Service.
47
+ * This instance provides methods to interact with Azion's Events service,
48
+ * such as retrieving console logs for a specific function.
49
+ * @type {BaseService}
50
+ * @function EventsService.getFunctionsLogs
51
+ * @example
52
+ *
53
+ * // Example usage
54
+ * const functionId = '12345';
55
+ *
56
+ * EventsService.getFunctionsLogs(functionId)
57
+ * .then((response) => {
58
+ * console.log(response);
59
+ * })
60
+ * .catch((error) => {
61
+ * feedback.error(error);
62
+ * });
63
+ */
64
+ const EventsServiceInstance = new EventsService();
65
+ export default EventsServiceInstance;
@@ -0,0 +1,105 @@
1
+ import BaseService from './base.service.js';
2
+
3
+ /**
4
+ * Class representing the Function Service.
5
+ * @augments BaseService
6
+ */
7
+ class FunctionService extends BaseService {
8
+ /**
9
+ * Create an instance of the FunctionService.
10
+ */
11
+ constructor() {
12
+ super('/edge_functions');
13
+ }
14
+
15
+ /**
16
+ * Get all functions.
17
+ * @returns {Promise} A Promise representing the result of the API call.
18
+ */
19
+ getAll() {
20
+ return super.get();
21
+ }
22
+
23
+ /**
24
+ * Get a function by ID.
25
+ * @param {string} id - The ID of the function.
26
+ * @returns {Promise} A Promise representing the result of the API call.
27
+ */
28
+ getById(id) {
29
+ return super.get(`/${id}`);
30
+ }
31
+
32
+ /**
33
+ * Create a new function.
34
+ * @param {object} payload - The payload for creating the function.
35
+ * @param {string} payload.name - The name of the function.
36
+ * @param {string} payload.code - The code of the function.
37
+ * @param {string} payload.language - The language of the function.
38
+ * @param {string} payload.initiator_type - The initiator type of the function.
39
+ * @param {object} payload.json_args - The JSON arguments of the function.
40
+ * @param {boolean} payload.active - The status of the function (active or inactive).
41
+ * @returns {Promise} A Promise representing the result of the API call.
42
+ */
43
+ create(payload) {
44
+ return super.post('', JSON.stringify(payload));
45
+ }
46
+
47
+ /**
48
+ * Update a function by ID.
49
+ * @param {string} id - The ID of the function.
50
+ * @param {object} payload - The payload for updating the function.
51
+ * @param {string} payload.name - The updated name of the function.
52
+ * @param {string} payload.code - The updated code of the function.
53
+ * @param {string} payload.language - The updated language of the function.
54
+ * @param {string} payload.initiator_type - The updated initiator type of the function.
55
+ * @param {object} payload.json_args - The updated JSON arguments of the function.
56
+ * @param {boolean} payload.active - The updated status of the function (active or inactive).
57
+ * @returns {Promise} A Promise representing the result of the API call.
58
+ */
59
+ update(id, payload) {
60
+ return super.patch(`/${id}`, JSON.stringify(payload));
61
+ }
62
+
63
+ /**
64
+ * Delete a function by ID.
65
+ * @param {string} id - The ID of the function to delete.
66
+ * @returns {Promise} A Promise representing the result of the API call.
67
+ */
68
+ delete(id) {
69
+ return super.delete(`/${id}`);
70
+ }
71
+ }
72
+ /**
73
+ * @name FunctionService
74
+ * @memberof Services
75
+ * Instance of the Function Service.
76
+ * This instance provides methods to interact with Azion's Function service,
77
+ * such as creating, updating, and deleting functions, as well as retrieving function details.
78
+ * @type {BaseService}
79
+ * @function FunctionService.create
80
+ * @function FunctionService.update
81
+ * @function FunctionService.getAll
82
+ * @function FunctionService.getById
83
+ * @example
84
+ * const functionService = new FunctionService();
85
+ *
86
+ * // Example usage
87
+ * const payload = {
88
+ name: "Function One"
89
+ code: "...",
90
+ language: "javascript",
91
+ initiator_type: "edge_application",
92
+ json_args: {},
93
+ active: true
94
+ };
95
+ *
96
+ * functionService.create(payload)
97
+ * .then((response) => {
98
+ * console.log(response);
99
+ * })
100
+ * .catch((error) => {
101
+ * feedback.error(error);
102
+ * });
103
+ */
104
+ const FunctionServiceInstance = new FunctionService();
105
+ export default FunctionServiceInstance;
@@ -0,0 +1,8 @@
1
+ import TokensService from './tokens.service.js';
2
+ import ApplicationService from './application.service.js';
3
+ import DomainService from './domain.service.js';
4
+ import FunctionService from './function.service.js';
5
+
6
+ export {
7
+ TokensService, ApplicationService, DomainService, FunctionService,
8
+ };
@@ -0,0 +1,59 @@
1
+ import BaseService from './base.service.js';
2
+
3
+ /**
4
+ * Service for interacting with the Azion Storage API.
5
+ * Extends the BaseService class.
6
+ */
7
+ class StorageService extends BaseService {
8
+ /**
9
+ * Constructs a new instance of the StorageService.
10
+ * Sets the base URL for the Storage API.
11
+ */
12
+ constructor() {
13
+ super('https://storage-api.azion.com/storage');
14
+ }
15
+
16
+ /**
17
+ * Uploads a file to the specified version ID in the storage API.
18
+ * @param {string} versionId - The version ID for the file.
19
+ * @param {string} file - The file content as a String.
20
+ * @param {string} staticPath - The static path for the asset.
21
+ * @param {string} contentType - The content type of the file.
22
+ * @returns {Promise} A promise that resolves with the API response.
23
+ */
24
+ async upload(versionId, file, staticPath, contentType) {
25
+ return super.post(`${versionId}`, file, {
26
+ headers: {
27
+ 'X-Azion-Static-Path': staticPath,
28
+ 'Content-Type': contentType,
29
+ },
30
+ });
31
+ }
32
+ }
33
+
34
+ /**
35
+ * @name StorageService
36
+ * @memberof Services
37
+ * Instance of the Storage Service.
38
+ * This instance provides methods to interact with the Azion Storage API,
39
+ * such as uploading files to the storage.
40
+ * @type {BaseService}
41
+ * @function StorageService.upload
42
+ * @example
43
+ *
44
+ * // Example usage
45
+ * const versionId = '12345';
46
+ * const fileContent = '...'; // File content as a string
47
+ * const staticPath = '/assets/images/';
48
+ * const contentType = 'text/javascript';
49
+ *
50
+ * StorageService.upload(versionId, fileContent, staticPath, contentType)
51
+ * .then((response) => {
52
+ * console.log(response);
53
+ * })
54
+ * .catch((error) => {
55
+ * feedback.error(error);
56
+ * });
57
+ */
58
+ const StorageServiceInstance = new StorageService();
59
+ export default StorageServiceInstance;