poke-gate 0.0.6 → 0.0.7
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/bin/poke-gate.js +22 -7
- package/clients/Poke macOS Gate/Poke macOS Gate/GateService.swift +78 -3
- package/clients/Poke macOS Gate/Poke macOS Gate/SettingsView.swift +67 -13
- package/clients/Poke macOS Gate/Poke macOS Gate.xcodeproj/project.xcworkspace/xcuserdata/fka.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/package.json +1 -1
- package/src/app.js +5 -0
package/bin/poke-gate.js
CHANGED
|
@@ -21,10 +21,20 @@ function saveConfig(config) {
|
|
|
21
21
|
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function loadPokeCredentials() {
|
|
25
|
+
try {
|
|
26
|
+
const creds = JSON.parse(readFileSync(join(CONFIG_DIR, "poke", "credentials.json"), "utf-8"));
|
|
27
|
+
if (creds.token) return creds.token;
|
|
28
|
+
} catch {}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
function resolveToken() {
|
|
25
33
|
if (process.env.POKE_API_KEY) return process.env.POKE_API_KEY;
|
|
26
34
|
const config = loadConfig();
|
|
27
35
|
if (config.apiKey) return config.apiKey;
|
|
36
|
+
const pokeCreds = loadPokeCredentials();
|
|
37
|
+
if (pokeCreds) return pokeCreds;
|
|
28
38
|
return null;
|
|
29
39
|
}
|
|
30
40
|
|
|
@@ -47,19 +57,24 @@ async function onboarding() {
|
|
|
47
57
|
console.log();
|
|
48
58
|
console.log(" ⚠ This grants full shell access. Only run on trusted networks.");
|
|
49
59
|
console.log();
|
|
50
|
-
console.log(" To get started,
|
|
60
|
+
console.log(" To get started, either:");
|
|
51
61
|
console.log();
|
|
52
|
-
console.log(" 1
|
|
53
|
-
console.log(" 2
|
|
54
|
-
console.log(" 3. Paste it below");
|
|
62
|
+
console.log(" Option 1: Run 'npx poke login' (recommended)");
|
|
63
|
+
console.log(" Option 2: Paste an API key from https://poke.com/kitchen/api-keys");
|
|
55
64
|
console.log();
|
|
56
65
|
|
|
57
|
-
const key = await ask(" API key: ");
|
|
66
|
+
const key = await ask(" API key (or press Enter if you ran poke login): ");
|
|
58
67
|
|
|
59
68
|
if (!key) {
|
|
69
|
+
const pokeCreds = loadPokeCredentials();
|
|
70
|
+
if (pokeCreds) {
|
|
71
|
+
console.log();
|
|
72
|
+
console.log(" Found poke login credentials! Starting...");
|
|
73
|
+
console.log();
|
|
74
|
+
return pokeCreds;
|
|
75
|
+
}
|
|
60
76
|
console.log();
|
|
61
|
-
console.log(" No
|
|
62
|
-
console.log(" export POKE_API_KEY=your_key_here");
|
|
77
|
+
console.log(" No credentials found. Run: npx poke login");
|
|
63
78
|
console.log();
|
|
64
79
|
process.exit(1);
|
|
65
80
|
}
|
|
@@ -27,8 +27,7 @@ class GateService: ObservableObject {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
var hasAPIKey: Bool {
|
|
30
|
-
|
|
31
|
-
return key != nil && !key!.isEmpty
|
|
30
|
+
resolveToken() != nil
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
func autoStartIfNeeded() {
|
|
@@ -111,7 +110,7 @@ class GateService: ObservableObject {
|
|
|
111
110
|
proc.arguments = ["-c", "npx -y poke-gate --verbose"]
|
|
112
111
|
proc.environment = ProcessInfo.processInfo.environment.merging(
|
|
113
112
|
[
|
|
114
|
-
"POKE_API_KEY":
|
|
113
|
+
"POKE_API_KEY": resolveToken() ?? "",
|
|
115
114
|
"PATH": fullPath,
|
|
116
115
|
],
|
|
117
116
|
uniquingKeysWith: { _, new in new }
|
|
@@ -226,4 +225,80 @@ class GateService: ObservableObject {
|
|
|
226
225
|
}
|
|
227
226
|
objectWillChange.send()
|
|
228
227
|
}
|
|
228
|
+
|
|
229
|
+
// MARK: - Poke Login Credentials
|
|
230
|
+
|
|
231
|
+
private var pokeCredentialsURL: URL {
|
|
232
|
+
let configDir: URL
|
|
233
|
+
if let xdg = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"] {
|
|
234
|
+
configDir = URL(fileURLWithPath: xdg)
|
|
235
|
+
} else {
|
|
236
|
+
configDir = FileManager.default.homeDirectoryForCurrentUser
|
|
237
|
+
.appendingPathComponent(".config")
|
|
238
|
+
}
|
|
239
|
+
return configDir
|
|
240
|
+
.appendingPathComponent("poke")
|
|
241
|
+
.appendingPathComponent("credentials.json")
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
var hasPokeLoginCredentials: Bool {
|
|
245
|
+
loadPokeLoginToken() != nil
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
func loadPokeLoginToken() -> String? {
|
|
249
|
+
guard let data = try? Data(contentsOf: pokeCredentialsURL),
|
|
250
|
+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
|
251
|
+
let token = json["token"] as? String else {
|
|
252
|
+
return nil
|
|
253
|
+
}
|
|
254
|
+
return token
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var authSource: AuthSource {
|
|
258
|
+
get {
|
|
259
|
+
let config = (try? Data(contentsOf: configURL))
|
|
260
|
+
.flatMap { try? JSONSerialization.jsonObject(with: $0) as? [String: Any] }
|
|
261
|
+
if let source = config?["authSource"] as? String, source == "pokeLogin" {
|
|
262
|
+
return .pokeLogin
|
|
263
|
+
}
|
|
264
|
+
if loadAPIKey() != nil {
|
|
265
|
+
return .apiKey
|
|
266
|
+
}
|
|
267
|
+
if hasPokeLoginCredentials {
|
|
268
|
+
return .pokeLogin
|
|
269
|
+
}
|
|
270
|
+
return .none
|
|
271
|
+
}
|
|
272
|
+
set {
|
|
273
|
+
let dir = configURL.deletingLastPathComponent()
|
|
274
|
+
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
275
|
+
var json: [String: Any] = [:]
|
|
276
|
+
if let data = try? Data(contentsOf: configURL),
|
|
277
|
+
let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
|
|
278
|
+
json = existing
|
|
279
|
+
}
|
|
280
|
+
json["authSource"] = newValue == .pokeLogin ? "pokeLogin" : "apiKey"
|
|
281
|
+
if let data = try? JSONSerialization.data(withJSONObject: json, options: [.prettyPrinted]) {
|
|
282
|
+
try? data.write(to: configURL)
|
|
283
|
+
}
|
|
284
|
+
objectWillChange.send()
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
func resolveToken() -> String? {
|
|
289
|
+
switch authSource {
|
|
290
|
+
case .pokeLogin:
|
|
291
|
+
return loadPokeLoginToken()
|
|
292
|
+
case .apiKey:
|
|
293
|
+
return loadAPIKey()
|
|
294
|
+
case .none:
|
|
295
|
+
return loadAPIKey() ?? loadPokeLoginToken()
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
enum AuthSource {
|
|
300
|
+
case pokeLogin
|
|
301
|
+
case apiKey
|
|
302
|
+
case none
|
|
303
|
+
}
|
|
229
304
|
}
|
|
@@ -3,6 +3,7 @@ import SwiftUI
|
|
|
3
3
|
struct SettingsView: View {
|
|
4
4
|
@ObservedObject var service: GateService
|
|
5
5
|
@State private var apiKeyInput: String = ""
|
|
6
|
+
@State private var usePokeLogin: Bool = true
|
|
6
7
|
@Environment(\.dismiss) private var dismiss
|
|
7
8
|
|
|
8
9
|
var body: some View {
|
|
@@ -10,18 +11,64 @@ struct SettingsView: View {
|
|
|
10
11
|
Text("Poke Gate Settings")
|
|
11
12
|
.font(.headline)
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
Text("
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Picker("Authentication", selection: $usePokeLogin) {
|
|
15
|
+
Text("Use poke login").tag(true)
|
|
16
|
+
Text("Use API key").tag(false)
|
|
17
|
+
}
|
|
18
|
+
.pickerStyle(.segmented)
|
|
19
|
+
|
|
20
|
+
if usePokeLogin {
|
|
21
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
22
|
+
if service.hasPokeLoginCredentials {
|
|
23
|
+
Label("poke login credentials found", systemImage: "checkmark.circle.fill")
|
|
24
|
+
.foregroundStyle(.green)
|
|
25
|
+
.font(.subheadline)
|
|
26
|
+
} else {
|
|
27
|
+
Label("No credentials found", systemImage: "xmark.circle")
|
|
28
|
+
.foregroundStyle(.red)
|
|
29
|
+
.font(.subheadline)
|
|
30
|
+
|
|
31
|
+
Text("Run this in your terminal:")
|
|
32
|
+
.font(.caption)
|
|
33
|
+
.foregroundStyle(.secondary)
|
|
34
|
+
|
|
35
|
+
HStack {
|
|
36
|
+
Text("npx poke login")
|
|
37
|
+
.font(.system(.caption, design: .monospaced))
|
|
38
|
+
.padding(.horizontal, 8)
|
|
39
|
+
.padding(.vertical, 4)
|
|
40
|
+
.background(.quaternary)
|
|
41
|
+
.cornerRadius(4)
|
|
17
42
|
|
|
18
|
-
|
|
19
|
-
|
|
43
|
+
Button {
|
|
44
|
+
NSPasteboard.general.clearContents()
|
|
45
|
+
NSPasteboard.general.setString("npx poke login", forType: .string)
|
|
46
|
+
} label: {
|
|
47
|
+
Image(systemName: "doc.on.doc")
|
|
48
|
+
}
|
|
49
|
+
.buttonStyle(.plain)
|
|
50
|
+
}
|
|
20
51
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
52
|
+
Text("Then come back here and click Save.")
|
|
53
|
+
.font(.caption)
|
|
54
|
+
.foregroundStyle(.secondary)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
58
|
+
} else {
|
|
59
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
60
|
+
Text("API Key")
|
|
61
|
+
.font(.subheadline)
|
|
62
|
+
.foregroundStyle(.secondary)
|
|
63
|
+
|
|
64
|
+
SecureField("Paste your API key", text: $apiKeyInput)
|
|
65
|
+
.textFieldStyle(.roundedBorder)
|
|
66
|
+
|
|
67
|
+
Link("Get your key at poke.com/kitchen/api-keys",
|
|
68
|
+
destination: URL(string: "https://poke.com/kitchen/api-keys")!)
|
|
69
|
+
.font(.caption)
|
|
70
|
+
.foregroundStyle(.blue)
|
|
71
|
+
}
|
|
25
72
|
}
|
|
26
73
|
|
|
27
74
|
HStack {
|
|
@@ -33,17 +80,24 @@ struct SettingsView: View {
|
|
|
33
80
|
Spacer()
|
|
34
81
|
|
|
35
82
|
Button("Save") {
|
|
36
|
-
|
|
83
|
+
if usePokeLogin {
|
|
84
|
+
service.authSource = .pokeLogin
|
|
85
|
+
} else {
|
|
86
|
+
service.apiKey = apiKeyInput
|
|
87
|
+
service.authSource = .apiKey
|
|
88
|
+
}
|
|
37
89
|
dismiss()
|
|
38
90
|
service.restart()
|
|
39
91
|
}
|
|
40
92
|
.keyboardShortcut(.defaultAction)
|
|
41
|
-
.disabled(apiKeyInput.isEmpty)
|
|
93
|
+
.disabled(!usePokeLogin && apiKeyInput.isEmpty)
|
|
94
|
+
.disabled(usePokeLogin && !service.hasPokeLoginCredentials)
|
|
42
95
|
}
|
|
43
96
|
}
|
|
44
97
|
.padding(20)
|
|
45
|
-
.frame(width:
|
|
98
|
+
.frame(width: 380)
|
|
46
99
|
.onAppear {
|
|
100
|
+
usePokeLogin = service.authSource != .apiKey
|
|
47
101
|
apiKeyInput = service.apiKey
|
|
48
102
|
}
|
|
49
103
|
}
|
|
Binary file
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -18,6 +18,11 @@ function resolveToken() {
|
|
|
18
18
|
if (cfg.apiKey) return cfg.apiKey;
|
|
19
19
|
} catch {}
|
|
20
20
|
|
|
21
|
+
try {
|
|
22
|
+
const creds = JSON.parse(readFileSync(join(configDir, "poke", "credentials.json"), "utf-8"));
|
|
23
|
+
if (creds.token) return creds.token;
|
|
24
|
+
} catch {}
|
|
25
|
+
|
|
21
26
|
return null;
|
|
22
27
|
}
|
|
23
28
|
|