@adobe/helix-deploy 4.13.0 → 4.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,99 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ /* eslint-env serviceworker */
13
+ /* global Dictionary */
14
+
15
+ async function handler(event) {
16
+ try {
17
+ const { request } = event;
18
+ console.log('Fastly Adapter is here');
19
+ let packageParams;
20
+ // eslint-disable-next-line import/no-unresolved,global-require
21
+ const { main } = require('./main.js');
22
+ const context = {
23
+ resolver: null,
24
+ pathInfo: {
25
+ suffix: request.url.replace(/\?.*/, ''),
26
+ },
27
+ runtime: {
28
+ name: 'compute-at-edge',
29
+ // region: request.cf.colo,
30
+ },
31
+ func: {
32
+ name: null,
33
+ package: null,
34
+ version: null,
35
+ fqn: null,
36
+ app: null,
37
+ },
38
+ invocation: {
39
+ id: null,
40
+ deadline: null,
41
+ transactionId: null,
42
+ requestId: null,
43
+ },
44
+ env: new Proxy(new Dictionary('secrets'), {
45
+ get: (target, prop) => {
46
+ try {
47
+ return target.get(prop);
48
+ } catch {
49
+ if (packageParams) {
50
+ console.log('Using cached params');
51
+ return packageParams[prop];
52
+ }
53
+ const url = target.get('_package');
54
+ const token = target.get('_token');
55
+ // console.log(`Getting secrets from ${url} with ${token}`);
56
+ return fetch(url, {
57
+ backend: 'gateway',
58
+ headers: {
59
+ authorization: `Bearer ${token}`,
60
+ },
61
+ }).then((response) => {
62
+ if (response.ok) {
63
+ // console.log('response is ok...');
64
+ return response.text().then((json) => {
65
+ // console.log('json received: ' + json);
66
+ packageParams = JSON.parse(json);
67
+ return packageParams[prop];
68
+ }).catch((error) => {
69
+ console.error(`Unable to parse JSON: ${error.message}`);
70
+ });
71
+ }
72
+ console.error(`HTTP status is not ok: ${response.status}`);
73
+ return undefined;
74
+ }).catch((err) => {
75
+ console.error(`Unable to fetch parames: ${err.message}`);
76
+ });
77
+ }
78
+ },
79
+ }),
80
+ storage: null,
81
+ };
82
+ const response = await main(request, context);
83
+ return response;
84
+ } catch (e) {
85
+ console.log(e.message);
86
+ return new Response(`Error: ${e.message}`, { status: 500 });
87
+ }
88
+ }
89
+
90
+ function fastly() {
91
+ console.log('checking for fastly environment');
92
+ /* eslint-disable-next-line no-undef */
93
+ if (CacheOverride) {
94
+ return handler;
95
+ }
96
+ return false;
97
+ }
98
+
99
+ module.exports = fastly;
@@ -9,7 +9,6 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
-
13
12
  // eslint-disable-next-line no-underscore-dangle
14
13
  global.__rootdir = __dirname;
15
14
 
File without changes
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ /* eslint-env serviceworker */
13
+
14
+ module.exports = {
15
+ // replacing helix-fetch with the built-in APIs
16
+ fetch,
17
+ Request,
18
+ Response,
19
+ };
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ /* eslint-env serviceworker */
13
+ const fastly = require('./fastly-adapter');
14
+ const cloudflare = require('./cloudflare-adapter');
15
+
16
+ /* eslint-disable no-restricted-globals */
17
+ if (typeof addEventListener === 'function') {
18
+ addEventListener('fetch', (event) => {
19
+ const handler = cloudflare() || fastly();
20
+ if (typeof handler === 'function') {
21
+ event.respondWith(handler(event));
22
+ }
23
+ });
24
+ }