appwrite-utils-cli 1.7.2 → 1.7.3
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/utils/ClientFactory.js +62 -19
- package/package.json +1 -1
- package/src/utils/ClientFactory.ts +70 -21
@@ -60,32 +60,75 @@ export class ClientFactory {
|
|
60
60
|
const client = new Client()
|
61
61
|
.setEndpoint(config.appwriteEndpoint)
|
62
62
|
.setProject(config.appwriteProject);
|
63
|
-
// Apply authentication
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
// Apply authentication based on authMethod preference
|
64
|
+
const authMethod = config.authMethod || "auto";
|
65
|
+
logger.debug("Applying authentication", {
|
66
|
+
prefix: "ClientFactory",
|
67
|
+
authMethod,
|
68
|
+
hasApiKey: !!config.appwriteKey,
|
69
|
+
hasSession: !!config.sessionCookie,
|
70
|
+
});
|
71
|
+
if (authMethod === "apikey") {
|
72
|
+
// Explicit API key preference - use only API key
|
73
|
+
if (!config.appwriteKey || config.appwriteKey.trim().length === 0) {
|
74
|
+
const error = new Error("authMethod set to 'apikey' but no API key provided.\n\n" +
|
75
|
+
"Either:\n" +
|
76
|
+
" - Set appwriteKey in your config file\n" +
|
77
|
+
" - Provide --apiKey flag\n" +
|
78
|
+
" - Set APPWRITE_API_KEY environment variable");
|
79
|
+
logger.error("Failed to create client - API key required", { prefix: "ClientFactory" });
|
80
|
+
throw error;
|
81
|
+
}
|
82
|
+
client.setKey(config.appwriteKey);
|
83
|
+
logger.debug("Applied API key authentication (explicit preference)", {
|
68
84
|
prefix: "ClientFactory",
|
69
|
-
email: config.sessionMetadata?.email,
|
70
85
|
});
|
71
86
|
}
|
72
|
-
else if (
|
73
|
-
//
|
74
|
-
|
75
|
-
|
87
|
+
else if (authMethod === "session") {
|
88
|
+
// Explicit session preference - use only session
|
89
|
+
if (!config.sessionCookie) {
|
90
|
+
const error = new Error("authMethod set to 'session' but no session cookie available.\n\n" +
|
91
|
+
"Either:\n" +
|
92
|
+
" - Run 'appwrite login' to create a session\n" +
|
93
|
+
" - Change authMethod to 'apikey' or 'auto'\n" +
|
94
|
+
" - Provide --sessionCookie flag");
|
95
|
+
logger.error("Failed to create client - session required", { prefix: "ClientFactory" });
|
96
|
+
throw error;
|
97
|
+
}
|
98
|
+
client.setSession(config.sessionCookie);
|
99
|
+
logger.debug("Applied session authentication (explicit preference)", {
|
76
100
|
prefix: "ClientFactory",
|
101
|
+
email: config.sessionMetadata?.email,
|
77
102
|
});
|
78
103
|
}
|
79
104
|
else {
|
80
|
-
//
|
81
|
-
|
82
|
-
|
83
|
-
"
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
105
|
+
// Auto mode: Prefer API key if present, fallback to session
|
106
|
+
if (config.appwriteKey && config.appwriteKey.trim().length > 0) {
|
107
|
+
client.setKey(config.appwriteKey);
|
108
|
+
logger.debug("Applied API key authentication (auto mode - preferred)", {
|
109
|
+
prefix: "ClientFactory",
|
110
|
+
});
|
111
|
+
}
|
112
|
+
else if (config.sessionCookie) {
|
113
|
+
client.setSession(config.sessionCookie);
|
114
|
+
logger.debug("Applied session authentication (auto mode - fallback)", {
|
115
|
+
prefix: "ClientFactory",
|
116
|
+
email: config.sessionMetadata?.email,
|
117
|
+
});
|
118
|
+
}
|
119
|
+
else {
|
120
|
+
// No authentication available
|
121
|
+
const error = new Error("No authentication method available in configuration.\n\n" +
|
122
|
+
"Expected either:\n" +
|
123
|
+
" - config.appwriteKey (from config file, CLI flags, or environment)\n" +
|
124
|
+
" - config.sessionCookie (from session authentication)\n\n" +
|
125
|
+
"Suggestion:\n" +
|
126
|
+
" - Add appwriteKey to your config file, OR\n" +
|
127
|
+
" - Run 'appwrite login' to create a session, OR\n" +
|
128
|
+
" - Provide --apiKey flag");
|
129
|
+
logger.error("Failed to create client - no authentication", { prefix: "ClientFactory" });
|
130
|
+
throw error;
|
131
|
+
}
|
89
132
|
}
|
90
133
|
// Create adapter with version detection
|
91
134
|
// AdapterFactory uses internal caching, so repeated calls are fast
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "appwrite-utils-cli",
|
3
3
|
"description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
|
4
|
-
"version": "1.7.
|
4
|
+
"version": "1.7.3",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
@@ -67,32 +67,81 @@ export class ClientFactory {
|
|
67
67
|
.setEndpoint(config.appwriteEndpoint)
|
68
68
|
.setProject(config.appwriteProject);
|
69
69
|
|
70
|
-
// Apply authentication
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
// Apply authentication based on authMethod preference
|
71
|
+
const authMethod = config.authMethod || "auto";
|
72
|
+
|
73
|
+
logger.debug("Applying authentication", {
|
74
|
+
prefix: "ClientFactory",
|
75
|
+
authMethod,
|
76
|
+
hasApiKey: !!config.appwriteKey,
|
77
|
+
hasSession: !!config.sessionCookie,
|
78
|
+
});
|
79
|
+
|
80
|
+
if (authMethod === "apikey") {
|
81
|
+
// Explicit API key preference - use only API key
|
82
|
+
if (!config.appwriteKey || config.appwriteKey.trim().length === 0) {
|
83
|
+
const error = new Error(
|
84
|
+
"authMethod set to 'apikey' but no API key provided.\n\n" +
|
85
|
+
"Either:\n" +
|
86
|
+
" - Set appwriteKey in your config file\n" +
|
87
|
+
" - Provide --apiKey flag\n" +
|
88
|
+
" - Set APPWRITE_API_KEY environment variable"
|
89
|
+
);
|
90
|
+
logger.error("Failed to create client - API key required", { prefix: "ClientFactory" });
|
91
|
+
throw error;
|
92
|
+
}
|
93
|
+
client.setKey(config.appwriteKey);
|
94
|
+
logger.debug("Applied API key authentication (explicit preference)", {
|
75
95
|
prefix: "ClientFactory",
|
76
|
-
email: config.sessionMetadata?.email,
|
77
96
|
});
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
97
|
+
|
98
|
+
} else if (authMethod === "session") {
|
99
|
+
// Explicit session preference - use only session
|
100
|
+
if (!config.sessionCookie) {
|
101
|
+
const error = new Error(
|
102
|
+
"authMethod set to 'session' but no session cookie available.\n\n" +
|
103
|
+
"Either:\n" +
|
104
|
+
" - Run 'appwrite login' to create a session\n" +
|
105
|
+
" - Change authMethod to 'apikey' or 'auto'\n" +
|
106
|
+
" - Provide --sessionCookie flag"
|
107
|
+
);
|
108
|
+
logger.error("Failed to create client - session required", { prefix: "ClientFactory" });
|
109
|
+
throw error;
|
110
|
+
}
|
111
|
+
client.setSession(config.sessionCookie);
|
112
|
+
logger.debug("Applied session authentication (explicit preference)", {
|
82
113
|
prefix: "ClientFactory",
|
114
|
+
email: config.sessionMetadata?.email,
|
83
115
|
});
|
116
|
+
|
84
117
|
} else {
|
85
|
-
//
|
86
|
-
|
87
|
-
|
88
|
-
"
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
118
|
+
// Auto mode: Prefer API key if present, fallback to session
|
119
|
+
if (config.appwriteKey && config.appwriteKey.trim().length > 0) {
|
120
|
+
client.setKey(config.appwriteKey);
|
121
|
+
logger.debug("Applied API key authentication (auto mode - preferred)", {
|
122
|
+
prefix: "ClientFactory",
|
123
|
+
});
|
124
|
+
} else if (config.sessionCookie) {
|
125
|
+
client.setSession(config.sessionCookie);
|
126
|
+
logger.debug("Applied session authentication (auto mode - fallback)", {
|
127
|
+
prefix: "ClientFactory",
|
128
|
+
email: config.sessionMetadata?.email,
|
129
|
+
});
|
130
|
+
} else {
|
131
|
+
// No authentication available
|
132
|
+
const error = new Error(
|
133
|
+
"No authentication method available in configuration.\n\n" +
|
134
|
+
"Expected either:\n" +
|
135
|
+
" - config.appwriteKey (from config file, CLI flags, or environment)\n" +
|
136
|
+
" - config.sessionCookie (from session authentication)\n\n" +
|
137
|
+
"Suggestion:\n" +
|
138
|
+
" - Add appwriteKey to your config file, OR\n" +
|
139
|
+
" - Run 'appwrite login' to create a session, OR\n" +
|
140
|
+
" - Provide --apiKey flag"
|
141
|
+
);
|
142
|
+
logger.error("Failed to create client - no authentication", { prefix: "ClientFactory" });
|
143
|
+
throw error;
|
144
|
+
}
|
96
145
|
}
|
97
146
|
|
98
147
|
// Create adapter with version detection
|