instant-cli 1.0.6-branch-drewh-github-oauth-cli-control.24530053141.1 → 1.0.6
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/.turbo/turbo-build.log +1 -1
- package/__tests__/authClientAddGoogle.test.ts +1 -14
- package/dist/commands/auth/client/add.d.ts.map +1 -1
- package/dist/commands/auth/client/add.js +7 -103
- package/dist/commands/auth/client/add.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/auth/client/add.ts +6 -131
- package/src/index.ts +1 -5
- package/__tests__/authClientAddGithub.test.ts +0 -223
package/.turbo/turbo-build.log
CHANGED
|
@@ -211,12 +211,6 @@ describe('web: success', () => {
|
|
|
211
211
|
expect(output).toContain(
|
|
212
212
|
'https://api.instantdb.com/runtime/oauth/callback',
|
|
213
213
|
);
|
|
214
|
-
expect(output).toContain('Google OAuth client created: google-web');
|
|
215
|
-
expect(output).toContain('App type: web');
|
|
216
|
-
expect(output).toContain('ID: client-1');
|
|
217
|
-
expect(output).toContain(
|
|
218
|
-
'Google Client ID: 123456.apps.googleusercontent.com',
|
|
219
|
-
);
|
|
220
214
|
});
|
|
221
215
|
|
|
222
216
|
test('with custom-redirect-uri → uses it and prints forwarding instructions', async () => {
|
|
@@ -262,13 +256,6 @@ describe('ios', () => {
|
|
|
262
256
|
clientId: '123456.apps.googleusercontent.com',
|
|
263
257
|
});
|
|
264
258
|
expect(addedClients[0].clientSecret).toBeUndefined();
|
|
265
|
-
|
|
266
|
-
expect(output).not.toContain('Add this redirect URI');
|
|
267
|
-
expect(output).toContain('Google OAuth client created: google-ios');
|
|
268
|
-
expect(output).toContain('App type: ios');
|
|
269
|
-
expect(output).toContain('ID: client-1');
|
|
270
|
-
expect(output).toContain(
|
|
271
|
-
'Google Client ID: 123456.apps.googleusercontent.com',
|
|
272
|
-
);
|
|
259
|
+
expect(logs.join('\n')).not.toContain('Add this redirect URI');
|
|
273
260
|
});
|
|
274
261
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../../src/commands/auth/client/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAyB,MAAM,QAAQ,CAAC;AAGvD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../../src/commands/auth/client/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAyB,MAAM,QAAQ,CAAC;AAGvD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAwP5D,eAAO,MAAM,gBAAgB;;;;qdA0D5B,CAAC"}
|
|
@@ -7,7 +7,8 @@ import { GOOGLE_AUTHORIZATION_ENDPOINT, GOOGLE_DEFAULT_CALLBACK_URL, GOOGLE_DISC
|
|
|
7
7
|
import { UI } from "../../../ui/index.js";
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import boxen from 'boxen';
|
|
10
|
-
|
|
10
|
+
import { redirect } from '@effect/platform/HttpServerResponse';
|
|
11
|
+
const ClientTypeSchema = Schema.Literal('google');
|
|
11
12
|
const GoogleAppTypeSchema = Schema.Literal('web', 'ios', 'android', 'button-for-web');
|
|
12
13
|
const selectGoogleAppType = (value) => Effect.gen(function* () {
|
|
13
14
|
const { yes } = yield* GlobalOpts;
|
|
@@ -159,106 +160,8 @@ ${chalk.dim('Your URI must forward to https://api.instantdb.com/runtime/oauth/ca
|
|
|
159
160
|
yield* Effect.log(boxen([
|
|
160
161
|
`Google OAuth client created: ${response.client.client_name}`,
|
|
161
162
|
`App type: ${appType}`,
|
|
162
|
-
`
|
|
163
|
-
`Google
|
|
164
|
-
...redirectMessages,
|
|
165
|
-
].join('\n'), { dimBorder: true, padding: { right: 1, left: 1 } }));
|
|
166
|
-
});
|
|
167
|
-
const GITHUB_DEFAULT_CALLBACK_URL = 'https://api.instantdb.com/runtime/oauth/callback';
|
|
168
|
-
const handleGithubClient = Effect.fn(function* (opts) {
|
|
169
|
-
const { auth, provider } = yield* getOrCreateProvider('github');
|
|
170
|
-
const usedClientNames = new Set((auth.oauth_clients ?? []).map((client) => client.client_name));
|
|
171
|
-
const suggestedClientName = findName('github-web', usedClientNames);
|
|
172
|
-
const clientName = yield* optOrPrompt(opts.name, {
|
|
173
|
-
simpleName: '--name',
|
|
174
|
-
required: true,
|
|
175
|
-
skipIf: false,
|
|
176
|
-
prompt: {
|
|
177
|
-
prompt: 'Client Name:',
|
|
178
|
-
defaultValue: suggestedClientName,
|
|
179
|
-
placeholder: suggestedClientName,
|
|
180
|
-
validate: validateRequired,
|
|
181
|
-
modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
if (usedClientNames.has(clientName || '')) {
|
|
185
|
-
return yield* BadArgsError.make({
|
|
186
|
-
message: `The unique name '${clientName}' is already in use.`,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
const clientId = yield* optOrPrompt(opts['client-id'], {
|
|
190
|
-
simpleName: '--client-id',
|
|
191
|
-
required: true,
|
|
192
|
-
skipIf: false,
|
|
193
|
-
prompt: {
|
|
194
|
-
prompt: `Client ID ${chalk.dim('(from https://github.com/settings/developers)')}`,
|
|
195
|
-
modifyOutput: UI.modifiers.piped([
|
|
196
|
-
UI.modifiers.topPadding,
|
|
197
|
-
UI.modifiers.dimOnComplete,
|
|
198
|
-
]),
|
|
199
|
-
validate: validateRequired,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
const clientSecret = yield* optOrPrompt(opts['client-secret'], {
|
|
203
|
-
required: true,
|
|
204
|
-
skipIf: false,
|
|
205
|
-
simpleName: '--client-secret',
|
|
206
|
-
prompt: {
|
|
207
|
-
prompt: `Client Secret: ${chalk.dim('(from https://github.com/settings/developers)')}`,
|
|
208
|
-
validate: validateRequired,
|
|
209
|
-
sensitive: true,
|
|
210
|
-
modifyOutput: UI.modifiers.piped([
|
|
211
|
-
UI.modifiers.topPadding,
|
|
212
|
-
UI.modifiers.dimOnComplete,
|
|
213
|
-
]),
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
const customRedirectUri = yield* optOrPrompt(opts['custom-redirect-uri'], {
|
|
217
|
-
required: false,
|
|
218
|
-
simpleName: '--custom-redirect-uri',
|
|
219
|
-
skipIf: false,
|
|
220
|
-
prompt: {
|
|
221
|
-
prompt: '',
|
|
222
|
-
placeholder: 'https://yoursite.com/oauth/callback',
|
|
223
|
-
modifyOutput: UI.modifiers.piped([
|
|
224
|
-
(output, status) => {
|
|
225
|
-
if (status === 'idle') {
|
|
226
|
-
return (`\nCustom redirect URI (optional):
|
|
227
|
-
${chalk.dim('With a custom redirect URI, users will see "Redirecting to yoursite.com..." for a more branded experience.')}
|
|
228
|
-
${chalk.dim('Your URI must forward to https://api.instantdb.com/runtime/oauth/callback with all query parameters preserved.')}\n\n` +
|
|
229
|
-
stripFirstBlankLine(output));
|
|
230
|
-
}
|
|
231
|
-
return `\nCustom redirect URI (optional):\n${stripFirstBlankLine(output)}`;
|
|
232
|
-
},
|
|
233
|
-
UI.modifiers.dimOnComplete,
|
|
234
|
-
]),
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
if (!clientName) {
|
|
238
|
-
return yield* BadArgsError.make({ message: 'Client name is required.' });
|
|
239
|
-
}
|
|
240
|
-
const redirectUri = customRedirectUri || GITHUB_DEFAULT_CALLBACK_URL;
|
|
241
|
-
// The backend infers GitHub's authorization/token endpoints from
|
|
242
|
-
// meta.providerName === 'github', so we don't pass them here.
|
|
243
|
-
const response = yield* addOAuthClient({
|
|
244
|
-
providerId: provider.id,
|
|
245
|
-
clientName,
|
|
246
|
-
clientId,
|
|
247
|
-
clientSecret,
|
|
248
|
-
redirectTo: redirectUri,
|
|
249
|
-
meta: { providerName: 'github' },
|
|
250
|
-
});
|
|
251
|
-
const redirectMessages = [
|
|
252
|
-
chalk.bold(`\nAdd this callback URL in your GitHub OAuth App settings:\n${redirectUri}\n`),
|
|
253
|
-
];
|
|
254
|
-
if (customRedirectUri) {
|
|
255
|
-
redirectMessages.push(`Your custom redirect must forward to ${chalk.bold(GITHUB_DEFAULT_CALLBACK_URL)} with all query parameters preserved.`);
|
|
256
|
-
redirectMessages.push(`You can test it by visiting: ${chalk.bold(redirectUri + '?test-redirect=true')}`);
|
|
257
|
-
}
|
|
258
|
-
yield* Effect.log(boxen([
|
|
259
|
-
`GitHub OAuth client created: ${response.client.client_name}`,
|
|
260
|
-
`ID: ${response.client.id}`,
|
|
261
|
-
`GitHub Client ID: ${response.client.client_id ?? clientId}`,
|
|
163
|
+
`Client database id: ${response.client.id}`,
|
|
164
|
+
`Google client id: ${response.client.client_id ?? clientId}`,
|
|
262
165
|
...redirectMessages,
|
|
263
166
|
].join('\n'), { dimBorder: true, padding: { right: 1, left: 1 } }));
|
|
264
167
|
});
|
|
@@ -272,9 +175,9 @@ export const authClientAddCmd = Effect.fn(function* (opts) {
|
|
|
272
175
|
const clientType = yield* Option.fromNullable(opts.type).pipe(Effect.catchTag('NoSuchElementException', () => runUIEffect(new UI.Select({
|
|
273
176
|
options: [
|
|
274
177
|
{ label: 'Google', value: 'google' },
|
|
275
|
-
{ label: 'GitHub', value: 'github' },
|
|
276
178
|
// TODO: implement
|
|
277
179
|
// { label: 'Apple', value: 'apple' },
|
|
180
|
+
// { label: 'GitHub', value: 'github' },
|
|
278
181
|
// { label: 'LinkedIn', value: 'linkedin' },
|
|
279
182
|
// { label: 'Clerk', value: 'clerk' },
|
|
280
183
|
// { label: 'Firebase', value: 'firebase' },
|
|
@@ -284,9 +187,10 @@ export const authClientAddCmd = Effect.fn(function* (opts) {
|
|
|
284
187
|
}))), Effect.andThen((s) => Schema.decodeUnknown(ClientTypeSchema)(s)), Effect.catchTag('ParseError', () => BadArgsError.make({
|
|
285
188
|
message: 'Invalid client type, must be one of: google, apple, github, linkedin, clerk, firebase',
|
|
286
189
|
})));
|
|
287
|
-
yield* Match.value(clientType).pipe(Match.withReturnType(), Match.when('google', () => handleGoogleClient(opts)),
|
|
190
|
+
yield* Match.value(clientType).pipe(Match.withReturnType(), Match.when('google', () => handleGoogleClient(opts)),
|
|
288
191
|
// Match.when('apple', () => Effect.logError('Not Implemented')),
|
|
289
192
|
// Match.when('clerk', () => Effect.logError('Not Implemented')),
|
|
193
|
+
// Match.when('github', () => Effect.logError('Not Implemented')),
|
|
290
194
|
// Match.when('firebase', () => Effect.logError('Not Implemented')),
|
|
291
195
|
// Match.when('linkedin', () => Effect.logError('Not Implemented')),
|
|
292
196
|
Match.exhaustive);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../../src/commands/auth/client/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CACrC,QAAQ,EACR,QAAQ,CAKT,CAAC;AAEF,MAAM,mBAAm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jB,CAAC;AACJ,CAAC,EACD,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CACpC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CACP,oFAAoF,CACrF,CACF,CAAC;AACJ,CAAC,CAAC,CACH,CACF,CAAC","sourcesContent":["import { Effect, Match, Option, Schema } from 'effect';\nimport type { authClientAddDef, OptsFromCommand } from '../../../index.ts';\nimport { BadArgsError } from '../../../errors.ts';\nimport { GlobalOpts } from '../../../context/globalOpts.ts';\nimport {\n optOrPrompt,\n runUIEffect,\n stripFirstBlankLine,\n validateRequired,\n} from '../../../lib/ui.ts';\nimport {\n addOAuthClient,\n addOAuthProvider,\n getAppsAuth,\n} from '../../../lib/oauth.ts';\nimport {\n GOOGLE_AUTHORIZATION_ENDPOINT,\n GOOGLE_DEFAULT_CALLBACK_URL,\n GOOGLE_DISCOVERY_ENDPOINT,\n GOOGLE_TOKEN_ENDPOINT,\n} from '@instantdb/platform';\nimport { UI } from '../../../ui/index.ts';\nimport chalk from 'chalk';\nimport boxen from 'boxen';\n\nconst ClientTypeSchema = Schema.Literal(\n 'google',\n 'github',\n // 'apple',\n // 'linkedin',\n // 'clerk',\n // 'firebase',\n);\n\nconst GoogleAppTypeSchema = Schema.Literal(\n 'web',\n 'ios',\n 'android',\n 'button-for-web',\n);\n\nconst selectGoogleAppType = (value: unknown) =>\n Effect.gen(function* () {\n const { yes } = yield* GlobalOpts;\n\n return yield* Option.fromNullable(value).pipe(\n Effect.catchTag('NoSuchElementException', () => {\n if (yes) {\n return BadArgsError.make({\n message: `Missing required value for --app-type. Expected one of: ${GoogleAppTypeSchema.literals.join(', ')}`,\n });\n }\n\n return runUIEffect(\n new UI.Select({\n options: [\n {\n label:\n 'Web' + chalk.dim(' (Redirect Flows or Expo Auth Session)'),\n value: 'web',\n },\n { label: 'iOS', value: 'ios' },\n { label: 'Android', value: 'android' },\n { label: 'Google Button for Web', value: 'button-for-web' },\n ],\n promptText: 'Select a Google app type:',\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n defaultValue: 'web',\n }),\n ).pipe(\n Effect.catchTag('UIError', (e) =>\n BadArgsError.make({ message: `UI error: ${e.message}` }),\n ),\n );\n }),\n Effect.andThen((raw) => Schema.decodeUnknown(GoogleAppTypeSchema)(raw)),\n Effect.catchTag('ParseError', () =>\n BadArgsError.make({\n message:\n 'Invalid app-type, must be one of: web, ios, android, button-for-web',\n }),\n ),\n );\n });\n\n// If user has clients google-web-1 and google-web-2, it will provide google-web-3\nconst findName = (prefix: string, used: Set<string>) => {\n if (!used.has(prefix)) {\n return prefix;\n }\n\n for (let i = 2; ; i++) {\n const candidate = `${prefix}${i}`;\n if (!used.has(candidate)) {\n return candidate;\n }\n }\n};\n\nconst getOrCreateProvider = Effect.fn(function* (\n type: typeof ClientTypeSchema.Type,\n) {\n const auth = yield* getAppsAuth();\n const provider = auth.oauth_service_providers?.find(\n (entry) => entry.provider_name === type,\n );\n\n if (provider) {\n return { auth, provider };\n }\n\n const created = yield* addOAuthProvider({ providerName: type });\n return { auth, provider: created.provider };\n});\n\nconst handleGoogleClient = Effect.fn(function* (opts: Record<string, unknown>) {\n const appType = yield* selectGoogleAppType(opts['app-type']);\n const { auth, provider } = yield* getOrCreateProvider('google');\n const usedClientNames = new Set(\n (auth.oauth_clients ?? []).map((client) => client.client_name),\n );\n const suggestedClientName = findName(`google-${appType}`, usedClientNames);\n\n const clientName = yield* optOrPrompt(opts.name, {\n simpleName: '--name',\n required: true,\n skipIf: false,\n prompt: {\n prompt: 'Client Name:',\n defaultValue: suggestedClientName,\n placeholder: suggestedClientName,\n validate: validateRequired,\n modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),\n },\n });\n\n if (usedClientNames.has(clientName || '')) {\n return yield* BadArgsError.make({\n message: `The unique name '${clientName}' is already in use.`,\n });\n }\n\n const clientId = yield* optOrPrompt(opts['client-id'], {\n simpleName: '--client-id',\n required: true,\n skipIf: false,\n prompt: {\n prompt: `Client ID ${chalk.dim('(from https://console.developers.google.com/apis/credentials)')}`,\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n validate: validateRequired,\n },\n });\n\n const clientSecret = yield* optOrPrompt(opts['client-secret'], {\n required: appType === 'web',\n skipIf: appType !== 'web',\n simpleName: '--client-secret',\n prompt: {\n prompt: `Client Secret: ${chalk.dim('(from https://console.developers.google.com/apis/credentials)')}`,\n validate: validateRequired,\n sensitive: true,\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n },\n });\n\n const customRedirectUri = yield* optOrPrompt(opts['custom-redirect-uri'], {\n required: false,\n prompt: {\n prompt: '',\n placeholder: 'https://yoursite.com/oauth/callback',\n modifyOutput: UI.modifiers.piped([\n (output, status) => {\n if (status === 'idle') {\n return (\n `\\nCustom redirect URI (optional):\n${chalk.dim('With a custom redirect URI, users will see \"Redirecting to yoursite.com...\" for a more branded experience.')}\n${chalk.dim('Your URI must forward to https://api.instantdb.com/runtime/oauth/callback with all query parameters preserved.')}\\n\\n` +\n stripFirstBlankLine(output)\n );\n }\n return `\\nCustom redirect URI (optional):\\n${stripFirstBlankLine(output)}`;\n },\n UI.modifiers.dimOnComplete,\n ]),\n },\n simpleName: '--custom-redirect-uri',\n skipIf: appType !== 'web',\n skipMessage: 'Provided custom redirect URI when not using web app type.',\n });\n\n if (!clientName) {\n return yield* BadArgsError.make({ message: 'Client name is required.' }); // Should never reach this\n }\n const redirectUri = customRedirectUri || GOOGLE_DEFAULT_CALLBACK_URL;\n\n const response = yield* addOAuthClient({\n providerId: provider.id,\n clientName,\n clientId,\n clientSecret: clientSecret,\n authorizationEndpoint: GOOGLE_AUTHORIZATION_ENDPOINT,\n tokenEndpoint: GOOGLE_TOKEN_ENDPOINT,\n discoveryEndpoint: GOOGLE_DISCOVERY_ENDPOINT,\n redirectTo: redirectUri,\n meta: {\n appType,\n skipNonceChecks: true,\n },\n });\n\n const redirectMessages: string[] = [];\n if (appType === 'web') {\n redirectMessages.push(\n chalk.bold(\n `\\nAdd this redirect URI in Google Console:\\n${redirectUri}\\n`,\n ),\n );\n if (customRedirectUri) {\n redirectMessages.push(\n `Your custom redirect must forward to ${chalk.bold(GOOGLE_DEFAULT_CALLBACK_URL)} with all query parameters preserved.`,\n );\n redirectMessages.push(\n `You can test it by visiting: ${chalk.bold(redirectUri + '?test-redirect=true')}`,\n );\n }\n }\n\n yield* Effect.log(\n boxen(\n [\n `Google OAuth client created: ${response.client.client_name}`,\n `App type: ${appType}`,\n `ID: ${response.client.id}`,\n `Google Client ID: ${response.client.client_id ?? clientId}`,\n ...redirectMessages,\n ].join('\\n'),\n { dimBorder: true, padding: { right: 1, left: 1 } },\n ),\n );\n});\n\nconst GITHUB_DEFAULT_CALLBACK_URL =\n 'https://api.instantdb.com/runtime/oauth/callback';\n\nconst handleGithubClient = Effect.fn(function* (opts: Record<string, unknown>) {\n const { auth, provider } = yield* getOrCreateProvider('github');\n const usedClientNames = new Set(\n (auth.oauth_clients ?? []).map((client) => client.client_name),\n );\n const suggestedClientName = findName('github-web', usedClientNames);\n\n const clientName = yield* optOrPrompt(opts.name, {\n simpleName: '--name',\n required: true,\n skipIf: false,\n prompt: {\n prompt: 'Client Name:',\n defaultValue: suggestedClientName,\n placeholder: suggestedClientName,\n validate: validateRequired,\n modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),\n },\n });\n\n if (usedClientNames.has(clientName || '')) {\n return yield* BadArgsError.make({\n message: `The unique name '${clientName}' is already in use.`,\n });\n }\n\n const clientId = yield* optOrPrompt(opts['client-id'], {\n simpleName: '--client-id',\n required: true,\n skipIf: false,\n prompt: {\n prompt: `Client ID ${chalk.dim('(from https://github.com/settings/developers)')}`,\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n validate: validateRequired,\n },\n });\n\n const clientSecret = yield* optOrPrompt(opts['client-secret'], {\n required: true,\n skipIf: false,\n simpleName: '--client-secret',\n prompt: {\n prompt: `Client Secret: ${chalk.dim('(from https://github.com/settings/developers)')}`,\n validate: validateRequired,\n sensitive: true,\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n },\n });\n\n const customRedirectUri = yield* optOrPrompt(opts['custom-redirect-uri'], {\n required: false,\n simpleName: '--custom-redirect-uri',\n skipIf: false,\n prompt: {\n prompt: '',\n placeholder: 'https://yoursite.com/oauth/callback',\n modifyOutput: UI.modifiers.piped([\n (output, status) => {\n if (status === 'idle') {\n return (\n `\\nCustom redirect URI (optional):\n${chalk.dim('With a custom redirect URI, users will see \"Redirecting to yoursite.com...\" for a more branded experience.')}\n${chalk.dim('Your URI must forward to https://api.instantdb.com/runtime/oauth/callback with all query parameters preserved.')}\\n\\n` +\n stripFirstBlankLine(output)\n );\n }\n return `\\nCustom redirect URI (optional):\\n${stripFirstBlankLine(output)}`;\n },\n UI.modifiers.dimOnComplete,\n ]),\n },\n });\n\n if (!clientName) {\n return yield* BadArgsError.make({ message: 'Client name is required.' });\n }\n\n const redirectUri = customRedirectUri || GITHUB_DEFAULT_CALLBACK_URL;\n\n // The backend infers GitHub's authorization/token endpoints from\n // meta.providerName === 'github', so we don't pass them here.\n const response = yield* addOAuthClient({\n providerId: provider.id,\n clientName,\n clientId,\n clientSecret,\n redirectTo: redirectUri,\n meta: { providerName: 'github' },\n });\n\n const redirectMessages: string[] = [\n chalk.bold(\n `\\nAdd this callback URL in your GitHub OAuth App settings:\\n${redirectUri}\\n`,\n ),\n ];\n if (customRedirectUri) {\n redirectMessages.push(\n `Your custom redirect must forward to ${chalk.bold(GITHUB_DEFAULT_CALLBACK_URL)} with all query parameters preserved.`,\n );\n redirectMessages.push(\n `You can test it by visiting: ${chalk.bold(redirectUri + '?test-redirect=true')}`,\n );\n }\n\n yield* Effect.log(\n boxen(\n [\n `GitHub OAuth client created: ${response.client.client_name}`,\n `ID: ${response.client.id}`,\n `GitHub Client ID: ${response.client.client_id ?? clientId}`,\n ...redirectMessages,\n ].join('\\n'),\n { dimBorder: true, padding: { right: 1, left: 1 } },\n ),\n );\n});\n\nexport const authClientAddCmd = Effect.fn(\n function* (\n opts: OptsFromCommand<typeof authClientAddDef> & Record<string, unknown>,\n ) {\n const { yes } = yield* GlobalOpts;\n if (!opts.type && yes) {\n return yield* BadArgsError.make({\n message: `Missing required value for --type. Expected one of: ${ClientTypeSchema.literals.join(', ')}`,\n });\n }\n const clientType = yield* Option.fromNullable(opts.type).pipe(\n Effect.catchTag('NoSuchElementException', () =>\n runUIEffect(\n new UI.Select({\n options: [\n { label: 'Google', value: 'google' },\n { label: 'GitHub', value: 'github' },\n // TODO: implement\n // { label: 'Apple', value: 'apple' },\n // { label: 'LinkedIn', value: 'linkedin' },\n // { label: 'Clerk', value: 'clerk' },\n // { label: 'Firebase', value: 'firebase' },\n ],\n promptText: 'Select a client type:',\n modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),\n }),\n ),\n ),\n Effect.andThen((s) => Schema.decodeUnknown(ClientTypeSchema)(s)),\n Effect.catchTag('ParseError', () =>\n BadArgsError.make({\n message:\n 'Invalid client type, must be one of: google, apple, github, linkedin, clerk, firebase',\n }),\n ),\n );\n\n yield* Match.value(clientType).pipe(\n Match.withReturnType<Effect.Effect<void, any, any>>(),\n Match.when('google', () => handleGoogleClient(opts)),\n Match.when('github', () => handleGithubClient(opts)),\n // Match.when('apple', () => Effect.logError('Not Implemented')),\n // Match.when('clerk', () => Effect.logError('Not Implemented')),\n // Match.when('firebase', () => Effect.logError('Not Implemented')),\n // Match.when('linkedin', () => Effect.logError('Not Implemented')),\n Match.exhaustive,\n );\n },\n Effect.catchTag('BadArgsError', (e) =>\n Effect.gen(function* () {\n yield* Effect.logError(e.message);\n yield* Effect.log(\n chalk.dim(\n 'hint: run `instant-cli auth client add --help` for the list of available arguments',\n ),\n );\n }),\n ),\n);\n"]}
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../../src/commands/auth/client/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAE/D,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CACrC,QAAQ,CAMT,CAAC;AAEF,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CACxC,KAAK,EACL,KAAK,EACL,SAAS,EACT,gBAAgB,CACjB,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,EAAE,CAC7C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC;IA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nC,YAAY,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;KAC/D,CAAC,CACH,CACF,EACD,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,EAChE,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE,CACjC,YAAY,CAAC,IAAI,CAAC;QAChB,OAAO,EACL,uFAAuF;KAC1F,CAAC,CACH,CACF,CAAC;IAEF,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CACjC,KAAK,CAAC,cAAc,EAAiC,EACrD,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACpD,iEAAiE;IACjE,iEAAiE;IACjE,kEAAkE;IAClE,oEAAoE;IACpE,oEAAoE;IACpE,KAAK,CAAC,UAAU,CACjB,CAAC;AACJ,CAAC,EACD,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CACpC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CACP,oFAAoF,CACrF,CACF,CAAC;AACJ,CAAC,CAAC,CACH,CACF,CAAC","sourcesContent":["import { Effect, Match, Option, Schema } from 'effect';\nimport type { authClientAddDef, OptsFromCommand } from '../../../index.ts';\nimport { BadArgsError } from '../../../errors.ts';\nimport { GlobalOpts } from '../../../context/globalOpts.ts';\nimport {\n optOrPrompt,\n runUIEffect,\n stripFirstBlankLine,\n validateRequired,\n} from '../../../lib/ui.ts';\nimport {\n addOAuthClient,\n addOAuthProvider,\n getAppsAuth,\n} from '../../../lib/oauth.ts';\nimport {\n GOOGLE_AUTHORIZATION_ENDPOINT,\n GOOGLE_DEFAULT_CALLBACK_URL,\n GOOGLE_DISCOVERY_ENDPOINT,\n GOOGLE_TOKEN_ENDPOINT,\n} from '@instantdb/platform';\nimport { UI } from '../../../ui/index.ts';\nimport chalk from 'chalk';\nimport boxen from 'boxen';\nimport { redirect } from '@effect/platform/HttpServerResponse';\n\nconst ClientTypeSchema = Schema.Literal(\n 'google',\n // 'apple',\n // 'github',\n // 'linkedin',\n // 'clerk',\n // 'firebase',\n);\n\nconst GoogleAppTypeSchema = Schema.Literal(\n 'web',\n 'ios',\n 'android',\n 'button-for-web',\n);\n\nconst selectGoogleAppType = (value: unknown) =>\n Effect.gen(function* () {\n const { yes } = yield* GlobalOpts;\n\n return yield* Option.fromNullable(value).pipe(\n Effect.catchTag('NoSuchElementException', () => {\n if (yes) {\n return BadArgsError.make({\n message: `Missing required value for --app-type. Expected one of: ${GoogleAppTypeSchema.literals.join(', ')}`,\n });\n }\n\n return runUIEffect(\n new UI.Select({\n options: [\n {\n label:\n 'Web' + chalk.dim(' (Redirect Flows or Expo Auth Session)'),\n value: 'web',\n },\n { label: 'iOS', value: 'ios' },\n { label: 'Android', value: 'android' },\n { label: 'Google Button for Web', value: 'button-for-web' },\n ],\n promptText: 'Select a Google app type:',\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n defaultValue: 'web',\n }),\n ).pipe(\n Effect.catchTag('UIError', (e) =>\n BadArgsError.make({ message: `UI error: ${e.message}` }),\n ),\n );\n }),\n Effect.andThen((raw) => Schema.decodeUnknown(GoogleAppTypeSchema)(raw)),\n Effect.catchTag('ParseError', () =>\n BadArgsError.make({\n message:\n 'Invalid app-type, must be one of: web, ios, android, button-for-web',\n }),\n ),\n );\n });\n\n// If user has clients google-web-1 and google-web-2, it will provide google-web-3\nconst findName = (prefix: string, used: Set<string>) => {\n if (!used.has(prefix)) {\n return prefix;\n }\n\n for (let i = 2; ; i++) {\n const candidate = `${prefix}${i}`;\n if (!used.has(candidate)) {\n return candidate;\n }\n }\n};\n\nconst getOrCreateProvider = Effect.fn(function* (\n type: typeof ClientTypeSchema.Type,\n) {\n const auth = yield* getAppsAuth();\n const provider = auth.oauth_service_providers?.find(\n (entry) => entry.provider_name === type,\n );\n\n if (provider) {\n return { auth, provider };\n }\n\n const created = yield* addOAuthProvider({ providerName: type });\n return { auth, provider: created.provider };\n});\n\nconst handleGoogleClient = Effect.fn(function* (opts: Record<string, unknown>) {\n const appType = yield* selectGoogleAppType(opts['app-type']);\n const { auth, provider } = yield* getOrCreateProvider('google');\n const usedClientNames = new Set(\n (auth.oauth_clients ?? []).map((client) => client.client_name),\n );\n const suggestedClientName = findName(`google-${appType}`, usedClientNames);\n\n const clientName = yield* optOrPrompt(opts.name, {\n simpleName: '--name',\n required: true,\n skipIf: false,\n prompt: {\n prompt: 'Client Name:',\n defaultValue: suggestedClientName,\n placeholder: suggestedClientName,\n validate: validateRequired,\n modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),\n },\n });\n\n if (usedClientNames.has(clientName || '')) {\n return yield* BadArgsError.make({\n message: `The unique name '${clientName}' is already in use.`,\n });\n }\n\n const clientId = yield* optOrPrompt(opts['client-id'], {\n simpleName: '--client-id',\n required: true,\n skipIf: false,\n prompt: {\n prompt: `Client ID ${chalk.dim('(from https://console.developers.google.com/apis/credentials)')}`,\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n validate: validateRequired,\n },\n });\n\n const clientSecret = yield* optOrPrompt(opts['client-secret'], {\n required: appType === 'web',\n skipIf: appType !== 'web',\n simpleName: '--client-secret',\n prompt: {\n prompt: `Client Secret: ${chalk.dim('(from https://console.developers.google.com/apis/credentials)')}`,\n validate: validateRequired,\n sensitive: true,\n modifyOutput: UI.modifiers.piped([\n UI.modifiers.topPadding,\n UI.modifiers.dimOnComplete,\n ]),\n },\n });\n\n const customRedirectUri = yield* optOrPrompt(opts['custom-redirect-uri'], {\n required: false,\n prompt: {\n prompt: '',\n placeholder: 'https://yoursite.com/oauth/callback',\n modifyOutput: UI.modifiers.piped([\n (output, status) => {\n if (status === 'idle') {\n return (\n `\\nCustom redirect URI (optional):\n${chalk.dim('With a custom redirect URI, users will see \"Redirecting to yoursite.com...\" for a more branded experience.')}\n${chalk.dim('Your URI must forward to https://api.instantdb.com/runtime/oauth/callback with all query parameters preserved.')}\\n\\n` +\n stripFirstBlankLine(output)\n );\n }\n return `\\nCustom redirect URI (optional):\\n${stripFirstBlankLine(output)}`;\n },\n UI.modifiers.dimOnComplete,\n ]),\n },\n simpleName: '--custom-redirect-uri',\n skipIf: appType !== 'web',\n skipMessage: 'Provided custom redirect URI when not using web app type.',\n });\n\n if (!clientName) {\n return yield* BadArgsError.make({ message: 'Client name is required.' }); // Should never reach this\n }\n const redirectUri = customRedirectUri || GOOGLE_DEFAULT_CALLBACK_URL;\n\n const response = yield* addOAuthClient({\n providerId: provider.id,\n clientName,\n clientId,\n clientSecret: clientSecret,\n authorizationEndpoint: GOOGLE_AUTHORIZATION_ENDPOINT,\n tokenEndpoint: GOOGLE_TOKEN_ENDPOINT,\n discoveryEndpoint: GOOGLE_DISCOVERY_ENDPOINT,\n redirectTo: redirectUri,\n meta: {\n appType,\n skipNonceChecks: true,\n },\n });\n\n const redirectMessages: string[] = [];\n if (appType === 'web') {\n redirectMessages.push(\n chalk.bold(\n `\\nAdd this redirect URI in Google Console:\\n${redirectUri}\\n`,\n ),\n );\n if (customRedirectUri) {\n redirectMessages.push(\n `Your custom redirect must forward to ${chalk.bold(GOOGLE_DEFAULT_CALLBACK_URL)} with all query parameters preserved.`,\n );\n redirectMessages.push(\n `You can test it by visiting: ${chalk.bold(redirectUri + '?test-redirect=true')}`,\n );\n }\n }\n\n yield* Effect.log(\n boxen(\n [\n `Google OAuth client created: ${response.client.client_name}`,\n `App type: ${appType}`,\n `Client database id: ${response.client.id}`,\n `Google client id: ${response.client.client_id ?? clientId}`,\n ...redirectMessages,\n ].join('\\n'),\n { dimBorder: true, padding: { right: 1, left: 1 } },\n ),\n );\n});\n\nexport const authClientAddCmd = Effect.fn(\n function* (\n opts: OptsFromCommand<typeof authClientAddDef> & Record<string, unknown>,\n ) {\n const { yes } = yield* GlobalOpts;\n if (!opts.type && yes) {\n return yield* BadArgsError.make({\n message: `Missing required value for --type. Expected one of: ${ClientTypeSchema.literals.join(', ')}`,\n });\n }\n const clientType = yield* Option.fromNullable(opts.type).pipe(\n Effect.catchTag('NoSuchElementException', () =>\n runUIEffect(\n new UI.Select({\n options: [\n { label: 'Google', value: 'google' },\n // TODO: implement\n // { label: 'Apple', value: 'apple' },\n // { label: 'GitHub', value: 'github' },\n // { label: 'LinkedIn', value: 'linkedin' },\n // { label: 'Clerk', value: 'clerk' },\n // { label: 'Firebase', value: 'firebase' },\n ],\n promptText: 'Select a client type:',\n modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),\n }),\n ),\n ),\n Effect.andThen((s) => Schema.decodeUnknown(ClientTypeSchema)(s)),\n Effect.catchTag('ParseError', () =>\n BadArgsError.make({\n message:\n 'Invalid client type, must be one of: google, apple, github, linkedin, clerk, firebase',\n }),\n ),\n );\n\n yield* Match.value(clientType).pipe(\n Match.withReturnType<Effect.Effect<void, any, any>>(),\n Match.when('google', () => handleGoogleClient(opts)),\n // Match.when('apple', () => Effect.logError('Not Implemented')),\n // Match.when('clerk', () => Effect.logError('Not Implemented')),\n // Match.when('github', () => Effect.logError('Not Implemented')),\n // Match.when('firebase', () => Effect.logError('Not Implemented')),\n // Match.when('linkedin', () => Effect.logError('Not Implemented')),\n Match.exhaustive,\n );\n },\n Effect.catchTag('BadArgsError', (e) =>\n Effect.gen(function* () {\n yield* Effect.logError(e.message);\n yield* Effect.log(\n chalk.dim(\n 'hint: run `instant-cli auth client add --help` for the list of available arguments',\n ),\n );\n }),\n ),\n);\n"]}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AA2B9D,MAAM,MAAM,eAAe,CAAC,CAAC,IAC3B,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAiBnD,eAAO,MAAM,OAAO;;;;;MAgChB,CAAC;AAIL,eAAO,MAAM,gBAAgB;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AA2B9D,MAAM,MAAM,eAAe,CAAC,CAAC,IAC3B,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAiBnD,eAAO,MAAM,OAAO;;;;;MAgChB,CAAC;AAIL,eAAO,MAAM,gBAAgB;;;;MAyCzB,CAAC;AACL,eAAO,MAAM,iBAAiB;;;MAsB1B,CAAC;AAEL,eAAO,MAAM,mBAAmB;;;;MAoB5B,CAAC;AAEL,eAAO,MAAM,mBAAmB;;;;MAgB5B,CAAC;AAEL,eAAO,MAAM,QAAQ;;;MAYjB,CAAC;AAWL,eAAO,MAAM,OAAO,qBAchB,CAAC;AAEL,eAAO,MAAM,WAAW;;MAmBpB,CAAC;AAEL,eAAO,MAAM,QAAQ;;;;;;MAiBjB,CAAC;AAEL,eAAO,MAAM,OAAO;;;;MA4ChB,CAAC;AAEL,eAAO,MAAM,OAAO;;;;;MAgDhB,CAAC;AAEL,eAAO,MAAM,QAAQ;;MAoBjB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ export const authClientAddDef = authClient
|
|
|
57
57
|
.command('add')
|
|
58
58
|
.allowExcessArguments(true)
|
|
59
59
|
.allowUnknownOption(true)
|
|
60
|
-
.option('--type <google
|
|
60
|
+
.option('--type <google>', 'Type of oauth client to add')
|
|
61
61
|
.option('--name <client name>', 'Custom name to identify the OAuth client (ex: google-web)')
|
|
62
62
|
.option('-a --app <app-id>', 'App ID to modify. Defaults to *_INSTANT_APP_ID in .env')
|
|
63
63
|
.addHelpText('after', `
|
|
@@ -67,10 +67,6 @@ Provider Specific Options:
|
|
|
67
67
|
--client-id
|
|
68
68
|
--client-secret (web only)
|
|
69
69
|
--custom-redirect-uri (optional, web only)
|
|
70
|
-
GitHub:
|
|
71
|
-
--client-id
|
|
72
|
-
--client-secret
|
|
73
|
-
--custom-redirect-uri (optional)
|
|
74
70
|
`)
|
|
75
71
|
.action((opts) => {
|
|
76
72
|
opts = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,CAAC;AAEV,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,aAAa,EACb,aAAa,EACb,gB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,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,OAAO,CAAC,aAAa,CAAC;IACpB,iBAAiB,EAAE,IAAI;IACvB,UAAU;CACX,CAAC,CAAC;AAEH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { loadEnv } from './util/loadEnv.ts';\nloadEnv();\n\nimport minimist from 'minimist';\nimport { Command, Option } from '@commander-js/extra-typings';\nimport chalk from 'chalk';\nimport { Effect, Layer } from 'effect';\nimport version from './version.js';\nimport { initCommand } from './commands/init.ts';\nimport { initWithoutFilesCommand } from './commands/initWithoutFiles.ts';\nimport { loginCommand } from './commands/login.ts';\nimport { logoutCommand } from './commands/logout.ts';\nimport {\n AuthLayerLive,\n BaseLayerLive,\n runCommandEffect,\n WithAppLayer,\n} from './layer.ts';\nimport { infoCommand } from './commands/info.ts';\nimport { pullCommand } from './commands/pull.ts';\nimport type { SchemaPermsOrBoth } from './commands/pull.ts';\nimport { claimCommand } from './commands/claim.ts';\nimport { pushCommand } from './commands/push.ts';\nimport { explorerCmd } from './commands/explorer.ts';\nimport { queryCmd } from './commands/query.ts';\nimport { program } from './program.ts';\nimport { PACKAGE_ALIAS_AND_FULL_NAMES } from './context/projectInfo.ts';\nimport { authClientAddCmd } from './commands/auth/client/add.ts';\nimport { authClientListCmd } from './commands/auth/client/list.ts';\nimport { authClientDeleteCmd } from './commands/auth/client/delete.ts';\n\nexport type OptsFromCommand<C> =\n C extends Command<any, infer R, any> ? R : never;\n\nprogram\n .name('instant-cli')\n .addOption(globalOption('-t --token <token>', 'Auth token override'))\n .addOption(globalOption('-y --yes', \"Answer 'yes' to all prompts\"))\n .addOption(globalOption('--env <file>', 'Use a specific .env file'))\n .addOption(\n globalOption('-v --version', 'Print the version number', () => {\n console.log(version);\n process.exit(0);\n }),\n )\n .addHelpOption(globalOption('-h --help', 'Print the help text for a command'))\n .usage(`<command> ${chalk.dim('[options] [args]')}`);\n\n// Command List\nexport const initDef = program\n .command('init')\n .description('Set up a new project.')\n .option(\n '-a --app <app-id>',\n 'If you have an existing app ID, we can pull schema and perms from there.',\n )\n .option(\n '-p --package <react|react-native|core|admin|solid|svelte>',\n 'Which package to automatically install if there is not one installed already.',\n )\n .option('--title <title>', 'Title for the created app')\n .option(\n '--temp',\n 'Create a temporary app which will automatically delete itself after >24 hours.',\n )\n .action((options) => {\n return runCommandEffect(\n initCommand(options).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: true,\n coerceAuth: true,\n title: options.title,\n appId: options.app,\n packageName: options.package as any,\n applyEnv: true,\n temp: options.temp,\n }),\n ),\n ),\n );\n });\n\nconst auth = program.command('auth');\nconst authClient = auth.command('client');\nexport const authClientAddDef = authClient\n .command('add')\n .allowExcessArguments(true)\n .allowUnknownOption(true)\n .option('--type <google|github>', 'Type of oauth client to add')\n .option(\n '--name <client name>',\n 'Custom name to identify the OAuth client (ex: google-web)',\n )\n .option(\n '-a --app <app-id>',\n 'App ID to modify. Defaults to *_INSTANT_APP_ID in .env',\n )\n .addHelpText(\n 'after',\n `\nProvider Specific Options:\n Google:\n --app-type web|ios|android|button-for-web\n --client-id\n --client-secret (web only)\n --custom-redirect-uri (optional, web only)\n GitHub:\n --client-id\n --client-secret\n --custom-redirect-uri (optional)\n`,\n )\n .action((opts) => {\n opts = {\n ...opts,\n ...minimist(process.argv),\n };\n return runCommandEffect(\n authClientAddCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n coerceAuth: false,\n appId: opts.app,\n allowAdminToken: true,\n }),\n ),\n ),\n );\n });\nexport const authClientListDef = authClient\n .command('list')\n .option(\n '-a --app <app-id>',\n 'App ID to list clients for. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option('--json', 'Enable JSON output')\n .allowUnknownOption(true)\n .action((opts) => {\n return runCommandEffect(\n authClientListCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n coerceAuth: false,\n appId: opts.app,\n allowAdminToken: true,\n // Silence \"searching for instant sdk.. logs for json output\"\n }).pipe(Layer.annotateLogs('silent', !!opts.json)),\n ),\n ),\n );\n });\n\nexport const authClientDeleteDef = authClient\n .command('delete')\n .option('--id <client-id>', 'Client ID to delete')\n .option('--name <client-name>', 'Client name to delete')\n .option(\n '-a --app <app-id>',\n 'App ID to delete a client from. Defaults to *_INSTANT_APP_ID in .env',\n )\n .action((opts) => {\n return runCommandEffect(\n authClientDeleteCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n appId: opts.app,\n allowAdminToken: true,\n }),\n ),\n ),\n );\n });\n\nexport const initWithoutFilesDef = program\n .command('init-without-files')\n .description('Generate a new app id and admin token pair without any files.')\n .option('--title <title>', 'Title for the created app.')\n .option(\n '--org-id <org-id>',\n 'Organization id for app. Cannot be used with --temp flag.',\n )\n .option(\n '--temp',\n 'Create a temporary app which will automatically delete itself after >24 hours.',\n )\n .action((opts) => {\n return runCommandEffect(\n initWithoutFilesCommand(opts).pipe(Effect.provide(BaseLayerLive)),\n );\n });\n\nexport const loginDef = program\n .command('login')\n .description('Log into your account')\n .option('-p --print', 'Prints the auth token into the console.')\n .option(\n '--headless',\n 'Print the login URL instead of trying to open the browser',\n )\n .action(async (opts) => {\n await runCommandEffect(\n loginCommand(opts).pipe(Effect.provide(BaseLayerLive)),\n );\n });\n\nprogram\n .command('logout')\n .description('Log out of your Instant account')\n .action(async () => {\n return runCommandEffect(\n logoutCommand().pipe(Effect.provide(BaseLayerLive)),\n );\n });\n\nexport const infoDef = program\n .command('info')\n .description('Display CLI version and login status')\n .action(async () => {\n return runCommandEffect(\n infoCommand().pipe(\n Effect.provide(\n AuthLayerLive({\n coerce: false,\n allowAdminToken: false,\n }).pipe(Layer.catchAll(() => Layer.empty)), // make the auth layer optional\n ),\n ),\n );\n });\n\nexport const explorerDef = program\n .command('explorer')\n .description('Opens the Explorer in your browser')\n .option(\n '-a --app <app-id>',\n 'App ID to open the explorer to. Defaults to *_INSTANT_APP_ID in .env',\n )\n .action(async (opts) => {\n return runCommandEffect(\n explorerCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: true,\n coerceAuth: true,\n appId: opts.app,\n }),\n ),\n ),\n );\n });\n\nexport const queryDef = program\n .command('query')\n .argument('<query>', 'InstaQL query as JSON/JSON5')\n .option(\n '-a --app <app-id>',\n 'App ID to query. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option('--admin', 'Run the query as admin (bypasses permissions)')\n .option('--as-email <email>', 'Run the query as a specific user by email')\n .option('--as-guest', 'Run the query as an unauthenticated guest')\n .option(\n '--as-token <refresh-token>',\n 'Run the query as a user identified by refresh token',\n )\n .description('Run an InstaQL query against your app.')\n .action(async function (queryArg, opts) {\n return runCommandEffect(queryCmd(queryArg, opts));\n });\n\nexport const pullDef = program\n .command('pull')\n .argument(\n '[schema|perms|all]',\n 'Which configuration to pull. Defaults to `all`',\n )\n .option(\n '-a --app <app-id>',\n 'App ID to pull to. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option(\n '-p --package <react|react-native|core|admin|solid|svelte>',\n 'Which package to automatically install if there is not one installed already.',\n )\n .option(\n '--experimental-type-preservation',\n \"[Experimental] Preserve manual type changes like `status: i.json<'online' | 'offline'>()` when doing `instant-cli pull schema`\",\n )\n .description('Pull schema and perm files from production.')\n .addHelpText(\n 'after',\n `\nEnvironment Variables:\n INSTANT_SCHEMA_FILE_PATH Override schema file location (default: instant.schema.ts)\n INSTANT_PERMS_FILE_PATH Override perms file location (default: instant.perms.ts)\n`,\n )\n .action(async function (arg, inputOpts) {\n return runCommandEffect(\n pullCommand(arg as SchemaPermsOrBoth, inputOpts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: true,\n packageName: inputOpts.package as\n | 'react'\n | 'react-native'\n | 'core'\n | 'admin'\n | undefined,\n appId: inputOpts.app,\n }),\n ),\n ),\n );\n });\n\nexport const pushDef = program\n .command('push')\n .argument(\n '[schema|perms|all]',\n 'Which configuration to push. Defaults to `all`',\n )\n .option(\n '-a --app <app-id>',\n 'App ID to push to. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option(\n '--skip-check-types',\n \"Don't check types on the server when pushing schema\",\n )\n .option(\n '--rename [renames...]',\n 'List of full attribute names separated by a \":\"\\n Example:`push --rename posts.author:posts.creator stores.owner:stores.manager`',\n )\n .option(\n '-p --package <react|react-native|core|admin|solid|svelte>',\n 'Which package to automatically install if there is not one installed already.',\n )\n .description('Push schema and perm files to production.')\n .addHelpText(\n 'after',\n `\nEnvironment Variables:\n INSTANT_SCHEMA_FILE_PATH Override schema file location (default: instant.schema.ts)\n INSTANT_PERMS_FILE_PATH Override perms file location (default: instant.perms.ts)\n`,\n )\n .action(async function (arg, inputOpts) {\n return runCommandEffect(\n pushCommand(arg, inputOpts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n appId: inputOpts.app,\n coerceLibraryInstall: true,\n coerceAuth: false,\n allowAdminToken: true,\n applyEnv: true,\n packageName:\n inputOpts.package as keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES,\n }),\n ),\n ),\n );\n });\n\nexport const claimDef = program\n .command('claim')\n .description('Transfer a temporary app into your Instant account')\n .option(\n '-a --app <app-id>',\n 'App to claim. Defaults to *_INSTANT_APP_ID in .env',\n )\n .action(async function (opts) {\n return runCommandEffect(\n claimCommand.pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n allowAdminToken: false,\n appId: opts.app,\n applyEnv: false,\n }),\n ),\n ),\n );\n });\n//// Program setup /////\n\nfunction globalOption(\n flags: string,\n description?: string,\n argParser?: (value: string, prev?: unknown) => unknown,\n) {\n const opt = new Option(flags, description);\n if (argParser) {\n opt.argParser(argParser);\n }\n // @ts-ignore\n // __global does not exist on `Option`,\n // but we use it in `getLocalAndGlobalOptions`, to produce\n // our own custom list of local and global options.\n // For more info, see the original PR:\n // https://github.com/instantdb/instant/pull/505\n opt.__global = true;\n return opt;\n}\n\nfunction getLocalAndGlobalOptions(cmd: any, helper: any) {\n const mixOfLocalAndGlobal = helper.visibleOptions(cmd);\n const localOptionsFromMix = mixOfLocalAndGlobal.filter(\n (option: any) => !option.__global,\n );\n const globalOptionsFromMix = mixOfLocalAndGlobal.filter(\n (option: any) => option.__global,\n );\n const globalOptions = helper.visibleGlobalOptions(cmd);\n\n return [localOptionsFromMix, globalOptionsFromMix.concat(globalOptions)];\n}\n\nfunction formatHelp(\n this: { showGlobalOptions: boolean },\n cmd: any,\n helper: any,\n) {\n const termWidth = helper.padWidth(cmd, helper);\n const helpWidth = helper.helpWidth || 80;\n const itemIndentWidth = 2;\n const itemSeparatorWidth = 2; // between term and description\n function formatItem(term: string, description: string | undefined) {\n if (description) {\n const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;\n return helper.boxWrap(\n fullText,\n helpWidth - itemIndentWidth,\n termWidth + itemSeparatorWidth,\n );\n }\n return term;\n }\n function formatList(textArray: string[]) {\n return textArray.join('\\n').replace(/^/gm, ' '.repeat(itemIndentWidth));\n }\n\n // Usage\n let output = [`${helper.commandUsage(cmd)}`, ''];\n\n // Description\n const commandDescription = helper.commandDescription(cmd);\n if (commandDescription.length > 0) {\n output = output.concat([\n helper.boxWrap(commandDescription, helpWidth, 0),\n '',\n ]);\n }\n\n // Arguments\n const argumentList = helper.visibleArguments(cmd).map((argument: any) => {\n return formatItem(\n helper.argumentTerm(argument),\n helper.argumentDescription(argument),\n );\n });\n if (argumentList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Arguments'),\n formatList(argumentList),\n '',\n ]);\n }\n const [visibleOptions, visibleGlobalOptions] = getLocalAndGlobalOptions(\n cmd,\n helper,\n );\n\n // Options\n const optionList = visibleOptions.map((option: any) => {\n return formatItem(\n helper.optionTerm(option),\n helper.optionDescription(option),\n );\n });\n if (optionList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Options'),\n formatList(optionList),\n '',\n ]);\n }\n // Commands\n const commandList = helper.visibleCommands(cmd).map((cmd: any) => {\n return formatItem(\n helper.subcommandTerm(cmd),\n helper.subcommandDescription(cmd),\n );\n });\n if (commandList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Commands'),\n formatList(commandList),\n '',\n ]);\n }\n\n if (this.showGlobalOptions) {\n const globalOptionList = visibleGlobalOptions.map((option: any) => {\n return formatItem(\n helper.optionTerm(option),\n helper.optionDescription(option),\n );\n });\n if (globalOptionList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Global Options'),\n formatList(globalOptionList),\n '',\n ]);\n }\n }\n\n return output.join('\\n');\n}\n\nprogram.configureHelp({\n showGlobalOptions: true,\n formatHelp,\n});\n\nprogram.parse(process.argv);\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,CAAC;AAEV,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAA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Env.ts';\nloadEnv();\n\nimport minimist from 'minimist';\nimport { Command, Option } from '@commander-js/extra-typings';\nimport chalk from 'chalk';\nimport { Effect, Layer } from 'effect';\nimport version from './version.js';\nimport { initCommand } from './commands/init.ts';\nimport { initWithoutFilesCommand } from './commands/initWithoutFiles.ts';\nimport { loginCommand } from './commands/login.ts';\nimport { logoutCommand } from './commands/logout.ts';\nimport {\n AuthLayerLive,\n BaseLayerLive,\n runCommandEffect,\n WithAppLayer,\n} from './layer.ts';\nimport { infoCommand } from './commands/info.ts';\nimport { pullCommand } from './commands/pull.ts';\nimport type { SchemaPermsOrBoth } from './commands/pull.ts';\nimport { claimCommand } from './commands/claim.ts';\nimport { pushCommand } from './commands/push.ts';\nimport { explorerCmd } from './commands/explorer.ts';\nimport { queryCmd } from './commands/query.ts';\nimport { program } from './program.ts';\nimport { PACKAGE_ALIAS_AND_FULL_NAMES } from './context/projectInfo.ts';\nimport { authClientAddCmd } from './commands/auth/client/add.ts';\nimport { authClientListCmd } from './commands/auth/client/list.ts';\nimport { authClientDeleteCmd } from './commands/auth/client/delete.ts';\n\nexport type OptsFromCommand<C> =\n C extends Command<any, infer R, any> ? R : never;\n\nprogram\n .name('instant-cli')\n .addOption(globalOption('-t --token <token>', 'Auth token override'))\n .addOption(globalOption('-y --yes', \"Answer 'yes' to all prompts\"))\n .addOption(globalOption('--env <file>', 'Use a specific .env file'))\n .addOption(\n globalOption('-v --version', 'Print the version number', () => {\n console.log(version);\n process.exit(0);\n }),\n )\n .addHelpOption(globalOption('-h --help', 'Print the help text for a command'))\n .usage(`<command> ${chalk.dim('[options] [args]')}`);\n\n// Command List\nexport const initDef = program\n .command('init')\n .description('Set up a new project.')\n .option(\n '-a --app <app-id>',\n 'If you have an existing app ID, we can pull schema and perms from there.',\n )\n .option(\n '-p --package <react|react-native|core|admin|solid|svelte>',\n 'Which package to automatically install if there is not one installed already.',\n )\n .option('--title <title>', 'Title for the created app')\n .option(\n '--temp',\n 'Create a temporary app which will automatically delete itself after >24 hours.',\n )\n .action((options) => {\n return runCommandEffect(\n initCommand(options).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: true,\n coerceAuth: true,\n title: options.title,\n appId: options.app,\n packageName: options.package as any,\n applyEnv: true,\n temp: options.temp,\n }),\n ),\n ),\n );\n });\n\nconst auth = program.command('auth');\nconst authClient = auth.command('client');\nexport const authClientAddDef = authClient\n .command('add')\n .allowExcessArguments(true)\n .allowUnknownOption(true)\n .option('--type <google>', 'Type of oauth client to add')\n .option(\n '--name <client name>',\n 'Custom name to identify the OAuth client (ex: google-web)',\n )\n .option(\n '-a --app <app-id>',\n 'App ID to modify. Defaults to *_INSTANT_APP_ID in .env',\n )\n .addHelpText(\n 'after',\n `\nProvider Specific Options:\n Google:\n --app-type web|ios|android|button-for-web\n --client-id\n --client-secret (web only)\n --custom-redirect-uri (optional, web only)\n`,\n )\n .action((opts) => {\n opts = {\n ...opts,\n ...minimist(process.argv),\n };\n return runCommandEffect(\n authClientAddCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n coerceAuth: false,\n appId: opts.app,\n allowAdminToken: true,\n }),\n ),\n ),\n );\n });\nexport const authClientListDef = authClient\n .command('list')\n .option(\n '-a --app <app-id>',\n 'App ID to list clients for. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option('--json', 'Enable JSON output')\n .allowUnknownOption(true)\n .action((opts) => {\n return runCommandEffect(\n authClientListCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n coerceAuth: false,\n appId: opts.app,\n allowAdminToken: true,\n // Silence \"searching for instant sdk.. logs for json output\"\n }).pipe(Layer.annotateLogs('silent', !!opts.json)),\n ),\n ),\n );\n });\n\nexport const authClientDeleteDef = authClient\n .command('delete')\n .option('--id <client-id>', 'Client ID to delete')\n .option('--name <client-name>', 'Client name to delete')\n .option(\n '-a --app <app-id>',\n 'App ID to delete a client from. Defaults to *_INSTANT_APP_ID in .env',\n )\n .action((opts) => {\n return runCommandEffect(\n authClientDeleteCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n appId: opts.app,\n allowAdminToken: true,\n }),\n ),\n ),\n );\n });\n\nexport const initWithoutFilesDef = program\n .command('init-without-files')\n .description('Generate a new app id and admin token pair without any files.')\n .option('--title <title>', 'Title for the created app.')\n .option(\n '--org-id <org-id>',\n 'Organization id for app. Cannot be used with --temp flag.',\n )\n .option(\n '--temp',\n 'Create a temporary app which will automatically delete itself after >24 hours.',\n )\n .action((opts) => {\n return runCommandEffect(\n initWithoutFilesCommand(opts).pipe(Effect.provide(BaseLayerLive)),\n );\n });\n\nexport const loginDef = program\n .command('login')\n .description('Log into your account')\n .option('-p --print', 'Prints the auth token into the console.')\n .option(\n '--headless',\n 'Print the login URL instead of trying to open the browser',\n )\n .action(async (opts) => {\n await runCommandEffect(\n loginCommand(opts).pipe(Effect.provide(BaseLayerLive)),\n );\n });\n\nprogram\n .command('logout')\n .description('Log out of your Instant account')\n .action(async () => {\n return runCommandEffect(\n logoutCommand().pipe(Effect.provide(BaseLayerLive)),\n );\n });\n\nexport const infoDef = program\n .command('info')\n .description('Display CLI version and login status')\n .action(async () => {\n return runCommandEffect(\n infoCommand().pipe(\n Effect.provide(\n AuthLayerLive({\n coerce: false,\n allowAdminToken: false,\n }).pipe(Layer.catchAll(() => Layer.empty)), // make the auth layer optional\n ),\n ),\n );\n });\n\nexport const explorerDef = program\n .command('explorer')\n .description('Opens the Explorer in your browser')\n .option(\n '-a --app <app-id>',\n 'App ID to open the explorer to. Defaults to *_INSTANT_APP_ID in .env',\n )\n .action(async (opts) => {\n return runCommandEffect(\n explorerCmd(opts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: true,\n coerceAuth: true,\n appId: opts.app,\n }),\n ),\n ),\n );\n });\n\nexport const queryDef = program\n .command('query')\n .argument('<query>', 'InstaQL query as JSON/JSON5')\n .option(\n '-a --app <app-id>',\n 'App ID to query. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option('--admin', 'Run the query as admin (bypasses permissions)')\n .option('--as-email <email>', 'Run the query as a specific user by email')\n .option('--as-guest', 'Run the query as an unauthenticated guest')\n .option(\n '--as-token <refresh-token>',\n 'Run the query as a user identified by refresh token',\n )\n .description('Run an InstaQL query against your app.')\n .action(async function (queryArg, opts) {\n return runCommandEffect(queryCmd(queryArg, opts));\n });\n\nexport const pullDef = program\n .command('pull')\n .argument(\n '[schema|perms|all]',\n 'Which configuration to pull. Defaults to `all`',\n )\n .option(\n '-a --app <app-id>',\n 'App ID to pull to. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option(\n '-p --package <react|react-native|core|admin|solid|svelte>',\n 'Which package to automatically install if there is not one installed already.',\n )\n .option(\n '--experimental-type-preservation',\n \"[Experimental] Preserve manual type changes like `status: i.json<'online' | 'offline'>()` when doing `instant-cli pull schema`\",\n )\n .description('Pull schema and perm files from production.')\n .addHelpText(\n 'after',\n `\nEnvironment Variables:\n INSTANT_SCHEMA_FILE_PATH Override schema file location (default: instant.schema.ts)\n INSTANT_PERMS_FILE_PATH Override perms file location (default: instant.perms.ts)\n`,\n )\n .action(async function (arg, inputOpts) {\n return runCommandEffect(\n pullCommand(arg as SchemaPermsOrBoth, inputOpts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: true,\n packageName: inputOpts.package as\n | 'react'\n | 'react-native'\n | 'core'\n | 'admin'\n | undefined,\n appId: inputOpts.app,\n }),\n ),\n ),\n );\n });\n\nexport const pushDef = program\n .command('push')\n .argument(\n '[schema|perms|all]',\n 'Which configuration to push. Defaults to `all`',\n )\n .option(\n '-a --app <app-id>',\n 'App ID to push to. Defaults to *_INSTANT_APP_ID in .env',\n )\n .option(\n '--skip-check-types',\n \"Don't check types on the server when pushing schema\",\n )\n .option(\n '--rename [renames...]',\n 'List of full attribute names separated by a \":\"\\n Example:`push --rename posts.author:posts.creator stores.owner:stores.manager`',\n )\n .option(\n '-p --package <react|react-native|core|admin|solid|svelte>',\n 'Which package to automatically install if there is not one installed already.',\n )\n .description('Push schema and perm files to production.')\n .addHelpText(\n 'after',\n `\nEnvironment Variables:\n INSTANT_SCHEMA_FILE_PATH Override schema file location (default: instant.schema.ts)\n INSTANT_PERMS_FILE_PATH Override perms file location (default: instant.perms.ts)\n`,\n )\n .action(async function (arg, inputOpts) {\n return runCommandEffect(\n pushCommand(arg, inputOpts).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n appId: inputOpts.app,\n coerceLibraryInstall: true,\n coerceAuth: false,\n allowAdminToken: true,\n applyEnv: true,\n packageName:\n inputOpts.package as keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES,\n }),\n ),\n ),\n );\n });\n\nexport const claimDef = program\n .command('claim')\n .description('Transfer a temporary app into your Instant account')\n .option(\n '-a --app <app-id>',\n 'App to claim. Defaults to *_INSTANT_APP_ID in .env',\n )\n .action(async function (opts) {\n return runCommandEffect(\n claimCommand.pipe(\n Effect.provide(\n WithAppLayer({\n coerce: false,\n allowAdminToken: false,\n appId: opts.app,\n applyEnv: false,\n }),\n ),\n ),\n );\n });\n//// Program setup /////\n\nfunction globalOption(\n flags: string,\n description?: string,\n argParser?: (value: string, prev?: unknown) => unknown,\n) {\n const opt = new Option(flags, description);\n if (argParser) {\n opt.argParser(argParser);\n }\n // @ts-ignore\n // __global does not exist on `Option`,\n // but we use it in `getLocalAndGlobalOptions`, to produce\n // our own custom list of local and global options.\n // For more info, see the original PR:\n // https://github.com/instantdb/instant/pull/505\n opt.__global = true;\n return opt;\n}\n\nfunction getLocalAndGlobalOptions(cmd: any, helper: any) {\n const mixOfLocalAndGlobal = helper.visibleOptions(cmd);\n const localOptionsFromMix = mixOfLocalAndGlobal.filter(\n (option: any) => !option.__global,\n );\n const globalOptionsFromMix = mixOfLocalAndGlobal.filter(\n (option: any) => option.__global,\n );\n const globalOptions = helper.visibleGlobalOptions(cmd);\n\n return [localOptionsFromMix, globalOptionsFromMix.concat(globalOptions)];\n}\n\nfunction formatHelp(\n this: { showGlobalOptions: boolean },\n cmd: any,\n helper: any,\n) {\n const termWidth = helper.padWidth(cmd, helper);\n const helpWidth = helper.helpWidth || 80;\n const itemIndentWidth = 2;\n const itemSeparatorWidth = 2; // between term and description\n function formatItem(term: string, description: string | undefined) {\n if (description) {\n const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;\n return helper.boxWrap(\n fullText,\n helpWidth - itemIndentWidth,\n termWidth + itemSeparatorWidth,\n );\n }\n return term;\n }\n function formatList(textArray: string[]) {\n return textArray.join('\\n').replace(/^/gm, ' '.repeat(itemIndentWidth));\n }\n\n // Usage\n let output = [`${helper.commandUsage(cmd)}`, ''];\n\n // Description\n const commandDescription = helper.commandDescription(cmd);\n if (commandDescription.length > 0) {\n output = output.concat([\n helper.boxWrap(commandDescription, helpWidth, 0),\n '',\n ]);\n }\n\n // Arguments\n const argumentList = helper.visibleArguments(cmd).map((argument: any) => {\n return formatItem(\n helper.argumentTerm(argument),\n helper.argumentDescription(argument),\n );\n });\n if (argumentList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Arguments'),\n formatList(argumentList),\n '',\n ]);\n }\n const [visibleOptions, visibleGlobalOptions] = getLocalAndGlobalOptions(\n cmd,\n helper,\n );\n\n // Options\n const optionList = visibleOptions.map((option: any) => {\n return formatItem(\n helper.optionTerm(option),\n helper.optionDescription(option),\n );\n });\n if (optionList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Options'),\n formatList(optionList),\n '',\n ]);\n }\n // Commands\n const commandList = helper.visibleCommands(cmd).map((cmd: any) => {\n return formatItem(\n helper.subcommandTerm(cmd),\n helper.subcommandDescription(cmd),\n );\n });\n if (commandList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Commands'),\n formatList(commandList),\n '',\n ]);\n }\n\n if (this.showGlobalOptions) {\n const globalOptionList = visibleGlobalOptions.map((option: any) => {\n return formatItem(\n helper.optionTerm(option),\n helper.optionDescription(option),\n );\n });\n if (globalOptionList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Global Options'),\n formatList(globalOptionList),\n '',\n ]);\n }\n }\n\n return output.join('\\n');\n}\n\nprogram.configureHelp({\n showGlobalOptions: true,\n formatHelp,\n});\n\nprogram.parse(process.argv);\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instant-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.6
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"description": "Instant's CLI",
|
|
6
6
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/cli",
|
|
7
7
|
"repository": {
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"strip-ansi": "^7.1.2",
|
|
50
50
|
"terminal-link": "^3.0.0",
|
|
51
51
|
"unconfig": "^0.5.5",
|
|
52
|
-
"@instantdb/core": "1.0.6
|
|
53
|
-
"@instantdb/platform": "1.0.6
|
|
54
|
-
"@instantdb/version": "1.0.6
|
|
52
|
+
"@instantdb/core": "1.0.6",
|
|
53
|
+
"@instantdb/platform": "1.0.6",
|
|
54
|
+
"@instantdb/version": "1.0.6"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@babel/core": "^7.17.9",
|
|
@@ -22,11 +22,12 @@ import {
|
|
|
22
22
|
import { UI } from '../../../ui/index.ts';
|
|
23
23
|
import chalk from 'chalk';
|
|
24
24
|
import boxen from 'boxen';
|
|
25
|
+
import { redirect } from '@effect/platform/HttpServerResponse';
|
|
25
26
|
|
|
26
27
|
const ClientTypeSchema = Schema.Literal(
|
|
27
28
|
'google',
|
|
28
|
-
'github',
|
|
29
29
|
// 'apple',
|
|
30
|
+
// 'github',
|
|
30
31
|
// 'linkedin',
|
|
31
32
|
// 'clerk',
|
|
32
33
|
// 'firebase',
|
|
@@ -239,134 +240,8 @@ ${chalk.dim('Your URI must forward to https://api.instantdb.com/runtime/oauth/ca
|
|
|
239
240
|
[
|
|
240
241
|
`Google OAuth client created: ${response.client.client_name}`,
|
|
241
242
|
`App type: ${appType}`,
|
|
242
|
-
`
|
|
243
|
-
`Google
|
|
244
|
-
...redirectMessages,
|
|
245
|
-
].join('\n'),
|
|
246
|
-
{ dimBorder: true, padding: { right: 1, left: 1 } },
|
|
247
|
-
),
|
|
248
|
-
);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
const GITHUB_DEFAULT_CALLBACK_URL =
|
|
252
|
-
'https://api.instantdb.com/runtime/oauth/callback';
|
|
253
|
-
|
|
254
|
-
const handleGithubClient = Effect.fn(function* (opts: Record<string, unknown>) {
|
|
255
|
-
const { auth, provider } = yield* getOrCreateProvider('github');
|
|
256
|
-
const usedClientNames = new Set(
|
|
257
|
-
(auth.oauth_clients ?? []).map((client) => client.client_name),
|
|
258
|
-
);
|
|
259
|
-
const suggestedClientName = findName('github-web', usedClientNames);
|
|
260
|
-
|
|
261
|
-
const clientName = yield* optOrPrompt(opts.name, {
|
|
262
|
-
simpleName: '--name',
|
|
263
|
-
required: true,
|
|
264
|
-
skipIf: false,
|
|
265
|
-
prompt: {
|
|
266
|
-
prompt: 'Client Name:',
|
|
267
|
-
defaultValue: suggestedClientName,
|
|
268
|
-
placeholder: suggestedClientName,
|
|
269
|
-
validate: validateRequired,
|
|
270
|
-
modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),
|
|
271
|
-
},
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
if (usedClientNames.has(clientName || '')) {
|
|
275
|
-
return yield* BadArgsError.make({
|
|
276
|
-
message: `The unique name '${clientName}' is already in use.`,
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const clientId = yield* optOrPrompt(opts['client-id'], {
|
|
281
|
-
simpleName: '--client-id',
|
|
282
|
-
required: true,
|
|
283
|
-
skipIf: false,
|
|
284
|
-
prompt: {
|
|
285
|
-
prompt: `Client ID ${chalk.dim('(from https://github.com/settings/developers)')}`,
|
|
286
|
-
modifyOutput: UI.modifiers.piped([
|
|
287
|
-
UI.modifiers.topPadding,
|
|
288
|
-
UI.modifiers.dimOnComplete,
|
|
289
|
-
]),
|
|
290
|
-
validate: validateRequired,
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
const clientSecret = yield* optOrPrompt(opts['client-secret'], {
|
|
295
|
-
required: true,
|
|
296
|
-
skipIf: false,
|
|
297
|
-
simpleName: '--client-secret',
|
|
298
|
-
prompt: {
|
|
299
|
-
prompt: `Client Secret: ${chalk.dim('(from https://github.com/settings/developers)')}`,
|
|
300
|
-
validate: validateRequired,
|
|
301
|
-
sensitive: true,
|
|
302
|
-
modifyOutput: UI.modifiers.piped([
|
|
303
|
-
UI.modifiers.topPadding,
|
|
304
|
-
UI.modifiers.dimOnComplete,
|
|
305
|
-
]),
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
const customRedirectUri = yield* optOrPrompt(opts['custom-redirect-uri'], {
|
|
310
|
-
required: false,
|
|
311
|
-
simpleName: '--custom-redirect-uri',
|
|
312
|
-
skipIf: false,
|
|
313
|
-
prompt: {
|
|
314
|
-
prompt: '',
|
|
315
|
-
placeholder: 'https://yoursite.com/oauth/callback',
|
|
316
|
-
modifyOutput: UI.modifiers.piped([
|
|
317
|
-
(output, status) => {
|
|
318
|
-
if (status === 'idle') {
|
|
319
|
-
return (
|
|
320
|
-
`\nCustom redirect URI (optional):
|
|
321
|
-
${chalk.dim('With a custom redirect URI, users will see "Redirecting to yoursite.com..." for a more branded experience.')}
|
|
322
|
-
${chalk.dim('Your URI must forward to https://api.instantdb.com/runtime/oauth/callback with all query parameters preserved.')}\n\n` +
|
|
323
|
-
stripFirstBlankLine(output)
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
return `\nCustom redirect URI (optional):\n${stripFirstBlankLine(output)}`;
|
|
327
|
-
},
|
|
328
|
-
UI.modifiers.dimOnComplete,
|
|
329
|
-
]),
|
|
330
|
-
},
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
if (!clientName) {
|
|
334
|
-
return yield* BadArgsError.make({ message: 'Client name is required.' });
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const redirectUri = customRedirectUri || GITHUB_DEFAULT_CALLBACK_URL;
|
|
338
|
-
|
|
339
|
-
// The backend infers GitHub's authorization/token endpoints from
|
|
340
|
-
// meta.providerName === 'github', so we don't pass them here.
|
|
341
|
-
const response = yield* addOAuthClient({
|
|
342
|
-
providerId: provider.id,
|
|
343
|
-
clientName,
|
|
344
|
-
clientId,
|
|
345
|
-
clientSecret,
|
|
346
|
-
redirectTo: redirectUri,
|
|
347
|
-
meta: { providerName: 'github' },
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
const redirectMessages: string[] = [
|
|
351
|
-
chalk.bold(
|
|
352
|
-
`\nAdd this callback URL in your GitHub OAuth App settings:\n${redirectUri}\n`,
|
|
353
|
-
),
|
|
354
|
-
];
|
|
355
|
-
if (customRedirectUri) {
|
|
356
|
-
redirectMessages.push(
|
|
357
|
-
`Your custom redirect must forward to ${chalk.bold(GITHUB_DEFAULT_CALLBACK_URL)} with all query parameters preserved.`,
|
|
358
|
-
);
|
|
359
|
-
redirectMessages.push(
|
|
360
|
-
`You can test it by visiting: ${chalk.bold(redirectUri + '?test-redirect=true')}`,
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
yield* Effect.log(
|
|
365
|
-
boxen(
|
|
366
|
-
[
|
|
367
|
-
`GitHub OAuth client created: ${response.client.client_name}`,
|
|
368
|
-
`ID: ${response.client.id}`,
|
|
369
|
-
`GitHub Client ID: ${response.client.client_id ?? clientId}`,
|
|
243
|
+
`Client database id: ${response.client.id}`,
|
|
244
|
+
`Google client id: ${response.client.client_id ?? clientId}`,
|
|
370
245
|
...redirectMessages,
|
|
371
246
|
].join('\n'),
|
|
372
247
|
{ dimBorder: true, padding: { right: 1, left: 1 } },
|
|
@@ -390,9 +265,9 @@ export const authClientAddCmd = Effect.fn(
|
|
|
390
265
|
new UI.Select({
|
|
391
266
|
options: [
|
|
392
267
|
{ label: 'Google', value: 'google' },
|
|
393
|
-
{ label: 'GitHub', value: 'github' },
|
|
394
268
|
// TODO: implement
|
|
395
269
|
// { label: 'Apple', value: 'apple' },
|
|
270
|
+
// { label: 'GitHub', value: 'github' },
|
|
396
271
|
// { label: 'LinkedIn', value: 'linkedin' },
|
|
397
272
|
// { label: 'Clerk', value: 'clerk' },
|
|
398
273
|
// { label: 'Firebase', value: 'firebase' },
|
|
@@ -414,9 +289,9 @@ export const authClientAddCmd = Effect.fn(
|
|
|
414
289
|
yield* Match.value(clientType).pipe(
|
|
415
290
|
Match.withReturnType<Effect.Effect<void, any, any>>(),
|
|
416
291
|
Match.when('google', () => handleGoogleClient(opts)),
|
|
417
|
-
Match.when('github', () => handleGithubClient(opts)),
|
|
418
292
|
// Match.when('apple', () => Effect.logError('Not Implemented')),
|
|
419
293
|
// Match.when('clerk', () => Effect.logError('Not Implemented')),
|
|
294
|
+
// Match.when('github', () => Effect.logError('Not Implemented')),
|
|
420
295
|
// Match.when('firebase', () => Effect.logError('Not Implemented')),
|
|
421
296
|
// Match.when('linkedin', () => Effect.logError('Not Implemented')),
|
|
422
297
|
Match.exhaustive,
|
package/src/index.ts
CHANGED
|
@@ -87,7 +87,7 @@ export const authClientAddDef = authClient
|
|
|
87
87
|
.command('add')
|
|
88
88
|
.allowExcessArguments(true)
|
|
89
89
|
.allowUnknownOption(true)
|
|
90
|
-
.option('--type <google
|
|
90
|
+
.option('--type <google>', 'Type of oauth client to add')
|
|
91
91
|
.option(
|
|
92
92
|
'--name <client name>',
|
|
93
93
|
'Custom name to identify the OAuth client (ex: google-web)',
|
|
@@ -105,10 +105,6 @@ Provider Specific Options:
|
|
|
105
105
|
--client-id
|
|
106
106
|
--client-secret (web only)
|
|
107
107
|
--custom-redirect-uri (optional, web only)
|
|
108
|
-
GitHub:
|
|
109
|
-
--client-id
|
|
110
|
-
--client-secret
|
|
111
|
-
--custom-redirect-uri (optional)
|
|
112
108
|
`,
|
|
113
109
|
)
|
|
114
110
|
.action((opts) => {
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { test, expect, describe, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { Effect, Layer, Logger } from 'effect';
|
|
3
|
-
import { GlobalOpts } from '../src/context/globalOpts.ts';
|
|
4
|
-
import { CurrentApp } from '../src/context/currentApp.ts';
|
|
5
|
-
import { InstantHttpAuthed } from '../src/lib/http.ts';
|
|
6
|
-
|
|
7
|
-
// -- mocks --
|
|
8
|
-
|
|
9
|
-
// Prevent src/index.ts side-effect (program.parse) from running.
|
|
10
|
-
// add.ts has `import type` from index.ts, but vitest still evaluates it.
|
|
11
|
-
vi.mock('../src/index.ts', () => ({}));
|
|
12
|
-
|
|
13
|
-
let prompts: any[] = [];
|
|
14
|
-
let mockPromptReturn: any = '';
|
|
15
|
-
|
|
16
|
-
vi.mock('../src/ui/lib.ts', async (importOriginal) => {
|
|
17
|
-
const orig: any = await importOriginal();
|
|
18
|
-
return {
|
|
19
|
-
...orig,
|
|
20
|
-
renderUnwrap: (prompt: any) => {
|
|
21
|
-
prompts.push(prompt);
|
|
22
|
-
return Promise.resolve(mockPromptReturn);
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
let addedClients: any[] = [];
|
|
28
|
-
|
|
29
|
-
vi.mock('../src/lib/oauth.ts', () => ({
|
|
30
|
-
getAppsAuth: () =>
|
|
31
|
-
Effect.succeed({
|
|
32
|
-
oauth_service_providers: [{ id: 'prov-1', provider_name: 'github' }],
|
|
33
|
-
oauth_clients: [],
|
|
34
|
-
}),
|
|
35
|
-
addOAuthProvider: () =>
|
|
36
|
-
Effect.succeed({
|
|
37
|
-
provider: { id: 'prov-1', provider_name: 'github' },
|
|
38
|
-
}),
|
|
39
|
-
addOAuthClient: (params: any) => {
|
|
40
|
-
addedClients.push(params);
|
|
41
|
-
return Effect.succeed({
|
|
42
|
-
client: {
|
|
43
|
-
id: 'client-1',
|
|
44
|
-
client_name: params.clientName,
|
|
45
|
-
client_id: params.clientId,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
}));
|
|
50
|
-
|
|
51
|
-
// Lazy import so mocks are in place
|
|
52
|
-
const { authClientAddCmd } = await import('../src/commands/auth/client/add.ts');
|
|
53
|
-
|
|
54
|
-
// -- helpers --
|
|
55
|
-
|
|
56
|
-
let logs: string[] = [];
|
|
57
|
-
|
|
58
|
-
const run = (flags: Map<string, string>, { yes }: { yes: boolean }) =>
|
|
59
|
-
Effect.runPromise(
|
|
60
|
-
authClientAddCmd(Object.fromEntries(flags) as any).pipe(
|
|
61
|
-
Effect.provide(
|
|
62
|
-
Layer.mergeAll(
|
|
63
|
-
Layer.succeed(GlobalOpts, { yes }),
|
|
64
|
-
Layer.succeed(CurrentApp, { appId: 'test-app', source: 'env' }),
|
|
65
|
-
Layer.succeed(InstantHttpAuthed, {} as any),
|
|
66
|
-
Logger.replace(
|
|
67
|
-
Logger.defaultLogger,
|
|
68
|
-
Logger.make(({ message }) => {
|
|
69
|
-
logs.push(String(message));
|
|
70
|
-
}),
|
|
71
|
-
),
|
|
72
|
-
),
|
|
73
|
-
),
|
|
74
|
-
),
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const without = (flags: Map<string, string>, key: string) => {
|
|
78
|
-
const copy = new Map(flags);
|
|
79
|
-
copy.delete(key);
|
|
80
|
-
return copy;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const withEntry = (flags: Map<string, string>, key: string, value: string) =>
|
|
84
|
-
new Map([...flags, [key, value]]);
|
|
85
|
-
|
|
86
|
-
beforeEach(() => {
|
|
87
|
-
prompts = [];
|
|
88
|
-
addedClients = [];
|
|
89
|
-
logs = [];
|
|
90
|
-
mockPromptReturn = '';
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// -- flag sets --
|
|
94
|
-
|
|
95
|
-
const webFlags = new Map([
|
|
96
|
-
['type', 'github'],
|
|
97
|
-
['name', 'github-web'],
|
|
98
|
-
['client-id', 'Iv1.abc123'],
|
|
99
|
-
['client-secret', 'ghs_abc123'],
|
|
100
|
-
]);
|
|
101
|
-
|
|
102
|
-
// -- --yes: build-up errors on each missing required flag --
|
|
103
|
-
|
|
104
|
-
describe('--yes errors on each missing required flag', () => {
|
|
105
|
-
test('missing --type', async () => {
|
|
106
|
-
await run(without(webFlags, 'type'), { yes: true });
|
|
107
|
-
expect(logs.join('\n')).toContain('Missing required value for --type');
|
|
108
|
-
expect(addedClients).toHaveLength(0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('missing --name', async () => {
|
|
112
|
-
await run(without(webFlags, 'name'), { yes: true });
|
|
113
|
-
expect(logs.join('\n')).toContain('Missing required value for --name');
|
|
114
|
-
expect(addedClients).toHaveLength(0);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('missing --client-id', async () => {
|
|
118
|
-
await run(without(webFlags, 'client-id'), { yes: true });
|
|
119
|
-
expect(logs.join('\n')).toContain('Missing required value for --client-id');
|
|
120
|
-
expect(addedClients).toHaveLength(0);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('missing --client-secret', async () => {
|
|
124
|
-
await run(without(webFlags, 'client-secret'), { yes: true });
|
|
125
|
-
expect(logs.join('\n')).toContain(
|
|
126
|
-
'Missing required value for --client-secret',
|
|
127
|
-
);
|
|
128
|
-
expect(addedClients).toHaveLength(0);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// -- interactive prompts for each missing flag --
|
|
133
|
-
|
|
134
|
-
describe('interactive prompts for each missing flag', () => {
|
|
135
|
-
test('missing --type → prompts type selector', async () => {
|
|
136
|
-
mockPromptReturn = 'github';
|
|
137
|
-
await run(without(webFlags, 'type'), { yes: false });
|
|
138
|
-
expect((prompts[0] as any).params.promptText).toBe('Select a client type:');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('missing --name → prompts for name', async () => {
|
|
142
|
-
mockPromptReturn = 'github-web';
|
|
143
|
-
await run(without(webFlags, 'name'), { yes: false });
|
|
144
|
-
expect((prompts[0] as any).props.prompt).toBe('Client Name:');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('missing --client-id → prompts for client id', async () => {
|
|
148
|
-
mockPromptReturn = 'Iv1.abc123';
|
|
149
|
-
await run(without(webFlags, 'client-id'), { yes: false });
|
|
150
|
-
expect((prompts[0] as any).props.prompt).toContain('Client ID');
|
|
151
|
-
expect((prompts[0] as any).props.prompt).toContain(
|
|
152
|
-
'github.com/settings/developers',
|
|
153
|
-
);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('missing --client-secret → prompts for client secret', async () => {
|
|
157
|
-
mockPromptReturn = 'ghs_abc123';
|
|
158
|
-
await run(without(webFlags, 'client-secret'), { yes: false });
|
|
159
|
-
expect((prompts[0] as any).props.prompt).toContain('Client Secret:');
|
|
160
|
-
expect((prompts[0] as any).props.sensitive).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('custom-redirect-uri → prompts when omitted', async () => {
|
|
164
|
-
mockPromptReturn = '';
|
|
165
|
-
await run(webFlags, { yes: false });
|
|
166
|
-
expect(prompts).toHaveLength(1);
|
|
167
|
-
expect((prompts[0] as any).props.placeholder).toBe(
|
|
168
|
-
'https://yoursite.com/oauth/callback',
|
|
169
|
-
);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('custom-redirect-uri → skipped with --yes', async () => {
|
|
173
|
-
await run(webFlags, { yes: true });
|
|
174
|
-
expect(prompts).toHaveLength(0);
|
|
175
|
-
expect(addedClients).toHaveLength(1);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
// -- success cases --
|
|
180
|
-
|
|
181
|
-
describe('success', () => {
|
|
182
|
-
test('all required flags → creates client and prints callback URL', async () => {
|
|
183
|
-
await run(webFlags, { yes: true });
|
|
184
|
-
expect(addedClients).toHaveLength(1);
|
|
185
|
-
expect(addedClients[0]).toMatchObject({
|
|
186
|
-
clientName: 'github-web',
|
|
187
|
-
clientId: 'Iv1.abc123',
|
|
188
|
-
clientSecret: 'ghs_abc123',
|
|
189
|
-
redirectTo: 'https://api.instantdb.com/runtime/oauth/callback',
|
|
190
|
-
meta: { providerName: 'github' },
|
|
191
|
-
});
|
|
192
|
-
expect(addedClients[0].authorizationEndpoint).toBeUndefined();
|
|
193
|
-
expect(addedClients[0].tokenEndpoint).toBeUndefined();
|
|
194
|
-
expect(addedClients[0].discoveryEndpoint).toBeUndefined();
|
|
195
|
-
const output = logs.join('\n');
|
|
196
|
-
expect(output).toContain(
|
|
197
|
-
'Add this callback URL in your GitHub OAuth App settings:',
|
|
198
|
-
);
|
|
199
|
-
expect(output).toContain(
|
|
200
|
-
'https://api.instantdb.com/runtime/oauth/callback',
|
|
201
|
-
);
|
|
202
|
-
expect(output).toContain('GitHub OAuth client created: github-web');
|
|
203
|
-
expect(output).toContain('ID: client-1');
|
|
204
|
-
expect(output).toContain('GitHub Client ID: Iv1.abc123');
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
test('with custom-redirect-uri → uses it and prints forwarding instructions', async () => {
|
|
208
|
-
await run(
|
|
209
|
-
withEntry(webFlags, 'custom-redirect-uri', 'https://myapp.com/cb'),
|
|
210
|
-
{ yes: true },
|
|
211
|
-
);
|
|
212
|
-
expect(addedClients[0].redirectTo).toBe('https://myapp.com/cb');
|
|
213
|
-
const output = logs.join('\n');
|
|
214
|
-
expect(output).toContain(
|
|
215
|
-
'Add this callback URL in your GitHub OAuth App settings:',
|
|
216
|
-
);
|
|
217
|
-
expect(output).toContain('https://myapp.com/cb');
|
|
218
|
-
expect(output).toContain(
|
|
219
|
-
'https://api.instantdb.com/runtime/oauth/callback with all query parameters',
|
|
220
|
-
);
|
|
221
|
-
expect(output).toContain('https://myapp.com/cb?test-redirect=true');
|
|
222
|
-
});
|
|
223
|
-
});
|