@knocklabs/cli 0.1.23 → 0.2.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/README.md +128 -102
- package/bin/dev.js +4 -4
- package/dist/commands/knock.js +3 -0
- package/dist/commands/login.js +50 -0
- package/dist/commands/logout.js +48 -0
- package/dist/commands/whoami.js +6 -2
- package/dist/lib/api-v1.js +13 -4
- package/dist/lib/auth.js +256 -0
- package/dist/lib/base-command.js +85 -12
- package/dist/lib/helpers/browser.js +25 -0
- package/dist/lib/types.js +4 -0
- package/dist/lib/urls.js +32 -0
- package/dist/lib/user-config.js +69 -31
- package/oclif.manifest.json +220 -146
- package/package.json +7 -6
package/dist/lib/user-config.js
CHANGED
|
@@ -4,16 +4,29 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "UserConfigStore", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function() {
|
|
10
|
-
return
|
|
10
|
+
return UserConfigStore;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
|
|
14
14
|
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
15
|
-
const
|
|
15
|
+
const _zod = require("zod");
|
|
16
16
|
const _const = require("./helpers/const");
|
|
17
|
+
function _define_property(obj, key, value) {
|
|
18
|
+
if (key in obj) {
|
|
19
|
+
Object.defineProperty(obj, key, {
|
|
20
|
+
value: value,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
obj[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
17
30
|
function _getRequireWildcardCache(nodeInterop) {
|
|
18
31
|
if (typeof WeakMap !== "function") return null;
|
|
19
32
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -55,33 +68,58 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
55
68
|
}
|
|
56
69
|
return newObj;
|
|
57
70
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
// When a user has authenticated via OAuth, we store the session in the user config.
|
|
72
|
+
const userSessionSchema = _zod.z.object({
|
|
73
|
+
accessToken: _zod.z.string(),
|
|
74
|
+
clientId: _zod.z.string(),
|
|
75
|
+
refreshToken: _zod.z.string()
|
|
76
|
+
});
|
|
77
|
+
const userConfigSchema = _zod.z.object({
|
|
78
|
+
serviceToken: _zod.z.string().optional(),
|
|
79
|
+
apiOrigin: _zod.z.string().optional(),
|
|
80
|
+
dashboardOrigin: _zod.z.string().optional(),
|
|
81
|
+
authOrigin: _zod.z.string().optional(),
|
|
82
|
+
userSession: userSessionSchema.optional()
|
|
61
83
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!USER_CONFIG) {
|
|
80
|
-
throw new Error("User config must be loaded first.");
|
|
84
|
+
class UserConfigStore {
|
|
85
|
+
async load() {
|
|
86
|
+
const readConfig = await this.maybeReadJsonConfig();
|
|
87
|
+
const validConfig = userConfigSchema.parse(readConfig || {});
|
|
88
|
+
this.userConfig = validConfig || {};
|
|
89
|
+
return this.userConfig;
|
|
90
|
+
}
|
|
91
|
+
get() {
|
|
92
|
+
return this.userConfig;
|
|
93
|
+
}
|
|
94
|
+
async set(updatedConfig) {
|
|
95
|
+
this.userConfig = {
|
|
96
|
+
...this.userConfig,
|
|
97
|
+
...updatedConfig
|
|
98
|
+
};
|
|
99
|
+
await this.maybeWriteJsonConfig();
|
|
100
|
+
return this.userConfig;
|
|
81
101
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
configPath() {
|
|
103
|
+
return _nodepath.resolve(this.configDir, "config.json");
|
|
104
|
+
}
|
|
105
|
+
async maybeReadJsonConfig() {
|
|
106
|
+
if (_const.isTestEnv) return {};
|
|
107
|
+
const path = this.configPath();
|
|
108
|
+
const exists = await _fsextra.pathExists(path);
|
|
109
|
+
if (!exists) return {};
|
|
110
|
+
return _fsextra.readJSON(path);
|
|
111
|
+
}
|
|
112
|
+
async maybeWriteJsonConfig() {
|
|
113
|
+
if (_const.isTestEnv) return;
|
|
114
|
+
const path = this.configPath();
|
|
115
|
+
await _fsextra.outputJson(path, this.userConfig, {
|
|
116
|
+
spaces: 2
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
constructor(configDir){
|
|
120
|
+
_define_property(this, "configDir", void 0);
|
|
121
|
+
_define_property(this, "userConfig", void 0);
|
|
122
|
+
this.configDir = configDir;
|
|
123
|
+
this.userConfig = {};
|
|
124
|
+
}
|
|
125
|
+
}
|