@vicinae/api 0.3.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.
Files changed (113) hide show
  1. package/README.md +37 -0
  2. package/bin/run.js +9 -0
  3. package/dist/api/ai.d.ts +110 -0
  4. package/dist/api/ai.js +120 -0
  5. package/dist/api/alert.d.ts +22 -0
  6. package/dist/api/alert.js +61 -0
  7. package/dist/api/bus.d.ts +95 -0
  8. package/dist/api/bus.js +211 -0
  9. package/dist/api/cache.d.ts +117 -0
  10. package/dist/api/cache.js +52 -0
  11. package/dist/api/clipboard.d.ts +34 -0
  12. package/dist/api/clipboard.js +52 -0
  13. package/dist/api/color.d.ts +24 -0
  14. package/dist/api/color.js +24 -0
  15. package/dist/api/components/action-pannel.d.ts +23 -0
  16. package/dist/api/components/action-pannel.js +30 -0
  17. package/dist/api/components/actions.d.ts +52 -0
  18. package/dist/api/components/actions.js +81 -0
  19. package/dist/api/components/detail.d.ts +21 -0
  20. package/dist/api/components/detail.js +12 -0
  21. package/dist/api/components/dropdown.d.ts +36 -0
  22. package/dist/api/components/dropdown.js +21 -0
  23. package/dist/api/components/empty-view.d.ts +9 -0
  24. package/dist/api/components/empty-view.js +12 -0
  25. package/dist/api/components/form.d.ts +81 -0
  26. package/dist/api/components/form.js +53 -0
  27. package/dist/api/components/grid.d.ts +117 -0
  28. package/dist/api/components/grid.js +80 -0
  29. package/dist/api/components/index.d.ts +7 -0
  30. package/dist/api/components/index.js +23 -0
  31. package/dist/api/components/list.d.ts +109 -0
  32. package/dist/api/components/list.js +53 -0
  33. package/dist/api/components/menu-bar.d.ts +26 -0
  34. package/dist/api/components/menu-bar.js +25 -0
  35. package/dist/api/components/metadata.d.ts +23 -0
  36. package/dist/api/components/metadata.js +27 -0
  37. package/dist/api/components/tag.d.ts +16 -0
  38. package/dist/api/components/tag.js +28 -0
  39. package/dist/api/context/index.d.ts +1 -0
  40. package/dist/api/context/index.js +17 -0
  41. package/dist/api/context/navigation-context.d.ts +7 -0
  42. package/dist/api/context/navigation-context.js +8 -0
  43. package/dist/api/context/navigation-provider.d.ts +4 -0
  44. package/dist/api/context/navigation-provider.js +40 -0
  45. package/dist/api/controls.d.ts +3 -0
  46. package/dist/api/controls.js +20 -0
  47. package/dist/api/environment.d.ts +118 -0
  48. package/dist/api/environment.js +17 -0
  49. package/dist/api/hooks/index.d.ts +2 -0
  50. package/dist/api/hooks/index.js +18 -0
  51. package/dist/api/hooks/use-applications.d.ts +2 -0
  52. package/dist/api/hooks/use-applications.js +19 -0
  53. package/dist/api/hooks/use-imperative-form-handle.d.ts +3 -0
  54. package/dist/api/hooks/use-imperative-form-handle.js +25 -0
  55. package/dist/api/hooks/use-navigation.d.ts +4 -0
  56. package/dist/api/hooks/use-navigation.js +13 -0
  57. package/dist/api/hooks.d.ts +1 -0
  58. package/dist/api/hooks.js +24 -0
  59. package/dist/api/icon.d.ts +444 -0
  60. package/dist/api/icon.js +448 -0
  61. package/dist/api/image.d.ts +35 -0
  62. package/dist/api/image.js +84 -0
  63. package/dist/api/index.d.ts +19 -0
  64. package/dist/api/index.js +35 -0
  65. package/dist/api/keyboard.d.ts +16 -0
  66. package/dist/api/keyboard.js +12 -0
  67. package/dist/api/lib/result.d.ts +9 -0
  68. package/dist/api/lib/result.js +11 -0
  69. package/dist/api/local-storage.d.ts +13 -0
  70. package/dist/api/local-storage.js +31 -0
  71. package/dist/api/oauth.d.ts +319 -0
  72. package/dist/api/oauth.js +166 -0
  73. package/dist/api/preference.d.ts +5 -0
  74. package/dist/api/preference.js +18 -0
  75. package/dist/api/proto/application.d.ts +48 -0
  76. package/dist/api/proto/application.js +378 -0
  77. package/dist/api/proto/clipboard.d.ts +65 -0
  78. package/dist/api/proto/clipboard.js +614 -0
  79. package/dist/api/proto/common.d.ts +28 -0
  80. package/dist/api/proto/common.js +102 -0
  81. package/dist/api/proto/extension.d.ts +68 -0
  82. package/dist/api/proto/extension.js +604 -0
  83. package/dist/api/proto/google/protobuf/struct.d.ts +107 -0
  84. package/dist/api/proto/google/protobuf/struct.js +456 -0
  85. package/dist/api/proto/ipc.d.ts +64 -0
  86. package/dist/api/proto/ipc.js +604 -0
  87. package/dist/api/proto/manager.d.ts +82 -0
  88. package/dist/api/proto/manager.js +689 -0
  89. package/dist/api/proto/oauth.d.ts +55 -0
  90. package/dist/api/proto/oauth.js +379 -0
  91. package/dist/api/proto/storage.d.ts +80 -0
  92. package/dist/api/proto/storage.js +804 -0
  93. package/dist/api/proto/ui.d.ts +186 -0
  94. package/dist/api/proto/ui.js +1993 -0
  95. package/dist/api/toast.d.ts +168 -0
  96. package/dist/api/toast.js +152 -0
  97. package/dist/api/utils.d.ts +15 -0
  98. package/dist/api/utils.js +64 -0
  99. package/dist/commands/build/index.d.ts +11 -0
  100. package/dist/commands/build/index.js +123 -0
  101. package/dist/commands/develop/index.d.ts +10 -0
  102. package/dist/commands/develop/index.js +193 -0
  103. package/dist/index.d.ts +1 -0
  104. package/dist/index.js +17 -0
  105. package/dist/schemas/manifest.d.ts +75 -0
  106. package/dist/schemas/manifest.js +4 -0
  107. package/dist/utils/logger.d.ts +13 -0
  108. package/dist/utils/logger.js +38 -0
  109. package/dist/utils/utils.d.ts +2 -0
  110. package/dist/utils/utils.js +19 -0
  111. package/dist/utils/vicinae.d.ts +12 -0
  112. package/dist/utils/vicinae.js +33 -0
  113. package/package.json +73 -0
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Err = exports.Ok = void 0;
4
+ const Ok = (data) => {
5
+ return { ok: true, value: data };
6
+ };
7
+ exports.Ok = Ok;
8
+ const Err = (error) => {
9
+ return { ok: false, error };
10
+ };
11
+ exports.Err = Err;
@@ -0,0 +1,13 @@
1
+ export declare namespace LocalStorage {
2
+ type Value = string | number | boolean;
3
+ type Values = {
4
+ [key: string]: Value;
5
+ };
6
+ }
7
+ export declare class LocalStorage {
8
+ static getItem<T extends LocalStorage.Value>(key: string): Promise<T | undefined>;
9
+ static setItem(key: string, value: LocalStorage.Value): Promise<void>;
10
+ static removeItem(key: string): Promise<void>;
11
+ static allItems(): Promise<LocalStorage.Values>;
12
+ static clear(): Promise<void>;
13
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalStorage = void 0;
4
+ const bus_1 = require("./bus");
5
+ ;
6
+ class LocalStorage {
7
+ static async getItem(key) {
8
+ const res = await bus_1.bus.turboRequest('storage.get', { key });
9
+ if (!res.ok) {
10
+ return undefined;
11
+ }
12
+ ;
13
+ return res.value.value;
14
+ }
15
+ static async setItem(key, value) {
16
+ await bus_1.bus.turboRequest('storage.set', { key, value });
17
+ }
18
+ static async removeItem(key) {
19
+ await bus_1.bus.turboRequest('storage.remove', { key });
20
+ }
21
+ static async allItems() {
22
+ const res = await bus_1.bus.turboRequest('storage.list', {});
23
+ if (!res.ok)
24
+ return {};
25
+ return res.value.values;
26
+ }
27
+ static async clear() {
28
+ await bus_1.bus.turboRequest('storage.clear', {});
29
+ }
30
+ }
31
+ exports.LocalStorage = LocalStorage;
@@ -0,0 +1,319 @@
1
+ import { Image } from './image';
2
+ declare enum OauthRedirectMethod {
3
+ /**
4
+ * Use this type for a redirect back to the Raycast website, which will then open the extension.
5
+ * In the OAuth app, configure `https://raycast.com/redirect?packageName=Extension`
6
+ * (This is a static redirect URL for all extensions.)
7
+ * If the provider does not accept query parameters in redirect URLs, you can alternatively use `https://raycast.com/redirect/extension`
8
+ * and then customize the {@link OAuth.AuthorizationRequest} via its `extraParameters` property. For example add:
9
+ * `extraParameters: { "redirect_uri": "https://raycast.com/redirect/extension" }`
10
+ */
11
+ Web = "web",
12
+ /**
13
+ * Use this type for an app-scheme based redirect that directly opens Raycast.
14
+ * In the OAuth app, configure `raycast://oauth?package_name=Extension`
15
+ */
16
+ App = "app",
17
+ /**
18
+ * Use this type for a URI-style app scheme that directly opens Raycast.
19
+ * In the OAuth app, configure `com.raycast:/oauth?package_name=Extension`
20
+ * (Note the single slash - Google, for example, would require this flavor for an OAuth app where the Bundle ID is `com.raycast`)
21
+ */
22
+ AppURI = "appURI"
23
+ }
24
+ export declare namespace OAuth {
25
+ namespace PKCEClient {
26
+ /**
27
+ * The options for creating a new {@link OAuth.PKCEClient}.
28
+ */
29
+ interface Options {
30
+ /**
31
+ * The redirect method for the OAuth flow.
32
+ * Make sure to set this to the correct method for the provider, see {@link OAuth.RedirectMethod} for more information.
33
+ */
34
+ redirectMethod: RedirectMethod;
35
+ /**
36
+ * The name of the provider, displayed in the OAuth overlay.
37
+ */
38
+ providerName: string;
39
+ /**
40
+ * An icon displayed in the OAuth overlay.
41
+ * Make sure to provide at least a size of 64x64 pixels.
42
+ */
43
+ providerIcon?: Image.ImageLike;
44
+ /**
45
+ * An optional ID for associating the client with a provider.
46
+ * Only set this if you use multiple different clients in your extension.
47
+ */
48
+ providerId?: string;
49
+ /**
50
+ * An optional description, shown in the OAuth overlay.
51
+ * You can use this to customize the message for the end user, for example for handling scope changes or other migrations.
52
+ * Raycast shows a default message if this is not configured.
53
+ */
54
+ description?: string;
55
+ }
56
+ }
57
+ type RedirectMethod = OauthRedirectMethod;
58
+ /**
59
+ * A client for the [OAuth PKCE extension](https://datatracker.ietf.org/doc/html/rfc7636).
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import { OAuth } from "@raycast/api";
64
+ *
65
+ * const client = new OAuth.PKCEClient({
66
+ * redirectMethod: OAuth.RedirectMethod.Web,
67
+ * providerName: "Twitter",
68
+ * providerIcon: "twitter-logo.png",
69
+ * description: "Connect your Twitter account…",
70
+ * });
71
+ * ```
72
+ */
73
+ /**
74
+ * Defines the supported redirect methods for the OAuth flow.
75
+ * You can choose between web and app-scheme redirect methods, depending on what the provider requires when setting up the OAuth app.
76
+ * For examples on what redirect URI you need to configure, see the docs for each method.
77
+ */
78
+ /**
79
+ * The options for an authorization request via {@link OAuth.PKCEClient.authorizationRequest}.
80
+ */
81
+ interface AuthorizationRequestOptions {
82
+ /**
83
+ * The URL to the authorization endpoint for the OAuth provider.
84
+ */
85
+ endpoint: string;
86
+ /**
87
+ * The client ID of the configured OAuth app.
88
+ */
89
+ clientId: string;
90
+ /**
91
+ * A space-delimited list of scopes for identifying the resources to access on the user's behalf.
92
+ * The scopes are typically shown to the user on the provider's consent screen in the browser.
93
+ * Note that some providers require the same scopes be configured in the registered OAuth app.
94
+ */
95
+ scope: string;
96
+ /**
97
+ * Optional additional parameters for the authorization request.
98
+ * Note that some providers require additional parameters, for example to obtain long-lived refresh tokens.
99
+ */
100
+ extraParameters?: Record<string, string>;
101
+ }
102
+ /**
103
+ * Values of {@link OAuth.AuthorizationRequest}.
104
+ * The PKCE client automatically generates the values for you and returns them for {@link OAuth.PKCEClient.authorizationRequest}.
105
+ */
106
+ interface AuthorizationRequestURLParams {
107
+ /**
108
+ * The PKCE `code_challenge` value.
109
+ */
110
+ codeChallenge: string;
111
+ /**
112
+ * The PKCE `code_verifier` value.
113
+ */
114
+ codeVerifier: string;
115
+ /**
116
+ * The OAuth `state` value.
117
+ */
118
+ state: string;
119
+ /**
120
+ * The OAuth `redirect_uri` value.
121
+ */
122
+ redirectURI: string;
123
+ }
124
+ /**
125
+ * The request returned by {@link OAuth.PKCEClient.authorizationRequest}.
126
+ * Can be used as direct input to {@link OAuth.PKCEClient.authorize}, or
127
+ * to extract parameters for constructing a custom URL in {@link OAuth.AuthorizationOptions}.
128
+ */
129
+ interface AuthorizationRequest extends AuthorizationRequestURLParams {
130
+ /**
131
+ * Constructs the full authorization URL.
132
+ */
133
+ toURL(): string;
134
+ }
135
+ /**
136
+ * Options for customizing {@link OAuth.PKCEClient.authorize}.
137
+ * You can use values from {@link OAuth.AuthorizationRequest} to build your own URL.
138
+ */
139
+ interface AuthorizationOptions {
140
+ /**
141
+ * The full authorization URL.
142
+ */
143
+ url: string;
144
+ }
145
+ /**
146
+ * The response returned by {@link OAuth.PKCEClient.authorize}, containing the authorization code after the provider redirect.
147
+ * You can then exchange the authorization code for an access token using the provider's token endpoint.
148
+ */
149
+ interface AuthorizationResponse {
150
+ /**
151
+ * The authorization code from the OAuth provider.
152
+ */
153
+ authorizationCode: string;
154
+ }
155
+ /**
156
+ * Describes the TokenSet created from an OAuth provider's token response.
157
+ * The `accessToken` is the only required parameter but typically OAuth providers also return a refresh token, an expires value, and the scope.
158
+ * Securely store a token set via {@link OAuth.PKCEClient.setTokens} and retrieve it via {@link OAuth.PKCEClient.getTokens}.
159
+ */
160
+ interface TokenSet {
161
+ /**
162
+ * The access token returned by an OAuth token request.
163
+ */
164
+ accessToken: string;
165
+ /**
166
+ * An optional refresh token returned by an OAuth token request.
167
+ */
168
+ refreshToken?: string;
169
+ /**
170
+ * An optional id token returned by an identity request (e.g. /me, Open ID Connect).
171
+ */
172
+ idToken?: string;
173
+ /**
174
+ * An optional expires value (in seconds) returned by an OAuth token request.
175
+ */
176
+ expiresIn?: number;
177
+ /**
178
+ * The optional space-delimited list of scopes returned by an OAuth token request.
179
+ * You can use this to compare the currently stored access scopes against new access scopes the extension might require in a future version,
180
+ * and then ask the user to re-authorize with new scopes.
181
+ */
182
+ scope?: string;
183
+ /**
184
+ * The date when the token set was stored via {@link OAuth.PKCEClient.setTokens}.
185
+ */
186
+ updatedAt: Date;
187
+ /**
188
+ * A convenience method for checking whether the access token has expired.
189
+ * The method factors in some seconds of "buffer", so it returns true a couple of seconds before the actual expiration time.
190
+ * This requires the `expiresIn` parameter to be set.
191
+ */
192
+ isExpired(): boolean;
193
+ }
194
+ /**
195
+ * Options for a {@link OAuth.TokenSet} to store via {@link OAuth.PKCEClient.setTokens}.
196
+ */
197
+ interface TokenSetOptions {
198
+ /**
199
+ * The access token returned by an OAuth token request.
200
+ */
201
+ accessToken: string;
202
+ /**
203
+ * An optional refresh token returned by an OAuth token request.
204
+ */
205
+ refreshToken?: string;
206
+ /**
207
+ * An optional id token returned by an identity request (e.g. /me, Open ID Connect).
208
+ */
209
+ idToken?: string;
210
+ /**
211
+ * An optional expires value (in seconds) returned by an OAuth token request.
212
+ */
213
+ expiresIn?: number;
214
+ /**
215
+ * The optional scope value returned by an OAuth token request.
216
+ */
217
+ scope?: string;
218
+ }
219
+ /**
220
+ * Defines the standard JSON response for an OAuth token request.
221
+ * The response can be directly used to store a {@link OAuth.TokenSet} via {@link OAuth.PKCEClient.setTokens}.
222
+ */
223
+ interface TokenResponse {
224
+ /**
225
+ * The `access_token` value returned by an OAuth token request.
226
+ */
227
+ access_token: string;
228
+ /**
229
+ * An optional `refresh_token` value returned by an OAuth token request.
230
+ */
231
+ refresh_token?: string;
232
+ /**
233
+ * An optional `id_token` value returned by an identity request (e.g. /me, Open ID Connect).
234
+ */
235
+ id_token?: string;
236
+ /**
237
+ * An optional `expires_in` value (in seconds) returned by an OAuth token request.
238
+ */
239
+ expires_in?: number;
240
+ /**
241
+ * The optional `scope` value returned by an OAuth token request.
242
+ */
243
+ scope?: string;
244
+ }
245
+ }
246
+ export declare class PKCEClient {
247
+ redirectMethod: OAuth.RedirectMethod;
248
+ providerName: string;
249
+ providerIcon?: Image.ImageLike;
250
+ providerId?: string;
251
+ description?: string;
252
+ private resolvesOnRedirect?;
253
+ private isAuthorizing;
254
+ constructor(options: OAuth.PKCEClient.Options);
255
+ buildAuthUrl(options: OAuth.AuthorizationRequestOptions, state: string, codeChallenge: string, redirectURI: string): string;
256
+ getRedirectURI(): "https://raycast.com/redirect?packageName=Extension" | "raycast://oauth?package_name=Extension" | "com.raycast:/oauth?package_name=Extension";
257
+ /**
258
+ * Creates an authorization request for the provided authorization endpoint, client ID, and scopes.
259
+ * You need to first create the authorization request before calling {@link OAuth.PKCEClient.authorize}.
260
+ *
261
+ * @remarks The generated code challenge for the PKCE request uses the S256 method.
262
+ *
263
+ * @returns A promise for an {@link OAuth.AuthorizationRequest} that you can use as input for {@link OAuth.PKCEClient.authorize}.
264
+ */
265
+ authorizationRequest(options: OAuth.AuthorizationRequestOptions): Promise<OAuth.AuthorizationRequest>;
266
+ /**
267
+ * Starts the authorization and shows the OAuth overlay in Raycast.
268
+ * As parameter you can either directly use the returned request from {@link OAuth.PKCEClient.authorizationRequest},
269
+ * or customize the URL by extracting parameters from {@link OAuth.AuthorizationRequest} and providing your own URL via {@link AuthorizationOptions}.
270
+ * Eventually the URL will be used to open the authorization page of the provider in the web browser.
271
+ *
272
+ * @returns A promise for an {@link OAuth.AuthorizationResponse}, which contains the authorization code needed for the token exchange.
273
+ * The promise is resolved when the user was redirected back from the provider's authorization page to the Raycast extension.
274
+ */
275
+ authorize(options: OAuth.AuthorizationRequest | OAuth.AuthorizationOptions): Promise<OAuth.AuthorizationResponse>;
276
+ private authorizationURL;
277
+ /**
278
+ * Securely stores a {@link OAuth.TokenSet} for the provider. Use this after fetching the access token from the provider.
279
+ * If the provider returns a a standard OAuth JSON token response, you can directly pass the {@link OAuth.TokenResponse}.
280
+ * At a minimum, you need to set the {@link OAuth.TokenSet.accessToken}, and typically you also set {@link OAuth.TokenSet.refreshToken} and {@link OAuth.TokenSet.isExpired}.
281
+ * Raycast automatically shows a logout preference for the extension when a token set was saved.
282
+ *
283
+ * @remarks If you want to make use of the convenience {@link OAuth.TokenSet.isExpired} method, the property {@link OAuth.TokenSet.expiresIn} must be configured.
284
+ *
285
+ * @returns A promise that resolves when the token set has been stored.
286
+ */
287
+ setTokens(options: OAuth.TokenSetOptions | OAuth.TokenResponse): Promise<void>;
288
+ /**
289
+ * Retrieves the stored {@link OAuth.TokenSet} for the client.
290
+ * You can use this to initially check whether the authorization flow should be initiated or
291
+ * the user is already logged in and you might have to refresh the access token.
292
+ *
293
+ * @returns A promise that resolves when the token set has been retrieved.
294
+ */
295
+ getTokens(): Promise<OAuth.TokenSet | undefined>;
296
+ /**
297
+ * Removes the stored {@link OAuth.TokenSet} for the client.
298
+ *
299
+ * @remarks Raycast automatically shows a logout preference that removes the token set.
300
+ * Use this method only if you need to provide an additional logout option in your extension or you want to remove the token set because of a migration.
301
+ *
302
+ */
303
+ removeTokens(): Promise<void>;
304
+ }
305
+ declare class TokenSet {
306
+ accessToken: string;
307
+ refreshToken?: string;
308
+ idToken?: string;
309
+ expiresIn?: number;
310
+ scope?: string;
311
+ updatedAt: Date;
312
+ isExpired(): boolean;
313
+ }
314
+ export declare const OAuth: {
315
+ PKCEClient: typeof PKCEClient;
316
+ RedirectMethod: typeof OauthRedirectMethod;
317
+ TokenSet: typeof TokenSet;
318
+ };
319
+ export {};
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuth = exports.PKCEClient = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const image_1 = require("./image");
6
+ const bus_1 = require("./bus");
7
+ var OauthRedirectMethod;
8
+ (function (OauthRedirectMethod) {
9
+ /**
10
+ * Use this type for a redirect back to the Raycast website, which will then open the extension.
11
+ * In the OAuth app, configure `https://raycast.com/redirect?packageName=Extension`
12
+ * (This is a static redirect URL for all extensions.)
13
+ * If the provider does not accept query parameters in redirect URLs, you can alternatively use `https://raycast.com/redirect/extension`
14
+ * and then customize the {@link OAuth.AuthorizationRequest} via its `extraParameters` property. For example add:
15
+ * `extraParameters: { "redirect_uri": "https://raycast.com/redirect/extension" }`
16
+ */
17
+ OauthRedirectMethod["Web"] = "web";
18
+ /**
19
+ * Use this type for an app-scheme based redirect that directly opens Raycast.
20
+ * In the OAuth app, configure `raycast://oauth?package_name=Extension`
21
+ */
22
+ OauthRedirectMethod["App"] = "app";
23
+ /**
24
+ * Use this type for a URI-style app scheme that directly opens Raycast.
25
+ * In the OAuth app, configure `com.raycast:/oauth?package_name=Extension`
26
+ * (Note the single slash - Google, for example, would require this flavor for an OAuth app where the Bundle ID is `com.raycast`)
27
+ */
28
+ OauthRedirectMethod["AppURI"] = "appURI";
29
+ })(OauthRedirectMethod || (OauthRedirectMethod = {}));
30
+ class PKCEClient {
31
+ redirectMethod;
32
+ providerName;
33
+ providerIcon;
34
+ providerId;
35
+ description;
36
+ resolvesOnRedirect;
37
+ isAuthorizing;
38
+ constructor(options) {
39
+ this.providerId = options.providerId;
40
+ this.providerName = options.providerName;
41
+ this.providerIcon = options.providerIcon;
42
+ this.description = options.description;
43
+ this.redirectMethod = options.redirectMethod;
44
+ this.resolvesOnRedirect = false;
45
+ this.isAuthorizing = false;
46
+ }
47
+ buildAuthUrl(options, state, codeChallenge, redirectURI) {
48
+ const params = new URLSearchParams({
49
+ response_type: 'code',
50
+ client_id: options.clientId,
51
+ redirect_uri: redirectURI,
52
+ scope: options.scope,
53
+ state: state,
54
+ code_challenge: codeChallenge,
55
+ code_challenge_method: 'S256',
56
+ ...options.extraParameters
57
+ });
58
+ return `${options.endpoint}?${params}`;
59
+ }
60
+ getRedirectURI() {
61
+ switch (this.redirectMethod) {
62
+ case exports.OAuth.RedirectMethod.Web:
63
+ return 'https://raycast.com/redirect?packageName=Extension';
64
+ case exports.OAuth.RedirectMethod.App:
65
+ return 'raycast://oauth?package_name=Extension';
66
+ case exports.OAuth.RedirectMethod.AppURI:
67
+ return 'com.raycast:/oauth?package_name=Extension';
68
+ }
69
+ }
70
+ /**
71
+ * Creates an authorization request for the provided authorization endpoint, client ID, and scopes.
72
+ * You need to first create the authorization request before calling {@link OAuth.PKCEClient.authorize}.
73
+ *
74
+ * @remarks The generated code challenge for the PKCE request uses the S256 method.
75
+ *
76
+ * @returns A promise for an {@link OAuth.AuthorizationRequest} that you can use as input for {@link OAuth.PKCEClient.authorize}.
77
+ */
78
+ async authorizationRequest(options) {
79
+ const codeVerifier = (0, node_crypto_1.randomBytes)(128).toString('hex');
80
+ const codeChallenge = (0, node_crypto_1.createHash)('sha256').update(codeVerifier).digest('base64url');
81
+ const state = (0, node_crypto_1.randomBytes)(32).toString('hex');
82
+ const redirectURI = this.getRedirectURI();
83
+ return {
84
+ state,
85
+ codeChallenge,
86
+ codeVerifier,
87
+ redirectURI,
88
+ toURL: () => this.buildAuthUrl(options, state, codeChallenge, redirectURI)
89
+ };
90
+ }
91
+ /**
92
+ * Starts the authorization and shows the OAuth overlay in Raycast.
93
+ * As parameter you can either directly use the returned request from {@link OAuth.PKCEClient.authorizationRequest},
94
+ * or customize the URL by extracting parameters from {@link OAuth.AuthorizationRequest} and providing your own URL via {@link AuthorizationOptions}.
95
+ * Eventually the URL will be used to open the authorization page of the provider in the web browser.
96
+ *
97
+ * @returns A promise for an {@link OAuth.AuthorizationResponse}, which contains the authorization code needed for the token exchange.
98
+ * The promise is resolved when the user was redirected back from the provider's authorization page to the Raycast extension.
99
+ */
100
+ async authorize(options) {
101
+ const isAuthorizationOptions = (s) => {
102
+ return typeof s.url === 'string';
103
+ };
104
+ const res = await bus_1.bus.turboRequest('oauth.authorize', {
105
+ client: {
106
+ id: this.providerId,
107
+ description: this.description ?? 'Connect to your account',
108
+ name: this.providerName,
109
+ icon: this.providerIcon ? (0, image_1.serializeProtoImage)(this.providerIcon) : undefined
110
+ },
111
+ url: isAuthorizationOptions(options) ? options.url : options.toURL()
112
+ });
113
+ if (!res.ok) {
114
+ throw res.error;
115
+ }
116
+ return { authorizationCode: res.value.code };
117
+ }
118
+ authorizationURL;
119
+ /**
120
+ * Securely stores a {@link OAuth.TokenSet} for the provider. Use this after fetching the access token from the provider.
121
+ * If the provider returns a a standard OAuth JSON token response, you can directly pass the {@link OAuth.TokenResponse}.
122
+ * At a minimum, you need to set the {@link OAuth.TokenSet.accessToken}, and typically you also set {@link OAuth.TokenSet.refreshToken} and {@link OAuth.TokenSet.isExpired}.
123
+ * Raycast automatically shows a logout preference for the extension when a token set was saved.
124
+ *
125
+ * @remarks If you want to make use of the convenience {@link OAuth.TokenSet.isExpired} method, the property {@link OAuth.TokenSet.expiresIn} must be configured.
126
+ *
127
+ * @returns A promise that resolves when the token set has been stored.
128
+ */
129
+ async setTokens(options) {
130
+ }
131
+ /**
132
+ * Retrieves the stored {@link OAuth.TokenSet} for the client.
133
+ * You can use this to initially check whether the authorization flow should be initiated or
134
+ * the user is already logged in and you might have to refresh the access token.
135
+ *
136
+ * @returns A promise that resolves when the token set has been retrieved.
137
+ */
138
+ async getTokens() {
139
+ return undefined;
140
+ }
141
+ /**
142
+ * Removes the stored {@link OAuth.TokenSet} for the client.
143
+ *
144
+ * @remarks Raycast automatically shows a logout preference that removes the token set.
145
+ * Use this method only if you need to provide an additional logout option in your extension or you want to remove the token set because of a migration.
146
+ *
147
+ */
148
+ async removeTokens() { }
149
+ }
150
+ exports.PKCEClient = PKCEClient;
151
+ class TokenSet {
152
+ accessToken = '';
153
+ refreshToken;
154
+ idToken;
155
+ expiresIn;
156
+ scope;
157
+ updatedAt = new Date;
158
+ isExpired() {
159
+ return true;
160
+ }
161
+ }
162
+ exports.OAuth = {
163
+ PKCEClient,
164
+ RedirectMethod: OauthRedirectMethod,
165
+ TokenSet
166
+ };
@@ -0,0 +1,5 @@
1
+ export declare const getPreferenceValues: <T = {
2
+ [preferenceName: string]: any;
3
+ }>() => T;
4
+ export declare const openExtensionPreferences: () => Promise<void>;
5
+ export declare const openCommandPreferences: () => Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openCommandPreferences = exports.openExtensionPreferences = exports.getPreferenceValues = void 0;
4
+ const worker_threads_1 = require("worker_threads");
5
+ const bus_1 = require("./bus");
6
+ const getPreferenceValues = () => {
7
+ const { preferenceValues = {} } = worker_threads_1.workerData;
8
+ return preferenceValues;
9
+ };
10
+ exports.getPreferenceValues = getPreferenceValues;
11
+ const openExtensionPreferences = async () => {
12
+ await bus_1.bus.request('open-extension-preferences');
13
+ };
14
+ exports.openExtensionPreferences = openExtensionPreferences;
15
+ const openCommandPreferences = async () => {
16
+ await bus_1.bus.request('open-command-preferences');
17
+ };
18
+ exports.openCommandPreferences = openCommandPreferences;
@@ -0,0 +1,48 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ export declare const protobufPackage = "proto.ext.application";
3
+ export interface OpenApplicationRequest {
4
+ target: string;
5
+ appId?: string | undefined;
6
+ }
7
+ export interface ListApplicationRequest {
8
+ }
9
+ export interface ListApplicationResponse {
10
+ apps: Application[];
11
+ }
12
+ export interface Request {
13
+ list?: ListApplicationRequest | undefined;
14
+ open?: OpenApplicationRequest | undefined;
15
+ }
16
+ export interface Response {
17
+ list?: ListApplicationResponse | undefined;
18
+ }
19
+ export interface Application {
20
+ id: string;
21
+ name: string;
22
+ icon: string;
23
+ }
24
+ export declare const OpenApplicationRequest: MessageFns<OpenApplicationRequest>;
25
+ export declare const ListApplicationRequest: MessageFns<ListApplicationRequest>;
26
+ export declare const ListApplicationResponse: MessageFns<ListApplicationResponse>;
27
+ export declare const Request: MessageFns<Request>;
28
+ export declare const Response: MessageFns<Response>;
29
+ export declare const Application: MessageFns<Application>;
30
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
31
+ export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
32
+ [K in keyof T]?: DeepPartial<T[K]>;
33
+ } : Partial<T>;
34
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
35
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
36
+ [K in keyof P]: Exact<P[K], I[K]>;
37
+ } & {
38
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
39
+ };
40
+ export interface MessageFns<T> {
41
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
42
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
43
+ fromJSON(object: any): T;
44
+ toJSON(message: T): unknown;
45
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
46
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
47
+ }
48
+ export {};