instant-cli 0.22.95-experimental.surgical.20386947966.1 → 0.22.96-experimental.add-posthog-frontend.20386914944.1

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > instant-cli@0.22.95-experimental.surgical.20386947966.1 build /home/runner/work/instant/instant/client/packages/cli
2
+ > instant-cli@0.22.96-experimental.add-posthog-frontend.20386914944.1 build /home/runner/work/instant/instant/client/packages/cli
3
3
  > rm -rf dist; tsc -p tsconfig.json
4
4
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA68DA,8EAQC;AA+ED;;;;;EAKE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAq8DA,8EAQC;AA+ED;;;;;EAKE"}
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  // @ts-check
11
11
  import { generatePermsTypescriptFile, apiSchemaToInstantSchemaDef, generateSchemaTypescriptFile, diffSchemas, convertTxSteps, validateSchema, SchemaValidationError, PlatformApi, } from '@instantdb/platform';
12
12
  import version from './version.js';
13
+ import { existsSync } from 'fs';
13
14
  import { mkdir, writeFile, readFile, unlink } from 'fs/promises';
14
15
  import path, { join } from 'path';
15
16
  import { randomUUID } from 'crypto';
@@ -37,7 +38,6 @@ import { buildAutoRenameSelector } from './rename.js';
37
38
  import { loadEnv } from './util/loadEnv.js';
38
39
  import { isHeadlessEnvironment } from './util/isHeadlessEnvironment.js';
39
40
  import { getSchemaReadCandidates, getPermsReadCandidates, getSchemaPathToWrite, getPermsPathToWrite, } from './util/findConfigCandidates.js';
40
- import { updateSchemaFile } from './util/updateSchemaFile.js';
41
41
  const execAsync = promisify(exec);
42
42
  loadEnv();
43
43
  const dev = Boolean(process.env.INSTANT_CLI_DEV);
@@ -353,7 +353,6 @@ program
353
353
  .argument('[schema|perms|all]', 'Which configuration to push. Defaults to `all`')
354
354
  .option('-a --app <app-id>', 'App ID to push to. Defaults to *_INSTANT_APP_ID in .env')
355
355
  .option('-p --package <react|react-native|core|admin>', 'Which package to automatically install if there is not one installed already.')
356
- .option('--experimental-type-preservation', '[Experimental] Preserve manual type changes and schema edits when pulling schema')
357
356
  .description('Pull schema and perm files from production.')
358
357
  .addHelpText('after', `
359
358
  Environment Variables:
@@ -505,7 +504,7 @@ function handlePull(bag, opts) {
505
504
  error('No app ID detected. Please specify one with --app or set up with `instant-cli init`');
506
505
  return;
507
506
  }
508
- yield pull(bag, appId, Object.assign(Object.assign({}, pkgAndAuthInfo), opts));
507
+ yield pull(bag, appId, pkgAndAuthInfo);
509
508
  });
510
509
  }
511
510
  function push(bag, appId, opts) {
@@ -608,6 +607,7 @@ function login(options) {
608
607
  debugName: 'Login register',
609
608
  errorMessage: 'Failed to register login.',
610
609
  noAuth: true,
610
+ command: 'login',
611
611
  });
612
612
  if (!registerRes.ok) {
613
613
  return process.exit(1);
@@ -741,6 +741,7 @@ function promptCreateApp(opts) {
741
741
  method: 'GET',
742
742
  path: '/dash',
743
743
  errorMessage: 'Failed to fetch apps.',
744
+ command: 'init',
744
745
  });
745
746
  if (!res.ok) {
746
747
  return { ok: false };
@@ -767,6 +768,7 @@ function promptCreateApp(opts) {
767
768
  debugName: 'App create',
768
769
  errorMessage: 'Failed to create app.',
769
770
  body: app,
771
+ command: 'init',
770
772
  });
771
773
  if (!appRes.ok)
772
774
  return { ok: false };
@@ -786,6 +788,7 @@ function promptImportAppOrCreateApp() {
786
788
  method: 'GET',
787
789
  path: '/dash',
788
790
  errorMessage: 'Failed to fetch apps.',
791
+ command: 'init',
789
792
  });
790
793
  if (!res.ok) {
791
794
  return { ok: false };
@@ -803,6 +806,7 @@ function promptImportAppOrCreateApp() {
803
806
  method: 'GET',
804
807
  path: `/dash/orgs/${orgId}`,
805
808
  errorMessage: 'Failed to fetch apps.',
809
+ command: 'init',
806
810
  });
807
811
  if (!orgsRes.ok) {
808
812
  throw new Error('Failed to fetch org apps');
@@ -831,6 +835,7 @@ function createApp(title, orgId) {
831
835
  debugName: 'App create',
832
836
  errorMessage: 'Failed to create app.',
833
837
  body: app,
838
+ command: 'init',
834
839
  });
835
840
  if (!appRes.ok)
836
841
  throw new Error('Failed to create app');
@@ -989,12 +994,13 @@ function getOrPromptPackageAndAuthInfoWithErrorLogging(opts) {
989
994
  });
990
995
  }
991
996
  function pullSchema(appId_1, _a) {
992
- return __awaiter(this, arguments, void 0, function* (appId, { pkgDir, instantModuleName, experimentalTypePreservation }) {
997
+ return __awaiter(this, arguments, void 0, function* (appId, { pkgDir, instantModuleName }) {
993
998
  console.log('Pulling schema...');
994
999
  const pullRes = yield fetchJson({
995
1000
  path: `/dash/apps/${appId}/schema/pull`,
996
1001
  debugName: 'Schema pull',
997
1002
  errorMessage: 'Failed to pull schema.',
1003
+ command: 'pull',
998
1004
  });
999
1005
  if (!pullRes.ok)
1000
1006
  return pullRes;
@@ -1016,21 +1022,7 @@ function pullSchema(appId_1, _a) {
1016
1022
  }
1017
1023
  const shortSchemaPath = getSchemaPathToWrite(prev === null || prev === void 0 ? void 0 : prev.path);
1018
1024
  const schemaPath = join(pkgDir, shortSchemaPath);
1019
- const serverSchema = apiSchemaToInstantSchemaDef(pullRes.data.schema);
1020
- let newSchemaContent;
1021
- if (prev && experimentalTypePreservation) {
1022
- try {
1023
- const oldSchemaContent = yield readFile(prev.path, 'utf-8');
1024
- newSchemaContent = yield updateSchemaFile(oldSchemaContent, prev.schema, serverSchema);
1025
- }
1026
- catch (e) {
1027
- warn('Failed to update schema with existing file. Overwriting instead.', e);
1028
- }
1029
- }
1030
- if (!newSchemaContent) {
1031
- newSchemaContent = generateSchemaTypescriptFile(prev === null || prev === void 0 ? void 0 : prev.schema, serverSchema, instantModuleName);
1032
- }
1033
- yield writeTypescript(schemaPath, newSchemaContent, 'utf-8');
1025
+ yield writeTypescript(schemaPath, generateSchemaTypescriptFile(prev === null || prev === void 0 ? void 0 : prev.schema, apiSchemaToInstantSchemaDef(pullRes.data.schema), instantModuleName), 'utf-8');
1034
1026
  console.log('✅ Wrote schema to ' + shortSchemaPath);
1035
1027
  return { ok: true };
1036
1028
  });
@@ -1042,6 +1034,7 @@ function pullPerms(appId_1, _a) {
1042
1034
  path: `/dash/apps/${appId}/perms/pull`,
1043
1035
  debugName: 'Perms pull',
1044
1036
  errorMessage: 'Failed to pull perms.',
1037
+ command: 'pull',
1045
1038
  });
1046
1039
  if (!pullRes.ok)
1047
1040
  return pullRes;
@@ -1257,6 +1250,7 @@ function waitForIndexingJobsToFinish(appId, data) {
1257
1250
  method: 'GET',
1258
1251
  path: `/dash/apps/${appId}/indexing-jobs/group/${groupId}`,
1259
1252
  errorMessage: 'Failed to check indexing status.',
1253
+ command: 'push',
1260
1254
  });
1261
1255
  if (!res.ok) {
1262
1256
  break;
@@ -1311,6 +1305,7 @@ function pushSchema(appId, opts) {
1311
1305
  path: `/dash/apps/${appId}/schema/pull`,
1312
1306
  debugName: 'Schema plan',
1313
1307
  errorMessage: 'Failed to get old schema.',
1308
+ command: 'push',
1314
1309
  });
1315
1310
  if (!pulledSchemaResponse.ok)
1316
1311
  return pulledSchemaResponse;
@@ -1386,6 +1381,7 @@ function pushSchema(appId, opts) {
1386
1381
  body: {
1387
1382
  steps: txSteps,
1388
1383
  },
1384
+ command: 'push',
1389
1385
  });
1390
1386
  console.log(chalk.green('Schema updated!'));
1391
1387
  if (!applyRes.ok)
@@ -1411,6 +1407,7 @@ function claimEphemeralApp(appId, adminToken) {
1411
1407
  path: `/dash/apps/ephemeral/${appId}/claim`,
1412
1408
  debugName: 'Claim ephemeral app',
1413
1409
  errorMessage: 'Failed to claim ephemeral app.',
1410
+ command: 'claim',
1414
1411
  });
1415
1412
  if (!res.ok)
1416
1413
  return res;
@@ -1429,6 +1426,7 @@ function pushPerms(appId) {
1429
1426
  path: `/dash/apps/${appId}/perms/pull`,
1430
1427
  debugName: 'Perms pull',
1431
1428
  errorMessage: 'Failed to pull perms.',
1429
+ command: 'push',
1432
1430
  });
1433
1431
  if (!prodPerms.ok)
1434
1432
  return prodPerms;
@@ -1460,6 +1458,7 @@ function pushPerms(appId) {
1460
1458
  body: {
1461
1459
  code: res.perms,
1462
1460
  },
1461
+ command: 'push',
1463
1462
  });
1464
1463
  if (!permsRes.ok)
1465
1464
  return permsRes;
@@ -1480,6 +1479,7 @@ function waitForAuthToken(_a) {
1480
1479
  body: { secret },
1481
1480
  noAuth: true,
1482
1481
  noLogError: true,
1482
+ command: 'login',
1483
1483
  });
1484
1484
  if (authCheckRes.ok) {
1485
1485
  return authCheckRes.data;
@@ -1507,10 +1507,11 @@ function waitForAuthToken(_a) {
1507
1507
  * @param {Object} [options.body=undefined]
1508
1508
  * @param {boolean} [options.noAuth]
1509
1509
  * @param {boolean} [options.noLogError]
1510
+ * @param {string} [options.command] - The CLI command being executed (e.g., 'push', 'pull', 'login')
1510
1511
  * @returns {Promise<{ ok: boolean; data: any }>}
1511
1512
  */
1512
1513
  function fetchJson(_a) {
1513
- return __awaiter(this, arguments, void 0, function* ({ debugName, errorMessage, path, body, method, noAuth, noLogError, }) {
1514
+ return __awaiter(this, arguments, void 0, function* ({ debugName, errorMessage, path, body, method, noAuth, noLogError, command, }) {
1514
1515
  const withAuth = !noAuth;
1515
1516
  const withErrorLogging = !noLogError;
1516
1517
  let authToken = null;
@@ -1524,7 +1525,7 @@ function fetchJson(_a) {
1524
1525
  try {
1525
1526
  const res = yield fetch(`${instantBackendOrigin}${path}`, {
1526
1527
  method: method !== null && method !== void 0 ? method : 'GET',
1527
- headers: Object.assign(Object.assign({}, (withAuth ? { Authorization: `Bearer ${authToken}` } : {})), { 'Content-Type': 'application/json', 'Instant-CLI-Version': version }),
1528
+ headers: Object.assign(Object.assign(Object.assign({}, (withAuth ? { Authorization: `Bearer ${authToken}` } : {})), { 'Content-Type': 'application/json', 'X-Instant-Source': 'instant-cli', 'X-Instant-Version': version }), (command ? { 'X-Instant-Command': command } : {})),
1528
1529
  body: body ? JSON.stringify(body) : undefined,
1529
1530
  signal: AbortSignal.timeout(timeoutMs),
1530
1531
  });