@mastra/deployer-cloudflare 0.0.0-storage-20250225005900 → 0.0.0-stream-vnext-usage-20250908171242
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 +2898 -4
- package/LICENSE.md +15 -0
- package/dist/babel/mastra-instance-wrapper.d.ts +24 -0
- package/dist/babel/mastra-instance-wrapper.d.ts.map +1 -0
- package/dist/babel/postgres-store-instance-checker.d.ts +21 -0
- package/dist/babel/postgres-store-instance-checker.d.ts.map +1 -0
- package/dist/index.cjs +292 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +45 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +213 -56
- package/dist/index.js.map +1 -0
- package/dist/plugins/__fixtures__/basic.d.ts +5 -0
- package/dist/plugins/__fixtures__/basic.d.ts.map +1 -0
- package/dist/plugins/__fixtures__/empty-mastra.d.ts +3 -0
- package/dist/plugins/__fixtures__/empty-mastra.d.ts.map +1 -0
- package/dist/plugins/__fixtures__/multiple-postgres-stores.d.ts +6 -0
- package/dist/plugins/__fixtures__/multiple-postgres-stores.d.ts.map +1 -0
- package/dist/plugins/mastra-instance-wrapper.d.ts +3 -0
- package/dist/plugins/mastra-instance-wrapper.d.ts.map +1 -0
- package/dist/plugins/postgres-store-instance-checker.d.ts +3 -0
- package/dist/plugins/postgres-store-instance-checker.d.ts.map +1 -0
- package/{src/secrets-manager/index.ts → dist/secrets-manager/index.cjs} +33 -52
- package/dist/secrets-manager/index.cjs.map +1 -0
- package/dist/secrets-manager/index.d.ts +25 -1
- package/dist/secrets-manager/index.d.ts.map +1 -0
- package/dist/secrets-manager/index.js +2 -0
- package/dist/secrets-manager/index.js.map +1 -0
- package/package.json +55 -23
- package/.turbo/turbo-build.log +0 -20
- package/LICENSE +0 -44
- package/dist/_tsup-dts-rollup.d.ts +0 -65
- package/global.d.ts +0 -1
- package/src/index.ts +0 -148
- package/src/secrets-manager/index.test.ts +0 -230
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -8
package/package.json
CHANGED
|
@@ -1,46 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-cloudflare",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-stream-vnext-usage-20250908171242",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"CHANGELOG.md"
|
|
9
|
+
],
|
|
6
10
|
"main": "dist/index.js",
|
|
7
11
|
"types": "dist/index.d.ts",
|
|
8
12
|
"exports": {
|
|
9
13
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
12
22
|
},
|
|
13
23
|
"./secrets-manager": {
|
|
14
|
-
"
|
|
15
|
-
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/secrets-manager/index.d.ts",
|
|
26
|
+
"default": "./dist/secrets-manager/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/secrets-manager/index.d.ts",
|
|
30
|
+
"default": "./dist/secrets-manager/index.cjs"
|
|
31
|
+
}
|
|
16
32
|
},
|
|
17
33
|
"./package.json": "./package.json"
|
|
18
34
|
},
|
|
19
35
|
"keywords": [],
|
|
20
36
|
"author": "",
|
|
21
|
-
"license": "
|
|
37
|
+
"license": "Apache-2.0",
|
|
22
38
|
"dependencies": {
|
|
39
|
+
"@babel/core": "^7.28.0",
|
|
23
40
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
24
|
-
"cloudflare": "^4.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
28
|
-
"rollup-plugin-shim": "^1.0.0",
|
|
29
|
-
"wrangler": "^3.103.2",
|
|
30
|
-
"zod": "^3.24.1",
|
|
31
|
-
"@mastra/core": "^0.0.0-storage-20250225005900",
|
|
32
|
-
"@mastra/deployer": "^0.0.0-storage-20250225005900"
|
|
41
|
+
"cloudflare": "^4.5.0",
|
|
42
|
+
"rollup": "~4.50.0",
|
|
43
|
+
"@mastra/deployer": "0.0.0-stream-vnext-usage-20250908171242"
|
|
33
44
|
},
|
|
34
45
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
46
|
+
"@babel/types": "^7.28.2",
|
|
47
|
+
"@microsoft/api-extractor": "^7.52.8",
|
|
48
|
+
"@types/babel__core": "^7.20.5",
|
|
49
|
+
"@types/node": "^20.19.0",
|
|
50
|
+
"eslint": "^9.30.1",
|
|
51
|
+
"tsup": "^8.5.0",
|
|
52
|
+
"typescript": "^5.8.3",
|
|
53
|
+
"vitest": "^3.2.4",
|
|
54
|
+
"zod": "^3.25.76",
|
|
55
|
+
"@internal/types-builder": "0.0.0-stream-vnext-usage-20250908171242",
|
|
56
|
+
"@internal/lint": "0.0.0-stream-vnext-usage-20250908171242",
|
|
57
|
+
"@mastra/core": "0.0.0-stream-vnext-usage-20250908171242"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://mastra.ai",
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
63
|
+
"directory": "deployers/cloudflare"
|
|
64
|
+
},
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"zod": "^3.25.0 || ^4.0.0",
|
|
70
|
+
"@mastra/core": "0.0.0-stream-vnext-usage-20250908171242"
|
|
40
71
|
},
|
|
41
72
|
"scripts": {
|
|
42
|
-
"build": "tsup
|
|
43
|
-
"build:watch": "
|
|
44
|
-
"test": "vitest run"
|
|
73
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
74
|
+
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
75
|
+
"test": "vitest run",
|
|
76
|
+
"lint": "eslint ."
|
|
45
77
|
}
|
|
46
78
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @mastra/deployer-cloudflare@0.1.5-alpha.1 build /Users/ward/projects/mastra/mastra/deployers/cloudflare
|
|
4
|
-
> tsup src/index.ts src/secrets-manager/index.ts --format esm --experimental-dts --clean --treeshake
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m Building entry: src/index.ts, src/secrets-manager/index.ts
|
|
7
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
-
[34mCLI[39m tsup v8.3.6
|
|
9
|
-
[34mTSC[39m Build start
|
|
10
|
-
[32mTSC[39m ⚡️ Build success in 2330ms
|
|
11
|
-
[34mDTS[39m Build start
|
|
12
|
-
[34mCLI[39m Target: es2022
|
|
13
|
-
Analysis will use the bundled TypeScript version 5.7.3
|
|
14
|
-
[36mWriting package typings: /Users/ward/projects/mastra/mastra/deployers/cloudflare/dist/_tsup-dts-rollup.d.ts[39m
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in 831ms
|
|
16
|
-
[34mCLI[39m Cleaning output folder
|
|
17
|
-
[34mESM[39m Build start
|
|
18
|
-
[32mESM[39m [1mdist/index.js [22m[32m2.89 KB[39m
|
|
19
|
-
[32mESM[39m [1mdist/secrets-manager/index.js [22m[32m2.38 KB[39m
|
|
20
|
-
[32mESM[39m ⚡️ Build success in 57ms
|
package/LICENSE
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
Elastic License 2.0 (ELv2)
|
|
2
|
-
|
|
3
|
-
**Acceptance**
|
|
4
|
-
By using the software, you agree to all of the terms and conditions below.
|
|
5
|
-
|
|
6
|
-
**Copyright License**
|
|
7
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
8
|
-
|
|
9
|
-
**Limitations**
|
|
10
|
-
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
11
|
-
|
|
12
|
-
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
13
|
-
|
|
14
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
15
|
-
|
|
16
|
-
**Patents**
|
|
17
|
-
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
18
|
-
|
|
19
|
-
**Notices**
|
|
20
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
21
|
-
|
|
22
|
-
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
23
|
-
|
|
24
|
-
**No Other Rights**
|
|
25
|
-
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
26
|
-
|
|
27
|
-
**Termination**
|
|
28
|
-
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
29
|
-
|
|
30
|
-
**No Liability**
|
|
31
|
-
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
32
|
-
|
|
33
|
-
**Definitions**
|
|
34
|
-
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
35
|
-
|
|
36
|
-
_you_ refers to the individual or entity agreeing to these terms.
|
|
37
|
-
|
|
38
|
-
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
39
|
-
|
|
40
|
-
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
41
|
-
|
|
42
|
-
_use_ means anything you do with the software requiring one of your licenses.
|
|
43
|
-
|
|
44
|
-
_trademark_ means trademarks, service marks, and similar rights.
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Deployer } from '@mastra/deployer';
|
|
2
|
-
|
|
3
|
-
declare interface CFRoute {
|
|
4
|
-
pattern: string;
|
|
5
|
-
zone_name: string;
|
|
6
|
-
custom_domain?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export declare class CloudflareDeployer extends Deployer {
|
|
10
|
-
private cloudflare;
|
|
11
|
-
routes?: CFRoute[];
|
|
12
|
-
workerNamespace?: string;
|
|
13
|
-
scope: string;
|
|
14
|
-
env?: Record<string, any>;
|
|
15
|
-
projectName?: string;
|
|
16
|
-
constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
|
|
17
|
-
env?: Record<string, any>;
|
|
18
|
-
scope: string;
|
|
19
|
-
projectName?: string;
|
|
20
|
-
routes?: CFRoute[];
|
|
21
|
-
workerNamespace?: string;
|
|
22
|
-
auth: {
|
|
23
|
-
apiToken: string;
|
|
24
|
-
apiEmail?: string;
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
writeFiles(outputDirectory: string): Promise<void>;
|
|
28
|
-
private getEntry;
|
|
29
|
-
prepare(outputDirectory: string): Promise<void>;
|
|
30
|
-
bundle(entryFile: string, outputDirectory: string): Promise<void>;
|
|
31
|
-
deploy(outputDirectory: string): Promise<void>;
|
|
32
|
-
tagWorker({ workerName, namespace, tags, scope, }: {
|
|
33
|
-
scope: string;
|
|
34
|
-
workerName: string;
|
|
35
|
-
namespace: string;
|
|
36
|
-
tags: string[];
|
|
37
|
-
}): Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export declare class CloudflareSecretsManager {
|
|
41
|
-
accountId: string;
|
|
42
|
-
apiToken: string;
|
|
43
|
-
baseUrl: string;
|
|
44
|
-
constructor({ accountId, apiToken }: {
|
|
45
|
-
accountId: string;
|
|
46
|
-
apiToken: string;
|
|
47
|
-
});
|
|
48
|
-
createSecret({ workerId, secretName, secretValue, }: {
|
|
49
|
-
workerId: string;
|
|
50
|
-
secretName: string;
|
|
51
|
-
secretValue: string;
|
|
52
|
-
}): Promise<any>;
|
|
53
|
-
createProjectSecrets({ workerId, customerId, envVars, }: {
|
|
54
|
-
workerId: string;
|
|
55
|
-
customerId: string;
|
|
56
|
-
envVars: Record<string, string>;
|
|
57
|
-
}): Promise<any>;
|
|
58
|
-
deleteSecret({ workerId, secretName }: {
|
|
59
|
-
workerId: string;
|
|
60
|
-
secretName: string;
|
|
61
|
-
}): Promise<any>;
|
|
62
|
-
listSecrets(workerId: string): Promise<any>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { }
|
package/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'rollup-plugin-shim';
|
package/src/index.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { Deployer, createChildProcessLogger } from '@mastra/deployer';
|
|
2
|
-
import { getBundler } from '@mastra/deployer/build';
|
|
3
|
-
import virtual from '@rollup/plugin-virtual';
|
|
4
|
-
import { Cloudflare } from 'cloudflare';
|
|
5
|
-
import { writeFileSync } from 'fs';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
|
|
8
|
-
interface CFRoute {
|
|
9
|
-
pattern: string;
|
|
10
|
-
zone_name: string;
|
|
11
|
-
custom_domain?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class CloudflareDeployer extends Deployer {
|
|
15
|
-
private cloudflare: Cloudflare | undefined;
|
|
16
|
-
routes?: CFRoute[] = [];
|
|
17
|
-
workerNamespace?: string;
|
|
18
|
-
scope: string;
|
|
19
|
-
env?: Record<string, any>;
|
|
20
|
-
projectName?: string;
|
|
21
|
-
|
|
22
|
-
constructor({
|
|
23
|
-
scope,
|
|
24
|
-
env,
|
|
25
|
-
projectName = 'mastra',
|
|
26
|
-
routes,
|
|
27
|
-
workerNamespace,
|
|
28
|
-
auth,
|
|
29
|
-
}: {
|
|
30
|
-
env?: Record<string, any>;
|
|
31
|
-
scope: string;
|
|
32
|
-
projectName?: string;
|
|
33
|
-
routes?: CFRoute[];
|
|
34
|
-
workerNamespace?: string;
|
|
35
|
-
auth: {
|
|
36
|
-
apiToken: string;
|
|
37
|
-
apiEmail?: string;
|
|
38
|
-
};
|
|
39
|
-
}) {
|
|
40
|
-
super({ name: 'CLOUDFLARE' });
|
|
41
|
-
|
|
42
|
-
this.scope = scope;
|
|
43
|
-
this.projectName = projectName;
|
|
44
|
-
this.routes = routes;
|
|
45
|
-
this.workerNamespace = workerNamespace;
|
|
46
|
-
|
|
47
|
-
if (env) {
|
|
48
|
-
this.env = env;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.cloudflare = new Cloudflare(auth);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async writeFiles(outputDirectory: string): Promise<void> {
|
|
55
|
-
const env = await this.loadEnvVars();
|
|
56
|
-
|
|
57
|
-
const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
|
|
58
|
-
|
|
59
|
-
const cfWorkerName = this.projectName;
|
|
60
|
-
|
|
61
|
-
const wranglerConfig: Record<string, any> = {
|
|
62
|
-
name: cfWorkerName,
|
|
63
|
-
main: 'index.mjs',
|
|
64
|
-
compatibility_date: '2024-12-02',
|
|
65
|
-
compatibility_flags: ['nodejs_compat'],
|
|
66
|
-
observability: {
|
|
67
|
-
logs: {
|
|
68
|
-
enabled: true,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
vars: envsAsObject,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
if (!this.workerNamespace && this.routes) {
|
|
75
|
-
wranglerConfig.routes = this.routes;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
writeFileSync(join(outputDirectory, 'wrangler.json'), JSON.stringify(wranglerConfig));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private getEntry(): string {
|
|
82
|
-
return `
|
|
83
|
-
export default {
|
|
84
|
-
fetch: async (request, env, context) => {
|
|
85
|
-
Object.keys(env).forEach(key => {
|
|
86
|
-
process.env[key] = env[key]
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
const { mastra } = await import('#mastra')
|
|
90
|
-
const { createHonoServer } = await import('#server')
|
|
91
|
-
const app = await createHonoServer(mastra)
|
|
92
|
-
return app.fetch(request, env, context);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
async prepare(outputDirectory: string): Promise<void> {
|
|
98
|
-
await super.prepare(outputDirectory);
|
|
99
|
-
await this.writeFiles(outputDirectory);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async bundle(entryFile: string, outputDirectory: string): Promise<void> {
|
|
103
|
-
return this._bundle(this.getEntry(), entryFile, outputDirectory);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async deploy(outputDirectory: string): Promise<void> {
|
|
107
|
-
const cmd = this.workerNamespace
|
|
108
|
-
? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}`
|
|
109
|
-
: 'npm exec -- wrangler deploy';
|
|
110
|
-
|
|
111
|
-
const cpLogger = createChildProcessLogger({
|
|
112
|
-
logger: this.logger,
|
|
113
|
-
root: outputDirectory,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
await cpLogger({
|
|
117
|
-
cmd,
|
|
118
|
-
args: [],
|
|
119
|
-
env: {
|
|
120
|
-
CLOUDFLARE_API_TOKEN: this.cloudflare!.apiToken!,
|
|
121
|
-
CLOUDFLARE_ACCOUNT_ID: this.scope,
|
|
122
|
-
...this.env,
|
|
123
|
-
PATH: process.env.PATH!,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async tagWorker({
|
|
129
|
-
workerName,
|
|
130
|
-
namespace,
|
|
131
|
-
tags,
|
|
132
|
-
scope,
|
|
133
|
-
}: {
|
|
134
|
-
scope: string;
|
|
135
|
-
workerName: string;
|
|
136
|
-
namespace: string;
|
|
137
|
-
tags: string[];
|
|
138
|
-
}): Promise<void> {
|
|
139
|
-
if (!this.cloudflare) {
|
|
140
|
-
throw new Error('Cloudflare Deployer not initialized');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
|
|
144
|
-
account_id: scope,
|
|
145
|
-
body: tags,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
// secrets-manager.test.ts
|
|
2
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { CloudflareSecretsManager } from './index.js';
|
|
5
|
-
|
|
6
|
-
const mockFetch = vi.fn();
|
|
7
|
-
global.fetch = mockFetch;
|
|
8
|
-
|
|
9
|
-
describe('CloudflareSecretsManager', () => {
|
|
10
|
-
let secretsManager: CloudflareSecretsManager;
|
|
11
|
-
const mockAccountId = 'test-account-id';
|
|
12
|
-
const mockApiToken = 'test-api-token';
|
|
13
|
-
const mockWorkerId = 'test-worker';
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
secretsManager = new CloudflareSecretsManager({
|
|
17
|
-
accountId: mockAccountId,
|
|
18
|
-
apiToken: mockApiToken,
|
|
19
|
-
});
|
|
20
|
-
vi.resetAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('createSecret', () => {
|
|
24
|
-
it('should successfully create a secret', async () => {
|
|
25
|
-
const mockResponse = {
|
|
26
|
-
success: true,
|
|
27
|
-
result: { name: 'TEST_SECRET_123', type: 'secret_text' },
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
mockFetch.mockReturnValueOnce(
|
|
31
|
-
Promise.resolve({
|
|
32
|
-
json: () => Promise.resolve(mockResponse),
|
|
33
|
-
} as Response),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const result = await secretsManager.createSecret({
|
|
37
|
-
workerId: mockWorkerId,
|
|
38
|
-
secretName: 'TEST_SECRET_123',
|
|
39
|
-
secretValue: 'test-value',
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
43
|
-
`https://api.cloudflare.com/client/v4/accounts/${mockAccountId}/workers/scripts/${mockWorkerId}/secrets`,
|
|
44
|
-
{
|
|
45
|
-
method: 'PUT',
|
|
46
|
-
headers: {
|
|
47
|
-
Authorization: `Bearer ${mockApiToken}`,
|
|
48
|
-
'Content-Type': 'application/json',
|
|
49
|
-
},
|
|
50
|
-
body: JSON.stringify({
|
|
51
|
-
name: 'TEST_SECRET_123',
|
|
52
|
-
text: 'test-value',
|
|
53
|
-
}),
|
|
54
|
-
},
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(result).toEqual(mockResponse.result);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should handle API errors for invalid secret names', async () => {
|
|
61
|
-
const mockError = {
|
|
62
|
-
success: false,
|
|
63
|
-
errors: [{ message: 'Invalid secret name' }],
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
mockFetch.mockReturnValueOnce(
|
|
67
|
-
Promise.resolve({
|
|
68
|
-
json: () => Promise.resolve(mockError),
|
|
69
|
-
} as Response),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
await expect(
|
|
73
|
-
secretsManager.createSecret({
|
|
74
|
-
workerId: mockWorkerId,
|
|
75
|
-
secretName: 'invalid-name!', // Invalid secret name with special character
|
|
76
|
-
secretValue: 'test-value',
|
|
77
|
-
}),
|
|
78
|
-
).rejects.toThrowError('Invalid secret name');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should handle network errors', async () => {
|
|
82
|
-
mockFetch.mockRejectedValueOnce(new Error('Network error'));
|
|
83
|
-
|
|
84
|
-
await expect(
|
|
85
|
-
secretsManager.createSecret({
|
|
86
|
-
workerId: mockWorkerId,
|
|
87
|
-
secretName: 'VALID_SECRET_NAME',
|
|
88
|
-
secretValue: 'test-value',
|
|
89
|
-
}),
|
|
90
|
-
).rejects.toThrowError('Network error');
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('createProjectSecrets', () => {
|
|
95
|
-
it('should create project-specific secrets', async () => {
|
|
96
|
-
const mockResponse = {
|
|
97
|
-
success: true,
|
|
98
|
-
result: { name: 'PROJECT_ABC123', type: 'secret_text' },
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
mockFetch.mockReturnValueOnce(
|
|
102
|
-
Promise.resolve({
|
|
103
|
-
json: () => Promise.resolve(mockResponse),
|
|
104
|
-
} as Response),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
const envVars = {
|
|
108
|
-
API_KEY: 'test_key',
|
|
109
|
-
DATABASE_URL: 'test_url',
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const result = await secretsManager.createProjectSecrets({
|
|
113
|
-
workerId: mockWorkerId,
|
|
114
|
-
customerId: 'ABC123',
|
|
115
|
-
envVars,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
119
|
-
expect.any(String),
|
|
120
|
-
expect.objectContaining({
|
|
121
|
-
method: 'PUT',
|
|
122
|
-
body: JSON.stringify({
|
|
123
|
-
name: 'PROJECT_ABC123',
|
|
124
|
-
text: JSON.stringify(envVars),
|
|
125
|
-
}),
|
|
126
|
-
}),
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
expect(result).toEqual(mockResponse.result);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('deleteSecret', () => {
|
|
134
|
-
it('should successfully delete a secret', async () => {
|
|
135
|
-
const mockResponse = {
|
|
136
|
-
success: true,
|
|
137
|
-
result: { id: 'deleted-secret-id' },
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
mockFetch.mockReturnValueOnce(
|
|
141
|
-
Promise.resolve({
|
|
142
|
-
json: () => Promise.resolve(mockResponse),
|
|
143
|
-
} as Response),
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const result = await secretsManager.deleteSecret({
|
|
147
|
-
workerId: mockWorkerId,
|
|
148
|
-
secretName: 'TEST_SECRET_123',
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
152
|
-
`https://api.cloudflare.com/client/v4/accounts/${mockAccountId}/workers/scripts/${mockWorkerId}/secrets/TEST_SECRET_123`,
|
|
153
|
-
{
|
|
154
|
-
method: 'DELETE',
|
|
155
|
-
headers: {
|
|
156
|
-
Authorization: `Bearer ${mockApiToken}`,
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
expect(result).toEqual(mockResponse.result);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should handle deletion errors', async () => {
|
|
165
|
-
const mockError = {
|
|
166
|
-
success: false,
|
|
167
|
-
errors: [{ message: 'Secret not found' }],
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
mockFetch.mockReturnValueOnce(
|
|
171
|
-
Promise.resolve({
|
|
172
|
-
json: () => Promise.resolve(mockError),
|
|
173
|
-
} as Response),
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
await expect(
|
|
177
|
-
secretsManager.deleteSecret({
|
|
178
|
-
workerId: mockWorkerId,
|
|
179
|
-
secretName: 'NONEXISTENT_SECRET',
|
|
180
|
-
}),
|
|
181
|
-
).rejects.toThrowError('Secret not found');
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe('listSecrets', () => {
|
|
186
|
-
it('should successfully list all secrets', async () => {
|
|
187
|
-
const mockResponse = {
|
|
188
|
-
success: true,
|
|
189
|
-
result: [
|
|
190
|
-
{ name: 'PROJECT_ABC123', type: 'secret_text' },
|
|
191
|
-
{ name: 'PROJECT_DEF456', type: 'secret_text' },
|
|
192
|
-
],
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
mockFetch.mockReturnValueOnce(
|
|
196
|
-
Promise.resolve({
|
|
197
|
-
json: () => Promise.resolve(mockResponse),
|
|
198
|
-
} as Response),
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
const result = await secretsManager.listSecrets(mockWorkerId);
|
|
202
|
-
|
|
203
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
204
|
-
`https://api.cloudflare.com/client/v4/accounts/${mockAccountId}/workers/scripts/${mockWorkerId}/secrets`,
|
|
205
|
-
{
|
|
206
|
-
headers: {
|
|
207
|
-
Authorization: `Bearer ${mockApiToken}`,
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
expect(result).toEqual(mockResponse.result);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('should handle listing errors', async () => {
|
|
216
|
-
const mockError = {
|
|
217
|
-
success: false,
|
|
218
|
-
errors: [{ message: 'Invalid worker ID' }],
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
mockFetch.mockReturnValueOnce(
|
|
222
|
-
Promise.resolve({
|
|
223
|
-
json: () => Promise.resolve(mockError),
|
|
224
|
-
} as Response),
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
await expect(secretsManager.listSecrets('invalid-worker')).rejects.toThrowError('Invalid worker ID');
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
});
|
package/tsconfig.json
DELETED