@adobe/helix-deploy 11.1.11 → 11.1.12

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [11.1.12](https://github.com/adobe/helix-deploy/compare/v11.1.11...v11.1.12) (2024-06-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * restore worker settings ([#712](https://github.com/adobe/helix-deploy/issues/712)) ([8ba9ca1](https://github.com/adobe/helix-deploy/commit/8ba9ca1414c3e2ea10258bef64e509e53d4cd72a))
7
+
1
8
  ## [11.1.11](https://github.com/adobe/helix-deploy/compare/v11.1.10...v11.1.11) (2024-06-08)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-deploy",
3
- "version": "11.1.11",
3
+ "version": "11.1.12",
4
4
  "description": "Library and Commandline Tools to build and deploy OpenWhisk Actions",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/adobe/helix-deploy#readme",
@@ -155,7 +155,10 @@ export default class BaseBundler {
155
155
 
156
156
  async updateArchive(archive, packageJson) {
157
157
  const { cfg } = this;
158
- archive.file(cfg.bundle, { name: 'index.js' });
158
+ if (cfg.archs.includes('node')) {
159
+ archive.file(cfg.bundle, { name: 'index.js' });
160
+ }
161
+
159
162
  cfg.statics.forEach(([src, name]) => {
160
163
  try {
161
164
  if (fse.lstatSync(src)
@@ -168,6 +171,7 @@ export default class BaseBundler {
168
171
  throw Error(`error with static file: ${e.message}`);
169
172
  }
170
173
  });
174
+
171
175
  cfg.modules.forEach((mod) => {
172
176
  archive.directory(path.resolve(cfg.cwd, `node_modules/${mod}`), `node_modules/${mod}`);
173
177
  });
@@ -124,4 +124,9 @@ export default class EdgeBundler extends WebpackBundler {
124
124
  }
125
125
  return this.createWebpackBundle('edge');
126
126
  }
127
+
128
+ // eslint-disable-next-line class-methods-use-this
129
+ validateBundle() {
130
+ // TODO: validate edge bundle, skipped since we're on node
131
+ }
127
132
  }
@@ -44,7 +44,12 @@ export default class CloudflareConfig {
44
44
 
45
45
  static yarg(yargs) {
46
46
  return yargs
47
- .group(['cloudflare-account-id', 'cloudflare-auth', 'cloudflare-email', 'cloudflare-test-domain'], 'Cloudflare Workers Deployment Options')
47
+ .group([
48
+ 'cloudflare-account-id',
49
+ 'cloudflare-auth',
50
+ 'cloudflare-email',
51
+ 'cloudflare-test-domain',
52
+ ], 'Cloudflare Workers Deployment Options')
48
53
  .option('cloudflare-account-id', {
49
54
  description: 'the Cloudflare account ID to deploy to',
50
55
  type: 'string',
@@ -43,6 +43,7 @@ export default class CloudflareDeployer extends BaseDeployer {
43
43
 
44
44
  async deploy() {
45
45
  const body = fs.readFileSync(this.cfg.edgeBundle);
46
+ const settings = await this.getSettings();
46
47
  const { id } = await this.createKVNamespace(`${this.cfg.packageName}--secrets`);
47
48
 
48
49
  const metadata = {
@@ -86,12 +87,46 @@ export default class CloudflareDeployer extends BaseDeployer {
86
87
  }
87
88
 
88
89
  await this.updatePackageParams(id, this.cfg.packageParams);
90
+
91
+ await this.restoreSettings(settings);
92
+ }
93
+
94
+ async getSettings() {
95
+ const res = await this.fetch(`https://api.cloudflare.com/client/v4/accounts/${this._cfg.accountID}/workers/scripts/${this.fullFunctionName}/script-settings`, {
96
+ method: 'GET',
97
+ headers: {
98
+ Authorization: `Bearer ${this._cfg.auth}`,
99
+ },
100
+ });
101
+ if (!res.ok) {
102
+ return null;
103
+ }
104
+ const { result } = await res.json();
105
+ return result;
106
+ }
107
+
108
+ async restoreSettings(existing) {
109
+ if (!existing) {
110
+ return true;
111
+ }
112
+ const res = await this.fetch(`https://api.cloudflare.com/client/v4/accounts/${this._cfg.accountID}/workers/scripts/${this.fullFunctionName}/script-settings`, {
113
+ method: 'PATCH',
114
+ headers: {
115
+ Authorization: `Bearer ${this._cfg.auth}`,
116
+ 'content-type': 'application/json',
117
+ },
118
+ body: JSON.stringify(existing),
119
+ });
120
+ return res.ok;
89
121
  }
90
122
 
91
123
  async updatePackageParams(id, params) {
92
124
  const kvlist = Object.entries(params).map(([key, value]) => ({
93
125
  key, value,
94
126
  }));
127
+ if (!kvlist.length) {
128
+ return true;
129
+ }
95
130
 
96
131
  const res = await this.fetch(`https://api.cloudflare.com/client/v4/accounts/${this._cfg.accountID}/storage/kv/namespaces/${id}/bulk`, {
97
132
  method: 'PUT',
@@ -35,7 +35,6 @@ async function run(bundlePath, cfg) {
35
35
  },
36
36
  },
37
37
  };
38
-
39
38
  const testUrl = String(test).startsWith('/') ? test : cfg.testUrl;
40
39
  if (testUrl) {
41
40
  const url = new URL(testUrl, 'https://localhost/');
@@ -43,6 +42,7 @@ async function run(bundlePath, cfg) {
43
42
  event.rawPath += url.pathname;
44
43
  event.rawQueryString = url.searchParams.toString();
45
44
  }
45
+
46
46
  const fn = typeof lambda.raw === 'function' ? lambda.raw : lambda;
47
47
  result.response = await fn(event, {
48
48
  invokedFunctionArn: `arn:aws:lambda:us-east-1:118435662149:function:${cfg.packageName}--${cfg.baseName}:${cfg.version}`,