@project-ajax/cli 0.0.14 → 0.0.16

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/dist/config.d.ts CHANGED
@@ -1,63 +1,165 @@
1
+ import z from "zod";
1
2
  import type { GlobalFlags } from "./flags.js";
2
- export declare const Environments: readonly ["local", "staging", "dev", "prod"];
3
- export type Environment = (typeof Environments)[number];
4
- export interface ConfigMap {
5
- environment: Environment;
6
- baseUrl: string;
7
- token: string | null;
8
- workerId: string | null;
9
- }
10
- export declare function parseEnvironment(name: string): Environment;
11
- export declare class TokenNotSetError extends Error {
12
- constructor(message?: string);
3
+ import { type TokenInfo } from "./token.js";
4
+ export declare const Environment: z.ZodLiteral<"local" | "dev" | "stg" | "prod">;
5
+ export type Environment = z.infer<typeof Environment>;
6
+ declare const SpaceCache: z.ZodObject<{
7
+ version: z.ZodLiteral<"1">;
8
+ spaces: z.ZodRecord<z.ZodString, z.ZodObject<{
9
+ id: z.ZodString;
10
+ name: z.ZodString;
11
+ cellId: z.ZodString;
12
+ }, z.z.core.$strip>>;
13
+ }, z.z.core.$strip>;
14
+ export type SpaceCache = z.infer<typeof SpaceCache>;
15
+ declare const LocalConfig: z.ZodObject<{
16
+ version: z.ZodLiteral<"1">;
17
+ environment: z.ZodLiteral<"local" | "dev" | "stg" | "prod">;
18
+ baseURL: z.ZodOptional<z.ZodString>;
19
+ spaceId: z.ZodNullable<z.ZodString>;
20
+ workerId: z.ZodNullable<z.ZodString>;
21
+ }, z.z.core.$strip>;
22
+ export type LocalConfig = z.infer<typeof LocalConfig>;
23
+ export declare class NoSuitableConfigFileError extends Error {
24
+ constructor();
13
25
  }
14
26
  /**
15
- * Manages configuration for the CLI.
16
- *
17
- * Environment variables take precedence over the config file.
27
+ * Manages configuration for the command line interface.
18
28
  *
19
- * | Environment Variable | Config File | Description |
20
- * |----------------------|-------------|-------------|
21
- * | WORKERS_TOKEN | token | The token to use for authentication |
22
- * | WORKERS_ENVIRONMENT | environment | The environment to use |
23
- * | WORKERS_WORKER_ID | workerId | The worker ID to use |
24
- * | WORKERS_BASE_URL | baseUrl | The base URL to use |
29
+ * Order of precedence: Command-line flags, environment variables, local config
30
+ * files, where appropriate.
25
31
  */
26
32
  export declare class Config {
27
33
  #private;
28
34
  constructor(opts: {
29
- configMap: ConfigMap;
30
- configFilePath: string;
35
+ spaceCachePath: string;
36
+ spaceCache: SpaceCache;
37
+ localConfigPath: string;
38
+ localConfig: LocalConfig;
39
+ environment: Environment;
40
+ baseURL: string;
41
+ spaceId: string | null;
42
+ workerId: string | null;
43
+ token: string | null;
31
44
  });
32
- get baseUrl(): string;
33
- get token(): string | null;
34
- get environment(): "local" | "staging" | "dev" | "prod";
45
+ get environment(): Environment;
46
+ get baseURL(): string;
47
+ get spaceId(): string | null;
35
48
  get workerId(): string | null;
36
- get tokenInfo(): {
49
+ /**
50
+ * Get the list of cached spaces.
51
+ *
52
+ * @returns An array of cached spaces with id, name, and cellId.
53
+ */
54
+ getCachedSpaces(): Array<{
55
+ id: string;
56
+ name: string;
57
+ cellId: string;
58
+ }>;
59
+ /**
60
+ * Get the token and token information from the keychain.
61
+ *
62
+ * @returns The token and token information, or null if no token is found.
63
+ */
64
+ getToken(): Promise<[token: string, tokenInfo: TokenInfo] | null>;
65
+ /**
66
+ * Get the token and token information from the keychain.
67
+ *
68
+ * Throws an error if no token is found.
69
+ *
70
+ * @returns The token and token information.
71
+ */
72
+ mustGetToken(): Promise<[token: string, tokenInfo: TokenInfo]>;
73
+ /**
74
+ * Log in by updating the local configuration and the space cache, and
75
+ * storing the token in the keychain.
76
+ *
77
+ * @param args The arguments to login.
78
+ * @param args.environment The environment to login to.
79
+ * @param args.token The token to login with.
80
+ * @param args.spaceId The space ID to login to.
81
+ * @param args.spaceName The space name to login to.
82
+ * @param args.cellId The cell ID to login to.
83
+ */
84
+ login(args: {
85
+ environment: Environment;
37
86
  token: string;
38
87
  spaceId: string;
88
+ spaceName: string;
39
89
  cellId: string;
40
- };
90
+ }): Promise<void>;
41
91
  /**
42
- * Update the config with a partial config map.
92
+ * Set the worker ID.
43
93
  *
44
- * This will write only the updated keys in the config file on disk. Not all
45
- * keys are written, since some current keys in the Config object may have
46
- * come from e.g. environment variables, rather than the original config
47
- * file.
94
+ * @param workerId The worker ID to set.
95
+ */
96
+ setWorker(workerId: string): void;
97
+ /**
98
+ * Switch to an existing cached space.
48
99
  *
49
- * @param config The config update.
100
+ * This updates the local configuration to use the specified space.
101
+ * The token for this space should already exist in the keychain.
102
+ *
103
+ * @param spaceId The space ID to switch to.
104
+ * @throws Error if the space is not in the cache.
105
+ */
106
+ switchToSpace(spaceId: string): void;
107
+ /**
108
+ * Resolve the space cache path.
109
+ *
110
+ * @param opts Options for resolving the space cache path.
111
+ * @param opts.filePath The path to the space cache file.
112
+ * @param opts.env The environment variables.
113
+ * @returns The path to the space cache file.
114
+ */
115
+ static resolveSpaceCachePath(opts: {
116
+ filePath?: string;
117
+ env: NodeJS.ProcessEnv;
118
+ }): string;
119
+ /**
120
+ * Resolve the local config path.
121
+ *
122
+ * @param opts Options for resolving the local config path.
123
+ * @param opts.filePath The path to the local config file.
124
+ * @returns
125
+ */
126
+ static resolveLocalConfigPath(opts?: {
127
+ filePath?: string;
128
+ }): string;
129
+ /**
130
+ * Load config from space cache and local config files, then resolve them to
131
+ * a final config for this execution of the command line interface.
132
+ *
133
+ * If the local config is v0, it will be upgraded to v1.
134
+ *
135
+ * Overrides:
136
+ *
137
+ * - Environment: WORKERS_ENVIRONMENT or --env flag
138
+ * - Token: WORKERS_TOKEN or --token flag
139
+ * - Base URL: WORKERS_BASE_URL or --base-url flag
140
+ *
141
+ * @param opts The options to load the config from.
142
+ * @param opts.spaceCachePath The path to the space cache file.
143
+ * @param opts.localPath The path to the local config file.
144
+ * @param opts.env The process environment.
145
+ * @param opts.processEnv The process environment.
146
+ * @param opts.flags The global flags.
147
+ * @returns The resolved config.
50
148
  */
51
- update(config: Partial<ConfigMap>): Promise<void>;
52
149
  static load(opts: {
53
- configFilePath: string;
54
- processEnv: NodeJS.ProcessEnv;
150
+ spaceCachePath: string;
151
+ localPath: string;
152
+ env: NodeJS.ProcessEnv;
55
153
  flags: GlobalFlags;
56
- }): Promise<Config>;
154
+ }): Config;
155
+ /**
156
+ * The empty local config.
157
+ */
158
+ static get emptyLocalConfig(): LocalConfig;
159
+ /**
160
+ * The empty space cache.
161
+ */
162
+ static get emptySpaceCache(): SpaceCache;
57
163
  }
58
- export declare function extractPayloadFromToken(token: string): {
59
- spaceId: string;
60
- userId: string;
61
- cellId: string;
62
- };
164
+ export {};
63
165
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,YAAY,8CAA+C,CAAC;AACzE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,MAAM,WAAW,SAAS;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAM1D;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAEzC,OAAO,GAAE,MAA6D;CAKvE;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;;gBAIN,IAAI,EAAE;QACjB,SAAS,EAAE,SAAS,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;KACvB;IAOD,IAAI,OAAO,WAEV;IAED,IAAI,KAAK,kBAER;IAED,IAAI,WAAW,yCAEd;IAED,IAAI,QAAQ,kBAEX;IAED,IAAI,SAAS,IAAI;QAAE,KAAK,EAAE,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